summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2012-03-14 10:52:50 +0100
committerStefan Metzmacher <metze@samba.org>2012-03-14 12:00:46 +0100
commit800209aad5b07f9c61d7986971f42ff0f5ade78e (patch)
tree8ad4b5e2f9b1e85f95833ed78364f620039d8132
parentbfe990af89ebd870625c0740f1c6073a5349771e (diff)
downloadsamba-800209aad5b07f9c61d7986971f42ff0f5ade78e.tar.gz
samba-800209aad5b07f9c61d7986971f42ff0f5ade78e.tar.bz2
samba-800209aad5b07f9c61d7986971f42ff0f5ade78e.zip
lib/util: only change umask during mkdir()
metze
-rw-r--r--lib/util/util.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/lib/util/util.c b/lib/util/util.c
index e3d22f3614..960bda0f9b 100644
--- a/lib/util/util.c
+++ b/lib/util/util.c
@@ -146,20 +146,20 @@ _PUBLIC_ bool directory_create_or_exist(const char *dname, uid_t uid,
mode_t dir_perms)
{
int ret;
- mode_t old_umask;
struct stat st;
- old_umask = umask(0);
ret = lstat(dname, &st);
if (ret == -1) {
+ mode_t old_umask;
+
if (errno != ENOENT) {
DEBUG(0, ("lstat failed on directory %s: %s\n",
dname, strerror(errno)));
- umask(old_umask);
return false;
}
/* Create directory */
+ old_umask = umask(0);
ret = mkdir(dname, dir_perms);
if (ret == -1 && errno != EEXIST) {
DEBUG(0, ("mkdir failed on directory "
@@ -168,12 +168,12 @@ _PUBLIC_ bool directory_create_or_exist(const char *dname, uid_t uid,
umask(old_umask);
return false;
}
+ umask(old_umask);
ret = lstat(dname, &st);
if (ret == -1) {
DEBUG(0, ("lstat failed on created directory %s: %s\n",
dname, strerror(errno)));
- umask(old_umask);
return false;
}
}
@@ -182,20 +182,17 @@ _PUBLIC_ bool directory_create_or_exist(const char *dname, uid_t uid,
if (!S_ISDIR(st.st_mode)) {
DEBUG(0, ("directory %s isn't a directory\n",
dname));
- umask(old_umask);
return false;
}
if (st.st_uid != uid && !uwrap_enabled()) {
DEBUG(0, ("invalid ownership on directory "
"%s\n", dname));
- umask(old_umask);
return false;
}
if ((st.st_mode & 0777) != dir_perms) {
DEBUG(0, ("invalid permissions on directory "
"'%s': has 0%o should be 0%o\n", dname,
(st.st_mode & 0777), dir_perms));
- umask(old_umask);
return false;
}