1 |
/* |
2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
* |
4 |
* Copyright (c) 1997-2019 ircd-hybrid development team |
5 |
* |
6 |
* This program is free software; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU General Public License as published by |
8 |
* the Free Software Foundation; either version 2 of the License, or |
9 |
* (at your option) any later version. |
10 |
* |
11 |
* This program is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
19 |
* USA |
20 |
*/ |
21 |
|
22 |
/*! \file m_set.c |
23 |
* \brief Includes required functions for processing the SET command. |
24 |
* \version $Id$ |
25 |
*/ |
26 |
|
27 |
#include "stdinc.h" |
28 |
#include "client.h" |
29 |
#include "event.h" |
30 |
#include "irc_string.h" |
31 |
#include "ircd.h" |
32 |
#include "numeric.h" |
33 |
#include "send.h" |
34 |
#include "conf.h" |
35 |
#include "parse.h" |
36 |
#include "modules.h" |
37 |
#include "misc.h" |
38 |
|
39 |
|
40 |
/* SET AUTOCONN */ |
41 |
static void |
42 |
quote_autoconn(struct Client *source_p, const char *arg, int newval) |
43 |
{ |
44 |
if (EmptyString(arg)) |
45 |
{ |
46 |
sendto_one_notice(source_p, &me, ":Please specify a server name!"); |
47 |
return; |
48 |
} |
49 |
|
50 |
struct MaskItem *conf = connect_find(arg, irccmp); |
51 |
if (conf == NULL) |
52 |
{ |
53 |
sendto_one_notice(source_p, &me, ":Cannot find %s", arg); |
54 |
return; |
55 |
} |
56 |
|
57 |
if (newval) |
58 |
SetConfAllowAutoConn(conf); |
59 |
else |
60 |
ClearConfAllowAutoConn(conf); |
61 |
|
62 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
63 |
"%s has changed AUTOCONN for %s to %i", |
64 |
get_oper_name(source_p), conf->name, newval); |
65 |
sendto_one_notice(source_p, &me, ":AUTOCONN for %s is now set to %i", |
66 |
conf->name, newval); |
67 |
} |
68 |
|
69 |
/* SET AUTOCONNALL */ |
70 |
static void |
71 |
quote_autoconnall(struct Client *source_p, const char *arg, int newval) |
72 |
{ |
73 |
if (newval >= 0) |
74 |
{ |
75 |
GlobalSetOptions.autoconn = newval; |
76 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
77 |
"%s has changed AUTOCONNALL to %u", |
78 |
get_oper_name(source_p), GlobalSetOptions.autoconn); |
79 |
} |
80 |
else |
81 |
sendto_one_notice(source_p, &me, ":AUTOCONNALL is currently %u", |
82 |
GlobalSetOptions.autoconn); |
83 |
} |
84 |
|
85 |
/* SET FLOODCOUNT */ |
86 |
static void |
87 |
quote_floodcount(struct Client *source_p, const char *arg, int newval) |
88 |
{ |
89 |
if (newval >= 0) |
90 |
{ |
91 |
GlobalSetOptions.floodcount = newval; |
92 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
93 |
"%s has changed FLOODCOUNT to %u", |
94 |
get_oper_name(source_p), GlobalSetOptions.floodcount); |
95 |
} |
96 |
else |
97 |
sendto_one_notice(source_p, &me, ":FLOODCOUNT is currently %u", |
98 |
GlobalSetOptions.floodcount); |
99 |
} |
100 |
|
101 |
/* SET FLOODTIME */ |
102 |
static void |
103 |
quote_floodtime(struct Client *source_p, const char *arg, int newval) |
104 |
{ |
105 |
if (newval >= 0) |
106 |
{ |
107 |
GlobalSetOptions.floodtime = newval; |
108 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
109 |
"%s has changed FLOODTIME to %u", |
110 |
get_oper_name(source_p), GlobalSetOptions.floodtime); |
111 |
} |
112 |
else |
113 |
sendto_one_notice(source_p, &me, ":FLOODTIME is currently %u", |
114 |
GlobalSetOptions.floodtime); |
115 |
} |
116 |
|
117 |
/* SET IDENTTIMEOUT */ |
118 |
static void |
119 |
quote_identtimeout(struct Client *source_p, const char *arg, int newval) |
120 |
{ |
121 |
if (!HasUMode(source_p, UMODE_ADMIN)) |
122 |
{ |
123 |
sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "set"); |
124 |
return; |
125 |
} |
126 |
|
127 |
if (newval > 0) |
128 |
{ |
129 |
GlobalSetOptions.ident_timeout = newval; |
130 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
131 |
"%s has changed IDENTTIMEOUT to %u", |
132 |
get_oper_name(source_p), GlobalSetOptions.ident_timeout); |
133 |
} |
134 |
else |
135 |
sendto_one_notice(source_p, &me, ":IDENTTIMEOUT is currently %u", |
136 |
GlobalSetOptions.ident_timeout); |
137 |
} |
138 |
|
139 |
/* SET MAX */ |
140 |
static void |
141 |
quote_max(struct Client *source_p, const char *arg, int newval) |
142 |
{ |
143 |
if (newval > 0) |
144 |
{ |
145 |
if (newval > MAXCLIENTS_MAX) |
146 |
{ |
147 |
sendto_one_notice(source_p, &me, ":You cannot set MAXCLIENTS to > %d, restoring to %u", |
148 |
MAXCLIENTS_MAX, GlobalSetOptions.maxclients); |
149 |
return; |
150 |
} |
151 |
|
152 |
if (newval < MAXCLIENTS_MIN) |
153 |
{ |
154 |
sendto_one_notice(source_p, &me, ":You cannot set MAXCLIENTS to < %d, restoring to %u", |
155 |
MAXCLIENTS_MIN, GlobalSetOptions.maxclients); |
156 |
return; |
157 |
} |
158 |
|
159 |
GlobalSetOptions.maxclients = newval; |
160 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
161 |
"%s set new MAXCLIENTS to %u (%u current)", |
162 |
get_oper_name(source_p), GlobalSetOptions.maxclients, dlink_list_length(&local_client_list)); |
163 |
} |
164 |
else |
165 |
sendto_one_notice(source_p, &me, ":Current MAXCLIENTS = %u (%u)", |
166 |
GlobalSetOptions.maxclients, dlink_list_length(&local_client_list)); |
167 |
} |
168 |
|
169 |
/* SET SPAMNUM */ |
170 |
static void |
171 |
quote_spamnum(struct Client *source_p, const char *arg, int newval) |
172 |
{ |
173 |
if (newval >= 0) |
174 |
{ |
175 |
if (newval == 0) |
176 |
{ |
177 |
GlobalSetOptions.spam_num = newval; |
178 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
179 |
"%s has disabled ANTI_SPAMBOT", source_p->name); |
180 |
return; |
181 |
} |
182 |
|
183 |
GlobalSetOptions.spam_num = IRCD_MAX(newval, MIN_SPAM_NUM); |
184 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
185 |
"%s has changed SPAMNUM to %i", |
186 |
get_oper_name(source_p), GlobalSetOptions.spam_num); |
187 |
} |
188 |
else |
189 |
sendto_one_notice(source_p, &me, ":SPAMNUM is currently %i", |
190 |
GlobalSetOptions.spam_num); |
191 |
} |
192 |
|
193 |
/* SET SPAMTIME */ |
194 |
static void |
195 |
quote_spamtime(struct Client *source_p, const char *arg, int newval) |
196 |
{ |
197 |
if (newval > 0) |
198 |
{ |
199 |
GlobalSetOptions.spam_time = IRCD_MAX(newval, MIN_SPAM_TIME); |
200 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
201 |
"%s has changed SPAMTIME to %u", |
202 |
get_oper_name(source_p), GlobalSetOptions.spam_time); |
203 |
} |
204 |
else |
205 |
sendto_one_notice(source_p, &me, ":SPAMTIME is currently %u", |
206 |
GlobalSetOptions.spam_time); |
207 |
} |
208 |
|
209 |
/* SET JFLOODTIME */ |
210 |
static void |
211 |
quote_jfloodtime(struct Client *source_p, const char *arg, int newval) |
212 |
{ |
213 |
if (newval >= 0) |
214 |
{ |
215 |
GlobalSetOptions.joinfloodtime = newval; |
216 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
217 |
"%s has changed JFLOODTIME to %u", |
218 |
get_oper_name(source_p), GlobalSetOptions.joinfloodtime); |
219 |
} |
220 |
else |
221 |
sendto_one_notice(source_p, &me, ":JFLOODTIME is currently %u", |
222 |
GlobalSetOptions.joinfloodtime); |
223 |
} |
224 |
|
225 |
/* SET JFLOODCOUNT */ |
226 |
static void |
227 |
quote_jfloodcount(struct Client *source_p, const char *arg, int newval) |
228 |
{ |
229 |
if (newval >= 0) |
230 |
{ |
231 |
GlobalSetOptions.joinfloodcount = newval; |
232 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
233 |
"%s has changed JFLOODCOUNT to %u", |
234 |
get_oper_name(source_p), GlobalSetOptions.joinfloodcount); |
235 |
} |
236 |
else |
237 |
sendto_one_notice(source_p, &me, ":JFLOODCOUNT is currently %u", |
238 |
GlobalSetOptions.joinfloodcount); |
239 |
} |
240 |
|
241 |
/* Structure used for the SET table itself */ |
242 |
struct SetStruct |
243 |
{ |
244 |
const char *const name; |
245 |
void (*const handler)(struct Client *, const char *, int); |
246 |
bool wants_char; /* 1 if it expects (char *, [int]) */ |
247 |
bool wants_int; /* 1 if it expects ([char *], int) */ |
248 |
/* eg: 0, 1 == only an int arg |
249 |
* eg: 1, 1 == char and int args */ |
250 |
}; |
251 |
|
252 |
/* |
253 |
* If this ever needs to be expanded to more than one arg of each |
254 |
* type, want_char/want_int could be the count of the arguments, |
255 |
* instead of just a boolean flag... |
256 |
* |
257 |
* -davidt |
258 |
*/ |
259 |
static const struct SetStruct set_cmd_table[] = |
260 |
{ |
261 |
/* name function string arg int arg */ |
262 |
/* ------------------------------------------------------ */ |
263 |
{ "AUTOCONN", quote_autoconn, true, true }, |
264 |
{ "AUTOCONNALL", quote_autoconnall, false, true }, |
265 |
{ "FLOODCOUNT", quote_floodcount, false, true }, |
266 |
{ "FLOODTIME", quote_floodtime, false, true }, |
267 |
{ "IDENTTIMEOUT", quote_identtimeout, false, true }, |
268 |
{ "MAX", quote_max, false, true }, |
269 |
{ "SPAMNUM", quote_spamnum, false, true }, |
270 |
{ "SPAMTIME", quote_spamtime, false, true }, |
271 |
{ "JFLOODTIME", quote_jfloodtime, false, true }, |
272 |
{ "JFLOODCOUNT", quote_jfloodcount, false, true }, |
273 |
/* ------------------------------------------------------ */ |
274 |
{ NULL, NULL, false, false } |
275 |
}; |
276 |
|
277 |
/* |
278 |
* list_quote_commands() sends the client all the available commands. |
279 |
* Four to a line for now. |
280 |
*/ |
281 |
static void |
282 |
list_quote_commands(struct Client *source_p) |
283 |
{ |
284 |
unsigned int j = 0; |
285 |
const char *names[4] = { "", "", "", "" }; |
286 |
|
287 |
sendto_one_notice(source_p, &me, ":Available QUOTE SET commands:"); |
288 |
|
289 |
for (const struct SetStruct *tab = set_cmd_table; tab->handler; ++tab) |
290 |
{ |
291 |
names[j++] = tab->name; |
292 |
|
293 |
if (j > 3) |
294 |
{ |
295 |
sendto_one_notice(source_p, &me, ":%s %s %s %s", |
296 |
names[0], names[1], |
297 |
names[2], names[3]); |
298 |
j = 0; |
299 |
names[0] = names[1] = names[2] = names[3] = ""; |
300 |
} |
301 |
} |
302 |
|
303 |
if (j) |
304 |
sendto_one_notice(source_p, &me, ":%s %s %s %s", |
305 |
names[0], names[1], |
306 |
names[2], names[3]); |
307 |
} |
308 |
|
309 |
/* |
310 |
* mo_set - SET command handler |
311 |
* set options while running |
312 |
*/ |
313 |
static int |
314 |
mo_set(struct Client *source_p, int parc, char *parv[]) |
315 |
{ |
316 |
int newval; |
317 |
const char *strarg = NULL; |
318 |
const char *intarg = NULL; |
319 |
|
320 |
if (!HasOFlag(source_p, OPER_FLAG_SET)) |
321 |
{ |
322 |
sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "set"); |
323 |
return 0; |
324 |
} |
325 |
|
326 |
if (parc > 1) |
327 |
{ |
328 |
/* |
329 |
* Go through all the commands in set_cmd_table, until one is |
330 |
* matched. |
331 |
*/ |
332 |
for (const struct SetStruct *tab = set_cmd_table; tab->handler; ++tab) |
333 |
{ |
334 |
if (irccmp(tab->name, parv[1])) |
335 |
continue; |
336 |
|
337 |
/* |
338 |
* Command found; now execute the code |
339 |
*/ |
340 |
int n = 2; |
341 |
|
342 |
if (tab->wants_char) |
343 |
strarg = parv[n++]; |
344 |
|
345 |
if (tab->wants_int) |
346 |
intarg = parv[n++]; |
347 |
|
348 |
if ((n - 1) > parc) |
349 |
sendto_one_notice(source_p, &me, ":SET %s expects (\"%s%s\") args", tab->name, |
350 |
(tab->wants_char ? "string, " : ""), |
351 |
(tab->wants_int ? "int" : "")); |
352 |
|
353 |
if (parc <= 2) |
354 |
{ |
355 |
strarg = NULL; |
356 |
intarg = NULL; |
357 |
} |
358 |
|
359 |
if (tab->wants_int && parc > 2) |
360 |
{ |
361 |
if (intarg) |
362 |
{ |
363 |
if (irccmp(intarg, "yes") == 0 || irccmp(intarg, "on") == 0) |
364 |
newval = 1; |
365 |
else if (irccmp(intarg, "no") == 0 || irccmp(intarg, "off") == 0) |
366 |
newval = 0; |
367 |
else |
368 |
newval = atoi(intarg); |
369 |
} |
370 |
else |
371 |
newval = -1; |
372 |
|
373 |
if (newval < 0) |
374 |
{ |
375 |
sendto_one_notice(source_p, &me, ":Value less than 0 illegal for %s", tab->name); |
376 |
return 0; |
377 |
} |
378 |
} |
379 |
else |
380 |
newval = -1; |
381 |
|
382 |
tab->handler(source_p, strarg, newval); |
383 |
return 0; |
384 |
} |
385 |
|
386 |
/* |
387 |
* Code here will be executed when a /QUOTE SET command is not |
388 |
* found within set_cmd_table. |
389 |
*/ |
390 |
sendto_one_notice(source_p, &me, ":Variable not found."); |
391 |
return 0; |
392 |
} |
393 |
|
394 |
list_quote_commands(source_p); |
395 |
return 0; |
396 |
} |
397 |
|
398 |
static struct Message set_msgtab = |
399 |
{ |
400 |
.cmd = "SET", |
401 |
.args_max = MAXPARA, |
402 |
.handlers[UNREGISTERED_HANDLER] = m_unregistered, |
403 |
.handlers[CLIENT_HANDLER] = m_not_oper, |
404 |
.handlers[SERVER_HANDLER] = m_ignore, |
405 |
.handlers[ENCAP_HANDLER] = m_ignore, |
406 |
.handlers[OPER_HANDLER] = mo_set |
407 |
}; |
408 |
|
409 |
static void |
410 |
module_init(void) |
411 |
{ |
412 |
mod_add_cmd(&set_msgtab); |
413 |
} |
414 |
|
415 |
static void |
416 |
module_exit(void) |
417 |
{ |
418 |
mod_del_cmd(&set_msgtab); |
419 |
} |
420 |
|
421 |
struct module module_entry = |
422 |
{ |
423 |
.version = "$Revision$", |
424 |
.modinit = module_init, |
425 |
.modexit = module_exit, |
426 |
}; |