use $username for subgid check

/etc/subgid contains a mapping of user names (not group names) to group
ids as defined in man subgid.
This commit is contained in:
Jochen Sprickerhof 2022-11-18 19:42:12 +01:00 committed by Johannes Schauer Marin Rodrigues
parent 1f15194a6e
commit 374ae3dc99
Signed by: josch
GPG key ID: F2CBA5C78FBD83E1

View file

@ -421,8 +421,6 @@ sub read_subuid_subgid() {
return;
}
my $groupname = getgrgid $REAL_GROUP_ID;
if (!-e "/etc/subgid") {
warning "/etc/subgid doesn't exist";
return;
@ -436,25 +434,25 @@ sub read_subuid_subgid() {
or error "cannot open /etc/subgid for reading: $!";
while (my $line = <$fh>) {
($n, $subid, $num_subid) = split(/:/, $line, 3);
last if ($n eq $groupname);
last if ($n eq $username);
}
close $fh;
if (!length $subid) {
warning "/etc/subgid is empty";
return;
}
if ($n ne $groupname) {
warning "no entry in /etc/subgid for $groupname";
if ($n ne $username) {
warning "no entry in /etc/subgid for $username";
return;
}
push @result, ["g", 0, $subid, $num_subid];
if (scalar(@result) < 2) {
warning "/etc/subgid does not contain an entry for $groupname";
warning "/etc/subgid does not contain an entry for $username";
return;
}
if (scalar(@result) > 2) {
warning "/etc/subgid contains multiple entries for $groupname";
warning "/etc/subgid contains multiple entries for $username";
return;
}