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 1158 by michael, Wed Aug 10 19:46:00 2011 UTC vs.
ircd-hybrid/trunk/src/client.c (file contents), Revision 5551 by michael, Thu Feb 12 21:43:47 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"
29 #include "common.h"
30   #include "event.h"
31 #include "fdlist.h"
31   #include "hash.h"
32   #include "irc_string.h"
33   #include "ircd.h"
35 #include "s_gline.h"
34   #include "numeric.h"
35 < #include "packet.h"
38 < #include "s_auth.h"
35 > #include "auth.h"
36   #include "s_bsd.h"
37 < #include "s_conf.h"
38 < #include "s_log.h"
39 < #include "s_misc.h"
40 < #include "s_serv.h"
37 > #include "conf.h"
38 > #include "log.h"
39 > #include "misc.h"
40 > #include "server.h"
41   #include "send.h"
42   #include "whowas.h"
43 < #include "s_user.h"
47 < #include "dbuf.h"
43 > #include "user.h"
44   #include "memory.h"
45 + #include "mempool.h"
46   #include "hostmask.h"
50 #include "balloc.h"
47   #include "listener.h"
52 #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  
56 dlink_list listing_client_list = { NULL, NULL, 0 };
57 /* Pointer to beginning of Client list */
58 dlink_list global_client_list = {NULL, NULL, 0};
59 /* unknown/client pointer lists */
60 dlink_list unknown_list = {NULL, NULL, 0};
61 dlink_list local_client_list = {NULL, NULL, 0};
62 dlink_list serv_list = {NULL, NULL, 0};
63 dlink_list global_serv_list = {NULL, NULL, 0};
64 dlink_list oper_list = {NULL, NULL, 0};
65
66 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  
76 static void check_pings_list(dlink_list *);
77 static void check_unknowns_list(void);
78 static void ban_them(struct Client *, struct ConfItem *);
79
80
81 /* init_client()
82 *
83 * inputs       - NONE
84 * output       - NONE
85 * side effects - initialize client free memory
86 */
87 void
88 init_client(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);
95  eventAdd("check_pings", check_pings, NULL, 5);
96 }
67  
68   /*
69   * make_client - create a new Client struct and set it to initial state.
# Line 113 | 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->since = client_p->lasttime = client_p->firsttime = CurrentTime;
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  
123    client_p->localClient = BlockHeapAlloc(lclient_heap);
124    client_p->localClient->registration = REG_INIT;
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, "0");
108  
109    return client_p;
110   }
# Line 145 | Line 119 | make_client(struct Client *from)
119   static void
120   free_client(struct Client *client_p)
121   {
148  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(!IsServer(client_p) || client_p->serv);
129  
154  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 &&
173 <          !client_p->localClient->listener->active)
174 <        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 < *
190 < * inputs       - NOT USED (from event)
191 < * output       - next time_t when check_pings() should be called again
192 < * side effects -
193 < *
194 < *
195 < * A PING can be sent to clients as necessary.
196 < *
197 < * Client/Server ping outs are handled.
198 < */
163 > void
164 > client_clear_svstags(struct Client *client_p)
165 > {
166 >  dlink_node *node = NULL, *node_next = NULL;
167  
168 < /*
169 < * Addon from adrian. We used to call this after nextping seconds,
170 < * however I've changed it to run once a second. This is only for
203 < * PING timeouts, not K/etc-line checks (thanks dianora!). Having it
204 < * run once a second makes life a lot easier - when a new client connects
205 < * and they need a ping in 4 seconds, if nextping was set to 20 seconds
206 < * we end up waiting 20 seconds. This is stupid. :-)
207 < * I will optimise (hah!) check_pings() once I've finished working on
208 < * tidying up other network IO evilnesses.
209 < *     -- adrian
210 < */
168 >  DLINK_FOREACH_SAFE(node, node_next, client_p->svstags.head)
169 >  {
170 >    struct ServicesTag *svstag = node->data;
171  
172 < static void
173 < check_pings(void *notused)
174 < {              
175 <  check_pings_list(&local_client_list);
216 <  check_pings_list(&serv_list);
217 <  check_unknowns_list();
172 >    dlinkDelete(&svstag->node, &client_p->svstags);
173 >    MyFree(svstag->tag);
174 >    MyFree(svstag);
175 >  }
176   }
177  
178   /* check_pings_list()
179   *
180   * inputs       - pointer to list to check
181   * output       - NONE
182 < * side effects -
182 > * side effects -
183   */
184   static void
185   check_pings_list(dlink_list *list)
186   {
187 <  char scratch[32];        /* way too generous but... */
188 <  struct Client *client_p; /* current local client_p being examined */
189 <  int ping, pingwarn;      /* ping time value from client */
232 <  dlink_node *ptr, *next_ptr;
187 >  char buf[IRCD_BUFSIZE] = "";
188 >  int ping = 0;      /* ping time value from client */
189 >  dlink_node *node = NULL, *node_next = NULL;
190  
191 <  DLINK_FOREACH_SAFE(ptr, next_ptr, list->head)
191 >  DLINK_FOREACH_SAFE(node, node_next, list->head)
192    {
193 <    client_p = ptr->data;
193 >    struct Client *client_p = node->data;
194  
238    /*
239    ** Note: No need to notify opers here. It's
240    ** already done when "FLAGS_DEADSOCKET" is set.
241    */
195      if (IsDead(client_p))
196 <    {
244 <      /* 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");
252 <      continue;
253 <    }
254 <
255 <    if (GlobalSetOptions.idletime && IsClient(client_p))
256 <    {
257 <      if (!IsExemptKline(client_p) && !IsOper(client_p) &&
258 <          !IsIdlelined(client_p) &&
259 <          ((CurrentTime - client_p->localClient->last) > GlobalSetOptions.idletime))
260 <      {
261 <        struct ConfItem *conf;
262 <        struct AccessItem *aconf;
263 <
264 <        conf = make_conf_item(KLINE_TYPE);
265 <        aconf = map_to_conf(conf);
266 <
267 <        DupString(aconf->host, client_p->host);
268 <        DupString(aconf->reason, "idle exceeder");
269 <        DupString(aconf->user, client_p->username);
270 <        aconf->hold = CurrentTime + 60;
271 <        add_temp_line(conf);
272 <
273 <        sendto_realops_flags(UMODE_ALL, L_ALL,
274 <                             "Idle time limit exceeded for %s - temp k-lining",
275 <                             get_client_name(client_p, HIDE_IP));
276 <        exit_client(client_p, &me, aconf->reason);
277 <        continue;
278 <      }
279 <    }
196 >      continue;  /* Ignore it, its been exited already */
197  
198      if (!IsRegistered(client_p))
199 <      ping = CONNECTTIMEOUT, pingwarn = 0;
199 >      ping = CONNECTTIMEOUT;
200      else
201 <      ping = get_client_ping(client_p, &pingwarn);
201 >      ping = get_client_ping(&client_p->connection->confs);
202  
203 <    if (ping < CurrentTime - client_p->lasttime)
203 >    if (ping < CurrentTime - client_p->connection->lasttime)
204      {
205        if (!IsPingSent(client_p))
206        {
207 <        /*
208 <         * if we havent PINGed the connection and we havent
209 <         * heard from it in a while, PING it to make sure
210 <         * it is still alive.
211 <         */
212 <        SetPingSent(client_p);
213 <        ClearPingWarning(client_p);
214 <        client_p->lasttime = CurrentTime - ping;
298 <        sendto_one(client_p, "PING :%s", ID_or_name(&me, client_p));
207 >        /*
208 >         * If we haven't PINGed the connection and we haven't
209 >         * heard from it in a while, PING it to make sure
210 >         * it is still alive.
211 >         */
212 >        SetPingSent(client_p);
213 >        client_p->connection->lasttime = CurrentTime - ping;
214 >        sendto_one(client_p, "PING :%s", ID_or_name(&me, client_p));
215        }
216        else
217        {
218 <        if (CurrentTime - client_p->lasttime >= 2 * ping)
218 >        if (CurrentTime - client_p->connection->lasttime >= 2 * ping)
219          {
220            /*
221             * If the client/server hasn't talked to us in 2*ping seconds
222             * and it has a ping time, then close its connection.
223             */
224            if (IsServer(client_p) || IsHandshake(client_p))
225 <          {
226 <            sendto_realops_flags(UMODE_ALL, L_ADMIN,
227 <                                 "No response from %s, closing link",
228 <                                 get_client_name(client_p, HIDE_IP));
229 <            sendto_realops_flags(UMODE_ALL, L_OPER,
230 <                                 "No response from %s, closing link",
231 <                                 get_client_name(client_p, MASK_IP));
232 <            ilog(L_NOTICE, "No response from %s, closing link",
233 <                 get_client_name(client_p, HIDE_IP));
234 <          }
235 <
236 <          snprintf(scratch, sizeof(scratch), "Ping timeout: %d seconds",
237 <                   (int)(CurrentTime - client_p->lasttime));
238 <          exit_client(client_p, &me, scratch);
323 <        }
324 <        else if (!IsPingWarning(client_p) && pingwarn > 0 &&
325 <                 (IsServer(client_p) || IsHandshake(client_p)) &&
326 <                 CurrentTime - client_p->lasttime >= ping + pingwarn)
327 <        {
328 <          /*
329 <           * If the server hasn't replied in pingwarn seconds after sending
330 <           * the PING, notify the opers so that they are aware of the problem.
331 <           */
332 <          SetPingWarning(client_p);
333 <          sendto_realops_flags(UMODE_ALL, L_ADMIN,
334 <                               "Warning, no response from %s in %d seconds",
335 <                               get_client_name(client_p, HIDE_IP), pingwarn);
336 <          sendto_realops_flags(UMODE_ALL, L_OPER,
337 <                               "Warning, no response from %s in %d seconds",
338 <                               get_client_name(client_p, MASK_IP), pingwarn);
339 <          ilog(L_NOTICE, "No response from %s in %d seconds",
340 <               get_client_name(client_p, HIDE_IP), pingwarn);
225 >          {
226 >            sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
227 >                                 "No response from %s, closing link",
228 >                                 get_client_name(client_p, HIDE_IP));
229 >            sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
230 >                                 "No response from %s, closing link",
231 >                                 get_client_name(client_p, MASK_IP));
232 >            ilog(LOG_TYPE_IRCD, "No response from %s, closing link",
233 >                 get_client_name(client_p, HIDE_IP));
234 >          }
235 >
236 >          snprintf(buf, sizeof(buf), "Ping timeout: %d seconds",
237 >                   (int)(CurrentTime - client_p->connection->lasttime));
238 >          exit_client(client_p, buf);
239          }
240        }
241      }
# Line 353 | Line 251 | check_pings_list(dlink_list *list)
251   static void
252   check_unknowns_list(void)
253   {
254 <  dlink_node *ptr, *next_ptr;
254 >  dlink_node *node = NULL, *node_next = NULL;
255  
256 <  DLINK_FOREACH_SAFE(ptr, next_ptr, unknown_list.head)
256 >  DLINK_FOREACH_SAFE(node, node_next, unknown_list.head)
257    {
258 <    struct Client *client_p = ptr->data;
361 <
362 <    if (client_p->localClient->reject_delay > 0)
363 <    {
364 <      if (client_p->localClient->reject_delay <= CurrentTime)
365 <        exit_client(client_p, &me, "Rejected");
366 <      continue;
367 <    }
258 >    struct Client *client_p = node->data;
259  
260      /*
261       * Check UNKNOWN connections - if they have been in this state
262       * for > 30s, close them.
263       */
264 <    if (IsAuthFinished(client_p) && (CurrentTime - client_p->firsttime) > 30)
265 <      exit_client(client_p, &me, "Registration timed out");
264 >    if (IsAuthFinished(client_p) && (CurrentTime - client_p->connection->firsttime) > 30)
265 >      exit_client(client_p, "Registration timed out");
266    }
267   }
268  
269 + /*
270 + * check_pings - go through the local client list and check activity
271 + * kill off stuff that should die
272 + *
273 + * inputs       - NOT USED (from event)
274 + * output       - next time_t when check_pings() should be called again
275 + * side effects -
276 + *
277 + *
278 + * A PING can be sent to clients as necessary.
279 + *
280 + * Client/Server ping outs are handled.
281 + */
282 +
283 + /*
284 + * Addon from adrian. We used to call this after nextping seconds,
285 + * however I've changed it to run once a second. This is only for
286 + * PING timeouts, not K/etc-line checks (thanks dianora!). Having it
287 + * run once a second makes life a lot easier - when a new client connects
288 + * and they need a ping in 4 seconds, if nextping was set to 20 seconds
289 + * we end up waiting 20 seconds. This is stupid. :-)
290 + * I will optimise (hah!) check_pings() once I've finished working on
291 + * tidying up other network IO evilnesses.
292 + *     -- adrian
293 + */
294 +
295 + static void
296 + check_pings(void *unused)
297 + {
298 +  check_pings_list(&local_client_list);
299 +  check_pings_list(&local_server_list);
300 +  check_unknowns_list();
301 + }
302 +
303   /* check_conf_klines()
304   *
305   * inputs       - NONE
# Line 382 | Line 307 | check_unknowns_list(void)
307   * side effects - Check all connections for a pending kline against the
308   *                client, exit the client if a kline matches.
309   */
310 < void
310 > void
311   check_conf_klines(void)
312 < {              
313 <  struct Client *client_p = NULL;       /* current local client_p being examined */
314 <  struct AccessItem *aconf = NULL;
390 <  struct ConfItem *conf = NULL;
391 <  dlink_node *ptr, *next_ptr;
312 > {
313 >  struct MaskItem *conf = NULL;
314 >  dlink_node *node = NULL, *node_next = NULL;
315  
316 <  DLINK_FOREACH_SAFE(ptr, next_ptr, local_client_list.head)
316 >  DLINK_FOREACH_SAFE(node, node_next, local_client_list.head)
317    {
318 <    client_p = ptr->data;
318 >    struct Client *client_p = node->data;
319  
320 <    /* If a client is already being exited
321 <     */
399 <    if (IsDead(client_p) || !IsClient(client_p))
320 >    /* If a client is already being exited */
321 >    if (IsDead(client_p))
322        continue;
323  
324 <    /* if there is a returned struct ConfItem then kill it */
325 <    if ((aconf = find_dline_conf(&client_p->localClient->ip,
404 <                                  client_p->localClient->aftype)) != NULL)
324 >    if ((conf = find_conf_by_address(NULL, &client_p->connection->ip, CONF_DLINE,
325 >                                     client_p->connection->aftype, NULL, NULL, 1)))
326      {
327 <      if (aconf->status & CONF_EXEMPTDLINE)
407 <        continue;
408 <
409 <      conf = unmap_conf_item(aconf);
410 <      ban_them(client_p, conf);
327 >      conf_try_ban(client_p, conf);
328        continue; /* and go examine next fd/client_p */
329      }
330  
331 <    if (ConfigFileEntry.glines && (aconf = find_gline(client_p)))
331 >    if (ConfigGeneral.glines)
332      {
333 <      if (IsExemptKline(client_p) ||
334 <          IsExemptGline(client_p))
333 >      if ((conf = find_conf_by_address(client_p->host, &client_p->connection->ip,
334 >                                       CONF_GLINE, client_p->connection->aftype,
335 >                                       client_p->username, NULL, 1)))
336        {
337 <        sendto_realops_flags(UMODE_ALL, L_ALL,
338 <                             "GLINE over-ruled for %s, client is %sline_exempt",
421 <                             get_client_name(client_p, HIDE_IP), IsExemptKline(client_p) ? "k" : "g");
337 >        conf_try_ban(client_p, conf);
338 >        /* and go examine next fd/client_p */
339          continue;
340        }
341 +    }
342  
343 <      conf = unmap_conf_item(aconf);
344 <      ban_them(client_p, conf);
345 <      /* and go examine next fd/client_p */    
428 <      continue;
429 <    }
430 <
431 <    if ((aconf = find_kill(client_p)) != NULL)
343 >    if ((conf = find_conf_by_address(client_p->host, &client_p->connection->ip,
344 >                                     CONF_KLINE, client_p->connection->aftype,
345 >                                     client_p->username, NULL, 1)))
346      {
347 <
348 <      /* if there is a returned struct AccessItem.. then kill it */
435 <      if (IsExemptKline(client_p))
436 <      {
437 <        sendto_realops_flags(UMODE_ALL, L_ALL,
438 <                             "KLINE over-ruled for %s, client is kline_exempt",
439 <                             get_client_name(client_p, HIDE_IP));
440 <        continue;
441 <      }
442 <
443 <      conf = unmap_conf_item(aconf);
444 <      ban_them(client_p, conf);
445 <      continue;
347 >      conf_try_ban(client_p, conf);
348 >      continue;
349      }
350  
351 <    /* if there is a returned struct MatchItem then kill it */
352 <    if ((conf = find_matching_name_conf(XLINE_TYPE,  client_p->info,
450 <                                        NULL, NULL, 0)) != NULL ||
451 <        (conf = find_matching_name_conf(RXLINE_TYPE, client_p->info,
452 <                                        NULL, NULL, 0)) != NULL)
351 >    if ((conf = find_matching_name_conf(CONF_XLINE,  client_p->info,
352 >                                        NULL, NULL, 0)))
353      {
354 <      ban_them(client_p, conf);
354 >      conf_try_ban(client_p, conf);
355        continue;
356      }
357    }
358  
359    /* also check the unknowns list for new dlines */
360 <  DLINK_FOREACH_SAFE(ptr, next_ptr, unknown_list.head)
360 >  DLINK_FOREACH_SAFE(node, node_next, unknown_list.head)
361    {
362 <    client_p = ptr->data;
362 >    struct Client *client_p = node->data;
363  
364 <    if ((aconf = find_dline_conf(&client_p->localClient->ip,
365 <                                  client_p->localClient->aftype)))
364 >    if ((conf = find_conf_by_address(NULL, &client_p->connection->ip, CONF_DLINE,
365 >                                     client_p->connection->aftype, NULL, NULL, 1)))
366      {
367 <      if (aconf->status & CONF_EXEMPTDLINE)
368 <        continue;
469 <
470 <      exit_client(client_p, &me, "D-lined");
367 >      conf_try_ban(client_p, conf);
368 >      continue; /* and go examine next fd/client_p */
369      }
370    }
371   }
372  
373   /*
374 < * ban_them
374 > * conf_try_ban
375   *
376   * inputs       - pointer to client to ban
377 < *              - pointer to ConfItem
377 > *              - pointer to MaskItem
378   * output       - NONE
379   * side effects - given client_p is banned
380   */
381 < static void
382 < ban_them(struct Client *client_p, struct ConfItem *conf)
381 > void
382 > conf_try_ban(struct Client *client_p, struct MaskItem *conf)
383   {
384 <  const char *user_reason = NULL;       /* What is sent to user */
487 <  const char *channel_reason = NULL;    /* What is sent to channel */
488 <  struct AccessItem *aconf = NULL;
489 <  struct MatchItem *xconf = NULL;
384 >  const char *user_reason = NULL;  /* What is sent to user */
385    const char *type_string = NULL;
386    const char dline_string[] = "D-line";
387    const char kline_string[] = "K-line";
# Line 495 | Line 390 | ban_them(struct Client *client_p, struct
390  
391    switch (conf->type)
392    {
393 <    case RKLINE_TYPE:
394 <    case KLINE_TYPE:
393 >    case CONF_KLINE:
394 >      if (IsExemptKline(client_p))
395 >      {
396 >        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
397 >                             "KLINE over-ruled for %s, client is kline_exempt",
398 >                             get_client_name(client_p, HIDE_IP));
399 >        return;
400 >      }
401 >
402        type_string = kline_string;
501      aconf = map_to_conf(conf);
403        break;
404 <    case DLINE_TYPE:
404 >    case CONF_DLINE:
405 >      if (find_conf_by_address(NULL, &client_p->connection->ip, CONF_EXEMPT,
406 >                               client_p->connection->aftype, NULL, NULL, 1))
407 >        return;
408        type_string = dline_string;
505      aconf = map_to_conf(conf);
409        break;
410 <    case GLINE_TYPE:
410 >    case CONF_GLINE:
411 >      if (IsExemptKline(client_p) ||
412 >          IsExemptGline(client_p))
413 >      {
414 >        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
415 >                             "GLINE over-ruled for %s, client is %sline_exempt",
416 >                             get_client_name(client_p, HIDE_IP), IsExemptKline(client_p) ? "k" : "g");
417 >        return;
418 >      }
419 >
420        type_string = gline_string;
509      aconf = map_to_conf(conf);
421        break;
422 <    case RXLINE_TYPE:
512 <    case XLINE_TYPE:
422 >    case CONF_XLINE:
423        type_string = xline_string;
424 <      xconf = map_to_conf(conf);
515 <      ++xconf->count;
424 >      ++conf->count;
425        break;
426      default:
427        assert(0);
428        break;
429    }
430  
431 <  if (ConfigFileEntry.kline_with_reason)
523 <  {
524 <    if (aconf != NULL)
525 <      user_reason = aconf->reason ? aconf->reason : type_string;
526 <    if (xconf != NULL)
527 <      user_reason = xconf->reason ? xconf->reason : type_string;
528 <  }
529 <  else
530 <    user_reason = type_string;
531 <
532 <  if (ConfigFileEntry.kline_reason != NULL)
533 <    channel_reason = ConfigFileEntry.kline_reason;
534 <  else
535 <    channel_reason = user_reason;
431 >  user_reason = conf->reason ? conf->reason : type_string;
432  
433 <  sendto_realops_flags(UMODE_ALL, L_ALL, "%s active for %s",
433 >  sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, "%s active for %s",
434                         type_string, get_client_name(client_p, HIDE_IP));
435  
436    if (IsClient(client_p))
437 <    sendto_one(client_p, form_str(ERR_YOUREBANNEDCREEP),
542 <               me.name, client_p->name, user_reason);
437 >    sendto_one_numeric(client_p, &me, ERR_YOUREBANNEDCREEP, user_reason);
438  
439 <  exit_client(client_p, &me, channel_reason);
439 >  exit_client(client_p, user_reason);
440   }
441  
442   /* update_client_exit_stats()
443   *
444   * input        - pointer to client
445   * output       - NONE
446 < * side effects -
446 > * side effects -
447   */
448   static void
449   update_client_exit_stats(struct Client *client_p)
# Line 556 | Line 451 | update_client_exit_stats(struct Client *
451    if (IsClient(client_p))
452    {
453      assert(Count.total > 0);
454 +
455      --Count.total;
456 <    if (IsOper(client_p))
456 >    if (HasUMode(client_p, UMODE_OPER))
457        --Count.oper;
458 <    if (IsInvisible(client_p))
458 >    if (HasUMode(client_p, UMODE_INVISIBLE))
459        --Count.invisi;
460    }
461    else if (IsServer(client_p))
462 <    sendto_realops_flags(UMODE_EXTERNAL, L_ALL, "Server %s split from %s",
462 >    sendto_realops_flags(UMODE_EXTERNAL, L_ALL, SEND_NOTICE,
463 >                         "Server %s split from %s",
464                           client_p->name, client_p->servptr->name);
465  
466    if (splitchecking && !splitmode)
# Line 576 | Line 473 | update_client_exit_stats(struct Client *
473   * output       - return client pointer
474   * side effects - find person by (nick)name
475   */
579 /* XXX - ugly wrapper */
476   struct Client *
477 < find_person(const struct Client *client_p, const char *name)
477 > find_person(const struct Client *const source_p, const char *name)
478   {
479 <  struct Client *c2ptr;
479 >  struct Client *target_p = NULL;
480  
481    if (IsDigit(*name))
482    {
483 <    if ((c2ptr = hash_find_id(name)) != NULL)
484 <    {
589 <      /* invisible users shall not be found by UID guessing */
590 <      if (IsInvisible(c2ptr) && !IsServer(client_p))
591 <        c2ptr = NULL;
592 <    }
483 >    if (IsServer(source_p->from))
484 >      target_p = hash_find_id(name);
485    }
486    else
487 <    c2ptr = find_client(name);
487 >    target_p = hash_find_client(name);
488  
489 <  return ((c2ptr != NULL && IsClient(c2ptr)) ? c2ptr : NULL);
489 >  return (target_p && IsClient(target_p)) ? target_p : NULL;
490   }
491  
492   /*
493 < * find_chasing - find the client structure for a nick name (user)
494 < *      using history mechanism if necessary. If the client is not found,
495 < *      an error message (NO SUCH NICK) is generated. If the client was found
604 < *      through the history, chasing will be 1 and otherwise 0.
493 > * find_chasing - find the client structure for a nick name (name)
494 > *      using history mechanism if necessary. If the client is not found,
495 > *      an error message (NO SUCH NICK) is generated.
496   */
497   struct Client *
498 < find_chasing(struct Client *client_p, struct Client *source_p, const char *user, int *chasing)
498 > find_chasing(struct Client *source_p, const char *name)
499   {
500 <  struct Client *who = find_person(client_p, user);
500 >  struct Client *target_p = find_person(source_p, name);
501  
502 <  if (chasing)
503 <    *chasing = 0;
502 >  if (target_p)
503 >    return target_p;
504  
505 <  if (who)
506 <    return(who);
505 >  if (IsDigit(*name))
506 >    return NULL;
507  
508 <  if (IsDigit(*user))
618 <    return(NULL);
508 >  target_p = whowas_get_history(name, (time_t)ConfigGeneral.kill_chase_time_limit);
509  
510 <  if ((who = get_history(user,
621 <                        (time_t)ConfigFileEntry.kill_chase_time_limit))
622 <                         == NULL)
510 >  if (!target_p)
511    {
512 <    sendto_one(source_p, form_str(ERR_NOSUCHNICK),
513 <               me.name, source_p->name, user);
626 <    return(NULL);
512 >    sendto_one_numeric(source_p, &me, ERR_NOSUCHNICK, name);
513 >    return NULL;
514    }
515  
516 <  if (chasing)
630 <    *chasing = 1;
631 <
632 <  return(who);
516 >  return target_p;
517   }
518  
519   /*
# Line 641 | Line 525 | find_chasing(struct Client *client_p, st
525   *        But, this can be used to any client structure.
526   *
527   * NOTE 1:
528 < *        Watch out the allocation of "nbuf", if either source_p->name
528 > *        Watch out the allocation of "buf", if either source_p->name
529   *        or source_p->sockhost gets changed into pointers instead of
530   *        directly allocated within the structure...
531   *
532   * NOTE 2:
533   *        Function return either a pointer to the structure (source_p) or
534 < *        to internal buffer (nbuf). *NEVER* use the returned pointer
534 > *        to internal buffer (buf). *NEVER* use the returned pointer
535   *        to modify what it points!!!
536   */
537   const char *
538 < get_client_name(const struct Client *client, int showip)
538 > get_client_name(const struct Client *client_p, enum addr_mask_type type)
539   {
540 <  static char nbuf[HOSTLEN * 2 + USERLEN + 5];
657 <
658 <  assert(client != NULL);
659 <
660 <  if (irccmp(client->name, client->host) == 0)
661 <    return client->name;
540 >  static char buf[HOSTLEN * 2 + USERLEN + 5];
541  
542 <  if (ConfigServerHide.hide_server_ips)
543 <    if (IsServer(client) || IsConnecting(client) || IsHandshake(client))
665 <      showip = MASK_IP;
542 >  if (!MyConnect(client_p))
543 >    return client_p->name;
544  
545 <  if (ConfigFileEntry.hide_spoof_ips)
546 <    if (showip == SHOW_IP && IsIPSpoof(client))
547 <      showip = MASK_IP;
545 >  if (IsServer(client_p) || IsConnecting(client_p) || IsHandshake(client_p))
546 >  {
547 >    if (!irccmp(client_p->name, client_p->host))
548 >      return client_p->name;
549 >    else if (ConfigServerHide.hide_server_ips)
550 >      type = MASK_IP;
551 >  }
552  
553    /* And finally, let's get the host information, ip or name */
554 <  switch (showip)
554 >  switch (type)
555    {
556      case SHOW_IP:
557 <      if (MyConnect(client))
558 <      {
559 <        snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]",
560 <                 client->name,
679 <                 client->username, client->sockhost);
680 <        break;
681 <      }
557 >      snprintf(buf, sizeof(buf), "%s[%s@%s]",
558 >               client_p->name,
559 >               client_p->username, client_p->sockhost);
560 >      break;
561      case MASK_IP:
562 <      snprintf(nbuf, sizeof(nbuf), "%s[%s@255.255.255.255]",
563 <               client->name, client->username);
562 >      if (client_p->connection->aftype == AF_INET)
563 >        snprintf(buf, sizeof(buf), "%s[%s@255.255.255.255]",
564 >                 client_p->name, client_p->username);
565 >      else
566 >        snprintf(buf, sizeof(buf), "%s[%s@ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]",
567 >                 client_p->name, client_p->username);
568        break;
569      default:
570 <      snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]",
571 <               client->name,
572 <               client->username, client->host);
570 >      snprintf(buf, sizeof(buf), "%s[%s@%s]",
571 >               client_p->name,
572 >               client_p->username, client_p->host);
573    }
574  
575 <  return nbuf;
575 >  return buf;
576   }
577  
578   void
579   free_exited_clients(void)
580   {
581 <  dlink_node *ptr = NULL, *next = NULL;
582 <  
583 <  DLINK_FOREACH_SAFE(ptr, next, dead_list.head)
581 >  dlink_node *node = NULL, *node_next = NULL;
582 >
583 >  DLINK_FOREACH_SAFE(node, node_next, dead_list.head)
584    {
585 <    free_client(ptr->data);
586 <    dlinkDelete(ptr, &dead_list);
587 <    free_dlink_node(ptr);
585 >    free_client(node->data);
586 >    dlinkDelete(node, &dead_list);
587 >    free_dlink_node(node);
588    }
589   }
590  
# Line 712 | Line 595 | free_exited_clients(void)
595   * The only messages generated are QUITs on channels.
596   */
597   static void
598 < exit_one_client(struct Client *source_p, const char *quitmsg)
598 > exit_one_client(struct Client *source_p, const char *comment)
599   {
600 <  dlink_node *lp = NULL, *next_lp = NULL;
600 >  dlink_node *node = NULL, *node_next = NULL;
601  
602    assert(!IsMe(source_p));
603 +  assert(source_p != &me);
604  
605    if (IsClient(source_p))
606    {
607 <    if (source_p->servptr->serv != NULL)
608 <      dlinkDelete(&source_p->lnode, &source_p->servptr->serv->client_list);
607 >    dlinkDelete(&source_p->lnode, &source_p->servptr->serv->client_list);
608 >    dlinkDelete(&source_p->node, &global_client_list);
609  
610      /*
611       * If a person is on a channel, send a QUIT notice
# Line 729 | Line 613 | exit_one_client(struct Client *source_p,
613       * that the client can show the "**signoff" message).
614       * (Note: The notice is to the local clients *only*)
615       */
616 <    sendto_common_channels_local(source_p, 0, ":%s!%s@%s QUIT :%s",
616 >    sendto_common_channels_local(source_p, 0, 0, ":%s!%s@%s QUIT :%s",
617                                   source_p->name, source_p->username,
618 <                                 source_p->host, quitmsg);
735 <    DLINK_FOREACH_SAFE(lp, next_lp, source_p->channel.head)
736 <      remove_user_from_channel(lp->data);
618 >                                 source_p->host, comment);
619  
620 <    add_history(source_p, 0);
621 <    off_history(source_p);
620 >    DLINK_FOREACH_SAFE(node, node_next, source_p->channel.head)
621 >      remove_user_from_channel(node->data);
622 >
623 >    whowas_add_history(source_p, 0);
624 >    whowas_off_history(source_p);
625  
626      watch_check_hash(source_p, RPL_LOGOFF);
627  
628      if (MyConnect(source_p))
629      {
630        /* Clean up invitefield */
631 <      DLINK_FOREACH_SAFE(lp, next_lp, source_p->localClient->invited.head)
632 <        del_invite(lp->data, source_p);
631 >      DLINK_FOREACH_SAFE(node, node_next, source_p->connection->invited.head)
632 >        del_invite(node->data, source_p);
633  
634        del_all_accepts(source_p);
635      }
# Line 752 | Line 637 | exit_one_client(struct Client *source_p,
637    else if (IsServer(source_p))
638    {
639      dlinkDelete(&source_p->lnode, &source_p->servptr->serv->server_list);
640 +    dlinkDelete(&source_p->node, &global_client_list);
641  
642 <    if ((lp = dlinkFindDelete(&global_serv_list, source_p)) != NULL)
643 <      free_dlink_node(lp);
642 >    if ((node = dlinkFindDelete(&global_server_list, source_p)))
643 >      free_dlink_node(node);
644    }
645  
646    /* Remove source_p from the client lists */
647 <  if (HasID(source_p))
647 >  if (source_p->id[0])
648      hash_del_id(source_p);
649 +
650    if (source_p->name[0])
651      hash_del_client(source_p);
652  
653    if (IsUserHostIp(source_p))
654      delete_user_host(source_p->username, source_p->host, !MyConnect(source_p));
655  
769  /* remove from global client list
770   * NOTE: source_p->node.next cannot be NULL if the client is added
771   *       to global_client_list (there is always &me at its end)
772   */
773  if (source_p != NULL && source_p->node.next != NULL)
774    dlinkDelete(&source_p->node, &global_client_list);
775
656    update_client_exit_stats(source_p);
657  
658    /* Check to see if the client isn't already on the dead list */
# Line 783 | Line 663 | exit_one_client(struct Client *source_p,
663    dlinkAdd(source_p, make_dlink_node(), &dead_list);
664   }
665  
666 < /* Recursively send QUITs and SQUITs for source_p and all its dependent clients
787 < * and servers to those servers that need them.  A server needs the client
788 < * QUITs if it can't figure them out from the SQUIT (ie pre-TS4) or if it
789 < * isn't getting the SQUIT because of @#(*&@)# hostmasking.  With TS4, once
790 < * a link gets a SQUIT, it doesn't need any QUIT/SQUITs for clients depending
791 < * on that one -orabidoo
792 < *
793 < * This is now called on each local server -adx
794 < */
795 < static void
796 < recurse_send_quits(struct Client *original_source_p, struct Client *source_p,
797 <                   struct Client *from, struct Client *to, const char *comment,
798 <                   const char *splitstr)
799 < {
800 <  dlink_node *ptr, *next;
801 <  struct Client *target_p;
802 <  int hidden = match(me.name, source_p->name); /* XXX */
803 <
804 <  assert(to != source_p);  /* should be already removed from serv_list */
805 <
806 <  /* If this server can handle quit storm (QS) removal
807 <   * of dependents, just send the SQUIT
808 <   *
809 <   * Always check *all* dependent servers if some of them are
810 <   * hidden behind fakename. If so, send out the QUITs -adx
811 <   */
812 <  if (hidden || !IsCapable(to, CAP_QS))
813 <    DLINK_FOREACH_SAFE(ptr, next, source_p->serv->client_list.head)
814 <    {
815 <      target_p = ptr->data;
816 <      sendto_one(to, ":%s QUIT :%s", target_p->name, splitstr);
817 <    }
818 <
819 <  DLINK_FOREACH_SAFE(ptr, next, source_p->serv->server_list.head)
820 <    recurse_send_quits(original_source_p, ptr->data, from, to,
821 <                       comment, splitstr);
822 <
823 <  if (!hidden && ((source_p == original_source_p && to != from) ||
824 <                  !IsCapable(to, CAP_QS)))
825 <  {
826 <    /* don't use a prefix here - we have to be 100% sure the message
827 <     * will be accepted without Unknown prefix etc.. */
828 <    sendto_one(to, "SQUIT %s :%s", ID_or_name(source_p, to), comment);
829 <  }
830 < }
831 <
832 < /*
666 > /*
667   * Remove all clients that depend on source_p; assumes all (S)QUITs have
668 < * already been sent.  we make sure to exit a server's dependent clients
669 < * and servers before the server itself; exit_one_client takes care of
668 > * already been sent.  we make sure to exit a server's dependent clients
669 > * and servers before the server itself; exit_one_client takes care of
670   * actually removing things off llists.   tweaked from +CSr31  -orabidoo
671   */
672   static void
673 < recurse_remove_clients(struct Client *source_p, const char *quitmsg)
673 > recurse_remove_clients(struct Client *source_p, const char *comment)
674   {
675 <  dlink_node *ptr, *next;
675 >  dlink_node *node = NULL, *node_next = NULL;
676  
677 <  DLINK_FOREACH_SAFE(ptr, next, source_p->serv->client_list.head)
678 <    exit_one_client(ptr->data, quitmsg);
677 >  DLINK_FOREACH_SAFE(node, node_next, source_p->serv->client_list.head)
678 >    exit_one_client(node->data, comment);
679  
680 <  DLINK_FOREACH_SAFE(ptr, next, source_p->serv->server_list.head)
680 >  DLINK_FOREACH_SAFE(node, node_next, source_p->serv->server_list.head)
681    {
682 <    recurse_remove_clients(ptr->data, quitmsg);
683 <    exit_one_client(ptr->data, quitmsg);
682 >    recurse_remove_clients(node->data, comment);
683 >    exit_one_client(node->data, comment);
684    }
685   }
686  
687   /*
854 ** Remove *everything* that depends on source_p, from all lists, and sending
855 ** all necessary QUITs and SQUITs.  source_p itself is still on the lists,
856 ** and its SQUITs have been sent except for the upstream one  -orabidoo
857 */
858 static void
859 remove_dependents(struct Client *source_p, struct Client *from,
860                  const char *comment, const char *splitstr)
861 {
862  dlink_node *ptr = NULL;
863
864  DLINK_FOREACH(ptr, serv_list.head)
865    recurse_send_quits(source_p, source_p, from, ptr->data,
866                       comment, splitstr);
867
868  recurse_remove_clients(source_p, splitstr);
869 }
870
871 /*
688   * exit_client - exit a client of any type. Generally, you can use
689   * this on any struct Client, regardless of its state.
690   *
691   * Note, you shouldn't exit remote _users_ without first doing
692 < * SetKilled and propagating a kill or similar message. However,
693 < * it is perfectly correct to call exit_client to force a _server_
692 > * AddFlag(x, FLAGS_KILLED) and propagating a kill or similar message.
693 > *
694 > * However, it is perfectly correct to call exit_client to force a _server_
695   * quit (either local or remote one).
696   *
697 + *
698   * inputs:       - a client pointer that is going to be exited
881 *               - for servers, the second argument is a pointer to who
882 *                 is firing the server. This side won't get any generated
883 *                 messages. NEVER NULL!
699   * output:       none
700   * side effects: the client is delinked from all lists, disconnected,
701   *               and the rest of IRC network is notified of the exit.
702   *               Client memory is scheduled to be freed
703   */
704   void
705 < exit_client(struct Client *source_p, struct Client *from, const char *comment)
705 > exit_client(struct Client *source_p, const char *comment)
706   {
707 <  dlink_node *m = NULL;
707 >  dlink_node *node = NULL;
708 >
709 >  assert(!IsMe(source_p));
710 >  assert(source_p != &me);
711  
712    if (MyConnect(source_p))
713    {
# Line 901 | Line 719 | exit_client(struct Client *source_p, str
719  
720      SetClosing(source_p);
721  
722 <    if (IsIpHash(source_p))
905 <      remove_one_ip(&source_p->localClient->ip);
906 <
907 <    if (source_p->localClient->auth)
722 >    if (HasFlag(source_p, FLAGS_IPHASH))
723      {
724 <      delete_auth(source_p->localClient->auth);
725 <      source_p->localClient->auth = NULL;
724 >      DelFlag(source_p, FLAGS_IPHASH);
725 >      ipcache_remove_address(&source_p->connection->ip);
726      }
727  
728 <    /* This source_p could have status of one of STAT_UNKNOWN, STAT_CONNECTING
728 >    delete_auth(&source_p->connection->auth);
729 >
730 >    /*
731 >     * This source_p could have status of one of STAT_UNKNOWN, STAT_CONNECTING
732       * STAT_HANDSHAKE or STAT_UNKNOWN
733       * all of which are lumped together into unknown_list
734       *
# Line 920 | Line 738 | exit_client(struct Client *source_p, str
738      {
739        assert(dlinkFind(&unknown_list, source_p));
740  
741 <      dlinkDelete(&source_p->localClient->lclient_node, &unknown_list);
741 >      dlinkDelete(&source_p->connection->lclient_node, &unknown_list);
742      }
743      else if (IsClient(source_p))
744      {
745 +      time_t on_for = CurrentTime - source_p->connection->firsttime;
746 +
747        assert(Count.local > 0);
928      Count.local--;
748  
749 <      if (IsOper(source_p))
750 <      {
751 <        if ((m = dlinkFindDelete(&oper_list, source_p)) != NULL)
752 <          free_dlink_node(m);
753 <      }
749 >      --Count.local;
750 >
751 >      if (HasUMode(source_p, UMODE_OPER))
752 >        if ((node = dlinkFindDelete(&oper_list, source_p)))
753 >          free_dlink_node(node);
754  
755        assert(dlinkFind(&local_client_list, source_p));
756 <      dlinkDelete(&source_p->localClient->lclient_node, &local_client_list);
756 >      dlinkDelete(&source_p->connection->lclient_node, &local_client_list);
757  
758 <      if (source_p->localClient->list_task != NULL)
759 <        free_list_task(source_p->localClient->list_task, source_p);
758 >      if (source_p->connection->list_task)
759 >        free_list_task(source_p);
760  
761        watch_del_watch_list(source_p);
762 <      sendto_realops_flags(UMODE_CCONN, L_ALL, "Client exiting: %s (%s@%s) [%s] [%s]",
762 >      client_clear_svstags(source_p);
763 >
764 >      sendto_realops_flags(UMODE_CCONN, L_ALL, SEND_NOTICE,
765 >                           "Client exiting: %s (%s@%s) [%s] [%s]",
766                             source_p->name, source_p->username, source_p->host, comment,
767 <                           ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
946 <                           "255.255.255.255" : source_p->sockhost);
947 <      sendto_realops_flags(UMODE_CCONN_FULL, L_ALL, "CLIEXIT: %s %s %s %s 0 %s",
948 <                           source_p->name,
949 <                           source_p->username,
950 <                           source_p->host,
951 <
952 <                           ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
953 <                           "255.255.255.255" : source_p->sockhost,
954 <                           comment);
955 <    }
767 >                           source_p->sockhost);
768  
769 <    /* As soon as a client is known to be a server of some sort
770 <     * it has to be put on the serv_list, or SJOIN's to this new server
771 <     * from the connect burst will not be seen.
772 <     */
773 <    if (IsServer(source_p) || IsConnecting(source_p) ||
774 <        IsHandshake(source_p))
769 >      ilog(LOG_TYPE_USER, "%s (%3u:%02u:%02u): %s!%s@%s %llu/%llu",
770 >           myctime(source_p->connection->firsttime), (unsigned int)(on_for / 3600),
771 >           (unsigned int)((on_for % 3600)/60), (unsigned int)(on_for % 60),
772 >           source_p->name, source_p->username, source_p->host,
773 >           source_p->connection->send.bytes>>10,
774 >           source_p->connection->recv.bytes>>10);
775 >    }
776 >    else if (IsServer(source_p))
777      {
778 <      if ((m = dlinkFindDelete(&serv_list, source_p)) != NULL)
965 <      {
966 <        free_dlink_node(m);
967 <        unset_chcap_usage_counts(source_p);
968 <      }
778 >      assert(Count.myserver > 0);
779  
780 <      if (IsServer(source_p))
971 <        Count.myserver--;
972 <    }
780 >      --Count.myserver;
781  
782 <    log_user_exit(source_p);
782 >      assert(dlinkFind(&local_server_list, source_p));
783 >      dlinkDelete(&source_p->connection->lclient_node, &local_server_list);
784 >    }
785  
786      if (!IsDead(source_p))
787      {
788        if (IsServer(source_p))
789        {
790 <        /* for them, we are exiting the network */
791 <        sendto_one(source_p, ":%s SQUIT %s :%s",
792 <                   ID_or_name(from, source_p), me.name, comment);
790 >        if (!HasFlag(source_p, FLAGS_SQUIT))
791 >        {
792 >          /* for them, we are exiting the network */
793 >          sendto_one(source_p, ":%s SQUIT %s :%s",
794 >                     me.id, me.id, comment);
795 >        }
796        }
797  
798        sendto_one(source_p, "ERROR :Closing Link: %s (%s)",
799                   source_p->host, comment);
800      }
801  
989    /*
990    ** Currently only server connections can have
991    ** depending remote clients here, but it does no
992    ** harm to check for all local clients. In
993    ** future some other clients than servers might
994    ** have remotes too...
995    **
996    ** Close the Client connection first and mark it
997    ** so that no messages are attempted to send to it.
998    ** Remember it makes source_p->from == NULL.
999    */
802      close_connection(source_p);
803    }
804 +  else if (IsClient(source_p) && HasFlag(source_p->servptr, FLAGS_EOB))
805 +    sendto_realops_flags(UMODE_FARCONNECT, L_ALL, SEND_NOTICE,
806 +                         "Client exiting at %s: %s (%s@%s) [%s]",
807 +                         source_p->servptr->name, source_p->name,
808 +                         source_p->username, source_p->host, comment);
809  
810    if (IsServer(source_p))
811    {
812 <    char splitstr[HOSTLEN + HOSTLEN + 2];
812 >    char splitstr[HOSTLEN + HOSTLEN + 2] = "";
813  
814      /* This shouldn't ever happen */
815 <    assert(source_p->serv != NULL && source_p->servptr != NULL);
815 >    assert(source_p->serv && source_p->servptr);
816  
817      if (ConfigServerHide.hide_servers)
818        /*
819 <       * Set netsplit message to "*.net *.split" to still show
819 >       * Set netsplit message to "*.net *.split" to still show
820         * that its a split, but hide the servers splitting
821         */
822 <      strcpy(splitstr, "*.net *.split");
822 >      strlcpy(splitstr, "*.net *.split", sizeof(splitstr));
823      else
824        snprintf(splitstr, sizeof(splitstr), "%s %s",
825                 source_p->servptr->name, source_p->name);
826  
827 <    remove_dependents(source_p, from->from, comment, splitstr);
827 >    /* Send SQUIT for source_p in every direction. source_p is already off of local_server_list here */
828 >    if (!HasFlag(source_p, FLAGS_SQUIT))
829 >      sendto_server(NULL, 0, 0, "SQUIT %s :%s", source_p->id, comment);
830 >
831 >    /* Now exit the clients internally */
832 >    recurse_remove_clients(source_p, splitstr);
833  
834 <    if (source_p->servptr == &me)
834 >    if (MyConnect(source_p))
835      {
836 <      sendto_realops_flags(UMODE_ALL, L_ALL,
837 <                           "%s was connected for %d seconds.  %llu/%llu sendK/recvK.",
838 <                           source_p->name, (int)(CurrentTime - source_p->firsttime),
839 <                           source_p->localClient->send.bytes >> 10,
840 <                           source_p->localClient->recv.bytes >> 10);
841 <      ilog(L_NOTICE, "%s was connected for %d seconds.  %llu/%llu sendK/recvK.",
842 <           source_p->name, (int)(CurrentTime - source_p->firsttime),
843 <           source_p->localClient->send.bytes >> 10,
844 <           source_p->localClient->recv.bytes >> 10);
845 <    }
846 <  }
847 <  else if (IsClient(source_p) && !IsKilled(source_p))
848 <  {
849 <    sendto_server(from->from, NULL, CAP_TS6, NOCAPS,
850 <                  ":%s QUIT :%s", ID(source_p), comment);
851 <    sendto_server(from->from, NULL, NOCAPS, CAP_TS6,
852 <                  ":%s QUIT :%s", source_p->name, comment);
1041 <  }
836 >      int connected = CurrentTime - source_p->connection->firsttime;
837 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
838 >                           "%s was connected for %d day%s, %2d:%02d:%02d. %llu/%llu sendK/recvK.",
839 >                           source_p->name, connected/86400, (connected/86400 == 1) ? "" : "s",
840 >                           (connected % 86400) / 3600, (connected % 3600) / 60, connected % 60,
841 >                           source_p->connection->send.bytes >> 10,
842 >                           source_p->connection->recv.bytes >> 10);
843 >      ilog(LOG_TYPE_IRCD, "%s was connected for %d day%s, %2d:%02d:%02d. %llu/%llu sendK/recvK.",
844 >           source_p->name, connected/86400, (connected/86400 == 1) ? "" : "s",
845 >          (connected % 86400) / 3600, (connected % 3600) / 60, connected % 60,
846 >          source_p->connection->send.bytes >> 10,
847 >          source_p->connection->recv.bytes >> 10);
848 >    }
849 >  }
850 >  else if (IsClient(source_p) && !HasFlag(source_p, FLAGS_KILLED))
851 >    sendto_server(source_p->from, 0, 0, ":%s QUIT :%s",
852 >                  source_p->id, comment);
853  
854    /* The client *better* be off all of the lists */
855    assert(dlinkFind(&unknown_list, source_p) == NULL);
856    assert(dlinkFind(&local_client_list, source_p) == NULL);
857 <  assert(dlinkFind(&serv_list, source_p) == NULL);
857 >  assert(dlinkFind(&local_server_list, source_p) == NULL);
858    assert(dlinkFind(&oper_list, source_p) == NULL);
859  
860    exit_one_client(source_p, comment);
# Line 1056 | Line 867 | exit_client(struct Client *source_p, str
867   void
868   dead_link_on_write(struct Client *client_p, int ierrno)
869   {
870 <  dlink_node *ptr;
870 >  dlink_node *node;
871  
872    if (IsDefunct(client_p))
873      return;
874  
875 <  dbuf_clear(&client_p->localClient->buf_recvq);
876 <  dbuf_clear(&client_p->localClient->buf_sendq);
875 >  dbuf_clear(&client_p->connection->buf_recvq);
876 >  dbuf_clear(&client_p->connection->buf_sendq);
877  
878    assert(dlinkFind(&abort_list, client_p) == NULL);
879 <  ptr = make_dlink_node();
879 >  node = make_dlink_node();
880    /* don't let exit_aborted_clients() finish yet */
881 <  dlinkAddTail(client_p, ptr, &abort_list);
881 >  dlinkAddTail(client_p, node, &abort_list);
882  
883    if (eac_next == NULL)
884 <    eac_next = ptr;
884 >    eac_next = node;
885  
886    SetDead(client_p); /* You are dead my friend */
887   }
# Line 1082 | Line 893 | dead_link_on_write(struct Client *client
893   void
894   dead_link_on_read(struct Client *client_p, int error)
895   {
896 <  char errmsg[255];
896 >  char errmsg[IRCD_BUFSIZE];
897    int current_error;
898  
899    if (IsDefunct(client_p))
900      return;
901  
902 <  dbuf_clear(&client_p->localClient->buf_recvq);
903 <  dbuf_clear(&client_p->localClient->buf_sendq);
902 >  dbuf_clear(&client_p->connection->buf_recvq);
903 >  dbuf_clear(&client_p->connection->buf_sendq);
904  
905 <  current_error = get_sockerr(client_p->localClient->fd.fd);
905 >  current_error = get_sockerr(client_p->connection->fd.fd);
906  
907    if (IsServer(client_p) || IsHandshake(client_p))
908    {
909 <    int connected = CurrentTime - client_p->firsttime;
910 <      
909 >    int connected = CurrentTime - client_p->connection->firsttime;
910 >
911      if (error == 0)
912      {
913        /* Admins get the real IP */
914 <      sendto_realops_flags(UMODE_ALL, L_ADMIN,
915 <                           "Server %s closed the connection",
916 <                           get_client_name(client_p, SHOW_IP));
914 >      sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
915 >                           "Server %s closed the connection",
916 >                           get_client_name(client_p, SHOW_IP));
917  
918        /* Opers get a masked IP */
919 <      sendto_realops_flags(UMODE_ALL, L_OPER,
920 <                           "Server %s closed the connection",
921 <                           get_client_name(client_p, MASK_IP));
919 >      sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
920 >                           "Server %s closed the connection",
921 >                           get_client_name(client_p, MASK_IP));
922  
923 <      ilog(L_NOTICE, "Server %s closed the connection",
924 <           get_client_name(client_p, SHOW_IP));
923 >      ilog(LOG_TYPE_IRCD, "Server %s closed the connection",
924 >           get_client_name(client_p, SHOW_IP));
925      }
926      else
927      {
928        report_error(L_ADMIN, "Lost connection to %s: %s",
929 <                   get_client_name(client_p, SHOW_IP), current_error);
929 >                   get_client_name(client_p, SHOW_IP), current_error);
930        report_error(L_OPER, "Lost connection to %s: %s",
931 <                   get_client_name(client_p, MASK_IP), current_error);
931 >                   get_client_name(client_p, MASK_IP), current_error);
932      }
933  
934 <    sendto_realops_flags(UMODE_ALL, L_ALL,
935 <                         "%s had been connected for %d day%s, %2d:%02d:%02d",
936 <                         client_p->name, connected/86400,
937 <                         (connected/86400 == 1) ? "" : "s",
938 <                         (connected % 86400) / 3600, (connected % 3600) / 60,
939 <                         connected % 60);
934 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
935 >                         "%s was connected for %d day%s, %2d:%02d:%02d",
936 >                         client_p->name, connected/86400,
937 >                         (connected/86400 == 1) ? "" : "s",
938 >                         (connected % 86400) / 3600, (connected % 3600) / 60,
939 >                         connected % 60);
940    }
941  
942    if (error == 0)
# Line 1135 | Line 946 | dead_link_on_read(struct Client *client_
946      snprintf(errmsg, sizeof(errmsg), "Read error: %s",
947               strerror(current_error));
948  
949 <  exit_client(client_p, &me, errmsg);
949 >  exit_client(client_p, errmsg);
950   }
951  
952   void
# Line 1152 | Line 963 | exit_aborted_clients(void)
963  
964      if (target_p == NULL)
965      {
966 <      sendto_realops_flags(UMODE_ALL, L_ALL,
966 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
967                             "Warning: null client on abort_list!");
968        dlinkDelete(ptr, &abort_list);
969        free_dlink_node(ptr);
# Line 1166 | Line 977 | exit_aborted_clients(void)
977      else
978        notice = "Write error: connection closed";
979  
980 <    exit_client(target_p, &me, notice);  
980 >    exit_client(target_p, notice);
981      free_dlink_node(ptr);
982    }
983   }
# Line 1184 | Line 995 | exit_aborted_clients(void)
995   void
996   del_accept(struct split_nuh_item *accept_p, struct Client *client_p)
997   {
998 <  dlinkDelete(&accept_p->node, &client_p->localClient->acceptlist);
998 >  dlinkDelete(&accept_p->node, &client_p->connection->acceptlist);
999  
1000    MyFree(accept_p->nickptr);
1001    MyFree(accept_p->userptr);
# Line 1194 | Line 1005 | del_accept(struct split_nuh_item *accept
1005  
1006   struct split_nuh_item *
1007   find_accept(const char *nick, const char *user,
1008 <            const char *host, struct Client *client_p, int do_match)
1008 >            const char *host, struct Client *client_p,
1009 >            int (*cmpfunc)(const char *, const char *))
1010   {
1011 <  dlink_node *ptr = NULL;
1200 <  /* XXX We wouldn't need that if match() would return 0 on match */
1201 <  int (*cmpfunc)(const char *, const char *) = do_match ? match : irccmp;
1011 >  dlink_node *node = NULL;
1012  
1013 <  DLINK_FOREACH(ptr, client_p->localClient->acceptlist.head)
1013 >  DLINK_FOREACH(node, client_p->connection->acceptlist.head)
1014    {
1015 <    struct split_nuh_item *accept_p = ptr->data;
1015 >    struct split_nuh_item *accept_p = node->data;
1016  
1017 <    if (cmpfunc(accept_p->nickptr, nick) == do_match &&
1018 <        cmpfunc(accept_p->userptr, user) == do_match &&
1019 <        cmpfunc(accept_p->hostptr, host) == do_match)
1017 >    if (!cmpfunc(accept_p->nickptr, nick) &&
1018 >        !cmpfunc(accept_p->userptr, user) &&
1019 >        !cmpfunc(accept_p->hostptr, host))
1020        return accept_p;
1021    }
1022  
# Line 1224 | Line 1034 | int
1034   accept_message(struct Client *source,
1035                 struct Client *target)
1036   {
1037 <  dlink_node *ptr = NULL;
1037 >  dlink_node *node = NULL;
1038 >
1039 >  if (HasFlag(source, FLAGS_SERVICE) ||
1040 >      (HasUMode(source, UMODE_OPER) && ConfigGeneral.opers_bypass_callerid))
1041 >    return 1;
1042  
1043    if (source == target || find_accept(source->name, source->username,
1044 <                                      source->host, target, 1))
1044 >                                      source->host, target, match))
1045      return 1;
1046  
1047 <  if (IsSoftCallerId(target))
1048 <    DLINK_FOREACH(ptr, target->channel.head)
1049 <      if (IsMember(source, ((struct Membership *)ptr->data)->chptr))
1047 >  if (!HasUMode(target, UMODE_CALLERID) && HasUMode(target, UMODE_SOFTCALLERID))
1048 >    DLINK_FOREACH(node, target->channel.head)
1049 >      if (IsMember(source, ((struct Membership *)node->data)->chptr))
1050          return 1;
1051  
1052    return 0;
# Line 1247 | Line 1061 | accept_message(struct Client *source,
1061   void
1062   del_all_accepts(struct Client *client_p)
1063   {
1064 <  dlink_node *ptr = NULL, *next_ptr = NULL;
1064 >  dlink_node *node = NULL, *node_next = NULL;
1065  
1066 <  DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->localClient->acceptlist.head)
1067 <    del_accept(ptr->data, client_p);
1066 >  DLINK_FOREACH_SAFE(node, node_next, client_p->connection->acceptlist.head)
1067 >    del_accept(node->data, client_p);
1068   }
1069  
1070 < /* change_local_nick()
1071 < *
1072 < * inputs       - pointer to server
1259 < *              - pointer to client
1260 < *              - nick
1261 < * output       -
1262 < * side effects - changes nick of a LOCAL user
1263 < */
1264 < void
1265 < change_local_nick(struct Client *client_p, struct Client *source_p, const char *nick)
1070 > unsigned int
1071 > client_get_idle_time(const struct Client *source_p,
1072 >                     const struct Client *target_p)
1073   {
1074 <  int samenick = 0;
1074 >  unsigned int idle = 0;
1075 >  unsigned int min_idle = 0;
1076 >  unsigned int max_idle = 0;
1077 >  const struct ClassItem *const class = get_class_ptr(&target_p->connection->confs);
1078  
1079 <  assert(source_p->name[0] && !EmptyString(nick));
1079 >  if (!(class->flags & CLASS_FLAGS_FAKE_IDLE) || target_p == source_p)
1080 >    return CurrentTime - target_p->connection->last_privmsg;
1081  
1082 <  /*
1083 <   * Client just changing his/her nick. If he/she is
1084 <   * on a channel, send note of change to all clients
1274 <   * on that channel. Propagate notice to other servers.
1275 <   */
1276 <  if ((source_p->localClient->last_nick_change +
1277 <       ConfigFileEntry.max_nick_time) < CurrentTime)
1278 <    source_p->localClient->number_of_nick_changes = 0;
1279 <  source_p->localClient->last_nick_change = CurrentTime;
1280 <  source_p->localClient->number_of_nick_changes++;
1281 <
1282 <  if ((ConfigFileEntry.anti_nick_flood &&
1283 <      (source_p->localClient->number_of_nick_changes
1284 <       <= ConfigFileEntry.max_nick_changes)) ||
1285 <     !ConfigFileEntry.anti_nick_flood ||
1286 <     (IsOper(source_p) && ConfigFileEntry.no_oper_flood))
1287 <  {
1288 <    samenick = !irccmp(source_p->name, nick);
1082 >  if (HasUMode(source_p, UMODE_OPER) &&
1083 >      !(class->flags & CLASS_FLAGS_HIDE_IDLE_FROM_OPERS))
1084 >    return CurrentTime - target_p->connection->last_privmsg;
1085  
1086 <    if (!samenick)
1087 <    {
1292 <      source_p->tsinfo = CurrentTime;
1293 <      clear_ban_cache_client(source_p);
1294 <      watch_check_hash(source_p, RPL_LOGOFF);
1086 >  min_idle = class->min_idle;
1087 >  max_idle = class->max_idle;
1088  
1089 <      if (HasUMode(source_p, UMODE_REGISTERED))
1090 <      {
1298 <        unsigned int oldmodes = source_p->umodes;
1299 <        char modebuf[IRCD_BUFSIZE] = { '\0' };
1300 <
1301 <        DelUMode(source_p, UMODE_REGISTERED);
1302 <        send_umode(source_p, source_p, oldmodes, 0xffffffff, modebuf);
1303 <      }
1304 <    }
1089 >  if (min_idle == max_idle)
1090 >    return min_idle;
1091  
1092 <    /* XXX - the format of this notice should eventually be changed
1093 <     * to either %s[%s@%s], or even better would be get_client_name() -bill
1094 <     */
1095 <    sendto_realops_flags(UMODE_NCHANGE, L_ALL, "Nick change: From %s to %s [%s@%s]",
1310 <                         source_p->name, nick, source_p->username, source_p->host);
1311 <    sendto_common_channels_local(source_p, 1, ":%s!%s@%s NICK :%s",
1312 <                                 source_p->name, source_p->username,
1313 <                                 source_p->host, nick);
1314 <    add_history(source_p, 1);
1092 >  if (class->flags & CLASS_FLAGS_RANDOM_IDLE)
1093 >    idle = genrand_int32();
1094 >  else
1095 >    idle = CurrentTime - target_p->connection->last_privmsg;
1096  
1097 <    sendto_server(client_p, NULL, CAP_TS6, NOCAPS,
1098 <                  ":%s NICK %s :%lu",
1099 <                  ID(source_p), nick, (unsigned long)source_p->tsinfo);
1100 <    sendto_server(client_p, NULL, NOCAPS, CAP_TS6,
1320 <                  ":%s NICK %s :%lu",
1321 <                  source_p->name, nick, (unsigned long)source_p->tsinfo);
1097 >  if (!max_idle)
1098 >    idle = 0;
1099 >  else
1100 >    idle %= max_idle;
1101  
1102 <    hash_del_client(source_p);
1103 <    strcpy(source_p->name, nick);
1325 <    hash_add_client(source_p);
1102 >  if (idle < min_idle)
1103 >    idle = min_idle + (idle % (max_idle - min_idle));
1104  
1105 <    if (!samenick)
1106 <      watch_check_hash(source_p, RPL_LOGON);
1105 >  return idle;
1106 > }
1107  
1108 <    /* fd_desc is long enough */
1109 <    fd_note(&client_p->localClient->fd, "Nick: %s", nick);
1110 <  }
1111 <  else
1112 <    sendto_one(source_p, form_str(ERR_NICKTOOFAST),
1113 <               me.name, source_p->name, source_p->name,
1114 <               nick, ConfigFileEntry.max_nick_time);
1108 > /* client_init()
1109 > *
1110 > * inputs       - NONE
1111 > * output       - NONE
1112 > * side effects - initialize client free memory
1113 > */
1114 > void
1115 > client_init(void)
1116 > {
1117 >  static struct event event_ping =
1118 >  {
1119 >    .name = "check_pings",
1120 >    .handler = check_pings,
1121 >    .when = 5
1122 >  };
1123 >
1124 >  client_pool = mp_pool_new(sizeof(struct Client), MP_CHUNK_SIZE_CLIENT);
1125 >  connection_pool = mp_pool_new(sizeof(struct Connection), MP_CHUNK_SIZE_CONNECTION);
1126 >  event_add(&event_ping, NULL);
1127   }

Diff Legend

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