]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Fix euidaccess call in lib/file
authorVMware, Inc <>
Mon, 26 Jul 2010 19:20:10 +0000 (12:20 -0700)
committerMarcelo Vanzin <mvanzin@vmware.com>
Mon, 26 Jul 2010 19:20:10 +0000 (12:20 -0700)
cs 899353 added some broken code inside #ifdef GLIBC_VERSION_24.
Since GLIBC_VERSION_24 was erroneously never set, this went unnoticed
for a long time.  This change creates a new Posix_EuidAccess()
function and calls it directly instead of embedding euidaccess()
inside FileAttributes() in lib/file.  When Posix_EuidAccess() is
unavailable, the fallback uses FileAttributes().

Signed-off-by: Marcelo Vanzin <mvanzin@vmware.com>
open-vm-tools/lib/file/file.c
open-vm-tools/lib/file/filePosix.c
open-vm-tools/lib/include/posix.h
open-vm-tools/lib/misc/posixPosix.c

index 54ac6d02c0e838d049248db957e24c0d9d63a047..3b830648625d44d6f0c0e8916e7890ead8dbe559 100644 (file)
@@ -77,9 +77,9 @@
  *
  *      XXX - This function invokes access(), which uses the real uid,
  *      not the effective uid, so it probably does not do what you 
- *      expect.  Instead it should use FileAttributes(), which calls
- *      Posix_Stat() and uses the effective uid, but it's too risky 
- *      to fix right now.  See PR 459242.
+ *      expect.  Instead it should use Posix_EuidAccess(), which 
+ *      uses the effective uid, but it's too risky to fix right now.
+ *      See PR 459242.
  *
  * Results:
  *      TRUE    file is accessible with the process' real uid
@@ -2049,15 +2049,15 @@ File_DeleteDirectoryTree(ConstUnicode pathName)  // IN: directory to delete
    Unicode *fileList = NULL;
    Bool sawFileError = FALSE;
 
-   switch (FileAttributes(pathName, NULL)) {
-   case 0:
-      break;
-   case ENOENT:
-   case ENOTDIR:
-      /* path does not exist or is inaccessible */
-      return TRUE;
-   default:
-      return FALSE;
+   if (Posix_EuidAccess(pathName, F_OK)) {
+      switch (errno) {
+      case ENOENT:
+      case ENOTDIR:
+         /* path does not exist or is inaccessible */
+         return TRUE;
+      default:
+         break;
+      }
    }
 
    /* get list of files in current directory */
@@ -2238,7 +2238,10 @@ File_FindFileInSearchPath(const char *fileIn,      // IN:
       cur = Str_SafeAsprintf(NULL, "%s%s%s", cwd, DIRSEPS, fileIn);
    }
 
-   if (FileAttributes(cur, NULL) == 0) {
+   if (Posix_EuidAccess(cur, F_OK) == 0) {
+      goto done;
+   }
+   if (errno == ENOSYS && FileAttributes(cur, NULL) == 0) {
       goto done;
    }
 
@@ -2270,7 +2273,10 @@ File_FindFileInSearchPath(const char *fileIn,      // IN:
          }
       }
 
-      if (FileAttributes(cur, NULL) == 0) {
+      if (Posix_EuidAccess(cur, F_OK) == 0) {
+         break;
+      }
+      if (errno == ENOSYS && FileAttributes(cur, NULL) == 0) {
          break;
       }
 
index 5bd4ba6cbc4c07ace1a69237b4977c819d15a88f..09244a75db45fa196b753141666d89839ddd52ac 100644 (file)
@@ -41,9 +41,6 @@
 # endif
 #include <signal.h>
 #endif
-#if defined(GLIBC_VERSION_24)
-#define _GNU_SOURCE
-#endif
 #include <unistd.h>
 #include <errno.h>
 #include <sys/stat.h>
@@ -292,20 +289,6 @@ FileAttributes(ConstUnicode pathName,  // IN:
    int err;
    struct stat statbuf;
 
-#if defined(GLIBC_VERSION_24)
-   char *path;
-
-   if (fileData == NULL) {
-      if (!PosixConvertToCurrent(pathName, &path)) {
-         return -1;
-      }
-      ret = euidaccess(path, F_OK);
-      free(path);
-
-      return ret;
-   }
-#endif
-
    if (Posix_Stat(pathName, &statbuf) == -1) {
       err = errno;
    } else {
index 4a0500122411bd4080fafa6b1b95b7373b5de3ef..c5f2db35264a6b9c5a9a19e0e206eeffa16f0d86 100644 (file)
@@ -74,6 +74,7 @@ int Posix_Rmdir(ConstUnicode pathName);
 int Posix_Unlink(ConstUnicode pathName);
 FILE *Posix_Freopen(ConstUnicode pathName, const char *mode, FILE *stream);
 int Posix_Access(ConstUnicode pathName, int mode);
+int Posix_EuidAccess(ConstUnicode pathName, int mode);
 int Posix_Stat(ConstUnicode pathName, struct stat *statbuf);
 int Posix_Chmod(ConstUnicode pathName, mode_t mode);
 void Posix_Perror(ConstUnicode str);
index d5df87d4c8576ca3b5b3566ef1eebcea00011912..e2375af1fdbdf70e7f3c28a6a42df050753e8bec 100644 (file)
 #endif
 
 #define UNICODE_BUILDING_POSIX_WRAPPERS
+
+#if __linux__
+#define _GNU_SOURCE // Needed to get euidaccess()
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <fcntl.h>
@@ -82,6 +87,8 @@
 #include "hashTable.h" // For setenv emulation
 #endif
 
+#include "vm_basic_defs.h"
+
 #if !defined(N_PLAT_NLM)
 static struct passwd *GetpwInternal(struct passwd *pw);
 static int GetpwInternal_r(struct passwd *pw, char *buf, size_t size,
@@ -459,6 +466,47 @@ Posix_Access(ConstUnicode pathName,  // IN:
 }
 
 
+/*
+ *----------------------------------------------------------------------
+ *
+ * Posix_EuidAccess --
+ *
+ *      POSIX euidaccess().
+ *
+ * Results:
+ *      -1     Error
+ *      0      Success
+ *
+ * Side effects:
+ *      errno is set on error
+ *
+ *----------------------------------------------------------------------
+ */
+
+int
+Posix_EuidAccess(ConstUnicode pathName,  // IN:
+                 int mode)               // IN:
+{
+#if defined(GLIBC_VERSION_24)
+   char *path;
+   int ret;
+   int err;
+
+   if (!PosixConvertToCurrent(pathName, &path)) {
+      return -1;
+   }
+   ret = euidaccess(path, mode);
+   err = errno;
+   free(path);
+   errno = err;
+   return ret;
+#else
+   errno = ENOSYS;
+   return -1;
+#endif
+}
+
+
 /*
  *----------------------------------------------------------------------
  *