summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2012-03-14 10:50:34 +0100
committerStefan Metzmacher <metze@samba.org>2012-03-14 12:00:46 +0100
commitbfe990af89ebd870625c0740f1c6073a5349771e (patch)
treedd2ea376959f0861fbeb771c02f727b5e3033c09 /lib
parente03059fc96931416c551d7d0a30eccb727a4f524 (diff)
downloadsamba-bfe990af89ebd870625c0740f1c6073a5349771e.tar.gz
samba-bfe990af89ebd870625c0740f1c6073a5349771e.tar.bz2
samba-bfe990af89ebd870625c0740f1c6073a5349771e.zip
lib/util: cope with races between lstat and mkdir in directory_create_or_exist()
metze
Diffstat (limited to 'lib')
-rw-r--r--lib/util/util.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/util/util.c b/lib/util/util.c
index 54a8c88245..e3d22f3614 100644
--- a/lib/util/util.c
+++ b/lib/util/util.c
@@ -161,7 +161,7 @@ _PUBLIC_ bool directory_create_or_exist(const char *dname, uid_t uid,
/* Create directory */
ret = mkdir(dname, dir_perms);
- if (ret == -1) {
+ if (ret == -1 && errno != EEXIST) {
DEBUG(0, ("mkdir failed on directory "
"%s: %s\n", dname,
strerror(errno)));
@@ -169,7 +169,13 @@ _PUBLIC_ bool directory_create_or_exist(const char *dname, uid_t uid,
return false;
}
- return true;
+ 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;
+ }
}
/* Check ownership and permission on existing directory */