aboutsummaryrefslogtreecommitdiffstats
path: root/src/firejail/env.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/firejail/env.c')
-rw-r--r--src/firejail/env.c83
1 files changed, 55 insertions, 28 deletions
diff --git a/src/firejail/env.c b/src/firejail/env.c
index 54a6b0036..a02c67ae1 100644
--- a/src/firejail/env.c
+++ b/src/firejail/env.c
@@ -27,12 +27,27 @@ typedef struct env_t {
27 struct env_t *next; 27 struct env_t *next;
28 char *name; 28 char *name;
29 char *value; 29 char *value;
30 ENV_OP op;
30} Env; 31} Env;
31static Env *envlist = NULL; 32static Env *envlist = NULL;
32 33
33static void env_add(Env *env) { 34static void env_add(Env *env) {
34 env->next = envlist; 35 env->next = NULL;
35 envlist = env; 36
37 // add the new entry at the end of the list
38 if (envlist == NULL) {
39 envlist = env;
40 return;
41 }
42
43 Env *ptr = envlist;
44 while (1) {
45 if (ptr->next == NULL) {
46 ptr->next = env;
47 break;
48 }
49 ptr = ptr->next;
50 }
36} 51}
37 52
38// load IBUS env variables 53// load IBUS env variables
@@ -87,7 +102,7 @@ void env_ibus_load(void) {
87 if (arg_debug) 102 if (arg_debug)
88 printf("%s\n", buf); 103 printf("%s\n", buf);
89 EUID_USER(); 104 EUID_USER();
90 env_store(buf); 105 env_store(buf, SETENV);
91 EUID_ROOT(); 106 EUID_ROOT();
92 } 107 }
93 108
@@ -104,29 +119,31 @@ void env_defaults(void) {
104 // fix qt 4.8 119 // fix qt 4.8
105 if (setenv("QT_X11_NO_MITSHM", "1", 1) < 0) 120 if (setenv("QT_X11_NO_MITSHM", "1", 1) < 0)
106 errExit("setenv"); 121 errExit("setenv");
122// if (setenv("MOZ_NO_REMOTE, "1", 1) < 0)
123// errExit("setenv");
107 if (setenv("container", "firejail", 1) < 0) // LXC sets container=lxc, 124 if (setenv("container", "firejail", 1) < 0) // LXC sets container=lxc,
108 errExit("setenv"); 125 errExit("setenv");
109 if (arg_zsh && setenv("SHELL", "/usr/bin/zsh", 1) < 0) 126 if (!cfg.shell)
110 errExit("setenv"); 127 cfg.shell = guess_shell();
111 if (arg_csh && setenv("SHELL", "/bin/csh", 1) < 0)
112 errExit("setenv");
113 if (cfg.shell && setenv("SHELL", cfg.shell, 1) < 0) 128 if (cfg.shell && setenv("SHELL", cfg.shell, 1) < 0)
114 errExit("setenv"); 129 errExit("setenv");
130
115 // set prompt color to green 131 // set prompt color to green
116 //export PS1='\[\e[1;32m\][\u@\h \W]\$\[\e[0m\] ' 132 char *prompt = getenv("FIREJAIL_PROMPT");
117 if (setenv("PROMPT_COMMAND", "export PS1=\"\\[\\e[1;32m\\][\\u@\\h \\W]\\$\\[\\e[0m\\] \"", 1) < 0) 133 if (prompt && strcmp(prompt, "yes") == 0) {
118 errExit("setenv"); 134 //export PS1='\[\e[1;32m\][\u@\h \W]\$\[\e[0m\] '
135 if (setenv("PROMPT_COMMAND", "export PS1=\"\\[\\e[1;32m\\][\\u@\\h \\W]\\$\\[\\e[0m\\] \"", 1) < 0)
136 errExit("setenv");
137 }
119 138
120 // build the window title and set it 139 // set the window title
121 char *title; 140 if (!arg_quiet)
122 if (asprintf(&title, "\033]0;firejail %s\007\n", cfg.window_title) == -1) 141 printf("\033]0;firejail %s\007", cfg.window_title);
123 errExit("asprintf"); 142 fflush(0);
124 printf("%s", title);
125 free(title);
126} 143}
127 144
128// parse and store the environment setting 145// parse and store the environment setting
129void env_store(const char *str) { 146void env_store(const char *str, ENV_OP op) {
130 EUID_ASSERT(); 147 EUID_ASSERT();
131 assert(str); 148 assert(str);
132 149
@@ -134,11 +151,13 @@ void env_store(const char *str) {
134 if (*str == '\0') 151 if (*str == '\0')
135 goto errexit; 152 goto errexit;
136 char *ptr = strchr(str, '='); 153 char *ptr = strchr(str, '=');
137 if (!ptr) 154 if (op == SETENV) {
138 goto errexit; 155 if (!ptr)
139 ptr++; 156 goto errexit;
140 if (*ptr == '\0') 157 ptr++;
141 goto errexit; 158 if (*ptr == '\0')
159 goto errexit;
160 }
142 161
143 // build list entry 162 // build list entry
144 Env *env = malloc(sizeof(Env)); 163 Env *env = malloc(sizeof(Env));
@@ -148,10 +167,13 @@ void env_store(const char *str) {
148 env->name = strdup(str); 167 env->name = strdup(str);
149 if (env->name == NULL) 168 if (env->name == NULL)
150 errExit("strdup"); 169 errExit("strdup");
151 char *ptr2 = strchr(env->name, '='); 170 if (op == SETENV) {
152 assert(ptr2); 171 char *ptr2 = strchr(env->name, '=');
153 *ptr2 = '\0'; 172 assert(ptr2);
154 env->value = ptr2 + 1; 173 *ptr2 = '\0';
174 env->value = ptr2 + 1;
175 }
176 env->op = op;
155 177
156 // add entry to the list 178 // add entry to the list
157 env_add(env); 179 env_add(env);
@@ -167,8 +189,13 @@ void env_apply(void) {
167 Env *env = envlist; 189 Env *env = envlist;
168 190
169 while (env) { 191 while (env) {
170 if (setenv(env->name, env->value, 1) < 0) 192 if (env->op == SETENV) {
171 errExit("setenv"); 193 if (setenv(env->name, env->value, 1) < 0)
194 errExit("setenv");
195 }
196 else if (env->op == RMENV) {
197 unsetenv(env->name);
198 }
172 env = env->next; 199 env = env->next;
173 } 200 }
174} 201}