From 2d5e88dc84bfb0b4ee3324448cd3149a8d95c035 Mon Sep 17 00:00:00 2001 From: Christof Schmitt Date: Fri, 14 Aug 2020 09:36:26 -0700 Subject: util: Allow symlinks in directory_create_or_exist Commit 9f60a77e0b updated the check to avoid having files or other objects instead of a directory. This missed the valid case that there might be a symlink to a directory. Updated the check accordingly to allow symlinks to directories. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14166 Signed-off-by: Christof Schmitt Reviewed-by: Volker Lendecke (cherry picked from commit 672212cecdd7a7de40acdc81c56e2996ea82c090) --- lib/util/util.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/util/util.c b/lib/util/util.c index 0d9ffe5cb7b..52fc61a3e81 100644 --- a/lib/util/util.c +++ b/lib/util/util.c @@ -339,6 +339,7 @@ _PUBLIC_ bool directory_exist(const char *dname) /** * Try to create the specified directory if it didn't exist. + * A symlink to a directory is also accepted as a valid existing directory. * * @retval true if the directory already existed * or was successfully created. @@ -372,9 +373,22 @@ _PUBLIC_ bool directory_create_or_exist(const char *dname, return false; } - if (!S_ISDIR(sbuf.st_mode)) { - return false; + if (S_ISDIR(sbuf.st_mode)) { + return true; } + + if (S_ISLNK(sbuf.st_mode)) { + ret = stat(dname, &sbuf); + if (ret != 0) { + return false; + } + + if (S_ISDIR(sbuf.st_mode)) { + return true; + } + } + + return false; } return true; -- cgit v1.2.1