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 2583 by michael, Wed Nov 20 23:01:19 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)
516 <    {
517 <      /* 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 <    }
515 >    if ((target_p = hash_find_id(name)) != NULL)
516 >      if (!IsServer(client_p) && !HasFlag(client_p, FLAGS_SERVICE))
517 >        target_p = NULL;
518    }
519    else
520 <    c2ptr = hash_find_client(name);
520 >    target_p = hash_find_client(name);
521  
522 <  return ((c2ptr != NULL && IsClient(c2ptr)) ? c2ptr : NULL);
522 >  return (target_p && IsClient(target_p)) ? target_p : NULL;
523   }
524  
525   /*
526 < * find_chasing - find the client structure for a nick name (user)
527 < *      using history mechanism if necessary. If the client is not found,
526 > * find_chasing - find the client structure for a nick name (name)
527 > *      using history mechanism if necessary. If the client is not found,
528   *      an error message (NO SUCH NICK) is generated. If the client was found
529   *      through the history, chasing will be 1 and otherwise 0.
530   */
531   struct Client *
532 < find_chasing(struct Client *client_p, struct Client *source_p, const char *user, int *chasing)
532 > find_chasing(struct Client *source_p, const char *name, int *const chasing)
533   {
534 <  struct Client *who = find_person(client_p, user);
534 >  struct Client *who = find_person(source_p->from, name);
535  
536    if (chasing)
537      *chasing = 0;
# Line 539 | Line 539 | find_chasing(struct Client *client_p, st
539    if (who)
540      return who;
541  
542 <  if (IsDigit(*user))
542 >  if (IsDigit(*name))
543      return NULL;
544  
545 <  if ((who = get_history(user,
546 <                        (time_t)ConfigFileEntry.kill_chase_time_limit))
547 <                         == NULL)
545 >  if ((who = whowas_get_history(name,
546 >                         (time_t)ConfigFileEntry.kill_chase_time_limit))
547 >                         == NULL)
548    {
549      sendto_one(source_p, form_str(ERR_NOSUCHNICK),
550 <               me.name, source_p->name, user);
550 >               me.name, source_p->name, name);
551      return NULL;
552    }
553  
# Line 582 | Line 582 | get_client_name(const struct Client *cli
582  
583    assert(client != NULL);
584  
585 <  if (!MyConnect(client))
585 >  if (!MyConnect(client))
586      return client->name;
587  
588    if (IsServer(client) || IsConnecting(client) || IsHandshake(client))
# Line 626 | Line 626 | void
626   free_exited_clients(void)
627   {
628    dlink_node *ptr = NULL, *next = NULL;
629 <  
629 >
630    DLINK_FOREACH_SAFE(ptr, next, dead_list.head)
631    {
632      free_client(ptr->data);
# Line 665 | Line 665 | exit_one_client(struct Client *source_p,
665      DLINK_FOREACH_SAFE(lp, next_lp, source_p->channel.head)
666        remove_user_from_channel(lp->data);
667  
668 <    add_history(source_p, 0);
669 <    off_history(source_p);
668 >    whowas_add_history(source_p, 0);
669 >    whowas_off_history(source_p);
670  
671      watch_check_hash(source_p, RPL_LOGOFF);
672  
# Line 755 | Line 755 | recurse_send_quits(struct Client *origin
755    }
756   }
757  
758 < /*
758 > /*
759   * Remove all clients that depend on source_p; assumes all (S)QUITs have
760 < * already been sent.  we make sure to exit a server's dependent clients
761 < * and servers before the server itself; exit_one_client takes care of
760 > * already been sent.  we make sure to exit a server's dependent clients
761 > * and servers before the server itself; exit_one_client takes care of
762   * actually removing things off llists.   tweaked from +CSr31  -orabidoo
763   */
764   static void
# Line 830 | Line 830 | exit_client(struct Client *source_p, str
830      if (IsIpHash(source_p))
831        remove_one_ip(&source_p->localClient->ip);
832  
833 <    if (source_p->localClient->auth)
834 <    {
835 <      delete_auth(source_p->localClient->auth);
836 <      source_p->localClient->auth = NULL;
837 <    }
833 >    delete_auth(&source_p->localClient->auth);
834  
835      /*
836       * This source_p could have status of one of STAT_UNKNOWN, STAT_CONNECTING
# Line 871 | Line 867 | exit_client(struct Client *source_p, str
867                             source_p->name, source_p->username, source_p->host, comment,
868                             ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
869                             "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);
870        ilog(LOG_TYPE_USER, "%s (%3u:%02u:%02u): %s!%s@%s %llu/%llu",
871             myctime(source_p->localClient->firsttime), (unsigned int)(on_for / 3600),
872             (unsigned int)((on_for % 3600)/60), (unsigned int)(on_for % 60),
# Line 902 | Line 890 | exit_client(struct Client *source_p, str
890        {
891          /* for them, we are exiting the network */
892          sendto_one(source_p, ":%s SQUIT %s :%s",
893 <                   ID_or_name(from, source_p), me.name, comment);
893 >                   ID_or_name(from, source_p), me.name, comment);
894        }
895  
896        sendto_one(source_p, "ERROR :Closing Link: %s (%s)",
# Line 922 | Line 910 | exit_client(struct Client *source_p, str
910      */
911      close_connection(source_p);
912    }
913 +  else if (IsClient(source_p) && HasFlag(source_p->servptr, FLAGS_EOB))
914 +    sendto_realops_flags(UMODE_FARCONNECT, L_ALL, SEND_NOTICE,
915 +                         "Client exiting at %s: %s (%s@%s) [%s]",
916 +                         source_p->servptr->name, source_p->name,
917 +                         source_p->username, source_p->host, comment);
918  
919    if (IsServer(source_p))
920    {
# Line 932 | Line 925 | exit_client(struct Client *source_p, str
925  
926      if (ConfigServerHide.hide_servers)
927        /*
928 <       * Set netsplit message to "*.net *.split" to still show
928 >       * Set netsplit message to "*.net *.split" to still show
929         * that its a split, but hide the servers splitting
930         */
931        strcpy(splitstr, "*.net *.split");
# Line 950 | Line 943 | exit_client(struct Client *source_p, str
943                             source_p->localClient->send.bytes >> 10,
944                             source_p->localClient->recv.bytes >> 10);
945        ilog(LOG_TYPE_IRCD, "%s was connected for %d seconds.  %llu/%llu sendK/recvK.",
946 <           source_p->name, (int)(CurrentTime - source_p->localClient->firsttime),
946 >           source_p->name, (int)(CurrentTime - source_p->localClient->firsttime),
947             source_p->localClient->send.bytes >> 10,
948             source_p->localClient->recv.bytes >> 10);
949      }
# Line 1019 | Line 1012 | dead_link_on_read(struct Client *client_
1012    if (IsServer(client_p) || IsHandshake(client_p))
1013    {
1014      int connected = CurrentTime - client_p->localClient->firsttime;
1015 <      
1015 >
1016      if (error == 0)
1017      {
1018        /* Admins get the real IP */
1019        sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
1020 <                           "Server %s closed the connection",
1021 <                           get_client_name(client_p, SHOW_IP));
1020 >                           "Server %s closed the connection",
1021 >                           get_client_name(client_p, SHOW_IP));
1022  
1023        /* Opers get a masked IP */
1024        sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
1025 <                           "Server %s closed the connection",
1026 <                           get_client_name(client_p, MASK_IP));
1025 >                           "Server %s closed the connection",
1026 >                           get_client_name(client_p, MASK_IP));
1027  
1028        ilog(LOG_TYPE_IRCD, "Server %s closed the connection",
1029 <           get_client_name(client_p, SHOW_IP));
1029 >           get_client_name(client_p, SHOW_IP));
1030      }
1031      else
1032      {
1033        report_error(L_ADMIN, "Lost connection to %s: %s",
1034 <                   get_client_name(client_p, SHOW_IP), current_error);
1034 >                   get_client_name(client_p, SHOW_IP), current_error);
1035        report_error(L_OPER, "Lost connection to %s: %s",
1036 <                   get_client_name(client_p, MASK_IP), current_error);
1036 >                   get_client_name(client_p, MASK_IP), current_error);
1037      }
1038  
1039      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1040 <                         "%s had been connected for %d day%s, %2d:%02d:%02d",
1041 <                         client_p->name, connected/86400,
1042 <                         (connected/86400 == 1) ? "" : "s",
1043 <                         (connected % 86400) / 3600, (connected % 3600) / 60,
1044 <                         connected % 60);
1040 >                         "%s had been connected for %d day%s, %2d:%02d:%02d",
1041 >                         client_p->name, connected/86400,
1042 >                         (connected/86400 == 1) ? "" : "s",
1043 >                         (connected % 86400) / 3600, (connected % 3600) / 60,
1044 >                         connected % 60);
1045    }
1046  
1047    if (error == 0)
# Line 1089 | Line 1082 | exit_aborted_clients(void)
1082      else
1083        notice = "Write error: connection closed";
1084  
1085 <    exit_client(target_p, &me, notice);  
1085 >    exit_client(target_p, &me, notice);
1086      free_dlink_node(ptr);
1087    }
1088   }
# Line 1117 | Line 1110 | del_accept(struct split_nuh_item *accept
1110  
1111   struct split_nuh_item *
1112   find_accept(const char *nick, const char *user,
1113 <            const char *host, struct Client *client_p, int do_match)
1113 >            const char *host, struct Client *client_p,
1114 >            int (*cmpfunc)(const char *, const char *))
1115   {
1116    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;
1117  
1118    DLINK_FOREACH(ptr, client_p->localClient->acceptlist.head)
1119    {
# Line 1150 | Line 1142 | accept_message(struct Client *source,
1142    dlink_node *ptr = NULL;
1143  
1144    if (source == target || find_accept(source->name, source->username,
1145 <                                      source->host, target, 1))
1145 >                                      source->host, target, match))
1146      return 1;
1147  
1148    if (HasUMode(target, UMODE_SOFTCALLERID))
# Line 1182 | Line 1174 | idle_time_get(const struct Client *sourc
1174    unsigned int idle = 0;
1175    unsigned int min_idle = 0;
1176    unsigned int max_idle = 0;
1177 <  struct ClassItem *class = get_class_ptr(&target_p->localClient->confs);
1177 >  const struct ClassItem *class = get_class_ptr(&target_p->localClient->confs);
1178  
1179    if (!(class->flags & CLASS_FLAGS_FAKE_IDLE) || target_p == source_p)
1180      return CurrentTime - target_p->localClient->last_privmsg;

Diff Legend

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