| 1 |
pippijn |
1.1 |
/* |
| 2 |
pippijn |
1.4 |
* Copyright © 2005 Alex Lambert |
| 3 |
pippijn |
1.2 |
* Rights to this code are as documented in doc/pod/license.pod. |
| 4 |
pippijn |
1.1 |
* |
| 5 |
|
|
* Implements nickserv RETURN. |
| 6 |
|
|
* |
| 7 |
pippijn |
1.4 |
* $Id: return.C,v 1.3 2007-07-21 13:23:20 pippijn Exp $ |
| 8 |
pippijn |
1.1 |
*/ |
| 9 |
|
|
|
| 10 |
|
|
#include "atheme.h" |
| 11 |
pippijn |
1.4 |
#include <ermyth/module.h> |
| 12 |
pippijn |
1.1 |
#include <account/myuser.h> |
| 13 |
|
|
|
| 14 |
pippijn |
1.4 |
static char const rcsid[] = "$Id: return.C,v 1.3 2007-07-21 13:23:20 pippijn Exp $"; |
| 15 |
pippijn |
1.1 |
|
| 16 |
pippijn |
1.4 |
REGISTER_MODULE ("nickserv/return", false, "The Ermyth Team <http://ermyth.schmorp.de>"); |
| 17 |
pippijn |
1.1 |
|
| 18 |
|
|
static void ns_cmd_return (sourceinfo_t *si, int parc, char *parv[]); |
| 19 |
|
|
|
| 20 |
pippijn |
1.4 |
command_t const ns_return = { "RETURN", N_("Returns a nickname to its owner."), PRIV_USER_ADMIN, 2, ns_cmd_return }; |
| 21 |
pippijn |
1.1 |
|
| 22 |
pippijn |
1.4 |
E cmdvec ns_cmdtree; |
| 23 |
|
|
E helpvec ns_helptree; |
| 24 |
pippijn |
1.1 |
|
| 25 |
pippijn |
1.4 |
bool |
| 26 |
|
|
_modinit (module *m) |
| 27 |
pippijn |
1.1 |
{ |
| 28 |
|
|
ns_cmdtree << ns_return; |
| 29 |
|
|
help_addentry (ns_helptree, "RETURN", "help/nickserv/return", NULL); |
| 30 |
pippijn |
1.4 |
|
| 31 |
|
|
return true; |
| 32 |
pippijn |
1.1 |
} |
| 33 |
|
|
|
| 34 |
|
|
void |
| 35 |
|
|
_moddeinit () |
| 36 |
|
|
{ |
| 37 |
|
|
ns_cmdtree >> ns_return; |
| 38 |
|
|
help_delentry (ns_helptree, "RETURN"); |
| 39 |
|
|
} |
| 40 |
|
|
|
| 41 |
|
|
static void |
| 42 |
|
|
ns_cmd_return (sourceinfo_t *si, int parc, char *parv[]) |
| 43 |
|
|
{ |
| 44 |
|
|
char *target = parv[0]; |
| 45 |
|
|
char *newmail = parv[1]; |
| 46 |
|
|
char *newpass; |
| 47 |
|
|
char oldmail[EMAILLEN]; |
| 48 |
|
|
myuser_t *mu; |
| 49 |
|
|
user_t *u; |
| 50 |
|
|
|
| 51 |
|
|
if (!target || !newmail) |
| 52 |
|
|
{ |
| 53 |
|
|
command_fail (si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "RETURN"); |
| 54 |
|
|
command_fail (si, fault_needmoreparams, _("Usage: RETURN <nickname> <e-mail address>")); |
| 55 |
|
|
return; |
| 56 |
|
|
} |
| 57 |
|
|
|
| 58 |
|
|
if (!(mu = myuser_find (target))) |
| 59 |
|
|
{ |
| 60 |
|
|
command_fail (si, fault_nosuch_target, _("\2%s\2 is not registered."), target); |
| 61 |
|
|
return; |
| 62 |
|
|
} |
| 63 |
|
|
|
| 64 |
|
|
if (is_soper (mu)) |
| 65 |
|
|
{ |
| 66 |
|
|
logcommand (si, CMDLOG_ADMIN, "failed RETURN %s to %s (is SOPER)", target, newmail); |
| 67 |
|
|
command_fail (si, fault_badparams, _("\2%s\2 belongs to a services operator; it cannot be returned."), target); |
| 68 |
|
|
return; |
| 69 |
|
|
} |
| 70 |
|
|
|
| 71 |
|
|
if ((strlen (newmail) > 32) || !validemail (newmail)) |
| 72 |
|
|
{ |
| 73 |
|
|
command_fail (si, fault_badparams, _("\2%s\2 is not a valid e-mail address."), newmail); |
| 74 |
|
|
return; |
| 75 |
|
|
} |
| 76 |
|
|
|
| 77 |
|
|
newpass = gen_pw (12); |
| 78 |
|
|
strlcpy (oldmail, mu->email, EMAILLEN); |
| 79 |
|
|
strlcpy (mu->email, newmail, EMAILLEN); |
| 80 |
|
|
|
| 81 |
|
|
if (!sendemail (si->su != NULL ? si->su : si->service->me, EMAIL_SENDPASS, mu, newpass)) |
| 82 |
|
|
{ |
| 83 |
|
|
strlcpy (mu->email, oldmail, EMAILLEN); |
| 84 |
|
|
command_fail (si, fault_emailfail, _("Sending email failed, nickname \2%s\2 remains with \2%s\2."), mu->name, mu->email); |
| 85 |
|
|
return; |
| 86 |
|
|
} |
| 87 |
|
|
|
| 88 |
pippijn |
1.4 |
mu->set_password (newpass); |
| 89 |
pippijn |
1.1 |
|
| 90 |
pippijn |
1.4 |
sfree (newpass); |
| 91 |
pippijn |
1.1 |
|
| 92 |
|
|
/* prevents users from "stealing it back" in the event of a takeover */ |
| 93 |
|
|
mu->del_metadata ("private:verify:emailchg:key"); |
| 94 |
|
|
mu->del_metadata ("private:verify:emailchg:newemail"); |
| 95 |
|
|
mu->del_metadata ("private:verify:emailchg:timestamp"); |
| 96 |
|
|
mu->del_metadata ("private:setpass:key"); |
| 97 |
|
|
/* log them out */ |
| 98 |
|
|
while (!mu->logins.empty ()) |
| 99 |
|
|
{ |
| 100 |
|
|
u = mu->logins.back (); |
| 101 |
pippijn |
1.4 |
if (!phandler->ircd_on_logout (u->nick, mu->name, NULL)) |
| 102 |
pippijn |
1.1 |
{ |
| 103 |
|
|
u->myuser = NULL; |
| 104 |
|
|
mu->logins.erase (u); |
| 105 |
|
|
} |
| 106 |
|
|
} |
| 107 |
|
|
mu->flags |= MU_NOBURSTLOGIN; |
| 108 |
|
|
|
| 109 |
|
|
wallops ("%s returned the nickname \2%s\2 to \2%s\2", get_oper_name (si), target, newmail); |
| 110 |
|
|
snoop ("RETURN: \2%s\2 to \2%s\2 by \2%s\2", target, newmail, get_oper_name (si)); |
| 111 |
|
|
logcommand (si, CMDLOG_ADMIN | LG_REGISTER, "RETURN %s to %s", target, newmail); |
| 112 |
|
|
command_success_nodata (si, _("The e-mail address for \2%s\2 has been set to \2%s\2"), target, newmail); |
| 113 |
|
|
command_success_nodata (si, _("A random password has been set; it has been sent to \2%s\2."), newmail); |
| 114 |
|
|
} |