diff options
Diffstat (limited to 'src/firejail/fs.c')
-rw-r--r-- | src/firejail/fs.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/firejail/fs.c b/src/firejail/fs.c index 484b99537..63ffa8bff 100644 --- a/src/firejail/fs.c +++ b/src/firejail/fs.c | |||
@@ -814,6 +814,44 @@ void fs_basic_fs(void) { | |||
814 | } | 814 | } |
815 | 815 | ||
816 | 816 | ||
817 | |||
818 | char *fs_check_overlay_dir(const char *subdirname, int allow_reuse) { | ||
819 | // create ~/.firejail directory | ||
820 | struct stat s; | ||
821 | char *dirname; | ||
822 | if (asprintf(&dirname, "%s/.firejail", cfg.homedir) == -1) | ||
823 | errExit("asprintf"); | ||
824 | if (stat(dirname, &s) == -1) { | ||
825 | /* coverity[toctou] */ | ||
826 | if (mkdir(dirname, 0700)) | ||
827 | errExit("mkdir"); | ||
828 | if (chown(dirname, getuid(), getgid()) < 0) | ||
829 | errExit("chown"); | ||
830 | if (chmod(dirname, 0700) < 0) | ||
831 | errExit("chmod"); | ||
832 | } | ||
833 | else if (is_link(dirname)) { | ||
834 | fprintf(stderr, "Error: invalid ~/.firejail directory\n"); | ||
835 | exit(1); | ||
836 | } | ||
837 | |||
838 | free(dirname); | ||
839 | |||
840 | // check overlay directory | ||
841 | if (asprintf(&dirname, "%s/.firejail/%s", cfg.homedir, subdirname) == -1) | ||
842 | errExit("asprintf"); | ||
843 | if (allow_reuse == 0) { | ||
844 | if (stat(dirname, &s) == 0) { | ||
845 | fprintf(stderr, "Error: overlay directory already exists: %s\n", dirname); | ||
846 | exit(1); | ||
847 | } | ||
848 | } | ||
849 | |||
850 | return dirname; | ||
851 | } | ||
852 | |||
853 | |||
854 | |||
817 | // mount overlayfs on top of / directory | 855 | // mount overlayfs on top of / directory |
818 | // mounting an overlay and chrooting into it: | 856 | // mounting an overlay and chrooting into it: |
819 | // | 857 | // |