php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #56483 Error starting up SSH connection(-2): Timeout waiting for banner
Submitted: 2005-08-09 11:27 UTC Modified: 2006-04-05 13:09 UTC
From: theonelikejibi at gmail dot com Assigned: pollita (profile)
Status: Closed Package: ssh2 (PECL)
PHP Version: 5_1 CVS-2005-08-09 (dev) OS: Windows 2000 Server
Private report: No CVE-ID: None
 [2005-08-09 11:27 UTC] theonelikejibi at gmail dot com
Description:
------------
When running any script that uses the PECL/ssh2 module, I am receiving an error: "Error starting up SSH connection(-2): Timeout waiting for banner".

In reference to Bug #4616, I upgraded to PHP 5.1b3 to attempt and fix this issue; however, I am still receiving the error when running a simple test script (from the SSH2 functions page).

Windows 2000 Server SP4
IIS 5.0
PHP 5.1b3
PECL/ssh2 5.1.0.0

I wasn't sure if the proper response would be to submit a new ticket or reply to a closed ticket, so I decided on the first option.

Reproduce code:
---------------
<?php
$connection = ssh2_connect('x.x.x.x', 22);

if (ssh2_auth_password($connection, 'uname', 'passwd')) {
  echo "Authentication Successful!\n";
} else {
  die('Authentication Failed...');
}
?>

Expected result:
----------------
I have yet to get this module to work with PHP and Windows/IIS, so I'm not sure.  With the test code provided above, the result should read 'Authentication Successful!' obviously.

Actual result:
--------------
Warning: ssh2_connect() [function.ssh2-connect]: Error starting up SSH connection(-2): Timeout waiting for banner in C:\Inetpub\wwwroot\ssh.php on line 2

Warning: ssh2_connect() [function.ssh2-connect]: Unable to connect to x.x.x.x in C:\Inetpub\wwwroot\ssh.php on line 2

Warning: ssh2_auth_password() expects parameter 1 to be resource, boolean given in C:\Inetpub\wwwroot\ssh.php on line 4
Authentication Failed...

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-09-30 15:46 UTC] jbrady at sbccd dot cc dot ca dot us
Using the DLL on 9/30/2005, I get the same error, but only for some connections. I also get an occaisional access error. 

After looking at the source code and doing some experiments, I have determined that on windows, it fails to caputure non-blocking socket errors in "libssh2_banner_receive()". For windows, you must use "(WSAGetLastError() != WSAEWOULDBLOCK)" to catch them. I fixed this, and I no longer get connection errors. I still however get the occasional access violation. I don't have the address with me at the moment, but I'll post it when I get it.

Windows 2003 SP1
IIS 6.0
PHP 5_1 CVS-2005-09-30
PECL/ssh2 5.1.0.0
 [2005-09-30 16:20 UTC] jbrady at sbccd dot cc dot ca dot us
I am getting the access violation at "010188BA".
 [2005-10-05 05:42 UTC] williamsp at goldencasket dot com
I have the same problem as above trying to connect from Windows 2000 Server to Cisco Router using 5.0.3. I note that Bug#4908 is very similar. V6 php_ssh2 was found http://pecl4win.php.net/index.php but supportive libraries are not yet available.
 [2005-10-06 23:44 UTC] williamsp at goldencasket dot com
PHP 5.1 has the same problem when connecting Windows Server to Cisco Router via SSH2
 [2005-11-08 16:43 UTC] noidea_2 at hotmail dot com
Classic "me too"-post: I've got the same issue using the dll november 8, Win XP Pro (IIS 5.1) and php 5.0.5. Tried to connect to Cisco IOS as well as a linux box from two different xp-boxes
 [2005-11-11 21:57 UTC] williamsp at goldencasket dot com
jbrady provided a new version of php_ssh2.dll for PHP 5.0.5.
Preliminary testing has allowed me to successfully connect and authentic with a Cisco Router using PHP - SSH2.
msvcr71.dll - microsoft C runtime library V7.1 was required.
 [2005-11-11 22:04 UTC] williamsp at goldencasket dot com
