mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-05-30 08:24:41 +00:00
lxc-attach: Default to /bin/sh if shell cannot be determined or exec'd
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. Signed-off-by: Christian Seiler <christian@iwakd.de>
This commit is contained in:
parent
905022f73f
commit
21da9912d4
@ -452,18 +452,24 @@ int main(int argc, char *argv[])
|
|||||||
else
|
else
|
||||||
user_shell = passwd->pw_shell;
|
user_shell = passwd->pw_shell;
|
||||||
|
|
||||||
if (!user_shell) {
|
if (user_shell) {
|
||||||
SYSERROR("failed to get passwd " \
|
|
||||||
"entry for uid '%d'", uid);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
char *const args[] = {
|
char *const args[] = {
|
||||||
user_shell,
|
user_shell,
|
||||||
NULL,
|
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[] = {
|
||||||
|
"/bin/sh",
|
||||||
|
NULL,
|
||||||
|
};
|
||||||
|
|
||||||
execvp(args[0], args);
|
execvp(args[0], args);
|
||||||
SYSERROR("failed to exec '%s'", args[0]);
|
SYSERROR("failed to exec '%s'", args[0]);
|
||||||
return -1;
|
return -1;
|
||||||
|
Loading…
Reference in New Issue
Block a user