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 $
36 #include "irc_string.h"
37 #include "sprintf_irc.h"
45 #include "s_newconf.h"
61 #include "blacklist.h"
64 #include "irc_dictionary.h"
66 #define DEBUG_EXITED_CLIENTS
68 static void check_pings_list(dlink_list
* list
);
69 static void check_unknowns_list(dlink_list
* list
);
70 static void free_exited_clients(void *unused
);
71 static void exit_aborted_clients(void *unused
);
73 static int exit_remote_client(struct Client
*, struct Client
*, struct Client
*,const char *);
74 static int exit_remote_server(struct Client
*, struct Client
*, struct Client
*,const char *);
75 static int exit_local_client(struct Client
*, struct Client
*, struct Client
*,const char *);
76 static int exit_unknown_client(struct Client
*, struct Client
*, struct Client
*,const char *);
77 static int exit_local_server(struct Client
*, struct Client
*, struct Client
*,const char *);
78 static int qs_server(struct Client
*, struct Client
*, struct Client
*, const char *comment
);
80 static EVH check_pings
;
82 extern BlockHeap
*client_heap
;
83 extern BlockHeap
*lclient_heap
;
84 extern BlockHeap
*pclient_heap
;
86 extern char current_uid
[IDLEN
];
88 struct Dictionary
*nd_dict
= NULL
;
98 #ifdef DEBUG_EXITED_CLIENTS
99 static dlink_list dead_remote_list
;
105 struct Client
*client
;
106 char notice
[REASONLEN
];
109 static dlink_list abort_list
;
117 * side effects - initialize client free memory
123 * start off the check ping event .. -- adrian
124 * Every 30 seconds is plenty -- db
126 client_heap
= BlockHeapCreate(sizeof(struct Client
), CLIENT_HEAP_SIZE
);
127 lclient_heap
= BlockHeapCreate(sizeof(struct LocalUser
), LCLIENT_HEAP_SIZE
);
128 pclient_heap
= BlockHeapCreate(sizeof(struct PreClient
), PCLIENT_HEAP_SIZE
);
129 eventAddIsh("check_pings", check_pings
, NULL
, 30);
130 eventAddIsh("free_exited_clients", &free_exited_clients
, NULL
, 4);
131 eventAddIsh("exit_aborted_clients", exit_aborted_clients
, NULL
, 1);
133 nd_dict
= irc_dictionary_create(irccmp
);
138 * make_client - create a new Client struct and set it to initial state.
140 * from == NULL, create local client (a client connected
143 * from, create remote client (behind a socket
144 * associated with the client defined by
145 * 'from'). ('from' is a local client!!).
148 make_client(struct Client
*from
)
150 struct Client
*client_p
= NULL
;
151 struct LocalUser
*localClient
;
153 client_p
= BlockHeapAlloc(client_heap
);
157 client_p
->from
= client_p
; /* 'from' of local client is self! */
159 localClient
= (struct LocalUser
*) BlockHeapAlloc(lclient_heap
);
160 SetMyConnect(client_p
);
161 client_p
->localClient
= localClient
;
163 client_p
->localClient
->lasttime
= client_p
->localClient
->firsttime
= CurrentTime
;
165 client_p
->localClient
->F
= NULL
;
166 client_p
->localClient
->ctrlfd
= -1;
168 client_p
->preClient
= (struct PreClient
*) BlockHeapAlloc(pclient_heap
);
170 /* as good a place as any... */
171 dlinkAdd(client_p
, &client_p
->localClient
->tnode
, &unknown_list
);
174 { /* from is not NULL */
175 client_p
->localClient
= NULL
;
176 client_p
->preClient
= NULL
;
177 client_p
->from
= from
; /* 'from' of local client is self! */
180 SetUnknown(client_p
);
181 strcpy(client_p
->username
, "unknown");
187 free_pre_client(struct Client
*client_p
)
189 struct Blacklist
*blptr
;
191 s_assert(NULL
!= client_p
);
193 if(client_p
->preClient
== NULL
)
196 blptr
= client_p
->preClient
->dnsbl_listed
;
198 unref_blacklist(blptr
);
199 abort_blacklist_queries(client_p
);
200 BlockHeapFree(pclient_heap
, client_p
->preClient
);
201 client_p
->preClient
= NULL
;
205 free_local_client(struct Client
*client_p
)
207 s_assert(NULL
!= client_p
);
208 s_assert(&me
!= client_p
);
210 if(client_p
->localClient
== NULL
)
214 * clean up extra sockets from P-lines which have been discarded.
216 if(client_p
->localClient
->listener
)
218 s_assert(0 < client_p
->localClient
->listener
->ref_count
);
219 if(0 == --client_p
->localClient
->listener
->ref_count
220 && !client_p
->localClient
->listener
->active
)
221 free_listener(client_p
->localClient
->listener
);
222 client_p
->localClient
->listener
= 0;
225 if(client_p
->localClient
->F
)
226 comm_close(client_p
->localClient
->F
->fd
);
228 if(client_p
->localClient
->passwd
)
230 memset(client_p
->localClient
->passwd
, 0,
231 strlen(client_p
->localClient
->passwd
));
232 MyFree(client_p
->localClient
->passwd
);
235 MyFree(client_p
->localClient
->challenge
);
236 MyFree(client_p
->localClient
->fullcaps
);
237 MyFree(client_p
->localClient
->opername
);
238 MyFree(client_p
->localClient
->mangledhost
);
240 BlockHeapFree(lclient_heap
, client_p
->localClient
);
241 client_p
->localClient
= NULL
;
245 free_client(struct Client
*client_p
)
247 s_assert(NULL
!= client_p
);
248 s_assert(&me
!= client_p
);
249 free_local_client(client_p
);
250 free_pre_client(client_p
);
251 BlockHeapFree(client_heap
, client_p
);
255 * check_pings - go through the local client list and check activity
256 * kill off stuff that should die
258 * inputs - NOT USED (from event)
259 * output - next time_t when check_pings() should be called again
263 * A PING can be sent to clients as necessary.
265 * Client/Server ping outs are handled.
269 * Addon from adrian. We used to call this after nextping seconds,
270 * however I've changed it to run once a second. This is only for
271 * PING timeouts, not K/etc-line checks (thanks dianora!). Having it
272 * run once a second makes life a lot easier - when a new client connects
273 * and they need a ping in 4 seconds, if nextping was set to 20 seconds
274 * we end up waiting 20 seconds. This is stupid. :-)
275 * I will optimise (hah!) check_pings() once I've finished working on
276 * tidying up other network IO evilnesses.
281 check_pings(void *notused
)
283 check_pings_list(&lclient_list
);
284 check_pings_list(&serv_list
);
285 check_unknowns_list(&unknown_list
);
291 * inputs - pointer to list to check
296 check_pings_list(dlink_list
* list
)
298 char scratch
[32]; /* way too generous but... */
299 struct Client
*client_p
; /* current local client_p being examined */
300 int ping
= 0; /* ping time value from client */
301 dlink_node
*ptr
, *next_ptr
;
303 DLINK_FOREACH_SAFE(ptr
, next_ptr
, list
->head
)
305 client_p
= ptr
->data
;
307 if(!MyConnect(client_p
) || IsDead(client_p
))
310 ping
= get_client_ping(client_p
);
312 if(ping
< (CurrentTime
- client_p
->localClient
->lasttime
))
315 * If the client/server hasnt talked to us in 2*ping seconds
316 * and it has a ping time, then close its connection.
318 if(((CurrentTime
- client_p
->localClient
->lasttime
) >= (2 * ping
)
319 && (client_p
->flags
& FLAGS_PINGSENT
)))
321 if(IsServer(client_p
))
323 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
324 "No response from %s, closing link",
325 get_server_name(client_p
, HIDE_IP
));
327 "No response from %s, closing link",
328 log_client_name(client_p
, HIDE_IP
));
330 (void) ircsnprintf(scratch
, sizeof(scratch
),
331 "Ping timeout: %d seconds",
332 (int) (CurrentTime
- client_p
->localClient
->lasttime
));
334 exit_client(client_p
, client_p
, &me
, scratch
);
337 else if((client_p
->flags
& FLAGS_PINGSENT
) == 0)
340 * if we havent PINGed the connection and we havent
341 * heard from it in a while, PING it to make sure
344 client_p
->flags
|= FLAGS_PINGSENT
;
345 /* not nice but does the job */
346 client_p
->localClient
->lasttime
= CurrentTime
- ping
;
347 sendto_one(client_p
, "PING :%s", me
.name
);
356 * check_unknowns_list
358 * inputs - pointer to list of unknown clients
360 * side effects - unknown clients get marked for termination after n seconds
363 check_unknowns_list(dlink_list
* list
)
365 dlink_node
*ptr
, *next_ptr
;
366 struct Client
*client_p
;
369 DLINK_FOREACH_SAFE(ptr
, next_ptr
, list
->head
)
371 client_p
= ptr
->data
;
373 if(IsDead(client_p
) || IsClosing(client_p
))
377 * Check UNKNOWN connections - if they have been in this state
378 * for > 30s, close them.
381 timeout
= IsAnyServer(client_p
) ? ConfigFileEntry
.connect_timeout
: 30;
382 if((CurrentTime
- client_p
->localClient
->firsttime
) > timeout
)
384 if(IsAnyServer(client_p
))
386 sendto_realops_snomask(SNO_GENERAL
, is_remote_connect(client_p
) ? L_NETWIDE
: L_ALL
,
387 "No response from %s, closing link",
388 get_server_name(client_p
, HIDE_IP
));
390 "No response from %s, closing link",
391 log_client_name(client_p
, HIDE_IP
));
393 exit_client(client_p
, client_p
, &me
, "Connection timed out");
399 notify_banned_client(struct Client
*client_p
, struct ConfItem
*aconf
, int ban
)
401 static const char conn_closed
[] = "Connection closed";
402 static const char d_lined
[] = "D-lined";
403 static const char k_lined
[] = "K-lined";
404 static const char g_lined
[] = "G-lined";
405 const char *reason
= NULL
;
406 const char *exit_reason
= conn_closed
;
408 if(ConfigFileEntry
.kline_with_reason
&& !EmptyString(aconf
->passwd
))
410 reason
= aconf
->passwd
;
411 exit_reason
= aconf
->passwd
;
415 switch (aconf
->status
)
429 if(ban
== D_LINED
&& !IsPerson(client_p
))
430 sendto_one(client_p
, "NOTICE DLINE :*** You have been D-lined");
432 sendto_one(client_p
, form_str(ERR_YOUREBANNEDCREEP
),
433 me
.name
, client_p
->name
, reason
);
435 exit_client(client_p
, client_p
, &me
,
436 EmptyString(ConfigFileEntry
.kline_reason
) ? exit_reason
:
437 ConfigFileEntry
.kline_reason
);
444 * side effects - Check all connections for a pending k/d/gline against the
445 * client, exit the client if found.
448 check_banned_lines(void)
450 struct Client
*client_p
; /* current local client_p being examined */
451 struct ConfItem
*aconf
= NULL
;
452 dlink_node
*ptr
, *next_ptr
;
454 DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
456 client_p
= ptr
->data
;
461 /* if there is a returned struct ConfItem then kill it */
462 if((aconf
= find_dline((struct sockaddr
*)&client_p
->localClient
->ip
, client_p
->localClient
->ip
.ss_family
)))
464 if(aconf
->status
& CONF_EXEMPTDLINE
)
467 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
468 "DLINE active for %s",
469 get_client_name(client_p
, HIDE_IP
));
471 notify_banned_client(client_p
, aconf
, D_LINED
);
472 continue; /* and go examine next fd/client_p */
475 if(!IsPerson(client_p
))
478 if((aconf
= find_kline(client_p
)) != NULL
)
480 if(IsExemptKline(client_p
))
482 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
483 "KLINE over-ruled for %s, client is kline_exempt [%s@%s]",
484 get_client_name(client_p
, HIDE_IP
),
485 aconf
->user
, aconf
->host
);
489 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
490 "KLINE active for %s",
491 get_client_name(client_p
, HIDE_IP
));
492 notify_banned_client(client_p
, aconf
, K_LINED
);
495 else if((aconf
= find_gline(client_p
)) != NULL
)
497 if(IsExemptKline(client_p
))
499 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
500 "GLINE over-ruled for %s, client is kline_exempt [%s@%s]",
501 get_client_name(client_p
, HIDE_IP
),
502 aconf
->user
, aconf
->host
);
506 if(IsExemptGline(client_p
))
508 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
509 "GLINE over-ruled for %s, client is gline_exempt [%s@%s]",
510 get_client_name(client_p
, HIDE_IP
),
511 aconf
->user
, aconf
->host
);
515 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
516 "GLINE active for %s",
517 get_client_name(client_p
, HIDE_IP
));
519 notify_banned_client(client_p
, aconf
, G_LINED
);
522 else if((aconf
= find_xline(client_p
->info
, 1)) != NULL
)
524 if(IsExemptKline(client_p
))
526 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
527 "XLINE over-ruled for %s, client is kline_exempt [%s]",
528 get_client_name(client_p
, HIDE_IP
),
533 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "XLINE active for %s",
534 get_client_name(client_p
, HIDE_IP
));
536 (void) exit_client(client_p
, client_p
, &me
, "Bad user info");
541 /* also check the unknowns list for new dlines */
542 DLINK_FOREACH_SAFE(ptr
, next_ptr
, unknown_list
.head
)
544 client_p
= ptr
->data
;
546 if((aconf
= find_dline((struct sockaddr
*)&client_p
->localClient
->ip
,client_p
->localClient
->ip
.ss_family
)))
548 if(aconf
->status
& CONF_EXEMPTDLINE
)
551 notify_banned_client(client_p
, aconf
, D_LINED
);
557 /* check_klines_event()
561 * side effects - check_klines() is called, kline_queued unset
564 check_klines_event(void *unused
)
574 * side effects - all clients will be checked for klines
579 struct Client
*client_p
;
580 struct ConfItem
*aconf
;
582 dlink_node
*next_ptr
;
584 DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
586 client_p
= ptr
->data
;
588 if(IsMe(client_p
) || !IsPerson(client_p
))
591 if((aconf
= find_kline(client_p
)) != NULL
)
593 if(IsExemptKline(client_p
))
595 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
596 "KLINE over-ruled for %s, client is kline_exempt",
597 get_client_name(client_p
, HIDE_IP
));
601 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
602 "KLINE active for %s",
603 get_client_name(client_p
, HIDE_IP
));
605 notify_banned_client(client_p
, aconf
, K_LINED
);
615 * side effects - all clients will be checked for glines
620 struct Client
*client_p
;
621 struct ConfItem
*aconf
;
623 dlink_node
*next_ptr
;
625 DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
627 client_p
= ptr
->data
;
629 if(IsMe(client_p
) || !IsPerson(client_p
))
632 if((aconf
= find_gline(client_p
)) != NULL
)
634 if(IsExemptKline(client_p
))
636 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
637 "GLINE over-ruled for %s, client is kline_exempt",
638 get_client_name(client_p
, HIDE_IP
));
642 if(IsExemptGline(client_p
))
644 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
645 "GLINE over-ruled for %s, client is gline_exempt",
646 get_client_name(client_p
, HIDE_IP
));
650 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
651 "GLINE active for %s",
652 get_client_name(client_p
, HIDE_IP
));
654 notify_banned_client(client_p
, aconf
, K_LINED
);
664 * side effects - all clients will be checked for dlines
669 struct Client
*client_p
;
670 struct ConfItem
*aconf
;
672 dlink_node
*next_ptr
;
674 DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
676 client_p
= ptr
->data
;
681 if((aconf
= find_dline((struct sockaddr
*)&client_p
->localClient
->ip
,client_p
->localClient
->ip
.ss_family
)) != NULL
)
683 if(aconf
->status
& CONF_EXEMPTDLINE
)
686 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
687 "DLINE active for %s",
688 get_client_name(client_p
, HIDE_IP
));
690 notify_banned_client(client_p
, aconf
, D_LINED
);
695 /* dlines need to be checked against unknowns too */
696 DLINK_FOREACH_SAFE(ptr
, next_ptr
, unknown_list
.head
)
698 client_p
= ptr
->data
;
700 if((aconf
= find_dline((struct sockaddr
*)&client_p
->localClient
->ip
,client_p
->localClient
->ip
.ss_family
)) != NULL
)
702 if(aconf
->status
& CONF_EXEMPTDLINE
)
705 notify_banned_client(client_p
, aconf
, D_LINED
);
714 * side effects - all clients will be checked for xlines
719 struct Client
*client_p
;
720 struct ConfItem
*aconf
;
722 dlink_node
*next_ptr
;
724 DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
726 client_p
= ptr
->data
;
728 if(IsMe(client_p
) || !IsPerson(client_p
))
731 if((aconf
= find_xline(client_p
->info
, 1)) != NULL
)
733 if(IsExemptKline(client_p
))
735 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
736 "XLINE over-ruled for %s, client is kline_exempt",
737 get_client_name(client_p
, HIDE_IP
));
741 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "XLINE active for %s",
742 get_client_name(client_p
, HIDE_IP
));
744 (void) exit_client(client_p
, client_p
, &me
, "Bad user info");
751 * update_client_exit_stats
753 * input - pointer to client
758 update_client_exit_stats(struct Client
*client_p
)
760 if(IsServer(client_p
))
762 sendto_realops_snomask(SNO_EXTERNAL
, L_ALL
,
763 "Server %s split from %s",
764 client_p
->name
, client_p
->servptr
->name
);
765 if(HasSentEob(client_p
))
768 else if(IsClient(client_p
))
773 if(IsInvisible(client_p
))
777 if(splitchecking
&& !splitmode
)
778 check_splitmode(NULL
);
782 * release_client_state
784 * input - pointer to client to release
789 release_client_state(struct Client
*client_p
)
791 if(client_p
->user
!= NULL
)
793 free_user(client_p
->user
, client_p
); /* try this here */
797 if(client_p
->serv
->user
!= NULL
)
798 free_user(client_p
->serv
->user
, client_p
);
799 if(client_p
->serv
->fullcaps
)
800 MyFree(client_p
->serv
->fullcaps
);
801 MyFree(client_p
->serv
);
806 * remove_client_from_list
807 * inputs - point to client to remove
809 * side effects - taken the code from ExitOneClient() for this
810 * and placed it here. - avalon
813 remove_client_from_list(struct Client
*client_p
)
815 s_assert(NULL
!= client_p
);
820 /* A client made with make_client()
821 * is on the unknown_list until removed.
822 * If it =does= happen to exit before its removed from that list
823 * and its =not= on the global_client_list, it will core here.
824 * short circuit that case now -db
826 if(client_p
->node
.prev
== NULL
&& client_p
->node
.next
== NULL
)
829 dlinkDelete(&client_p
->node
, &global_client_list
);
831 update_client_exit_stats(client_p
);
836 * find_person - find person by (nick)name.
837 * inputs - pointer to name
838 * output - return client pointer
842 find_person(const char *name
)
844 struct Client
*c2ptr
;
846 c2ptr
= find_client(name
);
848 if(c2ptr
&& IsPerson(c2ptr
))
854 find_named_person(const char *name
)
856 struct Client
*c2ptr
;
858 c2ptr
= find_named_client(name
);
860 if(c2ptr
&& IsPerson(c2ptr
))
867 * find_chasing - find the client structure for a nick name (user)
868 * using history mechanism if necessary. If the client is not found,
869 * an error message (NO SUCH NICK) is generated. If the client was found
870 * through the history, chasing will be 1 and otherwise 0.
873 find_chasing(struct Client
*source_p
, const char *user
, int *chasing
)
877 if(MyClient(source_p
))
878 who
= find_named_person(user
);
880 who
= find_person(user
);
885 if(who
|| IsDigit(*user
))
888 if(!(who
= get_history(user
, (long) KILLCHASETIMELIMIT
)))
890 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
891 form_str(ERR_NOSUCHNICK
), user
);
900 * get_client_name - Return the name of the client
901 * for various tracking and
902 * admin purposes. The main purpose of this function is to
903 * return the "socket host" name of the client, if that
904 * differs from the advertised name (other than case).
905 * But, this can be used to any client structure.
908 * Watch out the allocation of "nbuf", if either source_p->name
909 * or source_p->sockhost gets changed into pointers instead of
910 * directly allocated within the structure...
913 * Function return either a pointer to the structure (source_p) or
914 * to internal buffer (nbuf). *NEVER* use the returned pointer
915 * to modify what it points!!!
919 get_client_name(struct Client
*client
, int showip
)
921 static char nbuf
[HOSTLEN
* 2 + USERLEN
+ 5];
923 s_assert(NULL
!= client
);
927 if(MyConnect(client
))
929 if(!irccmp(client
->name
, client
->host
))
932 if(ConfigFileEntry
.hide_spoof_ips
&&
933 showip
== SHOW_IP
&& IsIPSpoof(client
))
935 #ifdef HIDE_SERVERS_IPS
936 if(IsAnyServer(client
))
940 /* And finally, let's get the host information, ip or name */
944 ircsnprintf(nbuf
, sizeof(nbuf
), "%s[%s@%s]",
945 client
->name
, client
->username
,
949 ircsnprintf(nbuf
, sizeof(nbuf
), "%s[%s@255.255.255.255]",
950 client
->name
, client
->username
);
953 ircsnprintf(nbuf
, sizeof(nbuf
), "%s[%s@%s]",
954 client
->name
, client
->username
, client
->host
);
959 /* As pointed out by Adel Mezibra
960 * Neph|l|m@EFnet. Was missing a return here.
966 get_server_name(struct Client
*target_p
, int showip
)
968 static char nbuf
[HOSTLEN
* 2 + USERLEN
+ 5];
973 if(!MyConnect(target_p
) || !irccmp(target_p
->name
, target_p
->host
))
974 return target_p
->name
;
976 #ifdef HIDE_SERVERS_IPS
977 if(EmptyString(target_p
->name
))
979 ircsnprintf(nbuf
, sizeof(nbuf
), "[%s@255.255.255.255]",
984 return target_p
->name
;
990 ircsnprintf(nbuf
, sizeof(nbuf
), "%s[%s@%s]",
991 target_p
->name
, target_p
->username
,
996 ircsnprintf(nbuf
, sizeof(nbuf
), "%s[%s@255.255.255.255]",
997 target_p
->name
, target_p
->username
);
1000 ircsnprintf(nbuf
, sizeof(nbuf
), "%s[%s@%s]",
1001 target_p
->name
, target_p
->username
,
1008 /* log_client_name()
1010 * This version is the same as get_client_name, but doesnt contain the
1011 * code that will hide IPs always. This should be used for logfiles.
1014 log_client_name(struct Client
*target_p
, int showip
)
1016 static char nbuf
[HOSTLEN
* 2 + USERLEN
+ 5];
1018 if(target_p
== NULL
)
1021 if(MyConnect(target_p
))
1023 if(irccmp(target_p
->name
, target_p
->host
) == 0)
1024 return target_p
->name
;
1029 ircsnprintf(nbuf
, sizeof(nbuf
), "%s[%s@%s]", target_p
->name
,
1030 target_p
->username
, target_p
->sockhost
);
1034 ircsnprintf(nbuf
, sizeof(nbuf
), "%s[%s@255.255.255.255]",
1035 target_p
->name
, target_p
->username
);
1038 ircsnprintf(nbuf
, sizeof(nbuf
), "%s[%s@%s]", target_p
->name
,
1039 target_p
->username
, target_p
->host
);
1045 return target_p
->name
;
1048 /* is_remote_connect - Returns whether a server was /connect'ed by a remote
1049 * oper (send notices netwide) */
1051 is_remote_connect(struct Client
*client_p
)
1053 struct Client
*oper
;
1055 if (client_p
->serv
== NULL
)
1057 oper
= find_named_person(client_p
->serv
->by
);
1058 return oper
!= NULL
&& IsOper(oper
) && !MyConnect(oper
);
1062 free_exited_clients(void *unused
)
1064 dlink_node
*ptr
, *next
;
1065 struct Client
*target_p
;
1067 DLINK_FOREACH_SAFE(ptr
, next
, dead_list
.head
)
1069 target_p
= ptr
->data
;
1071 #ifdef DEBUG_EXITED_CLIENTS
1073 struct abort_client
*abt
;
1077 DLINK_FOREACH(aptr
, abort_list
.head
)
1080 if(abt
->client
== target_p
)
1083 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1084 "On abort_list: %s stat: %u flags: %u/%u handler: %c",
1085 target_p
->name
, (unsigned int) target_p
->status
,
1086 target_p
->flags
, target_p
->flags2
, target_p
->handler
);
1087 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1088 "Please report this to the charybdis developers!");
1095 dlinkDestroy(ptr
, &dead_list
);
1101 if(ptr
->data
== NULL
)
1103 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1104 "Warning: null client on dead_list!");
1105 dlinkDestroy(ptr
, &dead_list
);
1108 release_client_state(target_p
);
1109 free_client(target_p
);
1110 dlinkDestroy(ptr
, &dead_list
);
1113 #ifdef DEBUG_EXITED_CLIENTS
1114 DLINK_FOREACH_SAFE(ptr
, next
, dead_remote_list
.head
)
1116 target_p
= ptr
->data
;
1118 if(ptr
->data
== NULL
)
1120 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1121 "Warning: null client on dead_list!");
1122 dlinkDestroy(ptr
, &dead_list
);
1125 release_client_state(target_p
);
1126 free_client(target_p
);
1127 dlinkDestroy(ptr
, &dead_remote_list
);
1134 ** Recursively send QUITs and SQUITs for source_p and all its dependent clients
1135 ** and servers to those servers that need them. A server needs the client
1136 ** QUITs if it can't figure them out from the SQUIT (ie pre-TS4) or if it
1137 ** isn't getting the SQUIT because of @#(*&@)# hostmasking. With TS4, once
1138 ** a link gets a SQUIT, it doesn't need any QUIT/SQUITs for clients depending
1139 ** on that one -orabidoo
1142 recurse_send_quits(struct Client
*client_p
, struct Client
*source_p
,
1143 struct Client
*to
, const char *comment1
,
1144 const char *comment
)
1146 struct Client
*target_p
;
1147 dlink_node
*ptr
, *ptr_next
;
1148 /* If this server can handle quit storm (QS) removal
1149 * of dependents, just send the SQUIT
1152 if(IsCapable(to
, CAP_QS
))
1154 sendto_one(to
, "SQUIT %s :%s",
1155 get_id(source_p
, to
), comment
);
1159 DLINK_FOREACH_SAFE(ptr
, ptr_next
, source_p
->serv
->users
.head
)
1161 target_p
= ptr
->data
;
1162 sendto_one(to
, ":%s QUIT :%s", target_p
->name
, comment1
);
1164 DLINK_FOREACH_SAFE(ptr
, ptr_next
, source_p
->serv
->servers
.head
)
1166 target_p
= ptr
->data
;
1167 recurse_send_quits(client_p
, target_p
, to
, comment1
, comment
);
1169 sendto_one(to
, "SQUIT %s :%s", source_p
->name
, comment
);
1174 ** Remove all clients that depend on source_p; assumes all (S)QUITs have
1175 ** already been sent. we make sure to exit a server's dependent clients
1176 ** and servers before the server itself; exit_one_client takes care of
1177 ** actually removing things off llists. tweaked from +CSr31 -orabidoo
1180 * added sanity test code.... source_p->serv might be NULL...
1183 recurse_remove_clients(struct Client
*source_p
, const char *comment
)
1185 struct Client
*target_p
;
1186 dlink_node
*ptr
, *ptr_next
;
1191 if(source_p
->serv
== NULL
) /* oooops. uh this is actually a major bug */
1194 /* this is very ugly, but it saves cpu :P */
1195 if(ConfigFileEntry
.nick_delay
> 0)
1197 DLINK_FOREACH_SAFE(ptr
, ptr_next
, source_p
->serv
->users
.head
)
1199 target_p
= ptr
->data
;
1200 target_p
->flags
|= FLAGS_KILLED
;
1201 add_nd_entry(target_p
->name
);
1203 if(!IsDead(target_p
) && !IsClosing(target_p
))
1204 exit_remote_client(NULL
, target_p
, &me
, comment
);
1209 DLINK_FOREACH_SAFE(ptr
, ptr_next
, source_p
->serv
->users
.head
)
1211 target_p
= ptr
->data
;
1212 target_p
->flags
|= FLAGS_KILLED
;
1214 if(!IsDead(target_p
) && !IsClosing(target_p
))
1215 exit_remote_client(NULL
, target_p
, &me
, comment
);
1219 DLINK_FOREACH_SAFE(ptr
, ptr_next
, source_p
->serv
->servers
.head
)
1221 target_p
= ptr
->data
;
1222 recurse_remove_clients(target_p
, comment
);
1223 qs_server(NULL
, target_p
, &me
, comment
);
1228 ** Remove *everything* that depends on source_p, from all lists, and sending
1229 ** all necessary QUITs and SQUITs. source_p itself is still on the lists,
1230 ** and its SQUITs have been sent except for the upstream one -orabidoo
1233 remove_dependents(struct Client
*client_p
,
1234 struct Client
*source_p
,
1235 struct Client
*from
, const char *comment
, const char *comment1
)
1238 dlink_node
*ptr
, *next
;
1240 DLINK_FOREACH_SAFE(ptr
, next
, serv_list
.head
)
1244 if(IsMe(to
) || to
== source_p
->from
||
1245 (to
== client_p
&& IsCapable(to
, CAP_QS
)))
1248 recurse_send_quits(client_p
, source_p
, to
, comment1
, comment
);
1251 recurse_remove_clients(source_p
, comment1
);
1255 exit_aborted_clients(void *unused
)
1257 struct abort_client
*abt
;
1258 dlink_node
*ptr
, *next
;
1259 DLINK_FOREACH_SAFE(ptr
, next
, abort_list
.head
)
1263 #ifdef DEBUG_EXITED_CLIENTS
1265 if(dlinkFind(abt
->client
, &dead_list
))
1268 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1269 "On dead_list: %s stat: %u flags: %u/%u handler: %c",
1270 abt
->client
->name
, (unsigned int) abt
->client
->status
,
1271 abt
->client
->flags
, abt
->client
->flags2
, abt
->client
->handler
);
1272 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1273 "Please report this to the charybdis developers!");
1279 s_assert(*((unsigned long*)abt
->client
) != 0xdeadbeef); /* This is lame but its a debug thing */
1280 dlinkDelete(ptr
, &abort_list
);
1282 if(IsAnyServer(abt
->client
))
1283 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1284 "Closing link to %s: %s",
1285 get_server_name(abt
->client
, HIDE_IP
), abt
->notice
);
1287 /* its no longer on abort list - we *must* remove
1288 * FLAGS_CLOSING otherwise exit_client() will not run --fl
1290 abt
->client
->flags
&= ~FLAGS_CLOSING
;
1291 exit_client(abt
->client
, abt
->client
, &me
, abt
->notice
);
1298 * dead_link - Adds client to a list of clients that need an exit_client()
1302 dead_link(struct Client
*client_p
)
1304 struct abort_client
*abt
;
1306 s_assert(!IsMe(client_p
));
1307 if(IsDead(client_p
) || IsClosing(client_p
) || IsMe(client_p
))
1310 abt
= (struct abort_client
*) MyMalloc(sizeof(struct abort_client
));
1312 if(client_p
->flags
& FLAGS_SENDQEX
)
1313 strlcpy(abt
->notice
, "Max SendQ exceeded", sizeof(abt
->notice
));
1315 ircsnprintf(abt
->notice
, sizeof(abt
->notice
), "Write error: %s", strerror(errno
));
1317 abt
->client
= client_p
;
1318 SetIOError(client_p
);
1320 SetClosing(client_p
);
1321 dlinkAdd(abt
, &abt
->node
, &abort_list
);
1325 /* This does the remove of the user from channels..local or remote */
1327 exit_generic_client(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1328 const char *comment
)
1330 dlink_node
*ptr
, *next_ptr
;
1332 if(IsOper(source_p
))
1333 dlinkFindDestroy(source_p
, &oper_list
);
1335 sendto_common_channels_local(source_p
, ":%s!%s@%s QUIT :%s",
1337 source_p
->username
, source_p
->host
, comment
);
1339 remove_user_from_channels(source_p
);
1341 /* Should not be in any channels now */
1342 s_assert(source_p
->user
->channel
.head
== NULL
);
1344 /* Clean up invitefield */
1345 DLINK_FOREACH_SAFE(ptr
, next_ptr
, source_p
->user
->invited
.head
)
1347 del_invite(ptr
->data
, source_p
);
1350 /* Clean up allow lists */
1351 del_all_accepts(source_p
);
1353 add_history(source_p
, 0);
1354 off_history(source_p
);
1356 monitor_signoff(source_p
);
1358 if(has_id(source_p
))
1359 del_from_id_hash(source_p
->id
, source_p
);
1361 del_from_hostname_hash(source_p
->orighost
, source_p
);
1362 del_from_client_hash(source_p
->name
, source_p
);
1363 remove_client_from_list(source_p
);
1367 * Assumes IsPerson(source_p) && !MyConnect(source_p)
1371 exit_remote_client(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1372 const char *comment
)
1374 exit_generic_client(client_p
, source_p
, from
, comment
);
1376 if(source_p
->servptr
&& source_p
->servptr
->serv
)
1378 dlinkDelete(&source_p
->lnode
, &source_p
->servptr
->serv
->users
);
1381 if((source_p
->flags
& FLAGS_KILLED
) == 0)
1383 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
,
1384 ":%s QUIT :%s", use_id(source_p
), comment
);
1385 sendto_server(client_p
, NULL
, NOCAPS
, CAP_TS6
,
1386 ":%s QUIT :%s", source_p
->name
, comment
);
1390 #ifdef DEBUG_EXITED_CLIENTS
1391 dlinkAddAlloc(source_p
, &dead_remote_list
);
1393 dlinkAddAlloc(source_p
, &dead_list
);
1395 return(CLIENT_EXITED
);
1399 * This assumes IsUnknown(source_p) == TRUE and MyConnect(source_p) == TRUE
1403 exit_unknown_client(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1404 const char *comment
)
1406 delete_auth_queries(source_p
);
1407 client_flush_input(source_p
);
1408 del_unknown_ip(source_p
);
1409 dlinkDelete(&source_p
->localClient
->tnode
, &unknown_list
);
1411 if(!IsIOError(source_p
))
1412 sendto_one(source_p
, "ERROR :Closing Link: %s (%s)",
1413 source_p
->user
!= NULL
? source_p
->host
: "127.0.0.1",
1416 close_connection(source_p
);
1418 if(has_id(source_p
))
1419 del_from_id_hash(source_p
->id
, source_p
);
1421 del_from_hostname_hash(source_p
->host
, source_p
);
1422 del_from_client_hash(source_p
->name
, source_p
);
1423 remove_client_from_list(source_p
);
1425 dlinkAddAlloc(source_p
, &dead_list
);
1427 /* Note that we don't need to add unknowns to the dead_list */
1428 return(CLIENT_EXITED
);
1432 exit_remote_server(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1433 const char *comment
)
1435 static char comment1
[(HOSTLEN
*2)+2];
1436 static char newcomment
[BUFSIZE
];
1437 struct Client
*target_p
;
1439 if(ConfigServerHide
.flatten_links
)
1440 strcpy(comment1
, "*.net *.split");
1443 strcpy(comment1
, source_p
->servptr
->name
);
1444 strcat(comment1
, " ");
1445 strcat(comment1
, source_p
->name
);
1448 ircsnprintf(newcomment
, sizeof(newcomment
), "by %s: %s",
1449 from
->name
, comment
);
1451 if(source_p
->serv
!= NULL
)
1452 remove_dependents(client_p
, source_p
, from
, IsPerson(from
) ? newcomment
: comment
, comment1
);
1454 if(source_p
->servptr
&& source_p
->servptr
->serv
)
1455 dlinkDelete(&source_p
->lnode
, &source_p
->servptr
->serv
->servers
);
1459 dlinkFindDestroy(source_p
, &global_serv_list
);
1460 target_p
= source_p
->from
;
1462 if(target_p
!= NULL
&& IsServer(target_p
) && target_p
!= client_p
&&
1463 !IsMe(target_p
) && (source_p
->flags
& FLAGS_KILLED
) == 0)
1465 sendto_one(target_p
, ":%s SQUIT %s :%s",
1466 get_id(from
, target_p
), get_id(source_p
, target_p
),
1470 if(has_id(source_p
))
1471 del_from_id_hash(source_p
->id
, source_p
);
1473 del_from_client_hash(source_p
->name
, source_p
);
1474 remove_client_from_list(source_p
);
1475 scache_split(source_p
->serv
->nameinfo
);
1478 #ifdef DEBUG_EXITED_CLIENTS
1479 dlinkAddAlloc(source_p
, &dead_remote_list
);
1481 dlinkAddAlloc(source_p
, &dead_list
);
1487 qs_server(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1488 const char *comment
)
1490 struct Client
*target_p
;
1492 if(source_p
->servptr
&& source_p
->servptr
->serv
)
1493 dlinkDelete(&source_p
->lnode
, &source_p
->servptr
->serv
->servers
);
1497 dlinkFindDestroy(source_p
, &global_serv_list
);
1498 target_p
= source_p
->from
;
1500 if(has_id(source_p
))
1501 del_from_id_hash(source_p
->id
, source_p
);
1503 del_from_client_hash(source_p
->name
, source_p
);
1504 remove_client_from_list(source_p
);
1505 scache_split(source_p
->serv
->nameinfo
);
1508 dlinkAddAlloc(source_p
, &dead_list
);
1513 exit_local_server(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1514 const char *comment
)
1516 static char comment1
[(HOSTLEN
*2)+2];
1517 static char newcomment
[BUFSIZE
];
1518 unsigned int sendk
, recvk
;
1520 dlinkDelete(&source_p
->localClient
->tnode
, &serv_list
);
1521 dlinkFindDestroy(source_p
, &global_serv_list
);
1523 unset_chcap_usage_counts(source_p
);
1524 sendk
= source_p
->localClient
->sendK
;
1525 recvk
= source_p
->localClient
->receiveK
;
1527 /* Always show source here, so the server notices show
1528 * which side initiated the split -- jilles
1530 ircsnprintf(newcomment
, sizeof(newcomment
), "by %s: %s",
1531 from
== source_p
? me
.name
: from
->name
, comment
);
1532 if (!IsIOError(source_p
))
1533 sendto_one(source_p
, "SQUIT %s :%s", use_id(source_p
),
1535 if(client_p
!= NULL
&& source_p
!= client_p
&& !IsIOError(source_p
))
1537 sendto_one(source_p
, "ERROR :Closing Link: 127.0.0.1 %s (%s)",
1538 source_p
->name
, comment
);
1541 if(source_p
->servptr
&& source_p
->servptr
->serv
)
1542 dlinkDelete(&source_p
->lnode
, &source_p
->servptr
->serv
->servers
);
1547 close_connection(source_p
);
1549 if(ConfigServerHide
.flatten_links
)
1550 strcpy(comment1
, "*.net *.split");
1553 strcpy(comment1
, source_p
->servptr
->name
);
1554 strcat(comment1
, " ");
1555 strcat(comment1
, source_p
->name
);
1558 if(source_p
->serv
!= NULL
)
1559 remove_dependents(client_p
, source_p
, from
, IsPerson(from
) ? newcomment
: comment
, comment1
);
1561 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s was connected"
1562 " for %ld seconds. %d/%d sendK/recvK.",
1563 source_p
->name
, CurrentTime
- source_p
->localClient
->firsttime
, sendk
, recvk
);
1565 ilog(L_SERVER
, "%s was connected for %ld seconds. %d/%d sendK/recvK.",
1566 source_p
->name
, CurrentTime
- source_p
->localClient
->firsttime
, sendk
, recvk
);
1568 if(has_id(source_p
))
1569 del_from_id_hash(source_p
->id
, source_p
);
1571 del_from_client_hash(source_p
->name
, source_p
);
1572 remove_client_from_list(source_p
);
1573 scache_split(source_p
->serv
->nameinfo
);
1576 dlinkAddAlloc(source_p
, &dead_list
);
1582 * This assumes IsPerson(source_p) == TRUE && MyConnect(source_p) == TRUE
1586 exit_local_client(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1587 const char *comment
)
1589 unsigned long on_for
;
1591 exit_generic_client(client_p
, source_p
, from
, comment
);
1592 clear_monitor(source_p
);
1594 s_assert(IsPerson(source_p
));
1595 client_flush_input(source_p
);
1596 dlinkDelete(&source_p
->localClient
->tnode
, &lclient_list
);
1597 dlinkDelete(&source_p
->lnode
, &me
.serv
->users
);
1599 if(IsOper(source_p
))
1600 dlinkFindDestroy(source_p
, &local_oper_list
);
1602 sendto_realops_snomask(SNO_CCONN
, L_ALL
,
1603 "Client exiting: %s (%s@%s) [%s] [%s]",
1605 source_p
->username
, source_p
->host
, comment
,
1606 show_ip(NULL
, source_p
) ? source_p
->sockhost
: "255.255.255.255");
1608 sendto_realops_snomask(SNO_CCONNEXT
, L_ALL
,
1609 "CLIEXIT %s %s %s %s 0 %s",
1610 source_p
->name
, source_p
->username
, source_p
->host
,
1611 show_ip(NULL
, source_p
) ? source_p
->sockhost
: "255.255.255.255",
1614 on_for
= CurrentTime
- source_p
->localClient
->firsttime
;
1616 ilog(L_USER
, "%s (%3lu:%02lu:%02lu): %s!%s@%s %d/%d",
1617 myctime(CurrentTime
), on_for
/ 3600,
1618 (on_for
% 3600) / 60, on_for
% 60,
1619 source_p
->name
, source_p
->username
, source_p
->host
,
1620 source_p
->localClient
->sendK
, source_p
->localClient
->receiveK
);
1622 sendto_one(source_p
, "ERROR :Closing Link: %s (%s)", source_p
->host
, comment
);
1623 close_connection(source_p
);
1625 if((source_p
->flags
& FLAGS_KILLED
) == 0)
1627 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
,
1628 ":%s QUIT :%s", use_id(source_p
), comment
);
1629 sendto_server(client_p
, NULL
, NOCAPS
, CAP_TS6
,
1630 ":%s QUIT :%s", source_p
->name
, comment
);
1634 dlinkAddAlloc(source_p
, &dead_list
);
1635 return(CLIENT_EXITED
);
1640 ** exit_client - This is old "m_bye". Name changed, because this is not a
1641 ** protocol function, but a general server utility function.
1643 ** This function exits a client of *any* type (user, server, etc)
1644 ** from this server. Also, this generates all necessary prototol
1645 ** messages that this exit may cause.
1647 ** 1) If the client is a local client, then this implicitly
1648 ** exits all other clients depending on this connection (e.g.
1649 ** remote clients having 'from'-field that points to this.
1651 ** 2) If the client is a remote client, then only this is exited.
1653 ** For convenience, this function returns a suitable value for
1654 ** m_function return value:
1656 ** CLIENT_EXITED if (client_p == source_p)
1657 ** 0 if (client_p != source_p)
1660 exit_client(struct Client
*client_p
, /* The local client originating the
1661 * exit or NULL, if this exit is
1662 * generated by this server for
1664 * This will not get any of the
1665 * generated messages. */
1666 struct Client
*source_p
, /* Client exiting */
1667 struct Client
*from
, /* Client firing off this Exit,
1669 const char *comment
/* Reason for the exit */
1672 hook_data_client_exit hdata
;
1673 if(IsClosing(source_p
))
1676 /* note, this HAS to be here, when we exit a client we attempt to
1677 * send them data, if this generates a write error we must *not* add
1678 * them to the abort list --fl
1680 SetClosing(source_p
);
1682 hdata
.local_link
= client_p
;
1683 hdata
.target
= source_p
;
1685 hdata
.comment
= comment
;
1686 call_hook(h_client_exit
, &hdata
);
1688 if(MyConnect(source_p
))
1690 /* Local clients of various types */
1691 if(IsPerson(source_p
))
1692 return exit_local_client(client_p
, source_p
, from
, comment
);
1693 else if(IsServer(source_p
))
1694 return exit_local_server(client_p
, source_p
, from
, comment
);
1695 /* IsUnknown || IsConnecting || IsHandShake */
1696 else if(!IsReject(source_p
))
1697 return exit_unknown_client(client_p
, source_p
, from
, comment
);
1702 if(IsPerson(source_p
))
1703 return exit_remote_client(client_p
, source_p
, from
, comment
);
1704 else if(IsServer(source_p
))
1705 return exit_remote_server(client_p
, source_p
, from
, comment
);
1712 * Count up local client memory
1715 /* XXX one common Client list now */
1717 count_local_client_memory(size_t * count
, size_t * local_client_memory_used
)
1720 BlockHeapUsage(lclient_heap
, count
, NULL
, &lusage
);
1721 *local_client_memory_used
= lusage
+ (*count
* (sizeof(MemBlock
) + sizeof(struct Client
)));
1725 * Count up remote client memory
1728 count_remote_client_memory(size_t * count
, size_t * remote_client_memory_used
)
1730 size_t lcount
, rcount
;
1731 BlockHeapUsage(lclient_heap
, &lcount
, NULL
, NULL
);
1732 BlockHeapUsage(client_heap
, &rcount
, NULL
, NULL
);
1733 *count
= rcount
- lcount
;
1734 *remote_client_memory_used
= *count
* (sizeof(MemBlock
) + sizeof(struct Client
));
1739 * accept processing, this adds a form of "caller ID" to ircd
1741 * If a client puts themselves into "caller ID only" mode,
1742 * only clients that match a client pointer they have put on
1743 * the accept list will be allowed to message them.
1745 * [ source.on_allow_list ] -> [ target1 ] -> [ target2 ]
1747 * [target.allow_list] -> [ source1 ] -> [source2 ]
1749 * i.e. a target will have a link list of source pointers it will allow
1750 * each source client then has a back pointer pointing back
1751 * to the client that has it on its accept list.
1752 * This allows for exit_one_client to remove these now bogus entries
1753 * from any client having an accept on them.
1758 * inputs - pointer to exiting client
1760 * side effects - Walk through given clients allow_list and on_allow_list
1761 * remove all references to this client
1764 del_all_accepts(struct Client
*client_p
)
1767 dlink_node
*next_ptr
;
1768 struct Client
*target_p
;
1770 if(MyClient(client_p
) && client_p
->localClient
->allow_list
.head
)
1772 /* clear this clients accept list, and remove them from
1773 * everyones on_accept_list
1775 DLINK_FOREACH_SAFE(ptr
, next_ptr
, client_p
->localClient
->allow_list
.head
)
1777 target_p
= ptr
->data
;
1778 dlinkFindDestroy(client_p
, &target_p
->on_allow_list
);
1779 dlinkDestroy(ptr
, &client_p
->localClient
->allow_list
);
1783 /* remove this client from everyones accept list */
1784 DLINK_FOREACH_SAFE(ptr
, next_ptr
, client_p
->on_allow_list
.head
)
1786 target_p
= ptr
->data
;
1787 dlinkFindDestroy(client_p
, &target_p
->localClient
->allow_list
);
1788 dlinkDestroy(ptr
, &client_p
->on_allow_list
);
1793 * show_ip() - asks if the true IP shoudl be shown when source is
1794 * askin for info about target
1796 * Inputs - source_p who is asking
1797 * - target_p who do we want the info on
1798 * Output - returns 1 if clear IP can be showed, otherwise 0
1799 * Side Effects - none
1803 show_ip(struct Client
*source_p
, struct Client
*target_p
)
1805 if(IsAnyServer(target_p
))
1807 #ifndef HIDE_SERVERS_IPS
1808 if(source_p
== NULL
|| IsOper(source_p
))
1813 else if(IsIPSpoof(target_p
))
1815 /* source == NULL indicates message is being sent
1818 if(!ConfigFileEntry
.hide_spoof_ips
&&
1819 (source_p
== NULL
|| MyOper(source_p
)))
1823 else if(IsDynSpoof(target_p
) && (source_p
!= NULL
&& !IsOper(source_p
)))
1830 show_ip_conf(struct ConfItem
*aconf
, struct Client
*source_p
)
1832 if(IsConfDoSpoofIp(aconf
))
1834 if(!ConfigFileEntry
.hide_spoof_ips
&& MyOper(source_p
))
1849 * side effects - Creates a block heap for struct Users
1852 static BlockHeap
*user_heap
;
1856 user_heap
= BlockHeapCreate(sizeof(struct User
), USER_HEAP_SIZE
);
1864 * inputs - pointer to client struct
1865 * output - pointer to struct User
1866 * side effects - add's an User information block to a client
1867 * if it was not previously allocated.
1870 make_user(struct Client
*client_p
)
1874 user
= client_p
->user
;
1877 user
= (struct User
*) BlockHeapAlloc(user_heap
);
1879 client_p
->user
= user
;
1887 * inputs - pointer to client struct
1888 * output - pointer to server_t
1889 * side effects - add's an Server information block to a client
1890 * if it was not previously allocated.
1893 make_server(struct Client
*client_p
)
1895 server_t
*serv
= client_p
->serv
;
1899 serv
= (server_t
*) MyMalloc(sizeof(server_t
));
1900 client_p
->serv
= serv
;
1902 return client_p
->serv
;
1908 * inputs - pointer to user struct
1909 * - pointer to client struct
1911 * side effects - Decrease user reference count by one and release block,
1912 * if count reaches 0
1915 free_user(struct User
*user
, struct Client
*client_p
)
1917 if(--user
->refcnt
<= 0)
1920 MyFree((char *) user
->away
);
1924 if(user
->refcnt
< 0 || user
->invited
.head
|| user
->channel
.head
)
1926 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1927 "* %#lx user (%s!%s@%s) %#lx %#lx %#lx %lu %d *",
1928 (unsigned long) client_p
,
1929 client_p
? client_p
->
1933 (unsigned long) user
,
1934 (unsigned long) user
->invited
.head
,
1935 (unsigned long) user
->channel
.head
,
1936 dlink_list_length(&user
->channel
),
1938 s_assert(!user
->refcnt
);
1939 s_assert(!user
->invited
.head
);
1940 s_assert(!user
->channel
.head
);
1943 BlockHeapFree(user_heap
, user
);
1952 for(i
= 0; i
< 3; i
++)
1953 current_uid
[i
] = me
.id
[i
];
1955 for(i
= 3; i
< 9; i
++)
1956 current_uid
[i
] = 'A';
1958 current_uid
[9] = '\0';
1967 for(i
= 8; i
> 3; i
--)
1969 if(current_uid
[i
] == 'Z')
1971 current_uid
[i
] = '0';
1974 else if(current_uid
[i
] != '9')
1980 current_uid
[i
] = 'A';
1983 /* if this next if() triggers, we're fucked. */
1984 if(current_uid
[3] == 'Z')
1986 current_uid
[i
] = 'A';
1997 * Close the physical connection. This function must make
1998 * MyConnect(client_p) == FALSE, and set client_p->from == NULL.
2001 close_connection(struct Client
*client_p
)
2003 s_assert(client_p
!= NULL
);
2004 if(client_p
== NULL
)
2007 s_assert(MyConnect(client_p
));
2008 if(!MyConnect(client_p
))
2011 if(IsServer(client_p
))
2013 struct server_conf
*server_p
;
2015 ServerStats
->is_sv
++;
2016 ServerStats
->is_sbs
+= client_p
->localClient
->sendB
;
2017 ServerStats
->is_sbr
+= client_p
->localClient
->receiveB
;
2018 ServerStats
->is_sks
+= client_p
->localClient
->sendK
;
2019 ServerStats
->is_skr
+= client_p
->localClient
->receiveK
;
2020 ServerStats
->is_sti
+= CurrentTime
- client_p
->localClient
->firsttime
;
2021 if(ServerStats
->is_sbs
> 2047)
2023 ServerStats
->is_sks
+= (ServerStats
->is_sbs
>> 10);
2024 ServerStats
->is_sbs
&= 0x3ff;
2026 if(ServerStats
->is_sbr
> 2047)
2028 ServerStats
->is_skr
+= (ServerStats
->is_sbr
>> 10);
2029 ServerStats
->is_sbr
&= 0x3ff;
2033 * If the connection has been up for a long amount of time, schedule
2034 * a 'quick' reconnect, else reset the next-connect cycle.
2036 if((server_p
= find_server_conf(client_p
->name
)) != NULL
)
2039 * Reschedule a faster reconnect, if this was a automatically
2040 * connected configuration entry. (Note that if we have had
2041 * a rehash in between, the status has been changed to
2042 * CONF_ILLEGAL). But only do this if it was a "good" link.
2044 server_p
->hold
= time(NULL
);
2046 (server_p
->hold
- client_p
->localClient
->lasttime
>
2047 HANGONGOODLINK
) ? HANGONRETRYDELAY
: ConFreq(server_p
->class);
2051 else if(IsClient(client_p
))
2053 ServerStats
->is_cl
++;
2054 ServerStats
->is_cbs
+= client_p
->localClient
->sendB
;
2055 ServerStats
->is_cbr
+= client_p
->localClient
->receiveB
;
2056 ServerStats
->is_cks
+= client_p
->localClient
->sendK
;
2057 ServerStats
->is_ckr
+= client_p
->localClient
->receiveK
;
2058 ServerStats
->is_cti
+= CurrentTime
- client_p
->localClient
->firsttime
;
2059 if(ServerStats
->is_cbs
> 2047)
2061 ServerStats
->is_cks
+= (ServerStats
->is_cbs
>> 10);
2062 ServerStats
->is_cbs
&= 0x3ff;
2064 if(ServerStats
->is_cbr
> 2047)
2066 ServerStats
->is_ckr
+= (ServerStats
->is_cbr
>> 10);
2067 ServerStats
->is_cbr
&= 0x3ff;
2071 ServerStats
->is_ni
++;
2073 if(client_p
->localClient
->F
)
2075 /* attempt to flush any pending dbufs. Evil, but .. -- adrian */
2076 if(!IsIOError(client_p
))
2077 send_queued_write(client_p
->localClient
->F
->fd
, client_p
);
2079 comm_close(client_p
->localClient
->F
->fd
);
2080 client_p
->localClient
->F
= NULL
;
2083 if(-1 < client_p
->localClient
->ctrlfd
)
2085 comm_close(client_p
->localClient
->ctrlfd
);
2086 client_p
->localClient
->ctrlfd
= -1;
2089 linebuf_donebuf(&client_p
->localClient
->buf_sendq
);
2090 linebuf_donebuf(&client_p
->localClient
->buf_recvq
);
2091 detach_conf(client_p
);
2093 /* XXX shouldnt really be done here. */
2094 detach_server_conf(client_p
);
2096 client_p
->from
= NULL
; /* ...this should catch them! >:) --msa */
2097 ClearMyConnect(client_p
);
2098 SetIOError(client_p
);
2104 error_exit_client(struct Client
*client_p
, int error
)
2107 * ...hmm, with non-blocking sockets we might get
2108 * here from quite valid reasons, although.. why
2109 * would select report "data available" when there
2110 * wasn't... so, this must be an error anyway... --msa
2111 * actually, EOF occurs when read() returns 0 and
2112 * in due course, select() returns that fd as ready
2113 * for reading even though it ends up being an EOF. -avalon
2116 int current_error
= comm_get_sockerr(client_p
->localClient
->F
->fd
);
2118 SetIOError(client_p
);
2120 if(IsServer(client_p
) || IsHandshake(client_p
))
2124 sendto_realops_snomask(SNO_GENERAL
, is_remote_connect(client_p
) && !IsServer(client_p
) ? L_NETWIDE
: L_ALL
,
2125 "Server %s closed the connection",
2126 get_server_name(client_p
, SHOW_IP
));
2128 ilog(L_SERVER
, "Server %s closed the connection",
2129 log_client_name(client_p
, SHOW_IP
));
2133 sendto_realops_snomask(SNO_GENERAL
, is_remote_connect(client_p
) && !IsServer(client_p
) ? L_NETWIDE
: L_ALL
,
2134 "Lost connection to %s: %s",
2135 client_p
->name
, strerror(current_error
));
2136 ilog(L_SERVER
, "Lost connection to %s: %s",
2137 log_client_name(client_p
, SHOW_IP
), strerror(current_error
));
2142 strlcpy(errmsg
, "Remote host closed the connection", sizeof(errmsg
));
2144 ircsnprintf(errmsg
, sizeof(errmsg
), "Read error: %s", strerror(current_error
));
2146 exit_client(client_p
, client_p
, &me
, errmsg
);