]> jfr.im git - solanum.git/blob - src/newconf.c
Avoid wrong detection of redundant/duplicate auth blocks with auth_user.
[solanum.git] / src / newconf.c
1 /* This code is in the public domain.
2 * $Id: newconf.c 3550 2007-08-09 06:47:26Z nenolod $
3 */
4
5 #include "stdinc.h"
6
7 #ifdef HAVE_LIBCRYPTO
8 #include <openssl/pem.h>
9 #include <openssl/rsa.h>
10 #endif
11
12 #include "newconf.h"
13 #include "ircd_defs.h"
14 #include "common.h"
15 #include "logger.h"
16 #include "s_conf.h"
17 #include "s_user.h"
18 #include "s_newconf.h"
19 #include "send.h"
20 #include "setup.h"
21 #include "modules.h"
22 #include "listener.h"
23 #include "hostmask.h"
24 #include "s_serv.h"
25 #include "hash.h"
26 #include "cache.h"
27 #include "ircd.h"
28 #include "snomask.h"
29 #include "blacklist.h"
30 #include "sslproc.h"
31 #include "privilege.h"
32
33 #define CF_TYPE(x) ((x) & CF_MTYPE)
34
35 static int yy_defer_accept = 1;
36
37 struct TopConf *conf_cur_block;
38 static char *conf_cur_block_name;
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 int yy_blacklist_ipv4 = 1;
60 static int yy_blacklist_ipv6 = 0;
61 static rb_dlink_list yy_blacklist_filters;
62
63 static char *yy_privset_extends = NULL;
64
65 static const char *
66 conf_strtype(int type)
67 {
68 switch (type & CF_MTYPE)
69 {
70 case CF_INT:
71 return "integer value";
72 case CF_STRING:
73 return "unquoted string";
74 case CF_YESNO:
75 return "yes/no value";
76 case CF_QSTRING:
77 return "quoted string";
78 case CF_TIME:
79 return "time/size value";
80 default:
81 return "unknown type";
82 }
83 }
84
85 int
86 add_top_conf(const char *name, int (*sfunc) (struct TopConf *),
87 int (*efunc) (struct TopConf *), struct ConfEntry *items)
88 {
89 struct TopConf *tc;
90
91 tc = rb_malloc(sizeof(struct TopConf));
92
93 tc->tc_name = name;
94 tc->tc_sfunc = sfunc;
95 tc->tc_efunc = efunc;
96 tc->tc_entries = items;
97
98 rb_dlinkAddAlloc(tc, &conf_items);
99 return 0;
100 }
101
102 struct TopConf *
103 find_top_conf(const char *name)
104 {
105 rb_dlink_node *d;
106 struct TopConf *tc;
107
108 RB_DLINK_FOREACH(d, conf_items.head)
109 {
110 tc = d->data;
111 if(strcasecmp(tc->tc_name, name) == 0)
112 return tc;
113 }
114
115 return NULL;
116 }
117
118
119 struct ConfEntry *
120 find_conf_item(const struct TopConf *top, const char *name)
121 {
122 struct ConfEntry *cf;
123 rb_dlink_node *d;
124
125 if(top->tc_entries)
126 {
127 int i;
128
129 for(i = 0; top->tc_entries[i].cf_type; i++)
130 {
131 cf = &top->tc_entries[i];
132
133 if(!strcasecmp(cf->cf_name, name))
134 return cf;
135 }
136 }
137
138 RB_DLINK_FOREACH(d, top->tc_items.head)
139 {
140 cf = d->data;
141 if(strcasecmp(cf->cf_name, name) == 0)
142 return cf;
143 }
144
145 return NULL;
146 }
147
148 int
149 remove_top_conf(char *name)
150 {
151 struct TopConf *tc;
152 rb_dlink_node *ptr;
153
154 if((tc = find_top_conf(name)) == NULL)
155 return -1;
156
157 if((ptr = rb_dlinkFind(tc, &conf_items)) == NULL)
158 return -1;
159
160 rb_dlinkDestroy(ptr, &conf_items);
161 rb_free(tc);
162
163 return 0;
164 }
165
166 static void
167 conf_set_serverinfo_name(void *data)
168 {
169 if(ServerInfo.name == NULL)
170 {
171 const char *s;
172 int dots = 0;
173
174 for(s = data; *s != '\0'; s++)
175 {
176 if(!IsServChar(*s))
177 {
178 conf_report_error("Ignoring serverinfo::name "
179 "-- bogus servername.");
180 return;
181 }
182 else if(*s == '.')
183 ++dots;
184 }
185
186 if(!dots)
187 {
188 conf_report_error("Ignoring serverinfo::name -- must contain '.'");
189 return;
190 }
191
192 s = data;
193
194 if(IsDigit(*s))
195 {
196 conf_report_error("Ignoring serverinfo::name -- cannot begin with digit.");
197 return;
198 }
199
200 /* the ircd will exit() in main() if we dont set one */
201 if(strlen(s) <= HOSTLEN)
202 ServerInfo.name = rb_strdup((char *) data);
203 }
204 }
205
206 static void
207 conf_set_serverinfo_sid(void *data)
208 {
209 char *sid = data;
210
211 if(ServerInfo.sid[0] == '\0')
212 {
213 if(!IsDigit(sid[0]) || !IsIdChar(sid[1]) ||
214 !IsIdChar(sid[2]) || sid[3] != '\0')
215 {
216 conf_report_error("Ignoring serverinfo::sid "
217 "-- bogus sid.");
218 return;
219 }
220
221 strcpy(ServerInfo.sid, sid);
222 }
223 }
224
225 static void
226 conf_set_serverinfo_network_name(void *data)
227 {
228 char *p;
229
230 if((p = strchr((char *) data, ' ')))
231 *p = '\0';
232
233 rb_free(ServerInfo.network_name);
234 ServerInfo.network_name = rb_strdup((char *) data);
235 }
236
237 static void
238 conf_set_serverinfo_vhost(void *data)
239 {
240 if(rb_inet_pton(AF_INET, (char *) data, &ServerInfo.ip.sin_addr) <= 0)
241 {
242 conf_report_error("Invalid netmask for server IPv4 vhost (%s)", (char *) data);
243 return;
244 }
245 ServerInfo.ip.sin_family = AF_INET;
246 ServerInfo.specific_ipv4_vhost = 1;
247 }
248
249 static void
250 conf_set_serverinfo_vhost6(void *data)
251 {
252 #ifdef RB_IPV6
253 if(rb_inet_pton(AF_INET6, (char *) data, &ServerInfo.ip6.sin6_addr) <= 0)
254 {
255 conf_report_error("Invalid netmask for server IPv6 vhost (%s)", (char *) data);
256 return;
257 }
258
259 ServerInfo.specific_ipv6_vhost = 1;
260 ServerInfo.ip6.sin6_family = AF_INET6;
261 #else
262 conf_report_error("Warning -- ignoring serverinfo::vhost6 -- IPv6 support not available.");
263 #endif
264 }
265
266 static void
267 conf_set_serverinfo_nicklen(void *data)
268 {
269 ConfigFileEntry.nicklen = (*(unsigned int *) data) + 1;
270
271 if (ConfigFileEntry.nicklen > NICKLEN)
272 {
273 conf_report_error("Warning -- ignoring serverinfo::nicklen -- provided nicklen (%u) is greater than allowed nicklen (%u)",
274 ConfigFileEntry.nicklen - 1, NICKLEN - 1);
275 ConfigFileEntry.nicklen = NICKLEN;
276 }
277 else if (ConfigFileEntry.nicklen < 9 + 1)
278 {
279 conf_report_error("Warning -- serverinfo::nicklen is too low (%u) -- forcing 9",
280 ConfigFileEntry.nicklen);
281 ConfigFileEntry.nicklen = 9 + 1;
282 }
283 }
284
285 static void
286 conf_set_modules_module(void *data)
287 {
288 #ifndef STATIC_MODULES
289 char *m_bn;
290
291 m_bn = rb_basename((char *) data);
292
293 if(findmodule_byname(m_bn) != -1)
294 return;
295
296 load_one_module((char *) data, 0);
297
298 rb_free(m_bn);
299 #else
300 conf_report_error("Ignoring modules::module -- loadable module support not present.");
301 #endif
302 }
303
304 static void
305 conf_set_modules_path(void *data)
306 {
307 #ifndef STATIC_MODULES
308 mod_add_path((char *) data);
309 #else
310 conf_report_error("Ignoring modules::path -- loadable module support not present.");
311 #endif
312 }
313
314 struct mode_table
315 {
316 const char *name;
317 int mode;
318 };
319
320 /* *INDENT-OFF* */
321 static struct mode_table umode_table[] = {
322 {"callerid", UMODE_CALLERID },
323 {"deaf", UMODE_DEAF },
324 {"invisible", UMODE_INVISIBLE },
325 {"locops", UMODE_LOCOPS },
326 {"noforward", UMODE_NOFORWARD },
327 {"regonlymsg", UMODE_REGONLYMSG},
328 {"servnotice", UMODE_SERVNOTICE},
329 {"wallop", UMODE_WALLOP },
330 {"operwall", UMODE_OPERWALL },
331 {NULL, 0}
332 };
333
334 static struct mode_table oper_table[] = {
335 {"encrypted", OPER_ENCRYPTED },
336 {"need_ssl", OPER_NEEDSSL },
337 {NULL, 0}
338 };
339
340 static struct mode_table auth_table[] = {
341 {"encrypted", CONF_FLAGS_ENCRYPTED },
342 {"spoof_notice", CONF_FLAGS_SPOOF_NOTICE },
343 {"exceed_limit", CONF_FLAGS_NOLIMIT },
344 {"dnsbl_exempt", CONF_FLAGS_EXEMPTDNSBL },
345 {"kline_exempt", CONF_FLAGS_EXEMPTKLINE },
346 {"flood_exempt", CONF_FLAGS_EXEMPTFLOOD },
347 {"spambot_exempt", CONF_FLAGS_EXEMPTSPAMBOT },
348 {"shide_exempt", CONF_FLAGS_EXEMPTSHIDE },
349 {"jupe_exempt", CONF_FLAGS_EXEMPTJUPE },
350 {"resv_exempt", CONF_FLAGS_EXEMPTRESV },
351 {"no_tilde", CONF_FLAGS_NO_TILDE },
352 {"need_ident", CONF_FLAGS_NEED_IDENTD },
353 {"have_ident", CONF_FLAGS_NEED_IDENTD },
354 {"need_ssl", CONF_FLAGS_NEED_SSL },
355 {"need_sasl", CONF_FLAGS_NEED_SASL },
356 {NULL, 0}
357 };
358
359 static struct mode_table connect_table[] = {
360 { "autoconn", SERVER_AUTOCONN },
361 { "compressed", SERVER_COMPRESSED },
362 { "encrypted", SERVER_ENCRYPTED },
363 { "topicburst", SERVER_TB },
364 { "ssl", SERVER_SSL },
365 { NULL, 0 },
366 };
367
368 static struct mode_table cluster_table[] = {
369 { "kline", SHARED_PKLINE },
370 { "tkline", SHARED_TKLINE },
371 { "unkline", SHARED_UNKLINE },
372 { "locops", SHARED_LOCOPS },
373 { "xline", SHARED_PXLINE },
374 { "txline", SHARED_TXLINE },
375 { "unxline", SHARED_UNXLINE },
376 { "resv", SHARED_PRESV },
377 { "tresv", SHARED_TRESV },
378 { "unresv", SHARED_UNRESV },
379 { "all", CLUSTER_ALL },
380 {NULL, 0}
381 };
382
383 static struct mode_table shared_table[] =
384 {
385 { "kline", SHARED_PKLINE|SHARED_TKLINE },
386 { "xline", SHARED_PXLINE|SHARED_TXLINE },
387 { "resv", SHARED_PRESV|SHARED_TRESV },
388 { "dline", SHARED_PDLINE|SHARED_TDLINE },
389 { "tdline", SHARED_TDLINE },
390 { "pdline", SHARED_PDLINE },
391 { "undline", SHARED_UNDLINE },
392 { "tkline", SHARED_TKLINE },
393 { "unkline", SHARED_UNKLINE },
394 { "txline", SHARED_TXLINE },
395 { "unxline", SHARED_UNXLINE },
396 { "tresv", SHARED_TRESV },
397 { "unresv", SHARED_UNRESV },
398 { "locops", SHARED_LOCOPS },
399 { "rehash", SHARED_REHASH },
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((args->type & CF_MTYPE) != 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_port_both(void *data, int ssl)
858 {
859 conf_parm_t *args = data;
860 for (; args; args = args->next)
861 {
862 if((args->type & CF_MTYPE) != CF_INT)
863 {
864 conf_report_error
865 ("listener::port argument is not an integer " "-- ignoring.");
866 continue;
867 }
868 if(listener_address == NULL)
869 {
870 add_listener(args->v.number, listener_address, AF_INET, ssl, yy_defer_accept);
871 #ifdef RB_IPV6
872 add_listener(args->v.number, listener_address, AF_INET6, ssl, yy_defer_accept);
873 #endif
874 }
875 else
876 {
877 int family;
878 #ifdef RB_IPV6
879 if(strchr(listener_address, ':') != NULL)
880 family = AF_INET6;
881 else
882 #endif
883 family = AF_INET;
884
885 add_listener(args->v.number, listener_address, family, ssl, yy_defer_accept);
886
887 }
888
889 }
890 }
891
892 static void
893 conf_set_listen_port(void *data)
894 {
895 conf_set_listen_port_both(data, 0);
896 }
897
898 static void
899 conf_set_listen_sslport(void *data)
900 {
901 conf_set_listen_port_both(data, 1);
902 }
903
904 static void
905 conf_set_listen_address(void *data)
906 {
907 rb_free(listener_address);
908 listener_address = rb_strdup(data);
909 }
910
911 static int
912 conf_begin_auth(struct TopConf *tc)
913 {
914 rb_dlink_node *ptr;
915 rb_dlink_node *next_ptr;
916
917 if(yy_aconf)
918 free_conf(yy_aconf);
919
920 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_aconf_list.head)
921 {
922 free_conf(ptr->data);
923 rb_dlinkDestroy(ptr, &yy_aconf_list);
924 }
925
926 yy_aconf = make_conf();
927 yy_aconf->status = CONF_CLIENT;
928
929 return 0;
930 }
931
932 static int
933 conf_end_auth(struct TopConf *tc)
934 {
935 struct ConfItem *yy_tmp, *found_conf;
936 rb_dlink_node *ptr;
937 rb_dlink_node *next_ptr;
938
939 if(EmptyString(yy_aconf->info.name))
940 yy_aconf->info.name = rb_strdup("NOMATCH");
941
942 /* didnt even get one ->host? */
943 if(EmptyString(yy_aconf->host))
944 {
945 conf_report_error("Ignoring auth block -- missing user@host");
946 return 0;
947 }
948
949 /* so the stacking works in order.. */
950 collapse(yy_aconf->user);
951 collapse(yy_aconf->host);
952 conf_add_class_to_conf(yy_aconf);
953 if ((found_conf = find_exact_conf_by_address("*", CONF_CLIENT, "*")) && found_conf->spasswd == NULL)
954 conf_report_error("Ignoring redundant auth block (after *@*)");
955 else if ((found_conf = find_exact_conf_by_address(yy_aconf->host, CONF_CLIENT, yy_aconf->user)) &&
956 (!found_conf->spasswd || (yy_aconf->spasswd &&
957 0 == irccmp(found_conf->spasswd, yy_aconf->spasswd))))
958 conf_report_error("Ignoring duplicate auth block for %s@%s",
959 yy_aconf->user, yy_aconf->host);
960 else
961 add_conf_by_address(yy_aconf->host, CONF_CLIENT, yy_aconf->user, yy_aconf->spasswd, yy_aconf);
962
963 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_aconf_list.head)
964 {
965 yy_tmp = ptr->data;
966
967 if(yy_aconf->passwd)
968 yy_tmp->passwd = rb_strdup(yy_aconf->passwd);
969
970 if(yy_aconf->spasswd)
971 yy_tmp->spasswd = rb_strdup(yy_aconf->spasswd);
972
973 /* this will always exist.. */
974 yy_tmp->info.name = rb_strdup(yy_aconf->info.name);
975
976 if(yy_aconf->className)
977 yy_tmp->className = rb_strdup(yy_aconf->className);
978
979 yy_tmp->flags = yy_aconf->flags;
980 yy_tmp->port = yy_aconf->port;
981
982 collapse(yy_tmp->user);
983 collapse(yy_tmp->host);
984
985 conf_add_class_to_conf(yy_tmp);
986
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_tmp->host, CONF_CLIENT, yy_tmp->user)) &&
990 (!found_conf->spasswd || (yy_tmp->spasswd &&
991 0 == irccmp(found_conf->spasswd, yy_tmp->spasswd))))
992 conf_report_error("Ignoring duplicate auth block for %s@%s",
993 yy_tmp->user, yy_tmp->host);
994 else
995 add_conf_by_address(yy_tmp->host, CONF_CLIENT, yy_tmp->user, yy_tmp->spasswd, yy_tmp);
996 rb_dlinkDestroy(ptr, &yy_aconf_list);
997 }
998
999 yy_aconf = NULL;
1000 return 0;
1001 }
1002
1003 static void
1004 conf_set_auth_user(void *data)
1005 {
1006 struct ConfItem *yy_tmp;
1007 char *p;
1008
1009 /* The first user= line doesn't allocate a new conf */
1010 if(!EmptyString(yy_aconf->host))
1011 {
1012 yy_tmp = make_conf();
1013 yy_tmp->status = CONF_CLIENT;
1014 }
1015 else
1016 yy_tmp = yy_aconf;
1017
1018 if((p = strchr(data, '@')))
1019 {
1020 *p++ = '\0';
1021
1022 yy_tmp->user = rb_strdup(data);
1023 yy_tmp->host = rb_strdup(p);
1024 }
1025 else
1026 {
1027 yy_tmp->user = rb_strdup("*");
1028 yy_tmp->host = rb_strdup(data);
1029 }
1030
1031 if(yy_aconf != yy_tmp)
1032 rb_dlinkAddAlloc(yy_tmp, &yy_aconf_list);
1033 }
1034
1035 static void
1036 conf_set_auth_auth_user(void *data)
1037 {
1038 if(yy_aconf->spasswd)
1039 memset(yy_aconf->spasswd, 0, strlen(yy_aconf->spasswd));
1040 rb_free(yy_aconf->spasswd);
1041 yy_aconf->spasswd = rb_strdup(data);
1042 }
1043
1044 static void
1045 conf_set_auth_passwd(void *data)
1046 {
1047 if(yy_aconf->passwd)
1048 memset(yy_aconf->passwd, 0, strlen(yy_aconf->passwd));
1049 rb_free(yy_aconf->passwd);
1050 yy_aconf->passwd = rb_strdup(data);
1051 }
1052
1053 static void
1054 conf_set_auth_spoof(void *data)
1055 {
1056 char *p;
1057 char *user = NULL;
1058 char *host = NULL;
1059
1060 host = data;
1061
1062 /* user@host spoof */
1063 if((p = strchr(host, '@')) != NULL)
1064 {
1065 *p = '\0';
1066 user = data;
1067 host = p+1;
1068
1069 if(EmptyString(user))
1070 {
1071 conf_report_error("Warning -- spoof ident empty.");
1072 return;
1073 }
1074
1075 if(strlen(user) > USERLEN)
1076 {
1077 conf_report_error("Warning -- spoof ident length invalid.");
1078 return;
1079 }
1080
1081 if(!valid_username(user))
1082 {
1083 conf_report_error("Warning -- invalid spoof (ident).");
1084 return;
1085 }
1086
1087 /* this must be restored! */
1088 *p = '@';
1089 }
1090
1091 if(EmptyString(host))
1092 {
1093 conf_report_error("Warning -- spoof host empty.");
1094 return;
1095 }
1096
1097 if(strlen(host) > HOSTLEN)
1098 {
1099 conf_report_error("Warning -- spoof host length invalid.");
1100 return;
1101 }
1102
1103 if(!valid_hostname(host))
1104 {
1105 conf_report_error("Warning -- invalid spoof (host).");
1106 return;
1107 }
1108
1109 rb_free(yy_aconf->info.name);
1110 yy_aconf->info.name = rb_strdup(data);
1111 yy_aconf->flags |= CONF_FLAGS_SPOOF_IP;
1112 }
1113
1114 static void
1115 conf_set_auth_flags(void *data)
1116 {
1117 conf_parm_t *args = data;
1118
1119 set_modes_from_table((int *) &yy_aconf->flags, "flag", auth_table, args);
1120 }
1121
1122 static void
1123 conf_set_auth_redir_serv(void *data)
1124 {
1125 yy_aconf->flags |= CONF_FLAGS_REDIR;
1126 rb_free(yy_aconf->info.name);
1127 yy_aconf->info.name = rb_strdup(data);
1128 }
1129
1130 static void
1131 conf_set_auth_redir_port(void *data)
1132 {
1133 int port = *(unsigned int *) data;
1134
1135 yy_aconf->flags |= CONF_FLAGS_REDIR;
1136 yy_aconf->port = port;
1137 }
1138
1139 static void
1140 conf_set_auth_class(void *data)
1141 {
1142 rb_free(yy_aconf->className);
1143 yy_aconf->className = rb_strdup(data);
1144 }
1145
1146 /* ok, shared_oper handles the stacking, shared_flags handles adding
1147 * things.. so all we need to do when we start and end a shared block, is
1148 * clean up anything thats been left over.
1149 */
1150 static int
1151 conf_cleanup_shared(struct TopConf *tc)
1152 {
1153 rb_dlink_node *ptr, *next_ptr;
1154
1155 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_shared_list.head)
1156 {
1157 free_remote_conf(ptr->data);
1158 rb_dlinkDestroy(ptr, &yy_shared_list);
1159 }
1160
1161 if(yy_shared != NULL)
1162 {
1163 free_remote_conf(yy_shared);
1164 yy_shared = NULL;
1165 }
1166
1167 return 0;
1168 }
1169
1170 static void
1171 conf_set_shared_oper(void *data)
1172 {
1173 conf_parm_t *args = data;
1174 const char *username;
1175 char *p;
1176
1177 if(yy_shared != NULL)
1178 free_remote_conf(yy_shared);
1179
1180 yy_shared = make_remote_conf();
1181
1182 if(args->next != NULL)
1183 {
1184 if((args->type & CF_MTYPE) != CF_QSTRING)
1185 {
1186 conf_report_error("Ignoring shared::oper -- server is not a qstring");
1187 return;
1188 }
1189
1190 yy_shared->server = rb_strdup(args->v.string);
1191 args = args->next;
1192 }
1193 else
1194 yy_shared->server = rb_strdup("*");
1195
1196 if((args->type & CF_MTYPE) != CF_QSTRING)
1197 {
1198 conf_report_error("Ignoring shared::oper -- oper is not a qstring");
1199 return;
1200 }
1201
1202 if((p = strchr(args->v.string, '@')) == NULL)
1203 {
1204 conf_report_error("Ignoring shard::oper -- oper is not a user@host");
1205 return;
1206 }
1207
1208 username = args->v.string;
1209 *p++ = '\0';
1210
1211 if(EmptyString(p))
1212 yy_shared->host = rb_strdup("*");
1213 else
1214 yy_shared->host = rb_strdup(p);
1215
1216 if(EmptyString(username))
1217 yy_shared->username = rb_strdup("*");
1218 else
1219 yy_shared->username = rb_strdup(username);
1220
1221 rb_dlinkAddAlloc(yy_shared, &yy_shared_list);
1222 yy_shared = NULL;
1223 }
1224
1225 static void
1226 conf_set_shared_flags(void *data)
1227 {
1228 conf_parm_t *args = data;
1229 int flags = 0;
1230 rb_dlink_node *ptr, *next_ptr;
1231
1232 if(yy_shared != NULL)
1233 free_remote_conf(yy_shared);
1234
1235 set_modes_from_table(&flags, "flag", shared_table, args);
1236
1237 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_shared_list.head)
1238 {
1239 yy_shared = ptr->data;
1240
1241 yy_shared->flags = flags;
1242 rb_dlinkDestroy(ptr, &yy_shared_list);
1243 rb_dlinkAddTail(yy_shared, &yy_shared->node, &shared_conf_list);
1244 }
1245
1246 yy_shared = NULL;
1247 }
1248
1249 static int
1250 conf_begin_connect(struct TopConf *tc)
1251 {
1252 if(yy_server)
1253 free_server_conf(yy_server);
1254
1255 yy_server = make_server_conf();
1256 yy_server->port = PORTNUM;
1257 yy_server->flags |= SERVER_TB;
1258
1259 if(conf_cur_block_name != NULL)
1260 yy_server->name = rb_strdup(conf_cur_block_name);
1261
1262 return 0;
1263 }
1264
1265 static int
1266 conf_end_connect(struct TopConf *tc)
1267 {
1268 if(EmptyString(yy_server->name))
1269 {
1270 conf_report_error("Ignoring connect block -- missing name.");
1271 return 0;
1272 }
1273
1274 if(ServerInfo.name != NULL && !irccmp(ServerInfo.name, yy_server->name))
1275 {
1276 conf_report_error("Ignoring connect block for %s -- name is equal to my own name.",
1277 yy_server->name);
1278 return 0;
1279 }
1280
1281 if((EmptyString(yy_server->passwd) || EmptyString(yy_server->spasswd)) && EmptyString(yy_server->certfp))
1282 {
1283 conf_report_error("Ignoring connect block for %s -- no fingerprint or password credentials provided.",
1284 yy_server->name);
1285 return 0;
1286 }
1287
1288 if(EmptyString(yy_server->host))
1289 {
1290 conf_report_error("Ignoring connect block for %s -- missing host.",
1291 yy_server->name);
1292 return 0;
1293 }
1294
1295 #ifndef HAVE_LIBZ
1296 if(ServerConfCompressed(yy_server))
1297 {
1298 conf_report_error("Ignoring connect::flags::compressed -- zlib not available.");
1299 yy_server->flags &= ~SERVER_COMPRESSED;
1300 }
1301 #endif
1302
1303 add_server_conf(yy_server);
1304 rb_dlinkAdd(yy_server, &yy_server->node, &server_conf_list);
1305
1306 yy_server = NULL;
1307 return 0;
1308 }
1309
1310 static void
1311 conf_set_connect_host(void *data)
1312 {
1313 rb_free(yy_server->host);
1314 yy_server->host = rb_strdup(data);
1315 if (strchr(yy_server->host, ':'))
1316 yy_server->aftype = AF_INET6;
1317 }
1318
1319 static void
1320 conf_set_connect_vhost(void *data)
1321 {
1322 if(rb_inet_pton_sock(data, (struct sockaddr *)&yy_server->my_ipnum) <= 0)
1323 {
1324 conf_report_error("Invalid netmask for server vhost (%s)",
1325 (char *) data);
1326 return;
1327 }
1328
1329 yy_server->flags |= SERVER_VHOSTED;
1330 }
1331
1332 static void
1333 conf_set_connect_send_password(void *data)
1334 {
1335 if(yy_server->spasswd)
1336 {
1337 memset(yy_server->spasswd, 0, strlen(yy_server->spasswd));
1338 rb_free(yy_server->spasswd);
1339 }
1340
1341 yy_server->spasswd = rb_strdup(data);
1342 }
1343
1344 static void
1345 conf_set_connect_accept_password(void *data)
1346 {
1347 if(yy_server->passwd)
1348 {
1349 memset(yy_server->passwd, 0, strlen(yy_server->passwd));
1350 rb_free(yy_server->passwd);
1351 }
1352 yy_server->passwd = rb_strdup(data);
1353 }
1354
1355 static void
1356 conf_set_connect_fingerprint(void *data)
1357 {
1358 if (yy_server->certfp)
1359 rb_free(yy_server->certfp);
1360 yy_server->certfp = rb_strdup((char *) data);
1361
1362 /* force SSL to be enabled if fingerprint is enabled. */
1363 yy_server->flags |= SERVER_SSL;
1364 }
1365
1366 static void
1367 conf_set_connect_port(void *data)
1368 {
1369 int port = *(unsigned int *) data;
1370
1371 if(port < 1)
1372 port = PORTNUM;
1373
1374 yy_server->port = port;
1375 }
1376
1377 static void
1378 conf_set_connect_aftype(void *data)
1379 {
1380 char *aft = data;
1381
1382 if(strcasecmp(aft, "ipv4") == 0)
1383 yy_server->aftype = AF_INET;
1384 #ifdef RB_IPV6
1385 else if(strcasecmp(aft, "ipv6") == 0)
1386 yy_server->aftype = AF_INET6;
1387 #endif
1388 else
1389 conf_report_error("connect::aftype '%s' is unknown.", aft);
1390 }
1391
1392 static void
1393 conf_set_connect_flags(void *data)
1394 {
1395 conf_parm_t *args = data;
1396
1397 /* note, we allow them to set compressed, then remove it later if
1398 * they do and LIBZ isnt available
1399 */
1400 set_modes_from_table(&yy_server->flags, "flag", connect_table, args);
1401 }
1402
1403 static void
1404 conf_set_connect_hub_mask(void *data)
1405 {
1406 struct remote_conf *yy_hub;
1407
1408 if(EmptyString(yy_server->name))
1409 return;
1410
1411 yy_hub = make_remote_conf();
1412 yy_hub->flags = CONF_HUB;
1413
1414 yy_hub->host = rb_strdup(data);
1415 yy_hub->server = rb_strdup(yy_server->name);
1416 rb_dlinkAdd(yy_hub, &yy_hub->node, &hubleaf_conf_list);
1417 }
1418
1419 static void
1420 conf_set_connect_leaf_mask(void *data)
1421 {
1422 struct remote_conf *yy_leaf;
1423
1424 if(EmptyString(yy_server->name))
1425 return;
1426
1427 yy_leaf = make_remote_conf();
1428 yy_leaf->flags = CONF_LEAF;
1429
1430 yy_leaf->host = rb_strdup(data);
1431 yy_leaf->server = rb_strdup(yy_server->name);
1432 rb_dlinkAdd(yy_leaf, &yy_leaf->node, &hubleaf_conf_list);
1433 }
1434
1435 static void
1436 conf_set_connect_class(void *data)
1437 {
1438 rb_free(yy_server->class_name);
1439 yy_server->class_name = rb_strdup(data);
1440 }
1441
1442 static void
1443 conf_set_exempt_ip(void *data)
1444 {
1445 struct ConfItem *yy_tmp;
1446
1447 if(parse_netmask(data, NULL, NULL) == HM_HOST)
1448 {
1449 conf_report_error("Ignoring exempt -- invalid exempt::ip.");
1450 return;
1451 }
1452
1453 yy_tmp = make_conf();
1454 yy_tmp->passwd = rb_strdup("*");
1455 yy_tmp->host = rb_strdup(data);
1456 yy_tmp->status = CONF_EXEMPTDLINE;
1457 add_conf_by_address(yy_tmp->host, CONF_EXEMPTDLINE, NULL, NULL, yy_tmp);
1458 }
1459
1460 static int
1461 conf_cleanup_cluster(struct TopConf *tc)
1462 {
1463 rb_dlink_node *ptr, *next_ptr;
1464
1465 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_cluster_list.head)
1466 {
1467 free_remote_conf(ptr->data);
1468 rb_dlinkDestroy(ptr, &yy_cluster_list);
1469 }
1470
1471 if(yy_shared != NULL)
1472 {
1473 free_remote_conf(yy_shared);
1474 yy_shared = NULL;
1475 }
1476
1477 return 0;
1478 }
1479
1480 static void
1481 conf_set_cluster_name(void *data)
1482 {
1483 if(yy_shared != NULL)
1484 free_remote_conf(yy_shared);
1485
1486 yy_shared = make_remote_conf();
1487 yy_shared->server = rb_strdup(data);
1488 rb_dlinkAddAlloc(yy_shared, &yy_cluster_list);
1489
1490 yy_shared = NULL;
1491 }
1492
1493 static void
1494 conf_set_cluster_flags(void *data)
1495 {
1496 conf_parm_t *args = data;
1497 int flags = 0;
1498 rb_dlink_node *ptr, *next_ptr;
1499
1500 if(yy_shared != NULL)
1501 free_remote_conf(yy_shared);
1502
1503 set_modes_from_table(&flags, "flag", cluster_table, args);
1504
1505 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_cluster_list.head)
1506 {
1507 yy_shared = ptr->data;
1508 yy_shared->flags = flags;
1509 rb_dlinkAddTail(yy_shared, &yy_shared->node, &cluster_conf_list);
1510 rb_dlinkDestroy(ptr, &yy_cluster_list);
1511 }
1512
1513 yy_shared = NULL;
1514 }
1515
1516 static void
1517 conf_set_general_havent_read_conf(void *data)
1518 {
1519 if(*(unsigned int *) data)
1520 {
1521 conf_report_error("You haven't read your config file properly.");
1522 conf_report_error
1523 ("There is a line in the example conf that will kill your server if not removed.");
1524 conf_report_error
1525 ("Consider actually reading/editing the conf file, and removing this line.");
1526 if (!testing_conf)
1527 exit(0);
1528 }
1529 }
1530
1531 static void
1532 conf_set_general_hide_error_messages(void *data)
1533 {
1534 char *val = data;
1535
1536 if(strcasecmp(val, "yes") == 0)
1537 ConfigFileEntry.hide_error_messages = 2;
1538 else if(strcasecmp(val, "opers") == 0)
1539 ConfigFileEntry.hide_error_messages = 1;
1540 else if(strcasecmp(val, "no") == 0)
1541 ConfigFileEntry.hide_error_messages = 0;
1542 else
1543 conf_report_error("Invalid setting '%s' for general::hide_error_messages.", val);
1544 }
1545
1546 static void
1547 conf_set_general_kline_delay(void *data)
1548 {
1549 ConfigFileEntry.kline_delay = *(unsigned int *) data;
1550
1551 /* THIS MUST BE HERE to stop us being unable to check klines */
1552 kline_queued = 0;
1553 }
1554
1555 static void
1556 conf_set_general_stats_k_oper_only(void *data)
1557 {
1558 char *val = data;
1559
1560 if(strcasecmp(val, "yes") == 0)
1561 ConfigFileEntry.stats_k_oper_only = 2;
1562 else if(strcasecmp(val, "masked") == 0)
1563 ConfigFileEntry.stats_k_oper_only = 1;
1564 else if(strcasecmp(val, "no") == 0)
1565 ConfigFileEntry.stats_k_oper_only = 0;
1566 else
1567 conf_report_error("Invalid setting '%s' for general::stats_k_oper_only.", val);
1568 }
1569
1570 static void
1571 conf_set_general_stats_i_oper_only(void *data)
1572 {
1573 char *val = data;
1574
1575 if(strcasecmp(val, "yes") == 0)
1576 ConfigFileEntry.stats_i_oper_only = 2;
1577 else if(strcasecmp(val, "masked") == 0)
1578 ConfigFileEntry.stats_i_oper_only = 1;
1579 else if(strcasecmp(val, "no") == 0)
1580 ConfigFileEntry.stats_i_oper_only = 0;
1581 else
1582 conf_report_error("Invalid setting '%s' for general::stats_i_oper_only.", val);
1583 }
1584
1585 static void
1586 conf_set_general_compression_level(void *data)
1587 {
1588 #ifdef HAVE_LIBZ
1589 ConfigFileEntry.compression_level = *(unsigned int *) data;
1590
1591 if((ConfigFileEntry.compression_level < 1) || (ConfigFileEntry.compression_level > 9))
1592 {
1593 conf_report_error
1594 ("Invalid general::compression_level %d -- using default.",
1595 ConfigFileEntry.compression_level);
1596 ConfigFileEntry.compression_level = 0;
1597 }
1598 #else
1599 conf_report_error("Ignoring general::compression_level -- zlib not available.");
1600 #endif
1601 }
1602
1603 static void
1604 conf_set_general_default_umodes(void *data)
1605 {
1606 char *pm;
1607 int what = MODE_ADD, flag;
1608
1609 ConfigFileEntry.default_umodes = 0;
1610 for (pm = (char *) data; *pm; pm++)
1611 {
1612 switch (*pm)
1613 {
1614 case '+':
1615 what = MODE_ADD;
1616 break;
1617 case '-':
1618 what = MODE_DEL;
1619 break;
1620
1621 /* don't allow +o */
1622 case 'o':
1623 case 'S':
1624 case 'Z':
1625 case ' ':
1626 break;
1627
1628 default:
1629 if ((flag = user_modes[(unsigned char) *pm]))
1630 {
1631 /* Proper value has probably not yet been set
1632 * so don't check oper_only_umodes -- jilles */
1633 if (what == MODE_ADD)
1634 ConfigFileEntry.default_umodes |= flag;
1635 else
1636 ConfigFileEntry.default_umodes &= ~flag;
1637 }
1638 break;
1639 }
1640 }
1641 }
1642
1643 static void
1644 conf_set_general_oper_umodes(void *data)
1645 {
1646 set_modes_from_table(&ConfigFileEntry.oper_umodes, "umode", umode_table, data);
1647 }
1648
1649 static void
1650 conf_set_general_oper_only_umodes(void *data)
1651 {
1652 set_modes_from_table(&ConfigFileEntry.oper_only_umodes, "umode", umode_table, data);
1653 }
1654
1655 static void
1656 conf_set_general_oper_snomask(void *data)
1657 {
1658 char *pm;
1659 int what = MODE_ADD, flag;
1660
1661 ConfigFileEntry.oper_snomask = 0;
1662 for (pm = (char *) data; *pm; pm++)
1663 {
1664 switch (*pm)
1665 {
1666 case '+':
1667 what = MODE_ADD;
1668 break;
1669 case '-':
1670 what = MODE_DEL;
1671 break;
1672
1673 default:
1674 if ((flag = snomask_modes[(unsigned char) *pm]))
1675 {
1676 if (what == MODE_ADD)
1677 ConfigFileEntry.oper_snomask |= flag;
1678 else
1679 ConfigFileEntry.oper_snomask &= ~flag;
1680 }
1681 break;
1682 }
1683 }
1684 }
1685
1686 static void
1687 conf_set_serverhide_links_delay(void *data)
1688 {
1689 int val = *(unsigned int *) data;
1690
1691 ConfigServerHide.links_delay = val;
1692 }
1693
1694 static void
1695 conf_set_service_name(void *data)
1696 {
1697 struct Client *target_p;
1698 const char *s;
1699 char *tmp;
1700 int dots = 0;
1701
1702 for(s = data; *s != '\0'; s++)
1703 {
1704 if(!IsServChar(*s))
1705 {
1706 conf_report_error("Ignoring service::name "
1707 "-- bogus servername.");
1708 return;
1709 }
1710 else if(*s == '.')
1711 dots++;
1712 }
1713
1714 if(!dots)
1715 {
1716 conf_report_error("Ignoring service::name -- must contain '.'");
1717 return;
1718 }
1719
1720 tmp = rb_strdup(data);
1721 rb_dlinkAddAlloc(tmp, &service_list);
1722 }
1723
1724 static int
1725 conf_begin_alias(struct TopConf *tc)
1726 {
1727 yy_alias = rb_malloc(sizeof(struct alias_entry));
1728
1729 if (conf_cur_block_name != NULL)
1730 yy_alias->name = rb_strdup(conf_cur_block_name);
1731
1732 yy_alias->flags = 0;
1733 yy_alias->hits = 0;
1734
1735 return 0;
1736 }
1737
1738 static int
1739 conf_end_alias(struct TopConf *tc)
1740 {
1741 if (yy_alias == NULL)
1742 return -1;
1743
1744 if (yy_alias->name == NULL)
1745 {
1746 conf_report_error("Ignoring alias -- must have a name.");
1747
1748 rb_free(yy_alias);
1749
1750 return -1;
1751 }
1752
1753 if (yy_alias->target == NULL)
1754 {
1755 conf_report_error("Ignoring alias -- must have a target.");
1756
1757 rb_free(yy_alias);
1758
1759 return -1;
1760 }
1761
1762 irc_dictionary_add(alias_dict, yy_alias->name, yy_alias);
1763
1764 return 0;
1765 }
1766
1767 static void
1768 conf_set_alias_name(void *data)
1769 {
1770 if (data == NULL || yy_alias == NULL) /* this shouldn't ever happen */
1771 return;
1772
1773 yy_alias->name = rb_strdup(data);
1774 }
1775
1776 static void
1777 conf_set_alias_target(void *data)
1778 {
1779 if (data == NULL || yy_alias == NULL) /* this shouldn't ever happen */
1780 return;
1781
1782 yy_alias->target = rb_strdup(data);
1783 }
1784
1785 /* XXX for below */
1786 static void conf_set_blacklist_reason(void *data);
1787
1788 static void
1789 conf_set_blacklist_host(void *data)
1790 {
1791 if (yy_blacklist_host)
1792 {
1793 conf_report_error("blacklist::host %s overlaps existing host %s",
1794 (char *)data, yy_blacklist_host);
1795
1796 /* Cleanup */
1797 conf_set_blacklist_reason(NULL);
1798 return;
1799 }
1800
1801 yy_blacklist_ipv4 = 1;
1802 yy_blacklist_ipv6 = 0;
1803 yy_blacklist_host = rb_strdup(data);
1804 }
1805
1806 static void
1807 conf_set_blacklist_type(void *data)
1808 {
1809 conf_parm_t *args = data;
1810
1811 /* Don't assume we have either if we got here */
1812 yy_blacklist_ipv4 = 0;
1813 yy_blacklist_ipv6 = 0;
1814
1815 for (; args; args = args->next)
1816 {
1817 if (!strcasecmp(args->v.string, "ipv4"))
1818 yy_blacklist_ipv4 = 1;
1819 else if (!strcasecmp(args->v.string, "ipv6"))
1820 yy_blacklist_ipv6 = 1;
1821 else
1822 conf_report_error("blacklist::type has unknown address family %s",
1823 args->v.string);
1824 }
1825
1826 /* If we have neither, just default to IPv4 */
1827 if (!yy_blacklist_ipv4 && !yy_blacklist_ipv6)
1828 {
1829 conf_report_error("blacklist::type has neither IPv4 nor IPv6 (defaulting to IPv4)");
1830 yy_blacklist_ipv4 = 1;
1831 }
1832 }
1833
1834 static void
1835 conf_set_blacklist_matches(void *data)
1836 {
1837 conf_parm_t *args = data;
1838
1839 for (; args; args = args->next)
1840 {
1841 struct BlacklistFilter *filter;
1842 char *str = args->v.string;
1843 char *p;
1844 int type = BLACKLIST_FILTER_LAST;
1845
1846 if (CF_TYPE(args->type) != CF_QSTRING)
1847 {
1848 conf_report_error("blacklist::matches -- must be quoted string");
1849 continue;
1850 }
1851
1852 if (str == NULL)
1853 {
1854 conf_report_error("blacklist::matches -- invalid entry");
1855 continue;
1856 }
1857
1858 if (strlen(str) > HOSTIPLEN)
1859 {
1860 conf_report_error("blacklist::matches has an entry too long: %s",
1861 str);
1862 continue;
1863 }
1864
1865 for (p = str; *p != '\0'; p++)
1866 {
1867 /* Check for validity */
1868 if (*p == '.')
1869 type = BLACKLIST_FILTER_ALL;
1870 else if (!isalnum(*p))
1871 {
1872 conf_report_error("blacklist::matches has invalid IP match entry %s",
1873 str);
1874 type = 0;
1875 break;
1876 }
1877 }
1878
1879 if (type == BLACKLIST_FILTER_ALL)
1880 {
1881 /* Basic IP sanity check */
1882 struct rb_sockaddr_storage tmp;
1883 if (rb_inet_pton(AF_INET, str, &tmp) <= 0)
1884 {
1885 conf_report_error("blacklist::matches has invalid IP match entry %s",
1886 str);
1887 continue;
1888 }
1889 }
1890 else if (type == BLACKLIST_FILTER_LAST)
1891 {
1892 /* Verify it's the correct length */
1893 if (strlen(str) > 3)
1894 {
1895 conf_report_error("blacklist::matches has invalid octet match entry %s",
1896 str);
1897 continue;
1898 }
1899 }
1900 else
1901 {
1902 continue; /* Invalid entry */
1903 }
1904
1905 filter = rb_malloc(sizeof(struct BlacklistFilter));
1906 filter->type = type;
1907 rb_strlcpy(filter->filterstr, str, sizeof(filter->filterstr));
1908
1909 rb_dlinkAdd(filter, &filter->node, &yy_blacklist_filters);
1910 }
1911 }
1912
1913 static void
1914 conf_set_blacklist_reason(void *data)
1915 {
1916 yy_blacklist_reason = rb_strdup(data);
1917 rb_dlink_node *ptr, *nptr;
1918
1919 if (yy_blacklist_host && yy_blacklist_reason)
1920 {
1921 if (yy_blacklist_ipv6)
1922 {
1923 /* Make sure things fit (64 = alnum count + dots) */
1924 if ((64 + strlen(yy_blacklist_host)) > IRCD_RES_HOSTLEN)
1925 {
1926 conf_report_error("blacklist::host %s results in IPv6 queries that are too long",
1927 yy_blacklist_host);
1928 goto cleanup_bl;
1929 }
1930 }
1931 /* Avoid doing redundant check, IPv6 is bigger than IPv4 --Elizabeth */
1932 if (yy_blacklist_ipv4 && !yy_blacklist_ipv6)
1933 {
1934 /* Make sure things fit (16 = number of nums + dots) */
1935 if ((16 + strlen(yy_blacklist_host)) > IRCD_RES_HOSTLEN)
1936 {
1937 conf_report_error("blacklist::host %s results in IPv4 queries that are too long",
1938 yy_blacklist_host);
1939 goto cleanup_bl;
1940 }
1941 }
1942
1943 new_blacklist(yy_blacklist_host, yy_blacklist_reason, yy_blacklist_ipv4, yy_blacklist_ipv6,
1944 &yy_blacklist_filters);
1945 }
1946
1947 cleanup_bl:
1948 if (data == NULL)
1949 {
1950 RB_DLINK_FOREACH_SAFE(ptr, nptr, yy_blacklist_filters.head)
1951 {
1952 rb_free(ptr);
1953 rb_dlinkDelete(ptr, &yy_blacklist_filters);
1954 }
1955 }
1956 else
1957 {
1958 yy_blacklist_filters = (rb_dlink_list){ NULL, NULL, 0 };
1959 }
1960
1961 rb_free(yy_blacklist_host);
1962 rb_free(yy_blacklist_reason);
1963 yy_blacklist_host = NULL;
1964 yy_blacklist_reason = NULL;
1965 yy_blacklist_ipv4 = 1;
1966 yy_blacklist_ipv6 = 0;
1967 }
1968
1969 /* public functions */
1970
1971
1972 void
1973 conf_report_error(const char *fmt, ...)
1974 {
1975 va_list ap;
1976 char msg[IRCD_BUFSIZE + 1] = { 0 };
1977
1978 va_start(ap, fmt);
1979 rb_vsnprintf(msg, IRCD_BUFSIZE, fmt, ap);
1980 va_end(ap);
1981
1982 if (testing_conf)
1983 {
1984 fprintf(stderr, "\"%s\", line %d: %s\n", current_file, lineno + 1, msg);
1985 return;
1986 }
1987
1988 ierror("\"%s\", line %d: %s", current_file, lineno + 1, msg);
1989 sendto_realops_snomask(SNO_GENERAL, L_ALL, "\"%s\", line %d: %s", current_file, lineno + 1, msg);
1990 }
1991
1992 int
1993 conf_start_block(char *block, char *name)
1994 {
1995 if((conf_cur_block = find_top_conf(block)) == NULL)
1996 {
1997 conf_report_error("Configuration block '%s' is not defined.", block);
1998 return -1;
1999 }
2000
2001 if(name)
2002 conf_cur_block_name = rb_strdup(name);
2003 else
2004 conf_cur_block_name = NULL;
2005
2006 if(conf_cur_block->tc_sfunc)
2007 if(conf_cur_block->tc_sfunc(conf_cur_block) < 0)
2008 return -1;
2009
2010 return 0;
2011 }
2012
2013 int
2014 conf_end_block(struct TopConf *tc)
2015 {
2016 if(tc->tc_efunc)
2017 return tc->tc_efunc(tc);
2018
2019 rb_free(conf_cur_block_name);
2020 return 0;
2021 }
2022
2023 static void
2024 conf_set_generic_int(void *data, void *location)
2025 {
2026 *((int *) location) = *((unsigned int *) data);
2027 }
2028
2029 static void
2030 conf_set_generic_string(void *data, int len, void *location)
2031 {
2032 char **loc = location;
2033 char *input = data;
2034
2035 if(len && strlen(input) > (unsigned int)len)
2036 input[len] = '\0';
2037
2038 rb_free(*loc);
2039 *loc = rb_strdup(input);
2040 }
2041
2042 int
2043 conf_call_set(struct TopConf *tc, char *item, conf_parm_t * value, int type)
2044 {
2045 struct ConfEntry *cf;
2046 conf_parm_t *cp;
2047
2048 if(!tc)
2049 return -1;
2050
2051 if((cf = find_conf_item(tc, item)) == NULL)
2052 {
2053 conf_report_error
2054 ("Non-existant configuration setting %s::%s.", tc->tc_name, (char *) item);
2055 return -1;
2056 }
2057
2058 /* if it takes one thing, make sure they only passed one thing,
2059 and handle as needed. */
2060 if((value->v.list->type & CF_FLIST) && !(cf->cf_type & CF_FLIST))
2061 {
2062 conf_report_error
2063 ("Option %s::%s does not take a list of values.", tc->tc_name, item);
2064 return -1;
2065 }
2066
2067 cp = value->v.list;
2068
2069
2070 if(CF_TYPE(value->v.list->type) != CF_TYPE(cf->cf_type))
2071 {
2072 /* if it expects a string value, but we got a yesno,
2073 * convert it back
2074 */
2075 if((CF_TYPE(value->v.list->type) == CF_YESNO) &&
2076 (CF_TYPE(cf->cf_type) == CF_STRING))
2077 {
2078 value->v.list->type = CF_STRING;
2079
2080 if(cp->v.number == 1)
2081 cp->v.string = rb_strdup("yes");
2082 else
2083 cp->v.string = rb_strdup("no");
2084 }
2085
2086 /* maybe it's a CF_TIME and they passed CF_INT --
2087 should still be valid */
2088 else if(!((CF_TYPE(value->v.list->type) == CF_INT) &&
2089 (CF_TYPE(cf->cf_type) == CF_TIME)))
2090 {
2091 conf_report_error
2092 ("Wrong type for %s::%s (expected %s, got %s)",
2093 tc->tc_name, (char *) item,
2094 conf_strtype(cf->cf_type), conf_strtype(value->v.list->type));
2095 return -1;
2096 }
2097 }
2098
2099 if(cf->cf_type & CF_FLIST)
2100 {
2101 #if 0
2102 if(cf->cf_arg)
2103 conf_set_generic_list(value->v.list, cf->cf_arg);
2104 else
2105 #endif
2106 /* just pass it the extended argument list */
2107 cf->cf_func(value->v.list);
2108 }
2109 else
2110 {
2111 /* it's old-style, needs only one arg */
2112 switch (cf->cf_type)
2113 {
2114 case CF_INT:
2115 case CF_TIME:
2116 case CF_YESNO:
2117 if(cf->cf_arg)
2118 conf_set_generic_int(&cp->v.number, cf->cf_arg);
2119 else
2120 cf->cf_func(&cp->v.number);
2121 break;
2122 case CF_STRING:
2123 case CF_QSTRING:
2124 if(EmptyString(cp->v.string))
2125 conf_report_error("Ignoring %s::%s -- empty field",
2126 tc->tc_name, item);
2127 else if(cf->cf_arg)
2128 conf_set_generic_string(cp->v.string, cf->cf_len, cf->cf_arg);
2129 else
2130 cf->cf_func(cp->v.string);
2131 break;
2132 }
2133 }
2134
2135
2136 return 0;
2137 }
2138
2139 int
2140 add_conf_item(const char *topconf, const char *name, int type, void (*func) (void *))
2141 {
2142 struct TopConf *tc;
2143 struct ConfEntry *cf;
2144
2145 if((tc = find_top_conf(topconf)) == NULL)
2146 return -1;
2147
2148 if((cf = find_conf_item(tc, name)) != NULL)
2149 return -1;
2150
2151 cf = rb_malloc(sizeof(struct ConfEntry));
2152
2153 cf->cf_name = name;
2154 cf->cf_type = type;
2155 cf->cf_func = func;
2156 cf->cf_arg = NULL;
2157
2158 rb_dlinkAddAlloc(cf, &tc->tc_items);
2159
2160 return 0;
2161 }
2162
2163 int
2164 remove_conf_item(const char *topconf, const char *name)
2165 {
2166 struct TopConf *tc;
2167 struct ConfEntry *cf;
2168 rb_dlink_node *ptr;
2169
2170 if((tc = find_top_conf(topconf)) == NULL)
2171 return -1;
2172
2173 if((cf = find_conf_item(tc, name)) == NULL)
2174 return -1;
2175
2176 if((ptr = rb_dlinkFind(cf, &tc->tc_items)) == NULL)
2177 return -1;
2178
2179 rb_dlinkDestroy(ptr, &tc->tc_items);
2180 rb_free(cf);
2181
2182 return 0;
2183 }
2184
2185 /* *INDENT-OFF* */
2186 static struct ConfEntry conf_serverinfo_table[] =
2187 {
2188 { "description", CF_QSTRING, NULL, 0, &ServerInfo.description },
2189 { "network_desc", CF_QSTRING, NULL, 0, &ServerInfo.network_desc },
2190 { "hub", CF_YESNO, NULL, 0, &ServerInfo.hub },
2191
2192 { "network_name", CF_QSTRING, conf_set_serverinfo_network_name, 0, NULL },
2193 { "name", CF_QSTRING, conf_set_serverinfo_name, 0, NULL },
2194 { "sid", CF_QSTRING, conf_set_serverinfo_sid, 0, NULL },
2195 { "vhost", CF_QSTRING, conf_set_serverinfo_vhost, 0, NULL },
2196 { "vhost6", CF_QSTRING, conf_set_serverinfo_vhost6, 0, NULL },
2197
2198 { "ssl_private_key", CF_QSTRING, NULL, 0, &ServerInfo.ssl_private_key },
2199 { "ssl_ca_cert", CF_QSTRING, NULL, 0, &ServerInfo.ssl_ca_cert },
2200 { "ssl_cert", CF_QSTRING, NULL, 0, &ServerInfo.ssl_cert },
2201 { "ssl_dh_params", CF_QSTRING, NULL, 0, &ServerInfo.ssl_dh_params },
2202 { "ssld_count", CF_INT, NULL, 0, &ServerInfo.ssld_count },
2203
2204 { "default_max_clients",CF_INT, NULL, 0, &ServerInfo.default_max_clients },
2205
2206 { "nicklen", CF_INT, conf_set_serverinfo_nicklen, 0, NULL },
2207
2208 { "\0", 0, NULL, 0, NULL }
2209 };
2210
2211 static struct ConfEntry conf_admin_table[] =
2212 {
2213 { "name", CF_QSTRING, NULL, 200, &AdminInfo.name },
2214 { "description",CF_QSTRING, NULL, 200, &AdminInfo.description },
2215 { "email", CF_QSTRING, NULL, 200, &AdminInfo.email },
2216 { "\0", 0, NULL, 0, NULL }
2217 };
2218
2219 static struct ConfEntry conf_log_table[] =
2220 {
2221 { "fname_userlog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_userlog },
2222 { "fname_fuserlog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_fuserlog },
2223 { "fname_operlog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_operlog },
2224 { "fname_foperlog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_foperlog },
2225 { "fname_serverlog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_serverlog },
2226 { "fname_killlog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_killlog },
2227 { "fname_klinelog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_klinelog },
2228 { "fname_operspylog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_operspylog },
2229 { "fname_ioerrorlog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_ioerrorlog },
2230 { "\0", 0, NULL, 0, NULL }
2231 };
2232
2233 static struct ConfEntry conf_operator_table[] =
2234 {
2235 { "rsa_public_key_file", CF_QSTRING, conf_set_oper_rsa_public_key_file, 0, NULL },
2236 { "flags", CF_STRING | CF_FLIST, conf_set_oper_flags, 0, NULL },
2237 { "umodes", CF_STRING | CF_FLIST, conf_set_oper_umodes, 0, NULL },
2238 { "privset", CF_QSTRING, conf_set_oper_privset, 0, NULL },
2239 { "snomask", CF_QSTRING, conf_set_oper_snomask, 0, NULL },
2240 { "user", CF_QSTRING, conf_set_oper_user, 0, NULL },
2241 { "password", CF_QSTRING, conf_set_oper_password, 0, NULL },
2242 { "fingerprint", CF_QSTRING, conf_set_oper_fingerprint, 0, NULL },
2243 { "\0", 0, NULL, 0, NULL }
2244 };
2245
2246 static struct ConfEntry conf_privset_table[] =
2247 {
2248 { "extends", CF_QSTRING, conf_set_privset_extends, 0, NULL },
2249 { "privs", CF_STRING | CF_FLIST, conf_set_privset_privs, 0, NULL },
2250 { "\0", 0, NULL, 0, NULL }
2251 };
2252
2253 static struct ConfEntry conf_class_table[] =
2254 {
2255 { "ping_time", CF_TIME, conf_set_class_ping_time, 0, NULL },
2256 { "cidr_ipv4_bitlen", CF_INT, conf_set_class_cidr_ipv4_bitlen, 0, NULL },
2257 #ifdef RB_IPV6
2258 { "cidr_ipv6_bitlen", CF_INT, conf_set_class_cidr_ipv6_bitlen, 0, NULL },
2259 #endif
2260 { "number_per_cidr", CF_INT, conf_set_class_number_per_cidr, 0, NULL },
2261 { "number_per_ip", CF_INT, conf_set_class_number_per_ip, 0, NULL },
2262 { "number_per_ip_global", CF_INT,conf_set_class_number_per_ip_global, 0, NULL },
2263 { "number_per_ident", CF_INT, conf_set_class_number_per_ident, 0, NULL },
2264 { "connectfreq", CF_TIME, conf_set_class_connectfreq, 0, NULL },
2265 { "max_number", CF_INT, conf_set_class_max_number, 0, NULL },
2266 { "sendq", CF_TIME, conf_set_class_sendq, 0, NULL },
2267 { "\0", 0, NULL, 0, NULL }
2268 };
2269
2270 static struct ConfEntry conf_auth_table[] =
2271 {
2272 { "user", CF_QSTRING, conf_set_auth_user, 0, NULL },
2273 { "auth_user", CF_QSTRING, conf_set_auth_auth_user, 0, NULL },
2274 { "password", CF_QSTRING, conf_set_auth_passwd, 0, NULL },
2275 { "class", CF_QSTRING, conf_set_auth_class, 0, NULL },
2276 { "spoof", CF_QSTRING, conf_set_auth_spoof, 0, NULL },
2277 { "redirserv", CF_QSTRING, conf_set_auth_redir_serv, 0, NULL },
2278 { "redirport", CF_INT, conf_set_auth_redir_port, 0, NULL },
2279 { "flags", CF_STRING | CF_FLIST, conf_set_auth_flags, 0, NULL },
2280 { "\0", 0, NULL, 0, NULL }
2281 };
2282
2283 static struct ConfEntry conf_connect_table[] =
2284 {
2285 { "send_password", CF_QSTRING, conf_set_connect_send_password, 0, NULL },
2286 { "accept_password", CF_QSTRING, conf_set_connect_accept_password, 0, NULL },
2287 { "fingerprint", CF_QSTRING, conf_set_connect_fingerprint, 0, NULL },
2288 { "flags", CF_STRING | CF_FLIST, conf_set_connect_flags, 0, NULL },
2289 { "host", CF_QSTRING, conf_set_connect_host, 0, NULL },
2290 { "vhost", CF_QSTRING, conf_set_connect_vhost, 0, NULL },
2291 { "port", CF_INT, conf_set_connect_port, 0, NULL },
2292 { "aftype", CF_STRING, conf_set_connect_aftype, 0, NULL },
2293 { "hub_mask", CF_QSTRING, conf_set_connect_hub_mask, 0, NULL },
2294 { "leaf_mask", CF_QSTRING, conf_set_connect_leaf_mask, 0, NULL },
2295 { "class", CF_QSTRING, conf_set_connect_class, 0, NULL },
2296 { "\0", 0, NULL, 0, NULL }
2297 };
2298
2299 static struct ConfEntry conf_general_table[] =
2300 {
2301 { "oper_only_umodes", CF_STRING | CF_FLIST, conf_set_general_oper_only_umodes, 0, NULL },
2302 { "oper_umodes", CF_STRING | CF_FLIST, conf_set_general_oper_umodes, 0, NULL },
2303 { "oper_snomask", CF_QSTRING, conf_set_general_oper_snomask, 0, NULL },
2304 { "compression_level", CF_INT, conf_set_general_compression_level, 0, NULL },
2305 { "havent_read_conf", CF_YESNO, conf_set_general_havent_read_conf, 0, NULL },
2306 { "hide_error_messages",CF_STRING, conf_set_general_hide_error_messages,0, NULL },
2307 { "kline_delay", CF_TIME, conf_set_general_kline_delay, 0, NULL },
2308 { "stats_k_oper_only", CF_STRING, conf_set_general_stats_k_oper_only, 0, NULL },
2309 { "stats_i_oper_only", CF_STRING, conf_set_general_stats_i_oper_only, 0, NULL },
2310 { "default_umodes", CF_QSTRING, conf_set_general_default_umodes, 0, NULL },
2311
2312 { "default_operstring", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.default_operstring },
2313 { "default_adminstring",CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.default_adminstring },
2314 { "servicestring", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.servicestring },
2315 { "egdpool_path", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.egdpool_path },
2316 { "kline_reason", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.kline_reason },
2317 { "identify_service", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.identifyservice },
2318 { "identify_command", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.identifycommand },
2319
2320 { "anti_spam_exit_message_time", CF_TIME, NULL, 0, &ConfigFileEntry.anti_spam_exit_message_time },
2321 { "disable_fake_channels", CF_YESNO, NULL, 0, &ConfigFileEntry.disable_fake_channels },
2322 { "min_nonwildcard_simple", CF_INT, NULL, 0, &ConfigFileEntry.min_nonwildcard_simple },
2323 { "non_redundant_klines", CF_YESNO, NULL, 0, &ConfigFileEntry.non_redundant_klines },
2324 { "tkline_expire_notices", CF_YESNO, NULL, 0, &ConfigFileEntry.tkline_expire_notices },
2325
2326 { "anti_nick_flood", CF_YESNO, NULL, 0, &ConfigFileEntry.anti_nick_flood },
2327 { "burst_away", CF_YESNO, NULL, 0, &ConfigFileEntry.burst_away },
2328 { "caller_id_wait", CF_TIME, NULL, 0, &ConfigFileEntry.caller_id_wait },
2329 { "client_exit", CF_YESNO, NULL, 0, &ConfigFileEntry.client_exit },
2330 { "collision_fnc", CF_YESNO, NULL, 0, &ConfigFileEntry.collision_fnc },
2331 { "resv_fnc", CF_YESNO, NULL, 0, &ConfigFileEntry.resv_fnc },
2332 { "connect_timeout", CF_TIME, NULL, 0, &ConfigFileEntry.connect_timeout },
2333 { "default_floodcount", CF_INT, NULL, 0, &ConfigFileEntry.default_floodcount },
2334 { "default_ident_timeout", CF_INT, NULL, 0, &ConfigFileEntry.default_ident_timeout },
2335 { "disable_auth", CF_YESNO, NULL, 0, &ConfigFileEntry.disable_auth },
2336 { "dots_in_ident", CF_INT, NULL, 0, &ConfigFileEntry.dots_in_ident },
2337 { "failed_oper_notice", CF_YESNO, NULL, 0, &ConfigFileEntry.failed_oper_notice },
2338 { "global_snotices", CF_YESNO, NULL, 0, &ConfigFileEntry.global_snotices },
2339 { "hide_spoof_ips", CF_YESNO, NULL, 0, &ConfigFileEntry.hide_spoof_ips },
2340 { "dline_with_reason", CF_YESNO, NULL, 0, &ConfigFileEntry.dline_with_reason },
2341 { "kline_with_reason", CF_YESNO, NULL, 0, &ConfigFileEntry.kline_with_reason },
2342 { "map_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.map_oper_only },
2343 { "max_accept", CF_INT, NULL, 0, &ConfigFileEntry.max_accept },
2344 { "max_monitor", CF_INT, NULL, 0, &ConfigFileEntry.max_monitor },
2345 { "max_nick_time", CF_TIME, NULL, 0, &ConfigFileEntry.max_nick_time },
2346 { "max_nick_changes", CF_INT, NULL, 0, &ConfigFileEntry.max_nick_changes },
2347 { "max_targets", CF_INT, NULL, 0, &ConfigFileEntry.max_targets },
2348 { "min_nonwildcard", CF_INT, NULL, 0, &ConfigFileEntry.min_nonwildcard },
2349 { "nick_delay", CF_TIME, NULL, 0, &ConfigFileEntry.nick_delay },
2350 { "no_oper_flood", CF_YESNO, NULL, 0, &ConfigFileEntry.no_oper_flood },
2351 { "operspy_admin_only", CF_YESNO, NULL, 0, &ConfigFileEntry.operspy_admin_only },
2352 { "operspy_dont_care_user_info", CF_YESNO, NULL, 0, &ConfigFileEntry.operspy_dont_care_user_info },
2353 { "pace_wait", CF_TIME, NULL, 0, &ConfigFileEntry.pace_wait },
2354 { "pace_wait_simple", CF_TIME, NULL, 0, &ConfigFileEntry.pace_wait_simple },
2355 { "ping_cookie", CF_YESNO, NULL, 0, &ConfigFileEntry.ping_cookie },
2356 { "reject_after_count", CF_INT, NULL, 0, &ConfigFileEntry.reject_after_count },
2357 { "reject_ban_time", CF_TIME, NULL, 0, &ConfigFileEntry.reject_ban_time },
2358 { "reject_duration", CF_TIME, NULL, 0, &ConfigFileEntry.reject_duration },
2359 { "throttle_count", CF_INT, NULL, 0, &ConfigFileEntry.throttle_count },
2360 { "throttle_duration", CF_TIME, NULL, 0, &ConfigFileEntry.throttle_duration },
2361 { "short_motd", CF_YESNO, NULL, 0, &ConfigFileEntry.short_motd },
2362 { "stats_c_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_c_oper_only },
2363 { "stats_e_disabled", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_e_disabled },
2364 { "stats_h_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_h_oper_only },
2365 { "stats_o_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_o_oper_only },
2366 { "stats_P_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_P_oper_only },
2367 { "stats_y_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_y_oper_only },
2368 { "target_change", CF_YESNO, NULL, 0, &ConfigFileEntry.target_change },
2369 { "ts_max_delta", CF_TIME, NULL, 0, &ConfigFileEntry.ts_max_delta },
2370 { "use_egd", CF_YESNO, NULL, 0, &ConfigFileEntry.use_egd },
2371 { "ts_warn_delta", CF_TIME, NULL, 0, &ConfigFileEntry.ts_warn_delta },
2372 { "use_whois_actually", CF_YESNO, NULL, 0, &ConfigFileEntry.use_whois_actually },
2373 { "warn_no_nline", CF_YESNO, NULL, 0, &ConfigFileEntry.warn_no_nline },
2374 { "use_propagated_bans",CF_YESNO, NULL, 0, &ConfigFileEntry.use_propagated_bans },
2375 { "client_flood_max_lines", CF_INT, NULL, 0, &ConfigFileEntry.client_flood_max_lines },
2376 { "client_flood_burst_rate", CF_INT, NULL, 0, &ConfigFileEntry.client_flood_burst_rate },
2377 { "client_flood_burst_max", CF_INT, NULL, 0, &ConfigFileEntry.client_flood_burst_max },
2378 { "client_flood_message_num", CF_INT, NULL, 0, &ConfigFileEntry.client_flood_message_num },
2379 { "client_flood_message_time", CF_INT, NULL, 0, &ConfigFileEntry.client_flood_message_time },
2380 { "max_ratelimit_tokens", CF_INT, NULL, 0, &ConfigFileEntry.max_ratelimit_tokens },
2381 { "away_interval", CF_INT, NULL, 0, &ConfigFileEntry.away_interval },
2382 { "\0", 0, NULL, 0, NULL }
2383 };
2384
2385 static struct ConfEntry conf_channel_table[] =
2386 {
2387 { "default_split_user_count", CF_INT, NULL, 0, &ConfigChannel.default_split_user_count },
2388 { "default_split_server_count", CF_INT, NULL, 0, &ConfigChannel.default_split_server_count },
2389 { "burst_topicwho", CF_YESNO, NULL, 0, &ConfigChannel.burst_topicwho },
2390 { "kick_on_split_riding", CF_YESNO, NULL, 0, &ConfigChannel.kick_on_split_riding },
2391 { "knock_delay", CF_TIME, NULL, 0, &ConfigChannel.knock_delay },
2392 { "knock_delay_channel",CF_TIME, NULL, 0, &ConfigChannel.knock_delay_channel },
2393 { "max_bans", CF_INT, NULL, 0, &ConfigChannel.max_bans },
2394 { "max_bans_large", CF_INT, NULL, 0, &ConfigChannel.max_bans_large },
2395 { "max_chans_per_user", CF_INT, NULL, 0, &ConfigChannel.max_chans_per_user },
2396 { "no_create_on_split", CF_YESNO, NULL, 0, &ConfigChannel.no_create_on_split },
2397 { "no_join_on_split", CF_YESNO, NULL, 0, &ConfigChannel.no_join_on_split },
2398 { "only_ascii_channels", CF_YESNO, NULL, 0, &ConfigChannel.only_ascii_channels },
2399 { "use_except", CF_YESNO, NULL, 0, &ConfigChannel.use_except },
2400 { "use_invex", CF_YESNO, NULL, 0, &ConfigChannel.use_invex },
2401 { "use_forward", CF_YESNO, NULL, 0, &ConfigChannel.use_forward },
2402 { "use_knock", CF_YESNO, NULL, 0, &ConfigChannel.use_knock },
2403 { "resv_forcepart", CF_YESNO, NULL, 0, &ConfigChannel.resv_forcepart },
2404 { "channel_target_change", CF_YESNO, NULL, 0, &ConfigChannel.channel_target_change },
2405 { "disable_local_channels", CF_YESNO, NULL, 0, &ConfigChannel.disable_local_channels },
2406 { "\0", 0, NULL, 0, NULL }
2407 };
2408
2409 static struct ConfEntry conf_serverhide_table[] =
2410 {
2411 { "disable_hidden", CF_YESNO, NULL, 0, &ConfigServerHide.disable_hidden },
2412 { "flatten_links", CF_YESNO, NULL, 0, &ConfigServerHide.flatten_links },
2413 { "hidden", CF_YESNO, NULL, 0, &ConfigServerHide.hidden },
2414 { "links_delay", CF_TIME, conf_set_serverhide_links_delay, 0, NULL },
2415 { "\0", 0, NULL, 0, NULL }
2416 };
2417 /* *INDENT-ON* */
2418
2419 void
2420 newconf_init()
2421 {
2422 add_top_conf("modules", NULL, NULL, NULL);
2423 add_conf_item("modules", "path", CF_QSTRING, conf_set_modules_path);
2424 add_conf_item("modules", "module", CF_QSTRING, conf_set_modules_module);
2425
2426 add_top_conf("serverinfo", NULL, NULL, conf_serverinfo_table);
2427 add_top_conf("admin", NULL, NULL, conf_admin_table);
2428 add_top_conf("log", NULL, NULL, conf_log_table);
2429 add_top_conf("operator", conf_begin_oper, conf_end_oper, conf_operator_table);
2430 add_top_conf("class", conf_begin_class, conf_end_class, conf_class_table);
2431 add_top_conf("privset", NULL, NULL, conf_privset_table);
2432
2433 add_top_conf("listen", conf_begin_listen, conf_end_listen, NULL);
2434 add_conf_item("listen", "defer_accept", CF_YESNO, conf_set_listen_defer_accept);
2435 add_conf_item("listen", "port", CF_INT | CF_FLIST, conf_set_listen_port);
2436 add_conf_item("listen", "sslport", CF_INT | CF_FLIST, conf_set_listen_sslport);
2437 add_conf_item("listen", "ip", CF_QSTRING, conf_set_listen_address);
2438 add_conf_item("listen", "host", CF_QSTRING, conf_set_listen_address);
2439
2440 add_top_conf("auth", conf_begin_auth, conf_end_auth, conf_auth_table);
2441
2442 add_top_conf("shared", conf_cleanup_shared, conf_cleanup_shared, NULL);
2443 add_conf_item("shared", "oper", CF_QSTRING|CF_FLIST, conf_set_shared_oper);
2444 add_conf_item("shared", "flags", CF_STRING | CF_FLIST, conf_set_shared_flags);
2445
2446 add_top_conf("connect", conf_begin_connect, conf_end_connect, conf_connect_table);
2447
2448 add_top_conf("exempt", NULL, NULL, NULL);
2449 add_conf_item("exempt", "ip", CF_QSTRING, conf_set_exempt_ip);
2450
2451 add_top_conf("cluster", conf_cleanup_cluster, conf_cleanup_cluster, NULL);
2452 add_conf_item("cluster", "name", CF_QSTRING, conf_set_cluster_name);
2453 add_conf_item("cluster", "flags", CF_STRING | CF_FLIST, conf_set_cluster_flags);
2454
2455 add_top_conf("general", NULL, NULL, conf_general_table);
2456 add_top_conf("channel", NULL, NULL, conf_channel_table);
2457 add_top_conf("serverhide", NULL, NULL, conf_serverhide_table);
2458
2459 add_top_conf("service", NULL, NULL, NULL);
2460 add_conf_item("service", "name", CF_QSTRING, conf_set_service_name);
2461
2462 add_top_conf("alias", conf_begin_alias, conf_end_alias, NULL);
2463 add_conf_item("alias", "name", CF_QSTRING, conf_set_alias_name);
2464 add_conf_item("alias", "target", CF_QSTRING, conf_set_alias_target);
2465
2466 add_top_conf("blacklist", NULL, NULL, NULL);
2467 add_conf_item("blacklist", "host", CF_QSTRING, conf_set_blacklist_host);
2468 add_conf_item("blacklist", "type", CF_STRING | CF_FLIST, conf_set_blacklist_type);
2469 add_conf_item("blacklist", "matches", CF_QSTRING | CF_FLIST, conf_set_blacklist_matches);
2470 add_conf_item("blacklist", "reject_reason", CF_QSTRING, conf_set_blacklist_reason);
2471 }