]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Fix error on file deletion on read-only HGFS share
authorVMware, Inc <>
Thu, 2 Aug 2012 05:26:04 +0000 (22:26 -0700)
committerDmitry Torokhov <dtor@vmware.com>
Thu, 2 Aug 2012 18:08:24 +0000 (11:08 -0700)
The failure was being done at the set file information call of the
Windows client instead of the create call. This only occurred when
communicating to HGFS servers on Posix platforms. The Posix platform
only uses the open mode of the HGFS open protocol request even if the
desired access is valid. On Windows HGFS servers the desired access is
checked and used if valid, and if not falls back to the Posix open mode
call.

However, for the case of delete requests, the Windows client does not
set up the Posix open mode quite correctly. It igonores the DELETE
desired access flag.  This should be mapped to a Posix open mode
requesting write access. So for occasions where read attributes and
delete is requested in the desired access the Posix open mode is still
passed as read-only. This causes the open to succeed on a read-only
share when it should be failed with access denied.

This fix is to address the HGFS Posix server to try to map a Windows
client passing the desired access mask to the Posix open mode will then
allow all Windows clients to have the open for delete access validated
by the HGFS server.  Linux clients are unaffected and do not use this
field for the open requests.  It also has the benefit of making the
Posix and Windows HGFS servers more compatible.

Signed-off-by: Dmitry Torokhov <dtor@vmware.com>
open-vm-tools/lib/hgfsServer/hgfsServerLinux.c

index 6336730aa3b53a70d189d3a697955f53ba96ee9e..86aa31b2467281b75324165e6c36404d7f0237f1 100644 (file)
@@ -247,6 +247,17 @@ struct FInfoAttrBuf {
    char finderInfo[32];
 };
 #endif
+
+/*
+ * Taken from WinNT.h.
+ * For verifying the Windows client which can ask for delete access as well as the
+ * standard read, write, execute permissions.
+ * XXX - should probably be moved into a header file and may need to be expanded if
+ * Posix looks at the access mode more thoroughly or we expand the set of cross-platform
+ * access mode flags.
+ */
+#define DELETE                           (0x00010000L)
+
 /*
  * Server open flags, indexed by HgfsOpenFlags. Stolen from
  * lib/fileIOPosix.c
@@ -1008,8 +1019,20 @@ HgfsPlatformValidateOpen(HgfsFileOpenInfo *openInfo, // IN: Open info struct
     */
    status = 0;
    if (!openInfo->shareInfo.writePermissions) {
+      Bool deleteAccess = FALSE;
+      /*
+       * If a valid desiredAccess field specified by the Windows client, we use that
+       * as the desiredAccess field has more data such as delete than is contained
+       * in the mode.
+       */
+      if ((0 != (openInfo->mask & HGFS_OPEN_VALID_DESIRED_ACCESS)) &&
+          (0 != (openInfo->desiredAccess & DELETE))) {
+         deleteAccess = TRUE;
+      }
+
       if ((openFlags & (O_APPEND | O_CREAT | O_TRUNC)) ||
-          (openMode & (O_WRONLY | O_RDWR))) {
+          (openMode & (O_WRONLY | O_RDWR)) ||
+          deleteAccess) {
          status = Posix_Access(openInfo->utf8Name, F_OK);
          if (status < 0) {
             status = errno;