From: VMware, Inc <> Date: Thu, 2 Aug 2012 05:24:32 +0000 (-0700) Subject: VIX: directories created via VIX api should have 0700 permissions X-Git-Tag: 2012.10.14-874563~91 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b897dc27fcf06b9b07f613887f3ba3b67f30625a;p=thirdparty%2Fopen-vm-tools.git VIX: directories created via VIX api should have 0700 permissions 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 --- diff --git a/open-vm-tools/lib/file/file.c b/open-vm-tools/lib/file/file.c index dc6b437df..48e729207 100644 --- a/open-vm-tools/lib/file/file.c +++ b/open-vm-tools/lib/file/file.c @@ -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); +} + + /* *---------------------------------------------------------------------- * diff --git a/open-vm-tools/lib/include/file.h b/open-vm-tools/lib/include/file.h index 8a3e379a1..afd17898f 100644 --- a/open-vm-tools/lib/include/file.h +++ b/open-vm-tools/lib/include/file.h @@ -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, diff --git a/open-vm-tools/services/plugins/vix/vixTools.c b/open-vm-tools/services/plugins/vix/vixTools.c index 0e6a9dfa3..5537a6b21 100644 --- a/open-vm-tools/services/plugins/vix/vixTools.c +++ b/open-vm-tools/services/plugins/vix/vixTools.c @@ -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; }