/** * setpass.C: This file contains code for the NickServ SETPASS function. * * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team * Rights to this code are as documented in COPYING. * * * Portions of this file were derived from sources bearing the following license: * Copyright © 2007 Atheme Development Group * Rights to this code are as documented in doc/pod/license.pod. * * $Id: setpass.C,v 1.9 2007/09/22 14:27:28 pippijn Exp $ */ #include "atheme.h" #include #include #include static char const rcsid[] = "$Id: setpass.C,v 1.9 2007/09/22 14:27:28 pippijn Exp $"; REGISTER_MODULE ("nickserv/setpass", false, "The Ermyth Team "); static void ns_cmd_setpass (sourceinfo_t *si, int parc, char *parv[]); command_t const ns_setpass = { "SETPASS", N_("Changes a password using an authcode."), AC_NONE, 3, ns_cmd_setpass }; E cmdvec ns_cmdtree; E helpvec ns_helptree; static void ns_cmd_setpass (sourceinfo_t *si, int parc, char *parv[]) { myuser_t *mu; metadata *md; char *nick = parv[0]; char *key = parv[1]; char *password = parv[2]; if (!nick || !key || !password) { command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "SETPASS"); command_fail (si, fault::needmoreparams, _("Syntax: SETPASS ")); return; } if (strchr (password, ' ')) { command_fail (si, fault::badparams, STR_INVALID_PARAMS, "SETPASS"); command_fail (si, fault::badparams, _("Syntax: SETPASS ")); return; } if (!(mu = myuser_t::find (nick))) { command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), nick); return; } if (strlen (password) > 32) { command_fail (si, fault::badparams, STR_INVALID_PARAMS, "SETPASS"); return; } if (!strcasecmp (password, mu->name)) { command_fail (si, fault::badparams, _("You cannot use your nickname as a password.")); command_fail (si, fault::badparams, _("Syntax: SETPASS ")); return; } md = mu->find_metadata ("private:setpass:key"); if (md != NULL && crypto::verify_password (key, md->value)) { snoop ("SETPASS:VS: \2%s\2 by \2%s\2", mu->name, get_source_name (si)); logcommand (si, CMDLOG_SET, "SETPASS %s", mu->name); mu->set_password (password); mu->del_metadata ("private:setpass:key"); command_success_nodata (si, _("The password for \2%s\2 has been changed to \2%s\2. Please write this down for future reference."), mu->name, password); return; } if (md != NULL) { snoop ("SETPASS:VF: \2%s\2 by \2%s\2", mu->name, get_source_name (si)); logcommand (si, CMDLOG_SET, "failed SETPASS (invalid key)"); } command_fail (si, fault::badparams, _("Verification failed. Invalid key for \2%s\2."), mu->name); return; } static void clear_setpass_key (user_t *u) { myuser_t *mu = u->myuser; metadata *md; if (!(md = mu->find_metadata ("private:setpass:key"))) return; mu->del_metadata ("private:setpass:key"); notice (nicksvs.nick, u->nick, "Warning: SENDPASS had been used to mail you a password recovery " "key. Since you have identified, that key is no longer valid."); } bool _modinit (module *m) { user_t::callback.identify.attach (clear_setpass_key); ns_cmdtree << ns_setpass; help_addentry (ns_helptree, "SETPASS", "help/nickserv/setpass", NULL); return true; } void _moddeinit () { user_t::callback.identify.detach (clear_setpass_key); ns_cmdtree >> ns_setpass; help_delentry (ns_helptree, "SETPASS"); }