helpers: Don't enforce umask on mkdir_p, just force that when needed

Swupd state dir should be masked as 700, but we can't mask all parent directories
as 700. This is particularly a problem because /var and /var/lib/ shoudn't
be 700, but /var/lib/swupd should. So creating all folders with current
umask and using chmod syscall to set only the swupd statedir diretory to
root only

Also, stop using mkdir_p where are no longer needed

Fixes #655

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
This commit is contained in:
Otavio Pontes
2018-11-16 10:44:28 -08:00
parent 5cb094e1b1
commit 6ff94a82df
2 changed files with 10 additions and 4 deletions
+1 -1
View File
@@ -428,7 +428,7 @@ static void track_installed(const char *bundle_name)
* user installed themselves just copy the entire system tracking directory
* into the state tracking directory. */
if (!is_populated_dir(dst)) {
ret = mkdir_p(dst);
ret = mkdir(dst, S_IRWXU);
if (ret) {
goto out;
}
+9 -3
View File
@@ -189,7 +189,7 @@ int copy_all(const char *src, const char *dst)
int mkdir_p(const char *dir)
{
char *cmd;
string_or_die(&cmd, "umask 077 ; mkdir -p %s", dir);
string_or_die(&cmd, "mkdir -p %s", dir);
int ret = system(cmd);
free_string(&cmd);
return ret;
@@ -204,13 +204,19 @@ static int create_required_dirs(void)
const char *state_dirs[] = { "delta", "staged", "download", "telemetry" };
// check for existence
ensure_root_owned_dir(state_dir);
if (ensure_root_owned_dir(state_dir)) {
//state dir doesn't exist
if (mkdir_p(state_dir) != 0 || chmod(state_dir, S_IRWXU) != 0) {
fprintf(stderr, "Error: failed to create %s\n", state_dir);
return -1;
}
}
for (i = 0; i < STATE_DIR_COUNT; i++) {
string_or_die(&dir, "%s/%s", state_dir, state_dirs[i]);
ret = ensure_root_owned_dir(dir);
if (ret) {
ret = mkdir_p(dir);
ret = mkdir(dir, S_IRWXU);
if (ret) {
fprintf(stderr, "Error: failed to create %s\n", dir);
return -1;