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
37 #include "s_newconf.h"
52 #include "rb_dictionary.h"
57 #define DEBUG_EXITED_CLIENTS
59 static void check_pings_list(rb_dlink_list
* list
);
60 static void check_unknowns_list(rb_dlink_list
* list
);
61 static void free_exited_clients(void *unused
);
62 static void exit_aborted_clients(void *unused
);
64 static int exit_remote_client(struct Client
*, struct Client
*, struct Client
*,const char *);
65 static int exit_remote_server(struct Client
*, struct Client
*, struct Client
*,const char *);
66 static int exit_local_client(struct Client
*, struct Client
*, struct Client
*,const char *);
67 static int exit_unknown_client(struct Client
*, struct Client
*, struct Client
*,const char *);
68 static int exit_local_server(struct Client
*, struct Client
*, struct Client
*,const char *);
69 static int qs_server(struct Client
*, struct Client
*, struct Client
*, const char *comment
);
71 static EVH check_pings
;
73 static rb_bh
*client_heap
= NULL
;
74 static rb_bh
*lclient_heap
= NULL
;
75 static rb_bh
*pclient_heap
= NULL
;
76 static rb_bh
*user_heap
= NULL
;
77 static rb_bh
*away_heap
= NULL
;
78 static char current_uid
[IDLEN
];
79 static uint32_t current_connid
= 0;
81 rb_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
= rb_dictionary_create("nickdelay", irccmp
);
133 * connid_get - allocate a connid
136 * outputs - a connid token which is used to represent a logical circuit
137 * side effects - current_connid is incremented, possibly multiple times.
138 * the association of the connid to it's client is committed.
141 connid_get(struct Client
*client_p
)
143 s_assert(MyConnect(client_p
));
144 if (!MyConnect(client_p
))
147 /* find a connid that is available */
148 while (find_cli_connid_hash(++current_connid
) != NULL
)
150 /* handle wraparound, current_connid must NEVER be 0 */
151 if (current_connid
== 0)
155 add_to_cli_connid_hash(client_p
, current_connid
);
156 rb_dlinkAddAlloc(RB_UINT_TO_POINTER(current_connid
), &client_p
->localClient
->connids
);
158 return current_connid
;
162 * connid_put - free a connid
164 * inputs - connid to free
166 * side effects - connid bookkeeping structures are freed
169 connid_put(uint32_t id
)
171 struct Client
*client_p
;
177 client_p
= find_cli_connid_hash(id
);
178 if (client_p
== NULL
)
181 del_from_cli_connid_hash(id
);
182 rb_dlinkFindDestroy(RB_UINT_TO_POINTER(id
), &client_p
->localClient
->connids
);
186 * client_release_connids - release any connids still attached to a client
188 * inputs - client to garbage collect
190 * side effects - client's connids are garbage collected
193 client_release_connids(struct Client
*client_p
)
195 rb_dlink_node
*ptr
, *ptr2
;
197 if (client_p
->localClient
->connids
.head
)
198 s_assert(MyConnect(client_p
));
200 if (!MyConnect(client_p
))
203 RB_DLINK_FOREACH_SAFE(ptr
, ptr2
, client_p
->localClient
->connids
.head
)
204 connid_put(RB_POINTER_TO_UINT(ptr
->data
));
208 * make_client - create a new Client struct and set it to initial state.
210 * from == NULL, create local client (a client connected
213 * from, create remote client (behind a socket
214 * associated with the client defined by
215 * 'from'). ('from' is a local client!!).
218 make_client(struct Client
*from
)
220 struct Client
*client_p
= NULL
;
221 struct LocalUser
*localClient
;
223 client_p
= rb_bh_alloc(client_heap
);
227 client_p
->from
= client_p
; /* 'from' of local client is self! */
229 localClient
= rb_bh_alloc(lclient_heap
);
230 SetMyConnect(client_p
);
231 client_p
->localClient
= localClient
;
233 client_p
->localClient
->lasttime
= client_p
->localClient
->firsttime
= rb_current_time();
235 client_p
->localClient
->F
= NULL
;
237 client_p
->preClient
= rb_bh_alloc(pclient_heap
);
239 /* as good a place as any... */
240 rb_dlinkAdd(client_p
, &client_p
->localClient
->tnode
, &unknown_list
);
243 { /* from is not NULL */
244 client_p
->localClient
= NULL
;
245 client_p
->preClient
= NULL
;
246 client_p
->from
= from
; /* 'from' of local client is self! */
249 SetUnknown(client_p
);
250 rb_strlcpy(client_p
->username
, "unknown", sizeof(client_p
->username
));
256 free_pre_client(struct Client
*client_p
)
258 s_assert(NULL
!= client_p
);
260 if(client_p
->preClient
== NULL
)
263 s_assert(client_p
->preClient
->auth
.cid
== 0);
265 rb_free(client_p
->preClient
->auth
.data
);
266 rb_free(client_p
->preClient
->auth
.reason
);
268 rb_bh_free(pclient_heap
, client_p
->preClient
);
269 client_p
->preClient
= NULL
;
273 free_local_client(struct Client
*client_p
)
275 s_assert(NULL
!= client_p
);
276 s_assert(&me
!= client_p
);
278 if(client_p
->localClient
== NULL
)
282 * clean up extra sockets from P-lines which have been discarded.
284 if(client_p
->localClient
->listener
)
286 s_assert(0 < client_p
->localClient
->listener
->ref_count
);
287 if(0 == --client_p
->localClient
->listener
->ref_count
288 && !client_p
->localClient
->listener
->active
)
289 free_listener(client_p
->localClient
->listener
);
290 client_p
->localClient
->listener
= 0;
293 client_release_connids(client_p
);
294 if(client_p
->localClient
->F
!= NULL
)
296 rb_close(client_p
->localClient
->F
);
299 if(client_p
->localClient
->passwd
)
301 memset(client_p
->localClient
->passwd
, 0,
302 strlen(client_p
->localClient
->passwd
));
303 rb_free(client_p
->localClient
->passwd
);
306 rb_free(client_p
->localClient
->auth_user
);
307 rb_free(client_p
->localClient
->challenge
);
308 rb_free(client_p
->localClient
->fullcaps
);
309 rb_free(client_p
->localClient
->opername
);
310 rb_free(client_p
->localClient
->mangledhost
);
311 if (client_p
->localClient
->privset
)
312 privilegeset_unref(client_p
->localClient
->privset
);
315 ssld_decrement_clicount(client_p
->localClient
->ssl_ctl
);
317 if (IsCapable(client_p
, CAP_ZIP
))
318 ssld_decrement_clicount(client_p
->localClient
->z_ctl
);
320 if (client_p
->localClient
->ws_ctl
!= NULL
)
321 wsockd_decrement_clicount(client_p
->localClient
->ws_ctl
);
323 rb_bh_free(lclient_heap
, client_p
->localClient
);
324 client_p
->localClient
= NULL
;
328 free_client(struct Client
*client_p
)
330 s_assert(NULL
!= client_p
);
331 s_assert(&me
!= client_p
);
332 free_local_client(client_p
);
333 free_pre_client(client_p
);
334 rb_free(client_p
->certfp
);
335 rb_bh_free(client_heap
, client_p
);
339 * check_pings - go through the local client list and check activity
340 * kill off stuff that should die
342 * inputs - NOT USED (from event)
343 * output - next time_t when check_pings() should be called again
347 * A PING can be sent to clients as necessary.
349 * Client/Server ping outs are handled.
353 * Addon from adrian. We used to call this after nextping seconds,
354 * however I've changed it to run once a second. This is only for
355 * PING timeouts, not K/etc-line checks (thanks dianora!). Having it
356 * run once a second makes life a lot easier - when a new client connects
357 * and they need a ping in 4 seconds, if nextping was set to 20 seconds
358 * we end up waiting 20 seconds. This is stupid. :-)
359 * I will optimise (hah!) check_pings() once I've finished working on
360 * tidying up other network IO evilnesses.
365 check_pings(void *notused
)
367 check_pings_list(&lclient_list
);
368 check_pings_list(&serv_list
);
369 check_unknowns_list(&unknown_list
);
375 * inputs - pointer to list to check
380 check_pings_list(rb_dlink_list
* list
)
382 char scratch
[32]; /* way too generous but... */
383 struct Client
*client_p
; /* current local client_p being examined */
384 int ping
= 0; /* ping time value from client */
385 rb_dlink_node
*ptr
, *next_ptr
;
387 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, list
->head
)
389 client_p
= ptr
->data
;
391 if(!MyConnect(client_p
) || IsDead(client_p
))
394 ping
= get_client_ping(client_p
);
396 if(ping
< (rb_current_time() - client_p
->localClient
->lasttime
))
399 * If the client/server hasnt talked to us in 2*ping seconds
400 * and it has a ping time, then close its connection.
402 if(((rb_current_time() - client_p
->localClient
->lasttime
) >= (2 * ping
)
403 && (client_p
->flags
& FLAGS_PINGSENT
)))
405 if(IsServer(client_p
))
407 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
408 "No response from %s, closing link",
411 "No response from %s, closing link",
412 log_client_name(client_p
, HIDE_IP
));
414 (void) snprintf(scratch
, sizeof(scratch
),
415 "Ping timeout: %d seconds",
416 (int) (rb_current_time() - client_p
->localClient
->lasttime
));
418 exit_client(client_p
, client_p
, &me
, scratch
);
421 else if((client_p
->flags
& FLAGS_PINGSENT
) == 0)
424 * if we havent PINGed the connection and we havent
425 * heard from it in a while, PING it to make sure
428 client_p
->flags
|= FLAGS_PINGSENT
;
429 /* not nice but does the job */
430 client_p
->localClient
->lasttime
= rb_current_time() - ping
;
431 sendto_one(client_p
, "PING :%s", me
.name
);
440 * check_unknowns_list
442 * inputs - pointer to list of unknown clients
444 * side effects - unknown clients get marked for termination after n seconds
447 check_unknowns_list(rb_dlink_list
* list
)
449 rb_dlink_node
*ptr
, *next_ptr
;
450 struct Client
*client_p
;
453 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, list
->head
)
455 client_p
= ptr
->data
;
457 if(IsDead(client_p
) || IsClosing(client_p
))
460 /* Still querying with authd */
461 if(client_p
->preClient
!= NULL
&& client_p
->preClient
->auth
.cid
!= 0)
465 * Check UNKNOWN connections - if they have been in this state
466 * for > 30s, close them.
469 timeout
= IsAnyServer(client_p
) ? ConfigFileEntry
.connect_timeout
: 30;
470 if((rb_current_time() - client_p
->localClient
->firsttime
) > timeout
)
472 if(IsAnyServer(client_p
))
474 sendto_realops_snomask(SNO_GENERAL
, is_remote_connect(client_p
) ? L_NETWIDE
: L_ALL
,
475 "No response from %s, closing link",
478 "No response from %s, closing link",
479 log_client_name(client_p
, HIDE_IP
));
481 exit_client(client_p
, client_p
, &me
, "Connection timed out");
487 notify_banned_client(struct Client
*client_p
, struct ConfItem
*aconf
, int ban
)
489 static const char conn_closed
[] = "Connection closed";
490 static const char d_lined
[] = "D-lined";
491 static const char k_lined
[] = "K-lined";
492 const char *reason
= NULL
;
493 const char *exit_reason
= conn_closed
;
495 if(ConfigFileEntry
.kline_with_reason
)
497 reason
= get_user_ban_reason(aconf
);
498 exit_reason
= reason
;
502 reason
= aconf
->status
== D_LINED
? d_lined
: k_lined
;
505 if(ban
== D_LINED
&& !IsPerson(client_p
))
506 sendto_one(client_p
, "NOTICE DLINE :*** You have been D-lined");
508 sendto_one(client_p
, form_str(ERR_YOUREBANNEDCREEP
),
509 me
.name
, client_p
->name
, reason
);
511 exit_client(client_p
, client_p
, &me
,
512 EmptyString(ConfigFileEntry
.kline_reason
) ? exit_reason
:
513 ConfigFileEntry
.kline_reason
);
520 * side effects - Check all connections for a pending k/dline against the
521 * client, exit the client if found.
524 check_banned_lines(void)
531 /* check_klines_event()
535 * side effects - check_klines() is called, kline_queued unset
538 check_klines_event(void *unused
)
540 kline_queued
= false;
548 * side effects - all clients will be checked for klines
553 struct Client
*client_p
;
554 struct ConfItem
*aconf
;
556 rb_dlink_node
*next_ptr
;
558 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
560 client_p
= ptr
->data
;
562 if(IsMe(client_p
) || !IsPerson(client_p
))
565 if((aconf
= find_kline(client_p
)) != NULL
)
567 if(IsExemptKline(client_p
))
569 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
570 "KLINE over-ruled for %s, client is kline_exempt [%s@%s]",
571 get_client_name(client_p
, HIDE_IP
),
572 aconf
->user
, aconf
->host
);
576 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
577 "KLINE active for %s",
578 get_client_name(client_p
, HIDE_IP
));
580 notify_banned_client(client_p
, aconf
, K_LINED
);
590 * side effects - all clients will be checked for dlines
595 struct Client
*client_p
;
596 struct ConfItem
*aconf
;
598 rb_dlink_node
*next_ptr
;
600 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
602 client_p
= ptr
->data
;
607 if((aconf
= find_dline((struct sockaddr
*)&client_p
->localClient
->ip
, GET_SS_FAMILY(&client_p
->localClient
->ip
))) != NULL
)
609 if(aconf
->status
& CONF_EXEMPTDLINE
)
612 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
613 "DLINE active for %s",
614 get_client_name(client_p
, HIDE_IP
));
616 notify_banned_client(client_p
, aconf
, D_LINED
);
621 /* dlines need to be checked against unknowns too */
622 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, unknown_list
.head
)
624 client_p
= ptr
->data
;
626 if((aconf
= find_dline((struct sockaddr
*)&client_p
->localClient
->ip
, GET_SS_FAMILY(&client_p
->localClient
->ip
))) != NULL
)
628 if(aconf
->status
& CONF_EXEMPTDLINE
)
631 notify_banned_client(client_p
, aconf
, D_LINED
);
640 * side effects - all clients will be checked for xlines
645 struct Client
*client_p
;
646 struct ConfItem
*aconf
;
648 rb_dlink_node
*next_ptr
;
650 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
652 client_p
= ptr
->data
;
654 if(IsMe(client_p
) || !IsPerson(client_p
))
657 if((aconf
= find_xline(client_p
->info
, 1)) != NULL
)
659 if(IsExemptKline(client_p
))
661 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
662 "XLINE over-ruled for %s, client is kline_exempt [%s]",
663 get_client_name(client_p
, HIDE_IP
),
668 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "XLINE active for %s",
669 get_client_name(client_p
, HIDE_IP
));
671 (void) exit_client(client_p
, client_p
, &me
, "Bad user info");
679 * inputs - resv, reason, time
681 * side effects - all local clients matching resv will be FNC'd
684 resv_nick_fnc(const char *mask
, const char *reason
, int temp_time
)
686 struct Client
*client_p
, *target_p
;
688 rb_dlink_node
*next_ptr
;
690 char note
[NICKLEN
+10];
692 if (!ConfigFileEntry
.resv_fnc
)
695 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
697 client_p
= ptr
->data
;
699 if(IsMe(client_p
) || !IsPerson(client_p
) || IsExemptResv(client_p
))
702 /* Skip users that already have UID nicks. */
703 if(IsDigit(client_p
->name
[0]))
706 if(match_esc(mask
, client_p
->name
))
711 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
712 "RESV forced nick change for %s!%s@%s to %s; nick matched [%s] (%s)",
713 client_p
->name
, client_p
->username
, client_p
->host
, nick
, mask
, reason
);
715 sendto_realops_snomask(SNO_NCHANGE
, L_ALL
,
716 "Nick change: From %s to %s [%s@%s]",
717 client_p
->name
, nick
, client_p
->username
, client_p
->host
);
722 sendto_one_notice(client_p
,
723 ":*** Nick %s is temporarily unavailable on this server.",
728 sendto_one_notice(client_p
,
729 ":*** Nick %s is no longer available on this server.",
733 /* Do all of the nick-changing gymnastics. */
734 client_p
->tsinfo
= rb_current_time();
735 whowas_add_history(client_p
, 1);
737 monitor_signoff(client_p
);
739 invalidate_bancache_user(client_p
);
741 sendto_common_channels_local(client_p
, NOCAPS
, NOCAPS
, ":%s!%s@%s NICK :%s",
742 client_p
->name
, client_p
->username
, client_p
->host
, nick
);
743 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s NICK %s :%ld",
744 use_id(client_p
), nick
, (long) client_p
->tsinfo
);
746 del_from_client_hash(client_p
->name
, client_p
);
747 rb_strlcpy(client_p
->name
, nick
, sizeof(client_p
->name
));
748 add_to_client_hash(nick
, client_p
);
750 monitor_signon(client_p
);
752 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, client_p
->on_allow_list
.head
)
754 target_p
= ptr
->data
;
755 rb_dlinkFindDestroy(client_p
, &target_p
->localClient
->allow_list
);
756 rb_dlinkDestroy(ptr
, &client_p
->on_allow_list
);
759 snprintf(note
, sizeof(note
), "Nick: %s", nick
);
760 rb_note(client_p
->localClient
->F
, note
);
766 * update_client_exit_stats
768 * input - pointer to client
773 update_client_exit_stats(struct Client
*client_p
)
775 if(IsServer(client_p
))
777 sendto_realops_snomask(SNO_EXTERNAL
, L_ALL
,
778 "Server %s split from %s",
779 client_p
->name
, client_p
->servptr
->name
);
780 if(HasSentEob(client_p
))
783 else if(IsClient(client_p
))
788 if(IsInvisible(client_p
))
792 if(splitchecking
&& !splitmode
)
793 check_splitmode(NULL
);
797 * release_client_state
799 * input - pointer to client to release
804 release_client_state(struct Client
*client_p
)
806 if(client_p
->user
!= NULL
)
808 free_user(client_p
->user
, client_p
); /* try this here */
812 if(client_p
->serv
->user
!= NULL
)
813 free_user(client_p
->serv
->user
, client_p
);
814 if(client_p
->serv
->fullcaps
)
815 rb_free(client_p
->serv
->fullcaps
);
816 rb_free(client_p
->serv
);
821 * remove_client_from_list
822 * inputs - point to client to remove
824 * side effects - taken the code from ExitOneClient() for this
825 * and placed it here. - avalon
828 remove_client_from_list(struct Client
*client_p
)
830 s_assert(NULL
!= client_p
);
835 /* A client made with make_client()
836 * is on the unknown_list until removed.
837 * If it =does= happen to exit before its removed from that list
838 * and its =not= on the global_client_list, it will core here.
839 * short circuit that case now -db
841 if(client_p
->node
.prev
== NULL
&& client_p
->node
.next
== NULL
)
844 rb_dlinkDelete(&client_p
->node
, &global_client_list
);
846 update_client_exit_stats(client_p
);
852 * input - nickname to check, flag for nick from local client
853 * output - 0 if erroneous, else 1
857 clean_nick(const char *nick
, int loc_client
)
861 /* nicks cant start with a digit or -, and must have a length */
862 if(*nick
== '-' || *nick
== '\0')
865 if(loc_client
&& IsDigit(*nick
))
871 if(!IsNickChar(*nick
))
876 if(len
>= NICKLEN
&& (unsigned int)len
>= ConfigFileEntry
.nicklen
)
883 * find_person - find person by (nick)name.
884 * inputs - pointer to name
885 * output - return client pointer
889 find_person(const char *name
)
891 struct Client
*c2ptr
;
893 c2ptr
= find_client(name
);
895 if(c2ptr
&& IsPerson(c2ptr
))
901 find_named_person(const char *name
)
903 struct Client
*c2ptr
;
905 c2ptr
= find_named_client(name
);
907 if(c2ptr
&& IsPerson(c2ptr
))
914 * find_chasing - find the client structure for a nick name (user)
915 * using history mechanism if necessary. If the client is not found,
916 * an error message (NO SUCH NICK) is generated. If the client was found
917 * through the history, chasing will be 1 and otherwise 0.
920 find_chasing(struct Client
*source_p
, const char *user
, int *chasing
)
924 if(MyClient(source_p
))
925 who
= find_named_person(user
);
927 who
= find_person(user
);
932 if(who
|| IsDigit(*user
))
935 if(!(who
= whowas_get_history(user
, (long) KILLCHASETIMELIMIT
)))
937 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
938 form_str(ERR_NOSUCHNICK
), user
);
947 * get_client_name - Return the name of the client
948 * for various tracking and
949 * admin purposes. The main purpose of this function is to
950 * return the "socket host" name of the client, if that
951 * differs from the advertised name (other than case).
952 * But, this can be used to any client structure.
955 * Watch out the allocation of "nbuf", if either source_p->name
956 * or source_p->sockhost gets changed into pointers instead of
957 * directly allocated within the structure...
960 * Function return either a pointer to the structure (source_p) or
961 * to internal buffer (nbuf). *NEVER* use the returned pointer
962 * to modify what it points!!!
966 get_client_name(struct Client
*client
, int showip
)
968 static char nbuf
[HOSTLEN
* 2 + USERLEN
+ 5];
970 s_assert(NULL
!= client
);
974 if(MyConnect(client
))
976 if(!irccmp(client
->name
, client
->host
))
979 if(ConfigFileEntry
.hide_spoof_ips
&&
980 showip
== SHOW_IP
&& IsIPSpoof(client
))
982 if(IsAnyServer(client
))
985 /* And finally, let's get the host information, ip or name */
989 snprintf(nbuf
, sizeof(nbuf
), "%s[%s@%s]",
990 client
->name
, client
->username
,
994 snprintf(nbuf
, sizeof(nbuf
), "%s[%s@255.255.255.255]",
995 client
->name
, client
->username
);
998 snprintf(nbuf
, sizeof(nbuf
), "%s[%s@%s]",
999 client
->name
, client
->username
, client
->host
);
1004 /* As pointed out by Adel Mezibra
1005 * Neph|l|m@EFnet. Was missing a return here.
1007 return client
->name
;
1010 /* log_client_name()
1012 * This version is the same as get_client_name, but doesnt contain the
1013 * code that will hide IPs always. This should be used for logfiles.
1016 log_client_name(struct Client
*target_p
, int showip
)
1018 static char nbuf
[HOSTLEN
* 2 + USERLEN
+ 5];
1020 if(target_p
== NULL
)
1023 if(MyConnect(target_p
))
1025 if(irccmp(target_p
->name
, target_p
->host
) == 0)
1026 return target_p
->name
;
1031 snprintf(nbuf
, sizeof(nbuf
), "%s[%s@%s]", target_p
->name
,
1032 target_p
->username
, target_p
->sockhost
);
1036 snprintf(nbuf
, sizeof(nbuf
), "%s[%s@%s]", target_p
->name
,
1037 target_p
->username
, target_p
->host
);
1043 return target_p
->name
;
1046 /* is_remote_connect - Returns whether a server was /connect'ed by a remote
1047 * oper (send notices netwide) */
1049 is_remote_connect(struct Client
*client_p
)
1051 struct Client
*oper
;
1053 if (client_p
->serv
== NULL
)
1055 oper
= find_named_person(client_p
->serv
->by
);
1056 return oper
!= NULL
&& IsOper(oper
) && !MyConnect(oper
);
1060 free_exited_clients(void *unused
)
1062 rb_dlink_node
*ptr
, *next
;
1063 struct Client
*target_p
;
1065 RB_DLINK_FOREACH_SAFE(ptr
, next
, dead_list
.head
)
1067 target_p
= ptr
->data
;
1069 #ifdef DEBUG_EXITED_CLIENTS
1071 struct abort_client
*abt
;
1072 rb_dlink_node
*aptr
;
1075 RB_DLINK_FOREACH(aptr
, abort_list
.head
)
1078 if(abt
->client
== target_p
)
1081 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1082 "On abort_list: %s stat: %u flags: %llu handler: %c",
1083 target_p
->name
, (unsigned int) target_p
->status
,
1084 (unsigned long long)target_p
->flags
, target_p
->handler
);
1085 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1086 "Please report this to the charybdis developers!");
1093 rb_dlinkDestroy(ptr
, &dead_list
);
1099 if(ptr
->data
== NULL
)
1101 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1102 "Warning: null client on dead_list!");
1103 rb_dlinkDestroy(ptr
, &dead_list
);
1106 release_client_state(target_p
);
1107 free_client(target_p
);
1108 rb_dlinkDestroy(ptr
, &dead_list
);
1111 #ifdef DEBUG_EXITED_CLIENTS
1112 RB_DLINK_FOREACH_SAFE(ptr
, next
, dead_remote_list
.head
)
1114 target_p
= ptr
->data
;
1116 if(ptr
->data
== NULL
)
1118 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1119 "Warning: null client on dead_list!");
1120 rb_dlinkDestroy(ptr
, &dead_list
);
1123 release_client_state(target_p
);
1124 free_client(target_p
);
1125 rb_dlinkDestroy(ptr
, &dead_remote_list
);
1132 ** Remove all clients that depend on source_p; assumes all (S)QUITs have
1133 ** already been sent. we make sure to exit a server's dependent clients
1134 ** and servers before the server itself; exit_one_client takes care of
1135 ** actually removing things off llists. tweaked from +CSr31 -orabidoo
1138 * added sanity test code.... source_p->serv might be NULL...
1141 recurse_remove_clients(struct Client
*source_p
, const char *comment
)
1143 struct Client
*target_p
;
1144 rb_dlink_node
*ptr
, *ptr_next
;
1149 if(source_p
->serv
== NULL
) /* oooops. uh this is actually a major bug */
1152 /* this is very ugly, but it saves cpu :P */
1153 if(ConfigFileEntry
.nick_delay
> 0)
1155 RB_DLINK_FOREACH_SAFE(ptr
, ptr_next
, source_p
->serv
->users
.head
)
1157 target_p
= ptr
->data
;
1158 target_p
->flags
|= FLAGS_KILLED
;
1159 add_nd_entry(target_p
->name
);
1161 if(!IsDead(target_p
) && !IsClosing(target_p
))
1162 exit_remote_client(NULL
, target_p
, &me
, comment
);
1167 RB_DLINK_FOREACH_SAFE(ptr
, ptr_next
, source_p
->serv
->users
.head
)
1169 target_p
= ptr
->data
;
1170 target_p
->flags
|= FLAGS_KILLED
;
1172 if(!IsDead(target_p
) && !IsClosing(target_p
))
1173 exit_remote_client(NULL
, target_p
, &me
, comment
);
1177 RB_DLINK_FOREACH_SAFE(ptr
, ptr_next
, source_p
->serv
->servers
.head
)
1179 target_p
= ptr
->data
;
1180 recurse_remove_clients(target_p
, comment
);
1181 qs_server(NULL
, target_p
, &me
, comment
);
1186 ** Remove *everything* that depends on source_p, from all lists, and sending
1187 ** all necessary SQUITs. source_p itself is still on the lists,
1188 ** and its SQUITs have been sent except for the upstream one -orabidoo
1191 remove_dependents(struct Client
*client_p
,
1192 struct Client
*source_p
,
1193 struct Client
*from
, const char *comment
, const char *comment1
)
1196 rb_dlink_node
*ptr
, *next
;
1198 RB_DLINK_FOREACH_SAFE(ptr
, next
, serv_list
.head
)
1202 if(IsMe(to
) || to
== source_p
->from
|| to
== client_p
)
1205 sendto_one(to
, "SQUIT %s :%s", get_id(source_p
, to
), comment
);
1208 recurse_remove_clients(source_p
, comment1
);
1212 exit_aborted_clients(void *unused
)
1214 struct abort_client
*abt
;
1215 rb_dlink_node
*ptr
, *next
;
1216 RB_DLINK_FOREACH_SAFE(ptr
, next
, abort_list
.head
)
1220 #ifdef DEBUG_EXITED_CLIENTS
1222 if(rb_dlinkFind(abt
->client
, &dead_list
))
1225 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1226 "On dead_list: %s stat: %u flags: %llu handler: %c",
1227 abt
->client
->name
, (unsigned int) abt
->client
->status
,
1228 (unsigned long long)abt
->client
->flags
, abt
->client
->handler
);
1229 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1230 "Please report this to the charybdis developers!");
1236 s_assert(*((unsigned long*)abt
->client
) != 0xdeadbeef); /* This is lame but its a debug thing */
1237 rb_dlinkDelete(ptr
, &abort_list
);
1239 if(IsAnyServer(abt
->client
))
1240 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1241 "Closing link to %s: %s",
1242 abt
->client
->name
, abt
->notice
);
1244 /* its no longer on abort list - we *must* remove
1245 * FLAGS_CLOSING otherwise exit_client() will not run --fl
1247 abt
->client
->flags
&= ~FLAGS_CLOSING
;
1248 exit_client(abt
->client
, abt
->client
, &me
, abt
->notice
);
1255 * dead_link - Adds client to a list of clients that need an exit_client()
1258 dead_link(struct Client
*client_p
, int sendqex
)
1260 struct abort_client
*abt
;
1262 s_assert(!IsMe(client_p
));
1263 if(IsDead(client_p
) || IsClosing(client_p
) || IsMe(client_p
))
1266 abt
= (struct abort_client
*) rb_malloc(sizeof(struct abort_client
));
1269 rb_strlcpy(abt
->notice
, "Max SendQ exceeded", sizeof(abt
->notice
));
1271 snprintf(abt
->notice
, sizeof(abt
->notice
), "Write error: %s", strerror(errno
));
1273 abt
->client
= client_p
;
1274 SetIOError(client_p
);
1276 SetClosing(client_p
);
1277 rb_dlinkAdd(abt
, &abt
->node
, &abort_list
);
1281 /* This does the remove of the user from channels..local or remote */
1283 exit_generic_client(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1284 const char *comment
)
1286 rb_dlink_node
*ptr
, *next_ptr
;
1288 if(IsOper(source_p
))
1289 rb_dlinkFindDestroy(source_p
, &oper_list
);
1291 sendto_common_channels_local(source_p
, NOCAPS
, NOCAPS
, ":%s!%s@%s QUIT :%s",
1293 source_p
->username
, source_p
->host
, comment
);
1295 remove_user_from_channels(source_p
);
1297 /* Should not be in any channels now */
1298 s_assert(source_p
->user
->channel
.head
== NULL
);
1300 /* Clean up invitefield */
1301 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, source_p
->user
->invited
.head
)
1303 del_invite(ptr
->data
, source_p
);
1306 /* Clean up allow lists */
1307 del_all_accepts(source_p
);
1309 whowas_add_history(source_p
, 0);
1310 whowas_off_history(source_p
);
1312 monitor_signoff(source_p
);
1314 if(has_id(source_p
))
1315 del_from_id_hash(source_p
->id
, source_p
);
1317 del_from_hostname_hash(source_p
->orighost
, source_p
);
1318 del_from_client_hash(source_p
->name
, source_p
);
1319 remove_client_from_list(source_p
);
1323 * Assumes IsPerson(source_p) && !MyConnect(source_p)
1327 exit_remote_client(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1328 const char *comment
)
1330 exit_generic_client(client_p
, source_p
, from
, comment
);
1332 if(source_p
->servptr
&& source_p
->servptr
->serv
)
1334 rb_dlinkDelete(&source_p
->lnode
, &source_p
->servptr
->serv
->users
);
1337 if((source_p
->flags
& FLAGS_KILLED
) == 0)
1339 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
,
1340 ":%s QUIT :%s", use_id(source_p
), comment
);
1344 #ifdef DEBUG_EXITED_CLIENTS
1345 rb_dlinkAddAlloc(source_p
, &dead_remote_list
);
1347 rb_dlinkAddAlloc(source_p
, &dead_list
);
1349 return(CLIENT_EXITED
);
1353 * This assumes IsUnknown(source_p) == true and MyConnect(source_p) == true
1357 exit_unknown_client(struct Client
*client_p
, /* The local client originating the
1358 * exit or NULL, if this exit is
1359 * generated by this server for
1361 * This will not get any of the
1362 * generated messages. */
1363 struct Client
*source_p
, /* Client exiting */
1364 struct Client
*from
, /* Client firing off this Exit,
1366 const char *comment
)
1368 authd_abort_client(source_p
);
1369 rb_dlinkDelete(&source_p
->localClient
->tnode
, &unknown_list
);
1371 if(!IsIOError(source_p
))
1372 sendto_one(source_p
, "ERROR :Closing Link: %s (%s)",
1373 source_p
->user
!= NULL
? source_p
->host
: "127.0.0.1",
1376 close_connection(source_p
);
1378 if(has_id(source_p
))
1379 del_from_id_hash(source_p
->id
, source_p
);
1381 del_from_hostname_hash(source_p
->host
, source_p
);
1382 del_from_client_hash(source_p
->name
, source_p
);
1383 remove_client_from_list(source_p
);
1385 rb_dlinkAddAlloc(source_p
, &dead_list
);
1387 /* Note that we don't need to add unknowns to the dead_list */
1388 return(CLIENT_EXITED
);
1392 exit_remote_server(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1393 const char *comment
)
1395 static char comment1
[(HOSTLEN
*2)+2];
1396 static char newcomment
[BUFSIZE
];
1397 struct Client
*target_p
;
1399 if(ConfigServerHide
.flatten_links
)
1400 strcpy(comment1
, "*.net *.split");
1403 strcpy(comment1
, source_p
->servptr
->name
);
1404 strcat(comment1
, " ");
1405 strcat(comment1
, source_p
->name
);
1408 snprintf(newcomment
, sizeof(newcomment
), "by %s: %s",
1409 from
->name
, comment
);
1411 if(source_p
->serv
!= NULL
)
1412 remove_dependents(client_p
, source_p
, from
, IsPerson(from
) ? newcomment
: comment
, comment1
);
1414 if(source_p
->servptr
&& source_p
->servptr
->serv
)
1415 rb_dlinkDelete(&source_p
->lnode
, &source_p
->servptr
->serv
->servers
);
1419 rb_dlinkFindDestroy(source_p
, &global_serv_list
);
1420 target_p
= source_p
->from
;
1422 if(target_p
!= NULL
&& IsServer(target_p
) && target_p
!= client_p
&&
1423 !IsMe(target_p
) && (source_p
->flags
& FLAGS_KILLED
) == 0)
1425 sendto_one(target_p
, ":%s SQUIT %s :%s",
1426 get_id(from
, target_p
), get_id(source_p
, target_p
),
1430 if(has_id(source_p
))
1431 del_from_id_hash(source_p
->id
, source_p
);
1433 del_from_client_hash(source_p
->name
, source_p
);
1434 remove_client_from_list(source_p
);
1435 scache_split(source_p
->serv
->nameinfo
);
1438 #ifdef DEBUG_EXITED_CLIENTS
1439 rb_dlinkAddAlloc(source_p
, &dead_remote_list
);
1441 rb_dlinkAddAlloc(source_p
, &dead_list
);
1447 qs_server(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1448 const char *comment
)
1450 if(source_p
->servptr
&& source_p
->servptr
->serv
)
1451 rb_dlinkDelete(&source_p
->lnode
, &source_p
->servptr
->serv
->servers
);
1455 rb_dlinkFindDestroy(source_p
, &global_serv_list
);
1457 if(has_id(source_p
))
1458 del_from_id_hash(source_p
->id
, source_p
);
1460 del_from_client_hash(source_p
->name
, source_p
);
1461 remove_client_from_list(source_p
);
1462 scache_split(source_p
->serv
->nameinfo
);
1465 rb_dlinkAddAlloc(source_p
, &dead_list
);
1470 exit_local_server(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1471 const char *comment
)
1473 static char comment1
[(HOSTLEN
*2)+2];
1474 static char newcomment
[BUFSIZE
];
1475 unsigned int sendk
, recvk
;
1477 rb_dlinkDelete(&source_p
->localClient
->tnode
, &serv_list
);
1478 rb_dlinkFindDestroy(source_p
, &global_serv_list
);
1480 sendk
= source_p
->localClient
->sendK
;
1481 recvk
= source_p
->localClient
->receiveK
;
1483 /* Always show source here, so the server notices show
1484 * which side initiated the split -- jilles
1486 snprintf(newcomment
, sizeof(newcomment
), "by %s: %s",
1487 from
== source_p
? me
.name
: from
->name
, comment
);
1488 if (!IsIOError(source_p
))
1489 sendto_one(source_p
, "SQUIT %s :%s", use_id(source_p
),
1491 if(client_p
!= NULL
&& source_p
!= client_p
&& !IsIOError(source_p
))
1493 sendto_one(source_p
, "ERROR :Closing Link: 127.0.0.1 %s (%s)",
1494 source_p
->name
, comment
);
1497 if(source_p
->servptr
&& source_p
->servptr
->serv
)
1498 rb_dlinkDelete(&source_p
->lnode
, &source_p
->servptr
->serv
->servers
);
1503 close_connection(source_p
);
1505 if(ConfigServerHide
.flatten_links
)
1506 strcpy(comment1
, "*.net *.split");
1509 strcpy(comment1
, source_p
->servptr
->name
);
1510 strcat(comment1
, " ");
1511 strcat(comment1
, source_p
->name
);
1514 if(source_p
->serv
!= NULL
)
1515 remove_dependents(client_p
, source_p
, from
, IsPerson(from
) ? newcomment
: comment
, comment1
);
1517 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s was connected"
1518 " for %ld seconds. %d/%d sendK/recvK.",
1519 source_p
->name
, (long) rb_current_time() - source_p
->localClient
->firsttime
, sendk
, recvk
);
1521 ilog(L_SERVER
, "%s was connected for %ld seconds. %d/%d sendK/recvK.",
1522 source_p
->name
, (long) rb_current_time() - source_p
->localClient
->firsttime
, sendk
, recvk
);
1524 if(has_id(source_p
))
1525 del_from_id_hash(source_p
->id
, source_p
);
1527 del_from_client_hash(source_p
->name
, source_p
);
1528 remove_client_from_list(source_p
);
1529 scache_split(source_p
->serv
->nameinfo
);
1532 rb_dlinkAddAlloc(source_p
, &dead_list
);
1538 * This assumes IsPerson(source_p) == true && MyConnect(source_p) == true
1542 exit_local_client(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1543 const char *comment
)
1545 unsigned long on_for
;
1548 exit_generic_client(client_p
, source_p
, from
, comment
);
1549 clear_monitor(source_p
);
1551 s_assert(IsPerson(source_p
));
1552 rb_dlinkDelete(&source_p
->localClient
->tnode
, &lclient_list
);
1553 rb_dlinkDelete(&source_p
->lnode
, &me
.serv
->users
);
1555 if(IsOper(source_p
))
1556 rb_dlinkFindDestroy(source_p
, &local_oper_list
);
1558 sendto_realops_snomask(SNO_CCONN
, L_ALL
,
1559 "Client exiting: %s (%s@%s) [%s] [%s]",
1561 source_p
->username
, source_p
->host
, comment
,
1562 show_ip(NULL
, source_p
) ? source_p
->sockhost
: "255.255.255.255");
1564 sendto_realops_snomask(SNO_CCONNEXT
, L_ALL
,
1565 "CLIEXIT %s %s %s %s 0 %s",
1566 source_p
->name
, source_p
->username
, source_p
->host
,
1567 show_ip(NULL
, source_p
) ? source_p
->sockhost
: "255.255.255.255",
1570 on_for
= rb_current_time() - source_p
->localClient
->firsttime
;
1572 ilog(L_USER
, "%s (%3lu:%02lu:%02lu): %s!%s@%s %s %d/%d",
1573 rb_ctime(rb_current_time(), tbuf
, sizeof(tbuf
)), on_for
/ 3600,
1574 (on_for
% 3600) / 60, on_for
% 60,
1575 source_p
->name
, source_p
->username
, source_p
->host
,
1577 source_p
->localClient
->sendK
, source_p
->localClient
->receiveK
);
1579 sendto_one(source_p
, "ERROR :Closing Link: %s (%s)", source_p
->host
, comment
);
1580 close_connection(source_p
);
1582 if((source_p
->flags
& FLAGS_KILLED
) == 0)
1584 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
,
1585 ":%s QUIT :%s", use_id(source_p
), comment
);
1589 rb_dlinkAddAlloc(source_p
, &dead_list
);
1590 return(CLIENT_EXITED
);
1595 ** exit_client - This is old "m_bye". Name changed, because this is not a
1596 ** protocol function, but a general server utility function.
1598 ** This function exits a client of *any* type (user, server, etc)
1599 ** from this server. Also, this generates all necessary prototol
1600 ** messages that this exit may cause.
1602 ** 1) If the client is a local client, then this implicitly
1603 ** exits all other clients depending on this connection (e.g.
1604 ** remote clients having 'from'-field that points to this.
1606 ** 2) If the client is a remote client, then only this is exited.
1608 ** For convenience, this function returns a suitable value for
1609 ** m_function return value:
1611 ** CLIENT_EXITED if (client_p == source_p)
1612 ** 0 if (client_p != source_p)
1615 exit_client(struct Client
*client_p
, /* The local client originating the
1616 * exit or NULL, if this exit is
1617 * generated by this server for
1619 * This will not get any of the
1620 * generated messages. */
1621 struct Client
*source_p
, /* Client exiting */
1622 struct Client
*from
, /* Client firing off this Exit,
1624 const char *comment
/* Reason for the exit */
1627 hook_data_client_exit hdata
;
1628 if(IsClosing(source_p
))
1631 /* note, this HAS to be here, when we exit a client we attempt to
1632 * send them data, if this generates a write error we must *not* add
1633 * them to the abort list --fl
1635 SetClosing(source_p
);
1637 hdata
.local_link
= client_p
;
1638 hdata
.target
= source_p
;
1640 hdata
.comment
= comment
;
1641 call_hook(h_client_exit
, &hdata
);
1643 if(MyConnect(source_p
))
1645 /* Local clients of various types */
1646 if(IsPerson(source_p
))
1647 return exit_local_client(client_p
, source_p
, from
, comment
);
1648 else if(IsServer(source_p
))
1649 return exit_local_server(client_p
, source_p
, from
, comment
);
1650 /* IsUnknown || IsConnecting || IsHandShake */
1651 else if(!IsReject(source_p
))
1652 return exit_unknown_client(client_p
, source_p
, from
, comment
);
1657 if(IsPerson(source_p
))
1658 return exit_remote_client(client_p
, source_p
, from
, comment
);
1659 else if(IsServer(source_p
))
1660 return exit_remote_server(client_p
, source_p
, from
, comment
);
1667 * Count up local client memory
1670 /* XXX one common Client list now */
1672 count_local_client_memory(size_t * count
, size_t * local_client_memory_used
)
1675 rb_bh_usage(lclient_heap
, count
, NULL
, &lusage
, NULL
);
1676 *local_client_memory_used
= lusage
+ (*count
* (sizeof(void *) + sizeof(struct Client
)));
1680 * Count up remote client memory
1683 count_remote_client_memory(size_t * count
, size_t * remote_client_memory_used
)
1685 size_t lcount
, rcount
;
1686 rb_bh_usage(lclient_heap
, &lcount
, NULL
, NULL
, NULL
);
1687 rb_bh_usage(client_heap
, &rcount
, NULL
, NULL
, NULL
);
1688 *count
= rcount
- lcount
;
1689 *remote_client_memory_used
= *count
* (sizeof(void *) + sizeof(struct Client
));
1694 * accept processing, this adds a form of "caller ID" to ircd
1696 * If a client puts themselves into "caller ID only" mode,
1697 * only clients that match a client pointer they have put on
1698 * the accept list will be allowed to message them.
1700 * [ source.on_allow_list ] -> [ target1 ] -> [ target2 ]
1702 * [target.allow_list] -> [ source1 ] -> [source2 ]
1704 * i.e. a target will have a link list of source pointers it will allow
1705 * each source client then has a back pointer pointing back
1706 * to the client that has it on its accept list.
1707 * This allows for exit_one_client to remove these now bogus entries
1708 * from any client having an accept on them.
1713 * inputs - pointer to exiting client
1715 * side effects - Walk through given clients allow_list and on_allow_list
1716 * remove all references to this client
1719 del_all_accepts(struct Client
*client_p
)
1722 rb_dlink_node
*next_ptr
;
1723 struct Client
*target_p
;
1725 if(MyClient(client_p
) && client_p
->localClient
->allow_list
.head
)
1727 /* clear this clients accept list, and remove them from
1728 * everyones on_accept_list
1730 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, client_p
->localClient
->allow_list
.head
)
1732 target_p
= ptr
->data
;
1733 rb_dlinkFindDestroy(client_p
, &target_p
->on_allow_list
);
1734 rb_dlinkDestroy(ptr
, &client_p
->localClient
->allow_list
);
1738 /* remove this client from everyones accept list */
1739 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, client_p
->on_allow_list
.head
)
1741 target_p
= ptr
->data
;
1742 rb_dlinkFindDestroy(client_p
, &target_p
->localClient
->allow_list
);
1743 rb_dlinkDestroy(ptr
, &client_p
->on_allow_list
);
1748 * show_ip() - asks if the true IP should be shown when source is
1749 * asking for info about target
1751 * Inputs - source_p who is asking
1752 * - target_p who do we want the info on
1753 * Output - returns 1 if clear IP can be shown, otherwise 0
1754 * Side Effects - none
1758 show_ip(struct Client
*source_p
, struct Client
*target_p
)
1760 if(IsAnyServer(target_p
))
1764 else if(IsIPSpoof(target_p
))
1766 /* source == NULL indicates message is being sent
1769 if(!ConfigFileEntry
.hide_spoof_ips
&&
1770 (source_p
== NULL
|| MyOper(source_p
)))
1774 else if(IsDynSpoof(target_p
) && (source_p
!= NULL
&& !IsOper(source_p
)))
1781 show_ip_conf(struct ConfItem
*aconf
, struct Client
*source_p
)
1783 if(IsConfDoSpoofIp(aconf
))
1785 if(!ConfigFileEntry
.hide_spoof_ips
&& MyOper(source_p
))
1795 show_ip_whowas(struct Whowas
*whowas
, struct Client
*source_p
)
1797 if(whowas
->flags
& WHOWAS_IP_SPOOFING
)
1798 if(ConfigFileEntry
.hide_spoof_ips
|| !MyOper(source_p
))
1800 if(whowas
->flags
& WHOWAS_DYNSPOOF
)
1801 if(!IsOper(source_p
))
1809 * inputs - pointer to client struct
1810 * output - pointer to struct User
1811 * side effects - add's an User information block to a client
1812 * if it was not previously allocated.
1815 make_user(struct Client
*client_p
)
1819 user
= client_p
->user
;
1822 user
= (struct User
*) rb_bh_alloc(user_heap
);
1824 client_p
->user
= user
;
1832 * inputs - pointer to client struct
1833 * output - pointer to server_t
1834 * side effects - add's an Server information block to a client
1835 * if it was not previously allocated.
1838 make_server(struct Client
*client_p
)
1840 struct Server
*serv
= client_p
->serv
;
1844 serv
= (struct Server
*) rb_malloc(sizeof(struct Server
));
1845 client_p
->serv
= serv
;
1847 return client_p
->serv
;
1853 * inputs - pointer to user struct
1854 * - pointer to client struct
1856 * side effects - Decrease user reference count by one and release block,
1857 * if count reaches 0
1860 free_user(struct User
*user
, struct Client
*client_p
)
1862 free_away(client_p
);
1864 if(--user
->refcnt
<= 0)
1867 rb_free((char *) user
->away
);
1871 if(user
->refcnt
< 0 || user
->invited
.head
|| user
->channel
.head
)
1873 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1874 "* %p user (%s!%s@%s) %p %p %p %lu %d *",
1876 client_p
? client_p
->
1883 rb_dlink_list_length(&user
->channel
),
1885 s_assert(!user
->refcnt
);
1886 s_assert(!user
->invited
.head
);
1887 s_assert(!user
->channel
.head
);
1890 rb_bh_free(user_heap
, user
);
1895 allocate_away(struct Client
*client_p
)
1897 if(client_p
->user
->away
== NULL
)
1898 client_p
->user
->away
= rb_bh_alloc(away_heap
);
1903 free_away(struct Client
*client_p
)
1905 if(client_p
->user
!= NULL
&& client_p
->user
->away
!= NULL
) {
1906 rb_bh_free(away_heap
, client_p
->user
->away
);
1907 client_p
->user
->away
= NULL
;
1916 for(i
= 0; i
< 3; i
++)
1917 current_uid
[i
] = me
.id
[i
];
1919 for(i
= 3; i
< 9; i
++)
1920 current_uid
[i
] = 'A';
1922 current_uid
[9] = '\0';
1929 static int flipped
= 0;
1933 for(i
= 8; i
> 3; i
--)
1935 if(current_uid
[i
] == 'Z')
1937 current_uid
[i
] = '0';
1940 else if(current_uid
[i
] != '9')
1946 current_uid
[i
] = 'A';
1949 /* if this next if() triggers, we're fucked. */
1950 if(current_uid
[3] == 'Z')
1952 current_uid
[i
] = 'A';
1958 /* if this happens..well, i'm not sure what to say, but lets handle it correctly */
1959 if(rb_unlikely(flipped
))
1961 /* this slows down uid generation a bit... */
1962 if(find_id(current_uid
) != NULL
)
1970 * Close the physical connection. This function must make
1971 * MyConnect(client_p) == FALSE, and set client_p->from == NULL.
1974 close_connection(struct Client
*client_p
)
1976 s_assert(client_p
!= NULL
);
1977 if(client_p
== NULL
)
1980 s_assert(MyConnect(client_p
));
1981 if(!MyConnect(client_p
))
1984 if(IsServer(client_p
))
1986 struct server_conf
*server_p
;
1988 ServerStats
.is_sv
++;
1989 ServerStats
.is_sbs
+= client_p
->localClient
->sendB
;
1990 ServerStats
.is_sbr
+= client_p
->localClient
->receiveB
;
1991 ServerStats
.is_sti
+= (unsigned long long)(rb_current_time() - client_p
->localClient
->firsttime
);
1994 * If the connection has been up for a long amount of time, schedule
1995 * a 'quick' reconnect, else reset the next-connect cycle.
1997 if((server_p
= find_server_conf(client_p
->name
)) != NULL
)
2000 * Reschedule a faster reconnect, if this was a automatically
2001 * connected configuration entry. (Note that if we have had
2002 * a rehash in between, the status has been changed to
2003 * CONF_ILLEGAL). But only do this if it was a "good" link.
2005 server_p
->hold
= time(NULL
);
2007 (server_p
->hold
- client_p
->localClient
->lasttime
>
2008 HANGONGOODLINK
) ? HANGONRETRYDELAY
: ConFreq(server_p
->class);
2012 else if(IsClient(client_p
))
2014 ServerStats
.is_cl
++;
2015 ServerStats
.is_cbs
+= client_p
->localClient
->sendB
;
2016 ServerStats
.is_cbr
+= client_p
->localClient
->receiveB
;
2017 ServerStats
.is_cti
+= (unsigned long long)(rb_current_time() - client_p
->localClient
->firsttime
);
2020 ServerStats
.is_ni
++;
2022 client_release_connids(client_p
);
2024 if(client_p
->localClient
->F
!= NULL
)
2026 /* attempt to flush any pending dbufs. Evil, but .. -- adrian */
2027 if(!IsIOError(client_p
))
2028 send_queued(client_p
);
2030 rb_close(client_p
->localClient
->F
);
2031 client_p
->localClient
->F
= NULL
;
2034 rb_linebuf_donebuf(&client_p
->localClient
->buf_sendq
);
2035 rb_linebuf_donebuf(&client_p
->localClient
->buf_recvq
);
2036 detach_conf(client_p
);
2038 /* XXX shouldnt really be done here. */
2039 detach_server_conf(client_p
);
2041 client_p
->from
= NULL
; /* ...this should catch them! >:) --msa */
2042 ClearMyConnect(client_p
);
2043 SetIOError(client_p
);
2049 error_exit_client(struct Client
*client_p
, int error
)
2052 * ...hmm, with non-blocking sockets we might get
2053 * here from quite valid reasons, although.. why
2054 * would select report "data available" when there
2055 * wasn't... so, this must be an error anyway... --msa
2056 * actually, EOF occurs when read() returns 0 and
2057 * in due course, select() returns that fd as ready
2058 * for reading even though it ends up being an EOF. -avalon
2061 int current_error
= rb_get_sockerr(client_p
->localClient
->F
);
2063 SetIOError(client_p
);
2065 if(IsServer(client_p
) || IsHandshake(client_p
))
2069 sendto_realops_snomask(SNO_GENERAL
, is_remote_connect(client_p
) && !IsServer(client_p
) ? L_NETWIDE
: L_ALL
,
2070 "Server %s closed the connection",
2073 ilog(L_SERVER
, "Server %s closed the connection",
2074 log_client_name(client_p
, SHOW_IP
));
2078 sendto_realops_snomask(SNO_GENERAL
, is_remote_connect(client_p
) && !IsServer(client_p
) ? L_NETWIDE
: L_ALL
,
2079 "Lost connection to %s: %s",
2080 client_p
->name
, strerror(current_error
));
2081 ilog(L_SERVER
, "Lost connection to %s: %s",
2082 log_client_name(client_p
, SHOW_IP
), strerror(current_error
));
2087 rb_strlcpy(errmsg
, "Remote host closed the connection", sizeof(errmsg
));
2089 snprintf(errmsg
, sizeof(errmsg
), "Read error: %s", strerror(current_error
));
2091 exit_client(client_p
, client_p
, &me
, errmsg
);