From: VMware, Inc <> Date: Tue, 28 Jun 2011 17:49:19 +0000 (-0700) Subject: Switch to Super User if futimes() fail. X-Git-Tag: 2011.06.27-437995~50 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f7068b1dfc1c89853bb4d1ecbc69cbe837b9898a;p=thirdparty%2Fopen-vm-tools.git Switch to Super User if futimes() fail. Even if the userid of the VMX process matches the userid of the file residing on the file system, futimes fails in few scenarios. In such case, we should switch to superuser and try one more time. Signed-off-by: Marcelo Vanzin --- diff --git a/open-vm-tools/lib/hgfsServer/hgfsServerLinux.c b/open-vm-tools/lib/hgfsServer/hgfsServerLinux.c index 678a85bd0..fa2964267 100644 --- a/open-vm-tools/lib/hgfsServer/hgfsServerLinux.c +++ b/open-vm-tools/lib/hgfsServer/hgfsServerLinux.c @@ -2868,6 +2868,11 @@ HgfsPlatformSetattrFromFd(HgfsHandle file, // IN: file descriptor * to set the files times using futimes. */ + /* + * XXX Bug 718252: Ideally we should use geteuid() instead of + * getuid(). For Nitrogen/Honeycomb, we can live with getuid() + * and fix it later on the *-main. + */ if (getuid() != statBuf.st_uid) { /* We are not the file owner. Check if we are running as root. */ if (!Id_IsSuperUser()) { @@ -2886,10 +2891,27 @@ HgfsPlatformSetattrFromFd(HgfsHandle file, // IN: file descriptor */ if (futimes(fd, times) < 0) { - error = errno; - LOG(4, ("%s: futimes error on file %u: %s\n", __FUNCTION__, - fd, strerror(error))); - status = error; + if (!switchToSuperUser) { + /* + * Check bug 718252. If futimes() fails, switch to + * superuser briefly and try futimes() one more time. + */ + uid = Id_BeginSuperUser(); + switchToSuperUser = TRUE; + if (futimes(fd, times) < 0) { + error = errno; + LOG(4, ("%s: Executing futimes as owner on file: %u " + "failed with error: %s\n", __FUNCTION__, + fd, strerror(error))); + status = error; + } + } else { + error = errno; + LOG(4, ("%s: Executing futimes as superuser on file: %u " + "failed with error: %s\n", __FUNCTION__, + fd, strerror(error))); + status = error; + } } if (switchToSuperUser) { Id_EndSuperUser(uid);