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