Blame SOURCES/pam_ssh_agent_auth-0.10.3-seteuid.patch

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