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 $
40 #include "s_newconf.h"
53 #include "blacklist.h"
56 #include "irc_dictionary.h"
59 #define DEBUG_EXITED_CLIENTS
61 static void check_pings_list(rb_dlink_list
* list
);
62 static void check_unknowns_list(rb_dlink_list
* list
);
63 static void free_exited_clients(void *unused
);
64 static void exit_aborted_clients(void *unused
);
66 static int exit_remote_client(struct Client
*, struct Client
*, struct Client
*,const char *);
67 static int exit_remote_server(struct Client
*, struct Client
*, struct Client
*,const char *);
68 static int exit_local_client(struct Client
*, struct Client
*, struct Client
*,const char *);
69 static int exit_unknown_client(struct Client
*, struct Client
*, struct Client
*,const char *);
70 static int exit_local_server(struct Client
*, struct Client
*, struct Client
*,const char *);
71 static int qs_server(struct Client
*, struct Client
*, struct Client
*, const char *comment
);
73 static EVH check_pings
;
75 static rb_bh
*client_heap
= NULL
;
76 static rb_bh
*lclient_heap
= NULL
;
77 static rb_bh
*pclient_heap
= NULL
;
78 static rb_bh
*user_heap
= NULL
;
79 static rb_bh
*away_heap
= NULL
;
80 static char current_uid
[IDLEN
];
82 struct Dictionary
*nd_dict
= NULL
;
90 rb_dlink_list dead_list
;
91 #ifdef DEBUG_EXITED_CLIENTS
92 static rb_dlink_list dead_remote_list
;
98 struct Client
*client
;
99 char notice
[REASONLEN
];
102 static rb_dlink_list abort_list
;
110 * side effects - initialize client free memory
116 * start off the check ping event .. -- adrian
117 * Every 30 seconds is plenty -- db
119 client_heap
= rb_bh_create(sizeof(struct Client
), CLIENT_HEAP_SIZE
, "client_heap");
120 lclient_heap
= rb_bh_create(sizeof(struct LocalUser
), LCLIENT_HEAP_SIZE
, "lclient_heap");
121 pclient_heap
= rb_bh_create(sizeof(struct PreClient
), PCLIENT_HEAP_SIZE
, "pclient_heap");
122 user_heap
= rb_bh_create(sizeof(struct User
), USER_HEAP_SIZE
, "user_heap");
123 away_heap
= rb_bh_create(AWAYLEN
, AWAY_HEAP_SIZE
, "away_heap");
125 rb_event_addish("check_pings", check_pings
, NULL
, 30);
126 rb_event_addish("free_exited_clients", &free_exited_clients
, NULL
, 4);
127 rb_event_addish("exit_aborted_clients", exit_aborted_clients
, NULL
, 1);
128 rb_event_add("flood_recalc", flood_recalc
, 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
= 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
;
164 client_p
->preClient
= rb_bh_alloc(pclient_heap
);;
166 /* as good a place as any... */
167 rb_dlinkAdd(client_p
, &client_p
->localClient
->tnode
, &unknown_list
);
170 { /* from is not NULL */
171 client_p
->localClient
= NULL
;
172 client_p
->preClient
= NULL
;
173 client_p
->from
= from
; /* 'from' of local client is self! */
176 SetUnknown(client_p
);
177 strcpy(client_p
->username
, "unknown");
183 free_pre_client(struct Client
*client_p
)
185 struct Blacklist
*blptr
;
187 s_assert(NULL
!= client_p
);
189 if(client_p
->preClient
== NULL
)
192 blptr
= client_p
->preClient
->dnsbl_listed
;
194 unref_blacklist(blptr
);
195 abort_blacklist_queries(client_p
);
196 rb_bh_free(pclient_heap
, client_p
->preClient
);
197 client_p
->preClient
= NULL
;
201 free_local_client(struct Client
*client_p
)
203 s_assert(NULL
!= client_p
);
204 s_assert(&me
!= client_p
);
206 if(client_p
->localClient
== NULL
)
210 * clean up extra sockets from P-lines which have been discarded.
212 if(client_p
->localClient
->listener
)
214 s_assert(0 < client_p
->localClient
->listener
->ref_count
);
215 if(0 == --client_p
->localClient
->listener
->ref_count
216 && !client_p
->localClient
->listener
->active
)
217 free_listener(client_p
->localClient
->listener
);
218 client_p
->localClient
->listener
= 0;
221 if(client_p
->localClient
->F
!= NULL
)
223 del_from_cli_fd_hash(client_p
);
224 rb_close(client_p
->localClient
->F
);
227 if(client_p
->localClient
->passwd
)
229 memset(client_p
->localClient
->passwd
, 0,
230 strlen(client_p
->localClient
->passwd
));
231 rb_free(client_p
->localClient
->passwd
);
234 rb_free(client_p
->localClient
->challenge
);
235 rb_free(client_p
->localClient
->fullcaps
);
236 rb_free(client_p
->localClient
->opername
);
237 rb_free(client_p
->localClient
->mangledhost
);
238 if (client_p
->localClient
->privset
)
239 privilegeset_unref(client_p
->localClient
->privset
);
242 ssld_decrement_clicount(client_p
->localClient
->ssl_ctl
);
244 if(IsCapable(client_p
, CAP_ZIP
))
245 ssld_decrement_clicount(client_p
->localClient
->z_ctl
);
247 rb_bh_free(lclient_heap
, client_p
->localClient
);
248 client_p
->localClient
= NULL
;
252 free_client(struct Client
*client_p
)
254 s_assert(NULL
!= client_p
);
255 s_assert(&me
!= client_p
);
256 free_local_client(client_p
);
257 free_pre_client(client_p
);
258 rb_bh_free(client_heap
, client_p
);
262 * check_pings - go through the local client list and check activity
263 * kill off stuff that should die
265 * inputs - NOT USED (from event)
266 * output - next time_t when check_pings() should be called again
270 * A PING can be sent to clients as necessary.
272 * Client/Server ping outs are handled.
276 * Addon from adrian. We used to call this after nextping seconds,
277 * however I've changed it to run once a second. This is only for
278 * PING timeouts, not K/etc-line checks (thanks dianora!). Having it
279 * run once a second makes life a lot easier - when a new client connects
280 * and they need a ping in 4 seconds, if nextping was set to 20 seconds
281 * we end up waiting 20 seconds. This is stupid. :-)
282 * I will optimise (hah!) check_pings() once I've finished working on
283 * tidying up other network IO evilnesses.
288 check_pings(void *notused
)
290 check_pings_list(&lclient_list
);
291 check_pings_list(&serv_list
);
292 check_unknowns_list(&unknown_list
);
298 * inputs - pointer to list to check
303 check_pings_list(rb_dlink_list
* list
)
305 char scratch
[32]; /* way too generous but... */
306 struct Client
*client_p
; /* current local client_p being examined */
307 int ping
= 0; /* ping time value from client */
308 rb_dlink_node
*ptr
, *next_ptr
;
310 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, list
->head
)
312 client_p
= ptr
->data
;
314 if(!MyConnect(client_p
) || IsDead(client_p
))
317 ping
= get_client_ping(client_p
);
319 if(ping
< (rb_current_time() - client_p
->localClient
->lasttime
))
322 * If the client/server hasnt talked to us in 2*ping seconds
323 * and it has a ping time, then close its connection.
325 if(((rb_current_time() - client_p
->localClient
->lasttime
) >= (2 * ping
)
326 && (client_p
->flags
& FLAGS_PINGSENT
)))
328 if(IsServer(client_p
))
330 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
331 "No response from %s, closing link",
334 "No response from %s, closing link",
335 log_client_name(client_p
, HIDE_IP
));
337 (void) rb_snprintf(scratch
, sizeof(scratch
),
338 "Ping timeout: %d seconds",
339 (int) (rb_current_time() - client_p
->localClient
->lasttime
));
341 exit_client(client_p
, client_p
, &me
, scratch
);
344 else if((client_p
->flags
& FLAGS_PINGSENT
) == 0)
347 * if we havent PINGed the connection and we havent
348 * heard from it in a while, PING it to make sure
351 client_p
->flags
|= FLAGS_PINGSENT
;
352 /* not nice but does the job */
353 client_p
->localClient
->lasttime
= rb_current_time() - ping
;
354 sendto_one(client_p
, "PING :%s", me
.name
);
363 * check_unknowns_list
365 * inputs - pointer to list of unknown clients
367 * side effects - unknown clients get marked for termination after n seconds
370 check_unknowns_list(rb_dlink_list
* list
)
372 rb_dlink_node
*ptr
, *next_ptr
;
373 struct Client
*client_p
;
376 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, list
->head
)
378 client_p
= ptr
->data
;
380 if(IsDead(client_p
) || IsClosing(client_p
))
383 /* still has DNSbls to validate against */
384 if(client_p
->preClient
!= NULL
&&
385 rb_dlink_list_length(&client_p
->preClient
->dnsbl_queries
) > 0)
389 * Check UNKNOWN connections - if they have been in this state
390 * for > 30s, close them.
393 timeout
= IsAnyServer(client_p
) ? ConfigFileEntry
.connect_timeout
: 30;
394 if((rb_current_time() - client_p
->localClient
->firsttime
) > timeout
)
396 if(IsAnyServer(client_p
))
398 sendto_realops_snomask(SNO_GENERAL
, is_remote_connect(client_p
) ? L_NETWIDE
: L_ALL
,
399 "No response from %s, closing link",
402 "No response from %s, closing link",
403 log_client_name(client_p
, HIDE_IP
));
405 exit_client(client_p
, client_p
, &me
, "Connection timed out");
411 notify_banned_client(struct Client
*client_p
, struct ConfItem
*aconf
, int ban
)
413 static const char conn_closed
[] = "Connection closed";
414 static const char d_lined
[] = "D-lined";
415 static const char k_lined
[] = "K-lined";
416 const char *reason
= NULL
;
417 const char *exit_reason
= conn_closed
;
419 if(ConfigFileEntry
.kline_with_reason
&& !EmptyString(aconf
->passwd
))
421 reason
= aconf
->passwd
;
422 exit_reason
= aconf
->passwd
;
426 reason
= aconf
->status
== D_LINED
? d_lined
: k_lined
;
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/dline 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 rb_dlink_node
*ptr
, *next_ptr
;
454 RB_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
)) && !(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_xline(client_p
->info
, 1)) != NULL
)
494 if(IsExemptKline(client_p
))
496 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
497 "XLINE over-ruled for %s, client is kline_exempt [%s]",
498 get_client_name(client_p
, HIDE_IP
),
503 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "XLINE active for %s",
504 get_client_name(client_p
, HIDE_IP
));
506 (void) exit_client(client_p
, client_p
, &me
, "Bad user info");
511 /* also check the unknowns list for new dlines */
512 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, unknown_list
.head
)
514 client_p
= ptr
->data
;
516 if((aconf
= find_dline((struct sockaddr
*)&client_p
->localClient
->ip
,client_p
->localClient
->ip
.ss_family
)))
518 if(aconf
->status
& CONF_EXEMPTDLINE
)
521 notify_banned_client(client_p
, aconf
, D_LINED
);
527 /* check_klines_event()
531 * side effects - check_klines() is called, kline_queued unset
534 check_klines_event(void *unused
)
544 * side effects - all clients will be checked for klines
549 struct Client
*client_p
;
550 struct ConfItem
*aconf
;
552 rb_dlink_node
*next_ptr
;
554 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
556 client_p
= ptr
->data
;
558 if(IsMe(client_p
) || !IsPerson(client_p
))
561 if((aconf
= find_kline(client_p
)) != NULL
)
563 if(IsExemptKline(client_p
))
565 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
566 "KLINE over-ruled for %s, client is kline_exempt [%s@%s]",
567 get_client_name(client_p
, HIDE_IP
),
568 aconf
->user
, aconf
->host
);
572 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
573 "KLINE active for %s",
574 get_client_name(client_p
, HIDE_IP
));
576 notify_banned_client(client_p
, aconf
, K_LINED
);
586 * side effects - all clients will be checked for dlines
591 struct Client
*client_p
;
592 struct ConfItem
*aconf
;
594 rb_dlink_node
*next_ptr
;
596 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
598 client_p
= ptr
->data
;
603 if((aconf
= find_dline((struct sockaddr
*)&client_p
->localClient
->ip
,client_p
->localClient
->ip
.ss_family
)) != NULL
)
605 if(aconf
->status
& CONF_EXEMPTDLINE
)
608 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
609 "DLINE active for %s",
610 get_client_name(client_p
, HIDE_IP
));
612 notify_banned_client(client_p
, aconf
, D_LINED
);
617 /* dlines need to be checked against unknowns too */
618 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, unknown_list
.head
)
620 client_p
= ptr
->data
;
622 if((aconf
= find_dline((struct sockaddr
*)&client_p
->localClient
->ip
,client_p
->localClient
->ip
.ss_family
)) != NULL
)
624 if(aconf
->status
& CONF_EXEMPTDLINE
)
627 notify_banned_client(client_p
, aconf
, D_LINED
);
636 * side effects - all clients will be checked for xlines
641 struct Client
*client_p
;
642 struct ConfItem
*aconf
;
644 rb_dlink_node
*next_ptr
;
646 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
648 client_p
= ptr
->data
;
650 if(IsMe(client_p
) || !IsPerson(client_p
))
653 if((aconf
= find_xline(client_p
->info
, 1)) != NULL
)
655 if(IsExemptKline(client_p
))
657 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
658 "XLINE over-ruled for %s, client is kline_exempt [%s]",
659 get_client_name(client_p
, HIDE_IP
),
664 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "XLINE active for %s",
665 get_client_name(client_p
, HIDE_IP
));
667 (void) exit_client(client_p
, client_p
, &me
, "Bad user info");
674 * update_client_exit_stats
676 * input - pointer to client
681 update_client_exit_stats(struct Client
*client_p
)
683 if(IsServer(client_p
))
685 sendto_realops_snomask(SNO_EXTERNAL
, L_ALL
,
686 "Server %s split from %s",
687 client_p
->name
, client_p
->servptr
->name
);
688 if(HasSentEob(client_p
))
691 else if(IsClient(client_p
))
696 if(IsInvisible(client_p
))
700 if(splitchecking
&& !splitmode
)
701 check_splitmode(NULL
);
705 * release_client_state
707 * input - pointer to client to release
712 release_client_state(struct Client
*client_p
)
714 if(client_p
->user
!= NULL
)
716 free_user(client_p
->user
, client_p
); /* try this here */
720 if(client_p
->serv
->user
!= NULL
)
721 free_user(client_p
->serv
->user
, client_p
);
722 if(client_p
->serv
->fullcaps
)
723 rb_free(client_p
->serv
->fullcaps
);
724 rb_free(client_p
->serv
);
729 * remove_client_from_list
730 * inputs - point to client to remove
732 * side effects - taken the code from ExitOneClient() for this
733 * and placed it here. - avalon
736 remove_client_from_list(struct Client
*client_p
)
738 s_assert(NULL
!= client_p
);
743 /* A client made with make_client()
744 * is on the unknown_list until removed.
745 * If it =does= happen to exit before its removed from that list
746 * and its =not= on the global_client_list, it will core here.
747 * short circuit that case now -db
749 if(client_p
->node
.prev
== NULL
&& client_p
->node
.next
== NULL
)
752 rb_dlinkDelete(&client_p
->node
, &global_client_list
);
754 update_client_exit_stats(client_p
);
759 * find_person - find person by (nick)name.
760 * inputs - pointer to name
761 * output - return client pointer
765 find_person(const char *name
)
767 struct Client
*c2ptr
;
769 c2ptr
= find_client(name
);
771 if(c2ptr
&& IsPerson(c2ptr
))
777 find_named_person(const char *name
)
779 struct Client
*c2ptr
;
781 c2ptr
= find_named_client(name
);
783 if(c2ptr
&& IsPerson(c2ptr
))
790 * find_chasing - find the client structure for a nick name (user)
791 * using history mechanism if necessary. If the client is not found,
792 * an error message (NO SUCH NICK) is generated. If the client was found
793 * through the history, chasing will be 1 and otherwise 0.
796 find_chasing(struct Client
*source_p
, const char *user
, int *chasing
)
800 if(MyClient(source_p
))
801 who
= find_named_person(user
);
803 who
= find_person(user
);
808 if(who
|| IsDigit(*user
))
811 if(!(who
= get_history(user
, (long) KILLCHASETIMELIMIT
)))
813 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
814 form_str(ERR_NOSUCHNICK
), user
);
823 * get_client_name - Return the name of the client
824 * for various tracking and
825 * admin purposes. The main purpose of this function is to
826 * return the "socket host" name of the client, if that
827 * differs from the advertised name (other than case).
828 * But, this can be used to any client structure.
831 * Watch out the allocation of "nbuf", if either source_p->name
832 * or source_p->sockhost gets changed into pointers instead of
833 * directly allocated within the structure...
836 * Function return either a pointer to the structure (source_p) or
837 * to internal buffer (nbuf). *NEVER* use the returned pointer
838 * to modify what it points!!!
842 get_client_name(struct Client
*client
, int showip
)
844 static char nbuf
[HOSTLEN
* 2 + USERLEN
+ 5];
846 s_assert(NULL
!= client
);
850 if(MyConnect(client
))
852 if(!irccmp(client
->name
, client
->host
))
855 if(ConfigFileEntry
.hide_spoof_ips
&&
856 showip
== SHOW_IP
&& IsIPSpoof(client
))
858 if(IsAnyServer(client
))
861 /* And finally, let's get the host information, ip or name */
865 rb_snprintf(nbuf
, sizeof(nbuf
), "%s[%s@%s]",
866 client
->name
, client
->username
,
870 rb_snprintf(nbuf
, sizeof(nbuf
), "%s[%s@255.255.255.255]",
871 client
->name
, client
->username
);
874 rb_snprintf(nbuf
, sizeof(nbuf
), "%s[%s@%s]",
875 client
->name
, client
->username
, client
->host
);
880 /* As pointed out by Adel Mezibra
881 * Neph|l|m@EFnet. Was missing a return here.
888 * This version is the same as get_client_name, but doesnt contain the
889 * code that will hide IPs always. This should be used for logfiles.
892 log_client_name(struct Client
*target_p
, int showip
)
894 static char nbuf
[HOSTLEN
* 2 + USERLEN
+ 5];
899 if(MyConnect(target_p
))
901 if(irccmp(target_p
->name
, target_p
->host
) == 0)
902 return target_p
->name
;
907 rb_snprintf(nbuf
, sizeof(nbuf
), "%s[%s@%s]", target_p
->name
,
908 target_p
->username
, target_p
->sockhost
);
912 rb_snprintf(nbuf
, sizeof(nbuf
), "%s[%s@255.255.255.255]",
913 target_p
->name
, target_p
->username
);
916 rb_snprintf(nbuf
, sizeof(nbuf
), "%s[%s@%s]", target_p
->name
,
917 target_p
->username
, target_p
->host
);
923 return target_p
->name
;
926 /* is_remote_connect - Returns whether a server was /connect'ed by a remote
927 * oper (send notices netwide) */
929 is_remote_connect(struct Client
*client_p
)
933 if (client_p
->serv
== NULL
)
935 oper
= find_named_person(client_p
->serv
->by
);
936 return oper
!= NULL
&& IsOper(oper
) && !MyConnect(oper
);
940 free_exited_clients(void *unused
)
942 rb_dlink_node
*ptr
, *next
;
943 struct Client
*target_p
;
945 RB_DLINK_FOREACH_SAFE(ptr
, next
, dead_list
.head
)
947 target_p
= ptr
->data
;
949 #ifdef DEBUG_EXITED_CLIENTS
951 struct abort_client
*abt
;
955 RB_DLINK_FOREACH(aptr
, abort_list
.head
)
958 if(abt
->client
== target_p
)
961 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
962 "On abort_list: %s stat: %u flags: %u/%u handler: %c",
963 target_p
->name
, (unsigned int) target_p
->status
,
964 target_p
->flags
, target_p
->flags2
, target_p
->handler
);
965 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
966 "Please report this to the charybdis developers!");
973 rb_dlinkDestroy(ptr
, &dead_list
);
979 if(ptr
->data
== NULL
)
981 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
982 "Warning: null client on dead_list!");
983 rb_dlinkDestroy(ptr
, &dead_list
);
986 release_client_state(target_p
);
987 free_client(target_p
);
988 rb_dlinkDestroy(ptr
, &dead_list
);
991 #ifdef DEBUG_EXITED_CLIENTS
992 RB_DLINK_FOREACH_SAFE(ptr
, next
, dead_remote_list
.head
)
994 target_p
= ptr
->data
;
996 if(ptr
->data
== NULL
)
998 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
999 "Warning: null client on dead_list!");
1000 rb_dlinkDestroy(ptr
, &dead_list
);
1003 release_client_state(target_p
);
1004 free_client(target_p
);
1005 rb_dlinkDestroy(ptr
, &dead_remote_list
);
1012 ** Recursively send QUITs and SQUITs for source_p and all its dependent clients
1013 ** and servers to those servers that need them. A server needs the client
1014 ** QUITs if it can't figure them out from the SQUIT (ie pre-TS4) or if it
1015 ** isn't getting the SQUIT because of @#(*&@)# hostmasking. With TS4, once
1016 ** a link gets a SQUIT, it doesn't need any QUIT/SQUITs for clients depending
1017 ** on that one -orabidoo
1020 recurse_send_quits(struct Client
*client_p
, struct Client
*source_p
,
1021 struct Client
*to
, const char *comment1
,
1022 const char *comment
)
1024 struct Client
*target_p
;
1025 rb_dlink_node
*ptr
, *ptr_next
;
1026 /* If this server can handle quit storm (QS) removal
1027 * of dependents, just send the SQUIT
1030 if(IsCapable(to
, CAP_QS
))
1032 sendto_one(to
, "SQUIT %s :%s",
1033 get_id(source_p
, to
), comment
);
1037 RB_DLINK_FOREACH_SAFE(ptr
, ptr_next
, source_p
->serv
->users
.head
)
1039 target_p
= ptr
->data
;
1040 sendto_one(to
, ":%s QUIT :%s", target_p
->name
, comment1
);
1042 RB_DLINK_FOREACH_SAFE(ptr
, ptr_next
, source_p
->serv
->servers
.head
)
1044 target_p
= ptr
->data
;
1045 recurse_send_quits(client_p
, target_p
, to
, comment1
, comment
);
1047 sendto_one(to
, "SQUIT %s :%s", source_p
->name
, comment
);
1052 ** Remove all clients that depend on source_p; assumes all (S)QUITs have
1053 ** already been sent. we make sure to exit a server's dependent clients
1054 ** and servers before the server itself; exit_one_client takes care of
1055 ** actually removing things off llists. tweaked from +CSr31 -orabidoo
1058 * added sanity test code.... source_p->serv might be NULL...
1061 recurse_remove_clients(struct Client
*source_p
, const char *comment
)
1063 struct Client
*target_p
;
1064 rb_dlink_node
*ptr
, *ptr_next
;
1069 if(source_p
->serv
== NULL
) /* oooops. uh this is actually a major bug */
1072 /* this is very ugly, but it saves cpu :P */
1073 if(ConfigFileEntry
.nick_delay
> 0)
1075 RB_DLINK_FOREACH_SAFE(ptr
, ptr_next
, source_p
->serv
->users
.head
)
1077 target_p
= ptr
->data
;
1078 target_p
->flags
|= FLAGS_KILLED
;
1079 add_nd_entry(target_p
->name
);
1081 if(!IsDead(target_p
) && !IsClosing(target_p
))
1082 exit_remote_client(NULL
, target_p
, &me
, comment
);
1087 RB_DLINK_FOREACH_SAFE(ptr
, ptr_next
, source_p
->serv
->users
.head
)
1089 target_p
= ptr
->data
;
1090 target_p
->flags
|= FLAGS_KILLED
;
1092 if(!IsDead(target_p
) && !IsClosing(target_p
))
1093 exit_remote_client(NULL
, target_p
, &me
, comment
);
1097 RB_DLINK_FOREACH_SAFE(ptr
, ptr_next
, source_p
->serv
->servers
.head
)
1099 target_p
= ptr
->data
;
1100 recurse_remove_clients(target_p
, comment
);
1101 qs_server(NULL
, target_p
, &me
, comment
);
1106 ** Remove *everything* that depends on source_p, from all lists, and sending
1107 ** all necessary QUITs and SQUITs. source_p itself is still on the lists,
1108 ** and its SQUITs have been sent except for the upstream one -orabidoo
1111 remove_dependents(struct Client
*client_p
,
1112 struct Client
*source_p
,
1113 struct Client
*from
, const char *comment
, const char *comment1
)
1116 rb_dlink_node
*ptr
, *next
;
1118 RB_DLINK_FOREACH_SAFE(ptr
, next
, serv_list
.head
)
1122 if(IsMe(to
) || to
== source_p
->from
||
1123 (to
== client_p
&& IsCapable(to
, CAP_QS
)))
1126 recurse_send_quits(client_p
, source_p
, to
, comment1
, comment
);
1129 recurse_remove_clients(source_p
, comment1
);
1133 exit_aborted_clients(void *unused
)
1135 struct abort_client
*abt
;
1136 rb_dlink_node
*ptr
, *next
;
1137 RB_DLINK_FOREACH_SAFE(ptr
, next
, abort_list
.head
)
1141 #ifdef DEBUG_EXITED_CLIENTS
1143 if(rb_dlinkFind(abt
->client
, &dead_list
))
1146 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1147 "On dead_list: %s stat: %u flags: %u/%u handler: %c",
1148 abt
->client
->name
, (unsigned int) abt
->client
->status
,
1149 abt
->client
->flags
, abt
->client
->flags2
, abt
->client
->handler
);
1150 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1151 "Please report this to the charybdis developers!");
1157 s_assert(*((unsigned long*)abt
->client
) != 0xdeadbeef); /* This is lame but its a debug thing */
1158 rb_dlinkDelete(ptr
, &abort_list
);
1160 if(IsAnyServer(abt
->client
))
1161 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1162 "Closing link to %s: %s",
1163 abt
->client
->name
, abt
->notice
);
1165 /* its no longer on abort list - we *must* remove
1166 * FLAGS_CLOSING otherwise exit_client() will not run --fl
1168 abt
->client
->flags
&= ~FLAGS_CLOSING
;
1169 exit_client(abt
->client
, abt
->client
, &me
, abt
->notice
);
1176 * dead_link - Adds client to a list of clients that need an exit_client()
1180 dead_link(struct Client
*client_p
)
1182 struct abort_client
*abt
;
1184 s_assert(!IsMe(client_p
));
1185 if(IsDead(client_p
) || IsClosing(client_p
) || IsMe(client_p
))
1188 abt
= (struct abort_client
*) rb_malloc(sizeof(struct abort_client
));
1190 if(client_p
->flags
& FLAGS_SENDQEX
)
1191 rb_strlcpy(abt
->notice
, "Max SendQ exceeded", sizeof(abt
->notice
));
1193 rb_snprintf(abt
->notice
, sizeof(abt
->notice
), "Write error: %s", strerror(errno
));
1195 abt
->client
= client_p
;
1196 SetIOError(client_p
);
1198 SetClosing(client_p
);
1199 rb_dlinkAdd(abt
, &abt
->node
, &abort_list
);
1203 /* This does the remove of the user from channels..local or remote */
1205 exit_generic_client(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1206 const char *comment
)
1208 rb_dlink_node
*ptr
, *next_ptr
;
1210 if(IsOper(source_p
))
1211 rb_dlinkFindDestroy(source_p
, &oper_list
);
1213 sendto_common_channels_local(source_p
, ":%s!%s@%s QUIT :%s",
1215 source_p
->username
, source_p
->host
, comment
);
1217 remove_user_from_channels(source_p
);
1219 /* Should not be in any channels now */
1220 s_assert(source_p
->user
->channel
.head
== NULL
);
1222 /* Clean up invitefield */
1223 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, source_p
->user
->invited
.head
)
1225 del_invite(ptr
->data
, source_p
);
1228 /* Clean up allow lists */
1229 del_all_accepts(source_p
);
1231 add_history(source_p
, 0);
1232 off_history(source_p
);
1234 monitor_signoff(source_p
);
1236 if(has_id(source_p
))
1237 del_from_id_hash(source_p
->id
, source_p
);
1239 del_from_hostname_hash(source_p
->orighost
, source_p
);
1240 del_from_client_hash(source_p
->name
, source_p
);
1241 remove_client_from_list(source_p
);
1245 * Assumes IsPerson(source_p) && !MyConnect(source_p)
1249 exit_remote_client(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1250 const char *comment
)
1252 exit_generic_client(client_p
, source_p
, from
, comment
);
1254 if(source_p
->servptr
&& source_p
->servptr
->serv
)
1256 rb_dlinkDelete(&source_p
->lnode
, &source_p
->servptr
->serv
->users
);
1259 if((source_p
->flags
& FLAGS_KILLED
) == 0)
1261 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
,
1262 ":%s QUIT :%s", use_id(source_p
), comment
);
1266 #ifdef DEBUG_EXITED_CLIENTS
1267 rb_dlinkAddAlloc(source_p
, &dead_remote_list
);
1269 rb_dlinkAddAlloc(source_p
, &dead_list
);
1271 return(CLIENT_EXITED
);
1275 * This assumes IsUnknown(source_p) == TRUE and MyConnect(source_p) == TRUE
1279 exit_unknown_client(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1280 const char *comment
)
1282 delete_auth_queries(source_p
);
1283 if (source_p
->localClient
->dnsquery
)
1285 delete_resolver_queries(source_p
->localClient
->dnsquery
);
1286 rb_free(source_p
->localClient
->dnsquery
);
1288 rb_dlinkDelete(&source_p
->localClient
->tnode
, &unknown_list
);
1290 if(!IsIOError(source_p
))
1291 sendto_one(source_p
, "ERROR :Closing Link: %s (%s)",
1292 source_p
->user
!= NULL
? source_p
->host
: "127.0.0.1",
1295 close_connection(source_p
);
1297 if(has_id(source_p
))
1298 del_from_id_hash(source_p
->id
, source_p
);
1300 del_from_hostname_hash(source_p
->host
, source_p
);
1301 del_from_client_hash(source_p
->name
, source_p
);
1302 remove_client_from_list(source_p
);
1304 rb_dlinkAddAlloc(source_p
, &dead_list
);
1306 /* Note that we don't need to add unknowns to the dead_list */
1307 return(CLIENT_EXITED
);
1311 exit_remote_server(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1312 const char *comment
)
1314 static char comment1
[(HOSTLEN
*2)+2];
1315 static char newcomment
[BUFSIZE
];
1316 struct Client
*target_p
;
1318 if(ConfigServerHide
.flatten_links
)
1319 strcpy(comment1
, "*.net *.split");
1322 strcpy(comment1
, source_p
->servptr
->name
);
1323 strcat(comment1
, " ");
1324 strcat(comment1
, source_p
->name
);
1327 rb_snprintf(newcomment
, sizeof(newcomment
), "by %s: %s",
1328 from
->name
, comment
);
1330 if(source_p
->serv
!= NULL
)
1331 remove_dependents(client_p
, source_p
, from
, IsPerson(from
) ? newcomment
: comment
, comment1
);
1333 if(source_p
->servptr
&& source_p
->servptr
->serv
)
1334 rb_dlinkDelete(&source_p
->lnode
, &source_p
->servptr
->serv
->servers
);
1338 rb_dlinkFindDestroy(source_p
, &global_serv_list
);
1339 target_p
= source_p
->from
;
1341 if(target_p
!= NULL
&& IsServer(target_p
) && target_p
!= client_p
&&
1342 !IsMe(target_p
) && (source_p
->flags
& FLAGS_KILLED
) == 0)
1344 sendto_one(target_p
, ":%s SQUIT %s :%s",
1345 get_id(from
, target_p
), get_id(source_p
, target_p
),
1349 if(has_id(source_p
))
1350 del_from_id_hash(source_p
->id
, source_p
);
1352 del_from_client_hash(source_p
->name
, source_p
);
1353 remove_client_from_list(source_p
);
1354 scache_split(source_p
->serv
->nameinfo
);
1357 #ifdef DEBUG_EXITED_CLIENTS
1358 rb_dlinkAddAlloc(source_p
, &dead_remote_list
);
1360 rb_dlinkAddAlloc(source_p
, &dead_list
);
1366 qs_server(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1367 const char *comment
)
1369 if(source_p
->servptr
&& source_p
->servptr
->serv
)
1370 rb_dlinkDelete(&source_p
->lnode
, &source_p
->servptr
->serv
->servers
);
1374 rb_dlinkFindDestroy(source_p
, &global_serv_list
);
1376 if(has_id(source_p
))
1377 del_from_id_hash(source_p
->id
, source_p
);
1379 del_from_client_hash(source_p
->name
, source_p
);
1380 remove_client_from_list(source_p
);
1381 scache_split(source_p
->serv
->nameinfo
);
1384 rb_dlinkAddAlloc(source_p
, &dead_list
);
1389 exit_local_server(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1390 const char *comment
)
1392 static char comment1
[(HOSTLEN
*2)+2];
1393 static char newcomment
[BUFSIZE
];
1394 unsigned int sendk
, recvk
;
1396 rb_dlinkDelete(&source_p
->localClient
->tnode
, &serv_list
);
1397 rb_dlinkFindDestroy(source_p
, &global_serv_list
);
1399 unset_chcap_usage_counts(source_p
);
1400 sendk
= source_p
->localClient
->sendK
;
1401 recvk
= source_p
->localClient
->receiveK
;
1403 /* Always show source here, so the server notices show
1404 * which side initiated the split -- jilles
1406 rb_snprintf(newcomment
, sizeof(newcomment
), "by %s: %s",
1407 from
== source_p
? me
.name
: from
->name
, comment
);
1408 if (!IsIOError(source_p
))
1409 sendto_one(source_p
, "SQUIT %s :%s", use_id(source_p
),
1411 if(client_p
!= NULL
&& source_p
!= client_p
&& !IsIOError(source_p
))
1413 sendto_one(source_p
, "ERROR :Closing Link: 127.0.0.1 %s (%s)",
1414 source_p
->name
, comment
);
1417 if(source_p
->servptr
&& source_p
->servptr
->serv
)
1418 rb_dlinkDelete(&source_p
->lnode
, &source_p
->servptr
->serv
->servers
);
1423 close_connection(source_p
);
1425 if(ConfigServerHide
.flatten_links
)
1426 strcpy(comment1
, "*.net *.split");
1429 strcpy(comment1
, source_p
->servptr
->name
);
1430 strcat(comment1
, " ");
1431 strcat(comment1
, source_p
->name
);
1434 if(source_p
->serv
!= NULL
)
1435 remove_dependents(client_p
, source_p
, from
, IsPerson(from
) ? newcomment
: comment
, comment1
);
1437 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s was connected"
1438 " for %ld seconds. %d/%d sendK/recvK.",
1439 source_p
->name
, (long) rb_current_time() - source_p
->localClient
->firsttime
, sendk
, recvk
);
1441 ilog(L_SERVER
, "%s was connected for %ld seconds. %d/%d sendK/recvK.",
1442 source_p
->name
, (long) rb_current_time() - source_p
->localClient
->firsttime
, sendk
, recvk
);
1444 if(has_id(source_p
))
1445 del_from_id_hash(source_p
->id
, source_p
);
1447 del_from_client_hash(source_p
->name
, source_p
);
1448 remove_client_from_list(source_p
);
1449 scache_split(source_p
->serv
->nameinfo
);
1452 rb_dlinkAddAlloc(source_p
, &dead_list
);
1458 * This assumes IsPerson(source_p) == TRUE && MyConnect(source_p) == TRUE
1462 exit_local_client(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1463 const char *comment
)
1465 unsigned long on_for
;
1468 exit_generic_client(client_p
, source_p
, from
, comment
);
1469 clear_monitor(source_p
);
1471 s_assert(IsPerson(source_p
));
1472 rb_dlinkDelete(&source_p
->localClient
->tnode
, &lclient_list
);
1473 rb_dlinkDelete(&source_p
->lnode
, &me
.serv
->users
);
1475 if(IsOper(source_p
))
1476 rb_dlinkFindDestroy(source_p
, &local_oper_list
);
1478 sendto_realops_snomask(SNO_CCONN
, L_ALL
,
1479 "Client exiting: %s (%s@%s) [%s] [%s]",
1481 source_p
->username
, source_p
->host
, comment
,
1482 show_ip(NULL
, source_p
) ? source_p
->sockhost
: "255.255.255.255");
1484 sendto_realops_snomask(SNO_CCONNEXT
, L_ALL
,
1485 "CLIEXIT %s %s %s %s 0 %s",
1486 source_p
->name
, source_p
->username
, source_p
->host
,
1487 show_ip(NULL
, source_p
) ? source_p
->sockhost
: "255.255.255.255",
1490 on_for
= rb_current_time() - source_p
->localClient
->firsttime
;
1492 ilog(L_USER
, "%s (%3lu:%02lu:%02lu): %s!%s@%s %s %d/%d",
1493 rb_ctime(rb_current_time(), tbuf
, sizeof(tbuf
)), on_for
/ 3600,
1494 (on_for
% 3600) / 60, on_for
% 60,
1495 source_p
->name
, source_p
->username
, source_p
->host
,
1497 source_p
->localClient
->sendK
, source_p
->localClient
->receiveK
);
1499 sendto_one(source_p
, "ERROR :Closing Link: %s (%s)", source_p
->host
, comment
);
1500 close_connection(source_p
);
1502 if((source_p
->flags
& FLAGS_KILLED
) == 0)
1504 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
,
1505 ":%s QUIT :%s", use_id(source_p
), comment
);
1509 rb_dlinkAddAlloc(source_p
, &dead_list
);
1510 return(CLIENT_EXITED
);
1515 ** exit_client - This is old "m_bye". Name changed, because this is not a
1516 ** protocol function, but a general server utility function.
1518 ** This function exits a client of *any* type (user, server, etc)
1519 ** from this server. Also, this generates all necessary prototol
1520 ** messages that this exit may cause.
1522 ** 1) If the client is a local client, then this implicitly
1523 ** exits all other clients depending on this connection (e.g.
1524 ** remote clients having 'from'-field that points to this.
1526 ** 2) If the client is a remote client, then only this is exited.
1528 ** For convenience, this function returns a suitable value for
1529 ** m_function return value:
1531 ** CLIENT_EXITED if (client_p == source_p)
1532 ** 0 if (client_p != source_p)
1535 exit_client(struct Client
*client_p
, /* The local client originating the
1536 * exit or NULL, if this exit is
1537 * generated by this server for
1539 * This will not get any of the
1540 * generated messages. */
1541 struct Client
*source_p
, /* Client exiting */
1542 struct Client
*from
, /* Client firing off this Exit,
1544 const char *comment
/* Reason for the exit */
1547 hook_data_client_exit hdata
;
1548 if(IsClosing(source_p
))
1551 /* note, this HAS to be here, when we exit a client we attempt to
1552 * send them data, if this generates a write error we must *not* add
1553 * them to the abort list --fl
1555 SetClosing(source_p
);
1557 hdata
.local_link
= client_p
;
1558 hdata
.target
= source_p
;
1560 hdata
.comment
= comment
;
1561 call_hook(h_client_exit
, &hdata
);
1563 if(MyConnect(source_p
))
1565 /* Local clients of various types */
1566 if(IsPerson(source_p
))
1567 return exit_local_client(client_p
, source_p
, from
, comment
);
1568 else if(IsServer(source_p
))
1569 return exit_local_server(client_p
, source_p
, from
, comment
);
1570 /* IsUnknown || IsConnecting || IsHandShake */
1571 else if(!IsReject(source_p
))
1572 return exit_unknown_client(client_p
, source_p
, from
, comment
);
1577 if(IsPerson(source_p
))
1578 return exit_remote_client(client_p
, source_p
, from
, comment
);
1579 else if(IsServer(source_p
))
1580 return exit_remote_server(client_p
, source_p
, from
, comment
);
1587 * Count up local client memory
1590 /* XXX one common Client list now */
1592 count_local_client_memory(size_t * count
, size_t * local_client_memory_used
)
1595 rb_bh_usage(lclient_heap
, count
, NULL
, &lusage
, NULL
);
1596 *local_client_memory_used
= lusage
+ (*count
* (sizeof(void *) + sizeof(struct Client
)));
1600 * Count up remote client memory
1603 count_remote_client_memory(size_t * count
, size_t * remote_client_memory_used
)
1605 size_t lcount
, rcount
;
1606 rb_bh_usage(lclient_heap
, &lcount
, NULL
, NULL
, NULL
);
1607 rb_bh_usage(client_heap
, &rcount
, NULL
, NULL
, NULL
);
1608 *count
= rcount
- lcount
;
1609 *remote_client_memory_used
= *count
* (sizeof(void *) + sizeof(struct Client
));
1614 * accept processing, this adds a form of "caller ID" to ircd
1616 * If a client puts themselves into "caller ID only" mode,
1617 * only clients that match a client pointer they have put on
1618 * the accept list will be allowed to message them.
1620 * [ source.on_allow_list ] -> [ target1 ] -> [ target2 ]
1622 * [target.allow_list] -> [ source1 ] -> [source2 ]
1624 * i.e. a target will have a link list of source pointers it will allow
1625 * each source client then has a back pointer pointing back
1626 * to the client that has it on its accept list.
1627 * This allows for exit_one_client to remove these now bogus entries
1628 * from any client having an accept on them.
1633 * inputs - pointer to exiting client
1635 * side effects - Walk through given clients allow_list and on_allow_list
1636 * remove all references to this client
1639 del_all_accepts(struct Client
*client_p
)
1642 rb_dlink_node
*next_ptr
;
1643 struct Client
*target_p
;
1645 if(MyClient(client_p
) && client_p
->localClient
->allow_list
.head
)
1647 /* clear this clients accept list, and remove them from
1648 * everyones on_accept_list
1650 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, client_p
->localClient
->allow_list
.head
)
1652 target_p
= ptr
->data
;
1653 rb_dlinkFindDestroy(client_p
, &target_p
->on_allow_list
);
1654 rb_dlinkDestroy(ptr
, &client_p
->localClient
->allow_list
);
1658 /* remove this client from everyones accept list */
1659 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, client_p
->on_allow_list
.head
)
1661 target_p
= ptr
->data
;
1662 rb_dlinkFindDestroy(client_p
, &target_p
->localClient
->allow_list
);
1663 rb_dlinkDestroy(ptr
, &client_p
->on_allow_list
);
1668 * show_ip() - asks if the true IP shoudl be shown when source is
1669 * askin for info about target
1671 * Inputs - source_p who is asking
1672 * - target_p who do we want the info on
1673 * Output - returns 1 if clear IP can be showed, otherwise 0
1674 * Side Effects - none
1678 show_ip(struct Client
*source_p
, struct Client
*target_p
)
1680 if(IsAnyServer(target_p
))
1684 else if(IsIPSpoof(target_p
))
1686 /* source == NULL indicates message is being sent
1689 if(!ConfigFileEntry
.hide_spoof_ips
&&
1690 (source_p
== NULL
|| MyOper(source_p
)))
1694 else if(IsDynSpoof(target_p
) && (source_p
!= NULL
&& !IsOper(source_p
)))
1701 show_ip_conf(struct ConfItem
*aconf
, struct Client
*source_p
)
1703 if(IsConfDoSpoofIp(aconf
))
1705 if(!ConfigFileEntry
.hide_spoof_ips
&& MyOper(source_p
))
1717 * inputs - pointer to client struct
1718 * output - pointer to struct User
1719 * side effects - add's an User information block to a client
1720 * if it was not previously allocated.
1723 make_user(struct Client
*client_p
)
1727 user
= client_p
->user
;
1730 user
= (struct User
*) rb_bh_alloc(user_heap
);
1732 client_p
->user
= user
;
1740 * inputs - pointer to client struct
1741 * output - pointer to server_t
1742 * side effects - add's an Server information block to a client
1743 * if it was not previously allocated.
1746 make_server(struct Client
*client_p
)
1748 server_t
*serv
= client_p
->serv
;
1752 serv
= (server_t
*) rb_malloc(sizeof(server_t
));
1753 client_p
->serv
= serv
;
1755 return client_p
->serv
;
1761 * inputs - pointer to user struct
1762 * - pointer to client struct
1764 * side effects - Decrease user reference count by one and release block,
1765 * if count reaches 0
1768 free_user(struct User
*user
, struct Client
*client_p
)
1770 free_away(client_p
);
1772 if(--user
->refcnt
<= 0)
1775 rb_free((char *) user
->away
);
1779 if(user
->refcnt
< 0 || user
->invited
.head
|| user
->channel
.head
)
1781 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1782 "* %#lx user (%s!%s@%s) %#lx %#lx %#lx %lu %d *",
1783 (unsigned long) client_p
,
1784 client_p
? client_p
->
1788 (unsigned long) user
,
1789 (unsigned long) user
->invited
.head
,
1790 (unsigned long) user
->channel
.head
,
1791 rb_dlink_list_length(&user
->channel
),
1793 s_assert(!user
->refcnt
);
1794 s_assert(!user
->invited
.head
);
1795 s_assert(!user
->channel
.head
);
1798 rb_bh_free(user_heap
, user
);
1803 allocate_away(struct Client
*client_p
)
1805 if(client_p
->user
->away
== NULL
)
1806 client_p
->user
->away
= rb_bh_alloc(away_heap
);
1811 free_away(struct Client
*client_p
)
1813 if(client_p
->user
!= NULL
&& client_p
->user
->away
!= NULL
) {
1814 rb_bh_free(away_heap
, client_p
->user
->away
);
1815 client_p
->user
->away
= NULL
;
1824 for(i
= 0; i
< 3; i
++)
1825 current_uid
[i
] = me
.id
[i
];
1827 for(i
= 3; i
< 9; i
++)
1828 current_uid
[i
] = 'A';
1830 current_uid
[9] = '\0';
1839 for(i
= 8; i
> 3; i
--)
1841 if(current_uid
[i
] == 'Z')
1843 current_uid
[i
] = '0';
1846 else if(current_uid
[i
] != '9')
1852 current_uid
[i
] = 'A';
1855 /* if this next if() triggers, we're fucked. */
1856 if(current_uid
[3] == 'Z')
1858 current_uid
[i
] = 'A';
1869 * Close the physical connection. This function must make
1870 * MyConnect(client_p) == FALSE, and set client_p->from == NULL.
1873 close_connection(struct Client
*client_p
)
1875 s_assert(client_p
!= NULL
);
1876 if(client_p
== NULL
)
1879 s_assert(MyConnect(client_p
));
1880 if(!MyConnect(client_p
))
1883 if(IsServer(client_p
))
1885 struct server_conf
*server_p
;
1887 ServerStats
.is_sv
++;
1888 ServerStats
.is_sbs
+= client_p
->localClient
->sendB
;
1889 ServerStats
.is_sbr
+= client_p
->localClient
->receiveB
;
1890 ServerStats
.is_sti
+= (unsigned long long)(rb_current_time() - client_p
->localClient
->firsttime
);
1893 * If the connection has been up for a long amount of time, schedule
1894 * a 'quick' reconnect, else reset the next-connect cycle.
1896 if((server_p
= find_server_conf(client_p
->name
)) != NULL
)
1899 * Reschedule a faster reconnect, if this was a automatically
1900 * connected configuration entry. (Note that if we have had
1901 * a rehash in between, the status has been changed to
1902 * CONF_ILLEGAL). But only do this if it was a "good" link.
1904 server_p
->hold
= time(NULL
);
1906 (server_p
->hold
- client_p
->localClient
->lasttime
>
1907 HANGONGOODLINK
) ? HANGONRETRYDELAY
: ConFreq(server_p
->class);
1911 else if(IsClient(client_p
))
1913 ServerStats
.is_cl
++;
1914 ServerStats
.is_cbs
+= client_p
->localClient
->sendB
;
1915 ServerStats
.is_cbr
+= client_p
->localClient
->receiveB
;
1916 ServerStats
.is_cti
+= (unsigned long long)(rb_current_time() - client_p
->localClient
->firsttime
);
1919 ServerStats
.is_ni
++;
1921 if(client_p
->localClient
->F
!= NULL
)
1923 /* attempt to flush any pending dbufs. Evil, but .. -- adrian */
1924 if(!IsIOError(client_p
))
1925 send_queued(client_p
);
1927 del_from_cli_fd_hash(client_p
);
1928 rb_close(client_p
->localClient
->F
);
1929 client_p
->localClient
->F
= NULL
;
1932 rb_linebuf_donebuf(&client_p
->localClient
->buf_sendq
);
1933 rb_linebuf_donebuf(&client_p
->localClient
->buf_recvq
);
1934 detach_conf(client_p
);
1936 /* XXX shouldnt really be done here. */
1937 detach_server_conf(client_p
);
1939 client_p
->from
= NULL
; /* ...this should catch them! >:) --msa */
1940 ClearMyConnect(client_p
);
1941 SetIOError(client_p
);
1947 error_exit_client(struct Client
*client_p
, int error
)
1950 * ...hmm, with non-blocking sockets we might get
1951 * here from quite valid reasons, although.. why
1952 * would select report "data available" when there
1953 * wasn't... so, this must be an error anyway... --msa
1954 * actually, EOF occurs when read() returns 0 and
1955 * in due course, select() returns that fd as ready
1956 * for reading even though it ends up being an EOF. -avalon
1959 int current_error
= rb_get_sockerr(client_p
->localClient
->F
);
1961 SetIOError(client_p
);
1963 if(IsServer(client_p
) || IsHandshake(client_p
))
1967 sendto_realops_snomask(SNO_GENERAL
, is_remote_connect(client_p
) && !IsServer(client_p
) ? L_NETWIDE
: L_ALL
,
1968 "Server %s closed the connection",
1971 ilog(L_SERVER
, "Server %s closed the connection",
1972 log_client_name(client_p
, SHOW_IP
));
1976 sendto_realops_snomask(SNO_GENERAL
, is_remote_connect(client_p
) && !IsServer(client_p
) ? L_NETWIDE
: L_ALL
,
1977 "Lost connection to %s: %s",
1978 client_p
->name
, strerror(current_error
));
1979 ilog(L_SERVER
, "Lost connection to %s: %s",
1980 log_client_name(client_p
, SHOW_IP
), strerror(current_error
));
1985 rb_strlcpy(errmsg
, "Remote host closed the connection", sizeof(errmsg
));
1987 rb_snprintf(errmsg
, sizeof(errmsg
), "Read error: %s", strerror(current_error
));
1989 exit_client(client_p
, client_p
, &me
, errmsg
);