Only use user namespace if we actually need it for chroot()

Since we don't have proper user/group info inside the user namespace we
set up, avoid going there unless we have to. Fixes a regression introduced
in commit b4c832caed where non-root,
non-chroot verification shows user and group differing on all files.
This commit is contained in:
Panu Matilainen 2019-05-13 10:13:52 +03:00 committed by Florian Festi
parent 59aee7a198
commit 4dfe5e7a18
1 changed files with 3 additions and 2 deletions

View File

@ -100,8 +100,6 @@ int rpmChrootSet(const char *rootDir)
rpmlog(RPMLOG_ERR, _("Unable to open current directory: %m\n"));
rc = -1;
}
if (!_rpm_nouserns && rc == 0 && getuid())
try_become_root();
}
return rc;
@ -123,6 +121,9 @@ int rpmChrootIn(void)
if (rootState.chrootDone > 0) {
rootState.chrootDone++;
} else if (rootState.chrootDone == 0) {
if (!_rpm_nouserns && getuid())
try_become_root();
if (chdir("/") == 0 && chroot(rootState.rootDir) == 0) {
rootState.chrootDone = 1;
} else {