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 5805 by michael, Tue Apr 21 21:49:58 2015 UTC vs.
Revision 6732 by michael, Wed Nov 4 21:56:03 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 >  if (IsConfExemptXline(conf))
175 >  {
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 255 | 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 286 | Line 263 | introduce_client(struct Client *source_p
263   static void
264   user_welcome(struct Client *source_p)
265   {
289 #if defined(__TIME__) && defined(__DATE__)
266    static const char built_date[] = __DATE__ " at " __TIME__;
291 #else
292  static const char built_date[] = "unknown";
293 #endif
267  
268   #ifdef HAVE_LIBCRYPTO
269    if (HasFlag(source_p, FLAGS_SSL))
# Line 304 | 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);
310  show_isupport(source_p);
311  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 325 | 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 360 | Line 335 | register_local_user(struct Client *sourc
335  
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 391 | 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] = "";
397    const char *p = username;
372      unsigned int i = 0;
373  
374      if (IsNeedIdentd(conf))
# Line 411 | 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 453 | 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 503 | 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 523 | 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 574 | 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      sendto_realops_flags(UMODE_FARCONNECT, L_ALL, SEND_NOTICE,
# Line 702 | Line 676 | valid_nickname(const char *nickname, con
676   * inputs       - client_p
677   *              - source_p
678   *              - int old
705 *              - sendmask mask of modes to send
679   *              - suplied umode_buf
680   * output       - NONE
681   */
# Line 792 | 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 859 | Line 832 | user_set_hostmask(struct Client *target_
832                                   target_p->name, target_p->username,
833                                   target_p->host, target_p->away);
834   }
862
863 /*! \brief Blindly opers up given source_p, using conf info.
864 *         All checks on passwords have already been done.
865 * \param source_p Pointer to given client to oper
866 */
867 void
868 oper_up(struct Client *source_p)
869 {
870  const unsigned int old = source_p->umodes;
871  const struct MaskItem *const conf = source_p->connection->confs.head->data;
872
873  assert(source_p->connection->confs.head);
874
875  ++Count.oper;
876  SetOper(source_p);
877
878  if (conf->modes)
879    AddUMode(source_p, conf->modes);
880  else if (ConfigGeneral.oper_umodes)
881    AddUMode(source_p, ConfigGeneral.oper_umodes);
882
883  if (!(old & UMODE_INVISIBLE) && HasUMode(source_p, UMODE_INVISIBLE))
884    ++Count.invisi;
885  if ((old & UMODE_INVISIBLE) && !HasUMode(source_p, UMODE_INVISIBLE))
886    --Count.invisi;
887
888  assert(dlinkFind(&oper_list, source_p) == NULL);
889  dlinkAdd(source_p, make_dlink_node(), &oper_list);
890
891  AddOFlag(source_p, conf->port);
892
893  if (HasOFlag(source_p, OPER_FLAG_ADMIN))
894    AddUMode(source_p, UMODE_ADMIN);
895
896  if (!EmptyString(conf->whois))
897  {
898    client_attach_svstag(source_p, RPL_WHOISOPERATOR, "+", conf->whois);
899    sendto_server(source_p, 0, 0, ":%s SVSTAG %s %lu %u + :%s",
900                  me.id, source_p->id, (unsigned long)source_p->tsinfo,
901                  RPL_WHOISOPERATOR, conf->whois);
902  }
903
904  sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, "%s is now an operator",
905                       get_oper_name(source_p));
906  sendto_server(NULL, 0, 0, ":%s GLOBOPS :%s is now an operator",
907                me.id, get_oper_name(source_p));
908  send_umode_out(source_p, old);
909  sendto_one_numeric(source_p, &me, RPL_YOUREOPER);
910 }
911
912 static char new_uid[TOTALSIDUID + 1];  /* Allow for \0 */
913
914 int
915 valid_sid(const char *sid)
916 {
917  if (strlen(sid) == IRC_MAXSID)
918    if (IsDigit(*sid))
919      if (IsAlNum(*(sid + 1)) && IsAlNum(*(sid + 2)))
920        return 1;
921
922  return 0;
923 }
924
925 /*
926 * init_uid()
927 *
928 * inputs       - NONE
929 * output       - NONE
930 * side effects - new_uid is filled in with server id portion (sid)
931 *                (first 3 bytes). Rest is filled in with '9'.
932 *
933 * NOTE: this function assumes that 'ConfigServerInfo.sid' has been set to a proper value
934 */
935 void
936 init_uid(void)
937 {
938  snprintf(new_uid, sizeof(new_uid), "%s999999", ConfigServerInfo.sid);
939 }
940
941 /*
942 * add_one_to_uid
943 *
944 * inputs       - index number into new_uid
945 * output       - NONE
946 * side effects - new_uid is incremented by one
947 *                note this is a recursive function
948 */
949 static void
950 add_one_to_uid(unsigned int i)
951 {
952  if (i < IRC_MAXSID)
953    return;
954
955  if (new_uid[i] == 'Z')
956    new_uid[i] = '0';
957  else if (new_uid[i] == '9')
958  {
959    new_uid[i] = 'A';
960    add_one_to_uid(i - 1);
961  }
962  else
963    ++new_uid[i];
964 }
965
966 /*
967 * uid_get
968 *
969 * inputs       - struct Client *
970 * output       - new UID is returned to caller
971 * side effects - new_uid is incremented by one.
972 */
973 static const char *
974 uid_get(void)
975 {
976  add_one_to_uid(TOTALSIDUID - 1);  /* Index from 0 */
977  return new_uid;
978 }
979
980 /*
981 * init_isupport()
982 *
983 * input        - NONE
984 * output       - NONE
985 * side effects - Must be called before isupport is enabled
986 */
987 void
988 init_isupport(void)
989 {
990  add_isupport("CALLERID", NULL, -1);
991  add_isupport("CASEMAPPING", "rfc1459", -1);
992  add_isupport("DEAF", "D", -1);
993  add_isupport("KICKLEN", NULL, KICKLEN);
994  add_isupport("MODES", NULL, MAXMODEPARAMS);
995  add_isupport("PREFIX", "(ohv)@%+", -1);
996  add_isupport("STATUSMSG", "@%+", -1);
997  add_isupport("EXCEPTS", NULL, -1);
998  add_isupport("INVEX", NULL, -1);
999 }
1000
1001 /*
1002 * add_isupport()
1003 *
1004 * input        - name of supported function
1005 *              - options if any
1006 *              - number if any
1007 * output       - NONE
1008 * side effects - Each supported item must call this when activated
1009 */
1010 void
1011 add_isupport(const char *name, const char *options, int n)
1012 {
1013  dlink_node *node = NULL;
1014  struct Isupport *support = NULL;
1015
1016  DLINK_FOREACH(node, support_list.head)
1017  {
1018    support = node->data;
1019    if (irccmp(support->name, name) == 0)
1020    {
1021      MyFree(support->name);
1022      MyFree(support->options);
1023      break;
1024    }
1025  }
1026
1027  if (node == NULL)
1028  {
1029    support = MyCalloc(sizeof(*support));
1030    dlinkAddTail(support, &support->node, &support_list);
1031  }
1032
1033  support->name = xstrdup(name);
1034  if (options)
1035    support->options = xstrdup(options);
1036  support->number = n;
1037
1038  rebuild_isupport_message_line();
1039 }
1040
1041 /*
1042 * delete_isupport()
1043 *
1044 * input        - name of supported function
1045 * output       - NONE
1046 * side effects - Each supported item must call this when deactivated
1047 */
1048 void
1049 delete_isupport(const char *name)
1050 {
1051  dlink_node *node = NULL;
1052
1053  DLINK_FOREACH(node, support_list.head)
1054  {
1055    struct Isupport *support = node->data;
1056
1057    if (irccmp(support->name, name) == 0)
1058    {
1059      dlinkDelete(node, &support_list);
1060      MyFree(support->name);
1061      MyFree(support->options);
1062      MyFree(support);
1063      break;
1064    }
1065  }
1066
1067  rebuild_isupport_message_line();
1068 }
1069
1070 /*
1071 * rebuild_isupport_message_line
1072 *
1073 * input        - NONE
1074 * output       - NONE
1075 * side effects - Destroy the isupport MessageFile lines, and rebuild.
1076 */
1077 void
1078 rebuild_isupport_message_line(void)
1079 {
1080  char isupportbuffer[IRCD_BUFSIZE];
1081  char *p = isupportbuffer;
1082  dlink_node *node = NULL, *node_next = NULL;
1083  int n = 0;
1084  int tokens = 0;
1085  size_t len = 0;
1086  size_t reserve = strlen(me.name) + HOSTLEN + strlen(numeric_form(RPL_ISUPPORT));
1087
1088  DLINK_FOREACH_SAFE(node, node_next, support_list_lines.head)
1089  {
1090    dlinkDelete(node, &support_list_lines);
1091    MyFree(node->data);
1092    free_dlink_node(node);
1093  }
1094
1095  DLINK_FOREACH(node, support_list.head)
1096  {
1097    struct Isupport *support = node->data;
1098
1099    p += (n = sprintf(p, "%s", support->name));
1100    len += n;
1101
1102    if (support->options)
1103    {
1104      p += (n = sprintf(p, "=%s", support->options));
1105      len += n;
1106    }
1107
1108    if (support->number > 0)
1109    {
1110      p += (n = sprintf(p, "=%d", support->number));
1111      len += n;
1112    }
1113
1114    *p++ = ' ';
1115    len++;
1116    *p = '\0';
1117
1118    if (++tokens == (MAXPARA-2) || len >= (sizeof(isupportbuffer)-reserve))
1119    { /* arbritrary for now */
1120      if (*--p == ' ')
1121        *p = '\0';
1122
1123      dlinkAddTail(xstrdup(isupportbuffer), make_dlink_node(), &support_list_lines);
1124      p = isupportbuffer;
1125      len = 0;
1126      n = tokens = 0;
1127    }
1128  }
1129
1130  if (len)
1131  {
1132    if (*--p == ' ')
1133      *p = '\0';
1134    dlinkAddTail(xstrdup(isupportbuffer), make_dlink_node(), &support_list_lines);
1135  }
1136 }

Diff Legend

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