summaryrefslogtreecommitdiff
path: root/security/trousers/files/patch-src-tspi-ps-tspps.c
blob: d58f17d5f48c2bc48d7c6b22d65efbfc243a9610 (plain) (blame)
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
--- src/tspi/ps/tspps.c.orig	2014-04-24 18:05:44 UTC
+++ src/tspi/ps/tspps.c
@@ -29,6 +29,11 @@
 #define LE_16 htole16
 #define LE_32 htole32
 #define LE_64 htole64
+#elif defined(HAVE_SYS_ENDIAN_H)
+#include <sys/endian.h>
+#define LE_16 htole16
+#define LE_32 htole32
+#define LE_64 htole64
 #else
 #define LE_16(x) (x)
 #define LE_32(x) (x)
@@ -43,9 +48,13 @@
 #include "tspps.h"
 #include "tsplog.h"
 
+
 static int user_ps_fd = -1;
 static MUTEX_DECLARE_INIT(user_ps_lock);
 #if (defined (__FreeBSD__) || defined (__OpenBSD__))
+#include <sys/endian.h>
+#define	LE_16 htole16
+#define	LE_32 htole32
 static MUTEX_DECLARE_INIT(user_ps_path);
 #endif
 static struct flock fl;
@@ -60,9 +69,7 @@ get_user_ps_path(char **file)
 	TSS_RESULT result;
 	char *file_name = NULL, *home_dir = NULL;
 	struct passwd *pwp;
-#if (defined (__linux) || defined (linux) || defined(__GLIBC__))
 	struct passwd pw;
-#endif
 	struct stat stat_buf;
 	char buf[PASSWD_BUFSIZE];
 	uid_t euid;
@@ -72,10 +79,6 @@ get_user_ps_path(char **file)
 		*file = strdup(file_name);
 		return (*file) ? TSS_SUCCESS : TSPERR(TSS_E_OUTOFMEMORY);
 	}
-#if (defined (__FreeBSD__) || defined (__OpenBSD__))
-	MUTEX_LOCK(user_ps_path);
-#endif
-
 	euid = geteuid();
 
 #if defined (SOLARIS)
@@ -88,32 +91,14 @@ get_user_ps_path(char **file)
          */
         rc = snprintf(buf, sizeof (buf), "%s/%d", TSS_USER_PS_DIR, euid);
 #else
-	setpwent();
-	while (1) {
-#if (defined (__linux) || defined (linux) || defined(__GLIBC__))
-		rc = getpwent_r(&pw, buf, PASSWD_BUFSIZE, &pwp);
-		if (rc) {
-			LogDebugFn("USER PS: Error getting path to home directory: getpwent_r: %s",
-				   strerror(rc));
-			endpwent();
-			return TSPERR(TSS_E_INTERNAL_ERROR);
-		}
+	rc = getpwuid_r(euid, &pw, buf, PASSWD_BUFSIZE, &pwp);
+	if (rc) {
+		LogDebugFn("USER PS: Error getting path to home directory: "
+			"getpwent_r: %s", strerror(rc));
+		return TSPERR(TSS_E_INTERNAL_ERROR);
+	}
 
-#elif (defined (__FreeBSD__) || defined (__OpenBSD__))
-		if ((pwp = getpwent()) == NULL) {
-			LogDebugFn("USER PS: Error getting path to home directory: getpwent: %s",
-                                   strerror(rc));
-			endpwent();
-			MUTEX_UNLOCK(user_ps_path);
-			return TSPERR(TSS_E_INTERNAL_ERROR);
-		}
-#endif
-		if (euid == pwp->pw_uid) {
-                        home_dir = strdup(pwp->pw_dir);
-                        break;
-                }
-        }
-        endpwent();
+	home_dir = strdup(pwp->pw_dir);
 
 	if (!home_dir)
 		return TSPERR(TSS_E_OUTOFMEMORY);