Compare commits

..

83 Commits

Author SHA1 Message Date
Daniel Stenberg
0ecd0eb37c channel_close: no longer wait for the SSH_MSG_CHANNEL_CLOSE message
As the packet may simply not arrive we cannot have the close
function wait for it unconditionally.
2010-04-13 22:59:52 +02:00
Daniel Stenberg
f514bcac53 less code duplication in the poll vs select code flows
libssh2_keepalive_send and libssh2_session_block_directions are
now used outside of the #ifdef blocks.
2010-04-13 10:45:01 +02:00
Daniel Stenberg
79ee2f339e make it C90 compliant 2010-04-12 22:09:38 +02:00
Daniel Stenberg
12fd204ae4 updated with all changes and bugs since 1.2.4 2010-04-11 14:58:19 +02:00
Daniel Stenberg
2386a5a21c Added LIBSSH2_SFTP_S_IS***() macros and updated docs
libssh2_sftp_fstat_ex.3 is now extended quite a lot to describe a
lot of the struct and the bits it uses and how to test for them.
2010-04-11 11:26:16 +02:00
Daniel Stenberg
8b7e22cb33 sftp_init() deal with _libssh2_channel_write() returns short
When _libssh2_channel_write() is asked to send off 9 bytes, the
code needs to deal with the situation where less than 9 bytes
were sent off and prepare to send the remaining piece at a later
time.
2010-04-01 20:25:49 +02:00
Daniel Stenberg
1d49f1bc21 handle a NULL password as if it was ""
libssh2_userauth_publickey_fromfile_ex() takes a "passphrase"
but didn't deal with it being set to NULL.
2010-03-29 17:19:58 +02:00
Daniel Stenberg
1711917c2c Reduce used window sizes by factor 10
As reported in bug report #166 http://libssh2.stuge.se/ticket/166
by 'ptjm', the maximum window size must be less crazy for libssh2
to do better with more server implementations. I did not do any
testing to see how this changes raw SCP performance, but the
maximum window size is still almost 4MB. This also has the upside
that libssh2 will use less memory.
2010-03-28 15:36:58 +02:00
Peter Stuge
b6ed60d2cc Correctly clear blocking flag after sending multipart packet
commit 7317edab61 cleared the outbound
blocking bit when send_existing() returned PACKET_NONE and *ret=0, as
opposed to before even calling send_existing(), but because *ret=1 when
sending parts 2..n of an existing packet, the bit would only be cleared
when calling libssh2_transport_write() for a new packet.

Clear the direction flag after the final part of a packet has been sent.
2010-03-28 01:35:55 +01:00
Daniel Stenberg
79acf60ae6 Added man page for libssh2_knownhost_addc()
Added mention in libssh2_knownhost_add() docs that
libssh2_knownhost_addc() is the preferred function now.
2010-03-24 15:39:46 +01:00
Daniel Stenberg
7810656564 at next soname bump remove libssh2_knownhost_add() 2010-03-24 15:39:13 +01:00
Daniel Stenberg
4bc10aa728 ignore TAGS ("make tags" makes them) 2010-03-24 15:38:44 +01:00
Daniel Stenberg
5512d0d593 fix memory leak
we must not assign the pointer a NULL since it keeps allocated
data and at least parts of an error string
2010-03-23 23:16:08 +01:00
Daniel Stenberg
05f9fb878e fixed the pattern for avoiding the poll check
added some comments about known problems with poll on darwin
2010-03-23 22:50:53 +01:00
Daniel Stenberg
f314f3b5fd avoid checking for poll on some systems
darwin and interix are known to have broken poll implementations
so we skip the check on those and thus have them use select
unconditionally
2010-03-23 22:00:31 +01:00
Daniel Stenberg
eb4407975c ignore libssh2.dsp 2010-03-23 21:59:12 +01:00
Simon Josefsson
6d253324be Fix logic in "on-the-fly" crypto init. 2010-03-23 21:09:32 +01:00
Simon Josefsson
aebcc45a37 Make sure keepalive is working even when poll is used. 2010-03-23 21:08:47 +01:00
Paul Querna
1decccbb52 Use poll when available on blocking API.
Signed-off-by: Simon Josefsson <simon@josefsson.org>
2010-03-23 20:48:58 +01:00
Peter Stuge
4c09324b02 Fix speling 2010-03-20 02:45:46 +01:00
Daniel Stenberg
6d4b1bbb45 fix NULL dereference when window adjusting a non-existing channel
Suyog Jadhav pointed out that when receiving a window adjust to
a channel not found, the code would reference a NULL pointer.
Now it will instead output a message about that fact.
2010-03-19 14:58:05 +01:00
Simon Josefsson
5456163507 Fix build problem. 2010-03-19 09:40:50 +01:00
Simon Josefsson
7301036421 Eat our own dog food, call libssh2_init and libssh2_exit in the examples. 2010-03-19 09:35:00 +01:00
Simon Josefsson
fa4017c613 Fix init/exit logic. Add self-test of it. 2010-03-19 09:27:19 +01:00
Daniel Stenberg
2e3f380ff2 fix typo 2010-03-19 09:23:47 +01:00
Simon Josefsson
6c3c3e1b49 Add man page for libssh2_init and libssh2_exit. Fix libssh2_exit prototype. 2010-03-19 09:21:48 +01:00
Simon Josefsson
55ede3b41b Shorten constant a bit. More documentation. 2010-03-19 09:17:42 +01:00
Simon Josefsson
d00283927f Fix namespace pollution. 2010-03-19 09:14:21 +01:00
Simon Josefsson
9ea5b0625e Add global init/exit points, to do crypto initialization in one place.
By Lars Nordin.
2010-03-19 09:05:52 +01:00
Daniel Stenberg
1b1b4ac387 libssh2 is released under the Modifed BSD license, not GPL 2010-03-14 23:30:46 +01:00
Alexander Lamaison
9abf81de97 Add libssh2_knownhost_addc to handle comments.
Comments in known_hosts file were not handle properly.  They were parsed as
part of the key causing key matching to return a mismatch if the entry had a
comment.  This adds a new API function that takes an optional comment and
changes libssh2_knownhost_readline to parse the comment as pass it to the
new function.

Fixes #164.
2010-03-14 19:52:00 +00:00
Alexander Lamaison
c585828d2b Fix gettimeofday to compile with Visual C++ 6.
Reported by Steven Van Ingelgem.
2010-03-12 11:29:31 +00:00
Simon Josefsson
e54786cf2e Add. 2010-03-10 18:50:29 +01:00
Simon Josefsson
4cfeade243 keepalive.c: Fix libssh2_error usage. 2010-03-10 13:16:32 +01:00
Simon Josefsson
60ff0a2ade Fix typo in last commit. 2010-03-10 13:13:48 +01:00
Simon Josefsson
64c97765a5 Tidy up build option notice. 2010-03-10 13:13:19 +01:00
Simon Josefsson
ab66ff488b Add entry about keep alive stuff. 2010-03-10 13:10:57 +01:00
Simon Josefsson
0d331aade1 Add keep-alive support. 2010-03-10 13:08:42 +01:00
Alexander Lamaison
69520e1564 Untabify. 2010-03-07 17:12:56 +00:00
Alexander Lamaison
f87f4ab836 Fix memory leak in libssh2_knownhost_add. 2010-03-07 16:20:07 +00:00
Daniel Stenberg
b3556c2e0c change 'int' to 'libssh2_socket_t' in the public API for sockets 2010-03-06 19:51:58 +01:00
Daniel Stenberg
1f406feaa4 reduce code duplication and return underlying error better 2010-03-03 23:57:22 +01:00
Daniel Stenberg
c0436fc602 acknowledge when _libssh2_packet_requirev() returns error
when _libssh2_packet_requirev() returns an error when waiting for
SSH_MSG_USERAUTH_SUCCESS or SSH_MSG_USERAUTH_FAILURE, it is an
error and it should be treated as such
2010-03-03 23:44:54 +01:00
Daniel Stenberg
0034a83e4c wrap long lines 2010-03-03 23:44:24 +01:00
Daniel Stenberg
f0f4ba92f0 polished the phrasing in two error strings 2010-03-03 23:37:58 +01:00
Daniel Stenberg
c29ba827e4 silence picky compiler warnings 2010-03-03 23:33:25 +01:00
Daniel Stenberg
a03e1b0457 silence picky compiler warnings 2010-03-03 23:32:56 +01:00
Daniel Stenberg
d4a768af4e removed libssh2_error()'s forth argument
libssh2_error() no longer allocates a string and only accepts a const
error string. I also made a lot of functions use the construct of
return libssh2_error(...) instead of having one call to
libssh2_error() and then a separate return call. In several of those
cases I then also changed the former -1 return code to a more
detailed one - something that I think will not change behaviors
anywhere but it's worth keeping an eye open for any such.
2010-03-03 23:04:05 +01:00
Daniel Stenberg
d377c3065a repaired --enable-debug 2010-03-03 22:51:15 +01:00
Simon Josefsson
51fcb11d60 Make ./configure output a summary of build options. 2010-03-01 17:01:47 +01:00
Daniel Stenberg
8bbc109e52 let the err_msg in the session struct be const too 2010-03-01 13:16:19 +01:00
Simon Josefsson
0ef84144ac Revert #ifdef change that pulled in AES-CTR code when explicitly disabled. 2010-03-01 13:09:18 +01:00
Daniel Stenberg
ef27023eb9 fix #ifdefs 2010-03-01 11:42:38 +01:00
Daniel Stenberg
a9621548f8 make function match the new proto 2010-03-01 11:42:04 +01:00
Simon Josefsson
a925bdd5bb Improve AES-CTR check. 2010-03-01 11:38:50 +01:00
Daniel Stenberg
3420e9858c use const to silence a bazillion warnings 2010-03-01 11:05:40 +01:00
Simon Josefsson
2de339b2f7 Use AES-CTR from OpenSSL when available.
Reported by Lars Nordin <Lars.Nordin@SDlabs.se>.
2010-03-01 10:34:00 +01:00
Simon Josefsson
c46cbd46e2 Make it possible to disable DSA.
Patch from Lars Nordin <Lars.Nordin@SDlabs.se>.
2010-03-01 10:30:22 +01:00
Peter Stuge
16af813b81 Send and receive channel EOF before sending SSH_MSG_CHANNEL_CLOSE
Sending SSH_MSG_CHANNEL_CLOSE without channel EOF is explicitly allowed
in RFC 4254, but some non-conforming servers will hang or time out when
the channel is closed before EOF.

Other common clients send and receive EOF before closing, there are no
drawbacks, and some servers need it to work correctly.
2010-03-01 06:43:53 +01:00
Alexander Lamaison
a2157c8391 Style improvements to knownhost error handling.
Made improvements as suggested by Peter Stuge: http://www.libssh2.org/mail/libssh2-devel-archive-2010-02/0161.shtml.
2010-02-26 18:47:54 +00:00
Alexander Lamaison
942a40b482 Call libssh2_error for every knownhost API failure.
The libssh2 API calls should set the last error code and a message when
returning a failure by calling libssh2_error.  This changeset adds these
calls to the libssh2_knownhost_* API as well as libssh2_base64_decode.

This change also makes libssh2_error into a function rather than a macro.
Its implementation is moved to misc.c.  This function returns the error
code passed to it allowing callers to return the error value directly
without duplicating the error code.
2010-02-24 13:45:00 +00:00
Alexander Lamaison
ef096220ce Fix LIBSSH2_ALLOC checks.
These appear to be cut-and paste errors where the wrong variable is checked
for NULLness after calling LIBSSH2_ALLOC.
2010-02-23 22:00:40 +00:00
Simon Josefsson
e4232e531b Silence compiler warning. 2010-02-23 15:49:47 +01:00
Simon Josefsson
cdc1366b2c Make it portable; test uses = for string comparison (not ==). Indent. 2010-02-23 15:27:18 +01:00
Alexander Lamaison
3e1a95392e libssh2_knownhost_del: fix write to freed memory.
When removing a known host, libssh2_knownhost_del would remove the node from the linked list, free its memory and then overwrite the struct parameter (which indicated which node to remove) with 0.  However, this struct is actually allocated within the just-freed node meaning we're writing to freed memory.  This made Windows very upset.

The fix is simply to overwrite the struct first before freeing the memory.
2010-02-22 14:50:08 +00:00
Daniel Stenberg
b4f12e153a show more verbose error when SCP send fails 2010-02-21 19:29:23 +01:00
Daniel Stenberg
bd5519c7a2 libssh2_socket_t is done, a library-free function is needed 2010-02-21 19:20:07 +01:00
Daniel Stenberg
05b1bb3cd3 clarify that this frees all data associated with a session 2010-02-21 19:16:30 +01:00
Daniel Stenberg
dea503df73 improved error handling 2010-02-21 19:08:14 +01:00
Daniel Stenberg
c5609acb17 add missing libssh2_error() calls
To make sure the public API is functional and that the
BLOCK_ADJUST_ERRNO() macro works correctly we MUST make sure to
call libssh2_error() when we return errors.
2010-02-18 13:20:11 +01:00
Daniel Stenberg
37c08983a3 fix memory leak in userauth_keyboard_interactive()
Mr anonymous in bug #125 pointed out that the userauth_keyboard_interactive()
function does in fact assign the same pointer a second time to a new allocated
buffer without properly freeing the previous one, which caused a memory leak.
2010-02-18 13:04:29 +01:00
Daniel Stenberg
72ae0866cb added missing error codes
To allow the libssh2_session_last_error() function to work as
documented, userauth_password() now better makes sure to call
libssh2_error() everywhere before it returns error.

Pointed out by mr anonymous in bug #128
2010-02-18 00:01:33 +01:00
Peter Stuge
2149244cfe Fix resource and memory leaks in examples as reported by cppcheck
Thanks to Ettl Martin for the report and patch. This fixes #132
2010-02-16 13:21:57 +01:00
Daniel Stenberg
a491017f5a mention the new man pages for macros 2010-02-15 14:29:04 +01:00
Daniel Stenberg
ec699ef684 added man pages for API macros
all #defined macros in the public headers are considered to be part
of the API and I've generated individual man pages for each of them
to A) make it easier to figure out what each function/macro actually
is for so that automated lookups work better and for B) make sure we
have all public functions document (both macros and functions) to
make it easier for us to work away from all the macros in a future
release.
2010-02-15 14:24:40 +01:00
Daniel Stenberg
514104b37d Committed the patch by Yoichi Iwaki in bug #2929647
Committed the patch by Yoichi Iwaki in bug #2929647, which fixed a memory
leak when an 'outbuf' was still allocated when a session was freed.
2010-02-15 00:15:30 +01:00
Daniel Stenberg
4d13c6e59b free "outbuf" when killing a session
Fix memoary leak: if there was an "output" still allocated when a
session was torn down it needs to be freed in session_free()

Patch by Yoichi Iwaki in bug #2929647
2010-02-15 00:12:10 +01:00
Daniel Stenberg
72a28f6b16 the working version name is now 1.2.5_DEV 2010-02-13 17:18:55 +01:00
Daniel Stenberg
c889058cb3 updated info for 1.2.4 2010-02-13 17:10:30 +01:00
Dan Fandrich
69c876e210 Allow compiling with OpenSSL when AES isn't available. 2010-02-10 14:49:17 -08:00
Dave McCaldon
10f5c70ac0 Fix Tru64 socklen_t compile issue with example/direct_tcpip.c
Building libssh2-1.2.3 on Tru64 fails at line 48 and 166 because socklen_t
isn't defined on Tru64 unless _POSIX_PII_SOCKET is defined.

This patch updates configure.ac to add -D_POSIX_PII_SOCKET when building
on Tru64 platform(s).
2010-02-09 11:45:40 +01:00
Dave McCaldon
ea914c8b72 Resolve compile issues on Solaris x64 and UltraSPARC
Solaris builds of libssh2-1.2.3 failed on both x64 and UltraSPARC
platforms because of two problems:

1) src/agent.c:145 sun is a reserved word when using the SUNWspro compiler
2) example/direct_tcpip.c:84 INADDR_NONE is not defined
2010-02-09 11:19:52 +01:00
Daniel Stenberg
64a6c255ec towards 1.2.4 now 2010-02-03 19:36:19 +01:00
103 changed files with 2904 additions and 1224 deletions

1
.gitignore vendored
View File

@@ -32,3 +32,4 @@ install-sh
mkinstalldirs
tags
libssh2.pc
TAGS

View File

@@ -1,5 +1,7 @@
CSOURCES = channel.c comp.c crypt.c hostkey.c kex.c mac.c misc.c \
packet.c publickey.c scp.c session.c sftp.c userauth.c transport.c \
version.c knownhost.c agent.c openssl.c libgcrypt.c pem.c
version.c knownhost.c agent.c openssl.c libgcrypt.c pem.c keepalive.c \
global.c
HHEADERS = libssh2_priv.h openssl.h libgcrypt.h transport.h channel.h comp.h mac.h misc.h
HHEADERS = libssh2_priv.h openssl.h libgcrypt.h transport.h channel.h \
comp.h mac.h misc.h

23
NEWS
View File

@@ -1,3 +1,26 @@
o Use poll instead of select when available. By Paul Querna.
o Add APIs to have libssh2 automatically send keep-alive requests.
The APIs are libssh2_keepalive_config, and libssh2_keepalive_send.
By Simon Josefsson.
o Add global init/exit points, to do crypto initialization in one place.
The APIs are libssh2_init and libssh2_exit. By Lars Nordin.
* (February 15 2010) Daniel Stenberg:
- Added 46 new man pages for public convenience macros. The man pages are
just short redirects to the actual underlying function. The were all
initially created by a script.
- Committed the patch by Yoichi Iwaki in bug #2929647, which fixed a memory
leak when an 'outbuf' was still allocated when a session was freed.
Version 1.2.4 (February 13, 2010)
o Resolve compile issues on Solaris x64 and UltraSPARC
o Allow compiling with OpenSSL when AES isn't available
o Fix Tru64 socklen_t compile issue with example/direct_tcpip.c
Version 1.2.3 (February 3, 2010)
o Added libssh2_trace_sethandler()

View File

@@ -1,27 +1,33 @@
libssh2 1.2.3
libssh2 1.2.5
This release includes the following changes:
o ssh-agent support with the new libssh2_agent_* functions
o Added libssh2_trace_sethandler()
o Added the direct_tcpip.c and ssh2_agent.c examples
o Added Add keep-alive support: libssh2_keepalive_config() and
libssh2_keepalive_send()
o Added libssh2_knownhost_addc(), libssh2_init() and libssh2_exit()
o Added LIBSSH2_SFTP_S_IS***() macros
This release includes the following bugfixes:
o Fixed memory leak in userauth_publickey
o Fixed publickey authentication regression
o Silenced several compiler warnings
o avoid returning data to memory already freed
o transport layer fix for bogus -39 (LIBSSH2_ERROR_BAD_USE) errors
o Fixed padding in ssh-dss signature blob encoding
o Fixed direction blocking flag problems
o Fixed memory leak in sftp_fstat()
o fix memory leak in libssh2_session_startup()
o added missing error codes - shown as hangs in blocking mode
o fix memory leak in userauth_keyboard_interactive()
o libssh2_knownhost_del: fix write to freed memory
o Send and receive channel EOF before sending SSH_MSG_CHANNEL_CLOSE
o Use AES-CTR from OpenSSL when available
o Fixed gettimeofday to compile with Visual C++ 6
o NULL dereference when window adjusting a non-existing channel
o avoid using poll on interix and mac os x systems
o fix scp memory leak
o Correctly clear blocking flag after sending multipart packet
o Reduce used window sizes by factor 10
o libssh2_userauth_publickey_fromfile_ex() handles a NULL password
o sftp_init() deal with _libssh2_channel_write() short returns
This release would not have looked like this without help, code, reports and
advice from friends like these:
Simon Josefsson, Peter Stuge, Daiki Ueno, Dave McCaldon,
Alexander Lamaison
Peter Stuge, Simon Josefsson, Alexander Lamaison, Paul Querna, Suyog Jadhav,
Lars Nordin
Thanks! (and sorry if I forgot to mention someone)

18
TODO
View File

@@ -2,9 +2,12 @@ Things TODO
===========
* make sure the windowing code adapts better to slow situations so that it
doesn't then use as much memory as today
doesn't then use as much memory as today. Possibly by an app-controllable
"Window mode"?
* Introduce a 'libssh2_socket_t' type for sockets in internal code
* Introduce a function that can free data that is returned allocated from the
lib, like when libssh2_session_last_error() is asked to return the string
with 'want_buf' set to non-zero.
* Provide a libssh2_scp_send() API for files larger than 4GB (32bit size)
@@ -41,4 +44,13 @@ At next SONAME bump
* Rename a few function:
libssh2_hostkey_hash => libssh2_session_hostkey_hash
libssh2_banner_set => libssh2_session_banner_set
libssh2_banner_set => libssh2_session_banner_set
* change 'int' to 'libssh2_socket_t' in the public API for sockets.
* Use 'size_t' for string lengths in all functions.
* Add a comment field to struct libssh2_knownhost.
* remove the existing libssh2_knownhost_add() function and rename
libssh2_knownhost_addc to become the new libssh2_knownhost_add instead

View File

@@ -2,20 +2,15 @@
LIBTOOLIZE="libtoolize"
if [ "x`which $LIBTOOLIZE`" == "x" ];
then
LIBTOOLIZE="glibtoolize";
if [ "x`which $LIBTOOLIZE`" = "x" ]; then
LIBTOOLIZE="glibtoolize"
fi
if [ "x`which $LIBTOOLIZE`" == "x" ];
then
echo "Neither libtoolize nor glibtoolize could be found!";
exit 1
if [ "x`which $LIBTOOLIZE`" = "x" ]; then
echo "Neither libtoolize nor glibtoolize could be found!"
exit 1
fi
${LIBTOOLIZE} --copy --automake --force
${ACLOCAL:-aclocal} -I m4 $ACLOCAL_FLAGS
${AUTOHEADER:-autoheader}

View File

@@ -41,6 +41,9 @@ case "$host" in
;;
*hpux*)
;;
*osf*)
CFLAGS="$CFLAGS -D_POSIX_PII_SOCKET"
;;
*)
;;
esac
@@ -108,6 +111,14 @@ if test "$ac_cv_libgcrypt" = "yes"; then
fi
AM_CONDITIONAL(LIBGCRYPT, test "$ac_cv_libgcrypt" = "yes")
# Not all OpenSSL have AES-CTR functions.
if test "$ac_cv_libssl" = "yes"; then
save_LDFLAGS="$LDFLAGS"
LDFLAGS="$LDFLAGS $LIBSSL"
AC_CHECK_FUNCS(EVP_aes128_ctr)
LDFLAGS="$save_LDFLAGS"
fi
# Look for Libz
if test "$use_libz" != "no"; then
AC_LIB_HAVE_LINKFLAGS([z], [], [#include <zlib.h>])
@@ -144,12 +155,12 @@ AC_MSG_CHECKING([whether to enable pedantic and debug compiler options])
AC_ARG_ENABLE(debug,
AC_HELP_STRING([--enable-debug],[Enable pedantic and debug options])
AC_HELP_STRING([--disable-debug],[Disable debug options]),
[ case "$enableval" in
[ case "$enable_debug" in
no)
AC_MSG_RESULT(no)
;;
*) AC_MSG_RESULT(yes)
enable_debug=yes
CPPFLAGS="$CPPFLAGS -DLIBSSH2DEBUG"
CFLAGS="$CFLAGS -g"
@@ -159,6 +170,7 @@ AC_HELP_STRING([--disable-debug],[Disable debug options]),
;;
esac
],
enable_debug=no
AC_MSG_RESULT(no)
)
@@ -217,7 +229,25 @@ case $host in
;;
esac
AC_CHECK_FUNCS(poll gettimeofday select strtoll)
case $host in
*darwin*|*interix*)
dnl poll() does not work on these platforms
dnl Interix: "does provide poll(), but the implementing developer must
dnl have been in a bad mood, because poll() only works on the /proc
dnl filesystem here"
dnl Mac OS X's poll has funny behaviors, like:
dnl not being able to do poll on no fildescriptors (10.3?)
dnl not being able to poll on some files (like anything in /dev)
dnl not having reliable timeout support
dnl inconsistent return of POLLHUP where other implementations give POLLIN
AC_MSG_NOTICE([poll use is disabled on this platform])
;;
*)
AC_CHECK_FUNCS(poll)
;;
esac
AC_CHECK_FUNCS(gettimeofday select strtoll)
dnl Check for select() into ws2_32 for Msys/Mingw
if test "$ac_cv_func_select" != "yes"; then
@@ -256,3 +286,17 @@ AC_CONFIG_FILES([Makefile
docs/Makefile
libssh2.pc])
AC_OUTPUT
AC_MSG_NOTICE([summary of build options:
version: ${VERSION}
Host type: ${host}
Install prefix: ${prefix}
Compiler: ${CC}
Compiler flags: ${CFLAGS}
Library types: Shared=${enable_shared}, Static=${enable_static}
Crypto library: openssl: ${ac_cv_libssl:-no} (AES-CTR: ${ac_cv_func_EVP_aes128_ctr:-N/A}) libgcrypt: ${ac_cv_libgcrypt:-no}
Debug build: $enable_debug
Path to sshd: $ac_cv_path_SSHD (only for self-tests)
libz compression: $ac_cv_libz
])

View File

@@ -13,41 +13,63 @@ dist_man_MANS = \
libssh2_banner_set.3 \
libssh2_base64_decode.3 \
libssh2_channel_close.3 \
libssh2_channel_direct_tcpip.3 \
libssh2_channel_direct_tcpip_ex.3 \
libssh2_channel_eof.3 \
libssh2_channel_exec.3 \
libssh2_channel_flush.3 \
libssh2_channel_flush_ex.3 \
libssh2_channel_flush_stderr.3 \
libssh2_channel_forward_accept.3 \
libssh2_channel_forward_cancel.3 \
libssh2_channel_forward_listen.3 \
libssh2_channel_forward_listen_ex.3 \
libssh2_channel_free.3 \
libssh2_channel_get_exit_status.3 \
libssh2_channel_handle_extended_data.3 \
libssh2_channel_handle_extended_data2.3 \
libssh2_channel_ignore_extended_data.3 \
libssh2_channel_open_ex.3 \
libssh2_channel_open_session.3 \
libssh2_channel_process_startup.3 \
libssh2_channel_read.3 \
libssh2_channel_read_ex.3 \
libssh2_channel_read_stderr.3 \
libssh2_channel_receive_window_adjust.3 \
libssh2_channel_receive_window_adjust2.3 \
libssh2_channel_request_pty.3 \
libssh2_channel_request_pty_ex.3 \
libssh2_channel_request_pty_size.3 \
libssh2_channel_request_pty_size_ex.3 \
libssh2_channel_send_eof.3 \
libssh2_channel_set_blocking.3 \
libssh2_channel_setenv.3 \
libssh2_channel_setenv_ex.3 \
libssh2_channel_shell.3 \
libssh2_channel_subsystem.3 \
libssh2_channel_wait_closed.3 \
libssh2_channel_wait_eof.3 \
libssh2_channel_window_read.3 \
libssh2_channel_window_read_ex.3 \
libssh2_channel_window_write.3 \
libssh2_channel_window_write_ex.3 \
libssh2_channel_write.3 \
libssh2_channel_write_ex.3 \
libssh2_channel_write_stderr.3 \
libssh2_channel_x11_req.3 \
libssh2_channel_x11_req_ex.3 \
libssh2_exit.3 \
libssh2_free_host_entry.3 \
libssh2_host_entry_match.3 \
libssh2_hostkey_hash.3 \
libssh2_init.3 \
libssh2_knownhost_add.3 \
libssh2_knownhost_addc.3 \
libssh2_knownhost_check.3 \
libssh2_knownhost_del.3 \
libssh2_knownhost_free.3 \
libssh2_knownhost_get.3 \
libssh2_knownhost_init.3 \
libssh2_knownhost_free.3 \
libssh2_knownhost_readfile.3 \
libssh2_knownhost_readline.3 \
libssh2_knownhost_writefile.3 \
@@ -55,22 +77,27 @@ dist_man_MANS = \
libssh2_new_host_entry.3 \
libssh2_poll.3 \
libssh2_poll_channel_read.3 \
libssh2_publickey_add.3 \
libssh2_publickey_add_ex.3 \
libssh2_publickey_init.3 \
libssh2_publickey_list_fetch.3 \
libssh2_publickey_list_free.3 \
libssh2_publickey_remove.3 \
libssh2_publickey_remove_ex.3 \
libssh2_publickey_shutdown.3 \
libssh2_scp_recv.3 \
libssh2_scp_send.3 \
libssh2_scp_send_ex.3 \
libssh2_session_abstract.3 \
libssh2_session_block_directions.3 \
libssh2_session_callback_set.3 \
libssh2_session_disconnect.3 \
libssh2_session_disconnect_ex.3 \
libssh2_session_flag.3 \
libssh2_session_free.3 \
libssh2_session_get_blocking.3 \
libssh2_session_hostkey.3 \
libssh2_session_init.3 \
libssh2_session_init_ex.3 \
libssh2_session_last_errno.3 \
libssh2_session_last_error.3 \
@@ -78,30 +105,52 @@ dist_man_MANS = \
libssh2_session_methods.3 \
libssh2_session_set_blocking.3 \
libssh2_session_startup.3 \
libssh2_sftp_close.3 \
libssh2_sftp_close_handle.3 \
libssh2_sftp_closedir.3 \
libssh2_sftp_fsetstat.3 \
libssh2_sftp_fstat.3 \
libssh2_sftp_fstat_ex.3 \
libssh2_sftp_init.3 \
libssh2_sftp_last_error.3 \
libssh2_sftp_lstat.3 \
libssh2_sftp_mkdir.3 \
libssh2_sftp_mkdir_ex.3 \
libssh2_sftp_open.3 \
libssh2_sftp_open_ex.3 \
libssh2_sftp_opendir.3 \
libssh2_sftp_read.3 \
libssh2_sftp_readdir.3 \
libssh2_sftp_readdir_ex.3 \
libssh2_sftp_readlink.3 \
libssh2_sftp_realpath.3 \
libssh2_sftp_rename.3 \
libssh2_sftp_rename_ex.3 \
libssh2_sftp_rewind.3 \
libssh2_sftp_rmdir.3 \
libssh2_sftp_rmdir_ex.3 \
libssh2_sftp_seek.3 \
libssh2_sftp_setstat.3 \
libssh2_sftp_shutdown.3 \
libssh2_sftp_stat.3 \
libssh2_sftp_stat_ex.3 \
libssh2_sftp_symlink.3 \
libssh2_sftp_symlink_ex.3 \
libssh2_sftp_tell.3 \
libssh2_sftp_tell64.3 \
libssh2_sftp_unlink.3 \
libssh2_sftp_unlink_ex.3 \
libssh2_sftp_write.3 \
libssh2_trace.3 \
libssh2_trace_sethandler.3 \
libssh2_userauth_authenticated.3 \
libssh2_userauth_hostbased_fromfile.3 \
libssh2_userauth_hostbased_fromfile_ex.3 \
libssh2_userauth_keyboard_interactive.3 \
libssh2_userauth_keyboard_interactive_ex.3 \
libssh2_userauth_list.3 \
libssh2_userauth_password.3 \
libssh2_userauth_password_ex.3 \
libssh2_userauth_publickey_fromfile.3 \
libssh2_userauth_publickey_fromfile_ex.3 \
libssh2_version.3

