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