I am now using WAMP5 1.4.5 -->Apache/1.3.33 (Win32), PHP 5.0.5, MySQL 5.0.15 + your replacement extension php_ssh2.dll Preliminary testing has allowed me to successfully connect and authentic with a Cisco Router using PHP - SSH2. I will now replace the telnet object with a SSH object and hopefully everything should work as originally planned.
Note:
msvcr71.dll - Microsoft C runtime library V7.1 was required. 
Note:
If this hadn't worked I was thinking about trying the PHP/Java Bridge and adding the java secure shell library jsch-0.1.23.jar from http://www.sourceforge.net/
 [2005-11-19 05:43 UTC] decke at users dot sourceforge dot net
I got the same Error connecting to FreeBSD 5.4 and RedHat 9.0.

Windows 2000 SP4
Apache 1.3.33
PHP 5.1.0RC6
PECL4win/ssh2 5.1.0.0 (RC2-dev, 18.11.05)

FreeBSD 5.4 SSH-2.0-OpenSSH_3.8.1p1
RedHat 9.0 SSH-1.99-OpenSSH_3.5p1

For FreeBSD 5.4 the connect works about 50% of the time. It seems that the length of the banner doesn't matter i got the same result with 20 lines and also when removing it completely from sshd_config.
The RedHat machine has the same Banner and failes with 100% with "Error starting up SSH connection(-2): Timeout waiting for banner in ..."
 [2005-11-20 16:51 UTC] eric dot stoltz at deltanetsolutions dot com
OK I'm having the same problem. I'm trying to build a set of scripts to manipulate multiple cisco switches and routers.  I connect to them via ssh and I get the timed out waiting for banner message.  jbrady could you explain your comment about "(WSAGetLastError() != WSAEWOULDBLOCK)" 

I don't quite understand it.  

PHP 5.0.5 CLI
windows xp
php_ssh2.dll

Eric Stoltz, CCNA

"Never argue with an idiot.  He will only bring you down to his level and beat you with experience."
 [2005-11-22 14:17 UTC] jbrady at sbccd dot cc dot ca dot us
I have gotten ssh2 to work on windows. However, it doesn't work with ISAPI because it is not thread-safe. I think it doesn't use the openssl libraries in the required thread-safe manner (as in their documentation). We are currently using it with cgi-mode php and so far it's running great. We are also using 5.0.5, because 5.1 seemed to still have some problems with our website.

I'll try to send out the fixes soon. I need to use the current
 [2005-11-22 14:19 UTC] jbrady at sbccd dot cc dot ca dot us
Didn't finish... I need to use the current release version. My changes are based on a direct CVS pull. I'll try to get it out before thanksgiving :).
 [2005-11-23 13:05 UTC] jbrady at sbccd dot cc dot ca dot us
Ok, here is my patch. I used ssh2-0.10.tgz and libssh2-0.12.tar.gz. I unziped them in the following directory structure in the php source directory (php-src/ext/ssh2/...):
 
ssh2
|----->libssh2
            |----->src
            |----->include
 
I placed the files in the coresponding directories. Then you can run the patch by using patch. Go to a directory above ssh2 and run 'patch -p1 < path/to/php-ssh2_windows_fixes.diff'. You can also create them manually. Pay particular attention that ssh2/config.w32 and ssh2/libssh2/include/libssh2_config.h.in.w32 are new files. I got these from cvs on the php_ssh2 PECL site.
 
The main 2 fixes on in the patch are to ssh2/libssh2/src/session.c and ssh2/ssh2_fopen_wrappers.c. In session.c, they didn't check for windows WSAEWOULDBLOCK errors (even tho they did elsewhere). In ssh2_fopen_wrappers.c, their use of pointer arithmetic doesn't work (at least on my version of visual studio). I added perenthesis to clerify it, and it corrected a memory error.
 
