2 * charybdis: an advanced ircd.
3 * client.c: Controls clients.
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
8 * Copyright (C) 2007 William Pitcock
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.
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.
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
25 * $Id: client.c 3514 2007-06-06 16:25:21Z nenolod $
34 #include "irc_string.h"
35 #include "sprintf_irc.h"
42 #include "s_newconf.h"
55 #include "blacklist.h"
58 #include "irc_dictionary.h"
60 #define DEBUG_EXITED_CLIENTS
62 static void check_pings_list(rb_dlink_list
* list
);
63 static void check_unknowns_list(rb_dlink_list
* list
);
64 static void free_exited_clients(void *unused
);
65 static void exit_aborted_clients(void *unused
);
67 static int exit_remote_client(struct Client
*, struct Client
*, struct Client
*,const char *);
68 static int exit_remote_server(struct Client
*, struct Client
*, struct Client
*,const char *);
69 static int exit_local_client(struct Client
*, struct Client
*, struct Client
*,const char *);
70 static int exit_unknown_client(struct Client
*, struct Client
*, struct Client
*,const char *);
71 static int exit_local_server(struct Client
*, struct Client
*, struct Client
*,const char *);
72 static int qs_server(struct Client
*, struct Client
*, struct Client
*, const char *comment
);
74 static EVH check_pings
;
76 extern rb_bh
*client_heap
;
77 extern rb_bh
*lclient_heap
;
78 extern rb_bh
*pclient_heap
;
79 static rb_bh
*away_heap
= NULL
;
81 extern char current_uid
[IDLEN
];
83 struct Dictionary
*nd_dict
= NULL
;
92 rb_dlink_list dead_list
;
93 #ifdef DEBUG_EXITED_CLIENTS
94 static rb_dlink_list dead_remote_list
;
100 struct Client
*client
;
101 char notice
[REASONLEN
];
104 static rb_dlink_list abort_list
;
112 * side effects - initialize client free memory
118 * start off the check ping event .. -- adrian
119 * Every 30 seconds is plenty -- db
121 client_heap
= rb_bh_create(sizeof(struct Client
), CLIENT_HEAP_SIZE
, "client_heap");
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");
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);
130 nd_dict
= irc_dictionary_create(irccmp
);
135 * make_client - create a new Client struct and set it to initial state.
137 * from == NULL, create local client (a client connected
140 * from, create remote client (behind a socket
141 * associated with the client defined by
142 * 'from'). ('from' is a local client!!).
145 make_client(struct Client
*from
)
147 struct Client
*client_p
= NULL
;
148 struct LocalUser
*localClient
;
150 client_p
= rb_bh_alloc(client_heap
);
154 client_p
->from
= client_p
; /* 'from' of local client is self! */
156 localClient
= (struct LocalUser
*) rb_bh_alloc(lclient_heap
);
157 SetMyConnect(client_p
);
158 client_p
->localClient
= localClient
;
160 client_p
->localClient
->lasttime
= client_p
->localClient
->firsttime
= rb_current_time();
162 client_p
->localClient
->F
= NULL
;
163 client_p
->localClient
->ctrlfd
= -1;
165 client_p
->preClient
= (struct PreClient
*) rb_bh_alloc(pclient_heap
);
167 /* as good a place as any... */
168 rb_dlinkAdd(client_p
, &client_p
->localClient
->tnode
, &unknown_list
);
171 { /* from is not NULL */
172 client_p
->localClient
= NULL
;
173 client_p
->preClient
= NULL
;
174 client_p
->from
= from
; /* 'from' of local client is self! */
177 SetUnknown(client_p
);
178 strcpy(client_p
->username
, "unknown");
184 free_pre_client(struct Client
*client_p
)
186 struct Blacklist
*blptr
;
188 s_assert(NULL
!= client_p
);
190 if(client_p
->preClient
== NULL
)
193 blptr
= client_p
->preClient
->dnsbl_listed
;
195 unref_blacklist(blptr
);
196 abort_blacklist_queries(client_p
);
197 rb_bh_free(pclient_heap
, client_p
->preClient
);
198 client_p
->preClient
= NULL
;
202 free_local_client(struct Client
*client_p
)
204 s_assert(NULL
!= client_p
);
205 s_assert(&me
!= client_p
);
207 if(client_p
->localClient
== NULL
)
211 * clean up extra sockets from P-lines which have been discarded.
213 if(client_p
->localClient
->listener
)
215 s_assert(0 < client_p
->localClient
->listener
->ref_count
);
216 if(0 == --client_p
->localClient
->listener
->ref_count
217 && !client_p
->localClient
->listener
->active
)
218 free_listener(client_p
->localClient
->listener
);
219 client_p
->localClient
->listener
= 0;
222 if(client_p
->localClient
->F
)
223 rb_close(client_p
->localClient
->F
);
225 if(client_p
->localClient
->passwd
)
227 memset(client_p
->localClient
->passwd
, 0,
228 strlen(client_p
->localClient
->passwd
));
229 rb_free(client_p
->localClient
->passwd
);
232 rb_free(client_p
->localClient
->challenge
);
233 rb_free(client_p
->localClient
->fullcaps
);
234 rb_free(client_p
->localClient
->opername
);
235 rb_free(client_p
->localClient
->mangledhost
);
237 rb_bh_free(lclient_heap
, client_p
->localClient
);
238 client_p
->localClient
= NULL
;
242 free_client(struct Client
*client_p
)
244 s_assert(NULL
!= client_p
);
245 s_assert(&me
!= client_p
);
246 free_local_client(client_p
);
247 free_pre_client(client_p
);
248 rb_bh_free(client_heap
, client_p
);
252 * check_pings - go through the local client list and check activity
253 * kill off stuff that should die
255 * inputs - NOT USED (from event)
256 * output - next time_t when check_pings() should be called again
260 * A PING can be sent to clients as necessary.
262 * Client/Server ping outs are handled.
266 * Addon from adrian. We used to call this after nextping seconds,
267 * however I've changed it to run once a second. This is only for
268 * PING timeouts, not K/etc-line checks (thanks dianora!). Having it
269 * run once a second makes life a lot easier - when a new client connects
270 * and they need a ping in 4 seconds, if nextping was set to 20 seconds
271 * we end up waiting 20 seconds. This is stupid. :-)
272 * I will optimise (hah!) check_pings() once I've finished working on
273 * tidying up other network IO evilnesses.
278 check_pings(void *notused
)
280 check_pings_list(&lclient_list
);
281 check_pings_list(&serv_list
);
282 check_unknowns_list(&unknown_list
);
288 * inputs - pointer to list to check
293 check_pings_list(rb_dlink_list
* list
)
295 char scratch
[32]; /* way too generous but... */
296 struct Client
*client_p
; /* current local client_p being examined */
297 int ping
= 0; /* ping time value from client */
298 rb_dlink_node
*ptr
, *next_ptr
;
300 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, list
->head
)
302 client_p
= ptr
->data
;
304 if(!MyConnect(client_p
) || IsDead(client_p
))
307 ping
= get_client_ping(client_p
);
309 if(ping
< (rb_current_time() - client_p
->localClient
->lasttime
))
312 * If the client/server hasnt talked to us in 2*ping seconds
313 * and it has a ping time, then close its connection.
315 if(((rb_current_time() - client_p
->localClient
->lasttime
) >= (2 * ping
)
316 && (client_p
->flags
& FLAGS_PINGSENT
)))
318 if(IsServer(client_p
))
320 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
321 "No response from %s, closing link",
322 get_server_name(client_p
, HIDE_IP
));
324 "No response from %s, closing link",
325 log_client_name(client_p
, HIDE_IP
));
327 (void) rb_snprintf(scratch
, sizeof(scratch
),
328 "Ping timeout: %d seconds",
329 (int) (rb_current_time() - client_p
->localClient
->lasttime
));
331 exit_client(client_p
, client_p
, &me
, scratch
);
334 else if((client_p
->flags
& FLAGS_PINGSENT
) == 0)
337 * if we havent PINGed the connection and we havent
338 * heard from it in a while, PING it to make sure
341 client_p
->flags
|= FLAGS_PINGSENT
;
342 /* not nice but does the job */
343 client_p
->localClient
->lasttime
= rb_current_time() - ping
;
344 sendto_one(client_p
, "PING :%s", me
.name
);
353 * check_unknowns_list
355 * inputs - pointer to list of unknown clients
357 * side effects - unknown clients get marked for termination after n seconds
360 check_unknowns_list(rb_dlink_list
* list
)
362 rb_dlink_node
*ptr
, *next_ptr
;
363 struct Client
*client_p
;
366 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, list
->head
)
368 client_p
= ptr
->data
;
370 if(IsDead(client_p
) || IsClosing(client_p
))
374 * Check UNKNOWN connections - if they have been in this state
375 * for > 30s, close them.
378 timeout
= IsAnyServer(client_p
) ? ConfigFileEntry
.connect_timeout
: 30;
379 if((rb_current_time() - client_p
->localClient
->firsttime
) > timeout
)
381 if(IsAnyServer(client_p
))
383 sendto_realops_snomask(SNO_GENERAL
, is_remote_connect(client_p
) ? L_NETWIDE
: L_ALL
,
384 "No response from %s, closing link",
385 get_server_name(client_p
, HIDE_IP
));
387 "No response from %s, closing link",
388 log_client_name(client_p
, HIDE_IP
));
390 exit_client(client_p
, client_p
, &me
, "Connection timed out");
396 notify_banned_client(struct Client
*client_p
, struct ConfItem
*aconf
, int ban
)
398 static const char conn_closed
[] = "Connection closed";
399 static const char d_lined
[] = "D-lined";
400 static const char k_lined
[] = "K-lined";
401 static const char g_lined
[] = "G-lined";
402 const char *reason
= NULL
;
403 const char *exit_reason
= conn_closed
;
405 if(ConfigFileEntry
.kline_with_reason
&& !EmptyString(aconf
->passwd
))
407 reason
= aconf
->passwd
;
408 exit_reason
= aconf
->passwd
;
412 switch (aconf
->status
)
426 if(ban
== D_LINED
&& !IsPerson(client_p
))
427 sendto_one(client_p
, "NOTICE DLINE :*** You have been D-lined");
429 sendto_one(client_p
, form_str(ERR_YOUREBANNEDCREEP
),
430 me
.name
, client_p
->name
, reason
);
432 exit_client(client_p
, client_p
, &me
,
433 EmptyString(ConfigFileEntry
.kline_reason
) ? exit_reason
:
434 ConfigFileEntry
.kline_reason
);
441 * side effects - Check all connections for a pending k/d/gline against the
442 * client, exit the client if found.
445 check_banned_lines(void)
447 struct Client
*client_p
; /* current local client_p being examined */
448 struct ConfItem
*aconf
= NULL
;
449 rb_dlink_node
*ptr
, *next_ptr
;
451 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
453 client_p
= ptr
->data
;
458 /* if there is a returned struct ConfItem then kill it */
459 if((aconf
= find_dline((struct sockaddr
*)&client_p
->localClient
->ip
, client_p
->localClient
->ip
.ss_family
)))
461 if(aconf
->status
& CONF_EXEMPTDLINE
)
464 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
465 "DLINE active for %s",
466 get_client_name(client_p
, HIDE_IP
));
468 notify_banned_client(client_p
, aconf
, D_LINED
);
469 continue; /* and go examine next fd/client_p */
472 if(!IsPerson(client_p
))
475 if((aconf
= find_kline(client_p
)) != NULL
)
477 if(IsExemptKline(client_p
))
479 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
480 "KLINE over-ruled for %s, client is kline_exempt [%s@%s]",
481 get_client_name(client_p
, HIDE_IP
),
482 aconf
->user
, aconf
->host
);
486 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
487 "KLINE active for %s",
488 get_client_name(client_p
, HIDE_IP
));
489 notify_banned_client(client_p
, aconf
, K_LINED
);
492 else if((aconf
= find_gline(client_p
)) != NULL
)
494 if(IsExemptKline(client_p
))
496 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
497 "GLINE over-ruled for %s, client is kline_exempt [%s@%s]",
498 get_client_name(client_p
, HIDE_IP
),
499 aconf
->user
, aconf
->host
);
503 if(IsExemptGline(client_p
))
505 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
506 "GLINE over-ruled for %s, client is gline_exempt [%s@%s]",
507 get_client_name(client_p
, HIDE_IP
),
508 aconf
->user
, aconf
->host
);
512 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
513 "GLINE active for %s",
514 get_client_name(client_p
, HIDE_IP
));
516 notify_banned_client(client_p
, aconf
, G_LINED
);
519 else if((aconf
= find_xline(client_p
->info
, 1)) != NULL
)
521 if(IsExemptKline(client_p
))
523 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
524 "XLINE over-ruled for %s, client is kline_exempt [%s]",
525 get_client_name(client_p
, HIDE_IP
),
530 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "XLINE active for %s",
531 get_client_name(client_p
, HIDE_IP
));
533 (void) exit_client(client_p
, client_p
, &me
, "Bad user info");
538 /* also check the unknowns list for new dlines */
539 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, unknown_list
.head
)
541 client_p
= ptr
->data
;
543 if((aconf
= find_dline((struct sockaddr
*)&client_p
->localClient
->ip
,client_p
->localClient
->ip
.ss_family
)))
545 if(aconf
->status
& CONF_EXEMPTDLINE
)
548 notify_banned_client(client_p
, aconf
, D_LINED
);
554 /* check_klines_event()
558 * side effects - check_klines() is called, kline_queued unset
561 check_klines_event(void *unused
)
571 * side effects - all clients will be checked for klines
576 struct Client
*client_p
;
577 struct ConfItem
*aconf
;
579 rb_dlink_node
*next_ptr
;
581 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
583 client_p
= ptr
->data
;
585 if(IsMe(client_p
) || !IsPerson(client_p
))
588 if((aconf
= find_kline(client_p
)) != NULL
)
590 if(IsExemptKline(client_p
))
592 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
593 "KLINE over-ruled for %s, client is kline_exempt",
594 get_client_name(client_p
, HIDE_IP
));
598 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
599 "KLINE active for %s",
600 get_client_name(client_p
, HIDE_IP
));
602 notify_banned_client(client_p
, aconf
, K_LINED
);
612 * side effects - all clients will be checked for glines
617 struct Client
*client_p
;
618 struct ConfItem
*aconf
;
620 rb_dlink_node
*next_ptr
;
622 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
624 client_p
= ptr
->data
;
626 if(IsMe(client_p
) || !IsPerson(client_p
))
629 if((aconf
= find_gline(client_p
)) != NULL
)
631 if(IsExemptKline(client_p
))
633 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
634 "GLINE over-ruled for %s, client is kline_exempt",
635 get_client_name(client_p
, HIDE_IP
));
639 if(IsExemptGline(client_p
))
641 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
642 "GLINE over-ruled for %s, client is gline_exempt",
643 get_client_name(client_p
, HIDE_IP
));
647 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
648 "GLINE active for %s",
649 get_client_name(client_p
, HIDE_IP
));
651 notify_banned_client(client_p
, aconf
, K_LINED
);
661 * side effects - all clients will be checked for dlines
666 struct Client
*client_p
;
667 struct ConfItem
*aconf
;
669 rb_dlink_node
*next_ptr
;
671 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
673 client_p
= ptr
->data
;
678 if((aconf
= find_dline((struct sockaddr
*)&client_p
->localClient
->ip
,client_p
->localClient
->ip
.ss_family
)) != NULL
)
680 if(aconf
->status
& CONF_EXEMPTDLINE
)
683 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
684 "DLINE active for %s",
685 get_client_name(client_p
, HIDE_IP
));
687 notify_banned_client(client_p
, aconf
, D_LINED
);
692 /* dlines need to be checked against unknowns too */
693 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, unknown_list
.head
)
695 client_p
= ptr
->data
;
697 if((aconf
= find_dline((struct sockaddr
*)&client_p
->localClient
->ip
,client_p
->localClient
->ip
.ss_family
)) != NULL
)
699 if(aconf
->status
& CONF_EXEMPTDLINE
)
702 notify_banned_client(client_p
, aconf
, D_LINED
);
711 * side effects - all clients will be checked for xlines
716 struct Client
*client_p
;
717 struct ConfItem
*aconf
;
719 rb_dlink_node
*next_ptr
;
721 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
723 client_p
= ptr
->data
;
725 if(IsMe(client_p
) || !IsPerson(client_p
))
728 if((aconf
= find_xline(client_p
->info
, 1)) != NULL
)
730 if(IsExemptKline(client_p
))
732 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
733 "XLINE over-ruled for %s, client is kline_exempt",
734 get_client_name(client_p
, HIDE_IP
));
738 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "XLINE active for %s",
739 get_client_name(client_p
, HIDE_IP
));
741 (void) exit_client(client_p
, client_p
, &me
, "Bad user info");
748 * update_client_exit_stats
750 * input - pointer to client
755 update_client_exit_stats(struct Client
*client_p
)
757 if(IsServer(client_p
))
759 sendto_realops_snomask(SNO_EXTERNAL
, L_ALL
,
760 "Server %s split from %s",
761 client_p
->name
, client_p
->servptr
->name
);
762 if(HasSentEob(client_p
))
765 else if(IsClient(client_p
))
770 if(IsInvisible(client_p
))
774 if(splitchecking
&& !splitmode
)
775 check_splitmode(NULL
);
779 * release_client_state
781 * input - pointer to client to release
786 release_client_state(struct Client
*client_p
)
788 if(client_p
->user
!= NULL
)
790 free_user(client_p
->user
, client_p
); /* try this here */
794 if(client_p
->serv
->user
!= NULL
)
795 free_user(client_p
->serv
->user
, client_p
);
796 if(client_p
->serv
->fullcaps
)
797 rb_free(client_p
->serv
->fullcaps
);
798 rb_free(client_p
->serv
);
803 * remove_client_from_list
804 * inputs - point to client to remove
806 * side effects - taken the code from ExitOneClient() for this
807 * and placed it here. - avalon
810 remove_client_from_list(struct Client
*client_p
)
812 s_assert(NULL
!= client_p
);
817 /* A client made with make_client()
818 * is on the unknown_list until removed.
819 * If it =does= happen to exit before its removed from that list
820 * and its =not= on the global_client_list, it will core here.
821 * short circuit that case now -db
823 if(client_p
->node
.prev
== NULL
&& client_p
->node
.next
== NULL
)
826 rb_dlinkDelete(&client_p
->node
, &global_client_list
);
828 update_client_exit_stats(client_p
);
833 * find_person - find person by (nick)name.
834 * inputs - pointer to name
835 * output - return client pointer
839 find_person(const char *name
)
841 struct Client
*c2ptr
;
843 c2ptr
= find_client(name
);
845 if(c2ptr
&& IsPerson(c2ptr
))
851 find_named_person(const char *name
)
853 struct Client
*c2ptr
;
855 c2ptr
= find_named_client(name
);
857 if(c2ptr
&& IsPerson(c2ptr
))
864 * find_chasing - find the client structure for a nick name (user)
865 * using history mechanism if necessary. If the client is not found,
866 * an error message (NO SUCH NICK) is generated. If the client was found
867 * through the history, chasing will be 1 and otherwise 0.
870 find_chasing(struct Client
*source_p
, const char *user
, int *chasing
)
874 if(MyClient(source_p
))
875 who
= find_named_person(user
);
877 who
= find_person(user
);
882 if(who
|| IsDigit(*user
))
885 if(!(who
= get_history(user
, (long) KILLCHASETIMELIMIT
)))
887 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
888 form_str(ERR_NOSUCHNICK
), user
);
897 * get_client_name - Return the name of the client
898 * for various tracking and
899 * admin purposes. The main purpose of this function is to
900 * return the "socket host" name of the client, if that
901 * differs from the advertised name (other than case).
902 * But, this can be used to any client structure.
905 * Watch out the allocation of "nbuf", if either source_p->name
906 * or source_p->sockhost gets changed into pointers instead of
907 * directly allocated within the structure...
910 * Function return either a pointer to the structure (source_p) or
911 * to internal buffer (nbuf). *NEVER* use the returned pointer
912 * to modify what it points!!!
916 get_client_name(struct Client
*client
, int showip
)
918 static char nbuf
[HOSTLEN
* 2 + USERLEN
+ 5];
920 s_assert(NULL
!= client
);
924 if(MyConnect(client
))
926 if(!irccmp(client
->name
, client
->host
))
929 if(ConfigFileEntry
.hide_spoof_ips
&&
930 showip
== SHOW_IP
&& IsIPSpoof(client
))
932 #ifdef HIDE_SERVERS_IPS
933 if(IsAnyServer(client
))
937 /* And finally, let's get the host information, ip or name */
941 rb_snprintf(nbuf
, sizeof(nbuf
), "%s[%s@%s]",
942 client
->name
, client
->username
,
946 rb_snprintf(nbuf
, sizeof(nbuf
), "%s[%s@255.255.255.255]",
947 client
->name
, client
->username
);
950 rb_snprintf(nbuf
, sizeof(nbuf
), "%s[%s@%s]",
951 client
->name
, client
->username
, client
->host
);
956 /* As pointed out by Adel Mezibra
957 * Neph|l|m@EFnet. Was missing a return here.
963 get_server_name(struct Client
*target_p
, int showip
)
965 static char nbuf
[HOSTLEN
* 2 + USERLEN
+ 5];
970 if(!MyConnect(target_p
) || !irccmp(target_p
->name
, target_p
->host
))
971 return target_p
->name
;
973 #ifdef HIDE_SERVERS_IPS
974 if(EmptyString(target_p
->name
))
976 rb_snprintf(nbuf
, sizeof(nbuf
), "[%s@255.255.255.255]",
981 return target_p
->name
;
987 rb_snprintf(nbuf
, sizeof(nbuf
), "%s[%s@%s]",
988 target_p
->name
, target_p
->username
,
993 rb_snprintf(nbuf
, sizeof(nbuf
), "%s[%s@255.255.255.255]",
994 target_p
->name
, target_p
->username
);
997 rb_snprintf(nbuf
, sizeof(nbuf
), "%s[%s@%s]",
998 target_p
->name
, target_p
->username
,
1005 /* log_client_name()
1007 * This version is the same as get_client_name, but doesnt contain the
1008 * code that will hide IPs always. This should be used for logfiles.
1011 log_client_name(struct Client
*target_p
, int showip
)
1013 static char nbuf
[HOSTLEN
* 2 + USERLEN
+ 5];
1015 if(target_p
== NULL
)
1018 if(MyConnect(target_p
))
1020 if(irccmp(target_p
->name
, target_p
->host
) == 0)
1021 return target_p
->name
;
1026 rb_snprintf(nbuf
, sizeof(nbuf
), "%s[%s@%s]", target_p
->name
,
1027 target_p
->username
, target_p
->sockhost
);
1031 rb_snprintf(nbuf
, sizeof(nbuf
), "%s[%s@255.255.255.255]",
1032 target_p
->name
, target_p
->username
);
1035 rb_snprintf(nbuf
, sizeof(nbuf
), "%s[%s@%s]", target_p
->name
,
1036 target_p
->username
, target_p
->host
);
1042 return target_p
->name
;
1045 /* is_remote_connect - Returns whether a server was /connect'ed by a remote
1046 * oper (send notices netwide) */
1048 is_remote_connect(struct Client
*client_p
)
1050 struct Client
*oper
;
1052 if (client_p
->serv
== NULL
)
1054 oper
= find_named_person(client_p
->serv
->by
);
1055 return oper
!= NULL
&& IsOper(oper
) && !MyConnect(oper
);
1059 free_exited_clients(void *unused
)
1061 rb_dlink_node
*ptr
, *next
;
1062 struct Client
*target_p
;
1064 RB_DLINK_FOREACH_SAFE(ptr
, next
, dead_list
.head
)
1066 target_p
= ptr
->data
;
1068 #ifdef DEBUG_EXITED_CLIENTS
1070 struct abort_client
*abt
;
1071 rb_dlink_node
*aptr
;
1074 RB_DLINK_FOREACH(aptr
, abort_list
.head
)
1077 if(abt
->client
== target_p
)
1080 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1081 "On abort_list: %s stat: %u flags: %u/%u handler: %c",
1082 target_p
->name
, (unsigned int) target_p
->status
,
1083 target_p
->flags
, target_p
->flags2
, target_p
->handler
);
1084 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1085 "Please report this to the charybdis developers!");
1092 rb_dlinkDestroy(ptr
, &dead_list
);
1098 if(ptr
->data
== NULL
)
1100 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1101 "Warning: null client on dead_list!");
1102 rb_dlinkDestroy(ptr
, &dead_list
);
1105 release_client_state(target_p
);
1106 free_client(target_p
);
1107 rb_dlinkDestroy(ptr
, &dead_list
);
1110 #ifdef DEBUG_EXITED_CLIENTS
1111 RB_DLINK_FOREACH_SAFE(ptr
, next
, dead_remote_list
.head
)
1113 target_p
= ptr
->data
;
1115 if(ptr
->data
== NULL
)
1117 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1118 "Warning: null client on dead_list!");
1119 rb_dlinkDestroy(ptr
, &dead_list
);
1122 release_client_state(target_p
);
1123 free_client(target_p
);
1124 rb_dlinkDestroy(ptr
, &dead_remote_list
);
1131 ** Recursively send QUITs and SQUITs for source_p and all its dependent clients
1132 ** and servers to those servers that need them. A server needs the client
1133 ** QUITs if it can't figure them out from the SQUIT (ie pre-TS4) or if it
1134 ** isn't getting the SQUIT because of @#(*&@)# hostmasking. With TS4, once
1135 ** a link gets a SQUIT, it doesn't need any QUIT/SQUITs for clients depending
1136 ** on that one -orabidoo
1139 recurse_send_quits(struct Client
*client_p
, struct Client
*source_p
,
1140 struct Client
*to
, const char *comment1
,
1141 const char *comment
)
1143 struct Client
*target_p
;
1144 rb_dlink_node
*ptr
, *ptr_next
;
1145 /* If this server can handle quit storm (QS) removal
1146 * of dependents, just send the SQUIT
1149 if(IsCapable(to
, CAP_QS
))
1151 sendto_one(to
, "SQUIT %s :%s",
1152 get_id(source_p
, to
), comment
);
1156 RB_DLINK_FOREACH_SAFE(ptr
, ptr_next
, source_p
->serv
->users
.head
)
1158 target_p
= ptr
->data
;
1159 sendto_one(to
, ":%s QUIT :%s", target_p
->name
, comment1
);
1161 RB_DLINK_FOREACH_SAFE(ptr
, ptr_next
, source_p
->serv
->servers
.head
)
1163 target_p
= ptr
->data
;
1164 recurse_send_quits(client_p
, target_p
, to
, comment1
, comment
);
1166 sendto_one(to
, "SQUIT %s :%s", source_p
->name
, comment
);
1171 ** Remove all clients that depend on source_p; assumes all (S)QUITs have
1172 ** already been sent. we make sure to exit a server's dependent clients
1173 ** and servers before the server itself; exit_one_client takes care of
1174 ** actually removing things off llists. tweaked from +CSr31 -orabidoo
1177 * added sanity test code.... source_p->serv might be NULL...
1180 recurse_remove_clients(struct Client
*source_p
, const char *comment
)
1182 struct Client
*target_p
;
1183 rb_dlink_node
*ptr
, *ptr_next
;
1188 if(source_p
->serv
== NULL
) /* oooops. uh this is actually a major bug */
1191 /* this is very ugly, but it saves cpu :P */
1192 if(ConfigFileEntry
.nick_delay
> 0)
1194 RB_DLINK_FOREACH_SAFE(ptr
, ptr_next
, source_p
->serv
->users
.head
)
1196 target_p
= ptr
->data
;
1197 target_p
->flags
|= FLAGS_KILLED
;
1198 add_nd_entry(target_p
->name
);
1200 if(!IsDead(target_p
) && !IsClosing(target_p
))
1201 exit_remote_client(NULL
, target_p
, &me
, comment
);
1206 RB_DLINK_FOREACH_SAFE(ptr
, ptr_next
, source_p
->serv
->users
.head
)
1208 target_p
= ptr
->data
;
1209 target_p
->flags
|= FLAGS_KILLED
;
1211 if(!IsDead(target_p
) && !IsClosing(target_p
))
1212 exit_remote_client(NULL
, target_p
, &me
, comment
);
1216 RB_DLINK_FOREACH_SAFE(ptr
, ptr_next
, source_p
->serv
->servers
.head
)
1218 target_p
= ptr
->data
;
1219 recurse_remove_clients(target_p
, comment
);
1220 qs_server(NULL
, target_p
, &me
, comment
);
1225 ** Remove *everything* that depends on source_p, from all lists, and sending
1226 ** all necessary QUITs and SQUITs. source_p itself is still on the lists,
1227 ** and its SQUITs have been sent except for the upstream one -orabidoo
1230 remove_dependents(struct Client
*client_p
,
1231 struct Client
*source_p
,
1232 struct Client
*from
, const char *comment
, const char *comment1
)
1235 rb_dlink_node
*ptr
, *next
;
1237 RB_DLINK_FOREACH_SAFE(ptr
, next
, serv_list
.head
)
1241 if(IsMe(to
) || to
== source_p
->from
||
1242 (to
== client_p
&& IsCapable(to
, CAP_QS
)))
1245 recurse_send_quits(client_p
, source_p
, to
, comment1
, comment
);
1248 recurse_remove_clients(source_p
, comment1
);
1252 exit_aborted_clients(void *unused
)
1254 struct abort_client
*abt
;
1255 rb_dlink_node
*ptr
, *next
;
1256 RB_DLINK_FOREACH_SAFE(ptr
, next
, abort_list
.head
)
1260 #ifdef DEBUG_EXITED_CLIENTS
1262 if(rb_dlinkFind(abt
->client
, &dead_list
))
1265 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1266 "On dead_list: %s stat: %u flags: %u/%u handler: %c",
1267 abt
->client
->name
, (unsigned int) abt
->client
->status
,
1268 abt
->client
->flags
, abt
->client
->flags2
, abt
->client
->handler
);
1269 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1270 "Please report this to the charybdis developers!");
1276 s_assert(*((unsigned long*)abt
->client
) != 0xdeadbeef); /* This is lame but its a debug thing */
1277 rb_dlinkDelete(ptr
, &abort_list
);
1279 if(IsAnyServer(abt
->client
))
1280 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1281 "Closing link to %s: %s",
1282 get_server_name(abt
->client
, HIDE_IP
), abt
->notice
);
1284 /* its no longer on abort list - we *must* remove
1285 * FLAGS_CLOSING otherwise exit_client() will not run --fl
1287 abt
->client
->flags
&= ~FLAGS_CLOSING
;
1288 exit_client(abt
->client
, abt
->client
, &me
, abt
->notice
);
1295 * dead_link - Adds client to a list of clients that need an exit_client()
1299 dead_link(struct Client
*client_p
)
1301 struct abort_client
*abt
;
1303 s_assert(!IsMe(client_p
));
1304 if(IsDead(client_p
) || IsClosing(client_p
) || IsMe(client_p
))
1307 abt
= (struct abort_client
*) rb_malloc(sizeof(struct abort_client
));
1309 if(client_p
->flags
& FLAGS_SENDQEX
)
1310 strlcpy(abt
->notice
, "Max SendQ exceeded", sizeof(abt
->notice
));
1312 rb_snprintf(abt
->notice
, sizeof(abt
->notice
), "Write error: %s", strerror(errno
));
1314 abt
->client
= client_p
;
1315 SetIOError(client_p
);
1317 SetClosing(client_p
);
1318 rb_dlinkAdd(abt
, &abt
->node
, &abort_list
);
1322 /* This does the remove of the user from channels..local or remote */
1324 exit_generic_client(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1325 const char *comment
)
1327 rb_dlink_node
*ptr
, *next_ptr
;
1329 if(IsOper(source_p
))
1330 rb_dlinkFindDestroy(source_p
, &oper_list
);
1332 sendto_common_channels_local(source_p
, ":%s!%s@%s QUIT :%s",
1334 source_p
->username
, source_p
->host
, comment
);
1336 remove_user_from_channels(source_p
);
1338 /* Should not be in any channels now */
1339 s_assert(source_p
->user
->channel
.head
== NULL
);
1341 /* Clean up invitefield */
1342 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, source_p
->user
->invited
.head
)
1344 del_invite(ptr
->data
, source_p
);
1347 /* Clean up allow lists */
1348 del_all_accepts(source_p
);
1350 add_history(source_p
, 0);
1351 off_history(source_p
);
1353 monitor_signoff(source_p
);
1355 if(has_id(source_p
))
1356 del_from_id_hash(source_p
->id
, source_p
);
1358 del_from_hostname_hash(source_p
->orighost
, source_p
);
1359 del_from_client_hash(source_p
->name
, source_p
);
1360 remove_client_from_list(source_p
);
1364 * Assumes IsPerson(source_p) && !MyConnect(source_p)
1368 exit_remote_client(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1369 const char *comment
)
1371 exit_generic_client(client_p
, source_p
, from
, comment
);
1373 if(source_p
->servptr
&& source_p
->servptr
->serv
)
1375 rb_dlinkDelete(&source_p
->lnode
, &source_p
->servptr
->serv
->users
);
1378 if((source_p
->flags
& FLAGS_KILLED
) == 0)
1380 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
,
1381 ":%s QUIT :%s", use_id(source_p
), comment
);
1382 sendto_server(client_p
, NULL
, NOCAPS
, CAP_TS6
,
1383 ":%s QUIT :%s", source_p
->name
, comment
);
1387 #ifdef DEBUG_EXITED_CLIENTS
1388 rb_dlinkAddAlloc(source_p
, &dead_remote_list
);
1390 rb_dlinkAddAlloc(source_p
, &dead_list
);
1392 return(CLIENT_EXITED
);
1396 * This assumes IsUnknown(source_p) == TRUE and MyConnect(source_p) == TRUE
1400 exit_unknown_client(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1401 const char *comment
)
1403 delete_auth_queries(source_p
);
1404 del_unknown_ip(source_p
);
1405 rb_dlinkDelete(&source_p
->localClient
->tnode
, &unknown_list
);
1407 if(!IsIOError(source_p
))
1408 sendto_one(source_p
, "ERROR :Closing Link: %s (%s)",
1409 source_p
->user
!= NULL
? source_p
->host
: "127.0.0.1",
1412 close_connection(source_p
);
1414 if(has_id(source_p
))
1415 del_from_id_hash(source_p
->id
, source_p
);
1417 del_from_hostname_hash(source_p
->host
, source_p
);
1418 del_from_client_hash(source_p
->name
, source_p
);
1419 remove_client_from_list(source_p
);
1421 rb_dlinkAddAlloc(source_p
, &dead_list
);
1423 /* Note that we don't need to add unknowns to the dead_list */
1424 return(CLIENT_EXITED
);
1428 exit_remote_server(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1429 const char *comment
)
1431 static char comment1
[(HOSTLEN
*2)+2];
1432 static char newcomment
[BUFSIZE
];
1433 struct Client
*target_p
;
1435 if(ConfigServerHide
.flatten_links
)
1436 strcpy(comment1
, "*.net *.split");
1439 strcpy(comment1
, source_p
->servptr
->name
);
1440 strcat(comment1
, " ");
1441 strcat(comment1
, source_p
->name
);
1444 rb_snprintf(newcomment
, sizeof(newcomment
), "by %s: %s",
1445 from
->name
, comment
);
1447 if(source_p
->serv
!= NULL
)
1448 remove_dependents(client_p
, source_p
, from
, IsPerson(from
) ? newcomment
: comment
, comment1
);
1450 if(source_p
->servptr
&& source_p
->servptr
->serv
)
1451 rb_dlinkDelete(&source_p
->lnode
, &source_p
->servptr
->serv
->servers
);
1455 rb_dlinkFindDestroy(source_p
, &global_serv_list
);
1456 target_p
= source_p
->from
;
1458 if(target_p
!= NULL
&& IsServer(target_p
) && target_p
!= client_p
&&
1459 !IsMe(target_p
) && (source_p
->flags
& FLAGS_KILLED
) == 0)
1461 sendto_one(target_p
, ":%s SQUIT %s :%s",
1462 get_id(from
, target_p
), get_id(source_p
, target_p
),
1466 if(has_id(source_p
))
1467 del_from_id_hash(source_p
->id
, source_p
);
1469 del_from_client_hash(source_p
->name
, source_p
);
1470 remove_client_from_list(source_p
);
1471 scache_split(source_p
->serv
->nameinfo
);
1474 #ifdef DEBUG_EXITED_CLIENTS
1475 rb_dlinkAddAlloc(source_p
, &dead_remote_list
);
1477 rb_dlinkAddAlloc(source_p
, &dead_list
);
1483 qs_server(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1484 const char *comment
)
1486 struct Client
*target_p
;
1488 if(source_p
->servptr
&& source_p
->servptr
->serv
)
1489 rb_dlinkDelete(&source_p
->lnode
, &source_p
->servptr
->serv
->servers
);
1493 rb_dlinkFindDestroy(source_p
, &global_serv_list
);
1494 target_p
= source_p
->from
;
1496 if(has_id(source_p
))
1497 del_from_id_hash(source_p
->id
, source_p
);
1499 del_from_client_hash(source_p
->name
, source_p
);
1500 remove_client_from_list(source_p
);
1501 scache_split(source_p
->serv
->nameinfo
);
1504 rb_dlinkAddAlloc(source_p
, &dead_list
);
1509 exit_local_server(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1510 const char *comment
)
1512 static char comment1
[(HOSTLEN
*2)+2];
1513 static char newcomment
[BUFSIZE
];
1514 unsigned int sendk
, recvk
;
1516 rb_dlinkDelete(&source_p
->localClient
->tnode
, &serv_list
);
1517 rb_dlinkFindDestroy(source_p
, &global_serv_list
);
1519 unset_chcap_usage_counts(source_p
);
1520 sendk
= source_p
->localClient
->sendK
;
1521 recvk
= source_p
->localClient
->receiveK
;
1523 /* Always show source here, so the server notices show
1524 * which side initiated the split -- jilles
1526 rb_snprintf(newcomment
, sizeof(newcomment
), "by %s: %s",
1527 from
== source_p
? me
.name
: from
->name
, comment
);
1528 if (!IsIOError(source_p
))
1529 sendto_one(source_p
, "SQUIT %s :%s", use_id(source_p
),
1531 if(client_p
!= NULL
&& source_p
!= client_p
&& !IsIOError(source_p
))
1533 sendto_one(source_p
, "ERROR :Closing Link: 127.0.0.1 %s (%s)",
1534 source_p
->name
, comment
);
1537 if(source_p
->servptr
&& source_p
->servptr
->serv
)
1538 rb_dlinkDelete(&source_p
->lnode
, &source_p
->servptr
->serv
->servers
);
1543 close_connection(source_p
);
1545 if(ConfigServerHide
.flatten_links
)
1546 strcpy(comment1
, "*.net *.split");
1549 strcpy(comment1
, source_p
->servptr
->name
);
1550 strcat(comment1
, " ");
1551 strcat(comment1
, source_p
->name
);
1554 if(source_p
->serv
!= NULL
)
1555 remove_dependents(client_p
, source_p
, from
, IsPerson(from
) ? newcomment
: comment
, comment1
);
1557 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s was connected"
1558 " for %ld seconds. %d/%d sendK/recvK.",
1559 source_p
->name
, (long) rb_current_time() - source_p
->localClient
->firsttime
, sendk
, recvk
);
1561 ilog(L_SERVER
, "%s was connected for %ld seconds. %d/%d sendK/recvK.",
1562 source_p
->name
, (long) rb_current_time() - source_p
->localClient
->firsttime
, sendk
, recvk
);
1564 if(has_id(source_p
))
1565 del_from_id_hash(source_p
->id
, source_p
);
1567 del_from_client_hash(source_p
->name
, source_p
);
1568 remove_client_from_list(source_p
);
1569 scache_split(source_p
->serv
->nameinfo
);
1572 rb_dlinkAddAlloc(source_p
, &dead_list
);
1578 * This assumes IsPerson(source_p) == TRUE && MyConnect(source_p) == TRUE
1582 exit_local_client(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1583 const char *comment
)
1585 unsigned long on_for
;
1587 exit_generic_client(client_p
, source_p
, from
, comment
);
1588 clear_monitor(source_p
);
1590 s_assert(IsPerson(source_p
));
1591 rb_dlinkDelete(&source_p
->localClient
->tnode
, &lclient_list
);
1592 rb_dlinkDelete(&source_p
->lnode
, &me
.serv
->users
);
1594 if(IsOper(source_p
))
1595 rb_dlinkFindDestroy(source_p
, &local_oper_list
);
1597 sendto_realops_snomask(SNO_CCONN
, L_ALL
,
1598 "Client exiting: %s (%s@%s) [%s] [%s]",
1600 source_p
->username
, source_p
->host
, comment
,
1601 show_ip(NULL
, source_p
) ? source_p
->sockhost
: "255.255.255.255");
1603 sendto_realops_snomask(SNO_CCONNEXT
, L_ALL
,
1604 "CLIEXIT %s %s %s %s 0 %s",
1605 source_p
->name
, source_p
->username
, source_p
->host
,
1606 show_ip(NULL
, source_p
) ? source_p
->sockhost
: "255.255.255.255",
1609 on_for
= rb_current_time() - source_p
->localClient
->firsttime
;
1611 ilog(L_USER
, "%s (%3lu:%02lu:%02lu): %s!%s@%s %d/%d",
1612 myctime(rb_current_time()), on_for
/ 3600,
1613 (on_for
% 3600) / 60, on_for
% 60,
1614 source_p
->name
, source_p
->username
, source_p
->host
,
1615 source_p
->localClient
->sendK
, source_p
->localClient
->receiveK
);
1617 sendto_one(source_p
, "ERROR :Closing Link: %s (%s)", source_p
->host
, comment
);
1618 close_connection(source_p
);
1620 if((source_p
->flags
& FLAGS_KILLED
) == 0)
1622 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
,
1623 ":%s QUIT :%s", use_id(source_p
), comment
);
1624 sendto_server(client_p
, NULL
, NOCAPS
, CAP_TS6
,
1625 ":%s QUIT :%s", source_p
->name
, comment
);
1629 rb_dlinkAddAlloc(source_p
, &dead_list
);
1630 return(CLIENT_EXITED
);
1635 ** exit_client - This is old "m_bye". Name changed, because this is not a
1636 ** protocol function, but a general server utility function.
1638 ** This function exits a client of *any* type (user, server, etc)
1639 ** from this server. Also, this generates all necessary prototol
1640 ** messages that this exit may cause.
1642 ** 1) If the client is a local client, then this implicitly
1643 ** exits all other clients depending on this connection (e.g.
1644 ** remote clients having 'from'-field that points to this.
1646 ** 2) If the client is a remote client, then only this is exited.
1648 ** For convenience, this function returns a suitable value for
1649 ** m_function return value:
1651 ** CLIENT_EXITED if (client_p == source_p)
1652 ** 0 if (client_p != source_p)
1655 exit_client(struct Client
*client_p
, /* The local client originating the
1656 * exit or NULL, if this exit is
1657 * generated by this server for
1659 * This will not get any of the
1660 * generated messages. */
1661 struct Client
*source_p
, /* Client exiting */
1662 struct Client
*from
, /* Client firing off this Exit,
1664 const char *comment
/* Reason for the exit */
1667 hook_data_client_exit hdata
;
1668 if(IsClosing(source_p
))
1671 /* note, this HAS to be here, when we exit a client we attempt to
1672 * send them data, if this generates a write error we must *not* add
1673 * them to the abort list --fl
1675 SetClosing(source_p
);
1677 hdata
.local_link
= client_p
;
1678 hdata
.target
= source_p
;
1680 hdata
.comment
= comment
;
1681 call_hook(h_client_exit
, &hdata
);
1683 if(MyConnect(source_p
))
1685 /* Local clients of various types */
1686 if(IsPerson(source_p
))
1687 return exit_local_client(client_p
, source_p
, from
, comment
);
1688 else if(IsServer(source_p
))
1689 return exit_local_server(client_p
, source_p
, from
, comment
);
1690 /* IsUnknown || IsConnecting || IsHandShake */
1691 else if(!IsReject(source_p
))
1692 return exit_unknown_client(client_p
, source_p
, from
, comment
);
1697 if(IsPerson(source_p
))
1698 return exit_remote_client(client_p
, source_p
, from
, comment
);
1699 else if(IsServer(source_p
))
1700 return exit_remote_server(client_p
, source_p
, from
, comment
);
1707 * Count up local client memory
1710 /* XXX one common Client list now */
1712 count_local_client_memory(size_t * count
, size_t * local_client_memory_used
)
1715 rb_bh_usage(lclient_heap
, count
, NULL
, &lusage
, NULL
);
1716 *local_client_memory_used
= lusage
+ (*count
* (sizeof(void *) + sizeof(struct Client
)));
1720 * Count up remote client memory
1723 count_remote_client_memory(size_t * count
, size_t * remote_client_memory_used
)
1725 size_t lcount
, rcount
;
1726 rb_bh_usage(lclient_heap
, &lcount
, NULL
, NULL
, NULL
);
1727 rb_bh_usage(client_heap
, &rcount
, NULL
, NULL
, NULL
);
1728 *count
= rcount
- lcount
;
1729 *remote_client_memory_used
= *count
* (sizeof(void *) + sizeof(struct Client
));
1734 * accept processing, this adds a form of "caller ID" to ircd
1736 * If a client puts themselves into "caller ID only" mode,
1737 * only clients that match a client pointer they have put on
1738 * the accept list will be allowed to message them.
1740 * [ source.on_allow_list ] -> [ target1 ] -> [ target2 ]
1742 * [target.allow_list] -> [ source1 ] -> [source2 ]
1744 * i.e. a target will have a link list of source pointers it will allow
1745 * each source client then has a back pointer pointing back
1746 * to the client that has it on its accept list.
1747 * This allows for exit_one_client to remove these now bogus entries
1748 * from any client having an accept on them.
1753 * inputs - pointer to exiting client
1755 * side effects - Walk through given clients allow_list and on_allow_list
1756 * remove all references to this client
1759 del_all_accepts(struct Client
*client_p
)
1762 rb_dlink_node
*next_ptr
;
1763 struct Client
*target_p
;
1765 if(MyClient(client_p
) && client_p
->localClient
->allow_list
.head
)
1767 /* clear this clients accept list, and remove them from
1768 * everyones on_accept_list
1770 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, client_p
->localClient
->allow_list
.head
)
1772 target_p
= ptr
->data
;
1773 rb_dlinkFindDestroy(client_p
, &target_p
->on_allow_list
);
1774 rb_dlinkDestroy(ptr
, &client_p
->localClient
->allow_list
);
1778 /* remove this client from everyones accept list */
1779 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, client_p
->on_allow_list
.head
)
1781 target_p
= ptr
->data
;
1782 rb_dlinkFindDestroy(client_p
, &target_p
->localClient
->allow_list
);
1783 rb_dlinkDestroy(ptr
, &client_p
->on_allow_list
);
1788 * show_ip() - asks if the true IP shoudl be shown when source is
1789 * askin for info about target
1791 * Inputs - source_p who is asking
1792 * - target_p who do we want the info on
1793 * Output - returns 1 if clear IP can be showed, otherwise 0
1794 * Side Effects - none
1798 show_ip(struct Client
*source_p
, struct Client
*target_p
)
1800 if(IsAnyServer(target_p
))
1802 #ifndef HIDE_SERVERS_IPS
1803 if(source_p
== NULL
|| IsOper(source_p
))
1808 else if(IsIPSpoof(target_p
))
1810 /* source == NULL indicates message is being sent
1813 if(!ConfigFileEntry
.hide_spoof_ips
&&
1814 (source_p
== NULL
|| MyOper(source_p
)))
1818 else if(IsDynSpoof(target_p
) && (source_p
!= NULL
&& !IsOper(source_p
)))
1825 show_ip_conf(struct ConfItem
*aconf
, struct Client
*source_p
)
1827 if(IsConfDoSpoofIp(aconf
))
1829 if(!ConfigFileEntry
.hide_spoof_ips
&& MyOper(source_p
))
1844 * side effects - Creates a block heap for struct Users
1847 static rb_bh
*user_heap
;
1851 user_heap
= rb_bh_create(sizeof(struct User
), USER_HEAP_SIZE
, "user_heap");
1859 * inputs - pointer to client struct
1860 * output - pointer to struct User
1861 * side effects - add's an User information block to a client
1862 * if it was not previously allocated.
1865 make_user(struct Client
*client_p
)
1869 user
= client_p
->user
;
1872 user
= (struct User
*) rb_bh_alloc(user_heap
);
1874 client_p
->user
= user
;
1882 * inputs - pointer to client struct
1883 * output - pointer to server_t
1884 * side effects - add's an Server information block to a client
1885 * if it was not previously allocated.
1888 make_server(struct Client
*client_p
)
1890 server_t
*serv
= client_p
->serv
;
1894 serv
= (server_t
*) rb_malloc(sizeof(server_t
));
1895 client_p
->serv
= serv
;
1897 return client_p
->serv
;
1903 * inputs - pointer to user struct
1904 * - pointer to client struct
1906 * side effects - Decrease user reference count by one and release block,
1907 * if count reaches 0
1910 free_user(struct User
*user
, struct Client
*client_p
)
1912 free_away(client_p
);
1914 if(--user
->refcnt
<= 0)
1917 rb_free((char *) user
->away
);
1921 if(user
->refcnt
< 0 || user
->invited
.head
|| user
->channel
.head
)
1923 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1924 "* %#lx user (%s!%s@%s) %#lx %#lx %#lx %lu %d *",
1925 (unsigned long) client_p
,
1926 client_p
? client_p
->
1930 (unsigned long) user
,
1931 (unsigned long) user
->invited
.head
,
1932 (unsigned long) user
->channel
.head
,
1933 rb_dlink_list_length(&user
->channel
),
1935 s_assert(!user
->refcnt
);
1936 s_assert(!user
->invited
.head
);
1937 s_assert(!user
->channel
.head
);
1940 rb_bh_free(user_heap
, user
);
1945 allocate_away(struct Client
*client_p
)
1947 if(client_p
->user
->away
== NULL
)
1948 client_p
->user
->away
= rb_bh_alloc(away_heap
);
1953 free_away(struct Client
*client_p
)
1955 if(client_p
->user
->away
!= NULL
) {
1956 rb_bh_free(away_heap
, client_p
->user
->away
);
1957 client_p
->user
->away
= NULL
;
1966 for(i
= 0; i
< 3; i
++)
1967 current_uid
[i
] = me
.id
[i
];
1969 for(i
= 3; i
< 9; i
++)
1970 current_uid
[i
] = 'A';
1972 current_uid
[9] = '\0';
1981 for(i
= 8; i
> 3; i
--)
1983 if(current_uid
[i
] == 'Z')
1985 current_uid
[i
] = '0';
1988 else if(current_uid
[i
] != '9')
1994 current_uid
[i
] = 'A';
1997 /* if this next if() triggers, we're fucked. */
1998 if(current_uid
[3] == 'Z')
2000 current_uid
[i
] = 'A';
2011 * Close the physical connection. This function must make
2012 * MyConnect(client_p) == FALSE, and set client_p->from == NULL.
2015 close_connection(struct Client
*client_p
)
2017 s_assert(client_p
!= NULL
);
2018 if(client_p
== NULL
)
2021 s_assert(MyConnect(client_p
));
2022 if(!MyConnect(client_p
))
2025 if(IsServer(client_p
))
2027 struct server_conf
*server_p
;
2029 ServerStats
->is_sv
++;
2030 ServerStats
->is_sbs
+= client_p
->localClient
->sendB
;
2031 ServerStats
->is_sbr
+= client_p
->localClient
->receiveB
;
2032 ServerStats
->is_sks
+= client_p
->localClient
->sendK
;
2033 ServerStats
->is_skr
+= client_p
->localClient
->receiveK
;
2034 ServerStats
->is_sti
+= rb_current_time() - client_p
->localClient
->firsttime
;
2035 if(ServerStats
->is_sbs
> 2047)
2037 ServerStats
->is_sks
+= (ServerStats
->is_sbs
>> 10);
2038 ServerStats
->is_sbs
&= 0x3ff;
2040 if(ServerStats
->is_sbr
> 2047)
2042 ServerStats
->is_skr
+= (ServerStats
->is_sbr
>> 10);
2043 ServerStats
->is_sbr
&= 0x3ff;
2047 * If the connection has been up for a long amount of time, schedule
2048 * a 'quick' reconnect, else reset the next-connect cycle.
2050 if((server_p
= find_server_conf(client_p
->name
)) != NULL
)
2053 * Reschedule a faster reconnect, if this was a automatically
2054 * connected configuration entry. (Note that if we have had
2055 * a rehash in between, the status has been changed to
2056 * CONF_ILLEGAL). But only do this if it was a "good" link.
2058 server_p
->hold
= time(NULL
);
2060 (server_p
->hold
- client_p
->localClient
->lasttime
>
2061 HANGONGOODLINK
) ? HANGONRETRYDELAY
: ConFreq(server_p
->class);
2065 else if(IsClient(client_p
))
2067 ServerStats
->is_cl
++;
2068 ServerStats
->is_cbs
+= client_p
->localClient
->sendB
;
2069 ServerStats
->is_cbr
+= client_p
->localClient
->receiveB
;
2070 ServerStats
->is_cks
+= client_p
->localClient
->sendK
;
2071 ServerStats
->is_ckr
+= client_p
->localClient
->receiveK
;
2072 ServerStats
->is_cti
+= rb_current_time() - client_p
->localClient
->firsttime
;
2073 if(ServerStats
->is_cbs
> 2047)
2075 ServerStats
->is_cks
+= (ServerStats
->is_cbs
>> 10);
2076 ServerStats
->is_cbs
&= 0x3ff;
2078 if(ServerStats
->is_cbr
> 2047)
2080 ServerStats
->is_ckr
+= (ServerStats
->is_cbr
>> 10);
2081 ServerStats
->is_cbr
&= 0x3ff;
2085 ServerStats
->is_ni
++;
2087 if(client_p
->localClient
->F
)
2089 /* attempt to flush any pending dbufs. Evil, but .. -- adrian */
2090 if(!IsIOError(client_p
))
2091 send_queued(client_p
);
2093 rb_close(client_p
->localClient
->F
);
2094 client_p
->localClient
->F
= NULL
;
2097 if(-1 < client_p
->localClient
->ctrlfd
)
2099 rb_close(client_p
->localClient
->ctrlfd
);
2100 client_p
->localClient
->ctrlfd
= -1;
2103 rb_linebuf_donebuf(&client_p
->localClient
->buf_sendq
);
2104 rb_linebuf_donebuf(&client_p
->localClient
->buf_recvq
);
2105 detach_conf(client_p
);
2107 /* XXX shouldnt really be done here. */
2108 detach_server_conf(client_p
);
2110 client_p
->from
= NULL
; /* ...this should catch them! >:) --msa */
2111 ClearMyConnect(client_p
);
2112 SetIOError(client_p
);
2118 error_exit_client(struct Client
*client_p
, int error
)
2121 * ...hmm, with non-blocking sockets we might get
2122 * here from quite valid reasons, although.. why
2123 * would select report "data available" when there
2124 * wasn't... so, this must be an error anyway... --msa
2125 * actually, EOF occurs when read() returns 0 and
2126 * in due course, select() returns that fd as ready
2127 * for reading even though it ends up being an EOF. -avalon
2130 int current_error
= rb_get_sockerr(client_p
->localClient
->F
);
2132 SetIOError(client_p
);
2134 if(IsServer(client_p
) || IsHandshake(client_p
))
2138 sendto_realops_snomask(SNO_GENERAL
, is_remote_connect(client_p
) && !IsServer(client_p
) ? L_NETWIDE
: L_ALL
,
2139 "Server %s closed the connection",
2140 get_server_name(client_p
, SHOW_IP
));
2142 ilog(L_SERVER
, "Server %s closed the connection",
2143 log_client_name(client_p
, SHOW_IP
));
2147 sendto_realops_snomask(SNO_GENERAL
, is_remote_connect(client_p
) && !IsServer(client_p
) ? L_NETWIDE
: L_ALL
,
2148 "Lost connection to %s: %s",
2149 client_p
->name
, strerror(current_error
));
2150 ilog(L_SERVER
, "Lost connection to %s: %s",
2151 log_client_name(client_p
, SHOW_IP
), strerror(current_error
));
2156 strlcpy(errmsg
, "Remote host closed the connection", sizeof(errmsg
));
2158 rb_snprintf(errmsg
, sizeof(errmsg
), "Read error: %s", strerror(current_error
));
2160 exit_client(client_p
, client_p
, &me
, errmsg
);