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 1785 by michael, Sat Jan 26 22:40:55 2013 UTC vs.
Revision 2522 by michael, Fri Nov 1 20:44:04 2013 UTC

# Line 78 | Line 78 | static void check_unknowns_list(void);
78   static void ban_them(struct Client *, struct MaskItem *);
79  
80  
81 < /* init_client()
81 > /* client_init()
82   *
83   * inputs       - NONE
84   * output       - NONE
85   * side effects - initialize client free memory
86   */
87   void
88 < init_client(void)
88 > client_init(void)
89   {
90    /* start off the check ping event ..  -- adrian
91     * Every 30 seconds is plenty -- db
# 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)
# 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 (!(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 +        continue;
370 +
371        if (IsExemptKline(client_p) ||
372            IsExemptGline(client_p))
373        {
# Line 372 | Line 378 | check_conf_klines(void)
378        }
379  
380        ban_them(client_p, conf);
381 <      /* and go examine next fd/client_p */    
381 >      /* and go examine next fd/client_p */
382        continue;
383 <    }
383 >    }
384  
385 <    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)) != NULL)
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 427 | Line 433 | check_conf_klines(void)
433   static 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        type_string = kline_string;
447        break;
# Line 446 | Line 451 | ban_them(struct Client *client_p, struct
451      case CONF_GLINE:
452        type_string = gline_string;
453        break;
449    case CONF_RXLINE:
454      case CONF_XLINE:
455        type_string = xline_string;
456        ++conf->count;
# Line 463 | Line 467 | ban_them(struct Client *client_p, struct
467  
468    if (IsClient(client_p))
469      sendto_one(client_p, form_str(ERR_YOUREBANNEDCREEP),
470 <               me.name, client_p->name, user_reason);
470 >               me.name, client_p->name, user_reason);
471  
472    exit_client(client_p, &me, user_reason);
473   }
# Line 472 | Line 476 | ban_them(struct Client *client_p, struct
476   *
477   * input        - pointer to client
478   * output       - NONE
479 < * side effects -
479 > * side effects -
480   */
481   static void
482   update_client_exit_stats(struct Client *client_p)
# Line 504 | Line 508 | update_client_exit_stats(struct Client *
508   struct Client *
509   find_person(const struct Client *client_p, const char *name)
510   {
511 <  struct Client *c2ptr = NULL;
511 >  struct Client *target_p = NULL;
512  
513    if (IsDigit(*name))
514    {
515 <    if ((c2ptr = hash_find_id(name)) != NULL)
515 >    if ((target_p = hash_find_id(name)) != NULL)
516      {
517        /* invisible users shall not be found by UID guessing */
518 <      if (HasUMode(c2ptr, UMODE_INVISIBLE))
518 >      if (HasUMode(target_p, UMODE_INVISIBLE))
519          if (!IsServer(client_p) && !HasFlag(client_p, FLAGS_SERVICE))
520 <          c2ptr = NULL;
520 >          target_p = NULL;
521      }
522    }
523    else
524 <    c2ptr = hash_find_client(name);
524 >    target_p = hash_find_client(name);
525  
526 <  return ((c2ptr != NULL && IsClient(c2ptr)) ? c2ptr : NULL);
526 >  return (target_p && IsClient(target_p)) ? target_p : NULL;
527   }
528  
529   /*
530 < * find_chasing - find the client structure for a nick name (user)
531 < *      using history mechanism if necessary. If the client is not found,
530 > * find_chasing - find the client structure for a nick name (name)
531 > *      using history mechanism if necessary. If the client is not found,
532   *      an error message (NO SUCH NICK) is generated. If the client was found
533   *      through the history, chasing will be 1 and otherwise 0.
534   */
535   struct Client *
536 < find_chasing(struct Client *client_p, struct Client *source_p, const char *user, int *chasing)
536 > find_chasing(struct Client *source_p, const char *name, int *const chasing)
537   {
538 <  struct Client *who = find_person(client_p, user);
538 >  struct Client *who = find_person(source_p->from, name);
539  
540    if (chasing)
541      *chasing = 0;
# Line 539 | Line 543 | find_chasing(struct Client *client_p, st
543    if (who)
544      return who;
545  
546 <  if (IsDigit(*user))
546 >  if (IsDigit(*name))
547      return NULL;
548  
549 <  if ((who = get_history(user,
550 <                        (time_t)ConfigFileEntry.kill_chase_time_limit))
551 <                         == NULL)
549 >  if ((who = whowas_get_history(name,
550 >                         (time_t)ConfigFileEntry.kill_chase_time_limit))
551 >                         == NULL)
552    {
553      sendto_one(source_p, form_str(ERR_NOSUCHNICK),
554 <               me.name, source_p->name, user);
554 >               me.name, source_p->name, name);
555      return NULL;
556    }
557  
# Line 582 | Line 586 | get_client_name(const struct Client *cli
586  
587    assert(client != NULL);
588  
589 <  if (!MyConnect(client))
589 >  if (!MyConnect(client))
590      return client->name;
591  
592    if (IsServer(client) || IsConnecting(client) || IsHandshake(client))
# Line 626 | Line 630 | void
630   free_exited_clients(void)
631   {
632    dlink_node *ptr = NULL, *next = NULL;
633 <  
633 >
634    DLINK_FOREACH_SAFE(ptr, next, dead_list.head)
635    {
636      free_client(ptr->data);
# Line 665 | Line 669 | exit_one_client(struct Client *source_p,
669      DLINK_FOREACH_SAFE(lp, next_lp, source_p->channel.head)
670        remove_user_from_channel(lp->data);
671  
672 <    add_history(source_p, 0);
673 <    off_history(source_p);
672 >    whowas_add_history(source_p, 0);
673 >    whowas_off_history(source_p);
674  
675      watch_check_hash(source_p, RPL_LOGOFF);
676  
# Line 755 | Line 759 | recurse_send_quits(struct Client *origin
759    }
760   }
761  
762 < /*
762 > /*
763   * Remove all clients that depend on source_p; assumes all (S)QUITs have
764 < * already been sent.  we make sure to exit a server's dependent clients
765 < * and servers before the server itself; exit_one_client takes care of
764 > * already been sent.  we make sure to exit a server's dependent clients
765 > * and servers before the server itself; exit_one_client takes care of
766   * actually removing things off llists.   tweaked from +CSr31  -orabidoo
767   */
768   static void
# Line 830 | Line 834 | exit_client(struct Client *source_p, str
834      if (IsIpHash(source_p))
835        remove_one_ip(&source_p->localClient->ip);
836  
837 <    if (source_p->localClient->auth)
834 <    {
835 <      delete_auth(source_p->localClient->auth);
836 <      source_p->localClient->auth = NULL;
837 <    }
837 >    delete_auth(&source_p->localClient->auth);
838  
839      /*
840       * This source_p could have status of one of STAT_UNKNOWN, STAT_CONNECTING
# Line 871 | Line 871 | exit_client(struct Client *source_p, str
871                             source_p->name, source_p->username, source_p->host, comment,
872                             ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
873                             "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);
874        ilog(LOG_TYPE_USER, "%s (%3u:%02u:%02u): %s!%s@%s %llu/%llu",
875             myctime(source_p->localClient->firsttime), (unsigned int)(on_for / 3600),
876             (unsigned int)((on_for % 3600)/60), (unsigned int)(on_for % 60),
# Line 902 | Line 894 | exit_client(struct Client *source_p, str
894        {
895          /* for them, we are exiting the network */
896          sendto_one(source_p, ":%s SQUIT %s :%s",
897 <                   ID_or_name(from, source_p), me.name, comment);
897 >                   ID_or_name(from, source_p), me.name, comment);
898        }
899  
900        sendto_one(source_p, "ERROR :Closing Link: %s (%s)",
# Line 922 | Line 914 | exit_client(struct Client *source_p, str
914      */
915      close_connection(source_p);
916    }
917 +  else if (IsClient(source_p) && HasFlag(source_p->servptr, FLAGS_EOB))
918 +    sendto_realops_flags(UMODE_FARCONNECT, L_ALL, SEND_NOTICE,
919 +                         "Client exiting at %s: %s (%s@%s) [%s]",
920 +                         source_p->servptr->name, source_p->name,
921 +                         source_p->username, source_p->host, comment);
922  
923    if (IsServer(source_p))
924    {
# Line 932 | Line 929 | exit_client(struct Client *source_p, str
929  
930      if (ConfigServerHide.hide_servers)
931        /*
932 <       * Set netsplit message to "*.net *.split" to still show
932 >       * Set netsplit message to "*.net *.split" to still show
933         * that its a split, but hide the servers splitting
934         */
935        strcpy(splitstr, "*.net *.split");
# Line 950 | Line 947 | exit_client(struct Client *source_p, str
947                             source_p->localClient->send.bytes >> 10,
948                             source_p->localClient->recv.bytes >> 10);
949        ilog(LOG_TYPE_IRCD, "%s was connected for %d seconds.  %llu/%llu sendK/recvK.",
950 <           source_p->name, (int)(CurrentTime - source_p->localClient->firsttime),
950 >           source_p->name, (int)(CurrentTime - source_p->localClient->firsttime),
951             source_p->localClient->send.bytes >> 10,
952             source_p->localClient->recv.bytes >> 10);
953      }
# Line 1019 | Line 1016 | dead_link_on_read(struct Client *client_
1016    if (IsServer(client_p) || IsHandshake(client_p))
1017    {
1018      int connected = CurrentTime - client_p->localClient->firsttime;
1019 <      
1019 >
1020      if (error == 0)
1021      {
1022        /* Admins get the real IP */
1023        sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
1024 <                           "Server %s closed the connection",
1025 <                           get_client_name(client_p, SHOW_IP));
1024 >                           "Server %s closed the connection",
1025 >                           get_client_name(client_p, SHOW_IP));
1026  
1027        /* Opers get a masked IP */
1028        sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
1029 <                           "Server %s closed the connection",
1030 <                           get_client_name(client_p, MASK_IP));
1029 >                           "Server %s closed the connection",
1030 >                           get_client_name(client_p, MASK_IP));
1031  
1032        ilog(LOG_TYPE_IRCD, "Server %s closed the connection",
1033 <           get_client_name(client_p, SHOW_IP));
1033 >           get_client_name(client_p, SHOW_IP));
1034      }
1035      else
1036      {
1037        report_error(L_ADMIN, "Lost connection to %s: %s",
1038 <                   get_client_name(client_p, SHOW_IP), current_error);
1038 >                   get_client_name(client_p, SHOW_IP), current_error);
1039        report_error(L_OPER, "Lost connection to %s: %s",
1040 <                   get_client_name(client_p, MASK_IP), current_error);
1040 >                   get_client_name(client_p, MASK_IP), current_error);
1041      }
1042  
1043      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1044 <                         "%s had been connected for %d day%s, %2d:%02d:%02d",
1045 <                         client_p->name, connected/86400,
1046 <                         (connected/86400 == 1) ? "" : "s",
1047 <                         (connected % 86400) / 3600, (connected % 3600) / 60,
1048 <                         connected % 60);
1044 >                         "%s had been connected for %d day%s, %2d:%02d:%02d",
1045 >                         client_p->name, connected/86400,
1046 >                         (connected/86400 == 1) ? "" : "s",
1047 >                         (connected % 86400) / 3600, (connected % 3600) / 60,
1048 >                         connected % 60);
1049    }
1050  
1051    if (error == 0)
# Line 1089 | Line 1086 | exit_aborted_clients(void)
1086      else
1087        notice = "Write error: connection closed";
1088  
1089 <    exit_client(target_p, &me, notice);  
1089 >    exit_client(target_p, &me, notice);
1090      free_dlink_node(ptr);
1091    }
1092   }
# Line 1117 | Line 1114 | del_accept(struct split_nuh_item *accept
1114  
1115   struct split_nuh_item *
1116   find_accept(const char *nick, const char *user,
1117 <            const char *host, struct Client *client_p, int do_match)
1117 >            const char *host, struct Client *client_p,
1118 >            int (*cmpfunc)(const char *, const char *))
1119   {
1120    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;
1121  
1122    DLINK_FOREACH(ptr, client_p->localClient->acceptlist.head)
1123    {
# Line 1150 | Line 1146 | accept_message(struct Client *source,
1146    dlink_node *ptr = NULL;
1147  
1148    if (source == target || find_accept(source->name, source->username,
1149 <                                      source->host, target, 1))
1149 >                                      source->host, target, match))
1150      return 1;
1151  
1152    if (HasUMode(target, UMODE_SOFTCALLERID))
# Line 1182 | Line 1178 | idle_time_get(const struct Client *sourc
1178    unsigned int idle = 0;
1179    unsigned int min_idle = 0;
1180    unsigned int max_idle = 0;
1181 <  struct ClassItem *class = get_class_ptr(&target_p->localClient->confs);
1181 >  const struct ClassItem *class = get_class_ptr(&target_p->localClient->confs);
1182  
1183    if (!(class->flags & CLASS_FLAGS_FAKE_IDLE) || target_p == source_p)
1184      return CurrentTime - target_p->localClient->last_privmsg;

Diff Legend

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