From cc29de3777a4e44cf09b10e5efcc7572400c8e09 Mon Sep 17 00:00:00 2001 From: netblue30 Date: Wed, 4 Nov 2015 07:47:45 -0500 Subject: IBus support --- src/firejail/cpu.c | 2 ++ src/firejail/env.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++ src/firejail/firejail.h | 2 ++ src/firejail/sandbox.c | 25 +++++---------- 4 files changed, 94 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/firejail/cpu.c b/src/firejail/cpu.c index 807dc55a4..343bc8971 100644 --- a/src/firejail/cpu.c +++ b/src/firejail/cpu.c @@ -19,6 +19,8 @@ */ #include "firejail.h" #include +#include +#include // converts a numeric cpu value in the corresponding bit mask static void set_cpu(const char *str) { diff --git a/src/firejail/env.c b/src/firejail/env.c index b4f56a9f0..2bbd2d226 100644 --- a/src/firejail/env.c +++ b/src/firejail/env.c @@ -18,6 +18,10 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "firejail.h" +#include +#include +#include +#include typedef struct env_t { struct env_t *next; @@ -31,6 +35,85 @@ static void env_add(Env *env) { envlist = env; } +// load IBUS env variables +void env_ibus_load(void) { + // check ~/.config/ibus/bus directory + char *dirname; + if (asprintf(&dirname, "%s/.config/ibus/bus", cfg.homedir) == -1) + errExit("asprintf"); + + struct stat s; + if (stat(dirname, &s) == -1) + return; + + // find the file + DIR *dir = opendir(dirname); + if (!dir) { + free(dirname); + return; + } + + struct dirent *entry; + while ((entry = readdir(dir)) != NULL) { + // check the file name ends in "unix-0" + char *ptr = strstr(entry->d_name, "unix-0"); + if (!ptr) + continue; + if (strlen(ptr) != 6) + continue; + + // open the file + char *fname; + if (asprintf(&fname, "%s/%s", dirname, entry->d_name) == -1) + errExit("asprintf"); + FILE *fp = fopen(fname, "r"); + free(fname); + if (!fp) + continue; + + // read the file + const int maxline = 4096; + char buf[maxline]; + while (fgets(buf, maxline, fp)) { + if (strncmp(buf, "IBUS_", 5) != 0) + continue; + char *ptr = strchr(buf, '='); + if (!ptr) + continue; + ptr = strchr(buf, '\n'); + if (ptr) + *ptr = '\0'; + if (arg_debug) + printf("%s\n", buf); + env_store(buf); + } + + fclose(fp); + } + + free(dirname); +} + + +// default sandbox env variables +void env_defaults(void) { + // fix qt 4.8 + if (setenv("QT_X11_NO_MITSHM", "1", 1) < 0) + errExit("setenv"); + if (setenv("container", "firejail", 1) < 0) // LXC sets container=lxc, + errExit("setenv"); + if (arg_zsh && setenv("SHELL", "/usr/bin/zsh", 1) < 0) + errExit("setenv"); + if (arg_csh && setenv("SHELL", "/bin/csh", 1) < 0) + errExit("setenv"); + if (cfg.shell && setenv("SHELL", cfg.shell, 1) < 0) + errExit("setenv"); + // set prompt color to green + //export PS1='\[\e[1;32m\][\u@\h \W]\$\[\e[0m\] ' + if (setenv("PROMPT_COMMAND", "export PS1=\"\\[\\e[1;32m\\][\\u@\\h \\W]\\$\\[\\e[0m\\] \"", 1) < 0) + errExit("setenv"); +} + // parse and store the environment setting void env_store(const char *str) { assert(str); diff --git a/src/firejail/firejail.h b/src/firejail/firejail.h index 29ce77ca4..18fc4baf0 100644 --- a/src/firejail/firejail.h +++ b/src/firejail/firejail.h @@ -424,6 +424,8 @@ void run_no_sandbox(int argc, char **argv); // env.c void env_store(const char *str); void env_apply(void); +void env_defaults(void); +void env_ibus_load(void); // fs_whitelist.c void fs_whitelist(void); diff --git a/src/firejail/sandbox.c b/src/firejail/sandbox.c index 79ed473c0..d0aaa214e 100644 --- a/src/firejail/sandbox.c +++ b/src/firejail/sandbox.c @@ -159,17 +159,19 @@ int sandbox(void* sandbox_arg) { } //**************************** - // netfilter + // netfilter etc. //**************************** if (arg_netfilter && any_bridge_configured()) { // assuming by default the client filter netfilter(arg_netfilter_file); } + // load IBUS env variables + env_ibus_load(); + + // grab a copy of cp command fs_build_cp_command(); - //**************************** // trace pre-install - //**************************** if (arg_trace) fs_trace_preload(); @@ -396,21 +398,8 @@ int sandbox(void* sandbox_arg) { } // set environment - // fix qt 4.8 - if (setenv("QT_X11_NO_MITSHM", "1", 1) < 0) - errExit("setenv"); - if (setenv("container", "firejail", 1) < 0) // LXC sets container=lxc, - errExit("setenv"); - if (arg_zsh && setenv("SHELL", "/usr/bin/zsh", 1) < 0) - errExit("setenv"); - if (arg_csh && setenv("SHELL", "/bin/csh", 1) < 0) - errExit("setenv"); - if (cfg.shell && setenv("SHELL", cfg.shell, 1) < 0) - errExit("setenv"); - // set prompt color to green - //export PS1='\[\e[1;32m\][\u@\h \W]\$\[\e[0m\] ' - if (setenv("PROMPT_COMMAND", "export PS1=\"\\[\\e[1;32m\\][\\u@\\h \\W]\\$\\[\\e[0m\\] \"", 1) < 0) - errExit("setenv"); + env_defaults(); + // set user-supplied environment variables env_apply(); -- cgit v1.2.3-54-g00ecf