465b6e6
diff -up openssh-7.4p1/pam_ssh_agent_auth-0.10.3/iterate_ssh_agent_keys.c.psaa-seteuid openssh-7.4p1/pam_ssh_agent_auth-0.10.3/iterate_ssh_agent_keys.c
465b6e6
--- openssh-7.4p1/pam_ssh_agent_auth-0.10.3/iterate_ssh_agent_keys.c.psaa-seteuid	2017-02-07 15:41:53.172334151 +0100
465b6e6
+++ openssh-7.4p1/pam_ssh_agent_auth-0.10.3/iterate_ssh_agent_keys.c	2017-02-07 15:41:53.174334149 +0100
465b6e6
@@ -238,17 +238,26 @@ ssh_get_authentication_socket_for_uid(ui
Jan F bb5eb00
 	}
Jan F bb5eb00
 
Jan F bb5eb00
 	errno = 0; 
Jan F bb5eb00
-	seteuid(uid); /* To ensure a race condition is not used to circumvent the stat
Jan F bb5eb00
-	             above, we will temporarily drop UID to the caller */
465b6e6
-	if (connect(sock, (struct sockaddr *)&sunaddr, sizeof sunaddr) < 0) {
Jan F bb5eb00
+	/* To ensure a race condition is not used to circumvent the stat
Jan F bb5eb00
+	   above, we will temporarily drop UID to the caller */
Jan F bb5eb00
+	if (seteuid(uid) == -1) {
Jan F bb5eb00
 		close(sock);
Jan F bb5eb00
-        if(errno == EACCES)
Jan F bb5eb00
-		fatal("MAJOR SECURITY WARNING: uid %lu made a deliberate and malicious attempt to open an agent socket owned by another user", (unsigned long) uid);
465b6e6
+		error("seteuid(%lu) failed with error: %s",
465b6e6
+		    (unsigned long) uid, strerror(errno));
465b6e6
 		return -1;
465b6e6
 	}
465b6e6
+	if (connect(sock, (struct sockaddr *)&sunaddr, sizeof sunaddr) < 0) {
465b6e6
+		close(sock);
Jan F bb5eb00
+		sock = -1;
Jan F bb5eb00
+		if(errno == EACCES)
Jan F bb5eb00
+			fatal("MAJOR SECURITY WARNING: uid %lu made a deliberate and malicious attempt to open an agent socket owned by another user", (unsigned long) uid);
465b6e6
+	}
465b6e6
 
465b6e6
-	seteuid(0); /* we now continue the regularly scheduled programming */
465b6e6
-
465b6e6
+	/* we now continue the regularly scheduled programming */
465b6e6
+	if (0 != seteuid(0)) {
465b6e6
+		fatal("setuid(0) failed with error: %s", strerror(errno));
465b6e6
+		return -1;
465b6e6
+	}
465b6e6
 	return sock;
465b6e6
 }
Jan F bb5eb00