summaryrefslogtreecommitdiffstats
path: root/agent/command-ssh.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2017-02-03 17:13:08 +0100
committerWerner Koch <wk@gnupg.org>2017-02-03 17:13:08 +0100
commit309f464a5952c7d7504b875bf4853914b1242346 (patch)
tree7c81ec6fbd9c8f02bfcbef9dbcdd3f9323654b92 /agent/command-ssh.c
parentgpg: More diagnostics for a launched pinentry. (diff)
downloadgnupg2-309f464a5952c7d7504b875bf4853914b1242346.tar.xz
gnupg2-309f464a5952c7d7504b875bf4853914b1242346.zip
agent: Tell the Pinentry the client's pid.
* configure.ac: Check for SO_PEERCRED et al. * agent/agent.h (server_control_s): Add field 'client_pid'. * agent/command.c (start_command_handler): Set CLIENT_PID. * agent/command-ssh.c (get_client_pid): New. (start_command_handler_ssh): Set CLIENT_PID. * agent/call-pinentry.c (start_pinentry): Tell Pinentry the client-pid. Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'agent/command-ssh.c')
-rw-r--r--agent/command-ssh.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/agent/command-ssh.c b/agent/command-ssh.c
index f57bac397..1d4453c84 100644
--- a/agent/command-ssh.c
+++ b/agent/command-ssh.c
@@ -3491,6 +3491,44 @@ ssh_request_process (ctrl_t ctrl, estream_t stream_sock)
}
+/* Return the peer's pid. Stripped down code from libassuan. */
+static unsigned long
+get_client_pid (int fd)
+{
+ pid_t client_pid = (pid_t)(-1);
+
+#ifdef HAVE_SO_PEERCRED
+ {
+ struct ucred cr;
+ socklen_t cl = sizeof cr;
+
+ if ( !getsockopt (fd, SOL_SOCKET, SO_PEERCRED, &cr, &cl))
+ client_pid = cr.pid;
+ }
+#elif defined (HAVE_GETPEERUCRED)
+ {
+ ucred_t *ucred = NULL;
+
+ if (getpeerucred (fd, &ucred) != -1)
+ {
+ client_pid= ucred_getpid (ucred);
+ ucred_free (ucred);
+ }
+ }
+#elif defined (HAVE_LOCAL_PEEREID)
+ {
+ struct unpcbid unp;
+ socklen_t unpl = sizeof unp;
+
+ if (getsockopt (fd, 0, LOCAL_PEEREID, &unp, &unpl) != -1)
+ client_pid = unp.unp_pid;
+ }
+#endif
+
+ return client_pid == (pid_t)(-1)? 0 : (unsigned long)client_pid;
+}
+
+
/* Start serving client on SOCK_CLIENT. */
void
start_command_handler_ssh (ctrl_t ctrl, gnupg_fd_t sock_client)
@@ -3503,6 +3541,8 @@ start_command_handler_ssh (ctrl_t ctrl, gnupg_fd_t sock_client)
if (err)
goto out;
+ ctrl->client_pid = get_client_pid (FD2INT(sock_client));
+
/* Create stream from socket. */
stream_sock = es_fdopen (FD2INT(sock_client), "r+");
if (!stream_sock)