aboutsummaryrefslogtreecommitdiffstats
path: root/main/open-vm-tools/0006-Use-configure-to-test-for-feature-instead-of-platfor.patch
blob: 33e720d6742e92a0537a23bdf51b2da8cb3fe834 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
From 1a6d86a39e8ac164074ed8e0be116e7c07bb886d Mon Sep 17 00:00:00 2001
From: Natanael Copa <ncopa@alpinelinux.org>
Date: Wed, 18 Nov 2015 10:05:07 +0000
Subject: [PATCH 06/11] Use configure to test for feature instead of platform

Test for various functions instead of trying to keep track of what
platform and what version of the given platform has support for what.

This should make it easier to port to currently unknown platforms and
will solve the issue if a platform add support for a missing feature in
the future.

The features we test for are:
- getifaddrs
- getauxval
- setresuid
- setresgid
- issetugid
- __secure_getenv

This is needed for musl libc.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
---
 open-vm-tools/configure.ac               |  4 ++++
 open-vm-tools/lib/misc/idLinux.c         | 30 ++++++++++++++----------------
 open-vm-tools/lib/nicInfo/nicInfoPosix.c |  8 ++++++--
 open-vm-tools/lib/procMgr/procMgrPosix.c |  9 ++++++---
 4 files changed, 30 insertions(+), 21 deletions(-)

