]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
util: Allow symlinks in directory_create_or_exist
authorChristof Schmitt <cs@samba.org>
Fri, 14 Aug 2020 16:36:26 +0000 (09:36 -0700)
committerKarolin Seeger <kseeger@samba.org>
Mon, 17 Aug 2020 12:45:13 +0000 (12:45 +0000)
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)

lib/util/util.c

index 0d9ffe5cb7b61bb897ac686845ace2d893cc1117..52fc61a3e810483e69bd2e09bfa54e637de8ed2e 100644 (file)
@@ -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;