]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Changes to common source files not directly applicable to open-vm-tools.
authorOliver Kurth <okurth@vmware.com>
Tue, 21 Apr 2020 21:43:46 +0000 (14:43 -0700)
committerOliver Kurth <okurth@vmware.com>
Tue, 21 Apr 2020 21:43:46 +0000 (14:43 -0700)
open-vm-tools/lib/file/file.c
open-vm-tools/lib/include/file.h

index 0b99e159eeeb5a36380c77e563ebc4f7137ab47e..30d4919599c377f8a6b6357105899d64bdd80e8f 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 1998-2019 VMware, Inc. All rights reserved.
+ * Copyright (C) 1998-2020 VMware, Inc. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published
@@ -2684,3 +2684,48 @@ File_ContainSymLink(const char *pathName)  // IN:
 
    return retValue;
 }
+
+
+/*
+ *----------------------------------------------------------------------------
+ *
+ * File_IsSubPathOf --
+ *
+ *    Check if the argument path is a sub path for argument base.
+ *    The argument path will be converted to canonical path which doesn't
+ *    contain ".." and then check if this canonical path is a sub path for
+ *    argument base.
+ *    So, this function can correctly recognize that a path like
+ *    "/tmp/dir1/dir2/../../../bin/" is not a sub path for "/tmp/".
+ *
+ * Results:
+ *    True if the argument path is a sub path for argument base.
+ *
+ * Side effects:
+ *    None.
+ *
+ *----------------------------------------------------------------------------
+ */
+
+Bool
+File_IsSubPathOf(const char *base, // IN: the base path to test against.
+                 const char *path) // IN: the possible subpath to test.
+{
+   char *fullBase = File_FullPath(base);
+   char *fullPath = File_FullPath(path);
+   Bool isSubPath = TRUE;
+
+   ASSERT(fullBase);
+   ASSERT(fullPath);
+   if (   fullPath == NULL
+       || fullBase == NULL
+       || strncmp(fullPath, fullBase, strlen(fullBase)) != 0) {
+      isSubPath = FALSE;
+   }
+
+   free(fullBase);
+   free(fullPath);
+
+   return isSubPath;
+}
+
index 181308ea0fc3eba3f9ad005ffb942a07ff1c2f6c..d2bb8d824e4d559b5d0af572cb13ea8726568570 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 1998-2019 VMware, Inc. All rights reserved.
+ * Copyright (C) 1998-2020 VMware, Inc. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published
@@ -372,6 +372,8 @@ int File_MakeSafeTemp(const char *tag,
 
 Bool File_DoesVolumeSupportAcls(const char *pathName);
 
+Bool File_IsSubPathOf(const char *base, const char *path);
+
 /*
  *---------------------------------------------------------------------------
  *