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