1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-01-03 12:11:33 +01:00

Support specifying the pipe name by the option.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
NIIBE Yutaka 2022-08-01 11:59:43 +09:00
parent 30df964607
commit c0a3748979
2 changed files with 37 additions and 39 deletions

View File

@ -3785,7 +3785,7 @@ start_command_handler_ssh_stream (ctrl_t ctrl, estream_t stream)
if (ret) if (ret)
{ {
log_error ("failed to disable buffering on socket stream: %s\n", log_error ("failed to disable buffering on socket stream: %s\n",
strerror (errno)); strerror (errno));
goto out; goto out;
} }
@ -3793,7 +3793,7 @@ start_command_handler_ssh_stream (ctrl_t ctrl, estream_t stream)
while ( !ssh_request_process (ctrl, stream) ) while ( !ssh_request_process (ctrl, stream) )
{ {
/* Check whether we have reached EOF before trying to read /* Check whether we have reached EOF before trying to read
another request. */ another request. */
int c; int c;
c = es_fgetc (stream); c = es_fgetc (stream);
@ -3830,7 +3830,7 @@ start_command_handler_ssh (ctrl_t ctrl, gnupg_fd_t sock_client)
if (!stream_sock) if (!stream_sock)
{ {
log_error (_("failed to create stream from socket: %s\n"), log_error (_("failed to create stream from socket: %s\n"),
strerror (errno)); strerror (errno));
return; return;
} }

View File

@ -230,7 +230,7 @@ static gpgrt_opt_t opts[] = {
/* */ "@" /* */ "@"
#endif #endif
), ),
ARGPARSE_s_n (oWin32OpenSSHSupport, "enable-win32-openssh-support", ARGPARSE_o_s (oWin32OpenSSHSupport, "enable-win32-openssh-support",
#ifdef HAVE_W32_SYSTEM #ifdef HAVE_W32_SYSTEM
/* */ N_("enable Win32-OpenSSH support") /* */ N_("enable Win32-OpenSSH support")
#else #else
@ -366,8 +366,9 @@ static int putty_support;
for the foreseeable future. */ for the foreseeable future. */
#define PUTTY_IPC_MAXLEN 16384 #define PUTTY_IPC_MAXLEN 16384
/* Flag indicating that support for Win32-OpenSSH has been enabled. */ /* Path to the pipe, which handles requests from Win32-OpenSSH. */
static int win32_openssh_support; static const char *win32_openssh_support;
#define W32_DEFAILT_AGENT_PIPE_NAME "\\\\.\\pipe\\openssh-ssh-agent"
#endif /*HAVE_W32_SYSTEM*/ #endif /*HAVE_W32_SYSTEM*/
/* The list of open file descriptors at startup. Note that this list /* The list of open file descriptors at startup. Note that this list
@ -1302,7 +1303,10 @@ main (int argc, char **argv)
case oWin32OpenSSHSupport: case oWin32OpenSSHSupport:
# ifdef HAVE_W32_SYSTEM # ifdef HAVE_W32_SYSTEM
win32_openssh_support = 1; if (pargs.r_type)
win32_openssh_support = pargs.r.ret_str;
else
win32_openssh_support = W32_DEFAILT_AGENT_PIPE_NAME;
# endif # endif
break; break;
@ -2763,9 +2767,7 @@ putty_message_thread (void *arg)
return NULL; return NULL;
} }
/* FIXME: it would be good to be specified by an option. */ #define BUFSIZE (5 * 1024)
#define AGENT_PIPE_NAME "\\\\.\\pipe\\openssh-ssh-agent"
#define BUFSIZE 5 * 1024
/* The thread handling Win32-OpenSSH requests through NamedPipe. */ /* The thread handling Win32-OpenSSH requests through NamedPipe. */
static void * static void *
@ -2785,7 +2787,7 @@ win32_openssh_thread (void *arg)
es_syshd_t syshd; es_syshd_t syshd;
npth_unprotect (); npth_unprotect ();
pipe = CreateNamedPipeA (AGENT_PIPE_NAME, PIPE_ACCESS_DUPLEX, pipe = CreateNamedPipeA (win32_openssh_support, PIPE_ACCESS_DUPLEX,
(PIPE_TYPE_BYTE | PIPE_READMODE_BYTE (PIPE_TYPE_BYTE | PIPE_READMODE_BYTE
| PIPE_WAIT | PIPE_REJECT_REMOTE_CLIENTS), | PIPE_WAIT | PIPE_REJECT_REMOTE_CLIENTS),
PIPE_UNLIMITED_INSTANCES, PIPE_UNLIMITED_INSTANCES,
@ -2793,7 +2795,7 @@ win32_openssh_thread (void *arg)
if (pipe == INVALID_HANDLE_VALUE) if (pipe == INVALID_HANDLE_VALUE)
{ {
npth_protect (); npth_protect ();
log_error ("cannot create pipe: %ld\n", GetLastError ()); log_error ("cannot create pipe: %ld\n", GetLastError ());
break; break;
} }
@ -2803,41 +2805,41 @@ win32_openssh_thread (void *arg)
npth_protect (); npth_protect ();
CloseHandle (pipe); CloseHandle (pipe);
log_error ("Error at ConnectNamedPipe: %ld\n", GetLastError ()); log_error ("Error at ConnectNamedPipe: %ld\n", GetLastError ());
break; break;
} }
npth_protect (); npth_protect ();
ctrl = xtrycalloc (1, sizeof *ctrl); ctrl = xtrycalloc (1, sizeof *ctrl);
if (!ctrl) if (!ctrl)
{ {
CloseHandle (pipe); CloseHandle (pipe);
log_error ("error allocating connection control data: %s\n", log_error ("error allocating connection control data: %s\n",
strerror (errno)); strerror (errno));
break; break;
} }
ctrl->session_env = session_env_new (); ctrl->session_env = session_env_new ();
if (!ctrl->session_env) if (!ctrl->session_env)
{ {
log_error ("error allocating session environment block: %s\n", log_error ("error allocating session environment block: %s\n",
strerror (errno)); strerror (errno));
agent_deinit_default_ctrl (ctrl); agent_deinit_default_ctrl (ctrl);
xfree (ctrl); xfree (ctrl);
CloseHandle (pipe); CloseHandle (pipe);
break; break;
} }
agent_init_default_ctrl (ctrl); agent_init_default_ctrl (ctrl);
syshd.type = ES_SYSHD_HANDLE; syshd.type = ES_SYSHD_HANDLE;
syshd.u.handle = pipe; syshd.u.handle = pipe;
ssh_stream = es_sysopen (&syshd, "r+b"); ssh_stream = es_sysopen (&syshd, "r+b");
if (!ssh_stream) if (!ssh_stream)
{ {
agent_deinit_default_ctrl (ctrl); agent_deinit_default_ctrl (ctrl);
xfree (ctrl); xfree (ctrl);
CloseHandle (pipe); CloseHandle (pipe);
break; break;
} }
start_command_handler_ssh_stream (ctrl, ssh_stream); start_command_handler_ssh_stream (ctrl, ssh_stream);
@ -3042,9 +3044,7 @@ handle_connections (gnupg_fd_t listen_fd,
ret = npth_create (&thread, &tattr, putty_message_thread, NULL); ret = npth_create (&thread, &tattr, putty_message_thread, NULL);
if (ret) if (ret)
{ log_error ("error spawning putty message loop: %s\n", strerror (ret));
log_error ("error spawning putty message loop: %s\n", strerror (ret));
}
} }
if (win32_openssh_support) if (win32_openssh_support)
@ -3053,9 +3053,7 @@ handle_connections (gnupg_fd_t listen_fd,
ret = npth_create (&thread, &tattr, win32_openssh_thread, NULL); ret = npth_create (&thread, &tattr, win32_openssh_thread, NULL);
if (ret) if (ret)
{ log_error ("error spawning Win32-OpenSSH loop: %s\n", strerror (ret));
log_error ("error spawning Win32-OpenSSH loop: %s\n", strerror (ret));
}
} }
#endif /*HAVE_W32_SYSTEM*/ #endif /*HAVE_W32_SYSTEM*/