agent: Fix sending connecting process uid to pinentry.
authorNIIBE Yutaka <gniibe@fsij.org>
Fri, 26 Jan 2018 01:52:56 +0000 (10:52 +0900)
committerNIIBE Yutaka <gniibe@fsij.org>
Fri, 26 Jan 2018 01:52:56 +0000 (10:52 +0900)
* agent/command-ssh.c (get_client_info): Use LOCAL_PEERCRED.

--

LOCAL_PEERUID was wrong (while there is LOCAL_PEERUUID).
For FreeBSD and macOS, we can use LOCAL_PEERCRED to get uid.

GnuPG-bug-id: 3757
Fixes-commit: 28aa6890588cc108639951bb4bef03ac17743046
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
agent/command-ssh.c

index 4ec02ec..7155446 100644 (file)
@@ -3622,7 +3622,15 @@ get_client_info (int fd, struct peer_info_s *out)
     socklen_t len = sizeof (pid_t);
 
     getsockopt (fd, SOL_LOCAL, LOCAL_PEERPID, &client_pid, &len);
-    getsockopt (fd, SOL_LOCAL, LOCAL_PEERUID, &client_uid, &len);
+#if defined (LOCAL_PEERCRED)
+    {
+      struct xucred cr;
+      len = sizeof (struct xucred);
+
+      if (!getsockopt (fd, SOL_LOCAL, LOCAL_PEERCRED, &cr, &len))
+       client_uid = cr.cr_uid;
+    }
+#endif
   }
 #elif defined (LOCAL_PEEREID)
   {