summaryrefslogtreecommitdiff
path: root/debian/patches-applied/hurd_no_setfsuid
blob: 24ce40a0c693436c45e4578f9d14ee67daa4eb5d (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
On systems without setfsuid(), use setreuid() instead.

Authors: Steve Langasek <vorlon@debian.org>

Upstream status: superseded by pam_modutil_set_euid proposal

Index: pam.deb/modules/pam_xauth/pam_xauth.c
===================================================================
--- pam.deb.orig/modules/pam_xauth/pam_xauth.c
+++ pam.deb/modules/pam_xauth/pam_xauth.c
@@ -35,7 +35,9 @@
 
 #include "config.h"
 #include <sys/types.h>
+#ifdef HAVE_SYS_FSUID_H
 #include <sys/fsuid.h>
+#endif /* HAVE_SYS_FSUID_H */
 #include <sys/wait.h>
 #include <errno.h>
 #include <fnmatch.h>
@@ -218,6 +220,9 @@
 	FILE *fp;
 	int i;
 	uid_t euid;
+#ifndef HAVE_SYS_FSUID_H
+	uid_t uid;
+#endif
 	/* Check this user's <sense> file. */
 	pwd = pam_modutil_getpwnam(pamh, this_user);
 	if (pwd == NULL) {
@@ -234,9 +239,34 @@
 		return PAM_SESSION_ERR;
 	}
 	euid = geteuid();
+#ifdef HAVE_SYS_FSUID_H
 	setfsuid(pwd->pw_uid);
+#else
+	uid = getuid();
+	if (uid == pwd->pw_uid)
+		setreuid(euid, uid);
+	else {
+		setreuid(0, -1);
+		if (setreuid(-1, uid) == -1) {
+			setreuid(-1, 0);
+			setreuid(0, -1);
+			if (setreuid(-1, pwd->pw_uid))
+				return PAM_CRED_INSUFFICIENT;
+		}
+	}
+#endif
 	fp = fopen(path, "r");
+#ifdef HAVE_SYS_FSUID_H
 	setfsuid(euid);
+#else
+	if (uid == pwd->pw_uid)
+		setreuid(uid, euid);
+	else {
+		if (setreuid(-1, 0) != -1)
+			setreuid(uid, -1);
+		setreuid(-1, euid);
+	}
+#endif
 	if (fp != NULL) {
 		char buf[LINE_MAX], *tmp;
 		/* Scan the file for a list of specs of users to "trust". */
@@ -306,6 +336,9 @@
 	int fd, i, debug = 0;
 	int retval = PAM_SUCCESS;
 	uid_t systemuser = 499, targetuser = 0, euid;
+#ifndef HAVE_SYS_FSUID_H
+	uid_t uid;
+#endif
 
 	/* Parse arguments.  We don't understand many, so no sense in breaking
 	 * this into a separate function. */
@@ -554,7 +587,22 @@
 
 		/* Generate a new file to hold the data. */
 		euid = geteuid();
+#ifdef HAVE_SYS_FSUID_H
 		setfsuid(tpwd->pw_uid);
+#else
+		uid = getuid();
+		if (uid == tpwd->pw_uid)
+			setreuid(euid, uid);
+		else {
+			setreuid(0, -1);
+			if (setreuid(-1, uid) == -1) {
+				setreuid(-1, 0);
+				setreuid(0, -1);
+				if (setreuid(-1, tpwd->pw_uid))
+					return PAM_CRED_INSUFFICIENT;
+			}
+		}
+#endif
 		
 #ifdef WITH_SELINUX
 		if (is_selinux_enabled() > 0) {
@@ -584,7 +632,17 @@
 		save_errno = errno;
 #endif
 
+#ifdef HAVE_SYS_FSUID_H
 		setfsuid(euid);
+#else
+		if (uid == tpwd->pw_uid)
+			setreuid(uid, euid);
+		else {
+			if (setreuid(-1, 0) == -1)
+				setreuid(uid, -1);
+			setreuid(-1, euid);
+		}
+#endif
 		if (fd == -1) {
 			errno = save_errno;
 			pam_syslog(pamh, LOG_ERR,