ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/modules/m_set.c
Revision: 7400
Committed: Sun Mar 6 16:10:14 2016 UTC (8 years, 1 month ago) by michael
Content type: text/x-csrc
File size: 11562 byte(s)
Log Message:
- Cleanups to operator/connect block lookup routines

File Contents

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

Properties

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