/* * Copyright (c) 2005 William Pitcock * Copyright (c) 2007 Jilles Tjoelker * Copyright (c) 2007 Jordan Bracco * Rights to this code are as documented in doc/LICENSE. * * No utility- just kill an user when identity. * Derived from nickserv/vhost and freenode/ns_killonauth * * $Id$ */ #include "atheme.h" #include "uplink.h" DECLARE_MODULE_V1 ( "contrib/ns_killonauth", FALSE, _modinit, _moddeinit, "$Id$", "Jordan Bracco " ); list_t *ns_cmdtree, *ns_helptree; static void killonauth_on_identify(void *vptr); static void ns_cmd_killonauth(sourceinfo_t *si, int parc, char *parv[]); static void ns_cmd_listkillonauth(sourceinfo_t *si, int parc, char *parv[]); command_t ns_killonauth = { "KILLONAUTH", N_("Enables or disables auto kill on authentification."), PRIV_USER_ADMIN, 2, ns_cmd_killonauth }; command_t ns_listkillonauth = { "LISTKILLONAUTH", N_("Lists accounts with auto kill enabled."), PRIV_USER_AUSPEX, 1, ns_cmd_listkillonauth }; void _modinit(module_t *m) { MODULE_USE_SYMBOL(ns_cmdtree, "nickserv/main", "ns_cmdtree"); MODULE_USE_SYMBOL(ns_helptree, "nickserv/main", "ns_helptree"); hook_add_event("user_identify"); hook_add_hook("user_identify", killonauth_on_identify); command_add(&ns_killonauth, ns_cmdtree); command_add(&ns_listkillonauth, ns_cmdtree); help_addentry(ns_helptree, "KILLONAUTH", "help/nickserv/killonauth", NULL); help_addentry(ns_helptree, "LISTKILLONAUTH", "help/nickserv/listkillonauth", NULL); } void _moddeinit(void) { hook_del_hook("user_identify", killonauth_on_identify); command_delete(&ns_killonauth, ns_cmdtree); command_delete(&ns_listkillonauth, ns_cmdtree); help_delentry(ns_helptree, "KILLONAUTH"); help_delentry(ns_helptree, "LISTKILLONAUTH"); } static void do_killonauth(user_t *u, boolean_t enable) { char luhost[BUFSIZE]; sts("KILL %s :LOLDONGS.", u->nick); snoop("KILLONAUTH:KILLED: \2%s\2", u->nick); } static void do_killonauth_all(myuser_t *mu, boolean_t enable) { node_t *n; user_t *u; char luhost[BUFSIZE]; LIST_FOREACH(n, mu->logins.head) { u = n->data; do_killonauth(u, enable); } } /* killonauth [ON|OFF] */ static void ns_cmd_killonauth(sourceinfo_t *si, int parc, char *parv[]) { char *newstate = parv[1]; myuser_t *mu; char *p; if (parc < 1) { command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "KILLONAUTH"); command_fail(si, fault_needmoreparams, _("Syntax: KILLONAUTH [ON|OFF]")); return; } /* find the user... */ if (!(mu = myuser_find_ext(parv[0]))) { command_fail(si, fault_nosuch_target, _("\2%s\2 is not registered."), parv[0]); return; } if (parc == 1) { command_success_nodata(si, "Wallops is \2%s\2 for %s", metadata_find(mu, METADATA_USER, "private:killonauth") ? "ON" : "OFF", mu->name); return; } if (!strcasecmp(parv[1], "OFF")) { metadata_delete(mu, METADATA_USER, "private:killonauth"); command_success_nodata(si, _("Disabled Wallops for \2%s\2."), mu->name); snoop("KILLONAUTH:OFF: \2%s\2 by \2%s\2", mu->name, get_oper_name(si)); logcommand(si, CMDLOG_ADMIN, "KILLONAUTH %s OFF", mu->name); do_killonauth_all(mu, FALSE); } else if (!strcasecmp(parv[1], "ON")) { metadata_add(mu, METADATA_USER, "private:killonauth", "1"); command_success_nodata(si, _("Enabled killonauth for \2%s\2."), mu->name); snoop("KILLONAUTH:ON: \2%s\2 by \2%s\2", mu->name, get_oper_name(si)); logcommand(si, CMDLOG_ADMIN, "KILLONAUTH %s ON", mu->name); do_killonauth_all(mu, TRUE); } else { command_fail(si, fault_badparams, STR_INVALID_PARAMS, "KILLONAUTH"); command_fail(si, fault_badparams, _("Syntax: KILLONAUTH [ON|OFF]")); return; } return; } static void ns_cmd_listkillonauth(sourceinfo_t *si, int parc, char *parv[]) { const char *pattern; dictionary_iteration_state_t state; myuser_t *mu; metadata_t *md; int matches = 0; pattern = parc >= 1 ? parv[0] : "*"; snoop("LISTKILLONAUTH: \2%s\2 by \2%s\2", pattern, get_oper_name(si)); DICTIONARY_FOREACH(mu, &state, mulist) { md = metadata_find(mu, METADATA_USER, "private:killonauth"); if (md == NULL) continue; if (!match(pattern, mu->name)) { command_success_nodata(si, "- %-30s", mu->name); matches++; } } logcommand(si, CMDLOG_ADMIN, "LISTKILLONAUTH %s (%d matches)", pattern, matches); if (matches == 0) command_success_nodata(si, _("No killonauth users matched pattern \2%s\2"), pattern); else command_success_nodata(si, ngettext(N_("\2%d\2 match for pattern \2%s\2"), N_("\2%d\2 matches for pattern \2%s\2"), matches), matches, pattern); } static void killonauth_on_identify(void *vptr) { user_t *u = vptr; myuser_t *mu = u->myuser; metadata_t *md; if (!(md = metadata_find(mu, METADATA_USER, "private:killonauth"))) return; do_killonauth(u, TRUE); }