Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame^] | 1 | From 719d60978f979cf2e03771a9b8a62e36c92639f9 Mon Sep 17 00:00:00 2001 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2 | From: Natanael Copa <ncopa@alpinelinux.org> |
| 3 | Date: Wed, 18 Nov 2015 10:05:07 +0000 |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame^] | 4 | Subject: [PATCH] Use configure to test for feature instead of platform |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5 | |
| 6 | Test for various functions instead of trying to keep track of what |
| 7 | platform and what version of the given platform has support for what. |
| 8 | |
| 9 | This should make it easier to port to currently unknown platforms and |
| 10 | will solve the issue if a platform add support for a missing feature in |
| 11 | the future. |
| 12 | |
| 13 | The features we test for are: |
| 14 | - getifaddrs |
| 15 | - getauxval |
| 16 | - issetugid |
| 17 | - __secure_getenv |
| 18 | |
| 19 | This is needed for musl libc. |
| 20 | |
| 21 | Signed-off-by: Natanael Copa <ncopa@alpinelinux.org> |
| 22 | --- |
| 23 | open-vm-tools/configure.ac | 4 ++++ |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame^] | 24 | open-vm-tools/lib/misc/idLinux.c | 30 +++++++++++------------- |
| 25 | open-vm-tools/lib/nicInfo/nicInfoPosix.c | 6 ++++- |
| 26 | 3 files changed, 23 insertions(+), 17 deletions(-) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 27 | |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame^] | 28 | diff --git a/open-vm-tools/configure.ac b/open-vm-tools/configure.ac |
| 29 | index 48ff1ef3..71e684bb 100644 |
| 30 | --- a/open-vm-tools/configure.ac |
| 31 | +++ b/open-vm-tools/configure.ac |
| 32 | @@ -897,6 +897,7 @@ AC_CHECK_FUNCS( |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 33 | |
| 34 | AC_CHECK_FUNCS([ecvt]) |
| 35 | AC_CHECK_FUNCS([fcvt]) |
| 36 | +AC_CHECK_FUNCS([getifaddrs getauxval issetugid __secure_getenv]) |
| 37 | |
| 38 | AC_CHECK_FUNC([mkdtemp], [have_mkdtemp=yes]) |
| 39 | |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame^] | 40 | @@ -1145,10 +1146,13 @@ fi |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 41 | ### |
| 42 | |
| 43 | AC_CHECK_HEADERS([crypt.h]) |
| 44 | +AC_CHECK_HEADERS([ifaddrs.h]) |
| 45 | AC_CHECK_HEADERS([inttypes.h]) |
| 46 | AC_CHECK_HEADERS([stdint.h]) |
| 47 | AC_CHECK_HEADERS([stdlib.h]) |
| 48 | AC_CHECK_HEADERS([wchar.h]) |
| 49 | +AC_CHECK_HEADERS([net/if.h]) |
| 50 | +AC_CHECK_HEADERS([sys/auxv.h]) |
| 51 | AC_CHECK_HEADERS([sys/inttypes.h]) |
| 52 | AC_CHECK_HEADERS([sys/io.h]) |
| 53 | AC_CHECK_HEADERS([sys/param.h]) # Required to make the sys/user.h check work correctly on FreeBSD |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame^] | 54 | diff --git a/open-vm-tools/lib/misc/idLinux.c b/open-vm-tools/lib/misc/idLinux.c |
| 55 | index b950cf84..1dcfb508 100644 |
| 56 | --- a/open-vm-tools/lib/misc/idLinux.c |
| 57 | +++ b/open-vm-tools/lib/misc/idLinux.c |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 58 | @@ -27,12 +27,9 @@ |
| 59 | #include <sys/syscall.h> |
| 60 | #include <string.h> |
| 61 | #include <unistd.h> |
| 62 | -#ifdef __linux__ |
| 63 | -#if defined(__GLIBC__) && \ |
| 64 | - (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 16)) |
| 65 | +#ifdef HAVE_SYS_AUXV_H |
| 66 | #include <sys/auxv.h> |
| 67 | #endif |
| 68 | -#endif |
| 69 | #ifdef __APPLE__ |
| 70 | #include <sys/socket.h> |
| 71 | #include <TargetConditionals.h> |
| 72 | @@ -997,31 +994,32 @@ Id_EndSuperUser(uid_t uid) // IN: |
| 73 | static Bool |
| 74 | IdIsSetUGid(void) |
| 75 | { |
| 76 | -#if defined(__ANDROID__) |
| 77 | - /* Android does not have a secure_getenv, so be conservative. */ |
| 78 | - return TRUE; |
| 79 | -#else |
| 80 | /* |
| 81 | * We use __secure_getenv, which returns NULL if the binary is |
| 82 | - * setuid or setgid. Alternatives include, |
| 83 | + * setuid or setgid, when issetugid or getauxval(AT_SECURE) is not |
| 84 | + * available. Alternatives include, |
| 85 | * |
| 86 | - * a) getauxval(AT_SECURE); not available until glibc 2.16. |
| 87 | - * b) __libc_enable_secure; may not be exported. |
| 88 | + * a) issetugid(); not (yet?) available in glibc. |
| 89 | + * b) getauxval(AT_SECURE); not available until glibc 2.16. |
| 90 | + * c) __libc_enable_secure; may not be exported. |
| 91 | * |
| 92 | - * Use (a) when we are based on glibc 2.16, or newer. |
| 93 | + * Use (b) when we are based on glibc 2.16, or newer. |
| 94 | */ |
| 95 | |
| 96 | -#if defined(__GLIBC__) && \ |
| 97 | - (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 16)) |
| 98 | +#if HAVE_ISSETUGID |
| 99 | + return issetugid(); |
| 100 | +#elif HAVE_GETAUXVAL |
| 101 | return getauxval(AT_SECURE) != 0; |
| 102 | -#else |
| 103 | +#elif HAVE___SECURE_GETENV |
| 104 | static const char envName[] = "VMW_SETUGID_TEST"; |
| 105 | |
| 106 | if (setenv(envName, "1", TRUE) == -1) { |
| 107 | return TRUE; /* Conservative */ |
| 108 | } |
| 109 | return __secure_getenv(envName) == NULL; |
| 110 | -#endif |
| 111 | +#else |
| 112 | + /* Android does not have a secure_getenv, so be conservative. */ |
| 113 | + return TRUE; |
| 114 | #endif |
| 115 | } |
| 116 | #endif |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame^] | 117 | diff --git a/open-vm-tools/lib/nicInfo/nicInfoPosix.c b/open-vm-tools/lib/nicInfo/nicInfoPosix.c |
| 118 | index a22981d5..b4e08681 100644 |
| 119 | --- a/open-vm-tools/lib/nicInfo/nicInfoPosix.c |
| 120 | +++ b/open-vm-tools/lib/nicInfo/nicInfoPosix.c |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 121 | @@ -34,9 +34,13 @@ |
| 122 | #include <sys/socket.h> |
| 123 | #include <sys/stat.h> |
| 124 | #include <errno.h> |
| 125 | -#if defined(__FreeBSD__) || defined(__APPLE__) |
| 126 | +#if HAVE_SYS_SYSCTL_H |
| 127 | # include <sys/sysctl.h> |
| 128 | +#endif |
| 129 | +#if HAVE_IFADDRS_H |
| 130 | # include <ifaddrs.h> |
| 131 | +#endif |
| 132 | +#if HAVE_NET_IF_H |
| 133 | # include <net/if.h> |
| 134 | #endif |
| 135 | #ifndef NO_DNET |