ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_set.c
Revision: 1285
Committed: Sun Feb 5 15:12:59 2012 UTC (13 years, 6 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/modules/m_set.c
File size: 16979 byte(s)
Log Message:
- added CIDR support for operator{} blocks
- operator "name"{} is no longer supported

File Contents

# User Rev Content
1 adx 30 /*
2     * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3     * m_set.c: Sets a server parameter.
4     *
5     * Copyright (C) 2002 by the past and present ircd coders, and others.
6     *
7     * This program is free software; you can redistribute it and/or modify
8     * it under the terms of the GNU General Public License as published by
9     * the Free Software Foundation; either version 2 of the License, or
10     * (at your option) any later version.
11     *
12     * This program is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with this program; if not, write to the Free Software
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20     * USA
21     *
22 knight 31 * $Id$
23 adx 30 */
24    
25     /* rewritten by jdc */
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 "fdlist.h"
34     #include "s_bsd.h"
35     #include "s_serv.h"
36     #include "send.h"
37     #include "channel.h"
38     #include "s_log.h"
39     #include "s_conf.h"
40     #include "parse.h"
41     #include "modules.h"
42     #include "s_user.h"
43 michael 1243 #include "s_misc.h"
44 adx 30
45    
46     /* Structure used for the SET table itself */
47     struct SetStruct
48     {
49     const char *name;
50     void (*handler)();
51 michael 1013 const int wants_char; /* 1 if it expects (char *, [int]) */
52     const int wants_int; /* 1 if it expects ([char *], int) */
53 adx 30 /* eg: 0, 1 == only an int arg
54     * eg: 1, 1 == char and int args */
55     };
56    
57     static void quote_autoconn(struct Client *, const char *, int);
58     static void quote_autoconnall(struct Client *, int);
59     static void quote_floodcount(struct Client *, int);
60     static void quote_identtimeout(struct Client *, int);
61     static void quote_max(struct Client *, int);
62     static void quote_msglocale(struct Client *, char *);
63     static void quote_spamnum(struct Client *, int);
64     static void quote_spamtime(struct Client *, int);
65     static void quote_splitmode(struct Client *, char *);
66     static void quote_splitnum(struct Client *, int);
67     static void quote_splitusers(struct Client *, int);
68     static void list_quote_commands(struct Client *);
69     static void quote_jfloodtime(struct Client *, int);
70     static void quote_jfloodcount(struct Client *, int);
71     static void quote_rejecttime(struct Client *, int);
72    
73     /*
74     * If this ever needs to be expanded to more than one arg of each
75     * type, want_char/want_int could be the count of the arguments,
76     * instead of just a boolean flag...
77     *
78     * -davidt
79     */
80    
81 michael 1013 static const struct SetStruct set_cmd_table[] =
82 adx 30 {
83     /* name function string arg int arg */
84     /* -------------------------------------------------------- */
85     { "AUTOCONN", quote_autoconn, 1, 1 },
86     { "AUTOCONNALL", quote_autoconnall, 0, 1 },
87     { "FLOODCOUNT", quote_floodcount, 0, 1 },
88     { "IDENTTIMEOUT", quote_identtimeout, 0, 1 },
89     { "MAX", quote_max, 0, 1 },
90     { "MSGLOCALE", quote_msglocale, 1, 0 },
91     { "SPAMNUM", quote_spamnum, 0, 1 },
92     { "SPAMTIME", quote_spamtime, 0, 1 },
93     { "SPLITMODE", quote_splitmode, 1, 0 },
94     { "SPLITNUM", quote_splitnum, 0, 1 },
95     { "SPLITUSERS", quote_splitusers, 0, 1 },
96     { "JFLOODTIME", quote_jfloodtime, 0, 1 },
97     { "JFLOODCOUNT", quote_jfloodcount, 0, 1 },
98     { "REJECTTIME", quote_rejecttime, 0, 1 },
99     /* -------------------------------------------------------- */
100 michael 946 { NULL, NULL, 0, 0 }
101 adx 30 };
102    
103     /*
104     * list_quote_commands() sends the client all the available commands.
105     * Four to a line for now.
106     */
107     static void
108     list_quote_commands(struct Client *source_p)
109     {
110     int j = 0;
111 michael 1013 const struct SetStruct *tab = set_cmd_table;
112 michael 896 const char *names[4] = { "", "", "", "" };
113 adx 30
114     sendto_one(source_p, ":%s NOTICE %s :Available QUOTE SET commands:",
115     me.name, source_p->name);
116    
117 michael 1013 for (; tab->handler; ++tab)
118 adx 30 {
119 michael 1013 names[j++] = tab->name;
120 adx 30
121     if (j > 3)
122     {
123     sendto_one(source_p, ":%s NOTICE %s :%s %s %s %s",
124     me.name, source_p->name,
125     names[0], names[1],
126     names[2], names[3]);
127     j = 0;
128     names[0] = names[1] = names[2] = names[3] = "";
129     }
130    
131     }
132 michael 896
133 adx 30 if (j)
134     sendto_one(source_p, ":%s NOTICE %s :%s %s %s %s",
135     me.name, source_p->name,
136     names[0], names[1],
137     names[2], names[3]);
138     }
139    
140     /* SET AUTOCONN */
141     static void
142     quote_autoconn(struct Client *source_p, const char *arg, int newval)
143     {
144 michael 896 struct AccessItem *aconf;
145    
146     if (arg != NULL)
147     {
148 michael 1285 struct ConfItem *conf = find_exact_name_conf(SERVER_TYPE, NULL, arg, NULL, NULL);
149 michael 896
150     if (conf != NULL)
151     {
152     aconf = map_to_conf(conf);
153     if (newval)
154     SetConfAllowAutoConn(aconf);
155     else
156     ClearConfAllowAutoConn(aconf);
157    
158     sendto_realops_flags(UMODE_ALL, L_ALL,
159     "%s has changed AUTOCONN for %s to %i",
160 michael 1141 get_oper_name(source_p), arg, newval);
161 michael 896 sendto_one(source_p,
162     ":%s NOTICE %s :AUTOCONN for %s is now set to %i",
163     me.name, source_p->name, arg, newval);
164     }
165     else
166     {
167     sendto_one(source_p, ":%s NOTICE %s :Can't find %s",
168     me.name, source_p->name, arg);
169     }
170     }
171     else
172     {
173     sendto_one(source_p, ":%s NOTICE %s :Please specify a server name!",
174     me.name, source_p->name);
175     }
176 adx 30 }
177    
178     /* SET AUTOCONNALL */
179     static void
180     quote_autoconnall(struct Client *source_p, int newval)
181     {
182     if (newval >= 0)
183     {
184     sendto_realops_flags(UMODE_ALL, L_ALL, "%s has changed AUTOCONNALL to %i",
185 michael 1141 get_oper_name(source_p), newval);
186 adx 30
187     GlobalSetOptions.autoconn = newval;
188     }
189     else
190     sendto_one(source_p, ":%s NOTICE %s :AUTOCONNALL is currently %i",
191     me.name, source_p->name, GlobalSetOptions.autoconn);
192     }
193    
194     /* SET FLOODCOUNT */
195     static void
196     quote_floodcount(struct Client *source_p, int newval)
197     {
198     if (newval >= 0)
199     {
200     GlobalSetOptions.floodcount = newval;
201     sendto_realops_flags(UMODE_ALL, L_ALL,
202 michael 1141 "%s has changed FLOODCOUNT to %i",
203     get_oper_name(source_p), GlobalSetOptions.floodcount);
204 adx 30 }
205     else
206     sendto_one(source_p, ":%s NOTICE %s :FLOODCOUNT is currently %i",
207     me.name, source_p->name, GlobalSetOptions.floodcount);
208     }
209    
210     /* SET IDENTTIMEOUT */
211     static void
212     quote_identtimeout(struct Client *source_p, int newval)
213     {
214 michael 1219 if (!HasUMode(source_p, UMODE_ADMIN))
215 adx 30 {
216     sendto_one(source_p, form_str(ERR_NOPRIVS),
217     me.name, source_p->name, "set");
218     return;
219     }
220    
221     if (newval > 0)
222     {
223     sendto_realops_flags(UMODE_ALL, L_ALL,
224     "%s has changed IDENTTIMEOUT to %d",
225     get_oper_name(source_p), newval);
226     GlobalSetOptions.ident_timeout = newval;
227     }
228     else
229     sendto_one(source_p, ":%s NOTICE %s :IDENTTIMEOUT is currently %d",
230     me.name, source_p->name, GlobalSetOptions.ident_timeout);
231     }
232    
233     /* SET MAX */
234     static void
235 michael 896 quote_max(struct Client *source_p, int newval)
236 adx 30 {
237     if (newval > 0)
238     {
239     recalc_fdlimit(NULL);
240    
241     if (newval > MAXCLIENTS_MAX)
242     {
243     sendto_one(source_p,
244     ":%s NOTICE %s :You cannot set MAXCLIENTS to > %d, restoring to %d",
245 michael 1140 me.name, source_p->name, MAXCLIENTS_MAX, ServerInfo.max_clients);
246 adx 30 return;
247     }
248    
249     if (newval < MAXCLIENTS_MIN)
250     {
251     sendto_one(source_p,
252     ":%s NOTICE %s :You cannot set MAXCLIENTS to < %d, restoring to %d",
253     me.name, source_p->name, MAXCLIENTS_MIN, ServerInfo.max_clients);
254     return;
255     }
256    
257     ServerInfo.max_clients = newval;
258    
259     sendto_realops_flags(UMODE_ALL, L_ALL,
260 michael 1141 "%s set new MAXCLIENTS to %d (%d current)",
261 michael 1142 get_oper_name(source_p), ServerInfo.max_clients, Count.local);
262 adx 30 }
263     else
264     sendto_one(source_p, ":%s NOTICE %s :Current MAXCLIENTS = %d (%d)",
265     me.name, source_p->name, ServerInfo.max_clients, Count.local);
266     }
267    
268     /* SET MSGLOCALE */
269     static void
270 michael 896 quote_msglocale(struct Client *source_p, char *locale)
271 adx 30 {
272     if (locale != NULL)
273     {
274     set_locale(locale);
275     rebuild_isupport_message_line();
276     sendto_one(source_p, ":%s NOTICE %s :Set MSGLOCALE to '%s'",
277     me.name, source_p->name, get_locale());
278     }
279     else
280     sendto_one(source_p, ":%s NOTICE %s :MSGLOCALE is currently '%s'",
281     me.name, source_p->name, get_locale());
282     }
283    
284     /* SET SPAMNUM */
285     static void
286 michael 896 quote_spamnum(struct Client *source_p, int newval)
287 adx 30 {
288 michael 646 if (newval >= 0)
289 adx 30 {
290     if (newval == 0)
291     {
292     sendto_realops_flags(UMODE_ALL, L_ALL,
293     "%s has disabled ANTI_SPAMBOT", source_p->name);
294     GlobalSetOptions.spam_num = newval;
295     return;
296     }
297    
298     GlobalSetOptions.spam_num = IRCD_MAX(newval, MIN_SPAM_NUM);
299 michael 1141 sendto_realops_flags(UMODE_ALL, L_ALL, "%s has changed SPAMNUM to %i",
300     get_oper_name(source_p), GlobalSetOptions.spam_num);
301 adx 30 }
302     else
303     sendto_one(source_p, ":%s NOTICE %s :SPAMNUM is currently %i",
304 michael 1013 me.name, source_p->name, GlobalSetOptions.spam_num);
305 adx 30 }
306    
307     /* SET SPAMTIME */
308     static void
309 michael 896 quote_spamtime(struct Client *source_p, int newval)
310 adx 30 {
311     if (newval > 0)
312     {
313     GlobalSetOptions.spam_time = IRCD_MAX(newval, MIN_SPAM_TIME);
314     sendto_realops_flags(UMODE_ALL, L_ALL, "%s has changed SPAMTIME to %i",
315 michael 1141 get_oper_name(source_p), GlobalSetOptions.spam_time);
316 adx 30 }
317     else
318     sendto_one(source_p, ":%s NOTICE %s :SPAMTIME is currently %i",
319 michael 1013 me.name, source_p->name, GlobalSetOptions.spam_time);
320 adx 30 }
321    
322     /* this table is what splitmode may be set to */
323     static const char *splitmode_values[] =
324     {
325     "OFF",
326     "ON",
327     "AUTO",
328     NULL
329     };
330    
331     /* this table is what splitmode may be */
332     static const char *splitmode_status[] =
333     {
334     "OFF",
335     "AUTO (OFF)",
336     "ON",
337     "AUTO (ON)",
338     NULL
339     };
340    
341     /* SET SPLITMODE */
342     static void
343     quote_splitmode(struct Client *source_p, char *charval)
344     {
345     if (charval)
346     {
347     int newval;
348    
349 michael 896 for (newval = 0; splitmode_values[newval]; ++newval)
350 adx 30 if (irccmp(splitmode_values[newval], charval) == 0)
351     break;
352    
353     /* OFF */
354     if (newval == 0)
355     {
356     sendto_realops_flags(UMODE_ALL, L_ALL,
357     "%s is disabling splitmode",
358     get_oper_name(source_p));
359    
360     splitmode = 0;
361     splitchecking = 0;
362    
363     eventDelete(check_splitmode, NULL);
364     }
365     /* ON */
366     else if (newval == 1)
367     {
368     sendto_realops_flags(UMODE_ALL, L_ALL,
369     "%s is enabling and activating splitmode",
370     get_oper_name(source_p));
371    
372     splitmode = 1;
373     splitchecking = 0;
374    
375     /* we might be deactivating an automatic splitmode, so pull the event */
376     eventDelete(check_splitmode, NULL);
377     }
378     /* AUTO */
379     else if (newval == 2)
380     {
381     sendto_realops_flags(UMODE_ALL, L_ALL,
382     "%s is enabling automatic splitmode",
383     get_oper_name(source_p));
384    
385     splitchecking = 1;
386     check_splitmode(NULL);
387     }
388     }
389     else
390     /* if we add splitchecking to splitmode*2 we get a unique table to
391     * pull values back out of, splitmode can be four states - but you can
392     * only set to three, which means we cant use the same table --fl_
393     */
394     sendto_one(source_p, ":%s NOTICE %s :SPLITMODE is currently %s",
395     me.name, source_p->name,
396 michael 1141 splitmode_status[(splitchecking + (splitmode * 2))]);
397 adx 30 }
398    
399     /* SET SPLITNUM */
400     static void
401     quote_splitnum(struct Client *source_p, int newval)
402     {
403     if (newval >= 0)
404     {
405     sendto_realops_flags(UMODE_ALL, L_ALL,
406     "%s has changed SPLITNUM to %i",
407 michael 1141 get_oper_name(source_p), newval);
408 adx 30 split_servers = newval;
409    
410     if (splitchecking)
411     check_splitmode(NULL);
412     }
413     else
414     sendto_one(source_p, ":%s NOTICE %s :SPLITNUM is currently %i",
415     me.name, source_p->name, split_servers);
416     }
417    
418     /* SET SPLITUSERS */
419     static void
420     quote_splitusers(struct Client *source_p, int newval)
421     {
422     if (newval >= 0)
423     {
424     sendto_realops_flags(UMODE_ALL, L_ALL,
425     "%s has changed SPLITUSERS to %i",
426 michael 1141 get_oper_name(source_p), newval);
427 adx 30 split_users = newval;
428    
429     if (splitchecking)
430     check_splitmode(NULL);
431     }
432     else
433     sendto_one(source_p, ":%s NOTICE %s :SPLITUSERS is currently %i",
434     me.name, source_p->name, split_users);
435     }
436    
437     /* SET JFLOODTIME */
438     static void
439     quote_jfloodtime(struct Client *source_p, int newval)
440     {
441     if (newval >= 0)
442     {
443     sendto_realops_flags(UMODE_ALL, L_ALL,
444     "%s has changed JFLOODTIME to %i",
445 michael 1141 get_oper_name(source_p), newval);
446 adx 30 GlobalSetOptions.joinfloodtime = newval;
447     }
448     else
449     sendto_one(source_p, ":%s NOTICE %s :JFLOODTIME is currently %i",
450     me.name, source_p->name, GlobalSetOptions.joinfloodtime);
451     }
452    
453     /* SET JFLOODCOUNT */
454     static void
455     quote_jfloodcount(struct Client *source_p, int newval)
456     {
457     if (newval >= 0)
458     {
459     sendto_realops_flags(UMODE_ALL, L_ALL,
460     "%s has changed JFLOODCOUNT to %i",
461 michael 1141 get_oper_name(source_p), newval);
462 adx 30 GlobalSetOptions.joinfloodcount = newval;
463     }
464     else
465     sendto_one(source_p, ":%s NOTICE %s :JFLOODCOUNT is currently %i",
466     me.name, source_p->name, GlobalSetOptions.joinfloodcount);
467     }
468    
469     /* SET REJECTTIME */
470     static void
471     quote_rejecttime(struct Client *source_p, int newval)
472     {
473     if (newval >= 0)
474     {
475     sendto_realops_flags(UMODE_ALL, L_ALL,
476     "%s has changed REJECTTIME to %i seconds",
477 michael 1141 get_oper_name(source_p), newval);
478 adx 30 GlobalSetOptions.rejecttime = newval;
479     }
480     else
481     sendto_one(source_p, ":%s NOTICE %s :REJECTTIME is currently %i seconds",
482     me.name, source_p->name, GlobalSetOptions.rejecttime);
483     }
484    
485     /*
486     * mo_set - SET command handler
487     * set options while running
488     */
489     static void
490     mo_set(struct Client *client_p, struct Client *source_p,
491     int parc, char *parv[])
492     {
493     int n;
494     int newval;
495     const char *arg = NULL;
496     const char *intarg = NULL;
497 michael 1013 const struct SetStruct *tab = set_cmd_table;
498 adx 30
499     if (parc > 1)
500     {
501 michael 1013 /*
502     * Go through all the commands in set_cmd_table, until one is
503     * matched.
504 adx 30 */
505 michael 1013 for (; tab->handler; ++tab)
506 adx 30 {
507 michael 1013 if (!irccmp(tab->name, parv[1]))
508 adx 30 {
509     /*
510     * Command found; now execute the code
511     */
512     n = 2;
513    
514 michael 1013 if (tab->wants_char)
515 adx 30 arg = parv[n++];
516    
517 michael 1013 if (tab->wants_int)
518 adx 30 intarg = parv[n++];
519    
520     if ((n - 1) > parc)
521     {
522     if (parc > 2)
523     sendto_one(source_p,
524     ":%s NOTICE %s :SET %s expects (\"%s%s\") args",
525 michael 1013 me.name, source_p->name, tab->name,
526     (tab->wants_char ? "string, " : ""),
527     (tab->wants_char ? "int" : ""));
528 adx 30 }
529    
530     if (parc <= 2)
531     {
532     arg = NULL;
533     intarg = NULL;
534     }
535    
536 michael 1013 if (!strcmp(tab->name, "AUTOCONN") && (parc < 4))
537 adx 30 {
538     sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
539     me.name, source_p->name, "SET");
540     return;
541     }
542    
543 michael 1013 if (tab->wants_int && (parc > 2))
544 adx 30 {
545     if (intarg)
546     {
547     if (irccmp(intarg, "yes") == 0 || irccmp(intarg, "on") == 0)
548     newval = 1;
549     else if (irccmp(intarg, "no") == 0|| irccmp(intarg, "off") == 0)
550     newval = 0;
551     else
552     newval = atoi(intarg);
553     }
554     else
555     {
556     newval = -1;
557     }
558    
559     if (newval < 0)
560     {
561     sendto_one(source_p,
562     ":%s NOTICE %s :Value less than 0 illegal for %s",
563     me.name, source_p->name,
564 michael 1013 tab->name);
565 adx 30
566     return;
567     }
568     }
569     else
570     newval = -1;
571    
572 michael 1013 if (tab->wants_char)
573 adx 30 {
574 michael 1013 if (tab->wants_int)
575     tab->handler(source_p, arg, newval);
576 adx 30 else
577 michael 1013 tab->handler(source_p, arg);
578 adx 30 return;
579     }
580     else
581     {
582 michael 1013 if (tab->wants_int)
583     tab->handler(source_p, newval);
584 adx 30 else
585     /* Just in case someone actually wants a
586     * set function that takes no args.. *shrug* */
587 michael 1013 tab->handler(source_p);
588 adx 30 return;
589     }
590     }
591     }
592    
593     /*
594     * Code here will be executed when a /QUOTE SET command is not
595     * found within set_cmd_table.
596     */
597     sendto_one(source_p, ":%s NOTICE %s :Variable not found.",
598     me.name, source_p->name);
599     return;
600     }
601    
602     list_quote_commands(source_p);
603     }
604 michael 1230
605     static struct Message set_msgtab = {
606     "SET", 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
607     {m_unregistered, m_not_oper, rfc1459_command_send_error, m_ignore, mo_set, m_ignore}
608     };
609    
610     static void
611     module_init(void)
612     {
613     mod_add_cmd(&set_msgtab);
614     }
615    
616     static void
617     module_exit(void)
618     {
619     mod_del_cmd(&set_msgtab);
620     }
621    
622     struct module module_entry = {
623     .node = { NULL, NULL, NULL },
624     .name = NULL,
625     .version = "$Revision$",
626     .handle = NULL,
627     .modinit = module_init,
628     .modexit = module_exit,
629     .flags = 0
630     };

Properties

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