summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristof Schmitt <cs@samba.org>2020-08-14 09:36:26 -0700
committerKarolin Seeger <kseeger@samba.org>2020-08-17 12:45:13 +0000
commit2d5e88dc84bfb0b4ee3324448cd3149a8d95c035 (patch)
tree0bea9fde18d033fd79c58a3e3460c8254c11734a
parentbb08c9b1f0897bd76e2df78aef4a5ad4576578ab (diff)
downloadsamba-2d5e88dc84bfb0b4ee3324448cd3149a8d95c035.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)
-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 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;