diff options
Diffstat (limited to 'src/firejail/util.c')
-rw-r--r-- | src/firejail/util.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/firejail/util.c b/src/firejail/util.c index 4b2e09953..4384c2b0b 100644 --- a/src/firejail/util.c +++ b/src/firejail/util.c | |||
@@ -696,3 +696,37 @@ void flush_stdin(void) { | |||
696 | } | 696 | } |
697 | } | 697 | } |
698 | 698 | ||
699 | void create_empty_dir_as_root(const char *dir, mode_t mode) { | ||
700 | assert(dir); | ||
701 | |||
702 | struct stat s; | ||
703 | if (stat(dir, &s)) { | ||
704 | if (arg_debug) | ||
705 | printf("Creating empty %s directory\n", dir); | ||
706 | if (mkdir(dir, mode) == -1) | ||
707 | errExit("mkdir"); | ||
708 | if (chmod(dir, mode) == -1) | ||
709 | errExit("chmod"); | ||
710 | ASSERT_PERMS(dir, 0, 0, mode); | ||
711 | } | ||
712 | |||
713 | } | ||
714 | |||
715 | void create_empty_file_as_root(const char *fname, mode_t mode) { | ||
716 | assert(fname); | ||
717 | struct stat s; | ||
718 | |||
719 | if (stat(fname, &s)) { | ||
720 | if (arg_debug) | ||
721 | printf("Creating empty %s file\n", fname); | ||
722 | |||
723 | /* coverity[toctou] */ | ||
724 | FILE *fp = fopen(fname, "w"); | ||
725 | if (!fp) | ||
726 | errExit("fopen"); | ||
727 | |||
728 | SET_PERMS_STREAM(fp, 0, 0, S_IRUSR); | ||
729 | fclose(fp); | ||
730 | } | ||
731 | } | ||
732 | |||