/** * return.C: Implements nickserv RETURN. * * 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 Alex Lambert * Rights to this code are as documented in doc/pod/license.pod. * * $Id: return.C,v 1.8 2007/09/22 14:27:28 pippijn Exp $ */ #include "atheme.h" #include #include static char const rcsid[] = "$Id: return.C,v 1.8 2007/09/22 14:27:28 pippijn Exp $"; REGISTER_MODULE ("nickserv/return", false, "The Ermyth Team "); static void ns_cmd_return (sourceinfo_t *si, int parc, char *parv[]); command_t const ns_return = { "RETURN", N_("Returns a nickname to its owner."), PRIV_USER_ADMIN, 2, ns_cmd_return }; E cmdvec ns_cmdtree; E helpvec ns_helptree; bool _modinit (module *m) { ns_cmdtree << ns_return; help_addentry (ns_helptree, "RETURN", "help/nickserv/return", NULL); return true; } void _moddeinit () { ns_cmdtree >> ns_return; help_delentry (ns_helptree, "RETURN"); } static void ns_cmd_return (sourceinfo_t *si, int parc, char *parv[]) { char *target = parv[0]; char *newmail = parv[1]; char *newpass; char oldmail[EMAILLEN]; myuser_t *mu; user_t *u; if (!target || !newmail) { command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "RETURN"); command_fail (si, fault::needmoreparams, _("Usage: RETURN ")); return; } if (!(mu = myuser_t::find (target))) { command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), target); return; } if (is_soper (mu)) { logcommand (si, CMDLOG_ADMIN, "failed RETURN %s to %s (is SOPER)", target, newmail); command_fail (si, fault::badparams, _("\2%s\2 belongs to a services operator; it cannot be returned."), target); return; } if ((strlen (newmail) > 32) || !validemail (newmail)) { command_fail (si, fault::badparams, _("\2%s\2 is not a valid e-mail address."), newmail); return; } newpass = gen_pw (12); strlcpy (oldmail, mu->email, EMAILLEN); strlcpy (mu->email, newmail, EMAILLEN); if (!sendemail (si->su != NULL ? si->su : si->service->me, EMAIL_SENDPASS, mu, newpass)) { strlcpy (mu->email, oldmail, EMAILLEN); command_fail (si, fault::emailfail, _("Sending email failed, nickname \2%s\2 remains with \2%s\2."), mu->name, mu->email); return; } mu->set_password (newpass); sfree (newpass); /* prevents users from "stealing it back" in the event of a takeover */ mu->del_metadata ("private:verify:emailchg:key"); mu->del_metadata ("private:verify:emailchg:newemail"); mu->del_metadata ("private:verify:emailchg:timestamp"); mu->del_metadata ("private:setpass:key"); /* log them out */ while (!mu->logins.empty ()) { u = mu->logins.back (); if (!phandler->ircd_on_logout (u->nick, mu->name, NULL)) { u->myuser = NULL; mu->logins.erase (u); } } mu->flags |= MU_NOBURSTLOGIN; wallops ("%s returned the nickname \2%s\2 to \2%s\2", get_oper_name (si), target, newmail); snoop ("RETURN: \2%s\2 to \2%s\2 by \2%s\2", target, newmail, get_oper_name (si)); logcommand (si, CMDLOG_ADMIN | LG_REGISTER, "RETURN %s to %s", target, newmail); command_success_nodata (si, _("The e-mail address for \2%s\2 has been set to \2%s\2"), target, newmail); command_success_nodata (si, _("A random password has been set; it has been sent to \2%s\2."), newmail); }