Debian Codegraph @

modules/nickserv/set_nopassword.c

raw
1 /*
2 * Copyright (c) 2005 William Pitcock <nenolod -at- nenolod.net>
3 * Copyright (c) 2007 Jilles Tjoelker
4 * Copyright (c) 2015 Max Teufel <[email protected]>
5 * Rights to this code are as documented in doc/LICENSE.
6 *
7 * Allows you to opt-out of password-based authentication methods.
8 *
9 */
10
11 #include "atheme.h"
12 #include "uplink.h"
13 #include "list_common.h"
14 #include "list.h"
15
16 DECLARE_MODULE_V1
17 (
18 "nickserv/set_nopassword", false, _modinit, _moddeinit,
19 PACKAGE_STRING,
20 "Zohlai Development Group"
21 );
22
23 mowgli_patricia_t **ns_set_cmdtree;
24
25 static void ns_cmd_set_nopassword(sourceinfo_t *si, int parc, char *parv[]);
26
27 command_t ns_set_nopassword = { "NOPASSWORD", N_("Allows you to disable any password-based authentication methods except for XMLRPC/JSONRPC."), AC_NONE, 1, ns_cmd_set_nopassword, { .path = "nickserv/set_nopassword" } };
28
29 static bool has_nopassword(const mynick_t *mn, const void *arg)
30 {
31 myuser_t *mu = mn->owner;
32
33 return ( mu->flags & MU_NOPASSWORD ) == MU_NOPASSWORD;
34 }
35
36 void _modinit(module_t *m)
37 {
38 MODULE_TRY_REQUEST_SYMBOL(m, ns_set_cmdtree, "nickserv/set_core", "ns_set_cmdtree");
39
40 command_add(&ns_set_nopassword, *ns_set_cmdtree);
41
42 use_nslist_main_symbols(m);
43
44 static list_param_t nopassword;
45 nopassword.opttype = OPT_BOOL;
46 nopassword.is_match = has_nopassword;
47
48 list_register("nopassword", &nopassword);
49 }
50
51 void _moddeinit(module_unload_intent_t intent)
52 {
53 command_delete(&ns_set_nopassword, *ns_set_cmdtree);
54
55 list_unregister("nopassword");
56 }
57
58 /* SET NOPASSWORD [ON|OFF] */
59 static void ns_cmd_set_nopassword(sourceinfo_t *si, int parc, char *parv[])
60 {
61 char *setting = parv[0];
62
63 if (!setting)
64 {
65 command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "NOPASSWORD");
66 return;
67 }
68
69 if (!strcasecmp("ON", setting))
70 {
71 if (MU_NOPASSWORD & si->smu->flags)
72 {
73 command_fail(si, fault_nochange, _("The \2%s\2 flag is already set for account \2%s\2."), "NOPASSWORD", entity(si->smu)->name);
74 return;
75 }
76
77 if (si->smu->cert_fingerprints.head == NULL && metadata_find(si->smu, "private:pubkey") == NULL && metadata_find(si->smu, "pubkey") == NULL && metadata_find(si->smu, "ecdsa-nist521p-pubkey") == NULL)
78 {
79 command_fail(si, fault_nochange, _("You are trying to enable NoPassword without any possibility to identify without a password."));
80 return;
81 }
82
83 logcommand(si, CMDLOG_SET, "SET:NOPASSWORD:ON");
84
85 si->smu->flags |= MU_NOPASSWORD;
86
87 command_success_nodata(si, _("The \2%s\2 flag has been set for account \2%s\2."), "NOPASSWORD" ,entity(si->smu)->name);
88
89 return;
90 }
91 else if (!strcasecmp("OFF", setting))
92 {
93 if (!(MU_NOPASSWORD & si->smu->flags))
94 {
95 command_fail(si, fault_nochange, _("The \2%s\2 flag is not set for account \2%s\2."), "NOPASSWORD", entity(si->smu)->name);
96 return;
97 }
98
99 logcommand(si, CMDLOG_SET, "SET:NOPASSWORD:OFF");
100
101 si->smu->flags &= ~MU_NOPASSWORD;
102
103 command_success_nodata(si, _("The \2%s\2 flag has been removed for account \2%s\2."), "NOPASSWORD", entity(si->smu)->name);
104
105 return;
106 }
107 else
108 {
109 command_fail(si, fault_badparams, STR_INVALID_PARAMS, "NOPASSWORD");
110 return;
111 }
112 }
113
114 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
115 * vim:ts=8
116 * vim:sw=8
117 * vim:noexpandtab
118 */