1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-22 10:19:57 +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)
{
log_error ("failed to disable buffering on socket stream: %s\n",
strerror (errno));
strerror (errno));
goto out;
}
@ -3793,7 +3793,7 @@ start_command_handler_ssh_stream (ctrl_t ctrl, estream_t stream)
while ( !ssh_request_process (ctrl, stream) )
{
/* Check whether we have reached EOF before trying to read
another request. */
another request. */
int c;
c = es_fgetc (stream);
@ -3830,7 +3830,7 @@ start_command_handler_ssh (ctrl_t ctrl, gnupg_fd_t sock_client)
if (!stream_sock)
{
log_error (_("failed to create stream from socket: %s\n"),
strerror (errno));
strerror (errno));
return;
}

View File

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