X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fipaccess.c;h=d00ac54ab4501e0079f03defc3288a2f536f877c;hb=d1bd9f9a0c3d8286cdd85a5d413b59206ebc2fe1;hp=18b1383ae6e25b5024a7b4a651a927eb9d0fa6a7;hpb=1d7fc9eb31d84e288cef60f39b0b70ab6a917aa5;p=libucw.git diff --git a/lib/ipaccess.c b/lib/ipaccess.c index 18b1383a..d00ac54a 100644 --- a/lib/ipaccess.c +++ b/lib/ipaccess.c @@ -2,6 +2,9 @@ * Sherlock Library -- IP address access lists * * (c) 1997--2001 Martin Mares + * + * This software may be freely distributed and used according to the terms + * of the GNU Lesser General Public License. */ #include "lib/lib.h" @@ -11,6 +14,7 @@ #include "lib/ipaccess.h" #include +#include struct ipaccess_list { list l; @@ -26,7 +30,7 @@ struct ipaccess_list * ipaccess_init(void) { /* Cannot use cfg_malloc() here as the pool can be uninitialized now */ - struct ipaccess_list *l = malloc(sizeof(*l)); + struct ipaccess_list *l = xmalloc(sizeof(*l)); init_list(&l->l); return l; @@ -58,19 +62,25 @@ parse_ip(byte *x, u32 *a) byte * ipaccess_parse(struct ipaccess_list *l, byte *c, int is_allow) { - byte *p = strchr(c, '/'); - byte *q; + char *p = strchr(c, '/'); + char *q; struct ipaccess_entry *a = cfg_malloc(sizeof(struct ipaccess_entry)); + unsigned long pxlen; a->allow = is_allow; + a->mask = ~0U; if (p) { *p++ = 0; - if (q = parse_ip(p, &a->mask)) + pxlen = strtoul(p, &q, 10); + if ((!q || !*q) && pxlen <= 32) + { + if (pxlen != 32) + a->mask = ~(~0U >> (uns) pxlen); + } + else if (q = parse_ip(p, &a->mask)) return q; } - else - a->mask = ~0; add_tail(&l->l, &a->n); return parse_ip(c, &a->addr); }