]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Fix saving MS Project files in a folder on a NFS server
authorVMware, Inc <>
Sat, 28 May 2011 19:51:41 +0000 (12:51 -0700)
committerMarcelo Vanzin <mvanzin@vmware.com>
Sat, 28 May 2011 19:51:41 +0000 (12:51 -0700)
The files appeared as read only because the set attributes
call to update the file modification time was failing.
This occurred due to the Posix HGFS server switching to
running as super user when updating the file timestamps by
calling futimes. This was done if the VMX was the file owner
or running as root. This is okay for local file systems but
not for network shares. In this case the VMX was indeed the
file owner and so switching to super user was not necessary.

Fix is to not switch to super user if the VMX is the file
owner.

Signed-off-by: Marcelo Vanzin <mvanzin@vmware.com>
open-vm-tools/lib/hgfsServer/hgfsServerLinux.c

index 385e5cfee05e8520360f0384096e8e4c7d3ff6d0..678a85bd071825971ed84d9b52402764474bd168 100644 (file)
@@ -2857,24 +2857,29 @@ HgfsPlatformSetattrFromFd(HgfsHandle file,          // IN: file descriptor
    timesStatus = HgfsSetattrTimes(&statBuf, attr, hints,
                                   &times[0], &times[1], &timesChanged);
    if (timesStatus == 0 && timesChanged) {
-      uid_t uid;
+      uid_t uid = (uid_t)-1;
+      Bool switchToSuperUser = FALSE;
 
       LOG(4, ("%s: setting new times\n", __FUNCTION__));
 
       /*
-       * If the VMX is either the file owner or running as root, switch to
-       * superuser briefly to set the files times using futimes. Otherwise
-       * return an error.
+       * If the VMX is neither the file owner nor running as root, return an error.
+       * Otherwise if we are not the file owner switch to superuser briefly
+       * to set the files times using futimes.
        */
 
-      if (!Id_IsSuperUser() && (getuid() != statBuf.st_uid)) {
-         LOG(4, ("%s: only owner of file %u or root can call futimes\n",
-                 __FUNCTION__, fd));
-         /* XXX: Linux kernel says both EPERM and EACCES are valid here. */
-         status = EPERM;
-         goto exit;
+      if (getuid() != statBuf.st_uid) {
+         /* We are not the file owner. Check if we are running as root. */
+         if (!Id_IsSuperUser()) {
+            LOG(4, ("%s: only owner of file %u or root can call futimes\n",
+                    __FUNCTION__, fd));
+            /* XXX: Linux kernel says both EPERM and EACCES are valid here. */
+            status = EPERM;
+            goto exit;
+         }
+         uid = Id_BeginSuperUser();
+         switchToSuperUser = TRUE;
       }
-      uid = Id_BeginSuperUser();
       /*
        * XXX Newer glibc provide also lutimes() and futimes()
        *     when we politely ask with -D_GNU_SOURCE -D_BSD_SOURCE
@@ -2886,7 +2891,9 @@ HgfsPlatformSetattrFromFd(HgfsHandle file,          // IN: file descriptor
                  fd, strerror(error)));
          status = error;
       }
-      Id_EndSuperUser(uid);
+      if (switchToSuperUser) {
+         Id_EndSuperUser(uid);
+      }
    } else if (timesStatus != 0) {
       status = timesStatus;
    }