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 rb_free(client_p
->localClient
->zipstats
);
322 if (client_p
->localClient
->ws_ctl
!= NULL
)
323 wsockd_decrement_clicount(client_p
->localClient
->ws_ctl
);
325 rb_bh_free(lclient_heap
, client_p
->localClient
);
326 client_p
->localClient
= NULL
;
330 free_client(struct Client
*client_p
)
332 s_assert(NULL
!= client_p
);
333 s_assert(&me
!= client_p
);
334 free_local_client(client_p
);
335 free_pre_client(client_p
);
336 rb_free(client_p
->certfp
);
337 rb_bh_free(client_heap
, client_p
);
341 * check_pings - go through the local client list and check activity
342 * kill off stuff that should die
344 * inputs - NOT USED (from event)
345 * output - next time_t when check_pings() should be called again
349 * A PING can be sent to clients as necessary.
351 * Client/Server ping outs are handled.
355 * Addon from adrian. We used to call this after nextping seconds,
356 * however I've changed it to run once a second. This is only for
357 * PING timeouts, not K/etc-line checks (thanks dianora!). Having it
358 * run once a second makes life a lot easier - when a new client connects
359 * and they need a ping in 4 seconds, if nextping was set to 20 seconds
360 * we end up waiting 20 seconds. This is stupid. :-)
361 * I will optimise (hah!) check_pings() once I've finished working on
362 * tidying up other network IO evilnesses.
367 check_pings(void *notused
)
369 check_pings_list(&lclient_list
);
370 check_pings_list(&serv_list
);
371 check_unknowns_list(&unknown_list
);
377 * inputs - pointer to list to check
382 check_pings_list(rb_dlink_list
* list
)
384 char scratch
[32]; /* way too generous but... */
385 struct Client
*client_p
; /* current local client_p being examined */
386 int ping
= 0; /* ping time value from client */
387 rb_dlink_node
*ptr
, *next_ptr
;
389 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, list
->head
)
391 client_p
= ptr
->data
;
393 if(!MyConnect(client_p
) || IsDead(client_p
))
396 ping
= get_client_ping(client_p
);
398 if(ping
< (rb_current_time() - client_p
->localClient
->lasttime
))
401 * If the client/server hasnt talked to us in 2*ping seconds
402 * and it has a ping time, then close its connection.
404 if(((rb_current_time() - client_p
->localClient
->lasttime
) >= (2 * ping
)
405 && (client_p
->flags
& FLAGS_PINGSENT
)))
407 if(IsServer(client_p
))
409 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
410 "No response from %s, closing link",
413 "No response from %s, closing link",
414 log_client_name(client_p
, HIDE_IP
));
416 (void) snprintf(scratch
, sizeof(scratch
),
417 "Ping timeout: %d seconds",
418 (int) (rb_current_time() - client_p
->localClient
->lasttime
));
420 exit_client(client_p
, client_p
, &me
, scratch
);
423 else if((client_p
->flags
& FLAGS_PINGSENT
) == 0)
426 * if we havent PINGed the connection and we havent
427 * heard from it in a while, PING it to make sure
430 client_p
->flags
|= FLAGS_PINGSENT
;
431 /* not nice but does the job */
432 client_p
->localClient
->lasttime
= rb_current_time() - ping
;
433 sendto_one(client_p
, "PING :%s", me
.name
);
442 * check_unknowns_list
444 * inputs - pointer to list of unknown clients
446 * side effects - unknown clients get marked for termination after n seconds
449 check_unknowns_list(rb_dlink_list
* list
)
451 rb_dlink_node
*ptr
, *next_ptr
;
452 struct Client
*client_p
;
455 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, list
->head
)
457 client_p
= ptr
->data
;
459 if(IsDead(client_p
) || IsClosing(client_p
))
462 /* Still querying with authd */
463 if(client_p
->preClient
!= NULL
&& client_p
->preClient
->auth
.cid
!= 0)
467 * Check UNKNOWN connections - if they have been in this state
468 * for > 30s, close them.
471 timeout
= IsAnyServer(client_p
) ? ConfigFileEntry
.connect_timeout
: 30;
472 if((rb_current_time() - client_p
->localClient
->firsttime
) > timeout
)
474 if(IsAnyServer(client_p
))
476 sendto_realops_snomask(SNO_GENERAL
, is_remote_connect(client_p
) ? L_NETWIDE
: L_ALL
,
477 "No response from %s, closing link",
480 "No response from %s, closing link",
481 log_client_name(client_p
, HIDE_IP
));
483 exit_client(client_p
, client_p
, &me
, "Connection timed out");
489 notify_banned_client(struct Client
*client_p
, struct ConfItem
*aconf
, int ban
)
491 static const char conn_closed
[] = "Connection closed";
492 static const char d_lined
[] = "D-lined";
493 static const char k_lined
[] = "K-lined";
494 const char *reason
= NULL
;
495 const char *exit_reason
= conn_closed
;
497 if(ConfigFileEntry
.kline_with_reason
)
499 reason
= get_user_ban_reason(aconf
);
500 exit_reason
= reason
;
504 reason
= aconf
->status
== D_LINED
? d_lined
: k_lined
;
507 if(ban
== D_LINED
&& !IsPerson(client_p
))
508 sendto_one(client_p
, "NOTICE DLINE :*** You have been D-lined");
510 sendto_one(client_p
, form_str(ERR_YOUREBANNEDCREEP
),
511 me
.name
, client_p
->name
, reason
);
513 exit_client(client_p
, client_p
, &me
,
514 EmptyString(ConfigFileEntry
.kline_reason
) ? exit_reason
:
515 ConfigFileEntry
.kline_reason
);
522 * side effects - Check all connections for a pending k/dline against the
523 * client, exit the client if found.
526 check_banned_lines(void)
533 /* check_klines_event()
537 * side effects - check_klines() is called, kline_queued unset
540 check_klines_event(void *unused
)
542 kline_queued
= false;
550 * side effects - all clients will be checked for klines
555 struct Client
*client_p
;
556 struct ConfItem
*aconf
;
558 rb_dlink_node
*next_ptr
;
560 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
562 client_p
= ptr
->data
;
564 if(IsMe(client_p
) || !IsPerson(client_p
))
567 if((aconf
= find_kline(client_p
)) != NULL
)
569 if(IsExemptKline(client_p
))
571 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
572 "KLINE over-ruled for %s, client is kline_exempt [%s@%s]",
573 get_client_name(client_p
, HIDE_IP
),
574 aconf
->user
, aconf
->host
);
578 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
579 "KLINE active for %s",
580 get_client_name(client_p
, HIDE_IP
));
582 notify_banned_client(client_p
, aconf
, K_LINED
);
592 * side effects - all clients will be checked for dlines
597 struct Client
*client_p
;
598 struct ConfItem
*aconf
;
600 rb_dlink_node
*next_ptr
;
602 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
604 client_p
= ptr
->data
;
609 if((aconf
= find_dline((struct sockaddr
*)&client_p
->localClient
->ip
, GET_SS_FAMILY(&client_p
->localClient
->ip
))) != NULL
)
611 if(aconf
->status
& CONF_EXEMPTDLINE
)
614 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
615 "DLINE active for %s",
616 get_client_name(client_p
, HIDE_IP
));
618 notify_banned_client(client_p
, aconf
, D_LINED
);
623 /* dlines need to be checked against unknowns too */
624 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, unknown_list
.head
)
626 client_p
= ptr
->data
;
628 if((aconf
= find_dline((struct sockaddr
*)&client_p
->localClient
->ip
, GET_SS_FAMILY(&client_p
->localClient
->ip
))) != NULL
)
630 if(aconf
->status
& CONF_EXEMPTDLINE
)
633 notify_banned_client(client_p
, aconf
, D_LINED
);
642 * side effects - all clients will be checked for xlines
647 struct Client
*client_p
;
648 struct ConfItem
*aconf
;
650 rb_dlink_node
*next_ptr
;
652 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
654 client_p
= ptr
->data
;
656 if(IsMe(client_p
) || !IsPerson(client_p
))
659 if((aconf
= find_xline(client_p
->info
, 1)) != NULL
)
661 if(IsExemptKline(client_p
))
663 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
664 "XLINE over-ruled for %s, client is kline_exempt [%s]",
665 get_client_name(client_p
, HIDE_IP
),
670 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "XLINE active for %s",
671 get_client_name(client_p
, HIDE_IP
));
673 (void) exit_client(client_p
, client_p
, &me
, "Bad user info");
681 * inputs - resv, reason, time
683 * side effects - all local clients matching resv will be FNC'd
686 resv_nick_fnc(const char *mask
, const char *reason
, int temp_time
)
688 struct Client
*client_p
, *target_p
;
690 rb_dlink_node
*next_ptr
;
692 char note
[NICKLEN
+10];
694 if (!ConfigFileEntry
.resv_fnc
)
697 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
699 client_p
= ptr
->data
;
701 if(IsMe(client_p
) || !IsPerson(client_p
) || IsExemptResv(client_p
))
704 /* Skip users that already have UID nicks. */
705 if(IsDigit(client_p
->name
[0]))
708 if(match_esc(mask
, client_p
->name
))
713 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
714 "RESV forced nick change for %s!%s@%s to %s; nick matched [%s] (%s)",
715 client_p
->name
, client_p
->username
, client_p
->host
, nick
, mask
, reason
);
717 sendto_realops_snomask(SNO_NCHANGE
, L_ALL
,
718 "Nick change: From %s to %s [%s@%s]",
719 client_p
->name
, nick
, client_p
->username
, client_p
->host
);
724 sendto_one_notice(client_p
,
725 ":*** Nick %s is temporarily unavailable on this server.",
730 sendto_one_notice(client_p
,
731 ":*** Nick %s is no longer available on this server.",
735 /* Do all of the nick-changing gymnastics. */
736 client_p
->tsinfo
= rb_current_time();
737 whowas_add_history(client_p
, 1);
739 monitor_signoff(client_p
);
741 invalidate_bancache_user(client_p
);
743 sendto_common_channels_local(client_p
, NOCAPS
, NOCAPS
, ":%s!%s@%s NICK :%s",
744 client_p
->name
, client_p
->username
, client_p
->host
, nick
);
745 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s NICK %s :%ld",
746 use_id(client_p
), nick
, (long) client_p
->tsinfo
);
748 del_from_client_hash(client_p
->name
, client_p
);
749 rb_strlcpy(client_p
->name
, nick
, sizeof(client_p
->name
));
750 add_to_client_hash(nick
, client_p
);
752 monitor_signon(client_p
);
754 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, client_p
->on_allow_list
.head
)
756 target_p
= ptr
->data
;
757 rb_dlinkFindDestroy(client_p
, &target_p
->localClient
->allow_list
);
758 rb_dlinkDestroy(ptr
, &client_p
->on_allow_list
);
761 snprintf(note
, sizeof(note
), "Nick: %s", nick
);
762 rb_note(client_p
->localClient
->F
, note
);
768 * update_client_exit_stats
770 * input - pointer to client
775 update_client_exit_stats(struct Client
*client_p
)
777 if(IsServer(client_p
))
779 sendto_realops_snomask(SNO_EXTERNAL
, L_ALL
,
780 "Server %s split from %s",
781 client_p
->name
, client_p
->servptr
->name
);
782 if(HasSentEob(client_p
))
785 else if(IsClient(client_p
))
790 if(IsInvisible(client_p
))
794 if(splitchecking
&& !splitmode
)
795 check_splitmode(NULL
);
799 * release_client_state
801 * input - pointer to client to release
806 release_client_state(struct Client
*client_p
)
808 if(client_p
->user
!= NULL
)
810 free_user(client_p
->user
, client_p
); /* try this here */
814 if(client_p
->serv
->user
!= NULL
)
815 free_user(client_p
->serv
->user
, client_p
);
816 if(client_p
->serv
->fullcaps
)
817 rb_free(client_p
->serv
->fullcaps
);
818 rb_free(client_p
->serv
);
823 * remove_client_from_list
824 * inputs - point to client to remove
826 * side effects - taken the code from ExitOneClient() for this
827 * and placed it here. - avalon
830 remove_client_from_list(struct Client
*client_p
)
832 s_assert(NULL
!= client_p
);
837 /* A client made with make_client()
838 * is on the unknown_list until removed.
839 * If it =does= happen to exit before its removed from that list
840 * and its =not= on the global_client_list, it will core here.
841 * short circuit that case now -db
843 if(client_p
->node
.prev
== NULL
&& client_p
->node
.next
== NULL
)
846 rb_dlinkDelete(&client_p
->node
, &global_client_list
);
848 update_client_exit_stats(client_p
);
854 * input - nickname to check, flag for nick from local client
855 * output - 0 if erroneous, else 1
859 clean_nick(const char *nick
, int loc_client
)
863 /* nicks cant start with a digit or -, and must have a length */
864 if(*nick
== '-' || *nick
== '\0')
867 if(loc_client
&& IsDigit(*nick
))
873 if(!IsNickChar(*nick
))
878 if(len
>= NICKLEN
&& (unsigned int)len
>= ConfigFileEntry
.nicklen
)
885 * find_person - find person by (nick)name.
886 * inputs - pointer to name
887 * output - return client pointer
891 find_person(const char *name
)
893 struct Client
*c2ptr
;
895 c2ptr
= find_client(name
);
897 if(c2ptr
&& IsPerson(c2ptr
))
903 find_named_person(const char *name
)
905 struct Client
*c2ptr
;
907 c2ptr
= find_named_client(name
);
909 if(c2ptr
&& IsPerson(c2ptr
))
916 * find_chasing - find the client structure for a nick name (user)
917 * using history mechanism if necessary. If the client is not found,
918 * an error message (NO SUCH NICK) is generated. If the client was found
919 * through the history, chasing will be 1 and otherwise 0.
922 find_chasing(struct Client
*source_p
, const char *user
, int *chasing
)
926 if(MyClient(source_p
))
927 who
= find_named_person(user
);
929 who
= find_person(user
);
934 if(who
|| IsDigit(*user
))
937 if(!(who
= whowas_get_history(user
, (long) KILLCHASETIMELIMIT
)))
939 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
940 form_str(ERR_NOSUCHNICK
), user
);
949 * get_client_name - Return the name of the client
950 * for various tracking and
951 * admin purposes. The main purpose of this function is to
952 * return the "socket host" name of the client, if that
953 * differs from the advertised name (other than case).
954 * But, this can be used to any client structure.
957 * Watch out the allocation of "nbuf", if either source_p->name
958 * or source_p->sockhost gets changed into pointers instead of
959 * directly allocated within the structure...
962 * Function return either a pointer to the structure (source_p) or
963 * to internal buffer (nbuf). *NEVER* use the returned pointer
964 * to modify what it points!!!
968 get_client_name(struct Client
*client
, int showip
)
970 static char nbuf
[HOSTLEN
* 2 + USERLEN
+ 5];
972 s_assert(NULL
!= client
);
976 if(MyConnect(client
))
978 if(!irccmp(client
->name
, client
->host
))
981 if(ConfigFileEntry
.hide_spoof_ips
&&
982 showip
== SHOW_IP
&& IsIPSpoof(client
))
984 if(IsAnyServer(client
))
987 /* And finally, let's get the host information, ip or name */
991 snprintf(nbuf
, sizeof(nbuf
), "%s[%s@%s]",
992 client
->name
, client
->username
,
996 snprintf(nbuf
, sizeof(nbuf
), "%s[%s@255.255.255.255]",
997 client
->name
, client
->username
);
1000 snprintf(nbuf
, sizeof(nbuf
), "%s[%s@%s]",
1001 client
->name
, client
->username
, client
->host
);
1006 /* As pointed out by Adel Mezibra
1007 * Neph|l|m@EFnet. Was missing a return here.
1009 return client
->name
;
1012 /* log_client_name()
1014 * This version is the same as get_client_name, but doesnt contain the
1015 * code that will hide IPs always. This should be used for logfiles.
1018 log_client_name(struct Client
*target_p
, int showip
)
1020 static char nbuf
[HOSTLEN
* 2 + USERLEN
+ 5];
1022 if(target_p
== NULL
)
1025 if(MyConnect(target_p
))
1027 if(irccmp(target_p
->name
, target_p
->host
) == 0)
1028 return target_p
->name
;
1033 snprintf(nbuf
, sizeof(nbuf
), "%s[%s@%s]", target_p
->name
,
1034 target_p
->username
, target_p
->sockhost
);
1038 snprintf(nbuf
, sizeof(nbuf
), "%s[%s@%s]", target_p
->name
,
1039 target_p
->username
, target_p
->host
);
1045 return target_p
->name
;
1048 /* is_remote_connect - Returns whether a server was /connect'ed by a remote
1049 * oper (send notices netwide) */
1051 is_remote_connect(struct Client
*client_p
)
1053 struct Client
*oper
;
1055 if (client_p
->serv
== NULL
)
1057 oper
= find_named_person(client_p
->serv
->by
);
1058 return oper
!= NULL
&& IsOper(oper
) && !MyConnect(oper
);
1062 free_exited_clients(void *unused
)
1064 rb_dlink_node
*ptr
, *next
;
1065 struct Client
*target_p
;
1067 RB_DLINK_FOREACH_SAFE(ptr
, next
, dead_list
.head
)
1069 target_p
= ptr
->data
;
1071 #ifdef DEBUG_EXITED_CLIENTS
1073 struct abort_client
*abt
;
1074 rb_dlink_node
*aptr
;
1077 RB_DLINK_FOREACH(aptr
, abort_list
.head
)
1080 if(abt
->client
== target_p
)
1083 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1084 "On abort_list: %s stat: %u flags: %llu handler: %c",
1085 target_p
->name
, (unsigned int) target_p
->status
,
1086 (unsigned long long)target_p
->flags
, target_p
->handler
);
1087 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1088 "Please report this to the charybdis developers!");
1095 rb_dlinkDestroy(ptr
, &dead_list
);
1101 if(ptr
->data
== NULL
)
1103 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1104 "Warning: null client on dead_list!");
1105 rb_dlinkDestroy(ptr
, &dead_list
);
1108 release_client_state(target_p
);
1109 free_client(target_p
);
1110 rb_dlinkDestroy(ptr
, &dead_list
);
1113 #ifdef DEBUG_EXITED_CLIENTS
1114 RB_DLINK_FOREACH_SAFE(ptr
, next
, dead_remote_list
.head
)
1116 target_p
= ptr
->data
;
1118 if(ptr
->data
== NULL
)
1120 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1121 "Warning: null client on dead_list!");
1122 rb_dlinkDestroy(ptr
, &dead_list
);
1125 release_client_state(target_p
);
1126 free_client(target_p
);
1127 rb_dlinkDestroy(ptr
, &dead_remote_list
);
1134 ** Remove all clients that depend on source_p; assumes all (S)QUITs have
1135 ** already been sent. we make sure to exit a server's dependent clients
1136 ** and servers before the server itself; exit_one_client takes care of
1137 ** actually removing things off llists. tweaked from +CSr31 -orabidoo
1140 * added sanity test code.... source_p->serv might be NULL...
1143 recurse_remove_clients(struct Client
*source_p
, const char *comment
)
1145 struct Client
*target_p
;
1146 rb_dlink_node
*ptr
, *ptr_next
;
1151 if(source_p
->serv
== NULL
) /* oooops. uh this is actually a major bug */
1154 /* this is very ugly, but it saves cpu :P */
1155 if(ConfigFileEntry
.nick_delay
> 0)
1157 RB_DLINK_FOREACH_SAFE(ptr
, ptr_next
, source_p
->serv
->users
.head
)
1159 target_p
= ptr
->data
;
1160 target_p
->flags
|= FLAGS_KILLED
;
1161 add_nd_entry(target_p
->name
);
1163 if(!IsDead(target_p
) && !IsClosing(target_p
))
1164 exit_remote_client(NULL
, target_p
, &me
, comment
);
1169 RB_DLINK_FOREACH_SAFE(ptr
, ptr_next
, source_p
->serv
->users
.head
)
1171 target_p
= ptr
->data
;
1172 target_p
->flags
|= FLAGS_KILLED
;
1174 if(!IsDead(target_p
) && !IsClosing(target_p
))
1175 exit_remote_client(NULL
, target_p
, &me
, comment
);
1179 RB_DLINK_FOREACH_SAFE(ptr
, ptr_next
, source_p
->serv
->servers
.head
)
1181 target_p
= ptr
->data
;
1182 recurse_remove_clients(target_p
, comment
);
1183 qs_server(NULL
, target_p
, &me
, comment
);
1188 ** Remove *everything* that depends on source_p, from all lists, and sending
1189 ** all necessary SQUITs. source_p itself is still on the lists,
1190 ** and its SQUITs have been sent except for the upstream one -orabidoo
1193 remove_dependents(struct Client
*client_p
,
1194 struct Client
*source_p
,
1195 struct Client
*from
, const char *comment
, const char *comment1
)
1198 rb_dlink_node
*ptr
, *next
;
1200 RB_DLINK_FOREACH_SAFE(ptr
, next
, serv_list
.head
)
1204 if(IsMe(to
) || to
== source_p
->from
|| to
== client_p
)
1207 sendto_one(to
, "SQUIT %s :%s", get_id(source_p
, to
), comment
);
1210 recurse_remove_clients(source_p
, comment1
);
1214 exit_aborted_clients(void *unused
)
1216 struct abort_client
*abt
;
1217 rb_dlink_node
*ptr
, *next
;
1218 RB_DLINK_FOREACH_SAFE(ptr
, next
, abort_list
.head
)
1222 #ifdef DEBUG_EXITED_CLIENTS
1224 if(rb_dlinkFind(abt
->client
, &dead_list
))
1227 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1228 "On dead_list: %s stat: %u flags: %llu handler: %c",
1229 abt
->client
->name
, (unsigned int) abt
->client
->status
,
1230 (unsigned long long)abt
->client
->flags
, abt
->client
->handler
);
1231 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1232 "Please report this to the charybdis developers!");
1238 s_assert(*((unsigned long*)abt
->client
) != 0xdeadbeef); /* This is lame but its a debug thing */
1239 rb_dlinkDelete(ptr
, &abort_list
);
1241 if(IsAnyServer(abt
->client
))
1242 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1243 "Closing link to %s: %s",
1244 abt
->client
->name
, abt
->notice
);
1246 /* its no longer on abort list - we *must* remove
1247 * FLAGS_CLOSING otherwise exit_client() will not run --fl
1249 abt
->client
->flags
&= ~FLAGS_CLOSING
;
1250 exit_client(abt
->client
, abt
->client
, &me
, abt
->notice
);
1257 * dead_link - Adds client to a list of clients that need an exit_client()
1260 dead_link(struct Client
*client_p
, int sendqex
)
1262 struct abort_client
*abt
;
1264 s_assert(!IsMe(client_p
));
1265 if(IsDead(client_p
) || IsClosing(client_p
) || IsMe(client_p
))
1268 abt
= (struct abort_client
*) rb_malloc(sizeof(struct abort_client
));
1271 rb_strlcpy(abt
->notice
, "Max SendQ exceeded", sizeof(abt
->notice
));
1273 snprintf(abt
->notice
, sizeof(abt
->notice
), "Write error: %s", strerror(errno
));
1275 abt
->client
= client_p
;
1276 SetIOError(client_p
);
1278 SetClosing(client_p
);
1279 rb_dlinkAdd(abt
, &abt
->node
, &abort_list
);
1283 /* This does the remove of the user from channels..local or remote */
1285 exit_generic_client(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1286 const char *comment
)
1288 rb_dlink_node
*ptr
, *next_ptr
;
1290 if(IsOper(source_p
))
1291 rb_dlinkFindDestroy(source_p
, &oper_list
);
1293 sendto_common_channels_local(source_p
, NOCAPS
, NOCAPS
, ":%s!%s@%s QUIT :%s",
1295 source_p
->username
, source_p
->host
, comment
);
1297 remove_user_from_channels(source_p
);
1299 /* Should not be in any channels now */
1300 s_assert(source_p
->user
->channel
.head
== NULL
);
1302 /* Clean up invitefield */
1303 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, source_p
->user
->invited
.head
)
1305 del_invite(ptr
->data
, source_p
);
1308 /* Clean up allow lists */
1309 del_all_accepts(source_p
);
1311 whowas_add_history(source_p
, 0);
1312 whowas_off_history(source_p
);
1314 monitor_signoff(source_p
);
1316 if(has_id(source_p
))
1317 del_from_id_hash(source_p
->id
, source_p
);
1319 del_from_hostname_hash(source_p
->orighost
, source_p
);
1320 del_from_client_hash(source_p
->name
, source_p
);
1321 remove_client_from_list(source_p
);
1325 * Assumes IsPerson(source_p) && !MyConnect(source_p)
1329 exit_remote_client(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1330 const char *comment
)
1332 exit_generic_client(client_p
, source_p
, from
, comment
);
1334 if(source_p
->servptr
&& source_p
->servptr
->serv
)
1336 rb_dlinkDelete(&source_p
->lnode
, &source_p
->servptr
->serv
->users
);
1339 if((source_p
->flags
& FLAGS_KILLED
) == 0)
1341 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
,
1342 ":%s QUIT :%s", use_id(source_p
), comment
);
1346 #ifdef DEBUG_EXITED_CLIENTS
1347 rb_dlinkAddAlloc(source_p
, &dead_remote_list
);
1349 rb_dlinkAddAlloc(source_p
, &dead_list
);
1351 return(CLIENT_EXITED
);
1355 * This assumes IsUnknown(source_p) == true and MyConnect(source_p) == true
1359 exit_unknown_client(struct Client
*client_p
, /* The local client originating the
1360 * exit or NULL, if this exit is
1361 * generated by this server for
1363 * This will not get any of the
1364 * generated messages. */
1365 struct Client
*source_p
, /* Client exiting */
1366 struct Client
*from
, /* Client firing off this Exit,
1368 const char *comment
)
1370 authd_abort_client(source_p
);
1371 rb_dlinkDelete(&source_p
->localClient
->tnode
, &unknown_list
);
1373 if(!IsIOError(source_p
))
1374 sendto_one(source_p
, "ERROR :Closing Link: %s (%s)",
1375 source_p
->user
!= NULL
? source_p
->host
: "127.0.0.1",
1378 close_connection(source_p
);
1380 if(has_id(source_p
))
1381 del_from_id_hash(source_p
->id
, source_p
);
1383 del_from_hostname_hash(source_p
->host
, source_p
);
1384 del_from_client_hash(source_p
->name
, source_p
);
1385 remove_client_from_list(source_p
);
1387 rb_dlinkAddAlloc(source_p
, &dead_list
);
1389 /* Note that we don't need to add unknowns to the dead_list */
1390 return(CLIENT_EXITED
);
1394 exit_remote_server(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1395 const char *comment
)
1397 static char comment1
[(HOSTLEN
*2)+2];
1398 static char newcomment
[BUFSIZE
];
1399 struct Client
*target_p
;
1401 if(ConfigServerHide
.flatten_links
)
1402 strcpy(comment1
, "*.net *.split");
1405 strcpy(comment1
, source_p
->servptr
->name
);
1406 strcat(comment1
, " ");
1407 strcat(comment1
, source_p
->name
);
1410 snprintf(newcomment
, sizeof(newcomment
), "by %s: %s",
1411 from
->name
, comment
);
1413 if(source_p
->serv
!= NULL
)
1414 remove_dependents(client_p
, source_p
, from
, IsPerson(from
) ? newcomment
: comment
, comment1
);
1416 if(source_p
->servptr
&& source_p
->servptr
->serv
)
1417 rb_dlinkDelete(&source_p
->lnode
, &source_p
->servptr
->serv
->servers
);
1421 rb_dlinkFindDestroy(source_p
, &global_serv_list
);
1422 target_p
= source_p
->from
;
1424 if(target_p
!= NULL
&& IsServer(target_p
) && target_p
!= client_p
&&
1425 !IsMe(target_p
) && (source_p
->flags
& FLAGS_KILLED
) == 0)
1427 sendto_one(target_p
, ":%s SQUIT %s :%s",
1428 get_id(from
, target_p
), get_id(source_p
, target_p
),
1432 if(has_id(source_p
))
1433 del_from_id_hash(source_p
->id
, source_p
);
1435 del_from_client_hash(source_p
->name
, source_p
);
1436 remove_client_from_list(source_p
);
1437 scache_split(source_p
->serv
->nameinfo
);
1440 #ifdef DEBUG_EXITED_CLIENTS
1441 rb_dlinkAddAlloc(source_p
, &dead_remote_list
);
1443 rb_dlinkAddAlloc(source_p
, &dead_list
);
1449 qs_server(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1450 const char *comment
)
1452 if(source_p
->servptr
&& source_p
->servptr
->serv
)
1453 rb_dlinkDelete(&source_p
->lnode
, &source_p
->servptr
->serv
->servers
);
1457 rb_dlinkFindDestroy(source_p
, &global_serv_list
);
1459 if(has_id(source_p
))
1460 del_from_id_hash(source_p
->id
, source_p
);
1462 del_from_client_hash(source_p
->name
, source_p
);
1463 remove_client_from_list(source_p
);
1464 scache_split(source_p
->serv
->nameinfo
);
1467 rb_dlinkAddAlloc(source_p
, &dead_list
);
1472 exit_local_server(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1473 const char *comment
)
1475 static char comment1
[(HOSTLEN
*2)+2];
1476 static char newcomment
[BUFSIZE
];
1477 unsigned int sendk
, recvk
;
1479 rb_dlinkDelete(&source_p
->localClient
->tnode
, &serv_list
);
1480 rb_dlinkFindDestroy(source_p
, &global_serv_list
);
1482 sendk
= source_p
->localClient
->sendK
;
1483 recvk
= source_p
->localClient
->receiveK
;
1485 /* Always show source here, so the server notices show
1486 * which side initiated the split -- jilles
1488 snprintf(newcomment
, sizeof(newcomment
), "by %s: %s",
1489 from
== source_p
? me
.name
: from
->name
, comment
);
1490 if (!IsIOError(source_p
))
1491 sendto_one(source_p
, "SQUIT %s :%s", use_id(source_p
),
1493 if(client_p
!= NULL
&& source_p
!= client_p
&& !IsIOError(source_p
))
1495 sendto_one(source_p
, "ERROR :Closing Link: 127.0.0.1 %s (%s)",
1496 source_p
->name
, comment
);
1499 if(source_p
->servptr
&& source_p
->servptr
->serv
)
1500 rb_dlinkDelete(&source_p
->lnode
, &source_p
->servptr
->serv
->servers
);
1505 close_connection(source_p
);
1507 if(ConfigServerHide
.flatten_links
)
1508 strcpy(comment1
, "*.net *.split");
1511 strcpy(comment1
, source_p
->servptr
->name
);
1512 strcat(comment1
, " ");
1513 strcat(comment1
, source_p
->name
);
1516 if(source_p
->serv
!= NULL
)
1517 remove_dependents(client_p
, source_p
, from
, IsPerson(from
) ? newcomment
: comment
, comment1
);
1519 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s was connected"
1520 " for %ld seconds. %d/%d sendK/recvK.",
1521 source_p
->name
, (long) rb_current_time() - source_p
->localClient
->firsttime
, sendk
, recvk
);
1523 ilog(L_SERVER
, "%s was connected for %ld seconds. %d/%d sendK/recvK.",
1524 source_p
->name
, (long) rb_current_time() - source_p
->localClient
->firsttime
, sendk
, recvk
);
1526 if(has_id(source_p
))
1527 del_from_id_hash(source_p
->id
, source_p
);
1529 del_from_client_hash(source_p
->name
, source_p
);
1530 remove_client_from_list(source_p
);
1531 scache_split(source_p
->serv
->nameinfo
);
1534 rb_dlinkAddAlloc(source_p
, &dead_list
);
1540 * This assumes IsPerson(source_p) == true && MyConnect(source_p) == true
1544 exit_local_client(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1545 const char *comment
)
1547 unsigned long on_for
;
1550 exit_generic_client(client_p
, source_p
, from
, comment
);
1551 clear_monitor(source_p
);
1553 s_assert(IsPerson(source_p
));
1554 rb_dlinkDelete(&source_p
->localClient
->tnode
, &lclient_list
);
1555 rb_dlinkDelete(&source_p
->lnode
, &me
.serv
->users
);
1557 if(IsOper(source_p
))
1558 rb_dlinkFindDestroy(source_p
, &local_oper_list
);
1560 sendto_realops_snomask(SNO_CCONN
, L_ALL
,
1561 "Client exiting: %s (%s@%s) [%s] [%s]",
1563 source_p
->username
, source_p
->host
, comment
,
1564 show_ip(NULL
, source_p
) ? source_p
->sockhost
: "255.255.255.255");
1566 sendto_realops_snomask(SNO_CCONNEXT
, L_ALL
,
1567 "CLIEXIT %s %s %s %s 0 %s",
1568 source_p
->name
, source_p
->username
, source_p
->host
,
1569 show_ip(NULL
, source_p
) ? source_p
->sockhost
: "255.255.255.255",
1572 on_for
= rb_current_time() - source_p
->localClient
->firsttime
;
1574 ilog(L_USER
, "%s (%3lu:%02lu:%02lu): %s!%s@%s %s %d/%d",
1575 rb_ctime(rb_current_time(), tbuf
, sizeof(tbuf
)), on_for
/ 3600,
1576 (on_for
% 3600) / 60, on_for
% 60,
1577 source_p
->name
, source_p
->username
, source_p
->host
,
1579 source_p
->localClient
->sendK
, source_p
->localClient
->receiveK
);
1581 sendto_one(source_p
, "ERROR :Closing Link: %s (%s)", source_p
->host
, comment
);
1582 close_connection(source_p
);
1584 if((source_p
->flags
& FLAGS_KILLED
) == 0)
1586 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
,
1587 ":%s QUIT :%s", use_id(source_p
), comment
);
1591 rb_dlinkAddAlloc(source_p
, &dead_list
);
1592 return(CLIENT_EXITED
);
1597 ** exit_client - This is old "m_bye". Name changed, because this is not a
1598 ** protocol function, but a general server utility function.
1600 ** This function exits a client of *any* type (user, server, etc)
1601 ** from this server. Also, this generates all necessary prototol
1602 ** messages that this exit may cause.
1604 ** 1) If the client is a local client, then this implicitly
1605 ** exits all other clients depending on this connection (e.g.
1606 ** remote clients having 'from'-field that points to this.
1608 ** 2) If the client is a remote client, then only this is exited.
1610 ** For convenience, this function returns a suitable value for
1611 ** m_function return value:
1613 ** CLIENT_EXITED if (client_p == source_p)
1614 ** 0 if (client_p != source_p)
1617 exit_client(struct Client
*client_p
, /* The local client originating the
1618 * exit or NULL, if this exit is
1619 * generated by this server for
1621 * This will not get any of the
1622 * generated messages. */
1623 struct Client
*source_p
, /* Client exiting */
1624 struct Client
*from
, /* Client firing off this Exit,
1626 const char *comment
/* Reason for the exit */
1629 hook_data_client_exit hdata
;
1630 if(IsClosing(source_p
))
1633 /* note, this HAS to be here, when we exit a client we attempt to
1634 * send them data, if this generates a write error we must *not* add
1635 * them to the abort list --fl
1637 SetClosing(source_p
);
1639 hdata
.local_link
= client_p
;
1640 hdata
.target
= source_p
;
1642 hdata
.comment
= comment
;
1643 call_hook(h_client_exit
, &hdata
);
1645 if(MyConnect(source_p
))
1647 /* Local clients of various types */
1648 if(IsPerson(source_p
))
1649 return exit_local_client(client_p
, source_p
, from
, comment
);
1650 else if(IsServer(source_p
))
1651 return exit_local_server(client_p
, source_p
, from
, comment
);
1652 /* IsUnknown || IsConnecting || IsHandShake */
1653 else if(!IsReject(source_p
))
1654 return exit_unknown_client(client_p
, source_p
, from
, comment
);
1659 if(IsPerson(source_p
))
1660 return exit_remote_client(client_p
, source_p
, from
, comment
);
1661 else if(IsServer(source_p
))
1662 return exit_remote_server(client_p
, source_p
, from
, comment
);
1669 * Count up local client memory
1672 /* XXX one common Client list now */
1674 count_local_client_memory(size_t * count
, size_t * local_client_memory_used
)
1677 rb_bh_usage(lclient_heap
, count
, NULL
, &lusage
, NULL
);
1678 *local_client_memory_used
= lusage
+ (*count
* (sizeof(void *) + sizeof(struct Client
)));
1682 * Count up remote client memory
1685 count_remote_client_memory(size_t * count
, size_t * remote_client_memory_used
)
1687 size_t lcount
, rcount
;
1688 rb_bh_usage(lclient_heap
, &lcount
, NULL
, NULL
, NULL
);
1689 rb_bh_usage(client_heap
, &rcount
, NULL
, NULL
, NULL
);
1690 *count
= rcount
- lcount
;
1691 *remote_client_memory_used
= *count
* (sizeof(void *) + sizeof(struct Client
));
1696 * accept processing, this adds a form of "caller ID" to ircd
1698 * If a client puts themselves into "caller ID only" mode,
1699 * only clients that match a client pointer they have put on
1700 * the accept list will be allowed to message them.
1702 * [ source.on_allow_list ] -> [ target1 ] -> [ target2 ]
1704 * [target.allow_list] -> [ source1 ] -> [source2 ]
1706 * i.e. a target will have a link list of source pointers it will allow
1707 * each source client then has a back pointer pointing back
1708 * to the client that has it on its accept list.
1709 * This allows for exit_one_client to remove these now bogus entries
1710 * from any client having an accept on them.
1715 * inputs - pointer to exiting client
1717 * side effects - Walk through given clients allow_list and on_allow_list
1718 * remove all references to this client
1721 del_all_accepts(struct Client
*client_p
)
1724 rb_dlink_node
*next_ptr
;
1725 struct Client
*target_p
;
1727 if(MyClient(client_p
) && client_p
->localClient
->allow_list
.head
)
1729 /* clear this clients accept list, and remove them from
1730 * everyones on_accept_list
1732 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, client_p
->localClient
->allow_list
.head
)
1734 target_p
= ptr
->data
;
1735 rb_dlinkFindDestroy(client_p
, &target_p
->on_allow_list
);
1736 rb_dlinkDestroy(ptr
, &client_p
->localClient
->allow_list
);
1740 /* remove this client from everyones accept list */
1741 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, client_p
->on_allow_list
.head
)
1743 target_p
= ptr
->data
;
1744 rb_dlinkFindDestroy(client_p
, &target_p
->localClient
->allow_list
);
1745 rb_dlinkDestroy(ptr
, &client_p
->on_allow_list
);
1750 * show_ip() - asks if the true IP should be shown when source is
1751 * asking for info about target
1753 * Inputs - source_p who is asking
1754 * - target_p who do we want the info on
1755 * Output - returns 1 if clear IP can be shown, otherwise 0
1756 * Side Effects - none
1760 show_ip(struct Client
*source_p
, struct Client
*target_p
)
1762 if(IsAnyServer(target_p
))
1766 else if(IsIPSpoof(target_p
))
1768 /* source == NULL indicates message is being sent
1771 if(!ConfigFileEntry
.hide_spoof_ips
&&
1772 (source_p
== NULL
|| MyOper(source_p
)))
1776 else if(IsDynSpoof(target_p
) && (source_p
!= NULL
&& !IsOper(source_p
)))
1783 show_ip_conf(struct ConfItem
*aconf
, struct Client
*source_p
)
1785 if(IsConfDoSpoofIp(aconf
))
1787 if(!ConfigFileEntry
.hide_spoof_ips
&& MyOper(source_p
))
1797 show_ip_whowas(struct Whowas
*whowas
, struct Client
*source_p
)
1799 if(whowas
->flags
& WHOWAS_IP_SPOOFING
)
1800 if(ConfigFileEntry
.hide_spoof_ips
|| !MyOper(source_p
))
1802 if(whowas
->flags
& WHOWAS_DYNSPOOF
)
1803 if(!IsOper(source_p
))
1811 * inputs - pointer to client struct
1812 * output - pointer to struct User
1813 * side effects - add's an User information block to a client
1814 * if it was not previously allocated.
1817 make_user(struct Client
*client_p
)
1821 user
= client_p
->user
;
1824 user
= (struct User
*) rb_bh_alloc(user_heap
);
1826 client_p
->user
= user
;
1834 * inputs - pointer to client struct
1835 * output - pointer to server_t
1836 * side effects - add's an Server information block to a client
1837 * if it was not previously allocated.
1840 make_server(struct Client
*client_p
)
1842 struct Server
*serv
= client_p
->serv
;
1846 serv
= (struct Server
*) rb_malloc(sizeof(struct Server
));
1847 client_p
->serv
= serv
;
1849 return client_p
->serv
;
1855 * inputs - pointer to user struct
1856 * - pointer to client struct
1858 * side effects - Decrease user reference count by one and release block,
1859 * if count reaches 0
1862 free_user(struct User
*user
, struct Client
*client_p
)
1864 free_away(client_p
);
1866 if(--user
->refcnt
<= 0)
1869 rb_free((char *) user
->away
);
1873 if(user
->refcnt
< 0 || user
->invited
.head
|| user
->channel
.head
)
1875 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1876 "* %p user (%s!%s@%s) %p %p %p %lu %d *",
1878 client_p
? client_p
->
1885 rb_dlink_list_length(&user
->channel
),
1887 s_assert(!user
->refcnt
);
1888 s_assert(!user
->invited
.head
);
1889 s_assert(!user
->channel
.head
);
1892 rb_bh_free(user_heap
, user
);
1897 allocate_away(struct Client
*client_p
)
1899 if(client_p
->user
->away
== NULL
)
1900 client_p
->user
->away
= rb_bh_alloc(away_heap
);
1905 free_away(struct Client
*client_p
)
1907 if(client_p
->user
!= NULL
&& client_p
->user
->away
!= NULL
) {
1908 rb_bh_free(away_heap
, client_p
->user
->away
);
1909 client_p
->user
->away
= NULL
;
1918 for(i
= 0; i
< 3; i
++)
1919 current_uid
[i
] = me
.id
[i
];
1921 for(i
= 3; i
< 9; i
++)
1922 current_uid
[i
] = 'A';
1924 current_uid
[9] = '\0';
1931 static int flipped
= 0;
1935 for(i
= 8; i
> 3; i
--)
1937 if(current_uid
[i
] == 'Z')
1939 current_uid
[i
] = '0';
1942 else if(current_uid
[i
] != '9')
1948 current_uid
[i
] = 'A';
1951 /* if this next if() triggers, we're fucked. */
1952 if(current_uid
[3] == 'Z')
1954 current_uid
[i
] = 'A';
1960 /* if this happens..well, i'm not sure what to say, but lets handle it correctly */
1961 if(rb_unlikely(flipped
))
1963 /* this slows down uid generation a bit... */
1964 if(find_id(current_uid
) != NULL
)
1972 * Close the physical connection. This function must make
1973 * MyConnect(client_p) == FALSE, and set client_p->from == NULL.
1976 close_connection(struct Client
*client_p
)
1978 s_assert(client_p
!= NULL
);
1979 if(client_p
== NULL
)
1982 s_assert(MyConnect(client_p
));
1983 if(!MyConnect(client_p
))
1986 if(IsServer(client_p
))
1988 struct server_conf
*server_p
;
1990 ServerStats
.is_sv
++;
1991 ServerStats
.is_sbs
+= client_p
->localClient
->sendB
;
1992 ServerStats
.is_sbr
+= client_p
->localClient
->receiveB
;
1993 ServerStats
.is_sti
+= (unsigned long long)(rb_current_time() - client_p
->localClient
->firsttime
);
1996 * If the connection has been up for a long amount of time, schedule
1997 * a 'quick' reconnect, else reset the next-connect cycle.
1999 if((server_p
= find_server_conf(client_p
->name
)) != NULL
)
2002 * Reschedule a faster reconnect, if this was a automatically
2003 * connected configuration entry. (Note that if we have had
2004 * a rehash in between, the status has been changed to
2005 * CONF_ILLEGAL). But only do this if it was a "good" link.
2007 server_p
->hold
= time(NULL
);
2009 (server_p
->hold
- client_p
->localClient
->lasttime
>
2010 HANGONGOODLINK
) ? HANGONRETRYDELAY
: ConFreq(server_p
->class);
2014 else if(IsClient(client_p
))
2016 ServerStats
.is_cl
++;
2017 ServerStats
.is_cbs
+= client_p
->localClient
->sendB
;
2018 ServerStats
.is_cbr
+= client_p
->localClient
->receiveB
;
2019 ServerStats
.is_cti
+= (unsigned long long)(rb_current_time() - client_p
->localClient
->firsttime
);
2022 ServerStats
.is_ni
++;
2024 client_release_connids(client_p
);
2026 if(client_p
->localClient
->F
!= NULL
)
2028 /* attempt to flush any pending dbufs. Evil, but .. -- adrian */
2029 if(!IsIOError(client_p
))
2030 send_queued(client_p
);
2032 rb_close(client_p
->localClient
->F
);
2033 client_p
->localClient
->F
= NULL
;
2036 rb_linebuf_donebuf(&client_p
->localClient
->buf_sendq
);
2037 rb_linebuf_donebuf(&client_p
->localClient
->buf_recvq
);
2038 detach_conf(client_p
);
2040 /* XXX shouldnt really be done here. */
2041 detach_server_conf(client_p
);
2043 client_p
->from
= NULL
; /* ...this should catch them! >:) --msa */
2044 ClearMyConnect(client_p
);
2045 SetIOError(client_p
);
2051 error_exit_client(struct Client
*client_p
, int error
)
2054 * ...hmm, with non-blocking sockets we might get
2055 * here from quite valid reasons, although.. why
2056 * would select report "data available" when there
2057 * wasn't... so, this must be an error anyway... --msa
2058 * actually, EOF occurs when read() returns 0 and
2059 * in due course, select() returns that fd as ready
2060 * for reading even though it ends up being an EOF. -avalon
2063 int current_error
= rb_get_sockerr(client_p
->localClient
->F
);
2065 SetIOError(client_p
);
2067 if(IsServer(client_p
) || IsHandshake(client_p
))
2071 sendto_realops_snomask(SNO_GENERAL
, is_remote_connect(client_p
) && !IsServer(client_p
) ? L_NETWIDE
: L_ALL
,
2072 "Server %s closed the connection",
2075 ilog(L_SERVER
, "Server %s closed the connection",
2076 log_client_name(client_p
, SHOW_IP
));
2080 sendto_realops_snomask(SNO_GENERAL
, is_remote_connect(client_p
) && !IsServer(client_p
) ? L_NETWIDE
: L_ALL
,
2081 "Lost connection to %s: %s",
2082 client_p
->name
, strerror(current_error
));
2083 ilog(L_SERVER
, "Lost connection to %s: %s",
2084 log_client_name(client_p
, SHOW_IP
), strerror(current_error
));
2089 rb_strlcpy(errmsg
, "Remote host closed the connection", sizeof(errmsg
));
2091 snprintf(errmsg
, sizeof(errmsg
), "Read error: %s", strerror(current_error
));
2093 exit_client(client_p
, client_p
, &me
, errmsg
);