From: Christof Schmitt Date: Fri, 14 Aug 2020 16:36:26 +0000 (-0700) Subject: util: Allow symlinks in directory_create_or_exist X-Git-Tag: talloc-2.3.2~872 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=672212cecdd7a7de40acdc81c56e2996ea82c090;p=thirdparty%2Fsamba.git 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 --- diff --git a/lib/util/util.c b/lib/util/util.c index 1f37688cbad..d7331f743f3 100644 --- a/lib/util/util.c +++ b/lib/util/util.c @@ -191,6 +191,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. @@ -224,9 +225,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;