diff options
author | John Hood <cgull@glup.org> | 2016-01-17 17:01:36 -0500 |
---|---|---|
committer | John Hood <cgull@glup.org> | 2016-03-30 23:52:19 -0400 |
commit | dbbed24d83fa450960beb6ddc9c165aef1d1c6c9 (patch) | |
tree | 8b1bd891573caccbe26a6d68cfed1ac1579e093c /scripts | |
parent | 9dbf3b366dcc8c3240bd9aac6a6792c809128360 (diff) |
Use server's $SSH_CONNECTION if ProxyCommand isn't run.
This is an alternate way to resolve #417 without affecting
backward compatibility.
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/mosh.pl | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/scripts/mosh.pl b/scripts/mosh.pl index 1cbaaf4..4e5ee86 100755 --- a/scripts/mosh.pl +++ b/scripts/mosh.pl @@ -334,6 +334,12 @@ die "$0: fork: $!\n" unless ( defined $pid ); if ( $pid == 0 ) { # child open(STDERR, ">&STDOUT") or die; + # Ask the server for its IP. The user's shell may not be + # Posix-compatible so invoke sh explicitly. + my $ssh_connection = "sh -c " . + shell_quote ( '[ -n "$SSH_CONNECTION" ] && printf "\nMOSH SSH_CONNECTION %s\n" "$SSH_CONNECTION"' ) . + ";"; + my @server = ( 'new' ); push @server, ( '-c', $colors ); @@ -359,12 +365,12 @@ if ( $pid == 0 ) { # child exec( $server, @server ); die "Cannot exec $server: $!\n"; } - my $quoted_proxy_command = shell_quote( $0, "--family=$family" ); - exec @ssh, '-S', 'none', '-o', "ProxyCommand=$quoted_proxy_command --fake-proxy -- %h %p", '-n', '-tt', $userhost, '--', "$server " . shell_quote( @server ); + my @exec_argv = ( @ssh, '-S', 'none', '-o', "ProxyCommand=$quoted_proxy_command --fake-proxy -- %h %p", '-n', '-tt', $userhost, '--', $ssh_connection . " $server " . shell_quote( @server ) ); + exec @exec_argv; die "Cannot exec ssh: $!\n"; } else { # parent - my ( $ip, $port, $key ); + my ( $ip, $sship, $port, $key ); my $bad_udp_port_warning = 0; LINE: while ( <$pipe> ) { chomp; @@ -373,6 +379,13 @@ if ( $pid == 0 ) { # child die "$0 error: detected attempt to redefine MOSH IP.\n"; } ( $ip ) = m{^MOSH IP (\S+)\s*$} or die "Bad MOSH IP string: $_\n"; + } elsif ( m{^MOSH SSH_CONNECTION } ) { + my @words = split; + if ( scalar @words == 6 ) { + $sship = $words[4]; + } else { + die "Bad MOSH SSH_CONNECTION string: $_\n"; + } } elsif ( m{^MOSH CONNECT } ) { if ( ( $port, $key ) = m{^MOSH CONNECT (\d+?) ([A-Za-z0-9/+]{22})\s*$} ) { last LINE; @@ -390,7 +403,12 @@ if ( $pid == 0 ) { # child close $pipe; if ( not defined $ip ) { - die "$0: Did not find remote IP address (is SSH ProxyCommand disabled?).\n"; + if ( defined $sship ) { + warn "$0: Using remote IP address ${sship} from \$SSH_CONNECTION for hostname ${userhost}\n"; + $ip = $sship; + } else { + die "$0: Did not find remote IP address (is SSH ProxyCommand disabled?).\n"; + } } if ( not defined $key or not defined $port ) { |