ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/nickserv/return.C
Revision: 1.8
Committed: Sat Sep 22 14:27:28 2007 UTC (19 years, 1 month ago) by pippijn
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.7: +3 -3 lines
Log Message:
split up ermyth into ermyth-modules, libermyth (currently just ermyth-util) and ermyth-core

File Contents

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