View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_channel_direct_tcpip 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_channel_direct_tcpip - convenience macro for \fIlibssh2_channel_direct_tcpip_ex(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_channel_direct_tcpip(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_channel_direct_tcpip_ex(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_channel_direct_tcpip_ex(3)\fP
.SH ERRORS
See \fIlibssh2_channel_direct_tcpip_ex(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_channel_direct_tcpip_ex(3)\fP

View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_channel_exec 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_channel_exec - convenience macro for \fIlibssh2_channel_process_startup(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_channel_exec(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_channel_process_startup(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_channel_process_startup(3)\fP
.SH ERRORS
See \fIlibssh2_channel_process_startup(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_channel_process_startup(3)\fP

View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_channel_flush 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_channel_flush - convenience macro for \fIlibssh2_channel_flush_ex(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_channel_flush(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_channel_flush_ex(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_channel_flush_ex(3)\fP
.SH ERRORS
See \fIlibssh2_channel_flush_ex(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_channel_flush_ex(3)\fP

View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_channel_flush_stderr 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_channel_flush_stderr - convenience macro for \fIlibssh2_channel_flush_ex(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_channel_flush_stderr(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_channel_flush_ex(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_channel_flush_ex(3)\fP
.SH ERRORS
See \fIlibssh2_channel_flush_ex(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_channel_flush_ex(3)\fP

View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_channel_forward_listen 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_channel_forward_listen - convenience macro for \fIlibssh2_channel_forward_listen_ex(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_channel_forward_listen(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_channel_forward_listen_ex(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_channel_forward_listen_ex(3)\fP
.SH ERRORS
See \fIlibssh2_channel_forward_listen_ex(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_channel_forward_listen_ex(3)\fP

View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_channel_ignore_extended_data 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_channel_ignore_extended_data - convenience macro for \fIlibssh2_channel_handle_extended_data(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_channel_ignore_extended_data(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_channel_handle_extended_data(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_channel_handle_extended_data(3)\fP
.SH ERRORS
See \fIlibssh2_channel_handle_extended_data(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_channel_handle_extended_data(3)\fP

View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_channel_open_session 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_channel_open_session - convenience macro for \fIlibssh2_channel_open_ex(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_channel_open_session(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_channel_open_ex(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_channel_open_ex(3)\fP
.SH ERRORS
See \fIlibssh2_channel_open_ex(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_channel_open_ex(3)\fP

View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_channel_read 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_channel_read - convenience macro for \fIlibssh2_channel_read_ex(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_channel_read(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_channel_read_ex(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_channel_read_ex(3)\fP
.SH ERRORS
See \fIlibssh2_channel_read_ex(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_channel_read_ex(3)\fP

View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_channel_read_stderr 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_channel_read_stderr - convenience macro for \fIlibssh2_channel_read_ex(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_channel_read_stderr(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_channel_read_ex(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_channel_read_ex(3)\fP
.SH ERRORS
See \fIlibssh2_channel_read_ex(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_channel_read_ex(3)\fP

View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_channel_request_pty 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_channel_request_pty - convenience macro for \fIlibssh2_channel_request_pty_ex(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_channel_request_pty(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_channel_request_pty_ex(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_channel_request_pty_ex(3)\fP
.SH ERRORS
See \fIlibssh2_channel_request_pty_ex(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_channel_request_pty_ex(3)\fP

View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_channel_request_pty_size 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_channel_request_pty_size - convenience macro for \fIlibssh2_channel_request_pty_size_ex(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_channel_request_pty_size(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_channel_request_pty_size_ex(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_channel_request_pty_size_ex(3)\fP
.SH ERRORS
See \fIlibssh2_channel_request_pty_size_ex(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_channel_request_pty_size_ex(3)\fP

View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_channel_setenv 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_channel_setenv - convenience macro for \fIlibssh2_channel_setenv_ex(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_channel_setenv(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_channel_setenv_ex(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_channel_setenv_ex(3)\fP
.SH ERRORS
See \fIlibssh2_channel_setenv_ex(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_channel_setenv_ex(3)\fP

View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_channel_shell 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_channel_shell - convenience macro for \fIlibssh2_channel_process_startup(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_channel_shell(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_channel_process_startup(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_channel_process_startup(3)\fP
.SH ERRORS
See \fIlibssh2_channel_process_startup(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_channel_process_startup(3)\fP

View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_channel_subsystem 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_channel_subsystem - convenience macro for \fIlibssh2_channel_process_startup(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_channel_subsystem(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_channel_process_startup(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_channel_process_startup(3)\fP
.SH ERRORS
See \fIlibssh2_channel_process_startup(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_channel_process_startup(3)\fP

View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_channel_window_read 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_channel_window_read - convenience macro for \fIlibssh2_channel_window_read_ex(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_channel_window_read(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_channel_window_read_ex(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_channel_window_read_ex(3)\fP
.SH ERRORS
See \fIlibssh2_channel_window_read_ex(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_channel_window_read_ex(3)\fP

View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_channel_window_write 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_channel_window_write - convenience macro for \fIlibssh2_channel_window_write_ex(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_channel_window_write(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_channel_window_write_ex(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_channel_window_write_ex(3)\fP
.SH ERRORS
See \fIlibssh2_channel_window_write_ex(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_channel_window_write_ex(3)\fP

View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_channel_write 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_channel_write - convenience macro for \fIlibssh2_channel_write_ex(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_channel_write(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_channel_write_ex(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_channel_write_ex(3)\fP
.SH ERRORS
See \fIlibssh2_channel_write_ex(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_channel_write_ex(3)\fP

View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_channel_write_stderr 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_channel_write_stderr - convenience macro for \fIlibssh2_channel_write_ex(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_channel_write_stderr(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_channel_write_ex(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_channel_write_ex(3)\fP
.SH ERRORS
See \fIlibssh2_channel_write_ex(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_channel_write_ex(3)\fP

View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_channel_x11_req 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_channel_x11_req - convenience macro for \fIlibssh2_channel_x11_req_ex(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_channel_x11_req(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_channel_x11_req_ex(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_channel_x11_req_ex(3)\fP
.SH ERRORS
See \fIlibssh2_channel_x11_req_ex(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_channel_x11_req_ex(3)\fP

14
docs/libssh2_exit.3 Normal file
View File

@@ -0,0 +1,14 @@
.TH libssh2_exit 3 "19 Mar 2010" "libssh2 1.2.5" "libssh2 manual"
.SH NAME
libssh2_exit - global library deinitialization
.SH SYNOPSIS
#include <libssh2.h>
int
libssh2_exit(void);
.SH DESCRIPTION
Exit the libssh2 functions and free's all memory used internal.
.SH SEE ALSO
.BR libssh2_init(3)

21
docs/libssh2_init.3 Normal file
View File

@@ -0,0 +1,21 @@
.TH libssh2_init 3 "19 Mar 2010" "libssh2 1.2.5" "libssh2 manual"
.SH NAME
libssh2_init - global library initialization
.SH SYNOPSIS
#include <libssh2.h>
#define LIBSSH2_INIT_NO_CRYPTO 0x0001
int
libssh2_init(int flags);
.SH DESCRIPTION
Initialize the libssh2 functions. This typically initialize the
crypto library. It uses a global state, and is not thread safe -- you
must make sure this function is not called concurrently.
.SH RETURN VALUE
Returns 0 if succeeded, or a negative value for error.
.SH SEE ALSO
.BR libssh2_exit(3)

View File

@@ -13,6 +13,11 @@ int libssh2_knownhost_add(LIBSSH2_KNOWNHOSTS *hosts,
int typemask,
struct libssh2_knownhost **store);
.SH DESCRIPTION
We discourage use of this function as of libssh2 1.2.5. Instead we strongly
urge users to sue \fIlibssh2_knownhost_addc(3)\fP instead, which as a more
complete API. \fIlibssh2_knownhost_add(3)\fP is subject for removal in a
future release.
Adds a known host to the collection of known hosts identified by the 'hosts'
handle.
@@ -51,8 +56,10 @@ this pointer.
Returns a regular libssh2 error code, where negative values are error codes
and 0 indicates success.
.SH AVAILABILITY
Added in libssh2 1.2
Added in libssh2 1.2, deprecated since libssh2 1.2.5. Use
\fIlibssh2_knownhost_addc(3)\fP instead!
.SH SEE ALSO
.BR libssh2_knownhost_init(3)
.BR libssh2_knownhost_free(3)
.BR libssh2_knownhost_check(3)
.BR libssh2_knownhost_addc(3)

View File

@@ -0,0 +1,63 @@
.\" Copyright (c) 2009, 2010 by Daniel Stenberg
.\"
.TH libssh2_knownhost_add 3 "28 May 2009" "libssh2 1.2" "libssh2 manual"
.SH NAME
libssh2_knownhost_add - add a known host
.SH SYNOPSIS
#include <libssh2.h>
int libssh2_knownhost_add(LIBSSH2_KNOWNHOSTS *hosts,
char *host, char *salt,
char *key, size_t keylen,
const char *comment, size_t commentlen,
int typemask,
struct libssh2_knownhost **store);
.SH DESCRIPTION
Adds a known host to the collection of known hosts identified by the 'hosts'
handle.
\fIhost\fP is a pointer the host name in plain text or hashed. If hashed, it
must be provided base64 encoded. The host name can be the IP numerical address
of the host or the full name.
\fIsalt\P is a pointer to the salt used for the host hashing, if the host is
provided hashed. If the host is provided in plain text, salt has no meaning.
The salt has to be provided base64 encoded with a trailing zero byte.
\fIkey\fP is a pointer to the key for the given host.
\fIkeylen\fP is the total size in bytes of the key pointed to by the \fIkey\fP
argument
\fIcomment\fP is a pointer to a comment for the key.
\fIcommentlen\fP is the total size in bytes of the comment pointed to by the \fIcomment\fP argument
\fItypemask\fP is a bitmask that specifies format and info about the data
passed to this function. Specificly, it details what format the host name is,
what format the key is and what key type it is.
The host name is given as one of the following types:
LIBSSH2_KNOWNHOST_TYPE_PLAIN, LIBSSH2_KNOWNHOST_TYPE_SHA1 or
LIBSSH2_KNOWNHOST_TYPE_CUSTOM.
The key is encoded using one of the following encodings:
LIBSSH2_KNOWNHOST_KEYENC_RAW or LIBSSH2_KNOWNHOST_KEYENC_BASE64.
The key is using one of these algorithms:
LIBSSH2_KNOWNHOST_KEY_RSA1, LIBSSH2_KNOWNHOST_KEY_SSHRSA or
LIBSSH2_KNOWNHOST_KEY_SSHDSS.
\fIstore\fP should point to a pointer that gets filled in to point to the
known host data after the addition. NULL can be passed if you don't care about
this pointer.
.SH RETURN VALUE
Returns a regular libssh2 error code, where negative values are error codes
and 0 indicates success.
.SH AVAILABILITY
Added in libssh2 1.2.5
.SH SEE ALSO
.BR libssh2_knownhost_init(3)
.BR libssh2_knownhost_free(3)
.BR libssh2_knownhost_check(3)

View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_publickey_add 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_publickey_add - convenience macro for \fIlibssh2_publickey_add_ex(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_publickey_add(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_publickey_add_ex(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_publickey_add_ex(3)\fP
.SH ERRORS
See \fIlibssh2_publickey_add_ex(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_publickey_add_ex(3)\fP

View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_publickey_remove 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_publickey_remove - convenience macro for \fIlibssh2_publickey_remove_ex(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_publickey_remove(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_publickey_remove_ex(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_publickey_remove_ex(3)\fP
.SH ERRORS
See \fIlibssh2_publickey_remove_ex(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_publickey_remove_ex(3)\fP

19
docs/libssh2_scp_send.3 Normal file
View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_scp_send 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_scp_send - convenience macro for \fIlibssh2_scp_send_ex(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_scp_send(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_scp_send_ex(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_scp_send_ex(3)\fP
.SH ERRORS
See \fIlibssh2_scp_send_ex(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_scp_send_ex(3)\fP

View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_session_disconnect 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_session_disconnect - convenience macro for \fIlibssh2_session_disconnect_ex(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_session_disconnect(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_session_disconnect_ex(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_session_disconnect_ex(3)\fP
.SH ERRORS
See \fIlibssh2_session_disconnect_ex(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_session_disconnect_ex(3)\fP

View File

@@ -9,7 +9,7 @@ libssh2_session_free - frees resources associated with a session instance
int
libssh2_session_free(LIBSSH2_SESSION *session);
.SH DESCRIPTION
Frees resources associated with a session instance. Typically called after
Frees all resources associated with a session instance. Typically called after
.BR libssh2_session_disconnect_ex(3)
.SH RETURN VALUE
Return 0 on success or negative on failure. It returns

View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_session_init 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_session_init - convenience macro for \fIlibssh2_session_init_ex(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_session_init(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_session_init_ex(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_session_init_ex(3)\fP
.SH ERRORS
See \fIlibssh2_session_init_ex(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_session_init_ex(3)\fP

19
docs/libssh2_sftp_close.3 Normal file
View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_sftp_close 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_sftp_close - convenience macro for \fIlibssh2_sftp_close_handle(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_sftp_close(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_sftp_close_handle(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_sftp_close_handle(3)\fP
.SH ERRORS
See \fIlibssh2_sftp_close_handle(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_sftp_close_handle(3)\fP

View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_sftp_closedir 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_sftp_closedir - convenience macro for \fIlibssh2_sftp_close_handle(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_sftp_closedir(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_sftp_close_handle(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_sftp_close_handle(3)\fP
.SH ERRORS
See \fIlibssh2_sftp_close_handle(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_sftp_close_handle(3)\fP

View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_sftp_fsetstat 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_sftp_fsetstat - convenience macro for \fIlibssh2_sftp_fstat_ex(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_sftp_fsetstat(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_sftp_fstat_ex(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_sftp_fstat_ex(3)\fP
.SH ERRORS
See \fIlibssh2_sftp_fstat_ex(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_sftp_fstat_ex(3)\fP

19
docs/libssh2_sftp_fstat.3 Normal file
View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_sftp_fstat 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_sftp_fstat - convenience macro for \fIlibssh2_sftp_fstat_ex(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_sftp_fstat(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_sftp_fstat_ex(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_sftp_fstat_ex(3)\fP
.SH ERRORS
See \fIlibssh2_sftp_fstat_ex(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_sftp_fstat_ex(3)\fP

View File

@@ -2,32 +2,88 @@
.\"
.TH libssh2_sftp_fstat_ex 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual"
.SH NAME
libssh2_sftp_fstat_ex - get or set attributes on a file handle
libssh2_sftp_fstat_ex - get or set attributes on an SFTP file handle
.SH SYNOPSIS
.nf
#include <libssh2.h>
#include <libssh2_sftp.h>
int
libssh2_sftp_fstat_ex(LIBSSH2_SFTP_HANDLE *handle, LIBSSH2_SFTP_ATTRIBUTES *attrs, int setstat)
int
libssh2_sftp_fstat(LIBSSH2_SFTP_HANDLE *handle, LIBSSH2_SFTP_ATTRIBUTES *attrs)
int
libssh2_sftp_fsetstat(LIBSSH2_SFTP_HANDLE *handle, LIBSSH2_SFTP_ATTRIBUTES *attrs)
libssh2_sftp_fstat_ex(LIBSSH2_SFTP_HANDLE *handle,
LIBSSH2_SFTP_ATTRIBUTES *attrs, int setstat)
#define libbssh2_sftp_fstat(handle, attrs) \\
libssh2_sftp_fstat_ex((handle), (attrs), 0)
#define libssh2_sftp_fsetstat(handle, attrs) \\
libssh2_sftp_fstat_ex((handle), (attrs), 1)
.fi
.SH DESCRIPTION
\fIhandle\fP - SFTP File Handle as returned by
.BR libssh2_sftp_open_ex(3)
\fIattrs\fP - Pointer to attribute structure to set file metadata
from or into depending on the value of setstat.
\fIattrs\fP - Pointer to an LIBSSH2_SFTP_ATTRIBUTES structure to set file
metadata from or into depending on the value of setstat.
\fIsetstat\fP - When non-zero, the file's metadata will be updated
with the data found in attrs according to the values of attrs->flags
and other relevant member attributes.
Get or Set statbuf type data for a given LIBSSH2_SFTP_HANDLE instance.
.SH DATA TYPES
LIBSSH2_SFTP_ATTRIBUTES is a typedefed struct that is defined as below
.nf
struct _LIBSSH2_SFTP_ATTRIBUTES {
/* If flags & ATTR_* bit is set, then the value in this
* struct will be meaningful Otherwise it should be ignored
*/
unsigned long flags;
/* size of file, in bytes */
libssh2_uint64_t filesize;
/* numerical representation of the user and group owner of
* the file
*/
unsigned long uid, gid;
/* bitmask of permissions */
unsigned long permissions;
/* access time and modified time of file */
unsigned long atime, mtime;
};
.fi
You will find a full set of defines and macros to identify flags and
permissions on the \fBlibssh2_sftp.h\fP header file, but some of the
most common ones are:
To check for specific user permissons, the set of defines are in the
pattern LIBSSH2_SFTP_S_I<action><who> where <action> is R, W or X for
read, write and excutable and <who> is USR, GRP and OTH for user,
group and other. So, you check for a user readable file, use the bit
\fILIBSSH2_SFTP_S_IRUSR\fP while you want to see if it is executable
for other, you use \fILIBSSH2_SFTP_S_IXOTH\fP and so on.
To check for specific file types, you would previously (before libssh2
1.2.5) use the standard posix S_IS***() macros, but since 1.2.5
libssh2 offers its own set of macros for this functionality:
.IP LIBSSH2_SFTP_S_ISLNK
Test for a symbolic link
.IP LIBSSH2_SFTP_S_ISREG
Test for a regular file
.IP LIBSSH2_SFTP_S_ISDIR
Test for a directory
.IP LIBSSH2_SFTP_S_ISCHR
Test for a character special file
.IP LIBSSH2_SFTP_S_ISBLK
Test for a block special file
.IP LIBSSH2_SFTP_S_ISFIFO
Test for a pipe or FIFO special file
.IP LIBSSH2_SFTP_S_ISSOCK
Test for a socket
.SH RETURN VALUE
Return 0 on success or negative on failure. It returns
LIBSSH2_ERROR_EAGAIN when it would otherwise block. While
@@ -42,5 +98,9 @@ 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
received on the socket, or an SFTP operation caused an errorcode to
be returned by the server.
.SH AVAILABILITY
This function has been around since forever, but most of the
LIBSSH2_SFTP_S_* defines were introduced in libssh2 0.14 and the
LIBSSH2_SFTP_S_IS***() macros were introduced in libssh2 1.2.5.
.SH SEE ALSO
.BR libssh2_sftp_open_ex(3)

19
docs/libssh2_sftp_lstat.3 Normal file
View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_sftp_lstat 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_sftp_lstat - convenience macro for \fIlibssh2_sftp_stat_ex(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_sftp_lstat(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_sftp_stat_ex(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_sftp_stat_ex(3)\fP
.SH ERRORS
See \fIlibssh2_sftp_stat_ex(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_sftp_stat_ex(3)\fP

19
docs/libssh2_sftp_mkdir.3 Normal file
View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_sftp_mkdir 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_sftp_mkdir - convenience macro for \fIlibssh2_sftp_mkdir_ex(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_sftp_mkdir(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_sftp_mkdir_ex(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_sftp_mkdir_ex(3)\fP
.SH ERRORS
See \fIlibssh2_sftp_mkdir_ex(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_sftp_mkdir_ex(3)\fP

19
docs/libssh2_sftp_open.3 Normal file
View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_sftp_open 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_sftp_open - convenience macro for \fIlibssh2_sftp_open_ex(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_sftp_open(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_sftp_open_ex(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_sftp_open_ex(3)\fP
.SH ERRORS
See \fIlibssh2_sftp_open_ex(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_sftp_open_ex(3)\fP

View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_sftp_opendir 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_sftp_opendir - convenience macro for \fIlibssh2_sftp_open_ex(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_sftp_opendir(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_sftp_open_ex(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_sftp_open_ex(3)\fP
.SH ERRORS
See \fIlibssh2_sftp_open_ex(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_sftp_open_ex(3)\fP

View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_sftp_readdir 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_sftp_readdir - convenience macro for \fIlibssh2_sftp_readdir_exa(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_sftp_readdir(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_sftp_readdir_exa(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_sftp_readdir_exa(3)\fP
.SH ERRORS
See \fIlibssh2_sftp_readdir_exa(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_sftp_readdir_exa(3)\fP

View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_sftp_readlink 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_sftp_readlink - convenience macro for \fIlibssh2_sftp_symlink_ex(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_sftp_readlink(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_sftp_symlink_ex(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_sftp_symlink_ex(3)\fP
.SH ERRORS
See \fIlibssh2_sftp_symlink_ex(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_sftp_symlink_ex(3)\fP

View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_sftp_realpath 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_sftp_realpath - convenience macro for \fIlibssh2_sftp_symlink_ex(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_sftp_realpath(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_sftp_symlink_ex(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_sftp_symlink_ex(3)\fP
.SH ERRORS
See \fIlibssh2_sftp_symlink_ex(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_sftp_symlink_ex(3)\fP

View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_sftp_rename 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_sftp_rename - convenience macro for \fIlibssh2_sftp_rename_ex(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_sftp_rename(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_sftp_rename_ex(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_sftp_rename_ex(3)\fP
.SH ERRORS
See \fIlibssh2_sftp_rename_ex(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_sftp_rename_ex(3)\fP

View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_sftp_rewind 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_sftp_rewind - convenience macro for \fIlibssh2_sftp_seek64(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_sftp_rewind(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_sftp_seek64(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_sftp_seek64(3)\fP
.SH ERRORS
See \fIlibssh2_sftp_seek64(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_sftp_seek64(3)\fP

19
docs/libssh2_sftp_rmdir.3 Normal file
View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_sftp_rmdir 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_sftp_rmdir - convenience macro for \fIlibssh2_sftp_rmdir_ex(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_sftp_rmdir(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_sftp_rmdir_ex(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_sftp_rmdir_ex(3)\fP
.SH ERRORS
See \fIlibssh2_sftp_rmdir_ex(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_sftp_rmdir_ex(3)\fP

View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_sftp_setstat 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_sftp_setstat - convenience macro for \fIlibssh2_sftp_stat_ex(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_sftp_setstat(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_sftp_stat_ex(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_sftp_stat_ex(3)\fP
.SH ERRORS
See \fIlibssh2_sftp_stat_ex(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_sftp_stat_ex(3)\fP

19
docs/libssh2_sftp_stat.3 Normal file
View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_sftp_stat 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_sftp_stat - convenience macro for \fIlibssh2_sftp_fstat_ex(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_sftp_stat(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_sftp_fstat_ex(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_sftp_fstat_ex(3)\fP
.SH ERRORS
See \fIlibssh2_sftp_fstat_ex(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_sftp_fstat_ex(3)\fP

View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_sftp_symlink 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_sftp_symlink - convenience macro for \fIlibssh2_sftp_symlink_ex(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_sftp_symlink(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_sftp_symlink_ex(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_sftp_symlink_ex(3)\fP
.SH ERRORS
See \fIlibssh2_sftp_symlink_ex(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_sftp_symlink_ex(3)\fP

View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_sftp_unlink 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_sftp_unlink - convenience macro for \fIlibssh2_sftp_unlink_ex(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_sftp_unlink(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_sftp_unlink_ex(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_sftp_unlink_ex(3)\fP
.SH ERRORS
See \fIlibssh2_sftp_unlink_ex(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_sftp_unlink_ex(3)\fP

View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_userauth_hostbased_fromfile 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_userauth_hostbased_fromfile - convenience macro for \fIlibssh2_userauth_hostbased_fromfile_ex(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_userauth_hostbased_fromfile(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_userauth_hostbased_fromfile_ex(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_userauth_hostbased_fromfile_ex(3)\fP
.SH ERRORS
See \fIlibssh2_userauth_hostbased_fromfile_ex(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_userauth_hostbased_fromfile_ex(3)\fP

View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_userauth_keyboard_interactive 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_userauth_keyboard_interactive - convenience macro for \fIlibssh2_userauth_keyboard_interactive_ex(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_userauth_keyboard_interactive(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_userauth_keyboard_interactive_ex(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_userauth_keyboard_interactive_ex(3)\fP
.SH ERRORS
See \fIlibssh2_userauth_keyboard_interactive_ex(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_userauth_keyboard_interactive_ex(3)\fP

View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_userauth_password 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_userauth_password - convenience macro for \fIlibssh2_userauth_password_ex(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_userauth_password(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_userauth_password_ex(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_userauth_password_ex(3)\fP
.SH ERRORS
See \fIlibssh2_userauth_password_ex(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_userauth_password_ex(3)\fP

View File

@@ -0,0 +1,19 @@
.\" $Id: template.3,v 1.4 2007/06/13 16:41:33 jehousley Exp $
.\"
.TH libssh2_userauth_publickey_fromfile 3 "20 Feb 2010" "libssh2 1.2.4" "libssh2 manual"
.SH NAME
libssh2_userauth_publickey_fromfile - convenience macro for \fIlibssh2_userauth_publickey_fromfile_ex(3)\fP calls
.SH SYNOPSIS
#include <libssh2.h>
libssh2_userauth_publickey_fromfile(arguments)
.SH DESCRIPTION
This is a macro defined in a public libssh2 header file that is using the
underlying function \fIlibssh2_userauth_publickey_fromfile_ex(3)\fP.
.SH RETURN VALUE
See \fIlibssh2_userauth_publickey_fromfile_ex(3)\fP
.SH ERRORS
See \fIlibssh2_userauth_publickey_fromfile_ex(3)\fP
.SH SEE ALSO
.BR \fIlibssh2_userauth_publickey_fromfile_ex(3)\fP

View File

@@ -18,6 +18,10 @@
#include <unistd.h>
#include <sys/types.h>
#ifndef INADDR_NONE
#define INADDR_NONE (in_addr_t)-1
#endif
const char *keyfile1 = "/home/username/.ssh/id_rsa.pub";
const char *keyfile2 = "/home/username/.ssh/id_rsa";
const char *username = "username";
@@ -77,6 +81,12 @@ int main(int argc, char *argv[])
if (argc > 7)
remote_destport = atoi(argv[7]);
rc = libssh2_init (0);
if (rc != 0) {
fprintf (stderr, "libssh2 initialization failed (%d)\n", rc);
return 1;
}
/* Connect to SSH server */
sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
sin.sin_family = AF_INET;
@@ -267,5 +277,8 @@ shutdown:
#else
close(sock);
#endif
libssh2_exit();
return 0;
}

View File

@@ -68,6 +68,12 @@ int main(int argc, char *argv[])
scppath = argv[4];
}
rc = libssh2_init (0);
if (rc != 0) {
fprintf (stderr, "libssh2 initialization failed (%d)\n", rc);
return 1;
}
/* Ultra basic "connect to port 22 on localhost"
* Your code is responsible for creating the socket establishing the
* connection
@@ -169,5 +175,8 @@ int main(int argc, char *argv[])
close(sock);
#endif
fprintf(stderr, "all done\n");
libssh2_exit();
return 0;
}

View File

@@ -121,6 +121,12 @@ int main(int argc, char *argv[])
scppath = argv[4];
}
rc = libssh2_init (0);
if (rc != 0) {
fprintf (stderr, "libssh2 initialization failed (%d)\n", rc);
return 1;
}
/* Ultra basic "connect to port 22 on localhost"
* Your code is responsible for creating the socket establishing the
* connection
@@ -267,5 +273,8 @@ shutdown:
close(sock);
#endif
fprintf(stderr, "all done\n");
libssh2_exit();
return 0;
}

View File

@@ -38,7 +38,7 @@ int main(int argc, char *argv[])
int sock, i, auth_pw = 1;
struct sockaddr_in sin;
const char *fingerprint;
LIBSSH2_SESSION *session;
LIBSSH2_SESSION *session = NULL;
LIBSSH2_CHANNEL *channel;
const char *username="username";
const char *password="password";
@@ -75,9 +75,15 @@ int main(int argc, char *argv[])
scppath = argv[5];
}
rc = libssh2_init (0);
if (rc != 0) {
fprintf (stderr, "libssh2 initialization failed (%d)\n", rc);
return 1;
}
local = fopen(loclfile, "rb");
if (!local) {
fprintf(stderr, "Can't local file %s\n", loclfile);
fprintf(stderr, "Can't open local file %s\n", loclfile);
goto shutdown;
}
@@ -147,7 +153,10 @@ int main(int argc, char *argv[])
(unsigned long)fileinfo.st_size);
if (!channel) {
fprintf(stderr, "Unable to open a session\n");
char *errmsg;
int errlen;
int err = libssh2_session_last_error(session, &errmsg, &errlen, 0);
fprintf(stderr, "Unable to open a session: (%d) %s\n", err, errmsg);
goto shutdown;
}
@@ -189,14 +198,20 @@ int main(int argc, char *argv[])
shutdown:
libssh2_session_disconnect(session, "Normal Shutdown, Thank you for playing");
libssh2_session_free(session);
if(session) {
libssh2_session_disconnect(session, "Normal Shutdown, Thank you for playing");
libssh2_session_free(session);
}
#ifdef WIN32
closesocket(sock);
#else
close(sock);
#endif
if (local)
fclose(local);
fprintf(stderr, "all done\n");
libssh2_exit();
return 0;
}

View File

@@ -79,6 +79,12 @@ int main(int argc, char *argv[])
scppath = argv[5];
}
rc = libssh2_init (0);
if (rc != 0) {
fprintf (stderr, "libssh2 initialization failed (%d)\n", rc);
return 1;
}
local = fopen(loclfile, "rb");
if (!local) {
fprintf(stderr, "Can't local file %s\n", loclfile);
@@ -218,5 +224,8 @@ int main(int argc, char *argv[])
close(sock);
#endif
fprintf(stderr, "all done\n");
libssh2_exit();
return 0;
}

View File

@@ -98,6 +98,13 @@ int main(int argc, char *argv[])
if(argc > 4) {
sftppath = argv[4];
}
rc = libssh2_init (0);
if (rc != 0) {
fprintf (stderr, "libssh2 initialization failed (%d)\n", rc);
return 1;
}
/*
* The application code is responsible for creating the socket
* and establishing the connection
@@ -241,5 +248,8 @@ int main(int argc, char *argv[])
close(sock);
#endif
fprintf(stderr, "all done\n");
libssh2_exit();
return 0;
}

View File

@@ -72,6 +72,12 @@ int main(int argc, char *argv[])
WSAStartup(MAKEWORD(2,0), &wsadata);
#endif
rc = libssh2_init (0);
if (rc != 0) {
fprintf (stderr, "libssh2 initialization failed (%d)\n", rc);
return 1;
}
/* Ultra basic "connect to port 22 on localhost"
* The application is responsible for creating the socket establishing
* the connection
@@ -283,6 +289,11 @@ int main(int argc, char *argv[])
#else
close(sock);
#endif
if (tempstorage)
fclose(tempstorage);
printf("all done\n");
libssh2_exit();
return 0;
}

View File

@@ -70,6 +70,12 @@ int main(int argc, char *argv[])
sftppath = argv[4];
}
rc = libssh2_init (0);
if (rc != 0) {
fprintf (stderr, "libssh2 initialization failed (%d)\n", rc);
return 1;
}
/*
* The application code is responsible for creating the socket
* and establishing the connection
@@ -159,6 +165,9 @@ int main(int argc, char *argv[])
#else
close(sock);
#endif
printf("all done\n");
printf("all done\n");
libssh2_exit();
return 0;
}

View File

@@ -73,6 +73,12 @@ int main(int argc, char *argv[])
sftppath = argv[4];
}
rc = libssh2_init (0);
if (rc != 0) {
fprintf (stderr, "libssh2 initialization failed (%d)\n", rc);
return 1;
}
/*
* The application code is responsible for creating the socket
* and establishing the connection
@@ -165,6 +171,9 @@ int main(int argc, char *argv[])
#else
close(sock);
#endif
printf("all done\n");
printf("all done\n");
libssh2_exit();
return 0;
}

View File

@@ -121,6 +121,13 @@ int main(int argc, char *argv[])
if (argc > 4) {
sftppath = argv[4];
}
rc = libssh2_init (0);
if (rc != 0) {
fprintf (stderr, "libssh2 initialization failed (%d)\n", rc);
return 1;
}
/*
* The application code is responsible for creating the socket
* and establishing the connection
@@ -269,5 +276,8 @@ shutdown:
close(sock);
#endif
fprintf(stderr, "all done\n");
libssh2_exit();
return 0;
}

View File

@@ -79,6 +79,12 @@ int main(int argc, char *argv[])
sftppath = argv[5];
}
rc = libssh2_init (0);
if (rc != 0) {
fprintf (stderr, "libssh2 initialization failed (%d)\n", rc);
return 1;
}
local = fopen(loclfile, "rb");
if (!local) {
printf("Can't local file %s\n", loclfile);
@@ -184,12 +190,10 @@ int main(int argc, char *argv[])
} while (rc > 0);
} while (1);
fclose(local);
libssh2_sftp_close(sftp_handle);
libssh2_sftp_shutdown(sftp_session);
shutdown:
shutdown:
libssh2_session_disconnect(session,
"Normal Shutdown, Thank you for playing");
libssh2_session_free(session);
@@ -199,6 +203,11 @@ int main(int argc, char *argv[])
#else
close(sock);
#endif
printf("all done\n");
if (local)
fclose(local);
printf("all done\n");
libssh2_exit();
return 0;
}

View File

@@ -82,6 +82,12 @@ int main(int argc, char *argv[])
sftppath = argv[5];
}
rc = libssh2_init (0);
if (rc != 0) {
fprintf (stderr, "libssh2 initialization failed (%d)\n", rc);
return 1;
}
local = fopen(loclfile, "rb");
if (!local) {
printf("Can't local file %s\n", loclfile);
@@ -212,5 +218,8 @@ shutdown:
close(sock);
#endif
printf("all done\n");
libssh2_exit();
return 0;
}

View File

@@ -70,6 +70,13 @@ int main(int argc, char *argv[])
if(argc > 4) {
sftppath = argv[4];
}
rc = libssh2_init (0);
if (rc != 0) {
fprintf (stderr, "libssh2 initialization failed (%d)\n", rc);
return 1;
}
/*
* The application code is responsible for creating the socket
* and establishing the connection
@@ -211,6 +218,9 @@ int main(int argc, char *argv[])
#else
close(sock);
#endif
printf("all done\n");
printf("all done\n");
libssh2_exit();
return 0;
}

View File

@@ -73,6 +73,13 @@ int main(int argc, char *argv[])
if(argc > 4) {
sftppath = argv[4];
}
rc = libssh2_init (0);
if (rc != 0) {
fprintf (stderr, "libssh2 initialization failed (%d)\n", rc);
return 1;
}
/*
* The application code is responsible for creating the socket
* and establishing the connection
@@ -224,5 +231,8 @@ int main(int argc, char *argv[])
close(sock);
#endif
printf("all done\n");
libssh2_exit();
return 0;
}

View File

@@ -68,7 +68,7 @@ static void kbd_callback(const char *name, int name_len,
int main(int argc, char *argv[])
{
unsigned long hostaddr;
int sock, i, auth_pw = 0;
int rc, sock, i, auth_pw = 0;
struct sockaddr_in sin;
const char *fingerprint;
char *userauthlist;
@@ -93,6 +93,12 @@ int main(int argc, char *argv[])
password = argv[3];
}
rc = libssh2_init (0);
if (rc != 0) {
fprintf (stderr, "libssh2 initialization failed (%d)\n", rc);
return 1;
}
/* Ultra basic "connect to port 22 on localhost". Your code is
* responsible for creating the socket establishing the connection
*/
@@ -247,5 +253,8 @@ int main(int argc, char *argv[])
close(sock);
#endif
printf("all done!\n");
libssh2_exit();
return 0;
}

View File

@@ -65,6 +65,12 @@ int main(int argc, char *argv[])
username = argv[2];
}
rc = libssh2_init (0);
if (rc != 0) {
fprintf (stderr, "libssh2 initialization failed (%d)\n", rc);
return 1;
}
/* Ultra basic "connect to port 22 on localhost". Your code is
* responsible for creating the socket establishing the connection
*/
@@ -225,5 +231,8 @@ int main(int argc, char *argv[])
}
printf("all done!\n");
libssh2_exit();
return rc;
}

View File

@@ -109,6 +109,12 @@ int main(int argc, char *argv[])
commandline = argv[4];
}
rc = libssh2_init (0);
if (rc != 0) {
fprintf (stderr, "libssh2 initialization failed (%d)\n", rc);
return 1;
}
hostaddr = inet_addr(hostname);
/* Ultra basic "connect to port 22 on localhost"
@@ -289,6 +295,8 @@ shutdown:
close(sock);
#endif
fprintf(stderr, "all done\n");
libssh2_exit();
return 0;
}

View File

@@ -121,11 +121,16 @@ static void x11_callback(LIBSSH2_SESSION *session, LIBSSH2_CHANNEL *channel,
/* Connect to the local unix domain */
ptr = strrchr(display, ':');
temp_buff = (char *) calloc(strlen(ptr+1), sizeof(char));
if (!temp_buff) {
perror("calloc");
return;
}
memcpy(temp_buff, ptr+1, strlen(ptr+1));
display_port = atoi(temp_buff);
free(temp_buff);
sock = socket(AF_UNIX,SOCK_STREAM, 0);
if (sock <0)
sock = socket(AF_UNIX, SOCK_STREAM, 0);
if (sock < 0)
return;
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
@@ -272,6 +277,12 @@ main (int argc, char *argv[])
fprintf (stderr, "DEBUG is ON: %d\n", set_debug_on);
}
rc = libssh2_init (0);
if (rc != 0) {
fprintf (stderr, "libssh2 initialization failed (%d)\n", rc);
return 1;
}
sock = socket (AF_INET, SOCK_STREAM, 0);
sin.sin_family = AF_INET;
@@ -429,5 +440,8 @@ main (int argc, char *argv[])
channel = NULL;
}
_normal_mode();
libssh2_exit();
return 0;
}

View File

@@ -1,5 +1,6 @@
/* Copyright (c) 2004-2009, Sara Golemon <sarag@libssh2.org>
* Copyright (c) 2009 by Daniel Stenberg
* Copyright (c) 2010 Simon Josefsson <simon@josefsson.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms,
@@ -88,13 +89,13 @@ typedef long long libssh2_int64_t;
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.2_DEV"
#define LIBSSH2_VERSION "1.2.5_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 2
#define LIBSSH2_VERSION_PATCH 5
/* This is the numeric version of the libssh2 version number, meant for easier
parsing and comparions by programs. The LIBSSH2_VERSION_NUM define will
@@ -111,7 +112,7 @@ typedef long long libssh2_int64_t;
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 0x010202
#define LIBSSH2_VERSION_NUM 0x010205
/*
* This is the date and time when the full source package was created. The
@@ -368,6 +369,32 @@ typedef struct _LIBSSH2_POLLFD {
#define LIBSSH2_ERROR_OUT_OF_BOUNDARY -41
#define LIBSSH2_ERROR_AGENT_PROTOCOL -42
/* Global API */
#define LIBSSH2_INIT_NO_CRYPTO 0x0001
/*
* libssh2_init()
*
* Initialize the libssh2 functions. This typically initialize the
* crypto library. It uses a global state, and is not thread safe --
* you must make sure this function is not called concurrently.
*
* Flags can be:
* 0: Normal initialize
* LIBSSH2_INIT_NO_CRYPTO: Do not initialize the crypto library (ie.
* OPENSSL_add_cipher_algoritms() for OpenSSL
*
* Returns 0 if succeeded, or a negative value for error.
*/
LIBSSH2_API int libssh2_init(int flags);
/*
* libssh2_exit()
*
* Exit the libssh2 functions and free's all memory used internal.
*/
LIBSSH2_API void libssh2_exit(void);
/* Session API */
LIBSSH2_API LIBSSH2_SESSION *
libssh2_session_init_ex(LIBSSH2_ALLOC_FUNC((*my_alloc)),
@@ -718,7 +745,7 @@ libssh2_knownhost_init(LIBSSH2_SESSION *session);
*
* Add a host and its associated key to the collection of known hosts.
*
* The 'type' argument specifies on what format the given host is:
* The 'type' argument specifies on what format the given host and keys are:
*
* plain - ascii "hostname.domain.tld"
* sha1 - SHA1(<salt> <host>) base64-encoded!
@@ -731,6 +758,8 @@ libssh2_knownhost_init(LIBSSH2_SESSION *session);
* a custom type is used, salt is ignored and you must provide the host
* pre-hashed when checking for it in the libssh2_knownhost_check() function.
*
* The keylen parameter may be omitted (zero) if the key is provided as a
* NULL-terminated base64-encoded string.
*/
/* host format (2 bits) */
@@ -758,6 +787,41 @@ libssh2_knownhost_add(LIBSSH2_KNOWNHOSTS *hosts,
const char *key, size_t keylen, int typemask,
struct libssh2_knownhost **store);
/*
* libssh2_knownhost_addc
*
* Add a host and its associated key to the collection of known hosts.
*
* Takes a comment argument that may be NULL. A NULL comment indicates
* there is no comment and the entry will end directly after the key
* when written out to a file. An empty string "" comment will indicate an
* empty comment which will cause a single space to be written after the key.
*
* The 'type' argument specifies on what format the given host and keys are:
*
* plain - ascii "hostname.domain.tld"
* sha1 - SHA1(<salt> <host>) base64-encoded!
* custom - another hash
*
* If 'sha1' is selected as type, the salt must be provided to the salt
* argument. This too base64 encoded.
*
* The SHA-1 hash is what OpenSSH can be told to use in known_hosts files. If
* a custom type is used, salt is ignored and you must provide the host
* pre-hashed when checking for it in the libssh2_knownhost_check() function.
*
* The keylen parameter may be omitted (zero) if the key is provided as a
* NULL-terminated base64-encoded string.
*/
LIBSSH2_API int
libssh2_knownhost_addc(LIBSSH2_KNOWNHOSTS *hosts,
const char *host,
const char *salt,
const char *key, size_t keylen,
const char *comment, size_t commentlen, int typemask,
struct libssh2_knownhost **store);
/*
* libssh2_knownhost_check
*
@@ -939,8 +1003,8 @@ libssh2_agent_list_identities(LIBSSH2_AGENT *agent);
*/
LIBSSH2_API int
libssh2_agent_get_identity(LIBSSH2_AGENT *agent,
struct libssh2_agent_publickey **store,
struct libssh2_agent_publickey *prev);
struct libssh2_agent_publickey **store,
struct libssh2_agent_publickey *prev);
/*
* libssh2_agent_userauth()
@@ -951,8 +1015,8 @@ libssh2_agent_get_identity(LIBSSH2_AGENT *agent,
*/
LIBSSH2_API int
libssh2_agent_userauth(LIBSSH2_AGENT *agent,
const char *username,
struct libssh2_agent_publickey *identity);
const char *username,
struct libssh2_agent_publickey *identity);
/*
* libssh2_agent_disconnect()
@@ -973,6 +1037,35 @@ libssh2_agent_disconnect(LIBSSH2_AGENT *agent);
LIBSSH2_API void
libssh2_agent_free(LIBSSH2_AGENT *agent);
/*
* libssh2_keepalive_config()
*
* Set how often keepalive messages should be sent. WANT_REPLY
* indicates whether the keepalive messages should request a response
* from the server. INTERVAL is number of seconds that can pass
* without any I/O, use 0 (the default) to disable keepalives. To
* avoid some busy-loop corner-cases, if you specify an interval of 1
* it will be treated as 2.
*
* Note that non-blocking applications are responsible for sending the
* keepalive messages using libssh2_keepalive_send().
*/
LIBSSH2_API void libssh2_keepalive_config (LIBSSH2_SESSION *session,
int want_reply,
unsigned interval);
/*
* libssh2_keepalive_send()
*
* Send a keepalive message if needed. SECONDS_TO_NEXT indicates how
* many seconds you can sleep after this call before you need to call
* it again. Returns 0 on success, or LIBSSH2_ERROR_SOCKET_SEND on
* I/O errors.
*/
LIBSSH2_API int libssh2_keepalive_send (LIBSSH2_SESSION *session,
int *seconds_to_next);
/* NOTE NOTE NOTE
libssh2_trace() has no function in builds that aren't built with debug
enabled

View File

@@ -142,6 +142,22 @@ struct _LIBSSH2_SFTP_ATTRIBUTES {
#define LIBSSH2_SFTP_S_IWOTH 0000002 /* W for other */
#define LIBSSH2_SFTP_S_IXOTH 0000001 /* X for other */
/* macros to check for specific file types, added in 1.2.5 */
#define LIBSSH2_SFTP_S_ISLNK(m) \
(((m) & LIBSSH2_SFTP_S_IFMT) == LIBSSH2_SFTP_S_IFLNK)
#define LIBSSH2_SFTP_S_ISREG(m) \
(((m) & LIBSSH2_SFTP_S_IFMT) == LIBSSH2_SFTP_S_IFREG)
#define LIBSSH2_SFTP_S_ISDIR(m) \
(((m) & LIBSSH2_SFTP_S_IFMT) == LIBSSH2_SFTP_S_IFDIR)
#define LIBSSH2_SFTP_S_ISCHR(m) \
(((m) & LIBSSH2_SFTP_S_IFMT) == LIBSSH2_SFTP_S_IFCHR)
#define LIBSSH2_SFTP_S_ISBLK(m) \
(((m) & LIBSSH2_SFTP_S_IFMT) == LIBSSH2_SFTP_S_IFBLK)
#define LIBSSH2_SFTP_S_ISFIFO(m) \
(((m) & LIBSSH2_SFTP_S_IFMT) == LIBSSH2_SFTP_S_IFIFO)
#define LIBSSH2_SFTP_S_ISSOCK(m) \
(((m) & LIBSSH2_SFTP_S_IFMT) == LIBSSH2_SFTP_S_IFSOCK)
/* SFTP File Transfer Flags -- (e.g. flags parameter to sftp_open())
* Danger will robinson... APPEND doesn't have any effect on OpenSSH servers */
#define LIBSSH2_FXF_READ 0x00000001

View File

@@ -142,7 +142,7 @@ static int
agent_connect_unix(LIBSSH2_AGENT *agent)
{
const char *path;
struct sockaddr_un sun;
struct sockaddr_un s_un;
path = getenv("SSH_AUTH_SOCK");
if (!path) {
@@ -154,9 +154,9 @@ agent_connect_unix(LIBSSH2_AGENT *agent)
return -1;
}
sun.sun_family = AF_UNIX;
strncpy (sun.sun_path, path, sizeof sun.sun_path);
if (connect(agent->fd, (struct sockaddr*)(&sun), sizeof sun) != 0) {
s_un.sun_family = AF_UNIX;
strncpy (s_un.sun_path, path, sizeof s_un.sun_path);
if (connect(agent->fd, (struct sockaddr*)(&s_un), sizeof s_un) != 0) {
close (agent->fd);
return -1;
}
@@ -337,7 +337,7 @@ static struct {
#ifdef PF_UNIX
{"Unix", &agent_ops_unix},
#endif /* PF_UNIX */
{NULL}
{NULL, NULL}
};
static int
@@ -619,7 +619,7 @@ libssh2_agent_init(LIBSSH2_SESSION *session)
agent = LIBSSH2_ALLOC(session, sizeof *agent);
if (!agent) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate space for agent connection", 0);
"Unable to allocate space for agent connection");
return NULL;
}
memset(agent, 0, sizeof *agent);

View File

@@ -156,7 +156,7 @@ _libssh2_channel_open(LIBSSH2_SESSION * session, const char *channel_type,
LIBSSH2_ALLOC(session, sizeof(LIBSSH2_CHANNEL));
if (!session->open_channel) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate space for channel data", 0);
"Unable to allocate space for channel data");
return NULL;
}
memset(session->open_channel, 0, sizeof(LIBSSH2_CHANNEL));
@@ -166,7 +166,7 @@ _libssh2_channel_open(LIBSSH2_SESSION * session, const char *channel_type,
LIBSSH2_ALLOC(session, channel_type_len);
if (!session->open_channel->channel_type) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Failed allocating memory for channel type name", 0);
"Failed allocating memory for channel type name");
LIBSSH2_FREE(session, session->open_channel);
session->open_channel = NULL;
return NULL;
@@ -188,7 +188,7 @@ _libssh2_channel_open(LIBSSH2_SESSION * session, const char *channel_type,
LIBSSH2_ALLOC(session, session->open_packet_len);
if (!session->open_packet) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate temporary space for packet", 0);
"Unable to allocate temporary space for packet");
goto channel_error;
}
*(s++) = SSH_MSG_CHANNEL_OPEN;
@@ -220,11 +220,11 @@ _libssh2_channel_open(LIBSSH2_SESSION * session, const char *channel_type,
session->open_packet_len);
if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block sending channel-open request", 0);
"Would block sending channel-open request");
return NULL;
} else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send channel-open request", 0);
"Unable to send channel-open request");
goto channel_error;
}
@@ -239,7 +239,7 @@ _libssh2_channel_open(LIBSSH2_SESSION * session, const char *channel_type,
channel_type_len, 4,
&session->open_packet_requirev_state);
if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block", 0);
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block");
return NULL;
} else if (rc) {
goto channel_error;
@@ -274,7 +274,7 @@ _libssh2_channel_open(LIBSSH2_SESSION * session, const char *channel_type,
if (session->open_data[0] == SSH_MSG_CHANNEL_OPEN_FAILURE) {
libssh2_error(session, LIBSSH2_ERROR_CHANNEL_FAILURE,
"Channel open failure", 0);
"Channel open failure");
}
}
@@ -369,8 +369,7 @@ channel_direct_tcpip(LIBSSH2_SESSION * session, const char *host,
LIBSSH2_ALLOC(session, session->direct_message_len);
if (!session->direct_message) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for direct-tcpip connection",
0);
"Unable to allocate memory for direct-tcpip connection");
return NULL;
}
_libssh2_htonu32(s, session->direct_host_len);
@@ -463,7 +462,7 @@ channel_forward_listen(LIBSSH2_SESSION * session, const char *host,
LIBSSH2_ALLOC(session, session->fwdLstn_packet_len);
if (!session->fwdLstn_packet) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memeory for setenv packet", 0);
"Unable to allocate memeory for setenv packet");
return NULL;
}
@@ -490,14 +489,12 @@ channel_forward_listen(LIBSSH2_SESSION * session, const char *host,
if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block sending global-request packet for "
"forward listen request",
0);
"forward listen request");
return NULL;
} else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send global-request packet for forward "
"listen request",
0);
"listen request");
LIBSSH2_FREE(session, session->fwdLstn_packet);
session->fwdLstn_packet = NULL;
session->fwdLstn_state = libssh2_NB_state_idle;
@@ -514,10 +511,10 @@ channel_forward_listen(LIBSSH2_SESSION * session, const char *host,
0, NULL, 0,
&session->fwdLstn_packet_requirev_state);
if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block", 0);
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block");
return NULL;
} else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_PROTO, "Unknown", 0);
libssh2_error(session, LIBSSH2_ERROR_PROTO, "Unknown");
session->fwdLstn_state = libssh2_NB_state_idle;
return NULL;
}
@@ -528,8 +525,7 @@ channel_forward_listen(LIBSSH2_SESSION * session, const char *host,
listener = LIBSSH2_ALLOC(session, sizeof(LIBSSH2_LISTENER));
if (!listener) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for listener queue",
0);
"Unable to allocate memory for listener queue");
LIBSSH2_FREE(session, data);
session->fwdLstn_state = libssh2_NB_state_idle;
return NULL;
@@ -540,8 +536,7 @@ channel_forward_listen(LIBSSH2_SESSION * session, const char *host,
LIBSSH2_ALLOC(session, session->fwdLstn_host_len + 1);
if (!listener->host) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for listener queue",
0);
"Unable to allocate memory for listener queue");
LIBSSH2_FREE(session, listener);
LIBSSH2_FREE(session, data);
session->fwdLstn_state = libssh2_NB_state_idle;
@@ -577,7 +572,7 @@ channel_forward_listen(LIBSSH2_SESSION * session, const char *host,
if (data[0] == SSH_MSG_REQUEST_FAILURE) {
LIBSSH2_FREE(session, data);
libssh2_error(session, LIBSSH2_ERROR_REQUEST_DENIED,
"Unable to complete request for forward-listen", 0);
"Unable to complete request for forward-listen");
session->fwdLstn_state = libssh2_NB_state_idle;
return NULL;
}
@@ -632,7 +627,7 @@ static int channel_forward_cancel(LIBSSH2_LISTENER *listener)
s = packet = LIBSSH2_ALLOC(session, packet_len);
if (!packet) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memeory for setenv packet", 0);
"Unable to allocate memeory for setenv packet");
return LIBSSH2_ERROR_ALLOC;
}
@@ -664,8 +659,7 @@ static int channel_forward_cancel(LIBSSH2_LISTENER *listener)
else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send global-request packet for forward "
"listen request",
0);
"listen request");
LIBSSH2_FREE(session, packet);
listener->chanFwdCncl_state = libssh2_NB_state_idle;
return LIBSSH2_ERROR_SOCKET_SEND;
@@ -743,11 +737,11 @@ channel_forward_accept(LIBSSH2_LISTENER *listener)
if (rc == PACKET_EAGAIN) {
libssh2_error(listener->session, LIBSSH2_ERROR_EAGAIN,
"Would block waiting for packet", 0);
"Would block waiting for packet");
}
else
libssh2_error(listener->session, LIBSSH2_ERROR_CHANNEL_UNKNOWN,
"Channel not found", 0);
"Channel not found");
return NULL;
}
@@ -799,9 +793,9 @@ static int channel_setenv(LIBSSH2_CHANNEL *channel,
s = channel->setenv_packet =
LIBSSH2_ALLOC(session, channel->setenv_packet_len);
if (!channel->setenv_packet) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memeory for setenv packet", 0);
return LIBSSH2_ERROR_ALLOC;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memeory "
"for setenv packet");
}
*(s++) = SSH_MSG_CHANNEL_REQUEST;
@@ -833,14 +827,12 @@ static int channel_setenv(LIBSSH2_CHANNEL *channel,
if (rc == PACKET_EAGAIN) {
return rc;
} else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send channel-request packet for "
"setenv request",
0);
LIBSSH2_FREE(session, channel->setenv_packet);
channel->setenv_packet = NULL;
channel->setenv_state = libssh2_NB_state_idle;
return LIBSSH2_ERROR_SOCKET_SEND;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send channel-request packet for "
"setenv request");
}
LIBSSH2_FREE(session, channel->setenv_packet);
channel->setenv_packet = NULL;
@@ -872,10 +864,9 @@ static int channel_setenv(LIBSSH2_CHANNEL *channel,
LIBSSH2_FREE(session, data);
}
libssh2_error(session, LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED,
"Unable to complete request for channel-setenv", 0);
channel->setenv_state = libssh2_NB_state_idle;
return LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED;
return libssh2_error(session, LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED,
"Unable to complete request for channel-setenv");
}
/*
@@ -929,9 +920,8 @@ static int channel_request_pty(LIBSSH2_CHANNEL *channel,
s = channel->reqPTY_packet =
LIBSSH2_ALLOC(session, channel->reqPTY_packet_len);
if (!channel->reqPTY_packet) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for pty-request", 0);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for pty-request");
}
*(s++) = SSH_MSG_CHANNEL_REQUEST;
@@ -976,12 +966,11 @@ static int channel_request_pty(LIBSSH2_CHANNEL *channel,
if (rc == PACKET_EAGAIN) {
return rc;
} else if (rc) {
libssh2_error(session, rc,
"Unable to send pty-request packet", 0);
LIBSSH2_FREE(session, channel->reqPTY_packet);
channel->reqPTY_packet = NULL;
channel->reqPTY_state = libssh2_NB_state_idle;
return rc;
return libssh2_error(session, rc,
"Unable to send pty-request packet");
}
LIBSSH2_FREE(session, channel->reqPTY_packet);
channel->reqPTY_packet = NULL;
@@ -1010,10 +999,9 @@ static int channel_request_pty(LIBSSH2_CHANNEL *channel,
}
LIBSSH2_FREE(session, data);
libssh2_error(session, LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED,
"Unable to complete request for channel request-pty", 0);
channel->reqPTY_state = libssh2_NB_state_idle;
return LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED;
return libssh2_error(session, LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED,
"Unable to complete request for channel request-pty");
}
/*
@@ -1058,9 +1046,8 @@ channel_request_pty_size(LIBSSH2_CHANNEL * channel, int width,
LIBSSH2_ALLOC(session, channel->reqPTY_packet_len);
if (!channel->reqPTY_packet) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for pty-request", 0);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for pty-request");
}
*(s++) = SSH_MSG_CHANNEL_REQUEST;
@@ -1090,12 +1077,11 @@ channel_request_pty_size(LIBSSH2_CHANNEL * channel, int width,
if (rc == PACKET_EAGAIN) {
return rc;
} else if (rc) {
libssh2_error(session, rc,
"Unable to send window-change packet", 0);
LIBSSH2_FREE(session, channel->reqPTY_packet);
channel->reqPTY_packet = NULL;
channel->reqPTY_state = libssh2_NB_state_idle;
return rc;
return libssh2_error(session, rc,
"Unable to send window-change packet");
}
LIBSSH2_FREE(session, channel->reqPTY_packet);
channel->reqPTY_packet = NULL;
@@ -1164,9 +1150,8 @@ channel_x11_req(LIBSSH2_CHANNEL *channel, int single_connection,
s = channel->reqX11_packet =
LIBSSH2_ALLOC(session, channel->reqX11_packet_len);
if (!channel->reqX11_packet) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for pty-request", 0);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for pty-request");
}
*(s++) = SSH_MSG_CHANNEL_REQUEST;
@@ -1217,12 +1202,11 @@ channel_x11_req(LIBSSH2_CHANNEL *channel, int single_connection,
return rc;
}
if (rc) {
libssh2_error(session, rc,
"Unable to send x11-req packet", 0);
LIBSSH2_FREE(session, channel->reqX11_packet);
channel->reqX11_packet = NULL;
channel->reqX11_state = libssh2_NB_state_idle;
return rc;
return libssh2_error(session, rc,
"Unable to send x11-req packet");
}
LIBSSH2_FREE(session, channel->reqX11_packet);
channel->reqX11_packet = NULL;
@@ -1239,9 +1223,9 @@ channel_x11_req(LIBSSH2_CHANNEL *channel, int single_connection,
if (rc == PACKET_EAGAIN) {
return rc;
} else if (rc) {
/* TODO: call libssh2_error() here! */
channel->reqX11_state = libssh2_NB_state_idle;
return rc;
return libssh2_error(session, rc,
"waiting for x11-req response packet");
}
if (data[0] == SSH_MSG_CHANNEL_SUCCESS) {
@@ -1252,9 +1236,8 @@ channel_x11_req(LIBSSH2_CHANNEL *channel, int single_connection,
}
LIBSSH2_FREE(session, data);
libssh2_error(session, LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED,
"Unable to complete request for channel x11-req", 0);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED,
"Unable to complete request for channel x11-req");
}
/*
@@ -1310,10 +1293,9 @@ _libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel,
s = channel->process_packet =
LIBSSH2_ALLOC(session, channel->process_packet_len);
if (!channel->process_packet) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for channel-process request",
0);
return LIBSSH2_ERROR_ALLOC;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory "
"for channel-process request");
}
*(s++) = SSH_MSG_CHANNEL_REQUEST;
@@ -1343,12 +1325,11 @@ _libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel,
return rc;
}
else if (rc) {
libssh2_error(session, rc,
"Unable to send channel request", 0);
LIBSSH2_FREE(session, channel->process_packet);
channel->process_packet = NULL;
channel->process_state = libssh2_NB_state_idle;
return rc;
return libssh2_error(session, rc,
"Unable to send channel request");
}
LIBSSH2_FREE(session, channel->process_packet);
channel->process_packet = NULL;
@@ -1366,9 +1347,8 @@ _libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel,
return rc;
} else if (rc) {
channel->process_state = libssh2_NB_state_idle;
libssh2_error(session, rc,
"Failed waiting for channel success", 0);
return rc;
return libssh2_error(session, rc,
"Failed waiting for channel success");
}
if (data[0] == SSH_MSG_CHANNEL_SUCCESS) {
@@ -1379,10 +1359,10 @@ _libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel,
}
LIBSSH2_FREE(session, data);
libssh2_error(session, LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED,
"Unable to complete request for channel-process-startup", 0);
channel->process_state = libssh2_NB_state_idle;
return LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED;
return libssh2_error(session, LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED,
"Unable to complete request for "
"channel-process-startup");
}
/*
@@ -1569,11 +1549,10 @@ _libssh2_channel_receive_window_adjust(LIBSSH2_CHANNEL * channel,
return rc;
}
else if (rc) {
libssh2_error(channel->session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send transfer-window adjustment packet, "
"deferring", 0);
channel->adjust_queue = adjustment;
return rc;
return libssh2_error(channel->session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send transfer-window adjustment "
"packet, deferring");
}
else {
channel->remote.window_size += adjustment;
@@ -1735,10 +1714,8 @@ ssize_t _libssh2_channel_read(LIBSSH2_CHANNEL *channel, int stream_id,
while (rc > 0)
rc = _libssh2_transport_read(session);
if ((rc < 0) && (rc != PACKET_EAGAIN)) {
libssh2_error(session, rc, "tranport read", 0);
return rc;
}
if ((rc < 0) && (rc != PACKET_EAGAIN))
return libssh2_error(session, rc, "transport read");
/*
* =============================== NOTE ===============================
@@ -1844,7 +1821,7 @@ ssize_t _libssh2_channel_read(LIBSSH2_CHANNEL *channel, int stream_id,
more off the network again */
channel->read_state = libssh2_NB_state_created;
if(channel->remote.window_size < (LIBSSH2_CHANNEL_WINDOW_DEFAULT*300)) {
if(channel->remote.window_size < (LIBSSH2_CHANNEL_WINDOW_DEFAULT*30)) {
/* the window is getting too narrow, expand it! */
channel_read_ex_point1:
@@ -1852,7 +1829,7 @@ ssize_t _libssh2_channel_read(LIBSSH2_CHANNEL *channel, int stream_id,
/* the actual window adjusting may not finish so we need to deal with
this special state here */
rc = _libssh2_channel_receive_window_adjust(channel,
(LIBSSH2_CHANNEL_WINDOW_DEFAULT*600), 0, NULL);
(LIBSSH2_CHANNEL_WINDOW_DEFAULT*60), 0, NULL);
if (rc == PACKET_EAGAIN)
return rc;
@@ -1972,15 +1949,14 @@ _libssh2_channel_write(LIBSSH2_CHANNEL *channel, int stream_id,
stream_id);
if (channel->local.close) {
libssh2_error(session, LIBSSH2_ERROR_CHANNEL_CLOSED,
"We've already closed this channel", 0);
return LIBSSH2_ERROR_CHANNEL_CLOSED;
return libssh2_error(session, LIBSSH2_ERROR_CHANNEL_CLOSED,
"We've already closed this channel");
}
if (channel->local.eof) {
libssh2_error(session, LIBSSH2_ERROR_CHANNEL_EOF_SENT,
"EOF has already been sight, data might be ignored",
0);
return libssh2_error(session, LIBSSH2_ERROR_CHANNEL_EOF_SENT,
"EOF has already been received, "
"data might be ignored");
}
/* [13] 9 = packet_type(1) + channelno(4) [ + streamid(4) ] +
@@ -1989,10 +1965,9 @@ _libssh2_channel_write(LIBSSH2_CHANNEL *channel, int stream_id,
channel->write_packet =
LIBSSH2_ALLOC(session, channel->write_packet_len);
if (!channel->write_packet) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocte space for data transmission packet",
0);
return LIBSSH2_ERROR_ALLOC;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocte space "
"for data transmission packet");
}
channel->write_state = libssh2_NB_state_allocated;
@@ -2063,17 +2038,15 @@ _libssh2_channel_write(LIBSSH2_CHANNEL *channel, int stream_id,
channel->write_s -
channel->write_packet);
if (rc == PACKET_EAGAIN) {
libssh2_error(session, rc,
"Unable to send channel data", 0);
return rc;
return libssh2_error(session, rc,
"Unable to send channel data");
}
else if (rc) {
libssh2_error(session, rc,
"Unable to send channel data", 0);
LIBSSH2_FREE(session, channel->write_packet);
channel->write_packet = NULL;
channel->write_state = libssh2_NB_state_idle;
return rc;
return libssh2_error(session, rc,
"Unable to send channel data");
}
/* Shrink local window size */
channel->local.window_size -= channel->write_bufwrite;
@@ -2131,9 +2104,8 @@ static int channel_send_eof(LIBSSH2_CHANNEL *channel)
return rc;
}
else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send EOF on channel", 0);
return LIBSSH2_ERROR_SOCKET_SEND;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send EOF on channel");
}
channel->local.eof = 1;
@@ -2245,6 +2217,13 @@ channel_close(LIBSSH2_CHANNEL * channel)
return 0;
}
if (!channel->local.eof)
if ((retcode = channel_send_eof(channel)))
return retcode;
/* ignore if we have received a remote eof or not, as it is now too
late for us to wait for it. Continue closing! */
if (channel->close_state == libssh2_NB_state_idle) {
_libssh2_debug(session, LIBSSH2_TRACE_CONN, "Closing channel %lu/%lu",
channel->local.id, channel->remote.id);
@@ -2260,10 +2239,9 @@ channel_close(LIBSSH2_CHANNEL * channel)
if (retcode == PACKET_EAGAIN) {
return retcode;
} else if (retcode) {
libssh2_error(session, retcode,
"Unable to send close-channel request", 0);
channel->close_state = libssh2_NB_state_idle;
return retcode;
return libssh2_error(session, retcode,
"Unable to send close-channel request");
}
channel->close_state = libssh2_NB_state_sent;
@@ -2319,11 +2297,9 @@ static int channel_wait_closed(LIBSSH2_CHANNEL *channel)
int rc;
if (!libssh2_channel_eof(channel)) {
libssh2_error(session, LIBSSH2_ERROR_INVAL,
"libssh2_channel_wait_closed() invoked when channel is "
"not in EOF state",
0);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_INVAL,
"libssh2_channel_wait_closed() invoked when "
"channel is not in EOF state");
}
if (channel->wait_closed_state == libssh2_NB_state_idle) {

View File

@@ -122,10 +122,9 @@ comp_method_zlib_init(LIBSSH2_SESSION * session, int compress,
strm = LIBSSH2_ALLOC(session, sizeof(z_stream));
if (!strm) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for zlib compression/decompression",
0);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for "
"zlib compression/decompression");
}
memset(strm, 0, sizeof(z_stream));
@@ -186,10 +185,9 @@ comp_method_zlib_comp(LIBSSH2_SESSION * session,
out = (char *) strm->next_out;
strm->avail_out = out_maxlen;
if (!strm->next_out) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate compression/decompression buffer",
0);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate compression/decompression "
"buffer");
}
while (strm->avail_in) {
int status;
@@ -200,10 +198,9 @@ comp_method_zlib_comp(LIBSSH2_SESSION * session,
status = inflate(strm, Z_PARTIAL_FLUSH);
}
if (status != Z_OK) {
libssh2_error(session, LIBSSH2_ERROR_ZLIB,
"compress/decompression failure", 0);
LIBSSH2_FREE(session, out);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_ZLIB,
"compress/decompression failure");
}
if (strm->avail_in) {
unsigned long out_ofs = out_maxlen - strm->avail_out;
@@ -213,19 +210,17 @@ comp_method_zlib_comp(LIBSSH2_SESSION * session,
compress ? (strm->avail_in + 4) : (2 * strm->avail_in);
if ((out_maxlen > (int) payload_limit) && !compress && limiter++) {
libssh2_error(session, LIBSSH2_ERROR_ZLIB,
"Excessive growth in decompression phase", 0);
LIBSSH2_FREE(session, out);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_ZLIB,
"Excessive growth in decompression phase");
}
newout = LIBSSH2_REALLOC(session, out, out_maxlen);
if (!newout) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to expand compress/decompression buffer",
0);
LIBSSH2_FREE(session, out);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to expand compress/"
"decompression buffer");
}
out = newout;
strm->next_out = (unsigned char *) out + out_ofs;
@@ -241,11 +236,10 @@ comp_method_zlib_comp(LIBSSH2_SESSION * session,
char *newout;
if (out_maxlen >= (int) payload_limit) {
libssh2_error(session, LIBSSH2_ERROR_ZLIB,
"Excessive growth in decompression phase",
0);
LIBSSH2_FREE(session, out);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_ZLIB,
"Excessive growth in decompression "
"phase");
}
if (grow_size > (int) (payload_limit - out_maxlen)) {
@@ -257,11 +251,10 @@ comp_method_zlib_comp(LIBSSH2_SESSION * session,
newout = LIBSSH2_REALLOC(session, out, out_maxlen);
if (!newout) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to expand final compress/decompress buffer",
0);
LIBSSH2_FREE(session, out);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to expand final compress/"
"decompress buffer");
}
out = newout;
strm->next_out = (unsigned char *) out + out_maxlen -
@@ -273,10 +266,9 @@ comp_method_zlib_comp(LIBSSH2_SESSION * session,
status = inflate(strm, Z_PARTIAL_FLUSH);
}
if (status != Z_OK) {
libssh2_error(session, LIBSSH2_ERROR_ZLIB,
"compress/decompression failure", 0);
LIBSSH2_FREE(session, out);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_ZLIB,
"compress/decompression failure");
}
}
}

77
src/global.c Normal file
View File

@@ -0,0 +1,77 @@
/* Copyright (c) 2010 Lars Nordin <Lars.Nordin@SDlabs.se>
* Copyright (C) 2010 Simon Josefsson <simon@josefsson.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms,
* with or without modification, are permitted provided
* that the following conditions are met:
*
* Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
*
* Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* Neither the name of the copyright holder nor the names
* of any other contributors may be used to endorse or
* promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*/
#include "libssh2_priv.h"
static int _libssh2_initialized = 0;
static int _libssh2_init_flags = 0;
LIBSSH2_API int
libssh2_init(int flags)
{
if (_libssh2_initialized == 0 && !(flags & LIBSSH2_INIT_NO_CRYPTO)) {
libssh2_crypto_init();
}
_libssh2_initialized++;
_libssh2_init_flags |= flags;
return 0;
}
LIBSSH2_API void
libssh2_exit(void)
{
if (_libssh2_initialized == 0)
return;
_libssh2_initialized--;
if (!(_libssh2_init_flags & LIBSSH2_INIT_NO_CRYPTO)) {
libssh2_crypto_exit();
}
return;
}
void
_libssh2_init_if_needed(void)
{
if (_libssh2_initialized == 0)
libssh2_init (0);
}

View File

@@ -324,9 +324,8 @@ hostkey_method_ssh_dss_sig_verify(LIBSSH2_SESSION * session,
sig += 15;
sig_len -= 15;
if (sig_len != 40) {
libssh2_error(session, LIBSSH2_ERROR_PROTO,
"Invalid DSS signature length", 0);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_PROTO,
"Invalid DSS signature length");
}
return _libssh2_dsa_sha1_verify(dsactx, sig, m, m_len);
}

97
src/keepalive.c Normal file
View File

@@ -0,0 +1,97 @@
/* Copyright (C) 2010 Simon Josefsson
* Author: Simon Josefsson
*
* Redistribution and use in source and binary forms,
* with or without modification, are permitted provided
* that the following conditions are met:
*
* Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
*
* Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* Neither the name of the copyright holder nor the names
* of any other contributors may be used to endorse or
* promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
*/
#include "libssh2_priv.h"
#include "transport.h" /* _libssh2_transport_write */
/* Keep-alive stuff. */
LIBSSH2_API void
libssh2_keepalive_config (LIBSSH2_SESSION *session,
int want_reply,
unsigned interval)
{
if (interval == 1)
session->keepalive_interval = 2;
else
session->keepalive_interval = interval;
session->keepalive_want_reply = want_reply ? 1 : 0;
}
LIBSSH2_API int
libssh2_keepalive_send (LIBSSH2_SESSION *session,
int *seconds_to_next)
{
time_t now;
if (!session->keepalive_interval) {
if (seconds_to_next)
*seconds_to_next = 0;
return 0;
}
now = time (NULL);
if (session->keepalive_last_sent + session->keepalive_interval <= now) {
/* Format is "SSH_MSG_GLOBAL_REQUEST || 4-byte len || str || want-reply". */
unsigned char keepalive_data[]
= "\x50\x00\x00\x00\x15keepalive@libssh2.orgW";
size_t len = sizeof (keepalive_data) - 1;
int rc;
keepalive_data[len - 1] = session->keepalive_want_reply;
rc = _libssh2_transport_write(session, keepalive_data, len);
/* Silently ignore PACKET_EAGAIN here: if the write buffer is
already full, sending another keepalive is not useful. */
if (rc && rc != PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send keepalive message");
return rc;
}
session->keepalive_last_sent = now;
if (seconds_to_next)
*seconds_to_next = session->keepalive_interval;
} else if (seconds_to_next) {
*seconds_to_next = session->keepalive_last_sent
+ session->keepalive_interval - now;
}
return 0;
}

View File

@@ -118,9 +118,8 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
exchange_state->e_packet =
LIBSSH2_ALLOC(session, exchange_state->e_packet_len);
if (!exchange_state->e_packet) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Out of memory error",
0);
ret = LIBSSH2_ERROR_ALLOC;
ret = libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Out of memory error");
goto clean_exit;
}
exchange_state->e_packet[0] = packet_type_init;
@@ -146,9 +145,8 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
if (rc == PACKET_EAGAIN) {
return rc;
} else if (rc) {
libssh2_error(session, rc,
"Unable to send KEX init message", 0);
ret = rc;
ret = libssh2_error(session, rc,
"Unable to send KEX init message");
goto clean_exit;
}
exchange_state->state = libssh2_NB_state_sent;
@@ -192,9 +190,8 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
return rc;
}
if (rc) {
libssh2_error(session, LIBSSH2_ERROR_TIMEOUT,
"Timed out waiting for KEX reply", 0);
ret = rc;
ret = libssh2_error(session, LIBSSH2_ERROR_TIMEOUT,
"Timed out waiting for KEX reply");
goto clean_exit;
}
@@ -206,10 +203,9 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
session->server_hostkey =
LIBSSH2_ALLOC(session, session->server_hostkey_len);
if (!session->server_hostkey) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for a copy of the host key",
0);
ret = LIBSSH2_ERROR_ALLOC;
ret = libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for a copy "
"of the host key");
goto clean_exit;
}
memcpy(session->server_hostkey, exchange_state->s,
@@ -264,9 +260,8 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
if (session->hostkey->init(session, session->server_hostkey,
session->server_hostkey_len,
&session->server_hostkey_abstract)) {
libssh2_error(session, LIBSSH2_ERROR_HOSTKEY_INIT,
"Unable to initialize hostkey importer", 0);
ret = LIBSSH2_ERROR_HOSTKEY_INIT;
ret = libssh2_error(session, LIBSSH2_ERROR_HOSTKEY_INIT,
"Unable to initialize hostkey importer");
goto clean_exit;
}
@@ -292,9 +287,8 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
exchange_state->k_value =
LIBSSH2_ALLOC(session, exchange_state->k_value_len);
if (!exchange_state->k_value) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate buffer for K", 0);
ret = LIBSSH2_ERROR_ALLOC;
ret = libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate buffer for K");
goto clean_exit;
}
_libssh2_htonu32(exchange_state->k_value,
@@ -404,9 +398,8 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
sig_verify(session, exchange_state->h_sig,
exchange_state->h_sig_len, exchange_state->h_sig_comp,
20, &session->server_hostkey_abstract)) {
libssh2_error(session, LIBSSH2_ERROR_HOSTKEY_SIGN,
"Unable to verify hostkey signature", 0);
ret = -1;
ret = libssh2_error(session, LIBSSH2_ERROR_HOSTKEY_SIGN,
"Unable to verify hostkey signature");
goto clean_exit;
}
@@ -421,8 +414,7 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
if (rc == PACKET_EAGAIN) {
return rc;
} else if (rc) {
libssh2_error(session, rc, "Unable to send NEWKEYS message", 0);
ret = rc;
ret = libssh2_error(session, rc, "Unable to send NEWKEYS message");
goto clean_exit;
}
@@ -437,8 +429,7 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
if (rc == PACKET_EAGAIN) {
return rc;
} else if (rc) {
libssh2_error(session, rc, "Timed out waiting for NEWKEYS", 0);
ret = rc;
ret = libssh2_error(session, rc, "Timed out waiting for NEWKEYS");
goto clean_exit;
}
/* The first key exchange has been performed,
@@ -453,9 +444,8 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
if (!session->session_id) {
session->session_id = LIBSSH2_ALLOC(session, SHA_DIGEST_LENGTH);
if (!session->session_id) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate buffer for SHA digest", 0);
ret = LIBSSH2_ERROR_ALLOC;
ret = libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate buffer for SHA digest");
goto clean_exit;
}
memcpy(session->session_id, exchange_state->h_sig_comp,
@@ -825,9 +815,8 @@ kex_method_diffie_hellman_group_exchange_sha1_key_exchange
if (rc == PACKET_EAGAIN) {
return rc;
} else if (rc) {
libssh2_error(session, rc,
"Unable to send Group Exchange Request", 0);
ret = rc;
ret = libssh2_error(session, rc,
"Unable to send Group Exchange Request");
goto dh_gex_clean_exit;
}
@@ -841,9 +830,8 @@ kex_method_diffie_hellman_group_exchange_sha1_key_exchange
if (rc == PACKET_EAGAIN) {
return rc;
} else if (rc) {
libssh2_error(session, rc,
"Timeout waiting for GEX_GROUP reply", 0);
ret = rc;
ret = libssh2_error(session, rc,
"Timeout waiting for GEX_GROUP reply");
goto dh_gex_clean_exit;
}
@@ -1038,9 +1026,8 @@ static int kexinit(LIBSSH2_SESSION * session)
s = data = LIBSSH2_ALLOC(session, data_len);
if (!data) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory", 0);
return LIBSSH2_ERROR_ALLOC;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory");
}
*(s++) = SSH_MSG_KEXINIT;
@@ -1127,10 +1114,10 @@ static int kexinit(LIBSSH2_SESSION * session)
}
else if (rc) {
LIBSSH2_FREE(session, data);
libssh2_error(session, rc,
"Unable to send KEXINIT packet to remote host", 0);
session->kexinit_state = libssh2_NB_state_idle;
return rc;
return libssh2_error(session, rc,
"Unable to send KEXINIT packet to remote host");
}
if (session->local.kexinit) {
@@ -1749,9 +1736,8 @@ libssh2_kex_exchange(LIBSSH2_SESSION * session, int reexchange,
session->state &= ~LIBSSH2_STATE_KEX_ACTIVE;
return retcode;
} else if (retcode) {
libssh2_error(session, LIBSSH2_ERROR_KEY_EXCHANGE_FAILURE,
"Unrecoverable error exchanging keys", 0);
rc = retcode;
rc = libssh2_error(session, LIBSSH2_ERROR_KEY_EXCHANGE_FAILURE,
"Unrecoverable error exchanging keys");
}
}
}
@@ -1839,16 +1825,14 @@ libssh2_session_method_pref(LIBSSH2_SESSION * session, int method_type,
break;
default:
libssh2_error(session, LIBSSH2_ERROR_INVAL,
"Invalid parameter specified for method_type", 0);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_INVAL,
"Invalid parameter specified for method_type");
}
s = newprefs = LIBSSH2_ALLOC(session, prefs_len + 1);
if (!newprefs) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Error allocated space for method preferences", 0);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Error allocated space for method preferences");
}
memcpy(s, prefs, prefs_len + 1);
@@ -1873,11 +1857,10 @@ libssh2_session_method_pref(LIBSSH2_SESSION * session, int method_type,
}
if (strlen(newprefs) == 0) {
libssh2_error(session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
"The requested method(s) are not currently supported",
0);
LIBSSH2_FREE(session, newprefs);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
"The requested method(s) are not currently "
"supported");
}
if (*prefvar) {

View File

@@ -48,6 +48,7 @@ struct known_host {
size_t salt_len; /* size of salt */
char *key; /* the (allocated) associated key. This is kept base64
encoded in memory. */
char *comment; /* the (allocated) optional comment text, may be NULL */
/* this is the struct we expose externally */
struct libssh2_knownhost external;
@@ -62,6 +63,8 @@ struct _LIBSSH2_KNOWNHOSTS
static void free_host(LIBSSH2_SESSION *session, struct known_host *entry)
{
if(entry) {
if(entry->comment)
LIBSSH2_FREE(session, entry->comment);
if(entry->key)
LIBSSH2_FREE(session, entry->key);
if(entry->salt)
@@ -84,8 +87,12 @@ libssh2_knownhost_init(LIBSSH2_SESSION *session)
LIBSSH2_KNOWNHOSTS *knh =
LIBSSH2_ALLOC(session, sizeof(struct _LIBSSH2_KNOWNHOSTS));
if(!knh)
if(!knh) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for known-hosts "
"collection");
return NULL;
}
knh->session = session;
@@ -115,45 +122,31 @@ static struct libssh2_knownhost *knownhost_to_external(struct known_host *node)
return ext;
}
/*
* libssh2_knownhost_add
*
* Add a host and its associated key to the collection of known hosts.
*
* The 'type' argument specifies on what format the given host and keys are:
*
* plain - ascii "hostname.domain.tld"
* sha1 - SHA1(<salt> <host>) base64-encoded!
* custom - another hash
*
* If 'sha1' is selected as type, the salt must be provided to the salt
* argument. This too base64 encoded.
*
* The SHA-1 hash is what OpenSSH can be told to use in known_hosts files. If
* a custom type is used, salt is ignored and you must provide the host
* pre-hashed when checking for it in the libssh2_knownhost_check() function.
*
*/
LIBSSH2_API int
libssh2_knownhost_add(LIBSSH2_KNOWNHOSTS *hosts,
const char *host, const char *salt,
const char *key, size_t keylen,
int typemask, struct libssh2_knownhost **store)
static int
knownhost_add(LIBSSH2_KNOWNHOSTS *hosts,
const char *host, const char *salt,
const char *key, size_t keylen,
const char *comment, size_t commentlen,
int typemask, struct libssh2_knownhost **store)
{
struct known_host *entry =
LIBSSH2_ALLOC(hosts->session, sizeof(struct known_host));
size_t hostlen = strlen(host);
int rc = LIBSSH2_ERROR_ALLOC;
int rc;
char *ptr;
unsigned int ptrlen;
if(!entry)
return rc;
return libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for known host "
"entry");
if(!(typemask & LIBSSH2_KNOWNHOST_KEY_MASK))
/* make sure we have a key type set */
return LIBSSH2_ERROR_INVAL;
/* make sure we have a key type set */
if(!(typemask & LIBSSH2_KNOWNHOST_KEY_MASK)) {
rc = libssh2_error(hosts->session, LIBSSH2_ERROR_INVAL,
"No key type set");
goto error;
}
memset(entry, 0, sizeof(struct known_host));
@@ -163,8 +156,11 @@ libssh2_knownhost_add(LIBSSH2_KNOWNHOSTS *hosts,
case LIBSSH2_KNOWNHOST_TYPE_PLAIN:
case LIBSSH2_KNOWNHOST_TYPE_CUSTOM:
entry->name = LIBSSH2_ALLOC(hosts->session, hostlen+1);
if(!entry)
if(!entry->name) {
rc = libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for host name");
goto error;
}
memcpy(entry->name, host, hostlen+1);
break;
case LIBSSH2_KNOWNHOST_TYPE_SHA1:
@@ -183,7 +179,8 @@ libssh2_knownhost_add(LIBSSH2_KNOWNHOSTS *hosts,
entry->salt_len = ptrlen;
break;
default:
rc = LIBSSH2_ERROR_METHOD_NOT_SUPPORTED;
rc = libssh2_error(hosts->session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
"Unknown host name type");
goto error;
}
@@ -192,8 +189,11 @@ libssh2_knownhost_add(LIBSSH2_KNOWNHOSTS *hosts,
if(!keylen)
keylen = strlen(key);
entry->key = LIBSSH2_ALLOC(hosts->session, keylen+1);
if(!entry)
if(!entry->key) {
rc = libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for key");
goto error;
}
memcpy(entry->key, key, keylen+1);
entry->key[keylen]=0; /* force a terminating zero trailer */
}
@@ -201,12 +201,30 @@ libssh2_knownhost_add(LIBSSH2_KNOWNHOSTS *hosts,
/* key is raw, we base64 encode it and store it as such */
size_t nlen = _libssh2_base64_encode(hosts->session, key, keylen,
&ptr);
if(!nlen)
if(!nlen) {
rc = libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for "
"base64-encoded key");
goto error;
}
entry->key = ptr;
}
if (comment) {
entry->comment = LIBSSH2_ALLOC(hosts->session, commentlen+1);
if(!entry->comment) {
rc = libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for comment");
goto error;
}
memcpy(entry->comment, comment, commentlen+1);
entry->comment[commentlen]=0; /* force a terminating zero trailer */
}
else {
entry->comment = NULL;
}
/* add this new host to the big list of known hosts */
_libssh2_list_add(&hosts->head, &entry->node);
@@ -219,6 +237,77 @@ libssh2_knownhost_add(LIBSSH2_KNOWNHOSTS *hosts,
return rc;
}
/*
* libssh2_knownhost_add
*
* Add a host and its associated key to the collection of known hosts.
*
* The 'type' argument specifies on what format the given host and keys are:
*
* plain - ascii "hostname.domain.tld"
* sha1 - SHA1(<salt> <host>) base64-encoded!
* custom - another hash
*
* If 'sha1' is selected as type, the salt must be provided to the salt
* argument. This too base64 encoded.
*
* The SHA-1 hash is what OpenSSH can be told to use in known_hosts files. If
* a custom type is used, salt is ignored and you must provide the host
* pre-hashed when checking for it in the libssh2_knownhost_check() function.
*
* The keylen parameter may be omitted (zero) if the key is provided as a
* NULL-terminated base64-encoded string.
*/
LIBSSH2_API int
libssh2_knownhost_add(LIBSSH2_KNOWNHOSTS *hosts,
const char *host, const char *salt,
const char *key, size_t keylen,
int typemask, struct libssh2_knownhost **store)
{
return knownhost_add(hosts, host, salt, key, keylen, NULL, 0, typemask,
store);
}
/*
* libssh2_knownhost_addc
*
* Add a host and its associated key to the collection of known hosts.
*
* Takes a comment argument that may be NULL. A NULL comment indicates
* there is no comment and the entry will end directly after the key
* when written out to a file. An empty string "" comment will indicate an
* empty comment which will cause a single space to be written after the key.
*
* The 'type' argument specifies on what format the given host and keys are:
*
* plain - ascii "hostname.domain.tld"
* sha1 - SHA1(<salt> <host>) base64-encoded!
* custom - another hash
*
* If 'sha1' is selected as type, the salt must be provided to the salt
* argument. This too base64 encoded.
*
* The SHA-1 hash is what OpenSSH can be told to use in known_hosts files. If
* a custom type is used, salt is ignored and you must provide the host
* pre-hashed when checking for it in the libssh2_knownhost_check() function.
*
* The keylen parameter may be omitted (zero) if the key is provided as a
* NULL-terminated base64-encoded string.
*/
LIBSSH2_API int
libssh2_knownhost_addc(LIBSSH2_KNOWNHOSTS *hosts,
const char *host, const char *salt,
const char *key, size_t keylen,
const char *comment, size_t commentlen,
int typemask, struct libssh2_knownhost **store)
{
return knownhost_add(hosts, host, salt, key, keylen, comment, commentlen,
typemask, store);
}
/*
* libssh2_knownhost_check
*
@@ -257,8 +346,12 @@ libssh2_knownhost_check(LIBSSH2_KNOWNHOSTS *hosts,
/* we got a raw key input, convert it to base64 for the checks below */
size_t nlen = _libssh2_base64_encode(hosts->session, key, keylen,
&keyalloc);
if(!nlen)
if(!nlen) {
libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for base64-encoded "
"key");
return LIBSSH2_KNOWNHOST_CHECK_FAILURE;
}
/* make the key point to this */
key = keyalloc;
@@ -344,9 +437,11 @@ libssh2_knownhost_del(LIBSSH2_KNOWNHOSTS *hosts,
struct libssh2_knownhost *entry)
{
struct known_host *node;
/* check that this was retrieved the right way or get out */
if(!entry || (entry->magic != KNOWNHOST_MAGIC))
/* check that this was retrieved the right way or get out */
return LIBSSH2_ERROR_INVAL;
return libssh2_error(hosts->session, LIBSSH2_ERROR_INVAL,
"Invalid host information");
/* get the internal node pointer */
node = entry->node;
@@ -354,12 +449,13 @@ libssh2_knownhost_del(LIBSSH2_KNOWNHOSTS *hosts,
/* unlink from the list of all hosts */
_libssh2_list_remove(&node->node);
/* clear the struct now since the memory in which it is allocated is
about to be freed! */
memset(entry, 0, sizeof(struct libssh2_knownhost));
/* free all resources */
free_host(hosts->session, node);
/* clear the struct now since this host entry has been removed! */
memset(entry, 0, sizeof(struct libssh2_knownhost));
return 0;
}
@@ -387,6 +483,10 @@ libssh2_knownhost_free(LIBSSH2_KNOWNHOSTS *hosts)
*
* Parse a single known_host line pre-split into host and key.
*
* The key part may include an optional comment which will be parsed here
* for ssh-rsa and ssh-dsa keys. Comments in other key types aren't handled.
*
* The function assumes new-lines have already been removed from the arguments.
*/
static int hostline(LIBSSH2_KNOWNHOSTS *hosts,
const char *host, size_t hostlen,
@@ -395,6 +495,8 @@ static int hostline(LIBSSH2_KNOWNHOSTS *hosts,
const char *p;
const char *orig = host;
const char *salt = NULL;
const char *comment = NULL;
size_t commentlen = 0;
int rc;
int type = LIBSSH2_KNOWNHOST_TYPE_PLAIN;
const char *sep = NULL;
@@ -439,8 +541,11 @@ static int hostline(LIBSSH2_KNOWNHOSTS *hosts,
if(*p=='|') {
const char *hash = NULL;
size_t saltlen = p - salt;
if(saltlen >= (sizeof(saltbuf)-1))
return LIBSSH2_ERROR_METHOD_NOT_SUPPORTED; /* weird length */
if(saltlen >= (sizeof(saltbuf)-1)) /* weird length */
return libssh2_error(hosts->session,
LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
"Failed to parse known_hosts line "
"(unexpectedly long salt)");
memcpy(saltbuf, salt, saltlen);
saltbuf[saltlen] = 0; /* zero terminate */
@@ -456,11 +561,14 @@ static int hostline(LIBSSH2_KNOWNHOSTS *hosts,
return 0;
}
/* make some checks that the lenghts seem sensible */
/* make some checks that the lengths seem sensible */
if((keylen < 20) ||
(seplen >= sizeof(hostbuf)-1) ||
(hostlen >= sizeof(hostbuf)-1))
return LIBSSH2_ERROR_METHOD_NOT_SUPPORTED;
return libssh2_error(hosts->session,
LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
"Failed to parse known_hosts line "
"(unexpected length)");
switch(key[0]) {
case '0': case '1': case '2': case '3': case '4':
@@ -480,7 +588,10 @@ static int hostline(LIBSSH2_KNOWNHOSTS *hosts,
else if(!strncmp(key, "ssh-rsa", 7))
type |= LIBSSH2_KNOWNHOST_KEY_SSHRSA;
else
return LIBSSH2_ERROR_METHOD_NOT_SUPPORTED; /* unknown key type */
/* unknown key type */
return libssh2_error(hosts->session,
LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
"Unknown key type");
key += 7;
keylen -= 7;
@@ -490,10 +601,36 @@ static int hostline(LIBSSH2_KNOWNHOSTS *hosts,
key++;
keylen--;
}
comment = key;
commentlen = keylen;
/* move over key */
while(commentlen && *comment &&
(*comment != ' ') && (*comment != '\t')) {
comment++;
commentlen--;
}
/* reduce key by comment length */
keylen -= commentlen;
/* Distinguish empty comment (a space) from no comment (no space) */
if (commentlen == 0)
comment = NULL;
/* skip whitespaces */
while(commentlen && *comment &&
((*comment ==' ') || (*comment == '\t'))) {
comment++;
commentlen--;
}
break;
default: /* unknown key format */
return LIBSSH2_ERROR_METHOD_NOT_SUPPORTED;
return libssh2_error(hosts->session,
LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
"Unknown key format");
}
if(sep) {
@@ -502,9 +639,10 @@ static int hostline(LIBSSH2_KNOWNHOSTS *hosts,
memcpy(hostbuf, sep, seplen);
hostbuf[seplen]=0;
rc = libssh2_knownhost_add(hosts, hostbuf, salt, key, keylen,
type | LIBSSH2_KNOWNHOST_KEYENC_BASE64,
NULL);
rc = libssh2_knownhost_addc(hosts, hostbuf, salt, key, keylen,
comment, commentlen,
type | LIBSSH2_KNOWNHOST_KEYENC_BASE64,
NULL);
if(rc)
return rc;
}
@@ -514,9 +652,10 @@ static int hostline(LIBSSH2_KNOWNHOSTS *hosts,
memcpy(hostbuf, host, hostlen);
hostbuf[hostlen]=0;
rc = libssh2_knownhost_add(hosts, hostbuf, salt, key, keylen,
type | LIBSSH2_KNOWNHOST_KEYENC_BASE64,
NULL);
rc = libssh2_knownhost_addc(hosts, hostbuf, salt, key, keylen, comment,
commentlen,
type | LIBSSH2_KNOWNHOST_KEYENC_BASE64,
NULL);
return rc;
}
@@ -560,7 +699,10 @@ libssh2_knownhost_readline(LIBSSH2_KNOWNHOSTS *hosts,
int rc;
if(type != LIBSSH2_KNOWNHOST_FILE_OPENSSH)
return LIBSSH2_ERROR_METHOD_NOT_SUPPORTED;
return libssh2_error(hosts->session,
LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
"Unsupported type of known-host information "
"store");
cp = line;
@@ -591,9 +733,10 @@ libssh2_knownhost_readline(LIBSSH2_KNOWNHOSTS *hosts,
len--;
}
if(!*cp || !len)
/* illegal line */
return LIBSSH2_ERROR_METHOD_NOT_SUPPORTED;
if(!*cp || !len) /* illegal line */
return libssh2_error(hosts->session,
LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
"Failed to parse known_hosts line");
keyp = cp; /* the key starts here */
keylen = len;
@@ -634,7 +777,10 @@ libssh2_knownhost_readfile(LIBSSH2_KNOWNHOSTS *hosts,
char buf[2048];
if(type != LIBSSH2_KNOWNHOST_FILE_OPENSSH)
return LIBSSH2_ERROR_METHOD_NOT_SUPPORTED;
return libssh2_error(hosts->session,
LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
"Unsupported type of known-host information "
"store");
file = fopen(filename, "r");
if(file) {
@@ -646,7 +792,9 @@ libssh2_knownhost_readfile(LIBSSH2_KNOWNHOSTS *hosts,
fclose(file);
}
else
return LIBSSH2_ERROR_FILE;
return libssh2_error(hosts->session, LIBSSH2_ERROR_FILE,
"Failed to open file");
return num;
}
@@ -677,11 +825,15 @@ knownhost_writeline(LIBSSH2_KNOWNHOSTS *hosts,
};
const char *keytype;
size_t nlen;
size_t commentlen = 0;
/* we only support this single file type for now, bail out on all other
attempts */
if(type != LIBSSH2_KNOWNHOST_FILE_OPENSSH)
return LIBSSH2_ERROR_METHOD_NOT_SUPPORTED;
return libssh2_error(hosts->session,
LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
"Unsupported type of known-host information "
"store");
tindex = (node->typemask & LIBSSH2_KNOWNHOST_KEY_MASK) >>
LIBSSH2_KNOWNHOST_KEY_SHIFT;
@@ -689,6 +841,10 @@ knownhost_writeline(LIBSSH2_KNOWNHOSTS *hosts,
/* set the string used in the file */
keytype = keytypes[tindex];
/* calculate extra space needed for comment */
if(node->comment)
commentlen = strlen(node->comment) + 1;
if((node->typemask & LIBSSH2_KNOWNHOST_TYPE_MASK) ==
LIBSSH2_KNOWNHOST_TYPE_SHA1) {
char *namealloc;
@@ -696,36 +852,52 @@ knownhost_writeline(LIBSSH2_KNOWNHOSTS *hosts,
nlen = _libssh2_base64_encode(hosts->session, node->name,
node->name_len, &namealloc);
if(!nlen)
return LIBSSH2_ERROR_ALLOC;
return libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for "
"base64-encoded host name");
nlen = _libssh2_base64_encode(hosts->session,
node->salt, node->salt_len,
&saltalloc);
if(!nlen) {
free(namealloc);
return LIBSSH2_ERROR_ALLOC;
return libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for "
"base64-encoded salt");
}
nlen = strlen(saltalloc) + strlen(namealloc) + strlen(keytype) +
strlen(node->key) + 7; /* |1| + | + ' ' + \n + \0 = 7 */
strlen(node->key) + commentlen + 7;
/* |1| + | + ' ' + \n + \0 = 7 */
if(nlen <= buflen)
sprintf(buf, "|1|%s|%s%s %s\n", saltalloc, namealloc, keytype,
node->key);
if(node->comment)
sprintf(buf, "|1|%s|%s%s %s %s\n", saltalloc, namealloc,
keytype, node->key, node->comment);
else
sprintf(buf, "|1|%s|%s%s %s\n", saltalloc, namealloc,
keytype, node->key);
else
rc = LIBSSH2_ERROR_BUFFER_TOO_SMALL;
rc = libssh2_error(hosts->session, LIBSSH2_ERROR_BUFFER_TOO_SMALL,
"Known-host write buffer too small");
free(namealloc);
free(saltalloc);
}
else {
nlen = strlen(node->name) + strlen(keytype) + strlen(node->key) + 3;
nlen = strlen(node->name) + strlen(keytype) + strlen(node->key) +
commentlen + 3;
/* ' ' + '\n' + \0 = 3 */
if(nlen <= buflen)
/* these types have the plain name */
sprintf(buf, "%s%s %s\n", node->name, keytype, node->key);
if(node->comment)
sprintf(buf, "%s%s %s %s\n", node->name, keytype, node->key,
node->comment);
else
sprintf(buf, "%s%s %s\n", node->name, keytype, node->key);
else
rc = LIBSSH2_ERROR_BUFFER_TOO_SMALL;
rc = libssh2_error(hosts->session, LIBSSH2_ERROR_BUFFER_TOO_SMALL,
"Known-host write buffer too small");
}
/* we report the full length of the data with the trailing zero excluded */
@@ -752,7 +924,8 @@ libssh2_knownhost_writeline(LIBSSH2_KNOWNHOSTS *hosts,
struct known_host *node;
if(known->magic != KNOWNHOST_MAGIC)
return LIBSSH2_ERROR_INVAL;
return libssh2_error(hosts->session, LIBSSH2_ERROR_INVAL,
"Invalid host information");
node = known->node;
@@ -776,11 +949,15 @@ libssh2_knownhost_writefile(LIBSSH2_KNOWNHOSTS *hosts,
/* we only support this single file type for now, bail out on all other
attempts */
if(type != LIBSSH2_KNOWNHOST_FILE_OPENSSH)
return LIBSSH2_ERROR_METHOD_NOT_SUPPORTED;
return libssh2_error(hosts->session,
LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
"Unsupported type of known-host information "
"store");
file = fopen(filename, "w");
if(!file)
return LIBSSH2_ERROR_FILE;
return libssh2_error(hosts->session, LIBSSH2_ERROR_FILE,
"Failed to open file");
for(node = _libssh2_list_first(&hosts->head);
node;
@@ -795,7 +972,8 @@ libssh2_knownhost_writefile(LIBSSH2_KNOWNHOSTS *hosts,
nwrote = fwrite(buffer, 1, wrote, file);
if(nwrote != wrote) {
/* failed to write the whole thing, bail out */
rc = LIBSSH2_ERROR_FILE;
rc = libssh2_error(hosts->session, LIBSSH2_ERROR_FILE,
"Write failed");
break;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2008, 2009 Simon Josefsson
* Copyright (C) 2008, 2009, 2010 Simon Josefsson
* Copyright (C) 2006, 2007, The Written Word, Inc.
* All rights reserved.
*
@@ -93,6 +93,7 @@
#define libssh2_hmac_cleanup(ctx) gcry_md_close (*ctx);
#define libssh2_crypto_init() gcry_control (GCRYCTL_DISABLE_SECMEM)
#define libssh2_crypto_exit()
#define libssh2_rsa_ctx struct gcry_sexp

View File

@@ -1,4 +1,4 @@
/* Copyright (c) 2004-2008, Sara Golemon <sarag@libssh2.org>
/* Copyright (c) 2004-2008, 2010, Sara Golemon <sarag@libssh2.org>
* Copyright (c) 2009 by Daniel Stenberg
* Copyright (c) 2010 Simon Josefsson
* All rights reserved.
@@ -730,9 +730,7 @@ struct _LIBSSH2_SESSION
when libssh2_session_startup() is called */
/* Error tracking */
char *err_msg;
unsigned long err_msglen;
int err_should_free;
const char *err_msg;
int err_code;
/* struct members for packet-level reading */
@@ -879,6 +877,8 @@ struct _LIBSSH2_SESSION
LIBSSH2_CHANNEL *sftpInit_channel;
unsigned char sftpInit_buffer[9]; /* sftp_header(5){excludes request_id}
+ version_id(4) */
int sftpInit_sent; /* number of bytes from the buffer that have been
sent */
/* State variables used in libssh2_scp_recv() */
libssh2_nonblocking_states scpRecv_state;
@@ -910,6 +910,11 @@ struct _LIBSSH2_SESSION
char *scpSend_err_msg;
long scpSend_err_len;
LIBSSH2_CHANNEL *scpSend_channel;
/* Keepalive variables used by keepalive.c. */
int keepalive_interval;
int keepalive_want_reply;
time_t keepalive_last_sent;
};
/* session.state bits */
@@ -1036,34 +1041,7 @@ _libssh2_debug(LIBSSH2_SESSION * session, int context, const char *format, ...)
#endif
#endif
#ifdef LIBSSH2DEBUG
#define libssh2_error(session, errcode, errmsg, should_free) \
{ \
if (session->err_msg && session->err_should_free) { \
LIBSSH2_FREE(session, session->err_msg); \
} \
session->err_msg = (char *)errmsg; \
session->err_msglen = strlen(errmsg); \
session->err_should_free = should_free; \
session->err_code = errcode; \
_libssh2_debug(session, LIBSSH2_TRACE_ERROR, "%d - %s", session->err_code, session->err_msg); \
}
#else /* ! LIBSSH2DEBUG */
#define libssh2_error(session, errcode, errmsg, should_free) \
{ \
if (session->err_msg && session->err_should_free) { \
LIBSSH2_FREE(session, session->err_msg); \
} \
session->err_msg = (char *)errmsg; \
session->err_msglen = strlen(errmsg); \
session->err_should_free = should_free; \
session->err_code = errcode; \
}
#endif /* ! LIBSSH2DEBUG */
int libssh2_error(LIBSSH2_SESSION* session, int errcode, const char* errmsg);
#define LIBSSH2_SOCKET_UNKNOWN 1
#define LIBSSH2_SOCKET_CONNECTED 0
@@ -1224,6 +1202,8 @@ int _libssh2_pem_decode_sequence(unsigned char **data, unsigned int *datalen);
int _libssh2_pem_decode_integer(unsigned char **data, unsigned int *datalen,
unsigned char **i, unsigned int *ilen);
/* global.c */
void _libssh2_init_if_needed (void);
/* Conveniance-macros to allow code like this;
@@ -1271,5 +1251,4 @@ int _libssh2_pem_decode_integer(unsigned char **data, unsigned int *datalen,
#define ARRAY_SIZE(a) (sizeof ((a)) / sizeof ((a)[0]))
#endif /* LIBSSH2_H */

View File

@@ -1,4 +1,4 @@
/* Copyright (c) 2004-2007, Sara Golemon <sarag@libssh2.org>
/* Copyright (c) 2004-2007 Sara Golemon <sarag@libssh2.org>
* Copyright (c) 2009 by Daniel Stenberg
* All rights reserved.
*
@@ -49,6 +49,18 @@
#include <errno.h>
int libssh2_error(LIBSSH2_SESSION* session, int errcode, const char* errmsg)
{
session->err_msg = errmsg;
session->err_code = errcode;
#ifdef LIBSSH2DEBUG
_libssh2_debug(session, LIBSSH2_TRACE_ERROR, "%d - %s", session->err_code,
session->err_msg);
#endif
return errcode;
}
#ifdef WIN32
static int wsa2errno(void)
{
@@ -189,7 +201,8 @@ libssh2_base64_decode(LIBSSH2_SESSION *session, char **data,
*data = LIBSSH2_ALLOC(session, (3 * src_len / 4) + 1);
d = (unsigned char *) *data;
if (!d) {
return -1;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for base64 decoding");
}
for(s = (unsigned char *) src; ((char *) s) < (src + src_len); s++) {
@@ -217,7 +230,8 @@ libssh2_base64_decode(LIBSSH2_SESSION *session, char **data,
/* Invalid -- We have a byte which belongs exclusively to a partial
octet */
LIBSSH2_FREE(session, *data);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_INVAL,
"Invalid data (byte belonging to partial octet)");
}
*datalen = len;
@@ -514,22 +528,22 @@ void _libssh2_list_insert(struct list_node *after, /* insert before this */
*/
/* Offset between 1/1/1601 and 1/1/1970 in 100 nanosec units */
#define _W32_FT_OFFSET (116444736000000000ULL)
#define _W32_FT_OFFSET (116444736000000000)
int __cdecl gettimeofday(struct timeval *tp,
void *tzp)
{
union {
unsigned long long ns100; /*time since 1 Jan 1601 in 100ns units */
unsigned __int64 ns100; /*time since 1 Jan 1601 in 100ns units */
FILETIME ft;
} _now;
if(tp)
{
GetSystemTimeAsFileTime (&_now.ft);
tp->tv_usec=(long)((_now.ns100 / 10ULL) % 1000000ULL );
tp->tv_sec= (long)((_now.ns100 - _W32_FT_OFFSET) / 10000000ULL);
tp->tv_usec=(long)((_now.ns100 / 10) % 1000000 );
tp->tv_sec= (long)((_now.ns100 - _W32_FT_OFFSET) / 10000000);
}
/* Always return 0 as per Open Group Base Specifications Issue 6.
Do not set errno on error. */

View File

@@ -1,4 +1,4 @@
/* Copyright (C) 2009 Simon Josefsson
/* Copyright (C) 2009, 2010 Simon Josefsson
* Copyright (C) 2006, 2007 The Written Word, Inc. All rights reserved.
* Copyright (c) 2004-2006, Sara Golemon <sarag@libssh2.org>
*
@@ -105,12 +105,13 @@ _libssh2_rsa_sha1_verify(libssh2_rsa_ctx * rsactx,
unsigned char hash[SHA_DIGEST_LENGTH];
int ret;
SHA1(m, m_len, hash);
libssh2_sha1(m, m_len, hash);
ret = RSA_verify(NID_sha1, hash, SHA_DIGEST_LENGTH,
(unsigned char *) sig, sig_len, rsactx);
return (ret == 1) ? 0 : -1;
}
#if LIBSSH2_DSA
int
_libssh2_dsa_new(libssh2_dsa_ctx ** dsactx,
const unsigned char *p,
@@ -166,6 +167,7 @@ _libssh2_dsa_sha1_verify(libssh2_dsa_ctx * dsactx,
return (ret == 1) ? 0 : -1;
}
#endif /* LIBSSH_DSA */
int
_libssh2_cipher_init(_libssh2_cipher_ctx * h,
@@ -199,6 +201,8 @@ _libssh2_cipher_crypt(_libssh2_cipher_ctx * ctx,
return ret == 1 ? 0 : 1;
}
#if LIBSSH2_AES_CTR && !defined(HAVE_EVP_AES128_CTR)
#include <openssl/aes.h>
typedef struct
@@ -300,6 +304,7 @@ _libssh2_EVP_aes_256_ctr(void)
{
return make_ctr_evp (32);
}
#endif /* LIBSSH2_AES_CTR */
/* TODO: Optionally call a passphrase callback specified by the
* calling program
@@ -353,18 +358,13 @@ _libssh2_rsa_new_private(libssh2_rsa_ctx ** rsa,
(pem_read_bio_func) &PEM_read_bio_RSAPrivateKey;
(void) session;
if (!EVP_get_cipherbyname("des")) {
/* If this cipher isn't loaded it's a pretty good indication that none are.
* I have *NO DOUBT* that there's a better way to deal with this ($#&%#$(%$#(
* Someone buy me an OpenSSL manual and I'll read up on it.
*/
OpenSSL_add_all_ciphers();
}
_libssh2_init_if_needed ();
return read_private_key_from_file((void **) rsa, read_rsa,
filename, passphrase);
}
#if LIBSSH2_DSA
int
_libssh2_dsa_new_private(libssh2_dsa_ctx ** dsa,
LIBSSH2_SESSION * session,
@@ -374,17 +374,12 @@ _libssh2_dsa_new_private(libssh2_dsa_ctx ** dsa,
(pem_read_bio_func) &PEM_read_bio_DSAPrivateKey;
(void) session;
if (!EVP_get_cipherbyname("des")) {
/* If this cipher isn't loaded it's a pretty good indication that none are.
* I have *NO DOUBT* that there's a better way to deal with this ($#&%#$(%$#(
* Someone buy me an OpenSSL manual and I'll read up on it.
*/
OpenSSL_add_all_ciphers();
}
_libssh2_init_if_needed ();
return read_private_key_from_file((void **) dsa, read_dsa,
filename, passphrase);
}
#endif /* LIBSSH_DSA */
int
_libssh2_rsa_sha1_sign(LIBSSH2_SESSION * session,
@@ -417,6 +412,7 @@ _libssh2_rsa_sha1_sign(LIBSSH2_SESSION * session,
return 0;
}
#if LIBSSH2_DSA
int
_libssh2_dsa_sha1_sign(libssh2_dsa_ctx * dsactx,
const unsigned char *hash,
@@ -451,5 +447,28 @@ _libssh2_dsa_sha1_sign(libssh2_dsa_ctx * dsactx,
return 0;
}
#endif /* LIBSSH_DSA */
void
libssh2_sha1(const unsigned char *message, unsigned long len,
unsigned char *out)
{
EVP_MD_CTX ctx;
EVP_DigestInit(&ctx, EVP_get_digestbyname("sha1"));
EVP_DigestUpdate(&ctx, message, len);
EVP_DigestFinal(&ctx, out, NULL);
}
void
libssh2_md5(const unsigned char *message, unsigned long len,
unsigned char *out)
{
EVP_MD_CTX ctx;
EVP_DigestInit(&ctx, EVP_get_digestbyname("md5"));
EVP_DigestUpdate(&ctx, message, len);
EVP_DigestFinal(&ctx, out, NULL);
}
#endif /* !LIBSSH2_LIBGCRYPT */

View File

@@ -1,4 +1,4 @@
/* Copyright (C) 2009 Simon Josefsson
/* Copyright (C) 2009, 2010 Simon Josefsson
* Copyright (C) 2006, 2007 The Written Word, Inc. All rights reserved.
*
* Author: Simon Josefsson
@@ -76,6 +76,7 @@
# define LIBSSH2_AES_CTR 1
# define LIBSSH2_AES 1
#else
# define LIBSSH2_AES_CTR 0
# define LIBSSH2_AES 0
#endif
@@ -105,17 +106,17 @@
#define libssh2_random(buf, len) RAND_bytes ((buf), (len))
#define libssh2_sha1_ctx SHA_CTX
#define libssh2_sha1_init(ctx) SHA1_Init(ctx)
#define libssh2_sha1_update(ctx, data, len) SHA1_Update(&(ctx), data, len)
#define libssh2_sha1_final(ctx, out) SHA1_Final(out, &(ctx))
#define libssh2_sha1(message, len, out) SHA1(message, len, out)
#define libssh2_sha1_ctx EVP_MD_CTX
#define libssh2_sha1_init(ctx) EVP_DigestInit(ctx, EVP_get_digestbyname("sha1"))
#define libssh2_sha1_update(ctx, data, len) EVP_DigestUpdate(&(ctx), data, len)
#define libssh2_sha1_final(ctx, out) EVP_DigestFinal(&(ctx), out, NULL)
void libssh2_sha1(const unsigned char *message, unsigned long len, unsigned char *out);
#define libssh2_md5_ctx MD5_CTX
#define libssh2_md5_init(ctx) MD5_Init(ctx)
#define libssh2_md5_update(ctx, data, len) MD5_Update(&(ctx), data, len)
#define libssh2_md5_final(ctx, out) MD5_Final(out, &(ctx))
#define libssh2_md5(message, len, out) MD5(message, len, out)
#define libssh2_md5_ctx EVP_MD_CTX
#define libssh2_md5_init(ctx) EVP_DigestInit(ctx, EVP_get_digestbyname("md5"))
#define libssh2_md5_update(ctx, data, len) EVP_DigestUpdate(&(ctx), data, len)
#define libssh2_md5_final(ctx, out) EVP_DigestFinal(&(ctx), out, NULL)
void libssh2_md5(const unsigned char *message, unsigned long len, unsigned char *out);
#define libssh2_hmac_ctx HMAC_CTX
#define libssh2_hmac_sha1_init(ctx, key, keylen) \
@@ -129,7 +130,8 @@
#define libssh2_hmac_final(ctx, data) HMAC_Final(&(ctx), data, NULL)
#define libssh2_hmac_cleanup(ctx) HMAC_cleanup(ctx)
#define libssh2_crypto_init()
#define libssh2_crypto_init() OpenSSL_add_all_algorithms()
#define libssh2_crypto_exit()
#define libssh2_rsa_ctx RSA
@@ -197,9 +199,15 @@ int _libssh2_dsa_sha1_sign(libssh2_dsa_ctx * dsactx,
#define _libssh2_cipher_aes256 EVP_aes_256_cbc
#define _libssh2_cipher_aes192 EVP_aes_192_cbc
#define _libssh2_cipher_aes128 EVP_aes_128_cbc
#ifdef HAVE_EVP_AES128_CTR
#define _libssh2_cipher_aes128ctr EVP_aes_128_ctr
#define _libssh2_cipher_aes192ctr EVP_aes_192_ctr
#define _libssh2_cipher_aes256ctr EVP_aes_256_ctr
#else
#define _libssh2_cipher_aes128ctr _libssh2_EVP_aes_128_ctr
#define _libssh2_cipher_aes192ctr _libssh2_EVP_aes_192_ctr
#define _libssh2_cipher_aes256ctr _libssh2_EVP_aes_256_ctr
#endif
#define _libssh2_cipher_blowfish EVP_bf_cbc
#define _libssh2_cipher_arcfour EVP_rc4
#define _libssh2_cipher_cast5 EVP_cast5_cbc

View File

@@ -141,8 +141,8 @@ packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data,
channel = LIBSSH2_ALLOC(session, sizeof(LIBSSH2_CHANNEL));
if (!channel) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate a channel for new connection",
0);
"Unable to allocate a channel for "
"new connection");
failure_code = 4; /* SSH_OPEN_RESOURCE_SHORTAGE */
listen_state->state = libssh2_NB_state_sent;
break;
@@ -159,8 +159,8 @@ packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data,
1);
if (!channel->channel_type) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate a channel for new connection",
0);
"Unable to allocate a channel for new"
" connection");
LIBSSH2_FREE(session, channel);
failure_code = 4; /* SSH_OPEN_RESOURCE_SHORTAGE */
listen_state->state = libssh2_NB_state_sent;
@@ -212,11 +212,10 @@ packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data,
if (rc == PACKET_EAGAIN)
return rc;
else if (rc) {
libssh2_error(session, rc,
"Unable to send channel "
"open confirmation", 0);
listen_state->state = libssh2_NB_state_idle;
return rc;
return libssh2_error(session, rc,
"Unable to send channel "
"open confirmation");
}
/* Link the channel into the end of the queue list */
@@ -253,9 +252,9 @@ packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data,
if (rc == PACKET_EAGAIN) {
return rc;
} else if (rc) {
libssh2_error(session, rc, "Unable to send open failure", 0);
listen_state->state = libssh2_NB_state_idle;
return rc;
return libssh2_error(session, rc, "Unable to send open failure");
}
listen_state->state = libssh2_NB_state_idle;
return 0;
@@ -308,8 +307,7 @@ packet_x11_open(LIBSSH2_SESSION * session, unsigned char *data,
channel = LIBSSH2_ALLOC(session, sizeof(LIBSSH2_CHANNEL));
if (!channel) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate a channel for new connection",
0);
"Unable to allocate a channel for new connection");
failure_code = 4; /* SSH_OPEN_RESOURCE_SHORTAGE */
goto x11_exit;
}
@@ -322,8 +320,7 @@ packet_x11_open(LIBSSH2_SESSION * session, unsigned char *data,
1);
if (!channel->channel_type) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate a channel for new connection",
0);
"Unable to allocate a channel for new connection");
LIBSSH2_FREE(session, channel);
failure_code = 4; /* SSH_OPEN_RESOURCE_SHORTAGE */
goto x11_exit;
@@ -369,10 +366,10 @@ packet_x11_open(LIBSSH2_SESSION * session, unsigned char *data,
if (rc == PACKET_EAGAIN) {
return rc;
} else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send channel open confirmation", 0);
x11open_state->state = libssh2_NB_state_idle;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send channel open "
"confirmation");
}
/* Link the channel into the session */
@@ -409,9 +406,8 @@ packet_x11_open(LIBSSH2_SESSION * session, unsigned char *data,
if (rc == PACKET_EAGAIN) {
return rc;
} else if (rc) {
libssh2_error(session, rc, "Unable to send open failure", 0);
x11open_state->state = libssh2_NB_state_idle;
return rc;
return libssh2_error(session, rc, "Unable to send open failure");
}
x11open_state->state = libssh2_NB_state_idle;
return 0;
@@ -456,9 +452,6 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
/* Calling app has given the OK, Process it anyway */
macstate = LIBSSH2_MAC_CONFIRMED;
} else {
libssh2_error(session, LIBSSH2_ERROR_INVALID_MAC,
"Invalid Message Authentication Code received",
0);
if (session->ssh_msg_disconnect) {
LIBSSH2_DISCONNECT(session, SSH_DISCONNECT_MAC_ERROR,
"Invalid MAC received",
@@ -466,7 +459,8 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
"", 0);
}
LIBSSH2_FREE(session, data);
return LIBSSH2_ERROR_INVALID_MAC;
return libssh2_error(session, LIBSSH2_ERROR_INVALID_MAC,
"Invalid MAC received");
}
}
@@ -535,9 +529,8 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
LIBSSH2_FREE(session, data);
session->socket_state = LIBSSH2_SOCKET_DISCONNECTED;
session->packAdd_state = libssh2_NB_state_idle;
libssh2_error(session, LIBSSH2_ERROR_SOCKET_DISCONNECT,
"socket disconnect", 0);
return LIBSSH2_ERROR_SOCKET_DISCONNECT;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_DISCONNECT,
"socket disconnect");
}
break;
@@ -636,8 +629,7 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
if (!session->packAdd_channel) {
libssh2_error(session, LIBSSH2_ERROR_CHANNEL_UNKNOWN,
"Packet received for unknown channel, ignoring",
0);
"Packet received for unknown channel, ignoring");
LIBSSH2_FREE(session, data);
session->packAdd_state = libssh2_NB_state_idle;
return 0;
@@ -693,7 +685,7 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
libssh2_error(session,
LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED,
"Packet contains more data than we offered"
" to receive, truncating", 0);
" to receive, truncating");
datalen =
session->packAdd_channel->remote.packet_size +
session->packAdd_data_head;
@@ -706,8 +698,7 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
libssh2_error(session,
LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED,
"The current receive window is full,"
" data ignored",
0);
" data ignored");
LIBSSH2_FREE(session, data);
session->packAdd_state = libssh2_NB_state_idle;
return 0;
@@ -720,8 +711,7 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
libssh2_error(session,
LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED,
"Remote sent more data than current "
"window allows, truncating",
0);
"window allows, truncating");
datalen =
session->packAdd_channel->remote.window_size +
session->packAdd_data_head;
@@ -871,12 +861,16 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
if (session->packAdd_channel && bytestoadd) {
session->packAdd_channel->local.window_size += bytestoadd;
}
_libssh2_debug(session, LIBSSH2_TRACE_CONN,
"Window adjust received for channel %lu/%lu, adding %lu bytes, new window_size=%lu",
session->packAdd_channel->local.id,
session->packAdd_channel->remote.id,
bytestoadd,
session->packAdd_channel->local.window_size);
if(session->packAdd_channel)
_libssh2_debug(session, LIBSSH2_TRACE_CONN,
"Window adjust received for channel %lu/%lu, adding %lu bytes, new window_size=%lu",
session->packAdd_channel->local.id,
session->packAdd_channel->remote.id,
bytestoadd,
session->packAdd_channel->local.window_size);
else
_libssh2_debug(session, LIBSSH2_TRACE_CONN,
"Window adjust for non-existing channel!");
LIBSSH2_FREE(session, data);
session->packAdd_state = libssh2_NB_state_idle;
@@ -1143,10 +1137,9 @@ _libssh2_packet_burn(LIBSSH2_SESSION * session,
/*
* _libssh2_packet_requirev
*
* Loops _libssh2_transport_read() until one of a list of packet types requested is
* available
* SSH_DISCONNECT or a SOCKET_DISCONNECTED will cause a bailout
* packet_types is a null terminated list of packet_type numbers
* Loops _libssh2_transport_read() until one of a list of packet types
* requested is available. SSH_DISCONNECT or a SOCKET_DISCONNECTED will cause
* a bailout. packet_types is a null terminated list of packet_type numbers
*/
int
@@ -1176,7 +1169,8 @@ _libssh2_packet_requirev(LIBSSH2_SESSION * session,
return ret;
}
if (ret <= 0) {
long left = LIBSSH2_READ_TIMEOUT - (long)(time(NULL) - state->start);
long left = LIBSSH2_READ_TIMEOUT -
(long)(time(NULL) - state->start);
if (left <= 0) {
state->start = 0;

View File

@@ -101,18 +101,11 @@ static const LIBSSH2_PUBLICKEY_CODE_LIST publickey_status_codes[] = {
*
* Format an error message from a status code
*/
#define LIBSSH2_PUBLICKEY_STATUS_TEXT_START "Publickey Subsystem Error: \""
#define LIBSSH2_PUBLICKEY_STATUS_TEXT_MID "\" Server Reports: \""
#define LIBSSH2_PUBLICKEY_STATUS_TEXT_END "\""
static void
publickey_status_error(const LIBSSH2_PUBLICKEY * pkey,
LIBSSH2_SESSION * session, int status,
const unsigned char *message, int message_len)
publickey_status_error(const LIBSSH2_PUBLICKEY *pkey,
LIBSSH2_SESSION *session, int status)
{
const char *status_text;
int status_text_len;
char *m, *s;
int m_len;
const char *msg;
/* GENERAL_FAILURE got remapped between version 1 and 2 */
if (status == 6 && pkey && pkey->version == 1) {
@@ -120,38 +113,12 @@ publickey_status_error(const LIBSSH2_PUBLICKEY * pkey,
}
if (status < 0 || status > LIBSSH2_PUBLICKEY_STATUS_CODE_MAX) {
status_text = "unknown";
status_text_len = sizeof("unknown") - 1;
msg = "unknown";
} else {
status_text = publickey_status_codes[status].name;
status_text_len = publickey_status_codes[status].name_len;
msg = publickey_status_codes[status].name;
}
m_len =
(sizeof(LIBSSH2_PUBLICKEY_STATUS_TEXT_START) - 1) + status_text_len +
(sizeof(LIBSSH2_PUBLICKEY_STATUS_TEXT_MID) - 1) + message_len +
(sizeof(LIBSSH2_PUBLICKEY_STATUS_TEXT_END) - 1);
m = LIBSSH2_ALLOC(session, m_len + 1);
if (!m) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for status message", 0);
return;
}
s = m;
memcpy(s, LIBSSH2_PUBLICKEY_STATUS_TEXT_START,
sizeof(LIBSSH2_PUBLICKEY_STATUS_TEXT_START) - 1);
s += sizeof(LIBSSH2_PUBLICKEY_STATUS_TEXT_START) - 1;
memcpy(s, status_text, status_text_len);
s += status_text_len;
memcpy(s, LIBSSH2_PUBLICKEY_STATUS_TEXT_MID,
sizeof(LIBSSH2_PUBLICKEY_STATUS_TEXT_MID) - 1);
s += sizeof(LIBSSH2_PUBLICKEY_STATUS_TEXT_MID) - 1;
memcpy(s, message, message_len);
s += message_len;
memcpy(s, LIBSSH2_PUBLICKEY_STATUS_TEXT_END,
sizeof(LIBSSH2_PUBLICKEY_STATUS_TEXT_END) - 1);
s += sizeof(LIBSSH2_PUBLICKEY_STATUS_TEXT_END);
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, m, 1);
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, msg);
}
/*
@@ -173,18 +140,17 @@ publickey_packet_receive(LIBSSH2_PUBLICKEY * pkey,
if (rc == PACKET_EAGAIN) {
return rc;
} else if (rc != 4) {
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL,
"Invalid response from publickey subsystem", 0);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL,
"Invalid response from publickey subsystem");
}
pkey->receive_packet_len = _libssh2_ntohu32(buffer);
pkey->receive_packet =
LIBSSH2_ALLOC(session, pkey->receive_packet_len);
if (!pkey->receive_packet) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate publickey response buffer", 0);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate publickey response "
"buffer");
}
pkey->receive_state = libssh2_NB_state_sent;
@@ -196,13 +162,12 @@ publickey_packet_receive(LIBSSH2_PUBLICKEY * pkey,
if (rc == PACKET_EAGAIN) {
return rc;
} else if (rc != (int)pkey->receive_packet_len) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for publickey subsystem response packet",
0);
LIBSSH2_FREE(session, pkey->receive_packet);
pkey->receive_packet = NULL;
pkey->receive_state = libssh2_NB_state_idle;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for publickey subsystem "
"response packet");
}
*data = pkey->receive_packet;
@@ -268,60 +233,36 @@ publickey_response_success(LIBSSH2_PUBLICKEY * pkey)
if (rc == PACKET_EAGAIN) {
return rc;
} else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for response from publickey subsystem",
0);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for response from "
"publickey subsystem");
}
s = data;
if ((response = publickey_response_id(&s, data_len)) < 0) {
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL,
"Invalid publickey subsystem response code", 0);
LIBSSH2_FREE(session, data);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL,
"Invalid publickey subsystem response code");
}
switch (response) {
case LIBSSH2_PUBLICKEY_RESPONSE_STATUS:
/* Error, or processing complete */
{
unsigned long status, descr_len, lang_len;
unsigned char *descr, *lang;
unsigned long status = _libssh2_ntohu32(s);
status = _libssh2_ntohu32(s);
s += 4;
descr_len = _libssh2_ntohu32(s);
s += 4;
descr = s;
s += descr_len;
lang_len = _libssh2_ntohu32(s);
s += 4;
lang = s;
s += lang_len;
if (s > data + data_len) {
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL,
"Malformed publickey subsystem packet", 0);
LIBSSH2_FREE(session, data);
return -1;
}
if (status == LIBSSH2_PUBLICKEY_SUCCESS) {
LIBSSH2_FREE(session, data);
return 0;
}
publickey_status_error(pkey, session, status, descr,
descr_len);
LIBSSH2_FREE(session, data);
if (status == LIBSSH2_PUBLICKEY_SUCCESS)
return 0;
publickey_status_error(pkey, session, status);
return -1;
}
default:
/* Unknown/Unexpected */
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL,
"Unexpected publickey subsystem response, ignoring",
0);
"Unexpected publickey subsystem response, ignoring");
LIBSSH2_FREE(session, data);
data = NULL;
}
@@ -372,13 +313,13 @@ libssh2_publickey_init(LIBSSH2_SESSION * session)
LIBSSH2_ERROR_EAGAIN)) {
/* The error state is already set, so leave it */
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block to startup channel", 0);
"Would block to startup channel");
return NULL;
} else if (!session->pkeyInit_channel
&& (libssh2_session_last_errno(session) !=
LIBSSH2_ERROR_EAGAIN)) {
libssh2_error(session, LIBSSH2_ERROR_CHANNEL_FAILURE,
"Unable to startup channel", 0);
"Unable to startup channel");
goto err_exit;
}
} while (!session->pkeyInit_channel);
@@ -393,11 +334,11 @@ libssh2_publickey_init(LIBSSH2_SESSION * session)
"publickey", strlen("publickey"));
if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block starting publickey subsystem", 0);
"Would block starting publickey subsystem");
return NULL;
} else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_CHANNEL_FAILURE,
"Unable to request publickey subsystem", 0);
"Unable to request publickey subsystem");
goto err_exit;
}
@@ -409,7 +350,7 @@ libssh2_publickey_init(LIBSSH2_SESSION * session)
LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE);
if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block starting publickey subsystem", 0);
"Would block starting publickey subsystem");
return NULL;
}
@@ -417,7 +358,7 @@ libssh2_publickey_init(LIBSSH2_SESSION * session)
LIBSSH2_ALLOC(session, sizeof(LIBSSH2_PUBLICKEY));
if (!session->pkeyInit_pkey) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate a new publickey structure", 0);
"Unable to allocate a new publickey structure");
goto err_exit;
}
memset(session->pkeyInit_pkey, 0, sizeof(LIBSSH2_PUBLICKEY));
@@ -446,11 +387,11 @@ libssh2_publickey_init(LIBSSH2_SESSION * session)
(char *) buffer, (s - buffer));
if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block sending publickey version packet", 0);
"Would block sending publickey version packet");
return NULL;
} else if ((s - buffer) != rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send publickey version packet", 0);
"Unable to send publickey version packet");
goto err_exit;
}
@@ -464,13 +405,13 @@ libssh2_publickey_init(LIBSSH2_SESSION * session)
&session->pkeyInit_data_len);
if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block waiting for response from publickey subsystem",
0);
"Would block waiting for response from "
"publickey subsystem");
return NULL;
} else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for response from publickey subsystem",
0);
"Timeout waiting for response from "
"publickey subsystem");
goto err_exit;
}
@@ -478,7 +419,7 @@ libssh2_publickey_init(LIBSSH2_SESSION * session)
if ((response =
publickey_response_id(&s, session->pkeyInit_data_len)) < 0) {
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL,
"Invalid publickey subsystem response code", 0);
"Invalid publickey subsystem response code");
goto err_exit;
}
@@ -504,13 +445,12 @@ libssh2_publickey_init(LIBSSH2_SESSION * session)
session->pkeyInit_data + session->pkeyInit_data_len) {
libssh2_error(session,
LIBSSH2_ERROR_PUBLICKEY_PROTOCOL,
"Malformed publickey subsystem packet",
0);
"Malformed publickey subsystem packet");
goto err_exit;
}
publickey_status_error(NULL, session, status,
descr, descr_len);
publickey_status_error(NULL, session, status);
goto err_exit;
}
@@ -536,8 +476,8 @@ libssh2_publickey_init(LIBSSH2_SESSION * session)
default:
/* Unknown/Unexpected */
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL,
"Unexpected publickey subsystem response, ignoring",
0);
"Unexpected publickey subsystem response, "
"ignoring");
LIBSSH2_FREE(session, session->pkeyInit_data);
session->pkeyInit_data = NULL;
}
@@ -551,7 +491,7 @@ libssh2_publickey_init(LIBSSH2_SESSION * session)
rc = libssh2_channel_close(session->pkeyInit_channel);
if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block closing channel", 0);
"Would block closing channel");
return NULL;
}
}
@@ -615,10 +555,9 @@ libssh2_publickey_add_ex(LIBSSH2_PUBLICKEY * pkey, const unsigned char *name,
pkey->add_packet = LIBSSH2_ALLOC(session, packet_len);
if (!pkey->add_packet) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for publickey \"add\" packet",
0);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for "
"publickey \"add\" packet");
}
pkey->add_s = pkey->add_packet;
@@ -684,11 +623,10 @@ libssh2_publickey_add_ex(LIBSSH2_PUBLICKEY * pkey, const unsigned char *name,
if (rc == PACKET_EAGAIN) {
return rc;
} else if ((pkey->add_s - pkey->add_packet) != rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send publickey add packet", 0);
LIBSSH2_FREE(session, pkey->add_packet);
pkey->add_packet = NULL;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send publickey add packet");
}
LIBSSH2_FREE(session, pkey->add_packet);
pkey->add_packet = NULL;
@@ -725,10 +663,9 @@ libssh2_publickey_remove_ex(LIBSSH2_PUBLICKEY * pkey,
pkey->remove_packet = LIBSSH2_ALLOC(session, packet_len);
if (!pkey->remove_packet) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for publickey \"remove\" packet",
0);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for "
"publickey \"remove\" packet");
}
pkey->remove_s = pkey->remove_packet;
@@ -760,12 +697,11 @@ libssh2_publickey_remove_ex(LIBSSH2_PUBLICKEY * pkey,
if (rc == PACKET_EAGAIN) {
return rc;
} else if ((pkey->remove_s - pkey->remove_packet) != rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send publickey remove packet", 0);
LIBSSH2_FREE(session, pkey->remove_packet);
pkey->remove_packet = NULL;
pkey->remove_state = libssh2_NB_state_idle;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send publickey remove packet");
}
LIBSSH2_FREE(session, pkey->remove_packet);
pkey->remove_packet = NULL;
@@ -823,10 +759,9 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys,
if (rc == PACKET_EAGAIN) {
return rc;
} else if ((pkey->listFetch_s - pkey->listFetch_buffer) != rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send publickey list packet", 0);
pkey->listFetch_state = libssh2_NB_state_idle;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send publickey list packet");
}
pkey->listFetch_state = libssh2_NB_state_sent;
@@ -839,8 +774,8 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys,
return rc;
} else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for response from publickey subsystem",
0);
"Timeout waiting for response from "
"publickey subsystem");
goto err_exit;
}
@@ -849,7 +784,7 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys,
publickey_response_id(&pkey->listFetch_s,
pkey->listFetch_data_len)) < 0) {
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL,
"Invalid publickey subsystem response code", 0);
"Invalid publickey subsystem response code");
goto err_exit;
}
@@ -874,7 +809,7 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys,
if (pkey->listFetch_s >
pkey->listFetch_data + pkey->listFetch_data_len) {
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL,
"Malformed publickey subsystem packet", 0);
"Malformed publickey subsystem packet");
goto err_exit;
}
@@ -887,8 +822,7 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys,
return 0;
}
publickey_status_error(pkey, session, status, descr,
descr_len);
publickey_status_error(pkey, session, status);
goto err_exit;
}
case LIBSSH2_PUBLICKEY_RESPONSE_PUBLICKEY:
@@ -903,8 +837,8 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys,
1) * sizeof(libssh2_publickey_list));
if (!newlist) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for publickey list",
0);
"Unable to allocate memory for "
"publickey list");
goto err_exit;
}
list = newlist;
@@ -921,8 +855,8 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys,
sizeof(libssh2_publickey_attribute));
if (!list[keys].attrs) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for publickey attributes",
0);
"Unable to allocate memory for "
"publickey attributes");
goto err_exit;
}
list[keys].attrs[0].name = "comment";
@@ -963,8 +897,8 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys,
sizeof(libssh2_publickey_attribute));
if (!list[keys].attrs) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for publickey attributes",
0);
"Unable to allocate memory for "
"publickey attributes");
goto err_exit;
}
for(i = 0; i < list[keys].num_attrs; i++) {
@@ -993,8 +927,7 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys,
default:
/* Unknown/Unexpected */
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL,
"Unexpected publickey subsystem response, ignoring",
0);
"Unexpected publickey subsystem response, ignoring");
LIBSSH2_FREE(session, pkey->listFetch_data);
pkey->listFetch_data = NULL;
}

217
src/scp.c
View File

@@ -44,7 +44,7 @@
/* Max. length of a quoted string after libssh2_shell_quotearg() processing */
#define libssh2_shell_quotedsize(s) (3 * strlen(s) + 2)
#define libssh2_shell_quotedsize(s) (3 * strlen(s) + 2)
/*
This function quotes a string in a way suitable to be used with a
@@ -59,32 +59,32 @@
The following special cases are handled:
o If the string contains an apostrophy itself, the apostrophy
character is written in quotation marks, e.g. "'".
The shell cannot handle the syntax 'doesn\'t', so we close the
current argument word, add the apostrophe in quotation marks "",
and open a new argument word instead (_ indicate the input
string characters):
_____ _ _
'doesn' "'" 't'
character is written in quotation marks, e.g. "'".
The shell cannot handle the syntax 'doesn\'t', so we close the
current argument word, add the apostrophe in quotation marks "",
and open a new argument word instead (_ indicate the input
string characters):
_____ _ _
'doesn' "'" 't'
Sequences of apostrophes are combined in one pair of quotation marks:
a'''b
becomes
_ ___ _
'a'"'''"'b'
Sequences of apostrophes are combined in one pair of quotation marks:
a'''b
becomes
_ ___ _
'a'"'''"'b'
o If the string contains an exclamation mark (!), the C-Shell
interprets it as an event number. Using \! (not within quotation
marks or single quotation marks) is a mechanism understood by
both Bourne Shell and C-Shell.
o If the string contains an exclamation mark (!), the C-Shell
interprets it as an event number. Using \! (not within quotation
marks or single quotation marks) is a mechanism understood by
both Bourne Shell and C-Shell.
If a quotation was already started, the argument word is closed
first:
a!b
If a quotation was already started, the argument word is closed
first:
a!b
become
_ _ _
'a'\!'b'
become
_ _ _
'a'\!'b'
The result buffer must be large enough for the expanded result. A
bad case regarding expansion is alternating characters and
@@ -96,7 +96,7 @@
This is the worst case.
Maximum length of the result:
1 + 6 * (length(input) + 1) / 2) + 1
1 + 6 * (length(input) + 1) / 2) + 1
=> 3 * length(input) + 2
@@ -130,8 +130,8 @@ libssh2_shell_quotearg(const char *path, unsigned char *buf,
/*
* Processing States:
* UQSTRING: unquoted string: ... -- used for quoting exclamation
* marks. This is the initial state
* UQSTRING: unquoted string: ... -- used for quoting exclamation
* marks. This is the initial state
* SQSTRING: single-qouted-string: '... -- any character may follow
* QSTRING: quoted string: "... -- only apostrophes may follow
*/
@@ -142,23 +142,23 @@ libssh2_shell_quotearg(const char *path, unsigned char *buf,
dst = buf;
while (*src && dst < endp - 1) {
switch (*src) {
/*
* Special handling for apostrophe.
* An apostrophe is always written in quotation marks, e.g.
* ' -> "'".
*/
switch (*src) {
/*
* Special handling for apostrophe.
* An apostrophe is always written in quotation marks, e.g.
* ' -> "'".
*/
case '\'':
switch (state) {
case UQSTRING: /* Unquoted string */
case UQSTRING: /* Unquoted string */
if (dst+1 >= endp)
return 0;
*dst++ = '"';
break;
case QSTRING: /* Continue quoted string */
case QSTRING: /* Continue quoted string */
break;
case SQSTRING: /* Close single quoted string */
case SQSTRING: /* Close single quoted string */
if (dst+2 >= endp)
return 0;
*dst++ = '\'';
@@ -187,10 +187,10 @@ libssh2_shell_quotearg(const char *path, unsigned char *buf,
case QSTRING:
if (dst+2 >= endp)
return 0;
*dst++ = '"'; /* Closing quotation mark */
*dst++ = '"'; /* Closing quotation mark */
*dst++ = '\\';
break;
case SQSTRING: /* Close single quoted string */
case SQSTRING: /* Close single quoted string */
if (dst+2 >= endp)
return 0;
*dst++ = '\'';
@@ -202,9 +202,9 @@ libssh2_shell_quotearg(const char *path, unsigned char *buf,
state = UQSTRING;
break;
/*
* Ordinary character: prefer single-quoted string
*/
/*
* Ordinary character: prefer single-quoted string
*/
default:
switch (state) {
@@ -216,17 +216,17 @@ libssh2_shell_quotearg(const char *path, unsigned char *buf,
case QSTRING:
if (dst+2 >= endp)
return 0;
*dst++ = '"'; /* Closing quotation mark */
*dst++ = '"'; /* Closing quotation mark */
*dst++ = '\'';
break;
case SQSTRING: /* Continue single quoted string */
case SQSTRING: /* Continue single quoted string */
break;
default:
break;
}
state = SQSTRING; /* Start single-quoted string */
state = SQSTRING; /* Start single-quoted string */
break;
}
}
if (dst+1 >= endp)
return 0;
@@ -234,7 +234,7 @@ libssh2_shell_quotearg(const char *path, unsigned char *buf,
}
switch (state) {
case UQSTRING:
case UQSTRING:
break;
case QSTRING: /* Close quoted string */
if (dst+1 >= endp)
@@ -286,8 +286,8 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
if (!session->scpRecv_command) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate a command buffer for SCP session",
0);
"Unable to allocate a command buffer for "
"SCP session");
return NULL;
}
@@ -324,7 +324,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
}
else {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block starting up channel", 0);
"Would block starting up channel");
}
return NULL;
}
@@ -340,7 +340,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
session->scpRecv_command_len);
if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block requesting SCP startup", 0);
"Would block requesting SCP startup");
return NULL;
} else if (rc) {
LIBSSH2_FREE(session, session->scpRecv_command);
@@ -362,7 +362,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
(char *) session->scpRecv_response, 1);
if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block sending initial wakeup", 0);
"Would block sending initial wakeup");
return NULL;
} else if (rc != 1) {
goto scp_recv_error;
@@ -387,12 +387,12 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
session->scpRecv_response_len, 1);
if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block waiting for SCP response", 0);
"Would block waiting for SCP response");
return NULL;
} else if (rc <= 0) {
/* Timeout, give up */
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Timed out waiting for SCP response", 0);
"Timed out waiting for SCP response");
goto scp_recv_error;
}
session->scpRecv_response_len++;
@@ -403,8 +403,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
* we are successful it will be replaced
*/
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Invalid data in SCP response, missing Time data",
0);
"Invalid data in SCP response, missing Time data");
session->scpRecv_err_len =
_libssh2_channel_packet_data_len(session->
@@ -427,16 +426,18 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
* it is already in the systems so it can't return
* PACKET_EAGAIN
*/
LIBSSH2_FREE(session, session->scpRecv_err_msg);
session->scpRecv_err_msg = NULL;
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Unknown error while getting error string",
0);
goto scp_recv_error;
"Unknown error" );
}
else
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"SCP protocol error");
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
session->scpRecv_err_msg, 1);
/* TODO: for debugging purposes, the
session->scpRecv_err_msg should be displayed here
when available */
LIBSSH2_FREE(session, session->scpRecv_err_msg);
session->scpRecv_err_msg = NULL;
goto scp_recv_error;
}
@@ -458,7 +459,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
scpRecv_response[session->scpRecv_response_len - 1] !=
'\n')) {
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Invalid data in SCP response", 0);
"Invalid data in SCP response");
goto scp_recv_error;
}
@@ -470,8 +471,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
LIBSSH2_SCP_RESPONSE_BUFLEN) {
/* You had your chance */
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Unterminated response from SCP server",
0);
"Unterminated response from SCP server");
goto scp_recv_error;
}
/* Way too short to be an SCP response, or not done yet,
@@ -494,8 +494,8 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
if (session->scpRecv_response_len < 8) {
/* EOL came too soon */
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Invalid response from SCP server, too short",
0);
"Invalid response from SCP server, "
"too short" );
goto scp_recv_error;
}
@@ -505,8 +505,8 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
if (!p || ((p - s) <= 0)) {
/* No spaces or space in the wrong spot */
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Invalid response from SCP server, malformed mtime",
0);
"Invalid response from SCP server, "
"malformed mtime");
goto scp_recv_error;
}
@@ -516,16 +516,14 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
session->scpRecv_mtime = strtol((char *) s, NULL, 10);
if (errno) {
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Invalid response from SCP server, invalid mtime",
0);
"Invalid response from SCP server, invalid mtime");
goto scp_recv_error;
}
s = (unsigned char *) strchr((char *) p, ' ');
if (!s || ((s - p) <= 0)) {
/* No spaces or space in the wrong spot */
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Invalid response from SCP server, malformed mtime.usec",
0);
"Invalid response from SCP server, malformed mtime.usec");
goto scp_recv_error;
}
@@ -535,8 +533,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
if (!p || ((p - s) <= 0)) {
/* No spaces or space in the wrong spot */
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Invalid response from SCP server, too short or malformed",
0);
"Invalid response from SCP server, too short or malformed");
goto scp_recv_error;
}
@@ -546,8 +543,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
session->scpRecv_atime = strtol((char *) s, NULL, 10);
if (errno) {
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Invalid response from SCP server, invalid atime",
0);
"Invalid response from SCP server, invalid atime");
goto scp_recv_error;
}
@@ -563,7 +559,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
scpRecv_response, 1);
if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block waiting to send SCP ACK", 0);
"Would block waiting to send SCP ACK");
return NULL;
} else if (rc != 1) {
goto scp_recv_error;
@@ -600,19 +596,19 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
session->scpRecv_response_len, 1);
if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block waiting for SCP response", 0);
"Would block waiting for SCP response");
return NULL;
} else if (rc <= 0) {
/* Timeout, give up */
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Timed out waiting for SCP response", 0);
"Timed out waiting for SCP response");
goto scp_recv_error;
}
session->scpRecv_response_len++;
if (session->scpRecv_response[0] != 'C') {
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Invalid response from SCP server", 0);
"Invalid response from SCP server");
goto scp_recv_error;
}
@@ -630,7 +626,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
scpRecv_response[session->scpRecv_response_len - 1] >
126))) {
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Invalid data in SCP response", 0);
"Invalid data in SCP response");
goto scp_recv_error;
}
@@ -642,8 +638,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
LIBSSH2_SCP_RESPONSE_BUFLEN) {
/* You had your chance */
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Unterminated response from SCP server",
0);
"Unterminated response from SCP server");
goto scp_recv_error;
}
/* Way too short to be an SCP response, or not done yet,
@@ -667,8 +662,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
if (session->scpRecv_response_len < 6) {
/* EOL came too soon */
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Invalid response from SCP server, too short",
0);
"Invalid response from SCP server, too short");
goto scp_recv_error;
}
@@ -678,8 +672,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
if (!p || ((p - s) <= 0)) {
/* No spaces or space in the wrong spot */
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Invalid response from SCP server, malformed mode",
0);
"Invalid response from SCP server, malformed mode");
goto scp_recv_error;
}
@@ -689,8 +682,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
session->scpRecv_mode = strtol(s, &e, 8);
if ((e && *e) || errno) {
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Invalid response from SCP server, invalid mode",
0);
"Invalid response from SCP server, invalid mode");
goto scp_recv_error;
}
@@ -698,8 +690,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
if (!s || ((s - p) <= 0)) {
/* No spaces or space in the wrong spot */
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Invalid response from SCP server, too short or malformed",
0);
"Invalid response from SCP server, too short or malformed");
goto scp_recv_error;
}
@@ -709,8 +700,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
session->scpRecv_size = scpsize_strtol(p, &e, 10);
if ((e && *e) || errno) {
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Invalid response from SCP server, invalid size",
0);
"Invalid response from SCP server, invalid size");
goto scp_recv_error;
}
@@ -726,7 +716,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
scpRecv_response, 1);
if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block sending SCP ACK", 0);
"Would block sending SCP ACK");
return NULL;
} else if (rc != 1) {
goto scp_recv_error;
@@ -800,8 +790,7 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
LIBSSH2_ALLOC(session, session->scpSend_command_len);
if (!session->scpSend_command) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate a command buffer for scp session",
0);
"Unable to allocate a command buffer for scp session");
return NULL;
}
@@ -838,7 +827,7 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
}
else {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block starting up channel", 0);
"Would block starting up channel");
}
return NULL;
}
@@ -854,7 +843,7 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
session->scpSend_command_len);
if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block requesting SCP startup", 0);
"Would block requesting SCP startup");
return NULL;
}
else if (rc) {
@@ -863,7 +852,7 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
LIBSSH2_FREE(session, session->scpSend_command);
session->scpSend_command = NULL;
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Unknown error while getting error string", 0);
"Unknown error while getting error string");
goto scp_send_error;
}
LIBSSH2_FREE(session, session->scpSend_command);
@@ -878,11 +867,11 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
(char *) session->scpSend_response, 1);
if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block waiting for response from remote", 0);
"Would block waiting for response from remote");
return NULL;
} else if ((rc <= 0) || (session->scpSend_response[0] != 0)) {
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Invalid ACK response from remote", 0);
"Invalid ACK response from remote");
goto scp_send_error;
}
@@ -907,11 +896,11 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
session->scpSend_response_len);
if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block sending time data for SCP file", 0);
"Would block sending time data for SCP file");
return NULL;
} else if (rc != (int)session->scpSend_response_len) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send time data for SCP file", 0);
"Unable to send time data for SCP file");
goto scp_send_error;
}
@@ -924,11 +913,11 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
(char *) session->scpSend_response, 1);
if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block waiting for response", 0);
"Would block waiting for response");
return NULL;
} else if ((rc <= 0) || (session->scpSend_response[0] != 0)) {
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Invalid ACK response from remote", 0);
"Invalid ACK response from remote");
goto scp_send_error;
}
@@ -965,11 +954,11 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
session->scpSend_response_len);
if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block send core file data for SCP file", 0);
"Would block send core file data for SCP file");
return NULL;
} else if (rc != (int)session->scpSend_response_len) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send core file data for SCP file", 0);
"Unable to send core file data for SCP file");
goto scp_send_error;
}
@@ -982,11 +971,11 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
(char *) session->scpSend_response, 1);
if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block waiting for response", 0);
"Would block waiting for response");
return NULL;
} else if (rc <= 0) {
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Invalid ACK response from remote", 0);
"Invalid ACK response from remote");
goto scp_send_error;
} else if (session->scpSend_response[0] != 0) {
/*
@@ -994,7 +983,7 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
* we are successful it will be replaced
*/
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Invalid ACK response from remote", 0);
"Invalid ACK response from remote");
session->scpSend_err_len =
_libssh2_channel_packet_data_len(session->scpSend_channel, 0);
@@ -1016,12 +1005,10 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
*/
LIBSSH2_FREE(session, session->scpSend_err_msg);
session->scpSend_err_msg = NULL;
goto scp_send_error;
}
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
session->scpSend_err_msg, 1);
session->scpSend_err_msg = NULL;
else
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"failed waiting for ACK");
goto scp_send_error;
}
}

