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 6513 by michael, Sun Sep 6 18:32:38 2015 UTC vs.
Revision 7967 by michael, Mon Mar 13 19:10:19 2017 UTC

# Line 1 | Line 1
1   /*
2   *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (c) 1997-2015 ircd-hybrid development team
4 > *  Copyright (c) 1997-2017 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 35 | Line 35
35   #include "auth.h"
36   #include "s_bsd.h"
37   #include "conf.h"
38 + #include "conf_gecos.h"
39   #include "log.h"
40   #include "misc.h"
41   #include "server.h"
# Line 81 | Line 82 | static dlink_node *eac_next;  /* next ab
82   *                      'from'). ('from' is a local client!!).
83   */
84   struct Client *
85 < make_client(struct Client *from)
85 > client_make(struct Client *from)
86   {
87    struct Client *const client_p = mp_pool_get(client_pool);
88  
89 <  if (!from)
89 >  if (from)
90 >    client_p->from = from;
91 >  else
92    {
93      client_p->from = client_p;  /* 'from' of local client is self! */
94      client_p->connection = mp_pool_get(connection_pool);
# Line 97 | Line 100 | make_client(struct Client *from)
100      /* as good a place as any... */
101      dlinkAdd(client_p, &client_p->connection->lclient_node, &unknown_list);
102    }
100  else
101    client_p->from = from;
103  
104    client_p->idhnext = client_p;
105    client_p->hnext = client_p;
# Line 110 | Line 111 | make_client(struct Client *from)
111   }
112  
113   /*
114 < * free_client
114 > * client_free
115   *
116   * inputs       - pointer to client
117   * output       - NONE
118   * side effects - client pointed to has its memory freed
119   */
120   static void
121 < free_client(struct Client *client_p)
121 > client_free(struct Client *client_p)
122   {
123    assert(client_p != &me);
124    assert(client_p->hnext == client_p);
125    assert(client_p->idhnext == client_p);
126    assert(client_p->channel.head == NULL);
127    assert(dlink_list_length(&client_p->channel) == 0);
128 <  assert(dlink_list_length(&client_p->whowas) == 0);
128 >  assert(dlink_list_length(&client_p->whowas_list) == 0);
129    assert(dlink_list_length(&client_p->svstags) == 0);
130  
131 <  MyFree(client_p->serv);
132 <  MyFree(client_p->certfp);
131 >  xfree(client_p->serv);
132 >  xfree(client_p->certfp);
133  
134    if (MyConnect(client_p))
135    {
# Line 137 | Line 138 | free_client(struct Client *client_p)
138      assert(dlink_list_length(&client_p->connection->watches) == 0);
139      assert(HasFlag(client_p, FLAGS_CLOSING) && IsDead(client_p));
140  
140    MyFree(client_p->connection->challenge_response);
141    client_p->connection->challenge_response = NULL;
142    MyFree(client_p->connection->challenge_operator);
143    client_p->connection->challenge_operator = NULL;
144
141      /*
142       * Clean up extra sockets from listen {} blocks which have been discarded.
143       */
# Line 162 | Line 158 | free_client(struct Client *client_p)
158  
159   void
160   client_attach_svstag(struct Client *client_p, unsigned int numeric,
161 <                     const char *umodes, const char *const tag)
161 >                     const char *umodes, const char *tag)
162   {
167  struct ServicesTag *svstag = NULL;
163    const struct user_modes *tab = NULL;
164  
165    if (numeric >= ERR_LAST_ERR_MSG || *umodes != '+')
166      return;
167  
168 <  svstag = MyCalloc(sizeof(*svstag));
168 >  struct ServicesTag *svstag = xcalloc(sizeof(*svstag));
169    svstag->numeric = numeric;
170    svstag->tag = xstrdup(tag);
171  
# Line 187 | Line 182 | client_attach_svstag(struct Client *clie
182   void
183   client_clear_svstags(struct Client *client_p)
184   {
185 <  dlink_node *node = NULL, *node_next = NULL;
191 <
192 <  DLINK_FOREACH_SAFE(node, node_next, client_p->svstags.head)
185 >  while (client_p->svstags.head)
186    {
187 <    struct ServicesTag *svstag = node->data;
187 >    struct ServicesTag *svstag = client_p->svstags.head->data;
188  
189      dlinkDelete(&svstag->node, &client_p->svstags);
190 <    MyFree(svstag->tag);
191 <    MyFree(svstag);
190 >    xfree(svstag->tag);
191 >    xfree(svstag);
192    }
193   }
194  
# Line 208 | Line 201 | client_clear_svstags(struct Client *clie
201   static void
202   check_pings_list(dlink_list *list)
203   {
204 <  char buf[IRCD_BUFSIZE] = "";
205 <  int ping = 0;      /* ping time value from client */
204 >  char buf[32] = "";  /* 32 = sizeof("Ping timeout: 999999999 seconds") */
205 >  unsigned int ping = 0;      /* ping time value from client */
206    dlink_node *node = NULL, *node_next = NULL;
207  
208    DLINK_FOREACH_SAFE(node, node_next, list->head)
# Line 257 | Line 250 | check_pings_list(dlink_list *list)
250                   get_client_name(client_p, SHOW_IP));
251            }
252  
253 <          snprintf(buf, sizeof(buf), "Ping timeout: %d seconds",
254 <                   (int)(CurrentTime - client_p->connection->lasttime));
253 >          snprintf(buf, sizeof(buf), "Ping timeout: %ji seconds",
254 >                   (CurrentTime - client_p->connection->lasttime));
255            exit_client(client_p, buf);
256          }
257        }
# Line 295 | Line 288 | check_unknowns_list(void)
288   * kill off stuff that should die
289   *
290   * inputs       - NOT USED (from event)
298 * output       - next time_t when check_pings() should be called again
291   * side effects -
292   *
293   *
# Line 334 | Line 326 | check_pings(void *unused)
326   void
327   check_conf_klines(void)
328   {
337  struct MaskItem *conf = NULL;
329    dlink_node *node = NULL, *node_next = NULL;
330 +  const void *ptr;
331  
332    DLINK_FOREACH_SAFE(node, node_next, local_client_list.head)
333    {
# Line 345 | Line 337 | check_conf_klines(void)
337      if (IsDead(client_p))
338        continue;
339  
340 <    if ((conf = find_conf_by_address(NULL, &client_p->connection->ip, CONF_DLINE,
341 <                                     client_p->connection->aftype, NULL, NULL, 1)))
340 >    if ((ptr = find_conf_by_address(NULL, &client_p->connection->ip, CONF_DLINE,
341 >                                    client_p->connection->aftype, NULL, NULL, 1)))
342      {
343 <      conf_try_ban(client_p, conf);
343 >      const struct MaskItem *conf = ptr;
344 >      conf_try_ban(client_p, CLIENT_BAN_DLINE, conf->reason);
345        continue;  /* and go examine next Client */
346      }
347  
348 <    if ((conf = find_conf_by_address(client_p->host, &client_p->connection->ip,
349 <                                     CONF_KLINE, client_p->connection->aftype,
350 <                                     client_p->username, NULL, 1)))
348 >    if ((ptr = find_conf_by_address(client_p->host, &client_p->connection->ip,
349 >                                    CONF_KLINE, client_p->connection->aftype,
350 >                                    client_p->username, NULL, 1)))
351      {
352 <      conf_try_ban(client_p, conf);
352 >      const struct MaskItem *conf = ptr;
353 >      conf_try_ban(client_p, CLIENT_BAN_KLINE, conf->reason);
354        continue;  /* and go examine next Client */
355      }
356  
357 <    if ((conf = find_matching_name_conf(CONF_XLINE, client_p->info,
364 <                                        NULL, NULL, 0)))
357 >    if ((ptr = gecos_find(client_p->info, match)))
358      {
359 <      conf_try_ban(client_p, conf);
359 >      const struct GecosItem *conf = ptr;
360 >      conf_try_ban(client_p, CLIENT_BAN_XLINE, conf->reason);
361        continue;  /* and go examine next Client */
362      }
363    }
# Line 373 | Line 367 | check_conf_klines(void)
367    {
368      struct Client *client_p = node->data;
369  
370 <    if ((conf = find_conf_by_address(NULL, &client_p->connection->ip, CONF_DLINE,
371 <                                     client_p->connection->aftype, NULL, NULL, 1)))
370 >    if ((ptr = find_conf_by_address(NULL, &client_p->connection->ip, CONF_DLINE,
371 >                                    client_p->connection->aftype, NULL, NULL, 1)))
372      {
373 <      conf_try_ban(client_p, conf);
373 >      const struct MaskItem *conf = ptr;
374 >      conf_try_ban(client_p, CLIENT_BAN_DLINE, conf->reason);
375        continue;  /* and go examine next Client */
376      }
377    }
# Line 391 | Line 386 | check_conf_klines(void)
386   * side effects - given client_p is banned
387   */
388   void
389 < conf_try_ban(struct Client *client_p, struct MaskItem *conf)
389 > conf_try_ban(struct Client *client_p, int type, const char *reason)
390   {
391 <  char ban_type = '\0';
391 >  char ban_type = '?';
392  
393 <  switch (conf->type)
393 >  switch (type)
394    {
395 <    case CONF_KLINE:
395 >    case CLIENT_BAN_KLINE:
396        if (HasFlag(client_p, FLAGS_EXEMPTKLINE))
397        {
398          sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
# Line 408 | Line 403 | conf_try_ban(struct Client *client_p, st
403  
404        ban_type = 'K';
405        break;
406 <    case CONF_DLINE:
406 >    case CLIENT_BAN_DLINE:
407        if (find_conf_by_address(NULL, &client_p->connection->ip, CONF_EXEMPT,
408                                 client_p->connection->aftype, NULL, NULL, 1))
409          return;
410        ban_type = 'D';
411        break;
412 <    case CONF_XLINE:
412 >    case CLIENT_BAN_XLINE:
413        if (HasFlag(client_p, FLAGS_EXEMPTXLINE))
414        {
415          sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
# Line 424 | Line 419 | conf_try_ban(struct Client *client_p, st
419        }
420  
421        ban_type = 'X';
427      ++conf->count;
422        break;
423      default:
424        assert(0);
# Line 435 | Line 429 | conf_try_ban(struct Client *client_p, st
429                         ban_type, get_client_name(client_p, HIDE_IP));
430  
431    if (IsClient(client_p))
432 <    sendto_one_numeric(client_p, &me, ERR_YOUREBANNEDCREEP, conf->reason);
439 <
440 <  exit_client(client_p, conf->reason);
441 < }
442 <
443 < /* update_client_exit_stats()
444 < *
445 < * input        - pointer to client
446 < * output       - NONE
447 < * side effects -
448 < */
449 < static void
450 < update_client_exit_stats(struct Client *client_p)
451 < {
452 <  if (IsClient(client_p))
453 <  {
454 <    assert(Count.total > 0);
432 >    sendto_one_numeric(client_p, &me, ERR_YOUREBANNEDCREEP, reason);
433  
434 <    --Count.total;
457 <    if (HasUMode(client_p, UMODE_OPER))
458 <      --Count.oper;
459 <    if (HasUMode(client_p, UMODE_INVISIBLE))
460 <      --Count.invisi;
461 <  }
462 <  else if (IsServer(client_p))
463 <    sendto_realops_flags(UMODE_EXTERNAL, L_ALL, SEND_NOTICE,
464 <                         "Server %s split from %s",
465 <                         client_p->name, client_p->servptr->name);
434 >  exit_client(client_p, reason);
435   }
436  
437   /* find_person()
# Line 472 | Line 441 | update_client_exit_stats(struct Client *
441   * side effects - find person by (nick)name
442   */
443   struct Client *
444 < find_person(const struct Client *const source_p, const char *name)
444 > find_person(const struct Client *source_p, const char *name)
445   {
446    struct Client *target_p = NULL;
447  
# Line 503 | Line 472 | find_chasing(struct Client *source_p, co
472    if (IsDigit(*name))
473      return NULL;
474  
475 <  target_p = whowas_get_history(name, (time_t)ConfigGeneral.kill_chase_time_limit);
507 <
475 >  target_p = whowas_get_history(name, ConfigGeneral.kill_chase_time_limit);
476    if (!target_p)
509  {
477      sendto_one_numeric(source_p, &me, ERR_NOSUCHNICK, name);
511    return NULL;
512  }
478  
479    return target_p;
480   }
# Line 535 | Line 500 | find_chasing(struct Client *source_p, co
500   const char *
501   get_client_name(const struct Client *client_p, enum addr_mask_type type)
502   {
503 <  static char buf[HOSTLEN * 2 + USERLEN + 5];
503 >  static char buf[HOSTLEN * 2 + USERLEN + 4];  /* +4 for [,@,],\0 */
504  
505    if (!MyConnect(client_p))
506      return client_p->name;
# Line 580 | Line 545 | free_exited_clients(void)
545  
546    DLINK_FOREACH_SAFE(node, node_next, dead_list.head)
547    {
548 <    free_client(node->data);
548 >    client_free(node->data);
549      dlinkDelete(node, &dead_list);
550      free_dlink_node(node);
551    }
# Line 602 | Line 567 | exit_one_client(struct Client *source_p,
567  
568    if (IsClient(source_p))
569    {
570 +    if (HasUMode(source_p, UMODE_OPER))
571 +      --Count.oper;
572 +    if (HasUMode(source_p, UMODE_INVISIBLE))
573 +      --Count.invisi;
574 +
575      dlinkDelete(&source_p->lnode, &source_p->servptr->serv->client_list);
576      dlinkDelete(&source_p->node, &global_client_list);
577  
# Line 611 | Line 581 | exit_one_client(struct Client *source_p,
581       * that the client can show the "**signoff" message).
582       * (Note: The notice is to the local clients *only*)
583       */
584 <    sendto_common_channels_local(source_p, 0, 0, ":%s!%s@%s QUIT :%s",
584 >    sendto_common_channels_local(source_p, 0, 0, 0, ":%s!%s@%s QUIT :%s",
585                                   source_p->name, source_p->username,
586                                   source_p->host, comment);
587  
588      DLINK_FOREACH_SAFE(node, node_next, source_p->channel.head)
589        remove_user_from_channel(node->data);
590  
591 +    client_clear_svstags(source_p);
592 +
593      whowas_add_history(source_p, 0);
594      whowas_off_history(source_p);
595  
# Line 625 | Line 597 | exit_one_client(struct Client *source_p,
597  
598      if (MyConnect(source_p))
599      {
600 <      clear_invites_client(source_p);
600 >      clear_invite_list(&source_p->connection->invited);
601        del_all_accepts(source_p);
602      }
603    }
604    else if (IsServer(source_p))
605    {
606 <    dlinkDelete(&source_p->lnode, &source_p->servptr->serv->server_list);
607 <    dlinkDelete(&source_p->node, &global_client_list);
606 >    sendto_realops_flags(UMODE_EXTERNAL, L_ALL, SEND_NOTICE,
607 >                         "Server %s split from %s",
608 >                         source_p->name, source_p->servptr->name);
609  
610 <    if ((node = dlinkFindDelete(&global_server_list, source_p)))
611 <      free_dlink_node(node);
610 >    dlinkDelete(&source_p->lnode, &source_p->servptr->serv->server_list);
611 >    dlinkDelete(&source_p->node, &global_server_list);
612    }
613  
614    /* Remove source_p from the client lists */
# Line 646 | Line 619 | exit_one_client(struct Client *source_p,
619      hash_del_client(source_p);
620  
621    if (HasFlag(source_p, FLAGS_USERHOST))
622 <    userhost_del(source_p->username, source_p->host, !MyConnect(source_p));
650 <
651 <  update_client_exit_stats(source_p);
622 >    userhost_del(source_p->sockhost, !MyConnect(source_p));
623  
624    /* Check to see if the client isn't already on the dead list */
625    assert(dlinkFind(&dead_list, source_p) == NULL);
# Line 720 | Line 691 | exit_client(struct Client *source_p, con
691        ipcache_remove_address(&source_p->connection->ip);
692      }
693  
694 <    delete_auth(&source_p->connection->auth);
694 >    auth_delete(&source_p->connection->auth);
695  
696      if (IsClient(source_p))
697      {
727      time_t on_for = CurrentTime - source_p->connection->firsttime;
728
698        assert(Count.local > 0);
699  
700        --Count.local;
# Line 741 | Line 710 | exit_client(struct Client *source_p, con
710          free_list_task(source_p);
711  
712        watch_del_watch_list(source_p);
744      client_clear_svstags(source_p);
713  
714        sendto_realops_flags(UMODE_CCONN, L_ALL, SEND_NOTICE,
715                             "Client exiting: %s (%s@%s) [%s] [%s]",
716 <                           source_p->name, source_p->username, source_p->host, comment,
717 <                           source_p->sockhost);
716 >                           source_p->name, source_p->username, source_p->host,
717 >                           source_p->sockhost, comment);
718  
719 <      ilog(LOG_TYPE_USER, "%s (%3u:%02u:%02u): %s!%s@%s %llu/%llu",
720 <           date_ctime(source_p->connection->firsttime), (unsigned int)(on_for / 3600),
721 <           (unsigned int)((on_for % 3600)/60), (unsigned int)(on_for % 60),
719 >      ilog(LOG_TYPE_USER, "%s (%ju): %s!%s@%s %s %s %ju/%ju :%s",
720 >           date_ctime(source_p->connection->firsttime),
721 >           CurrentTime - source_p->connection->firsttime,
722             source_p->name, source_p->username, source_p->host,
723 <           source_p->connection->send.bytes>>10,
724 <           source_p->connection->recv.bytes>>10);
723 >           source_p->sockhost, source_p->account,
724 >           source_p->connection->send.bytes >> 10,
725 >           source_p->connection->recv.bytes >> 10, source_p->info);
726      }
727      else if (IsServer(source_p))
728      {
760      assert(Count.myserver > 0);
761
762      --Count.myserver;
763
729        assert(dlinkFind(&local_server_list, source_p));
730        dlinkDelete(&source_p->connection->lclient_node, &local_server_list);
731      }
# Line 790 | Line 755 | exit_client(struct Client *source_p, con
755    }
756    else if (IsClient(source_p) && HasFlag(source_p->servptr, FLAGS_EOB))
757      sendto_realops_flags(UMODE_FARCONNECT, L_ALL, SEND_NOTICE,
758 <                         "Client exiting at %s: %s (%s@%s) [%s]",
758 >                         "Client exiting at %s: %s (%s@%s) [%s] [%s]",
759                           source_p->servptr->name, source_p->name,
760 <                         source_p->username, source_p->host, comment);
760 >                         source_p->username, source_p->host, source_p->sockhost, comment);
761  
762    if (IsServer(source_p))
763    {
# Line 820 | Line 785 | exit_client(struct Client *source_p, con
785  
786      if (MyConnect(source_p))
787      {
823      int connected = CurrentTime - source_p->connection->firsttime;
788        sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
789 <                           "%s was connected for %d day%s, %2d:%02d:%02d. %llu/%llu sendK/recvK.",
790 <                           source_p->name, connected/86400, (connected/86400 == 1) ? "" : "s",
827 <                           (connected % 86400) / 3600, (connected % 3600) / 60, connected % 60,
789 >                           "%s was connected for %s. %ju/%ju sendK/recvK.",
790 >                           source_p->name, time_dissect(CurrentTime - source_p->connection->firsttime),
791                             source_p->connection->send.bytes >> 10,
792                             source_p->connection->recv.bytes >> 10);
793 <      ilog(LOG_TYPE_IRCD, "%s was connected for %d day%s, %2d:%02d:%02d. %llu/%llu sendK/recvK.",
794 <           source_p->name, connected/86400, (connected/86400 == 1) ? "" : "s",
832 <           (connected % 86400) / 3600, (connected % 3600) / 60, connected % 60,
793 >      ilog(LOG_TYPE_IRCD, "%s was connected for %s. %ju/%ju sendK/recvK.",
794 >           source_p->name, time_dissect(CurrentTime - source_p->connection->firsttime),
795             source_p->connection->send.bytes >> 10,
796             source_p->connection->recv.bytes >> 10);
797      }
798    }
799    else if (IsClient(source_p) && !HasFlag(source_p, FLAGS_KILLED))
800 <    sendto_server(source_p->from, 0, 0, ":%s QUIT :%s",
839 <                  source_p->id, comment);
800 >    sendto_server(source_p->from, 0, 0, ":%s QUIT :%s", source_p->id, comment);
801  
802    /* The client *better* be off all of the lists */
803    assert(dlinkFind(&unknown_list, source_p) == NULL);
# Line 893 | Line 854 | dead_link_on_read(struct Client *client_
854  
855    if (IsServer(client_p) || IsHandshake(client_p))
856    {
896    int connected = CurrentTime - client_p->connection->firsttime;
897
857      if (error == 0)
858      {
859        /* Admins get the real IP */
# Line 919 | Line 878 | dead_link_on_read(struct Client *client_
878      }
879  
880      sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
881 <                         "%s was connected for %d day%s, %2d:%02d:%02d",
882 <                         client_p->name, connected/86400,
924 <                         (connected/86400 == 1) ? "" : "s",
925 <                         (connected % 86400) / 3600, (connected % 3600) / 60,
926 <                         connected % 60);
881 >                         "%s was connected for %s",
882 >                         client_p->name, time_dissect(CurrentTime - client_p->connection->firsttime));
883    }
884  
885    if (error == 0)
# Line 984 | Line 940 | del_accept(struct split_nuh_item *accept
940   {
941    dlinkDelete(&accept_p->node, &client_p->connection->acceptlist);
942  
943 <  MyFree(accept_p->nickptr);
944 <  MyFree(accept_p->userptr);
945 <  MyFree(accept_p->hostptr);
946 <  MyFree(accept_p);
943 >  xfree(accept_p->nickptr);
944 >  xfree(accept_p->userptr);
945 >  xfree(accept_p->hostptr);
946 >  xfree(accept_p);
947   }
948  
949   struct split_nuh_item *
# Line 1081 | Line 1037 | client_get_idle_time(const struct Client
1037    else
1038      idle = CurrentTime - target_p->connection->last_privmsg;
1039  
1040 <  if (!max_idle)
1085 <    idle = 0;
1086 <  else
1040 >  if (max_idle)
1041      idle %= max_idle;
1042 +  else
1043 +    idle = 0;
1044  
1045    if (idle < min_idle)
1046      idle = min_idle + (idle % (max_idle - min_idle));

Comparing ircd-hybrid/trunk/src/client.c (property svn:keywords):
Revision 6513 by michael, Sun Sep 6 18:32:38 2015 UTC vs.
Revision 7967 by michael, Mon Mar 13 19:10:19 2017 UTC

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

Diff Legend

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