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: 1460
Committed: Fri Jul 6 14:32:53 2012 UTC (11 years, 8 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/modules/m_set.c
File size: 17321 byte(s)
Log Message:
- Added 'set' to operator privilege flags. Gives access to the "SET" command

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

Properties

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