| 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-2016 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; |
| 41 |
> |
static uintmax_t current_serial; |
| 42 |
|
|
| 43 |
|
|
| 44 |
|
/* send_format() |
| 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 |
|
{ |
| 91 |
|
if (IsServer(to)) |
| 92 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 93 |
< |
"Max SendQ limit exceeded for %s: %lu > %u", |
| 92 |
> |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
| 93 |
> |
"Max SendQ limit exceeded for %s: %zu > %u", |
| 94 |
|
get_client_name(to, HIDE_IP), |
| 95 |
< |
(unsigned long)(dbuf_length(&to->connection->buf_sendq) + buf->size), |
| 95 |
> |
(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; |
| 126 |
|
* |
| 127 |
|
*/ |
| 128 |
|
static void |
| 129 |
< |
send_message_remote(struct Client *to, struct Client *from, struct dbuf_block *buf) |
| 129 |
> |
send_message_remote(struct Client *to, const 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 |
|
{ |
| 138 |
< |
if (IsServer(from)) |
| 139 |
< |
{ |
| 140 |
< |
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 |
< |
|
| 156 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 157 |
< |
"Ghosted: %s[%s@%s] from %s[%s@%s] (%s)", |
| 158 |
< |
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"); |
| 138 |
> |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
| 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); |
| 168 |
|
send_queued_write(struct Client *to) |
| 169 |
|
{ |
| 170 |
|
int retlen = 0; |
| 171 |
+ |
int want_read = 0; |
| 172 |
|
|
| 173 |
|
/* |
| 174 |
|
** Once socket is marked dead, we cannot start writing to it, |
| 182 |
|
{ |
| 183 |
|
do |
| 184 |
|
{ |
| 185 |
< |
struct dbuf_block *first = to->connection->buf_sendq.blocks.head->data; |
| 185 |
> |
const struct dbuf_block *first = to->connection->buf_sendq.blocks.head->data; |
| 186 |
|
|
| 187 |
< |
#ifdef HAVE_LIBCRYPTO |
| 220 |
< |
if (to->connection->fd.ssl) |
| 187 |
> |
if (tls_isusing(&to->connection->fd.ssl)) |
| 188 |
|
{ |
| 189 |
< |
retlen = SSL_write(to->connection->fd.ssl, first->data + to->connection->buf_sendq.pos, first->size - to->connection->buf_sendq.pos); |
| 189 |
> |
retlen = tls_write(&to->connection->fd.ssl, first->data + to->connection->buf_sendq.pos, |
| 190 |
> |
first->size - to->connection->buf_sendq.pos, &want_read); |
| 191 |
|
|
| 192 |
< |
/* translate openssl error codes, sigh */ |
| 193 |
< |
if (retlen < 0) |
| 226 |
< |
{ |
| 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 */ |
| 231 |
< |
case SSL_ERROR_WANT_WRITE: |
| 232 |
< |
errno = EWOULDBLOCK; |
| 233 |
< |
case SSL_ERROR_SYSCALL: |
| 234 |
< |
break; |
| 235 |
< |
case SSL_ERROR_SSL: |
| 236 |
< |
if (errno == EAGAIN) |
| 237 |
< |
break; |
| 238 |
< |
default: |
| 239 |
< |
retlen = errno = 0; /* either an SSL-specific error or EOF */ |
| 240 |
< |
} |
| 241 |
< |
} |
| 192 |
> |
if (want_read) |
| 193 |
> |
return; /* Retry later, don't register for write events */ |
| 194 |
|
} |
| 195 |
|
else |
| 196 |
< |
#endif |
| 197 |
< |
retlen = send(to->connection->fd.fd, first->data + to->connection->buf_sendq.pos, first->size - to->connection->buf_sendq.pos, 0); |
| 196 |
> |
retlen = send(to->connection->fd.fd, first->data + to->connection->buf_sendq.pos, |
| 197 |
> |
first->size - to->connection->buf_sendq.pos, 0); |
| 198 |
|
|
| 199 |
|
if (retlen <= 0) |
| 200 |
|
break; |
| 211 |
|
AddFlag(to, FLAGS_BLOCKED); |
| 212 |
|
|
| 213 |
|
/* we have a non-fatal error, reschedule a write */ |
| 214 |
< |
comm_setselect(&to->connection->fd, COMM_SELECT_WRITE, |
| 263 |
< |
sendq_unblocked, to, 0); |
| 214 |
> |
comm_setselect(&to->connection->fd, COMM_SELECT_WRITE, sendq_unblocked, to, 0); |
| 215 |
|
} |
| 216 |
|
else if (retlen <= 0) |
| 217 |
|
{ |
| 230 |
|
void |
| 231 |
|
send_queued_all(void) |
| 232 |
|
{ |
| 233 |
< |
dlink_node *ptr; |
| 233 |
> |
dlink_node *node = NULL; |
| 234 |
|
|
| 235 |
|
/* Servers are processed first, mainly because this can generate |
| 236 |
|
* a notice to opers, which is to be delivered by this function. |
| 237 |
|
*/ |
| 238 |
< |
DLINK_FOREACH(ptr, local_server_list.head) |
| 239 |
< |
send_queued_write(ptr->data); |
| 238 |
> |
DLINK_FOREACH(node, local_server_list.head) |
| 239 |
> |
send_queued_write(node->data); |
| 240 |
|
|
| 241 |
< |
DLINK_FOREACH(ptr, unknown_list.head) |
| 242 |
< |
send_queued_write(ptr->data); |
| 241 |
> |
DLINK_FOREACH(node, unknown_list.head) |
| 242 |
> |
send_queued_write(node->data); |
| 243 |
|
|
| 244 |
< |
DLINK_FOREACH(ptr, local_client_list.head) |
| 245 |
< |
send_queued_write(ptr->data); |
| 244 |
> |
DLINK_FOREACH(node, local_client_list.head) |
| 245 |
> |
send_queued_write(node->data); |
| 246 |
|
|
| 247 |
|
/* NOTE: This can still put clients on aborted_list; unfortunately, |
| 248 |
|
* exit_aborted_clients takes precedence over send_queued_all, |
| 280 |
|
} |
| 281 |
|
|
| 282 |
|
void |
| 283 |
< |
sendto_one_numeric(struct Client *to, struct Client *from, enum irc_numerics numeric, ...) |
| 283 |
> |
sendto_one_numeric(struct Client *to, const struct Client *from, enum irc_numerics numeric, ...) |
| 284 |
|
{ |
| 285 |
|
struct dbuf_block *buffer = NULL; |
| 286 |
|
const char *dest = NULL, *numstr = NULL; |
| 314 |
|
} |
| 315 |
|
|
| 316 |
|
void |
| 317 |
< |
sendto_one_notice(struct Client *to, struct Client *from, const char *pattern, ...) |
| 317 |
> |
sendto_one_notice(struct Client *to, const struct Client *from, const char *pattern, ...) |
| 318 |
|
{ |
| 319 |
|
struct dbuf_block *buffer = NULL; |
| 320 |
|
const char *dest = NULL; |
| 353 |
|
* WARNING - +D clients are ignored |
| 354 |
|
*/ |
| 355 |
|
void |
| 356 |
< |
sendto_channel_butone(struct Client *one, struct Client *from, |
| 356 |
> |
sendto_channel_butone(struct Client *one, const struct Client *from, |
| 357 |
|
struct Channel *chptr, unsigned int type, |
| 358 |
|
const char *pattern, ...) |
| 359 |
|
{ |
| 360 |
|
va_list alocal, aremote; |
| 361 |
|
struct dbuf_block *local_buf, *remote_buf; |
| 362 |
< |
dlink_node *ptr = NULL, *ptr_next = NULL; |
| 362 |
> |
dlink_node *node = NULL; |
| 363 |
|
|
| 364 |
|
local_buf = dbuf_alloc(), remote_buf = dbuf_alloc(); |
| 365 |
|
|
| 380 |
|
|
| 381 |
|
++current_serial; |
| 382 |
|
|
| 383 |
< |
DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->members.head) |
| 383 |
> |
DLINK_FOREACH(node, chptr->members.head) |
| 384 |
|
{ |
| 385 |
< |
struct Membership *ms = ptr->data; |
| 386 |
< |
struct Client *target_p = ms->client_p; |
| 385 |
> |
struct Membership *member = node->data; |
| 386 |
> |
struct Client *target_p = member->client_p; |
| 387 |
|
|
| 388 |
|
assert(IsClient(target_p)); |
| 389 |
|
|
| 391 |
|
(one && target_p->from == one->from)) |
| 392 |
|
continue; |
| 393 |
|
|
| 394 |
< |
if (type && (ms->flags & type) == 0) |
| 394 |
> |
if (type && (member->flags & type) == 0) |
| 395 |
|
continue; |
| 396 |
|
|
| 397 |
|
if (MyConnect(target_p)) |
| 398 |
|
send_message(target_p, local_buf); |
| 399 |
|
else if (target_p->from->connection->serial != current_serial) |
| 400 |
|
send_message_remote(target_p->from, from, remote_buf); |
| 401 |
+ |
|
| 402 |
|
target_p->from->connection->serial = current_serial; |
| 403 |
|
} |
| 404 |
|
|
| 425 |
|
* -davidt |
| 426 |
|
*/ |
| 427 |
|
void |
| 428 |
< |
sendto_server(struct Client *one, |
| 428 |
> |
sendto_server(const struct Client *one, |
| 429 |
|
const unsigned int caps, |
| 430 |
|
const unsigned int nocaps, |
| 431 |
|
const char *format, ...) |
| 432 |
|
{ |
| 433 |
|
va_list args; |
| 434 |
< |
dlink_node *ptr = NULL; |
| 435 |
< |
struct dbuf_block *buffer; |
| 484 |
< |
|
| 485 |
< |
buffer = dbuf_alloc(); |
| 434 |
> |
dlink_node *node = NULL; |
| 435 |
> |
struct dbuf_block *buffer = dbuf_alloc(); |
| 436 |
|
|
| 437 |
|
va_start(args, format); |
| 438 |
|
send_format(buffer, format, args); |
| 439 |
|
va_end(args); |
| 440 |
|
|
| 441 |
< |
DLINK_FOREACH(ptr, local_server_list.head) |
| 441 |
> |
DLINK_FOREACH(node, local_server_list.head) |
| 442 |
|
{ |
| 443 |
< |
struct Client *client_p = ptr->data; |
| 443 |
> |
struct Client *client_p = node->data; |
| 444 |
|
|
| 445 |
|
/* If dead already skip */ |
| 446 |
|
if (IsDead(client_p)) |
| 447 |
|
continue; |
| 448 |
+ |
|
| 449 |
|
/* check against 'one' */ |
| 450 |
|
if (one && (client_p == one->from)) |
| 451 |
|
continue; |
| 452 |
+ |
|
| 453 |
|
/* check we have required capabs */ |
| 454 |
|
if ((client_p->connection->caps & caps) != caps) |
| 455 |
|
continue; |
| 456 |
+ |
|
| 457 |
|
/* check we don't have any forbidden capabs */ |
| 458 |
|
if ((client_p->connection->caps & nocaps)) |
| 459 |
|
continue; |
| 474 |
|
* used by m_nick.c and exit_one_client. |
| 475 |
|
*/ |
| 476 |
|
void |
| 477 |
< |
sendto_common_channels_local(struct Client *user, int touser, unsigned int cap, |
| 478 |
< |
const char *pattern, ...) |
| 477 |
> |
sendto_common_channels_local(struct Client *user, int touser, unsigned int poscap, |
| 478 |
> |
unsigned int negcap, const char *pattern, ...) |
| 479 |
|
{ |
| 480 |
|
va_list args; |
| 481 |
|
dlink_node *uptr; |
| 482 |
|
dlink_node *cptr; |
| 483 |
|
struct Channel *chptr; |
| 484 |
< |
struct Membership *ms; |
| 484 |
> |
struct Membership *member; |
| 485 |
|
struct Client *target_p; |
| 486 |
< |
struct dbuf_block *buffer; |
| 534 |
< |
|
| 535 |
< |
buffer = dbuf_alloc(); |
| 486 |
> |
struct dbuf_block *buffer = dbuf_alloc(); |
| 487 |
|
|
| 488 |
|
va_start(args, pattern); |
| 489 |
|
send_format(buffer, pattern, args); |
| 497 |
|
|
| 498 |
|
DLINK_FOREACH(uptr, chptr->locmembers.head) |
| 499 |
|
{ |
| 500 |
< |
ms = uptr->data; |
| 501 |
< |
target_p = ms->client_p; |
| 500 |
> |
member = uptr->data; |
| 501 |
> |
target_p = member->client_p; |
| 502 |
|
|
| 503 |
|
if (target_p == user || IsDefunct(target_p) || |
| 504 |
|
target_p->connection->serial == current_serial) |
| 505 |
|
continue; |
| 506 |
|
|
| 507 |
< |
if (HasCap(target_p, cap) != cap) |
| 507 |
> |
if (poscap && HasCap(target_p, poscap) != poscap) |
| 508 |
> |
continue; |
| 509 |
> |
|
| 510 |
> |
if (negcap && HasCap(target_p, negcap)) |
| 511 |
|
continue; |
| 512 |
|
|
| 513 |
|
target_p->connection->serial = current_serial; |
| 517 |
|
|
| 518 |
|
if (touser && MyConnect(user) && !IsDead(user) && |
| 519 |
|
user->connection->serial != current_serial) |
| 520 |
< |
if (HasCap(user, cap) == cap) |
| 520 |
> |
if (HasCap(user, poscap) == poscap) |
| 521 |
|
send_message(user, buffer); |
| 522 |
|
|
| 523 |
|
dbuf_ref_free(buffer); |
| 524 |
|
} |
| 525 |
|
|
| 526 |
< |
/* sendto_channel_local() |
| 527 |
< |
* |
| 528 |
< |
* inputs - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE |
| 529 |
< |
* - whether to ignore +D clients (YES/NO) |
| 530 |
< |
* - pointer to channel to send to |
| 531 |
< |
* - var args pattern |
| 532 |
< |
* output - NONE |
| 579 |
< |
* side effects - Send a message to all members of a channel that are |
| 580 |
< |
* locally connected to this server. |
| 526 |
> |
/*! \brief Send a message to members of a channel that are locally connected to this server. |
| 527 |
> |
* \param one Client to skip; can be NULL |
| 528 |
> |
* \param chptr Destination channel |
| 529 |
> |
* \param status Channel member status flags clients must have |
| 530 |
> |
* \param poscap Positive client capabilities flags (CAP) |
| 531 |
> |
* \param negcap Negative client capabilities flags (CAP) |
| 532 |
> |
* \param pattern Format string for command arguments |
| 533 |
|
*/ |
| 534 |
|
void |
| 535 |
< |
sendto_channel_local(unsigned int type, int nodeaf, struct Channel *chptr, |
| 536 |
< |
const char *pattern, ...) |
| 535 |
> |
sendto_channel_local(const struct Client *one, struct Channel *chptr, unsigned int status, |
| 536 |
> |
unsigned int poscap, unsigned int negcap, const char *pattern, ...) |
| 537 |
|
{ |
| 538 |
|
va_list args; |
| 539 |
< |
dlink_node *ptr = NULL; |
| 540 |
< |
struct dbuf_block *buffer; |
| 589 |
< |
|
| 590 |
< |
buffer = dbuf_alloc(); |
| 539 |
> |
dlink_node *node = NULL; |
| 540 |
> |
struct dbuf_block *buffer = dbuf_alloc(); |
| 541 |
|
|
| 542 |
|
va_start(args, pattern); |
| 543 |
|
send_format(buffer, pattern, args); |
| 544 |
|
va_end(args); |
| 545 |
|
|
| 546 |
< |
DLINK_FOREACH(ptr, chptr->locmembers.head) |
| 546 |
> |
DLINK_FOREACH(node, chptr->locmembers.head) |
| 547 |
|
{ |
| 548 |
< |
struct Membership *ms = ptr->data; |
| 549 |
< |
struct Client *target_p = ms->client_p; |
| 600 |
< |
|
| 601 |
< |
if (type && (ms->flags & type) == 0) |
| 602 |
< |
continue; |
| 548 |
> |
struct Membership *member = node->data; |
| 549 |
> |
struct Client *target_p = member->client_p; |
| 550 |
|
|
| 551 |
< |
if (IsDefunct(target_p) || |
| 605 |
< |
(nodeaf && HasUMode(target_p, UMODE_DEAF))) |
| 551 |
> |
if (IsDefunct(target_p)) |
| 552 |
|
continue; |
| 553 |
|
|
| 608 |
– |
send_message(target_p, buffer); |
| 609 |
– |
} |
| 610 |
– |
|
| 611 |
– |
dbuf_ref_free(buffer); |
| 612 |
– |
} |
| 613 |
– |
|
| 614 |
– |
/* sendto_channel_local_butone() |
| 615 |
– |
* |
| 616 |
– |
* inputs - pointer to client to NOT send message to |
| 617 |
– |
* - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE |
| 618 |
– |
* - pointer to channel to send to |
| 619 |
– |
* - var args pattern |
| 620 |
– |
* output - NONE |
| 621 |
– |
* side effects - Send a message to all members of a channel that are |
| 622 |
– |
* locally connected to this server except one. |
| 623 |
– |
* |
| 624 |
– |
* WARNING - +D clients are omitted |
| 625 |
– |
*/ |
| 626 |
– |
void |
| 627 |
– |
sendto_channel_local_butone(struct Client *one, unsigned int poscap, unsigned int negcap, |
| 628 |
– |
struct Channel *chptr, const char *pattern, ...) |
| 629 |
– |
{ |
| 630 |
– |
va_list args; |
| 631 |
– |
dlink_node *ptr = NULL; |
| 632 |
– |
struct dbuf_block *buffer = dbuf_alloc(); |
| 633 |
– |
|
| 634 |
– |
va_start(args, pattern); |
| 635 |
– |
send_format(buffer, pattern, args); |
| 636 |
– |
va_end(args); |
| 637 |
– |
|
| 638 |
– |
DLINK_FOREACH(ptr, chptr->locmembers.head) |
| 639 |
– |
{ |
| 640 |
– |
struct Membership *ms = ptr->data; |
| 641 |
– |
struct Client *target_p = ms->client_p; |
| 642 |
– |
|
| 554 |
|
if (one && target_p == one->from) |
| 555 |
|
continue; |
| 556 |
|
|
| 557 |
< |
if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF)) |
| 557 |
> |
if (status && (member->flags & status) == 0) |
| 558 |
|
continue; |
| 559 |
|
|
| 560 |
|
if (poscap && HasCap(target_p, poscap) != poscap) |
| 603 |
|
* ugh. ONLY used by m_message.c to send an "oper magic" message. ugh. |
| 604 |
|
*/ |
| 605 |
|
void |
| 606 |
< |
sendto_match_butone(struct Client *one, struct Client *from, const char *mask, |
| 607 |
< |
int what, const char *pattern, ...) |
| 606 |
> |
sendto_match_butone(const struct Client *one, const struct Client *from, |
| 607 |
> |
const char *mask, int what, const char *pattern, ...) |
| 608 |
|
{ |
| 609 |
|
va_list alocal, aremote; |
| 610 |
< |
dlink_node *ptr = NULL, *ptr_next = NULL; |
| 610 |
> |
dlink_node *node = NULL; |
| 611 |
|
struct dbuf_block *local_buf, *remote_buf; |
| 612 |
|
|
| 613 |
|
local_buf = dbuf_alloc(), remote_buf = dbuf_alloc(); |
| 623 |
|
va_end(alocal); |
| 624 |
|
|
| 625 |
|
/* scan the local clients */ |
| 626 |
< |
DLINK_FOREACH(ptr, local_client_list.head) |
| 626 |
> |
DLINK_FOREACH(node, local_client_list.head) |
| 627 |
|
{ |
| 628 |
< |
struct Client *client_p = ptr->data; |
| 628 |
> |
struct Client *client_p = node->data; |
| 629 |
|
|
| 630 |
|
if ((!one || client_p != one->from) && !IsDefunct(client_p) && |
| 631 |
|
match_it(client_p, mask, what)) |
| 633 |
|
} |
| 634 |
|
|
| 635 |
|
/* Now scan servers */ |
| 636 |
< |
DLINK_FOREACH_SAFE(ptr, ptr_next, local_server_list.head) |
| 636 |
> |
DLINK_FOREACH(node, local_server_list.head) |
| 637 |
|
{ |
| 638 |
< |
struct Client *client_p = ptr->data; |
| 638 |
> |
struct Client *client_p = node->data; |
| 639 |
|
|
| 640 |
|
/* |
| 641 |
|
* The old code looped through every client on the |
| 679 |
|
* side effects - data sent to servers matching with capab |
| 680 |
|
*/ |
| 681 |
|
void |
| 682 |
< |
sendto_match_servs(struct Client *source_p, const char *mask, unsigned int cap, |
| 682 |
> |
sendto_match_servs(const struct Client *source_p, const char *mask, unsigned int cap, |
| 683 |
|
const char *pattern, ...) |
| 684 |
|
{ |
| 685 |
|
va_list args; |
| 686 |
< |
dlink_node *ptr = NULL, *ptr_next = NULL; |
| 687 |
< |
struct dbuf_block *buffer; |
| 777 |
< |
|
| 778 |
< |
buffer = dbuf_alloc(); |
| 686 |
> |
dlink_node *node = NULL; |
| 687 |
> |
struct dbuf_block *buffer = dbuf_alloc(); |
| 688 |
|
|
| 689 |
|
dbuf_put_fmt(buffer, ":%s ", source_p->id); |
| 690 |
|
va_start(args, pattern); |
| 693 |
|
|
| 694 |
|
++current_serial; |
| 695 |
|
|
| 696 |
< |
DLINK_FOREACH_SAFE(ptr, ptr_next, global_server_list.head) |
| 696 |
> |
DLINK_FOREACH(node, global_server_list.head) |
| 697 |
|
{ |
| 698 |
< |
struct Client *target_p = ptr->data; |
| 698 |
> |
struct Client *target_p = node->data; |
| 699 |
|
|
| 700 |
|
/* Do not attempt to send to ourselves, or the source */ |
| 701 |
|
if (IsMe(target_p) || target_p->from == source_p->from) |
| 704 |
|
if (target_p->from->connection->serial == current_serial) |
| 705 |
|
continue; |
| 706 |
|
|
| 707 |
< |
if (!match(mask, target_p->name)) |
| 708 |
< |
{ |
| 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; |
| 707 |
> |
if (match(mask, target_p->name)) |
| 708 |
> |
continue; |
| 709 |
|
|
| 710 |
< |
if (!IsCapable(target_p->from, cap)) |
| 711 |
< |
continue; |
| 710 |
> |
/* |
| 711 |
> |
* If we set the serial here, then we'll never do a |
| 712 |
> |
* match() again, if !IsCapable() |
| 713 |
> |
*/ |
| 714 |
> |
target_p->from->connection->serial = current_serial; |
| 715 |
|
|
| 716 |
< |
send_message_remote(target_p->from, source_p, buffer); |
| 717 |
< |
} |
| 716 |
> |
if (cap && IsCapable(target_p->from, cap) != cap) |
| 717 |
> |
continue; |
| 718 |
> |
|
| 719 |
> |
send_message_remote(target_p->from, source_p, buffer); |
| 720 |
|
} |
| 721 |
|
|
| 722 |
|
dbuf_ref_free(buffer); |
| 732 |
|
* but useful when one does not know where target "lives" |
| 733 |
|
*/ |
| 734 |
|
void |
| 735 |
< |
sendto_anywhere(struct Client *to, struct Client *from, |
| 735 |
> |
sendto_anywhere(struct Client *to, const struct Client *from, |
| 736 |
|
const char *command, |
| 737 |
|
const char *pattern, ...) |
| 738 |
|
{ |
| 755 |
|
send_format(buffer, pattern, args); |
| 756 |
|
va_end(args); |
| 757 |
|
|
| 758 |
< |
if (MyClient(to)) |
| 758 |
> |
if (MyConnect(to)) |
| 759 |
|
send_message(to, buffer); |
| 760 |
|
else |
| 761 |
< |
send_message_remote(to, from, buffer); |
| 761 |
> |
send_message_remote(to->from, from, buffer); |
| 762 |
|
|
| 763 |
|
dbuf_ref_free(buffer); |
| 764 |
|
} |
| 775 |
|
sendto_realops_flags(unsigned int flags, int level, int type, const char *pattern, ...) |
| 776 |
|
{ |
| 777 |
|
const char *ntype = NULL; |
| 778 |
< |
dlink_node *ptr = NULL; |
| 778 |
> |
dlink_node *node = NULL; |
| 779 |
|
char nbuf[IRCD_BUFSIZE] = ""; |
| 780 |
|
va_list args; |
| 781 |
|
|
| 798 |
|
assert(0); |
| 799 |
|
} |
| 800 |
|
|
| 801 |
< |
DLINK_FOREACH(ptr, oper_list.head) |
| 801 |
> |
DLINK_FOREACH(node, oper_list.head) |
| 802 |
|
{ |
| 803 |
< |
struct Client *client_p = ptr->data; |
| 803 |
> |
struct Client *client_p = node->data; |
| 804 |
|
assert(HasUMode(client_p, UMODE_OPER)); |
| 805 |
|
|
| 806 |
|
/* |
| 832 |
|
|
| 833 |
|
if ((CurrentTime - *rate) < 20) |
| 834 |
|
return; |
| 835 |
+ |
|
| 836 |
|
*rate = CurrentTime; |
| 837 |
|
|
| 838 |
|
va_start(args, pattern); |
| 839 |
|
vsnprintf(buffer, sizeof(buffer), pattern, args); |
| 840 |
|
va_end(args); |
| 841 |
|
|
| 842 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, "%s", buffer); |
| 842 |
> |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, "%s", buffer); |
| 843 |
|
ilog(LOG_TYPE_IRCD, "%s", buffer); |
| 844 |
|
} |
| 845 |
|
|
| 852 |
|
* side effects - Send a wallops to local opers |
| 853 |
|
*/ |
| 854 |
|
void |
| 855 |
< |
sendto_wallops_flags(unsigned int flags, struct Client *source_p, |
| 855 |
> |
sendto_wallops_flags(unsigned int flags, const struct Client *source_p, |
| 856 |
|
const char *pattern, ...) |
| 857 |
|
{ |
| 858 |
< |
dlink_node *ptr = NULL; |
| 858 |
> |
dlink_node *node = NULL; |
| 859 |
|
va_list args; |
| 860 |
< |
struct dbuf_block *buffer; |
| 951 |
< |
|
| 952 |
< |
buffer = dbuf_alloc(); |
| 860 |
> |
struct dbuf_block *buffer = dbuf_alloc(); |
| 861 |
|
|
| 862 |
|
if (IsClient(source_p)) |
| 863 |
|
dbuf_put_fmt(buffer, ":%s!%s@%s WALLOPS :", source_p->name, source_p->username, source_p->host); |
| 868 |
|
send_format(buffer, pattern, args); |
| 869 |
|
va_end(args); |
| 870 |
|
|
| 871 |
< |
DLINK_FOREACH(ptr, oper_list.head) |
| 871 |
> |
DLINK_FOREACH(node, oper_list.head) |
| 872 |
|
{ |
| 873 |
< |
struct Client *client_p = ptr->data; |
| 873 |
> |
struct Client *client_p = node->data; |
| 874 |
|
assert(client_p->umodes & UMODE_OPER); |
| 875 |
|
|
| 876 |
|
if (HasUMode(client_p, flags) && !IsDefunct(client_p)) |