View File

@@ -1,5 +1,6 @@
/* Copyright (c) 2004-2007 Sara Golemon <sarag@libssh2.org>
* Copyright (c) 2009 by Daniel Stenberg
* Copyright (c) 2010 Simon Josefsson <simon@josefsson.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms,
@@ -85,7 +86,7 @@ LIBSSH2_REALLOC_FUNC(libssh2_default_realloc)
*
* Wait for a hello from the remote host
* Allocate a buffer and store the banner in session->remote.banner
* Returns: 0 on success, PACKET_EAGAIN if read would block, 1 on failure
* Returns: 0 on success, PACKET_EAGAIN if read would block, negative on failure
*/
static int
banner_receive(LIBSSH2_SESSION * session)
@@ -129,7 +130,7 @@ banner_receive(LIBSSH2_SESSION * session)
/* Some kinda error */
session->banner_TxRx_state = libssh2_NB_state_idle;
session->banner_TxRx_total_send = 0;
return 1;
return -1;
}
if (ret == 0) {
@@ -141,7 +142,7 @@ banner_receive(LIBSSH2_SESSION * session)
/* NULLs are not allowed in SSH banners */
session->banner_TxRx_state = libssh2_NB_state_idle;
session->banner_TxRx_total_send = 0;
return 1;
return -1;
}
session->banner_TxRx_banner[banner_len++] = c;
@@ -158,13 +159,12 @@ banner_receive(LIBSSH2_SESSION * session)
session->banner_TxRx_total_send = 0;
if (!banner_len)
return 1;
return -1;
session->remote.banner = LIBSSH2_ALLOC(session, banner_len + 1);
if (!session->remote.banner) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Error allocating space for remote banner", 0);
return 1;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Error allocating space for remote banner");
}
memcpy(session->remote.banner, session->banner_TxRx_banner, banner_len);
session->remote.banner[banner_len] = '\0';
@@ -403,9 +403,8 @@ libssh2_banner_set(LIBSSH2_SESSION * session, const char *banner)
session->local.banner = LIBSSH2_ALLOC(session, banner_len + 3);
if (!session->local.banner) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for local banner", 0);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for local banner");
}
memcpy(session->local.banner, banner, banner_len);
@@ -458,7 +457,7 @@ libssh2_session_init_ex(LIBSSH2_ALLOC_FUNC((*my_alloc)),
session->api_block_mode = 1; /* blocking API by default */
_libssh2_debug(session, LIBSSH2_TRACE_TRANS,
"New session resource allocated");
libssh2_crypto_init();
_libssh2_init_if_needed ();
}
return session;
}
@@ -518,27 +517,55 @@ libssh2_session_callback_set(LIBSSH2_SESSION * session,
*/
int _libssh2_wait_socket(LIBSSH2_SESSION *session)
{
fd_set fd;
fd_set *writefd = NULL;
fd_set *readfd = NULL;
int dir;
int rc;
int dir;
int seconds_to_next;
FD_ZERO(&fd);
FD_SET(session->socket_fd, &fd);
rc = libssh2_keepalive_send (session, &seconds_to_next);
if (rc < 0)
return rc;
else {
/* figure out what to wait for */
dir = libssh2_session_block_directions(session);
/* now make sure we wait in the correct direction */
dir = libssh2_session_block_directions(session);
#ifdef HAVE_POLL
struct pollfd sockets[1];
if(dir & LIBSSH2_SESSION_BLOCK_INBOUND)
readfd = &fd;
sockets[0].fd = session->socket_fd;
sockets[0].events = 0;
sockets[0].revents = 0;
if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND)
writefd = &fd;
if(dir & LIBSSH2_SESSION_BLOCK_INBOUND)
sockets[0].events |= POLLIN;
/* Note that this COULD be made to use a timeout that perhaps could be
customizable by the app or something... */
rc = select(session->socket_fd + 1, readfd, writefd, NULL, NULL);
if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND)
sockets[0].events |= POLLOUT;
rc = poll(sockets, 1, seconds_to_next ? seconds_to_next / 1000 : -1);
#else
fd_set fd;
fd_set *writefd = NULL;
fd_set *readfd = NULL;
struct timeval tv;
tv.tv_sec = seconds_to_next;
tv.tv_usec = 0;
FD_ZERO(&fd);
FD_SET(session->socket_fd, &fd);
if(dir & LIBSSH2_SESSION_BLOCK_INBOUND)
readfd = &fd;
if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND)
writefd = &fd;
/* Note that this COULD be made to use a timeout that perhaps could be
customizable by the app or something... */
rc = select(session->socket_fd + 1, readfd, writefd, NULL,
seconds_to_next ? &tv : NULL);
#endif
}
if(rc <= 0) {
/* timeout (or error), bail out with a timeout error */
@@ -559,9 +586,8 @@ session_startup(LIBSSH2_SESSION *session, libssh2_socket_t sock)
"session_startup for socket %d", sock);
if (INVALID_SOCKET == sock) {
/* Did we forget something? */
libssh2_error(session, LIBSSH2_ERROR_SOCKET_NONE,
"Bad socket provided", 0);
return LIBSSH2_ERROR_SOCKET_NONE;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_NONE,
"Bad socket provided");
}
session->socket_fd = sock;
@@ -579,9 +605,8 @@ session_startup(LIBSSH2_SESSION *session, libssh2_socket_t sock)
if (session->startup_state == libssh2_NB_state_created) {
rc = banner_send(session);
if (rc) {
libssh2_error(session, rc,
"Failed sending banner", 0);
return rc;
return libssh2_error(session, rc,
"Failed sending banner");
}
session->startup_state = libssh2_NB_state_sent;
}
@@ -589,9 +614,8 @@ session_startup(LIBSSH2_SESSION *session, libssh2_socket_t sock)
if (session->startup_state == libssh2_NB_state_sent) {
rc = banner_receive(session);
if (rc) {
libssh2_error(session, rc,
"Failed getting banner", 0);
return rc;
return libssh2_error(session, rc,
"Failed getting banner");
}
session->startup_state = libssh2_NB_state_sent1;
@@ -600,9 +624,8 @@ session_startup(LIBSSH2_SESSION *session, libssh2_socket_t sock)
if (session->startup_state == libssh2_NB_state_sent1) {
rc = libssh2_kex_exchange(session, 0, &session->startup_key_state);
if (rc) {
libssh2_error(session, rc,
"Unable to exchange encryption keys", 0);
return rc;
return libssh2_error(session, rc,
"Unable to exchange encryption keys");
}
session->startup_state = libssh2_NB_state_sent2;
@@ -626,9 +649,8 @@ session_startup(LIBSSH2_SESSION *session, libssh2_socket_t sock)
rc = _libssh2_transport_write(session, session->startup_service,
sizeof("ssh-userauth") + 5 - 1);
if (rc) {
libssh2_error(session, rc,
"Unable to ask for ssh-userauth service", 0);
return rc;
return libssh2_error(session, rc,
"Unable to ask for ssh-userauth service");
}
session->startup_state = libssh2_NB_state_sent4;
@@ -650,9 +672,8 @@ session_startup(LIBSSH2_SESSION *session, libssh2_socket_t sock)
session->startup_service_length)) {
LIBSSH2_FREE(session, session->startup_data);
session->startup_data = NULL;
libssh2_error(session, LIBSSH2_ERROR_PROTO,
"Invalid response received from server", 0);
return LIBSSH2_ERROR_PROTO;
return libssh2_error(session, LIBSSH2_ERROR_PROTO,
"Invalid response received from server");
}
LIBSSH2_FREE(session, session->startup_data);
session->startup_data = NULL;
@@ -698,6 +719,7 @@ session_free(LIBSSH2_SESSION *session)
LIBSSH2_PACKET *pkg;
LIBSSH2_CHANNEL *ch;
LIBSSH2_LISTENER *l;
struct transportpacket *p = &session->packet;
if (session->free_state == libssh2_NB_state_idle) {
_libssh2_debug(session, LIBSSH2_TRACE_TRANS, "Freeing session resource",
@@ -904,11 +926,6 @@ session_free(LIBSSH2_SESSION *session)
LIBSSH2_FREE(session, session->scpSend_err_msg);
}
/* Free the error message, if we ar supposed to */
if (session->err_msg && session->err_should_free) {
LIBSSH2_FREE(session, session->err_msg);
}
/* Cleanup all remaining packets */
while ((pkg = _libssh2_list_first(&session->packets))) {
/* unlink the node */
@@ -919,6 +936,11 @@ session_free(LIBSSH2_SESSION *session)
LIBSSH2_FREE(session, pkg);
}
/* Cleanup remaining outgoing packet buffer */
if (p->outbuf) {
LIBSSH2_FREE(session, p->outbuf);
}
if(session->socket_prev_blockstate)
/* if the socket was previously blocking, put it back so */
session_nonblock(session->socket_fd, 0);
@@ -975,11 +997,10 @@ session_disconnect(LIBSSH2_SESSION *session, int reason,
s = session->disconnect_data =
LIBSSH2_ALLOC(session, session->disconnect_data_len);
if (!session->disconnect_data) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for disconnect packet",
0);
session->disconnect_state = libssh2_NB_state_idle;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for "
"disconnect packet");
}
*(s++) = SSH_MSG_DISCONNECT;
@@ -1079,22 +1100,19 @@ libssh2_session_methods(LIBSSH2_SESSION * session, int method_type)
case LIBSSH2_METHOD_LANG_CS:
return "";
break;
case LIBSSH2_METHOD_LANG_SC:
return "";
break;
default:
libssh2_error(session, LIBSSH2_ERROR_INVAL,
"Invalid parameter specified for method_type", 0);
"Invalid parameter specified for method_type");
return NULL;
break;
}
if (!method) {
libssh2_error(session, LIBSSH2_ERROR_METHOD_NONE,
"No method negotiated", 0);
"No method negotiated");
return NULL;
}
@@ -1120,6 +1138,8 @@ LIBSSH2_API int
libssh2_session_last_error(LIBSSH2_SESSION * session, char **errmsg,
int *errmsg_len, int want_buf)
{
size_t msglen = 0;
/* No error to report */
if (!session->err_code) {
if (errmsg) {
@@ -1139,29 +1159,24 @@ libssh2_session_last_error(LIBSSH2_SESSION * session, char **errmsg,
}
if (errmsg) {
char *serrmsg = session->err_msg ? session->err_msg : (char *) "";
int ownbuf = session->err_msg ? session->err_should_free : 0;
const char *error = session->err_msg ? session->err_msg : "";
msglen = strlen(error);
if (want_buf) {
if (ownbuf) {
/* Just give the calling program the buffer */
*errmsg = serrmsg;
session->err_should_free = 0;
} else {
/* Make a copy so the calling program can own it */
*errmsg = LIBSSH2_ALLOC(session, session->err_msglen + 1);
if (*errmsg) {
memcpy(*errmsg, session->err_msg, session->err_msglen);
(*errmsg)[session->err_msglen] = 0;
}
/* Make a copy so the calling program can own it */
*errmsg = LIBSSH2_ALLOC(session, msglen + 1);
if (*errmsg) {
memcpy(*errmsg, error, msglen);
(*errmsg)[msglen] = 0;
}
} else {
*errmsg = serrmsg;
}
else
*errmsg = (char *)error;
}
if (errmsg_len) {
*errmsg_len = session->err_msglen;
*errmsg_len = msglen;
}
return session->err_code;
@@ -1338,8 +1353,7 @@ libssh2_poll(LIBSSH2_POLLFD * fds, unsigned int nfds, long timeout)
default:
if (session)
libssh2_error(session, LIBSSH2_ERROR_INVALID_POLL_TYPE,
"Invalid descriptor passed to libssh2_poll()",
0);
"Invalid descriptor passed to libssh2_poll()");
return -1;
}
}
@@ -1386,8 +1400,7 @@ libssh2_poll(LIBSSH2_POLLFD * fds, unsigned int nfds, long timeout)
default:
if (session)
libssh2_error(session, LIBSSH2_ERROR_INVALID_POLL_TYPE,
"Invalid descriptor passed to libssh2_poll()",
0);
"Invalid descriptor passed to libssh2_poll()");
return -1;
}
}

