version 1.454, 2017/04/30 23:11:45 |
version 1.455, 2017/04/30 23:13:25 |
|
|
exit(255); |
exit(255); |
} |
} |
|
|
static int ssh_session(void); |
|
static int ssh_session2(void); |
static int ssh_session2(void); |
static void load_public_identity_files(void); |
static void load_public_identity_files(void); |
static void main_sigchld_handler(int); |
static void main_sigchld_handler(int); |
|
|
if ((sock = muxclient(options.control_path)) >= 0) { |
if ((sock = muxclient(options.control_path)) >= 0) { |
packet_set_connection(sock, sock); |
packet_set_connection(sock, sock); |
ssh = active_state; /* XXX */ |
ssh = active_state; /* XXX */ |
enable_compat20(); /* XXX */ |
|
packet_set_mux(); |
packet_set_mux(); |
goto skip_connect; |
goto skip_connect; |
} |
} |
|
|
} |
} |
|
|
skip_connect: |
skip_connect: |
exit_status = compat20 ? ssh_session2() : ssh_session(); |
exit_status = ssh_session2(); |
packet_close(); |
packet_close(); |
|
|
if (options.control_path != NULL && muxserver_sock != -1) |
if (options.control_path != NULL && muxserver_sock != -1) |
|
|
|
|
if (options.stdio_forward_host == NULL) |
if (options.stdio_forward_host == NULL) |
return; |
return; |
if (!compat20) |
|
fatal("stdio forwarding require Protocol 2"); |
|
|
|
debug3("%s: %s:%d", __func__, options.stdio_forward_host, |
debug3("%s: %s:%d", __func__, options.stdio_forward_host, |
options.stdio_forward_port); |
options.stdio_forward_port); |
|
|
} |
} |
} |
} |
|
|
static int |
|
ssh_session(void) |
|
{ |
|
int type; |
|
int interactive = 0; |
|
int have_tty = 0; |
|
struct winsize ws; |
|
char *cp; |
|
const char *display; |
|
char *proto = NULL, *data = NULL; |
|
|
|
/* Enable compression if requested. */ |
|
if (options.compression) { |
|
debug("Requesting compression at level %d.", |
|
options.compression_level); |
|
|
|
if (options.compression_level < 1 || |
|
options.compression_level > 9) |
|
fatal("Compression level must be from 1 (fast) to " |
|
"9 (slow, best)."); |
|
|
|
/* Send the request. */ |
|
packet_start(SSH_CMSG_REQUEST_COMPRESSION); |
|
packet_put_int(options.compression_level); |
|
packet_send(); |
|
packet_write_wait(); |
|
type = packet_read(); |
|
if (type == SSH_SMSG_SUCCESS) |
|
packet_start_compression(options.compression_level); |
|
else if (type == SSH_SMSG_FAILURE) |
|
logit("Warning: Remote host refused compression."); |
|
else |
|
packet_disconnect("Protocol error waiting for " |
|
"compression response."); |
|
} |
|
/* Allocate a pseudo tty if appropriate. */ |
|
if (tty_flag) { |
|
debug("Requesting pty."); |
|
|
|
/* Start the packet. */ |
|
packet_start(SSH_CMSG_REQUEST_PTY); |
|
|
|
/* Store TERM in the packet. There is no limit on the |
|
length of the string. */ |
|
cp = getenv("TERM"); |
|
if (!cp) |
|
cp = ""; |
|
packet_put_cstring(cp); |
|
|
|
/* Store window size in the packet. */ |
|
if (ioctl(fileno(stdin), TIOCGWINSZ, &ws) < 0) |
|
memset(&ws, 0, sizeof(ws)); |
|
packet_put_int((u_int)ws.ws_row); |
|
packet_put_int((u_int)ws.ws_col); |
|
packet_put_int((u_int)ws.ws_xpixel); |
|
packet_put_int((u_int)ws.ws_ypixel); |
|
|
|
/* Store tty modes in the packet. */ |
|
tty_make_modes(fileno(stdin), NULL); |
|
|
|
/* Send the packet, and wait for it to leave. */ |
|
packet_send(); |
|
packet_write_wait(); |
|
|
|
/* Read response from the server. */ |
|
type = packet_read(); |
|
if (type == SSH_SMSG_SUCCESS) { |
|
interactive = 1; |
|
have_tty = 1; |
|
} else if (type == SSH_SMSG_FAILURE) |
|
logit("Warning: Remote host failed or refused to " |
|
"allocate a pseudo tty."); |
|
else |
|
packet_disconnect("Protocol error waiting for pty " |
|
"request response."); |
|
} |
|
/* Request X11 forwarding if enabled and DISPLAY is set. */ |
|
display = getenv("DISPLAY"); |
|
if (display == NULL && options.forward_x11) |
|
debug("X11 forwarding requested but DISPLAY not set"); |
|
if (options.forward_x11 && client_x11_get_proto(display, |
|
options.xauth_location, options.forward_x11_trusted, |
|
options.forward_x11_timeout, &proto, &data) == 0) { |
|
/* Request forwarding with authentication spoofing. */ |
|
debug("Requesting X11 forwarding with authentication " |
|
"spoofing."); |
|
x11_request_forwarding_with_spoofing(0, display, proto, |
|
data, 0); |
|
/* Read response from the server. */ |
|
type = packet_read(); |
|
if (type == SSH_SMSG_SUCCESS) { |
|
interactive = 1; |
|
} else if (type == SSH_SMSG_FAILURE) { |
|
logit("Warning: Remote host denied X11 forwarding."); |
|
} else { |
|
packet_disconnect("Protocol error waiting for X11 " |
|
"forwarding"); |
|
} |
|
} |
|
/* Tell the packet module whether this is an interactive session. */ |
|
packet_set_interactive(interactive, |
|
options.ip_qos_interactive, options.ip_qos_bulk); |
|
|
|
/* Request authentication agent forwarding if appropriate. */ |
|
check_agent_present(); |
|
|
|
if (options.forward_agent) { |
|
debug("Requesting authentication agent forwarding."); |
|
auth_request_forwarding(); |
|
|
|
/* Read response from the server. */ |
|
type = packet_read(); |
|
packet_check_eom(); |
|
if (type != SSH_SMSG_SUCCESS) |
|
logit("Warning: Remote host denied authentication agent forwarding."); |
|
} |
|
|
|
/* Initiate port forwardings. */ |
|
ssh_init_stdio_forwarding(); |
|
ssh_init_forwarding(); |
|
|
|
/* Execute a local command */ |
|
if (options.local_command != NULL && |
|
options.permit_local_command) |
|
ssh_local_cmd(options.local_command); |
|
|
|
/* |
|
* If requested and we are not interested in replies to remote |
|
* forwarding requests, then let ssh continue in the background. |
|
*/ |
|
if (fork_after_authentication_flag) { |
|
if (options.exit_on_forward_failure && |
|
options.num_remote_forwards > 0) { |
|
debug("deferring postauth fork until remote forward " |
|
"confirmation received"); |
|
} else |
|
fork_postauth(); |
|
} |
|
|
|
/* |
|
* If a command was specified on the command line, execute the |
|
* command now. Otherwise request the server to start a shell. |
|
*/ |
|
if (buffer_len(&command) > 0) { |
|
int len = buffer_len(&command); |
|
if (len > 900) |
|
len = 900; |
|
debug("Sending command: %.*s", len, |
|
(u_char *)buffer_ptr(&command)); |
|
packet_start(SSH_CMSG_EXEC_CMD); |
|
packet_put_string(buffer_ptr(&command), buffer_len(&command)); |
|
packet_send(); |
|
packet_write_wait(); |
|
} else { |
|
debug("Requesting shell."); |
|
packet_start(SSH_CMSG_EXEC_SHELL); |
|
packet_send(); |
|
packet_write_wait(); |
|
} |
|
|
|
/* Enter the interactive session. */ |
|
return client_loop(have_tty, tty_flag ? |
|
options.escape_char : SSH_ESCAPECHAR_NONE, 0); |
|
} |
|
|
|
/* request pty/x11/agent/tcpfwd/shell for channel */ |
|
static void |
static void |
ssh_session2_setup(int id, int success, void *arg) |
ssh_session2_setup(int id, int success, void *arg) |
{ |
{ |