|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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... PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 19:00:01 2025 UTC |
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));