View File

@@ -1,5 +1,5 @@
/* Copyright (c) 2004-2008, Sara Golemon <sarag@libssh2.org>
* Copyright (c) 2009 by Daniel Stenberg
* Copyright (c) 2009-2010 by Daniel Stenberg
* All rights reserved.
*
* Redistribution and use in source and binary forms,
@@ -122,9 +122,8 @@ sftp_packet_add(LIBSSH2_SFTP *sftp, unsigned char *data,
(int) data[0], data_len);
packet = LIBSSH2_ALLOC(session, sizeof(LIBSSH2_PACKET));
if (!packet) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate datablock for SFTP packet", 0);
return LIBSSH2_ERROR_ALLOC;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate datablock for SFTP packet");
}
memset(packet, 0, sizeof(LIBSSH2_PACKET));
@@ -175,25 +174,22 @@ sftp_packet_read(LIBSSH2_SFTP *sftp)
/* TODO: this is stupid since we can in fact get 1-3 bytes in a
legitimate working case as well if the connection happens to be
super slow or something */
libssh2_error(session, LIBSSH2_ERROR_CHANNEL_FAILURE,
"Read part of packet", 0);
return LIBSSH2_ERROR_CHANNEL_FAILURE;
return libssh2_error(session, LIBSSH2_ERROR_CHANNEL_FAILURE,
"Read part of packet");
}
packet_len = _libssh2_ntohu32(buffer);
_libssh2_debug(session, LIBSSH2_TRACE_SFTP,
"Data begin - Packet Length: %lu", packet_len);
if (packet_len > LIBSSH2_SFTP_PACKET_MAXLEN) {
libssh2_error(session, LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED,
"SFTP packet too large", 0);
return LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED;
return libssh2_error(session, LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED,
"SFTP packet too large");
}
packet = LIBSSH2_ALLOC(session, packet_len);
if (!packet) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate SFTP packet", 0);
return LIBSSH2_ERROR_ALLOC;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate SFTP packet");
}
packet_received = 0;
@@ -219,10 +215,9 @@ sftp_packet_read(LIBSSH2_SFTP *sftp)
return bytes_received;
}
else if (bytes_received < 0) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Receive error waiting for SFTP packet", 0);
LIBSSH2_FREE(session, packet);
return bytes_received;
return libssh2_error(session, bytes_received,
"Receive error waiting for SFTP packet");
}
packet_received += bytes_received;
}
@@ -560,11 +555,11 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session)
if (!session->sftpInit_channel) {
if (libssh2_session_last_errno(session) == LIBSSH2_ERROR_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block starting up channel", 0);
"Would block starting up channel");
}
else {
libssh2_error(session, LIBSSH2_ERROR_CHANNEL_FAILURE,
"Unable to startup channel", 0);
"Unable to startup channel");
session->sftpInit_state = libssh2_NB_state_idle;
}
return NULL;
@@ -580,11 +575,11 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session)
strlen("sftp"));
if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block to request SFTP subsystem", 0);
"Would block to request SFTP subsystem");
return NULL;
} else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_CHANNEL_FAILURE,
"Unable to request SFTP subsystem", 0);
"Unable to request SFTP subsystem");
goto sftp_init_error;
}
@@ -596,7 +591,7 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session)
LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE);
if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block requesting handle extended data", 0);
"Would block requesting handle extended data");
return NULL;
}
@@ -605,7 +600,7 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session)
LIBSSH2_ALLOC(session, sizeof(LIBSSH2_SFTP));
if (!sftp_handle) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate a new SFTP structure", 0);
"Unable to allocate a new SFTP structure");
goto sftp_init_error;
}
memset(sftp_handle, 0, sizeof(LIBSSH2_SFTP));
@@ -615,6 +610,7 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session)
_libssh2_htonu32(session->sftpInit_buffer, 5);
session->sftpInit_buffer[4] = SSH_FXP_INIT;
_libssh2_htonu32(session->sftpInit_buffer + 5, LIBSSH2_SFTP_VERSION);
session->sftpInit_sent = 0; /* nothing's sent yet */
_libssh2_debug(session, LIBSSH2_TRACE_SFTP,
"Sending FXP_INIT packet advertising version %d support",
@@ -624,36 +620,47 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session)
}
if (session->sftpInit_state == libssh2_NB_state_sent2) {
/* sent off what's left of the init buffer to send */
rc = _libssh2_channel_write(session->sftpInit_channel, 0,
(char *) session->sftpInit_buffer, 9);
(char *)session->sftpInit_buffer +
session->sftpInit_sent,
9 - session->sftpInit_sent);
if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block sending SSH_FXP_INIT", 0);
"Would block sending SSH_FXP_INIT");
return NULL;
} else if (9 != rc) {
}
else if(rc < 0) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send SSH_FXP_INIT", 0);
"Unable to send SSH_FXP_INIT");
goto sftp_init_error;
}
else {
/* add up the number of bytes sent */
session->sftpInit_sent += rc;
session->sftpInit_state = libssh2_NB_state_sent3;
if(session->sftpInit_sent == 9)
/* move on */
session->sftpInit_state = libssh2_NB_state_sent3;
/* if less than 9, we remain in this state to send more later on */
}
}
rc = sftp_packet_require(sftp_handle, SSH_FXP_VERSION,
0, &data, &data_len);
if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block waiting for response from SFTP subsystem",
0);
"Would block waiting for response from SFTP subsystem");
return NULL;
} else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for response from SFTP subsystem", 0);
"Timeout waiting for response from SFTP subsystem");
goto sftp_init_error;
}
if (data_len < 5) {
libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"Invalid SSH_FXP_VERSION response", 0);
"Invalid SSH_FXP_VERSION response");
goto sftp_init_error;
}
@@ -836,8 +843,7 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename,
if (!sftp->open_packet) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for FXP_OPEN or "
"FXP_OPENDIR packet",
0);
"FXP_OPENDIR packet");
return NULL;
}
/* Filetype in SFTP 3 and earlier */
@@ -876,8 +882,7 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename,
sftp->open_packet_len);
if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block sending FXP_OPEN or FXP_OPENDIR command",
0);
"Would block sending FXP_OPEN or FXP_OPENDIR command");
return NULL;
}
else if (sftp->open_packet_len != rc) {
@@ -885,7 +890,7 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename,
an error when in non-blocking mode! */
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send FXP_OPEN or FXP_OPENDIR command", 0);
"Unable to send FXP_OPEN or FXP_OPENDIR command");
LIBSSH2_FREE(session, sftp->open_packet);
sftp->open_packet = NULL;
sftp->open_state = libssh2_NB_state_idle;
@@ -903,12 +908,11 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename,
&data_len);
if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block waiting for status message", 0);
"Would block waiting for status message");
return NULL;
}
else if (rc) {
libssh2_error(session, rc,
"Timeout waiting for status message", 0);
libssh2_error(session, rc, "Timeout waiting for status message");
sftp->open_state = libssh2_NB_state_idle;
return NULL;
}
@@ -942,7 +946,7 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename,
if(badness) {
libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"Failed opening remote file", 0);
"Failed opening remote file");
_libssh2_debug(session, LIBSSH2_TRACE_SFTP, "got FXP_STATUS %d",
sftp->last_errno);
LIBSSH2_FREE(session, data);
@@ -953,7 +957,7 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename,
fp = LIBSSH2_ALLOC(session, sizeof(LIBSSH2_SFTP_HANDLE));
if (!fp) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate new SFTP handle structure", 0);
"Unable to allocate new SFTP handle structure");
LIBSSH2_FREE(session, data);
return NULL;
}
@@ -1095,11 +1099,10 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
} else if (packet_len != retcode) {
/* TODO: a partial write is not a critical error when in
non-blocking mode! */
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"_libssh2_channel_write() failed", 0);
sftp->read_packet = NULL;
sftp->read_state = libssh2_NB_state_idle;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"_libssh2_channel_write() failed");
}
sftp->read_packet = packet;
sftp->read_request_id = request_id;
@@ -1112,15 +1115,13 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
sftp_packet_requirev(sftp, 2, read_responses,
request_id, &data, &data_len);
if (retcode == PACKET_EAGAIN) {
libssh2_error(session, retcode,
"Would block waiting for status message", 0);
return retcode;
return libssh2_error(session, retcode,
"Would block waiting for status message");
} else if (retcode) {
libssh2_error(session, retcode,
"Timeout waiting for status message", 0);
sftp->read_packet = NULL;
sftp->read_state = libssh2_NB_state_idle;
return -1;
return libssh2_error(session, retcode,
"Timeout waiting for status message");
}
sftp->read_state = libssh2_NB_state_sent1;
@@ -1140,9 +1141,8 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
return total_read;
} else {
sftp->last_errno = retcode;
libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol Error", 0);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol Error");
}
case SSH_FXP_DATA:
@@ -1267,10 +1267,9 @@ static int sftp_readdir(LIBSSH2_SFTP_HANDLE *handle, char *buffer,
s = sftp->readdir_packet = LIBSSH2_ALLOC(session, packet_len);
if (!sftp->readdir_packet) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for FXP_READDIR packet",
0);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for "
"FXP_READDIR packet");
}
_libssh2_htonu32(s, packet_len - 4);
@@ -1297,12 +1296,11 @@ static int sftp_readdir(LIBSSH2_SFTP_HANDLE *handle, char *buffer,
return retcode;
}
else if (packet_len != retcode) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"_libssh2_channel_write() failed", 0);
LIBSSH2_FREE(session, sftp->readdir_packet);
sftp->readdir_packet = NULL;
sftp->readdir_state = libssh2_NB_state_idle;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"_libssh2_channel_write() failed");
}
LIBSSH2_FREE(session, sftp->readdir_packet);
@@ -1318,10 +1316,9 @@ static int sftp_readdir(LIBSSH2_SFTP_HANDLE *handle, char *buffer,
if (retcode == PACKET_EAGAIN) {
return retcode;
} else if (retcode) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for status message", 0);
sftp->readdir_state = libssh2_NB_state_idle;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for status message");
}
if (data[0] == SSH_FXP_STATUS) {
@@ -1332,10 +1329,9 @@ static int sftp_readdir(LIBSSH2_SFTP_HANDLE *handle, char *buffer,
return 0;
} else {
sftp->last_errno = retcode;
libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol Error", 0);
sftp->readdir_state = libssh2_NB_state_idle;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol Error");
}
}
@@ -1435,9 +1431,8 @@ static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer,
(unsigned long) count);
s = sftp->write_packet = LIBSSH2_ALLOC(session, packet_len);
if (!sftp->write_packet) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for FXP_WRITE", 0);
return LIBSSH2_ERROR_ALLOC;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for FXP_WRITE");
}
_libssh2_htonu32(s, packet_len - 4);
s += 4;
@@ -1484,10 +1479,9 @@ static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer,
return rc;
}
else if (rc) {
libssh2_error(session, rc,
"Timeout waiting for status message", 0);
sftp->write_state = libssh2_NB_state_idle;
return rc;
return libssh2_error(session, rc,
"Timeout waiting for status message");
}
sftp->write_state = libssh2_NB_state_idle;
@@ -1499,11 +1493,10 @@ static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer,
handle->u.file.offset += count;
return count;
}
libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, "SFTP Protocol Error",
0);
sftp->last_errno = retcode;
return LIBSSH2_ERROR_SFTP_PROTOCOL;
return libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol Error");
}
/* libssh2_sftp_write
@@ -1545,10 +1538,9 @@ static int sftp_fstat(LIBSSH2_SFTP_HANDLE *handle,
setstat ? "set-stat" : "stat");
s = sftp->fstat_packet = LIBSSH2_ALLOC(session, packet_len);
if (!sftp->fstat_packet) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for FSTAT/FSETSTAT packet",
0);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for "
"FSTAT/FSETSTAT packet");
}
_libssh2_htonu32(s, packet_len - 4);
@@ -1574,13 +1566,12 @@ static int sftp_fstat(LIBSSH2_SFTP_HANDLE *handle,
if (rc == PACKET_EAGAIN) {
return rc;
} else if (packet_len != rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
(setstat ? "Unable to send FXP_FSETSTAT"
: "Unable to send FXP_FSTAT command"), 0);
LIBSSH2_FREE(session, sftp->fstat_packet);
sftp->fstat_packet = NULL;
sftp->fstat_state = libssh2_NB_state_idle;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
(setstat ? "Unable to send FXP_FSETSTAT"
: "Unable to send FXP_FSTAT command"));
}
LIBSSH2_FREE(session, sftp->fstat_packet);
sftp->fstat_packet = NULL;
@@ -1594,10 +1585,9 @@ static int sftp_fstat(LIBSSH2_SFTP_HANDLE *handle,
if (rc == PACKET_EAGAIN) {
return rc;
} else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for status message", 0);
sftp->fstat_state = libssh2_NB_state_idle;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for status message");
}
sftp->fstat_state = libssh2_NB_state_idle;
@@ -1611,9 +1601,8 @@ static int sftp_fstat(LIBSSH2_SFTP_HANDLE *handle,
return 0;
} else {
sftp->last_errno = retcode;
libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol Error", 0);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol Error");
}
}
@@ -1696,9 +1685,9 @@ sftp_close_handle(LIBSSH2_SFTP_HANDLE *handle)
_libssh2_debug(session, LIBSSH2_TRACE_SFTP, "Closing handle");
s = handle->close_packet = LIBSSH2_ALLOC(session, packet_len);
if (!handle->close_packet) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for FXP_CLOSE packet", 0);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for FXP_CLOSE "
"packet");
}
_libssh2_htonu32(s, packet_len - 4);
@@ -1721,12 +1710,11 @@ sftp_close_handle(LIBSSH2_SFTP_HANDLE *handle)
if (rc == PACKET_EAGAIN) {
return rc;
} else if (packet_len != rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send FXP_CLOSE command", 0);
LIBSSH2_FREE(session, handle->close_packet);
handle->close_packet = NULL;
handle->close_state = libssh2_NB_state_idle;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send FXP_CLOSE command");
}
LIBSSH2_FREE(session, handle->close_packet);
handle->close_packet = NULL;
@@ -1741,10 +1729,9 @@ sftp_close_handle(LIBSSH2_SFTP_HANDLE *handle)
if (rc == PACKET_EAGAIN) {
return rc;
} else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for status message", 0);
handle->close_state = libssh2_NB_state_idle;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for status message");
}
handle->close_state = libssh2_NB_state_sent1;
@@ -1755,10 +1742,9 @@ sftp_close_handle(LIBSSH2_SFTP_HANDLE *handle)
if (retcode != LIBSSH2_FX_OK) {
sftp->last_errno = retcode;
libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol Error", 0);
handle->close_state = libssh2_NB_state_idle;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol Error");
}
/* remove this handle from the parent's list */
@@ -1807,10 +1793,9 @@ static int sftp_unlink(LIBSSH2_SFTP *sftp, const char *filename,
_libssh2_debug(session, LIBSSH2_TRACE_SFTP, "Unlinking %s", filename);
s = sftp->unlink_packet = LIBSSH2_ALLOC(session, packet_len);
if (!sftp->unlink_packet) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for FXP_REMOVE packet",
0);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for FXP_REMOVE "
"packet");
}
_libssh2_htonu32(s, packet_len - 4);
@@ -1833,12 +1818,11 @@ static int sftp_unlink(LIBSSH2_SFTP *sftp, const char *filename,
if (rc == PACKET_EAGAIN) {
return rc;
} else if (packet_len != rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send FXP_REMOVE command", 0);
LIBSSH2_FREE(session, sftp->unlink_packet);
sftp->unlink_packet = NULL;
sftp->unlink_state = libssh2_NB_state_idle;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send FXP_REMOVE command");
}
LIBSSH2_FREE(session, sftp->unlink_packet);
sftp->unlink_packet = NULL;
@@ -1853,10 +1837,9 @@ static int sftp_unlink(LIBSSH2_SFTP *sftp, const char *filename,
return rc;
}
else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for status message", 0);
sftp->unlink_state = libssh2_NB_state_idle;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for status message");
}
sftp->unlink_state = libssh2_NB_state_idle;
@@ -1868,9 +1851,8 @@ static int sftp_unlink(LIBSSH2_SFTP *sftp, const char *filename,
return 0;
} else {
sftp->last_errno = retcode;
libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol Error", 0);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol Error");
}
}
@@ -1910,9 +1892,8 @@ static int sftp_rename(LIBSSH2_SFTP *sftp, const char *source_filename,
int rc;
if (sftp->version < 2) {
libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"Server does not support RENAME", 0);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"Server does not support RENAME");
}
if (sftp->rename_state == libssh2_NB_state_idle) {
@@ -1921,10 +1902,9 @@ static int sftp_rename(LIBSSH2_SFTP *sftp, const char *source_filename,
sftp->rename_s = sftp->rename_packet =
LIBSSH2_ALLOC(session, packet_len);
if (!sftp->rename_packet) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for FXP_RENAME packet",
0);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for FXP_RENAME "
"packet");
}
_libssh2_htonu32(sftp->rename_s, packet_len - 4);
@@ -1956,12 +1936,11 @@ static int sftp_rename(LIBSSH2_SFTP *sftp, const char *source_filename,
if (rc == PACKET_EAGAIN) {
return rc;
} else if (packet_len != rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send FXP_RENAME command", 0);
LIBSSH2_FREE(session, sftp->rename_packet);
sftp->rename_packet = NULL;
sftp->rename_state = libssh2_NB_state_idle;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send FXP_RENAME command");
}
LIBSSH2_FREE(session, sftp->rename_packet);
sftp->rename_packet = NULL;
@@ -1975,10 +1954,9 @@ static int sftp_rename(LIBSSH2_SFTP *sftp, const char *source_filename,
if (rc == PACKET_EAGAIN) {
return rc;
} else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for status message", 0);
sftp->rename_state = libssh2_NB_state_idle;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for status message");
}
sftp->rename_state = libssh2_NB_state_idle;
@@ -1986,31 +1964,30 @@ static int sftp_rename(LIBSSH2_SFTP *sftp, const char *source_filename,
retcode = _libssh2_ntohu32(data + 5);
LIBSSH2_FREE(session, data);
sftp->last_errno = retcode;
/* now convert the SFTP error code to libssh2 return code or error
message */
switch (retcode) {
case LIBSSH2_FX_OK:
retcode = 0;
retcode = LIBSSH2_ERROR_NONE;
break;
case LIBSSH2_FX_FILE_ALREADY_EXISTS:
libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"File already exists and SSH_FXP_RENAME_OVERWRITE not specified",
0);
sftp->last_errno = retcode;
retcode = -1;
retcode = libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"File already exists and "
"SSH_FXP_RENAME_OVERWRITE not specified");
break;
case LIBSSH2_FX_OP_UNSUPPORTED:
libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"Operation Not Supported", 0);
sftp->last_errno = retcode;
retcode = -1;
retcode = libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"Operation Not Supported");
break;
default:
libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol Error", 0);
sftp->last_errno = retcode;
retcode = -1;
retcode = libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol Error");
break;
}
return retcode;
@@ -2056,9 +2033,9 @@ static int sftp_mkdir(LIBSSH2_SFTP *sftp, const char *path,
"Creating directory %s with mode 0%lo", path, mode);
s = packet = LIBSSH2_ALLOC(session, packet_len);
if (!packet) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for FXP_MKDIR packet", 0);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for FXP_MKDIR "
"packet");
}
/* Filetype in SFTP 3 and earlier */
attrs.permissions = mode | LIBSSH2_SFTP_ATTR_PFILETYPE_DIR;
@@ -2088,11 +2065,10 @@ static int sftp_mkdir(LIBSSH2_SFTP *sftp, const char *path,
return rc;
}
if (packet_len != rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"_libssh2_channel_write() failed", 0);
LIBSSH2_FREE(session, packet);
sftp->mkdir_state = libssh2_NB_state_idle;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"_libssh2_channel_write() failed");
}
LIBSSH2_FREE(session, packet);
sftp->mkdir_state = libssh2_NB_state_sent;
@@ -2104,10 +2080,9 @@ static int sftp_mkdir(LIBSSH2_SFTP *sftp, const char *path,
if (rc == PACKET_EAGAIN) {
return rc;
} else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for status message", 0);
sftp->mkdir_state = libssh2_NB_state_idle;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for status message");
}
sftp->mkdir_state = libssh2_NB_state_idle;
@@ -2119,10 +2094,9 @@ static int sftp_mkdir(LIBSSH2_SFTP *sftp, const char *path,
_libssh2_debug(session, LIBSSH2_TRACE_SFTP, "OK!");
return 0;
} else {
libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol Error", 0);
sftp->last_errno = retcode;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol Error");
}
}
@@ -2160,9 +2134,9 @@ static int sftp_rmdir(LIBSSH2_SFTP *sftp, const char *path,
path);
s = sftp->rmdir_packet = LIBSSH2_ALLOC(session, packet_len);
if (!sftp->rmdir_packet) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for FXP_RMDIR packet", 0);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for FXP_RMDIR "
"packet");
}
_libssh2_htonu32(s, packet_len - 4);
@@ -2185,12 +2159,11 @@ static int sftp_rmdir(LIBSSH2_SFTP *sftp, const char *path,
if (rc == PACKET_EAGAIN) {
return rc;
} else if (packet_len != rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send FXP_RMDIR command", 0);
LIBSSH2_FREE(session, sftp->rmdir_packet);
sftp->rmdir_packet = NULL;
sftp->rmdir_state = libssh2_NB_state_idle;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send FXP_RMDIR command");
}
LIBSSH2_FREE(session, sftp->rmdir_packet);
sftp->rmdir_packet = NULL;
@@ -2203,10 +2176,9 @@ static int sftp_rmdir(LIBSSH2_SFTP *sftp, const char *path,
if (rc == PACKET_EAGAIN) {
return rc;
} else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for status message", 0);
sftp->rmdir_state = libssh2_NB_state_idle;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for status message");
}
sftp->rmdir_state = libssh2_NB_state_idle;
@@ -2218,9 +2190,8 @@ static int sftp_rmdir(LIBSSH2_SFTP *sftp, const char *path,
return 0;
} else {
sftp->last_errno = retcode;
libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol Error", 0);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol Error");
}
}
@@ -2264,9 +2235,9 @@ static int sftp_stat(LIBSSH2_SFTP *sftp, const char *path,
LIBSSH2_SFTP_LSTAT ? "LStatting" : "Statting"), path);
s = sftp->stat_packet = LIBSSH2_ALLOC(session, packet_len);
if (!sftp->stat_packet) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for FXP_*STAT packet", 0);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for FXP_*STAT "
"packet");
}
_libssh2_htonu32(s, packet_len - 4);
@@ -2304,12 +2275,11 @@ static int sftp_stat(LIBSSH2_SFTP *sftp, const char *path,
if (rc == PACKET_EAGAIN) {
return rc;
} else if (packet_len != rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send STAT/LSTAT/SETSTAT command", 0);
LIBSSH2_FREE(session, sftp->stat_packet);
sftp->stat_packet = NULL;
sftp->stat_state = libssh2_NB_state_idle;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send STAT/LSTAT/SETSTAT command");
}
LIBSSH2_FREE(session, sftp->stat_packet);
sftp->stat_packet = NULL;
@@ -2322,10 +2292,9 @@ static int sftp_stat(LIBSSH2_SFTP *sftp, const char *path,
if (rc == PACKET_EAGAIN) {
return rc;
} else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for status message", 0);
sftp->stat_state = libssh2_NB_state_idle;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for status message");
}
sftp->stat_state = libssh2_NB_state_idle;
@@ -2339,9 +2308,8 @@ static int sftp_stat(LIBSSH2_SFTP *sftp, const char *path,
return 0;
} else {
sftp->last_errno = retcode;
libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol Error", 0);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol Error");
}
}
@@ -2386,18 +2354,16 @@ static int sftp_symlink(LIBSSH2_SFTP *sftp, const char *path,
int rc;
if ((sftp->version < 3) && (link_type != LIBSSH2_SFTP_REALPATH)) {
libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"Server does not support SYMLINK or READLINK", 0);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"Server does not support SYMLINK or READLINK");
}
if (sftp->symlink_state == libssh2_NB_state_idle) {
s = sftp->symlink_packet = LIBSSH2_ALLOC(session, packet_len);
if (!sftp->symlink_packet) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for SYMLINK/READLINK"
"/REALPATH packet", 0);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for "
"SYMLINK/READLINK/REALPATH packet");
}
_libssh2_debug(session, LIBSSH2_TRACE_SFTP, "%s %s on %s",
@@ -2444,12 +2410,11 @@ static int sftp_symlink(LIBSSH2_SFTP *sftp, const char *path,
if (rc == PACKET_EAGAIN) {
return rc;
} else if (packet_len != rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send SYMLINK/READLINK command", 0);
LIBSSH2_FREE(session, sftp->symlink_packet);
sftp->symlink_packet = NULL;
sftp->symlink_state = libssh2_NB_state_idle;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send SYMLINK/READLINK command");
}
LIBSSH2_FREE(session, sftp->symlink_packet);
sftp->symlink_packet = NULL;
@@ -2464,10 +2429,9 @@ static int sftp_symlink(LIBSSH2_SFTP *sftp, const char *path,
return rc;
}
else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for status message", 0);
sftp->symlink_state = libssh2_NB_state_idle;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for status message");
}
sftp->symlink_state = libssh2_NB_state_idle;
@@ -2481,18 +2445,16 @@ static int sftp_symlink(LIBSSH2_SFTP *sftp, const char *path,
return 0;
} else {
sftp->last_errno = retcode;
libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol Error", 0);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol Error");
}
}
if (_libssh2_ntohu32(data + 5) < 1) {
libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"Invalid READLINK/REALPATH response, no name entries",
0);
LIBSSH2_FREE(session, data);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"Invalid READLINK/REALPATH response, "
"no name entries");
}
link_len = _libssh2_ntohu32(data + 9);

