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