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