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 5489 by michael, Sun Feb 8 14:52:23 2015 UTC vs.
Revision 6732 by michael, Wed Nov 4 21:56:03 2015 UTC

# Line 19 | Line 19
19   *  USA
20   */
21  
22 < /*! \file s_user.c
22 > /*! \file user.c
23   * \brief User related functions.
24   * \version $Id$
25   */
# 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))
236 <      sendto_one(server, ":%s UID %s %d %lu %s %s %s %s %s %s :%s",
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,
239                   (unsigned long)source_p->tsinfo,
# Line 275 | Line 242 | introduce_client(struct Client *source_p
242                   source_p->account,
243                   source_p->info);
244      else
245 <      sendto_one(server, ":%s UID %s %d %lu %s %s %s %s %s :%s",
245 >      sendto_one(server, ":%s UID %s %u %lu %s %s %s %s %s :%s",
246                   source_p->servptr->id,
247                   source_p->name, source_p->hopcount+1,
248                   (unsigned long)source_p->tsinfo,
# Line 296 | Line 263 | introduce_client(struct Client *source_p
263   static void
264   user_welcome(struct Client *source_p)
265   {
299 #if defined(__TIME__) && defined(__DATE__)
266    static const char built_date[] = __DATE__ " at " __TIME__;
301 #else
302  static const char built_date[] = "unknown";
303 #endif
267  
268   #ifdef HAVE_LIBCRYPTO
269    if (HasFlag(source_p, FLAGS_SSL))
# Line 314 | Line 277 | user_welcome(struct Client *source_p)
277    sendto_one_numeric(source_p, &me, RPL_WELCOME, ConfigServerInfo.network_name,
278                       source_p->name);
279    sendto_one_numeric(source_p, &me, RPL_YOURHOST,
280 <                     get_listener_name(source_p->connection->listener), ircd_version);
280 >                     listener_get_name(source_p->connection->listener), ircd_version);
281    sendto_one_numeric(source_p, &me, RPL_CREATED, built_date);
282    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);
283  
284 +  isupport_show(source_p);
285    show_lusers(source_p);
286    motd_signon(source_p);
287   }
# Line 335 | Line 297 | check_xline(struct Client *source_p)
297   {
298    struct MaskItem *conf = NULL;
299  
300 +  if (HasFlag(source_p, FLAGS_EXEMPTXLINE))
301 +    return 0;
302 +
303    if ((conf = find_matching_name_conf(CONF_XLINE, source_p->info, NULL, NULL, 0)))
304    {
305      ++conf->count;
# Line 365 | Line 330 | register_local_user(struct Client *sourc
330  
331    assert(source_p == source_p->from);
332    assert(MyConnect(source_p));
333 +  assert(IsUnknown(source_p));
334    assert(!source_p->connection->registration);
335  
370  ClearCap(source_p, CAP_TS6);
371
336    if (ConfigGeneral.ping_cookie)
337    {
338 <    if (!IsPingSent(source_p) && !source_p->connection->random_ping)
338 >    if (!HasFlag(source_p, FLAGS_PINGSENT) && !source_p->connection->random_ping)
339      {
340        do
341          source_p->connection->random_ping = genrand_int32();
342        while (!source_p->connection->random_ping);
343  
344        sendto_one(source_p, "PING :%u", source_p->connection->random_ping);
345 <      SetPingSent(source_p);
345 >      AddFlag(source_p, FLAGS_PINGSENT);
346        return;
347      }
348  
349 <    if (!HasPingCookie(source_p))
349 >    if (!HasFlag(source_p, FLAGS_PING_COOKIE))
350        return;
351    }
352  
# Line 402 | Line 366 | register_local_user(struct Client *sourc
366  
367    conf = source_p->connection->confs.head->data;
368  
369 <  if (!IsGotId(source_p))
369 >  if (!HasFlag(source_p, FLAGS_GOTID))
370    {
371      char username[USERLEN + 1] = "";
408    const char *p = username;
372      unsigned int i = 0;
373  
374      if (IsNeedIdentd(conf))
# Line 422 | Line 385 | register_local_user(struct Client *sourc
385      if (!IsNoTilde(conf))
386        source_p->username[i++] = '~';
387  
388 <    for (; *p && i < USERLEN; ++p)
388 >    for (const char *p = username; *p && i < USERLEN; ++p)
389        source_p->username[i++] = *p;
390  
391      source_p->username[i] = '\0';
# Line 464 | Line 427 | register_local_user(struct Client *sourc
427     *   -Taner
428     */
429    if ((Count.local >= GlobalSetOptions.maxclients + MAX_BUFFER) ||
430 <      (Count.local >= GlobalSetOptions.maxclients && !IsExemptLimits(source_p)))
430 >      (Count.local >= GlobalSetOptions.maxclients && !HasFlag(source_p, FLAGS_NOLIMIT)))
431    {
432      sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
433                           "Too many clients, rejecting %s[%s].",
# Line 514 | Line 477 | register_local_user(struct Client *sourc
477      Count.max_loc = Count.local;
478  
479      if (!(Count.max_loc % 10))
480 <      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
480 >      sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
481                             "New maximum local client connections: %u",
482                             Count.max_loc);
483    }
# Line 534 | Line 497 | register_local_user(struct Client *sourc
497                    &unknown_list, &local_client_list);
498  
499    user_welcome(source_p);
500 <  add_user_host(source_p->username, source_p->host, 0);
501 <  SetUserHost(source_p);
500 >  userhost_add(source_p->username, source_p->host, 0);
501 >  AddFlag(source_p, FLAGS_USERHOST);
502  
503    introduce_client(source_p);
504   }
# Line 585 | Line 548 | register_remote_user(struct Client *sour
548    SetClient(source_p);
549    dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->client_list);
550    dlinkAdd(source_p, &source_p->node, &global_client_list);
551 <  add_user_host(source_p->username, source_p->host, 1);
552 <  SetUserHost(source_p);
551 >  userhost_add(source_p->username, source_p->host, 1);
552 >  AddFlag(source_p, FLAGS_USERHOST);
553  
554    if (HasFlag(source_p->servptr, FLAGS_EOB))
555 <  {
556 <    if (strcmp(source_p->sockhost, "0")) /* XXX: TBR */
557 <      sendto_realops_flags(UMODE_FARCONNECT, L_ALL, SEND_NOTICE,
558 <                           "Client connecting at %s: %s (%s@%s) [%s] [%s] <%s>",
559 <                           source_p->servptr->name,
597 <                           source_p->name, source_p->username, source_p->host,
598 <                           source_p->sockhost, source_p->info, source_p->id);
599 <    else
600 <      sendto_realops_flags(UMODE_FARCONNECT, L_ALL, SEND_NOTICE,
601 <                           "Client connecting at %s: %s (%s@%s) [%s] <%s>",
602 <                           source_p->servptr->name,
603 <                           source_p->name, source_p->username, source_p->host,
604 <                           source_p->info, source_p->id);
605 <  }
555 >    sendto_realops_flags(UMODE_FARCONNECT, L_ALL, SEND_NOTICE,
556 >                         "Client connecting at %s: %s (%s@%s) [%s] [%s] <%s>",
557 >                         source_p->servptr->name,
558 >                         source_p->name, source_p->username, source_p->host,
559 >                         source_p->sockhost, source_p->info, source_p->id);
560  
561    introduce_client(source_p);
562   }
# Line 722 | Line 676 | valid_nickname(const char *nickname, con
676   * inputs       - client_p
677   *              - source_p
678   *              - int old
725 *              - sendmask mask of modes to send
679   *              - suplied umode_buf
680   * output       - NONE
681   */
# Line 812 | Line 765 | user_set_hostmask(struct Client *target_
765      sendto_common_channels_local(target_p, 0, 0, ":%s!%s@%s QUIT :Changing hostname",
766                                   target_p->name, target_p->username, target_p->host);
767  
768 <  if (IsUserHostIp(target_p))
769 <    delete_user_host(target_p->username, target_p->host, !MyConnect(target_p));
768 >  if (HasFlag(target_p, FLAGS_USERHOST))
769 >    userhost_del(target_p->username, target_p->host, !MyConnect(target_p));
770  
771    strlcpy(target_p->host, hostname, sizeof(target_p->host));
772  
773 <  add_user_host(target_p->username, target_p->host, !MyConnect(target_p));
774 <  SetUserHost(target_p);
773 >  userhost_add(target_p->username, target_p->host, !MyConnect(target_p));
774 >  AddFlag(target_p, FLAGS_USERHOST);
775  
776 <  if (MyClient(target_p))
776 >  if (MyConnect(target_p))
777    {
778      sendto_one_numeric(target_p, &me, RPL_VISIBLEHOST, target_p->host);
779      clear_ban_cache_client(target_p);
# Line 879 | Line 832 | user_set_hostmask(struct Client *target_
832                                   target_p->name, target_p->username,
833                                   target_p->host, target_p->away);
834   }
882
883 /*! \brief Blindly opers up given source_p, using conf info.
884 *         All checks on passwords have already been done.
885 * \param source_p Pointer to given client to oper
886 */
887 void
888 oper_up(struct Client *source_p)
889 {
890  const unsigned int old = source_p->umodes;
891  const struct MaskItem *const conf = source_p->connection->confs.head->data;
892
893  assert(source_p->connection->confs.head);
894
895  ++Count.oper;
896  SetOper(source_p);
897
898  if (conf->modes)
899    AddUMode(source_p, conf->modes);
900  else if (ConfigGeneral.oper_umodes)
901    AddUMode(source_p, ConfigGeneral.oper_umodes);
902
903  if (!(old & UMODE_INVISIBLE) && HasUMode(source_p, UMODE_INVISIBLE))
904    ++Count.invisi;
905  if ((old & UMODE_INVISIBLE) && !HasUMode(source_p, UMODE_INVISIBLE))
906    --Count.invisi;
907
908  assert(dlinkFind(&oper_list, source_p) == NULL);
909  dlinkAdd(source_p, make_dlink_node(), &oper_list);
910
911  AddOFlag(source_p, conf->port);
912
913  if (HasOFlag(source_p, OPER_FLAG_ADMIN))
914    AddUMode(source_p, UMODE_ADMIN);
915
916  sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, "%s is now an operator",
917                       get_oper_name(source_p));
918  sendto_server(NULL, 0, 0, ":%s GLOBOPS :%s is now an operator",
919                me.id, get_oper_name(source_p));
920  send_umode_out(source_p, old);
921  sendto_one_numeric(source_p, &me, RPL_YOUREOPER);
922 }
923
924 static char new_uid[TOTALSIDUID + 1];  /* Allow for \0 */
925
926 int
927 valid_sid(const char *sid)
928 {
929  if (strlen(sid) == IRC_MAXSID)
930    if (IsDigit(*sid))
931      if (IsAlNum(*(sid + 1)) && IsAlNum(*(sid + 2)))
932        return 1;
933
934  return 0;
935 }
936
937 /*
938 * init_uid()
939 *
940 * inputs       - NONE
941 * output       - NONE
942 * side effects - new_uid is filled in with server id portion (sid)
943 *                (first 3 bytes) or defaulted to 'A'.
944 *                Rest is filled in with 'A'
945 */
946 void
947 init_uid(void)
948 {
949  memset(new_uid, 0, sizeof(new_uid));
950
951  if (!EmptyString(ConfigServerInfo.sid))
952    strlcpy(new_uid, ConfigServerInfo.sid, sizeof(new_uid));
953
954  for (unsigned int i = 0; i < IRC_MAXSID; ++i)
955    if (new_uid[i] == '\0')
956      new_uid[i] = 'A';
957
958  /* NOTE: if IRC_MAXUID != 6, this will have to be rewritten */
959  memcpy(new_uid + IRC_MAXSID, "AAAAA@", IRC_MAXUID);
960 }
961
962 /*
963 * add_one_to_uid
964 *
965 * inputs       - index number into new_uid
966 * output       - NONE
967 * side effects - new_uid is incremented by one
968 *                note this is a recursive function
969 */
970 static void
971 add_one_to_uid(unsigned int i)
972 {
973  if (i != IRC_MAXSID)  /* Not reached server SID portion yet? */
974  {
975    if (new_uid[i] == 'Z')
976      new_uid[i] = '0';
977    else if (new_uid[i] == '9')
978    {
979      new_uid[i] = 'A';
980      add_one_to_uid(i - 1);
981    }
982    else
983      ++new_uid[i];
984  }
985  else
986  {
987    /* NOTE: if IRC_MAXUID != 6, this will have to be rewritten */
988    if (new_uid[i] == 'Z')
989      memcpy(new_uid + IRC_MAXSID, "AAAAAA", IRC_MAXUID);
990    else
991      ++new_uid[i];
992  }
993 }
994
995 /*
996 * uid_get
997 *
998 * inputs       - struct Client *
999 * output       - new UID is returned to caller
1000 * side effects - new_uid is incremented by one.
1001 */
1002 static const char *
1003 uid_get(void)
1004 {
1005  add_one_to_uid(TOTALSIDUID - 1);  /* Index from 0 */
1006  return new_uid;
1007 }
1008
1009 /*
1010 * init_isupport()
1011 *
1012 * input        - NONE
1013 * output       - NONE
1014 * side effects - Must be called before isupport is enabled
1015 */
1016 void
1017 init_isupport(void)
1018 {
1019  add_isupport("CALLERID", NULL, -1);
1020  add_isupport("CASEMAPPING", "rfc1459", -1);
1021  add_isupport("DEAF", "D", -1);
1022  add_isupport("KICKLEN", NULL, KICKLEN);
1023  add_isupport("MODES", NULL, MAXMODEPARAMS);
1024  add_isupport("PREFIX", "(ohv)@%+", -1);
1025  add_isupport("STATUSMSG", "@%+", -1);
1026  add_isupport("EXCEPTS", NULL, -1);
1027  add_isupport("INVEX", NULL, -1);
1028 }
1029
1030 /*
1031 * add_isupport()
1032 *
1033 * input        - name of supported function
1034 *              - options if any
1035 *              - number if any
1036 * output       - NONE
1037 * side effects - Each supported item must call this when activated
1038 */
1039 void
1040 add_isupport(const char *name, const char *options, int n)
1041 {
1042  dlink_node *node = NULL;
1043  struct Isupport *support = NULL;
1044
1045  DLINK_FOREACH(node, support_list.head)
1046  {
1047    support = node->data;
1048    if (irccmp(support->name, name) == 0)
1049    {
1050      MyFree(support->name);
1051      MyFree(support->options);
1052      break;
1053    }
1054  }
1055
1056  if (node == NULL)
1057  {
1058    support = MyCalloc(sizeof(*support));
1059    dlinkAddTail(support, &support->node, &support_list);
1060  }
1061
1062  support->name = xstrdup(name);
1063  if (options)
1064    support->options = xstrdup(options);
1065  support->number = n;
1066
1067  rebuild_isupport_message_line();
1068 }
1069
1070 /*
1071 * delete_isupport()
1072 *
1073 * input        - name of supported function
1074 * output       - NONE
1075 * side effects - Each supported item must call this when deactivated
1076 */
1077 void
1078 delete_isupport(const char *name)
1079 {
1080  dlink_node *node = NULL;
1081
1082  DLINK_FOREACH(node, support_list.head)
1083  {
1084    struct Isupport *support = node->data;
1085
1086    if (irccmp(support->name, name) == 0)
1087    {
1088      dlinkDelete(node, &support_list);
1089      MyFree(support->name);
1090      MyFree(support->options);
1091      MyFree(support);
1092      break;
1093    }
1094  }
1095
1096  rebuild_isupport_message_line();
1097 }
1098
1099 /*
1100 * rebuild_isupport_message_line
1101 *
1102 * input        - NONE
1103 * output       - NONE
1104 * side effects - Destroy the isupport MessageFile lines, and rebuild.
1105 */
1106 void
1107 rebuild_isupport_message_line(void)
1108 {
1109  char isupportbuffer[IRCD_BUFSIZE];
1110  char *p = isupportbuffer;
1111  dlink_node *node = NULL, *node_next = NULL;
1112  int n = 0;
1113  int tokens = 0;
1114  size_t len = 0;
1115  size_t reserve = strlen(me.name) + HOSTLEN + strlen(numeric_form(RPL_ISUPPORT));
1116
1117  DLINK_FOREACH_SAFE(node, node_next, support_list_lines.head)
1118  {
1119    dlinkDelete(node, &support_list_lines);
1120    MyFree(node->data);
1121    free_dlink_node(node);
1122  }
1123
1124  DLINK_FOREACH(node, support_list.head)
1125  {
1126    struct Isupport *support = node->data;
1127
1128    p += (n = sprintf(p, "%s", support->name));
1129    len += n;
1130
1131    if (support->options)
1132    {
1133      p += (n = sprintf(p, "=%s", support->options));
1134      len += n;
1135    }
1136
1137    if (support->number > 0)
1138    {
1139      p += (n = sprintf(p, "=%d", support->number));
1140      len += n;
1141    }
1142
1143    *p++ = ' ';
1144    len++;
1145    *p = '\0';
1146
1147    if (++tokens == (MAXPARA-2) || len >= (sizeof(isupportbuffer)-reserve))
1148    { /* arbritrary for now */
1149      if (*--p == ' ')
1150        *p = '\0';
1151
1152      dlinkAddTail(xstrdup(isupportbuffer), make_dlink_node(), &support_list_lines);
1153      p = isupportbuffer;
1154      len = 0;
1155      n = tokens = 0;
1156    }
1157  }
1158
1159  if (len)
1160  {
1161    if (*--p == ' ')
1162      *p = '\0';
1163    dlinkAddTail(xstrdup(isupportbuffer), make_dlink_node(), &support_list_lines);
1164  }
1165 }

Diff Legend

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