]> git.gsnw.org Git - fping.git/commitdiff
test-11-nopriv: check Linux GID permission for unprivileged ping
authorSteven Noonan <steven@uplinklabs.net>
Thu, 27 Feb 2020 21:04:34 +0000 (13:04 -0800)
committerSteven Noonan <steven@uplinklabs.net>
Thu, 27 Feb 2020 21:46:39 +0000 (13:46 -0800)
Signed-off-by: Steven Noonan <steven@uplinklabs.net>
ci/test-11-nopriv.pl

index a6bcfd234b86a63748673d8afccf2085f26a518e..243362ee1e86482c1aa771557ac292ad7f3565ad 100755 (executable)
@@ -1,5 +1,6 @@
 #!/usr/bin/perl -w
 
+use English;
 use Test::Command;
 use Test::More;
 
@@ -7,6 +8,26 @@ if( $^O eq 'darwin' ) {
     plan skip_all => 'Test irrelevant on MacOS';
     exit 0;
 }
+
+sub get_ping_gid_range {
+       open FD, "/proc/sys/net/ipv4/ping_group_range" or return undef;
+       chomp(my $line = <FD>);
+       my @range = split(/\s+/, $line);
+       close FD;
+       return @range;
+}
+
+my @gids = split(' ', $EGID);
+my @allowed_gid_range = get_ping_gid_range();
+
+# Linux test for unprivileged ping support
+foreach(@gids) {
+       if ($_ >= $allowed_gid_range[0] && $_ <= $allowed_gid_range[1]) {
+               plan skip_all => "Userspace pings are allowed, gid $_ in range [$allowed_gid_range[0], $allowed_gid_range[1]]";
+               exit 0;
+       }
+}
+
 plan tests => 3;
 
 # run without privileges