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