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