coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: chroot with --userspec when chrooting from x86_64 to i686


From: Dmitry V. Levin
Subject: Re: chroot with --userspec when chrooting from x86_64 to i686
Date: Wed, 2 May 2012 13:37:33 +0400

Hi,

On Tue, May 01, 2012 at 09:32:20PM +0100, John Lane wrote:
> Hello, this is my first post here, I hope this is the right place to ask 
> this question. I have also asked this on Stack Exchange but I think this 
> might be a more appropriate audience. I hope that's ok. I'm experencing 
> a problem with chroot and I am running on Arch Linux x86_64.
> 
> I have a 64 bit chroot and a 32 bit chroot. They are identical except 
> that one is 32 bit and one is 64 bit.
> 
> I can enter either of them using "chroot /path/to/chroot". No problems.
> 
> If I want to do that as a specific user the command is "chroot 
> --userspec=user:group /path/to/chroot"
> 
> This also works fine for the 64 bit chroot. However it fails for the 32 
> bit chroot. It fails with status 125 and the message "chroot: invalid user"

Looks like your 64-bit glibc failed to load 32-bit NSS plugins.
Please try this tentative patch:

diff --git a/src/chroot.c b/src/chroot.c
index dbb5c6d..195c43e 100644
--- a/src/chroot.c
+++ b/src/chroot.c
@@ -198,6 +198,22 @@ main (int argc, char **argv)
       usage (EXIT_CANCELED);
     }
 
+  /* We have to call parse_user_spec twice:
+     - first time outside chroot to load potentially necessary passwd/group
+       parsing plugins (e.g. NSS);
+     - second time inside chroot to do actual parsing. */
+  if (userspec)
+    {
+      uid_t uid = -1;
+      gid_t gid = -1;
+      char *user = NULL;
+      char *group = NULL;
+
+      parse_user_spec (userspec, &uid, &gid, &user, &group);
+      free (user);
+      free (group);
+    }
+
   if (chroot (argv[optind]) != 0)
     error (EXIT_CANCELED, errno, _("cannot change root directory to %s"),
            argv[optind]);

-- 
ldv

Attachment: pgpik3yVeH1sV.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]