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" |
39 |
< |
#include "s_log.h" |
38 |
> |
#include "conf.h" |
39 |
> |
#include "log.h" |
40 |
|
#include "memory.h" |
41 |
|
#include "hook.h" |
42 |
|
#include "packet.h" |
43 |
|
|
44 |
|
|
45 |
|
struct Callback *iosend_cb = NULL; |
48 |
– |
struct Callback *iosendctrl_cb = NULL; |
46 |
|
static unsigned int current_serial = 0; |
47 |
|
|
48 |
|
|
106 |
|
assert(!IsMe(to)); |
107 |
|
assert(to != &me); |
108 |
|
|
109 |
< |
if (dbuf_length(&to->localClient->buf_sendq) + len > get_sendq(to)) |
109 |
> |
if (dbuf_length(&to->localClient->buf_sendq) + len > get_sendq(&to->localClient->confs)) |
110 |
|
{ |
111 |
|
if (IsServer(to)) |
112 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
112 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
113 |
|
"Max SendQ limit exceeded for %s: %lu > %lu", |
114 |
|
get_client_name(to, HIDE_IP), |
115 |
|
(unsigned long)(dbuf_length(&to->localClient->buf_sendq) + len), |
116 |
< |
get_sendq(to)); |
116 |
> |
get_sendq(&to->localClient->confs)); |
117 |
|
if (IsClient(to)) |
118 |
|
SetSendQExceeded(to); |
119 |
|
dead_link_on_write(to, 0); |
152 |
|
{ |
153 |
|
if (!MyConnect(to)) |
154 |
|
{ |
155 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
155 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
156 |
|
"server send message to %s [%s] dropped from %s(Not local server)", |
157 |
|
to->name, to->from->name, from->name); |
158 |
|
return; |
165 |
|
{ |
166 |
|
if (IsServer(from)) |
167 |
|
{ |
168 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
168 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
169 |
|
"Send message to %s [%s] dropped from %s(Fake Dir)", |
170 |
|
to->name, to->from->name, from->name); |
171 |
|
return; |
172 |
|
} |
173 |
|
|
174 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
174 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
175 |
|
"Ghosted: %s[%s@%s] from %s[%s@%s] (%s)", |
176 |
|
to->name, to->username, to->host, |
177 |
|
from->name, from->username, from->host, |
178 |
|
to->from->name); |
179 |
|
|
180 |
< |
sendto_server(NULL, NULL, CAP_TS6, NOCAPS, |
180 |
> |
sendto_server(NULL, CAP_TS6, NOCAPS, |
181 |
|
":%s KILL %s :%s (%s[%s@%s] Ghosted %s)", |
182 |
|
me.id, to->name, me.name, to->name, |
183 |
|
to->username, to->host, to->from->name); |
184 |
< |
sendto_server(NULL, NULL, NOCAPS, CAP_TS6, |
184 |
> |
sendto_server(NULL, NOCAPS, CAP_TS6, |
185 |
|
":%s KILL %s :%s (%s[%s@%s] Ghosted %s)", |
186 |
|
me.name, to->name, me.name, to->name, |
187 |
|
to->username, to->host, to->from->name); |
188 |
|
|
189 |
< |
SetKilled(to); |
189 |
> |
AddFlag(to, FLAGS_KILLED); |
190 |
|
|
191 |
|
if (IsClient(from)) |
192 |
|
sendto_one(from, form_str(ERR_GHOSTEDCLIENT), |
221 |
|
} |
222 |
|
|
223 |
|
/* |
227 |
– |
** slinkq_unblocked |
228 |
– |
** Called when a server control socket is ready for writing. |
229 |
– |
*/ |
230 |
– |
static void |
231 |
– |
slinkq_unblocked(fde_t *fd, struct Client *client_p) |
232 |
– |
{ |
233 |
– |
ClearSlinkqBlocked(client_p); |
234 |
– |
send_queued_slink_write(client_p); |
235 |
– |
} |
236 |
– |
|
237 |
– |
/* |
224 |
|
** send_queued_write |
225 |
|
** This is called when there is a chance that some output would |
226 |
|
** be possible. This attempts to empty the send queue as far as |
298 |
|
} |
299 |
|
} |
300 |
|
|
315 |
– |
/* |
316 |
– |
** send_queued_slink_write |
317 |
– |
** This is called when there is a chance the some output would |
318 |
– |
** be possible. This attempts to empty the send queue as far as |
319 |
– |
** possible, and then if any data is left, a write is rescheduled. |
320 |
– |
*/ |
321 |
– |
void |
322 |
– |
send_queued_slink_write(struct Client *to) |
323 |
– |
{ |
324 |
– |
int retlen; |
325 |
– |
|
326 |
– |
/* |
327 |
– |
** Once socket is marked dead, we cannot start writing to it, |
328 |
– |
** even if the error is removed... |
329 |
– |
*/ |
330 |
– |
if (IsDead(to) || IsSlinkqBlocked(to)) |
331 |
– |
return; /* no use calling send() now */ |
332 |
– |
|
333 |
– |
/* Next, lets try to write some data */ |
334 |
– |
if (to->localClient->slinkq != NULL) |
335 |
– |
{ |
336 |
– |
retlen = send(to->localClient->ctrlfd.fd, |
337 |
– |
to->localClient->slinkq + to->localClient->slinkq_ofs, |
338 |
– |
to->localClient->slinkq_len, 0); |
339 |
– |
if (retlen < 0) |
340 |
– |
{ |
341 |
– |
/* If we have a fatal error */ |
342 |
– |
if (!ignoreErrno(errno)) |
343 |
– |
{ |
344 |
– |
dead_link_on_write(to, errno); |
345 |
– |
return; |
346 |
– |
} |
347 |
– |
} |
348 |
– |
else if (retlen == 0) |
349 |
– |
{ |
350 |
– |
/* 0 bytes is an EOF .. */ |
351 |
– |
dead_link_on_write(to, 0); |
352 |
– |
return; |
353 |
– |
} |
354 |
– |
else |
355 |
– |
{ |
356 |
– |
execute_callback(iosendctrl_cb, to, retlen, |
357 |
– |
to->localClient->slinkq + to->localClient->slinkq_ofs); |
358 |
– |
to->localClient->slinkq_len -= retlen; |
359 |
– |
|
360 |
– |
assert(to->localClient->slinkq_len >= 0); |
361 |
– |
if (to->localClient->slinkq_len) |
362 |
– |
to->localClient->slinkq_ofs += retlen; |
363 |
– |
else |
364 |
– |
{ |
365 |
– |
to->localClient->slinkq_ofs = 0; |
366 |
– |
MyFree(to->localClient->slinkq); |
367 |
– |
to->localClient->slinkq = NULL; |
368 |
– |
} |
369 |
– |
} |
370 |
– |
|
371 |
– |
/* Finally, if we have any more data, reschedule a write */ |
372 |
– |
if (to->localClient->slinkq_len) |
373 |
– |
{ |
374 |
– |
SetSlinkqBlocked(to); |
375 |
– |
comm_setselect(&to->localClient->ctrlfd, COMM_SELECT_WRITE, |
376 |
– |
(PF *)slinkq_unblocked, (void *)to, 0); |
377 |
– |
} |
378 |
– |
} |
379 |
– |
} |
380 |
– |
|
301 |
|
/* send_queued_all() |
302 |
|
* |
303 |
|
* input - NONE |
368 |
|
*/ |
369 |
|
void |
370 |
|
sendto_channel_butone(struct Client *one, struct Client *from, |
371 |
< |
struct Channel *chptr, const char *command, |
371 |
> |
struct Channel *chptr, unsigned int type, |
372 |
|
const char *pattern, ...) |
373 |
|
{ |
374 |
|
va_list alocal, aremote, auid; |
379 |
|
dlink_node *ptr = NULL, *ptr_next = NULL; |
380 |
|
|
381 |
|
if (IsServer(from)) |
382 |
< |
local_len = ircsprintf(local_buf, ":%s %s %s ", |
383 |
< |
from->name, command, chptr->chname); |
382 |
> |
local_len = ircsprintf(local_buf, ":%s ", |
383 |
> |
from->name); |
384 |
|
else |
385 |
< |
local_len = ircsprintf(local_buf, ":%s!%s@%s %s %s ", |
386 |
< |
from->name, from->username, from->host, |
387 |
< |
command, chptr->chname); |
388 |
< |
remote_len = ircsprintf(remote_buf, ":%s %s %s ", |
389 |
< |
from->name, command, chptr->chname); |
390 |
< |
uid_len = ircsprintf(uid_buf, ":%s %s %s ", |
471 |
< |
ID(from), command, chptr->chname); |
385 |
> |
local_len = ircsprintf(local_buf, ":%s!%s@%s ", |
386 |
> |
from->name, from->username, from->host); |
387 |
> |
remote_len = ircsprintf(remote_buf, ":%s ", |
388 |
> |
from->name); |
389 |
> |
uid_len = ircsprintf(uid_buf, ":%s ", |
390 |
> |
ID(from)); |
391 |
|
|
392 |
|
va_start(alocal, pattern); |
393 |
|
va_start(aremote, pattern); |
406 |
|
|
407 |
|
DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->members.head) |
408 |
|
{ |
409 |
< |
struct Client *target_p = ((struct Membership *)ptr->data)->client_p; |
409 |
> |
struct Membership *ms = ptr->data; |
410 |
> |
struct Client *target_p = ms->client_p; |
411 |
|
|
412 |
|
assert(IsClient(target_p)); |
413 |
|
|
414 |
< |
if (IsDefunct(target_p) || IsDeaf(target_p) || target_p->from == one) |
414 |
> |
if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF) || target_p->from == one) |
415 |
> |
continue; |
416 |
> |
|
417 |
> |
if (type != 0 && (ms->flags & type) == 0) |
418 |
|
continue; |
419 |
|
|
420 |
|
if (MyConnect(target_p)) |
461 |
|
* -davidt |
462 |
|
*/ |
463 |
|
void |
464 |
< |
sendto_server(struct Client *one, const struct Channel *chptr, |
464 |
> |
sendto_server(struct Client *one, |
465 |
|
const unsigned int caps, |
466 |
|
const unsigned int nocaps, |
467 |
|
const char *format, ...) |
471 |
|
char buffer[IRCD_BUFSIZE]; |
472 |
|
int len = 0; |
473 |
|
|
551 |
– |
if (chptr && chptr->chname[0] != '#') |
552 |
– |
return; |
553 |
– |
|
474 |
|
va_start(args, format); |
475 |
|
len = send_format(buffer, IRCD_BUFSIZE, format, args); |
476 |
|
va_end(args); |
583 |
|
continue; |
584 |
|
|
585 |
|
if (!MyConnect(target_p) || IsDefunct(target_p) || |
586 |
< |
(nodeaf && IsDeaf(target_p))) |
586 |
> |
(nodeaf && HasUMode(target_p, UMODE_DEAF))) |
587 |
|
continue; |
588 |
|
|
589 |
|
send_message(target_p, buffer, len); |
626 |
|
continue; |
627 |
|
|
628 |
|
if (!MyConnect(target_p) || target_p == one || |
629 |
< |
IsDefunct(target_p) || IsDeaf(target_p)) |
629 |
> |
IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF)) |
630 |
|
continue; |
631 |
|
send_message(target_p, buffer, len); |
632 |
|
} |
707 |
|
match_it(const struct Client *one, const char *mask, int what) |
708 |
|
{ |
709 |
|
if (what == MATCH_HOST) |
710 |
< |
return match(mask, one->host); |
710 |
> |
return !match(mask, one->host); |
711 |
|
|
712 |
< |
return match(mask, one->servptr->name); |
712 |
> |
return !match(mask, one->servptr->name); |
713 |
|
} |
714 |
|
|
715 |
|
/* sendto_match_butone() |
820 |
|
if (target_p->from->localClient->serial == current_serial) |
821 |
|
continue; |
822 |
|
|
823 |
< |
if (match(mask, target_p->name)) |
823 |
> |
if (!match(mask, target_p->name)) |
824 |
|
{ |
825 |
|
/* |
826 |
|
* if we set the serial here, then we'll never do a |
892 |
|
* side effects - Send to *local* ops only but NOT +s nonopers. |
893 |
|
*/ |
894 |
|
void |
895 |
< |
sendto_realops_flags(unsigned int flags, int level, const char *pattern, ...) |
895 |
> |
sendto_realops_flags(unsigned int flags, int level, int type, const char *pattern, ...) |
896 |
|
{ |
897 |
+ |
const char *ntype = NULL; |
898 |
|
dlink_node *ptr = NULL; |
899 |
|
char nbuf[IRCD_BUFSIZE]; |
900 |
|
va_list args; |
901 |
|
|
902 |
|
va_start(args, pattern); |
903 |
< |
vsnprintf(nbuf, IRCD_BUFSIZE, pattern, args); |
903 |
> |
vsnprintf(nbuf, sizeof(nbuf), pattern, args); |
904 |
|
va_end(args); |
905 |
|
|
906 |
< |
DLINK_FOREACH(ptr, oper_list.head) |
906 |
> |
switch (type) |
907 |
|
{ |
908 |
< |
struct Client *client_p = ptr->data; |
909 |
< |
assert(client_p->umodes & UMODE_OPER); |
910 |
< |
|
911 |
< |
/* If we're sending it to opers and theyre an admin, skip. |
912 |
< |
* If we're sending it to admins, and theyre not, skip. |
913 |
< |
*/ |
914 |
< |
if (((level == L_ADMIN) && !IsAdmin(client_p)) || |
915 |
< |
((level == L_OPER) && IsAdmin(client_p))) |
916 |
< |
continue; |
917 |
< |
|
918 |
< |
if (client_p->umodes & flags) |
998 |
< |
sendto_one(client_p, ":%s NOTICE %s :*** Notice -- %s", |
999 |
< |
me.name, client_p->name, nbuf); |
908 |
> |
case SEND_NOTICE: |
909 |
> |
ntype = "Notice"; |
910 |
> |
break; |
911 |
> |
case SEND_GLOBAL: |
912 |
> |
ntype = "Global"; |
913 |
> |
break; |
914 |
> |
case SEND_LOCOPS: |
915 |
> |
ntype = "LocOps"; |
916 |
> |
break; |
917 |
> |
default: |
918 |
> |
assert(0); |
919 |
|
} |
1001 |
– |
} |
1002 |
– |
|
1003 |
– |
void |
1004 |
– |
sendto_globops_flags(unsigned int flags, int level, const char *pattern, ...) |
1005 |
– |
{ |
1006 |
– |
dlink_node *ptr = NULL; |
1007 |
– |
char nbuf[IRCD_BUFSIZE]; |
1008 |
– |
va_list args; |
1009 |
– |
|
1010 |
– |
va_start(args, pattern); |
1011 |
– |
vsnprintf(nbuf, IRCD_BUFSIZE, pattern, args); |
1012 |
– |
va_end(args); |
920 |
|
|
921 |
|
DLINK_FOREACH(ptr, oper_list.head) |
922 |
|
{ |
923 |
|
struct Client *client_p = ptr->data; |
924 |
< |
assert(client_p->umodes & UMODE_OPER); |
924 |
> |
assert(HasUMode(client_p, UMODE_OPER)); |
925 |
|
|
926 |
< |
/* If we're sending it to opers and theyre an admin, skip. |
927 |
< |
* If we're sending it to admins, and theyre not, skip. |
926 |
> |
/* |
927 |
> |
* If we're sending it to opers and they're an admin, skip. |
928 |
> |
* If we're sending it to admins, and they're not, skip. |
929 |
|
*/ |
930 |
< |
if (((level == L_ADMIN) && !IsAdmin(client_p)) || |
931 |
< |
((level == L_OPER) && IsAdmin(client_p))) |
930 |
> |
if (((level == L_ADMIN) && !HasUMode(client_p, UMODE_ADMIN)) || |
931 |
> |
((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN))) |
932 |
|
continue; |
933 |
|
|
934 |
< |
if (client_p->umodes & flags) |
935 |
< |
sendto_one(client_p, ":%s NOTICE %s :*** Global -- %s", |
936 |
< |
me.name, client_p->name, nbuf); |
934 |
> |
if (HasUMode(client_p, flags)) |
935 |
> |
sendto_one(client_p, ":%s NOTICE %s :*** %s -- %s", |
936 |
> |
me.name, client_p->name, ntype, nbuf); |
937 |
|
} |
938 |
|
} |
939 |
|
|
969 |
|
struct Client *client_p = ptr->data; |
970 |
|
assert(client_p->umodes & UMODE_OPER); |
971 |
|
|
972 |
< |
if ((client_p->umodes & flags) && !IsDefunct(client_p)) |
972 |
> |
if (HasUMode(client_p, flags) && !IsDefunct(client_p)) |
973 |
|
send_message(client_p, buffer, len); |
974 |
|
} |
975 |
|
} |
1011 |
|
vsnprintf(buffer, sizeof(buffer), pattern, args); |
1012 |
|
va_end(args); |
1013 |
|
|
1014 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, "%s", buffer); |
1015 |
< |
ilog(L_CRIT, "%s", buffer); |
1014 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, "%s", buffer); |
1015 |
> |
ilog(LOG_TYPE_IRCD, "%s", buffer); |
1016 |
|
} |
1017 |
|
|
1018 |
|
/* kill_client() |