]>
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. | |
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" | |
212380e3 | 46 | #include "sprintf_irc.h" |
b37021a4 | 47 | #include "irc_dictionary.h" |
212380e3 | 48 | |
330fc5c1 AC |
49 | rb_dlink_list shared_conf_list; |
50 | rb_dlink_list cluster_conf_list; | |
51 | rb_dlink_list oper_conf_list; | |
52 | rb_dlink_list hubleaf_conf_list; | |
53 | rb_dlink_list server_conf_list; | |
54 | rb_dlink_list xline_conf_list; | |
55 | rb_dlink_list resv_conf_list; /* nicks only! */ | |
56 | rb_dlink_list nd_list; /* nick delay */ | |
57 | rb_dlink_list tgchange_list; | |
212380e3 | 58 | |
7018b86a | 59 | rb_patricia_tree_t *tgchange_tree; |
212380e3 | 60 | |
398b6a73 | 61 | static rb_bh *nd_heap = NULL; |
212380e3 AC |
62 | |
63 | static void expire_temp_rxlines(void *unused); | |
64 | static void expire_nd_entries(void *unused); | |
65 | ||
e410dcf5 AC |
66 | struct ev_entry *expire_nd_entries_ev = NULL; |
67 | struct ev_entry *expire_temp_rxlines_ev = NULL; | |
68 | ||
212380e3 AC |
69 | void |
70 | init_s_newconf(void) | |
71 | { | |
e410dcf5 AC |
72 | tgchange_tree = rb_new_patricia(PATRICIA_BITS); |
73 | nd_heap = rb_bh_create(sizeof(struct nd_entry), ND_HEAP_SIZE, "nd_heap"); | |
74 | expire_nd_entries_ev = rb_event_addish("expire_nd_entries", expire_nd_entries, NULL, 30); | |
75 | expire_temp_rxlines_ev = rb_event_addish("expire_temp_rxlines", expire_temp_rxlines, NULL, 60); | |
212380e3 AC |
76 | } |
77 | ||
78 | void | |
79 | clear_s_newconf(void) | |
80 | { | |
81 | struct server_conf *server_p; | |
330fc5c1 | 82 | rb_dlink_node *ptr; |
637c4932 | 83 | rb_dlink_node *next_ptr; |
212380e3 | 84 | |
637c4932 | 85 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, shared_conf_list.head) |
212380e3 AC |
86 | { |
87 | /* ptr here is ptr->data->node */ | |
330fc5c1 | 88 | rb_dlinkDelete(ptr, &shared_conf_list); |
212380e3 AC |
89 | free_remote_conf(ptr->data); |
90 | } | |
91 | ||
637c4932 | 92 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, cluster_conf_list.head) |
212380e3 | 93 | { |
330fc5c1 | 94 | rb_dlinkDelete(ptr, &cluster_conf_list); |
212380e3 AC |
95 | free_remote_conf(ptr->data); |
96 | } | |
97 | ||
637c4932 | 98 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, hubleaf_conf_list.head) |
212380e3 | 99 | { |
330fc5c1 | 100 | rb_dlinkDelete(ptr, &hubleaf_conf_list); |
212380e3 AC |
101 | free_remote_conf(ptr->data); |
102 | } | |
103 | ||
637c4932 | 104 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, oper_conf_list.head) |
212380e3 AC |
105 | { |
106 | free_oper_conf(ptr->data); | |
330fc5c1 | 107 | rb_dlinkDestroy(ptr, &oper_conf_list); |
212380e3 AC |
108 | } |
109 | ||
637c4932 | 110 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, server_conf_list.head) |
212380e3 AC |
111 | { |
112 | server_p = ptr->data; | |
113 | ||
114 | if(!server_p->servers) | |
115 | { | |
330fc5c1 | 116 | rb_dlinkDelete(ptr, &server_conf_list); |
212380e3 AC |
117 | free_server_conf(ptr->data); |
118 | } | |
119 | else | |
120 | server_p->flags |= SERVER_ILLEGAL; | |
121 | } | |
122 | } | |
123 | ||
124 | void | |
125 | clear_s_newconf_bans(void) | |
126 | { | |
127 | struct ConfItem *aconf; | |
637c4932 | 128 | rb_dlink_node *ptr, *next_ptr; |
212380e3 | 129 | |
637c4932 | 130 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, xline_conf_list.head) |
212380e3 AC |
131 | { |
132 | aconf = ptr->data; | |
133 | ||
134 | if(aconf->hold) | |
135 | continue; | |
136 | ||
137 | free_conf(aconf); | |
330fc5c1 | 138 | rb_dlinkDestroy(ptr, &xline_conf_list); |
212380e3 AC |
139 | } |
140 | ||
637c4932 | 141 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, resv_conf_list.head) |
212380e3 AC |
142 | { |
143 | aconf = ptr->data; | |
144 | ||
145 | /* temporary resv */ | |
146 | if(aconf->hold) | |
147 | continue; | |
148 | ||
149 | free_conf(aconf); | |
330fc5c1 | 150 | rb_dlinkDestroy(ptr, &resv_conf_list); |
212380e3 AC |
151 | } |
152 | ||
153 | clear_resv_hash(); | |
154 | } | |
155 | ||
156 | struct remote_conf * | |
157 | make_remote_conf(void) | |
158 | { | |
eddc2ab6 | 159 | struct remote_conf *remote_p = rb_malloc(sizeof(struct remote_conf)); |
212380e3 AC |
160 | return remote_p; |
161 | } | |
162 | ||
163 | void | |
164 | free_remote_conf(struct remote_conf *remote_p) | |
165 | { | |
166 | s_assert(remote_p != NULL); | |
167 | if(remote_p == NULL) | |
168 | return; | |
169 | ||
637c4932 VY |
170 | rb_free(remote_p->username); |
171 | rb_free(remote_p->host); | |
172 | rb_free(remote_p->server); | |
173 | rb_free(remote_p); | |
212380e3 AC |
174 | } |
175 | ||
176 | int | |
177 | find_shared_conf(const char *username, const char *host, | |
178 | const char *server, int flags) | |
179 | { | |
180 | struct remote_conf *shared_p; | |
330fc5c1 | 181 | rb_dlink_node *ptr; |
212380e3 | 182 | |
5cefa1d6 | 183 | RB_DLINK_FOREACH(ptr, shared_conf_list.head) |
212380e3 AC |
184 | { |
185 | shared_p = ptr->data; | |
186 | ||
187 | if(match(shared_p->username, username) && | |
188 | match(shared_p->host, host) && | |
189 | match(shared_p->server, server)) | |
190 | { | |
191 | if(shared_p->flags & flags) | |
192 | return YES; | |
193 | else | |
194 | return NO; | |
195 | } | |
196 | } | |
197 | ||
198 | return NO; | |
199 | } | |
200 | ||
201 | void | |
202 | propagate_generic(struct Client *source_p, const char *command, | |
203 | const char *target, int cap, const char *format, ...) | |
204 | { | |
205 | char buffer[BUFSIZE]; | |
206 | va_list args; | |
207 | ||
208 | va_start(args, format); | |
e410dcf5 | 209 | rb_vsnprintf(buffer, sizeof(buffer), format, args); |
212380e3 AC |
210 | va_end(args); |
211 | ||
212 | sendto_match_servs(source_p, target, cap, NOCAPS, | |
213 | "%s %s %s", | |
214 | command, target, buffer); | |
215 | sendto_match_servs(source_p, target, CAP_ENCAP, cap, | |
216 | "ENCAP %s %s %s", | |
217 | target, command, buffer); | |
218 | } | |
219 | ||
220 | void | |
221 | cluster_generic(struct Client *source_p, const char *command, | |
222 | int cltype, int cap, const char *format, ...) | |
223 | { | |
224 | char buffer[BUFSIZE]; | |
225 | struct remote_conf *shared_p; | |
226 | va_list args; | |
330fc5c1 | 227 | rb_dlink_node *ptr; |
212380e3 AC |
228 | |
229 | va_start(args, format); | |
e410dcf5 | 230 | rb_vsnprintf(buffer, sizeof(buffer), format, args); |
212380e3 AC |
231 | va_end(args); |
232 | ||
5cefa1d6 | 233 | RB_DLINK_FOREACH(ptr, cluster_conf_list.head) |
212380e3 AC |
234 | { |
235 | shared_p = ptr->data; | |
236 | ||
237 | if(!(shared_p->flags & cltype)) | |
238 | continue; | |
239 | ||
240 | sendto_match_servs(source_p, shared_p->server, cap, NOCAPS, | |
241 | "%s %s %s", | |
242 | command, shared_p->server, buffer); | |
243 | sendto_match_servs(source_p, shared_p->server, CAP_ENCAP, cap, | |
244 | "ENCAP %s %s %s", | |
245 | shared_p->server, command, buffer); | |
246 | } | |
247 | } | |
248 | ||
249 | struct oper_conf * | |
250 | make_oper_conf(void) | |
251 | { | |
eddc2ab6 | 252 | struct oper_conf *oper_p = rb_malloc(sizeof(struct oper_conf)); |
212380e3 AC |
253 | return oper_p; |
254 | } | |
255 | ||
256 | void | |
257 | free_oper_conf(struct oper_conf *oper_p) | |
258 | { | |
259 | s_assert(oper_p != NULL); | |
260 | if(oper_p == NULL) | |
261 | return; | |
262 | ||
637c4932 VY |
263 | rb_free(oper_p->username); |
264 | rb_free(oper_p->host); | |
265 | rb_free(oper_p->name); | |
212380e3 AC |
266 | |
267 | if(oper_p->passwd) | |
268 | { | |
269 | memset(oper_p->passwd, 0, strlen(oper_p->passwd)); | |
637c4932 | 270 | rb_free(oper_p->passwd); |
212380e3 AC |
271 | } |
272 | ||
273 | #ifdef HAVE_LIBCRYPTO | |
637c4932 | 274 | rb_free(oper_p->rsa_pubkey_file); |
212380e3 AC |
275 | |
276 | if(oper_p->rsa_pubkey) | |
277 | RSA_free(oper_p->rsa_pubkey); | |
278 | #endif | |
279 | ||
637c4932 | 280 | rb_free(oper_p); |
212380e3 AC |
281 | } |
282 | ||
283 | struct oper_conf * | |
284 | find_oper_conf(const char *username, const char *host, const char *locip, const char *name) | |
285 | { | |
286 | struct oper_conf *oper_p; | |
e7046ee5 | 287 | struct rb_sockaddr_storage ip, cip; |
212380e3 AC |
288 | char addr[HOSTLEN+1]; |
289 | int bits, cbits; | |
330fc5c1 | 290 | rb_dlink_node *ptr; |
212380e3 AC |
291 | |
292 | parse_netmask(locip, (struct sockaddr *)&cip, &cbits); | |
293 | ||
5cefa1d6 | 294 | RB_DLINK_FOREACH(ptr, oper_conf_list.head) |
212380e3 AC |
295 | { |
296 | oper_p = ptr->data; | |
297 | ||
298 | /* name/username doesnt match.. */ | |
299 | if(irccmp(oper_p->name, name) || !match(oper_p->username, username)) | |
300 | continue; | |
301 | ||
302 | strlcpy(addr, oper_p->host, sizeof(addr)); | |
303 | ||
304 | if(parse_netmask(addr, (struct sockaddr *)&ip, &bits) != HM_HOST) | |
305 | { | |
306 | if(ip.ss_family == cip.ss_family && | |
307 | comp_with_mask_sock((struct sockaddr *)&ip, (struct sockaddr *)&cip, bits)) | |
308 | return oper_p; | |
309 | } | |
310 | ||
311 | /* we have to compare against the host as well, because its | |
312 | * valid to set a spoof to an IP, which if we only compare | |
313 | * in ip form to sockhost will not necessarily match --anfl | |
314 | */ | |
315 | if(match(oper_p->host, host)) | |
316 | return oper_p; | |
317 | } | |
318 | ||
319 | return NULL; | |
320 | } | |
321 | ||
322 | struct oper_flags | |
323 | { | |
324 | int flag; | |
325 | char has; | |
326 | char hasnt; | |
327 | }; | |
328 | static struct oper_flags oper_flagtable[] = | |
329 | { | |
212380e3 AC |
330 | { OPER_KLINE, 'K', 'k' }, |
331 | { OPER_XLINE, 'X', 'x' }, | |
1ebe6ffc | 332 | { OPER_RESV, 'Q', 'q' }, |
212380e3 AC |
333 | { OPER_GLOBKILL, 'O', 'o' }, |
334 | { OPER_LOCKILL, 'C', 'c' }, | |
335 | { OPER_REMOTE, 'R', 'r' }, | |
336 | { OPER_UNKLINE, 'U', 'u' }, | |
337 | { OPER_REHASH, 'H', 'h' }, | |
338 | { OPER_DIE, 'D', 'd' }, | |
339 | { OPER_ADMIN, 'A', 'a' }, | |
340 | { OPER_NICKS, 'N', 'n' }, | |
341 | { OPER_OPERWALL, 'L', 'l' }, | |
342 | { OPER_SPY, 'S', 's' }, | |
343 | { OPER_INVIS, 'P', 'p' }, | |
344 | { OPER_REMOTEBAN, 'B', 'b' }, | |
a6f4368b | 345 | { OPER_MASSNOTICE, 'M', 'm' }, |
212380e3 AC |
346 | { 0, '\0', '\0' } |
347 | }; | |
348 | ||
349 | const char * | |
350 | get_oper_privs(int flags) | |
351 | { | |
352 | static char buf[20]; | |
353 | char *p; | |
354 | int i; | |
355 | ||
356 | p = buf; | |
357 | ||
358 | for(i = 0; oper_flagtable[i].flag; i++) | |
359 | { | |
360 | if(flags & oper_flagtable[i].flag) | |
361 | *p++ = oper_flagtable[i].has; | |
362 | else | |
363 | *p++ = oper_flagtable[i].hasnt; | |
364 | } | |
365 | ||
366 | *p = '\0'; | |
367 | ||
368 | return buf; | |
369 | } | |
370 | ||
371 | struct server_conf * | |
372 | make_server_conf(void) | |
373 | { | |
eddc2ab6 | 374 | struct server_conf *server_p = rb_malloc(sizeof(struct server_conf)); |
212380e3 AC |
375 | server_p->aftype = AF_INET; |
376 | return server_p; | |
377 | } | |
378 | ||
379 | void | |
380 | free_server_conf(struct server_conf *server_p) | |
381 | { | |
382 | s_assert(server_p != NULL); | |
383 | if(server_p == NULL) | |
384 | return; | |
385 | ||
386 | if(!EmptyString(server_p->passwd)) | |
387 | { | |
388 | memset(server_p->passwd, 0, strlen(server_p->passwd)); | |
637c4932 | 389 | rb_free(server_p->passwd); |
212380e3 AC |
390 | } |
391 | ||
392 | if(!EmptyString(server_p->spasswd)) | |
393 | { | |
394 | memset(server_p->spasswd, 0, strlen(server_p->spasswd)); | |
637c4932 | 395 | rb_free(server_p->spasswd); |
212380e3 AC |
396 | } |
397 | ||
637c4932 VY |
398 | rb_free(server_p->name); |
399 | rb_free(server_p->host); | |
400 | rb_free(server_p->class_name); | |
401 | rb_free(server_p); | |
212380e3 AC |
402 | } |
403 | ||
404 | void | |
405 | add_server_conf(struct server_conf *server_p) | |
406 | { | |
407 | if(EmptyString(server_p->class_name)) | |
408 | { | |
47a03750 | 409 | server_p->class_name = rb_strdup("default"); |
212380e3 AC |
410 | server_p->class = default_class; |
411 | return; | |
412 | } | |
413 | ||
414 | server_p->class = find_class(server_p->class_name); | |
415 | ||
416 | if(server_p->class == default_class) | |
417 | { | |
418 | conf_report_error("Warning connect::class invalid for %s", | |
419 | server_p->name); | |
420 | ||
637c4932 | 421 | rb_free(server_p->class_name); |
47a03750 | 422 | server_p->class_name = rb_strdup("default"); |
212380e3 AC |
423 | } |
424 | ||
425 | if(strchr(server_p->host, '*') || strchr(server_p->host, '?')) | |
426 | return; | |
427 | } | |
428 | ||
429 | struct server_conf * | |
430 | find_server_conf(const char *name) | |
431 | { | |
432 | struct server_conf *server_p; | |
330fc5c1 | 433 | rb_dlink_node *ptr; |
212380e3 | 434 | |
5cefa1d6 | 435 | RB_DLINK_FOREACH(ptr, server_conf_list.head) |
212380e3 AC |
436 | { |
437 | server_p = ptr->data; | |
438 | ||
439 | if(ServerConfIllegal(server_p)) | |
440 | continue; | |
441 | ||
442 | if(match(name, server_p->name)) | |
443 | return server_p; | |
444 | } | |
445 | ||
446 | return NULL; | |
447 | } | |
448 | ||
449 | void | |
450 | attach_server_conf(struct Client *client_p, struct server_conf *server_p) | |
451 | { | |
452 | /* already have an attached conf */ | |
453 | if(client_p->localClient->att_sconf) | |
454 | { | |
455 | /* short circuit this special case :) */ | |
456 | if(client_p->localClient->att_sconf == server_p) | |
457 | return; | |
458 | ||
459 | detach_server_conf(client_p); | |
460 | } | |
461 | ||
462 | CurrUsers(server_p->class)++; | |
463 | ||
464 | client_p->localClient->att_sconf = server_p; | |
465 | server_p->servers++; | |
466 | } | |
467 | ||
468 | void | |
469 | detach_server_conf(struct Client *client_p) | |
470 | { | |
471 | struct server_conf *server_p = client_p->localClient->att_sconf; | |
472 | ||
473 | if(server_p == NULL) | |
474 | return; | |
475 | ||
476 | client_p->localClient->att_sconf = NULL; | |
477 | server_p->servers--; | |
478 | CurrUsers(server_p->class)--; | |
479 | ||
480 | if(ServerConfIllegal(server_p) && !server_p->servers) | |
481 | { | |
482 | /* the class this one is using may need destroying too */ | |
483 | if(MaxUsers(server_p->class) < 0 && CurrUsers(server_p->class) <= 0) | |
484 | free_class(server_p->class); | |
485 | ||
330fc5c1 | 486 | rb_dlinkDelete(&server_p->node, &server_conf_list); |
212380e3 AC |
487 | free_server_conf(server_p); |
488 | } | |
489 | } | |
490 | ||
491 | void | |
492 | set_server_conf_autoconn(struct Client *source_p, char *name, int newval) | |
493 | { | |
494 | struct server_conf *server_p; | |
495 | ||
496 | if((server_p = find_server_conf(name)) != NULL) | |
497 | { | |
498 | if(newval) | |
499 | server_p->flags |= SERVER_AUTOCONN; | |
500 | else | |
501 | server_p->flags &= ~SERVER_AUTOCONN; | |
502 | ||
503 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
504 | "%s has changed AUTOCONN for %s to %i", | |
505 | get_oper_name(source_p), name, newval); | |
506 | } | |
507 | else | |
5366977b | 508 | sendto_one_notice(source_p, ":Can't find %s", name); |
212380e3 AC |
509 | } |
510 | ||
511 | struct ConfItem * | |
512 | find_xline(const char *gecos, int counter) | |
513 | { | |
514 | struct ConfItem *aconf; | |
330fc5c1 | 515 | rb_dlink_node *ptr; |
212380e3 | 516 | |
5cefa1d6 | 517 | RB_DLINK_FOREACH(ptr, xline_conf_list.head) |
212380e3 AC |
518 | { |
519 | aconf = ptr->data; | |
520 | ||
521 | if(match_esc(aconf->name, gecos)) | |
522 | { | |
523 | if(counter) | |
524 | aconf->port++; | |
525 | return aconf; | |
526 | } | |
527 | } | |
528 | ||
529 | return NULL; | |
530 | } | |
531 | ||
0fdb2570 JT |
532 | struct ConfItem * |
533 | find_xline_mask(const char *gecos) | |
534 | { | |
535 | struct ConfItem *aconf; | |
330fc5c1 | 536 | rb_dlink_node *ptr; |
0fdb2570 | 537 | |
5cefa1d6 | 538 | RB_DLINK_FOREACH(ptr, xline_conf_list.head) |
0fdb2570 JT |
539 | { |
540 | aconf = ptr->data; | |
541 | ||
542 | if(!irccmp(aconf->name, gecos)) | |
543 | return aconf; | |
544 | } | |
545 | ||
546 | return NULL; | |
547 | } | |
548 | ||
212380e3 AC |
549 | struct ConfItem * |
550 | find_nick_resv(const char *name) | |
551 | { | |
552 | struct ConfItem *aconf; | |
330fc5c1 | 553 | rb_dlink_node *ptr; |
212380e3 | 554 | |
5cefa1d6 | 555 | RB_DLINK_FOREACH(ptr, resv_conf_list.head) |
212380e3 AC |
556 | { |
557 | aconf = ptr->data; | |
558 | ||
559 | if(match_esc(aconf->name, name)) | |
560 | { | |
561 | aconf->port++; | |
562 | return aconf; | |
563 | } | |
564 | } | |
565 | ||
566 | return NULL; | |
567 | } | |
568 | ||
0fdb2570 JT |
569 | struct ConfItem * |
570 | find_nick_resv_mask(const char *name) | |
571 | { | |
572 | struct ConfItem *aconf; | |
330fc5c1 | 573 | rb_dlink_node *ptr; |
0fdb2570 | 574 | |
5cefa1d6 | 575 | RB_DLINK_FOREACH(ptr, resv_conf_list.head) |
0fdb2570 JT |
576 | { |
577 | aconf = ptr->data; | |
578 | ||
579 | if(!irccmp(aconf->name, name)) | |
580 | return aconf; | |
581 | } | |
582 | ||
583 | return NULL; | |
584 | } | |
585 | ||
212380e3 AC |
586 | /* clean_resv_nick() |
587 | * | |
588 | * inputs - nick | |
589 | * outputs - 1 if nick is vaild resv, 0 otherwise | |
590 | * side effects - | |
591 | */ | |
592 | int | |
593 | clean_resv_nick(const char *nick) | |
594 | { | |
595 | char tmpch; | |
596 | int as = 0; | |
597 | int q = 0; | |
598 | int ch = 0; | |
599 | ||
600 | if(*nick == '-' || IsDigit(*nick)) | |
601 | return 0; | |
602 | ||
603 | while ((tmpch = *nick++)) | |
604 | { | |
605 | if(tmpch == '?' || tmpch == '@' || tmpch == '#') | |
606 | q++; | |
607 | else if(tmpch == '*') | |
608 | as++; | |
609 | else if(IsNickChar(tmpch)) | |
610 | ch++; | |
611 | else | |
612 | return 0; | |
613 | } | |
614 | ||
615 | if(!ch && as) | |
616 | return 0; | |
617 | ||
618 | return 1; | |
619 | } | |
620 | ||
621 | /* valid_wild_card_simple() | |
622 | * | |
623 | * inputs - "thing" to test | |
624 | * outputs - 1 if enough wildcards, else 0 | |
625 | * side effects - | |
626 | */ | |
627 | int | |
628 | valid_wild_card_simple(const char *data) | |
629 | { | |
630 | const char *p; | |
631 | char tmpch; | |
632 | int nonwild = 0; | |
7d08aa89 | 633 | int wild = 0; |
212380e3 AC |
634 | |
635 | /* check the string for minimum number of nonwildcard chars */ | |
636 | p = data; | |
637 | ||
638 | while((tmpch = *p++)) | |
639 | { | |
640 | /* found an escape, p points to the char after it, so skip | |
641 | * that and move on. | |
642 | */ | |
7d08aa89 | 643 | if(tmpch == '\\' && *p) |
212380e3 AC |
644 | { |
645 | p++; | |
7d08aa89 JT |
646 | if(++nonwild >= ConfigFileEntry.min_nonwildcard_simple) |
647 | return 1; | |
212380e3 AC |
648 | } |
649 | else if(!IsMWildChar(tmpch)) | |
650 | { | |
651 | /* if we have enough nonwildchars, return */ | |
652 | if(++nonwild >= ConfigFileEntry.min_nonwildcard_simple) | |
653 | return 1; | |
654 | } | |
7d08aa89 JT |
655 | else |
656 | wild++; | |
212380e3 AC |
657 | } |
658 | ||
7d08aa89 JT |
659 | /* strings without wilds are also ok */ |
660 | return wild == 0; | |
212380e3 AC |
661 | } |
662 | ||
663 | time_t | |
664 | valid_temp_time(const char *p) | |
665 | { | |
666 | time_t result = 0; | |
667 | ||
668 | while(*p) | |
669 | { | |
670 | if(IsDigit(*p)) | |
671 | { | |
672 | result *= 10; | |
673 | result += ((*p) & 0xF); | |
674 | p++; | |
675 | } | |
676 | else | |
677 | return -1; | |
678 | } | |
679 | ||
680 | if(result > (60 * 24 * 7 * 52)) | |
681 | result = (60 * 24 * 7 * 52); | |
682 | ||
683 | return(result * 60); | |
684 | } | |
685 | ||
686 | static void | |
687 | expire_temp_rxlines(void *unused) | |
688 | { | |
689 | struct ConfItem *aconf; | |
330fc5c1 | 690 | rb_dlink_node *ptr; |
637c4932 | 691 | rb_dlink_node *next_ptr; |
212380e3 AC |
692 | int i; |
693 | ||
637c4932 | 694 | HASH_WALK_SAFE(i, R_MAX, ptr, next_ptr, resvTable) |
212380e3 AC |
695 | { |
696 | aconf = ptr->data; | |
697 | ||
e3354945 | 698 | if(aconf->hold && aconf->hold <= rb_current_time()) |
212380e3 AC |
699 | { |
700 | if(ConfigFileEntry.tkline_expire_notices) | |
701 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
702 | "Temporary RESV for [%s] expired", | |
703 | aconf->name); | |
704 | ||
705 | free_conf(aconf); | |
330fc5c1 | 706 | rb_dlinkDestroy(ptr, &resvTable[i]); |
212380e3 AC |
707 | } |
708 | } | |
709 | HASH_WALK_END | |
710 | ||
637c4932 | 711 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, resv_conf_list.head) |
212380e3 AC |
712 | { |
713 | aconf = ptr->data; | |
714 | ||
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", | |
720 | aconf->name); | |
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 | ||
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", | |
735 | aconf->name); | |
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 | ||
b37021a4 | 753 | if(irc_dictionary_find(nd_dict, name) != NULL) |
212380e3 AC |
754 | return; |
755 | ||
398b6a73 | 756 | nd = rb_bh_alloc(nd_heap); |
212380e3 AC |
757 | |
758 | 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 AC |
763 | |
764 | irc_dictionary_add(nd_dict, nd->name, nd); | |
212380e3 AC |
765 | } |
766 | ||
767 | void | |
768 | free_nd_entry(struct nd_entry *nd) | |
769 | { | |
b37021a4 AC |
770 | irc_dictionary_delete(nd_dict, nd->name); |
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 | } | |
828 |