]> jfr.im git - irc/rqf/shadowircd.git/blame - src/client.c
Some global structs cleaned up a bit in their initalization and declarations.
[irc/rqf/shadowircd.git] / src / client.c
CommitLineData
212380e3 1/*
b37021a4 2 * charybdis: an advanced ircd.
212380e3 3 * client.c: Controls clients.
4 *
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
b37021a4 8 * Copyright (C) 2007 William Pitcock
212380e3 9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 * USA
24 *
f80a1823 25 * $Id: client.c 3514 2007-06-06 16:25:21Z nenolod $
212380e3 26 */
27#include "stdinc.h"
28#include "config.h"
29
212380e3 30#include "client.h"
31#include "class.h"
32#include "common.h"
212380e3 33#include "hash.h"
34#include "irc_string.h"
35#include "sprintf_irc.h"
36#include "ircd.h"
37#include "s_gline.h"
38#include "numeric.h"
39#include "packet.h"
40#include "s_auth.h"
212380e3 41#include "s_conf.h"
42#include "s_newconf.h"
d3455e2c 43#include "logger.h"
212380e3 44#include "s_serv.h"
45#include "s_stats.h"
46#include "send.h"
47#include "whowas.h"
48#include "s_user.h"
212380e3 49#include "hash.h"
212380e3 50#include "hostmask.h"
212380e3 51#include "listener.h"
52#include "hook.h"
53#include "msg.h"
54#include "monitor.h"
55#include "blacklist.h"
54015b5f 56#include "reject.h"
994544c2 57#include "scache.h"
b37021a4 58#include "irc_dictionary.h"
212380e3 59
60#define DEBUG_EXITED_CLIENTS
61
af81d5a0
WP
62static void check_pings_list(rb_dlink_list * list);
63static void check_unknowns_list(rb_dlink_list * list);
212380e3 64static void free_exited_clients(void *unused);
65static void exit_aborted_clients(void *unused);
66
67static int exit_remote_client(struct Client *, struct Client *, struct Client *,const char *);
68static int exit_remote_server(struct Client *, struct Client *, struct Client *,const char *);
69static int exit_local_client(struct Client *, struct Client *, struct Client *,const char *);
70static int exit_unknown_client(struct Client *, struct Client *, struct Client *,const char *);
71static int exit_local_server(struct Client *, struct Client *, struct Client *,const char *);
72static int qs_server(struct Client *, struct Client *, struct Client *, const char *comment);
73
74static EVH check_pings;
75
6e9b4415
VY
76extern rb_bh *client_heap;
77extern rb_bh *lclient_heap;
78extern rb_bh *pclient_heap;
784fdac0 79static rb_bh *away_heap = NULL;
212380e3 80
81extern char current_uid[IDLEN];
82
43de0f45
WP
83struct Dictionary *nd_dict = NULL;
84
212380e3 85enum
86{
87 D_LINED,
88 K_LINED,
89 G_LINED
90};
91
af81d5a0 92rb_dlink_list dead_list;
212380e3 93#ifdef DEBUG_EXITED_CLIENTS
af81d5a0 94static rb_dlink_list dead_remote_list;
212380e3 95#endif
96
97struct abort_client
98{
af81d5a0 99 rb_dlink_node node;
212380e3 100 struct Client *client;
101 char notice[REASONLEN];
102};
103
af81d5a0 104static rb_dlink_list abort_list;
212380e3 105
106
107/*
108 * init_client
109 *
110 * inputs - NONE
111 * output - NONE
112 * side effects - initialize client free memory
113 */
114void
115init_client(void)
116{
117 /*
118 * start off the check ping event .. -- adrian
119 * Every 30 seconds is plenty -- db
120 */
ae4091d2 121 client_heap = rb_bh_create(sizeof(struct Client), CLIENT_HEAP_SIZE, "client_heap");
784fdac0
VY
122 lclient_heap = rb_bh_create(sizeof(struct LocalUser), LCLIENT_HEAP_SIZE, "lclient_heap");
123 pclient_heap = rb_bh_create(sizeof(struct PreClient), PCLIENT_HEAP_SIZE, "pclient_heap");
124 away_heap = rb_bh_create(AWAYLEN, AWAY_HEAP_SIZE, "away_heap");
125
780087dc
JT
126 rb_event_addish("check_pings", check_pings, NULL, 30);
127 rb_event_addish("free_exited_clients", &free_exited_clients, NULL, 4);
128 rb_event_addish("exit_aborted_clients", exit_aborted_clients, NULL, 1);
6227ed01 129 rb_event_add("flood_recalc", flood_recalc, NULL, 1);
43de0f45
WP
130
131 nd_dict = irc_dictionary_create(irccmp);
212380e3 132}
133
134
135/*
136 * make_client - create a new Client struct and set it to initial state.
137 *
138 * from == NULL, create local client (a client connected
139 * to a socket).
140 *
141 * from, create remote client (behind a socket
142 * associated with the client defined by
143 * 'from'). ('from' is a local client!!).
144 */
145struct Client *
146make_client(struct Client *from)
147{
148 struct Client *client_p = NULL;
149 struct LocalUser *localClient;
150
6e9b4415 151 client_p = rb_bh_alloc(client_heap);
212380e3 152
153 if(from == NULL)
154 {
155 client_p->from = client_p; /* 'from' of local client is self! */
156
6e9b4415 157 localClient = (struct LocalUser *) rb_bh_alloc(lclient_heap);
212380e3 158 SetMyConnect(client_p);
159 client_p->localClient = localClient;
160
9f6bbe3c 161 client_p->localClient->lasttime = client_p->localClient->firsttime = rb_current_time();
212380e3 162
de057244 163 client_p->localClient->F = NULL;
83b667df 164 client_p->localClient->ctrlF = NULL;
212380e3 165
6e9b4415 166 client_p->preClient = (struct PreClient *) rb_bh_alloc(pclient_heap);
212380e3 167
168 /* as good a place as any... */
af81d5a0 169 rb_dlinkAdd(client_p, &client_p->localClient->tnode, &unknown_list);
212380e3 170 }
171 else
172 { /* from is not NULL */
173 client_p->localClient = NULL;
174 client_p->preClient = NULL;
175 client_p->from = from; /* 'from' of local client is self! */
176 }
177
178 SetUnknown(client_p);
179 strcpy(client_p->username, "unknown");
180
181 return client_p;
182}
183
184void
185free_pre_client(struct Client *client_p)
186{
187 struct Blacklist *blptr;
188
189 s_assert(NULL != client_p);
190
191 if(client_p->preClient == NULL)
192 return;
193
194 blptr = client_p->preClient->dnsbl_listed;
195 if (blptr != NULL)
196 unref_blacklist(blptr);
197 abort_blacklist_queries(client_p);
6e9b4415 198 rb_bh_free(pclient_heap, client_p->preClient);
212380e3 199 client_p->preClient = NULL;
200}
201
202static void
203free_local_client(struct Client *client_p)
204{
205 s_assert(NULL != client_p);
206 s_assert(&me != client_p);
207
208 if(client_p->localClient == NULL)
209 return;
210
211 /*
212 * clean up extra sockets from P-lines which have been discarded.
213 */
214 if(client_p->localClient->listener)
215 {
216 s_assert(0 < client_p->localClient->listener->ref_count);
217 if(0 == --client_p->localClient->listener->ref_count
218 && !client_p->localClient->listener->active)
219 free_listener(client_p->localClient->listener);
220 client_p->localClient->listener = 0;
221 }
222
24350e62 223 if(client_p->localClient->F)
780087dc 224 rb_close(client_p->localClient->F);
212380e3 225
226 if(client_p->localClient->passwd)
227 {
228 memset(client_p->localClient->passwd, 0,
229 strlen(client_p->localClient->passwd));
90a3c35b 230 rb_free(client_p->localClient->passwd);
212380e3 231 }
232
90a3c35b
VY
233 rb_free(client_p->localClient->challenge);
234 rb_free(client_p->localClient->fullcaps);
235 rb_free(client_p->localClient->opername);
236 rb_free(client_p->localClient->mangledhost);
212380e3 237
6e9b4415 238 rb_bh_free(lclient_heap, client_p->localClient);
212380e3 239 client_p->localClient = NULL;
240}
241
242void
243free_client(struct Client *client_p)
244{
245 s_assert(NULL != client_p);
246 s_assert(&me != client_p);
247 free_local_client(client_p);
248 free_pre_client(client_p);
6e9b4415 249 rb_bh_free(client_heap, client_p);
212380e3 250}
251
252/*
253 * check_pings - go through the local client list and check activity
254 * kill off stuff that should die
255 *
256 * inputs - NOT USED (from event)
257 * output - next time_t when check_pings() should be called again
258 * side effects -
259 *
260 *
261 * A PING can be sent to clients as necessary.
262 *
263 * Client/Server ping outs are handled.
264 */
265
266/*
267 * Addon from adrian. We used to call this after nextping seconds,
268 * however I've changed it to run once a second. This is only for
269 * PING timeouts, not K/etc-line checks (thanks dianora!). Having it
270 * run once a second makes life a lot easier - when a new client connects
271 * and they need a ping in 4 seconds, if nextping was set to 20 seconds
272 * we end up waiting 20 seconds. This is stupid. :-)
273 * I will optimise (hah!) check_pings() once I've finished working on
274 * tidying up other network IO evilnesses.
275 * -- adrian
276 */
277
278static void
279check_pings(void *notused)
280{
281 check_pings_list(&lclient_list);
282 check_pings_list(&serv_list);
283 check_unknowns_list(&unknown_list);
284}
285
286/*
287 * Check_pings_list()
288 *
289 * inputs - pointer to list to check
290 * output - NONE
291 * side effects -
292 */
293static void
af81d5a0 294check_pings_list(rb_dlink_list * list)
212380e3 295{
296 char scratch[32]; /* way too generous but... */
297 struct Client *client_p; /* current local client_p being examined */
298 int ping = 0; /* ping time value from client */
90a3c35b 299 rb_dlink_node *ptr, *next_ptr;
212380e3 300
90a3c35b 301 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, list->head)
212380e3 302 {
303 client_p = ptr->data;
304
212380e3 305 if(!MyConnect(client_p) || IsDead(client_p))
306 continue;
307
e883cf07 308 ping = get_client_ping(client_p);
212380e3 309
9f6bbe3c 310 if(ping < (rb_current_time() - client_p->localClient->lasttime))
212380e3 311 {
312 /*
313 * If the client/server hasnt talked to us in 2*ping seconds
314 * and it has a ping time, then close its connection.
315 */
9f6bbe3c 316 if(((rb_current_time() - client_p->localClient->lasttime) >= (2 * ping)
212380e3 317 && (client_p->flags & FLAGS_PINGSENT)))
318 {
e883cf07 319 if(IsServer(client_p))
212380e3 320 {
e883cf07 321 sendto_realops_snomask(SNO_GENERAL, L_ALL,
212380e3 322 "No response from %s, closing link",
323 get_server_name(client_p, HIDE_IP));
324 ilog(L_SERVER,
325 "No response from %s, closing link",
326 log_client_name(client_p, HIDE_IP));
327 }
38e6acdd 328 (void) rb_snprintf(scratch, sizeof(scratch),
212380e3 329 "Ping timeout: %d seconds",
9f6bbe3c 330 (int) (rb_current_time() - client_p->localClient->lasttime));
212380e3 331
332 exit_client(client_p, client_p, &me, scratch);
333 continue;
334 }
335 else if((client_p->flags & FLAGS_PINGSENT) == 0)
336 {
337 /*
338 * if we havent PINGed the connection and we havent
339 * heard from it in a while, PING it to make sure
340 * it is still alive.
341 */
342 client_p->flags |= FLAGS_PINGSENT;
343 /* not nice but does the job */
9f6bbe3c 344 client_p->localClient->lasttime = rb_current_time() - ping;
212380e3 345 sendto_one(client_p, "PING :%s", me.name);
346 }
347 }
348 /* ping_timeout: */
349
350 }
351}
352
353/*
354 * check_unknowns_list
355 *
356 * inputs - pointer to list of unknown clients
357 * output - NONE
358 * side effects - unknown clients get marked for termination after n seconds
359 */
360static void
af81d5a0 361check_unknowns_list(rb_dlink_list * list)
212380e3 362{
90a3c35b 363 rb_dlink_node *ptr, *next_ptr;
212380e3 364 struct Client *client_p;
16d59a0d 365 int timeout;
212380e3 366
90a3c35b 367 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, list->head)
212380e3 368 {
369 client_p = ptr->data;
370
371 if(IsDead(client_p) || IsClosing(client_p))
372 continue;
373
374 /*
375 * Check UNKNOWN connections - if they have been in this state
376 * for > 30s, close them.
377 */
378
16d59a0d 379 timeout = IsAnyServer(client_p) ? ConfigFileEntry.connect_timeout : 30;
9f6bbe3c 380 if((rb_current_time() - client_p->localClient->firsttime) > timeout)
16d59a0d
JT
381 {
382 if(IsAnyServer(client_p))
383 {
384 sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) ? L_NETWIDE : L_ALL,
385 "No response from %s, closing link",
386 get_server_name(client_p, HIDE_IP));
387 ilog(L_SERVER,
388 "No response from %s, closing link",
389 log_client_name(client_p, HIDE_IP));
390 }
212380e3 391 exit_client(client_p, client_p, &me, "Connection timed out");
16d59a0d 392 }
212380e3 393 }
394}
395
396static void
397notify_banned_client(struct Client *client_p, struct ConfItem *aconf, int ban)
398{
399 static const char conn_closed[] = "Connection closed";
400 static const char d_lined[] = "D-lined";
401 static const char k_lined[] = "K-lined";
402 static const char g_lined[] = "G-lined";
403 const char *reason = NULL;
404 const char *exit_reason = conn_closed;
405
406 if(ConfigFileEntry.kline_with_reason && !EmptyString(aconf->passwd))
407 {
408 reason = aconf->passwd;
409 exit_reason = aconf->passwd;
410 }
411 else
412 {
413 switch (aconf->status)
414 {
415 case D_LINED:
416 reason = d_lined;
417 break;
418 case G_LINED:
419 reason = g_lined;
420 break;
421 default:
422 reason = k_lined;
423 break;
424 }
425 }
426
427 if(ban == D_LINED && !IsPerson(client_p))
428 sendto_one(client_p, "NOTICE DLINE :*** You have been D-lined");
429 else
430 sendto_one(client_p, form_str(ERR_YOUREBANNEDCREEP),
431 me.name, client_p->name, reason);
432
433 exit_client(client_p, client_p, &me,
434 EmptyString(ConfigFileEntry.kline_reason) ? exit_reason :
435 ConfigFileEntry.kline_reason);
436}
437
438/*
439 * check_banned_lines
440 * inputs - NONE
441 * output - NONE
442 * side effects - Check all connections for a pending k/d/gline against the
443 * client, exit the client if found.
444 */
445void
446check_banned_lines(void)
447{
448 struct Client *client_p; /* current local client_p being examined */
449 struct ConfItem *aconf = NULL;
90a3c35b 450 rb_dlink_node *ptr, *next_ptr;
212380e3 451
90a3c35b 452 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, lclient_list.head)
212380e3 453 {
454 client_p = ptr->data;
455
456 if(IsMe(client_p))
457 continue;
458
459 /* if there is a returned struct ConfItem then kill it */
21c9d815 460 if((aconf = find_dline((struct sockaddr *)&client_p->localClient->ip, client_p->localClient->ip.ss_family)))
212380e3 461 {
462 if(aconf->status & CONF_EXEMPTDLINE)
463 continue;
464
465 sendto_realops_snomask(SNO_GENERAL, L_ALL,
466 "DLINE active for %s",
467 get_client_name(client_p, HIDE_IP));
468
469 notify_banned_client(client_p, aconf, D_LINED);
470 continue; /* and go examine next fd/client_p */
471 }
472
473 if(!IsPerson(client_p))
474 continue;
475
476 if((aconf = find_kline(client_p)) != NULL)
477 {
478 if(IsExemptKline(client_p))
479 {
480 sendto_realops_snomask(SNO_GENERAL, L_ALL,
481 "KLINE over-ruled for %s, client is kline_exempt [%s@%s]",
482 get_client_name(client_p, HIDE_IP),
483 aconf->user, aconf->host);
484 continue;
485 }
486
487 sendto_realops_snomask(SNO_GENERAL, L_ALL,
488 "KLINE active for %s",
489 get_client_name(client_p, HIDE_IP));
490 notify_banned_client(client_p, aconf, K_LINED);
491 continue;
492 }
493 else if((aconf = find_gline(client_p)) != NULL)
494 {
495 if(IsExemptKline(client_p))
496 {
497 sendto_realops_snomask(SNO_GENERAL, L_ALL,
498 "GLINE over-ruled for %s, client is kline_exempt [%s@%s]",
499 get_client_name(client_p, HIDE_IP),
500 aconf->user, aconf->host);
501 continue;
502 }
503
504 if(IsExemptGline(client_p))
505 {
506 sendto_realops_snomask(SNO_GENERAL, L_ALL,
507 "GLINE over-ruled for %s, client is gline_exempt [%s@%s]",
508 get_client_name(client_p, HIDE_IP),
509 aconf->user, aconf->host);
510 continue;
511 }
512
513 sendto_realops_snomask(SNO_GENERAL, L_ALL,
514 "GLINE active for %s",
515 get_client_name(client_p, HIDE_IP));
516
517 notify_banned_client(client_p, aconf, G_LINED);
518 continue;
519 }
520 else if((aconf = find_xline(client_p->info, 1)) != NULL)
521 {
522 if(IsExemptKline(client_p))
523 {
524 sendto_realops_snomask(SNO_GENERAL, L_ALL,
525 "XLINE over-ruled for %s, client is kline_exempt [%s]",
526 get_client_name(client_p, HIDE_IP),
527 aconf->name);
528 continue;
529 }
530
531 sendto_realops_snomask(SNO_GENERAL, L_ALL, "XLINE active for %s",
532 get_client_name(client_p, HIDE_IP));
533
534 (void) exit_client(client_p, client_p, &me, "Bad user info");
535 continue;
536 }
537 }
538
539 /* also check the unknowns list for new dlines */
90a3c35b 540 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, unknown_list.head)
212380e3 541 {
542 client_p = ptr->data;
543
21c9d815 544 if((aconf = find_dline((struct sockaddr *)&client_p->localClient->ip,client_p->localClient->ip.ss_family)))
212380e3 545 {
546 if(aconf->status & CONF_EXEMPTDLINE)
547 continue;
548
549 notify_banned_client(client_p, aconf, D_LINED);
550 }
551 }
552
553}
554
555/* check_klines_event()
556 *
557 * inputs -
558 * outputs -
559 * side effects - check_klines() is called, kline_queued unset
560 */
561void
562check_klines_event(void *unused)
563{
564 kline_queued = 0;
565 check_klines();
566}
567
568/* check_klines
569 *
570 * inputs -
571 * outputs -
572 * side effects - all clients will be checked for klines
573 */
574void
575check_klines(void)
576{
577 struct Client *client_p;
578 struct ConfItem *aconf;
af81d5a0 579 rb_dlink_node *ptr;
90a3c35b 580 rb_dlink_node *next_ptr;
212380e3 581
90a3c35b 582 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, lclient_list.head)
212380e3 583 {
584 client_p = ptr->data;
585
586 if(IsMe(client_p) || !IsPerson(client_p))
587 continue;
588
589 if((aconf = find_kline(client_p)) != NULL)
590 {
591 if(IsExemptKline(client_p))
592 {
593 sendto_realops_snomask(SNO_GENERAL, L_ALL,
594 "KLINE over-ruled for %s, client is kline_exempt",
595 get_client_name(client_p, HIDE_IP));
596 continue;
597 }
598
599 sendto_realops_snomask(SNO_GENERAL, L_ALL,
600 "KLINE active for %s",
601 get_client_name(client_p, HIDE_IP));
602
603 notify_banned_client(client_p, aconf, K_LINED);
604 continue;
605 }
606 }
607}
608
609/* check_glines()
610 *
611 * inputs -
612 * outputs -
613 * side effects - all clients will be checked for glines
614 */
615void
616check_glines(void)
617{
618 struct Client *client_p;
619 struct ConfItem *aconf;
af81d5a0 620 rb_dlink_node *ptr;
90a3c35b 621 rb_dlink_node *next_ptr;
212380e3 622
90a3c35b 623 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, lclient_list.head)
212380e3 624 {
625 client_p = ptr->data;
626
627 if(IsMe(client_p) || !IsPerson(client_p))
628 continue;
629
630 if((aconf = find_gline(client_p)) != NULL)
631 {
632 if(IsExemptKline(client_p))
633 {
634 sendto_realops_snomask(SNO_GENERAL, L_ALL,
635 "GLINE over-ruled for %s, client is kline_exempt",
636 get_client_name(client_p, HIDE_IP));
637 continue;
638 }
639
640 if(IsExemptGline(client_p))
641 {
642 sendto_realops_snomask(SNO_GENERAL, L_ALL,
643 "GLINE over-ruled for %s, client is gline_exempt",
644 get_client_name(client_p, HIDE_IP));
645 continue;
646 }
647
648 sendto_realops_snomask(SNO_GENERAL, L_ALL,
649 "GLINE active for %s",
650 get_client_name(client_p, HIDE_IP));
651
652 notify_banned_client(client_p, aconf, K_LINED);
653 continue;
654 }
655 }
656}
657
658/* check_dlines()
659 *
660 * inputs -
661 * outputs -
662 * side effects - all clients will be checked for dlines
663 */
664void
665check_dlines(void)
666{
667 struct Client *client_p;
668 struct ConfItem *aconf;
af81d5a0 669 rb_dlink_node *ptr;
90a3c35b 670 rb_dlink_node *next_ptr;
212380e3 671
90a3c35b 672 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, lclient_list.head)
212380e3 673 {
674 client_p = ptr->data;
675
676 if(IsMe(client_p))
677 continue;
678
21c9d815 679 if((aconf = find_dline((struct sockaddr *)&client_p->localClient->ip,client_p->localClient->ip.ss_family)) != NULL)
212380e3 680 {
681 if(aconf->status & CONF_EXEMPTDLINE)
682 continue;
683
684 sendto_realops_snomask(SNO_GENERAL, L_ALL,
685 "DLINE active for %s",
686 get_client_name(client_p, HIDE_IP));
687
688 notify_banned_client(client_p, aconf, D_LINED);
689 continue;
690 }
691 }
692
693 /* dlines need to be checked against unknowns too */
90a3c35b 694 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, unknown_list.head)
212380e3 695 {
696 client_p = ptr->data;
697
21c9d815 698 if((aconf = find_dline((struct sockaddr *)&client_p->localClient->ip,client_p->localClient->ip.ss_family)) != NULL)
212380e3 699 {
700 if(aconf->status & CONF_EXEMPTDLINE)
701 continue;
702
703 notify_banned_client(client_p, aconf, D_LINED);
704 }
705 }
706}
707
708/* check_xlines
709 *
710 * inputs -
711 * outputs -
712 * side effects - all clients will be checked for xlines
713 */
714void
715check_xlines(void)
716{
717 struct Client *client_p;
718 struct ConfItem *aconf;
af81d5a0 719 rb_dlink_node *ptr;
90a3c35b 720 rb_dlink_node *next_ptr;
212380e3 721
90a3c35b 722 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, lclient_list.head)
212380e3 723 {
724 client_p = ptr->data;
725
726 if(IsMe(client_p) || !IsPerson(client_p))
727 continue;
728
729 if((aconf = find_xline(client_p->info, 1)) != NULL)
730 {
731 if(IsExemptKline(client_p))
732 {
733 sendto_realops_snomask(SNO_GENERAL, L_ALL,
734 "XLINE over-ruled for %s, client is kline_exempt",
735 get_client_name(client_p, HIDE_IP));
736 continue;
737 }
738
739 sendto_realops_snomask(SNO_GENERAL, L_ALL, "XLINE active for %s",
740 get_client_name(client_p, HIDE_IP));
741
742 (void) exit_client(client_p, client_p, &me, "Bad user info");
743 continue;
744 }
745 }
746}
747
748/*
749 * update_client_exit_stats
750 *
751 * input - pointer to client
752 * output - NONE
753 * side effects -
754 */
755static void
756update_client_exit_stats(struct Client *client_p)
757{
758 if(IsServer(client_p))
759 {
760 sendto_realops_snomask(SNO_EXTERNAL, L_ALL,
761 "Server %s split from %s",
762 client_p->name, client_p->servptr->name);
763 if(HasSentEob(client_p))
764 eob_count--;
765 }
766 else if(IsClient(client_p))
767 {
768 --Count.total;
769 if(IsOper(client_p))
770 --Count.oper;
771 if(IsInvisible(client_p))
772 --Count.invisi;
773 }
774
775 if(splitchecking && !splitmode)
776 check_splitmode(NULL);
777}
778
779/*
780 * release_client_state
781 *
782 * input - pointer to client to release
783 * output - NONE
784 * side effects -
785 */
786static void
787release_client_state(struct Client *client_p)
788{
789 if(client_p->user != NULL)
790 {
791 free_user(client_p->user, client_p); /* try this here */
792 }
793 if(client_p->serv)
794 {
795 if(client_p->serv->user != NULL)
796 free_user(client_p->serv->user, client_p);
797 if(client_p->serv->fullcaps)
90a3c35b
VY
798 rb_free(client_p->serv->fullcaps);
799 rb_free(client_p->serv);
212380e3 800 }
801}
802
803/*
804 * remove_client_from_list
805 * inputs - point to client to remove
806 * output - NONE
807 * side effects - taken the code from ExitOneClient() for this
808 * and placed it here. - avalon
809 */
810static void
811remove_client_from_list(struct Client *client_p)
812{
813 s_assert(NULL != client_p);
814
815 if(client_p == NULL)
816 return;
817
818 /* A client made with make_client()
819 * is on the unknown_list until removed.
820 * If it =does= happen to exit before its removed from that list
821 * and its =not= on the global_client_list, it will core here.
822 * short circuit that case now -db
823 */
824 if(client_p->node.prev == NULL && client_p->node.next == NULL)
825 return;
826
af81d5a0 827 rb_dlinkDelete(&client_p->node, &global_client_list);
212380e3 828
829 update_client_exit_stats(client_p);
830}
831
832
833/*
834 * find_person - find person by (nick)name.
835 * inputs - pointer to name
836 * output - return client pointer
837 * side effects -
838 */
839struct Client *
840find_person(const char *name)
841{
842 struct Client *c2ptr;
843
844 c2ptr = find_client(name);
845
846 if(c2ptr && IsPerson(c2ptr))
847 return (c2ptr);
848 return (NULL);
849}
850
851struct Client *
852find_named_person(const char *name)
853{
854 struct Client *c2ptr;
855
856 c2ptr = find_named_client(name);
857
858 if(c2ptr && IsPerson(c2ptr))
859 return (c2ptr);
860 return (NULL);
861}
862
863
864/*
865 * find_chasing - find the client structure for a nick name (user)
866 * using history mechanism if necessary. If the client is not found,
867 * an error message (NO SUCH NICK) is generated. If the client was found
868 * through the history, chasing will be 1 and otherwise 0.
869 */
870struct Client *
871find_chasing(struct Client *source_p, const char *user, int *chasing)
872{
873 struct Client *who;
874
875 if(MyClient(source_p))
876 who = find_named_person(user);
877 else
878 who = find_person(user);
879
880 if(chasing)
881 *chasing = 0;
882
883 if(who || IsDigit(*user))
884 return who;
885
886 if(!(who = get_history(user, (long) KILLCHASETIMELIMIT)))
887 {
888 sendto_one_numeric(source_p, ERR_NOSUCHNICK,
889 form_str(ERR_NOSUCHNICK), user);
890 return (NULL);
891 }
892 if(chasing)
893 *chasing = 1;
894 return who;
895}
896
897/*
898 * get_client_name - Return the name of the client
899 * for various tracking and
900 * admin purposes. The main purpose of this function is to
901 * return the "socket host" name of the client, if that
902 * differs from the advertised name (other than case).
903 * But, this can be used to any client structure.
904 *
905 * NOTE 1:
906 * Watch out the allocation of "nbuf", if either source_p->name
907 * or source_p->sockhost gets changed into pointers instead of
908 * directly allocated within the structure...
909 *
910 * NOTE 2:
911 * Function return either a pointer to the structure (source_p) or
912 * to internal buffer (nbuf). *NEVER* use the returned pointer
913 * to modify what it points!!!
914 */
915
916const char *
917get_client_name(struct Client *client, int showip)
918{
919 static char nbuf[HOSTLEN * 2 + USERLEN + 5];
920
921 s_assert(NULL != client);
922 if(client == NULL)
923 return NULL;
924
925 if(MyConnect(client))
926 {
927 if(!irccmp(client->name, client->host))
928 return client->name;
929
930 if(ConfigFileEntry.hide_spoof_ips &&
931 showip == SHOW_IP && IsIPSpoof(client))
932 showip = MASK_IP;
933#ifdef HIDE_SERVERS_IPS
934 if(IsAnyServer(client))
935 showip = MASK_IP;
936#endif
937
938 /* And finally, let's get the host information, ip or name */
939 switch (showip)
940 {
941 case SHOW_IP:
38e6acdd 942 rb_snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]",
212380e3 943 client->name, client->username,
944 client->sockhost);
945 break;
946 case MASK_IP:
38e6acdd 947 rb_snprintf(nbuf, sizeof(nbuf), "%s[%s@255.255.255.255]",
212380e3 948 client->name, client->username);
949 break;
950 default:
38e6acdd 951 rb_snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]",
212380e3 952 client->name, client->username, client->host);
953 }
954 return nbuf;
955 }
956
957 /* As pointed out by Adel Mezibra
958 * Neph|l|m@EFnet. Was missing a return here.
959 */
960 return client->name;
961}
962
963const char *
964get_server_name(struct Client *target_p, int showip)
965{
966 static char nbuf[HOSTLEN * 2 + USERLEN + 5];
967
968 if(target_p == NULL)
969 return NULL;
970
971 if(!MyConnect(target_p) || !irccmp(target_p->name, target_p->host))
972 return target_p->name;
973
974#ifdef HIDE_SERVERS_IPS
975 if(EmptyString(target_p->name))
976 {
38e6acdd 977 rb_snprintf(nbuf, sizeof(nbuf), "[%s@255.255.255.255]",
212380e3 978 target_p->username);
979 return nbuf;
980 }
981 else
982 return target_p->name;
983#endif
984
985 switch (showip)
986 {
987 case SHOW_IP:
38e6acdd 988 rb_snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]",
212380e3 989 target_p->name, target_p->username,
990 target_p->sockhost);
991 break;
992
993 case MASK_IP:
38e6acdd 994 rb_snprintf(nbuf, sizeof(nbuf), "%s[%s@255.255.255.255]",
212380e3 995 target_p->name, target_p->username);
996
997 default:
38e6acdd 998 rb_snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]",
212380e3 999 target_p->name, target_p->username,
1000 target_p->host);
1001 }
1002
1003 return nbuf;
1004}
1005
1006/* log_client_name()
1007 *
1008 * This version is the same as get_client_name, but doesnt contain the
1009 * code that will hide IPs always. This should be used for logfiles.
1010 */
1011const char *
1012log_client_name(struct Client *target_p, int showip)
1013{
1014 static char nbuf[HOSTLEN * 2 + USERLEN + 5];
1015
1016 if(target_p == NULL)
1017 return NULL;
1018
1019 if(MyConnect(target_p))
1020 {
1021 if(irccmp(target_p->name, target_p->host) == 0)
1022 return target_p->name;
1023
1024 switch (showip)
1025 {
1026 case SHOW_IP:
38e6acdd 1027 rb_snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]", target_p->name,
212380e3 1028 target_p->username, target_p->sockhost);
1029 break;
1030
1031 case MASK_IP:
38e6acdd 1032 rb_snprintf(nbuf, sizeof(nbuf), "%s[%s@255.255.255.255]",
212380e3 1033 target_p->name, target_p->username);
1034
1035 default:
38e6acdd 1036 rb_snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]", target_p->name,
212380e3 1037 target_p->username, target_p->host);
1038 }
1039
1040 return nbuf;
1041 }
1042
1043 return target_p->name;
1044}
1045
1046/* is_remote_connect - Returns whether a server was /connect'ed by a remote
1047 * oper (send notices netwide) */
1048int
1049is_remote_connect(struct Client *client_p)
1050{
1051 struct Client *oper;
1052
1053 if (client_p->serv == NULL)
1054 return FALSE;
1055 oper = find_named_person(client_p->serv->by);
1056 return oper != NULL && IsOper(oper) && !MyConnect(oper);
1057}
1058
1059static void
1060free_exited_clients(void *unused)
1061{
af81d5a0 1062 rb_dlink_node *ptr, *next;
212380e3 1063 struct Client *target_p;
1064
8e69bb4e 1065 RB_DLINK_FOREACH_SAFE(ptr, next, dead_list.head)
212380e3 1066 {
1067 target_p = ptr->data;
1068
1069#ifdef DEBUG_EXITED_CLIENTS
1070 {
1071 struct abort_client *abt;
af81d5a0 1072 rb_dlink_node *aptr;
212380e3 1073 int found = 0;
1074
8e69bb4e 1075 RB_DLINK_FOREACH(aptr, abort_list.head)
212380e3 1076 {
1077 abt = aptr->data;
1078 if(abt->client == target_p)
1079 {
1080 s_assert(0);
1081 sendto_realops_snomask(SNO_GENERAL, L_ALL,
1082 "On abort_list: %s stat: %u flags: %u/%u handler: %c",
1083 target_p->name, (unsigned int) target_p->status,
1084 target_p->flags, target_p->flags2, target_p->handler);
1085 sendto_realops_snomask(SNO_GENERAL, L_ALL,
f80a1823 1086 "Please report this to the charybdis developers!");
212380e3 1087 found++;
1088 }
1089 }
1090
1091 if(found)
1092 {
af81d5a0 1093 rb_dlinkDestroy(ptr, &dead_list);
212380e3 1094 continue;
1095 }
1096 }
1097#endif
1098
1099 if(ptr->data == NULL)
1100 {
1101 sendto_realops_snomask(SNO_GENERAL, L_ALL,
1102 "Warning: null client on dead_list!");
af81d5a0 1103 rb_dlinkDestroy(ptr, &dead_list);
212380e3 1104 continue;
1105 }
1106 release_client_state(target_p);
1107 free_client(target_p);
af81d5a0 1108 rb_dlinkDestroy(ptr, &dead_list);
212380e3 1109 }
1110
1111#ifdef DEBUG_EXITED_CLIENTS
8e69bb4e 1112 RB_DLINK_FOREACH_SAFE(ptr, next, dead_remote_list.head)
212380e3 1113 {
1114 target_p = ptr->data;
1115
1116 if(ptr->data == NULL)
1117 {
1118 sendto_realops_snomask(SNO_GENERAL, L_ALL,
1119 "Warning: null client on dead_list!");
af81d5a0 1120 rb_dlinkDestroy(ptr, &dead_list);
212380e3 1121 continue;
1122 }
1123 release_client_state(target_p);
1124 free_client(target_p);
af81d5a0 1125 rb_dlinkDestroy(ptr, &dead_remote_list);
212380e3 1126 }
1127#endif
1128
1129}
1130
1131/*
1132** Recursively send QUITs and SQUITs for source_p and all its dependent clients
1133** and servers to those servers that need them. A server needs the client
1134** QUITs if it can't figure them out from the SQUIT (ie pre-TS4) or if it
1135** isn't getting the SQUIT because of @#(*&@)# hostmasking. With TS4, once
1136** a link gets a SQUIT, it doesn't need any QUIT/SQUITs for clients depending
1137** on that one -orabidoo
1138*/
1139static void
1140recurse_send_quits(struct Client *client_p, struct Client *source_p,
1141 struct Client *to, const char *comment1,
1142 const char *comment)
1143{
1144 struct Client *target_p;
af81d5a0 1145 rb_dlink_node *ptr, *ptr_next;
212380e3 1146 /* If this server can handle quit storm (QS) removal
1147 * of dependents, just send the SQUIT
1148 */
1149
1150 if(IsCapable(to, CAP_QS))
1151 {
1152 sendto_one(to, "SQUIT %s :%s",
1153 get_id(source_p, to), comment);
1154 }
1155 else
1156 {
8e69bb4e 1157 RB_DLINK_FOREACH_SAFE(ptr, ptr_next, source_p->serv->users.head)
212380e3 1158 {
1159 target_p = ptr->data;
1160 sendto_one(to, ":%s QUIT :%s", target_p->name, comment1);
1161 }
8e69bb4e 1162 RB_DLINK_FOREACH_SAFE(ptr, ptr_next, source_p->serv->servers.head)
212380e3 1163 {
1164 target_p = ptr->data;
1165 recurse_send_quits(client_p, target_p, to, comment1, comment);
1166 }
1167 sendto_one(to, "SQUIT %s :%s", source_p->name, comment);
1168 }
1169}
1170
1171/*
1172** Remove all clients that depend on source_p; assumes all (S)QUITs have
1173** already been sent. we make sure to exit a server's dependent clients
1174** and servers before the server itself; exit_one_client takes care of
1175** actually removing things off llists. tweaked from +CSr31 -orabidoo
1176*/
1177/*
1178 * added sanity test code.... source_p->serv might be NULL...
1179 */
1180static void
1181recurse_remove_clients(struct Client *source_p, const char *comment)
1182{
1183 struct Client *target_p;
af81d5a0 1184 rb_dlink_node *ptr, *ptr_next;
212380e3 1185
1186 if(IsMe(source_p))
1187 return;
1188
1189 if(source_p->serv == NULL) /* oooops. uh this is actually a major bug */
1190 return;
1191
1192 /* this is very ugly, but it saves cpu :P */
1193 if(ConfigFileEntry.nick_delay > 0)
1194 {
8e69bb4e 1195 RB_DLINK_FOREACH_SAFE(ptr, ptr_next, source_p->serv->users.head)
212380e3 1196 {
1197 target_p = ptr->data;
1198 target_p->flags |= FLAGS_KILLED;
1199 add_nd_entry(target_p->name);
1200
1201 if(!IsDead(target_p) && !IsClosing(target_p))
1202 exit_remote_client(NULL, target_p, &me, comment);
1203 }
1204 }
1205 else
1206 {
8e69bb4e 1207 RB_DLINK_FOREACH_SAFE(ptr, ptr_next, source_p->serv->users.head)
212380e3 1208 {
1209 target_p = ptr->data;
1210 target_p->flags |= FLAGS_KILLED;
1211
1212 if(!IsDead(target_p) && !IsClosing(target_p))
1213 exit_remote_client(NULL, target_p, &me, comment);
1214 }
1215 }
1216
8e69bb4e 1217 RB_DLINK_FOREACH_SAFE(ptr, ptr_next, source_p->serv->servers.head)
212380e3 1218 {
1219 target_p = ptr->data;
1220 recurse_remove_clients(target_p, comment);
1221 qs_server(NULL, target_p, &me, comment);
1222 }
1223}
1224
1225/*
1226** Remove *everything* that depends on source_p, from all lists, and sending
1227** all necessary QUITs and SQUITs. source_p itself is still on the lists,
1228** and its SQUITs have been sent except for the upstream one -orabidoo
1229*/
1230static void
1231remove_dependents(struct Client *client_p,
1232 struct Client *source_p,
1233 struct Client *from, const char *comment, const char *comment1)
1234{
1235 struct Client *to;
af81d5a0 1236 rb_dlink_node *ptr, *next;
212380e3 1237
8e69bb4e 1238 RB_DLINK_FOREACH_SAFE(ptr, next, serv_list.head)
212380e3 1239 {
1240 to = ptr->data;
1241
1242 if(IsMe(to) || to == source_p->from ||
1243 (to == client_p && IsCapable(to, CAP_QS)))
1244 continue;
1245
1246 recurse_send_quits(client_p, source_p, to, comment1, comment);
1247 }
1248
1249 recurse_remove_clients(source_p, comment1);
1250}
1251
1252void
1253exit_aborted_clients(void *unused)
1254{
1255 struct abort_client *abt;
af81d5a0 1256 rb_dlink_node *ptr, *next;
8e69bb4e 1257 RB_DLINK_FOREACH_SAFE(ptr, next, abort_list.head)
212380e3 1258 {
1259 abt = ptr->data;
1260
1261#ifdef DEBUG_EXITED_CLIENTS
1262 {
af81d5a0 1263 if(rb_dlinkFind(abt->client, &dead_list))
212380e3 1264 {
1265 s_assert(0);
1266 sendto_realops_snomask(SNO_GENERAL, L_ALL,
1267 "On dead_list: %s stat: %u flags: %u/%u handler: %c",
1268 abt->client->name, (unsigned int) abt->client->status,
1269 abt->client->flags, abt->client->flags2, abt->client->handler);
1270 sendto_realops_snomask(SNO_GENERAL, L_ALL,
f80a1823 1271 "Please report this to the charybdis developers!");
212380e3 1272 continue;
1273 }
1274 }
1275#endif
1276
1277 s_assert(*((unsigned long*)abt->client) != 0xdeadbeef); /* This is lame but its a debug thing */
af81d5a0 1278 rb_dlinkDelete(ptr, &abort_list);
212380e3 1279
1280 if(IsAnyServer(abt->client))
1281 sendto_realops_snomask(SNO_GENERAL, L_ALL,
1282 "Closing link to %s: %s",
1283 get_server_name(abt->client, HIDE_IP), abt->notice);
1284
1285 /* its no longer on abort list - we *must* remove
1286 * FLAGS_CLOSING otherwise exit_client() will not run --fl
1287 */
1288 abt->client->flags &= ~FLAGS_CLOSING;
1289 exit_client(abt->client, abt->client, &me, abt->notice);
90a3c35b 1290 rb_free(abt);
212380e3 1291 }
1292}
1293
1294
1295/*
1296 * dead_link - Adds client to a list of clients that need an exit_client()
1297 *
1298 */
1299void
1300dead_link(struct Client *client_p)
1301{
1302 struct abort_client *abt;
1303
1304 s_assert(!IsMe(client_p));
1305 if(IsDead(client_p) || IsClosing(client_p) || IsMe(client_p))
1306 return;
1307
8e43b0b4 1308 abt = (struct abort_client *) rb_malloc(sizeof(struct abort_client));
212380e3 1309
1310 if(client_p->flags & FLAGS_SENDQEX)
1311 strlcpy(abt->notice, "Max SendQ exceeded", sizeof(abt->notice));
1312 else
38e6acdd 1313 rb_snprintf(abt->notice, sizeof(abt->notice), "Write error: %s", strerror(errno));
212380e3 1314
1315 abt->client = client_p;
1316 SetIOError(client_p);
1317 SetDead(client_p);
1318 SetClosing(client_p);
af81d5a0 1319 rb_dlinkAdd(abt, &abt->node, &abort_list);
212380e3 1320}
1321
1322
1323/* This does the remove of the user from channels..local or remote */
1324static inline void
1325exit_generic_client(struct Client *client_p, struct Client *source_p, struct Client *from,
1326 const char *comment)
1327{
90a3c35b 1328 rb_dlink_node *ptr, *next_ptr;
212380e3 1329
1330 if(IsOper(source_p))
af81d5a0 1331 rb_dlinkFindDestroy(source_p, &oper_list);
212380e3 1332
1333 sendto_common_channels_local(source_p, ":%s!%s@%s QUIT :%s",
1334 source_p->name,
1335 source_p->username, source_p->host, comment);
1336
1337 remove_user_from_channels(source_p);
1338
1339 /* Should not be in any channels now */
1340 s_assert(source_p->user->channel.head == NULL);
1341
1342 /* Clean up invitefield */
90a3c35b 1343 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, source_p->user->invited.head)
212380e3 1344 {
1345 del_invite(ptr->data, source_p);
1346 }
1347
1348 /* Clean up allow lists */
1349 del_all_accepts(source_p);
1350
1351 add_history(source_p, 0);
1352 off_history(source_p);
1353
1354 monitor_signoff(source_p);
1355
1356 if(has_id(source_p))
1357 del_from_id_hash(source_p->id, source_p);
1358
1359 del_from_hostname_hash(source_p->orighost, source_p);
1360 del_from_client_hash(source_p->name, source_p);
1361 remove_client_from_list(source_p);
1362}
1363
1364/*
1365 * Assumes IsPerson(source_p) && !MyConnect(source_p)
1366 */
1367
1368static int
1369exit_remote_client(struct Client *client_p, struct Client *source_p, struct Client *from,
1370 const char *comment)
1371{
1372 exit_generic_client(client_p, source_p, from, comment);
1373
1374 if(source_p->servptr && source_p->servptr->serv)
1375 {
af81d5a0 1376 rb_dlinkDelete(&source_p->lnode, &source_p->servptr->serv->users);
212380e3 1377 }
1378
1379 if((source_p->flags & FLAGS_KILLED) == 0)
1380 {
1381 sendto_server(client_p, NULL, CAP_TS6, NOCAPS,
1382 ":%s QUIT :%s", use_id(source_p), comment);
1383 sendto_server(client_p, NULL, NOCAPS, CAP_TS6,
1384 ":%s QUIT :%s", source_p->name, comment);
1385 }
1386
1387 SetDead(source_p);
1388#ifdef DEBUG_EXITED_CLIENTS
af81d5a0 1389 rb_dlinkAddAlloc(source_p, &dead_remote_list);
212380e3 1390#else
af81d5a0 1391 rb_dlinkAddAlloc(source_p, &dead_list);
212380e3 1392#endif
1393 return(CLIENT_EXITED);
1394}
1395
1396/*
1397 * This assumes IsUnknown(source_p) == TRUE and MyConnect(source_p) == TRUE
1398 */
1399
1400static int
1401exit_unknown_client(struct Client *client_p, struct Client *source_p, struct Client *from,
1402 const char *comment)
1403{
1404 delete_auth_queries(source_p);
21c9d815 1405 del_unknown_ip(source_p);
af81d5a0 1406 rb_dlinkDelete(&source_p->localClient->tnode, &unknown_list);
212380e3 1407
1408 if(!IsIOError(source_p))
dd12a19c 1409 sendto_one(source_p, "ERROR :Closing Link: %s (%s)",
1410 source_p->user != NULL ? source_p->host : "127.0.0.1",
1411 comment);
212380e3 1412
1413 close_connection(source_p);
1414
1415 if(has_id(source_p))
1416 del_from_id_hash(source_p->id, source_p);
1417
1418 del_from_hostname_hash(source_p->host, source_p);
1419 del_from_client_hash(source_p->name, source_p);
1420 remove_client_from_list(source_p);
212380e3 1421 SetDead(source_p);
af81d5a0 1422 rb_dlinkAddAlloc(source_p, &dead_list);
212380e3 1423
1424 /* Note that we don't need to add unknowns to the dead_list */
1425 return(CLIENT_EXITED);
1426}
1427
1428static int
1429exit_remote_server(struct Client *client_p, struct Client *source_p, struct Client *from,
1430 const char *comment)
1431{
1432 static char comment1[(HOSTLEN*2)+2];
1433 static char newcomment[BUFSIZE];
1434 struct Client *target_p;
1435
1436 if(ConfigServerHide.flatten_links)
1437 strcpy(comment1, "*.net *.split");
1438 else
1439 {
66c8fdd2 1440 strcpy(comment1, source_p->servptr->name);
212380e3 1441 strcat(comment1, " ");
1442 strcat(comment1, source_p->name);
1443 }
1444 if (IsPerson(from))
38e6acdd 1445 rb_snprintf(newcomment, sizeof(newcomment), "by %s: %s",
212380e3 1446 from->name, comment);
1447
1448 if(source_p->serv != NULL)
1449 remove_dependents(client_p, source_p, from, IsPerson(from) ? newcomment : comment, comment1);
1450
1451 if(source_p->servptr && source_p->servptr->serv)
af81d5a0 1452 rb_dlinkDelete(&source_p->lnode, &source_p->servptr->serv->servers);
212380e3 1453 else
1454 s_assert(0);
1455
af81d5a0 1456 rb_dlinkFindDestroy(source_p, &global_serv_list);
212380e3 1457 target_p = source_p->from;
1458
1459 if(target_p != NULL && IsServer(target_p) && target_p != client_p &&
1460 !IsMe(target_p) && (source_p->flags & FLAGS_KILLED) == 0)
1461 {
1462 sendto_one(target_p, ":%s SQUIT %s :%s",
1463 get_id(from, target_p), get_id(source_p, target_p),
1464 comment);
1465 }
1466
1467 if(has_id(source_p))
1468 del_from_id_hash(source_p->id, source_p);
1469
1470 del_from_client_hash(source_p->name, source_p);
1471 remove_client_from_list(source_p);
994544c2 1472 scache_split(source_p->serv->nameinfo);
212380e3 1473
1474 SetDead(source_p);
1475#ifdef DEBUG_EXITED_CLIENTS
af81d5a0 1476 rb_dlinkAddAlloc(source_p, &dead_remote_list);
212380e3 1477#else
af81d5a0 1478 rb_dlinkAddAlloc(source_p, &dead_list);
212380e3 1479#endif
1480 return 0;
1481}
1482
1483static int
1484qs_server(struct Client *client_p, struct Client *source_p, struct Client *from,
1485 const char *comment)
1486{
1487 struct Client *target_p;
1488
1489 if(source_p->servptr && source_p->servptr->serv)
af81d5a0 1490 rb_dlinkDelete(&source_p->lnode, &source_p->servptr->serv->servers);
212380e3 1491 else
1492 s_assert(0);
1493
af81d5a0 1494 rb_dlinkFindDestroy(source_p, &global_serv_list);
212380e3 1495 target_p = source_p->from;
1496
1497 if(has_id(source_p))
1498 del_from_id_hash(source_p->id, source_p);
1499
1500 del_from_client_hash(source_p->name, source_p);
1501 remove_client_from_list(source_p);
4f5ec033 1502 scache_split(source_p->serv->nameinfo);
212380e3 1503
1504 SetDead(source_p);
af81d5a0 1505 rb_dlinkAddAlloc(source_p, &dead_list);
212380e3 1506 return 0;
1507}
1508
1509static int
1510exit_local_server(struct Client *client_p, struct Client *source_p, struct Client *from,
1511 const char *comment)
1512{
1513 static char comment1[(HOSTLEN*2)+2];
1514 static char newcomment[BUFSIZE];
1515 unsigned int sendk, recvk;
1516
af81d5a0
WP
1517 rb_dlinkDelete(&source_p->localClient->tnode, &serv_list);
1518 rb_dlinkFindDestroy(source_p, &global_serv_list);
212380e3 1519
1520 unset_chcap_usage_counts(source_p);
1521 sendk = source_p->localClient->sendK;
1522 recvk = source_p->localClient->receiveK;
1523
1524 /* Always show source here, so the server notices show
1525 * which side initiated the split -- jilles
1526 */
38e6acdd 1527 rb_snprintf(newcomment, sizeof(newcomment), "by %s: %s",
212380e3 1528 from == source_p ? me.name : from->name, comment);
1529 if (!IsIOError(source_p))
1530 sendto_one(source_p, "SQUIT %s :%s", use_id(source_p),
1531 newcomment);
1532 if(client_p != NULL && source_p != client_p && !IsIOError(source_p))
1533 {
1534 sendto_one(source_p, "ERROR :Closing Link: 127.0.0.1 %s (%s)",
1535 source_p->name, comment);
1536 }
1537
212380e3 1538 if(source_p->servptr && source_p->servptr->serv)
af81d5a0 1539 rb_dlinkDelete(&source_p->lnode, &source_p->servptr->serv->servers);
212380e3 1540 else
1541 s_assert(0);
1542
1543
1544 close_connection(source_p);
1545
1546 if(ConfigServerHide.flatten_links)
1547 strcpy(comment1, "*.net *.split");
1548 else
1549 {
66c8fdd2 1550 strcpy(comment1, source_p->servptr->name);
212380e3 1551 strcat(comment1, " ");
1552 strcat(comment1, source_p->name);
1553 }
1554
1555 if(source_p->serv != NULL)
1556 remove_dependents(client_p, source_p, from, IsPerson(from) ? newcomment : comment, comment1);
1557
1558 sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s was connected"
1559 " for %ld seconds. %d/%d sendK/recvK.",
784fdac0 1560 source_p->name, (long) rb_current_time() - source_p->localClient->firsttime, sendk, recvk);
212380e3 1561
1562 ilog(L_SERVER, "%s was connected for %ld seconds. %d/%d sendK/recvK.",
784fdac0 1563 source_p->name, (long) rb_current_time() - source_p->localClient->firsttime, sendk, recvk);
212380e3 1564
1565 if(has_id(source_p))
1566 del_from_id_hash(source_p->id, source_p);
1567
1568 del_from_client_hash(source_p->name, source_p);
1569 remove_client_from_list(source_p);
994544c2 1570 scache_split(source_p->serv->nameinfo);
212380e3 1571
1572 SetDead(source_p);
af81d5a0 1573 rb_dlinkAddAlloc(source_p, &dead_list);
212380e3 1574 return 0;
1575}
1576
1577
1578/*
1579 * This assumes IsPerson(source_p) == TRUE && MyConnect(source_p) == TRUE
1580 */
1581
1582static int
1583exit_local_client(struct Client *client_p, struct Client *source_p, struct Client *from,
1584 const char *comment)
1585{
1586 unsigned long on_for;
1587
1588 exit_generic_client(client_p, source_p, from, comment);
1589 clear_monitor(source_p);
1590
1591 s_assert(IsPerson(source_p));
af81d5a0
WP
1592 rb_dlinkDelete(&source_p->localClient->tnode, &lclient_list);
1593 rb_dlinkDelete(&source_p->lnode, &me.serv->users);
212380e3 1594
1595 if(IsOper(source_p))
af81d5a0 1596 rb_dlinkFindDestroy(source_p, &local_oper_list);
212380e3 1597
1598 sendto_realops_snomask(SNO_CCONN, L_ALL,
1599 "Client exiting: %s (%s@%s) [%s] [%s]",
1600 source_p->name,
1601 source_p->username, source_p->host, comment,
1602 show_ip(NULL, source_p) ? source_p->sockhost : "255.255.255.255");
1603
1604 sendto_realops_snomask(SNO_CCONNEXT, L_ALL,
1605 "CLIEXIT %s %s %s %s 0 %s",
1606 source_p->name, source_p->username, source_p->host,
1607 show_ip(NULL, source_p) ? source_p->sockhost : "255.255.255.255",
1608 comment);
1609
9f6bbe3c 1610 on_for = rb_current_time() - source_p->localClient->firsttime;
212380e3 1611
1612 ilog(L_USER, "%s (%3lu:%02lu:%02lu): %s!%s@%s %d/%d",
9f6bbe3c 1613 myctime(rb_current_time()), on_for / 3600,
212380e3 1614 (on_for % 3600) / 60, on_for % 60,
1615 source_p->name, source_p->username, source_p->host,
1616 source_p->localClient->sendK, source_p->localClient->receiveK);
1617
1618 sendto_one(source_p, "ERROR :Closing Link: %s (%s)", source_p->host, comment);
1619 close_connection(source_p);
1620
1621 if((source_p->flags & FLAGS_KILLED) == 0)
1622 {
1623 sendto_server(client_p, NULL, CAP_TS6, NOCAPS,
1624 ":%s QUIT :%s", use_id(source_p), comment);
1625 sendto_server(client_p, NULL, NOCAPS, CAP_TS6,
1626 ":%s QUIT :%s", source_p->name, comment);
1627 }
1628
1629 SetDead(source_p);
af81d5a0 1630 rb_dlinkAddAlloc(source_p, &dead_list);
212380e3 1631 return(CLIENT_EXITED);
1632}
1633
1634
1635/*
1636** exit_client - This is old "m_bye". Name changed, because this is not a
1637** protocol function, but a general server utility function.
1638**
1639** This function exits a client of *any* type (user, server, etc)
1640** from this server. Also, this generates all necessary prototol
1641** messages that this exit may cause.
1642**
1643** 1) If the client is a local client, then this implicitly
1644** exits all other clients depending on this connection (e.g.
1645** remote clients having 'from'-field that points to this.
1646**
1647** 2) If the client is a remote client, then only this is exited.
1648**
1649** For convenience, this function returns a suitable value for
1650** m_function return value:
1651**
1652** CLIENT_EXITED if (client_p == source_p)
1653** 0 if (client_p != source_p)
1654*/
1655int
1656exit_client(struct Client *client_p, /* The local client originating the
1657 * exit or NULL, if this exit is
1658 * generated by this server for
1659 * internal reasons.
1660 * This will not get any of the
1661 * generated messages. */
1662 struct Client *source_p, /* Client exiting */
1663 struct Client *from, /* Client firing off this Exit,
1664 * never NULL! */
1665 const char *comment /* Reason for the exit */
1666 )
1667{
1668 hook_data_client_exit hdata;
1669 if(IsClosing(source_p))
1670 return -1;
1671
1672 /* note, this HAS to be here, when we exit a client we attempt to
1673 * send them data, if this generates a write error we must *not* add
1674 * them to the abort list --fl
1675 */
1676 SetClosing(source_p);
1677
1678 hdata.local_link = client_p;
1679 hdata.target = source_p;
1680 hdata.from = from;
1681 hdata.comment = comment;
1682 call_hook(h_client_exit, &hdata);
1683
1684 if(MyConnect(source_p))
1685 {
1686 /* Local clients of various types */
1687 if(IsPerson(source_p))
1688 return exit_local_client(client_p, source_p, from, comment);
1689 else if(IsServer(source_p))
1690 return exit_local_server(client_p, source_p, from, comment);
1691 /* IsUnknown || IsConnecting || IsHandShake */
1692 else if(!IsReject(source_p))
1693 return exit_unknown_client(client_p, source_p, from, comment);
1694 }
1695 else
1696 {
1697 /* Remotes */
1698 if(IsPerson(source_p))
1699 return exit_remote_client(client_p, source_p, from, comment);
1700 else if(IsServer(source_p))
1701 return exit_remote_server(client_p, source_p, from, comment);
1702 }
1703
1704 return -1;
1705}
1706
1707/*
1708 * Count up local client memory
1709 */
1710
1711/* XXX one common Client list now */
1712void
1713count_local_client_memory(size_t * count, size_t * local_client_memory_used)
1714{
ae4091d2
JT
1715 size_t lusage;
1716 rb_bh_usage(lclient_heap, count, NULL, &lusage, NULL);
784fdac0 1717 *local_client_memory_used = lusage + (*count * (sizeof(void *) + sizeof(struct Client)));
212380e3 1718}
1719
1720/*
1721 * Count up remote client memory
1722 */
1723void
1724count_remote_client_memory(size_t * count, size_t * remote_client_memory_used)
1725{
ae4091d2
JT
1726 size_t lcount, rcount;
1727 rb_bh_usage(lclient_heap, &lcount, NULL, NULL, NULL);
1728 rb_bh_usage(client_heap, &rcount, NULL, NULL, NULL);
1729 *count = rcount - lcount;
784fdac0 1730 *remote_client_memory_used = *count * (sizeof(void *) + sizeof(struct Client));
212380e3 1731}
1732
1733
1734/*
1735 * accept processing, this adds a form of "caller ID" to ircd
1736 *
1737 * If a client puts themselves into "caller ID only" mode,
1738 * only clients that match a client pointer they have put on
1739 * the accept list will be allowed to message them.
1740 *
1741 * [ source.on_allow_list ] -> [ target1 ] -> [ target2 ]
1742 *
1743 * [target.allow_list] -> [ source1 ] -> [source2 ]
1744 *
1745 * i.e. a target will have a link list of source pointers it will allow
1746 * each source client then has a back pointer pointing back
1747 * to the client that has it on its accept list.
1748 * This allows for exit_one_client to remove these now bogus entries
1749 * from any client having an accept on them.
1750 */
1751/*
1752 * del_all_accepts
1753 *
1754 * inputs - pointer to exiting client
1755 * output - NONE
1756 * side effects - Walk through given clients allow_list and on_allow_list
1757 * remove all references to this client
1758 */
1759void
1760del_all_accepts(struct Client *client_p)
1761{
af81d5a0 1762 rb_dlink_node *ptr;
90a3c35b 1763 rb_dlink_node *next_ptr;
212380e3 1764 struct Client *target_p;
1765
1766 if(MyClient(client_p) && client_p->localClient->allow_list.head)
1767 {
1768 /* clear this clients accept list, and remove them from
1769 * everyones on_accept_list
1770 */
90a3c35b 1771 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->localClient->allow_list.head)
212380e3 1772 {
1773 target_p = ptr->data;
af81d5a0
WP
1774 rb_dlinkFindDestroy(client_p, &target_p->on_allow_list);
1775 rb_dlinkDestroy(ptr, &client_p->localClient->allow_list);
212380e3 1776 }
1777 }
1778
1779 /* remove this client from everyones accept list */
90a3c35b 1780 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->on_allow_list.head)
212380e3 1781 {
1782 target_p = ptr->data;
af81d5a0
WP
1783 rb_dlinkFindDestroy(client_p, &target_p->localClient->allow_list);
1784 rb_dlinkDestroy(ptr, &client_p->on_allow_list);
212380e3 1785 }
1786}
1787
1788/*
1789 * show_ip() - asks if the true IP shoudl be shown when source is
1790 * askin for info about target
1791 *
1792 * Inputs - source_p who is asking
1793 * - target_p who do we want the info on
1794 * Output - returns 1 if clear IP can be showed, otherwise 0
1795 * Side Effects - none
1796 */
1797
1798int
1799show_ip(struct Client *source_p, struct Client *target_p)
1800{
1801 if(IsAnyServer(target_p))
1802 {
1803#ifndef HIDE_SERVERS_IPS
1804 if(source_p == NULL || IsOper(source_p))
1805 return 1;
1806#endif
1807 return 0;
1808 }
1809 else if(IsIPSpoof(target_p))
1810 {
1811 /* source == NULL indicates message is being sent
1812 * to local opers.
1813 */
1814 if(!ConfigFileEntry.hide_spoof_ips &&
1815 (source_p == NULL || MyOper(source_p)))
1816 return 1;
1817 return 0;
1818 }
1819 else if(IsDynSpoof(target_p) && (source_p != NULL && !IsOper(source_p)))
1820 return 0;
1821 else
1822 return 1;
1823}
1824
1825int
1826show_ip_conf(struct ConfItem *aconf, struct Client *source_p)
1827{
1828 if(IsConfDoSpoofIp(aconf))
1829 {
1830 if(!ConfigFileEntry.hide_spoof_ips && MyOper(source_p))
1831 return 1;
1832
1833 return 0;
1834 }
1835 else
1836 return 1;
1837}
1838
1839/*
1840 * initUser
1841 *
1842 * inputs - none
1843 * outputs - none
1844 *
1845 * side effects - Creates a block heap for struct Users
1846 *
1847 */
6e9b4415 1848static rb_bh *user_heap;
212380e3 1849void
1850initUser(void)
1851{
784fdac0 1852 user_heap = rb_bh_create(sizeof(struct User), USER_HEAP_SIZE, "user_heap");
212380e3 1853 if(!user_heap)
784fdac0 1854 rb_outofmemory();
212380e3 1855}
1856
1857/*
1858 * make_user
1859 *
1860 * inputs - pointer to client struct
1861 * output - pointer to struct User
1862 * side effects - add's an User information block to a client
1863 * if it was not previously allocated.
1864 */
1865struct User *
1866make_user(struct Client *client_p)
1867{
1868 struct User *user;
1869
1870 user = client_p->user;
1871 if(!user)
1872 {
6e9b4415 1873 user = (struct User *) rb_bh_alloc(user_heap);
212380e3 1874 user->refcnt = 1;
1875 client_p->user = user;
1876 }
1877 return user;
1878}
1879
1880/*
1881 * make_server
1882 *
1883 * inputs - pointer to client struct
1884 * output - pointer to server_t
1885 * side effects - add's an Server information block to a client
1886 * if it was not previously allocated.
1887 */
1888server_t *
1889make_server(struct Client *client_p)
1890{
1891 server_t *serv = client_p->serv;
1892
1893 if(!serv)
1894 {
8e43b0b4 1895 serv = (server_t *) rb_malloc(sizeof(server_t));
212380e3 1896 client_p->serv = serv;
1897 }
1898 return client_p->serv;
1899}
1900
1901/*
1902 * free_user
1903 *
1904 * inputs - pointer to user struct
1905 * - pointer to client struct
1906 * output - none
1907 * side effects - Decrease user reference count by one and release block,
1908 * if count reaches 0
1909 */
1910void
1911free_user(struct User *user, struct Client *client_p)
1912{
784fdac0
VY
1913 free_away(client_p);
1914
212380e3 1915 if(--user->refcnt <= 0)
1916 {
1917 if(user->away)
90a3c35b 1918 rb_free((char *) user->away);
212380e3 1919 /*
1920 * sanity check
1921 */
1922 if(user->refcnt < 0 || user->invited.head || user->channel.head)
1923 {
1924 sendto_realops_snomask(SNO_GENERAL, L_ALL,
1925 "* %#lx user (%s!%s@%s) %#lx %#lx %#lx %lu %d *",
1926 (unsigned long) client_p,
1927 client_p ? client_p->
1928 name : "<noname>",
1929 client_p->username,
1930 client_p->host,
1931 (unsigned long) user,
1932 (unsigned long) user->invited.head,
1933 (unsigned long) user->channel.head,
af81d5a0 1934 rb_dlink_list_length(&user->channel),
212380e3 1935 user->refcnt);
1936 s_assert(!user->refcnt);
1937 s_assert(!user->invited.head);
1938 s_assert(!user->channel.head);
1939 }
1940
6e9b4415 1941 rb_bh_free(user_heap, user);
212380e3 1942 }
1943}
1944
784fdac0
VY
1945void
1946allocate_away(struct Client *client_p)
1947{
1948 if(client_p->user->away == NULL)
1949 client_p->user->away = rb_bh_alloc(away_heap);
1950}
1951
1952
1953void
1954free_away(struct Client *client_p)
1955{
72b8a371 1956 if(client_p->user != NULL && client_p->user->away != NULL) {
784fdac0
VY
1957 rb_bh_free(away_heap, client_p->user->away);
1958 client_p->user->away = NULL;
1959 }
ece36b7b
VY
1960}
1961
212380e3 1962void
1963init_uid(void)
1964{
1965 int i;
1966
1967 for(i = 0; i < 3; i++)
1968 current_uid[i] = me.id[i];
1969
1970 for(i = 3; i < 9; i++)
1971 current_uid[i] = 'A';
1972
1973 current_uid[9] = '\0';
1974}
1975
1976
1977char *
1978generate_uid(void)
1979{
1980 int i;
1981
1982 for(i = 8; i > 3; i--)
1983 {
1984 if(current_uid[i] == 'Z')
1985 {
1986 current_uid[i] = '0';
1987 return current_uid;
1988 }
1989 else if(current_uid[i] != '9')
1990 {
1991 current_uid[i]++;
1992 return current_uid;
1993 }
1994 else
1995 current_uid[i] = 'A';
1996 }
1997
1998 /* if this next if() triggers, we're fucked. */
1999 if(current_uid[3] == 'Z')
2000 {
2001 current_uid[i] = 'A';
2002 s_assert(0);
2003 }
2004 else
2005 current_uid[i]++;
2006
2007 return current_uid;
2008}
2009
2010/*
2011 * close_connection
2012 * Close the physical connection. This function must make
2013 * MyConnect(client_p) == FALSE, and set client_p->from == NULL.
2014 */
2015void
2016close_connection(struct Client *client_p)
2017{
2018 s_assert(client_p != NULL);
2019 if(client_p == NULL)
2020 return;
2021
2022 s_assert(MyConnect(client_p));
2023 if(!MyConnect(client_p))
2024 return;
2025
2026 if(IsServer(client_p))
2027 {
2028 struct server_conf *server_p;
2029
83251205
VY
2030 ServerStats.is_sv++;
2031 ServerStats.is_sbs += client_p->localClient->sendB;
2032 ServerStats.is_sbr += client_p->localClient->receiveB;
2033 ServerStats.is_sks += client_p->localClient->sendK;
2034 ServerStats.is_skr += client_p->localClient->receiveK;
2035 ServerStats.is_sti += rb_current_time() - client_p->localClient->firsttime;
2036 if(ServerStats.is_sbs > 2047)
212380e3 2037 {
83251205
VY
2038 ServerStats.is_sks += (ServerStats.is_sbs >> 10);
2039 ServerStats.is_sbs &= 0x3ff;
212380e3 2040 }
83251205 2041 if(ServerStats.is_sbr > 2047)
212380e3 2042 {
83251205
VY
2043 ServerStats.is_skr += (ServerStats.is_sbr >> 10);
2044 ServerStats.is_sbr &= 0x3ff;
212380e3 2045 }
2046
2047 /*
2048 * If the connection has been up for a long amount of time, schedule
2049 * a 'quick' reconnect, else reset the next-connect cycle.
2050 */
2051 if((server_p = find_server_conf(client_p->name)) != NULL)
2052 {
2053 /*
2054 * Reschedule a faster reconnect, if this was a automatically
2055 * connected configuration entry. (Note that if we have had
2056 * a rehash in between, the status has been changed to
2057 * CONF_ILLEGAL). But only do this if it was a "good" link.
2058 */
2059 server_p->hold = time(NULL);
2060 server_p->hold +=
2061 (server_p->hold - client_p->localClient->lasttime >
2062 HANGONGOODLINK) ? HANGONRETRYDELAY : ConFreq(server_p->class);
2063 }
2064
2065 }
2066 else if(IsClient(client_p))
2067 {
83251205
VY
2068 ServerStats.is_cl++;
2069 ServerStats.is_cbs += client_p->localClient->sendB;
2070 ServerStats.is_cbr += client_p->localClient->receiveB;
2071 ServerStats.is_cks += client_p->localClient->sendK;
2072 ServerStats.is_ckr += client_p->localClient->receiveK;
2073 ServerStats.is_cti += rb_current_time() - client_p->localClient->firsttime;
2074 if(ServerStats.is_cbs > 2047)
212380e3 2075 {
83251205
VY
2076 ServerStats.is_cks += (ServerStats.is_cbs >> 10);
2077 ServerStats.is_cbs &= 0x3ff;
212380e3 2078 }
83251205 2079 if(ServerStats.is_cbr > 2047)
212380e3 2080 {
83251205
VY
2081 ServerStats.is_ckr += (ServerStats.is_cbr >> 10);
2082 ServerStats.is_cbr &= 0x3ff;
212380e3 2083 }
2084 }
2085 else
83251205 2086 ServerStats.is_ni++;
21c9d815
VY
2087
2088 if(client_p->localClient->F)
2089 {
2090 /* attempt to flush any pending dbufs. Evil, but .. -- adrian */
2091 if(!IsIOError(client_p))
2092 send_queued(client_p);
2093
2094 rb_close(client_p->localClient->F);
2095 client_p->localClient->F = NULL;
2096 }
2097
83b667df
JT
2098 if(client_p->localClient->ctrlF)
2099 {
2100 rb_close(client_p->localClient->ctrlF);
2101 client_p->localClient->ctrlF = NULL;
2102 }
2103
527ec911
JT
2104 rb_linebuf_donebuf(&client_p->localClient->buf_sendq);
2105 rb_linebuf_donebuf(&client_p->localClient->buf_recvq);
212380e3 2106 detach_conf(client_p);
2107
2108 /* XXX shouldnt really be done here. */
2109 detach_server_conf(client_p);
2110
2111 client_p->from = NULL; /* ...this should catch them! >:) --msa */
2112 ClearMyConnect(client_p);
2113 SetIOError(client_p);
2114}
2115
2116
2117
2118void
2119error_exit_client(struct Client *client_p, int error)
2120{
2121 /*
2122 * ...hmm, with non-blocking sockets we might get
2123 * here from quite valid reasons, although.. why
2124 * would select report "data available" when there
2125 * wasn't... so, this must be an error anyway... --msa
2126 * actually, EOF occurs when read() returns 0 and
2127 * in due course, select() returns that fd as ready
2128 * for reading even though it ends up being an EOF. -avalon
2129 */
2130 char errmsg[255];
527ec911 2131 int current_error = rb_get_sockerr(client_p->localClient->F);
212380e3 2132
2133 SetIOError(client_p);
2134
2135 if(IsServer(client_p) || IsHandshake(client_p))
2136 {
212380e3 2137 if(error == 0)
2138 {
2139 sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) && !IsServer(client_p) ? L_NETWIDE : L_ALL,
2140 "Server %s closed the connection",
2141 get_server_name(client_p, SHOW_IP));
2142
2143 ilog(L_SERVER, "Server %s closed the connection",
2144 log_client_name(client_p, SHOW_IP));
2145 }
2146 else
2147 {
2148 sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) && !IsServer(client_p) ? L_NETWIDE : L_ALL,
2149 "Lost connection to %s: %s",
2150 client_p->name, strerror(current_error));
2151 ilog(L_SERVER, "Lost connection to %s: %s",
2152 log_client_name(client_p, SHOW_IP), strerror(current_error));
2153 }
212380e3 2154 }
2155
2156 if(error == 0)
2157 strlcpy(errmsg, "Remote host closed the connection", sizeof(errmsg));
2158 else
38e6acdd 2159 rb_snprintf(errmsg, sizeof(errmsg), "Read error: %s", strerror(current_error));
212380e3 2160
2161 exit_client(client_p, client_p, &me, errmsg);
2162}