ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/src/conf.C
Revision: 1.9
Committed: Sun Sep 16 18:54:44 2007 UTC (16 years, 8 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.8: +7 -2 lines
Log Message:
#defines to enum

File Contents

# User Rev Content
1 pippijn 1.1 /*
2     * conf.C: Configuration processing.
3 pippijn 1.9 *
4     * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team
5     * Rights to this code are as documented in COPYING.
6     *
7     *
8     * Portions of this file were derived from sources bearing the following license:
9 pippijn 1.2 * Rights to this code are documented in doc/pod/license.pod.
10 pippijn 1.4 * Copyright © 2005-2007 Atheme Project (http://www.atheme.org)
11 pippijn 1.1 */
12    
13 pippijn 1.9 static char const rcsid[] = "$Id: conf.C,v 1.8 2007-09-09 20:05:52 pippijn Exp $";
14 pippijn 1.1
15     #include "atheme.h"
16 pippijn 1.8 #include "confparse.h"
17 pippijn 1.4 #include <ermyth/crypto.h>
18     #include <ermyth/database.h>
19     #include <ermyth/module.h>
20 pippijn 1.1 #include <account/myuser.h>
21     #include <account/mychan.h>
22     #include <account/chanacs.h>
23     #include "uplink.h"
24     #include "pmodule.h"
25     #include "privs.h"
26    
27 pippijn 1.4 ConfTable::callbacks ConfTable::callback;
28    
29 pippijn 1.8 enum config_error
30 pippijn 1.5 {
31 pippijn 1.8 no_param,
32     wrong_param
33     };
34 pippijn 1.5
35 pippijn 1.8 template<config_error e>
36 pippijn 1.5 int param_error (config_entry_t *ce, char const * const msg = NULL);
37    
38     template<>
39 pippijn 1.8 int param_error<no_param> (config_entry_t *ce, char const * const msg)
40 pippijn 1.5 {
41 pippijn 1.6 slog (LG_INFO, "%s:%i: %s: %s",
42 pippijn 1.5 ce->ce_fileptr->cf_filename,
43 pippijn 1.6 ce->ce_varlinenum, msg ? msg : "no parameter for option",
44     ce->ce_varname);
45 pippijn 1.5 return 1;
46     }
47    
48     template<>
49 pippijn 1.8 int param_error<wrong_param> (config_entry_t *ce, char const * const msg)
50 pippijn 1.5 {
51 pippijn 1.6 slog (LG_INFO, "%s:%i: %s: %s",
52 pippijn 1.5 ce->ce_fileptr->cf_filename,
53 pippijn 1.6 ce->ce_varlinenum, msg ? msg : "wrong parameter for option",
54     ce->ce_varname);
55 pippijn 1.5 return 1;
56 pippijn 1.1 }
57    
58 pippijn 1.4 static int c_serverinfo (config_entry_t *);
59     static int c_general (config_entry_t *);
60     static int c_database (config_entry_t *);
61     static int c_uplink (config_entry_t *);
62     static int c_chanserv (config_entry_t *);
63     static int c_globserv (config_entry_t *);
64     static int c_operserv (config_entry_t *);
65     static int c_memoserv (config_entry_t *);
66     static int c_gameserv (config_entry_t *);
67     static int c_nickserv (config_entry_t *);
68     static int c_saslserv (config_entry_t *);
69     static int c_loadmodule (config_entry_t *);
70     static int c_backend (config_entry_t *);
71     static int c_crypto (config_entry_t *);
72     static int c_protocol (config_entry_t *);
73     static int c_operclass (config_entry_t *);
74     static int c_operator (config_entry_t *);
75     static int c_logfile (config_entry_t *);
76    
77     static int c_si_name (config_entry_t *);
78     static int c_si_desc (config_entry_t *);
79     static int c_si_numeric (config_entry_t *);
80     static int c_si_vhost (config_entry_t *);
81     static int c_si_recontime (config_entry_t *);
82     static int c_si_restarttime (config_entry_t *);
83     static int c_si_netname (config_entry_t *);
84     static int c_si_hidehostsuffix (config_entry_t *);
85     static int c_si_adminname (config_entry_t *);
86     static int c_si_adminemail (config_entry_t *);
87     static int c_si_mta (config_entry_t *);
88     static int c_si_loglevel (config_entry_t *);
89     static int c_si_maxlogins (config_entry_t *);
90     static int c_si_maxusers (config_entry_t *);
91     static int c_si_maxnicks (config_entry_t *);
92     static int c_si_maxchans (config_entry_t *);
93     static int c_si_emaillimit (config_entry_t *);
94     static int c_si_emailtime (config_entry_t *);
95     static int c_si_auth (config_entry_t *);
96     static int c_si_mdlimit (config_entry_t *);
97     static int c_si_casemapping (config_entry_t *);
98    
99     /* ChanServ client information. */
100     static int c_ci_nick (config_entry_t *);
101     static int c_ci_user (config_entry_t *);
102     static int c_ci_host (config_entry_t *);
103     static int c_ci_real (config_entry_t *);
104     static int c_ci_fantasy (config_entry_t *);
105     static int c_ci_vop (config_entry_t *);
106     static int c_ci_hop (config_entry_t *);
107     static int c_ci_aop (config_entry_t *);
108     static int c_ci_sop (config_entry_t *);
109     static int c_ci_changets (config_entry_t *);
110     static int c_ci_trigger (config_entry_t *);
111     static int c_ci_expire (config_entry_t *);
112     static int c_ci_maxchanacs (config_entry_t *);
113     static int c_ci_maxfounders (config_entry_t *);
114    
115     /* GlobServ client information. */
116     static int c_gl_nick (config_entry_t *);
117     static int c_gl_user (config_entry_t *);
118     static int c_gl_host (config_entry_t *);
119     static int c_gl_real (config_entry_t *);
120    
121     /* OperServ client information. */
122     static int c_oi_nick (config_entry_t *);
123     static int c_oi_user (config_entry_t *);
124     static int c_oi_host (config_entry_t *);
125     static int c_oi_real (config_entry_t *);
126 pippijn 1.1
127     /* NickServ client information. */
128 pippijn 1.4 static int c_ni_nick (config_entry_t *);
129     static int c_ni_user (config_entry_t *);
130     static int c_ni_host (config_entry_t *);
131     static int c_ni_real (config_entry_t *);
132     static int c_ni_spam (config_entry_t *);
133     static int c_ni_no_nick_ownership (config_entry_t *);
134     static int c_ni_expire (config_entry_t *);
135 pippijn 1.1
136     /* SaslServ client information. */
137 pippijn 1.4 static int c_ss_nick (config_entry_t *);
138     static int c_ss_user (config_entry_t *);
139     static int c_ss_host (config_entry_t *);
140     static int c_ss_real (config_entry_t *);
141 pippijn 1.1
142     /* MemoServ client information. */
143 pippijn 1.4 static int c_ms_nick (config_entry_t *);
144     static int c_ms_user (config_entry_t *);
145     static int c_ms_host (config_entry_t *);
146     static int c_ms_real (config_entry_t *);
147 pippijn 1.1
148     /* GameServ client information. */
149 pippijn 1.4 static int c_gs_nick (config_entry_t *);
150     static int c_gs_user (config_entry_t *);
151     static int c_gs_host (config_entry_t *);
152     static int c_gs_real (config_entry_t *);
153 pippijn 1.1
154     /* Database information. */
155 pippijn 1.4 static int c_db_user (config_entry_t *);
156     static int c_db_host (config_entry_t *);
157     static int c_db_password (config_entry_t *);
158     static int c_db_database (config_entry_t *);
159     static int c_db_port (config_entry_t *);
160    
161     static int c_gi_chan (config_entry_t *);
162     static int c_gi_silent (config_entry_t *);
163     static int c_gi_verbose_wallops (config_entry_t *);
164     static int c_gi_use_privmsg (config_entry_t *);
165     static int c_gi_join_chans (config_entry_t *);
166     static int c_gi_leave_chans (config_entry_t *);
167     static int c_gi_uflags (config_entry_t *);
168     static int c_gi_cflags (config_entry_t *);
169     static int c_gi_raw (config_entry_t *);
170     static int c_gi_flood_msgs (config_entry_t *);
171     static int c_gi_flood_time (config_entry_t *);
172     static int c_gi_kline_time (config_entry_t *);
173     static int c_gi_commit_interval (config_entry_t *);
174     static int c_gi_expire (config_entry_t *);
175     static int c_gi_secure (config_entry_t *);
176     static int c_gi_default_clone_limit (config_entry_t *);
177 pippijn 1.1
178     /* *INDENT-OFF* */
179    
180     static Token uflags[] = {
181     { "HOLD", MU_HOLD },
182     { "NEVEROP", MU_NEVEROP },
183     { "NOOP", MU_NOOP },
184     { "HIDEMAIL", MU_HIDEMAIL },
185     { "NONE", 0 },
186     { NULL, 0 }
187     };
188    
189     static Token cflags[] = {
190     { "HOLD", MC_HOLD },
191     { "SECURE", MC_SECURE },
192     { "VERBOSE", MC_VERBOSE },
193     { "KEEPTOPIC", MC_KEEPTOPIC },
194     { "VERBOSE_OPS", MC_VERBOSE_OPS },
195     { "TOPICLOCK", MC_TOPICLOCK },
196 pippijn 1.4 { "GUARD", MC_GUARD },
197 pippijn 1.1 { "NONE", 0 },
198     { NULL, 0 }
199     };
200    
201     static Token logflags[] = {
202 pippijn 1.4 { "DEBUG", LG_ALL },
203     { "TRACE", LG_INFO | LG_ERROR | LG_CMD_ALL | LG_NETWORK | LG_WALLOPS | LG_REGISTER },
204 pippijn 1.1 { "MISC", LG_INFO | LG_ERROR | LG_CMD_ADMIN | LG_CMD_REGISTER | LG_CMD_SET | LG_NETWORK | LG_WALLOPS | LG_REGISTER },
205 pippijn 1.4 { "NOTICE", LG_INFO | LG_ERROR | LG_CMD_ADMIN | LG_CMD_REGISTER | LG_NETWORK | LG_REGISTER },
206     { "ALL", LG_ALL },
207     { "INFO", LG_INFO },
208     { "ERROR", LG_ERROR },
209     { "COMMANDS", LG_CMD_ALL },
210     { "ADMIN", LG_CMD_ADMIN },
211     { "REGISTER", LG_CMD_REGISTER | LG_REGISTER },
212     { "SET", LG_CMD_SET },
213     { "NETWORK", LG_NETWORK },
214     { "WALLOPS", LG_WALLOPS },
215     { "RAWDATA", LG_RAWDATA },
216     { NULL, 0 }
217 pippijn 1.1 };
218    
219 pippijn 1.8 static ConfTable::list_type confblocks;
220     static ConfTable::list_type conf_si_table;
221     static ConfTable::list_type conf_ci_table;
222     static ConfTable::list_type conf_gl_table;
223     static ConfTable::list_type conf_oi_table;
224     static ConfTable::list_type conf_ni_table;
225     static ConfTable::list_type conf_db_table;
226     static ConfTable::list_type conf_gi_table;
227     static ConfTable::list_type conf_ms_table;
228     static ConfTable::list_type conf_la_table;
229     static ConfTable::list_type conf_ss_table;
230     static ConfTable::list_type conf_gs_table;
231 pippijn 1.1
232     /* *INDENT-ON* */
233    
234     static void
235 pippijn 1.4 conf_report_error (config_entry_t *ce, char const * const fmt, ...)
236 pippijn 1.1 {
237     va_list va;
238     char buf[BUFSIZE];
239    
240     return_if_fail (ce != NULL);
241     return_if_fail (fmt != NULL);
242    
243     va_start (va, fmt);
244     vsnprintf (buf, BUFSIZE, fmt, va);
245     va_end (va);
246    
247     slog (LG_INFO, "%s:%d: configuration error - %s", ce->ce_fileptr->cf_filename, ce->ce_varlinenum, buf);
248     }
249    
250     static void
251     conf_process (config_file_t *cfp)
252     {
253     config_file_t *cfptr;
254     config_entry_t *ce;
255     ConfTable *ct = NULL;
256    
257     for (cfptr = cfp; cfptr; cfptr = cfptr->cf_next)
258     {
259     for (ce = cfptr->cf_entries; ce; ce = ce->ce_next)
260 pippijn 1.4 {
261 pippijn 1.8 foreach (ConfTable *ct2, confblocks)
262     {
263     ct = ct2;
264     if (!strcasecmp (ct->name, ce->ce_varname))
265     {
266     ct->handler (ce);
267     break;
268     }
269     }
270 pippijn 1.4
271     if (ct == NULL)
272     conf_report_error (ce, "invalid configuration option: %s", ce->ce_varname);
273     }
274 pippijn 1.1 }
275     }
276    
277     bool
278     conf_parse (char *file)
279     {
280     config_file_t *cfp;
281    
282     cfp = config_load (file);
283     if (cfp == NULL)
284     {
285     slog (LG_ERROR, "conf_parse(): unable to load configuration file: %s", strerror (errno));
286    
287     return false;
288     }
289    
290     conf_process (cfp);
291     config_free (cfp);
292    
293 pippijn 1.4 if (!protocol::handler::loaded)
294 pippijn 1.1 {
295     slog (LG_ERROR, "No protocol module loaded, aborting");
296     exit (EXIT_FAILURE);
297     }
298    
299 pippijn 1.4 ConfTable::callback.ready ();
300 pippijn 1.1 return true;
301     }
302    
303     void
304     conf_init (void)
305     {
306 pippijn 1.4 me.init ();
307 pippijn 1.1 if (chansvs.nick)
308 pippijn 1.4 sfree (chansvs.nick);
309 pippijn 1.1 if (config_options.chan)
310 pippijn 1.4 sfree (config_options.chan);
311 pippijn 1.1 if (config_options.global)
312 pippijn 1.4 sfree (config_options.global);
313 pippijn 1.1 if (config_options.languagefile)
314 pippijn 1.4 sfree (config_options.languagefile);
315 pippijn 1.1
316 pippijn 1.4 chansvs.nick = config_options.chan = config_options.global = config_options.languagefile = NULL;
317 pippijn 1.1
318 pippijn 1.4 config_options.flood_msgs = config_options.flood_time = config_options.kline_time = config_options.commit_interval = 0;
319 pippijn 1.1
320     nicksvs.expiry = chansvs.expiry = 0;
321    
322     config_options.defuflags = config_options.defcflags = 0x00000000;
323    
324     config_options.silent = config_options.join_chans = config_options.leave_chans = config_options.raw = false;
325    
326     me.auth = AUTH_NONE;
327    
328     me.mdlimit = 30;
329    
330     chansvs.fantasy = false;
331     if (chansvs.me != NULL && fcmd_agent == chansvs.me)
332     fcmd_agent = NULL;
333     chansvs.ca_vop = CA_VOP_DEF & ca_all;
334     chansvs.ca_hop = CA_HOP_DEF & ca_all;
335     chansvs.ca_aop = CA_AOP_DEF & ca_all;
336     chansvs.ca_sop = CA_SOP_DEF & ca_all;
337     chansvs.changets = false;
338     if (chansvs.trigger != NULL)
339 pippijn 1.4 sfree (chansvs.trigger);
340 pippijn 1.1 chansvs.trigger = sstrdup ("!");
341     chansvs.maxchanacs = 0;
342 pippijn 1.4 chansvs.maxfounders = 4;
343 pippijn 1.1
344     if (!(runflags & RF_REHASHING))
345     {
346     if (me.name)
347 pippijn 1.4 sfree (me.name);
348 pippijn 1.1 if (me.desc)
349 pippijn 1.4 sfree (me.desc);
350 pippijn 1.1 if (me.vhost)
351 pippijn 1.4 sfree (me.vhost);
352 pippijn 1.1 if (chansvs.user)
353 pippijn 1.4 sfree (chansvs.user);
354 pippijn 1.1 if (chansvs.host)
355 pippijn 1.4 sfree (chansvs.host);
356 pippijn 1.1 if (chansvs.real)
357 pippijn 1.4 sfree (chansvs.real);
358 pippijn 1.1
359     me.name = me.desc = me.vhost = chansvs.user = chansvs.host = chansvs.real = NULL;
360    
361 pippijn 1.4 set_match_mapping (MATCH_RFC1459); /* default to RFC compliancy */
362 pippijn 1.1 }
363     }
364    
365     int
366 pippijn 1.8 subblock_handler (config_entry_t *ce, ConfTable::list_type &entries)
367 pippijn 1.1 {
368     ConfTable *ct = NULL;
369    
370     for (ce = ce->ce_entries; ce; ce = ce->ce_next)
371     {
372 pippijn 1.8 foreach (ConfTable *ct2, entries)
373     {
374     ct = ct2;
375    
376     if (!strcasecmp (ct->name, ce->ce_varname))
377     {
378     ct->handler (ce);
379     break;
380     }
381     }
382    
383 pippijn 1.1 if (ct == NULL)
384 pippijn 1.4 conf_report_error (ce, "invalid configuration option: %s", ce->ce_varname);
385 pippijn 1.1 }
386     return 0;
387     }
388    
389 pippijn 1.6 ConfTable *
390 pippijn 1.4 find_top_conf (char const * const name)
391 pippijn 1.1 {
392 pippijn 1.8 foreach (ConfTable *ct, confblocks)
393 pippijn 1.1 if (!strcasecmp (ct->name, name))
394     return ct;
395    
396     return NULL;
397     }
398    
399 pippijn 1.6 ConfTable *
400 pippijn 1.8 find_conf_item (char const * const name, ConfTable::list_type &conflist)
401 pippijn 1.1 {
402 pippijn 1.8 foreach (ConfTable *ct, conflist)
403 pippijn 1.1 if (!strcasecmp (ct->name, name))
404     return ct;
405    
406     return NULL;
407     }
408    
409     void
410 pippijn 1.4 add_top_conf (char const * const name, int (*handler) (config_entry_t *ce))
411 pippijn 1.1 {
412     ConfTable *ct;
413    
414     if ((ct = find_top_conf (name)))
415     {
416     slog (LG_DEBUG, "add_top_conf(): duplicate config block '%s'.", name);
417     return;
418     }
419    
420 pippijn 1.4 ct = new ConfTable (name, 1, handler);
421 pippijn 1.1
422 pippijn 1.8 confblocks.insert (ct);
423 pippijn 1.1 }
424    
425     void
426 pippijn 1.8 add_conf_item (char const * const name, ConfTable::list_type &conflist, int (*handler) (config_entry_t *ce))
427 pippijn 1.1 {
428     ConfTable *ct;
429    
430     if ((ct = find_conf_item (name, conflist)))
431     {
432     slog (LG_DEBUG, "add_conf_item(): duplicate item %s", name);
433     return;
434     }
435    
436 pippijn 1.4 ct = new ConfTable (name, 1, handler);
437 pippijn 1.1
438 pippijn 1.8 conflist.insert (ct);
439 pippijn 1.1 }
440    
441     void
442 pippijn 1.4 del_top_conf (char const * const name)
443 pippijn 1.1 {
444     ConfTable *ct;
445    
446     if (!(ct = find_top_conf (name)))
447     {
448     slog (LG_DEBUG, "del_top_conf(): cannot delete nonexistant block %s", name);
449     return;
450     }
451    
452 pippijn 1.8 confblocks.erase (ct);
453 pippijn 1.1
454 pippijn 1.4 delete ct;
455 pippijn 1.1 }
456    
457     void
458 pippijn 1.8 del_conf_item (char const * const name, ConfTable::list_type &conflist)
459 pippijn 1.1 {
460     ConfTable *ct;
461    
462     if (!(ct = find_conf_item (name, conflist)))
463     {
464     slog (LG_DEBUG, "del_conf_item(): cannot delete nonexistant item %s", name);
465     return;
466     }
467    
468 pippijn 1.8 conflist.erase (ct);
469 pippijn 1.1
470 pippijn 1.4 delete ct;
471 pippijn 1.1 }
472    
473     /* stolen from Sentinel */
474 pippijn 1.4 #define TOKEN_UNMATCHED -1
475     #define TOKEN_ERROR -2
476    
477     static int
478 pippijn 1.6 token_to_value (Token token_table[], char *token)
479 pippijn 1.1 {
480     int i;
481    
482     if ((token_table != NULL) && (token != NULL))
483     {
484     for (i = 0; token_table[i].text != NULL; i++)
485 pippijn 1.6 if (strcasecmp (token_table[i].text, token) == 0)
486     return token_table[i].value;
487 pippijn 1.1 /* If no match... */
488     return TOKEN_UNMATCHED;
489     }
490 pippijn 1.6
491 pippijn 1.1 /* Otherwise... */
492     return TOKEN_ERROR;
493     }
494    
495     void
496     init_newconf (void)
497     {
498 pippijn 1.4 #if 0
499 pippijn 1.6 conftable_heap = BlockHeapCreate (sizeof (ConfTable), 32);
500 pippijn 1.4 #endif
501 pippijn 1.1
502     /* First we set up the blocks. */
503     add_top_conf ("SERVERINFO", c_serverinfo);
504 pippijn 1.4 add_top_conf ("CHANSERV", c_chanserv);
505     add_top_conf ("GLOBAL", c_globserv);
506     add_top_conf ("OPERSERV", c_operserv);
507 pippijn 1.1 add_top_conf ("NICKSERV", c_nickserv);
508     add_top_conf ("SASLSERV", c_saslserv);
509     add_top_conf ("MEMOSERV", c_memoserv);
510     add_top_conf ("GAMESERV", c_gameserv);
511     add_top_conf ("UPLINK", c_uplink);
512     add_top_conf ("GENERAL", c_general);
513     add_top_conf ("DATABASE", c_database);
514     add_top_conf ("LOADMODULE", c_loadmodule);
515 pippijn 1.4 add_top_conf ("BACKEND", c_backend);
516     add_top_conf ("CRYPTO", c_crypto);
517     add_top_conf ("PROTOCOL", c_protocol);
518 pippijn 1.1 add_top_conf ("OPERCLASS", c_operclass);
519     add_top_conf ("OPERATOR", c_operator);
520     add_top_conf ("LOGFILE", c_logfile);
521    
522     /* Now we fill in the information */
523 pippijn 1.8 add_conf_item ("NAME", conf_si_table, c_si_name);
524     add_conf_item ("DESC", conf_si_table, c_si_desc);
525     add_conf_item ("NUMERIC", conf_si_table, c_si_numeric);
526     add_conf_item ("VHOST", conf_si_table, c_si_vhost);
527     add_conf_item ("RECONTIME", conf_si_table, c_si_recontime);
528     add_conf_item ("RESTARTTIME", conf_si_table, c_si_restarttime);
529     add_conf_item ("EXPIRE", conf_si_table, c_gi_expire);
530     add_conf_item ("NETNAME", conf_si_table, c_si_netname);
531     add_conf_item ("HIDEHOSTSUFFIX", conf_si_table, c_si_hidehostsuffix);
532     add_conf_item ("ADMINNAME", conf_si_table, c_si_adminname);
533     add_conf_item ("ADMINEMAIL", conf_si_table, c_si_adminemail);
534     add_conf_item ("MTA", conf_si_table, c_si_mta);
535     add_conf_item ("LOGLEVEL", conf_si_table, c_si_loglevel);
536     add_conf_item ("MAXLOGINS", conf_si_table, c_si_maxlogins);
537     add_conf_item ("MAXUSERS", conf_si_table, c_si_maxusers);
538     add_conf_item ("MAXNICKS", conf_si_table, c_si_maxnicks);
539     add_conf_item ("MAXCHANS", conf_si_table, c_si_maxchans);
540     add_conf_item ("EMAILLIMIT", conf_si_table, c_si_emaillimit);
541     add_conf_item ("EMAILTIME", conf_si_table, c_si_emailtime);
542     add_conf_item ("AUTH", conf_si_table, c_si_auth);
543     add_conf_item ("MDLIMIT", conf_si_table, c_si_mdlimit);
544     add_conf_item ("CASEMAPPING", conf_si_table, c_si_casemapping);
545    
546     /* general{} block. */
547     add_conf_item ("CHAN", conf_gi_table, c_gi_chan);
548     add_conf_item ("VERBOSE_WALLOPS", conf_gi_table, c_gi_verbose_wallops);
549     add_conf_item ("USE_PRIVMSG", conf_gi_table, c_gi_use_privmsg);
550     add_conf_item ("SILENT", conf_gi_table, c_gi_silent);
551     add_conf_item ("JOIN_CHANS", conf_gi_table, c_gi_join_chans);
552     add_conf_item ("LEAVE_CHANS", conf_gi_table, c_gi_leave_chans);
553     add_conf_item ("UFLAGS", conf_gi_table, c_gi_uflags);
554     add_conf_item ("CFLAGS", conf_gi_table, c_gi_cflags);
555     add_conf_item ("RAW", conf_gi_table, c_gi_raw);
556     add_conf_item ("SECURE", conf_gi_table, c_gi_secure);
557     add_conf_item ("FLOOD_MSGS", conf_gi_table, c_gi_flood_msgs);
558     add_conf_item ("FLOOD_TIME", conf_gi_table, c_gi_flood_time);
559     add_conf_item ("KLINE_TIME", conf_gi_table, c_gi_kline_time);
560     add_conf_item ("COMMIT_INTERVAL", conf_gi_table, c_gi_commit_interval);
561     add_conf_item ("EXPIRE", conf_gi_table, c_gi_expire);
562     add_conf_item ("DEFAULT_CLONE_LIMIT", conf_gi_table, c_gi_default_clone_limit);
563    
564     /* chanserv{} block */
565     add_conf_item ("NICK", conf_ci_table, c_ci_nick);
566     add_conf_item ("USER", conf_ci_table, c_ci_user);
567     add_conf_item ("HOST", conf_ci_table, c_ci_host);
568     add_conf_item ("REAL", conf_ci_table, c_ci_real);
569     add_conf_item ("FANTASY", conf_ci_table, c_ci_fantasy);
570     add_conf_item ("VOP", conf_ci_table, c_ci_vop);
571     add_conf_item ("HOP", conf_ci_table, c_ci_hop);
572     add_conf_item ("AOP", conf_ci_table, c_ci_aop);
573     add_conf_item ("SOP", conf_ci_table, c_ci_sop);
574     add_conf_item ("CHANGETS", conf_ci_table, c_ci_changets);
575     add_conf_item ("TRIGGER", conf_ci_table, c_ci_trigger);
576     add_conf_item ("EXPIRE", conf_ci_table, c_ci_expire);
577     add_conf_item ("MAXCHANACS", conf_ci_table, c_ci_maxchanacs);
578     add_conf_item ("MAXFOUNDERS", conf_ci_table, c_ci_maxfounders);
579    
580     /* global{} block */
581     add_conf_item ("NICK", conf_gl_table, c_gl_nick);
582     add_conf_item ("USER", conf_gl_table, c_gl_user);
583     add_conf_item ("HOST", conf_gl_table, c_gl_host);
584     add_conf_item ("REAL", conf_gl_table, c_gl_real);
585    
586     /* operserv{} block */
587     add_conf_item ("NICK", conf_oi_table, c_oi_nick);
588     add_conf_item ("USER", conf_oi_table, c_oi_user);
589     add_conf_item ("HOST", conf_oi_table, c_oi_host);
590     add_conf_item ("REAL", conf_oi_table, c_oi_real);
591    
592     /* nickserv{} block */
593     add_conf_item ("NICK", conf_ni_table, c_ni_nick);
594     add_conf_item ("USER", conf_ni_table, c_ni_user);
595     add_conf_item ("HOST", conf_ni_table, c_ni_host);
596     add_conf_item ("REAL", conf_ni_table, c_ni_real);
597     add_conf_item ("SPAM", conf_ni_table, c_ni_spam);
598     add_conf_item ("NO_NICK_OWNERSHIP", conf_ni_table, c_ni_no_nick_ownership);
599     add_conf_item ("EXPIRE", conf_ni_table, c_ni_expire);
600    
601     /* saslserv{} block */
602     add_conf_item ("NICK", conf_ss_table, c_ss_nick);
603     add_conf_item ("USER", conf_ss_table, c_ss_user);
604     add_conf_item ("HOST", conf_ss_table, c_ss_host);
605     add_conf_item ("REAL", conf_ss_table, c_ss_real);
606    
607     /* memoserv{} block */
608     add_conf_item ("NICK", conf_ms_table, c_ms_nick);
609     add_conf_item ("USER", conf_ms_table, c_ms_user);
610     add_conf_item ("HOST", conf_ms_table, c_ms_host);
611     add_conf_item ("REAL", conf_ms_table, c_ms_real);
612    
613     /* memoserv{} block */
614     add_conf_item ("NICK", conf_gs_table, c_gs_nick);
615     add_conf_item ("USER", conf_gs_table, c_gs_user);
616     add_conf_item ("HOST", conf_gs_table, c_gs_host);
617     add_conf_item ("REAL", conf_gs_table, c_gs_real);
618    
619     /* database{} block */
620     add_conf_item ("USER", conf_db_table, c_db_user);
621     add_conf_item ("HOST", conf_db_table, c_db_host);
622     add_conf_item ("PASSWORD", conf_db_table, c_db_password);
623     add_conf_item ("DATABASE", conf_db_table, c_db_database);
624     add_conf_item ("PORT", conf_db_table, c_db_port);
625     }
626    
627     void
628     deinit_conf (void)
629     {
630     #if 0
631     conftable_heap = BlockHeapCreate (sizeof (ConfTable), 32);
632     #endif
633    
634     /* Now we fill in the information */
635     del_conf_item ("NAME", conf_si_table);
636     del_conf_item ("DESC", conf_si_table);
637     del_conf_item ("NUMERIC", conf_si_table);
638     del_conf_item ("VHOST", conf_si_table);
639     del_conf_item ("RECONTIME", conf_si_table);
640     del_conf_item ("RESTARTTIME", conf_si_table);
641     del_conf_item ("EXPIRE", conf_si_table);
642     del_conf_item ("NETNAME", conf_si_table);
643     del_conf_item ("HIDEHOSTSUFFIX", conf_si_table);
644     del_conf_item ("ADMINNAME", conf_si_table);
645     del_conf_item ("ADMINEMAIL", conf_si_table);
646     del_conf_item ("MTA", conf_si_table);
647     del_conf_item ("LOGLEVEL", conf_si_table);
648     del_conf_item ("MAXLOGINS", conf_si_table);
649     del_conf_item ("MAXUSERS", conf_si_table);
650     del_conf_item ("MAXNICKS", conf_si_table);
651     del_conf_item ("MAXCHANS", conf_si_table);
652     del_conf_item ("EMAILLIMIT", conf_si_table);
653     del_conf_item ("EMAILTIME", conf_si_table);
654     del_conf_item ("AUTH", conf_si_table);
655     del_conf_item ("MDLIMIT", conf_si_table);
656     del_conf_item ("CASEMAPPING", conf_si_table);
657 pippijn 1.1
658     /* general{} block. */
659 pippijn 1.8 del_conf_item ("CHAN", conf_gi_table);
660     del_conf_item ("VERBOSE_WALLOPS", conf_gi_table);
661     del_conf_item ("USE_PRIVMSG", conf_gi_table);
662     del_conf_item ("SILENT", conf_gi_table);
663     del_conf_item ("JOIN_CHANS", conf_gi_table);
664     del_conf_item ("LEAVE_CHANS", conf_gi_table);
665     del_conf_item ("UFLAGS", conf_gi_table);
666     del_conf_item ("CFLAGS", conf_gi_table);
667     del_conf_item ("RAW", conf_gi_table);
668     del_conf_item ("SECURE", conf_gi_table);
669     del_conf_item ("FLOOD_MSGS", conf_gi_table);
670     del_conf_item ("FLOOD_TIME", conf_gi_table);
671     del_conf_item ("KLINE_TIME", conf_gi_table);
672     del_conf_item ("COMMIT_INTERVAL", conf_gi_table);
673     del_conf_item ("EXPIRE", conf_gi_table);
674     del_conf_item ("DEFAULT_CLONE_LIMIT", conf_gi_table);
675 pippijn 1.1
676     /* chanserv{} block */
677 pippijn 1.8 del_conf_item ("NICK", conf_ci_table);
678     del_conf_item ("USER", conf_ci_table);
679     del_conf_item ("HOST", conf_ci_table);
680     del_conf_item ("REAL", conf_ci_table);
681     del_conf_item ("FANTASY", conf_ci_table);
682     del_conf_item ("VOP", conf_ci_table);
683     del_conf_item ("HOP", conf_ci_table);
684     del_conf_item ("AOP", conf_ci_table);
685     del_conf_item ("SOP", conf_ci_table);
686     del_conf_item ("CHANGETS", conf_ci_table);
687     del_conf_item ("TRIGGER", conf_ci_table);
688     del_conf_item ("EXPIRE", conf_ci_table);
689     del_conf_item ("MAXCHANACS", conf_ci_table);
690     del_conf_item ("MAXFOUNDERS", conf_ci_table);
691 pippijn 1.1
692     /* global{} block */
693 pippijn 1.8 del_conf_item ("NICK", conf_gl_table);
694     del_conf_item ("USER", conf_gl_table);
695     del_conf_item ("HOST", conf_gl_table);
696     del_conf_item ("REAL", conf_gl_table);
697 pippijn 1.1
698     /* operserv{} block */
699 pippijn 1.8 del_conf_item ("NICK", conf_oi_table);
700     del_conf_item ("USER", conf_oi_table);
701     del_conf_item ("HOST", conf_oi_table);
702     del_conf_item ("REAL", conf_oi_table);
703 pippijn 1.1
704     /* nickserv{} block */
705 pippijn 1.8 del_conf_item ("NICK", conf_ni_table);
706     del_conf_item ("USER", conf_ni_table);
707     del_conf_item ("HOST", conf_ni_table);
708     del_conf_item ("REAL", conf_ni_table);
709     del_conf_item ("SPAM", conf_ni_table);
710     del_conf_item ("NO_NICK_OWNERSHIP", conf_ni_table);
711     del_conf_item ("EXPIRE", conf_ni_table);
712 pippijn 1.1
713     /* saslserv{} block */
714 pippijn 1.8 del_conf_item ("NICK", conf_ss_table);
715     del_conf_item ("USER", conf_ss_table);
716     del_conf_item ("HOST", conf_ss_table);
717     del_conf_item ("REAL", conf_ss_table);
718 pippijn 1.1
719     /* memoserv{} block */
720 pippijn 1.8 del_conf_item ("NICK", conf_ms_table);
721     del_conf_item ("USER", conf_ms_table);
722     del_conf_item ("HOST", conf_ms_table);
723     del_conf_item ("REAL", conf_ms_table);
724 pippijn 1.1
725     /* memoserv{} block */
726 pippijn 1.8 del_conf_item ("NICK", conf_gs_table);
727     del_conf_item ("USER", conf_gs_table);
728     del_conf_item ("HOST", conf_gs_table);
729     del_conf_item ("REAL", conf_gs_table);
730 pippijn 1.1
731     /* database{} block */
732 pippijn 1.8 del_conf_item ("USER", conf_db_table);
733     del_conf_item ("HOST", conf_db_table);
734     del_conf_item ("PASSWORD", conf_db_table);
735     del_conf_item ("DATABASE", conf_db_table);
736     del_conf_item ("PORT", conf_db_table);
737    
738     /* First we set up the blocks. */
739     del_top_conf ("SERVERINFO");
740     del_top_conf ("CHANSERV");
741     del_top_conf ("GLOBAL");
742     del_top_conf ("OPERSERV");
743     del_top_conf ("NICKSERV");
744     del_top_conf ("SASLSERV");
745     del_top_conf ("MEMOSERV");
746     del_top_conf ("GAMESERV");
747     del_top_conf ("UPLINK");
748     del_top_conf ("GENERAL");
749     del_top_conf ("DATABASE");
750     del_top_conf ("LOADMODULE");
751     del_top_conf ("BACKEND");
752     del_top_conf ("CRYPTO");
753     del_top_conf ("PROTOCOL");
754     del_top_conf ("OPERCLASS");
755     del_top_conf ("OPERATOR");
756     del_top_conf ("LOGFILE");
757 pippijn 1.1 }
758    
759     static int
760     c_serverinfo (config_entry_t *ce)
761     {
762 pippijn 1.8 return subblock_handler (ce, conf_si_table);
763 pippijn 1.1 }
764    
765     static int
766 pippijn 1.4 c_chanserv (config_entry_t *ce)
767 pippijn 1.1 {
768 pippijn 1.8 return subblock_handler (ce, conf_ci_table);
769 pippijn 1.1 }
770    
771     static int
772 pippijn 1.4 c_globserv (config_entry_t *ce)
773 pippijn 1.1 {
774 pippijn 1.8 return subblock_handler (ce, conf_gl_table);
775 pippijn 1.1 }
776    
777     static int
778 pippijn 1.4 c_operserv (config_entry_t *ce)
779 pippijn 1.1 {
780 pippijn 1.8 return subblock_handler (ce, conf_oi_table);
781 pippijn 1.1 }
782    
783     static int
784     c_nickserv (config_entry_t *ce)
785     {
786 pippijn 1.8 return subblock_handler (ce, conf_ni_table);
787 pippijn 1.1 }
788    
789     static int
790     c_saslserv (config_entry_t *ce)
791     {
792 pippijn 1.8 return subblock_handler (ce, conf_ss_table);
793 pippijn 1.1 }
794    
795     static int
796     c_memoserv (config_entry_t *ce)
797     {
798 pippijn 1.8 return subblock_handler (ce, conf_ms_table);
799 pippijn 1.1 }
800    
801     static int
802     c_gameserv (config_entry_t *ce)
803     {
804 pippijn 1.8 return subblock_handler (ce, conf_gs_table);
805 pippijn 1.1 }
806    
807     static int
808     c_database (config_entry_t *ce)
809     {
810 pippijn 1.8 return subblock_handler (ce, conf_db_table);
811 pippijn 1.4 }
812    
813     static int
814     c_protocol (config_entry_t *ce)
815     {
816     char *name;
817    
818     if (cold_start == false)
819     return 0;
820    
821 pippijn 1.5 if (ce->vardata<char *> () == NULL)
822 pippijn 1.8 return param_error<no_param> (ce);
823 pippijn 1.4
824 pippijn 1.5 name = ce->vardata<char *> ();
825 pippijn 1.4
826     typedef factory::factory_mgr<protocol::handler> protocol_factory;
827     protocol_factory &f = protocol_factory::instance ();
828    
829     if (!f.provides (name))
830 pippijn 1.8 return param_error<wrong_param> (ce, "no such protocol handler");
831 pippijn 1.4
832     phandler = f.create (name);
833    
834 pippijn 1.1 return 0;
835     }
836    
837     static int
838     c_loadmodule (config_entry_t *ce)
839     {
840     char *name;
841    
842     if (cold_start == false)
843     return 0;
844    
845 pippijn 1.5 if (ce->vardata<char *> () == NULL)
846 pippijn 1.8 return param_error<no_param> (ce);
847 pippijn 1.1
848 pippijn 1.5 name = ce->vardata<char *> ();
849 pippijn 1.1
850 pippijn 1.4 if (!modules::provides (name))
851 pippijn 1.8 return param_error<wrong_param> (ce, "no such module");
852 pippijn 1.4
853     modules::enable (name);
854    
855     return 0;
856     }
857    
858     static int
859     c_crypto (config_entry_t *ce)
860     {
861     char *name;
862    
863     if (cold_start == false)
864     return 0;
865    
866 pippijn 1.5 if (ce->vardata<char *> () == NULL)
867 pippijn 1.8 return param_error<no_param> (ce);
868 pippijn 1.4
869 pippijn 1.5 name = ce->vardata<char *> ();
870 pippijn 1.4
871     typedef factory::factory_mgr<crypto::handler> crypto_factory;
872     crypto_factory &f = crypto_factory::instance ();
873    
874     if (!f.provides (name))
875 pippijn 1.8 return param_error<wrong_param> (ce, "no such crypto handler");
876 pippijn 1.4
877     crypter = f.create (name);
878    
879     return 0;
880     }
881    
882     static int
883     c_backend (config_entry_t *ce)
884     {
885     char *name;
886    
887     if (cold_start == false)
888     return 0;
889    
890 pippijn 1.5 if (ce->vardata<char *> () == NULL)
891 pippijn 1.8 return param_error<no_param> (ce);
892 pippijn 1.4
893 pippijn 1.5 name = ce->vardata<char *> ();
894 pippijn 1.4
895     typedef factory::factory_mgr<database::handler> backend_factory;
896     backend_factory &f = backend_factory::instance ();
897    
898     if (!f.provides (name))
899 pippijn 1.8 return param_error<wrong_param> (ce, "no such database backend");
900 pippijn 1.4
901     backend = f.create (name);
902    
903     return 0;
904 pippijn 1.1 }
905    
906     static int
907     c_uplink (config_entry_t *ce)
908     {
909     char *name;
910     char *host = NULL, *vhost = NULL, *password = NULL;
911     unsigned int port = 0;
912    
913 pippijn 1.5 if (ce->vardata<char *> () == NULL)
914 pippijn 1.8 return param_error<no_param> (ce);
915 pippijn 1.1
916 pippijn 1.5 if (me.name != NULL && !irccasecmp (ce->vardata<char *> (), me.name))
917     slog (LG_ERROR, "%s:%d: uplink's server name %s should not be the same as our server name, continuing anyway", ce->ce_fileptr->cf_filename, ce->ce_varlinenum, ce->vardata<char *> ());
918     else if (!strchr (ce->vardata<char *> (), '.'))
919     slog (LG_ERROR, "%s:%d: uplink's server name %s is invalid, continuing anyway", ce->ce_fileptr->cf_filename, ce->ce_varlinenum, ce->vardata<char *> ());
920     else if (isdigit (ce->vardata<char *> ()[0]))
921     slog (LG_ERROR, "%s:%d: uplink's server name %s starts with a digit, probably invalid (continuing anyway)", ce->ce_fileptr->cf_filename, ce->ce_varlinenum, ce->vardata<char *> ());
922 pippijn 1.1
923 pippijn 1.5 name = sstrdup (ce->vardata<char *> ());
924 pippijn 1.1
925     for (ce = ce->ce_entries; ce; ce = ce->ce_next)
926     {
927     if (!strcasecmp ("HOST", ce->ce_varname))
928 pippijn 1.4 {
929 pippijn 1.5 if (ce->vardata<char *> () == NULL)
930 pippijn 1.8 return param_error<no_param> (ce);
931 pippijn 1.1
932 pippijn 1.5 host = sstrdup (ce->vardata<char *> ());
933 pippijn 1.4 }
934 pippijn 1.1 else if (!strcasecmp ("VHOST", ce->ce_varname))
935 pippijn 1.4 {
936 pippijn 1.5 if (ce->vardata<char *> () == NULL)
937 pippijn 1.8 return param_error<no_param> (ce);
938 pippijn 1.1
939 pippijn 1.5 vhost = sstrdup (ce->vardata<char *> ());
940 pippijn 1.4 }
941 pippijn 1.1 else if (!strcasecmp ("PASSWORD", ce->ce_varname))
942 pippijn 1.4 {
943 pippijn 1.5 if (ce->vardata<char *> () == NULL)
944 pippijn 1.8 return param_error<no_param> (ce);
945 pippijn 1.1
946 pippijn 1.5 password = sstrdup (ce->vardata<char *> ());
947 pippijn 1.4 }
948 pippijn 1.1 else if (!strcasecmp ("PORT", ce->ce_varname))
949 pippijn 1.4 {
950 pippijn 1.5 if (ce->vardata<char *> () == NULL)
951 pippijn 1.8 return param_error<no_param> (ce);
952 pippijn 1.1
953 pippijn 1.5 port = ce->vardata<int> ();
954 pippijn 1.4 }
955 pippijn 1.1 else
956 pippijn 1.4 {
957     slog (LG_ERROR, "%s:%d: Invalid configuration option uplink::%s", ce->ce_fileptr->cf_filename, ce->ce_varlinenum, ce->ce_varname);
958     continue;
959     }
960 pippijn 1.1 }
961    
962     uplink_add (name, host, password, vhost, port);
963    
964 pippijn 1.4 sfree (name);
965     sfree (host);
966     sfree (password);
967     sfree (vhost);
968 pippijn 1.1
969     return 0;
970     }
971    
972     static int
973     c_operclass (config_entry_t *ce)
974     {
975     operclass_t *operclass;
976     char *name;
977     char *privs = NULL, *newprivs;
978     int flags = 0;
979    
980 pippijn 1.5 if (ce->vardata<char *> () == NULL)
981 pippijn 1.8 return param_error<no_param> (ce);
982 pippijn 1.1
983 pippijn 1.5 name = ce->vardata<char *> ();
984 pippijn 1.1
985     for (ce = ce->ce_entries; ce; ce = ce->ce_next)
986     {
987     if (!strcasecmp ("PRIVS", ce->ce_varname))
988 pippijn 1.4 {
989 pippijn 1.5 if (ce->vardata<char *> () == NULL && ce->ce_entries == NULL)
990 pippijn 1.8 return param_error<no_param> (ce);
991 pippijn 1.4
992     if (ce->ce_entries == NULL)
993     {
994     if (privs == NULL)
995 pippijn 1.5 privs = sstrdup (ce->vardata<char *> ());
996 pippijn 1.4 else
997     {
998 pippijn 1.7 newprivs = salloc<char> (strlen (privs) + 1 + strlen (ce->vardata<char *> ()) + 1);
999 pippijn 1.4 strcpy (newprivs, privs);
1000     strcat (newprivs, " ");
1001 pippijn 1.5 strcat (newprivs, ce->vardata<char *> ());
1002 pippijn 1.4 sfree (privs);
1003     privs = newprivs;
1004     }
1005     }
1006     else
1007     {
1008     config_entry_t *conf_p;
1009     /*
1010     * New definition format for operclasses.
1011     *
1012     * operclass "sra" {
1013     * privs = {
1014     * special:ircop;
1015     * };
1016     * };
1017     *
1018     * - nenolod
1019     */
1020     for (conf_p = ce->ce_entries; conf_p; conf_p = conf_p->ce_next)
1021     {
1022     if (privs == NULL)
1023     privs = sstrdup (conf_p->ce_varname);
1024     else
1025     {
1026 pippijn 1.7 newprivs = salloc<char> (strlen (privs) + 1 + strlen (conf_p->ce_varname) + 1);
1027 pippijn 1.4 strcpy (newprivs, privs);
1028     strcat (newprivs, " ");
1029     strcat (newprivs, conf_p->ce_varname);
1030     sfree (privs);
1031     privs = newprivs;
1032     }
1033     }
1034     }
1035     }
1036 pippijn 1.1 else if (!strcasecmp ("NEEDOPER", ce->ce_varname))
1037 pippijn 1.4 flags |= OPERCLASS_NEEDOPER;
1038 pippijn 1.1 else
1039 pippijn 1.4 {
1040     slog (LG_ERROR, "%s:%d: Invalid configuration option operclass::%s", ce->ce_fileptr->cf_filename, ce->ce_varlinenum, ce->ce_varname);
1041     continue;
1042     }
1043 pippijn 1.1 }
1044    
1045     operclass = operclass_add (name, privs ? privs : "");
1046     if (operclass != NULL)
1047     operclass->flags |= flags;
1048 pippijn 1.4 sfree (privs);
1049 pippijn 1.1 return 0;
1050     }
1051    
1052     static int
1053     c_operator (config_entry_t *ce)
1054     {
1055     char *name;
1056     operclass_t *operclass = NULL;
1057     config_entry_t *topce;
1058    
1059 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1060 pippijn 1.8 return param_error<no_param> (ce);
1061 pippijn 1.1
1062     topce = ce;
1063 pippijn 1.5 name = ce->vardata<char *> ();
1064 pippijn 1.1
1065     for (ce = ce->ce_entries; ce; ce = ce->ce_next)
1066     {
1067     if (!strcasecmp ("OPERCLASS", ce->ce_varname))
1068 pippijn 1.4 {
1069 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1070 pippijn 1.8 return param_error<no_param> (ce);
1071 pippijn 1.4
1072 pippijn 1.5 operclass = operclass_find (ce->vardata<char *> ());
1073 pippijn 1.4 if (operclass == NULL)
1074 pippijn 1.5 slog (LG_ERROR, "%s:%d: invalid operclass %s for operator %s", ce->ce_fileptr->cf_filename, ce->ce_varlinenum, ce->vardata<char *> (), name);
1075 pippijn 1.4 }
1076 pippijn 1.1 else
1077 pippijn 1.4 {
1078     slog (LG_ERROR, "%s:%d: Invalid configuration option operator::%s", ce->ce_fileptr->cf_filename, ce->ce_varlinenum, ce->ce_varname);
1079     continue;
1080     }
1081 pippijn 1.1 }
1082    
1083     if (operclass != NULL)
1084     soper_add (name, operclass->name, SOPER_CONF);
1085     else
1086     slog (LG_ERROR, "%s:%d: skipping operator %s because of bad/missing parameters", topce->ce_fileptr->cf_filename, topce->ce_varlinenum, name);
1087     return 0;
1088     }
1089    
1090     static int
1091     c_general (config_entry_t *ce)
1092     {
1093 pippijn 1.8 return subblock_handler (ce, conf_gi_table);
1094 pippijn 1.1 }
1095    
1096     static int
1097     c_si_name (config_entry_t *ce)
1098     {
1099 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1100 pippijn 1.8 return param_error<no_param> (ce);
1101 pippijn 1.1
1102     if (!(runflags & RF_REHASHING))
1103 pippijn 1.5 me.name = sstrdup (ce->vardata<char *> ());
1104 pippijn 1.1
1105     return 0;
1106     }
1107    
1108     static int
1109     c_si_desc (config_entry_t *ce)
1110     {
1111 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1112 pippijn 1.8 return param_error<no_param> (ce);
1113 pippijn 1.1
1114     if (me.desc != NULL)
1115 pippijn 1.4 sfree (me.desc);
1116 pippijn 1.5 me.desc = sstrdup (ce->vardata<char *> ());
1117 pippijn 1.1
1118     return 0;
1119     }
1120    
1121     static int
1122     c_si_numeric (config_entry_t *ce)
1123     {
1124 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1125 pippijn 1.8 return param_error<no_param> (ce);
1126 pippijn 1.1
1127     if (!(runflags & RF_REHASHING))
1128 pippijn 1.5 me.numeric = sstrdup (ce->vardata<char *> ());
1129 pippijn 1.1
1130     return 0;
1131     }
1132    
1133     static int
1134     c_si_mdlimit (config_entry_t *ce)
1135     {
1136 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1137 pippijn 1.8 return param_error<no_param> (ce);
1138 pippijn 1.1
1139 pippijn 1.5 me.mdlimit = ce->vardata<int> ();
1140 pippijn 1.1
1141     return 0;
1142     }
1143    
1144     static int
1145     c_si_vhost (config_entry_t *ce)
1146     {
1147 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1148 pippijn 1.8 return param_error<no_param> (ce);
1149 pippijn 1.1
1150 pippijn 1.5 me.vhost = sstrdup (ce->vardata<char *> ());
1151 pippijn 1.1
1152     return 0;
1153     }
1154    
1155     static int
1156     c_si_recontime (config_entry_t *ce)
1157     {
1158 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1159 pippijn 1.8 return param_error<no_param> (ce);
1160 pippijn 1.1
1161 pippijn 1.5 me.recontime = ce->vardata<int> ();
1162 pippijn 1.1
1163     return 0;
1164     }
1165    
1166     static int
1167     c_si_restarttime (config_entry_t *ce)
1168     {
1169 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1170 pippijn 1.8 return param_error<no_param> (ce);
1171 pippijn 1.1
1172 pippijn 1.5 me.restarttime = ce->vardata<int> ();
1173 pippijn 1.1
1174     return 0;
1175     }
1176    
1177     static int
1178     c_si_netname (config_entry_t *ce)
1179     {
1180 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1181 pippijn 1.8 return param_error<no_param> (ce);
1182 pippijn 1.1
1183 pippijn 1.5 me.netname = sstrdup (ce->vardata<char *> ());
1184 pippijn 1.1
1185     return 0;
1186     }
1187    
1188     static int
1189     c_si_hidehostsuffix (config_entry_t *ce)
1190     {
1191 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1192 pippijn 1.8 return param_error<no_param> (ce);
1193 pippijn 1.1
1194 pippijn 1.5 me.hidehostsuffix = sstrdup (ce->vardata<char *> ());
1195 pippijn 1.1
1196     return 0;
1197     }
1198    
1199     static int
1200     c_si_adminname (config_entry_t *ce)
1201     {
1202 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1203 pippijn 1.8 return param_error<no_param> (ce);
1204 pippijn 1.1
1205 pippijn 1.5 me.adminname = sstrdup (ce->vardata<char *> ());
1206 pippijn 1.1
1207     return 0;
1208     }
1209    
1210     static int
1211     c_si_adminemail (config_entry_t *ce)
1212     {
1213 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1214 pippijn 1.8 return param_error<no_param> (ce);
1215 pippijn 1.1
1216 pippijn 1.5 me.adminemail = sstrdup (ce->vardata<char *> ());
1217 pippijn 1.1
1218     return 0;
1219     }
1220    
1221     static int
1222     c_si_mta (config_entry_t *ce)
1223     {
1224 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1225 pippijn 1.8 return param_error<no_param> (ce);
1226 pippijn 1.1
1227 pippijn 1.5 me.mta = sstrdup (ce->vardata<char *> ());
1228 pippijn 1.1
1229     return 0;
1230     }
1231    
1232     static int
1233     c_si_loglevel (config_entry_t *ce)
1234     {
1235     config_entry_t *flce;
1236     int val;
1237     int mask = 0;
1238    
1239 pippijn 1.5 if (ce->vardata<char *> () != NULL)
1240 pippijn 1.1 {
1241 pippijn 1.5 val = token_to_value (logflags, ce->vardata<char *> ());
1242 pippijn 1.1
1243     if ((val != TOKEN_UNMATCHED) && (val != TOKEN_ERROR))
1244 pippijn 1.4 mask |= val;
1245 pippijn 1.1 else
1246 pippijn 1.6 slog (LG_INFO, "%s:%d: unknown flag: %s", ce->ce_fileptr->cf_filename, ce->ce_varlinenum, ce->vardata<char *> ());
1247 pippijn 1.1 }
1248     for (flce = ce->ce_entries; flce; flce = flce->ce_next)
1249     {
1250     val = token_to_value (logflags, flce->ce_varname);
1251    
1252     if ((val != TOKEN_UNMATCHED) && (val != TOKEN_ERROR))
1253 pippijn 1.4 mask |= val;
1254 pippijn 1.1 else
1255 pippijn 1.6 slog (LG_INFO, "%s:%d: unknown flag: %s", flce->ce_fileptr->cf_filename, flce->ce_varlinenum, flce->ce_varname);
1256 pippijn 1.1 }
1257     log_master_set_mask (mask);
1258    
1259     return 0;
1260     }
1261    
1262     static int
1263     c_si_maxlogins (config_entry_t *ce)
1264     {
1265 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1266 pippijn 1.8 return param_error<no_param> (ce);
1267 pippijn 1.1
1268 pippijn 1.5 me.maxlogins = ce->vardata<int> ();
1269 pippijn 1.1
1270     return 0;
1271    
1272     }
1273    
1274     static int
1275     c_si_maxusers (config_entry_t *ce)
1276     {
1277 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1278 pippijn 1.8 return param_error<no_param> (ce);
1279 pippijn 1.1
1280 pippijn 1.5 me.maxusers = ce->vardata<int> ();
1281 pippijn 1.1
1282     return 0;
1283    
1284     }
1285    
1286     static int
1287     c_si_maxnicks (config_entry_t *ce)
1288     {
1289 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1290 pippijn 1.8 return param_error<no_param> (ce);
1291 pippijn 1.1
1292 pippijn 1.5 me.maxnicks = ce->vardata<int> ();
1293 pippijn 1.1
1294     return 0;
1295     }
1296    
1297     static int
1298     c_si_maxchans (config_entry_t *ce)
1299     {
1300 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1301 pippijn 1.8 return param_error<no_param> (ce);
1302 pippijn 1.1
1303 pippijn 1.5 me.maxchans = ce->vardata<int> ();
1304 pippijn 1.1
1305     return 0;
1306     }
1307    
1308     static int
1309     c_si_emaillimit (config_entry_t *ce)
1310     {
1311 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1312 pippijn 1.8 return param_error<no_param> (ce);
1313 pippijn 1.1
1314 pippijn 1.5 me.emaillimit = ce->vardata<int> ();
1315 pippijn 1.1
1316     return 0;
1317     }
1318    
1319     static int
1320     c_si_emailtime (config_entry_t *ce)
1321     {
1322 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1323 pippijn 1.8 return param_error<no_param> (ce);
1324 pippijn 1.1
1325 pippijn 1.5 me.emailtime = ce->vardata<int> ();
1326 pippijn 1.1
1327     return 0;
1328     }
1329    
1330     static int
1331     c_si_auth (config_entry_t *ce)
1332     {
1333 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1334 pippijn 1.8 return param_error<no_param> (ce);
1335 pippijn 1.1
1336 pippijn 1.5 if (!strcasecmp ("EMAIL", ce->vardata<char *> ()))
1337 pippijn 1.1 me.auth = AUTH_EMAIL;
1338    
1339     else
1340     me.auth = AUTH_NONE;
1341    
1342     return 0;
1343     }
1344    
1345     static int
1346     c_si_casemapping (config_entry_t *ce)
1347     {
1348 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1349 pippijn 1.8 return param_error<no_param> (ce);
1350 pippijn 1.1
1351 pippijn 1.5 if (!strcasecmp ("ASCII", ce->vardata<char *> ()))
1352 pippijn 1.1 set_match_mapping (MATCH_ASCII);
1353    
1354     else
1355     set_match_mapping (MATCH_RFC1459);
1356    
1357     return 0;
1358     }
1359    
1360     static int
1361     c_ci_nick (config_entry_t *ce)
1362     {
1363 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1364 pippijn 1.8 return param_error<no_param> (ce);
1365 pippijn 1.1
1366     if (chansvs.nick != NULL)
1367 pippijn 1.4 sfree (chansvs.nick);
1368 pippijn 1.5 chansvs.nick = sstrdup (ce->vardata<char *> ());
1369 pippijn 1.1
1370     return 0;
1371     }
1372    
1373     static int
1374     c_ci_user (config_entry_t *ce)
1375     {
1376 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1377 pippijn 1.8 return param_error<no_param> (ce);
1378 pippijn 1.1
1379     if (chansvs.user != NULL)
1380 pippijn 1.4 sfree (chansvs.user);
1381 pippijn 1.5 chansvs.user = sstrdup (ce->vardata<char *> ());
1382 pippijn 1.1
1383     return 0;
1384     }
1385    
1386     static int
1387     c_ci_host (config_entry_t *ce)
1388     {
1389 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1390 pippijn 1.8 return param_error<no_param> (ce);
1391 pippijn 1.1
1392     if (chansvs.host != NULL)
1393 pippijn 1.4 sfree (chansvs.host);
1394 pippijn 1.5 chansvs.host = sstrdup (ce->vardata<char *> ());
1395 pippijn 1.1
1396     return 0;
1397     }
1398    
1399     static int
1400     c_ci_real (config_entry_t *ce)
1401     {
1402 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1403 pippijn 1.8 return param_error<no_param> (ce);
1404 pippijn 1.1
1405     if (chansvs.real != NULL)
1406 pippijn 1.4 sfree (chansvs.real);
1407 pippijn 1.5 chansvs.real = sstrdup (ce->vardata<char *> ());
1408 pippijn 1.1
1409     return 0;
1410     }
1411    
1412     static int
1413     c_ci_fantasy (config_entry_t *ce)
1414     {
1415     chansvs.fantasy = true;
1416    
1417     if (chansvs.me != NULL)
1418     fcmd_agent = chansvs.me;
1419    
1420     return 0;
1421     }
1422    
1423     static int
1424     c_ci_vop (config_entry_t *ce)
1425     {
1426 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1427 pippijn 1.8 return param_error<no_param> (ce);
1428 pippijn 1.1
1429 pippijn 1.5 chansvs.ca_vop = flags_to_bitmask (ce->vardata<char *> (), chanacs_flags, 0);
1430 pippijn 1.1
1431     return 0;
1432     }
1433    
1434     static int
1435     c_ci_hop (config_entry_t *ce)
1436     {
1437 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1438 pippijn 1.8 return param_error<no_param> (ce);
1439 pippijn 1.1
1440 pippijn 1.5 chansvs.ca_hop = flags_to_bitmask (ce->vardata<char *> (), chanacs_flags, 0);
1441 pippijn 1.1
1442     return 0;
1443     }
1444    
1445     static int
1446     c_ci_aop (config_entry_t *ce)
1447     {
1448 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1449 pippijn 1.8 return param_error<no_param> (ce);
1450 pippijn 1.1
1451 pippijn 1.5 chansvs.ca_aop = flags_to_bitmask (ce->vardata<char *> (), chanacs_flags, 0);
1452 pippijn 1.1
1453     return 0;
1454     }
1455    
1456     static int
1457     c_ci_sop (config_entry_t *ce)
1458     {
1459 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1460 pippijn 1.8 return param_error<no_param> (ce);
1461 pippijn 1.1
1462 pippijn 1.5 chansvs.ca_sop = flags_to_bitmask (ce->vardata<char *> (), chanacs_flags, 0);
1463 pippijn 1.1
1464     return 0;
1465     }
1466    
1467     static int
1468     c_ci_changets (config_entry_t *ce)
1469     {
1470     chansvs.changets = true;
1471     return 0;
1472     }
1473    
1474     static int
1475     c_ci_trigger (config_entry_t *ce)
1476     {
1477 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1478 pippijn 1.8 return param_error<no_param> (ce);
1479 pippijn 1.1
1480     if (chansvs.trigger != NULL)
1481 pippijn 1.4 sfree (chansvs.trigger);
1482 pippijn 1.5 chansvs.trigger = sstrdup (ce->vardata<char *> ());
1483 pippijn 1.1
1484     return 0;
1485     }
1486    
1487     static int
1488     c_ci_expire (config_entry_t *ce)
1489     {
1490 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1491 pippijn 1.8 return param_error<no_param> (ce);
1492 pippijn 1.1
1493 pippijn 1.5 chansvs.expiry = (ce->vardata<int> () * 60 * 60 * 24);
1494 pippijn 1.1
1495     return 0;
1496     }
1497    
1498     static int
1499     c_ci_maxchanacs (config_entry_t *ce)
1500     {
1501 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1502 pippijn 1.8 return param_error<no_param> (ce);
1503 pippijn 1.1
1504 pippijn 1.5 chansvs.maxchanacs = ce->vardata<int> ();
1505 pippijn 1.1
1506     return 0;
1507     }
1508    
1509     static int
1510 pippijn 1.4 c_ci_maxfounders (config_entry_t *ce)
1511     {
1512 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1513 pippijn 1.8 return param_error<no_param> (ce);
1514 pippijn 1.4
1515 pippijn 1.5 chansvs.maxfounders = ce->vardata<int> ();
1516 pippijn 1.4
1517     return 0;
1518     }
1519    
1520     static int
1521 pippijn 1.1 c_gi_chan (config_entry_t *ce)
1522     {
1523 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1524 pippijn 1.8 return param_error<no_param> (ce);
1525 pippijn 1.1
1526 pippijn 1.5 config_options.chan = sstrdup (ce->vardata<char *> ());
1527 pippijn 1.1
1528     return 0;
1529     }
1530    
1531     static int
1532     c_gi_silent (config_entry_t *ce)
1533     {
1534     config_options.silent = true;
1535     return 0;
1536     }
1537    
1538     static int
1539     c_gi_verbose_wallops (config_entry_t *ce)
1540     {
1541     config_options.verbose_wallops = true;
1542     return 0;
1543     }
1544    
1545     static int
1546     c_gi_use_privmsg (config_entry_t *ce)
1547     {
1548     config_options.use_privmsg = true;
1549     return 0;
1550     }
1551    
1552     static int
1553     c_gi_secure (config_entry_t *ce)
1554     {
1555     config_options.secure = true;
1556     return 0;
1557     }
1558    
1559     static int
1560     c_gi_join_chans (config_entry_t *ce)
1561     {
1562     config_options.join_chans = true;
1563     return 0;
1564     }
1565    
1566     static int
1567     c_gi_leave_chans (config_entry_t *ce)
1568     {
1569     config_options.leave_chans = true;
1570     return 0;
1571     }
1572    
1573     static int
1574     c_gi_uflags (config_entry_t *ce)
1575     {
1576     config_entry_t *flce;
1577    
1578     for (flce = ce->ce_entries; flce; flce = flce->ce_next)
1579     {
1580     int val;
1581    
1582     val = token_to_value (uflags, flce->ce_varname);
1583    
1584     if ((val != TOKEN_UNMATCHED) && (val != TOKEN_ERROR))
1585 pippijn 1.4 config_options.defuflags |= val;
1586 pippijn 1.1
1587     else
1588 pippijn 1.4 {
1589     slog (LG_INFO, "%s:%d: unknown flag: %s", flce->ce_fileptr->cf_filename, flce->ce_varlinenum, flce->ce_varname);
1590     }
1591 pippijn 1.1 }
1592    
1593     return 0;
1594     }
1595    
1596     static int
1597     c_gi_cflags (config_entry_t *ce)
1598     {
1599     config_entry_t *flce;
1600    
1601     for (flce = ce->ce_entries; flce; flce = flce->ce_next)
1602     {
1603     int val;
1604    
1605     val = token_to_value (cflags, flce->ce_varname);
1606    
1607     if ((val != TOKEN_UNMATCHED) && (val != TOKEN_ERROR))
1608 pippijn 1.4 config_options.defcflags |= val;
1609 pippijn 1.1
1610     else
1611 pippijn 1.4 {
1612     slog (LG_INFO, "%s:%d: unknown flag: %s", flce->ce_fileptr->cf_filename, flce->ce_varlinenum, flce->ce_varname);
1613     }
1614 pippijn 1.1 }
1615    
1616     if (config_options.defcflags & MC_TOPICLOCK)
1617     config_options.defcflags |= MC_KEEPTOPIC;
1618    
1619     return 0;
1620     }
1621    
1622     static int
1623     c_gi_raw (config_entry_t *ce)
1624     {
1625     config_options.raw = true;
1626     return 0;
1627     }
1628    
1629     static int
1630     c_gi_flood_msgs (config_entry_t *ce)
1631     {
1632 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1633 pippijn 1.8 return param_error<no_param> (ce);
1634 pippijn 1.1
1635 pippijn 1.5 config_options.flood_msgs = ce->vardata<int> ();
1636 pippijn 1.1
1637     return 0;
1638     }
1639    
1640     static int
1641     c_gi_flood_time (config_entry_t *ce)
1642     {
1643 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1644 pippijn 1.8 return param_error<no_param> (ce);
1645 pippijn 1.1
1646 pippijn 1.5 config_options.flood_time = ce->vardata<int> ();
1647 pippijn 1.1
1648     return 0;
1649     }
1650    
1651     static int
1652     c_gi_kline_time (config_entry_t *ce)
1653     {
1654 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1655 pippijn 1.8 return param_error<no_param> (ce);
1656 pippijn 1.1
1657 pippijn 1.5 config_options.kline_time = (ce->vardata<int> () * 60 * 60 * 24);
1658 pippijn 1.1
1659     return 0;
1660     }
1661    
1662     static int
1663     c_gi_commit_interval (config_entry_t *ce)
1664     {
1665 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1666 pippijn 1.8 return param_error<no_param> (ce);
1667 pippijn 1.1
1668 pippijn 1.5 config_options.commit_interval = (ce->vardata<int> () * 60);
1669 pippijn 1.1
1670     return 0;
1671     }
1672    
1673     static int
1674     c_gi_expire (config_entry_t *ce)
1675     {
1676 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1677 pippijn 1.8 return param_error<no_param> (ce);
1678 pippijn 1.1
1679     slog (LG_INFO, "warning: general::expire has been deprecated. please use nickserv::expire and chanserv::expire respectively.");
1680    
1681 pippijn 1.5 nicksvs.expiry = (ce->vardata<int> () * 60 * 60 * 24);
1682     chansvs.expiry = (ce->vardata<int> () * 60 * 60 * 24);
1683 pippijn 1.1
1684     return 0;
1685     }
1686    
1687     static int
1688 pippijn 1.4 c_gi_default_clone_limit (config_entry_t *ce)
1689     {
1690 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1691 pippijn 1.8 return param_error<no_param> (ce);
1692 pippijn 1.4
1693 pippijn 1.5 config_options.default_clone_limit = ce->vardata<int> ();
1694 pippijn 1.4
1695     return 0;
1696     }
1697    
1698     static int
1699 pippijn 1.1 c_oi_nick (config_entry_t *ce)
1700     {
1701 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1702 pippijn 1.8 return param_error<no_param> (ce);
1703 pippijn 1.1
1704     if (opersvs.nick != NULL)
1705 pippijn 1.4 sfree (opersvs.nick);
1706 pippijn 1.5 opersvs.nick = sstrdup (ce->vardata<char *> ());
1707 pippijn 1.1
1708     return 0;
1709     }
1710    
1711     static int
1712     c_oi_user (config_entry_t *ce)
1713     {
1714 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1715 pippijn 1.8 return param_error<no_param> (ce);
1716 pippijn 1.1
1717     if (opersvs.user != NULL)
1718 pippijn 1.4 sfree (opersvs.user);
1719 pippijn 1.5 opersvs.user = sstrdup (ce->vardata<char *> ());
1720 pippijn 1.1
1721     return 0;
1722     }
1723    
1724     static int
1725     c_oi_host (config_entry_t *ce)
1726     {
1727 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1728 pippijn 1.8 return param_error<no_param> (ce);
1729 pippijn 1.1
1730     if (opersvs.host != NULL)
1731 pippijn 1.4 sfree (opersvs.host);
1732 pippijn 1.5 opersvs.host = sstrdup (ce->vardata<char *> ());
1733 pippijn 1.1
1734     return 0;
1735     }
1736    
1737     static int
1738     c_oi_real (config_entry_t *ce)
1739     {
1740 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1741 pippijn 1.8 return param_error<no_param> (ce);
1742 pippijn 1.1
1743     if (opersvs.real != NULL)
1744 pippijn 1.4 sfree (opersvs.real);
1745 pippijn 1.5 opersvs.real = sstrdup (ce->vardata<char *> ());
1746 pippijn 1.1
1747     return 0;
1748     }
1749    
1750     static int
1751     c_ni_nick (config_entry_t *ce)
1752     {
1753 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1754 pippijn 1.8 return param_error<no_param> (ce);
1755 pippijn 1.1
1756     if (nicksvs.nick != NULL)
1757 pippijn 1.4 sfree (nicksvs.nick);
1758 pippijn 1.5 nicksvs.nick = sstrdup (ce->vardata<char *> ());
1759 pippijn 1.1
1760     return 0;
1761     }
1762    
1763     static int
1764     c_ni_user (config_entry_t *ce)
1765     {
1766 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1767 pippijn 1.8 return param_error<no_param> (ce);
1768 pippijn 1.1
1769     if (nicksvs.user != NULL)
1770 pippijn 1.4 sfree (nicksvs.user);
1771 pippijn 1.5 nicksvs.user = sstrdup (ce->vardata<char *> ());
1772 pippijn 1.1
1773     return 0;
1774     }
1775    
1776     static int
1777     c_ni_host (config_entry_t *ce)
1778     {
1779 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1780 pippijn 1.8 return param_error<no_param> (ce);
1781 pippijn 1.1
1782     if (nicksvs.host != NULL)
1783 pippijn 1.4 sfree (nicksvs.host);
1784 pippijn 1.5 nicksvs.host = sstrdup (ce->vardata<char *> ());
1785 pippijn 1.1
1786     return 0;
1787     }
1788    
1789     static int
1790     c_ni_real (config_entry_t *ce)
1791     {
1792 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1793 pippijn 1.8 return param_error<no_param> (ce);
1794 pippijn 1.1
1795     if (nicksvs.real != NULL)
1796 pippijn 1.4 sfree (nicksvs.real);
1797 pippijn 1.5 nicksvs.real = sstrdup (ce->vardata<char *> ());
1798 pippijn 1.1
1799     return 0;
1800     }
1801    
1802     static int
1803     c_ni_spam (config_entry_t *ce)
1804     {
1805     nicksvs.spam = true;
1806     return 0;
1807     }
1808    
1809     static int
1810     c_ni_no_nick_ownership (config_entry_t *ce)
1811     {
1812     nicksvs.no_nick_ownership = true;
1813     return 0;
1814     }
1815    
1816     static int
1817     c_ni_expire (config_entry_t *ce)
1818     {
1819 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1820 pippijn 1.8 return param_error<no_param> (ce);
1821 pippijn 1.1
1822 pippijn 1.5 nicksvs.expiry = (ce->vardata<int> () * 60 * 60 * 24);
1823 pippijn 1.1
1824     return 0;
1825     }
1826    
1827     static int
1828     c_ss_nick (config_entry_t *ce)
1829     {
1830 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1831 pippijn 1.8 return param_error<no_param> (ce);
1832 pippijn 1.1
1833     if (saslsvs.nick != NULL)
1834 pippijn 1.4 sfree (saslsvs.nick);
1835 pippijn 1.5 saslsvs.nick = sstrdup (ce->vardata<char *> ());
1836 pippijn 1.1
1837     return 0;
1838     }
1839    
1840     static int
1841     c_ss_user (config_entry_t *ce)
1842     {
1843 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1844 pippijn 1.8 return param_error<no_param> (ce);
1845 pippijn 1.1
1846     if (saslsvs.user != NULL)
1847 pippijn 1.4 sfree (saslsvs.user);
1848 pippijn 1.5 saslsvs.user = sstrdup (ce->vardata<char *> ());
1849 pippijn 1.1
1850     return 0;
1851     }
1852    
1853     static int
1854     c_ss_host (config_entry_t *ce)
1855     {
1856 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1857 pippijn 1.8 return param_error<no_param> (ce);
1858 pippijn 1.1
1859     if (saslsvs.host != NULL)
1860 pippijn 1.4 sfree (saslsvs.host);
1861 pippijn 1.5 saslsvs.host = sstrdup (ce->vardata<char *> ());
1862 pippijn 1.1
1863     return 0;
1864     }
1865    
1866     static int
1867     c_ss_real (config_entry_t *ce)
1868     {
1869 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1870 pippijn 1.8 return param_error<no_param> (ce);
1871 pippijn 1.1
1872     if (saslsvs.real != NULL)
1873 pippijn 1.4 sfree (saslsvs.real);
1874 pippijn 1.5 saslsvs.real = sstrdup (ce->vardata<char *> ());
1875 pippijn 1.1
1876     return 0;
1877     }
1878    
1879     static int
1880     c_ms_nick (config_entry_t *ce)
1881     {
1882 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1883 pippijn 1.8 return param_error<no_param> (ce);
1884 pippijn 1.1
1885     if (memosvs.nick != NULL)
1886 pippijn 1.4 sfree (memosvs.nick);
1887 pippijn 1.5 memosvs.nick = sstrdup (ce->vardata<char *> ());
1888 pippijn 1.1
1889     return 0;
1890     }
1891    
1892     static int
1893     c_ms_user (config_entry_t *ce)
1894     {
1895 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1896 pippijn 1.8 return param_error<no_param> (ce);
1897 pippijn 1.1
1898     if (memosvs.user != NULL)
1899 pippijn 1.4 sfree (memosvs.user);
1900 pippijn 1.5 memosvs.user = sstrdup (ce->vardata<char *> ());
1901 pippijn 1.1
1902     return 0;
1903     }
1904    
1905     static int
1906     c_ms_host (config_entry_t *ce)
1907     {
1908 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1909 pippijn 1.8 return param_error<no_param> (ce);
1910 pippijn 1.1
1911     if (memosvs.host != NULL)
1912 pippijn 1.4 sfree (memosvs.host);
1913 pippijn 1.5 memosvs.host = sstrdup (ce->vardata<char *> ());
1914 pippijn 1.1
1915     return 0;
1916     }
1917    
1918     static int
1919     c_ms_real (config_entry_t *ce)
1920     {
1921 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1922 pippijn 1.8 return param_error<no_param> (ce);
1923 pippijn 1.1
1924     if (memosvs.real != NULL)
1925 pippijn 1.4 sfree (memosvs.real);
1926 pippijn 1.5 memosvs.real = sstrdup (ce->vardata<char *> ());
1927 pippijn 1.1
1928     return 0;
1929     }
1930    
1931     static int
1932     c_gs_nick (config_entry_t *ce)
1933     {
1934 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1935 pippijn 1.8 return param_error<no_param> (ce);
1936 pippijn 1.1
1937     if (gamesvs.nick != NULL)
1938 pippijn 1.4 sfree (gamesvs.nick);
1939 pippijn 1.5 gamesvs.nick = sstrdup (ce->vardata<char *> ());
1940 pippijn 1.1
1941     return 0;
1942     }
1943    
1944     static int
1945     c_gs_user (config_entry_t *ce)
1946     {
1947 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1948 pippijn 1.8 return param_error<no_param> (ce);
1949 pippijn 1.1
1950     if (gamesvs.user != NULL)
1951 pippijn 1.4 sfree (gamesvs.user);
1952 pippijn 1.5 gamesvs.user = sstrdup (ce->vardata<char *> ());
1953 pippijn 1.1
1954     return 0;
1955     }
1956    
1957     static int
1958     c_gs_host (config_entry_t *ce)
1959     {
1960 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1961 pippijn 1.8 return param_error<no_param> (ce);
1962 pippijn 1.1
1963     if (gamesvs.host != NULL)
1964 pippijn 1.4 sfree (gamesvs.host);
1965 pippijn 1.5 gamesvs.host = sstrdup (ce->vardata<char *> ());
1966 pippijn 1.1
1967     return 0;
1968     }
1969    
1970     static int
1971     c_gs_real (config_entry_t *ce)
1972     {
1973 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1974 pippijn 1.8 return param_error<no_param> (ce);
1975 pippijn 1.1
1976     if (gamesvs.real != NULL)
1977 pippijn 1.4 sfree (gamesvs.real);
1978 pippijn 1.5 gamesvs.real = sstrdup (ce->vardata<char *> ());
1979 pippijn 1.1
1980     return 0;
1981     }
1982    
1983     static int
1984     c_gl_nick (config_entry_t *ce)
1985     {
1986 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1987 pippijn 1.8 return param_error<no_param> (ce);
1988 pippijn 1.1
1989     if (globsvs.nick != NULL)
1990 pippijn 1.4 sfree (globsvs.nick);
1991 pippijn 1.5 globsvs.nick = sstrdup (ce->vardata<char *> ());
1992 pippijn 1.1
1993     return 0;
1994     }
1995    
1996     static int
1997     c_gl_user (config_entry_t *ce)
1998     {
1999 pippijn 1.5 if (ce->vardata<char *> () == NULL)
2000 pippijn 1.8 return param_error<no_param> (ce);
2001 pippijn 1.1
2002     if (globsvs.user != NULL)
2003 pippijn 1.4 sfree (globsvs.user);
2004 pippijn 1.5 globsvs.user = sstrdup (ce->vardata<char *> ());
2005 pippijn 1.1
2006     return 0;
2007     }
2008    
2009     static int
2010     c_gl_host (config_entry_t *ce)
2011     {
2012 pippijn 1.5 if (ce->vardata<char *> () == NULL)
2013 pippijn 1.8 return param_error<no_param> (ce);
2014 pippijn 1.1
2015     if (globsvs.host != NULL)
2016 pippijn 1.4 sfree (globsvs.host);
2017 pippijn 1.5 globsvs.host = sstrdup (ce->vardata<char *> ());
2018 pippijn 1.1
2019     return 0;
2020     }
2021    
2022     static int
2023     c_gl_real (config_entry_t *ce)
2024     {
2025 pippijn 1.5 if (ce->vardata<char *> () == NULL)
2026 pippijn 1.8 return param_error<no_param> (ce);
2027 pippijn 1.1
2028     if (globsvs.real != NULL)
2029 pippijn 1.4 sfree (globsvs.real);
2030 pippijn 1.5 globsvs.real = sstrdup (ce->vardata<char *> ());
2031 pippijn 1.1
2032     return 0;
2033     }
2034    
2035     static int
2036     c_db_user (config_entry_t *ce)
2037     {
2038 pippijn 1.5 if (ce->vardata<char *> () == NULL)
2039 pippijn 1.8 return param_error<no_param> (ce);
2040 pippijn 1.1
2041     if (database_options.user != NULL)
2042 pippijn 1.4 sfree (database_options.user);
2043 pippijn 1.5 database_options.user = sstrdup (ce->vardata<char *> ());
2044 pippijn 1.1
2045     return 0;
2046     }
2047    
2048     static int
2049     c_db_host (config_entry_t *ce)
2050     {
2051 pippijn 1.5 if (ce->vardata<char *> () == NULL)
2052 pippijn 1.8 return param_error<no_param> (ce);
2053 pippijn 1.1
2054     if (database_options.host != NULL)
2055 pippijn 1.4 sfree (database_options.host);
2056 pippijn 1.5 database_options.host = sstrdup (ce->vardata<char *> ());
2057 pippijn 1.1
2058     return 0;
2059     }
2060    
2061     static int
2062     c_db_password (config_entry_t *ce)
2063     {
2064 pippijn 1.5 if (ce->vardata<char *> () == NULL)
2065 pippijn 1.8 return param_error<no_param> (ce);
2066 pippijn 1.1
2067     if (database_options.pass != NULL)
2068 pippijn 1.4 sfree (database_options.pass);
2069 pippijn 1.5 database_options.pass = sstrdup (ce->vardata<char *> ());
2070 pippijn 1.1
2071     return 0;
2072     }
2073    
2074     static int
2075     c_db_database (config_entry_t *ce)
2076     {
2077 pippijn 1.5 if (ce->vardata<char *> () == NULL)
2078 pippijn 1.8 return param_error<no_param> (ce);
2079 pippijn 1.1
2080     if (database_options.database != NULL)
2081 pippijn 1.4 sfree (database_options.database);
2082 pippijn 1.5 database_options.database = sstrdup (ce->vardata<char *> ());
2083 pippijn 1.1
2084     return 0;
2085     }
2086    
2087     static int
2088     c_db_port (config_entry_t *ce)
2089     {
2090 pippijn 1.5 if (ce->vardata<int> () == 0)
2091 pippijn 1.8 return param_error<no_param> (ce);
2092 pippijn 1.1
2093 pippijn 1.5 database_options.port = ce->vardata<int> ();
2094 pippijn 1.1
2095     return 0;
2096     }
2097    
2098     static int
2099     c_logfile (config_entry_t *ce)
2100     {
2101     config_entry_t *flce;
2102     unsigned int logval = 0;
2103    
2104 pippijn 1.5 if (ce->vardata<char *> () == NULL)
2105 pippijn 1.8 return param_error<no_param> (ce);
2106 pippijn 1.1
2107     for (flce = ce->ce_entries; flce; flce = flce->ce_next)
2108     {
2109     int val;
2110    
2111     val = token_to_value (logflags, flce->ce_varname);
2112    
2113     if ((val != TOKEN_UNMATCHED) && (val != TOKEN_ERROR))
2114 pippijn 1.4 logval |= val;
2115 pippijn 1.1 else
2116 pippijn 1.4 {
2117     slog (LG_INFO, "%s:%d: unknown flag: %s", flce->ce_fileptr->cf_filename, flce->ce_varlinenum, flce->ce_varname);
2118     }
2119 pippijn 1.1 }
2120    
2121 pippijn 1.8 logfile_t::create (ce->vardata<char *> (), logval);
2122 pippijn 1.1
2123     return 0;
2124     }
2125    
2126     bool
2127     conf_rehash (void)
2128     {
2129     me_t hold_me;
2130     char *oldsnoop;
2131     config_file_t *cfp;
2132    
2133     /* we're rehashing */
2134     slog (LG_INFO, "conf_rehash(): rehashing");
2135     runflags |= RF_REHASHING;
2136    
2137     errno = 0;
2138     cfp = config_load (config_file);
2139     if (cfp == NULL)
2140     {
2141     slog (LG_ERROR, "conf_rehash(): unable to load configuration file: %s, aborting rehash", strerror (errno));
2142     runflags &= ~RF_REHASHING;
2143     return false;
2144     }
2145    
2146     hold_me = me;
2147    
2148     oldsnoop = config_options.chan != NULL ? sstrdup (config_options.chan) : NULL;
2149    
2150     /* reset everything */
2151     conf_init ();
2152     mark_all_illegal ();
2153     log_shutdown ();
2154    
2155     /* now reload */
2156     log_open ();
2157     conf_process (cfp);
2158     config_free (cfp);
2159 pippijn 1.4 ConfTable::callback.ready ();
2160 pippijn 1.1
2161     /* now recheck */
2162     if (!conf_check ())
2163     {
2164     slog (LG_ERROR, "conf_rehash(): conf file was malformed, aborting rehash");
2165    
2166     /* freeing the new conf strings */
2167 pippijn 1.4 sfree (chansvs.nick);
2168     me.fini ();
2169 pippijn 1.1
2170     /* return everything to the way it was before */
2171     me = hold_me;
2172    
2173     /* not fully ok, oh well */
2174     unmark_all_illegal ();
2175    
2176 pippijn 1.4 sfree (oldsnoop);
2177 pippijn 1.1
2178     runflags &= ~RF_REHASHING;
2179     return false;
2180     }
2181    
2182     if (oldsnoop != NULL || config_options.chan != NULL)
2183     {
2184     if (config_options.chan == NULL)
2185 pippijn 1.4 partall (oldsnoop);
2186 pippijn 1.1 else if (oldsnoop == NULL)
2187 pippijn 1.4 joinall (config_options.chan);
2188 pippijn 1.1 else if (strcmp (oldsnoop, config_options.chan))
2189 pippijn 1.4 {
2190     partall (oldsnoop);
2191     joinall (config_options.chan);
2192     }
2193 pippijn 1.1 }
2194    
2195     remove_illegals ();
2196    
2197 pippijn 1.4 sfree (oldsnoop);
2198 pippijn 1.1
2199     runflags &= ~RF_REHASHING;
2200     return true;
2201     }
2202    
2203     bool
2204     conf_check (void)
2205     {
2206     if (!me.name)
2207     {
2208     slog (LG_ERROR, "conf_check(): no `name' set in %s", config_file);
2209     return false;
2210     }
2211    
2212     /* The following checks could perhaps be stricter */
2213     if (!strchr (me.name, '.') || strchr ("!\"#$%&+,-./:@", me.name[0]) || strchr (me.name, ' '))
2214     {
2215     slog (LG_ERROR, "conf_check(): bogus `name' in %s (did you specify a valid server name?)", config_file);
2216     return false;
2217     }
2218    
2219     if (isdigit (me.name[0]))
2220     slog (LG_ERROR, "conf_check(): `name' in %s starts with a digit, probably invalid (continuing anyway)", config_file);
2221    
2222     if (!me.desc)
2223     me.desc = sstrdup ("Ermyth IRC Services");
2224    
2225     if ((!me.recontime) || (me.recontime < 10))
2226     {
2227     slog (LG_INFO, "conf_check(): invalid `recontime' set in %s; " "defaulting to 10", config_file);
2228     me.recontime = 10;
2229     }
2230    
2231     if (!me.netname)
2232     {
2233     slog (LG_INFO, "conf_check(): no `netname' set in %s", config_file);
2234     return false;
2235     }
2236    
2237     if (!me.adminname)
2238     {
2239     slog (LG_INFO, "conf_check(): no `adminname' set in %s", config_file);
2240     return false;
2241     }
2242    
2243     if (!me.adminemail)
2244     {
2245     slog (LG_INFO, "conf_check(): no `adminemail' set in %s", config_file);
2246     return false;
2247     }
2248    
2249     if (!me.mta && me.auth == AUTH_EMAIL)
2250     {
2251     slog (LG_INFO, "conf_check(): no `mta' set in %s (but `auth' is email)", config_file);
2252     return false;
2253     }
2254    
2255     if (!me.maxlogins)
2256     {
2257     slog (LG_INFO, "conf_check(): no `maxlogins' set in %s; " "defaulting to 5", config_file);
2258     me.maxlogins = 5;
2259     }
2260    
2261     if (!me.maxusers)
2262     {
2263     slog (LG_INFO, "conf_check(): no `maxusers' set in %s; " "defaulting to 5", config_file);
2264     me.maxusers = 5;
2265     }
2266    
2267     if (!me.maxnicks)
2268     {
2269     if (!nicksvs.no_nick_ownership)
2270 pippijn 1.4 slog (LG_INFO, "conf_check(): no `maxnicks' set in %s; " "defaulting to 5", config_file);
2271 pippijn 1.1 me.maxnicks = 5;
2272     }
2273    
2274     if (!me.maxchans)
2275     {
2276     slog (LG_INFO, "conf_check(): no `maxchans' set in %s; " "defaulting to 5", config_file);
2277     me.maxchans = 5;
2278     }
2279    
2280     if (!me.emaillimit)
2281     {
2282     slog (LG_INFO, "conf_check(): no `emaillimit' set in %s; " "defaulting to 10", config_file);
2283     me.emaillimit = 10;
2284     }
2285    
2286     if (!me.emailtime)
2287     {
2288     slog (LG_INFO, "conf_check(): no `emailtime' set in %s; " "defaulting to 300", config_file);
2289     me.emailtime = 300;
2290     }
2291    
2292     if (me.auth != 0 && me.auth != 1)
2293     {
2294     slog (LG_INFO, "conf_check(): no `auth' set in %s; " "defaulting to NONE", config_file);
2295     me.auth = AUTH_NONE;
2296     }
2297    
2298     if (!chansvs.nick || !chansvs.user || !chansvs.host || !chansvs.real)
2299     {
2300     slog (LG_ERROR, "conf_check(): invalid chanserv{} block in %s", config_file);
2301     return false;
2302     }
2303    
2304     if ((strchr (chansvs.user, ' ')) || (strlen (chansvs.user) > 10))
2305     {
2306     slog (LG_ERROR, "conf_check(): invalid `chanserv::user' in %s", config_file);
2307     return false;
2308     }
2309    
2310     /* we know ca_all now */
2311     chansvs.ca_vop &= ca_all;
2312     chansvs.ca_hop &= ca_all;
2313     chansvs.ca_aop &= ca_all;
2314     chansvs.ca_sop &= ca_all;
2315     /* chansvs.ca_hop may be equal to chansvs.ca_vop to disable HOP */
2316     if (!chansvs.ca_vop || !chansvs.ca_hop || !chansvs.ca_aop || !chansvs.ca_sop || chansvs.ca_vop == chansvs.ca_aop || chansvs.ca_vop == chansvs.ca_sop || chansvs.ca_hop == chansvs.ca_aop || chansvs.ca_hop == chansvs.ca_sop || chansvs.ca_aop == chansvs.ca_sop)
2317     {
2318     slog (LG_INFO, "conf_check(): invalid xop levels in %s, using defaults", config_file);
2319     chansvs.ca_vop = CA_VOP_DEF & ca_all;
2320     chansvs.ca_hop = CA_HOP_DEF & ca_all;
2321     chansvs.ca_aop = CA_AOP_DEF & ca_all;
2322     chansvs.ca_sop = CA_SOP_DEF & ca_all;
2323     }
2324    
2325     if (config_options.flood_msgs && !config_options.flood_time)
2326     config_options.flood_time = 10;
2327 pippijn 1.4
2328     if (!config_options.default_clone_limit)
2329     config_options.default_clone_limit = 6;
2330    
2331 pippijn 1.1 /* recall that commit_interval is in seconds */
2332     if ((!config_options.commit_interval) || (config_options.commit_interval < 60) || (config_options.commit_interval > 3600))
2333     {
2334     slog (LG_INFO, "conf_check(): invalid `commit_interval' set in %s; " "defaulting to 5 minutes", config_file);
2335     config_options.commit_interval = 300;
2336     }
2337    
2338     return true;
2339     }