blob: 613bba2126944f2b16f252a9cd5904ff6c0feb1e [file] [log] [blame]
Patrick Williams2194f502022-10-16 14:26:09 -05001From 9d22fba096cd77101fc45420c918ec748d2cc31b 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
Andrew Geisslere34f8962021-04-15 15:53:51 -050021Refit patch of open-vm-tools/lib/nicInfo/nicInfoPosix.c
22
Brad Bishopd7bf8c12018-02-25 22:55:05 -050023Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Andrew Geisslere34f8962021-04-15 15:53:51 -050024Signed-off-by: Randy MacLeod <randy.macleod@windriver.com>
Brad Bishopd7bf8c12018-02-25 22:55:05 -050025---
26 open-vm-tools/configure.ac | 4 ++++
Brad Bishop15ae2502019-06-18 21:44:24 -040027 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 Bishopd7bf8c12018-02-25 22:55:05 -050030
Brad Bishop15ae2502019-06-18 21:44:24 -040031diff --git a/open-vm-tools/configure.ac b/open-vm-tools/configure.ac
Patrick Williams2194f502022-10-16 14:26:09 -050032index 05f37f275..9a0c63cf6 100644
Brad Bishop15ae2502019-06-18 21:44:24 -040033--- a/open-vm-tools/configure.ac
34+++ b/open-vm-tools/configure.ac
Patrick Williams2194f502022-10-16 14:26:09 -050035@@ -1169,6 +1169,7 @@ AC_CHECK_FUNCS(
Brad Bishopd7bf8c12018-02-25 22:55:05 -050036
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 Williams2194f502022-10-16 14:26:09 -050043@@ -1378,10 +1379,13 @@ fi
Brad Bishopd7bf8c12018-02-25 22:55:05 -050044 ###
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 Bishop15ae2502019-06-18 21:44:24 -040057diff --git a/open-vm-tools/lib/misc/idLinux.c b/open-vm-tools/lib/misc/idLinux.c
Patrick Williams2194f502022-10-16 14:26:09 -050058index 1bb86f483..41c670cfc 100644
Brad Bishop15ae2502019-06-18 21:44:24 -040059--- a/open-vm-tools/lib/misc/idLinux.c
60+++ b/open-vm-tools/lib/misc/idLinux.c
Brad Bishopd7bf8c12018-02-25 22:55:05 -050061@@ -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 Geisslere34f8962021-04-15 15:53:51 -050075@@ -1025,31 +1022,32 @@ Id_EndSuperUser(uid_t uid) // IN:
Brad Bishopd7bf8c12018-02-25 22:55:05 -050076 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 Bishop15ae2502019-06-18 21:44:24 -0400120diff --git a/open-vm-tools/lib/nicInfo/nicInfoPosix.c b/open-vm-tools/lib/nicInfo/nicInfoPosix.c
Patrick Williams2194f502022-10-16 14:26:09 -0500121index de57a4a90..c56b73cfe 100644
Brad Bishop15ae2502019-06-18 21:44:24 -0400122--- a/open-vm-tools/lib/nicInfo/nicInfoPosix.c
123+++ b/open-vm-tools/lib/nicInfo/nicInfoPosix.c
Andrew Geisslere34f8962021-04-15 15:53:51 -0500124@@ -35,9 +35,13 @@
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500125 #include <sys/stat.h>
126 #include <errno.h>
Andrew Geisslere34f8962021-04-15 15:53:51 -0500127 #include <limits.h>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500128-#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 Geisslere34f8962021-04-15 15:53:51 -0500139--
Patrick Williams2194f502022-10-16 14:26:09 -05001402.25.1
Andrew Geisslere34f8962021-04-15 15:53:51 -0500141