]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
unshare: Fix "you (user xxxx) don't exist" error when uid differs from primary gid
authorSol Boucher <sboucher@cmu.edu>
Fri, 8 Jul 2022 16:09:13 +0000 (12:09 -0400)
committerKarel Zak <kzak@redhat.com>
Wed, 20 Jul 2022 16:00:58 +0000 (18:00 +0200)
This problem affected the --map-auto and --map-groups=auto command-line switches.
The root cause is that /etc/subgid is indexed by user or uid, not by group or gid;
therefore, we should be using the effective uid to find entries in this file, just
as we do for /etc/subuid.

Signed-off-by: Sol Boucher <sboucher@cmu.edu>
sys-utils/unshare.c

index 95f1c1bc2a6e6f5855ceca395b084abcb3d9110d..21916adfd03e3ff3c4ad2e40778ef730c8851242 100644 (file)
@@ -859,14 +859,14 @@ int main(int argc, char *argv[])
                case OPT_MAPGROUPS:
                        unshare_flags |= CLONE_NEWUSER;
                        if (!strcmp(optarg, "auto"))
-                               groupmap = read_subid_range(_PATH_SUBGID, real_egid);
+                               groupmap = read_subid_range(_PATH_SUBGID, real_euid);
                        else
                                groupmap = get_map_range(optarg);
                        break;
                case OPT_MAPAUTO:
                        unshare_flags |= CLONE_NEWUSER;
                        usermap = read_subid_range(_PATH_SUBUID, real_euid);
-                       groupmap = read_subid_range(_PATH_SUBGID, real_egid);
+                       groupmap = read_subid_range(_PATH_SUBGID, real_euid);
                        break;
                case OPT_SETGROUPS:
                        setgrpcmd = setgroups_str2id(optarg);