diff options
-rw-r--r-- | src/firejail/join.c | 87 |
1 files changed, 64 insertions, 23 deletions
diff --git a/src/firejail/join.c b/src/firejail/join.c index 504748331..c14108986 100644 --- a/src/firejail/join.c +++ b/src/firejail/join.c | |||
@@ -352,17 +352,25 @@ void join(pid_t pid, int argc, char **argv, int index) { | |||
352 | 352 | ||
353 | // run cmdline trough /bin/bash | 353 | // run cmdline trough /bin/bash |
354 | if (cfg.command_line == NULL) { | 354 | if (cfg.command_line == NULL) { |
355 | struct stat s; | ||
356 | 355 | ||
357 | // replace the process with a shell | 356 | // replace the process with a shell |
358 | if (stat("/bin/bash", &s) == 0) | 357 | if (cfg.shell) |
359 | execlp("/bin/bash", "/bin/bash", NULL); | 358 | execlp(cfg.shell, cfg.shell, NULL); |
360 | else if (stat("/usr/bin/zsh", &s) == 0) | 359 | else if (arg_zsh) |
361 | execlp("/usr/bin/zsh", "/usr/bin/zsh", NULL); | 360 | execlp("/usr/bin/zsh", "/usr/bin/zsh", NULL); |
362 | else if (stat("/bin/csh", &s) == 0) | 361 | else if (arg_csh) |
363 | execlp("/bin/csh", "/bin/csh", NULL); | 362 | execlp("/bin/csh", "/bin/csh", NULL); |
364 | else if (stat("/bin/sh", &s) == 0) | 363 | else { |
365 | execlp("/bin/sh", "/bin/sh", NULL); | 364 | struct stat s; |
365 | if (stat("/bin/bash", &s) == 0) | ||
366 | execlp("/bin/bash", "/bin/bash", NULL); | ||
367 | else if (stat("/usr/bin/zsh", &s) == 0) | ||
368 | execlp("/usr/bin/zsh", "/usr/bin/zsh", NULL); | ||
369 | else if (stat("/bin/csh", &s) == 0) | ||
370 | execlp("/bin/csh", "/bin/csh", NULL); | ||
371 | else if (stat("/bin/sh", &s) == 0) | ||
372 | execlp("/bin/sh", "/bin/sh", NULL); | ||
373 | } | ||
366 | 374 | ||
367 | // no shell found, print an error and exit | 375 | // no shell found, print an error and exit |
368 | fprintf(stderr, "Error: no POSIX shell found\n"); | 376 | fprintf(stderr, "Error: no POSIX shell found\n"); |
@@ -389,21 +397,54 @@ void join(pid_t pid, int argc, char **argv, int index) { | |||
389 | } | 397 | } |
390 | } | 398 | } |
391 | 399 | ||
392 | char *arg[5]; | 400 | if (arg_shell_none) { |
393 | arg[0] = "/bin/bash"; | 401 | if (arg_debug) { |
394 | arg[1] = "-c"; | 402 | int i; |
395 | if (arg_debug) | 403 | for (i = cfg.original_program_index; i < cfg.original_argc; i++) { |
396 | printf("Starting %s\n", cfg.command_line); | 404 | if (cfg.original_argv[i] == NULL) |
397 | if (!arg_doubledash) { | 405 | break; |
398 | arg[2] = cfg.command_line; | 406 | printf("execvp argument %d: %s\n", i - cfg.original_program_index, cfg.original_argv[i]); |
399 | arg[3] = NULL; | 407 | } |
400 | } | 408 | } |
401 | else { | 409 | |
402 | arg[2] = "--"; | 410 | if (cfg.original_program_index == 0) { |
403 | arg[3] = cfg.command_line; | 411 | fprintf(stderr, "Error: --shell=none configured, but no program specified\n"); |
404 | arg[4] = NULL; | 412 | exit(1); |
413 | } | ||
414 | |||
415 | if (!arg_command && !arg_quiet) | ||
416 | printf("Child process initialized\n"); | ||
417 | |||
418 | execvp(cfg.original_argv[cfg.original_program_index], &cfg.original_argv[cfg.original_program_index]); | ||
419 | exit(1); | ||
420 | } else { | ||
421 | // choose the shell requested by the user, or use bash as default | ||
422 | char *sh; | ||
423 | if (cfg.shell) | ||
424 | sh = cfg.shell; | ||
425 | else if (arg_zsh) | ||
426 | sh = "/usr/bin/zsh"; | ||
427 | else if (arg_csh) | ||
428 | sh = "/bin/csh"; | ||
429 | else | ||
430 | sh = "/bin/bash"; | ||
431 | |||
432 | char *arg[5]; | ||
433 | arg[0] = sh; | ||
434 | arg[1] = "-c"; | ||
435 | if (arg_debug) | ||
436 | printf("Starting %s\n", cfg.command_line); | ||
437 | if (!arg_doubledash) { | ||
438 | arg[2] = cfg.command_line; | ||
439 | arg[3] = NULL; | ||
440 | } | ||
441 | else { | ||
442 | arg[2] = "--"; | ||
443 | arg[3] = cfg.command_line; | ||
444 | arg[4] = NULL; | ||
445 | } | ||
446 | execvp("/bin/bash", arg); | ||
405 | } | 447 | } |
406 | execvp("/bin/bash", arg); | ||
407 | } | 448 | } |
408 | 449 | ||
409 | // it will never get here!!! | 450 | // it will never get here!!! |