diff options
author | 2016-11-12 09:52:53 -0500 | |
---|---|---|
committer | 2016-11-12 09:52:53 -0500 | |
commit | 3ed5918832344db694d094eefbe2189fd847345d (patch) | |
tree | bdc2d85eb7e31c0eebf1a572a6996168f1b74b50 /src/firejail/util.c | |
parent | testing (diff) | |
download | firejail-3ed5918832344db694d094eefbe2189fd847345d.tar.gz firejail-3ed5918832344db694d094eefbe2189fd847345d.tar.zst firejail-3ed5918832344db694d094eefbe2189fd847345d.zip |
set_perms cleanup
Diffstat (limited to 'src/firejail/util.c')
-rw-r--r-- | src/firejail/util.c | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/firejail/util.c b/src/firejail/util.c index a7712441e..3424d8ab6 100644 --- a/src/firejail/util.c +++ b/src/firejail/util.c | |||
@@ -100,10 +100,8 @@ int mkpath_as_root(const char* path) { | |||
100 | } | 100 | } |
101 | } | 101 | } |
102 | else { | 102 | else { |
103 | if (chmod(file_path, 0755) == -1) | 103 | if (set_perms(file_path, 0, 0, 0755)) |
104 | errExit("chmod"); | 104 | errExit("set_perms"); |
105 | if (chown(file_path, 0, 0) == -1) | ||
106 | errExit("chown"); | ||
107 | done = 1; | 105 | done = 1; |
108 | } | 106 | } |
109 | 107 | ||
@@ -699,10 +697,8 @@ void create_empty_dir_as_root(const char *dir, mode_t mode) { | |||
699 | printf("Creating empty %s directory\n", dir); | 697 | printf("Creating empty %s directory\n", dir); |
700 | if (mkdir(dir, mode) == -1) | 698 | if (mkdir(dir, mode) == -1) |
701 | errExit("mkdir"); | 699 | errExit("mkdir"); |
702 | if (chmod(dir, mode) == -1) | 700 | if (set_perms(dir, 0, 0, mode)) |
703 | errExit("chmod"); | 701 | errExit("set_perms"); |
704 | if (chown(dir, 0, 0) == -1) | ||
705 | errExit("chown"); | ||
706 | ASSERT_PERMS(dir, 0, 0, mode); | 702 | ASSERT_PERMS(dir, 0, 0, mode); |
707 | } | 703 | } |
708 | } | 704 | } |
@@ -725,3 +721,14 @@ void create_empty_file_as_root(const char *fname, mode_t mode) { | |||
725 | } | 721 | } |
726 | } | 722 | } |
727 | 723 | ||
724 | // return 1 if error | ||
725 | int set_perms(const char *fname, uid_t uid, gid_t gid, mode_t mode) { | ||
726 | assert(fname); | ||
727 | if (chmod(fname, mode) == -1) | ||
728 | return 1; | ||
729 | if (chown(fname, uid, gid) == -1) | ||
730 | return 1; | ||
731 | return 0; | ||
732 | } | ||
733 | |||
734 | |||