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/src/client.c (file contents), Revision 32 by knight, Sun Oct 2 20:41:23 2005 UTC vs.
ircd-hybrid/trunk/src/client.c (file contents), Revision 1592 by michael, Sat Oct 27 21:02:32 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 53 | Line 50
50   #include "listener.h"
51   #include "irc_res.h"
52   #include "userhost.h"
53 + #include "watch.h"
54  
55   dlink_list listing_client_list = { NULL, NULL, 0 };
56   /* Pointer to beginning of Client list */
# Line 76 | 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 118 | 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;
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  
124 –    client_p->localClient = BlockHeapAlloc(lclient_heap);
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! */
131  
132 +  client_p->idhnext = client_p;
133    client_p->hnext  = client_p;
134    client_p->status = STAT_UNKNOWN;
135    strcpy(client_p->username, "unknown");
136 +  strcpy(client_p->svid, "0");
137  
138    return client_p;
139   }
# Line 148 | Line 151 | free_client(struct Client *client_p)
151    assert(client_p != NULL);
152    assert(client_p != &me);
153    assert(client_p->hnext == client_p);
154 <  assert(client_p->invited.head == NULL);
154 >  assert(client_p->idhnext == client_p);
155    assert(client_p->channel.head == NULL);
153 –  assert(dlink_list_length(&client_p->invited) == 0);
156    assert(dlink_list_length(&client_p->channel) == 0);
157 +  assert(dlink_list_length(&client_p->whowas) == 0);
158 +  assert(!IsServer(client_p) || IsServer(client_p) && client_p->serv);
159  
156 –  MyFree(client_p->away);
160    MyFree(client_p->serv);
161  
162    if (MyConnect(client_p))
163    {
164 +    assert(client_p->localClient->invited.head == NULL);
165 +    assert(dlink_list_length(&client_p->localClient->invited) == 0);
166 +    assert(dlink_list_length(&client_p->localClient->watches) == 0);
167      assert(IsClosing(client_p) && IsDead(client_p));
168  
169      MyFree(client_p->localClient->response);
# Line 245 | Line 251 | check_pings_list(dlink_list *list)
251        continue;
252      }
253  
248 –    if (client_p->localClient->reject_delay > 0)
249 –    {
250 –      if (client_p->localClient->reject_delay <= CurrentTime)
251 –        exit_client(client_p, &me, "Rejected");
252 –      continue;
253 –    }
254 –
255 –    if (GlobalSetOptions.idletime && IsClient(client_p))
256 –    {
257 –      if (!IsExemptKline(client_p) && !IsOper(client_p) &&
258 –          !IsIdlelined(client_p) &&
259 –          ((CurrentTime - client_p->localClient->last) > GlobalSetOptions.idletime))
260 –      {
261 –        struct ConfItem *conf;
262 –        struct AccessItem *aconf;
263 –
264 –        conf = make_conf_item(KLINE_TYPE);
265 –        aconf = (struct AccessItem *)map_to_conf(conf);
266 –
267 –        DupString(aconf->host, client_p->host);
268 –        DupString(aconf->reason, "idle exceeder");
269 –        DupString(aconf->user, client_p->username);
270 –        aconf->hold = CurrentTime + 60;
271 –        add_temp_line(conf);
272 –
273 –        sendto_realops_flags(UMODE_ALL, L_ALL,
274 –                             "Idle time limit exceeded for %s - temp k-lining",
275 –                             get_client_name(client_p, HIDE_IP));
276 –        exit_client(client_p, &me, aconf->reason);
277 –        continue;
278 –      }
279 –    }
280 –
254      if (!IsRegistered(client_p))
255        ping = CONNECTTIMEOUT, pingwarn = 0;
256      else
257        ping = get_client_ping(client_p, &pingwarn);
258  
259 <    if (ping < CurrentTime - client_p->lasttime)
259 >    if (ping < CurrentTime - client_p->localClient->lasttime)
260      {
261        if (!IsPingSent(client_p))
262        {
# Line 294 | Line 267 | check_pings_list(dlink_list *list)
267           */
268          SetPingSent(client_p);
269          ClearPingWarning(client_p);
270 <        client_p->lasttime = CurrentTime - ping;
270 >        client_p->localClient->lasttime = CurrentTime - ping;
271          sendto_one(client_p, "PING :%s", ID_or_name(&me, client_p));
272        }
273        else
274        {
275 <        if (CurrentTime - client_p->lasttime >= 2 * ping)
275 >        if (CurrentTime - client_p->localClient->lasttime >= 2 * ping)
276          {
277            /*
278             * If the client/server hasn't talked to us in 2*ping seconds
# Line 313 | Line 286 | check_pings_list(dlink_list *list)
286              sendto_realops_flags(UMODE_ALL, L_OPER,
287                                   "No response from %s, closing link",
288                                   get_client_name(client_p, MASK_IP));
289 <            ilog(L_NOTICE, "No response from %s, closing link",
289 >            ilog(LOG_TYPE_IRCD, "No response from %s, closing link",
290                   get_client_name(client_p, HIDE_IP));
291            }
319 –          ircsprintf(scratch, "Ping timeout: %d seconds",
320 –                     (int)(CurrentTime - client_p->lasttime));
292  
293 +          snprintf(scratch, sizeof(scratch), "Ping timeout: %d seconds",
294 +                   (int)(CurrentTime - client_p->localClient->lasttime));
295            exit_client(client_p, &me, scratch);
296          }
297          else if (!IsPingWarning(client_p) && pingwarn > 0 &&
298                   (IsServer(client_p) || IsHandshake(client_p)) &&
299 <                 CurrentTime - client_p->lasttime >= ping + pingwarn)
299 >                 CurrentTime - client_p->localClient->lasttime >= ping + pingwarn)
300          {
301            /*
302             * If the server hasn't replied in pingwarn seconds after sending
# Line 336 | Line 309 | check_pings_list(dlink_list *list)
309            sendto_realops_flags(UMODE_ALL, L_OPER,
310                                 "Warning, no response from %s in %d seconds",
311                                 get_client_name(client_p, MASK_IP), pingwarn);
312 <          ilog(L_NOTICE, "No response from %s in %d seconds",
312 >          ilog(LOG_TYPE_IRCD, "No response from %s in %d seconds",
313                 get_client_name(client_p, HIDE_IP), pingwarn);
314          }
315        }
# Line 359 | Line 332 | check_unknowns_list(void)
332    {
333      struct Client *client_p = ptr->data;
334  
335 <    if (client_p->localClient->reject_delay > 0)
336 <    {
364 <      if (client_p->localClient->reject_delay <= CurrentTime)
365 <        exit_client(client_p, &me, "Rejected");
366 <      continue;
367 <    }
368 <
369 <    /* Check UNKNOWN connections - if they have been in this state
335 >    /*
336 >     * Check UNKNOWN connections - if they have been in this state
337       * for > 30s, close them.
338       */
339 <    if (client_p->firsttime ? ((CurrentTime - client_p->firsttime) > 30) : 0)
340 <      exit_client(client_p, &me, "Connection timed out");
339 >    if (IsAuthFinished(client_p) && (CurrentTime - client_p->localClient->firsttime) > 30)
340 >      exit_client(client_p, &me, "Registration timed out");
341    }
342   }
343  
# Line 483 | Line 450 | static void
450   ban_them(struct Client *client_p, struct ConfItem *conf)
451   {
452    const char *user_reason = NULL;       /* What is sent to user */
486 –  const char *channel_reason = NULL;    /* What is sent to channel */
453    struct AccessItem *aconf = NULL;
454    struct MatchItem *xconf = NULL;
455    const char *type_string = NULL;
# Line 518 | Line 484 | ban_them(struct Client *client_p, struct
484        break;
485    }
486  
487 <  if (ConfigFileEntry.kline_with_reason)
488 <  {
489 <    if (aconf != NULL)
490 <      user_reason = aconf->reason ? aconf->reason : type_string;
525 <    if (xconf != NULL)
526 <      user_reason = xconf->reason ? xconf->reason : type_string;
527 <  }
528 <  else
529 <    user_reason = type_string;
530 <
531 <  if (ConfigFileEntry.kline_reason != NULL)
532 <    channel_reason = ConfigFileEntry.kline_reason;
533 <  else
534 <    channel_reason = user_reason;
487 >  if (aconf != NULL)
488 >    user_reason = aconf->reason ? aconf->reason : type_string;
489 >  if (xconf != NULL)
490 >    user_reason = xconf->reason ? xconf->reason : type_string;
491  
492    sendto_realops_flags(UMODE_ALL, L_ALL, "%s active for %s",
493                         type_string, get_client_name(client_p, HIDE_IP));
# Line 540 | Line 496 | ban_them(struct Client *client_p, struct
496      sendto_one(client_p, form_str(ERR_YOUREBANNEDCREEP),
497                 me.name, client_p->name, user_reason);
498  
499 <  exit_client(client_p, &me, channel_reason);
499 >  exit_client(client_p, &me, user_reason);
500   }
501  
502   /* update_client_exit_stats()
# Line 552 | Line 508 | ban_them(struct Client *client_p, struct
508   static void
509   update_client_exit_stats(struct Client *client_p)
510   {
511 <  if (IsServer(client_p))
556 <  {
557 <    sendto_realops_flags(UMODE_EXTERNAL, L_ALL,
558 <                         "Server %s split from %s",
559 <                         client_p->name, client_p->servptr->name);
560 <  }
561 <  else if (IsClient(client_p))
511 >  if (IsClient(client_p))
512    {
513 +    assert(Count.total > 0);
514      --Count.total;
515 <    if (IsOper(client_p))
515 >    if (HasUMode(client_p, UMODE_OPER))
516        --Count.oper;
517 <    if (IsInvisible(client_p))
517 >    if (HasUMode(client_p, UMODE_INVISIBLE))
518        --Count.invisi;
519    }
520 +  else if (IsServer(client_p))
521 +    sendto_realops_flags(UMODE_EXTERNAL, L_ALL, "Server %s split from %s",
522 +                         client_p->name, client_p->servptr->name);
523  
524    if (splitchecking && !splitmode)
525      check_splitmode(NULL);
# Line 577 | Line 531 | update_client_exit_stats(struct Client *
531   * output       - return client pointer
532   * side effects - find person by (nick)name
533   */
580 – /* XXX - ugly wrapper */
534   struct Client *
535   find_person(const struct Client *client_p, const char *name)
536   {
537 <  struct Client *c2ptr;
537 >  struct Client *c2ptr = NULL;
538  
539    if (IsDigit(*name))
540    {
541      if ((c2ptr = hash_find_id(name)) != NULL)
542      {
543        /* invisible users shall not be found by UID guessing */
544 <      if (IsInvisible(c2ptr) && !IsServer(client_p))
545 <        c2ptr = NULL;
544 >      if (HasUMode(c2ptr, UMODE_INVISIBLE))
545 >        if (!IsServer(client_p) && !HasFlag(client_p, FLAGS_SERVICE))
546 >          c2ptr = NULL;
547      }
548    }
549    else
550 <    c2ptr = find_client(name);
550 >    c2ptr = hash_find_client(name);
551  
552    return ((c2ptr != NULL && IsClient(c2ptr)) ? c2ptr : NULL);
553   }
# Line 613 | Line 567 | find_chasing(struct Client *client_p, st
567      *chasing = 0;
568  
569    if (who)
570 <    return(who);
570 >    return who;
571  
572    if (IsDigit(*user))
573 <    return(NULL);
573 >    return NULL;
574  
575    if ((who = get_history(user,
576                          (time_t)ConfigFileEntry.kill_chase_time_limit))
# Line 624 | Line 578 | find_chasing(struct Client *client_p, st
578    {
579      sendto_one(source_p, form_str(ERR_NOSUCHNICK),
580                 me.name, source_p->name, user);
581 <    return(NULL);
581 >    return NULL;
582    }
583  
584    if (chasing)
585      *chasing = 1;
586  
587 <  return(who);
587 >  return who;
588   }
589  
590   /*
# Line 652 | Line 606 | find_chasing(struct Client *client_p, st
606   *        to modify what it points!!!
607   */
608   const char *
609 < get_client_name(struct Client *client, int showip)
609 > get_client_name(const struct Client *client, enum addr_mask_type type)
610   {
611    static char nbuf[HOSTLEN * 2 + USERLEN + 5];
612  
613    assert(client != NULL);
614  
615 <  if (irccmp(client->name, client->host) == 0)
616 <    return(client->name);
615 >  if (!MyConnect(client))
616 >    return client->name;
617  
618 <  if (ConfigServerHide.hide_server_ips)
619 <    if (IsServer(client) || IsConnecting(client) || IsHandshake(client))
620 <      showip = MASK_IP;
618 >  if (IsServer(client) || IsConnecting(client) || IsHandshake(client))
619 >  {
620 >    if (!irccmp(client->name, client->host))
621 >      return client->name;
622 >    else if (ConfigServerHide.hide_server_ips)
623 >      type = MASK_IP;
624 >  }
625  
626    if (ConfigFileEntry.hide_spoof_ips)
627 <    if (showip == SHOW_IP && IsIPSpoof(client))
628 <      showip = MASK_IP;
627 >    if (type == SHOW_IP && IsIPSpoof(client))
628 >      type = MASK_IP;
629  
630    /* And finally, let's get the host information, ip or name */
631 <  switch (showip)
631 >  switch (type)
632    {
633      case SHOW_IP:
634 <      if (MyConnect(client))
635 <      {
636 <        ircsprintf(nbuf, "%s[%s@%s]", client->name, client->username,
637 <                   client->sockhost);
680 <        break;
681 <      }
634 >      snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]",
635 >               client->name,
636 >               client->username, client->sockhost);
637 >      break;
638      case MASK_IP:
639 <      ircsprintf(nbuf, "%s[%s@255.255.255.255]", client->name,
640 <                 client->username);
639 >      if (client->localClient->aftype == AF_INET)
640 >        snprintf(nbuf, sizeof(nbuf), "%s[%s@255.255.255.255]",
641 >                 client->name, client->username);
642 >      else
643 >        snprintf(nbuf, sizeof(nbuf), "%s[%s@ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]",
644 >                 client->name, client->username);
645        break;
646      default:
647 <      ircsprintf(nbuf, "%s[%s@%s]", client->name, client->username,
648 <                 client->host);
647 >      snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]",
648 >               client->name,
649 >               client->username, client->host);
650    }
651  
652 <  return(nbuf);
652 >  return nbuf;
653   }
654  
655   void
656   free_exited_clients(void)
657   {
658 <  dlink_node *ptr, *next;
698 <  struct Client *target_p;
658 >  dlink_node *ptr = NULL, *next = NULL;
659    
660    DLINK_FOREACH_SAFE(ptr, next, dead_list.head)
661    {
662 <    target_p = ptr->data;
703 <
704 <    if (ptr->data == NULL)
705 <    {
706 <      sendto_realops_flags(UMODE_ALL, L_ALL,
707 <                           "Warning: null client on dead_list!");
708 <      dlinkDelete(ptr, &dead_list);
709 <      free_dlink_node(ptr);
710 <      continue;
711 <    }
712 <
713 <    free_client(target_p);
662 >    free_client(ptr->data);
663      dlinkDelete(ptr, &dead_list);
664      free_dlink_node(ptr);
665    }
# Line 729 | Line 678 | exit_one_client(struct Client *source_p,
678  
679    assert(!IsMe(source_p));
680  
681 <  if (IsServer(source_p))
733 <  {
734 <    dlinkDelete(&source_p->lnode, &source_p->servptr->serv->servers);
735 <
736 <    if ((lp = dlinkFindDelete(&global_serv_list, source_p)) != NULL)
737 <      free_dlink_node(lp);
738 <
739 <    if (!MyConnect(source_p))
740 <    {
741 <      source_p->from->serv->dep_servers--;
742 <      assert(source_p->from->serv->dep_servers > 0);
743 <    }
744 <  }
745 <  else if (IsClient(source_p))
681 >  if (IsClient(source_p))
682    {
683      if (source_p->servptr->serv != NULL)
684 <      dlinkDelete(&source_p->lnode, &source_p->servptr->serv->users);
684 >      dlinkDelete(&source_p->lnode, &source_p->servptr->serv->client_list);
685  
686 <    /* If a person is on a channel, send a QUIT notice
687 <    ** to every client (person) on the same channel (so
688 <    ** that the client can show the "**signoff" message).
689 <    ** (Note: The notice is to the local clients *only*)
690 <    */
686 >    /*
687 >     * If a person is on a channel, send a QUIT notice
688 >     * to every client (person) on the same channel (so
689 >     * that the client can show the "**signoff" message).
690 >     * (Note: The notice is to the local clients *only*)
691 >     */
692      sendto_common_channels_local(source_p, 0, ":%s!%s@%s QUIT :%s",
693                                   source_p->name, source_p->username,
694                                   source_p->host, quitmsg);
695      DLINK_FOREACH_SAFE(lp, next_lp, source_p->channel.head)
696        remove_user_from_channel(lp->data);
697  
761 –    /* Clean up invitefield */
762 –    DLINK_FOREACH_SAFE(lp, next_lp, source_p->invited.head)
763 –      del_invite(lp->data, source_p);
764 –
765 –    /* Clean up allow lists */
766 –    del_all_accepts(source_p);
698      add_history(source_p, 0);
699      off_history(source_p);
700  
701 <    if (!MyConnect(source_p))
701 >    watch_check_hash(source_p, RPL_LOGOFF);
702 >
703 >    if (MyConnect(source_p))
704      {
705 <      source_p->from->serv->dep_users--;
706 <      assert(source_p->from->serv->dep_users >= 0);
705 >      /* Clean up invitefield */
706 >      DLINK_FOREACH_SAFE(lp, next_lp, source_p->localClient->invited.head)
707 >        del_invite(lp->data, source_p);
708 >
709 >      del_all_accepts(source_p);
710      }
711    }
712 +  else if (IsServer(source_p))
713 +  {
714 +    dlinkDelete(&source_p->lnode, &source_p->servptr->serv->server_list);
715 +
716 +    if ((lp = dlinkFindDelete(&global_serv_list, source_p)) != NULL)
717 +      free_dlink_node(lp);
718 +  }
719  
720    /* Remove source_p from the client lists */
721    if (HasID(source_p))
# Line 812 | Line 755 | exit_one_client(struct Client *source_p,
755   static void
756   recurse_send_quits(struct Client *original_source_p, struct Client *source_p,
757                     struct Client *from, struct Client *to, const char *comment,
758 <                   const char *splitstr, const char *myname)
758 >                   const char *splitstr)
759   {
760    dlink_node *ptr, *next;
761    struct Client *target_p;
819 –  int hidden = match(myname, source_p->name);
762  
763    assert(to != source_p);  /* should be already removed from serv_list */
764  
765    /* If this server can handle quit storm (QS) removal
766     * of dependents, just send the SQUIT
825 –   *
826 –   * Always check *all* dependent servers if some of them are
827 –   * hidden behind fakename. If so, send out the QUITs -adx
767     */
768 <  if (hidden || !IsCapable(to, CAP_QS))
769 <    DLINK_FOREACH_SAFE(ptr, next, source_p->serv->users.head)
768 >  if (!IsCapable(to, CAP_QS))
769 >    DLINK_FOREACH_SAFE(ptr, next, source_p->serv->client_list.head)
770      {
771        target_p = ptr->data;
772        sendto_one(to, ":%s QUIT :%s", target_p->name, splitstr);
773      }
774  
775 <  DLINK_FOREACH_SAFE(ptr, next, source_p->serv->servers.head)
775 >  DLINK_FOREACH_SAFE(ptr, next, source_p->serv->server_list.head)
776      recurse_send_quits(original_source_p, ptr->data, from, to,
777 <                       comment, splitstr, myname);
777 >                       comment, splitstr);
778  
779 <  if (!hidden && ((source_p == original_source_p && to != from) ||
780 <                  !IsCapable(to, CAP_QS)))
779 >  if ((source_p == original_source_p && to != from) ||
780 >                  !IsCapable(to, CAP_QS))
781    {
782      /* don't use a prefix here - we have to be 100% sure the message
783       * will be accepted without Unknown prefix etc.. */
# Line 857 | Line 796 | recurse_remove_clients(struct Client *so
796   {
797    dlink_node *ptr, *next;
798  
799 <  DLINK_FOREACH_SAFE(ptr, next, source_p->serv->users.head)
799 >  DLINK_FOREACH_SAFE(ptr, next, source_p->serv->client_list.head)
800      exit_one_client(ptr->data, quitmsg);
801  
802 <  DLINK_FOREACH_SAFE(ptr, next, source_p->serv->servers.head)
802 >  DLINK_FOREACH_SAFE(ptr, next, source_p->serv->server_list.head)
803    {
804      recurse_remove_clients(ptr->data, quitmsg);
805      exit_one_client(ptr->data, quitmsg);
806    }
868 –
869 –  assert(source_p->serv->dep_servers == 1);
870 –  assert(source_p->serv->dep_users == 0);
807   }
808  
809   /*
# Line 879 | Line 815 | static void
815   remove_dependents(struct Client *source_p, struct Client *from,
816                    const char *comment, const char *splitstr)
817   {
818 <  struct Client *to;
883 <  struct ConfItem *conf;
884 <  static char myname[HOSTLEN+1];
885 <  dlink_node *ptr;
818 >  dlink_node *ptr = NULL;
819  
820    DLINK_FOREACH(ptr, serv_list.head)
821 <  {
822 <    to = ptr->data;
890 <
891 <    if ((conf = to->serv->sconf) != NULL)
892 <      strlcpy(myname, my_name_for_link(conf), sizeof(myname));
893 <    else
894 <      strlcpy(myname, me.name, sizeof(myname));
895 <    recurse_send_quits(source_p, source_p, from, to,
896 <                       comment, splitstr, myname);
897 <  }
821 >    recurse_send_quits(source_p, source_p, from, ptr->data,
822 >                       comment, splitstr);
823  
824    recurse_remove_clients(source_p, splitstr);
825   }
# Line 904 | Line 829 | remove_dependents(struct Client *source_
829   * this on any struct Client, regardless of its state.
830   *
831   * Note, you shouldn't exit remote _users_ without first doing
832 < * SetKilled and propagating a kill or similar message. However,
833 < * it is perfectly correct to call exit_client to force a _server_
832 > * AddFlag(x, FLAGS_KILLED) and propagating a kill or similar message.
833 > * However, it is perfectly correct to call exit_client to force a _server_
834   * quit (either local or remote one).
835   *
836   * inputs:       - a client pointer that is going to be exited
# Line 920 | Line 845 | remove_dependents(struct Client *source_
845   void
846   exit_client(struct Client *source_p, struct Client *from, const char *comment)
847   {
848 <  dlink_node *m;
848 >  dlink_node *m = NULL;
849  
850    if (MyConnect(source_p))
851    {
# Line 935 | Line 860 | exit_client(struct Client *source_p, str
860      if (IsIpHash(source_p))
861        remove_one_ip(&source_p->localClient->ip);
862  
863 <    delete_auth(source_p);
863 >    if (source_p->localClient->auth)
864 >    {
865 >      delete_auth(source_p->localClient->auth);
866 >      source_p->localClient->auth = NULL;
867 >    }
868  
869 <    /* This source_p could have status of one of STAT_UNKNOWN, STAT_CONNECTING
869 >    /*
870 >     * This source_p could have status of one of STAT_UNKNOWN, STAT_CONNECTING
871       * STAT_HANDSHAKE or STAT_UNKNOWN
872       * all of which are lumped together into unknown_list
873       *
# Line 945 | Line 875 | exit_client(struct Client *source_p, str
875       */
876      if (!IsRegistered(source_p))
877      {
878 <      if ((m = dlinkFindDelete(&unknown_list, source_p)) != NULL)
879 <        free_dlink_node(m);
878 >      assert(dlinkFind(&unknown_list, source_p));
879 >
880 >      dlinkDelete(&source_p->localClient->lclient_node, &unknown_list);
881      }
882      else if (IsClient(source_p))
883      {
884 +      time_t on_for = CurrentTime - source_p->localClient->firsttime;
885 +      assert(Count.local > 0);
886        Count.local--;
887  
888 <      if (IsOper(source_p))
956 <      {
888 >      if (HasUMode(source_p, UMODE_OPER))
889          if ((m = dlinkFindDelete(&oper_list, source_p)) != NULL)
890            free_dlink_node(m);
959 –      }
891  
892 +      assert(dlinkFind(&local_client_list, source_p));
893        dlinkDelete(&source_p->localClient->lclient_node, &local_client_list);
894 +
895        if (source_p->localClient->list_task != NULL)
896          free_list_task(source_p->localClient->list_task, source_p);
897  
898 +      watch_del_watch_list(source_p);
899        sendto_realops_flags(UMODE_CCONN, L_ALL, "Client exiting: %s (%s@%s) [%s] [%s]",
900                             source_p->name, source_p->username, source_p->host, comment,
901                             ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
902                             "255.255.255.255" : source_p->sockhost);
903 +      sendto_realops_flags(UMODE_CCONN_FULL, L_ALL, "CLIEXIT: %s %s %s %s 0 %s",
904 +                           source_p->name,
905 +                           source_p->username,
906 +                           source_p->host,
907 +                           ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
908 +                           "255.255.255.255" : source_p->sockhost,
909 +                           comment);
910 +      ilog(LOG_TYPE_USER, "%s (%3u:%02u:%02u): %s!%s@%s %llu/%llu",
911 +           myctime(source_p->localClient->firsttime), (unsigned int)(on_for / 3600),
912 +           (unsigned int)((on_for % 3600)/60), (unsigned int)(on_for % 60),
913 +           source_p->name, source_p->username, source_p->host,
914 +           source_p->localClient->send.bytes>>10,
915 +           source_p->localClient->recv.bytes>>10);
916 +    }
917 +    else if (IsServer(source_p))
918 +    {
919 +      assert(Count.myserver > 0);
920 +      --Count.myserver;
921 +
922 +      assert(dlinkFind(&serv_list, source_p));
923 +      dlinkDelete(&source_p->localClient->lclient_node, &serv_list);
924 +      unset_chcap_usage_counts(source_p);
925      }
926  
971 –    /* As soon as a client is known to be a server of some sort
972 –     * it has to be put on the serv_list, or SJOIN's to this new server
973 –     * from the connect burst will not be seen.
974 –     */
975 –    if (IsServer(source_p) || IsConnecting(source_p) ||
976 –        IsHandshake(source_p))
977 –    {
978 –      if ((m = dlinkFindDelete(&serv_list, source_p)) != NULL)
979 –      {
980 –        free_dlink_node(m);
981 –        unset_chcap_usage_counts(source_p);
982 –      }
983 –
984 –      if (IsServer(source_p))
985 –      {
986 –        Count.myserver--;
987 –        if (ServerInfo.hub)
988 –          remove_lazylink_flags(source_p->localClient->serverMask);
989 –        else
990 –          uplink = NULL;
991 –      }
992 –    }
993 –
994 –    log_user_exit(source_p);
995 –
927      if (!IsDead(source_p))
928      {
929        if (IsServer(source_p))
# Line 1028 | Line 959 | exit_client(struct Client *source_p, str
959      assert(source_p->serv != NULL && source_p->servptr != NULL);
960  
961      if (ConfigServerHide.hide_servers)
962 <      /* set netsplit message to "*.net *.split" to still show
962 >      /*
963 >       * Set netsplit message to "*.net *.split" to still show
964         * that its a split, but hide the servers splitting
965         */
966        strcpy(splitstr, "*.net *.split");
# Line 1042 | Line 974 | exit_client(struct Client *source_p, str
974      {
975        sendto_realops_flags(UMODE_ALL, L_ALL,
976                             "%s was connected for %d seconds.  %llu/%llu sendK/recvK.",
977 <                           source_p->name, (int)(CurrentTime - source_p->firsttime),
977 >                           source_p->name, (int)(CurrentTime - source_p->localClient->firsttime),
978                             source_p->localClient->send.bytes >> 10,
979                             source_p->localClient->recv.bytes >> 10);
980 <      ilog(L_NOTICE, "%s was connected for %d seconds.  %llu/%llu sendK/recvK.",
981 <           source_p->name, (int)(CurrentTime - source_p->firsttime),
980 >      ilog(LOG_TYPE_IRCD, "%s was connected for %d seconds.  %llu/%llu sendK/recvK.",
981 >           source_p->name, (int)(CurrentTime - source_p->localClient->firsttime),
982             source_p->localClient->send.bytes >> 10,
983             source_p->localClient->recv.bytes >> 10);
984      }
985    }
986 <  else if (IsClient(source_p) && !IsKilled(source_p))
986 >  else if (IsClient(source_p) && !HasFlag(source_p, FLAGS_KILLED))
987    {
988 <    sendto_server(NULL, source_p, NULL, CAP_TS6, NOCAPS, NOFLAGS,
988 >    sendto_server(from->from, CAP_TS6, NOCAPS,
989                    ":%s QUIT :%s", ID(source_p), comment);
990 <    sendto_server(NULL, source_p, NULL, NOCAPS, CAP_TS6, NOFLAGS,
990 >    sendto_server(from->from, NOCAPS, CAP_TS6,
991                    ":%s QUIT :%s", source_p->name, comment);
992    }
993  
# Line 1114 | Line 1046 | dead_link_on_read(struct Client *client_
1046  
1047    if (IsServer(client_p) || IsHandshake(client_p))
1048    {
1049 <    int connected = CurrentTime - client_p->firsttime;
1049 >    int connected = CurrentTime - client_p->localClient->firsttime;
1050        
1051      if (error == 0)
1052      {
# Line 1128 | Line 1060 | dead_link_on_read(struct Client *client_
1060                             "Server %s closed the connection",
1061                             get_client_name(client_p, MASK_IP));
1062  
1063 <      ilog(L_NOTICE, "Server %s closed the connection",
1063 >      ilog(LOG_TYPE_IRCD, "Server %s closed the connection",
1064             get_client_name(client_p, SHOW_IP));
1065      }
1066      else
1067      {
1068 <      report_error(L_ADMIN, "Lost connection to %s: %d",
1068 >      report_error(L_ADMIN, "Lost connection to %s: %s",
1069                     get_client_name(client_p, SHOW_IP), current_error);
1070 <      report_error(L_OPER, "Lost connection to %s: %d",
1070 >      report_error(L_OPER, "Lost connection to %s: %s",
1071                     get_client_name(client_p, MASK_IP), current_error);
1072      }
1073  
# Line 1151 | Line 1083 | dead_link_on_read(struct Client *client_
1083      strlcpy(errmsg, "Remote host closed the connection",
1084              sizeof(errmsg));
1085    else
1086 <    ircsprintf(errmsg, "Read error: %s",
1087 <               strerror(current_error));
1086 >    snprintf(errmsg, sizeof(errmsg), "Read error: %s",
1087 >             strerror(current_error));
1088  
1089    exit_client(client_p, &me, errmsg);
1090   }
# Line 1192 | Line 1124 | exit_aborted_clients(void)
1124  
1125   /*
1126   * accept processing, this adds a form of "caller ID" to ircd
1127 < *
1127 > *
1128   * If a client puts themselves into "caller ID only" mode,
1129 < * only clients that match a client pointer they have put on
1129 > * only clients that match a client pointer they have put on
1130   * the accept list will be allowed to message them.
1131   *
1132 < * [ source.on_allow_list ] -> [ target1 ] -> [ target2 ]
1201 < *
1202 < * [target.allow_list] -> [ source1 ] -> [source2 ]
1203 < *
1204 < * i.e. a target will have a link list of source pointers it will allow
1205 < * each source client then has a back pointer pointing back
1206 < * to the client that has it on its accept list.
1207 < * This allows for exit_one_client to remove these now bogus entries
1208 < * from any client having an accept on them.
1132 > * Diane Bruce, "Dianora" db@db.net
1133   */
1134  
1135 < /* accept_message()
1136 < *
1213 < * inputs       - pointer to source client
1214 < *              - pointer to target client
1215 < * output       - 1 if accept this message 0 if not
1216 < * side effects - See if source is on target's allow list
1217 < */
1218 < int
1219 < accept_message(struct Client *source, struct Client *target)
1135 > void
1136 > del_accept(struct split_nuh_item *accept_p, struct Client *client_p)
1137   {
1138 <  dlink_node *ptr;
1222 <
1223 <  DLINK_FOREACH(ptr, target->allow_list.head)
1224 <  {
1225 <    struct Client *target_p = ptr->data;
1138 >  dlinkDelete(&accept_p->node, &client_p->localClient->acceptlist);
1139  
1140 <    if (source == target_p)
1141 <      return (1);
1142 <  }
1143 <
1231 <  if (IsSoftCallerId(target))
1232 <  {
1233 <    DLINK_FOREACH(ptr, target->channel.head)
1234 <      if (IsMember(source, ptr->data))
1235 <        return (1);
1236 <  }
1237 <
1238 <  return (0);
1140 >  MyFree(accept_p->nickptr);
1141 >  MyFree(accept_p->userptr);
1142 >  MyFree(accept_p->hostptr);
1143 >  MyFree(accept_p);
1144   }
1145  
1146 < /* del_from_accept()
1147 < *
1148 < * inputs       - pointer to source client
1244 < *              - pointer to target client
1245 < * output       - NONE
1246 < * side effects - Delete's source pointer to targets allow list
1247 < *
1248 < * Walk through the target's accept list, remove if source is found,
1249 < * Then walk through the source's on_accept_list remove target if found.
1250 < */
1251 < void
1252 < del_from_accept(struct Client *source, struct Client *target)
1146 > struct split_nuh_item *
1147 > find_accept(const char *nick, const char *user,
1148 >            const char *host, struct Client *client_p, int do_match)
1149   {
1150 <  dlink_node *ptr;
1151 <  dlink_node *ptr2;
1152 <  dlink_node *next_ptr;
1257 <  dlink_node *next_ptr2;
1258 <  struct Client *target_p;
1150 >  dlink_node *ptr = NULL;
1151 >  /* XXX We wouldn't need that if match() would return 0 on match */
1152 >  int (*cmpfunc)(const char *, const char *) = do_match ? match : irccmp;
1153  
1154 <  DLINK_FOREACH_SAFE(ptr, next_ptr, target->allow_list.head)
1154 >  DLINK_FOREACH(ptr, client_p->localClient->acceptlist.head)
1155    {
1156 <    target_p = ptr->data;
1263 <
1264 <    if (source == target_p)
1265 <    {
1266 <      dlinkDelete(ptr, &target->allow_list);
1267 <      free_dlink_node(ptr);
1156 >    struct split_nuh_item *accept_p = ptr->data;
1157  
1158 <      DLINK_FOREACH_SAFE(ptr2, next_ptr2, source->on_allow_list.head)
1159 <      {
1160 <        target_p = ptr2->data;
1161 <
1273 <        if (target == target_p)
1274 <        {
1275 <          dlinkDelete(ptr2, &source->on_allow_list);
1276 <          free_dlink_node(ptr2);
1277 <        }
1278 <      }
1279 <    }
1158 >    if (cmpfunc(accept_p->nickptr, nick) == do_match &&
1159 >        cmpfunc(accept_p->userptr, user) == do_match &&
1160 >        cmpfunc(accept_p->hostptr, host) == do_match)
1161 >      return accept_p;
1162    }
1281 – }
1282 –
1283 – /* del_all_accepts()
1284 – *
1285 – * inputs       - pointer to exiting client
1286 – * output       - NONE
1287 – * side effects - Walk through given clients allow_list and on_allow_list
1288 – *                remove all references to this client
1289 – */
1290 – void
1291 – del_all_accepts(struct Client *client_p)
1292 – {
1293 –  dlink_node *ptr, *next_ptr;
1294 –
1295 –  DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->allow_list.head)
1296 –    del_from_accept(ptr->data, client_p);
1163  
1164 <  DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->on_allow_list.head)
1299 <    del_from_accept(client_p, ptr->data);
1164 >  return NULL;
1165   }
1166  
1167 < /* del_all_their_accepts()
1303 < *
1304 < * inputs       - pointer to exiting client
1305 < * output       - NONE
1306 < * side effects - Walk through given clients on_allow_list
1307 < *                remove all references to this client,
1308 < *                allow this client to keep their own allow_list
1309 < */
1310 < void
1311 < del_all_their_accepts(struct Client *client_p)
1312 < {
1313 <  dlink_node *ptr, *next_ptr;
1314 <
1315 <  DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->on_allow_list.head)
1316 <    del_from_accept(client_p, ptr->data);
1317 < }
1318 <
1319 < /* set_initial_nick()
1320 < *
1321 < * inputs
1322 < * output
1323 < * side effects -
1167 > /* accept_message()
1168   *
1169 < * This function is only called to set up an initially registering
1170 < * client.
1169 > * inputs       - pointer to source client
1170 > *              - pointer to target client
1171 > * output       - 1 if accept this message 0 if not
1172 > * side effects - See if source is on target's allow list
1173   */
1174 < void
1175 < set_initial_nick(struct Client *client_p, struct Client *source_p,
1176 <                 const char *nick)
1174 > int
1175 > accept_message(struct Client *source,
1176 >               struct Client *target)
1177   {
1178 < char buf[USERLEN + 1];
1333 <
1334 <  /* Client setting NICK the first time */
1335 <  
1336 <  /* This had to be copied here to avoid problems.. */
1337 <  source_p->tsinfo = CurrentTime;
1178 >  dlink_node *ptr = NULL;
1179  
1180 <  if (source_p->name[0])
1181 <    hash_del_client(source_p);
1180 >  if (source == target || find_accept(source->name, source->username,
1181 >                                      source->host, target, 1))
1182 >    return 1;
1183  
1184 <  strlcpy(source_p->name, nick, sizeof(source_p->name));
1185 <  hash_add_client(source_p);
1186 <
1187 <  /* fd_desc is long enough */
1346 <  fd_note(&client_p->localClient->fd, "Nick: %s", nick);
1347 <  
1348 <  /* They have the nick they want now.. */
1349 <  client_p->llname[0] = '\0';
1350 <
1351 <  if (source_p->flags & FLAGS_GOTUSER)
1352 <  {
1353 <    strlcpy(buf, source_p->username, sizeof(buf));
1184 >  if (HasUMode(target, UMODE_SOFTCALLERID))
1185 >    DLINK_FOREACH(ptr, target->channel.head)
1186 >      if (IsMember(source, ((struct Membership *)ptr->data)->chptr))
1187 >        return 1;
1188  
1189 <    /*
1356 <     * USER already received, now we have NICK.
1357 <     * *NOTE* For servers "NICK" *must* precede the
1358 <     * user message (giving USER before NICK is possible
1359 <     * only for local client connection!). register_user
1360 <     * may reject the client and call exit_client for it
1361 <     * --must test this and exit m_nick too!!!
1362 <     */
1363 <    register_local_user(client_p, source_p, nick, buf);
1364 <  }
1189 >  return 0;
1190   }
1191  
1192 < /* change_local_nick()
1192 > /* del_all_accepts()
1193   *
1194 < * inputs       - pointer to server
1195 < *              - pointer to client
1196 < *              - nick
1372 < * output       -
1373 < * side effects - changes nick of a LOCAL user
1194 > * inputs       - pointer to exiting client
1195 > * output       - NONE
1196 > * side effects - Walk through given clients acceptlist and remove all entries
1197   */
1198   void
1199 < change_local_nick(struct Client *client_p, struct Client *source_p, const char *nick)
1199 > del_all_accepts(struct Client *client_p)
1200   {
1201 <  /*
1379 <  ** Client just changing his/her nick. If he/she is
1380 <  ** on a channel, send note of change to all clients
1381 <  ** on that channel. Propagate notice to other servers.
1382 <  */
1383 <  if ((source_p->localClient->last_nick_change +
1384 <       ConfigFileEntry.max_nick_time) < CurrentTime)
1385 <    source_p->localClient->number_of_nick_changes = 0;
1386 <  source_p->localClient->last_nick_change = CurrentTime;
1387 <  source_p->localClient->number_of_nick_changes++;
1388 <
1389 <  if ((ConfigFileEntry.anti_nick_flood &&
1390 <      (source_p->localClient->number_of_nick_changes
1391 <       <= ConfigFileEntry.max_nick_changes)) ||
1392 <     !ConfigFileEntry.anti_nick_flood ||
1393 <     (IsOper(source_p) && ConfigFileEntry.no_oper_flood))
1394 <  {
1395 <    if (irccmp(source_p->name, nick))
1396 <      source_p->tsinfo = CurrentTime;
1397 <
1398 <    /* XXX - the format of this notice should eventually be changed
1399 <     * to either %s[%s@%s], or even better would be get_client_name() -bill
1400 <     */
1401 <    sendto_realops_flags(UMODE_NCHANGE, L_ALL, "Nick change: From %s to %s [%s@%s]",
1402 <                         source_p->name, nick, source_p->username, source_p->host);
1403 <    sendto_common_channels_local(source_p, 1, ":%s!%s@%s NICK :%s",
1404 <                                 source_p->name, source_p->username,
1405 <                                 source_p->host, nick);
1406 <
1407 <    add_history(source_p, 1);
1408 <          
1409 <         /* Only hubs care about lazy link nicks not being sent on yet
1410 <           * lazylink leafs/leafs always send their nicks up to hub,
1411 <           * hence must always propagate nick changes.
1412 <           * hubs might not propagate a nick change, if the leaf
1413 <           * does not know about that client yet.
1414 <           */
1415 <    sendto_server(client_p, source_p, NULL, CAP_TS6, NOCAPS, NOFLAGS,
1416 <                  ":%s NICK %s :%lu",
1417 <                  ID(source_p), nick, (unsigned long)source_p->tsinfo);
1418 <    sendto_server(client_p, source_p, NULL, NOCAPS, CAP_TS6, NOFLAGS,
1419 <                  ":%s NICK %s :%lu",
1420 <                  source_p->name, nick, (unsigned long)source_p->tsinfo);
1421 <  }
1422 <  else
1423 <  {
1424 <    sendto_one(source_p, form_str(ERR_NICKTOOFAST),
1425 <               me.name, source_p->name, source_p->name,
1426 <               nick, ConfigFileEntry.max_nick_time);
1427 <    return;
1428 <  }
1429 <
1430 <  /* Finally, add to hash */
1431 <  if (source_p->name[0])
1432 <    hash_del_client(source_p);
1433 <
1434 <  strcpy(source_p->name, nick);
1435 <  hash_add_client(source_p);
1436 <
1437 <  /* Make sure everyone that has this client on its accept list
1438 <   * loses that reference.
1439 <   */
1440 <  del_all_their_accepts(source_p);
1201 >  dlink_node *ptr = NULL, *next_ptr = NULL;
1202  
1203 <  /* fd_desc is long enough */
1204 <  fd_note(&client_p->localClient->fd, "Nick: %s", nick);
1203 >  DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->localClient->acceptlist.head)
1204 >    del_accept(ptr->data, client_p);
1205   }

Comparing:
ircd-hybrid/src/client.c (property svn:keywords), Revision 32 by knight, Sun Oct 2 20:41:23 2005 UTC vs.
ircd-hybrid/trunk/src/client.c (property svn:keywords), Revision 1592 by michael, Sat Oct 27 21:02:32 2012 UTC

# Line 1 | Line 1
1 < Revision
1 > Id Revision

Diff Legend

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