diff options
Diffstat (limited to 'src/firejail/fs_var.c')
-rw-r--r-- | src/firejail/fs_var.c | 26 |
1 files changed, 8 insertions, 18 deletions
diff --git a/src/firejail/fs_var.c b/src/firejail/fs_var.c index 588090c00..9f554f662 100644 --- a/src/firejail/fs_var.c +++ b/src/firejail/fs_var.c | |||
@@ -240,7 +240,7 @@ void dbg_test_dir(const char *dir) { | |||
240 | if (is_dir(dir)) | 240 | if (is_dir(dir)) |
241 | printf("%s is a directory\n", dir); | 241 | printf("%s is a directory\n", dir); |
242 | if (is_link(dir)) { | 242 | if (is_link(dir)) { |
243 | char *lnk = get_link(dir); | 243 | char *lnk = realpath(dir, NULL); |
244 | if (lnk) { | 244 | if (lnk) { |
245 | printf("%s is a symbolic link to %s\n", dir, lnk); | 245 | printf("%s is a symbolic link to %s\n", dir, lnk); |
246 | free(lnk); | 246 | free(lnk); |
@@ -259,30 +259,20 @@ void fs_var_lock(void) { | |||
259 | errExit("mounting /lock"); | 259 | errExit("mounting /lock"); |
260 | } | 260 | } |
261 | else { | 261 | else { |
262 | char *lnk = get_link("/var/lock"); | 262 | char *lnk = realpath("/var/lock", NULL); |
263 | if (lnk) { | 263 | if (lnk) { |
264 | // convert a link such as "../shm" into "/shm" | 264 | if (!is_dir(lnk)) { |
265 | char *lnk2 = lnk; | ||
266 | int cnt = 0; | ||
267 | while (strncmp(lnk2, "../", 3) == 0) { | ||
268 | cnt++; | ||
269 | lnk2 = lnk2 + 3; | ||
270 | } | ||
271 | if (cnt != 0) | ||
272 | lnk2 = lnk + (cnt - 1) * 3 + 2; | ||
273 | |||
274 | if (!is_dir(lnk2)) { | ||
275 | // create directory | 265 | // create directory |
276 | if (mkdir(lnk2, S_IRWXU|S_IRWXG|S_IRWXO)) | 266 | if (mkdir(lnk, S_IRWXU|S_IRWXG|S_IRWXO)) |
277 | errExit("mkdir"); | 267 | errExit("mkdir"); |
278 | if (chown(lnk2, 0, 0)) | 268 | if (chown(lnk, 0, 0)) |
279 | errExit("chown"); | 269 | errExit("chown"); |
280 | if (chmod(lnk2, S_IRWXU|S_IRWXG|S_IRWXO)) | 270 | if (chmod(lnk, S_IRWXU|S_IRWXG|S_IRWXO)) |
281 | errExit("chmod"); | 271 | errExit("chmod"); |
282 | } | 272 | } |
283 | if (arg_debug) | 273 | if (arg_debug) |
284 | printf("Mounting tmpfs on %s on behalf of /var/lock\n", lnk2); | 274 | printf("Mounting tmpfs on %s on behalf of /var/lock\n", lnk); |
285 | if (mount("tmpfs", lnk2, "tmpfs", MS_NOSUID | MS_STRICTATIME | MS_REC, "mode=777,gid=0") < 0) | 275 | if (mount("tmpfs", lnk, "tmpfs", MS_NOSUID | MS_STRICTATIME | MS_REC, "mode=777,gid=0") < 0) |
286 | errExit("mounting /var/lock"); | 276 | errExit("mounting /var/lock"); |
287 | free(lnk); | 277 | free(lnk); |
288 | } | 278 | } |