Debian Codegraph @

modules/nickserv/resetpass.c

raw
1 /*
2 * Copyright (c) 2005 Patrick Fish, et al.
3 * Rights to this code are as documented in doc/LICENSE.
4 *
5 * This file contains code for nickserv RESETPASS
6 *
7 */
8
9 #include "atheme.h"
10
11 DECLARE_MODULE_V1
12 (
13 "nickserv/resetpass", false, _modinit, _moddeinit,
14 PACKAGE_STRING,
15 VENDOR_STRING
16 );
17
18 static void ns_cmd_resetpass(sourceinfo_t *si, int parc, char *parv[]);
19
20 command_t ns_resetpass = { "RESETPASS", N_("Resets an account password."), PRIV_USER_ADMIN, 1, ns_cmd_resetpass, { .path = "nickserv/resetpass" } };
21
22 void _modinit(module_t *m)
23 {
24 service_named_bind_command("nickserv", &ns_resetpass);
25 }
26
27 void _moddeinit(module_unload_intent_t intent)
28 {
29 service_named_unbind_command("nickserv", &ns_resetpass);
30 }
31
32 static void ns_cmd_resetpass(sourceinfo_t *si, int parc, char *parv[])
33 {
34 myuser_t *mu;
35 metadata_t *md;
36 char *name = parv[0];
37 char *newpass;
38
39 if (!name)
40 {
41 command_fail(si, fault_needmoreparams, STR_INVALID_PARAMS, "RESETPASS");
42 command_fail(si, fault_needmoreparams, _("Syntax: RESETPASS <account>"));
43 return;
44 }
45
46 if (!(mu = myuser_find_by_nick(name)))
47 {
48 command_fail(si, fault_nosuch_target, _("\2%s\2 is not registered."), name);
49 return;
50 }
51
52 if (is_soper(mu) && !has_priv(si, PRIV_ADMIN))
53 {
54 logcommand(si, CMDLOG_ADMIN, "failed RESETPASS \2%s\2 (is SOPER)", name);
55 command_fail(si, fault_badparams, _("\2%s\2 belongs to a services operator; you need %s privilege to reset the password."), name, PRIV_ADMIN);
56 return;
57 }
58
59 if ((md = metadata_find(mu, "private:mark:setter")))
60 {
61 if (has_priv(si, PRIV_MARK))
62 {
63 wallops("%s reset the password for the \2MARKED\2 account %s.", get_oper_name(si), entity(mu)->name);
64 logcommand(si, CMDLOG_ADMIN, "RESETPASS: \2%s\2 (overriding mark by \2%s\2)", entity(mu)->name, md->value);
65 command_success_nodata(si, _("Overriding MARK placed by %s on the account %s."), md->value, entity(mu)->name);
66 }
67 else
68 {
69 logcommand(si, CMDLOG_ADMIN, "failed RESETPASS \2%s\2 (marked by \2%s\2)", entity(mu)->name, md->value);
70 command_fail(si, fault_badparams, _("This operation cannot be performed on %s, because the account has been marked by %s."), entity(mu)->name, md->value);
71 return;
72 }
73 }
74 else
75 {
76 wallops("%s reset the password for the account %s", get_oper_name(si), entity(mu)->name);
77 logcommand(si, CMDLOG_ADMIN, "RESETPASS: \2%s\2", entity(mu)->name);
78 }
79
80 newpass = random_string(12);
81 metadata_delete(mu, "private:setpass:key");
82 metadata_add(mu, "private:sendpass:sender", get_oper_name(si));
83 metadata_add(mu, "private:sendpass:timestamp", number_to_string(time(NULL)));
84 set_password(mu, newpass);
85 command_success_nodata(si, _("The password for \2%s\2 has been changed to \2%s\2."), entity(mu)->name, newpass);
86
87 free(newpass);
88
89 if (mu->flags & MU_NOPASSWORD)
90 {
91 mu->flags &= ~MU_NOPASSWORD;
92 command_success_nodata(si, _("The \2%s\2 flag has been removed for account \2%s\2."), "NOPASSWORD", entity(mu)->name);
93 }
94 }
95
96 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
97 * vim:ts=8
98 * vim:sw=8
99 * vim:noexpandtab
100 */