1
1

53 Коммитов

Автор SHA1 Сообщение Дата
Marc Hoersken
1e7988cb0d scp.c: fix that scp_recv may transmit not initialised memory 2015-03-23 23:04:24 +01:00
Marc Hoersken
b99204f289 scp.c: fix that scp_send may transmit not initialised memory
Fixes ticket 244. Thanks Torsten.
2015-03-23 22:47:46 +01:00
Marc Hoersken
8f799f98d9 silence multiple data conversion warnings 2014-12-26 11:05:34 +01:00
Dan Fandrich
c00efa5f93 Fixed a few typos 2014-02-24 23:23:13 +01:00
Guenter Knauf
d6cf1c7df0 Fixed LIBSSH2_INT64_T_FORMAT macro.
Usually a format macro should hold the whole format, otherwise
it should be named a prefix. Also fixed usage of this macro in
scp.c for a signed var where it was used as prefix for unsigned.
2012-06-04 22:54:25 +02:00
Steven Dake
4449905ea5 Use safer snprintf rather then sprintf in scp_send()
Signed-off-by: Steven Dake <sdake@redhat.com>
2012-03-06 23:24:32 +01:00
Steven Dake
8e0cddd01f Use safer snprintf rather then sprintf in scp_recv()
While the buffer is indeed allocated to a safe length, better safe then sorry.

Signed-off-by: Steven Dake <sdake@redhat.com>
2012-03-06 23:23:21 +01:00
Guenter Knauf
689fc5c596 Silent compiler warning with MinGW64. 2011-08-29 15:30:18 +02:00
Daniel Stenberg
e652b4c7b8 SCP: fix incorrect error code
After an error occurs in libssh2_scp_recv() or libssh2_scp_send(), the
function libssh2_session_last_error() would return
LIBSSH2_ERROR_SOCKET_NONE on error.

Bug: http://trac.libssh2.org/ticket/216
Patch by: "littlesavage"

Fixes #216
2011-05-02 22:27:29 +02:00
Daniel Stenberg
ca2e81eb1f send/recv: use _libssh2_recv and _libssh2_send now
Starting now, we unconditionally use the internal replacement functions
for send() and recv() - creatively named _libssh2_recv() and
_libssh2_send().

On errors, these functions return the negative 'errno' value instead of
the traditional -1. This design allows systems that have no "natural"
errno support to not have to invent it. It also means that no code
outside of these two transfer functions should use the errno variable.
2010-11-12 21:53:35 +01:00
Daniel Stenberg
1c3e1c4d25 SCP: clean up failure treatment
When SCP send or recv fails, it gets a special message from the server
with a warning or error message included. We have no current API to
expose that message but the foundation is there. Removed unnecessary use
of session struct fields.
2010-11-10 17:17:32 +01:00
Daniel Stenberg
4760e4d051 scp_recv: remove dead assignment
Instead of assigning a variable we won't read, we now use the more
explicit (void) prefix.
2010-11-01 22:59:15 +01:00
Daniel Stenberg
c48840ba88 _libssh2_transport_send: replaces _libssh2_transport_write
The new function takes two data areas, combines them and sends them as a
single SSH packet. This allows several functions to allocate and copy
less data.

I also found and fixed a mixed up use of the compression function
arguments that I introduced in my rewrite in a recent commit.
2010-10-23 00:11:59 +02:00
Daniel Stenberg
cd6d41b806 scp_recv: improved treatment of channel_read() returning zero
As a zero return code from channel_read() is not an error we must make
sure that the SCP functions deal with that properly. channel_read()
always returns 0 if the channel is EOFed already so we check for EOF
after 0-reads to be able to return error properly.
2010-10-11 22:54:24 +02:00
Daniel Stenberg
018602cb34 SCP: allow file names with bytes > 126
When parsing the SCP protocol and verifying that the data looks like a
valid file name, byte values over 126 must not be consider illegal since
UTF-8 file names will use such codes.

Reported by: Uli Zappe
Bug: http://www.libssh2.org/mail/libssh2-devel-archive-2010-08/0112.shtml
2010-08-31 19:56:00 +02:00
Daniel Stenberg
49ddf447ff portability: introduce LIBSSH2_INT64_T_FORMAT for 64bit printf()s
As pointed out in bug #177, some of the Windows compilers use
%I64 to output 64 bit variables with the printf family.
2010-06-15 19:47:31 +02:00
Daniel Stenberg
71fb9cc93e cleanup: prefer the internal functions
To get the blocking vs non-blocking to work as smooth as possible
and behave better internally, we avoid using the external
interfaces when calling functions internally.

Renamed a few internal functions to use _libssh2 prefix when not
being private within a file, and removed the libssh2_ for one
that was private within the file.
2010-04-25 19:35:43 +02:00
Daniel Stenberg
000b0f73d0 libssh2_publickey_init: fixed to work better non-blocking
This was triggered by a clang-analyzer complaint that turned out
to be valid, and it made me dig deeper and fix some generic non-
blocking problems I disovered in the code.

