fixup read_subuid_subgid
- use $REAL_USER_ID from English instead of $< - use getgrgid $REAL_GROUP_ID to get the group name instead of assuming the group name to be equal to the user name - also check whether /etc/subgid exists and is readable
This commit is contained in:
parent
15029c1c3b
commit
60dba1c19e
1 changed files with 17 additions and 6 deletions
23
mmdebstrap
23
mmdebstrap
|
@ -325,7 +325,7 @@ sub test_unshare_userns {
|
||||||
}
|
}
|
||||||
|
|
||||||
sub read_subuid_subgid() {
|
sub read_subuid_subgid() {
|
||||||
my $username = getpwuid $<;
|
my $username = getpwuid $REAL_USER_ID;
|
||||||
my ($subid, $num_subid, $fh, $n);
|
my ($subid, $num_subid, $fh, $n);
|
||||||
my @result = ();
|
my @result = ();
|
||||||
|
|
||||||
|
@ -364,29 +364,40 @@ sub read_subuid_subgid() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my $groupname = getgrgid $REAL_GROUP_ID;
|
||||||
|
|
||||||
|
if (!-e "/etc/subgid") {
|
||||||
|
warning "/etc/subgid doesn't exist";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!-r "/etc/subgid") {
|
||||||
|
warning "/etc/subgid is not readable";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
open $fh, "<", "/etc/subgid"
|
open $fh, "<", "/etc/subgid"
|
||||||
or error "cannot open /etc/subgid for reading: $!";
|
or error "cannot open /etc/subgid for reading: $!";
|
||||||
while (my $line = <$fh>) {
|
while (my $line = <$fh>) {
|
||||||
($n, $subid, $num_subid) = split(/:/, $line, 3);
|
($n, $subid, $num_subid) = split(/:/, $line, 3);
|
||||||
last if ($n eq $username);
|
last if ($n eq $groupname);
|
||||||
}
|
}
|
||||||
close $fh;
|
close $fh;
|
||||||
if (!length $subid) {
|
if (!length $subid) {
|
||||||
warning "/etc/subgid is empty";
|
warning "/etc/subgid is empty";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ($n ne $username) {
|
if ($n ne $groupname) {
|
||||||
warning "no entry in /etc/subgid for $username";
|
warning "no entry in /etc/subgid for $groupname";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
push @result, ["g", 0, $subid, $num_subid];
|
push @result, ["g", 0, $subid, $num_subid];
|
||||||
|
|
||||||
if (scalar(@result) < 2) {
|
if (scalar(@result) < 2) {
|
||||||
warning "/etc/subgid does not contain an entry for $username";
|
warning "/etc/subgid does not contain an entry for $groupname";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (scalar(@result) > 2) {
|
if (scalar(@result) > 2) {
|
||||||
warning "/etc/subgid contains multiple entries for $username";
|
warning "/etc/subgid contains multiple entries for $groupname";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue