]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * charybdis: an advanced internet relay chat daemon (ircd). | |
3 | * hostmask.c: Code to efficiently find IP & hostmask based configs. | |
4 | * | |
5 | * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center | |
6 | * Copyright (C) 1996-2002 Hybrid Development Team | |
7 | * Copyright (C) 2002-2005 ircd-ratbox development team | |
8 | * Copyright (C) 2005-2008 charybdis development team | |
9 | * | |
10 | * This program is free software; you can redistribute it and/or modify | |
11 | * it under the terms of the GNU General Public License as published by | |
12 | * the Free Software Foundation; either version 2 of the License, or | |
13 | * (at your option) any later version. | |
14 | * | |
15 | * This program is distributed in the hope that it will be useful, | |
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | * GNU General Public License for more details. | |
19 | * | |
20 | * You should have received a copy of the GNU General Public License | |
21 | * along with this program; if not, write to the Free Software | |
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
23 | * USA | |
24 | * | |
25 | */ | |
26 | ||
27 | #include "stdinc.h" | |
28 | #include "ircd_defs.h" | |
29 | #include "s_conf.h" | |
30 | #include "hostmask.h" | |
31 | #include "numeric.h" | |
32 | #include "send.h" | |
33 | #include "match.h" | |
34 | ||
35 | #ifdef RB_IPV6 | |
36 | static unsigned long hash_ipv6(struct sockaddr *, int); | |
37 | #endif | |
38 | static unsigned long hash_ipv4(struct sockaddr *, int); | |
39 | ||
40 | ||
41 | /* int parse_netmask(const char *, struct rb_sockaddr_storage *, int *); | |
42 | * Input: A hostmask, or an IPV4/6 address. | |
43 | * Output: An integer describing whether it is an IPV4, IPV6 address or a | |
44 | * hostmask, an address(if it is an IP mask), | |
45 | * a bitlength(if it is IP mask). | |
46 | * Side effects: None | |
47 | */ | |
48 | int | |
49 | parse_netmask(const char *text, struct sockaddr *naddr, int *nb) | |
50 | { | |
51 | char *ip = LOCAL_COPY(text); | |
52 | char *ptr; | |
53 | struct rb_sockaddr_storage *addr, xaddr; | |
54 | int *b, xb; | |
55 | if(nb == NULL) | |
56 | b = &xb; | |
57 | else | |
58 | b = nb; | |
59 | ||
60 | if(naddr == NULL) | |
61 | addr = (struct rb_sockaddr_storage *)&xaddr; | |
62 | else | |
63 | addr = (struct rb_sockaddr_storage *)naddr; | |
64 | ||
65 | if(strpbrk(ip, "*?") != NULL) | |
66 | { | |
67 | return HM_HOST; | |
68 | } | |
69 | #ifdef RB_IPV6 | |
70 | if(strchr(ip, ':')) | |
71 | { | |
72 | if((ptr = strchr(ip, '/'))) | |
73 | { | |
74 | *ptr = '\0'; | |
75 | ptr++; | |
76 | *b = atoi(ptr); | |
77 | if(*b > 128) | |
78 | *b = 128; | |
79 | } else | |
80 | *b = 128; | |
81 | if(rb_inet_pton_sock(ip, (struct sockaddr *)addr) > 0) | |
82 | return HM_IPV6; | |
83 | else | |
84 | return HM_HOST; | |
85 | } else | |
86 | #endif | |
87 | if(strchr(text, '.')) | |
88 | { | |
89 | if((ptr = strchr(ip, '/'))) | |
90 | { | |
91 | *ptr = '\0'; | |
92 | ptr++; | |
93 | *b = atoi(ptr); | |
94 | if(*b > 32) | |
95 | *b = 32; | |
96 | } else | |
97 | *b = 32; | |
98 | if(rb_inet_pton_sock(ip, (struct sockaddr *)addr) > 0) | |
99 | return HM_IPV4; | |
100 | else | |
101 | return HM_HOST; | |
102 | } | |
103 | return HM_HOST; | |
104 | } | |
105 | ||
106 | /* Hashtable stuff...now external as its used in m_stats.c */ | |
107 | struct AddressRec *atable[ATABLE_SIZE]; | |
108 | ||
109 | void | |
110 | init_host_hash(void) | |
111 | { | |
112 | memset(&atable, 0, sizeof(atable)); | |
113 | } | |
114 | ||
115 | /* unsigned long hash_ipv4(struct rb_sockaddr_storage*) | |
116 | * Input: An IP address. | |
117 | * Output: A hash value of the IP address. | |
118 | * Side effects: None | |
119 | */ | |
120 | static unsigned long | |
121 | hash_ipv4(struct sockaddr *saddr, int bits) | |
122 | { | |
123 | struct sockaddr_in *addr = (struct sockaddr_in *) saddr; | |
124 | ||
125 | if(bits != 0) | |
126 | { | |
127 | unsigned long av = ntohl(addr->sin_addr.s_addr) & ~((1 << (32 - bits)) - 1); | |
128 | return (av ^ (av >> 12) ^ (av >> 24)) & (ATABLE_SIZE - 1); | |
129 | } | |
130 | ||
131 | return 0; | |
132 | } | |
133 | ||
134 | /* unsigned long hash_ipv6(struct rb_sockaddr_storage*) | |
135 | * Input: An IP address. | |
136 | * Output: A hash value of the IP address. | |
137 | * Side effects: None | |
138 | */ | |
139 | #ifdef RB_IPV6 | |
140 | static unsigned long | |
141 | hash_ipv6(struct sockaddr *saddr, int bits) | |
142 | { | |
143 | struct sockaddr_in6 *addr = (struct sockaddr_in6 *) saddr; | |
144 | unsigned long v = 0, n; | |
145 | for (n = 0; n < 16; n++) | |
146 | { | |
147 | if(bits >= 8) | |
148 | { | |
149 | v ^= addr->sin6_addr.s6_addr[n]; | |
150 | bits -= 8; | |
151 | } | |
152 | else if(bits) | |
153 | { | |
154 | v ^= addr->sin6_addr.s6_addr[n] & ~((1 << (8 - bits)) - 1); | |
155 | return v & (ATABLE_SIZE - 1); | |
156 | } | |
157 | else | |
158 | return v & (ATABLE_SIZE - 1); | |
159 | } | |
160 | return v & (ATABLE_SIZE - 1); | |
161 | } | |
162 | #endif | |
163 | ||
164 | /* int hash_text(const char *start) | |
165 | * Input: The start of the text to hash. | |
166 | * Output: The hash of the string between 1 and (TH_MAX-1) | |
167 | * Side-effects: None. | |
168 | */ | |
169 | static int | |
170 | hash_text(const char *start) | |
171 | { | |
172 | const char *p = start; | |
173 | unsigned long h = 0; | |
174 | ||
175 | while(*p) | |
176 | { | |
177 | h = (h << 4) - (h + (unsigned char) ToLower(*p++)); | |
178 | } | |
179 | ||
180 | return (h & (ATABLE_SIZE - 1)); | |
181 | } | |
182 | ||
183 | /* unsigned long get_hash_mask(const char *) | |
184 | * Input: The text to hash. | |
185 | * Output: The hash of the string right of the first '.' past the last | |
186 | * wildcard in the string. | |
187 | * Side-effects: None. | |
188 | */ | |
189 | static unsigned long | |
190 | get_mask_hash(const char *text) | |
191 | { | |
192 | const char *hp = "", *p; | |
193 | ||
194 | for (p = text + strlen(text) - 1; p >= text; p--) | |
195 | if(*p == '*' || *p == '?') | |
196 | return hash_text(hp); | |
197 | else if(*p == '.') | |
198 | hp = p + 1; | |
199 | return hash_text(text); | |
200 | } | |
201 | ||
202 | /* struct ConfItem* find_conf_by_address(const char*, struct rb_sockaddr_storage*, | |
203 | * int type, int fam, const char *username) | |
204 | * Input: The hostname, the address, the type of mask to find, the address | |
205 | * family, the username. | |
206 | * Output: The matching value with the highest precedence. | |
207 | * Side-effects: None | |
208 | * Note: Setting bit 0 of the type means that the username is ignored. | |
209 | */ | |
210 | struct ConfItem * | |
211 | find_conf_by_address(const char *name, const char *sockhost, | |
212 | const char *orighost, | |
213 | struct sockaddr *addr, int type, int fam, | |
214 | const char *username, const char *auth_user) | |
215 | { | |
216 | unsigned long hprecv = 0; | |
217 | struct ConfItem *hprec = NULL; | |
218 | struct AddressRec *arec; | |
219 | int b; | |
220 | ||
221 | if(username == NULL) | |
222 | username = ""; | |
223 | ||
224 | if(addr) | |
225 | { | |
226 | /* Check for IPV6 matches... */ | |
227 | #ifdef RB_IPV6 | |
228 | if(fam == AF_INET6) | |
229 | { | |
230 | ||
231 | for (b = 128; b >= 0; b -= 16) | |
232 | { | |
233 | for (arec = atable[hash_ipv6(addr, b)]; arec; arec = arec->next) | |
234 | if(arec->type == (type & ~0x1) && | |
235 | arec->masktype == HM_IPV6 && | |
236 | comp_with_mask_sock(addr, (struct sockaddr *)&arec->Mask.ipa.addr, | |
237 | arec->Mask.ipa.bits) && | |
238 | (type & 0x1 || match(arec-> username, username)) && | |
239 | (type != CONF_CLIENT || !arec->auth_user || | |
240 | (auth_user && match(arec->auth_user, auth_user))) && | |
241 | arec->precedence > hprecv) | |
242 | { | |
243 | hprecv = arec->precedence; | |
244 | hprec = arec->aconf; | |
245 | } | |
246 | } | |
247 | } | |
248 | else | |
249 | #endif | |
250 | if(fam == AF_INET) | |
251 | { | |
252 | for (b = 32; b >= 0; b -= 8) | |
253 | { | |
254 | for (arec = atable[hash_ipv4(addr, b)]; arec; arec = arec->next) | |
255 | if(arec->type == (type & ~0x1) && | |
256 | arec->masktype == HM_IPV4 && | |
257 | comp_with_mask_sock(addr, (struct sockaddr *)&arec->Mask.ipa.addr, | |
258 | arec->Mask.ipa.bits) && | |
259 | (type & 0x1 || match(arec->username, username)) && | |
260 | (type != CONF_CLIENT || !arec->auth_user || | |
261 | (auth_user && match(arec->auth_user, auth_user))) && | |
262 | arec->precedence > hprecv) | |
263 | { | |
264 | hprecv = arec->precedence; | |
265 | hprec = arec->aconf; | |
266 | } | |
267 | } | |
268 | } | |
269 | } | |
270 | ||
271 | if(orighost != NULL) | |
272 | { | |
273 | const char *p; | |
274 | ||
275 | for (p = orighost; p != NULL;) | |
276 | { | |
277 | for (arec = atable[hash_text(p)]; arec; arec = arec->next) | |
278 | ||
279 | if((arec->type == (type & ~0x1)) && | |
280 | (arec->masktype == HM_HOST) && | |
281 | arec->precedence > hprecv && | |
282 | match(arec->Mask.hostname, orighost) && | |
283 | (type != CONF_CLIENT || !arec->auth_user || | |
284 | (auth_user && match(arec->auth_user, auth_user))) && | |
285 | (type & 0x1 || match(arec->username, username))) | |
286 | { | |
287 | hprecv = arec->precedence; | |
288 | hprec = arec->aconf; | |
289 | } | |
290 | p = strchr(p, '.'); | |
291 | if(p != NULL) | |
292 | p++; | |
293 | else | |
294 | break; | |
295 | } | |
296 | for (arec = atable[0]; arec; arec = arec->next) | |
297 | { | |
298 | if(arec->type == (type & ~0x1) && | |
299 | arec->masktype == HM_HOST && | |
300 | arec->precedence > hprecv && | |
301 | (match(arec->Mask.hostname, orighost) || | |
302 | (sockhost && match(arec->Mask.hostname, sockhost))) && | |
303 | (type != CONF_CLIENT || !arec->auth_user || | |
304 | (auth_user && match(arec->auth_user, auth_user))) && | |
305 | (type & 0x1 || match(arec->username, username))) | |
306 | { | |
307 | hprecv = arec->precedence; | |
308 | hprec = arec->aconf; | |
309 | } | |
310 | } | |
311 | } | |
312 | ||
313 | if(name != NULL) | |
314 | { | |
315 | const char *p; | |
316 | /* And yes - we have to check p after strchr and p after increment for | |
317 | * NULL -kre */ | |
318 | for (p = name; p != NULL;) | |
319 | { | |
320 | for (arec = atable[hash_text(p)]; arec; arec = arec->next) | |
321 | if((arec->type == (type & ~0x1)) && | |
322 | (arec->masktype == HM_HOST) && | |
323 | arec->precedence > hprecv && | |
324 | match(arec->Mask.hostname, name) && | |
325 | (type != CONF_CLIENT || !arec->auth_user || | |
326 | (auth_user && match(arec->auth_user, auth_user))) && | |
327 | (type & 0x1 || match(arec->username, username))) | |
328 | { | |
329 | hprecv = arec->precedence; | |
330 | hprec = arec->aconf; | |
331 | } | |
332 | p = strchr(p, '.'); | |
333 | if(p != NULL) | |
334 | p++; | |
335 | else | |
336 | break; | |
337 | } | |
338 | for (arec = atable[0]; arec; arec = arec->next) | |
339 | { | |
340 | if(arec->type == (type & ~0x1) && | |
341 | arec->masktype == HM_HOST && | |
342 | arec->precedence > hprecv && | |
343 | (match(arec->Mask.hostname, name) || | |
344 | (sockhost && match(arec->Mask.hostname, sockhost))) && | |
345 | (type != CONF_CLIENT || !arec->auth_user || | |
346 | (auth_user && match(arec->auth_user, auth_user))) && | |
347 | (type & 0x1 || match(arec->username, username))) | |
348 | { | |
349 | hprecv = arec->precedence; | |
350 | hprec = arec->aconf; | |
351 | } | |
352 | } | |
353 | } | |
354 | return hprec; | |
355 | } | |
356 | ||
357 | /* struct ConfItem* find_address_conf(const char*, const char*, | |
358 | * struct rb_sockaddr_storage*, int); | |
359 | * Input: The hostname, username, address, address family. | |
360 | * Output: The applicable ConfItem. | |
361 | * Side-effects: None | |
362 | */ | |
363 | struct ConfItem * | |
364 | find_address_conf(const char *host, const char *sockhost, const char *user, | |
365 | const char *notildeuser, struct sockaddr *ip, int aftype, char *auth_user) | |
366 | { | |
367 | struct ConfItem *iconf, *kconf; | |
368 | const char *vuser; | |
369 | ||
370 | /* Find the best I-line... If none, return NULL -A1kmm */ | |
371 | if(!(iconf = find_conf_by_address(host, sockhost, NULL, ip, CONF_CLIENT, aftype, user, auth_user))) | |
372 | return NULL; | |
373 | /* Find what their visible username will be. | |
374 | * Note that the username without tilde may contain one char more. | |
375 | * -- jilles */ | |
376 | vuser = IsNoTilde(iconf) ? notildeuser : user; | |
377 | ||
378 | /* If they are exempt from K-lines, return the best I-line. -A1kmm */ | |
379 | if(IsConfExemptKline(iconf)) | |
380 | return iconf; | |
381 | ||
382 | /* Find the best K-line... -A1kmm */ | |
383 | kconf = find_conf_by_address(host, sockhost, NULL, ip, CONF_KILL, aftype, user, NULL); | |
384 | ||
385 | /* If they are K-lined, return the K-line */ | |
386 | if(kconf) | |
387 | return kconf; | |
388 | ||
389 | /* if theres a spoof, check it against klines.. */ | |
390 | if(IsConfDoSpoofIp(iconf)) | |
391 | { | |
392 | char *p = strchr(iconf->info.name, '@'); | |
393 | ||
394 | /* note, we dont need to pass sockhost here, as its | |
395 | * guaranteed to not match by whats above.. --anfl | |
396 | */ | |
397 | if(p) | |
398 | { | |
399 | *p = '\0'; | |
400 | kconf = find_conf_by_address(p+1, NULL, NULL, ip, CONF_KILL, aftype, iconf->info.name, NULL); | |
401 | *p = '@'; | |
402 | } | |
403 | else | |
404 | kconf = find_conf_by_address(iconf->info.name, NULL, NULL, ip, CONF_KILL, aftype, vuser, NULL); | |
405 | ||
406 | if(kconf) | |
407 | return kconf; | |
408 | } | |
409 | ||
410 | /* if no_tilde, check the username without tilde against klines too | |
411 | * -- jilles */ | |
412 | if(user != vuser) | |
413 | { | |
414 | kconf = find_conf_by_address(host, sockhost, NULL, ip, CONF_KILL, aftype, vuser, NULL); | |
415 | if(kconf) | |
416 | return kconf; | |
417 | } | |
418 | ||
419 | return iconf; | |
420 | } | |
421 | ||
422 | /* struct ConfItem* find_dline(struct rb_sockaddr_storage*, int) | |
423 | * Input: An address, an address family. | |
424 | * Output: The best matching D-line or exempt line. | |
425 | * Side effects: None. | |
426 | */ | |
427 | struct ConfItem * | |
428 | find_dline(struct sockaddr *addr, int aftype) | |
429 | { | |
430 | struct ConfItem *eline; | |
431 | eline = find_conf_by_address(NULL, NULL, NULL, addr, CONF_EXEMPTDLINE | 1, aftype, NULL, NULL); | |
432 | if(eline) | |
433 | return eline; | |
434 | return find_conf_by_address(NULL, NULL, NULL, addr, CONF_DLINE | 1, aftype, NULL, NULL); | |
435 | } | |
436 | ||
437 | /* void find_exact_conf_by_address(const char*, int, const char *) | |
438 | * Input: | |
439 | * Output: ConfItem if found | |
440 | * Side-effects: None | |
441 | */ | |
442 | struct ConfItem * | |
443 | find_exact_conf_by_address(const char *address, int type, const char *username) | |
444 | { | |
445 | int masktype, bits; | |
446 | unsigned long hv; | |
447 | struct AddressRec *arec; | |
448 | struct rb_sockaddr_storage addr; | |
449 | ||
450 | if(address == NULL) | |
451 | address = "/NOMATCH!/"; | |
452 | masktype = parse_netmask(address, (struct sockaddr *)&addr, &bits); | |
453 | #ifdef RB_IPV6 | |
454 | if(masktype == HM_IPV6) | |
455 | { | |
456 | /* We have to do this, since we do not re-hash for every bit -A1kmm. */ | |
457 | hv = hash_ipv6((struct sockaddr *)&addr, bits - bits % 16); | |
458 | } | |
459 | else | |
460 | #endif | |
461 | if(masktype == HM_IPV4) | |
462 | { | |
463 | /* We have to do this, since we do not re-hash for every bit -A1kmm. */ | |
464 | hv = hash_ipv4((struct sockaddr *)&addr, bits - bits % 8); | |
465 | } | |
466 | else | |
467 | { | |
468 | hv = get_mask_hash(address); | |
469 | } | |
470 | for (arec = atable[hv]; arec; arec = arec->next) | |
471 | { | |
472 | if (arec->type == type && | |
473 | arec->masktype == masktype && | |
474 | (arec->username == NULL || username == NULL ? arec->username == username : !irccmp(arec->username, username))) | |
475 | { | |
476 | if (masktype == HM_HOST) | |
477 | { | |
478 | if (!irccmp(arec->Mask.hostname, address)) | |
479 | return arec->aconf; | |
480 | } | |
481 | else | |
482 | { | |
483 | if (arec->Mask.ipa.bits == bits && | |
484 | comp_with_mask_sock((struct sockaddr *)&arec->Mask.ipa.addr, (struct sockaddr *)&addr, bits)) | |
485 | return arec->aconf; | |
486 | } | |
487 | } | |
488 | } | |
489 | return NULL; | |
490 | } | |
491 | ||
492 | /* void add_conf_by_address(const char*, int, const char *, | |
493 | * struct ConfItem *aconf) | |
494 | * Input: | |
495 | * Output: None | |
496 | * Side-effects: Adds this entry to the hash table. | |
497 | */ | |
498 | void | |
499 | add_conf_by_address(const char *address, int type, const char *username, const char *auth_user, struct ConfItem *aconf) | |
500 | { | |
501 | static unsigned long prec_value = 0xFFFFFFFF; | |
502 | int masktype, bits; | |
503 | unsigned long hv; | |
504 | struct AddressRec *arec; | |
505 | ||
506 | if(address == NULL) | |
507 | address = "/NOMATCH!/"; | |
508 | arec = rb_malloc(sizeof(struct AddressRec)); | |
509 | masktype = parse_netmask(address, (struct sockaddr *)&arec->Mask.ipa.addr, &bits); | |
510 | arec->Mask.ipa.bits = bits; | |
511 | arec->masktype = masktype; | |
512 | #ifdef RB_IPV6 | |
513 | if(masktype == HM_IPV6) | |
514 | { | |
515 | /* We have to do this, since we do not re-hash for every bit -A1kmm. */ | |
516 | bits -= bits % 16; | |
517 | arec->next = atable[(hv = hash_ipv6((struct sockaddr *)&arec->Mask.ipa.addr, bits))]; | |
518 | atable[hv] = arec; | |
519 | } | |
520 | else | |
521 | #endif | |
522 | if(masktype == HM_IPV4) | |
523 | { | |
524 | /* We have to do this, since we do not re-hash for every bit -A1kmm. */ | |
525 | bits -= bits % 8; | |
526 | arec->next = atable[(hv = hash_ipv4((struct sockaddr *)&arec->Mask.ipa.addr, bits))]; | |
527 | atable[hv] = arec; | |
528 | } | |
529 | else | |
530 | { | |
531 | arec->Mask.hostname = address; | |
532 | arec->next = atable[(hv = get_mask_hash(address))]; | |
533 | atable[hv] = arec; | |
534 | } | |
535 | arec->username = username; | |
536 | arec->auth_user = auth_user; | |
537 | arec->aconf = aconf; | |
538 | arec->precedence = prec_value--; | |
539 | arec->type = type; | |
540 | } | |
541 | ||
542 | /* void delete_one_address(const char*, struct ConfItem*) | |
543 | * Input: An address string, the associated ConfItem. | |
544 | * Output: None | |
545 | * Side effects: Deletes an address record. Frees the ConfItem if there | |
546 | * is nothing referencing it, sets it as illegal otherwise. | |
547 | */ | |
548 | void | |
549 | delete_one_address_conf(const char *address, struct ConfItem *aconf) | |
550 | { | |
551 | int masktype, bits; | |
552 | unsigned long hv; | |
553 | struct AddressRec *arec, *arecl = NULL; | |
554 | struct rb_sockaddr_storage addr; | |
555 | masktype = parse_netmask(address, (struct sockaddr *)&addr, &bits); | |
556 | #ifdef RB_IPV6 | |
557 | if(masktype == HM_IPV6) | |
558 | { | |
559 | /* We have to do this, since we do not re-hash for every bit -A1kmm. */ | |
560 | bits -= bits % 16; | |
561 | hv = hash_ipv6((struct sockaddr *)&addr, bits); | |
562 | } | |
563 | else | |
564 | #endif | |
565 | if(masktype == HM_IPV4) | |
566 | { | |
567 | /* We have to do this, since we do not re-hash for every bit -A1kmm. */ | |
568 | bits -= bits % 8; | |
569 | hv = hash_ipv4((struct sockaddr *)&addr, bits); | |
570 | } | |
571 | else | |
572 | hv = get_mask_hash(address); | |
573 | for (arec = atable[hv]; arec; arec = arec->next) | |
574 | { | |
575 | if(arec->aconf == aconf) | |
576 | { | |
577 | if(arecl) | |
578 | arecl->next = arec->next; | |
579 | else | |
580 | atable[hv] = arec->next; | |
581 | aconf->status |= CONF_ILLEGAL; | |
582 | if(!aconf->clients) | |
583 | free_conf(aconf); | |
584 | rb_free(arec); | |
585 | return; | |
586 | } | |
587 | arecl = arec; | |
588 | } | |
589 | } | |
590 | ||
591 | /* void clear_out_address_conf(void) | |
592 | * Input: None | |
593 | * Output: None | |
594 | * Side effects: Clears out all address records in the hash table, | |
595 | * frees them, and frees the ConfItems if nothing references | |
596 | * them, otherwise sets them as illegal. | |
597 | */ | |
598 | void | |
599 | clear_out_address_conf(void) | |
600 | { | |
601 | int i; | |
602 | struct AddressRec **store_next; | |
603 | struct AddressRec *arec, *arecn; | |
604 | ||
605 | for (i = 0; i < ATABLE_SIZE; i++) | |
606 | { | |
607 | store_next = &atable[i]; | |
608 | for (arec = atable[i]; arec; arec = arecn) | |
609 | { | |
610 | arecn = arec->next; | |
611 | /* We keep the temporary K-lines and destroy the | |
612 | * permanent ones, just to be confusing :) -A1kmm */ | |
613 | if(arec->aconf->flags & CONF_FLAGS_TEMPORARY || | |
614 | (arec->type != CONF_CLIENT && arec->type != CONF_EXEMPTDLINE)) | |
615 | { | |
616 | *store_next = arec; | |
617 | store_next = &arec->next; | |
618 | } | |
619 | else | |
620 | { | |
621 | arec->aconf->status |= CONF_ILLEGAL; | |
622 | if(!arec->aconf->clients) | |
623 | free_conf(arec->aconf); | |
624 | rb_free(arec); | |
625 | } | |
626 | } | |
627 | *store_next = NULL; | |
628 | } | |
629 | } | |
630 | ||
631 | void | |
632 | clear_out_address_conf_bans(void) | |
633 | { | |
634 | int i; | |
635 | struct AddressRec **store_next; | |
636 | struct AddressRec *arec, *arecn; | |
637 | ||
638 | for (i = 0; i < ATABLE_SIZE; i++) | |
639 | { | |
640 | store_next = &atable[i]; | |
641 | for (arec = atable[i]; arec; arec = arecn) | |
642 | { | |
643 | arecn = arec->next; | |
644 | /* We keep the temporary K-lines and destroy the | |
645 | * permanent ones, just to be confusing :) -A1kmm */ | |
646 | if(arec->aconf->flags & CONF_FLAGS_TEMPORARY || | |
647 | (arec->type == CONF_CLIENT || arec->type == CONF_EXEMPTDLINE)) | |
648 | { | |
649 | *store_next = arec; | |
650 | store_next = &arec->next; | |
651 | } | |
652 | else | |
653 | { | |
654 | arec->aconf->status |= CONF_ILLEGAL; | |
655 | if(!arec->aconf->clients) | |
656 | free_conf(arec->aconf); | |
657 | rb_free(arec); | |
658 | } | |
659 | } | |
660 | *store_next = NULL; | |
661 | } | |
662 | } | |
663 | ||
664 | ||
665 | /* | |
666 | * show_iline_prefix() | |
667 | * | |
668 | * inputs - pointer to struct Client requesting output | |
669 | * - pointer to struct ConfItem | |
670 | * - name to which iline prefix will be prefixed to | |
671 | * output - pointer to static string with prefixes listed in ascii form | |
672 | * side effects - NONE | |
673 | */ | |
674 | char * | |
675 | show_iline_prefix(struct Client *sptr, struct ConfItem *aconf, char *name) | |
676 | { | |
677 | static char prefix_of_host[USERLEN + 15]; | |
678 | char *prefix_ptr; | |
679 | ||
680 | prefix_ptr = prefix_of_host; | |
681 | if(IsNoTilde(aconf)) | |
682 | *prefix_ptr++ = '-'; | |
683 | if(IsNeedIdentd(aconf)) | |
684 | *prefix_ptr++ = '+'; | |
685 | if(IsConfDoSpoofIp(aconf)) | |
686 | *prefix_ptr++ = '='; | |
687 | if(IsOper(sptr) && IsConfExemptFlood(aconf)) | |
688 | *prefix_ptr++ = '|'; | |
689 | if(IsOper(sptr) && IsConfExemptDNSBL(aconf) && !IsConfExemptKline(aconf)) | |
690 | *prefix_ptr++ = '$'; | |
691 | if(IsOper(sptr) && IsConfExemptKline(aconf)) | |
692 | *prefix_ptr++ = '^'; | |
693 | if(IsOper(sptr) && IsConfExemptLimits(aconf)) | |
694 | *prefix_ptr++ = '>'; | |
695 | *prefix_ptr = '\0'; | |
696 | strncpy(prefix_ptr, name, USERLEN); | |
697 | return (prefix_of_host); | |
698 | } | |
699 | ||
700 | /* report_auth() | |
701 | * | |
702 | * Inputs: pointer to client to report to | |
703 | * Output: None | |
704 | * Side effects: Reports configured auth{} blocks to client_p | |
705 | */ | |
706 | void | |
707 | report_auth(struct Client *client_p) | |
708 | { | |
709 | char *name, *host, *pass, *user, *classname; | |
710 | struct AddressRec *arec; | |
711 | struct ConfItem *aconf; | |
712 | int i, port; | |
713 | ||
714 | for (i = 0; i < ATABLE_SIZE; i++) | |
715 | for (arec = atable[i]; arec; arec = arec->next) | |
716 | if(arec->type == CONF_CLIENT) | |
717 | { | |
718 | aconf = arec->aconf; | |
719 | ||
720 | if(!IsOper(client_p) && IsConfDoSpoofIp(aconf)) | |
721 | continue; | |
722 | ||
723 | get_printable_conf(aconf, &name, &host, &pass, &user, &port, | |
724 | &classname); | |
725 | ||
726 | if(!EmptyString(aconf->spasswd)) | |
727 | pass = aconf->spasswd; | |
728 | ||
729 | sendto_one_numeric(client_p, RPL_STATSILINE, | |
730 | form_str(RPL_STATSILINE), | |
731 | name, pass, show_iline_prefix(client_p, aconf, user), | |
732 | show_ip_conf(aconf, client_p) ? host : "255.255.255.255", | |
733 | port, classname); | |
734 | } | |
735 | } | |
736 | ||
737 | /* report_Klines() | |
738 | * | |
739 | * inputs - Client to report to, mask | |
740 | * outputs - | |
741 | * side effects - Reports configured K-lines to client_p. | |
742 | */ | |
743 | void | |
744 | report_Klines(struct Client *source_p) | |
745 | { | |
746 | char *host, *pass, *user, *oper_reason; | |
747 | struct AddressRec *arec; | |
748 | struct ConfItem *aconf = NULL; | |
749 | int i; | |
750 | ||
751 | for (i = 0; i < ATABLE_SIZE; i++) | |
752 | { | |
753 | for (arec = atable[i]; arec; arec = arec->next) | |
754 | { | |
755 | if(arec->type == CONF_KILL) | |
756 | { | |
757 | aconf = arec->aconf; | |
758 | ||
759 | /* its a tempkline, theyre reported elsewhere */ | |
760 | if(aconf->flags & CONF_FLAGS_TEMPORARY) | |
761 | continue; | |
762 | ||
763 | get_printable_kline(source_p, aconf, &host, &pass, &user, &oper_reason); | |
764 | sendto_one_numeric(source_p, RPL_STATSKLINE, | |
765 | form_str(RPL_STATSKLINE), | |
766 | 'K', host, user, pass, | |
767 | oper_reason ? "|" : "", | |
768 | oper_reason ? oper_reason : ""); | |
769 | } | |
770 | } | |
771 | } | |
772 | } |