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

Comparing ircd-hybrid-7.2/src/s_user.c (file contents):
Revision 507 by michael, Sat Mar 4 08:20:28 2006 UTC vs.
Revision 948 by michael, Tue Jul 21 17:34:06 2009 UTC

# Line 35 | Line 35
35   #include "irc_string.h"
36   #include "sprintf_irc.h"
37   #include "s_bsd.h"
38 #include "irc_getnameinfo.h"
38   #include "ircd.h"
39   #include "list.h"
40   #include "listener.h"
# Line 44 | Line 43
43   #include "s_conf.h"
44   #include "s_log.h"
45   #include "s_serv.h"
47 #include "s_stats.h"
46   #include "send.h"
47   #include "supported.h"
48   #include "whowas.h"
# Line 55 | Line 53
53   #include "s_misc.h"
54   #include "msg.h"
55   #include "pcre.h"
56 + #include "watch.h"
57  
58   int MaxClientCount     = 1;
59   int MaxConnectionCount = 1;
# Line 67 | Line 66 | static char umode_buffer[IRCD_BUFSIZE];
66   static void user_welcome(struct Client *);
67   static void report_and_set_user_flags(struct Client *, const struct AccessItem *);
68   static int check_xline(struct Client *);
70 static int check_regexp_xline(struct Client *);
69   static void introduce_client(struct Client *, struct Client *);
70   static void *uid_get(va_list);
71  
# Line 96 | Line 94 | unsigned int user_modes[256] =
94    0,                  /* @ */
95    0,                  /* A */
96    0,                  /* B */
97 <  0,                  /* C */
97 >  UMODE_CCONN_FULL,   /* C */
98    UMODE_DEAF,         /* D */
99    0,                  /* E */
100    0,                  /* F */
# Line 287 | Line 285 | register_local_user(struct Client *clien
285                      const char *nick, const char *username)
286   {
287    const struct AccessItem *aconf = NULL;
290  char ipaddr[HOSTIPLEN];
288    dlink_node *ptr = NULL;
289    dlink_node *m = NULL;
290  
# Line 296 | Line 293 | register_local_user(struct Client *clien
293    assert(source_p->username != username);
294    assert(!source_p->localClient->registration);
295  
296 +  ClearCap(client_p, CAP_TS6);
297 +
298    if (ConfigFileEntry.ping_cookie)
299    {
300      if (!IsPingSent(source_p) &&
# Line 337 | Line 336 | register_local_user(struct Client *clien
336  
337      if (IsNeedIdentd(aconf))
338      {
339 <      ServerStats->is_ref++;
339 >      ++ServerStats.is_ref;
340        sendto_one(source_p, ":%s NOTICE %s :*** Notice -- You need to install "
341                   "identd to use this server", me.name, source_p->name);
342        exit_client(source_p, &me, "Install identd");
# Line 366 | Line 365 | register_local_user(struct Client *clien
365  
366      if (!match_conf_password(pass, aconf))
367      {
368 <      ServerStats->is_ref++;
368 >      ++ServerStats.is_ref;
369        sendto_one(source_p, form_str(ERR_PASSWDMISMATCH),
370                   me.name, source_p->name);
371        exit_client(source_p, &me, "Bad Password");
# Line 396 | Line 395 | register_local_user(struct Client *clien
395      sendto_realops_flags(UMODE_FULL, L_ALL,
396                           "Too many clients, rejecting %s[%s].",
397                           nick, source_p->host);
398 <    ServerStats->is_ref++;
398 >    ++ServerStats.is_ref;
399      exit_client(source_p, &me, "Sorry, server is full - try later");
400      return;
401    }
# Line 408 | Line 407 | register_local_user(struct Client *clien
407  
408      sendto_realops_flags(UMODE_REJ, L_ALL, "Invalid username: %s (%s@%s)",
409                           nick, source_p->username, source_p->host);
410 <    ServerStats->is_ref++;
410 >    ++ServerStats.is_ref;
411      ircsprintf(tmpstr2, "Invalid username [%s]", source_p->username);
412      exit_client(source_p, &me, tmpstr2);
413      return;
# Line 416 | Line 415 | register_local_user(struct Client *clien
415  
416    assert(source_p == client_p);
417  
418 <  /* end of valid user name check */
420 <  if (check_xline(source_p) || check_regexp_xline(source_p))
418 >  if (check_xline(source_p))
419      return;
420  
421    if (IsDead(client_p))
422      return;
423  
424 <  if (source_p->id[0] == '\0' && me.id[0])
424 >  if (me.id[0])
425    {
426 <    char *id = (char *)execute_callback(uid_get_cb, source_p);
426 >    const char *id = execute_callback(uid_get_cb, source_p);
427 >
428      while (hash_find_id(id) != NULL)
429        id = uid_get(NULL);
430  
# Line 433 | Line 432 | register_local_user(struct Client *clien
432      hash_add_id(source_p);
433    }
434  
436  irc_getnameinfo((struct sockaddr *)&source_p->localClient->ip,
437                  source_p->localClient->ip.ss_len, ipaddr,
438                  HOSTIPLEN, NULL, 0, NI_NUMERICHOST);
439
435    sendto_realops_flags(UMODE_CCONN, L_ALL,
436                         "Client connecting: %s (%s@%s) [%s] {%s} [%s]",
437                         nick, source_p->username, source_p->host,
438                         ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
439 <                       "255.255.255.255" : ipaddr, get_client_class(source_p),
439 >                       "255.255.255.255" : source_p->sockhost,
440 >                       get_client_class(source_p),
441 >                       source_p->info);
442 >
443 >  sendto_realops_flags(UMODE_CCONN_FULL, L_ALL,
444 >                       "CLICONN %s %s %s %s %s %s %s 0 %s",
445 >                       nick, source_p->username, source_p->host,
446 >                       ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
447 >                       "255.255.255.255" : source_p->sockhost,
448 >                       get_client_class(source_p),
449 >                       ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
450 >                           "<hidden>" : source_p->client_host,
451 >                       ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
452 >                           "<hidden>" : source_p->client_server,
453                         source_p->info);
454  
455 +
456    /* If they have died in send_* don't do anything. */
457    if (IsDead(source_p))
458      return;
# Line 466 | Line 475 | register_local_user(struct Client *clien
475    SetClient(source_p);
476  
477    source_p->servptr = &me;
478 <  dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->users);
478 >  dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->client_list);
479  
480    /* Increment our total user count here */
481    if (++Count.total > Count.max_tot)
482      Count.max_tot = Count.total;
483 <  Count.totalrestartcount++;
483 >  ++Count.totalrestartcount;
484  
485    source_p->localClient->allow_read = MAX_FLOOD_BURST;
486  
# Line 515 | Line 524 | register_remote_user(struct Client *clie
524    strlcpy(source_p->info, realname, sizeof(source_p->info));
525    strlcpy(source_p->username, username, sizeof(source_p->username));
526  
518  /* Increment our total user count here */
519  if (++Count.total > Count.max_tot)
520    Count.max_tot = Count.total;
521
522  source_p->from->serv->dep_users++;
523
527    /*
528     * coming from another server, take the servers word for it
529     */
# Line 558 | Line 561 | register_remote_user(struct Client *clie
561      return;
562    }
563  
564 +  /* Increment our total user count here */
565 +  if (++Count.total > Count.max_tot)
566 +    Count.max_tot = Count.total;
567 +
568    SetClient(source_p);
569 <  dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->users);
569 >  dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->client_list);
570    add_user_host(source_p->username, source_p->host, 1);
571    SetUserHost(source_p);
572  
# Line 586 | Line 593 | introduce_client(struct Client *client_p
593    else
594      send_umode(NULL, source_p, 0, SEND_UMODES, ubuf);
595  
596 +  watch_check_hash(source_p, RPL_LOGON);
597 +
598    if (*ubuf == '\0')
599    {
600      ubuf[0] = '+';
601      ubuf[1] = '\0';
602    }
603  
604 <  /* arghhh one could try not introducing new nicks to ll leafs
596 <   * but then you have to introduce them "on the fly" in SJOIN
597 <   * not fun.
598 <   * Its not going to cost much more bandwidth to simply let new
599 <   * nicks just ride on through.
600 <   */
601 <
602 <  /* We now introduce nicks "on the fly" in SJOIN anyway --
603 <   * you _need_ to if you aren't going to burst everyone initially.
604 <   *
605 <   * Only send to non CAP_LL servers, unless we're a lazylink leaf,
606 <   * in that case just send it to the uplink.
607 <   * -davidt
608 <   * rewritten to cope with SIDs .. eww eww eww --is
609 <   */
610 <  if (!ServerInfo.hub && uplink && IsCapable(uplink, CAP_LL) &&
611 <      client_p != uplink)
604 >  DLINK_FOREACH(server_node, serv_list.head)
605    {
606 <    if (IsCapable(uplink, CAP_TS6) && HasID(source_p))
607 <    {
608 <      sendto_one(uplink, ":%s UID %s %d %lu %s %s %s %s %s :%s",
606 >    struct Client *server = server_node->data;
607 >
608 >    if (server == client_p)
609 >        continue;
610 >
611 >    if (IsCapable(server, CAP_TS6) && HasID(source_p))
612 >      sendto_one(server, ":%s UID %s %d %lu %s %s %s %s %s :%s",
613                   source_p->servptr->id,
614                   source_p->name, source_p->hopcount+1,
615                   (unsigned long)source_p->tsinfo,
616                   ubuf, source_p->username, source_p->host,
617                   (MyClient(source_p) && IsIPSpoof(source_p)) ?
618                   "0" : source_p->sockhost, source_p->id, source_p->info);
622    }
619      else
620 <    {
625 <      sendto_one(uplink, "NICK %s %d %lu %s %s %s %s :%s",
620 >      sendto_one(server, "NICK %s %d %lu %s %s %s %s :%s",
621                   source_p->name, source_p->hopcount+1,
622                   (unsigned long)source_p->tsinfo,
623                   ubuf, source_p->username, source_p->host,
624                   source_p->servptr->name, source_p->info);
630    }
631  }
632  else
633  {
634    DLINK_FOREACH(server_node, serv_list.head)
635    {
636      struct Client *server = server_node->data;
637
638      if (IsCapable(server, CAP_LL) || server == client_p)
639        continue;
640
641      if (IsCapable(server, CAP_TS6) && HasID(source_p))
642        sendto_one(server, ":%s UID %s %d %lu %s %s %s %s %s :%s",
643                   source_p->servptr->id,
644                   source_p->name, source_p->hopcount+1,
645                   (unsigned long)source_p->tsinfo,
646                   ubuf, source_p->username, source_p->host,
647                   (MyClient(source_p) && IsIPSpoof(source_p)) ?
648                   "0" : source_p->sockhost, source_p->id, source_p->info);
649      else
650        sendto_one(server, "NICK %s %d %lu %s %s %s %s :%s",
651                   source_p->name, source_p->hopcount+1,
652                   (unsigned long)source_p->tsinfo,
653                   ubuf, source_p->username, source_p->host,
654                   source_p->servptr->name, source_p->info);
655    }
625    }
626   }
627  
# Line 837 | Line 806 | do_local_user(const char *nick, struct C
806  
807    strlcpy(source_p->info, realname, sizeof(source_p->info));
808  
809 +  /* stash for later */
810 +  strlcpy(source_p->client_host, host, sizeof(source_p->client_host));
811 +  strlcpy(source_p->client_server, server, sizeof(source_p->client_server));
812 +
813    if (!IsGotId(source_p))
814    {
815      /* save the username in the client
# Line 858 | Line 831 | do_local_user(const char *nick, struct C
831   static void *
832   change_simple_umode(va_list args)
833   {
834 +  struct Client *client_p;
835    struct Client *source_p;
836    int what;
837    unsigned int flag;
838  
839 <  va_arg(args, struct Client *);
839 >  client_p = va_arg(args, struct Client *);
840    source_p = va_arg(args, struct Client *);
841    what = va_arg(args, int);
842    flag = va_arg(args, unsigned int);
# Line 1048 | Line 1022 | set_user_mode(struct Client *client_p, s
1022   /* send_umode()
1023   * send the MODE string for user (user) to connection client_p
1024   * -avalon
1025 + *
1026 + * inputs       - client_p
1027 + *              - source_p
1028 + *              - int old
1029 + *              - sendmask mask of modes to send
1030 + *              - suplied umode_buf
1031 + * output       - NONE
1032   */
1033   void
1034   send_umode(struct Client *client_p, struct Client *source_p,
# Line 1098 | Line 1079 | send_umode(struct Client *client_p, stru
1079    *m = '\0';
1080  
1081    if (*umode_buf && client_p)
1082 <    sendto_one(client_p, ":%s MODE %s :%s",
1083 <               source_p->name, source_p->name, umode_buf);
1082 >    sendto_one(client_p, ":%s!%s@%s MODE %s :%s",
1083 >               source_p->name, source_p->username,
1084 >               source_p->host, source_p->name, umode_buf);
1085   }
1086  
1087   /* send_umode_out()
# Line 1112 | Line 1094 | void
1094   send_umode_out(struct Client *client_p, struct Client *source_p,
1095                 unsigned int old)
1096   {
1097 <  char buf[IRCD_BUFSIZE];
1097 >  char buf[IRCD_BUFSIZE] = { '\0' };
1098    dlink_node *ptr = NULL;
1099  
1100    send_umode(NULL, source_p, old, IsOperHiddenAdmin(source_p) ?
1101               SEND_UMODES & ~UMODE_ADMIN : SEND_UMODES, buf);
1102  
1103 <  if (*buf)
1103 >  if (buf[0])
1104    {
1105      DLINK_FOREACH(ptr, serv_list.head)
1106      {
1107        struct Client *target_p = ptr->data;
1108  
1109        if ((target_p != client_p) && (target_p != source_p))
1110 <      {
1111 <        if ((!(ServerInfo.hub && IsCapable(target_p, CAP_LL))) ||
1112 <            (target_p->localClient->serverMask &
1131 <             source_p->lazyLinkClientExists))
1132 <          sendto_one(target_p, ":%s MODE %s :%s",
1133 <                     ID_or_name(source_p, target_p),
1134 <                     ID_or_name(source_p, target_p), buf);
1135 <      }
1110 >        sendto_one(target_p, ":%s MODE %s :%s",
1111 >                   ID_or_name(source_p, target_p),
1112 >                   ID_or_name(source_p, target_p), buf);
1113      }
1114    }
1115  
# Line 1206 | Line 1183 | user_welcome(struct Client *source_p)
1183   static int
1184   check_xline(struct Client *source_p)
1185   {
1186 <  struct ConfItem *conf;
1187 <  struct MatchItem *xconf;
1211 <  const char *reason;
1186 >  struct ConfItem *conf = NULL;
1187 >  const char *reason = NULL;
1188  
1189 <  if ((conf = find_matching_name_conf(XLINE_TYPE, source_p->info,
1190 <                                      NULL, NULL, 0)) != NULL)
1189 >  if ((conf = find_matching_name_conf(XLINE_TYPE, source_p->info, NULL, NULL, 0)) ||
1190 >      (conf = find_matching_name_conf(RXLINE_TYPE, source_p->info, NULL, NULL, 0)))
1191    {
1192 <    xconf = map_to_conf(conf);
1193 <    xconf->count++;
1192 >    struct MatchItem *reg = map_to_conf(conf);
1193 >
1194 >    ++reg->count;
1195  
1196 <    if (xconf->reason != NULL)
1197 <      reason = xconf->reason;
1196 >    if (reg->reason != NULL)
1197 >      reason = reg->reason;
1198      else
1199        reason = "No Reason";
1200  
# Line 1227 | Line 1204 | check_xline(struct Client *source_p)
1204                           get_client_name(source_p, HIDE_IP),
1205                           source_p->sockhost);
1206  
1207 <    ServerStats->is_ref++;      
1207 >    ++ServerStats.is_ref;
1208      if (REJECT_HOLD_TIME > 0)
1209      {
1210        sendto_one(source_p, ":%s NOTICE %s :Bad user info",
# Line 1243 | Line 1220 | check_xline(struct Client *source_p)
1220    return 0;
1221   }
1222  
1246 static int
1247 check_regexp_xline(struct Client *source_p)
1248 {
1249  struct ConfItem *conf = NULL;
1250  const char *reason = NULL;
1251
1252  if ((conf = find_matching_name_conf(RXLINE_TYPE, source_p->info, NULL, NULL, 0)))
1253  {
1254    struct MatchItem *reg = map_to_conf(conf);
1255
1256    ++reg->count;
1257
1258    if (reg->reason != NULL)
1259      reason = reg->reason;
1260    else
1261      reason = "No Reason";
1262
1263    sendto_realops_flags(UMODE_REJ, L_ALL,
1264                         "X-line (REGEX) Rejecting [%s] [%s], user %s [%s]",
1265                         source_p->info, reason,
1266                         get_client_name(source_p, HIDE_IP),
1267                         source_p->sockhost);
1268
1269    ServerStats->is_ref++;
1270    exit_client(source_p, &me, "Bad user info");
1271    return 1;
1272  }
1273
1274  return 0;
1275 }
1276
1223   /* oper_up()
1224   *
1225   * inputs       - pointer to given client to oper
# Line 1303 | Line 1249 | oper_up(struct Client *source_p)
1249      source_p->umodes |= (UMODE_SERVNOTICE|UMODE_OPERWALL|
1250                           UMODE_WALLOP|UMODE_LOCOPS);
1251  
1252 +  if (!(old & UMODE_INVISIBLE) && IsInvisible(source_p))
1253 +    ++Count.invisi;
1254 +  if ((old & UMODE_INVISIBLE) && !IsInvisible(source_p))
1255 +    --Count.invisi;
1256 +
1257    assert(dlinkFind(&oper_list, source_p) == NULL);
1258    dlinkAdd(source_p, make_dlink_node(), &oper_list);
1259  
# Line 1324 | Line 1275 | oper_up(struct Client *source_p)
1275    send_message_file(source_p, &ConfigFileEntry.opermotd);
1276   }
1277  
1278 < /*
1279 < * Quick and dirty UID code for new proposed SID on EFnet
1280 < *
1281 < */
1278 > static char new_uid[TOTALSIDUID + 1];     /* allow for \0 */
1279 >
1280 > int
1281 > valid_sid(const char *sid)
1282 > {
1283  
1284 < static char new_uid[TOTALSIDUID+1];     /* allow for \0 */
1285 < static void add_one_to_uid(int i);
1284 >  if (strlen(sid) == IRC_MAXSID)
1285 >    if (IsDigit(*sid))
1286 >      if (IsAlNum(*(sid + 1)) && IsAlNum(*(sid + 2)))
1287 >        return 1;
1288 >
1289 >  return 0;
1290 > }
1291  
1292   /*
1293   * init_uid()
# Line 1350 | Line 1307 | init_uid(void)
1307  
1308    if (ServerInfo.sid != NULL)
1309    {
1310 <    memcpy(new_uid, ServerInfo.sid, IRCD_MIN(strlen(ServerInfo.sid),
1311 <                                             IRC_MAXSID));
1312 <    memcpy(&me.id, ServerInfo.sid, IRCD_MIN(strlen(ServerInfo.sid),
1356 <                                            IRC_MAXSID));
1310 >    strlcpy(new_uid, ServerInfo.sid, sizeof(new_uid));
1311 >    strlcpy(me.id, ServerInfo.sid, sizeof(me.id));
1312 >
1313      hash_add_id(&me);
1314    }
1315  
# Line 1361 | Line 1317 | init_uid(void)
1317      if (new_uid[i] == '\0')
1318        new_uid[i] = 'A';
1319  
1320 <  /* XXX if IRC_MAXUID != 6, this will have to be rewritten */
1320 >  /* NOTE: if IRC_MAXUID != 6, this will have to be rewritten */
1321    /* Yes nenolod, I have known it was off by one ever since I wrote it
1322     * But *JUST* for you, though, it really doesn't look as *pretty*
1323     * -Dianora
1324     */
1325 <  memcpy(new_uid+IRC_MAXSID, "AAAAA@", IRC_MAXUID);
1325 >  memcpy(new_uid + IRC_MAXSID, "AAAAA@", IRC_MAXUID);
1326  
1327    entering_umode_cb = register_callback("entering_umode", NULL);
1328    umode_cb = register_callback("changing_umode", change_simple_umode);
# Line 1374 | Line 1330 | init_uid(void)
1330   }
1331  
1332   /*
1377 * uid_get
1378 *
1379 * inputs       - struct Client *
1380 * output       - new UID is returned to caller
1381 * side effects - new_uid is incremented by one.
1382 */
1383 static void *
1384 uid_get(va_list args)
1385 {
1386  add_one_to_uid(TOTALSIDUID-1);    /* index from 0 */
1387  return ((void *) new_uid);
1388 }
1389
1390 /*
1333   * add_one_to_uid
1334   *
1335   * inputs       - index number into new_uid
# Line 1407 | Line 1349 | add_one_to_uid(int i)
1349        new_uid[i] = 'A';
1350        add_one_to_uid(i-1);
1351      }
1352 <    else new_uid[i] = new_uid[i] + 1;
1352 >    else
1353 >      ++new_uid[i];
1354    }
1355    else
1356    {
1357 <    /* XXX if IRC_MAXUID != 6, this will have to be rewritten */
1357 >    /* NOTE: if IRC_MAXUID != 6, this will have to be rewritten */
1358      if (new_uid[i] == 'Z')
1359 <      memcpy(new_uid+IRC_MAXSID, "AAAAAA", IRC_MAXUID);
1359 >      memcpy(new_uid + IRC_MAXSID, "AAAAAA", IRC_MAXUID);
1360      else
1361 <      new_uid[i] = new_uid[i] + 1;
1361 >      ++new_uid[i];
1362    }
1363   }
1364  
1365   /*
1366 + * uid_get
1367 + *
1368 + * inputs       - struct Client *
1369 + * output       - new UID is returned to caller
1370 + * side effects - new_uid is incremented by one.
1371 + */
1372 + static void *
1373 + uid_get(va_list args)
1374 + {
1375 +  add_one_to_uid(TOTALSIDUID - 1);    /* index from 0 */
1376 +  return new_uid;
1377 + }
1378 +
1379 + /*
1380   * init_isupport()
1381   *
1382   * input        - NONE
# Line 1433 | Line 1390 | init_isupport(void)
1390  
1391    add_isupport("CALLERID", NULL, -1);
1392    add_isupport("CASEMAPPING", CASEMAP, -1);
1393 +  add_isupport("DEAF", "D", -1);
1394    add_isupport("KICKLEN", NULL, KICKLEN);
1395    add_isupport("MODES", NULL, MAXMODEPARAMS);
1396    add_isupport("NICKLEN", NULL, NICKLEN-1);

Diff Legend

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