summaryrefslogtreecommitdiff
path: root/src/chroot.c
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2009-05-27 23:06:15 +0200
committerJim Meyering <meyering@redhat.com>2009-06-02 16:34:53 +0200
commit2e62250e987dfb2e6253f512ef52707edc626719 (patch)
treeb026ed22fd91612cbbcb0479782214035663f8b4 /src/chroot.c
parentbb7ff3bccdf643bbe4ae01c09db996e79092da80 (diff)
downloadcoreutils-2e62250e987dfb2e6253f512ef52707edc626719.tar.xz
chroot: don't set bogus user-ID or group-ID for --u=U: or --u=:G
* src/chroot.c (main): Initialize both "uid" and "gid". To -1. This also allows one to set the user-ID or primary group-ID to 0, in case it's not that already. * tests/chroot/credentials: Test for the above.
Diffstat (limited to 'src/chroot.c')
-rw-r--r--src/chroot.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/chroot.c b/src/chroot.c
index dccddd722..39b3acf03 100644
--- a/src/chroot.c
+++ b/src/chroot.c
@@ -202,8 +202,8 @@ main (int argc, char **argv)
if (userspec)
{
- uid_t uid;
- gid_t gid;
+ uid_t uid = -1;
+ gid_t gid = -1;
char *user;
char *group;
char const *err = parse_user_spec (userspec, &uid, &gid, &user, &group);
@@ -223,13 +223,13 @@ main (int argc, char **argv)
fail = true;
}
- if (gid && setgid (gid))
+ if (gid != (gid_t) -1 && setgid (gid))
{
error (0, errno, _("failed to set group-ID"));
fail = true;
}
- if (uid && setuid (uid))
+ if (uid != (uid_t) -1 && setuid (uid))
{
error (0, errno, _("failed to set user-ID"));
fail = true;