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 5551 by michael, Thu Feb 12 21:43:47 2015 UTC vs.
Revision 6513 by michael, Sun Sep 6 18:32:38 2015 UTC

# Line 104 | Line 104 | make_client(struct Client *from)
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 135 | Line 135 | free_client(struct Client *client_p)
135      assert(client_p->connection->invited.head == NULL);
136      assert(dlink_list_length(&client_p->connection->invited) == 0);
137      assert(dlink_list_length(&client_p->connection->watches) == 0);
138 <    assert(IsClosing(client_p) && IsDead(client_p));
138 >    assert(HasFlag(client_p, FLAGS_CLOSING) && IsDead(client_p));
139  
140      MyFree(client_p->connection->challenge_response);
141      client_p->connection->challenge_response = NULL;
# Line 143 | Line 143 | free_client(struct Client *client_p)
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 161 | Line 161 | free_client(struct Client *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;
# Line 195 | Line 219 | check_pings_list(dlink_list *list)
219      if (IsDead(client_p))
220        continue;  /* Ignore it, its been exited already */
221  
222 <    if (!IsRegistered(client_p))
199 <      ping = CONNECTTIMEOUT;
200 <    else
222 >    if (IsClient(client_p) || IsServer(client_p))
223        ping = get_client_ping(&client_p->connection->confs);
224 +    else
225 +      ping = CONNECTTIMEOUT;
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 223 | 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,
252 >                                 get_client_name(client_p, SHOW_IP));
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",
257 <                 get_client_name(client_p, HIDE_IP));
257 >                 get_client_name(client_p, SHOW_IP));
258            }
259  
260            snprintf(buf, sizeof(buf), "Ping timeout: %d seconds",
# Line 261 | Line 285 | check_unknowns_list(void)
285       * Check UNKNOWN connections - if they have been in this state
286       * for > 30s, close them.
287       */
288 <    if (IsAuthFinished(client_p) && (CurrentTime - client_p->connection->firsttime) > 30)
288 >    if (HasFlag(client_p, FLAGS_FINISHED_AUTH) && (CurrentTime - client_p->connection->firsttime) > 30)
289        exit_client(client_p, "Registration timed out");
290    }
291   }
# Line 325 | 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 */
329 <    }
330 <
331 <    if (ConfigGeneral.glines)
332 <    {
333 <      if ((conf = find_conf_by_address(client_p->host, &client_p->connection->ip,
334 <                                       CONF_GLINE, client_p->connection->aftype,
335 <                                       client_p->username, NULL, 1)))
336 <      {
337 <        conf_try_ban(client_p, conf);
338 <        /* and go examine next fd/client_p */
339 <        continue;
340 <      }
352 >      continue;  /* and go examine next Client */
353      }
354  
355      if ((conf = find_conf_by_address(client_p->host, &client_p->connection->ip,
# Line 345 | 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 365 | 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 381 | 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 */
385 <  const char *type_string = NULL;
386 <  const char dline_string[] = "D-line";
387 <  const char kline_string[] = "K-line";
388 <  const char gline_string[] = "G-line";
389 <  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) ||
412 <          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;
421 <      break;
422 <    case CONF_XLINE:
423 <      type_string = xline_string;
426 >      ban_type = 'X';
427        ++conf->count;
428        break;
429      default:
# Line 428 | Line 431 | conf_try_ban(struct Client *client_p, st
431        break;
432    }
433  
434 <  user_reason = conf->reason ? conf->reason : type_string;
435 <
433 <  sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, "%s active for %s",
434 <                       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 462 | Line 463 | update_client_exit_stats(struct Client *
463      sendto_realops_flags(UMODE_EXTERNAL, L_ALL, SEND_NOTICE,
464                           "Server %s split from %s",
465                           client_p->name, client_p->servptr->name);
465
466  if (splitchecking && !splitmode)
467    check_splitmode(NULL);
466   }
467  
468   /* find_person()
# Line 566 | Line 564 | get_client_name(const struct Client *cli
564          snprintf(buf, sizeof(buf), "%s[%s@ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]",
565                   client_p->name, client_p->username);
566        break;
567 <    default:
567 >    default:  /* HIDE_IP */
568        snprintf(buf, sizeof(buf), "%s[%s@%s]",
569                 client_p->name,
570                 client_p->username, client_p->host);
# Line 627 | Line 625 | exit_one_client(struct Client *source_p,
625  
626      if (MyConnect(source_p))
627      {
628 <      /* Clean up invitefield */
631 <      DLINK_FOREACH_SAFE(node, node_next, source_p->connection->invited.head)
632 <        del_invite(node->data, source_p);
633 <
628 >      clear_invites_client(source_p);
629        del_all_accepts(source_p);
630      }
631    }
# Line 650 | Line 645 | exit_one_client(struct Client *source_p,
645    if (source_p->name[0])
646      hash_del_client(source_p);
647  
648 <  if (IsUserHostIp(source_p))
649 <    delete_user_host(source_p->username, source_p->host, !MyConnect(source_p));
648 >  if (HasFlag(source_p, FLAGS_USERHOST))
649 >    userhost_del(source_p->username, source_p->host, !MyConnect(source_p));
650  
651    update_client_exit_stats(source_p);
652  
# Line 714 | Line 709 | exit_client(struct Client *source_p, con
709      /* DO NOT REMOVE. exit_client can be called twice after a failed
710       * read/write.
711       */
712 <    if (IsClosing(source_p))
712 >    if (HasFlag(source_p, FLAGS_CLOSING))
713        return;
714  
715 <    SetClosing(source_p);
715 >    AddFlag(source_p, FLAGS_CLOSING);
716  
717      if (HasFlag(source_p, FLAGS_IPHASH))
718      {
# Line 727 | Line 722 | exit_client(struct Client *source_p, con
722  
723      delete_auth(&source_p->connection->auth);
724  
725 <    /*
731 <     * This source_p could have status of one of STAT_UNKNOWN, STAT_CONNECTING
732 <     * STAT_HANDSHAKE or STAT_UNKNOWN
733 <     * all of which are lumped together into unknown_list
734 <     *
735 <     * In all above cases IsRegistered() will not be true.
736 <     */
737 <    if (!IsRegistered(source_p))
738 <    {
739 <      assert(dlinkFind(&unknown_list, source_p));
740 <
741 <      dlinkDelete(&source_p->connection->lclient_node, &unknown_list);
742 <    }
743 <    else if (IsClient(source_p))
725 >    if (IsClient(source_p))
726      {
727        time_t on_for = CurrentTime - source_p->connection->firsttime;
728  
# Line 767 | Line 749 | exit_client(struct Client *source_p, con
749                             source_p->sockhost);
750  
751        ilog(LOG_TYPE_USER, "%s (%3u:%02u:%02u): %s!%s@%s %llu/%llu",
752 <           myctime(source_p->connection->firsttime), (unsigned int)(on_for / 3600),
752 >           date_ctime(source_p->connection->firsttime), (unsigned int)(on_for / 3600),
753             (unsigned int)((on_for % 3600)/60), (unsigned int)(on_for % 60),
754             source_p->name, source_p->username, source_p->host,
755             source_p->connection->send.bytes>>10,
# Line 782 | Line 764 | exit_client(struct Client *source_p, con
764        assert(dlinkFind(&local_server_list, source_p));
765        dlinkDelete(&source_p->connection->lclient_node, &local_server_list);
766      }
767 +    else
768 +    {
769 +      assert(dlinkFind(&unknown_list, source_p));
770 +      dlinkDelete(&source_p->connection->lclient_node, &unknown_list);
771 +    }
772  
773      if (!IsDead(source_p))
774      {
# Line 811 | Line 798 | exit_client(struct Client *source_p, con
798    {
799      char splitstr[HOSTLEN + HOSTLEN + 2] = "";
800  
801 <    /* This shouldn't ever happen */
802 <    assert(source_p->serv && source_p->servptr);
801 >    assert(source_p->serv);
802 >    assert(source_p->servptr);
803  
804      if (ConfigServerHide.hide_servers)
805        /*
# Line 834 | Line 821 | exit_client(struct Client *source_p, con
821      if (MyConnect(source_p))
822      {
823        int connected = CurrentTime - source_p->connection->firsttime;
824 <      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
824 >      sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
825                             "%s was connected for %d day%s, %2d:%02d:%02d. %llu/%llu sendK/recvK.",
826                             source_p->name, connected/86400, (connected/86400 == 1) ? "" : "s",
827                             (connected % 86400) / 3600, (connected % 3600) / 60, connected % 60,
# Line 842 | Line 829 | exit_client(struct Client *source_p, con
829                             source_p->connection->recv.bytes >> 10);
830        ilog(LOG_TYPE_IRCD, "%s was connected for %d day%s, %2d:%02d:%02d. %llu/%llu sendK/recvK.",
831             source_p->name, connected/86400, (connected/86400 == 1) ? "" : "s",
832 <          (connected % 86400) / 3600, (connected % 3600) / 60, connected % 60,
833 <          source_p->connection->send.bytes >> 10,
834 <          source_p->connection->recv.bytes >> 10);
832 >           (connected % 86400) / 3600, (connected % 3600) / 60, connected % 60,
833 >           source_p->connection->send.bytes >> 10,
834 >           source_p->connection->recv.bytes >> 10);
835      }
836    }
837    else if (IsClient(source_p) && !HasFlag(source_p, FLAGS_KILLED))
# Line 911 | Line 898 | dead_link_on_read(struct Client *client_
898      if (error == 0)
899      {
900        /* Admins get the real IP */
901 <      sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
901 >      sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
902                             "Server %s closed the connection",
903                             get_client_name(client_p, SHOW_IP));
904  
905        /* Opers get a masked IP */
906 <      sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
906 >      sendto_realops_flags(UMODE_SERVNOTICE, L_OPER, SEND_NOTICE,
907                             "Server %s closed the connection",
908                             get_client_name(client_p, MASK_IP));
909  
# Line 931 | Line 918 | dead_link_on_read(struct Client *client_
918                     get_client_name(client_p, MASK_IP), current_error);
919      }
920  
921 <    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
921 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
922                           "%s was connected for %d day%s, %2d:%02d:%02d",
923                           client_p->name, connected/86400,
924                           (connected/86400 == 1) ? "" : "s",
# Line 963 | Line 950 | exit_aborted_clients(void)
950  
951      if (target_p == NULL)
952      {
953 <      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
953 >      sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
954                             "Warning: null client on abort_list!");
955        dlinkDelete(ptr, &abort_list);
956        free_dlink_node(ptr);
# Line 972 | Line 959 | exit_aborted_clients(void)
959  
960      dlinkDelete(ptr, &abort_list);
961  
962 <    if (IsSendQExceeded(target_p))
962 >    if (HasFlag(target_p, FLAGS_SENDQEX))
963        notice = "Max SendQ exceeded";
964      else
965        notice = "Write error: connection closed";

Diff Legend

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