Thats it. Tell me how it goes.
------------------------------------------------------------
diff -Naur orig/ssh2/config.w32 new/ssh2/config.w32
--- orig/ssh2/config.w32	1969-12-31 16:00:00.000000000 -0800
+++ new/ssh2/config.w32	2005-09-30 09:23:04.080944000 -0700
@@ -0,0 +1,32 @@
+// $Id: config.w32,v 1.9 2005/07/25 19:37:08 fmk Exp $
+// vim:ft=javascript
+
+ARG_WITH("ssh2", "SSH2 support", "no");
+
+if (PHP_SSH2 != "no") {
+	if ((!PHP_ZLIB_SHARED || CHECK_LIB("zlib.lib", "ssh2", PHP_SSH2)) &&
+		CHECK_LIB("libeay32.lib", "ssh2", PHP_SSH2) &&
+		CHECK_LIB("ssleay32.lib", "ssh2", PHP_SSH2) &&
+		CHECK_LIB("ws2_32.lib", "ssh2", PHP_SSH2)) {
+
+		FSO.CopyFile(configure_module_dirname + "\\libssh2\\include\\libssh2_config.h.in.w32",
+	  		 	configure_module_dirname + "\\libssh2\\include\\libssh2_config.h");
+
+		AC_DEFINE('HAVE_SSH2LIB', 1);
+		AC_DEFINE('PHP_SSH2_REMOTE_FORWARDING', 1);
+		AC_DEFINE('PHP_SSH2_HOSTBASED_AUTH', 1);
+		AC_DEFINE('PHP_SSH2_POLL', 1);
+		AC_DEFINE('PHP_SSH2_PUBLICKEY_SUBSYSTEM', 1);
+
+		ADD_FLAG('CFLAGS_SSH2', '/DLIBSSH2_WIN32=1 /DLIBSSH2_API= /I ' + 
+				configure_module_dirname + '/libssh2/include');
+
+		EXTENSION("ssh2", "ssh2.c ssh2_fopen_wrappers.c ssh2_sftp.c");
+
+		ADD_SOURCES(configure_module_dirname + "/libssh2/src", "channel.c  crypt.c \
+				kex.c misc.c publickey.c scp.c sftp.c comp.c hostkey.c mac.c packet.c \
+				session.c userauth.c", "ssh2");
+	} else {
+		WARNING("ssh2 not enabled: libraries or headers not found");
+	}
+}
diff -Naur orig/ssh2/libssh2/include/libssh2_config.h.in.w32 new/ssh2/libssh2/include/libssh2_config.h.in.w32
--- orig/ssh2/libssh2/include/libssh2_config.h.in.w32	1969-12-31 16:00:00.000000000 -0800
+++ new/ssh2/libssh2/include/libssh2_config.h.in.w32	2005-09-30 14:57:46.047393600 -0700
@@ -0,0 +1,59 @@
+#ifndef WIN32
+#define WIN32
+#endif
+#include <winsock2.h>
+#include <mswsock.h>
+#include <ws2tcpip.h>
+
+/* same as WSABUF */
+struct iovec {
+	u_long iov_len;
+	char *iov_base;
+};
+
+#define inline __inline
+
+static inline int writev(int sock, struct iovec *iov, int nvecs)
+{
+	DWORD ret;
+	if (WSASend(sock, (LPWSABUF)iov, nvecs, &ret, 0, NULL, NULL) == 0) {
+		return ret;
+	}
+	return -1;
+}
+
+/* not really usleep, but safe for the way we use it in this lib */
+static inline int usleep(int udelay)
+{
+	Sleep(udelay / 1000);
+	return 0;
+}
+
+#define snprintf	_snprintf
+
+/* Output connection layer debugging info to stderr */
+//#define LIBSSH2_DEBUG_CONNECTION 1
+
+/* Output failure events to stderr */
+//#define LIBSSH2_DEBUG_ERRORS 1
+
+/* Output Key Exchange debugging info to stderr */
+//#define LIBSSH2_DEBUG_KEX 1
+
+/* Output scp subsystem debugging info to stderr */
+//#define LIBSSH2_DEBUG_SCP 1
+
+/* Output sftp subsystem debugging info to stderr */
+//#define LIBSSH2_DEBUG_SFTP 1
+
+/* Output transport layer debugging info to stderr */
+//#define LIBSSH2_DEBUG_TRANSPORT 1
+
+/* Output userauth layer debugging info to stderr */
+//#define LIBSSH2_DEBUG_USERAUTH 1
+
+/* Compile in zlib support */
+#define LIBSSH2_HAVE_ZLIB 1
+
+/* Enable newer diffie-hellman-group-exchange-sha1 syntax */
+#define LIBSSH2_DH_GEX_NEW 1
diff -Naur orig/ssh2/libssh2/src/session.c new/ssh2/libssh2/src/session.c
--- orig/ssh2/libssh2/src/session.c	2005-07-12 19:49:44.000000000 -0700
+++ new/ssh2/libssh2/src/session.c	2005-11-22 21:02:48.676248000 -0800
@@ -103,9 +103,20 @@
 
 		ret = recv(session->socket_fd, &c, 1, LIBSSH2_SOCKET_RECV_FLAGS(session));
 
