blob: c6378b8086547cdde5ab545d61012838b9a7344a [file] [log] [blame]
Brad Bishop15ae2502019-06-18 21:44:24 -04001From 719d60978f979cf2e03771a9b8a62e36c92639f9 Mon Sep 17 00:00:00 2001
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002From: Natanael Copa <ncopa@alpinelinux.org>
3Date: Wed, 18 Nov 2015 10:05:07 +0000
Brad Bishop15ae2502019-06-18 21:44:24 -04004Subject: [PATCH] Use configure to test for feature instead of platform
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005
6Test for various functions instead of trying to keep track of what
7platform and what version of the given platform has support for what.
8
9This should make it easier to port to currently unknown platforms and
10will solve the issue if a platform add support for a missing feature in
11the future.
12
13The features we test for are:
14- getifaddrs
15- getauxval
16- issetugid
17- __secure_getenv
18
19This is needed for musl libc.
20
21Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
22---
23 open-vm-tools/configure.ac | 4 ++++
Brad Bishop15ae2502019-06-18 21:44:24 -040024 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 Bishopd7bf8c12018-02-25 22:55:05 -050027
Brad Bishop15ae2502019-06-18 21:44:24 -040028diff --git a/open-vm-tools/configure.ac b/open-vm-tools/configure.ac
29index 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 Bishopd7bf8c12018-02-25 22:55:05 -050033
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 Bishop15ae2502019-06-18 21:44:24 -040040@@ -1145,10 +1146,13 @@ fi
Brad Bishopd7bf8c12018-02-25 22:55:05 -050041 ###
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 Bishop15ae2502019-06-18 21:44:24 -040054diff --git a/open-vm-tools/lib/misc/idLinux.c b/open-vm-tools/lib/misc/idLinux.c
55index b950cf84..1dcfb508 100644
56--- a/open-vm-tools/lib/misc/idLinux.c
57+++ b/open-vm-tools/lib/misc/idLinux.c
Brad Bishopd7bf8c12018-02-25 22:55:05 -050058@@ -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 Bishop15ae2502019-06-18 21:44:24 -0400117diff --git a/open-vm-tools/lib/nicInfo/nicInfoPosix.c b/open-vm-tools/lib/nicInfo/nicInfoPosix.c
118index a22981d5..b4e08681 100644
119--- a/open-vm-tools/lib/nicInfo/nicInfoPosix.c
120+++ b/open-vm-tools/lib/nicInfo/nicInfoPosix.c
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500121@@ -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