/[svn]/ircd-hybrid/trunk/modules/m_set.c
ViewVC logotype

Contents of /ircd-hybrid/trunk/modules/m_set.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9405 - (show annotations)
Sat May 23 17:43:34 2020 UTC (2 months, 2 weeks ago) by michael
File MIME type: text/x-chdr
File size: 11434 byte(s)
- m_set.c:quote_spamnum(): use proper conversion specifier for GlobalSetOptions.spam_num

1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2020 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 static const char *const status[] =
74 {
75 "OFF", "ON"
76 };
77
78 if (newval >= 0)
79 {
80 GlobalSetOptions.autoconn = newval != 0;
81 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
82 "%s has changed AUTOCONNALL to %s",
83 get_oper_name(source_p), status[GlobalSetOptions.autoconn == true]);
84 }
85 else
86 sendto_one_notice(source_p, &me, ":AUTOCONNALL is currently %s",
87 status[GlobalSetOptions.autoconn == true]);
88 }
89
90 /* SET FLOODCOUNT */
91 static void
92 quote_floodcount(struct Client *source_p, const char *arg, int newval)
93 {
94 if (newval >= 0)
95 {
96 GlobalSetOptions.floodcount = newval;
97 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
98 "%s has changed FLOODCOUNT to %u",
99 get_oper_name(source_p), GlobalSetOptions.floodcount);
100 }
101 else
102 sendto_one_notice(source_p, &me, ":FLOODCOUNT is currently %u",
103 GlobalSetOptions.floodcount);
104 }
105
106 /* SET FLOODTIME */
107 static void
108 quote_floodtime(struct Client *source_p, const char *arg, int newval)
109 {
110 if (newval >= 0)
111 {
112 GlobalSetOptions.floodtime = newval;
113 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
114 "%s has changed FLOODTIME to %u",
115 get_oper_name(source_p), GlobalSetOptions.floodtime);
116 }
117 else
118 sendto_one_notice(source_p, &me, ":FLOODTIME is currently %u",
119 GlobalSetOptions.floodtime);
120 }
121
122 /* SET MAX */
123 static void
124 quote_max(struct Client *source_p, const char *arg, int newval)
125 {
126 if (newval > 0)
127 {
128 if (newval > MAXCLIENTS_MAX)
129 {
130 sendto_one_notice(source_p, &me, ":You cannot set MAXCLIENTS to > %d, restoring to %u",
131 MAXCLIENTS_MAX, GlobalSetOptions.maxclients);
132 return;
133 }
134
135 GlobalSetOptions.maxclients = newval;
136 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
137 "%s set new MAXCLIENTS to %u (%u current)",
138 get_oper_name(source_p), GlobalSetOptions.maxclients, dlink_list_length(&local_client_list));
139 }
140 else
141 sendto_one_notice(source_p, &me, ":Current MAXCLIENTS = %u (%u)",
142 GlobalSetOptions.maxclients, dlink_list_length(&local_client_list));
143 }
144
145 /* SET SPAMNUM */
146 static void
147 quote_spamnum(struct Client *source_p, const char *arg, int newval)
148 {
149 if (newval >= 0)
150 {
151 if (newval == 0)
152 {
153 GlobalSetOptions.spam_num = newval;
154 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
155 "%s has disabled ANTI_SPAMBOT", source_p->name);
156 return;
157 }
158
159 GlobalSetOptions.spam_num = IRCD_MAX(newval, MIN_SPAM_NUM);
160 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
161 "%s has changed SPAMNUM to %u",
162 get_oper_name(source_p), GlobalSetOptions.spam_num);
163 }
164 else
165 sendto_one_notice(source_p, &me, ":SPAMNUM is currently %u",
166 GlobalSetOptions.spam_num);
167 }
168
169 /* SET SPAMTIME */
170 static void
171 quote_spamtime(struct Client *source_p, const char *arg, int newval)
172 {
173 if (newval > 0)
174 {
175 GlobalSetOptions.spam_time = IRCD_MAX(newval, MIN_SPAM_TIME);
176 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
177 "%s has changed SPAMTIME to %u",
178 get_oper_name(source_p), GlobalSetOptions.spam_time);
179 }
180 else
181 sendto_one_notice(source_p, &me, ":SPAMTIME is currently %u",
182 GlobalSetOptions.spam_time);
183 }
184
185 /* SET JFLOODTIME */
186 static void
187 quote_jfloodtime(struct Client *source_p, const char *arg, int newval)
188 {
189 if (newval >= 0)
190 {
191 GlobalSetOptions.joinfloodtime = newval;
192 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
193 "%s has changed JFLOODTIME to %u",
194 get_oper_name(source_p), GlobalSetOptions.joinfloodtime);
195 }
196 else
197 sendto_one_notice(source_p, &me, ":JFLOODTIME is currently %u",
198 GlobalSetOptions.joinfloodtime);
199 }
200
201 /* SET JFLOODCOUNT */
202 static void
203 quote_jfloodcount(struct Client *source_p, const char *arg, int newval)
204 {
205 if (newval >= 0)
206 {
207 GlobalSetOptions.joinfloodcount = newval;
208 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
209 "%s has changed JFLOODCOUNT to %u",
210 get_oper_name(source_p), GlobalSetOptions.joinfloodcount);
211 }
212 else
213 sendto_one_notice(source_p, &me, ":JFLOODCOUNT is currently %u",
214 GlobalSetOptions.joinfloodcount);
215 }
216
217 /* Structure used for the SET table itself */
218 struct SetStruct
219 {
220 const char *const name;
221 void (*const handler)(struct Client *, const char *, int);
222 bool wants_char; /* 1 if it expects (char *, [int]) */
223 bool wants_int; /* 1 if it expects ([char *], int) */
224 /* eg: 0, 1 == only an int arg
225 * eg: 1, 1 == char and int args */
226 };
227
228 /*
229 * If this ever needs to be expanded to more than one arg of each
230 * type, want_char/want_int could be the count of the arguments,
231 * instead of just a boolean flag...
232 *
233 * -davidt
234 */
235 static const struct SetStruct set_cmd_table[] =
236 {
237 /* name function string arg int arg */
238 /* ------------------------------------------------------ */
239 { "AUTOCONN", quote_autoconn, true, true },
240 { "AUTOCONNALL", quote_autoconnall, false, true },
241 { "FLOODCOUNT", quote_floodcount, false, true },
242 { "FLOODTIME", quote_floodtime, false, true },
243 { "MAX", quote_max, false, true },
244 { "SPAMNUM", quote_spamnum, false, true },
245 { "SPAMTIME", quote_spamtime, false, true },
246 { "JFLOODTIME", quote_jfloodtime, false, true },
247 { "JFLOODCOUNT", quote_jfloodcount, false, true },
248 /* ------------------------------------------------------ */
249 { NULL, NULL, false, false }
250 };
251
252 /*
253 * list_quote_commands() sends the client all the available commands.
254 * Four to a line for now.
255 */
256 static void
257 list_quote_commands(struct Client *source_p)
258 {
259 unsigned int j = 0;
260 const char *names[4] = { "", "", "", "" };
261
262 sendto_one_notice(source_p, &me, ":Available QUOTE SET commands:");
263
264 for (const struct SetStruct *tab = set_cmd_table; tab->handler; ++tab)
265 {
266 names[j++] = tab->name;
267
268 if (j > 3)
269 {
270 sendto_one_notice(source_p, &me, ":%s %s %s %s",
271 names[0], names[1],
272 names[2], names[3]);
273 j = 0;
274 names[0] = names[1] = names[2] = names[3] = "";
275 }
276 }
277
278 if (j)
279 sendto_one_notice(source_p, &me, ":%s %s %s %s",
280 names[0], names[1],
281 names[2], names[3]);
282 }
283
284 /*
285 * mo_set - SET command handler
286 * set options while running
287 */
288 static void
289 mo_set(struct Client *source_p, int parc, char *parv[])
290 {
291 int newval;
292 const char *strarg = NULL;
293 const char *intarg = NULL;
294
295 if (!HasOFlag(source_p, OPER_FLAG_SET))
296 {
297 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "set");
298 return;
299 }
300
301 if (parc > 1)
302 {
303 /*
304 * Go through all the commands in set_cmd_table, until one is
305 * matched.
306 */
307 for (const struct SetStruct *tab = set_cmd_table; tab->handler; ++tab)
308 {
309 if (irccmp(tab->name, parv[1]))
310 continue;
311
312 /*
313 * Command found; now execute the code
314 */
315 int n = 2;
316
317 if (tab->wants_char)
318 strarg = parv[n++];
319
320 if (tab->wants_int)
321 intarg = parv[n++];
322
323 if ((n - 1) > parc)
324 sendto_one_notice(source_p, &me, ":SET %s expects (\"%s%s\") args", tab->name,
325 (tab->wants_char ? "string, " : ""),
326 (tab->wants_int ? "int" : ""));
327
328 if (parc <= 2)
329 {
330 strarg = NULL;
331 intarg = NULL;
332 }
333
334 if (tab->wants_int && parc > 2)
335 {
336 if (intarg)
337 {
338 if (irccmp(intarg, "yes") == 0 || irccmp(intarg, "on") == 0)
339 newval = 1;
340 else if (irccmp(intarg, "no") == 0 || irccmp(intarg, "off") == 0)
341 newval = 0;
342 else
343 newval = atoi(intarg);
344 }
345 else
346 newval = -1;
347
348 if (newval < 0)
349 {
350 sendto_one_notice(source_p, &me, ":Value less than 0 illegal for %s", tab->name);
351 return;
352 }
353 }
354 else
355 newval = -1;
356
357 tab->handler(source_p, strarg, newval);
358 return;
359 }
360
361 /*
362 * Code here will be executed when a /QUOTE SET command is not
363 * found within set_cmd_table.
364 */
365 sendto_one_notice(source_p, &me, ":Variable not found.");
366 return;
367 }
368
369 list_quote_commands(source_p);
370 }
371
372 static struct Message set_msgtab =
373 {
374 .cmd = "SET",
375 .handlers[UNREGISTERED_HANDLER] = { .handler = m_unregistered },
376 .handlers[CLIENT_HANDLER] = { .handler = m_not_oper },
377 .handlers[SERVER_HANDLER] = { .handler = m_ignore },
378 .handlers[ENCAP_HANDLER] = { .handler = m_ignore },
379 .handlers[OPER_HANDLER] = { .handler = mo_set }
380 };
381
382 static void
383 module_init(void)
384 {
385 mod_add_cmd(&set_msgtab);
386 }
387
388 static void
389 module_exit(void)
390 {
391 mod_del_cmd(&set_msgtab);
392 }
393
394 struct module module_entry =
395 {
396 .version = "$Revision$",
397 .modinit = module_init,
398 .modexit = module_exit,
399 };

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28