While cleaning this up, I moved session-specific stuff over to a
new session.h header from the libssh2_priv.h header.
2010-04-25 19:35:43 +02:00
Daniel Stenberg
f8b42cab86 remove two unnecessary increments 2010-04-18 15:26:41 +02:00
Daniel Stenberg
be9ee7095e libssh2_scp_send64: added to API to provide large file transfers
The previously existing libssh2_scp_send_ex() function has no way
to send files that are larger than 'size_t' which on 32bit
systems mean 4GB. This new API uses a libssh2_int64_t type and
should thus on most modern systems be able to send enormous
files.
2010-04-17 19:47:50 +02:00
Daniel Stenberg
c3bcdd88a4 cleanups: better binary packet gen, size_t fixes and PACKET_* removal
I'll introduce a new internal function set named

 _libssh2_store_u32
 _libssh2_store_u64
 _libssh2_store_str

That can be used all through the library to build binary outgoing
packets.  Using these instead of the current approach removes
hundreds of lines from the library while at the same time greatly
enhances readability. I've not yet fully converted everything to
use these functions.

I've converted LOTS of 'unsigned long' to 'size_t' where
data/string lengths are dealt with internally. This is The Right
Thing and it will help us make the transition to our
size_t-polished API later on as well.

I'm removing the PACKET_* error codes. They were originally
introduced as a set of separate error codes from the transport
layer, but having its own set of errors turned out to be very
awkward and they were then converted into a set of #defines that
simply maps them to the global libssh2 error codes instead. Now,
I'l take the next logical step and simply replace the PACKET_*
defines with the actual LIBSSH2_ERROR_* defines. It will increase
readability and decrease confusion.

I also separated packet stuff into its own packet.h header file.
2010-04-17 13:18:15 +02:00
Daniel Stenberg
1adcb5234f rename libssh2_error to the correct _libssh2_error
We reserve ^libssh2_ for public symbols and we use _libssh2 as
prefix for internal ones. I fixed the intendation of all these
edits with emacs afterwards, which then changed it slightly more
than just _libssh2_error() expressions but I didn't see any
obvious problems.
2010-04-16 00:18:51 +02: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
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
Peter Stuge
d142f385da Use LIBSSH2_TRACE_* internally and remove redundant LIBSSH2_DBG_* 2009-12-08 08:52:03 +01:00
Daniel Stenberg
9e84b999a5 make libssh2_scp_send/recv do blocking mode correctly
Somehow I had completely missed to make the libssh2_scp_send/recv
functions support the blocking mode the correct way so when I
cleaned up things the other day blocking mode broke for them...
Fixed now.
2009-09-15 23:29:46 +02:00
Daniel Stenberg
5bb1fb5cbc s/libssh2_channel_write_ex/_libssh2_channel_write internally 2009-08-30 19:31:07 +02:00
Daniel Stenberg
85198c1cdb channel_read() was changed to _libssh2_channel_read() as lots of
internal code was changed to use that instead of wrongly using
libssh2_channel_read_ex(). Some files now need to include
channel.h to get this proto.

channel_read() calls libssh2_error() properly on transport_read()
failures

channel_read() was adjusted to not "invent" EAGAIN return code in
case the transport_read() didn't return it

channel_close() now returns 0 or error code, as
documented. Previously it would return number of bytes read in
the last read, which was confusing (and useless).
2009-08-30 17:00:49 +02:00
Daniel Stenberg
cc5e952fa0 A cleanup effort: libssh2_ prefixes only on external APIs. Use _libssh2_ prefix
for library-wide internal functions. Don't use any of those on static functions.
I also did some comments and whitespace changes.
2009-03-17 13:48:35 +00:00
Daniel Stenberg
94090cf55c Patch from bug report #1960894 by "Heiner" applied, and edited by me. It makes
SCP recv and send deal with file names containing spaces (and other
shell-special letters) by quoting them before they are passed to the remote
server.
2009-03-15 23:28:25 +00:00
Daniel Stenberg
ce9d44a3ff fixed some wrong comments and did a minor code edit and some further
whitespace changes
2009-03-15 23:07:09 +00:00
Daniel Stenberg
0812744424 fix a compiler warning 2009-03-15 22:40:11 +00:00
Daniel Stenberg
f56b8ef605 simplified how the "scp" command line is created in the libssh2_scp_recv()
function
2009-03-15 22:38:47 +00:00
Daniel Stenberg
369fcddb24 fixed compiler warnings, and stripped off "libssh2_" from static functions
as that makes shorter function names and then making the code look fine within
80 columns is easier!
2009-01-01 22:47:06 +00:00
Daniel Stenberg
93ae080bbc - Based on a patch in bug #1878059 by Steven Ayre libssh2 now parses >2GB file
sizes when downloading SCP files.
2008-09-29 14:04:01 +00:00
Daniel Stenberg
210459db4b re-indented the source code with this script:
indent \
--braces-on-if-line \
--braces-after-struct-decl-line \
--space-after-cast \
--line-length 79 \
--comment-line-length 79 \
--cuddle-else \
--no-tabs \
--tab-size 8 \
--indent-level 4 \
--no-space-after-for \
--space-after-if \
--space-after-while \
--no-space-after-function-call-names \
*.[ch]
2007-08-06 20:48:04 +00:00
James Housley
46f59112d9 * After setting the error to the error string from in the packet, set
the pointer to NULL so it can't be double freed.
* On session cleanup be sure to free the last error if it needs to be
2007-07-19 15:02:37 +00:00
James Housley
6ac790a477 * Since the packet as already had data read from it, it can't retrun
PACKET_EAGAIN while reading the rest of it.
* Get the error message in libssh2_scp_recv() in the same manner as it
  was gotten in libssh2_scp_send_ex()
