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 rb_free(client_p
->localClient
->cipher_string
);
319 if (IsCapable(client_p
, CAP_ZIP
))
320 ssld_decrement_clicount(client_p
->localClient
->z_ctl
);
322 rb_free(client_p
->localClient
->zipstats
);
324 if (client_p
->localClient
->ws_ctl
!= NULL
)
325 wsockd_decrement_clicount(client_p
->localClient
->ws_ctl
);
327 rb_bh_free(lclient_heap
, client_p
->localClient
);
328 client_p
->localClient
= NULL
;
332 free_client(struct Client
*client_p
)
334 s_assert(NULL
!= client_p
);
335 s_assert(&me
!= client_p
);
336 free_local_client(client_p
);
337 free_pre_client(client_p
);
338 rb_free(client_p
->certfp
);
339 rb_bh_free(client_heap
, client_p
);
343 * check_pings - go through the local client list and check activity
344 * kill off stuff that should die
346 * inputs - NOT USED (from event)
347 * output - next time_t when check_pings() should be called again
351 * A PING can be sent to clients as necessary.
353 * Client/Server ping outs are handled.
357 * Addon from adrian. We used to call this after nextping seconds,
358 * however I've changed it to run once a second. This is only for
359 * PING timeouts, not K/etc-line checks (thanks dianora!). Having it
360 * run once a second makes life a lot easier - when a new client connects
361 * and they need a ping in 4 seconds, if nextping was set to 20 seconds
362 * we end up waiting 20 seconds. This is stupid. :-)
363 * I will optimise (hah!) check_pings() once I've finished working on
364 * tidying up other network IO evilnesses.
369 check_pings(void *notused
)
371 check_pings_list(&lclient_list
);
372 check_pings_list(&serv_list
);
373 check_unknowns_list(&unknown_list
);
379 * inputs - pointer to list to check
384 check_pings_list(rb_dlink_list
* list
)
386 char scratch
[32]; /* way too generous but... */
387 struct Client
*client_p
; /* current local client_p being examined */
388 int ping
= 0; /* ping time value from client */
389 rb_dlink_node
*ptr
, *next_ptr
;
391 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, list
->head
)
393 client_p
= ptr
->data
;
395 if(!MyConnect(client_p
) || IsDead(client_p
))
398 ping
= get_client_ping(client_p
);
400 if(ping
< (rb_current_time() - client_p
->localClient
->lasttime
))
403 * If the client/server hasnt talked to us in 2*ping seconds
404 * and it has a ping time, then close its connection.
406 if(((rb_current_time() - client_p
->localClient
->lasttime
) >= (2 * ping
)
407 && (client_p
->flags
& FLAGS_PINGSENT
)))
409 if(IsServer(client_p
))
411 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
412 "No response from %s, closing link",
415 "No response from %s, closing link",
416 log_client_name(client_p
, HIDE_IP
));
418 (void) snprintf(scratch
, sizeof(scratch
),
419 "Ping timeout: %d seconds",
420 (int) (rb_current_time() - client_p
->localClient
->lasttime
));
422 exit_client(client_p
, client_p
, &me
, scratch
);
425 else if((client_p
->flags
& FLAGS_PINGSENT
) == 0)
428 * if we havent PINGed the connection and we havent
429 * heard from it in a while, PING it to make sure
432 client_p
->flags
|= FLAGS_PINGSENT
;
433 /* not nice but does the job */
434 client_p
->localClient
->lasttime
= rb_current_time() - ping
;
435 sendto_one(client_p
, "PING :%s", me
.name
);
444 * check_unknowns_list
446 * inputs - pointer to list of unknown clients
448 * side effects - unknown clients get marked for termination after n seconds
451 check_unknowns_list(rb_dlink_list
* list
)
453 rb_dlink_node
*ptr
, *next_ptr
;
454 struct Client
*client_p
;
457 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, list
->head
)
459 client_p
= ptr
->data
;
461 if(IsDead(client_p
) || IsClosing(client_p
))
464 /* Still querying with authd */
465 if(client_p
->preClient
!= NULL
&& client_p
->preClient
->auth
.cid
!= 0)
469 * Check UNKNOWN connections - if they have been in this state
470 * for > 30s, close them.
473 timeout
= IsAnyServer(client_p
) ? ConfigFileEntry
.connect_timeout
: 30;
474 if((rb_current_time() - client_p
->localClient
->firsttime
) > timeout
)
476 if(IsAnyServer(client_p
))
478 sendto_realops_snomask(SNO_GENERAL
, is_remote_connect(client_p
) ? L_NETWIDE
: L_ALL
,
479 "No response from %s, closing link",
482 "No response from %s, closing link",
483 log_client_name(client_p
, HIDE_IP
));
485 exit_client(client_p
, client_p
, &me
, "Connection timed out");
491 notify_banned_client(struct Client
*client_p
, struct ConfItem
*aconf
, int ban
)
493 static const char conn_closed
[] = "Connection closed";
494 static const char d_lined
[] = "D-lined";
495 static const char k_lined
[] = "K-lined";
496 const char *reason
= NULL
;
497 const char *exit_reason
= conn_closed
;
499 if(ConfigFileEntry
.kline_with_reason
)
501 reason
= get_user_ban_reason(aconf
);
502 exit_reason
= reason
;
506 reason
= aconf
->status
== D_LINED
? d_lined
: k_lined
;
509 if(ban
== D_LINED
&& !IsPerson(client_p
))
510 sendto_one(client_p
, "NOTICE DLINE :*** You have been D-lined");
512 sendto_one(client_p
, form_str(ERR_YOUREBANNEDCREEP
),
513 me
.name
, client_p
->name
, reason
);
515 exit_client(client_p
, client_p
, &me
,
516 EmptyString(ConfigFileEntry
.kline_reason
) ? exit_reason
:
517 ConfigFileEntry
.kline_reason
);
524 * side effects - Check all connections for a pending k/dline against the
525 * client, exit the client if found.
528 check_banned_lines(void)
535 /* check_klines_event()
539 * side effects - check_klines() is called, kline_queued unset
542 check_klines_event(void *unused
)
544 kline_queued
= false;
552 * side effects - all clients will be checked for klines
557 struct Client
*client_p
;
558 struct ConfItem
*aconf
;
560 rb_dlink_node
*next_ptr
;
562 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
564 client_p
= ptr
->data
;
566 if(IsMe(client_p
) || !IsPerson(client_p
))
569 if((aconf
= find_kline(client_p
)) != NULL
)
571 if(IsExemptKline(client_p
))
573 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
574 "KLINE over-ruled for %s, client is kline_exempt [%s@%s]",
575 get_client_name(client_p
, HIDE_IP
),
576 aconf
->user
, aconf
->host
);
580 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
581 "KLINE active for %s",
582 get_client_name(client_p
, HIDE_IP
));
584 notify_banned_client(client_p
, aconf
, K_LINED
);
594 * side effects - all clients will be checked for dlines
599 struct Client
*client_p
;
600 struct ConfItem
*aconf
;
602 rb_dlink_node
*next_ptr
;
604 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
606 client_p
= ptr
->data
;
611 if((aconf
= find_dline((struct sockaddr
*)&client_p
->localClient
->ip
, GET_SS_FAMILY(&client_p
->localClient
->ip
))) != NULL
)
613 if(aconf
->status
& CONF_EXEMPTDLINE
)
616 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
617 "DLINE active for %s",
618 get_client_name(client_p
, HIDE_IP
));
620 notify_banned_client(client_p
, aconf
, D_LINED
);
625 /* dlines need to be checked against unknowns too */
626 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, unknown_list
.head
)
628 client_p
= ptr
->data
;
630 if((aconf
= find_dline((struct sockaddr
*)&client_p
->localClient
->ip
, GET_SS_FAMILY(&client_p
->localClient
->ip
))) != NULL
)
632 if(aconf
->status
& CONF_EXEMPTDLINE
)
635 notify_banned_client(client_p
, aconf
, D_LINED
);
644 * side effects - all clients will be checked for xlines
649 struct Client
*client_p
;
650 struct ConfItem
*aconf
;
652 rb_dlink_node
*next_ptr
;
654 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
656 client_p
= ptr
->data
;
658 if(IsMe(client_p
) || !IsPerson(client_p
))
661 if((aconf
= find_xline(client_p
->info
, 1)) != NULL
)
663 if(IsExemptKline(client_p
))
665 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
666 "XLINE over-ruled for %s, client is kline_exempt [%s]",
667 get_client_name(client_p
, HIDE_IP
),
672 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "XLINE active for %s",
673 get_client_name(client_p
, HIDE_IP
));
675 (void) exit_client(client_p
, client_p
, &me
, "Bad user info");
683 * inputs - resv, reason, time
685 * side effects - all local clients matching resv will be FNC'd
688 resv_nick_fnc(const char *mask
, const char *reason
, int temp_time
)
690 struct Client
*client_p
, *target_p
;
692 rb_dlink_node
*next_ptr
;
694 char note
[NICKLEN
+10];
696 if (!ConfigFileEntry
.resv_fnc
)
699 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
701 client_p
= ptr
->data
;
703 if(IsMe(client_p
) || !IsPerson(client_p
) || IsExemptResv(client_p
))
706 /* Skip users that already have UID nicks. */
707 if(IsDigit(client_p
->name
[0]))
710 if(match_esc(mask
, client_p
->name
))
715 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
716 "RESV forced nick change for %s!%s@%s to %s; nick matched [%s] (%s)",
717 client_p
->name
, client_p
->username
, client_p
->host
, nick
, mask
, reason
);
719 sendto_realops_snomask(SNO_NCHANGE
, L_ALL
,
720 "Nick change: From %s to %s [%s@%s]",
721 client_p
->name
, nick
, client_p
->username
, client_p
->host
);
726 sendto_one_notice(client_p
,
727 ":*** Nick %s is temporarily unavailable on this server.",
732 sendto_one_notice(client_p
,
733 ":*** Nick %s is no longer available on this server.",
737 /* Do all of the nick-changing gymnastics. */
738 client_p
->tsinfo
= rb_current_time();
739 whowas_add_history(client_p
, 1);
741 monitor_signoff(client_p
);
743 invalidate_bancache_user(client_p
);
745 sendto_common_channels_local(client_p
, NOCAPS
, NOCAPS
, ":%s!%s@%s NICK :%s",
746 client_p
->name
, client_p
->username
, client_p
->host
, nick
);
747 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s NICK %s :%ld",
748 use_id(client_p
), nick
, (long) client_p
->tsinfo
);
750 del_from_client_hash(client_p
->name
, client_p
);
751 rb_strlcpy(client_p
->name
, nick
, sizeof(client_p
->name
));
752 add_to_client_hash(nick
, client_p
);
754 monitor_signon(client_p
);
756 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, client_p
->on_allow_list
.head
)
758 target_p
= ptr
->data
;
759 rb_dlinkFindDestroy(client_p
, &target_p
->localClient
->allow_list
);
760 rb_dlinkDestroy(ptr
, &client_p
->on_allow_list
);
763 snprintf(note
, sizeof(note
), "Nick: %s", nick
);
764 rb_note(client_p
->localClient
->F
, note
);
770 * update_client_exit_stats
772 * input - pointer to client
777 update_client_exit_stats(struct Client
*client_p
)
779 if(IsServer(client_p
))
781 sendto_realops_snomask(SNO_EXTERNAL
, L_ALL
,
782 "Server %s split from %s",
783 client_p
->name
, client_p
->servptr
->name
);
784 if(HasSentEob(client_p
))
787 else if(IsClient(client_p
))
792 if(IsInvisible(client_p
))
796 if(splitchecking
&& !splitmode
)
797 check_splitmode(NULL
);
801 * release_client_state
803 * input - pointer to client to release
808 release_client_state(struct Client
*client_p
)
810 if(client_p
->user
!= NULL
)
812 free_user(client_p
->user
, client_p
); /* try this here */
816 if(client_p
->serv
->user
!= NULL
)
817 free_user(client_p
->serv
->user
, client_p
);
818 if(client_p
->serv
->fullcaps
)
819 rb_free(client_p
->serv
->fullcaps
);
820 rb_free(client_p
->serv
);
825 * remove_client_from_list
826 * inputs - point to client to remove
828 * side effects - taken the code from ExitOneClient() for this
829 * and placed it here. - avalon
832 remove_client_from_list(struct Client
*client_p
)
834 s_assert(NULL
!= client_p
);
839 /* A client made with make_client()
840 * is on the unknown_list until removed.
841 * If it =does= happen to exit before its removed from that list
842 * and its =not= on the global_client_list, it will core here.
843 * short circuit that case now -db
845 if(client_p
->node
.prev
== NULL
&& client_p
->node
.next
== NULL
)
848 rb_dlinkDelete(&client_p
->node
, &global_client_list
);
850 update_client_exit_stats(client_p
);
856 * input - nickname to check, flag for nick from local client
857 * output - 0 if erroneous, else 1
861 clean_nick(const char *nick
, int loc_client
)
865 /* nicks cant start with a digit or -, and must have a length */
866 if(*nick
== '-' || *nick
== '\0')
869 if(loc_client
&& IsDigit(*nick
))
875 if(!IsNickChar(*nick
))
880 if(len
>= NICKLEN
&& (unsigned int)len
>= ConfigFileEntry
.nicklen
)
887 * find_person - find person by (nick)name.
888 * inputs - pointer to name
889 * output - return client pointer
893 find_person(const char *name
)
895 struct Client
*c2ptr
;
897 c2ptr
= find_client(name
);
899 if(c2ptr
&& IsPerson(c2ptr
))
905 find_named_person(const char *name
)
907 struct Client
*c2ptr
;
909 c2ptr
= find_named_client(name
);
911 if(c2ptr
&& IsPerson(c2ptr
))
918 * find_chasing - find the client structure for a nick name (user)
919 * using history mechanism if necessary. If the client is not found,
920 * an error message (NO SUCH NICK) is generated. If the client was found
921 * through the history, chasing will be 1 and otherwise 0.
924 find_chasing(struct Client
*source_p
, const char *user
, int *chasing
)
928 if(MyClient(source_p
))
929 who
= find_named_person(user
);
931 who
= find_person(user
);
936 if(who
|| IsDigit(*user
))
939 if(!(who
= whowas_get_history(user
, (long) KILLCHASETIMELIMIT
)))
941 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
942 form_str(ERR_NOSUCHNICK
), user
);
951 * get_client_name - Return the name of the client
952 * for various tracking and
953 * admin purposes. The main purpose of this function is to
954 * return the "socket host" name of the client, if that
955 * differs from the advertised name (other than case).
956 * But, this can be used to any client structure.
959 * Watch out the allocation of "nbuf", if either source_p->name
960 * or source_p->sockhost gets changed into pointers instead of
961 * directly allocated within the structure...
964 * Function return either a pointer to the structure (source_p) or
965 * to internal buffer (nbuf). *NEVER* use the returned pointer
966 * to modify what it points!!!
970 get_client_name(struct Client
*client
, int showip
)
972 static char nbuf
[HOSTLEN
* 2 + USERLEN
+ 5];
974 s_assert(NULL
!= client
);
978 if(MyConnect(client
))
980 if(!irccmp(client
->name
, client
->host
))
983 if(ConfigFileEntry
.hide_spoof_ips
&&
984 showip
== SHOW_IP
&& IsIPSpoof(client
))
986 if(IsAnyServer(client
))
989 /* And finally, let's get the host information, ip or name */
993 snprintf(nbuf
, sizeof(nbuf
), "%s[%s@%s]",
994 client
->name
, client
->username
,
998 snprintf(nbuf
, sizeof(nbuf
), "%s[%s@255.255.255.255]",
999 client
->name
, client
->username
);
1002 snprintf(nbuf
, sizeof(nbuf
), "%s[%s@%s]",
1003 client
->name
, client
->username
, client
->host
);
1008 /* As pointed out by Adel Mezibra
1009 * Neph|l|m@EFnet. Was missing a return here.
1011 return client
->name
;
1014 /* log_client_name()
1016 * This version is the same as get_client_name, but doesnt contain the
1017 * code that will hide IPs always. This should be used for logfiles.
1020 log_client_name(struct Client
*target_p
, int showip
)
1022 static char nbuf
[HOSTLEN
* 2 + USERLEN
+ 5];
1024 if(target_p
== NULL
)
1027 if(MyConnect(target_p
))
1029 if(irccmp(target_p
->name
, target_p
->host
) == 0)
1030 return target_p
->name
;
1035 snprintf(nbuf
, sizeof(nbuf
), "%s[%s@%s]", target_p
->name
,
1036 target_p
->username
, target_p
->sockhost
);
1040 snprintf(nbuf
, sizeof(nbuf
), "%s[%s@%s]", target_p
->name
,
1041 target_p
->username
, target_p
->host
);
1047 return target_p
->name
;
1050 /* is_remote_connect - Returns whether a server was /connect'ed by a remote
1051 * oper (send notices netwide) */
1053 is_remote_connect(struct Client
*client_p
)
1055 struct Client
*oper
;
1057 if (client_p
->serv
== NULL
)
1059 oper
= find_named_person(client_p
->serv
->by
);
1060 return oper
!= NULL
&& IsOper(oper
) && !MyConnect(oper
);
1064 free_exited_clients(void *unused
)
1066 rb_dlink_node
*ptr
, *next
;
1067 struct Client
*target_p
;
1069 RB_DLINK_FOREACH_SAFE(ptr
, next
, dead_list
.head
)
1071 target_p
= ptr
->data
;
1073 #ifdef DEBUG_EXITED_CLIENTS
1075 struct abort_client
*abt
;
1076 rb_dlink_node
*aptr
;
1079 RB_DLINK_FOREACH(aptr
, abort_list
.head
)
1082 if(abt
->client
== target_p
)
1085 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1086 "On abort_list: %s stat: %u flags: %llu handler: %c",
1087 target_p
->name
, (unsigned int) target_p
->status
,
1088 (unsigned long long)target_p
->flags
, target_p
->handler
);
1089 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1090 "Please report this to the charybdis developers!");
1097 rb_dlinkDestroy(ptr
, &dead_list
);
1103 if(ptr
->data
== NULL
)
1105 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1106 "Warning: null client on dead_list!");
1107 rb_dlinkDestroy(ptr
, &dead_list
);
1110 release_client_state(target_p
);
1111 free_client(target_p
);
1112 rb_dlinkDestroy(ptr
, &dead_list
);
1115 #ifdef DEBUG_EXITED_CLIENTS
1116 RB_DLINK_FOREACH_SAFE(ptr
, next
, dead_remote_list
.head
)
1118 target_p
= ptr
->data
;
1120 if(ptr
->data
== NULL
)
1122 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1123 "Warning: null client on dead_list!");
1124 rb_dlinkDestroy(ptr
, &dead_list
);
1127 release_client_state(target_p
);
1128 free_client(target_p
);
1129 rb_dlinkDestroy(ptr
, &dead_remote_list
);
1136 ** Remove all clients that depend on source_p; assumes all (S)QUITs have
1137 ** already been sent. we make sure to exit a server's dependent clients
1138 ** and servers before the server itself; exit_one_client takes care of
1139 ** actually removing things off llists. tweaked from +CSr31 -orabidoo
1142 * added sanity test code.... source_p->serv might be NULL...
1145 recurse_remove_clients(struct Client
*source_p
, const char *comment
)
1147 struct Client
*target_p
;
1148 rb_dlink_node
*ptr
, *ptr_next
;
1153 if(source_p
->serv
== NULL
) /* oooops. uh this is actually a major bug */
1156 /* this is very ugly, but it saves cpu :P */
1157 if(ConfigFileEntry
.nick_delay
> 0)
1159 RB_DLINK_FOREACH_SAFE(ptr
, ptr_next
, source_p
->serv
->users
.head
)
1161 target_p
= ptr
->data
;
1162 target_p
->flags
|= FLAGS_KILLED
;
1163 add_nd_entry(target_p
->name
);
1165 if(!IsDead(target_p
) && !IsClosing(target_p
))
1166 exit_remote_client(NULL
, target_p
, &me
, comment
);
1171 RB_DLINK_FOREACH_SAFE(ptr
, ptr_next
, source_p
->serv
->users
.head
)
1173 target_p
= ptr
->data
;
1174 target_p
->flags
|= FLAGS_KILLED
;
1176 if(!IsDead(target_p
) && !IsClosing(target_p
))
1177 exit_remote_client(NULL
, target_p
, &me
, comment
);
1181 RB_DLINK_FOREACH_SAFE(ptr
, ptr_next
, source_p
->serv
->servers
.head
)
1183 target_p
= ptr
->data
;
1184 recurse_remove_clients(target_p
, comment
);
1185 qs_server(NULL
, target_p
, &me
, comment
);
1190 ** Remove *everything* that depends on source_p, from all lists, and sending
1191 ** all necessary SQUITs. source_p itself is still on the lists,
1192 ** and its SQUITs have been sent except for the upstream one -orabidoo
1195 remove_dependents(struct Client
*client_p
,
1196 struct Client
*source_p
,
1197 struct Client
*from
, const char *comment
, const char *comment1
)
1200 rb_dlink_node
*ptr
, *next
;
1202 RB_DLINK_FOREACH_SAFE(ptr
, next
, serv_list
.head
)
1206 if(IsMe(to
) || to
== source_p
->from
|| to
== client_p
)
1209 sendto_one(to
, "SQUIT %s :%s", get_id(source_p
, to
), comment
);
1212 recurse_remove_clients(source_p
, comment1
);
1216 exit_aborted_clients(void *unused
)
1218 struct abort_client
*abt
;
1219 rb_dlink_node
*ptr
, *next
;
1220 RB_DLINK_FOREACH_SAFE(ptr
, next
, abort_list
.head
)
1224 #ifdef DEBUG_EXITED_CLIENTS
1226 if(rb_dlinkFind(abt
->client
, &dead_list
))
1229 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1230 "On dead_list: %s stat: %u flags: %llu handler: %c",
1231 abt
->client
->name
, (unsigned int) abt
->client
->status
,
1232 (unsigned long long)abt
->client
->flags
, abt
->client
->handler
);
1233 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1234 "Please report this to the charybdis developers!");
1240 s_assert(*((unsigned long*)abt
->client
) != 0xdeadbeef); /* This is lame but its a debug thing */
1241 rb_dlinkDelete(ptr
, &abort_list
);
1243 if(IsAnyServer(abt
->client
))
1244 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1245 "Closing link to %s: %s",
1246 abt
->client
->name
, abt
->notice
);
1248 /* its no longer on abort list - we *must* remove
1249 * FLAGS_CLOSING otherwise exit_client() will not run --fl
1251 abt
->client
->flags
&= ~FLAGS_CLOSING
;
1252 exit_client(abt
->client
, abt
->client
, &me
, abt
->notice
);
1259 * dead_link - Adds client to a list of clients that need an exit_client()
1262 dead_link(struct Client
*client_p
, int sendqex
)
1264 struct abort_client
*abt
;
1266 s_assert(!IsMe(client_p
));
1267 if(IsDead(client_p
) || IsClosing(client_p
) || IsMe(client_p
))
1270 abt
= (struct abort_client
*) rb_malloc(sizeof(struct abort_client
));
1273 rb_strlcpy(abt
->notice
, "Max SendQ exceeded", sizeof(abt
->notice
));
1275 snprintf(abt
->notice
, sizeof(abt
->notice
), "Write error: %s", strerror(errno
));
1277 abt
->client
= client_p
;
1278 SetIOError(client_p
);
1280 SetClosing(client_p
);
1281 rb_dlinkAdd(abt
, &abt
->node
, &abort_list
);
1285 /* This does the remove of the user from channels..local or remote */
1287 exit_generic_client(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1288 const char *comment
)
1290 rb_dlink_node
*ptr
, *next_ptr
;
1292 if(IsOper(source_p
))
1293 rb_dlinkFindDestroy(source_p
, &oper_list
);
1295 sendto_common_channels_local(source_p
, NOCAPS
, NOCAPS
, ":%s!%s@%s QUIT :%s",
1297 source_p
->username
, source_p
->host
, comment
);
1299 remove_user_from_channels(source_p
);
1301 /* Should not be in any channels now */
1302 s_assert(source_p
->user
->channel
.head
== NULL
);
1304 /* Clean up invitefield */
1305 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, source_p
->user
->invited
.head
)
1307 del_invite(ptr
->data
, source_p
);
1310 /* Clean up allow lists */
1311 del_all_accepts(source_p
);
1313 whowas_add_history(source_p
, 0);
1314 whowas_off_history(source_p
);
1316 monitor_signoff(source_p
);
1318 if(has_id(source_p
))
1319 del_from_id_hash(source_p
->id
, source_p
);
1321 del_from_hostname_hash(source_p
->orighost
, source_p
);
1322 del_from_client_hash(source_p
->name
, source_p
);
1323 remove_client_from_list(source_p
);
1327 * Assumes IsPerson(source_p) && !MyConnect(source_p)
1331 exit_remote_client(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1332 const char *comment
)
1334 exit_generic_client(client_p
, source_p
, from
, comment
);
1336 if(source_p
->servptr
&& source_p
->servptr
->serv
)
1338 rb_dlinkDelete(&source_p
->lnode
, &source_p
->servptr
->serv
->users
);
1341 if((source_p
->flags
& FLAGS_KILLED
) == 0)
1343 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
,
1344 ":%s QUIT :%s", use_id(source_p
), comment
);
1348 #ifdef DEBUG_EXITED_CLIENTS
1349 rb_dlinkAddAlloc(source_p
, &dead_remote_list
);
1351 rb_dlinkAddAlloc(source_p
, &dead_list
);
1353 return(CLIENT_EXITED
);
1357 * This assumes IsUnknown(source_p) == true and MyConnect(source_p) == true
1361 exit_unknown_client(struct Client
*client_p
, /* The local client originating the
1362 * exit or NULL, if this exit is
1363 * generated by this server for
1365 * This will not get any of the
1366 * generated messages. */
1367 struct Client
*source_p
, /* Client exiting */
1368 struct Client
*from
, /* Client firing off this Exit,
1370 const char *comment
)
1372 authd_abort_client(source_p
);
1373 rb_dlinkDelete(&source_p
->localClient
->tnode
, &unknown_list
);
1375 if(!IsIOError(source_p
))
1376 sendto_one(source_p
, "ERROR :Closing Link: %s (%s)",
1377 source_p
->user
!= NULL
? source_p
->host
: "127.0.0.1",
1380 close_connection(source_p
);
1382 if(has_id(source_p
))
1383 del_from_id_hash(source_p
->id
, source_p
);
1385 del_from_hostname_hash(source_p
->host
, source_p
);
1386 del_from_client_hash(source_p
->name
, source_p
);
1387 remove_client_from_list(source_p
);
1389 rb_dlinkAddAlloc(source_p
, &dead_list
);
1391 /* Note that we don't need to add unknowns to the dead_list */
1392 return(CLIENT_EXITED
);
1396 exit_remote_server(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1397 const char *comment
)
1399 static char comment1
[(HOSTLEN
*2)+2];
1400 static char newcomment
[BUFSIZE
];
1401 struct Client
*target_p
;
1403 if(ConfigServerHide
.flatten_links
)
1404 strcpy(comment1
, "*.net *.split");
1407 strcpy(comment1
, source_p
->servptr
->name
);
1408 strcat(comment1
, " ");
1409 strcat(comment1
, source_p
->name
);
1412 snprintf(newcomment
, sizeof(newcomment
), "by %s: %s",
1413 from
->name
, comment
);
1415 remove_dependents(client_p
, source_p
, from
, IsPerson(from
) ? newcomment
: comment
, comment1
);
1417 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
);
1436 scache_split(source_p
->serv
->nameinfo
);
1439 #ifdef DEBUG_EXITED_CLIENTS
1440 rb_dlinkAddAlloc(source_p
, &dead_remote_list
);
1442 rb_dlinkAddAlloc(source_p
, &dead_list
);
1448 qs_server(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1449 const char *comment
)
1451 if(source_p
->servptr
&& source_p
->servptr
->serv
)
1452 rb_dlinkDelete(&source_p
->lnode
, &source_p
->servptr
->serv
->servers
);
1456 rb_dlinkFindDestroy(source_p
, &global_serv_list
);
1458 if(has_id(source_p
))
1459 del_from_id_hash(source_p
->id
, source_p
);
1461 del_from_client_hash(source_p
->name
, source_p
);
1462 remove_client_from_list(source_p
);
1463 scache_split(source_p
->serv
->nameinfo
);
1466 rb_dlinkAddAlloc(source_p
, &dead_list
);
1471 exit_local_server(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1472 const char *comment
)
1474 static char comment1
[(HOSTLEN
*2)+2];
1475 static char newcomment
[BUFSIZE
];
1476 unsigned int sendk
, recvk
;
1478 rb_dlinkDelete(&source_p
->localClient
->tnode
, &serv_list
);
1479 rb_dlinkFindDestroy(source_p
, &global_serv_list
);
1481 sendk
= source_p
->localClient
->sendK
;
1482 recvk
= source_p
->localClient
->receiveK
;
1484 /* Always show source here, so the server notices show
1485 * which side initiated the split -- jilles
1487 snprintf(newcomment
, sizeof(newcomment
), "by %s: %s",
1488 from
== source_p
? me
.name
: from
->name
, comment
);
1489 if (!IsIOError(source_p
))
1490 sendto_one(source_p
, "SQUIT %s :%s", use_id(source_p
),
1492 if(client_p
!= NULL
&& source_p
!= client_p
&& !IsIOError(source_p
))
1494 sendto_one(source_p
, "ERROR :Closing Link: 127.0.0.1 %s (%s)",
1495 source_p
->name
, comment
);
1498 if(source_p
->servptr
&& source_p
->servptr
->serv
)
1499 rb_dlinkDelete(&source_p
->lnode
, &source_p
->servptr
->serv
->servers
);
1504 close_connection(source_p
);
1506 if(ConfigServerHide
.flatten_links
)
1507 strcpy(comment1
, "*.net *.split");
1510 strcpy(comment1
, source_p
->servptr
->name
);
1511 strcat(comment1
, " ");
1512 strcat(comment1
, source_p
->name
);
1515 if(source_p
->serv
!= NULL
)
1516 remove_dependents(client_p
, source_p
, from
, IsPerson(from
) ? newcomment
: comment
, comment1
);
1518 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s was connected"
1519 " for %ld seconds. %d/%d sendK/recvK.",
1520 source_p
->name
, (long) rb_current_time() - source_p
->localClient
->firsttime
, sendk
, recvk
);
1522 ilog(L_SERVER
, "%s was connected for %ld seconds. %d/%d sendK/recvK.",
1523 source_p
->name
, (long) rb_current_time() - source_p
->localClient
->firsttime
, sendk
, recvk
);
1525 if(has_id(source_p
))
1526 del_from_id_hash(source_p
->id
, source_p
);
1528 del_from_client_hash(source_p
->name
, source_p
);
1529 remove_client_from_list(source_p
);
1530 scache_split(source_p
->serv
->nameinfo
);
1533 rb_dlinkAddAlloc(source_p
, &dead_list
);
1539 * This assumes IsPerson(source_p) == true && MyConnect(source_p) == true
1543 exit_local_client(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1544 const char *comment
)
1546 unsigned long on_for
;
1549 exit_generic_client(client_p
, source_p
, from
, comment
);
1550 clear_monitor(source_p
);
1552 s_assert(IsPerson(source_p
));
1553 rb_dlinkDelete(&source_p
->localClient
->tnode
, &lclient_list
);
1554 rb_dlinkDelete(&source_p
->lnode
, &me
.serv
->users
);
1556 if(IsOper(source_p
))
1557 rb_dlinkFindDestroy(source_p
, &local_oper_list
);
1559 sendto_realops_snomask(SNO_CCONN
, L_ALL
,
1560 "Client exiting: %s (%s@%s) [%s] [%s]",
1562 source_p
->username
, source_p
->host
, comment
,
1563 show_ip(NULL
, source_p
) ? source_p
->sockhost
: "255.255.255.255");
1565 sendto_realops_snomask(SNO_CCONNEXT
, L_ALL
,
1566 "CLIEXIT %s %s %s %s 0 %s",
1567 source_p
->name
, source_p
->username
, source_p
->host
,
1568 show_ip(NULL
, source_p
) ? source_p
->sockhost
: "255.255.255.255",
1571 on_for
= rb_current_time() - source_p
->localClient
->firsttime
;
1573 ilog(L_USER
, "%s (%3lu:%02lu:%02lu): %s!%s@%s %s %d/%d",
1574 rb_ctime(rb_current_time(), tbuf
, sizeof(tbuf
)), on_for
/ 3600,
1575 (on_for
% 3600) / 60, on_for
% 60,
1576 source_p
->name
, source_p
->username
, source_p
->host
,
1578 source_p
->localClient
->sendK
, source_p
->localClient
->receiveK
);
1580 sendto_one(source_p
, "ERROR :Closing Link: %s (%s)", source_p
->host
, comment
);
1581 close_connection(source_p
);
1583 if((source_p
->flags
& FLAGS_KILLED
) == 0)
1585 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
,
1586 ":%s QUIT :%s", use_id(source_p
), comment
);
1590 rb_dlinkAddAlloc(source_p
, &dead_list
);
1591 return(CLIENT_EXITED
);
1596 ** exit_client - This is old "m_bye". Name changed, because this is not a
1597 ** protocol function, but a general server utility function.
1599 ** This function exits a client of *any* type (user, server, etc)
1600 ** from this server. Also, this generates all necessary prototol
1601 ** messages that this exit may cause.
1603 ** 1) If the client is a local client, then this implicitly
1604 ** exits all other clients depending on this connection (e.g.
1605 ** remote clients having 'from'-field that points to this.
1607 ** 2) If the client is a remote client, then only this is exited.
1609 ** For convenience, this function returns a suitable value for
1610 ** m_function return value:
1612 ** CLIENT_EXITED if (client_p == source_p)
1613 ** 0 if (client_p != source_p)
1616 exit_client(struct Client
*client_p
, /* The local client originating the
1617 * exit or NULL, if this exit is
1618 * generated by this server for
1620 * This will not get any of the
1621 * generated messages. */
1622 struct Client
*source_p
, /* Client exiting */
1623 struct Client
*from
, /* Client firing off this Exit,
1625 const char *comment
/* Reason for the exit */
1628 hook_data_client_exit hdata
;
1629 if(IsClosing(source_p
))
1632 /* note, this HAS to be here, when we exit a client we attempt to
1633 * send them data, if this generates a write error we must *not* add
1634 * them to the abort list --fl
1636 SetClosing(source_p
);
1638 hdata
.local_link
= client_p
;
1639 hdata
.target
= source_p
;
1641 hdata
.comment
= comment
;
1642 call_hook(h_client_exit
, &hdata
);
1644 if(MyConnect(source_p
))
1646 /* Local clients of various types */
1647 if(IsPerson(source_p
))
1648 return exit_local_client(client_p
, source_p
, from
, comment
);
1649 else if(IsServer(source_p
))
1650 return exit_local_server(client_p
, source_p
, from
, comment
);
1651 /* IsUnknown || IsConnecting || IsHandShake */
1652 else if(!IsReject(source_p
))
1653 return exit_unknown_client(client_p
, source_p
, from
, comment
);
1658 if(IsPerson(source_p
))
1659 return exit_remote_client(client_p
, source_p
, from
, comment
);
1660 else if(IsServer(source_p
))
1661 return exit_remote_server(client_p
, source_p
, from
, comment
);
1668 * Count up local client memory
1671 /* XXX one common Client list now */
1673 count_local_client_memory(size_t * count
, size_t * local_client_memory_used
)
1676 rb_bh_usage(lclient_heap
, count
, NULL
, &lusage
, NULL
);
1677 *local_client_memory_used
= lusage
+ (*count
* (sizeof(void *) + sizeof(struct Client
)));
1681 * Count up remote client memory
1684 count_remote_client_memory(size_t * count
, size_t * remote_client_memory_used
)
1686 size_t lcount
, rcount
;
1687 rb_bh_usage(lclient_heap
, &lcount
, NULL
, NULL
, NULL
);
1688 rb_bh_usage(client_heap
, &rcount
, NULL
, NULL
, NULL
);
1689 *count
= rcount
- lcount
;
1690 *remote_client_memory_used
= *count
* (sizeof(void *) + sizeof(struct Client
));
1695 * accept processing, this adds a form of "caller ID" to ircd
1697 * If a client puts themselves into "caller ID only" mode,
1698 * only clients that match a client pointer they have put on
1699 * the accept list will be allowed to message them.
1701 * [ source.on_allow_list ] -> [ target1 ] -> [ target2 ]
1703 * [target.allow_list] -> [ source1 ] -> [source2 ]
1705 * i.e. a target will have a link list of source pointers it will allow
1706 * each source client then has a back pointer pointing back
1707 * to the client that has it on its accept list.
1708 * This allows for exit_one_client to remove these now bogus entries
1709 * from any client having an accept on them.
1714 * inputs - pointer to exiting client
1716 * side effects - Walk through given clients allow_list and on_allow_list
1717 * remove all references to this client
1720 del_all_accepts(struct Client
*client_p
)
1723 rb_dlink_node
*next_ptr
;
1724 struct Client
*target_p
;
1726 if(MyClient(client_p
) && client_p
->localClient
->allow_list
.head
)
1728 /* clear this clients accept list, and remove them from
1729 * everyones on_accept_list
1731 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, client_p
->localClient
->allow_list
.head
)
1733 target_p
= ptr
->data
;
1734 rb_dlinkFindDestroy(client_p
, &target_p
->on_allow_list
);
1735 rb_dlinkDestroy(ptr
, &client_p
->localClient
->allow_list
);
1739 /* remove this client from everyones accept list */
1740 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, client_p
->on_allow_list
.head
)
1742 target_p
= ptr
->data
;
1743 rb_dlinkFindDestroy(client_p
, &target_p
->localClient
->allow_list
);
1744 rb_dlinkDestroy(ptr
, &client_p
->on_allow_list
);
1749 * show_ip() - asks if the true IP should be shown when source is
1750 * asking for info about target
1752 * Inputs - source_p who is asking
1753 * - target_p who do we want the info on
1754 * Output - returns 1 if clear IP can be shown, otherwise 0
1755 * Side Effects - none
1759 show_ip(struct Client
*source_p
, struct Client
*target_p
)
1761 if(IsAnyServer(target_p
))
1765 else if(IsIPSpoof(target_p
))
1767 /* source == NULL indicates message is being sent
1770 if(!ConfigFileEntry
.hide_spoof_ips
&&
1771 (source_p
== NULL
|| MyOper(source_p
)))
1775 else if(IsDynSpoof(target_p
) && (source_p
!= NULL
&& !IsOper(source_p
)))
1782 show_ip_conf(struct ConfItem
*aconf
, struct Client
*source_p
)
1784 if(IsConfDoSpoofIp(aconf
))
1786 if(!ConfigFileEntry
.hide_spoof_ips
&& MyOper(source_p
))
1796 show_ip_whowas(struct Whowas
*whowas
, struct Client
*source_p
)
1798 if(whowas
->flags
& WHOWAS_IP_SPOOFING
)
1799 if(ConfigFileEntry
.hide_spoof_ips
|| !MyOper(source_p
))
1801 if(whowas
->flags
& WHOWAS_DYNSPOOF
)
1802 if(!IsOper(source_p
))
1810 * inputs - pointer to client struct
1811 * output - pointer to struct User
1812 * side effects - add's an User information block to a client
1813 * if it was not previously allocated.
1816 make_user(struct Client
*client_p
)
1820 user
= client_p
->user
;
1823 user
= (struct User
*) rb_bh_alloc(user_heap
);
1825 client_p
->user
= user
;
1833 * inputs - pointer to client struct
1834 * output - pointer to server_t
1835 * side effects - add's an Server information block to a client
1836 * if it was not previously allocated.
1839 make_server(struct Client
*client_p
)
1841 struct Server
*serv
= client_p
->serv
;
1845 serv
= (struct Server
*) rb_malloc(sizeof(struct Server
));
1846 client_p
->serv
= serv
;
1848 return client_p
->serv
;
1854 * inputs - pointer to user struct
1855 * - pointer to client struct
1857 * side effects - Decrease user reference count by one and release block,
1858 * if count reaches 0
1861 free_user(struct User
*user
, struct Client
*client_p
)
1863 free_away(client_p
);
1865 if(--user
->refcnt
<= 0)
1868 rb_free((char *) user
->away
);
1872 if(user
->refcnt
< 0 || user
->invited
.head
|| user
->channel
.head
)
1874 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1875 "* %p user (%s!%s@%s) %p %p %p %lu %d *",
1877 client_p
? client_p
->
1884 rb_dlink_list_length(&user
->channel
),
1886 s_assert(!user
->refcnt
);
1887 s_assert(!user
->invited
.head
);
1888 s_assert(!user
->channel
.head
);
1891 rb_bh_free(user_heap
, user
);
1896 allocate_away(struct Client
*client_p
)
1898 if(client_p
->user
->away
== NULL
)
1899 client_p
->user
->away
= rb_bh_alloc(away_heap
);
1904 free_away(struct Client
*client_p
)
1906 if(client_p
->user
!= NULL
&& client_p
->user
->away
!= NULL
) {
1907 rb_bh_free(away_heap
, client_p
->user
->away
);
1908 client_p
->user
->away
= NULL
;
1917 for(i
= 0; i
< 3; i
++)
1918 current_uid
[i
] = me
.id
[i
];
1920 for(i
= 3; i
< 9; i
++)
1921 current_uid
[i
] = 'A';
1923 current_uid
[9] = '\0';
1930 static int flipped
= 0;
1934 for(i
= 8; i
> 3; i
--)
1936 if(current_uid
[i
] == 'Z')
1938 current_uid
[i
] = '0';
1941 else if(current_uid
[i
] != '9')
1947 current_uid
[i
] = 'A';
1950 /* if this next if() triggers, we're fucked. */
1951 if(current_uid
[3] == 'Z')
1953 current_uid
[i
] = 'A';
1959 /* if this happens..well, i'm not sure what to say, but lets handle it correctly */
1960 if(rb_unlikely(flipped
))
1962 /* this slows down uid generation a bit... */
1963 if(find_id(current_uid
) != NULL
)
1971 * Close the physical connection. This function must make
1972 * MyConnect(client_p) == FALSE, and set client_p->from == NULL.
1975 close_connection(struct Client
*client_p
)
1977 s_assert(client_p
!= NULL
);
1978 if(client_p
== NULL
)
1981 s_assert(MyConnect(client_p
));
1982 if(!MyConnect(client_p
))
1985 if(IsServer(client_p
))
1987 struct server_conf
*server_p
;
1989 ServerStats
.is_sv
++;
1990 ServerStats
.is_sbs
+= client_p
->localClient
->sendB
;
1991 ServerStats
.is_sbr
+= client_p
->localClient
->receiveB
;
1992 ServerStats
.is_sti
+= (unsigned long long)(rb_current_time() - client_p
->localClient
->firsttime
);
1995 * If the connection has been up for a long amount of time, schedule
1996 * a 'quick' reconnect, else reset the next-connect cycle.
1998 if((server_p
= find_server_conf(client_p
->name
)) != NULL
)
2001 * Reschedule a faster reconnect, if this was a automatically
2002 * connected configuration entry. (Note that if we have had
2003 * a rehash in between, the status has been changed to
2004 * CONF_ILLEGAL). But only do this if it was a "good" link.
2006 server_p
->hold
= time(NULL
);
2008 (server_p
->hold
- client_p
->localClient
->lasttime
>
2009 HANGONGOODLINK
) ? HANGONRETRYDELAY
: ConFreq(server_p
->class);
2013 else if(IsClient(client_p
))
2015 ServerStats
.is_cl
++;
2016 ServerStats
.is_cbs
+= client_p
->localClient
->sendB
;
2017 ServerStats
.is_cbr
+= client_p
->localClient
->receiveB
;
2018 ServerStats
.is_cti
+= (unsigned long long)(rb_current_time() - client_p
->localClient
->firsttime
);
2021 ServerStats
.is_ni
++;
2023 client_release_connids(client_p
);
2025 if(client_p
->localClient
->F
!= NULL
)
2027 /* attempt to flush any pending dbufs. Evil, but .. -- adrian */
2028 if(!IsIOError(client_p
))
2029 send_queued(client_p
);
2031 rb_close(client_p
->localClient
->F
);
2032 client_p
->localClient
->F
= NULL
;
2035 rb_linebuf_donebuf(&client_p
->localClient
->buf_sendq
);
2036 rb_linebuf_donebuf(&client_p
->localClient
->buf_recvq
);
2037 detach_conf(client_p
);
2039 /* XXX shouldnt really be done here. */
2040 detach_server_conf(client_p
);
2042 client_p
->from
= NULL
; /* ...this should catch them! >:) --msa */
2043 ClearMyConnect(client_p
);
2044 SetIOError(client_p
);
2050 error_exit_client(struct Client
*client_p
, int error
)
2053 * ...hmm, with non-blocking sockets we might get
2054 * here from quite valid reasons, although.. why
2055 * would select report "data available" when there
2056 * wasn't... so, this must be an error anyway... --msa
2057 * actually, EOF occurs when read() returns 0 and
2058 * in due course, select() returns that fd as ready
2059 * for reading even though it ends up being an EOF. -avalon
2062 int current_error
= rb_get_sockerr(client_p
->localClient
->F
);
2064 SetIOError(client_p
);
2066 if(IsServer(client_p
) || IsHandshake(client_p
))
2070 sendto_realops_snomask(SNO_GENERAL
, is_remote_connect(client_p
) && !IsServer(client_p
) ? L_NETWIDE
: L_ALL
,
2071 "Server %s closed the connection",
2074 ilog(L_SERVER
, "Server %s closed the connection",
2075 log_client_name(client_p
, SHOW_IP
));
2079 sendto_realops_snomask(SNO_GENERAL
, is_remote_connect(client_p
) && !IsServer(client_p
) ? L_NETWIDE
: L_ALL
,
2080 "Lost connection to %s: %s",
2081 client_p
->name
, strerror(current_error
));
2082 ilog(L_SERVER
, "Lost connection to %s: %s",
2083 log_client_name(client_p
, SHOW_IP
), strerror(current_error
));
2088 rb_strlcpy(errmsg
, "Remote host closed the connection", sizeof(errmsg
));
2090 snprintf(errmsg
, sizeof(errmsg
), "Read error: %s", strerror(current_error
));
2092 exit_client(client_p
, client_p
, &me
, errmsg
);