23 |
|
*/ |
24 |
|
|
25 |
|
#include "stdinc.h" |
26 |
< |
#include "tools.h" |
26 |
> |
#include "list.h" |
27 |
|
#include "send.h" |
28 |
|
#include "channel.h" |
29 |
|
#include "client.h" |
38 |
|
#include "s_serv.h" |
39 |
|
#include "sprintf_irc.h" |
40 |
|
#include "s_conf.h" |
41 |
– |
#include "list.h" |
41 |
|
#include "s_log.h" |
42 |
|
#include "memory.h" |
43 |
|
#include "hook.h" |
45 |
– |
#include "irc_getnameinfo.h" |
44 |
|
#include "packet.h" |
45 |
|
|
48 |
– |
#define LOG_BUFSIZE 2048 |
46 |
|
|
47 |
|
struct Callback *iosend_cb = NULL; |
48 |
|
struct Callback *iosendctrl_cb = NULL; |
49 |
+ |
static unsigned int current_serial = 0; |
50 |
|
|
53 |
– |
static void send_message(struct Client *, char *, int); |
54 |
– |
static void send_message_remote(struct Client *, struct Client *, char *, int); |
55 |
– |
|
56 |
– |
static unsigned long current_serial = 0L; |
51 |
|
|
52 |
|
/* send_format() |
53 |
|
* |
81 |
|
|
82 |
|
lsendbuf[len++] = '\r'; |
83 |
|
lsendbuf[len++] = '\n'; |
84 |
< |
return (len); |
84 |
> |
return len; |
85 |
|
} |
86 |
|
|
87 |
|
/* |
161 |
|
return; |
162 |
|
} |
163 |
|
|
170 |
– |
if (ServerInfo.hub && IsCapable(to, CAP_LL)) |
171 |
– |
{ |
172 |
– |
if (((from->lazyLinkClientExists & |
173 |
– |
to->localClient->serverMask) == 0)) |
174 |
– |
client_burst_if_needed(to, from); |
175 |
– |
} |
176 |
– |
|
164 |
|
/* Optimize by checking if (from && to) before everything */ |
165 |
|
/* we set to->from up there.. */ |
166 |
|
|
180 |
|
from->name, from->username, from->host, |
181 |
|
to->from->name); |
182 |
|
|
183 |
< |
sendto_server(NULL, to, NULL, CAP_TS6, NOCAPS, NOFLAGS, |
183 |
> |
sendto_server(NULL, NULL, CAP_TS6, NOCAPS, |
184 |
|
":%s KILL %s :%s (%s[%s@%s] Ghosted %s)", |
185 |
|
me.id, to->name, me.name, to->name, |
186 |
|
to->username, to->host, to->from->name); |
187 |
< |
sendto_server(NULL, to, NULL, NOCAPS, CAP_TS6, NOFLAGS, |
187 |
> |
sendto_server(NULL, NULL, NOCAPS, CAP_TS6, |
188 |
|
":%s KILL %s :%s (%s[%s@%s] Ghosted %s)", |
189 |
|
me.name, to->name, me.name, to->name, |
190 |
|
to->username, to->host, to->from->name); |
288 |
|
retlen = send(to->localClient->fd.fd, first->data, first->size, 0); |
289 |
|
|
290 |
|
if (retlen <= 0) |
304 |
– |
{ |
305 |
– |
#ifdef _WIN32 |
306 |
– |
errno = WSAGetLastError(); |
307 |
– |
#endif |
291 |
|
break; |
309 |
– |
} |
292 |
|
|
293 |
|
dbuf_delete(&to->localClient->buf_sendq, retlen); |
294 |
|
|
456 |
|
char remote_buf[IRCD_BUFSIZE]; |
457 |
|
char uid_buf[IRCD_BUFSIZE]; |
458 |
|
int local_len, remote_len, uid_len; |
459 |
< |
dlink_node *ptr; |
478 |
< |
dlink_node *ptr_next; |
479 |
< |
struct Client *target_p; |
459 |
> |
dlink_node *ptr = NULL, *ptr_next = NULL; |
460 |
|
|
461 |
|
if (IsServer(from)) |
462 |
|
local_len = ircsprintf(local_buf, ":%s %s %s ", |
487 |
|
|
488 |
|
DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->members.head) |
489 |
|
{ |
490 |
< |
target_p = ((struct Membership *)ptr->data)->client_p; |
491 |
< |
assert(target_p != NULL); |
490 |
> |
struct Client *target_p = ((struct Membership *)ptr->data)->client_p; |
491 |
> |
|
492 |
> |
assert(IsClient(target_p)); |
493 |
|
|
494 |
|
if (IsDefunct(target_p) || IsDeaf(target_p) || target_p->from == one) |
495 |
|
continue; |
496 |
|
|
497 |
< |
if (MyClient(target_p)) |
497 |
> |
if (MyConnect(target_p)) |
498 |
|
{ |
499 |
< |
if (target_p->serial != current_serial) |
499 |
> |
if (target_p->localClient->serial != current_serial) |
500 |
|
{ |
501 |
|
send_message(target_p, local_buf, local_len); |
502 |
< |
target_p->serial = current_serial; |
502 |
> |
target_p->localClient->serial = current_serial; |
503 |
|
} |
504 |
|
} |
505 |
|
else |
507 |
|
/* Now check whether a message has been sent to this |
508 |
|
* remote link already |
509 |
|
*/ |
510 |
< |
if (target_p->from->serial != current_serial) |
510 |
> |
if (target_p->from->localClient->serial != current_serial) |
511 |
|
{ |
512 |
|
if (IsCapable(target_p->from, CAP_TS6)) |
513 |
|
send_message_remote(target_p->from, from, uid_buf, uid_len); |
514 |
|
else |
515 |
|
send_message_remote(target_p->from, from, remote_buf, remote_len); |
516 |
< |
target_p->from->serial = current_serial; |
516 |
> |
target_p->from->localClient->serial = current_serial; |
517 |
|
} |
518 |
|
} |
519 |
|
} |
522 |
|
/* sendto_server() |
523 |
|
* |
524 |
|
* inputs - pointer to client to NOT send to |
525 |
< |
* - pointer to source client required by LL (if any) |
545 |
< |
* - pointer to channel required by LL (if any) |
525 |
> |
* - pointer to channel |
526 |
|
* - caps or'd together which must ALL be present |
527 |
|
* - caps or'd together which must ALL NOT be present |
548 |
– |
* - LL flags: LL_ICLIENT | LL_ICHAN |
528 |
|
* - printf style format string |
529 |
|
* - args to format string |
530 |
|
* output - NONE |
531 |
|
* side effects - Send a message to all connected servers, except the |
532 |
|
* client 'one' (if non-NULL), as long as the servers |
533 |
|
* support ALL capabs in 'caps', and NO capabs in 'nocaps'. |
555 |
– |
* If the server is a lazylink client, then it must know |
556 |
– |
* about source_p if non-NULL (unless LL_ICLIENT is specified, |
557 |
– |
* when source_p will be introduced where required) and |
558 |
– |
* chptr if non-NULL (unless LL_ICHANNEL is specified, when |
559 |
– |
* chptr will be introduced where required). |
560 |
– |
* Note: nothing will be introduced to a LazyLeaf unless |
561 |
– |
* the message is actually sent. |
534 |
|
* |
535 |
|
* This function was written in an attempt to merge together the other |
536 |
|
* billion sendto_*serv*() functions, which sprung up with capabs, |
538 |
|
* -davidt |
539 |
|
*/ |
540 |
|
void |
541 |
< |
sendto_server(struct Client *one, struct Client *source_p, |
542 |
< |
struct Channel *chptr, unsigned long caps, |
543 |
< |
unsigned long nocaps, unsigned long llflags, |
541 |
> |
sendto_server(struct Client *one, const struct Channel *chptr, |
542 |
> |
const unsigned int caps, |
543 |
> |
const unsigned int nocaps, |
544 |
|
const char *format, ...) |
545 |
|
{ |
546 |
|
va_list args; |
547 |
< |
struct Client *client_p; |
576 |
< |
dlink_node *ptr; |
547 |
> |
dlink_node *ptr = NULL; |
548 |
|
char buffer[IRCD_BUFSIZE]; |
549 |
< |
int len; |
549 |
> |
int len = 0; |
550 |
|
|
551 |
< |
if (chptr != NULL) |
552 |
< |
{ |
582 |
< |
if (chptr->chname[0] != '#') |
583 |
< |
return; |
584 |
< |
} |
551 |
> |
if (chptr && chptr->chname[0] != '#') |
552 |
> |
return; |
553 |
|
|
554 |
|
va_start(args, format); |
555 |
|
len = send_format(buffer, IRCD_BUFSIZE, format, args); |
557 |
|
|
558 |
|
DLINK_FOREACH(ptr, serv_list.head) |
559 |
|
{ |
560 |
< |
client_p = ptr->data; |
560 |
> |
struct Client *client_p = ptr->data; |
561 |
|
|
562 |
|
/* If dead already skip */ |
563 |
|
if (IsDead(client_p)) |
572 |
|
if ((client_p->localClient->caps & nocaps) != 0) |
573 |
|
continue; |
574 |
|
|
607 |
– |
if (ServerInfo.hub && IsCapable(client_p, CAP_LL)) |
608 |
– |
{ |
609 |
– |
/* check LL channel */ |
610 |
– |
if (chptr != NULL && |
611 |
– |
((chptr->lazyLinkChannelExists & |
612 |
– |
client_p->localClient->serverMask) == 0)) |
613 |
– |
{ |
614 |
– |
/* Only introduce the channel if we really will send this message */ |
615 |
– |
if (!(llflags & LL_ICLIENT) && source_p && |
616 |
– |
((source_p->lazyLinkClientExists & |
617 |
– |
client_p->localClient->serverMask) == 0)) |
618 |
– |
continue; /* we can't introduce the unknown source_p, skip */ |
619 |
– |
|
620 |
– |
if (llflags & LL_ICHAN) |
621 |
– |
burst_channel(client_p, chptr); |
622 |
– |
else |
623 |
– |
continue; /* we can't introduce the unknown chptr, skip */ |
624 |
– |
} |
625 |
– |
/* check LL client */ |
626 |
– |
if (source_p && |
627 |
– |
((source_p->lazyLinkClientExists & |
628 |
– |
client_p->localClient->serverMask) == 0)) |
629 |
– |
{ |
630 |
– |
if (llflags & LL_ICLIENT) |
631 |
– |
client_burst_if_needed(client_p,source_p); |
632 |
– |
else |
633 |
– |
continue; /* we can't introduce the unknown source_p, skip */ |
634 |
– |
} |
635 |
– |
} |
575 |
|
send_message(client_p, buffer, len); |
576 |
|
} |
577 |
|
} |
609 |
|
chptr = ((struct Membership *) cptr->data)->chptr; |
610 |
|
assert(chptr != NULL); |
611 |
|
|
612 |
< |
DLINK_FOREACH(uptr, chptr->locmembers.head) |
612 |
> |
DLINK_FOREACH(uptr, chptr->members.head) |
613 |
|
{ |
614 |
|
ms = uptr->data; |
615 |
|
target_p = ms->client_p; |
616 |
|
assert(target_p != NULL); |
617 |
|
|
618 |
< |
if (target_p == user || IsDefunct(target_p) || |
619 |
< |
target_p->serial == current_serial) |
618 |
> |
if (!MyConnect(target_p) || target_p == user || IsDefunct(target_p) || |
619 |
> |
target_p->localClient->serial == current_serial) |
620 |
|
continue; |
621 |
|
|
622 |
< |
target_p->serial = current_serial; |
622 |
> |
target_p->localClient->serial = current_serial; |
623 |
|
send_message(target_p, buffer, len); |
624 |
|
} |
625 |
|
} |
626 |
|
|
627 |
|
if (touser && MyConnect(user) && !IsDead(user) && |
628 |
< |
user->serial != current_serial) |
628 |
> |
user->localClient->serial != current_serial) |
629 |
|
send_message(user, buffer, len); |
630 |
|
} |
631 |
|
|
654 |
|
len = send_format(buffer, IRCD_BUFSIZE, pattern, args); |
655 |
|
va_end(args); |
656 |
|
|
657 |
< |
DLINK_FOREACH(ptr, chptr->locmembers.head) |
657 |
> |
DLINK_FOREACH(ptr, chptr->members.head) |
658 |
|
{ |
659 |
|
ms = ptr->data; |
660 |
|
target_p = ms->client_p; |
662 |
|
if (type != 0 && (ms->flags & type) == 0) |
663 |
|
continue; |
664 |
|
|
665 |
< |
if (IsDefunct(target_p) || (nodeaf && IsDeaf(target_p))) |
665 |
> |
if (!MyConnect(target_p) || IsDefunct(target_p) || |
666 |
> |
(nodeaf && IsDeaf(target_p))) |
667 |
|
continue; |
668 |
|
|
669 |
|
send_message(target_p, buffer, len); |
697 |
|
len = send_format(buffer, IRCD_BUFSIZE, pattern, args); |
698 |
|
va_end(args); |
699 |
|
|
700 |
< |
DLINK_FOREACH(ptr, chptr->locmembers.head) |
700 |
> |
DLINK_FOREACH(ptr, chptr->members.head) |
701 |
|
{ |
702 |
|
ms = ptr->data; |
703 |
|
target_p = ms->client_p; |
705 |
|
if (type != 0 && (ms->flags & type) == 0) |
706 |
|
continue; |
707 |
|
|
708 |
< |
if (target_p == one || IsDefunct(target_p) || IsDeaf(target_p)) |
708 |
> |
if (!MyConnect(target_p) || target_p == one || |
709 |
> |
IsDefunct(target_p) || IsDeaf(target_p)) |
710 |
|
continue; |
711 |
|
send_message(target_p, buffer, len); |
712 |
|
} |
725 |
|
* remote to this server. |
726 |
|
*/ |
727 |
|
void |
728 |
< |
sendto_channel_remote(struct Client *one, struct Client *from, int type, int caps, |
729 |
< |
int nocaps, struct Channel *chptr, const char *pattern, ...) |
728 |
> |
sendto_channel_remote(struct Client *one, struct Client *from, int type, |
729 |
> |
const unsigned int caps, const unsigned int nocaps, |
730 |
> |
struct Channel *chptr, const char *pattern, ...) |
731 |
|
{ |
732 |
|
va_list args; |
733 |
|
char buffer[IRCD_BUFSIZE]; |
758 |
|
((target_p->from->localClient->caps & caps) != caps) || |
759 |
|
((target_p->from->localClient->caps & nocaps) != 0)) |
760 |
|
continue; |
761 |
< |
if (target_p->from->serial != current_serial) |
761 |
> |
if (target_p->from->localClient->serial != current_serial) |
762 |
|
{ |
763 |
|
send_message(target_p, buffer, len); |
764 |
< |
target_p->from->serial = current_serial; |
764 |
> |
target_p->from->localClient->serial = current_serial; |
765 |
|
} |
766 |
|
} |
767 |
|
} |
787 |
|
match_it(const struct Client *one, const char *mask, int what) |
788 |
|
{ |
789 |
|
if (what == MATCH_HOST) |
790 |
< |
return(match(mask, one->host)); |
790 |
> |
return match(mask, one->host); |
791 |
|
|
792 |
< |
return(match(mask, one->servptr->name)); |
792 |
> |
return match(mask, one->servptr->name); |
793 |
|
} |
794 |
|
|
795 |
|
/* sendto_match_butone() |
887 |
|
vsnprintf(buffer, sizeof(buffer), pattern, args); |
888 |
|
va_end(args); |
889 |
|
|
890 |
< |
current_serial++; |
890 |
> |
++current_serial; |
891 |
|
|
892 |
|
DLINK_FOREACH(ptr, global_serv_list.head) |
893 |
|
{ |
897 |
|
if (IsMe(target_p) || target_p->from == source_p->from) |
898 |
|
continue; |
899 |
|
|
900 |
< |
if (target_p->from->serial == current_serial) |
900 |
> |
if (target_p->from->localClient->serial == current_serial) |
901 |
|
continue; |
902 |
|
|
903 |
|
if (match(mask, target_p->name)) |
906 |
|
* if we set the serial here, then we'll never do a |
907 |
|
* match() again, if !IsCapable() |
908 |
|
*/ |
909 |
< |
target_p->from->serial = current_serial; |
909 |
> |
target_p->from->localClient->serial = current_serial; |
910 |
|
found++; |
911 |
|
|
912 |
|
if (!IsCapable(target_p->from, cap)) |
974 |
|
void |
975 |
|
sendto_realops_flags(unsigned int flags, int level, const char *pattern, ...) |
976 |
|
{ |
977 |
< |
struct Client *client_p; |
977 |
> |
dlink_node *ptr = NULL; |
978 |
|
char nbuf[IRCD_BUFSIZE]; |
1037 |
– |
dlink_node *ptr; |
979 |
|
va_list args; |
980 |
|
|
981 |
|
va_start(args, pattern); |
984 |
|
|
985 |
|
DLINK_FOREACH(ptr, oper_list.head) |
986 |
|
{ |
987 |
< |
client_p = ptr->data; |
987 |
> |
struct Client *client_p = ptr->data; |
988 |
|
assert(client_p->umodes & UMODE_OPER); |
989 |
|
|
990 |
|
/* If we're sending it to opers and theyre an admin, skip. |
1000 |
|
} |
1001 |
|
} |
1002 |
|
|
1003 |
+ |
void |
1004 |
+ |
sendto_globops_flags(unsigned int flags, int level, const char *pattern, ...) |
1005 |
+ |
{ |
1006 |
+ |
dlink_node *ptr = NULL; |
1007 |
+ |
char nbuf[IRCD_BUFSIZE]; |
1008 |
+ |
va_list args; |
1009 |
+ |
|
1010 |
+ |
va_start(args, pattern); |
1011 |
+ |
vsnprintf(nbuf, IRCD_BUFSIZE, pattern, args); |
1012 |
+ |
va_end(args); |
1013 |
+ |
|
1014 |
+ |
DLINK_FOREACH(ptr, oper_list.head) |
1015 |
+ |
{ |
1016 |
+ |
struct Client *client_p = ptr->data; |
1017 |
+ |
assert(client_p->umodes & UMODE_OPER); |
1018 |
+ |
|
1019 |
+ |
/* If we're sending it to opers and theyre an admin, skip. |
1020 |
+ |
* If we're sending it to admins, and theyre not, skip. |
1021 |
+ |
*/ |
1022 |
+ |
if (((level == L_ADMIN) && !IsAdmin(client_p)) || |
1023 |
+ |
((level == L_OPER) && IsAdmin(client_p))) |
1024 |
+ |
continue; |
1025 |
+ |
|
1026 |
+ |
if (client_p->umodes & flags) |
1027 |
+ |
sendto_one(client_p, ":%s NOTICE %s :*** Global -- %s", |
1028 |
+ |
me.name, client_p->name, nbuf); |
1029 |
+ |
} |
1030 |
+ |
} |
1031 |
+ |
|
1032 |
|
/* sendto_wallops_flags() |
1033 |
|
* |
1034 |
|
* inputs - flag types of messages to show to real opers |
1041 |
|
sendto_wallops_flags(unsigned int flags, struct Client *source_p, |
1042 |
|
const char *pattern, ...) |
1043 |
|
{ |
1044 |
< |
struct Client *client_p; |
1075 |
< |
dlink_node *ptr; |
1044 |
> |
dlink_node *ptr = NULL; |
1045 |
|
va_list args; |
1046 |
|
char buffer[IRCD_BUFSIZE]; |
1047 |
|
int len; |
1058 |
|
|
1059 |
|
DLINK_FOREACH(ptr, oper_list.head) |
1060 |
|
{ |
1061 |
< |
client_p = ptr->data; |
1061 |
> |
struct Client *client_p = ptr->data; |
1062 |
|
assert(client_p->umodes & UMODE_OPER); |
1063 |
|
|
1064 |
|
if ((client_p->umodes & flags) && !IsDefunct(client_p)) |
1077 |
|
ts_warn(const char *pattern, ...) |
1078 |
|
{ |
1079 |
|
va_list args; |
1080 |
< |
char buffer[LOG_BUFSIZE]; |
1080 |
> |
char buffer[IRCD_BUFSIZE]; |
1081 |
|
static time_t last = 0; |
1082 |
|
static int warnings = 0; |
1083 |
|
|
1100 |
|
} |
1101 |
|
|
1102 |
|
va_start(args, pattern); |
1103 |
< |
vsprintf_irc(buffer, pattern, args); |
1103 |
> |
vsnprintf(buffer, sizeof(buffer), pattern, args); |
1104 |
|
va_end(args); |
1105 |
|
|
1106 |
|
sendto_realops_flags(UMODE_ALL, L_ALL, "%s", buffer); |
1154 |
|
{ |
1155 |
|
va_list args; |
1156 |
|
int have_uid = 0; |
1157 |
< |
struct Client *client_p; |
1189 |
< |
dlink_node *ptr; |
1157 |
> |
dlink_node *ptr = NULL; |
1158 |
|
char buf_uid[IRCD_BUFSIZE], buf_nick[IRCD_BUFSIZE]; |
1159 |
< |
int len_uid = 0, len_nick; |
1159 |
> |
int len_uid = 0, len_nick = 0; |
1160 |
|
|
1161 |
< |
if (HasID(source_p) && (me.id[0] != '\0')) |
1161 |
> |
if (HasID(source_p)) |
1162 |
|
{ |
1163 |
|
have_uid = 1; |
1164 |
|
va_start(args, pattern); |
1176 |
|
|
1177 |
|
DLINK_FOREACH(ptr, serv_list.head) |
1178 |
|
{ |
1179 |
< |
client_p = ptr->data; |
1179 |
> |
struct Client *client_p = ptr->data; |
1180 |
|
|
1181 |
|
if (one != NULL && (client_p == one->from)) |
1182 |
|
continue; |
1183 |
|
if (IsDefunct(client_p)) |
1184 |
|
continue; |
1185 |
|
|
1186 |
< |
/* XXX perhaps IsCapable should test for localClient itself ? -db */ |
1187 |
< |
if (client_p->localClient == NULL || !IsCapable(client_p, CAP_LL) || |
1188 |
< |
!ServerInfo.hub || |
1189 |
< |
(source_p->lazyLinkClientExists & client_p->localClient->serverMask)) |
1222 |
< |
{ |
1223 |
< |
if (have_uid && IsCapable(client_p, CAP_TS6)) |
1224 |
< |
send_message(client_p, buf_uid, len_uid); |
1225 |
< |
else |
1226 |
< |
send_message(client_p, buf_nick, len_nick); |
1227 |
< |
} |
1186 |
> |
if (have_uid && IsCapable(client_p, CAP_TS6)) |
1187 |
> |
send_message(client_p, buf_uid, len_uid); |
1188 |
> |
else |
1189 |
> |
send_message(client_p, buf_nick, len_nick); |
1190 |
|
} |
1191 |
|
} |