ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/nickserv/return.C
Revision: 1.2
Committed: Sat Jul 21 01:29:09 2007 UTC (19 years, 3 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.1: +2 -2 lines
Log Message:
- moved to new documentation system
- fixed small build error

File Contents

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