| 1 |
/* |
| 2 |
* Copyright (c) 2005 William Pitcock, et al. |
| 3 |
* Rights to this code are as documented in doc/LICENSE. |
| 4 |
* |
| 5 |
* This file contains code for the CService AKICK functions. |
| 6 |
* |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "atheme.h" |
| 10 |
|
| 11 |
static void cs_cmd_akick(sourceinfo_t *si, int parc, char *parv[]); |
| 12 |
static void cs_cmd_akick_add(sourceinfo_t *si, int parc, char *parv[]); |
| 13 |
static void cs_cmd_akick_del(sourceinfo_t *si, int parc, char *parv[]); |
| 14 |
static void cs_cmd_akick_list(sourceinfo_t *si, int parc, char *parv[]); |
| 15 |
|
| 16 |
static void akick_timeout_check(void *arg); |
| 17 |
static void akickdel_list_create(void *arg); |
| 18 |
|
| 19 |
DECLARE_MODULE_V1 |
| 20 |
( |
| 21 |
"chanserv/akick", false, _modinit, _moddeinit, |
| 22 |
PACKAGE_STRING, |
| 23 |
VENDOR_STRING |
| 24 |
); |
| 25 |
|
| 26 |
command_t cs_akick = { "AKICK", N_("Manipulates a channel's AKICK list."), |
| 27 |
AC_NONE, 4, cs_cmd_akick, { .path = "cservice/akick" } }; |
| 28 |
command_t cs_akick_add = { "ADD", N_("Adds a channel AKICK."), |
| 29 |
AC_NONE, 4, cs_cmd_akick_add, { .path = "" } }; |
| 30 |
command_t cs_akick_del = { "DEL", N_("Deletes a channel AKICK."), |
| 31 |
AC_NONE, 3, cs_cmd_akick_del, { .path = "" } }; |
| 32 |
command_t cs_akick_list = { "LIST", N_("Displays a channel's AKICK list."), |
| 33 |
AC_NONE, 2, cs_cmd_akick_list, { .path = "" } }; |
| 34 |
|
| 35 |
typedef struct { |
| 36 |
time_t expiration; |
| 37 |
|
| 38 |
myentity_t *entity; |
| 39 |
mychan_t *chan; |
| 40 |
|
| 41 |
char host[NICKLEN + USERLEN + HOSTLEN + 4]; |
| 42 |
|
| 43 |
mowgli_node_t node; |
| 44 |
} akick_timeout_t; |
| 45 |
|
| 46 |
time_t akickdel_next; |
| 47 |
mowgli_list_t akickdel_list; |
| 48 |
mowgli_patricia_t *cs_akick_cmds; |
| 49 |
mowgli_eventloop_timer_t *akick_timeout_check_timer = NULL; |
| 50 |
|
| 51 |
static akick_timeout_t *akick_add_timeout(mychan_t *mc, myentity_t *mt, const char *host, time_t expireson); |
| 52 |
|
| 53 |
mowgli_heap_t *akick_timeout_heap; |
| 54 |
|
| 55 |
void _modinit(module_t *m) |
| 56 |
{ |
| 57 |
service_named_bind_command("chanserv", &cs_akick); |
| 58 |
|
| 59 |
cs_akick_cmds = mowgli_patricia_create(strcasecanon); |
| 60 |
|
| 61 |
/* Add sub-commands */ |
| 62 |
command_add(&cs_akick_add, cs_akick_cmds); |
| 63 |
command_add(&cs_akick_del, cs_akick_cmds); |
| 64 |
command_add(&cs_akick_list, cs_akick_cmds); |
| 65 |
|
| 66 |
akick_timeout_heap = mowgli_heap_create(sizeof(akick_timeout_t), 512, BH_NOW); |
| 67 |
|
| 68 |
if (akick_timeout_heap == NULL) |
| 69 |
{ |
| 70 |
m->mflags = MODTYPE_FAIL; |
| 71 |
return; |
| 72 |
} |
| 73 |
|
| 74 |
mowgli_timer_add_once(base_eventloop, "akickdel_list_create", akickdel_list_create, NULL, 0); |
| 75 |
} |
| 76 |
|
| 77 |
void _moddeinit(module_unload_intent_t intent) |
| 78 |
{ |
| 79 |
if (akick_timeout_check_timer) |
| 80 |
mowgli_timer_destroy(base_eventloop, akick_timeout_check_timer); |
| 81 |
|
| 82 |
service_named_unbind_command("chanserv", &cs_akick); |
| 83 |
|
| 84 |
/* Delete sub-commands */ |
| 85 |
command_delete(&cs_akick_add, cs_akick_cmds); |
| 86 |
command_delete(&cs_akick_del, cs_akick_cmds); |
| 87 |
command_delete(&cs_akick_list, cs_akick_cmds); |
| 88 |
|
| 89 |
mowgli_heap_destroy(akick_timeout_heap); |
| 90 |
mowgli_patricia_destroy(cs_akick_cmds, NULL, NULL); |
| 91 |
} |
| 92 |
|
| 93 |
static void clear_bans_matching_entity(mychan_t *mc, myentity_t *mt) |
| 94 |
{ |
| 95 |
mowgli_node_t *n; |
| 96 |
myuser_t *tmu; |
| 97 |
|
| 98 |
if (mc->chan == NULL) |
| 99 |
return; |
| 100 |
|
| 101 |
if (!isuser(mt)) |
| 102 |
return; |
| 103 |
|
| 104 |
tmu = user(mt); |
| 105 |
|
| 106 |
MOWGLI_ITER_FOREACH(n, tmu->logins.head) |
| 107 |
{ |
| 108 |
user_t *tu; |
| 109 |
mowgli_node_t *it, *itn; |
| 110 |
|
| 111 |
char hostbuf2[BUFSIZE]; |
| 112 |
|
| 113 |
tu = n->data; |
| 114 |
|
| 115 |
snprintf(hostbuf2, BUFSIZE, "%s!%s@%s", tu->nick, tu->user, tu->vhost); |
| 116 |
for (it = next_matching_ban(mc->chan, tu, 'b', mc->chan->bans.head); it != NULL; it = next_matching_ban(mc->chan, tu, 'b', itn)) |
| 117 |
{ |
| 118 |
chanban_t *cb; |
| 119 |
|
| 120 |
itn = it->next; |
| 121 |
cb = it->data; |
| 122 |
|
| 123 |
modestack_mode_param(chansvs.nick, mc->chan, MTYPE_DEL, cb->type, cb->mask); |
| 124 |
chanban_delete(cb); |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
modestack_flush_channel(mc->chan); |
| 129 |
} |
| 130 |
|
| 131 |
static void cs_cmd_akick(sourceinfo_t *si, int parc, char *parv[]) |
| 132 |
{ |
| 133 |
char *chan; |
| 134 |
char *cmd; |
| 135 |
command_t *c; |
| 136 |
|
| 137 |
if (parc < 2) |
| 138 |
{ |
| 139 |
command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "AKICK"); |
| 140 |
command_fail(si, fault_needmoreparams, _("Syntax: AKICK <#channel> <ADD|DEL|LIST> [parameters]")); |
| 141 |
return; |
| 142 |
} |
| 143 |
|
| 144 |
if (parv[0][0] == '#') |
| 145 |
chan = parv[0], cmd = parv[1]; |
| 146 |
else if (parv[1][0] == '#') |
| 147 |
cmd = parv[0], chan = parv[1]; |
| 148 |
else |
| 149 |
{ |
| 150 |
command_fail(si, fault_badparams, STR_INVALID_PARAMS, "AKICK"); |
| 151 |
command_fail(si, fault_badparams, _("Syntax: AKICK <#channel> <ADD|DEL|LIST> [parameters]")); |
| 152 |
return; |
| 153 |
} |
| 154 |
|
| 155 |
c = command_find(cs_akick_cmds, cmd); |
| 156 |
if (c == NULL) |
| 157 |
{ |
| 158 |
command_fail(si, fault_badparams, _("Invalid command. Use \2/%s%s help\2 for a command listing."), (ircd->uses_rcommand == false) ? "msg " : "", chansvs.me->disp); |
| 159 |
return; |
| 160 |
} |
| 161 |
|
| 162 |
parv[1] = chan; |
| 163 |
command_exec(si->service, si, c, parc - 1, parv + 1); |
| 164 |
} |
| 165 |
|
| 166 |
void cs_cmd_akick_add(sourceinfo_t *si, int parc, char *parv[]) |
| 167 |
{ |
| 168 |
myentity_t *mt; |
| 169 |
mychan_t *mc; |
| 170 |
hook_channel_acl_req_t req; |
| 171 |
chanacs_t *ca, *ca2; |
| 172 |
char *chan = parv[0]; |
| 173 |
long duration; |
| 174 |
char expiry[512]; |
| 175 |
char *s; |
| 176 |
char *target; |
| 177 |
char *uname; |
| 178 |
char *token; |
| 179 |
char *treason, reason[BUFSIZE]; |
| 180 |
|
| 181 |
target = parv[1]; |
| 182 |
token = strtok(parv[2], " "); |
| 183 |
|
| 184 |
if (!target) |
| 185 |
{ |
| 186 |
command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "AKICK"); |
| 187 |
command_fail(si, fault_needmoreparams, _("Syntax: AKICK <#channel> ADD <nickname|hostmask> [!P|!T <minutes>] [reason]")); |
| 188 |
return; |
| 189 |
} |
| 190 |
|
| 191 |
mc = mychan_find(chan); |
| 192 |
if (!mc) |
| 193 |
{ |
| 194 |
command_fail(si, fault_nosuch_target, _("Channel \2%s\2 is not registered."), chan); |
| 195 |
return; |
| 196 |
} |
| 197 |
|
| 198 |
if (metadata_find(mc, "private:close:closer")) |
| 199 |
{ |
| 200 |
command_fail(si, fault_noprivs, _("\2%s\2 is closed."), chan); |
| 201 |
return; |
| 202 |
} |
| 203 |
|
| 204 |
/* A duration, reason or duration and reason. */ |
| 205 |
if (token) |
| 206 |
{ |
| 207 |
if (!strcasecmp(token, "!P")) /* A duration [permanent] */ |
| 208 |
{ |
| 209 |
duration = 0; |
| 210 |
treason = strtok(NULL, ""); |
| 211 |
|
| 212 |
if (treason) |
| 213 |
mowgli_strlcpy(reason, treason, BUFSIZE); |
| 214 |
else |
| 215 |
reason[0] = 0; |
| 216 |
} |
| 217 |
else if (!strcasecmp(token, "!T")) /* A duration [temporary] */ |
| 218 |
{ |
| 219 |
s = strtok(NULL, " "); |
| 220 |
treason = strtok(NULL, ""); |
| 221 |
|
| 222 |
if (treason) |
| 223 |
mowgli_strlcpy(reason, treason, BUFSIZE); |
| 224 |
else |
| 225 |
reason[0] = 0; |
| 226 |
|
| 227 |
if (s) |
| 228 |
{ |
| 229 |
duration = (atol(s) * 60); |
| 230 |
while (isdigit((unsigned char)*s)) |
| 231 |
s++; |
| 232 |
if (*s == 'h' || *s == 'H') |
| 233 |
duration *= 60; |
| 234 |
else if (*s == 'd' || *s == 'D') |
| 235 |
duration *= 1440; |
| 236 |
else if (*s == 'w' || *s == 'W') |
| 237 |
duration *= 10080; |
| 238 |
else if (*s == '\0') |
| 239 |
; |
| 240 |
else |
| 241 |
duration = 0; |
| 242 |
|
| 243 |
if (duration == 0) |
| 244 |
{ |
| 245 |
command_fail(si, fault_badparams, _("Invalid duration given.")); |
| 246 |
command_fail(si, fault_badparams, _("Syntax: AKICK <#channel> ADD <nick|hostmask> [!P|!T <minutes>] [reason]")); |
| 247 |
return; |
| 248 |
} |
| 249 |
} |
| 250 |
else |
| 251 |
{ |
| 252 |
command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "AKICK ADD"); |
| 253 |
command_fail(si, fault_needmoreparams, _("Syntax: AKICK <#channel> ADD <nick|hostmask> [!P|!T <minutes>] [reason]")); |
| 254 |
return; |
| 255 |
} |
| 256 |
} |
| 257 |
else |
| 258 |
{ |
| 259 |
duration = chansvs.akick_time; |
| 260 |
mowgli_strlcpy(reason, token, BUFSIZE); |
| 261 |
treason = strtok(NULL, ""); |
| 262 |
|
| 263 |
if (treason) |
| 264 |
{ |
| 265 |
mowgli_strlcat(reason, " ", BUFSIZE); |
| 266 |
mowgli_strlcat(reason, treason, BUFSIZE); |
| 267 |
} |
| 268 |
} |
| 269 |
} |
| 270 |
else |
| 271 |
{ /* No reason and no duration */ |
| 272 |
duration = chansvs.akick_time; |
| 273 |
reason[0] = 0; |
| 274 |
} |
| 275 |
|
| 276 |
if ((chanacs_source_flags(mc, si) & (CA_FLAGS | CA_REMOVE)) != (CA_FLAGS | CA_REMOVE)) |
| 277 |
{ |
| 278 |
command_fail(si, fault_noprivs, _("You are not authorized to perform this operation.")); |
| 279 |
return; |
| 280 |
} |
| 281 |
|
| 282 |
mt = myentity_find_ext(target); |
| 283 |
if (!mt) |
| 284 |
{ |
| 285 |
uname = pretty_mask(target); |
| 286 |
if (uname == NULL) |
| 287 |
uname = target; |
| 288 |
|
| 289 |
/* we might be adding a hostmask */ |
| 290 |
if (!validhostmask(uname)) |
| 291 |
{ |
| 292 |
command_fail(si, fault_badparams, _("\2%s\2 is neither a nickname nor a hostmask."), uname); |
| 293 |
return; |
| 294 |
} |
| 295 |
|
| 296 |
uname = collapse(uname); |
| 297 |
|
| 298 |
ca = chanacs_find_host_literal(mc, uname, 0); |
| 299 |
if (ca != NULL) |
| 300 |
{ |
| 301 |
if (ca->level & CA_AKICK) |
| 302 |
command_fail(si, fault_nochange, _("\2%s\2 is already on the AKICK list for \2%s\2"), uname, mc->name); |
| 303 |
else |
| 304 |
command_fail(si, fault_alreadyexists, _("\2%s\2 already has flags \2%s\2 on \2%s\2"), uname, bitmask_to_flags(ca->level), mc->name); |
| 305 |
return; |
| 306 |
} |
| 307 |
|
| 308 |
ca = chanacs_find_host(mc, uname, CA_AKICK); |
| 309 |
if (ca != NULL) |
| 310 |
{ |
| 311 |
command_fail(si, fault_nochange, _("The more general mask \2%s\2 is already on the AKICK list for \2%s\2"), ca->host, mc->name); |
| 312 |
return; |
| 313 |
} |
| 314 |
|
| 315 |
/* new entry */ |
| 316 |
ca2 = chanacs_open(mc, NULL, uname, true, entity(si->smu)); |
| 317 |
if (chanacs_is_table_full(ca2)) |
| 318 |
{ |
| 319 |
command_fail(si, fault_toomany, _("Channel %s access list is full."), mc->name); |
| 320 |
chanacs_close(ca2); |
| 321 |
return; |
| 322 |
} |
| 323 |
|
| 324 |
req.ca = ca2; |
| 325 |
req.oldlevel = ca2->level; |
| 326 |
|
| 327 |
chanacs_modify_simple(ca2, CA_AKICK, 0); |
| 328 |
|
| 329 |
req.newlevel = ca2->level; |
| 330 |
|
| 331 |
if (reason[0]) |
| 332 |
metadata_add(ca2, "reason", reason); |
| 333 |
|
| 334 |
if (duration > 0) |
| 335 |
{ |
| 336 |
akick_timeout_t *timeout; |
| 337 |
time_t expireson = ca2->tmodified+duration; |
| 338 |
|
| 339 |
snprintf(expiry, sizeof expiry, "%ld", expireson); |
| 340 |
metadata_add(ca2, "expires", expiry); |
| 341 |
|
| 342 |
verbose(mc, _("\2%s\2 added \2%s\2 to the AKICK list, expires in %s."), get_source_name(si), uname,timediff(duration)); |
| 343 |
logcommand(si, CMDLOG_SET, "AKICK:ADD: \2%s\2 on \2%s\2, expires in %s.", uname, mc->name,timediff(duration)); |
| 344 |
command_success_nodata(si, _("AKICK on \2%s\2 was successfully added for \2%s\2 and will expire in %s."), uname, mc->name,timediff(duration) ); |
| 345 |
|
| 346 |
timeout = akick_add_timeout(mc, NULL, uname, expireson); |
| 347 |
|
| 348 |
if (akickdel_next == 0 || akickdel_next > timeout->expiration) |
| 349 |
{ |
| 350 |
if (akickdel_next != 0) |
| 351 |
mowgli_timer_destroy(base_eventloop, akick_timeout_check_timer); |
| 352 |
|
| 353 |
akickdel_next = timeout->expiration; |
| 354 |
akick_timeout_check_timer = mowgli_timer_add_once(base_eventloop, "akick_timeout_check", akick_timeout_check, NULL, akickdel_next - CURRTIME); |
| 355 |
} |
| 356 |
} |
| 357 |
else |
| 358 |
{ |
| 359 |
verbose(mc, _("\2%s\2 added \2%s\2 to the AKICK list."), get_source_name(si), uname); |
| 360 |
logcommand(si, CMDLOG_SET, "AKICK:ADD: \2%s\2 on \2%s\2", uname, mc->name); |
| 361 |
|
| 362 |
command_success_nodata(si, _("AKICK on \2%s\2 was successfully added to the AKICK list for \2%s\2."), uname, mc->name); |
| 363 |
} |
| 364 |
|
| 365 |
hook_call_channel_acl_change(&req); |
| 366 |
chanacs_close(ca2); |
| 367 |
|
| 368 |
return; |
| 369 |
} |
| 370 |
else |
| 371 |
{ |
| 372 |
if ((ca = chanacs_find_literal(mc, mt, 0x0))) |
| 373 |
{ |
| 374 |
if (ca->level & CA_AKICK) |
| 375 |
command_fail(si, fault_nochange, _("\2%s\2 is already on the AKICK list for \2%s\2"), mt->name, mc->name); |
| 376 |
else |
| 377 |
command_fail(si, fault_alreadyexists, _("\2%s\2 already has flags \2%s\2 on \2%s\2"), mt->name, bitmask_to_flags(ca->level), mc->name); |
| 378 |
return; |
| 379 |
} |
| 380 |
|
| 381 |
/* new entry */ |
| 382 |
ca2 = chanacs_open(mc, mt, NULL, true, entity(si->smu)); |
| 383 |
if (chanacs_is_table_full(ca2)) |
| 384 |
{ |
| 385 |
command_fail(si, fault_toomany, _("Channel %s access list is full."), mc->name); |
| 386 |
chanacs_close(ca2); |
| 387 |
return; |
| 388 |
} |
| 389 |
|
| 390 |
req.ca = ca2; |
| 391 |
req.oldlevel = ca2->level; |
| 392 |
|
| 393 |
chanacs_modify_simple(ca2, CA_AKICK, 0); |
| 394 |
|
| 395 |
req.newlevel = ca2->level; |
| 396 |
|
| 397 |
if (reason[0]) |
| 398 |
metadata_add(ca2, "reason", reason); |
| 399 |
|
| 400 |
if (duration > 0) |
| 401 |
{ |
| 402 |
akick_timeout_t *timeout; |
| 403 |
time_t expireson = ca2->tmodified+duration; |
| 404 |
|
| 405 |
snprintf(expiry, sizeof expiry, "%ld", expireson); |
| 406 |
metadata_add(ca2, "expires", expiry); |
| 407 |
|
| 408 |
command_success_nodata(si, _("AKICK on \2%s\2 was successfully added for \2%s\2 and will expire in %s."), mt->name, mc->name, timediff(duration)); |
| 409 |
verbose(mc, _("\2%s\2 added \2%s\2 to the AKICK list, expires in %s."), get_source_name(si), mt->name, timediff(duration)); |
| 410 |
logcommand(si, CMDLOG_SET, "AKICK:ADD: \2%s\2 on \2%s\2, expires in %s", mt->name, mc->name, timediff(duration)); |
| 411 |
|
| 412 |
timeout = akick_add_timeout(mc, mt, mt->name, expireson); |
| 413 |
|
| 414 |
if (akickdel_next == 0 || akickdel_next > timeout->expiration) |
| 415 |
{ |
| 416 |
if (akickdel_next != 0) |
| 417 |
mowgli_timer_destroy(base_eventloop, akick_timeout_check_timer); |
| 418 |
|
| 419 |
akickdel_next = timeout->expiration; |
| 420 |
akick_timeout_check_timer = mowgli_timer_add_once(base_eventloop, "akick_timeout_check", akick_timeout_check, NULL, akickdel_next - CURRTIME); |
| 421 |
} |
| 422 |
} |
| 423 |
else |
| 424 |
{ |
| 425 |
command_success_nodata(si, _("AKICK on \2%s\2 was successfully added to the AKICK list for \2%s\2."), mt->name, mc->name); |
| 426 |
|
| 427 |
verbose(mc, _("\2%s\2 added \2%s\2 to the AKICK list."), get_source_name(si), mt->name); |
| 428 |
logcommand(si, CMDLOG_SET, "AKICK:ADD: \2%s\2 on \2%s\2", mt->name, mc->name); |
| 429 |
} |
| 430 |
|
| 431 |
hook_call_channel_acl_change(&req); |
| 432 |
chanacs_close(ca2); |
| 433 |
return; |
| 434 |
} |
| 435 |
} |
| 436 |
|
| 437 |
void cs_cmd_akick_del(sourceinfo_t *si, int parc, char *parv[]) |
| 438 |
{ |
| 439 |
myentity_t *mt; |
| 440 |
mychan_t *mc; |
| 441 |
hook_channel_acl_req_t req; |
| 442 |
chanacs_t *ca; |
| 443 |
mowgli_node_t *n, *tn; |
| 444 |
char *chan = parv[0]; |
| 445 |
char *uname = parv[1]; |
| 446 |
|
| 447 |
if (!chan || !uname) |
| 448 |
{ |
| 449 |
command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "AKICK"); |
| 450 |
command_fail(si, fault_needmoreparams, _("Syntax: AKICK <#channel> DEL <nickname|hostmask>")); |
| 451 |
return; |
| 452 |
} |
| 453 |
|
| 454 |
mc = mychan_find(chan); |
| 455 |
if (!mc) |
| 456 |
{ |
| 457 |
command_fail(si, fault_nosuch_target, _("Channel \2%s\2 is not registered."), chan); |
| 458 |
return; |
| 459 |
} |
| 460 |
|
| 461 |
if (metadata_find(mc, "private:close:closer")) |
| 462 |
{ |
| 463 |
command_fail(si, fault_noprivs, _("\2%s\2 is closed."), chan); |
| 464 |
return; |
| 465 |
} |
| 466 |
|
| 467 |
akick_timeout_t *timeout; |
| 468 |
chanban_t *cb; |
| 469 |
|
| 470 |
if ((chanacs_source_flags(mc, si) & (CA_FLAGS | CA_REMOVE)) != (CA_FLAGS | CA_REMOVE)) |
| 471 |
{ |
| 472 |
command_fail(si, fault_noprivs, _("You are not authorized to perform this operation.")); |
| 473 |
return; |
| 474 |
} |
| 475 |
|
| 476 |
mt = myentity_find_ext(uname); |
| 477 |
if (!mt) |
| 478 |
{ |
| 479 |
/* we might be deleting a hostmask */ |
| 480 |
ca = chanacs_find_host_literal(mc, uname, CA_AKICK); |
| 481 |
if (ca == NULL) |
| 482 |
{ |
| 483 |
ca = chanacs_find_host(mc, uname, CA_AKICK); |
| 484 |
if (ca != NULL) |
| 485 |
command_fail(si, fault_nosuch_key, _("\2%s\2 is not on the AKICK list for \2%s\2, however \2%s\2 is."), uname, mc->name, ca->host); |
| 486 |
else |
| 487 |
command_fail(si, fault_nosuch_key, _("\2%s\2 is not on the AKICK list for \2%s\2."), uname, mc->name); |
| 488 |
return; |
| 489 |
} |
| 490 |
|
| 491 |
req.ca = ca; |
| 492 |
req.oldlevel = ca->level; |
| 493 |
|
| 494 |
chanacs_modify_simple(ca, 0, CA_AKICK); |
| 495 |
|
| 496 |
req.newlevel = ca->level; |
| 497 |
|
| 498 |
hook_call_channel_acl_change(&req); |
| 499 |
chanacs_close(ca); |
| 500 |
|
| 501 |
verbose(mc, _("\2%s\2 removed \2%s\2 from the AKICK list."), get_source_name(si), uname); |
| 502 |
logcommand(si, CMDLOG_SET, "AKICK:DEL: \2%s\2 on \2%s\2", uname, mc->name); |
| 503 |
command_success_nodata(si, _("\2%s\2 has been removed from the AKICK list for \2%s\2."), uname, mc->name); |
| 504 |
|
| 505 |
MOWGLI_ITER_FOREACH_SAFE(n, tn, akickdel_list.head) |
| 506 |
{ |
| 507 |
timeout = n->data; |
| 508 |
if (!match(timeout->host, uname) && timeout->chan == mc) |
| 509 |
{ |
| 510 |
mowgli_node_delete(&timeout->node, &akickdel_list); |
| 511 |
mowgli_heap_free(akick_timeout_heap, timeout); |
| 512 |
} |
| 513 |
} |
| 514 |
|
| 515 |
if (mc->chan != NULL && (cb = chanban_find(mc->chan, uname, 'b'))) |
| 516 |
{ |
| 517 |
modestack_mode_param(chansvs.nick, mc->chan, MTYPE_DEL, cb->type, cb->mask); |
| 518 |
chanban_delete(cb); |
| 519 |
} |
| 520 |
|
| 521 |
return; |
| 522 |
} |
| 523 |
|
| 524 |
if (!(ca = chanacs_find_literal(mc, mt, CA_AKICK))) |
| 525 |
{ |
| 526 |
command_fail(si, fault_nosuch_key, _("\2%s\2 is not on the AKICK list for \2%s\2."), mt->name, mc->name); |
| 527 |
return; |
| 528 |
} |
| 529 |
|
| 530 |
clear_bans_matching_entity(mc, mt); |
| 531 |
|
| 532 |
MOWGLI_ITER_FOREACH_SAFE(n, tn, akickdel_list.head) |
| 533 |
{ |
| 534 |
timeout = n->data; |
| 535 |
if (timeout->entity == mt && timeout->chan == mc) |
| 536 |
{ |
| 537 |
mowgli_node_delete(&timeout->node, &akickdel_list); |
| 538 |
mowgli_heap_free(akick_timeout_heap, timeout); |
| 539 |
} |
| 540 |
} |
| 541 |
|
| 542 |
req.ca = ca; |
| 543 |
req.oldlevel = ca->level; |
| 544 |
|
| 545 |
chanacs_modify_simple(ca, 0, CA_AKICK); |
| 546 |
|
| 547 |
req.newlevel = ca->level; |
| 548 |
|
| 549 |
hook_call_channel_acl_change(&req); |
| 550 |
chanacs_close(ca); |
| 551 |
|
| 552 |
command_success_nodata(si, _("\2%s\2 has been removed from the AKICK list for \2%s\2."), mt->name, mc->name); |
| 553 |
logcommand(si, CMDLOG_SET, "AKICK:DEL: \2%s\2 on \2%s\2", mt->name, mc->name); |
| 554 |
verbose(mc, _("\2%s\2 removed \2%s\2 from the AKICK list."), get_source_name(si), mt->name); |
| 555 |
|
| 556 |
return; |
| 557 |
} |
| 558 |
|
| 559 |
void cs_cmd_akick_list(sourceinfo_t *si, int parc, char *parv[]) |
| 560 |
{ |
| 561 |
mychan_t *mc; |
| 562 |
chanacs_t *ca; |
| 563 |
metadata_t *md, *md2; |
| 564 |
mowgli_node_t *n, *tn; |
| 565 |
bool operoverride = false; |
| 566 |
char *chan = parv[0]; |
| 567 |
char expiry[512]; |
| 568 |
|
| 569 |
if (!chan) |
| 570 |
{ |
| 571 |
command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "AKICK"); |
| 572 |
command_fail(si, fault_needmoreparams, _("Syntax: AKICK <#channel> LIST")); |
| 573 |
return; |
| 574 |
} |
| 575 |
|
| 576 |
/* make sure they're registered, logged in |
| 577 |
* and the founder of the channel before |
| 578 |
* we go any further. |
| 579 |
*/ |
| 580 |
if (!si->smu) |
| 581 |
{ |
| 582 |
/* if they're opers and just want to LIST, they don't have to log in */ |
| 583 |
if (!(has_priv(si, PRIV_CHAN_AUSPEX))) |
| 584 |
{ |
| 585 |
command_fail(si, fault_noprivs, _("You are not logged in.")); |
| 586 |
return; |
| 587 |
} |
| 588 |
} |
| 589 |
|
| 590 |
mc = mychan_find(chan); |
| 591 |
if (!mc) |
| 592 |
{ |
| 593 |
command_fail(si, fault_nosuch_target, _("Channel \2%s\2 is not registered."), chan); |
| 594 |
return; |
| 595 |
} |
| 596 |
|
| 597 |
if (metadata_find(mc, "private:close:closer")) |
| 598 |
{ |
| 599 |
command_fail(si, fault_noprivs, _("\2%s\2 is closed."), chan); |
| 600 |
return; |
| 601 |
} |
| 602 |
|
| 603 |
int i = 0; |
| 604 |
|
| 605 |
if (!chanacs_source_has_flag(mc, si, CA_ACLVIEW)) |
| 606 |
{ |
| 607 |
if (has_priv(si, PRIV_CHAN_AUSPEX)) |
| 608 |
operoverride = true; |
| 609 |
else |
| 610 |
{ |
| 611 |
command_fail(si, fault_noprivs, _("You are not authorized to perform this operation.")); |
| 612 |
return; |
| 613 |
} |
| 614 |
} |
| 615 |
command_success_nodata(si, _("AKICK list for \2%s\2:"), mc->name); |
| 616 |
|
| 617 |
MOWGLI_ITER_FOREACH_SAFE(n, tn, mc->chanacs.head) |
| 618 |
{ |
| 619 |
time_t expires_on = 0; |
| 620 |
char *ago; |
| 621 |
long time_left = 0; |
| 622 |
|
| 623 |
ca = (chanacs_t *)n->data; |
| 624 |
|
| 625 |
if (ca->level == CA_AKICK) |
| 626 |
{ |
| 627 |
char buf[BUFSIZE], *buf_iter; |
| 628 |
|
| 629 |
md = metadata_find(ca, "reason"); |
| 630 |
|
| 631 |
/* check if it's a temporary akick */ |
| 632 |
if ((md2 = metadata_find(ca, "expires"))) |
| 633 |
{ |
| 634 |
snprintf(expiry, sizeof expiry, "%s", md2->value); |
| 635 |
expires_on = (time_t)atol(expiry); |
| 636 |
time_left = difftime(expires_on, CURRTIME); |
| 637 |
} |
| 638 |
ago = ca->tmodified ? time_ago(ca->tmodified) : "?"; |
| 639 |
|
| 640 |
buf_iter = buf; |
| 641 |
buf_iter += snprintf(buf_iter, sizeof(buf) - (buf_iter - buf), _("%d: \2%s\2 (\2%s\2) ["), |
| 642 |
++i, ca->entity != NULL ? ca->entity->name : ca->host, |
| 643 |
md != NULL ? md->value : _("no AKICK reason specified")); |
| 644 |
|
| 645 |
if (ca->setter) |
| 646 |
buf_iter += snprintf(buf_iter, sizeof(buf) - (buf_iter - buf), _("setter: %s"), |
| 647 |
ca->setter); |
| 648 |
|
| 649 |
if (expires_on > 0) |
| 650 |
buf_iter += snprintf(buf_iter, sizeof(buf) - (buf_iter - buf), _("%sexpires: %s"), |
| 651 |
ca->setter != NULL ? ", " : "", timediff(time_left)); |
| 652 |
|
| 653 |
if (ca->tmodified) |
| 654 |
buf_iter += snprintf(buf_iter, sizeof(buf) - (buf_iter - buf), _("%smodified: %s"), |
| 655 |
expires_on > 0 || ca->setter != NULL ? ", " : "", ago); |
| 656 |
|
| 657 |
mowgli_strlcat(buf, "]", sizeof buf); |
| 658 |
|
| 659 |
command_success_nodata(si, "%s", buf); |
| 660 |
} |
| 661 |
|
| 662 |
} |
| 663 |
|
| 664 |
command_success_nodata(si, _("Total of \2%d\2 %s in \2%s\2's AKICK list."), i, (i == 1) ? "entry" : "entries", mc->name); |
| 665 |
|
| 666 |
if (operoverride) |
| 667 |
logcommand(si, CMDLOG_ADMIN, "AKICK:LIST: \2%s\2 (oper override)", mc->name); |
| 668 |
else |
| 669 |
logcommand(si, CMDLOG_GET, "AKICK:LIST: \2%s\2", mc->name); |
| 670 |
} |
| 671 |
|
| 672 |
void akick_timeout_check(void *arg) |
| 673 |
{ |
| 674 |
mowgli_node_t *n, *tn; |
| 675 |
akick_timeout_t *timeout; |
| 676 |
chanacs_t *ca; |
| 677 |
mychan_t *mc; |
| 678 |
|
| 679 |
chanban_t *cb; |
| 680 |
akickdel_next = 0; |
| 681 |
|
| 682 |
MOWGLI_ITER_FOREACH_SAFE(n, tn, akickdel_list.head) |
| 683 |
{ |
| 684 |
timeout = n->data; |
| 685 |
mc = timeout->chan; |
| 686 |
|
| 687 |
if (timeout->expiration > CURRTIME) |
| 688 |
{ |
| 689 |
akickdel_next = timeout->expiration; |
| 690 |
akick_timeout_check_timer = mowgli_timer_add_once(base_eventloop, "akick_timeout_check", akick_timeout_check, NULL, akickdel_next - CURRTIME); |
| 691 |
break; |
| 692 |
} |
| 693 |
|
| 694 |
ca = NULL; |
| 695 |
|
| 696 |
if (timeout->entity == NULL) |
| 697 |
{ |
| 698 |
if ((ca = chanacs_find_host_literal(mc, timeout->host, CA_AKICK)) && mc->chan != NULL && (cb = chanban_find(mc->chan, ca->host, 'b'))) |
| 699 |
{ |
| 700 |
modestack_mode_param(chansvs.nick, mc->chan, MTYPE_DEL, cb->type, cb->mask); |
| 701 |
chanban_delete(cb); |
| 702 |
} |
| 703 |
} |
| 704 |
else |
| 705 |
{ |
| 706 |
ca = chanacs_find_literal(mc, timeout->entity, CA_AKICK); |
| 707 |
if (ca == NULL) |
| 708 |
{ |
| 709 |
mowgli_node_delete(&timeout->node, &akickdel_list); |
| 710 |
mowgli_heap_free(akick_timeout_heap, timeout); |
| 711 |
|
| 712 |
continue; |
| 713 |
} |
| 714 |
|
| 715 |
clear_bans_matching_entity(mc, timeout->entity); |
| 716 |
} |
| 717 |
|
| 718 |
if (ca) |
| 719 |
{ |
| 720 |
chanacs_modify_simple(ca, 0, CA_AKICK); |
| 721 |
chanacs_close(ca); |
| 722 |
} |
| 723 |
|
| 724 |
mowgli_node_delete(&timeout->node, &akickdel_list); |
| 725 |
mowgli_heap_free(akick_timeout_heap, timeout); |
| 726 |
} |
| 727 |
} |
| 728 |
|
| 729 |
static akick_timeout_t *akick_add_timeout(mychan_t *mc, myentity_t *mt, const char *host, time_t expireson) |
| 730 |
{ |
| 731 |
mowgli_node_t *n; |
| 732 |
akick_timeout_t *timeout, *timeout2; |
| 733 |
|
| 734 |
timeout = mowgli_heap_alloc(akick_timeout_heap); |
| 735 |
|
| 736 |
timeout->entity = mt; |
| 737 |
timeout->chan = mc; |
| 738 |
timeout->expiration = expireson; |
| 739 |
|
| 740 |
mowgli_strlcpy(timeout->host, host, sizeof timeout->host); |
| 741 |
|
| 742 |
MOWGLI_ITER_FOREACH_PREV(n, akickdel_list.tail) |
| 743 |
{ |
| 744 |
timeout2 = n->data; |
| 745 |
if (timeout2->expiration <= timeout->expiration) |
| 746 |
break; |
| 747 |
} |
| 748 |
if (n == NULL) |
| 749 |
mowgli_node_add_head(timeout, &timeout->node, &akickdel_list); |
| 750 |
else if (n->next == NULL) |
| 751 |
mowgli_node_add(timeout, &timeout->node, &akickdel_list); |
| 752 |
else |
| 753 |
mowgli_node_add_before(timeout, &timeout->node, &akickdel_list, n->next); |
| 754 |
|
| 755 |
return timeout; |
| 756 |
} |
| 757 |
|
| 758 |
void akickdel_list_create(void *arg) |
| 759 |
{ |
| 760 |
mychan_t *mc; |
| 761 |
mowgli_node_t *n, *tn; |
| 762 |
chanacs_t *ca; |
| 763 |
metadata_t *md; |
| 764 |
time_t expireson; |
| 765 |
|
| 766 |
mowgli_patricia_iteration_state_t state; |
| 767 |
|
| 768 |
MOWGLI_PATRICIA_FOREACH(mc, &state, mclist) |
| 769 |
{ |
| 770 |
MOWGLI_ITER_FOREACH_SAFE(n, tn, mc->chanacs.head) |
| 771 |
{ |
| 772 |
ca = (chanacs_t *)n->data; |
| 773 |
|
| 774 |
if (!(ca->level & CA_AKICK)) |
| 775 |
continue; |
| 776 |
|
| 777 |
md = metadata_find(ca, "expires"); |
| 778 |
|
| 779 |
if (!md) |
| 780 |
continue; |
| 781 |
|
| 782 |
expireson = atol(md->value); |
| 783 |
|
| 784 |
if (CURRTIME > expireson) |
| 785 |
{ |
| 786 |
chanacs_modify_simple(ca, 0, CA_AKICK); |
| 787 |
chanacs_close(ca); |
| 788 |
} |
| 789 |
else |
| 790 |
{ |
| 791 |
/* overcomplicate the logic here a tiny bit */ |
| 792 |
if (ca->host == NULL && ca->entity != NULL) |
| 793 |
akick_add_timeout(mc, ca->entity, entity(ca->entity)->name, expireson); |
| 794 |
else if (ca->host != NULL && ca->entity == NULL) |
| 795 |
akick_add_timeout(mc, NULL, ca->host, expireson); |
| 796 |
} |
| 797 |
} |
| 798 |
} |
| 799 |
} |
| 800 |
/* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs |
| 801 |
* vim:ts=8 |
| 802 |
* vim:sw=8 |
| 803 |
* vim:noexpandtab |
| 804 |
*/ |