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