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 889 by michael, Thu Nov 1 12:59:05 2007 UTC vs.
ircd-hybrid-7.3/src/s_user.c (file contents), Revision 1126 by michael, Sun Feb 20 14:30:12 2011 UTC

# Line 23 | Line 23
23   */
24  
25   #include "stdinc.h"
26 < #include "tools.h"
26 > #include "list.h"
27   #include "s_user.h"
28   #include "s_misc.h"
29   #include "channel.h"
# 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"
40 #include "list.h"
39   #include "listener.h"
40   #include "motd.h"
41   #include "numeric.h"
42   #include "s_conf.h"
43   #include "s_log.h"
44   #include "s_serv.h"
47 #include "s_stats.h"
45   #include "send.h"
46   #include "supported.h"
47   #include "whowas.h"
48   #include "memory.h"
49   #include "packet.h"
50 + #include "rng_mt.h"
51   #include "userhost.h"
52   #include "hook.h"
53   #include "s_misc.h"
54   #include "msg.h"
57 #include "pcre.h"
55   #include "watch.h"
56  
57 < int MaxClientCount     = 1;
58 < int MaxConnectionCount = 1;
57 > unsigned int MaxClientCount     = 1;
58 > unsigned int MaxConnectionCount = 1;
59   struct Callback *entering_umode_cb = NULL;
60   struct Callback *umode_cb = NULL;
64 struct Callback *uid_get_cb = NULL;
61  
62   static char umode_buffer[IRCD_BUFSIZE];
63  
64   static void user_welcome(struct Client *);
65   static void report_and_set_user_flags(struct Client *, const struct AccessItem *);
66   static int check_xline(struct Client *);
67 < static void introduce_client(struct Client *, struct Client *);
68 < static void *uid_get(va_list);
67 > static void introduce_client(struct Client *);
68 > static const char *uid_get(void);
69  
70   /* Used for building up the isupport string,
71   * used with init_isupport, add_isupport, delete_isupport
# Line 166 | Line 162 | assemble_umode_buffer(void)
162    unsigned int idx = 0;
163    char *umode_buffer_ptr = umode_buffer;
164  
165 <  for (; idx < (sizeof(user_modes) / sizeof(int)); ++idx)
165 >  for (; idx < (sizeof(user_modes) / sizeof(user_modes[0])); ++idx)
166      if (user_modes[idx])
167        *umode_buffer_ptr++ = idx;
168  
# Line 283 | Line 279 | show_isupport(struct Client *source_p)
279   **         nick from local user or kill him/her...
280   */
281   void
282 < register_local_user(struct Client *client_p, struct Client *source_p,
287 <                    const char *nick, const char *username)
282 > register_local_user(struct Client *source_p)
283   {
284 +  const char *id = NULL;
285    const struct AccessItem *aconf = NULL;
290  char ipaddr[HOSTIPLEN];
286    dlink_node *ptr = NULL;
292  dlink_node *m = NULL;
287  
288    assert(source_p != NULL);
289 +  assert(source_p == source_p->from);
290    assert(MyConnect(source_p));
296  assert(source_p->username != username);
291    assert(!source_p->localClient->registration);
292  
293 <  ClearCap(client_p, CAP_TS6);
293 >  ClearCap(source_p, CAP_TS6);
294  
295    if (ConfigFileEntry.ping_cookie)
296    {
297 <    if (!IsPingSent(source_p) &&
304 <       source_p->localClient->random_ping == 0)
297 >    if (!IsPingSent(source_p) && source_p->localClient->random_ping == 0)
298      {
299 <      source_p->localClient->random_ping = (unsigned long)rand();
300 <      sendto_one(source_p, "PING :%lu",
299 >      do
300 >        source_p->localClient->random_ping = genrand_int32();
301 >      while (!source_p->localClient->random_ping);
302 >
303 >      sendto_one(source_p, "PING :%u",
304                   source_p->localClient->random_ping);
305        SetPingSent(source_p);
306        return;
# Line 318 | Line 314 | register_local_user(struct Client *clien
314    /* Straight up the maximum rate of flooding... */
315    source_p->localClient->allow_read = MAX_FLOOD_BURST;
316  
317 <  if (!execute_callback(client_check_cb, source_p, username))
317 >  if (!execute_callback(client_check_cb, source_p, source_p->username))
318      return;
319  
320    if (valid_hostname(source_p->host) == 0)
# Line 334 | Line 330 | register_local_user(struct Client *clien
330  
331    if (!IsGotId(source_p))
332    {
333 <    const char *p = NULL;
333 >    char username[USERLEN + 1];
334 >    const char *p = username;
335      unsigned int i = 0;
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");
343        return;
344      }
345  
346 <    p = username;
346 >    strlcpy(username, source_p->username, sizeof(username));
347  
348      if (!IsNoTilde(aconf))
349        source_p->username[i++] = '~';
350  
351 <    while (*p && i < USERLEN)
355 <    {
351 >    for (; *p && i < USERLEN; ++p)
352        if (*p != '[')
353          source_p->username[i++] = *p;
358      p++;
359    }
354  
355      source_p->username[i] = '\0';
356    }
# Line 368 | Line 362 | register_local_user(struct Client *clien
362  
363      if (!match_conf_password(pass, aconf))
364      {
365 <      ServerStats->is_ref++;
365 >      ++ServerStats.is_ref;
366        sendto_one(source_p, form_str(ERR_PASSWDMISMATCH),
367                   me.name, source_p->name);
368        exit_client(source_p, &me, "Bad Password");
# Line 384 | Line 378 | register_local_user(struct Client *clien
378    /* report if user has &^>= etc. and set flags as needed in source_p */
379    report_and_set_user_flags(source_p, aconf);
380  
381 +  if (IsDead(source_p))
382 +    return;
383 +
384    /* Limit clients -
385     * We want to be able to have servers and F-line clients
386     * connect, so save room for "buffer" connections.
# Line 397 | Line 394 | register_local_user(struct Client *clien
394    {
395      sendto_realops_flags(UMODE_FULL, L_ALL,
396                           "Too many clients, rejecting %s[%s].",
397 <                         nick, source_p->host);
398 <    ServerStats->is_ref++;
397 >                         source_p->name, source_p->host);
398 >    ++ServerStats.is_ref;
399      exit_client(source_p, &me, "Sorry, server is full - try later");
400      return;
401    }
# Line 409 | Line 406 | register_local_user(struct Client *clien
406      char tmpstr2[IRCD_BUFSIZE];
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++;
411 <    ircsprintf(tmpstr2, "Invalid username [%s]", source_p->username);
409 >                         source_p->name, source_p->username, source_p->host);
410 >    ++ServerStats.is_ref;
411 >    snprintf(tmpstr2, sizeof(tmpstr2), "Invalid username [%s]",
412 >             source_p->username);
413      exit_client(source_p, &me, tmpstr2);
414      return;
415    }
416  
419  assert(source_p == client_p);
420
417    if (check_xline(source_p))
418      return;
419  
420 <  if (IsDead(client_p))
421 <    return;
426 <
427 <  if (me.id[0])
428 <  {
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 <
434 <    strlcpy(source_p->id, id, sizeof(source_p->id));
435 <    hash_add_id(source_p);
436 <  }
420 >  while (hash_find_id((id = uid_get())) != NULL)
421 >    ;
422  
423 <  irc_getnameinfo((struct sockaddr *)&source_p->localClient->ip,
424 <                  source_p->localClient->ip.ss_len, ipaddr,
440 <                  HOSTIPLEN, NULL, 0, NI_NUMERICHOST);
423 >  strlcpy(source_p->id, id, sizeof(source_p->id));
424 >  hash_add_id(source_p);
425  
426    sendto_realops_flags(UMODE_CCONN, L_ALL,
427                         "Client connecting: %s (%s@%s) [%s] {%s} [%s]",
428 <                       nick, source_p->username, source_p->host,
428 >                       source_p->name, source_p->username, source_p->host,
429                         ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
430 <                       "255.255.255.255" : ipaddr, get_client_class(source_p),
430 >                       "255.255.255.255" : source_p->sockhost,
431 >                       get_client_class(source_p),
432                         source_p->info);
433  
434    sendto_realops_flags(UMODE_CCONN_FULL, L_ALL,
435                         "CLICONN %s %s %s %s %s %s %s 0 %s",
436 <                       nick, source_p->username, source_p->host,
436 >                       source_p->name, source_p->username, source_p->host,
437                         ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
438 <                       "255.255.255.255" : ipaddr,
438 >                       "255.255.255.255" : source_p->sockhost,
439                         get_client_class(source_p),
440                         ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
441 <                           "<hidden>" : source_p->client_host,
441 >                           "<hidden>" : source_p->localClient->client_host,
442                         ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
443 <                           "<hidden>" : source_p->client_server,
443 >                           "<hidden>" : source_p->localClient->client_server,
444                         source_p->info);
445  
446  
462  /* If they have died in send_* don't do anything. */
463  if (IsDead(source_p))
464    return;
465
447    if (ConfigFileEntry.invisible_on_connect)
448    {
449      source_p->umodes |= UMODE_INVISIBLE;
450 <    Count.invisi++;
450 >    ++Count.invisi;
451    }
452  
453    if ((++Count.local) > Count.max_loc)
# Line 478 | Line 459 | register_local_user(struct Client *clien
459                             Count.max_loc);
460    }
461  
481  SetClient(source_p);
482
483  source_p->servptr = &me;
484  dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->client_list);
485
462    /* Increment our total user count here */
463    if (++Count.total > Count.max_tot)
464      Count.max_tot = Count.total;
465 <  Count.totalrestartcount++;
465 >  ++Count.totalrestartcount;
466 >
467 >  assert(source_p->servptr == &me);
468 >  SetClient(source_p);
469 >  dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->client_list);
470  
471    source_p->localClient->allow_read = MAX_FLOOD_BURST;
472  
473 <  if ((m = dlinkFindDelete(&unknown_list, source_p)) != NULL)
474 <  {
475 <    free_dlink_node(m);
476 <    dlinkAdd(source_p, &source_p->localClient->lclient_node, &local_client_list);
497 <  }
498 <  else assert(0);
473 >  assert(dlinkFind(&unknown_list, source_p));
474 >
475 >  dlink_move_node(&source_p->localClient->lclient_node,
476 >                  &unknown_list, &local_client_list);
477  
478    user_welcome(source_p);
479    add_user_host(source_p->username, source_p->host, 0);
480    SetUserHost(source_p);
481  
482 <  introduce_client(client_p, source_p);
482 >  introduce_client(source_p);
483   }
484  
485   /* register_remote_user()
486   *
487 < * inputs       - client_p directly connected client
510 < *              - source_p remote or directly connected client
487 > * inputs       - source_p remote or directly connected client
488   *              - username to register as
489   *              - host name to register as
490   *              - server name
# Line 517 | Line 494 | register_local_user(struct Client *clien
494   *                is introduced by a server.
495   */
496   void
497 < register_remote_user(struct Client *client_p, struct Client *source_p,
497 > register_remote_user(struct Client *source_p,
498                       const char *username, const char *host, const char *server,
499                       const char *realname)
500   {
# Line 527 | Line 504 | register_remote_user(struct Client *clie
504    assert(source_p->username != username);
505  
506    strlcpy(source_p->host, host, sizeof(source_p->host));
530  strlcpy(source_p->info, realname, sizeof(source_p->info));
507    strlcpy(source_p->username, username, sizeof(source_p->username));
508  
509    /*
# Line 545 | Line 521 | register_remote_user(struct Client *clie
521                           "No server %s for user %s[%s@%s] from %s",
522                           server, source_p->name, source_p->username,
523                           source_p->host, source_p->from->name);
524 <    kill_client(client_p, source_p, "%s (Server doesn't exist)", me.name);
524 >    kill_client(source_p->from, source_p, "%s (Server doesn't exist)", me.name);
525  
526      SetKilled(source_p);
527      exit_client(source_p, &me, "Ghosted Client");
# Line 556 | Line 532 | register_remote_user(struct Client *clie
532    {
533      sendto_realops_flags(UMODE_DEBUG, L_ALL,
534                           "Bad User [%s] :%s USER %s@%s %s, != %s[%s]",
535 <                         client_p->name, source_p->name, source_p->username,
535 >                         source_p->from->name, source_p->name, source_p->username,
536                           source_p->host, source_p->servptr->name,
537                           target_p->name, target_p->from->name);
538 <    kill_client(client_p, source_p,
538 >    kill_client(source_p->from, source_p,
539                  "%s (NICK from wrong direction (%s != %s))",
540                  me.name, source_p->servptr->name, target_p->from->name);
541      SetKilled(source_p);
# Line 576 | Line 552 | register_remote_user(struct Client *clie
552    add_user_host(source_p->username, source_p->host, 1);
553    SetUserHost(source_p);
554  
555 <  introduce_client(client_p, source_p);
555 >  introduce_client(source_p);
556   }
557  
558   /* introduce_client()
559   *
560 < * inputs       - client_p
585 < *              - source_p
560 > * inputs       - source_p
561   * output       - NONE
562   * side effects - This common function introduces a client to the rest
563   *                of the net, either from a local client connect or
564   *                from a remote connect.
565   */
566   static void
567 < introduce_client(struct Client *client_p, struct Client *source_p)
567 > introduce_client(struct Client *source_p)
568   {
569    dlink_node *server_node = NULL;
570    static char ubuf[12];
# Line 611 | Line 586 | introduce_client(struct Client *client_p
586    {
587      struct Client *server = server_node->data;
588  
589 <    if (server == client_p)
589 >    if (server == source_p->from)
590          continue;
591  
592      if (IsCapable(server, CAP_TS6) && HasID(source_p))
# Line 647 | Line 622 | valid_hostname(const char *hostname)
622  
623    assert(p != NULL);
624  
625 <  if ('.' == *p || ':' == *p)
625 >  if (*p == '.' || *p == ':')
626      return 0;
627  
628 <  while (*p)
654 <  {
628 >  for (; *p; ++p)
629      if (!IsHostChar(*p))
630        return 0;
657    p++;
658  }
631  
632    return 1;
633   }
# Line 679 | Line 651 | valid_username(const char *username)
651  
652    assert(p != NULL);
653  
654 <  if ('~' == *p)
654 >  if (*p == '~')
655      ++p;
656  
657    /* reject usernames that don't start with an alphanum
# Line 693 | Line 665 | valid_username(const char *username)
665    {
666      if ((*p == '.') && ConfigFileEntry.dots_in_ident)
667      {
668 <      dots++;
697 <
698 <      if (dots > ConfigFileEntry.dots_in_ident)
668 >      if (++dots > ConfigFileEntry.dots_in_ident)
669          return 0;
670 <      if (!IsUserChar(p[1]))
670 >      if (!IsUserChar(*(p + 1)))
671          return 0;
672      }
673      else if (!IsUserChar(*p))
# Line 779 | Line 749 | report_and_set_user_flags(struct Client
749    }
750   }
751  
782 /* do_local_user()
783 *
784 * inputs       -
785 * output       - NONE
786 * side effects -
787 */
788 void
789 do_local_user(const char *nick, struct Client *client_p, struct Client *source_p,
790              const char *username, const char *host, const char *server,
791              const char *realname)
792 {
793  assert(source_p != NULL);
794  assert(source_p->username != username);
795
796  if (source_p == NULL)
797    return;
798
799  if (!IsUnknown(source_p))
800  {
801    sendto_one(source_p, form_str(ERR_ALREADYREGISTRED),
802               me.name, nick);
803    return;
804  }
805
806  source_p->localClient->registration &= ~REG_NEED_USER;
807
808  /*
809   * don't take the clients word for it, ever
810   */
811  source_p->servptr = &me;
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
822     * If you move this you'll break ping cookies..you've been warned
823     */
824    strlcpy(source_p->username, username, sizeof(source_p->username));
825  }
826
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);
830 }
831
752   /* change_simple_umode()
753   *
754   * this callback can be hooked to allow special handling of
# Line 888 | Line 808 | set_user_mode(struct Client *client_p, s
808       return;
809    }
810  
811 <  if (source_p != target_p || target_p->from != source_p->from)
811 >  if (source_p != target_p)
812    {
813       sendto_one(source_p, form_str(ERR_USERSDONTMATCH),
814                  me.name, source_p->name);
# Line 946 | Line 866 | set_user_mode(struct Client *client_p, s
866                break;
867  
868              ClearOper(source_p);
949            source_p->umodes &= ~ConfigFileEntry.oper_only_umodes;
869              Count.oper--;
870  
871              if (MyConnect(source_p))
# Line 955 | Line 874 | set_user_mode(struct Client *client_p, s
874  
875                detach_conf(source_p, OPER_TYPE);
876                ClearOperFlags(source_p);
877 +              source_p->umodes &= ~ConfigFileEntry.oper_only_umodes;
878  
879                if ((dm = dlinkFindDelete(&oper_list, source_p)) != NULL)
880                  free_dlink_node(dm);
# Line 1040 | Line 960 | void
960   send_umode(struct Client *client_p, struct Client *source_p,
961             unsigned int old, unsigned int sendmask, char *umode_buf)
962   {
963 +  char *m = umode_buf;
964    int what = 0;
965    unsigned int i;
966    unsigned int flag;
1046  char *m = umode_buf;
967  
968    /*
969     * build a string in umode_buf to represent the change in the user's
# Line 1163 | Line 1083 | user_welcome(struct Client *source_p)
1083  
1084    if (ConfigFileEntry.short_motd)
1085    {
1086 <    sendto_one(source_p, "NOTICE %s :*** Notice -- motd was last changed at %s",
1087 <               source_p->name, ConfigFileEntry.motd.lastChangedDate);
1086 >    sendto_one(source_p, ":%s NOTICE %s :*** Notice -- motd was last changed at %s",
1087 >               me.name, source_p->name, ConfigFileEntry.motd.lastChangedDate);
1088      sendto_one(source_p,
1089 <               "NOTICE %s :*** Notice -- Please read the motd if you haven't "
1090 <               "read it", source_p->name);
1089 >               ":%s NOTICE %s :*** Notice -- Please read the motd if you haven't "
1090 >               "read it", me.name, source_p->name);
1091      sendto_one(source_p, form_str(RPL_MOTDSTART),
1092                 me.name, source_p->name, me.name);
1093      sendto_one(source_p, form_str(RPL_MOTD),
# Line 1210 | Line 1130 | check_xline(struct Client *source_p)
1130                           get_client_name(source_p, HIDE_IP),
1131                           source_p->sockhost);
1132  
1133 <    ServerStats->is_ref++;
1133 >    ++ServerStats.is_ref;
1134      if (REJECT_HOLD_TIME > 0)
1135      {
1136        sendto_one(source_p, ":%s NOTICE %s :Bad user info",
# Line 1286 | Line 1206 | static char new_uid[TOTALSIDUID + 1];
1206   int
1207   valid_sid(const char *sid)
1208   {
1289
1209    if (strlen(sid) == IRC_MAXSID)
1210      if (IsDigit(*sid))
1211        if (IsAlNum(*(sid + 1)) && IsAlNum(*(sid + 2)))
# Line 1311 | Line 1230 | init_uid(void)
1230  
1231    memset(new_uid, 0, sizeof(new_uid));
1232  
1233 <  if (ServerInfo.sid != NULL)
1315 <  {
1233 >  if (!EmptyString(ServerInfo.sid))
1234      strlcpy(new_uid, ServerInfo.sid, sizeof(new_uid));
1317    strlcpy(me.id, ServerInfo.sid, sizeof(me.id));
1318
1319    hash_add_id(&me);
1320  }
1235  
1236 <  for (i = 0; i < IRC_MAXSID; i++)
1236 >  for (i = 0; i < IRC_MAXSID; ++i)
1237      if (new_uid[i] == '\0')
1238        new_uid[i] = 'A';
1239  
# Line 1332 | Line 1246 | init_uid(void)
1246  
1247    entering_umode_cb = register_callback("entering_umode", NULL);
1248    umode_cb = register_callback("changing_umode", change_simple_umode);
1335  uid_get_cb = register_callback("uid_get", uid_get);
1249   }
1250  
1251   /*
# Line 1375 | Line 1288 | add_one_to_uid(int i)
1288   * output       - new UID is returned to caller
1289   * side effects - new_uid is incremented by one.
1290   */
1291 < static void *
1292 < uid_get(va_list args)
1291 > static const char *
1292 > uid_get(void)
1293   {
1294    add_one_to_uid(TOTALSIDUID - 1);    /* index from 0 */
1295    return new_uid;

Diff Legend

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