]> jfr.im git - solanum.git/blame - ircd/newconf.c
Normalize snprintf size to use sizeof where possible
[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 1039
48a06ae3
EM
1040 if(yy_aconf->desc)
1041 yy_tmp->desc = rb_strdup(yy_aconf->desc);
1042
212380e3
AC
1043 yy_tmp->flags = yy_aconf->flags;
1044 yy_tmp->port = yy_aconf->port;
1045
1046 collapse(yy_tmp->user);
1047 collapse(yy_tmp->host);
1048
1049 conf_add_class_to_conf(yy_tmp);
1050
0c2ea0c3 1051 if ((found_conf = find_exact_conf_by_address("*", CONF_CLIENT, "*")) && found_conf->spasswd == NULL)
6e5e2b00 1052 conf_report_error("Ignoring redundant auth block (after *@*)");
0c2ea0c3
JT
1053 else if ((found_conf = find_exact_conf_by_address(yy_tmp->host, CONF_CLIENT, yy_tmp->user)) &&
1054 (!found_conf->spasswd || (yy_tmp->spasswd &&
1055 0 == irccmp(found_conf->spasswd, yy_tmp->spasswd))))
6e5e2b00
JT
1056 conf_report_error("Ignoring duplicate auth block for %s@%s",
1057 yy_tmp->user, yy_tmp->host);
1058 else
1059 add_conf_by_address(yy_tmp->host, CONF_CLIENT, yy_tmp->user, yy_tmp->spasswd, yy_tmp);
330fc5c1 1060 rb_dlinkDestroy(ptr, &yy_aconf_list);
212380e3
AC
1061 }
1062
1063 yy_aconf = NULL;
1064 return 0;
1065}
1066
1067static void
1068conf_set_auth_user(void *data)
1069{
1070 struct ConfItem *yy_tmp;
1071 char *p;
1072
1073 /* The first user= line doesn't allocate a new conf */
1074 if(!EmptyString(yy_aconf->host))
1075 {
1076 yy_tmp = make_conf();
1077 yy_tmp->status = CONF_CLIENT;
1078 }
1079 else
1080 yy_tmp = yy_aconf;
1081
1082 if((p = strchr(data, '@')))
1083 {
1084 *p++ = '\0';
1085
47a03750
VY
1086 yy_tmp->user = rb_strdup(data);
1087 yy_tmp->host = rb_strdup(p);
212380e3
AC
1088 }
1089 else
1090 {
47a03750
VY
1091 yy_tmp->user = rb_strdup("*");
1092 yy_tmp->host = rb_strdup(data);
212380e3
AC
1093 }
1094
1095 if(yy_aconf != yy_tmp)
330fc5c1 1096 rb_dlinkAddAlloc(yy_tmp, &yy_aconf_list);
212380e3
AC
1097}
1098
40c1fd47
VY
1099static void
1100conf_set_auth_auth_user(void *data)
1101{
1102 if(yy_aconf->spasswd)
1103 memset(yy_aconf->spasswd, 0, strlen(yy_aconf->spasswd));
1104 rb_free(yy_aconf->spasswd);
1105 yy_aconf->spasswd = rb_strdup(data);
1106}
1107
212380e3
AC
1108static void
1109conf_set_auth_passwd(void *data)
1110{
1111 if(yy_aconf->passwd)
1112 memset(yy_aconf->passwd, 0, strlen(yy_aconf->passwd));
637c4932 1113 rb_free(yy_aconf->passwd);
47a03750 1114 yy_aconf->passwd = rb_strdup(data);
212380e3
AC
1115}
1116
1117static void
1118conf_set_auth_spoof(void *data)
1119{
1120 char *p;
1121 char *user = NULL;
1122 char *host = NULL;
1123
1124 host = data;
1125
1126 /* user@host spoof */
1127 if((p = strchr(host, '@')) != NULL)
1128 {
1129 *p = '\0';
1130 user = data;
1131 host = p+1;
1132
1133 if(EmptyString(user))
1134 {
1135 conf_report_error("Warning -- spoof ident empty.");
1136 return;
1137 }
1138
1139 if(strlen(user) > USERLEN)
1140 {
1141 conf_report_error("Warning -- spoof ident length invalid.");
1142 return;
1143 }
1144
1145 if(!valid_username(user))
1146 {
1147 conf_report_error("Warning -- invalid spoof (ident).");
1148 return;
1149 }
1150
1151 /* this must be restored! */
1152 *p = '@';
1153 }
1154
1155 if(EmptyString(host))
1156 {
1157 conf_report_error("Warning -- spoof host empty.");
1158 return;
1159 }
1160
1161 if(strlen(host) > HOSTLEN)
1162 {
1163 conf_report_error("Warning -- spoof host length invalid.");
1164 return;
1165 }
1166
1167 if(!valid_hostname(host))
1168 {
1169 conf_report_error("Warning -- invalid spoof (host).");
1170 return;
1171 }
1172
27f616dd
JT
1173 rb_free(yy_aconf->info.name);
1174 yy_aconf->info.name = rb_strdup(data);
212380e3
AC
1175 yy_aconf->flags |= CONF_FLAGS_SPOOF_IP;
1176}
1177
48a06ae3
EM
1178static void
1179conf_set_auth_desc(void *data)
1180{
1181 rb_free(yy_aconf->desc);
1182 yy_aconf->desc = rb_strdup(data);
1183}
1184
212380e3
AC
1185static void
1186conf_set_auth_flags(void *data)
1187{
1188 conf_parm_t *args = data;
1189
1190 set_modes_from_table((int *) &yy_aconf->flags, "flag", auth_table, args);
1191}
1192
1193static void
1194conf_set_auth_redir_serv(void *data)
1195{
1196 yy_aconf->flags |= CONF_FLAGS_REDIR;
27f616dd
JT
1197 rb_free(yy_aconf->info.name);
1198 yy_aconf->info.name = rb_strdup(data);
212380e3
AC
1199}
1200
1201static void
1202conf_set_auth_redir_port(void *data)
1203{
1204 int port = *(unsigned int *) data;
1205
1206 yy_aconf->flags |= CONF_FLAGS_REDIR;
1207 yy_aconf->port = port;
1208}
1209
1210static void
1211conf_set_auth_class(void *data)
1212{
637c4932 1213 rb_free(yy_aconf->className);
47a03750 1214 yy_aconf->className = rb_strdup(data);
212380e3
AC
1215}
1216
4d8088c3
EM
1217static void
1218conf_set_auth_umodes(void *data)
1219{
1220 char *umodes = data;
1221
1222 parse_umodes(umodes, &yy_aconf->umodes, &yy_aconf->umodes_mask);
1223}
1224
212380e3
AC
1225static int
1226conf_begin_connect(struct TopConf *tc)
1227{
1228 if(yy_server)
1229 free_server_conf(yy_server);
1230
1231 yy_server = make_server_conf();
1232 yy_server->port = PORTNUM;
5aa453a4 1233 yy_server->flags |= SERVER_TB;
212380e3
AC
1234
1235 if(conf_cur_block_name != NULL)
47a03750 1236 yy_server->name = rb_strdup(conf_cur_block_name);
212380e3
AC
1237
1238 return 0;
1239}
1240
1241static int
1242conf_end_connect(struct TopConf *tc)
1243{
95898abb 1244 if (EmptyString(yy_server->name))
212380e3
AC
1245 {
1246 conf_report_error("Ignoring connect block -- missing name.");
1247 return 0;
1248 }
1249
95898abb
AJ
1250 if (ServerInfo.name != NULL && !irccmp(ServerInfo.name, yy_server->name))
1251 {
1252 conf_report_error("Ignoring connect block for %s -- name is "
1253 "equal to my own name.", yy_server->name);
1254 return 0;
1255 }
1256
1257 if ((EmptyString(yy_server->passwd) || EmptyString(yy_server->spasswd))
1258 && EmptyString(yy_server->certfp))
212380e3 1259 {
95898abb
AJ
1260 conf_report_error("Ignoring connect block for %s -- no "
1261 "fingerprint or password credentials "
1262 "provided.", yy_server->name);
212380e3
AC
1263 return 0;
1264 }
1265
95898abb 1266 if ((yy_server->flags & SERVER_SSL) && EmptyString(yy_server->certfp))
212380e3 1267 {
95898abb
AJ
1268 conf_report_error("Ignoring connect block for %s -- no "
1269 "fingerprint provided for SSL "
1270 "connection.", yy_server->name);
212380e3
AC
1271 return 0;
1272 }
1273
95898abb 1274 if (! (yy_server->flags & SERVER_SSL) && ! EmptyString(yy_server->certfp))
f61d0961 1275 {
95898abb
AJ
1276 conf_report_error("Ignoring connect block for %s -- "
1277 "fingerprint authentication has "
1278 "been requested; but the ssl flag "
1279 "is not set.", yy_server->name);
f61d0961
SA
1280 return 0;
1281 }
1282
95898abb
AJ
1283 if (EmptyString(yy_server->connect_host)
1284 && GET_SS_FAMILY(&yy_server->connect4) != AF_INET
1285 && GET_SS_FAMILY(&yy_server->connect6) != AF_INET6)
212380e3 1286 {
95898abb
AJ
1287 conf_report_error("Ignoring connect block for %s -- missing "
1288 "host.", yy_server->name);
212380e3
AC
1289 return 0;
1290 }
1291
212380e3 1292 add_server_conf(yy_server);
330fc5c1 1293 rb_dlinkAdd(yy_server, &yy_server->node, &server_conf_list);
212380e3
AC
1294
1295 yy_server = NULL;
1296 return 0;
1297}
1298
1299static void
1300conf_set_connect_host(void *data)
1301{
d4214e94
SA
1302 struct rb_sockaddr_storage addr;
1303
17809d2d 1304 if(rb_inet_pton_sock(data, &addr) <= 0)
d4214e94
SA
1305 {
1306 rb_free(yy_server->connect_host);
1307 yy_server->connect_host = rb_strdup(data);
1308 }
1309 else if(GET_SS_FAMILY(&addr) == AF_INET)
1310 {
1311 yy_server->connect4 = addr;
1312 }
d4214e94
SA
1313 else if(GET_SS_FAMILY(&addr) == AF_INET6)
1314 {
1315 yy_server->connect6 = addr;
1316 }
d4214e94
SA
1317 else
1318 {
1319 conf_report_error("Unsupported IP address for server connect host (%s)",
1320 (char *)data);
1321 return;
1322 }
212380e3
AC
1323}
1324
1325static void
1326conf_set_connect_vhost(void *data)
1327{
d4214e94
SA
1328 struct rb_sockaddr_storage addr;
1329
17809d2d 1330 if(rb_inet_pton_sock(data, &addr) <= 0)
d4214e94
SA
1331 {
1332 rb_free(yy_server->bind_host);
1333 yy_server->bind_host = rb_strdup(data);
1334 }
1335 else if(GET_SS_FAMILY(&addr) == AF_INET)
212380e3 1336 {
d4214e94
SA
1337 yy_server->bind4 = addr;
1338 }
d4214e94
SA
1339 else if(GET_SS_FAMILY(&addr) == AF_INET6)
1340 {
1341 yy_server->bind6 = addr;
1342 }
d4214e94
SA
1343 else
1344 {
1345 conf_report_error("Unsupported IP address for server connect vhost (%s)",
1346 (char *)data);
212380e3
AC
1347 return;
1348 }
212380e3
AC
1349}
1350
1351static void
1352conf_set_connect_send_password(void *data)
1353{
1354 if(yy_server->spasswd)
1355 {
1356 memset(yy_server->spasswd, 0, strlen(yy_server->spasswd));
637c4932 1357 rb_free(yy_server->spasswd);
212380e3
AC
1358 }
1359
95898abb
AJ
1360 if (EmptyString((const char *) data))
1361 {
1362 yy_server->spasswd = NULL;
1363 conf_report_warning("Invalid send_password for connect "
1364 "block; must not be empty if provided");
1365 }
1366 else if (strpbrk(data, " :"))
1367 {
1368 yy_server->spasswd = NULL;
1369 conf_report_error("Invalid send_password for connect "
1370 "block; cannot contain spaces or colons");
1371 }
1372 else
1373 yy_server->spasswd = rb_strdup(data);
212380e3
AC
1374}
1375
1376static void
1377conf_set_connect_accept_password(void *data)
1378{
1379 if(yy_server->passwd)
1380 {
1381 memset(yy_server->passwd, 0, strlen(yy_server->passwd));
637c4932 1382 rb_free(yy_server->passwd);
212380e3 1383 }
95898abb
AJ
1384
1385 if (EmptyString((const char *) data))
1386 {
1387 yy_server->passwd = NULL;
1388 conf_report_warning("Invalid accept_password for connect "
1389 "block; must not be empty if provided");
1390 }
1391 else if (strpbrk(data, " :"))
1392 {
1393 yy_server->passwd = NULL;
1394 conf_report_error("Invalid accept_password for connect "
1395 "block; cannot contain spaces or colons");
1396 }
1397 else
1398 yy_server->passwd = rb_strdup(data);
212380e3
AC
1399}
1400
ff0cc1e6
AC
1401static void
1402conf_set_connect_fingerprint(void *data)
1403{
462ae9d7
JT
1404 if (yy_server->certfp)
1405 rb_free(yy_server->certfp);
ff0cc1e6
AC
1406 yy_server->certfp = rb_strdup((char *) data);
1407
1408 /* force SSL to be enabled if fingerprint is enabled. */
1409 yy_server->flags |= SERVER_SSL;
1410}
1411
212380e3
AC
1412static void
1413conf_set_connect_port(void *data)
1414{
1415 int port = *(unsigned int *) data;
1416
1417 if(port < 1)
1418 port = PORTNUM;
1419
1420 yy_server->port = port;
1421}
1422
1423static void
1424conf_set_connect_aftype(void *data)
1425{
1426 char *aft = data;
1427
f956cb0f 1428 if(rb_strcasecmp(aft, "ipv4") == 0)
212380e3 1429 yy_server->aftype = AF_INET;
f956cb0f 1430 else if(rb_strcasecmp(aft, "ipv6") == 0)
212380e3 1431 yy_server->aftype = AF_INET6;
212380e3
AC
1432 else
1433 conf_report_error("connect::aftype '%s' is unknown.", aft);
1434}
1435
1436static void
1437conf_set_connect_flags(void *data)
1438{
1439 conf_parm_t *args = data;
1440
212380e3
AC
1441 set_modes_from_table(&yy_server->flags, "flag", connect_table, args);
1442}
1443
212380e3
AC
1444static void
1445conf_set_connect_class(void *data)
1446{
637c4932 1447 rb_free(yy_server->class_name);
47a03750 1448 yy_server->class_name = rb_strdup(data);
212380e3
AC
1449}
1450
1451static void
1452conf_set_exempt_ip(void *data)
1453{
1454 struct ConfItem *yy_tmp;
7d9e8e9d 1455 int masktype = parse_netmask_strict(data, NULL, NULL);
212380e3 1456
7d9e8e9d 1457 if(masktype != HM_IPV4 && masktype != HM_IPV6)
212380e3
AC
1458 {
1459 conf_report_error("Ignoring exempt -- invalid exempt::ip.");
1460 return;
1461 }
1462
1463 yy_tmp = make_conf();
47a03750
VY
1464 yy_tmp->passwd = rb_strdup("*");
1465 yy_tmp->host = rb_strdup(data);
212380e3 1466 yy_tmp->status = CONF_EXEMPTDLINE;
40c1fd47 1467 add_conf_by_address(yy_tmp->host, CONF_EXEMPTDLINE, NULL, NULL, yy_tmp);
212380e3
AC
1468}
1469
1cf798be
EK
1470static void
1471conf_set_secure_ip(void *data)
1472{
1473 struct ConfItem *yy_tmp;
1474 int masktype = parse_netmask_strict(data, NULL, NULL);
1475
1476 if(masktype != HM_IPV4 && masktype != HM_IPV6)
1477 {
1478 conf_report_error("Ignoring secure -- invalid secure::ip.");
1479 return;
1480 }
1481
1482 yy_tmp = make_conf();
1483 yy_tmp->passwd = rb_strdup("*");
1484 yy_tmp->host = rb_strdup(data);
1485 yy_tmp->status = CONF_SECURE;
1486 add_conf_by_address(yy_tmp->host, CONF_SECURE, NULL, NULL, yy_tmp);
1487}
1488
212380e3
AC
1489static int
1490conf_cleanup_cluster(struct TopConf *tc)
1491{
637c4932 1492 rb_dlink_node *ptr, *next_ptr;
212380e3 1493
637c4932 1494 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_cluster_list.head)
212380e3
AC
1495 {
1496 free_remote_conf(ptr->data);
330fc5c1 1497 rb_dlinkDestroy(ptr, &yy_cluster_list);
212380e3
AC
1498 }
1499
1500 if(yy_shared != NULL)
1501 {
1502 free_remote_conf(yy_shared);
1503 yy_shared = NULL;
1504 }
1505
1506 return 0;
1507}
1508
1509static void
1510conf_set_cluster_name(void *data)
1511{
1512 if(yy_shared != NULL)
1513 free_remote_conf(yy_shared);
1514
1515 yy_shared = make_remote_conf();
47a03750 1516 yy_shared->server = rb_strdup(data);
330fc5c1 1517 rb_dlinkAddAlloc(yy_shared, &yy_cluster_list);
212380e3
AC
1518
1519 yy_shared = NULL;
1520}
1521
1522static void
1523conf_set_cluster_flags(void *data)
1524{
1525 conf_parm_t *args = data;
1526 int flags = 0;
637c4932 1527 rb_dlink_node *ptr, *next_ptr;
212380e3
AC
1528
1529 if(yy_shared != NULL)
1530 free_remote_conf(yy_shared);
1531
1532 set_modes_from_table(&flags, "flag", cluster_table, args);
1533
637c4932 1534 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_cluster_list.head)
212380e3
AC
1535 {
1536 yy_shared = ptr->data;
1537 yy_shared->flags = flags;
330fc5c1
AC
1538 rb_dlinkAddTail(yy_shared, &yy_shared->node, &cluster_conf_list);
1539 rb_dlinkDestroy(ptr, &yy_cluster_list);
212380e3
AC
1540 }
1541
1542 yy_shared = NULL;
1543}
1544
1545static void
1546conf_set_general_havent_read_conf(void *data)
1547{
1548 if(*(unsigned int *) data)
1549 {
1550 conf_report_error("You haven't read your config file properly.");
1551 conf_report_error
1552 ("There is a line in the example conf that will kill your server if not removed.");
1553 conf_report_error
1554 ("Consider actually reading/editing the conf file, and removing this line.");
1555 if (!testing_conf)
1556 exit(0);
1557 }
1558}
1559
1560static void
1561conf_set_general_hide_error_messages(void *data)
1562{
1563 char *val = data;
1564
f956cb0f 1565 if(rb_strcasecmp(val, "yes") == 0)
212380e3 1566 ConfigFileEntry.hide_error_messages = 2;
f956cb0f 1567 else if(rb_strcasecmp(val, "opers") == 0)
212380e3 1568 ConfigFileEntry.hide_error_messages = 1;
f956cb0f 1569 else if(rb_strcasecmp(val, "no") == 0)
212380e3
AC
1570 ConfigFileEntry.hide_error_messages = 0;
1571 else
1572 conf_report_error("Invalid setting '%s' for general::hide_error_messages.", val);
1573}
1574
212380e3
AC
1575static void
1576conf_set_general_stats_k_oper_only(void *data)
1577{
1578 char *val = data;
1579
f956cb0f 1580 if(rb_strcasecmp(val, "yes") == 0)
212380e3 1581 ConfigFileEntry.stats_k_oper_only = 2;
f956cb0f 1582 else if(rb_strcasecmp(val, "masked") == 0)
212380e3 1583 ConfigFileEntry.stats_k_oper_only = 1;
f956cb0f 1584 else if(rb_strcasecmp(val, "no") == 0)
212380e3
AC
1585 ConfigFileEntry.stats_k_oper_only = 0;
1586 else
1587 conf_report_error("Invalid setting '%s' for general::stats_k_oper_only.", val);
1588}
1589
1590static void
1591conf_set_general_stats_i_oper_only(void *data)
1592{
1593 char *val = data;
1594
f956cb0f 1595 if(rb_strcasecmp(val, "yes") == 0)
212380e3 1596 ConfigFileEntry.stats_i_oper_only = 2;
f956cb0f 1597 else if(rb_strcasecmp(val, "masked") == 0)
212380e3 1598 ConfigFileEntry.stats_i_oper_only = 1;
f956cb0f 1599 else if(rb_strcasecmp(val, "no") == 0)
212380e3
AC
1600 ConfigFileEntry.stats_i_oper_only = 0;
1601 else
1602 conf_report_error("Invalid setting '%s' for general::stats_i_oper_only.", val);
1603}
1604
63ab1dd6
EK
1605static void
1606conf_set_general_stats_l_oper_only(void *data)
1607{
1608 char *val = data;
1609
1610 if(rb_strcasecmp(val, "yes") == 0)
1611 ConfigFileEntry.stats_l_oper_only = STATS_L_OPER_ONLY_YES;
1612 else if(rb_strcasecmp(val, "self") == 0)
1613 ConfigFileEntry.stats_l_oper_only = STATS_L_OPER_ONLY_SELF;
1614 else if(rb_strcasecmp(val, "no") == 0)
1615 ConfigFileEntry.stats_l_oper_only = STATS_L_OPER_ONLY_NO;
1616 else
1617 conf_report_error("Invalid setting '%s' for general::stats_l_oper_only.", val);
1618}
1619
212380e3
AC
1620static void
1621conf_set_general_default_umodes(void *data)
1622{
4d8088c3 1623 char *umodes = data;
212380e3 1624
4d8088c3 1625 parse_umodes(umodes, &ConfigFileEntry.default_umodes, NULL);
212380e3
AC
1626}
1627
1628static void
1629conf_set_general_oper_umodes(void *data)
1630{
1631 set_modes_from_table(&ConfigFileEntry.oper_umodes, "umode", umode_table, data);
1632}
1633
13d8f0ed
AC
1634static void
1635conf_set_general_certfp_method(void *data)
1636{
1637 char *method = data;
1638
f018ed84 1639 if (!rb_strcasecmp(method, CERTFP_NAME_CERT_SHA1))
cf430c1a 1640 ConfigFileEntry.certfp_method = RB_SSL_CERTFP_METH_CERT_SHA1;
f018ed84 1641 else if (!rb_strcasecmp(method, CERTFP_NAME_CERT_SHA256))
cf430c1a 1642 ConfigFileEntry.certfp_method = RB_SSL_CERTFP_METH_CERT_SHA256;
f018ed84 1643 else if (!rb_strcasecmp(method, CERTFP_NAME_CERT_SHA512))
cf430c1a 1644 ConfigFileEntry.certfp_method = RB_SSL_CERTFP_METH_CERT_SHA512;
f018ed84 1645 else if (!rb_strcasecmp(method, CERTFP_NAME_SPKI_SHA256))
cf430c1a 1646 ConfigFileEntry.certfp_method = RB_SSL_CERTFP_METH_SPKI_SHA256;
f018ed84 1647 else if (!rb_strcasecmp(method, CERTFP_NAME_SPKI_SHA512))
cf430c1a 1648 ConfigFileEntry.certfp_method = RB_SSL_CERTFP_METH_SPKI_SHA512;
13d8f0ed
AC
1649 else
1650 {
cf430c1a 1651 ConfigFileEntry.certfp_method = RB_SSL_CERTFP_METH_CERT_SHA1;
13d8f0ed
AC
1652 conf_report_error("Ignoring general::certfp_method -- bogus certfp method %s", method);
1653 }
1654}
1655
212380e3
AC
1656static void
1657conf_set_general_oper_only_umodes(void *data)
1658{
1659 set_modes_from_table(&ConfigFileEntry.oper_only_umodes, "umode", umode_table, data);
1660}
1661
1662static void
1663conf_set_general_oper_snomask(void *data)
1664{
1665 char *pm;
1666 int what = MODE_ADD, flag;
1667
1668 ConfigFileEntry.oper_snomask = 0;
1669 for (pm = (char *) data; *pm; pm++)
1670 {
1671 switch (*pm)
1672 {
1673 case '+':
1674 what = MODE_ADD;
1675 break;
1676 case '-':
1677 what = MODE_DEL;
1678 break;
1679
1680 default:
1681 if ((flag = snomask_modes[(unsigned char) *pm]))
1682 {
1683 if (what == MODE_ADD)
1684 ConfigFileEntry.oper_snomask |= flag;
1685 else
1686 ConfigFileEntry.oper_snomask &= ~flag;
1687 }
1688 break;
1689 }
1690 }
1691}
1692
6ac21a70
EK
1693static void
1694conf_set_general_hidden_caps(void *data)
1695{
1696 size_t n = 0;
1697
1698 for (conf_parm_t *arg = data; arg; arg = arg->next)
1699 n += 1;
1700
1701 if (ConfigFileEntry.hidden_caps != NULL)
1702 {
1703 for (n = 0; ConfigFileEntry.hidden_caps[n] != NULL; n++)
1704 rb_free(ConfigFileEntry.hidden_caps[n]);
1705 rb_free(ConfigFileEntry.hidden_caps);
1706 }
1707 ConfigFileEntry.hidden_caps = rb_malloc(sizeof *ConfigFileEntry.hidden_caps * (n + 1));
1708
1709 n = 0;
1710 for (conf_parm_t *arg = data; arg; arg = arg->next)
1711 {
1712 ConfigFileEntry.hidden_caps[n++] = rb_strdup(arg->v.string);
1713 }
1714 ConfigFileEntry.hidden_caps[n] = NULL;
1715}
1716
212380e3
AC
1717static void
1718conf_set_serverhide_links_delay(void *data)
1719{
1720 int val = *(unsigned int *) data;
1721
212380e3
AC
1722 ConfigServerHide.links_delay = val;
1723}
1724
212380e3
AC
1725static void
1726conf_set_service_name(void *data)
1727{
212380e3
AC
1728 const char *s;
1729 char *tmp;
1730 int dots = 0;
1731
1732 for(s = data; *s != '\0'; s++)
1733 {
1734 if(!IsServChar(*s))
1735 {
1736 conf_report_error("Ignoring service::name "
1737 "-- bogus servername.");
1738 return;
1739 }
1740 else if(*s == '.')
1741 dots++;
1742 }
1743
1744 if(!dots)
1745 {
1746 conf_report_error("Ignoring service::name -- must contain '.'");
1747 return;
1748 }
1749
47a03750 1750 tmp = rb_strdup(data);
330fc5c1 1751 rb_dlinkAddAlloc(tmp, &service_list);
212380e3
AC
1752}
1753
212380e3
AC
1754static int
1755conf_begin_alias(struct TopConf *tc)
1756{
eddc2ab6 1757 yy_alias = rb_malloc(sizeof(struct alias_entry));
212380e3
AC
1758
1759 if (conf_cur_block_name != NULL)
47a03750 1760 yy_alias->name = rb_strdup(conf_cur_block_name);
212380e3
AC
1761
1762 yy_alias->flags = 0;
212380e3
AC
1763
1764 return 0;
1765}
1766
1767static int
1768conf_end_alias(struct TopConf *tc)
1769{
212380e3
AC
1770 if (yy_alias == NULL)
1771 return -1;
1772
1773 if (yy_alias->name == NULL)
1774 {
1775 conf_report_error("Ignoring alias -- must have a name.");
1776
637c4932 1777 rb_free(yy_alias);
212380e3
AC
1778
1779 return -1;
1780 }
1781
1782 if (yy_alias->target == NULL)
1783 {
1784 conf_report_error("Ignoring alias -- must have a target.");
1785
637c4932 1786 rb_free(yy_alias);
212380e3
AC
1787
1788 return -1;
1789 }
1790
a4bf26dd 1791 rb_dictionary_add(alias_dict, yy_alias->name, yy_alias);
212380e3
AC
1792
1793 return 0;
1794}
1795
1796static void
1797conf_set_alias_name(void *data)
1798{
1799 if (data == NULL || yy_alias == NULL) /* this shouldn't ever happen */
1800 return;
1801
47a03750 1802 yy_alias->name = rb_strdup(data);
212380e3
AC
1803}
1804
1805static void
1806conf_set_alias_target(void *data)
1807{
1808 if (data == NULL || yy_alias == NULL) /* this shouldn't ever happen */
1809 return;
1810
47a03750 1811 yy_alias->target = rb_strdup(data);
212380e3
AC
1812}
1813
63eb8567
AC
1814static void
1815conf_set_channel_autochanmodes(void *data)
1816{
1817 char *pm;
1818 int what = MODE_ADD;
1819
1820 ConfigChannel.autochanmodes = 0;
1821 for (pm = (char *) data; *pm; pm++)
1822 {
1823 switch (*pm)
1824 {
1825 case '+':
1826 what = MODE_ADD;
1827 break;
1828 case '-':
1829 what = MODE_DEL;
1830 break;
1831
1832 default:
1833 if (chmode_table[(unsigned char) *pm].set_func == chm_simple)
1834 {
1835 if (what == MODE_ADD)
1836 ConfigChannel.autochanmodes |= chmode_table[(unsigned char) *pm].mode_type;
1837 else
1838 ConfigChannel.autochanmodes &= ~chmode_table[(unsigned char) *pm].mode_type;
1839 }
1840 else
1841 {
4952e40b 1842 conf_report_error("channel::autochanmodes -- Invalid channel mode %c", *pm);
63eb8567
AC
1843 continue;
1844 }
1845 break;
1846 }
1847 }
1848}
1849
3c93d380 1850/* XXX for below */
7f24f506 1851static void conf_set_dnsbl_entry_reason(void *data);
3c93d380 1852
d3f6b808
EM
1853#define IPTYPE_IPV4 1
1854#define IPTYPE_IPV6 2
1855
7f24f506
AC
1856static int
1857conf_warn_blacklist_deprecation(struct TopConf *tc)
1858{
1859 conf_report_error("blacklist{} blocks have been deprecated -- use dnsbl{} blocks instead.");
1860 return 0;
1861}
1862
212380e3 1863static void
7f24f506 1864conf_set_dnsbl_entry_host(void *data)
212380e3 1865{
7f24f506 1866 if (yy_dnsbl_entry_host)
3c93d380 1867 {
7f24f506
AC
1868 conf_report_error("dnsbl::host %s overlaps existing host %s",
1869 (char *)data, yy_dnsbl_entry_host);
3c93d380
EM
1870
1871 /* Cleanup */
7f24f506 1872 conf_set_dnsbl_entry_reason(NULL);
3c93d380
EM
1873 return;
1874 }
1875
7f24f506
AC
1876 yy_dnsbl_entry_iptype |= IPTYPE_IPV4;
1877 yy_dnsbl_entry_host = rb_strdup(data);
212380e3
AC
1878}
1879
0a1e77c2 1880static void
7f24f506 1881conf_set_dnsbl_entry_type(void *data)
0a1e77c2
EM
1882{
1883 conf_parm_t *args = data;
1884
1885 /* Don't assume we have either if we got here */
7f24f506 1886 yy_dnsbl_entry_iptype = 0;
0a1e77c2
EM
1887
1888 for (; args; args = args->next)
1889 {
f956cb0f 1890 if (!rb_strcasecmp(args->v.string, "ipv4"))
7f24f506 1891 yy_dnsbl_entry_iptype |= IPTYPE_IPV4;
f956cb0f 1892 else if (!rb_strcasecmp(args->v.string, "ipv6"))
7f24f506 1893 yy_dnsbl_entry_iptype |= IPTYPE_IPV6;
0a1e77c2 1894 else
7f24f506 1895 conf_report_error("dnsbl::type has unknown address family %s",
0a1e77c2
EM
1896 args->v.string);
1897 }
1898
1899 /* If we have neither, just default to IPv4 */
7f24f506 1900 if (!yy_dnsbl_entry_iptype)
0a1e77c2 1901 {
7f24f506
AC
1902 conf_report_warning("dnsbl::type has neither IPv4 nor IPv6 (defaulting to IPv4)");
1903 yy_dnsbl_entry_iptype = IPTYPE_IPV4;
0a1e77c2
EM
1904 }
1905}
1906
3c93d380 1907static void
7f24f506 1908conf_set_dnsbl_entry_matches(void *data)
3c93d380
EM
1909{
1910 conf_parm_t *args = data;
d3f6b808 1911 enum filter_t { FILTER_NONE, FILTER_ALL, FILTER_LAST };
3c93d380
EM
1912
1913 for (; args; args = args->next)
1914 {
3c93d380
EM
1915 char *str = args->v.string;
1916 char *p;
d3f6b808 1917 enum filter_t type = FILTER_LAST;
3c93d380
EM
1918
1919 if (CF_TYPE(args->type) != CF_QSTRING)
1920 {
7f24f506 1921 conf_report_error("dnsbl::matches -- must be quoted string");
3c93d380
EM
1922 continue;
1923 }
1924
1925 if (str == NULL)
1926 {
7f24f506 1927 conf_report_error("dnsbl::matches -- invalid entry");
3c93d380
EM
1928 continue;
1929 }
1930
1931 if (strlen(str) > HOSTIPLEN)
1932 {
7f24f506 1933 conf_report_error("dnsbl::matches has an entry too long: %s",
3c93d380
EM
1934 str);
1935 continue;
1936 }
1937
1938 for (p = str; *p != '\0'; p++)
1939 {
1940 /* Check for validity */
1941 if (*p == '.')
d3f6b808
EM
1942 type = FILTER_ALL;
1943 else if (!isdigit((unsigned char)*p))
3c93d380 1944 {
7f24f506 1945 conf_report_error("dnsbl::matches has invalid IP match entry %s",
3c93d380 1946 str);
d3f6b808 1947 type = FILTER_NONE;
3c93d380
EM
1948 break;
1949 }
1950 }
1951
d3f6b808 1952 if (type == FILTER_ALL)
3c93d380
EM
1953 {
1954 /* Basic IP sanity check */
1955 struct rb_sockaddr_storage tmp;
1956 if (rb_inet_pton(AF_INET, str, &tmp) <= 0)
1957 {
7f24f506 1958 conf_report_error("dnsbl::matches has invalid IP match entry %s",
3c93d380
EM
1959 str);
1960 continue;
1961 }
1962 }
d3f6b808 1963 else if (type == FILTER_LAST)
3c93d380
EM
1964 {
1965 /* Verify it's the correct length */
1966 if (strlen(str) > 3)
1967 {
7f24f506 1968 conf_report_error("dnsbl::matches has invalid octet match entry %s",
3c93d380
EM
1969 str);
1970 continue;
1971 }
1972 }
1973 else
1974 {
1975 continue; /* Invalid entry */
1976 }
1977
7f24f506 1978 rb_dlinkAddAlloc(rb_strdup(str), &yy_dnsbl_entry_filters);
3c93d380
EM
1979 }
1980}
1981
212380e3 1982static void
7f24f506 1983conf_set_dnsbl_entry_reason(void *data)
212380e3 1984{
3c93d380 1985 rb_dlink_node *ptr, *nptr;
212380e3 1986
7f24f506 1987 if (yy_dnsbl_entry_host && data)
212380e3 1988 {
7f24f506
AC
1989 yy_dnsbl_entry_reason = rb_strdup(data);
1990 if (yy_dnsbl_entry_iptype & IPTYPE_IPV6)
0a1e77c2 1991 {
a6a30cc7 1992 /* Make sure things fit (magic number 64 = alnum count + dots)
771dcfad
EM
1993 * 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
1994 */
7f24f506 1995 if ((64 + strlen(yy_dnsbl_entry_host)) > IRCD_RES_HOSTLEN)
0a1e77c2 1996 {
7f24f506
AC
1997 conf_report_error("dnsbl::host %s results in IPv6 queries that are too long",
1998 yy_dnsbl_entry_host);
0a1e77c2
EM
1999 goto cleanup_bl;
2000 }
2001 }
2002 /* Avoid doing redundant check, IPv6 is bigger than IPv4 --Elizabeth */
7f24f506 2003 if ((yy_dnsbl_entry_iptype & IPTYPE_IPV4) && !(yy_dnsbl_entry_iptype & IPTYPE_IPV6))
0a1e77c2 2004 {
a6a30cc7
EM
2005 /* Make sure things fit for worst case (magic number 16 = number of nums + dots)
2006 * Example: 127.127.127.127.in-addr.arpa
771dcfad 2007 */
7f24f506 2008 if ((16 + strlen(yy_dnsbl_entry_host)) > IRCD_RES_HOSTLEN)
0a1e77c2 2009 {
7f24f506
AC
2010 conf_report_error("dnsbl::host %s results in IPv4 queries that are too long",
2011 yy_dnsbl_entry_host);
0a1e77c2
EM
2012 goto cleanup_bl;
2013 }
2014 }
2015
7f24f506 2016 add_dnsbl_entry(yy_dnsbl_entry_host, yy_dnsbl_entry_reason, yy_dnsbl_entry_iptype, &yy_dnsbl_entry_filters);
3c93d380 2017 }
0a1e77c2
EM
2018
2019cleanup_bl:
7f24f506 2020 RB_DLINK_FOREACH_SAFE(ptr, nptr, yy_dnsbl_entry_filters.head)
e232f35c 2021 {
d3f6b808 2022 rb_free(ptr->data);
7f24f506 2023 rb_dlinkDestroy(ptr, &yy_dnsbl_entry_filters);
212380e3 2024 }
3c93d380 2025
7f24f506 2026 yy_dnsbl_entry_filters = (rb_dlink_list){ NULL, NULL, 0 };
d3f6b808 2027
7f24f506
AC
2028 rb_free(yy_dnsbl_entry_host);
2029 rb_free(yy_dnsbl_entry_reason);
2030 yy_dnsbl_entry_host = NULL;
2031 yy_dnsbl_entry_reason = NULL;
2032 yy_dnsbl_entry_iptype = 0;
212380e3
AC
2033}
2034
51fa2ab8
EM
2035
2036struct opm_scanner
2037{
2038 const char *type;
2039 uint16_t port;
2040
2041 rb_dlink_node node;
2042};
2043
8275e270
EM
2044static int
2045conf_begin_opm(struct TopConf *tc)
2046{
2047 yy_opm_address_ipv4 = yy_opm_address_ipv6 = NULL;
9bba0f61 2048 yy_opm_port_ipv4 = yy_opm_port_ipv6 = yy_opm_timeout = 0;
5c5296c8 2049 delete_opm_proxy_scanner_all();
5e9a3f86 2050 delete_opm_listener_all();
8275e270
EM
2051 return 0;
2052}
2053
2054static int
2055conf_end_opm(struct TopConf *tc)
2056{
51fa2ab8
EM
2057 rb_dlink_node *ptr, *nptr;
2058 bool fail = false;
2059
ffa79a95 2060 if(rb_dlink_list_length(&yy_opm_scanner_list) == 0)
51fa2ab8 2061 {
c1f4db3f 2062 conf_report_error("No opm scanners configured -- disabling opm.");
51fa2ab8
EM
2063 fail = true;
2064 goto end;
2065 }
2066
8275e270
EM
2067 if(yy_opm_port_ipv4 > 0)
2068 {
2069 if(yy_opm_address_ipv4 != NULL)
5e9a3f86 2070 conf_create_opm_listener(yy_opm_address_ipv4, yy_opm_port_ipv4);
8275e270
EM
2071 else
2072 {
2073 char ip[HOSTIPLEN];
d4214e94 2074 if(!rb_inet_ntop_sock((struct sockaddr *)&ServerInfo.bind4, ip, sizeof(ip)))
8275e270 2075 conf_report_error("No opm::listen_ipv4 nor serverinfo::vhost directive; cannot listen on IPv4");
8275e270 2076 else
5e9a3f86 2077 conf_create_opm_listener(ip, yy_opm_port_ipv4);
8275e270
EM
2078 }
2079 }
2080
2081 if(yy_opm_port_ipv6 > 0)
2082 {
2083 if(yy_opm_address_ipv6 != NULL)
5e9a3f86 2084 conf_create_opm_listener(yy_opm_address_ipv6, yy_opm_port_ipv6);
8275e270
EM
2085 else
2086 {
2087 char ip[HOSTIPLEN];
d4214e94 2088 if(!rb_inet_ntop_sock((struct sockaddr *)&ServerInfo.bind6, ip, sizeof(ip)))
8275e270 2089 conf_report_error("No opm::listen_ipv6 nor serverinfo::vhost directive; cannot listen on IPv6");
8275e270 2090 else
5e9a3f86 2091 conf_create_opm_listener(ip, yy_opm_port_ipv6);
8275e270
EM
2092 }
2093 }
2094
51fa2ab8
EM
2095 /* If there's no listeners... */
2096 fail = (yy_opm_port_ipv4 == 0 || yy_opm_port_ipv6 == 0);
c1f4db3f 2097 if(!fail && yy_opm_timeout > 0 && yy_opm_timeout < 60)
9bba0f61
EM
2098 /* Send timeout */
2099 set_authd_timeout("opm_timeout", yy_opm_timeout);
c1f4db3f
EM
2100 else if(fail)
2101 conf_report_error("No opm listeners -- disabling");
2102 else if(yy_opm_timeout <= 0 || yy_opm_timeout >= 60)
2103 conf_report_error("opm::timeout value is invalid -- ignoring");
9bba0f61 2104
51fa2ab8
EM
2105end:
2106 RB_DLINK_FOREACH_SAFE(ptr, nptr, yy_opm_scanner_list.head)
2107 {
2108 struct opm_scanner *scanner = ptr->data;
2109
2110 if(!fail)
2111 create_opm_proxy_scanner(scanner->type, scanner->port);
2112
2113 rb_dlinkDelete(&scanner->node, &yy_opm_scanner_list);
2114 rb_free(scanner);
2115 }
2116
34bc7cae
EM
2117 if(!fail)
2118 opm_check_enable(true);
2119
8275e270
EM
2120 rb_free(yy_opm_address_ipv4);
2121 rb_free(yy_opm_address_ipv6);
2122 return 0;
2123}
2124
9bba0f61
EM
2125static void
2126conf_set_opm_timeout(void *data)
2127{
2128 int timeout = *((int *)data);
2129
2130 if(timeout <= 0 || timeout > 60)
2131 {
2132 conf_report_error("opm::timeout value %d is bogus, ignoring", timeout);
2133 return;
2134 }
2135
2136 yy_opm_timeout = timeout;
2137}
51fa2ab8 2138
8275e270 2139static void
51fa2ab8 2140conf_set_opm_listen_address_both(void *data, bool ipv6)
8275e270
EM
2141{
2142 struct rb_sockaddr_storage addr;
51fa2ab8 2143 const char *confstr = (ipv6 ? "opm::listen_ipv6" : "opm::listen_ipv4");
8275e270
EM
2144 char *ip = data;
2145
17809d2d 2146 if(!rb_inet_pton_sock(ip, &addr))
8275e270 2147 {
51fa2ab8 2148 conf_report_error("%s is an invalid address: %s", confstr, ip);
8275e270
EM
2149 return;
2150 }
2151
51fa2ab8 2152 if(ipv6)
8275e270 2153 {
51fa2ab8
EM
2154 if(GET_SS_FAMILY(&addr) != AF_INET6)
2155 {
2156 conf_report_error("%s is of the wrong address type: %s", confstr, ip);
2157 return;
2158 }
2159
2160 if(yy_opm_address_ipv6 != NULL)
2161 {
2162 conf_report_error("%s overwrites previous address %s", confstr, ip);
2163 return;
2164 }
2165
2166 yy_opm_address_ipv6 = rb_strdup(ip);
51fa2ab8
EM
2167 }
2168 else
8275e270 2169 {
51fa2ab8
EM
2170 if(GET_SS_FAMILY(&addr) != AF_INET)
2171 {
2172 conf_report_error("%s is of the wrong address type: %s", confstr, ip);
2173 return;
2174 }
2175
2176 if(yy_opm_address_ipv4 != NULL)
2177 {
2178 conf_report_error("%s overwrites previous address %s", confstr, ip);
2179 return;
2180 }
2181
2182 yy_opm_address_ipv4 = rb_strdup(ip);
8275e270 2183 }
51fa2ab8 2184}
8275e270 2185
51fa2ab8
EM
2186static void
2187conf_set_opm_listen_address_ipv4(void *data)
2188{
2189 conf_set_opm_listen_address_both(data, false);
8275e270
EM
2190}
2191
2192static void
2193conf_set_opm_listen_address_ipv6(void *data)
2194{
51fa2ab8
EM
2195 conf_set_opm_listen_address_both(data, true);
2196}
8275e270 2197
51fa2ab8
EM
2198static void
2199conf_set_opm_listen_port_both(void *data, bool ipv6)
2200{
2201 int port = *((int *)data);
2202 const char *confstr = (ipv6 ? "opm::port_ipv6" : "opm::port_ipv4");
8275e270 2203
51fa2ab8 2204 if(port > 65535 || port <= 0)
8275e270 2205 {
51fa2ab8 2206 conf_report_error("%s is out of range: %d", confstr, port);
8275e270
EM
2207 return;
2208 }
2209
51fa2ab8 2210 if(ipv6)
8275e270 2211 {
51fa2ab8
EM
2212 if(yy_opm_port_ipv4)
2213 {
2214 conf_report_error("%s overwrites existing port %hu",
2215 confstr, yy_opm_port_ipv4);
2216 return;
2217 }
2218
2219 yy_opm_port_ipv4 = port;
8275e270 2220 }
51fa2ab8
EM
2221 else
2222 {
2223 if(yy_opm_port_ipv6)
2224 {
2225 conf_report_error("%s overwrites existing port %hu",
2226 confstr, yy_opm_port_ipv6);
2227 return;
2228 }
8275e270 2229
51fa2ab8
EM
2230 yy_opm_port_ipv6 = port;
2231 }
8275e270
EM
2232}
2233
2234static void
2235conf_set_opm_listen_port_ipv4(void *data)
2236{
51fa2ab8 2237 conf_set_opm_listen_port_both(data, false);
8275e270
EM
2238}
2239
2240static void
2241conf_set_opm_listen_port_ipv6(void *data)
2242{
51fa2ab8 2243 conf_set_opm_listen_port_both(data, true);
8275e270
EM
2244}
2245
2246static void
2247conf_set_opm_listen_port(void *data)
2248{
51fa2ab8
EM
2249 conf_set_opm_listen_port_both(data, true);
2250 conf_set_opm_listen_port_both(data, false);
2251}
8275e270 2252
51fa2ab8
EM
2253static void
2254conf_set_opm_scan_ports_all(void *data, const char *node, const char *type)
2255{
2256 conf_parm_t *args = data;
2257 for (; args; args = args->next)
8275e270 2258 {
51fa2ab8
EM
2259 rb_dlink_node *ptr;
2260 bool dup = false;
8275e270 2261
51fa2ab8
EM
2262 if(CF_TYPE(args->type) != CF_INT)
2263 {
2264 conf_report_error("%s argument is not an integer -- ignoring.", node);
2265 continue;
2266 }
5e9a3f86 2267
51fa2ab8
EM
2268 if(args->v.number > 65535 || args->v.number <= 0)
2269 {
2270 conf_report_error("%s argument is not an integer between 1 and 65535 -- ignoring.", node);
2271 continue;
2272 }
8275e270 2273
51fa2ab8
EM
2274 /* Check for duplicates */
2275 RB_DLINK_FOREACH(ptr, yy_opm_scanner_list.head)
2276 {
2277 struct opm_scanner *scanner = ptr->data;
2278
2279 if(scanner->port == args->v.number && strcmp(type, scanner->type) == 0)
2280 {
2281 conf_report_error("%s argument is duplicate", node);
2282 dup = true;
2283 break;
2284 }
2285 }
2286
2287 if(!dup)
2288 {
2289 struct opm_scanner *scanner = rb_malloc(sizeof(struct opm_scanner));
2290 scanner->port = args->v.number;
2291 scanner->type = type;
2292 rb_dlinkAdd(scanner, &scanner->node, &yy_opm_scanner_list);
2293 }
8275e270 2294 }
51fa2ab8 2295}
8275e270 2296
51fa2ab8
EM
2297static void
2298conf_set_opm_scan_ports_socks4(void *data)
2299{
2300 conf_set_opm_scan_ports_all(data, "opm::socks4_ports", "socks4");
2301}
8275e270 2302
51fa2ab8
EM
2303static void
2304conf_set_opm_scan_ports_socks5(void *data)
2305{
2306 conf_set_opm_scan_ports_all(data, "opm::socks5_ports", "socks5");
8275e270
EM
2307}
2308
fabe8b94
EM
2309static void
2310conf_set_opm_scan_ports_httpconnect(void *data)
2311{
2312 conf_set_opm_scan_ports_all(data, "opm::httpconnect_ports", "httpconnect");
2313}
2314
eb0814b3
EM
2315static void
2316conf_set_opm_scan_ports_httpsconnect(void *data)
2317{
2318 conf_set_opm_scan_ports_all(data, "opm::httpsconnect_ports", "httpsconnect");
2319}
2320
212380e3
AC
2321/* public functions */
2322
2323
2324void
2325conf_report_error(const char *fmt, ...)
2326{
2327 va_list ap;
82236a2a 2328 char msg[BUFSIZE + 1] = { 0 };
212380e3
AC
2329
2330 va_start(ap, fmt);
57aa79ac 2331 vsnprintf(msg, sizeof msg, fmt, ap);
212380e3
AC
2332 va_end(ap);
2333
2334 if (testing_conf)
2335 {
2336 fprintf(stderr, "\"%s\", line %d: %s\n", current_file, lineno + 1, msg);
2337 return;
2338 }
2339
2340 ierror("\"%s\", line %d: %s", current_file, lineno + 1, msg);
a9227555 2341 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "error: \"%s\", line %d: %s", current_file, lineno + 1, msg);
d84acbce
AC
2342}
2343
2344void
2345conf_report_warning(const char *fmt, ...)
2346{
2347 va_list ap;
82236a2a 2348 char msg[BUFSIZE + 1] = { 0 };
d84acbce
AC
2349
2350 va_start(ap, fmt);
57aa79ac 2351 vsnprintf(msg, sizeof msg, fmt, ap);
d84acbce
AC
2352 va_end(ap);
2353
2354 if (testing_conf)
2355 {
2356 fprintf(stderr, "\"%s\", line %d: %s\n", current_file, lineno + 1, msg);
2357 return;
2358 }
2359
2360 iwarn("\"%s\", line %d: %s", current_file, lineno + 1, msg);
a9227555 2361 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "warning: \"%s\", line %d: %s", current_file, lineno + 1, msg);
212380e3
AC
2362}
2363
2364int
2365conf_start_block(char *block, char *name)
2366{
2367 if((conf_cur_block = find_top_conf(block)) == NULL)
2368 {
2369 conf_report_error("Configuration block '%s' is not defined.", block);
2370 return -1;
2371 }
2372
2373 if(name)
47a03750 2374 conf_cur_block_name = rb_strdup(name);
212380e3
AC
2375 else
2376 conf_cur_block_name = NULL;
2377
2378 if(conf_cur_block->tc_sfunc)
2379 if(conf_cur_block->tc_sfunc(conf_cur_block) < 0)
2380 return -1;
2381
2382 return 0;
2383}
2384
2385int
2386conf_end_block(struct TopConf *tc)
2387{
e12981c0 2388 int ret = 0;
212380e3 2389 if(tc->tc_efunc)
e12981c0 2390 ret = tc->tc_efunc(tc);
212380e3 2391
637c4932 2392 rb_free(conf_cur_block_name);
e12981c0
KB
2393 conf_cur_block_name = NULL;
2394 return ret;
212380e3
AC
2395}
2396
2397static void
2398conf_set_generic_int(void *data, void *location)
2399{
2400 *((int *) location) = *((unsigned int *) data);
2401}
2402
2403static void
2404conf_set_generic_string(void *data, int len, void *location)
2405{
2406 char **loc = location;
2407 char *input = data;
2408
2e819b6b 2409 if(len && strlen(input) > (unsigned int)len)
212380e3
AC
2410 input[len] = '\0';
2411
637c4932 2412 rb_free(*loc);
47a03750 2413 *loc = rb_strdup(input);
212380e3
AC
2414}
2415
2416int
dceac3e4 2417conf_call_set(struct TopConf *tc, char *item, conf_parm_t * value)
212380e3
AC
2418{
2419 struct ConfEntry *cf;
2420 conf_parm_t *cp;
2421
2422 if(!tc)
2423 return -1;
2424
2425 if((cf = find_conf_item(tc, item)) == NULL)
2426 {
2427 conf_report_error
ffa79a95 2428 ("Non-existent configuration setting %s::%s.", tc->tc_name, (char *) item);
212380e3
AC
2429 return -1;
2430 }
2431
2432 /* if it takes one thing, make sure they only passed one thing,
2433 and handle as needed. */
ed45dfe6 2434 if((value->v.list->type & CF_FLIST) && !(cf->cf_type & CF_FLIST))
212380e3
AC
2435 {
2436 conf_report_error
2437 ("Option %s::%s does not take a list of values.", tc->tc_name, item);
2438 return -1;
2439 }
2440
2441 cp = value->v.list;
2442
2443
2444 if(CF_TYPE(value->v.list->type) != CF_TYPE(cf->cf_type))
2445 {
023c36ae 2446 /* if it expects a string value, but we got a yesno,
212380e3
AC
2447 * convert it back
2448 */
2449 if((CF_TYPE(value->v.list->type) == CF_YESNO) &&
2450 (CF_TYPE(cf->cf_type) == CF_STRING))
2451 {
2452 value->v.list->type = CF_STRING;
2453
2454 if(cp->v.number == 1)
47a03750 2455 cp->v.string = rb_strdup("yes");
212380e3 2456 else
47a03750 2457 cp->v.string = rb_strdup("no");
212380e3
AC
2458 }
2459
2460 /* maybe it's a CF_TIME and they passed CF_INT --
2461 should still be valid */
2462 else if(!((CF_TYPE(value->v.list->type) == CF_INT) &&
2463 (CF_TYPE(cf->cf_type) == CF_TIME)))
2464 {
2465 conf_report_error
2466 ("Wrong type for %s::%s (expected %s, got %s)",
2467 tc->tc_name, (char *) item,
2468 conf_strtype(cf->cf_type), conf_strtype(value->v.list->type));
2469 return -1;
2470 }
2471 }
2472
2473 if(cf->cf_type & CF_FLIST)
2474 {
2475#if 0
2476 if(cf->cf_arg)
2477 conf_set_generic_list(value->v.list, cf->cf_arg);
2478 else
2479#endif
2480 /* just pass it the extended argument list */
2481 cf->cf_func(value->v.list);
2482 }
2483 else
2484 {
2485 /* it's old-style, needs only one arg */
2486 switch (cf->cf_type)
2487 {
2488 case CF_INT:
2489 case CF_TIME:
2490 case CF_YESNO:
2491 if(cf->cf_arg)
2492 conf_set_generic_int(&cp->v.number, cf->cf_arg);
2493 else
2494 cf->cf_func(&cp->v.number);
2495 break;
2496 case CF_STRING:
2497 case CF_QSTRING:
2498 if(EmptyString(cp->v.string))
2499 conf_report_error("Ignoring %s::%s -- empty field",
2500 tc->tc_name, item);
2501 else if(cf->cf_arg)
2502 conf_set_generic_string(cp->v.string, cf->cf_len, cf->cf_arg);
2503 else
2504 cf->cf_func(cp->v.string);
2505 break;
2506 }
2507 }
2508
2509
2510 return 0;
2511}
2512
2513int
2514add_conf_item(const char *topconf, const char *name, int type, void (*func) (void *))
2515{
2516 struct TopConf *tc;
2517 struct ConfEntry *cf;
2518
2519 if((tc = find_top_conf(topconf)) == NULL)
2520 return -1;
2521
12edf3e3 2522 if(find_conf_item(tc, name) != NULL)
212380e3
AC
2523 return -1;
2524
eddc2ab6 2525 cf = rb_malloc(sizeof(struct ConfEntry));
212380e3 2526
d7f753cd 2527 cf->cf_name = name;
212380e3
AC
2528 cf->cf_type = type;
2529 cf->cf_func = func;
2530 cf->cf_arg = NULL;
2531
330fc5c1 2532 rb_dlinkAddAlloc(cf, &tc->tc_items);
212380e3
AC
2533
2534 return 0;
2535}
2536
2537int
2538remove_conf_item(const char *topconf, const char *name)
2539{
2540 struct TopConf *tc;
2541 struct ConfEntry *cf;
330fc5c1 2542 rb_dlink_node *ptr;
212380e3
AC
2543
2544 if((tc = find_top_conf(topconf)) == NULL)
2545 return -1;
2546
2547 if((cf = find_conf_item(tc, name)) == NULL)
2548 return -1;
2549
330fc5c1 2550 if((ptr = rb_dlinkFind(cf, &tc->tc_items)) == NULL)
212380e3
AC
2551 return -1;
2552
330fc5c1 2553 rb_dlinkDestroy(ptr, &tc->tc_items);
637c4932 2554 rb_free(cf);
212380e3
AC
2555
2556 return 0;
2557}
2558
2559/* *INDENT-OFF* */
2560static struct ConfEntry conf_serverinfo_table[] =
2561{
2562 { "description", CF_QSTRING, NULL, 0, &ServerInfo.description },
212380e3
AC
2563
2564 { "network_name", CF_QSTRING, conf_set_serverinfo_network_name, 0, NULL },
2565 { "name", CF_QSTRING, conf_set_serverinfo_name, 0, NULL },
2566 { "sid", CF_QSTRING, conf_set_serverinfo_sid, 0, NULL },
2567 { "vhost", CF_QSTRING, conf_set_serverinfo_vhost, 0, NULL },
2568 { "vhost6", CF_QSTRING, conf_set_serverinfo_vhost6, 0, NULL },
2569
8bd5767b
JT
2570 { "ssl_private_key", CF_QSTRING, NULL, 0, &ServerInfo.ssl_private_key },
2571 { "ssl_ca_cert", CF_QSTRING, NULL, 0, &ServerInfo.ssl_ca_cert },
023c36ae 2572 { "ssl_cert", CF_QSTRING, NULL, 0, &ServerInfo.ssl_cert },
8bd5767b 2573 { "ssl_dh_params", CF_QSTRING, NULL, 0, &ServerInfo.ssl_dh_params },
c1725bda 2574 { "ssl_cipher_list", CF_QSTRING, NULL, 0, &ServerInfo.ssl_cipher_list },
c6d72037
VY
2575 { "ssld_count", CF_INT, NULL, 0, &ServerInfo.ssld_count },
2576
101db4c4 2577 { "default_max_clients",CF_INT, NULL, 0, &ServerInfo.default_max_clients },
c2d96fcb 2578
b583faf9
AC
2579 { "nicklen", CF_INT, conf_set_serverinfo_nicklen, 0, NULL },
2580
212380e3
AC
2581 { "\0", 0, NULL, 0, NULL }
2582};
2583
2584static struct ConfEntry conf_admin_table[] =
2585{
2586 { "name", CF_QSTRING, NULL, 200, &AdminInfo.name },
2587 { "description",CF_QSTRING, NULL, 200, &AdminInfo.description },
2588 { "email", CF_QSTRING, NULL, 200, &AdminInfo.email },
2589 { "\0", 0, NULL, 0, NULL }
2590};
2591
2592static struct ConfEntry conf_log_table[] =
2593{
d74fa5b5
JT
2594 { "fname_userlog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_userlog },
2595 { "fname_fuserlog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_fuserlog },
2596 { "fname_operlog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_operlog },
2597 { "fname_foperlog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_foperlog },
2598 { "fname_serverlog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_serverlog },
2599 { "fname_killlog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_killlog },
2600 { "fname_klinelog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_klinelog },
2601 { "fname_operspylog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_operspylog },
2602 { "fname_ioerrorlog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_ioerrorlog },
212380e3
AC
2603 { "\0", 0, NULL, 0, NULL }
2604};
2605
2606static struct ConfEntry conf_operator_table[] =
2607{
2608 { "rsa_public_key_file", CF_QSTRING, conf_set_oper_rsa_public_key_file, 0, NULL },
2609 { "flags", CF_STRING | CF_FLIST, conf_set_oper_flags, 0, NULL },
2610 { "umodes", CF_STRING | CF_FLIST, conf_set_oper_umodes, 0, NULL },
22c3b270 2611 { "privset", CF_QSTRING, conf_set_oper_privset, 0, NULL },
212380e3
AC
2612 { "snomask", CF_QSTRING, conf_set_oper_snomask, 0, NULL },
2613 { "user", CF_QSTRING, conf_set_oper_user, 0, NULL },
2614 { "password", CF_QSTRING, conf_set_oper_password, 0, NULL },
ff31db84 2615 { "fingerprint", CF_QSTRING, conf_set_oper_fingerprint, 0, NULL },
212380e3
AC
2616 { "\0", 0, NULL, 0, NULL }
2617};
2618
f8606875
AC
2619static struct ConfEntry conf_privset_table[] =
2620{
2621 { "extends", CF_QSTRING, conf_set_privset_extends, 0, NULL },
2622 { "privs", CF_STRING | CF_FLIST, conf_set_privset_privs, 0, NULL },
2623 { "\0", 0, NULL, 0, NULL }
2624};
2625
212380e3
AC
2626static struct ConfEntry conf_class_table[] =
2627{
2628 { "ping_time", CF_TIME, conf_set_class_ping_time, 0, NULL },
e33e589c 2629 { "cidr_ipv4_bitlen", CF_INT, conf_set_class_cidr_ipv4_bitlen, 0, NULL },
e33e589c 2630 { "cidr_ipv6_bitlen", CF_INT, conf_set_class_cidr_ipv6_bitlen, 0, NULL },
212380e3
AC
2631 { "number_per_cidr", CF_INT, conf_set_class_number_per_cidr, 0, NULL },
2632 { "number_per_ip", CF_INT, conf_set_class_number_per_ip, 0, NULL },
2633 { "number_per_ip_global", CF_INT,conf_set_class_number_per_ip_global, 0, NULL },
2634 { "number_per_ident", CF_INT, conf_set_class_number_per_ident, 0, NULL },
2635 { "connectfreq", CF_TIME, conf_set_class_connectfreq, 0, NULL },
2636 { "max_number", CF_INT, conf_set_class_max_number, 0, NULL },
7c7065b0 2637 { "max_autoconn", CF_INT, conf_set_class_max_autoconn, 0, NULL },
212380e3
AC
2638 { "sendq", CF_TIME, conf_set_class_sendq, 0, NULL },
2639 { "\0", 0, NULL, 0, NULL }
2640};
2641
2642static struct ConfEntry conf_auth_table[] =
2643{
2644 { "user", CF_QSTRING, conf_set_auth_user, 0, NULL },
40c1fd47 2645 { "auth_user", CF_QSTRING, conf_set_auth_auth_user, 0, NULL },
212380e3
AC
2646 { "password", CF_QSTRING, conf_set_auth_passwd, 0, NULL },
2647 { "class", CF_QSTRING, conf_set_auth_class, 0, NULL },
2648 { "spoof", CF_QSTRING, conf_set_auth_spoof, 0, NULL },
2649 { "redirserv", CF_QSTRING, conf_set_auth_redir_serv, 0, NULL },
2650 { "redirport", CF_INT, conf_set_auth_redir_port, 0, NULL },
2651 { "flags", CF_STRING | CF_FLIST, conf_set_auth_flags, 0, NULL },
4d8088c3 2652 { "umodes", CF_QSTRING, conf_set_auth_umodes, 0, NULL},
48a06ae3 2653 { "description",CF_QSTRING, conf_set_auth_desc, 0, NULL},
212380e3
AC
2654 { "\0", 0, NULL, 0, NULL }
2655};
2656
2657static struct ConfEntry conf_connect_table[] =
2658{
2659 { "send_password", CF_QSTRING, conf_set_connect_send_password, 0, NULL },
2660 { "accept_password", CF_QSTRING, conf_set_connect_accept_password, 0, NULL },
ff0cc1e6 2661 { "fingerprint", CF_QSTRING, conf_set_connect_fingerprint, 0, NULL },
212380e3
AC
2662 { "flags", CF_STRING | CF_FLIST, conf_set_connect_flags, 0, NULL },
2663 { "host", CF_QSTRING, conf_set_connect_host, 0, NULL },
2664 { "vhost", CF_QSTRING, conf_set_connect_vhost, 0, NULL },
2665 { "port", CF_INT, conf_set_connect_port, 0, NULL },
2666 { "aftype", CF_STRING, conf_set_connect_aftype, 0, NULL },
212380e3
AC
2667 { "class", CF_QSTRING, conf_set_connect_class, 0, NULL },
2668 { "\0", 0, NULL, 0, NULL }
2669};
2670
2671static struct ConfEntry conf_general_table[] =
2672{
2673 { "oper_only_umodes", CF_STRING | CF_FLIST, conf_set_general_oper_only_umodes, 0, NULL },
2674 { "oper_umodes", CF_STRING | CF_FLIST, conf_set_general_oper_umodes, 0, NULL },
2675 { "oper_snomask", CF_QSTRING, conf_set_general_oper_snomask, 0, NULL },
212380e3
AC
2676 { "havent_read_conf", CF_YESNO, conf_set_general_havent_read_conf, 0, NULL },
2677 { "hide_error_messages",CF_STRING, conf_set_general_hide_error_messages,0, NULL },
212380e3 2678 { "stats_i_oper_only", CF_STRING, conf_set_general_stats_i_oper_only, 0, NULL },
63ab1dd6
EK
2679 { "stats_k_oper_only", CF_STRING, conf_set_general_stats_k_oper_only, 0, NULL },
2680 { "stats_l_oper_only", CF_STRING, conf_set_general_stats_l_oper_only, 0, NULL },
212380e3
AC
2681 { "default_umodes", CF_QSTRING, conf_set_general_default_umodes, 0, NULL },
2682
2683 { "default_operstring", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.default_operstring },
2684 { "default_adminstring",CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.default_adminstring },
2685 { "servicestring", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.servicestring },
212380e3
AC
2686 { "kline_reason", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.kline_reason },
2687 { "identify_service", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.identifyservice },
2688 { "identify_command", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.identifycommand },
7d33cce8 2689 { "sasl_service", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.sasl_service },
212380e3
AC
2690
2691 { "anti_spam_exit_message_time", CF_TIME, NULL, 0, &ConfigFileEntry.anti_spam_exit_message_time },
2692 { "disable_fake_channels", CF_YESNO, NULL, 0, &ConfigFileEntry.disable_fake_channels },
2693 { "min_nonwildcard_simple", CF_INT, NULL, 0, &ConfigFileEntry.min_nonwildcard_simple },
2694 { "non_redundant_klines", CF_YESNO, NULL, 0, &ConfigFileEntry.non_redundant_klines },
2695 { "tkline_expire_notices", CF_YESNO, NULL, 0, &ConfigFileEntry.tkline_expire_notices },
2696
6ac21a70
EK
2697 { "hidden_caps", CF_QSTRING | CF_FLIST, conf_set_general_hidden_caps, 0, NULL },
2698
212380e3
AC
2699 { "anti_nick_flood", CF_YESNO, NULL, 0, &ConfigFileEntry.anti_nick_flood },
2700 { "burst_away", CF_YESNO, NULL, 0, &ConfigFileEntry.burst_away },
2701 { "caller_id_wait", CF_TIME, NULL, 0, &ConfigFileEntry.caller_id_wait },
2702 { "client_exit", CF_YESNO, NULL, 0, &ConfigFileEntry.client_exit },
212380e3 2703 { "collision_fnc", CF_YESNO, NULL, 0, &ConfigFileEntry.collision_fnc },
330692a1 2704 { "resv_fnc", CF_YESNO, NULL, 0, &ConfigFileEntry.resv_fnc },
b3a00991 2705 { "post_registration_delay", CF_TIME, NULL, 0, &ConfigFileEntry.post_registration_delay },
212380e3
AC
2706 { "connect_timeout", CF_TIME, NULL, 0, &ConfigFileEntry.connect_timeout },
2707 { "default_floodcount", CF_INT, NULL, 0, &ConfigFileEntry.default_floodcount },
944b0584 2708 { "default_ident_timeout", CF_INT, NULL, 0, &ConfigFileEntry.default_ident_timeout },
212380e3 2709 { "disable_auth", CF_YESNO, NULL, 0, &ConfigFileEntry.disable_auth },
212380e3
AC
2710 { "dots_in_ident", CF_INT, NULL, 0, &ConfigFileEntry.dots_in_ident },
2711 { "failed_oper_notice", CF_YESNO, NULL, 0, &ConfigFileEntry.failed_oper_notice },
212380e3 2712 { "global_snotices", CF_YESNO, NULL, 0, &ConfigFileEntry.global_snotices },
212380e3
AC
2713 { "hide_spoof_ips", CF_YESNO, NULL, 0, &ConfigFileEntry.hide_spoof_ips },
2714 { "dline_with_reason", CF_YESNO, NULL, 0, &ConfigFileEntry.dline_with_reason },
2715 { "kline_with_reason", CF_YESNO, NULL, 0, &ConfigFileEntry.kline_with_reason },
9914c013 2716 { "hide_tkdline_duration", CF_YESNO, NULL, 0, &ConfigFileEntry.hide_tkdline_duration },
212380e3
AC
2717 { "map_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.map_oper_only },
2718 { "max_accept", CF_INT, NULL, 0, &ConfigFileEntry.max_accept },
2719 { "max_monitor", CF_INT, NULL, 0, &ConfigFileEntry.max_monitor },
2720 { "max_nick_time", CF_TIME, NULL, 0, &ConfigFileEntry.max_nick_time },
2721 { "max_nick_changes", CF_INT, NULL, 0, &ConfigFileEntry.max_nick_changes },
2722 { "max_targets", CF_INT, NULL, 0, &ConfigFileEntry.max_targets },
2723 { "min_nonwildcard", CF_INT, NULL, 0, &ConfigFileEntry.min_nonwildcard },
2724 { "nick_delay", CF_TIME, NULL, 0, &ConfigFileEntry.nick_delay },
2725 { "no_oper_flood", CF_YESNO, NULL, 0, &ConfigFileEntry.no_oper_flood },
2726 { "operspy_admin_only", CF_YESNO, NULL, 0, &ConfigFileEntry.operspy_admin_only },
2727 { "operspy_dont_care_user_info", CF_YESNO, NULL, 0, &ConfigFileEntry.operspy_dont_care_user_info },
2728 { "pace_wait", CF_TIME, NULL, 0, &ConfigFileEntry.pace_wait },
2729 { "pace_wait_simple", CF_TIME, NULL, 0, &ConfigFileEntry.pace_wait_simple },
2730 { "ping_cookie", CF_YESNO, NULL, 0, &ConfigFileEntry.ping_cookie },
2731 { "reject_after_count", CF_INT, NULL, 0, &ConfigFileEntry.reject_after_count },
2732 { "reject_ban_time", CF_TIME, NULL, 0, &ConfigFileEntry.reject_ban_time },
2733 { "reject_duration", CF_TIME, NULL, 0, &ConfigFileEntry.reject_duration },
43946961
JT
2734 { "throttle_count", CF_INT, NULL, 0, &ConfigFileEntry.throttle_count },
2735 { "throttle_duration", CF_TIME, NULL, 0, &ConfigFileEntry.throttle_duration },
212380e3
AC
2736 { "short_motd", CF_YESNO, NULL, 0, &ConfigFileEntry.short_motd },
2737 { "stats_c_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_c_oper_only },
2738 { "stats_e_disabled", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_e_disabled },
212380e3
AC
2739 { "stats_o_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_o_oper_only },
2740 { "stats_P_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_P_oper_only },
2741 { "stats_y_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_y_oper_only },
2742 { "target_change", CF_YESNO, NULL, 0, &ConfigFileEntry.target_change },
2743 { "ts_max_delta", CF_TIME, NULL, 0, &ConfigFileEntry.ts_max_delta },
212380e3
AC
2744 { "ts_warn_delta", CF_TIME, NULL, 0, &ConfigFileEntry.ts_warn_delta },
2745 { "use_whois_actually", CF_YESNO, NULL, 0, &ConfigFileEntry.use_whois_actually },
2746 { "warn_no_nline", CF_YESNO, NULL, 0, &ConfigFileEntry.warn_no_nline },
1702b694 2747 { "use_propagated_bans",CF_YESNO, NULL, 0, &ConfigFileEntry.use_propagated_bans },
e6e54763
SB
2748 { "client_flood_max_lines", CF_INT, NULL, 0, &ConfigFileEntry.client_flood_max_lines },
2749 { "client_flood_burst_rate", CF_INT, NULL, 0, &ConfigFileEntry.client_flood_burst_rate },
2750 { "client_flood_burst_max", CF_INT, NULL, 0, &ConfigFileEntry.client_flood_burst_max },
2751 { "client_flood_message_num", CF_INT, NULL, 0, &ConfigFileEntry.client_flood_message_num },
2752 { "client_flood_message_time", CF_INT, NULL, 0, &ConfigFileEntry.client_flood_message_time },
e88a1f1b 2753 { "max_ratelimit_tokens", CF_INT, NULL, 0, &ConfigFileEntry.max_ratelimit_tokens },
d42e6915 2754 { "away_interval", CF_INT, NULL, 0, &ConfigFileEntry.away_interval },
71c95533 2755 { "hide_opers_in_whois", CF_YESNO, NULL, 0, &ConfigFileEntry.hide_opers_in_whois },
1123eefc 2756 { "hide_opers", CF_YESNO, NULL, 0, &ConfigFileEntry.hide_opers },
13d8f0ed 2757 { "certfp_method", CF_STRING, conf_set_general_certfp_method, 0, NULL },
b674a619 2758 { "drain_reason", CF_QSTRING, NULL, BUFSIZE, &ConfigFileEntry.drain_reason },
05bc814d 2759 { "sasl_only_client_message", CF_QSTRING, NULL, BUFSIZE, &ConfigFileEntry.sasl_only_client_message },
e4a62bbc
MD
2760 { "identd_only_client_message", CF_QSTRING, NULL, BUFSIZE, &ConfigFileEntry.identd_only_client_message },
2761 { "sctp_forbidden_client_message", CF_QSTRING, NULL, BUFSIZE, &ConfigFileEntry.sctp_forbidden_client_message },
2762 { "ssltls_only_client_message", CF_QSTRING, NULL, BUFSIZE, &ConfigFileEntry.ssltls_only_client_message },
2763 { "not_authorised_client_message", CF_QSTRING, NULL, BUFSIZE, &ConfigFileEntry.not_authorised_client_message },
2764 { "illegal_hostname_client_message", CF_QSTRING, NULL, BUFSIZE, &ConfigFileEntry.not_authorised_client_message },
2765 { "server_full_client_message", CF_QSTRING, NULL, BUFSIZE, &ConfigFileEntry.server_full_client_message },
2766 { "illegal_name_long_client_message", CF_QSTRING, NULL, BUFSIZE, &ConfigFileEntry.illegal_name_long_client_message },
2767 { "illegal_name_short_client_message", CF_QSTRING, NULL, BUFSIZE, &ConfigFileEntry.illegal_name_short_client_message },
fff4f763 2768 { "tls_ciphers_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.tls_ciphers_oper_only },
40ecb85a 2769 { "oper_secure_only", CF_YESNO, NULL, 0, &ConfigFileEntry.oper_secure_only },
212380e3
AC
2770 { "\0", 0, NULL, 0, NULL }
2771};
2772
2773static struct ConfEntry conf_channel_table[] =
2774{
2775 { "default_split_user_count", CF_INT, NULL, 0, &ConfigChannel.default_split_user_count },
2776 { "default_split_server_count", CF_INT, NULL, 0, &ConfigChannel.default_split_server_count },
2777 { "burst_topicwho", CF_YESNO, NULL, 0, &ConfigChannel.burst_topicwho },
212380e3
AC
2778 { "kick_on_split_riding", CF_YESNO, NULL, 0, &ConfigChannel.kick_on_split_riding },
2779 { "knock_delay", CF_TIME, NULL, 0, &ConfigChannel.knock_delay },
2780 { "knock_delay_channel",CF_TIME, NULL, 0, &ConfigChannel.knock_delay_channel },
2781 { "max_bans", CF_INT, NULL, 0, &ConfigChannel.max_bans },
2782 { "max_bans_large", CF_INT, NULL, 0, &ConfigChannel.max_bans_large },
2783 { "max_chans_per_user", CF_INT, NULL, 0, &ConfigChannel.max_chans_per_user },
a4721f5e 2784 { "max_chans_per_user_large", CF_INT, NULL, 0, &ConfigChannel.max_chans_per_user_large },
212380e3
AC
2785 { "no_create_on_split", CF_YESNO, NULL, 0, &ConfigChannel.no_create_on_split },
2786 { "no_join_on_split", CF_YESNO, NULL, 0, &ConfigChannel.no_join_on_split },
6865c0b0 2787 { "only_ascii_channels", CF_YESNO, NULL, 0, &ConfigChannel.only_ascii_channels },
212380e3
AC
2788 { "use_except", CF_YESNO, NULL, 0, &ConfigChannel.use_except },
2789 { "use_invex", CF_YESNO, NULL, 0, &ConfigChannel.use_invex },
2da6f6eb 2790 { "use_forward", CF_YESNO, NULL, 0, &ConfigChannel.use_forward },
212380e3 2791 { "use_knock", CF_YESNO, NULL, 0, &ConfigChannel.use_knock },
c2c25552 2792 { "resv_forcepart", CF_YESNO, NULL, 0, &ConfigChannel.resv_forcepart },
717238d2 2793 { "channel_target_change", CF_YESNO, NULL, 0, &ConfigChannel.channel_target_change },
341f971e 2794 { "disable_local_channels", CF_YESNO, NULL, 0, &ConfigChannel.disable_local_channels },
63eb8567 2795 { "autochanmodes", CF_QSTRING, conf_set_channel_autochanmodes, 0, NULL },
d513218a 2796 { "displayed_usercount", CF_INT, NULL, 0, &ConfigChannel.displayed_usercount },
14482679 2797 { "strip_topic_colors", CF_YESNO, NULL, 0, &ConfigChannel.strip_topic_colors },
04e5ed6c 2798 { "opmod_send_statusmsg", CF_YESNO, NULL, 0, &ConfigChannel.opmod_send_statusmsg },
dfeba655 2799 { "ip_bans_through_vhost", CF_YESNO, NULL, 0, &ConfigChannel.ip_bans_through_vhost },
212380e3
AC
2800 { "\0", 0, NULL, 0, NULL }
2801};
2802
2803static struct ConfEntry conf_serverhide_table[] =
2804{
2805 { "disable_hidden", CF_YESNO, NULL, 0, &ConfigServerHide.disable_hidden },
2806 { "flatten_links", CF_YESNO, NULL, 0, &ConfigServerHide.flatten_links },
2807 { "hidden", CF_YESNO, NULL, 0, &ConfigServerHide.hidden },
2808 { "links_delay", CF_TIME, conf_set_serverhide_links_delay, 0, NULL },
2809 { "\0", 0, NULL, 0, NULL }
2810};
2811/* *INDENT-ON* */
2812
2813void
2814newconf_init()
2815{
2816 add_top_conf("modules", NULL, NULL, NULL);
2817 add_conf_item("modules", "path", CF_QSTRING, conf_set_modules_path);
2818 add_conf_item("modules", "module", CF_QSTRING, conf_set_modules_module);
2819
2820 add_top_conf("serverinfo", NULL, NULL, conf_serverinfo_table);
2821 add_top_conf("admin", NULL, NULL, conf_admin_table);
2822 add_top_conf("log", NULL, NULL, conf_log_table);
2823 add_top_conf("operator", conf_begin_oper, conf_end_oper, conf_operator_table);
2824 add_top_conf("class", conf_begin_class, conf_end_class, conf_class_table);
f8606875 2825 add_top_conf("privset", NULL, NULL, conf_privset_table);
212380e3
AC
2826
2827 add_top_conf("listen", conf_begin_listen, conf_end_listen, NULL);
02270e96 2828 add_conf_item("listen", "defer_accept", CF_YESNO, conf_set_listen_defer_accept);
c53ca1e0 2829 add_conf_item("listen", "wsock", CF_YESNO, conf_set_listen_wsock);
212380e3 2830 add_conf_item("listen", "port", CF_INT | CF_FLIST, conf_set_listen_port);
c6d72037 2831 add_conf_item("listen", "sslport", CF_INT | CF_FLIST, conf_set_listen_sslport);
c6ad9b0c
SA
2832 add_conf_item("listen", "sctp_port", CF_INT | CF_FLIST, conf_set_listen_sctp_port);
2833 add_conf_item("listen", "sctp_sslport", CF_INT | CF_FLIST, conf_set_listen_sctp_sslport);
212380e3
AC
2834 add_conf_item("listen", "ip", CF_QSTRING, conf_set_listen_address);
2835 add_conf_item("listen", "host", CF_QSTRING, conf_set_listen_address);
2836
2837 add_top_conf("auth", conf_begin_auth, conf_end_auth, conf_auth_table);
2838
212380e3
AC
2839 add_top_conf("connect", conf_begin_connect, conf_end_connect, conf_connect_table);
2840
2841 add_top_conf("exempt", NULL, NULL, NULL);
2842 add_conf_item("exempt", "ip", CF_QSTRING, conf_set_exempt_ip);
2843
1cf798be
EK
2844 add_top_conf("secure", NULL, NULL, NULL);
2845 add_conf_item("secure", "ip", CF_QSTRING, conf_set_secure_ip);
2846
212380e3
AC
2847 add_top_conf("cluster", conf_cleanup_cluster, conf_cleanup_cluster, NULL);
2848 add_conf_item("cluster", "name", CF_QSTRING, conf_set_cluster_name);
2849 add_conf_item("cluster", "flags", CF_STRING | CF_FLIST, conf_set_cluster_flags);
2850
2851 add_top_conf("general", NULL, NULL, conf_general_table);
2852 add_top_conf("channel", NULL, NULL, conf_channel_table);
2853 add_top_conf("serverhide", NULL, NULL, conf_serverhide_table);
2854
c46a4ecd 2855 add_top_conf("service", NULL, NULL, NULL);
212380e3
AC
2856 add_conf_item("service", "name", CF_QSTRING, conf_set_service_name);
2857
2858 add_top_conf("alias", conf_begin_alias, conf_end_alias, NULL);
2859 add_conf_item("alias", "name", CF_QSTRING, conf_set_alias_name);
2860 add_conf_item("alias", "target", CF_QSTRING, conf_set_alias_target);
2861
7f24f506
AC
2862 add_top_conf("dnsbl", NULL, NULL, NULL);
2863 add_conf_item("dnsbl", "host", CF_QSTRING, conf_set_dnsbl_entry_host);
2864 add_conf_item("dnsbl", "type", CF_STRING | CF_FLIST, conf_set_dnsbl_entry_type);
2865 add_conf_item("dnsbl", "matches", CF_QSTRING | CF_FLIST, conf_set_dnsbl_entry_matches);
2866 add_conf_item("dnsbl", "reject_reason", CF_QSTRING, conf_set_dnsbl_entry_reason);
2867
2868 add_top_conf("blacklist", conf_warn_blacklist_deprecation, NULL, NULL);
2869 add_conf_item("blacklist", "host", CF_QSTRING, conf_set_dnsbl_entry_host);
2870 add_conf_item("blacklist", "type", CF_STRING | CF_FLIST, conf_set_dnsbl_entry_type);
2871 add_conf_item("blacklist", "matches", CF_QSTRING | CF_FLIST, conf_set_dnsbl_entry_matches);
2872 add_conf_item("blacklist", "reject_reason", CF_QSTRING, conf_set_dnsbl_entry_reason);
8275e270
EM
2873
2874 add_top_conf("opm", conf_begin_opm, conf_end_opm, NULL);
9bba0f61 2875 add_conf_item("opm", "timeout", CF_INT, conf_set_opm_timeout);
8275e270 2876 add_conf_item("opm", "listen_ipv4", CF_QSTRING, conf_set_opm_listen_address_ipv4);
8275e270 2877 add_conf_item("opm", "listen_ipv6", CF_QSTRING, conf_set_opm_listen_address_ipv6);
51fa2ab8 2878 add_conf_item("opm", "port_v4", CF_INT, conf_set_opm_listen_port_ipv4);
8275e270
EM
2879 add_conf_item("opm", "port_v6", CF_INT, conf_set_opm_listen_port_ipv6);
2880 add_conf_item("opm", "listen_port", CF_INT, conf_set_opm_listen_port);
51fa2ab8
EM
2881 add_conf_item("opm", "socks4_ports", CF_INT | CF_FLIST, conf_set_opm_scan_ports_socks4);
2882 add_conf_item("opm", "socks5_ports", CF_INT | CF_FLIST, conf_set_opm_scan_ports_socks5);
fabe8b94 2883 add_conf_item("opm", "httpconnect_ports", CF_INT | CF_FLIST, conf_set_opm_scan_ports_httpconnect);
eb0814b3 2884 add_conf_item("opm", "httpsconnect_ports", CF_INT | CF_FLIST, conf_set_opm_scan_ports_httpsconnect);
212380e3 2885}