check whether newuidmap and newgidmap are available

This commit is contained in:
Johannes 'josch' Schauer 2018-09-24 20:09:08 +02:00
parent 95669ff193
commit d232870b28
Signed by untrusted user: josch
GPG key ID: F2CBA5C78FBD83E1

View file

@ -109,6 +109,16 @@ sub test_unshare() {
if (($? >> 8) != 0) {
return 0;
}
# if newuidmap and newgidmap exist, the exit status will be 1 when
# executed without parameters
system "newuidmap 2>/dev/null";
if (($? >> 8) != 1) {
return 0;
}
system "newgidmap 2>/dev/null";
if (($? >> 8) != 1) {
return 0;
}
return 1;
}
@ -1357,6 +1367,22 @@ sub main() {
if ($EFFECTIVE_USER_ID == 0) {
print STDERR "I: cannot use unshare mode when executing as root\n";
}
system "newuidmap 2>/dev/null";
if (($? >> 8) != 1) {
if (($? >> 8) == 127) {
print STDERR "I: cannot find newuidmap\n";
} else {
print STDERR "I: newuidmap returned unknown exit status\n";
}
}
system "newgidmap 2>/dev/null";
if (($? >> 8) != 1) {
if (($? >> 8) == 127) {
print STDERR "I: cannot find newgidmap\n";
} else {
print STDERR "I: newgidmap returned unknown exit status\n";
}
}
my $procfile = '/proc/sys/kernel/unprivileged_userns_clone';
open(my $fh, '<', $procfile) or die "failed to open $procfile: $!";
chomp(my $content = do { local $/; <$fh> });