-		if ((ret < 0) && (ret != EAGAIN)) {
-			/* Some kinda error, but don't break for non-blocking issues */
-			return 1;
+		if (ret < 0) {
+#ifdef WIN32
+			switch (WSAGetLastError()) {
+				case WSAEWOULDBLOCK:	errno = EAGAIN;		break;
+				case WSAENOTCONN:
+				case WSAENOTSOCK:
+				case WSAECONNABORTED:	errno = EBADF;		break;
+				case WSAEINTR:			errno = EINTR;		break;
+			}
+#endif
+			if(errno != EAGAIN) {
+				/* Some kinda error, but don't break for non-blocking issues */
+				return 1;
+			}
 		}
 
 		if (ret <= 0) continue;
diff -Naur orig/ssh2/ssh2_fopen_wrappers.c new/ssh2/ssh2_fopen_wrappers.c
--- orig/ssh2/ssh2_fopen_wrappers.c	2005-11-01 15:24:12.000000000 -0800
+++ new/ssh2/ssh2_fopen_wrappers.c	2005-11-22 20:49:50.627468800 -0800
@@ -48,7 +48,7 @@
 {
 	php_ssh2_channel_data *abstract = (php_ssh2_channel_data*)stream->abstract;
 
-	if (!abstract->refcount || (--*(abstract->refcount) == 0)) {
+	if (!abstract->refcount || (--(*(abstract->refcount)) == 0)) {
 		/* Last one out, turn off the lights */
 		if (abstract->refcount) {
 			efree(abstract->refcount);
@@ -1232,7 +1232,7 @@
 		RETURN_FALSE;
 	}
 
-	*(data->refcount)++;
+	(*(data->refcount))++;
 
 	stream_data = emalloc(sizeof(php_ssh2_channel_data));
 	memcpy(stream_data, data, sizeof(php_ssh2_channel_data));
 [2005-12-20 08:31 UTC] mauroi at digbang dot com
Is there any news about this issue?
Seems it has been around some time now. Bug #3227 reports the same banner timeout and it dates from 2005-01-18.

Thanks in advance.
 [2006-04-05 13:09 UTC] pollita@php.net
This bug has been fixed in CVS.

In case this was a documentation problem, the fix will show up at the
end of next Sunday (CET) on pecl.php.net.

In case this was a pecl.php.net website problem, the change will show
up on the website in short time.
 
Thank you for the report, and for helping us make PECL better.

jbrady's patch seems to have done the trick according to user feedback, the latest snapshot at http://pecl4win.php.net/ext.php/php_ssh2.dll should work fine.  Sorry for the delay.
 [2006-04-17 11:36 UTC] mauroi at digbang dot com
Nothing to sorry about.
Thank you very much for your work.
 [2007-06-20 04:51 UTC] frank at nuoto dot it
if you have libeay32 ordinal not found error in the 0.9.8x version you must replace libeay32.dll and ssleay32.dll
library with those in the openssl 0.9.8e
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC