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-7.2/src/s_user.c (file contents):
Revision 528 by michael, Sat Mar 18 15:13:11 2006 UTC vs.
Revision 889 by michael, Thu Nov 1 12:59:05 2007 UTC

# Line 55 | Line 55
55   #include "s_misc.h"
56   #include "msg.h"
57   #include "pcre.h"
58 + #include "watch.h"
59  
60   int MaxClientCount     = 1;
61   int MaxConnectionCount = 1;
# Line 67 | Line 68 | static char umode_buffer[IRCD_BUFSIZE];
68   static void user_welcome(struct Client *);
69   static void report_and_set_user_flags(struct Client *, const struct AccessItem *);
70   static int check_xline(struct Client *);
70 static int check_regexp_xline(struct Client *);
71   static void introduce_client(struct Client *, struct Client *);
72   static void *uid_get(va_list);
73  
# Line 96 | Line 96 | unsigned int user_modes[256] =
96    0,                  /* @ */
97    0,                  /* A */
98    0,                  /* B */
99 <  0,                  /* C */
99 >  UMODE_CCONN_FULL,   /* C */
100    UMODE_DEAF,         /* D */
101    0,                  /* E */
102    0,                  /* F */
# Line 296 | Line 296 | register_local_user(struct Client *clien
296    assert(source_p->username != username);
297    assert(!source_p->localClient->registration);
298  
299 +  ClearCap(client_p, CAP_TS6);
300 +
301    if (ConfigFileEntry.ping_cookie)
302    {
303      if (!IsPingSent(source_p) &&
# Line 416 | Line 418 | register_local_user(struct Client *clien
418  
419    assert(source_p == client_p);
420  
421 <  /* end of valid user name check */
420 <  if (check_xline(source_p) || check_regexp_xline(source_p))
421 >  if (check_xline(source_p))
422      return;
423  
424    if (IsDead(client_p))
425      return;
426  
427 <  if (source_p->id[0] == '\0' && me.id[0])
427 >  if (me.id[0])
428    {
429 <    char *id = (char *)execute_callback(uid_get_cb, source_p);
429 >    const char *id = execute_callback(uid_get_cb, source_p);
430 >
431      while (hash_find_id(id) != NULL)
432        id = uid_get(NULL);
433  
# Line 444 | Line 446 | register_local_user(struct Client *clien
446                         "255.255.255.255" : ipaddr, get_client_class(source_p),
447                         source_p->info);
448  
449 +  sendto_realops_flags(UMODE_CCONN_FULL, L_ALL,
450 +                       "CLICONN %s %s %s %s %s %s %s 0 %s",
451 +                       nick, source_p->username, source_p->host,
452 +                       ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
453 +                       "255.255.255.255" : ipaddr,
454 +                       get_client_class(source_p),
455 +                       ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
456 +                           "<hidden>" : source_p->client_host,
457 +                       ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
458 +                           "<hidden>" : source_p->client_server,
459 +                       source_p->info);
460 +
461 +
462    /* If they have died in send_* don't do anything. */
463    if (IsDead(source_p))
464      return;
# Line 466 | Line 481 | register_local_user(struct Client *clien
481    SetClient(source_p);
482  
483    source_p->servptr = &me;
484 <  dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->users);
484 >  dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->client_list);
485  
486    /* Increment our total user count here */
487    if (++Count.total > Count.max_tot)
# Line 556 | Line 571 | register_remote_user(struct Client *clie
571    if (++Count.total > Count.max_tot)
572      Count.max_tot = Count.total;
573  
559  ++source_p->from->serv->dep_users;
560
574    SetClient(source_p);
575 <  dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->users);
575 >  dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->client_list);
576    add_user_host(source_p->username, source_p->host, 1);
577    SetUserHost(source_p);
578  
# Line 586 | Line 599 | introduce_client(struct Client *client_p
599    else
600      send_umode(NULL, source_p, 0, SEND_UMODES, ubuf);
601  
602 +  watch_check_hash(source_p, RPL_LOGON);
603 +
604    if (*ubuf == '\0')
605    {
606      ubuf[0] = '+';
607      ubuf[1] = '\0';
608    }
609  
610 <  /* 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)
610 >  DLINK_FOREACH(server_node, serv_list.head)
611    {
612 <    if (IsCapable(uplink, CAP_TS6) && HasID(source_p))
613 <    {
614 <      sendto_one(uplink, ":%s UID %s %d %lu %s %s %s %s %s :%s",
612 >    struct Client *server = server_node->data;
613 >
614 >    if (server == client_p)
615 >        continue;
616 >
617 >    if (IsCapable(server, CAP_TS6) && HasID(source_p))
618 >      sendto_one(server, ":%s UID %s %d %lu %s %s %s %s %s :%s",
619                   source_p->servptr->id,
620                   source_p->name, source_p->hopcount+1,
621                   (unsigned long)source_p->tsinfo,
622                   ubuf, source_p->username, source_p->host,
623                   (MyClient(source_p) && IsIPSpoof(source_p)) ?
624                   "0" : source_p->sockhost, source_p->id, source_p->info);
622    }
625      else
626 <    {
625 <      sendto_one(uplink, "NICK %s %d %lu %s %s %s %s :%s",
626 >      sendto_one(server, "NICK %s %d %lu %s %s %s %s :%s",
627                   source_p->name, source_p->hopcount+1,
628                   (unsigned long)source_p->tsinfo,
629                   ubuf, source_p->username, source_p->host,
630                   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    }
631    }
632   }
633  
# Line 837 | Line 812 | do_local_user(const char *nick, struct C
812  
813    strlcpy(source_p->info, realname, sizeof(source_p->info));
814  
815 +  /* stash for later */
816 +  strlcpy(source_p->client_host, host, sizeof(source_p->client_host));
817 +  strlcpy(source_p->client_server, server, sizeof(source_p->client_server));
818 +
819    if (!IsGotId(source_p))
820    {
821      /* save the username in the client
# Line 858 | Line 837 | do_local_user(const char *nick, struct C
837   static void *
838   change_simple_umode(va_list args)
839   {
840 +  struct Client *client_p;
841    struct Client *source_p;
842    int what;
843    unsigned int flag;
844  
845 <  va_arg(args, struct Client *);
845 >  client_p = va_arg(args, struct Client *);
846    source_p = va_arg(args, struct Client *);
847    what = va_arg(args, int);
848    flag = va_arg(args, unsigned int);
# Line 1048 | Line 1028 | set_user_mode(struct Client *client_p, s
1028   /* send_umode()
1029   * send the MODE string for user (user) to connection client_p
1030   * -avalon
1031 + *
1032 + * inputs       - client_p
1033 + *              - source_p
1034 + *              - int old
1035 + *              - sendmask mask of modes to send
1036 + *              - suplied umode_buf
1037 + * output       - NONE
1038   */
1039   void
1040   send_umode(struct Client *client_p, struct Client *source_p,
# Line 1113 | Line 1100 | void
1100   send_umode_out(struct Client *client_p, struct Client *source_p,
1101                 unsigned int old)
1102   {
1103 <  char buf[IRCD_BUFSIZE];
1103 >  char buf[IRCD_BUFSIZE] = { '\0' };
1104    dlink_node *ptr = NULL;
1105  
1106    send_umode(NULL, source_p, old, IsOperHiddenAdmin(source_p) ?
1107               SEND_UMODES & ~UMODE_ADMIN : SEND_UMODES, buf);
1108  
1109 <  if (*buf)
1109 >  if (buf[0])
1110    {
1111      DLINK_FOREACH(ptr, serv_list.head)
1112      {
1113        struct Client *target_p = ptr->data;
1114  
1115        if ((target_p != client_p) && (target_p != source_p))
1116 <      {
1117 <        if ((!(ServerInfo.hub && IsCapable(target_p, CAP_LL))) ||
1118 <            (target_p->localClient->serverMask &
1132 <             source_p->lazyLinkClientExists))
1133 <          sendto_one(target_p, ":%s MODE %s :%s",
1134 <                     ID_or_name(source_p, target_p),
1135 <                     ID_or_name(source_p, target_p), buf);
1136 <      }
1116 >        sendto_one(target_p, ":%s MODE %s :%s",
1117 >                   ID_or_name(source_p, target_p),
1118 >                   ID_or_name(source_p, target_p), buf);
1119      }
1120    }
1121  
# Line 1207 | Line 1189 | user_welcome(struct Client *source_p)
1189   static int
1190   check_xline(struct Client *source_p)
1191   {
1192 <  struct ConfItem *conf;
1193 <  struct MatchItem *xconf;
1212 <  const char *reason;
1192 >  struct ConfItem *conf = NULL;
1193 >  const char *reason = NULL;
1194  
1195 <  if ((conf = find_matching_name_conf(XLINE_TYPE, source_p->info,
1196 <                                      NULL, NULL, 0)) != NULL)
1195 >  if ((conf = find_matching_name_conf(XLINE_TYPE, source_p->info, NULL, NULL, 0)) ||
1196 >      (conf = find_matching_name_conf(RXLINE_TYPE, source_p->info, NULL, NULL, 0)))
1197    {
1198 <    xconf = map_to_conf(conf);
1199 <    xconf->count++;
1198 >    struct MatchItem *reg = map_to_conf(conf);
1199 >
1200 >    ++reg->count;
1201  
1202 <    if (xconf->reason != NULL)
1203 <      reason = xconf->reason;
1202 >    if (reg->reason != NULL)
1203 >      reason = reg->reason;
1204      else
1205        reason = "No Reason";
1206  
# Line 1228 | Line 1210 | check_xline(struct Client *source_p)
1210                           get_client_name(source_p, HIDE_IP),
1211                           source_p->sockhost);
1212  
1213 <    ServerStats->is_ref++;      
1213 >    ServerStats->is_ref++;
1214      if (REJECT_HOLD_TIME > 0)
1215      {
1216        sendto_one(source_p, ":%s NOTICE %s :Bad user info",
# Line 1244 | Line 1226 | check_xline(struct Client *source_p)
1226    return 0;
1227   }
1228  
1247 static int
1248 check_regexp_xline(struct Client *source_p)
1249 {
1250  struct ConfItem *conf = NULL;
1251  const char *reason = NULL;
1252
1253  if ((conf = find_matching_name_conf(RXLINE_TYPE, source_p->info, NULL, NULL, 0)))
1254  {
1255    struct MatchItem *reg = map_to_conf(conf);
1256
1257    ++reg->count;
1258
1259    if (reg->reason != NULL)
1260      reason = reg->reason;
1261    else
1262      reason = "No Reason";
1263
1264    sendto_realops_flags(UMODE_REJ, L_ALL,
1265                         "X-line (REGEX) Rejecting [%s] [%s], user %s [%s]",
1266                         source_p->info, reason,
1267                         get_client_name(source_p, HIDE_IP),
1268                         source_p->sockhost);
1269
1270    ServerStats->is_ref++;
1271    exit_client(source_p, &me, "Bad user info");
1272    return 1;
1273  }
1274
1275  return 0;
1276 }
1277
1229   /* oper_up()
1230   *
1231   * inputs       - pointer to given client to oper
# Line 1304 | Line 1255 | oper_up(struct Client *source_p)
1255      source_p->umodes |= (UMODE_SERVNOTICE|UMODE_OPERWALL|
1256                           UMODE_WALLOP|UMODE_LOCOPS);
1257  
1258 +  if (!(old & UMODE_INVISIBLE) && IsInvisible(source_p))
1259 +    ++Count.invisi;
1260 +  if ((old & UMODE_INVISIBLE) && !IsInvisible(source_p))
1261 +    --Count.invisi;
1262 +
1263    assert(dlinkFind(&oper_list, source_p) == NULL);
1264    dlinkAdd(source_p, make_dlink_node(), &oper_list);
1265  
# Line 1325 | Line 1281 | oper_up(struct Client *source_p)
1281    send_message_file(source_p, &ConfigFileEntry.opermotd);
1282   }
1283  
1284 < /*
1285 < * Quick and dirty UID code for new proposed SID on EFnet
1286 < *
1287 < */
1284 > static char new_uid[TOTALSIDUID + 1];     /* allow for \0 */
1285 >
1286 > int
1287 > valid_sid(const char *sid)
1288 > {
1289  
1290 < static char new_uid[TOTALSIDUID+1];     /* allow for \0 */
1291 < static void add_one_to_uid(int i);
1290 >  if (strlen(sid) == IRC_MAXSID)
1291 >    if (IsDigit(*sid))
1292 >      if (IsAlNum(*(sid + 1)) && IsAlNum(*(sid + 2)))
1293 >        return 1;
1294 >
1295 >  return 0;
1296 > }
1297  
1298   /*
1299   * init_uid()
# Line 1351 | Line 1313 | init_uid(void)
1313  
1314    if (ServerInfo.sid != NULL)
1315    {
1316 <    memcpy(new_uid, ServerInfo.sid, IRCD_MIN(strlen(ServerInfo.sid),
1317 <                                             IRC_MAXSID));
1318 <    memcpy(&me.id, ServerInfo.sid, IRCD_MIN(strlen(ServerInfo.sid),
1357 <                                            IRC_MAXSID));
1316 >    strlcpy(new_uid, ServerInfo.sid, sizeof(new_uid));
1317 >    strlcpy(me.id, ServerInfo.sid, sizeof(me.id));
1318 >
1319      hash_add_id(&me);
1320    }
1321  
# Line 1362 | Line 1323 | init_uid(void)
1323      if (new_uid[i] == '\0')
1324        new_uid[i] = 'A';
1325  
1326 <  /* XXX if IRC_MAXUID != 6, this will have to be rewritten */
1326 >  /* NOTE: if IRC_MAXUID != 6, this will have to be rewritten */
1327    /* Yes nenolod, I have known it was off by one ever since I wrote it
1328     * But *JUST* for you, though, it really doesn't look as *pretty*
1329     * -Dianora
1330     */
1331 <  memcpy(new_uid+IRC_MAXSID, "AAAAA@", IRC_MAXUID);
1331 >  memcpy(new_uid + IRC_MAXSID, "AAAAA@", IRC_MAXUID);
1332  
1333    entering_umode_cb = register_callback("entering_umode", NULL);
1334    umode_cb = register_callback("changing_umode", change_simple_umode);
# Line 1375 | Line 1336 | init_uid(void)
1336   }
1337  
1338   /*
1378 * uid_get
1379 *
1380 * inputs       - struct Client *
1381 * output       - new UID is returned to caller
1382 * side effects - new_uid is incremented by one.
1383 */
1384 static void *
1385 uid_get(va_list args)
1386 {
1387  add_one_to_uid(TOTALSIDUID-1);    /* index from 0 */
1388  return ((void *) new_uid);
1389 }
1390
1391 /*
1339   * add_one_to_uid
1340   *
1341   * inputs       - index number into new_uid
# Line 1408 | Line 1355 | add_one_to_uid(int i)
1355        new_uid[i] = 'A';
1356        add_one_to_uid(i-1);
1357      }
1358 <    else new_uid[i] = new_uid[i] + 1;
1358 >    else
1359 >      ++new_uid[i];
1360    }
1361    else
1362    {
1363 <    /* XXX if IRC_MAXUID != 6, this will have to be rewritten */
1363 >    /* NOTE: if IRC_MAXUID != 6, this will have to be rewritten */
1364      if (new_uid[i] == 'Z')
1365 <      memcpy(new_uid+IRC_MAXSID, "AAAAAA", IRC_MAXUID);
1365 >      memcpy(new_uid + IRC_MAXSID, "AAAAAA", IRC_MAXUID);
1366      else
1367 <      new_uid[i] = new_uid[i] + 1;
1367 >      ++new_uid[i];
1368    }
1369   }
1370  
1371   /*
1372 + * uid_get
1373 + *
1374 + * inputs       - struct Client *
1375 + * output       - new UID is returned to caller
1376 + * side effects - new_uid is incremented by one.
1377 + */
1378 + static void *
1379 + uid_get(va_list args)
1380 + {
1381 +  add_one_to_uid(TOTALSIDUID - 1);    /* index from 0 */
1382 +  return new_uid;
1383 + }
1384 +
1385 + /*
1386   * init_isupport()
1387   *
1388   * input        - NONE
# Line 1434 | Line 1396 | init_isupport(void)
1396  
1397    add_isupport("CALLERID", NULL, -1);
1398    add_isupport("CASEMAPPING", CASEMAP, -1);
1399 +  add_isupport("DEAF", "D", -1);
1400    add_isupport("KICKLEN", NULL, KICKLEN);
1401    add_isupport("MODES", NULL, MAXMODEPARAMS);
1402    add_isupport("NICKLEN", NULL, NICKLEN-1);

Diff Legend

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