ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/send.c
Revision: 3189
Committed: Fri Mar 21 18:18:00 2014 UTC (12 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 26063 byte(s)
Log Message:
- send.c:sendto_one_numeric(), sendto_one_numeric(): fixed issue where NOTICE and numerics
  were destined to the wrong target nick/ID

File Contents

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

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision