diff options
author | Christof Schmitt <cs@samba.org> | 2020-08-14 09:36:26 -0700 |
---|---|---|
committer | Karolin Seeger <kseeger@samba.org> | 2020-08-17 11:20:20 +0000 |
commit | 0797eef2901cc0b8d1fcc11f368285cfcf1b0400 (patch) | |
tree | 2c081a2311b71da90f211963a8b2301cf0725bfb /lib | |
parent | 6b8d52984e5d339f353e8e04fa3812442074da01 (diff) | |
download | samba-0797eef2901cc0b8d1fcc11f368285cfcf1b0400.tar.gz |
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 <cs@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
(cherry picked from commit 672212cecdd7a7de40acdc81c56e2996ea82c090)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/util/util.c | 18 |
1 files 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; |