X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=blobdiff_plain;f=ipif%2Fservice.c;h=08b0ed9f61a40859d37f531231940433db77d76c;hb=5f3e811b5415dcff74f82bdd2f26d3af1f73c555;hp=397740cba8e4db12008d46c3e74aa4c40bb272f2;hpb=5124214b2f9f6c40ac43ca9044a6b82eedd48b71;p=userv-utils.git diff --git a/ipif/service.c b/ipif/service.c index 397740c..08b0ed9 100644 --- a/ipif/service.c +++ b/ipif/service.c @@ -59,7 +59,7 @@ * Reads a file which contains lines which are each * items. * - * ,[=]/[,] + * ,[=][-|+]/(-|+/...)[,] * * Indicates that may allocate addresses in the relevant address * range ( is ignored). must be numeric. To specify a @@ -67,6 +67,13 @@ * specified then the specific subrange is only allowed for the local * endpoint address, but not for remote addresses. * + * More than one range may be given, with each range prefixed + * by + or -. In this case each address range in the rule will + * scanned in order, and the first range in the rule that matches + * any desired rule will count: if that first matching range is + * prefixed by `+' (or nothing) then the rule applies, if it + * is prefixed by `-' (or nothing matches), the rule does not. + * * * * Means that anything is to be permitted. This should not appear in * /etc/userv/ipif-networks, as that would permit any user on the @@ -84,7 +91,8 @@ * The service program should be run from userv with no-disconnect-hup. */ /* - * Copyright (C) 1999-2000 Ian Jackson + * Copyright (C) 1999-2000,2003 Ian Jackson + * This file is part of ipif, part of userv-utils * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by @@ -119,7 +127,7 @@ #include #define NARGS 4 -#define MAXEXROUTES 5 +#define MAXEXROUTES 50 #define ATXTLEN 16 static const unsigned long gidmaxval= (unsigned long)((gid_t)-2); @@ -128,11 +136,12 @@ static const int signals[]= { SIGHUP, SIGINT, SIGTERM, 0 }; static const char *configstr, *proto; static unsigned long localaddr, peeraddr, mtu; +static int localpming, peerpming; static int localallow, peerallow, allallow; static int nexroutes; static struct exroute { unsigned long prefix, mask; - int allow; + int allow, pming; char prefixtxt[ATXTLEN], masktxt[ATXTLEN]; } exroutes[MAXEXROUTES]; @@ -290,12 +299,17 @@ static unsigned long eat_number(const char **argp, const char *what, return rv; } -static void addrnet_mustdiffer(const char *w1, unsigned long p1, unsigned long m1, - const char *w2, unsigned long p2, unsigned long m2) { +static int addrnet_overlap(unsigned long p1, unsigned long m1, + unsigned long p2, unsigned long m2) { unsigned long mask; mask= m1&m2; - if ((p1 & mask) != (p2 & mask)) return; + return (p1 & mask) == (p2 & mask); +} + +static void addrnet_mustdiffer(const char *w1, unsigned long p1, unsigned long m1, + const char *w2, unsigned long p2, unsigned long m2) { + if (!addrnet_overlap(p1,m1,p2,m2)) return; badusage("%s %08lx/%08lx overlaps/clashes with %s %08lx/%08lx", w1,p1,m1, w2,p2,m2); } @@ -329,7 +343,7 @@ static void eat_prefixmask(const char **argp, const char *what, sprintf(whatbuf,"%s length",what); len= eat_number(argp,whatbuf, 0,32, endchars,endchar_r); - mask= (~0UL << (32-len)); + mask= len ? (~0UL << (32-len)) : 0UL; if (prefix & ~mask) badusage("%s prefix %08lx not fully contained in mask %08lx", what,prefix,mask); *prefix_r= prefix; @@ -341,35 +355,66 @@ static int addrnet_isin(unsigned long prefix, unsigned long mask, unsigned long mprefix, unsigned long mmask) { return !(~mask & mmask) && (prefix & mmask) == mprefix; } + +/* Totally hideous algorithm for parsing the config file lines. + * For each config file line, we first see if its gid applies. If not + * we skip it. Otherwise, we do + * permit_begin + * which sets pming to 1 + * for each range. pming may be 0 if we've determined that + * this line does not apply to . + * permit_range + * which calls permit_range_thing for each + * which checks to see if is inside the relevant + * range (for +) or overlaps it (for -) and updates + * allow and pming. + */ + +static void permit_begin(void) { + int i; + localpming= peerpming= 1; + for (i=0; i