Patrick Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame^] | 1 | From 9d22fba096cd77101fc45420c918ec748d2cc31b 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 | |
Andrew Geissler | e34f896 | 2021-04-15 15:53:51 -0500 | [diff] [blame] | 21 | Refit patch of open-vm-tools/lib/nicInfo/nicInfoPosix.c |
| 22 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 23 | Signed-off-by: Natanael Copa <ncopa@alpinelinux.org> |
Andrew Geissler | e34f896 | 2021-04-15 15:53:51 -0500 | [diff] [blame] | 24 | Signed-off-by: Randy MacLeod <randy.macleod@windriver.com> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 25 | --- |
| 26 | open-vm-tools/configure.ac | 4 ++++ |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 27 | open-vm-tools/lib/misc/idLinux.c | 30 +++++++++++------------- |
| 28 | open-vm-tools/lib/nicInfo/nicInfoPosix.c | 6 ++++- |
| 29 | 3 files changed, 23 insertions(+), 17 deletions(-) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 30 | |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 31 | diff --git a/open-vm-tools/configure.ac b/open-vm-tools/configure.ac |
Patrick Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame^] | 32 | index 05f37f275..9a0c63cf6 100644 |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 33 | --- a/open-vm-tools/configure.ac |
| 34 | +++ b/open-vm-tools/configure.ac |
Patrick Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame^] | 35 | @@ -1169,6 +1169,7 @@ AC_CHECK_FUNCS( |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 36 | |
| 37 | AC_CHECK_FUNCS([ecvt]) |
| 38 | AC_CHECK_FUNCS([fcvt]) |
| 39 | +AC_CHECK_FUNCS([getifaddrs getauxval issetugid __secure_getenv]) |
| 40 | |
| 41 | AC_CHECK_FUNC([mkdtemp], [have_mkdtemp=yes]) |
| 42 | |
Patrick Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame^] | 43 | @@ -1378,10 +1379,13 @@ fi |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 44 | ### |
| 45 | |
| 46 | AC_CHECK_HEADERS([crypt.h]) |
| 47 | +AC_CHECK_HEADERS([ifaddrs.h]) |
| 48 | AC_CHECK_HEADERS([inttypes.h]) |
| 49 | AC_CHECK_HEADERS([stdint.h]) |
| 50 | AC_CHECK_HEADERS([stdlib.h]) |
| 51 | AC_CHECK_HEADERS([wchar.h]) |
| 52 | +AC_CHECK_HEADERS([net/if.h]) |
| 53 | +AC_CHECK_HEADERS([sys/auxv.h]) |
| 54 | AC_CHECK_HEADERS([sys/inttypes.h]) |
| 55 | AC_CHECK_HEADERS([sys/io.h]) |
| 56 | 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] | 57 | diff --git a/open-vm-tools/lib/misc/idLinux.c b/open-vm-tools/lib/misc/idLinux.c |
Patrick Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame^] | 58 | index 1bb86f483..41c670cfc 100644 |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 59 | --- a/open-vm-tools/lib/misc/idLinux.c |
| 60 | +++ b/open-vm-tools/lib/misc/idLinux.c |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 61 | @@ -27,12 +27,9 @@ |
| 62 | #include <sys/syscall.h> |
| 63 | #include <string.h> |
| 64 | #include <unistd.h> |
| 65 | -#ifdef __linux__ |
| 66 | -#if defined(__GLIBC__) && \ |
| 67 | - (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 16)) |
| 68 | +#ifdef HAVE_SYS_AUXV_H |
| 69 | #include <sys/auxv.h> |
| 70 | #endif |
| 71 | -#endif |
| 72 | #ifdef __APPLE__ |
| 73 | #include <sys/socket.h> |
| 74 | #include <TargetConditionals.h> |
Andrew Geissler | e34f896 | 2021-04-15 15:53:51 -0500 | [diff] [blame] | 75 | @@ -1025,31 +1022,32 @@ Id_EndSuperUser(uid_t uid) // IN: |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 76 | static Bool |
| 77 | IdIsSetUGid(void) |
| 78 | { |
| 79 | -#if defined(__ANDROID__) |
| 80 | - /* Android does not have a secure_getenv, so be conservative. */ |
| 81 | - return TRUE; |
| 82 | -#else |
| 83 | /* |
| 84 | * We use __secure_getenv, which returns NULL if the binary is |
| 85 | - * setuid or setgid. Alternatives include, |
| 86 | + * setuid or setgid, when issetugid or getauxval(AT_SECURE) is not |
| 87 | + * available. Alternatives include, |
| 88 | * |
| 89 | - * a) getauxval(AT_SECURE); not available until glibc 2.16. |
| 90 | - * b) __libc_enable_secure; may not be exported. |
| 91 | + * a) issetugid(); not (yet?) available in glibc. |
| 92 | + * b) getauxval(AT_SECURE); not available until glibc 2.16. |
| 93 | + * c) __libc_enable_secure; may not be exported. |
| 94 | * |
| 95 | - * Use (a) when we are based on glibc 2.16, or newer. |
| 96 | + * Use (b) when we are based on glibc 2.16, or newer. |
| 97 | */ |
| 98 | |
| 99 | -#if defined(__GLIBC__) && \ |
| 100 | - (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 16)) |
| 101 | +#if HAVE_ISSETUGID |
| 102 | + return issetugid(); |
| 103 | +#elif HAVE_GETAUXVAL |
| 104 | return getauxval(AT_SECURE) != 0; |
| 105 | -#else |
| 106 | +#elif HAVE___SECURE_GETENV |
| 107 | static const char envName[] = "VMW_SETUGID_TEST"; |
| 108 | |
| 109 | if (setenv(envName, "1", TRUE) == -1) { |
| 110 | return TRUE; /* Conservative */ |
| 111 | } |
| 112 | return __secure_getenv(envName) == NULL; |
| 113 | -#endif |
| 114 | +#else |
| 115 | + /* Android does not have a secure_getenv, so be conservative. */ |
| 116 | + return TRUE; |
| 117 | #endif |
| 118 | } |
| 119 | #endif |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 120 | diff --git a/open-vm-tools/lib/nicInfo/nicInfoPosix.c b/open-vm-tools/lib/nicInfo/nicInfoPosix.c |
Patrick Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame^] | 121 | index de57a4a90..c56b73cfe 100644 |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 122 | --- a/open-vm-tools/lib/nicInfo/nicInfoPosix.c |
| 123 | +++ b/open-vm-tools/lib/nicInfo/nicInfoPosix.c |
Andrew Geissler | e34f896 | 2021-04-15 15:53:51 -0500 | [diff] [blame] | 124 | @@ -35,9 +35,13 @@ |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 125 | #include <sys/stat.h> |
| 126 | #include <errno.h> |
Andrew Geissler | e34f896 | 2021-04-15 15:53:51 -0500 | [diff] [blame] | 127 | #include <limits.h> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 128 | -#if defined(__FreeBSD__) || defined(__APPLE__) |
| 129 | +#if HAVE_SYS_SYSCTL_H |
| 130 | # include <sys/sysctl.h> |
| 131 | +#endif |
| 132 | +#if HAVE_IFADDRS_H |
| 133 | # include <ifaddrs.h> |
| 134 | +#endif |
| 135 | +#if HAVE_NET_IF_H |
| 136 | # include <net/if.h> |
| 137 | #endif |
| 138 | #ifndef NO_DNET |
Andrew Geissler | e34f896 | 2021-04-15 15:53:51 -0500 | [diff] [blame] | 139 | -- |
Patrick Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame^] | 140 | 2.25.1 |
Andrew Geissler | e34f896 | 2021-04-15 15:53:51 -0500 | [diff] [blame] | 141 | |