version 1.19, 2016/08/02 13:45:12 |
version 1.20, 2016/12/25 00:07:47 |
|
|
/* $NetBSD$ */ |
/* $NetBSD$ */ |
/* $OpenBSD: clientloop.c,v 1.286 2016/07/23 02:54:08 djm Exp $ */ |
/* $OpenBSD: clientloop.c,v 1.289 2016/09/30 09:19:13 markus Exp $ */ |
|
|
/* |
/* |
* Author: Tatu Ylonen <ylo@cs.hut.fi> |
* Author: Tatu Ylonen <ylo@cs.hut.fi> |
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
|
|
#include "includes.h" |
#include "includes.h" |
__RCSID("$NetBSD$"); |
__RCSID("$NetBSD$"); |
|
|
#include <sys/param.h> /* MIN MAX */ |
|
#include <sys/types.h> |
#include <sys/types.h> |
#include <sys/ioctl.h> |
#include <sys/ioctl.h> |
#include <sys/stat.h> |
#include <sys/stat.h> |
Line 308 client_x11_get_proto(const char *display |
|
Line 308 client_x11_get_proto(const char *display |
|
char xauthfile[PATH_MAX], xauthdir[PATH_MAX]; |
char xauthfile[PATH_MAX], xauthdir[PATH_MAX]; |
static char proto[512], data[512]; |
static char proto[512], data[512]; |
FILE *f; |
FILE *f; |
int got_data = 0, generated = 0, do_unlink = 0, i, r; |
int got_data = 0, generated = 0, do_unlink = 0, r; |
struct stat st; |
struct stat st; |
u_int now, x11_timeout_real; |
u_int now, x11_timeout_real; |
|
|
Line 435 client_x11_get_proto(const char *display |
|
Line 435 client_x11_get_proto(const char *display |
|
* for the local connection. |
* for the local connection. |
*/ |
*/ |
if (!got_data) { |
if (!got_data) { |
u_int32_t rnd = 0; |
u_int8_t rnd[16]; |
|
u_int i; |
|
|
logit("Warning: No xauth data; " |
logit("Warning: No xauth data; " |
"using fake authentication data for X11 forwarding."); |
"using fake authentication data for X11 forwarding."); |
strlcpy(proto, SSH_X11_PROTO, sizeof proto); |
strlcpy(proto, SSH_X11_PROTO, sizeof proto); |
for (i = 0; i < 16; i++) { |
arc4random_buf(rnd, sizeof(rnd)); |
if (i % 4 == 0) |
for (i = 0; i < sizeof(rnd); i++) { |
rnd = arc4random(); |
|
snprintf(data + 2 * i, sizeof data - 2 * i, "%02x", |
snprintf(data + 2 * i, sizeof data - 2 * i, "%02x", |
rnd & 0xff); |
rnd[i]); |
rnd >>= 8; |
|
} |
} |
} |
} |
|
|
Line 671 client_wait_until_can_do_something(fd_se |
|
Line 670 client_wait_until_can_do_something(fd_se |
|
server_alive_time = now + options.server_alive_interval; |
server_alive_time = now + options.server_alive_interval; |
} |
} |
if (options.rekey_interval > 0 && compat20 && !rekeying) |
if (options.rekey_interval > 0 && compat20 && !rekeying) |
timeout_secs = MIN(timeout_secs, packet_get_rekey_timeout()); |
timeout_secs = MINIMUM(timeout_secs, packet_get_rekey_timeout()); |
set_control_persist_exit_time(); |
set_control_persist_exit_time(); |
if (control_persist_exit_time > 0) { |
if (control_persist_exit_time > 0) { |
timeout_secs = MIN(timeout_secs, |
timeout_secs = MINIMUM(timeout_secs, |
control_persist_exit_time - now); |
control_persist_exit_time - now); |
if (timeout_secs < 0) |
if (timeout_secs < 0) |
timeout_secs = 0; |
timeout_secs = 0; |
} |
} |
if (minwait_secs != 0) |
if (minwait_secs != 0) |
timeout_secs = MIN(timeout_secs, (int)minwait_secs); |
timeout_secs = MINIMUM(timeout_secs, (int)minwait_secs); |
if (timeout_secs == INT_MAX) |
if (timeout_secs == INT_MAX) |
tvp = NULL; |
tvp = NULL; |
else { |
else { |
Line 1551 client_loop(int have_pty, int escape_cha |
|
Line 1550 client_loop(int have_pty, int escape_cha |
|
buffer_high = 64 * 1024; |
buffer_high = 64 * 1024; |
connection_in = packet_get_connection_in(); |
connection_in = packet_get_connection_in(); |
connection_out = packet_get_connection_out(); |
connection_out = packet_get_connection_out(); |
max_fd = MAX(connection_in, connection_out); |
max_fd = MAXIMUM(connection_in, connection_out); |
|
|
if (!compat20) { |
if (!compat20) { |
/* enable nonblocking unless tty */ |
/* enable nonblocking unless tty */ |
Line 1561 client_loop(int have_pty, int escape_cha |
|
Line 1560 client_loop(int have_pty, int escape_cha |
|
set_nonblock(fileno(stdout)); |
set_nonblock(fileno(stdout)); |
if (!isatty(fileno(stderr))) |
if (!isatty(fileno(stderr))) |
set_nonblock(fileno(stderr)); |
set_nonblock(fileno(stderr)); |
max_fd = MAX(max_fd, fileno(stdin)); |
max_fd = MAXIMUM(max_fd, fileno(stdin)); |
max_fd = MAX(max_fd, fileno(stdout)); |
max_fd = MAXIMUM(max_fd, fileno(stdout)); |
max_fd = MAX(max_fd, fileno(stderr)); |
max_fd = MAXIMUM(max_fd, fileno(stderr)); |
} |
} |
quit_pending = 0; |
quit_pending = 0; |
escape_char1 = escape_char_arg; |
escape_char1 = escape_char_arg; |
Line 1883 client_input_agent_open(int type, u_int3 |
|
Line 1882 client_input_agent_open(int type, u_int3 |
|
} |
} |
|
|
static Channel * |
static Channel * |
client_request_forwarded_tcpip(const char *request_type, int rchan) |
client_request_forwarded_tcpip(const char *request_type, int rchan, |
|
u_int rwindow, u_int rmaxpack) |
{ |
{ |
Channel *c = NULL; |
Channel *c = NULL; |
|
struct sshbuf *b = NULL; |
char *listen_address, *originator_address; |
char *listen_address, *originator_address; |
u_short listen_port, originator_port; |
u_short listen_port, originator_port; |
|
int r; |
|
|
/* Get rest of the packet */ |
/* Get rest of the packet */ |
listen_address = packet_get_string(NULL); |
listen_address = packet_get_string(NULL); |
Line 1902 client_request_forwarded_tcpip(const cha |
|
Line 1904 client_request_forwarded_tcpip(const cha |
|
c = channel_connect_by_listen_address(listen_address, listen_port, |
c = channel_connect_by_listen_address(listen_address, listen_port, |
"forwarded-tcpip", originator_address); |
"forwarded-tcpip", originator_address); |
|
|
|
if (c != NULL && c->type == SSH_CHANNEL_MUX_CLIENT) { |
|
if ((b = sshbuf_new()) == NULL) { |
|
error("%s: alloc reply", __func__); |
|
goto out; |
|
} |
|
/* reconstruct and send to muxclient */ |
|
if ((r = sshbuf_put_u8(b, 0)) != 0 || /* padlen */ |
|
(r = sshbuf_put_u8(b, SSH2_MSG_CHANNEL_OPEN)) != 0 || |
|
(r = sshbuf_put_cstring(b, request_type)) != 0 || |
|
(r = sshbuf_put_u32(b, rchan)) != 0 || |
|
(r = sshbuf_put_u32(b, rwindow)) != 0 || |
|
(r = sshbuf_put_u32(b, rmaxpack)) != 0 || |
|
(r = sshbuf_put_cstring(b, listen_address)) != 0 || |
|
(r = sshbuf_put_u32(b, listen_port)) != 0 || |
|
(r = sshbuf_put_cstring(b, originator_address)) != 0 || |
|
(r = sshbuf_put_u32(b, originator_port)) != 0 || |
|
(r = sshbuf_put_stringb(&c->output, b)) != 0) { |
|
error("%s: compose for muxclient %s", __func__, |
|
ssh_err(r)); |
|
goto out; |
|
} |
|
} |
|
|
|
out: |
|
sshbuf_free(b); |
free(originator_address); |
free(originator_address); |
free(listen_address); |
free(listen_address); |
return c; |
return c; |
Line 2067 client_input_channel_open(int type, u_in |
|
Line 2094 client_input_channel_open(int type, u_in |
|
ctype, rchan, rwindow, rmaxpack); |
ctype, rchan, rwindow, rmaxpack); |
|
|
if (strcmp(ctype, "forwarded-tcpip") == 0) { |
if (strcmp(ctype, "forwarded-tcpip") == 0) { |
c = client_request_forwarded_tcpip(ctype, rchan); |
c = client_request_forwarded_tcpip(ctype, rchan, rwindow, |
|
rmaxpack); |
} else if (strcmp(ctype, "forwarded-streamlocal@openssh.com") == 0) { |
} else if (strcmp(ctype, "forwarded-streamlocal@openssh.com") == 0) { |
c = client_request_forwarded_streamlocal(ctype, rchan); |
c = client_request_forwarded_streamlocal(ctype, rchan); |
} else if (strcmp(ctype, "x11") == 0) { |
} else if (strcmp(ctype, "x11") == 0) { |
Line 2075 client_input_channel_open(int type, u_in |
|
Line 2103 client_input_channel_open(int type, u_in |
|
} else if (strcmp(ctype, "auth-agent@openssh.com") == 0) { |
} else if (strcmp(ctype, "auth-agent@openssh.com") == 0) { |
c = client_request_agent(ctype, rchan); |
c = client_request_agent(ctype, rchan); |
} |
} |
/* XXX duplicate : */ |
if (c != NULL && c->type == SSH_CHANNEL_MUX_CLIENT) { |
if (c != NULL) { |
debug3("proxied to downstream: %s", ctype); |
|
} else if (c != NULL) { |
debug("confirm %s", ctype); |
debug("confirm %s", ctype); |
c->remote_id = rchan; |
c->remote_id = rchan; |
c->remote_window = rwindow; |
c->remote_window = rwindow; |
Line 2112 client_input_channel_req(int type, u_int |
|
Line 2141 client_input_channel_req(int type, u_int |
|
char *rtype; |
char *rtype; |
|
|
id = packet_get_int(); |
id = packet_get_int(); |
|
c = channel_lookup(id); |
|
if (channel_proxy_upstream(c, type, seq, ctxt)) |
|
return 0; |
rtype = packet_get_string(NULL); |
rtype = packet_get_string(NULL); |
reply = packet_get_char(); |
reply = packet_get_char(); |
|
|
Line 2120 client_input_channel_req(int type, u_int |
|
Line 2152 client_input_channel_req(int type, u_int |
|
|
|
if (id == -1) { |
if (id == -1) { |
error("client_input_channel_req: request for channel -1"); |
error("client_input_channel_req: request for channel -1"); |
} else if ((c = channel_lookup(id)) == NULL) { |
} else if (c == NULL) { |
error("client_input_channel_req: channel %d: " |
error("client_input_channel_req: channel %d: " |
"unknown channel", id); |
"unknown channel", id); |
} else if (strcmp(rtype, "eow@openssh.com") == 0) { |
} else if (strcmp(rtype, "eow@openssh.com") == 0) { |