Compare commits

..

47 Commits

Author SHA1 Message Date
Daniel Stenberg
8d9d3e0d7a release: updated to hold 1.2.7 info 2010-08-17 23:10:54 +02:00
Guenter Knauf
c46abb2663 Use the new libssh2.rc file. 2010-08-17 01:58:39 +02:00
Guenter Knauf
0a34fa79f0 Added resource file for libssh2.dll (shamelessly stolen from libcurl). 2010-08-17 01:54:20 +02:00
Guenter Knauf
43001570d6 Updated Win32 MSVC dependencies versions. 2010-08-17 01:35:55 +02:00
Guenter Knauf
4b878e7cf8 Added include for sys/select.h to get fd.set on some platforms. 2010-08-17 01:34:32 +02:00
Guenter Knauf
ac709e0d4f Added Watcom makefile borrowed from libcurl.
This makefile compiles already all files fine for static lib, but needs
final touch when I have OpenSSL fully working with shared libs and Watcom.
2010-08-16 16:10:07 +02:00
Guenter Knauf
56d0877f07 Added copyright define to libssh2.h and use it for binary builds. 2010-08-15 04:09:01 +02:00
Guenter Knauf
51a8335486 Moved version defines up in order to include from .rc file.
Blocked rest of header with ifndef so its possible to let
the rc compiler only use the version defines.
2010-08-15 03:38:49 +02:00
Guenter Knauf
2bd9418ac7 Some minor makefile tweaks. 2010-08-14 21:56:37 +02:00
Daniel Stenberg
4b8013a8a7 example: treat the libssh2_channel_read() return code properly
A short read is not an error. Only negative values are errors!
2010-08-02 00:20:24 +02:00
Daniel Stenberg
697b4e8ed7 libssh2_wait_socket: reset error code to "leak" EAGAIN less
Since libssh2 often sets LIBSSH2_ERROR_EAGAIN internally before
_libssh2_wait_socket is called, we can decrease some amount of
confusion in user programs by resetting the error code in this function
to reduce the risk of EAGAIN being stored as error when a blocking
function returns.
2010-07-18 19:47:21 +02:00
Daniel Stenberg
2afa5b2dc2 _libssh2_wait_socket: poll needs milliseconds
As reported on the mailing list, the code path using poll() should
multiple seconds with 1000 to get milliseconds, not divide!

Reported by: Jan Van Boghout
2010-07-17 19:20:20 +02:00
Daniel Stenberg
992aff7aca typedef: make ssize_t get typedef without LIBSSH2_WIN32
The condition around the ssize_t typedef depended on both LIBSSH2_WIN32
*and* _MSC_VER being defined when it should be enough to depend on
_MSC_VER only. It also makes it nicer so libssh2-using code builds fine
without having custom defines.
2010-07-06 16:17:59 +02:00
John Little
ef4c8718c2 session_free: free more data to avoid memory leaks 2010-07-01 19:56:06 +02:00
Daniel Stenberg
c375e5e5ad channel_free: ignore problems with channel_close()
As was pointed out in bug #182, we must not return failure from
_libssh2_channel_free() when _libssh2_channel_close() returns an error
that isn't EAGAIN. It can effectively cause the function to never go
through, like it did now in the case where the socket was actually
closed but socket_state still said LIBSSH2_SOCKET_CONNECTED.

I consider this fix the right thing as it now also survives other
errors, even if making sure socket_state isn't lying is also a good
idea.
2010-06-30 22:47:22 +02:00
Daniel Stenberg
46be03f92b publickey_list_free: no return value from a void function
Fixed a compiler warning I introduced previously when checking input
arguments more. I also added a check for the other pointer to avoid NULL
pointer dereferences.
2010-06-30 15:43:31 +02:00
Lars Nordin
1d83b520b4 openssl: make use of the EVP interface
Make use of the EVP interface for the AES-funktion. Using this method
supports the use of different ENGINES in OpenSSL for the AES function
(and the direct call to the AES_encrypt should not be used according to
openssl.org)
2010-06-27 22:23:50 +02:00
Tor Arntsen
f9c0a4a95a Don't overflow MD5 server hostkey
Use SHA_DIGEST_LENGTH and MD5_DIGEST_LENGTH in memcpy instead of hardcoded
values. An incorrect value was used for MD5.
2010-06-23 11:31:04 +02:00
Peter Stuge
7861ae8e4e Fix message length bugs in libssh2_debug()
There was a buffer overflow waiting to happen when a debug message was
longer than 1536 bytes.

Thanks to Daniel who spotted that there was a problem with the message
length passed to a trace handler also after commit
0f0652a309.
2010-06-23 11:16:02 +02:00
Peter Stuge
0f0652a309 Make libssh2_debug() create a correctly terminated string
Also use FILE *stderr rather than fd 2, which can very well be something
completely different.
2010-06-23 10:48:29 +02:00
TJ Saunders
2cc4a629ac handshake: Compression enabled at the wrong time
In KEXINIT messages, the client and server agree on, among other
things, whether to use compression. This method agreement occurs
in src/kex.c's kex_agree_methods() function. However, if
compression is enabled (either client->server, server->client, or
both), then the compression layer is initialized in
kex_agree_methods() -- before NEWKEYS has been received.

Instead, the initialization of the compression layer should
happen after NEWKEYS has been received. This looks to occur
insrc/kex.c's diffie_hellman_sha1(), which even has the comment:

    /* The first key exchange has been performed,

        switch to active crypt/comp/mac mode */

There, after NEWKEYS is received, the cipher and mac algorithms
are initialized, and that is where the compression should be
initialized as well.

The current implementation fails if server->client compression is
enabled because most server implementations follow OpenSSH's
lead, where compression is initialized after NEWKEYS. Since the
server initializes compression after NEWKEYS, but libssh2
initializes compression after KEXINIT (i.e. before NEWKEYS), they
are out of sync.

Reported in bug report #180
2010-06-23 00:03:31 +02:00
TJ Saunders
04f90b2265 userauth_hostbased_fromfile: packet length too short
The packet length calculated in src/userauth.c's
userauth_hostbased_fromfile() function is too short by 4 bytes;
it forgets to add four bytes for the length of the hostname.
This causes hostbased authentication to fail, since the server
will read junk data.

verified against proftpd's mod_sftp module
2010-06-22 23:34:21 +02:00
Daniel Stenberg
7dc2bfac94 _libssh2_userauth_publickey: reject method names longer than the data
This functions get the method length by looking at the first 32
bit of data, and I now made it not accept method lengths that are
longer than the whole data set is, as given in the dedicated
function argument.

This was detected when the function was given bogus public key
data as an ascii string, which caused the first 32bits to create
a HUGE number.
2010-06-20 00:23:28 +02:00
Daniel Stenberg
35cf08e130 NULL resistance: make more public functions survive NULL pointer input
Sending in NULL as the primary pointer is now dealt with by more
public functions. I also narrowed the userauth.c code somewhat to
stay within 80 columns better.
2010-06-18 20:25:03 +02:00
Daniel Stenberg
32bd0df992 agent: make libssh2_agent_userauth() work blocking properly
previously it would always work in a non-blocking manner
2010-06-18 20:13:08 +02:00
Peter Stuge
38940f45d2 Fix underscore typo for 64-bit printf format specifiers on Windows
Commit 49ddf447ff was missing underscores.
2010-06-17 12:23:25 +02:00
Daniel Stenberg
537a00ee4b libssh2_session_callback_set: extended the man page 2010-06-16 00:12:24 +02:00
John
6ddcc493e8 LIBSSH2_DEBUG: macro uses incorrect function variable
The LIBSSH2_DEBUG macro, defined in libssh2_priv.h, incorrectly uses the
function variable ssh_msg_disconnect when it should use ssh_msg_debug.

This shows that the LIBSSH2_CALLBACK_DEBUG callback never has worked...
2010-06-16 00:04:25 +02:00
Daniel Stenberg
3496e1c2a2 warning: fix a compiler warning 'pointer differs in signedness'
As reported in bug #177
2010-06-15 19:51:26 +02:00
Daniel Stenberg
49ddf447ff portability: introduce LIBSSH2_INT64_T_FORMAT for 64bit printf()s
As pointed out in bug #177, some of the Windows compilers use
%I64 to output 64 bit variables with the printf family.
2010-06-15 19:47:31 +02:00
Daniel Stenberg
04d4bbb66b debug: avoid sending NULL to sprintf %s
Via the _libssh2_debug() macro/function. Pointed out by john in bug report
2010-06-15 17:00:02 +02:00
Daniel Stenberg
897f8463d8 sftp docs: show macro on macro page, only function on function page
The individual man pages for macros now show the full convenience
macro as defined, and then the man page for the actual function
only shows the function.
2010-06-14 20:04:29 +02:00
Daniel Stenberg
2fd044fdf5 code police: make the code use less than 80 columns 2010-06-14 17:23:00 +02:00
Daniel Stenberg
20e969d2e0 libssh2_channel_write_ex: remove macros, added wording on buffer size 2010-06-13 17:00:43 +02:00
Daniel Stenberg
33e2bc8785 libssh2_sftp_write: document buffer size and changed some ordering 2010-06-13 17:00:14 +02:00
Daniel Stenberg
d7e6f9cf27 libssh2_channel_write_stderr: show how the macro is defined 2010-06-13 16:59:40 +02:00
Daniel Stenberg
be7cee1b3e libssh2_channel_write: show how the macro is defined 2010-06-13 16:59:18 +02:00
Daniel Stenberg
518d25eba1 SFTP: limit write() to not produce overly large packets
sftp_write() now limits how much data it gets at a time even more
than before. Since this function creates a complete outgoing
packet based on what gets passed to it, it is crucial that it
doesn't create too large packets.

With this method, there's also no longer any problem to use very
large buffers in your application and feed that to libssh2. I've
done numerous tests now with uploading data over SFTP using 100K
buffers and I've had no problems with that.
2010-06-11 16:07:30 +02:00
Daniel Stenberg
1785d0d6f3 scp_write_nonblock: add transfer time info
Using the same timing logic and output format as
sftp_write_nonblock allows us to very easily run benchmarks on
SCP vs SFTP uploads using libssh2.
2010-06-11 16:05:22 +02:00
Daniel Stenberg
31d71a94f2 sftp_write_nonblock: select() on socket, use *BIG* buffer, time transfer
The select() is just to make it nicer so that it doesn't
crazy-loop on EAGAIN. The buffer size thing is mostly to verify
that this really work as supposed.

Transfer timing is just a minor thing, but it can just as well be
there and help us time and work on performance easier using out
of the box examples.
2010-06-11 16:03:33 +02:00
Daniel Stenberg
22a2de7347 agent: use _libssh2_error() when returning errors
As pointed out in bug report #173, this module basically never
used _libssh2_error() which made it work inconstently with other
parts of the libssh2 code base. This is my first take at making
this code more in line with the rest.
2010-06-11 13:32:41 +02:00
Daniel Stenberg
4cf935abab inputchecks: make lots of API functions check for NULL pointers
If an application accidentally provides a NULL handle pointer to
the channel or sftp public functions, they now return an error
instead of segfaulting.
2010-06-11 13:05:55 +02:00
Daniel Stenberg
cce6ebbee7 libssh2_channel_eof: clarify that it returns negative on errors 2010-06-11 13:02:00 +02:00
Daniel Stenberg
18605cb81f SFTP: keep the sftp error code as 32 bit
'last_errno' holds to the error code from the SFTP protocol and
since that is 32 bits on the wire there's no point in using a
long for this internally which is larger on some platforms.
2010-06-11 13:00:31 +02:00
Daniel Stenberg
3490b3fe10 agent: make the code better deal with unexpected code flows
agent->ops gets initialized by the libssh2_agent_connect() call
but we need to make sure that we don't segfault even if a bad
sequence of function calls is used.
2010-06-11 11:13:46 +02:00
Alexander Lamaison
c87a48ae4c Better handling of invalid key files.
Passing an invalid public key to libssh2_userauth_publickey_fromfile_ex
triggered an assertion.  Replaced this with a runtime check that rejects
obviously invalid key data.
2010-06-10 12:25:26 +01:00
Daniel Stenberg
ab8ee8abf3 version: we start working on 1.2.7 now 2010-06-10 10:31:18 +02:00
39 changed files with 1025 additions and 361 deletions

27
NEWS
View File

@@ -1,3 +1,30 @@
libssh2 1.2.7 (August 17, 2010)
This release includes the following changes:
o Added Watcom makefile
This release includes the following bugfixes:
o Better handling of invalid key files
o inputchecks: make lots of API functions check for NULL pointers
o libssh2_session_callback_set: extended the man page
o SFTP: limit write() to not produce overly large packets
o agent: make libssh2_agent_userauth() work blocking properly
o _libssh2_userauth_publickey: reject method names longer than the data
o channel_free: ignore problems with channel_close()
o typedef: make ssize_t get typedef without LIBSSH2_WIN32
o _libssh2_wait_socket: poll needs milliseconds
o libssh2_wait_socket: reset error code to "leak" EAGAIN less
o Added include for sys/select.h to get fd.set on some platforms
o session_free: free more data to avoid memory leaks
o openssl: make use of the EVP interface
o Fix underscore typo for 64-bit printf format specifiers on Windows
o Make libssh2_debug() create a correctly terminated string
o userauth_hostbased_fromfile: packet length too short
o handshake: Compression enabled at the wrong time
o Don't overflow MD5 server hostkey
libssh2 1.2.6 (June 10, 2010) libssh2 1.2.6 (June 10, 2010)
This release includes the following changes: This release includes the following changes:

View File

@@ -1,32 +1,34 @@
libssh2 1.2.6 libssh2 1.2.7
This release includes the following changes: This release includes the following changes:
o Added libssh2_sftp_statvfs() and libssh2_sftp_fstatvfs() o Added Watcom makefile
o Added libssh2_knownhost_checkp()
o Added libssh2_scp_send64()
This release includes the following bugfixes: This release includes the following bugfixes:
o wait_socket: make c89 compliant and use two fd_sets for select() o Better handling of invalid key files
o OpenSSL AES-128-CTR detection o inputchecks: make lots of API functions check for NULL pointers
o proper keyboard-interactive user dialog in the sftp.c example o libssh2_session_callback_set: extended the man page
o build procedure for VMS o SFTP: limit write() to not produce overly large packets
o fixed libssh2.dsw to use the generated libssh2.dsp o agent: make libssh2_agent_userauth() work blocking properly
o several Windows-related build fixes o _libssh2_userauth_publickey: reject method names longer than the data
o fail to init SFTP if session isn't already authenticated o channel_free: ignore problems with channel_close()
o many tiny fixes that address clang-analyzer warnings o typedef: make ssize_t get typedef without LIBSSH2_WIN32
o sftp_open: deal with short channel_write calls o _libssh2_wait_socket: poll needs milliseconds
o libssh2_publickey_init: fixed to work better non-blocking o libssh2_wait_socket: reset error code to "leak" EAGAIN less
o sftp_close_handle: add precation to not access NULL pointer o Added include for sys/select.h to get fd.set on some platforms
o sftp_readdir: simplified and bugfixed o session_free: free more data to avoid memory leaks
o channel_write: if data has been sent, don't return EAGAIN o openssl: make use of the EVP interface
o Fix underscore typo for 64-bit printf format specifiers on Windows
o Make libssh2_debug() create a correctly terminated string
o userauth_hostbased_fromfile: packet length too short
o handshake: Compression enabled at the wrong time
o Don't overflow MD5 server hostkey
This release would not have looked like this without help, code, reports and This release would not have looked like this without help, code, reports and
advice from friends like these: advice from friends like these:
Alexander Lamaison, Guenter Knauf, Dan Fandrich, Grubsky Grigory, Alexander Lamaison, Guenter Knauf, Peter Stuge, Simon Josefsson, Lars Nordin,
Joey Degges, Jose Baars, Mikhail Gusarov, Peter Stuge, Simon Josefsson, John Little, Daniel Stenberg, TJ Saunders, Tor Arntsen
Daniel Stenberg
Thanks! (and sorry if I forgot to mention someone) Thanks! (and sorry if I forgot to mention someone)

View File

@@ -13,6 +13,7 @@ libssh2_channel_eof(LIBSSH2_CHANNEL *channel);
Check if the remote host has sent an EOF status for the selected stream. Check if the remote host has sent an EOF status for the selected stream.
.SH RETURN VALUE .SH RETURN VALUE
Returns 1 if the remote host has sent EOF, otherwise 0. Returns 1 if the remote host has sent EOF, otherwise 0. Negative on
failure.
.SH SEE ALSO .SH SEE ALSO
.BR libssh2_channel_close(3) .BR libssh2_channel_close(3)

View File

@@ -2,12 +2,13 @@
.\" .\"
.TH libssh2_channel_write 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" .TH libssh2_channel_write 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME .SH NAME
libssh2_channel_write - convenience macro for \fIlibssh2_channel_write_ex(3)\fP calls libssh2_channel_write - convenience macro for \fIlibssh2_channel_write_ex(3)\fP
.SH SYNOPSIS .SH SYNOPSIS
.nf
#include <libssh2.h> #include <libssh2.h>
libssh2_channel_write(arguments) #define libssh2_channel_write(channel, buf, buflen) \\
libssh2_channel_write_ex((channel), 0, (buf), (buflen))
.SH DESCRIPTION .SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_channel_write_ex(3)\fP. underlying function \fIlibssh2_channel_write_ex(3)\fP.

View File

@@ -4,16 +4,12 @@
.SH NAME .SH NAME
libssh2_channel_write_ex - write data to a channel stream blocking libssh2_channel_write_ex - write data to a channel stream blocking
.SH SYNOPSIS .SH SYNOPSIS
.nf
#include <libssh2.h> #include <libssh2.h>
ssize_t ssize_t libssh2_channel_write_ex(LIBSSH2_CHANNEL *channel,
libssh2_channel_write_ex(LIBSSH2_CHANNEL *channel, int stream_id, char *buf, size_t buflen); int stream_id, char *buf,
size_t buflen);
ssize_t
libssh2_channel_write(LIBSSH2_CHANNEL *channel, char *buf, size_t buflen);
ssize_t
libssh2_channel_write_stderr(LIBSSH2_CHANNEL *channel, char *buf, size_t buflen);
.SH DESCRIPTION .SH DESCRIPTION
Write data to a channel stream. All channel streams have one standard I/O Write data to a channel stream. All channel streams have one standard I/O
substream (stream_id == 0), and may have up to 2^32 extended data streams as substream (stream_id == 0), and may have up to 2^32 extended data streams as
@@ -29,7 +25,12 @@ defines a stream ID of 1 to be the stderr substream.
\fIbuflen\fP - size of the data to write \fIbuflen\fP - size of the data to write
\fIlibssh2_channel_write(3)\fP and \fIlibssh2_channel_write_stderr(3)\fP are \fIlibssh2_channel_write(3)\fP and \fIlibssh2_channel_write_stderr(3)\fP are
macros. convenience macros for this function.
\fIlibssh2_channel_write_ex(3)\fP will use as much as possible of the buffer
and put it into a single SSH protocol packet. This means that to get maximum
performance when sending larger files, you should try to always pass in at
least 32K of data to this function.
.SH RETURN VALUE .SH RETURN VALUE
Actual number of bytes written or negative on failure. Actual number of bytes written or negative on failure.
LIBSSH2_ERROR_EAGAIN when it would otherwise block. While LIBSSH2_ERROR_EAGAIN when it would otherwise block. While

