]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Allow copying of object policy within the same container
authorOliver Kurth <okurth@vmware.com>
Fri, 5 Jan 2018 22:47:14 +0000 (14:47 -0800)
committerOliver Kurth <okurth@vmware.com>
Fri, 5 Jan 2018 22:47:14 +0000 (14:47 -0800)
ObjLib_CloneExtParams is currently not allowing copying of policy from
parent to child/clone object on VSAN. This is because the copy policy
check is based on unique filesystem ID, which will be different for
parent and child on VSAN because they will mostly be created on same
container but different namespace. This change uses VCFS root instead
of namespace UUID to make the comparison on VSAN.

Bonus fix: File_FullPath is now fixed to work for any combination of
ancestor path being present. Currently it only works if either the
given path exists, or when only the last component of the path does
not exist. And since this fix relies on finding the VCFS root of both
parent and child (parent is present but child is not),
ObjLibPathToVCFSRoot has been modified to rely on File_FullPath  in
addition to Util_GetCanonicalPath if the path does not exist.

open-vm-tools/lib/file/filePosix.c

index 6f45d84651284ae4c25fd9545678cab34f73420c..55602b59a3c053f5ceb4e464ac591b526c832a5f 100644 (file)
@@ -574,11 +574,12 @@ File_StripFwdSlashes(const char *pathName)  // IN:
  *      path of "." is the current working directory, ".." is parent
  *      directory and so on. If the path is NULL or "", this routine
  *      returns the current working directory.
- *      There are mainly two use cases for this function. To find the
- *      canonical path of a file or directory that exists, or when we
- *      are about to create a child in an existing parent directory.
- *      For other uses cases, this routine is not guaranteed to return
- *      a canonical path.
+ *
+ *      On FreeBSD and Sun platforms, this routine will only work if
+ *      the path exists, or when we are about to create a child in an
+ *      existing parent directory. This is because on these platforms,
+ *      we cannot rely on finding existing ancestor and such because
+ *      those functions are not compiled.
  *
  * Results:
  *      NULL if error (reported to the user)
@@ -619,18 +620,41 @@ File_FullPath(const char *pathName)  // IN:
       if (ret == NULL) {
          char *dir;
          char *file;
+#if defined(__FreeBSD__) || defined(sun)
          char *realDir;
+#else
+         char *ancestorPath;
+         char *ancestorRealPath;
+#endif
 
          File_GetPathName(path, &dir, &file);
+#if defined(__FreeBSD__) || defined(sun)
          realDir = Posix_RealPath(dir);
          if (realDir == NULL) {
             realDir = File_StripFwdSlashes(dir);
          }
 
          ret = Unicode_Join(realDir, DIRSEPS, file, NULL);
+         Posix_Free(realDir);
+#else
+         ancestorPath = FilePosixNearestExistingAncestor(dir);
+         ancestorRealPath = Posix_RealPath(ancestorPath);
+
+         /*
+          * Check if the ancestor was deleted before we could compute its
+          * realPath
+          */
+         if (ancestorRealPath == NULL) {
+            ret = File_StripFwdSlashes(path);
+         } else {
+            ret = File_PathJoin(ancestorRealPath, path + strlen(ancestorPath));
+            Posix_Free(ancestorRealPath);
+         }
+
+         Posix_Free(ancestorPath);
+#endif
          Posix_Free(dir);
          Posix_Free(file);
-         Posix_Free(realDir);
       }
 
       Posix_Free(path);