ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/src/conf.C
Revision: 1.8
Committed: Sun Sep 9 20:05:52 2007 UTC (16 years, 10 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

# Content
1 /*
2 * conf.C: Configuration processing.
3 * Rights to this code are documented in doc/pod/license.pod.
4 *
5 * Copyright © 2005-2007 Atheme Project (http://www.atheme.org)
6 */
7
8 static char const rcsid[] = "$Id: conf.C,v 1.7 2007-08-30 19:56:24 pippijn Exp $";
9
10 #include "atheme.h"
11 #include "confparse.h"
12 #include <ermyth/crypto.h>
13 #include <ermyth/database.h>
14 #include <ermyth/module.h>
15 #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 ConfTable::callbacks ConfTable::callback;
23
24 enum config_error
25 {
26 no_param,
27 wrong_param
28 };
29
30 template<config_error e>
31 int param_error (config_entry_t *ce, char const * const msg = NULL);
32
33 template<>
34 int param_error<no_param> (config_entry_t *ce, char const * const msg)
35 {
36 slog (LG_INFO, "%s:%i: %s: %s",
37 ce->ce_fileptr->cf_filename,
38 ce->ce_varlinenum, msg ? msg : "no parameter for option",
39 ce->ce_varname);
40 return 1;
41 }
42
43 template<>
44 int param_error<wrong_param> (config_entry_t *ce, char const * const msg)
45 {
46 slog (LG_INFO, "%s:%i: %s: %s",
47 ce->ce_fileptr->cf_filename,
48 ce->ce_varlinenum, msg ? msg : "wrong parameter for option",
49 ce->ce_varname);
50 return 1;
51 }
52
53 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
122 /* NickServ client information. */
123 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
131 /* SaslServ client information. */
132 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
137 /* MemoServ client information. */
138 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
143 /* GameServ client information. */
144 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
149 /* Database information. */
150 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
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 { "GUARD", MC_GUARD },
192 { "NONE", 0 },
193 { NULL, 0 }
194 };
195
196 static Token logflags[] = {
197 { "DEBUG", LG_ALL },
198 { "TRACE", LG_INFO | LG_ERROR | LG_CMD_ALL | LG_NETWORK | LG_WALLOPS | LG_REGISTER },
199 { "MISC", LG_INFO | LG_ERROR | LG_CMD_ADMIN | LG_CMD_REGISTER | LG_CMD_SET | LG_NETWORK | LG_WALLOPS | LG_REGISTER },
200 { "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 };
213
214 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
227 /* *INDENT-ON* */
228
229 static void
230 conf_report_error (config_entry_t *ce, char const * const fmt, ...)
231 {
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 {
256 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
266 if (ct == NULL)
267 conf_report_error (ce, "invalid configuration option: %s", ce->ce_varname);
268 }
269 }
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 if (!protocol::handler::loaded)
289 {
290 slog (LG_ERROR, "No protocol module loaded, aborting");
291 exit (EXIT_FAILURE);
292 }
293
294 ConfTable::callback.ready ();
295 return true;
296 }
297
298 void
299 conf_init (void)
300 {
301 me.init ();
302 if (chansvs.nick)
303 sfree (chansvs.nick);
304 if (config_options.chan)
305 sfree (config_options.chan);
306 if (config_options.global)
307 sfree (config_options.global);
308 if (config_options.languagefile)
309 sfree (config_options.languagefile);
310
311 chansvs.nick = config_options.chan = config_options.global = config_options.languagefile = NULL;
312
313 config_options.flood_msgs = config_options.flood_time = config_options.kline_time = config_options.commit_interval = 0;
314
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 sfree (chansvs.trigger);
335 chansvs.trigger = sstrdup ("!");
336 chansvs.maxchanacs = 0;
337 chansvs.maxfounders = 4;
338
339 if (!(runflags & RF_REHASHING))
340 {
341 if (me.name)
342 sfree (me.name);
343 if (me.desc)
344 sfree (me.desc);
345 if (me.vhost)
346 sfree (me.vhost);
347 if (chansvs.user)
348 sfree (chansvs.user);
349 if (chansvs.host)
350 sfree (chansvs.host);
351 if (chansvs.real)
352 sfree (chansvs.real);
353
354 me.name = me.desc = me.vhost = chansvs.user = chansvs.host = chansvs.real = NULL;
355
356 set_match_mapping (MATCH_RFC1459); /* default to RFC compliancy */
357 }
358 }
359
360 int
361 subblock_handler (config_entry_t *ce, ConfTable::list_type &entries)
362 {
363 ConfTable *ct = NULL;
364
365 for (ce = ce->ce_entries; ce; ce = ce->ce_next)
366 {
367 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 if (ct == NULL)
379 conf_report_error (ce, "invalid configuration option: %s", ce->ce_varname);
380 }
381 return 0;
382 }
383
384 ConfTable *
385 find_top_conf (char const * const name)
386 {
387 foreach (ConfTable *ct, confblocks)
388 if (!strcasecmp (ct->name, name))
389 return ct;
390
391 return NULL;
392 }
393
394 ConfTable *
395 find_conf_item (char const * const name, ConfTable::list_type &conflist)
396 {
397 foreach (ConfTable *ct, conflist)
398 if (!strcasecmp (ct->name, name))
399 return ct;
400
401 return NULL;
402 }
403
404 void
405 add_top_conf (char const * const name, int (*handler) (config_entry_t *ce))
406 {
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 ct = new ConfTable (name, 1, handler);
416
417 confblocks.insert (ct);
418 }
419
420 void
421 add_conf_item (char const * const name, ConfTable::list_type &conflist, int (*handler) (config_entry_t *ce))
422 {
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 ct = new ConfTable (name, 1, handler);
432
433 conflist.insert (ct);
434 }
435
436 void
437 del_top_conf (char const * const name)
438 {
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 confblocks.erase (ct);
448
449 delete ct;
450 }
451
452 void
453 del_conf_item (char const * const name, ConfTable::list_type &conflist)
454 {
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 conflist.erase (ct);
464
465 delete ct;
466 }
467
468 /* stolen from Sentinel */
469 #define TOKEN_UNMATCHED -1
470 #define TOKEN_ERROR -2
471
472 static int
473 token_to_value (Token token_table[], char *token)
474 {
475 int i;
476
477 if ((token_table != NULL) && (token != NULL))
478 {
479 for (i = 0; token_table[i].text != NULL; i++)
480 if (strcasecmp (token_table[i].text, token) == 0)
481 return token_table[i].value;
482 /* If no match... */
483 return TOKEN_UNMATCHED;
484 }
485
486 /* Otherwise... */
487 return TOKEN_ERROR;
488 }
489
490 void
491 init_newconf (void)
492 {
493 #if 0
494 conftable_heap = BlockHeapCreate (sizeof (ConfTable), 32);
495 #endif
496
497 /* First we set up the blocks. */
498 add_top_conf ("SERVERINFO", c_serverinfo);
499 add_top_conf ("CHANSERV", c_chanserv);
500 add_top_conf ("GLOBAL", c_globserv);
501 add_top_conf ("OPERSERV", c_operserv);
502 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 add_top_conf ("BACKEND", c_backend);
511 add_top_conf ("CRYPTO", c_crypto);
512 add_top_conf ("PROTOCOL", c_protocol);
513 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 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
653 /* general{} block. */
654 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
671 /* chanserv{} block */
672 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
687 /* global{} block */
688 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
693 /* operserv{} block */
694 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
699 /* nickserv{} block */
700 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
708 /* saslserv{} block */
709 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
714 /* memoserv{} block */
715 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
720 /* memoserv{} block */
721 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
726 /* database{} block */
727 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 }
753
754 static int
755 c_serverinfo (config_entry_t *ce)
756 {
757 return subblock_handler (ce, conf_si_table);
758 }
759
760 static int
761 c_chanserv (config_entry_t *ce)
762 {
763 return subblock_handler (ce, conf_ci_table);
764 }
765
766 static int
767 c_globserv (config_entry_t *ce)
768 {
769 return subblock_handler (ce, conf_gl_table);
770 }
771
772 static int
773 c_operserv (config_entry_t *ce)
774 {
775 return subblock_handler (ce, conf_oi_table);
776 }
777
778 static int
779 c_nickserv (config_entry_t *ce)
780 {
781 return subblock_handler (ce, conf_ni_table);
782 }
783
784 static int
785 c_saslserv (config_entry_t *ce)
786 {
787 return subblock_handler (ce, conf_ss_table);
788 }
789
790 static int
791 c_memoserv (config_entry_t *ce)
792 {
793 return subblock_handler (ce, conf_ms_table);
794 }
795
796 static int
797 c_gameserv (config_entry_t *ce)
798 {
799 return subblock_handler (ce, conf_gs_table);
800 }
801
802 static int
803 c_database (config_entry_t *ce)
804 {
805 return subblock_handler (ce, conf_db_table);
806 }
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 if (ce->vardata<char *> () == NULL)
817 return param_error<no_param> (ce);
818
819 name = ce->vardata<char *> ();
820
821 typedef factory::factory_mgr<protocol::handler> protocol_factory;
822 protocol_factory &f = protocol_factory::instance ();
823
824 if (!f.provides (name))
825 return param_error<wrong_param> (ce, "no such protocol handler");
826
827 phandler = f.create (name);
828
829 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 if (ce->vardata<char *> () == NULL)
841 return param_error<no_param> (ce);
842
843 name = ce->vardata<char *> ();
844
845 if (!modules::provides (name))
846 return param_error<wrong_param> (ce, "no such module");
847
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 if (ce->vardata<char *> () == NULL)
862 return param_error<no_param> (ce);
863
864 name = ce->vardata<char *> ();
865
866 typedef factory::factory_mgr<crypto::handler> crypto_factory;
867 crypto_factory &f = crypto_factory::instance ();
868
869 if (!f.provides (name))
870 return param_error<wrong_param> (ce, "no such crypto handler");
871
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 if (ce->vardata<char *> () == NULL)
886 return param_error<no_param> (ce);
887
888 name = ce->vardata<char *> ();
889
890 typedef factory::factory_mgr<database::handler> backend_factory;
891 backend_factory &f = backend_factory::instance ();
892
893 if (!f.provides (name))
894 return param_error<wrong_param> (ce, "no such database backend");
895
896 backend = f.create (name);
897
898 return 0;
899 }
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 if (ce->vardata<char *> () == NULL)
909 return param_error<no_param> (ce);
910
911 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
918 name = sstrdup (ce->vardata<char *> ());
919
920 for (ce = ce->ce_entries; ce; ce = ce->ce_next)
921 {
922 if (!strcasecmp ("HOST", ce->ce_varname))
923 {
924 if (ce->vardata<char *> () == NULL)
925 return param_error<no_param> (ce);
926
927 host = sstrdup (ce->vardata<char *> ());
928 }
929 else if (!strcasecmp ("VHOST", ce->ce_varname))
930 {
931 if (ce->vardata<char *> () == NULL)
932 return param_error<no_param> (ce);
933
934 vhost = sstrdup (ce->vardata<char *> ());
935 }
936 else if (!strcasecmp ("PASSWORD", ce->ce_varname))
937 {
938 if (ce->vardata<char *> () == NULL)
939 return param_error<no_param> (ce);
940
941 password = sstrdup (ce->vardata<char *> ());
942 }
943 else if (!strcasecmp ("PORT", ce->ce_varname))
944 {
945 if (ce->vardata<char *> () == NULL)
946 return param_error<no_param> (ce);
947
948 port = ce->vardata<int> ();
949 }
950 else
951 {
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 }
956
957 uplink_add (name, host, password, vhost, port);
958
959 sfree (name);
960 sfree (host);
961 sfree (password);
962 sfree (vhost);
963
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 if (ce->vardata<char *> () == NULL)
976 return param_error<no_param> (ce);
977
978 name = ce->vardata<char *> ();
979
980 for (ce = ce->ce_entries; ce; ce = ce->ce_next)
981 {
982 if (!strcasecmp ("PRIVS", ce->ce_varname))
983 {
984 if (ce->vardata<char *> () == NULL && ce->ce_entries == NULL)
985 return param_error<no_param> (ce);
986
987 if (ce->ce_entries == NULL)
988 {
989 if (privs == NULL)
990 privs = sstrdup (ce->vardata<char *> ());
991 else
992 {
993 newprivs = salloc<char> (strlen (privs) + 1 + strlen (ce->vardata<char *> ()) + 1);
994 strcpy (newprivs, privs);
995 strcat (newprivs, " ");
996 strcat (newprivs, ce->vardata<char *> ());
997 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 newprivs = salloc<char> (strlen (privs) + 1 + strlen (conf_p->ce_varname) + 1);
1022 strcpy (newprivs, privs);
1023 strcat (newprivs, " ");
1024 strcat (newprivs, conf_p->ce_varname);
1025 sfree (privs);
1026 privs = newprivs;
1027 }
1028 }
1029 }
1030 }
1031 else if (!strcasecmp ("NEEDOPER", ce->ce_varname))
1032 flags |= OPERCLASS_NEEDOPER;
1033 else
1034 {
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 }
1039
1040 operclass = operclass_add (name, privs ? privs : "");
1041 if (operclass != NULL)
1042 operclass->flags |= flags;
1043 sfree (privs);
1044 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 if (ce->vardata<char *> () == NULL)
1055 return param_error<no_param> (ce);
1056
1057 topce = ce;
1058 name = ce->vardata<char *> ();
1059
1060 for (ce = ce->ce_entries; ce; ce = ce->ce_next)
1061 {
1062 if (!strcasecmp ("OPERCLASS", ce->ce_varname))
1063 {
1064 if (ce->vardata<char *> () == NULL)
1065 return param_error<no_param> (ce);
1066
1067 operclass = operclass_find (ce->vardata<char *> ());
1068 if (operclass == NULL)
1069 slog (LG_ERROR, "%s:%d: invalid operclass %s for operator %s", ce->ce_fileptr->cf_filename, ce->ce_varlinenum, ce->vardata<char *> (), name);
1070 }
1071 else
1072 {
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 }
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 return subblock_handler (ce, conf_gi_table);
1089 }
1090
1091 static int
1092 c_si_name (config_entry_t *ce)
1093 {
1094 if (ce->vardata<char *> () == NULL)
1095 return param_error<no_param> (ce);
1096
1097 if (!(runflags & RF_REHASHING))
1098 me.name = sstrdup (ce->vardata<char *> ());
1099
1100 return 0;
1101 }
1102
1103 static int
1104 c_si_desc (config_entry_t *ce)
1105 {
1106 if (ce->vardata<char *> () == NULL)
1107 return param_error<no_param> (ce);
1108
1109 if (me.desc != NULL)
1110 sfree (me.desc);
1111 me.desc = sstrdup (ce->vardata<char *> ());
1112
1113 return 0;
1114 }
1115
1116 static int
1117 c_si_numeric (config_entry_t *ce)
1118 {
1119 if (ce->vardata<char *> () == NULL)
1120 return param_error<no_param> (ce);
1121
1122 if (!(runflags & RF_REHASHING))
1123 me.numeric = sstrdup (ce->vardata<char *> ());
1124
1125 return 0;
1126 }
1127
1128 static int
1129 c_si_mdlimit (config_entry_t *ce)
1130 {
1131 if (ce->vardata<char *> () == NULL)
1132 return param_error<no_param> (ce);
1133
1134 me.mdlimit = ce->vardata<int> ();
1135
1136 return 0;
1137 }
1138
1139 static int
1140 c_si_vhost (config_entry_t *ce)
1141 {
1142 if (ce->vardata<char *> () == NULL)
1143 return param_error<no_param> (ce);
1144
1145 me.vhost = sstrdup (ce->vardata<char *> ());
1146
1147 return 0;
1148 }
1149
1150 static int
1151 c_si_recontime (config_entry_t *ce)
1152 {
1153 if (ce->vardata<char *> () == NULL)
1154 return param_error<no_param> (ce);
1155
1156 me.recontime = ce->vardata<int> ();
1157
1158 return 0;
1159 }
1160
1161 static int
1162 c_si_restarttime (config_entry_t *ce)
1163 {
1164 if (ce->vardata<char *> () == NULL)
1165 return param_error<no_param> (ce);
1166
1167 me.restarttime = ce->vardata<int> ();
1168
1169 return 0;
1170 }
1171
1172 static int
1173 c_si_netname (config_entry_t *ce)
1174 {
1175 if (ce->vardata<char *> () == NULL)
1176 return param_error<no_param> (ce);
1177
1178 me.netname = sstrdup (ce->vardata<char *> ());
1179
1180 return 0;
1181 }
1182
1183 static int
1184 c_si_hidehostsuffix (config_entry_t *ce)
1185 {
1186 if (ce->vardata<char *> () == NULL)
1187 return param_error<no_param> (ce);
1188
1189 me.hidehostsuffix = sstrdup (ce->vardata<char *> ());
1190
1191 return 0;
1192 }
1193
1194 static int
1195 c_si_adminname (config_entry_t *ce)
1196 {
1197 if (ce->vardata<char *> () == NULL)
1198 return param_error<no_param> (ce);
1199
1200 me.adminname = sstrdup (ce->vardata<char *> ());
1201
1202 return 0;
1203 }
1204
1205 static int
1206 c_si_adminemail (config_entry_t *ce)
1207 {
1208 if (ce->vardata<char *> () == NULL)
1209 return param_error<no_param> (ce);
1210
1211 me.adminemail = sstrdup (ce->vardata<char *> ());
1212
1213 return 0;
1214 }
1215
1216 static int
1217 c_si_mta (config_entry_t *ce)
1218 {
1219 if (ce->vardata<char *> () == NULL)
1220 return param_error<no_param> (ce);
1221
1222 me.mta = sstrdup (ce->vardata<char *> ());
1223
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 if (ce->vardata<char *> () != NULL)
1235 {
1236 val = token_to_value (logflags, ce->vardata<char *> ());
1237
1238 if ((val != TOKEN_UNMATCHED) && (val != TOKEN_ERROR))
1239 mask |= val;
1240 else
1241 slog (LG_INFO, "%s:%d: unknown flag: %s", ce->ce_fileptr->cf_filename, ce->ce_varlinenum, ce->vardata<char *> ());
1242 }
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 mask |= val;
1249 else
1250 slog (LG_INFO, "%s:%d: unknown flag: %s", flce->ce_fileptr->cf_filename, flce->ce_varlinenum, flce->ce_varname);
1251 }
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 if (ce->vardata<char *> () == NULL)
1261 return param_error<no_param> (ce);
1262
1263 me.maxlogins = ce->vardata<int> ();
1264
1265 return 0;
1266
1267 }
1268
1269 static int
1270 c_si_maxusers (config_entry_t *ce)
1271 {
1272 if (ce->vardata<char *> () == NULL)
1273 return param_error<no_param> (ce);
1274
1275 me.maxusers = ce->vardata<int> ();
1276
1277 return 0;
1278
1279 }
1280
1281 static int
1282 c_si_maxnicks (config_entry_t *ce)
1283 {
1284 if (ce->vardata<char *> () == NULL)
1285 return param_error<no_param> (ce);
1286
1287 me.maxnicks = ce->vardata<int> ();
1288
1289 return 0;
1290 }
1291
1292 static int
1293 c_si_maxchans (config_entry_t *ce)
1294 {
1295 if (ce->vardata<char *> () == NULL)
1296 return param_error<no_param> (ce);
1297
1298 me.maxchans = ce->vardata<int> ();
1299
1300 return 0;
1301 }
1302
1303 static int
1304 c_si_emaillimit (config_entry_t *ce)
1305 {
1306 if (ce->vardata<char *> () == NULL)
1307 return param_error<no_param> (ce);
1308
1309 me.emaillimit = ce->vardata<int> ();
1310
1311 return 0;
1312 }
1313
1314 static int
1315 c_si_emailtime (config_entry_t *ce)
1316 {
1317 if (ce->vardata<char *> () == NULL)
1318 return param_error<no_param> (ce);
1319
1320 me.emailtime = ce->vardata<int> ();
1321
1322 return 0;
1323 }
1324
1325 static int
1326 c_si_auth (config_entry_t *ce)
1327 {
1328 if (ce->vardata<char *> () == NULL)
1329 return param_error<no_param> (ce);
1330
1331 if (!strcasecmp ("EMAIL", ce->vardata<char *> ()))
1332 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 if (ce->vardata<char *> () == NULL)
1344 return param_error<no_param> (ce);
1345
1346 if (!strcasecmp ("ASCII", ce->vardata<char *> ()))
1347 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 if (ce->vardata<char *> () == NULL)
1359 return param_error<no_param> (ce);
1360
1361 if (chansvs.nick != NULL)
1362 sfree (chansvs.nick);
1363 chansvs.nick = sstrdup (ce->vardata<char *> ());
1364
1365 return 0;
1366 }
1367
1368 static int
1369 c_ci_user (config_entry_t *ce)
1370 {
1371 if (ce->vardata<char *> () == NULL)
1372 return param_error<no_param> (ce);
1373
1374 if (chansvs.user != NULL)
1375 sfree (chansvs.user);
1376 chansvs.user = sstrdup (ce->vardata<char *> ());
1377
1378 return 0;
1379 }
1380
1381 static int
1382 c_ci_host (config_entry_t *ce)
1383 {
1384 if (ce->vardata<char *> () == NULL)
1385 return param_error<no_param> (ce);
1386
1387 if (chansvs.host != NULL)
1388 sfree (chansvs.host);
1389 chansvs.host = sstrdup (ce->vardata<char *> ());
1390
1391 return 0;
1392 }
1393
1394 static int
1395 c_ci_real (config_entry_t *ce)
1396 {
1397 if (ce->vardata<char *> () == NULL)
1398 return param_error<no_param> (ce);
1399
1400 if (chansvs.real != NULL)
1401 sfree (chansvs.real);
1402 chansvs.real = sstrdup (ce->vardata<char *> ());
1403
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 if (ce->vardata<char *> () == NULL)
1422 return param_error<no_param> (ce);
1423
1424 chansvs.ca_vop = flags_to_bitmask (ce->vardata<char *> (), chanacs_flags, 0);
1425
1426 return 0;
1427 }
1428
1429 static int
1430 c_ci_hop (config_entry_t *ce)
1431 {
1432 if (ce->vardata<char *> () == NULL)
1433 return param_error<no_param> (ce);
1434
1435 chansvs.ca_hop = flags_to_bitmask (ce->vardata<char *> (), chanacs_flags, 0);
1436
1437 return 0;
1438 }
1439
1440 static int
1441 c_ci_aop (config_entry_t *ce)
1442 {
1443 if (ce->vardata<char *> () == NULL)
1444 return param_error<no_param> (ce);
1445
1446 chansvs.ca_aop = flags_to_bitmask (ce->vardata<char *> (), chanacs_flags, 0);
1447
1448 return 0;
1449 }
1450
1451 static int
1452 c_ci_sop (config_entry_t *ce)
1453 {
1454 if (ce->vardata<char *> () == NULL)
1455 return param_error<no_param> (ce);
1456
1457 chansvs.ca_sop = flags_to_bitmask (ce->vardata<char *> (), chanacs_flags, 0);
1458
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 if (ce->vardata<char *> () == NULL)
1473 return param_error<no_param> (ce);
1474
1475 if (chansvs.trigger != NULL)
1476 sfree (chansvs.trigger);
1477 chansvs.trigger = sstrdup (ce->vardata<char *> ());
1478
1479 return 0;
1480 }
1481
1482 static int
1483 c_ci_expire (config_entry_t *ce)
1484 {
1485 if (ce->vardata<char *> () == NULL)
1486 return param_error<no_param> (ce);
1487
1488 chansvs.expiry = (ce->vardata<int> () * 60 * 60 * 24);
1489
1490 return 0;
1491 }
1492
1493 static int
1494 c_ci_maxchanacs (config_entry_t *ce)
1495 {
1496 if (ce->vardata<char *> () == NULL)
1497 return param_error<no_param> (ce);
1498
1499 chansvs.maxchanacs = ce->vardata<int> ();
1500
1501 return 0;
1502 }
1503
1504 static int
1505 c_ci_maxfounders (config_entry_t *ce)
1506 {
1507 if (ce->vardata<char *> () == NULL)
1508 return param_error<no_param> (ce);
1509
1510 chansvs.maxfounders = ce->vardata<int> ();
1511
1512 return 0;
1513 }
1514
1515 static int
1516 c_gi_chan (config_entry_t *ce)
1517 {
1518 if (ce->vardata<char *> () == NULL)
1519 return param_error<no_param> (ce);
1520
1521 config_options.chan = sstrdup (ce->vardata<char *> ());
1522
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 config_options.defuflags |= val;
1581
1582 else
1583 {
1584 slog (LG_INFO, "%s:%d: unknown flag: %s", flce->ce_fileptr->cf_filename, flce->ce_varlinenum, flce->ce_varname);
1585 }
1586 }
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 config_options.defcflags |= val;
1604
1605 else
1606 {
1607 slog (LG_INFO, "%s:%d: unknown flag: %s", flce->ce_fileptr->cf_filename, flce->ce_varlinenum, flce->ce_varname);
1608 }
1609 }
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 if (ce->vardata<char *> () == NULL)
1628 return param_error<no_param> (ce);
1629
1630 config_options.flood_msgs = ce->vardata<int> ();
1631
1632 return 0;
1633 }
1634
1635 static int
1636 c_gi_flood_time (config_entry_t *ce)
1637 {
1638 if (ce->vardata<char *> () == NULL)
1639 return param_error<no_param> (ce);
1640
1641 config_options.flood_time = ce->vardata<int> ();
1642
1643 return 0;
1644 }
1645
1646 static int
1647 c_gi_kline_time (config_entry_t *ce)
1648 {
1649 if (ce->vardata<char *> () == NULL)
1650 return param_error<no_param> (ce);
1651
1652 config_options.kline_time = (ce->vardata<int> () * 60 * 60 * 24);
1653
1654 return 0;
1655 }
1656
1657 static int
1658 c_gi_commit_interval (config_entry_t *ce)
1659 {
1660 if (ce->vardata<char *> () == NULL)
1661 return param_error<no_param> (ce);
1662
1663 config_options.commit_interval = (ce->vardata<int> () * 60);
1664
1665 return 0;
1666 }
1667
1668 static int
1669 c_gi_expire (config_entry_t *ce)
1670 {
1671 if (ce->vardata<char *> () == NULL)
1672 return param_error<no_param> (ce);
1673
1674 slog (LG_INFO, "warning: general::expire has been deprecated. please use nickserv::expire and chanserv::expire respectively.");
1675
1676 nicksvs.expiry = (ce->vardata<int> () * 60 * 60 * 24);
1677 chansvs.expiry = (ce->vardata<int> () * 60 * 60 * 24);
1678
1679 return 0;
1680 }
1681
1682 static int
1683 c_gi_default_clone_limit (config_entry_t *ce)
1684 {
1685 if (ce->vardata<char *> () == NULL)
1686 return param_error<no_param> (ce);
1687
1688 config_options.default_clone_limit = ce->vardata<int> ();
1689
1690 return 0;
1691 }
1692
1693 static int
1694 c_oi_nick (config_entry_t *ce)
1695 {
1696 if (ce->vardata<char *> () == NULL)
1697 return param_error<no_param> (ce);
1698
1699 if (opersvs.nick != NULL)
1700 sfree (opersvs.nick);
1701 opersvs.nick = sstrdup (ce->vardata<char *> ());
1702
1703 return 0;
1704 }
1705
1706 static int
1707 c_oi_user (config_entry_t *ce)
1708 {
1709 if (ce->vardata<char *> () == NULL)
1710 return param_error<no_param> (ce);
1711
1712 if (opersvs.user != NULL)
1713 sfree (opersvs.user);
1714 opersvs.user = sstrdup (ce->vardata<char *> ());
1715
1716 return 0;
1717 }
1718
1719 static int
1720 c_oi_host (config_entry_t *ce)
1721 {
1722 if (ce->vardata<char *> () == NULL)
1723 return param_error<no_param> (ce);
1724
1725 if (opersvs.host != NULL)
1726 sfree (opersvs.host);
1727 opersvs.host = sstrdup (ce->vardata<char *> ());
1728
1729 return 0;
1730 }
1731
1732 static int
1733 c_oi_real (config_entry_t *ce)
1734 {
1735 if (ce->vardata<char *> () == NULL)
1736 return param_error<no_param> (ce);
1737
1738 if (opersvs.real != NULL)
1739 sfree (opersvs.real);
1740 opersvs.real = sstrdup (ce->vardata<char *> ());
1741
1742 return 0;
1743 }
1744
1745 static int
1746 c_ni_nick (config_entry_t *ce)
1747 {
1748 if (ce->vardata<char *> () == NULL)
1749 return param_error<no_param> (ce);
1750
1751 if (nicksvs.nick != NULL)
1752 sfree (nicksvs.nick);
1753 nicksvs.nick = sstrdup (ce->vardata<char *> ());
1754
1755 return 0;
1756 }
1757
1758 static int
1759 c_ni_user (config_entry_t *ce)
1760 {
1761 if (ce->vardata<char *> () == NULL)
1762 return param_error<no_param> (ce);
1763
1764 if (nicksvs.user != NULL)
1765 sfree (nicksvs.user);
1766 nicksvs.user = sstrdup (ce->vardata<char *> ());
1767
1768 return 0;
1769 }
1770
1771 static int
1772 c_ni_host (config_entry_t *ce)
1773 {
1774 if (ce->vardata<char *> () == NULL)
1775 return param_error<no_param> (ce);
1776
1777 if (nicksvs.host != NULL)
1778 sfree (nicksvs.host);
1779 nicksvs.host = sstrdup (ce->vardata<char *> ());
1780
1781 return 0;
1782 }
1783
1784 static int
1785 c_ni_real (config_entry_t *ce)
1786 {
1787 if (ce->vardata<char *> () == NULL)
1788 return param_error<no_param> (ce);
1789
1790 if (nicksvs.real != NULL)
1791 sfree (nicksvs.real);
1792 nicksvs.real = sstrdup (ce->vardata<char *> ());
1793
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 if (ce->vardata<char *> () == NULL)
1815 return param_error<no_param> (ce);
1816
1817 nicksvs.expiry = (ce->vardata<int> () * 60 * 60 * 24);
1818
1819 return 0;
1820 }
1821
1822 static int
1823 c_ss_nick (config_entry_t *ce)
1824 {
1825 if (ce->vardata<char *> () == NULL)
1826 return param_error<no_param> (ce);
1827
1828 if (saslsvs.nick != NULL)
1829 sfree (saslsvs.nick);
1830 saslsvs.nick = sstrdup (ce->vardata<char *> ());
1831
1832 return 0;
1833 }
1834
1835 static int
1836 c_ss_user (config_entry_t *ce)
1837 {
1838 if (ce->vardata<char *> () == NULL)
1839 return param_error<no_param> (ce);
1840
1841 if (saslsvs.user != NULL)
1842 sfree (saslsvs.user);
1843 saslsvs.user = sstrdup (ce->vardata<char *> ());
1844
1845 return 0;
1846 }
1847
1848 static int
1849 c_ss_host (config_entry_t *ce)
1850 {
1851 if (ce->vardata<char *> () == NULL)
1852 return param_error<no_param> (ce);
1853
1854 if (saslsvs.host != NULL)
1855 sfree (saslsvs.host);
1856 saslsvs.host = sstrdup (ce->vardata<char *> ());
1857
1858 return 0;
1859 }
1860
1861 static int
1862 c_ss_real (config_entry_t *ce)
1863 {
1864 if (ce->vardata<char *> () == NULL)
1865 return param_error<no_param> (ce);
1866
1867 if (saslsvs.real != NULL)
1868 sfree (saslsvs.real);
1869 saslsvs.real = sstrdup (ce->vardata<char *> ());
1870
1871 return 0;
1872 }
1873
1874 static int
1875 c_ms_nick (config_entry_t *ce)
1876 {
1877 if (ce->vardata<char *> () == NULL)
1878 return param_error<no_param> (ce);
1879
1880 if (memosvs.nick != NULL)
1881 sfree (memosvs.nick);
1882 memosvs.nick = sstrdup (ce->vardata<char *> ());
1883
1884 return 0;
1885 }
1886
1887 static int
1888 c_ms_user (config_entry_t *ce)
1889 {
1890 if (ce->vardata<char *> () == NULL)
1891 return param_error<no_param> (ce);
1892
1893 if (memosvs.user != NULL)
1894 sfree (memosvs.user);
1895 memosvs.user = sstrdup (ce->vardata<char *> ());
1896
1897 return 0;
1898 }
1899
1900 static int
1901 c_ms_host (config_entry_t *ce)
1902 {
1903 if (ce->vardata<char *> () == NULL)
1904 return param_error<no_param> (ce);
1905
1906 if (memosvs.host != NULL)
1907 sfree (memosvs.host);
1908 memosvs.host = sstrdup (ce->vardata<char *> ());
1909
1910 return 0;
1911 }
1912
1913 static int
1914 c_ms_real (config_entry_t *ce)
1915 {
1916 if (ce->vardata<char *> () == NULL)
1917 return param_error<no_param> (ce);
1918
1919 if (memosvs.real != NULL)
1920 sfree (memosvs.real);
1921 memosvs.real = sstrdup (ce->vardata<char *> ());
1922
1923 return 0;
1924 }
1925
1926 static int
1927 c_gs_nick (config_entry_t *ce)
1928 {
1929 if (ce->vardata<char *> () == NULL)
1930 return param_error<no_param> (ce);
1931
1932 if (gamesvs.nick != NULL)
1933 sfree (gamesvs.nick);
1934 gamesvs.nick = sstrdup (ce->vardata<char *> ());
1935
1936 return 0;
1937 }
1938
1939 static int
1940 c_gs_user (config_entry_t *ce)
1941 {
1942 if (ce->vardata<char *> () == NULL)
1943 return param_error<no_param> (ce);
1944
1945 if (gamesvs.user != NULL)
1946 sfree (gamesvs.user);
1947 gamesvs.user = sstrdup (ce->vardata<char *> ());
1948
1949 return 0;
1950 }
1951
1952 static int
1953 c_gs_host (config_entry_t *ce)
1954 {
1955 if (ce->vardata<char *> () == NULL)
1956 return param_error<no_param> (ce);
1957
1958 if (gamesvs.host != NULL)
1959 sfree (gamesvs.host);
1960 gamesvs.host = sstrdup (ce->vardata<char *> ());
1961
1962 return 0;
1963 }
1964
1965 static int
1966 c_gs_real (config_entry_t *ce)
1967 {
1968 if (ce->vardata<char *> () == NULL)
1969 return param_error<no_param> (ce);
1970
1971 if (gamesvs.real != NULL)
1972 sfree (gamesvs.real);
1973 gamesvs.real = sstrdup (ce->vardata<char *> ());
1974
1975 return 0;
1976 }
1977
1978 static int
1979 c_gl_nick (config_entry_t *ce)
1980 {
1981 if (ce->vardata<char *> () == NULL)
1982 return param_error<no_param> (ce);
1983
1984 if (globsvs.nick != NULL)
1985 sfree (globsvs.nick);
1986 globsvs.nick = sstrdup (ce->vardata<char *> ());
1987
1988 return 0;
1989 }
1990
1991 static int
1992 c_gl_user (config_entry_t *ce)
1993 {
1994 if (ce->vardata<char *> () == NULL)
1995 return param_error<no_param> (ce);
1996
1997 if (globsvs.user != NULL)
1998 sfree (globsvs.user);
1999 globsvs.user = sstrdup (ce->vardata<char *> ());
2000
2001 return 0;
2002 }
2003
2004 static int
2005 c_gl_host (config_entry_t *ce)
2006 {
2007 if (ce->vardata<char *> () == NULL)
2008 return param_error<no_param> (ce);
2009
2010 if (globsvs.host != NULL)
2011 sfree (globsvs.host);
2012 globsvs.host = sstrdup (ce->vardata<char *> ());
2013
2014 return 0;
2015 }
2016
2017 static int
2018 c_gl_real (config_entry_t *ce)
2019 {
2020 if (ce->vardata<char *> () == NULL)
2021 return param_error<no_param> (ce);
2022
2023 if (globsvs.real != NULL)
2024 sfree (globsvs.real);
2025 globsvs.real = sstrdup (ce->vardata<char *> ());
2026
2027 return 0;
2028 }
2029
2030 static int
2031 c_db_user (config_entry_t *ce)
2032 {
2033 if (ce->vardata<char *> () == NULL)
2034 return param_error<no_param> (ce);
2035
2036 if (database_options.user != NULL)
2037 sfree (database_options.user);
2038 database_options.user = sstrdup (ce->vardata<char *> ());
2039
2040 return 0;
2041 }
2042
2043 static int
2044 c_db_host (config_entry_t *ce)
2045 {
2046 if (ce->vardata<char *> () == NULL)
2047 return param_error<no_param> (ce);
2048
2049 if (database_options.host != NULL)
2050 sfree (database_options.host);
2051 database_options.host = sstrdup (ce->vardata<char *> ());
2052
2053 return 0;
2054 }
2055
2056 static int
2057 c_db_password (config_entry_t *ce)
2058 {
2059 if (ce->vardata<char *> () == NULL)
2060 return param_error<no_param> (ce);
2061
2062 if (database_options.pass != NULL)
2063 sfree (database_options.pass);
2064 database_options.pass = sstrdup (ce->vardata<char *> ());
2065
2066 return 0;
2067 }
2068
2069 static int
2070 c_db_database (config_entry_t *ce)
2071 {
2072 if (ce->vardata<char *> () == NULL)
2073 return param_error<no_param> (ce);
2074
2075 if (database_options.database != NULL)
2076 sfree (database_options.database);
2077 database_options.database = sstrdup (ce->vardata<char *> ());
2078
2079 return 0;
2080 }
2081
2082 static int
2083 c_db_port (config_entry_t *ce)
2084 {
2085 if (ce->vardata<int> () == 0)
2086 return param_error<no_param> (ce);
2087
2088 database_options.port = ce->vardata<int> ();
2089
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 if (ce->vardata<char *> () == NULL)
2100 return param_error<no_param> (ce);
2101
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 logval |= val;
2110 else
2111 {
2112 slog (LG_INFO, "%s:%d: unknown flag: %s", flce->ce_fileptr->cf_filename, flce->ce_varlinenum, flce->ce_varname);
2113 }
2114 }
2115
2116 logfile_t::create (ce->vardata<char *> (), logval);
2117
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 ConfTable::callback.ready ();
2155
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 sfree (chansvs.nick);
2163 me.fini ();
2164
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 sfree (oldsnoop);
2172
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 partall (oldsnoop);
2181 else if (oldsnoop == NULL)
2182 joinall (config_options.chan);
2183 else if (strcmp (oldsnoop, config_options.chan))
2184 {
2185 partall (oldsnoop);
2186 joinall (config_options.chan);
2187 }
2188 }
2189
2190 remove_illegals ();
2191
2192 sfree (oldsnoop);
2193
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 slog (LG_INFO, "conf_check(): no `maxnicks' set in %s; " "defaulting to 5", config_file);
2266 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
2323 if (!config_options.default_clone_limit)
2324 config_options.default_clone_limit = 6;
2325
2326 /* 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 }