2007-07-05 15:31:19 +00:00
James Housley
530e57d4ac Gavrie Philipson sumitted a patch to get the actual text of the error
on scp upload.
2007-07-05 11:08:17 +00:00
James Housley
dde2b09496 libssh2_channel_free() actually can return PACKET_EAGAIN. Update all
calling functions to support that with the following API notes:

* libssh2_publickey_shutdown(), libssh2_session_free() changed
  to return an "int" to allow signaling of LIBSSH2_ERROR_EAGAIN.

* libssh2_scp_recv(), libssh2_scp_send_ex() and libssh2_sftp_init()
  will loop in on libssh2_channel_free() when there is an error.
  It is not possible to return LIBSSH2_ERROR_EAGAIN in this condition
  in these 3 functions and not lose the original error code.
2007-06-12 18:27:37 +00:00
James Housley
4b8db8c1ab Modify the code to truely support non-blocking. Propogate the EAGAIN error
all the way up to the user interface.  All code modules bug sftp.c have
been completed.

Functions that return an "int", or similar return LIBSSH2CHANNEL_EAGAIN to
indicate some part of the call would block, in non-blocking mode.

Functions that return a structure, like "LIBSSH2_CHANNEL *", return NULL
and set the libssh2 error.  The error can be obtained with either
libssh2_session_last_error() or libssh2_session_last_errno().  Either of
these will return the error code of LIBSSH2_ERROR_EAGAIN if the
call would block, in non-blocking mode.

The current state of a function and some variable are keep in the
structures so that on the next call the operation that would block can
be retried again with the same data.
2007-06-06 12:34:06 +00:00
James Housley
412b25d971 Initially the libssh2 code was indented with tabs of 4 spaces. Some of
the recent commits converted the tabs to 4 spaces, which matched the
initial indent size.  Other commits converted the tabs to 8 spaces, this
didn't match.

All the code has been converted to 4 space indents.  No changes to line
lengths or actual code was performed.  This is in preperation to my up
coming non-blocking work so my commits should only be code changes and
line lengths in the code I am working on.
2007-05-28 17:56:08 +00:00
Daniel Stenberg
4f1cfb20a9 1 - new public function libssh2_trace() that enables tracing/debug output on
various stuff if libssh2 was built with debug. If built without debug, the
 function does nothing.
2 - configure --enable-debug is now enough to build a debug version (including
picky compiler options)
3 - internally, we no longer need/use #ifdef/#endif around all uses of the
_libssh2_debug() function/macro.

The scp.c example is the first application to test this new debug logging.
2007-02-02 23:23:36 +00:00
Daniel Stenberg
9d55db6501 Adding src/transport.c for the SECSH transport layer read/write in a non-
blocking way. The channel code is now responsible for enabling/disabling
blocking status and to work with it.

I've also modified indenting and fixed compiler warnings at places, and
added a bunch of new examples in example/simple that I've used to verify that
the code still runs like before.

libssh2_channel_{read|write}nb_ex() and libssh2_sftp_{read|write}nb() are the
four new functions that supposedly work non-blocking.
2007-02-02 16:21:20 +00:00
Sara Golemon
c45992da55 Bump copyright year 2006-03-02 01:10:52 +00:00
Mikhail Gusarov
b6d13ebe8a Strictening function prototypes: char* -> const char* where applicable 2005-06-18 10:41:59 +00:00
Sara Golemon
ebfbd22e59 Add debugging hooks for development diagnostics 2005-05-11 05:11:31 +00:00
Sara Golemon
141ac5b856 Add sys/uio.h for FBSD builds and remove old stdio references 2005-03-21 21:26:08 +00:00
Sara Golemon
ef7496b29a Update copyright year 2005-02-18 16:32:02 +00:00
Bert Vermeulen
bfc2f5039e Added a couple of comments to keep my last-error-not-set-o-meter from going off 2005-01-19 16:29:53 +00:00