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

File Contents

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