version 1.260, 2014/06/27 16:41:56 |
version 1.261, 2014/07/15 15:54:14 |
|
|
#include "cipher.h" |
#include "cipher.h" |
#include "kex.h" |
#include "kex.h" |
#include "log.h" |
#include "log.h" |
|
#include "misc.h" |
#include "readconf.h" |
#include "readconf.h" |
#include "clientloop.h" |
#include "clientloop.h" |
#include "sshconnect.h" |
#include "sshconnect.h" |
#include "authfd.h" |
#include "authfd.h" |
#include "atomicio.h" |
#include "atomicio.h" |
#include "sshpty.h" |
#include "sshpty.h" |
#include "misc.h" |
|
#include "match.h" |
#include "match.h" |
#include "msg.h" |
#include "msg.h" |
#include "roaming.h" |
#include "roaming.h" |
|
|
process_cmdline(void) |
process_cmdline(void) |
{ |
{ |
void (*handler)(int); |
void (*handler)(int); |
char *s, *cmd, *cancel_host; |
char *s, *cmd; |
int delete = 0, local = 0, remote = 0, dynamic = 0; |
int ok, delete = 0, local = 0, remote = 0, dynamic = 0; |
int cancel_port, ok; |
struct Forward fwd; |
Forward fwd; |
|
|
|
memset(&fwd, 0, sizeof(fwd)); |
memset(&fwd, 0, sizeof(fwd)); |
fwd.listen_host = fwd.connect_host = NULL; |
|
|
|
leave_raw_mode(options.request_tty == REQUEST_TTY_FORCE); |
leave_raw_mode(options.request_tty == REQUEST_TTY_FORCE); |
handler = signal(SIGINT, SIG_IGN); |
handler = signal(SIGINT, SIG_IGN); |
|
|
|
|
/* XXX update list of forwards in options */ |
/* XXX update list of forwards in options */ |
if (delete) { |
if (delete) { |
cancel_port = 0; |
/* We pass 1 for dynamicfwd to restrict to 1 or 2 fields. */ |
cancel_host = hpdelim(&s); /* may be NULL */ |
if (!parse_forward(&fwd, s, 1, 0)) { |
if (s != NULL) { |
logit("Bad forwarding close specification."); |
cancel_port = a2port(s); |
|
cancel_host = cleanhostname(cancel_host); |
|
} else { |
|
cancel_port = a2port(cancel_host); |
|
cancel_host = NULL; |
|
} |
|
if (cancel_port <= 0) { |
|
logit("Bad forwarding close port"); |
|
goto out; |
goto out; |
} |
} |
if (remote) |
if (remote) |
ok = channel_request_rforward_cancel(cancel_host, |
ok = channel_request_rforward_cancel(&fwd) == 0; |
cancel_port) == 0; |
|
else if (dynamic) |
else if (dynamic) |
ok = channel_cancel_lport_listener(cancel_host, |
ok = channel_cancel_lport_listener(&fwd, |
cancel_port, 0, options.gateway_ports) > 0; |
0, &options.fwd_opts) > 0; |
else |
else |
ok = channel_cancel_lport_listener(cancel_host, |
ok = channel_cancel_lport_listener(&fwd, |
cancel_port, CHANNEL_CANCEL_PORT_STATIC, |
CHANNEL_CANCEL_PORT_STATIC, |
options.gateway_ports) > 0; |
&options.fwd_opts) > 0; |
if (!ok) { |
if (!ok) { |
logit("Unkown port forwarding."); |
logit("Unkown port forwarding."); |
goto out; |
goto out; |
|
|
goto out; |
goto out; |
} |
} |
if (local || dynamic) { |
if (local || dynamic) { |
if (!channel_setup_local_fwd_listener(fwd.listen_host, |
if (!channel_setup_local_fwd_listener(&fwd, |
fwd.listen_port, fwd.connect_host, |
&options.fwd_opts)) { |
fwd.connect_port, options.gateway_ports)) { |
|
logit("Port forwarding failed."); |
logit("Port forwarding failed."); |
goto out; |
goto out; |
} |
} |
} else { |
} else { |
if (channel_request_remote_forwarding(fwd.listen_host, |
if (channel_request_remote_forwarding(&fwd) < 0) { |
fwd.listen_port, fwd.connect_host, |
|
fwd.connect_port) < 0) { |
|
logit("Port forwarding failed."); |
logit("Port forwarding failed."); |
goto out; |
goto out; |
} |
} |
|
|
enter_raw_mode(options.request_tty == REQUEST_TTY_FORCE); |
enter_raw_mode(options.request_tty == REQUEST_TTY_FORCE); |
free(cmd); |
free(cmd); |
free(fwd.listen_host); |
free(fwd.listen_host); |
|
free(fwd.listen_path); |
free(fwd.connect_host); |
free(fwd.connect_host); |
|
free(fwd.connect_path); |
} |
} |
|
|
/* reasons to suppress output of an escape command in help output */ |
/* reasons to suppress output of an escape command in help output */ |
|
|
originator_port = packet_get_int(); |
originator_port = packet_get_int(); |
packet_check_eom(); |
packet_check_eom(); |
|
|
debug("client_request_forwarded_tcpip: listen %s port %d, " |
debug("%s: listen %s port %d, originator %s port %d", __func__, |
"originator %s port %d", listen_address, listen_port, |
listen_address, listen_port, originator_address, originator_port); |
originator_address, originator_port); |
|
|
|
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); |
|
|
} |
} |
|
|
static Channel * |
static Channel * |
|
client_request_forwarded_streamlocal(const char *request_type, int rchan) |
|
{ |
|
Channel *c = NULL; |
|
char *listen_path; |
|
|
|
/* Get the remote path. */ |
|
listen_path = packet_get_string(NULL); |
|
/* XXX: Skip reserved field for now. */ |
|
if (packet_get_string_ptr(NULL) == NULL) |
|
fatal("%s: packet_get_string_ptr failed", __func__); |
|
packet_check_eom(); |
|
|
|
debug("%s: %s", __func__, listen_path); |
|
|
|
c = channel_connect_by_listen_path(listen_path, |
|
"forwarded-streamlocal@openssh.com", "forwarded-streamlocal"); |
|
free(listen_path); |
|
return c; |
|
} |
|
|
|
static Channel * |
client_request_x11(const char *request_type, int rchan) |
client_request_x11(const char *request_type, int rchan) |
{ |
{ |
Channel *c = NULL; |
Channel *c = NULL; |
|
|
|
|
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); |
|
} else if (strcmp(ctype, "forwarded-streamlocal@openssh.com") == 0) { |
|
c = client_request_forwarded_streamlocal(ctype, rchan); |
} else if (strcmp(ctype, "x11") == 0) { |
} else if (strcmp(ctype, "x11") == 0) { |
c = client_request_x11(ctype, rchan); |
c = client_request_x11(ctype, rchan); |
} else if (strcmp(ctype, "auth-agent@openssh.com") == 0) { |
} else if (strcmp(ctype, "auth-agent@openssh.com") == 0) { |