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
39 #include "s_newconf.h"
52 #include "blacklist.h"
55 #include "irc_dictionary.h"
58 #define DEBUG_EXITED_CLIENTS
60 static void check_pings_list(rb_dlink_list
* list
);
61 static void check_unknowns_list(rb_dlink_list
* list
);
62 static void free_exited_clients(void *unused
);
63 static void exit_aborted_clients(void *unused
);
65 static int exit_remote_client(struct Client
*, struct Client
*, struct Client
*,const char *);
66 static int exit_remote_server(struct Client
*, struct Client
*, struct Client
*,const char *);
67 static int exit_local_client(struct Client
*, struct Client
*, struct Client
*,const char *);
68 static int exit_unknown_client(struct Client
*, struct Client
*, struct Client
*,const char *);
69 static int exit_local_server(struct Client
*, struct Client
*, struct Client
*,const char *);
70 static int qs_server(struct Client
*, struct Client
*, struct Client
*, const char *comment
);
72 static EVH check_pings
;
74 static rb_bh
*client_heap
= NULL
;
75 static rb_bh
*lclient_heap
= NULL
;
76 static rb_bh
*pclient_heap
= NULL
;
77 static rb_bh
*user_heap
= NULL
;
78 static rb_bh
*away_heap
= NULL
;
79 static char current_uid
[IDLEN
];
81 struct Dictionary
*nd_dict
= NULL
;
89 rb_dlink_list dead_list
;
90 #ifdef DEBUG_EXITED_CLIENTS
91 static rb_dlink_list dead_remote_list
;
97 struct Client
*client
;
98 char notice
[REASONLEN
];
101 static rb_dlink_list abort_list
;
109 * side effects - initialize client free memory
115 * start off the check ping event .. -- adrian
116 * Every 30 seconds is plenty -- db
118 client_heap
= rb_bh_create(sizeof(struct Client
), CLIENT_HEAP_SIZE
, "client_heap");
119 lclient_heap
= rb_bh_create(sizeof(struct LocalUser
), LCLIENT_HEAP_SIZE
, "lclient_heap");
120 pclient_heap
= rb_bh_create(sizeof(struct PreClient
), PCLIENT_HEAP_SIZE
, "pclient_heap");
121 user_heap
= rb_bh_create(sizeof(struct User
), USER_HEAP_SIZE
, "user_heap");
122 away_heap
= rb_bh_create(AWAYLEN
, AWAY_HEAP_SIZE
, "away_heap");
124 rb_event_addish("check_pings", check_pings
, NULL
, 30);
125 rb_event_addish("free_exited_clients", &free_exited_clients
, NULL
, 4);
126 rb_event_addish("exit_aborted_clients", exit_aborted_clients
, NULL
, 1);
127 rb_event_add("flood_recalc", flood_recalc
, NULL
, 1);
129 nd_dict
= irc_dictionary_create(irccmp
);
134 * make_client - create a new Client struct and set it to initial state.
136 * from == NULL, create local client (a client connected
139 * from, create remote client (behind a socket
140 * associated with the client defined by
141 * 'from'). ('from' is a local client!!).
144 make_client(struct Client
*from
)
146 struct Client
*client_p
= NULL
;
147 struct LocalUser
*localClient
;
149 client_p
= rb_bh_alloc(client_heap
);
153 client_p
->from
= client_p
; /* 'from' of local client is self! */
155 localClient
= rb_bh_alloc(lclient_heap
);
156 SetMyConnect(client_p
);
157 client_p
->localClient
= localClient
;
159 client_p
->localClient
->lasttime
= client_p
->localClient
->firsttime
= rb_current_time();
161 client_p
->localClient
->F
= NULL
;
163 client_p
->preClient
= rb_bh_alloc(pclient_heap
);;
165 /* as good a place as any... */
166 rb_dlinkAdd(client_p
, &client_p
->localClient
->tnode
, &unknown_list
);
169 { /* from is not NULL */
170 client_p
->localClient
= NULL
;
171 client_p
->preClient
= NULL
;
172 client_p
->from
= from
; /* 'from' of local client is self! */
175 SetUnknown(client_p
);
176 strcpy(client_p
->username
, "unknown");
182 free_pre_client(struct Client
*client_p
)
184 struct Blacklist
*blptr
;
186 s_assert(NULL
!= client_p
);
188 if(client_p
->preClient
== NULL
)
191 blptr
= client_p
->preClient
->dnsbl_listed
;
193 unref_blacklist(blptr
);
194 abort_blacklist_queries(client_p
);
195 rb_bh_free(pclient_heap
, client_p
->preClient
);
196 client_p
->preClient
= NULL
;
200 free_local_client(struct Client
*client_p
)
202 s_assert(NULL
!= client_p
);
203 s_assert(&me
!= client_p
);
205 if(client_p
->localClient
== NULL
)
209 * clean up extra sockets from P-lines which have been discarded.
211 if(client_p
->localClient
->listener
)
213 s_assert(0 < client_p
->localClient
->listener
->ref_count
);
214 if(0 == --client_p
->localClient
->listener
->ref_count
215 && !client_p
->localClient
->listener
->active
)
216 free_listener(client_p
->localClient
->listener
);
217 client_p
->localClient
->listener
= 0;
220 if(client_p
->localClient
->F
!= NULL
)
222 del_from_cli_fd_hash(client_p
);
223 rb_close(client_p
->localClient
->F
);
226 if(client_p
->localClient
->passwd
)
228 memset(client_p
->localClient
->passwd
, 0,
229 strlen(client_p
->localClient
->passwd
));
230 rb_free(client_p
->localClient
->passwd
);
233 rb_free(client_p
->localClient
->auth_user
);
235 if(client_p
->localClient
->override_timeout_event
)
237 rb_event_delete(client_p
->localClient
->override_timeout_event
);
240 rb_free(client_p
->localClient
->challenge
);
241 rb_free(client_p
->localClient
->fullcaps
);
242 rb_free(client_p
->localClient
->opername
);
243 rb_free(client_p
->localClient
->mangledhost
);
244 if (client_p
->localClient
->privset
)
245 privilegeset_unref(client_p
->localClient
->privset
);
248 ssld_decrement_clicount(client_p
->localClient
->ssl_ctl
);
250 if(IsCapable(client_p
, CAP_ZIP
))
251 ssld_decrement_clicount(client_p
->localClient
->z_ctl
);
253 rb_bh_free(lclient_heap
, client_p
->localClient
);
254 client_p
->localClient
= NULL
;
258 free_client(struct Client
*client_p
)
260 s_assert(NULL
!= client_p
);
261 s_assert(&me
!= client_p
);
262 free_local_client(client_p
);
263 free_pre_client(client_p
);
264 rb_free(client_p
->certfp
);
265 rb_bh_free(client_heap
, client_p
);
269 * check_pings - go through the local client list and check activity
270 * kill off stuff that should die
272 * inputs - NOT USED (from event)
273 * output - next time_t when check_pings() should be called again
277 * A PING can be sent to clients as necessary.
279 * Client/Server ping outs are handled.
283 * Addon from adrian. We used to call this after nextping seconds,
284 * however I've changed it to run once a second. This is only for
285 * PING timeouts, not K/etc-line checks (thanks dianora!). Having it
286 * run once a second makes life a lot easier - when a new client connects
287 * and they need a ping in 4 seconds, if nextping was set to 20 seconds
288 * we end up waiting 20 seconds. This is stupid. :-)
289 * I will optimise (hah!) check_pings() once I've finished working on
290 * tidying up other network IO evilnesses.
295 check_pings(void *notused
)
297 check_pings_list(&lclient_list
);
298 check_pings_list(&serv_list
);
299 check_unknowns_list(&unknown_list
);
305 * inputs - pointer to list to check
310 check_pings_list(rb_dlink_list
* list
)
312 char scratch
[32]; /* way too generous but... */
313 struct Client
*client_p
; /* current local client_p being examined */
314 int ping
= 0; /* ping time value from client */
315 rb_dlink_node
*ptr
, *next_ptr
;
317 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, list
->head
)
319 client_p
= ptr
->data
;
321 if(!MyConnect(client_p
) || IsDead(client_p
))
324 ping
= get_client_ping(client_p
);
326 if(ping
< (rb_current_time() - client_p
->localClient
->lasttime
))
329 * If the client/server hasnt talked to us in 2*ping seconds
330 * and it has a ping time, then close its connection.
332 if(((rb_current_time() - client_p
->localClient
->lasttime
) >= (2 * ping
)
333 && (client_p
->flags
& FLAGS_PINGSENT
)))
335 if(IsServer(client_p
))
337 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
338 "No response from %s, closing link",
341 "No response from %s, closing link",
342 log_client_name(client_p
, HIDE_IP
));
344 (void) rb_snprintf(scratch
, sizeof(scratch
),
345 "Ping timeout: %d seconds",
346 (int) (rb_current_time() - client_p
->localClient
->lasttime
));
348 exit_client(client_p
, client_p
, &me
, scratch
);
351 else if((client_p
->flags
& FLAGS_PINGSENT
) == 0)
354 * if we havent PINGed the connection and we havent
355 * heard from it in a while, PING it to make sure
358 client_p
->flags
|= FLAGS_PINGSENT
;
359 /* not nice but does the job */
360 client_p
->localClient
->lasttime
= rb_current_time() - ping
;
361 sendto_one(client_p
, "PING :%s", me
.name
);
370 * check_unknowns_list
372 * inputs - pointer to list of unknown clients
374 * side effects - unknown clients get marked for termination after n seconds
377 check_unknowns_list(rb_dlink_list
* list
)
379 rb_dlink_node
*ptr
, *next_ptr
;
380 struct Client
*client_p
;
383 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, list
->head
)
385 client_p
= ptr
->data
;
387 if(IsDead(client_p
) || IsClosing(client_p
))
390 /* still has DNSbls to validate against */
391 if(client_p
->preClient
!= NULL
&&
392 rb_dlink_list_length(&client_p
->preClient
->dnsbl_queries
) > 0)
396 * Check UNKNOWN connections - if they have been in this state
397 * for > 30s, close them.
400 timeout
= IsAnyServer(client_p
) ? ConfigFileEntry
.connect_timeout
: 30;
401 if((rb_current_time() - client_p
->localClient
->firsttime
) > timeout
)
403 if(IsAnyServer(client_p
))
405 sendto_realops_snomask(SNO_GENERAL
, is_remote_connect(client_p
) ? L_NETWIDE
: L_ALL
,
406 "No response from %s, closing link",
409 "No response from %s, closing link",
410 log_client_name(client_p
, HIDE_IP
));
412 exit_client(client_p
, client_p
, &me
, "Connection timed out");
418 notify_banned_client(struct Client
*client_p
, struct ConfItem
*aconf
, int ban
)
420 static const char conn_closed
[] = "Connection closed";
421 static const char d_lined
[] = "D-lined";
422 static const char k_lined
[] = "K-lined";
423 const char *reason
= NULL
;
424 const char *exit_reason
= conn_closed
;
426 if(ConfigFileEntry
.kline_with_reason
)
428 reason
= get_user_ban_reason(aconf
);
429 exit_reason
= reason
;
433 reason
= aconf
->status
== D_LINED
? d_lined
: k_lined
;
436 if(ban
== D_LINED
&& !IsPerson(client_p
))
437 sendto_one(client_p
, "NOTICE DLINE :*** You have been D-lined");
439 sendto_one(client_p
, form_str(ERR_YOUREBANNEDCREEP
),
440 me
.name
, client_p
->name
, reason
);
442 exit_client(client_p
, client_p
, &me
,
443 EmptyString(ConfigFileEntry
.kline_reason
) ? exit_reason
:
444 ConfigFileEntry
.kline_reason
);
451 * side effects - Check all connections for a pending k/dline against the
452 * client, exit the client if found.
455 check_banned_lines(void)
462 /* check_klines_event()
466 * side effects - check_klines() is called, kline_queued unset
469 check_klines_event(void *unused
)
479 * side effects - all clients will be checked for klines
484 struct Client
*client_p
;
485 struct ConfItem
*aconf
;
487 rb_dlink_node
*next_ptr
;
489 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
491 client_p
= ptr
->data
;
493 if(IsMe(client_p
) || !IsPerson(client_p
))
496 if((aconf
= find_kline(client_p
)) != NULL
)
498 if(IsExemptKline(client_p
))
500 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
501 "KLINE over-ruled for %s, client is kline_exempt [%s@%s]",
502 get_client_name(client_p
, HIDE_IP
),
503 aconf
->user
, aconf
->host
);
507 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
508 "KLINE active for %s",
509 get_client_name(client_p
, HIDE_IP
));
511 notify_banned_client(client_p
, aconf
, K_LINED
);
521 * side effects - all clients will be checked for dlines
526 struct Client
*client_p
;
527 struct ConfItem
*aconf
;
529 rb_dlink_node
*next_ptr
;
531 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
533 client_p
= ptr
->data
;
538 if((aconf
= find_dline((struct sockaddr
*)&client_p
->localClient
->ip
,client_p
->localClient
->ip
.ss_family
)) != NULL
)
540 if(aconf
->status
& CONF_EXEMPTDLINE
)
543 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
544 "DLINE active for %s",
545 get_client_name(client_p
, HIDE_IP
));
547 notify_banned_client(client_p
, aconf
, D_LINED
);
552 /* dlines need to be checked against unknowns too */
553 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, unknown_list
.head
)
555 client_p
= ptr
->data
;
557 if((aconf
= find_dline((struct sockaddr
*)&client_p
->localClient
->ip
,client_p
->localClient
->ip
.ss_family
)) != NULL
)
559 if(aconf
->status
& CONF_EXEMPTDLINE
)
562 notify_banned_client(client_p
, aconf
, D_LINED
);
571 * side effects - all clients will be checked for xlines
576 struct Client
*client_p
;
577 struct ConfItem
*aconf
;
579 rb_dlink_node
*next_ptr
;
581 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
583 client_p
= ptr
->data
;
585 if(IsMe(client_p
) || !IsPerson(client_p
))
588 if((aconf
= find_xline(client_p
->info
, 1)) != NULL
)
590 if(IsExemptKline(client_p
))
592 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
593 "XLINE over-ruled for %s, client is kline_exempt [%s]",
594 get_client_name(client_p
, HIDE_IP
),
599 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "XLINE active for %s",
600 get_client_name(client_p
, HIDE_IP
));
602 (void) exit_client(client_p
, client_p
, &me
, "Bad user info");
609 * update_client_exit_stats
611 * input - pointer to client
616 update_client_exit_stats(struct Client
*client_p
)
618 if(IsServer(client_p
))
620 sendto_realops_snomask(SNO_EXTERNAL
, L_ALL
,
621 "Server %s split from %s",
622 client_p
->name
, client_p
->servptr
->name
);
623 if(HasSentEob(client_p
))
626 else if(IsClient(client_p
))
631 if(IsInvisible(client_p
))
635 if(splitchecking
&& !splitmode
)
636 check_splitmode(NULL
);
640 * release_client_state
642 * input - pointer to client to release
647 release_client_state(struct Client
*client_p
)
649 if(client_p
->user
!= NULL
)
651 free_user(client_p
->user
, client_p
); /* try this here */
655 if(client_p
->serv
->user
!= NULL
)
656 free_user(client_p
->serv
->user
, client_p
);
657 if(client_p
->serv
->fullcaps
)
658 rb_free(client_p
->serv
->fullcaps
);
659 rb_free(client_p
->serv
);
664 * remove_client_from_list
665 * inputs - point to client to remove
667 * side effects - taken the code from ExitOneClient() for this
668 * and placed it here. - avalon
671 remove_client_from_list(struct Client
*client_p
)
673 s_assert(NULL
!= client_p
);
678 /* A client made with make_client()
679 * is on the unknown_list until removed.
680 * If it =does= happen to exit before its removed from that list
681 * and its =not= on the global_client_list, it will core here.
682 * short circuit that case now -db
684 if(client_p
->node
.prev
== NULL
&& client_p
->node
.next
== NULL
)
687 rb_dlinkDelete(&client_p
->node
, &global_client_list
);
689 update_client_exit_stats(client_p
);
694 * find_person - find person by (nick)name.
695 * inputs - pointer to name
696 * output - return client pointer
700 find_person(const char *name
)
702 struct Client
*c2ptr
;
704 c2ptr
= find_client(name
);
706 if(c2ptr
&& IsPerson(c2ptr
))
712 find_named_person(const char *name
)
714 struct Client
*c2ptr
;
716 c2ptr
= find_named_client(name
);
718 if(c2ptr
&& IsPerson(c2ptr
))
725 * find_chasing - find the client structure for a nick name (user)
726 * using history mechanism if necessary. If the client is not found,
727 * an error message (NO SUCH NICK) is generated. If the client was found
728 * through the history, chasing will be 1 and otherwise 0.
731 find_chasing(struct Client
*source_p
, const char *user
, int *chasing
)
735 if(MyClient(source_p
))
736 who
= find_named_person(user
);
738 who
= find_person(user
);
743 if(who
|| IsDigit(*user
))
746 if(!(who
= get_history(user
, (long) KILLCHASETIMELIMIT
)))
748 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
749 form_str(ERR_NOSUCHNICK
), user
);
758 * get_client_name - Return the name of the client
759 * for various tracking and
760 * admin purposes. The main purpose of this function is to
761 * return the "socket host" name of the client, if that
762 * differs from the advertised name (other than case).
763 * But, this can be used to any client structure.
766 * Watch out the allocation of "nbuf", if either source_p->name
767 * or source_p->sockhost gets changed into pointers instead of
768 * directly allocated within the structure...
771 * Function return either a pointer to the structure (source_p) or
772 * to internal buffer (nbuf). *NEVER* use the returned pointer
773 * to modify what it points!!!
777 get_client_name(struct Client
*client
, int showip
)
779 static char nbuf
[HOSTLEN
* 2 + USERLEN
+ 5];
781 s_assert(NULL
!= client
);
785 if(MyConnect(client
))
787 if(!irccmp(client
->name
, client
->host
))
790 if(ConfigFileEntry
.hide_spoof_ips
&&
791 showip
== SHOW_IP
&& IsIPSpoof(client
))
793 if(IsAnyServer(client
))
796 /* And finally, let's get the host information, ip or name */
800 rb_snprintf(nbuf
, sizeof(nbuf
), "%s[%s@%s]",
801 client
->name
, client
->username
,
805 rb_snprintf(nbuf
, sizeof(nbuf
), "%s[%s@255.255.255.255]",
806 client
->name
, client
->username
);
809 rb_snprintf(nbuf
, sizeof(nbuf
), "%s[%s@%s]",
810 client
->name
, client
->username
, client
->host
);
815 /* As pointed out by Adel Mezibra
816 * Neph|l|m@EFnet. Was missing a return here.
823 * This version is the same as get_client_name, but doesnt contain the
824 * code that will hide IPs always. This should be used for logfiles.
827 log_client_name(struct Client
*target_p
, int showip
)
829 static char nbuf
[HOSTLEN
* 2 + USERLEN
+ 5];
834 if(MyConnect(target_p
))
836 if(irccmp(target_p
->name
, target_p
->host
) == 0)
837 return target_p
->name
;
842 rb_snprintf(nbuf
, sizeof(nbuf
), "%s[%s@%s]", target_p
->name
,
843 target_p
->username
, target_p
->sockhost
);
847 rb_snprintf(nbuf
, sizeof(nbuf
), "%s[%s@255.255.255.255]",
848 target_p
->name
, target_p
->username
);
851 rb_snprintf(nbuf
, sizeof(nbuf
), "%s[%s@%s]", target_p
->name
,
852 target_p
->username
, target_p
->host
);
858 return target_p
->name
;
861 /* is_remote_connect - Returns whether a server was /connect'ed by a remote
862 * oper (send notices netwide) */
864 is_remote_connect(struct Client
*client_p
)
868 if (client_p
->serv
== NULL
)
870 oper
= find_named_person(client_p
->serv
->by
);
871 return oper
!= NULL
&& IsOper(oper
) && !MyConnect(oper
);
875 free_exited_clients(void *unused
)
877 rb_dlink_node
*ptr
, *next
;
878 struct Client
*target_p
;
880 RB_DLINK_FOREACH_SAFE(ptr
, next
, dead_list
.head
)
882 target_p
= ptr
->data
;
884 #ifdef DEBUG_EXITED_CLIENTS
886 struct abort_client
*abt
;
890 RB_DLINK_FOREACH(aptr
, abort_list
.head
)
893 if(abt
->client
== target_p
)
896 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
897 "On abort_list: %s stat: %u flags: %u/%u handler: %c",
898 target_p
->name
, (unsigned int) target_p
->status
,
899 target_p
->flags
, target_p
->flags2
, target_p
->handler
);
900 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
901 "Please report this to the charybdis developers!");
908 rb_dlinkDestroy(ptr
, &dead_list
);
914 if(ptr
->data
== NULL
)
916 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
917 "Warning: null client on dead_list!");
918 rb_dlinkDestroy(ptr
, &dead_list
);
921 release_client_state(target_p
);
922 free_client(target_p
);
923 rb_dlinkDestroy(ptr
, &dead_list
);
926 #ifdef DEBUG_EXITED_CLIENTS
927 RB_DLINK_FOREACH_SAFE(ptr
, next
, dead_remote_list
.head
)
929 target_p
= ptr
->data
;
931 if(ptr
->data
== NULL
)
933 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
934 "Warning: null client on dead_list!");
935 rb_dlinkDestroy(ptr
, &dead_list
);
938 release_client_state(target_p
);
939 free_client(target_p
);
940 rb_dlinkDestroy(ptr
, &dead_remote_list
);
947 ** Recursively send QUITs and SQUITs for source_p and all its dependent clients
948 ** and servers to those servers that need them. A server needs the client
949 ** QUITs if it can't figure them out from the SQUIT (ie pre-TS4) or if it
950 ** isn't getting the SQUIT because of @#(*&@)# hostmasking. With TS4, once
951 ** a link gets a SQUIT, it doesn't need any QUIT/SQUITs for clients depending
952 ** on that one -orabidoo
955 recurse_send_quits(struct Client
*client_p
, struct Client
*source_p
,
956 struct Client
*to
, const char *comment1
,
959 struct Client
*target_p
;
960 rb_dlink_node
*ptr
, *ptr_next
;
961 /* If this server can handle quit storm (QS) removal
962 * of dependents, just send the SQUIT
965 if(IsCapable(to
, CAP_QS
))
967 sendto_one(to
, "SQUIT %s :%s",
968 get_id(source_p
, to
), comment
);
972 RB_DLINK_FOREACH_SAFE(ptr
, ptr_next
, source_p
->serv
->users
.head
)
974 target_p
= ptr
->data
;
975 sendto_one(to
, ":%s QUIT :%s", target_p
->name
, comment1
);
977 RB_DLINK_FOREACH_SAFE(ptr
, ptr_next
, source_p
->serv
->servers
.head
)
979 target_p
= ptr
->data
;
980 recurse_send_quits(client_p
, target_p
, to
, comment1
, comment
);
982 sendto_one(to
, "SQUIT %s :%s", source_p
->name
, comment
);
987 ** Remove all clients that depend on source_p; assumes all (S)QUITs have
988 ** already been sent. we make sure to exit a server's dependent clients
989 ** and servers before the server itself; exit_one_client takes care of
990 ** actually removing things off llists. tweaked from +CSr31 -orabidoo
993 * added sanity test code.... source_p->serv might be NULL...
996 recurse_remove_clients(struct Client
*source_p
, const char *comment
)
998 struct Client
*target_p
;
999 rb_dlink_node
*ptr
, *ptr_next
;
1004 if(source_p
->serv
== NULL
) /* oooops. uh this is actually a major bug */
1007 /* this is very ugly, but it saves cpu :P */
1008 if(ConfigFileEntry
.nick_delay
> 0)
1010 RB_DLINK_FOREACH_SAFE(ptr
, ptr_next
, source_p
->serv
->users
.head
)
1012 target_p
= ptr
->data
;
1013 target_p
->flags
|= FLAGS_KILLED
;
1014 add_nd_entry(target_p
->name
);
1016 if(!IsDead(target_p
) && !IsClosing(target_p
))
1017 exit_remote_client(NULL
, target_p
, &me
, comment
);
1022 RB_DLINK_FOREACH_SAFE(ptr
, ptr_next
, source_p
->serv
->users
.head
)
1024 target_p
= ptr
->data
;
1025 target_p
->flags
|= FLAGS_KILLED
;
1027 if(!IsDead(target_p
) && !IsClosing(target_p
))
1028 exit_remote_client(NULL
, target_p
, &me
, comment
);
1032 RB_DLINK_FOREACH_SAFE(ptr
, ptr_next
, source_p
->serv
->servers
.head
)
1034 target_p
= ptr
->data
;
1035 recurse_remove_clients(target_p
, comment
);
1036 qs_server(NULL
, target_p
, &me
, comment
);
1041 ** Remove *everything* that depends on source_p, from all lists, and sending
1042 ** all necessary QUITs and SQUITs. source_p itself is still on the lists,
1043 ** and its SQUITs have been sent except for the upstream one -orabidoo
1046 remove_dependents(struct Client
*client_p
,
1047 struct Client
*source_p
,
1048 struct Client
*from
, const char *comment
, const char *comment1
)
1051 rb_dlink_node
*ptr
, *next
;
1053 RB_DLINK_FOREACH_SAFE(ptr
, next
, serv_list
.head
)
1057 if(IsMe(to
) || to
== source_p
->from
||
1058 (to
== client_p
&& IsCapable(to
, CAP_QS
)))
1061 recurse_send_quits(client_p
, source_p
, to
, comment1
, comment
);
1064 recurse_remove_clients(source_p
, comment1
);
1068 exit_aborted_clients(void *unused
)
1070 struct abort_client
*abt
;
1071 rb_dlink_node
*ptr
, *next
;
1072 RB_DLINK_FOREACH_SAFE(ptr
, next
, abort_list
.head
)
1076 #ifdef DEBUG_EXITED_CLIENTS
1078 if(rb_dlinkFind(abt
->client
, &dead_list
))
1081 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1082 "On dead_list: %s stat: %u flags: %u/%u handler: %c",
1083 abt
->client
->name
, (unsigned int) abt
->client
->status
,
1084 abt
->client
->flags
, abt
->client
->flags2
, abt
->client
->handler
);
1085 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1086 "Please report this to the charybdis developers!");
1092 s_assert(*((unsigned long*)abt
->client
) != 0xdeadbeef); /* This is lame but its a debug thing */
1093 rb_dlinkDelete(ptr
, &abort_list
);
1095 if(IsAnyServer(abt
->client
))
1096 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1097 "Closing link to %s: %s",
1098 abt
->client
->name
, abt
->notice
);
1100 /* its no longer on abort list - we *must* remove
1101 * FLAGS_CLOSING otherwise exit_client() will not run --fl
1103 abt
->client
->flags
&= ~FLAGS_CLOSING
;
1104 exit_client(abt
->client
, abt
->client
, &me
, abt
->notice
);
1111 * dead_link - Adds client to a list of clients that need an exit_client()
1115 dead_link(struct Client
*client_p
, int sendqex
)
1117 struct abort_client
*abt
;
1119 s_assert(!IsMe(client_p
));
1120 if(IsDead(client_p
) || IsClosing(client_p
) || IsMe(client_p
))
1123 abt
= (struct abort_client
*) rb_malloc(sizeof(struct abort_client
));
1126 rb_strlcpy(abt
->notice
, "Max SendQ exceeded", sizeof(abt
->notice
));
1128 rb_snprintf(abt
->notice
, sizeof(abt
->notice
), "Write error: %s", strerror(errno
));
1130 abt
->client
= client_p
;
1131 SetIOError(client_p
);
1133 SetClosing(client_p
);
1134 rb_dlinkAdd(abt
, &abt
->node
, &abort_list
);
1138 /* This does the remove of the user from channels..local or remote */
1140 exit_generic_client(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1141 const char *comment
)
1143 rb_dlink_node
*ptr
, *next_ptr
;
1145 if(IsOper(source_p
))
1146 rb_dlinkFindDestroy(source_p
, &oper_list
);
1148 /* get rid of any metadata the user may have */
1149 user_metadata_clear(source_p
);
1151 sendto_common_channels_local(source_p
, ":%s!%s@%s QUIT :%s",
1153 source_p
->username
, source_p
->host
, comment
);
1155 remove_user_from_channels(source_p
);
1157 /* Should not be in any channels now */
1158 s_assert(source_p
->user
->channel
.head
== NULL
);
1160 /* Clean up invitefield */
1161 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, source_p
->user
->invited
.head
)
1163 del_invite(ptr
->data
, source_p
);
1166 /* Clean up allow lists */
1167 del_all_accepts(source_p
);
1169 add_history(source_p
, 0);
1170 off_history(source_p
);
1172 monitor_signoff(source_p
);
1174 if(has_id(source_p
))
1175 del_from_id_hash(source_p
->id
, source_p
);
1177 del_from_hostname_hash(source_p
->orighost
, source_p
);
1178 del_from_client_hash(source_p
->name
, source_p
);
1179 remove_client_from_list(source_p
);
1183 * Assumes IsPerson(source_p) && !MyConnect(source_p)
1187 exit_remote_client(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1188 const char *comment
)
1190 exit_generic_client(client_p
, source_p
, from
, comment
);
1192 if(source_p
->servptr
&& source_p
->servptr
->serv
)
1194 rb_dlinkDelete(&source_p
->lnode
, &source_p
->servptr
->serv
->users
);
1197 if((source_p
->flags
& FLAGS_KILLED
) == 0)
1199 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
,
1200 ":%s QUIT :%s", use_id(source_p
), comment
);
1204 #ifdef DEBUG_EXITED_CLIENTS
1205 rb_dlinkAddAlloc(source_p
, &dead_remote_list
);
1207 rb_dlinkAddAlloc(source_p
, &dead_list
);
1209 return(CLIENT_EXITED
);
1213 * This assumes IsUnknown(source_p) == TRUE and MyConnect(source_p) == TRUE
1217 exit_unknown_client(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1218 const char *comment
)
1220 delete_auth_queries(source_p
);
1221 if (source_p
->localClient
->dnsquery
)
1223 delete_resolver_queries(source_p
->localClient
->dnsquery
);
1224 rb_free(source_p
->localClient
->dnsquery
);
1226 rb_dlinkDelete(&source_p
->localClient
->tnode
, &unknown_list
);
1228 if(!IsIOError(source_p
))
1229 sendto_one(source_p
, "ERROR :Closing Link: %s (%s)",
1230 source_p
->user
!= NULL
? source_p
->host
: "127.0.0.1",
1233 close_connection(source_p
);
1235 if(has_id(source_p
))
1236 del_from_id_hash(source_p
->id
, source_p
);
1238 del_from_hostname_hash(source_p
->host
, source_p
);
1239 del_from_client_hash(source_p
->name
, source_p
);
1240 remove_client_from_list(source_p
);
1242 rb_dlinkAddAlloc(source_p
, &dead_list
);
1244 /* Note that we don't need to add unknowns to the dead_list */
1245 return(CLIENT_EXITED
);
1249 exit_remote_server(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1250 const char *comment
)
1252 static char comment1
[(HOSTLEN
*2)+2];
1253 static char newcomment
[BUFSIZE
];
1254 struct Client
*target_p
;
1256 if(ConfigServerHide
.flatten_links
)
1257 strcpy(comment1
, "*.net *.split");
1260 strcpy(comment1
, source_p
->servptr
->name
);
1261 strcat(comment1
, " ");
1262 strcat(comment1
, source_p
->name
);
1265 rb_snprintf(newcomment
, sizeof(newcomment
), "by %s: %s",
1266 from
->name
, comment
);
1268 if(source_p
->serv
!= NULL
)
1269 remove_dependents(client_p
, source_p
, from
, IsPerson(from
) ? newcomment
: comment
, comment1
);
1271 if(source_p
->servptr
&& source_p
->servptr
->serv
)
1272 rb_dlinkDelete(&source_p
->lnode
, &source_p
->servptr
->serv
->servers
);
1276 rb_dlinkFindDestroy(source_p
, &global_serv_list
);
1277 target_p
= source_p
->from
;
1279 if(target_p
!= NULL
&& IsServer(target_p
) && target_p
!= client_p
&&
1280 !IsMe(target_p
) && (source_p
->flags
& FLAGS_KILLED
) == 0)
1282 sendto_one(target_p
, ":%s SQUIT %s :%s",
1283 get_id(from
, target_p
), get_id(source_p
, target_p
),
1287 if(has_id(source_p
))
1288 del_from_id_hash(source_p
->id
, source_p
);
1290 del_from_client_hash(source_p
->name
, source_p
);
1291 remove_client_from_list(source_p
);
1292 scache_split(source_p
->serv
->nameinfo
);
1295 #ifdef DEBUG_EXITED_CLIENTS
1296 rb_dlinkAddAlloc(source_p
, &dead_remote_list
);
1298 rb_dlinkAddAlloc(source_p
, &dead_list
);
1304 qs_server(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1305 const char *comment
)
1307 if(source_p
->servptr
&& source_p
->servptr
->serv
)
1308 rb_dlinkDelete(&source_p
->lnode
, &source_p
->servptr
->serv
->servers
);
1312 rb_dlinkFindDestroy(source_p
, &global_serv_list
);
1314 if(has_id(source_p
))
1315 del_from_id_hash(source_p
->id
, source_p
);
1317 del_from_client_hash(source_p
->name
, source_p
);
1318 remove_client_from_list(source_p
);
1319 scache_split(source_p
->serv
->nameinfo
);
1322 rb_dlinkAddAlloc(source_p
, &dead_list
);
1327 exit_local_server(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1328 const char *comment
)
1330 static char comment1
[(HOSTLEN
*2)+2];
1331 static char newcomment
[BUFSIZE
];
1332 unsigned int sendk
, recvk
;
1334 rb_dlinkDelete(&source_p
->localClient
->tnode
, &serv_list
);
1335 rb_dlinkFindDestroy(source_p
, &global_serv_list
);
1337 unset_chcap_usage_counts(source_p
);
1338 sendk
= source_p
->localClient
->sendK
;
1339 recvk
= source_p
->localClient
->receiveK
;
1341 /* Always show source here, so the server notices show
1342 * which side initiated the split -- jilles
1344 rb_snprintf(newcomment
, sizeof(newcomment
), "by %s: %s",
1345 from
== source_p
? me
.name
: from
->name
, comment
);
1346 if (!IsIOError(source_p
))
1347 sendto_one(source_p
, "SQUIT %s :%s", use_id(source_p
),
1349 if(client_p
!= NULL
&& source_p
!= client_p
&& !IsIOError(source_p
))
1351 sendto_one(source_p
, "ERROR :Closing Link: 127.0.0.1 %s (%s)",
1352 source_p
->name
, comment
);
1355 if(source_p
->servptr
&& source_p
->servptr
->serv
)
1356 rb_dlinkDelete(&source_p
->lnode
, &source_p
->servptr
->serv
->servers
);
1361 close_connection(source_p
);
1363 if(ConfigServerHide
.flatten_links
)
1364 strcpy(comment1
, "*.net *.split");
1367 strcpy(comment1
, source_p
->servptr
->name
);
1368 strcat(comment1
, " ");
1369 strcat(comment1
, source_p
->name
);
1372 if(source_p
->serv
!= NULL
)
1373 remove_dependents(client_p
, source_p
, from
, IsPerson(from
) ? newcomment
: comment
, comment1
);
1375 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s was connected"
1376 " for %ld seconds. %d/%d sendK/recvK.",
1377 source_p
->name
, (long) rb_current_time() - source_p
->localClient
->firsttime
, sendk
, recvk
);
1379 ilog(L_SERVER
, "%s was connected for %ld seconds. %d/%d sendK/recvK.",
1380 source_p
->name
, (long) rb_current_time() - source_p
->localClient
->firsttime
, sendk
, recvk
);
1382 if(has_id(source_p
))
1383 del_from_id_hash(source_p
->id
, source_p
);
1385 del_from_client_hash(source_p
->name
, source_p
);
1386 remove_client_from_list(source_p
);
1387 scache_split(source_p
->serv
->nameinfo
);
1390 rb_dlinkAddAlloc(source_p
, &dead_list
);
1396 * This assumes IsPerson(source_p) == TRUE && MyConnect(source_p) == TRUE
1400 exit_local_client(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1401 const char *comment
)
1403 unsigned long on_for
;
1406 exit_generic_client(client_p
, source_p
, from
, comment
);
1407 clear_monitor(source_p
);
1409 s_assert(IsPerson(source_p
));
1410 rb_dlinkDelete(&source_p
->localClient
->tnode
, &lclient_list
);
1411 rb_dlinkDelete(&source_p
->lnode
, &me
.serv
->users
);
1413 if(IsOper(source_p
))
1414 rb_dlinkFindDestroy(source_p
, &local_oper_list
);
1416 sendto_realops_snomask(SNO_CCONN
, L_ALL
,
1417 "Client exiting: %s (%s@%s) [%s] [%s]",
1419 source_p
->username
, source_p
->host
, comment
,
1420 show_ip(NULL
, source_p
) ? source_p
->sockhost
: "255.255.255.255");
1422 sendto_realops_snomask(SNO_CCONNEXT
, L_ALL
,
1423 "CLIEXIT %s %s %s %s 0 %s",
1424 source_p
->name
, source_p
->username
, source_p
->host
,
1425 show_ip(NULL
, source_p
) ? source_p
->sockhost
: "255.255.255.255",
1428 on_for
= rb_current_time() - source_p
->localClient
->firsttime
;
1430 ilog(L_USER
, "%s (%3lu:%02lu:%02lu): %s!%s@%s %s %d/%d",
1431 rb_ctime(rb_current_time(), tbuf
, sizeof(tbuf
)), on_for
/ 3600,
1432 (on_for
% 3600) / 60, on_for
% 60,
1433 source_p
->name
, source_p
->username
, source_p
->host
,
1435 source_p
->localClient
->sendK
, source_p
->localClient
->receiveK
);
1437 sendto_one(source_p
, "ERROR :Closing Link: %s (%s)", source_p
->host
, comment
);
1438 close_connection(source_p
);
1440 if((source_p
->flags
& FLAGS_KILLED
) == 0)
1442 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
,
1443 ":%s QUIT :%s", use_id(source_p
), comment
);
1447 rb_dlinkAddAlloc(source_p
, &dead_list
);
1448 return(CLIENT_EXITED
);
1453 ** exit_client - This is old "m_bye". Name changed, because this is not a
1454 ** protocol function, but a general server utility function.
1456 ** This function exits a client of *any* type (user, server, etc)
1457 ** from this server. Also, this generates all necessary prototol
1458 ** messages that this exit may cause.
1460 ** 1) If the client is a local client, then this implicitly
1461 ** exits all other clients depending on this connection (e.g.
1462 ** remote clients having 'from'-field that points to this.
1464 ** 2) If the client is a remote client, then only this is exited.
1466 ** For convenience, this function returns a suitable value for
1467 ** m_function return value:
1469 ** CLIENT_EXITED if (client_p == source_p)
1470 ** 0 if (client_p != source_p)
1473 exit_client(struct Client
*client_p
, /* The local client originating the
1474 * exit or NULL, if this exit is
1475 * generated by this server for
1477 * This will not get any of the
1478 * generated messages. */
1479 struct Client
*source_p
, /* Client exiting */
1480 struct Client
*from
, /* Client firing off this Exit,
1482 const char *comment
/* Reason for the exit */
1485 hook_data_client_exit hdata
;
1486 if(IsClosing(source_p
))
1489 /* note, this HAS to be here, when we exit a client we attempt to
1490 * send them data, if this generates a write error we must *not* add
1491 * them to the abort list --fl
1493 SetClosing(source_p
);
1495 hdata
.local_link
= client_p
;
1496 hdata
.target
= source_p
;
1498 hdata
.comment
= comment
;
1499 call_hook(h_client_exit
, &hdata
);
1501 if(MyConnect(source_p
))
1503 /* Local clients of various types */
1504 if(IsPerson(source_p
))
1505 return exit_local_client(client_p
, source_p
, from
, comment
);
1506 else if(IsServer(source_p
))
1507 return exit_local_server(client_p
, source_p
, from
, comment
);
1508 /* IsUnknown || IsConnecting || IsHandShake */
1509 else if(!IsReject(source_p
))
1510 return exit_unknown_client(client_p
, source_p
, from
, comment
);
1515 if(IsPerson(source_p
))
1516 return exit_remote_client(client_p
, source_p
, from
, comment
);
1517 else if(IsServer(source_p
))
1518 return exit_remote_server(client_p
, source_p
, from
, comment
);
1525 * Count up local client memory
1528 /* XXX one common Client list now */
1530 count_local_client_memory(size_t * count
, size_t * local_client_memory_used
)
1533 rb_bh_usage(lclient_heap
, count
, NULL
, &lusage
, NULL
);
1534 *local_client_memory_used
= lusage
+ (*count
* (sizeof(void *) + sizeof(struct Client
)));
1538 * Count up remote client memory
1541 count_remote_client_memory(size_t * count
, size_t * remote_client_memory_used
)
1543 size_t lcount
, rcount
;
1544 rb_bh_usage(lclient_heap
, &lcount
, NULL
, NULL
, NULL
);
1545 rb_bh_usage(client_heap
, &rcount
, NULL
, NULL
, NULL
);
1546 *count
= rcount
- lcount
;
1547 *remote_client_memory_used
= *count
* (sizeof(void *) + sizeof(struct Client
));
1552 * accept processing, this adds a form of "caller ID" to ircd
1554 * If a client puts themselves into "caller ID only" mode,
1555 * only clients that match a client pointer they have put on
1556 * the accept list will be allowed to message them.
1558 * [ source.on_allow_list ] -> [ target1 ] -> [ target2 ]
1560 * [target.allow_list] -> [ source1 ] -> [source2 ]
1562 * i.e. a target will have a link list of source pointers it will allow
1563 * each source client then has a back pointer pointing back
1564 * to the client that has it on its accept list.
1565 * This allows for exit_one_client to remove these now bogus entries
1566 * from any client having an accept on them.
1571 * inputs - pointer to exiting client
1573 * side effects - Walk through given clients allow_list and on_allow_list
1574 * remove all references to this client
1577 del_all_accepts(struct Client
*client_p
)
1580 rb_dlink_node
*next_ptr
;
1581 struct Client
*target_p
;
1583 if(MyClient(client_p
) && client_p
->localClient
->allow_list
.head
)
1585 /* clear this clients accept list, and remove them from
1586 * everyones on_accept_list
1588 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, client_p
->localClient
->allow_list
.head
)
1590 target_p
= ptr
->data
;
1591 rb_dlinkFindDestroy(client_p
, &target_p
->on_allow_list
);
1592 rb_dlinkDestroy(ptr
, &client_p
->localClient
->allow_list
);
1596 /* remove this client from everyones accept list */
1597 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, client_p
->on_allow_list
.head
)
1599 target_p
= ptr
->data
;
1600 rb_dlinkFindDestroy(client_p
, &target_p
->localClient
->allow_list
);
1601 rb_dlinkDestroy(ptr
, &client_p
->on_allow_list
);
1606 * show_ip() - asks if the true IP shoudl be shown when source is
1607 * askin for info about target
1609 * Inputs - source_p who is asking
1610 * - target_p who do we want the info on
1611 * Output - returns 1 if clear IP can be showed, otherwise 0
1612 * Side Effects - none
1616 show_ip(struct Client
*source_p
, struct Client
*target_p
)
1618 if(IsAnyServer(target_p
))
1622 else if(IsIPSpoof(target_p
))
1624 /* source == NULL indicates message is being sent
1627 if(!ConfigFileEntry
.hide_spoof_ips
&&
1628 (source_p
== NULL
|| MyOper(source_p
)))
1632 else if(IsDynSpoof(target_p
) && (source_p
!= NULL
&& !IsOper(source_p
)))
1639 show_ip_conf(struct ConfItem
*aconf
, struct Client
*source_p
)
1641 if(IsConfDoSpoofIp(aconf
))
1643 if(!ConfigFileEntry
.hide_spoof_ips
&& MyOper(source_p
))
1655 * inputs - pointer to client struct
1656 * output - pointer to struct User
1657 * side effects - add's an User information block to a client
1658 * if it was not previously allocated.
1661 make_user(struct Client
*client_p
)
1664 struct Dictionary
*metadata
;
1666 user
= client_p
->user
;
1669 user
= (struct User
*) rb_bh_alloc(user_heap
);
1671 client_p
->user
= user
;
1673 metadata
= irc_dictionary_create(irccmp
);
1674 client_p
->user
->metadata
= metadata
;
1682 * inputs - pointer to client struct
1683 * output - pointer to server_t
1684 * side effects - add's an Server information block to a client
1685 * if it was not previously allocated.
1688 make_server(struct Client
*client_p
)
1690 struct Server
*serv
= client_p
->serv
;
1694 serv
= (struct Server
*) rb_malloc(sizeof(struct Server
));
1695 client_p
->serv
= serv
;
1697 return client_p
->serv
;
1703 * inputs - pointer to user struct
1704 * - pointer to client struct
1706 * side effects - Decrease user reference count by one and release block,
1707 * if count reaches 0
1710 free_user(struct User
*user
, struct Client
*client_p
)
1712 free_away(client_p
);
1714 if(--user
->refcnt
<= 0)
1717 rb_free((char *) user
->away
);
1722 if(user
->refcnt
< 0 || user
->invited
.head
|| user
->channel
.head
)
1724 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1725 "* %#lx user (%s!%s@%s) %#lx %#lx %#lx %lu %d *",
1726 (unsigned long) client_p
,
1727 client_p
? client_p
->
1731 (unsigned long) user
,
1732 (unsigned long) user
->invited
.head
,
1733 (unsigned long) user
->channel
.head
,
1734 rb_dlink_list_length(&user
->channel
),
1736 s_assert(!user
->refcnt
);
1737 s_assert(!user
->invited
.head
);
1738 s_assert(!user
->channel
.head
);
1741 rb_bh_free(user_heap
, user
);
1746 allocate_away(struct Client
*client_p
)
1748 if(client_p
->user
->away
== NULL
)
1749 client_p
->user
->away
= rb_bh_alloc(away_heap
);
1754 free_away(struct Client
*client_p
)
1756 if(client_p
->user
!= NULL
&& client_p
->user
->away
!= NULL
) {
1757 rb_bh_free(away_heap
, client_p
->user
->away
);
1758 client_p
->user
->away
= NULL
;
1767 for(i
= 0; i
< 3; i
++)
1768 current_uid
[i
] = me
.id
[i
];
1770 for(i
= 3; i
< 9; i
++)
1771 current_uid
[i
] = 'A';
1773 current_uid
[9] = '\0';
1782 for(i
= 8; i
> 3; i
--)
1784 if(current_uid
[i
] == 'Z')
1786 current_uid
[i
] = '0';
1789 else if(current_uid
[i
] != '9')
1795 current_uid
[i
] = 'A';
1798 /* if this next if() triggers, we're fucked. */
1799 if(current_uid
[3] == 'Z')
1801 current_uid
[i
] = 'A';
1812 * Close the physical connection. This function must make
1813 * MyConnect(client_p) == FALSE, and set client_p->from == NULL.
1816 close_connection(struct Client
*client_p
)
1818 s_assert(client_p
!= NULL
);
1819 if(client_p
== NULL
)
1822 s_assert(MyConnect(client_p
));
1823 if(!MyConnect(client_p
))
1826 if(IsServer(client_p
))
1828 struct server_conf
*server_p
;
1830 ServerStats
.is_sv
++;
1831 ServerStats
.is_sbs
+= client_p
->localClient
->sendB
;
1832 ServerStats
.is_sbr
+= client_p
->localClient
->receiveB
;
1833 ServerStats
.is_sti
+= (unsigned long long)(rb_current_time() - client_p
->localClient
->firsttime
);
1836 * If the connection has been up for a long amount of time, schedule
1837 * a 'quick' reconnect, else reset the next-connect cycle.
1839 if((server_p
= find_server_conf(client_p
->name
)) != NULL
)
1842 * Reschedule a faster reconnect, if this was a automatically
1843 * connected configuration entry. (Note that if we have had
1844 * a rehash in between, the status has been changed to
1845 * CONF_ILLEGAL). But only do this if it was a "good" link.
1847 server_p
->hold
= time(NULL
);
1849 (server_p
->hold
- client_p
->localClient
->lasttime
>
1850 HANGONGOODLINK
) ? HANGONRETRYDELAY
: ConFreq(server_p
->class);
1854 else if(IsClient(client_p
))
1856 ServerStats
.is_cl
++;
1857 ServerStats
.is_cbs
+= client_p
->localClient
->sendB
;
1858 ServerStats
.is_cbr
+= client_p
->localClient
->receiveB
;
1859 ServerStats
.is_cti
+= (unsigned long long)(rb_current_time() - client_p
->localClient
->firsttime
);
1862 ServerStats
.is_ni
++;
1864 if(client_p
->localClient
->F
!= NULL
)
1866 /* attempt to flush any pending dbufs. Evil, but .. -- adrian */
1867 if(!IsIOError(client_p
))
1868 send_queued(client_p
);
1870 del_from_cli_fd_hash(client_p
);
1871 rb_close(client_p
->localClient
->F
);
1872 client_p
->localClient
->F
= NULL
;
1875 rb_linebuf_donebuf(&client_p
->localClient
->buf_sendq
);
1876 rb_linebuf_donebuf(&client_p
->localClient
->buf_recvq
);
1877 detach_conf(client_p
);
1879 /* XXX shouldnt really be done here. */
1880 detach_server_conf(client_p
);
1882 client_p
->from
= NULL
; /* ...this should catch them! >:) --msa */
1883 ClearMyConnect(client_p
);
1884 SetIOError(client_p
);
1890 error_exit_client(struct Client
*client_p
, int error
)
1893 * ...hmm, with non-blocking sockets we might get
1894 * here from quite valid reasons, although.. why
1895 * would select report "data available" when there
1896 * wasn't... so, this must be an error anyway... --msa
1897 * actually, EOF occurs when read() returns 0 and
1898 * in due course, select() returns that fd as ready
1899 * for reading even though it ends up being an EOF. -avalon
1902 int current_error
= rb_get_sockerr(client_p
->localClient
->F
);
1904 SetIOError(client_p
);
1906 if(IsServer(client_p
) || IsHandshake(client_p
))
1910 sendto_realops_snomask(SNO_GENERAL
, is_remote_connect(client_p
) && !IsServer(client_p
) ? L_NETWIDE
: L_ALL
,
1911 "Server %s closed the connection",
1914 ilog(L_SERVER
, "Server %s closed the connection",
1915 log_client_name(client_p
, SHOW_IP
));
1919 sendto_realops_snomask(SNO_GENERAL
, is_remote_connect(client_p
) && !IsServer(client_p
) ? L_NETWIDE
: L_ALL
,
1920 "Lost connection to %s: %s",
1921 client_p
->name
, strerror(current_error
));
1922 ilog(L_SERVER
, "Lost connection to %s: %s",
1923 log_client_name(client_p
, SHOW_IP
), strerror(current_error
));
1928 rb_strlcpy(errmsg
, "Remote host closed the connection", sizeof(errmsg
));
1930 rb_snprintf(errmsg
, sizeof(errmsg
), "Read error: %s", strerror(current_error
));
1932 exit_client(client_p
, client_p
, &me
, errmsg
);
1938 * inputs - pointer to client struct
1939 * - name of metadata item you wish to add
1940 * - value of metadata item
1941 * - 1 if metadata should be propegated, 0 if not
1943 * side effects - metadata is added to the user in question
1944 * - metadata is propegated if propegate is set.
1947 user_metadata_add(struct Client
*target
, const char *name
, const char *value
, int propegate
)
1949 struct Metadata
*md
;
1951 md
= rb_malloc(sizeof(struct Metadata
));
1952 md
->name
= rb_strdup(name
);
1953 md
->value
= rb_strdup(value
);
1955 irc_dictionary_add(target
->user
->metadata
, md
->name
, md
);
1958 sendto_match_servs(&me
, "*", CAP_ENCAP
, NOCAPS
, "ENCAP * METADATA ADD %s %s :%s",
1959 target
->id
, name
, value
);
1965 * user_metadata_delete
1967 * inputs - pointer to client struct
1968 * - name of metadata item you wish to delete
1970 * side effects - metadata is deleted from the user in question
1971 * - deletion is propegated if propegate is set
1974 user_metadata_delete(struct Client
*target
, const char *name
, int propegate
)
1976 struct Metadata
*md
= user_metadata_find(target
, name
);
1981 irc_dictionary_delete(target
->user
->metadata
, md
->name
);
1986 sendto_match_servs(&me
, "*", CAP_ENCAP
, NOCAPS
, "ENCAP * METADATA DELETE %s %s",
1991 * user_metadata_find
1993 * inputs - pointer to client struct
1994 * - name of metadata item you wish to read
1995 * output - the requested metadata, if it exists, elsewise null.
1999 user_metadata_find(struct Client
*target
, const char *name
)
2004 if(!target
->user
->metadata
)
2007 return irc_dictionary_retrieve(target
->user
->metadata
, name
);
2010 * user_metadata_clear
2012 * inputs - pointer to user struct
2014 * side effects - metadata is cleared from the user in question
2017 user_metadata_clear(struct Client
*target
)
2019 struct Metadata
*md
;
2020 struct DictionaryIter iter
;
2022 DICTIONARY_FOREACH(md
, &iter
, target
->user
->metadata
)
2024 user_metadata_delete(target
, md
->name
, 0);