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