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