ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/nickserv/resetpass.C
Revision: 1.9
Committed: Sat Sep 22 14:27:28 2007 UTC (19 years ago) by pippijn
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.8: +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.8 /**
2     * resetpass.C: This file contains code for nickserv RESETPASS
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 Patrick Fish, et al.
10 pippijn 1.2 * Rights to this code are as documented in doc/pod/license.pod.
11 pippijn 1.1 *
12 pippijn 1.9 * $Id: resetpass.C,v 1.8 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.9 static char const rcsid[] = "$Id: resetpass.C,v 1.8 2007-09-16 18:54:43 pippijn Exp $";
20 pippijn 1.1
21 pippijn 1.9 REGISTER_MODULE ("nickserv/resetpass", false, "The Ermyth Team <http://ermyth.xinutec.org>");
22 pippijn 1.1
23     static void ns_cmd_resetpass (sourceinfo_t *si, int parc, char *parv[]);
24    
25 pippijn 1.4 command_t const ns_resetpass = { "RESETPASS", N_("Resets a nickname password."), PRIV_USER_ADMIN, 1, ns_cmd_resetpass };
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_resetpass;
34     help_addentry (ns_helptree, "RESETPASS", "help/nickserv/resetpass", NULL);
35 pippijn 1.4
36     return true;
37 pippijn 1.1 }
38    
39     void
40     _moddeinit ()
41     {
42     ns_cmdtree >> ns_resetpass;
43     help_delentry (ns_helptree, "RESETPASS");
44     }
45    
46     static void
47     ns_cmd_resetpass (sourceinfo_t *si, int parc, char *parv[])
48     {
49     myuser_t *mu;
50 pippijn 1.7 metadata *md;
51 pippijn 1.1 char *name = parv[0];
52     char *newpass;
53    
54     if (!name)
55     {
56 pippijn 1.6 command_fail (si, fault::needmoreparams, STR_INVALID_PARAMS, "RESETPASS");
57     command_fail (si, fault::needmoreparams, _("Syntax: RESETPASS <nickname>"));
58 pippijn 1.1 return;
59     }
60    
61 pippijn 1.5 if (!(mu = myuser_t::find (name)))
62 pippijn 1.1 {
63 pippijn 1.6 command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), name);
64 pippijn 1.1 return;
65     }
66    
67     if (is_soper (mu) && !has_priv (si, PRIV_ADMIN))
68     {
69     logcommand (si, CMDLOG_ADMIN, "failed RESETPASS %s (is SOPER)", name);
70 pippijn 1.6 command_fail (si, fault::badparams, _("\2%s\2 belongs to a services operator; you need %s privilege to reset the password."), name, PRIV_ADMIN);
71 pippijn 1.1 return;
72     }
73    
74     if ((md = mu->find_metadata ("private:mark:setter")) && has_priv (si, PRIV_MARK))
75     {
76     logcommand (si, CMDLOG_ADMIN, "RESETPASS %s (overriding mark by %s)", name, md->value);
77     command_success_nodata (si, _("Overriding MARK placed by %s on the nickname %s."), md->value, name);
78     newpass = gen_pw (12);
79     command_success_nodata (si, _("The password for the nickname %s has been changed to %s."), name, newpass);
80 pippijn 1.4 mu->set_password (newpass);
81     sfree (newpass);
82 pippijn 1.1 wallops ("%s reset the password for the \2MARKED\2 nickname %s.", get_oper_name (si), name);
83     snoop ("RESETPASS: \2%s\2 by \2%s\2", name, get_oper_name (si));
84     return;
85     }
86    
87     if ((md = mu->find_metadata ("private:mark:setter")))
88     {
89     logcommand (si, CMDLOG_ADMIN, "failed RESETPASS %s (marked by %s)", name, md->value);
90 pippijn 1.6 command_fail (si, fault::badparams, _("This operation cannot be performed on %s, because the nickname has been marked by %s."), name, md->value);
91 pippijn 1.1 return;
92     }
93    
94     newpass = gen_pw (12);
95     command_success_nodata (si, _("The password for the nickname %s has been changed to %s."), name, newpass);
96 pippijn 1.4 mu->set_password (newpass);
97     sfree (newpass);
98 pippijn 1.1 mu->del_metadata ("private:setpass:key");
99    
100     wallops ("%s reset the password for the nickname %s", get_oper_name (si), name);
101     snoop ("RESETPASS: \2%s\2 by \2%s\2", name, get_oper_name (si));
102     logcommand (si, CMDLOG_ADMIN, "RESETPASS %s", name);
103     }