diff --git a/phpseclib/Net/SSH2.php b/phpseclib/Net/SSH2.php index 82f607d8..e4600c36 100644 --- a/phpseclib/Net/SSH2.php +++ b/phpseclib/Net/SSH2.php @@ -2778,7 +2778,7 @@ class SSH2 NET_SSH2_MSG_CHANNEL_REQUEST, $this->server_channels[self::CHANNEL_SHELL], 'pty-req', - 1, + true, // want reply $this->term, $this->windowColumns, $this->windowRows, @@ -2789,24 +2789,6 @@ class SSH2 $this->send_binary_packet($packet); - $response = $this->get_binary_packet(); - if ($response === false) { - $this->disconnect_helper(NET_SSH2_DISCONNECT_CONNECTION_LOST); - throw new ConnectionClosedException('Connection closed by server'); - } - - list($type) = Strings::unpackSSH2('C', $response); - - switch ($type) { - case NET_SSH2_MSG_CHANNEL_SUCCESS: - // if a pty can't be opened maybe commands can still be executed - case NET_SSH2_MSG_CHANNEL_FAILURE: - break; - default: - $this->disconnect_helper(NET_SSH2_DISCONNECT_BY_APPLICATION); - throw new \UnexpectedValueException('Unable to request pseudo-terminal'); - } - $packet = Strings::packSSH2( 'CNsb', NET_SSH2_MSG_CHANNEL_REQUEST, @@ -2816,7 +2798,7 @@ class SSH2 ); $this->send_binary_packet($packet); - $this->channel_status[self::CHANNEL_SHELL] = NET_SSH2_MSG_CHANNEL_REQUEST; + $this->channel_status[self::CHANNEL_SHELL] = NET_SSH2_MSG_IGNORE; $response = $this->get_channel_packet(self::CHANNEL_SHELL); if ($response === false) { @@ -3830,6 +3812,16 @@ class SSH2 throw new \RuntimeException('Unable to open channel'); } break; + case NET_SSH2_MSG_IGNORE: + switch ($type) { + case NET_SSH2_MSG_CHANNEL_SUCCESS: + //$this->channel_status[$channel] = NET_SSH2_MSG_CHANNEL_DATA; + continue 3; + case NET_SSH2_MSG_CHANNEL_FAILURE: + $this->_disconnect(NET_SSH2_DISCONNECT_BY_APPLICATION); + throw new \RuntimeException('Error opening channel'); + } + break; case NET_SSH2_MSG_CHANNEL_REQUEST: switch ($type) { case NET_SSH2_MSG_CHANNEL_SUCCESS: @@ -3849,6 +3841,10 @@ class SSH2 switch ($type) { case NET_SSH2_MSG_CHANNEL_DATA: + //if ($this->channel_status[$channel] == NET_SSH2_MSG_IGNORE) { + // $this->channel_status[$channel] = NET_SSH2_MSG_CHANNEL_DATA; + //} + /* if ($channel == self::CHANNEL_EXEC) { // SCP requires null packets, such as this, be sent. further, in the case of the ssh.com SSH server