From 660eafa3a9f68e116e9b0597edc317d8ff90f9b2 Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Fri, 26 Jan 2018 10:52:56 +0900 Subject: [PATCH] agent: Fix sending connecting process uid to pinentry. * 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 --- agent/command-ssh.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/agent/command-ssh.c b/agent/command-ssh.c index 4ec02ec02..715544635 100644 --- a/agent/command-ssh.c +++ b/agent/command-ssh.c @@ -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) {