]> jfr.im git - solanum.git/blame - src/newconf.c
Support IPv6 blacklists. Also add a conf file option allowing the use of IPv4, IPv6...
[solanum.git] / src / newconf.c
CommitLineData
212380e3 1/* This code is in the public domain.
cda8e9b8 2 * $Id: newconf.c 3550 2007-08-09 06:47:26Z nenolod $
212380e3
AC
3 */
4
5#include "stdinc.h"
6
7#ifdef HAVE_LIBCRYPTO
8#include <openssl/pem.h>
9#include <openssl/rsa.h>
10#endif
11
212380e3 12#include "newconf.h"
212380e3 13#include "ircd_defs.h"
212380e3 14#include "common.h"
4016731b 15#include "logger.h"
212380e3
AC
16#include "s_conf.h"
17#include "s_user.h"
18#include "s_newconf.h"
19#include "send.h"
20#include "setup.h"
21#include "modules.h"
22#include "listener.h"
23#include "hostmask.h"
24#include "s_serv.h"
212380e3
AC
25#include "hash.h"
26#include "cache.h"
27#include "ircd.h"
28#include "snomask.h"
29#include "blacklist.h"
c6d72037 30#include "sslproc.h"
f8606875 31#include "privilege.h"
212380e3
AC
32
33#define CF_TYPE(x) ((x) & CF_MTYPE)
34
35struct TopConf *conf_cur_block;
36static char *conf_cur_block_name;
37
330fc5c1 38static rb_dlink_list conf_items;
212380e3
AC
39
40static struct ConfItem *yy_aconf = NULL;
41
42static struct Class *yy_class = NULL;
43
44static struct remote_conf *yy_shared = NULL;
45static struct server_conf *yy_server = NULL;
46
330fc5c1
AC
47static rb_dlink_list yy_aconf_list;
48static rb_dlink_list yy_oper_list;
49static rb_dlink_list yy_shared_list;
50static rb_dlink_list yy_cluster_list;
212380e3
AC
51static struct oper_conf *yy_oper = NULL;
52
53static struct alias_entry *yy_alias = NULL;
54
55static char *yy_blacklist_host = NULL;
56static char *yy_blacklist_reason = NULL;
0a1e77c2
EM
57static int yy_blacklist_ipv4 = 1;
58static int yy_blacklist_ipv6 = 0;
59
f8606875 60static char *yy_privset_extends = NULL;
212380e3
AC
61
62static const char *
63conf_strtype(int type)
64{
65 switch (type & CF_MTYPE)
66 {
67 case CF_INT:
68 return "integer value";
69 case CF_STRING:
70 return "unquoted string";
71 case CF_YESNO:
72 return "yes/no value";
73 case CF_QSTRING:
74 return "quoted string";
75 case CF_TIME:
76 return "time/size value";
77 default:
78 return "unknown type";
79 }
80}
81
82int
83add_top_conf(const char *name, int (*sfunc) (struct TopConf *),
84 int (*efunc) (struct TopConf *), struct ConfEntry *items)
85{
86 struct TopConf *tc;
87
eddc2ab6 88 tc = rb_malloc(sizeof(struct TopConf));
212380e3 89
d7f753cd 90 tc->tc_name = name;
212380e3
AC
91 tc->tc_sfunc = sfunc;
92 tc->tc_efunc = efunc;
93 tc->tc_entries = items;
94
330fc5c1 95 rb_dlinkAddAlloc(tc, &conf_items);
212380e3
AC
96 return 0;
97}
98
99struct TopConf *
100find_top_conf(const char *name)
101{
330fc5c1 102 rb_dlink_node *d;
212380e3
AC
103 struct TopConf *tc;
104
5cefa1d6 105 RB_DLINK_FOREACH(d, conf_items.head)
212380e3
AC
106 {
107 tc = d->data;
108 if(strcasecmp(tc->tc_name, name) == 0)
109 return tc;
110 }
111
112 return NULL;
113}
114
115
116struct ConfEntry *
117find_conf_item(const struct TopConf *top, const char *name)
118{
119 struct ConfEntry *cf;
330fc5c1 120 rb_dlink_node *d;
212380e3
AC
121
122 if(top->tc_entries)
123 {
124 int i;
125
126 for(i = 0; top->tc_entries[i].cf_type; i++)
127 {
128 cf = &top->tc_entries[i];
129
130 if(!strcasecmp(cf->cf_name, name))
131 return cf;
132 }
133 }
134
5cefa1d6 135 RB_DLINK_FOREACH(d, top->tc_items.head)
212380e3
AC
136 {
137 cf = d->data;
138 if(strcasecmp(cf->cf_name, name) == 0)
139 return cf;
140 }
141
142 return NULL;
143}
144
145int
146remove_top_conf(char *name)
147{
148 struct TopConf *tc;
330fc5c1 149 rb_dlink_node *ptr;
212380e3
AC
150
151 if((tc = find_top_conf(name)) == NULL)
152 return -1;
153
330fc5c1 154 if((ptr = rb_dlinkFind(tc, &conf_items)) == NULL)
212380e3
AC
155 return -1;
156
330fc5c1 157 rb_dlinkDestroy(ptr, &conf_items);
637c4932 158 rb_free(tc);
212380e3
AC
159
160 return 0;
161}
162
163static void
164conf_set_serverinfo_name(void *data)
165{
166 if(ServerInfo.name == NULL)
167 {
168 const char *s;
169 int dots = 0;
170
171 for(s = data; *s != '\0'; s++)
172 {
173 if(!IsServChar(*s))
174 {
175 conf_report_error("Ignoring serverinfo::name "
176 "-- bogus servername.");
177 return;
178 }
179 else if(*s == '.')
180 ++dots;
181 }
182
183 if(!dots)
184 {
185 conf_report_error("Ignoring serverinfo::name -- must contain '.'");
186 return;
187 }
188
189 s = data;
190
191 if(IsDigit(*s))
192 {
193 conf_report_error("Ignoring serverinfo::name -- cannot begin with digit.");
194 return;
195 }
196
197 /* the ircd will exit() in main() if we dont set one */
198 if(strlen(s) <= HOSTLEN)
47a03750 199 ServerInfo.name = rb_strdup((char *) data);
212380e3
AC
200 }
201}
202
203static void
204conf_set_serverinfo_sid(void *data)
205{
206 char *sid = data;
207
208 if(ServerInfo.sid[0] == '\0')
209 {
210 if(!IsDigit(sid[0]) || !IsIdChar(sid[1]) ||
211 !IsIdChar(sid[2]) || sid[3] != '\0')
212 {
213 conf_report_error("Ignoring serverinfo::sid "
214 "-- bogus sid.");
215 return;
216 }
217
218 strcpy(ServerInfo.sid, sid);
219 }
220}
221
222static void
223conf_set_serverinfo_network_name(void *data)
224{
225 char *p;
226
227 if((p = strchr((char *) data, ' ')))
228 *p = '\0';
229
637c4932 230 rb_free(ServerInfo.network_name);
47a03750 231 ServerInfo.network_name = rb_strdup((char *) data);
212380e3
AC
232}
233
234static void
235conf_set_serverinfo_vhost(void *data)
236{
caa4d9d2 237 if(rb_inet_pton(AF_INET, (char *) data, &ServerInfo.ip.sin_addr) <= 0)
212380e3
AC
238 {
239 conf_report_error("Invalid netmask for server IPv4 vhost (%s)", (char *) data);
240 return;
241 }
242 ServerInfo.ip.sin_family = AF_INET;
243 ServerInfo.specific_ipv4_vhost = 1;
244}
245
246static void
247conf_set_serverinfo_vhost6(void *data)
248{
ccda6e3f 249#ifdef RB_IPV6
caa4d9d2 250 if(rb_inet_pton(AF_INET6, (char *) data, &ServerInfo.ip6.sin6_addr) <= 0)
212380e3
AC
251 {
252 conf_report_error("Invalid netmask for server IPv6 vhost (%s)", (char *) data);
253 return;
254 }
255
256 ServerInfo.specific_ipv6_vhost = 1;
257 ServerInfo.ip6.sin6_family = AF_INET6;
258#else
259 conf_report_error("Warning -- ignoring serverinfo::vhost6 -- IPv6 support not available.");
260#endif
261}
262
263static void
264conf_set_modules_module(void *data)
265{
266#ifndef STATIC_MODULES
267 char *m_bn;
268
b7a689d1 269 m_bn = rb_basename((char *) data);
212380e3
AC
270
271 if(findmodule_byname(m_bn) != -1)
272 return;
273
274 load_one_module((char *) data, 0);
275
637c4932 276 rb_free(m_bn);
212380e3
AC
277#else
278 conf_report_error("Ignoring modules::module -- loadable module support not present.");
279#endif
280}
281
282static void
283conf_set_modules_path(void *data)
284{
285#ifndef STATIC_MODULES
286 mod_add_path((char *) data);
287#else
288 conf_report_error("Ignoring modules::path -- loadable module support not present.");
289#endif
290}
291
292struct mode_table
293{
294 const char *name;
295 int mode;
296};
297
298/* *INDENT-OFF* */
299static struct mode_table umode_table[] = {
300 {"callerid", UMODE_CALLERID },
301 {"deaf", UMODE_DEAF },
302 {"invisible", UMODE_INVISIBLE },
303 {"locops", UMODE_LOCOPS },
304 {"noforward", UMODE_NOFORWARD },
305 {"regonlymsg", UMODE_REGONLYMSG},
306 {"servnotice", UMODE_SERVNOTICE},
307 {"wallop", UMODE_WALLOP },
308 {"operwall", UMODE_OPERWALL },
309 {NULL, 0}
310};
311
19c13ce5 312static struct mode_table oper_table[] = {
212380e3 313 {"encrypted", OPER_ENCRYPTED },
b1594414 314 {"need_ssl", OPER_NEEDSSL },
212380e3
AC
315 {NULL, 0}
316};
317
318static struct mode_table auth_table[] = {
319 {"encrypted", CONF_FLAGS_ENCRYPTED },
320 {"spoof_notice", CONF_FLAGS_SPOOF_NOTICE },
321 {"exceed_limit", CONF_FLAGS_NOLIMIT },
322 {"dnsbl_exempt", CONF_FLAGS_EXEMPTDNSBL },
323 {"kline_exempt", CONF_FLAGS_EXEMPTKLINE },
212380e3
AC
324 {"flood_exempt", CONF_FLAGS_EXEMPTFLOOD },
325 {"spambot_exempt", CONF_FLAGS_EXEMPTSPAMBOT },
326 {"shide_exempt", CONF_FLAGS_EXEMPTSHIDE },
327 {"jupe_exempt", CONF_FLAGS_EXEMPTJUPE },
328 {"resv_exempt", CONF_FLAGS_EXEMPTRESV },
329 {"no_tilde", CONF_FLAGS_NO_TILDE },
330 {"need_ident", CONF_FLAGS_NEED_IDENTD },
331 {"have_ident", CONF_FLAGS_NEED_IDENTD },
b1594414 332 {"need_ssl", CONF_FLAGS_NEED_SSL },
212380e3
AC
333 {"need_sasl", CONF_FLAGS_NEED_SASL },
334 {NULL, 0}
335};
336
337static struct mode_table connect_table[] = {
338 { "autoconn", SERVER_AUTOCONN },
339 { "compressed", SERVER_COMPRESSED },
340 { "encrypted", SERVER_ENCRYPTED },
341 { "topicburst", SERVER_TB },
c6d72037 342 { "ssl", SERVER_SSL },
212380e3
AC
343 { NULL, 0 },
344};
345
346static struct mode_table cluster_table[] = {
347 { "kline", SHARED_PKLINE },
348 { "tkline", SHARED_TKLINE },
349 { "unkline", SHARED_UNKLINE },
350 { "locops", SHARED_LOCOPS },
351 { "xline", SHARED_PXLINE },
352 { "txline", SHARED_TXLINE },
353 { "unxline", SHARED_UNXLINE },
354 { "resv", SHARED_PRESV },
355 { "tresv", SHARED_TRESV },
356 { "unresv", SHARED_UNRESV },
357 { "all", CLUSTER_ALL },
358 {NULL, 0}
359};
360
361static struct mode_table shared_table[] =
362{
363 { "kline", SHARED_PKLINE|SHARED_TKLINE },
364 { "xline", SHARED_PXLINE|SHARED_TXLINE },
365 { "resv", SHARED_PRESV|SHARED_TRESV },
f5cb68d5
VY
366 { "dline", SHARED_PDLINE|SHARED_TDLINE },
367 { "tdline", SHARED_TDLINE },
368 { "pdline", SHARED_PDLINE },
369 { "undline", SHARED_UNDLINE },
212380e3
AC
370 { "tkline", SHARED_TKLINE },
371 { "unkline", SHARED_UNKLINE },
372 { "txline", SHARED_TXLINE },
373 { "unxline", SHARED_UNXLINE },
374 { "tresv", SHARED_TRESV },
375 { "unresv", SHARED_UNRESV },
376 { "locops", SHARED_LOCOPS },
377 { "rehash", SHARED_REHASH },
378 { "all", SHARED_ALL },
379 { "none", 0 },
380 {NULL, 0}
381};
382/* *INDENT-ON* */
383
384static int
385find_umode(struct mode_table *tab, const char *name)
386{
387 int i;
388
389 for (i = 0; tab[i].name; i++)
390 {
391 if(strcmp(tab[i].name, name) == 0)
392 return tab[i].mode;
393 }
394
395 return -1;
396}
397
398static void
399set_modes_from_table(int *modes, const char *whatis, struct mode_table *tab, conf_parm_t * args)
400{
401 for (; args; args = args->next)
402 {
403 const char *umode;
404 int dir = 1;
405 int mode;
406
407 if((args->type & CF_MTYPE) != CF_STRING)
408 {
409 conf_report_error("Warning -- %s is not a string; ignoring.", whatis);
410 continue;
411 }
412
413 umode = args->v.string;
414
415 if(*umode == '~')
416 {
417 dir = 0;
418 umode++;
419 }
420
421 mode = find_umode(tab, umode);
422
423 if(mode == -1)
424 {
425 conf_report_error("Warning -- unknown %s %s.", whatis, args->v.string);
426 continue;
427 }
428
429 if(mode)
430 {
431 if(dir)
432 *modes |= mode;
433 else
434 *modes &= ~mode;
435 }
436 else
437 *modes = 0;
438 }
439}
440
f8606875
AC
441static void
442conf_set_privset_extends(void *data)
443{
444 yy_privset_extends = rb_strdup((char *) data);
445}
446
447static void
448conf_set_privset_privs(void *data)
449{
450 char *privs = NULL;
451 conf_parm_t *args = data;
452
453 for (; args; args = args->next)
454 {
455 if (privs == NULL)
456 privs = rb_strdup(args->v.string);
457 else
458 {
459 char *privs_old = privs;
460
461 privs = rb_malloc(strlen(privs_old) + 1 + strlen(args->v.string) + 1);
065f67db 462 strcpy(privs, privs_old);
f8606875
AC
463 strcat(privs, " ");
464 strcat(privs, args->v.string);
465
466 rb_free(privs_old);
467 }
468 }
469
470 if (privs)
471 {
472 if (yy_privset_extends)
473 {
474 struct PrivilegeSet *set = privilegeset_get(yy_privset_extends);
475
476 if (!set)
477 {
49b0375d 478 conf_report_error("Warning -- unknown parent privilege set %s for %s; assuming defaults", yy_privset_extends, conf_cur_block_name);
f8606875 479
49b0375d 480 set = privilegeset_get("default");
f8606875
AC
481 }
482
483 privilegeset_extend(set, conf_cur_block_name != NULL ? conf_cur_block_name : "<unknown>", privs, 0);
484
485 rb_free(yy_privset_extends);
486 yy_privset_extends = NULL;
487 }
488 else
489 privilegeset_set_new(conf_cur_block_name != NULL ? conf_cur_block_name : "<unknown>", privs, 0);
490
491 rb_free(privs);
492 }
493}
494
212380e3
AC
495static int
496conf_begin_oper(struct TopConf *tc)
497{
330fc5c1 498 rb_dlink_node *ptr;
637c4932 499 rb_dlink_node *next_ptr;
212380e3
AC
500
501 if(yy_oper != NULL)
502 {
503 free_oper_conf(yy_oper);
504 yy_oper = NULL;
505 }
506
637c4932 507 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_oper_list.head)
212380e3
AC
508 {
509 free_oper_conf(ptr->data);
330fc5c1 510 rb_dlinkDestroy(ptr, &yy_oper_list);
212380e3
AC
511 }
512
513 yy_oper = make_oper_conf();
10847f65 514 yy_oper->flags |= OPER_ENCRYPTED;
212380e3
AC
515
516 return 0;
517}
518
519static int
520conf_end_oper(struct TopConf *tc)
521{
522 struct oper_conf *yy_tmpoper;
330fc5c1 523 rb_dlink_node *ptr;
637c4932 524 rb_dlink_node *next_ptr;
212380e3
AC
525
526 if(conf_cur_block_name != NULL)
527 {
528 if(strlen(conf_cur_block_name) > OPERNICKLEN)
529 conf_cur_block_name[OPERNICKLEN] = '\0';
530
47a03750 531 yy_oper->name = rb_strdup(conf_cur_block_name);
212380e3
AC
532 }
533
534 if(EmptyString(yy_oper->name))
535 {
536 conf_report_error("Ignoring operator block -- missing name.");
537 return 0;
538 }
539
540#ifdef HAVE_LIBCRYPTO
541 if(EmptyString(yy_oper->passwd) && EmptyString(yy_oper->rsa_pubkey_file))
542#else
543 if(EmptyString(yy_oper->passwd))
544#endif
545 {
546 conf_report_error("Ignoring operator block for %s -- missing password",
547 yy_oper->name);
548 return 0;
549 }
550
7d5acab7
JT
551
552 if (!yy_oper->privset)
553 yy_oper->privset = privilegeset_get("default");
554
212380e3
AC
555 /* now, yy_oper_list contains a stack of oper_conf's with just user
556 * and host in, yy_oper contains the rest of the information which
557 * we need to copy into each element in yy_oper_list
558 */
637c4932 559 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_oper_list.head)
212380e3
AC
560 {
561 yy_tmpoper = ptr->data;
562
47a03750 563 yy_tmpoper->name = rb_strdup(yy_oper->name);
212380e3
AC
564
565 /* could be an rsa key instead.. */
566 if(!EmptyString(yy_oper->passwd))
47a03750 567 yy_tmpoper->passwd = rb_strdup(yy_oper->passwd);
212380e3
AC
568
569 yy_tmpoper->flags = yy_oper->flags;
570 yy_tmpoper->umodes = yy_oper->umodes;
571 yy_tmpoper->snomask = yy_oper->snomask;
22c3b270 572 yy_tmpoper->privset = yy_oper->privset;
212380e3
AC
573
574#ifdef HAVE_LIBCRYPTO
575 if(yy_oper->rsa_pubkey_file)
576 {
577 BIO *file;
578
579 if((file = BIO_new_file(yy_oper->rsa_pubkey_file, "r")) == NULL)
580 {
581 conf_report_error("Ignoring operator block for %s -- "
582 "rsa_public_key_file cant be opened",
583 yy_tmpoper->name);
584 return 0;
585 }
586
587 yy_tmpoper->rsa_pubkey =
588 (RSA *) PEM_read_bio_RSA_PUBKEY(file, NULL, 0, NULL);
589
c422d2a0 590 (void)BIO_set_close(file, BIO_CLOSE);
212380e3
AC
591 BIO_free(file);
592
593 if(yy_tmpoper->rsa_pubkey == NULL)
594 {
595 conf_report_error("Ignoring operator block for %s -- "
596 "rsa_public_key_file key invalid; check syntax",
597 yy_tmpoper->name);
598 return 0;
599 }
600 }
63c7a68e
EM
601
602 if(!EmptyString(yy_oper->certfp))
462ae9d7 603 yy_tmpoper->certfp = rb_strdup(yy_oper->certfp);
212380e3
AC
604#endif
605
606 /* all is ok, put it on oper_conf_list */
330fc5c1 607 rb_dlinkMoveNode(ptr, &yy_oper_list, &oper_conf_list);
212380e3
AC
608 }
609
610 free_oper_conf(yy_oper);
611 yy_oper = NULL;
612
613 return 0;
614}
615
616static void
617conf_set_oper_flags(void *data)
618{
619 conf_parm_t *args = data;
620
19c13ce5 621 set_modes_from_table(&yy_oper->flags, "flag", oper_table, args);
212380e3
AC
622}
623
ff31db84
AC
624static void
625conf_set_oper_fingerprint(void *data)
626{
462ae9d7
JT
627 if (yy_oper->certfp)
628 rb_free(yy_oper->certfp);
ff31db84
AC
629 yy_oper->certfp = rb_strdup((char *) data);
630}
631
22c3b270
AC
632static void
633conf_set_oper_privset(void *data)
634{
635 yy_oper->privset = privilegeset_get((char *) data);
636}
637
212380e3
AC
638static void
639conf_set_oper_user(void *data)
640{
641 struct oper_conf *yy_tmpoper;
642 char *p;
643 char *host = (char *) data;
644
645 yy_tmpoper = make_oper_conf();
646
647 if((p = strchr(host, '@')))
648 {
649 *p++ = '\0';
650
47a03750
VY
651 yy_tmpoper->username = rb_strdup(host);
652 yy_tmpoper->host = rb_strdup(p);
212380e3
AC
653 }
654 else
655 {
656
47a03750
VY
657 yy_tmpoper->username = rb_strdup("*");
658 yy_tmpoper->host = rb_strdup(host);
212380e3
AC
659 }
660
661 if(EmptyString(yy_tmpoper->username) || EmptyString(yy_tmpoper->host))
662 {
663 conf_report_error("Ignoring user -- missing username/host");
664 free_oper_conf(yy_tmpoper);
665 return;
666 }
667
330fc5c1 668 rb_dlinkAddAlloc(yy_tmpoper, &yy_oper_list);
212380e3
AC
669}
670
671static void
672conf_set_oper_password(void *data)
673{
674 if(yy_oper->passwd)
675 {
676 memset(yy_oper->passwd, 0, strlen(yy_oper->passwd));
637c4932 677 rb_free(yy_oper->passwd);
212380e3
AC
678 }
679
47a03750 680 yy_oper->passwd = rb_strdup((char *) data);
212380e3
AC
681}
682
683static void
684conf_set_oper_rsa_public_key_file(void *data)
685{
686#ifdef HAVE_LIBCRYPTO
637c4932 687 rb_free(yy_oper->rsa_pubkey_file);
47a03750 688 yy_oper->rsa_pubkey_file = rb_strdup((char *) data);
212380e3
AC
689#else
690 conf_report_error("Warning -- ignoring rsa_public_key_file (OpenSSL support not available");
691#endif
692}
693
694static void
695conf_set_oper_umodes(void *data)
696{
697 set_modes_from_table(&yy_oper->umodes, "umode", umode_table, data);
698}
699
700static void
701conf_set_oper_snomask(void *data)
702{
703 yy_oper->snomask = parse_snobuf_to_mask(0, (const char *) data);
704}
705
706static int
707conf_begin_class(struct TopConf *tc)
708{
709 if(yy_class)
710 free_class(yy_class);
711
712 yy_class = make_class();
713 return 0;
714}
715
716static int
717conf_end_class(struct TopConf *tc)
718{
719 if(conf_cur_block_name != NULL)
47a03750 720 yy_class->class_name = rb_strdup(conf_cur_block_name);
212380e3
AC
721
722 if(EmptyString(yy_class->class_name))
723 {
724 conf_report_error("Ignoring connect block -- missing name.");
725 return 0;
726 }
727
728 add_class(yy_class);
729 yy_class = NULL;
730 return 0;
731}
732
733static void
734conf_set_class_ping_time(void *data)
735{
736 yy_class->ping_freq = *(unsigned int *) data;
737}
738
739static void
e33e589c 740conf_set_class_cidr_ipv4_bitlen(void *data)
212380e3 741{
e33e589c
JT
742 unsigned int maxsize = 32;
743 if(*(unsigned int *) data > maxsize)
744 conf_report_error
745 ("class::cidr_ipv4_bitlen argument exceeds maxsize (%d > %d) - ignoring.",
746 *(unsigned int *) data, maxsize);
747 else
748 yy_class->cidr_ipv4_bitlen = *(unsigned int *) data;
749
750}
751
ccda6e3f 752#ifdef RB_IPV6
e33e589c
JT
753static void
754conf_set_class_cidr_ipv6_bitlen(void *data)
755{
212380e3 756 unsigned int maxsize = 128;
212380e3
AC
757 if(*(unsigned int *) data > maxsize)
758 conf_report_error
e33e589c 759 ("class::cidr_ipv6_bitlen argument exceeds maxsize (%d > %d) - ignoring.",
212380e3
AC
760 *(unsigned int *) data, maxsize);
761 else
e33e589c 762 yy_class->cidr_ipv6_bitlen = *(unsigned int *) data;
212380e3
AC
763
764}
e33e589c
JT
765#endif
766
212380e3
AC
767static void
768conf_set_class_number_per_cidr(void *data)
769{
770 yy_class->cidr_amount = *(unsigned int *) data;
771}
772
773static void
774conf_set_class_number_per_ip(void *data)
775{
776 yy_class->max_local = *(unsigned int *) data;
777}
778
779
780static void
781conf_set_class_number_per_ip_global(void *data)
782{
783 yy_class->max_global = *(unsigned int *) data;
784}
785
786static void
787conf_set_class_number_per_ident(void *data)
788{
789 yy_class->max_ident = *(unsigned int *) data;
790}
791
792static void
793conf_set_class_connectfreq(void *data)
794{
795 yy_class->con_freq = *(unsigned int *) data;
796}
797
798static void
799conf_set_class_max_number(void *data)
800{
801 yy_class->max_total = *(unsigned int *) data;
802}
803
804static void
805conf_set_class_sendq(void *data)
806{
807 yy_class->max_sendq = *(unsigned int *) data;
808}
809
810static char *listener_address;
811
812static int
813conf_begin_listen(struct TopConf *tc)
814{
637c4932 815 rb_free(listener_address);
212380e3
AC
816 listener_address = NULL;
817 return 0;
818}
819
820static int
821conf_end_listen(struct TopConf *tc)
822{
637c4932 823 rb_free(listener_address);
212380e3
AC
824 listener_address = NULL;
825 return 0;
826}
827
c6d72037
VY
828
829
212380e3 830static void
c6d72037 831conf_set_listen_port_both(void *data, int ssl)
212380e3
AC
832{
833 conf_parm_t *args = data;
834 for (; args; args = args->next)
835 {
836 if((args->type & CF_MTYPE) != CF_INT)
837 {
838 conf_report_error
839 ("listener::port argument is not an integer " "-- ignoring.");
840 continue;
841 }
842 if(listener_address == NULL)
843 {
c6d72037 844 add_listener(args->v.number, listener_address, AF_INET, ssl);
ccda6e3f 845#ifdef RB_IPV6
c6d72037 846 add_listener(args->v.number, listener_address, AF_INET6, ssl);
212380e3
AC
847#endif
848 }
849 else
850 {
851 int family;
ccda6e3f 852#ifdef RB_IPV6
212380e3
AC
853 if(strchr(listener_address, ':') != NULL)
854 family = AF_INET6;
855 else
856#endif
857 family = AF_INET;
858
c6d72037 859 add_listener(args->v.number, listener_address, family, ssl);
212380e3
AC
860
861 }
862
863 }
864}
865
8bd5767b
JT
866static void
867conf_set_listen_port(void *data)
868{
869 conf_set_listen_port_both(data, 0);
870}
871
872static void
873conf_set_listen_sslport(void *data)
874{
875 conf_set_listen_port_both(data, 1);
c6d72037
VY
876}
877
212380e3
AC
878static void
879conf_set_listen_address(void *data)
880{
637c4932 881 rb_free(listener_address);
47a03750 882 listener_address = rb_strdup(data);
212380e3
AC
883}
884
885static int
886conf_begin_auth(struct TopConf *tc)
887{
330fc5c1 888 rb_dlink_node *ptr;
637c4932 889 rb_dlink_node *next_ptr;
212380e3
AC
890
891 if(yy_aconf)
892 free_conf(yy_aconf);
893
637c4932 894 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_aconf_list.head)
212380e3
AC
895 {
896 free_conf(ptr->data);
330fc5c1 897 rb_dlinkDestroy(ptr, &yy_aconf_list);
212380e3
AC
898 }
899
900 yy_aconf = make_conf();
901 yy_aconf->status = CONF_CLIENT;
902
903 return 0;
904}
905
906static int
907conf_end_auth(struct TopConf *tc)
908{
3d1f32c0 909 struct ConfItem *yy_tmp, *found_conf;
330fc5c1 910 rb_dlink_node *ptr;
637c4932 911 rb_dlink_node *next_ptr;
212380e3 912
27f616dd
JT
913 if(EmptyString(yy_aconf->info.name))
914 yy_aconf->info.name = rb_strdup("NOMATCH");
212380e3
AC
915
916 /* didnt even get one ->host? */
917 if(EmptyString(yy_aconf->host))
918 {
919 conf_report_error("Ignoring auth block -- missing user@host");
920 return 0;
921 }
922
923 /* so the stacking works in order.. */
924 collapse(yy_aconf->user);
925 collapse(yy_aconf->host);
926 conf_add_class_to_conf(yy_aconf);
3d1f32c0 927 if ((found_conf = find_exact_conf_by_address("*", CONF_CLIENT, "*")) && found_conf->spasswd == NULL)
6e5e2b00 928 conf_report_error("Ignoring redundant auth block (after *@*)");
3d1f32c0 929 else if ((found_conf = find_exact_conf_by_address(yy_aconf->host, CONF_CLIENT, yy_aconf->user)) &&
5f2df251 930 (!found_conf->spasswd || (yy_aconf->spasswd &&
3d1f32c0 931 0 == irccmp(found_conf->spasswd, yy_aconf->spasswd))))
6e5e2b00
JT
932 conf_report_error("Ignoring duplicate auth block for %s@%s",
933 yy_aconf->user, yy_aconf->host);
934 else
935 add_conf_by_address(yy_aconf->host, CONF_CLIENT, yy_aconf->user, yy_aconf->spasswd, yy_aconf);
212380e3 936
637c4932 937 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_aconf_list.head)
212380e3
AC
938 {
939 yy_tmp = ptr->data;
940
941 if(yy_aconf->passwd)
47a03750 942 yy_tmp->passwd = rb_strdup(yy_aconf->passwd);
212380e3 943
40c1fd47
VY
944 if(yy_aconf->spasswd)
945 yy_tmp->spasswd = rb_strdup(yy_aconf->spasswd);
946
212380e3 947 /* this will always exist.. */
27f616dd 948 yy_tmp->info.name = rb_strdup(yy_aconf->info.name);
212380e3
AC
949
950 if(yy_aconf->className)
47a03750 951 yy_tmp->className = rb_strdup(yy_aconf->className);
212380e3
AC
952
953 yy_tmp->flags = yy_aconf->flags;
954 yy_tmp->port = yy_aconf->port;
955
956 collapse(yy_tmp->user);
957 collapse(yy_tmp->host);
958
959 conf_add_class_to_conf(yy_tmp);
960
6e5e2b00
JT
961 if (find_exact_conf_by_address("*", CONF_CLIENT, "*"))
962 conf_report_error("Ignoring redundant auth block (after *@*)");
963 else if (find_exact_conf_by_address(yy_tmp->host, CONF_CLIENT, yy_tmp->user))
964 conf_report_error("Ignoring duplicate auth block for %s@%s",
965 yy_tmp->user, yy_tmp->host);
966 else
967 add_conf_by_address(yy_tmp->host, CONF_CLIENT, yy_tmp->user, yy_tmp->spasswd, yy_tmp);
330fc5c1 968 rb_dlinkDestroy(ptr, &yy_aconf_list);
212380e3
AC
969 }
970
971 yy_aconf = NULL;
972 return 0;
973}
974
975static void
976conf_set_auth_user(void *data)
977{
978 struct ConfItem *yy_tmp;
979 char *p;
980
981 /* The first user= line doesn't allocate a new conf */
982 if(!EmptyString(yy_aconf->host))
983 {
984 yy_tmp = make_conf();
985 yy_tmp->status = CONF_CLIENT;
986 }
987 else
988 yy_tmp = yy_aconf;
989
990 if((p = strchr(data, '@')))
991 {
992 *p++ = '\0';
993
47a03750
VY
994 yy_tmp->user = rb_strdup(data);
995 yy_tmp->host = rb_strdup(p);
212380e3
AC
996 }
997 else
998 {
47a03750
VY
999 yy_tmp->user = rb_strdup("*");
1000 yy_tmp->host = rb_strdup(data);
212380e3
AC
1001 }
1002
1003 if(yy_aconf != yy_tmp)
330fc5c1 1004 rb_dlinkAddAlloc(yy_tmp, &yy_aconf_list);
212380e3
AC
1005}
1006
40c1fd47
VY
1007static void
1008conf_set_auth_auth_user(void *data)
1009{
1010 if(yy_aconf->spasswd)
1011 memset(yy_aconf->spasswd, 0, strlen(yy_aconf->spasswd));
1012 rb_free(yy_aconf->spasswd);
1013 yy_aconf->spasswd = rb_strdup(data);
1014}
1015
212380e3
AC
1016static void
1017conf_set_auth_passwd(void *data)
1018{
1019 if(yy_aconf->passwd)
1020 memset(yy_aconf->passwd, 0, strlen(yy_aconf->passwd));
637c4932 1021 rb_free(yy_aconf->passwd);
47a03750 1022 yy_aconf->passwd = rb_strdup(data);
212380e3
AC
1023}
1024
1025static void
1026conf_set_auth_spoof(void *data)
1027{
1028 char *p;
1029 char *user = NULL;
1030 char *host = NULL;
1031
1032 host = data;
1033
1034 /* user@host spoof */
1035 if((p = strchr(host, '@')) != NULL)
1036 {
1037 *p = '\0';
1038 user = data;
1039 host = p+1;
1040
1041 if(EmptyString(user))
1042 {
1043 conf_report_error("Warning -- spoof ident empty.");
1044 return;
1045 }
1046
1047 if(strlen(user) > USERLEN)
1048 {
1049 conf_report_error("Warning -- spoof ident length invalid.");
1050 return;
1051 }
1052
1053 if(!valid_username(user))
1054 {
1055 conf_report_error("Warning -- invalid spoof (ident).");
1056 return;
1057 }
1058
1059 /* this must be restored! */
1060 *p = '@';
1061 }
1062
1063 if(EmptyString(host))
1064 {
1065 conf_report_error("Warning -- spoof host empty.");
1066 return;
1067 }
1068
1069 if(strlen(host) > HOSTLEN)
1070 {
1071 conf_report_error("Warning -- spoof host length invalid.");
1072 return;
1073 }
1074
1075 if(!valid_hostname(host))
1076 {
1077 conf_report_error("Warning -- invalid spoof (host).");
1078 return;
1079 }
1080
27f616dd
JT
1081 rb_free(yy_aconf->info.name);
1082 yy_aconf->info.name = rb_strdup(data);
212380e3
AC
1083 yy_aconf->flags |= CONF_FLAGS_SPOOF_IP;
1084}
1085
1086static void
1087conf_set_auth_flags(void *data)
1088{
1089 conf_parm_t *args = data;
1090
1091 set_modes_from_table((int *) &yy_aconf->flags, "flag", auth_table, args);
1092}
1093
1094static void
1095conf_set_auth_redir_serv(void *data)
1096{
1097 yy_aconf->flags |= CONF_FLAGS_REDIR;
27f616dd
JT
1098 rb_free(yy_aconf->info.name);
1099 yy_aconf->info.name = rb_strdup(data);
212380e3
AC
1100}
1101
1102static void
1103conf_set_auth_redir_port(void *data)
1104{
1105 int port = *(unsigned int *) data;
1106
1107 yy_aconf->flags |= CONF_FLAGS_REDIR;
1108 yy_aconf->port = port;
1109}
1110
1111static void
1112conf_set_auth_class(void *data)
1113{
637c4932 1114 rb_free(yy_aconf->className);
47a03750 1115 yy_aconf->className = rb_strdup(data);
212380e3
AC
1116}
1117
1118/* ok, shared_oper handles the stacking, shared_flags handles adding
1119 * things.. so all we need to do when we start and end a shared block, is
1120 * clean up anything thats been left over.
1121 */
1122static int
1123conf_cleanup_shared(struct TopConf *tc)
1124{
637c4932 1125 rb_dlink_node *ptr, *next_ptr;
212380e3 1126
637c4932 1127 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_shared_list.head)
212380e3
AC
1128 {
1129 free_remote_conf(ptr->data);
330fc5c1 1130 rb_dlinkDestroy(ptr, &yy_shared_list);
212380e3
AC
1131 }
1132
1133 if(yy_shared != NULL)
1134 {
1135 free_remote_conf(yy_shared);
1136 yy_shared = NULL;
1137 }
1138
1139 return 0;
1140}
1141
1142static void
1143conf_set_shared_oper(void *data)
1144{
1145 conf_parm_t *args = data;
1146 const char *username;
1147 char *p;
1148
1149 if(yy_shared != NULL)
1150 free_remote_conf(yy_shared);
1151
1152 yy_shared = make_remote_conf();
1153
1154 if(args->next != NULL)
1155 {
1156 if((args->type & CF_MTYPE) != CF_QSTRING)
1157 {
1158 conf_report_error("Ignoring shared::oper -- server is not a qstring");
1159 return;
1160 }
1161
47a03750 1162 yy_shared->server = rb_strdup(args->v.string);
212380e3
AC
1163 args = args->next;
1164 }
1165 else
47a03750 1166 yy_shared->server = rb_strdup("*");
212380e3
AC
1167
1168 if((args->type & CF_MTYPE) != CF_QSTRING)
1169 {
1170 conf_report_error("Ignoring shared::oper -- oper is not a qstring");
1171 return;
1172 }
1173
1174 if((p = strchr(args->v.string, '@')) == NULL)
1175 {
1176 conf_report_error("Ignoring shard::oper -- oper is not a user@host");
1177 return;
1178 }
1179
1180 username = args->v.string;
1181 *p++ = '\0';
1182
1183 if(EmptyString(p))
47a03750 1184 yy_shared->host = rb_strdup("*");
212380e3 1185 else
47a03750 1186 yy_shared->host = rb_strdup(p);
212380e3
AC
1187
1188 if(EmptyString(username))
47a03750 1189 yy_shared->username = rb_strdup("*");
212380e3 1190 else
47a03750 1191 yy_shared->username = rb_strdup(username);
212380e3 1192
330fc5c1 1193 rb_dlinkAddAlloc(yy_shared, &yy_shared_list);
212380e3
AC
1194 yy_shared = NULL;
1195}
1196
1197static void
1198conf_set_shared_flags(void *data)
1199{
1200 conf_parm_t *args = data;
1201 int flags = 0;
637c4932 1202 rb_dlink_node *ptr, *next_ptr;
212380e3
AC
1203
1204 if(yy_shared != NULL)
1205 free_remote_conf(yy_shared);
1206
1207 set_modes_from_table(&flags, "flag", shared_table, args);
1208
637c4932 1209 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_shared_list.head)
212380e3
AC
1210 {
1211 yy_shared = ptr->data;
1212
1213 yy_shared->flags = flags;
330fc5c1
AC
1214 rb_dlinkDestroy(ptr, &yy_shared_list);
1215 rb_dlinkAddTail(yy_shared, &yy_shared->node, &shared_conf_list);
212380e3
AC
1216 }
1217
1218 yy_shared = NULL;
1219}
1220
1221static int
1222conf_begin_connect(struct TopConf *tc)
1223{
1224 if(yy_server)
1225 free_server_conf(yy_server);
1226
1227 yy_server = make_server_conf();
1228 yy_server->port = PORTNUM;
5aa453a4 1229 yy_server->flags |= SERVER_TB;
212380e3
AC
1230
1231 if(conf_cur_block_name != NULL)
47a03750 1232 yy_server->name = rb_strdup(conf_cur_block_name);
212380e3
AC
1233
1234 return 0;
1235}
1236
1237static int
1238conf_end_connect(struct TopConf *tc)
1239{
1240 if(EmptyString(yy_server->name))
1241 {
1242 conf_report_error("Ignoring connect block -- missing name.");
1243 return 0;
1244 }
1245
1246 if(ServerInfo.name != NULL && !irccmp(ServerInfo.name, yy_server->name))
1247 {
1248 conf_report_error("Ignoring connect block for %s -- name is equal to my own name.",
1249 yy_server->name);
1250 return 0;
1251 }
1252
ff0cc1e6 1253 if((EmptyString(yy_server->passwd) || EmptyString(yy_server->spasswd)) && EmptyString(yy_server->certfp))
212380e3 1254 {
c8f26906 1255 conf_report_error("Ignoring connect block for %s -- no fingerprint or password credentials provided.",
212380e3
AC
1256 yy_server->name);
1257 return 0;
1258 }
1259
1260 if(EmptyString(yy_server->host))
1261 {
1262 conf_report_error("Ignoring connect block for %s -- missing host.",
1263 yy_server->name);
1264 return 0;
1265 }
1266
1267#ifndef HAVE_LIBZ
1268 if(ServerConfCompressed(yy_server))
1269 {
1270 conf_report_error("Ignoring connect::flags::compressed -- zlib not available.");
1271 yy_server->flags &= ~SERVER_COMPRESSED;
1272 }
1273#endif
1274
1275 add_server_conf(yy_server);
330fc5c1 1276 rb_dlinkAdd(yy_server, &yy_server->node, &server_conf_list);
212380e3
AC
1277
1278 yy_server = NULL;
1279 return 0;
1280}
1281
1282static void
1283conf_set_connect_host(void *data)
1284{
637c4932 1285 rb_free(yy_server->host);
47a03750 1286 yy_server->host = rb_strdup(data);
212380e3
AC
1287 if (strchr(yy_server->host, ':'))
1288 yy_server->aftype = AF_INET6;
1289}
1290
1291static void
1292conf_set_connect_vhost(void *data)
1293{
caa4d9d2 1294 if(rb_inet_pton_sock(data, (struct sockaddr *)&yy_server->my_ipnum) <= 0)
212380e3
AC
1295 {
1296 conf_report_error("Invalid netmask for server vhost (%s)",
1297 (char *) data);
1298 return;
1299 }
1300
1301 yy_server->flags |= SERVER_VHOSTED;
1302}
1303
1304static void
1305conf_set_connect_send_password(void *data)
1306{
1307 if(yy_server->spasswd)
1308 {
1309 memset(yy_server->spasswd, 0, strlen(yy_server->spasswd));
637c4932 1310 rb_free(yy_server->spasswd);
212380e3
AC
1311 }
1312
47a03750 1313 yy_server->spasswd = rb_strdup(data);
212380e3
AC
1314}
1315
1316static void
1317conf_set_connect_accept_password(void *data)
1318{
1319 if(yy_server->passwd)
1320 {
1321 memset(yy_server->passwd, 0, strlen(yy_server->passwd));
637c4932 1322 rb_free(yy_server->passwd);
212380e3 1323 }
47a03750 1324 yy_server->passwd = rb_strdup(data);
212380e3
AC
1325}
1326
ff0cc1e6
AC
1327static void
1328conf_set_connect_fingerprint(void *data)
1329{
462ae9d7
JT
1330 if (yy_server->certfp)
1331 rb_free(yy_server->certfp);
ff0cc1e6
AC
1332 yy_server->certfp = rb_strdup((char *) data);
1333
1334 /* force SSL to be enabled if fingerprint is enabled. */
1335 yy_server->flags |= SERVER_SSL;
1336}
1337
212380e3
AC
1338static void
1339conf_set_connect_port(void *data)
1340{
1341 int port = *(unsigned int *) data;
1342
1343 if(port < 1)
1344 port = PORTNUM;
1345
1346 yy_server->port = port;
1347}
1348
1349static void
1350conf_set_connect_aftype(void *data)
1351{
1352 char *aft = data;
1353
1354 if(strcasecmp(aft, "ipv4") == 0)
1355 yy_server->aftype = AF_INET;
ccda6e3f 1356#ifdef RB_IPV6
212380e3
AC
1357 else if(strcasecmp(aft, "ipv6") == 0)
1358 yy_server->aftype = AF_INET6;
1359#endif
1360 else
1361 conf_report_error("connect::aftype '%s' is unknown.", aft);
1362}
1363
1364static void
1365conf_set_connect_flags(void *data)
1366{
1367 conf_parm_t *args = data;
1368
1369 /* note, we allow them to set compressed, then remove it later if
1370 * they do and LIBZ isnt available
1371 */
1372 set_modes_from_table(&yy_server->flags, "flag", connect_table, args);
1373}
1374
1375static void
1376conf_set_connect_hub_mask(void *data)
1377{
1378 struct remote_conf *yy_hub;
1379
1380 if(EmptyString(yy_server->name))
1381 return;
1382
1383 yy_hub = make_remote_conf();
1384 yy_hub->flags = CONF_HUB;
1385
47a03750
VY
1386 yy_hub->host = rb_strdup(data);
1387 yy_hub->server = rb_strdup(yy_server->name);
330fc5c1 1388 rb_dlinkAdd(yy_hub, &yy_hub->node, &hubleaf_conf_list);
212380e3
AC
1389}
1390
1391static void
1392conf_set_connect_leaf_mask(void *data)
1393{
1394 struct remote_conf *yy_leaf;
1395
1396 if(EmptyString(yy_server->name))
1397 return;
1398
1399 yy_leaf = make_remote_conf();
1400 yy_leaf->flags = CONF_LEAF;
1401
47a03750
VY
1402 yy_leaf->host = rb_strdup(data);
1403 yy_leaf->server = rb_strdup(yy_server->name);
330fc5c1 1404 rb_dlinkAdd(yy_leaf, &yy_leaf->node, &hubleaf_conf_list);
212380e3
AC
1405}
1406
1407static void
1408conf_set_connect_class(void *data)
1409{
637c4932 1410 rb_free(yy_server->class_name);
47a03750 1411 yy_server->class_name = rb_strdup(data);
212380e3
AC
1412}
1413
1414static void
1415conf_set_exempt_ip(void *data)
1416{
1417 struct ConfItem *yy_tmp;
1418
1419 if(parse_netmask(data, NULL, NULL) == HM_HOST)
1420 {
1421 conf_report_error("Ignoring exempt -- invalid exempt::ip.");
1422 return;
1423 }
1424
1425 yy_tmp = make_conf();
47a03750
VY
1426 yy_tmp->passwd = rb_strdup("*");
1427 yy_tmp->host = rb_strdup(data);
212380e3 1428 yy_tmp->status = CONF_EXEMPTDLINE;
40c1fd47 1429 add_conf_by_address(yy_tmp->host, CONF_EXEMPTDLINE, NULL, NULL, yy_tmp);
212380e3
AC
1430}
1431
1432static int
1433conf_cleanup_cluster(struct TopConf *tc)
1434{
637c4932 1435 rb_dlink_node *ptr, *next_ptr;
212380e3 1436
637c4932 1437 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_cluster_list.head)
212380e3
AC
1438 {
1439 free_remote_conf(ptr->data);
330fc5c1 1440 rb_dlinkDestroy(ptr, &yy_cluster_list);
212380e3
AC
1441 }
1442
1443 if(yy_shared != NULL)
1444 {
1445 free_remote_conf(yy_shared);
1446 yy_shared = NULL;
1447 }
1448
1449 return 0;
1450}
1451
1452static void
1453conf_set_cluster_name(void *data)
1454{
1455 if(yy_shared != NULL)
1456 free_remote_conf(yy_shared);
1457
1458 yy_shared = make_remote_conf();
47a03750 1459 yy_shared->server = rb_strdup(data);
330fc5c1 1460 rb_dlinkAddAlloc(yy_shared, &yy_cluster_list);
212380e3
AC
1461
1462 yy_shared = NULL;
1463}
1464
1465static void
1466conf_set_cluster_flags(void *data)
1467{
1468 conf_parm_t *args = data;
1469 int flags = 0;
637c4932 1470 rb_dlink_node *ptr, *next_ptr;
212380e3
AC
1471
1472 if(yy_shared != NULL)
1473 free_remote_conf(yy_shared);
1474
1475 set_modes_from_table(&flags, "flag", cluster_table, args);
1476
637c4932 1477 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_cluster_list.head)
212380e3
AC
1478 {
1479 yy_shared = ptr->data;
1480 yy_shared->flags = flags;
330fc5c1
AC
1481 rb_dlinkAddTail(yy_shared, &yy_shared->node, &cluster_conf_list);
1482 rb_dlinkDestroy(ptr, &yy_cluster_list);
212380e3
AC
1483 }
1484
1485 yy_shared = NULL;
1486}
1487
1488static void
1489conf_set_general_havent_read_conf(void *data)
1490{
1491 if(*(unsigned int *) data)
1492 {
1493 conf_report_error("You haven't read your config file properly.");
1494 conf_report_error
1495 ("There is a line in the example conf that will kill your server if not removed.");
1496 conf_report_error
1497 ("Consider actually reading/editing the conf file, and removing this line.");
1498 if (!testing_conf)
1499 exit(0);
1500 }
1501}
1502
1503static void
1504conf_set_general_hide_error_messages(void *data)
1505{
1506 char *val = data;
1507
1508 if(strcasecmp(val, "yes") == 0)
1509 ConfigFileEntry.hide_error_messages = 2;
1510 else if(strcasecmp(val, "opers") == 0)
1511 ConfigFileEntry.hide_error_messages = 1;
1512 else if(strcasecmp(val, "no") == 0)
1513 ConfigFileEntry.hide_error_messages = 0;
1514 else
1515 conf_report_error("Invalid setting '%s' for general::hide_error_messages.", val);
1516}
1517
1518static void
1519conf_set_general_kline_delay(void *data)
1520{
1521 ConfigFileEntry.kline_delay = *(unsigned int *) data;
1522
1523 /* THIS MUST BE HERE to stop us being unable to check klines */
1524 kline_queued = 0;
1525}
1526
1527static void
1528conf_set_general_stats_k_oper_only(void *data)
1529{
1530 char *val = data;
1531
1532 if(strcasecmp(val, "yes") == 0)
1533 ConfigFileEntry.stats_k_oper_only = 2;
1534 else if(strcasecmp(val, "masked") == 0)
1535 ConfigFileEntry.stats_k_oper_only = 1;
1536 else if(strcasecmp(val, "no") == 0)
1537 ConfigFileEntry.stats_k_oper_only = 0;
1538 else
1539 conf_report_error("Invalid setting '%s' for general::stats_k_oper_only.", val);
1540}
1541
1542static void
1543conf_set_general_stats_i_oper_only(void *data)
1544{
1545 char *val = data;
1546
1547 if(strcasecmp(val, "yes") == 0)
1548 ConfigFileEntry.stats_i_oper_only = 2;
1549 else if(strcasecmp(val, "masked") == 0)
1550 ConfigFileEntry.stats_i_oper_only = 1;
1551 else if(strcasecmp(val, "no") == 0)
1552 ConfigFileEntry.stats_i_oper_only = 0;
1553 else
1554 conf_report_error("Invalid setting '%s' for general::stats_i_oper_only.", val);
1555}
1556
1557static void
1558conf_set_general_compression_level(void *data)
1559{
1560#ifdef HAVE_LIBZ
1561 ConfigFileEntry.compression_level = *(unsigned int *) data;
1562
1563 if((ConfigFileEntry.compression_level < 1) || (ConfigFileEntry.compression_level > 9))
1564 {
1565 conf_report_error
1566 ("Invalid general::compression_level %d -- using default.",
1567 ConfigFileEntry.compression_level);
1568 ConfigFileEntry.compression_level = 0;
1569 }
1570#else
1571 conf_report_error("Ignoring general::compression_level -- zlib not available.");
1572#endif
1573}
1574
1575static void
1576conf_set_general_default_umodes(void *data)
1577{
1578 char *pm;
1579 int what = MODE_ADD, flag;
1580
1581 ConfigFileEntry.default_umodes = 0;
1582 for (pm = (char *) data; *pm; pm++)
1583 {
1584 switch (*pm)
1585 {
1586 case '+':
1587 what = MODE_ADD;
1588 break;
1589 case '-':
1590 what = MODE_DEL;
1591 break;
1592
1593 /* don't allow +o */
1594 case 'o':
1595 case 'S':
1596 case ' ':
1597 break;
1598
1599 default:
1600 if ((flag = user_modes[(unsigned char) *pm]))
1601 {
1602 /* Proper value has probably not yet been set
1603 * so don't check oper_only_umodes -- jilles */
1604 if (what == MODE_ADD)
1605 ConfigFileEntry.default_umodes |= flag;
1606 else
1607 ConfigFileEntry.default_umodes &= ~flag;
1608 }
1609 break;
1610 }
1611 }
1612}
1613
1614static void
1615conf_set_general_oper_umodes(void *data)
1616{
1617 set_modes_from_table(&ConfigFileEntry.oper_umodes, "umode", umode_table, data);
1618}
1619
1620static void
1621conf_set_general_oper_only_umodes(void *data)
1622{
1623 set_modes_from_table(&ConfigFileEntry.oper_only_umodes, "umode", umode_table, data);
1624}
1625
1626static void
1627conf_set_general_oper_snomask(void *data)
1628{
1629 char *pm;
1630 int what = MODE_ADD, flag;
1631
1632 ConfigFileEntry.oper_snomask = 0;
1633 for (pm = (char *) data; *pm; pm++)
1634 {
1635 switch (*pm)
1636 {
1637 case '+':
1638 what = MODE_ADD;
1639 break;
1640 case '-':
1641 what = MODE_DEL;
1642 break;
1643
1644 default:
1645 if ((flag = snomask_modes[(unsigned char) *pm]))
1646 {
1647 if (what == MODE_ADD)
1648 ConfigFileEntry.oper_snomask |= flag;
1649 else
1650 ConfigFileEntry.oper_snomask &= ~flag;
1651 }
1652 break;
1653 }
1654 }
1655}
1656
1657static void
1658conf_set_serverhide_links_delay(void *data)
1659{
1660 int val = *(unsigned int *) data;
1661
212380e3
AC
1662 ConfigServerHide.links_delay = val;
1663}
1664
1665static int
1666conf_begin_service(struct TopConf *tc)
1667{
1668 struct Client *target_p;
330fc5c1 1669 rb_dlink_node *ptr;
212380e3 1670
5cefa1d6 1671 RB_DLINK_FOREACH(ptr, global_serv_list.head)
212380e3
AC
1672 {
1673 target_p = ptr->data;
1674
1675 target_p->flags &= ~FLAGS_SERVICE;
1676 }
1677
1678 return 0;
1679}
1680
1681static void
1682conf_set_service_name(void *data)
1683{
1684 struct Client *target_p;
1685 const char *s;
1686 char *tmp;
1687 int dots = 0;
1688
1689 for(s = data; *s != '\0'; s++)
1690 {
1691 if(!IsServChar(*s))
1692 {
1693 conf_report_error("Ignoring service::name "
1694 "-- bogus servername.");
1695 return;
1696 }
1697 else if(*s == '.')
1698 dots++;
1699 }
1700
1701 if(!dots)
1702 {
1703 conf_report_error("Ignoring service::name -- must contain '.'");
1704 return;
1705 }
1706
47a03750 1707 tmp = rb_strdup(data);
330fc5c1 1708 rb_dlinkAddAlloc(tmp, &service_list);
212380e3
AC
1709
1710 if((target_p = find_server(NULL, tmp)))
1711 target_p->flags |= FLAGS_SERVICE;
1712}
1713
212380e3
AC
1714static int
1715conf_begin_alias(struct TopConf *tc)
1716{
eddc2ab6 1717 yy_alias = rb_malloc(sizeof(struct alias_entry));
212380e3
AC
1718
1719 if (conf_cur_block_name != NULL)
47a03750 1720 yy_alias->name = rb_strdup(conf_cur_block_name);
212380e3
AC
1721
1722 yy_alias->flags = 0;
1723 yy_alias->hits = 0;
1724
1725 return 0;
1726}
1727
1728static int
1729conf_end_alias(struct TopConf *tc)
1730{
212380e3
AC
1731 if (yy_alias == NULL)
1732 return -1;
1733
1734 if (yy_alias->name == NULL)
1735 {
1736 conf_report_error("Ignoring alias -- must have a name.");
1737
637c4932 1738 rb_free(yy_alias);
212380e3
AC
1739
1740 return -1;
1741 }
1742
1743 if (yy_alias->target == NULL)
1744 {
1745 conf_report_error("Ignoring alias -- must have a target.");
1746
637c4932 1747 rb_free(yy_alias);
212380e3
AC
1748
1749 return -1;
1750 }
1751
8ac75529 1752 irc_dictionary_add(alias_dict, yy_alias->name, yy_alias);
212380e3
AC
1753
1754 return 0;
1755}
1756
1757static void
1758conf_set_alias_name(void *data)
1759{
1760 if (data == NULL || yy_alias == NULL) /* this shouldn't ever happen */
1761 return;
1762
47a03750 1763 yy_alias->name = rb_strdup(data);
212380e3
AC
1764}
1765
1766static void
1767conf_set_alias_target(void *data)
1768{
1769 if (data == NULL || yy_alias == NULL) /* this shouldn't ever happen */
1770 return;
1771
47a03750 1772 yy_alias->target = rb_strdup(data);
212380e3
AC
1773}
1774
1775static void
1776conf_set_blacklist_host(void *data)
1777{
47a03750 1778 yy_blacklist_host = rb_strdup(data);
212380e3
AC
1779}
1780
0a1e77c2
EM
1781static void
1782conf_set_blacklist_type(void *data)
1783{
1784 conf_parm_t *args = data;
1785
1786 /* Don't assume we have either if we got here */
1787 yy_blacklist_ipv4 = 0;
1788 yy_blacklist_ipv6 = 0;
1789
1790 for (; args; args = args->next)
1791 {
1792 if (!strcasecmp(args->v.string, "ipv4"))
1793 yy_blacklist_ipv4 = 1;
1794 else if (!strcasecmp(args->v.string, "ipv6"))
1795 yy_blacklist_ipv6 = 1;
1796 else
1797 conf_report_error("blacklist::type has unknown address family %s",
1798 args->v.string);
1799 }
1800
1801 /* If we have neither, just default to IPv4 */
1802 if (!yy_blacklist_ipv4 && !yy_blacklist_ipv6)
1803 {
1804 conf_report_error("blacklist::type has neither IPv4 nor IPv6 (defaulting to IPv4)");
1805 yy_blacklist_ipv4 = 1;
1806 }
1807}
1808
212380e3
AC
1809static void
1810conf_set_blacklist_reason(void *data)
1811{
47a03750 1812 yy_blacklist_reason = rb_strdup(data);
212380e3
AC
1813
1814 if (yy_blacklist_host && yy_blacklist_reason)
1815 {
0a1e77c2
EM
1816 if (yy_blacklist_ipv6)
1817 {
1818 /* Make sure things fit (64 = alnum count + dots) */
1819 if ((64 + strlen(yy_blacklist_host)) > IRCD_RES_HOSTLEN)
1820 {
1821 conf_report_error("blacklist::host %s results in IPv6 queries that are too long",
1822 yy_blacklist_host);
1823 goto cleanup_bl;
1824 }
1825 }
1826 /* Avoid doing redundant check, IPv6 is bigger than IPv4 --Elizabeth */
1827 if (yy_blacklist_ipv4 && !yy_blacklist_ipv6)
1828 {
1829 /* Make sure things fit (16 = number of nums + dots) */
1830 if ((16 + strlen(yy_blacklist_host)) > IRCD_RES_HOSTLEN)
1831 {
1832 conf_report_error("blacklist::host %s results in IPv4 queries that are too long",
1833 yy_blacklist_host);
1834 goto cleanup_bl;
1835 }
1836 }
1837
1838 new_blacklist(yy_blacklist_host, yy_blacklist_reason, yy_blacklist_ipv4, yy_blacklist_ipv6);
1839
1840cleanup_bl:
637c4932
VY
1841 rb_free(yy_blacklist_host);
1842 rb_free(yy_blacklist_reason);
212380e3
AC
1843 yy_blacklist_host = NULL;
1844 yy_blacklist_reason = NULL;
0a1e77c2
EM
1845 yy_blacklist_ipv4 = 1;
1846 yy_blacklist_ipv6 = 0;
212380e3
AC
1847 }
1848}
1849
1850/* public functions */
1851
1852
1853void
1854conf_report_error(const char *fmt, ...)
1855{
1856 va_list ap;
1857 char msg[IRCD_BUFSIZE + 1] = { 0 };
1858
1859 va_start(ap, fmt);
afdc068c 1860 rb_vsnprintf(msg, IRCD_BUFSIZE, fmt, ap);
212380e3
AC
1861 va_end(ap);
1862
1863 if (testing_conf)
1864 {
1865 fprintf(stderr, "\"%s\", line %d: %s\n", current_file, lineno + 1, msg);
1866 return;
1867 }
1868
1869 ierror("\"%s\", line %d: %s", current_file, lineno + 1, msg);
1870 sendto_realops_snomask(SNO_GENERAL, L_ALL, "\"%s\", line %d: %s", current_file, lineno + 1, msg);
1871}
1872
1873int
1874conf_start_block(char *block, char *name)
1875{
1876 if((conf_cur_block = find_top_conf(block)) == NULL)
1877 {
1878 conf_report_error("Configuration block '%s' is not defined.", block);
1879 return -1;
1880 }
1881
1882 if(name)
47a03750 1883 conf_cur_block_name = rb_strdup(name);
212380e3
AC
1884 else
1885 conf_cur_block_name = NULL;
1886
1887 if(conf_cur_block->tc_sfunc)
1888 if(conf_cur_block->tc_sfunc(conf_cur_block) < 0)
1889 return -1;
1890
1891 return 0;
1892}
1893
1894int
1895conf_end_block(struct TopConf *tc)
1896{
1897 if(tc->tc_efunc)
1898 return tc->tc_efunc(tc);
1899
637c4932 1900 rb_free(conf_cur_block_name);
212380e3
AC
1901 return 0;
1902}
1903
1904static void
1905conf_set_generic_int(void *data, void *location)
1906{
1907 *((int *) location) = *((unsigned int *) data);
1908}
1909
1910static void
1911conf_set_generic_string(void *data, int len, void *location)
1912{
1913 char **loc = location;
1914 char *input = data;
1915
2e819b6b 1916 if(len && strlen(input) > (unsigned int)len)
212380e3
AC
1917 input[len] = '\0';
1918
637c4932 1919 rb_free(*loc);
47a03750 1920 *loc = rb_strdup(input);
212380e3
AC
1921}
1922
1923int
1924conf_call_set(struct TopConf *tc, char *item, conf_parm_t * value, int type)
1925{
1926 struct ConfEntry *cf;
1927 conf_parm_t *cp;
1928
1929 if(!tc)
1930 return -1;
1931
1932 if((cf = find_conf_item(tc, item)) == NULL)
1933 {
1934 conf_report_error
1935 ("Non-existant configuration setting %s::%s.", tc->tc_name, (char *) item);
1936 return -1;
1937 }
1938
1939 /* if it takes one thing, make sure they only passed one thing,
1940 and handle as needed. */
ed45dfe6 1941 if((value->v.list->type & CF_FLIST) && !(cf->cf_type & CF_FLIST))
212380e3
AC
1942 {
1943 conf_report_error
1944 ("Option %s::%s does not take a list of values.", tc->tc_name, item);
1945 return -1;
1946 }
1947
1948 cp = value->v.list;
1949
1950
1951 if(CF_TYPE(value->v.list->type) != CF_TYPE(cf->cf_type))
1952 {
1953 /* if it expects a string value, but we got a yesno,
1954 * convert it back
1955 */
1956 if((CF_TYPE(value->v.list->type) == CF_YESNO) &&
1957 (CF_TYPE(cf->cf_type) == CF_STRING))
1958 {
1959 value->v.list->type = CF_STRING;
1960
1961 if(cp->v.number == 1)
47a03750 1962 cp->v.string = rb_strdup("yes");
212380e3 1963 else
47a03750 1964 cp->v.string = rb_strdup("no");
212380e3
AC
1965 }
1966
1967 /* maybe it's a CF_TIME and they passed CF_INT --
1968 should still be valid */
1969 else if(!((CF_TYPE(value->v.list->type) == CF_INT) &&
1970 (CF_TYPE(cf->cf_type) == CF_TIME)))
1971 {
1972 conf_report_error
1973 ("Wrong type for %s::%s (expected %s, got %s)",
1974 tc->tc_name, (char *) item,
1975 conf_strtype(cf->cf_type), conf_strtype(value->v.list->type));
1976 return -1;
1977 }
1978 }
1979
1980 if(cf->cf_type & CF_FLIST)
1981 {
1982#if 0
1983 if(cf->cf_arg)
1984 conf_set_generic_list(value->v.list, cf->cf_arg);
1985 else
1986#endif
1987 /* just pass it the extended argument list */
1988 cf->cf_func(value->v.list);
1989 }
1990 else
1991 {
1992 /* it's old-style, needs only one arg */
1993 switch (cf->cf_type)
1994 {
1995 case CF_INT:
1996 case CF_TIME:
1997 case CF_YESNO:
1998 if(cf->cf_arg)
1999 conf_set_generic_int(&cp->v.number, cf->cf_arg);
2000 else
2001 cf->cf_func(&cp->v.number);
2002 break;
2003 case CF_STRING:
2004 case CF_QSTRING:
2005 if(EmptyString(cp->v.string))
2006 conf_report_error("Ignoring %s::%s -- empty field",
2007 tc->tc_name, item);
2008 else if(cf->cf_arg)
2009 conf_set_generic_string(cp->v.string, cf->cf_len, cf->cf_arg);
2010 else
2011 cf->cf_func(cp->v.string);
2012 break;
2013 }
2014 }
2015
2016
2017 return 0;
2018}
2019
2020int
2021add_conf_item(const char *topconf, const char *name, int type, void (*func) (void *))
2022{
2023 struct TopConf *tc;
2024 struct ConfEntry *cf;
2025
2026 if((tc = find_top_conf(topconf)) == NULL)
2027 return -1;
2028
2029 if((cf = find_conf_item(tc, name)) != NULL)
2030 return -1;
2031
eddc2ab6 2032 cf = rb_malloc(sizeof(struct ConfEntry));
212380e3 2033
d7f753cd 2034 cf->cf_name = name;
212380e3
AC
2035 cf->cf_type = type;
2036 cf->cf_func = func;
2037 cf->cf_arg = NULL;
2038
330fc5c1 2039 rb_dlinkAddAlloc(cf, &tc->tc_items);
212380e3
AC
2040
2041 return 0;
2042}
2043
2044int
2045remove_conf_item(const char *topconf, const char *name)
2046{
2047 struct TopConf *tc;
2048 struct ConfEntry *cf;
330fc5c1 2049 rb_dlink_node *ptr;
212380e3
AC
2050
2051 if((tc = find_top_conf(topconf)) == NULL)
2052 return -1;
2053
2054 if((cf = find_conf_item(tc, name)) == NULL)
2055 return -1;
2056
330fc5c1 2057 if((ptr = rb_dlinkFind(cf, &tc->tc_items)) == NULL)
212380e3
AC
2058 return -1;
2059
330fc5c1 2060 rb_dlinkDestroy(ptr, &tc->tc_items);
637c4932 2061 rb_free(cf);
212380e3
AC
2062
2063 return 0;
2064}
2065
2066/* *INDENT-OFF* */
2067static struct ConfEntry conf_serverinfo_table[] =
2068{
2069 { "description", CF_QSTRING, NULL, 0, &ServerInfo.description },
2070 { "network_desc", CF_QSTRING, NULL, 0, &ServerInfo.network_desc },
2071 { "hub", CF_YESNO, NULL, 0, &ServerInfo.hub },
212380e3
AC
2072
2073 { "network_name", CF_QSTRING, conf_set_serverinfo_network_name, 0, NULL },
2074 { "name", CF_QSTRING, conf_set_serverinfo_name, 0, NULL },
2075 { "sid", CF_QSTRING, conf_set_serverinfo_sid, 0, NULL },
2076 { "vhost", CF_QSTRING, conf_set_serverinfo_vhost, 0, NULL },
2077 { "vhost6", CF_QSTRING, conf_set_serverinfo_vhost6, 0, NULL },
2078
8bd5767b
JT
2079 { "ssl_private_key", CF_QSTRING, NULL, 0, &ServerInfo.ssl_private_key },
2080 { "ssl_ca_cert", CF_QSTRING, NULL, 0, &ServerInfo.ssl_ca_cert },
2081 { "ssl_cert", CF_QSTRING, NULL, 0, &ServerInfo.ssl_cert },
2082 { "ssl_dh_params", CF_QSTRING, NULL, 0, &ServerInfo.ssl_dh_params },
c6d72037
VY
2083 { "ssld_count", CF_INT, NULL, 0, &ServerInfo.ssld_count },
2084
101db4c4 2085 { "default_max_clients",CF_INT, NULL, 0, &ServerInfo.default_max_clients },
c2d96fcb 2086
212380e3
AC
2087 { "\0", 0, NULL, 0, NULL }
2088};
2089
2090static struct ConfEntry conf_admin_table[] =
2091{
2092 { "name", CF_QSTRING, NULL, 200, &AdminInfo.name },
2093 { "description",CF_QSTRING, NULL, 200, &AdminInfo.description },
2094 { "email", CF_QSTRING, NULL, 200, &AdminInfo.email },
2095 { "\0", 0, NULL, 0, NULL }
2096};
2097
2098static struct ConfEntry conf_log_table[] =
2099{
2100 { "fname_userlog", CF_QSTRING, NULL, MAXPATHLEN, &ConfigFileEntry.fname_userlog },
2101 { "fname_fuserlog", CF_QSTRING, NULL, MAXPATHLEN, &ConfigFileEntry.fname_fuserlog },
2102 { "fname_operlog", CF_QSTRING, NULL, MAXPATHLEN, &ConfigFileEntry.fname_operlog },
2103 { "fname_foperlog", CF_QSTRING, NULL, MAXPATHLEN, &ConfigFileEntry.fname_foperlog },
2104 { "fname_serverlog", CF_QSTRING, NULL, MAXPATHLEN, &ConfigFileEntry.fname_serverlog },
2105 { "fname_killlog", CF_QSTRING, NULL, MAXPATHLEN, &ConfigFileEntry.fname_killlog },
212380e3
AC
2106 { "fname_klinelog", CF_QSTRING, NULL, MAXPATHLEN, &ConfigFileEntry.fname_klinelog },
2107 { "fname_operspylog", CF_QSTRING, NULL, MAXPATHLEN, &ConfigFileEntry.fname_operspylog },
2108 { "fname_ioerrorlog", CF_QSTRING, NULL, MAXPATHLEN, &ConfigFileEntry.fname_ioerrorlog },
2109 { "\0", 0, NULL, 0, NULL }
2110};
2111
2112static struct ConfEntry conf_operator_table[] =
2113{
2114 { "rsa_public_key_file", CF_QSTRING, conf_set_oper_rsa_public_key_file, 0, NULL },
2115 { "flags", CF_STRING | CF_FLIST, conf_set_oper_flags, 0, NULL },
2116 { "umodes", CF_STRING | CF_FLIST, conf_set_oper_umodes, 0, NULL },
22c3b270 2117 { "privset", CF_QSTRING, conf_set_oper_privset, 0, NULL },
212380e3
AC
2118 { "snomask", CF_QSTRING, conf_set_oper_snomask, 0, NULL },
2119 { "user", CF_QSTRING, conf_set_oper_user, 0, NULL },
2120 { "password", CF_QSTRING, conf_set_oper_password, 0, NULL },
ff31db84 2121 { "fingerprint", CF_QSTRING, conf_set_oper_fingerprint, 0, NULL },
212380e3
AC
2122 { "\0", 0, NULL, 0, NULL }
2123};
2124
f8606875
AC
2125static struct ConfEntry conf_privset_table[] =
2126{
2127 { "extends", CF_QSTRING, conf_set_privset_extends, 0, NULL },
2128 { "privs", CF_STRING | CF_FLIST, conf_set_privset_privs, 0, NULL },
2129 { "\0", 0, NULL, 0, NULL }
2130};
2131
212380e3
AC
2132static struct ConfEntry conf_class_table[] =
2133{
2134 { "ping_time", CF_TIME, conf_set_class_ping_time, 0, NULL },
e33e589c
JT
2135 { "cidr_ipv4_bitlen", CF_INT, conf_set_class_cidr_ipv4_bitlen, 0, NULL },
2136#ifdef RB_IPV6
2137 { "cidr_ipv6_bitlen", CF_INT, conf_set_class_cidr_ipv6_bitlen, 0, NULL },
2138#endif
212380e3
AC
2139 { "number_per_cidr", CF_INT, conf_set_class_number_per_cidr, 0, NULL },
2140 { "number_per_ip", CF_INT, conf_set_class_number_per_ip, 0, NULL },
2141 { "number_per_ip_global", CF_INT,conf_set_class_number_per_ip_global, 0, NULL },
2142 { "number_per_ident", CF_INT, conf_set_class_number_per_ident, 0, NULL },
2143 { "connectfreq", CF_TIME, conf_set_class_connectfreq, 0, NULL },
2144 { "max_number", CF_INT, conf_set_class_max_number, 0, NULL },
2145 { "sendq", CF_TIME, conf_set_class_sendq, 0, NULL },
2146 { "\0", 0, NULL, 0, NULL }
2147};
2148
2149static struct ConfEntry conf_auth_table[] =
2150{
2151 { "user", CF_QSTRING, conf_set_auth_user, 0, NULL },
40c1fd47 2152 { "auth_user", CF_QSTRING, conf_set_auth_auth_user, 0, NULL },
212380e3
AC
2153 { "password", CF_QSTRING, conf_set_auth_passwd, 0, NULL },
2154 { "class", CF_QSTRING, conf_set_auth_class, 0, NULL },
2155 { "spoof", CF_QSTRING, conf_set_auth_spoof, 0, NULL },
2156 { "redirserv", CF_QSTRING, conf_set_auth_redir_serv, 0, NULL },
2157 { "redirport", CF_INT, conf_set_auth_redir_port, 0, NULL },
2158 { "flags", CF_STRING | CF_FLIST, conf_set_auth_flags, 0, NULL },
2159 { "\0", 0, NULL, 0, NULL }
2160};
2161
2162static struct ConfEntry conf_connect_table[] =
2163{
2164 { "send_password", CF_QSTRING, conf_set_connect_send_password, 0, NULL },
2165 { "accept_password", CF_QSTRING, conf_set_connect_accept_password, 0, NULL },
ff0cc1e6 2166 { "fingerprint", CF_QSTRING, conf_set_connect_fingerprint, 0, NULL },
212380e3
AC
2167 { "flags", CF_STRING | CF_FLIST, conf_set_connect_flags, 0, NULL },
2168 { "host", CF_QSTRING, conf_set_connect_host, 0, NULL },
2169 { "vhost", CF_QSTRING, conf_set_connect_vhost, 0, NULL },
2170 { "port", CF_INT, conf_set_connect_port, 0, NULL },
2171 { "aftype", CF_STRING, conf_set_connect_aftype, 0, NULL },
2172 { "hub_mask", CF_QSTRING, conf_set_connect_hub_mask, 0, NULL },
2173 { "leaf_mask", CF_QSTRING, conf_set_connect_leaf_mask, 0, NULL },
2174 { "class", CF_QSTRING, conf_set_connect_class, 0, NULL },
2175 { "\0", 0, NULL, 0, NULL }
2176};
2177
2178static struct ConfEntry conf_general_table[] =
2179{
2180 { "oper_only_umodes", CF_STRING | CF_FLIST, conf_set_general_oper_only_umodes, 0, NULL },
2181 { "oper_umodes", CF_STRING | CF_FLIST, conf_set_general_oper_umodes, 0, NULL },
2182 { "oper_snomask", CF_QSTRING, conf_set_general_oper_snomask, 0, NULL },
2183 { "compression_level", CF_INT, conf_set_general_compression_level, 0, NULL },
2184 { "havent_read_conf", CF_YESNO, conf_set_general_havent_read_conf, 0, NULL },
2185 { "hide_error_messages",CF_STRING, conf_set_general_hide_error_messages,0, NULL },
2186 { "kline_delay", CF_TIME, conf_set_general_kline_delay, 0, NULL },
2187 { "stats_k_oper_only", CF_STRING, conf_set_general_stats_k_oper_only, 0, NULL },
2188 { "stats_i_oper_only", CF_STRING, conf_set_general_stats_i_oper_only, 0, NULL },
2189 { "default_umodes", CF_QSTRING, conf_set_general_default_umodes, 0, NULL },
2190
2191 { "default_operstring", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.default_operstring },
2192 { "default_adminstring",CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.default_adminstring },
2193 { "servicestring", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.servicestring },
2194 { "egdpool_path", CF_QSTRING, NULL, MAXPATHLEN, &ConfigFileEntry.egdpool_path },
2195 { "kline_reason", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.kline_reason },
2196 { "identify_service", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.identifyservice },
2197 { "identify_command", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.identifycommand },
212380e3
AC
2198
2199 { "anti_spam_exit_message_time", CF_TIME, NULL, 0, &ConfigFileEntry.anti_spam_exit_message_time },
2200 { "disable_fake_channels", CF_YESNO, NULL, 0, &ConfigFileEntry.disable_fake_channels },
2201 { "min_nonwildcard_simple", CF_INT, NULL, 0, &ConfigFileEntry.min_nonwildcard_simple },
2202 { "non_redundant_klines", CF_YESNO, NULL, 0, &ConfigFileEntry.non_redundant_klines },
2203 { "tkline_expire_notices", CF_YESNO, NULL, 0, &ConfigFileEntry.tkline_expire_notices },
2204
2205 { "anti_nick_flood", CF_YESNO, NULL, 0, &ConfigFileEntry.anti_nick_flood },
2206 { "burst_away", CF_YESNO, NULL, 0, &ConfigFileEntry.burst_away },
2207 { "caller_id_wait", CF_TIME, NULL, 0, &ConfigFileEntry.caller_id_wait },
2208 { "client_exit", CF_YESNO, NULL, 0, &ConfigFileEntry.client_exit },
2209 { "client_flood", CF_INT, NULL, 0, &ConfigFileEntry.client_flood },
2210 { "collision_fnc", CF_YESNO, NULL, 0, &ConfigFileEntry.collision_fnc },
2211 { "connect_timeout", CF_TIME, NULL, 0, &ConfigFileEntry.connect_timeout },
2212 { "default_floodcount", CF_INT, NULL, 0, &ConfigFileEntry.default_floodcount },
944b0584 2213 { "default_ident_timeout", CF_INT, NULL, 0, &ConfigFileEntry.default_ident_timeout },
212380e3 2214 { "disable_auth", CF_YESNO, NULL, 0, &ConfigFileEntry.disable_auth },
212380e3
AC
2215 { "dots_in_ident", CF_INT, NULL, 0, &ConfigFileEntry.dots_in_ident },
2216 { "failed_oper_notice", CF_YESNO, NULL, 0, &ConfigFileEntry.failed_oper_notice },
212380e3 2217 { "global_snotices", CF_YESNO, NULL, 0, &ConfigFileEntry.global_snotices },
212380e3
AC
2218 { "hide_spoof_ips", CF_YESNO, NULL, 0, &ConfigFileEntry.hide_spoof_ips },
2219 { "dline_with_reason", CF_YESNO, NULL, 0, &ConfigFileEntry.dline_with_reason },
2220 { "kline_with_reason", CF_YESNO, NULL, 0, &ConfigFileEntry.kline_with_reason },
2221 { "map_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.map_oper_only },
2222 { "max_accept", CF_INT, NULL, 0, &ConfigFileEntry.max_accept },
2223 { "max_monitor", CF_INT, NULL, 0, &ConfigFileEntry.max_monitor },
2224 { "max_nick_time", CF_TIME, NULL, 0, &ConfigFileEntry.max_nick_time },
2225 { "max_nick_changes", CF_INT, NULL, 0, &ConfigFileEntry.max_nick_changes },
2226 { "max_targets", CF_INT, NULL, 0, &ConfigFileEntry.max_targets },
2227 { "min_nonwildcard", CF_INT, NULL, 0, &ConfigFileEntry.min_nonwildcard },
2228 { "nick_delay", CF_TIME, NULL, 0, &ConfigFileEntry.nick_delay },
2229 { "no_oper_flood", CF_YESNO, NULL, 0, &ConfigFileEntry.no_oper_flood },
2230 { "operspy_admin_only", CF_YESNO, NULL, 0, &ConfigFileEntry.operspy_admin_only },
2231 { "operspy_dont_care_user_info", CF_YESNO, NULL, 0, &ConfigFileEntry.operspy_dont_care_user_info },
2232 { "pace_wait", CF_TIME, NULL, 0, &ConfigFileEntry.pace_wait },
2233 { "pace_wait_simple", CF_TIME, NULL, 0, &ConfigFileEntry.pace_wait_simple },
2234 { "ping_cookie", CF_YESNO, NULL, 0, &ConfigFileEntry.ping_cookie },
2235 { "reject_after_count", CF_INT, NULL, 0, &ConfigFileEntry.reject_after_count },
2236 { "reject_ban_time", CF_TIME, NULL, 0, &ConfigFileEntry.reject_ban_time },
2237 { "reject_duration", CF_TIME, NULL, 0, &ConfigFileEntry.reject_duration },
43946961
JT
2238 { "throttle_count", CF_INT, NULL, 0, &ConfigFileEntry.throttle_count },
2239 { "throttle_duration", CF_TIME, NULL, 0, &ConfigFileEntry.throttle_duration },
212380e3
AC
2240 { "short_motd", CF_YESNO, NULL, 0, &ConfigFileEntry.short_motd },
2241 { "stats_c_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_c_oper_only },
2242 { "stats_e_disabled", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_e_disabled },
2243 { "stats_h_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_h_oper_only },
2244 { "stats_o_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_o_oper_only },
2245 { "stats_P_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_P_oper_only },
2246 { "stats_y_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_y_oper_only },
2247 { "target_change", CF_YESNO, NULL, 0, &ConfigFileEntry.target_change },
2248 { "ts_max_delta", CF_TIME, NULL, 0, &ConfigFileEntry.ts_max_delta },
2249 { "use_egd", CF_YESNO, NULL, 0, &ConfigFileEntry.use_egd },
2250 { "ts_warn_delta", CF_TIME, NULL, 0, &ConfigFileEntry.ts_warn_delta },
2251 { "use_whois_actually", CF_YESNO, NULL, 0, &ConfigFileEntry.use_whois_actually },
2252 { "warn_no_nline", CF_YESNO, NULL, 0, &ConfigFileEntry.warn_no_nline },
1702b694 2253 { "use_propagated_bans",CF_YESNO, NULL, 0, &ConfigFileEntry.use_propagated_bans },
212380e3
AC
2254 { "\0", 0, NULL, 0, NULL }
2255};
2256
2257static struct ConfEntry conf_channel_table[] =
2258{
2259 { "default_split_user_count", CF_INT, NULL, 0, &ConfigChannel.default_split_user_count },
2260 { "default_split_server_count", CF_INT, NULL, 0, &ConfigChannel.default_split_server_count },
2261 { "burst_topicwho", CF_YESNO, NULL, 0, &ConfigChannel.burst_topicwho },
212380e3
AC
2262 { "kick_on_split_riding", CF_YESNO, NULL, 0, &ConfigChannel.kick_on_split_riding },
2263 { "knock_delay", CF_TIME, NULL, 0, &ConfigChannel.knock_delay },
2264 { "knock_delay_channel",CF_TIME, NULL, 0, &ConfigChannel.knock_delay_channel },
2265 { "max_bans", CF_INT, NULL, 0, &ConfigChannel.max_bans },
2266 { "max_bans_large", CF_INT, NULL, 0, &ConfigChannel.max_bans_large },
2267 { "max_chans_per_user", CF_INT, NULL, 0, &ConfigChannel.max_chans_per_user },
2268 { "no_create_on_split", CF_YESNO, NULL, 0, &ConfigChannel.no_create_on_split },
2269 { "no_join_on_split", CF_YESNO, NULL, 0, &ConfigChannel.no_join_on_split },
6865c0b0 2270 { "only_ascii_channels", CF_YESNO, NULL, 0, &ConfigChannel.only_ascii_channels },
212380e3
AC
2271 { "use_except", CF_YESNO, NULL, 0, &ConfigChannel.use_except },
2272 { "use_invex", CF_YESNO, NULL, 0, &ConfigChannel.use_invex },
2273 { "use_knock", CF_YESNO, NULL, 0, &ConfigChannel.use_knock },
2274 { "use_forward", CF_YESNO, NULL, 0, &ConfigChannel.use_forward },
c2c25552 2275 { "resv_forcepart", CF_YESNO, NULL, 0, &ConfigChannel.resv_forcepart },
717238d2 2276 { "channel_target_change", CF_YESNO, NULL, 0, &ConfigChannel.channel_target_change },
341f971e 2277 { "disable_local_channels", CF_YESNO, NULL, 0, &ConfigChannel.disable_local_channels },
212380e3
AC
2278 { "\0", 0, NULL, 0, NULL }
2279};
2280
2281static struct ConfEntry conf_serverhide_table[] =
2282{
2283 { "disable_hidden", CF_YESNO, NULL, 0, &ConfigServerHide.disable_hidden },
2284 { "flatten_links", CF_YESNO, NULL, 0, &ConfigServerHide.flatten_links },
2285 { "hidden", CF_YESNO, NULL, 0, &ConfigServerHide.hidden },
2286 { "links_delay", CF_TIME, conf_set_serverhide_links_delay, 0, NULL },
2287 { "\0", 0, NULL, 0, NULL }
2288};
2289/* *INDENT-ON* */
2290
2291void
2292newconf_init()
2293{
2294 add_top_conf("modules", NULL, NULL, NULL);
2295 add_conf_item("modules", "path", CF_QSTRING, conf_set_modules_path);
2296 add_conf_item("modules", "module", CF_QSTRING, conf_set_modules_module);
2297
2298 add_top_conf("serverinfo", NULL, NULL, conf_serverinfo_table);
2299 add_top_conf("admin", NULL, NULL, conf_admin_table);
2300 add_top_conf("log", NULL, NULL, conf_log_table);
2301 add_top_conf("operator", conf_begin_oper, conf_end_oper, conf_operator_table);
2302 add_top_conf("class", conf_begin_class, conf_end_class, conf_class_table);
f8606875 2303 add_top_conf("privset", NULL, NULL, conf_privset_table);
212380e3
AC
2304
2305 add_top_conf("listen", conf_begin_listen, conf_end_listen, NULL);
2306 add_conf_item("listen", "port", CF_INT | CF_FLIST, conf_set_listen_port);
c6d72037 2307 add_conf_item("listen", "sslport", CF_INT | CF_FLIST, conf_set_listen_sslport);
212380e3
AC
2308 add_conf_item("listen", "ip", CF_QSTRING, conf_set_listen_address);
2309 add_conf_item("listen", "host", CF_QSTRING, conf_set_listen_address);
2310
2311 add_top_conf("auth", conf_begin_auth, conf_end_auth, conf_auth_table);
2312
2313 add_top_conf("shared", conf_cleanup_shared, conf_cleanup_shared, NULL);
2314 add_conf_item("shared", "oper", CF_QSTRING|CF_FLIST, conf_set_shared_oper);
2315 add_conf_item("shared", "flags", CF_STRING | CF_FLIST, conf_set_shared_flags);
2316
2317 add_top_conf("connect", conf_begin_connect, conf_end_connect, conf_connect_table);
2318
2319 add_top_conf("exempt", NULL, NULL, NULL);
2320 add_conf_item("exempt", "ip", CF_QSTRING, conf_set_exempt_ip);
2321
2322 add_top_conf("cluster", conf_cleanup_cluster, conf_cleanup_cluster, NULL);
2323 add_conf_item("cluster", "name", CF_QSTRING, conf_set_cluster_name);
2324 add_conf_item("cluster", "flags", CF_STRING | CF_FLIST, conf_set_cluster_flags);
2325
2326 add_top_conf("general", NULL, NULL, conf_general_table);
2327 add_top_conf("channel", NULL, NULL, conf_channel_table);
2328 add_top_conf("serverhide", NULL, NULL, conf_serverhide_table);
2329
2330 add_top_conf("service", conf_begin_service, NULL, NULL);
2331 add_conf_item("service", "name", CF_QSTRING, conf_set_service_name);
2332
2333 add_top_conf("alias", conf_begin_alias, conf_end_alias, NULL);
2334 add_conf_item("alias", "name", CF_QSTRING, conf_set_alias_name);
2335 add_conf_item("alias", "target", CF_QSTRING, conf_set_alias_target);
2336
2337 add_top_conf("blacklist", NULL, NULL, NULL);
2338 add_conf_item("blacklist", "host", CF_QSTRING, conf_set_blacklist_host);
0a1e77c2 2339 add_conf_item("blacklist", "type", CF_STRING | CF_FLIST, conf_set_blacklist_type);
212380e3
AC
2340 add_conf_item("blacklist", "reject_reason", CF_QSTRING, conf_set_blacklist_reason);
2341}