]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
VIX: directories created via VIX api should have 0700 permissions
authorVMware, Inc <>
Thu, 2 Aug 2012 05:24:32 +0000 (22:24 -0700)
committerDmitry Torokhov <dtor@vmware.com>
Thu, 2 Aug 2012 18:08:03 +0000 (11:08 -0700)
There are visibility issues with the directories created via VIX apis
(VixVM_CreateDirectory). All the directories created via VIX apis should
be tagged with 0700 permissions instead of 0755 permissions.

Added few Ex functions in file.c to create directories with the specified
permission. Modified the vix tools code to create the new Ex functions
with the specific permission mode.

Signed-off-by: Dmitry Torokhov <dtor@vmware.com>
open-vm-tools/lib/file/file.c
open-vm-tools/lib/include/file.h
open-vm-tools/services/plugins/vix/vixTools.c

index dc6b437df084bd5a055d64c4d5146e65fcaec1fa..48e729207e43480e0adfd8d839a7792e76b91fa4 100644 (file)
@@ -287,9 +287,9 @@ File_UnlinkNoFollow(ConstUnicode pathName)  // IN:
 /*
  *----------------------------------------------------------------------
  *
- * File_CreateDirectory --
+ * File_CreateDirectoryEx --
  *
- *      Creates the specified directory.
+ *      Creates the specified directory with the specified permissions.
  *
  * Results:
  *      True if the directory is successfully created, false otherwise.
@@ -301,14 +301,38 @@ File_UnlinkNoFollow(ConstUnicode pathName)  // IN:
  */
 
 Bool
-File_CreateDirectory(ConstUnicode pathName)  // IN:
+File_CreateDirectoryEx(ConstUnicode pathName,  // IN:
+                       int mask)               // IN:
 {
-   int err = FileCreateDirectory(pathName, 0777);
+   int err = FileCreateDirectory(pathName, mask);
 
    return err == 0;
 }
 
 
+/*
+ *----------------------------------------------------------------------
+ *
+ * File_CreateDirectory --
+ *
+ *      Creates the specified directory with 0777 permissions.
+ *
+ * Results:
+ *      True if the directory is successfully created, false otherwise.
+ *
+ * Side effects:
+ *      Creates the directory on disk.
+ *
+ *----------------------------------------------------------------------
+ */
+
+Bool
+File_CreateDirectory(ConstUnicode pathName)  // IN:
+{
+   return File_CreateDirectoryEx(pathName, 0777);
+}
+
+
 /*
  *----------------------------------------------------------------------
  *
@@ -1646,9 +1670,10 @@ File_GetSizeByPath(ConstUnicode pathName)  // IN:
 /*
  *-----------------------------------------------------------------------------
  *
- * File_CreateDirectoryHierarchy --
+ * File_CreateDirectoryHierarchyEx --
  *
  *      Create a directory including any parents that don't already exist.
+ *      All the created directories are tagged with the specified permission.
  *      Returns the topmost directory which was created, to allow calling code
  *      to remove it after in case later operations fail.
  *
@@ -1669,8 +1694,9 @@ File_GetSizeByPath(ConstUnicode pathName)  // IN:
  */
 
 Bool
-File_CreateDirectoryHierarchy(ConstUnicode pathName,   // IN:
-                              Unicode *topmostCreated) // OUT:
+File_CreateDirectoryHierarchyEx(ConstUnicode pathName,   // IN:
+                                int mask,                // IN
+                                Unicode *topmostCreated) // OUT:
 {
    Unicode volume;
    UnicodeIndex index;
@@ -1719,7 +1745,7 @@ File_CreateDirectoryHierarchy(ConstUnicode pathName,   // IN:
       if (File_IsDirectory(temp)) {
          failed = FALSE;
       } else {
-         failed = !File_CreateDirectory(temp);
+         failed = !File_CreateDirectoryEx(temp, mask);
          if (!failed && topmostCreated != NULL && *topmostCreated == NULL) {
             *topmostCreated = temp;
             temp = NULL;
@@ -1742,6 +1768,42 @@ File_CreateDirectoryHierarchy(ConstUnicode pathName,   // IN:
 }
 
 
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * File_CreateDirectoryHierarchy --
+ *
+ *      Create a directory including any parents that don't already exist.
+ *      All the created directories are tagged with 0777 permissions.
+ *      Returns the topmost directory which was created, to allow calling code
+ *      to remove it after in case later operations fail.
+ *
+ * Results:
+ *      TRUE on success, FALSE on failure.
+ *
+ *      If topmostCreated is not NULL, it returns the result of the hierarchy
+ *      creation. If no directory was created, *topmostCreated is set to NULL.
+ *      Otherwise *topmostCreated is set to the topmost directory which was
+ *      created. *topmostCreated is set even in case of failure.
+ *
+ *      The caller most Unicode_Free the resulting string.
+ *
+ * Side effects:
+ *      Only the obvious.
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+Bool
+File_CreateDirectoryHierarchy(ConstUnicode pathName,   // IN:
+                              Unicode *topmostCreated) // OUT:
+{
+   return File_CreateDirectoryHierarchyEx(pathName,
+                                          0777,
+                                          topmostCreated);
+}
+
+
 /*
  *----------------------------------------------------------------------
  *
index 8a3e379a15b6fb0acc51e475810b5ab5ed56a244..afd17898f9901016a58828dfbdceecc177649c42 100644 (file)
@@ -158,6 +158,9 @@ Unicode File_PathJoin(ConstUnicode dirName,
                       ConstUnicode baseName);
 
 Bool File_CreateDirectory(ConstUnicode pathName);
+
+Bool File_CreateDirectoryEx(ConstUnicode pathName, int mask);
+
 Bool File_EnsureDirectory(ConstUnicode pathName);
 
 Bool File_DeleteEmptyDirectory(ConstUnicode pathName);
@@ -165,6 +168,10 @@ Bool File_DeleteEmptyDirectory(ConstUnicode pathName);
 Bool File_CreateDirectoryHierarchy(ConstUnicode pathName,
                                    Unicode *topmostCreated);
 
+Bool File_CreateDirectoryHierarchyEx(ConstUnicode pathName,
+                                     int mask,
+                                     Unicode *topmostCreated);
+
 Bool File_DeleteDirectoryTree(ConstUnicode pathName);
 
 int File_ListDirectory(ConstUnicode pathName,
index 0e6a9dfa343b4dea3abbe582244d9490cd95671b..5537a6b21a522677bd3135c41d0672a8898fbd37 100644 (file)
@@ -5673,12 +5673,12 @@ VixToolsCreateDirectory(VixCommandRequestHeader *requestMsg)  // IN
    }
 
    if (createParentDirectories) {
-      if (!(File_CreateDirectoryHierarchy(dirPathName, NULL))) {
+      if (!(File_CreateDirectoryHierarchyEx(dirPathName, 0700, NULL))) {
          err = FoundryToolsDaemon_TranslateSystemErr();
          goto abort;
       }
    } else {
-      if (!(File_CreateDirectory(dirPathName))) {
+      if (!(File_CreateDirectoryEx(dirPathName, 0700))) {
          err = FoundryToolsDaemon_TranslateSystemErr();
          goto abort;
       }