From 9d0b172103ddee18f29276af1790a0f59a065cd0 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sun, 10 Jun 2012 21:52:30 -0500 Subject: [PATCH] - exit-status's sent before channel data no longer produce empty output --- phpseclib/Net/SSH2.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/phpseclib/Net/SSH2.php b/phpseclib/Net/SSH2.php index 961b8241..95a47a88 100644 --- a/phpseclib/Net/SSH2.php +++ b/phpseclib/Net/SSH2.php @@ -2224,8 +2224,10 @@ class Net_SSH2 { case 'exit-status': // "The channel needs to be closed with SSH_MSG_CHANNEL_CLOSE after this message." // -- http://tools.ietf.org/html/rfc4254#section-6.10 - $this->_close_channel($client_channel); - return true; + $this->_send_binary_packet(pack('CN', NET_SSH2_MSG_CHANNEL_EOF, $this->server_channels[$client_channel])); + $this->_send_binary_packet(pack('CN', NET_SSH2_MSG_CHANNEL_CLOSE, $this->server_channels[$channel])); + + $this->channel_status[$channel] = NET_SSH2_MSG_CHANNEL_EOF; default: // "Some systems may not implement signals, in which case they SHOULD ignore this message." // -- http://tools.ietf.org/html/rfc4254#section-6.9 @@ -2233,7 +2235,16 @@ class Net_SSH2 { } break; case NET_SSH2_MSG_CHANNEL_CLOSE: - $this->_send_binary_packet(pack('CN', NET_SSH2_MSG_CHANNEL_CLOSE, $this->server_channels[$channel])); + $this->curTimeout = 0; + + if ($this->bitmap & NET_SSH2_MASK_SHELL) { + $this->bitmap&= ~NET_SSH2_MASK_SHELL; + } + if ($this->channel_status[$channel] != NET_SSH2_MSG_CHANNEL_EOF) { + $this->_send_binary_packet(pack('CN', NET_SSH2_MSG_CHANNEL_CLOSE, $this->server_channels[$channel])); + } + + $this->channel_status[$channel] = NET_SSH2_MSG_CHANNEL_CLOSE; return true; case NET_SSH2_MSG_CHANNEL_EOF: break; @@ -2843,4 +2854,4 @@ class Net_SSH2 { return $this->server_public_host_key; } -} +} \ No newline at end of file