Fix handling ACLs where > 1 entry exists

This commit is contained in:
nick
2012-06-11 12:56:45 +01:00
parent 0b90517035
commit 224bdcbf87
3 changed files with 122 additions and 19 deletions

View File

@@ -46,7 +46,7 @@ int parse_ip_to_sockaddr(struct sockaddr* out, char* src)
int parse_acl(struct ip_and_mask (**out)[], int max, char **entries)
{
struct ip_and_mask (*list)[0];
struct ip_and_mask* list;
int i;
if (max == 0) {
@@ -54,35 +54,37 @@ int parse_acl(struct ip_and_mask (**out)[], int max, char **entries)
return 0;
}
else {
*out = xmalloc(max * sizeof(struct ip_and_mask));
list = xmalloc(max * sizeof(struct ip_and_mask));
*out = (struct ip_and_mask (*)[])list;
debug("acl alloc: %p", *out);
}
list = *out;
for (i = 0; i < max; i++) {
# define MAX_MASK_BITS (outentry->ip.family == AF_INET ? 32 : 128)
int j;
struct ip_and_mask* outentry = list[i];
if (parse_ip_to_sockaddr(&outentry->ip.generic, entries[i]) == 0)
struct ip_and_mask* outentry = &list[i];
# define MAX_MASK_BITS (outentry->ip.family == AF_INET ? 32 : 128)
if (parse_ip_to_sockaddr(&outentry->ip.generic, entries[i]) == 0) {
return i;
}
for (j=0; entries[i][j] && entries[i][j] != '/'; j++)
;
; // increment j!
if (entries[i][j] == '/') {
outentry->mask = atoi(entries[i]+j+1);
if (outentry->mask < 1 || outentry->mask > MAX_MASK_BITS)
return i;
}
else
else {
outentry->mask = MAX_MASK_BITS;
}
# undef MAX_MASK_BITS
debug("acl ptr[%d]: %p %d",i, outentry, outentry->mask);
}
for (i=0; i < max; i++) {
debug("acl entry %d @ %p has mask %d", i, list[i], list[i]->mask);
debug("acl entry %d @ %p has mask %d", i, list[i], list[i].mask);
}
return max;