46 |
ch = ch - 'A' + 10; \ |
ch = ch - 'A' + 10; \ |
47 |
else if (ch >= 'a' && ch <= 'f') \ |
else if (ch >= 'a' && ch <= 'f') \ |
48 |
ch = ch - 'a' + 10; \ |
ch = ch - 'a' + 10; \ |
49 |
} while(0); |
} while (0); |
50 |
|
|
51 |
/* The mask parser/type determination code... */ |
/* The mask parser/type determination code... */ |
52 |
|
|
74 |
int bits = 128; |
int bits = 128; |
75 |
int deficit = 0; |
int deficit = 0; |
76 |
short dc[8]; |
short dc[8]; |
77 |
struct sockaddr_in6 *v6 = (struct sockaddr_in6*) addr; |
struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)addr; |
78 |
|
|
79 |
for (p = text; (c = *p); p++) |
for (p = text; (c = *p); p++) |
80 |
if (IsXDigit(c)) |
if (IsXDigit(c)) |
116 |
d[dp] = d[dp] >> 4 * nyble; |
d[dp] = d[dp] >> 4 * nyble; |
117 |
dp++; |
dp++; |
118 |
bits = strtoul(p + 1, &after, 10); |
bits = strtoul(p + 1, &after, 10); |
119 |
|
|
120 |
if (bits < 0 || *after) |
if (bits < 0 || *after) |
121 |
return HM_HOST; |
return HM_HOST; |
122 |
if (bits > dp * 4 && !(finsert >= 0 && bits <= 128)) |
if (bits > dp * 4 && !(finsert >= 0 && bits <= 128)) |
127 |
return HM_HOST; |
return HM_HOST; |
128 |
|
|
129 |
d[dp] = d[dp] >> 4 * nyble; |
d[dp] = d[dp] >> 4 * nyble; |
130 |
|
|
131 |
if (c == 0) |
if (c == 0) |
132 |
dp++; |
dp++; |
133 |
if (finsert < 0 && bits == 0) |
if (finsert < 0 && bits == 0) |
134 |
bits = dp * 16; |
bits = dp * 16; |
135 |
|
|
136 |
/* How many words are missing? -A1kmm */ |
/* How many words are missing? -A1kmm */ |
137 |
deficit = bits / 16 + ((bits % 16) ? 1 : 0) - dp; |
deficit = bits / 16 + ((bits % 16) ? 1 : 0) - dp; |
138 |
|
|
139 |
/* Now fill in the gaps(from ::) in the copied table... -A1kmm */ |
/* Now fill in the gaps(from ::) in the copied table... -A1kmm */ |
140 |
for (dp = 0, nyble = 0; dp < 8; dp++) |
for (dp = 0, nyble = 0; dp < 8; dp++) |
141 |
{ |
{ |
147 |
else |
else |
148 |
dc[dp] = d[nyble++]; |
dc[dp] = d[nyble++]; |
149 |
} |
} |
150 |
|
|
151 |
/* Set unused bits to 0... -A1kmm */ |
/* Set unused bits to 0... -A1kmm */ |
152 |
if (bits < 128 && (bits % 16 != 0)) |
if (bits < 128 && (bits % 16 != 0)) |
153 |
dc[bits / 16] &= ~((1 << (15 - bits % 16)) - 1); |
dc[bits / 16] &= ~((1 << (15 - bits % 16)) - 1); |
154 |
for (dp = bits / 16 + (bits % 16 ? 1 : 0); dp < 8; dp++) |
for (dp = bits / 16 + (bits % 16 ? 1 : 0); dp < 8; dp++) |
155 |
dc[dp] = 0; |
dc[dp] = 0; |
156 |
|
|
157 |
/* And assign... -A1kmm */ |
/* And assign... -A1kmm */ |
158 |
if (addr) |
if (addr) |
159 |
for (dp = 0; dp < 8; dp++) |
for (dp = 0; dp < 8; dp++) |
160 |
/* The cast is a kludge to make netbsd work. */ |
/* The cast is a kludge to make netbsd work. */ |
161 |
((unsigned short *)&v6->sin6_addr)[dp] = htons(dc[dp]); |
((unsigned short *)&v6->sin6_addr)[dp] = htons(dc[dp]); |
162 |
|
|
163 |
if (b != NULL) |
if (b != NULL) |
164 |
*b = bits; |
*b = bits; |
165 |
return HM_IPV6; |
return HM_IPV6; |
181 |
unsigned char addb[4]; |
unsigned char addb[4]; |
182 |
int n = 0, bits = 0; |
int n = 0, bits = 0; |
183 |
char c; |
char c; |
184 |
struct sockaddr_in *v4 = (struct sockaddr_in*) addr; |
struct sockaddr_in *v4 = (struct sockaddr_in *)addr; |
185 |
|
|
186 |
digits[n++] = text; |
digits[n++] = text; |
187 |
|
|
192 |
{ |
{ |
193 |
if (n >= 4) |
if (n >= 4) |
194 |
return HM_HOST; |
return HM_HOST; |
195 |
|
|
196 |
digits[n++] = p + 1; |
digits[n++] = p + 1; |
197 |
} |
} |
198 |
else if (c == '*') |
else if (c == '*') |
199 |
{ |
{ |
200 |
if (*(p + 1) || n == 0 || *(p - 1) != '.') |
if (*(p + 1) || n == 0 || *(p - 1) != '.') |
201 |
return HM_HOST; |
return HM_HOST; |
202 |
|
|
203 |
bits = (n - 1) * 8; |
bits = (n - 1) * 8; |
204 |
break; |
break; |
205 |
} |
} |
207 |
{ |
{ |
208 |
char *after; |
char *after; |
209 |
bits = strtoul(p + 1, &after, 10); |
bits = strtoul(p + 1, &after, 10); |
210 |
|
|
211 |
if (!bits || *after) |
if (!bits || *after) |
212 |
return HM_HOST; |
return HM_HOST; |
213 |
if (bits > n * 8) |
if (bits > n * 8) |
214 |
return HM_HOST; |
return HM_HOST; |
215 |
|
|
216 |
break; |
break; |
217 |
} |
} |
218 |
else |
else |
223 |
if (bits) |
if (bits) |
224 |
while (n < 4) |
while (n < 4) |
225 |
digits[n++] = "0"; |
digits[n++] = "0"; |
226 |
|
|
227 |
for (n = 0; n < 4; n++) |
for (n = 0; n < 4; n++) |
228 |
addb[n] = strtoul(digits[n], NULL, 10); |
addb[n] = strtoul(digits[n], NULL, 10); |
229 |
|
|
230 |
if (bits == 0) |
if (bits == 0) |
231 |
bits = 32; |
bits = 32; |
232 |
|
|
233 |
/* Set unused bits to 0... -A1kmm */ |
/* Set unused bits to 0... -A1kmm */ |
234 |
if (bits < 32 && bits % 8) |
if (bits < 32 && bits % 8) |
235 |
addb[bits / 8] &= ~((1 << (8 - bits % 8)) - 1); |
addb[bits / 8] &= ~((1 << (8 - bits % 8)) - 1); |
254 |
parse_netmask(const char *text, struct irc_ssaddr *addr, int *b) |
parse_netmask(const char *text, struct irc_ssaddr *addr, int *b) |
255 |
{ |
{ |
256 |
#ifdef IPV6 |
#ifdef IPV6 |
257 |
if (strchr(text, ':')) |
if (strchr(text, ':')) |
258 |
return try_parse_v6_netmask(text, addr, b); |
return try_parse_v6_netmask(text, addr, b); |
259 |
#endif |
#endif |
260 |
if (strchr(text, '.')) |
if (strchr(text, '.')) |
273 |
match_ipv6(struct irc_ssaddr *addr, struct irc_ssaddr *mask, int bits) |
match_ipv6(struct irc_ssaddr *addr, struct irc_ssaddr *mask, int bits) |
274 |
{ |
{ |
275 |
int i, m, n = bits / 8; |
int i, m, n = bits / 8; |
276 |
struct sockaddr_in6 *v6 = (struct sockaddr_in6*)addr; |
struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)addr; |
277 |
struct sockaddr_in6 *v6mask = (struct sockaddr_in6*)mask; |
struct sockaddr_in6 *v6mask = (struct sockaddr_in6 *)mask; |
278 |
|
|
279 |
for (i = 0; i < n; i++) |
for (i = 0; i < n; i++) |
280 |
if (v6->sin6_addr.s6_addr[i] != v6mask->sin6_addr.s6_addr[i]) |
if (v6->sin6_addr.s6_addr[i] != v6mask->sin6_addr.s6_addr[i]) |
295 |
int |
int |
296 |
match_ipv4(struct irc_ssaddr *addr, struct irc_ssaddr *mask, int bits) |
match_ipv4(struct irc_ssaddr *addr, struct irc_ssaddr *mask, int bits) |
297 |
{ |
{ |
298 |
struct sockaddr_in *v4 = (struct sockaddr_in*) addr; |
struct sockaddr_in *v4 = (struct sockaddr_in *)addr; |
299 |
struct sockaddr_in *v4mask = (struct sockaddr_in*) mask; |
struct sockaddr_in *v4mask = (struct sockaddr_in *)mask; |
300 |
|
|
301 |
if ((ntohl(v4->sin_addr.s_addr) & ~((1 << (32 - bits)) - 1)) != |
if ((ntohl(v4->sin_addr.s_addr) & ~((1 << (32 - bits)) - 1)) != |
302 |
ntohl(v4mask->sin_addr.s_addr)) |
ntohl(v4mask->sin_addr.s_addr)) |
303 |
return 0; |
return 0; |
326 |
if (ip->ss.ss_family != AF_INET6) |
if (ip->ss.ss_family != AF_INET6) |
327 |
#endif |
#endif |
328 |
{ |
{ |
329 |
v4_base_ip = (struct sockaddr_in*)ip; |
v4_base_ip = (struct sockaddr_in *)ip; |
330 |
|
|
331 |
mask = ~((1 << (32 - bits)) - 1); |
mask = ~((1 << (32 - bits)) - 1); |
332 |
v4_base_ip->sin_addr.s_addr = |
v4_base_ip->sin_addr.s_addr = htonl(ntohl(v4_base_ip->sin_addr.s_addr) & mask); |
|
htonl(ntohl(v4_base_ip->sin_addr.s_addr) & mask); |
|
333 |
} |
} |
334 |
#ifdef IPV6 |
#ifdef IPV6 |
335 |
else |
else |
336 |
{ |
{ |
337 |
n = bits / 8; |
n = bits / 8; |
338 |
m = bits % 8; |
m = bits % 8; |
339 |
v6_base_ip = (struct sockaddr_in6*)ip; |
v6_base_ip = (struct sockaddr_in6 *)ip; |
340 |
|
|
341 |
mask = ~((1 << (8 - m)) -1 ); |
mask = ~((1 << (8 - m)) -1 ); |
342 |
v6_base_ip->sin6_addr.s6_addr[n] = v6_base_ip->sin6_addr.s6_addr[n] & mask; |
v6_base_ip->sin6_addr.s6_addr[n] = v6_base_ip->sin6_addr.s6_addr[n] & mask; |
343 |
|
|
344 |
for (i = n + 1; i < 16; i++) |
for (i = n + 1; i < 16; i++) |
345 |
v6_base_ip->sin6_addr.s6_addr[i] = 0; |
v6_base_ip->sin6_addr.s6_addr[i] = 0; |
346 |
} |
} |
368 |
{ |
{ |
369 |
struct sockaddr_in *v4 = (struct sockaddr_in *)addr; |
struct sockaddr_in *v4 = (struct sockaddr_in *)addr; |
370 |
unsigned long av = ntohl(v4->sin_addr.s_addr) & ~((1 << (32 - bits)) - 1); |
unsigned long av = ntohl(v4->sin_addr.s_addr) & ~((1 << (32 - bits)) - 1); |
371 |
return((av ^ (av >> 12) ^ (av >> 24)) & (ATABLE_SIZE - 1)); |
|
372 |
|
return (av ^ (av >> 12) ^ (av >> 24)) & (ATABLE_SIZE - 1); |
373 |
} |
} |
374 |
|
|
375 |
return(0); |
return 0; |
376 |
} |
} |
377 |
|
|
378 |
/* unsigned long hash_ipv6(struct irc_ssaddr*) |
/* unsigned long hash_ipv6(struct irc_ssaddr*) |
385 |
hash_ipv6(struct irc_ssaddr *addr, int bits) |
hash_ipv6(struct irc_ssaddr *addr, int bits) |
386 |
{ |
{ |
387 |
unsigned long v = 0, n; |
unsigned long v = 0, n; |
388 |
struct sockaddr_in6 *v6 = (struct sockaddr_in6*) addr; |
struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)addr; |
389 |
|
|
390 |
for (n = 0; n < 16; n++) |
for (n = 0; n < 16; n++) |
391 |
{ |
{ |
392 |
if (bits >= 8) |
if (bits >= 8) |
418 |
unsigned long h = 0; |
unsigned long h = 0; |
419 |
|
|
420 |
while (*p) |
while (*p) |
|
{ |
|
421 |
h = (h << 4) - (h + (unsigned char)ToLower(*p++)); |
h = (h << 4) - (h + (unsigned char)ToLower(*p++)); |
422 |
} |
|
423 |
return (h & (ATABLE_SIZE - 1)); |
return h & (ATABLE_SIZE - 1); |
424 |
} |
} |
425 |
|
|
426 |
/* unsigned long get_hash_mask(const char *) |
/* unsigned long get_hash_mask(const char *) |
567 |
/* Find the best I-line... If none, return NULL -A1kmm */ |
/* Find the best I-line... If none, return NULL -A1kmm */ |
568 |
if ((iconf = find_conf_by_address(host, ip, CONF_CLIENT, aftype, user, |
if ((iconf = find_conf_by_address(host, ip, CONF_CLIENT, aftype, user, |
569 |
password)) == NULL) |
password)) == NULL) |
570 |
return(NULL); |
return NULL; |
571 |
|
|
572 |
/* If they are exempt from K-lines, return the best I-line. -A1kmm */ |
/* If they are exempt from K-lines, return the best I-line. -A1kmm */ |
573 |
if (IsConfExemptKline(iconf)) |
if (IsConfExemptKline(iconf)) |
574 |
return(iconf); |
return iconf; |
575 |
|
|
576 |
/* Find the best K-line... -A1kmm */ |
/* Find the best K-line... -A1kmm */ |
577 |
kconf = find_conf_by_address(host, ip, CONF_KILL, aftype, user, NULL); |
kconf = find_conf_by_address(host, ip, CONF_KILL, aftype, user, NULL); |
579 |
/* If they are K-lined, return the K-line. Otherwise, return the |
/* If they are K-lined, return the K-line. Otherwise, return the |
580 |
* I-line. -A1kmm */ |
* I-line. -A1kmm */ |
581 |
if (kconf != NULL) |
if (kconf != NULL) |
582 |
return(kconf); |
return kconf; |
583 |
|
|
584 |
kconf = find_conf_by_address(host, ip, CONF_GLINE, aftype, user, NULL); |
kconf = find_conf_by_address(host, ip, CONF_GLINE, aftype, user, NULL); |
585 |
if (kconf != NULL && !IsConfExemptGline(iconf)) |
if (kconf != NULL && !IsConfExemptGline(iconf)) |
586 |
return(kconf); |
return kconf; |
587 |
|
|
588 |
return(iconf); |
return iconf; |
589 |
} |
} |
590 |
|
|
591 |
struct AccessItem * |
struct AccessItem * |
597 |
eline = find_conf_by_address(host, ip, CONF_EXEMPTKLINE, aftype, |
eline = find_conf_by_address(host, ip, CONF_EXEMPTKLINE, aftype, |
598 |
user, NULL); |
user, NULL); |
599 |
if (eline != NULL) |
if (eline != NULL) |
600 |
return(eline); |
return eline; |
601 |
|
|
602 |
return(find_conf_by_address(host, ip, CONF_GLINE, aftype, user, NULL)); |
return find_conf_by_address(host, ip, CONF_GLINE, aftype, user, NULL); |
603 |
} |
} |
604 |
|
|
605 |
/* find_kline_conf |
/* find_kline_conf |
612 |
*/ |
*/ |
613 |
struct AccessItem * |
struct AccessItem * |
614 |
find_kline_conf(const char *host, const char *user, |
find_kline_conf(const char *host, const char *user, |
615 |
struct irc_ssaddr *ip, int aftype) |
struct irc_ssaddr *ip, int aftype) |
616 |
{ |
{ |
617 |
struct AccessItem *eline; |
struct AccessItem *eline; |
618 |
|
|
619 |
eline = find_conf_by_address(host, ip, CONF_EXEMPTKLINE, aftype, |
eline = find_conf_by_address(host, ip, CONF_EXEMPTKLINE, aftype, |
620 |
user, NULL); |
user, NULL); |
621 |
if (eline != NULL) |
if (eline != NULL) |
622 |
return(eline); |
return eline; |
623 |
|
|
624 |
return(find_conf_by_address(host, ip, CONF_KILL, aftype, user, NULL)); |
return find_conf_by_address(host, ip, CONF_KILL, aftype, user, NULL); |
625 |
} |
} |
626 |
|
|
627 |
/* struct AccessItem* find_dline_conf(struct irc_ssaddr*, int) |
/* struct AccessItem* find_dline_conf(struct irc_ssaddr*, int) |
638 |
eline = find_conf_by_address(NULL, addr, CONF_EXEMPTDLINE | 1, aftype, |
eline = find_conf_by_address(NULL, addr, CONF_EXEMPTDLINE | 1, aftype, |
639 |
NULL, NULL); |
NULL, NULL); |
640 |
if (eline != NULL) |
if (eline != NULL) |
641 |
return(eline); |
return eline; |
642 |
return(find_conf_by_address(NULL, addr, CONF_DLINE | 1, aftype, NULL, NULL)); |
|
643 |
|
return find_conf_by_address(NULL, addr, CONF_DLINE | 1, aftype, NULL, NULL); |
644 |
} |
} |
645 |
|
|
646 |
/* void add_conf_by_address(int, struct AccessItem *aconf) |
/* void add_conf_by_address(int, struct AccessItem *aconf) |
671 |
masktype = parse_netmask(address, &arec->Mask.ipa.addr, &bits); |
masktype = parse_netmask(address, &arec->Mask.ipa.addr, &bits); |
672 |
arec->Mask.ipa.bits = bits; |
arec->Mask.ipa.bits = bits; |
673 |
arec->masktype = masktype; |
arec->masktype = masktype; |
674 |
|
|
675 |
#ifdef IPV6 |
#ifdef IPV6 |
676 |
if (masktype == HM_IPV6) |
if (masktype == HM_IPV6) |
677 |
{ |
{ |
695 |
arec->next = atable[(hv = get_mask_hash(address))]; |
arec->next = atable[(hv = get_mask_hash(address))]; |
696 |
atable[hv] = arec; |
atable[hv] = arec; |
697 |
} |
} |
698 |
|
|
699 |
arec->username = username; |
arec->username = username; |
700 |
arec->aconf = aconf; |
arec->aconf = aconf; |
701 |
arec->precedence = prec_value--; |
arec->precedence = prec_value--; |
715 |
unsigned long hv; |
unsigned long hv; |
716 |
struct AddressRec *arec, *arecl = NULL; |
struct AddressRec *arec, *arecl = NULL; |
717 |
struct irc_ssaddr addr; |
struct irc_ssaddr addr; |
718 |
|
|
719 |
masktype = parse_netmask(address, &addr, &bits); |
masktype = parse_netmask(address, &addr, &bits); |
720 |
|
|
721 |
#ifdef IPV6 |
#ifdef IPV6 |
735 |
} |
} |
736 |
else |
else |
737 |
hv = get_mask_hash(address); |
hv = get_mask_hash(address); |
738 |
|
|
739 |
for (arec = atable[hv]; arec; arec = arec->next) |
for (arec = atable[hv]; arec; arec = arec->next) |
740 |
{ |
{ |
741 |
if (arec->aconf == aconf) |
if (arec->aconf == aconf) |
744 |
arecl->next = arec->next; |
arecl->next = arec->next; |
745 |
else |
else |
746 |
atable[hv] = arec->next; |
atable[hv] = arec->next; |
747 |
|
|
748 |
aconf->status |= CONF_ILLEGAL; |
aconf->status |= CONF_ILLEGAL; |
749 |
|
|
750 |
if (aconf->clients == 0) |
if (aconf->clients == 0) |
751 |
free_access_item(aconf); |
free_access_item(aconf); |
752 |
|
|
753 |
MyFree(arec); |
MyFree(arec); |
754 |
return; |
return; |
755 |
} |
} |
775 |
for (i = 0; i < ATABLE_SIZE; i++) |
for (i = 0; i < ATABLE_SIZE; i++) |
776 |
{ |
{ |
777 |
last_arec = NULL; |
last_arec = NULL; |
778 |
|
|
779 |
for (arec = atable[i]; arec; arec = next_arec) |
for (arec = atable[i]; arec; arec = next_arec) |
780 |
{ |
{ |
781 |
/* We keep the temporary K-lines and destroy the |
/* We keep the temporary K-lines and destroy the |
801 |
} |
} |
802 |
|
|
803 |
arec->aconf->status |= CONF_ILLEGAL; |
arec->aconf->status |= CONF_ILLEGAL; |
804 |
|
|
805 |
if (arec->aconf->clients == 0) |
if (arec->aconf->clients == 0) |
806 |
free_access_item(arec->aconf); |
free_access_item(arec->aconf); |
807 |
MyFree(arec); |
MyFree(arec); |
823 |
show_iline_prefix(struct Client *sptr, struct AccessItem *aconf, const char *name) |
show_iline_prefix(struct Client *sptr, struct AccessItem *aconf, const char *name) |
824 |
{ |
{ |
825 |
static char prefix_of_host[USERLEN + 14]; |
static char prefix_of_host[USERLEN + 14]; |
826 |
char *prefix_ptr; |
char *prefix_ptr = prefix_of_host; |
827 |
|
|
|
prefix_ptr = prefix_of_host; |
|
828 |
if (IsNoTilde(aconf)) |
if (IsNoTilde(aconf)) |
829 |
*prefix_ptr++ = '-'; |
*prefix_ptr++ = '-'; |
830 |
if (IsLimitIp(aconf)) |
if (IsLimitIp(aconf)) |
847 |
*prefix_ptr++ = '>'; |
*prefix_ptr++ = '>'; |
848 |
if (IsConfCanFlood(aconf)) |
if (IsConfCanFlood(aconf)) |
849 |
*prefix_ptr++ = '|'; |
*prefix_ptr++ = '|'; |
850 |
|
|
851 |
strlcpy(prefix_ptr, name, USERLEN+1); |
strlcpy(prefix_ptr, name, USERLEN+1); |
852 |
|
|
853 |
return(prefix_of_host); |
return prefix_of_host; |
854 |
} |
} |
855 |
|
|
856 |
/* report_auth() |
/* report_auth() |
934 |
(!tkline && ((aconf = arec->aconf)->flags & CONF_FLAGS_TEMPORARY))) |
(!tkline && ((aconf = arec->aconf)->flags & CONF_FLAGS_TEMPORARY))) |
935 |
continue; |
continue; |
936 |
|
|
937 |
if (HasUMode(client_p, UMODE_OPER)) |
if (HasUMode(client_p, UMODE_OPER)) |
938 |
sendto_one(client_p, form_str(RPL_STATSKLINE), me.name, |
sendto_one(client_p, form_str(RPL_STATSKLINE), me.name, |
939 |
client_p->name, p, aconf->host, aconf->user, |
client_p->name, p, aconf->host, aconf->user, |
940 |
aconf->reason, aconf->oper_reason ? aconf->oper_reason : ""); |
aconf->reason, aconf->oper_reason ? aconf->oper_reason : ""); |
941 |
else |
else |
942 |
sendto_one(client_p, form_str(RPL_STATSKLINE), me.name, |
sendto_one(client_p, form_str(RPL_STATSKLINE), me.name, |
943 |
client_p->name, p, aconf->host, aconf->user, |
client_p->name, p, aconf->host, aconf->user, |
944 |
aconf->reason, ""); |
aconf->reason, ""); |
945 |
} |
} |
946 |
} |
} |
947 |
} |
} |