View File

@@ -2,12 +2,13 @@
.\" .\"
.TH libssh2_channel_write_stderr 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" .TH libssh2_channel_write_stderr 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME .SH NAME
libssh2_channel_write_stderr - convenience macro for \fIlibssh2_channel_write_ex(3)\fP calls libssh2_channel_write_stderr - convenience macro for \fIlibssh2_channel_write_ex(3)\fP
.SH SYNOPSIS .SH SYNOPSIS
.nf
#include <libssh2.h> #include <libssh2.h>
libssh2_channel_write_stderr(arguments) #define libssh2_channel_write_stderr(channel, buf, buflen) \\
libssh2_channel_write_ex((channel), SSH_EXTENDED_DATA_STDERR, (buf), (buflen))
.SH DESCRIPTION .SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_channel_write_ex(3)\fP. underlying function \fIlibssh2_channel_write_ex(3)\fP.

View File

@@ -4,12 +4,16 @@
.SH NAME .SH NAME
libssh2_session_callback_set - set a callback function libssh2_session_callback_set - set a callback function
.SH SYNOPSIS .SH SYNOPSIS
.nf
#include <libssh2.h> #include <libssh2.h>
void * void *libssh2_session_callback_set(LIBSSH2_SESSION *session,
libssh2_session_callback_set(LIBSSH2_SESSION *session, int cbtype, void *callback); int cbtype, void *callback);
.SH DESCRIPTION .SH DESCRIPTION
Sets a custom callback handler for a previously initialized session
object. Callbacks are triggered by the receipt of special packets at the
Transport layer. To disable a callback, set it to NULL.
\fIsession\fP - Session instance as returned by \fIsession\fP - Session instance as returned by
.BR libssh2_session_init_ex(3) .BR libssh2_session_init_ex(3)
@@ -17,14 +21,19 @@ libssh2_session_callback_set(LIBSSH2_SESSION *session, int cbtype, void *callbac
\fIcallback\fP - Pointer to custom callback function. The prototype for \fIcallback\fP - Pointer to custom callback function. The prototype for
this function must match the associated callback declaration macro. this function must match the associated callback declaration macro.
.SH CALLBACK TYPES
Sets a custom callback handler for a previously initialized session .IP LIBSSH2_CALLBACK_IGNORE
object. Callbacks are triggered by the receipt of special packets at Called when a SSH_MSG_IGNORE message is received
the Transport layer. To disable a callback, set it to NULL. .IP LIBSSH2_CALLBACK_DEBUG
Called when a SSH_MSG_DEBUG message is received
.IP LIBSSH2_CALLBACK_DISCONNECT
Called when a SSH_MSG_DISCONNECT message is received
.IP LIBSSH2_CALLBACK_MACERROR
Called when a mismatched MAC has been detected in the transport layer
.IP LIBSSH2_CALLBACK_X11
Called when an X11 connection has been accepted
.SH RETURN VALUE .SH RETURN VALUE
Pointer to previous callback handler. Returns NULL if no Pointer to previous callback handler. Returns NULL if no prior callback
prior callback handler was set. handler was set or the callback type was unknown.
.SH SEE ALSO .SH SEE ALSO
.BR libssh2_session_init_ex(3) .BR libssh2_session_init_ex(3)

View File

@@ -2,12 +2,14 @@
.\" .\"
.TH libssh2_sftp_readlink 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" .TH libssh2_sftp_readlink 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME .SH NAME
libssh2_sftp_readlink - convenience macro for \fIlibssh2_sftp_symlink_ex(3)\fP calls libssh2_sftp_readlink - convenience macro for \fIlibssh2_sftp_symlink_ex(3)\fP
.SH SYNOPSIS .SH SYNOPSIS
.nf
#include <libssh2.h> #include <libssh2.h>
libssh2_sftp_readlink(arguments) #define libssh2_sftp_readlink(sftp, path, target, maxlen) \\
libssh2_sftp_symlink_ex((sftp), (path), strlen(path), (target), (maxlen), \\
LIBSSH2_SFTP_READLINK)
.SH DESCRIPTION .SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_sftp_symlink_ex(3)\fP. underlying function \fIlibssh2_sftp_symlink_ex(3)\fP.

View File

@@ -2,12 +2,14 @@
.\" .\"
.TH libssh2_sftp_realpath 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" .TH libssh2_sftp_realpath 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME .SH NAME
libssh2_sftp_realpath - convenience macro for \fIlibssh2_sftp_symlink_ex(3)\fP calls libssh2_sftp_realpath - convenience macro for \fIlibssh2_sftp_symlink_ex(3)\fP
.SH SYNOPSIS .SH SYNOPSIS
.nf
#include <libssh2.h> #include <libssh2.h>
libssh2_sftp_realpath(arguments) #define libssh2_sftp_realpath(sftp, path, target, maxlen) \\
libssh2_sftp_symlink_ex((sftp), (path), strlen(path), (target), (maxlen), \\
LIBSSH2_SFTP_REALPATH)
.SH DESCRIPTION .SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_sftp_symlink_ex(3)\fP. underlying function \fIlibssh2_sftp_symlink_ex(3)\fP.

View File

@@ -2,12 +2,13 @@
.\" .\"
.TH libssh2_sftp_rmdir 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" .TH libssh2_sftp_rmdir 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME .SH NAME
libssh2_sftp_rmdir - convenience macro for \fIlibssh2_sftp_rmdir_ex(3)\fP calls libssh2_sftp_rmdir - convenience macro for \fIlibssh2_sftp_rmdir_ex(3)\fP
.SH SYNOPSIS .SH SYNOPSIS
.nf
#include <libssh2.h> #include <libssh2.h>
libssh2_sftp_rmdir(arguments) #define libssh2_sftp_rmdir(sftp, path) \\
libssh2_sftp_rmdir_ex((sftp), (path), strlen(path))
.SH DESCRIPTION .SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_sftp_rmdir_ex(3)\fP. underlying function \fIlibssh2_sftp_rmdir_ex(3)\fP.

View File

@@ -4,30 +4,26 @@
.SH NAME .SH NAME
libssh2_sftp_rmdir_ex - remove an SFTP directory libssh2_sftp_rmdir_ex - remove an SFTP directory
.SH SYNOPSIS .SH SYNOPSIS
.nf
#include <libssh2.h> #include <libssh2.h>
#include <libssh2_sftp.h> #include <libssh2_sftp.h>
int int libssh2_sftp_rmdir_ex(LIBSSH2_SFTP *sftp, const char *path,
libssh2_sftp_rmdir_ex(LIBSSH2_SFTP *sftp, const char *path, unsigned int path_len); unsigned int path_len);
int
libssh2_sftp_rmdir_ex(LIBSSH2_SFTP *sftp, const char *path);
.SH DESCRIPTION .SH DESCRIPTION
Remove a directory from the remote file system.
\fIsftp\fP - SFTP instance as returned by \fIsftp\fP - SFTP instance as returned by
.BR libssh2_sftp_init(3) .BR libssh2_sftp_init(3)
\fIsourcefile\fP - Full path of the existing directory to remove. \fIsourcefile\fP - Full path of the existing directory to remove.
\fIsourcefile_len\fP - Length of the full path of the existing directory to remove. \fIsourcefile_len\fP - Length of the full path of the existing directory to
remove.
Remove a directory from the remote file system.
.SH RETURN VALUE .SH RETURN VALUE
Return 0 on success or negative on failure. It returns Return 0 on success or negative on failure. It returns
LIBSSH2_ERROR_EAGAIN when it would otherwise block. While LIBSSH2_ERROR_EAGAIN when it would otherwise block. While
LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se. LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se.
.SH ERRORS .SH ERRORS
\fILIBSSH2_ERROR_ALLOC\fP - An internal memory allocation call failed. \fILIBSSH2_ERROR_ALLOC\fP - An internal memory allocation call failed.
@@ -38,6 +34,5 @@ LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se.
\fILIBSSH2_ERROR_SFTP_PROTOCOL\fP - An invalid SFTP protocol response was \fILIBSSH2_ERROR_SFTP_PROTOCOL\fP - An invalid SFTP protocol response was
received on the socket, or an SFTP operation caused an errorcode to received on the socket, or an SFTP operation caused an errorcode to
be returned by the server. be returned by the server.
.SH SEE ALSO .SH SEE ALSO
.BR libssh2_sftp_init(3) .BR libssh2_sftp_init(3)

View File

@@ -2,12 +2,14 @@
.\" .\"
.TH libssh2_sftp_symlink 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual" .TH libssh2_sftp_symlink 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME .SH NAME
libssh2_sftp_symlink - convenience macro for \fIlibssh2_sftp_symlink_ex(3)\fP calls libssh2_sftp_symlink - convenience macro for \fIlibssh2_sftp_symlink_ex(3)\fP
.SH SYNOPSIS .SH SYNOPSIS
.nf
#include <libssh2.h> #include <libssh2.h>
libssh2_sftp_symlink(arguments) #define libssh2_sftp_symlink(sftp, orig, linkpath) \\
libssh2_sftp_symlink_ex((sftp), (orig), strlen(orig), (linkpath), \\
strlen(linkpath), LIBSSH2_SFTP_SYMLINK)
.SH DESCRIPTION .SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_sftp_symlink_ex(3)\fP. underlying function \fIlibssh2_sftp_symlink_ex(3)\fP.

View File

@@ -12,14 +12,6 @@ int
libssh2_sftp_symlink_ex(LIBSSH2_SFTP *sftp, const char *path, libssh2_sftp_symlink_ex(LIBSSH2_SFTP *sftp, const char *path,
unsigned int path_len, char *target, unsigned int path_len, char *target,
unsigned int target_len, int link_type); unsigned int target_len, int link_type);
int
libssh2_sftp_symlink(LIBSSH2_SFTP *sftp, const char *path, char *target);
int
libssh2_sftp_readlink(LIBSSH2_SFTP *sftp, const char *path, char *target,
unsigned int target_len);
int int
libssh2_sftp_realpath(LIBSSH2_SFTP *sftp, const char *path, char *target, libssh2_sftp_realpath(LIBSSH2_SFTP *sftp, const char *path, char *target,
unsigned int target_len); unsigned int target_len);

View File

@@ -4,23 +4,29 @@
.SH NAME .SH NAME
libssh2_sftp_write - write SFTP data libssh2_sftp_write - write SFTP data
.SH SYNOPSIS .SH SYNOPSIS
.nf
#include <libssh2.h> #include <libssh2.h>
#include <libssh2_sftp.h> #include <libssh2_sftp.h>
ssize_t ssize_t libssh2_sftp_write(LIBSSH2_SFTP_HANDLE *handle,
libssh2_sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer, size_t count); const char *buffer,
size_t count);
.SH DESCRIPTION .SH DESCRIPTION
\fBlibssh2_sftp_write(3)\fP writes a block of data to the SFTP server. This
method is modeled after the POSIX write() function and uses the same calling
semantics.
\fIhandle\fP - SFTP file handle as returned by \fIlibssh2_sftp_open_ex(3)\fP. \fIhandle\fP - SFTP file handle as returned by \fIlibssh2_sftp_open_ex(3)\fP.
\fIbuffer\fP - points to the data to send off \fIbuffer\fP - points to the data to send off.
\fIcount\fP - Number of bytes from 'buffer' to write. Note that it may not be \fIcount\fP - Number of bytes from 'buffer' to write. Note that it may not be
possible to write all bytes as requested. possible to write all bytes as requested.
\fBlibssh2_sftp_write(3)\fP writes a block of data to the SFTP server. This \fIlibssh2_sftp_handle(3)\fP will use as much as possible of the buffer and
method is modeled after the POSIX write() function and uses the same calling put it into a single SFTP protocol packet. This means that to get maximum
semantics. performance when sending larger files, you should try to always pass in at
least 32K of data to this function.
.SH RETURN VALUE .SH RETURN VALUE
Actual number of bytes written or negative on failure. Actual number of bytes written or negative on failure.

View File

@@ -151,10 +151,10 @@ int main(int argc, char *argv[])
} }
rc = libssh2_channel_read(channel, mem, amount); rc = libssh2_channel_read(channel, mem, amount);
if(rc == amount) { if(rc > 0) {
write(1, mem, rc); write(1, mem, rc);
} }
else { else if(rc < 0) {
fprintf(stderr, "libssh2_channel_read() failed: %d\n", rc); fprintf(stderr, "libssh2_channel_read() failed: %d\n", rc);
break; break;
} }

View File

@@ -32,6 +32,7 @@
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <ctype.h> #include <ctype.h>
#include <time.h>
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
@@ -50,10 +51,13 @@ int main(int argc, char *argv[])
#if defined(HAVE_IOCTLSOCKET) #if defined(HAVE_IOCTLSOCKET)
long flag = 1; long flag = 1;
#endif #endif
char mem[1024]; char mem[1024*100];
size_t nread; size_t nread;
char *ptr; char *ptr;
struct stat fileinfo; struct stat fileinfo;
time_t start;
long total = 0;
int duration;
#ifdef WIN32 #ifdef WIN32
WSADATA wsadata; WSADATA wsadata;
@@ -175,6 +179,7 @@ int main(int argc, char *argv[])
} while (!channel); } while (!channel);
fprintf(stderr, "SCP session waiting to send file\n"); fprintf(stderr, "SCP session waiting to send file\n");
start = time(NULL);
do { do {
nread = fread(mem, 1, sizeof(mem), local); nread = fread(mem, 1, sizeof(mem), local);
if (nread <= 0) { if (nread <= 0) {
@@ -183,6 +188,8 @@ int main(int argc, char *argv[])
} }
ptr = mem; ptr = mem;
total += nread;
do { do {
/* write the same data over and over, until error or completion */ /* write the same data over and over, until error or completion */
rc = libssh2_channel_write(channel, ptr, nread); rc = libssh2_channel_write(channel, ptr, nread);
@@ -199,6 +206,11 @@ int main(int argc, char *argv[])
} while (nread); } while (nread);
} while (!nread); /* only continue if nread was drained */ } while (!nread); /* only continue if nread was drained */
duration = (int)(time(NULL)-start);
printf("%ld bytes in %d seconds makes %.1f bytes/sec\n",
total, duration, total/(double)duration);
fprintf(stderr, "Sending EOF\n"); fprintf(stderr, "Sending EOF\n");
while (libssh2_channel_send_eof(channel) == LIBSSH2_ERROR_EAGAIN); while (libssh2_channel_send_eof(channel) == LIBSSH2_ERROR_EAGAIN);

View File

