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.3/src/s_user.c (file contents):
Revision 1029 by michael, Sun Nov 8 13:10:50 2009 UTC vs.
Revision 1080 by michael, Wed Mar 10 23:09:36 2010 UTC

# Line 58 | Line 58 | unsigned int MaxClientCount     = 1;
58   unsigned int MaxConnectionCount = 1;
59   struct Callback *entering_umode_cb = NULL;
60   struct Callback *umode_cb = NULL;
61 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 280 | 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,
284 <                    const char *nick, const char *username)
282 > register_local_user(struct Client *source_p)
283   {
284    const struct AccessItem *aconf = NULL;
285    dlink_node *ptr = NULL;
286    dlink_node *m = NULL;
287  
288    assert(source_p != NULL);
289 +  assert(source_p == source_p->from);
290    assert(MyConnect(source_p));
292  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) &&
300 <       source_p->localClient->random_ping == 0)
297 >    if (!IsPingSent(source_p) && source_p->localClient->random_ping == 0)
298      {
299        do
300          source_p->localClient->random_ping = genrand_int32();
# Line 317 | 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 333 | 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))
# Line 345 | Line 343 | register_local_user(struct Client *clien
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)
354 <    {
351 >    for (; *p && i < USERLEN; ++p)
352        if (*p != '[')
353          source_p->username[i++] = *p;
357      p++;
358    }
354  
355      source_p->username[i] = '\0';
356    }
# Line 383 | 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(client_p))
381 >  if (IsDead(source_p))
382      return;
383  
384    /* Limit clients -
# Line 399 | 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);
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;
# Line 411 | 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);
409 >                         source_p->name, source_p->username, source_p->host);
410      ++ServerStats.is_ref;
411      ircsprintf(tmpstr2, "Invalid username [%s]", source_p->username);
412      exit_client(source_p, &me, tmpstr2);
413      return;
414    }
415  
421  assert(source_p == client_p);
422
416    if (check_xline(source_p))
417      return;
418  
419    if (me.id[0])
420    {
421 <    const char *id = execute_callback(uid_get_cb, source_p);
421 >    const char *id = NULL;
422  
423 <    while (hash_find_id(id) != NULL)
424 <      id = uid_get(NULL);
423 >    while (hash_find_id((id = uid_get())) != NULL)
424 >      ;
425  
426      strlcpy(source_p->id, id, sizeof(source_p->id));
427      hash_add_id(source_p);
# Line 436 | Line 429 | register_local_user(struct Client *clien
429  
430    sendto_realops_flags(UMODE_CCONN, L_ALL,
431                         "Client connecting: %s (%s@%s) [%s] {%s} [%s]",
432 <                       nick, source_p->username, source_p->host,
432 >                       source_p->name, source_p->username, source_p->host,
433                         ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
434                         "255.255.255.255" : source_p->sockhost,
435                         get_client_class(source_p),
# Line 444 | Line 437 | register_local_user(struct Client *clien
437  
438    sendto_realops_flags(UMODE_CCONN_FULL, L_ALL,
439                         "CLICONN %s %s %s %s %s %s %s 0 %s",
440 <                       nick, source_p->username, source_p->host,
440 >                       source_p->name, source_p->username, source_p->host,
441                         ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
442                         "255.255.255.255" : source_p->sockhost,
443                         get_client_class(source_p),
# Line 470 | Line 463 | register_local_user(struct Client *clien
463                             Count.max_loc);
464    }
465  
473  SetClient(source_p);
474
475  source_p->servptr = &me;
476  dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->client_list);
477
466    /* Increment our total user count here */
467    if (++Count.total > Count.max_tot)
468      Count.max_tot = Count.total;
469    ++Count.totalrestartcount;
470  
471 +  assert(source_p->servptr == &me);
472 +  SetClient(source_p);
473 +  dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->client_list);
474 +
475    source_p->localClient->allow_read = MAX_FLOOD_BURST;
476  
477    assert(dlinkFindDelete(&unknown_list, source_p));
# Line 494 | Line 486 | register_local_user(struct Client *clien
486    add_user_host(source_p->username, source_p->host, 0);
487    SetUserHost(source_p);
488  
489 <  introduce_client(client_p, source_p);
489 >  introduce_client(source_p);
490   }
491  
492   /* register_remote_user()
493   *
494 < * inputs       - client_p directly connected client
503 < *              - source_p remote or directly connected client
494 > * inputs       - source_p remote or directly connected client
495   *              - username to register as
496   *              - host name to register as
497   *              - server name
# Line 510 | Line 501 | register_local_user(struct Client *clien
501   *                is introduced by a server.
502   */
503   void
504 < register_remote_user(struct Client *client_p, struct Client *source_p,
504 > register_remote_user(struct Client *source_p,
505                       const char *username, const char *host, const char *server,
506                       const char *realname)
507   {
# Line 537 | Line 528 | register_remote_user(struct Client *clie
528                           "No server %s for user %s[%s@%s] from %s",
529                           server, source_p->name, source_p->username,
530                           source_p->host, source_p->from->name);
531 <    kill_client(client_p, source_p, "%s (Server doesn't exist)", me.name);
531 >    kill_client(source_p->from, source_p, "%s (Server doesn't exist)", me.name);
532  
533      SetKilled(source_p);
534      exit_client(source_p, &me, "Ghosted Client");
# Line 548 | Line 539 | register_remote_user(struct Client *clie
539    {
540      sendto_realops_flags(UMODE_DEBUG, L_ALL,
541                           "Bad User [%s] :%s USER %s@%s %s, != %s[%s]",
542 <                         client_p->name, source_p->name, source_p->username,
542 >                         source_p->from->name, source_p->name, source_p->username,
543                           source_p->host, source_p->servptr->name,
544                           target_p->name, target_p->from->name);
545 <    kill_client(client_p, source_p,
545 >    kill_client(source_p->from, source_p,
546                  "%s (NICK from wrong direction (%s != %s))",
547                  me.name, source_p->servptr->name, target_p->from->name);
548      SetKilled(source_p);
# Line 568 | Line 559 | register_remote_user(struct Client *clie
559    add_user_host(source_p->username, source_p->host, 1);
560    SetUserHost(source_p);
561  
562 <  introduce_client(client_p, source_p);
562 >  introduce_client(source_p);
563   }
564  
565   /* introduce_client()
566   *
567 < * inputs       - client_p
577 < *              - source_p
567 > * inputs       - source_p
568   * output       - NONE
569   * side effects - This common function introduces a client to the rest
570   *                of the net, either from a local client connect or
571   *                from a remote connect.
572   */
573   static void
574 < introduce_client(struct Client *client_p, struct Client *source_p)
574 > introduce_client(struct Client *source_p)
575   {
576    dlink_node *server_node = NULL;
577    static char ubuf[12];
# Line 603 | Line 593 | introduce_client(struct Client *client_p
593    {
594      struct Client *server = server_node->data;
595  
596 <    if (server == client_p)
596 >    if (server == source_p->from)
597          continue;
598  
599      if (IsCapable(server, CAP_TS6) && HasID(source_p))
# Line 639 | Line 629 | valid_hostname(const char *hostname)
629  
630    assert(p != NULL);
631  
632 <  if ('.' == *p || ':' == *p)
632 >  if (*p == '.' || *p == ':')
633      return 0;
634  
635 <  while (*p)
646 <  {
635 >  for (; *p; ++p)
636      if (!IsHostChar(*p))
637        return 0;
649    p++;
650  }
638  
639    return 1;
640   }
# Line 671 | Line 658 | valid_username(const char *username)
658  
659    assert(p != NULL);
660  
661 <  if ('~' == *p)
661 >  if (*p == '~')
662      ++p;
663  
664    /* reject usernames that don't start with an alphanum
# Line 685 | Line 672 | valid_username(const char *username)
672    {
673      if ((*p == '.') && ConfigFileEntry.dots_in_ident)
674      {
675 <      dots++;
689 <
690 <      if (dots > ConfigFileEntry.dots_in_ident)
675 >      if (++dots > ConfigFileEntry.dots_in_ident)
676          return 0;
677 <      if (!IsUserChar(p[1]))
677 >      if (!IsUserChar(*(p + 1)))
678          return 0;
679      }
680      else if (!IsUserChar(*p))
# Line 778 | Line 763 | report_and_set_user_flags(struct Client
763   * side effects -
764   */
765   void
766 < do_local_user(const char *nick, struct Client *client_p, struct Client *source_p,
766 > do_local_user(struct Client *source_p,
767                const char *username, const char *host, const char *server,
768                const char *realname)
769   {
770    assert(source_p != NULL);
771    assert(source_p->username != username);
772 <
788 <  if (source_p == NULL)
789 <    return;
790 <
791 <  if (!IsUnknown(source_p))
792 <  {
793 <    sendto_one(source_p, form_str(ERR_ALREADYREGISTRED),
794 <               me.name, nick);
795 <    return;
796 <  }
772 >  assert(IsUnknown(source_p));
773  
774    source_p->localClient->registration &= ~REG_NEED_USER;
775  
# Line 809 | Line 785 | do_local_user(const char *nick, struct C
785    strlcpy(source_p->client_server, server, sizeof(source_p->client_server));
786  
787    if (!IsGotId(source_p))
812  {
813    /* save the username in the client
814     * If you move this you'll break ping cookies..you've been warned
815     */
788      strlcpy(source_p->username, username, sizeof(source_p->username));
817  }
789  
790    if (!source_p->localClient->registration)
791 <    /* NICK already received, now I have USER... */
821 <    register_local_user(client_p, source_p, source_p->name, username);
791 >    register_local_user(source_p);
792   }
793  
794   /* change_simple_umode()
# Line 1324 | Line 1294 | init_uid(void)
1294  
1295    entering_umode_cb = register_callback("entering_umode", NULL);
1296    umode_cb = register_callback("changing_umode", change_simple_umode);
1327  uid_get_cb = register_callback("uid_get", uid_get);
1297   }
1298  
1299   /*
# Line 1367 | Line 1336 | add_one_to_uid(int i)
1336   * output       - new UID is returned to caller
1337   * side effects - new_uid is incremented by one.
1338   */
1339 < static void *
1340 < uid_get(va_list args)
1339 > static const char *
1340 > uid_get(void)
1341   {
1342    add_one_to_uid(TOTALSIDUID - 1);    /* index from 0 */
1343    return new_uid;

Diff Legend

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