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"
56 #define DEBUG_EXITED_CLIENTS
58 static void check_pings_list(rb_dlink_list
* list
);
59 static void check_unknowns_list(rb_dlink_list
* list
);
60 static void free_exited_clients(void *unused
);
61 static void exit_aborted_clients(void *unused
);
63 static int exit_remote_client(struct Client
*, struct Client
*, struct Client
*,const char *);
64 static int exit_remote_server(struct Client
*, struct Client
*, struct Client
*,const char *);
65 static int exit_local_client(struct Client
*, struct Client
*, struct Client
*,const char *);
66 static int exit_unknown_client(struct Client
*, struct Client
*, struct Client
*,const char *);
67 static int exit_local_server(struct Client
*, struct Client
*, struct Client
*,const char *);
68 static int qs_server(struct Client
*, struct Client
*, struct Client
*, const char *comment
);
70 static EVH check_pings
;
72 static rb_bh
*client_heap
= NULL
;
73 static rb_bh
*lclient_heap
= NULL
;
74 static rb_bh
*pclient_heap
= NULL
;
75 static rb_bh
*user_heap
= NULL
;
76 static rb_bh
*away_heap
= NULL
;
77 static char current_uid
[IDLEN
];
78 static uint32_t current_connid
= 0;
80 rb_dictionary
*nd_dict
= NULL
;
88 rb_dlink_list dead_list
;
89 #ifdef DEBUG_EXITED_CLIENTS
90 static rb_dlink_list dead_remote_list
;
96 struct Client
*client
;
97 char notice
[REASONLEN
];
100 static rb_dlink_list abort_list
;
108 * side effects - initialize client free memory
114 * start off the check ping event .. -- adrian
115 * Every 30 seconds is plenty -- db
117 client_heap
= rb_bh_create(sizeof(struct Client
), CLIENT_HEAP_SIZE
, "client_heap");
118 lclient_heap
= rb_bh_create(sizeof(struct LocalUser
), LCLIENT_HEAP_SIZE
, "lclient_heap");
119 pclient_heap
= rb_bh_create(sizeof(struct PreClient
), PCLIENT_HEAP_SIZE
, "pclient_heap");
120 user_heap
= rb_bh_create(sizeof(struct User
), USER_HEAP_SIZE
, "user_heap");
121 away_heap
= rb_bh_create(AWAYLEN
, AWAY_HEAP_SIZE
, "away_heap");
123 rb_event_addish("check_pings", check_pings
, NULL
, 30);
124 rb_event_addish("free_exited_clients", &free_exited_clients
, NULL
, 4);
125 rb_event_addish("exit_aborted_clients", exit_aborted_clients
, NULL
, 1);
126 rb_event_add("flood_recalc", flood_recalc
, NULL
, 1);
128 nd_dict
= rb_dictionary_create("nickdelay", irccmp
);
132 * connid_get - allocate a connid
135 * outputs - a connid token which is used to represent a logical circuit
136 * side effects - current_connid is incremented, possibly multiple times.
137 * the association of the connid to it's client is committed.
140 connid_get(struct Client
*client_p
)
142 s_assert(MyClient(client_p
));
143 if (!MyClient(client_p
))
146 /* find a connid that is available */
147 while (find_cli_connid_hash(++current_connid
) != NULL
)
149 /* handle wraparound, current_connid must NEVER be 0 */
150 if (current_connid
== 0)
154 add_to_cli_connid_hash(client_p
, current_connid
);
155 rb_dlinkAddAlloc(RB_UINT_TO_POINTER(current_connid
), &client_p
->localClient
->connids
);
157 return current_connid
;
161 * connid_put - free a connid
163 * inputs - connid to free
165 * side effects - connid bookkeeping structures are freed
168 connid_put(uint32_t id
)
170 struct Client
*client_p
;
176 client_p
= find_cli_connid_hash(id
);
177 if (client_p
== NULL
)
180 del_from_cli_connid_hash(id
);
181 rb_dlinkFindDestroy(RB_UINT_TO_POINTER(id
), &client_p
->localClient
->connids
);
185 * client_release_connids - release any connids still attached to a client
187 * inputs - client to garbage collect
189 * side effects - client's connids are garbage collected
192 client_release_connids(struct Client
*client_p
)
194 rb_dlink_node
*ptr
, *ptr2
;
196 s_assert(MyClient(client_p
));
197 if (!MyClient(client_p
))
200 RB_DLINK_FOREACH_SAFE(ptr
, ptr2
, client_p
->localClient
->connids
.head
)
201 connid_put(RB_POINTER_TO_UINT(ptr
->data
));
205 * make_client - create a new Client struct and set it to initial state.
207 * from == NULL, create local client (a client connected
210 * from, create remote client (behind a socket
211 * associated with the client defined by
212 * 'from'). ('from' is a local client!!).
215 make_client(struct Client
*from
)
217 struct Client
*client_p
= NULL
;
218 struct LocalUser
*localClient
;
220 client_p
= rb_bh_alloc(client_heap
);
224 client_p
->from
= client_p
; /* 'from' of local client is self! */
226 localClient
= rb_bh_alloc(lclient_heap
);
227 SetMyConnect(client_p
);
228 client_p
->localClient
= localClient
;
230 client_p
->localClient
->lasttime
= client_p
->localClient
->firsttime
= rb_current_time();
232 client_p
->localClient
->F
= NULL
;
234 client_p
->preClient
= rb_bh_alloc(pclient_heap
);
236 /* as good a place as any... */
237 rb_dlinkAdd(client_p
, &client_p
->localClient
->tnode
, &unknown_list
);
240 { /* from is not NULL */
241 client_p
->localClient
= NULL
;
242 client_p
->preClient
= NULL
;
243 client_p
->from
= from
; /* 'from' of local client is self! */
246 SetUnknown(client_p
);
247 strcpy(client_p
->username
, "unknown");
253 free_pre_client(struct Client
*client_p
)
255 s_assert(NULL
!= client_p
);
257 if(client_p
->preClient
== NULL
)
260 s_assert(client_p
->preClient
->authd_cid
== 0);
262 rb_free(client_p
->preClient
->authd_data
);
263 rb_free(client_p
->preClient
->authd_reason
);
265 rb_bh_free(pclient_heap
, client_p
->preClient
);
266 client_p
->preClient
= NULL
;
270 free_local_client(struct Client
*client_p
)
272 s_assert(NULL
!= client_p
);
273 s_assert(&me
!= client_p
);
275 if(client_p
->localClient
== NULL
)
279 * clean up extra sockets from P-lines which have been discarded.
281 if(client_p
->localClient
->listener
)
283 s_assert(0 < client_p
->localClient
->listener
->ref_count
);
284 if(0 == --client_p
->localClient
->listener
->ref_count
285 && !client_p
->localClient
->listener
->active
)
286 free_listener(client_p
->localClient
->listener
);
287 client_p
->localClient
->listener
= 0;
290 client_release_connids(client_p
);
291 if(client_p
->localClient
->F
!= NULL
)
293 rb_close(client_p
->localClient
->F
);
296 if(client_p
->localClient
->passwd
)
298 memset(client_p
->localClient
->passwd
, 0,
299 strlen(client_p
->localClient
->passwd
));
300 rb_free(client_p
->localClient
->passwd
);
303 rb_free(client_p
->localClient
->auth_user
);
304 rb_free(client_p
->localClient
->challenge
);
305 rb_free(client_p
->localClient
->fullcaps
);
306 rb_free(client_p
->localClient
->opername
);
307 rb_free(client_p
->localClient
->mangledhost
);
308 if (client_p
->localClient
->privset
)
309 privilegeset_unref(client_p
->localClient
->privset
);
312 ssld_decrement_clicount(client_p
->localClient
->ssl_ctl
);
314 if(IsCapable(client_p
, CAP_ZIP
))
315 ssld_decrement_clicount(client_p
->localClient
->z_ctl
);
317 rb_bh_free(lclient_heap
, client_p
->localClient
);
318 client_p
->localClient
= NULL
;
322 free_client(struct Client
*client_p
)
324 s_assert(NULL
!= client_p
);
325 s_assert(&me
!= client_p
);
326 free_local_client(client_p
);
327 free_pre_client(client_p
);
328 rb_free(client_p
->certfp
);
329 rb_bh_free(client_heap
, client_p
);
333 * check_pings - go through the local client list and check activity
334 * kill off stuff that should die
336 * inputs - NOT USED (from event)
337 * output - next time_t when check_pings() should be called again
341 * A PING can be sent to clients as necessary.
343 * Client/Server ping outs are handled.
347 * Addon from adrian. We used to call this after nextping seconds,
348 * however I've changed it to run once a second. This is only for
349 * PING timeouts, not K/etc-line checks (thanks dianora!). Having it
350 * run once a second makes life a lot easier - when a new client connects
351 * and they need a ping in 4 seconds, if nextping was set to 20 seconds
352 * we end up waiting 20 seconds. This is stupid. :-)
353 * I will optimise (hah!) check_pings() once I've finished working on
354 * tidying up other network IO evilnesses.
359 check_pings(void *notused
)
361 check_pings_list(&lclient_list
);
362 check_pings_list(&serv_list
);
363 check_unknowns_list(&unknown_list
);
369 * inputs - pointer to list to check
374 check_pings_list(rb_dlink_list
* list
)
376 char scratch
[32]; /* way too generous but... */
377 struct Client
*client_p
; /* current local client_p being examined */
378 int ping
= 0; /* ping time value from client */
379 rb_dlink_node
*ptr
, *next_ptr
;
381 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, list
->head
)
383 client_p
= ptr
->data
;
385 if(!MyConnect(client_p
) || IsDead(client_p
))
388 ping
= get_client_ping(client_p
);
390 if(ping
< (rb_current_time() - client_p
->localClient
->lasttime
))
393 * If the client/server hasnt talked to us in 2*ping seconds
394 * and it has a ping time, then close its connection.
396 if(((rb_current_time() - client_p
->localClient
->lasttime
) >= (2 * ping
)
397 && (client_p
->flags
& FLAGS_PINGSENT
)))
399 if(IsServer(client_p
))
401 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
402 "No response from %s, closing link",
405 "No response from %s, closing link",
406 log_client_name(client_p
, HIDE_IP
));
408 (void) snprintf(scratch
, sizeof(scratch
),
409 "Ping timeout: %d seconds",
410 (int) (rb_current_time() - client_p
->localClient
->lasttime
));
412 exit_client(client_p
, client_p
, &me
, scratch
);
415 else if((client_p
->flags
& FLAGS_PINGSENT
) == 0)
418 * if we havent PINGed the connection and we havent
419 * heard from it in a while, PING it to make sure
422 client_p
->flags
|= FLAGS_PINGSENT
;
423 /* not nice but does the job */
424 client_p
->localClient
->lasttime
= rb_current_time() - ping
;
425 sendto_one(client_p
, "PING :%s", me
.name
);
434 * check_unknowns_list
436 * inputs - pointer to list of unknown clients
438 * side effects - unknown clients get marked for termination after n seconds
441 check_unknowns_list(rb_dlink_list
* list
)
443 rb_dlink_node
*ptr
, *next_ptr
;
444 struct Client
*client_p
;
447 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, list
->head
)
449 client_p
= ptr
->data
;
451 if(IsDead(client_p
) || IsClosing(client_p
))
454 /* Still querying with authd */
455 if(client_p
->preClient
!= NULL
&& client_p
->preClient
->authd_cid
!= 0)
459 * Check UNKNOWN connections - if they have been in this state
460 * for > 30s, close them.
463 timeout
= IsAnyServer(client_p
) ? ConfigFileEntry
.connect_timeout
: 30;
464 if((rb_current_time() - client_p
->localClient
->firsttime
) > timeout
)
466 if(IsAnyServer(client_p
))
468 sendto_realops_snomask(SNO_GENERAL
, is_remote_connect(client_p
) ? L_NETWIDE
: L_ALL
,
469 "No response from %s, closing link",
472 "No response from %s, closing link",
473 log_client_name(client_p
, HIDE_IP
));
475 exit_client(client_p
, client_p
, &me
, "Connection timed out");
481 notify_banned_client(struct Client
*client_p
, struct ConfItem
*aconf
, int ban
)
483 static const char conn_closed
[] = "Connection closed";
484 static const char d_lined
[] = "D-lined";
485 static const char k_lined
[] = "K-lined";
486 const char *reason
= NULL
;
487 const char *exit_reason
= conn_closed
;
489 if(ConfigFileEntry
.kline_with_reason
)
491 reason
= get_user_ban_reason(aconf
);
492 exit_reason
= reason
;
496 reason
= aconf
->status
== D_LINED
? d_lined
: k_lined
;
499 if(ban
== D_LINED
&& !IsPerson(client_p
))
500 sendto_one(client_p
, "NOTICE DLINE :*** You have been D-lined");
502 sendto_one(client_p
, form_str(ERR_YOUREBANNEDCREEP
),
503 me
.name
, client_p
->name
, reason
);
505 exit_client(client_p
, client_p
, &me
,
506 EmptyString(ConfigFileEntry
.kline_reason
) ? exit_reason
:
507 ConfigFileEntry
.kline_reason
);
514 * side effects - Check all connections for a pending k/dline against the
515 * client, exit the client if found.
518 check_banned_lines(void)
525 /* check_klines_event()
529 * side effects - check_klines() is called, kline_queued unset
532 check_klines_event(void *unused
)
534 kline_queued
= false;
542 * side effects - all clients will be checked for klines
547 struct Client
*client_p
;
548 struct ConfItem
*aconf
;
550 rb_dlink_node
*next_ptr
;
552 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
554 client_p
= ptr
->data
;
556 if(IsMe(client_p
) || !IsPerson(client_p
))
559 if((aconf
= find_kline(client_p
)) != NULL
)
561 if(IsExemptKline(client_p
))
563 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
564 "KLINE over-ruled for %s, client is kline_exempt [%s@%s]",
565 get_client_name(client_p
, HIDE_IP
),
566 aconf
->user
, aconf
->host
);
570 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
571 "KLINE active for %s",
572 get_client_name(client_p
, HIDE_IP
));
574 notify_banned_client(client_p
, aconf
, K_LINED
);
584 * side effects - all clients will be checked for dlines
589 struct Client
*client_p
;
590 struct ConfItem
*aconf
;
592 rb_dlink_node
*next_ptr
;
594 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
596 client_p
= ptr
->data
;
601 if((aconf
= find_dline((struct sockaddr
*)&client_p
->localClient
->ip
, GET_SS_FAMILY(&client_p
->localClient
->ip
))) != NULL
)
603 if(aconf
->status
& CONF_EXEMPTDLINE
)
606 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
607 "DLINE active for %s",
608 get_client_name(client_p
, HIDE_IP
));
610 notify_banned_client(client_p
, aconf
, D_LINED
);
615 /* dlines need to be checked against unknowns too */
616 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, unknown_list
.head
)
618 client_p
= ptr
->data
;
620 if((aconf
= find_dline((struct sockaddr
*)&client_p
->localClient
->ip
, GET_SS_FAMILY(&client_p
->localClient
->ip
))) != NULL
)
622 if(aconf
->status
& CONF_EXEMPTDLINE
)
625 notify_banned_client(client_p
, aconf
, D_LINED
);
634 * side effects - all clients will be checked for xlines
639 struct Client
*client_p
;
640 struct ConfItem
*aconf
;
642 rb_dlink_node
*next_ptr
;
644 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
646 client_p
= ptr
->data
;
648 if(IsMe(client_p
) || !IsPerson(client_p
))
651 if((aconf
= find_xline(client_p
->info
, 1)) != NULL
)
653 if(IsExemptKline(client_p
))
655 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
656 "XLINE over-ruled for %s, client is kline_exempt [%s]",
657 get_client_name(client_p
, HIDE_IP
),
662 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "XLINE active for %s",
663 get_client_name(client_p
, HIDE_IP
));
665 (void) exit_client(client_p
, client_p
, &me
, "Bad user info");
673 * inputs - resv, reason, time
675 * side effects - all local clients matching resv will be FNC'd
678 resv_nick_fnc(const char *mask
, const char *reason
, int temp_time
)
680 struct Client
*client_p
, *target_p
;
682 rb_dlink_node
*next_ptr
;
684 char note
[NICKLEN
+10];
686 if (!ConfigFileEntry
.resv_fnc
)
689 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, lclient_list
.head
)
691 client_p
= ptr
->data
;
693 if(IsMe(client_p
) || !IsPerson(client_p
) || IsExemptResv(client_p
))
696 /* Skip users that already have UID nicks. */
697 if(IsDigit(client_p
->name
[0]))
700 if(match_esc(mask
, client_p
->name
))
705 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
706 "RESV forced nick change for %s!%s@%s to %s; nick matched [%s] (%s)",
707 client_p
->name
, client_p
->username
, client_p
->host
, nick
, mask
, reason
);
709 sendto_realops_snomask(SNO_NCHANGE
, L_ALL
,
710 "Nick change: From %s to %s [%s@%s]",
711 client_p
->name
, nick
, client_p
->username
, client_p
->host
);
716 sendto_one_notice(client_p
,
717 ":*** Nick %s is temporarily unavailable on this server.",
722 sendto_one_notice(client_p
,
723 ":*** Nick %s is no longer available on this server.",
727 /* Do all of the nick-changing gymnastics. */
728 client_p
->tsinfo
= rb_current_time();
729 whowas_add_history(client_p
, 1);
731 monitor_signoff(client_p
);
733 invalidate_bancache_user(client_p
);
735 sendto_common_channels_local(client_p
, NOCAPS
, NOCAPS
, ":%s!%s@%s NICK :%s",
736 client_p
->name
, client_p
->username
, client_p
->host
, nick
);
737 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s NICK %s :%ld",
738 use_id(client_p
), nick
, (long) client_p
->tsinfo
);
740 del_from_client_hash(client_p
->name
, client_p
);
741 rb_strlcpy(client_p
->name
, nick
, sizeof(client_p
->name
));
742 add_to_client_hash(nick
, client_p
);
744 monitor_signon(client_p
);
746 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, client_p
->on_allow_list
.head
)
748 target_p
= ptr
->data
;
749 rb_dlinkFindDestroy(client_p
, &target_p
->localClient
->allow_list
);
750 rb_dlinkDestroy(ptr
, &client_p
->on_allow_list
);
753 snprintf(note
, sizeof(note
), "Nick: %s", nick
);
754 rb_note(client_p
->localClient
->F
, note
);
760 * update_client_exit_stats
762 * input - pointer to client
767 update_client_exit_stats(struct Client
*client_p
)
769 if(IsServer(client_p
))
771 sendto_realops_snomask(SNO_EXTERNAL
, L_ALL
,
772 "Server %s split from %s",
773 client_p
->name
, client_p
->servptr
->name
);
774 if(HasSentEob(client_p
))
777 else if(IsClient(client_p
))
782 if(IsInvisible(client_p
))
786 if(splitchecking
&& !splitmode
)
787 check_splitmode(NULL
);
791 * release_client_state
793 * input - pointer to client to release
798 release_client_state(struct Client
*client_p
)
800 if(client_p
->user
!= NULL
)
802 free_user(client_p
->user
, client_p
); /* try this here */
806 if(client_p
->serv
->user
!= NULL
)
807 free_user(client_p
->serv
->user
, client_p
);
808 if(client_p
->serv
->fullcaps
)
809 rb_free(client_p
->serv
->fullcaps
);
810 rb_free(client_p
->serv
);
815 * remove_client_from_list
816 * inputs - point to client to remove
818 * side effects - taken the code from ExitOneClient() for this
819 * and placed it here. - avalon
822 remove_client_from_list(struct Client
*client_p
)
824 s_assert(NULL
!= client_p
);
829 /* A client made with make_client()
830 * is on the unknown_list until removed.
831 * If it =does= happen to exit before its removed from that list
832 * and its =not= on the global_client_list, it will core here.
833 * short circuit that case now -db
835 if(client_p
->node
.prev
== NULL
&& client_p
->node
.next
== NULL
)
838 rb_dlinkDelete(&client_p
->node
, &global_client_list
);
840 update_client_exit_stats(client_p
);
846 * input - nickname to check, flag for nick from local client
847 * output - 0 if erroneous, else 1
851 clean_nick(const char *nick
, int loc_client
)
855 /* nicks cant start with a digit or -, and must have a length */
856 if(*nick
== '-' || *nick
== '\0')
859 if(loc_client
&& IsDigit(*nick
))
865 if(!IsNickChar(*nick
))
870 if(len
>= NICKLEN
&& (unsigned int)len
>= ConfigFileEntry
.nicklen
)
877 * find_person - find person by (nick)name.
878 * inputs - pointer to name
879 * output - return client pointer
883 find_person(const char *name
)
885 struct Client
*c2ptr
;
887 c2ptr
= find_client(name
);
889 if(c2ptr
&& IsPerson(c2ptr
))
895 find_named_person(const char *name
)
897 struct Client
*c2ptr
;
899 c2ptr
= find_named_client(name
);
901 if(c2ptr
&& IsPerson(c2ptr
))
908 * find_chasing - find the client structure for a nick name (user)
909 * using history mechanism if necessary. If the client is not found,
910 * an error message (NO SUCH NICK) is generated. If the client was found
911 * through the history, chasing will be 1 and otherwise 0.
914 find_chasing(struct Client
*source_p
, const char *user
, int *chasing
)
918 if(MyClient(source_p
))
919 who
= find_named_person(user
);
921 who
= find_person(user
);
926 if(who
|| IsDigit(*user
))
929 if(!(who
= whowas_get_history(user
, (long) KILLCHASETIMELIMIT
)))
931 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
932 form_str(ERR_NOSUCHNICK
), user
);
941 * get_client_name - Return the name of the client
942 * for various tracking and
943 * admin purposes. The main purpose of this function is to
944 * return the "socket host" name of the client, if that
945 * differs from the advertised name (other than case).
946 * But, this can be used to any client structure.
949 * Watch out the allocation of "nbuf", if either source_p->name
950 * or source_p->sockhost gets changed into pointers instead of
951 * directly allocated within the structure...
954 * Function return either a pointer to the structure (source_p) or
955 * to internal buffer (nbuf). *NEVER* use the returned pointer
956 * to modify what it points!!!
960 get_client_name(struct Client
*client
, int showip
)
962 static char nbuf
[HOSTLEN
* 2 + USERLEN
+ 5];
964 s_assert(NULL
!= client
);
968 if(MyConnect(client
))
970 if(!irccmp(client
->name
, client
->host
))
973 if(ConfigFileEntry
.hide_spoof_ips
&&
974 showip
== SHOW_IP
&& IsIPSpoof(client
))
976 if(IsAnyServer(client
))
979 /* And finally, let's get the host information, ip or name */
983 snprintf(nbuf
, sizeof(nbuf
), "%s[%s@%s]",
984 client
->name
, client
->username
,
988 snprintf(nbuf
, sizeof(nbuf
), "%s[%s@255.255.255.255]",
989 client
->name
, client
->username
);
992 snprintf(nbuf
, sizeof(nbuf
), "%s[%s@%s]",
993 client
->name
, client
->username
, client
->host
);
998 /* As pointed out by Adel Mezibra
999 * Neph|l|m@EFnet. Was missing a return here.
1001 return client
->name
;
1004 /* log_client_name()
1006 * This version is the same as get_client_name, but doesnt contain the
1007 * code that will hide IPs always. This should be used for logfiles.
1010 log_client_name(struct Client
*target_p
, int showip
)
1012 static char nbuf
[HOSTLEN
* 2 + USERLEN
+ 5];
1014 if(target_p
== NULL
)
1017 if(MyConnect(target_p
))
1019 if(irccmp(target_p
->name
, target_p
->host
) == 0)
1020 return target_p
->name
;
1025 snprintf(nbuf
, sizeof(nbuf
), "%s[%s@%s]", target_p
->name
,
1026 target_p
->username
, target_p
->sockhost
);
1030 snprintf(nbuf
, sizeof(nbuf
), "%s[%s@%s]", target_p
->name
,
1031 target_p
->username
, target_p
->host
);
1037 return target_p
->name
;
1040 /* is_remote_connect - Returns whether a server was /connect'ed by a remote
1041 * oper (send notices netwide) */
1043 is_remote_connect(struct Client
*client_p
)
1045 struct Client
*oper
;
1047 if (client_p
->serv
== NULL
)
1049 oper
= find_named_person(client_p
->serv
->by
);
1050 return oper
!= NULL
&& IsOper(oper
) && !MyConnect(oper
);
1054 free_exited_clients(void *unused
)
1056 rb_dlink_node
*ptr
, *next
;
1057 struct Client
*target_p
;
1059 RB_DLINK_FOREACH_SAFE(ptr
, next
, dead_list
.head
)
1061 target_p
= ptr
->data
;
1063 #ifdef DEBUG_EXITED_CLIENTS
1065 struct abort_client
*abt
;
1066 rb_dlink_node
*aptr
;
1069 RB_DLINK_FOREACH(aptr
, abort_list
.head
)
1072 if(abt
->client
== target_p
)
1075 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1076 "On abort_list: %s stat: %u flags: %u/%u handler: %c",
1077 target_p
->name
, (unsigned int) target_p
->status
,
1078 target_p
->flags
, target_p
->flags2
, target_p
->handler
);
1079 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1080 "Please report this to the charybdis developers!");
1087 rb_dlinkDestroy(ptr
, &dead_list
);
1093 if(ptr
->data
== NULL
)
1095 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1096 "Warning: null client on dead_list!");
1097 rb_dlinkDestroy(ptr
, &dead_list
);
1100 release_client_state(target_p
);
1101 free_client(target_p
);
1102 rb_dlinkDestroy(ptr
, &dead_list
);
1105 #ifdef DEBUG_EXITED_CLIENTS
1106 RB_DLINK_FOREACH_SAFE(ptr
, next
, dead_remote_list
.head
)
1108 target_p
= ptr
->data
;
1110 if(ptr
->data
== NULL
)
1112 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1113 "Warning: null client on dead_list!");
1114 rb_dlinkDestroy(ptr
, &dead_list
);
1117 release_client_state(target_p
);
1118 free_client(target_p
);
1119 rb_dlinkDestroy(ptr
, &dead_remote_list
);
1126 ** Remove all clients that depend on source_p; assumes all (S)QUITs have
1127 ** already been sent. we make sure to exit a server's dependent clients
1128 ** and servers before the server itself; exit_one_client takes care of
1129 ** actually removing things off llists. tweaked from +CSr31 -orabidoo
1132 * added sanity test code.... source_p->serv might be NULL...
1135 recurse_remove_clients(struct Client
*source_p
, const char *comment
)
1137 struct Client
*target_p
;
1138 rb_dlink_node
*ptr
, *ptr_next
;
1143 if(source_p
->serv
== NULL
) /* oooops. uh this is actually a major bug */
1146 /* this is very ugly, but it saves cpu :P */
1147 if(ConfigFileEntry
.nick_delay
> 0)
1149 RB_DLINK_FOREACH_SAFE(ptr
, ptr_next
, source_p
->serv
->users
.head
)
1151 target_p
= ptr
->data
;
1152 target_p
->flags
|= FLAGS_KILLED
;
1153 add_nd_entry(target_p
->name
);
1155 if(!IsDead(target_p
) && !IsClosing(target_p
))
1156 exit_remote_client(NULL
, target_p
, &me
, comment
);
1161 RB_DLINK_FOREACH_SAFE(ptr
, ptr_next
, source_p
->serv
->users
.head
)
1163 target_p
= ptr
->data
;
1164 target_p
->flags
|= FLAGS_KILLED
;
1166 if(!IsDead(target_p
) && !IsClosing(target_p
))
1167 exit_remote_client(NULL
, target_p
, &me
, comment
);
1171 RB_DLINK_FOREACH_SAFE(ptr
, ptr_next
, source_p
->serv
->servers
.head
)
1173 target_p
= ptr
->data
;
1174 recurse_remove_clients(target_p
, comment
);
1175 qs_server(NULL
, target_p
, &me
, comment
);
1180 ** Remove *everything* that depends on source_p, from all lists, and sending
1181 ** all necessary SQUITs. source_p itself is still on the lists,
1182 ** and its SQUITs have been sent except for the upstream one -orabidoo
1185 remove_dependents(struct Client
*client_p
,
1186 struct Client
*source_p
,
1187 struct Client
*from
, const char *comment
, const char *comment1
)
1190 rb_dlink_node
*ptr
, *next
;
1192 RB_DLINK_FOREACH_SAFE(ptr
, next
, serv_list
.head
)
1196 if(IsMe(to
) || to
== source_p
->from
|| to
== client_p
)
1199 sendto_one(to
, "SQUIT %s :%s", get_id(source_p
, to
), comment
);
1202 recurse_remove_clients(source_p
, comment1
);
1206 exit_aborted_clients(void *unused
)
1208 struct abort_client
*abt
;
1209 rb_dlink_node
*ptr
, *next
;
1210 RB_DLINK_FOREACH_SAFE(ptr
, next
, abort_list
.head
)
1214 #ifdef DEBUG_EXITED_CLIENTS
1216 if(rb_dlinkFind(abt
->client
, &dead_list
))
1219 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1220 "On dead_list: %s stat: %u flags: %u/%u handler: %c",
1221 abt
->client
->name
, (unsigned int) abt
->client
->status
,
1222 abt
->client
->flags
, abt
->client
->flags2
, abt
->client
->handler
);
1223 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1224 "Please report this to the charybdis developers!");
1230 s_assert(*((unsigned long*)abt
->client
) != 0xdeadbeef); /* This is lame but its a debug thing */
1231 rb_dlinkDelete(ptr
, &abort_list
);
1233 if(IsAnyServer(abt
->client
))
1234 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1235 "Closing link to %s: %s",
1236 abt
->client
->name
, abt
->notice
);
1238 /* its no longer on abort list - we *must* remove
1239 * FLAGS_CLOSING otherwise exit_client() will not run --fl
1241 abt
->client
->flags
&= ~FLAGS_CLOSING
;
1242 exit_client(abt
->client
, abt
->client
, &me
, abt
->notice
);
1249 * dead_link - Adds client to a list of clients that need an exit_client()
1252 dead_link(struct Client
*client_p
, int sendqex
)
1254 struct abort_client
*abt
;
1256 s_assert(!IsMe(client_p
));
1257 if(IsDead(client_p
) || IsClosing(client_p
) || IsMe(client_p
))
1260 abt
= (struct abort_client
*) rb_malloc(sizeof(struct abort_client
));
1263 rb_strlcpy(abt
->notice
, "Max SendQ exceeded", sizeof(abt
->notice
));
1265 snprintf(abt
->notice
, sizeof(abt
->notice
), "Write error: %s", strerror(errno
));
1267 abt
->client
= client_p
;
1268 SetIOError(client_p
);
1270 SetClosing(client_p
);
1271 rb_dlinkAdd(abt
, &abt
->node
, &abort_list
);
1275 /* This does the remove of the user from channels..local or remote */
1277 exit_generic_client(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1278 const char *comment
)
1280 rb_dlink_node
*ptr
, *next_ptr
;
1282 if(IsOper(source_p
))
1283 rb_dlinkFindDestroy(source_p
, &oper_list
);
1285 sendto_common_channels_local(source_p
, NOCAPS
, NOCAPS
, ":%s!%s@%s QUIT :%s",
1287 source_p
->username
, source_p
->host
, comment
);
1289 remove_user_from_channels(source_p
);
1291 /* Should not be in any channels now */
1292 s_assert(source_p
->user
->channel
.head
== NULL
);
1294 /* Clean up invitefield */
1295 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, source_p
->user
->invited
.head
)
1297 del_invite(ptr
->data
, source_p
);
1300 /* Clean up allow lists */
1301 del_all_accepts(source_p
);
1303 whowas_add_history(source_p
, 0);
1304 whowas_off_history(source_p
);
1306 monitor_signoff(source_p
);
1308 if(has_id(source_p
))
1309 del_from_id_hash(source_p
->id
, source_p
);
1311 del_from_hostname_hash(source_p
->orighost
, source_p
);
1312 del_from_client_hash(source_p
->name
, source_p
);
1313 remove_client_from_list(source_p
);
1317 * Assumes IsPerson(source_p) && !MyConnect(source_p)
1321 exit_remote_client(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1322 const char *comment
)
1324 exit_generic_client(client_p
, source_p
, from
, comment
);
1326 if(source_p
->servptr
&& source_p
->servptr
->serv
)
1328 rb_dlinkDelete(&source_p
->lnode
, &source_p
->servptr
->serv
->users
);
1331 if((source_p
->flags
& FLAGS_KILLED
) == 0)
1333 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
,
1334 ":%s QUIT :%s", use_id(source_p
), comment
);
1338 #ifdef DEBUG_EXITED_CLIENTS
1339 rb_dlinkAddAlloc(source_p
, &dead_remote_list
);
1341 rb_dlinkAddAlloc(source_p
, &dead_list
);
1343 return(CLIENT_EXITED
);
1347 * This assumes IsUnknown(source_p) == true and MyConnect(source_p) == true
1351 exit_unknown_client(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1352 const char *comment
)
1354 authd_abort_client(client_p
);
1355 rb_dlinkDelete(&source_p
->localClient
->tnode
, &unknown_list
);
1357 if(!IsIOError(source_p
))
1358 sendto_one(source_p
, "ERROR :Closing Link: %s (%s)",
1359 source_p
->user
!= NULL
? source_p
->host
: "127.0.0.1",
1362 close_connection(source_p
);
1364 if(has_id(source_p
))
1365 del_from_id_hash(source_p
->id
, source_p
);
1367 del_from_hostname_hash(source_p
->host
, source_p
);
1368 del_from_client_hash(source_p
->name
, source_p
);
1369 remove_client_from_list(source_p
);
1371 rb_dlinkAddAlloc(source_p
, &dead_list
);
1373 /* Note that we don't need to add unknowns to the dead_list */
1374 return(CLIENT_EXITED
);
1378 exit_remote_server(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1379 const char *comment
)
1381 static char comment1
[(HOSTLEN
*2)+2];
1382 static char newcomment
[BUFSIZE
];
1383 struct Client
*target_p
;
1385 if(ConfigServerHide
.flatten_links
)
1386 strcpy(comment1
, "*.net *.split");
1389 strcpy(comment1
, source_p
->servptr
->name
);
1390 strcat(comment1
, " ");
1391 strcat(comment1
, source_p
->name
);
1394 snprintf(newcomment
, sizeof(newcomment
), "by %s: %s",
1395 from
->name
, comment
);
1397 if(source_p
->serv
!= NULL
)
1398 remove_dependents(client_p
, source_p
, from
, IsPerson(from
) ? newcomment
: comment
, comment1
);
1400 if(source_p
->servptr
&& source_p
->servptr
->serv
)
1401 rb_dlinkDelete(&source_p
->lnode
, &source_p
->servptr
->serv
->servers
);
1405 rb_dlinkFindDestroy(source_p
, &global_serv_list
);
1406 target_p
= source_p
->from
;
1408 if(target_p
!= NULL
&& IsServer(target_p
) && target_p
!= client_p
&&
1409 !IsMe(target_p
) && (source_p
->flags
& FLAGS_KILLED
) == 0)
1411 sendto_one(target_p
, ":%s SQUIT %s :%s",
1412 get_id(from
, target_p
), get_id(source_p
, target_p
),
1416 if(has_id(source_p
))
1417 del_from_id_hash(source_p
->id
, source_p
);
1419 del_from_client_hash(source_p
->name
, source_p
);
1420 remove_client_from_list(source_p
);
1421 scache_split(source_p
->serv
->nameinfo
);
1424 #ifdef DEBUG_EXITED_CLIENTS
1425 rb_dlinkAddAlloc(source_p
, &dead_remote_list
);
1427 rb_dlinkAddAlloc(source_p
, &dead_list
);
1433 qs_server(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1434 const char *comment
)
1436 if(source_p
->servptr
&& source_p
->servptr
->serv
)
1437 rb_dlinkDelete(&source_p
->lnode
, &source_p
->servptr
->serv
->servers
);
1441 rb_dlinkFindDestroy(source_p
, &global_serv_list
);
1443 if(has_id(source_p
))
1444 del_from_id_hash(source_p
->id
, source_p
);
1446 del_from_client_hash(source_p
->name
, source_p
);
1447 remove_client_from_list(source_p
);
1448 scache_split(source_p
->serv
->nameinfo
);
1451 rb_dlinkAddAlloc(source_p
, &dead_list
);
1456 exit_local_server(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1457 const char *comment
)
1459 static char comment1
[(HOSTLEN
*2)+2];
1460 static char newcomment
[BUFSIZE
];
1461 unsigned int sendk
, recvk
;
1463 rb_dlinkDelete(&source_p
->localClient
->tnode
, &serv_list
);
1464 rb_dlinkFindDestroy(source_p
, &global_serv_list
);
1466 sendk
= source_p
->localClient
->sendK
;
1467 recvk
= source_p
->localClient
->receiveK
;
1469 /* Always show source here, so the server notices show
1470 * which side initiated the split -- jilles
1472 snprintf(newcomment
, sizeof(newcomment
), "by %s: %s",
1473 from
== source_p
? me
.name
: from
->name
, comment
);
1474 if (!IsIOError(source_p
))
1475 sendto_one(source_p
, "SQUIT %s :%s", use_id(source_p
),
1477 if(client_p
!= NULL
&& source_p
!= client_p
&& !IsIOError(source_p
))
1479 sendto_one(source_p
, "ERROR :Closing Link: 127.0.0.1 %s (%s)",
1480 source_p
->name
, comment
);
1483 if(source_p
->servptr
&& source_p
->servptr
->serv
)
1484 rb_dlinkDelete(&source_p
->lnode
, &source_p
->servptr
->serv
->servers
);
1489 close_connection(source_p
);
1491 if(ConfigServerHide
.flatten_links
)
1492 strcpy(comment1
, "*.net *.split");
1495 strcpy(comment1
, source_p
->servptr
->name
);
1496 strcat(comment1
, " ");
1497 strcat(comment1
, source_p
->name
);
1500 if(source_p
->serv
!= NULL
)
1501 remove_dependents(client_p
, source_p
, from
, IsPerson(from
) ? newcomment
: comment
, comment1
);
1503 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s was connected"
1504 " for %ld seconds. %d/%d sendK/recvK.",
1505 source_p
->name
, (long) rb_current_time() - source_p
->localClient
->firsttime
, sendk
, recvk
);
1507 ilog(L_SERVER
, "%s was connected for %ld seconds. %d/%d sendK/recvK.",
1508 source_p
->name
, (long) rb_current_time() - source_p
->localClient
->firsttime
, sendk
, recvk
);
1510 if(has_id(source_p
))
1511 del_from_id_hash(source_p
->id
, source_p
);
1513 del_from_client_hash(source_p
->name
, source_p
);
1514 remove_client_from_list(source_p
);
1515 scache_split(source_p
->serv
->nameinfo
);
1518 rb_dlinkAddAlloc(source_p
, &dead_list
);
1524 * This assumes IsPerson(source_p) == true && MyConnect(source_p) == true
1528 exit_local_client(struct Client
*client_p
, struct Client
*source_p
, struct Client
*from
,
1529 const char *comment
)
1531 unsigned long on_for
;
1534 exit_generic_client(client_p
, source_p
, from
, comment
);
1535 clear_monitor(source_p
);
1537 s_assert(IsPerson(source_p
));
1538 rb_dlinkDelete(&source_p
->localClient
->tnode
, &lclient_list
);
1539 rb_dlinkDelete(&source_p
->lnode
, &me
.serv
->users
);
1541 if(IsOper(source_p
))
1542 rb_dlinkFindDestroy(source_p
, &local_oper_list
);
1544 sendto_realops_snomask(SNO_CCONN
, L_ALL
,
1545 "Client exiting: %s (%s@%s) [%s] [%s]",
1547 source_p
->username
, source_p
->host
, comment
,
1548 show_ip(NULL
, source_p
) ? source_p
->sockhost
: "255.255.255.255");
1550 sendto_realops_snomask(SNO_CCONNEXT
, L_ALL
,
1551 "CLIEXIT %s %s %s %s 0 %s",
1552 source_p
->name
, source_p
->username
, source_p
->host
,
1553 show_ip(NULL
, source_p
) ? source_p
->sockhost
: "255.255.255.255",
1556 on_for
= rb_current_time() - source_p
->localClient
->firsttime
;
1558 ilog(L_USER
, "%s (%3lu:%02lu:%02lu): %s!%s@%s %s %d/%d",
1559 rb_ctime(rb_current_time(), tbuf
, sizeof(tbuf
)), on_for
/ 3600,
1560 (on_for
% 3600) / 60, on_for
% 60,
1561 source_p
->name
, source_p
->username
, source_p
->host
,
1563 source_p
->localClient
->sendK
, source_p
->localClient
->receiveK
);
1565 sendto_one(source_p
, "ERROR :Closing Link: %s (%s)", source_p
->host
, comment
);
1566 close_connection(source_p
);
1568 if((source_p
->flags
& FLAGS_KILLED
) == 0)
1570 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
,
1571 ":%s QUIT :%s", use_id(source_p
), comment
);
1575 rb_dlinkAddAlloc(source_p
, &dead_list
);
1576 return(CLIENT_EXITED
);
1581 ** exit_client - This is old "m_bye". Name changed, because this is not a
1582 ** protocol function, but a general server utility function.
1584 ** This function exits a client of *any* type (user, server, etc)
1585 ** from this server. Also, this generates all necessary prototol
1586 ** messages that this exit may cause.
1588 ** 1) If the client is a local client, then this implicitly
1589 ** exits all other clients depending on this connection (e.g.
1590 ** remote clients having 'from'-field that points to this.
1592 ** 2) If the client is a remote client, then only this is exited.
1594 ** For convenience, this function returns a suitable value for
1595 ** m_function return value:
1597 ** CLIENT_EXITED if (client_p == source_p)
1598 ** 0 if (client_p != source_p)
1601 exit_client(struct Client
*client_p
, /* The local client originating the
1602 * exit or NULL, if this exit is
1603 * generated by this server for
1605 * This will not get any of the
1606 * generated messages. */
1607 struct Client
*source_p
, /* Client exiting */
1608 struct Client
*from
, /* Client firing off this Exit,
1610 const char *comment
/* Reason for the exit */
1613 hook_data_client_exit hdata
;
1614 if(IsClosing(source_p
))
1617 /* note, this HAS to be here, when we exit a client we attempt to
1618 * send them data, if this generates a write error we must *not* add
1619 * them to the abort list --fl
1621 SetClosing(source_p
);
1623 hdata
.local_link
= client_p
;
1624 hdata
.target
= source_p
;
1626 hdata
.comment
= comment
;
1627 call_hook(h_client_exit
, &hdata
);
1629 if(MyConnect(source_p
))
1631 /* Local clients of various types */
1632 if(IsPerson(source_p
))
1633 return exit_local_client(client_p
, source_p
, from
, comment
);
1634 else if(IsServer(source_p
))
1635 return exit_local_server(client_p
, source_p
, from
, comment
);
1636 /* IsUnknown || IsConnecting || IsHandShake */
1637 else if(!IsReject(source_p
))
1638 return exit_unknown_client(client_p
, source_p
, from
, comment
);
1643 if(IsPerson(source_p
))
1644 return exit_remote_client(client_p
, source_p
, from
, comment
);
1645 else if(IsServer(source_p
))
1646 return exit_remote_server(client_p
, source_p
, from
, comment
);
1653 * Count up local client memory
1656 /* XXX one common Client list now */
1658 count_local_client_memory(size_t * count
, size_t * local_client_memory_used
)
1661 rb_bh_usage(lclient_heap
, count
, NULL
, &lusage
, NULL
);
1662 *local_client_memory_used
= lusage
+ (*count
* (sizeof(void *) + sizeof(struct Client
)));
1666 * Count up remote client memory
1669 count_remote_client_memory(size_t * count
, size_t * remote_client_memory_used
)
1671 size_t lcount
, rcount
;
1672 rb_bh_usage(lclient_heap
, &lcount
, NULL
, NULL
, NULL
);
1673 rb_bh_usage(client_heap
, &rcount
, NULL
, NULL
, NULL
);
1674 *count
= rcount
- lcount
;
1675 *remote_client_memory_used
= *count
* (sizeof(void *) + sizeof(struct Client
));
1680 * accept processing, this adds a form of "caller ID" to ircd
1682 * If a client puts themselves into "caller ID only" mode,
1683 * only clients that match a client pointer they have put on
1684 * the accept list will be allowed to message them.
1686 * [ source.on_allow_list ] -> [ target1 ] -> [ target2 ]
1688 * [target.allow_list] -> [ source1 ] -> [source2 ]
1690 * i.e. a target will have a link list of source pointers it will allow
1691 * each source client then has a back pointer pointing back
1692 * to the client that has it on its accept list.
1693 * This allows for exit_one_client to remove these now bogus entries
1694 * from any client having an accept on them.
1699 * inputs - pointer to exiting client
1701 * side effects - Walk through given clients allow_list and on_allow_list
1702 * remove all references to this client
1705 del_all_accepts(struct Client
*client_p
)
1708 rb_dlink_node
*next_ptr
;
1709 struct Client
*target_p
;
1711 if(MyClient(client_p
) && client_p
->localClient
->allow_list
.head
)
1713 /* clear this clients accept list, and remove them from
1714 * everyones on_accept_list
1716 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, client_p
->localClient
->allow_list
.head
)
1718 target_p
= ptr
->data
;
1719 rb_dlinkFindDestroy(client_p
, &target_p
->on_allow_list
);
1720 rb_dlinkDestroy(ptr
, &client_p
->localClient
->allow_list
);
1724 /* remove this client from everyones accept list */
1725 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, client_p
->on_allow_list
.head
)
1727 target_p
= ptr
->data
;
1728 rb_dlinkFindDestroy(client_p
, &target_p
->localClient
->allow_list
);
1729 rb_dlinkDestroy(ptr
, &client_p
->on_allow_list
);
1734 * show_ip() - asks if the true IP should be shown when source is
1735 * asking for info about target
1737 * Inputs - source_p who is asking
1738 * - target_p who do we want the info on
1739 * Output - returns 1 if clear IP can be shown, otherwise 0
1740 * Side Effects - none
1744 show_ip(struct Client
*source_p
, struct Client
*target_p
)
1746 if(IsAnyServer(target_p
))
1750 else if(IsIPSpoof(target_p
))
1752 /* source == NULL indicates message is being sent
1755 if(!ConfigFileEntry
.hide_spoof_ips
&&
1756 (source_p
== NULL
|| MyOper(source_p
)))
1760 else if(IsDynSpoof(target_p
) && (source_p
!= NULL
&& !IsOper(source_p
)))
1767 show_ip_conf(struct ConfItem
*aconf
, struct Client
*source_p
)
1769 if(IsConfDoSpoofIp(aconf
))
1771 if(!ConfigFileEntry
.hide_spoof_ips
&& MyOper(source_p
))
1781 show_ip_whowas(struct Whowas
*whowas
, struct Client
*source_p
)
1783 if(whowas
->flags
& WHOWAS_IP_SPOOFING
)
1784 if(ConfigFileEntry
.hide_spoof_ips
|| !MyOper(source_p
))
1786 if(whowas
->flags
& WHOWAS_DYNSPOOF
)
1787 if(!IsOper(source_p
))
1795 * inputs - pointer to client struct
1796 * output - pointer to struct User
1797 * side effects - add's an User information block to a client
1798 * if it was not previously allocated.
1801 make_user(struct Client
*client_p
)
1805 user
= client_p
->user
;
1808 user
= (struct User
*) rb_bh_alloc(user_heap
);
1810 client_p
->user
= user
;
1818 * inputs - pointer to client struct
1819 * output - pointer to server_t
1820 * side effects - add's an Server information block to a client
1821 * if it was not previously allocated.
1824 make_server(struct Client
*client_p
)
1826 struct Server
*serv
= client_p
->serv
;
1830 serv
= (struct Server
*) rb_malloc(sizeof(struct Server
));
1831 client_p
->serv
= serv
;
1833 return client_p
->serv
;
1839 * inputs - pointer to user struct
1840 * - pointer to client struct
1842 * side effects - Decrease user reference count by one and release block,
1843 * if count reaches 0
1846 free_user(struct User
*user
, struct Client
*client_p
)
1848 free_away(client_p
);
1850 if(--user
->refcnt
<= 0)
1853 rb_free((char *) user
->away
);
1857 if(user
->refcnt
< 0 || user
->invited
.head
|| user
->channel
.head
)
1859 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1860 "* %p user (%s!%s@%s) %p %p %p %lu %d *",
1862 client_p
? client_p
->
1869 rb_dlink_list_length(&user
->channel
),
1871 s_assert(!user
->refcnt
);
1872 s_assert(!user
->invited
.head
);
1873 s_assert(!user
->channel
.head
);
1876 rb_bh_free(user_heap
, user
);
1881 allocate_away(struct Client
*client_p
)
1883 if(client_p
->user
->away
== NULL
)
1884 client_p
->user
->away
= rb_bh_alloc(away_heap
);
1889 free_away(struct Client
*client_p
)
1891 if(client_p
->user
!= NULL
&& client_p
->user
->away
!= NULL
) {
1892 rb_bh_free(away_heap
, client_p
->user
->away
);
1893 client_p
->user
->away
= NULL
;
1902 for(i
= 0; i
< 3; i
++)
1903 current_uid
[i
] = me
.id
[i
];
1905 for(i
= 3; i
< 9; i
++)
1906 current_uid
[i
] = 'A';
1908 current_uid
[9] = '\0';
1915 static int flipped
= 0;
1919 for(i
= 8; i
> 3; i
--)
1921 if(current_uid
[i
] == 'Z')
1923 current_uid
[i
] = '0';
1926 else if(current_uid
[i
] != '9')
1932 current_uid
[i
] = 'A';
1935 /* if this next if() triggers, we're fucked. */
1936 if(current_uid
[3] == 'Z')
1938 current_uid
[i
] = 'A';
1944 /* if this happens..well, i'm not sure what to say, but lets handle it correctly */
1945 if(rb_unlikely(flipped
))
1947 /* this slows down uid generation a bit... */
1948 if(find_id(current_uid
) != NULL
)
1956 * Close the physical connection. This function must make
1957 * MyConnect(client_p) == FALSE, and set client_p->from == NULL.
1960 close_connection(struct Client
*client_p
)
1962 s_assert(client_p
!= NULL
);
1963 if(client_p
== NULL
)
1966 s_assert(MyConnect(client_p
));
1967 if(!MyConnect(client_p
))
1970 if(IsServer(client_p
))
1972 struct server_conf
*server_p
;
1974 ServerStats
.is_sv
++;
1975 ServerStats
.is_sbs
+= client_p
->localClient
->sendB
;
1976 ServerStats
.is_sbr
+= client_p
->localClient
->receiveB
;
1977 ServerStats
.is_sti
+= (unsigned long long)(rb_current_time() - client_p
->localClient
->firsttime
);
1980 * If the connection has been up for a long amount of time, schedule
1981 * a 'quick' reconnect, else reset the next-connect cycle.
1983 if((server_p
= find_server_conf(client_p
->name
)) != NULL
)
1986 * Reschedule a faster reconnect, if this was a automatically
1987 * connected configuration entry. (Note that if we have had
1988 * a rehash in between, the status has been changed to
1989 * CONF_ILLEGAL). But only do this if it was a "good" link.
1991 server_p
->hold
= time(NULL
);
1993 (server_p
->hold
- client_p
->localClient
->lasttime
>
1994 HANGONGOODLINK
) ? HANGONRETRYDELAY
: ConFreq(server_p
->class);
1998 else if(IsClient(client_p
))
2000 ServerStats
.is_cl
++;
2001 ServerStats
.is_cbs
+= client_p
->localClient
->sendB
;
2002 ServerStats
.is_cbr
+= client_p
->localClient
->receiveB
;
2003 ServerStats
.is_cti
+= (unsigned long long)(rb_current_time() - client_p
->localClient
->firsttime
);
2006 ServerStats
.is_ni
++;
2008 client_release_connids(client_p
);
2010 if(client_p
->localClient
->F
!= NULL
)
2012 /* attempt to flush any pending dbufs. Evil, but .. -- adrian */
2013 if(!IsIOError(client_p
))
2014 send_queued(client_p
);
2016 rb_close(client_p
->localClient
->F
);
2017 client_p
->localClient
->F
= NULL
;
2020 rb_linebuf_donebuf(&client_p
->localClient
->buf_sendq
);
2021 rb_linebuf_donebuf(&client_p
->localClient
->buf_recvq
);
2022 detach_conf(client_p
);
2024 /* XXX shouldnt really be done here. */
2025 detach_server_conf(client_p
);
2027 client_p
->from
= NULL
; /* ...this should catch them! >:) --msa */
2028 ClearMyConnect(client_p
);
2029 SetIOError(client_p
);
2035 error_exit_client(struct Client
*client_p
, int error
)
2038 * ...hmm, with non-blocking sockets we might get
2039 * here from quite valid reasons, although.. why
2040 * would select report "data available" when there
2041 * wasn't... so, this must be an error anyway... --msa
2042 * actually, EOF occurs when read() returns 0 and
2043 * in due course, select() returns that fd as ready
2044 * for reading even though it ends up being an EOF. -avalon
2047 int current_error
= rb_get_sockerr(client_p
->localClient
->F
);
2049 SetIOError(client_p
);
2051 if(IsServer(client_p
) || IsHandshake(client_p
))
2055 sendto_realops_snomask(SNO_GENERAL
, is_remote_connect(client_p
) && !IsServer(client_p
) ? L_NETWIDE
: L_ALL
,
2056 "Server %s closed the connection",
2059 ilog(L_SERVER
, "Server %s closed the connection",
2060 log_client_name(client_p
, SHOW_IP
));
2064 sendto_realops_snomask(SNO_GENERAL
, is_remote_connect(client_p
) && !IsServer(client_p
) ? L_NETWIDE
: L_ALL
,
2065 "Lost connection to %s: %s",
2066 client_p
->name
, strerror(current_error
));
2067 ilog(L_SERVER
, "Lost connection to %s: %s",
2068 log_client_name(client_p
, SHOW_IP
), strerror(current_error
));
2073 rb_strlcpy(errmsg
, "Remote host closed the connection", sizeof(errmsg
));
2075 snprintf(errmsg
, sizeof(errmsg
), "Read error: %s", strerror(current_error
));
2077 exit_client(client_p
, client_p
, &me
, errmsg
);