@@ -22,6 +22,9 @@
#ifdef HAVE_NETINET_IN_H #ifdef HAVE_NETINET_IN_H
# include <netinet/in.h> # include <netinet/in.h>
#endif #endif
#ifdef HAVE_SYS_SELECT_H
# include <sys/select.h>
#endif
# ifdef HAVE_UNISTD_H # ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
#endif #endif
@@ -34,6 +37,37 @@
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <ctype.h> #include <ctype.h>
#include <time.h>
static int waitsocket(int socket_fd, LIBSSH2_SESSION *session)
{
struct timeval timeout;
int rc;
fd_set fd;
fd_set *writefd = NULL;
fd_set *readfd = NULL;
int dir;
timeout.tv_sec = 10;
timeout.tv_usec = 0;
FD_ZERO(&fd);
FD_SET(socket_fd, &fd);
/* now make sure we wait in the correct direction */
dir = libssh2_session_block_directions(session);
if(dir & LIBSSH2_SESSION_BLOCK_INBOUND)
readfd = &fd;
if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND)
writefd = &fd;
rc = select(socket_fd + 1, readfd, writefd, NULL, &timeout);
return rc;
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
@@ -53,9 +87,12 @@ int main(int argc, char *argv[])
FILE *local; FILE *local;
LIBSSH2_SFTP *sftp_session; LIBSSH2_SFTP *sftp_session;
LIBSSH2_SFTP_HANDLE *sftp_handle; LIBSSH2_SFTP_HANDLE *sftp_handle;
char mem[1024]; char mem[1024 * 100];
size_t nread; size_t nread;
char *ptr; char *ptr;
time_t start;
long total = 0;
int duration;
#ifdef WIN32 #ifdef WIN32
WSADATA wsadata; WSADATA wsadata;
@@ -142,7 +179,8 @@ int main(int argc, char *argv[])
if (auth_pw) { if (auth_pw) {
/* We could authenticate via password */ /* We could authenticate via password */
while ((rc = libssh2_userauth_password(session, username, password)) == LIBSSH2_ERROR_EAGAIN); while ((rc = libssh2_userauth_password(session, username, password)) ==
LIBSSH2_ERROR_EAGAIN);
if (rc) { if (rc) {
printf("Authentication by password failed.\n"); printf("Authentication by password failed.\n");
goto shutdown; goto shutdown;
@@ -152,7 +190,8 @@ int main(int argc, char *argv[])
while ((rc = libssh2_userauth_publickey_fromfile(session, username, while ((rc = libssh2_userauth_publickey_fromfile(session, username,
"/home/username/.ssh/id_rsa.pub", "/home/username/.ssh/id_rsa.pub",
"/home/username/.ssh/id_rsa", "/home/username/.ssh/id_rsa",
password)) == LIBSSH2_ERROR_EAGAIN); password)) ==
LIBSSH2_ERROR_EAGAIN);
if (rc) { if (rc) {
printf("\tAuthentication by public key failed\n"); printf("\tAuthentication by public key failed\n");
goto shutdown; goto shutdown;
@@ -163,7 +202,8 @@ int main(int argc, char *argv[])
do { do {
sftp_session = libssh2_sftp_init(session); sftp_session = libssh2_sftp_init(session);
if ((!sftp_session) && (libssh2_session_last_errno(session) != LIBSSH2_ERROR_EAGAIN)) { if (!sftp_session &&
(libssh2_session_last_errno(session) != LIBSSH2_ERROR_EAGAIN)) {
fprintf(stderr, "Unable to init SFTP session\n"); fprintf(stderr, "Unable to init SFTP session\n");
goto shutdown; goto shutdown;
} }
@@ -178,13 +218,17 @@ int main(int argc, char *argv[])
LIBSSH2_SFTP_S_IRUSR|LIBSSH2_SFTP_S_IWUSR| LIBSSH2_SFTP_S_IRUSR|LIBSSH2_SFTP_S_IWUSR|
LIBSSH2_SFTP_S_IRGRP|LIBSSH2_SFTP_S_IROTH); LIBSSH2_SFTP_S_IRGRP|LIBSSH2_SFTP_S_IROTH);
if ((!sftp_handle) && (libssh2_session_last_errno(session) != LIBSSH2_ERROR_EAGAIN)) { if (!sftp_handle &&
(libssh2_session_last_errno(session) != LIBSSH2_ERROR_EAGAIN)) {
fprintf(stderr, "Unable to open file with SFTP\n"); fprintf(stderr, "Unable to open file with SFTP\n");
goto shutdown; goto shutdown;
} }
} while (!sftp_handle); } while (!sftp_handle);
fprintf(stderr, "libssh2_sftp_open() is done, now send data!\n"); fprintf(stderr, "libssh2_sftp_open() is done, now send data!\n");
start = time(NULL);
do { do {
nread = fread(mem, 1, sizeof(mem), local); nread = fread(mem, 1, sizeof(mem), local);
if (nread <= 0) { if (nread <= 0) {
@@ -193,16 +237,28 @@ int main(int argc, char *argv[])
} }
ptr = mem; ptr = mem;
total += nread;
do { do {
/* write data in a loop until we block */ /* write data in a loop until we block */
while ((rc = libssh2_sftp_write(sftp_handle, ptr, nread)) == LIBSSH2_ERROR_EAGAIN) { while ((rc = libssh2_sftp_write(sftp_handle, ptr, nread)) ==
; LIBSSH2_ERROR_EAGAIN) {
waitsocket(sock, session);
} }
if(rc < 0)
break;
ptr += rc; ptr += rc;
nread -= rc; nread -= rc;
} while (nread); } while (nread);
} while (rc > 0); } while (rc > 0);
duration = (int)(time(NULL)-start);
printf("%ld bytes in %d seconds makes %.1f bytes/sec\n",
total, duration, total/(double)duration);
fclose(local); fclose(local);
libssh2_sftp_close(sftp_handle); libssh2_sftp_close(sftp_handle);
libssh2_sftp_shutdown(sftp_session); libssh2_sftp_shutdown(sftp_session);

View File

@@ -1,7 +1,10 @@
# fetch libssh2 version number from input file and write them to STDOUT # fetch libssh2 version number from input file and write them to STDOUT
BEGIN { BEGIN {
while ((getline < ARGV[1]) > 0) { while ((getline < ARGV[1]) > 0) {
if (match ($0, /^#define LIBSSH2_VERSION[ |\t]+"[^"]+"/)) { if (match ($0, /^#define LIBSSH2_COPYRIGHT "[^"]+"$/)) {
my_copyright_str = substr($0, 28, length($0)-28);
}
else if (match ($0, /^#define LIBSSH2_VERSION[ |\t]+"[^"]+"/)) {
my_ver_str = substr($3, 2, length($3) - 2); my_ver_str = substr($3, 2, length($3) - 2);
split(my_ver_str, v, "."); split(my_ver_str, v, ".");
if (v[3]) if (v[3])
@@ -17,4 +20,5 @@ BEGIN {
} }
print "LIBSSH2_VERSION = " my_ver ""; print "LIBSSH2_VERSION = " my_ver "";
print "LIBSSH2_VERSION_STR = " my_ver_str ""; print "LIBSSH2_VERSION_STR = " my_ver_str "";
print "LIBSSH2_COPYRIGHT_STR = " my_copyright_str "";
} }

View File

@@ -40,6 +40,50 @@
#ifndef LIBSSH2_H #ifndef LIBSSH2_H
#define LIBSSH2_H 1 #define LIBSSH2_H 1
#define LIBSSH2_COPYRIGHT "2004-2010 The libssh2 project and its contributors."
/* We use underscore instead of dash when appending DEV in dev versions just
to make the BANNER define (used by src/session.c) be a valid SSH
banner. Release versions have no appended strings and may of course not
have dashes either. */
#define LIBSSH2_VERSION "1.2.7_DEV"
/* The numeric version number is also available "in parts" by using these
defines: */
#define LIBSSH2_VERSION_MAJOR 1
#define LIBSSH2_VERSION_MINOR 2
#define LIBSSH2_VERSION_PATCH 7
/* This is the numeric version of the libssh2 version number, meant for easier
parsing and comparions by programs. The LIBSSH2_VERSION_NUM define will
always follow this syntax:
0xXXYYZZ
Where XX, YY and ZZ are the main version, release and patch numbers in
hexadecimal (using 8 bits each). All three numbers are always represented
using two digits. 1.2 would appear as "0x010200" while version 9.11.7
appears as "0x090b07".
This 6-digit (24 bits) hexadecimal number does not show pre-release number,
and it is always a greater number in a more recent release. It makes
comparisons with greater than and less than work.
*/
#define LIBSSH2_VERSION_NUM 0x010207
/*
* This is the date and time when the full source package was created. The
* timestamp is not stored in the source code repo, as the timestamp is
* properly set in the tarballs by the maketgz script.
*
* The format of the date should follow this template:
*
* "Mon Feb 12 11:35:33 UTC 2007"
*/
#define LIBSSH2_TIMESTAMP "DEV"
#ifndef LIBSSH2_VERSION_ONLY
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@@ -73,7 +117,7 @@ typedef unsigned char uint8_t;
typedef unsigned int uint32_t; typedef unsigned int uint32_t;
#endif #endif
#if defined(LIBSSH2_WIN32) && defined(_MSC_VER) #ifdef _MSC_VER
typedef unsigned char uint8_t; typedef unsigned char uint8_t;
typedef unsigned int uint32_t; typedef unsigned int uint32_t;
typedef unsigned __int64 libssh2_uint64_t; typedef unsigned __int64 libssh2_uint64_t;
@@ -87,46 +131,6 @@ typedef unsigned long long libssh2_uint64_t;
typedef long long libssh2_int64_t; typedef long long libssh2_int64_t;
#endif #endif
/* We use underscore instead of dash when appending DEV in dev versions just
to make the BANNER define (used by src/session.c) be a valid SSH
banner. Release versions have no appended strings and may of course not
have dashes either. */
#define LIBSSH2_VERSION "1.2.6_DEV"
/* The numeric version number is also available "in parts" by using these
defines: */
#define LIBSSH2_VERSION_MAJOR 1
#define LIBSSH2_VERSION_MINOR 2
#define LIBSSH2_VERSION_PATCH 6
/* This is the numeric version of the libssh2 version number, meant for easier
parsing and comparions by programs. The LIBSSH2_VERSION_NUM define will
always follow this syntax:
0xXXYYZZ
Where XX, YY and ZZ are the main version, release and patch numbers in
hexadecimal (using 8 bits each). All three numbers are always represented
using two digits. 1.2 would appear as "0x010200" while version 9.11.7
appears as "0x090b07".
This 6-digit (24 bits) hexadecimal number does not show pre-release number,
and it is always a greater number in a more recent release. It makes
comparisons with greater than and less than work.
*/
#define LIBSSH2_VERSION_NUM 0x010206
/*
* This is the date and time when the full source package was created. The
* timestamp is not stored in the source code repo, as the timestamp is
* properly set in the tarballs by the maketgz script.
*
* The format of the date should follow this template:
*
* "Mon Feb 12 11:35:33 UTC 2007"
*/
#define LIBSSH2_TIMESTAMP "DEV"
/* Part of every banner, user specified or not */ /* Part of every banner, user specified or not */
#define LIBSSH2_SSH_BANNER "SSH-2.0-libssh2_" LIBSSH2_VERSION #define LIBSSH2_SSH_BANNER "SSH-2.0-libssh2_" LIBSSH2_VERSION
@@ -1108,4 +1112,6 @@ LIBSSH2_API int libssh2_trace_sethandler(LIBSSH2_SESSION *session,
} /* extern "C" */ } /* extern "C" */
#endif #endif
#endif /* LIBSSH2_VERSION_ONLY */
#endif /* LIBSSH2_H */ #endif /* LIBSSH2_H */

View File

@@ -3,9 +3,7 @@
## Makefile for building libssh2 (NetWare version - gnu make) ## Makefile for building libssh2 (NetWare version - gnu make)
## Use: make -f Makefile.netware [help|all|clean|dev|devclean|dist|distclean|lib|nlm|objclean] ## Use: make -f Makefile.netware [help|all|clean|dev|devclean|dist|distclean|lib|nlm|objclean]
## ##
## Comments to: Guenter Knauf <eflash@gmx.net> ## Comments to: Guenter Knauf http://www.gknw.net/phpbb
##
## $Id: Makefile.netware,v 1.14 2009/04/09 03:13:51 gknauf Exp $
# #
######################################################################### #########################################################################
@@ -21,7 +19,7 @@ endif
# Edit the path below to point to the base of your OpenSSL package. # Edit the path below to point to the base of your OpenSSL package.
ifndef OPENSSL_PATH ifndef OPENSSL_PATH
OPENSSL_PATH = ../../openssl-0.9.8n OPENSSL_PATH = ../../openssl-0.9.8o
endif endif
# Edit the path below to point to your Distribution folder. # Edit the path below to point to your Distribution folder.
@@ -39,7 +37,7 @@ DEVLARC = $(DEVLDIR).zip
# Edit the vars below to change NLM target settings. # Edit the vars below to change NLM target settings.
TARGET = libssh2 TARGET = libssh2
VERSION = $(LIBSSH2_VERSION) VERSION = $(LIBSSH2_VERSION)
COPYR = Copyright (c) 2004-2010 The libssh2 project and its contributors. COPYR = Copyright (c) $(LIBSSH2_COPYRIGHT_STR)
WWWURL = http://www.libssh2.org/ WWWURL = http://www.libssh2.org/
DESCR = libssh2 $(LIBSSH2_VERSION_STR) ($(LIBARCH)) - $(WWWURL) DESCR = libssh2 $(LIBSSH2_VERSION_STR) ($(LIBARCH)) - $(WWWURL)
MTSAFE = YES MTSAFE = YES
@@ -81,9 +79,9 @@ endif
CP = cp -afv CP = cp -afv
# RM = rm -f # RM = rm -f
# Here you can find a native Win32 binary of the original awk: # Here you can find a native Win32 binary of the original awk:
# http://www.gknw.net/development/prgtools/awk.zip # http://www.gknw.net/development/prgtools/awk-20070501.zip
AWK = awk AWK = awk
# if you want to mark the target as MTSAFE you will need a tool for # If you want to mark the target as MTSAFE you will need a tool for
# generating the xdc data for the linker; here's a minimal tool: # generating the xdc data for the linker; here's a minimal tool:
# http://www.gknw.net/development/prgtools/mkxdc.zip # http://www.gknw.net/development/prgtools/mkxdc.zip
MPKXDC = mkxdc MPKXDC = mkxdc
@@ -507,6 +505,7 @@ endif
@echo $(DL) libssh2_channel_write_ex,$(DL) >> $@ @echo $(DL) libssh2_channel_write_ex,$(DL) >> $@
@echo $(DL) libssh2_hostkey_hash,$(DL) >> $@ @echo $(DL) libssh2_hostkey_hash,$(DL) >> $@
@echo $(DL) libssh2_scp_recv,$(DL) >> $@ @echo $(DL) libssh2_scp_recv,$(DL) >> $@
@echo $(DL) libssh2_scp_send64,$(DL) >> $@
@echo $(DL) libssh2_scp_send_ex,$(DL) >> $@ @echo $(DL) libssh2_scp_send_ex,$(DL) >> $@
@echo $(DL) libssh2_knownhost_add,$(DL) >> $@ @echo $(DL) libssh2_knownhost_add,$(DL) >> $@
@echo $(DL) libssh2_knownhost_check,$(DL) >> $@ @echo $(DL) libssh2_knownhost_check,$(DL) >> $@

View File

@@ -3,9 +3,7 @@
## Makefile for building libssh2 (NetWare version - gnu make) ## Makefile for building libssh2 (NetWare version - gnu make)
## Use: make -f Makefile.netware ## Use: make -f Makefile.netware
## ##
## Comments to: Guenter Knauf <eflash@gmx.net> ## Comments to: Guenter Knauf http://www.gknw.net/phpbb
##
## $Id: Makefile.netware,v 1.10 2009/04/09 03:13:52 gknauf Exp $
# #
######################################################################### #########################################################################
@@ -21,7 +19,7 @@ endif
# Edit the path below to point to the base of your OpenSSL package. # Edit the path below to point to the base of your OpenSSL package.
ifndef OPENSSL_PATH ifndef OPENSSL_PATH
OPENSSL_PATH = ../../../openssl-0.9.8n OPENSSL_PATH = ../../../openssl-0.9.8o
endif endif
# Edit the var below to enable static linking of libssh2 and libz # Edit the var below to enable static linking of libssh2 and libz
@@ -75,9 +73,9 @@ endif
CP = cp -afv CP = cp -afv
# RM = rm -f # RM = rm -f
# Here you can find a native Win32 binary of the original awk: # Here you can find a native Win32 binary of the original awk:
# http://www.gknw.net/development/prgtools/awk.zip # http://www.gknw.net/development/prgtools/awk-20070501.zip
AWK = awk AWK = awk
# if you want to mark the target as MTSAFE you will need a tool for # If you want to mark the target as MTSAFE you will need a tool for
# generating the xdc data for the linker; here's a minimal tool: # generating the xdc data for the linker; here's a minimal tool:
# http://www.gknw.net/development/prgtools/mkxdc.zip # http://www.gknw.net/development/prgtools/mkxdc.zip
MPKXDC = mkxdc MPKXDC = mkxdc

View File

@@ -48,6 +48,7 @@
#undef PF_UNIX #undef PF_UNIX
#endif #endif
#include "userauth.h" #include "userauth.h"
#include "session.h"
/* Requests from client to agent for protocol 1 key operations */ /* Requests from client to agent for protocol 1 key operations */
#define SSH_AGENTC_REQUEST_RSA_IDENTITIES 1 #define SSH_AGENTC_REQUEST_RSA_IDENTITIES 1
@@ -146,23 +147,24 @@ agent_connect_unix(LIBSSH2_AGENT *agent)
struct sockaddr_un s_un; struct sockaddr_un s_un;
path = getenv("SSH_AUTH_SOCK"); path = getenv("SSH_AUTH_SOCK");
if (!path) { if (!path)
return -1; return _libssh2_error(agent->session, LIBSSH2_ERROR_BAD_USE,
} "no auth sock variable");
agent->fd = socket(PF_UNIX, SOCK_STREAM, 0); agent->fd = socket(PF_UNIX, SOCK_STREAM, 0);
if (agent->fd < 0) { if (agent->fd < 0)
return -1; return _libssh2_error(agent->session, LIBSSH2_ERROR_SOCKET_NONE,
} "failed creating socket");
s_un.sun_family = AF_UNIX; s_un.sun_family = AF_UNIX;
strncpy (s_un.sun_path, path, sizeof s_un.sun_path); strncpy (s_un.sun_path, path, sizeof s_un.sun_path);
if (connect(agent->fd, (struct sockaddr*)(&s_un), sizeof s_un) != 0) { if (connect(agent->fd, (struct sockaddr*)(&s_un), sizeof s_un) != 0) {
close (agent->fd); close (agent->fd);
return -1; return _libssh2_error(agent->session, LIBSSH2_ERROR_SOCKET_NONE,
"failed connecting");
} }
return 0; return LIBSSH2_ERROR_NONE;
} }
static int static int
@@ -178,7 +180,8 @@ agent_transact_unix(LIBSSH2_AGENT *agent, agent_transaction_ctx_t transctx)
if (rc < 0) { if (rc < 0) {
if (errno == EAGAIN) if (errno == EAGAIN)
return LIBSSH2_ERROR_EAGAIN; return LIBSSH2_ERROR_EAGAIN;
return -1; return _libssh2_error(agent->session, LIBSSH2_ERROR_SOCKET_SEND,
"agent send failed");
} }
transctx->state = agent_NB_state_request_length_sent; transctx->state = agent_NB_state_request_length_sent;
} }
@@ -190,7 +193,8 @@ agent_transact_unix(LIBSSH2_AGENT *agent, agent_transaction_ctx_t transctx)
if (rc < 0) { if (rc < 0) {
if (errno == EAGAIN) if (errno == EAGAIN)
return LIBSSH2_ERROR_EAGAIN; return LIBSSH2_ERROR_EAGAIN;
return -1; return _libssh2_error(agent->session, LIBSSH2_ERROR_SOCKET_SEND,
"agent send failed");
} }
transctx->state = agent_NB_state_request_sent; transctx->state = agent_NB_state_request_sent;
} }
@@ -201,14 +205,15 @@ agent_transact_unix(LIBSSH2_AGENT *agent, agent_transaction_ctx_t transctx)
if (rc < 0) { if (rc < 0) {
if (errno == EAGAIN) if (errno == EAGAIN)
return LIBSSH2_ERROR_EAGAIN; return LIBSSH2_ERROR_EAGAIN;
return -1; return _libssh2_error(agent->session, LIBSSH2_ERROR_SOCKET_NONE,
"agent recv failed");
} }
transctx->response_len = _libssh2_ntohu32(buf); transctx->response_len = _libssh2_ntohu32(buf);
transctx->response = LIBSSH2_ALLOC(agent->session, transctx->response = LIBSSH2_ALLOC(agent->session,
transctx->response_len); transctx->response_len);
if (!transctx->response) { if (!transctx->response)
return LIBSSH2_ERROR_ALLOC; return LIBSSH2_ERROR_ALLOC;
}
transctx->state = agent_NB_state_response_length_received; transctx->state = agent_NB_state_response_length_received;
} }
@@ -218,7 +223,8 @@ agent_transact_unix(LIBSSH2_AGENT *agent, agent_transaction_ctx_t transctx)
if (rc < 0) { if (rc < 0) {
if (errno == EAGAIN) if (errno == EAGAIN)
return LIBSSH2_ERROR_EAGAIN; return LIBSSH2_ERROR_EAGAIN;
return -1; return _libssh2_error(agent->session, LIBSSH2_ERROR_SOCKET_SEND,
"agent recv failed");
} }
transctx->state = agent_NB_state_response_received; transctx->state = agent_NB_state_response_received;
} }
@@ -229,7 +235,13 @@ agent_transact_unix(LIBSSH2_AGENT *agent, agent_transaction_ctx_t transctx)
static int static int
agent_disconnect_unix(LIBSSH2_AGENT *agent) agent_disconnect_unix(LIBSSH2_AGENT *agent)
{ {
return close(agent->fd); int ret;
ret = close(agent->fd);
if(ret == -1)
return _libssh2_error(agent->session, LIBSSH2_ERROR_SOCKET_DISCONNECT,
"failed closing the agent socket");
return LIBSSH2_ERROR_NONE;
} }
struct agent_ops agent_ops_unix = { struct agent_ops agent_ops_unix = {
@@ -256,9 +268,10 @@ agent_connect_pageant(LIBSSH2_AGENT *agent)
HWND hwnd; HWND hwnd;
hwnd = FindWindow("Pageant", "Pageant"); hwnd = FindWindow("Pageant", "Pageant");
if (!hwnd) if (!hwnd)
return -1; return _libssh2_error(agent->session, LIBSSH2_ERROR_SOCKET_NONE,
"failed connecting agent");
agent->fd = 0; /* Mark as the connection has been established */ agent->fd = 0; /* Mark as the connection has been established */
return 0; return LIBSSH2_ERROR_NONE;
} }
static int static int
@@ -272,21 +285,26 @@ agent_transact_pageant(LIBSSH2_AGENT *agent, agent_transaction_ctx_t transctx)
int id; int id;
COPYDATASTRUCT cds; COPYDATASTRUCT cds;
if (!transctx || 4 + transctx->request_len > PAGEANT_MAX_MSGLEN) { if (!transctx || 4 + transctx->request_len > PAGEANT_MAX_MSGLEN)
return LIBSSH2_ERROR_INVAL; return _libssh2_error(agent->session, LIBSSH2_ERROR_INVAL,
} "illegal input");
hwnd = FindWindow("Pageant", "Pageant"); hwnd = FindWindow("Pageant", "Pageant");
if (!hwnd) { if (!hwnd)
return -1; return _libssh2_error(agent->session, LIBSSH2_ERROR_AGENT_PROTOCOL,
} "found no pageant");
sprintf(mapname, "PageantRequest%08x", (unsigned)GetCurrentThreadId()); sprintf(mapname, "PageantRequest%08x", (unsigned)GetCurrentThreadId());
filemap = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, filemap = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE,
0, PAGEANT_MAX_MSGLEN, mapname); 0, PAGEANT_MAX_MSGLEN, mapname);
if (filemap == NULL || filemap == INVALID_HANDLE_VALUE) {
return -1; if (filemap == NULL || filemap == INVALID_HANDLE_VALUE)
} return _libssh2_error(agent->session, LIBSSH2_ERROR_AGENT_PROTOCOL,
"failed setting up pageant filemap");
p2 = p = MapViewOfFile(filemap, FILE_MAP_WRITE, 0, 0, 0); p2 = p = MapViewOfFile(filemap, FILE_MAP_WRITE, 0, 0, 0);
_libssh2_store_str(&p2, transctx->request, transctx->request_len); _libssh2_store_str(&p2, (const char *)transctx->request,
transctx->request_len);
cds.dwData = PAGEANT_COPYDATA_ID; cds.dwData = PAGEANT_COPYDATA_ID;
cds.cbData = 1 + strlen(mapname); cds.cbData = 1 + strlen(mapname);
@@ -298,14 +316,16 @@ agent_transact_pageant(LIBSSH2_AGENT *agent, agent_transaction_ctx_t transctx)
if (transctx->response_len > PAGEANT_MAX_MSGLEN) { if (transctx->response_len > PAGEANT_MAX_MSGLEN) {
UnmapViewOfFile(p); UnmapViewOfFile(p);
CloseHandle(filemap); CloseHandle(filemap);
return LIBSSH2_ERROR_AGENT_PROTOCOL; return _libssh2_error(agent->session, LIBSSH2_ERROR_AGENT_PROTOCOL,
"agent setup fail");
} }
transctx->response = LIBSSH2_ALLOC(agent->session, transctx->response = LIBSSH2_ALLOC(agent->session,
transctx->response_len); transctx->response_len);
if (!transctx->response) { if (!transctx->response) {
UnmapViewOfFile(p); UnmapViewOfFile(p);
CloseHandle(filemap); CloseHandle(filemap);
return LIBSSH2_ERROR_ALLOC; return _libssh2_error(agent->session, LIBSSH2_ERROR_ALLOC,
"agent malloc");
} }
memcpy(transctx->response, p + 4, transctx->response_len); memcpy(transctx->response, p + 4, transctx->response_len);
} }
@@ -357,9 +377,9 @@ agent_sign(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len,
/* Create a request to sign the data */ /* Create a request to sign the data */
if (transctx->state == agent_NB_state_init) { if (transctx->state == agent_NB_state_init) {
s = transctx->request = LIBSSH2_ALLOC(session, len); s = transctx->request = LIBSSH2_ALLOC(session, len);
if (!transctx->request) { if (!transctx->request)
return LIBSSH2_ERROR_ALLOC; return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
} "out of memory");
*s++ = SSH2_AGENTC_SIGN_REQUEST; *s++ = SSH2_AGENTC_SIGN_REQUEST;
/* key blob */ /* key blob */
@@ -376,9 +396,14 @@ agent_sign(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len,
} }
/* Make sure to be re-called as a result of EAGAIN. */ /* Make sure to be re-called as a result of EAGAIN. */
if (*transctx->request != SSH2_AGENTC_SIGN_REQUEST) { if (*transctx->request != SSH2_AGENTC_SIGN_REQUEST)
return LIBSSH2_ERROR_BAD_USE; return _libssh2_error(session, LIBSSH2_ERROR_BAD_USE,
} "illegal request");
if (!agent->ops)
/* if no agent has been connected, bail out */
return _libssh2_error(session, LIBSSH2_ERROR_BAD_USE,
"agent not connected");
rc = agent->ops->transact(agent, transctx); rc = agent->ops->transact(agent, transctx);
if (rc) { if (rc) {
@@ -451,7 +476,7 @@ agent_sign(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len,
LIBSSH2_FREE(session, transctx->response); LIBSSH2_FREE(session, transctx->response);
transctx->response = NULL; transctx->response = NULL;
return rc; return _libssh2_error(session, rc, "agent sign failure");
} }
static int static int
@@ -471,9 +496,14 @@ agent_list_identities(LIBSSH2_AGENT *agent)
} }
/* Make sure to be re-called as a result of EAGAIN. */ /* Make sure to be re-called as a result of EAGAIN. */
if (*transctx->request != SSH2_AGENTC_REQUEST_IDENTITIES) { if (*transctx->request != SSH2_AGENTC_REQUEST_IDENTITIES)
return LIBSSH2_ERROR_BAD_USE; return _libssh2_error(agent->session, LIBSSH2_ERROR_BAD_USE,
} "illegal agent request");
if (!agent->ops)
/* if no agent has been connected, bail out */
return _libssh2_error(agent->session, LIBSSH2_ERROR_BAD_USE,
"agent not connected");
rc = agent->ops->transact(agent, transctx); rc = agent->ops->transact(agent, transctx);
if (rc) { if (rc) {
@@ -568,7 +598,8 @@ agent_list_identities(LIBSSH2_AGENT *agent)
LIBSSH2_FREE(agent->session, transctx->response); LIBSSH2_FREE(agent->session, transctx->response);
transctx->response = NULL; transctx->response = NULL;
return rc; return _libssh2_error(agent->session, rc,
"agent list id failed");
} }
static void static void
@@ -713,17 +744,21 @@ libssh2_agent_userauth(LIBSSH2_AGENT *agent,
struct libssh2_agent_publickey *identity) struct libssh2_agent_publickey *identity)
{ {
void *abstract = agent; void *abstract = agent;
int rc;
if (agent->session->userauth_pblc_state == libssh2_NB_state_idle) { if (agent->session->userauth_pblc_state == libssh2_NB_state_idle) {
memset(&agent->transctx, 0, sizeof agent->transctx); memset(&agent->transctx, 0, sizeof agent->transctx);
agent->identity = identity->node; agent->identity = identity->node;
} }
return _libssh2_userauth_publickey(agent->session, username,
BLOCK_ADJUST(rc, agent->session,
_libssh2_userauth_publickey(agent->session, username,
strlen(username), strlen(username),
identity->blob, identity->blob,
identity->blob_len, identity->blob_len,
agent_sign, agent_sign,
&abstract); &abstract));
return rc;
} }
/* /*

View File

@@ -329,6 +329,10 @@ libssh2_channel_open_ex(LIBSSH2_SESSION *session, const char *type,
const char *msg, unsigned int msg_len) const char *msg, unsigned int msg_len)
{ {
LIBSSH2_CHANNEL *ptr; LIBSSH2_CHANNEL *ptr;
if(!session)
return NULL;
BLOCK_ADJUST_ERRNO(ptr, session, BLOCK_ADJUST_ERRNO(ptr, session,
_libssh2_channel_open(session, type, type_len, _libssh2_channel_open(session, type, type_len,
window_size, packet_size, window_size, packet_size,
@@ -402,10 +406,14 @@ channel_direct_tcpip(LIBSSH2_SESSION * session, const char *host,
* Tunnel TCP/IP connect through the SSH session to direct host/port * Tunnel TCP/IP connect through the SSH session to direct host/port
*/ */
LIBSSH2_API LIBSSH2_CHANNEL * LIBSSH2_API LIBSSH2_CHANNEL *
libssh2_channel_direct_tcpip_ex(LIBSSH2_SESSION * session, const char *host, libssh2_channel_direct_tcpip_ex(LIBSSH2_SESSION *session, const char *host,
int port, const char *shost, int sport) int port, const char *shost, int sport)
{ {
LIBSSH2_CHANNEL *ptr; LIBSSH2_CHANNEL *ptr;
if(!session)
return NULL;
BLOCK_ADJUST_ERRNO(ptr, session, BLOCK_ADJUST_ERRNO(ptr, session,
channel_direct_tcpip(session, host, port, shost, sport)); channel_direct_tcpip(session, host, port, shost, sport));
return ptr; return ptr;
@@ -569,6 +577,10 @@ libssh2_channel_forward_listen_ex(LIBSSH2_SESSION *session, const char *host,
int port, int *bound_port, int queue_maxsize) int port, int *bound_port, int queue_maxsize)
{ {
LIBSSH2_LISTENER *ptr; LIBSSH2_LISTENER *ptr;
if(!session)
return NULL;
BLOCK_ADJUST_ERRNO(ptr, session, BLOCK_ADJUST_ERRNO(ptr, session,
channel_forward_listen(session, host, port, bound_port, channel_forward_listen(session, host, port, bound_port,
queue_maxsize)); queue_maxsize));
@@ -673,6 +685,10 @@ LIBSSH2_API int
libssh2_channel_forward_cancel(LIBSSH2_LISTENER *listener) libssh2_channel_forward_cancel(LIBSSH2_LISTENER *listener)
{ {
int rc; int rc;
if(!listener)
return LIBSSH2_ERROR_BAD_USE;
BLOCK_ADJUST(rc, listener->session, BLOCK_ADJUST(rc, listener->session,
_libssh2_channel_forward_cancel(listener)); _libssh2_channel_forward_cancel(listener));
return rc; return rc;
@@ -725,6 +741,10 @@ LIBSSH2_API LIBSSH2_CHANNEL *
libssh2_channel_forward_accept(LIBSSH2_LISTENER *listener) libssh2_channel_forward_accept(LIBSSH2_LISTENER *listener)
{ {
LIBSSH2_CHANNEL *ptr; LIBSSH2_CHANNEL *ptr;
if(!listener)
return NULL;
BLOCK_ADJUST_ERRNO(ptr, listener->session, BLOCK_ADJUST_ERRNO(ptr, listener->session,
channel_forward_accept(listener)); channel_forward_accept(listener));
return ptr; return ptr;
@@ -838,6 +858,10 @@ libssh2_channel_setenv_ex(LIBSSH2_CHANNEL *channel,
const char *value, unsigned int value_len) const char *value, unsigned int value_len)
{ {
int rc; int rc;
if(!channel)
return LIBSSH2_ERROR_BAD_USE;
BLOCK_ADJUST(rc, channel->session, BLOCK_ADJUST(rc, channel->session,
channel_setenv(channel, varname, varname_len, channel_setenv(channel, varname, varname_len,
value, value_len)); value, value_len));
@@ -955,6 +979,10 @@ libssh2_channel_request_pty_ex(LIBSSH2_CHANNEL *channel, const char *term,
int width_px, int height_px) int width_px, int height_px)
{ {
int rc; int rc;
if(!channel)
return LIBSSH2_ERROR_BAD_USE;
BLOCK_ADJUST(rc, channel->session, BLOCK_ADJUST(rc, channel->session,
channel_request_pty(channel, term, term_len, modes, channel_request_pty(channel, term, term_len, modes,
modes_len, width, height, modes_len, width, height,
@@ -1031,6 +1059,10 @@ libssh2_channel_request_pty_size_ex(LIBSSH2_CHANNEL *channel, int width,
int height, int width_px, int height_px) int height, int width_px, int height_px)
{ {
int rc; int rc;
if(!channel)
return LIBSSH2_ERROR_BAD_USE;
BLOCK_ADJUST(rc, channel->session, BLOCK_ADJUST(rc, channel->session,
channel_request_pty_size(channel, width, height, width_px, channel_request_pty_size(channel, width, height, width_px,
height_px)); height_px));
@@ -1175,6 +1207,10 @@ libssh2_channel_x11_req_ex(LIBSSH2_CHANNEL *channel, int single_connection,
int screen_number) int screen_number)
{ {
int rc; int rc;
if(!channel)
return LIBSSH2_ERROR_BAD_USE;
BLOCK_ADJUST(rc, channel->session, BLOCK_ADJUST(rc, channel->session,
channel_x11_req(channel, single_connection, auth_proto, channel_x11_req(channel, single_connection, auth_proto,
auth_cookie, screen_number)); auth_cookie, screen_number));
@@ -1206,21 +1242,19 @@ _libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel,
memset(&channel->process_packet_requirev_state, 0, memset(&channel->process_packet_requirev_state, 0,
sizeof(channel->process_packet_requirev_state)); sizeof(channel->process_packet_requirev_state));
if (message) { if (message)
channel->process_packet_len += message_len + 4; channel->process_packet_len += message_len + 4;
}
_libssh2_debug(session, LIBSSH2_TRACE_CONN, _libssh2_debug(session, LIBSSH2_TRACE_CONN,
"starting request(%s) on channel %lu/%lu, message=%s", "starting request(%s) on channel %lu/%lu, message=%s",
request, channel->local.id, channel->remote.id, request, channel->local.id, channel->remote.id,
message); message?message:"<null>");
s = channel->process_packet = s = channel->process_packet =
LIBSSH2_ALLOC(session, channel->process_packet_len); LIBSSH2_ALLOC(session, channel->process_packet_len);
if (!channel->process_packet) { if (!channel->process_packet)
return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory " "Unable to allocate memory "
"for channel-process request"); "for channel-process request");
}
*(s++) = SSH_MSG_CHANNEL_REQUEST; *(s++) = SSH_MSG_CHANNEL_REQUEST;
_libssh2_store_u32(&s, channel->remote.id); _libssh2_store_u32(&s, channel->remote.id);
@@ -1293,6 +1327,10 @@ libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel,
const char *msg, unsigned int msg_len) const char *msg, unsigned int msg_len)
{ {
int rc; int rc;
if(!channel)
return LIBSSH2_ERROR_BAD_USE;
BLOCK_ADJUST(rc, channel->session, BLOCK_ADJUST(rc, channel->session,
_libssh2_channel_process_startup(channel, req, req_len, _libssh2_channel_process_startup(channel, req, req_len,
msg, msg_len)); msg, msg_len));
@@ -1309,6 +1347,7 @@ libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel,
LIBSSH2_API void LIBSSH2_API void
libssh2_channel_set_blocking(LIBSSH2_CHANNEL * channel, int blocking) libssh2_channel_set_blocking(LIBSSH2_CHANNEL * channel, int blocking)
{ {
if(channel)
(void) _libssh2_session_set_blocking(channel->session, blocking); (void) _libssh2_session_set_blocking(channel->session, blocking);
} }
@@ -1394,6 +1433,10 @@ LIBSSH2_API int
libssh2_channel_flush_ex(LIBSSH2_CHANNEL *channel, int stream) libssh2_channel_flush_ex(LIBSSH2_CHANNEL *channel, int stream)
{ {
int rc; int rc;
if(!channel)
return LIBSSH2_ERROR_BAD_USE;
BLOCK_ADJUST(rc, channel->session, BLOCK_ADJUST(rc, channel->session,
_libssh2_channel_flush(channel, stream)); _libssh2_channel_flush(channel, stream));
return rc; return rc;
@@ -1402,11 +1445,17 @@ libssh2_channel_flush_ex(LIBSSH2_CHANNEL *channel, int stream)
/* /*
* libssh2_channel_get_exit_status * libssh2_channel_get_exit_status
* *
* Return the channel's program exit status * Return the channel's program exit status. Note that the actual protocol
* provides the full 32bit this function returns. We cannot abuse it to
* return error values in case of errors so we return a zero if channel is
* NULL.
*/ */
LIBSSH2_API int LIBSSH2_API int
libssh2_channel_get_exit_status(LIBSSH2_CHANNEL * channel) libssh2_channel_get_exit_status(LIBSSH2_CHANNEL *channel)
{ {
if(!channel)
return 0;
return channel->exit_status; return channel->exit_status;
} }
@@ -1502,6 +1551,10 @@ libssh2_channel_receive_window_adjust(LIBSSH2_CHANNEL *channel,
{ {
unsigned int window; unsigned int window;
int rc; int rc;
if(!channel)
return LIBSSH2_ERROR_BAD_USE;
BLOCK_ADJUST(rc, channel->session, BLOCK_ADJUST(rc, channel->session,
_libssh2_channel_receive_window_adjust(channel, adj, _libssh2_channel_receive_window_adjust(channel, adj,
force, &window)); force, &window));
@@ -1529,6 +1582,10 @@ libssh2_channel_receive_window_adjust2(LIBSSH2_CHANNEL *channel,
unsigned int *window) unsigned int *window)
{ {
int rc; int rc;
if(!channel)
return LIBSSH2_ERROR_BAD_USE;
BLOCK_ADJUST(rc, channel->session, BLOCK_ADJUST(rc, channel->session,
_libssh2_channel_receive_window_adjust(channel, adj, force, _libssh2_channel_receive_window_adjust(channel, adj, force,
window)); window));
@@ -1571,6 +1628,10 @@ libssh2_channel_handle_extended_data2(LIBSSH2_CHANNEL *channel,
int mode) int mode)
{ {
int rc; int rc;
if(!channel)
return LIBSSH2_ERROR_BAD_USE;
BLOCK_ADJUST(rc, channel->session, _libssh2_channel_extended_data(channel, BLOCK_ADJUST(rc, channel->session, _libssh2_channel_extended_data(channel,
mode)); mode));
return rc; return rc;
@@ -1776,6 +1837,10 @@ libssh2_channel_read_ex(LIBSSH2_CHANNEL *channel, int stream_id, char *buf,
size_t buflen) size_t buflen)
{ {
int rc; int rc;
if(!channel)
return LIBSSH2_ERROR_BAD_USE;
BLOCK_ADJUST(rc, channel->session, BLOCK_ADJUST(rc, channel->session,
_libssh2_channel_read(channel, stream_id, buf, buflen)); _libssh2_channel_read(channel, stream_id, buf, buflen));
return rc; return rc;
@@ -2000,6 +2065,10 @@ libssh2_channel_write_ex(LIBSSH2_CHANNEL *channel, int stream_id,
const char *buf, size_t buflen) const char *buf, size_t buflen)
{ {
ssize_t rc; ssize_t rc;
if(!channel)
return LIBSSH2_ERROR_BAD_USE;
BLOCK_ADJUST(rc, channel->session, BLOCK_ADJUST(rc, channel->session,
_libssh2_channel_write(channel, stream_id, buf, buflen)); _libssh2_channel_write(channel, stream_id, buf, buflen));
return rc; return rc;
@@ -2042,6 +2111,10 @@ LIBSSH2_API int
libssh2_channel_send_eof(LIBSSH2_CHANNEL *channel) libssh2_channel_send_eof(LIBSSH2_CHANNEL *channel)
{ {
int rc; int rc;
if(!channel)
return LIBSSH2_ERROR_BAD_USE;
BLOCK_ADJUST(rc, channel->session, channel_send_eof(channel)); BLOCK_ADJUST(rc, channel->session, channel_send_eof(channel));
return rc; return rc;
} }
@@ -2054,8 +2127,14 @@ libssh2_channel_send_eof(LIBSSH2_CHANNEL *channel)
LIBSSH2_API int LIBSSH2_API int
libssh2_channel_eof(LIBSSH2_CHANNEL * channel) libssh2_channel_eof(LIBSSH2_CHANNEL * channel)
{ {
LIBSSH2_SESSION *session = channel->session; LIBSSH2_SESSION *session;
LIBSSH2_PACKET *packet = _libssh2_list_first(&session->packets); LIBSSH2_PACKET *packet;
if(!channel)
return LIBSSH2_ERROR_BAD_USE;
session = channel->session;
packet = _libssh2_list_first(&session->packets);
while (packet) { while (packet) {
if (((packet->data[0] == SSH_MSG_CHANNEL_DATA) if (((packet->data[0] == SSH_MSG_CHANNEL_DATA)
@@ -2120,6 +2199,10 @@ LIBSSH2_API int
libssh2_channel_wait_eof(LIBSSH2_CHANNEL *channel) libssh2_channel_wait_eof(LIBSSH2_CHANNEL *channel)
{ {
int rc; int rc;
if(!channel)
return LIBSSH2_ERROR_BAD_USE;
BLOCK_ADJUST(rc, channel->session, channel_wait_eof(channel)); BLOCK_ADJUST(rc, channel->session, channel_wait_eof(channel));
return rc; return rc;
} }
@@ -2202,6 +2285,10 @@ LIBSSH2_API int
libssh2_channel_close(LIBSSH2_CHANNEL *channel) libssh2_channel_close(LIBSSH2_CHANNEL *channel)
{ {
int rc; int rc;
if(!channel)
return LIBSSH2_ERROR_BAD_USE;
BLOCK_ADJUST(rc, channel->session, _libssh2_channel_close(channel) ); BLOCK_ADJUST(rc, channel->session, _libssh2_channel_close(channel) );
return rc; return rc;
} }
@@ -2259,6 +2346,10 @@ LIBSSH2_API int
libssh2_channel_wait_closed(LIBSSH2_CHANNEL *channel) libssh2_channel_wait_closed(LIBSSH2_CHANNEL *channel)
{ {
int rc; int rc;
if(!channel)
return LIBSSH2_ERROR_BAD_USE;
BLOCK_ADJUST(rc, channel->session, channel_wait_closed(channel)); BLOCK_ADJUST(rc, channel->session, channel_wait_closed(channel));
return rc; return rc;
} }
@@ -2296,10 +2387,9 @@ int _libssh2_channel_free(LIBSSH2_CHANNEL *channel)
if(rc == LIBSSH2_ERROR_EAGAIN) if(rc == LIBSSH2_ERROR_EAGAIN)
return rc; return rc;
else if (rc < 0) {
channel->free_state = libssh2_NB_state_idle; /* ignore all other errors as they otherwise risk blocking the channel
return rc; free from happening */
}
} }
channel->free_state = libssh2_NB_state_idle; channel->free_state = libssh2_NB_state_idle;
@@ -2358,12 +2448,16 @@ int _libssh2_channel_free(LIBSSH2_CHANNEL *channel)
* Make sure a channel is closed, then remove the channel from the session * Make sure a channel is closed, then remove the channel from the session
* and free its resource(s) * and free its resource(s)
* *
* Returns 0 on success, -1 on failure * Returns 0 on success, negative on failure
*/ */
LIBSSH2_API int LIBSSH2_API int
libssh2_channel_free(LIBSSH2_CHANNEL *channel) libssh2_channel_free(LIBSSH2_CHANNEL *channel)
{ {
int rc; int rc;
if(!channel)
return LIBSSH2_ERROR_BAD_USE;
BLOCK_ADJUST(rc, channel->session, _libssh2_channel_free(channel)); BLOCK_ADJUST(rc, channel->session, _libssh2_channel_free(channel));
return rc; return rc;
} }
@@ -2377,10 +2471,13 @@ libssh2_channel_free(LIBSSH2_CHANNEL *channel)
* window_size_initial as defined by the channel_open request * window_size_initial as defined by the channel_open request
*/ */
LIBSSH2_API unsigned long LIBSSH2_API unsigned long
libssh2_channel_window_read_ex(LIBSSH2_CHANNEL * channel, libssh2_channel_window_read_ex(LIBSSH2_CHANNEL *channel,
unsigned long *read_avail, unsigned long *read_avail,
unsigned long *window_size_initial) unsigned long *window_size_initial)
{ {
if(!channel)
return 0; /* no channel, no window! */
if (window_size_initial) { if (window_size_initial) {
*window_size_initial = channel->remote.window_size_initial; *window_size_initial = channel->remote.window_size_initial;
} }
@@ -2417,9 +2514,12 @@ libssh2_channel_window_read_ex(LIBSSH2_CHANNEL * channel,
* the channel_open request * the channel_open request
*/ */
LIBSSH2_API unsigned long LIBSSH2_API unsigned long
libssh2_channel_window_write_ex(LIBSSH2_CHANNEL * channel, libssh2_channel_window_write_ex(LIBSSH2_CHANNEL *channel,
unsigned long *window_size_initial) unsigned long *window_size_initial)
{ {
if(!channel)
return 0; /* no channel, no window! */
if (window_size_initial) { if (window_size_initial) {
/* For locally initiated channels this is very often 0, so it's not /* For locally initiated channels this is very often 0, so it's not
* *that* useful as information goes */ * *that* useful as information goes */

View File

@@ -170,6 +170,15 @@ comp_method_zlib_comp(LIBSSH2_SESSION * session,
int out_maxlen = compress ? (src_len + 4) : (2 * src_len); int out_maxlen = compress ? (src_len + 4) : (2 * src_len);
int limiter = 0; int limiter = 0;
/* If strm is null, then we have not yet been initialized. */
if (strm == NULL) {
*dest = (unsigned char *) src;
*dest_len = src_len;
*free_dest = 0;
return 0;
}
/* In practice they never come smaller than this */ /* In practice they never come smaller than this */
if (out_maxlen < 25) { if (out_maxlen < 25) {
out_maxlen = 25; out_maxlen = 25;

View File

@@ -600,6 +600,40 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
} }
_libssh2_debug(session, LIBSSH2_TRACE_KEX, _libssh2_debug(session, LIBSSH2_TRACE_KEX,
"Server to Client HMAC Key calculated"); "Server to Client HMAC Key calculated");
/* Initialize compression for each direction */
/* Cleanup any existing compression */
if (session->local.comp && session->local.comp->dtor) {
session->local.comp->dtor(session, 1,
&session->local.comp_abstract);
}
if (session->local.comp && session->local.comp->init) {
if (session->local.comp->init(session, 1,
&session->local.comp_abstract)) {
ret = LIBSSH2_ERROR_KEX_FAILURE;
goto clean_exit;
}
}
_libssh2_debug(session, LIBSSH2_TRACE_KEX,
"Client to Server compression initialized");
if (session->remote.comp && session->remote.comp->dtor) {
session->remote.comp->dtor(session, 0,
&session->remote.comp_abstract);
}
if (session->remote.comp && session->remote.comp->init) {
if (session->remote.comp->init(session, 0,
&session->remote.comp_abstract)) {
ret = LIBSSH2_ERROR_KEX_FAILURE;
goto clean_exit;
}
}
_libssh2_debug(session, LIBSSH2_TRACE_KEX,
"Server to Client compression initialized");
} }
clean_exit: clean_exit:
@@ -1099,6 +1133,9 @@ static int kexinit(LIBSSH2_SESSION * session)
} else { } else {
data = session->kexinit_data; data = session->kexinit_data;
data_len = session->kexinit_data_len; data_len = session->kexinit_data_len;
/* zap the variables to ensure there is NOT a double free later */
session->kexinit_data = NULL;
session->kexinit_data_len = 0;
} }
rc = _libssh2_transport_write(session, data, data_len); rc = _libssh2_transport_write(session, data, data_len);
@@ -1609,18 +1646,6 @@ static int kex_agree_methods(LIBSSH2_SESSION * session, unsigned char *data,
_libssh2_debug(session, LIBSSH2_TRACE_KEX, "Agreed on COMP_SC method: %s", _libssh2_debug(session, LIBSSH2_TRACE_KEX, "Agreed on COMP_SC method: %s",
session->remote.comp->name); session->remote.comp->name);
/* Initialize compression layer */
if (session->local.comp && session->local.comp->init &&
session->local.comp->init(session, 1, &session->local.comp_abstract)) {
return -1;
}
if (session->remote.comp && session->remote.comp->init &&
session->remote.comp->init(session, 0,
&session->remote.comp_abstract)) {
return -1;
}
return 0; return 0;
} }

View File

@@ -63,7 +63,7 @@
#define libssh2_sha1_init(ctx) gcry_md_open (ctx, GCRY_MD_SHA1, 0); #define libssh2_sha1_init(ctx) gcry_md_open (ctx, GCRY_MD_SHA1, 0);
#define libssh2_sha1_update(ctx, data, len) gcry_md_write (ctx, data, len) #define libssh2_sha1_update(ctx, data, len) gcry_md_write (ctx, data, len)
#define libssh2_sha1_final(ctx, out) \ #define libssh2_sha1_final(ctx, out) \
memcpy (out, gcry_md_read (ctx, 0), 20), gcry_md_close (ctx) memcpy (out, gcry_md_read (ctx, 0), SHA_DIGEST_LENGTH), gcry_md_close (ctx)
#define libssh2_sha1(message, len, out) \ #define libssh2_sha1(message, len, out) \
gcry_md_hash_buffer (GCRY_MD_SHA1, out, message, len) gcry_md_hash_buffer (GCRY_MD_SHA1, out, message, len)
@@ -71,7 +71,7 @@
#define libssh2_md5_init(ctx) gcry_md_open (ctx, GCRY_MD_MD5, 0); #define libssh2_md5_init(ctx) gcry_md_open (ctx, GCRY_MD_MD5, 0);
#define libssh2_md5_update(ctx, data, len) gcry_md_write (ctx, data, len) #define libssh2_md5_update(ctx, data, len) gcry_md_write (ctx, data, len)
#define libssh2_md5_final(ctx, out) \ #define libssh2_md5_final(ctx, out) \
memcpy (out, gcry_md_read (ctx, 0), 20), gcry_md_close (ctx) memcpy (out, gcry_md_read (ctx, 0), MD5_DIGEST_LENGTH), gcry_md_close (ctx)
#define libssh2_md5(message, len, out) \ #define libssh2_md5(message, len, out) \
gcry_md_hash_buffer (GCRY_MD_MD5, out, message, len) gcry_md_hash_buffer (GCRY_MD_MD5, out, message, len)

View File

@@ -172,7 +172,7 @@ typedef int libssh2_socket_t;
session->ssh_msg_ignore((session), (data), (datalen), &(session)->abstract) session->ssh_msg_ignore((session), (data), (datalen), &(session)->abstract)
#define LIBSSH2_DEBUG(session, always_display, message, message_len, \ #define LIBSSH2_DEBUG(session, always_display, message, message_len, \
language, language_len) \ language, language_len) \
session->ssh_msg_disconnect((session), (always_display), (message), \ session->ssh_msg_debug((session), (always_display), (message), \
(message_len), (language), (language_len), \ (message_len), (language), (language_len), \
&(session)->abstract) &(session)->abstract)
#define LIBSSH2_DISCONNECT(session, reason, message, message_len, language, language_len) \ #define LIBSSH2_DISCONNECT(session, reason, message, message_len, language, language_len) \
@@ -583,7 +583,7 @@ struct _LIBSSH2_SFTP
/* a list of _LIBSSH2_SFTP_HANDLE structs */ /* a list of _LIBSSH2_SFTP_HANDLE structs */
struct list_head sftp_handles; struct list_head sftp_handles;
unsigned long last_errno; uint32_t last_errno;
/* Holder for partial packet, use in libssh2_sftp_packet_read() */ /* Holder for partial packet, use in libssh2_sftp_packet_read() */
unsigned char *partial_packet; /* The data */ unsigned char *partial_packet; /* The data */
@@ -1149,4 +1149,11 @@ void _libssh2_init_if_needed (void);
#define ARRAY_SIZE(a) (sizeof ((a)) / sizeof ((a)[0])) #define ARRAY_SIZE(a) (sizeof ((a)) / sizeof ((a)[0]))
/* define to output the libssh2_int64_t type in a *printf() */
#if defined( __BORLANDC__ ) || defined( _MSC_VER ) || defined( __MINGW32__ )
#define LIBSSH2_INT64_T_FORMAT "I64"
#else
#define LIBSSH2_INT64_T_FORMAT "ll"
#endif
#endif /* LIBSSH2_H */ #endif /* LIBSSH2_H */

View File

@@ -47,6 +47,7 @@
#include <sys/time.h> #include <sys/time.h>
#endif #endif
#include <stdio.h>
#include <errno.h> #include <errno.h>
int _libssh2_error(LIBSSH2_SESSION* session, int errcode, const char* errmsg) int _libssh2_error(LIBSSH2_SESSION* session, int errcode, const char* errmsg)
@@ -114,7 +115,8 @@ _libssh2_recv(libssh2_socket_t socket, void *buffer, size_t length, int flags)
* to set errno * to set errno
*/ */
ssize_t ssize_t
_libssh2_send(libssh2_socket_t socket, const void *buffer, size_t length, int flags) _libssh2_send(libssh2_socket_t socket, const void *buffer, size_t length,
int flags)
{ {
ssize_t rc = send(socket, buffer, length, flags); ssize_t rc = send(socket, buffer, length, flags);
#ifdef WIN32 #ifdef WIN32
@@ -259,8 +261,7 @@ libssh2_base64_decode(LIBSSH2_SESSION *session, char **data,
/* Invalid -- We have a byte which belongs exclusively to a partial /* Invalid -- We have a byte which belongs exclusively to a partial
octet */ octet */
LIBSSH2_FREE(session, *data); LIBSSH2_FREE(session, *data);
return _libssh2_error(session, LIBSSH2_ERROR_INVAL, return _libssh2_error(session, LIBSSH2_ERROR_INVAL, "Invalid base64");
"Invalid data (byte belonging to partial octet)");
} }
*datalen = len; *datalen = len;
@@ -356,7 +357,8 @@ libssh2_trace(LIBSSH2_SESSION * session, int bitmask)
} }
LIBSSH2_API int LIBSSH2_API int
libssh2_trace_sethandler(LIBSSH2_SESSION *session, void* handler_context, libssh2_trace_handler_func callback) libssh2_trace_sethandler(LIBSSH2_SESSION *session, void* handler_context,
libssh2_trace_handler_func callback)
{ {
session->tracehandler = callback; session->tracehandler = callback;
session->tracehandler_context = handler_context; session->tracehandler_context = handler_context;
@@ -367,7 +369,7 @@ void
_libssh2_debug(LIBSSH2_SESSION * session, int context, const char *format, ...) _libssh2_debug(LIBSSH2_SESSION * session, int context, const char *format, ...)
{ {
char buffer[1536]; char buffer[1536];
int len; int len, msglen, buflen = sizeof(buffer);
va_list vargs; va_list vargs;
struct timeval now; struct timeval now;
static int firstsec; static int firstsec;
@@ -392,7 +394,8 @@ _libssh2_debug(LIBSSH2_SESSION * session, int context, const char *format, ...)
} }
/* Find the first matching context string for this message */ /* Find the first matching context string for this message */
for (contextindex = 0; contextindex < ARRAY_SIZE(contexts); contextindex++) { for (contextindex = 0; contextindex < ARRAY_SIZE(contexts);
contextindex++) {
if ((context & (1 << contextindex)) != 0) { if ((context & (1 << contextindex)) != 0) {
contexttext = contexts[contextindex]; contexttext = contexts[contextindex];
break; break;
@@ -405,19 +408,25 @@ _libssh2_debug(LIBSSH2_SESSION * session, int context, const char *format, ...)
} }
now.tv_sec -= firstsec; now.tv_sec -= firstsec;
len = snprintf(buffer, sizeof(buffer), "[libssh2] %d.%06d %s: ", len = snprintf(buffer, buflen, "[libssh2] %d.%06d %s: ",
(int)now.tv_sec, (int)now.tv_usec, contexttext); (int)now.tv_sec, (int)now.tv_usec, contexttext);
if (len >= buflen)
msglen = buflen - 1;
else {
buflen -= len;
msglen = len;
va_start(vargs, format); va_start(vargs, format);
len += vsnprintf(buffer + len, 1535 - len, format, vargs); len = vsnprintf(buffer + msglen, buflen, format, vargs);
buffer[len] = '\n';
va_end(vargs); va_end(vargs);
msglen += len < buflen ? len : buflen - 1;
if (session->tracehandler) {
(session->tracehandler)(session, session->tracehandler_context, buffer, len + 1);
} else {
write(2, buffer, len + 1);
} }
if (session->tracehandler)
(session->tracehandler)(session, session->tracehandler_context, buffer,
msglen);
else
fprintf(stderr, "%s\n", buffer);
} }
#else #else
@@ -430,7 +439,8 @@ libssh2_trace(LIBSSH2_SESSION * session, int bitmask)
} }
LIBSSH2_API int LIBSSH2_API int
libssh2_trace_sethandler(LIBSSH2_SESSION *session, void* handler_context, libssh2_trace_handler_func callback) libssh2_trace_sethandler(LIBSSH2_SESSION *session, void* handler_context,
libssh2_trace_handler_func callback)
{ {
(void) session; (void) session;
(void) handler_context; (void) handler_context;

View File

@@ -204,10 +204,12 @@ _libssh2_cipher_crypt(_libssh2_cipher_ctx * ctx,
#if LIBSSH2_AES_CTR && !defined(HAVE_EVP_AES_128_CTR) #if LIBSSH2_AES_CTR && !defined(HAVE_EVP_AES_128_CTR)
#include <openssl/aes.h> #include <openssl/aes.h>
#include <openssl/evp.h>
typedef struct typedef struct
{ {
AES_KEY key; AES_KEY key;
EVP_CIPHER_CTX *aes_ctx;
unsigned char ctr[AES_BLOCK_SIZE]; unsigned char ctr[AES_BLOCK_SIZE];
} aes_ctr_ctx; } aes_ctr_ctx;
@@ -216,12 +218,35 @@ aes_ctr_init(EVP_CIPHER_CTX *ctx, const unsigned char *key,
const unsigned char *iv, int enc) /* init key */ const unsigned char *iv, int enc) /* init key */
{ {
aes_ctr_ctx *c = malloc(sizeof(*c)); aes_ctr_ctx *c = malloc(sizeof(*c));
const EVP_CIPHER *aes_cipher;
(void) enc; (void) enc;
if (c == NULL) if (c == NULL)
return 0; return 0;
AES_set_encrypt_key(key, 8 * ctx->key_len, &c->key); switch (ctx->key_len) {
case 16:
aes_cipher = EVP_aes_128_ecb();
break;
case 24:
aes_cipher = EVP_aes_192_ecb();
break;
case 32:
aes_cipher = EVP_aes_256_ecb();
break;
default:
return 0;
}
c->aes_ctx = malloc(sizeof(EVP_CIPHER_CTX));
if (c->aes_ctx == NULL)
return 0;
if (EVP_EncryptInit(c->aes_ctx, aes_cipher, key, NULL) != 1) {
return 0;
}
EVP_CIPHER_CTX_set_padding(c->aes_ctx, 0);
memcpy(c->ctr, iv, AES_BLOCK_SIZE); memcpy(c->ctr, iv, AES_BLOCK_SIZE);
EVP_CIPHER_CTX_set_app_data(ctx, c); EVP_CIPHER_CTX_set_app_data(ctx, c);
@@ -236,11 +261,16 @@ aes_ctr_do_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
{ {
aes_ctr_ctx *c = EVP_CIPHER_CTX_get_app_data(ctx); aes_ctr_ctx *c = EVP_CIPHER_CTX_get_app_data(ctx);
unsigned char b1[AES_BLOCK_SIZE]; unsigned char b1[AES_BLOCK_SIZE];
size_t i; size_t i = 0;
int outlen = 0;
if (inl != 16) /* libssh2 only ever encrypt one block */ if (inl != 16) /* libssh2 only ever encrypt one block */
return 0; return 0;
if (c == NULL) {
return 0;
}
/* /*
To encrypt a packet P=P1||P2||...||Pn (where P1, P2, ..., Pn are each To encrypt a packet P=P1||P2||...||Pn (where P1, P2, ..., Pn are each
blocks of length L), the encryptor first encrypts <X> with <cipher> blocks of length L), the encryptor first encrypts <X> with <cipher>
@@ -248,7 +278,9 @@ aes_ctr_do_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
the ciphertext block C1. The counter X is then incremented the ciphertext block C1. The counter X is then incremented
*/ */
AES_encrypt(c->ctr, b1, &c->key); if (EVP_EncryptUpdate(c->aes_ctx, b1, &outlen, c->ctr, AES_BLOCK_SIZE) != 1) {
return 0;
}
for (i = 0; i < 16; i++) for (i = 0; i < 16; i++)
*out++ = *in++ ^ b1[i]; *out++ = *in++ ^ b1[i];
@@ -266,7 +298,18 @@ aes_ctr_do_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
static int static int
aes_ctr_cleanup(EVP_CIPHER_CTX *ctx) /* cleanup ctx */ aes_ctr_cleanup(EVP_CIPHER_CTX *ctx) /* cleanup ctx */
{ {
free(EVP_CIPHER_CTX_get_app_data(ctx)); aes_ctr_ctx *c = EVP_CIPHER_CTX_get_app_data(ctx);
if (c == NULL) {
return 1;
}
if (c->aes_ctx != NULL) {
free(c->aes_ctx);
}
free(c);
return 1; return 1;
} }

View File

@@ -43,7 +43,7 @@
#define LIBSSH2_PUBLICKEY_VERSION 2 #define LIBSSH2_PUBLICKEY_VERSION 2
/* Numericised response codes -- Not IETF standard, just a local representation */ /* Numericised response codes -- Not IETF, just local representation */
#define LIBSSH2_PUBLICKEY_RESPONSE_STATUS 0 #define LIBSSH2_PUBLICKEY_RESPONSE_STATUS 0
#define LIBSSH2_PUBLICKEY_RESPONSE_VERSION 1 #define LIBSSH2_PUBLICKEY_RESPONSE_VERSION 1
#define LIBSSH2_PUBLICKEY_RESPONSE_PUBLICKEY 2 #define LIBSSH2_PUBLICKEY_RESPONSE_PUBLICKEY 2
@@ -259,12 +259,13 @@ publickey_response_success(LIBSSH2_PUBLICKEY * pkey)
default: default:
LIBSSH2_FREE(session, data); LIBSSH2_FREE(session, data);
if (response < 0) { if (response < 0) {
return _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, return _libssh2_error(session,
"Invalid publickey subsystem response code"); LIBSSH2_ERROR_PUBLICKEY_PROTOCOL,
"Invalid publickey subsystem response");
} }
/* Unknown/Unexpected */ /* Unknown/Unexpected */
_libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL,
"Unexpected publickey subsystem response, ignoring"); "Unexpected publickey subsystem response");
data = NULL; data = NULL;
} }
} }
@@ -321,7 +322,8 @@ static LIBSSH2_PUBLICKEY *publickey_init(LIBSSH2_SESSION *session)
rc = _libssh2_channel_process_startup(session->pkeyInit_channel, rc = _libssh2_channel_process_startup(session->pkeyInit_channel,
"subsystem", "subsystem",
sizeof("subsystem") - 1, sizeof("subsystem") - 1,
"publickey", strlen("publickey")); "publickey",
sizeof("publickey") - 1);
if (rc == LIBSSH2_ERROR_EAGAIN) { if (rc == LIBSSH2_ERROR_EAGAIN) {
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block starting publickey subsystem"); "Would block starting publickey subsystem");
@@ -368,7 +370,7 @@ static LIBSSH2_PUBLICKEY *publickey_init(LIBSSH2_SESSION *session)
session->pkeyInit_buffer_sent = 0; session->pkeyInit_buffer_sent = 0;
_libssh2_debug(session, LIBSSH2_TRACE_PUBLICKEY, _libssh2_debug(session, LIBSSH2_TRACE_PUBLICKEY,
"Sending publickey version packet advertising version %d support", "Sending publickey advertising version %d support",
(int) LIBSSH2_PUBLICKEY_VERSION); (int) LIBSSH2_PUBLICKEY_VERSION);
session->pkeyInit_state = libssh2_NB_state_sent2; session->pkeyInit_state = libssh2_NB_state_sent2;
@@ -459,7 +461,7 @@ static LIBSSH2_PUBLICKEY *publickey_init(LIBSSH2_SESSION *session)
if (session->pkeyInit_pkey->version > if (session->pkeyInit_pkey->version >
LIBSSH2_PUBLICKEY_VERSION) { LIBSSH2_PUBLICKEY_VERSION) {
_libssh2_debug(session, LIBSSH2_TRACE_PUBLICKEY, _libssh2_debug(session, LIBSSH2_TRACE_PUBLICKEY,
"Truncating remote publickey version from %lu", "Truncate remote publickey version from %lu",
session->pkeyInit_pkey->version); session->pkeyInit_pkey->version);
session->pkeyInit_pkey->version = session->pkeyInit_pkey->version =
LIBSSH2_PUBLICKEY_VERSION; LIBSSH2_PUBLICKEY_VERSION;
@@ -529,20 +531,27 @@ libssh2_publickey_init(LIBSSH2_SESSION *session)
* Add a new public key entry * Add a new public key entry
*/ */
LIBSSH2_API int LIBSSH2_API int
libssh2_publickey_add_ex(LIBSSH2_PUBLICKEY * pkey, const unsigned char *name, libssh2_publickey_add_ex(LIBSSH2_PUBLICKEY *pkey, const unsigned char *name,
unsigned long name_len, const unsigned char *blob, unsigned long name_len, const unsigned char *blob,
unsigned long blob_len, char overwrite, unsigned long blob_len, char overwrite,
unsigned long num_attrs, unsigned long num_attrs,
const libssh2_publickey_attribute attrs[]) const libssh2_publickey_attribute attrs[])
{ {
LIBSSH2_CHANNEL *channel = pkey->channel; LIBSSH2_CHANNEL *channel;
LIBSSH2_SESSION *session = channel->session; LIBSSH2_SESSION *session;
/* 19 = packet_len(4) + add_len(4) + "add"(3) + name_len(4) + {name} blob_len(4) + {blob} */ /* 19 = packet_len(4) + add_len(4) + "add"(3) + name_len(4) + {name}
blob_len(4) + {blob} */
unsigned long i, packet_len = 19 + name_len + blob_len; unsigned long i, packet_len = 19 + name_len + blob_len;
unsigned char *comment = NULL; unsigned char *comment = NULL;
unsigned long comment_len = 0; unsigned long comment_len = 0;
int rc; int rc;
if(!pkey)
return LIBSSH2_ERROR_BAD_USE;
channel = pkey->channel;
session = channel->session;
if (pkey->add_state == libssh2_NB_state_idle) { if (pkey->add_state == libssh2_NB_state_idle) {
pkey->add_packet = NULL; pkey->add_packet = NULL;
@@ -627,7 +636,8 @@ libssh2_publickey_add_ex(LIBSSH2_PUBLICKEY * pkey, const unsigned char *name,
} }
_libssh2_debug(session, LIBSSH2_TRACE_PUBLICKEY, _libssh2_debug(session, LIBSSH2_TRACE_PUBLICKEY,
"Sending publickey \"add\" packet: type=%s blob_len=%ld num_attrs=%ld", "Sending publickey \"add\" packet: "
"type=%s blob_len=%ld num_attrs=%ld",
name, blob_len, num_attrs); name, blob_len, num_attrs);
pkey->add_state = libssh2_NB_state_created; pkey->add_state = libssh2_NB_state_created;
@@ -661,19 +671,27 @@ libssh2_publickey_add_ex(LIBSSH2_PUBLICKEY * pkey, const unsigned char *name,
} }
/* libssh2_publickey_remove_ex /* libssh2_publickey_remove_ex
* Remove an existing publickey so that authentication can no longer be performed using it * Remove an existing publickey so that authentication can no longer be
* performed using it
*/ */
LIBSSH2_API int LIBSSH2_API int
libssh2_publickey_remove_ex(LIBSSH2_PUBLICKEY * pkey, libssh2_publickey_remove_ex(LIBSSH2_PUBLICKEY * pkey,
const unsigned char *name, unsigned long name_len, const unsigned char *name, unsigned long name_len,
const unsigned char *blob, unsigned long blob_len) const unsigned char *blob, unsigned long blob_len)
{ {
LIBSSH2_CHANNEL *channel = pkey->channel; LIBSSH2_CHANNEL *channel;
LIBSSH2_SESSION *session = channel->session; LIBSSH2_SESSION *session;
/* 22 = packet_len(4) + remove_len(4) + "remove"(6) + name_len(4) + {name} + blob_len(4) + {blob} */ /* 22 = packet_len(4) + remove_len(4) + "remove"(6) + name_len(4) + {name}
+ blob_len(4) + {blob} */
unsigned long packet_len = 22 + name_len + blob_len; unsigned long packet_len = 22 + name_len + blob_len;
int rc; int rc;
if(!pkey)
return LIBSSH2_ERROR_BAD_USE;
channel = pkey->channel;
session = channel->session;
if (pkey->remove_state == libssh2_NB_state_idle) { if (pkey->remove_state == libssh2_NB_state_idle) {
pkey->remove_packet = NULL; pkey->remove_packet = NULL;
@@ -701,7 +719,8 @@ libssh2_publickey_remove_ex(LIBSSH2_PUBLICKEY * pkey,
pkey->remove_s += blob_len; pkey->remove_s += blob_len;
_libssh2_debug(session, LIBSSH2_TRACE_PUBLICKEY, _libssh2_debug(session, LIBSSH2_TRACE_PUBLICKEY,
"Sending publickey \"remove\" packet: type=%s blob_len=%ld", "Sending publickey \"remove\" packet: "
"type=%s blob_len=%ld",
name, blob_len); name, blob_len);
pkey->remove_state = libssh2_NB_state_created; pkey->remove_state = libssh2_NB_state_created;
@@ -742,14 +761,20 @@ LIBSSH2_API int
libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys, libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys,
libssh2_publickey_list ** pkey_list) libssh2_publickey_list ** pkey_list)
{ {
LIBSSH2_CHANNEL *channel = pkey->channel; LIBSSH2_CHANNEL *channel;
LIBSSH2_SESSION *session = channel->session; LIBSSH2_SESSION *session;
libssh2_publickey_list *list = NULL; libssh2_publickey_list *list = NULL;
unsigned long buffer_len = 12, keys = 0, max_keys = 0, i; unsigned long buffer_len = 12, keys = 0, max_keys = 0, i;
/* 12 = packet_len(4) + list_len(4) + "list"(4) */ /* 12 = packet_len(4) + list_len(4) + "list"(4) */
int response; int response;
int rc; int rc;
if(!pkey)
return LIBSSH2_ERROR_BAD_USE;
channel = pkey->channel;
session = channel->session;
if (pkey->listFetch_state == libssh2_NB_state_idle) { if (pkey->listFetch_state == libssh2_NB_state_idle) {
pkey->listFetch_data = NULL; pkey->listFetch_data = NULL;
@@ -927,13 +952,16 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys,
pkey->listFetch_s += 4; pkey->listFetch_s += 4;
list[keys].attrs[i].value = (char *) pkey->listFetch_s; list[keys].attrs[i].value = (char *) pkey->listFetch_s;
pkey->listFetch_s += list[keys].attrs[i].value_len; pkey->listFetch_s += list[keys].attrs[i].value_len;
list[keys].attrs[i].mandatory = 0; /* actually an ignored value */
/* actually an ignored value */
list[keys].attrs[i].mandatory = 0;
} }
} else { } else {
list[keys].attrs = NULL; list[keys].attrs = NULL;
} }
} }
list[keys].packet = pkey->listFetch_data; /* To be FREEd in libssh2_publickey_list_free() */ /* To be FREEd in libssh2_publickey_list_free() */
list[keys].packet = pkey->listFetch_data;
keys++; keys++;
list[keys].packet = NULL; /* Terminate the list */ list[keys].packet = NULL; /* Terminate the list */
@@ -942,7 +970,7 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys,
default: default:
/* Unknown/Unexpected */ /* Unknown/Unexpected */
_libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL,
"Unexpected publickey subsystem response, ignoring"); "Unexpected publickey subsystem response");
LIBSSH2_FREE(session, pkey->listFetch_data); LIBSSH2_FREE(session, pkey->listFetch_data);
pkey->listFetch_data = NULL; pkey->listFetch_data = NULL;
} }
@@ -968,9 +996,14 @@ LIBSSH2_API void
libssh2_publickey_list_free(LIBSSH2_PUBLICKEY * pkey, libssh2_publickey_list_free(LIBSSH2_PUBLICKEY * pkey,
libssh2_publickey_list * pkey_list) libssh2_publickey_list * pkey_list)
{ {
LIBSSH2_SESSION *session = pkey->channel->session; LIBSSH2_SESSION *session;
libssh2_publickey_list *p = pkey_list; libssh2_publickey_list *p = pkey_list;
if(!pkey || !p)
return;
session = pkey->channel->session;
while (p->packet) { while (p->packet) {
if (p->attrs) { if (p->attrs) {
LIBSSH2_FREE(session, p->attrs); LIBSSH2_FREE(session, p->attrs);
@@ -986,11 +1019,16 @@ libssh2_publickey_list_free(LIBSSH2_PUBLICKEY * pkey,
* Shutdown the publickey subsystem * Shutdown the publickey subsystem
*/ */
LIBSSH2_API int LIBSSH2_API int
libssh2_publickey_shutdown(LIBSSH2_PUBLICKEY * pkey) libssh2_publickey_shutdown(LIBSSH2_PUBLICKEY *pkey)
{ {
LIBSSH2_SESSION *session = pkey->channel->session; LIBSSH2_SESSION *session;
int rc; int rc;
if(!pkey)
return LIBSSH2_ERROR_BAD_USE;
session = pkey->channel->session;
/* /*
* Make sure all memory used in the state variables are free * Make sure all memory used in the state variables are free
*/ */

View File

@@ -939,7 +939,8 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
session->scpSend_response_len = session->scpSend_response_len =
snprintf((char *) session->scpSend_response, snprintf((char *) session->scpSend_response,
LIBSSH2_SCP_RESPONSE_BUFLEN, "C0%o %llu %s\n", mode, LIBSSH2_SCP_RESPONSE_BUFLEN, "C0%o %"
LIBSSH2_INT64_T_FORMAT "u %s\n", mode,
size, base); size, base);
_libssh2_debug(session, LIBSSH2_TRACE_SCP, "Sent %s", _libssh2_debug(session, LIBSSH2_TRACE_SCP, "Sent %s",
session->scpSend_response); session->scpSend_response);

View File

@@ -543,6 +543,12 @@ int _libssh2_wait_socket(LIBSSH2_SESSION *session)
int seconds_to_next; int seconds_to_next;
int dir; int dir;
/* since libssh2 often sets EAGAIN internally before this function is
called, we can decrease some amount of confusion in user programs by
resetting the error code in this function to reduce the risk of EAGAIN
being stored as error when a blocking function has returned */
session->err_code = LIBSSH2_ERROR_NONE;
rc = libssh2_keepalive_send (session, &seconds_to_next); rc = libssh2_keepalive_send (session, &seconds_to_next);
if (rc < 0) if (rc < 0)
return rc; return rc;
@@ -564,7 +570,8 @@ int _libssh2_wait_socket(LIBSSH2_SESSION *session)
if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND) if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND)
sockets[0].events |= POLLOUT; sockets[0].events |= POLLOUT;
rc = poll(sockets, 1, seconds_to_next ? seconds_to_next / 1000 : -1); rc = poll(sockets, 1, seconds_to_next ?
seconds_to_next * 1000 : -1);
#else #else
fd_set rfd; fd_set rfd;
fd_set wfd; fd_set wfd;
@@ -836,6 +843,9 @@ session_free(LIBSSH2_SESSION *session)
LIBSSH2_FREE(session, session->hostkey_prefs); LIBSSH2_FREE(session, session->hostkey_prefs);
} }
if (session->local.kexinit) {
LIBSSH2_FREE(session, session->local.kexinit);
}
if (session->local.crypt_prefs) { if (session->local.crypt_prefs) {
LIBSSH2_FREE(session, session->local.crypt_prefs); LIBSSH2_FREE(session, session->local.crypt_prefs);
} }
@@ -849,6 +859,9 @@ session_free(LIBSSH2_SESSION *session)
LIBSSH2_FREE(session, session->local.lang_prefs); LIBSSH2_FREE(session, session->local.lang_prefs);
} }
if (session->remote.kexinit) {
LIBSSH2_FREE(session, session->remote.kexinit);
}
if (session->remote.crypt_prefs) { if (session->remote.crypt_prefs) {
LIBSSH2_FREE(session, session->remote.crypt_prefs); LIBSSH2_FREE(session, session->remote.crypt_prefs);
} }
@@ -865,6 +878,9 @@ session_free(LIBSSH2_SESSION *session)
/* /*
* Make sure all memory used in the state variables are free * Make sure all memory used in the state variables are free
*/ */
if (session->kexinit_data) {
LIBSSH2_FREE(session, session->kexinit_data);
}
if (session->startup_data) { if (session->startup_data) {
LIBSSH2_FREE(session, session->startup_data); LIBSSH2_FREE(session, session->startup_data);
} }
@@ -1252,10 +1268,16 @@ libssh2_session_get_blocking(LIBSSH2_SESSION * session)
* non-0 if data is available * non-0 if data is available
*/ */
LIBSSH2_API int LIBSSH2_API int
libssh2_poll_channel_read(LIBSSH2_CHANNEL * channel, int extended) libssh2_poll_channel_read(LIBSSH2_CHANNEL *channel, int extended)
{ {
LIBSSH2_SESSION *session = channel->session; LIBSSH2_SESSION *session;
LIBSSH2_PACKET *packet = _libssh2_list_first(&session->packets); LIBSSH2_PACKET *packet;
if(!channel)
return LIBSSH2_ERROR_BAD_USE;
session = channel->session;
packet = _libssh2_list_first(&session->packets);
while (packet) { while (packet) {
if ( channel->local.id == _libssh2_ntohu32(packet->data + 1)) { if ( channel->local.id == _libssh2_ntohu32(packet->data + 1)) {

View File

@@ -698,7 +698,8 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session)
return sftp_handle; return sftp_handle;
sftp_init_error: sftp_init_error:
while (_libssh2_channel_free(session->sftpInit_channel) == LIBSSH2_ERROR_EAGAIN); while (_libssh2_channel_free(session->sftpInit_channel) ==
LIBSSH2_ERROR_EAGAIN);
session->sftpInit_channel = NULL; session->sftpInit_channel = NULL;
if (session->sftpInit_sftp) { if (session->sftpInit_sftp) {
LIBSSH2_FREE(session, session->sftpInit_sftp); LIBSSH2_FREE(session, session->sftpInit_sftp);
@@ -717,6 +718,9 @@ LIBSSH2_API LIBSSH2_SFTP *libssh2_sftp_init(LIBSSH2_SESSION *session)
{ {
LIBSSH2_SFTP *ptr; LIBSSH2_SFTP *ptr;
if(!session)
return NULL;
if(!(session->state & LIBSSH2_STATE_AUTHENTICATED)) { if(!(session->state & LIBSSH2_STATE_AUTHENTICATED)) {
_libssh2_error(session, LIBSSH2_ERROR_INVAL, _libssh2_error(session, LIBSSH2_ERROR_INVAL,
"session not authenticated yet"); "session not authenticated yet");
@@ -808,6 +812,8 @@ LIBSSH2_API int
libssh2_sftp_shutdown(LIBSSH2_SFTP *sftp) libssh2_sftp_shutdown(LIBSSH2_SFTP *sftp)
{ {
int rc; int rc;
if(!sftp)
return LIBSSH2_ERROR_BAD_USE;
BLOCK_ADJUST(rc, sftp->channel->session, sftp_shutdown(sftp)); BLOCK_ADJUST(rc, sftp->channel->session, sftp_shutdown(sftp));
return rc; return rc;
} }
@@ -1016,6 +1022,10 @@ libssh2_sftp_open_ex(LIBSSH2_SFTP *sftp, const char *filename,
int open_type) int open_type)
{ {
LIBSSH2_SFTP_HANDLE *hnd; LIBSSH2_SFTP_HANDLE *hnd;
if(!sftp)
return NULL;
BLOCK_ADJUST_ERRNO(hnd, sftp->channel->session, BLOCK_ADJUST_ERRNO(hnd, sftp->channel->session,
sftp_open(sftp, filename, filename_len, flags, mode, sftp_open(sftp, filename, filename_len, flags, mode,
open_type)); open_type));
@@ -1192,6 +1202,8 @@ libssh2_sftp_read(LIBSSH2_SFTP_HANDLE *hnd, char *buffer,
size_t buffer_maxlen) size_t buffer_maxlen)
{ {
ssize_t rc; ssize_t rc;
if(!hnd)
return LIBSSH2_ERROR_BAD_USE;
BLOCK_ADJUST(rc, hnd->sftp->channel->session, BLOCK_ADJUST(rc, hnd->sftp->channel->session,
sftp_read(hnd, buffer, buffer_maxlen)); sftp_read(hnd, buffer, buffer_maxlen));
return rc; return rc;
@@ -1363,6 +1375,8 @@ libssh2_sftp_readdir_ex(LIBSSH2_SFTP_HANDLE *hnd, char *buffer,
LIBSSH2_SFTP_ATTRIBUTES *attrs) LIBSSH2_SFTP_ATTRIBUTES *attrs)
{ {
int rc; int rc;
if(!hnd)
return LIBSSH2_ERROR_BAD_USE;
BLOCK_ADJUST(rc, hnd->sftp->channel->session, BLOCK_ADJUST(rc, hnd->sftp->channel->session,
sftp_readdir(hnd, buffer, buffer_maxlen, longentry, sftp_readdir(hnd, buffer, buffer_maxlen, longentry,
longentry_maxlen, attrs)); longentry_maxlen, attrs));
@@ -1388,12 +1402,9 @@ static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer,
unsigned char *s, *data; unsigned char *s, *data;
int rc; int rc;
/* There's no point in us accepting a VERY large packet here since we /* we limit this to just send a single SSH packet at a time */
cannot send it anyway. We just accept 4 times the big size to fill up if(count > 32500)
the queue somewhat. */ count = 32500;
if(count > (MAX_SSH_PACKET_LEN*4))
count = MAX_SSH_PACKET_LEN*4;
packet_len = handle->handle_len + count + 25; packet_len = handle->handle_len + count + 25;
@@ -1470,6 +1481,8 @@ libssh2_sftp_write(LIBSSH2_SFTP_HANDLE *hnd, const char *buffer,
size_t count) size_t count)
{ {
ssize_t rc; ssize_t rc;
if(!hnd)
return LIBSSH2_ERROR_BAD_USE;
BLOCK_ADJUST(rc, hnd->sftp->channel->session, BLOCK_ADJUST(rc, hnd->sftp->channel->session,
sftp_write(hnd, buffer, count)); sftp_write(hnd, buffer, count));
return rc; return rc;
@@ -1575,10 +1588,12 @@ static int sftp_fstat(LIBSSH2_SFTP_HANDLE *handle,
* Get or Set stat on a file * Get or Set stat on a file
*/ */
LIBSSH2_API int LIBSSH2_API int
libssh2_sftp_fstat_ex(LIBSSH2_SFTP_HANDLE * hnd, libssh2_sftp_fstat_ex(LIBSSH2_SFTP_HANDLE *hnd,
LIBSSH2_SFTP_ATTRIBUTES *attrs, int setstat) LIBSSH2_SFTP_ATTRIBUTES *attrs, int setstat)
{ {
int rc; int rc;
if(!hnd || !attrs)
return LIBSSH2_ERROR_BAD_USE;
BLOCK_ADJUST(rc, hnd->sftp->channel->session, BLOCK_ADJUST(rc, hnd->sftp->channel->session,
sftp_fstat(hnd, attrs, setstat)); sftp_fstat(hnd, attrs, setstat));
return rc; return rc;
@@ -1588,8 +1603,9 @@ libssh2_sftp_fstat_ex(LIBSSH2_SFTP_HANDLE * hnd,
* Set the read/write pointer to an arbitrary position within the file * Set the read/write pointer to an arbitrary position within the file
*/ */
LIBSSH2_API void LIBSSH2_API void
libssh2_sftp_seek(LIBSSH2_SFTP_HANDLE * handle, size_t offset) libssh2_sftp_seek(LIBSSH2_SFTP_HANDLE *handle, size_t offset)
{ {
if(handle)
handle->u.file.offset = offset; handle->u.file.offset = offset;
} }
@@ -1597,8 +1613,9 @@ libssh2_sftp_seek(LIBSSH2_SFTP_HANDLE * handle, size_t offset)
* Set the read/write pointer to an arbitrary position within the file * Set the read/write pointer to an arbitrary position within the file
*/ */
LIBSSH2_API void LIBSSH2_API void
libssh2_sftp_seek64(LIBSSH2_SFTP_HANDLE * handle, libssh2_uint64_t offset) libssh2_sftp_seek64(LIBSSH2_SFTP_HANDLE *handle, libssh2_uint64_t offset)
{ {
if(handle)
handle->u.file.offset = offset; handle->u.file.offset = offset;
} }
@@ -1606,8 +1623,11 @@ libssh2_sftp_seek64(LIBSSH2_SFTP_HANDLE * handle, libssh2_uint64_t offset)
* Return the current read/write pointer's offset * Return the current read/write pointer's offset
*/ */
LIBSSH2_API size_t LIBSSH2_API size_t
libssh2_sftp_tell(LIBSSH2_SFTP_HANDLE * handle) libssh2_sftp_tell(LIBSSH2_SFTP_HANDLE *handle)
{ {
if(!handle)
return 0; /* no handle, no size */
/* NOTE: this may very well truncate the size if it is larger than what /* NOTE: this may very well truncate the size if it is larger than what
size_t can hold, so libssh2_sftp_tell64() is really the function you size_t can hold, so libssh2_sftp_tell64() is really the function you
should use */ should use */
@@ -1618,8 +1638,11 @@ libssh2_sftp_tell(LIBSSH2_SFTP_HANDLE * handle)
* Return the current read/write pointer's offset * Return the current read/write pointer's offset
*/ */
LIBSSH2_API libssh2_uint64_t LIBSSH2_API libssh2_uint64_t
libssh2_sftp_tell64(LIBSSH2_SFTP_HANDLE * handle) libssh2_sftp_tell64(LIBSSH2_SFTP_HANDLE *handle)
{ {
if(!handle)
return 0; /* no handle, no size */
return handle->u.file.offset; return handle->u.file.offset;
} }
@@ -1731,6 +1754,8 @@ LIBSSH2_API int
libssh2_sftp_close_handle(LIBSSH2_SFTP_HANDLE *hnd) libssh2_sftp_close_handle(LIBSSH2_SFTP_HANDLE *hnd)
{ {
int rc; int rc;
if(!hnd)
return LIBSSH2_ERROR_BAD_USE;
BLOCK_ADJUST(rc, hnd->sftp->channel->session, sftp_close_handle(hnd)); BLOCK_ADJUST(rc, hnd->sftp->channel->session, sftp_close_handle(hnd));
return rc; return rc;
} }
@@ -1819,6 +1844,8 @@ libssh2_sftp_unlink_ex(LIBSSH2_SFTP *sftp, const char *filename,
unsigned int filename_len) unsigned int filename_len)
{ {
int rc; int rc;
if(!sftp)
return LIBSSH2_ERROR_BAD_USE;
BLOCK_ADJUST(rc, sftp->channel->session, BLOCK_ADJUST(rc, sftp->channel->session,
sftp_unlink(sftp, filename, filename_len)); sftp_unlink(sftp, filename, filename_len));
return rc; return rc;
@@ -1949,6 +1976,8 @@ libssh2_sftp_rename_ex(LIBSSH2_SFTP *sftp, const char *source_filename,
unsigned int dest_filename_len, long flags) unsigned int dest_filename_len, long flags)
{ {
int rc; int rc;
if(!sftp)
return LIBSSH2_ERROR_BAD_USE;
BLOCK_ADJUST(rc, sftp->channel->session, BLOCK_ADJUST(rc, sftp->channel->session,
sftp_rename(sftp, source_filename, source_filename_len, sftp_rename(sftp, source_filename, source_filename_len,
dest_filename, dest_filename_len, flags)); dest_filename, dest_filename_len, flags));
@@ -2061,6 +2090,8 @@ LIBSSH2_API int
libssh2_sftp_fstatvfs(LIBSSH2_SFTP_HANDLE *handle, LIBSSH2_SFTP_STATVFS *st) libssh2_sftp_fstatvfs(LIBSSH2_SFTP_HANDLE *handle, LIBSSH2_SFTP_STATVFS *st)
{ {
int rc; int rc;
if(!handle || !st)
return LIBSSH2_ERROR_BAD_USE;
BLOCK_ADJUST(rc, handle->sftp->channel->session, sftp_fstatvfs(handle, st)); BLOCK_ADJUST(rc, handle->sftp->channel->session, sftp_fstatvfs(handle, st));
return rc; return rc;
} }
@@ -2172,6 +2203,8 @@ libssh2_sftp_statvfs(LIBSSH2_SFTP *sftp, const char *path,
size_t path_len, LIBSSH2_SFTP_STATVFS *st) size_t path_len, LIBSSH2_SFTP_STATVFS *st)
{ {
int rc; int rc;
if(!sftp || !st)
return LIBSSH2_ERROR_BAD_USE;
BLOCK_ADJUST(rc, sftp->channel->session, sftp_statvfs(sftp, path, path_len, BLOCK_ADJUST(rc, sftp->channel->session, sftp_statvfs(sftp, path, path_len,
st)); st));
return rc; return rc;
@@ -2277,6 +2310,8 @@ libssh2_sftp_mkdir_ex(LIBSSH2_SFTP *sftp, const char *path,
unsigned int path_len, long mode) unsigned int path_len, long mode)
{ {
int rc; int rc;
if(!sftp)
return LIBSSH2_ERROR_BAD_USE;
BLOCK_ADJUST(rc, sftp->channel->session, BLOCK_ADJUST(rc, sftp->channel->session,
sftp_mkdir(sftp, path, path_len, mode)); sftp_mkdir(sftp, path, path_len, mode));
return rc; return rc;
@@ -2366,6 +2401,8 @@ libssh2_sftp_rmdir_ex(LIBSSH2_SFTP *sftp, const char *path,
unsigned int path_len) unsigned int path_len)
{ {
int rc; int rc;
if(!sftp)
return LIBSSH2_ERROR_BAD_USE;
BLOCK_ADJUST(rc, sftp->channel->session, BLOCK_ADJUST(rc, sftp->channel->session,
sftp_rmdir(sftp, path, path_len)); sftp_rmdir(sftp, path, path_len));
return rc; return rc;
@@ -2488,6 +2525,8 @@ libssh2_sftp_stat_ex(LIBSSH2_SFTP *sftp, const char *path,
LIBSSH2_SFTP_ATTRIBUTES *attrs) LIBSSH2_SFTP_ATTRIBUTES *attrs)
{ {
int rc; int rc;
if(!sftp)
return LIBSSH2_ERROR_BAD_USE;
BLOCK_ADJUST(rc, sftp->channel->session, BLOCK_ADJUST(rc, sftp->channel->session,
sftp_stat(sftp, path, path_len, stat_type, attrs)); sftp_stat(sftp, path, path_len, stat_type, attrs));
return rc; return rc;
@@ -2629,6 +2668,8 @@ libssh2_sftp_symlink_ex(LIBSSH2_SFTP *sftp, const char *path,
unsigned int target_len, int link_type) unsigned int target_len, int link_type)
{ {
int rc; int rc;
if(!sftp)
return LIBSSH2_ERROR_BAD_USE;
BLOCK_ADJUST(rc, sftp->channel->session, BLOCK_ADJUST(rc, sftp->channel->session,
sftp_symlink(sftp, path, path_len, target, target_len, sftp_symlink(sftp, path, path_len, target, target_len,
link_type)); link_type));
@@ -2641,5 +2682,8 @@ libssh2_sftp_symlink_ex(LIBSSH2_SFTP *sftp, const char *path,
LIBSSH2_API unsigned long LIBSSH2_API unsigned long
libssh2_sftp_last_error(LIBSSH2_SFTP *sftp) libssh2_sftp_last_error(LIBSSH2_SFTP *sftp)
{ {
if(!sftp)
return 0;
return sftp->last_errno; return sftp->last_errno;
} }

View File

@@ -657,14 +657,14 @@ userauth_hostbased_fromfile(LIBSSH2_SESSION *session,
return rc; return rc;
/* /*
* 48 = packet_type(1) + username_len(4) + servicename_len(4) + * 52 = packet_type(1) + username_len(4) + servicename_len(4) +
* service_name(14)"ssh-connection" + authmethod_len(4) + * service_name(14)"ssh-connection" + authmethod_len(4) +
* authmethod(9)"hostbased" + method_len(4) + pubkeydata_len(4) + * authmethod(9)"hostbased" + method_len(4) + pubkeydata_len(4) +
* local_username_len(4) * hostname_len(4) + local_username_len(4)
*/ */
session->userauth_host_packet_len = session->userauth_host_packet_len =
username_len + session->userauth_host_method_len + hostname_len + username_len + session->userauth_host_method_len + hostname_len +
local_username_len + pubkeydata_len + 48; local_username_len + pubkeydata_len + 52;
/* /*
* Preallocate space for an overall length, method name again, * Preallocate space for an overall length, method name again,
@@ -876,6 +876,15 @@ _libssh2_userauth_publickey(LIBSSH2_SESSION *session,
unsigned char *s; unsigned char *s;
if (session->userauth_pblc_state == libssh2_NB_state_idle) { if (session->userauth_pblc_state == libssh2_NB_state_idle) {
/*
* The call to _libssh2_ntohu32 later relies on pubkeydata having at
* least 4 valid bytes containing the length of the method name.
*/
if (pubkeydata_len < 4)
return _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED,
"Invalid public key, too short");
/* Zero the whole thing out */ /* Zero the whole thing out */
memset(&session->userauth_pblc_packet_requirev_state, 0, memset(&session->userauth_pblc_packet_requirev_state, 0,
sizeof(session->userauth_pblc_packet_requirev_state)); sizeof(session->userauth_pblc_packet_requirev_state));
@@ -888,6 +897,15 @@ _libssh2_userauth_publickey(LIBSSH2_SESSION *session,
*/ */
if (!session->userauth_pblc_method) { if (!session->userauth_pblc_method) {
session->userauth_pblc_method_len = _libssh2_ntohu32(pubkeydata); session->userauth_pblc_method_len = _libssh2_ntohu32(pubkeydata);
if(session->userauth_pblc_method_len > pubkeydata_len)
/* the method length simply cannot be longer than the entire
passed in data, so we use this to detect crazy input
data */
return _libssh2_error(session,
LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED,
"Invalid public key");
session->userauth_pblc_method = session->userauth_pblc_method =
LIBSSH2_ALLOC(session, session->userauth_pblc_method_len); LIBSSH2_ALLOC(session, session->userauth_pblc_method_len);
if (!session->userauth_pblc_method) { if (!session->userauth_pblc_method) {
@@ -898,8 +916,15 @@ _libssh2_userauth_publickey(LIBSSH2_SESSION *session,
memcpy(session->userauth_pblc_method, pubkeydata + 4, memcpy(session->userauth_pblc_method, pubkeydata + 4,
session->userauth_pblc_method_len); session->userauth_pblc_method_len);
} }
assert( /* preallocated method len should match what we expect */ /*
session->userauth_pblc_method_len == _libssh2_ntohu32(pubkeydata)); * The length of the method name read from plaintext prefix in the
* file must match length embedded in the key.
* TODO: The data should match too but we don't check that. Should we?
*/
else if (session->userauth_pblc_method_len !=
_libssh2_ntohu32(pubkeydata))
return _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED,
"Invalid public key");
/* /*
* 45 = packet_type(1) + username_len(4) + servicename_len(4) + * 45 = packet_type(1) + username_len(4) + servicename_len(4) +
@@ -1234,6 +1259,10 @@ libssh2_userauth_publickey(LIBSSH2_SESSION *session,
void **abstract) void **abstract)
{ {
int rc; int rc;
if(!session)
return LIBSSH2_ERROR_BAD_USE;
BLOCK_ADJUST(rc, session, BLOCK_ADJUST(rc, session,
_libssh2_userauth_publickey(session, user, strlen(user), _libssh2_userauth_publickey(session, user, strlen(user),
pubkeydata, pubkeydata_len, pubkeydata, pubkeydata_len,

179
win32/Makefile.Watcom Normal file
View File

@@ -0,0 +1,179 @@
#
# Watcom / OpenWatcom Win32 makefile for libssh2.
#
# Comments to: Guenter Knauf http://www.gknw.net/phpbb
#
!ifndef %watcom
!error WATCOM environment variable not set!
!else
SYS_INCL = -I$(%watcom)\h\nt -I$(%watcom)\h
SYS_LIBS = $(%watcom)\lib386\nt;$(%watcom)\lib386
!endif
!ifdef %libname
LIBNAME = $(%libname)
!else
LIBNAME = libssh2
!endif
TARGETS = $(LIBNAME).dll $(LIBNAME)_imp.lib $(LIBNAME).lib
CC = wcc386
LD = wlink
AR = wlib
RC = wrc
!ifdef __LOADDLL__
! loaddll wcc386 wccd386
! loaddll wpp386 wppd386
! loaddll wlib wlibd
! if $(__VERSION__) > 1270
! loaddll wlink wlinkd
! else
! loaddll wlink wlink
! endif
!endif
!if $(__VERSION__) < 1250
RM = del /q /f >NUL 2>&1
!else
RM = rm -f
!endif
MD = mkdir
RD = rmdir /q /s >NUL 2>&1
CP = copy
CFLAGS = -3r -mf -hc -zff -zgf -zq -zm -zc -s -fr=nul -w2 -fpi -oilrtfm &
-wcd=201 -bt=nt -d+ -dWIN32 -DLIBSSH2_WIN32 &
-I. -I..\include $(SYS_INCL)
!ifdef %debug
DEBUG = -dDEBUG=1 -dDEBUGBUILD
CFLAGS += -d3 $(DEBUG)
!else
CFLAGS += -d0
!endif
!ifdef %use_ipv6
CFLAGS += -d_WIN32_WINNT=0x0501 -dENABLE_IPV6
!endif
#
# Change to suite.
#
!ifdef %zlib_root
ZLIB_ROOT = $(%zlib_root)
!else
ZLIB_ROOT = ..\..\zlib-1.2.5
!endif
!ifdef %openssl_root
OPENSSL_ROOT = $(%openssl_root)
!else
OPENSSL_ROOT = ..\..\openssl-0.9.8o
!endif
#!ifdef %use_zlib
CFLAGS += -dHAVE_ZLIB_H -dHAVE_LIBZ -I$(ZLIB_ROOT)
#!endif
#!ifdef %use_ssl
CFLAGS += -wcd=138 -dUSE_OPENSSL -dUSE_SSLEAY -I$(OPENSSL_ROOT)\inc32
#!endif
!ifdef %use_watt32
CFLAGS += -dUSE_WATT32 -I$(%watt_root)\inc
!endif
OBJ_BASE = WC_Win32.obj
LINK_ARG = $(OBJ_BASE)\dyn\wlink.arg
LIB_ARG = $(OBJ_BASE)\stat\wlib.arg
# In order to process Makefile.inc wmake must be called with -u switch!
!ifndef %MAKEFLAGS
!error You MUST call wmake with the -u switch!
!else
!include ..\Makefile.inc
!endif
OBJS = $(CSOURCES:.c=.obj)
OBJS = $OBJ_DIR\$(OBJS: = $OBJ_DIR\)
#
# Use $(OBJS) as a template to generate $(OBJS_STAT) and $(OBJS_DYN).
#
OBJ_DIR = $(OBJ_BASE)\stat
OBJS_STAT = $+ $(OBJS) $-
OBJ_DIR = $(OBJ_BASE)\dyn
OBJS_DYN = $+ $(OBJS) $-
RESOURCE = $(OBJ_BASE)\dyn\libssh2.res
.c: ..\src
all: $(OBJ_BASE) $(TARGETS) .SYMBOLIC
@echo Welcome to libssh2
clean: .SYMBOLIC
-$(RM) $(OBJS_STAT)
-$(RM) $(OBJS_DYN)
-$(RM) $(RESOURCE) $(LINK_ARG) $(LIB_ARG)
vclean realclean: clean .SYMBOLIC
-$(RM) $(TARGETS) $(LIBNAME).map $(LIBNAME).sym
-$(RD) $(OBJ_BASE)\stat
-$(RD) $(OBJ_BASE)\dyn
-$(RD) $(OBJ_BASE)
$(OBJ_BASE):
-$(MD) $^@
-$(MD) $^@\stat
-$(MD) $^@\dyn
$(LIBNAME).dll: $(OBJS_DYN) $(RESOURCE) $(LINK_ARG)
$(LD) name $^@ @$]@
$(LIBNAME).lib: $(OBJS_STAT) $(LIB_ARG)
$(AR) -q -b -c $^@ @$]@
.ERASE
$(RESOURCE): libssh2.rc
$(RC) $(DEBUG) -q -r -zm -DLIBSSH2_VERSION_ONLY -I..\include $(SYS_INCL) $[@ -fo=$^@
.ERASE
.c{$(OBJ_BASE)\dyn}.obj:
$(CC) $(CFLAGS) -bd -br $[@ -fo=$^@
.ERASE
.c{$(OBJ_BASE)\stat}.obj:
$(CC) $(CFLAGS) $[@ -fo=$^@
$(LINK_ARG): $(__MAKEFILES__)
%create $^@
@%append $^@ system nt dll
@%append $^@ file { $(OBJS_DYN) }
!ifdef %debug
@%append $^@ debug all
@%append $^@ option symfile
!endif
@%append $^@ option quiet, map, caseexact, eliminate, implib=$(LIBNAME)_imp.lib,
@%append $^@ res=$(RESOURCE) libpath $(SYS_LIBS)
!ifdef %use_watt32
@%append $^@ library $(%watt_root)\lib\wattcpw_imp.lib
!else
@%append $^@ library ws2_32.lib
!endif
#!ifdef %use_zlib
@%append $^@ library $(ZLIB_ROOT)\zlib.lib
#!endif
#!ifdef %use_ssl
@%append $^@ library $(OPENSSL_ROOT)\out32\libeay32.lib, $(OPENSSL_ROOT)\out32\ssleay32.lib
#!endif
$(LIB_ARG): $(__MAKEFILES__)
%create $^@
@for %f in ($(OBJS_STAT)) do @%append $^@ +- %f

View File

@@ -3,9 +3,7 @@
## Makefile for building libssh2 (Win32 version - gnu make) ## Makefile for building libssh2 (Win32 version - gnu make)
## Use: make -f Makefile.win32 [help|all|clean|dev|devclean|dist|distclean|dll|objclean] ## Use: make -f Makefile.win32 [help|all|clean|dev|devclean|dist|distclean|dll|objclean]
## ##
## Comments to: Guenter Knauf <eflash@gmx.net> ## Comments to: Guenter Knauf http://www.gknw.net/phpbb
##
## $Id: Makefile.win32,v 1.11 2009/04/09 03:13:52 gknauf Exp $
# #
######################################################################### #########################################################################
@@ -18,7 +16,7 @@ WITH_ZLIB = 1
# Edit the path below to point to the base of your OpenSSL package. # Edit the path below to point to the base of your OpenSSL package.
ifndef OPENSSL_PATH ifndef OPENSSL_PATH
OPENSSL_PATH = ../../openssl-0.9.8n OPENSSL_PATH = ../../openssl-0.9.8o
endif endif
# Edit the path below to point to your Distribution folder. # Edit the path below to point to your Distribution folder.
@@ -36,7 +34,7 @@ DEVLARC = $(DEVLDIR).zip
# Edit the vars below to change target settings. # Edit the vars below to change target settings.
TARGET = libssh2 TARGET = libssh2
VERSION = $(LIBSSH2_VERSION) VERSION = $(LIBSSH2_VERSION)
COPYR = (c) 2004-2010 The libssh2 project and its contributors. COPYR = (c) $(LIBSSH2_COPYRIGHT_STR)
WWWURL = http://www.libssh2.org/ WWWURL = http://www.libssh2.org/
DESCR = libssh2 $(LIBSSH2_VERSION_STR) DESCR = libssh2 $(LIBSSH2_VERSION_STR)
#STACK = 64000 #STACK = 64000
@@ -68,7 +66,7 @@ endif
CP = cp -afv CP = cp -afv
# RM = rm -f # RM = rm -f
# Here you can find a native Win32 binary of the original awk: # Here you can find a native Win32 binary of the original awk:
# http://www.gknw.net/development/prgtools/awk.zip # http://www.gknw.net/development/prgtools/awk-20070501.zip
AWK = awk AWK = awk
ZIP = zip -qzr9 ZIP = zip -qzr9
@@ -222,46 +220,10 @@ $(TARGET).dll $(TARGET)dll.a: $(OBJL)
@$(LD) $(LDFLAGS) $^ -o $@ $(LIBPATH) $(LDLIBS) @$(LD) $(LDFLAGS) $^ -o $@ $(LIBPATH) $(LDLIBS)
$(OBJDIR)/%.res: $(OBJDIR)/%.rc $(OBJDIR)/%.res: %.rc
@echo Creating $@ @echo Creating $@
@$(RC) $(RCFLAGS) $< -o $@ @$(RC) $(RCFLAGS) -DLIBSSH2_VERSION_ONLY -I. -I ../include $< -o $@
$(OBJDIR)/%.rc: Makefile.win32 $(OBJDIR)/version.inc
@echo $(DL)1 VERSIONINFO$(DL) > $@
@echo $(DL) FILEVERSION $(LIBSSH2_VERSION),0$(DL) >> $@
@echo $(DL) PRODUCTVERSION $(LIBSSH2_VERSION),0$(DL) >> $@
@echo $(DL) FILEFLAGSMASK 0x3fL$(DL) >> $@
@echo $(DL) FILEOS 0x40004L$(DL) >> $@
@echo $(DL) FILEFLAGS 0x0L$(DL) >> $@
@echo $(DL) FILETYPE 0x1L$(DL) >> $@
@echo $(DL) FILESUBTYPE 0x0L$(DL) >> $@
@echo $(DL)BEGIN$(DL) >> $@
@echo $(DL) BLOCK "StringFileInfo"$(DL) >> $@
@echo $(DL) BEGIN$(DL) >> $@
@echo $(DL) BLOCK "040904E4"$(DL) >> $@
@echo $(DL) BEGIN$(DL) >> $@
@echo $(DL) VALUE "LegalCopyright","$(COPYR)\0"$(DL) >> $@
ifdef COMPANY
@echo $(DL) VALUE "CompanyName","$(COMPANY)\0"$(DL) >> $@
endif
@echo $(DL) VALUE "ProductName","$(notdir $(@:.rc=.dll))\0"$(DL) >> $@
@echo $(DL) VALUE "ProductVersion","$(LIBSSH2_VERSION_STR)\0"$(DL) >> $@
@echo $(DL) VALUE "License","Released under the Modified BSD license.\0"$(DL) >> $@
@echo $(DL) VALUE "FileDescription","$(DESCR)\0"$(DL) >> $@
@echo $(DL) VALUE "FileVersion","$(LIBSSH2_VERSION_STR)\0"$(DL) >> $@
@echo $(DL) VALUE "InternalName","$(notdir $(@:.rc=))\0"$(DL) >> $@
@echo $(DL) VALUE "OriginalFilename","$(notdir $(@:.rc=.dll))\0"$(DL) >> $@
@echo $(DL) VALUE "WWW","$(WWWURL)\0"$(DL) >> $@
@echo $(DL) END$(DL) >> $@
@echo $(DL) END$(DL) >> $@
@echo $(DL) BLOCK "VarFileInfo"$(DL) >> $@
@echo $(DL) BEGIN$(DL) >> $@
@echo $(DL) VALUE "Translation", 0x409, 1252$(DL) >> $@
@echo $(DL) END$(DL) >> $@
@echo $(DL)END$(DL) >> $@
ifdef ICON
@echo $(DL)10 ICON DISCARDABLE "$(ICON)"$(DL) >> $@
endif
$(DISTDIR)/readme.txt: Makefile.win32 $(DISTDIR)/readme.txt: Makefile.win32
@echo Creating $@ @echo Creating $@

View File

@@ -1,10 +1,10 @@
# Tweak these for your system # Tweak these for your system
OPENSSLINC=..\openssl-0.9.8e\inc32 OPENSSLINC=..\openssl-0.9.8o\inc32
OPENSSLLIB=..\openssl-0.9.8e\out32dll OPENSSLLIB=..\openssl-0.9.8o\out32dll
ZLIBINC=-DLIBSSH2_HAVE_ZLIB=1 /I..\zlib-1.2.3 ZLIBINC=-DLIBSSH2_HAVE_ZLIB=1 /I..\zlib-1.2.5
ZLIBLIB=..\zlib-1.2.3 ZLIBLIB=..\zlib-1.2.5
!if "$(TARGET)" == "" !if "$(TARGET)" == ""
TARGET=Release TARGET=Release

45
win32/libssh2.rc Normal file
View File

@@ -0,0 +1,45 @@
/***************************************************************************
* libssh2 Win32 resource file *
***************************************************************************/
#include <winver.h>
#include "../include/libssh2.h"
LANGUAGE 0x09,0x01
#define RC_VERSION LIBSSH2_VERSION_MAJOR, LIBSSH2_VERSION_MINOR, LIBSSH2_VERSION_PATCH, 0
VS_VERSION_INFO VERSIONINFO
FILEVERSION RC_VERSION
PRODUCTVERSION RC_VERSION
FILEFLAGSMASK 0x3fL
#if defined(DEBUGBUILD) || defined(_DEBUG)
FILEFLAGS 1
#else
FILEFLAGS 0
#endif
FILEOS VOS__WINDOWS32
FILETYPE VFT_DLL
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", "The libssh2 library, http://www.libssh2.org/\0"
VALUE "FileDescription", "libssh2 Shared Library\0"
VALUE "FileVersion", LIBSSH2_VERSION "\0"
VALUE "InternalName", "libssh2\0"
VALUE "OriginalFilename", "libssh2.dll\0"
VALUE "ProductName", "The libssh2 library\0"
VALUE "ProductVersion", LIBSSH2_VERSION "\0"
VALUE "LegalCopyright", "<22> " LIBSSH2_COPYRIGHT "\0"
VALUE "License", "http://www.libssh2.org/license.html\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END

View File

@@ -3,9 +3,7 @@
## Makefile for building libssh2 samples (Win32 version - gnu make) ## Makefile for building libssh2 samples (Win32 version - gnu make)
## Use: make -f Makefile.win32 [help] ## Use: make -f Makefile.win32 [help]
## ##
## Comments to: Guenter Knauf <eflash@gmx.net> ## Comments to: Guenter Knauf http://www.gknw.net/phpbb
##
## $Id: Makefile.win32,v 1.8 2009/04/09 03:14:05 gknauf Exp $
# #
######################################################################### #########################################################################
@@ -16,7 +14,7 @@ endif
# Edit the path below to point to the base of your OpenSSL package. # Edit the path below to point to the base of your OpenSSL package.
ifndef OPENSSL_PATH ifndef OPENSSL_PATH
OPENSSL_PATH = ../../../openssl-0.9.8n OPENSSL_PATH = ../../../openssl-0.9.8o
endif endif
# Edit the var below to enable static linking of libssh2 and libz # Edit the var below to enable static linking of libssh2 and libz
@@ -56,7 +54,7 @@ endif
CP = cp -afv CP = cp -afv
# RM = rm -f # RM = rm -f
# Here you can find a native Win32 binary of the original awk: # Here you can find a native Win32 binary of the original awk:
# http://www.gknw.net/development/prgtools/awk.zip # http://www.gknw.net/development/prgtools/awk-20070501.zip
AWK = awk AWK = awk
ZIP = zip -qzr9 ZIP = zip -qzr9