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