/** * verify.C: This file contains code for the NickServ VERIFY 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 © 2005 Atheme Development Group * Rights to this code are as documented in doc/pod/license.pod. * * $Id: verify.C,v 1.9 2007/09/22 14:27:28 pippijn Exp $ */ #include "atheme.h" #include #include static char const rcsid[] = "$Id: verify.C,v 1.9 2007/09/22 14:27:28 pippijn Exp $"; REGISTER_MODULE ("nickserv/verify", false, "The Ermyth Team "); static void ns_cmd_verify (sourceinfo_t *si, int parc, char *parv[]); static void ns_cmd_fverify (sourceinfo_t *si, int parc, char *parv[]); command_t const ns_verify = { "VERIFY", N_("Verifies a nickname registration."), AC_NONE, 3, ns_cmd_verify }; command_t const ns_fverify = { "FVERIFY", N_("Forcefully verifies a nickname registration."), PRIV_USER_ADMIN, 2, ns_cmd_fverify }; E cmdvec ns_cmdtree; E helpvec ns_helptree; bool _modinit (module *m) { ns_cmdtree << ns_verify; help_addentry (ns_helptree, "VERIFY", "help/nickserv/verify", NULL); ns_cmdtree << ns_fverify; help_addentry (ns_helptree, "FVERIFY", "help/nickserv/fverify", NULL); return true; } void _moddeinit () { ns_cmdtree >> ns_verify; help_delentry (ns_helptree, "VERIFY"); ns_cmdtree >> ns_fverify; help_delentry (ns_helptree, "FVERIFY"); } static void ns_cmd_verify (sourceinfo_t *si, int parc, char *parv[]) { myuser_t *mu; metadata *md; char *op = parv[0]; char *nick = parv[1]; char *key = parv[2]; myuser_t::login_vector::iterator it, it_end; if (!op || !nick || !key) { command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "VERIFY"); command_fail (si, fault::needmoreparams, _("Syntax: VERIFY ")); return; } if (!(mu = myuser_t::find (nick))) { command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), nick); return; } /* forcing users to log in before we verify * prevents some information leaks */ if (!(si->smu == mu)) { command_fail (si, fault::badparams, _("Please log in before attempting to verify your registration.")); return; } if (!strcasecmp (op, "REGISTER")) { if (!(mu->flags & MU_WAITAUTH) || !(md = mu->find_metadata ("private:verify:register:key"))) { command_fail (si, fault::badparams, _("\2%s\2 is not awaiting authorization."), nick); return; } if (!strcasecmp (key, md->value)) { mu->flags &= ~MU_WAITAUTH; snoop ("REGISTER:VS: \2%s\2 by \2%s\2", mu->email, get_source_name (si)); logcommand (si, CMDLOG_SET, "VERIFY REGISTER (email: %s)", mu->email); mu->del_metadata ("private:verify:register:key"); mu->del_metadata ("private:verify:register:timestamp"); command_success_nodata (si, _("\2%s\2 has now been verified."), mu->name); command_success_nodata (si, _("Thank you for verifying your e-mail address! You have taken steps in ensuring that your registrations are not exploited.")); for (it = mu->logins.begin (), it_end = mu->logins.end (); it != it_end; ++it) phandler->ircd_on_login ((*it)->nick, mu->name, NULL); return; } snoop ("REGISTER:VF: \2%s\2 by \2%s\2", mu->email, get_source_name (si)); logcommand (si, CMDLOG_SET, "failed VERIFY REGISTER (invalid key)"); command_fail (si, fault::badparams, _("Verification failed. Invalid key for \2%s\2."), mu->name); return; } else if (!strcasecmp (op, "EMAILCHG")) { if (!(md = mu->find_metadata ("private:verify:emailchg:key"))) { command_fail (si, fault::badparams, _("\2%s\2 is not awaiting authorization."), nick); return; } if (!strcasecmp (key, md->value)) { md = mu->find_metadata ("private:verify:emailchg:newemail"); strlcpy (mu->email, md->value, EMAILLEN); snoop ("SET:EMAIL:VS: \2%s\2 by \2%s\2", mu->email, get_source_name (si)); logcommand (si, CMDLOG_SET, "VERIFY EMAILCHG (email: %s)", mu->email); mu->del_metadata ("private:verify:emailchg:key"); mu->del_metadata ("private:verify:emailchg:newemail"); mu->del_metadata ("private:verify:emailchg:timestamp"); command_success_nodata (si, _("\2%s\2 has now been verified."), mu->email); return; } snoop ("REGISTER:VF: \2%s\2 by \2%s\2", mu->email, get_source_name (si)); logcommand (si, CMDLOG_SET, "failed VERIFY EMAILCHG (invalid key)"); command_fail (si, fault::badparams, _("Verification failed. Invalid key for \2%s\2."), mu->name); return; } else { command_fail (si, fault::badparams, _("Invalid operation specified for \2VERIFY\2.")); command_fail (si, fault::badparams, _("Please double-check your verification e-mail.")); return; } } static void ns_cmd_fverify (sourceinfo_t *si, int parc, char *parv[]) { myuser_t *mu; metadata *md; char *op = parv[0]; char *nick = parv[1]; myuser_t::login_vector::iterator it, it_end; if (!op || !nick) { command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "FVERIFY"); command_fail (si, fault::needmoreparams, _("Syntax: FVERIFY ")); return; } if (!(mu = myuser_t::find (nick))) { command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), nick); return; } if (!strcasecmp (op, "REGISTER")) { if (!(mu->flags & MU_WAITAUTH) || !(md = mu->find_metadata ("private:verify:register:key"))) { command_fail (si, fault::badparams, _("\2%s\2 is not awaiting authorization."), nick); return; } mu->flags &= ~MU_WAITAUTH; snoop ("REGISTER:VS: \2%s\2 for \2%s\2 by \2%s\2", mu->email, mu->name, get_source_name (si)); logcommand (si, CMDLOG_REGISTER, "FVERIFY REGISTER %s (email: %s)", mu->name, mu->email); mu->del_metadata ("private:verify:register:key"); mu->del_metadata ("private:verify:register:timestamp"); command_success_nodata (si, _("\2%s\2 has now been verified."), mu->name); for (it = mu->logins.begin (), it_end = mu->logins.end (); it != it_end; ++it) phandler->ircd_on_login ((*it)->nick, mu->name, NULL); return; } else if (!strcasecmp (op, "EMAILCHG")) { if (!(md = mu->find_metadata ("private:verify:emailchg:key"))) { command_fail (si, fault::badparams, _("\2%s\2 is not awaiting authorization."), nick); return; } md = mu->find_metadata ("private:verify:emailchg:newemail"); strlcpy (mu->email, md->value, EMAILLEN); snoop ("SET:EMAIL:VS: \2%s\2 for \2%s\2 by \2%s\2", mu->email, mu->name, get_source_name (si)); logcommand (si, CMDLOG_REGISTER, "FVERIFY EMAILCHG %s (email: %s)", mu->name, mu->email); mu->del_metadata ("private:verify:emailchg:key"); mu->del_metadata ("private:verify:emailchg:newemail"); mu->del_metadata ("private:verify:emailchg:timestamp"); command_success_nodata (si, _("\2%s\2 has now been verified."), mu->email); return; } else { command_fail (si, fault::badparams, _("Invalid operation specified for \2FVERIFY\2.")); command_fail (si, fault::badparams, _("Valid operations are REGISTER and EMAILCHG.")); return; } }