]>
Commit | Line | Data |
---|---|---|
212380e3 AC |
1 | /* |
2 | * ircd-ratbox: an advanced Internet Relay Chat Daemon(ircd). | |
3 | * s_newconf.c - code for dealing with conf stuff | |
4 | * | |
5 | * Copyright (C) 2004 Lee Hardy <lee@leeh.co.uk> | |
6 | * Copyright (C) 2004-2005 ircd-ratbox development team | |
7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions are | |
10 | * met: | |
11 | * | |
12 | * 1.Redistributions of source code must retain the above copyright notice, | |
13 | * this list of conditions and the following disclaimer. | |
14 | * 2.Redistributions in binary form must reproduce the above copyright | |
15 | * notice, this list of conditions and the following disclaimer in the | |
16 | * documentation and/or other materials provided with the distribution. | |
17 | * 3.The name of the author may not be used to endorse or promote products | |
18 | * derived from this software without specific prior written permission. | |
19 | * | |
20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
21 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
23 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, | |
24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
28 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | |
29 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
30 | * POSSIBILITY OF SUCH DAMAGE. | |
212380e3 AC |
31 | */ |
32 | ||
33 | #include "stdinc.h" | |
34 | #include "ircd_defs.h" | |
35 | #include "common.h" | |
36 | #include "s_conf.h" | |
37 | #include "s_newconf.h" | |
212380e3 | 38 | #include "client.h" |
212380e3 AC |
39 | #include "s_serv.h" |
40 | #include "send.h" | |
41 | #include "hostmask.h" | |
42 | #include "newconf.h" | |
43 | #include "hash.h" | |
a4bf26dd EM |
44 | #include "rb_dictionary.h" |
45 | #include "rb_radixtree.h" | |
77d3d2db KB |
46 | #include "s_assert.h" |
47 | #include "logger.h" | |
1d02144f | 48 | #include "dns.h" |
212380e3 | 49 | |
330fc5c1 AC |
50 | rb_dlink_list shared_conf_list; |
51 | rb_dlink_list cluster_conf_list; | |
52 | rb_dlink_list oper_conf_list; | |
53 | rb_dlink_list hubleaf_conf_list; | |
54 | rb_dlink_list server_conf_list; | |
55 | rb_dlink_list xline_conf_list; | |
56 | rb_dlink_list resv_conf_list; /* nicks only! */ | |
57 | rb_dlink_list nd_list; /* nick delay */ | |
58 | rb_dlink_list tgchange_list; | |
212380e3 | 59 | |
7018b86a | 60 | rb_patricia_tree_t *tgchange_tree; |
212380e3 | 61 | |
398b6a73 | 62 | static rb_bh *nd_heap = NULL; |
212380e3 AC |
63 | |
64 | static void expire_temp_rxlines(void *unused); | |
65 | static void expire_nd_entries(void *unused); | |
66 | ||
e410dcf5 AC |
67 | struct ev_entry *expire_nd_entries_ev = NULL; |
68 | struct ev_entry *expire_temp_rxlines_ev = NULL; | |
69 | ||
212380e3 AC |
70 | void |
71 | init_s_newconf(void) | |
72 | { | |
e410dcf5 AC |
73 | tgchange_tree = rb_new_patricia(PATRICIA_BITS); |
74 | nd_heap = rb_bh_create(sizeof(struct nd_entry), ND_HEAP_SIZE, "nd_heap"); | |
75 | expire_nd_entries_ev = rb_event_addish("expire_nd_entries", expire_nd_entries, NULL, 30); | |
76 | expire_temp_rxlines_ev = rb_event_addish("expire_temp_rxlines", expire_temp_rxlines, NULL, 60); | |
212380e3 AC |
77 | } |
78 | ||
79 | void | |
80 | clear_s_newconf(void) | |
81 | { | |
82 | struct server_conf *server_p; | |
330fc5c1 | 83 | rb_dlink_node *ptr; |
637c4932 | 84 | rb_dlink_node *next_ptr; |
212380e3 | 85 | |
637c4932 | 86 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, shared_conf_list.head) |
212380e3 AC |
87 | { |
88 | /* ptr here is ptr->data->node */ | |
330fc5c1 | 89 | rb_dlinkDelete(ptr, &shared_conf_list); |
212380e3 AC |
90 | free_remote_conf(ptr->data); |
91 | } | |
92 | ||
637c4932 | 93 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, cluster_conf_list.head) |
212380e3 | 94 | { |
330fc5c1 | 95 | rb_dlinkDelete(ptr, &cluster_conf_list); |
212380e3 AC |
96 | free_remote_conf(ptr->data); |
97 | } | |
98 | ||
637c4932 | 99 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, hubleaf_conf_list.head) |
212380e3 | 100 | { |
330fc5c1 | 101 | rb_dlinkDelete(ptr, &hubleaf_conf_list); |
212380e3 AC |
102 | free_remote_conf(ptr->data); |
103 | } | |
104 | ||
637c4932 | 105 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, oper_conf_list.head) |
212380e3 AC |
106 | { |
107 | free_oper_conf(ptr->data); | |
330fc5c1 | 108 | rb_dlinkDestroy(ptr, &oper_conf_list); |
212380e3 AC |
109 | } |
110 | ||
637c4932 | 111 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, server_conf_list.head) |
212380e3 AC |
112 | { |
113 | server_p = ptr->data; | |
114 | ||
115 | if(!server_p->servers) | |
116 | { | |
330fc5c1 | 117 | rb_dlinkDelete(ptr, &server_conf_list); |
212380e3 AC |
118 | free_server_conf(ptr->data); |
119 | } | |
120 | else | |
121 | server_p->flags |= SERVER_ILLEGAL; | |
122 | } | |
123 | } | |
124 | ||
125 | void | |
126 | clear_s_newconf_bans(void) | |
127 | { | |
128 | struct ConfItem *aconf; | |
637c4932 | 129 | rb_dlink_node *ptr, *next_ptr; |
212380e3 | 130 | |
637c4932 | 131 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, xline_conf_list.head) |
212380e3 AC |
132 | { |
133 | aconf = ptr->data; | |
134 | ||
135 | if(aconf->hold) | |
136 | continue; | |
137 | ||
138 | free_conf(aconf); | |
330fc5c1 | 139 | rb_dlinkDestroy(ptr, &xline_conf_list); |
212380e3 AC |
140 | } |
141 | ||
637c4932 | 142 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, resv_conf_list.head) |
212380e3 AC |
143 | { |
144 | aconf = ptr->data; | |
145 | ||
146 | /* temporary resv */ | |
147 | if(aconf->hold) | |
148 | continue; | |
149 | ||
150 | free_conf(aconf); | |
330fc5c1 | 151 | rb_dlinkDestroy(ptr, &resv_conf_list); |
212380e3 AC |
152 | } |
153 | ||
154 | clear_resv_hash(); | |
155 | } | |
156 | ||
157 | struct remote_conf * | |
158 | make_remote_conf(void) | |
159 | { | |
eddc2ab6 | 160 | struct remote_conf *remote_p = rb_malloc(sizeof(struct remote_conf)); |
212380e3 AC |
161 | return remote_p; |
162 | } | |
163 | ||
164 | void | |
165 | free_remote_conf(struct remote_conf *remote_p) | |
166 | { | |
167 | s_assert(remote_p != NULL); | |
168 | if(remote_p == NULL) | |
169 | return; | |
170 | ||
637c4932 VY |
171 | rb_free(remote_p->username); |
172 | rb_free(remote_p->host); | |
173 | rb_free(remote_p->server); | |
174 | rb_free(remote_p); | |
212380e3 AC |
175 | } |
176 | ||
177 | int | |
55abcbb2 | 178 | find_shared_conf(const char *username, const char *host, |
212380e3 AC |
179 | const char *server, int flags) |
180 | { | |
181 | struct remote_conf *shared_p; | |
330fc5c1 | 182 | rb_dlink_node *ptr; |
212380e3 | 183 | |
5cefa1d6 | 184 | RB_DLINK_FOREACH(ptr, shared_conf_list.head) |
212380e3 AC |
185 | { |
186 | shared_p = ptr->data; | |
187 | ||
188 | if(match(shared_p->username, username) && | |
189 | match(shared_p->host, host) && | |
190 | match(shared_p->server, server)) | |
191 | { | |
192 | if(shared_p->flags & flags) | |
193 | return YES; | |
194 | else | |
195 | return NO; | |
196 | } | |
197 | } | |
198 | ||
199 | return NO; | |
200 | } | |
201 | ||
202 | void | |
203 | propagate_generic(struct Client *source_p, const char *command, | |
204 | const char *target, int cap, const char *format, ...) | |
205 | { | |
206 | char buffer[BUFSIZE]; | |
207 | va_list args; | |
208 | ||
209 | va_start(args, format); | |
5203cba5 | 210 | vsnprintf(buffer, sizeof(buffer), format, args); |
212380e3 AC |
211 | va_end(args); |
212 | ||
213 | sendto_match_servs(source_p, target, cap, NOCAPS, | |
214 | "%s %s %s", | |
215 | command, target, buffer); | |
216 | sendto_match_servs(source_p, target, CAP_ENCAP, cap, | |
217 | "ENCAP %s %s %s", | |
218 | target, command, buffer); | |
219 | } | |
55abcbb2 | 220 | |
212380e3 AC |
221 | void |
222 | cluster_generic(struct Client *source_p, const char *command, | |
223 | int cltype, int cap, const char *format, ...) | |
224 | { | |
225 | char buffer[BUFSIZE]; | |
226 | struct remote_conf *shared_p; | |
227 | va_list args; | |
330fc5c1 | 228 | rb_dlink_node *ptr; |
212380e3 AC |
229 | |
230 | va_start(args, format); | |
5203cba5 | 231 | vsnprintf(buffer, sizeof(buffer), format, args); |
212380e3 AC |
232 | va_end(args); |
233 | ||
5cefa1d6 | 234 | RB_DLINK_FOREACH(ptr, cluster_conf_list.head) |
212380e3 AC |
235 | { |
236 | shared_p = ptr->data; | |
237 | ||
238 | if(!(shared_p->flags & cltype)) | |
239 | continue; | |
240 | ||
241 | sendto_match_servs(source_p, shared_p->server, cap, NOCAPS, | |
242 | "%s %s %s", | |
243 | command, shared_p->server, buffer); | |
244 | sendto_match_servs(source_p, shared_p->server, CAP_ENCAP, cap, | |
245 | "ENCAP %s %s %s", | |
246 | shared_p->server, command, buffer); | |
247 | } | |
248 | } | |
249 | ||
250 | struct oper_conf * | |
251 | make_oper_conf(void) | |
252 | { | |
eddc2ab6 | 253 | struct oper_conf *oper_p = rb_malloc(sizeof(struct oper_conf)); |
212380e3 AC |
254 | return oper_p; |
255 | } | |
256 | ||
257 | void | |
258 | free_oper_conf(struct oper_conf *oper_p) | |
259 | { | |
260 | s_assert(oper_p != NULL); | |
261 | if(oper_p == NULL) | |
262 | return; | |
263 | ||
637c4932 VY |
264 | rb_free(oper_p->username); |
265 | rb_free(oper_p->host); | |
266 | rb_free(oper_p->name); | |
462ae9d7 | 267 | rb_free(oper_p->certfp); |
212380e3 AC |
268 | |
269 | if(oper_p->passwd) | |
270 | { | |
271 | memset(oper_p->passwd, 0, strlen(oper_p->passwd)); | |
637c4932 | 272 | rb_free(oper_p->passwd); |
212380e3 AC |
273 | } |
274 | ||
275 | #ifdef HAVE_LIBCRYPTO | |
637c4932 | 276 | rb_free(oper_p->rsa_pubkey_file); |
212380e3 AC |
277 | |
278 | if(oper_p->rsa_pubkey) | |
279 | RSA_free(oper_p->rsa_pubkey); | |
280 | #endif | |
281 | ||
637c4932 | 282 | rb_free(oper_p); |
212380e3 AC |
283 | } |
284 | ||
285 | struct oper_conf * | |
286 | find_oper_conf(const char *username, const char *host, const char *locip, const char *name) | |
287 | { | |
288 | struct oper_conf *oper_p; | |
e7046ee5 | 289 | struct rb_sockaddr_storage ip, cip; |
212380e3 AC |
290 | char addr[HOSTLEN+1]; |
291 | int bits, cbits; | |
330fc5c1 | 292 | rb_dlink_node *ptr; |
212380e3 | 293 | |
29c92cf9 | 294 | parse_netmask(locip, &cip, &cbits); |
212380e3 | 295 | |
5cefa1d6 | 296 | RB_DLINK_FOREACH(ptr, oper_conf_list.head) |
212380e3 AC |
297 | { |
298 | oper_p = ptr->data; | |
299 | ||
300 | /* name/username doesnt match.. */ | |
301 | if(irccmp(oper_p->name, name) || !match(oper_p->username, username)) | |
302 | continue; | |
303 | ||
f427c8b0 | 304 | rb_strlcpy(addr, oper_p->host, sizeof(addr)); |
212380e3 | 305 | |
29c92cf9 | 306 | if(parse_netmask(addr, &ip, &bits) != HM_HOST) |
212380e3 AC |
307 | { |
308 | if(ip.ss_family == cip.ss_family && | |
309 | comp_with_mask_sock((struct sockaddr *)&ip, (struct sockaddr *)&cip, bits)) | |
310 | return oper_p; | |
311 | } | |
312 | ||
313 | /* we have to compare against the host as well, because its | |
314 | * valid to set a spoof to an IP, which if we only compare | |
315 | * in ip form to sockhost will not necessarily match --anfl | |
316 | */ | |
317 | if(match(oper_p->host, host)) | |
318 | return oper_p; | |
319 | } | |
320 | ||
321 | return NULL; | |
322 | } | |
323 | ||
212380e3 AC |
324 | struct server_conf * |
325 | make_server_conf(void) | |
326 | { | |
eddc2ab6 | 327 | struct server_conf *server_p = rb_malloc(sizeof(struct server_conf)); |
212380e3 AC |
328 | server_p->aftype = AF_INET; |
329 | return server_p; | |
330 | } | |
331 | ||
332 | void | |
333 | free_server_conf(struct server_conf *server_p) | |
334 | { | |
335 | s_assert(server_p != NULL); | |
336 | if(server_p == NULL) | |
337 | return; | |
338 | ||
339 | if(!EmptyString(server_p->passwd)) | |
340 | { | |
341 | memset(server_p->passwd, 0, strlen(server_p->passwd)); | |
637c4932 | 342 | rb_free(server_p->passwd); |
212380e3 AC |
343 | } |
344 | ||
345 | if(!EmptyString(server_p->spasswd)) | |
346 | { | |
347 | memset(server_p->spasswd, 0, strlen(server_p->spasswd)); | |
637c4932 | 348 | rb_free(server_p->spasswd); |
212380e3 AC |
349 | } |
350 | ||
637c4932 VY |
351 | rb_free(server_p->name); |
352 | rb_free(server_p->host); | |
353 | rb_free(server_p->class_name); | |
354 | rb_free(server_p); | |
212380e3 AC |
355 | } |
356 | ||
1d02144f AC |
357 | /* |
358 | * conf_dns_callback | |
359 | * inputs - pointer to struct ConfItem | |
360 | * - pointer to adns reply | |
361 | * output - none | |
362 | * side effects - called when resolver query finishes | |
363 | * if the query resulted in a successful search, hp will contain | |
364 | * a non-null pointer, otherwise hp will be null. | |
365 | * if successful save hp in the conf item it was called with | |
366 | */ | |
367 | static void | |
368 | conf_dns_callback(const char *result, int status, int aftype, void *data) | |
369 | { | |
370 | struct server_conf *server_p = data; | |
371 | ||
372 | if(status == 1) | |
373 | rb_inet_pton_sock(result, (struct sockaddr *)&server_p->my_ipnum); | |
374 | ||
375 | server_p->dns_query = 0; | |
376 | } | |
377 | ||
212380e3 AC |
378 | void |
379 | add_server_conf(struct server_conf *server_p) | |
380 | { | |
381 | if(EmptyString(server_p->class_name)) | |
382 | { | |
47a03750 | 383 | server_p->class_name = rb_strdup("default"); |
212380e3 AC |
384 | server_p->class = default_class; |
385 | return; | |
386 | } | |
387 | ||
388 | server_p->class = find_class(server_p->class_name); | |
389 | ||
390 | if(server_p->class == default_class) | |
391 | { | |
392 | conf_report_error("Warning connect::class invalid for %s", | |
393 | server_p->name); | |
394 | ||
637c4932 | 395 | rb_free(server_p->class_name); |
47a03750 | 396 | server_p->class_name = rb_strdup("default"); |
212380e3 AC |
397 | } |
398 | ||
1d02144f | 399 | if(strpbrk(server_p->host, "*?")) |
212380e3 | 400 | return; |
1d02144f AC |
401 | |
402 | server_p->dns_query = | |
403 | lookup_hostname(server_p->host, GET_SS_FAMILY(&server_p->my_ipnum), conf_dns_callback, server_p); | |
212380e3 AC |
404 | } |
405 | ||
406 | struct server_conf * | |
407 | find_server_conf(const char *name) | |
408 | { | |
409 | struct server_conf *server_p; | |
330fc5c1 | 410 | rb_dlink_node *ptr; |
212380e3 | 411 | |
5cefa1d6 | 412 | RB_DLINK_FOREACH(ptr, server_conf_list.head) |
212380e3 AC |
413 | { |
414 | server_p = ptr->data; | |
415 | ||
416 | if(ServerConfIllegal(server_p)) | |
417 | continue; | |
418 | ||
419 | if(match(name, server_p->name)) | |
420 | return server_p; | |
421 | } | |
422 | ||
423 | return NULL; | |
424 | } | |
425 | ||
426 | void | |
427 | attach_server_conf(struct Client *client_p, struct server_conf *server_p) | |
428 | { | |
429 | /* already have an attached conf */ | |
430 | if(client_p->localClient->att_sconf) | |
431 | { | |
432 | /* short circuit this special case :) */ | |
433 | if(client_p->localClient->att_sconf == server_p) | |
434 | return; | |
435 | ||
436 | detach_server_conf(client_p); | |
437 | } | |
438 | ||
439 | CurrUsers(server_p->class)++; | |
440 | ||
441 | client_p->localClient->att_sconf = server_p; | |
442 | server_p->servers++; | |
443 | } | |
444 | ||
445 | void | |
446 | detach_server_conf(struct Client *client_p) | |
447 | { | |
448 | struct server_conf *server_p = client_p->localClient->att_sconf; | |
449 | ||
450 | if(server_p == NULL) | |
451 | return; | |
452 | ||
453 | client_p->localClient->att_sconf = NULL; | |
454 | server_p->servers--; | |
455 | CurrUsers(server_p->class)--; | |
456 | ||
457 | if(ServerConfIllegal(server_p) && !server_p->servers) | |
458 | { | |
459 | /* the class this one is using may need destroying too */ | |
460 | if(MaxUsers(server_p->class) < 0 && CurrUsers(server_p->class) <= 0) | |
461 | free_class(server_p->class); | |
462 | ||
330fc5c1 | 463 | rb_dlinkDelete(&server_p->node, &server_conf_list); |
212380e3 AC |
464 | free_server_conf(server_p); |
465 | } | |
466 | } | |
467 | ||
468 | void | |
a3143c9b | 469 | set_server_conf_autoconn(struct Client *source_p, const char *name, int newval) |
212380e3 AC |
470 | { |
471 | struct server_conf *server_p; | |
472 | ||
473 | if((server_p = find_server_conf(name)) != NULL) | |
474 | { | |
475 | if(newval) | |
476 | server_p->flags |= SERVER_AUTOCONN; | |
477 | else | |
478 | server_p->flags &= ~SERVER_AUTOCONN; | |
479 | ||
480 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
481 | "%s has changed AUTOCONN for %s to %i", | |
482 | get_oper_name(source_p), name, newval); | |
483 | } | |
484 | else | |
5366977b | 485 | sendto_one_notice(source_p, ":Can't find %s", name); |
212380e3 AC |
486 | } |
487 | ||
53307da8 JT |
488 | void |
489 | disable_server_conf_autoconn(const char *name) | |
490 | { | |
491 | struct server_conf *server_p; | |
492 | ||
493 | server_p = find_server_conf(name); | |
494 | if(server_p != NULL && server_p->flags & SERVER_AUTOCONN) | |
495 | { | |
496 | server_p->flags &= ~SERVER_AUTOCONN; | |
497 | ||
498 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
499 | "Disabling AUTOCONN for %s because of error", | |
500 | name); | |
501 | ilog(L_SERVER, "Disabling AUTOCONN for %s because of error", | |
502 | name); | |
503 | } | |
504 | } | |
505 | ||
212380e3 AC |
506 | struct ConfItem * |
507 | find_xline(const char *gecos, int counter) | |
508 | { | |
509 | struct ConfItem *aconf; | |
330fc5c1 | 510 | rb_dlink_node *ptr; |
212380e3 | 511 | |
5cefa1d6 | 512 | RB_DLINK_FOREACH(ptr, xline_conf_list.head) |
212380e3 AC |
513 | { |
514 | aconf = ptr->data; | |
515 | ||
70ea02eb | 516 | if(match_esc(aconf->host, gecos)) |
212380e3 AC |
517 | { |
518 | if(counter) | |
519 | aconf->port++; | |
520 | return aconf; | |
521 | } | |
522 | } | |
523 | ||
524 | return NULL; | |
525 | } | |
526 | ||
0fdb2570 JT |
527 | struct ConfItem * |
528 | find_xline_mask(const char *gecos) | |
529 | { | |
530 | struct ConfItem *aconf; | |
330fc5c1 | 531 | rb_dlink_node *ptr; |
0fdb2570 | 532 | |
5cefa1d6 | 533 | RB_DLINK_FOREACH(ptr, xline_conf_list.head) |
0fdb2570 JT |
534 | { |
535 | aconf = ptr->data; | |
536 | ||
70ea02eb | 537 | if(!irccmp(aconf->host, gecos)) |
0fdb2570 JT |
538 | return aconf; |
539 | } | |
540 | ||
541 | return NULL; | |
542 | } | |
543 | ||
212380e3 AC |
544 | struct ConfItem * |
545 | find_nick_resv(const char *name) | |
546 | { | |
547 | struct ConfItem *aconf; | |
330fc5c1 | 548 | rb_dlink_node *ptr; |
212380e3 | 549 | |
5cefa1d6 | 550 | RB_DLINK_FOREACH(ptr, resv_conf_list.head) |
212380e3 AC |
551 | { |
552 | aconf = ptr->data; | |
553 | ||
70ea02eb | 554 | if(match_esc(aconf->host, name)) |
212380e3 AC |
555 | { |
556 | aconf->port++; | |
557 | return aconf; | |
558 | } | |
559 | } | |
560 | ||
561 | return NULL; | |
562 | } | |
563 | ||
0fdb2570 JT |
564 | struct ConfItem * |
565 | find_nick_resv_mask(const char *name) | |
566 | { | |
567 | struct ConfItem *aconf; | |
330fc5c1 | 568 | rb_dlink_node *ptr; |
0fdb2570 | 569 | |
5cefa1d6 | 570 | RB_DLINK_FOREACH(ptr, resv_conf_list.head) |
0fdb2570 JT |
571 | { |
572 | aconf = ptr->data; | |
573 | ||
70ea02eb | 574 | if(!irccmp(aconf->host, name)) |
0fdb2570 JT |
575 | return aconf; |
576 | } | |
577 | ||
578 | return NULL; | |
579 | } | |
580 | ||
212380e3 AC |
581 | /* clean_resv_nick() |
582 | * | |
583 | * inputs - nick | |
584 | * outputs - 1 if nick is vaild resv, 0 otherwise | |
585 | * side effects - | |
586 | */ | |
587 | int | |
588 | clean_resv_nick(const char *nick) | |
589 | { | |
590 | char tmpch; | |
591 | int as = 0; | |
592 | int q = 0; | |
593 | int ch = 0; | |
594 | ||
595 | if(*nick == '-' || IsDigit(*nick)) | |
596 | return 0; | |
597 | ||
598 | while ((tmpch = *nick++)) | |
599 | { | |
600 | if(tmpch == '?' || tmpch == '@' || tmpch == '#') | |
601 | q++; | |
602 | else if(tmpch == '*') | |
603 | as++; | |
604 | else if(IsNickChar(tmpch)) | |
605 | ch++; | |
606 | else | |
607 | return 0; | |
608 | } | |
609 | ||
610 | if(!ch && as) | |
611 | return 0; | |
612 | ||
613 | return 1; | |
614 | } | |
615 | ||
616 | /* valid_wild_card_simple() | |
617 | * | |
618 | * inputs - "thing" to test | |
619 | * outputs - 1 if enough wildcards, else 0 | |
620 | * side effects - | |
621 | */ | |
622 | int | |
623 | valid_wild_card_simple(const char *data) | |
624 | { | |
625 | const char *p; | |
626 | char tmpch; | |
627 | int nonwild = 0; | |
7d08aa89 | 628 | int wild = 0; |
212380e3 AC |
629 | |
630 | /* check the string for minimum number of nonwildcard chars */ | |
631 | p = data; | |
632 | ||
633 | while((tmpch = *p++)) | |
634 | { | |
635 | /* found an escape, p points to the char after it, so skip | |
636 | * that and move on. | |
637 | */ | |
7d08aa89 | 638 | if(tmpch == '\\' && *p) |
212380e3 AC |
639 | { |
640 | p++; | |
7d08aa89 JT |
641 | if(++nonwild >= ConfigFileEntry.min_nonwildcard_simple) |
642 | return 1; | |
212380e3 AC |
643 | } |
644 | else if(!IsMWildChar(tmpch)) | |
645 | { | |
646 | /* if we have enough nonwildchars, return */ | |
647 | if(++nonwild >= ConfigFileEntry.min_nonwildcard_simple) | |
648 | return 1; | |
649 | } | |
7d08aa89 JT |
650 | else |
651 | wild++; | |
212380e3 AC |
652 | } |
653 | ||
7d08aa89 JT |
654 | /* strings without wilds are also ok */ |
655 | return wild == 0; | |
212380e3 AC |
656 | } |
657 | ||
658 | time_t | |
659 | valid_temp_time(const char *p) | |
660 | { | |
661 | time_t result = 0; | |
662 | ||
663 | while(*p) | |
664 | { | |
665 | if(IsDigit(*p)) | |
666 | { | |
667 | result *= 10; | |
668 | result += ((*p) & 0xF); | |
669 | p++; | |
670 | } | |
671 | else | |
672 | return -1; | |
673 | } | |
674 | ||
675 | if(result > (60 * 24 * 7 * 52)) | |
676 | result = (60 * 24 * 7 * 52); | |
677 | ||
678 | return(result * 60); | |
679 | } | |
680 | ||
9197bc35 | 681 | /* Propagated bans are expired elsewhere. */ |
212380e3 AC |
682 | static void |
683 | expire_temp_rxlines(void *unused) | |
684 | { | |
685 | struct ConfItem *aconf; | |
330fc5c1 | 686 | rb_dlink_node *ptr; |
637c4932 | 687 | rb_dlink_node *next_ptr; |
212380e3 | 688 | int i; |
a4bf26dd | 689 | struct rb_radixtree_iteration_state state; |
212380e3 | 690 | |
a4bf26dd | 691 | RB_RADIXTREE_FOREACH(aconf, &state, resv_tree) |
212380e3 | 692 | { |
9197bc35 JT |
693 | if(aconf->lifetime != 0) |
694 | continue; | |
e3354945 | 695 | if(aconf->hold && aconf->hold <= rb_current_time()) |
212380e3 AC |
696 | { |
697 | if(ConfigFileEntry.tkline_expire_notices) | |
698 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
699 | "Temporary RESV for [%s] expired", | |
70ea02eb | 700 | aconf->host); |
212380e3 | 701 | |
a4bf26dd | 702 | rb_radixtree_delete(resv_tree, aconf->host); |
212380e3 | 703 | free_conf(aconf); |
212380e3 AC |
704 | } |
705 | } | |
212380e3 | 706 | |
637c4932 | 707 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, resv_conf_list.head) |
212380e3 AC |
708 | { |
709 | aconf = ptr->data; | |
710 | ||
9197bc35 JT |
711 | if(aconf->lifetime != 0) |
712 | continue; | |
e3354945 | 713 | if(aconf->hold && aconf->hold <= rb_current_time()) |
212380e3 AC |
714 | { |
715 | if(ConfigFileEntry.tkline_expire_notices) | |
716 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
717 | "Temporary RESV for [%s] expired", | |
70ea02eb | 718 | aconf->host); |
212380e3 | 719 | free_conf(aconf); |
330fc5c1 | 720 | rb_dlinkDestroy(ptr, &resv_conf_list); |
212380e3 AC |
721 | } |
722 | } | |
723 | ||
637c4932 | 724 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, xline_conf_list.head) |
212380e3 AC |
725 | { |
726 | aconf = ptr->data; | |
727 | ||
9197bc35 JT |
728 | if(aconf->lifetime != 0) |
729 | continue; | |
e3354945 | 730 | if(aconf->hold && aconf->hold <= rb_current_time()) |
212380e3 AC |
731 | { |
732 | if(ConfigFileEntry.tkline_expire_notices) | |
733 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
734 | "Temporary X-line for [%s] expired", | |
70ea02eb | 735 | aconf->host); |
212380e3 | 736 | free_conf(aconf); |
330fc5c1 | 737 | rb_dlinkDestroy(ptr, &xline_conf_list); |
212380e3 AC |
738 | } |
739 | } | |
740 | } | |
741 | ||
742 | unsigned long | |
743 | get_nd_count(void) | |
744 | { | |
330fc5c1 | 745 | return(rb_dlink_list_length(&nd_list)); |
212380e3 AC |
746 | } |
747 | ||
212380e3 AC |
748 | void |
749 | add_nd_entry(const char *name) | |
750 | { | |
751 | struct nd_entry *nd; | |
752 | ||
a4bf26dd | 753 | if(rb_dictionary_find(nd_dict, name) != NULL) |
212380e3 AC |
754 | return; |
755 | ||
398b6a73 | 756 | nd = rb_bh_alloc(nd_heap); |
55abcbb2 | 757 | |
f427c8b0 | 758 | rb_strlcpy(nd->name, name, sizeof(nd->name)); |
e3354945 | 759 | nd->expire = rb_current_time() + ConfigFileEntry.nick_delay; |
212380e3 AC |
760 | |
761 | /* this list is ordered */ | |
330fc5c1 | 762 | rb_dlinkAddTail(nd, &nd->lnode, &nd_list); |
b37021a4 | 763 | |
a4bf26dd | 764 | rb_dictionary_add(nd_dict, nd->name, nd); |
212380e3 AC |
765 | } |
766 | ||
767 | void | |
768 | free_nd_entry(struct nd_entry *nd) | |
769 | { | |
a4bf26dd | 770 | rb_dictionary_delete(nd_dict, nd->name); |
b37021a4 | 771 | |
330fc5c1 | 772 | rb_dlinkDelete(&nd->lnode, &nd_list); |
398b6a73 | 773 | rb_bh_free(nd_heap, nd); |
212380e3 AC |
774 | } |
775 | ||
776 | void | |
777 | expire_nd_entries(void *unused) | |
778 | { | |
779 | struct nd_entry *nd; | |
330fc5c1 | 780 | rb_dlink_node *ptr; |
637c4932 | 781 | rb_dlink_node *next_ptr; |
212380e3 | 782 | |
637c4932 | 783 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, nd_list.head) |
212380e3 AC |
784 | { |
785 | nd = ptr->data; | |
786 | ||
787 | /* this list is ordered - we can stop when we hit the first | |
788 | * entry that doesnt expire.. | |
789 | */ | |
e3354945 | 790 | if(nd->expire > rb_current_time()) |
212380e3 AC |
791 | return; |
792 | ||
793 | free_nd_entry(nd); | |
794 | } | |
795 | } | |
796 | ||
797 | void | |
798 | add_tgchange(const char *host) | |
799 | { | |
800 | tgchange *target; | |
e410dcf5 | 801 | rb_patricia_node_t *pnode; |
212380e3 AC |
802 | |
803 | if(find_tgchange(host)) | |
804 | return; | |
805 | ||
eddc2ab6 | 806 | target = rb_malloc(sizeof(tgchange)); |
212380e3 AC |
807 | pnode = make_and_lookup(tgchange_tree, host); |
808 | ||
809 | pnode->data = target; | |
810 | target->pnode = pnode; | |
811 | ||
47a03750 | 812 | target->ip = rb_strdup(host); |
e3354945 | 813 | target->expiry = rb_current_time() + (60*60*12); |
212380e3 | 814 | |
330fc5c1 | 815 | rb_dlinkAdd(target, &target->node, &tgchange_list); |
212380e3 AC |
816 | } |
817 | ||
818 | tgchange * | |
819 | find_tgchange(const char *host) | |
820 | { | |
e410dcf5 | 821 | rb_patricia_node_t *pnode; |
212380e3 | 822 | |
e410dcf5 | 823 | if((pnode = rb_match_exact_string(tgchange_tree, host))) |
212380e3 AC |
824 | return pnode->data; |
825 | ||
826 | return NULL; | |
827 | } |