ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/user.c
(Generate patch)

Comparing ircd-hybrid/trunk/src/user.c (file contents):
Revision 5784 by michael, Sun Apr 5 15:17:11 2015 UTC vs.
Revision 6694 by michael, Thu Oct 29 12:53:27 2015 UTC

# Line 31 | Line 31
31   #include "channel_mode.h"
32   #include "client.h"
33   #include "hash.h"
34 + #include "id.h"
35   #include "irc_string.h"
36   #include "ircd.h"
37   #include "listener.h"
# Line 47 | Line 48
48   #include "misc.h"
49   #include "parse.h"
50   #include "watch.h"
51 + #include "isupport.h"
52  
53   static char umode_buffer[IRCD_BUFSIZE];
52 static const char *uid_get(void);
53
54 /* Used for building up the isupport string,
55 * used with init_isupport, add_isupport, delete_isupport
56 */
57 struct Isupport
58 {
59  dlink_node node;
60  char *name;
61  char *options;
62  int number;
63 };
64
65 static dlink_list support_list;
66 static dlink_list support_list_lines;
54  
55   const struct user_modes *umode_map[256];
56   const struct user_modes  umode_tab[] =
# Line 100 | Line 87 | const struct user_modes  umode_tab[] =
87   };
88  
89   void
90 < user_usermodes_init(void)
90 > user_modes_init(void)
91   {
92    char *umode_buffer_ptr = umode_buffer;
93  
# Line 162 | Line 149 | show_lusers(struct Client *source_p)
149      Count.max_loc_con = Count.local + Count.myserver;
150   }
151  
165 /* show_isupport()
166 *
167 * inputs       - pointer to client
168 * output       - NONE
169 * side effects - display to client what we support (for them)
170 */
171 void
172 show_isupport(struct Client *source_p)
173 {
174  const dlink_node *node = NULL;
175
176  DLINK_FOREACH(node, support_list_lines.head)
177    sendto_one_numeric(source_p, &me, RPL_ISUPPORT, node->data);
178 }
179
180
152   /* report_and_set_user_flags()
153   *
154   * inputs       - pointer to source_p
# Line 196 | Line 167 | report_and_set_user_flags(struct Client
167    /* If this user is in the exception class, set it "E lined" */
168    if (IsConfExemptKline(conf))
169    {
170 <    SetExemptKline(source_p);
171 <    sendto_one_notice(source_p, &me, ":*** You are exempt from K/D/G lines. Congrats.");
170 >    AddFlag(source_p, FLAGS_EXEMPTKLINE);
171 >    sendto_one_notice(source_p, &me, ":*** You are exempt from K/D lines. Congrats.");
172    }
173  
174 <  /*
204 <   * The else here is to make sure that G line exempt users
205 <   * do not get noticed twice.
206 <   */
207 <  else if (IsConfExemptGline(conf))
174 >  if (IsConfExemptXline(conf))
175    {
176 <    SetExemptGline(source_p);
177 <    sendto_one_notice(source_p, &me, ":*** You are exempt from G lines. Congrats.");
176 >    AddFlag(source_p, FLAGS_EXEMPTXLINE);
177 >    sendto_one_notice(source_p, &me, ":*** You are exempt from X lines. Congrats.");
178    }
179  
180    if (IsConfExemptResv(conf))
181    {
182 <    SetExemptResv(source_p);
182 >    AddFlag(source_p, FLAGS_EXEMPTRESV);
183      sendto_one_notice(source_p, &me, ":*** You are exempt from resvs. Congrats.");
184    }
185  
186    /* If this user is exempt from user limits set it "F lined" */
187    if (IsConfExemptLimits(conf))
188    {
189 <    SetExemptLimits(source_p);
189 >    AddFlag(source_p, FLAGS_NOLIMIT);
190      sendto_one_notice(source_p, &me, ":*** You are exempt from user limits. Congrats.");
191    }
192  
193    if (IsConfCanFlood(conf))
194    {
195 <    SetCanFlood(source_p);
195 >    AddFlag(source_p, FLAGS_CANFLOOD);
196      sendto_one_notice(source_p, &me, ":*** You are exempt from flood "
197                        "protection, aren't you fearsome.");
198    }
# Line 265 | Line 232 | introduce_client(struct Client *source_p
232      if (server == source_p->from)
233        continue;
234  
235 <    if (IsCapable(server, CAP_SVS))
235 >    if (IsCapable(server, CAPAB_SVS))
236        sendto_one(server, ":%s UID %s %u %lu %s %s %s %s %s %s :%s",
237                   source_p->servptr->id,
238                   source_p->name, source_p->hopcount+1,
# Line 296 | Line 263 | introduce_client(struct Client *source_p
263   static void
264   user_welcome(struct Client *source_p)
265   {
266 < #if defined(__TIME__) && defined(__DATE__)
267 <  static const char built_date[] = __DATE__ " at " __TIME__;
266 > #ifdef BUILD_DATE
267 >  static const char built_date[] = BUILD_DATE;
268   #else
269 <  static const char built_date[] = "unknown";
269 >  static const char built_date[] = __DATE__ " at " __TIME__;
270   #endif
271  
272   #ifdef HAVE_LIBCRYPTO
# Line 314 | Line 281 | user_welcome(struct Client *source_p)
281    sendto_one_numeric(source_p, &me, RPL_WELCOME, ConfigServerInfo.network_name,
282                       source_p->name);
283    sendto_one_numeric(source_p, &me, RPL_YOURHOST,
284 <                     get_listener_name(source_p->connection->listener), ircd_version);
284 >                     listener_get_name(source_p->connection->listener), ircd_version);
285    sendto_one_numeric(source_p, &me, RPL_CREATED, built_date);
286    sendto_one_numeric(source_p, &me, RPL_MYINFO, me.name, ircd_version, umode_buffer);
320  show_isupport(source_p);
321  sendto_one_numeric(source_p, &me, RPL_YOURID, source_p->id);
287  
288 +  isupport_show(source_p);
289    show_lusers(source_p);
290    motd_signon(source_p);
291   }
# Line 335 | Line 301 | check_xline(struct Client *source_p)
301   {
302    struct MaskItem *conf = NULL;
303  
304 +  if (HasFlag(source_p, FLAGS_EXEMPTXLINE))
305 +    return 0;
306 +
307    if ((conf = find_matching_name_conf(CONF_XLINE, source_p->info, NULL, NULL, 0)))
308    {
309      ++conf->count;
# Line 370 | Line 339 | register_local_user(struct Client *sourc
339  
340    if (ConfigGeneral.ping_cookie)
341    {
342 <    if (!IsPingSent(source_p) && !source_p->connection->random_ping)
342 >    if (!HasFlag(source_p, FLAGS_PINGSENT) && !source_p->connection->random_ping)
343      {
344        do
345          source_p->connection->random_ping = genrand_int32();
346        while (!source_p->connection->random_ping);
347  
348        sendto_one(source_p, "PING :%u", source_p->connection->random_ping);
349 <      SetPingSent(source_p);
349 >      AddFlag(source_p, FLAGS_PINGSENT);
350        return;
351      }
352  
353 <    if (!HasPingCookie(source_p))
353 >    if (!HasFlag(source_p, FLAGS_PING_COOKIE))
354        return;
355    }
356  
# Line 401 | Line 370 | register_local_user(struct Client *sourc
370  
371    conf = source_p->connection->confs.head->data;
372  
373 <  if (!IsGotId(source_p))
373 >  if (!HasFlag(source_p, FLAGS_GOTID))
374    {
375      char username[USERLEN + 1] = "";
407    const char *p = username;
376      unsigned int i = 0;
377  
378      if (IsNeedIdentd(conf))
# Line 421 | Line 389 | register_local_user(struct Client *sourc
389      if (!IsNoTilde(conf))
390        source_p->username[i++] = '~';
391  
392 <    for (; *p && i < USERLEN; ++p)
392 >    for (const char *p = username; *p && i < USERLEN; ++p)
393        source_p->username[i++] = *p;
394  
395      source_p->username[i] = '\0';
# Line 463 | Line 431 | register_local_user(struct Client *sourc
431     *   -Taner
432     */
433    if ((Count.local >= GlobalSetOptions.maxclients + MAX_BUFFER) ||
434 <      (Count.local >= GlobalSetOptions.maxclients && !IsExemptLimits(source_p)))
434 >      (Count.local >= GlobalSetOptions.maxclients && !HasFlag(source_p, FLAGS_NOLIMIT)))
435    {
436      sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
437                           "Too many clients, rejecting %s[%s].",
# Line 513 | Line 481 | register_local_user(struct Client *sourc
481      Count.max_loc = Count.local;
482  
483      if (!(Count.max_loc % 10))
484 <      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
484 >      sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
485                             "New maximum local client connections: %u",
486                             Count.max_loc);
487    }
# Line 533 | Line 501 | register_local_user(struct Client *sourc
501                    &unknown_list, &local_client_list);
502  
503    user_welcome(source_p);
504 <  add_user_host(source_p->username, source_p->host, 0);
505 <  SetUserHost(source_p);
504 >  userhost_add(source_p->username, source_p->host, 0);
505 >  AddFlag(source_p, FLAGS_USERHOST);
506  
507    introduce_client(source_p);
508   }
# Line 584 | Line 552 | register_remote_user(struct Client *sour
552    SetClient(source_p);
553    dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->client_list);
554    dlinkAdd(source_p, &source_p->node, &global_client_list);
555 <  add_user_host(source_p->username, source_p->host, 1);
556 <  SetUserHost(source_p);
555 >  userhost_add(source_p->username, source_p->host, 1);
556 >  AddFlag(source_p, FLAGS_USERHOST);
557  
558    if (HasFlag(source_p->servptr, FLAGS_EOB))
559      sendto_realops_flags(UMODE_FARCONNECT, L_ALL, SEND_NOTICE,
# Line 712 | Line 680 | valid_nickname(const char *nickname, con
680   * inputs       - client_p
681   *              - source_p
682   *              - int old
715 *              - sendmask mask of modes to send
683   *              - suplied umode_buf
684   * output       - NONE
685   */
# Line 802 | Line 769 | user_set_hostmask(struct Client *target_
769      sendto_common_channels_local(target_p, 0, 0, ":%s!%s@%s QUIT :Changing hostname",
770                                   target_p->name, target_p->username, target_p->host);
771  
772 <  if (IsUserHostIp(target_p))
773 <    delete_user_host(target_p->username, target_p->host, !MyConnect(target_p));
772 >  if (HasFlag(target_p, FLAGS_USERHOST))
773 >    userhost_del(target_p->username, target_p->host, !MyConnect(target_p));
774  
775    strlcpy(target_p->host, hostname, sizeof(target_p->host));
776  
777 <  add_user_host(target_p->username, target_p->host, !MyConnect(target_p));
778 <  SetUserHost(target_p);
777 >  userhost_add(target_p->username, target_p->host, !MyConnect(target_p));
778 >  AddFlag(target_p, FLAGS_USERHOST);
779  
780    if (MyClient(target_p))
781    {
# Line 869 | Line 836 | user_set_hostmask(struct Client *target_
836                                   target_p->name, target_p->username,
837                                   target_p->host, target_p->away);
838   }
872
873 /*! \brief Blindly opers up given source_p, using conf info.
874 *         All checks on passwords have already been done.
875 * \param source_p Pointer to given client to oper
876 */
877 void
878 oper_up(struct Client *source_p)
879 {
880  const unsigned int old = source_p->umodes;
881  const struct MaskItem *const conf = source_p->connection->confs.head->data;
882
883  assert(source_p->connection->confs.head);
884
885  ++Count.oper;
886  SetOper(source_p);
887
888  if (conf->modes)
889    AddUMode(source_p, conf->modes);
890  else if (ConfigGeneral.oper_umodes)
891    AddUMode(source_p, ConfigGeneral.oper_umodes);
892
893  if (!(old & UMODE_INVISIBLE) && HasUMode(source_p, UMODE_INVISIBLE))
894    ++Count.invisi;
895  if ((old & UMODE_INVISIBLE) && !HasUMode(source_p, UMODE_INVISIBLE))
896    --Count.invisi;
897
898  assert(dlinkFind(&oper_list, source_p) == NULL);
899  dlinkAdd(source_p, make_dlink_node(), &oper_list);
900
901  AddOFlag(source_p, conf->port);
902
903  if (HasOFlag(source_p, OPER_FLAG_ADMIN))
904    AddUMode(source_p, UMODE_ADMIN);
905
906  if (!EmptyString(conf->whois))
907  {
908    client_attach_svstag(source_p, RPL_WHOISOPERATOR, "+", conf->whois);
909    sendto_server(source_p, 0, 0, ":%s SVSTAG %s %lu %u + :%s",
910                  me.id, source_p->id, (unsigned long)source_p->tsinfo,
911                  RPL_WHOISOPERATOR, conf->whois);
912  }
913
914  sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, "%s is now an operator",
915                       get_oper_name(source_p));
916  sendto_server(NULL, 0, 0, ":%s GLOBOPS :%s is now an operator",
917                me.id, get_oper_name(source_p));
918  send_umode_out(source_p, old);
919  sendto_one_numeric(source_p, &me, RPL_YOUREOPER);
920 }
921
922 static char new_uid[TOTALSIDUID + 1];  /* Allow for \0 */
923
924 int
925 valid_sid(const char *sid)
926 {
927  if (strlen(sid) == IRC_MAXSID)
928    if (IsDigit(*sid))
929      if (IsAlNum(*(sid + 1)) && IsAlNum(*(sid + 2)))
930        return 1;
931
932  return 0;
933 }
934
935 /*
936 * init_uid()
937 *
938 * inputs       - NONE
939 * output       - NONE
940 * side effects - new_uid is filled in with server id portion (sid)
941 *                (first 3 bytes). Rest is filled in with '9'.
942 *
943 * NOTE: this function assumes that 'ConfigServerInfo.sid' has been set to a proper value
944 */
945 void
946 init_uid(void)
947 {
948  snprintf(new_uid, sizeof(new_uid), "%s999999", ConfigServerInfo.sid);
949 }
950
951 /*
952 * add_one_to_uid
953 *
954 * inputs       - index number into new_uid
955 * output       - NONE
956 * side effects - new_uid is incremented by one
957 *                note this is a recursive function
958 */
959 static void
960 add_one_to_uid(unsigned int i)
961 {
962  if (i < IRC_MAXSID)
963    return;
964
965  if (new_uid[i] == 'Z')
966    new_uid[i] = '0';
967  else if (new_uid[i] == '9')
968  {
969    new_uid[i] = 'A';
970    add_one_to_uid(i - 1);
971  }
972  else
973    ++new_uid[i];
974 }
975
976 /*
977 * uid_get
978 *
979 * inputs       - struct Client *
980 * output       - new UID is returned to caller
981 * side effects - new_uid is incremented by one.
982 */
983 static const char *
984 uid_get(void)
985 {
986  add_one_to_uid(TOTALSIDUID - 1);  /* Index from 0 */
987  return new_uid;
988 }
989
990 /*
991 * init_isupport()
992 *
993 * input        - NONE
994 * output       - NONE
995 * side effects - Must be called before isupport is enabled
996 */
997 void
998 init_isupport(void)
999 {
1000  add_isupport("CALLERID", NULL, -1);
1001  add_isupport("CASEMAPPING", "rfc1459", -1);
1002  add_isupport("DEAF", "D", -1);
1003  add_isupport("KICKLEN", NULL, KICKLEN);
1004  add_isupport("MODES", NULL, MAXMODEPARAMS);
1005  add_isupport("PREFIX", "(ohv)@%+", -1);
1006  add_isupport("STATUSMSG", "@%+", -1);
1007  add_isupport("EXCEPTS", NULL, -1);
1008  add_isupport("INVEX", NULL, -1);
1009 }
1010
1011 /*
1012 * add_isupport()
1013 *
1014 * input        - name of supported function
1015 *              - options if any
1016 *              - number if any
1017 * output       - NONE
1018 * side effects - Each supported item must call this when activated
1019 */
1020 void
1021 add_isupport(const char *name, const char *options, int n)
1022 {
1023  dlink_node *node = NULL;
1024  struct Isupport *support = NULL;
1025
1026  DLINK_FOREACH(node, support_list.head)
1027  {
1028    support = node->data;
1029    if (irccmp(support->name, name) == 0)
1030    {
1031      MyFree(support->name);
1032      MyFree(support->options);
1033      break;
1034    }
1035  }
1036
1037  if (node == NULL)
1038  {
1039    support = MyCalloc(sizeof(*support));
1040    dlinkAddTail(support, &support->node, &support_list);
1041  }
1042
1043  support->name = xstrdup(name);
1044  if (options)
1045    support->options = xstrdup(options);
1046  support->number = n;
1047
1048  rebuild_isupport_message_line();
1049 }
1050
1051 /*
1052 * delete_isupport()
1053 *
1054 * input        - name of supported function
1055 * output       - NONE
1056 * side effects - Each supported item must call this when deactivated
1057 */
1058 void
1059 delete_isupport(const char *name)
1060 {
1061  dlink_node *node = NULL;
1062
1063  DLINK_FOREACH(node, support_list.head)
1064  {
1065    struct Isupport *support = node->data;
1066
1067    if (irccmp(support->name, name) == 0)
1068    {
1069      dlinkDelete(node, &support_list);
1070      MyFree(support->name);
1071      MyFree(support->options);
1072      MyFree(support);
1073      break;
1074    }
1075  }
1076
1077  rebuild_isupport_message_line();
1078 }
1079
1080 /*
1081 * rebuild_isupport_message_line
1082 *
1083 * input        - NONE
1084 * output       - NONE
1085 * side effects - Destroy the isupport MessageFile lines, and rebuild.
1086 */
1087 void
1088 rebuild_isupport_message_line(void)
1089 {
1090  char isupportbuffer[IRCD_BUFSIZE];
1091  char *p = isupportbuffer;
1092  dlink_node *node = NULL, *node_next = NULL;
1093  int n = 0;
1094  int tokens = 0;
1095  size_t len = 0;
1096  size_t reserve = strlen(me.name) + HOSTLEN + strlen(numeric_form(RPL_ISUPPORT));
1097
1098  DLINK_FOREACH_SAFE(node, node_next, support_list_lines.head)
1099  {
1100    dlinkDelete(node, &support_list_lines);
1101    MyFree(node->data);
1102    free_dlink_node(node);
1103  }
1104
1105  DLINK_FOREACH(node, support_list.head)
1106  {
1107    struct Isupport *support = node->data;
1108
1109    p += (n = sprintf(p, "%s", support->name));
1110    len += n;
1111
1112    if (support->options)
1113    {
1114      p += (n = sprintf(p, "=%s", support->options));
1115      len += n;
1116    }
1117
1118    if (support->number > 0)
1119    {
1120      p += (n = sprintf(p, "=%d", support->number));
1121      len += n;
1122    }
1123
1124    *p++ = ' ';
1125    len++;
1126    *p = '\0';
1127
1128    if (++tokens == (MAXPARA-2) || len >= (sizeof(isupportbuffer)-reserve))
1129    { /* arbritrary for now */
1130      if (*--p == ' ')
1131        *p = '\0';
1132
1133      dlinkAddTail(xstrdup(isupportbuffer), make_dlink_node(), &support_list_lines);
1134      p = isupportbuffer;
1135      len = 0;
1136      n = tokens = 0;
1137    }
1138  }
1139
1140  if (len)
1141  {
1142    if (*--p == ' ')
1143      *p = '\0';
1144    dlinkAddTail(xstrdup(isupportbuffer), make_dlink_node(), &support_list_lines);
1145  }
1146 }

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)