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