blob: ad19fb24b903ab179b9b5d01b48bdeea62a9d93a [file] [log] [blame]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001From 6cc1c22cc30320f56da552a76bd956db8f255b6a Mon Sep 17 00:00:00 2001
2From: Natanael Copa <ncopa@alpinelinux.org>
3Date: Wed, 18 Nov 2015 10:05:07 +0000
4Subject: [PATCH 07/11] Use configure to test for feature instead of platform
5
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 ++++
24 open-vm-tools/lib/misc/idLinux.c | 30 ++++++++++++++----------------
25 open-vm-tools/lib/nicInfo/nicInfoPosix.c | 8 ++++++--
26 3 files changed, 24 insertions(+), 18 deletions(-)
27
28Index: open-vm-tools/configure.ac
29===================================================================
30--- open-vm-tools.orig/configure.ac
31+++ open-vm-tools/configure.ac
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080032@@ -892,6 +892,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 Bishop1a4b7ee2018-12-16 17:11:34 -080040@@ -1076,10 +1077,13 @@ AC_PATH_PROG(
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
54Index: open-vm-tools/lib/misc/idLinux.c
55===================================================================
56--- open-vm-tools.orig/lib/misc/idLinux.c
57+++ open-vm-tools/lib/misc/idLinux.c
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
117Index: open-vm-tools/lib/nicInfo/nicInfoPosix.c
118===================================================================
119--- open-vm-tools.orig/lib/nicInfo/nicInfoPosix.c
120+++ open-vm-tools/lib/nicInfo/nicInfoPosix.c
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