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 2181 by michael, Tue Jun 4 11:03:41 2013 UTC vs.
Revision 2813 by michael, Sun Jan 12 20:23:50 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);
360 >      conf_try_ban(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",
370 <                             get_client_name(client_p, HIDE_IP), IsExemptKline(client_p) ? "k" : "g");
370 >        conf_try_ban(client_p, conf);
371 >        /* and go examine next fd/client_p */
372          continue;
373        }
374 +    }
375  
376 <      ban_them(client_p, conf);
377 <      /* and go examine next fd/client_p */    
378 <      continue;
377 <    }
378 <
379 <    if ((conf = find_kill(client_p)) != NULL)
376 >    if ((conf = find_conf_by_address(client_p->host, &client_p->localClient->ip,
377 >                                     CONF_KLINE, client_p->localClient->aftype,
378 >                                     client_p->username, NULL, 1)))
379      {
380 <      if (IsExemptKline(client_p))
381 <      {
383 <        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
384 <                             "KLINE over-ruled for %s, client is kline_exempt",
385 <                             get_client_name(client_p, HIDE_IP));
386 <        continue;
387 <      }
388 <
389 <      ban_them(client_p, conf);
390 <      continue;
380 >      conf_try_ban(client_p, conf);
381 >      continue;
382      }
383  
384      if ((conf = find_matching_name_conf(CONF_XLINE,  client_p->info,
385                                          NULL, NULL, 0)))
386      {
387 <      ban_them(client_p, conf);
387 >      conf_try_ban(client_p, conf);
388        continue;
389      }
390    }
# Line 415 | Line 406 | check_conf_klines(void)
406   }
407  
408   /*
409 < * ban_them
409 > * conf_try_ban
410   *
411   * inputs       - pointer to client to ban
412   *              - pointer to MaskItem
413   * output       - NONE
414   * side effects - given client_p is banned
415   */
416 < static void
417 < ban_them(struct Client *client_p, struct MaskItem *conf)
416 > void
417 > conf_try_ban(struct Client *client_p, struct MaskItem *conf)
418   {
419 <  const char *user_reason = NULL;       /* What is sent to user */
419 >  const char *user_reason = NULL;  /* What is sent to user */
420    const char *type_string = NULL;
421    const char dline_string[] = "D-line";
422    const char kline_string[] = "K-line";
# Line 435 | Line 426 | ban_them(struct Client *client_p, struct
426    switch (conf->type)
427    {
428      case CONF_KLINE:
429 +      if (IsExemptKline(client_p))
430 +      {
431 +        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
432 +                             "KLINE over-ruled for %s, client is kline_exempt",
433 +                             get_client_name(client_p, HIDE_IP));
434 +        return;
435 +      }
436 +
437        type_string = kline_string;
438        break;
439      case CONF_DLINE:
440        type_string = dline_string;
441        break;
442      case CONF_GLINE:
443 +      if (IsExemptKline(client_p) ||
444 +          IsExemptGline(client_p))
445 +      {
446 +        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
447 +                             "GLINE over-ruled for %s, client is %sline_exempt",
448 +                             get_client_name(client_p, HIDE_IP), IsExemptKline(client_p) ? "k" : "g");
449 +        return;
450 +      }
451 +        
452        type_string = gline_string;
453        break;
454      case CONF_XLINE:
# Line 459 | 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 468 | 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 500 | 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 <    {
509 <      /* invisible users shall not be found by UID guessing */
510 <      if (HasUMode(c2ptr, UMODE_INVISIBLE))
511 <        if (!IsServer(client_p) && !HasFlag(client_p, FLAGS_SERVICE))
512 <          c2ptr = NULL;
513 <    }
515 >    if (IsServer(client_p) || HasFlag(client_p, FLAGS_SERVICE))
516 >      target_p = hash_find_id(name);
517    }
518    else
519 <    c2ptr = hash_find_client(name);
519 >    target_p = hash_find_client(name);
520  
521 <  return ((c2ptr != NULL && IsClient(c2ptr)) ? c2ptr : NULL);
521 >  return (target_p && IsClient(target_p)) ? target_p : NULL;
522   }
523  
524   /*
525 < * find_chasing - find the client structure for a nick name (user)
526 < *      using history mechanism if necessary. If the client is not found,
525 > * find_chasing - find the client structure for a nick name (name)
526 > *      using history mechanism if necessary. If the client is not found,
527   *      an error message (NO SUCH NICK) is generated. If the client was found
528   *      through the history, chasing will be 1 and otherwise 0.
529   */
530   struct Client *
531 < find_chasing(struct Client *client_p, struct Client *source_p, const char *user, int *chasing)
531 > find_chasing(struct Client *source_p, const char *name, int *const chasing)
532   {
533 <  struct Client *who = find_person(client_p, user);
533 >  struct Client *who = find_person(source_p->from, name);
534  
535    if (chasing)
536      *chasing = 0;
# Line 535 | Line 538 | find_chasing(struct Client *client_p, st
538    if (who)
539      return who;
540  
541 <  if (IsDigit(*user))
541 >  if (IsDigit(*name))
542      return NULL;
543  
544 <  if ((who = get_history(user,
545 <                        (time_t)ConfigFileEntry.kill_chase_time_limit))
546 <                         == NULL)
544 >  if ((who = whowas_get_history(name,
545 >                         (time_t)ConfigFileEntry.kill_chase_time_limit))
546 >                         == NULL)
547    {
548      sendto_one(source_p, form_str(ERR_NOSUCHNICK),
549 <               me.name, source_p->name, user);
549 >               me.name, source_p->name, name);
550      return NULL;
551    }
552  
# Line 578 | Line 581 | get_client_name(const struct Client *cli
581  
582    assert(client != NULL);
583  
584 <  if (!MyConnect(client))
584 >  if (!MyConnect(client))
585      return client->name;
586  
587    if (IsServer(client) || IsConnecting(client) || IsHandshake(client))
# Line 622 | Line 625 | void
625   free_exited_clients(void)
626   {
627    dlink_node *ptr = NULL, *next = NULL;
628 <  
628 >
629    DLINK_FOREACH_SAFE(ptr, next, dead_list.head)
630    {
631      free_client(ptr->data);
# Line 661 | Line 664 | exit_one_client(struct Client *source_p,
664      DLINK_FOREACH_SAFE(lp, next_lp, source_p->channel.head)
665        remove_user_from_channel(lp->data);
666  
667 <    add_history(source_p, 0);
668 <    off_history(source_p);
667 >    whowas_add_history(source_p, 0);
668 >    whowas_off_history(source_p);
669  
670      watch_check_hash(source_p, RPL_LOGOFF);
671  
# Line 751 | Line 754 | recurse_send_quits(struct Client *origin
754    }
755   }
756  
757 < /*
757 > /*
758   * Remove all clients that depend on source_p; assumes all (S)QUITs have
759 < * already been sent.  we make sure to exit a server's dependent clients
760 < * and servers before the server itself; exit_one_client takes care of
759 > * already been sent.  we make sure to exit a server's dependent clients
760 > * and servers before the server itself; exit_one_client takes care of
761   * actually removing things off llists.   tweaked from +CSr31  -orabidoo
762   */
763   static void
# Line 863 | Line 866 | exit_client(struct Client *source_p, str
866                             source_p->name, source_p->username, source_p->host, comment,
867                             ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
868                             "255.255.255.255" : source_p->sockhost);
866      sendto_realops_flags(UMODE_CCONN_FULL, L_ALL, SEND_NOTICE,
867                           "CLIEXIT: %s %s %s %s 0 %s",
868                           source_p->name,
869                           source_p->username,
870                           source_p->host,
871                           ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
872                           "255.255.255.255" : source_p->sockhost,
873                           comment);
869        ilog(LOG_TYPE_USER, "%s (%3u:%02u:%02u): %s!%s@%s %llu/%llu",
870             myctime(source_p->localClient->firsttime), (unsigned int)(on_for / 3600),
871             (unsigned int)((on_for % 3600)/60), (unsigned int)(on_for % 60),
# Line 894 | Line 889 | exit_client(struct Client *source_p, str
889        {
890          /* for them, we are exiting the network */
891          sendto_one(source_p, ":%s SQUIT %s :%s",
892 <                   ID_or_name(from, source_p), me.name, comment);
892 >                   ID_or_name(from, source_p), me.name, comment);
893        }
894  
895        sendto_one(source_p, "ERROR :Closing Link: %s (%s)",
# Line 929 | Line 924 | exit_client(struct Client *source_p, str
924  
925      if (ConfigServerHide.hide_servers)
926        /*
927 <       * Set netsplit message to "*.net *.split" to still show
927 >       * Set netsplit message to "*.net *.split" to still show
928         * that its a split, but hide the servers splitting
929         */
930        strcpy(splitstr, "*.net *.split");
# Line 947 | Line 942 | exit_client(struct Client *source_p, str
942                             source_p->localClient->send.bytes >> 10,
943                             source_p->localClient->recv.bytes >> 10);
944        ilog(LOG_TYPE_IRCD, "%s was connected for %d seconds.  %llu/%llu sendK/recvK.",
945 <           source_p->name, (int)(CurrentTime - source_p->localClient->firsttime),
945 >           source_p->name, (int)(CurrentTime - source_p->localClient->firsttime),
946             source_p->localClient->send.bytes >> 10,
947             source_p->localClient->recv.bytes >> 10);
948      }
# Line 1002 | Line 997 | dead_link_on_write(struct Client *client
997   void
998   dead_link_on_read(struct Client *client_p, int error)
999   {
1000 <  char errmsg[255];
1000 >  char errmsg[IRCD_BUFSIZE];
1001    int current_error;
1002  
1003    if (IsDefunct(client_p))
# Line 1016 | Line 1011 | dead_link_on_read(struct Client *client_
1011    if (IsServer(client_p) || IsHandshake(client_p))
1012    {
1013      int connected = CurrentTime - client_p->localClient->firsttime;
1014 <      
1014 >
1015      if (error == 0)
1016      {
1017        /* Admins get the real IP */
1018        sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
1019 <                           "Server %s closed the connection",
1020 <                           get_client_name(client_p, SHOW_IP));
1019 >                           "Server %s closed the connection",
1020 >                           get_client_name(client_p, SHOW_IP));
1021  
1022        /* Opers get a masked IP */
1023        sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
1024 <                           "Server %s closed the connection",
1025 <                           get_client_name(client_p, MASK_IP));
1024 >                           "Server %s closed the connection",
1025 >                           get_client_name(client_p, MASK_IP));
1026  
1027        ilog(LOG_TYPE_IRCD, "Server %s closed the connection",
1028 <           get_client_name(client_p, SHOW_IP));
1028 >           get_client_name(client_p, SHOW_IP));
1029      }
1030      else
1031      {
1032        report_error(L_ADMIN, "Lost connection to %s: %s",
1033 <                   get_client_name(client_p, SHOW_IP), current_error);
1033 >                   get_client_name(client_p, SHOW_IP), current_error);
1034        report_error(L_OPER, "Lost connection to %s: %s",
1035 <                   get_client_name(client_p, MASK_IP), current_error);
1035 >                   get_client_name(client_p, MASK_IP), current_error);
1036      }
1037  
1038      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1039 <                         "%s had been connected for %d day%s, %2d:%02d:%02d",
1040 <                         client_p->name, connected/86400,
1041 <                         (connected/86400 == 1) ? "" : "s",
1042 <                         (connected % 86400) / 3600, (connected % 3600) / 60,
1043 <                         connected % 60);
1039 >                         "%s had been connected for %d day%s, %2d:%02d:%02d",
1040 >                         client_p->name, connected/86400,
1041 >                         (connected/86400 == 1) ? "" : "s",
1042 >                         (connected % 86400) / 3600, (connected % 3600) / 60,
1043 >                         connected % 60);
1044    }
1045  
1046    if (error == 0)
# Line 1086 | Line 1081 | exit_aborted_clients(void)
1081      else
1082        notice = "Write error: connection closed";
1083  
1084 <    exit_client(target_p, &me, notice);  
1084 >    exit_client(target_p, &me, notice);
1085      free_dlink_node(ptr);
1086    }
1087   }
# Line 1114 | Line 1109 | del_accept(struct split_nuh_item *accept
1109  
1110   struct split_nuh_item *
1111   find_accept(const char *nick, const char *user,
1112 <            const char *host, struct Client *client_p, int do_match)
1112 >            const char *host, struct Client *client_p,
1113 >            int (*cmpfunc)(const char *, const char *))
1114   {
1115    dlink_node *ptr = NULL;
1120  /* XXX We wouldn't need that if match() would return 0 on match */
1121  int (*cmpfunc)(const char *, const char *) = do_match ? match : irccmp;
1116  
1117    DLINK_FOREACH(ptr, client_p->localClient->acceptlist.head)
1118    {
# Line 1147 | Line 1141 | accept_message(struct Client *source,
1141    dlink_node *ptr = NULL;
1142  
1143    if (source == target || find_accept(source->name, source->username,
1144 <                                      source->host, target, 1))
1144 >                                      source->host, target, match))
1145      return 1;
1146  
1147    if (HasUMode(target, UMODE_SOFTCALLERID))

Diff Legend

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