From 9f5dfa5964f82fa03b5b86c705b1f599c9887316 Mon Sep 17 00:00:00 2001 From: Aleksey Manevich Date: Sun, 14 Aug 2016 13:33:22 +0300 Subject: join fixes --- src/firejail/firejail.h | 2 -- src/firejail/fs_home.c | 5 +++-- src/firejail/join.c | 18 +++--------------- src/firejail/main.c | 25 +++++++++++++------------ 4 files changed, 19 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/firejail/firejail.h b/src/firejail/firejail.h index 0de2a354d..c45b324fc 100644 --- a/src/firejail/firejail.h +++ b/src/firejail/firejail.h @@ -222,8 +222,6 @@ extern int arg_nonetwork; // --net=none extern int arg_command; // -c extern int arg_overlay; // overlay option extern int arg_overlay_keep; // place overlay diff directory in ~/.firejail -extern int arg_zsh; // use zsh as default shell -extern int arg_csh; // use csh as default shell extern int arg_seccomp; // enable default seccomp filter diff --git a/src/firejail/fs_home.c b/src/firejail/fs_home.c index c1e983c16..d328d5f1c 100644 --- a/src/firejail/fs_home.c +++ b/src/firejail/fs_home.c @@ -32,8 +32,9 @@ static void skel(const char *homedir, uid_t u, gid_t g) { char *fname; + // zsh - if (arg_zsh) { + if (!arg_shell_none && (strcmp(cfg.shell,"/usr/bin/zsh") == 0 || strcmp(cfg.shell,"/bin/zsh") == 0)) { // copy skel files if (asprintf(&fname, "%s/.zshrc", homedir) == -1) errExit("asprintf"); @@ -63,7 +64,7 @@ static void skel(const char *homedir, uid_t u, gid_t g) { free(fname); } // csh - else if (arg_csh) { + else if (!arg_shell_none && strcmp(cfg.shell,"/bin/csh") == 0) { // copy skel files if (asprintf(&fname, "%s/.cshrc", homedir) == -1) errExit("asprintf"); diff --git a/src/firejail/join.c b/src/firejail/join.c index 80ed1dc51..632715fea 100644 --- a/src/firejail/join.c +++ b/src/firejail/join.c @@ -332,13 +332,7 @@ void join(pid_t pid, int argc, char **argv, int index) { // run cmdline trough shell if (cfg.command_line == NULL) { - cfg.shell = guess_shell(); - if (!cfg.shell) { - fprintf(stderr, "Error: unable to guess your shell, please set explicitly by using --shell option.\n"); - exit(1); - } - if (arg_debug) - printf("Autoselecting %s as shell\n", cfg.shell); + assert(cfg.shell); // replace the process with a shell execlp(cfg.shell, cfg.shell, NULL); @@ -387,14 +381,8 @@ void join(pid_t pid, int argc, char **argv, int index) { execvp(cfg.original_argv[cfg.original_program_index], &cfg.original_argv[cfg.original_program_index]); exit(1); } else { -// assert(cfg.shell); - cfg.shell = guess_shell(); - if (!cfg.shell) { - fprintf(stderr, "Error: unable to guess your shell, please set explicitly by using --shell option.\n"); - exit(1); - } - if (arg_debug) - printf("Autoselecting %s as shell\n", cfg.shell); + assert(cfg.shell); + char *arg[5]; arg[0] = cfg.shell; arg[1] = "-c"; diff --git a/src/firejail/main.c b/src/firejail/main.c index 87c8389ad..e0f2a676c 100644 --- a/src/firejail/main.c +++ b/src/firejail/main.c @@ -60,8 +60,6 @@ int arg_nonetwork = 0; // --net=none int arg_command = 0; // -c int arg_overlay = 0; // overlay option int arg_overlay_keep = 0; // place overlay diff directory in ~/.firejail -int arg_zsh = 0; // use zsh as default shell -int arg_csh = 0; // use csh as default shell int arg_seccomp = 0; // enable default seccomp filter @@ -565,7 +563,18 @@ static void run_cmd_and_exit(int i, int argc, char **argv) { #endif else if (strncmp(argv[i], "--join=", 7) == 0) { logargs(argc, argv); - + + if (arg_shell_none) { + if (argc <= (i+1)) { + fprintf(stderr, "Error: --shell=none set, but no command specified\n"); + exit(1); + } + cfg.original_program_index = i + 1; + } + + if (!cfg.shell && !arg_shell_none) + cfg.shell = guess_shell(); + // join sandbox by pid or by name pid_t pid; if (read_pid(argv[i] + 7, &pid) == 0) @@ -573,6 +582,7 @@ static void run_cmd_and_exit(int i, int argc, char **argv) { else join_name(argv[i] + 7, argc, argv, i + 1); exit(0); + } #ifdef HAVE_NETWORK else if (strncmp(argv[i], "--join-network=", 15) == 0) { @@ -725,13 +735,6 @@ char *guess_shell(void) { i++; } - - // FIXME get rid of arg_csh and arg_zsh completely - if (strcmp(shell,"/bin/csh")) - arg_csh = 1; - if (strcmp(shell,"/usr/bin/zsh") || strcmp(shell,"/bin/zsh")) - arg_zsh = 1; - return shell; } @@ -1887,7 +1890,6 @@ int main(int argc, char **argv) { fprintf(stderr, "Error: only one default user shell can be specified\n"); return 1; } - arg_csh = 1; cfg.shell = "/bin/csh"; } else if (strcmp(argv[i], "--zsh") == 0) { @@ -1899,7 +1901,6 @@ int main(int argc, char **argv) { fprintf(stderr, "Error: only one default user shell can be specified\n"); return 1; } - arg_zsh = 1; cfg.shell = "/bin/zsh"; } else if (strcmp(argv[i], "--shell=none") == 0) { -- cgit v1.2.3-70-g09d2