23 |
|
*/ |
24 |
|
|
25 |
|
#include "stdinc.h" |
26 |
< |
#include "tools.h" |
26 |
> |
#include "list.h" |
27 |
|
#include "client.h" |
28 |
|
#include "channel_mode.h" |
29 |
|
#include "common.h" |
31 |
|
#include "fdlist.h" |
32 |
|
#include "hash.h" |
33 |
|
#include "irc_string.h" |
34 |
– |
#include "sprintf_irc.h" |
34 |
|
#include "ircd.h" |
36 |
– |
#include "list.h" |
35 |
|
#include "s_gline.h" |
36 |
|
#include "numeric.h" |
37 |
|
#include "packet.h" |
75 |
|
|
76 |
|
static void check_pings_list(dlink_list *); |
77 |
|
static void check_unknowns_list(void); |
78 |
< |
static void ban_them(struct Client *client_p, struct ConfItem *conf); |
78 |
> |
static void ban_them(struct Client *, struct ConfItem *); |
79 |
|
|
80 |
|
|
81 |
|
/* init_client() |
123 |
|
client_p->localClient = BlockHeapAlloc(lclient_heap); |
124 |
|
client_p->localClient->registration = REG_INIT; |
125 |
|
/* as good a place as any... */ |
126 |
< |
dlinkAdd(client_p, make_dlink_node(), &unknown_list); |
126 |
> |
dlinkAdd(client_p, &client_p->localClient->lclient_node, &unknown_list); |
127 |
|
} |
128 |
|
else |
129 |
|
client_p->from = from; /* 'from' of local client is self! */ |
262 |
|
struct AccessItem *aconf; |
263 |
|
|
264 |
|
conf = make_conf_item(KLINE_TYPE); |
265 |
< |
aconf = (struct AccessItem *)map_to_conf(conf); |
265 |
> |
aconf = map_to_conf(conf); |
266 |
|
|
267 |
|
DupString(aconf->host, client_p->host); |
268 |
|
DupString(aconf->reason, "idle exceeder"); |
317 |
|
get_client_name(client_p, HIDE_IP)); |
318 |
|
} |
319 |
|
|
320 |
< |
ircsprintf(scratch, "Ping timeout: %d seconds", |
321 |
< |
(int)(CurrentTime - client_p->lasttime)); |
320 |
> |
snprintf(scratch, sizeof(scratch), "Ping timeout: %d seconds", |
321 |
> |
(int)(CurrentTime - client_p->lasttime)); |
322 |
|
exit_client(client_p, &me, scratch); |
323 |
|
} |
324 |
|
else if (!IsPingWarning(client_p) && pingwarn > 0 && |
553 |
|
static void |
554 |
|
update_client_exit_stats(struct Client *client_p) |
555 |
|
{ |
556 |
< |
if (IsServer(client_p)) |
559 |
< |
{ |
560 |
< |
sendto_realops_flags(UMODE_EXTERNAL, L_ALL, |
561 |
< |
"Server %s split from %s", |
562 |
< |
client_p->name, client_p->servptr->name); |
563 |
< |
} |
564 |
< |
else if (IsClient(client_p)) |
556 |
> |
if (IsClient(client_p)) |
557 |
|
{ |
558 |
+ |
assert(Count.total > 0); |
559 |
|
--Count.total; |
560 |
|
if (IsOper(client_p)) |
561 |
|
--Count.oper; |
562 |
|
if (IsInvisible(client_p)) |
563 |
|
--Count.invisi; |
564 |
|
} |
565 |
+ |
else if (IsServer(client_p)) |
566 |
+ |
sendto_realops_flags(UMODE_EXTERNAL, L_ALL, "Server %s split from %s", |
567 |
+ |
client_p->name, client_p->servptr->name); |
568 |
|
|
569 |
|
if (splitchecking && !splitmode) |
570 |
|
check_splitmode(NULL); |
651 |
|
* to modify what it points!!! |
652 |
|
*/ |
653 |
|
const char * |
654 |
< |
get_client_name(struct Client *client, int showip) |
654 |
> |
get_client_name(const struct Client *client, int showip) |
655 |
|
{ |
656 |
|
static char nbuf[HOSTLEN * 2 + USERLEN + 5]; |
657 |
|
|
658 |
|
assert(client != NULL); |
659 |
|
|
660 |
|
if (irccmp(client->name, client->host) == 0) |
661 |
< |
return(client->name); |
661 |
> |
return client->name; |
662 |
|
|
663 |
|
if (ConfigServerHide.hide_server_ips) |
664 |
|
if (IsServer(client) || IsConnecting(client) || IsHandshake(client)) |
674 |
|
case SHOW_IP: |
675 |
|
if (MyConnect(client)) |
676 |
|
{ |
677 |
< |
ircsprintf(nbuf, "%s[%s@%s]", client->name, client->username, |
678 |
< |
client->sockhost); |
677 |
> |
snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]", |
678 |
> |
client->name, |
679 |
> |
client->username, client->sockhost); |
680 |
|
break; |
681 |
|
} |
682 |
|
case MASK_IP: |
683 |
< |
ircsprintf(nbuf, "%s[%s@255.255.255.255]", client->name, |
684 |
< |
client->username); |
683 |
> |
snprintf(nbuf, sizeof(nbuf), "%s[%s@255.255.255.255]", |
684 |
> |
client->name, client->username); |
685 |
|
break; |
686 |
|
default: |
687 |
< |
ircsprintf(nbuf, "%s[%s@%s]", client->name, client->username, |
688 |
< |
client->host); |
687 |
> |
snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]", |
688 |
> |
client->name, |
689 |
> |
client->username, client->host); |
690 |
|
} |
691 |
|
|
692 |
< |
return(nbuf); |
692 |
> |
return nbuf; |
693 |
|
} |
694 |
|
|
695 |
|
void |
718 |
|
|
719 |
|
assert(!IsMe(source_p)); |
720 |
|
|
721 |
< |
if (IsServer(source_p)) |
724 |
< |
{ |
725 |
< |
dlinkDelete(&source_p->lnode, &source_p->servptr->serv->servers); |
726 |
< |
|
727 |
< |
if ((lp = dlinkFindDelete(&global_serv_list, source_p)) != NULL) |
728 |
< |
free_dlink_node(lp); |
729 |
< |
|
730 |
< |
if (!MyConnect(source_p)) |
731 |
< |
{ |
732 |
< |
source_p->from->serv->dep_servers--; |
733 |
< |
assert(source_p->from->serv->dep_servers > 0); |
734 |
< |
} |
735 |
< |
} |
736 |
< |
else if (IsClient(source_p)) |
721 |
> |
if (IsClient(source_p)) |
722 |
|
{ |
723 |
|
if (source_p->servptr->serv != NULL) |
724 |
< |
dlinkDelete(&source_p->lnode, &source_p->servptr->serv->users); |
724 |
> |
dlinkDelete(&source_p->lnode, &source_p->servptr->serv->client_list); |
725 |
|
|
726 |
< |
/* If a person is on a channel, send a QUIT notice |
727 |
< |
** to every client (person) on the same channel (so |
728 |
< |
** that the client can show the "**signoff" message). |
729 |
< |
** (Note: The notice is to the local clients *only*) |
730 |
< |
*/ |
726 |
> |
/* |
727 |
> |
* If a person is on a channel, send a QUIT notice |
728 |
> |
* to every client (person) on the same channel (so |
729 |
> |
* that the client can show the "**signoff" message). |
730 |
> |
* (Note: The notice is to the local clients *only*) |
731 |
> |
*/ |
732 |
|
sendto_common_channels_local(source_p, 0, ":%s!%s@%s QUIT :%s", |
733 |
|
source_p->name, source_p->username, |
734 |
|
source_p->host, quitmsg); |
740 |
|
|
741 |
|
watch_check_hash(source_p, RPL_LOGOFF); |
742 |
|
|
743 |
< |
if (!MyConnect(source_p)) |
758 |
< |
{ |
759 |
< |
source_p->from->serv->dep_users--; |
760 |
< |
assert(source_p->from->serv->dep_users >= 0); |
761 |
< |
} |
762 |
< |
else |
743 |
> |
if (MyConnect(source_p)) |
744 |
|
{ |
745 |
|
/* Clean up invitefield */ |
746 |
|
DLINK_FOREACH_SAFE(lp, next_lp, source_p->localClient->invited.head) |
749 |
|
del_all_accepts(source_p); |
750 |
|
} |
751 |
|
} |
752 |
+ |
else if (IsServer(source_p)) |
753 |
+ |
{ |
754 |
+ |
dlinkDelete(&source_p->lnode, &source_p->servptr->serv->server_list); |
755 |
+ |
|
756 |
+ |
if ((lp = dlinkFindDelete(&global_serv_list, source_p)) != NULL) |
757 |
+ |
free_dlink_node(lp); |
758 |
+ |
} |
759 |
|
|
760 |
|
/* Remove source_p from the client lists */ |
761 |
|
if (HasID(source_p)) |
795 |
|
static void |
796 |
|
recurse_send_quits(struct Client *original_source_p, struct Client *source_p, |
797 |
|
struct Client *from, struct Client *to, const char *comment, |
798 |
< |
const char *splitstr, const char *myname) |
798 |
> |
const char *splitstr) |
799 |
|
{ |
800 |
|
dlink_node *ptr, *next; |
801 |
|
struct Client *target_p; |
802 |
< |
int hidden = match(myname, source_p->name); |
802 |
> |
int hidden = match(me.name, source_p->name); /* XXX */ |
803 |
|
|
804 |
|
assert(to != source_p); /* should be already removed from serv_list */ |
805 |
|
|
810 |
|
* hidden behind fakename. If so, send out the QUITs -adx |
811 |
|
*/ |
812 |
|
if (hidden || !IsCapable(to, CAP_QS)) |
813 |
< |
DLINK_FOREACH_SAFE(ptr, next, source_p->serv->users.head) |
813 |
> |
DLINK_FOREACH_SAFE(ptr, next, source_p->serv->client_list.head) |
814 |
|
{ |
815 |
|
target_p = ptr->data; |
816 |
|
sendto_one(to, ":%s QUIT :%s", target_p->name, splitstr); |
817 |
|
} |
818 |
|
|
819 |
< |
DLINK_FOREACH_SAFE(ptr, next, source_p->serv->servers.head) |
819 |
> |
DLINK_FOREACH_SAFE(ptr, next, source_p->serv->server_list.head) |
820 |
|
recurse_send_quits(original_source_p, ptr->data, from, to, |
821 |
< |
comment, splitstr, myname); |
821 |
> |
comment, splitstr); |
822 |
|
|
823 |
|
if (!hidden && ((source_p == original_source_p && to != from) || |
824 |
|
!IsCapable(to, CAP_QS))) |
840 |
|
{ |
841 |
|
dlink_node *ptr, *next; |
842 |
|
|
843 |
< |
DLINK_FOREACH_SAFE(ptr, next, source_p->serv->users.head) |
843 |
> |
DLINK_FOREACH_SAFE(ptr, next, source_p->serv->client_list.head) |
844 |
|
exit_one_client(ptr->data, quitmsg); |
845 |
|
|
846 |
< |
DLINK_FOREACH_SAFE(ptr, next, source_p->serv->servers.head) |
846 |
> |
DLINK_FOREACH_SAFE(ptr, next, source_p->serv->server_list.head) |
847 |
|
{ |
848 |
|
recurse_remove_clients(ptr->data, quitmsg); |
849 |
|
exit_one_client(ptr->data, quitmsg); |
850 |
|
} |
863 |
– |
|
864 |
– |
assert(source_p->serv->dep_servers == 1); |
865 |
– |
assert(source_p->serv->dep_users == 0); |
851 |
|
} |
852 |
|
|
853 |
|
/* |
859 |
|
remove_dependents(struct Client *source_p, struct Client *from, |
860 |
|
const char *comment, const char *splitstr) |
861 |
|
{ |
862 |
< |
struct Client *to; |
878 |
< |
struct ConfItem *conf; |
879 |
< |
static char myname[HOSTLEN+1]; |
880 |
< |
dlink_node *ptr; |
862 |
> |
dlink_node *ptr = NULL; |
863 |
|
|
864 |
|
DLINK_FOREACH(ptr, serv_list.head) |
865 |
< |
{ |
866 |
< |
to = ptr->data; |
885 |
< |
|
886 |
< |
if ((conf = to->serv->sconf) != NULL) |
887 |
< |
strlcpy(myname, my_name_for_link(conf), sizeof(myname)); |
888 |
< |
else |
889 |
< |
strlcpy(myname, me.name, sizeof(myname)); |
890 |
< |
recurse_send_quits(source_p, source_p, from, to, |
891 |
< |
comment, splitstr, myname); |
892 |
< |
} |
865 |
> |
recurse_send_quits(source_p, source_p, from, ptr->data, |
866 |
> |
comment, splitstr); |
867 |
|
|
868 |
|
recurse_remove_clients(source_p, splitstr); |
869 |
|
} |
889 |
|
void |
890 |
|
exit_client(struct Client *source_p, struct Client *from, const char *comment) |
891 |
|
{ |
892 |
< |
dlink_node *m; |
892 |
> |
dlink_node *m = NULL; |
893 |
|
|
894 |
|
if (MyConnect(source_p)) |
895 |
|
{ |
904 |
|
if (IsIpHash(source_p)) |
905 |
|
remove_one_ip(&source_p->localClient->ip); |
906 |
|
|
907 |
< |
delete_auth(source_p); |
907 |
> |
if (source_p->localClient->auth) |
908 |
> |
{ |
909 |
> |
delete_auth(source_p->localClient->auth); |
910 |
> |
source_p->localClient->auth = NULL; |
911 |
> |
} |
912 |
|
|
913 |
|
/* This source_p could have status of one of STAT_UNKNOWN, STAT_CONNECTING |
914 |
|
* STAT_HANDSHAKE or STAT_UNKNOWN |
918 |
|
*/ |
919 |
|
if (!IsRegistered(source_p)) |
920 |
|
{ |
921 |
< |
if ((m = dlinkFindDelete(&unknown_list, source_p)) != NULL) |
922 |
< |
free_dlink_node(m); |
921 |
> |
assert(dlinkFind(&unknown_list, source_p)); |
922 |
> |
|
923 |
> |
dlinkDelete(&source_p->localClient->lclient_node, &unknown_list); |
924 |
|
} |
925 |
|
else if (IsClient(source_p)) |
926 |
|
{ |
927 |
+ |
assert(Count.local > 0); |
928 |
|
Count.local--; |
929 |
|
|
930 |
|
if (IsOper(source_p)) |
933 |
|
free_dlink_node(m); |
934 |
|
} |
935 |
|
|
936 |
+ |
assert(dlinkFind(&local_client_list, source_p)); |
937 |
|
dlinkDelete(&source_p->localClient->lclient_node, &local_client_list); |
938 |
+ |
|
939 |
|
if (source_p->localClient->list_task != NULL) |
940 |
|
free_list_task(source_p->localClient->list_task, source_p); |
941 |
|
|
1132 |
|
strlcpy(errmsg, "Remote host closed the connection", |
1133 |
|
sizeof(errmsg)); |
1134 |
|
else |
1135 |
< |
ircsprintf(errmsg, "Read error: %s", |
1136 |
< |
strerror(current_error)); |
1135 |
> |
snprintf(errmsg, sizeof(errmsg), "Read error: %s", |
1136 |
> |
strerror(current_error)); |
1137 |
|
|
1138 |
|
exit_client(client_p, &me, errmsg); |
1139 |
|
} |
1253 |
|
del_accept(ptr->data, client_p); |
1254 |
|
} |
1255 |
|
|
1274 |
– |
/* set_initial_nick() |
1275 |
– |
* |
1276 |
– |
* inputs |
1277 |
– |
* output |
1278 |
– |
* side effects - |
1279 |
– |
* |
1280 |
– |
* This function is only called to set up an initially registering |
1281 |
– |
* client. |
1282 |
– |
*/ |
1283 |
– |
void |
1284 |
– |
set_initial_nick(struct Client *client_p, struct Client *source_p, |
1285 |
– |
const char *nick) |
1286 |
– |
{ |
1287 |
– |
char buf[USERLEN + 1]; |
1288 |
– |
|
1289 |
– |
/* Client setting NICK the first time */ |
1290 |
– |
|
1291 |
– |
/* This had to be copied here to avoid problems.. */ |
1292 |
– |
source_p->tsinfo = CurrentTime; |
1293 |
– |
source_p->localClient->registration &= ~REG_NEED_NICK; |
1294 |
– |
|
1295 |
– |
if (source_p->name[0]) |
1296 |
– |
hash_del_client(source_p); |
1297 |
– |
|
1298 |
– |
strlcpy(source_p->name, nick, sizeof(source_p->name)); |
1299 |
– |
hash_add_client(source_p); |
1300 |
– |
|
1301 |
– |
/* fd_desc is long enough */ |
1302 |
– |
fd_note(&client_p->localClient->fd, "Nick: %s", nick); |
1303 |
– |
|
1304 |
– |
if (!source_p->localClient->registration) |
1305 |
– |
{ |
1306 |
– |
strlcpy(buf, source_p->username, sizeof(buf)); |
1307 |
– |
|
1308 |
– |
/* |
1309 |
– |
* USER already received, now we have NICK. |
1310 |
– |
* *NOTE* For servers "NICK" *must* precede the |
1311 |
– |
* user message (giving USER before NICK is possible |
1312 |
– |
* only for local client connection!). register_user |
1313 |
– |
* may reject the client and call exit_client for it |
1314 |
– |
* --must test this and exit m_nick too!!! |
1315 |
– |
*/ |
1316 |
– |
register_local_user(client_p, source_p, nick, buf); |
1317 |
– |
} |
1318 |
– |
} |
1319 |
– |
|
1256 |
|
/* change_local_nick() |
1257 |
|
* |
1258 |
|
* inputs - pointer to server |