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 528 by michael, Sat Mar 18 15:13:11 2006 UTC vs.
Revision 981 by michael, Sun Aug 9 19:09:03 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 382 | Line 381 | register_local_user(struct Client *clien
381    /* report if user has &^>= etc. and set flags as needed in source_p */
382    report_and_set_user_flags(source_p, aconf);
383  
384 +  if (IsDead(client_p))
385 +    return;
386 +
387    /* Limit clients -
388     * We want to be able to have servers and F-line clients
389     * connect, so save room for "buffer" connections.
# Line 396 | Line 398 | register_local_user(struct Client *clien
398      sendto_realops_flags(UMODE_FULL, L_ALL,
399                           "Too many clients, rejecting %s[%s].",
400                           nick, source_p->host);
401 <    ServerStats->is_ref++;
401 >    ++ServerStats.is_ref;
402      exit_client(source_p, &me, "Sorry, server is full - try later");
403      return;
404    }
# Line 408 | Line 410 | register_local_user(struct Client *clien
410  
411      sendto_realops_flags(UMODE_REJ, L_ALL, "Invalid username: %s (%s@%s)",
412                           nick, source_p->username, source_p->host);
413 <    ServerStats->is_ref++;
413 >    ++ServerStats.is_ref;
414      ircsprintf(tmpstr2, "Invalid username [%s]", source_p->username);
415      exit_client(source_p, &me, tmpstr2);
416      return;
# 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 <    return;
422 <
423 <  if (IsDead(client_p))
421 >  if (check_xline(source_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  
447  /* If they have died in send_* don't do anything. */
448  if (IsDead(source_p))
449    return;
455  
456    if (ConfigFileEntry.invisible_on_connect)
457    {
458      source_p->umodes |= UMODE_INVISIBLE;
459 <    Count.invisi++;
459 >    ++Count.invisi;
460    }
461  
462    if ((++Count.local) > Count.max_loc)
# Line 466 | Line 471 | register_local_user(struct Client *clien
471    SetClient(source_p);
472  
473    source_p->servptr = &me;
474 <  dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->users);
474 >  dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->client_list);
475  
476    /* Increment our total user count here */
477    if (++Count.total > Count.max_tot)
478      Count.max_tot = Count.total;
479 <  Count.totalrestartcount++;
479 >  ++Count.totalrestartcount;
480  
481    source_p->localClient->allow_read = MAX_FLOOD_BURST;
482  
# Line 512 | Line 517 | register_remote_user(struct Client *clie
517    assert(source_p->username != username);
518  
519    strlcpy(source_p->host, host, sizeof(source_p->host));
515  strlcpy(source_p->info, realname, sizeof(source_p->info));
520    strlcpy(source_p->username, username, sizeof(source_p->username));
521  
522    /*
# Line 556 | Line 560 | register_remote_user(struct Client *clie
560    if (++Count.total > Count.max_tot)
561      Count.max_tot = Count.total;
562  
559  ++source_p->from->serv->dep_users;
560
563    SetClient(source_p);
564 <  dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->users);
564 >  dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->client_list);
565    add_user_host(source_p->username, source_p->host, 1);
566    SetUserHost(source_p);
567  
# Line 586 | Line 588 | introduce_client(struct Client *client_p
588    else
589      send_umode(NULL, source_p, 0, SEND_UMODES, ubuf);
590  
591 +  watch_check_hash(source_p, RPL_LOGON);
592 +
593    if (*ubuf == '\0')
594    {
595      ubuf[0] = '+';
596      ubuf[1] = '\0';
597    }
598  
599 <  /* 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)
599 >  DLINK_FOREACH(server_node, serv_list.head)
600    {
601 <    if (IsCapable(uplink, CAP_TS6) && HasID(source_p))
602 <    {
603 <      sendto_one(uplink, ":%s UID %s %d %lu %s %s %s %s %s :%s",
601 >    struct Client *server = server_node->data;
602 >
603 >    if (server == client_p)
604 >        continue;
605 >
606 >    if (IsCapable(server, CAP_TS6) && HasID(source_p))
607 >      sendto_one(server, ":%s UID %s %d %lu %s %s %s %s %s :%s",
608                   source_p->servptr->id,
609                   source_p->name, source_p->hopcount+1,
610                   (unsigned long)source_p->tsinfo,
611                   ubuf, source_p->username, source_p->host,
612                   (MyClient(source_p) && IsIPSpoof(source_p)) ?
613                   "0" : source_p->sockhost, source_p->id, source_p->info);
622    }
614      else
615 <    {
625 <      sendto_one(uplink, "NICK %s %d %lu %s %s %s %s :%s",
615 >      sendto_one(server, "NICK %s %d %lu %s %s %s %s :%s",
616                   source_p->name, source_p->hopcount+1,
617                   (unsigned long)source_p->tsinfo,
618                   ubuf, source_p->username, source_p->host,
619                   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    }
620    }
621   }
622  
# Line 837 | Line 801 | do_local_user(const char *nick, struct C
801  
802    strlcpy(source_p->info, realname, sizeof(source_p->info));
803  
804 +  /* stash for later */
805 +  strlcpy(source_p->client_host, host, sizeof(source_p->client_host));
806 +  strlcpy(source_p->client_server, server, sizeof(source_p->client_server));
807 +
808    if (!IsGotId(source_p))
809    {
810      /* save the username in the client
# Line 858 | Line 826 | do_local_user(const char *nick, struct C
826   static void *
827   change_simple_umode(va_list args)
828   {
829 +  struct Client *client_p;
830    struct Client *source_p;
831    int what;
832    unsigned int flag;
833  
834 <  va_arg(args, struct Client *);
834 >  client_p = va_arg(args, struct Client *);
835    source_p = va_arg(args, struct Client *);
836    what = va_arg(args, int);
837    flag = va_arg(args, unsigned int);
# Line 1048 | Line 1017 | set_user_mode(struct Client *client_p, s
1017   /* send_umode()
1018   * send the MODE string for user (user) to connection client_p
1019   * -avalon
1020 + *
1021 + * inputs       - client_p
1022 + *              - source_p
1023 + *              - int old
1024 + *              - sendmask mask of modes to send
1025 + *              - suplied umode_buf
1026 + * output       - NONE
1027   */
1028   void
1029   send_umode(struct Client *client_p, struct Client *source_p,
# Line 1113 | Line 1089 | void
1089   send_umode_out(struct Client *client_p, struct Client *source_p,
1090                 unsigned int old)
1091   {
1092 <  char buf[IRCD_BUFSIZE];
1092 >  char buf[IRCD_BUFSIZE] = { '\0' };
1093    dlink_node *ptr = NULL;
1094  
1095    send_umode(NULL, source_p, old, IsOperHiddenAdmin(source_p) ?
1096               SEND_UMODES & ~UMODE_ADMIN : SEND_UMODES, buf);
1097  
1098 <  if (*buf)
1098 >  if (buf[0])
1099    {
1100      DLINK_FOREACH(ptr, serv_list.head)
1101      {
1102        struct Client *target_p = ptr->data;
1103  
1104        if ((target_p != client_p) && (target_p != source_p))
1105 <      {
1106 <        if ((!(ServerInfo.hub && IsCapable(target_p, CAP_LL))) ||
1107 <            (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 <      }
1105 >        sendto_one(target_p, ":%s MODE %s :%s",
1106 >                   ID_or_name(source_p, target_p),
1107 >                   ID_or_name(source_p, target_p), buf);
1108      }
1109    }
1110  
# Line 1207 | Line 1178 | user_welcome(struct Client *source_p)
1178   static int
1179   check_xline(struct Client *source_p)
1180   {
1181 <  struct ConfItem *conf;
1182 <  struct MatchItem *xconf;
1212 <  const char *reason;
1181 >  struct ConfItem *conf = NULL;
1182 >  const char *reason = NULL;
1183  
1184 <  if ((conf = find_matching_name_conf(XLINE_TYPE, source_p->info,
1185 <                                      NULL, NULL, 0)) != NULL)
1184 >  if ((conf = find_matching_name_conf(XLINE_TYPE, source_p->info, NULL, NULL, 0)) ||
1185 >      (conf = find_matching_name_conf(RXLINE_TYPE, source_p->info, NULL, NULL, 0)))
1186    {
1187 <    xconf = map_to_conf(conf);
1188 <    xconf->count++;
1187 >    struct MatchItem *reg = map_to_conf(conf);
1188 >
1189 >    ++reg->count;
1190  
1191 <    if (xconf->reason != NULL)
1192 <      reason = xconf->reason;
1191 >    if (reg->reason != NULL)
1192 >      reason = reg->reason;
1193      else
1194        reason = "No Reason";
1195  
# Line 1228 | Line 1199 | check_xline(struct Client *source_p)
1199                           get_client_name(source_p, HIDE_IP),
1200                           source_p->sockhost);
1201  
1202 <    ServerStats->is_ref++;      
1202 >    ++ServerStats.is_ref;
1203      if (REJECT_HOLD_TIME > 0)
1204      {
1205        sendto_one(source_p, ":%s NOTICE %s :Bad user info",
# Line 1244 | Line 1215 | check_xline(struct Client *source_p)
1215    return 0;
1216   }
1217  
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
1218   /* oper_up()
1219   *
1220   * inputs       - pointer to given client to oper
# Line 1304 | Line 1244 | oper_up(struct Client *source_p)
1244      source_p->umodes |= (UMODE_SERVNOTICE|UMODE_OPERWALL|
1245                           UMODE_WALLOP|UMODE_LOCOPS);
1246  
1247 +  if (!(old & UMODE_INVISIBLE) && IsInvisible(source_p))
1248 +    ++Count.invisi;
1249 +  if ((old & UMODE_INVISIBLE) && !IsInvisible(source_p))
1250 +    --Count.invisi;
1251 +
1252    assert(dlinkFind(&oper_list, source_p) == NULL);
1253    dlinkAdd(source_p, make_dlink_node(), &oper_list);
1254  
# Line 1325 | Line 1270 | oper_up(struct Client *source_p)
1270    send_message_file(source_p, &ConfigFileEntry.opermotd);
1271   }
1272  
1273 < /*
1274 < * Quick and dirty UID code for new proposed SID on EFnet
1275 < *
1276 < */
1273 > static char new_uid[TOTALSIDUID + 1];     /* allow for \0 */
1274 >
1275 > int
1276 > valid_sid(const char *sid)
1277 > {
1278  
1279 < static char new_uid[TOTALSIDUID+1];     /* allow for \0 */
1280 < static void add_one_to_uid(int i);
1279 >  if (strlen(sid) == IRC_MAXSID)
1280 >    if (IsDigit(*sid))
1281 >      if (IsAlNum(*(sid + 1)) && IsAlNum(*(sid + 2)))
1282 >        return 1;
1283 >
1284 >  return 0;
1285 > }
1286  
1287   /*
1288   * init_uid()
# Line 1351 | Line 1302 | init_uid(void)
1302  
1303    if (ServerInfo.sid != NULL)
1304    {
1305 <    memcpy(new_uid, ServerInfo.sid, IRCD_MIN(strlen(ServerInfo.sid),
1306 <                                             IRC_MAXSID));
1307 <    memcpy(&me.id, ServerInfo.sid, IRCD_MIN(strlen(ServerInfo.sid),
1357 <                                            IRC_MAXSID));
1305 >    strlcpy(new_uid, ServerInfo.sid, sizeof(new_uid));
1306 >    strlcpy(me.id, ServerInfo.sid, sizeof(me.id));
1307 >
1308      hash_add_id(&me);
1309    }
1310  
# Line 1362 | Line 1312 | init_uid(void)
1312      if (new_uid[i] == '\0')
1313        new_uid[i] = 'A';
1314  
1315 <  /* XXX if IRC_MAXUID != 6, this will have to be rewritten */
1315 >  /* NOTE: if IRC_MAXUID != 6, this will have to be rewritten */
1316    /* Yes nenolod, I have known it was off by one ever since I wrote it
1317     * But *JUST* for you, though, it really doesn't look as *pretty*
1318     * -Dianora
1319     */
1320 <  memcpy(new_uid+IRC_MAXSID, "AAAAA@", IRC_MAXUID);
1320 >  memcpy(new_uid + IRC_MAXSID, "AAAAA@", IRC_MAXUID);
1321  
1322    entering_umode_cb = register_callback("entering_umode", NULL);
1323    umode_cb = register_callback("changing_umode", change_simple_umode);
# Line 1375 | Line 1325 | init_uid(void)
1325   }
1326  
1327   /*
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 /*
1328   * add_one_to_uid
1329   *
1330   * inputs       - index number into new_uid
# Line 1408 | Line 1344 | add_one_to_uid(int i)
1344        new_uid[i] = 'A';
1345        add_one_to_uid(i-1);
1346      }
1347 <    else new_uid[i] = new_uid[i] + 1;
1347 >    else
1348 >      ++new_uid[i];
1349    }
1350    else
1351    {
1352 <    /* XXX if IRC_MAXUID != 6, this will have to be rewritten */
1352 >    /* NOTE: if IRC_MAXUID != 6, this will have to be rewritten */
1353      if (new_uid[i] == 'Z')
1354 <      memcpy(new_uid+IRC_MAXSID, "AAAAAA", IRC_MAXUID);
1354 >      memcpy(new_uid + IRC_MAXSID, "AAAAAA", IRC_MAXUID);
1355      else
1356 <      new_uid[i] = new_uid[i] + 1;
1356 >      ++new_uid[i];
1357    }
1358   }
1359  
1360   /*
1361 + * uid_get
1362 + *
1363 + * inputs       - struct Client *
1364 + * output       - new UID is returned to caller
1365 + * side effects - new_uid is incremented by one.
1366 + */
1367 + static void *
1368 + uid_get(va_list args)
1369 + {
1370 +  add_one_to_uid(TOTALSIDUID - 1);    /* index from 0 */
1371 +  return new_uid;
1372 + }
1373 +
1374 + /*
1375   * init_isupport()
1376   *
1377   * input        - NONE
# Line 1434 | Line 1385 | init_isupport(void)
1385  
1386    add_isupport("CALLERID", NULL, -1);
1387    add_isupport("CASEMAPPING", CASEMAP, -1);
1388 +  add_isupport("DEAF", "D", -1);
1389    add_isupport("KICKLEN", NULL, KICKLEN);
1390    add_isupport("MODES", NULL, MAXMODEPARAMS);
1391    add_isupport("NICKLEN", NULL, NICKLEN-1);

Diff Legend

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