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-8/src/client.c (file contents), Revision 1176 by michael, Sun Aug 14 11:24:24 2011 UTC vs.
ircd-hybrid/trunk/src/client.c (file contents), Revision 2813 by michael, Sun Jan 12 20:23:50 2014 UTC

# Line 26 | Line 26
26   #include "list.h"
27   #include "client.h"
28   #include "channel_mode.h"
29 #include "common.h"
29   #include "event.h"
30   #include "fdlist.h"
31   #include "hash.h"
# Line 37 | Line 36
36   #include "packet.h"
37   #include "s_auth.h"
38   #include "s_bsd.h"
39 < #include "s_conf.h"
40 < #include "s_log.h"
39 > #include "conf.h"
40 > #include "log.h"
41   #include "s_misc.h"
42   #include "s_serv.h"
43   #include "send.h"
# Line 46 | Line 45
45   #include "s_user.h"
46   #include "dbuf.h"
47   #include "memory.h"
48 + #include "mempool.h"
49   #include "hostmask.h"
50 #include "balloc.h"
50   #include "listener.h"
51   #include "irc_res.h"
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 65 | Line 66 | dlink_list oper_list = {NULL, NULL, 0};
66  
67   static EVH check_pings;
68  
69 < static BlockHeap *client_heap  = NULL;
70 < static BlockHeap *lclient_heap = NULL;
69 > static mp_pool_t *client_pool  = NULL;
70 > static mp_pool_t *lclient_pool = NULL;
71  
72   static dlink_list dead_list  = { NULL, NULL, 0};
73   static dlink_list abort_list = { NULL, NULL, 0};
# 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 ConfItem *);
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
92     */
93 <  client_heap = BlockHeapCreate("client", sizeof(struct Client), CLIENT_HEAP_SIZE);
94 <  lclient_heap = BlockHeapCreate("local client", sizeof(struct LocalUser), LCLIENT_HEAP_SIZE);
93 >  client_pool = mp_pool_new(sizeof(struct Client), MP_CHUNK_SIZE_CLIENT);
94 >  lclient_pool = mp_pool_new(sizeof(struct LocalUser), MP_CHUNK_SIZE_LCLIENT);
95    eventAdd("check_pings", check_pings, NULL, 5);
96   }
97  
# Line 113 | Line 113 | init_client(void)
113   struct Client *
114   make_client(struct Client *from)
115   {
116 <  struct Client *client_p = BlockHeapAlloc(client_heap);
116 >  struct Client *client_p = mp_pool_get(client_pool);
117 >
118 >  memset(client_p, 0, sizeof(*client_p));
119  
120    if (from == NULL)
121    {
122 <    client_p->from  = client_p; /* 'from' of local client is self! */
123 <    client_p->since = client_p->lasttime = client_p->firsttime = CurrentTime;
122 >    client_p->from                      = client_p; /* 'from' of local client is self! */
123 >    client_p->localClient               = mp_pool_get(lclient_pool);
124 >
125 >    memset(client_p->localClient, 0, sizeof(*client_p->localClient));
126  
127 <    client_p->localClient = BlockHeapAlloc(lclient_heap);
127 >    client_p->localClient->since        = CurrentTime;
128 >    client_p->localClient->lasttime     = CurrentTime;
129 >    client_p->localClient->firsttime    = CurrentTime;
130      client_p->localClient->registration = REG_INIT;
131 +
132      /* as good a place as any... */
133      dlinkAdd(client_p, &client_p->localClient->lclient_node, &unknown_list);
134    }
135    else
136      client_p->from = from; /* 'from' of local client is self! */
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  
144    return client_p;
145   }
# Line 148 | Line 157 | free_client(struct Client *client_p)
157    assert(client_p != NULL);
158    assert(client_p != &me);
159    assert(client_p->hnext == client_p);
160 +  assert(client_p->idhnext == client_p);
161    assert(client_p->channel.head == NULL);
162    assert(dlink_list_length(&client_p->channel) == 0);
163 +  assert(dlink_list_length(&client_p->whowas) == 0);
164 +  assert(!IsServer(client_p) || (IsServer(client_p) && client_p->serv));
165  
154  MyFree(client_p->away);
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);
174      assert(IsClosing(client_p) && IsDead(client_p));
175  
176      MyFree(client_p->localClient->response);
# Line 170 | 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  
190      dbuf_clear(&client_p->localClient->buf_recvq);
191      dbuf_clear(&client_p->localClient->buf_sendq);
192  
193 <    BlockHeapFree(lclient_heap, client_p->localClient);
193 >    mp_pool_release(client_p->localClient);
194    }
195  
196 <  BlockHeapFree(client_heap, client_p);
196 >  mp_pool_release(client_p);
197   }
198  
199   /*
# Line 189 | 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 211 | 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 221 | 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... */
243 <  struct Client *client_p; /* current local client_p being examined */
244 <  int ping, pingwarn;      /* ping time value from client */
232 <  dlink_node *ptr, *next_ptr;
242 >  char scratch[IRCD_BUFSIZE];
243 >  int ping = 0;      /* ping time value from client */
244 >  dlink_node *ptr = NULL, *next_ptr = NULL;
245  
246    DLINK_FOREACH_SAFE(ptr, next_ptr, list->head)
247    {
248 <    client_p = ptr->data;
248 >    struct Client *client_p = ptr->data;
249  
250      /*
251      ** Note: No need to notify opers here. It's
# Line 242 | Line 254 | check_pings_list(dlink_list *list)
254      if (IsDead(client_p))
255      {
256        /* Ignore it, its been exited already */
245      continue;
246    }
247
248    if (client_p->localClient->reject_delay > 0)
249    {
250      if (client_p->localClient->reject_delay <= CurrentTime)
251        exit_client(client_p, &me, "Rejected");
257        continue;
258      }
259  
260      if (!IsRegistered(client_p))
261 <      ping = CONNECTTIMEOUT, pingwarn = 0;
261 >      ping = CONNECTTIMEOUT;
262      else
263 <      ping = get_client_ping(client_p, &pingwarn);
263 >      ping = get_client_ping(&client_p->localClient->confs);
264  
265 <    if (ping < CurrentTime - client_p->lasttime)
265 >    if (ping < CurrentTime - client_p->localClient->lasttime)
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 <        ClearPingWarning(client_p);
276 <        client_p->lasttime = CurrentTime - ping;
272 <        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        {
280 <        if (CurrentTime - client_p->lasttime >= 2 * ping)
280 >        if (CurrentTime - client_p->localClient->lasttime >= 2 * ping)
281          {
282            /*
283             * If the client/server hasn't talked to us in 2*ping seconds
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,
289 <                                 "No response from %s, closing link",
290 <                                 get_client_name(client_p, HIDE_IP));
291 <            sendto_realops_flags(UMODE_ALL, L_OPER,
292 <                                 "No response from %s, closing link",
293 <                                 get_client_name(client_p, MASK_IP));
294 <            ilog(L_NOTICE, "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->lasttime));
299 >                   (int)(CurrentTime - client_p->localClient->lasttime));
300            exit_client(client_p, &me, scratch);
301          }
298        else if (!IsPingWarning(client_p) && pingwarn > 0 &&
299                 (IsServer(client_p) || IsHandshake(client_p)) &&
300                 CurrentTime - client_p->lasttime >= ping + pingwarn)
301        {
302          /*
303           * If the server hasn't replied in pingwarn seconds after sending
304           * the PING, notify the opers so that they are aware of the problem.
305           */
306          SetPingWarning(client_p);
307          sendto_realops_flags(UMODE_ALL, L_ADMIN,
308                               "Warning, no response from %s in %d seconds",
309                               get_client_name(client_p, HIDE_IP), pingwarn);
310          sendto_realops_flags(UMODE_ALL, L_OPER,
311                               "Warning, no response from %s in %d seconds",
312                               get_client_name(client_p, MASK_IP), pingwarn);
313          ilog(L_NOTICE, "No response from %s in %d seconds",
314               get_client_name(client_p, HIDE_IP), pingwarn);
315        }
302        }
303      }
304    }
# Line 333 | Line 319 | check_unknowns_list(void)
319    {
320      struct Client *client_p = ptr->data;
321  
336    if (client_p->localClient->reject_delay > 0)
337    {
338      if (client_p->localClient->reject_delay <= CurrentTime)
339        exit_client(client_p, &me, "Rejected");
340      continue;
341    }
342
322      /*
323       * Check UNKNOWN connections - if they have been in this state
324       * for > 30s, close them.
325       */
326 <    if (IsAuthFinished(client_p) && (CurrentTime - client_p->firsttime) > 30)
326 >    if (IsAuthFinished(client_p) && (CurrentTime - client_p->localClient->firsttime) > 30)
327        exit_client(client_p, &me, "Registration timed out");
328    }
329   }
# Line 356 | 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 AccessItem *aconf = NULL;
364 <  struct ConfItem *conf = NULL;
342 >  struct MaskItem *conf = NULL;
343    dlink_node *ptr, *next_ptr;
344  
345    DLINK_FOREACH_SAFE(ptr, next_ptr, local_client_list.head)
# Line 373 | Line 351 | check_conf_klines(void)
351      if (IsDead(client_p) || !IsClient(client_p))
352        continue;
353  
354 <    /* if there is a returned struct ConfItem then kill it */
377 <    if ((aconf = find_dline_conf(&client_p->localClient->ip,
354 >    if ((conf = find_dline_conf(&client_p->localClient->ip,
355                                    client_p->localClient->aftype)) != NULL)
356      {
357 <      if (aconf->status & CONF_EXEMPTDLINE)
358 <        continue;
357 >      if (conf->type == CONF_EXEMPT)
358 >        continue;
359  
360 <      conf = unmap_conf_item(aconf);
384 <      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 && (aconf = 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,
371 <                             "GLINE over-ruled for %s, client is %sline_exempt",
395 <                             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 <      conf = unmap_conf_item(aconf);
377 <      ban_them(client_p, conf);
378 <      /* and go examine next fd/client_p */    
402 <      continue;
403 <    }
404 <
405 <    if ((aconf = 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 <
381 <      /* if there is a returned struct AccessItem.. then kill it */
409 <      if (IsExemptKline(client_p))
410 <      {
411 <        sendto_realops_flags(UMODE_ALL, L_ALL,
412 <                             "KLINE over-ruled for %s, client is kline_exempt",
413 <                             get_client_name(client_p, HIDE_IP));
414 <        continue;
415 <      }
416 <
417 <      conf = unmap_conf_item(aconf);
418 <      ban_them(client_p, conf);
419 <      continue;
380 >      conf_try_ban(client_p, conf);
381 >      continue;
382      }
383  
384 <    /* if there is a returned struct MatchItem then kill it */
385 <    if ((conf = find_matching_name_conf(XLINE_TYPE,  client_p->info,
424 <                                        NULL, NULL, 0)) != NULL ||
425 <        (conf = find_matching_name_conf(RXLINE_TYPE, client_p->info,
426 <                                        NULL, NULL, 0)) != NULL)
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 435 | Line 394 | check_conf_klines(void)
394    {
395      client_p = ptr->data;
396  
397 <    if ((aconf = find_dline_conf(&client_p->localClient->ip,
398 <                                  client_p->localClient->aftype)))
397 >    if ((conf = find_dline_conf(&client_p->localClient->ip,
398 >                                 client_p->localClient->aftype)))
399      {
400 <      if (aconf->status & CONF_EXEMPTDLINE)
400 >      if (conf->type == CONF_EXEMPT)
401          continue;
402  
403        exit_client(client_p, &me, "D-lined");
# Line 447 | 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 ConfItem
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 ConfItem *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 */
461 <  const char *channel_reason = NULL;    /* What is sent to channel */
462 <  struct AccessItem *aconf = NULL;
463 <  struct MatchItem *xconf = NULL;
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 469 | Line 425 | ban_them(struct Client *client_p, struct
425  
426    switch (conf->type)
427    {
428 <    case RKLINE_TYPE:
429 <    case KLINE_TYPE:
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;
475      aconf = map_to_conf(conf);
438        break;
439 <    case DLINE_TYPE:
439 >    case CONF_DLINE:
440        type_string = dline_string;
479      aconf = map_to_conf(conf);
441        break;
442 <    case GLINE_TYPE:
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;
483      aconf = map_to_conf(conf);
453        break;
454 <    case RXLINE_TYPE:
486 <    case XLINE_TYPE:
454 >    case CONF_XLINE:
455        type_string = xline_string;
456 <      xconf = map_to_conf(conf);
489 <      ++xconf->count;
456 >      ++conf->count;
457        break;
458      default:
459        assert(0);
460        break;
461    }
462  
463 <  if (ConfigFileEntry.kline_with_reason)
497 <  {
498 <    if (aconf != NULL)
499 <      user_reason = aconf->reason ? aconf->reason : type_string;
500 <    if (xconf != NULL)
501 <      user_reason = xconf->reason ? xconf->reason : type_string;
502 <  }
503 <  else
504 <    user_reason = type_string;
505 <
506 <  if (ConfigFileEntry.kline_reason != NULL)
507 <    channel_reason = ConfigFileEntry.kline_reason;
508 <  else
509 <    channel_reason = user_reason;
463 >  user_reason = conf->reason ? conf->reason : type_string;
464  
465 <  sendto_realops_flags(UMODE_ALL, L_ALL, "%s active for %s",
465 >  sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, "%s active for %s",
466                         type_string, get_client_name(client_p, HIDE_IP));
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, channel_reason);
472 >  exit_client(client_p, &me, user_reason);
473   }
474  
475   /* update_client_exit_stats()
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 531 | Line 485 | update_client_exit_stats(struct Client *
485    {
486      assert(Count.total > 0);
487      --Count.total;
488 <    if (IsOper(client_p))
488 >    if (HasUMode(client_p, UMODE_OPER))
489        --Count.oper;
490 <    if (IsInvisible(client_p))
490 >    if (HasUMode(client_p, UMODE_INVISIBLE))
491        --Count.invisi;
492    }
493    else if (IsServer(client_p))
494 <    sendto_realops_flags(UMODE_EXTERNAL, L_ALL, "Server %s split from %s",
494 >    sendto_realops_flags(UMODE_EXTERNAL, L_ALL, SEND_NOTICE,
495 >                         "Server %s split from %s",
496                           client_p->name, client_p->servptr->name);
497  
498    if (splitchecking && !splitmode)
# Line 550 | Line 505 | update_client_exit_stats(struct Client *
505   * output       - return client pointer
506   * side effects - find person by (nick)name
507   */
553 /* XXX - ugly wrapper */
508   struct Client *
509   find_person(const struct Client *client_p, const char *name)
510   {
511 <  struct Client *c2ptr;
511 >  struct Client *target_p = NULL;
512  
513    if (IsDigit(*name))
514    {
515 <    if ((c2ptr = hash_find_id(name)) != NULL)
516 <    {
563 <      /* invisible users shall not be found by UID guessing */
564 <      if (IsInvisible(c2ptr) && !IsServer(client_p))
565 <        c2ptr = NULL;
566 <    }
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 588 | 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 625 | Line 575 | find_chasing(struct Client *client_p, st
575   *        to modify what it points!!!
576   */
577   const char *
578 < get_client_name(const struct Client *client, int showip)
578 > get_client_name(const struct Client *client, enum addr_mask_type type)
579   {
580    static char nbuf[HOSTLEN * 2 + USERLEN + 5];
581  
582    assert(client != NULL);
583  
584 <  if (irccmp(client->name, client->host) == 0)
584 >  if (!MyConnect(client))
585      return client->name;
586  
587 <  if (ConfigServerHide.hide_server_ips)
588 <    if (IsServer(client) || IsConnecting(client) || IsHandshake(client))
589 <      showip = MASK_IP;
587 >  if (IsServer(client) || IsConnecting(client) || IsHandshake(client))
588 >  {
589 >    if (!irccmp(client->name, client->host))
590 >      return client->name;
591 >    else if (ConfigServerHide.hide_server_ips)
592 >      type = MASK_IP;
593 >  }
594  
595    if (ConfigFileEntry.hide_spoof_ips)
596 <    if (showip == SHOW_IP && IsIPSpoof(client))
597 <      showip = MASK_IP;
596 >    if (type == SHOW_IP && IsIPSpoof(client))
597 >      type = MASK_IP;
598  
599    /* And finally, let's get the host information, ip or name */
600 <  switch (showip)
600 >  switch (type)
601    {
602      case SHOW_IP:
603 <      if (MyConnect(client))
604 <      {
605 <        snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]",
606 <                 client->name,
653 <                 client->username, client->sockhost);
654 <        break;
655 <      }
603 >      snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]",
604 >               client->name,
605 >               client->username, client->sockhost);
606 >      break;
607      case MASK_IP:
608 <      snprintf(nbuf, sizeof(nbuf), "%s[%s@255.255.255.255]",
609 <               client->name, client->username);
608 >      if (client->localClient->aftype == AF_INET)
609 >        snprintf(nbuf, sizeof(nbuf), "%s[%s@255.255.255.255]",
610 >                 client->name, client->username);
611 >      else
612 >        snprintf(nbuf, sizeof(nbuf), "%s[%s@ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]",
613 >                 client->name, client->username);
614        break;
615      default:
616        snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]",
# Line 670 | 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 703 | Line 658 | exit_one_client(struct Client *source_p,
658       * that the client can show the "**signoff" message).
659       * (Note: The notice is to the local clients *only*)
660       */
661 <    sendto_common_channels_local(source_p, 0, ":%s!%s@%s QUIT :%s",
661 >    sendto_common_channels_local(source_p, 0, 0, ":%s!%s@%s QUIT :%s",
662                                   source_p->name, source_p->username,
663                                   source_p->host, quitmsg);
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 773 | Line 728 | recurse_send_quits(struct Client *origin
728   {
729    dlink_node *ptr, *next;
730    struct Client *target_p;
776  int hidden = match(me.name, source_p->name); /* XXX */
731  
732    assert(to != source_p);  /* should be already removed from serv_list */
733  
734    /* If this server can handle quit storm (QS) removal
735     * of dependents, just send the SQUIT
782   *
783   * Always check *all* dependent servers if some of them are
784   * hidden behind fakename. If so, send out the QUITs -adx
736     */
737 <  if (hidden || !IsCapable(to, CAP_QS))
737 >  if (!IsCapable(to, CAP_QS))
738      DLINK_FOREACH_SAFE(ptr, next, source_p->serv->client_list.head)
739      {
740        target_p = ptr->data;
# Line 794 | Line 745 | recurse_send_quits(struct Client *origin
745      recurse_send_quits(original_source_p, ptr->data, from, to,
746                         comment, splitstr);
747  
748 <  if (!hidden && ((source_p == original_source_p && to != from) ||
749 <                  !IsCapable(to, CAP_QS)))
748 >  if ((source_p == original_source_p && to != from) ||
749 >                  !IsCapable(to, CAP_QS))
750    {
751      /* don't use a prefix here - we have to be 100% sure the message
752       * will be accepted without Unknown prefix etc.. */
# Line 803 | 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 847 | Line 798 | remove_dependents(struct Client *source_
798   * this on any struct Client, regardless of its state.
799   *
800   * Note, you shouldn't exit remote _users_ without first doing
801 < * SetKilled and propagating a kill or similar message. However,
802 < * it is perfectly correct to call exit_client to force a _server_
801 > * AddFlag(x, FLAGS_KILLED) and propagating a kill or similar message.
802 > * However, it is perfectly correct to call exit_client to force a _server_
803   * quit (either local or remote one).
804   *
805   * inputs:       - a client pointer that is going to be exited
# Line 878 | Line 829 | exit_client(struct Client *source_p, str
829      if (IsIpHash(source_p))
830        remove_one_ip(&source_p->localClient->ip);
831  
832 <    if (source_p->localClient->auth)
882 <    {
883 <      delete_auth(source_p->localClient->auth);
884 <      source_p->localClient->auth = NULL;
885 <    }
832 >    delete_auth(&source_p->localClient->auth);
833  
834 <    /* This source_p could have status of one of STAT_UNKNOWN, STAT_CONNECTING
834 >    /*
835 >     * This source_p could have status of one of STAT_UNKNOWN, STAT_CONNECTING
836       * STAT_HANDSHAKE or STAT_UNKNOWN
837       * all of which are lumped together into unknown_list
838       *
# Line 898 | Line 846 | exit_client(struct Client *source_p, str
846      }
847      else if (IsClient(source_p))
848      {
849 +      time_t on_for = CurrentTime - source_p->localClient->firsttime;
850        assert(Count.local > 0);
851        Count.local--;
852  
853 <      if (IsOper(source_p))
905 <      {
853 >      if (HasUMode(source_p, UMODE_OPER))
854          if ((m = dlinkFindDelete(&oper_list, source_p)) != NULL)
855            free_dlink_node(m);
908      }
856  
857        assert(dlinkFind(&local_client_list, source_p));
858        dlinkDelete(&source_p->localClient->lclient_node, &local_client_list);
# Line 914 | Line 861 | exit_client(struct Client *source_p, str
861          free_list_task(source_p->localClient->list_task, source_p);
862  
863        watch_del_watch_list(source_p);
864 <      sendto_realops_flags(UMODE_CCONN, L_ALL, "Client exiting: %s (%s@%s) [%s] [%s]",
864 >      sendto_realops_flags(UMODE_CCONN, L_ALL, SEND_NOTICE,
865 >                           "Client exiting: %s (%s@%s) [%s] [%s]",
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);
869 <      sendto_realops_flags(UMODE_CCONN_FULL, L_ALL, "CLIEXIT: %s %s %s %s 0 %s",
870 <                           source_p->name,
871 <                           source_p->username,
872 <                           source_p->host,
873 <
874 <                           ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
875 <                           "255.255.255.255" : source_p->sockhost,
876 <                           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),
872 >           source_p->name, source_p->username, source_p->host,
873 >           source_p->localClient->send.bytes>>10,
874 >           source_p->localClient->recv.bytes>>10);
875 >    }
876 >    else if (IsServer(source_p))
877 >    {
878 >      assert(Count.myserver > 0);
879 >      --Count.myserver;
880 >
881 >      assert(dlinkFind(&serv_list, source_p));
882 >      dlinkDelete(&source_p->localClient->lclient_node, &serv_list);
883 >      unset_chcap_usage_counts(source_p);
884      }
885  
931    /* As soon as a client is known to be a server of some sort
932     * it has to be put on the serv_list, or SJOIN's to this new server
933     * from the connect burst will not be seen.
934     */
935    if (IsServer(source_p) || IsConnecting(source_p) ||
936        IsHandshake(source_p))
937    {
938      if ((m = dlinkFindDelete(&serv_list, source_p)) != NULL)
939      {
940        free_dlink_node(m);
941        unset_chcap_usage_counts(source_p);
942      }
943
944      if (IsServer(source_p))
945        Count.myserver--;
946    }
947
948    log_user_exit(source_p);
949
886      if (!IsDead(source_p))
887      {
888        if (IsServer(source_p))
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 973 | Line 909 | exit_client(struct Client *source_p, str
909      */
910      close_connection(source_p);
911    }
912 +  else if (IsClient(source_p) && HasFlag(source_p->servptr, FLAGS_EOB))
913 +    sendto_realops_flags(UMODE_FARCONNECT, L_ALL, SEND_NOTICE,
914 +                         "Client exiting at %s: %s (%s@%s) [%s]",
915 +                         source_p->servptr->name, source_p->name,
916 +                         source_p->username, source_p->host, comment);
917  
918    if (IsServer(source_p))
919    {
# Line 983 | 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 995 | Line 936 | exit_client(struct Client *source_p, str
936  
937      if (source_p->servptr == &me)
938      {
939 <      sendto_realops_flags(UMODE_ALL, L_ALL,
939 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
940                             "%s was connected for %d seconds.  %llu/%llu sendK/recvK.",
941 <                           source_p->name, (int)(CurrentTime - source_p->firsttime),
941 >                           source_p->name, (int)(CurrentTime - source_p->localClient->firsttime),
942                             source_p->localClient->send.bytes >> 10,
943                             source_p->localClient->recv.bytes >> 10);
944 <      ilog(L_NOTICE, "%s was connected for %d seconds.  %llu/%llu sendK/recvK.",
945 <           source_p->name, (int)(CurrentTime - source_p->firsttime),
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),
946             source_p->localClient->send.bytes >> 10,
947             source_p->localClient->recv.bytes >> 10);
948      }
949    }
950 <  else if (IsClient(source_p) && !IsKilled(source_p))
950 >  else if (IsClient(source_p) && !HasFlag(source_p, FLAGS_KILLED))
951    {
952 <    sendto_server(from->from, NULL, CAP_TS6, NOCAPS,
952 >    sendto_server(from->from, CAP_TS6, NOCAPS,
953                    ":%s QUIT :%s", ID(source_p), comment);
954 <    sendto_server(from->from, NULL, NOCAPS, CAP_TS6,
954 >    sendto_server(from->from, NOCAPS, CAP_TS6,
955                    ":%s QUIT :%s", source_p->name, comment);
956    }
957  
# Line 1056 | 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 1069 | Line 1010 | dead_link_on_read(struct Client *client_
1010  
1011    if (IsServer(client_p) || IsHandshake(client_p))
1012    {
1013 <    int connected = CurrentTime - client_p->firsttime;
1014 <      
1013 >    int connected = CurrentTime - client_p->localClient->firsttime;
1014 >
1015      if (error == 0)
1016      {
1017        /* Admins get the real IP */
1018 <      sendto_realops_flags(UMODE_ALL, L_ADMIN,
1019 <                           "Server %s closed the connection",
1020 <                           get_client_name(client_p, SHOW_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));
1021  
1022        /* Opers get a masked IP */
1023 <      sendto_realops_flags(UMODE_ALL, L_OPER,
1024 <                           "Server %s closed the connection",
1025 <                           get_client_name(client_p, MASK_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));
1026  
1027 <      ilog(L_NOTICE, "Server %s closed the connection",
1028 <           get_client_name(client_p, SHOW_IP));
1027 >      ilog(LOG_TYPE_IRCD, "Server %s closed the connection",
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,
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);
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);
1044    }
1045  
1046    if (error == 0)
# Line 1126 | Line 1067 | exit_aborted_clients(void)
1067  
1068      if (target_p == NULL)
1069      {
1070 <      sendto_realops_flags(UMODE_ALL, L_ALL,
1070 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1071                             "Warning: null client on abort_list!");
1072        dlinkDelete(ptr, &abort_list);
1073        free_dlink_node(ptr);
# Line 1140 | 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 1168 | 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;
1174  /* XXX We wouldn't need that if match() would return 0 on match */
1175  int (*cmpfunc)(const char *, const char *) = do_match ? match : irccmp;
1116  
1117    DLINK_FOREACH(ptr, client_p->localClient->acceptlist.head)
1118    {
1119      struct split_nuh_item *accept_p = ptr->data;
1120  
1121 <    if (cmpfunc(accept_p->nickptr, nick) == do_match &&
1122 <        cmpfunc(accept_p->userptr, user) == do_match &&
1123 <        cmpfunc(accept_p->hostptr, host) == do_match)
1121 >    if (!cmpfunc(accept_p->nickptr, nick) &&
1122 >        !cmpfunc(accept_p->userptr, user) &&
1123 >        !cmpfunc(accept_p->hostptr, host))
1124        return accept_p;
1125    }
1126  
# Line 1201 | 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 (IsSoftCallerId(target))
1147 >  if (HasUMode(target, UMODE_SOFTCALLERID))
1148      DLINK_FOREACH(ptr, target->channel.head)
1149        if (IsMember(source, ((struct Membership *)ptr->data)->chptr))
1150          return 1;
# Line 1227 | Line 1167 | del_all_accepts(struct Client *client_p)
1167      del_accept(ptr->data, client_p);
1168   }
1169  
1170 < /* change_local_nick()
1171 < *
1232 < * inputs       - pointer to server
1233 < *              - pointer to client
1234 < *              - nick
1235 < * output       -
1236 < * side effects - changes nick of a LOCAL user
1237 < */
1238 < void
1239 < change_local_nick(struct Client *client_p, struct Client *source_p, const char *nick)
1170 > unsigned int
1171 > idle_time_get(const struct Client *source_p, const struct Client *target_p)
1172   {
1173 <  int samenick = 0;
1174 <
1175 <  assert(source_p->name[0] && !EmptyString(nick));
1176 <
1177 <  /*
1178 <   * Client just changing his/her nick. If he/she is
1179 <   * on a channel, send note of change to all clients
1180 <   * on that channel. Propagate notice to other servers.
1181 <   */
1182 <  if ((source_p->localClient->last_nick_change +
1251 <       ConfigFileEntry.max_nick_time) < CurrentTime)
1252 <    source_p->localClient->number_of_nick_changes = 0;
1253 <  source_p->localClient->last_nick_change = CurrentTime;
1254 <  source_p->localClient->number_of_nick_changes++;
1255 <
1256 <  if ((ConfigFileEntry.anti_nick_flood &&
1257 <      (source_p->localClient->number_of_nick_changes
1258 <       <= ConfigFileEntry.max_nick_changes)) ||
1259 <     !ConfigFileEntry.anti_nick_flood ||
1260 <     (IsOper(source_p) && ConfigFileEntry.no_oper_flood))
1261 <  {
1262 <    samenick = !irccmp(source_p->name, nick);
1173 >  unsigned int idle = 0;
1174 >  unsigned int min_idle = 0;
1175 >  unsigned int max_idle = 0;
1176 >  const struct ClassItem *class = get_class_ptr(&target_p->localClient->confs);
1177 >
1178 >  if (!(class->flags & CLASS_FLAGS_FAKE_IDLE) || target_p == source_p)
1179 >    return CurrentTime - target_p->localClient->last_privmsg;
1180 >  if (HasUMode(source_p, UMODE_OPER) &&
1181 >      !(class->flags & CLASS_FLAGS_HIDE_IDLE_FROM_OPERS))
1182 >    return CurrentTime - target_p->localClient->last_privmsg;
1183  
1184 <    if (!samenick)
1185 <    {
1266 <      source_p->tsinfo = CurrentTime;
1267 <      clear_ban_cache_client(source_p);
1268 <      watch_check_hash(source_p, RPL_LOGOFF);
1184 >  min_idle = class->min_idle;
1185 >  max_idle = class->max_idle;
1186  
1187 <      if (HasUMode(source_p, UMODE_REGISTERED))
1188 <      {
1272 <        unsigned int oldmodes = source_p->umodes;
1273 <        char modebuf[IRCD_BUFSIZE] = { '\0' };
1187 >  if (min_idle == max_idle)
1188 >    return min_idle;
1189  
1190 <        DelUMode(source_p, UMODE_REGISTERED);
1191 <        send_umode(source_p, source_p, oldmodes, 0xffffffff, modebuf);
1192 <      }
1193 <    }
1279 <
1280 <    /* XXX - the format of this notice should eventually be changed
1281 <     * to either %s[%s@%s], or even better would be get_client_name() -bill
1282 <     */
1283 <    sendto_realops_flags(UMODE_NCHANGE, L_ALL, "Nick change: From %s to %s [%s@%s]",
1284 <                         source_p->name, nick, source_p->username, source_p->host);
1285 <    sendto_common_channels_local(source_p, 1, ":%s!%s@%s NICK :%s",
1286 <                                 source_p->name, source_p->username,
1287 <                                 source_p->host, nick);
1288 <    add_history(source_p, 1);
1289 <
1290 <    sendto_server(client_p, NULL, CAP_TS6, NOCAPS,
1291 <                  ":%s NICK %s :%lu",
1292 <                  ID(source_p), nick, (unsigned long)source_p->tsinfo);
1293 <    sendto_server(client_p, NULL, NOCAPS, CAP_TS6,
1294 <                  ":%s NICK %s :%lu",
1295 <                  source_p->name, nick, (unsigned long)source_p->tsinfo);
1190 >  if (class->flags & CLASS_FLAGS_RANDOM_IDLE)
1191 >    idle = genrand_int32();
1192 >  else
1193 >    idle = CurrentTime - target_p->localClient->last_privmsg;
1194  
1195 <    hash_del_client(source_p);
1196 <    strcpy(source_p->name, nick);
1197 <    hash_add_client(source_p);
1195 >  if (max_idle == 0)
1196 >    idle = 0;
1197 >  else
1198 >    idle %= max_idle;
1199  
1200 <    if (!samenick)
1201 <      watch_check_hash(source_p, RPL_LOGON);
1200 >  if (idle < min_idle)
1201 >    idle = min_idle + (idle % (max_idle - min_idle));
1202  
1203 <    /* fd_desc is long enough */
1305 <    fd_note(&client_p->localClient->fd, "Nick: %s", nick);
1306 <  }
1307 <  else
1308 <    sendto_one(source_p, form_str(ERR_NICKTOOFAST),
1309 <               me.name, source_p->name, source_p->name,
1310 <               nick, ConfigFileEntry.max_nick_time);
1203 >  return idle;
1204   }

Diff Legend

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