| 1 |
|
/* |
| 2 |
|
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
| 3 |
|
* |
| 4 |
< |
* Copyright (c) 1997-2014 ircd-hybrid development team |
| 4 |
> |
* Copyright (c) 1997-2015 ircd-hybrid development team |
| 5 |
|
* |
| 6 |
|
* This program is free software; you can redistribute it and/or modify |
| 7 |
|
* it under the terms of the GNU General Public License as published by |
| 32 |
|
#include "dbuf.h" |
| 33 |
|
#include "irc_string.h" |
| 34 |
|
#include "ircd.h" |
| 35 |
– |
#include "numeric.h" |
| 36 |
– |
#include "fdlist.h" |
| 35 |
|
#include "s_bsd.h" |
| 36 |
|
#include "server.h" |
| 37 |
< |
#include "conf.h" |
| 37 |
> |
#include "conf_class.h" |
| 38 |
|
#include "log.h" |
| 41 |
– |
#include "memory.h" |
| 42 |
– |
#include "packet.h" |
| 39 |
|
|
| 40 |
|
|
| 41 |
|
static uint64_t current_serial; |
| 84 |
|
{ |
| 85 |
|
assert(!IsMe(to)); |
| 86 |
|
assert(to != &me); |
| 87 |
+ |
assert(MyConnect(to)); |
| 88 |
|
|
| 89 |
|
if (dbuf_length(&to->connection->buf_sendq) + buf->size > get_sendq(&to->connection->confs)) |
| 90 |
|
{ |
| 94 |
|
get_client_name(to, HIDE_IP), |
| 95 |
|
(unsigned long)(dbuf_length(&to->connection->buf_sendq) + buf->size), |
| 96 |
|
get_sendq(&to->connection->confs)); |
| 97 |
+ |
|
| 98 |
|
if (IsClient(to)) |
| 99 |
< |
SetSendQExceeded(to); |
| 99 |
> |
AddFlag(to, FLAGS_SENDQEX); |
| 100 |
|
|
| 101 |
|
dead_link_on_write(to, 0); |
| 102 |
|
return; |
| 128 |
|
static void |
| 129 |
|
send_message_remote(struct Client *to, struct Client *from, struct dbuf_block *buf) |
| 130 |
|
{ |
| 131 |
< |
to = to->from; |
| 132 |
< |
|
| 133 |
< |
if (!MyConnect(to)) |
| 134 |
< |
{ |
| 137 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 138 |
< |
"Server send message to %s [%s] dropped from %s(Not local server)", |
| 139 |
< |
to->name, to->from->name, from->name); |
| 140 |
< |
return; |
| 141 |
< |
} |
| 142 |
< |
|
| 143 |
< |
/* Optimize by checking if (from && to) before everything */ |
| 144 |
< |
/* we set to->from up there.. */ |
| 131 |
> |
assert(MyConnect(to)); |
| 132 |
> |
assert(IsServer(to)); |
| 133 |
> |
assert(!IsMe(to)); |
| 134 |
> |
assert(to->from == to); |
| 135 |
|
|
| 136 |
< |
if (!MyClient(from) && IsClient(to) && (to == from->from)) |
| 136 |
> |
if (to == from->from) |
| 137 |
|
{ |
| 148 |
– |
if (IsServer(from)) |
| 149 |
– |
{ |
| 150 |
– |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 151 |
– |
"Send message to %s [%s] dropped from %s(Fake Dir)", |
| 152 |
– |
to->name, to->from->name, from->name); |
| 153 |
– |
return; |
| 154 |
– |
} |
| 155 |
– |
|
| 138 |
|
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 139 |
< |
"Ghosted: %s[%s@%s] from %s[%s@%s] (%s)", |
| 140 |
< |
to->name, to->username, to->host, |
| 159 |
< |
from->name, from->username, from->host, |
| 160 |
< |
to->from->name); |
| 161 |
< |
|
| 162 |
< |
sendto_server(NULL, NOCAPS, NOCAPS, |
| 163 |
< |
":%s KILL %s :%s (%s[%s@%s] Ghosted %s)", |
| 164 |
< |
me.id, to->id, me.name, to->name, |
| 165 |
< |
to->username, to->host, to->from->name); |
| 166 |
< |
|
| 167 |
< |
AddFlag(to, FLAGS_KILLED); |
| 168 |
< |
|
| 169 |
< |
if (IsClient(from)) |
| 170 |
< |
sendto_one_numeric(from, &me, ERR_GHOSTEDCLIENT, to->name, |
| 171 |
< |
to->username, to->host, to->from); |
| 172 |
< |
|
| 173 |
< |
exit_client(to, "Ghosted client"); |
| 139 |
> |
"Send message to %s dropped from %s (Fake Dir)", |
| 140 |
> |
to->name, from->name); |
| 141 |
|
return; |
| 142 |
|
} |
| 143 |
|
|
| 151 |
|
void |
| 152 |
|
sendq_unblocked(fde_t *fd, void *data) |
| 153 |
|
{ |
| 154 |
< |
struct Client *client_p = data; |
| 154 |
> |
struct Client *const client_p = data; |
| 155 |
|
assert(fd == &client_p->connection->fd); |
| 156 |
|
|
| 157 |
|
DelFlag(client_p, FLAGS_BLOCKED); |
| 246 |
|
void |
| 247 |
|
send_queued_all(void) |
| 248 |
|
{ |
| 249 |
< |
dlink_node *ptr; |
| 249 |
> |
dlink_node *node = NULL; |
| 250 |
|
|
| 251 |
|
/* Servers are processed first, mainly because this can generate |
| 252 |
|
* a notice to opers, which is to be delivered by this function. |
| 253 |
|
*/ |
| 254 |
< |
DLINK_FOREACH(ptr, local_server_list.head) |
| 255 |
< |
send_queued_write(ptr->data); |
| 254 |
> |
DLINK_FOREACH(node, local_server_list.head) |
| 255 |
> |
send_queued_write(node->data); |
| 256 |
|
|
| 257 |
< |
DLINK_FOREACH(ptr, unknown_list.head) |
| 258 |
< |
send_queued_write(ptr->data); |
| 257 |
> |
DLINK_FOREACH(node, unknown_list.head) |
| 258 |
> |
send_queued_write(node->data); |
| 259 |
|
|
| 260 |
< |
DLINK_FOREACH(ptr, local_client_list.head) |
| 261 |
< |
send_queued_write(ptr->data); |
| 260 |
> |
DLINK_FOREACH(node, local_client_list.head) |
| 261 |
> |
send_queued_write(node->data); |
| 262 |
|
|
| 263 |
|
/* NOTE: This can still put clients on aborted_list; unfortunately, |
| 264 |
|
* exit_aborted_clients takes precedence over send_queued_all, |
| 375 |
|
{ |
| 376 |
|
va_list alocal, aremote; |
| 377 |
|
struct dbuf_block *local_buf, *remote_buf; |
| 378 |
< |
dlink_node *ptr = NULL, *ptr_next = NULL; |
| 378 |
> |
dlink_node *node = NULL; |
| 379 |
|
|
| 380 |
|
local_buf = dbuf_alloc(), remote_buf = dbuf_alloc(); |
| 381 |
|
|
| 396 |
|
|
| 397 |
|
++current_serial; |
| 398 |
|
|
| 399 |
< |
DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->members.head) |
| 399 |
> |
DLINK_FOREACH(node, chptr->members.head) |
| 400 |
|
{ |
| 401 |
< |
struct Membership *ms = ptr->data; |
| 402 |
< |
struct Client *target_p = ms->client_p; |
| 401 |
> |
struct Membership *member = node->data; |
| 402 |
> |
struct Client *target_p = member->client_p; |
| 403 |
|
|
| 404 |
|
assert(IsClient(target_p)); |
| 405 |
|
|
| 407 |
|
(one && target_p->from == one->from)) |
| 408 |
|
continue; |
| 409 |
|
|
| 410 |
< |
if (type && (ms->flags & type) == 0) |
| 410 |
> |
if (type && (member->flags & type) == 0) |
| 411 |
|
continue; |
| 412 |
|
|
| 413 |
|
if (MyConnect(target_p)) |
| 414 |
|
send_message(target_p, local_buf); |
| 415 |
|
else if (target_p->from->connection->serial != current_serial) |
| 416 |
|
send_message_remote(target_p->from, from, remote_buf); |
| 417 |
+ |
|
| 418 |
|
target_p->from->connection->serial = current_serial; |
| 419 |
|
} |
| 420 |
|
|
| 447 |
|
const char *format, ...) |
| 448 |
|
{ |
| 449 |
|
va_list args; |
| 450 |
< |
dlink_node *ptr = NULL; |
| 451 |
< |
struct dbuf_block *buffer; |
| 484 |
< |
|
| 485 |
< |
buffer = dbuf_alloc(); |
| 450 |
> |
dlink_node *node = NULL; |
| 451 |
> |
struct dbuf_block *buffer = dbuf_alloc(); |
| 452 |
|
|
| 453 |
|
va_start(args, format); |
| 454 |
|
send_format(buffer, format, args); |
| 455 |
|
va_end(args); |
| 456 |
|
|
| 457 |
< |
DLINK_FOREACH(ptr, local_server_list.head) |
| 457 |
> |
DLINK_FOREACH(node, local_server_list.head) |
| 458 |
|
{ |
| 459 |
< |
struct Client *client_p = ptr->data; |
| 459 |
> |
struct Client *client_p = node->data; |
| 460 |
|
|
| 461 |
|
/* If dead already skip */ |
| 462 |
|
if (IsDead(client_p)) |
| 463 |
|
continue; |
| 464 |
+ |
|
| 465 |
|
/* check against 'one' */ |
| 466 |
|
if (one && (client_p == one->from)) |
| 467 |
|
continue; |
| 468 |
+ |
|
| 469 |
|
/* check we have required capabs */ |
| 470 |
|
if ((client_p->connection->caps & caps) != caps) |
| 471 |
|
continue; |
| 472 |
+ |
|
| 473 |
|
/* check we don't have any forbidden capabs */ |
| 474 |
|
if ((client_p->connection->caps & nocaps)) |
| 475 |
|
continue; |
| 497 |
|
dlink_node *uptr; |
| 498 |
|
dlink_node *cptr; |
| 499 |
|
struct Channel *chptr; |
| 500 |
< |
struct Membership *ms; |
| 500 |
> |
struct Membership *member; |
| 501 |
|
struct Client *target_p; |
| 502 |
< |
struct dbuf_block *buffer; |
| 534 |
< |
|
| 535 |
< |
buffer = dbuf_alloc(); |
| 502 |
> |
struct dbuf_block *buffer = dbuf_alloc(); |
| 503 |
|
|
| 504 |
|
va_start(args, pattern); |
| 505 |
|
send_format(buffer, pattern, args); |
| 513 |
|
|
| 514 |
|
DLINK_FOREACH(uptr, chptr->locmembers.head) |
| 515 |
|
{ |
| 516 |
< |
ms = uptr->data; |
| 517 |
< |
target_p = ms->client_p; |
| 516 |
> |
member = uptr->data; |
| 517 |
> |
target_p = member->client_p; |
| 518 |
|
|
| 519 |
|
if (target_p == user || IsDefunct(target_p) || |
| 520 |
|
target_p->connection->serial == current_serial) |
| 539 |
|
/* sendto_channel_local() |
| 540 |
|
* |
| 541 |
|
* inputs - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE |
| 575 |
– |
* - whether to ignore +D clients (YES/NO) |
| 542 |
|
* - pointer to channel to send to |
| 543 |
|
* - var args pattern |
| 544 |
|
* output - NONE |
| 546 |
|
* locally connected to this server. |
| 547 |
|
*/ |
| 548 |
|
void |
| 549 |
< |
sendto_channel_local(unsigned int type, int nodeaf, struct Channel *chptr, |
| 549 |
> |
sendto_channel_local(unsigned int type, struct Channel *chptr, |
| 550 |
|
const char *pattern, ...) |
| 551 |
|
{ |
| 552 |
|
va_list args; |
| 553 |
< |
dlink_node *ptr = NULL; |
| 554 |
< |
struct dbuf_block *buffer; |
| 589 |
< |
|
| 590 |
< |
buffer = dbuf_alloc(); |
| 553 |
> |
dlink_node *node = NULL; |
| 554 |
> |
struct dbuf_block *buffer = dbuf_alloc(); |
| 555 |
|
|
| 556 |
|
va_start(args, pattern); |
| 557 |
|
send_format(buffer, pattern, args); |
| 558 |
|
va_end(args); |
| 559 |
|
|
| 560 |
< |
DLINK_FOREACH(ptr, chptr->locmembers.head) |
| 560 |
> |
DLINK_FOREACH(node, chptr->locmembers.head) |
| 561 |
|
{ |
| 562 |
< |
struct Membership *ms = ptr->data; |
| 563 |
< |
struct Client *target_p = ms->client_p; |
| 562 |
> |
struct Membership *member = node->data; |
| 563 |
> |
struct Client *target_p = member->client_p; |
| 564 |
|
|
| 565 |
< |
if (type && (ms->flags & type) == 0) |
| 565 |
> |
if (type && (member->flags & type) == 0) |
| 566 |
|
continue; |
| 567 |
|
|
| 568 |
< |
if (IsDefunct(target_p) || |
| 605 |
< |
(nodeaf && HasUMode(target_p, UMODE_DEAF))) |
| 568 |
> |
if (IsDefunct(target_p)) |
| 569 |
|
continue; |
| 570 |
|
|
| 571 |
|
send_message(target_p, buffer); |
| 591 |
|
struct Channel *chptr, const char *pattern, ...) |
| 592 |
|
{ |
| 593 |
|
va_list args; |
| 594 |
< |
dlink_node *ptr = NULL; |
| 594 |
> |
dlink_node *node = NULL; |
| 595 |
|
struct dbuf_block *buffer = dbuf_alloc(); |
| 596 |
|
|
| 597 |
|
va_start(args, pattern); |
| 598 |
|
send_format(buffer, pattern, args); |
| 599 |
|
va_end(args); |
| 600 |
|
|
| 601 |
< |
DLINK_FOREACH(ptr, chptr->locmembers.head) |
| 601 |
> |
DLINK_FOREACH(node, chptr->locmembers.head) |
| 602 |
|
{ |
| 603 |
< |
struct Membership *ms = ptr->data; |
| 604 |
< |
struct Client *target_p = ms->client_p; |
| 603 |
> |
struct Membership *member = node->data; |
| 604 |
> |
struct Client *target_p = member->client_p; |
| 605 |
|
|
| 606 |
|
if (one && target_p == one->from) |
| 607 |
|
continue; |
| 608 |
|
|
| 609 |
< |
if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF)) |
| 609 |
> |
if (IsDefunct(target_p)) |
| 610 |
|
continue; |
| 611 |
|
|
| 612 |
|
if (poscap && HasCap(target_p, poscap) != poscap) |
| 659 |
|
int what, const char *pattern, ...) |
| 660 |
|
{ |
| 661 |
|
va_list alocal, aremote; |
| 662 |
< |
dlink_node *ptr = NULL, *ptr_next = NULL; |
| 662 |
> |
dlink_node *node = NULL; |
| 663 |
|
struct dbuf_block *local_buf, *remote_buf; |
| 664 |
|
|
| 665 |
|
local_buf = dbuf_alloc(), remote_buf = dbuf_alloc(); |
| 675 |
|
va_end(alocal); |
| 676 |
|
|
| 677 |
|
/* scan the local clients */ |
| 678 |
< |
DLINK_FOREACH(ptr, local_client_list.head) |
| 678 |
> |
DLINK_FOREACH(node, local_client_list.head) |
| 679 |
|
{ |
| 680 |
< |
struct Client *client_p = ptr->data; |
| 680 |
> |
struct Client *client_p = node->data; |
| 681 |
|
|
| 682 |
|
if ((!one || client_p != one->from) && !IsDefunct(client_p) && |
| 683 |
|
match_it(client_p, mask, what)) |
| 685 |
|
} |
| 686 |
|
|
| 687 |
|
/* Now scan servers */ |
| 688 |
< |
DLINK_FOREACH_SAFE(ptr, ptr_next, local_server_list.head) |
| 688 |
> |
DLINK_FOREACH(node, local_server_list.head) |
| 689 |
|
{ |
| 690 |
< |
struct Client *client_p = ptr->data; |
| 690 |
> |
struct Client *client_p = node->data; |
| 691 |
|
|
| 692 |
|
/* |
| 693 |
|
* The old code looped through every client on the |
| 735 |
|
const char *pattern, ...) |
| 736 |
|
{ |
| 737 |
|
va_list args; |
| 738 |
< |
dlink_node *ptr = NULL, *ptr_next = NULL; |
| 739 |
< |
struct dbuf_block *buffer; |
| 777 |
< |
|
| 778 |
< |
buffer = dbuf_alloc(); |
| 738 |
> |
dlink_node *node = NULL; |
| 739 |
> |
struct dbuf_block *buffer = dbuf_alloc(); |
| 740 |
|
|
| 741 |
|
dbuf_put_fmt(buffer, ":%s ", source_p->id); |
| 742 |
|
va_start(args, pattern); |
| 745 |
|
|
| 746 |
|
++current_serial; |
| 747 |
|
|
| 748 |
< |
DLINK_FOREACH_SAFE(ptr, ptr_next, global_server_list.head) |
| 748 |
> |
DLINK_FOREACH(node, global_server_list.head) |
| 749 |
|
{ |
| 750 |
< |
struct Client *target_p = ptr->data; |
| 750 |
> |
struct Client *target_p = node->data; |
| 751 |
|
|
| 752 |
|
/* Do not attempt to send to ourselves, or the source */ |
| 753 |
|
if (IsMe(target_p) || target_p->from == source_p->from) |
| 756 |
|
if (target_p->from->connection->serial == current_serial) |
| 757 |
|
continue; |
| 758 |
|
|
| 759 |
< |
if (!match(mask, target_p->name)) |
| 760 |
< |
{ |
| 800 |
< |
/* |
| 801 |
< |
* if we set the serial here, then we'll never do a |
| 802 |
< |
* match() again, if !IsCapable() |
| 803 |
< |
*/ |
| 804 |
< |
target_p->from->connection->serial = current_serial; |
| 759 |
> |
if (match(mask, target_p->name)) |
| 760 |
> |
continue; |
| 761 |
|
|
| 762 |
< |
if (!IsCapable(target_p->from, cap)) |
| 763 |
< |
continue; |
| 762 |
> |
/* |
| 763 |
> |
* If we set the serial here, then we'll never do a |
| 764 |
> |
* match() again, if !IsCapable() |
| 765 |
> |
*/ |
| 766 |
> |
target_p->from->connection->serial = current_serial; |
| 767 |
|
|
| 768 |
< |
send_message_remote(target_p->from, source_p, buffer); |
| 769 |
< |
} |
| 768 |
> |
if (!IsCapable(target_p->from, cap)) |
| 769 |
> |
continue; |
| 770 |
> |
|
| 771 |
> |
send_message_remote(target_p->from, source_p, buffer); |
| 772 |
|
} |
| 773 |
|
|
| 774 |
|
dbuf_ref_free(buffer); |
| 807 |
|
send_format(buffer, pattern, args); |
| 808 |
|
va_end(args); |
| 809 |
|
|
| 810 |
< |
if (MyClient(to)) |
| 810 |
> |
if (MyConnect(to)) |
| 811 |
|
send_message(to, buffer); |
| 812 |
|
else |
| 813 |
< |
send_message_remote(to, from, buffer); |
| 813 |
> |
send_message_remote(to->from, from, buffer); |
| 814 |
|
|
| 815 |
|
dbuf_ref_free(buffer); |
| 816 |
|
} |
| 827 |
|
sendto_realops_flags(unsigned int flags, int level, int type, const char *pattern, ...) |
| 828 |
|
{ |
| 829 |
|
const char *ntype = NULL; |
| 830 |
< |
dlink_node *ptr = NULL; |
| 830 |
> |
dlink_node *node = NULL; |
| 831 |
|
char nbuf[IRCD_BUFSIZE] = ""; |
| 832 |
|
va_list args; |
| 833 |
|
|
| 850 |
|
assert(0); |
| 851 |
|
} |
| 852 |
|
|
| 853 |
< |
DLINK_FOREACH(ptr, oper_list.head) |
| 853 |
> |
DLINK_FOREACH(node, oper_list.head) |
| 854 |
|
{ |
| 855 |
< |
struct Client *client_p = ptr->data; |
| 855 |
> |
struct Client *client_p = node->data; |
| 856 |
|
assert(HasUMode(client_p, UMODE_OPER)); |
| 857 |
|
|
| 858 |
|
/* |
| 884 |
|
|
| 885 |
|
if ((CurrentTime - *rate) < 20) |
| 886 |
|
return; |
| 887 |
+ |
|
| 888 |
|
*rate = CurrentTime; |
| 889 |
|
|
| 890 |
|
va_start(args, pattern); |
| 907 |
|
sendto_wallops_flags(unsigned int flags, struct Client *source_p, |
| 908 |
|
const char *pattern, ...) |
| 909 |
|
{ |
| 910 |
< |
dlink_node *ptr = NULL; |
| 910 |
> |
dlink_node *node = NULL; |
| 911 |
|
va_list args; |
| 912 |
< |
struct dbuf_block *buffer; |
| 951 |
< |
|
| 952 |
< |
buffer = dbuf_alloc(); |
| 912 |
> |
struct dbuf_block *buffer = dbuf_alloc(); |
| 913 |
|
|
| 914 |
|
if (IsClient(source_p)) |
| 915 |
|
dbuf_put_fmt(buffer, ":%s!%s@%s WALLOPS :", source_p->name, source_p->username, source_p->host); |
| 920 |
|
send_format(buffer, pattern, args); |
| 921 |
|
va_end(args); |
| 922 |
|
|
| 923 |
< |
DLINK_FOREACH(ptr, oper_list.head) |
| 923 |
> |
DLINK_FOREACH(node, oper_list.head) |
| 924 |
|
{ |
| 925 |
< |
struct Client *client_p = ptr->data; |
| 925 |
> |
struct Client *client_p = node->data; |
| 926 |
|
assert(client_p->umodes & UMODE_OPER); |
| 927 |
|
|
| 928 |
|
if (HasUMode(client_p, flags) && !IsDefunct(client_p)) |