ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/client.c
(Generate patch)

Comparing ircd-hybrid/trunk/src/client.c (file contents):
Revision 2185 by michael, Tue Jun 4 12:29:18 2013 UTC vs.
Revision 3247 by michael, Sun Mar 30 17:54:34 2014 UTC

# Line 1 | Line 1
1   /*
2 < *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 < *  client.c: Controls clients.
2 > *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (C) 2002 by the past and present ircd coders, and others.
4 > *  Copyright (c) 1997-2014 ircd-hybrid development team
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 18 | Line 17
17   *  along with this program; if not, write to the Free Software
18   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
19   *  USA
20 < *
21 < *  $Id$
20 > */
21 >
22 > /*! \file client.c
23 > * \brief Controls clients.
24 > * \version $Id$
25   */
26  
27   #include "stdinc.h"
# Line 52 | Line 54
54   #include "userhost.h"
55   #include "watch.h"
56   #include "rng_mt.h"
57 + #include "parse.h"
58  
59   dlink_list listing_client_list = { NULL, NULL, 0 };
60   /* Pointer to beginning of Client list */
# Line 75 | Line 78 | static dlink_node *eac_next;  /* next ab
78  
79   static void check_pings_list(dlink_list *);
80   static void check_unknowns_list(void);
78 static void ban_them(struct Client *, struct MaskItem *);
81  
82  
83   /* client_init()
# Line 117 | Line 119 | make_client(struct Client *from)
119  
120    memset(client_p, 0, sizeof(*client_p));
121  
122 <  if (from == NULL)
122 >  if (!from)
123    {
124      client_p->from                      = client_p; /* 'from' of local client is self! */
125      client_p->localClient               = mp_pool_get(lclient_pool);
# Line 137 | Line 139 | make_client(struct Client *from)
139  
140    client_p->idhnext = client_p;
141    client_p->hnext  = client_p;
142 <  client_p->status = STAT_UNKNOWN;
142 >  SetUnknown(client_p);
143    strcpy(client_p->username, "unknown");
144    strcpy(client_p->svid, "0");
145  
# Line 154 | Line 156 | make_client(struct Client *from)
156   static void
157   free_client(struct Client *client_p)
158   {
159 <  assert(client_p != NULL);
159 >  assert(client_p);
160    assert(client_p != &me);
161    assert(client_p->hnext == client_p);
162    assert(client_p->idhnext == client_p);
# Line 164 | Line 166 | free_client(struct Client *client_p)
166    assert(!IsServer(client_p) || (IsServer(client_p) && client_p->serv));
167  
168    MyFree(client_p->serv);
169 +  MyFree(client_p->certfp);
170  
171    if (MyConnect(client_p))
172    {
173      assert(client_p->localClient->invited.head == NULL);
174      assert(dlink_list_length(&client_p->localClient->invited) == 0);
175 <    assert(dlink_list_length(&client_p->localClient->watches) == 0);
175 >    assert(dlink_list_length(&client_p->localClient->watches) == 0);
176      assert(IsClosing(client_p) && IsDead(client_p));
177  
178      MyFree(client_p->localClient->response);
# Line 182 | Line 185 | free_client(struct Client *client_p)
185      {
186        assert(0 < client_p->localClient->listener->ref_count);
187        if (0 == --client_p->localClient->listener->ref_count &&
188 <          !client_p->localClient->listener->active)
188 >          !client_p->localClient->listener->active)
189          free_listener(client_p->localClient->listener);
190      }
191  
# Line 201 | Line 204 | free_client(struct Client *client_p)
204   *
205   * inputs       - NOT USED (from event)
206   * output       - next time_t when check_pings() should be called again
207 < * side effects -
207 > * side effects -
208   *
209   *
210   * A PING can be sent to clients as necessary.
# Line 223 | Line 226 | free_client(struct Client *client_p)
226  
227   static void
228   check_pings(void *notused)
229 < {              
229 > {
230    check_pings_list(&local_client_list);
231    check_pings_list(&serv_list);
232    check_unknowns_list();
# Line 233 | Line 236 | check_pings(void *notused)
236   *
237   * inputs       - pointer to list to check
238   * output       - NONE
239 < * side effects -
239 > * side effects -
240   */
241   static void
242   check_pings_list(dlink_list *list)
243   {
244 <  char scratch[32];        /* way too generous but... */
244 >  char scratch[IRCD_BUFSIZE];
245    int ping = 0;      /* ping time value from client */
246    dlink_node *ptr = NULL, *next_ptr = NULL;
247  
# Line 253 | Line 256 | check_pings_list(dlink_list *list)
256      if (IsDead(client_p))
257      {
258        /* Ignore it, its been exited already */
259 <      continue;
259 >      continue;
260      }
261  
262      if (!IsRegistered(client_p))
# Line 296 | Line 299 | check_pings_list(dlink_list *list)
299  
300            snprintf(scratch, sizeof(scratch), "Ping timeout: %d seconds",
301                     (int)(CurrentTime - client_p->localClient->lasttime));
302 <          exit_client(client_p, &me, scratch);
302 >          exit_client(client_p, scratch);
303          }
304        }
305      }
# Line 312 | Line 315 | check_pings_list(dlink_list *list)
315   static void
316   check_unknowns_list(void)
317   {
318 <  dlink_node *ptr, *next_ptr;
318 >  dlink_node *ptr = NULL, *ptr_next = NULL;
319  
320 <  DLINK_FOREACH_SAFE(ptr, next_ptr, unknown_list.head)
320 >  DLINK_FOREACH_SAFE(ptr, ptr_next, unknown_list.head)
321    {
322      struct Client *client_p = ptr->data;
323  
# Line 323 | Line 326 | check_unknowns_list(void)
326       * for > 30s, close them.
327       */
328      if (IsAuthFinished(client_p) && (CurrentTime - client_p->localClient->firsttime) > 30)
329 <      exit_client(client_p, &me, "Registration timed out");
329 >      exit_client(client_p, "Registration timed out");
330    }
331   }
332  
# Line 334 | Line 337 | check_unknowns_list(void)
337   * side effects - Check all connections for a pending kline against the
338   *                client, exit the client if a kline matches.
339   */
340 < void
340 > void
341   check_conf_klines(void)
342 < {              
342 > {
343    struct Client *client_p = NULL;       /* current local client_p being examined */
344    struct MaskItem *conf = NULL;
345    dlink_node *ptr, *next_ptr;
# Line 351 | Line 354 | check_conf_klines(void)
354        continue;
355  
356      if ((conf = find_dline_conf(&client_p->localClient->ip,
357 <                                  client_p->localClient->aftype)) != NULL)
357 >                                  client_p->localClient->aftype)))
358      {
359        if (conf->type == CONF_EXEMPT)
360          continue;
361  
362 <      ban_them(client_p, conf);
362 >      conf_try_ban(client_p, conf);
363        continue; /* and go examine next fd/client_p */
364      }
365  
366 <    if (ConfigFileEntry.glines && (conf = find_gline(client_p)))
366 >    if (ConfigFileEntry.glines)
367      {
368 <      if (IsExemptKline(client_p) ||
369 <          IsExemptGline(client_p))
368 >      if ((conf = find_conf_by_address(client_p->host, &client_p->localClient->ip,
369 >                                       CONF_GLINE, client_p->localClient->aftype,
370 >                                       client_p->username, NULL, 1)))
371        {
372 <        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
373 <                             "GLINE over-ruled for %s, client is %sline_exempt",
370 <                             get_client_name(client_p, HIDE_IP), IsExemptKline(client_p) ? "k" : "g");
372 >        conf_try_ban(client_p, conf);
373 >        /* and go examine next fd/client_p */
374          continue;
375        }
376 +    }
377  
378 <      ban_them(client_p, conf);
379 <      /* and go examine next fd/client_p */    
380 <      continue;
377 <    }
378 <
379 <    if ((conf = find_kill(client_p)) != NULL)
378 >    if ((conf = find_conf_by_address(client_p->host, &client_p->localClient->ip,
379 >                                     CONF_KLINE, client_p->localClient->aftype,
380 >                                     client_p->username, NULL, 1)))
381      {
382 <      if (IsExemptKline(client_p))
383 <      {
383 <        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
384 <                             "KLINE over-ruled for %s, client is kline_exempt",
385 <                             get_client_name(client_p, HIDE_IP));
386 <        continue;
387 <      }
388 <
389 <      ban_them(client_p, conf);
390 <      continue;
382 >      conf_try_ban(client_p, conf);
383 >      continue;
384      }
385  
386      if ((conf = find_matching_name_conf(CONF_XLINE,  client_p->info,
387                                          NULL, NULL, 0)))
388      {
389 <      ban_them(client_p, conf);
389 >      conf_try_ban(client_p, conf);
390        continue;
391      }
392    }
# Line 409 | Line 402 | check_conf_klines(void)
402        if (conf->type == CONF_EXEMPT)
403          continue;
404  
405 <      exit_client(client_p, &me, "D-lined");
405 >      exit_client(client_p, "D-lined");
406      }
407    }
408   }
409  
410   /*
411 < * ban_them
411 > * conf_try_ban
412   *
413   * inputs       - pointer to client to ban
414   *              - pointer to MaskItem
415   * output       - NONE
416   * side effects - given client_p is banned
417   */
418 < static void
419 < ban_them(struct Client *client_p, struct MaskItem *conf)
418 > void
419 > conf_try_ban(struct Client *client_p, struct MaskItem *conf)
420   {
421    const char *user_reason = NULL;  /* What is sent to user */
422    const char *type_string = NULL;
# Line 435 | Line 428 | ban_them(struct Client *client_p, struct
428    switch (conf->type)
429    {
430      case CONF_KLINE:
431 +      if (IsExemptKline(client_p))
432 +      {
433 +        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
434 +                             "KLINE over-ruled for %s, client is kline_exempt",
435 +                             get_client_name(client_p, HIDE_IP));
436 +        return;
437 +      }
438 +
439        type_string = kline_string;
440        break;
441      case CONF_DLINE:
442        type_string = dline_string;
443        break;
444      case CONF_GLINE:
445 +      if (IsExemptKline(client_p) ||
446 +          IsExemptGline(client_p))
447 +      {
448 +        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
449 +                             "GLINE over-ruled for %s, client is %sline_exempt",
450 +                             get_client_name(client_p, HIDE_IP), IsExemptKline(client_p) ? "k" : "g");
451 +        return;
452 +      }
453 +
454        type_string = gline_string;
455        break;
456      case CONF_XLINE:
# Line 458 | Line 468 | ban_them(struct Client *client_p, struct
468                         type_string, get_client_name(client_p, HIDE_IP));
469  
470    if (IsClient(client_p))
471 <    sendto_one(client_p, form_str(ERR_YOUREBANNEDCREEP),
462 <               me.name, client_p->name, user_reason);
471 >    sendto_one_numeric(client_p, &me, ERR_YOUREBANNEDCREEP, user_reason);
472  
473 <  exit_client(client_p, &me, user_reason);
473 >  exit_client(client_p, user_reason);
474   }
475  
476   /* update_client_exit_stats()
477   *
478   * input        - pointer to client
479   * output       - NONE
480 < * side effects -
480 > * side effects -
481   */
482   static void
483   update_client_exit_stats(struct Client *client_p)
# Line 498 | Line 507 | update_client_exit_stats(struct Client *
507   * side effects - find person by (nick)name
508   */
509   struct Client *
510 < find_person(const struct Client *client_p, const char *name)
510 > find_person(const struct Client *const source_p, const char *name)
511   {
512 <  struct Client *c2ptr = NULL;
512 >  struct Client *target_p = NULL;
513  
514    if (IsDigit(*name))
515    {
516 <    if ((c2ptr = hash_find_id(name)) != NULL)
517 <    {
509 <      /* invisible users shall not be found by UID guessing */
510 <      if (HasUMode(c2ptr, UMODE_INVISIBLE))
511 <        if (!IsServer(client_p) && !HasFlag(client_p, FLAGS_SERVICE))
512 <          c2ptr = NULL;
513 <    }
516 >    if (IsServer(source_p->from))
517 >      target_p = hash_find_id(name);
518    }
519    else
520 <    c2ptr = hash_find_client(name);
520 >    target_p = hash_find_client(name);
521  
522 <  return ((c2ptr != NULL && IsClient(c2ptr)) ? c2ptr : NULL);
522 >  return (target_p && IsClient(target_p)) ? target_p : NULL;
523   }
524  
525   /*
526 < * find_chasing - find the client structure for a nick name (user)
527 < *      using history mechanism if necessary. If the client is not found,
528 < *      an error message (NO SUCH NICK) is generated. If the client was found
525 < *      through the history, chasing will be 1 and otherwise 0.
526 > * find_chasing - find the client structure for a nick name (name)
527 > *      using history mechanism if necessary. If the client is not found,
528 > *      an error message (NO SUCH NICK) is generated.
529   */
530   struct Client *
531 < find_chasing(struct Client *client_p, struct Client *source_p, const char *user, int *chasing)
531 > find_chasing(struct Client *source_p, const char *name)
532   {
533 <  struct Client *who = find_person(client_p, user);
531 <
532 <  if (chasing)
533 <    *chasing = 0;
533 >  struct Client *who = find_person(source_p, name);
534  
535    if (who)
536      return who;
537  
538 <  if (IsDigit(*user))
538 >  if (IsDigit(*name))
539      return NULL;
540  
541 <  if ((who = get_history(user,
541 >  if ((who = whowas_get_history(name,
542                           (time_t)ConfigFileEntry.kill_chase_time_limit))
543                           == NULL)
544    {
545 <    sendto_one(source_p, form_str(ERR_NOSUCHNICK),
546 <               me.name, source_p->name, user);
545 >    sendto_one_numeric(source_p, &me, ERR_NOSUCHNICK, name);
546      return NULL;
547    }
548  
550  if (chasing)
551    *chasing = 1;
552
549    return who;
550   }
551  
# Line 572 | Line 568 | find_chasing(struct Client *client_p, st
568   *        to modify what it points!!!
569   */
570   const char *
571 < get_client_name(const struct Client *client, enum addr_mask_type type)
571 > get_client_name(const struct Client *client_p, enum addr_mask_type type)
572   {
573    static char nbuf[HOSTLEN * 2 + USERLEN + 5];
574  
575 <  assert(client != NULL);
575 >  assert(client_p);
576  
577 <  if (!MyConnect(client))
578 <    return client->name;
577 >  if (!MyConnect(client_p))
578 >    return client_p->name;
579  
580 <  if (IsServer(client) || IsConnecting(client) || IsHandshake(client))
580 >  if (IsServer(client_p) || IsConnecting(client_p) || IsHandshake(client_p))
581    {
582 <    if (!irccmp(client->name, client->host))
583 <      return client->name;
582 >    if (!irccmp(client_p->name, client_p->host))
583 >      return client_p->name;
584      else if (ConfigServerHide.hide_server_ips)
585        type = MASK_IP;
586    }
587  
588    if (ConfigFileEntry.hide_spoof_ips)
589 <    if (type == SHOW_IP && IsIPSpoof(client))
589 >    if (type == SHOW_IP && IsIPSpoof(client_p))
590        type = MASK_IP;
591  
592    /* And finally, let's get the host information, ip or name */
# Line 598 | Line 594 | get_client_name(const struct Client *cli
594    {
595      case SHOW_IP:
596        snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]",
597 <               client->name,
598 <               client->username, client->sockhost);
597 >               client_p->name,
598 >               client_p->username, client_p->sockhost);
599        break;
600      case MASK_IP:
601 <      if (client->localClient->aftype == AF_INET)
601 >      if (client_p->localClient->aftype == AF_INET)
602          snprintf(nbuf, sizeof(nbuf), "%s[%s@255.255.255.255]",
603 <                 client->name, client->username);
603 >                 client_p->name, client_p->username);
604        else
605          snprintf(nbuf, sizeof(nbuf), "%s[%s@ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]",
606 <                 client->name, client->username);
606 >                 client_p->name, client_p->username);
607        break;
608      default:
609        snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]",
610 <               client->name,
611 <               client->username, client->host);
610 >               client_p->name,
611 >               client_p->username, client_p->host);
612    }
613  
614    return nbuf;
# Line 622 | Line 618 | void
618   free_exited_clients(void)
619   {
620    dlink_node *ptr = NULL, *next = NULL;
621 <  
621 >
622    DLINK_FOREACH_SAFE(ptr, next, dead_list.head)
623    {
624      free_client(ptr->data);
# Line 640 | Line 636 | free_exited_clients(void)
636   static void
637   exit_one_client(struct Client *source_p, const char *quitmsg)
638   {
639 <  dlink_node *lp = NULL, *next_lp = NULL;
639 >  dlink_node *ptr = NULL, *ptr_next = NULL;
640  
641    assert(!IsMe(source_p));
642  
643    if (IsClient(source_p))
644    {
645 <    if (source_p->servptr->serv != NULL)
650 <      dlinkDelete(&source_p->lnode, &source_p->servptr->serv->client_list);
645 >    dlinkDelete(&source_p->lnode, &source_p->servptr->serv->client_list);
646  
647      /*
648       * If a person is on a channel, send a QUIT notice
# Line 658 | Line 653 | exit_one_client(struct Client *source_p,
653      sendto_common_channels_local(source_p, 0, 0, ":%s!%s@%s QUIT :%s",
654                                   source_p->name, source_p->username,
655                                   source_p->host, quitmsg);
656 <    DLINK_FOREACH_SAFE(lp, next_lp, source_p->channel.head)
657 <      remove_user_from_channel(lp->data);
656 >    DLINK_FOREACH_SAFE(ptr, ptr_next, source_p->channel.head)
657 >      remove_user_from_channel(ptr->data);
658  
659 <    add_history(source_p, 0);
660 <    off_history(source_p);
659 >    whowas_add_history(source_p, 0);
660 >    whowas_off_history(source_p);
661  
662      watch_check_hash(source_p, RPL_LOGOFF);
663  
664      if (MyConnect(source_p))
665      {
666        /* Clean up invitefield */
667 <      DLINK_FOREACH_SAFE(lp, next_lp, source_p->localClient->invited.head)
668 <        del_invite(lp->data, source_p);
667 >      DLINK_FOREACH_SAFE(ptr, ptr_next, source_p->localClient->invited.head)
668 >        del_invite(ptr->data, source_p);
669  
670        del_all_accepts(source_p);
671      }
# Line 679 | Line 674 | exit_one_client(struct Client *source_p,
674    {
675      dlinkDelete(&source_p->lnode, &source_p->servptr->serv->server_list);
676  
677 <    if ((lp = dlinkFindDelete(&global_serv_list, source_p)) != NULL)
678 <      free_dlink_node(lp);
677 >    if ((ptr = dlinkFindDelete(&global_serv_list, source_p)))
678 >      free_dlink_node(ptr);
679    }
680  
681    /* Remove source_p from the client lists */
682 <  if (HasID(source_p))
682 >  if (source_p->id[0])
683      hash_del_id(source_p);
684    if (source_p->name[0])
685      hash_del_client(source_p);
# Line 696 | Line 691 | exit_one_client(struct Client *source_p,
691     * NOTE: source_p->node.next cannot be NULL if the client is added
692     *       to global_client_list (there is always &me at its end)
693     */
694 <  if (source_p != NULL && source_p->node.next != NULL)
694 >  if (source_p->node.next) /* XXX: not needed? */
695      dlinkDelete(&source_p->node, &global_client_list);
696  
697    update_client_exit_stats(source_p);
# Line 709 | Line 704 | exit_one_client(struct Client *source_p,
704    dlinkAdd(source_p, make_dlink_node(), &dead_list);
705   }
706  
707 < /* Recursively send QUITs and SQUITs for source_p and all its dependent clients
713 < * and servers to those servers that need them.  A server needs the client
714 < * QUITs if it can't figure them out from the SQUIT (ie pre-TS4) or if it
715 < * isn't getting the SQUIT because of @#(*&@)# hostmasking.  With TS4, once
716 < * a link gets a SQUIT, it doesn't need any QUIT/SQUITs for clients depending
717 < * on that one -orabidoo
718 < *
719 < * This is now called on each local server -adx
720 < */
721 < static void
722 < recurse_send_quits(struct Client *original_source_p, struct Client *source_p,
723 <                   struct Client *from, struct Client *to, const char *comment,
724 <                   const char *splitstr)
725 < {
726 <  dlink_node *ptr, *next;
727 <  struct Client *target_p;
728 <
729 <  assert(to != source_p);  /* should be already removed from serv_list */
730 <
731 <  /* If this server can handle quit storm (QS) removal
732 <   * of dependents, just send the SQUIT
733 <   */
734 <  if (!IsCapable(to, CAP_QS))
735 <    DLINK_FOREACH_SAFE(ptr, next, source_p->serv->client_list.head)
736 <    {
737 <      target_p = ptr->data;
738 <      sendto_one(to, ":%s QUIT :%s", target_p->name, splitstr);
739 <    }
740 <
741 <  DLINK_FOREACH_SAFE(ptr, next, source_p->serv->server_list.head)
742 <    recurse_send_quits(original_source_p, ptr->data, from, to,
743 <                       comment, splitstr);
744 <
745 <  if ((source_p == original_source_p && to != from) ||
746 <                  !IsCapable(to, CAP_QS))
747 <  {
748 <    /* don't use a prefix here - we have to be 100% sure the message
749 <     * will be accepted without Unknown prefix etc.. */
750 <    sendto_one(to, "SQUIT %s :%s", ID_or_name(source_p, to), comment);
751 <  }
752 < }
753 <
754 < /*
707 > /*
708   * Remove all clients that depend on source_p; assumes all (S)QUITs have
709 < * already been sent.  we make sure to exit a server's dependent clients
710 < * and servers before the server itself; exit_one_client takes care of
709 > * already been sent.  we make sure to exit a server's dependent clients
710 > * and servers before the server itself; exit_one_client takes care of
711   * actually removing things off llists.   tweaked from +CSr31  -orabidoo
712   */
713   static void
714   recurse_remove_clients(struct Client *source_p, const char *quitmsg)
715   {
716 <  dlink_node *ptr, *next;
716 >  dlink_node *ptr = NULL, *ptr_next = NULL;
717  
718 <  DLINK_FOREACH_SAFE(ptr, next, source_p->serv->client_list.head)
718 >  DLINK_FOREACH_SAFE(ptr, ptr_next, source_p->serv->client_list.head)
719      exit_one_client(ptr->data, quitmsg);
720  
721 <  DLINK_FOREACH_SAFE(ptr, next, source_p->serv->server_list.head)
721 >  DLINK_FOREACH_SAFE(ptr, ptr_next, source_p->serv->server_list.head)
722    {
723      recurse_remove_clients(ptr->data, quitmsg);
724      exit_one_client(ptr->data, quitmsg);
# Line 773 | Line 726 | recurse_remove_clients(struct Client *so
726   }
727  
728   /*
776 ** Remove *everything* that depends on source_p, from all lists, and sending
777 ** all necessary QUITs and SQUITs.  source_p itself is still on the lists,
778 ** and its SQUITs have been sent except for the upstream one  -orabidoo
779 */
780 static void
781 remove_dependents(struct Client *source_p, struct Client *from,
782                  const char *comment, const char *splitstr)
783 {
784  dlink_node *ptr = NULL;
785
786  DLINK_FOREACH(ptr, serv_list.head)
787    recurse_send_quits(source_p, source_p, from, ptr->data,
788                       comment, splitstr);
789
790  recurse_remove_clients(source_p, splitstr);
791 }
792
793 /*
729   * exit_client - exit a client of any type. Generally, you can use
730   * this on any struct Client, regardless of its state.
731   *
732   * Note, you shouldn't exit remote _users_ without first doing
733   * AddFlag(x, FLAGS_KILLED) and propagating a kill or similar message.
734 + *
735   * However, it is perfectly correct to call exit_client to force a _server_
736   * quit (either local or remote one).
737   *
738 + *
739   * inputs:       - a client pointer that is going to be exited
803 *               - for servers, the second argument is a pointer to who
804 *                 is firing the server. This side won't get any generated
805 *                 messages. NEVER NULL!
740   * output:       none
741   * side effects: the client is delinked from all lists, disconnected,
742   *               and the rest of IRC network is notified of the exit.
743   *               Client memory is scheduled to be freed
744   */
745   void
746 < exit_client(struct Client *source_p, struct Client *from, const char *comment)
746 > exit_client(struct Client *source_p, const char *comment)
747   {
748    dlink_node *m = NULL;
749  
# Line 848 | Line 782 | exit_client(struct Client *source_p, str
782        Count.local--;
783  
784        if (HasUMode(source_p, UMODE_OPER))
785 <        if ((m = dlinkFindDelete(&oper_list, source_p)) != NULL)
785 >        if ((m = dlinkFindDelete(&oper_list, source_p)))
786            free_dlink_node(m);
787  
788        assert(dlinkFind(&local_client_list, source_p));
789        dlinkDelete(&source_p->localClient->lclient_node, &local_client_list);
790  
791 <      if (source_p->localClient->list_task != NULL)
791 >      if (source_p->localClient->list_task)
792          free_list_task(source_p->localClient->list_task, source_p);
793  
794        watch_del_watch_list(source_p);
# Line 877 | Line 811 | exit_client(struct Client *source_p, str
811  
812        assert(dlinkFind(&serv_list, source_p));
813        dlinkDelete(&source_p->localClient->lclient_node, &serv_list);
880      unset_chcap_usage_counts(source_p);
814      }
815  
816      if (!IsDead(source_p))
817      {
818        if (IsServer(source_p))
819        {
820 <        /* for them, we are exiting the network */
821 <        sendto_one(source_p, ":%s SQUIT %s :%s",
822 <                   ID_or_name(from, source_p), me.name, comment);
820 >        if (!HasFlag(source_p, FLAGS_SQUIT))
821 >        {
822 >          /* for them, we are exiting the network */
823 >          sendto_one(source_p, ":%s SQUIT %s :%s",
824 >                     me.id, me.id, comment);
825 >        }
826        }
827  
828        sendto_one(source_p, "ERROR :Closing Link: %s (%s)",
# Line 914 | Line 850 | exit_client(struct Client *source_p, str
850  
851    if (IsServer(source_p))
852    {
853 <    char splitstr[HOSTLEN + HOSTLEN + 2];
853 >    char splitstr[HOSTLEN + HOSTLEN + 2] = "";
854  
855      /* This shouldn't ever happen */
856 <    assert(source_p->serv != NULL && source_p->servptr != NULL);
856 >    assert(source_p->serv && source_p->servptr);
857  
858      if (ConfigServerHide.hide_servers)
859        /*
860 <       * Set netsplit message to "*.net *.split" to still show
860 >       * Set netsplit message to "*.net *.split" to still show
861         * that its a split, but hide the servers splitting
862         */
863 <      strcpy(splitstr, "*.net *.split");
863 >      strlcpy(splitstr, "*.net *.split", sizeof(splitstr));
864      else
865        snprintf(splitstr, sizeof(splitstr), "%s %s",
866                 source_p->servptr->name, source_p->name);
867  
868 <    remove_dependents(source_p, from->from, comment, splitstr);
868 >    /* Send SQUIT for source_p in every direction. source_p is already off of serv_list here */
869 >    if (!HasFlag(source_p, FLAGS_SQUIT))
870 >      sendto_server(NULL, NOCAPS, NOCAPS, "SQUIT %s :%s", source_p->id, comment);
871 >
872 >    /* Now exit the clients internally */
873 >    recurse_remove_clients(source_p, splitstr);
874  
875 <    if (source_p->servptr == &me)
875 >    if (MyConnect(source_p))
876      {
877        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
878                             "%s was connected for %d seconds.  %llu/%llu sendK/recvK.",
# Line 939 | Line 880 | exit_client(struct Client *source_p, str
880                             source_p->localClient->send.bytes >> 10,
881                             source_p->localClient->recv.bytes >> 10);
882        ilog(LOG_TYPE_IRCD, "%s was connected for %d seconds.  %llu/%llu sendK/recvK.",
883 <           source_p->name, (int)(CurrentTime - source_p->localClient->firsttime),
883 >           source_p->name, (int)(CurrentTime - source_p->localClient->firsttime),
884             source_p->localClient->send.bytes >> 10,
885             source_p->localClient->recv.bytes >> 10);
886      }
887    }
888    else if (IsClient(source_p) && !HasFlag(source_p, FLAGS_KILLED))
889 <  {
890 <    sendto_server(from->from, CAP_TS6, NOCAPS,
950 <                  ":%s QUIT :%s", ID(source_p), comment);
951 <    sendto_server(from->from, NOCAPS, CAP_TS6,
952 <                  ":%s QUIT :%s", source_p->name, comment);
953 <  }
889 >    sendto_server(source_p->from, NOCAPS, NOCAPS, ":%s QUIT :%s",
890 >                  source_p->id, comment);
891  
892    /* The client *better* be off all of the lists */
893    assert(dlinkFind(&unknown_list, source_p) == NULL);
# Line 994 | Line 931 | dead_link_on_write(struct Client *client
931   void
932   dead_link_on_read(struct Client *client_p, int error)
933   {
934 <  char errmsg[255];
934 >  char errmsg[IRCD_BUFSIZE];
935    int current_error;
936  
937    if (IsDefunct(client_p))
# Line 1008 | Line 945 | dead_link_on_read(struct Client *client_
945    if (IsServer(client_p) || IsHandshake(client_p))
946    {
947      int connected = CurrentTime - client_p->localClient->firsttime;
948 <      
948 >
949      if (error == 0)
950      {
951        /* Admins get the real IP */
# Line 1047 | Line 984 | dead_link_on_read(struct Client *client_
984      snprintf(errmsg, sizeof(errmsg), "Read error: %s",
985               strerror(current_error));
986  
987 <  exit_client(client_p, &me, errmsg);
987 >  exit_client(client_p, errmsg);
988   }
989  
990   void
# Line 1078 | Line 1015 | exit_aborted_clients(void)
1015      else
1016        notice = "Write error: connection closed";
1017  
1018 <    exit_client(target_p, &me, notice);  
1018 >    exit_client(target_p, notice);
1019      free_dlink_node(ptr);
1020    }
1021   }
# Line 1106 | Line 1043 | del_accept(struct split_nuh_item *accept
1043  
1044   struct split_nuh_item *
1045   find_accept(const char *nick, const char *user,
1046 <            const char *host, struct Client *client_p, int do_match)
1046 >            const char *host, struct Client *client_p,
1047 >            int (*cmpfunc)(const char *, const char *))
1048   {
1049    dlink_node *ptr = NULL;
1112  /* XXX We wouldn't need that if match() would return 0 on match */
1113  int (*cmpfunc)(const char *, const char *) = do_match ? match : irccmp;
1050  
1051    DLINK_FOREACH(ptr, client_p->localClient->acceptlist.head)
1052    {
# Line 1139 | Line 1075 | accept_message(struct Client *source,
1075    dlink_node *ptr = NULL;
1076  
1077    if (source == target || find_accept(source->name, source->username,
1078 <                                      source->host, target, 1))
1078 >                                      source->host, target, match))
1079      return 1;
1080  
1081    if (HasUMode(target, UMODE_SOFTCALLERID))
# Line 1159 | Line 1095 | accept_message(struct Client *source,
1095   void
1096   del_all_accepts(struct Client *client_p)
1097   {
1098 <  dlink_node *ptr = NULL, *next_ptr = NULL;
1098 >  dlink_node *ptr = NULL, *ptr_next = NULL;
1099  
1100 <  DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->localClient->acceptlist.head)
1100 >  DLINK_FOREACH_SAFE(ptr, ptr_next, client_p->localClient->acceptlist.head)
1101      del_accept(ptr->data, client_p);
1102   }
1103  
# Line 1190 | Line 1126 | idle_time_get(const struct Client *sourc
1126    else
1127      idle = CurrentTime - target_p->localClient->last_privmsg;
1128  
1129 <  if (max_idle == 0)
1129 >  if (!max_idle)
1130      idle = 0;
1131    else
1132      idle %= max_idle;

Diff Legend

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