mirror of
https://github.com/samba-team/samba.git
synced 2025-08-24 21:49:29 +03:00
lib: Fix lstat check in directory_create_or_exist
The lstat check in directory_create_or_exist did not verify whether an existing object is actually a directory. Also move the check to only apply when mkdir returns EEXIST; this fixes CID 241930 Time of check time of use. Signed-off-by: Christof Schmitt <cs@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
This commit is contained in:
@ -194,20 +194,8 @@ _PUBLIC_ bool directory_create_or_exist(const char *dname,
|
||||
mode_t dir_perms)
|
||||
{
|
||||
int ret;
|
||||
struct stat st;
|
||||
mode_t old_umask;
|
||||
|
||||
ret = lstat(dname, &st);
|
||||
if (ret == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (errno != ENOENT) {
|
||||
DBG_WARNING("lstat failed on directory %s: %s\n",
|
||||
dname, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Create directory */
|
||||
old_umask = umask(0);
|
||||
ret = mkdir(dname, dir_perms);
|
||||
@ -220,11 +208,17 @@ _PUBLIC_ bool directory_create_or_exist(const char *dname,
|
||||
}
|
||||
umask(old_umask);
|
||||
|
||||
ret = lstat(dname, &st);
|
||||
if (ret == -1) {
|
||||
DEBUG(0, ("lstat failed on created directory %s: %s\n",
|
||||
dname, strerror(errno)));
|
||||
return false;
|
||||
if (ret != 0 && errno == EEXIST) {
|
||||
struct stat sbuf;
|
||||
|
||||
ret = lstat(dname, &sbuf);
|
||||
if (ret != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!S_ISDIR(sbuf.st_mode)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user