From: VMware, Inc <> Date: Sat, 28 May 2011 19:51:41 +0000 (-0700) Subject: Fix saving MS Project files in a folder on a NFS server X-Git-Tag: 2011.05.27-420096~45 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5e2a46fb57ecb7b649e51276616fe3e73c08cfd0;p=thirdparty%2Fopen-vm-tools.git Fix saving MS Project files in a folder on a NFS server 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 --- diff --git a/open-vm-tools/lib/hgfsServer/hgfsServerLinux.c b/open-vm-tools/lib/hgfsServer/hgfsServerLinux.c index 385e5cfee..678a85bd0 100644 --- a/open-vm-tools/lib/hgfsServer/hgfsServerLinux.c +++ b/open-vm-tools/lib/hgfsServer/hgfsServerLinux.c @@ -2857,24 +2857,29 @@ HgfsPlatformSetattrFromFd(HgfsHandle file, // IN: file descriptor timesStatus = HgfsSetattrTimes(&statBuf, attr, hints, ×[0], ×[1], ×Changed); 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; }