diff options
author | 2016-07-27 16:21:13 -0400 | |
---|---|---|
committer | 2016-07-27 16:21:13 -0400 | |
commit | ebaada70b8bfa8ea12ecee44e793b5bf67c56d78 (patch) | |
tree | 5de76bc403e5d940d513ea264c02536f05c3820d /src | |
parent | --join fixes (diff) | |
parent | Merge pull request #652 from manevich/patch-3 (diff) | |
download | firejail-ebaada70b8bfa8ea12ecee44e793b5bf67c56d78.tar.gz firejail-ebaada70b8bfa8ea12ecee44e793b5bf67c56d78.tar.zst firejail-ebaada70b8bfa8ea12ecee44e793b5bf67c56d78.zip |
Merge branch 'master' of https://github.com/netblue30/firejail
Diffstat (limited to 'src')
-rw-r--r-- | src/firejail/join.c | 99 |
1 files changed, 76 insertions, 23 deletions
diff --git a/src/firejail/join.c b/src/firejail/join.c index 47d31669d..c14108986 100644 --- a/src/firejail/join.c +++ b/src/firejail/join.c | |||
@@ -23,6 +23,7 @@ | |||
23 | #include <fcntl.h> | 23 | #include <fcntl.h> |
24 | #include <unistd.h> | 24 | #include <unistd.h> |
25 | #include <sys/prctl.h> | 25 | #include <sys/prctl.h> |
26 | #include <errno.h> | ||
26 | 27 | ||
27 | static int apply_caps = 0; | 28 | static int apply_caps = 0; |
28 | static uint64_t caps = 0; | 29 | static uint64_t caps = 0; |
@@ -338,19 +339,38 @@ void join(pid_t pid, int argc, char **argv, int index) { | |||
338 | if (setenv("PROMPT_COMMAND", "export PS1=\"\\[\\e[1;32m\\][\\u@\\h \\W]\\$\\[\\e[0m\\] \"", 1) < 0) | 339 | if (setenv("PROMPT_COMMAND", "export PS1=\"\\[\\e[1;32m\\][\\u@\\h \\W]\\$\\[\\e[0m\\] \"", 1) < 0) |
339 | errExit("setenv"); | 340 | errExit("setenv"); |
340 | 341 | ||
342 | // set nice | ||
343 | if (arg_nice) { | ||
344 | errno = 0; | ||
345 | int rv = nice(cfg.nice); | ||
346 | (void) rv; | ||
347 | if (errno) { | ||
348 | fprintf(stderr, "Warning: cannot set nice value\n"); | ||
349 | errno = 0; | ||
350 | } | ||
351 | } | ||
352 | |||
341 | // run cmdline trough /bin/bash | 353 | // run cmdline trough /bin/bash |
342 | if (cfg.command_line == NULL) { | 354 | if (cfg.command_line == NULL) { |
343 | struct stat s; | ||
344 | 355 | ||
345 | // replace the process with a shell | 356 | // replace the process with a shell |
346 | if (stat("/bin/bash", &s) == 0) | 357 | if (cfg.shell) |
347 | execlp("/bin/bash", "/bin/bash", NULL); | 358 | execlp(cfg.shell, cfg.shell, NULL); |
348 | else if (stat("/usr/bin/zsh", &s) == 0) | 359 | else if (arg_zsh) |
349 | execlp("/usr/bin/zsh", "/usr/bin/zsh", NULL); | 360 | execlp("/usr/bin/zsh", "/usr/bin/zsh", NULL); |
350 | else if (stat("/bin/csh", &s) == 0) | 361 | else if (arg_csh) |
351 | execlp("/bin/csh", "/bin/csh", NULL); | 362 | execlp("/bin/csh", "/bin/csh", NULL); |
352 | else if (stat("/bin/sh", &s) == 0) | 363 | else { |
353 | 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 | } | ||
354 | 374 | ||
355 | // no shell found, print an error and exit | 375 | // no shell found, print an error and exit |
356 | fprintf(stderr, "Error: no POSIX shell found\n"); | 376 | fprintf(stderr, "Error: no POSIX shell found\n"); |
@@ -377,21 +397,54 @@ void join(pid_t pid, int argc, char **argv, int index) { | |||
377 | } | 397 | } |
378 | } | 398 | } |
379 | 399 | ||
380 | char *arg[5]; | 400 | if (arg_shell_none) { |
381 | arg[0] = "/bin/bash"; | 401 | if (arg_debug) { |
382 | arg[1] = "-c"; | 402 | int i; |
383 | if (arg_debug) | 403 | for (i = cfg.original_program_index; i < cfg.original_argc; i++) { |
384 | printf("Starting %s\n", cfg.command_line); | 404 | if (cfg.original_argv[i] == NULL) |
385 | if (!arg_doubledash) { | 405 | break; |
386 | arg[2] = cfg.command_line; | 406 | printf("execvp argument %d: %s\n", i - cfg.original_program_index, cfg.original_argv[i]); |
387 | arg[3] = NULL; | 407 | } |
388 | } | 408 | } |
389 | else { | 409 | |
390 | arg[2] = "--"; | 410 | if (cfg.original_program_index == 0) { |
391 | arg[3] = cfg.command_line; | 411 | fprintf(stderr, "Error: --shell=none configured, but no program specified\n"); |
392 | 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); | ||
393 | } | 447 | } |
394 | execvp("/bin/bash", arg); | ||
395 | } | 448 | } |
396 | 449 | ||
397 | // it will never get here!!! | 450 | // it will never get here!!! |