| 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 |
|
/* |
| 106 |
|
static void |
| 107 |
|
send_message(struct Client *to, char *buf, int len) |
| 108 |
|
{ |
| 109 |
< |
#ifdef INVARIANTS |
| 110 |
< |
if (IsMe(to)) |
| 117 |
< |
{ |
| 118 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 119 |
< |
"Trying to send message to myself!"); |
| 120 |
< |
return; |
| 121 |
< |
} |
| 122 |
< |
#endif |
| 109 |
> |
assert(!IsMe(to)); |
| 110 |
> |
assert(to != &me); |
| 111 |
|
|
| 112 |
|
if (dbuf_length(&to->localClient->buf_sendq) + len > get_sendq(to)) |
| 113 |
|
{ |
| 161 |
|
return; |
| 162 |
|
} |
| 163 |
|
|
| 176 |
– |
if (ServerInfo.hub && IsCapable(to, CAP_LL)) |
| 177 |
– |
{ |
| 178 |
– |
if (((from->lazyLinkClientExists & |
| 179 |
– |
to->localClient->serverMask) == 0)) |
| 180 |
– |
client_burst_if_needed(to, from); |
| 181 |
– |
} |
| 182 |
– |
|
| 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) |
| 310 |
– |
{ |
| 311 |
– |
#ifdef _WIN32 |
| 312 |
– |
errno = WSAGetLastError(); |
| 313 |
– |
#endif |
| 291 |
|
break; |
| 315 |
– |
} |
| 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; |
| 484 |
< |
dlink_node *ptr_next; |
| 485 |
< |
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) |
| 551 |
< |
* - 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 |
| 554 |
– |
* - 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'. |
| 561 |
– |
* If the server is a lazylink client, then it must know |
| 562 |
– |
* about source_p if non-NULL (unless LL_ICLIENT is specified, |
| 563 |
– |
* when source_p will be introduced where required) and |
| 564 |
– |
* chptr if non-NULL (unless LL_ICHANNEL is specified, when |
| 565 |
– |
* chptr will be introduced where required). |
| 566 |
– |
* Note: nothing will be introduced to a LazyLeaf unless |
| 567 |
– |
* 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; |
| 582 |
< |
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 |
< |
{ |
| 588 |
< |
if (chptr->chname[0] != '#') |
| 589 |
< |
return; |
| 590 |
< |
} |
| 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 |
|
|
| 613 |
– |
if (ServerInfo.hub && IsCapable(client_p, CAP_LL)) |
| 614 |
– |
{ |
| 615 |
– |
/* check LL channel */ |
| 616 |
– |
if (chptr != NULL && |
| 617 |
– |
((chptr->lazyLinkChannelExists & |
| 618 |
– |
client_p->localClient->serverMask) == 0)) |
| 619 |
– |
{ |
| 620 |
– |
/* Only introduce the channel if we really will send this message */ |
| 621 |
– |
if (!(llflags & LL_ICLIENT) && source_p && |
| 622 |
– |
((source_p->lazyLinkClientExists & |
| 623 |
– |
client_p->localClient->serverMask) == 0)) |
| 624 |
– |
continue; /* we can't introduce the unknown source_p, skip */ |
| 625 |
– |
|
| 626 |
– |
if (llflags & LL_ICHAN) |
| 627 |
– |
burst_channel(client_p, chptr); |
| 628 |
– |
else |
| 629 |
– |
continue; /* we can't introduce the unknown chptr, skip */ |
| 630 |
– |
} |
| 631 |
– |
/* check LL client */ |
| 632 |
– |
if (source_p && |
| 633 |
– |
((source_p->lazyLinkClientExists & |
| 634 |
– |
client_p->localClient->serverMask) == 0)) |
| 635 |
– |
{ |
| 636 |
– |
if (llflags & LL_ICLIENT) |
| 637 |
– |
client_burst_if_needed(client_p,source_p); |
| 638 |
– |
else |
| 639 |
– |
continue; /* we can't introduce the unknown source_p, skip */ |
| 640 |
– |
} |
| 641 |
– |
} |
| 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]; |
| 1043 |
– |
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. |
| 1012 |
|
sendto_wallops_flags(unsigned int flags, struct Client *source_p, |
| 1013 |
|
const char *pattern, ...) |
| 1014 |
|
{ |
| 1015 |
< |
struct Client *client_p; |
| 1081 |
< |
dlink_node *ptr; |
| 1015 |
> |
dlink_node *ptr = NULL; |
| 1016 |
|
va_list args; |
| 1017 |
|
char buffer[IRCD_BUFSIZE]; |
| 1018 |
|
int len; |
| 1029 |
|
|
| 1030 |
|
DLINK_FOREACH(ptr, oper_list.head) |
| 1031 |
|
{ |
| 1032 |
< |
client_p = ptr->data; |
| 1032 |
> |
struct Client *client_p = ptr->data; |
| 1033 |
|
assert(client_p->umodes & UMODE_OPER); |
| 1034 |
|
|
| 1035 |
|
if ((client_p->umodes & flags) && !IsDefunct(client_p)) |
| 1048 |
|
ts_warn(const char *pattern, ...) |
| 1049 |
|
{ |
| 1050 |
|
va_list args; |
| 1051 |
< |
char buffer[LOG_BUFSIZE]; |
| 1051 |
> |
char buffer[IRCD_BUFSIZE]; |
| 1052 |
|
static time_t last = 0; |
| 1053 |
|
static int warnings = 0; |
| 1054 |
|
|
| 1071 |
|
} |
| 1072 |
|
|
| 1073 |
|
va_start(args, pattern); |
| 1074 |
< |
vsprintf_irc(buffer, pattern, args); |
| 1074 |
> |
vsnprintf(buffer, sizeof(buffer), pattern, args); |
| 1075 |
|
va_end(args); |
| 1076 |
|
|
| 1077 |
|
sendto_realops_flags(UMODE_ALL, L_ALL, "%s", buffer); |
| 1125 |
|
{ |
| 1126 |
|
va_list args; |
| 1127 |
|
int have_uid = 0; |
| 1128 |
< |
struct Client *client_p; |
| 1195 |
< |
dlink_node *ptr; |
| 1128 |
> |
dlink_node *ptr = NULL; |
| 1129 |
|
char buf_uid[IRCD_BUFSIZE], buf_nick[IRCD_BUFSIZE]; |
| 1130 |
< |
int len_uid = 0, len_nick; |
| 1130 |
> |
int len_uid = 0, len_nick = 0; |
| 1131 |
|
|
| 1132 |
< |
if (HasID(source_p) && (me.id[0] != '\0')) |
| 1132 |
> |
if (HasID(source_p)) |
| 1133 |
|
{ |
| 1134 |
|
have_uid = 1; |
| 1135 |
|
va_start(args, pattern); |
| 1147 |
|
|
| 1148 |
|
DLINK_FOREACH(ptr, serv_list.head) |
| 1149 |
|
{ |
| 1150 |
< |
client_p = ptr->data; |
| 1150 |
> |
struct Client *client_p = ptr->data; |
| 1151 |
|
|
| 1152 |
|
if (one != NULL && (client_p == one->from)) |
| 1153 |
|
continue; |
| 1154 |
|
if (IsDefunct(client_p)) |
| 1155 |
|
continue; |
| 1156 |
|
|
| 1157 |
< |
/* XXX perhaps IsCapable should test for localClient itself ? -db */ |
| 1158 |
< |
if (client_p->localClient == NULL || !IsCapable(client_p, CAP_LL) || |
| 1159 |
< |
!ServerInfo.hub || |
| 1160 |
< |
(source_p->lazyLinkClientExists & client_p->localClient->serverMask)) |
| 1228 |
< |
{ |
| 1229 |
< |
if (have_uid && IsCapable(client_p, CAP_TS6)) |
| 1230 |
< |
send_message(client_p, buf_uid, len_uid); |
| 1231 |
< |
else |
| 1232 |
< |
send_message(client_p, buf_nick, len_nick); |
| 1233 |
< |
} |
| 1157 |
> |
if (have_uid && IsCapable(client_p, CAP_TS6)) |
| 1158 |
> |
send_message(client_p, buf_uid, len_uid); |
| 1159 |
> |
else |
| 1160 |
> |
send_message(client_p, buf_nick, len_nick); |
| 1161 |
|
} |
| 1162 |
|
} |