ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/modules/nickserv/return.C
Revision: 1.8
Committed: Sat Sep 22 14:27:28 2007 UTC (16 years, 8 months 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

# Content
1 /**
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 * Copyright © 2005 Alex Lambert
10 * Rights to this code are as documented in doc/pod/license.pod.
11 *
12 * $Id: return.C,v 1.7 2007-09-16 18:54:43 pippijn Exp $
13 */
14
15 #include "atheme.h"
16 #include <ermyth/module.h>
17 #include <account/myuser.h>
18
19 static char const rcsid[] = "$Id: return.C,v 1.7 2007-09-16 18:54:43 pippijn Exp $";
20
21 REGISTER_MODULE ("nickserv/return", false, "The Ermyth Team <http://ermyth.xinutec.org>");
22
23 static void ns_cmd_return (sourceinfo_t *si, int parc, char *parv[]);
24
25 command_t const ns_return = { "RETURN", N_("Returns a nickname to its owner."), PRIV_USER_ADMIN, 2, ns_cmd_return };
26
27 E cmdvec ns_cmdtree;
28 E helpvec ns_helptree;
29
30 bool
31 _modinit (module *m)
32 {
33 ns_cmdtree << ns_return;
34 help_addentry (ns_helptree, "RETURN", "help/nickserv/return", NULL);
35
36 return true;
37 }
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 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "RETURN");
59 command_fail (si, fault::needmoreparams, _("Usage: RETURN <nickname> <e-mail address>"));
60 return;
61 }
62
63 if (!(mu = myuser_t::find (target)))
64 {
65 command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), target);
66 return;
67 }
68
69 if (is_soper (mu))
70 {
71 logcommand (si, CMDLOG_ADMIN, "failed RETURN %s to %s (is SOPER)", target, newmail);
72 command_fail (si, fault::badparams, _("\2%s\2 belongs to a services operator; it cannot be returned."), target);
73 return;
74 }
75
76 if ((strlen (newmail) > 32) || !validemail (newmail))
77 {
78 command_fail (si, fault::badparams, _("\2%s\2 is not a valid e-mail address."), newmail);
79 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 command_fail (si, fault::emailfail, _("Sending email failed, nickname \2%s\2 remains with \2%s\2."), mu->name, mu->email);
90 return;
91 }
92
93 mu->set_password (newpass);
94
95 sfree (newpass);
96
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 if (!phandler->ircd_on_logout (u->nick, mu->name, NULL))
107 {
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 }