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