| 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" |
| 44 |
– |
#include "irc_getnameinfo.h" |
| 42 |
|
#include "packet.h" |
| 43 |
|
|
| 47 |
– |
#define LOG_BUFSIZE 2048 |
| 44 |
|
|
| 45 |
|
struct Callback *iosend_cb = NULL; |
| 50 |
– |
struct Callback *iosendctrl_cb = NULL; |
| 51 |
– |
|
| 52 |
– |
static void send_message(struct Client *, char *, int); |
| 53 |
– |
static void send_message_remote(struct Client *, struct Client *, char *, int); |
| 54 |
– |
|
| 46 |
|
static unsigned int current_serial = 0; |
| 47 |
|
|
| 48 |
+ |
|
| 49 |
|
/* send_format() |
| 50 |
|
* |
| 51 |
|
* inputs - buffer to format into |
| 78 |
|
|
| 79 |
|
lsendbuf[len++] = '\r'; |
| 80 |
|
lsendbuf[len++] = '\n'; |
| 81 |
< |
return (len); |
| 81 |
> |
return len; |
| 82 |
|
} |
| 83 |
|
|
| 84 |
|
/* |
| 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 |
|
/* |
| 232 |
– |
** slinkq_unblocked |
| 233 |
– |
** Called when a server control socket is ready for writing. |
| 234 |
– |
*/ |
| 235 |
– |
static void |
| 236 |
– |
slinkq_unblocked(fde_t *fd, struct Client *client_p) |
| 237 |
– |
{ |
| 238 |
– |
ClearSlinkqBlocked(client_p); |
| 239 |
– |
send_queued_slink_write(client_p); |
| 240 |
– |
} |
| 241 |
– |
|
| 242 |
– |
/* |
| 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 |
|
|
| 320 |
– |
/* |
| 321 |
– |
** send_queued_slink_write |
| 322 |
– |
** This is called when there is a chance the some output would |
| 323 |
– |
** be possible. This attempts to empty the send queue as far as |
| 324 |
– |
** possible, and then if any data is left, a write is rescheduled. |
| 325 |
– |
*/ |
| 326 |
– |
void |
| 327 |
– |
send_queued_slink_write(struct Client *to) |
| 328 |
– |
{ |
| 329 |
– |
int retlen; |
| 330 |
– |
|
| 331 |
– |
/* |
| 332 |
– |
** Once socket is marked dead, we cannot start writing to it, |
| 333 |
– |
** even if the error is removed... |
| 334 |
– |
*/ |
| 335 |
– |
if (IsDead(to) || IsSlinkqBlocked(to)) |
| 336 |
– |
return; /* no use calling send() now */ |
| 337 |
– |
|
| 338 |
– |
/* Next, lets try to write some data */ |
| 339 |
– |
if (to->localClient->slinkq != NULL) |
| 340 |
– |
{ |
| 341 |
– |
retlen = send(to->localClient->ctrlfd.fd, |
| 342 |
– |
to->localClient->slinkq + to->localClient->slinkq_ofs, |
| 343 |
– |
to->localClient->slinkq_len, 0); |
| 344 |
– |
if (retlen < 0) |
| 345 |
– |
{ |
| 346 |
– |
/* If we have a fatal error */ |
| 347 |
– |
if (!ignoreErrno(errno)) |
| 348 |
– |
{ |
| 349 |
– |
dead_link_on_write(to, errno); |
| 350 |
– |
return; |
| 351 |
– |
} |
| 352 |
– |
} |
| 353 |
– |
else if (retlen == 0) |
| 354 |
– |
{ |
| 355 |
– |
/* 0 bytes is an EOF .. */ |
| 356 |
– |
dead_link_on_write(to, 0); |
| 357 |
– |
return; |
| 358 |
– |
} |
| 359 |
– |
else |
| 360 |
– |
{ |
| 361 |
– |
execute_callback(iosendctrl_cb, to, retlen, |
| 362 |
– |
to->localClient->slinkq + to->localClient->slinkq_ofs); |
| 363 |
– |
to->localClient->slinkq_len -= retlen; |
| 364 |
– |
|
| 365 |
– |
assert(to->localClient->slinkq_len >= 0); |
| 366 |
– |
if (to->localClient->slinkq_len) |
| 367 |
– |
to->localClient->slinkq_ofs += retlen; |
| 368 |
– |
else |
| 369 |
– |
{ |
| 370 |
– |
to->localClient->slinkq_ofs = 0; |
| 371 |
– |
MyFree(to->localClient->slinkq); |
| 372 |
– |
to->localClient->slinkq = NULL; |
| 373 |
– |
} |
| 374 |
– |
} |
| 375 |
– |
|
| 376 |
– |
/* Finally, if we have any more data, reschedule a write */ |
| 377 |
– |
if (to->localClient->slinkq_len) |
| 378 |
– |
{ |
| 379 |
– |
SetSlinkqBlocked(to); |
| 380 |
– |
comm_setselect(&to->localClient->ctrlfd, COMM_SELECT_WRITE, |
| 381 |
– |
(PF *)slinkq_unblocked, (void *)to, 0); |
| 382 |
– |
} |
| 383 |
– |
} |
| 384 |
– |
} |
| 385 |
– |
|
| 301 |
|
/* send_queued_all() |
| 302 |
|
* |
| 303 |
|
* input - NONE |
| 376 |
|
char remote_buf[IRCD_BUFSIZE]; |
| 377 |
|
char uid_buf[IRCD_BUFSIZE]; |
| 378 |
|
int local_len, remote_len, uid_len; |
| 379 |
< |
dlink_node *ptr; |
| 465 |
< |
dlink_node *ptr_next; |
| 466 |
< |
struct Client *target_p; |
| 379 |
> |
dlink_node *ptr = NULL, *ptr_next = NULL; |
| 380 |
|
|
| 381 |
|
if (IsServer(from)) |
| 382 |
|
local_len = ircsprintf(local_buf, ":%s %s %s ", |
| 407 |
|
|
| 408 |
|
DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->members.head) |
| 409 |
|
{ |
| 410 |
< |
target_p = ((struct Membership *)ptr->data)->client_p; |
| 498 |
< |
assert(target_p != NULL); |
| 410 |
> |
struct Client *target_p = ((struct Membership *)ptr->data)->client_p; |
| 411 |
|
|
| 412 |
< |
if (IsDefunct(target_p) || IsDeaf(target_p) || target_p->from == one) |
| 412 |
> |
assert(IsClient(target_p)); |
| 413 |
> |
|
| 414 |
> |
if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF) || target_p->from == one) |
| 415 |
|
continue; |
| 416 |
|
|
| 417 |
< |
if (MyClient(target_p)) |
| 417 |
> |
if (MyConnect(target_p)) |
| 418 |
|
{ |
| 419 |
< |
if (target_p->serial != current_serial) |
| 419 |
> |
if (target_p->localClient->serial != current_serial) |
| 420 |
|
{ |
| 421 |
|
send_message(target_p, local_buf, local_len); |
| 422 |
< |
target_p->serial = current_serial; |
| 422 |
> |
target_p->localClient->serial = current_serial; |
| 423 |
|
} |
| 424 |
|
} |
| 425 |
|
else |
| 427 |
|
/* Now check whether a message has been sent to this |
| 428 |
|
* remote link already |
| 429 |
|
*/ |
| 430 |
< |
if (target_p->from->serial != current_serial) |
| 430 |
> |
if (target_p->from->localClient->serial != current_serial) |
| 431 |
|
{ |
| 432 |
|
if (IsCapable(target_p->from, CAP_TS6)) |
| 433 |
|
send_message_remote(target_p->from, from, uid_buf, uid_len); |
| 434 |
|
else |
| 435 |
|
send_message_remote(target_p->from, from, remote_buf, remote_len); |
| 436 |
< |
target_p->from->serial = current_serial; |
| 436 |
> |
target_p->from->localClient->serial = current_serial; |
| 437 |
|
} |
| 438 |
|
} |
| 439 |
|
} |
| 458 |
|
* -davidt |
| 459 |
|
*/ |
| 460 |
|
void |
| 461 |
< |
sendto_server(struct Client *one, |
| 462 |
< |
struct Channel *chptr, unsigned long caps, |
| 463 |
< |
unsigned long nocaps, |
| 461 |
> |
sendto_server(struct Client *one, const struct Channel *chptr, |
| 462 |
> |
const unsigned int caps, |
| 463 |
> |
const unsigned int nocaps, |
| 464 |
|
const char *format, ...) |
| 465 |
|
{ |
| 466 |
|
va_list args; |
| 536 |
|
assert(target_p != NULL); |
| 537 |
|
|
| 538 |
|
if (!MyConnect(target_p) || target_p == user || IsDefunct(target_p) || |
| 539 |
< |
target_p->serial == current_serial) |
| 539 |
> |
target_p->localClient->serial == current_serial) |
| 540 |
|
continue; |
| 541 |
|
|
| 542 |
< |
target_p->serial = current_serial; |
| 542 |
> |
target_p->localClient->serial = current_serial; |
| 543 |
|
send_message(target_p, buffer, len); |
| 544 |
|
} |
| 545 |
|
} |
| 546 |
|
|
| 547 |
|
if (touser && MyConnect(user) && !IsDead(user) && |
| 548 |
< |
user->serial != current_serial) |
| 548 |
> |
user->localClient->serial != current_serial) |
| 549 |
|
send_message(user, buffer, len); |
| 550 |
|
} |
| 551 |
|
|
| 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 |
|
} |
| 645 |
|
* remote to this server. |
| 646 |
|
*/ |
| 647 |
|
void |
| 648 |
< |
sendto_channel_remote(struct Client *one, struct Client *from, int type, int caps, |
| 649 |
< |
int nocaps, struct Channel *chptr, const char *pattern, ...) |
| 648 |
> |
sendto_channel_remote(struct Client *one, struct Client *from, int type, |
| 649 |
> |
const unsigned int caps, const unsigned int nocaps, |
| 650 |
> |
struct Channel *chptr, const char *pattern, ...) |
| 651 |
|
{ |
| 652 |
|
va_list args; |
| 653 |
|
char buffer[IRCD_BUFSIZE]; |
| 678 |
|
((target_p->from->localClient->caps & caps) != caps) || |
| 679 |
|
((target_p->from->localClient->caps & nocaps) != 0)) |
| 680 |
|
continue; |
| 681 |
< |
if (target_p->from->serial != current_serial) |
| 681 |
> |
if (target_p->from->localClient->serial != current_serial) |
| 682 |
|
{ |
| 683 |
|
send_message(target_p, buffer, len); |
| 684 |
< |
target_p->from->serial = current_serial; |
| 684 |
> |
target_p->from->localClient->serial = current_serial; |
| 685 |
|
} |
| 686 |
|
} |
| 687 |
|
} |
| 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() |
| 817 |
|
if (IsMe(target_p) || target_p->from == source_p->from) |
| 818 |
|
continue; |
| 819 |
|
|
| 820 |
< |
if (target_p->from->serial == current_serial) |
| 820 |
> |
if (target_p->from->localClient->serial == current_serial) |
| 821 |
|
continue; |
| 822 |
|
|
| 823 |
|
if (match(mask, target_p->name)) |
| 826 |
|
* if we set the serial here, then we'll never do a |
| 827 |
|
* match() again, if !IsCapable() |
| 828 |
|
*/ |
| 829 |
< |
target_p->from->serial = current_serial; |
| 829 |
> |
target_p->from->localClient->serial = current_serial; |
| 830 |
|
found++; |
| 831 |
|
|
| 832 |
|
if (!IsCapable(target_p->from, cap)) |
| 894 |
|
void |
| 895 |
|
sendto_realops_flags(unsigned int flags, int level, const char *pattern, ...) |
| 896 |
|
{ |
| 897 |
< |
struct Client *client_p; |
| 897 |
> |
dlink_node *ptr = NULL; |
| 898 |
|
char nbuf[IRCD_BUFSIZE]; |
| 984 |
– |
dlink_node *ptr; |
| 899 |
|
va_list args; |
| 900 |
|
|
| 901 |
|
va_start(args, pattern); |
| 904 |
|
|
| 905 |
|
DLINK_FOREACH(ptr, oper_list.head) |
| 906 |
|
{ |
| 907 |
< |
client_p = ptr->data; |
| 908 |
< |
assert(client_p->umodes & UMODE_OPER); |
| 907 |
> |
struct Client *client_p = ptr->data; |
| 908 |
> |
assert(HasUMode(client_p, UMODE_OPER)); |
| 909 |
|
|
| 910 |
|
/* If we're sending it to opers and theyre an admin, skip. |
| 911 |
|
* If we're sending it to admins, and theyre not, skip. |
| 912 |
|
*/ |
| 913 |
< |
if (((level == L_ADMIN) && !IsAdmin(client_p)) || |
| 914 |
< |
((level == L_OPER) && IsAdmin(client_p))) |
| 913 |
> |
if (((level == L_ADMIN) && !HasUMode(client_p, UMODE_ADMIN)) || |
| 914 |
> |
((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN))) |
| 915 |
|
continue; |
| 916 |
|
|
| 917 |
< |
if (client_p->umodes & flags) |
| 917 |
> |
if (HasUMode(client_p, flags)) |
| 918 |
|
sendto_one(client_p, ":%s NOTICE %s :*** Notice -- %s", |
| 919 |
|
me.name, client_p->name, nbuf); |
| 920 |
|
} |
| 921 |
|
} |
| 922 |
|
|
| 923 |
+ |
void |
| 924 |
+ |
sendto_globops_flags(unsigned int flags, int level, const char *pattern, ...) |
| 925 |
+ |
{ |
| 926 |
+ |
dlink_node *ptr = NULL; |
| 927 |
+ |
char nbuf[IRCD_BUFSIZE]; |
| 928 |
+ |
va_list args; |
| 929 |
+ |
|
| 930 |
+ |
va_start(args, pattern); |
| 931 |
+ |
vsnprintf(nbuf, IRCD_BUFSIZE, pattern, args); |
| 932 |
+ |
va_end(args); |
| 933 |
+ |
|
| 934 |
+ |
DLINK_FOREACH(ptr, oper_list.head) |
| 935 |
+ |
{ |
| 936 |
+ |
struct Client *client_p = ptr->data; |
| 937 |
+ |
assert(client_p->umodes & UMODE_OPER); |
| 938 |
+ |
|
| 939 |
+ |
/* If we're sending it to opers and theyre an admin, skip. |
| 940 |
+ |
* If we're sending it to admins, and theyre not, skip. |
| 941 |
+ |
*/ |
| 942 |
+ |
if (((level == L_ADMIN) && !HasUMode(client_p, UMODE_ADMIN)) || |
| 943 |
+ |
((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN))) |
| 944 |
+ |
continue; |
| 945 |
+ |
|
| 946 |
+ |
if (HasUMode(client_p, flags)) |
| 947 |
+ |
sendto_one(client_p, ":%s NOTICE %s :*** Global -- %s", |
| 948 |
+ |
me.name, client_p->name, nbuf); |
| 949 |
+ |
} |
| 950 |
+ |
} |
| 951 |
+ |
|
| 952 |
|
/* sendto_wallops_flags() |
| 953 |
|
* |
| 954 |
|
* inputs - flag types of messages to show to real opers |
| 961 |
|
sendto_wallops_flags(unsigned int flags, struct Client *source_p, |
| 962 |
|
const char *pattern, ...) |
| 963 |
|
{ |
| 964 |
< |
struct Client *client_p; |
| 1022 |
< |
dlink_node *ptr; |
| 964 |
> |
dlink_node *ptr = NULL; |
| 965 |
|
va_list args; |
| 966 |
|
char buffer[IRCD_BUFSIZE]; |
| 967 |
|
int len; |
| 978 |
|
|
| 979 |
|
DLINK_FOREACH(ptr, oper_list.head) |
| 980 |
|
{ |
| 981 |
< |
client_p = ptr->data; |
| 981 |
> |
struct Client *client_p = ptr->data; |
| 982 |
|
assert(client_p->umodes & UMODE_OPER); |
| 983 |
|
|
| 984 |
< |
if ((client_p->umodes & flags) && !IsDefunct(client_p)) |
| 984 |
> |
if (HasUMode(client_p, flags) && !IsDefunct(client_p)) |
| 985 |
|
send_message(client_p, buffer, len); |
| 986 |
|
} |
| 987 |
|
} |
| 997 |
|
ts_warn(const char *pattern, ...) |
| 998 |
|
{ |
| 999 |
|
va_list args; |
| 1000 |
< |
char buffer[LOG_BUFSIZE]; |
| 1000 |
> |
char buffer[IRCD_BUFSIZE]; |
| 1001 |
|
static time_t last = 0; |
| 1002 |
|
static int warnings = 0; |
| 1003 |
|
|
| 1020 |
|
} |
| 1021 |
|
|
| 1022 |
|
va_start(args, pattern); |
| 1023 |
< |
vsprintf_irc(buffer, pattern, args); |
| 1023 |
> |
vsnprintf(buffer, sizeof(buffer), pattern, args); |
| 1024 |
|
va_end(args); |
| 1025 |
|
|
| 1026 |
|
sendto_realops_flags(UMODE_ALL, L_ALL, "%s", buffer); |
| 1027 |
< |
ilog(L_CRIT, "%s", buffer); |
| 1027 |
> |
ilog(LOG_TYPE_IRCD, "%s", buffer); |
| 1028 |
|
} |
| 1029 |
|
|
| 1030 |
|
/* kill_client() |
| 1078 |
|
char buf_uid[IRCD_BUFSIZE], buf_nick[IRCD_BUFSIZE]; |
| 1079 |
|
int len_uid = 0, len_nick = 0; |
| 1080 |
|
|
| 1081 |
< |
if (HasID(source_p) && (me.id[0] != '\0')) |
| 1081 |
> |
if (HasID(source_p)) |
| 1082 |
|
{ |
| 1083 |
|
have_uid = 1; |
| 1084 |
|
va_start(args, pattern); |