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 5347 by michael, Sun Jan 11 12:42:20 2015 UTC vs.
Revision 6318 by michael, Wed Aug 5 16:04:43 2015 UTC

# Line 87 | Line 87 | make_client(struct Client *from)
87  
88    if (!from)
89    {
90 <    client_p->from                      = client_p; /* 'from' of local client is self! */
91 <    client_p->connection               = mp_pool_get(connection_pool);
92 <    client_p->connection->since        = CurrentTime;
93 <    client_p->connection->lasttime     = CurrentTime;
94 <    client_p->connection->firsttime    = CurrentTime;
90 >    client_p->from = client_p;  /* 'from' of local client is self! */
91 >    client_p->connection = mp_pool_get(connection_pool);
92 >    client_p->connection->since = CurrentTime;
93 >    client_p->connection->lasttime = CurrentTime;
94 >    client_p->connection->firsttime = CurrentTime;
95      client_p->connection->registration = REG_INIT;
96  
97      /* as good a place as any... */
98      dlinkAdd(client_p, &client_p->connection->lclient_node, &unknown_list);
99    }
100    else
101 <    client_p->from = from; /* 'from' of local client is self! */
101 >    client_p->from = from;
102  
103    client_p->idhnext = client_p;
104 <  client_p->hnext  = client_p;
104 >  client_p->hnext = client_p;
105    SetUnknown(client_p);
106    strcpy(client_p->username, "unknown");
107 <  strcpy(client_p->account, "0");
107 >  strcpy(client_p->account, "*");
108  
109    return client_p;
110   }
# Line 125 | Line 125 | free_client(struct Client *client_p)
125    assert(client_p->channel.head == NULL);
126    assert(dlink_list_length(&client_p->channel) == 0);
127    assert(dlink_list_length(&client_p->whowas) == 0);
128 <  assert(!IsServer(client_p) || client_p->serv);
128 >  assert(dlink_list_length(&client_p->svstags) == 0);
129  
130    MyFree(client_p->serv);
131    MyFree(client_p->certfp);
# Line 138 | Line 138 | free_client(struct Client *client_p)
138      assert(IsClosing(client_p) && IsDead(client_p));
139  
140      MyFree(client_p->connection->challenge_response);
141    MyFree(client_p->connection->challenge_operator);
141      client_p->connection->challenge_response = NULL;
142 +    MyFree(client_p->connection->challenge_operator);
143      client_p->connection->challenge_operator = NULL;
144  
145      /*
146 <     * Clean up extra sockets from listen{} blocks which have been discarded.
146 >     * Clean up extra sockets from listen {} blocks which have been discarded.
147       */
148      if (client_p->connection->listener)
149      {
# Line 160 | Line 160 | free_client(struct Client *client_p)
160    mp_pool_release(client_p);
161   }
162  
163 + void
164 + client_attach_svstag(struct Client *client_p, unsigned int numeric,
165 +                     const char *umodes, const char *const tag)
166 + {
167 +  struct ServicesTag *svstag = NULL;
168 +  const struct user_modes *tab = NULL;
169 +
170 +  if (numeric >= ERR_LAST_ERR_MSG || *umodes != '+')
171 +    return;
172 +
173 +  svstag = MyCalloc(sizeof(*svstag));
174 +  svstag->numeric = numeric;
175 +  svstag->tag = xstrdup(tag);
176 +
177 +  for (const char *m = umodes + 1; *m; ++m)
178 +    if ((tab = umode_map[(unsigned char)*m]))
179 +      svstag->umodes |= tab->flag;
180 +
181 +  if (numeric != RPL_WHOISOPERATOR)
182 +    dlinkAddTail(svstag, &svstag->node, &client_p->svstags);
183 +  else
184 +    dlinkAdd(svstag, &svstag->node, &client_p->svstags);
185 + }
186 +
187 + void
188 + client_clear_svstags(struct Client *client_p)
189 + {
190 +  dlink_node *node = NULL, *node_next = NULL;
191 +
192 +  DLINK_FOREACH_SAFE(node, node_next, client_p->svstags.head)
193 +  {
194 +    struct ServicesTag *svstag = node->data;
195 +
196 +    dlinkDelete(&svstag->node, &client_p->svstags);
197 +    MyFree(svstag->tag);
198 +    MyFree(svstag);
199 +  }
200 + }
201 +
202   /* check_pings_list()
203   *
204   * inputs       - pointer to list to check
# Line 187 | Line 226 | check_pings_list(dlink_list *list)
226  
227      if (ping < CurrentTime - client_p->connection->lasttime)
228      {
229 <      if (!IsPingSent(client_p))
229 >      if (!HasFlag(client_p, FLAGS_PINGSENT))
230        {
231          /*
232           * If we haven't PINGed the connection and we haven't
233           * heard from it in a while, PING it to make sure
234           * it is still alive.
235           */
236 <        SetPingSent(client_p);
236 >        AddFlag(client_p, FLAGS_PINGSENT);
237          client_p->connection->lasttime = CurrentTime - ping;
238          sendto_one(client_p, "PING :%s", ID_or_name(&me, client_p));
239        }
# Line 208 | Line 247 | check_pings_list(dlink_list *list)
247             */
248            if (IsServer(client_p) || IsHandshake(client_p))
249            {
250 <            sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
250 >            sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
251                                   "No response from %s, closing link",
252                                   get_client_name(client_p, HIDE_IP));
253 <            sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
253 >            sendto_realops_flags(UMODE_SERVNOTICE, L_OPER, SEND_NOTICE,
254                                   "No response from %s, closing link",
255                                   get_client_name(client_p, MASK_IP));
256              ilog(LOG_TYPE_IRCD, "No response from %s, closing link",
# Line 310 | Line 349 | check_conf_klines(void)
349                                       client_p->connection->aftype, NULL, NULL, 1)))
350      {
351        conf_try_ban(client_p, conf);
352 <      continue; /* and go examine next fd/client_p */
314 <    }
315 <
316 <    if (ConfigGeneral.glines)
317 <    {
318 <      if ((conf = find_conf_by_address(client_p->host, &client_p->connection->ip,
319 <                                       CONF_GLINE, client_p->connection->aftype,
320 <                                       client_p->username, NULL, 1)))
321 <      {
322 <        conf_try_ban(client_p, conf);
323 <        /* and go examine next fd/client_p */
324 <        continue;
325 <      }
352 >      continue;  /* and go examine next Client */
353      }
354  
355      if ((conf = find_conf_by_address(client_p->host, &client_p->connection->ip,
# Line 330 | Line 357 | check_conf_klines(void)
357                                       client_p->username, NULL, 1)))
358      {
359        conf_try_ban(client_p, conf);
360 <      continue;
360 >      continue;  /* and go examine next Client */
361      }
362  
363 <    if ((conf = find_matching_name_conf(CONF_XLINE,  client_p->info,
363 >    if ((conf = find_matching_name_conf(CONF_XLINE, client_p->info,
364                                          NULL, NULL, 0)))
365      {
366        conf_try_ban(client_p, conf);
367 <      continue;
367 >      continue;  /* and go examine next Client */
368      }
369    }
370  
371 <  /* also check the unknowns list for new dlines */
371 >  /* Also check the unknowns list for new dlines */
372    DLINK_FOREACH_SAFE(node, node_next, unknown_list.head)
373    {
374      struct Client *client_p = node->data;
# Line 350 | Line 377 | check_conf_klines(void)
377                                       client_p->connection->aftype, NULL, NULL, 1)))
378      {
379        conf_try_ban(client_p, conf);
380 <      continue; /* and go examine next fd/client_p */
380 >      continue;  /* and go examine next Client */
381      }
382    }
383   }
# Line 366 | Line 393 | check_conf_klines(void)
393   void
394   conf_try_ban(struct Client *client_p, struct MaskItem *conf)
395   {
396 <  const char *user_reason = NULL;  /* What is sent to user */
370 <  const char *type_string = NULL;
371 <  const char dline_string[] = "D-line";
372 <  const char kline_string[] = "K-line";
373 <  const char gline_string[] = "G-line";
374 <  const char xline_string[] = "X-line";
396 >  char ban_type = '\0';
397  
398    switch (conf->type)
399    {
400      case CONF_KLINE:
401 <      if (IsExemptKline(client_p))
401 >      if (HasFlag(client_p, FLAGS_EXEMPTKLINE))
402        {
403 <        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
403 >        sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
404                               "KLINE over-ruled for %s, client is kline_exempt",
405                               get_client_name(client_p, HIDE_IP));
406          return;
407        }
408  
409 <      type_string = kline_string;
409 >      ban_type = 'K';
410        break;
411      case CONF_DLINE:
412        if (find_conf_by_address(NULL, &client_p->connection->ip, CONF_EXEMPT,
413                                 client_p->connection->aftype, NULL, NULL, 1))
414          return;
415 <      type_string = dline_string;
415 >      ban_type = 'D';
416        break;
417 <    case CONF_GLINE:
418 <      if (IsExemptKline(client_p) ||
397 <          IsExemptGline(client_p))
417 >    case CONF_XLINE:
418 >      if (HasFlag(client_p, FLAGS_EXEMPTXLINE))
419        {
420 <        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
421 <                             "GLINE over-ruled for %s, client is %sline_exempt",
422 <                             get_client_name(client_p, HIDE_IP), IsExemptKline(client_p) ? "k" : "g");
420 >        sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
421 >                             "XLINE over-ruled for %s, client is xline_exempt",
422 >                             get_client_name(client_p, HIDE_IP));
423          return;
424        }
425  
426 <      type_string = gline_string;
406 <      break;
407 <    case CONF_XLINE:
408 <      type_string = xline_string;
426 >      ban_type = 'X';
427        ++conf->count;
428        break;
429      default:
# Line 413 | Line 431 | conf_try_ban(struct Client *client_p, st
431        break;
432    }
433  
434 <  user_reason = conf->reason ? conf->reason : type_string;
435 <
418 <  sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, "%s active for %s",
419 <                       type_string, get_client_name(client_p, HIDE_IP));
434 >  sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, "%c-line active for %s",
435 >                       ban_type, get_client_name(client_p, HIDE_IP));
436  
437    if (IsClient(client_p))
438 <    sendto_one_numeric(client_p, &me, ERR_YOUREBANNEDCREEP, user_reason);
438 >    sendto_one_numeric(client_p, &me, ERR_YOUREBANNEDCREEP, conf->reason);
439  
440 <  exit_client(client_p, user_reason);
440 >  exit_client(client_p, conf->reason);
441   }
442  
443   /* update_client_exit_stats()
# Line 551 | Line 567 | get_client_name(const struct Client *cli
567          snprintf(buf, sizeof(buf), "%s[%s@ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]",
568                   client_p->name, client_p->username);
569        break;
570 <    default:
570 >    default:  /* HIDE_IP */
571        snprintf(buf, sizeof(buf), "%s[%s@%s]",
572                 client_p->name,
573                 client_p->username, client_p->host);
# Line 612 | Line 628 | exit_one_client(struct Client *source_p,
628  
629      if (MyConnect(source_p))
630      {
631 <      /* Clean up invitefield */
616 <      DLINK_FOREACH_SAFE(node, node_next, source_p->connection->invited.head)
617 <        del_invite(node->data, source_p);
618 <
631 >      clear_invites_client(source_p);
632        del_all_accepts(source_p);
633      }
634    }
# Line 635 | Line 648 | exit_one_client(struct Client *source_p,
648    if (source_p->name[0])
649      hash_del_client(source_p);
650  
651 <  if (IsUserHostIp(source_p))
651 >  if (HasFlag(source_p, FLAGS_USERHOST))
652      delete_user_host(source_p->username, source_p->host, !MyConnect(source_p));
653  
654    update_client_exit_stats(source_p);
# Line 744 | Line 757 | exit_client(struct Client *source_p, con
757          free_list_task(source_p);
758  
759        watch_del_watch_list(source_p);
760 +      client_clear_svstags(source_p);
761 +
762        sendto_realops_flags(UMODE_CCONN, L_ALL, SEND_NOTICE,
763                             "Client exiting: %s (%s@%s) [%s] [%s]",
764                             source_p->name, source_p->username, source_p->host, comment,
# Line 794 | Line 809 | exit_client(struct Client *source_p, con
809    {
810      char splitstr[HOSTLEN + HOSTLEN + 2] = "";
811  
812 <    /* This shouldn't ever happen */
813 <    assert(source_p->serv && source_p->servptr);
812 >    assert(source_p->serv);
813 >    assert(source_p->servptr);
814  
815      if (ConfigServerHide.hide_servers)
816        /*
# Line 817 | Line 832 | exit_client(struct Client *source_p, con
832      if (MyConnect(source_p))
833      {
834        int connected = CurrentTime - source_p->connection->firsttime;
835 <      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
835 >      sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
836                             "%s was connected for %d day%s, %2d:%02d:%02d. %llu/%llu sendK/recvK.",
837                             source_p->name, connected/86400, (connected/86400 == 1) ? "" : "s",
838                             (connected % 86400) / 3600, (connected % 3600) / 60, connected % 60,
# Line 825 | Line 840 | exit_client(struct Client *source_p, con
840                             source_p->connection->recv.bytes >> 10);
841        ilog(LOG_TYPE_IRCD, "%s was connected for %d day%s, %2d:%02d:%02d. %llu/%llu sendK/recvK.",
842             source_p->name, connected/86400, (connected/86400 == 1) ? "" : "s",
843 <          (connected % 86400) / 3600, (connected % 3600) / 60, connected % 60,
844 <          source_p->connection->send.bytes >> 10,
845 <          source_p->connection->recv.bytes >> 10);
843 >           (connected % 86400) / 3600, (connected % 3600) / 60, connected % 60,
844 >           source_p->connection->send.bytes >> 10,
845 >           source_p->connection->recv.bytes >> 10);
846      }
847    }
848    else if (IsClient(source_p) && !HasFlag(source_p, FLAGS_KILLED))
# Line 894 | Line 909 | dead_link_on_read(struct Client *client_
909      if (error == 0)
910      {
911        /* Admins get the real IP */
912 <      sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
912 >      sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
913                             "Server %s closed the connection",
914                             get_client_name(client_p, SHOW_IP));
915  
916        /* Opers get a masked IP */
917 <      sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
917 >      sendto_realops_flags(UMODE_SERVNOTICE, L_OPER, SEND_NOTICE,
918                             "Server %s closed the connection",
919                             get_client_name(client_p, MASK_IP));
920  
# Line 914 | Line 929 | dead_link_on_read(struct Client *client_
929                     get_client_name(client_p, MASK_IP), current_error);
930      }
931  
932 <    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
932 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
933                           "%s was connected for %d day%s, %2d:%02d:%02d",
934                           client_p->name, connected/86400,
935                           (connected/86400 == 1) ? "" : "s",
# Line 946 | Line 961 | exit_aborted_clients(void)
961  
962      if (target_p == NULL)
963      {
964 <      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
964 >      sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
965                             "Warning: null client on abort_list!");
966        dlinkDelete(ptr, &abort_list);
967        free_dlink_node(ptr);
# Line 955 | Line 970 | exit_aborted_clients(void)
970  
971      dlinkDelete(ptr, &abort_list);
972  
973 <    if (IsSendQExceeded(target_p))
973 >    if (HasFlag(target_p, FLAGS_SENDQEX))
974        notice = "Max SendQ exceeded";
975      else
976        notice = "Write error: connection closed";
# Line 1019 | Line 1034 | accept_message(struct Client *source,
1034   {
1035    dlink_node *node = NULL;
1036  
1037 +  if (HasFlag(source, FLAGS_SERVICE) ||
1038 +      (HasUMode(source, UMODE_OPER) && ConfigGeneral.opers_bypass_callerid))
1039 +    return 1;
1040 +
1041    if (source == target || find_accept(source->name, source->username,
1042                                        source->host, target, match))
1043      return 1;
# Line 1047 | Line 1066 | del_all_accepts(struct Client *client_p)
1066   }
1067  
1068   unsigned int
1069 < idle_time_get(const struct Client *source_p, const struct Client *target_p)
1069 > client_get_idle_time(const struct Client *source_p,
1070 >                     const struct Client *target_p)
1071   {
1072    unsigned int idle = 0;
1073    unsigned int min_idle = 0;

Diff Legend

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