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