23 |
|
*/ |
24 |
|
|
25 |
|
#include "stdinc.h" |
26 |
< |
#include "tools.h" |
26 |
> |
#include "list.h" |
27 |
|
#include "send.h" |
28 |
|
#include "channel.h" |
29 |
|
#include "client.h" |
30 |
– |
#include "common.h" |
30 |
|
#include "dbuf.h" |
31 |
|
#include "irc_string.h" |
32 |
|
#include "ircd.h" |
34 |
– |
#include "handlers.h" |
33 |
|
#include "numeric.h" |
34 |
|
#include "fdlist.h" |
35 |
|
#include "s_bsd.h" |
36 |
|
#include "s_serv.h" |
37 |
< |
#include "sprintf_irc.h" |
38 |
< |
#include "s_conf.h" |
41 |
< |
#include "list.h" |
42 |
< |
#include "s_log.h" |
37 |
> |
#include "conf.h" |
38 |
> |
#include "log.h" |
39 |
|
#include "memory.h" |
44 |
– |
#include "hook.h" |
45 |
– |
#include "irc_getnameinfo.h" |
40 |
|
#include "packet.h" |
41 |
|
|
48 |
– |
#define LOG_BUFSIZE 2048 |
49 |
– |
|
50 |
– |
struct Callback *iosend_cb = NULL; |
51 |
– |
struct Callback *iosendctrl_cb = NULL; |
42 |
|
|
43 |
< |
static void send_message(struct Client *, char *, int); |
54 |
< |
static void send_message_remote(struct Client *, struct Client *, char *, int); |
43 |
> |
static unsigned int current_serial = 0; |
44 |
|
|
56 |
– |
static unsigned long current_serial = 0L; |
45 |
|
|
46 |
|
/* send_format() |
47 |
|
* |
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 |
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 |
75 |
|
|
76 |
|
lsendbuf[len++] = '\r'; |
77 |
|
lsendbuf[len++] = '\n'; |
78 |
< |
return (len); |
91 |
< |
} |
92 |
< |
|
93 |
< |
/* |
94 |
< |
* iosend_default - append a packet to the client's sendq. |
95 |
< |
*/ |
96 |
< |
void * |
97 |
< |
iosend_default(va_list args) |
98 |
< |
{ |
99 |
< |
struct Client *to = va_arg(args, struct Client *); |
100 |
< |
int length = va_arg(args, int); |
101 |
< |
char *buf = va_arg(args, char *); |
102 |
< |
|
103 |
< |
dbuf_put(&to->localClient->buf_sendq, buf, length); |
104 |
< |
return NULL; |
78 |
> |
return len; |
79 |
|
} |
80 |
|
|
81 |
|
/* |
89 |
|
assert(!IsMe(to)); |
90 |
|
assert(to != &me); |
91 |
|
|
92 |
< |
if (dbuf_length(&to->localClient->buf_sendq) + len > get_sendq(to)) |
92 |
> |
if (dbuf_length(&to->localClient->buf_sendq) + len > get_sendq(&to->localClient->confs)) |
93 |
|
{ |
94 |
|
if (IsServer(to)) |
95 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
96 |
< |
"Max SendQ limit exceeded for %s: %lu > %lu", |
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) + len), |
99 |
< |
get_sendq(to)); |
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 |
< |
execute_callback(iosend_cb, to, len, buf); |
106 |
> |
dbuf_put(&to->localClient->buf_sendq, buf, len); |
107 |
|
|
108 |
|
/* |
109 |
|
** Update statistics. The following is slightly incorrect |
113 |
|
++to->localClient->send.messages; |
114 |
|
++me.localClient->send.messages; |
115 |
|
|
116 |
< |
if (dbuf_length(&to->localClient->buf_sendq) > |
143 |
< |
(IsServer(to) ? (unsigned int) 1024 : (unsigned int) 4096)) |
144 |
< |
send_queued_write(to); |
116 |
> |
send_queued_write(to); |
117 |
|
} |
118 |
|
|
119 |
|
/* send_message_remote() |
131 |
|
send_message_remote(struct Client *to, struct Client *from, |
132 |
|
char *buf, int len) |
133 |
|
{ |
134 |
+ |
if (to->from) |
135 |
+ |
to = to->from; |
136 |
+ |
|
137 |
|
if (!MyConnect(to)) |
138 |
|
{ |
139 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
140 |
< |
"server send message to %s [%s] dropped from %s(Not local server)", |
141 |
< |
to->name, to->from->name, from->name); |
139 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
140 |
> |
"Server send message to %s [%s] dropped from %s(Not local server)", |
141 |
> |
to->name, to->from->name, from->name); |
142 |
|
return; |
143 |
|
} |
144 |
|
|
149 |
|
{ |
150 |
|
if (IsServer(from)) |
151 |
|
{ |
152 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
152 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
153 |
|
"Send message to %s [%s] dropped from %s(Fake Dir)", |
154 |
|
to->name, to->from->name, from->name); |
155 |
|
return; |
156 |
|
} |
157 |
|
|
158 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
158 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
159 |
|
"Ghosted: %s[%s@%s] from %s[%s@%s] (%s)", |
160 |
|
to->name, to->username, to->host, |
161 |
|
from->name, from->username, from->host, |
162 |
|
to->from->name); |
163 |
|
|
164 |
< |
sendto_server(NULL, NULL, CAP_TS6, NOCAPS, |
164 |
> |
sendto_server(NULL, CAP_TS6, NOCAPS, |
165 |
|
":%s KILL %s :%s (%s[%s@%s] Ghosted %s)", |
166 |
|
me.id, to->name, me.name, to->name, |
167 |
|
to->username, to->host, to->from->name); |
168 |
< |
sendto_server(NULL, NULL, NOCAPS, CAP_TS6, |
168 |
> |
sendto_server(NULL, NOCAPS, CAP_TS6, |
169 |
|
":%s KILL %s :%s (%s[%s@%s] Ghosted %s)", |
170 |
|
me.name, to->name, me.name, to->name, |
171 |
|
to->username, to->host, to->from->name); |
172 |
|
|
173 |
< |
SetKilled(to); |
173 |
> |
AddFlag(to, FLAGS_KILLED); |
174 |
|
|
175 |
|
if (IsClient(from)) |
176 |
|
sendto_one(from, form_str(ERR_GHOSTEDCLIENT), |
178 |
|
to->host, to->from); |
179 |
|
|
180 |
|
exit_client(to, &me, "Ghosted client"); |
206 |
– |
|
181 |
|
return; |
182 |
< |
} |
182 |
> |
} |
183 |
|
|
184 |
|
send_message(to, buf, len); |
185 |
|
} |
191 |
|
void |
192 |
|
sendq_unblocked(fde_t *fd, struct Client *client_p) |
193 |
|
{ |
194 |
< |
ClearSendqBlocked(client_p); |
195 |
< |
/* let send_queued_write be executed by send_queued_all */ |
222 |
< |
|
223 |
< |
#ifdef HAVE_LIBCRYPTO |
224 |
< |
if (fd->flags.pending_read) |
225 |
< |
{ |
226 |
< |
fd->flags.pending_read = 0; |
227 |
< |
read_packet(fd, client_p); |
228 |
< |
} |
229 |
< |
#endif |
230 |
< |
} |
231 |
< |
|
232 |
< |
/* |
233 |
< |
** slinkq_unblocked |
234 |
< |
** Called when a server control socket is ready for writing. |
235 |
< |
*/ |
236 |
< |
static void |
237 |
< |
slinkq_unblocked(fde_t *fd, struct Client *client_p) |
238 |
< |
{ |
239 |
< |
ClearSlinkqBlocked(client_p); |
240 |
< |
send_queued_slink_write(client_p); |
194 |
> |
assert(fd == &client_p->localClient->fd); |
195 |
> |
send_queued_write(client_p); |
196 |
|
} |
197 |
|
|
198 |
|
/* |
204 |
|
void |
205 |
|
send_queued_write(struct Client *to) |
206 |
|
{ |
207 |
< |
int retlen; |
208 |
< |
struct dbuf_block *first; |
207 |
> |
int retlen = 0; |
208 |
> |
struct dbuf_block *first = NULL; |
209 |
|
|
210 |
|
/* |
211 |
|
** Once socket is marked dead, we cannot start writing to it, |
212 |
|
** even if the error is removed... |
213 |
|
*/ |
214 |
< |
if (IsDead(to) || IsSendqBlocked(to)) |
214 |
> |
if (IsDead(to)) |
215 |
|
return; /* no use calling send() now */ |
216 |
|
|
217 |
|
/* Next, lets try to write some data */ |
263 |
– |
|
218 |
|
if (dbuf_length(&to->localClient->buf_sendq)) |
219 |
|
{ |
220 |
< |
do { |
220 |
> |
do |
221 |
> |
{ |
222 |
|
first = to->localClient->buf_sendq.blocks.head->data; |
223 |
|
|
224 |
|
#ifdef HAVE_LIBCRYPTO |
227 |
|
retlen = SSL_write(to->localClient->fd.ssl, first->data, first->size); |
228 |
|
|
229 |
|
/* translate openssl error codes, sigh */ |
230 |
< |
if (retlen < 0) |
231 |
< |
switch (SSL_get_error(to->localClient->fd.ssl, retlen)) |
232 |
< |
{ |
230 |
> |
if (retlen < 0) |
231 |
> |
{ |
232 |
> |
switch (SSL_get_error(to->localClient->fd.ssl, retlen)) |
233 |
> |
{ |
234 |
|
case SSL_ERROR_WANT_READ: |
235 |
< |
return; /* retry later, don't register for write events */ |
236 |
< |
|
237 |
< |
case SSL_ERROR_WANT_WRITE: |
282 |
< |
errno = EWOULDBLOCK; |
235 |
> |
return; /* retry later, don't register for write events */ |
236 |
> |
case SSL_ERROR_WANT_WRITE: |
237 |
> |
errno = EWOULDBLOCK; |
238 |
|
case SSL_ERROR_SYSCALL: |
239 |
< |
break; |
239 |
> |
break; |
240 |
|
case SSL_ERROR_SSL: |
241 |
|
if (errno == EAGAIN) |
242 |
|
break; |
243 |
|
default: |
244 |
< |
retlen = errno = 0; /* either an SSL-specific error or EOF */ |
245 |
< |
} |
244 |
> |
retlen = errno = 0; /* either an SSL-specific error or EOF */ |
245 |
> |
} |
246 |
> |
} |
247 |
|
} |
248 |
|
else |
249 |
|
#endif |
250 |
|
retlen = send(to->localClient->fd.fd, first->data, first->size, 0); |
251 |
|
|
252 |
|
if (retlen <= 0) |
297 |
– |
{ |
298 |
– |
#ifdef _WIN32 |
299 |
– |
errno = WSAGetLastError(); |
300 |
– |
#endif |
253 |
|
break; |
302 |
– |
} |
254 |
|
|
255 |
|
dbuf_delete(&to->localClient->buf_sendq, retlen); |
256 |
|
|
262 |
|
if ((retlen < 0) && (ignoreErrno(errno))) |
263 |
|
{ |
264 |
|
/* we have a non-fatal error, reschedule a write */ |
314 |
– |
SetSendqBlocked(to); |
265 |
|
comm_setselect(&to->localClient->fd, COMM_SELECT_WRITE, |
266 |
< |
(PF *)sendq_unblocked, (void *)to, 0); |
266 |
> |
(PF *)sendq_unblocked, to, 0); |
267 |
|
} |
268 |
|
else if (retlen <= 0) |
269 |
|
{ |
273 |
|
} |
274 |
|
} |
275 |
|
|
326 |
– |
/* |
327 |
– |
** send_queued_slink_write |
328 |
– |
** This is called when there is a chance the some output would |
329 |
– |
** be possible. This attempts to empty the send queue as far as |
330 |
– |
** possible, and then if any data is left, a write is rescheduled. |
331 |
– |
*/ |
332 |
– |
void |
333 |
– |
send_queued_slink_write(struct Client *to) |
334 |
– |
{ |
335 |
– |
int retlen; |
336 |
– |
|
337 |
– |
/* |
338 |
– |
** Once socket is marked dead, we cannot start writing to it, |
339 |
– |
** even if the error is removed... |
340 |
– |
*/ |
341 |
– |
if (IsDead(to) || IsSlinkqBlocked(to)) |
342 |
– |
return; /* no use calling send() now */ |
343 |
– |
|
344 |
– |
/* Next, lets try to write some data */ |
345 |
– |
if (to->localClient->slinkq != NULL) |
346 |
– |
{ |
347 |
– |
retlen = send(to->localClient->ctrlfd.fd, |
348 |
– |
to->localClient->slinkq + to->localClient->slinkq_ofs, |
349 |
– |
to->localClient->slinkq_len, 0); |
350 |
– |
if (retlen < 0) |
351 |
– |
{ |
352 |
– |
/* If we have a fatal error */ |
353 |
– |
if (!ignoreErrno(errno)) |
354 |
– |
{ |
355 |
– |
dead_link_on_write(to, errno); |
356 |
– |
return; |
357 |
– |
} |
358 |
– |
} |
359 |
– |
else if (retlen == 0) |
360 |
– |
{ |
361 |
– |
/* 0 bytes is an EOF .. */ |
362 |
– |
dead_link_on_write(to, 0); |
363 |
– |
return; |
364 |
– |
} |
365 |
– |
else |
366 |
– |
{ |
367 |
– |
execute_callback(iosendctrl_cb, to, retlen, |
368 |
– |
to->localClient->slinkq + to->localClient->slinkq_ofs); |
369 |
– |
to->localClient->slinkq_len -= retlen; |
370 |
– |
|
371 |
– |
assert(to->localClient->slinkq_len >= 0); |
372 |
– |
if (to->localClient->slinkq_len) |
373 |
– |
to->localClient->slinkq_ofs += retlen; |
374 |
– |
else |
375 |
– |
{ |
376 |
– |
to->localClient->slinkq_ofs = 0; |
377 |
– |
MyFree(to->localClient->slinkq); |
378 |
– |
to->localClient->slinkq = NULL; |
379 |
– |
} |
380 |
– |
} |
381 |
– |
|
382 |
– |
/* Finally, if we have any more data, reschedule a write */ |
383 |
– |
if (to->localClient->slinkq_len) |
384 |
– |
{ |
385 |
– |
SetSlinkqBlocked(to); |
386 |
– |
comm_setselect(&to->localClient->ctrlfd, COMM_SELECT_WRITE, |
387 |
– |
(PF *)slinkq_unblocked, (void *)to, 0); |
388 |
– |
} |
389 |
– |
} |
390 |
– |
} |
391 |
– |
|
276 |
|
/* send_queued_all() |
277 |
|
* |
278 |
|
* input - NONE |
288 |
|
* a notice to opers, which is to be delivered by this function. |
289 |
|
*/ |
290 |
|
DLINK_FOREACH(ptr, serv_list.head) |
291 |
< |
send_queued_write((struct Client *) ptr->data); |
291 |
> |
send_queued_write(ptr->data); |
292 |
|
|
293 |
|
DLINK_FOREACH(ptr, unknown_list.head) |
294 |
< |
send_queued_write((struct Client *) ptr->data); |
294 |
> |
send_queued_write(ptr->data); |
295 |
|
|
296 |
|
DLINK_FOREACH(ptr, local_client_list.head) |
297 |
< |
send_queued_write((struct Client *) ptr->data); |
297 |
> |
send_queued_write(ptr->data); |
298 |
|
|
299 |
|
/* NOTE: This can still put clients on aborted_list; unfortunately, |
300 |
|
* exit_aborted_clients takes precedence over send_queued_all, |
324 |
|
return; /* This socket has already been marked as dead */ |
325 |
|
|
326 |
|
va_start(args, pattern); |
327 |
< |
len = send_format(buffer, IRCD_BUFSIZE, pattern, args); |
327 |
> |
len = send_format(buffer, sizeof(buffer), pattern, args); |
328 |
|
va_end(args); |
329 |
|
|
330 |
|
send_message(to, buffer, len); |
343 |
|
*/ |
344 |
|
void |
345 |
|
sendto_channel_butone(struct Client *one, struct Client *from, |
346 |
< |
struct Channel *chptr, const char *command, |
346 |
> |
struct Channel *chptr, unsigned int type, |
347 |
|
const char *pattern, ...) |
348 |
|
{ |
349 |
|
va_list alocal, aremote, auid; |
351 |
|
char remote_buf[IRCD_BUFSIZE]; |
352 |
|
char uid_buf[IRCD_BUFSIZE]; |
353 |
|
int local_len, remote_len, uid_len; |
354 |
< |
dlink_node *ptr; |
471 |
< |
dlink_node *ptr_next; |
472 |
< |
struct Client *target_p; |
354 |
> |
dlink_node *ptr = NULL, *ptr_next = NULL; |
355 |
|
|
356 |
|
if (IsServer(from)) |
357 |
< |
local_len = ircsprintf(local_buf, ":%s %s %s ", |
358 |
< |
from->name, command, chptr->chname); |
357 |
> |
local_len = snprintf(local_buf, sizeof(local_buf), ":%s ", |
358 |
> |
from->name); |
359 |
|
else |
360 |
< |
local_len = ircsprintf(local_buf, ":%s!%s@%s %s %s ", |
361 |
< |
from->name, from->username, from->host, |
362 |
< |
command, chptr->chname); |
363 |
< |
remote_len = ircsprintf(remote_buf, ":%s %s %s ", |
364 |
< |
from->name, command, chptr->chname); |
483 |
< |
uid_len = ircsprintf(uid_buf, ":%s %s %s ", |
484 |
< |
ID(from), command, chptr->chname); |
360 |
> |
local_len = snprintf(local_buf, sizeof(local_buf), ":%s!%s@%s ", |
361 |
> |
from->name, from->username, from->host); |
362 |
> |
remote_len = snprintf(remote_buf, sizeof(remote_buf), ":%s ", |
363 |
> |
from->name); |
364 |
> |
uid_len = snprintf(uid_buf, sizeof(uid_buf), ":%s ", ID(from)); |
365 |
|
|
366 |
|
va_start(alocal, pattern); |
367 |
|
va_start(aremote, pattern); |
380 |
|
|
381 |
|
DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->members.head) |
382 |
|
{ |
383 |
< |
target_p = ((struct Membership *)ptr->data)->client_p; |
384 |
< |
assert(target_p != NULL); |
383 |
> |
struct Membership *ms = ptr->data; |
384 |
> |
struct Client *target_p = ms->client_p; |
385 |
|
|
386 |
< |
if (IsDefunct(target_p) || IsDeaf(target_p) || target_p->from == one) |
386 |
> |
assert(IsClient(target_p)); |
387 |
> |
|
388 |
> |
if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF) || target_p->from == one) |
389 |
> |
continue; |
390 |
> |
|
391 |
> |
if (type != 0 && (ms->flags & type) == 0) |
392 |
|
continue; |
393 |
|
|
394 |
< |
if (MyClient(target_p)) |
394 |
> |
if (MyConnect(target_p)) |
395 |
|
{ |
396 |
< |
if (target_p->serial != current_serial) |
396 |
> |
if (target_p->localClient->serial != current_serial) |
397 |
|
{ |
398 |
|
send_message(target_p, local_buf, local_len); |
399 |
< |
target_p->serial = current_serial; |
399 |
> |
target_p->localClient->serial = current_serial; |
400 |
|
} |
401 |
|
} |
402 |
|
else |
404 |
|
/* Now check whether a message has been sent to this |
405 |
|
* remote link already |
406 |
|
*/ |
407 |
< |
if (target_p->from->serial != current_serial) |
407 |
> |
if (target_p->from->localClient->serial != current_serial) |
408 |
|
{ |
409 |
|
if (IsCapable(target_p->from, CAP_TS6)) |
410 |
|
send_message_remote(target_p->from, from, uid_buf, uid_len); |
411 |
|
else |
412 |
|
send_message_remote(target_p->from, from, remote_buf, remote_len); |
413 |
< |
target_p->from->serial = current_serial; |
413 |
> |
target_p->from->localClient->serial = current_serial; |
414 |
|
} |
415 |
|
} |
416 |
|
} |
434 |
|
* lazylinks, uids, etc. |
435 |
|
* -davidt |
436 |
|
*/ |
437 |
< |
void |
437 |
> |
void |
438 |
|
sendto_server(struct Client *one, |
439 |
< |
struct Channel *chptr, unsigned long caps, |
440 |
< |
unsigned long nocaps, |
439 |
> |
const unsigned int caps, |
440 |
> |
const unsigned int nocaps, |
441 |
|
const char *format, ...) |
442 |
|
{ |
443 |
|
va_list args; |
445 |
|
char buffer[IRCD_BUFSIZE]; |
446 |
|
int len = 0; |
447 |
|
|
563 |
– |
if (chptr && chptr->chname[0] != '#') |
564 |
– |
return; |
565 |
– |
|
448 |
|
va_start(args, format); |
449 |
< |
len = send_format(buffer, IRCD_BUFSIZE, format, args); |
449 |
> |
len = send_format(buffer, sizeof(buffer), format, args); |
450 |
|
va_end(args); |
451 |
|
|
452 |
|
DLINK_FOREACH(ptr, serv_list.head) |
480 |
|
* used by m_nick.c and exit_one_client. |
481 |
|
*/ |
482 |
|
void |
483 |
< |
sendto_common_channels_local(struct Client *user, int touser, |
483 |
> |
sendto_common_channels_local(struct Client *user, int touser, unsigned int cap, |
484 |
|
const char *pattern, ...) |
485 |
|
{ |
486 |
|
va_list args; |
493 |
|
int len; |
494 |
|
|
495 |
|
va_start(args, pattern); |
496 |
< |
len = send_format(buffer, IRCD_BUFSIZE, pattern, args); |
496 |
> |
len = send_format(buffer, sizeof(buffer), pattern, args); |
497 |
|
va_end(args); |
498 |
|
|
499 |
|
++current_serial; |
500 |
|
|
501 |
|
DLINK_FOREACH(cptr, user->channel.head) |
502 |
|
{ |
503 |
< |
chptr = ((struct Membership *) cptr->data)->chptr; |
503 |
> |
chptr = ((struct Membership *)cptr->data)->chptr; |
504 |
|
assert(chptr != NULL); |
505 |
|
|
506 |
|
DLINK_FOREACH(uptr, chptr->members.head) |
510 |
|
assert(target_p != NULL); |
511 |
|
|
512 |
|
if (!MyConnect(target_p) || target_p == user || IsDefunct(target_p) || |
513 |
< |
target_p->serial == current_serial) |
513 |
> |
target_p->localClient->serial == current_serial) |
514 |
|
continue; |
515 |
|
|
516 |
< |
target_p->serial = current_serial; |
516 |
> |
if (HasCap(target_p, cap) != cap) |
517 |
> |
continue; |
518 |
> |
|
519 |
> |
target_p->localClient->serial = current_serial; |
520 |
|
send_message(target_p, buffer, len); |
521 |
|
} |
522 |
|
} |
523 |
|
|
524 |
|
if (touser && MyConnect(user) && !IsDead(user) && |
525 |
< |
user->serial != current_serial) |
526 |
< |
send_message(user, buffer, len); |
525 |
> |
user->localClient->serial != current_serial) |
526 |
> |
if (HasCap(user, cap) == cap) |
527 |
> |
send_message(user, buffer, len); |
528 |
|
} |
529 |
|
|
530 |
|
/* sendto_channel_local() |
538 |
|
* locally connected to this server. |
539 |
|
*/ |
540 |
|
void |
541 |
< |
sendto_channel_local(int type, int nodeaf, struct Channel *chptr, |
541 |
> |
sendto_channel_local(unsigned int type, int nodeaf, struct Channel *chptr, |
542 |
|
const char *pattern, ...) |
543 |
|
{ |
544 |
|
va_list args; |
545 |
|
char buffer[IRCD_BUFSIZE]; |
546 |
< |
int len; |
547 |
< |
dlink_node *ptr; |
662 |
< |
struct Membership *ms; |
663 |
< |
struct Client *target_p; |
546 |
> |
int len = 0; |
547 |
> |
dlink_node *ptr = NULL; |
548 |
|
|
549 |
|
va_start(args, pattern); |
550 |
< |
len = send_format(buffer, IRCD_BUFSIZE, pattern, args); |
550 |
> |
len = send_format(buffer, sizeof(buffer), pattern, args); |
551 |
|
va_end(args); |
552 |
|
|
553 |
|
DLINK_FOREACH(ptr, chptr->members.head) |
554 |
|
{ |
555 |
< |
ms = ptr->data; |
556 |
< |
target_p = ms->client_p; |
555 |
> |
struct Membership *ms = ptr->data; |
556 |
> |
struct Client *target_p = ms->client_p; |
557 |
|
|
558 |
|
if (type != 0 && (ms->flags & type) == 0) |
559 |
|
continue; |
560 |
|
|
561 |
|
if (!MyConnect(target_p) || IsDefunct(target_p) || |
562 |
< |
(nodeaf && IsDeaf(target_p))) |
562 |
> |
(nodeaf && HasUMode(target_p, UMODE_DEAF))) |
563 |
|
continue; |
564 |
|
|
565 |
|
send_message(target_p, buffer, len); |
578 |
|
* |
579 |
|
* WARNING - +D clients are omitted |
580 |
|
*/ |
581 |
< |
void |
582 |
< |
sendto_channel_local_butone(struct Client *one, int type, |
583 |
< |
struct Channel *chptr, const char *pattern, ...) |
581 |
> |
void |
582 |
> |
sendto_channel_local_butone(struct Client *one, unsigned int type, unsigned int cap, |
583 |
> |
struct Channel *chptr, const char *pattern, ...) |
584 |
|
{ |
585 |
|
va_list args; |
586 |
|
char buffer[IRCD_BUFSIZE]; |
587 |
< |
int len; |
588 |
< |
struct Client *target_p; |
705 |
< |
struct Membership *ms; |
706 |
< |
dlink_node *ptr; |
587 |
> |
int len = 0; |
588 |
> |
dlink_node *ptr = NULL; |
589 |
|
|
590 |
< |
va_start(args, pattern); |
591 |
< |
len = send_format(buffer, IRCD_BUFSIZE, pattern, args); |
590 |
> |
va_start(args, pattern); |
591 |
> |
len = send_format(buffer, sizeof(buffer), pattern, args); |
592 |
|
va_end(args); |
593 |
|
|
594 |
< |
DLINK_FOREACH(ptr, chptr->members.head) |
595 |
< |
{ |
596 |
< |
ms = ptr->data; |
597 |
< |
target_p = ms->client_p; |
594 |
> |
DLINK_FOREACH(ptr, chptr->members.head) |
595 |
> |
{ |
596 |
> |
struct Membership *ms = ptr->data; |
597 |
> |
struct Client *target_p = ms->client_p; |
598 |
|
|
599 |
|
if (type != 0 && (ms->flags & type) == 0) |
600 |
|
continue; |
601 |
|
|
602 |
|
if (!MyConnect(target_p) || target_p == one || |
603 |
< |
IsDefunct(target_p) || IsDeaf(target_p)) |
603 |
> |
IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF)) |
604 |
|
continue; |
605 |
+ |
|
606 |
+ |
if (HasCap(target_p, cap) != cap) |
607 |
+ |
continue; |
608 |
+ |
|
609 |
|
send_message(target_p, buffer, len); |
610 |
|
} |
611 |
|
} |
623 |
|
* remote to this server. |
624 |
|
*/ |
625 |
|
void |
626 |
< |
sendto_channel_remote(struct Client *one, struct Client *from, int type, int caps, |
627 |
< |
int nocaps, struct Channel *chptr, const char *pattern, ...) |
626 |
> |
sendto_channel_remote(struct Client *one, struct Client *from, unsigned int type, |
627 |
> |
const unsigned int caps, const unsigned int nocaps, |
628 |
> |
struct Channel *chptr, const char *pattern, ...) |
629 |
|
{ |
630 |
|
va_list args; |
631 |
|
char buffer[IRCD_BUFSIZE]; |
632 |
< |
int len; |
633 |
< |
dlink_node *ptr; |
747 |
< |
struct Client *target_p; |
748 |
< |
struct Membership *ms; |
632 |
> |
int len = 0; |
633 |
> |
dlink_node *ptr = NULL; |
634 |
|
|
635 |
|
va_start(args, pattern); |
636 |
< |
len = send_format(buffer, IRCD_BUFSIZE, pattern, args); |
636 |
> |
len = send_format(buffer, sizeof(buffer), pattern, args); |
637 |
|
va_end(args); |
638 |
|
|
639 |
|
++current_serial; |
640 |
|
|
641 |
|
DLINK_FOREACH(ptr, chptr->members.head) |
642 |
|
{ |
643 |
< |
ms = ptr->data; |
644 |
< |
target_p = ms->client_p; |
643 |
> |
struct Membership *ms = ptr->data; |
644 |
> |
struct Client *target_p = ms->client_p; |
645 |
|
|
646 |
|
if (type != 0 && (ms->flags & type) == 0) |
647 |
|
continue; |
648 |
|
|
649 |
|
if (MyConnect(target_p)) |
650 |
|
continue; |
651 |
+ |
|
652 |
|
target_p = target_p->from; |
653 |
|
|
654 |
|
if (target_p == one->from || |
655 |
|
((target_p->from->localClient->caps & caps) != caps) || |
656 |
|
((target_p->from->localClient->caps & nocaps) != 0)) |
657 |
|
continue; |
658 |
< |
if (target_p->from->serial != current_serial) |
658 |
> |
|
659 |
> |
if (target_p->from->localClient->serial != current_serial) |
660 |
|
{ |
661 |
|
send_message(target_p, buffer, len); |
662 |
< |
target_p->from->serial = current_serial; |
662 |
> |
target_p->from->localClient->serial = current_serial; |
663 |
|
} |
664 |
< |
} |
664 |
> |
} |
665 |
|
} |
666 |
|
|
667 |
|
/* |
682 |
|
* side effects - NONE |
683 |
|
*/ |
684 |
|
static int |
685 |
< |
match_it(const struct Client *one, const char *mask, int what) |
685 |
> |
match_it(const struct Client *one, const char *mask, unsigned int what) |
686 |
|
{ |
687 |
|
if (what == MATCH_HOST) |
688 |
< |
return(match(mask, one->host)); |
688 |
> |
return !match(mask, one->host); |
689 |
|
|
690 |
< |
return(match(mask, one->servptr->name)); |
690 |
> |
return !match(mask, one->servptr->name); |
691 |
|
} |
692 |
|
|
693 |
|
/* sendto_match_butone() |
705 |
|
struct Client *client_p; |
706 |
|
dlink_node *ptr, *ptr_next; |
707 |
|
char local_buf[IRCD_BUFSIZE], remote_buf[IRCD_BUFSIZE]; |
708 |
< |
int local_len = ircsprintf(local_buf, ":%s!%s@%s ", from->name, |
709 |
< |
from->username, from->host); |
710 |
< |
int remote_len = ircsprintf(remote_buf, ":%s ", from->name); |
708 |
> |
int local_len = snprintf(local_buf, sizeof(local_buf), ":%s!%s@%s ", |
709 |
> |
from->name, from->username, from->host); |
710 |
> |
int remote_len = snprintf(remote_buf, sizeof(remote_buf), ":%s ", |
711 |
> |
from->name); |
712 |
|
|
713 |
|
va_start(alocal, pattern); |
714 |
|
va_start(aremote, pattern); |
773 |
|
* side effects - data sent to servers matching with capab |
774 |
|
*/ |
775 |
|
void |
776 |
< |
sendto_match_servs(struct Client *source_p, const char *mask, int cap, |
776 |
> |
sendto_match_servs(struct Client *source_p, const char *mask, unsigned int cap, |
777 |
|
const char *pattern, ...) |
778 |
|
{ |
779 |
|
va_list args; |
780 |
< |
struct Client *target_p; |
781 |
< |
dlink_node *ptr; |
782 |
< |
char buffer[IRCD_BUFSIZE]; |
783 |
< |
int found = 0; |
780 |
> |
dlink_node *ptr = NULL; |
781 |
> |
char buff_suid[IRCD_BUFSIZE]; |
782 |
> |
char buff_name[IRCD_BUFSIZE]; |
783 |
> |
int len_suid = 0; |
784 |
> |
int len_name = 0; |
785 |
|
|
786 |
|
va_start(args, pattern); |
787 |
< |
vsnprintf(buffer, sizeof(buffer), pattern, args); |
787 |
> |
len_suid = snprintf(buff_suid, sizeof(buff_suid), ":%s ", ID(source_p)); |
788 |
> |
len_suid += send_format(&buff_suid[len_suid], sizeof(buff_suid) - len_suid, |
789 |
> |
pattern, args); |
790 |
|
va_end(args); |
791 |
|
|
792 |
< |
current_serial++; |
792 |
> |
va_start(args, pattern); |
793 |
> |
len_name = snprintf(buff_name, sizeof(buff_name), ":%s ", source_p->name); |
794 |
> |
len_name += send_format(&buff_name[len_name], sizeof(buff_name) - len_name, |
795 |
> |
pattern, args); |
796 |
> |
va_end(args); |
797 |
> |
|
798 |
> |
++current_serial; |
799 |
|
|
800 |
|
DLINK_FOREACH(ptr, global_serv_list.head) |
801 |
|
{ |
802 |
< |
target_p = ptr->data; |
802 |
> |
struct Client *target_p = ptr->data; |
803 |
|
|
804 |
|
/* Do not attempt to send to ourselves, or the source */ |
805 |
|
if (IsMe(target_p) || target_p->from == source_p->from) |
806 |
|
continue; |
807 |
|
|
808 |
< |
if (target_p->from->serial == current_serial) |
808 |
> |
if (target_p->from->localClient->serial == current_serial) |
809 |
|
continue; |
810 |
|
|
811 |
< |
if (match(mask, target_p->name)) |
811 |
> |
if (!match(mask, target_p->name)) |
812 |
|
{ |
813 |
|
/* |
814 |
|
* if we set the serial here, then we'll never do a |
815 |
|
* match() again, if !IsCapable() |
816 |
|
*/ |
817 |
< |
target_p->from->serial = current_serial; |
921 |
< |
found++; |
817 |
> |
target_p->from->localClient->serial = current_serial; |
818 |
|
|
819 |
|
if (!IsCapable(target_p->from, cap)) |
820 |
|
continue; |
821 |
|
|
822 |
< |
sendto_anywhere(target_p, source_p, "%s", buffer); |
822 |
> |
if (HasID(target_p->from)) |
823 |
> |
send_message_remote(target_p->from, source_p, buff_suid, len_suid); |
824 |
> |
else |
825 |
> |
send_message_remote(target_p->from, source_p, buff_name, len_name); |
826 |
|
} |
827 |
|
} |
828 |
|
} |
838 |
|
*/ |
839 |
|
void |
840 |
|
sendto_anywhere(struct Client *to, struct Client *from, |
841 |
+ |
const char *command, |
842 |
|
const char *pattern, ...) |
843 |
|
{ |
844 |
|
va_list args; |
845 |
|
char buffer[IRCD_BUFSIZE]; |
846 |
< |
int len; |
947 |
< |
struct Client *send_to = (to->from != NULL ? to->from : to); |
846 |
> |
int len = 0; |
847 |
|
|
848 |
< |
if (IsDead(send_to)) |
848 |
> |
if (IsDead(to->from)) |
849 |
|
return; |
850 |
|
|
851 |
|
if (MyClient(to)) |
852 |
|
{ |
853 |
|
if (IsServer(from)) |
854 |
< |
{ |
855 |
< |
if (IsCapable(to, CAP_TS6) && HasID(from)) |
957 |
< |
len = ircsprintf(buffer, ":%s ", from->id); |
958 |
< |
else |
959 |
< |
len = ircsprintf(buffer, ":%s ", from->name); |
960 |
< |
} |
854 |
> |
len = snprintf(buffer, sizeof(buffer), ":%s %s %s ", |
855 |
> |
from->name, command, to->name); |
856 |
|
else |
857 |
< |
len = ircsprintf(buffer, ":%s!%s@%s ", |
858 |
< |
from->name, from->username, from->host); |
857 |
> |
len = snprintf(buffer, sizeof(buffer), ":%s!%s@%s %s %s ", |
858 |
> |
from->name, from->username, from->host, command, to->name); |
859 |
|
} |
860 |
< |
else len = ircsprintf(buffer, ":%s ", ID_or_name(from, send_to)); |
860 |
> |
else |
861 |
> |
len = snprintf(buffer, sizeof(buffer), ":%s %s %s ", |
862 |
> |
ID_or_name(from, to), command, |
863 |
> |
ID_or_name(to, to)); |
864 |
|
|
865 |
|
va_start(args, pattern); |
866 |
< |
len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args); |
866 |
> |
len += send_format(&buffer[len], sizeof(buffer) - len, pattern, args); |
867 |
|
va_end(args); |
868 |
|
|
869 |
< |
if(MyClient(to)) |
870 |
< |
send_message(send_to, buffer, len); |
869 |
> |
if (MyClient(to)) |
870 |
> |
send_message(to, buffer, len); |
871 |
|
else |
872 |
< |
send_message_remote(send_to, from, buffer, len); |
872 |
> |
send_message_remote(to, from, buffer, len); |
873 |
|
} |
874 |
|
|
875 |
|
/* sendto_realops_flags() |
881 |
|
* side effects - Send to *local* ops only but NOT +s nonopers. |
882 |
|
*/ |
883 |
|
void |
884 |
< |
sendto_realops_flags(unsigned int flags, int level, const char *pattern, ...) |
884 |
> |
sendto_realops_flags(unsigned int flags, int level, int type, const char *pattern, ...) |
885 |
|
{ |
886 |
< |
struct Client *client_p; |
886 |
> |
const char *ntype = NULL; |
887 |
> |
dlink_node *ptr = NULL; |
888 |
|
char nbuf[IRCD_BUFSIZE]; |
990 |
– |
dlink_node *ptr; |
889 |
|
va_list args; |
890 |
|
|
891 |
|
va_start(args, pattern); |
892 |
< |
vsnprintf(nbuf, IRCD_BUFSIZE, pattern, args); |
892 |
> |
vsnprintf(nbuf, sizeof(nbuf), pattern, args); |
893 |
|
va_end(args); |
894 |
|
|
895 |
+ |
switch (type) |
896 |
+ |
{ |
897 |
+ |
case SEND_NOTICE: |
898 |
+ |
ntype = "Notice"; |
899 |
+ |
break; |
900 |
+ |
case SEND_GLOBAL: |
901 |
+ |
ntype = "Global"; |
902 |
+ |
break; |
903 |
+ |
case SEND_LOCOPS: |
904 |
+ |
ntype = "LocOps"; |
905 |
+ |
break; |
906 |
+ |
default: |
907 |
+ |
assert(0); |
908 |
+ |
} |
909 |
+ |
|
910 |
|
DLINK_FOREACH(ptr, oper_list.head) |
911 |
|
{ |
912 |
< |
client_p = ptr->data; |
913 |
< |
assert(client_p->umodes & UMODE_OPER); |
912 |
> |
struct Client *client_p = ptr->data; |
913 |
> |
assert(HasUMode(client_p, UMODE_OPER)); |
914 |
|
|
915 |
< |
/* If we're sending it to opers and theyre an admin, skip. |
916 |
< |
* If we're sending it to admins, and theyre not, skip. |
915 |
> |
/* |
916 |
> |
* If we're sending it to opers and they're an admin, skip. |
917 |
> |
* If we're sending it to admins, and they're not, skip. |
918 |
|
*/ |
919 |
< |
if (((level == L_ADMIN) && !IsAdmin(client_p)) || |
920 |
< |
((level == L_OPER) && IsAdmin(client_p))) |
919 |
> |
if (((level == L_ADMIN) && !HasUMode(client_p, UMODE_ADMIN)) || |
920 |
> |
((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN))) |
921 |
|
continue; |
922 |
|
|
923 |
< |
if (client_p->umodes & flags) |
924 |
< |
sendto_one(client_p, ":%s NOTICE %s :*** Notice -- %s", |
925 |
< |
me.name, client_p->name, nbuf); |
923 |
> |
if (HasUMode(client_p, flags)) |
924 |
> |
sendto_one(client_p, ":%s NOTICE %s :*** %s -- %s", |
925 |
> |
me.name, client_p->name, ntype, nbuf); |
926 |
|
} |
927 |
|
} |
928 |
|
|
938 |
|
sendto_wallops_flags(unsigned int flags, struct Client *source_p, |
939 |
|
const char *pattern, ...) |
940 |
|
{ |
941 |
< |
struct Client *client_p; |
1028 |
< |
dlink_node *ptr; |
941 |
> |
dlink_node *ptr = NULL; |
942 |
|
va_list args; |
943 |
|
char buffer[IRCD_BUFSIZE]; |
944 |
|
int len; |
945 |
|
|
946 |
|
if (IsClient(source_p)) |
947 |
< |
len = ircsprintf(buffer, ":%s!%s@%s WALLOPS :", |
948 |
< |
source_p->name, source_p->username, source_p->host); |
947 |
> |
len = snprintf(buffer, sizeof(buffer), ":%s!%s@%s WALLOPS :", |
948 |
> |
source_p->name, source_p->username, |
949 |
> |
source_p->host); |
950 |
|
else |
951 |
< |
len = ircsprintf(buffer, ":%s WALLOPS :", source_p->name); |
951 |
> |
len = snprintf(buffer, sizeof(buffer), ":%s WALLOPS :", |
952 |
> |
source_p->name); |
953 |
|
|
954 |
|
va_start(args, pattern); |
955 |
|
len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args); |
957 |
|
|
958 |
|
DLINK_FOREACH(ptr, oper_list.head) |
959 |
|
{ |
960 |
< |
client_p = ptr->data; |
960 |
> |
struct Client *client_p = ptr->data; |
961 |
|
assert(client_p->umodes & UMODE_OPER); |
962 |
|
|
963 |
< |
if ((client_p->umodes & flags) && !IsDefunct(client_p)) |
963 |
> |
if (HasUMode(client_p, flags) && !IsDefunct(client_p)) |
964 |
|
send_message(client_p, buffer, len); |
965 |
|
} |
966 |
|
} |
976 |
|
ts_warn(const char *pattern, ...) |
977 |
|
{ |
978 |
|
va_list args; |
979 |
< |
char buffer[LOG_BUFSIZE]; |
979 |
> |
char buffer[IRCD_BUFSIZE]; |
980 |
|
static time_t last = 0; |
981 |
|
static int warnings = 0; |
982 |
|
|
999 |
|
} |
1000 |
|
|
1001 |
|
va_start(args, pattern); |
1002 |
< |
vsprintf_irc(buffer, pattern, args); |
1002 |
> |
vsnprintf(buffer, sizeof(buffer), pattern, args); |
1003 |
|
va_end(args); |
1004 |
|
|
1005 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, "%s", buffer); |
1006 |
< |
ilog(L_CRIT, "%s", buffer); |
1005 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, "%s", buffer); |
1006 |
> |
ilog(LOG_TYPE_IRCD, "%s", buffer); |
1007 |
|
} |
1008 |
|
|
1009 |
|
/* kill_client() |
1027 |
|
if (IsDead(client_p)) |
1028 |
|
return; |
1029 |
|
|
1030 |
< |
len = ircsprintf(buffer, ":%s KILL %s :", ID_or_name(&me, client_p->from), |
1031 |
< |
ID_or_name(diedie, client_p)); |
1030 |
> |
len = snprintf(buffer, sizeof(buffer), ":%s KILL %s :", |
1031 |
> |
ID_or_name(&me, client_p->from), |
1032 |
> |
ID_or_name(diedie, client_p)); |
1033 |
|
|
1034 |
|
va_start(args, pattern); |
1035 |
|
len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args); |
1049 |
|
* client being unknown to leaf, as in lazylink... |
1050 |
|
*/ |
1051 |
|
void |
1052 |
< |
kill_client_ll_serv_butone(struct Client *one, struct Client *source_p, |
1053 |
< |
const char *pattern, ...) |
1052 |
> |
kill_client_serv_butone(struct Client *one, struct Client *source_p, |
1053 |
> |
const char *pattern, ...) |
1054 |
|
{ |
1055 |
|
va_list args; |
1056 |
|
int have_uid = 0; |
1058 |
|
char buf_uid[IRCD_BUFSIZE], buf_nick[IRCD_BUFSIZE]; |
1059 |
|
int len_uid = 0, len_nick = 0; |
1060 |
|
|
1061 |
< |
if (HasID(source_p) && (me.id[0] != '\0')) |
1061 |
> |
if (HasID(source_p)) |
1062 |
|
{ |
1063 |
|
have_uid = 1; |
1064 |
|
va_start(args, pattern); |
1065 |
< |
len_uid = ircsprintf(buf_uid, ":%s KILL %s :", me.id, ID(source_p)); |
1066 |
< |
len_uid += send_format(&buf_uid[len_uid], IRCD_BUFSIZE - len_uid, pattern, |
1067 |
< |
args); |
1065 |
> |
len_uid = snprintf(buf_uid, sizeof(buf_uid), ":%s KILL %s :", |
1066 |
> |
me.id, ID(source_p)); |
1067 |
> |
len_uid += send_format(&buf_uid[len_uid], IRCD_BUFSIZE - len_uid, pattern, args); |
1068 |
|
va_end(args); |
1069 |
|
} |
1070 |
|
|
1071 |
|
va_start(args, pattern); |
1072 |
< |
len_nick = ircsprintf(buf_nick, ":%s KILL %s :", me.name, source_p->name); |
1073 |
< |
len_nick += send_format(&buf_nick[len_nick], IRCD_BUFSIZE - len_nick, pattern, |
1074 |
< |
args); |
1072 |
> |
len_nick = snprintf(buf_nick, sizeof(buf_nick), ":%s KILL %s :", |
1073 |
> |
me.name, source_p->name); |
1074 |
> |
len_nick += send_format(&buf_nick[len_nick], IRCD_BUFSIZE - len_nick, pattern, args); |
1075 |
|
va_end(args); |
1076 |
|
|
1077 |
|
DLINK_FOREACH(ptr, serv_list.head) |
1088 |
|
else |
1089 |
|
send_message(client_p, buf_nick, len_nick); |
1090 |
|
} |
1091 |
< |
} |
1091 |
> |
} |