]>
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 | * $Id: s_newconf.c 3508 2007-06-04 16:04:49Z jilles $ | |
33 | */ | |
34 | ||
35 | #include "stdinc.h" | |
36 | #include "ircd_defs.h" | |
37 | #include "common.h" | |
38 | #include "s_conf.h" | |
39 | #include "s_newconf.h" | |
40 | #include "tools.h" | |
41 | #include "client.h" | |
42 | #include "memory.h" | |
43 | #include "s_serv.h" | |
44 | #include "send.h" | |
45 | #include "hostmask.h" | |
46 | #include "newconf.h" | |
47 | #include "hash.h" | |
48 | #include "balloc.h" | |
49 | #include "event.h" | |
50 | #include "sprintf_irc.h" | |
51 | #include "irc_dictionary.h" | |
52 | ||
53 | dlink_list shared_conf_list; | |
54 | dlink_list cluster_conf_list; | |
55 | dlink_list oper_conf_list; | |
56 | dlink_list hubleaf_conf_list; | |
57 | dlink_list server_conf_list; | |
58 | dlink_list xline_conf_list; | |
59 | dlink_list resv_conf_list; /* nicks only! */ | |
60 | dlink_list nd_list; /* nick delay */ | |
61 | dlink_list tgchange_list; | |
62 | ||
63 | patricia_tree_t *tgchange_tree; | |
64 | ||
65 | static BlockHeap *nd_heap = NULL; | |
66 | ||
67 | static void expire_temp_rxlines(void *unused); | |
68 | static void expire_nd_entries(void *unused); | |
69 | ||
70 | void | |
71 | init_s_newconf(void) | |
72 | { | |
73 | tgchange_tree = New_Patricia(PATRICIA_BITS); | |
74 | nd_heap = BlockHeapCreate(sizeof(struct nd_entry), ND_HEAP_SIZE); | |
75 | eventAddIsh("expire_nd_entries", expire_nd_entries, NULL, 30); | |
76 | eventAddIsh("expire_temp_rxlines", expire_temp_rxlines, NULL, 60); | |
77 | } | |
78 | ||
79 | void | |
80 | clear_s_newconf(void) | |
81 | { | |
82 | struct server_conf *server_p; | |
83 | dlink_node *ptr; | |
84 | dlink_node *next_ptr; | |
85 | ||
86 | DLINK_FOREACH_SAFE(ptr, next_ptr, shared_conf_list.head) | |
87 | { | |
88 | /* ptr here is ptr->data->node */ | |
89 | dlinkDelete(ptr, &shared_conf_list); | |
90 | free_remote_conf(ptr->data); | |
91 | } | |
92 | ||
93 | DLINK_FOREACH_SAFE(ptr, next_ptr, cluster_conf_list.head) | |
94 | { | |
95 | dlinkDelete(ptr, &cluster_conf_list); | |
96 | free_remote_conf(ptr->data); | |
97 | } | |
98 | ||
99 | DLINK_FOREACH_SAFE(ptr, next_ptr, hubleaf_conf_list.head) | |
100 | { | |
101 | dlinkDelete(ptr, &hubleaf_conf_list); | |
102 | free_remote_conf(ptr->data); | |
103 | } | |
104 | ||
105 | DLINK_FOREACH_SAFE(ptr, next_ptr, oper_conf_list.head) | |
106 | { | |
107 | free_oper_conf(ptr->data); | |
108 | dlinkDestroy(ptr, &oper_conf_list); | |
109 | } | |
110 | ||
111 | DLINK_FOREACH_SAFE(ptr, next_ptr, server_conf_list.head) | |
112 | { | |
113 | server_p = ptr->data; | |
114 | ||
115 | if(!server_p->servers) | |
116 | { | |
117 | dlinkDelete(ptr, &server_conf_list); | |
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; | |
129 | dlink_node *ptr, *next_ptr; | |
130 | ||
131 | DLINK_FOREACH_SAFE(ptr, next_ptr, xline_conf_list.head) | |
132 | { | |
133 | aconf = ptr->data; | |
134 | ||
135 | if(aconf->hold) | |
136 | continue; | |
137 | ||
138 | free_conf(aconf); | |
139 | dlinkDestroy(ptr, &xline_conf_list); | |
140 | } | |
141 | ||
142 | DLINK_FOREACH_SAFE(ptr, next_ptr, resv_conf_list.head) | |
143 | { | |
144 | aconf = ptr->data; | |
145 | ||
146 | /* temporary resv */ | |
147 | if(aconf->hold) | |
148 | continue; | |
149 | ||
150 | free_conf(aconf); | |
151 | dlinkDestroy(ptr, &resv_conf_list); | |
152 | } | |
153 | ||
154 | clear_resv_hash(); | |
155 | } | |
156 | ||
157 | struct remote_conf * | |
158 | make_remote_conf(void) | |
159 | { | |
160 | struct remote_conf *remote_p = MyMalloc(sizeof(struct remote_conf)); | |
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 | ||
171 | MyFree(remote_p->username); | |
172 | MyFree(remote_p->host); | |
173 | MyFree(remote_p->server); | |
174 | MyFree(remote_p); | |
175 | } | |
176 | ||
177 | int | |
178 | find_shared_conf(const char *username, const char *host, | |
179 | const char *server, int flags) | |
180 | { | |
181 | struct remote_conf *shared_p; | |
182 | dlink_node *ptr; | |
183 | ||
184 | DLINK_FOREACH(ptr, shared_conf_list.head) | |
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); | |
210 | ircvsnprintf(buffer, sizeof(buffer), format, args); | |
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 | } | |
220 | ||
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; | |
228 | dlink_node *ptr; | |
229 | ||
230 | va_start(args, format); | |
231 | ircvsnprintf(buffer, sizeof(buffer), format, args); | |
232 | va_end(args); | |
233 | ||
234 | DLINK_FOREACH(ptr, cluster_conf_list.head) | |
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 | { | |
253 | struct oper_conf *oper_p = MyMalloc(sizeof(struct oper_conf)); | |
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 | ||
264 | MyFree(oper_p->username); | |
265 | MyFree(oper_p->host); | |
266 | MyFree(oper_p->name); | |
267 | ||
268 | if(oper_p->passwd) | |
269 | { | |
270 | memset(oper_p->passwd, 0, strlen(oper_p->passwd)); | |
271 | MyFree(oper_p->passwd); | |
272 | } | |
273 | ||
274 | #ifdef HAVE_LIBCRYPTO | |
275 | MyFree(oper_p->rsa_pubkey_file); | |
276 | ||
277 | if(oper_p->rsa_pubkey) | |
278 | RSA_free(oper_p->rsa_pubkey); | |
279 | #endif | |
280 | ||
281 | MyFree(oper_p); | |
282 | } | |
283 | ||
284 | struct oper_conf * | |
285 | find_oper_conf(const char *username, const char *host, const char *locip, const char *name) | |
286 | { | |
287 | struct oper_conf *oper_p; | |
288 | struct irc_sockaddr_storage ip, cip; | |
289 | char addr[HOSTLEN+1]; | |
290 | int bits, cbits; | |
291 | dlink_node *ptr; | |
292 | ||
293 | parse_netmask(locip, (struct sockaddr *)&cip, &cbits); | |
294 | ||
295 | DLINK_FOREACH(ptr, oper_conf_list.head) | |
296 | { | |
297 | oper_p = ptr->data; | |
298 | ||
299 | /* name/username doesnt match.. */ | |
300 | if(irccmp(oper_p->name, name) || !match(oper_p->username, username)) | |
301 | continue; | |
302 | ||
303 | strlcpy(addr, oper_p->host, sizeof(addr)); | |
304 | ||
305 | if(parse_netmask(addr, (struct sockaddr *)&ip, &bits) != HM_HOST) | |
306 | { | |
307 | if(ip.ss_family == cip.ss_family && | |
308 | comp_with_mask_sock((struct sockaddr *)&ip, (struct sockaddr *)&cip, bits)) | |
309 | return oper_p; | |
310 | } | |
311 | ||
312 | /* we have to compare against the host as well, because its | |
313 | * valid to set a spoof to an IP, which if we only compare | |
314 | * in ip form to sockhost will not necessarily match --anfl | |
315 | */ | |
316 | if(match(oper_p->host, host)) | |
317 | return oper_p; | |
318 | } | |
319 | ||
320 | return NULL; | |
321 | } | |
322 | ||
323 | struct oper_flags | |
324 | { | |
325 | int flag; | |
326 | char has; | |
327 | char hasnt; | |
328 | }; | |
329 | static struct oper_flags oper_flagtable[] = | |
330 | { | |
331 | { OPER_GLINE, 'G', 'g' }, | |
332 | { OPER_KLINE, 'K', 'k' }, | |
333 | { OPER_XLINE, 'X', 'x' }, | |
334 | { OPER_RESV, 'Q', 'q' }, | |
335 | { OPER_GLOBKILL, 'O', 'o' }, | |
336 | { OPER_LOCKILL, 'C', 'c' }, | |
337 | { OPER_REMOTE, 'R', 'r' }, | |
338 | { OPER_UNKLINE, 'U', 'u' }, | |
339 | { OPER_REHASH, 'H', 'h' }, | |
340 | { OPER_DIE, 'D', 'd' }, | |
341 | { OPER_ADMIN, 'A', 'a' }, | |
342 | { OPER_NICKS, 'N', 'n' }, | |
343 | { OPER_OPERWALL, 'L', 'l' }, | |
344 | { OPER_SPY, 'S', 's' }, | |
345 | { OPER_INVIS, 'P', 'p' }, | |
346 | { OPER_REMOTEBAN, 'B', 'b' }, | |
347 | { 0, '\0', '\0' } | |
348 | }; | |
349 | ||
350 | const char * | |
351 | get_oper_privs(int flags) | |
352 | { | |
353 | static char buf[20]; | |
354 | char *p; | |
355 | int i; | |
356 | ||
357 | p = buf; | |
358 | ||
359 | for(i = 0; oper_flagtable[i].flag; i++) | |
360 | { | |
361 | if(flags & oper_flagtable[i].flag) | |
362 | *p++ = oper_flagtable[i].has; | |
363 | else | |
364 | *p++ = oper_flagtable[i].hasnt; | |
365 | } | |
366 | ||
367 | *p = '\0'; | |
368 | ||
369 | return buf; | |
370 | } | |
371 | ||
372 | struct server_conf * | |
373 | make_server_conf(void) | |
374 | { | |
375 | struct server_conf *server_p = MyMalloc(sizeof(struct server_conf)); | |
376 | server_p->aftype = AF_INET; | |
377 | return server_p; | |
378 | } | |
379 | ||
380 | void | |
381 | free_server_conf(struct server_conf *server_p) | |
382 | { | |
383 | s_assert(server_p != NULL); | |
384 | if(server_p == NULL) | |
385 | return; | |
386 | ||
387 | if(!EmptyString(server_p->passwd)) | |
388 | { | |
389 | memset(server_p->passwd, 0, strlen(server_p->passwd)); | |
390 | MyFree(server_p->passwd); | |
391 | } | |
392 | ||
393 | if(!EmptyString(server_p->spasswd)) | |
394 | { | |
395 | memset(server_p->spasswd, 0, strlen(server_p->spasswd)); | |
396 | MyFree(server_p->spasswd); | |
397 | } | |
398 | ||
399 | MyFree(server_p->name); | |
400 | MyFree(server_p->host); | |
401 | MyFree(server_p->class_name); | |
402 | MyFree(server_p); | |
403 | } | |
404 | ||
405 | void | |
406 | add_server_conf(struct server_conf *server_p) | |
407 | { | |
408 | if(EmptyString(server_p->class_name)) | |
409 | { | |
410 | DupString(server_p->class_name, "default"); | |
411 | server_p->class = default_class; | |
412 | return; | |
413 | } | |
414 | ||
415 | server_p->class = find_class(server_p->class_name); | |
416 | ||
417 | if(server_p->class == default_class) | |
418 | { | |
419 | conf_report_error("Warning connect::class invalid for %s", | |
420 | server_p->name); | |
421 | ||
422 | MyFree(server_p->class_name); | |
423 | DupString(server_p->class_name, "default"); | |
424 | } | |
425 | ||
426 | if(strchr(server_p->host, '*') || strchr(server_p->host, '?')) | |
427 | return; | |
428 | } | |
429 | ||
430 | struct server_conf * | |
431 | find_server_conf(const char *name) | |
432 | { | |
433 | struct server_conf *server_p; | |
434 | dlink_node *ptr; | |
435 | ||
436 | DLINK_FOREACH(ptr, server_conf_list.head) | |
437 | { | |
438 | server_p = ptr->data; | |
439 | ||
440 | if(ServerConfIllegal(server_p)) | |
441 | continue; | |
442 | ||
443 | if(match(name, server_p->name)) | |
444 | return server_p; | |
445 | } | |
446 | ||
447 | return NULL; | |
448 | } | |
449 | ||
450 | void | |
451 | attach_server_conf(struct Client *client_p, struct server_conf *server_p) | |
452 | { | |
453 | /* already have an attached conf */ | |
454 | if(client_p->localClient->att_sconf) | |
455 | { | |
456 | /* short circuit this special case :) */ | |
457 | if(client_p->localClient->att_sconf == server_p) | |
458 | return; | |
459 | ||
460 | detach_server_conf(client_p); | |
461 | } | |
462 | ||
463 | CurrUsers(server_p->class)++; | |
464 | ||
465 | client_p->localClient->att_sconf = server_p; | |
466 | server_p->servers++; | |
467 | } | |
468 | ||
469 | void | |
470 | detach_server_conf(struct Client *client_p) | |
471 | { | |
472 | struct server_conf *server_p = client_p->localClient->att_sconf; | |
473 | ||
474 | if(server_p == NULL) | |
475 | return; | |
476 | ||
477 | client_p->localClient->att_sconf = NULL; | |
478 | server_p->servers--; | |
479 | CurrUsers(server_p->class)--; | |
480 | ||
481 | if(ServerConfIllegal(server_p) && !server_p->servers) | |
482 | { | |
483 | /* the class this one is using may need destroying too */ | |
484 | if(MaxUsers(server_p->class) < 0 && CurrUsers(server_p->class) <= 0) | |
485 | free_class(server_p->class); | |
486 | ||
487 | dlinkDelete(&server_p->node, &server_conf_list); | |
488 | free_server_conf(server_p); | |
489 | } | |
490 | } | |
491 | ||
492 | void | |
493 | set_server_conf_autoconn(struct Client *source_p, char *name, int newval) | |
494 | { | |
495 | struct server_conf *server_p; | |
496 | ||
497 | if((server_p = find_server_conf(name)) != NULL) | |
498 | { | |
499 | if(newval) | |
500 | server_p->flags |= SERVER_AUTOCONN; | |
501 | else | |
502 | server_p->flags &= ~SERVER_AUTOCONN; | |
503 | ||
504 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
505 | "%s has changed AUTOCONN for %s to %i", | |
506 | get_oper_name(source_p), name, newval); | |
507 | } | |
508 | else | |
509 | sendto_one_notice(source_p, ":Can't find %s", name); | |
510 | } | |
511 | ||
512 | struct ConfItem * | |
513 | find_xline(const char *gecos, int counter) | |
514 | { | |
515 | struct ConfItem *aconf; | |
516 | dlink_node *ptr; | |
517 | ||
518 | DLINK_FOREACH(ptr, xline_conf_list.head) | |
519 | { | |
520 | aconf = ptr->data; | |
521 | ||
522 | if(match_esc(aconf->name, gecos)) | |
523 | { | |
524 | if(counter) | |
525 | aconf->port++; | |
526 | return aconf; | |
527 | } | |
528 | } | |
529 | ||
530 | return NULL; | |
531 | } | |
532 | ||
533 | struct ConfItem * | |
534 | find_xline_mask(const char *gecos) | |
535 | { | |
536 | struct ConfItem *aconf; | |
537 | dlink_node *ptr; | |
538 | ||
539 | DLINK_FOREACH(ptr, xline_conf_list.head) | |
540 | { | |
541 | aconf = ptr->data; | |
542 | ||
543 | if(!irccmp(aconf->name, gecos)) | |
544 | return aconf; | |
545 | } | |
546 | ||
547 | return NULL; | |
548 | } | |
549 | ||
550 | struct ConfItem * | |
551 | find_nick_resv(const char *name) | |
552 | { | |
553 | struct ConfItem *aconf; | |
554 | dlink_node *ptr; | |
555 | ||
556 | DLINK_FOREACH(ptr, resv_conf_list.head) | |
557 | { | |
558 | aconf = ptr->data; | |
559 | ||
560 | if(match_esc(aconf->name, name)) | |
561 | { | |
562 | aconf->port++; | |
563 | return aconf; | |
564 | } | |
565 | } | |
566 | ||
567 | return NULL; | |
568 | } | |
569 | ||
570 | struct ConfItem * | |
571 | find_nick_resv_mask(const char *name) | |
572 | { | |
573 | struct ConfItem *aconf; | |
574 | dlink_node *ptr; | |
575 | ||
576 | DLINK_FOREACH(ptr, resv_conf_list.head) | |
577 | { | |
578 | aconf = ptr->data; | |
579 | ||
580 | if(!irccmp(aconf->name, name)) | |
581 | return aconf; | |
582 | } | |
583 | ||
584 | return NULL; | |
585 | } | |
586 | ||
587 | /* clean_resv_nick() | |
588 | * | |
589 | * inputs - nick | |
590 | * outputs - 1 if nick is vaild resv, 0 otherwise | |
591 | * side effects - | |
592 | */ | |
593 | int | |
594 | clean_resv_nick(const char *nick) | |
595 | { | |
596 | char tmpch; | |
597 | int as = 0; | |
598 | int q = 0; | |
599 | int ch = 0; | |
600 | ||
601 | if(*nick == '-' || IsDigit(*nick)) | |
602 | return 0; | |
603 | ||
604 | while ((tmpch = *nick++)) | |
605 | { | |
606 | if(tmpch == '?' || tmpch == '@' || tmpch == '#') | |
607 | q++; | |
608 | else if(tmpch == '*') | |
609 | as++; | |
610 | else if(IsNickChar(tmpch)) | |
611 | ch++; | |
612 | else | |
613 | return 0; | |
614 | } | |
615 | ||
616 | if(!ch && as) | |
617 | return 0; | |
618 | ||
619 | return 1; | |
620 | } | |
621 | ||
622 | /* valid_wild_card_simple() | |
623 | * | |
624 | * inputs - "thing" to test | |
625 | * outputs - 1 if enough wildcards, else 0 | |
626 | * side effects - | |
627 | */ | |
628 | int | |
629 | valid_wild_card_simple(const char *data) | |
630 | { | |
631 | const char *p; | |
632 | char tmpch; | |
633 | int nonwild = 0; | |
634 | int wild = 0; | |
635 | ||
636 | /* check the string for minimum number of nonwildcard chars */ | |
637 | p = data; | |
638 | ||
639 | while((tmpch = *p++)) | |
640 | { | |
641 | /* found an escape, p points to the char after it, so skip | |
642 | * that and move on. | |
643 | */ | |
644 | if(tmpch == '\\' && *p) | |
645 | { | |
646 | p++; | |
647 | if(++nonwild >= ConfigFileEntry.min_nonwildcard_simple) | |
648 | return 1; | |
649 | } | |
650 | else if(!IsMWildChar(tmpch)) | |
651 | { | |
652 | /* if we have enough nonwildchars, return */ | |
653 | if(++nonwild >= ConfigFileEntry.min_nonwildcard_simple) | |
654 | return 1; | |
655 | } | |
656 | else | |
657 | wild++; | |
658 | } | |
659 | ||
660 | /* strings without wilds are also ok */ | |
661 | return wild == 0; | |
662 | } | |
663 | ||
664 | time_t | |
665 | valid_temp_time(const char *p) | |
666 | { | |
667 | time_t result = 0; | |
668 | ||
669 | while(*p) | |
670 | { | |
671 | if(IsDigit(*p)) | |
672 | { | |
673 | result *= 10; | |
674 | result += ((*p) & 0xF); | |
675 | p++; | |
676 | } | |
677 | else | |
678 | return -1; | |
679 | } | |
680 | ||
681 | if(result > (60 * 24 * 7 * 52)) | |
682 | result = (60 * 24 * 7 * 52); | |
683 | ||
684 | return(result * 60); | |
685 | } | |
686 | ||
687 | static void | |
688 | expire_temp_rxlines(void *unused) | |
689 | { | |
690 | struct ConfItem *aconf; | |
691 | dlink_node *ptr; | |
692 | dlink_node *next_ptr; | |
693 | int i; | |
694 | ||
695 | HASH_WALK_SAFE(i, R_MAX, ptr, next_ptr, resvTable) | |
696 | { | |
697 | aconf = ptr->data; | |
698 | ||
699 | if(aconf->hold && aconf->hold <= CurrentTime) | |
700 | { | |
701 | if(ConfigFileEntry.tkline_expire_notices) | |
702 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
703 | "Temporary RESV for [%s] expired", | |
704 | aconf->name); | |
705 | ||
706 | free_conf(aconf); | |
707 | dlinkDestroy(ptr, &resvTable[i]); | |
708 | } | |
709 | } | |
710 | HASH_WALK_END | |
711 | ||
712 | DLINK_FOREACH_SAFE(ptr, next_ptr, resv_conf_list.head) | |
713 | { | |
714 | aconf = ptr->data; | |
715 | ||
716 | if(aconf->hold && aconf->hold <= CurrentTime) | |
717 | { | |
718 | if(ConfigFileEntry.tkline_expire_notices) | |
719 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
720 | "Temporary RESV for [%s] expired", | |
721 | aconf->name); | |
722 | free_conf(aconf); | |
723 | dlinkDestroy(ptr, &resv_conf_list); | |
724 | } | |
725 | } | |
726 | ||
727 | DLINK_FOREACH_SAFE(ptr, next_ptr, xline_conf_list.head) | |
728 | { | |
729 | aconf = ptr->data; | |
730 | ||
731 | if(aconf->hold && aconf->hold <= CurrentTime) | |
732 | { | |
733 | if(ConfigFileEntry.tkline_expire_notices) | |
734 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
735 | "Temporary X-line for [%s] expired", | |
736 | aconf->name); | |
737 | free_conf(aconf); | |
738 | dlinkDestroy(ptr, &xline_conf_list); | |
739 | } | |
740 | } | |
741 | } | |
742 | ||
743 | unsigned long | |
744 | get_nd_count(void) | |
745 | { | |
746 | return(dlink_list_length(&nd_list)); | |
747 | } | |
748 | ||
749 | void | |
750 | add_nd_entry(const char *name) | |
751 | { | |
752 | struct nd_entry *nd; | |
753 | ||
754 | if(irc_dictionary_find(nd_dict, name) != NULL) | |
755 | return; | |
756 | ||
757 | nd = BlockHeapAlloc(nd_heap); | |
758 | ||
759 | strlcpy(nd->name, name, sizeof(nd->name)); | |
760 | nd->expire = CurrentTime + ConfigFileEntry.nick_delay; | |
761 | ||
762 | /* this list is ordered */ | |
763 | dlinkAddTail(nd, &nd->lnode, &nd_list); | |
764 | ||
765 | irc_dictionary_add(nd_dict, nd->name, nd); | |
766 | } | |
767 | ||
768 | void | |
769 | free_nd_entry(struct nd_entry *nd) | |
770 | { | |
771 | irc_dictionary_delete(nd_dict, nd->name); | |
772 | ||
773 | dlinkDelete(&nd->lnode, &nd_list); | |
774 | BlockHeapFree(nd_heap, nd); | |
775 | } | |
776 | ||
777 | void | |
778 | expire_nd_entries(void *unused) | |
779 | { | |
780 | struct nd_entry *nd; | |
781 | dlink_node *ptr; | |
782 | dlink_node *next_ptr; | |
783 | ||
784 | DLINK_FOREACH_SAFE(ptr, next_ptr, nd_list.head) | |
785 | { | |
786 | nd = ptr->data; | |
787 | ||
788 | /* this list is ordered - we can stop when we hit the first | |
789 | * entry that doesnt expire.. | |
790 | */ | |
791 | if(nd->expire > CurrentTime) | |
792 | return; | |
793 | ||
794 | free_nd_entry(nd); | |
795 | } | |
796 | } | |
797 | ||
798 | void | |
799 | add_tgchange(const char *host) | |
800 | { | |
801 | tgchange *target; | |
802 | patricia_node_t *pnode; | |
803 | ||
804 | if(find_tgchange(host)) | |
805 | return; | |
806 | ||
807 | target = MyMalloc(sizeof(tgchange)); | |
808 | pnode = make_and_lookup(tgchange_tree, host); | |
809 | ||
810 | pnode->data = target; | |
811 | target->pnode = pnode; | |
812 | ||
813 | DupString(target->ip, host); | |
814 | target->expiry = CurrentTime + (60*60*12); | |
815 | ||
816 | dlinkAdd(target, &target->node, &tgchange_list); | |
817 | } | |
818 | ||
819 | tgchange * | |
820 | find_tgchange(const char *host) | |
821 | { | |
822 | patricia_node_t *pnode; | |
823 | ||
824 | if((pnode = match_exact_string(tgchange_tree, host))) | |
825 | return pnode->data; | |
826 | ||
827 | return NULL; | |
828 | } | |
829 |