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-2018 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_capab.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 uintmax_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", |
94 |
< |
get_client_name(to, HIDE_IP), |
95 |
< |
(unsigned long)(dbuf_length(&to->localClient->buf_sendq) + buf->size), |
96 |
< |
get_sendq(&to->localClient->confs)); |
92 |
> |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
93 |
> |
"Max SendQ limit exceeded for %s: %zu > %u", |
94 |
> |
client_get_name(to, HIDE_IP), |
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 |
|
} |
126 |
|
* |
127 |
|
*/ |
128 |
|
static void |
129 |
< |
send_message_remote(struct Client *to, struct Client *from, struct dbuf_block *buf) |
129 |
> |
send_message_remote(struct Client *to, const struct Client *from, struct dbuf_block *buf) |
130 |
|
{ |
131 |
< |
to = to->from; |
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->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"); |
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 *F, void *data) |
153 |
|
{ |
154 |
< |
assert(fd == &client_p->localClient->fd); |
154 |
> |
struct Client *const client_p = data; |
155 |
> |
|
156 |
> |
assert(client_p); |
157 |
> |
assert(client_p->connection); |
158 |
> |
assert(client_p->connection->fd); |
159 |
> |
assert(client_p->connection->fd == F); |
160 |
> |
|
161 |
> |
DelFlag(client_p, FLAGS_BLOCKED); |
162 |
|
send_queued_write(client_p); |
163 |
|
} |
164 |
|
|
177 |
|
** Once socket is marked dead, we cannot start writing to it, |
178 |
|
** even if the error is removed... |
179 |
|
*/ |
180 |
< |
if (IsDead(to)) |
180 |
> |
if (IsDead(to) || HasFlag(to, FLAGS_BLOCKED)) |
181 |
|
return; /* no use calling send() now */ |
182 |
|
|
183 |
|
/* Next, lets try to write some data */ |
184 |
< |
if (dbuf_length(&to->localClient->buf_sendq)) |
184 |
> |
if (dbuf_length(&to->connection->buf_sendq)) |
185 |
|
{ |
186 |
|
do |
187 |
|
{ |
188 |
< |
struct dbuf_block *first = to->localClient->buf_sendq.blocks.head->data; |
188 |
> |
int want_read = 0; |
189 |
> |
const struct dbuf_block *first = to->connection->buf_sendq.blocks.head->data; |
190 |
|
|
191 |
< |
#ifdef HAVE_LIBCRYPTO |
216 |
< |
if (to->localClient->fd.ssl) |
191 |
> |
if (tls_isusing(&to->connection->fd->ssl)) |
192 |
|
{ |
193 |
< |
retlen = SSL_write(to->localClient->fd.ssl, first->data + to->localClient->buf_sendq.pos, first->size - to->localClient->buf_sendq.pos); |
193 |
> |
retlen = tls_write(&to->connection->fd->ssl, first->data + to->connection->buf_sendq.pos, |
194 |
> |
first->size - to->connection->buf_sendq.pos, &want_read); |
195 |
|
|
196 |
< |
/* translate openssl error codes, sigh */ |
197 |
< |
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 |
< |
} |
196 |
> |
if (want_read) |
197 |
> |
return; /* Retry later, don't register for write events */ |
198 |
|
} |
199 |
|
else |
200 |
< |
#endif |
201 |
< |
retlen = send(to->localClient->fd.fd, first->data + to->localClient->buf_sendq.pos, first->size - to->localClient->buf_sendq.pos, 0); |
200 |
> |
retlen = send(to->connection->fd->fd, first->data + to->connection->buf_sendq.pos, |
201 |
> |
first->size - to->connection->buf_sendq.pos, 0); |
202 |
|
|
203 |
|
if (retlen <= 0) |
204 |
|
break; |
205 |
|
|
206 |
< |
dbuf_delete(&to->localClient->buf_sendq, retlen); |
206 |
> |
dbuf_delete(&to->connection->buf_sendq, retlen); |
207 |
|
|
208 |
|
/* We have some data written .. update counters */ |
209 |
< |
to->localClient->send.bytes += retlen; |
210 |
< |
me.localClient->send.bytes += retlen; |
211 |
< |
} while (dbuf_length(&to->localClient->buf_sendq)); |
209 |
> |
to->connection->send.bytes += retlen; |
210 |
> |
me.connection->send.bytes += retlen; |
211 |
> |
} while (dbuf_length(&to->connection->buf_sendq)); |
212 |
|
|
213 |
< |
if ((retlen < 0) && (ignoreErrno(errno))) |
213 |
> |
if (retlen < 0 && comm_ignore_errno(errno)) |
214 |
|
{ |
215 |
+ |
AddFlag(to, FLAGS_BLOCKED); |
216 |
+ |
|
217 |
|
/* we have a non-fatal error, reschedule a write */ |
218 |
< |
comm_setselect(&to->localClient->fd, COMM_SELECT_WRITE, |
257 |
< |
(PF *)sendq_unblocked, to, 0); |
218 |
> |
comm_setselect(to->connection->fd, COMM_SELECT_WRITE, sendq_unblocked, to, 0); |
219 |
|
} |
220 |
|
else if (retlen <= 0) |
221 |
|
{ |
234 |
|
void |
235 |
|
send_queued_all(void) |
236 |
|
{ |
237 |
< |
dlink_node *ptr; |
237 |
> |
dlink_node *node; |
238 |
|
|
239 |
|
/* Servers are processed first, mainly because this can generate |
240 |
|
* a notice to opers, which is to be delivered by this function. |
241 |
|
*/ |
242 |
< |
DLINK_FOREACH(ptr, serv_list.head) |
243 |
< |
send_queued_write(ptr->data); |
242 |
> |
DLINK_FOREACH(node, local_server_list.head) |
243 |
> |
send_queued_write(node->data); |
244 |
|
|
245 |
< |
DLINK_FOREACH(ptr, unknown_list.head) |
246 |
< |
send_queued_write(ptr->data); |
245 |
> |
DLINK_FOREACH(node, unknown_list.head) |
246 |
> |
send_queued_write(node->data); |
247 |
|
|
248 |
< |
DLINK_FOREACH(ptr, local_client_list.head) |
249 |
< |
send_queued_write(ptr->data); |
248 |
> |
DLINK_FOREACH(node, local_client_list.head) |
249 |
> |
send_queued_write(node->data); |
250 |
|
|
251 |
|
/* NOTE: This can still put clients on aborted_list; unfortunately, |
252 |
|
* exit_aborted_clients takes precedence over send_queued_all, |
267 |
|
sendto_one(struct Client *to, const char *pattern, ...) |
268 |
|
{ |
269 |
|
va_list args; |
309 |
– |
struct dbuf_block *buffer = NULL; |
270 |
|
|
271 |
|
if (IsDead(to->from)) |
272 |
|
return; /* This socket has already been marked as dead */ |
273 |
|
|
314 |
– |
buffer = dbuf_alloc(); |
315 |
– |
|
274 |
|
va_start(args, pattern); |
275 |
+ |
|
276 |
+ |
struct dbuf_block *buffer = dbuf_alloc(); |
277 |
|
send_format(buffer, pattern, args); |
278 |
+ |
|
279 |
|
va_end(args); |
280 |
|
|
281 |
|
send_message(to->from, buffer); |
284 |
|
} |
285 |
|
|
286 |
|
void |
287 |
< |
sendto_one_numeric(struct Client *to, struct Client *from, enum irc_numerics numeric, ...) |
287 |
> |
sendto_one_numeric(struct Client *to, const struct Client *from, enum irc_numerics numeric, ...) |
288 |
|
{ |
328 |
– |
struct dbuf_block *buffer = NULL; |
329 |
– |
const char *dest = NULL; |
289 |
|
va_list args; |
290 |
+ |
const char *numstr = NULL; |
291 |
|
|
292 |
|
if (IsDead(to->from)) |
293 |
|
return; |
294 |
|
|
295 |
< |
dest = ID_or_name(to, to); |
295 |
> |
const char *dest = ID_or_name(to, to); |
296 |
|
if (EmptyString(dest)) |
297 |
|
dest = "*"; |
298 |
|
|
299 |
< |
buffer = dbuf_alloc(); |
300 |
< |
|
341 |
< |
dbuf_put_fmt(buffer, ":%s %03d %s ", ID_or_name(from, to), numeric, dest); |
299 |
> |
struct dbuf_block *buffer = dbuf_alloc(); |
300 |
> |
dbuf_put_fmt(buffer, ":%s %03d %s ", ID_or_name(from, to), numeric & ~SND_EXPLICIT, dest); |
301 |
|
|
302 |
|
va_start(args, numeric); |
303 |
< |
send_format(buffer, numeric_form(numeric), args); |
303 |
> |
|
304 |
> |
if (numeric & SND_EXPLICIT) |
305 |
> |
numstr = va_arg(args, const char *); |
306 |
> |
else |
307 |
> |
numstr = numeric_form(numeric); |
308 |
> |
|
309 |
> |
send_format(buffer, numstr, args); |
310 |
|
va_end(args); |
311 |
|
|
312 |
|
send_message(to->from, buffer); |
315 |
|
} |
316 |
|
|
317 |
|
void |
318 |
< |
sendto_one_notice(struct Client *to, struct Client *from, const char *pattern, ...) |
318 |
> |
sendto_one_notice(struct Client *to, const struct Client *from, const char *pattern, ...) |
319 |
|
{ |
355 |
– |
struct dbuf_block *buffer = NULL; |
356 |
– |
const char *dest = NULL; |
320 |
|
va_list args; |
321 |
|
|
322 |
|
if (IsDead(to->from)) |
323 |
|
return; |
324 |
|
|
325 |
< |
dest = ID_or_name(to, to); |
325 |
> |
const char *dest = ID_or_name(to, to); |
326 |
|
if (EmptyString(dest)) |
327 |
|
dest = "*"; |
328 |
|
|
329 |
< |
buffer = dbuf_alloc(); |
367 |
< |
|
329 |
> |
struct dbuf_block *buffer = dbuf_alloc(); |
330 |
|
dbuf_put_fmt(buffer, ":%s NOTICE %s ", ID_or_name(from, to), dest); |
331 |
|
|
332 |
|
va_start(args, pattern); |
350 |
|
* WARNING - +D clients are ignored |
351 |
|
*/ |
352 |
|
void |
353 |
< |
sendto_channel_butone(struct Client *one, struct Client *from, |
353 |
> |
sendto_channel_butone(struct Client *one, const struct Client *from, |
354 |
|
struct Channel *chptr, unsigned int type, |
355 |
|
const char *pattern, ...) |
356 |
|
{ |
357 |
|
va_list alocal, aremote; |
358 |
|
struct dbuf_block *local_buf, *remote_buf; |
359 |
< |
dlink_node *ptr = NULL, *ptr_next = NULL; |
359 |
> |
dlink_node *node; |
360 |
|
|
361 |
|
local_buf = dbuf_alloc(), remote_buf = dbuf_alloc(); |
362 |
|
|
363 |
< |
if (IsServer(from)) |
402 |
< |
dbuf_put_fmt(local_buf, ":%s ", from->name); |
403 |
< |
else |
363 |
> |
if (IsClient(from)) |
364 |
|
dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host); |
365 |
+ |
else |
366 |
+ |
dbuf_put_fmt(local_buf, ":%s ", from->name); |
367 |
|
|
368 |
|
dbuf_put_fmt(remote_buf, ":%s ", from->id); |
369 |
|
|
377 |
|
|
378 |
|
++current_serial; |
379 |
|
|
380 |
< |
DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->members.head) |
380 |
> |
DLINK_FOREACH(node, chptr->members.head) |
381 |
|
{ |
382 |
< |
struct Membership *ms = ptr->data; |
383 |
< |
struct Client *target_p = ms->client_p; |
382 |
> |
struct Membership *member = node->data; |
383 |
> |
struct Client *target_p = member->client_p; |
384 |
|
|
385 |
|
assert(IsClient(target_p)); |
386 |
|
|
387 |
< |
if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF) || |
388 |
< |
(one && target_p->from == one->from)) |
387 |
> |
if (IsDefunct(target_p->from)) |
388 |
> |
continue; |
389 |
> |
|
390 |
> |
if (one && (target_p->from == one->from)) |
391 |
|
continue; |
392 |
|
|
393 |
< |
if (type != 0 && (ms->flags & type) == 0) |
393 |
> |
if (type && (member->flags & type) == 0) |
394 |
> |
continue; |
395 |
> |
|
396 |
> |
if (HasUMode(target_p, UMODE_DEAF)) |
397 |
|
continue; |
398 |
|
|
399 |
|
if (MyConnect(target_p)) |
400 |
|
send_message(target_p, local_buf); |
401 |
< |
else if (target_p->from->localClient->serial != current_serial) |
401 |
> |
else if (target_p->from->connection->serial != current_serial) |
402 |
|
send_message_remote(target_p->from, from, remote_buf); |
403 |
< |
target_p->from->localClient->serial = current_serial; |
403 |
> |
|
404 |
> |
target_p->from->connection->serial = current_serial; |
405 |
|
} |
406 |
|
|
407 |
|
dbuf_ref_free(local_buf); |
427 |
|
* -davidt |
428 |
|
*/ |
429 |
|
void |
430 |
< |
sendto_server(struct Client *one, |
430 |
> |
sendto_server(const struct Client *one, |
431 |
|
const unsigned int caps, |
432 |
|
const unsigned int nocaps, |
433 |
|
const char *format, ...) |
434 |
|
{ |
435 |
|
va_list args; |
436 |
< |
dlink_node *ptr = NULL; |
469 |
< |
struct dbuf_block *buffer; |
470 |
< |
|
471 |
< |
buffer = dbuf_alloc(); |
436 |
> |
dlink_node *node; |
437 |
|
|
438 |
|
va_start(args, format); |
439 |
+ |
|
440 |
+ |
struct dbuf_block *buffer = dbuf_alloc(); |
441 |
|
send_format(buffer, format, args); |
442 |
+ |
|
443 |
|
va_end(args); |
444 |
|
|
445 |
< |
DLINK_FOREACH(ptr, serv_list.head) |
445 |
> |
DLINK_FOREACH(node, local_server_list.head) |
446 |
|
{ |
447 |
< |
struct Client *client_p = ptr->data; |
447 |
> |
struct Client *client_p = node->data; |
448 |
|
|
449 |
|
/* If dead already skip */ |
450 |
|
if (IsDead(client_p)) |
451 |
|
continue; |
452 |
+ |
|
453 |
|
/* check against 'one' */ |
454 |
< |
if (one != NULL && (client_p == one->from)) |
454 |
> |
if (one && (client_p == one->from)) |
455 |
|
continue; |
456 |
+ |
|
457 |
|
/* check we have required capabs */ |
458 |
< |
if ((client_p->localClient->caps & caps) != caps) |
458 |
> |
if ((client_p->connection->caps & caps) != caps) |
459 |
|
continue; |
460 |
+ |
|
461 |
|
/* check we don't have any forbidden capabs */ |
462 |
< |
if ((client_p->localClient->caps & nocaps) != 0) |
462 |
> |
if ((client_p->connection->caps & nocaps)) |
463 |
|
continue; |
464 |
|
|
465 |
|
send_message(client_p, buffer); |
478 |
|
* used by m_nick.c and exit_one_client. |
479 |
|
*/ |
480 |
|
void |
481 |
< |
sendto_common_channels_local(struct Client *user, int touser, unsigned int cap, |
482 |
< |
const char *pattern, ...) |
481 |
> |
sendto_common_channels_local(struct Client *user, int touser, unsigned int poscap, |
482 |
> |
unsigned int negcap, const char *pattern, ...) |
483 |
|
{ |
484 |
|
va_list args; |
485 |
|
dlink_node *uptr; |
486 |
|
dlink_node *cptr; |
487 |
|
struct Channel *chptr; |
488 |
< |
struct Membership *ms; |
488 |
> |
struct Membership *member; |
489 |
|
struct Client *target_p; |
490 |
< |
struct dbuf_block *buffer; |
520 |
< |
|
521 |
< |
buffer = dbuf_alloc(); |
490 |
> |
struct dbuf_block *buffer = dbuf_alloc(); |
491 |
|
|
492 |
|
va_start(args, pattern); |
493 |
|
send_format(buffer, pattern, args); |
498 |
|
DLINK_FOREACH(cptr, user->channel.head) |
499 |
|
{ |
500 |
|
chptr = ((struct Membership *)cptr->data)->chptr; |
532 |
– |
assert(chptr != NULL); |
501 |
|
|
502 |
< |
DLINK_FOREACH(uptr, chptr->members.head) |
502 |
> |
DLINK_FOREACH(uptr, chptr->members_local.head) |
503 |
|
{ |
504 |
< |
ms = uptr->data; |
505 |
< |
target_p = ms->client_p; |
506 |
< |
assert(target_p != NULL); |
504 |
> |
member = uptr->data; |
505 |
> |
target_p = member->client_p; |
506 |
> |
|
507 |
> |
if (target_p == user || IsDefunct(target_p) || |
508 |
> |
target_p->connection->serial == current_serial) |
509 |
> |
continue; |
510 |
|
|
511 |
< |
if (!MyConnect(target_p) || target_p == user || IsDefunct(target_p) || |
541 |
< |
target_p->localClient->serial == current_serial) |
511 |
> |
if (poscap && HasCap(target_p, poscap) != poscap) |
512 |
|
continue; |
513 |
|
|
514 |
< |
if (HasCap(target_p, cap) != cap) |
514 |
> |
if (negcap && HasCap(target_p, negcap)) |
515 |
|
continue; |
516 |
|
|
517 |
< |
target_p->localClient->serial = current_serial; |
517 |
> |
target_p->connection->serial = current_serial; |
518 |
|
send_message(target_p, buffer); |
519 |
|
} |
520 |
|
} |
521 |
|
|
522 |
|
if (touser && MyConnect(user) && !IsDead(user) && |
523 |
< |
user->localClient->serial != current_serial) |
524 |
< |
if (HasCap(user, cap) == cap) |
523 |
> |
user->connection->serial != current_serial) |
524 |
> |
if (HasCap(user, poscap) == poscap) |
525 |
|
send_message(user, buffer); |
526 |
|
|
527 |
|
dbuf_ref_free(buffer); |
528 |
|
} |
529 |
|
|
530 |
< |
/* sendto_channel_local() |
531 |
< |
* |
532 |
< |
* inputs - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE |
533 |
< |
* - whether to ignore +D clients (YES/NO) |
534 |
< |
* - pointer to channel to send to |
535 |
< |
* - var args pattern |
536 |
< |
* output - NONE |
567 |
< |
* side effects - Send a message to all members of a channel that are |
568 |
< |
* locally connected to this server. |
530 |
> |
/*! \brief Send a message to members of a channel that are locally connected to this server. |
531 |
> |
* \param one Client to skip; can be NULL |
532 |
> |
* \param chptr Destination channel |
533 |
> |
* \param status Channel member status flags clients must have |
534 |
> |
* \param poscap Positive client capabilities flags (CAP) |
535 |
> |
* \param negcap Negative client capabilities flags (CAP) |
536 |
> |
* \param pattern Format string for command arguments |
537 |
|
*/ |
538 |
|
void |
539 |
< |
sendto_channel_local(unsigned int type, int nodeaf, struct Channel *chptr, |
540 |
< |
const char *pattern, ...) |
539 |
> |
sendto_channel_local(const struct Client *one, struct Channel *chptr, unsigned int status, |
540 |
> |
unsigned int poscap, unsigned int negcap, const char *pattern, ...) |
541 |
|
{ |
542 |
|
va_list args; |
543 |
< |
dlink_node *ptr = NULL; |
544 |
< |
struct dbuf_block *buffer; |
577 |
< |
|
578 |
< |
buffer = dbuf_alloc(); |
543 |
> |
dlink_node *node; |
544 |
> |
struct dbuf_block *buffer = dbuf_alloc(); |
545 |
|
|
546 |
|
va_start(args, pattern); |
547 |
|
send_format(buffer, pattern, args); |
548 |
|
va_end(args); |
549 |
|
|
550 |
< |
DLINK_FOREACH(ptr, chptr->members.head) |
550 |
> |
DLINK_FOREACH(node, chptr->members_local.head) |
551 |
|
{ |
552 |
< |
struct Membership *ms = ptr->data; |
553 |
< |
struct Client *target_p = ms->client_p; |
552 |
> |
struct Membership *member = node->data; |
553 |
> |
struct Client *target_p = member->client_p; |
554 |
|
|
555 |
< |
if (type != 0 && (ms->flags & type) == 0) |
555 |
> |
if (IsDefunct(target_p)) |
556 |
|
continue; |
557 |
|
|
558 |
< |
if (!MyConnect(target_p) || IsDefunct(target_p) || |
593 |
< |
(nodeaf && HasUMode(target_p, UMODE_DEAF))) |
558 |
> |
if (one && target_p == one->from) |
559 |
|
continue; |
560 |
|
|
561 |
< |
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) |
561 |
> |
if (status && (member->flags & status) == 0) |
562 |
|
continue; |
563 |
|
|
564 |
< |
if (!MyConnect(target_p) || (one && target_p == one->from)) |
564 |
> |
if (poscap && HasCap(target_p, poscap) != poscap) |
565 |
|
continue; |
566 |
|
|
567 |
< |
if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF)) |
640 |
< |
continue; |
641 |
< |
|
642 |
< |
if (HasCap(target_p, cap) != cap) |
567 |
> |
if (negcap && HasCap(target_p, negcap)) |
568 |
|
continue; |
569 |
|
|
570 |
|
send_message(target_p, buffer); |
594 |
|
match_it(const struct Client *one, const char *mask, unsigned int what) |
595 |
|
{ |
596 |
|
if (what == MATCH_HOST) |
597 |
< |
return !match(mask, one->host); |
597 |
> |
return match(mask, one->host) == 0; |
598 |
|
|
599 |
< |
return !match(mask, one->servptr->name); |
599 |
> |
return match(mask, one->servptr->name) == 0; |
600 |
|
} |
601 |
|
|
602 |
|
/* sendto_match_butone() |
607 |
|
* ugh. ONLY used by m_message.c to send an "oper magic" message. ugh. |
608 |
|
*/ |
609 |
|
void |
610 |
< |
sendto_match_butone(struct Client *one, struct Client *from, const char *mask, |
611 |
< |
int what, const char *pattern, ...) |
610 |
> |
sendto_match_butone(const struct Client *one, const struct Client *from, |
611 |
> |
const char *mask, int what, const char *pattern, ...) |
612 |
|
{ |
613 |
|
va_list alocal, aremote; |
614 |
< |
dlink_node *ptr = NULL, *ptr_next = NULL; |
614 |
> |
dlink_node *node; |
615 |
|
struct dbuf_block *local_buf, *remote_buf; |
616 |
|
|
617 |
|
local_buf = dbuf_alloc(), remote_buf = dbuf_alloc(); |
627 |
|
va_end(alocal); |
628 |
|
|
629 |
|
/* scan the local clients */ |
630 |
< |
DLINK_FOREACH(ptr, local_client_list.head) |
630 |
> |
DLINK_FOREACH(node, local_client_list.head) |
631 |
|
{ |
632 |
< |
struct Client *client_p = ptr->data; |
632 |
> |
struct Client *client_p = node->data; |
633 |
|
|
634 |
< |
if ((!one || client_p != one->from) && !IsDefunct(client_p) && |
635 |
< |
match_it(client_p, mask, what)) |
636 |
< |
send_message(client_p, local_buf); |
634 |
> |
if ((one == NULL || client_p != one->from) && !IsDefunct(client_p)) |
635 |
> |
if (match_it(client_p, mask, what)) |
636 |
> |
send_message(client_p, local_buf); |
637 |
|
} |
638 |
|
|
639 |
|
/* Now scan servers */ |
640 |
< |
DLINK_FOREACH_SAFE(ptr, ptr_next, serv_list.head) |
640 |
> |
DLINK_FOREACH(node, local_server_list.head) |
641 |
|
{ |
642 |
< |
struct Client *client_p = ptr->data; |
642 |
> |
struct Client *client_p = node->data; |
643 |
|
|
644 |
|
/* |
645 |
|
* The old code looped through every client on the |
665 |
|
* server deal with it. |
666 |
|
* -wnder |
667 |
|
*/ |
668 |
< |
if ((!one || client_p != one->from) && !IsDefunct(client_p)) |
668 |
> |
if ((one == NULL || client_p != one->from) && !IsDefunct(client_p)) |
669 |
|
send_message_remote(client_p, from, remote_buf); |
670 |
|
} |
671 |
|
|
683 |
|
* side effects - data sent to servers matching with capab |
684 |
|
*/ |
685 |
|
void |
686 |
< |
sendto_match_servs(struct Client *source_p, const char *mask, unsigned int cap, |
686 |
> |
sendto_match_servs(const struct Client *source_p, const char *mask, unsigned int cap, |
687 |
|
const char *pattern, ...) |
688 |
|
{ |
689 |
|
va_list args; |
690 |
< |
dlink_node *ptr = NULL; |
691 |
< |
struct dbuf_block *buff_suid; |
767 |
< |
|
768 |
< |
buff_suid = dbuf_alloc(); |
690 |
> |
dlink_node *node; |
691 |
> |
struct dbuf_block *buffer = dbuf_alloc(); |
692 |
|
|
693 |
+ |
dbuf_put_fmt(buffer, ":%s ", source_p->id); |
694 |
|
va_start(args, pattern); |
695 |
< |
dbuf_put_fmt(buff_suid, ":%s ", source_p->id); |
772 |
< |
dbuf_put_args(buff_suid, pattern, args); |
695 |
> |
send_format(buffer, pattern, args); |
696 |
|
va_end(args); |
697 |
|
|
698 |
|
++current_serial; |
699 |
|
|
700 |
< |
DLINK_FOREACH(ptr, global_serv_list.head) |
700 |
> |
DLINK_FOREACH(node, global_server_list.head) |
701 |
|
{ |
702 |
< |
struct Client *target_p = ptr->data; |
702 |
> |
struct Client *target_p = node->data; |
703 |
|
|
704 |
|
/* Do not attempt to send to ourselves, or the source */ |
705 |
|
if (IsMe(target_p) || target_p->from == source_p->from) |
706 |
|
continue; |
707 |
|
|
708 |
< |
if (target_p->from->localClient->serial == current_serial) |
708 |
> |
if (target_p->from->connection->serial == current_serial) |
709 |
|
continue; |
710 |
|
|
711 |
< |
if (!match(mask, target_p->name)) |
712 |
< |
{ |
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; |
711 |
> |
if (match(mask, target_p->name)) |
712 |
> |
continue; |
713 |
|
|
714 |
< |
if (!IsCapable(target_p->from, cap)) |
715 |
< |
continue; |
714 |
> |
if (cap && IsCapable(target_p->from, cap) != cap) |
715 |
> |
continue; |
716 |
|
|
717 |
< |
send_message_remote(target_p->from, source_p, buff_suid); |
718 |
< |
} |
717 |
> |
target_p->from->connection->serial = current_serial; |
718 |
> |
send_message_remote(target_p->from, source_p, buffer); |
719 |
|
} |
720 |
|
|
721 |
< |
dbuf_ref_free(buff_suid); |
721 |
> |
dbuf_ref_free(buffer); |
722 |
|
} |
723 |
|
|
724 |
|
/* sendto_anywhere() |
731 |
|
* but useful when one does not know where target "lives" |
732 |
|
*/ |
733 |
|
void |
734 |
< |
sendto_anywhere(struct Client *to, struct Client *from, |
734 |
> |
sendto_anywhere(struct Client *to, const struct Client *from, |
735 |
|
const char *command, |
736 |
|
const char *pattern, ...) |
737 |
|
{ |
738 |
|
va_list args; |
821 |
– |
struct dbuf_block *buffer = NULL; |
739 |
|
|
740 |
|
if (IsDead(to->from)) |
741 |
|
return; |
742 |
|
|
743 |
< |
buffer = dbuf_alloc(); |
827 |
< |
|
743 |
> |
struct dbuf_block *buffer = dbuf_alloc(); |
744 |
|
if (MyClient(to) && IsClient(from)) |
745 |
|
dbuf_put_fmt(buffer, ":%s!%s@%s %s %s ", from->name, from->username, |
746 |
|
from->host, command, to->name); |
752 |
|
send_format(buffer, pattern, args); |
753 |
|
va_end(args); |
754 |
|
|
755 |
< |
if (MyClient(to)) |
755 |
> |
if (MyConnect(to)) |
756 |
|
send_message(to, buffer); |
757 |
|
else |
758 |
< |
send_message_remote(to, from, buffer); |
758 |
> |
send_message_remote(to->from, from, buffer); |
759 |
|
|
760 |
|
dbuf_ref_free(buffer); |
761 |
|
} |
771 |
|
void |
772 |
|
sendto_realops_flags(unsigned int flags, int level, int type, const char *pattern, ...) |
773 |
|
{ |
774 |
< |
const char *ntype = NULL; |
775 |
< |
dlink_node *ptr = NULL; |
860 |
< |
char nbuf[IRCD_BUFSIZE]; |
774 |
> |
const char *ntype = "???"; |
775 |
> |
dlink_node *node; |
776 |
|
va_list args; |
777 |
|
|
863 |
– |
va_start(args, pattern); |
864 |
– |
vsnprintf(nbuf, sizeof(nbuf), pattern, args); |
865 |
– |
va_end(args); |
866 |
– |
|
778 |
|
switch (type) |
779 |
|
{ |
780 |
|
case SEND_NOTICE: |
790 |
|
assert(0); |
791 |
|
} |
792 |
|
|
793 |
< |
DLINK_FOREACH(ptr, oper_list.head) |
793 |
> |
struct dbuf_block *buffer = dbuf_alloc(); |
794 |
> |
dbuf_put_fmt(buffer, ":%s NOTICE * :*** %s -- ", me.name, ntype); |
795 |
> |
|
796 |
> |
va_start(args, pattern); |
797 |
> |
send_format(buffer, pattern, args); |
798 |
> |
va_end(args); |
799 |
> |
|
800 |
> |
DLINK_FOREACH(node, oper_list.head) |
801 |
|
{ |
802 |
< |
struct Client *client_p = ptr->data; |
802 |
> |
struct Client *client_p = node->data; |
803 |
|
assert(HasUMode(client_p, UMODE_OPER)); |
804 |
|
|
805 |
|
/* |
810 |
|
((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN))) |
811 |
|
continue; |
812 |
|
|
813 |
< |
if (HasUMode(client_p, flags)) |
814 |
< |
sendto_one(client_p, ":%s NOTICE %s :*** %s -- %s", |
897 |
< |
me.name, client_p->name, ntype, nbuf); |
813 |
> |
if (HasUMode(client_p, flags) && !IsDead(client_p)) |
814 |
> |
send_message(client_p, buffer); |
815 |
|
} |
816 |
+ |
|
817 |
+ |
dbuf_ref_free(buffer); |
818 |
+ |
} |
819 |
+ |
|
820 |
+ |
/* ts_warn() |
821 |
+ |
* |
822 |
+ |
* inputs - var args message |
823 |
+ |
* output - NONE |
824 |
+ |
* side effects - Call sendto_realops_flags, with some flood checking |
825 |
+ |
* (at most 5 warnings every 5 seconds) |
826 |
+ |
*/ |
827 |
+ |
void |
828 |
+ |
sendto_realops_flags_ratelimited(uintmax_t *rate, const char *pattern, ...) |
829 |
+ |
{ |
830 |
+ |
va_list args; |
831 |
+ |
char buffer[IRCD_BUFSIZE] = ""; |
832 |
+ |
|
833 |
+ |
if ((CurrentTime - *rate) < 20) |
834 |
+ |
return; |
835 |
+ |
|
836 |
+ |
*rate = CurrentTime; |
837 |
+ |
|
838 |
+ |
va_start(args, pattern); |
839 |
+ |
vsnprintf(buffer, sizeof(buffer), pattern, args); |
840 |
+ |
va_end(args); |
841 |
+ |
|
842 |
+ |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, "%s", buffer); |
843 |
+ |
ilog(LOG_TYPE_IRCD, "%s", buffer); |
844 |
|
} |
845 |
|
|
846 |
|
/* sendto_wallops_flags() |
852 |
|
* side effects - Send a wallops to local opers |
853 |
|
*/ |
854 |
|
void |
855 |
< |
sendto_wallops_flags(unsigned int flags, struct Client *source_p, |
855 |
> |
sendto_wallops_flags(unsigned int flags, const struct Client *source_p, |
856 |
|
const char *pattern, ...) |
857 |
|
{ |
858 |
< |
dlink_node *ptr = NULL; |
858 |
> |
dlink_node *node; |
859 |
|
va_list args; |
860 |
< |
struct dbuf_block *buffer; |
916 |
< |
|
917 |
< |
buffer = dbuf_alloc(); |
860 |
> |
struct dbuf_block *buffer = dbuf_alloc(); |
861 |
|
|
862 |
|
if (IsClient(source_p)) |
863 |
|
dbuf_put_fmt(buffer, ":%s!%s@%s WALLOPS :", source_p->name, source_p->username, source_p->host); |
868 |
|
send_format(buffer, pattern, args); |
869 |
|
va_end(args); |
870 |
|
|
871 |
< |
DLINK_FOREACH(ptr, oper_list.head) |
871 |
> |
DLINK_FOREACH(node, oper_list.head) |
872 |
|
{ |
873 |
< |
struct Client *client_p = ptr->data; |
873 |
> |
struct Client *client_p = node->data; |
874 |
|
assert(client_p->umodes & UMODE_OPER); |
875 |
|
|
876 |
< |
if (HasUMode(client_p, flags) && !IsDefunct(client_p)) |
876 |
> |
if (HasUMode(client_p, flags) && !IsDead(client_p)) |
877 |
|
send_message(client_p, buffer); |
878 |
|
} |
879 |
|
|
880 |
|
dbuf_ref_free(buffer); |
881 |
|
} |
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 |
– |
} |