1 |
/** |
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 |
* Copyright © 2005 Patrick Fish, et al. |
10 |
* Rights to this code are as documented in doc/pod/license.pod. |
11 |
* |
12 |
* $Id: resetpass.C,v 1.8 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: resetpass.C,v 1.8 2007-09-16 18:54:43 pippijn Exp $"; |
20 |
|
21 |
REGISTER_MODULE ("nickserv/resetpass", false, "The Ermyth Team <http://ermyth.xinutec.org>"); |
22 |
|
23 |
static void ns_cmd_resetpass (sourceinfo_t *si, int parc, char *parv[]); |
24 |
|
25 |
command_t const ns_resetpass = { "RESETPASS", N_("Resets a nickname password."), PRIV_USER_ADMIN, 1, ns_cmd_resetpass }; |
26 |
|
27 |
E cmdvec ns_cmdtree; |
28 |
E helpvec ns_helptree; |
29 |
|
30 |
bool |
31 |
_modinit (module *m) |
32 |
{ |
33 |
ns_cmdtree << ns_resetpass; |
34 |
help_addentry (ns_helptree, "RESETPASS", "help/nickserv/resetpass", NULL); |
35 |
|
36 |
return true; |
37 |
} |
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 |
metadata *md; |
51 |
char *name = parv[0]; |
52 |
char *newpass; |
53 |
|
54 |
if (!name) |
55 |
{ |
56 |
command_fail (si, fault::needmoreparams, STR_INVALID_PARAMS, "RESETPASS"); |
57 |
command_fail (si, fault::needmoreparams, _("Syntax: RESETPASS <nickname>")); |
58 |
return; |
59 |
} |
60 |
|
61 |
if (!(mu = myuser_t::find (name))) |
62 |
{ |
63 |
command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), name); |
64 |
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 |
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 |
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 |
mu->set_password (newpass); |
81 |
sfree (newpass); |
82 |
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 |
command_fail (si, fault::badparams, _("This operation cannot be performed on %s, because the nickname has been marked by %s."), name, md->value); |
91 |
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 |
mu->set_password (newpass); |
97 |
sfree (newpass); |
98 |
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 |
} |