Debian Codegraph @

modules/nickserv/sendpass_user.c

raw
1 /*
2 * Copyright (c) 2005 William Pitcock, et al.
3 * Rights to this code are as documented in doc/LICENSE.
4 *
5 * This file contains code for the CService SENDPASS function.
6 *
7 */
8
9 #include "atheme.h"
10
11 DECLARE_MODULE_V1
12 (
13 "nickserv/sendpass_user", false, _modinit, _moddeinit,
14 PACKAGE_STRING,
15 VENDOR_STRING
16 );
17
18 static void ns_cmd_sendpass(sourceinfo_t *si, int parc, char *parv[]);
19
20 command_t ns_sendpass = { "SENDPASS", N_("Email registration passwords."), AC_NONE, 2, ns_cmd_sendpass, { .path = "nickserv/sendpass_user" } };
21
22 void _modinit(module_t *m)
23 {
24 MODULE_CONFLICT(m, "nickserv/sendpass")
25 MODULE_TRY_REQUEST_DEPENDENCY(m, "nickserv/setpass");
26
27 service_named_bind_command("nickserv", &ns_sendpass);
28 }
29
30 void _moddeinit(module_unload_intent_t intent)
31 {
32 service_named_unbind_command("nickserv", &ns_sendpass);
33 }
34
35 enum specialoperation
36 {
37 op_none,
38 op_force,
39 op_clear
40 };
41
42 static void ns_cmd_sendpass(sourceinfo_t *si, int parc, char *parv[])
43 {
44 myuser_t *mu;
45 char *name = parv[0];
46 char *key;
47 enum specialoperation op = op_none;
48 bool ismarked = false;
49
50 if (!name)
51 {
52 command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "SENDPASS");
53 command_fail(si, fault_needmoreparams, _("Syntax: SENDPASS <account>"));
54 return;
55 }
56
57 if (parc > 1)
58 {
59 if (!has_priv(si, PRIV_USER_SENDPASS))
60 {
61 command_fail(si, fault_noprivs, _("You are not authorized to perform this operation."));
62 return;
63 }
64 else if (!strcasecmp(parv[1], "FORCE"))
65 op = op_force;
66 else if (!strcasecmp(parv[1], "CLEAR"))
67 op = op_clear;
68 else
69 {
70 command_fail(si, fault_badparams, STR_INVALID_PARAMS, "SENDPASS");
71 command_fail(si, fault_badparams, _("Syntax: SENDPASS <account> [FORCE|CLEAR]"));
72 return;
73 }
74 }
75
76 if (!(mu = myuser_find_by_nick(name)))
77 {
78 command_fail(si, fault_nosuch_target, _("\2%s\2 is not registered."), name);
79 return;
80 }
81
82 if (mu->flags & MU_WAITAUTH)
83 {
84 command_fail(si, fault_badparams, _("\2%s\2 is not verified."), entity(mu)->name);
85 return;
86 }
87
88 if (metadata_find(mu, "private:mark:setter"))
89 {
90 ismarked = true;
91 /* don't want to disclose this, so just go ahead... */
92 }
93
94 if (op == op_clear)
95 {
96 if (metadata_find(mu, "private:setpass:key"))
97 {
98 logcommand(si, CMDLOG_ADMIN, "SENDPASS:CLEAR: \2%s\2", entity(mu)->name);
99 metadata_delete(mu, "private:setpass:key");
100 metadata_delete(mu, "private:sendpass:sender");
101 metadata_delete(mu, "private:sendpass:timestamp");
102 command_success_nodata(si, _("The password change key for \2%s\2 has been cleared."), entity(mu)->name);
103 }
104 else
105 command_fail(si, fault_nochange, _("\2%s\2 did not have a password change key outstanding."), entity(mu)->name);
106 return;
107 }
108
109 if (MOWGLI_LIST_LENGTH(&mu->logins) > 0)
110 {
111 if (si->smu == mu)
112 command_fail(si, fault_already_authed, _("You are logged in and can change your password using the SET PASSWORD command."));
113 else
114 command_fail(si, fault_noprivs, _("This operation cannot be performed on %s, because someone is logged in to it."), entity(mu)->name);
115 return;
116 }
117
118 if (metadata_find(mu, "private:freeze:freezer"))
119 {
120 command_fail(si, fault_noprivs, _("%s has been frozen by the %s administration."), entity(mu)->name, me.netname);
121 return;
122 }
123
124 if (metadata_find(mu, "private:setpass:key"))
125 {
126 command_fail(si, fault_alreadyexists, _("\2%s\2 already has a password change key outstanding."), entity(mu)->name);
127 if (has_priv(si, PRIV_USER_SENDPASS))
128 command_fail(si, fault_alreadyexists, _("Use SENDPASS %s CLEAR to clear it so that a new one can be sent."), entity(mu)->name);
129 return;
130 }
131
132 key = random_string(12);
133 if (sendemail(si->su != NULL ? si->su : si->service->me, mu, EMAIL_SETPASS, mu->email, key))
134 {
135 if (ismarked)
136 wallops("%s sent the password for the \2MARKED\2 account %s.", get_oper_name(si), entity(mu)->name);
137 logcommand(si, CMDLOG_ADMIN, "SENDPASS: \2%s\2 (change key)", name);
138 metadata_add(mu, "private:setpass:key", crypt_string(key, gen_salt()));
139 metadata_add(mu, "private:sendpass:sender", get_oper_name(si));
140 metadata_add(mu, "private:sendpass:timestamp", number_to_string(time(NULL)));
141 command_success_nodata(si, _("The password change key for \2%s\2 has been sent to the corresponding email address."), entity(mu)->name);
142 }
143 else
144 command_fail(si, fault_emailfail, _("Email send failed."));
145 free(key);
146 }
147
148 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
149 * vim:ts=8
150 * vim:sw=8
151 * vim:noexpandtab
152 */