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-7.2/src/client.c (file contents), Revision 876 by michael, Wed Oct 24 21:51:21 2007 UTC vs.
ircd-hybrid-8/src/client.c (file contents), Revision 1339 by michael, Fri Apr 6 10:22:36 2012 UTC

# Line 23 | Line 23
23   */
24  
25   #include "stdinc.h"
26 < #include "tools.h"
26 > #include "list.h"
27   #include "client.h"
28   #include "channel_mode.h"
29 #include "common.h"
29   #include "event.h"
30   #include "fdlist.h"
31   #include "hash.h"
32   #include "irc_string.h"
34 #include "sprintf_irc.h"
33   #include "ircd.h"
36 #include "list.h"
34   #include "s_gline.h"
35   #include "numeric.h"
36   #include "packet.h"
37   #include "s_auth.h"
38   #include "s_bsd.h"
39 < #include "s_conf.h"
40 < #include "s_log.h"
39 > #include "conf.h"
40 > #include "log.h"
41   #include "s_misc.h"
42   #include "s_serv.h"
43   #include "send.h"
# Line 77 | Line 74 | static dlink_node *eac_next;  /* next ab
74  
75   static void check_pings_list(dlink_list *);
76   static void check_unknowns_list(void);
77 < static void ban_them(struct Client *client_p, struct ConfItem *conf);
77 > static void ban_them(struct Client *, struct ConfItem *);
78  
79  
80   /* init_client()
# Line 119 | Line 116 | make_client(struct Client *from)
116  
117    if (from == NULL)
118    {
119 <    client_p->from  = client_p; /* 'from' of local client is self! */
120 <    client_p->since = client_p->lasttime = client_p->firsttime = CurrentTime;
121 <
122 <    client_p->localClient = BlockHeapAlloc(lclient_heap);
119 >    client_p->from                      = client_p; /* 'from' of local client is self! */
120 >    client_p->localClient               = BlockHeapAlloc(lclient_heap);
121 >    client_p->localClient->since        = CurrentTime;
122 >    client_p->localClient->lasttime     = CurrentTime;
123 >    client_p->localClient->firsttime    = CurrentTime;
124      client_p->localClient->registration = REG_INIT;
125 +
126      /* as good a place as any... */
127 <    dlinkAdd(client_p, make_dlink_node(), &unknown_list);
127 >    dlinkAdd(client_p, &client_p->localClient->lclient_node, &unknown_list);
128    }
129    else
130      client_p->from = from; /* 'from' of local client is self! */
# Line 254 | Line 253 | check_pings_list(dlink_list *list)
253        continue;
254      }
255  
257    if (GlobalSetOptions.idletime && IsClient(client_p))
258    {
259      if (!IsExemptKline(client_p) && !IsOper(client_p) &&
260          !IsIdlelined(client_p) &&
261          ((CurrentTime - client_p->localClient->last) > GlobalSetOptions.idletime))
262      {
263        struct ConfItem *conf;
264        struct AccessItem *aconf;
265
266        conf = make_conf_item(KLINE_TYPE);
267        aconf = (struct AccessItem *)map_to_conf(conf);
268
269        DupString(aconf->host, client_p->host);
270        DupString(aconf->reason, "idle exceeder");
271        DupString(aconf->user, client_p->username);
272        aconf->hold = CurrentTime + 60;
273        add_temp_line(conf);
274
275        sendto_realops_flags(UMODE_ALL, L_ALL,
276                             "Idle time limit exceeded for %s - temp k-lining",
277                             get_client_name(client_p, HIDE_IP));
278        exit_client(client_p, &me, aconf->reason);
279        continue;
280      }
281    }
282
256      if (!IsRegistered(client_p))
257        ping = CONNECTTIMEOUT, pingwarn = 0;
258      else
259        ping = get_client_ping(client_p, &pingwarn);
260  
261 <    if (ping < CurrentTime - client_p->lasttime)
261 >    if (ping < CurrentTime - client_p->localClient->lasttime)
262      {
263        if (!IsPingSent(client_p))
264        {
# Line 296 | Line 269 | check_pings_list(dlink_list *list)
269           */
270          SetPingSent(client_p);
271          ClearPingWarning(client_p);
272 <        client_p->lasttime = CurrentTime - ping;
272 >        client_p->localClient->lasttime = CurrentTime - ping;
273          sendto_one(client_p, "PING :%s", ID_or_name(&me, client_p));
274        }
275        else
276        {
277 <        if (CurrentTime - client_p->lasttime >= 2 * ping)
277 >        if (CurrentTime - client_p->localClient->lasttime >= 2 * ping)
278          {
279            /*
280             * If the client/server hasn't talked to us in 2*ping seconds
# Line 315 | Line 288 | check_pings_list(dlink_list *list)
288              sendto_realops_flags(UMODE_ALL, L_OPER,
289                                   "No response from %s, closing link",
290                                   get_client_name(client_p, MASK_IP));
291 <            ilog(L_NOTICE, "No response from %s, closing link",
291 >            ilog(LOG_TYPE_IRCD, "No response from %s, closing link",
292                   get_client_name(client_p, HIDE_IP));
293            }
294  
295 <          ircsprintf(scratch, "Ping timeout: %d seconds",
296 <                     (int)(CurrentTime - client_p->lasttime));
295 >          snprintf(scratch, sizeof(scratch), "Ping timeout: %d seconds",
296 >                   (int)(CurrentTime - client_p->localClient->lasttime));
297            exit_client(client_p, &me, scratch);
298          }
299          else if (!IsPingWarning(client_p) && pingwarn > 0 &&
300                   (IsServer(client_p) || IsHandshake(client_p)) &&
301 <                 CurrentTime - client_p->lasttime >= ping + pingwarn)
301 >                 CurrentTime - client_p->localClient->lasttime >= ping + pingwarn)
302          {
303            /*
304             * If the server hasn't replied in pingwarn seconds after sending
# Line 338 | Line 311 | check_pings_list(dlink_list *list)
311            sendto_realops_flags(UMODE_ALL, L_OPER,
312                                 "Warning, no response from %s in %d seconds",
313                                 get_client_name(client_p, MASK_IP), pingwarn);
314 <          ilog(L_NOTICE, "No response from %s in %d seconds",
314 >          ilog(LOG_TYPE_IRCD, "No response from %s in %d seconds",
315                 get_client_name(client_p, HIDE_IP), pingwarn);
316          }
317        }
# Line 372 | Line 345 | check_unknowns_list(void)
345       * Check UNKNOWN connections - if they have been in this state
346       * for > 30s, close them.
347       */
348 <    if (IsAuthFinished(client_p) && (CurrentTime - client_p->firsttime) > 30)
348 >    if (IsAuthFinished(client_p) && (CurrentTime - client_p->localClient->firsttime) > 30)
349        exit_client(client_p, &me, "Registration timed out");
350    }
351   }
# Line 555 | Line 528 | ban_them(struct Client *client_p, struct
528   static void
529   update_client_exit_stats(struct Client *client_p)
530   {
531 <  if (IsServer(client_p))
559 <  {
560 <    sendto_realops_flags(UMODE_EXTERNAL, L_ALL,
561 <                         "Server %s split from %s",
562 <                         client_p->name, client_p->servptr->name);
563 <  }
564 <  else if (IsClient(client_p))
531 >  if (IsClient(client_p))
532    {
533 +    assert(Count.total > 0);
534      --Count.total;
535 <    if (IsOper(client_p))
535 >    if (HasUMode(client_p, UMODE_OPER))
536        --Count.oper;
537 <    if (IsInvisible(client_p))
537 >    if (HasUMode(client_p, UMODE_INVISIBLE))
538        --Count.invisi;
539    }
540 +  else if (IsServer(client_p))
541 +    sendto_realops_flags(UMODE_EXTERNAL, L_ALL, "Server %s split from %s",
542 +                         client_p->name, client_p->servptr->name);
543  
544    if (splitchecking && !splitmode)
545      check_splitmode(NULL);
# Line 591 | Line 562 | find_person(const struct Client *client_
562      if ((c2ptr = hash_find_id(name)) != NULL)
563      {
564        /* invisible users shall not be found by UID guessing */
565 <      if (IsInvisible(c2ptr) && !IsServer(client_p))
565 >      if (HasUMode(c2ptr, UMODE_INVISIBLE) && !IsServer(client_p))
566          c2ptr = NULL;
567      }
568    }
569    else
570 <    c2ptr = find_client(name);
570 >    c2ptr = hash_find_client(name);
571  
572    return ((c2ptr != NULL && IsClient(c2ptr)) ? c2ptr : NULL);
573   }
# Line 616 | Line 587 | find_chasing(struct Client *client_p, st
587      *chasing = 0;
588  
589    if (who)
590 <    return(who);
590 >    return who;
591  
592    if (IsDigit(*user))
593 <    return(NULL);
593 >    return NULL;
594  
595    if ((who = get_history(user,
596                          (time_t)ConfigFileEntry.kill_chase_time_limit))
# Line 627 | Line 598 | find_chasing(struct Client *client_p, st
598    {
599      sendto_one(source_p, form_str(ERR_NOSUCHNICK),
600                 me.name, source_p->name, user);
601 <    return(NULL);
601 >    return NULL;
602    }
603  
604    if (chasing)
605      *chasing = 1;
606  
607 <  return(who);
607 >  return who;
608   }
609  
610   /*
# Line 655 | Line 626 | find_chasing(struct Client *client_p, st
626   *        to modify what it points!!!
627   */
628   const char *
629 < get_client_name(struct Client *client, int showip)
629 > get_client_name(const struct Client *client, enum addr_mask_type type)
630   {
631    static char nbuf[HOSTLEN * 2 + USERLEN + 5];
632  
633    assert(client != NULL);
634  
635 <  if (irccmp(client->name, client->host) == 0)
636 <    return(client->name);
635 >  if (!MyConnect(client) || !irccmp(client->name, client->host))
636 >    return client->name;
637  
638    if (ConfigServerHide.hide_server_ips)
639      if (IsServer(client) || IsConnecting(client) || IsHandshake(client))
640 <      showip = MASK_IP;
640 >      type = MASK_IP;
641  
642    if (ConfigFileEntry.hide_spoof_ips)
643 <    if (showip == SHOW_IP && IsIPSpoof(client))
644 <      showip = MASK_IP;
643 >    if (type == SHOW_IP && IsIPSpoof(client))
644 >      type = MASK_IP;
645  
646    /* And finally, let's get the host information, ip or name */
647 <  switch (showip)
647 >  switch (type)
648    {
649      case SHOW_IP:
650 <      if (MyConnect(client))
651 <      {
652 <        ircsprintf(nbuf, "%s[%s@%s]", client->name, client->username,
653 <                   client->sockhost);
683 <        break;
684 <      }
650 >      snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]",
651 >               client->name,
652 >               client->username, client->sockhost);
653 >      break;
654      case MASK_IP:
655 <      ircsprintf(nbuf, "%s[%s@255.255.255.255]", client->name,
656 <                 client->username);
655 >      if (client->localClient->aftype == AF_INET)
656 >        snprintf(nbuf, sizeof(nbuf), "%s[%s@255.255.255.255]",
657 >                 client->name, client->username);
658 >      else
659 >        snprintf(nbuf, sizeof(nbuf), "%s[%s@ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]",
660 >                 client->name, client->username);
661        break;
662      default:
663 <      ircsprintf(nbuf, "%s[%s@%s]", client->name, client->username,
664 <                 client->host);
663 >      snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]",
664 >               client->name,
665 >               client->username, client->host);
666    }
667  
668 <  return(nbuf);
668 >  return nbuf;
669   }
670  
671   void
672   free_exited_clients(void)
673   {
674 <  dlink_node *ptr, *next;
701 <  struct Client *target_p;
674 >  dlink_node *ptr = NULL, *next = NULL;
675    
676    DLINK_FOREACH_SAFE(ptr, next, dead_list.head)
677    {
678 <    target_p = ptr->data;
706 <
707 <    if (ptr->data == NULL)
708 <    {
709 <      sendto_realops_flags(UMODE_ALL, L_ALL,
710 <                           "Warning: null client on dead_list!");
711 <      dlinkDelete(ptr, &dead_list);
712 <      free_dlink_node(ptr);
713 <      continue;
714 <    }
715 <
716 <    free_client(target_p);
678 >    free_client(ptr->data);
679      dlinkDelete(ptr, &dead_list);
680      free_dlink_node(ptr);
681    }
# Line 732 | Line 694 | exit_one_client(struct Client *source_p,
694  
695    assert(!IsMe(source_p));
696  
697 <  if (IsServer(source_p))
736 <  {
737 <    dlinkDelete(&source_p->lnode, &source_p->servptr->serv->servers);
738 <
739 <    if ((lp = dlinkFindDelete(&global_serv_list, source_p)) != NULL)
740 <      free_dlink_node(lp);
741 <
742 <    if (!MyConnect(source_p))
743 <    {
744 <      source_p->from->serv->dep_servers--;
745 <      assert(source_p->from->serv->dep_servers > 0);
746 <    }
747 <  }
748 <  else if (IsClient(source_p))
697 >  if (IsClient(source_p))
698    {
699      if (source_p->servptr->serv != NULL)
700 <      dlinkDelete(&source_p->lnode, &source_p->servptr->serv->users);
700 >      dlinkDelete(&source_p->lnode, &source_p->servptr->serv->client_list);
701  
702 <    /* If a person is on a channel, send a QUIT notice
703 <    ** to every client (person) on the same channel (so
704 <    ** that the client can show the "**signoff" message).
705 <    ** (Note: The notice is to the local clients *only*)
706 <    */
702 >    /*
703 >     * If a person is on a channel, send a QUIT notice
704 >     * to every client (person) on the same channel (so
705 >     * that the client can show the "**signoff" message).
706 >     * (Note: The notice is to the local clients *only*)
707 >     */
708      sendto_common_channels_local(source_p, 0, ":%s!%s@%s QUIT :%s",
709                                   source_p->name, source_p->username,
710                                   source_p->host, quitmsg);
711      DLINK_FOREACH_SAFE(lp, next_lp, source_p->channel.head)
712        remove_user_from_channel(lp->data);
713  
764    /* Clean up allow lists */
765    del_all_accepts(source_p);
714      add_history(source_p, 0);
715      off_history(source_p);
716  
717      watch_check_hash(source_p, RPL_LOGOFF);
718  
719 <    if (!MyConnect(source_p))
772 <    {
773 <      source_p->from->serv->dep_users--;
774 <      assert(source_p->from->serv->dep_users >= 0);
775 <    }
776 <    else
719 >    if (MyConnect(source_p))
720      {
721        /* Clean up invitefield */
722        DLINK_FOREACH_SAFE(lp, next_lp, source_p->localClient->invited.head)
723          del_invite(lp->data, source_p);
724 +
725 +      del_all_accepts(source_p);
726      }
727    }
728 +  else if (IsServer(source_p))
729 +  {
730 +    dlinkDelete(&source_p->lnode, &source_p->servptr->serv->server_list);
731 +
732 +    if ((lp = dlinkFindDelete(&global_serv_list, source_p)) != NULL)
733 +      free_dlink_node(lp);
734 +  }
735  
736    /* Remove source_p from the client lists */
737    if (HasID(source_p))
# Line 819 | Line 771 | exit_one_client(struct Client *source_p,
771   static void
772   recurse_send_quits(struct Client *original_source_p, struct Client *source_p,
773                     struct Client *from, struct Client *to, const char *comment,
774 <                   const char *splitstr, const char *myname)
774 >                   const char *splitstr)
775   {
776    dlink_node *ptr, *next;
777    struct Client *target_p;
778 <  int hidden = match(myname, source_p->name);
778 >  int hidden = match(me.name, source_p->name); /* XXX */
779  
780    assert(to != source_p);  /* should be already removed from serv_list */
781  
# Line 834 | Line 786 | recurse_send_quits(struct Client *origin
786     * hidden behind fakename. If so, send out the QUITs -adx
787     */
788    if (hidden || !IsCapable(to, CAP_QS))
789 <    DLINK_FOREACH_SAFE(ptr, next, source_p->serv->users.head)
789 >    DLINK_FOREACH_SAFE(ptr, next, source_p->serv->client_list.head)
790      {
791        target_p = ptr->data;
792        sendto_one(to, ":%s QUIT :%s", target_p->name, splitstr);
793      }
794  
795 <  DLINK_FOREACH_SAFE(ptr, next, source_p->serv->servers.head)
795 >  DLINK_FOREACH_SAFE(ptr, next, source_p->serv->server_list.head)
796      recurse_send_quits(original_source_p, ptr->data, from, to,
797 <                       comment, splitstr, myname);
797 >                       comment, splitstr);
798  
799    if (!hidden && ((source_p == original_source_p && to != from) ||
800                    !IsCapable(to, CAP_QS)))
# Line 864 | Line 816 | recurse_remove_clients(struct Client *so
816   {
817    dlink_node *ptr, *next;
818  
819 <  DLINK_FOREACH_SAFE(ptr, next, source_p->serv->users.head)
819 >  DLINK_FOREACH_SAFE(ptr, next, source_p->serv->client_list.head)
820      exit_one_client(ptr->data, quitmsg);
821  
822 <  DLINK_FOREACH_SAFE(ptr, next, source_p->serv->servers.head)
822 >  DLINK_FOREACH_SAFE(ptr, next, source_p->serv->server_list.head)
823    {
824      recurse_remove_clients(ptr->data, quitmsg);
825      exit_one_client(ptr->data, quitmsg);
826    }
875
876  assert(source_p->serv->dep_servers == 1);
877  assert(source_p->serv->dep_users == 0);
827   }
828  
829   /*
# Line 886 | Line 835 | static void
835   remove_dependents(struct Client *source_p, struct Client *from,
836                    const char *comment, const char *splitstr)
837   {
838 <  struct Client *to;
890 <  struct ConfItem *conf;
891 <  static char myname[HOSTLEN+1];
892 <  dlink_node *ptr;
838 >  dlink_node *ptr = NULL;
839  
840    DLINK_FOREACH(ptr, serv_list.head)
841 <  {
842 <    to = ptr->data;
897 <
898 <    if ((conf = to->serv->sconf) != NULL)
899 <      strlcpy(myname, my_name_for_link(conf), sizeof(myname));
900 <    else
901 <      strlcpy(myname, me.name, sizeof(myname));
902 <    recurse_send_quits(source_p, source_p, from, to,
903 <                       comment, splitstr, myname);
904 <  }
841 >    recurse_send_quits(source_p, source_p, from, ptr->data,
842 >                       comment, splitstr);
843  
844    recurse_remove_clients(source_p, splitstr);
845   }
# Line 911 | Line 849 | remove_dependents(struct Client *source_
849   * this on any struct Client, regardless of its state.
850   *
851   * Note, you shouldn't exit remote _users_ without first doing
852 < * SetKilled and propagating a kill or similar message. However,
853 < * it is perfectly correct to call exit_client to force a _server_
852 > * AddFlag(x, FLAGS_KILLED) and propagating a kill or similar message.
853 > * However, it is perfectly correct to call exit_client to force a _server_
854   * quit (either local or remote one).
855   *
856   * inputs:       - a client pointer that is going to be exited
# Line 927 | Line 865 | remove_dependents(struct Client *source_
865   void
866   exit_client(struct Client *source_p, struct Client *from, const char *comment)
867   {
868 <  dlink_node *m;
868 >  dlink_node *m = NULL;
869  
870    if (MyConnect(source_p))
871    {
# Line 942 | Line 880 | exit_client(struct Client *source_p, str
880      if (IsIpHash(source_p))
881        remove_one_ip(&source_p->localClient->ip);
882  
883 <    delete_auth(source_p);
883 >    if (source_p->localClient->auth)
884 >    {
885 >      delete_auth(source_p->localClient->auth);
886 >      source_p->localClient->auth = NULL;
887 >    }
888  
889      /* This source_p could have status of one of STAT_UNKNOWN, STAT_CONNECTING
890       * STAT_HANDSHAKE or STAT_UNKNOWN
# Line 952 | Line 894 | exit_client(struct Client *source_p, str
894       */
895      if (!IsRegistered(source_p))
896      {
897 <      if ((m = dlinkFindDelete(&unknown_list, source_p)) != NULL)
898 <        free_dlink_node(m);
897 >      assert(dlinkFind(&unknown_list, source_p));
898 >
899 >      dlinkDelete(&source_p->localClient->lclient_node, &unknown_list);
900      }
901      else if (IsClient(source_p))
902      {
903 +      time_t on_for = CurrentTime - source_p->localClient->firsttime;
904 +      assert(Count.local > 0);
905        Count.local--;
906  
907 <      if (IsOper(source_p))
907 >      if (HasUMode(source_p, UMODE_OPER))
908        {
909          if ((m = dlinkFindDelete(&oper_list, source_p)) != NULL)
910            free_dlink_node(m);
911        }
912  
913 +      assert(dlinkFind(&local_client_list, source_p));
914        dlinkDelete(&source_p->localClient->lclient_node, &local_client_list);
915 +
916        if (source_p->localClient->list_task != NULL)
917          free_list_task(source_p->localClient->list_task, source_p);
918  
# Line 978 | Line 925 | exit_client(struct Client *source_p, str
925                             source_p->name,
926                             source_p->username,
927                             source_p->host,
981
928                             ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
929                             "255.255.255.255" : source_p->sockhost,
930                             comment);
931 +      ilog(LOG_TYPE_USER, "%s (%3u:%02u:%02u): %s!%s@%s %llu/%llu",
932 +           myctime(source_p->localClient->firsttime), (unsigned int)(on_for / 3600),
933 +           (unsigned int)((on_for % 3600)/60), (unsigned int)(on_for % 60),
934 +           source_p->name, source_p->username, source_p->host,
935 +           source_p->localClient->send.bytes>>10,
936 +           source_p->localClient->recv.bytes>>10);
937      }
938  
939      /* As soon as a client is known to be a server of some sort
940       * it has to be put on the serv_list, or SJOIN's to this new server
941       * from the connect burst will not be seen.
942 +     * XXX - TBV.  This is not true. The only place where we put a server on
943 +     * serv_list is in server_estab right now after registration process.
944 +     * And only after this, a burst is sent to the remote server, i.e. we never
945 +     * send a burst to STAT_CONNECTING, or STAT_HANDSHAKE. This will need
946 +     * more investigation later on, but for now, it's not a problem after all.
947       */
948      if (IsServer(source_p) || IsConnecting(source_p) ||
949          IsHandshake(source_p))
950      {
951 <      if ((m = dlinkFindDelete(&serv_list, source_p)) != NULL)
951 >      if (dlinkFind(&serv_list, source_p))
952        {
953 <        free_dlink_node(m);
953 >        dlinkDelete(&source_p->localClient->lclient_node, &serv_list);
954          unset_chcap_usage_counts(source_p);
955        }
956  
957        if (IsServer(source_p))
1001      {
958          Count.myserver--;
1003        if (ServerInfo.hub)
1004          remove_lazylink_flags(source_p->localClient->serverMask);
1005        else
1006          uplink = NULL;
1007      }
959      }
960  
1010    log_user_exit(source_p);
1011
961      if (!IsDead(source_p))
962      {
963        if (IsServer(source_p))
# Line 1044 | Line 993 | exit_client(struct Client *source_p, str
993      assert(source_p->serv != NULL && source_p->servptr != NULL);
994  
995      if (ConfigServerHide.hide_servers)
996 <      /* set netsplit message to "*.net *.split" to still show
996 >      /*
997 >       * Set netsplit message to "*.net *.split" to still show
998         * that its a split, but hide the servers splitting
999         */
1000        strcpy(splitstr, "*.net *.split");
# Line 1058 | Line 1008 | exit_client(struct Client *source_p, str
1008      {
1009        sendto_realops_flags(UMODE_ALL, L_ALL,
1010                             "%s was connected for %d seconds.  %llu/%llu sendK/recvK.",
1011 <                           source_p->name, (int)(CurrentTime - source_p->firsttime),
1011 >                           source_p->name, (int)(CurrentTime - source_p->localClient->firsttime),
1012                             source_p->localClient->send.bytes >> 10,
1013                             source_p->localClient->recv.bytes >> 10);
1014 <      ilog(L_NOTICE, "%s was connected for %d seconds.  %llu/%llu sendK/recvK.",
1015 <           source_p->name, (int)(CurrentTime - source_p->firsttime),
1014 >      ilog(LOG_TYPE_IRCD, "%s was connected for %d seconds.  %llu/%llu sendK/recvK.",
1015 >           source_p->name, (int)(CurrentTime - source_p->localClient->firsttime),
1016             source_p->localClient->send.bytes >> 10,
1017             source_p->localClient->recv.bytes >> 10);
1018      }
1019    }
1020 <  else if (IsClient(source_p) && !IsKilled(source_p))
1020 >  else if (IsClient(source_p) && !HasFlag(source_p, FLAGS_KILLED))
1021    {
1022 <    sendto_server(from->from, source_p, NULL, CAP_TS6, NOCAPS, NOFLAGS,
1022 >    sendto_server(from->from, NULL, CAP_TS6, NOCAPS,
1023                    ":%s QUIT :%s", ID(source_p), comment);
1024 <    sendto_server(from->from, source_p, NULL, NOCAPS, CAP_TS6, NOFLAGS,
1024 >    sendto_server(from->from, NULL, NOCAPS, CAP_TS6,
1025                    ":%s QUIT :%s", source_p->name, comment);
1026    }
1027  
# Line 1130 | Line 1080 | dead_link_on_read(struct Client *client_
1080  
1081    if (IsServer(client_p) || IsHandshake(client_p))
1082    {
1083 <    int connected = CurrentTime - client_p->firsttime;
1083 >    int connected = CurrentTime - client_p->localClient->firsttime;
1084        
1085      if (error == 0)
1086      {
# Line 1144 | Line 1094 | dead_link_on_read(struct Client *client_
1094                             "Server %s closed the connection",
1095                             get_client_name(client_p, MASK_IP));
1096  
1097 <      ilog(L_NOTICE, "Server %s closed the connection",
1097 >      ilog(LOG_TYPE_IRCD, "Server %s closed the connection",
1098             get_client_name(client_p, SHOW_IP));
1099      }
1100      else
# Line 1167 | Line 1117 | dead_link_on_read(struct Client *client_
1117      strlcpy(errmsg, "Remote host closed the connection",
1118              sizeof(errmsg));
1119    else
1120 <    ircsprintf(errmsg, "Read error: %s",
1121 <               strerror(current_error));
1120 >    snprintf(errmsg, sizeof(errmsg), "Read error: %s",
1121 >             strerror(current_error));
1122  
1123    exit_client(client_p, &me, errmsg);
1124   }
# Line 1208 | Line 1158 | exit_aborted_clients(void)
1158  
1159   /*
1160   * accept processing, this adds a form of "caller ID" to ircd
1161 < *
1161 > *
1162   * If a client puts themselves into "caller ID only" mode,
1163 < * only clients that match a client pointer they have put on
1163 > * only clients that match a client pointer they have put on
1164   * the accept list will be allowed to message them.
1165   *
1166 < * [ source.on_allow_list ] -> [ target1 ] -> [ target2 ]
1217 < *
1218 < * [target.allow_list] -> [ source1 ] -> [source2 ]
1219 < *
1220 < * i.e. a target will have a link list of source pointers it will allow
1221 < * each source client then has a back pointer pointing back
1222 < * to the client that has it on its accept list.
1223 < * This allows for exit_one_client to remove these now bogus entries
1224 < * from any client having an accept on them.
1166 > * Diane Bruce, "Dianora" db@db.net
1167   */
1168  
1169 < /* accept_message()
1170 < *
1229 < * inputs       - pointer to source client
1230 < *              - pointer to target client
1231 < * output       - 1 if accept this message 0 if not
1232 < * side effects - See if source is on target's allow list
1233 < */
1234 < int
1235 < accept_message(struct Client *source, struct Client *target)
1169 > void
1170 > del_accept(struct split_nuh_item *accept_p, struct Client *client_p)
1171   {
1172 <  dlink_node *ptr;
1238 <
1239 <  DLINK_FOREACH(ptr, target->allow_list.head)
1240 <  {
1241 <    struct Client *target_p = ptr->data;
1242 <
1243 <    if (source == target_p)
1244 <      return (1);
1245 <  }
1246 <
1247 <  if (IsSoftCallerId(target))
1248 <  {
1249 <    DLINK_FOREACH(ptr, target->channel.head)
1250 <      if (IsMember(source, ((struct Membership *)ptr->data)->chptr))
1251 <        return (1);
1252 <  }
1172 >  dlinkDelete(&accept_p->node, &client_p->localClient->acceptlist);
1173  
1174 <  return (0);
1174 >  MyFree(accept_p->nickptr);
1175 >  MyFree(accept_p->userptr);
1176 >  MyFree(accept_p->hostptr);
1177 >  MyFree(accept_p);
1178   }
1179  
1180 < /* del_from_accept()
1181 < *
1182 < * inputs       - pointer to source client
1260 < *              - pointer to target client
1261 < * output       - NONE
1262 < * side effects - Delete's source pointer to targets allow list
1263 < *
1264 < * Walk through the target's accept list, remove if source is found,
1265 < * Then walk through the source's on_accept_list remove target if found.
1266 < */
1267 < void
1268 < del_from_accept(struct Client *source, struct Client *target)
1180 > struct split_nuh_item *
1181 > find_accept(const char *nick, const char *user,
1182 >            const char *host, struct Client *client_p, int do_match)
1183   {
1184 <  dlink_node *ptr;
1185 <  dlink_node *ptr2;
1186 <  dlink_node *next_ptr;
1273 <  dlink_node *next_ptr2;
1274 <  struct Client *target_p;
1184 >  dlink_node *ptr = NULL;
1185 >  /* XXX We wouldn't need that if match() would return 0 on match */
1186 >  int (*cmpfunc)(const char *, const char *) = do_match ? match : irccmp;
1187  
1188 <  DLINK_FOREACH_SAFE(ptr, next_ptr, target->allow_list.head)
1188 >  DLINK_FOREACH(ptr, client_p->localClient->acceptlist.head)
1189    {
1190 <    target_p = ptr->data;
1279 <
1280 <    if (source == target_p)
1281 <    {
1282 <      dlinkDelete(ptr, &target->allow_list);
1283 <      free_dlink_node(ptr);
1284 <
1285 <      DLINK_FOREACH_SAFE(ptr2, next_ptr2, source->on_allow_list.head)
1286 <      {
1287 <        target_p = ptr2->data;
1190 >    struct split_nuh_item *accept_p = ptr->data;
1191  
1192 <        if (target == target_p)
1193 <        {
1194 <          dlinkDelete(ptr2, &source->on_allow_list);
1195 <          free_dlink_node(ptr2);
1293 <        }
1294 <      }
1295 <    }
1192 >    if (cmpfunc(accept_p->nickptr, nick) == do_match &&
1193 >        cmpfunc(accept_p->userptr, user) == do_match &&
1194 >        cmpfunc(accept_p->hostptr, host) == do_match)
1195 >      return accept_p;
1196    }
1297 }
1197  
1198 < /* del_all_accepts()
1300 < *
1301 < * inputs       - pointer to exiting client
1302 < * output       - NONE
1303 < * side effects - Walk through given clients allow_list and on_allow_list
1304 < *                remove all references to this client
1305 < */
1306 < void
1307 < del_all_accepts(struct Client *client_p)
1308 < {
1309 <  dlink_node *ptr, *next_ptr;
1310 <
1311 <  DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->allow_list.head)
1312 <    del_from_accept(ptr->data, client_p);
1313 <
1314 <  DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->on_allow_list.head)
1315 <    del_from_accept(client_p, ptr->data);
1198 >  return NULL;
1199   }
1200  
1201 < /* del_all_their_accepts()
1319 < *
1320 < * inputs       - pointer to exiting client
1321 < * output       - NONE
1322 < * side effects - Walk through given clients on_allow_list
1323 < *                remove all references to this client,
1324 < *                allow this client to keep their own allow_list
1325 < */
1326 < void
1327 < del_all_their_accepts(struct Client *client_p)
1328 < {
1329 <  dlink_node *ptr, *next_ptr;
1330 <
1331 <  DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->on_allow_list.head)
1332 <    del_from_accept(client_p, ptr->data);
1333 < }
1334 <
1335 < /* set_initial_nick()
1336 < *
1337 < * inputs
1338 < * output
1339 < * side effects -
1201 > /* accept_message()
1202   *
1203 < * This function is only called to set up an initially registering
1204 < * client.
1203 > * inputs       - pointer to source client
1204 > *              - pointer to target client
1205 > * output       - 1 if accept this message 0 if not
1206 > * side effects - See if source is on target's allow list
1207   */
1208 < void
1209 < set_initial_nick(struct Client *client_p, struct Client *source_p,
1210 <                 const char *nick)
1208 > int
1209 > accept_message(struct Client *source,
1210 >               struct Client *target)
1211   {
1212 < char buf[USERLEN + 1];
1212 >  dlink_node *ptr = NULL;
1213  
1214 <  /* Client setting NICK the first time */
1215 <  
1216 <  /* This had to be copied here to avoid problems.. */
1353 <  source_p->tsinfo = CurrentTime;
1354 <  source_p->localClient->registration &= ~REG_NEED_NICK;
1355 <
1356 <  if (source_p->name[0])
1357 <    hash_del_client(source_p);
1358 <
1359 <  strlcpy(source_p->name, nick, sizeof(source_p->name));
1360 <  hash_add_client(source_p);
1214 >  if (source == target || find_accept(source->name, source->username,
1215 >                                      source->host, target, 1))
1216 >    return 1;
1217  
1218 <  /* fd_desc is long enough */
1219 <  fd_note(&client_p->localClient->fd, "Nick: %s", nick);
1220 <  
1221 <  /* They have the nick they want now.. */
1366 <  client_p->llname[0] = '\0';
1367 <
1368 <  if (!source_p->localClient->registration)
1369 <  {
1370 <    strlcpy(buf, source_p->username, sizeof(buf));
1218 >  if (HasUMode(target, UMODE_SOFTCALLERID))
1219 >    DLINK_FOREACH(ptr, target->channel.head)
1220 >      if (IsMember(source, ((struct Membership *)ptr->data)->chptr))
1221 >        return 1;
1222  
1223 <    /*
1373 <     * USER already received, now we have NICK.
1374 <     * *NOTE* For servers "NICK" *must* precede the
1375 <     * user message (giving USER before NICK is possible
1376 <     * only for local client connection!). register_user
1377 <     * may reject the client and call exit_client for it
1378 <     * --must test this and exit m_nick too!!!
1379 <     */
1380 <    register_local_user(client_p, source_p, nick, buf);
1381 <  }
1223 >  return 0;
1224   }
1225  
1226 < /* change_local_nick()
1226 > /* del_all_accepts()
1227   *
1228 < * inputs       - pointer to server
1229 < *              - pointer to client
1230 < *              - nick
1389 < * output       -
1390 < * side effects - changes nick of a LOCAL user
1228 > * inputs       - pointer to exiting client
1229 > * output       - NONE
1230 > * side effects - Walk through given clients acceptlist and remove all entries
1231   */
1232   void
1233 < change_local_nick(struct Client *client_p, struct Client *source_p, const char *nick)
1233 > del_all_accepts(struct Client *client_p)
1234   {
1235 <  int samenick = 0;
1396 <
1397 <  /*
1398 <  ** Client just changing his/her nick. If he/she is
1399 <  ** on a channel, send note of change to all clients
1400 <  ** on that channel. Propagate notice to other servers.
1401 <  */
1402 <  if ((source_p->localClient->last_nick_change +
1403 <       ConfigFileEntry.max_nick_time) < CurrentTime)
1404 <    source_p->localClient->number_of_nick_changes = 0;
1405 <  source_p->localClient->last_nick_change = CurrentTime;
1406 <  source_p->localClient->number_of_nick_changes++;
1407 <
1408 <  if ((ConfigFileEntry.anti_nick_flood &&
1409 <      (source_p->localClient->number_of_nick_changes
1410 <       <= ConfigFileEntry.max_nick_changes)) ||
1411 <     !ConfigFileEntry.anti_nick_flood ||
1412 <     (IsOper(source_p) && ConfigFileEntry.no_oper_flood))
1413 <  {
1414 <    samenick = !irccmp(source_p->name, nick);
1415 <
1416 <    if (!samenick)
1417 <    {
1418 <      /*
1419 <       * Make sure everyone that has this client on its accept list
1420 <       * loses that reference.
1421 <       */
1422 <      del_all_their_accepts(source_p);
1423 <      source_p->tsinfo = CurrentTime;
1424 <      clear_ban_cache_client(source_p);
1425 <    }
1426 <
1427 <    /* XXX - the format of this notice should eventually be changed
1428 <     * to either %s[%s@%s], or even better would be get_client_name() -bill
1429 <     */
1430 <    sendto_realops_flags(UMODE_NCHANGE, L_ALL, "Nick change: From %s to %s [%s@%s]",
1431 <                         source_p->name, nick, source_p->username, source_p->host);
1432 <    sendto_common_channels_local(source_p, 1, ":%s!%s@%s NICK :%s",
1433 <                                 source_p->name, source_p->username,
1434 <                                 source_p->host, nick);
1435 <    add_history(source_p, 1);
1436 <
1437 <    /*
1438 <     * Only hubs care about lazy link nicks not being sent on yet
1439 <     * lazylink leafs/leafs always send their nicks up to hub,
1440 <     * hence must always propagate nick changes.
1441 <     * hubs might not propagate a nick change, if the leaf
1442 <     * does not know about that client yet.
1443 <     */
1444 <    sendto_server(client_p, source_p, NULL, CAP_TS6, NOCAPS, NOFLAGS,
1445 <                  ":%s NICK %s :%lu",
1446 <                  ID(source_p), nick, (unsigned long)source_p->tsinfo);
1447 <    sendto_server(client_p, source_p, NULL, NOCAPS, CAP_TS6, NOFLAGS,
1448 <                  ":%s NICK %s :%lu",
1449 <                  source_p->name, nick, (unsigned long)source_p->tsinfo);
1450 <  }
1451 <  else
1452 <  {
1453 <    sendto_one(source_p, form_str(ERR_NICKTOOFAST),
1454 <               me.name, source_p->name, source_p->name,
1455 <               nick, ConfigFileEntry.max_nick_time);
1456 <    return;
1457 <  }
1458 <
1459 <  /* Finally, add to hash */
1460 <  if (source_p->name[0])
1461 <    hash_del_client(source_p);
1462 <
1463 <  if (!samenick)
1464 <  {
1465 <    clear_ban_cache_client(source_p);
1466 <    watch_check_hash(source_p, RPL_LOGOFF);
1467 <  }
1468 <
1469 <  strcpy(source_p->name, nick);
1470 <  hash_add_client(source_p);
1471 <
1472 <  if (!samenick)
1473 <    watch_check_hash(source_p, RPL_LOGON);
1235 >  dlink_node *ptr = NULL, *next_ptr = NULL;
1236  
1237 <  /* fd_desc is long enough */
1238 <  fd_note(&client_p->localClient->fd, "Nick: %s", nick);
1237 >  DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->localClient->acceptlist.head)
1238 >    del_accept(ptr->data, client_p);
1239   }

Diff Legend

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