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>
*
* 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
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 */
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;
}
}
}
- if (FileAttributes(cur, NULL) == 0) {
+ if (Posix_EuidAccess(cur, F_OK) == 0) {
+ break;
+ }
+ if (errno == ENOSYS && FileAttributes(cur, NULL) == 0) {
break;
}
# endif
#include <signal.h>
#endif
-#if defined(GLIBC_VERSION_24)
-#define _GNU_SOURCE
-#endif
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
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 {
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);
#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>
#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,
}
+/*
+ *----------------------------------------------------------------------
+ *
+ * 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
+}
+
+
/*
*----------------------------------------------------------------------
*