diff --git a/open-vm-tools/configure.ac b/open-vm-tools/configure.ac
index 037679d..f474150 100644
--- a/open-vm-tools/configure.ac
+++ b/open-vm-tools/configure.ac
@@ -644,6 +644,7 @@ AC_CHECK_FUNCS(
 
 AC_CHECK_FUNCS([ecvt])
 AC_CHECK_FUNCS([fcvt])
+AC_CHECK_FUNCS([getifaddrs getauxval setresuid setresgid issetugid __secure_getenv])
 
 if test "$os" = "freebsd" -a "$osVersion" -ge 600000; then
    AC_CHECK_LIB(
@@ -861,10 +862,13 @@ AC_PATH_PROG(
 ###
 
 AC_CHECK_HEADERS([crypt.h])
+AC_CHECK_HEADERS([ifaddrs.h])
 AC_CHECK_HEADERS([inttypes.h])
 AC_CHECK_HEADERS([stdint.h])
 AC_CHECK_HEADERS([stdlib.h])
 AC_CHECK_HEADERS([wchar.h])
+AC_CHECK_HEADERS([net/if.h])
+AC_CHECK_HEADERS([sys/auxv.h])
 AC_CHECK_HEADERS([sys/inttypes.h])
 AC_CHECK_HEADERS([sys/io.h])
 AC_CHECK_HEADERS([sys/param.h]) # Required to make the sys/user.h check work correctly on FreeBSD
diff --git a/open-vm-tools/lib/misc/idLinux.c b/open-vm-tools/lib/misc/idLinux.c
index 58bcb53..a7d859f 100644
--- a/open-vm-tools/lib/misc/idLinux.c
+++ b/open-vm-tools/lib/misc/idLinux.c
@@ -27,12 +27,9 @@
 #include <sys/syscall.h>
 #include <string.h>
 #include <unistd.h>
-#ifdef __linux__
-#if defined(__GLIBC__) && \
-           (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 16))
+#ifdef HAVE_SYS_AUXV_H
 #include <sys/auxv.h>
 #endif
-#endif
 #ifdef __APPLE__
 #include <sys/socket.h>
 #include <TargetConditionals.h>
@@ -997,31 +994,32 @@ Id_EndSuperUser(uid_t uid)  // IN:
 static Bool
 IdIsSetUGid(void)
 {
-#if defined(__ANDROID__)
-   /* Android does not have a secure_getenv, so be conservative. */
-   return TRUE;
-#else
    /*
     * We use __secure_getenv, which returns NULL if the binary is
-    * setuid or setgid. Alternatives include,
+    * setuid or setgid, when issetugid or getauxval(AT_SECURE) is not
+    * available. Alternatives include,
     *
-    *   a) getauxval(AT_SECURE); not available until glibc 2.16.
-    *   b) __libc_enable_secure; may not be exported.
+    *   a) issetugid(); not (yet?) available in glibc.
+    *   b) getauxval(AT_SECURE); not available until glibc 2.16.
+    *   c) __libc_enable_secure; may not be exported.
     *
-    * Use (a) when we are based on glibc 2.16, or newer.
+    * Use (b) when we are based on glibc 2.16, or newer.
     */
 
-#if defined(__GLIBC__) && \
-           (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 16))
+#if HAVE_ISSETUGID
+   return issetugid();
+#elif HAVE_GETAUXVAL
    return getauxval(AT_SECURE) != 0;
-#else
+#elif HAVE___SECURE_GETENV
    static const char envName[] = "VMW_SETUGID_TEST";
 
    if (setenv(envName, "1", TRUE) == -1) {
       return TRUE; /* Conservative */
    }
    return __secure_getenv(envName) == NULL;
-#endif
+#else
+   /* Android does not have a secure_getenv, so be conservative. */
+   return TRUE;
 #endif
 }
 #endif
diff --git a/open-vm-tools/lib/nicInfo/nicInfoPosix.c b/open-vm-tools/lib/nicInfo/nicInfoPosix.c
index 4324637..e7ff9a2 100644
--- a/open-vm-tools/lib/nicInfo/nicInfoPosix.c
+++ b/open-vm-tools/lib/nicInfo/nicInfoPosix.c
@@ -34,9 +34,13 @@
 #include <sys/socket.h>
 #include <sys/stat.h>
 #include <errno.h>
-#if defined(__FreeBSD__) || defined(__APPLE__)
+#if HAVE_SYS_SYSCTL_H
 # include <sys/sysctl.h>
+#endif
+#if HAVE_IFADDRS_H
 # include <ifaddrs.h>
+#endif
+#if HAVE_NET_IF_H
 # include <net/if.h>
 #endif
 #ifndef NO_DNET
@@ -280,7 +284,7 @@ GuestInfoGetNicInfo(NicInfoV3 *nicInfo) // OUT
  *
  ******************************************************************************
  */
-#if defined(__FreeBSD__) || defined(__APPLE__) || defined(USERWORLD)
+#if defined(NO_DNET) && defined(HAVE_GETIFADDRS)
 
 char *
 GuestInfoGetPrimaryIP(void)
diff --git a/open-vm-tools/lib/procMgr/procMgrPosix.c b/open-vm-tools/lib/procMgr/procMgrPosix.c
index d0e78a4..5038b75 100644
--- a/open-vm-tools/lib/procMgr/procMgrPosix.c
+++ b/open-vm-tools/lib/procMgr/procMgrPosix.c
@@ -137,7 +137,7 @@ static int ProcMgrGetCommandLineArgs(long pid,
 #define  BASH_PATH "/bin/bash"
 #endif
 
-#if defined(linux) && !defined(GLIBC_VERSION_23) && !defined(__UCLIBC__)
+#if defined(linux)
 /*
  * Implements the system calls (they are not wrapped by glibc til 2.3.2).
  *
@@ -146,7 +146,7 @@ static int ProcMgrGetCommandLineArgs(long pid,
  *
  * (In fact, newer Linux kernels don't even define _syscall macros anymore.)
  */
-
+#ifndef HAVE_SETRESUID
 static INLINE int
 setresuid(uid_t ruid,
           uid_t euid,
@@ -154,8 +154,9 @@ setresuid(uid_t ruid,
 {
    return syscall(__NR_setresuid, ruid, euid, suid);
 }
+#endif
 
-
+#ifndef HAVE_SETRESGID
 static INLINE int
 setresgid(gid_t ruid,
           gid_t euid,
@@ -165,6 +166,8 @@ setresgid(gid_t ruid,
 }
 #endif
 
+#endif
+
 
 /*
  *----------------------------------------------------------------------
-- 
2.6.3