]> jfr.im git - solanum.git/blob - ircd/newconf.c
Add error handling to parse_netmask()
[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_sendq(void *data)
830 {
831 yy_class->max_sendq = *(unsigned int *) data;
832 }
833
834 static char *listener_address[2];
835
836 static int
837 conf_begin_listen(struct TopConf *tc)
838 {
839 for (int i = 0; i < ARRAY_SIZE(listener_address); i++) {
840 rb_free(listener_address[i]);
841 listener_address[i] = NULL;
842 }
843 yy_wsock = 0;
844 yy_defer_accept = 0;
845 return 0;
846 }
847
848 static int
849 conf_end_listen(struct TopConf *tc)
850 {
851 for (int i = 0; i < ARRAY_SIZE(listener_address); i++) {
852 rb_free(listener_address[i]);
853 listener_address[i] = NULL;
854 }
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, int sctp)
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("listener::port argument is not an integer -- ignoring.");
881 continue;
882 }
883 if(listener_address[0] == NULL)
884 {
885 if (sctp) {
886 conf_report_error("listener::sctp_port has no addresses -- ignoring.");
887 } else {
888 add_tcp_listener(args->v.number, NULL, AF_INET, ssl, ssl || yy_defer_accept, yy_wsock);
889 add_tcp_listener(args->v.number, NULL, AF_INET6, ssl, ssl || yy_defer_accept, yy_wsock);
890 }
891 }
892 else
893 {
894 int family;
895 if(strchr(listener_address[0], ':') != NULL)
896 family = AF_INET6;
897 else
898 family = AF_INET;
899
900 if (sctp) {
901 #ifdef HAVE_LIBSCTP
902 add_sctp_listener(args->v.number, listener_address[0], listener_address[1], ssl, yy_wsock);
903 #else
904 conf_report_error("Warning -- ignoring listener::sctp_port -- SCTP support not available.");
905 #endif
906 } else {
907 add_tcp_listener(args->v.number, listener_address[0], family, ssl, ssl || yy_defer_accept, yy_wsock);
908 }
909 }
910 }
911 }
912
913 static void
914 conf_set_listen_port(void *data)
915 {
916 conf_set_listen_port_both(data, 0, 0);
917 }
918
919 static void
920 conf_set_listen_sslport(void *data)
921 {
922 conf_set_listen_port_both(data, 1, 0 );
923 }
924
925 static void
926 conf_set_listen_sctp_port(void *data)
927 {
928 conf_set_listen_port_both(data, 0, 1);
929 }
930
931 static void
932 conf_set_listen_sctp_sslport(void *data)
933 {
934 conf_set_listen_port_both(data, 1, 1);
935 }
936
937 static void
938 conf_set_listen_address(void *data)
939 {
940 rb_free(listener_address[1]);
941 listener_address[1] = listener_address[0];
942 listener_address[0] = rb_strdup(data);
943 }
944
945 static int
946 conf_begin_auth(struct TopConf *tc)
947 {
948 rb_dlink_node *ptr;
949 rb_dlink_node *next_ptr;
950
951 if(yy_aconf)
952 free_conf(yy_aconf);
953
954 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_aconf_list.head)
955 {
956 free_conf(ptr->data);
957 rb_dlinkDestroy(ptr, &yy_aconf_list);
958 }
959
960 yy_aconf = make_conf();
961 yy_aconf->status = CONF_CLIENT;
962
963 return 0;
964 }
965
966 static int
967 conf_end_auth(struct TopConf *tc)
968 {
969 struct ConfItem *yy_tmp, *found_conf;
970 rb_dlink_node *ptr;
971 rb_dlink_node *next_ptr;
972
973 if(EmptyString(yy_aconf->info.name))
974 yy_aconf->info.name = rb_strdup("NOMATCH");
975
976 /* didnt even get one ->host? */
977 if(EmptyString(yy_aconf->host))
978 {
979 conf_report_error("Ignoring auth block -- missing user@host");
980 return 0;
981 }
982
983 /* so the stacking works in order.. */
984 collapse(yy_aconf->user);
985 collapse(yy_aconf->host);
986 conf_add_class_to_conf(yy_aconf);
987 if ((found_conf = find_exact_conf_by_address("*", CONF_CLIENT, "*")) && found_conf->spasswd == NULL)
988 conf_report_error("Ignoring redundant auth block (after *@*)");
989 else if ((found_conf = find_exact_conf_by_address(yy_aconf->host, CONF_CLIENT, yy_aconf->user)) &&
990 (!found_conf->spasswd || (yy_aconf->spasswd &&
991 0 == irccmp(found_conf->spasswd, yy_aconf->spasswd))))
992 conf_report_error("Ignoring duplicate auth block for %s@%s",
993 yy_aconf->user, yy_aconf->host);
994 else
995 add_conf_by_address(yy_aconf->host, CONF_CLIENT, yy_aconf->user, yy_aconf->spasswd, yy_aconf);
996
997 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_aconf_list.head)
998 {
999 yy_tmp = ptr->data;
1000
1001 if(yy_aconf->passwd)
1002 yy_tmp->passwd = rb_strdup(yy_aconf->passwd);
1003
1004 if(yy_aconf->spasswd)
1005 yy_tmp->spasswd = rb_strdup(yy_aconf->spasswd);
1006
1007 /* this will always exist.. */
1008 yy_tmp->info.name = rb_strdup(yy_aconf->info.name);
1009
1010 if(yy_aconf->className)
1011 yy_tmp->className = rb_strdup(yy_aconf->className);
1012
1013 yy_tmp->flags = yy_aconf->flags;
1014 yy_tmp->port = yy_aconf->port;
1015
1016 collapse(yy_tmp->user);
1017 collapse(yy_tmp->host);
1018
1019 conf_add_class_to_conf(yy_tmp);
1020
1021 if ((found_conf = find_exact_conf_by_address("*", CONF_CLIENT, "*")) && found_conf->spasswd == NULL)
1022 conf_report_error("Ignoring redundant auth block (after *@*)");
1023 else if ((found_conf = find_exact_conf_by_address(yy_tmp->host, CONF_CLIENT, yy_tmp->user)) &&
1024 (!found_conf->spasswd || (yy_tmp->spasswd &&
1025 0 == irccmp(found_conf->spasswd, yy_tmp->spasswd))))
1026 conf_report_error("Ignoring duplicate auth block for %s@%s",
1027 yy_tmp->user, yy_tmp->host);
1028 else
1029 add_conf_by_address(yy_tmp->host, CONF_CLIENT, yy_tmp->user, yy_tmp->spasswd, yy_tmp);
1030 rb_dlinkDestroy(ptr, &yy_aconf_list);
1031 }
1032
1033 yy_aconf = NULL;
1034 return 0;
1035 }
1036
1037 static void
1038 conf_set_auth_user(void *data)
1039 {
1040 struct ConfItem *yy_tmp;
1041 char *p;
1042
1043 /* The first user= line doesn't allocate a new conf */
1044 if(!EmptyString(yy_aconf->host))
1045 {
1046 yy_tmp = make_conf();
1047 yy_tmp->status = CONF_CLIENT;
1048 }
1049 else
1050 yy_tmp = yy_aconf;
1051
1052 if((p = strchr(data, '@')))
1053 {
1054 *p++ = '\0';
1055
1056 yy_tmp->user = rb_strdup(data);
1057 yy_tmp->host = rb_strdup(p);
1058 }
1059 else
1060 {
1061 yy_tmp->user = rb_strdup("*");
1062 yy_tmp->host = rb_strdup(data);
1063 }
1064
1065 if(yy_aconf != yy_tmp)
1066 rb_dlinkAddAlloc(yy_tmp, &yy_aconf_list);
1067 }
1068
1069 static void
1070 conf_set_auth_auth_user(void *data)
1071 {
1072 if(yy_aconf->spasswd)
1073 memset(yy_aconf->spasswd, 0, strlen(yy_aconf->spasswd));
1074 rb_free(yy_aconf->spasswd);
1075 yy_aconf->spasswd = rb_strdup(data);
1076 }
1077
1078 static void
1079 conf_set_auth_passwd(void *data)
1080 {
1081 if(yy_aconf->passwd)
1082 memset(yy_aconf->passwd, 0, strlen(yy_aconf->passwd));
1083 rb_free(yy_aconf->passwd);
1084 yy_aconf->passwd = rb_strdup(data);
1085 }
1086
1087 static void
1088 conf_set_auth_spoof(void *data)
1089 {
1090 char *p;
1091 char *user = NULL;
1092 char *host = NULL;
1093
1094 host = data;
1095
1096 /* user@host spoof */
1097 if((p = strchr(host, '@')) != NULL)
1098 {
1099 *p = '\0';
1100 user = data;
1101 host = p+1;
1102
1103 if(EmptyString(user))
1104 {
1105 conf_report_error("Warning -- spoof ident empty.");
1106 return;
1107 }
1108
1109 if(strlen(user) > USERLEN)
1110 {
1111 conf_report_error("Warning -- spoof ident length invalid.");
1112 return;
1113 }
1114
1115 if(!valid_username(user))
1116 {
1117 conf_report_error("Warning -- invalid spoof (ident).");
1118 return;
1119 }
1120
1121 /* this must be restored! */
1122 *p = '@';
1123 }
1124
1125 if(EmptyString(host))
1126 {
1127 conf_report_error("Warning -- spoof host empty.");
1128 return;
1129 }
1130
1131 if(strlen(host) > HOSTLEN)
1132 {
1133 conf_report_error("Warning -- spoof host length invalid.");
1134 return;
1135 }
1136
1137 if(!valid_hostname(host))
1138 {
1139 conf_report_error("Warning -- invalid spoof (host).");
1140 return;
1141 }
1142
1143 rb_free(yy_aconf->info.name);
1144 yy_aconf->info.name = rb_strdup(data);
1145 yy_aconf->flags |= CONF_FLAGS_SPOOF_IP;
1146 }
1147
1148 static void
1149 conf_set_auth_flags(void *data)
1150 {
1151 conf_parm_t *args = data;
1152
1153 set_modes_from_table((int *) &yy_aconf->flags, "flag", auth_table, args);
1154 }
1155
1156 static void
1157 conf_set_auth_redir_serv(void *data)
1158 {
1159 yy_aconf->flags |= CONF_FLAGS_REDIR;
1160 rb_free(yy_aconf->info.name);
1161 yy_aconf->info.name = rb_strdup(data);
1162 }
1163
1164 static void
1165 conf_set_auth_redir_port(void *data)
1166 {
1167 int port = *(unsigned int *) data;
1168
1169 yy_aconf->flags |= CONF_FLAGS_REDIR;
1170 yy_aconf->port = port;
1171 }
1172
1173 static void
1174 conf_set_auth_class(void *data)
1175 {
1176 rb_free(yy_aconf->className);
1177 yy_aconf->className = rb_strdup(data);
1178 }
1179
1180 /* ok, shared_oper handles the stacking, shared_flags handles adding
1181 * things.. so all we need to do when we start and end a shared block, is
1182 * clean up anything thats been left over.
1183 */
1184 static int
1185 conf_cleanup_shared(struct TopConf *tc)
1186 {
1187 rb_dlink_node *ptr, *next_ptr;
1188
1189 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_shared_list.head)
1190 {
1191 free_remote_conf(ptr->data);
1192 rb_dlinkDestroy(ptr, &yy_shared_list);
1193 }
1194
1195 if(yy_shared != NULL)
1196 {
1197 free_remote_conf(yy_shared);
1198 yy_shared = NULL;
1199 }
1200
1201 return 0;
1202 }
1203
1204 static void
1205 conf_set_shared_oper(void *data)
1206 {
1207 conf_parm_t *args = data;
1208 const char *username;
1209 char *p;
1210
1211 if(yy_shared != NULL)
1212 free_remote_conf(yy_shared);
1213
1214 yy_shared = make_remote_conf();
1215
1216 if(args->next != NULL)
1217 {
1218 if(CF_TYPE(args->type) != CF_QSTRING)
1219 {
1220 conf_report_error("Ignoring shared::oper -- server is not a qstring");
1221 return;
1222 }
1223
1224 yy_shared->server = rb_strdup(args->v.string);
1225 args = args->next;
1226 }
1227 else
1228 yy_shared->server = rb_strdup("*");
1229
1230 if(CF_TYPE(args->type) != CF_QSTRING)
1231 {
1232 conf_report_error("Ignoring shared::oper -- oper is not a qstring");
1233 return;
1234 }
1235
1236 if((p = strchr(args->v.string, '@')) == NULL)
1237 {
1238 conf_report_error("Ignoring shard::oper -- oper is not a user@host");
1239 return;
1240 }
1241
1242 username = args->v.string;
1243 *p++ = '\0';
1244
1245 if(EmptyString(p))
1246 yy_shared->host = rb_strdup("*");
1247 else
1248 yy_shared->host = rb_strdup(p);
1249
1250 if(EmptyString(username))
1251 yy_shared->username = rb_strdup("*");
1252 else
1253 yy_shared->username = rb_strdup(username);
1254
1255 rb_dlinkAddAlloc(yy_shared, &yy_shared_list);
1256 yy_shared = NULL;
1257 }
1258
1259 static void
1260 conf_set_shared_flags(void *data)
1261 {
1262 conf_parm_t *args = data;
1263 int flags = 0;
1264 rb_dlink_node *ptr, *next_ptr;
1265
1266 if(yy_shared != NULL)
1267 free_remote_conf(yy_shared);
1268
1269 set_modes_from_table(&flags, "flag", shared_table, args);
1270
1271 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_shared_list.head)
1272 {
1273 yy_shared = ptr->data;
1274
1275 yy_shared->flags = flags;
1276 rb_dlinkDestroy(ptr, &yy_shared_list);
1277 rb_dlinkAddTail(yy_shared, &yy_shared->node, &shared_conf_list);
1278 }
1279
1280 yy_shared = NULL;
1281 }
1282
1283 static int
1284 conf_begin_connect(struct TopConf *tc)
1285 {
1286 if(yy_server)
1287 free_server_conf(yy_server);
1288
1289 yy_server = make_server_conf();
1290 yy_server->port = PORTNUM;
1291 yy_server->flags |= SERVER_TB;
1292
1293 if(conf_cur_block_name != NULL)
1294 yy_server->name = rb_strdup(conf_cur_block_name);
1295
1296 return 0;
1297 }
1298
1299 static int
1300 conf_end_connect(struct TopConf *tc)
1301 {
1302 if(EmptyString(yy_server->name))
1303 {
1304 conf_report_error("Ignoring connect block -- missing name.");
1305 return 0;
1306 }
1307
1308 if(ServerInfo.name != NULL && !irccmp(ServerInfo.name, yy_server->name))
1309 {
1310 conf_report_error("Ignoring connect block for %s -- name is equal to my own name.",
1311 yy_server->name);
1312 return 0;
1313 }
1314
1315 if((EmptyString(yy_server->passwd) || EmptyString(yy_server->spasswd)) && EmptyString(yy_server->certfp))
1316 {
1317 conf_report_error("Ignoring connect block for %s -- no fingerprint or password credentials provided.",
1318 yy_server->name);
1319 return 0;
1320 }
1321
1322 if((yy_server->flags & SERVER_SSL) && EmptyString(yy_server->certfp))
1323 {
1324 conf_report_error("Ignoring connect block for %s -- no fingerprint provided for SSL connection.",
1325 yy_server->name);
1326 return 0;
1327 }
1328
1329 if(EmptyString(yy_server->connect_host)
1330 && GET_SS_FAMILY(&yy_server->connect4) != AF_INET
1331 && GET_SS_FAMILY(&yy_server->connect6) != AF_INET6
1332 )
1333 {
1334 conf_report_error("Ignoring connect block for %s -- missing host.",
1335 yy_server->name);
1336 return 0;
1337 }
1338
1339 #ifndef HAVE_LIBZ
1340 if(ServerConfCompressed(yy_server))
1341 {
1342 conf_report_error("Ignoring connect::flags::compressed -- zlib not available.");
1343 yy_server->flags &= ~SERVER_COMPRESSED;
1344 }
1345 #endif
1346
1347 add_server_conf(yy_server);
1348 rb_dlinkAdd(yy_server, &yy_server->node, &server_conf_list);
1349
1350 yy_server = NULL;
1351 return 0;
1352 }
1353
1354 static void
1355 conf_set_connect_host(void *data)
1356 {
1357 struct rb_sockaddr_storage addr;
1358
1359 if(rb_inet_pton_sock(data, &addr) <= 0)
1360 {
1361 rb_free(yy_server->connect_host);
1362 yy_server->connect_host = rb_strdup(data);
1363 }
1364 else if(GET_SS_FAMILY(&addr) == AF_INET)
1365 {
1366 yy_server->connect4 = addr;
1367 }
1368 else if(GET_SS_FAMILY(&addr) == AF_INET6)
1369 {
1370 yy_server->connect6 = addr;
1371 }
1372 else
1373 {
1374 conf_report_error("Unsupported IP address for server connect host (%s)",
1375 (char *)data);
1376 return;
1377 }
1378 }
1379
1380 static void
1381 conf_set_connect_vhost(void *data)
1382 {
1383 struct rb_sockaddr_storage addr;
1384
1385 if(rb_inet_pton_sock(data, &addr) <= 0)
1386 {
1387 rb_free(yy_server->bind_host);
1388 yy_server->bind_host = rb_strdup(data);
1389 }
1390 else if(GET_SS_FAMILY(&addr) == AF_INET)
1391 {
1392 yy_server->bind4 = addr;
1393 }
1394 else if(GET_SS_FAMILY(&addr) == AF_INET6)
1395 {
1396 yy_server->bind6 = addr;
1397 }
1398 else
1399 {
1400 conf_report_error("Unsupported IP address for server connect vhost (%s)",
1401 (char *)data);
1402 return;
1403 }
1404 }
1405
1406 static void
1407 conf_set_connect_send_password(void *data)
1408 {
1409 if(yy_server->spasswd)
1410 {
1411 memset(yy_server->spasswd, 0, strlen(yy_server->spasswd));
1412 rb_free(yy_server->spasswd);
1413 }
1414
1415 yy_server->spasswd = rb_strdup(data);
1416 }
1417
1418 static void
1419 conf_set_connect_accept_password(void *data)
1420 {
1421 if(yy_server->passwd)
1422 {
1423 memset(yy_server->passwd, 0, strlen(yy_server->passwd));
1424 rb_free(yy_server->passwd);
1425 }
1426 yy_server->passwd = rb_strdup(data);
1427 }
1428
1429 static void
1430 conf_set_connect_fingerprint(void *data)
1431 {
1432 if (yy_server->certfp)
1433 rb_free(yy_server->certfp);
1434 yy_server->certfp = rb_strdup((char *) data);
1435
1436 /* force SSL to be enabled if fingerprint is enabled. */
1437 yy_server->flags |= SERVER_SSL;
1438 }
1439
1440 static void
1441 conf_set_connect_port(void *data)
1442 {
1443 int port = *(unsigned int *) data;
1444
1445 if(port < 1)
1446 port = PORTNUM;
1447
1448 yy_server->port = port;
1449 }
1450
1451 static void
1452 conf_set_connect_aftype(void *data)
1453 {
1454 char *aft = data;
1455
1456 if(rb_strcasecmp(aft, "ipv4") == 0)
1457 yy_server->aftype = AF_INET;
1458 else if(rb_strcasecmp(aft, "ipv6") == 0)
1459 yy_server->aftype = AF_INET6;
1460 else
1461 conf_report_error("connect::aftype '%s' is unknown.", aft);
1462 }
1463
1464 static void
1465 conf_set_connect_flags(void *data)
1466 {
1467 conf_parm_t *args = data;
1468
1469 /* note, we allow them to set compressed, then remove it later if
1470 * they do and LIBZ isnt available
1471 */
1472 set_modes_from_table(&yy_server->flags, "flag", connect_table, args);
1473 }
1474
1475 static void
1476 conf_set_connect_hub_mask(void *data)
1477 {
1478 struct remote_conf *yy_hub;
1479
1480 if(EmptyString(yy_server->name))
1481 return;
1482
1483 yy_hub = make_remote_conf();
1484 yy_hub->flags = CONF_HUB;
1485
1486 yy_hub->host = rb_strdup(data);
1487 yy_hub->server = rb_strdup(yy_server->name);
1488 rb_dlinkAdd(yy_hub, &yy_hub->node, &hubleaf_conf_list);
1489 }
1490
1491 static void
1492 conf_set_connect_leaf_mask(void *data)
1493 {
1494 struct remote_conf *yy_leaf;
1495
1496 if(EmptyString(yy_server->name))
1497 return;
1498
1499 yy_leaf = make_remote_conf();
1500 yy_leaf->flags = CONF_LEAF;
1501
1502 yy_leaf->host = rb_strdup(data);
1503 yy_leaf->server = rb_strdup(yy_server->name);
1504 rb_dlinkAdd(yy_leaf, &yy_leaf->node, &hubleaf_conf_list);
1505 }
1506
1507 static void
1508 conf_set_connect_class(void *data)
1509 {
1510 rb_free(yy_server->class_name);
1511 yy_server->class_name = rb_strdup(data);
1512 }
1513
1514 static void
1515 conf_set_exempt_ip(void *data)
1516 {
1517 struct ConfItem *yy_tmp;
1518 int masktype = parse_netmask_strict(data, NULL, NULL);
1519
1520 if(masktype != HM_IPV4 && masktype != HM_IPV6)
1521 {
1522 conf_report_error("Ignoring exempt -- invalid exempt::ip.");
1523 return;
1524 }
1525
1526 yy_tmp = make_conf();
1527 yy_tmp->passwd = rb_strdup("*");
1528 yy_tmp->host = rb_strdup(data);
1529 yy_tmp->status = CONF_EXEMPTDLINE;
1530 add_conf_by_address(yy_tmp->host, CONF_EXEMPTDLINE, NULL, NULL, yy_tmp);
1531 }
1532
1533 static int
1534 conf_cleanup_cluster(struct TopConf *tc)
1535 {
1536 rb_dlink_node *ptr, *next_ptr;
1537
1538 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_cluster_list.head)
1539 {
1540 free_remote_conf(ptr->data);
1541 rb_dlinkDestroy(ptr, &yy_cluster_list);
1542 }
1543
1544 if(yy_shared != NULL)
1545 {
1546 free_remote_conf(yy_shared);
1547 yy_shared = NULL;
1548 }
1549
1550 return 0;
1551 }
1552
1553 static void
1554 conf_set_cluster_name(void *data)
1555 {
1556 if(yy_shared != NULL)
1557 free_remote_conf(yy_shared);
1558
1559 yy_shared = make_remote_conf();
1560 yy_shared->server = rb_strdup(data);
1561 rb_dlinkAddAlloc(yy_shared, &yy_cluster_list);
1562
1563 yy_shared = NULL;
1564 }
1565
1566 static void
1567 conf_set_cluster_flags(void *data)
1568 {
1569 conf_parm_t *args = data;
1570 int flags = 0;
1571 rb_dlink_node *ptr, *next_ptr;
1572
1573 if(yy_shared != NULL)
1574 free_remote_conf(yy_shared);
1575
1576 set_modes_from_table(&flags, "flag", cluster_table, args);
1577
1578 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_cluster_list.head)
1579 {
1580 yy_shared = ptr->data;
1581 yy_shared->flags = flags;
1582 rb_dlinkAddTail(yy_shared, &yy_shared->node, &cluster_conf_list);
1583 rb_dlinkDestroy(ptr, &yy_cluster_list);
1584 }
1585
1586 yy_shared = NULL;
1587 }
1588
1589 static void
1590 conf_set_general_havent_read_conf(void *data)
1591 {
1592 if(*(unsigned int *) data)
1593 {
1594 conf_report_error("You haven't read your config file properly.");
1595 conf_report_error
1596 ("There is a line in the example conf that will kill your server if not removed.");
1597 conf_report_error
1598 ("Consider actually reading/editing the conf file, and removing this line.");
1599 if (!testing_conf)
1600 exit(0);
1601 }
1602 }
1603
1604 static void
1605 conf_set_general_hide_error_messages(void *data)
1606 {
1607 char *val = data;
1608
1609 if(rb_strcasecmp(val, "yes") == 0)
1610 ConfigFileEntry.hide_error_messages = 2;
1611 else if(rb_strcasecmp(val, "opers") == 0)
1612 ConfigFileEntry.hide_error_messages = 1;
1613 else if(rb_strcasecmp(val, "no") == 0)
1614 ConfigFileEntry.hide_error_messages = 0;
1615 else
1616 conf_report_error("Invalid setting '%s' for general::hide_error_messages.", val);
1617 }
1618
1619 static void
1620 conf_set_general_stats_k_oper_only(void *data)
1621 {
1622 char *val = data;
1623
1624 if(rb_strcasecmp(val, "yes") == 0)
1625 ConfigFileEntry.stats_k_oper_only = 2;
1626 else if(rb_strcasecmp(val, "masked") == 0)
1627 ConfigFileEntry.stats_k_oper_only = 1;
1628 else if(rb_strcasecmp(val, "no") == 0)
1629 ConfigFileEntry.stats_k_oper_only = 0;
1630 else
1631 conf_report_error("Invalid setting '%s' for general::stats_k_oper_only.", val);
1632 }
1633
1634 static void
1635 conf_set_general_stats_i_oper_only(void *data)
1636 {
1637 char *val = data;
1638
1639 if(rb_strcasecmp(val, "yes") == 0)
1640 ConfigFileEntry.stats_i_oper_only = 2;
1641 else if(rb_strcasecmp(val, "masked") == 0)
1642 ConfigFileEntry.stats_i_oper_only = 1;
1643 else if(rb_strcasecmp(val, "no") == 0)
1644 ConfigFileEntry.stats_i_oper_only = 0;
1645 else
1646 conf_report_error("Invalid setting '%s' for general::stats_i_oper_only.", val);
1647 }
1648
1649 static void
1650 conf_set_general_compression_level(void *data)
1651 {
1652 #ifdef HAVE_LIBZ
1653 ConfigFileEntry.compression_level = *(unsigned int *) data;
1654
1655 if((ConfigFileEntry.compression_level < 1) || (ConfigFileEntry.compression_level > 9))
1656 {
1657 conf_report_error
1658 ("Invalid general::compression_level %d -- using default.",
1659 ConfigFileEntry.compression_level);
1660 ConfigFileEntry.compression_level = 0;
1661 }
1662 #else
1663 conf_report_error("Ignoring general::compression_level -- zlib not available.");
1664 #endif
1665 }
1666
1667 static void
1668 conf_set_general_default_umodes(void *data)
1669 {
1670 char *pm;
1671 int what = MODE_ADD, flag;
1672
1673 ConfigFileEntry.default_umodes = 0;
1674 for (pm = (char *) data; *pm; pm++)
1675 {
1676 switch (*pm)
1677 {
1678 case '+':
1679 what = MODE_ADD;
1680 break;
1681 case '-':
1682 what = MODE_DEL;
1683 break;
1684
1685 /* don't allow +o */
1686 case 'o':
1687 case 'S':
1688 case 'Z':
1689 case ' ':
1690 break;
1691
1692 default:
1693 if ((flag = user_modes[(unsigned char) *pm]))
1694 {
1695 /* Proper value has probably not yet been set
1696 * so don't check oper_only_umodes -- jilles */
1697 if (what == MODE_ADD)
1698 ConfigFileEntry.default_umodes |= flag;
1699 else
1700 ConfigFileEntry.default_umodes &= ~flag;
1701 }
1702 break;
1703 }
1704 }
1705 }
1706
1707 static void
1708 conf_set_general_oper_umodes(void *data)
1709 {
1710 set_modes_from_table(&ConfigFileEntry.oper_umodes, "umode", umode_table, data);
1711 }
1712
1713 static void
1714 conf_set_general_certfp_method(void *data)
1715 {
1716 char *method = data;
1717
1718 if (!rb_strcasecmp(method, CERTFP_NAME_CERT_SHA1))
1719 ConfigFileEntry.certfp_method = RB_SSL_CERTFP_METH_CERT_SHA1;
1720 else if (!rb_strcasecmp(method, CERTFP_NAME_CERT_SHA256))
1721 ConfigFileEntry.certfp_method = RB_SSL_CERTFP_METH_CERT_SHA256;
1722 else if (!rb_strcasecmp(method, CERTFP_NAME_CERT_SHA512))
1723 ConfigFileEntry.certfp_method = RB_SSL_CERTFP_METH_CERT_SHA512;
1724 else if (!rb_strcasecmp(method, CERTFP_NAME_SPKI_SHA256))
1725 ConfigFileEntry.certfp_method = RB_SSL_CERTFP_METH_SPKI_SHA256;
1726 else if (!rb_strcasecmp(method, CERTFP_NAME_SPKI_SHA512))
1727 ConfigFileEntry.certfp_method = RB_SSL_CERTFP_METH_SPKI_SHA512;
1728 else
1729 {
1730 ConfigFileEntry.certfp_method = RB_SSL_CERTFP_METH_CERT_SHA1;
1731 conf_report_error("Ignoring general::certfp_method -- bogus certfp method %s", method);
1732 }
1733 }
1734
1735 static void
1736 conf_set_general_oper_only_umodes(void *data)
1737 {
1738 set_modes_from_table(&ConfigFileEntry.oper_only_umodes, "umode", umode_table, data);
1739 }
1740
1741 static void
1742 conf_set_general_oper_snomask(void *data)
1743 {
1744 char *pm;
1745 int what = MODE_ADD, flag;
1746
1747 ConfigFileEntry.oper_snomask = 0;
1748 for (pm = (char *) data; *pm; pm++)
1749 {
1750 switch (*pm)
1751 {
1752 case '+':
1753 what = MODE_ADD;
1754 break;
1755 case '-':
1756 what = MODE_DEL;
1757 break;
1758
1759 default:
1760 if ((flag = snomask_modes[(unsigned char) *pm]))
1761 {
1762 if (what == MODE_ADD)
1763 ConfigFileEntry.oper_snomask |= flag;
1764 else
1765 ConfigFileEntry.oper_snomask &= ~flag;
1766 }
1767 break;
1768 }
1769 }
1770 }
1771
1772 static void
1773 conf_set_serverhide_links_delay(void *data)
1774 {
1775 int val = *(unsigned int *) data;
1776
1777 ConfigServerHide.links_delay = val;
1778 }
1779
1780 static void
1781 conf_set_service_name(void *data)
1782 {
1783 const char *s;
1784 char *tmp;
1785 int dots = 0;
1786
1787 for(s = data; *s != '\0'; s++)
1788 {
1789 if(!IsServChar(*s))
1790 {
1791 conf_report_error("Ignoring service::name "
1792 "-- bogus servername.");
1793 return;
1794 }
1795 else if(*s == '.')
1796 dots++;
1797 }
1798
1799 if(!dots)
1800 {
1801 conf_report_error("Ignoring service::name -- must contain '.'");
1802 return;
1803 }
1804
1805 tmp = rb_strdup(data);
1806 rb_dlinkAddAlloc(tmp, &service_list);
1807 }
1808
1809 static int
1810 conf_begin_alias(struct TopConf *tc)
1811 {
1812 yy_alias = rb_malloc(sizeof(struct alias_entry));
1813
1814 if (conf_cur_block_name != NULL)
1815 yy_alias->name = rb_strdup(conf_cur_block_name);
1816
1817 yy_alias->flags = 0;
1818
1819 return 0;
1820 }
1821
1822 static int
1823 conf_end_alias(struct TopConf *tc)
1824 {
1825 if (yy_alias == NULL)
1826 return -1;
1827
1828 if (yy_alias->name == NULL)
1829 {
1830 conf_report_error("Ignoring alias -- must have a name.");
1831
1832 rb_free(yy_alias);
1833
1834 return -1;
1835 }
1836
1837 if (yy_alias->target == NULL)
1838 {
1839 conf_report_error("Ignoring alias -- must have a target.");
1840
1841 rb_free(yy_alias);
1842
1843 return -1;
1844 }
1845
1846 rb_dictionary_add(alias_dict, yy_alias->name, yy_alias);
1847
1848 return 0;
1849 }
1850
1851 static void
1852 conf_set_alias_name(void *data)
1853 {
1854 if (data == NULL || yy_alias == NULL) /* this shouldn't ever happen */
1855 return;
1856
1857 yy_alias->name = rb_strdup(data);
1858 }
1859
1860 static void
1861 conf_set_alias_target(void *data)
1862 {
1863 if (data == NULL || yy_alias == NULL) /* this shouldn't ever happen */
1864 return;
1865
1866 yy_alias->target = rb_strdup(data);
1867 }
1868
1869 static void
1870 conf_set_channel_autochanmodes(void *data)
1871 {
1872 char *pm;
1873 int what = MODE_ADD;
1874
1875 ConfigChannel.autochanmodes = 0;
1876 for (pm = (char *) data; *pm; pm++)
1877 {
1878 switch (*pm)
1879 {
1880 case '+':
1881 what = MODE_ADD;
1882 break;
1883 case '-':
1884 what = MODE_DEL;
1885 break;
1886
1887 default:
1888 if (chmode_table[(unsigned char) *pm].set_func == chm_simple)
1889 {
1890 if (what == MODE_ADD)
1891 ConfigChannel.autochanmodes |= chmode_table[(unsigned char) *pm].mode_type;
1892 else
1893 ConfigChannel.autochanmodes &= ~chmode_table[(unsigned char) *pm].mode_type;
1894 }
1895 else
1896 {
1897 conf_report_error("channel::autochanmodes -- Invalid channel mode %c", *pm);
1898 continue;
1899 }
1900 break;
1901 }
1902 }
1903 }
1904
1905 /* XXX for below */
1906 static void conf_set_dnsbl_entry_reason(void *data);
1907
1908 #define IPTYPE_IPV4 1
1909 #define IPTYPE_IPV6 2
1910
1911 static int
1912 conf_warn_blacklist_deprecation(struct TopConf *tc)
1913 {
1914 conf_report_error("blacklist{} blocks have been deprecated -- use dnsbl{} blocks instead.");
1915 return 0;
1916 }
1917
1918 static void
1919 conf_set_dnsbl_entry_host(void *data)
1920 {
1921 if (yy_dnsbl_entry_host)
1922 {
1923 conf_report_error("dnsbl::host %s overlaps existing host %s",
1924 (char *)data, yy_dnsbl_entry_host);
1925
1926 /* Cleanup */
1927 conf_set_dnsbl_entry_reason(NULL);
1928 return;
1929 }
1930
1931 yy_dnsbl_entry_iptype |= IPTYPE_IPV4;
1932 yy_dnsbl_entry_host = rb_strdup(data);
1933 }
1934
1935 static void
1936 conf_set_dnsbl_entry_type(void *data)
1937 {
1938 conf_parm_t *args = data;
1939
1940 /* Don't assume we have either if we got here */
1941 yy_dnsbl_entry_iptype = 0;
1942
1943 for (; args; args = args->next)
1944 {
1945 if (!rb_strcasecmp(args->v.string, "ipv4"))
1946 yy_dnsbl_entry_iptype |= IPTYPE_IPV4;
1947 else if (!rb_strcasecmp(args->v.string, "ipv6"))
1948 yy_dnsbl_entry_iptype |= IPTYPE_IPV6;
1949 else
1950 conf_report_error("dnsbl::type has unknown address family %s",
1951 args->v.string);
1952 }
1953
1954 /* If we have neither, just default to IPv4 */
1955 if (!yy_dnsbl_entry_iptype)
1956 {
1957 conf_report_warning("dnsbl::type has neither IPv4 nor IPv6 (defaulting to IPv4)");
1958 yy_dnsbl_entry_iptype = IPTYPE_IPV4;
1959 }
1960 }
1961
1962 static void
1963 conf_set_dnsbl_entry_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("dnsbl::matches -- must be quoted string");
1977 continue;
1978 }
1979
1980 if (str == NULL)
1981 {
1982 conf_report_error("dnsbl::matches -- invalid entry");
1983 continue;
1984 }
1985
1986 if (strlen(str) > HOSTIPLEN)
1987 {
1988 conf_report_error("dnsbl::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("dnsbl::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("dnsbl::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("dnsbl::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_dnsbl_entry_filters);
2034 }
2035 }
2036
2037 static void
2038 conf_set_dnsbl_entry_reason(void *data)
2039 {
2040 rb_dlink_node *ptr, *nptr;
2041
2042 if (yy_dnsbl_entry_host && data)
2043 {
2044 yy_dnsbl_entry_reason = rb_strdup(data);
2045 if (yy_dnsbl_entry_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_dnsbl_entry_host)) > IRCD_RES_HOSTLEN)
2051 {
2052 conf_report_error("dnsbl::host %s results in IPv6 queries that are too long",
2053 yy_dnsbl_entry_host);
2054 goto cleanup_bl;
2055 }
2056 }
2057 /* Avoid doing redundant check, IPv6 is bigger than IPv4 --Elizabeth */
2058 if ((yy_dnsbl_entry_iptype & IPTYPE_IPV4) && !(yy_dnsbl_entry_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_dnsbl_entry_host)) > IRCD_RES_HOSTLEN)
2064 {
2065 conf_report_error("dnsbl::host %s results in IPv4 queries that are too long",
2066 yy_dnsbl_entry_host);
2067 goto cleanup_bl;
2068 }
2069 }
2070
2071 add_dnsbl_entry(yy_dnsbl_entry_host, yy_dnsbl_entry_reason, yy_dnsbl_entry_iptype, &yy_dnsbl_entry_filters);
2072 }
2073
2074 cleanup_bl:
2075 RB_DLINK_FOREACH_SAFE(ptr, nptr, yy_dnsbl_entry_filters.head)
2076 {
2077 rb_free(ptr->data);
2078 rb_dlinkDestroy(ptr, &yy_dnsbl_entry_filters);
2079 }
2080
2081 yy_dnsbl_entry_filters = (rb_dlink_list){ NULL, NULL, 0 };
2082
2083 rb_free(yy_dnsbl_entry_host);
2084 rb_free(yy_dnsbl_entry_reason);
2085 yy_dnsbl_entry_host = NULL;
2086 yy_dnsbl_entry_reason = NULL;
2087 yy_dnsbl_entry_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, &addr))
2202 {
2203 conf_report_error("%s is an invalid address: %s", confstr, ip);
2204 return;
2205 }
2206
2207 if(ipv6)
2208 {
2209 if(GET_SS_FAMILY(&addr) != AF_INET6)
2210 {
2211 conf_report_error("%s is of the wrong address type: %s", confstr, ip);
2212 return;
2213 }
2214
2215 if(yy_opm_address_ipv6 != NULL)
2216 {
2217 conf_report_error("%s overwrites previous address %s", confstr, ip);
2218 return;
2219 }
2220
2221 yy_opm_address_ipv6 = rb_strdup(ip);
2222 }
2223 else
2224 {
2225 if(GET_SS_FAMILY(&addr) != AF_INET)
2226 {
2227 conf_report_error("%s is of the wrong address type: %s", confstr, ip);
2228 return;
2229 }
2230
2231 if(yy_opm_address_ipv4 != NULL)
2232 {
2233 conf_report_error("%s overwrites previous address %s", confstr, ip);
2234 return;
2235 }
2236
2237 yy_opm_address_ipv4 = rb_strdup(ip);
2238 }
2239 }
2240
2241 static void
2242 conf_set_opm_listen_address_ipv4(void *data)
2243 {
2244 conf_set_opm_listen_address_both(data, false);
2245 }
2246
2247 static void
2248 conf_set_opm_listen_address_ipv6(void *data)
2249 {
2250 conf_set_opm_listen_address_both(data, true);
2251 }
2252
2253 static void
2254 conf_set_opm_listen_port_both(void *data, bool ipv6)
2255 {
2256 int port = *((int *)data);
2257 const char *confstr = (ipv6 ? "opm::port_ipv6" : "opm::port_ipv4");
2258
2259 if(port > 65535 || port <= 0)
2260 {
2261 conf_report_error("%s is out of range: %d", confstr, port);
2262 return;
2263 }
2264
2265 if(ipv6)
2266 {
2267 if(yy_opm_port_ipv4)
2268 {
2269 conf_report_error("%s overwrites existing port %hu",
2270 confstr, yy_opm_port_ipv4);
2271 return;
2272 }
2273
2274 yy_opm_port_ipv4 = port;
2275 }
2276 else
2277 {
2278 if(yy_opm_port_ipv6)
2279 {
2280 conf_report_error("%s overwrites existing port %hu",
2281 confstr, yy_opm_port_ipv6);
2282 return;
2283 }
2284
2285 yy_opm_port_ipv6 = port;
2286 }
2287 }
2288
2289 static void
2290 conf_set_opm_listen_port_ipv4(void *data)
2291 {
2292 conf_set_opm_listen_port_both(data, false);
2293 }
2294
2295 static void
2296 conf_set_opm_listen_port_ipv6(void *data)
2297 {
2298 conf_set_opm_listen_port_both(data, true);
2299 }
2300
2301 static void
2302 conf_set_opm_listen_port(void *data)
2303 {
2304 conf_set_opm_listen_port_both(data, true);
2305 conf_set_opm_listen_port_both(data, false);
2306 }
2307
2308 static void
2309 conf_set_opm_scan_ports_all(void *data, const char *node, const char *type)
2310 {
2311 conf_parm_t *args = data;
2312 for (; args; args = args->next)
2313 {
2314 rb_dlink_node *ptr;
2315 bool dup = false;
2316
2317 if(CF_TYPE(args->type) != CF_INT)
2318 {
2319 conf_report_error("%s argument is not an integer -- ignoring.", node);
2320 continue;
2321 }
2322
2323 if(args->v.number > 65535 || args->v.number <= 0)
2324 {
2325 conf_report_error("%s argument is not an integer between 1 and 65535 -- ignoring.", node);
2326 continue;
2327 }
2328
2329 /* Check for duplicates */
2330 RB_DLINK_FOREACH(ptr, yy_opm_scanner_list.head)
2331 {
2332 struct opm_scanner *scanner = ptr->data;
2333
2334 if(scanner->port == args->v.number && strcmp(type, scanner->type) == 0)
2335 {
2336 conf_report_error("%s argument is duplicate", node);
2337 dup = true;
2338 break;
2339 }
2340 }
2341
2342 if(!dup)
2343 {
2344 struct opm_scanner *scanner = rb_malloc(sizeof(struct opm_scanner));
2345 scanner->port = args->v.number;
2346 scanner->type = type;
2347 rb_dlinkAdd(scanner, &scanner->node, &yy_opm_scanner_list);
2348 }
2349 }
2350 }
2351
2352 static void
2353 conf_set_opm_scan_ports_socks4(void *data)
2354 {
2355 conf_set_opm_scan_ports_all(data, "opm::socks4_ports", "socks4");
2356 }
2357
2358 static void
2359 conf_set_opm_scan_ports_socks5(void *data)
2360 {
2361 conf_set_opm_scan_ports_all(data, "opm::socks5_ports", "socks5");
2362 }
2363
2364 static void
2365 conf_set_opm_scan_ports_httpconnect(void *data)
2366 {
2367 conf_set_opm_scan_ports_all(data, "opm::httpconnect_ports", "httpconnect");
2368 }
2369
2370 static void
2371 conf_set_opm_scan_ports_httpsconnect(void *data)
2372 {
2373 conf_set_opm_scan_ports_all(data, "opm::httpsconnect_ports", "httpsconnect");
2374 }
2375
2376 /* public functions */
2377
2378
2379 void
2380 conf_report_error(const char *fmt, ...)
2381 {
2382 va_list ap;
2383 char msg[BUFSIZE + 1] = { 0 };
2384
2385 va_start(ap, fmt);
2386 vsnprintf(msg, BUFSIZE, fmt, ap);
2387 va_end(ap);
2388
2389 if (testing_conf)
2390 {
2391 fprintf(stderr, "\"%s\", line %d: %s\n", current_file, lineno + 1, msg);
2392 return;
2393 }
2394
2395 ierror("\"%s\", line %d: %s", current_file, lineno + 1, msg);
2396 sendto_realops_snomask(SNO_GENERAL, L_ALL, "error: \"%s\", line %d: %s", current_file, lineno + 1, msg);
2397 }
2398
2399 void
2400 conf_report_warning(const char *fmt, ...)
2401 {
2402 va_list ap;
2403 char msg[BUFSIZE + 1] = { 0 };
2404
2405 va_start(ap, fmt);
2406 vsnprintf(msg, BUFSIZE, fmt, ap);
2407 va_end(ap);
2408
2409 if (testing_conf)
2410 {
2411 fprintf(stderr, "\"%s\", line %d: %s\n", current_file, lineno + 1, msg);
2412 return;
2413 }
2414
2415 iwarn("\"%s\", line %d: %s", current_file, lineno + 1, msg);
2416 sendto_realops_snomask(SNO_GENERAL, L_ALL, "warning: \"%s\", line %d: %s", current_file, lineno + 1, msg);
2417 }
2418
2419 int
2420 conf_start_block(char *block, char *name)
2421 {
2422 if((conf_cur_block = find_top_conf(block)) == NULL)
2423 {
2424 conf_report_error("Configuration block '%s' is not defined.", block);
2425 return -1;
2426 }
2427
2428 if(name)
2429 conf_cur_block_name = rb_strdup(name);
2430 else
2431 conf_cur_block_name = NULL;
2432
2433 if(conf_cur_block->tc_sfunc)
2434 if(conf_cur_block->tc_sfunc(conf_cur_block) < 0)
2435 return -1;
2436
2437 return 0;
2438 }
2439
2440 int
2441 conf_end_block(struct TopConf *tc)
2442 {
2443 int ret = 0;
2444 if(tc->tc_efunc)
2445 ret = tc->tc_efunc(tc);
2446
2447 rb_free(conf_cur_block_name);
2448 conf_cur_block_name = NULL;
2449 return ret;
2450 }
2451
2452 static void
2453 conf_set_generic_int(void *data, void *location)
2454 {
2455 *((int *) location) = *((unsigned int *) data);
2456 }
2457
2458 static void
2459 conf_set_generic_string(void *data, int len, void *location)
2460 {
2461 char **loc = location;
2462 char *input = data;
2463
2464 if(len && strlen(input) > (unsigned int)len)
2465 input[len] = '\0';
2466
2467 rb_free(*loc);
2468 *loc = rb_strdup(input);
2469 }
2470
2471 int
2472 conf_call_set(struct TopConf *tc, char *item, conf_parm_t * value)
2473 {
2474 struct ConfEntry *cf;
2475 conf_parm_t *cp;
2476
2477 if(!tc)
2478 return -1;
2479
2480 if((cf = find_conf_item(tc, item)) == NULL)
2481 {
2482 conf_report_error
2483 ("Non-existent configuration setting %s::%s.", tc->tc_name, (char *) item);
2484 return -1;
2485 }
2486
2487 /* if it takes one thing, make sure they only passed one thing,
2488 and handle as needed. */
2489 if((value->v.list->type & CF_FLIST) && !(cf->cf_type & CF_FLIST))
2490 {
2491 conf_report_error
2492 ("Option %s::%s does not take a list of values.", tc->tc_name, item);
2493 return -1;
2494 }
2495
2496 cp = value->v.list;
2497
2498
2499 if(CF_TYPE(value->v.list->type) != CF_TYPE(cf->cf_type))
2500 {
2501 /* if it expects a string value, but we got a yesno,
2502 * convert it back
2503 */
2504 if((CF_TYPE(value->v.list->type) == CF_YESNO) &&
2505 (CF_TYPE(cf->cf_type) == CF_STRING))
2506 {
2507 value->v.list->type = CF_STRING;
2508
2509 if(cp->v.number == 1)
2510 cp->v.string = rb_strdup("yes");
2511 else
2512 cp->v.string = rb_strdup("no");
2513 }
2514
2515 /* maybe it's a CF_TIME and they passed CF_INT --
2516 should still be valid */
2517 else if(!((CF_TYPE(value->v.list->type) == CF_INT) &&
2518 (CF_TYPE(cf->cf_type) == CF_TIME)))
2519 {
2520 conf_report_error
2521 ("Wrong type for %s::%s (expected %s, got %s)",
2522 tc->tc_name, (char *) item,
2523 conf_strtype(cf->cf_type), conf_strtype(value->v.list->type));
2524 return -1;
2525 }
2526 }
2527
2528 if(cf->cf_type & CF_FLIST)
2529 {
2530 #if 0
2531 if(cf->cf_arg)
2532 conf_set_generic_list(value->v.list, cf->cf_arg);
2533 else
2534 #endif
2535 /* just pass it the extended argument list */
2536 cf->cf_func(value->v.list);
2537 }
2538 else
2539 {
2540 /* it's old-style, needs only one arg */
2541 switch (cf->cf_type)
2542 {
2543 case CF_INT:
2544 case CF_TIME:
2545 case CF_YESNO:
2546 if(cf->cf_arg)
2547 conf_set_generic_int(&cp->v.number, cf->cf_arg);
2548 else
2549 cf->cf_func(&cp->v.number);
2550 break;
2551 case CF_STRING:
2552 case CF_QSTRING:
2553 if(EmptyString(cp->v.string))
2554 conf_report_error("Ignoring %s::%s -- empty field",
2555 tc->tc_name, item);
2556 else if(cf->cf_arg)
2557 conf_set_generic_string(cp->v.string, cf->cf_len, cf->cf_arg);
2558 else
2559 cf->cf_func(cp->v.string);
2560 break;
2561 }
2562 }
2563
2564
2565 return 0;
2566 }
2567
2568 int
2569 add_conf_item(const char *topconf, const char *name, int type, void (*func) (void *))
2570 {
2571 struct TopConf *tc;
2572 struct ConfEntry *cf;
2573
2574 if((tc = find_top_conf(topconf)) == NULL)
2575 return -1;
2576
2577 if(find_conf_item(tc, name) != NULL)
2578 return -1;
2579
2580 cf = rb_malloc(sizeof(struct ConfEntry));
2581
2582 cf->cf_name = name;
2583 cf->cf_type = type;
2584 cf->cf_func = func;
2585 cf->cf_arg = NULL;
2586
2587 rb_dlinkAddAlloc(cf, &tc->tc_items);
2588
2589 return 0;
2590 }
2591
2592 int
2593 remove_conf_item(const char *topconf, const char *name)
2594 {
2595 struct TopConf *tc;
2596 struct ConfEntry *cf;
2597 rb_dlink_node *ptr;
2598
2599 if((tc = find_top_conf(topconf)) == NULL)
2600 return -1;
2601
2602 if((cf = find_conf_item(tc, name)) == NULL)
2603 return -1;
2604
2605 if((ptr = rb_dlinkFind(cf, &tc->tc_items)) == NULL)
2606 return -1;
2607
2608 rb_dlinkDestroy(ptr, &tc->tc_items);
2609 rb_free(cf);
2610
2611 return 0;
2612 }
2613
2614 /* *INDENT-OFF* */
2615 static struct ConfEntry conf_serverinfo_table[] =
2616 {
2617 { "description", CF_QSTRING, NULL, 0, &ServerInfo.description },
2618
2619 { "network_name", CF_QSTRING, conf_set_serverinfo_network_name, 0, NULL },
2620 { "name", CF_QSTRING, conf_set_serverinfo_name, 0, NULL },
2621 { "sid", CF_QSTRING, conf_set_serverinfo_sid, 0, NULL },
2622 { "vhost", CF_QSTRING, conf_set_serverinfo_vhost, 0, NULL },
2623 { "vhost6", CF_QSTRING, conf_set_serverinfo_vhost6, 0, NULL },
2624
2625 { "ssl_private_key", CF_QSTRING, NULL, 0, &ServerInfo.ssl_private_key },
2626 { "ssl_ca_cert", CF_QSTRING, NULL, 0, &ServerInfo.ssl_ca_cert },
2627 { "ssl_cert", CF_QSTRING, NULL, 0, &ServerInfo.ssl_cert },
2628 { "ssl_dh_params", CF_QSTRING, NULL, 0, &ServerInfo.ssl_dh_params },
2629 { "ssl_cipher_list", CF_QSTRING, NULL, 0, &ServerInfo.ssl_cipher_list },
2630 { "ssld_count", CF_INT, NULL, 0, &ServerInfo.ssld_count },
2631
2632 { "default_max_clients",CF_INT, NULL, 0, &ServerInfo.default_max_clients },
2633
2634 { "nicklen", CF_INT, conf_set_serverinfo_nicklen, 0, NULL },
2635
2636 { "\0", 0, NULL, 0, NULL }
2637 };
2638
2639 static struct ConfEntry conf_admin_table[] =
2640 {
2641 { "name", CF_QSTRING, NULL, 200, &AdminInfo.name },
2642 { "description",CF_QSTRING, NULL, 200, &AdminInfo.description },
2643 { "email", CF_QSTRING, NULL, 200, &AdminInfo.email },
2644 { "\0", 0, NULL, 0, NULL }
2645 };
2646
2647 static struct ConfEntry conf_log_table[] =
2648 {
2649 { "fname_userlog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_userlog },
2650 { "fname_fuserlog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_fuserlog },
2651 { "fname_operlog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_operlog },
2652 { "fname_foperlog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_foperlog },
2653 { "fname_serverlog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_serverlog },
2654 { "fname_killlog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_killlog },
2655 { "fname_klinelog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_klinelog },
2656 { "fname_operspylog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_operspylog },
2657 { "fname_ioerrorlog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_ioerrorlog },
2658 { "\0", 0, NULL, 0, NULL }
2659 };
2660
2661 static struct ConfEntry conf_operator_table[] =
2662 {
2663 { "rsa_public_key_file", CF_QSTRING, conf_set_oper_rsa_public_key_file, 0, NULL },
2664 { "flags", CF_STRING | CF_FLIST, conf_set_oper_flags, 0, NULL },
2665 { "umodes", CF_STRING | CF_FLIST, conf_set_oper_umodes, 0, NULL },
2666 { "privset", CF_QSTRING, conf_set_oper_privset, 0, NULL },
2667 { "snomask", CF_QSTRING, conf_set_oper_snomask, 0, NULL },
2668 { "user", CF_QSTRING, conf_set_oper_user, 0, NULL },
2669 { "password", CF_QSTRING, conf_set_oper_password, 0, NULL },
2670 { "fingerprint", CF_QSTRING, conf_set_oper_fingerprint, 0, NULL },
2671 { "\0", 0, NULL, 0, NULL }
2672 };
2673
2674 static struct ConfEntry conf_privset_table[] =
2675 {
2676 { "extends", CF_QSTRING, conf_set_privset_extends, 0, NULL },
2677 { "privs", CF_STRING | CF_FLIST, conf_set_privset_privs, 0, NULL },
2678 { "\0", 0, NULL, 0, NULL }
2679 };
2680
2681 static struct ConfEntry conf_class_table[] =
2682 {
2683 { "ping_time", CF_TIME, conf_set_class_ping_time, 0, NULL },
2684 { "cidr_ipv4_bitlen", CF_INT, conf_set_class_cidr_ipv4_bitlen, 0, NULL },
2685 { "cidr_ipv6_bitlen", CF_INT, conf_set_class_cidr_ipv6_bitlen, 0, NULL },
2686 { "number_per_cidr", CF_INT, conf_set_class_number_per_cidr, 0, NULL },
2687 { "number_per_ip", CF_INT, conf_set_class_number_per_ip, 0, NULL },
2688 { "number_per_ip_global", CF_INT,conf_set_class_number_per_ip_global, 0, NULL },
2689 { "number_per_ident", CF_INT, conf_set_class_number_per_ident, 0, NULL },
2690 { "connectfreq", CF_TIME, conf_set_class_connectfreq, 0, NULL },
2691 { "max_number", CF_INT, conf_set_class_max_number, 0, NULL },
2692 { "sendq", CF_TIME, conf_set_class_sendq, 0, NULL },
2693 { "\0", 0, NULL, 0, NULL }
2694 };
2695
2696 static struct ConfEntry conf_auth_table[] =
2697 {
2698 { "user", CF_QSTRING, conf_set_auth_user, 0, NULL },
2699 { "auth_user", CF_QSTRING, conf_set_auth_auth_user, 0, NULL },
2700 { "password", CF_QSTRING, conf_set_auth_passwd, 0, NULL },
2701 { "class", CF_QSTRING, conf_set_auth_class, 0, NULL },
2702 { "spoof", CF_QSTRING, conf_set_auth_spoof, 0, NULL },
2703 { "redirserv", CF_QSTRING, conf_set_auth_redir_serv, 0, NULL },
2704 { "redirport", CF_INT, conf_set_auth_redir_port, 0, NULL },
2705 { "flags", CF_STRING | CF_FLIST, conf_set_auth_flags, 0, NULL },
2706 { "\0", 0, NULL, 0, NULL }
2707 };
2708
2709 static struct ConfEntry conf_connect_table[] =
2710 {
2711 { "send_password", CF_QSTRING, conf_set_connect_send_password, 0, NULL },
2712 { "accept_password", CF_QSTRING, conf_set_connect_accept_password, 0, NULL },
2713 { "fingerprint", CF_QSTRING, conf_set_connect_fingerprint, 0, NULL },
2714 { "flags", CF_STRING | CF_FLIST, conf_set_connect_flags, 0, NULL },
2715 { "host", CF_QSTRING, conf_set_connect_host, 0, NULL },
2716 { "vhost", CF_QSTRING, conf_set_connect_vhost, 0, NULL },
2717 { "port", CF_INT, conf_set_connect_port, 0, NULL },
2718 { "aftype", CF_STRING, conf_set_connect_aftype, 0, NULL },
2719 { "hub_mask", CF_QSTRING, conf_set_connect_hub_mask, 0, NULL },
2720 { "leaf_mask", CF_QSTRING, conf_set_connect_leaf_mask, 0, NULL },
2721 { "class", CF_QSTRING, conf_set_connect_class, 0, NULL },
2722 { "\0", 0, NULL, 0, NULL }
2723 };
2724
2725 static struct ConfEntry conf_general_table[] =
2726 {
2727 { "oper_only_umodes", CF_STRING | CF_FLIST, conf_set_general_oper_only_umodes, 0, NULL },
2728 { "oper_umodes", CF_STRING | CF_FLIST, conf_set_general_oper_umodes, 0, NULL },
2729 { "oper_snomask", CF_QSTRING, conf_set_general_oper_snomask, 0, NULL },
2730 { "compression_level", CF_INT, conf_set_general_compression_level, 0, NULL },
2731 { "havent_read_conf", CF_YESNO, conf_set_general_havent_read_conf, 0, NULL },
2732 { "hide_error_messages",CF_STRING, conf_set_general_hide_error_messages,0, NULL },
2733 { "stats_k_oper_only", CF_STRING, conf_set_general_stats_k_oper_only, 0, NULL },
2734 { "stats_i_oper_only", CF_STRING, conf_set_general_stats_i_oper_only, 0, NULL },
2735 { "default_umodes", CF_QSTRING, conf_set_general_default_umodes, 0, NULL },
2736
2737 { "default_operstring", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.default_operstring },
2738 { "default_adminstring",CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.default_adminstring },
2739 { "servicestring", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.servicestring },
2740 { "kline_reason", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.kline_reason },
2741 { "identify_service", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.identifyservice },
2742 { "identify_command", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.identifycommand },
2743 { "sasl_service", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.sasl_service },
2744
2745 { "anti_spam_exit_message_time", CF_TIME, NULL, 0, &ConfigFileEntry.anti_spam_exit_message_time },
2746 { "disable_fake_channels", CF_YESNO, NULL, 0, &ConfigFileEntry.disable_fake_channels },
2747 { "min_nonwildcard_simple", CF_INT, NULL, 0, &ConfigFileEntry.min_nonwildcard_simple },
2748 { "non_redundant_klines", CF_YESNO, NULL, 0, &ConfigFileEntry.non_redundant_klines },
2749 { "tkline_expire_notices", CF_YESNO, NULL, 0, &ConfigFileEntry.tkline_expire_notices },
2750
2751 { "anti_nick_flood", CF_YESNO, NULL, 0, &ConfigFileEntry.anti_nick_flood },
2752 { "burst_away", CF_YESNO, NULL, 0, &ConfigFileEntry.burst_away },
2753 { "caller_id_wait", CF_TIME, NULL, 0, &ConfigFileEntry.caller_id_wait },
2754 { "client_exit", CF_YESNO, NULL, 0, &ConfigFileEntry.client_exit },
2755 { "collision_fnc", CF_YESNO, NULL, 0, &ConfigFileEntry.collision_fnc },
2756 { "resv_fnc", CF_YESNO, NULL, 0, &ConfigFileEntry.resv_fnc },
2757 { "post_registration_delay", CF_TIME, NULL, 0, &ConfigFileEntry.post_registration_delay },
2758 { "connect_timeout", CF_TIME, NULL, 0, &ConfigFileEntry.connect_timeout },
2759 { "default_floodcount", CF_INT, NULL, 0, &ConfigFileEntry.default_floodcount },
2760 { "default_ident_timeout", CF_INT, NULL, 0, &ConfigFileEntry.default_ident_timeout },
2761 { "disable_auth", CF_YESNO, NULL, 0, &ConfigFileEntry.disable_auth },
2762 { "dots_in_ident", CF_INT, NULL, 0, &ConfigFileEntry.dots_in_ident },
2763 { "failed_oper_notice", CF_YESNO, NULL, 0, &ConfigFileEntry.failed_oper_notice },
2764 { "global_snotices", CF_YESNO, NULL, 0, &ConfigFileEntry.global_snotices },
2765 { "hide_spoof_ips", CF_YESNO, NULL, 0, &ConfigFileEntry.hide_spoof_ips },
2766 { "dline_with_reason", CF_YESNO, NULL, 0, &ConfigFileEntry.dline_with_reason },
2767 { "kline_with_reason", CF_YESNO, NULL, 0, &ConfigFileEntry.kline_with_reason },
2768 { "hide_tkdline_duration", CF_YESNO, NULL, 0, &ConfigFileEntry.hide_tkdline_duration },
2769 { "map_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.map_oper_only },
2770 { "max_accept", CF_INT, NULL, 0, &ConfigFileEntry.max_accept },
2771 { "max_monitor", CF_INT, NULL, 0, &ConfigFileEntry.max_monitor },
2772 { "max_nick_time", CF_TIME, NULL, 0, &ConfigFileEntry.max_nick_time },
2773 { "max_nick_changes", CF_INT, NULL, 0, &ConfigFileEntry.max_nick_changes },
2774 { "max_targets", CF_INT, NULL, 0, &ConfigFileEntry.max_targets },
2775 { "min_nonwildcard", CF_INT, NULL, 0, &ConfigFileEntry.min_nonwildcard },
2776 { "nick_delay", CF_TIME, NULL, 0, &ConfigFileEntry.nick_delay },
2777 { "no_oper_flood", CF_YESNO, NULL, 0, &ConfigFileEntry.no_oper_flood },
2778 { "operspy_admin_only", CF_YESNO, NULL, 0, &ConfigFileEntry.operspy_admin_only },
2779 { "operspy_dont_care_user_info", CF_YESNO, NULL, 0, &ConfigFileEntry.operspy_dont_care_user_info },
2780 { "pace_wait", CF_TIME, NULL, 0, &ConfigFileEntry.pace_wait },
2781 { "pace_wait_simple", CF_TIME, NULL, 0, &ConfigFileEntry.pace_wait_simple },
2782 { "ping_cookie", CF_YESNO, NULL, 0, &ConfigFileEntry.ping_cookie },
2783 { "reject_after_count", CF_INT, NULL, 0, &ConfigFileEntry.reject_after_count },
2784 { "reject_ban_time", CF_TIME, NULL, 0, &ConfigFileEntry.reject_ban_time },
2785 { "reject_duration", CF_TIME, NULL, 0, &ConfigFileEntry.reject_duration },
2786 { "throttle_count", CF_INT, NULL, 0, &ConfigFileEntry.throttle_count },
2787 { "throttle_duration", CF_TIME, NULL, 0, &ConfigFileEntry.throttle_duration },
2788 { "short_motd", CF_YESNO, NULL, 0, &ConfigFileEntry.short_motd },
2789 { "stats_c_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_c_oper_only },
2790 { "stats_e_disabled", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_e_disabled },
2791 { "stats_h_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_h_oper_only },
2792 { "stats_o_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_o_oper_only },
2793 { "stats_P_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_P_oper_only },
2794 { "stats_y_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_y_oper_only },
2795 { "target_change", CF_YESNO, NULL, 0, &ConfigFileEntry.target_change },
2796 { "ts_max_delta", CF_TIME, NULL, 0, &ConfigFileEntry.ts_max_delta },
2797 { "ts_warn_delta", CF_TIME, NULL, 0, &ConfigFileEntry.ts_warn_delta },
2798 { "use_whois_actually", CF_YESNO, NULL, 0, &ConfigFileEntry.use_whois_actually },
2799 { "warn_no_nline", CF_YESNO, NULL, 0, &ConfigFileEntry.warn_no_nline },
2800 { "use_propagated_bans",CF_YESNO, NULL, 0, &ConfigFileEntry.use_propagated_bans },
2801 { "client_flood_max_lines", CF_INT, NULL, 0, &ConfigFileEntry.client_flood_max_lines },
2802 { "client_flood_burst_rate", CF_INT, NULL, 0, &ConfigFileEntry.client_flood_burst_rate },
2803 { "client_flood_burst_max", CF_INT, NULL, 0, &ConfigFileEntry.client_flood_burst_max },
2804 { "client_flood_message_num", CF_INT, NULL, 0, &ConfigFileEntry.client_flood_message_num },
2805 { "client_flood_message_time", CF_INT, NULL, 0, &ConfigFileEntry.client_flood_message_time },
2806 { "max_ratelimit_tokens", CF_INT, NULL, 0, &ConfigFileEntry.max_ratelimit_tokens },
2807 { "away_interval", CF_INT, NULL, 0, &ConfigFileEntry.away_interval },
2808 { "hide_opers_in_whois", CF_YESNO, NULL, 0, &ConfigFileEntry.hide_opers_in_whois },
2809 { "hide_opers", CF_YESNO, NULL, 0, &ConfigFileEntry.hide_opers },
2810 { "certfp_method", CF_STRING, conf_set_general_certfp_method, 0, NULL },
2811 { "drain_reason", CF_QSTRING, NULL, BUFSIZE, &ConfigFileEntry.drain_reason },
2812 { "tls_ciphers_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.tls_ciphers_oper_only },
2813 { "\0", 0, NULL, 0, NULL }
2814 };
2815
2816 static struct ConfEntry conf_channel_table[] =
2817 {
2818 { "default_split_user_count", CF_INT, NULL, 0, &ConfigChannel.default_split_user_count },
2819 { "default_split_server_count", CF_INT, NULL, 0, &ConfigChannel.default_split_server_count },
2820 { "burst_topicwho", CF_YESNO, NULL, 0, &ConfigChannel.burst_topicwho },
2821 { "kick_on_split_riding", CF_YESNO, NULL, 0, &ConfigChannel.kick_on_split_riding },
2822 { "knock_delay", CF_TIME, NULL, 0, &ConfigChannel.knock_delay },
2823 { "knock_delay_channel",CF_TIME, NULL, 0, &ConfigChannel.knock_delay_channel },
2824 { "max_bans", CF_INT, NULL, 0, &ConfigChannel.max_bans },
2825 { "max_bans_large", CF_INT, NULL, 0, &ConfigChannel.max_bans_large },
2826 { "max_chans_per_user", CF_INT, NULL, 0, &ConfigChannel.max_chans_per_user },
2827 { "max_chans_per_user_large", CF_INT, NULL, 0, &ConfigChannel.max_chans_per_user_large },
2828 { "no_create_on_split", CF_YESNO, NULL, 0, &ConfigChannel.no_create_on_split },
2829 { "no_join_on_split", CF_YESNO, NULL, 0, &ConfigChannel.no_join_on_split },
2830 { "only_ascii_channels", CF_YESNO, NULL, 0, &ConfigChannel.only_ascii_channels },
2831 { "use_except", CF_YESNO, NULL, 0, &ConfigChannel.use_except },
2832 { "use_invex", CF_YESNO, NULL, 0, &ConfigChannel.use_invex },
2833 { "use_forward", CF_YESNO, NULL, 0, &ConfigChannel.use_forward },
2834 { "use_knock", CF_YESNO, NULL, 0, &ConfigChannel.use_knock },
2835 { "resv_forcepart", CF_YESNO, NULL, 0, &ConfigChannel.resv_forcepart },
2836 { "channel_target_change", CF_YESNO, NULL, 0, &ConfigChannel.channel_target_change },
2837 { "disable_local_channels", CF_YESNO, NULL, 0, &ConfigChannel.disable_local_channels },
2838 { "autochanmodes", CF_QSTRING, conf_set_channel_autochanmodes, 0, NULL },
2839 { "displayed_usercount", CF_INT, NULL, 0, &ConfigChannel.displayed_usercount },
2840 { "strip_topic_colors", CF_YESNO, NULL, 0, &ConfigChannel.strip_topic_colors },
2841 { "opmod_send_statusmsg", CF_YESNO, NULL, 0, &ConfigChannel.opmod_send_statusmsg },
2842 { "\0", 0, NULL, 0, NULL }
2843 };
2844
2845 static struct ConfEntry conf_serverhide_table[] =
2846 {
2847 { "disable_hidden", CF_YESNO, NULL, 0, &ConfigServerHide.disable_hidden },
2848 { "flatten_links", CF_YESNO, NULL, 0, &ConfigServerHide.flatten_links },
2849 { "hidden", CF_YESNO, NULL, 0, &ConfigServerHide.hidden },
2850 { "links_delay", CF_TIME, conf_set_serverhide_links_delay, 0, NULL },
2851 { "\0", 0, NULL, 0, NULL }
2852 };
2853 /* *INDENT-ON* */
2854
2855 void
2856 newconf_init()
2857 {
2858 add_top_conf("modules", NULL, NULL, NULL);
2859 add_conf_item("modules", "path", CF_QSTRING, conf_set_modules_path);
2860 add_conf_item("modules", "module", CF_QSTRING, conf_set_modules_module);
2861
2862 add_top_conf("serverinfo", NULL, NULL, conf_serverinfo_table);
2863 add_top_conf("admin", NULL, NULL, conf_admin_table);
2864 add_top_conf("log", NULL, NULL, conf_log_table);
2865 add_top_conf("operator", conf_begin_oper, conf_end_oper, conf_operator_table);
2866 add_top_conf("class", conf_begin_class, conf_end_class, conf_class_table);
2867 add_top_conf("privset", NULL, NULL, conf_privset_table);
2868
2869 add_top_conf("listen", conf_begin_listen, conf_end_listen, NULL);
2870 add_conf_item("listen", "defer_accept", CF_YESNO, conf_set_listen_defer_accept);
2871 add_conf_item("listen", "wsock", CF_YESNO, conf_set_listen_wsock);
2872 add_conf_item("listen", "port", CF_INT | CF_FLIST, conf_set_listen_port);
2873 add_conf_item("listen", "sslport", CF_INT | CF_FLIST, conf_set_listen_sslport);
2874 add_conf_item("listen", "sctp_port", CF_INT | CF_FLIST, conf_set_listen_sctp_port);
2875 add_conf_item("listen", "sctp_sslport", CF_INT | CF_FLIST, conf_set_listen_sctp_sslport);
2876 add_conf_item("listen", "ip", CF_QSTRING, conf_set_listen_address);
2877 add_conf_item("listen", "host", CF_QSTRING, conf_set_listen_address);
2878
2879 add_top_conf("auth", conf_begin_auth, conf_end_auth, conf_auth_table);
2880
2881 add_top_conf("shared", conf_cleanup_shared, conf_cleanup_shared, NULL);
2882 add_conf_item("shared", "oper", CF_QSTRING | CF_FLIST, conf_set_shared_oper);
2883 add_conf_item("shared", "flags", CF_STRING | CF_FLIST, conf_set_shared_flags);
2884
2885 add_top_conf("connect", conf_begin_connect, conf_end_connect, conf_connect_table);
2886
2887 add_top_conf("exempt", NULL, NULL, NULL);
2888 add_conf_item("exempt", "ip", CF_QSTRING, conf_set_exempt_ip);
2889
2890 add_top_conf("cluster", conf_cleanup_cluster, conf_cleanup_cluster, NULL);
2891 add_conf_item("cluster", "name", CF_QSTRING, conf_set_cluster_name);
2892 add_conf_item("cluster", "flags", CF_STRING | CF_FLIST, conf_set_cluster_flags);
2893
2894 add_top_conf("general", NULL, NULL, conf_general_table);
2895 add_top_conf("channel", NULL, NULL, conf_channel_table);
2896 add_top_conf("serverhide", NULL, NULL, conf_serverhide_table);
2897
2898 add_top_conf("service", NULL, NULL, NULL);
2899 add_conf_item("service", "name", CF_QSTRING, conf_set_service_name);
2900
2901 add_top_conf("alias", conf_begin_alias, conf_end_alias, NULL);
2902 add_conf_item("alias", "name", CF_QSTRING, conf_set_alias_name);
2903 add_conf_item("alias", "target", CF_QSTRING, conf_set_alias_target);
2904
2905 add_top_conf("dnsbl", NULL, NULL, NULL);
2906 add_conf_item("dnsbl", "host", CF_QSTRING, conf_set_dnsbl_entry_host);
2907 add_conf_item("dnsbl", "type", CF_STRING | CF_FLIST, conf_set_dnsbl_entry_type);
2908 add_conf_item("dnsbl", "matches", CF_QSTRING | CF_FLIST, conf_set_dnsbl_entry_matches);
2909 add_conf_item("dnsbl", "reject_reason", CF_QSTRING, conf_set_dnsbl_entry_reason);
2910
2911 add_top_conf("blacklist", conf_warn_blacklist_deprecation, NULL, NULL);
2912 add_conf_item("blacklist", "host", CF_QSTRING, conf_set_dnsbl_entry_host);
2913 add_conf_item("blacklist", "type", CF_STRING | CF_FLIST, conf_set_dnsbl_entry_type);
2914 add_conf_item("blacklist", "matches", CF_QSTRING | CF_FLIST, conf_set_dnsbl_entry_matches);
2915 add_conf_item("blacklist", "reject_reason", CF_QSTRING, conf_set_dnsbl_entry_reason);
2916
2917 add_top_conf("opm", conf_begin_opm, conf_end_opm, NULL);
2918 add_conf_item("opm", "timeout", CF_INT, conf_set_opm_timeout);
2919 add_conf_item("opm", "listen_ipv4", CF_QSTRING, conf_set_opm_listen_address_ipv4);
2920 add_conf_item("opm", "listen_ipv6", CF_QSTRING, conf_set_opm_listen_address_ipv6);
2921 add_conf_item("opm", "port_v4", CF_INT, conf_set_opm_listen_port_ipv4);
2922 add_conf_item("opm", "port_v6", CF_INT, conf_set_opm_listen_port_ipv6);
2923 add_conf_item("opm", "listen_port", CF_INT, conf_set_opm_listen_port);
2924 add_conf_item("opm", "socks4_ports", CF_INT | CF_FLIST, conf_set_opm_scan_ports_socks4);
2925 add_conf_item("opm", "socks5_ports", CF_INT | CF_FLIST, conf_set_opm_scan_ports_socks5);
2926 add_conf_item("opm", "httpconnect_ports", CF_INT | CF_FLIST, conf_set_opm_scan_ports_httpconnect);
2927 add_conf_item("opm", "httpsconnect_ports", CF_INT | CF_FLIST, conf_set_opm_scan_ports_httpsconnect);
2928 }