1 |
|
/* |
2 |
|
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
|
* |
4 |
< |
* Copyright (c) 1997-2014 ircd-hybrid development team |
4 |
> |
* Copyright (c) 1997-2015 ircd-hybrid development team |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
15 |
|
* |
16 |
|
* You should have received a copy of the GNU General Public License |
17 |
|
* along with this program; if not, write to the Free Software |
18 |
< |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
18 |
> |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
19 |
|
* USA |
20 |
|
*/ |
21 |
|
|
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 "s_serv.h" |
37 |
< |
#include "conf.h" |
36 |
> |
#include "server.h" |
37 |
> |
#include "conf_class.h" |
38 |
|
#include "log.h" |
41 |
– |
#include "memory.h" |
42 |
– |
#include "packet.h" |
39 |
|
|
40 |
|
|
41 |
< |
static unsigned int current_serial = 0; |
41 |
> |
static uint64_t current_serial; |
42 |
|
|
43 |
|
|
44 |
|
/* send_format() |
67 |
|
*/ |
68 |
|
dbuf_put_args(buffer, pattern, args); |
69 |
|
|
70 |
< |
if (buffer->size > sizeof(buffer->data) - 2) |
71 |
< |
buffer->size = sizeof(buffer->data) - 2; |
70 |
> |
if (buffer->size > IRCD_BUFSIZE - 2) |
71 |
> |
buffer->size = IRCD_BUFSIZE - 2; |
72 |
|
|
73 |
|
buffer->data[buffer->size++] = '\r'; |
74 |
|
buffer->data[buffer->size++] = '\n'; |
84 |
|
{ |
85 |
|
assert(!IsMe(to)); |
86 |
|
assert(to != &me); |
87 |
+ |
assert(MyConnect(to)); |
88 |
|
|
89 |
< |
if (dbuf_length(&to->localClient->buf_sendq) + buf->size > get_sendq(&to->localClient->confs)) |
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->localClient->buf_sendq) + buf->size), |
96 |
< |
get_sendq(&to->localClient->confs)); |
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; |
103 |
|
} |
104 |
|
|
105 |
< |
dbuf_add(&to->localClient->buf_sendq, buf); |
105 |
> |
dbuf_add(&to->connection->buf_sendq, buf); |
106 |
|
|
107 |
|
/* |
108 |
< |
** Update statistics. The following is slightly incorrect |
109 |
< |
** because it counts messages even if queued, but bytes |
110 |
< |
** only really sent. Queued bytes get updated in SendQueued. |
108 |
> |
* Update statistics. The following is slightly incorrect because |
109 |
> |
* it counts messages even if queued, but bytes only really sent. |
110 |
> |
* Queued bytes get updated in send_queued_write(). |
111 |
|
*/ |
112 |
< |
++to->localClient->send.messages; |
113 |
< |
++me.localClient->send.messages; |
112 |
> |
++to->connection->send.messages; |
113 |
> |
++me.connection->send.messages; |
114 |
|
|
115 |
|
send_queued_write(to); |
116 |
|
} |
128 |
|
static void |
129 |
|
send_message_remote(struct Client *to, struct Client *from, struct dbuf_block *buf) |
130 |
|
{ |
131 |
< |
to = to->from; |
131 |
> |
assert(MyConnect(to)); |
132 |
> |
assert(IsServer(to)); |
133 |
> |
assert(!IsMe(to)); |
134 |
> |
assert(to->from == to); |
135 |
|
|
136 |
< |
if (!MyConnect(to)) |
136 |
> |
if (to == from->from) |
137 |
|
{ |
138 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
139 |
< |
"Server send message to %s [%s] dropped from %s(Not local server)", |
140 |
< |
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->name, 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, &me, "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 |
|
|
149 |
|
** Called when a socket is ready for writing. |
150 |
|
*/ |
151 |
|
void |
152 |
< |
sendq_unblocked(fde_t *fd, struct Client *client_p) |
152 |
> |
sendq_unblocked(fde_t *fd, void *data) |
153 |
|
{ |
154 |
< |
assert(fd == &client_p->localClient->fd); |
154 |
> |
struct Client *const client_p = data; |
155 |
> |
assert(fd == &client_p->connection->fd); |
156 |
> |
|
157 |
> |
DelFlag(client_p, FLAGS_BLOCKED); |
158 |
|
send_queued_write(client_p); |
159 |
|
} |
160 |
|
|
173 |
|
** Once socket is marked dead, we cannot start writing to it, |
174 |
|
** even if the error is removed... |
175 |
|
*/ |
176 |
< |
if (IsDead(to)) |
176 |
> |
if (IsDead(to) || HasFlag(to, FLAGS_BLOCKED)) |
177 |
|
return; /* no use calling send() now */ |
178 |
|
|
179 |
|
/* Next, lets try to write some data */ |
180 |
< |
if (dbuf_length(&to->localClient->buf_sendq)) |
180 |
> |
if (dbuf_length(&to->connection->buf_sendq)) |
181 |
|
{ |
182 |
|
do |
183 |
|
{ |
184 |
< |
struct dbuf_block *first = to->localClient->buf_sendq.blocks.head->data; |
184 |
> |
const struct dbuf_block *first = to->connection->buf_sendq.blocks.head->data; |
185 |
|
|
186 |
|
#ifdef HAVE_LIBCRYPTO |
187 |
< |
if (to->localClient->fd.ssl) |
187 |
> |
if (to->connection->fd.ssl) |
188 |
|
{ |
189 |
< |
retlen = SSL_write(to->localClient->fd.ssl, first->data + to->localClient->buf_sendq.pos, first->size - to->localClient->buf_sendq.pos); |
189 |
> |
retlen = SSL_write(to->connection->fd.ssl, first->data + to->connection->buf_sendq.pos, first->size - to->connection->buf_sendq.pos); |
190 |
|
|
191 |
|
/* translate openssl error codes, sigh */ |
192 |
|
if (retlen < 0) |
193 |
|
{ |
194 |
< |
switch (SSL_get_error(to->localClient->fd.ssl, retlen)) |
194 |
> |
switch (SSL_get_error(to->connection->fd.ssl, retlen)) |
195 |
|
{ |
196 |
|
case SSL_ERROR_WANT_READ: |
197 |
|
return; /* retry later, don't register for write events */ |
209 |
|
} |
210 |
|
else |
211 |
|
#endif |
212 |
< |
retlen = send(to->localClient->fd.fd, first->data + to->localClient->buf_sendq.pos, first->size - to->localClient->buf_sendq.pos, 0); |
212 |
> |
retlen = send(to->connection->fd.fd, first->data + to->connection->buf_sendq.pos, first->size - to->connection->buf_sendq.pos, 0); |
213 |
|
|
214 |
|
if (retlen <= 0) |
215 |
|
break; |
216 |
|
|
217 |
< |
dbuf_delete(&to->localClient->buf_sendq, retlen); |
217 |
> |
dbuf_delete(&to->connection->buf_sendq, retlen); |
218 |
|
|
219 |
|
/* We have some data written .. update counters */ |
220 |
< |
to->localClient->send.bytes += retlen; |
221 |
< |
me.localClient->send.bytes += retlen; |
222 |
< |
} while (dbuf_length(&to->localClient->buf_sendq)); |
220 |
> |
to->connection->send.bytes += retlen; |
221 |
> |
me.connection->send.bytes += retlen; |
222 |
> |
} while (dbuf_length(&to->connection->buf_sendq)); |
223 |
|
|
224 |
< |
if ((retlen < 0) && (ignoreErrno(errno))) |
224 |
> |
if (retlen < 0 && ignoreErrno(errno)) |
225 |
|
{ |
226 |
+ |
AddFlag(to, FLAGS_BLOCKED); |
227 |
+ |
|
228 |
|
/* we have a non-fatal error, reschedule a write */ |
229 |
< |
comm_setselect(&to->localClient->fd, COMM_SELECT_WRITE, |
230 |
< |
(PF *)sendq_unblocked, to, 0); |
229 |
> |
comm_setselect(&to->connection->fd, COMM_SELECT_WRITE, |
230 |
> |
sendq_unblocked, to, 0); |
231 |
|
} |
232 |
|
else if (retlen <= 0) |
233 |
|
{ |
246 |
|
void |
247 |
|
send_queued_all(void) |
248 |
|
{ |
249 |
< |
dlink_node *ptr; |
249 |
> |
dlink_node *node = NULL; |
250 |
|
|
251 |
|
/* Servers are processed first, mainly because this can generate |
252 |
|
* a notice to opers, which is to be delivered by this function. |
253 |
|
*/ |
254 |
< |
DLINK_FOREACH(ptr, serv_list.head) |
255 |
< |
send_queued_write(ptr->data); |
254 |
> |
DLINK_FOREACH(node, local_server_list.head) |
255 |
> |
send_queued_write(node->data); |
256 |
|
|
257 |
< |
DLINK_FOREACH(ptr, unknown_list.head) |
258 |
< |
send_queued_write(ptr->data); |
257 |
> |
DLINK_FOREACH(node, unknown_list.head) |
258 |
> |
send_queued_write(node->data); |
259 |
|
|
260 |
< |
DLINK_FOREACH(ptr, local_client_list.head) |
261 |
< |
send_queued_write(ptr->data); |
260 |
> |
DLINK_FOREACH(node, local_client_list.head) |
261 |
> |
send_queued_write(node->data); |
262 |
|
|
263 |
|
/* NOTE: This can still put clients on aborted_list; unfortunately, |
264 |
|
* exit_aborted_clients takes precedence over send_queued_all, |
279 |
|
sendto_one(struct Client *to, const char *pattern, ...) |
280 |
|
{ |
281 |
|
va_list args; |
282 |
< |
struct dbuf_block *buffer; |
310 |
< |
|
311 |
< |
to = to->from; |
282 |
> |
struct dbuf_block *buffer = NULL; |
283 |
|
|
284 |
< |
if (IsDead(to)) |
284 |
> |
if (IsDead(to->from)) |
285 |
|
return; /* This socket has already been marked as dead */ |
286 |
|
|
287 |
|
buffer = dbuf_alloc(); |
290 |
|
send_format(buffer, pattern, args); |
291 |
|
va_end(args); |
292 |
|
|
293 |
< |
send_message(to, buffer); |
293 |
> |
send_message(to->from, buffer); |
294 |
|
|
295 |
|
dbuf_ref_free(buffer); |
296 |
|
} |
298 |
|
void |
299 |
|
sendto_one_numeric(struct Client *to, struct Client *from, enum irc_numerics numeric, ...) |
300 |
|
{ |
301 |
< |
struct dbuf_block *buffer; |
301 |
> |
struct dbuf_block *buffer = NULL; |
302 |
> |
const char *dest = NULL, *numstr = NULL; |
303 |
|
va_list args; |
332 |
– |
const char *dest; |
333 |
– |
|
334 |
– |
to = to->from; |
304 |
|
|
305 |
< |
if (IsDead(to)) |
305 |
> |
if (IsDead(to->from)) |
306 |
|
return; |
307 |
|
|
308 |
|
dest = ID_or_name(to, to); |
309 |
+ |
|
310 |
|
if (EmptyString(dest)) |
311 |
|
dest = "*"; |
312 |
|
|
313 |
|
buffer = dbuf_alloc(); |
314 |
|
|
315 |
< |
dbuf_put_fmt(buffer, ":%s %03d %s ", ID_or_name(from, to), numeric, dest); |
315 |
> |
dbuf_put_fmt(buffer, ":%s %03d %s ", ID_or_name(from, to), numeric & ~SND_EXPLICIT, dest); |
316 |
|
|
317 |
|
va_start(args, numeric); |
318 |
< |
send_format(buffer, numeric_form(numeric), args); |
318 |
> |
|
319 |
> |
if (numeric & SND_EXPLICIT) |
320 |
> |
numstr = va_arg(args, const char *); |
321 |
> |
else |
322 |
> |
numstr = numeric_form(numeric); |
323 |
> |
|
324 |
> |
send_format(buffer, numstr, args); |
325 |
|
va_end(args); |
326 |
|
|
327 |
< |
send_message(to, buffer); |
327 |
> |
send_message(to->from, buffer); |
328 |
|
|
329 |
|
dbuf_ref_free(buffer); |
330 |
|
} |
332 |
|
void |
333 |
|
sendto_one_notice(struct Client *to, struct Client *from, const char *pattern, ...) |
334 |
|
{ |
335 |
< |
struct dbuf_block *buffer; |
335 |
> |
struct dbuf_block *buffer = NULL; |
336 |
> |
const char *dest = NULL; |
337 |
|
va_list args; |
361 |
– |
const char *dest; |
362 |
– |
|
363 |
– |
to = to->from; |
338 |
|
|
339 |
< |
if (IsDead(to)) |
339 |
> |
if (IsDead(to->from)) |
340 |
|
return; |
341 |
|
|
342 |
|
dest = ID_or_name(to, to); |
343 |
+ |
|
344 |
|
if (EmptyString(dest)) |
345 |
|
dest = "*"; |
346 |
|
|
352 |
|
send_format(buffer, pattern, args); |
353 |
|
va_end(args); |
354 |
|
|
355 |
< |
send_message(to, buffer); |
355 |
> |
send_message(to->from, buffer); |
356 |
|
|
357 |
|
dbuf_ref_free(buffer); |
358 |
|
} |
375 |
|
{ |
376 |
|
va_list alocal, aremote; |
377 |
|
struct dbuf_block *local_buf, *remote_buf; |
378 |
< |
dlink_node *ptr = NULL, *ptr_next = NULL; |
378 |
> |
dlink_node *node = NULL; |
379 |
|
|
380 |
|
local_buf = dbuf_alloc(), remote_buf = dbuf_alloc(); |
381 |
|
|
382 |
< |
if (IsServer(from)) |
408 |
< |
dbuf_put_fmt(local_buf, ":%s ", from->name); |
409 |
< |
else |
382 |
> |
if (IsClient(from)) |
383 |
|
dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host); |
384 |
+ |
else |
385 |
+ |
dbuf_put_fmt(local_buf, ":%s ", from->name); |
386 |
|
|
387 |
< |
dbuf_put_fmt(remote_buf, ":%s ", ID(from)); |
387 |
> |
dbuf_put_fmt(remote_buf, ":%s ", from->id); |
388 |
|
|
389 |
|
va_start(alocal, pattern); |
390 |
|
va_start(aremote, pattern); |
396 |
|
|
397 |
|
++current_serial; |
398 |
|
|
399 |
< |
DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->members.head) |
399 |
> |
DLINK_FOREACH(node, chptr->members.head) |
400 |
|
{ |
401 |
< |
struct Membership *ms = ptr->data; |
402 |
< |
struct Client *target_p = ms->client_p; |
401 |
> |
struct Membership *member = node->data; |
402 |
> |
struct Client *target_p = member->client_p; |
403 |
|
|
404 |
|
assert(IsClient(target_p)); |
405 |
|
|
407 |
|
(one && target_p->from == one->from)) |
408 |
|
continue; |
409 |
|
|
410 |
< |
if (type != 0 && (ms->flags & type) == 0) |
410 |
> |
if (type && (member->flags & type) == 0) |
411 |
|
continue; |
412 |
|
|
413 |
|
if (MyConnect(target_p)) |
414 |
|
send_message(target_p, local_buf); |
415 |
< |
else if (target_p->from->localClient->serial != current_serial) |
415 |
> |
else if (target_p->from->connection->serial != current_serial) |
416 |
|
send_message_remote(target_p->from, from, remote_buf); |
417 |
< |
target_p->from->localClient->serial = current_serial; |
417 |
> |
|
418 |
> |
target_p->from->connection->serial = current_serial; |
419 |
|
} |
420 |
|
|
421 |
|
dbuf_ref_free(local_buf); |
447 |
|
const char *format, ...) |
448 |
|
{ |
449 |
|
va_list args; |
450 |
< |
dlink_node *ptr = NULL; |
451 |
< |
struct dbuf_block *buffer; |
476 |
< |
|
477 |
< |
buffer = dbuf_alloc(); |
450 |
> |
dlink_node *node = NULL; |
451 |
> |
struct dbuf_block *buffer = dbuf_alloc(); |
452 |
|
|
453 |
|
va_start(args, format); |
454 |
|
send_format(buffer, format, args); |
455 |
|
va_end(args); |
456 |
|
|
457 |
< |
DLINK_FOREACH(ptr, serv_list.head) |
457 |
> |
DLINK_FOREACH(node, local_server_list.head) |
458 |
|
{ |
459 |
< |
struct Client *client_p = ptr->data; |
459 |
> |
struct Client *client_p = node->data; |
460 |
|
|
461 |
|
/* If dead already skip */ |
462 |
|
if (IsDead(client_p)) |
463 |
|
continue; |
464 |
+ |
|
465 |
|
/* check against 'one' */ |
466 |
< |
if (one != NULL && (client_p == one->from)) |
466 |
> |
if (one && (client_p == one->from)) |
467 |
|
continue; |
468 |
+ |
|
469 |
|
/* check we have required capabs */ |
470 |
< |
if ((client_p->localClient->caps & caps) != caps) |
470 |
> |
if ((client_p->connection->caps & caps) != caps) |
471 |
|
continue; |
472 |
+ |
|
473 |
|
/* check we don't have any forbidden capabs */ |
474 |
< |
if ((client_p->localClient->caps & nocaps) != 0) |
474 |
> |
if ((client_p->connection->caps & nocaps)) |
475 |
|
continue; |
476 |
|
|
477 |
|
send_message(client_p, buffer); |
490 |
|
* used by m_nick.c and exit_one_client. |
491 |
|
*/ |
492 |
|
void |
493 |
< |
sendto_common_channels_local(struct Client *user, int touser, unsigned int cap, |
494 |
< |
const char *pattern, ...) |
493 |
> |
sendto_common_channels_local(struct Client *user, int touser, unsigned int poscap, |
494 |
> |
unsigned int negcap, const char *pattern, ...) |
495 |
|
{ |
496 |
|
va_list args; |
497 |
|
dlink_node *uptr; |
498 |
|
dlink_node *cptr; |
499 |
|
struct Channel *chptr; |
500 |
< |
struct Membership *ms; |
500 |
> |
struct Membership *member; |
501 |
|
struct Client *target_p; |
502 |
< |
struct dbuf_block *buffer; |
526 |
< |
|
527 |
< |
buffer = dbuf_alloc(); |
502 |
> |
struct dbuf_block *buffer = dbuf_alloc(); |
503 |
|
|
504 |
|
va_start(args, pattern); |
505 |
|
send_format(buffer, pattern, args); |
510 |
|
DLINK_FOREACH(cptr, user->channel.head) |
511 |
|
{ |
512 |
|
chptr = ((struct Membership *)cptr->data)->chptr; |
538 |
– |
assert(chptr != NULL); |
513 |
|
|
514 |
< |
DLINK_FOREACH(uptr, chptr->members.head) |
514 |
> |
DLINK_FOREACH(uptr, chptr->locmembers.head) |
515 |
|
{ |
516 |
< |
ms = uptr->data; |
517 |
< |
target_p = ms->client_p; |
518 |
< |
assert(target_p != NULL); |
516 |
> |
member = uptr->data; |
517 |
> |
target_p = member->client_p; |
518 |
> |
|
519 |
> |
if (target_p == user || IsDefunct(target_p) || |
520 |
> |
target_p->connection->serial == current_serial) |
521 |
> |
continue; |
522 |
|
|
523 |
< |
if (!MyConnect(target_p) || target_p == user || IsDefunct(target_p) || |
547 |
< |
target_p->localClient->serial == current_serial) |
523 |
> |
if (poscap && HasCap(target_p, poscap) != poscap) |
524 |
|
continue; |
525 |
|
|
526 |
< |
if (HasCap(target_p, cap) != cap) |
526 |
> |
if (negcap && HasCap(target_p, negcap)) |
527 |
|
continue; |
528 |
|
|
529 |
< |
target_p->localClient->serial = current_serial; |
529 |
> |
target_p->connection->serial = current_serial; |
530 |
|
send_message(target_p, buffer); |
531 |
|
} |
532 |
|
} |
533 |
|
|
534 |
|
if (touser && MyConnect(user) && !IsDead(user) && |
535 |
< |
user->localClient->serial != current_serial) |
536 |
< |
if (HasCap(user, cap) == cap) |
535 |
> |
user->connection->serial != current_serial) |
536 |
> |
if (HasCap(user, poscap) == poscap) |
537 |
|
send_message(user, buffer); |
538 |
|
|
539 |
|
dbuf_ref_free(buffer); |
540 |
|
} |
541 |
|
|
542 |
< |
/* sendto_channel_local() |
543 |
< |
* |
544 |
< |
* inputs - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE |
545 |
< |
* - whether to ignore +D clients (YES/NO) |
546 |
< |
* - pointer to channel to send to |
547 |
< |
* - var args pattern |
548 |
< |
* output - NONE |
573 |
< |
* side effects - Send a message to all members of a channel that are |
574 |
< |
* locally connected to this server. |
542 |
> |
/*! \brief Send a message to members of a channel that are locally connected to this server. |
543 |
> |
* \param one Client to skip; can be NULL |
544 |
> |
* \param chptr Destination channel |
545 |
> |
* \param status Channel member status flags clients must have |
546 |
> |
* \param poscap Positive client capabilities flags (CAP) |
547 |
> |
* \param negcap Negative client capabilities flags (CAP) |
548 |
> |
* \param pattern Format string for command arguments |
549 |
|
*/ |
550 |
|
void |
551 |
< |
sendto_channel_local(unsigned int type, int nodeaf, struct Channel *chptr, |
552 |
< |
const char *pattern, ...) |
551 |
> |
sendto_channel_local(const struct Client *one, struct Channel *chptr, unsigned int status, |
552 |
> |
unsigned int poscap, unsigned int negcap, const char *pattern, ...) |
553 |
|
{ |
554 |
|
va_list args; |
555 |
< |
dlink_node *ptr = NULL; |
556 |
< |
struct dbuf_block *buffer; |
583 |
< |
|
584 |
< |
buffer = dbuf_alloc(); |
555 |
> |
dlink_node *node = NULL; |
556 |
> |
struct dbuf_block *buffer = dbuf_alloc(); |
557 |
|
|
558 |
|
va_start(args, pattern); |
559 |
|
send_format(buffer, pattern, args); |
560 |
|
va_end(args); |
561 |
|
|
562 |
< |
DLINK_FOREACH(ptr, chptr->members.head) |
562 |
> |
DLINK_FOREACH(node, chptr->locmembers.head) |
563 |
|
{ |
564 |
< |
struct Membership *ms = ptr->data; |
565 |
< |
struct Client *target_p = ms->client_p; |
564 |
> |
struct Membership *member = node->data; |
565 |
> |
struct Client *target_p = member->client_p; |
566 |
|
|
567 |
< |
if (type != 0 && (ms->flags & type) == 0) |
567 |
> |
if (IsDefunct(target_p)) |
568 |
|
continue; |
569 |
|
|
570 |
< |
if (!MyConnect(target_p) || IsDefunct(target_p) || |
599 |
< |
(nodeaf && HasUMode(target_p, UMODE_DEAF))) |
600 |
< |
continue; |
601 |
< |
|
602 |
< |
send_message(target_p, buffer); |
603 |
< |
} |
604 |
< |
|
605 |
< |
dbuf_ref_free(buffer); |
606 |
< |
} |
607 |
< |
|
608 |
< |
/* sendto_channel_local_butone() |
609 |
< |
* |
610 |
< |
* inputs - pointer to client to NOT send message to |
611 |
< |
* - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE |
612 |
< |
* - pointer to channel to send to |
613 |
< |
* - var args pattern |
614 |
< |
* output - NONE |
615 |
< |
* side effects - Send a message to all members of a channel that are |
616 |
< |
* locally connected to this server except one. |
617 |
< |
* |
618 |
< |
* WARNING - +D clients are omitted |
619 |
< |
*/ |
620 |
< |
void |
621 |
< |
sendto_channel_local_butone(struct Client *one, unsigned int type, unsigned int cap, |
622 |
< |
struct Channel *chptr, const char *pattern, ...) |
623 |
< |
{ |
624 |
< |
va_list args; |
625 |
< |
dlink_node *ptr = NULL; |
626 |
< |
struct dbuf_block *buffer; |
627 |
< |
|
628 |
< |
buffer = dbuf_alloc(); |
629 |
< |
|
630 |
< |
va_start(args, pattern); |
631 |
< |
send_format(buffer, pattern, args); |
632 |
< |
va_end(args); |
633 |
< |
|
634 |
< |
DLINK_FOREACH(ptr, chptr->members.head) |
635 |
< |
{ |
636 |
< |
struct Membership *ms = ptr->data; |
637 |
< |
struct Client *target_p = ms->client_p; |
638 |
< |
|
639 |
< |
if (type != 0 && (ms->flags & type) == 0) |
570 |
> |
if (one && target_p == one->from) |
571 |
|
continue; |
572 |
|
|
573 |
< |
if (!MyConnect(target_p) || (one && target_p == one->from)) |
573 |
> |
if (status && (member->flags & status) == 0) |
574 |
|
continue; |
575 |
|
|
576 |
< |
if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF)) |
576 |
> |
if (poscap && HasCap(target_p, poscap) != poscap) |
577 |
|
continue; |
578 |
|
|
579 |
< |
if (HasCap(target_p, cap) != cap) |
579 |
> |
if (negcap && HasCap(target_p, negcap)) |
580 |
|
continue; |
581 |
|
|
582 |
|
send_message(target_p, buffer); |
623 |
|
int what, const char *pattern, ...) |
624 |
|
{ |
625 |
|
va_list alocal, aremote; |
626 |
< |
dlink_node *ptr = NULL, *ptr_next = NULL; |
626 |
> |
dlink_node *node = NULL; |
627 |
|
struct dbuf_block *local_buf, *remote_buf; |
628 |
|
|
629 |
|
local_buf = dbuf_alloc(), remote_buf = dbuf_alloc(); |
630 |
|
|
631 |
|
dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host); |
632 |
< |
dbuf_put_fmt(remote_buf, ":%s ", ID(from)); |
632 |
> |
dbuf_put_fmt(remote_buf, ":%s ", from->id); |
633 |
|
|
634 |
|
va_start(alocal, pattern); |
635 |
|
va_start(aremote, pattern); |
639 |
|
va_end(alocal); |
640 |
|
|
641 |
|
/* scan the local clients */ |
642 |
< |
DLINK_FOREACH(ptr, local_client_list.head) |
642 |
> |
DLINK_FOREACH(node, local_client_list.head) |
643 |
|
{ |
644 |
< |
struct Client *client_p = ptr->data; |
644 |
> |
struct Client *client_p = node->data; |
645 |
|
|
646 |
< |
if ((!one || client_p != one->from)&& !IsDefunct(client_p) && |
646 |
> |
if ((!one || client_p != one->from) && !IsDefunct(client_p) && |
647 |
|
match_it(client_p, mask, what)) |
648 |
|
send_message(client_p, local_buf); |
649 |
|
} |
650 |
|
|
651 |
|
/* Now scan servers */ |
652 |
< |
DLINK_FOREACH_SAFE(ptr, ptr_next, serv_list.head) |
652 |
> |
DLINK_FOREACH(node, local_server_list.head) |
653 |
|
{ |
654 |
< |
struct Client *client_p = ptr->data; |
654 |
> |
struct Client *client_p = node->data; |
655 |
|
|
656 |
|
/* |
657 |
|
* The old code looped through every client on the |
699 |
|
const char *pattern, ...) |
700 |
|
{ |
701 |
|
va_list args; |
702 |
< |
dlink_node *ptr = NULL; |
703 |
< |
struct dbuf_block *buff_suid; |
773 |
< |
|
774 |
< |
buff_suid = dbuf_alloc(); |
702 |
> |
dlink_node *node = NULL; |
703 |
> |
struct dbuf_block *buffer = dbuf_alloc(); |
704 |
|
|
705 |
+ |
dbuf_put_fmt(buffer, ":%s ", source_p->id); |
706 |
|
va_start(args, pattern); |
707 |
< |
dbuf_put_fmt(buff_suid, ":%s ", ID(source_p)); |
778 |
< |
dbuf_put_args(buff_suid, pattern, args); |
707 |
> |
send_format(buffer, pattern, args); |
708 |
|
va_end(args); |
709 |
|
|
710 |
|
++current_serial; |
711 |
|
|
712 |
< |
DLINK_FOREACH(ptr, global_serv_list.head) |
712 |
> |
DLINK_FOREACH(node, global_server_list.head) |
713 |
|
{ |
714 |
< |
struct Client *target_p = ptr->data; |
714 |
> |
struct Client *target_p = node->data; |
715 |
|
|
716 |
|
/* Do not attempt to send to ourselves, or the source */ |
717 |
|
if (IsMe(target_p) || target_p->from == source_p->from) |
718 |
|
continue; |
719 |
|
|
720 |
< |
if (target_p->from->localClient->serial == current_serial) |
720 |
> |
if (target_p->from->connection->serial == current_serial) |
721 |
|
continue; |
722 |
|
|
723 |
< |
if (!match(mask, target_p->name)) |
724 |
< |
{ |
796 |
< |
/* |
797 |
< |
* if we set the serial here, then we'll never do a |
798 |
< |
* match() again, if !IsCapable() |
799 |
< |
*/ |
800 |
< |
target_p->from->localClient->serial = current_serial; |
723 |
> |
if (match(mask, target_p->name)) |
724 |
> |
continue; |
725 |
|
|
726 |
< |
if (!IsCapable(target_p->from, cap)) |
727 |
< |
continue; |
726 |
> |
/* |
727 |
> |
* If we set the serial here, then we'll never do a |
728 |
> |
* match() again, if !IsCapable() |
729 |
> |
*/ |
730 |
> |
target_p->from->connection->serial = current_serial; |
731 |
|
|
732 |
< |
send_message_remote(target_p->from, source_p, buff_suid); |
733 |
< |
} |
732 |
> |
if (!IsCapable(target_p->from, cap)) |
733 |
> |
continue; |
734 |
> |
|
735 |
> |
send_message_remote(target_p->from, source_p, buffer); |
736 |
|
} |
737 |
|
|
738 |
< |
dbuf_ref_free(buff_suid); |
738 |
> |
dbuf_ref_free(buffer); |
739 |
|
} |
740 |
|
|
741 |
|
/* sendto_anywhere() |
753 |
|
const char *pattern, ...) |
754 |
|
{ |
755 |
|
va_list args; |
756 |
< |
struct dbuf_block *buffer; |
756 |
> |
struct dbuf_block *buffer = NULL; |
757 |
|
|
758 |
|
if (IsDead(to->from)) |
759 |
|
return; |
760 |
|
|
761 |
|
buffer = dbuf_alloc(); |
762 |
|
|
763 |
< |
if (MyClient(to)) |
764 |
< |
{ |
765 |
< |
if (IsServer(from)) |
837 |
< |
dbuf_put_fmt(buffer, ":%s %s %s ", from->name, command, to->name); |
838 |
< |
else |
839 |
< |
dbuf_put_fmt(buffer, ":%s!%s@%s %s %s ", from->name, from->username, from->host, command, to->name); |
840 |
< |
} |
763 |
> |
if (MyClient(to) && IsClient(from)) |
764 |
> |
dbuf_put_fmt(buffer, ":%s!%s@%s %s %s ", from->name, from->username, |
765 |
> |
from->host, command, to->name); |
766 |
|
else |
767 |
< |
dbuf_put_fmt(buffer, ":%s %s %s ", ID_or_name(from, to), command, ID_or_name(to, to)); |
767 |
> |
dbuf_put_fmt(buffer, ":%s %s %s ", ID_or_name(from, to), |
768 |
> |
command, ID_or_name(to, to)); |
769 |
|
|
770 |
|
va_start(args, pattern); |
771 |
|
send_format(buffer, pattern, args); |
772 |
|
va_end(args); |
773 |
|
|
774 |
< |
if (MyClient(to)) |
774 |
> |
if (MyConnect(to)) |
775 |
|
send_message(to, buffer); |
776 |
|
else |
777 |
< |
send_message_remote(to, from, buffer); |
777 |
> |
send_message_remote(to->from, from, buffer); |
778 |
|
|
779 |
|
dbuf_ref_free(buffer); |
780 |
|
} |
791 |
|
sendto_realops_flags(unsigned int flags, int level, int type, const char *pattern, ...) |
792 |
|
{ |
793 |
|
const char *ntype = NULL; |
794 |
< |
dlink_node *ptr = NULL; |
795 |
< |
char nbuf[IRCD_BUFSIZE]; |
794 |
> |
dlink_node *node = NULL; |
795 |
> |
char nbuf[IRCD_BUFSIZE] = ""; |
796 |
|
va_list args; |
797 |
|
|
798 |
|
va_start(args, pattern); |
814 |
|
assert(0); |
815 |
|
} |
816 |
|
|
817 |
< |
DLINK_FOREACH(ptr, oper_list.head) |
817 |
> |
DLINK_FOREACH(node, oper_list.head) |
818 |
|
{ |
819 |
< |
struct Client *client_p = ptr->data; |
819 |
> |
struct Client *client_p = node->data; |
820 |
|
assert(HasUMode(client_p, UMODE_OPER)); |
821 |
|
|
822 |
|
/* |
833 |
|
} |
834 |
|
} |
835 |
|
|
910 |
– |
/* sendto_wallops_flags() |
911 |
– |
* |
912 |
– |
* inputs - flag types of messages to show to real opers |
913 |
– |
* - client sending request |
914 |
– |
* - var args input message |
915 |
– |
* output - NONE |
916 |
– |
* side effects - Send a wallops to local opers |
917 |
– |
*/ |
918 |
– |
void |
919 |
– |
sendto_wallops_flags(unsigned int flags, struct Client *source_p, |
920 |
– |
const char *pattern, ...) |
921 |
– |
{ |
922 |
– |
dlink_node *ptr = NULL; |
923 |
– |
va_list args; |
924 |
– |
struct dbuf_block *buffer; |
925 |
– |
|
926 |
– |
buffer = dbuf_alloc(); |
927 |
– |
|
928 |
– |
if (IsClient(source_p)) |
929 |
– |
dbuf_put_fmt(buffer, ":%s!%s@%s WALLOPS :", source_p->name, source_p->username, source_p->host); |
930 |
– |
else |
931 |
– |
dbuf_put_fmt(buffer, ":%s WALLOPS :", source_p->name); |
932 |
– |
|
933 |
– |
va_start(args, pattern); |
934 |
– |
send_format(buffer, pattern, args); |
935 |
– |
va_end(args); |
936 |
– |
|
937 |
– |
DLINK_FOREACH(ptr, oper_list.head) |
938 |
– |
{ |
939 |
– |
struct Client *client_p = ptr->data; |
940 |
– |
assert(client_p->umodes & UMODE_OPER); |
941 |
– |
|
942 |
– |
if (HasUMode(client_p, flags) && !IsDefunct(client_p)) |
943 |
– |
send_message(client_p, buffer); |
944 |
– |
} |
945 |
– |
|
946 |
– |
dbuf_ref_free(buffer); |
947 |
– |
} |
948 |
– |
|
836 |
|
/* ts_warn() |
837 |
|
* |
838 |
< |
* inputs - var args message |
839 |
< |
* output - NONE |
840 |
< |
* side effects - Call sendto_realops_flags, with some flood checking |
841 |
< |
* (at most 5 warnings every 5 seconds) |
838 |
> |
* inputs - var args message |
839 |
> |
* output - NONE |
840 |
> |
* side effects - Call sendto_realops_flags, with some flood checking |
841 |
> |
* (at most 5 warnings every 5 seconds) |
842 |
|
*/ |
843 |
|
void |
844 |
< |
sendto_realops_flags_ratelimited(const char *pattern, ...) |
844 |
> |
sendto_realops_flags_ratelimited(time_t *rate, const char *pattern, ...) |
845 |
|
{ |
846 |
|
va_list args; |
847 |
< |
char buffer[IRCD_BUFSIZE]; |
961 |
< |
static time_t last = 0; |
962 |
< |
static int warnings = 0; |
847 |
> |
char buffer[IRCD_BUFSIZE] = ""; |
848 |
|
|
849 |
< |
/* |
850 |
< |
** if we're running with TS_WARNINGS enabled and someone does |
966 |
< |
** something silly like (remotely) connecting a nonTS server, |
967 |
< |
** we'll get a ton of warnings, so we make sure we don't send |
968 |
< |
** more than 5 every 5 seconds. -orabidoo |
969 |
< |
*/ |
849 |
> |
if ((CurrentTime - *rate) < 20) |
850 |
> |
return; |
851 |
|
|
852 |
< |
if (CurrentTime - last < 5) |
972 |
< |
{ |
973 |
< |
if (++warnings > 5) |
974 |
< |
return; |
975 |
< |
} |
976 |
< |
else |
977 |
< |
{ |
978 |
< |
last = CurrentTime; |
979 |
< |
warnings = 0; |
980 |
< |
} |
852 |
> |
*rate = CurrentTime; |
853 |
|
|
854 |
|
va_start(args, pattern); |
855 |
|
vsnprintf(buffer, sizeof(buffer), pattern, args); |
856 |
|
va_end(args); |
857 |
|
|
858 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, "%s", buffer); |
858 |
> |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, "%s", buffer); |
859 |
|
ilog(LOG_TYPE_IRCD, "%s", buffer); |
860 |
|
} |
861 |
|
|
862 |
< |
/* kill_client() |
862 |
> |
/* sendto_wallops_flags() |
863 |
|
* |
864 |
< |
* inputs - client to send kill towards |
865 |
< |
* - pointer to client to kill |
866 |
< |
* - reason for kill |
867 |
< |
* output - NONE |
868 |
< |
* side effects - NONE |
864 |
> |
* inputs - flag types of messages to show to real opers |
865 |
> |
* - client sending request |
866 |
> |
* - var args input message |
867 |
> |
* output - NONE |
868 |
> |
* side effects - Send a wallops to local opers |
869 |
|
*/ |
870 |
|
void |
871 |
< |
kill_client(struct Client *client_p, struct Client *diedie, |
872 |
< |
const char *pattern, ...) |
871 |
> |
sendto_wallops_flags(unsigned int flags, struct Client *source_p, |
872 |
> |
const char *pattern, ...) |
873 |
|
{ |
874 |
+ |
dlink_node *node = NULL; |
875 |
|
va_list args; |
876 |
< |
struct dbuf_block *buffer; |
1004 |
< |
|
1005 |
< |
client_p = client_p->from; |
1006 |
< |
|
1007 |
< |
if (IsDead(client_p)) |
1008 |
< |
return; |
1009 |
< |
|
1010 |
< |
buffer = dbuf_alloc(); |
876 |
> |
struct dbuf_block *buffer = dbuf_alloc(); |
877 |
|
|
878 |
< |
dbuf_put_fmt(buffer, ":%s KILL %s :", |
879 |
< |
ID_or_name(&me, client_p), |
880 |
< |
ID_or_name(diedie, client_p)); |
878 |
> |
if (IsClient(source_p)) |
879 |
> |
dbuf_put_fmt(buffer, ":%s!%s@%s WALLOPS :", source_p->name, source_p->username, source_p->host); |
880 |
> |
else |
881 |
> |
dbuf_put_fmt(buffer, ":%s WALLOPS :", source_p->name); |
882 |
|
|
883 |
|
va_start(args, pattern); |
884 |
|
send_format(buffer, pattern, args); |
885 |
|
va_end(args); |
886 |
|
|
887 |
< |
send_message(client_p, buffer); |
1021 |
< |
|
1022 |
< |
dbuf_ref_free(buffer); |
1023 |
< |
} |
1024 |
< |
|
1025 |
< |
/* kill_client_serv_butone() |
1026 |
< |
* |
1027 |
< |
* inputs - pointer to client to not send to |
1028 |
< |
* - pointer to client to kill |
1029 |
< |
* output - NONE |
1030 |
< |
* side effects - Send a KILL for the given client |
1031 |
< |
* message to all connected servers |
1032 |
< |
* except the client 'one'. Also deal with |
1033 |
< |
* client being unknown to leaf, as in lazylink... |
1034 |
< |
*/ |
1035 |
< |
void |
1036 |
< |
kill_client_serv_butone(struct Client *one, struct Client *source_p, |
1037 |
< |
const char *pattern, ...) |
1038 |
< |
{ |
1039 |
< |
va_list args; |
1040 |
< |
dlink_node *ptr = NULL; |
1041 |
< |
struct dbuf_block *uid_buffer = dbuf_alloc(); |
1042 |
< |
|
1043 |
< |
va_start(args, pattern); |
1044 |
< |
dbuf_put_fmt(uid_buffer, ":%s KILL %s :", ID(&me), ID(source_p)); |
1045 |
< |
send_format(uid_buffer, pattern, args); |
1046 |
< |
va_end(args); |
1047 |
< |
|
1048 |
< |
DLINK_FOREACH(ptr, serv_list.head) |
887 |
> |
DLINK_FOREACH(node, oper_list.head) |
888 |
|
{ |
889 |
< |
struct Client *client_p = ptr->data; |
890 |
< |
|
1052 |
< |
if (one != NULL && (client_p == one->from)) |
1053 |
< |
continue; |
1054 |
< |
if (IsDefunct(client_p)) |
1055 |
< |
continue; |
889 |
> |
struct Client *client_p = node->data; |
890 |
> |
assert(client_p->umodes & UMODE_OPER); |
891 |
|
|
892 |
< |
send_message(client_p, uid_buffer); |
892 |
> |
if (HasUMode(client_p, flags) && !IsDefunct(client_p)) |
893 |
> |
send_message(client_p, buffer); |
894 |
|
} |
895 |
|
|
896 |
< |
dbuf_ref_free(uid_buffer); |
896 |
> |
dbuf_ref_free(buffer); |
897 |
|
} |