]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Switch to Super User if futimes() fail.
authorVMware, Inc <>
Tue, 28 Jun 2011 17:49:19 +0000 (10:49 -0700)
committerMarcelo Vanzin <mvanzin@vmware.com>
Tue, 28 Jun 2011 17:49:19 +0000 (10:49 -0700)
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 <mvanzin@vmware.com>
open-vm-tools/lib/hgfsServer/hgfsServerLinux.c

index 678a85bd071825971ed84d9b52402764474bd168..fa2964267f472a4bfcbefaae9f4e616311ea6f57 100644 (file)
@@ -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);