| 15 |
|
* |
| 16 |
|
* You should have received a copy of the GNU General Public License |
| 17 |
|
* along with this program; if not, write to the Free Software |
| 18 |
< |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 18 |
> |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
| 19 |
|
* USA |
| 20 |
|
*/ |
| 21 |
|
|
| 35 |
|
#include "numeric.h" |
| 36 |
|
#include "fdlist.h" |
| 37 |
|
#include "s_bsd.h" |
| 38 |
< |
#include "s_serv.h" |
| 38 |
> |
#include "server.h" |
| 39 |
|
#include "conf.h" |
| 40 |
|
#include "log.h" |
| 41 |
|
#include "memory.h" |
| 42 |
|
#include "packet.h" |
| 43 |
|
|
| 44 |
|
|
| 45 |
< |
static unsigned int current_serial = 0; |
| 45 |
> |
static uint64_t current_serial; |
| 46 |
|
|
| 47 |
|
|
| 48 |
|
/* send_format() |
| 71 |
|
*/ |
| 72 |
|
dbuf_put_args(buffer, pattern, args); |
| 73 |
|
|
| 74 |
< |
if (buffer->size > sizeof(buffer->data) - 2) |
| 75 |
< |
buffer->size = sizeof(buffer->data) - 2; |
| 74 |
> |
if (buffer->size > IRCD_BUFSIZE - 2) |
| 75 |
> |
buffer->size = IRCD_BUFSIZE - 2; |
| 76 |
|
|
| 77 |
|
buffer->data[buffer->size++] = '\r'; |
| 78 |
|
buffer->data[buffer->size++] = '\n'; |
| 89 |
|
assert(!IsMe(to)); |
| 90 |
|
assert(to != &me); |
| 91 |
|
|
| 92 |
< |
if (dbuf_length(&to->localClient->buf_sendq) + buf->size > get_sendq(&to->localClient->confs)) |
| 92 |
> |
if (dbuf_length(&to->connection->buf_sendq) + buf->size > get_sendq(&to->connection->confs)) |
| 93 |
|
{ |
| 94 |
|
if (IsServer(to)) |
| 95 |
|
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 96 |
|
"Max SendQ limit exceeded for %s: %lu > %u", |
| 97 |
|
get_client_name(to, HIDE_IP), |
| 98 |
< |
(unsigned long)(dbuf_length(&to->localClient->buf_sendq) + buf->size), |
| 99 |
< |
get_sendq(&to->localClient->confs)); |
| 98 |
> |
(unsigned long)(dbuf_length(&to->connection->buf_sendq) + buf->size), |
| 99 |
> |
get_sendq(&to->connection->confs)); |
| 100 |
|
if (IsClient(to)) |
| 101 |
|
SetSendQExceeded(to); |
| 102 |
|
|
| 104 |
|
return; |
| 105 |
|
} |
| 106 |
|
|
| 107 |
< |
dbuf_add(&to->localClient->buf_sendq, buf); |
| 107 |
> |
dbuf_add(&to->connection->buf_sendq, buf); |
| 108 |
|
|
| 109 |
|
/* |
| 110 |
|
* Update statistics. The following is slightly incorrect because |
| 111 |
|
* it counts messages even if queued, but bytes only really sent. |
| 112 |
|
* Queued bytes get updated in send_queued_write(). |
| 113 |
|
*/ |
| 114 |
< |
++to->localClient->send.messages; |
| 115 |
< |
++me.localClient->send.messages; |
| 114 |
> |
++to->connection->send.messages; |
| 115 |
> |
++me.connection->send.messages; |
| 116 |
|
|
| 117 |
|
send_queued_write(to); |
| 118 |
|
} |
| 182 |
|
** Called when a socket is ready for writing. |
| 183 |
|
*/ |
| 184 |
|
void |
| 185 |
< |
sendq_unblocked(fde_t *fd, struct Client *client_p) |
| 185 |
> |
sendq_unblocked(fde_t *fd, void *data) |
| 186 |
|
{ |
| 187 |
< |
assert(fd == &client_p->localClient->fd); |
| 187 |
> |
struct Client *client_p = data; |
| 188 |
> |
assert(fd == &client_p->connection->fd); |
| 189 |
> |
|
| 190 |
> |
DelFlag(client_p, FLAGS_BLOCKED); |
| 191 |
|
send_queued_write(client_p); |
| 192 |
|
} |
| 193 |
|
|
| 206 |
|
** Once socket is marked dead, we cannot start writing to it, |
| 207 |
|
** even if the error is removed... |
| 208 |
|
*/ |
| 209 |
< |
if (IsDead(to)) |
| 209 |
> |
if (IsDead(to) || HasFlag(to, FLAGS_BLOCKED)) |
| 210 |
|
return; /* no use calling send() now */ |
| 211 |
|
|
| 212 |
|
/* Next, lets try to write some data */ |
| 213 |
< |
if (dbuf_length(&to->localClient->buf_sendq)) |
| 213 |
> |
if (dbuf_length(&to->connection->buf_sendq)) |
| 214 |
|
{ |
| 215 |
|
do |
| 216 |
|
{ |
| 217 |
< |
struct dbuf_block *first = to->localClient->buf_sendq.blocks.head->data; |
| 217 |
> |
struct dbuf_block *first = to->connection->buf_sendq.blocks.head->data; |
| 218 |
|
|
| 219 |
|
#ifdef HAVE_LIBCRYPTO |
| 220 |
< |
if (to->localClient->fd.ssl) |
| 220 |
> |
if (to->connection->fd.ssl) |
| 221 |
|
{ |
| 222 |
< |
retlen = SSL_write(to->localClient->fd.ssl, first->data + to->localClient->buf_sendq.pos, first->size - to->localClient->buf_sendq.pos); |
| 222 |
> |
retlen = SSL_write(to->connection->fd.ssl, first->data + to->connection->buf_sendq.pos, first->size - to->connection->buf_sendq.pos); |
| 223 |
|
|
| 224 |
|
/* translate openssl error codes, sigh */ |
| 225 |
|
if (retlen < 0) |
| 226 |
|
{ |
| 227 |
< |
switch (SSL_get_error(to->localClient->fd.ssl, retlen)) |
| 227 |
> |
switch (SSL_get_error(to->connection->fd.ssl, retlen)) |
| 228 |
|
{ |
| 229 |
|
case SSL_ERROR_WANT_READ: |
| 230 |
|
return; /* retry later, don't register for write events */ |
| 242 |
|
} |
| 243 |
|
else |
| 244 |
|
#endif |
| 245 |
< |
retlen = send(to->localClient->fd.fd, first->data + to->localClient->buf_sendq.pos, first->size - to->localClient->buf_sendq.pos, 0); |
| 245 |
> |
retlen = send(to->connection->fd.fd, first->data + to->connection->buf_sendq.pos, first->size - to->connection->buf_sendq.pos, 0); |
| 246 |
|
|
| 247 |
|
if (retlen <= 0) |
| 248 |
|
break; |
| 249 |
|
|
| 250 |
< |
dbuf_delete(&to->localClient->buf_sendq, retlen); |
| 250 |
> |
dbuf_delete(&to->connection->buf_sendq, retlen); |
| 251 |
|
|
| 252 |
|
/* We have some data written .. update counters */ |
| 253 |
< |
to->localClient->send.bytes += retlen; |
| 254 |
< |
me.localClient->send.bytes += retlen; |
| 255 |
< |
} while (dbuf_length(&to->localClient->buf_sendq)); |
| 253 |
> |
to->connection->send.bytes += retlen; |
| 254 |
> |
me.connection->send.bytes += retlen; |
| 255 |
> |
} while (dbuf_length(&to->connection->buf_sendq)); |
| 256 |
|
|
| 257 |
< |
if ((retlen < 0) && (ignoreErrno(errno))) |
| 257 |
> |
if (retlen < 0 && ignoreErrno(errno)) |
| 258 |
|
{ |
| 259 |
+ |
AddFlag(to, FLAGS_BLOCKED); |
| 260 |
+ |
|
| 261 |
|
/* we have a non-fatal error, reschedule a write */ |
| 262 |
< |
comm_setselect(&to->localClient->fd, COMM_SELECT_WRITE, |
| 263 |
< |
(PF *)sendq_unblocked, to, 0); |
| 262 |
> |
comm_setselect(&to->connection->fd, COMM_SELECT_WRITE, |
| 263 |
> |
sendq_unblocked, to, 0); |
| 264 |
|
} |
| 265 |
|
else if (retlen <= 0) |
| 266 |
|
{ |
| 284 |
|
/* Servers are processed first, mainly because this can generate |
| 285 |
|
* a notice to opers, which is to be delivered by this function. |
| 286 |
|
*/ |
| 287 |
< |
DLINK_FOREACH(ptr, serv_list.head) |
| 287 |
> |
DLINK_FOREACH(ptr, local_server_list.head) |
| 288 |
|
send_queued_write(ptr->data); |
| 289 |
|
|
| 290 |
|
DLINK_FOREACH(ptr, unknown_list.head) |
| 332 |
|
sendto_one_numeric(struct Client *to, struct Client *from, enum irc_numerics numeric, ...) |
| 333 |
|
{ |
| 334 |
|
struct dbuf_block *buffer = NULL; |
| 335 |
< |
const char *dest = NULL; |
| 335 |
> |
const char *dest = NULL, *numstr = NULL; |
| 336 |
|
va_list args; |
| 337 |
|
|
| 338 |
|
if (IsDead(to->from)) |
| 339 |
|
return; |
| 340 |
|
|
| 341 |
|
dest = ID_or_name(to, to); |
| 342 |
+ |
|
| 343 |
|
if (EmptyString(dest)) |
| 344 |
|
dest = "*"; |
| 345 |
|
|
| 346 |
|
buffer = dbuf_alloc(); |
| 347 |
|
|
| 348 |
< |
dbuf_put_fmt(buffer, ":%s %03d %s ", ID_or_name(from, to), numeric, dest); |
| 348 |
> |
dbuf_put_fmt(buffer, ":%s %03d %s ", ID_or_name(from, to), numeric & ~SND_EXPLICIT, dest); |
| 349 |
|
|
| 350 |
|
va_start(args, numeric); |
| 351 |
< |
send_format(buffer, numeric_form(numeric), args); |
| 351 |
> |
|
| 352 |
> |
if (numeric & SND_EXPLICIT) |
| 353 |
> |
numstr = va_arg(args, const char *); |
| 354 |
> |
else |
| 355 |
> |
numstr = numeric_form(numeric); |
| 356 |
> |
send_format(buffer, numstr, args); |
| 357 |
|
va_end(args); |
| 358 |
|
|
| 359 |
|
send_message(to->from, buffer); |
| 372 |
|
return; |
| 373 |
|
|
| 374 |
|
dest = ID_or_name(to, to); |
| 375 |
+ |
|
| 376 |
|
if (EmptyString(dest)) |
| 377 |
|
dest = "*"; |
| 378 |
|
|
| 411 |
|
|
| 412 |
|
local_buf = dbuf_alloc(), remote_buf = dbuf_alloc(); |
| 413 |
|
|
| 414 |
< |
if (IsServer(from)) |
| 403 |
< |
dbuf_put_fmt(local_buf, ":%s ", from->name); |
| 404 |
< |
else |
| 414 |
> |
if (IsClient(from)) |
| 415 |
|
dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host); |
| 416 |
+ |
else |
| 417 |
+ |
dbuf_put_fmt(local_buf, ":%s ", from->name); |
| 418 |
|
|
| 419 |
|
dbuf_put_fmt(remote_buf, ":%s ", from->id); |
| 420 |
|
|
| 439 |
|
(one && target_p->from == one->from)) |
| 440 |
|
continue; |
| 441 |
|
|
| 442 |
< |
if (type != 0 && (ms->flags & type) == 0) |
| 442 |
> |
if (type && (ms->flags & type) == 0) |
| 443 |
|
continue; |
| 444 |
|
|
| 445 |
|
if (MyConnect(target_p)) |
| 446 |
|
send_message(target_p, local_buf); |
| 447 |
< |
else if (target_p->from->localClient->serial != current_serial) |
| 447 |
> |
else if (target_p->from->connection->serial != current_serial) |
| 448 |
|
send_message_remote(target_p->from, from, remote_buf); |
| 449 |
< |
target_p->from->localClient->serial = current_serial; |
| 449 |
> |
target_p->from->connection->serial = current_serial; |
| 450 |
|
} |
| 451 |
|
|
| 452 |
|
dbuf_ref_free(local_buf); |
| 487 |
|
send_format(buffer, format, args); |
| 488 |
|
va_end(args); |
| 489 |
|
|
| 490 |
< |
DLINK_FOREACH(ptr, serv_list.head) |
| 490 |
> |
DLINK_FOREACH(ptr, local_server_list.head) |
| 491 |
|
{ |
| 492 |
|
struct Client *client_p = ptr->data; |
| 493 |
|
|
| 495 |
|
if (IsDead(client_p)) |
| 496 |
|
continue; |
| 497 |
|
/* check against 'one' */ |
| 498 |
< |
if (one != NULL && (client_p == one->from)) |
| 498 |
> |
if (one && (client_p == one->from)) |
| 499 |
|
continue; |
| 500 |
|
/* check we have required capabs */ |
| 501 |
< |
if ((client_p->localClient->caps & caps) != caps) |
| 501 |
> |
if ((client_p->connection->caps & caps) != caps) |
| 502 |
|
continue; |
| 503 |
|
/* check we don't have any forbidden capabs */ |
| 504 |
< |
if ((client_p->localClient->caps & nocaps) != 0) |
| 504 |
> |
if ((client_p->connection->caps & nocaps)) |
| 505 |
|
continue; |
| 506 |
|
|
| 507 |
|
send_message(client_p, buffer); |
| 542 |
|
DLINK_FOREACH(cptr, user->channel.head) |
| 543 |
|
{ |
| 544 |
|
chptr = ((struct Membership *)cptr->data)->chptr; |
| 533 |
– |
assert(chptr != NULL); |
| 545 |
|
|
| 546 |
< |
DLINK_FOREACH(uptr, chptr->members.head) |
| 546 |
> |
DLINK_FOREACH(uptr, chptr->locmembers.head) |
| 547 |
|
{ |
| 548 |
|
ms = uptr->data; |
| 549 |
|
target_p = ms->client_p; |
| 539 |
– |
assert(target_p != NULL); |
| 550 |
|
|
| 551 |
< |
if (!MyConnect(target_p) || target_p == user || IsDefunct(target_p) || |
| 552 |
< |
target_p->localClient->serial == current_serial) |
| 551 |
> |
if (target_p == user || IsDefunct(target_p) || |
| 552 |
> |
target_p->connection->serial == current_serial) |
| 553 |
|
continue; |
| 554 |
|
|
| 555 |
|
if (HasCap(target_p, cap) != cap) |
| 556 |
|
continue; |
| 557 |
|
|
| 558 |
< |
target_p->localClient->serial = current_serial; |
| 558 |
> |
target_p->connection->serial = current_serial; |
| 559 |
|
send_message(target_p, buffer); |
| 560 |
|
} |
| 561 |
|
} |
| 562 |
|
|
| 563 |
|
if (touser && MyConnect(user) && !IsDead(user) && |
| 564 |
< |
user->localClient->serial != current_serial) |
| 564 |
> |
user->connection->serial != current_serial) |
| 565 |
|
if (HasCap(user, cap) == cap) |
| 566 |
|
send_message(user, buffer); |
| 567 |
|
|
| 592 |
|
send_format(buffer, pattern, args); |
| 593 |
|
va_end(args); |
| 594 |
|
|
| 595 |
< |
DLINK_FOREACH(ptr, chptr->members.head) |
| 595 |
> |
DLINK_FOREACH(ptr, chptr->locmembers.head) |
| 596 |
|
{ |
| 597 |
|
struct Membership *ms = ptr->data; |
| 598 |
|
struct Client *target_p = ms->client_p; |
| 599 |
|
|
| 600 |
< |
if (type != 0 && (ms->flags & type) == 0) |
| 600 |
> |
if (type && (ms->flags & type) == 0) |
| 601 |
|
continue; |
| 602 |
|
|
| 603 |
< |
if (!MyConnect(target_p) || IsDefunct(target_p) || |
| 603 |
> |
if (IsDefunct(target_p) || |
| 604 |
|
(nodeaf && HasUMode(target_p, UMODE_DEAF))) |
| 605 |
|
continue; |
| 606 |
|
|
| 636 |
|
send_format(buffer, pattern, args); |
| 637 |
|
va_end(args); |
| 638 |
|
|
| 639 |
< |
DLINK_FOREACH(ptr, chptr->members.head) |
| 639 |
> |
DLINK_FOREACH(ptr, chptr->locmembers.head) |
| 640 |
|
{ |
| 641 |
|
struct Membership *ms = ptr->data; |
| 642 |
|
struct Client *target_p = ms->client_p; |
| 643 |
|
|
| 644 |
< |
if (type != 0 && (ms->flags & type) == 0) |
| 644 |
> |
if (type && (ms->flags & type) == 0) |
| 645 |
|
continue; |
| 646 |
|
|
| 647 |
< |
if (!MyConnect(target_p) || (one && target_p == one->from)) |
| 647 |
> |
if (one && target_p == one->from) |
| 648 |
|
continue; |
| 649 |
|
|
| 650 |
|
if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF)) |
| 723 |
|
} |
| 724 |
|
|
| 725 |
|
/* Now scan servers */ |
| 726 |
< |
DLINK_FOREACH_SAFE(ptr, ptr_next, serv_list.head) |
| 726 |
> |
DLINK_FOREACH_SAFE(ptr, ptr_next, local_server_list.head) |
| 727 |
|
{ |
| 728 |
|
struct Client *client_p = ptr->data; |
| 729 |
|
|
| 773 |
|
const char *pattern, ...) |
| 774 |
|
{ |
| 775 |
|
va_list args; |
| 776 |
< |
dlink_node *ptr = NULL; |
| 777 |
< |
struct dbuf_block *buff_suid; |
| 776 |
> |
dlink_node *ptr = NULL, *ptr_next = NULL; |
| 777 |
> |
struct dbuf_block *buffer; |
| 778 |
|
|
| 779 |
< |
buff_suid = dbuf_alloc(); |
| 779 |
> |
buffer = dbuf_alloc(); |
| 780 |
|
|
| 781 |
+ |
dbuf_put_fmt(buffer, ":%s ", source_p->id); |
| 782 |
|
va_start(args, pattern); |
| 783 |
< |
dbuf_put_fmt(buff_suid, ":%s ", source_p->id); |
| 773 |
< |
dbuf_put_args(buff_suid, pattern, args); |
| 783 |
> |
send_format(buffer, pattern, args); |
| 784 |
|
va_end(args); |
| 785 |
|
|
| 786 |
|
++current_serial; |
| 787 |
|
|
| 788 |
< |
DLINK_FOREACH(ptr, global_serv_list.head) |
| 788 |
> |
DLINK_FOREACH_SAFE(ptr, ptr_next, global_server_list.head) |
| 789 |
|
{ |
| 790 |
|
struct Client *target_p = ptr->data; |
| 791 |
|
|
| 793 |
|
if (IsMe(target_p) || target_p->from == source_p->from) |
| 794 |
|
continue; |
| 795 |
|
|
| 796 |
< |
if (target_p->from->localClient->serial == current_serial) |
| 796 |
> |
if (target_p->from->connection->serial == current_serial) |
| 797 |
|
continue; |
| 798 |
|
|
| 799 |
|
if (!match(mask, target_p->name)) |
| 802 |
|
* if we set the serial here, then we'll never do a |
| 803 |
|
* match() again, if !IsCapable() |
| 804 |
|
*/ |
| 805 |
< |
target_p->from->localClient->serial = current_serial; |
| 805 |
> |
target_p->from->connection->serial = current_serial; |
| 806 |
|
|
| 807 |
|
if (!IsCapable(target_p->from, cap)) |
| 808 |
|
continue; |
| 809 |
|
|
| 810 |
< |
send_message_remote(target_p->from, source_p, buff_suid); |
| 810 |
> |
send_message_remote(target_p->from, source_p, buffer); |
| 811 |
|
} |
| 812 |
|
} |
| 813 |
|
|
| 814 |
< |
dbuf_ref_free(buff_suid); |
| 814 |
> |
dbuf_ref_free(buffer); |
| 815 |
|
} |
| 816 |
|
|
| 817 |
|
/* sendto_anywhere() |
| 917 |
|
* (at most 5 warnings every 5 seconds) |
| 918 |
|
*/ |
| 919 |
|
void |
| 920 |
< |
sendto_realops_flags_ratelimited(const char *pattern, ...) |
| 920 |
> |
sendto_realops_flags_ratelimited(time_t *rate, const char *pattern, ...) |
| 921 |
|
{ |
| 922 |
|
va_list args; |
| 923 |
|
char buffer[IRCD_BUFSIZE] = ""; |
| 914 |
– |
static time_t last = 0; |
| 915 |
– |
static int warnings = 0; |
| 924 |
|
|
| 925 |
< |
/* |
| 926 |
< |
** if we're running with TS_WARNINGS enabled and someone does |
| 927 |
< |
** something silly like (remotely) connecting a nonTS server, |
| 920 |
< |
** we'll get a ton of warnings, so we make sure we don't send |
| 921 |
< |
** more than 5 every 5 seconds. -orabidoo |
| 922 |
< |
*/ |
| 923 |
< |
|
| 924 |
< |
if (CurrentTime - last < 5) |
| 925 |
< |
{ |
| 926 |
< |
if (++warnings > 5) |
| 927 |
< |
return; |
| 928 |
< |
} |
| 929 |
< |
else |
| 930 |
< |
{ |
| 931 |
< |
last = CurrentTime; |
| 932 |
< |
warnings = 0; |
| 933 |
< |
} |
| 925 |
> |
if ((CurrentTime - *rate) < 20) |
| 926 |
> |
return; |
| 927 |
> |
*rate = CurrentTime; |
| 928 |
|
|
| 929 |
|
va_start(args, pattern); |
| 930 |
|
vsnprintf(buffer, sizeof(buffer), pattern, args); |