1From 9e42c405f30d2b52d019598436ea346ef8586f43 Mon Sep 17 00:00:00 2001 2From: =?UTF-8?q?No=C3=A9=20Rubinstein?= <nrubinstein@aldebaran.com> 3Date: Wed, 24 Aug 2016 18:55:25 +0200 4Subject: [PATCH] Check that getpwent_r is available before using it 5 6This fixes building trousers with musl 7 8Signed-off-by: Noé Rubinstein <nrubinstein@aldebaran.com> 9[Bernd: Rebased for version 0.3.14] 10Signed-off-by: Bernd Kuhls <bernd.kuhls@t-online.de> 11--- 12 configure.ac | 4 ++++ 13 src/tspi/ps/tspps.c | 10 +++++----- 14 2 files changed, 9 insertions(+), 5 deletions(-) 15 16diff --git a/configure.in b/configure.in 17index fd3f5f1..e3d7acf 100644 18--- a/configure.ac 19+++ b/configure.ac 20@@ -145,6 +145,10 @@ else 21 AC_MSG_ERROR(["gtk", "openssl" and "none" are the only supported gui options for trousers]) 22 fi 23 24+# Look for getpwent_r. If it is not found, getpwent will be used instead, with 25+# an additional mutex. 26+AC_CHECK_FUNC(getpwent_r, [AC_DEFINE(HAVE_GETPWENT_R)]) 27+ 28 # 29 # The default port that the TCS daemon listens on 30 # 31diff --git a/src/tspi/ps/tspps.c b/src/tspi/ps/tspps.c 32index c6f9c3d..9d00d2a 100644 33--- a/src/tspi/ps/tspps.c 34+++ b/src/tspi/ps/tspps.c 35@@ -45,7 +45,7 @@ 36 37 static int user_ps_fd = -1; 38 static MUTEX_DECLARE_INIT(user_ps_lock); 39-#if (defined (__FreeBSD__) || defined (__OpenBSD__)) 40+#ifndef HAVE_GETPWENT_R 41 static MUTEX_DECLARE_INIT(user_ps_path); 42 #endif 43 static struct flock fl; 44@@ -60,7 +60,7 @@ get_user_ps_path(char **file) 45 TSS_RESULT result; 46 char *file_name = NULL, *home_dir = NULL; 47 struct passwd *pwp; 48-#if (defined (__linux) || defined (linux) || defined(__GLIBC__)) 49+#ifdef HAVE_GETPWENT_R 50 struct passwd pw; 51 #endif 52 struct stat stat_buf; 53@@ -72,7 +72,7 @@ get_user_ps_path(char **file) 54 *file = strdup(file_name); 55 return (*file) ? TSS_SUCCESS : TSPERR(TSS_E_OUTOFMEMORY); 56 } 57-#if (defined (__FreeBSD__) || defined (__OpenBSD__)) 58+#ifndef HAVE_GETPWENT_R 59 MUTEX_LOCK(user_ps_path); 60 #endif 61 62@@ -90,7 +90,7 @@ get_user_ps_path(char **file) 63 #else 64 setpwent(); 65 while (1) { 66-#if (defined (__linux) || defined (linux) || defined(__GLIBC__)) 67+#ifdef HAVE_GETPWENT_R 68 rc = getpwent_r(&pw, buf, PASSWD_BUFSIZE, &pwp); 69 if (rc) { 70 LogDebugFn("USER PS: Error getting path to home directory: getpwent_r: %s", 71@@ -99,7 +99,7 @@ get_user_ps_path(char **file) 72 return TSPERR(TSS_E_INTERNAL_ERROR); 73 } 74 75-#elif (defined (__FreeBSD__) || defined (__OpenBSD__)) 76+#else 77 if ((pwp = getpwent()) == NULL) { 78 LogDebugFn("USER PS: Error getting path to home directory: getpwent: %s", 79 strerror(rc)); 80-- 812.1.4 82 83