ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/src/conf.C
Revision: 1.8
Committed: Sun Sep 9 20:05:52 2007 UTC (16 years, 8 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.7: +365 -256 lines
Log Message:
- changed configurations to the c++ stdlib
- more #defines to enum
- removed getopt.h and link.h from the system as they were unused
- reworked logstreams
- added an itoa with old syntax
- made klines objects
- moved some global variables into appropriate classes
- fixed boost.foreach's compiler workaround #if's
- allow other files to add exceptions with ADD_EXCEPTION
- changed mynick_t to c++ object
- moved servers.h out of atheme.h
- corrected PING from inspircd 1.2

File Contents

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