2
0
mirror of https://github.com/sudo-project/sudo.git synced 2025-08-30 22:05:46 +00:00

Set umask temporarily when creating files instead of changing the

mode after the fact.  This is slightly less error prone.
This commit is contained in:
Todd C. Miller
2017-03-21 16:21:17 -06:00
parent 2a37590b7d
commit 7668b4b42b
3 changed files with 15 additions and 6 deletions

View File

@@ -154,8 +154,11 @@ ts_mkdirs(char *path, uid_t owner, gid_t group, mode_t mode,
mode_t parent_mode, bool quiet)
{
bool ret;
mode_t omask;
debug_decl(ts_mkdirs, SUDOERS_DEBUG_AUTH)
/* umask must not be more restrictive than the file modes. */
omask = umask(ACCESSPERMS & ~(mode|parent_mode));
ret = sudo_mkdir_parents(path, owner, group, parent_mode, quiet);
if (ret) {
/* Create final path component. */
@@ -170,6 +173,7 @@ ts_mkdirs(char *path, uid_t owner, gid_t group, mode_t mode,
ignore_result(chown(path, owner, group));
}
}
umask(omask);
debug_return_bool(ret);
}