| 1 |
adx |
30 |
/* |
| 2 |
|
|
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
| 3 |
|
|
* send.c: Functions for sending messages. |
| 4 |
|
|
* |
| 5 |
|
|
* Copyright (C) 2002 by the past and present ircd coders, and others. |
| 6 |
|
|
* |
| 7 |
|
|
* This program is free software; you can redistribute it and/or modify |
| 8 |
|
|
* it under the terms of the GNU General Public License as published by |
| 9 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
| 10 |
|
|
* (at your option) any later version. |
| 11 |
|
|
* |
| 12 |
|
|
* This program is distributed in the hope that it will be useful, |
| 13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
|
|
* GNU General Public License for more details. |
| 16 |
|
|
* |
| 17 |
|
|
* You should have received a copy of the GNU General Public License |
| 18 |
|
|
* along with this program; if not, write to the Free Software |
| 19 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 20 |
|
|
* USA |
| 21 |
|
|
* |
| 22 |
knight |
31 |
* $Id$ |
| 23 |
adx |
30 |
*/ |
| 24 |
|
|
|
| 25 |
|
|
#include "stdinc.h" |
| 26 |
|
|
#include "tools.h" |
| 27 |
|
|
#include "send.h" |
| 28 |
|
|
#include "channel.h" |
| 29 |
|
|
#include "client.h" |
| 30 |
|
|
#include "common.h" |
| 31 |
|
|
#include "dbuf.h" |
| 32 |
|
|
#include "irc_string.h" |
| 33 |
|
|
#include "ircd.h" |
| 34 |
|
|
#include "handlers.h" |
| 35 |
|
|
#include "numeric.h" |
| 36 |
|
|
#include "fdlist.h" |
| 37 |
|
|
#include "s_bsd.h" |
| 38 |
|
|
#include "s_serv.h" |
| 39 |
|
|
#include "sprintf_irc.h" |
| 40 |
|
|
#include "s_conf.h" |
| 41 |
|
|
#include "list.h" |
| 42 |
|
|
#include "s_log.h" |
| 43 |
|
|
#include "memory.h" |
| 44 |
|
|
#include "hook.h" |
| 45 |
|
|
#include "irc_getnameinfo.h" |
| 46 |
|
|
#include "packet.h" |
| 47 |
|
|
|
| 48 |
|
|
#define LOG_BUFSIZE 2048 |
| 49 |
|
|
|
| 50 |
|
|
struct Callback *iosend_cb = NULL; |
| 51 |
|
|
struct Callback *iosendctrl_cb = NULL; |
| 52 |
|
|
|
| 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; |
| 57 |
|
|
|
| 58 |
|
|
/* send_format() |
| 59 |
|
|
* |
| 60 |
|
|
* inputs - buffer to format into |
| 61 |
|
|
* - size of the buffer |
| 62 |
|
|
* - format pattern to use |
| 63 |
|
|
* - var args |
| 64 |
|
|
* output - number of bytes formatted output |
| 65 |
|
|
* side effects - modifies sendbuf |
| 66 |
|
|
*/ |
| 67 |
|
|
static inline int |
| 68 |
|
|
send_format(char *lsendbuf, int bufsize, const char *pattern, va_list args) |
| 69 |
|
|
{ |
| 70 |
|
|
int len; |
| 71 |
|
|
|
| 72 |
|
|
/* |
| 73 |
|
|
* from rfc1459 |
| 74 |
|
|
* |
| 75 |
|
|
* IRC messages are always lines of characters terminated with a CR-LF |
| 76 |
|
|
* (Carriage Return - Line Feed) pair, and these messages shall not |
| 77 |
|
|
* exceed 512 characters in length, counting all characters |
| 78 |
|
|
* including the trailing CR-LF. |
| 79 |
|
|
* Thus, there are 510 characters maximum allowed |
| 80 |
|
|
* for the command and its parameters. There is no provision for |
| 81 |
|
|
* continuation message lines. See section 7 for more details about |
| 82 |
|
|
* current implementations. |
| 83 |
|
|
*/ |
| 84 |
|
|
len = vsnprintf(lsendbuf, bufsize - 1, pattern, args); |
| 85 |
|
|
if (len > bufsize - 2) |
| 86 |
|
|
len = bufsize - 2; /* required by some versions of vsnprintf */ |
| 87 |
|
|
|
| 88 |
|
|
lsendbuf[len++] = '\r'; |
| 89 |
|
|
lsendbuf[len++] = '\n'; |
| 90 |
|
|
return (len); |
| 91 |
|
|
} |
| 92 |
|
|
|
| 93 |
|
|
/* |
| 94 |
adx |
163 |
* iosend_default - append a packet to the client's sendq. |
| 95 |
|
|
*/ |
| 96 |
|
|
void * |
| 97 |
|
|
iosend_default(va_list args) |
| 98 |
|
|
{ |
| 99 |
|
|
struct Client *to = va_arg(args, struct Client *); |
| 100 |
|
|
int length = va_arg(args, int); |
| 101 |
|
|
char *buf = va_arg(args, char *); |
| 102 |
|
|
|
| 103 |
|
|
dbuf_put(&to->localClient->buf_sendq, buf, length); |
| 104 |
|
|
return NULL; |
| 105 |
|
|
} |
| 106 |
|
|
|
| 107 |
|
|
/* |
| 108 |
adx |
30 |
** send_message |
| 109 |
|
|
** Internal utility which appends given buffer to the sockets |
| 110 |
|
|
** sendq. |
| 111 |
|
|
*/ |
| 112 |
|
|
static void |
| 113 |
|
|
send_message(struct Client *to, char *buf, int len) |
| 114 |
|
|
{ |
| 115 |
michael |
439 |
assert(!IsMe(to)); |
| 116 |
michael |
438 |
assert(to != &me); |
| 117 |
adx |
30 |
|
| 118 |
|
|
if (dbuf_length(&to->localClient->buf_sendq) + len > get_sendq(to)) |
| 119 |
|
|
{ |
| 120 |
|
|
if (IsServer(to)) |
| 121 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 122 |
|
|
"Max SendQ limit exceeded for %s: %lu > %lu", |
| 123 |
|
|
get_client_name(to, HIDE_IP), |
| 124 |
|
|
(unsigned long)(dbuf_length(&to->localClient->buf_sendq) + len), |
| 125 |
|
|
get_sendq(to)); |
| 126 |
|
|
if (IsClient(to)) |
| 127 |
|
|
SetSendQExceeded(to); |
| 128 |
|
|
dead_link_on_write(to, 0); |
| 129 |
|
|
return; |
| 130 |
|
|
} |
| 131 |
|
|
|
| 132 |
adx |
163 |
execute_callback(iosend_cb, to, len, buf); |
| 133 |
adx |
30 |
|
| 134 |
|
|
/* |
| 135 |
|
|
** Update statistics. The following is slightly incorrect |
| 136 |
|
|
** because it counts messages even if queued, but bytes |
| 137 |
|
|
** only really sent. Queued bytes get updated in SendQueued. |
| 138 |
|
|
*/ |
| 139 |
|
|
++to->localClient->send.messages; |
| 140 |
|
|
++me.localClient->send.messages; |
| 141 |
|
|
|
| 142 |
|
|
if (dbuf_length(&to->localClient->buf_sendq) > |
| 143 |
|
|
(IsServer(to) ? (unsigned int) 1024 : (unsigned int) 4096)) |
| 144 |
|
|
send_queued_write(to); |
| 145 |
|
|
} |
| 146 |
|
|
|
| 147 |
|
|
/* send_message_remote() |
| 148 |
|
|
* |
| 149 |
|
|
* inputs - pointer to client from message is being sent |
| 150 |
|
|
* - pointer to client to send to |
| 151 |
|
|
* - pointer to preformatted buffer |
| 152 |
|
|
* - length of input buffer |
| 153 |
|
|
* output - none |
| 154 |
|
|
* side effects - Despite the function name, this only sends to directly |
| 155 |
|
|
* connected clients. |
| 156 |
|
|
* |
| 157 |
|
|
*/ |
| 158 |
|
|
static void |
| 159 |
|
|
send_message_remote(struct Client *to, struct Client *from, |
| 160 |
|
|
char *buf, int len) |
| 161 |
|
|
{ |
| 162 |
|
|
if (!MyConnect(to)) |
| 163 |
|
|
{ |
| 164 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 165 |
|
|
"server send message to %s [%s] dropped from %s(Not local server)", |
| 166 |
|
|
to->name, to->from->name, from->name); |
| 167 |
|
|
return; |
| 168 |
|
|
} |
| 169 |
|
|
|
| 170 |
|
|
/* Optimize by checking if (from && to) before everything */ |
| 171 |
|
|
/* we set to->from up there.. */ |
| 172 |
|
|
|
| 173 |
|
|
if (!MyClient(from) && IsClient(to) && (to == from->from)) |
| 174 |
|
|
{ |
| 175 |
|
|
if (IsServer(from)) |
| 176 |
|
|
{ |
| 177 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 178 |
|
|
"Send message to %s [%s] dropped from %s(Fake Dir)", |
| 179 |
|
|
to->name, to->from->name, from->name); |
| 180 |
|
|
return; |
| 181 |
|
|
} |
| 182 |
|
|
|
| 183 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 184 |
|
|
"Ghosted: %s[%s@%s] from %s[%s@%s] (%s)", |
| 185 |
|
|
to->name, to->username, to->host, |
| 186 |
|
|
from->name, from->username, from->host, |
| 187 |
|
|
to->from->name); |
| 188 |
|
|
|
| 189 |
michael |
885 |
sendto_server(NULL, NULL, CAP_TS6, NOCAPS, |
| 190 |
adx |
30 |
":%s KILL %s :%s (%s[%s@%s] Ghosted %s)", |
| 191 |
|
|
me.id, to->name, me.name, to->name, |
| 192 |
|
|
to->username, to->host, to->from->name); |
| 193 |
michael |
885 |
sendto_server(NULL, NULL, NOCAPS, CAP_TS6, |
| 194 |
adx |
30 |
":%s KILL %s :%s (%s[%s@%s] Ghosted %s)", |
| 195 |
|
|
me.name, to->name, me.name, to->name, |
| 196 |
|
|
to->username, to->host, to->from->name); |
| 197 |
|
|
|
| 198 |
|
|
SetKilled(to); |
| 199 |
|
|
|
| 200 |
|
|
if (IsClient(from)) |
| 201 |
|
|
sendto_one(from, form_str(ERR_GHOSTEDCLIENT), |
| 202 |
|
|
me.name, from->name, to->name, to->username, |
| 203 |
|
|
to->host, to->from); |
| 204 |
|
|
|
| 205 |
|
|
exit_client(to, &me, "Ghosted client"); |
| 206 |
|
|
|
| 207 |
|
|
return; |
| 208 |
|
|
} |
| 209 |
|
|
|
| 210 |
|
|
send_message(to, buf, len); |
| 211 |
|
|
} |
| 212 |
|
|
|
| 213 |
|
|
/* |
| 214 |
|
|
** sendq_unblocked |
| 215 |
|
|
** Called when a socket is ready for writing. |
| 216 |
|
|
*/ |
| 217 |
|
|
void |
| 218 |
|
|
sendq_unblocked(fde_t *fd, struct Client *client_p) |
| 219 |
|
|
{ |
| 220 |
|
|
ClearSendqBlocked(client_p); |
| 221 |
|
|
/* let send_queued_write be executed by send_queued_all */ |
| 222 |
|
|
|
| 223 |
|
|
#ifdef HAVE_LIBCRYPTO |
| 224 |
|
|
if (fd->flags.pending_read) |
| 225 |
|
|
{ |
| 226 |
|
|
fd->flags.pending_read = 0; |
| 227 |
|
|
read_packet(fd, client_p); |
| 228 |
|
|
} |
| 229 |
|
|
#endif |
| 230 |
|
|
} |
| 231 |
|
|
|
| 232 |
|
|
/* |
| 233 |
|
|
** slinkq_unblocked |
| 234 |
|
|
** Called when a server control socket is ready for writing. |
| 235 |
|
|
*/ |
| 236 |
|
|
static void |
| 237 |
|
|
slinkq_unblocked(fde_t *fd, struct Client *client_p) |
| 238 |
|
|
{ |
| 239 |
|
|
ClearSlinkqBlocked(client_p); |
| 240 |
|
|
send_queued_slink_write(client_p); |
| 241 |
|
|
} |
| 242 |
|
|
|
| 243 |
|
|
/* |
| 244 |
|
|
** send_queued_write |
| 245 |
|
|
** This is called when there is a chance that some output would |
| 246 |
|
|
** be possible. This attempts to empty the send queue as far as |
| 247 |
|
|
** possible, and then if any data is left, a write is rescheduled. |
| 248 |
|
|
*/ |
| 249 |
|
|
void |
| 250 |
|
|
send_queued_write(struct Client *to) |
| 251 |
|
|
{ |
| 252 |
|
|
int retlen; |
| 253 |
|
|
struct dbuf_block *first; |
| 254 |
|
|
|
| 255 |
|
|
/* |
| 256 |
|
|
** Once socket is marked dead, we cannot start writing to it, |
| 257 |
|
|
** even if the error is removed... |
| 258 |
|
|
*/ |
| 259 |
|
|
if (IsDead(to) || IsSendqBlocked(to)) |
| 260 |
|
|
return; /* no use calling send() now */ |
| 261 |
|
|
|
| 262 |
|
|
/* Next, lets try to write some data */ |
| 263 |
|
|
|
| 264 |
|
|
if (dbuf_length(&to->localClient->buf_sendq)) |
| 265 |
|
|
{ |
| 266 |
|
|
do { |
| 267 |
|
|
first = to->localClient->buf_sendq.blocks.head->data; |
| 268 |
|
|
|
| 269 |
|
|
#ifdef HAVE_LIBCRYPTO |
| 270 |
|
|
if (to->localClient->fd.ssl) |
| 271 |
|
|
{ |
| 272 |
|
|
retlen = SSL_write(to->localClient->fd.ssl, first->data, first->size); |
| 273 |
|
|
|
| 274 |
|
|
/* translate openssl error codes, sigh */ |
| 275 |
|
|
if (retlen < 0) |
| 276 |
|
|
switch (SSL_get_error(to->localClient->fd.ssl, retlen)) |
| 277 |
|
|
{ |
| 278 |
|
|
case SSL_ERROR_WANT_READ: |
| 279 |
|
|
return; /* retry later, don't register for write events */ |
| 280 |
|
|
|
| 281 |
|
|
case SSL_ERROR_WANT_WRITE: |
| 282 |
|
|
errno = EWOULDBLOCK; |
| 283 |
|
|
case SSL_ERROR_SYSCALL: |
| 284 |
|
|
break; |
| 285 |
michael |
430 |
case SSL_ERROR_SSL: |
| 286 |
|
|
if (errno == EAGAIN) |
| 287 |
|
|
break; |
| 288 |
adx |
30 |
default: |
| 289 |
|
|
retlen = errno = 0; /* either an SSL-specific error or EOF */ |
| 290 |
|
|
} |
| 291 |
|
|
} |
| 292 |
|
|
else |
| 293 |
|
|
#endif |
| 294 |
|
|
retlen = send(to->localClient->fd.fd, first->data, first->size, 0); |
| 295 |
|
|
|
| 296 |
|
|
if (retlen <= 0) |
| 297 |
|
|
{ |
| 298 |
|
|
#ifdef _WIN32 |
| 299 |
|
|
errno = WSAGetLastError(); |
| 300 |
|
|
#endif |
| 301 |
|
|
break; |
| 302 |
|
|
} |
| 303 |
|
|
|
| 304 |
|
|
dbuf_delete(&to->localClient->buf_sendq, retlen); |
| 305 |
|
|
|
| 306 |
|
|
/* We have some data written .. update counters */ |
| 307 |
|
|
to->localClient->send.bytes += retlen; |
| 308 |
|
|
me.localClient->send.bytes += retlen; |
| 309 |
|
|
} while (dbuf_length(&to->localClient->buf_sendq)); |
| 310 |
|
|
|
| 311 |
|
|
if ((retlen < 0) && (ignoreErrno(errno))) |
| 312 |
|
|
{ |
| 313 |
|
|
/* we have a non-fatal error, reschedule a write */ |
| 314 |
|
|
SetSendqBlocked(to); |
| 315 |
|
|
comm_setselect(&to->localClient->fd, COMM_SELECT_WRITE, |
| 316 |
|
|
(PF *)sendq_unblocked, (void *)to, 0); |
| 317 |
|
|
} |
| 318 |
|
|
else if (retlen <= 0) |
| 319 |
|
|
{ |
| 320 |
|
|
dead_link_on_write(to, errno); |
| 321 |
|
|
return; |
| 322 |
|
|
} |
| 323 |
|
|
} |
| 324 |
|
|
} |
| 325 |
|
|
|
| 326 |
|
|
/* |
| 327 |
|
|
** send_queued_slink_write |
| 328 |
|
|
** This is called when there is a chance the some output would |
| 329 |
|
|
** be possible. This attempts to empty the send queue as far as |
| 330 |
|
|
** possible, and then if any data is left, a write is rescheduled. |
| 331 |
|
|
*/ |
| 332 |
|
|
void |
| 333 |
|
|
send_queued_slink_write(struct Client *to) |
| 334 |
|
|
{ |
| 335 |
|
|
int retlen; |
| 336 |
|
|
|
| 337 |
|
|
/* |
| 338 |
|
|
** Once socket is marked dead, we cannot start writing to it, |
| 339 |
|
|
** even if the error is removed... |
| 340 |
|
|
*/ |
| 341 |
|
|
if (IsDead(to) || IsSlinkqBlocked(to)) |
| 342 |
|
|
return; /* no use calling send() now */ |
| 343 |
|
|
|
| 344 |
|
|
/* Next, lets try to write some data */ |
| 345 |
|
|
if (to->localClient->slinkq != NULL) |
| 346 |
|
|
{ |
| 347 |
|
|
retlen = send(to->localClient->ctrlfd.fd, |
| 348 |
|
|
to->localClient->slinkq + to->localClient->slinkq_ofs, |
| 349 |
|
|
to->localClient->slinkq_len, 0); |
| 350 |
|
|
if (retlen < 0) |
| 351 |
|
|
{ |
| 352 |
|
|
/* If we have a fatal error */ |
| 353 |
|
|
if (!ignoreErrno(errno)) |
| 354 |
|
|
{ |
| 355 |
|
|
dead_link_on_write(to, errno); |
| 356 |
|
|
return; |
| 357 |
|
|
} |
| 358 |
|
|
} |
| 359 |
|
|
else if (retlen == 0) |
| 360 |
|
|
{ |
| 361 |
|
|
/* 0 bytes is an EOF .. */ |
| 362 |
|
|
dead_link_on_write(to, 0); |
| 363 |
|
|
return; |
| 364 |
|
|
} |
| 365 |
|
|
else |
| 366 |
|
|
{ |
| 367 |
|
|
execute_callback(iosendctrl_cb, to, retlen, |
| 368 |
|
|
to->localClient->slinkq + to->localClient->slinkq_ofs); |
| 369 |
|
|
to->localClient->slinkq_len -= retlen; |
| 370 |
|
|
|
| 371 |
|
|
assert(to->localClient->slinkq_len >= 0); |
| 372 |
|
|
if (to->localClient->slinkq_len) |
| 373 |
|
|
to->localClient->slinkq_ofs += retlen; |
| 374 |
|
|
else |
| 375 |
|
|
{ |
| 376 |
|
|
to->localClient->slinkq_ofs = 0; |
| 377 |
|
|
MyFree(to->localClient->slinkq); |
| 378 |
|
|
to->localClient->slinkq = NULL; |
| 379 |
|
|
} |
| 380 |
|
|
} |
| 381 |
|
|
|
| 382 |
|
|
/* Finally, if we have any more data, reschedule a write */ |
| 383 |
|
|
if (to->localClient->slinkq_len) |
| 384 |
|
|
{ |
| 385 |
|
|
SetSlinkqBlocked(to); |
| 386 |
|
|
comm_setselect(&to->localClient->ctrlfd, COMM_SELECT_WRITE, |
| 387 |
|
|
(PF *)slinkq_unblocked, (void *)to, 0); |
| 388 |
|
|
} |
| 389 |
|
|
} |
| 390 |
|
|
} |
| 391 |
|
|
|
| 392 |
|
|
/* send_queued_all() |
| 393 |
|
|
* |
| 394 |
|
|
* input - NONE |
| 395 |
|
|
* output - NONE |
| 396 |
|
|
* side effects - try to flush sendq of each client |
| 397 |
|
|
*/ |
| 398 |
|
|
void |
| 399 |
|
|
send_queued_all(void) |
| 400 |
|
|
{ |
| 401 |
|
|
dlink_node *ptr; |
| 402 |
|
|
|
| 403 |
|
|
/* Servers are processed first, mainly because this can generate |
| 404 |
|
|
* a notice to opers, which is to be delivered by this function. |
| 405 |
|
|
*/ |
| 406 |
|
|
DLINK_FOREACH(ptr, serv_list.head) |
| 407 |
|
|
send_queued_write((struct Client *) ptr->data); |
| 408 |
|
|
|
| 409 |
|
|
DLINK_FOREACH(ptr, unknown_list.head) |
| 410 |
|
|
send_queued_write((struct Client *) ptr->data); |
| 411 |
|
|
|
| 412 |
|
|
DLINK_FOREACH(ptr, local_client_list.head) |
| 413 |
|
|
send_queued_write((struct Client *) ptr->data); |
| 414 |
|
|
|
| 415 |
|
|
/* NOTE: This can still put clients on aborted_list; unfortunately, |
| 416 |
|
|
* exit_aborted_clients takes precedence over send_queued_all, |
| 417 |
|
|
* because exiting clients can generate server/oper traffic. |
| 418 |
|
|
* The easiest approach is dealing with aborted clients in the next I/O lap. |
| 419 |
|
|
* -adx |
| 420 |
|
|
*/ |
| 421 |
|
|
} |
| 422 |
|
|
|
| 423 |
|
|
/* sendto_one() |
| 424 |
|
|
* |
| 425 |
|
|
* inputs - pointer to destination client |
| 426 |
|
|
* - var args message |
| 427 |
|
|
* output - NONE |
| 428 |
|
|
* side effects - send message to single client |
| 429 |
|
|
*/ |
| 430 |
|
|
void |
| 431 |
|
|
sendto_one(struct Client *to, const char *pattern, ...) |
| 432 |
|
|
{ |
| 433 |
|
|
va_list args; |
| 434 |
|
|
char buffer[IRCD_BUFSIZE]; |
| 435 |
|
|
int len; |
| 436 |
|
|
|
| 437 |
|
|
if (to->from != NULL) |
| 438 |
|
|
to = to->from; |
| 439 |
|
|
if (IsDead(to)) |
| 440 |
|
|
return; /* This socket has already been marked as dead */ |
| 441 |
|
|
|
| 442 |
|
|
va_start(args, pattern); |
| 443 |
|
|
len = send_format(buffer, IRCD_BUFSIZE, pattern, args); |
| 444 |
|
|
va_end(args); |
| 445 |
|
|
|
| 446 |
|
|
send_message(to, buffer, len); |
| 447 |
|
|
} |
| 448 |
|
|
|
| 449 |
|
|
/* sendto_channel_butone() |
| 450 |
|
|
* |
| 451 |
|
|
* inputs - pointer to client(server) to NOT send message to |
| 452 |
|
|
* - pointer to client that is sending this message |
| 453 |
|
|
* - pointer to channel being sent to |
| 454 |
|
|
* - vargs message |
| 455 |
|
|
* output - NONE |
| 456 |
|
|
* side effects - message as given is sent to given channel members. |
| 457 |
|
|
* |
| 458 |
|
|
* WARNING - +D clients are ignored |
| 459 |
|
|
*/ |
| 460 |
|
|
void |
| 461 |
|
|
sendto_channel_butone(struct Client *one, struct Client *from, |
| 462 |
|
|
struct Channel *chptr, const char *command, |
| 463 |
|
|
const char *pattern, ...) |
| 464 |
|
|
{ |
| 465 |
adx |
285 |
va_list alocal, aremote, auid; |
| 466 |
adx |
30 |
char local_buf[IRCD_BUFSIZE]; |
| 467 |
|
|
char remote_buf[IRCD_BUFSIZE]; |
| 468 |
|
|
char uid_buf[IRCD_BUFSIZE]; |
| 469 |
|
|
int local_len, remote_len, uid_len; |
| 470 |
|
|
dlink_node *ptr; |
| 471 |
|
|
dlink_node *ptr_next; |
| 472 |
|
|
struct Client *target_p; |
| 473 |
|
|
|
| 474 |
|
|
if (IsServer(from)) |
| 475 |
|
|
local_len = ircsprintf(local_buf, ":%s %s %s ", |
| 476 |
|
|
from->name, command, chptr->chname); |
| 477 |
|
|
else |
| 478 |
|
|
local_len = ircsprintf(local_buf, ":%s!%s@%s %s %s ", |
| 479 |
|
|
from->name, from->username, from->host, |
| 480 |
|
|
command, chptr->chname); |
| 481 |
|
|
remote_len = ircsprintf(remote_buf, ":%s %s %s ", |
| 482 |
|
|
from->name, command, chptr->chname); |
| 483 |
|
|
uid_len = ircsprintf(uid_buf, ":%s %s %s ", |
| 484 |
|
|
ID(from), command, chptr->chname); |
| 485 |
|
|
|
| 486 |
adx |
285 |
va_start(alocal, pattern); |
| 487 |
|
|
va_start(aremote, pattern); |
| 488 |
|
|
va_start(auid, pattern); |
| 489 |
adx |
30 |
local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len, |
| 490 |
adx |
285 |
pattern, alocal); |
| 491 |
adx |
30 |
remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len, |
| 492 |
adx |
285 |
pattern, aremote); |
| 493 |
adx |
30 |
uid_len += send_format(&uid_buf[uid_len], IRCD_BUFSIZE - uid_len, pattern, |
| 494 |
adx |
285 |
auid); |
| 495 |
|
|
va_end(auid); |
| 496 |
|
|
va_end(aremote); |
| 497 |
|
|
va_end(alocal); |
| 498 |
adx |
30 |
|
| 499 |
|
|
++current_serial; |
| 500 |
|
|
|
| 501 |
|
|
DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->members.head) |
| 502 |
|
|
{ |
| 503 |
|
|
target_p = ((struct Membership *)ptr->data)->client_p; |
| 504 |
|
|
assert(target_p != NULL); |
| 505 |
|
|
|
| 506 |
|
|
if (IsDefunct(target_p) || IsDeaf(target_p) || target_p->from == one) |
| 507 |
|
|
continue; |
| 508 |
|
|
|
| 509 |
|
|
if (MyClient(target_p)) |
| 510 |
|
|
{ |
| 511 |
|
|
if (target_p->serial != current_serial) |
| 512 |
|
|
{ |
| 513 |
|
|
send_message(target_p, local_buf, local_len); |
| 514 |
|
|
target_p->serial = current_serial; |
| 515 |
|
|
} |
| 516 |
|
|
} |
| 517 |
|
|
else |
| 518 |
|
|
{ |
| 519 |
|
|
/* Now check whether a message has been sent to this |
| 520 |
|
|
* remote link already |
| 521 |
|
|
*/ |
| 522 |
|
|
if (target_p->from->serial != current_serial) |
| 523 |
|
|
{ |
| 524 |
|
|
if (IsCapable(target_p->from, CAP_TS6)) |
| 525 |
|
|
send_message_remote(target_p->from, from, uid_buf, uid_len); |
| 526 |
|
|
else |
| 527 |
|
|
send_message_remote(target_p->from, from, remote_buf, remote_len); |
| 528 |
|
|
target_p->from->serial = current_serial; |
| 529 |
|
|
} |
| 530 |
|
|
} |
| 531 |
|
|
} |
| 532 |
|
|
} |
| 533 |
|
|
|
| 534 |
|
|
/* sendto_server() |
| 535 |
|
|
* |
| 536 |
|
|
* inputs - pointer to client to NOT send to |
| 537 |
db |
939 |
* - pointer to channel |
| 538 |
adx |
30 |
* - caps or'd together which must ALL be present |
| 539 |
|
|
* - caps or'd together which must ALL NOT be present |
| 540 |
|
|
* - printf style format string |
| 541 |
|
|
* - args to format string |
| 542 |
|
|
* output - NONE |
| 543 |
|
|
* side effects - Send a message to all connected servers, except the |
| 544 |
|
|
* client 'one' (if non-NULL), as long as the servers |
| 545 |
|
|
* support ALL capabs in 'caps', and NO capabs in 'nocaps'. |
| 546 |
|
|
* |
| 547 |
|
|
* This function was written in an attempt to merge together the other |
| 548 |
|
|
* billion sendto_*serv*() functions, which sprung up with capabs, |
| 549 |
|
|
* lazylinks, uids, etc. |
| 550 |
|
|
* -davidt |
| 551 |
|
|
*/ |
| 552 |
|
|
void |
| 553 |
michael |
885 |
sendto_server(struct Client *one, |
| 554 |
adx |
30 |
struct Channel *chptr, unsigned long caps, |
| 555 |
michael |
885 |
unsigned long nocaps, |
| 556 |
adx |
30 |
const char *format, ...) |
| 557 |
|
|
{ |
| 558 |
|
|
va_list args; |
| 559 |
michael |
885 |
dlink_node *ptr = NULL; |
| 560 |
adx |
30 |
char buffer[IRCD_BUFSIZE]; |
| 561 |
michael |
885 |
int len = 0; |
| 562 |
adx |
30 |
|
| 563 |
michael |
885 |
if (chptr && chptr->chname[0] != '#') |
| 564 |
|
|
return; |
| 565 |
adx |
30 |
|
| 566 |
|
|
va_start(args, format); |
| 567 |
|
|
len = send_format(buffer, IRCD_BUFSIZE, format, args); |
| 568 |
|
|
va_end(args); |
| 569 |
|
|
|
| 570 |
|
|
DLINK_FOREACH(ptr, serv_list.head) |
| 571 |
|
|
{ |
| 572 |
michael |
885 |
struct Client *client_p = ptr->data; |
| 573 |
adx |
30 |
|
| 574 |
|
|
/* If dead already skip */ |
| 575 |
|
|
if (IsDead(client_p)) |
| 576 |
|
|
continue; |
| 577 |
|
|
/* check against 'one' */ |
| 578 |
|
|
if (one != NULL && (client_p == one->from)) |
| 579 |
|
|
continue; |
| 580 |
|
|
/* check we have required capabs */ |
| 581 |
|
|
if ((client_p->localClient->caps & caps) != caps) |
| 582 |
|
|
continue; |
| 583 |
|
|
/* check we don't have any forbidden capabs */ |
| 584 |
|
|
if ((client_p->localClient->caps & nocaps) != 0) |
| 585 |
|
|
continue; |
| 586 |
|
|
|
| 587 |
|
|
send_message(client_p, buffer, len); |
| 588 |
|
|
} |
| 589 |
|
|
} |
| 590 |
|
|
|
| 591 |
|
|
/* sendto_common_channels_local() |
| 592 |
|
|
* |
| 593 |
|
|
* inputs - pointer to client |
| 594 |
|
|
* - pattern to send |
| 595 |
|
|
* output - NONE |
| 596 |
|
|
* side effects - Sends a message to all people on local server who are |
| 597 |
|
|
* in same channel with user. |
| 598 |
|
|
* used by m_nick.c and exit_one_client. |
| 599 |
|
|
*/ |
| 600 |
|
|
void |
| 601 |
|
|
sendto_common_channels_local(struct Client *user, int touser, |
| 602 |
|
|
const char *pattern, ...) |
| 603 |
|
|
{ |
| 604 |
|
|
va_list args; |
| 605 |
|
|
dlink_node *uptr; |
| 606 |
|
|
dlink_node *cptr; |
| 607 |
|
|
struct Channel *chptr; |
| 608 |
|
|
struct Membership *ms; |
| 609 |
|
|
struct Client *target_p; |
| 610 |
|
|
char buffer[IRCD_BUFSIZE]; |
| 611 |
|
|
int len; |
| 612 |
|
|
|
| 613 |
|
|
va_start(args, pattern); |
| 614 |
|
|
len = send_format(buffer, IRCD_BUFSIZE, pattern, args); |
| 615 |
|
|
va_end(args); |
| 616 |
|
|
|
| 617 |
|
|
++current_serial; |
| 618 |
|
|
|
| 619 |
|
|
DLINK_FOREACH(cptr, user->channel.head) |
| 620 |
|
|
{ |
| 621 |
|
|
chptr = ((struct Membership *) cptr->data)->chptr; |
| 622 |
|
|
assert(chptr != NULL); |
| 623 |
|
|
|
| 624 |
michael |
572 |
DLINK_FOREACH(uptr, chptr->members.head) |
| 625 |
adx |
30 |
{ |
| 626 |
|
|
ms = uptr->data; |
| 627 |
|
|
target_p = ms->client_p; |
| 628 |
|
|
assert(target_p != NULL); |
| 629 |
|
|
|
| 630 |
michael |
572 |
if (!MyConnect(target_p) || target_p == user || IsDefunct(target_p) || |
| 631 |
adx |
30 |
target_p->serial == current_serial) |
| 632 |
|
|
continue; |
| 633 |
|
|
|
| 634 |
|
|
target_p->serial = current_serial; |
| 635 |
|
|
send_message(target_p, buffer, len); |
| 636 |
|
|
} |
| 637 |
|
|
} |
| 638 |
|
|
|
| 639 |
|
|
if (touser && MyConnect(user) && !IsDead(user) && |
| 640 |
|
|
user->serial != current_serial) |
| 641 |
|
|
send_message(user, buffer, len); |
| 642 |
|
|
} |
| 643 |
|
|
|
| 644 |
|
|
/* sendto_channel_local() |
| 645 |
|
|
* |
| 646 |
|
|
* inputs - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE |
| 647 |
|
|
* - whether to ignore +D clients (YES/NO) |
| 648 |
|
|
* - pointer to channel to send to |
| 649 |
|
|
* - var args pattern |
| 650 |
|
|
* output - NONE |
| 651 |
|
|
* side effects - Send a message to all members of a channel that are |
| 652 |
|
|
* locally connected to this server. |
| 653 |
|
|
*/ |
| 654 |
|
|
void |
| 655 |
|
|
sendto_channel_local(int type, int nodeaf, struct Channel *chptr, |
| 656 |
|
|
const char *pattern, ...) |
| 657 |
|
|
{ |
| 658 |
|
|
va_list args; |
| 659 |
|
|
char buffer[IRCD_BUFSIZE]; |
| 660 |
|
|
int len; |
| 661 |
|
|
dlink_node *ptr; |
| 662 |
|
|
struct Membership *ms; |
| 663 |
|
|
struct Client *target_p; |
| 664 |
|
|
|
| 665 |
|
|
va_start(args, pattern); |
| 666 |
|
|
len = send_format(buffer, IRCD_BUFSIZE, pattern, args); |
| 667 |
|
|
va_end(args); |
| 668 |
|
|
|
| 669 |
michael |
572 |
DLINK_FOREACH(ptr, chptr->members.head) |
| 670 |
adx |
30 |
{ |
| 671 |
|
|
ms = ptr->data; |
| 672 |
|
|
target_p = ms->client_p; |
| 673 |
|
|
|
| 674 |
|
|
if (type != 0 && (ms->flags & type) == 0) |
| 675 |
|
|
continue; |
| 676 |
|
|
|
| 677 |
michael |
572 |
if (!MyConnect(target_p) || IsDefunct(target_p) || |
| 678 |
|
|
(nodeaf && IsDeaf(target_p))) |
| 679 |
adx |
30 |
continue; |
| 680 |
|
|
|
| 681 |
|
|
send_message(target_p, buffer, len); |
| 682 |
|
|
} |
| 683 |
|
|
} |
| 684 |
|
|
|
| 685 |
|
|
/* sendto_channel_local_butone() |
| 686 |
|
|
* |
| 687 |
|
|
* inputs - pointer to client to NOT send message to |
| 688 |
|
|
* - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE |
| 689 |
|
|
* - pointer to channel to send to |
| 690 |
|
|
* - var args pattern |
| 691 |
|
|
* output - NONE |
| 692 |
|
|
* side effects - Send a message to all members of a channel that are |
| 693 |
|
|
* locally connected to this server except one. |
| 694 |
|
|
* |
| 695 |
|
|
* WARNING - +D clients are omitted |
| 696 |
|
|
*/ |
| 697 |
|
|
void |
| 698 |
|
|
sendto_channel_local_butone(struct Client *one, int type, |
| 699 |
|
|
struct Channel *chptr, const char *pattern, ...) |
| 700 |
|
|
{ |
| 701 |
|
|
va_list args; |
| 702 |
|
|
char buffer[IRCD_BUFSIZE]; |
| 703 |
|
|
int len; |
| 704 |
|
|
struct Client *target_p; |
| 705 |
|
|
struct Membership *ms; |
| 706 |
|
|
dlink_node *ptr; |
| 707 |
|
|
|
| 708 |
|
|
va_start(args, pattern); |
| 709 |
|
|
len = send_format(buffer, IRCD_BUFSIZE, pattern, args); |
| 710 |
|
|
va_end(args); |
| 711 |
|
|
|
| 712 |
michael |
572 |
DLINK_FOREACH(ptr, chptr->members.head) |
| 713 |
adx |
30 |
{ |
| 714 |
|
|
ms = ptr->data; |
| 715 |
|
|
target_p = ms->client_p; |
| 716 |
|
|
|
| 717 |
|
|
if (type != 0 && (ms->flags & type) == 0) |
| 718 |
|
|
continue; |
| 719 |
|
|
|
| 720 |
michael |
572 |
if (!MyConnect(target_p) || target_p == one || |
| 721 |
|
|
IsDefunct(target_p) || IsDeaf(target_p)) |
| 722 |
adx |
30 |
continue; |
| 723 |
|
|
send_message(target_p, buffer, len); |
| 724 |
|
|
} |
| 725 |
|
|
} |
| 726 |
|
|
|
| 727 |
|
|
|
| 728 |
|
|
/* sendto_channel_remote() |
| 729 |
|
|
* |
| 730 |
|
|
* inputs - Client not to send towards |
| 731 |
|
|
* - Client from whom message is from |
| 732 |
|
|
* - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE |
| 733 |
|
|
* - pointer to channel to send to |
| 734 |
|
|
* - var args pattern |
| 735 |
|
|
* output - NONE |
| 736 |
|
|
* side effects - Send a message to all members of a channel that are |
| 737 |
|
|
* remote to this server. |
| 738 |
|
|
*/ |
| 739 |
|
|
void |
| 740 |
|
|
sendto_channel_remote(struct Client *one, struct Client *from, int type, int caps, |
| 741 |
|
|
int nocaps, struct Channel *chptr, const char *pattern, ...) |
| 742 |
|
|
{ |
| 743 |
|
|
va_list args; |
| 744 |
|
|
char buffer[IRCD_BUFSIZE]; |
| 745 |
|
|
int len; |
| 746 |
|
|
dlink_node *ptr; |
| 747 |
|
|
struct Client *target_p; |
| 748 |
|
|
struct Membership *ms; |
| 749 |
|
|
|
| 750 |
|
|
va_start(args, pattern); |
| 751 |
|
|
len = send_format(buffer, IRCD_BUFSIZE, pattern, args); |
| 752 |
|
|
va_end(args); |
| 753 |
|
|
|
| 754 |
db |
189 |
++current_serial; |
| 755 |
|
|
|
| 756 |
adx |
30 |
DLINK_FOREACH(ptr, chptr->members.head) |
| 757 |
|
|
{ |
| 758 |
|
|
ms = ptr->data; |
| 759 |
|
|
target_p = ms->client_p; |
| 760 |
|
|
|
| 761 |
|
|
if (type != 0 && (ms->flags & type) == 0) |
| 762 |
|
|
continue; |
| 763 |
|
|
|
| 764 |
|
|
if (MyConnect(target_p)) |
| 765 |
|
|
continue; |
| 766 |
|
|
target_p = target_p->from; |
| 767 |
|
|
|
| 768 |
|
|
if (target_p == one->from || |
| 769 |
|
|
((target_p->from->localClient->caps & caps) != caps) || |
| 770 |
|
|
((target_p->from->localClient->caps & nocaps) != 0)) |
| 771 |
|
|
continue; |
| 772 |
db |
189 |
if (target_p->from->serial != current_serial) |
| 773 |
|
|
{ |
| 774 |
|
|
send_message(target_p, buffer, len); |
| 775 |
|
|
target_p->from->serial = current_serial; |
| 776 |
|
|
} |
| 777 |
adx |
30 |
} |
| 778 |
|
|
} |
| 779 |
|
|
|
| 780 |
|
|
/* |
| 781 |
|
|
** match_it() and sendto_match_butone() ARE only used |
| 782 |
|
|
** to send a msg to all ppl on servers/hosts that match a specified mask |
| 783 |
|
|
** (used for enhanced PRIVMSGs) for opers |
| 784 |
|
|
** |
| 785 |
|
|
** addition -- Armin, 8jun90 (gruner@informatik.tu-muenchen.de) |
| 786 |
|
|
** |
| 787 |
|
|
*/ |
| 788 |
|
|
|
| 789 |
|
|
/* match_it() |
| 790 |
|
|
* |
| 791 |
|
|
* inputs - client pointer to match on |
| 792 |
|
|
* - actual mask to match |
| 793 |
|
|
* - what to match on, HOST or SERVER |
| 794 |
|
|
* output - 1 or 0 if match or not |
| 795 |
|
|
* side effects - NONE |
| 796 |
|
|
*/ |
| 797 |
|
|
static int |
| 798 |
|
|
match_it(const struct Client *one, const char *mask, int what) |
| 799 |
|
|
{ |
| 800 |
|
|
if (what == MATCH_HOST) |
| 801 |
|
|
return(match(mask, one->host)); |
| 802 |
|
|
|
| 803 |
|
|
return(match(mask, one->servptr->name)); |
| 804 |
|
|
} |
| 805 |
|
|
|
| 806 |
|
|
/* sendto_match_butone() |
| 807 |
|
|
* |
| 808 |
|
|
* Send to all clients which match the mask in a way defined on 'what'; |
| 809 |
|
|
* either by user hostname or user servername. |
| 810 |
|
|
* |
| 811 |
|
|
* ugh. ONLY used by m_message.c to send an "oper magic" message. ugh. |
| 812 |
|
|
*/ |
| 813 |
|
|
void |
| 814 |
|
|
sendto_match_butone(struct Client *one, struct Client *from, char *mask, |
| 815 |
|
|
int what, const char *pattern, ...) |
| 816 |
|
|
{ |
| 817 |
adx |
285 |
va_list alocal, aremote; |
| 818 |
adx |
30 |
struct Client *client_p; |
| 819 |
|
|
dlink_node *ptr, *ptr_next; |
| 820 |
|
|
char local_buf[IRCD_BUFSIZE], remote_buf[IRCD_BUFSIZE]; |
| 821 |
|
|
int local_len = ircsprintf(local_buf, ":%s!%s@%s ", from->name, |
| 822 |
|
|
from->username, from->host); |
| 823 |
|
|
int remote_len = ircsprintf(remote_buf, ":%s ", from->name); |
| 824 |
|
|
|
| 825 |
adx |
285 |
va_start(alocal, pattern); |
| 826 |
|
|
va_start(aremote, pattern); |
| 827 |
adx |
30 |
local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len, |
| 828 |
adx |
285 |
pattern, alocal); |
| 829 |
adx |
30 |
remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len, |
| 830 |
adx |
285 |
pattern, aremote); |
| 831 |
|
|
va_end(aremote); |
| 832 |
|
|
va_end(alocal); |
| 833 |
adx |
30 |
|
| 834 |
|
|
/* scan the local clients */ |
| 835 |
|
|
DLINK_FOREACH(ptr, local_client_list.head) |
| 836 |
|
|
{ |
| 837 |
|
|
client_p = ptr->data; |
| 838 |
|
|
|
| 839 |
|
|
if (client_p != one && !IsDefunct(client_p) && |
| 840 |
|
|
match_it(client_p, mask, what)) |
| 841 |
|
|
send_message(client_p, local_buf, local_len); |
| 842 |
|
|
} |
| 843 |
|
|
|
| 844 |
|
|
/* Now scan servers */ |
| 845 |
|
|
DLINK_FOREACH_SAFE(ptr, ptr_next, serv_list.head) |
| 846 |
|
|
{ |
| 847 |
|
|
client_p = ptr->data; |
| 848 |
|
|
|
| 849 |
|
|
/* |
| 850 |
|
|
* The old code looped through every client on the |
| 851 |
|
|
* network for each server to check if the |
| 852 |
|
|
* server (client_p) has at least 1 client matching |
| 853 |
|
|
* the mask, using something like: |
| 854 |
|
|
* |
| 855 |
|
|
* for (target_p = GlobalClientList; target_p; target_p = target_p->next) |
| 856 |
|
|
* if (IsRegisteredUser(target_p) && |
| 857 |
|
|
* match_it(target_p, mask, what) && |
| 858 |
|
|
* (target_p->from == client_p)) |
| 859 |
|
|
* vsendto_prefix_one(client_p, from, pattern, args); |
| 860 |
|
|
* |
| 861 |
|
|
* That way, we wouldn't send the message to |
| 862 |
|
|
* a server who didn't have a matching client. |
| 863 |
|
|
* However, on a network such as EFNet, that |
| 864 |
|
|
* code would have looped through about 50 |
| 865 |
|
|
* servers, and in each loop, loop through |
| 866 |
|
|
* about 50k clients as well, calling match() |
| 867 |
|
|
* in each nested loop. That is a very bad |
| 868 |
|
|
* thing cpu wise - just send the message |
| 869 |
|
|
* to every connected server and let that |
| 870 |
|
|
* server deal with it. |
| 871 |
|
|
* -wnder |
| 872 |
|
|
*/ |
| 873 |
|
|
if (client_p != one && !IsDefunct(client_p)) |
| 874 |
|
|
send_message_remote(client_p, from, remote_buf, remote_len); |
| 875 |
|
|
} |
| 876 |
|
|
} |
| 877 |
|
|
|
| 878 |
|
|
/* sendto_match_servs() |
| 879 |
|
|
* |
| 880 |
|
|
* inputs - source client |
| 881 |
|
|
* - mask to send to |
| 882 |
|
|
* - capab needed |
| 883 |
|
|
* - data |
| 884 |
|
|
* outputs - none |
| 885 |
|
|
* side effects - data sent to servers matching with capab |
| 886 |
|
|
*/ |
| 887 |
|
|
void |
| 888 |
|
|
sendto_match_servs(struct Client *source_p, const char *mask, int cap, |
| 889 |
|
|
const char *pattern, ...) |
| 890 |
|
|
{ |
| 891 |
|
|
va_list args; |
| 892 |
|
|
struct Client *target_p; |
| 893 |
|
|
dlink_node *ptr; |
| 894 |
|
|
char buffer[IRCD_BUFSIZE]; |
| 895 |
|
|
int found = 0; |
| 896 |
|
|
|
| 897 |
|
|
va_start(args, pattern); |
| 898 |
|
|
vsnprintf(buffer, sizeof(buffer), pattern, args); |
| 899 |
|
|
va_end(args); |
| 900 |
|
|
|
| 901 |
|
|
current_serial++; |
| 902 |
|
|
|
| 903 |
|
|
DLINK_FOREACH(ptr, global_serv_list.head) |
| 904 |
|
|
{ |
| 905 |
|
|
target_p = ptr->data; |
| 906 |
|
|
|
| 907 |
|
|
/* Do not attempt to send to ourselves, or the source */ |
| 908 |
|
|
if (IsMe(target_p) || target_p->from == source_p->from) |
| 909 |
|
|
continue; |
| 910 |
|
|
|
| 911 |
|
|
if (target_p->from->serial == current_serial) |
| 912 |
|
|
continue; |
| 913 |
|
|
|
| 914 |
|
|
if (match(mask, target_p->name)) |
| 915 |
|
|
{ |
| 916 |
|
|
/* |
| 917 |
|
|
* if we set the serial here, then we'll never do a |
| 918 |
|
|
* match() again, if !IsCapable() |
| 919 |
|
|
*/ |
| 920 |
|
|
target_p->from->serial = current_serial; |
| 921 |
|
|
found++; |
| 922 |
|
|
|
| 923 |
|
|
if (!IsCapable(target_p->from, cap)) |
| 924 |
|
|
continue; |
| 925 |
|
|
|
| 926 |
|
|
sendto_anywhere(target_p, source_p, "%s", buffer); |
| 927 |
|
|
} |
| 928 |
|
|
} |
| 929 |
|
|
} |
| 930 |
|
|
|
| 931 |
|
|
/* sendto_anywhere() |
| 932 |
|
|
* |
| 933 |
|
|
* inputs - pointer to dest client |
| 934 |
|
|
* - pointer to from client |
| 935 |
|
|
* - varags |
| 936 |
|
|
* output - NONE |
| 937 |
|
|
* side effects - less efficient than sendto_remote and sendto_one |
| 938 |
|
|
* but useful when one does not know where target "lives" |
| 939 |
|
|
*/ |
| 940 |
|
|
void |
| 941 |
|
|
sendto_anywhere(struct Client *to, struct Client *from, |
| 942 |
|
|
const char *pattern, ...) |
| 943 |
|
|
{ |
| 944 |
|
|
va_list args; |
| 945 |
|
|
char buffer[IRCD_BUFSIZE]; |
| 946 |
|
|
int len; |
| 947 |
|
|
struct Client *send_to = (to->from != NULL ? to->from : to); |
| 948 |
|
|
|
| 949 |
|
|
if (IsDead(send_to)) |
| 950 |
|
|
return; |
| 951 |
|
|
|
| 952 |
|
|
if (MyClient(to)) |
| 953 |
|
|
{ |
| 954 |
|
|
if (IsServer(from)) |
| 955 |
|
|
{ |
| 956 |
|
|
if (IsCapable(to, CAP_TS6) && HasID(from)) |
| 957 |
|
|
len = ircsprintf(buffer, ":%s ", from->id); |
| 958 |
|
|
else |
| 959 |
|
|
len = ircsprintf(buffer, ":%s ", from->name); |
| 960 |
|
|
} |
| 961 |
|
|
else |
| 962 |
|
|
len = ircsprintf(buffer, ":%s!%s@%s ", |
| 963 |
|
|
from->name, from->username, from->host); |
| 964 |
|
|
} |
| 965 |
|
|
else len = ircsprintf(buffer, ":%s ", ID_or_name(from, send_to)); |
| 966 |
|
|
|
| 967 |
|
|
va_start(args, pattern); |
| 968 |
|
|
len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args); |
| 969 |
|
|
va_end(args); |
| 970 |
|
|
|
| 971 |
|
|
if(MyClient(to)) |
| 972 |
|
|
send_message(send_to, buffer, len); |
| 973 |
|
|
else |
| 974 |
|
|
send_message_remote(send_to, from, buffer, len); |
| 975 |
|
|
} |
| 976 |
|
|
|
| 977 |
|
|
/* sendto_realops_flags() |
| 978 |
|
|
* |
| 979 |
|
|
* inputs - flag types of messages to show to real opers |
| 980 |
|
|
* - flag indicating opers/admins |
| 981 |
|
|
* - var args input message |
| 982 |
|
|
* output - NONE |
| 983 |
|
|
* side effects - Send to *local* ops only but NOT +s nonopers. |
| 984 |
|
|
*/ |
| 985 |
|
|
void |
| 986 |
|
|
sendto_realops_flags(unsigned int flags, int level, const char *pattern, ...) |
| 987 |
|
|
{ |
| 988 |
|
|
struct Client *client_p; |
| 989 |
|
|
char nbuf[IRCD_BUFSIZE]; |
| 990 |
|
|
dlink_node *ptr; |
| 991 |
|
|
va_list args; |
| 992 |
|
|
|
| 993 |
|
|
va_start(args, pattern); |
| 994 |
|
|
vsnprintf(nbuf, IRCD_BUFSIZE, pattern, args); |
| 995 |
|
|
va_end(args); |
| 996 |
|
|
|
| 997 |
|
|
DLINK_FOREACH(ptr, oper_list.head) |
| 998 |
|
|
{ |
| 999 |
|
|
client_p = ptr->data; |
| 1000 |
|
|
assert(client_p->umodes & UMODE_OPER); |
| 1001 |
|
|
|
| 1002 |
|
|
/* If we're sending it to opers and theyre an admin, skip. |
| 1003 |
|
|
* If we're sending it to admins, and theyre not, skip. |
| 1004 |
|
|
*/ |
| 1005 |
|
|
if (((level == L_ADMIN) && !IsAdmin(client_p)) || |
| 1006 |
|
|
((level == L_OPER) && IsAdmin(client_p))) |
| 1007 |
|
|
continue; |
| 1008 |
|
|
|
| 1009 |
|
|
if (client_p->umodes & flags) |
| 1010 |
|
|
sendto_one(client_p, ":%s NOTICE %s :*** Notice -- %s", |
| 1011 |
|
|
me.name, client_p->name, nbuf); |
| 1012 |
|
|
} |
| 1013 |
|
|
} |
| 1014 |
|
|
|
| 1015 |
|
|
/* sendto_wallops_flags() |
| 1016 |
|
|
* |
| 1017 |
|
|
* inputs - flag types of messages to show to real opers |
| 1018 |
|
|
* - client sending request |
| 1019 |
|
|
* - var args input message |
| 1020 |
|
|
* output - NONE |
| 1021 |
|
|
* side effects - Send a wallops to local opers |
| 1022 |
|
|
*/ |
| 1023 |
|
|
void |
| 1024 |
|
|
sendto_wallops_flags(unsigned int flags, struct Client *source_p, |
| 1025 |
|
|
const char *pattern, ...) |
| 1026 |
|
|
{ |
| 1027 |
|
|
struct Client *client_p; |
| 1028 |
|
|
dlink_node *ptr; |
| 1029 |
|
|
va_list args; |
| 1030 |
|
|
char buffer[IRCD_BUFSIZE]; |
| 1031 |
|
|
int len; |
| 1032 |
|
|
|
| 1033 |
|
|
if (IsClient(source_p)) |
| 1034 |
|
|
len = ircsprintf(buffer, ":%s!%s@%s WALLOPS :", |
| 1035 |
|
|
source_p->name, source_p->username, source_p->host); |
| 1036 |
|
|
else |
| 1037 |
|
|
len = ircsprintf(buffer, ":%s WALLOPS :", source_p->name); |
| 1038 |
|
|
|
| 1039 |
|
|
va_start(args, pattern); |
| 1040 |
|
|
len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args); |
| 1041 |
|
|
va_end(args); |
| 1042 |
|
|
|
| 1043 |
|
|
DLINK_FOREACH(ptr, oper_list.head) |
| 1044 |
|
|
{ |
| 1045 |
|
|
client_p = ptr->data; |
| 1046 |
|
|
assert(client_p->umodes & UMODE_OPER); |
| 1047 |
|
|
|
| 1048 |
|
|
if ((client_p->umodes & flags) && !IsDefunct(client_p)) |
| 1049 |
|
|
send_message(client_p, buffer, len); |
| 1050 |
|
|
} |
| 1051 |
|
|
} |
| 1052 |
|
|
|
| 1053 |
|
|
/* ts_warn() |
| 1054 |
|
|
* |
| 1055 |
|
|
* inputs - var args message |
| 1056 |
|
|
* output - NONE |
| 1057 |
|
|
* side effects - Call sendto_realops_flags, with some flood checking |
| 1058 |
|
|
* (at most 5 warnings every 5 seconds) |
| 1059 |
|
|
*/ |
| 1060 |
|
|
void |
| 1061 |
|
|
ts_warn(const char *pattern, ...) |
| 1062 |
|
|
{ |
| 1063 |
|
|
va_list args; |
| 1064 |
|
|
char buffer[LOG_BUFSIZE]; |
| 1065 |
|
|
static time_t last = 0; |
| 1066 |
|
|
static int warnings = 0; |
| 1067 |
|
|
|
| 1068 |
|
|
/* |
| 1069 |
|
|
** if we're running with TS_WARNINGS enabled and someone does |
| 1070 |
|
|
** something silly like (remotely) connecting a nonTS server, |
| 1071 |
|
|
** we'll get a ton of warnings, so we make sure we don't send |
| 1072 |
|
|
** more than 5 every 5 seconds. -orabidoo |
| 1073 |
|
|
*/ |
| 1074 |
|
|
|
| 1075 |
|
|
if (CurrentTime - last < 5) |
| 1076 |
|
|
{ |
| 1077 |
|
|
if (++warnings > 5) |
| 1078 |
|
|
return; |
| 1079 |
|
|
} |
| 1080 |
|
|
else |
| 1081 |
|
|
{ |
| 1082 |
|
|
last = CurrentTime; |
| 1083 |
|
|
warnings = 0; |
| 1084 |
|
|
} |
| 1085 |
|
|
|
| 1086 |
|
|
va_start(args, pattern); |
| 1087 |
|
|
vsprintf_irc(buffer, pattern, args); |
| 1088 |
|
|
va_end(args); |
| 1089 |
|
|
|
| 1090 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, "%s", buffer); |
| 1091 |
|
|
ilog(L_CRIT, "%s", buffer); |
| 1092 |
|
|
} |
| 1093 |
|
|
|
| 1094 |
|
|
/* kill_client() |
| 1095 |
|
|
* |
| 1096 |
|
|
* inputs - client to send kill towards |
| 1097 |
|
|
* - pointer to client to kill |
| 1098 |
|
|
* - reason for kill |
| 1099 |
|
|
* output - NONE |
| 1100 |
|
|
* side effects - NONE |
| 1101 |
|
|
*/ |
| 1102 |
|
|
void |
| 1103 |
|
|
kill_client(struct Client *client_p, struct Client *diedie, |
| 1104 |
|
|
const char *pattern, ...) |
| 1105 |
|
|
{ |
| 1106 |
|
|
va_list args; |
| 1107 |
|
|
char buffer[IRCD_BUFSIZE]; |
| 1108 |
|
|
int len; |
| 1109 |
|
|
|
| 1110 |
|
|
if (client_p->from != NULL) |
| 1111 |
|
|
client_p = client_p->from; |
| 1112 |
|
|
if (IsDead(client_p)) |
| 1113 |
|
|
return; |
| 1114 |
|
|
|
| 1115 |
|
|
len = ircsprintf(buffer, ":%s KILL %s :", ID_or_name(&me, client_p->from), |
| 1116 |
|
|
ID_or_name(diedie, client_p)); |
| 1117 |
|
|
|
| 1118 |
|
|
va_start(args, pattern); |
| 1119 |
|
|
len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args); |
| 1120 |
|
|
va_end(args); |
| 1121 |
|
|
|
| 1122 |
|
|
send_message(client_p, buffer, len); |
| 1123 |
|
|
} |
| 1124 |
|
|
|
| 1125 |
|
|
/* kill_client_ll_serv_butone() |
| 1126 |
|
|
* |
| 1127 |
|
|
* inputs - pointer to client to not send to |
| 1128 |
|
|
* - pointer to client to kill |
| 1129 |
|
|
* output - NONE |
| 1130 |
|
|
* side effects - Send a KILL for the given client |
| 1131 |
|
|
* message to all connected servers |
| 1132 |
|
|
* except the client 'one'. Also deal with |
| 1133 |
|
|
* client being unknown to leaf, as in lazylink... |
| 1134 |
|
|
*/ |
| 1135 |
|
|
void |
| 1136 |
|
|
kill_client_ll_serv_butone(struct Client *one, struct Client *source_p, |
| 1137 |
|
|
const char *pattern, ...) |
| 1138 |
|
|
{ |
| 1139 |
|
|
va_list args; |
| 1140 |
|
|
int have_uid = 0; |
| 1141 |
michael |
885 |
dlink_node *ptr = NULL; |
| 1142 |
adx |
30 |
char buf_uid[IRCD_BUFSIZE], buf_nick[IRCD_BUFSIZE]; |
| 1143 |
michael |
885 |
int len_uid = 0, len_nick = 0; |
| 1144 |
adx |
30 |
|
| 1145 |
|
|
if (HasID(source_p) && (me.id[0] != '\0')) |
| 1146 |
|
|
{ |
| 1147 |
|
|
have_uid = 1; |
| 1148 |
adx |
285 |
va_start(args, pattern); |
| 1149 |
adx |
30 |
len_uid = ircsprintf(buf_uid, ":%s KILL %s :", me.id, ID(source_p)); |
| 1150 |
|
|
len_uid += send_format(&buf_uid[len_uid], IRCD_BUFSIZE - len_uid, pattern, |
| 1151 |
|
|
args); |
| 1152 |
adx |
285 |
va_end(args); |
| 1153 |
adx |
30 |
} |
| 1154 |
adx |
285 |
|
| 1155 |
|
|
va_start(args, pattern); |
| 1156 |
adx |
30 |
len_nick = ircsprintf(buf_nick, ":%s KILL %s :", me.name, source_p->name); |
| 1157 |
|
|
len_nick += send_format(&buf_nick[len_nick], IRCD_BUFSIZE - len_nick, pattern, |
| 1158 |
|
|
args); |
| 1159 |
|
|
va_end(args); |
| 1160 |
|
|
|
| 1161 |
|
|
DLINK_FOREACH(ptr, serv_list.head) |
| 1162 |
|
|
{ |
| 1163 |
michael |
885 |
struct Client *client_p = ptr->data; |
| 1164 |
adx |
30 |
|
| 1165 |
|
|
if (one != NULL && (client_p == one->from)) |
| 1166 |
|
|
continue; |
| 1167 |
|
|
if (IsDefunct(client_p)) |
| 1168 |
|
|
continue; |
| 1169 |
|
|
|
| 1170 |
michael |
885 |
if (have_uid && IsCapable(client_p, CAP_TS6)) |
| 1171 |
|
|
send_message(client_p, buf_uid, len_uid); |
| 1172 |
|
|
else |
| 1173 |
|
|
send_message(client_p, buf_nick, len_nick); |
| 1174 |
adx |
30 |
} |
| 1175 |
|
|
} |