]>
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 | { | |
330 | { OPER_GLINE, 'G', 'g' }, | |
331 | { OPER_KLINE, 'K', 'k' }, | |
332 | { OPER_XLINE, 'X', 'x' }, | |
1ebe6ffc | 333 | { OPER_RESV, 'Q', 'q' }, |
212380e3 AC |
334 | { OPER_GLOBKILL, 'O', 'o' }, |
335 | { OPER_LOCKILL, 'C', 'c' }, | |
336 | { OPER_REMOTE, 'R', 'r' }, | |
337 | { OPER_UNKLINE, 'U', 'u' }, | |
338 | { OPER_REHASH, 'H', 'h' }, | |
339 | { OPER_DIE, 'D', 'd' }, | |
340 | { OPER_ADMIN, 'A', 'a' }, | |
341 | { OPER_NICKS, 'N', 'n' }, | |
342 | { OPER_OPERWALL, 'L', 'l' }, | |
343 | { OPER_SPY, 'S', 's' }, | |
344 | { OPER_INVIS, 'P', 'p' }, | |
345 | { OPER_REMOTEBAN, 'B', 'b' }, | |
a6f4368b | 346 | { OPER_MASSNOTICE, 'M', 'm' }, |
212380e3 AC |
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 | { | |
eddc2ab6 | 375 | struct server_conf *server_p = rb_malloc(sizeof(struct server_conf)); |
212380e3 AC |
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)); | |
637c4932 | 390 | rb_free(server_p->passwd); |
212380e3 AC |
391 | } |
392 | ||
393 | if(!EmptyString(server_p->spasswd)) | |
394 | { | |
395 | memset(server_p->spasswd, 0, strlen(server_p->spasswd)); | |
637c4932 | 396 | rb_free(server_p->spasswd); |
212380e3 AC |
397 | } |
398 | ||
637c4932 VY |
399 | rb_free(server_p->name); |
400 | rb_free(server_p->host); | |
401 | rb_free(server_p->class_name); | |
402 | rb_free(server_p); | |
212380e3 AC |
403 | } |
404 | ||
405 | void | |
406 | add_server_conf(struct server_conf *server_p) | |
407 | { | |
408 | if(EmptyString(server_p->class_name)) | |
409 | { | |
47a03750 | 410 | server_p->class_name = rb_strdup("default"); |
212380e3 AC |
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 | ||
637c4932 | 422 | rb_free(server_p->class_name); |
47a03750 | 423 | server_p->class_name = rb_strdup("default"); |
212380e3 AC |
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; | |
330fc5c1 | 434 | rb_dlink_node *ptr; |
212380e3 | 435 | |
5cefa1d6 | 436 | RB_DLINK_FOREACH(ptr, server_conf_list.head) |
212380e3 AC |
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 | ||
330fc5c1 | 487 | rb_dlinkDelete(&server_p->node, &server_conf_list); |
212380e3 AC |
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 | |
5366977b | 509 | sendto_one_notice(source_p, ":Can't find %s", name); |
212380e3 AC |
510 | } |
511 | ||
512 | struct ConfItem * | |
513 | find_xline(const char *gecos, int counter) | |
514 | { | |
515 | struct ConfItem *aconf; | |
330fc5c1 | 516 | rb_dlink_node *ptr; |
212380e3 | 517 | |
5cefa1d6 | 518 | RB_DLINK_FOREACH(ptr, xline_conf_list.head) |
212380e3 AC |
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 | ||
0fdb2570 JT |
533 | struct ConfItem * |
534 | find_xline_mask(const char *gecos) | |
535 | { | |
536 | struct ConfItem *aconf; | |
330fc5c1 | 537 | rb_dlink_node *ptr; |
0fdb2570 | 538 | |
5cefa1d6 | 539 | RB_DLINK_FOREACH(ptr, xline_conf_list.head) |
0fdb2570 JT |
540 | { |
541 | aconf = ptr->data; | |
542 | ||
543 | if(!irccmp(aconf->name, gecos)) | |
544 | return aconf; | |
545 | } | |
546 | ||
547 | return NULL; | |
548 | } | |
549 | ||
212380e3 AC |
550 | struct ConfItem * |
551 | find_nick_resv(const char *name) | |
552 | { | |
553 | struct ConfItem *aconf; | |
330fc5c1 | 554 | rb_dlink_node *ptr; |
212380e3 | 555 | |
5cefa1d6 | 556 | RB_DLINK_FOREACH(ptr, resv_conf_list.head) |
212380e3 AC |
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 | ||
0fdb2570 JT |
570 | struct ConfItem * |
571 | find_nick_resv_mask(const char *name) | |
572 | { | |
573 | struct ConfItem *aconf; | |
330fc5c1 | 574 | rb_dlink_node *ptr; |
0fdb2570 | 575 | |
5cefa1d6 | 576 | RB_DLINK_FOREACH(ptr, resv_conf_list.head) |
0fdb2570 JT |
577 | { |
578 | aconf = ptr->data; | |
579 | ||
580 | if(!irccmp(aconf->name, name)) | |
581 | return aconf; | |
582 | } | |
583 | ||
584 | return NULL; | |
585 | } | |
586 | ||
212380e3 AC |
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; | |
7d08aa89 | 634 | int wild = 0; |
212380e3 AC |
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 | */ | |
7d08aa89 | 644 | if(tmpch == '\\' && *p) |
212380e3 AC |
645 | { |
646 | p++; | |
7d08aa89 JT |
647 | if(++nonwild >= ConfigFileEntry.min_nonwildcard_simple) |
648 | return 1; | |
212380e3 AC |
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 | } | |
7d08aa89 JT |
656 | else |
657 | wild++; | |
212380e3 AC |
658 | } |
659 | ||
7d08aa89 JT |
660 | /* strings without wilds are also ok */ |
661 | return wild == 0; | |
212380e3 AC |
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; | |
330fc5c1 | 691 | rb_dlink_node *ptr; |
637c4932 | 692 | rb_dlink_node *next_ptr; |
212380e3 AC |
693 | int i; |
694 | ||
637c4932 | 695 | HASH_WALK_SAFE(i, R_MAX, ptr, next_ptr, resvTable) |
212380e3 AC |
696 | { |
697 | aconf = ptr->data; | |
698 | ||
e3354945 | 699 | if(aconf->hold && aconf->hold <= rb_current_time()) |
212380e3 AC |
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); | |
330fc5c1 | 707 | rb_dlinkDestroy(ptr, &resvTable[i]); |
212380e3 AC |
708 | } |
709 | } | |
710 | HASH_WALK_END | |
711 | ||
637c4932 | 712 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, resv_conf_list.head) |
212380e3 AC |
713 | { |
714 | aconf = ptr->data; | |
715 | ||
e3354945 | 716 | if(aconf->hold && aconf->hold <= rb_current_time()) |
212380e3 AC |
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); | |
330fc5c1 | 723 | rb_dlinkDestroy(ptr, &resv_conf_list); |
212380e3 AC |
724 | } |
725 | } | |
726 | ||
637c4932 | 727 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, xline_conf_list.head) |
212380e3 AC |
728 | { |
729 | aconf = ptr->data; | |
730 | ||
e3354945 | 731 | if(aconf->hold && aconf->hold <= rb_current_time()) |
212380e3 AC |
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); | |
330fc5c1 | 738 | rb_dlinkDestroy(ptr, &xline_conf_list); |
212380e3 AC |
739 | } |
740 | } | |
741 | } | |
742 | ||
743 | unsigned long | |
744 | get_nd_count(void) | |
745 | { | |
330fc5c1 | 746 | return(rb_dlink_list_length(&nd_list)); |
212380e3 AC |
747 | } |
748 | ||
212380e3 AC |
749 | void |
750 | add_nd_entry(const char *name) | |
751 | { | |
752 | struct nd_entry *nd; | |
753 | ||
b37021a4 | 754 | if(irc_dictionary_find(nd_dict, name) != NULL) |
212380e3 AC |
755 | return; |
756 | ||
398b6a73 | 757 | nd = rb_bh_alloc(nd_heap); |
212380e3 AC |
758 | |
759 | strlcpy(nd->name, name, sizeof(nd->name)); | |
e3354945 | 760 | nd->expire = rb_current_time() + ConfigFileEntry.nick_delay; |
212380e3 AC |
761 | |
762 | /* this list is ordered */ | |
330fc5c1 | 763 | rb_dlinkAddTail(nd, &nd->lnode, &nd_list); |
b37021a4 AC |
764 | |
765 | irc_dictionary_add(nd_dict, nd->name, nd); | |
212380e3 AC |
766 | } |
767 | ||
768 | void | |
769 | free_nd_entry(struct nd_entry *nd) | |
770 | { | |
b37021a4 AC |
771 | irc_dictionary_delete(nd_dict, nd->name); |
772 | ||
330fc5c1 | 773 | rb_dlinkDelete(&nd->lnode, &nd_list); |
398b6a73 | 774 | rb_bh_free(nd_heap, nd); |
212380e3 AC |
775 | } |
776 | ||
777 | void | |
778 | expire_nd_entries(void *unused) | |
779 | { | |
780 | struct nd_entry *nd; | |
330fc5c1 | 781 | rb_dlink_node *ptr; |
637c4932 | 782 | rb_dlink_node *next_ptr; |
212380e3 | 783 | |
637c4932 | 784 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, nd_list.head) |
212380e3 AC |
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 | */ | |
e3354945 | 791 | if(nd->expire > rb_current_time()) |
212380e3 AC |
792 | return; |
793 | ||
794 | free_nd_entry(nd); | |
795 | } | |
796 | } | |
797 | ||
798 | void | |
799 | add_tgchange(const char *host) | |
800 | { | |
801 | tgchange *target; | |
e410dcf5 | 802 | rb_patricia_node_t *pnode; |
212380e3 AC |
803 | |
804 | if(find_tgchange(host)) | |
805 | return; | |
806 | ||
eddc2ab6 | 807 | target = rb_malloc(sizeof(tgchange)); |
212380e3 AC |
808 | pnode = make_and_lookup(tgchange_tree, host); |
809 | ||
810 | pnode->data = target; | |
811 | target->pnode = pnode; | |
812 | ||
47a03750 | 813 | target->ip = rb_strdup(host); |
e3354945 | 814 | target->expiry = rb_current_time() + (60*60*12); |
212380e3 | 815 | |
330fc5c1 | 816 | rb_dlinkAdd(target, &target->node, &tgchange_list); |
212380e3 AC |
817 | } |
818 | ||
819 | tgchange * | |
820 | find_tgchange(const char *host) | |
821 | { | |
e410dcf5 | 822 | rb_patricia_node_t *pnode; |
212380e3 | 823 | |
e410dcf5 | 824 | if((pnode = rb_match_exact_string(tgchange_tree, host))) |
212380e3 AC |
825 | return pnode->data; |
826 | ||
827 | return NULL; | |
828 | } | |
829 |