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