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 1834 by michael, Fri Apr 19 19:50:27 2013 UTC vs.
Revision 2811 by michael, Sun Jan 12 19:39:33 2014 UTC

# Line 52 | Line 52
52   #include "userhost.h"
53   #include "watch.h"
54   #include "rng_mt.h"
55 + #include "parse.h"
56  
57   dlink_list listing_client_list = { NULL, NULL, 0 };
58   /* Pointer to beginning of Client list */
# Line 75 | Line 76 | static dlink_node *eac_next;  /* next ab
76  
77   static void check_pings_list(dlink_list *);
78   static void check_unknowns_list(void);
78 static void ban_them(struct Client *, struct MaskItem *);
79  
80  
81   /* client_init()
# Line 137 | Line 137 | make_client(struct Client *from)
137  
138    client_p->idhnext = client_p;
139    client_p->hnext  = client_p;
140 <  client_p->status = STAT_UNKNOWN;
140 >  SetUnknown(client_p);
141    strcpy(client_p->username, "unknown");
142    strcpy(client_p->svid, "0");
143  
# Line 164 | Line 164 | free_client(struct Client *client_p)
164    assert(!IsServer(client_p) || (IsServer(client_p) && client_p->serv));
165  
166    MyFree(client_p->serv);
167 +  MyFree(client_p->certfp);
168  
169    if (MyConnect(client_p))
170    {
171      assert(client_p->localClient->invited.head == NULL);
172      assert(dlink_list_length(&client_p->localClient->invited) == 0);
173 <    assert(dlink_list_length(&client_p->localClient->watches) == 0);
173 >    assert(dlink_list_length(&client_p->localClient->watches) == 0);
174      assert(IsClosing(client_p) && IsDead(client_p));
175  
176      MyFree(client_p->localClient->response);
# Line 182 | Line 183 | free_client(struct Client *client_p)
183      {
184        assert(0 < client_p->localClient->listener->ref_count);
185        if (0 == --client_p->localClient->listener->ref_count &&
186 <          !client_p->localClient->listener->active)
186 >          !client_p->localClient->listener->active)
187          free_listener(client_p->localClient->listener);
188      }
189  
# Line 201 | Line 202 | free_client(struct Client *client_p)
202   *
203   * inputs       - NOT USED (from event)
204   * output       - next time_t when check_pings() should be called again
205 < * side effects -
205 > * side effects -
206   *
207   *
208   * A PING can be sent to clients as necessary.
# Line 223 | Line 224 | free_client(struct Client *client_p)
224  
225   static void
226   check_pings(void *notused)
227 < {              
227 > {
228    check_pings_list(&local_client_list);
229    check_pings_list(&serv_list);
230    check_unknowns_list();
# Line 233 | Line 234 | check_pings(void *notused)
234   *
235   * inputs       - pointer to list to check
236   * output       - NONE
237 < * side effects -
237 > * side effects -
238   */
239   static void
240   check_pings_list(dlink_list *list)
241   {
242 <  char scratch[32];        /* way too generous but... */
242 >  char scratch[IRCD_BUFSIZE];
243    int ping = 0;      /* ping time value from client */
244    dlink_node *ptr = NULL, *next_ptr = NULL;
245  
# Line 253 | Line 254 | check_pings_list(dlink_list *list)
254      if (IsDead(client_p))
255      {
256        /* Ignore it, its been exited already */
257 <      continue;
257 >      continue;
258      }
259  
260      if (!IsRegistered(client_p))
# Line 265 | Line 266 | check_pings_list(dlink_list *list)
266      {
267        if (!IsPingSent(client_p))
268        {
269 <        /*
270 <         * if we havent PINGed the connection and we havent
271 <         * heard from it in a while, PING it to make sure
272 <         * it is still alive.
273 <         */
274 <        SetPingSent(client_p);
275 <        client_p->localClient->lasttime = CurrentTime - ping;
276 <        sendto_one(client_p, "PING :%s", ID_or_name(&me, client_p));
269 >        /*
270 >         * if we havent PINGed the connection and we havent
271 >         * heard from it in a while, PING it to make sure
272 >         * it is still alive.
273 >         */
274 >        SetPingSent(client_p);
275 >        client_p->localClient->lasttime = CurrentTime - ping;
276 >        sendto_one(client_p, "PING :%s", ID_or_name(&me, client_p));
277        }
278        else
279        {
# Line 283 | Line 284 | check_pings_list(dlink_list *list)
284             * and it has a ping time, then close its connection.
285             */
286            if (IsServer(client_p) || IsHandshake(client_p))
287 <          {
288 <            sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
289 <                                 "No response from %s, closing link",
290 <                                 get_client_name(client_p, HIDE_IP));
291 <            sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
292 <                                 "No response from %s, closing link",
293 <                                 get_client_name(client_p, MASK_IP));
294 <            ilog(LOG_TYPE_IRCD, "No response from %s, closing link",
295 <                 get_client_name(client_p, HIDE_IP));
296 <          }
287 >          {
288 >            sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
289 >                                 "No response from %s, closing link",
290 >                                 get_client_name(client_p, HIDE_IP));
291 >            sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
292 >                                 "No response from %s, closing link",
293 >                                 get_client_name(client_p, MASK_IP));
294 >            ilog(LOG_TYPE_IRCD, "No response from %s, closing link",
295 >                 get_client_name(client_p, HIDE_IP));
296 >          }
297  
298            snprintf(scratch, sizeof(scratch), "Ping timeout: %d seconds",
299                     (int)(CurrentTime - client_p->localClient->lasttime));
# Line 334 | Line 335 | check_unknowns_list(void)
335   * side effects - Check all connections for a pending kline against the
336   *                client, exit the client if a kline matches.
337   */
338 < void
338 > void
339   check_conf_klines(void)
340 < {              
340 > {
341    struct Client *client_p = NULL;       /* current local client_p being examined */
342    struct MaskItem *conf = NULL;
343    dlink_node *ptr, *next_ptr;
# Line 354 | Line 355 | check_conf_klines(void)
355                                    client_p->localClient->aftype)) != NULL)
356      {
357        if (conf->type == CONF_EXEMPT)
358 <        continue;
358 >        continue;
359  
360        ban_them(client_p, conf);
361        continue; /* and go examine next fd/client_p */
362      }
363  
364 <    if (ConfigFileEntry.glines && (conf = find_gline(client_p)))
364 >    if (ConfigFileEntry.glines)
365      {
366 <      if (IsExemptKline(client_p) ||
367 <          IsExemptGline(client_p))
366 >      if ((conf = find_conf_by_address(client_p->host, &client_p->localClient->ip,
367 >                                       CONF_GLINE, client_p->localClient->aftype,
368 >                                       client_p->username, NULL, 1)))
369        {
370 <        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
371 <                             "GLINE over-ruled for %s, client is %sline_exempt",
372 <                             get_client_name(client_p, HIDE_IP), IsExemptKline(client_p) ? "k" : "g");
370 >        if (IsExemptKline(client_p) ||
371 >            IsExemptGline(client_p))
372 >        {
373 >          sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
374 >                               "GLINE over-ruled for %s, client is %sline_exempt",
375 >                               get_client_name(client_p, HIDE_IP), IsExemptKline(client_p) ? "k" : "g");
376 >          continue;
377 >        }
378 >
379 >        ban_them(client_p, conf);
380 >        /* and go examine next fd/client_p */
381          continue;
382        }
383 +    }
384  
385 <      ban_them(client_p, conf);
386 <      /* and go examine next fd/client_p */    
387 <      continue;
377 <    }
378 <
379 <    if ((conf = find_kill(client_p)) != NULL)
385 >    if ((conf = find_conf_by_address(client_p->host, &client_p->localClient->ip,
386 >                                     CONF_KLINE, client_p->localClient->aftype,
387 >                                     client_p->username, NULL, 1)))
388      {
389        if (IsExemptKline(client_p))
390        {
# Line 387 | Line 395 | check_conf_klines(void)
395        }
396  
397        ban_them(client_p, conf);
398 <      continue;
398 >      continue;
399      }
400  
401      if ((conf = find_matching_name_conf(CONF_XLINE,  client_p->info,
402 <                                        NULL, NULL, 0)) != NULL ||
395 <        (conf = find_matching_name_conf(CONF_RXLINE, client_p->info,
396 <                                        NULL, NULL, 0)) != NULL)
402 >                                        NULL, NULL, 0)))
403      {
404        ban_them(client_p, conf);
405        continue;
# Line 424 | Line 430 | check_conf_klines(void)
430   * output       - NONE
431   * side effects - given client_p is banned
432   */
433 < static void
433 > void
434   ban_them(struct Client *client_p, struct MaskItem *conf)
435   {
436 <  const char *user_reason = NULL;       /* What is sent to user */
436 >  const char *user_reason = NULL;  /* What is sent to user */
437    const char *type_string = NULL;
438    const char dline_string[] = "D-line";
439    const char kline_string[] = "K-line";
# Line 436 | Line 442 | ban_them(struct Client *client_p, struct
442  
443    switch (conf->type)
444    {
439    case CONF_RKLINE:
445      case CONF_KLINE:
446 +      if (IsExemptKline(client_p))
447 +      {
448 +        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
449 +                             "KLINE over-ruled for %s, client is kline_exempt",
450 +                             get_client_name(client_p, HIDE_IP));
451 +        return;
452 +      }
453 +
454        type_string = kline_string;
455        break;
456      case CONF_DLINE:
457        type_string = dline_string;
458        break;
459      case CONF_GLINE:
460 +      if (IsExemptKline(client_p) ||
461 +          IsExemptGline(client_p))
462 +      {
463 +        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
464 +                             "GLINE over-ruled for %s, client is %sline_exempt",
465 +                             get_client_name(client_p, HIDE_IP), IsExemptKline(client_p) ? "k" : "g");
466 +        return;
467 +      }
468 +        
469        type_string = gline_string;
470        break;
449    case CONF_RXLINE:
471      case CONF_XLINE:
472        type_string = xline_string;
473        ++conf->count;
# Line 463 | Line 484 | ban_them(struct Client *client_p, struct
484  
485    if (IsClient(client_p))
486      sendto_one(client_p, form_str(ERR_YOUREBANNEDCREEP),
487 <               me.name, client_p->name, user_reason);
487 >               me.name, client_p->name, user_reason);
488  
489    exit_client(client_p, &me, user_reason);
490   }
# Line 472 | Line 493 | ban_them(struct Client *client_p, struct
493   *
494   * input        - pointer to client
495   * output       - NONE
496 < * side effects -
496 > * side effects -
497   */
498   static void
499   update_client_exit_stats(struct Client *client_p)
# Line 504 | Line 525 | update_client_exit_stats(struct Client *
525   struct Client *
526   find_person(const struct Client *client_p, const char *name)
527   {
528 <  struct Client *c2ptr = NULL;
528 >  struct Client *target_p = NULL;
529  
530    if (IsDigit(*name))
531    {
532 <    if ((c2ptr = hash_find_id(name)) != NULL)
533 <    {
513 <      /* invisible users shall not be found by UID guessing */
514 <      if (HasUMode(c2ptr, UMODE_INVISIBLE))
515 <        if (!IsServer(client_p) && !HasFlag(client_p, FLAGS_SERVICE))
516 <          c2ptr = NULL;
517 <    }
532 >    if (IsServer(client_p) || HasFlag(client_p, FLAGS_SERVICE))
533 >      target_p = hash_find_id(name);
534    }
535    else
536 <    c2ptr = hash_find_client(name);
536 >    target_p = hash_find_client(name);
537  
538 <  return ((c2ptr != NULL && IsClient(c2ptr)) ? c2ptr : NULL);
538 >  return (target_p && IsClient(target_p)) ? target_p : NULL;
539   }
540  
541   /*
542 < * find_chasing - find the client structure for a nick name (user)
543 < *      using history mechanism if necessary. If the client is not found,
542 > * find_chasing - find the client structure for a nick name (name)
543 > *      using history mechanism if necessary. If the client is not found,
544   *      an error message (NO SUCH NICK) is generated. If the client was found
545   *      through the history, chasing will be 1 and otherwise 0.
546   */
547   struct Client *
548 < find_chasing(struct Client *client_p, struct Client *source_p, const char *user, int *chasing)
548 > find_chasing(struct Client *source_p, const char *name, int *const chasing)
549   {
550 <  struct Client *who = find_person(client_p, user);
550 >  struct Client *who = find_person(source_p->from, name);
551  
552    if (chasing)
553      *chasing = 0;
# Line 539 | Line 555 | find_chasing(struct Client *client_p, st
555    if (who)
556      return who;
557  
558 <  if (IsDigit(*user))
558 >  if (IsDigit(*name))
559      return NULL;
560  
561 <  if ((who = get_history(user,
562 <                        (time_t)ConfigFileEntry.kill_chase_time_limit))
563 <                         == NULL)
561 >  if ((who = whowas_get_history(name,
562 >                         (time_t)ConfigFileEntry.kill_chase_time_limit))
563 >                         == NULL)
564    {
565      sendto_one(source_p, form_str(ERR_NOSUCHNICK),
566 <               me.name, source_p->name, user);
566 >               me.name, source_p->name, name);
567      return NULL;
568    }
569  
# Line 582 | Line 598 | get_client_name(const struct Client *cli
598  
599    assert(client != NULL);
600  
601 <  if (!MyConnect(client))
601 >  if (!MyConnect(client))
602      return client->name;
603  
604    if (IsServer(client) || IsConnecting(client) || IsHandshake(client))
# Line 626 | Line 642 | void
642   free_exited_clients(void)
643   {
644    dlink_node *ptr = NULL, *next = NULL;
645 <  
645 >
646    DLINK_FOREACH_SAFE(ptr, next, dead_list.head)
647    {
648      free_client(ptr->data);
# Line 665 | Line 681 | exit_one_client(struct Client *source_p,
681      DLINK_FOREACH_SAFE(lp, next_lp, source_p->channel.head)
682        remove_user_from_channel(lp->data);
683  
684 <    add_history(source_p, 0);
685 <    off_history(source_p);
684 >    whowas_add_history(source_p, 0);
685 >    whowas_off_history(source_p);
686  
687      watch_check_hash(source_p, RPL_LOGOFF);
688  
# Line 755 | Line 771 | recurse_send_quits(struct Client *origin
771    }
772   }
773  
774 < /*
774 > /*
775   * Remove all clients that depend on source_p; assumes all (S)QUITs have
776 < * already been sent.  we make sure to exit a server's dependent clients
777 < * and servers before the server itself; exit_one_client takes care of
776 > * already been sent.  we make sure to exit a server's dependent clients
777 > * and servers before the server itself; exit_one_client takes care of
778   * actually removing things off llists.   tweaked from +CSr31  -orabidoo
779   */
780   static void
# Line 830 | Line 846 | exit_client(struct Client *source_p, str
846      if (IsIpHash(source_p))
847        remove_one_ip(&source_p->localClient->ip);
848  
849 <    if (source_p->localClient->auth)
834 <    {
835 <      delete_auth(source_p->localClient->auth);
836 <      source_p->localClient->auth = NULL;
837 <    }
849 >    delete_auth(&source_p->localClient->auth);
850  
851      /*
852       * This source_p could have status of one of STAT_UNKNOWN, STAT_CONNECTING
# Line 871 | Line 883 | exit_client(struct Client *source_p, str
883                             source_p->name, source_p->username, source_p->host, comment,
884                             ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
885                             "255.255.255.255" : source_p->sockhost);
874      sendto_realops_flags(UMODE_CCONN_FULL, L_ALL, SEND_NOTICE,
875                           "CLIEXIT: %s %s %s %s 0 %s",
876                           source_p->name,
877                           source_p->username,
878                           source_p->host,
879                           ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
880                           "255.255.255.255" : source_p->sockhost,
881                           comment);
886        ilog(LOG_TYPE_USER, "%s (%3u:%02u:%02u): %s!%s@%s %llu/%llu",
887             myctime(source_p->localClient->firsttime), (unsigned int)(on_for / 3600),
888             (unsigned int)((on_for % 3600)/60), (unsigned int)(on_for % 60),
# Line 902 | Line 906 | exit_client(struct Client *source_p, str
906        {
907          /* for them, we are exiting the network */
908          sendto_one(source_p, ":%s SQUIT %s :%s",
909 <                   ID_or_name(from, source_p), me.name, comment);
909 >                   ID_or_name(from, source_p), me.name, comment);
910        }
911  
912        sendto_one(source_p, "ERROR :Closing Link: %s (%s)",
# Line 922 | Line 926 | exit_client(struct Client *source_p, str
926      */
927      close_connection(source_p);
928    }
929 +  else if (IsClient(source_p) && HasFlag(source_p->servptr, FLAGS_EOB))
930 +    sendto_realops_flags(UMODE_FARCONNECT, L_ALL, SEND_NOTICE,
931 +                         "Client exiting at %s: %s (%s@%s) [%s]",
932 +                         source_p->servptr->name, source_p->name,
933 +                         source_p->username, source_p->host, comment);
934  
935    if (IsServer(source_p))
936    {
# Line 932 | Line 941 | exit_client(struct Client *source_p, str
941  
942      if (ConfigServerHide.hide_servers)
943        /*
944 <       * Set netsplit message to "*.net *.split" to still show
944 >       * Set netsplit message to "*.net *.split" to still show
945         * that its a split, but hide the servers splitting
946         */
947        strcpy(splitstr, "*.net *.split");
# Line 950 | Line 959 | exit_client(struct Client *source_p, str
959                             source_p->localClient->send.bytes >> 10,
960                             source_p->localClient->recv.bytes >> 10);
961        ilog(LOG_TYPE_IRCD, "%s was connected for %d seconds.  %llu/%llu sendK/recvK.",
962 <           source_p->name, (int)(CurrentTime - source_p->localClient->firsttime),
962 >           source_p->name, (int)(CurrentTime - source_p->localClient->firsttime),
963             source_p->localClient->send.bytes >> 10,
964             source_p->localClient->recv.bytes >> 10);
965      }
# Line 1005 | Line 1014 | dead_link_on_write(struct Client *client
1014   void
1015   dead_link_on_read(struct Client *client_p, int error)
1016   {
1017 <  char errmsg[255];
1017 >  char errmsg[IRCD_BUFSIZE];
1018    int current_error;
1019  
1020    if (IsDefunct(client_p))
# Line 1019 | Line 1028 | dead_link_on_read(struct Client *client_
1028    if (IsServer(client_p) || IsHandshake(client_p))
1029    {
1030      int connected = CurrentTime - client_p->localClient->firsttime;
1031 <      
1031 >
1032      if (error == 0)
1033      {
1034        /* Admins get the real IP */
1035        sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
1036 <                           "Server %s closed the connection",
1037 <                           get_client_name(client_p, SHOW_IP));
1036 >                           "Server %s closed the connection",
1037 >                           get_client_name(client_p, SHOW_IP));
1038  
1039        /* Opers get a masked IP */
1040        sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
1041 <                           "Server %s closed the connection",
1042 <                           get_client_name(client_p, MASK_IP));
1041 >                           "Server %s closed the connection",
1042 >                           get_client_name(client_p, MASK_IP));
1043  
1044        ilog(LOG_TYPE_IRCD, "Server %s closed the connection",
1045 <           get_client_name(client_p, SHOW_IP));
1045 >           get_client_name(client_p, SHOW_IP));
1046      }
1047      else
1048      {
1049        report_error(L_ADMIN, "Lost connection to %s: %s",
1050 <                   get_client_name(client_p, SHOW_IP), current_error);
1050 >                   get_client_name(client_p, SHOW_IP), current_error);
1051        report_error(L_OPER, "Lost connection to %s: %s",
1052 <                   get_client_name(client_p, MASK_IP), current_error);
1052 >                   get_client_name(client_p, MASK_IP), current_error);
1053      }
1054  
1055      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1056 <                         "%s had been connected for %d day%s, %2d:%02d:%02d",
1057 <                         client_p->name, connected/86400,
1058 <                         (connected/86400 == 1) ? "" : "s",
1059 <                         (connected % 86400) / 3600, (connected % 3600) / 60,
1060 <                         connected % 60);
1056 >                         "%s had been connected for %d day%s, %2d:%02d:%02d",
1057 >                         client_p->name, connected/86400,
1058 >                         (connected/86400 == 1) ? "" : "s",
1059 >                         (connected % 86400) / 3600, (connected % 3600) / 60,
1060 >                         connected % 60);
1061    }
1062  
1063    if (error == 0)
# Line 1089 | Line 1098 | exit_aborted_clients(void)
1098      else
1099        notice = "Write error: connection closed";
1100  
1101 <    exit_client(target_p, &me, notice);  
1101 >    exit_client(target_p, &me, notice);
1102      free_dlink_node(ptr);
1103    }
1104   }
# Line 1117 | Line 1126 | del_accept(struct split_nuh_item *accept
1126  
1127   struct split_nuh_item *
1128   find_accept(const char *nick, const char *user,
1129 <            const char *host, struct Client *client_p, int do_match)
1129 >            const char *host, struct Client *client_p,
1130 >            int (*cmpfunc)(const char *, const char *))
1131   {
1132    dlink_node *ptr = NULL;
1123  /* XXX We wouldn't need that if match() would return 0 on match */
1124  int (*cmpfunc)(const char *, const char *) = do_match ? match : irccmp;
1133  
1134    DLINK_FOREACH(ptr, client_p->localClient->acceptlist.head)
1135    {
# Line 1150 | Line 1158 | accept_message(struct Client *source,
1158    dlink_node *ptr = NULL;
1159  
1160    if (source == target || find_accept(source->name, source->username,
1161 <                                      source->host, target, 1))
1161 >                                      source->host, target, match))
1162      return 1;
1163  
1164    if (HasUMode(target, UMODE_SOFTCALLERID))
# Line 1182 | Line 1190 | idle_time_get(const struct Client *sourc
1190    unsigned int idle = 0;
1191    unsigned int min_idle = 0;
1192    unsigned int max_idle = 0;
1193 <  struct ClassItem *class = get_class_ptr(&target_p->localClient->confs);
1193 >  const struct ClassItem *class = get_class_ptr(&target_p->localClient->confs);
1194  
1195    if (!(class->flags & CLASS_FLAGS_FAKE_IDLE) || target_p == source_p)
1196      return CurrentTime - target_p->localClient->last_privmsg;

Diff Legend

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