summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChristof Schmitt <cs@samba.org>2020-08-14 09:36:26 -0700
committerStefan Metzmacher <metze@samba.org>2020-08-19 08:34:09 +0000
commit031618f0acb15bb05004c702dbb4ec086c3e27b9 (patch)
tree05474a51483c9d3b2b180b4d6f03d03406d287d2 /lib
parent2bd88d076e8824cd0f41d7d8f1e8fed6b974f95e (diff)
downloadsamba-031618f0acb15bb05004c702dbb4ec086c3e27b9.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.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/util/util.c b/lib/util/util.c
index a90d48f6f1b..59dc7bd6b71 100644
--- a/lib/util/util.c
+++ b/lib/util/util.c
@@ -343,6 +343,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.
@@ -376,9 +377,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;