1 |
/** |
2 |
* noop.C: OperServ NOOP command. |
3 |
* |
4 |
* Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team |
5 |
* Rights to this code are as documented in COPYING. |
6 |
* |
7 |
* |
8 |
* Portions of this file were derived from sources bearing the following license: |
9 |
* Copyright © 2005-2006 William Pitcock, et al. |
10 |
* Rights to this code are as documented in doc/pod/license.pod. |
11 |
* |
12 |
* $Id: noop.C,v 1.8 2007-09-16 18:54:44 pippijn Exp $ |
13 |
*/ |
14 |
|
15 |
#include "atheme.h" |
16 |
#include "servers.h" |
17 |
#include <ermyth/module.h> |
18 |
|
19 |
static char const rcsid[] = "$Id: noop.C,v 1.8 2007-09-16 18:54:44 pippijn Exp $"; |
20 |
|
21 |
REGISTER_MODULE ("operserv/noop", true, "The Ermyth Team <http://ermyth.xinutec.org>"); |
22 |
|
23 |
typedef struct noop_ noop_t; |
24 |
|
25 |
struct noop_ |
26 |
{ |
27 |
char *target; |
28 |
char *added_by; |
29 |
char *reason; |
30 |
}; |
31 |
|
32 |
list_t noop_hostmask_list; |
33 |
list_t noop_server_list; |
34 |
|
35 |
static void os_cmd_noop (sourceinfo_t *si, int parc, char *parv[]); |
36 |
|
37 |
command_t const os_noop = { "NOOP", N_("Restricts IRCop access."), PRIV_NOOP, 4, os_cmd_noop }; |
38 |
|
39 |
E cmdvec os_cmdtree; |
40 |
E helpvec os_helptree; |
41 |
|
42 |
static void |
43 |
check_user (user_t *u) |
44 |
{ |
45 |
node_t *n; |
46 |
char hostbuf[BUFSIZE]; |
47 |
|
48 |
snprintf (hostbuf, BUFSIZE, "%s!%s@%s", u->nick, u->user, u->host); |
49 |
|
50 |
LIST_FOREACH (n, noop_hostmask_list.head) |
51 |
{ |
52 |
noop_t *np = static_cast < noop_t * >(n->data); |
53 |
|
54 |
if (!match (np->target, hostbuf)) |
55 |
{ |
56 |
phandler->skill (opersvs.nick, u->nick, "Operator access denied to hostmask: %s [%s] <%s@%s>", np->target, np->reason, np->added_by, opersvs.nick); |
57 |
user_delete (u); |
58 |
return; |
59 |
} |
60 |
} |
61 |
|
62 |
LIST_FOREACH (n, noop_server_list.head) |
63 |
{ |
64 |
noop_t *np = static_cast < noop_t * >(n->data); |
65 |
|
66 |
if (!match (np->target, u->server->name)) |
67 |
{ |
68 |
phandler->skill (opersvs.nick, u->nick, "Operator access denied to server: %s [%s] <%s@%s>", np->target, np->reason, np->added_by, opersvs.nick); |
69 |
user_delete (u); |
70 |
return; |
71 |
} |
72 |
} |
73 |
} |
74 |
|
75 |
static noop_t * |
76 |
noop_find (char *target, list_t *list) |
77 |
{ |
78 |
node_t *n; |
79 |
|
80 |
LIST_FOREACH (n, list->head) |
81 |
{ |
82 |
noop_t *np = static_cast < noop_t * >(n->data); |
83 |
|
84 |
if (!match (np->target, target)) |
85 |
return np; |
86 |
} |
87 |
|
88 |
return NULL; |
89 |
} |
90 |
|
91 |
/* NOOP <ADD|DEL|LIST> <HOSTMASK|SERVER> [reason] */ |
92 |
static void |
93 |
os_cmd_noop (sourceinfo_t *si, int parc, char *parv[]) |
94 |
{ |
95 |
node_t *n; |
96 |
noop_t *np; |
97 |
char *action = parv[0]; |
98 |
char *type = parv[1]; |
99 |
char *mask = parv[2]; |
100 |
char *reason = parv[3]; |
101 |
|
102 |
if (!action || !type) |
103 |
{ |
104 |
command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "NOOP"); |
105 |
command_fail (si, fault::needmoreparams, _("Syntax: NOOP <ADD|DEL|LIST> <HOSTMASK|SERVER> <mask> [reason]")); |
106 |
return; |
107 |
} |
108 |
|
109 |
if (!strcasecmp (action, "ADD")) |
110 |
{ |
111 |
if (!strcasecmp (type, "HOSTMASK")) |
112 |
{ |
113 |
if (!mask) |
114 |
{ |
115 |
command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "NOOP"); |
116 |
command_fail (si, fault::needmoreparams, _("Syntax: NOOP <ADD|DEL|LIST> <HOSTMASK|SERVER> <mask> [reason]")); |
117 |
return; |
118 |
} |
119 |
if ((np = noop_find (mask, &noop_hostmask_list))) |
120 |
{ |
121 |
command_fail (si, fault::nochange, _("There is already a NOOP entry covering this target.")); |
122 |
return; |
123 |
} |
124 |
|
125 |
np = new noop_t; |
126 |
|
127 |
np->target = sstrdup (mask); |
128 |
np->added_by = sstrdup (get_oper_name (si)); |
129 |
|
130 |
if (reason) |
131 |
np->reason = sstrdup (reason); |
132 |
else |
133 |
np->reason = sstrdup ("Abusive operator."); |
134 |
|
135 |
n = node_create (); |
136 |
node_add (np, n, &noop_hostmask_list); |
137 |
|
138 |
logcommand (si, CMDLOG_ADMIN, "NOOP ADD HOSTMASK %s %s", np->target, np->reason); |
139 |
command_success_nodata (si, _("Added \2%s\2 to the hostmask NOOP list."), mask); |
140 |
|
141 |
return; |
142 |
} |
143 |
else if (!strcasecmp (type, "SERVER")) |
144 |
{ |
145 |
if (!mask) |
146 |
{ |
147 |
command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "NOOP"); |
148 |
command_fail (si, fault::needmoreparams, _("Syntax: NOOP <ADD|DEL|LIST> <HOSTMASK|SERVER> <mask> [reason]")); |
149 |
return; |
150 |
} |
151 |
if ((np = noop_find (mask, &noop_server_list))) |
152 |
{ |
153 |
command_fail (si, fault::nochange, _("There is already a NOOP entry covering this target.")); |
154 |
return; |
155 |
} |
156 |
|
157 |
np = new noop_t; |
158 |
|
159 |
np->target = sstrdup (mask); |
160 |
np->added_by = sstrdup (get_oper_name (si)); |
161 |
|
162 |
if (reason) |
163 |
np->reason = sstrdup (reason); |
164 |
else |
165 |
np->reason = sstrdup ("Abusive operator."); |
166 |
|
167 |
n = node_create (); |
168 |
node_add (np, n, &noop_server_list); |
169 |
|
170 |
logcommand (si, CMDLOG_ADMIN, "NOOP ADD SERVER %s %s", np->target, np->reason); |
171 |
command_success_nodata (si, _("Added \2%s\2 to the server NOOP list."), mask); |
172 |
|
173 |
return; |
174 |
} |
175 |
else |
176 |
{ |
177 |
command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "NOOP"); |
178 |
command_fail (si, fault::needmoreparams, _("Syntax: NOOP ADD <HOSTMASK|SERVER> <mask> [reason]")); |
179 |
} |
180 |
} |
181 |
else if (!strcasecmp (action, "DEL")) |
182 |
{ |
183 |
if (!strcasecmp (type, "HOSTMASK")) |
184 |
{ |
185 |
if (!mask) |
186 |
{ |
187 |
command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "NOOP"); |
188 |
command_fail (si, fault::needmoreparams, _("Syntax: NOOP <ADD|DEL|LIST> <HOSTMASK|SERVER> <mask> [reason]")); |
189 |
return; |
190 |
} |
191 |
if (!(np = noop_find (mask, &noop_hostmask_list))) |
192 |
{ |
193 |
command_fail (si, fault::nosuch_target, _("There is no NOOP hostmask entry for this target.")); |
194 |
return; |
195 |
} |
196 |
|
197 |
logcommand (si, CMDLOG_ADMIN, "NOOP DEL HOSTMASK %s", np->target); |
198 |
command_success_nodata (si, _("Removed \2%s\2 from the hostmask NOOP list."), np->target); |
199 |
|
200 |
n = node_find (np, &noop_hostmask_list); |
201 |
|
202 |
sfree (np->target); |
203 |
sfree (np->added_by); |
204 |
sfree (np->reason); |
205 |
|
206 |
node_del (n, &noop_hostmask_list); |
207 |
node_free (n); |
208 |
delete np; |
209 |
|
210 |
return; |
211 |
} |
212 |
else if (!strcasecmp (type, "SERVER")) |
213 |
{ |
214 |
if (!(np = noop_find (mask, &noop_server_list))) |
215 |
{ |
216 |
command_fail (si, fault::nosuch_target, _("There is no NOOP server entry for this target.")); |
217 |
return; |
218 |
} |
219 |
|
220 |
logcommand (si, CMDLOG_ADMIN, "NOOP DEL SERVER %s", np->target); |
221 |
command_success_nodata (si, _("Removed \2%s\2 from the server NOOP list."), np->target); |
222 |
|
223 |
n = node_find (np, &noop_server_list); |
224 |
|
225 |
sfree (np->target); |
226 |
sfree (np->added_by); |
227 |
sfree (np->reason); |
228 |
|
229 |
node_del (n, &noop_server_list); |
230 |
node_free (n); |
231 |
delete np; |
232 |
|
233 |
return; |
234 |
} |
235 |
else |
236 |
{ |
237 |
command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "NOOP"); |
238 |
command_fail (si, fault::needmoreparams, _("Syntax: NOOP DEL <HOSTMASK|SERVER> <mask>")); |
239 |
} |
240 |
} |
241 |
else if (!strcasecmp (action, "LIST")) |
242 |
{ |
243 |
if (!strcasecmp (type, "HOSTMASK")) |
244 |
{ |
245 |
unsigned int i = 1; |
246 |
logcommand (si, CMDLOG_GET, "NOOP LIST HOSTMASK"); |
247 |
command_success_nodata (si, _("Hostmask NOOP list (%d entries):"), noop_hostmask_list.count); |
248 |
command_success_nodata (si, " "); |
249 |
command_success_nodata (si, _("Entry Hostmask Adder Reason")); |
250 |
command_success_nodata (si, "----- ------------------------------- --------------------- --------------------------"); |
251 |
|
252 |
LIST_FOREACH (n, noop_hostmask_list.head) |
253 |
{ |
254 |
np = static_cast < noop_t * >(n->data); |
255 |
|
256 |
command_success_nodata (si, "%-5d %-31s %-21s %s", i, np->target, np->added_by, np->reason); |
257 |
i++; |
258 |
} |
259 |
|
260 |
command_success_nodata (si, "----- ------------------------------- --------------------- --------------------------"); |
261 |
command_success_nodata (si, _("End of Hostmask NOOP list.")); |
262 |
} |
263 |
else if (!strcasecmp (type, "SERVER")) |
264 |
{ |
265 |
unsigned int i = 1; |
266 |
logcommand (si, CMDLOG_GET, "NOOP LIST SERVER"); |
267 |
command_success_nodata (si, _("Server NOOP list (%d entries):"), noop_server_list.count); |
268 |
command_success_nodata (si, " "); |
269 |
command_success_nodata (si, _("Entry Hostmask Adder Reason")); |
270 |
command_success_nodata (si, "----- ------------------------------- --------------------- --------------------------"); |
271 |
|
272 |
LIST_FOREACH (n, noop_server_list.head) |
273 |
{ |
274 |
np = static_cast < noop_t * >(n->data); |
275 |
|
276 |
command_success_nodata (si, "%-5d %-31s %-21s %s", i, np->target, np->added_by, np->reason); |
277 |
i++; |
278 |
} |
279 |
|
280 |
command_success_nodata (si, "----- ------------------------------- --------------------- --------------------------"); |
281 |
command_success_nodata (si, _("End of Server NOOP list.")); |
282 |
} |
283 |
else |
284 |
{ |
285 |
command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "NOOP"); |
286 |
command_fail (si, fault::needmoreparams, _("Syntax: NOOP LIST <HOSTMASK|SERVER>")); |
287 |
} |
288 |
} |
289 |
} |
290 |
|
291 |
bool |
292 |
_modinit (module *m) |
293 |
{ |
294 |
os_cmdtree << os_noop; |
295 |
help_addentry (os_helptree, "NOOP", "help/operserv/noop", NULL); |
296 |
user_t::callback.oper.attach (check_user); |
297 |
|
298 |
return true; |
299 |
} |
300 |
|
301 |
void |
302 |
_moddeinit () |
303 |
{ |
304 |
os_cmdtree >> os_noop; |
305 |
help_delentry (os_helptree, "NOOP"); |
306 |
user_t::callback.oper.detach (check_user); |
307 |
} |