If getpwuid() fails and also the fallback of spawning of a 'getent'
process, and the user specified no command to execute, default to
/bin/sh and only fail if even that is not available. This should ensure
that unless the container is *really* weird, no matter what, the user
should always end up with a shell when calling lxc-attach with no
further arguments.
---
 src/lxc/lxc_attach.c |   16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/lxc/lxc_attach.c b/src/lxc/lxc_attach.c
index d84c3d8..9c86ffe 100644
--- a/src/lxc/lxc_attach.c
+++ b/src/lxc/lxc_attach.c
@@ -449,15 +449,21 @@ int main(int argc, char *argv[])
                if (!passwd)
                        passwd = lxc_attach_getpwuid(uid);
 
-               if (!passwd) {
-                       SYSERROR("failed to get passwd "                \
-                                "entry for uid '%d'", uid);
-                       return -1;
+               if (passwd) {
+                       char *const args[] = {
+                               passwd->pw_shell,
+                               NULL,
+                       };
+
+                       (void) execvp(args[0], args);
                }
 
+               /* executed if either no passwd entry or execvp fails,
+                * we will fall back on /bin/sh as a default shell
+                */
                {
                        char *const args[] = {
-                               passwd->pw_shell,
+                               "/bin/sh",
                                NULL,
                        };
 
-- 
1.7.10.4


------------------------------------------------------------------------------
Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester  
Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the  
endpoint security space. For insight on selecting the right partner to 
tackle endpoint security challenges, access the full report. 
http://p.sf.net/sfu/symantec-dev2dev
_______________________________________________
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel

Reply via email to