Debian Codegraph @

modules/hostserv/drop.c

raw
1 /*
2 * Copyright (c) 2015-2016 Atheme Development Group <http://atheme.github.io/>
3 * Rights to this code are as documented in doc/LICENSE.
4 *
5 * Allows a user to drop (unset) their assigned vhost without
6 * Staff intervention.
7 *
8 */
9
10 #include "atheme.h"
11 #include "hostserv.h"
12
13 DECLARE_MODULE_V1
14 (
15 "hostserv/drop", false, _modinit, _moddeinit,
16 PACKAGE_STRING,
17 "Atheme Development Group <http://atheme.github.io>"
18 );
19
20 static void hs_cmd_drop(sourceinfo_t *si, int parc, char *parv[]);
21 static void hs_cmd_off(sourceinfo_t *si, int parc, char *parv[]);
22
23 command_t hs_drop = { "DROP", N_("Drops your assigned vhost."), AC_AUTHENTICATED, 1, hs_cmd_drop, { .path = "hostserv/drop" } };
24
25 void _modinit(module_t *m)
26 {
27 service_named_bind_command("hostserv", &hs_drop);
28 }
29
30 void _moddeinit(module_unload_intent_t intent)
31 {
32 service_named_unbind_command("hostserv", &hs_drop);
33 }
34
35
36 static void hs_cmd_drop(sourceinfo_t *si, int parc, char *parv[])
37 {
38 mynick_t *mn;
39 metadata_t *md;
40 char buf[BUFSIZE];
41
42 /* This is only because we need a nick to copy from. */
43 if (si->su == NULL)
44 {
45 command_fail(si, fault_noprivs, _("\2%s\2 can only be executed via IRC."), "DROP");
46 return;
47 }
48
49 mn = mynick_find(si->su->nick);
50 if (mn == NULL)
51 {
52 command_fail(si, fault_nosuch_target, _("Nick \2%s\2 is not registered."), si->su->nick);
53 return;
54 }
55 if (mn->owner != si->smu)
56 {
57 command_fail(si, fault_noprivs, _("Nick \2%s\2 is not registered to your account."), mn->nick);
58 return;
59 }
60 snprintf(buf, BUFSIZE, "%s:%s", "private:usercloak", mn->nick);
61 md = metadata_find(si->smu, buf);
62 if (md == NULL)
63 md = metadata_find(si->smu, "private:usercloak");
64 if (md == NULL)
65 {
66 command_success_nodata(si, _("There is not a vhost assigned to this nick."));
67 return;
68 }
69 hs_sethost_all(si->smu, NULL, get_source_name(si));
70 command_success_nodata(si, _("Dropped all vhosts for \2%s\2."), get_source_name(si));
71 logcommand(si, CMDLOG_ADMIN, "VHOST:DROP: \2%s\2", get_source_name(si));
72 do_sethost_all(si->smu, NULL); // restore user vhost from user host
73
74 }