From: VMware, Inc <> Date: Mon, 26 Jul 2010 19:20:10 +0000 (-0700) Subject: Fix euidaccess call in lib/file X-Git-Tag: 2010.07.25-280253~13 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d6bf6f96b8bb690089cd6b60b57aa3511161a2d5;p=thirdparty%2Fopen-vm-tools.git Fix euidaccess call in lib/file 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 --- diff --git a/open-vm-tools/lib/file/file.c b/open-vm-tools/lib/file/file.c index 54ac6d02c..3b8306486 100644 --- a/open-vm-tools/lib/file/file.c +++ b/open-vm-tools/lib/file/file.c @@ -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; } diff --git a/open-vm-tools/lib/file/filePosix.c b/open-vm-tools/lib/file/filePosix.c index 5bd4ba6cb..09244a75d 100644 --- a/open-vm-tools/lib/file/filePosix.c +++ b/open-vm-tools/lib/file/filePosix.c @@ -41,9 +41,6 @@ # endif #include #endif -#if defined(GLIBC_VERSION_24) -#define _GNU_SOURCE -#endif #include #include #include @@ -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 { diff --git a/open-vm-tools/lib/include/posix.h b/open-vm-tools/lib/include/posix.h index 4a0500122..c5f2db352 100644 --- a/open-vm-tools/lib/include/posix.h +++ b/open-vm-tools/lib/include/posix.h @@ -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); diff --git a/open-vm-tools/lib/misc/posixPosix.c b/open-vm-tools/lib/misc/posixPosix.c index d5df87d4c..e2375af1f 100644 --- a/open-vm-tools/lib/misc/posixPosix.c +++ b/open-vm-tools/lib/misc/posixPosix.c @@ -21,6 +21,11 @@ #endif #define UNICODE_BUILDING_POSIX_WRAPPERS + +#if __linux__ +#define _GNU_SOURCE // Needed to get euidaccess() +#endif + #include #include #include @@ -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 +} + + /* *---------------------------------------------------------------------- *