chiark / gitweb /
ipif/service-wrap: Remove spurious space from space-matching regexp.
[userv-utils.git] / ipif / service-wrap
index 678a86789baf282bb72d51db146309bc973e2c9d..2bca709e9501619ee0db409df87a5c2527d4690c 100755 (executable)
@@ -62,6 +62,7 @@ use strict;
 use POSIX;
 use Carp;
 use NetAddr::IP::Lite qw(:nofqdn :lower);
+use File::Basename;
 
 our $default_ifname = 'userv%d';
 
@@ -228,7 +229,7 @@ sub readconfig ($) {
                    my $net = $hn->network() or die;
                    maybe_allow_addrs 'Local', $host;
                    maybe_allow_addrs 'Remote', $net;
-               } elsif (s{^(local|remote|addrs)\s+(\S+)\ s+}{}) {
+               } elsif (s{^(local|remote|addrs)\s+(\S+)\s+}{}) {
                    my $h = $1;
                    my $s = new NetAddr::IP::Lite $2 or
                        badcfg "invalid ip address or mask in $h";
@@ -265,7 +266,9 @@ sub readconfig ($) {
                    foreach @wrong;
            }
        } elsif (m{^include\s+(\S+)$}) {
-           readconfig $1;
+           my $include = $1;
+           $include =~ s{^(?!/)}{ dirname($cfgpath)."/" }e;
+           readconfig $include;
        } else {
            badcfg "unknown config directive or bad syntax";
        }
@@ -274,10 +277,21 @@ sub readconfig ($) {
     close $cfgfh;
 }
 
-readconfig $v1config;
-
-if ($v0config && $v0config =~ m{^[^#]} && $v0config ne '/dev/null') {
+sub try_v0config() {
+    return unless $v0config;
+    return unless $v0config =~ m{^[^#]};
+    return if $v0config eq '/dev/null';
+    if ($v0config =~ m{^/}) {
+       if (!stat $v0config) {
+           die "v0 config $v0config: $!\n" unless $!==ENOENT;
+           return;
+       }
+    }
     print "trying v0 config $v0config...\n" if $protocol eq 'debug';
     execreal $v0config;
 }
+
+readconfig $v1config;
+try_v0config();
+
 die "permission denied\n";