Debian Codegraph @

modules/nickserv/set_pubkey.c

raw
1 /*
2 * Copyright (c) 2005 William Pitcock <nenolod -at- nenolod.net>
3 * Copyright (c) 2007 Jilles Tjoelker
4 * Copyright (c) 2014 Zohlai Development Group
5 * Rights to this code are as documented in doc/LICENSE.
6 *
7 * Sets the public key (for SASL ECDSA-NIST256p-CHALLENGE) of a user.
8 *
9 */
10
11 #include "atheme.h"
12 #include "uplink.h"
13
14 DECLARE_MODULE_V1
15 (
16 "nickserv/set_pubkey", false, _modinit, _moddeinit,
17 PACKAGE_STRING,
18 "Zohlai Development Group"
19 );
20
21 mowgli_patricia_t **ns_set_cmdtree;
22
23 static void ns_cmd_set_pubkey(sourceinfo_t *si, int parc, char *parv[]);
24
25 command_t ns_set_pubkey = { "PUBKEY", N_("Changes your ECDSA-NIST256p-CHALLENGE public key."), AC_NONE, 1, ns_cmd_set_pubkey, { .path = "nickserv/set_pubkey" } };
26
27 void _modinit(module_t *m)
28 {
29 MODULE_TRY_REQUEST_SYMBOL(m, ns_set_cmdtree, "nickserv/set_core", "ns_set_cmdtree");
30
31 command_add(&ns_set_pubkey, *ns_set_cmdtree);
32 }
33
34 void _moddeinit(module_unload_intent_t intent)
35 {
36 command_delete(&ns_set_pubkey, *ns_set_cmdtree);
37 }
38
39 /* SET PUBKEY <key> */
40 static void ns_cmd_set_pubkey(sourceinfo_t *si, int parc, char *parv[])
41 {
42 char *newkey = parv[0];
43 metadata_t *md;
44
45 if (!newkey)
46 {
47 md = metadata_find(si->smu, "private:pubkey");
48
49 if (!md)
50 {
51 command_fail(si, fault_nosuch_target, _("Public key was not set"));
52 return;
53 }
54
55 metadata_delete(si->smu, "private:pubkey");
56 logcommand(si, CMDLOG_SET, "SET:PUBKEY:REMOVE");
57 command_success_nodata(si, _("Public key entry has been deleted."));
58 return;
59 }
60
61 md = metadata_find(si->smu, "private:pubkey");
62 if (md != NULL && !strcmp(md->value, newkey))
63 {
64 command_fail(si, fault_nochange, _("Your public key is already set to \2%s\2."), newkey);
65 return;
66 }
67
68 metadata_add(si->smu, "private:pubkey", newkey);
69 logcommand(si, CMDLOG_SET, "SET:PUBKEY: \2%s\2", newkey);
70 command_success_nodata(si, _("Your public key is now set to \2%s\2."), newkey);
71 return;
72 }
73
74 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
75 * vim:ts=8
76 * vim:sw=8
77 * vim:noexpandtab
78 */