net-ssh 0.6.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/doc/manual-html/chapter-1.html +59 -24
- data/doc/manual-html/chapter-2.html +116 -77
- data/doc/manual-html/chapter-3.html +80 -41
- data/doc/manual-html/chapter-4.html +111 -71
- data/doc/manual-html/chapter-5.html +267 -155
- data/doc/manual-html/chapter-6.html +211 -75
- data/doc/manual-html/chapter-7.html +331 -0
- data/doc/manual-html/index.html +39 -13
- data/doc/manual-html/{manual.css → stylesheets/manual.css} +81 -8
- data/doc/manual-html/stylesheets/ruby.css +17 -0
- data/doc/manual/chapter.erb +20 -0
- data/doc/manual/manual.rb +80 -9
- data/doc/manual/manual.yml +12 -2
- data/doc/manual/page.erb +1 -1
- data/doc/manual/parts/channels_callbacks.txt +11 -11
- data/doc/manual/parts/channels_loop.txt +6 -6
- data/doc/manual/parts/channels_open.txt +9 -9
- data/doc/manual/parts/exec_channels.txt +15 -15
- data/doc/manual/parts/exec_open.txt +17 -18
- data/doc/manual/parts/exec_popen3.txt +18 -18
- data/doc/manual/parts/forward_direct.txt +16 -16
- data/doc/manual/parts/forward_intro.txt +7 -7
- data/doc/manual/parts/forward_local.txt +9 -9
- data/doc/manual/parts/forward_remote.txt +9 -9
- data/doc/manual/parts/intro_getting.txt +11 -11
- data/doc/manual/parts/proxy_http.txt +27 -27
- data/doc/manual/parts/proxy_socks.txt +17 -17
- data/doc/manual/parts/session_key.txt +13 -14
- data/doc/manual/parts/session_options.txt +14 -14
- data/doc/manual/parts/session_session.txt +9 -9
- data/doc/manual/parts/session_start.txt +27 -27
- data/doc/manual/parts/shells_channels.txt +72 -0
- data/doc/manual/parts/shells_clients.txt +51 -0
- data/doc/manual/parts/shells_intro.txt +7 -0
- data/doc/manual/parts/shells_shell.txt +50 -0
- data/doc/manual/parts/shells_sync.txt +42 -0
- data/doc/manual/{manual.css → stylesheets/manual.css} +81 -8
- data/doc/manual/stylesheets/ruby.css +17 -0
- data/examples/channel-demo.rb +1 -1
- data/examples/port-forward.rb +1 -1
- data/examples/process-demo.rb +1 -1
- data/examples/remote-net-port-forward.rb +1 -1
- data/examples/remote-port-forward.rb +1 -1
- data/examples/shell-demo.rb +46 -0
- data/examples/ssh-client.rb +67 -0
- data/examples/sync-shell-demo.rb +69 -0
- data/examples/tail-demo.rb +1 -1
- data/lib/net/ssh.rb +1 -1
- data/lib/net/ssh/connection/channel.rb +61 -7
- data/lib/net/ssh/connection/constants.rb +1 -1
- data/lib/net/ssh/connection/driver.rb +61 -8
- data/lib/net/ssh/connection/services.rb +1 -1
- data/lib/net/ssh/connection/term.rb +1 -1
- data/lib/net/ssh/errors.rb +1 -1
- data/lib/net/ssh/proxy/errors.rb +1 -1
- data/lib/net/ssh/proxy/http.rb +1 -1
- data/lib/net/ssh/proxy/socks4.rb +1 -1
- data/lib/net/ssh/proxy/socks5.rb +1 -1
- data/lib/net/ssh/service/forward/driver.rb +1 -1
- data/lib/net/ssh/service/forward/local-network-handler.rb +1 -1
- data/lib/net/ssh/service/forward/remote-network-handler.rb +1 -1
- data/lib/net/ssh/service/forward/services.rb +1 -1
- data/lib/net/ssh/service/process/driver.rb +1 -1
- data/lib/net/ssh/service/process/open.rb +1 -1
- data/lib/net/ssh/service/process/popen3.rb +20 -2
- data/lib/net/ssh/service/process/services.rb +1 -1
- data/lib/net/ssh/service/services.rb +3 -1
- data/lib/net/ssh/service/shell/driver.rb +86 -0
- data/lib/net/ssh/service/shell/services.rb +54 -0
- data/lib/net/ssh/service/shell/shell.rb +213 -0
- data/lib/net/ssh/service/shell/sync.rb +114 -0
- data/lib/net/ssh/session.rb +9 -1
- data/lib/net/ssh/transport/algorithm-negotiator.rb +1 -1
- data/lib/net/ssh/transport/compress/compressor.rb +1 -1
- data/lib/net/ssh/transport/compress/decompressor.rb +1 -1
- data/lib/net/ssh/transport/compress/none-compressor.rb +1 -1
- data/lib/net/ssh/transport/compress/none-decompressor.rb +1 -1
- data/lib/net/ssh/transport/compress/services.rb +1 -1
- data/lib/net/ssh/transport/compress/zlib-compressor.rb +1 -1
- data/lib/net/ssh/transport/compress/zlib-decompressor.rb +1 -1
- data/lib/net/ssh/transport/constants.rb +1 -1
- data/lib/net/ssh/transport/errors.rb +1 -1
- data/lib/net/ssh/transport/identity-cipher.rb +1 -1
- data/lib/net/ssh/transport/kex/dh-gex.rb +1 -1
- data/lib/net/ssh/transport/kex/dh.rb +1 -1
- data/lib/net/ssh/transport/kex/services.rb +1 -1
- data/lib/net/ssh/transport/ossl/buffer-factory.rb +1 -1
- data/lib/net/ssh/transport/ossl/buffer.rb +1 -1
- data/lib/net/ssh/transport/ossl/cipher-factory.rb +1 -1
- data/lib/net/ssh/transport/ossl/digest-factory.rb +1 -1
- data/lib/net/ssh/transport/ossl/hmac-factory.rb +1 -1
- data/lib/net/ssh/transport/ossl/hmac/hmac.rb +1 -1
- data/lib/net/ssh/transport/ossl/hmac/md5-96.rb +1 -1
- data/lib/net/ssh/transport/ossl/hmac/md5.rb +1 -1
- data/lib/net/ssh/transport/ossl/hmac/none.rb +1 -1
- data/lib/net/ssh/transport/ossl/hmac/services.rb +1 -1
- data/lib/net/ssh/transport/ossl/hmac/sha1-96.rb +1 -1
- data/lib/net/ssh/transport/ossl/hmac/sha1.rb +1 -1
- data/lib/net/ssh/transport/ossl/key-factory.rb +5 -2
- data/lib/net/ssh/transport/ossl/services.rb +1 -1
- data/lib/net/ssh/transport/packet-stream.rb +1 -1
- data/lib/net/ssh/transport/services.rb +1 -1
- data/lib/net/ssh/transport/session.rb +10 -1
- data/lib/net/ssh/transport/version-negotiator.rb +1 -1
- data/lib/net/ssh/userauth/agent.rb +1 -1
- data/lib/net/ssh/userauth/constants.rb +1 -1
- data/lib/net/ssh/userauth/driver.rb +1 -1
- data/lib/net/ssh/userauth/methods/hostbased.rb +1 -1
- data/lib/net/ssh/userauth/methods/keyboard-interactive.rb +104 -0
- data/lib/net/ssh/userauth/methods/password.rb +1 -1
- data/lib/net/ssh/userauth/methods/publickey.rb +1 -1
- data/lib/net/ssh/userauth/methods/services.rb +28 -6
- data/lib/net/ssh/userauth/services.rb +8 -5
- data/lib/net/ssh/userauth/userkeys.rb +1 -1
- data/lib/net/ssh/util/buffer.rb +1 -1
- data/lib/net/ssh/util/openssl.rb +1 -1
- data/lib/net/ssh/util/prompter.rb +1 -1
- data/lib/net/ssh/version.rb +2 -2
- data/test/ALL-TESTS.rb +1 -1
- data/test/connection/tc_channel.rb +1 -1
- data/test/connection/tc_driver.rb +1 -1
- data/test/connection/tc_integration.rb +1 -1
- data/test/proxy/tc_http.rb +1 -1
- data/test/proxy/tc_socks4.rb +1 -1
- data/test/proxy/tc_socks5.rb +1 -1
- data/test/service/forward/tc_driver.rb +1 -1
- data/test/service/forward/tc_local_network_handler.rb +1 -1
- data/test/service/forward/tc_remote_network_handler.rb +1 -1
- data/test/service/process/tc_driver.rb +1 -1
- data/test/service/process/tc_integration.rb +1 -1
- data/test/service/process/tc_open.rb +1 -1
- data/test/service/process/tc_popen3.rb +13 -13
- data/test/tc_integration.rb +1 -1
- data/test/transport/compress/tc_none_compress.rb +1 -1
- data/test/transport/compress/tc_none_decompress.rb +1 -1
- data/test/transport/compress/tc_zlib_compress.rb +1 -1
- data/test/transport/compress/tc_zlib_decompress.rb +1 -1
- data/test/transport/kex/tc_dh.rb +2 -1
- data/test/transport/kex/tc_dh_gex.rb +1 -1
- data/test/transport/ossl/hmac/tc_hmac.rb +1 -1
- data/test/transport/ossl/hmac/tc_md5.rb +1 -1
- data/test/transport/ossl/hmac/tc_md5_96.rb +1 -1
- data/test/transport/ossl/hmac/tc_none.rb +1 -1
- data/test/transport/ossl/hmac/tc_sha1.rb +1 -1
- data/test/transport/ossl/hmac/tc_sha1_96.rb +1 -1
- data/test/transport/ossl/tc_buffer.rb +1 -1
- data/test/transport/ossl/tc_buffer_factory.rb +1 -1
- data/test/transport/ossl/tc_cipher_factory.rb +1 -1
- data/test/transport/ossl/tc_digest_factory.rb +1 -1
- data/test/transport/ossl/tc_hmac_factory.rb +1 -1
- data/test/transport/ossl/tc_key_factory.rb +1 -1
- data/test/transport/tc_algorithm_negotiator.rb +1 -1
- data/test/transport/tc_identity_cipher.rb +1 -1
- data/test/transport/tc_integration.rb +1 -1
- data/test/transport/tc_packet_stream.rb +1 -1
- data/test/transport/tc_session.rb +1 -1
- data/test/transport/tc_version_negotiator.rb +1 -1
- data/test/userauth/methods/tc_hostbased.rb +1 -1
- data/test/userauth/methods/tc_password.rb +1 -1
- data/test/userauth/methods/tc_publickey.rb +1 -1
- data/test/userauth/tc_agent.rb +1 -1
- data/test/userauth/tc_driver.rb +1 -1
- data/test/userauth/tc_integration.rb +15 -1
- data/test/userauth/tc_userkeys.rb +1 -1
- data/test/util/tc_buffer.rb +5 -5
- metadata +26 -6
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
.ruby .normal {}
|
|
2
|
+
.ruby .comment { color: #005; font-style: italic; }
|
|
3
|
+
.ruby .keyword { color: #A00; font-weight: bold; }
|
|
4
|
+
.ruby .method { color: #077; }
|
|
5
|
+
.ruby .class { color: #074; }
|
|
6
|
+
.ruby .module { color: #050; }
|
|
7
|
+
.ruby .punct { color: #447; font-weight: bold; }
|
|
8
|
+
.ruby .symbol { color: #099; }
|
|
9
|
+
.ruby .string { color: #944; }
|
|
10
|
+
.ruby .char { color: #F07; }
|
|
11
|
+
.ruby .ident { color: #004; }
|
|
12
|
+
.ruby .constant { color: #07F; }
|
|
13
|
+
.ruby .regex { color: #B66; }
|
|
14
|
+
.ruby .number { color: #D55; }
|
|
15
|
+
.ruby .attribute { color: #377; }
|
|
16
|
+
.ruby .global { color: #3B7; }
|
|
17
|
+
.ruby .expr { color: #227; }
|
data/examples/channel-demo.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#--
|
|
2
2
|
# =============================================================================
|
|
3
|
-
# Copyright (c) 2004, Jamis Buck (
|
|
3
|
+
# Copyright (c) 2004,2005 Jamis Buck (jamis_buck@byu.edu)
|
|
4
4
|
# All rights reserved.
|
|
5
5
|
#
|
|
6
6
|
# This source file is distributed as part of the Net::SSH Secure Shell Client
|
data/examples/port-forward.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#--
|
|
2
2
|
# =============================================================================
|
|
3
|
-
# Copyright (c) 2004, Jamis Buck (
|
|
3
|
+
# Copyright (c) 2004,2005 Jamis Buck (jamis_buck@byu.edu)
|
|
4
4
|
# All rights reserved.
|
|
5
5
|
#
|
|
6
6
|
# This source file is distributed as part of the Net::SSH Secure Shell Client
|
data/examples/process-demo.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#--
|
|
2
2
|
# =============================================================================
|
|
3
|
-
# Copyright (c) 2004, Jamis Buck (
|
|
3
|
+
# Copyright (c) 2004,2005 Jamis Buck (jamis_buck@byu.edu)
|
|
4
4
|
# All rights reserved.
|
|
5
5
|
#
|
|
6
6
|
# This source file is distributed as part of the Net::SSH Secure Shell Client
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#--
|
|
2
2
|
# =============================================================================
|
|
3
|
-
# Copyright (c) 2004, Jamis Buck (
|
|
3
|
+
# Copyright (c) 2004,2005 Jamis Buck (jamis_buck@byu.edu)
|
|
4
4
|
# All rights reserved.
|
|
5
5
|
#
|
|
6
6
|
# This source file is distributed as part of the Net::SSH Secure Shell Client
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#--
|
|
2
2
|
# =============================================================================
|
|
3
|
-
# Copyright (c) 2004, Jamis Buck (
|
|
3
|
+
# Copyright (c) 2004,2005 Jamis Buck (jamis_buck@byu.edu)
|
|
4
4
|
# All rights reserved.
|
|
5
5
|
#
|
|
6
6
|
# This source file is distributed as part of the Net::SSH Secure Shell Client
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#--
|
|
2
|
+
# =============================================================================
|
|
3
|
+
# Copyright (c) 2004,2005 Jamis Buck (jamis_buck@byu.edu)
|
|
4
|
+
# All rights reserved.
|
|
5
|
+
#
|
|
6
|
+
# This source file is distributed as part of the Net::SSH Secure Shell Client
|
|
7
|
+
# library for Ruby. This file (and the library as a whole) may be used only as
|
|
8
|
+
# allowed by either the BSD license, or the Ruby license (or, by association
|
|
9
|
+
# with the Ruby license, the GPL). See the "doc" subdirectory of the Net::SSH
|
|
10
|
+
# distribution for the texts of these licenses.
|
|
11
|
+
# -----------------------------------------------------------------------------
|
|
12
|
+
# net-ssh website : http://net-ssh.rubyforge.org
|
|
13
|
+
# project website: http://rubyforge.org/projects/net-ssh
|
|
14
|
+
# =============================================================================
|
|
15
|
+
#++
|
|
16
|
+
|
|
17
|
+
$:.unshift "../lib"
|
|
18
|
+
require 'net/ssh'
|
|
19
|
+
|
|
20
|
+
Net::SSH.start( 'localhost' ) do |session|
|
|
21
|
+
|
|
22
|
+
shell = session.shell.open
|
|
23
|
+
|
|
24
|
+
# script what we want to do
|
|
25
|
+
shell.pwd
|
|
26
|
+
shell.cd "/"
|
|
27
|
+
shell.pwd
|
|
28
|
+
shell.test "-e foo"
|
|
29
|
+
shell.ls "-laZ"
|
|
30
|
+
shell.cd "/really/bogus/directory"
|
|
31
|
+
shell.send_data "/sbin/ifconfig\n"
|
|
32
|
+
shell.pwd
|
|
33
|
+
shell.ruby "-v"
|
|
34
|
+
shell.cd "/usr/lib"
|
|
35
|
+
shell.pwd
|
|
36
|
+
shell.exit
|
|
37
|
+
|
|
38
|
+
# give the above commands sufficient time to terminate
|
|
39
|
+
sleep 0.5
|
|
40
|
+
|
|
41
|
+
# display the output
|
|
42
|
+
$stdout.print shell.stdout while shell.stdout?
|
|
43
|
+
$stderr.puts "-- stderr: --"
|
|
44
|
+
$stderr.print shell.stderr while shell.stderr?
|
|
45
|
+
|
|
46
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
#--
|
|
2
|
+
# =============================================================================
|
|
3
|
+
# Copyright (c) 2004,2005 Jamis Buck (jamis_buck@byu.edu)
|
|
4
|
+
# All rights reserved.
|
|
5
|
+
#
|
|
6
|
+
# This source file is distributed as part of the Net::SSH Secure Shell Client
|
|
7
|
+
# library for Ruby. This file (and the library as a whole) may be used only as
|
|
8
|
+
# allowed by either the BSD license, or the Ruby license (or, by association
|
|
9
|
+
# with the Ruby license, the GPL). See the "doc" subdirectory of the Net::SSH
|
|
10
|
+
# distribution for the texts of these licenses.
|
|
11
|
+
# -----------------------------------------------------------------------------
|
|
12
|
+
# net-ssh website : http://net-ssh.rubyforge.org
|
|
13
|
+
# project website: http://rubyforge.org/projects/net-ssh
|
|
14
|
+
# =============================================================================
|
|
15
|
+
#++
|
|
16
|
+
|
|
17
|
+
# This is a (very) simple, but capable, SSH terminal client. It DOES NOT send
|
|
18
|
+
# the size of the terminal window, or handle resizing of the terminal window.
|
|
19
|
+
|
|
20
|
+
$:.unshift "../lib"
|
|
21
|
+
require 'net/ssh'
|
|
22
|
+
|
|
23
|
+
begin
|
|
24
|
+
require 'termios'
|
|
25
|
+
rescue LoadError
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def stdin_buffer( enable )
|
|
29
|
+
return unless defined?( Termios )
|
|
30
|
+
attr = Termios::getattr( $stdin )
|
|
31
|
+
if enable
|
|
32
|
+
attr.c_lflag |= Termios::ICANON | Termios::ECHO
|
|
33
|
+
else
|
|
34
|
+
attr.c_lflag &= ~(Termios::ICANON|Termios::ECHO)
|
|
35
|
+
end
|
|
36
|
+
Termios::setattr( $stdin, Termios::TCSANOW, attr )
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
host = ARGV.shift or abort "You must specify the [user@]host to connect to"
|
|
40
|
+
if host =~ /@/
|
|
41
|
+
user, host = host.match( /(.*?)@(.*)/ )[1,2]
|
|
42
|
+
else
|
|
43
|
+
user = ENV['USER'] || ENV['USER_NAME']
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
Net::SSH.start( host, user ) do |session|
|
|
47
|
+
|
|
48
|
+
begin
|
|
49
|
+
stdin_buffer false
|
|
50
|
+
|
|
51
|
+
shell = session.shell.open( :pty => true )
|
|
52
|
+
|
|
53
|
+
loop do
|
|
54
|
+
break unless shell.open?
|
|
55
|
+
if IO.select([$stdin],nil,nil,0.01)
|
|
56
|
+
data = $stdin.sysread(1)
|
|
57
|
+
shell.send_data data
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
$stdout.print shell.stdout while shell.stdout?
|
|
61
|
+
$stdout.flush
|
|
62
|
+
end
|
|
63
|
+
ensure
|
|
64
|
+
stdin_buffer true
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
end
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#--
|
|
2
|
+
# =============================================================================
|
|
3
|
+
# Copyright (c) 2004,2005 Jamis Buck (jamis_buck@byu.edu)
|
|
4
|
+
# All rights reserved.
|
|
5
|
+
#
|
|
6
|
+
# This source file is distributed as part of the Net::SSH Secure Shell Client
|
|
7
|
+
# library for Ruby. This file (and the library as a whole) may be used only as
|
|
8
|
+
# allowed by either the BSD license, or the Ruby license (or, by association
|
|
9
|
+
# with the Ruby license, the GPL). See the "doc" subdirectory of the Net::SSH
|
|
10
|
+
# distribution for the texts of these licenses.
|
|
11
|
+
# -----------------------------------------------------------------------------
|
|
12
|
+
# net-ssh website : http://net-ssh.rubyforge.org
|
|
13
|
+
# project website: http://rubyforge.org/projects/net-ssh
|
|
14
|
+
# =============================================================================
|
|
15
|
+
#++
|
|
16
|
+
|
|
17
|
+
$:.unshift "../lib"
|
|
18
|
+
require 'net/ssh'
|
|
19
|
+
|
|
20
|
+
Net::SSH.start( 'localhost' ) do |session|
|
|
21
|
+
|
|
22
|
+
shell = session.shell.sync
|
|
23
|
+
|
|
24
|
+
out = shell.pwd
|
|
25
|
+
p out.stdout
|
|
26
|
+
|
|
27
|
+
out = shell.cd "/"
|
|
28
|
+
|
|
29
|
+
out = shell.pwd
|
|
30
|
+
p out.stdout
|
|
31
|
+
|
|
32
|
+
out = shell.test "-e foo"
|
|
33
|
+
p out.status
|
|
34
|
+
|
|
35
|
+
out = shell.ls "-laZ"
|
|
36
|
+
p out.stderr
|
|
37
|
+
p out.status
|
|
38
|
+
|
|
39
|
+
out = shell.cd "/really/bogus/directory"
|
|
40
|
+
p out.stderr
|
|
41
|
+
p out.status
|
|
42
|
+
|
|
43
|
+
out = shell.send_command "/sbin/ifconfig"
|
|
44
|
+
p out.stdout
|
|
45
|
+
p out.status
|
|
46
|
+
|
|
47
|
+
out = shell.pwd
|
|
48
|
+
p out.stdout
|
|
49
|
+
|
|
50
|
+
out = shell.ruby "-v"
|
|
51
|
+
p out.stdout
|
|
52
|
+
|
|
53
|
+
out = shell.cd "/usr/lib"
|
|
54
|
+
|
|
55
|
+
out = shell.pwd
|
|
56
|
+
p out.stdout
|
|
57
|
+
|
|
58
|
+
out = shell.send_command( "bc", <<CMD )
|
|
59
|
+
5+5
|
|
60
|
+
10*2
|
|
61
|
+
scale=5
|
|
62
|
+
3/4
|
|
63
|
+
quit
|
|
64
|
+
CMD
|
|
65
|
+
p out.stdout
|
|
66
|
+
|
|
67
|
+
p shell.exit
|
|
68
|
+
|
|
69
|
+
end
|
data/examples/tail-demo.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#--
|
|
2
2
|
# =============================================================================
|
|
3
|
-
# Copyright (c) 2004, Jamis Buck (
|
|
3
|
+
# Copyright (c) 2004,2005 Jamis Buck (jamis_buck@byu.edu)
|
|
4
4
|
# All rights reserved.
|
|
5
5
|
#
|
|
6
6
|
# This source file is distributed as part of the Net::SSH Secure Shell Client
|
data/lib/net/ssh.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#--
|
|
2
2
|
# =============================================================================
|
|
3
|
-
# Copyright (c) 2004, Jamis Buck (
|
|
3
|
+
# Copyright (c) 2004,2005 Jamis Buck (jamis_buck@byu.edu)
|
|
4
4
|
# All rights reserved.
|
|
5
5
|
#
|
|
6
6
|
# This source file is distributed as part of the Net::SSH Secure Shell Client
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#--
|
|
2
2
|
# =============================================================================
|
|
3
|
-
# Copyright (c) 2004, Jamis Buck (
|
|
3
|
+
# Copyright (c) 2004,2005 Jamis Buck (jamis_buck@byu.edu)
|
|
4
4
|
# All rights reserved.
|
|
5
5
|
#
|
|
6
6
|
# This source file is distributed as part of the Net::SSH Secure Shell Client
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
#++
|
|
16
16
|
|
|
17
17
|
require 'net/ssh/connection/constants'
|
|
18
|
+
require 'net/ssh/connection/term'
|
|
18
19
|
|
|
19
20
|
module Net
|
|
20
21
|
module SSH
|
|
@@ -256,23 +257,78 @@ module Net
|
|
|
256
257
|
|
|
257
258
|
# Send a data packet to the server, over the channel.
|
|
258
259
|
def send_data( data )
|
|
260
|
+
@connection.register_data_request( self, data )
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
# Send an extended data packet to the server, over the channel.
|
|
264
|
+
# Extended data always has a numeric type associated with it. The
|
|
265
|
+
# only predefined type is 1, whic corresponds to +stderr+ data.
|
|
266
|
+
def send_extended_data( type, data )
|
|
267
|
+
@connection.register_data_request( self, data, type )
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
# Splits the given data so that it will fit in a data packet, taking
|
|
271
|
+
# into consideration the current window size and maximum packet size.
|
|
272
|
+
# The +overhead+ parameter is the number of additional bytes added by
|
|
273
|
+
# the packet itself.
|
|
274
|
+
#
|
|
275
|
+
# This returns a tuple, <tt>[data,data_to_return]</tt>, where the first
|
|
276
|
+
# element is the data to include in the packet, and the second element
|
|
277
|
+
# is the data remaining that would not fit in the packet.
|
|
278
|
+
def split_data_for_packet( data, overhead )
|
|
279
|
+
data_to_return = nil
|
|
280
|
+
|
|
281
|
+
if data.length > window_size
|
|
282
|
+
data_to_return = data[window_size..-1]
|
|
283
|
+
data = data[0,window_size]
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
if data.length + overhead > maximum_packet_size
|
|
287
|
+
data_to_return = data[maximum_packet_size..-1] +
|
|
288
|
+
( data_to_return || "" )
|
|
289
|
+
data = data[0,maximum_packet_size]
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
[ data, data_to_return ]
|
|
293
|
+
end
|
|
294
|
+
private :split_data_for_packet
|
|
295
|
+
|
|
296
|
+
# Send a data packet to the server, over the channel. Only sends as
|
|
297
|
+
# much of that data as the channel is currently capable of sending
|
|
298
|
+
# (based on window size and maximum packet size), and returns any
|
|
299
|
+
# data that could not be sent. Returns +nil+ if all the data that
|
|
300
|
+
# was requested to be sent, was sent.
|
|
301
|
+
def send_data_packet( data )
|
|
302
|
+
# overhead is ( byte.length + id.length + strlen.length ) = 9
|
|
303
|
+
data, data_to_return = split_data_for_packet( data.to_s, 9 )
|
|
304
|
+
@window_size -= data.length
|
|
305
|
+
|
|
259
306
|
msg = @buffers.writer
|
|
260
307
|
msg.write_byte CHANNEL_DATA
|
|
261
308
|
msg.write_long @remote_id
|
|
262
|
-
msg.write_string data
|
|
309
|
+
msg.write_string data
|
|
263
310
|
@connection.send_message msg
|
|
311
|
+
|
|
312
|
+
data_to_return
|
|
264
313
|
end
|
|
265
314
|
|
|
266
315
|
# Send an extended data packet to the server, over the channel.
|
|
267
316
|
# Extended data always has a numeric type associated with it. The
|
|
268
317
|
# only predefined type is 1, whic corresponds to +stderr+ data.
|
|
269
|
-
def
|
|
318
|
+
def send_extended_data_packet( type, data )
|
|
319
|
+
# overhead is
|
|
320
|
+
# ( byte.length + id.length + type.length + strlen.length ) = 13
|
|
321
|
+
data, data_to_return = split_data_for_packet( data.to_s, 13 )
|
|
322
|
+
@window_size -= data.length
|
|
323
|
+
|
|
270
324
|
msg = @buffers.writer
|
|
271
325
|
msg.write_byte CHANNEL_EXTENDED_DATA
|
|
272
326
|
msg.write_long @remote_id
|
|
273
327
|
msg.write_long type
|
|
274
|
-
msg.write_string data
|
|
328
|
+
msg.write_string data
|
|
275
329
|
@connection.send_message msg
|
|
330
|
+
|
|
331
|
+
data_to_return
|
|
276
332
|
end
|
|
277
333
|
|
|
278
334
|
VALID_PTY_OPTIONS = { :term=>"xterm",
|
|
@@ -295,9 +351,7 @@ module Net
|
|
|
295
351
|
"invalid option(s) to request_pty: #{invalid_opts.inspect}"
|
|
296
352
|
end
|
|
297
353
|
|
|
298
|
-
VALID_PTY_OPTIONS.
|
|
299
|
-
opts[ opt ] ||= VALID_PTY_OPTIONS[ opt ]
|
|
300
|
-
end
|
|
354
|
+
opts = VALID_PTY_OPTIONS.merge( opts )
|
|
301
355
|
|
|
302
356
|
msg = @buffers.writer
|
|
303
357
|
msg.write_string opts[ :term ]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#--
|
|
2
2
|
# =============================================================================
|
|
3
|
-
# Copyright (c) 2004, Jamis Buck (
|
|
3
|
+
# Copyright (c) 2004,2005 Jamis Buck (jamis_buck@byu.edu)
|
|
4
4
|
# All rights reserved.
|
|
5
5
|
#
|
|
6
6
|
# This source file is distributed as part of the Net::SSH Secure Shell Client
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#--
|
|
2
2
|
# =============================================================================
|
|
3
|
-
# Copyright (c) 2004, Jamis Buck (
|
|
3
|
+
# Copyright (c) 2004,2005 Jamis Buck (jamis_buck@byu.edu)
|
|
4
4
|
# All rights reserved.
|
|
5
5
|
#
|
|
6
6
|
# This source file is distributed as part of the Net::SSH Secure Shell Client
|
|
@@ -29,6 +29,10 @@ module Net
|
|
|
29
29
|
# #global_request method.
|
|
30
30
|
Request = Struct.new( :type, :data, :callback )
|
|
31
31
|
|
|
32
|
+
# A structure for representing a data buffer that must be sent
|
|
33
|
+
# across a channel.
|
|
34
|
+
DataRequest = Struct.new( :channel, :data, :type )
|
|
35
|
+
|
|
32
36
|
#--
|
|
33
37
|
# ====================================================================
|
|
34
38
|
# CONSTRUCTOR
|
|
@@ -51,6 +55,7 @@ module Net
|
|
|
51
55
|
@channel_map = Hash.new
|
|
52
56
|
@request_queue = Array.new
|
|
53
57
|
@channel_open_handlers = Hash.new
|
|
58
|
+
@data_requests = Array.new
|
|
54
59
|
end
|
|
55
60
|
|
|
56
61
|
#--
|
|
@@ -100,6 +105,21 @@ module Net
|
|
|
100
105
|
end
|
|
101
106
|
end
|
|
102
107
|
|
|
108
|
+
# Register a data buffer (of an optional type) to be sent across the
|
|
109
|
+
# given channel at the next available opportunity.
|
|
110
|
+
#
|
|
111
|
+
# This is used internally by channels to hide the window size and
|
|
112
|
+
# maximum packet size from the client. Clients should not call this
|
|
113
|
+
# method directly.
|
|
114
|
+
def register_data_request( channel, data, type=nil )
|
|
115
|
+
@data_requests << DataRequest.new( channel, data, type )
|
|
116
|
+
|
|
117
|
+
# make sure the new data request has a chance to be sent to the
|
|
118
|
+
# server... Otherwise, it cannot be sent until the next time #process
|
|
119
|
+
# is invoked, which can be unexpected in synchronous situations.
|
|
120
|
+
process_data_requests
|
|
121
|
+
end
|
|
122
|
+
|
|
103
123
|
#--
|
|
104
124
|
# ====================================================================
|
|
105
125
|
# CONNECTION PROCESSING
|
|
@@ -114,16 +134,23 @@ module Net
|
|
|
114
134
|
process while block.call
|
|
115
135
|
end
|
|
116
136
|
|
|
117
|
-
# Wait for and dispatch a single event.
|
|
118
|
-
|
|
119
|
-
|
|
137
|
+
# Wait for and dispatch a single event. If +nonblock+ is false (the
|
|
138
|
+
# default) this will block until a message has been received. Otherwise,
|
|
139
|
+
# it will return immediately.
|
|
140
|
+
def process( nonblock=false )
|
|
141
|
+
process_data_requests
|
|
120
142
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
143
|
+
if !nonblock || reader_ready?
|
|
144
|
+
type, response = @session.wait_for_message
|
|
145
|
+
|
|
146
|
+
unless ( dispatcher = MESSAGES[ type ] )
|
|
147
|
+
raise Net::SSH::Exception,
|
|
148
|
+
"Unexpected response type '#{type}', (#{response.inspect})"
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
dispatcher[:method].bind( self ).call( response )
|
|
124
152
|
end
|
|
125
153
|
|
|
126
|
-
dispatcher[:method].bind( self ).call( response )
|
|
127
154
|
self
|
|
128
155
|
end
|
|
129
156
|
|
|
@@ -153,6 +180,11 @@ module Net
|
|
|
153
180
|
self
|
|
154
181
|
end
|
|
155
182
|
|
|
183
|
+
# Delegates the the #reader_ready method of the transport session.
|
|
184
|
+
def reader_ready?
|
|
185
|
+
@session.reader_ready?
|
|
186
|
+
end
|
|
187
|
+
|
|
156
188
|
#--
|
|
157
189
|
# ====================================================================
|
|
158
190
|
# MESSAGE HANDLERS
|
|
@@ -316,6 +348,27 @@ module Net
|
|
|
316
348
|
request.callback.call( success, response ) if request.callback
|
|
317
349
|
end
|
|
318
350
|
|
|
351
|
+
# Process all pending data requests.
|
|
352
|
+
def process_data_requests
|
|
353
|
+
@data_requests.map! do |req|
|
|
354
|
+
while req && req.channel.window_size > 0
|
|
355
|
+
remaining = if req.type
|
|
356
|
+
req.channel.send_extended_data_packet( req.type, req.data )
|
|
357
|
+
else
|
|
358
|
+
req.channel.send_data_packet( req.data )
|
|
359
|
+
end
|
|
360
|
+
if remaining
|
|
361
|
+
req.data = remaining
|
|
362
|
+
else
|
|
363
|
+
req = nil
|
|
364
|
+
end
|
|
365
|
+
end
|
|
366
|
+
|
|
367
|
+
req
|
|
368
|
+
end
|
|
369
|
+
@data_requests.compact!
|
|
370
|
+
end
|
|
371
|
+
|
|
319
372
|
#--
|
|
320
373
|
# ====================================================================
|
|
321
374
|
# MESSAGE DISPATCHER SETUP
|