View File

@@ -135,8 +135,6 @@ decrypt(LIBSSH2_SESSION * session, unsigned char *source,
while (len >= blocksize) {
if (session->remote.crypt->crypt(session, source,
&session->remote.crypt_abstract)) {
libssh2_error(session, LIBSSH2_ERROR_DECRYPT,
(char *) "Error decrypting packet", 0);
LIBSSH2_FREE(session, p->payload);
return PACKET_FAIL;
}
@@ -232,11 +230,9 @@ fullpacket(LIBSSH2_SESSION * session, int encrypted /* 1 or 0 */ )
/* We need a freeable struct otherwise the
* brigade won't know what to do with it */
p->payload = LIBSSH2_ALLOC(session, data_len);
if (!p->payload) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC, (char *)
"Unable to allocate memory", 0);
if (!p->payload)
return PACKET_ENOMEM;
}
memcpy(p->payload, data, data_len);
session->fullpacket_payload_len = data_len;
}
@@ -712,13 +708,14 @@ _libssh2_transport_write(LIBSSH2_SESSION * session, unsigned char *data,
/* FIRST, check if we have a pending write to complete */
rc = send_existing(session, data, data_len, &ret);
if (rc || ret) {
if (rc)
return rc;
}
/* default clear the bit */
session->socket_block_directions &= ~LIBSSH2_SESSION_BLOCK_OUTBOUND;
if (ret)
return rc;
encrypted = (session->state & LIBSSH2_STATE_NEWKEYS) ? 1 : 0;
/* check if we should compress */

View File

@@ -79,7 +79,7 @@ static char *userauth_list(LIBSSH2_SESSION *session, const char *username,
LIBSSH2_ALLOC(session, session->userauth_list_data_len);
if (!session->userauth_list_data) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for userauth_list", 0);
"Unable to allocate memory for userauth_list");
return NULL;
}
@@ -109,18 +109,19 @@ static char *userauth_list(LIBSSH2_SESSION *session, const char *username,
session->userauth_list_data_len);
if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block requesting userauth list", 0);
"Would block requesting userauth list");
return NULL;
} else if (rc) {
}
/* now free the packet that was sent */
LIBSSH2_FREE(session, session->userauth_list_data);
session->userauth_list_data = NULL;
if (rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send userauth-none request", 0);
LIBSSH2_FREE(session, session->userauth_list_data);
session->userauth_list_data = NULL;
"Unable to send userauth-none request");
session->userauth_list_state = libssh2_NB_state_idle;
return NULL;
}
LIBSSH2_FREE(session, session->userauth_list_data);
session->userauth_list_data = NULL;
session->userauth_list_state = libssh2_NB_state_sent;
}
@@ -133,17 +134,17 @@ static char *userauth_list(LIBSSH2_SESSION *session, const char *username,
&session->userauth_list_packet_requirev_state);
if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block requesting userauth list", 0);
"Would block requesting userauth list");
return NULL;
} else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_NONE, "No error", 0);
libssh2_error(session, rc, "Failed getting response");
session->userauth_list_state = libssh2_NB_state_idle;
return NULL;
}
if (session->userauth_list_data[0] == SSH_MSG_USERAUTH_SUCCESS) {
/* Wow, who'dve thought... */
libssh2_error(session, LIBSSH2_ERROR_NONE, "No error", 0);
libssh2_error(session, LIBSSH2_ERROR_NONE, "No error");
LIBSSH2_FREE(session, session->userauth_list_data);
session->userauth_list_data = NULL;
session->state |= LIBSSH2_STATE_AUTHENTICATED;
@@ -157,7 +158,8 @@ static char *userauth_list(LIBSSH2_SESSION *session, const char *username,
memmove(session->userauth_list_data, session->userauth_list_data + 5,
methods_len);
session->userauth_list_data[methods_len] = '\0';
_libssh2_debug(session, LIBSSH2_TRACE_AUTH, "Permitted auth methods: %s",
_libssh2_debug(session, LIBSSH2_TRACE_AUTH,
"Permitted auth methods: %s",
session->userauth_list_data);
}
@@ -228,10 +230,9 @@ userauth_password(LIBSSH2_SESSION *session, const char *username,
s = session->userauth_pswd_data =
LIBSSH2_ALLOC(session, session->userauth_pswd_data_len);
if (!session->userauth_pswd_data) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for userauth-password"
" request", 0);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for "
"userauth-password request");
}
*(s++) = SSH_MSG_USERAUTH_REQUEST;
@@ -268,18 +269,20 @@ userauth_password(LIBSSH2_SESSION *session, const char *username,
rc = _libssh2_transport_write(session, session->userauth_pswd_data,
session->userauth_pswd_data_len);
if (rc == PACKET_EAGAIN) {
return rc;
} else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send userauth-password request", 0);
LIBSSH2_FREE(session, session->userauth_pswd_data);
session->userauth_pswd_data = NULL;
session->userauth_pswd_state = libssh2_NB_state_idle;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block writing password request");
}
/* now free the sent packet */
LIBSSH2_FREE(session, session->userauth_pswd_data);
session->userauth_pswd_data = NULL;
if (rc) {
session->userauth_pswd_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send userauth-password request");
}
session->userauth_pswd_state = libssh2_NB_state_sent;
}
@@ -296,10 +299,12 @@ userauth_password(LIBSSH2_SESSION *session, const char *username,
&session->
userauth_pswd_packet_requirev_state);
if (rc == PACKET_EAGAIN) {
return rc;
return libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block waiting");
} else if (rc) {
session->userauth_pswd_state = libssh2_NB_state_idle;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_TIMEOUT,
"Would block waiting");
}
if (session->userauth_pswd_data[0] == SSH_MSG_USERAUTH_SUCCESS) {
@@ -316,11 +321,10 @@ userauth_password(LIBSSH2_SESSION *session, const char *username,
LIBSSH2_FREE(session, session->userauth_pswd_data);
session->userauth_pswd_data = NULL;
session->userauth_pswd_state = libssh2_NB_state_idle;
libssh2_error(session,
LIBSSH2_ERROR_AUTHENTICATION_FAILED,
"Authentication failed (username/password)",
0);
return -1;
return libssh2_error(session,
LIBSSH2_ERROR_AUTHENTICATION_FAILED,
"Authentication failed "
"(username/password)");
}
session->userauth_pswd_newpw = NULL;
@@ -350,11 +354,10 @@ userauth_password(LIBSSH2_SESSION *session, const char *username,
&session->userauth_pswd_newpw_len,
&session->abstract);
if (!session->userauth_pswd_newpw) {
libssh2_error(session,
LIBSSH2_ERROR_PASSWORD_EXPIRED,
"Password expired, and callback failed",
0);
return -1;
return libssh2_error(session,
LIBSSH2_ERROR_PASSWORD_EXPIRED,
"Password expired, and "
"callback failed");
}
/* basic data_len + newpw_len(4) */
@@ -366,13 +369,13 @@ userauth_password(LIBSSH2_SESSION *session, const char *username,
LIBSSH2_ALLOC(session,
session->userauth_pswd_data_len);
if (!session->userauth_pswd_data) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for userauth-password-change request",
0);
LIBSSH2_FREE(session,
session->userauth_pswd_newpw);
session->userauth_pswd_newpw = NULL;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory "
"for userauth password "
"change request");
}
*(s++) = SSH_MSG_USERAUTH_REQUEST;
@@ -415,23 +418,23 @@ userauth_password(LIBSSH2_SESSION *session, const char *username,
session->
userauth_pswd_data_len);
if (rc == PACKET_EAGAIN) {
return rc;
} else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send userauth-password-change request",
0);
LIBSSH2_FREE(session, session->userauth_pswd_data);
session->userauth_pswd_data = NULL;
LIBSSH2_FREE(session,
session->userauth_pswd_newpw);
session->userauth_pswd_newpw = NULL;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block waiting");
}
/* free the allocated packets again */
LIBSSH2_FREE(session, session->userauth_pswd_data);
session->userauth_pswd_data = NULL;
LIBSSH2_FREE(session, session->userauth_pswd_newpw);
session->userauth_pswd_newpw = NULL;
if (rc) {
return libssh2_error(session,
LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send userauth "
"password-change request");
}
/*
* Ugliest use of goto ever. Blame it on the
* askN => requirev migration.
@@ -441,11 +444,10 @@ userauth_password(LIBSSH2_SESSION *session, const char *username,
}
}
} else {
libssh2_error(session, LIBSSH2_ERROR_PASSWORD_EXPIRED,
"Password Expired, and no callback specified",
0);
session->userauth_pswd_state = libssh2_NB_state_idle;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_PASSWORD_EXPIRED,
"Password Expired, and no callback "
"specified");
}
}
}
@@ -454,7 +456,9 @@ userauth_password(LIBSSH2_SESSION *session, const char *username,
LIBSSH2_FREE(session, session->userauth_pswd_data);
session->userauth_pswd_data = NULL;
session->userauth_pswd_state = libssh2_NB_state_idle;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_AUTHENTICATION_FAILED,
"Authentication failed");
}
/*
@@ -505,9 +509,8 @@ file_read_publickey(LIBSSH2_SESSION * session, unsigned char **method,
/* Read Public Key */
fd = fopen(pubkeyfile, "r");
if (!fd) {
libssh2_error(session, LIBSSH2_ERROR_FILE,
"Unable to open public key file", 0);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_FILE,
"Unable to open public key file");
}
while (!feof(fd) && (c = fgetc(fd)) != '\r' && c != '\n')
pubkey_len++;
@@ -518,25 +521,22 @@ file_read_publickey(LIBSSH2_SESSION * session, unsigned char **method,
rewind(fd);
if (pubkey_len <= 1) {
libssh2_error(session, LIBSSH2_ERROR_FILE,
"Invalid data in public key file", 0);
fclose(fd);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_FILE,
"Invalid data in public key file");
}
pubkey = LIBSSH2_ALLOC(session, pubkey_len);
if (!pubkey) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for public key data", 0);
fclose(fd);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for public key data");
}
if (fread(pubkey, 1, pubkey_len, fd) != pubkey_len) {
libssh2_error(session, LIBSSH2_ERROR_FILE,
"Unable to read public key from file", 0);
LIBSSH2_FREE(session, pubkey);
fclose(fd);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_FILE,
"Unable to read public key from file");
}
fclose(fd);
/*
@@ -546,17 +546,15 @@ file_read_publickey(LIBSSH2_SESSION * session, unsigned char **method,
pubkey_len--;
if (!pubkey_len) {
libssh2_error(session, LIBSSH2_ERROR_FILE, "Missing public key data",
0);
LIBSSH2_FREE(session, pubkey);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_FILE,
"Missing public key data");
}
if ((sp1 = memchr(pubkey, ' ', pubkey_len)) == NULL) {
libssh2_error(session, LIBSSH2_ERROR_FILE, "Invalid public key data",
0);
LIBSSH2_FREE(session, pubkey);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_FILE,
"Invalid public key data");
}
sp1++;
@@ -568,10 +566,9 @@ file_read_publickey(LIBSSH2_SESSION * session, unsigned char **method,
if (libssh2_base64_decode(session, (char **) &tmp, &tmp_len,
(char *) sp1, sp2 - sp1)) {
libssh2_error(session, LIBSSH2_ERROR_FILE,
"Invalid key data, not base64 encoded", 0);
LIBSSH2_FREE(session, pubkey);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_FILE,
"Invalid key data, not base64 encoded");
}
/* Wasting some bytes here (okay, more than some), but since it's likely
@@ -615,17 +612,15 @@ file_read_privatekey(LIBSSH2_SESSION * session,
hostkey_methods_avail++;
}
if (!*hostkey_method) {
libssh2_error(session, LIBSSH2_ERROR_METHOD_NONE,
"No handler for specified private key", 0);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_METHOD_NONE,
"No handler for specified private key");
}
if ((*hostkey_method)->
initPEM(session, privkeyfile, (unsigned char *) passphrase,
hostkey_abstract)) {
libssh2_error(session, LIBSSH2_ERROR_FILE,
"Unable to initialize private key from file", 0);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_FILE,
"Unable to initialize private key from file");
}
return 0;
@@ -644,14 +639,15 @@ sign_fromfile(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len,
const LIBSSH2_HOSTKEY_METHOD *privkeyobj;
void *hostkey_abstract;
struct iovec datavec;
int rc;
if (file_read_privatekey(session, &privkeyobj, &hostkey_abstract,
session->userauth_pblc_method,
session->userauth_pblc_method_len,
privkey_file->filename,
privkey_file->passphrase)) {
return -1;
}
rc = file_read_privatekey(session, &privkeyobj, &hostkey_abstract,
session->userauth_pblc_method,
session->userauth_pblc_method_len,
privkey_file->filename,
privkey_file->passphrase);
if(rc)
return rc;
datavec.iov_base = (unsigned char *)data;
datavec.iov_len = data_len;
@@ -699,12 +695,13 @@ userauth_hostbased_fromfile(LIBSSH2_SESSION *session,
memset(&session->userauth_host_packet_requirev_state, 0,
sizeof(session->userauth_host_packet_requirev_state));
if (file_read_publickey(session, &session->userauth_host_method,
&session->userauth_host_method_len,
&pubkeydata, &pubkeydata_len,
publickey)) {
return -1;
}
rc = file_read_publickey(session, &session->userauth_host_method,
&session->userauth_host_method_len,
&pubkeydata, &pubkeydata_len,
publickey);
if(rc)
/* Note: file_read_publickey() calls libssh2_error() */
return rc;
/*
* 48 = packet_type(1) + username_len(4) + servicename_len(4) +
@@ -730,7 +727,8 @@ userauth_hostbased_fromfile(LIBSSH2_SESSION *session,
LIBSSH2_FREE(session, session->userauth_host_method);
session->userauth_host_method = NULL;
LIBSSH2_FREE(session, pubkeydata);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Out of memory");
}
*(session->userauth_host_s++) = SSH_MSG_USERAUTH_REQUEST;
@@ -774,15 +772,17 @@ userauth_hostbased_fromfile(LIBSSH2_SESSION *session,
memcpy(session->userauth_host_s, local_username, local_username_len);
session->userauth_host_s += local_username_len;
if (file_read_privatekey(session, &privkeyobj, &abstract,
session->userauth_host_method,
session->userauth_host_method_len,
privatekey, passphrase)) {
rc = file_read_privatekey(session, &privkeyobj, &abstract,
session->userauth_host_method,
session->userauth_host_method_len,
privatekey, passphrase);
if(rc) {
/* Note: file_read_privatekey() calls libssh2_error() */
LIBSSH2_FREE(session, session->userauth_host_method);
session->userauth_host_method = NULL;
LIBSSH2_FREE(session, session->userauth_host_packet);
session->userauth_host_packet = NULL;
return -1;
return rc;
}
_libssh2_htonu32(buf, session->session_id_len);
@@ -816,16 +816,14 @@ userauth_hostbased_fromfile(LIBSSH2_SESSION *session,
(4 + session->userauth_host_method_len)
+ (4 + sig_len)); /* PK sigblob */
if (!newpacket) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Failed allocating additional space for "
"userauth-hostbased packet",
0);
LIBSSH2_FREE(session, sig);
LIBSSH2_FREE(session, session->userauth_host_packet);
session->userauth_host_packet = NULL;
LIBSSH2_FREE(session, session->userauth_host_method);
session->userauth_host_method = NULL;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Failed allocating additional space for "
"userauth-hostbased packet");
}
session->userauth_host_packet = newpacket;
}
@@ -863,14 +861,14 @@ userauth_hostbased_fromfile(LIBSSH2_SESSION *session,
session->userauth_host_s -
session->userauth_host_packet);
if (rc == PACKET_EAGAIN) {
return rc;
} else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send userauth-hostbased request", 0);
return libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block");
}
else if (rc) {
LIBSSH2_FREE(session, session->userauth_host_packet);
session->userauth_host_packet = NULL;
session->userauth_host_state = libssh2_NB_state_idle;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send userauth-hostbased request");
}
LIBSSH2_FREE(session, session->userauth_host_packet);
session->userauth_host_packet = NULL;
@@ -888,12 +886,14 @@ userauth_hostbased_fromfile(LIBSSH2_SESSION *session,
&session->
userauth_host_packet_requirev_state);
if (rc == PACKET_EAGAIN) {
return rc;
return libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block");
}
session->userauth_host_state = libssh2_NB_state_idle;
if (rc)
return -1;
if (rc) {
return libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED,
"Auth failed");
}
if (session->userauth_host_data[0] == SSH_MSG_USERAUTH_SUCCESS) {
_libssh2_debug(session, LIBSSH2_TRACE_AUTH,
@@ -909,11 +909,9 @@ userauth_hostbased_fromfile(LIBSSH2_SESSION *session,
/* This public key is not allowed for this user on this server */
LIBSSH2_FREE(session, session->userauth_host_data);
session->userauth_host_data = NULL;
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED,
"Invalid signature for supplied public key, or bad "
"username/public key combination",
0);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED,
"Invalid signature for supplied public key, or bad "
"username/public key combination");
}
/* libssh2_userauth_hostbased_fromfile_ex
@@ -973,10 +971,9 @@ userauth_publickey(LIBSSH2_SESSION *session,
session->userauth_pblc_method =
LIBSSH2_ALLOC(session, session->userauth_pblc_method_len);
if (!session->userauth_pblc_method) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for public key "
"data", 0);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for public key "
"data");
}
memcpy(session->userauth_pblc_method, pubkeydata + 4,
session->userauth_pblc_method_len);
@@ -1007,7 +1004,8 @@ userauth_publickey(LIBSSH2_SESSION *session,
if (!session->userauth_pblc_packet) {
LIBSSH2_FREE(session, session->userauth_pblc_method);
session->userauth_pblc_method = NULL;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Out of memory");
}
*(session->userauth_pblc_s++) = SSH_MSG_USERAUTH_REQUEST;
@@ -1051,17 +1049,16 @@ userauth_publickey(LIBSSH2_SESSION *session,
if (session->userauth_pblc_state == libssh2_NB_state_created) {
rc = _libssh2_transport_write(session, session->userauth_pblc_packet,
session->userauth_pblc_packet_len);
if (rc == PACKET_EAGAIN) {
return rc;
} else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send userauth-publickey request", 0);
if (rc == PACKET_EAGAIN)
return libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block");
else if (rc) {
LIBSSH2_FREE(session, session->userauth_pblc_packet);
session->userauth_pblc_packet = NULL;
LIBSSH2_FREE(session, session->userauth_pblc_method);
session->userauth_pblc_method = NULL;
session->userauth_pblc_state = libssh2_NB_state_idle;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send userauth-publickey request");
}
session->userauth_pblc_state = libssh2_NB_state_sent;
@@ -1075,14 +1072,16 @@ userauth_publickey(LIBSSH2_SESSION *session,
&session->
userauth_pblc_packet_requirev_state);
if (rc == PACKET_EAGAIN) {
return rc;
} else if (rc) {
return libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block");
}
else if (rc) {
LIBSSH2_FREE(session, session->userauth_pblc_packet);
session->userauth_pblc_packet = NULL;
LIBSSH2_FREE(session, session->userauth_pblc_method);
session->userauth_pblc_method = NULL;
session->userauth_pblc_state = libssh2_NB_state_idle;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED,
"Failed waiting");
}
if (session->userauth_pblc_data[0] == SSH_MSG_USERAUTH_SUCCESS) {
@@ -1111,10 +1110,9 @@ userauth_publickey(LIBSSH2_SESSION *session,
session->userauth_pblc_packet = NULL;
LIBSSH2_FREE(session, session->userauth_pblc_method);
session->userauth_pblc_method = NULL;
libssh2_error(session, LIBSSH2_ERROR_AUTHENTICATION_FAILED,
"Username/PublicKey combination invalid", 0);
session->userauth_pblc_state = libssh2_NB_state_idle;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_AUTHENTICATION_FAILED,
"Username/PublicKey combination invalid");
}
/* Semi-Success! */
@@ -1133,10 +1131,9 @@ userauth_publickey(LIBSSH2_SESSION *session,
s = buf = LIBSSH2_ALLOC(session, 4 + session->session_id_len
+ session->userauth_pblc_packet_len);
if (!buf) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for userauth-publickey "
"signed data", 0);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for "
"userauth-publickey signed data");
}
_libssh2_htonu32(s, session->session_id_len);
@@ -1150,14 +1147,15 @@ userauth_publickey(LIBSSH2_SESSION *session,
rc = sign_callback(session, &sig, &sig_len, buf, s - buf, abstract);
LIBSSH2_FREE(session, buf);
if (rc == PACKET_EAGAIN) {
return rc;
return libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block");
} else if (rc) {
LIBSSH2_FREE(session, session->userauth_pblc_method);
session->userauth_pblc_method = NULL;
LIBSSH2_FREE(session, session->userauth_pblc_packet);
session->userauth_pblc_packet = NULL;
session->userauth_pblc_state = libssh2_NB_state_idle;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED,
"Callback returned error");
}
/*
@@ -1173,17 +1171,15 @@ userauth_publickey(LIBSSH2_SESSION *session,
(4 + session->userauth_pblc_method_len)
+ (4 + sig_len)); /* PK sigblob */
if (!newpacket) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Failed allocating additional space for "
"userauth-publickey packet",
0);
LIBSSH2_FREE(session, sig);
LIBSSH2_FREE(session, session->userauth_pblc_packet);
session->userauth_pblc_packet = NULL;
LIBSSH2_FREE(session, session->userauth_pblc_method);
session->userauth_pblc_method = NULL;
session->userauth_pblc_state = libssh2_NB_state_idle;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Failed allocating additional space for "
"userauth-publickey packet");
}
session->userauth_pblc_packet = newpacket;
}
@@ -1222,14 +1218,13 @@ userauth_publickey(LIBSSH2_SESSION *session,
session->userauth_pblc_s -
session->userauth_pblc_packet);
if (rc == PACKET_EAGAIN) {
return rc;
return libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block");
} else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send userauth-publickey request", 0);
LIBSSH2_FREE(session, session->userauth_pblc_packet);
session->userauth_pblc_packet = NULL;
session->userauth_pblc_state = libssh2_NB_state_idle;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send userauth-publickey request");
}
LIBSSH2_FREE(session, session->userauth_pblc_packet);
session->userauth_pblc_packet = NULL;
@@ -1245,10 +1240,12 @@ userauth_publickey(LIBSSH2_SESSION *session,
&session->userauth_pblc_data_len, 0, NULL, 0,
&session->userauth_pblc_packet_requirev_state);
if (rc == PACKET_EAGAIN) {
return rc;
return libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block requesting userauth list");
} else if (rc) {
session->userauth_pblc_state = libssh2_NB_state_idle;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED,
"Failed waiting");
}
if (session->userauth_pblc_data[0] == SSH_MSG_USERAUTH_SUCCESS) {
@@ -1265,12 +1262,10 @@ userauth_publickey(LIBSSH2_SESSION *session,
/* This public key is not allowed for this user on this server */
LIBSSH2_FREE(session, session->userauth_pblc_data);
session->userauth_pblc_data = NULL;
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED,
"Invalid signature for supplied public key, or bad "
"username/public key combination",
0);
session->userauth_pblc_state = libssh2_NB_state_idle;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED,
"Invalid signature for supplied public key, or bad "
"username/public key combination");
}
/*
@@ -1295,11 +1290,11 @@ userauth_publickey_fromfile(LIBSSH2_SESSION *session,
privkey_file.passphrase = passphrase;
if (session->userauth_pblc_state == libssh2_NB_state_idle) {
if (file_read_publickey(session, &session->userauth_pblc_method,
&session->userauth_pblc_method_len,
&pubkeydata, &pubkeydata_len, publickey)) {
return -1;
}
rc = file_read_publickey(session, &session->userauth_pblc_method,
&session->userauth_pblc_method_len,
&pubkeydata, &pubkeydata_len, publickey);
if(rc)
return rc;
}
rc = userauth_publickey(session, username, username_len,
@@ -1323,6 +1318,12 @@ libssh2_userauth_publickey_fromfile_ex(LIBSSH2_SESSION *session,
const char *passphrase)
{
int rc;
if(NULL == passphrase)
/* if given a NULL pointer, make it point to a zero-length
string to save us from having to check this all over */
passphrase="";
BLOCK_ADJUST(rc, session,
userauth_publickey_fromfile(session, user, user_len,
publickey, privatekey,
@@ -1398,11 +1399,9 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session,
session->userauth_kybd_data = s =
LIBSSH2_ALLOC(session, session->userauth_kybd_packet_len);
if (!s) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for "
"keyboard-interactive authentication",
0);
return -1;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for "
"keyboard-interactive authentication");
}
*s++ = SSH_MSG_USERAUTH_REQUEST;
@@ -1443,14 +1442,13 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session,
rc = _libssh2_transport_write(session, session->userauth_kybd_data,
session->userauth_kybd_packet_len);
if (rc == PACKET_EAGAIN) {
return rc;
return libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block");
} else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send keyboard-interactive request", 0);
LIBSSH2_FREE(session, session->userauth_kybd_data);
session->userauth_kybd_data = NULL;
session->userauth_kybd_state = libssh2_NB_state_idle;
return -1;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send keyboard-interactive request");
}
LIBSSH2_FREE(session, session->userauth_kybd_data);
session->userauth_kybd_data = NULL;
@@ -1467,10 +1465,13 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session,
&session->
userauth_kybd_packet_requirev_state);
if (rc == PACKET_EAGAIN) {
return rc;
return libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block");
} else if (rc) {
session->userauth_kybd_state = libssh2_NB_state_idle;
return -1;
return libssh2_error(session,
LIBSSH2_ERROR_AUTHENTICATION_FAILED,
"Failed waiting");
}
if (session->userauth_kybd_data[0] == SSH_MSG_USERAUTH_SUCCESS) {
@@ -1489,11 +1490,10 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session,
LIBSSH2_FREE(session, session->userauth_kybd_data);
session->userauth_kybd_data = NULL;
session->userauth_kybd_state = libssh2_NB_state_idle;
libssh2_error(session,
LIBSSH2_ERROR_AUTHENTICATION_FAILED,
"Authentication failed (keyboard-interactive)",
0);
return -1;
return libssh2_error(session,
LIBSSH2_ERROR_AUTHENTICATION_FAILED,
"Authentication failed "
"(keyboard-interactive)");
}
/* server requested PAM-like conversation */
@@ -1508,8 +1508,7 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session,
if (!session->userauth_kybd_auth_name) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for "
"keyboard-interactive 'name' request field",
0);
"keyboard-interactive 'name' request field");
goto cleanup;
}
memcpy(session->userauth_kybd_auth_name, s,
@@ -1526,8 +1525,7 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session,
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for "
"keyboard-interactive 'instruction' "
"request field",
0);
"request field");
goto cleanup;
}
memcpy(session->userauth_kybd_auth_instruction, s,
@@ -1551,8 +1549,7 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session,
if (!session->userauth_kybd_prompts) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for "
"keyboard-interactive prompts array",
0);
"keyboard-interactive prompts array");
goto cleanup;
}
memset(session->userauth_kybd_prompts, 0,
@@ -1566,8 +1563,7 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session,
if (!session->userauth_kybd_responses) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for "
"keyboard-interactive responses array",
0);
"keyboard-interactive responses array");
goto cleanup;
}
memset(session->userauth_kybd_responses, 0,
@@ -1584,8 +1580,7 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session,
if (!session->userauth_kybd_prompts[i].text) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for "
"keyboard-interactive prompt message",
0);
"keyboard-interactive prompt message");
goto cleanup;
}
memcpy(session->userauth_kybd_prompts[i].text, s,
@@ -1620,13 +1615,16 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session,
4 + session->userauth_kybd_responses[i].length;
}
/* A new userauth_kybd_data area is to be allocated, free the
former one. */
LIBSSH2_FREE(session, session->userauth_kybd_data);
session->userauth_kybd_data = s =
LIBSSH2_ALLOC(session, session->userauth_kybd_packet_len);
if (!s) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for keyboard-"
"interactive response packet",
0);
"interactive response packet");
goto cleanup;
}
@@ -1650,13 +1648,13 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session,
rc = _libssh2_transport_write(session, session->userauth_kybd_data,
session->userauth_kybd_packet_len);
if (rc == PACKET_EAGAIN) {
return rc;
return libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block");
}
if (rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send userauth-keyboard-interactive"
" request",
0);
" request");
goto cleanup;
}

Some files were not shown because too many files have changed in this diff Show More