aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatar Reiner Herrmann <reiner@reiner-h.de>2016-07-30 17:58:25 +0200
committerLibravatar Reiner Herrmann <reiner@reiner-h.de>2016-07-30 17:58:45 +0200
commit0657c20377d6f8d80f143e9c6a336601c8bbd2e2 (patch)
tree9a64c53de121fb14f64cc0db850fd8397883776b /src
parentfixes (diff)
downloadfirejail-0657c20377d6f8d80f143e9c6a336601c8bbd2e2.tar.gz
firejail-0657c20377d6f8d80f143e9c6a336601c8bbd2e2.tar.zst
firejail-0657c20377d6f8d80f143e9c6a336601c8bbd2e2.zip
Allow recursive mkdir (Closes #305)
Diffstat (limited to 'src')
-rw-r--r--src/firejail/fs_mkdir.c39
-rw-r--r--src/man/firejail-profile.txt8
2 files changed, 36 insertions, 11 deletions
diff --git a/src/firejail/fs_mkdir.c b/src/firejail/fs_mkdir.c
index 50bcc613b..5bc2df2cc 100644
--- a/src/firejail/fs_mkdir.c
+++ b/src/firejail/fs_mkdir.c
@@ -22,8 +22,38 @@
22#include <sys/stat.h> 22#include <sys/stat.h>
23#include <unistd.h> 23#include <unistd.h>
24#include <grp.h> 24#include <grp.h>
25 #include <sys/wait.h> 25#include <sys/wait.h>
26 26#include <string.h>
27
28static void mkdir_recursive(char *path) {
29 char *subdir = NULL;
30 struct stat s;
31
32 if (chdir("/")) {
33 fprintf(stderr, "Error: can't chdir to /");
34 return;
35 }
36
37 subdir = strtok(path, "/");
38 while(subdir) {
39 if (stat(subdir, &s) == -1) {
40 if (mkdir(subdir, 0700) == -1) {
41 fprintf(stderr, "Warning: cannot create %s directory\n", subdir);
42 return;
43 }
44 } else if (!S_ISDIR(s.st_mode)) {
45 fprintf(stderr, "Warning: '%s' exists, but is no directory\n", subdir);
46 return;
47 }
48 if (chdir(subdir)) {
49 fprintf(stderr, "Error: can't chdir to %s", subdir);
50 return;
51 }
52
53 subdir = strtok(NULL, "/");
54 }
55}
56
27void fs_mkdir(const char *name) { 57void fs_mkdir(const char *name) {
28 EUID_ASSERT(); 58 EUID_ASSERT();
29 59
@@ -50,8 +80,7 @@ void fs_mkdir(const char *name) {
50 drop_privs(0); 80 drop_privs(0);
51 81
52 // create directory 82 // create directory
53 if (mkdir(expanded, 0700) == -1) 83 mkdir_recursive(expanded);
54 fprintf(stderr, "Warning: cannot create %s directory\n", expanded);
55 exit(0); 84 exit(0);
56 } 85 }
57 // wait for the child to finish 86 // wait for the child to finish
@@ -101,4 +130,4 @@ void fs_mkfile(const char *name) {
101 130
102doexit: 131doexit:
103 free(expanded); 132 free(expanded);
104} \ No newline at end of file 133}
diff --git a/src/man/firejail-profile.txt b/src/man/firejail-profile.txt
index 504842a9e..7e33a6b45 100644
--- a/src/man/firejail-profile.txt
+++ b/src/man/firejail-profile.txt
@@ -136,7 +136,7 @@ The directory is created if it doesn't already exist.
136.br 136.br
137Use this command for whitelisted directories you need to preserve 137Use this command for whitelisted directories you need to preserve
138when the sandbox is closed. Without it, the application will create the directory, and the directory 138when the sandbox is closed. Without it, the application will create the directory, and the directory
139will be deleted when the sandbox is closed. Subdirectories also need to be created using mkdir. Example from 139will be deleted when the sandbox is closed. Subdirectories are recursively created. Example from
140firefox profile: 140firefox profile:
141.br 141.br
142 142
@@ -145,17 +145,13 @@ mkdir ~/.mozilla
145.br 145.br
146whitelist ~/.mozilla 146whitelist ~/.mozilla
147.br 147.br
148mkdir ~/.cache
149.br
150mkdir ~/.cache/mozilla
151.br
152mkdir ~/.cache/mozilla/firefox 148mkdir ~/.cache/mozilla/firefox
153.br 149.br
154whitelist ~/.cache/mozilla/firefox 150whitelist ~/.cache/mozilla/firefox
155.TP 151.TP
156\fBmkfile file 152\fBmkfile file
157Similar to mkdir, this command creates a file in user home before the sandbox is started. 153Similar to mkdir, this command creates a file in user home before the sandbox is started.
158The file is created if it doesn't already exist. 154The file is created if it doesn't already exist, but it's target directory has to exist.
159.TP 155.TP
160\fBnoexec file_or_directory 156\fBnoexec file_or_directory
161Remount the file or the directory noexec, nodev and nosuid. 157Remount the file or the directory noexec, nodev and nosuid.