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