0007-Use-configure-to-test-for-feature-instead-of-platfor.patch 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. From 6cc1c22cc30320f56da552a76bd956db8f255b6a Mon Sep 17 00:00:00 2001
  2. From: Natanael Copa <ncopa@alpinelinux.org>
  3. Date: Wed, 18 Nov 2015 10:05:07 +0000
  4. Subject: [PATCH] Use configure to test for feature instead of platform
  5. Test for various functions instead of trying to keep track of what
  6. platform and what version of the given platform has support for what.
  7. This should make it easier to port to currently unknown platforms and
  8. will solve the issue if a platform add support for a missing feature in
  9. the future.
  10. The features we test for are:
  11. - getifaddrs
  12. - getauxval
  13. - issetugid
  14. - __secure_getenv
  15. This is needed for musl libc.
  16. Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
  17. [Retrieved (and slightly updated) from:
  18. http://cgit.openembedded.org/meta-openembedded/tree/meta-oe/recipes-support/open-vm-tools/open-vm-tools/0007-Use-configure-to-test-for-feature-instead-of-platfor.patch?h=sumo]
  19. Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
  20. ---
  21. open-vm-tools/configure.ac | 4 ++++
  22. open-vm-tools/lib/misc/idLinux.c | 30 ++++++++++++++----------------
  23. open-vm-tools/lib/nicInfo/nicInfoPosix.c | 8 ++++++--
  24. 3 files changed, 24 insertions(+), 18 deletions(-)
  25. Index: open-vm-tools/configure.ac
  26. ===================================================================
  27. --- open-vm-tools.orig/configure.ac
  28. +++ open-vm-tools/configure.ac
  29. @@ -798,6 +798,7 @@ AC_CHECK_FUNCS(
  30. AC_CHECK_FUNCS([ecvt])
  31. AC_CHECK_FUNCS([fcvt])
  32. +AC_CHECK_FUNCS([getifaddrs getauxval issetugid __secure_getenv])
  33. AC_CHECK_FUNC([mkdtemp], [have_mkdtemp=yes])
  34. @@ -1063,10 +1064,13 @@ AC_PATH_PROG(
  35. ###
  36. AC_CHECK_HEADERS([crypt.h])
  37. +AC_CHECK_HEADERS([ifaddrs.h])
  38. AC_CHECK_HEADERS([inttypes.h])
  39. AC_CHECK_HEADERS([stdint.h])
  40. AC_CHECK_HEADERS([stdlib.h])
  41. AC_CHECK_HEADERS([wchar.h])
  42. +AC_CHECK_HEADERS([net/if.h])
  43. +AC_CHECK_HEADERS([sys/auxv.h])
  44. AC_CHECK_HEADERS([sys/inttypes.h])
  45. AC_CHECK_HEADERS([sys/io.h])
  46. AC_CHECK_HEADERS([sys/param.h]) # Required to make the sys/user.h check work correctly on FreeBSD
  47. Index: open-vm-tools/lib/misc/idLinux.c
  48. ===================================================================
  49. --- open-vm-tools.orig/lib/misc/idLinux.c
  50. +++ open-vm-tools/lib/misc/idLinux.c
  51. @@ -27,12 +27,9 @@
  52. #include <sys/syscall.h>
  53. #include <string.h>
  54. #include <unistd.h>
  55. -#ifdef __linux__
  56. -#if defined(__GLIBC__) && \
  57. - (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 16))
  58. +#ifdef HAVE_SYS_AUXV_H
  59. #include <sys/auxv.h>
  60. #endif
  61. -#endif
  62. #ifdef __APPLE__
  63. #include <sys/socket.h>
  64. #include <TargetConditionals.h>
  65. @@ -997,31 +994,32 @@ Id_EndSuperUser(uid_t uid) // IN:
  66. static Bool
  67. IdIsSetUGid(void)
  68. {
  69. -#if defined(__ANDROID__)
  70. - /* Android does not have a secure_getenv, so be conservative. */
  71. - return TRUE;
  72. -#else
  73. /*
  74. * We use __secure_getenv, which returns NULL if the binary is
  75. - * setuid or setgid. Alternatives include,
  76. + * setuid or setgid, when issetugid or getauxval(AT_SECURE) is not
  77. + * available. Alternatives include,
  78. *
  79. - * a) getauxval(AT_SECURE); not available until glibc 2.16.
  80. - * b) __libc_enable_secure; may not be exported.
  81. + * a) issetugid(); not (yet?) available in glibc.
  82. + * b) getauxval(AT_SECURE); not available until glibc 2.16.
  83. + * c) __libc_enable_secure; may not be exported.
  84. *
  85. - * Use (a) when we are based on glibc 2.16, or newer.
  86. + * Use (b) when we are based on glibc 2.16, or newer.
  87. */
  88. -#if defined(__GLIBC__) && \
  89. - (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 16))
  90. +#if HAVE_ISSETUGID
  91. + return issetugid();
  92. +#elif HAVE_GETAUXVAL
  93. return getauxval(AT_SECURE) != 0;
  94. -#else
  95. +#elif HAVE___SECURE_GETENV
  96. static const char envName[] = "VMW_SETUGID_TEST";
  97. if (setenv(envName, "1", TRUE) == -1) {
  98. return TRUE; /* Conservative */
  99. }
  100. return __secure_getenv(envName) == NULL;
  101. -#endif
  102. +#else
  103. + /* Android does not have a secure_getenv, so be conservative. */
  104. + return TRUE;
  105. #endif
  106. }
  107. #endif
  108. Index: open-vm-tools/lib/nicInfo/nicInfoPosix.c
  109. ===================================================================
  110. --- open-vm-tools.orig/lib/nicInfo/nicInfoPosix.c
  111. +++ open-vm-tools/lib/nicInfo/nicInfoPosix.c
  112. @@ -34,9 +34,13 @@
  113. #include <sys/socket.h>
  114. #include <sys/stat.h>
  115. #include <errno.h>
  116. -#if defined(__FreeBSD__) || defined(__APPLE__)
  117. +#if HAVE_SYS_SYSCTL_H
  118. # include <sys/sysctl.h>
  119. +#endif
  120. +#if HAVE_IFADDRS_H
  121. # include <ifaddrs.h>
  122. +#endif
  123. +#if HAVE_NET_IF_H
  124. # include <net/if.h>
  125. #endif
  126. #ifndef NO_DNET
  127. @@ -348,10 +352,7 @@ GuestInfoGetNicInfo(NicInfoV3 *nicInfo)
  128. *
  129. ******************************************************************************
  130. */
  131. -#if defined(__FreeBSD__) || \
  132. - defined(__APPLE__) || \
  133. - defined(USERWORLD) || \
  134. - (defined(__linux__) && defined(NO_DNET))
  135. +#if defined(NO_DNET) && defined(HAVE_GETIFADDRS)
  136. char *
  137. GuestInfoGetPrimaryIP(void)