aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar netblue30 <netblue30@protonmail.com>2022-06-19 16:14:40 -0400
committerLibravatar netblue30 <netblue30@protonmail.com>2022-06-19 16:14:40 -0400
commit4df89ed447a18d73f24a6fb1ea3d67e84448e09a (patch)
tree23834500cd61e2f102842f7bbd59d7d98974367c
parentshell none set as default (diff)
downloadfirejail-4df89ed447a18d73f24a6fb1ea3d67e84448e09a.tar.gz
firejail-4df89ed447a18d73f24a6fb1ea3d67e84448e09a.tar.zst
firejail-4df89ed447a18d73f24a6fb1ea3d67e84448e09a.zip
shell none set as default (2)
-rw-r--r--src/firejail/main.c30
-rw-r--r--src/firejail/sandbox.c21
2 files changed, 32 insertions, 19 deletions
diff --git a/src/firejail/main.c b/src/firejail/main.c
index 640605a6c..200a510a3 100644
--- a/src/firejail/main.c
+++ b/src/firejail/main.c
@@ -157,6 +157,7 @@ int arg_dbus_log_user = 0;
157int arg_dbus_log_system = 0; 157int arg_dbus_log_system = 0;
158int arg_tab = 0; 158int arg_tab = 0;
159int login_shell = 0; 159int login_shell = 0;
160int just_run_the_shell = 0;
160 161
161int parent_to_child_fds[2]; 162int parent_to_child_fds[2];
162int child_to_parent_fds[2]; 163int child_to_parent_fds[2];
@@ -795,15 +796,10 @@ static void run_cmd_and_exit(int i, int argc, char **argv) {
795 if (checkcfg(CFG_JOIN) || getuid() == 0) { 796 if (checkcfg(CFG_JOIN) || getuid() == 0) {
796 logargs(argc, argv); 797 logargs(argc, argv);
797 798
798 if (arg_shell_none) { 799 if (argc <= (i+1))
799 if (argc <= (i+1)) { 800 just_run_the_shell = 1;
800 fprintf(stderr, "Error: --shell=none set, but no command specified\n"); 801 cfg.original_program_index = i + 1;
801 exit(1); 802 if (!cfg.shell)
802 }
803 cfg.original_program_index = i + 1;
804 }
805
806 if (!cfg.shell && !arg_shell_none)
807 cfg.shell = cfg.usershell; 803 cfg.shell = cfg.usershell;
808 804
809 // join sandbox by pid or by name 805 // join sandbox by pid or by name
@@ -821,19 +817,17 @@ static void run_cmd_and_exit(int i, int argc, char **argv) {
821 if (checkcfg(CFG_JOIN) || getuid() == 0) { 817 if (checkcfg(CFG_JOIN) || getuid() == 0) {
822 logargs(argc, argv); 818 logargs(argc, argv);
823 819
824 if (arg_shell_none) { 820 if (argc <= (i+1))
825 if (argc <= (i+1)) { 821 just_run_the_shell = 1;
826 fprintf(stderr, "Error: --shell=none set, but no command specified\n"); 822 cfg.original_program_index = i + 1;
827 exit(1); 823
828 } 824 if (!cfg.shell)
829 cfg.original_program_index = i + 1; 825 cfg.shell = cfg.usershell;
830 }
831 826
827printf("***** %d\n", just_run_the_shell);
832 // try to join by name only 828 // try to join by name only
833 pid_t pid; 829 pid_t pid;
834 if (!read_pid(argv[i] + 16, &pid)) { 830 if (!read_pid(argv[i] + 16, &pid)) {
835 if (!cfg.shell && !arg_shell_none)
836 cfg.shell = cfg.usershell;
837 831
838 join(pid, argc, argv, i + 1); 832 join(pid, argc, argv, i + 1);
839 exit(0); 833 exit(0);
diff --git a/src/firejail/sandbox.c b/src/firejail/sandbox.c
index 4ad9eb678..7f74635ec 100644
--- a/src/firejail/sandbox.c
+++ b/src/firejail/sandbox.c
@@ -51,6 +51,7 @@
51#endif 51#endif
52 52
53static int force_nonewprivs = 0; 53static int force_nonewprivs = 0;
54extern int just_run_the_shell;
54 55
55static int monitored_pid = 0; 56static int monitored_pid = 0;
56static void sandbox_handler(int sig){ 57static void sandbox_handler(int sig){
@@ -506,10 +507,28 @@ void start_application(int no_sandbox, int fd, char *set_sandbox_status) {
506 printf("LD_PRELOAD=%s\n", getenv("LD_PRELOAD")); 507 printf("LD_PRELOAD=%s\n", getenv("LD_PRELOAD"));
507 } 508 }
508 509
510 if (just_run_the_shell) {
511 char *arg[2];
512 arg[0] = cfg.usershell;
513 arg[1] = NULL;
514
515 if (!arg_command && !arg_quiet)
516 print_time();
517
518 __gcov_dump();
519
520 seccomp_install_filters();
521
522 if (set_sandbox_status)
523 *set_sandbox_status = SANDBOX_DONE;
524 execvp(arg[0], arg);
525
526
527 }
509 //**************************************** 528 //****************************************
510 // start the program without using a shell 529 // start the program without using a shell
511 //**************************************** 530 //****************************************
512 if (arg_shell_none) { 531 else if (arg_shell_none) {
513 if (arg_debug) { 532 if (arg_debug) {
514 int i; 533 int i;
515 for (i = cfg.original_program_index; i < cfg.original_argc; i++) { 534 for (i = cfg.original_program_index; i < cfg.original_argc; i++) {