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 159 by michael, Wed Oct 19 09:39:13 2005 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 294 | Line 294 | register_local_user(struct Client *clien
294    assert(source_p != NULL);
295    assert(MyConnect(source_p));
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    {
# Line 415 | Line 418 | register_local_user(struct Client *clien
418  
419    assert(source_p == client_p);
420  
421 <  /* end of valid user name check */
419 <  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 443 | 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 465 | 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 514 | Line 530 | register_remote_user(struct Client *clie
530    strlcpy(source_p->info, realname, sizeof(source_p->info));
531    strlcpy(source_p->username, username, sizeof(source_p->username));
532  
517  /* Increment our total user count here */
518  if (++Count.total > Count.max_tot)
519    Count.max_tot = Count.total;
520
521  source_p->from->serv->dep_users++;
522
533    /*
534     * coming from another server, take the servers word for it
535     */
# Line 537 | Line 547 | register_remote_user(struct Client *clie
547                           source_p->host, source_p->from->name);
548      kill_client(client_p, source_p, "%s (Server doesn't exist)", me.name);
549  
540    /* XXX */
550      SetKilled(source_p);
551      exit_client(source_p, &me, "Ghosted Client");
552      return;
# Line 558 | Line 567 | register_remote_user(struct Client *clie
567      return;
568    }
569  
570 +  /* Increment our total user count here */
571 +  if (++Count.total > Count.max_tot)
572 +    Count.max_tot = Count.total;
573 +
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
611 <   * but then you have to introduce them "on the fly" in SJOIN
612 <   * not fun.
598 <   * Its not going to cost much more bandwidth to simply let new
599 <   * nicks just ride on through.
600 <   */
610 >  DLINK_FOREACH(server_node, serv_list.head)
611 >  {
612 >    struct Client *server = server_node->data;
613  
614 <  /* We now introduce nicks "on the fly" in SJOIN anyway --
615 <   * 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 <   */
614 >    if (server == client_p)
615 >        continue;
616  
617 <  /* XXX THESE NEED A PREFIX!?!?!? */
618 <  if (!ServerInfo.hub && uplink && IsCapable(uplink, CAP_LL) &&
613 <      client_p != uplink)
614 <  {
615 <    if (IsCapable(uplink, CAP_TS6) && HasID(source_p))
616 <    {
617 <      sendto_one(uplink, ":%s UID %s %d %lu %s %s %s %s %s :%s",
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,
621 >                 (unsigned long)source_p->tsinfo,
622                   ubuf, source_p->username, source_p->host,
623 <                 ((MyClient(source_p) && !IsIPSpoof(source_p)) ?
624 <                 source_p->sockhost : "0"),
624 <                 source_p->id, source_p->info);
625 <    }
623 >                 (MyClient(source_p) && IsIPSpoof(source_p)) ?
624 >                 "0" : source_p->sockhost, source_p->id, source_p->info);
625      else
626 <    {
628 <      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,
628 >                 (unsigned long)source_p->tsinfo,
629                   ubuf, source_p->username, source_p->host,
630 <                 source_p->servptr->name,
633 <                 source_p->info);
634 <    }
635 <  }
636 <  else
637 <  {
638 <    DLINK_FOREACH(server_node, serv_list.head)
639 <    {
640 <      struct Client *server = server_node->data;
641 <
642 <      if (IsCapable(server, CAP_LL) || server == client_p)
643 <        continue;
644 <
645 <      if (IsCapable(server, CAP_TS6) && HasID(source_p))
646 <        sendto_one(server, ":%s UID %s %d %lu %s %s %s %s %s :%s",
647 <                   source_p->servptr->id,
648 <                   source_p->name, source_p->hopcount+1,
649 <                   (unsigned long)source_p->tsinfo,
650 <                   ubuf, source_p->username, source_p->host,
651 <                   ((MyClient(source_p)&&!IsIPSpoof(source_p))?source_p->sockhost:"0"),
652 <                   source_p->id, source_p->info);
653 <      else
654 <        sendto_one(server, "NICK %s %d %lu %s %s %s %s :%s",
655 <                   source_p->name, source_p->hopcount+1,
656 <                   (unsigned long)source_p->tsinfo,
657 <                   ubuf, source_p->username, source_p->host,
658 <                   source_p->servptr->name,
659 <                   source_p->info);
660 <    }
630 >                 source_p->servptr->name, source_p->info);
631    }
632   }
633  
# Line 833 | Line 803 | do_local_user(const char *nick, struct C
803      return;
804    }
805  
806 <  source_p->flags |= FLAGS_GOTUSER;
806 >  source_p->localClient->registration &= ~REG_NEED_USER;
807  
808    /*
809     * don't take the clients word for it, ever
# Line 842 | 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 850 | Line 824 | do_local_user(const char *nick, struct C
824      strlcpy(source_p->username, username, sizeof(source_p->username));
825    }
826  
827 <  if (source_p->name[0])
854 <  {
827 >  if (!source_p->localClient->registration)
828      /* NICK already received, now I have USER... */
829      register_local_user(client_p, source_p, source_p->name, username);
857  }
830   }
831  
832   /* change_simple_umode()
# Line 865 | 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 1055 | 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 1105 | Line 1085 | send_umode(struct Client *client_p, stru
1085    *m = '\0';
1086  
1087    if (*umode_buf && client_p)
1088 <    sendto_one(client_p, ":%s MODE %s :%s",
1089 <               source_p->name, source_p->name, umode_buf);
1088 >    sendto_one(client_p, ":%s!%s@%s MODE %s :%s",
1089 >               source_p->name, source_p->username,
1090 >               source_p->host, source_p->name, umode_buf);
1091   }
1092  
1093   /* send_umode_out()
# Line 1119 | 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 &
1138 <             source_p->lazyLinkClientExists))
1139 <          sendto_one(target_p, ":%s MODE %s :%s",
1140 <                     ID_or_name(source_p, target_p),
1141 <                     ID_or_name(source_p, target_p), buf);
1142 <      }
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 1213 | 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;
1218 <  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);
1224 <    xconf->count++;
1198 >    struct MatchItem *reg = map_to_conf(conf);
1199  
1200 <    if (xconf->reason != NULL)
1201 <      reason = xconf->reason;
1200 >    ++reg->count;
1201 >
1202 >    if (reg->reason != NULL)
1203 >      reason = reg->reason;
1204      else
1205        reason = "No Reason";
1206  
# Line 1234 | 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 1250 | Line 1226 | check_xline(struct Client *source_p)
1226    return 0;
1227   }
1228  
1253 static int
1254 check_regexp_xline(struct Client *source_p)
1255 {
1256  struct ConfItem *conf = NULL;
1257  const char *reason = NULL;
1258
1259  if ((conf = find_matching_name_conf(RXLINE_TYPE, source_p->info, NULL, NULL, 0)))
1260  {
1261    struct MatchItem *reg = map_to_conf(conf);
1262
1263    ++reg->count;
1264
1265    if (reg->reason != NULL)
1266      reason = reg->reason;
1267    else
1268      reason = "No Reason";
1269
1270    sendto_realops_flags(UMODE_REJ, L_ALL,
1271                         "X-line (REGEX) Rejecting [%s] [%s], user %s [%s]",
1272                         source_p->info, reason,
1273                         get_client_name(source_p, HIDE_IP),
1274                         source_p->sockhost);
1275
1276    ServerStats->is_ref++;
1277    exit_client(source_p, &me, "Bad user info");
1278    return 1;
1279  }
1280
1281  return 0;
1282 }
1283
1229   /* oper_up()
1230   *
1231   * inputs       - pointer to given client to oper
# Line 1310 | 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 1331 | 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 1357 | 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),
1363 <                                            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 1368 | 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 1381 | Line 1336 | init_uid(void)
1336   }
1337  
1338   /*
1384 * uid_get
1385 *
1386 * inputs       - struct Client *
1387 * output       - new UID is returned to caller
1388 * side effects - new_uid is incremented by one.
1389 */
1390 static void *
1391 uid_get(va_list args)
1392 {
1393  add_one_to_uid(TOTALSIDUID-1);    /* index from 0 */
1394  return ((void *) new_uid);
1395 }
1396
1397 /*
1339   * add_one_to_uid
1340   *
1341   * inputs       - index number into new_uid
# Line 1414 | 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 1440 | 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)