From e6a01344866b5b008ba9efb7c6d446911b9e1588 Mon Sep 17 00:00:00 2001 From: ian Date: Sat, 15 Dec 2001 17:55:07 +0000 Subject: [PATCH] @@ -7,8 +7,9 @@ * udptunnel-vpn-config.m4 allows global file to override as intended. * www-cgi passes HTTP_COOKIE header. * indirect ssh via V_sshinvoke. + * userv-ipif config file allows exclusions in network permissions. - -- + -- Ian Jackson Sat, 15 Dec 2001 17:55:06 +0000 userv-utils (0.2.1) unstable; urgency=low --- changelog | 3 +- debian/changelog | 3 +- ipif/service.c | 148 +++++++++++++++++++++++++++++++++++------------ 3 files changed, 115 insertions(+), 39 deletions(-) diff --git a/changelog b/changelog index 9830a02..efb398b 100644 --- a/changelog +++ b/changelog @@ -7,8 +7,9 @@ userv-utils (0.2.2) unstable; urgency=low * udptunnel-vpn-config.m4 allows global file to override as intended. * www-cgi passes HTTP_COOKIE header. * indirect ssh via V_sshinvoke. + * userv-ipif config file allows exclusions in network permissions. - -- + -- Ian Jackson Sat, 15 Dec 2001 17:55:06 +0000 userv-utils (0.2.1) unstable; urgency=low diff --git a/debian/changelog b/debian/changelog index 9830a02..efb398b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -7,8 +7,9 @@ userv-utils (0.2.2) unstable; urgency=low * udptunnel-vpn-config.m4 allows global file to override as intended. * www-cgi passes HTTP_COOKIE header. * indirect ssh via V_sshinvoke. + * userv-ipif config file allows exclusions in network permissions. - -- + -- Ian Jackson Sat, 15 Dec 2001 17:55:06 +0000 userv-utils (0.2.1) unstable; urgency=low diff --git a/ipif/service.c b/ipif/service.c index 4137794..3a59b2b 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 @@ -128,11 +135,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 +298,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); } @@ -341,35 +354,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