Debian Codegraph @

modules/chanserv/drop.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 DROP function.
6 *
7 */
8
9 #include "atheme.h"
10
11 DECLARE_MODULE_V1
12 (
13 "chanserv/drop", false, _modinit, _moddeinit,
14 PACKAGE_STRING,
15 VENDOR_STRING
16 );
17
18 static void cs_cmd_drop(sourceinfo_t *si, int parc, char *parv[]);
19 static void cs_cmd_fdrop(sourceinfo_t *si, int parc, char *parv[]);
20
21 command_t cs_drop = { "DROP", N_("Drops a channel registration."),
22 AC_NONE, 2, cs_cmd_drop, { .path = "cservice/drop" } };
23 command_t cs_fdrop = { "FDROP", N_("Forces dropping of a channel registration."),
24 PRIV_CHAN_ADMIN, 1, cs_cmd_fdrop, { .path = "cservice/fdrop" } };
25
26 void _modinit(module_t *m)
27 {
28 service_named_bind_command("chanserv", &cs_drop);
29 service_named_bind_command("chanserv", &cs_fdrop);
30 }
31
32 void _moddeinit(module_unload_intent_t intent)
33 {
34 service_named_unbind_command("chanserv", &cs_drop);
35 service_named_unbind_command("chanserv", &cs_fdrop);
36 }
37
38 static void cs_cmd_drop(sourceinfo_t *si, int parc, char *parv[])
39 {
40 mychan_t *mc;
41 char *name = parv[0];
42 char *key = parv[1];
43 char fullcmd[512];
44 char key0[80], key1[80];
45
46 if (!name)
47 {
48 command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "DROP");
49 command_fail(si, fault_needmoreparams, _("Syntax: DROP <#channel>"));
50 return;
51 }
52
53 if (*name != '#')
54 {
55 command_fail(si, fault_badparams, STR_INVALID_PARAMS, "DROP");
56 command_fail(si, fault_badparams, _("Syntax: DROP <#channel>"));
57 return;
58 }
59
60 if (!(mc = mychan_find(name)))
61 {
62 command_fail(si, fault_nosuch_target, _("Channel \2%s\2 is not registered."), name);
63 return;
64 }
65
66 if (si->c != NULL)
67 {
68 command_fail(si, fault_noprivs, _("For security reasons, you may not drop a channel registration with a fantasy command."));
69 return;
70 }
71
72 if (!is_founder(mc, entity(si->smu)))
73 {
74 command_fail(si, fault_noprivs, _("You are not authorized to perform this operation."));
75 return;
76 }
77
78 if (metadata_find(mc, "private:close:closer"))
79 {
80 logcommand(si, CMDLOG_REGISTER, "DROP: \2%s\2 failed to drop (closed)", mc->name);
81 command_fail(si, fault_noprivs, _("The channel \2%s\2 is closed; it cannot be dropped."), mc->name);
82 return;
83 }
84
85 if (mc->flags & MC_HOLD)
86 {
87 command_fail(si, fault_noprivs, _("The channel \2%s\2 is held; it cannot be dropped."), mc->name);
88 return;
89 }
90
91 if (si->su != NULL)
92 {
93 if (!key)
94 {
95 create_challenge(si, mc->name, 0, key0);
96 snprintf(fullcmd, sizeof fullcmd, "/%s%s DROP %s %s",
97 (ircd->uses_rcommand == false) ? "msg " : "",
98 chansvs.me->disp, mc->name, key0);
99 command_success_nodata(si, _("To avoid accidental use of this command, this operation has to be confirmed. Please confirm by replying with \2%s\2"),
100 fullcmd);
101 return;
102 }
103 /* accept current and previous key */
104 create_challenge(si, mc->name, 0, key0);
105 create_challenge(si, mc->name, 1, key1);
106 if (strcmp(key, key0) && strcmp(key, key1))
107 {
108 command_fail(si, fault_badparams, _("Invalid key for %s."), "DROP");
109 return;
110 }
111 }
112
113 logcommand(si, CMDLOG_REGISTER, "DROP: \2%s\2", mc->name);
114
115 hook_call_channel_drop(mc);
116 if (mc->chan != NULL && !(mc->chan->flags & CHAN_LOG))
117 part(mc->name, chansvs.nick);
118 object_unref(mc);
119 command_success_nodata(si, _("The channel \2%s\2 has been dropped."), name);
120 return;
121 }
122
123 static void cs_cmd_fdrop(sourceinfo_t *si, int parc, char *parv[])
124 {
125 mychan_t *mc;
126 char *name = parv[0];
127
128 if (!name)
129 {
130 command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "FDROP");
131 command_fail(si, fault_needmoreparams, _("Syntax: FDROP <#channel>"));
132 return;
133 }
134
135 if (*name != '#')
136 {
137 command_fail(si, fault_badparams, STR_INVALID_PARAMS, "FDROP");
138 command_fail(si, fault_badparams, _("Syntax: FDROP <#channel>"));
139 return;
140 }
141
142 if (!(mc = mychan_find(name)))
143 {
144 command_fail(si, fault_nosuch_target, _("Channel \2%s\2 is not registered."), name);
145 return;
146 }
147
148 if (si->c != NULL)
149 {
150 command_fail(si, fault_noprivs, _("For security reasons, you may not drop a channel registration with a fantasy command."));
151 return;
152 }
153
154 if (mc->flags & MC_HOLD)
155 {
156 command_fail(si, fault_noprivs, _("The channel \2%s\2 is held; it cannot be dropped."), mc->name);
157 return;
158 }
159
160 logcommand(si, CMDLOG_ADMIN | LG_REGISTER, "FDROP: \2%s\2", mc->name);
161 wallops("%s dropped the channel \2%s\2", get_oper_name(si), name);
162
163 hook_call_channel_drop(mc);
164 if (mc->chan != NULL && !(mc->chan->flags & CHAN_LOG))
165 part(mc->name, chansvs.nick);
166 object_unref(mc);
167 command_success_nodata(si, _("The channel \2%s\2 has been dropped."), name);
168 return;
169 }
170
171 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
172 * vim:ts=8
173 * vim:sw=8
174 * vim:noexpandtab
175 */