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 1339 by michael, Fri Apr 6 10:22:36 2012 UTC vs.
ircd-hybrid/trunk/src/client.c (file contents), Revision 5852 by michael, Mon Apr 27 17:55:01 2015 UTC

# Line 1 | Line 1
1   /*
2 < *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 < *  client.c: Controls clients.
2 > *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (C) 2002 by the past and present ircd coders, and others.
4 > *  Copyright (c) 1997-2015 ircd-hybrid development team
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 16 | Line 15
15   *
16   *  You should have received a copy of the GNU General Public License
17   *  along with this program; if not, write to the Free Software
18 < *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
18 > *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19   *  USA
20 < *
21 < *  $Id$
20 > */
21 >
22 > /*! \file client.c
23 > * \brief Controls clients.
24 > * \version $Id$
25   */
26  
27   #include "stdinc.h"
28   #include "list.h"
29   #include "client.h"
28 #include "channel_mode.h"
30   #include "event.h"
30 #include "fdlist.h"
31   #include "hash.h"
32   #include "irc_string.h"
33   #include "ircd.h"
34 #include "s_gline.h"
34   #include "numeric.h"
35 < #include "packet.h"
37 < #include "s_auth.h"
35 > #include "auth.h"
36   #include "s_bsd.h"
37   #include "conf.h"
38   #include "log.h"
39 < #include "s_misc.h"
40 < #include "s_serv.h"
39 > #include "misc.h"
40 > #include "server.h"
41   #include "send.h"
42   #include "whowas.h"
43 < #include "s_user.h"
46 < #include "dbuf.h"
43 > #include "user.h"
44   #include "memory.h"
45 + #include "mempool.h"
46   #include "hostmask.h"
49 #include "balloc.h"
47   #include "listener.h"
51 #include "irc_res.h"
48   #include "userhost.h"
49   #include "watch.h"
50 + #include "rng_mt.h"
51 + #include "parse.h"
52 + #include "ipcache.h"
53  
55 dlink_list listing_client_list = { NULL, NULL, 0 };
56 /* Pointer to beginning of Client list */
57 dlink_list global_client_list = {NULL, NULL, 0};
58 /* unknown/client pointer lists */
59 dlink_list unknown_list = {NULL, NULL, 0};
60 dlink_list local_client_list = {NULL, NULL, 0};
61 dlink_list serv_list = {NULL, NULL, 0};
62 dlink_list global_serv_list = {NULL, NULL, 0};
63 dlink_list oper_list = {NULL, NULL, 0};
64
65 static EVH check_pings;
54  
55 < static BlockHeap *client_heap  = NULL;
56 < static BlockHeap *lclient_heap = NULL;
57 <
58 < static dlink_list dead_list  = { NULL, NULL, 0};
59 < static dlink_list abort_list = { NULL, NULL, 0};
55 > dlink_list listing_client_list;
56 > dlink_list unknown_list;
57 > dlink_list local_client_list;
58 > dlink_list local_server_list;
59 > dlink_list global_client_list;
60 > dlink_list global_server_list;
61 > dlink_list oper_list;
62  
63 + static mp_pool_t *client_pool, *connection_pool;
64 + static dlink_list dead_list, abort_list;
65   static dlink_node *eac_next;  /* next aborted client to exit */
66  
75 static void check_pings_list(dlink_list *);
76 static void check_unknowns_list(void);
77 static void ban_them(struct Client *, struct ConfItem *);
78
79
80 /* init_client()
81 *
82 * inputs       - NONE
83 * output       - NONE
84 * side effects - initialize client free memory
85 */
86 void
87 init_client(void)
88 {
89  /* start off the check ping event ..  -- adrian
90   * Every 30 seconds is plenty -- db
91   */
92  client_heap = BlockHeapCreate("client", sizeof(struct Client), CLIENT_HEAP_SIZE);
93  lclient_heap = BlockHeapCreate("local client", sizeof(struct LocalUser), LCLIENT_HEAP_SIZE);
94  eventAdd("check_pings", check_pings, NULL, 5);
95 }
67  
68   /*
69   * make_client - create a new Client struct and set it to initial state.
# Line 112 | Line 83 | init_client(void)
83   struct Client *
84   make_client(struct Client *from)
85   {
86 <  struct Client *client_p = BlockHeapAlloc(client_heap);
86 >  struct Client *const client_p = mp_pool_get(client_pool);
87  
88 <  if (from == NULL)
88 >  if (!from)
89    {
90 <    client_p->from                      = client_p; /* 'from' of local client is self! */
91 <    client_p->localClient               = BlockHeapAlloc(lclient_heap);
92 <    client_p->localClient->since        = CurrentTime;
93 <    client_p->localClient->lasttime     = CurrentTime;
94 <    client_p->localClient->firsttime    = CurrentTime;
95 <    client_p->localClient->registration = REG_INIT;
90 >    client_p->from = client_p;  /* 'from' of local client is self! */
91 >    client_p->connection = mp_pool_get(connection_pool);
92 >    client_p->connection->since = CurrentTime;
93 >    client_p->connection->lasttime = CurrentTime;
94 >    client_p->connection->firsttime = CurrentTime;
95 >    client_p->connection->registration = REG_INIT;
96  
97      /* as good a place as any... */
98 <    dlinkAdd(client_p, &client_p->localClient->lclient_node, &unknown_list);
98 >    dlinkAdd(client_p, &client_p->connection->lclient_node, &unknown_list);
99    }
100    else
101 <    client_p->from = from; /* 'from' of local client is self! */
101 >    client_p->from = from;
102  
103 <  client_p->hnext  = client_p;
104 <  client_p->status = STAT_UNKNOWN;
103 >  client_p->idhnext = client_p;
104 >  client_p->hnext = client_p;
105 >  SetUnknown(client_p);
106    strcpy(client_p->username, "unknown");
107 +  strcpy(client_p->account, "*");
108  
109    return client_p;
110   }
# Line 146 | Line 119 | make_client(struct Client *from)
119   static void
120   free_client(struct Client *client_p)
121   {
149  assert(client_p != NULL);
122    assert(client_p != &me);
123    assert(client_p->hnext == client_p);
124 +  assert(client_p->idhnext == client_p);
125    assert(client_p->channel.head == NULL);
126    assert(dlink_list_length(&client_p->channel) == 0);
127 +  assert(dlink_list_length(&client_p->whowas) == 0);
128 +  assert(dlink_list_length(&client_p->svstags) == 0);
129  
155  MyFree(client_p->away);
130    MyFree(client_p->serv);
131 +  MyFree(client_p->certfp);
132  
133    if (MyConnect(client_p))
134    {
135 <    assert(client_p->localClient->invited.head == NULL);
136 <    assert(dlink_list_length(&client_p->localClient->invited) == 0);
135 >    assert(client_p->connection->invited.head == NULL);
136 >    assert(dlink_list_length(&client_p->connection->invited) == 0);
137 >    assert(dlink_list_length(&client_p->connection->watches) == 0);
138      assert(IsClosing(client_p) && IsDead(client_p));
139  
140 <    MyFree(client_p->localClient->response);
141 <    MyFree(client_p->localClient->auth_oper);
140 >    MyFree(client_p->connection->challenge_response);
141 >    client_p->connection->challenge_response = NULL;
142 >    MyFree(client_p->connection->challenge_operator);
143 >    client_p->connection->challenge_operator = NULL;
144  
145      /*
146 <     * clean up extra sockets from P-lines which have been discarded.
146 >     * Clean up extra sockets from listen {} blocks which have been discarded.
147       */
148 <    if (client_p->localClient->listener)
148 >    if (client_p->connection->listener)
149      {
150 <      assert(0 < client_p->localClient->listener->ref_count);
151 <      if (0 == --client_p->localClient->listener->ref_count &&
174 <          !client_p->localClient->listener->active)
175 <        free_listener(client_p->localClient->listener);
150 >      listener_release(client_p->connection->listener);
151 >      client_p->connection->listener = NULL;
152      }
153  
154 <    dbuf_clear(&client_p->localClient->buf_recvq);
155 <    dbuf_clear(&client_p->localClient->buf_sendq);
154 >    dbuf_clear(&client_p->connection->buf_recvq);
155 >    dbuf_clear(&client_p->connection->buf_sendq);
156  
157 <    BlockHeapFree(lclient_heap, client_p->localClient);
157 >    mp_pool_release(client_p->connection);
158    }
159  
160 <  BlockHeapFree(client_heap, client_p);
160 >  mp_pool_release(client_p);
161   }
162  
163 < /*
164 < * check_pings - go through the local client list and check activity
165 < * kill off stuff that should die
166 < *
167 < * inputs       - NOT USED (from event)
168 < * output       - next time_t when check_pings() should be called again
193 < * side effects -
194 < *
195 < *
196 < * A PING can be sent to clients as necessary.
197 < *
198 < * Client/Server ping outs are handled.
199 < */
163 > void
164 > client_attach_svstag(struct Client *client_p, unsigned int numeric,
165 >                     const char *umodes, const char *const tag)
166 > {
167 >  struct ServicesTag *svstag = NULL;
168 >  const struct user_modes *tab = NULL;
169  
170 < /*
171 < * Addon from adrian. We used to call this after nextping seconds,
203 < * however I've changed it to run once a second. This is only for
204 < * PING timeouts, not K/etc-line checks (thanks dianora!). Having it
205 < * run once a second makes life a lot easier - when a new client connects
206 < * and they need a ping in 4 seconds, if nextping was set to 20 seconds
207 < * we end up waiting 20 seconds. This is stupid. :-)
208 < * I will optimise (hah!) check_pings() once I've finished working on
209 < * tidying up other network IO evilnesses.
210 < *     -- adrian
211 < */
170 >  if (numeric >= ERR_LAST_ERR_MSG || *umodes != '+')
171 >    return;
172  
173 < static void
174 < check_pings(void *notused)
175 < {              
176 <  check_pings_list(&local_client_list);
177 <  check_pings_list(&serv_list);
178 <  check_unknowns_list();
173 >  svstag = MyCalloc(sizeof(*svstag));
174 >  svstag->numeric = numeric;
175 >  svstag->tag = xstrdup(tag);
176 >
177 >  for (const char *m = umodes + 1; *m; ++m)
178 >    if ((tab = umode_map[(unsigned char)*m]))
179 >      svstag->umodes |= tab->flag;
180 >
181 >  if (numeric != RPL_WHOISOPERATOR)
182 >    dlinkAddTail(svstag, &svstag->node, &client_p->svstags);
183 >  else
184 >    dlinkAdd(svstag, &svstag->node, &client_p->svstags);
185 > }
186 >
187 > void
188 > client_clear_svstags(struct Client *client_p)
189 > {
190 >  dlink_node *node = NULL, *node_next = NULL;
191 >
192 >  DLINK_FOREACH_SAFE(node, node_next, client_p->svstags.head)
193 >  {
194 >    struct ServicesTag *svstag = node->data;
195 >
196 >    dlinkDelete(&svstag->node, &client_p->svstags);
197 >    MyFree(svstag->tag);
198 >    MyFree(svstag);
199 >  }
200   }
201  
202   /* check_pings_list()
203   *
204   * inputs       - pointer to list to check
205   * output       - NONE
206 < * side effects -
206 > * side effects -
207   */
208   static void
209   check_pings_list(dlink_list *list)
210   {
211 <  char scratch[32];        /* way too generous but... */
212 <  struct Client *client_p; /* current local client_p being examined */
213 <  int ping, pingwarn;      /* ping time value from client */
233 <  dlink_node *ptr, *next_ptr;
211 >  char buf[IRCD_BUFSIZE] = "";
212 >  int ping = 0;      /* ping time value from client */
213 >  dlink_node *node = NULL, *node_next = NULL;
214  
215 <  DLINK_FOREACH_SAFE(ptr, next_ptr, list->head)
215 >  DLINK_FOREACH_SAFE(node, node_next, list->head)
216    {
217 <    client_p = ptr->data;
217 >    struct Client *client_p = node->data;
218  
239    /*
240    ** Note: No need to notify opers here. It's
241    ** already done when "FLAGS_DEADSOCKET" is set.
242    */
219      if (IsDead(client_p))
220 <    {
245 <      /* Ignore it, its been exited already */
246 <      continue;
247 <    }
248 <
249 <    if (client_p->localClient->reject_delay > 0)
250 <    {
251 <      if (client_p->localClient->reject_delay <= CurrentTime)
252 <        exit_client(client_p, &me, "Rejected");
253 <      continue;
254 <    }
220 >      continue;  /* Ignore it, its been exited already */
221  
222      if (!IsRegistered(client_p))
223 <      ping = CONNECTTIMEOUT, pingwarn = 0;
223 >      ping = CONNECTTIMEOUT;
224      else
225 <      ping = get_client_ping(client_p, &pingwarn);
225 >      ping = get_client_ping(&client_p->connection->confs);
226  
227 <    if (ping < CurrentTime - client_p->localClient->lasttime)
227 >    if (ping < CurrentTime - client_p->connection->lasttime)
228      {
229        if (!IsPingSent(client_p))
230        {
231 <        /*
232 <         * if we havent PINGed the connection and we havent
233 <         * heard from it in a while, PING it to make sure
234 <         * it is still alive.
235 <         */
236 <        SetPingSent(client_p);
237 <        ClearPingWarning(client_p);
238 <        client_p->localClient->lasttime = CurrentTime - ping;
273 <        sendto_one(client_p, "PING :%s", ID_or_name(&me, client_p));
231 >        /*
232 >         * If we haven't PINGed the connection and we haven't
233 >         * heard from it in a while, PING it to make sure
234 >         * it is still alive.
235 >         */
236 >        SetPingSent(client_p);
237 >        client_p->connection->lasttime = CurrentTime - ping;
238 >        sendto_one(client_p, "PING :%s", ID_or_name(&me, client_p));
239        }
240        else
241        {
242 <        if (CurrentTime - client_p->localClient->lasttime >= 2 * ping)
242 >        if (CurrentTime - client_p->connection->lasttime >= 2 * ping)
243          {
244            /*
245             * If the client/server hasn't talked to us in 2*ping seconds
246             * and it has a ping time, then close its connection.
247             */
248            if (IsServer(client_p) || IsHandshake(client_p))
249 <          {
250 <            sendto_realops_flags(UMODE_ALL, L_ADMIN,
251 <                                 "No response from %s, closing link",
252 <                                 get_client_name(client_p, HIDE_IP));
253 <            sendto_realops_flags(UMODE_ALL, L_OPER,
254 <                                 "No response from %s, closing link",
255 <                                 get_client_name(client_p, MASK_IP));
256 <            ilog(LOG_TYPE_IRCD, "No response from %s, closing link",
257 <                 get_client_name(client_p, HIDE_IP));
258 <          }
259 <
260 <          snprintf(scratch, sizeof(scratch), "Ping timeout: %d seconds",
261 <                   (int)(CurrentTime - client_p->localClient->lasttime));
262 <          exit_client(client_p, &me, scratch);
298 <        }
299 <        else if (!IsPingWarning(client_p) && pingwarn > 0 &&
300 <                 (IsServer(client_p) || IsHandshake(client_p)) &&
301 <                 CurrentTime - client_p->localClient->lasttime >= ping + pingwarn)
302 <        {
303 <          /*
304 <           * If the server hasn't replied in pingwarn seconds after sending
305 <           * the PING, notify the opers so that they are aware of the problem.
306 <           */
307 <          SetPingWarning(client_p);
308 <          sendto_realops_flags(UMODE_ALL, L_ADMIN,
309 <                               "Warning, no response from %s in %d seconds",
310 <                               get_client_name(client_p, HIDE_IP), pingwarn);
311 <          sendto_realops_flags(UMODE_ALL, L_OPER,
312 <                               "Warning, no response from %s in %d seconds",
313 <                               get_client_name(client_p, MASK_IP), pingwarn);
314 <          ilog(LOG_TYPE_IRCD, "No response from %s in %d seconds",
315 <               get_client_name(client_p, HIDE_IP), pingwarn);
249 >          {
250 >            sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
251 >                                 "No response from %s, closing link",
252 >                                 get_client_name(client_p, HIDE_IP));
253 >            sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
254 >                                 "No response from %s, closing link",
255 >                                 get_client_name(client_p, MASK_IP));
256 >            ilog(LOG_TYPE_IRCD, "No response from %s, closing link",
257 >                 get_client_name(client_p, HIDE_IP));
258 >          }
259 >
260 >          snprintf(buf, sizeof(buf), "Ping timeout: %d seconds",
261 >                   (int)(CurrentTime - client_p->connection->lasttime));
262 >          exit_client(client_p, buf);
263          }
264        }
265      }
# Line 328 | Line 275 | check_pings_list(dlink_list *list)
275   static void
276   check_unknowns_list(void)
277   {
278 <  dlink_node *ptr, *next_ptr;
278 >  dlink_node *node = NULL, *node_next = NULL;
279  
280 <  DLINK_FOREACH_SAFE(ptr, next_ptr, unknown_list.head)
280 >  DLINK_FOREACH_SAFE(node, node_next, unknown_list.head)
281    {
282 <    struct Client *client_p = ptr->data;
336 <
337 <    if (client_p->localClient->reject_delay > 0)
338 <    {
339 <      if (client_p->localClient->reject_delay <= CurrentTime)
340 <        exit_client(client_p, &me, "Rejected");
341 <      continue;
342 <    }
282 >    struct Client *client_p = node->data;
283  
284      /*
285       * Check UNKNOWN connections - if they have been in this state
286       * for > 30s, close them.
287       */
288 <    if (IsAuthFinished(client_p) && (CurrentTime - client_p->localClient->firsttime) > 30)
289 <      exit_client(client_p, &me, "Registration timed out");
288 >    if (IsAuthFinished(client_p) && (CurrentTime - client_p->connection->firsttime) > 30)
289 >      exit_client(client_p, "Registration timed out");
290    }
291   }
292  
293 + /*
294 + * check_pings - go through the local client list and check activity
295 + * kill off stuff that should die
296 + *
297 + * inputs       - NOT USED (from event)
298 + * output       - next time_t when check_pings() should be called again
299 + * side effects -
300 + *
301 + *
302 + * A PING can be sent to clients as necessary.
303 + *
304 + * Client/Server ping outs are handled.
305 + */
306 +
307 + /*
308 + * Addon from adrian. We used to call this after nextping seconds,
309 + * however I've changed it to run once a second. This is only for
310 + * PING timeouts, not K/etc-line checks (thanks dianora!). Having it
311 + * run once a second makes life a lot easier - when a new client connects
312 + * and they need a ping in 4 seconds, if nextping was set to 20 seconds
313 + * we end up waiting 20 seconds. This is stupid. :-)
314 + * I will optimise (hah!) check_pings() once I've finished working on
315 + * tidying up other network IO evilnesses.
316 + *     -- adrian
317 + */
318 +
319 + static void
320 + check_pings(void *unused)
321 + {
322 +  check_pings_list(&local_client_list);
323 +  check_pings_list(&local_server_list);
324 +  check_unknowns_list();
325 + }
326 +
327   /* check_conf_klines()
328   *
329   * inputs       - NONE
# Line 357 | Line 331 | check_unknowns_list(void)
331   * side effects - Check all connections for a pending kline against the
332   *                client, exit the client if a kline matches.
333   */
334 < void
334 > void
335   check_conf_klines(void)
336 < {              
337 <  struct Client *client_p = NULL;       /* current local client_p being examined */
338 <  struct AccessItem *aconf = NULL;
365 <  struct ConfItem *conf = NULL;
366 <  dlink_node *ptr, *next_ptr;
336 > {
337 >  struct MaskItem *conf = NULL;
338 >  dlink_node *node = NULL, *node_next = NULL;
339  
340 <  DLINK_FOREACH_SAFE(ptr, next_ptr, local_client_list.head)
340 >  DLINK_FOREACH_SAFE(node, node_next, local_client_list.head)
341    {
342 <    client_p = ptr->data;
342 >    struct Client *client_p = node->data;
343  
344 <    /* If a client is already being exited
345 <     */
374 <    if (IsDead(client_p) || !IsClient(client_p))
344 >    /* If a client is already being exited */
345 >    if (IsDead(client_p))
346        continue;
347  
348 <    /* if there is a returned struct ConfItem then kill it */
349 <    if ((aconf = find_dline_conf(&client_p->localClient->ip,
379 <                                  client_p->localClient->aftype)) != NULL)
348 >    if ((conf = find_conf_by_address(NULL, &client_p->connection->ip, CONF_DLINE,
349 >                                     client_p->connection->aftype, NULL, NULL, 1)))
350      {
351 <      if (aconf->status & CONF_EXEMPTDLINE)
352 <        continue;
383 <
384 <      conf = unmap_conf_item(aconf);
385 <      ban_them(client_p, conf);
386 <      continue; /* and go examine next fd/client_p */
351 >      conf_try_ban(client_p, conf);
352 >      continue;  /* and go examine next Client */
353      }
354  
355 <    if (ConfigFileEntry.glines && (aconf = find_gline(client_p)))
356 <    {
357 <      if (IsExemptKline(client_p) ||
392 <          IsExemptGline(client_p))
393 <      {
394 <        sendto_realops_flags(UMODE_ALL, L_ALL,
395 <                             "GLINE over-ruled for %s, client is %sline_exempt",
396 <                             get_client_name(client_p, HIDE_IP), IsExemptKline(client_p) ? "k" : "g");
397 <        continue;
398 <      }
399 <
400 <      conf = unmap_conf_item(aconf);
401 <      ban_them(client_p, conf);
402 <      /* and go examine next fd/client_p */    
403 <      continue;
404 <    }
405 <
406 <    if ((aconf = find_kill(client_p)) != NULL)
355 >    if ((conf = find_conf_by_address(client_p->host, &client_p->connection->ip,
356 >                                     CONF_KLINE, client_p->connection->aftype,
357 >                                     client_p->username, NULL, 1)))
358      {
359 <
360 <      /* if there is a returned struct AccessItem.. then kill it */
410 <      if (IsExemptKline(client_p))
411 <      {
412 <        sendto_realops_flags(UMODE_ALL, L_ALL,
413 <                             "KLINE over-ruled for %s, client is kline_exempt",
414 <                             get_client_name(client_p, HIDE_IP));
415 <        continue;
416 <      }
417 <
418 <      conf = unmap_conf_item(aconf);
419 <      ban_them(client_p, conf);
420 <      continue;
359 >      conf_try_ban(client_p, conf);
360 >      continue;  /* and go examine next Client */
361      }
362  
363 <    /* if there is a returned struct MatchItem then kill it */
364 <    if ((conf = find_matching_name_conf(XLINE_TYPE,  client_p->info,
425 <                                        NULL, NULL, 0)) != NULL ||
426 <        (conf = find_matching_name_conf(RXLINE_TYPE, client_p->info,
427 <                                        NULL, NULL, 0)) != NULL)
363 >    if ((conf = find_matching_name_conf(CONF_XLINE, client_p->info,
364 >                                        NULL, NULL, 0)))
365      {
366 <      ban_them(client_p, conf);
367 <      continue;
366 >      conf_try_ban(client_p, conf);
367 >      continue;  /* and go examine next Client */
368      }
369    }
370  
371 <  /* also check the unknowns list for new dlines */
372 <  DLINK_FOREACH_SAFE(ptr, next_ptr, unknown_list.head)
371 >  /* Also check the unknowns list for new dlines */
372 >  DLINK_FOREACH_SAFE(node, node_next, unknown_list.head)
373    {
374 <    client_p = ptr->data;
374 >    struct Client *client_p = node->data;
375  
376 <    if ((aconf = find_dline_conf(&client_p->localClient->ip,
377 <                                  client_p->localClient->aftype)))
376 >    if ((conf = find_conf_by_address(NULL, &client_p->connection->ip, CONF_DLINE,
377 >                                     client_p->connection->aftype, NULL, NULL, 1)))
378      {
379 <      if (aconf->status & CONF_EXEMPTDLINE)
380 <        continue;
444 <
445 <      exit_client(client_p, &me, "D-lined");
379 >      conf_try_ban(client_p, conf);
380 >      continue;  /* and go examine next Client */
381      }
382    }
383   }
384  
385   /*
386 < * ban_them
386 > * conf_try_ban
387   *
388   * inputs       - pointer to client to ban
389 < *              - pointer to ConfItem
389 > *              - pointer to MaskItem
390   * output       - NONE
391   * side effects - given client_p is banned
392   */
393 < static void
394 < ban_them(struct Client *client_p, struct ConfItem *conf)
393 > void
394 > conf_try_ban(struct Client *client_p, struct MaskItem *conf)
395   {
396 <  const char *user_reason = NULL;       /* What is sent to user */
462 <  const char *channel_reason = NULL;    /* What is sent to channel */
463 <  struct AccessItem *aconf = NULL;
464 <  struct MatchItem *xconf = NULL;
396 >  const char *user_reason = NULL;  /* What is sent to user */
397    const char *type_string = NULL;
398    const char dline_string[] = "D-line";
399    const char kline_string[] = "K-line";
468  const char gline_string[] = "G-line";
400    const char xline_string[] = "X-line";
401  
402    switch (conf->type)
403    {
404 <    case RKLINE_TYPE:
405 <    case KLINE_TYPE:
404 >    case CONF_KLINE:
405 >      if (IsExemptKline(client_p))
406 >      {
407 >        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
408 >                             "KLINE over-ruled for %s, client is kline_exempt",
409 >                             get_client_name(client_p, HIDE_IP));
410 >        return;
411 >      }
412 >
413        type_string = kline_string;
476      aconf = map_to_conf(conf);
414        break;
415 <    case DLINE_TYPE:
415 >    case CONF_DLINE:
416 >      if (find_conf_by_address(NULL, &client_p->connection->ip, CONF_EXEMPT,
417 >                               client_p->connection->aftype, NULL, NULL, 1))
418 >        return;
419        type_string = dline_string;
480      aconf = map_to_conf(conf);
420        break;
421 <    case GLINE_TYPE:
483 <      type_string = gline_string;
484 <      aconf = map_to_conf(conf);
485 <      break;
486 <    case RXLINE_TYPE:
487 <    case XLINE_TYPE:
421 >    case CONF_XLINE:
422        type_string = xline_string;
423 <      xconf = map_to_conf(conf);
490 <      ++xconf->count;
423 >      ++conf->count;
424        break;
425      default:
426        assert(0);
427        break;
428    }
429  
430 <  if (ConfigFileEntry.kline_with_reason)
498 <  {
499 <    if (aconf != NULL)
500 <      user_reason = aconf->reason ? aconf->reason : type_string;
501 <    if (xconf != NULL)
502 <      user_reason = xconf->reason ? xconf->reason : type_string;
503 <  }
504 <  else
505 <    user_reason = type_string;
506 <
507 <  if (ConfigFileEntry.kline_reason != NULL)
508 <    channel_reason = ConfigFileEntry.kline_reason;
509 <  else
510 <    channel_reason = user_reason;
430 >  user_reason = conf->reason ? conf->reason : type_string;
431  
432 <  sendto_realops_flags(UMODE_ALL, L_ALL, "%s active for %s",
432 >  sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, "%s active for %s",
433                         type_string, get_client_name(client_p, HIDE_IP));
434  
435    if (IsClient(client_p))
436 <    sendto_one(client_p, form_str(ERR_YOUREBANNEDCREEP),
517 <               me.name, client_p->name, user_reason);
436 >    sendto_one_numeric(client_p, &me, ERR_YOUREBANNEDCREEP, user_reason);
437  
438 <  exit_client(client_p, &me, channel_reason);
438 >  exit_client(client_p, user_reason);
439   }
440  
441   /* update_client_exit_stats()
442   *
443   * input        - pointer to client
444   * output       - NONE
445 < * side effects -
445 > * side effects -
446   */
447   static void
448   update_client_exit_stats(struct Client *client_p)
# Line 531 | Line 450 | update_client_exit_stats(struct Client *
450    if (IsClient(client_p))
451    {
452      assert(Count.total > 0);
453 +
454      --Count.total;
455      if (HasUMode(client_p, UMODE_OPER))
456        --Count.oper;
# Line 538 | Line 458 | update_client_exit_stats(struct Client *
458        --Count.invisi;
459    }
460    else if (IsServer(client_p))
461 <    sendto_realops_flags(UMODE_EXTERNAL, L_ALL, "Server %s split from %s",
461 >    sendto_realops_flags(UMODE_EXTERNAL, L_ALL, SEND_NOTICE,
462 >                         "Server %s split from %s",
463                           client_p->name, client_p->servptr->name);
464  
465    if (splitchecking && !splitmode)
# Line 551 | Line 472 | update_client_exit_stats(struct Client *
472   * output       - return client pointer
473   * side effects - find person by (nick)name
474   */
554 /* XXX - ugly wrapper */
475   struct Client *
476 < find_person(const struct Client *client_p, const char *name)
476 > find_person(const struct Client *const source_p, const char *name)
477   {
478 <  struct Client *c2ptr;
478 >  struct Client *target_p = NULL;
479  
480    if (IsDigit(*name))
481    {
482 <    if ((c2ptr = hash_find_id(name)) != NULL)
483 <    {
564 <      /* invisible users shall not be found by UID guessing */
565 <      if (HasUMode(c2ptr, UMODE_INVISIBLE) && !IsServer(client_p))
566 <        c2ptr = NULL;
567 <    }
482 >    if (IsServer(source_p->from))
483 >      target_p = hash_find_id(name);
484    }
485    else
486 <    c2ptr = hash_find_client(name);
486 >    target_p = hash_find_client(name);
487  
488 <  return ((c2ptr != NULL && IsClient(c2ptr)) ? c2ptr : NULL);
488 >  return (target_p && IsClient(target_p)) ? target_p : NULL;
489   }
490  
491   /*
492 < * find_chasing - find the client structure for a nick name (user)
493 < *      using history mechanism if necessary. If the client is not found,
494 < *      an error message (NO SUCH NICK) is generated. If the client was found
579 < *      through the history, chasing will be 1 and otherwise 0.
492 > * find_chasing - find the client structure for a nick name (name)
493 > *      using history mechanism if necessary. If the client is not found,
494 > *      an error message (NO SUCH NICK) is generated.
495   */
496   struct Client *
497 < find_chasing(struct Client *client_p, struct Client *source_p, const char *user, int *chasing)
497 > find_chasing(struct Client *source_p, const char *name)
498   {
499 <  struct Client *who = find_person(client_p, user);
585 <
586 <  if (chasing)
587 <    *chasing = 0;
499 >  struct Client *target_p = find_person(source_p, name);
500  
501 <  if (who)
502 <    return who;
501 >  if (target_p)
502 >    return target_p;
503  
504 <  if (IsDigit(*user))
504 >  if (IsDigit(*name))
505      return NULL;
506  
507 <  if ((who = get_history(user,
508 <                        (time_t)ConfigFileEntry.kill_chase_time_limit))
509 <                         == NULL)
507 >  target_p = whowas_get_history(name, (time_t)ConfigGeneral.kill_chase_time_limit);
508 >
509 >  if (!target_p)
510    {
511 <    sendto_one(source_p, form_str(ERR_NOSUCHNICK),
600 <               me.name, source_p->name, user);
511 >    sendto_one_numeric(source_p, &me, ERR_NOSUCHNICK, name);
512      return NULL;
513    }
514  
515 <  if (chasing)
605 <    *chasing = 1;
606 <
607 <  return who;
515 >  return target_p;
516   }
517  
518   /*
# Line 616 | Line 524 | find_chasing(struct Client *client_p, st
524   *        But, this can be used to any client structure.
525   *
526   * NOTE 1:
527 < *        Watch out the allocation of "nbuf", if either source_p->name
527 > *        Watch out the allocation of "buf", if either source_p->name
528   *        or source_p->sockhost gets changed into pointers instead of
529   *        directly allocated within the structure...
530   *
531   * NOTE 2:
532   *        Function return either a pointer to the structure (source_p) or
533 < *        to internal buffer (nbuf). *NEVER* use the returned pointer
533 > *        to internal buffer (buf). *NEVER* use the returned pointer
534   *        to modify what it points!!!
535   */
536   const char *
537 < get_client_name(const struct Client *client, enum addr_mask_type type)
537 > get_client_name(const struct Client *client_p, enum addr_mask_type type)
538   {
539 <  static char nbuf[HOSTLEN * 2 + USERLEN + 5];
632 <
633 <  assert(client != NULL);
539 >  static char buf[HOSTLEN * 2 + USERLEN + 5];
540  
541 <  if (!MyConnect(client) || !irccmp(client->name, client->host))
542 <    return client->name;
541 >  if (!MyConnect(client_p))
542 >    return client_p->name;
543  
544 <  if (ConfigServerHide.hide_server_ips)
545 <    if (IsServer(client) || IsConnecting(client) || IsHandshake(client))
546 <      type = MASK_IP;
547 <
548 <  if (ConfigFileEntry.hide_spoof_ips)
643 <    if (type == SHOW_IP && IsIPSpoof(client))
544 >  if (IsServer(client_p) || IsConnecting(client_p) || IsHandshake(client_p))
545 >  {
546 >    if (!irccmp(client_p->name, client_p->host))
547 >      return client_p->name;
548 >    else if (ConfigServerHide.hide_server_ips)
549        type = MASK_IP;
550 +  }
551  
552    /* And finally, let's get the host information, ip or name */
553    switch (type)
554    {
555      case SHOW_IP:
556 <      snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]",
557 <               client->name,
558 <               client->username, client->sockhost);
556 >      snprintf(buf, sizeof(buf), "%s[%s@%s]",
557 >               client_p->name,
558 >               client_p->username, client_p->sockhost);
559        break;
560      case MASK_IP:
561 <      if (client->localClient->aftype == AF_INET)
562 <        snprintf(nbuf, sizeof(nbuf), "%s[%s@255.255.255.255]",
563 <                 client->name, client->username);
561 >      if (client_p->connection->aftype == AF_INET)
562 >        snprintf(buf, sizeof(buf), "%s[%s@255.255.255.255]",
563 >                 client_p->name, client_p->username);
564        else
565 <        snprintf(nbuf, sizeof(nbuf), "%s[%s@ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]",
566 <                 client->name, client->username);
565 >        snprintf(buf, sizeof(buf), "%s[%s@ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]",
566 >                 client_p->name, client_p->username);
567        break;
568      default:
569 <      snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]",
570 <               client->name,
571 <               client->username, client->host);
569 >      snprintf(buf, sizeof(buf), "%s[%s@%s]",
570 >               client_p->name,
571 >               client_p->username, client_p->host);
572    }
573  
574 <  return nbuf;
574 >  return buf;
575   }
576  
577   void
578   free_exited_clients(void)
579   {
580 <  dlink_node *ptr = NULL, *next = NULL;
581 <  
582 <  DLINK_FOREACH_SAFE(ptr, next, dead_list.head)
580 >  dlink_node *node = NULL, *node_next = NULL;
581 >
582 >  DLINK_FOREACH_SAFE(node, node_next, dead_list.head)
583    {
584 <    free_client(ptr->data);
585 <    dlinkDelete(ptr, &dead_list);
586 <    free_dlink_node(ptr);
584 >    free_client(node->data);
585 >    dlinkDelete(node, &dead_list);
586 >    free_dlink_node(node);
587    }
588   }
589  
# Line 688 | Line 594 | free_exited_clients(void)
594   * The only messages generated are QUITs on channels.
595   */
596   static void
597 < exit_one_client(struct Client *source_p, const char *quitmsg)
597 > exit_one_client(struct Client *source_p, const char *comment)
598   {
599 <  dlink_node *lp = NULL, *next_lp = NULL;
599 >  dlink_node *node = NULL, *node_next = NULL;
600  
601    assert(!IsMe(source_p));
602 +  assert(source_p != &me);
603  
604    if (IsClient(source_p))
605    {
606 <    if (source_p->servptr->serv != NULL)
607 <      dlinkDelete(&source_p->lnode, &source_p->servptr->serv->client_list);
606 >    dlinkDelete(&source_p->lnode, &source_p->servptr->serv->client_list);
607 >    dlinkDelete(&source_p->node, &global_client_list);
608  
609      /*
610       * If a person is on a channel, send a QUIT notice
# Line 705 | Line 612 | exit_one_client(struct Client *source_p,
612       * that the client can show the "**signoff" message).
613       * (Note: The notice is to the local clients *only*)
614       */
615 <    sendto_common_channels_local(source_p, 0, ":%s!%s@%s QUIT :%s",
615 >    sendto_common_channels_local(source_p, 0, 0, ":%s!%s@%s QUIT :%s",
616                                   source_p->name, source_p->username,
617 <                                 source_p->host, quitmsg);
711 <    DLINK_FOREACH_SAFE(lp, next_lp, source_p->channel.head)
712 <      remove_user_from_channel(lp->data);
617 >                                 source_p->host, comment);
618  
619 <    add_history(source_p, 0);
620 <    off_history(source_p);
619 >    DLINK_FOREACH_SAFE(node, node_next, source_p->channel.head)
620 >      remove_user_from_channel(node->data);
621 >
622 >    whowas_add_history(source_p, 0);
623 >    whowas_off_history(source_p);
624  
625      watch_check_hash(source_p, RPL_LOGOFF);
626  
627      if (MyConnect(source_p))
628      {
629 <      /* Clean up invitefield */
722 <      DLINK_FOREACH_SAFE(lp, next_lp, source_p->localClient->invited.head)
723 <        del_invite(lp->data, source_p);
724 <
629 >      clear_invites_client(source_p);
630        del_all_accepts(source_p);
631      }
632    }
633    else if (IsServer(source_p))
634    {
635      dlinkDelete(&source_p->lnode, &source_p->servptr->serv->server_list);
636 +    dlinkDelete(&source_p->node, &global_client_list);
637  
638 <    if ((lp = dlinkFindDelete(&global_serv_list, source_p)) != NULL)
639 <      free_dlink_node(lp);
638 >    if ((node = dlinkFindDelete(&global_server_list, source_p)))
639 >      free_dlink_node(node);
640    }
641  
642    /* Remove source_p from the client lists */
643 <  if (HasID(source_p))
643 >  if (source_p->id[0])
644      hash_del_id(source_p);
645 +
646    if (source_p->name[0])
647      hash_del_client(source_p);
648  
649    if (IsUserHostIp(source_p))
650      delete_user_host(source_p->username, source_p->host, !MyConnect(source_p));
651  
745  /* remove from global client list
746   * NOTE: source_p->node.next cannot be NULL if the client is added
747   *       to global_client_list (there is always &me at its end)
748   */
749  if (source_p != NULL && source_p->node.next != NULL)
750    dlinkDelete(&source_p->node, &global_client_list);
751
652    update_client_exit_stats(source_p);
653  
654    /* Check to see if the client isn't already on the dead list */
# Line 759 | Line 659 | exit_one_client(struct Client *source_p,
659    dlinkAdd(source_p, make_dlink_node(), &dead_list);
660   }
661  
662 < /* Recursively send QUITs and SQUITs for source_p and all its dependent clients
763 < * and servers to those servers that need them.  A server needs the client
764 < * QUITs if it can't figure them out from the SQUIT (ie pre-TS4) or if it
765 < * isn't getting the SQUIT because of @#(*&@)# hostmasking.  With TS4, once
766 < * a link gets a SQUIT, it doesn't need any QUIT/SQUITs for clients depending
767 < * on that one -orabidoo
768 < *
769 < * This is now called on each local server -adx
770 < */
771 < static void
772 < recurse_send_quits(struct Client *original_source_p, struct Client *source_p,
773 <                   struct Client *from, struct Client *to, const char *comment,
774 <                   const char *splitstr)
775 < {
776 <  dlink_node *ptr, *next;
777 <  struct Client *target_p;
778 <  int hidden = match(me.name, source_p->name); /* XXX */
779 <
780 <  assert(to != source_p);  /* should be already removed from serv_list */
781 <
782 <  /* If this server can handle quit storm (QS) removal
783 <   * of dependents, just send the SQUIT
784 <   *
785 <   * Always check *all* dependent servers if some of them are
786 <   * hidden behind fakename. If so, send out the QUITs -adx
787 <   */
788 <  if (hidden || !IsCapable(to, CAP_QS))
789 <    DLINK_FOREACH_SAFE(ptr, next, source_p->serv->client_list.head)
790 <    {
791 <      target_p = ptr->data;
792 <      sendto_one(to, ":%s QUIT :%s", target_p->name, splitstr);
793 <    }
794 <
795 <  DLINK_FOREACH_SAFE(ptr, next, source_p->serv->server_list.head)
796 <    recurse_send_quits(original_source_p, ptr->data, from, to,
797 <                       comment, splitstr);
798 <
799 <  if (!hidden && ((source_p == original_source_p && to != from) ||
800 <                  !IsCapable(to, CAP_QS)))
801 <  {
802 <    /* don't use a prefix here - we have to be 100% sure the message
803 <     * will be accepted without Unknown prefix etc.. */
804 <    sendto_one(to, "SQUIT %s :%s", ID_or_name(source_p, to), comment);
805 <  }
806 < }
807 <
808 < /*
662 > /*
663   * Remove all clients that depend on source_p; assumes all (S)QUITs have
664 < * already been sent.  we make sure to exit a server's dependent clients
665 < * and servers before the server itself; exit_one_client takes care of
664 > * already been sent.  we make sure to exit a server's dependent clients
665 > * and servers before the server itself; exit_one_client takes care of
666   * actually removing things off llists.   tweaked from +CSr31  -orabidoo
667   */
668   static void
669 < recurse_remove_clients(struct Client *source_p, const char *quitmsg)
669 > recurse_remove_clients(struct Client *source_p, const char *comment)
670   {
671 <  dlink_node *ptr, *next;
671 >  dlink_node *node = NULL, *node_next = NULL;
672  
673 <  DLINK_FOREACH_SAFE(ptr, next, source_p->serv->client_list.head)
674 <    exit_one_client(ptr->data, quitmsg);
673 >  DLINK_FOREACH_SAFE(node, node_next, source_p->serv->client_list.head)
674 >    exit_one_client(node->data, comment);
675  
676 <  DLINK_FOREACH_SAFE(ptr, next, source_p->serv->server_list.head)
676 >  DLINK_FOREACH_SAFE(node, node_next, source_p->serv->server_list.head)
677    {
678 <    recurse_remove_clients(ptr->data, quitmsg);
679 <    exit_one_client(ptr->data, quitmsg);
678 >    recurse_remove_clients(node->data, comment);
679 >    exit_one_client(node->data, comment);
680    }
681   }
682  
683   /*
830 ** Remove *everything* that depends on source_p, from all lists, and sending
831 ** all necessary QUITs and SQUITs.  source_p itself is still on the lists,
832 ** and its SQUITs have been sent except for the upstream one  -orabidoo
833 */
834 static void
835 remove_dependents(struct Client *source_p, struct Client *from,
836                  const char *comment, const char *splitstr)
837 {
838  dlink_node *ptr = NULL;
839
840  DLINK_FOREACH(ptr, serv_list.head)
841    recurse_send_quits(source_p, source_p, from, ptr->data,
842                       comment, splitstr);
843
844  recurse_remove_clients(source_p, splitstr);
845 }
846
847 /*
684   * exit_client - exit a client of any type. Generally, you can use
685   * this on any struct Client, regardless of its state.
686   *
687   * Note, you shouldn't exit remote _users_ without first doing
688   * AddFlag(x, FLAGS_KILLED) and propagating a kill or similar message.
689 + *
690   * However, it is perfectly correct to call exit_client to force a _server_
691   * quit (either local or remote one).
692   *
693 + *
694   * inputs:       - a client pointer that is going to be exited
857 *               - for servers, the second argument is a pointer to who
858 *                 is firing the server. This side won't get any generated
859 *                 messages. NEVER NULL!
695   * output:       none
696   * side effects: the client is delinked from all lists, disconnected,
697   *               and the rest of IRC network is notified of the exit.
698   *               Client memory is scheduled to be freed
699   */
700   void
701 < exit_client(struct Client *source_p, struct Client *from, const char *comment)
701 > exit_client(struct Client *source_p, const char *comment)
702   {
703 <  dlink_node *m = NULL;
703 >  dlink_node *node = NULL;
704 >
705 >  assert(!IsMe(source_p));
706 >  assert(source_p != &me);
707  
708    if (MyConnect(source_p))
709    {
# Line 877 | Line 715 | exit_client(struct Client *source_p, str
715  
716      SetClosing(source_p);
717  
718 <    if (IsIpHash(source_p))
881 <      remove_one_ip(&source_p->localClient->ip);
882 <
883 <    if (source_p->localClient->auth)
718 >    if (HasFlag(source_p, FLAGS_IPHASH))
719      {
720 <      delete_auth(source_p->localClient->auth);
721 <      source_p->localClient->auth = NULL;
720 >      DelFlag(source_p, FLAGS_IPHASH);
721 >      ipcache_remove_address(&source_p->connection->ip);
722      }
723  
724 <    /* This source_p could have status of one of STAT_UNKNOWN, STAT_CONNECTING
724 >    delete_auth(&source_p->connection->auth);
725 >
726 >    /*
727 >     * This source_p could have status of one of STAT_UNKNOWN, STAT_CONNECTING
728       * STAT_HANDSHAKE or STAT_UNKNOWN
729       * all of which are lumped together into unknown_list
730       *
# Line 896 | Line 734 | exit_client(struct Client *source_p, str
734      {
735        assert(dlinkFind(&unknown_list, source_p));
736  
737 <      dlinkDelete(&source_p->localClient->lclient_node, &unknown_list);
737 >      dlinkDelete(&source_p->connection->lclient_node, &unknown_list);
738      }
739      else if (IsClient(source_p))
740      {
741 <      time_t on_for = CurrentTime - source_p->localClient->firsttime;
741 >      time_t on_for = CurrentTime - source_p->connection->firsttime;
742 >
743        assert(Count.local > 0);
744 <      Count.local--;
744 >
745 >      --Count.local;
746  
747        if (HasUMode(source_p, UMODE_OPER))
748 <      {
749 <        if ((m = dlinkFindDelete(&oper_list, source_p)) != NULL)
910 <          free_dlink_node(m);
911 <      }
748 >        if ((node = dlinkFindDelete(&oper_list, source_p)))
749 >          free_dlink_node(node);
750  
751        assert(dlinkFind(&local_client_list, source_p));
752 <      dlinkDelete(&source_p->localClient->lclient_node, &local_client_list);
752 >      dlinkDelete(&source_p->connection->lclient_node, &local_client_list);
753  
754 <      if (source_p->localClient->list_task != NULL)
755 <        free_list_task(source_p->localClient->list_task, source_p);
754 >      if (source_p->connection->list_task)
755 >        free_list_task(source_p);
756  
757        watch_del_watch_list(source_p);
758 <      sendto_realops_flags(UMODE_CCONN, L_ALL, "Client exiting: %s (%s@%s) [%s] [%s]",
758 >      client_clear_svstags(source_p);
759 >
760 >      sendto_realops_flags(UMODE_CCONN, L_ALL, SEND_NOTICE,
761 >                           "Client exiting: %s (%s@%s) [%s] [%s]",
762                             source_p->name, source_p->username, source_p->host, comment,
763 <                           ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
764 <                           "255.255.255.255" : source_p->sockhost);
924 <      sendto_realops_flags(UMODE_CCONN_FULL, L_ALL, "CLIEXIT: %s %s %s %s 0 %s",
925 <                           source_p->name,
926 <                           source_p->username,
927 <                           source_p->host,
928 <                           ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
929 <                           "255.255.255.255" : source_p->sockhost,
930 <                           comment);
763 >                           source_p->sockhost);
764 >
765        ilog(LOG_TYPE_USER, "%s (%3u:%02u:%02u): %s!%s@%s %llu/%llu",
766 <           myctime(source_p->localClient->firsttime), (unsigned int)(on_for / 3600),
766 >           myctime(source_p->connection->firsttime), (unsigned int)(on_for / 3600),
767             (unsigned int)((on_for % 3600)/60), (unsigned int)(on_for % 60),
768             source_p->name, source_p->username, source_p->host,
769 <           source_p->localClient->send.bytes>>10,
770 <           source_p->localClient->recv.bytes>>10);
769 >           source_p->connection->send.bytes>>10,
770 >           source_p->connection->recv.bytes>>10);
771      }
772 <
939 <    /* As soon as a client is known to be a server of some sort
940 <     * it has to be put on the serv_list, or SJOIN's to this new server
941 <     * from the connect burst will not be seen.
942 <     * XXX - TBV.  This is not true. The only place where we put a server on
943 <     * serv_list is in server_estab right now after registration process.
944 <     * And only after this, a burst is sent to the remote server, i.e. we never
945 <     * send a burst to STAT_CONNECTING, or STAT_HANDSHAKE. This will need
946 <     * more investigation later on, but for now, it's not a problem after all.
947 <     */
948 <    if (IsServer(source_p) || IsConnecting(source_p) ||
949 <        IsHandshake(source_p))
772 >    else if (IsServer(source_p))
773      {
774 <      if (dlinkFind(&serv_list, source_p))
952 <      {
953 <        dlinkDelete(&source_p->localClient->lclient_node, &serv_list);
954 <        unset_chcap_usage_counts(source_p);
955 <      }
774 >      assert(Count.myserver > 0);
775  
776 <      if (IsServer(source_p))
777 <        Count.myserver--;
776 >      --Count.myserver;
777 >
778 >      assert(dlinkFind(&local_server_list, source_p));
779 >      dlinkDelete(&source_p->connection->lclient_node, &local_server_list);
780      }
781  
782      if (!IsDead(source_p))
783      {
784        if (IsServer(source_p))
785        {
786 <        /* for them, we are exiting the network */
787 <        sendto_one(source_p, ":%s SQUIT %s :%s",
788 <                   ID_or_name(from, source_p), me.name, comment);
786 >        if (!HasFlag(source_p, FLAGS_SQUIT))
787 >        {
788 >          /* for them, we are exiting the network */
789 >          sendto_one(source_p, ":%s SQUIT %s :%s",
790 >                     me.id, me.id, comment);
791 >        }
792        }
793  
794        sendto_one(source_p, "ERROR :Closing Link: %s (%s)",
795                   source_p->host, comment);
796      }
797  
974    /*
975    ** Currently only server connections can have
976    ** depending remote clients here, but it does no
977    ** harm to check for all local clients. In
978    ** future some other clients than servers might
979    ** have remotes too...
980    **
981    ** Close the Client connection first and mark it
982    ** so that no messages are attempted to send to it.
983    ** Remember it makes source_p->from == NULL.
984    */
798      close_connection(source_p);
799    }
800 +  else if (IsClient(source_p) && HasFlag(source_p->servptr, FLAGS_EOB))
801 +    sendto_realops_flags(UMODE_FARCONNECT, L_ALL, SEND_NOTICE,
802 +                         "Client exiting at %s: %s (%s@%s) [%s]",
803 +                         source_p->servptr->name, source_p->name,
804 +                         source_p->username, source_p->host, comment);
805  
806    if (IsServer(source_p))
807    {
808 <    char splitstr[HOSTLEN + HOSTLEN + 2];
808 >    char splitstr[HOSTLEN + HOSTLEN + 2] = "";
809  
810 <    /* This shouldn't ever happen */
811 <    assert(source_p->serv != NULL && source_p->servptr != NULL);
810 >    assert(source_p->serv);
811 >    assert(source_p->servptr);
812  
813      if (ConfigServerHide.hide_servers)
814        /*
815 <       * Set netsplit message to "*.net *.split" to still show
815 >       * Set netsplit message to "*.net *.split" to still show
816         * that its a split, but hide the servers splitting
817         */
818 <      strcpy(splitstr, "*.net *.split");
818 >      strlcpy(splitstr, "*.net *.split", sizeof(splitstr));
819      else
820        snprintf(splitstr, sizeof(splitstr), "%s %s",
821                 source_p->servptr->name, source_p->name);
822  
823 <    remove_dependents(source_p, from->from, comment, splitstr);
823 >    /* Send SQUIT for source_p in every direction. source_p is already off of local_server_list here */
824 >    if (!HasFlag(source_p, FLAGS_SQUIT))
825 >      sendto_server(NULL, 0, 0, "SQUIT %s :%s", source_p->id, comment);
826 >
827 >    /* Now exit the clients internally */
828 >    recurse_remove_clients(source_p, splitstr);
829  
830 <    if (source_p->servptr == &me)
830 >    if (MyConnect(source_p))
831      {
832 <      sendto_realops_flags(UMODE_ALL, L_ALL,
833 <                           "%s was connected for %d seconds.  %llu/%llu sendK/recvK.",
834 <                           source_p->name, (int)(CurrentTime - source_p->localClient->firsttime),
835 <                           source_p->localClient->send.bytes >> 10,
836 <                           source_p->localClient->recv.bytes >> 10);
837 <      ilog(LOG_TYPE_IRCD, "%s was connected for %d seconds.  %llu/%llu sendK/recvK.",
838 <           source_p->name, (int)(CurrentTime - source_p->localClient->firsttime),
839 <           source_p->localClient->send.bytes >> 10,
840 <           source_p->localClient->recv.bytes >> 10);
832 >      int connected = CurrentTime - source_p->connection->firsttime;
833 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
834 >                           "%s was connected for %d day%s, %2d:%02d:%02d. %llu/%llu sendK/recvK.",
835 >                           source_p->name, connected/86400, (connected/86400 == 1) ? "" : "s",
836 >                           (connected % 86400) / 3600, (connected % 3600) / 60, connected % 60,
837 >                           source_p->connection->send.bytes >> 10,
838 >                           source_p->connection->recv.bytes >> 10);
839 >      ilog(LOG_TYPE_IRCD, "%s was connected for %d day%s, %2d:%02d:%02d. %llu/%llu sendK/recvK.",
840 >           source_p->name, connected/86400, (connected/86400 == 1) ? "" : "s",
841 >           (connected % 86400) / 3600, (connected % 3600) / 60, connected % 60,
842 >           source_p->connection->send.bytes >> 10,
843 >           source_p->connection->recv.bytes >> 10);
844      }
845    }
846    else if (IsClient(source_p) && !HasFlag(source_p, FLAGS_KILLED))
847 <  {
848 <    sendto_server(from->from, NULL, CAP_TS6, NOCAPS,
1023 <                  ":%s QUIT :%s", ID(source_p), comment);
1024 <    sendto_server(from->from, NULL, NOCAPS, CAP_TS6,
1025 <                  ":%s QUIT :%s", source_p->name, comment);
1026 <  }
847 >    sendto_server(source_p->from, 0, 0, ":%s QUIT :%s",
848 >                  source_p->id, comment);
849  
850    /* The client *better* be off all of the lists */
851    assert(dlinkFind(&unknown_list, source_p) == NULL);
852    assert(dlinkFind(&local_client_list, source_p) == NULL);
853 <  assert(dlinkFind(&serv_list, source_p) == NULL);
853 >  assert(dlinkFind(&local_server_list, source_p) == NULL);
854    assert(dlinkFind(&oper_list, source_p) == NULL);
855  
856    exit_one_client(source_p, comment);
# Line 1041 | Line 863 | exit_client(struct Client *source_p, str
863   void
864   dead_link_on_write(struct Client *client_p, int ierrno)
865   {
866 <  dlink_node *ptr;
866 >  dlink_node *node;
867  
868    if (IsDefunct(client_p))
869      return;
870  
871 <  dbuf_clear(&client_p->localClient->buf_recvq);
872 <  dbuf_clear(&client_p->localClient->buf_sendq);
871 >  dbuf_clear(&client_p->connection->buf_recvq);
872 >  dbuf_clear(&client_p->connection->buf_sendq);
873  
874    assert(dlinkFind(&abort_list, client_p) == NULL);
875 <  ptr = make_dlink_node();
875 >  node = make_dlink_node();
876    /* don't let exit_aborted_clients() finish yet */
877 <  dlinkAddTail(client_p, ptr, &abort_list);
877 >  dlinkAddTail(client_p, node, &abort_list);
878  
879    if (eac_next == NULL)
880 <    eac_next = ptr;
880 >    eac_next = node;
881  
882    SetDead(client_p); /* You are dead my friend */
883   }
# Line 1067 | Line 889 | dead_link_on_write(struct Client *client
889   void
890   dead_link_on_read(struct Client *client_p, int error)
891   {
892 <  char errmsg[255];
892 >  char errmsg[IRCD_BUFSIZE];
893    int current_error;
894  
895    if (IsDefunct(client_p))
896      return;
897  
898 <  dbuf_clear(&client_p->localClient->buf_recvq);
899 <  dbuf_clear(&client_p->localClient->buf_sendq);
898 >  dbuf_clear(&client_p->connection->buf_recvq);
899 >  dbuf_clear(&client_p->connection->buf_sendq);
900  
901 <  current_error = get_sockerr(client_p->localClient->fd.fd);
901 >  current_error = get_sockerr(client_p->connection->fd.fd);
902  
903    if (IsServer(client_p) || IsHandshake(client_p))
904    {
905 <    int connected = CurrentTime - client_p->localClient->firsttime;
906 <      
905 >    int connected = CurrentTime - client_p->connection->firsttime;
906 >
907      if (error == 0)
908      {
909        /* Admins get the real IP */
910 <      sendto_realops_flags(UMODE_ALL, L_ADMIN,
911 <                           "Server %s closed the connection",
912 <                           get_client_name(client_p, SHOW_IP));
910 >      sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
911 >                           "Server %s closed the connection",
912 >                           get_client_name(client_p, SHOW_IP));
913  
914        /* Opers get a masked IP */
915 <      sendto_realops_flags(UMODE_ALL, L_OPER,
916 <                           "Server %s closed the connection",
917 <                           get_client_name(client_p, MASK_IP));
915 >      sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
916 >                           "Server %s closed the connection",
917 >                           get_client_name(client_p, MASK_IP));
918  
919        ilog(LOG_TYPE_IRCD, "Server %s closed the connection",
920 <           get_client_name(client_p, SHOW_IP));
920 >           get_client_name(client_p, SHOW_IP));
921      }
922      else
923      {
924        report_error(L_ADMIN, "Lost connection to %s: %s",
925 <                   get_client_name(client_p, SHOW_IP), current_error);
925 >                   get_client_name(client_p, SHOW_IP), current_error);
926        report_error(L_OPER, "Lost connection to %s: %s",
927 <                   get_client_name(client_p, MASK_IP), current_error);
927 >                   get_client_name(client_p, MASK_IP), current_error);
928      }
929  
930 <    sendto_realops_flags(UMODE_ALL, L_ALL,
931 <                         "%s had been connected for %d day%s, %2d:%02d:%02d",
932 <                         client_p->name, connected/86400,
933 <                         (connected/86400 == 1) ? "" : "s",
934 <                         (connected % 86400) / 3600, (connected % 3600) / 60,
935 <                         connected % 60);
930 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
931 >                         "%s was connected for %d day%s, %2d:%02d:%02d",
932 >                         client_p->name, connected/86400,
933 >                         (connected/86400 == 1) ? "" : "s",
934 >                         (connected % 86400) / 3600, (connected % 3600) / 60,
935 >                         connected % 60);
936    }
937  
938    if (error == 0)
# Line 1120 | Line 942 | dead_link_on_read(struct Client *client_
942      snprintf(errmsg, sizeof(errmsg), "Read error: %s",
943               strerror(current_error));
944  
945 <  exit_client(client_p, &me, errmsg);
945 >  exit_client(client_p, errmsg);
946   }
947  
948   void
# Line 1137 | Line 959 | exit_aborted_clients(void)
959  
960      if (target_p == NULL)
961      {
962 <      sendto_realops_flags(UMODE_ALL, L_ALL,
962 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
963                             "Warning: null client on abort_list!");
964        dlinkDelete(ptr, &abort_list);
965        free_dlink_node(ptr);
# Line 1151 | Line 973 | exit_aborted_clients(void)
973      else
974        notice = "Write error: connection closed";
975  
976 <    exit_client(target_p, &me, notice);  
976 >    exit_client(target_p, notice);
977      free_dlink_node(ptr);
978    }
979   }
# Line 1169 | Line 991 | exit_aborted_clients(void)
991   void
992   del_accept(struct split_nuh_item *accept_p, struct Client *client_p)
993   {
994 <  dlinkDelete(&accept_p->node, &client_p->localClient->acceptlist);
994 >  dlinkDelete(&accept_p->node, &client_p->connection->acceptlist);
995  
996    MyFree(accept_p->nickptr);
997    MyFree(accept_p->userptr);
# Line 1179 | Line 1001 | del_accept(struct split_nuh_item *accept
1001  
1002   struct split_nuh_item *
1003   find_accept(const char *nick, const char *user,
1004 <            const char *host, struct Client *client_p, int do_match)
1004 >            const char *host, struct Client *client_p,
1005 >            int (*cmpfunc)(const char *, const char *))
1006   {
1007 <  dlink_node *ptr = NULL;
1185 <  /* XXX We wouldn't need that if match() would return 0 on match */
1186 <  int (*cmpfunc)(const char *, const char *) = do_match ? match : irccmp;
1007 >  dlink_node *node = NULL;
1008  
1009 <  DLINK_FOREACH(ptr, client_p->localClient->acceptlist.head)
1009 >  DLINK_FOREACH(node, client_p->connection->acceptlist.head)
1010    {
1011 <    struct split_nuh_item *accept_p = ptr->data;
1011 >    struct split_nuh_item *accept_p = node->data;
1012  
1013 <    if (cmpfunc(accept_p->nickptr, nick) == do_match &&
1014 <        cmpfunc(accept_p->userptr, user) == do_match &&
1015 <        cmpfunc(accept_p->hostptr, host) == do_match)
1013 >    if (!cmpfunc(accept_p->nickptr, nick) &&
1014 >        !cmpfunc(accept_p->userptr, user) &&
1015 >        !cmpfunc(accept_p->hostptr, host))
1016        return accept_p;
1017    }
1018  
# Line 1209 | Line 1030 | int
1030   accept_message(struct Client *source,
1031                 struct Client *target)
1032   {
1033 <  dlink_node *ptr = NULL;
1033 >  dlink_node *node = NULL;
1034 >
1035 >  if (HasFlag(source, FLAGS_SERVICE) ||
1036 >      (HasUMode(source, UMODE_OPER) && ConfigGeneral.opers_bypass_callerid))
1037 >    return 1;
1038  
1039    if (source == target || find_accept(source->name, source->username,
1040 <                                      source->host, target, 1))
1040 >                                      source->host, target, match))
1041      return 1;
1042  
1043 <  if (HasUMode(target, UMODE_SOFTCALLERID))
1044 <    DLINK_FOREACH(ptr, target->channel.head)
1045 <      if (IsMember(source, ((struct Membership *)ptr->data)->chptr))
1043 >  if (!HasUMode(target, UMODE_CALLERID) && HasUMode(target, UMODE_SOFTCALLERID))
1044 >    DLINK_FOREACH(node, target->channel.head)
1045 >      if (IsMember(source, ((struct Membership *)node->data)->chptr))
1046          return 1;
1047  
1048    return 0;
# Line 1232 | Line 1057 | accept_message(struct Client *source,
1057   void
1058   del_all_accepts(struct Client *client_p)
1059   {
1060 <  dlink_node *ptr = NULL, *next_ptr = NULL;
1060 >  dlink_node *node = NULL, *node_next = NULL;
1061 >
1062 >  DLINK_FOREACH_SAFE(node, node_next, client_p->connection->acceptlist.head)
1063 >    del_accept(node->data, client_p);
1064 > }
1065 >
1066 > unsigned int
1067 > client_get_idle_time(const struct Client *source_p,
1068 >                     const struct Client *target_p)
1069 > {
1070 >  unsigned int idle = 0;
1071 >  unsigned int min_idle = 0;
1072 >  unsigned int max_idle = 0;
1073 >  const struct ClassItem *const class = get_class_ptr(&target_p->connection->confs);
1074 >
1075 >  if (!(class->flags & CLASS_FLAGS_FAKE_IDLE) || target_p == source_p)
1076 >    return CurrentTime - target_p->connection->last_privmsg;
1077 >
1078 >  if (HasUMode(source_p, UMODE_OPER) &&
1079 >      !(class->flags & CLASS_FLAGS_HIDE_IDLE_FROM_OPERS))
1080 >    return CurrentTime - target_p->connection->last_privmsg;
1081 >
1082 >  min_idle = class->min_idle;
1083 >  max_idle = class->max_idle;
1084 >
1085 >  if (min_idle == max_idle)
1086 >    return min_idle;
1087  
1088 <  DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->localClient->acceptlist.head)
1089 <    del_accept(ptr->data, client_p);
1088 >  if (class->flags & CLASS_FLAGS_RANDOM_IDLE)
1089 >    idle = genrand_int32();
1090 >  else
1091 >    idle = CurrentTime - target_p->connection->last_privmsg;
1092 >
1093 >  if (!max_idle)
1094 >    idle = 0;
1095 >  else
1096 >    idle %= max_idle;
1097 >
1098 >  if (idle < min_idle)
1099 >    idle = min_idle + (idle % (max_idle - min_idle));
1100 >
1101 >  return idle;
1102 > }
1103 >
1104 > /* client_init()
1105 > *
1106 > * inputs       - NONE
1107 > * output       - NONE
1108 > * side effects - initialize client free memory
1109 > */
1110 > void
1111 > client_init(void)
1112 > {
1113 >  static struct event event_ping =
1114 >  {
1115 >    .name = "check_pings",
1116 >    .handler = check_pings,
1117 >    .when = 5
1118 >  };
1119 >
1120 >  client_pool = mp_pool_new(sizeof(struct Client), MP_CHUNK_SIZE_CLIENT);
1121 >  connection_pool = mp_pool_new(sizeof(struct Connection), MP_CHUNK_SIZE_CONNECTION);
1122 >  event_add(&event_ping, NULL);
1123   }

Diff Legend

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