diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/firejail/ls.c | 38 |
1 files changed, 13 insertions, 25 deletions
diff --git a/src/firejail/ls.c b/src/firejail/ls.c index ed50934a8..1a65c9ff0 100644 --- a/src/firejail/ls.c +++ b/src/firejail/ls.c | |||
@@ -299,35 +299,23 @@ void sandboxfs(int op, pid_t pid, const char *path1, const char *path2) { | |||
299 | errExit("asprintf"); | 299 | errExit("asprintf"); |
300 | 300 | ||
301 | if (op == SANDBOX_FS_LS || op == SANDBOX_FS_CAT) { | 301 | if (op == SANDBOX_FS_LS || op == SANDBOX_FS_CAT) { |
302 | pid_t child = fork(); | 302 | EUID_ROOT(); |
303 | if (child < 0) | 303 | // chroot |
304 | errExit("fork"); | 304 | if (chroot(rootdir) < 0) |
305 | if (child == 0) { | 305 | errExit("chroot"); |
306 | EUID_ROOT(); | 306 | if (chdir("/") < 0) |
307 | // chroot | 307 | errExit("chdir"); |
308 | if (chroot(rootdir) < 0) | ||
309 | errExit("chroot"); | ||
310 | if (chdir("/") < 0) | ||
311 | errExit("chdir"); | ||
312 | 308 | ||
313 | // drop privileges | 309 | // drop privileges |
314 | drop_privs(0); | 310 | drop_privs(0); |
315 | 311 | ||
316 | if (op == SANDBOX_FS_LS) | 312 | if (op == SANDBOX_FS_LS) |
317 | ls(fname1); | 313 | ls(fname1); |
318 | else | 314 | else |
319 | cat(fname1); | 315 | cat(fname1); |
320 | #ifdef HAVE_GCOV | 316 | #ifdef HAVE_GCOV |
321 | __gcov_flush(); | 317 | __gcov_flush(); |
322 | #endif | 318 | #endif |
323 | _exit(0); | ||
324 | } | ||
325 | // wait for the child to finish | ||
326 | int status = 0; | ||
327 | waitpid(child, &status, 0); | ||
328 | if (WIFEXITED(status) && WEXITSTATUS(status) == 0); | ||
329 | else | ||
330 | exit(1); | ||
331 | } | 319 | } |
332 | 320 | ||
333 | // get file from sandbox and store it in the current directory | 321 | // get file from sandbox and store it in the current directory |