Marc Hoersken | 18 May 2013 23:52
Picon
Gravatar

[PATCH] knownhost.c: use LIBSSH2_FREE macro instead of free

Hello everyone,

another small patch to fix warnings I noticed during development. free
is actually not explicitly declared since the corresponding header
file is not imported.

It also makes sense to free the buffers using the same wrapper
interface they have been created with.

Best regards,
Marc
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
libssh2 Trac | 17 May 2013 20:25
Picon
Favicon

#265: agent_disconnect_unix closes stdin on Solaris 10 x64

#265: agent_disconnect_unix closes stdin on Solaris 10 x64
-------------------------+--------------------
 Reporter:  mkerestesch  |       Owner:
     Type:  defect       |      Status:  new
 Priority:  normal       |   Milestone:  1.4.3
Component:  SFTP         |     Version:  1.4.2
 Keywords:               |  Blocked By:
   Blocks:               |
-------------------------+--------------------
 Hi there.
 i'm, using libssh2 1.4.3 in a multi-threaded environment to connect to an
 sftp-server via curl (curl 7.30.0, openssl 1.0.1e).
 My code is working perfectly in a windows 7, Linux x64, Solaris 11 x64 and
 Mac OS X x64 environment, but shutting down a thread local curl
 handle under Solaris 10 x64 somehow seems to close stdin (which i rely on
 due to ipc-requirements).
 Anyway. I was able to generate a stacktrace for the problem and the
 offending call seems to be agent_disconnect_unix, which obviously
 closes fd with fd == 0.
 As I can see from libssh2_agent_init the LIBSSH_AGENT struct is zeroed,
 which also sets fd to zero.
 Changing (agent.c):

 LIBSSH2_API LIBSSH2_AGENT *
 libssh2_agent_init(LIBSSH2_SESSION *session)
 {
     LIBSSH2_AGENT *agent;

     agent = LIBSSH2_ALLOC(session, sizeof *agent);
     if (!agent) {
(Continue reading)

Marc Hoersken | 9 May 2013 22:06
Picon
Gravatar

[PATCH] libcrypt.c: Fixed typo in function parameter type

Hello everyone,

while looking into the crypto backends I noticed a small typo.
Attached you will find a patch.

Best regards,
Marc
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
libssh2 Trac | 29 Apr 2013 20:41
Picon
Favicon

#264: SCP send not properly setting mtime or atime

#264: SCP send not properly setting mtime or atime
--------------------------+--------------------
 Reporter:  wguynes       |       Owner:
     Type:  defect        |      Status:  new
 Priority:  normal        |   Milestone:  1.4.3
Component:  examples      |     Version:  1.4.2
 Keywords:  scp examples  |  Blocked By:
   Blocks:                |
--------------------------+--------------------
 When using libssh2_scp_send_ex() or libssh2_scp_send64() with non-zero
 mtime or atime parameters the time stamp does not get set.

 This is not so much a fault with the library, but that the scp send
 examples are misleading. After the data is actually sent the remote side
 is expecting one NULL byte. This will trigger the remote side to actually
 set the timestamp on the now fully received file. At present the examples
 merely slam the channel closed which the remote side meekly accepts.

 This will also be critical to implementation of any recursive SCP feature
 in the future. Multiple file transfers over one, open channel will require
 the NULL byte after each write data phase.

--

-- 
Ticket URL: <https://trac.libssh2.org/ticket/264>
libssh2 <https://trac.libssh2.org/>
C library for writing portable SSH2 clients

_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel

(Continue reading)

cosmin | 17 Apr 2013 10:00

libssh2_userauth_password return value

If the authentication fails for a couple of times  (libssh2_userauth_password() returns LIBSSH2_ERROR_AUTHENTICATION_FAILED) and the server closes the connection because of too many authentication failures libssh2_userauth_password() returns LIBSSH2_ERROR_TIMEOUT but in this case it should return LIBSSH2_ERROR_SOCKET_DISCONNECT.


src/userauth.c

        if (session->userauth_pswd_state == libssh2_NB_state_sent) {
            rc = _libssh2_packet_requirev(session, reply_codes,
                                          &session->userauth_pswd_data,
                                          &session->userauth_pswd_data_len,
                                          0, NULL, 0,
                                          &session->
                                          userauth_pswd_packet_requirev_state);
            if (rc == LIBSSH2_ERROR_EAGAIN) {
                return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
                                      "Would block waiting");
            } else if (rc) {
                session->userauth_pswd_state = libssh2_NB_state_idle;
                return _libssh2_error(session, LIBSSH2_ERROR_TIMEOUT,
                                      "Would block waiting");
            }


I think it should return the actual error from the transport layer and not a "general" LIBSSH2_ERROR_TIMEOUT error.
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Eric Frias | 10 Apr 2013 22:46
Favicon

proper use of non-blocking read

I've been trying to figure out how to use libssh2's non-blocking API
correctly, and I'm stuck.  I can get it to work 99% of the time, but
that last 1% is eludes me.

The main problem I'm battling is what happens when I need to do a read
on a channel, and I don't know if there's going to be any data there to
read.  If there is, I want to read it.  If there's no data, I want to be
able to do other stuff like write to the channel or read or write to
another channel.  Seems pretty normal.

So let's say I call libssh2_channel_read_ex() and it returns
LIBSSH2_ERROR_EAGAIN.  My problem is that I can't tell what this means. 
It could mean that:
* there was no data on that channel, and it's safe to go write some data
or service another channel.  or,
* in the process of doing the read, libssh2 wandered into
_libssh2_channel_receive_window_adjust, sending a message to the ssh
server.  While sending the adjust message, the TCP send buffer filled
up, and the OS level send(2) call returned EAGAIN

Of course, this second case is the one that is giving me problems. 
Although I haven't seen it stated explicitly anywhere, it looks like if
I get LIBSSH2_ERROR_EAGAIN due to a failed write, the only thing I can
safely do with libssh2 is wait and call the same
libssh2_channel_read_ex() function again with the same arguments until
it manages to finish the write.  If I were to make some other call to
libssh2 which could result in network traffic, libssh2 will give me a
slap on the wrist (in the form of a LIBSSH2_ERROR_BAD_USE) and then I'm
in trouble.

If I always assume that an LIBSSH2_ERROR_EAGAIN means that I can call
other functions, my tests will usually run pretty well for a few
minutes, maybe even hours, but eventually this error (or some variant of
it) will bite me.  If I assume that LIBSSH2_ERROR_EAGAIN means the only
thing I can do is call the exact same function until it succeeds, I'm
trapped because I can't safely read from a channel unless I know there
will be data on it.

Am I missing something that would let me use the public API safely? 
Right now I'm playing around with workarounds like only allowing my code
to switch and call another function if session->packet.olen == 0 after
an LIBSSH2_ERROR_EAGAIN, but that's ugly and I don't have much
confidence that I'm on the right track.

Thanks.
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel

libssh2 Trac | 10 Apr 2013 00:26
Picon
Favicon

#263: libssh2_channel_read for exec ends unpredictably

#263: libssh2_channel_read for exec ends unpredictably
---------------------+--------------------
 Reporter:  xtravar  |       Owner:
     Type:  defect   |      Status:  new
 Priority:  normal   |   Milestone:  1.4.3
Component:  API      |     Version:  1.4.2
 Keywords:           |  Blocked By:
   Blocks:           |
---------------------+--------------------
 Problem: libssh2_channel_exec is returning EOF sooner than expected
 randomly

 Client Platform: iOS
 Versions tried: 1.4.3, 1.4.4-20130409

 *Tried with blocking & non-blocking
 *Piped to 'tee' to verify the process isn't ending prematurely (the file
 gets written out completely)
 *Same problem does not happen with SCP
 *Never happens on the first run of the code

 My code vaguely looks like:
 {{{
 chan = libssh2_channel_open_session(session);
 libssh2_channel_exec(chan, "convert \"test.jpg\" -quality 60 -resize 100%
 -format JPEG - 2>/dev/null | tee converttest.jpg")
 // loop until read returns 0 (eof also becomes true at this point)
 libssh2_channel_close(chan);
 }}}

 The problem happens after a few runs of the code on the same command.
 It's fairly reproducible.  I have some trace output that might be useful.

 Good run:
  Conn: Allocated new channel ID#2
  Conn: Opening Channel - win 262144 pack 32768
  Socket: Sent 52/52 bytes at 0x8a9775c
  Failure Event: -37 - Would block
  Socket: Recved 52/16384 bytes to 0x8a93734+0
  Conn: Connection Established - ID: 2/1 win: 0/262144 pack: 32768/32768
  Conn: starting request(exec) on channel 2/1, message=convert "cover.jpg"
 -quality 60 -resize 100% -format JPEG -
  Socket: Sent 52/52 bytes at 0x8a9775c
  Socket: Recved 88/16384 bytes to 0x8a93734+0
  Conn: Window adjust for channel 2/1, adding 2097152 bytes, new
 window_size=2097152
  Conn: channel_read() wants 10240 bytes from channel 2/1 stream #0
  Failure Event: -37 - would block
  Conn: channel_read() wants 10240 bytes from channel 2/1 stream #0
  Socket: Recved 116/16384 bytes to 0x8a93734+0
  Conn: 8192 bytes packet_add() for 2/1/0
  Conn: channel_read() got 8192 of data from 2/1/0 [ul]
  Socket: Recved 376/16384 bytes to 0x8a93734+0
  Conn: 8192 bytes packet_add() for 2/1/0
  Conn: 4096 bytes packet_add() for 2/1/0
  Conn: 851 bytes packet_add() for 2/1/0
  Conn: EOF received for channel 2/1
  Conn: Channel 2 received request type exit-status (wr 0)
  Conn: Exit status 0 received for channel 2/1
  Conn: Close received for channel 2/1
  Conn: channel_read() got 8192 of data from 2/1/0 [ul]
  Conn: channel_read() got 2048 of data from 2/1/0
  Conn: channel_read() got 2048 of data from 2/1/0 [ul]
  Conn: channel_read() got 851 of data from 2/1/0 [ul]
  Conn: Sending EOF on channel 2/1
  Socket: Sent 36/36 bytes at 0x8a9775c
  Conn: Closing channel 2/1
  Socket: Sent 36/36 bytes at 0x8a9775c

 Bad run:
  Conn: Allocated new channel ID#2
  Conn: Opening Channel - win 262144 pack 32768
  Socket: Sent 52/52 bytes at 0x8a9775c
  Failure Event: -37 - Would block
  Socket: Recved 52/16384 bytes to 0x8a93734+0
  Conn: Connection Established - ID: 2/1 win: 0/262144 pack: 32768/32768
  Conn: starting request(exec) on channel 2/1, message=convert "cover.jpg"
 -quality 60 -resize 100% -format JPEG -
  Socket: Sent 52/52 bytes at 0x8a9775c
  Socket: Recved 88/16384 bytes to 0x8a93734+0
  Conn: Window adjust for channel 2/1, adding 2097152 bytes, new
 window_size=2097152
  Conn: channel_read() wants 10240 bytes from channel 2/1 stream #0
  Failure Event: -37 - would block
  Conn: channel_read() wants 10240 bytes from channel 2/1 stream #0
  Socket: Recved 116/16384 bytes to 0x8a93734+0
  Conn: 8007 bytes packet_add() for 2/1/0
  Conn: channel_read() got 8007 of data from 2/1/0 [ul]
  Failure Event: -37 - would block
  Conn: channel_read() wants 10240 bytes from channel 2/1 stream #0
  Socket: Recved 116/16384 bytes to 0x8a93734+0
  Failure Event: -37 - would block
  Conn: channel_read() wants 10240 bytes from channel 2/1 stream #0
  Socket: Recved 82/16384 bytes to 0x8a93734+0
  Conn: 4096 bytes packet_add() for 2/1/0
  Conn: channel_read() got 4096 of data from 2/1/0 [ul]
  Socket: Recved 176/16384 bytes to 0x8a93734+0
  Conn: 851 bytes packet_add() for 2/1/0
  Conn: Channel 2 received request type exit-status (wr 0)
  Conn: Exit status 0 received for channel 2/1
  Conn: EOF received for channel 2/1
  Conn: Close received for channel 2/1
  Conn: channel_read() got 851 of data from 2/1/0 [ul]
  Conn: Sending EOF on channel 2/1
  Socket: Sent 36/36 bytes at 0x8a9775c
  Conn: Closing channel 2/1
  Socket: Sent 36/36 bytes at 0x8a9775c

--

-- 
Ticket URL: <https://trac.libssh2.org/ticket/263>
libssh2 <https://trac.libssh2.org/>
C library for writing portable SSH2 clients

_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel

Richard W.M. Jones | 9 Apr 2013 11:42
Picon
Favicon
Gravatar

[PATCH] sftp: Add support for fsync (OpenSSH extension).

The patch (in the following email) adds fsync support to libssh2 via a
new API function called 'libssh2_sftp_fsync'.

*NOTE:* For this to work you will need a patched OpenSSH with an
accepted-upstream-but-not-included patch that adds the
fsync@... extension to OpenSSH sftp-server.  For details see
here:

https://bugzilla.mindrot.org/show_bug.cgi?id=1798

I have tested this via my qemu ssh block device patch both with and
without fsync support on the server side.

Rich.

_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel

Richard W.M. Jones | 8 Apr 2013 18:32
Picon
Favicon
Gravatar

[PATCH] sftp: statvfs: Along error path, reset the correct 'state' variable.


This appears to be a typo in the code.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
libguestfs lets you edit virtual machines.  Supports shell scripting,
bindings from many languages.  http://libguestfs.org
From 4722dc2709ec35bbab9d2cd90f291a4914aa8781 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@...>
Date: Mon, 8 Apr 2013 17:30:10 +0100
Subject: [PATCH] sftp: statvfs: Along error path, reset the correct 'state'
 variable.

---
 src/sftp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/sftp.c b/src/sftp.c
index 3760025..65fa77a 100644
--- a/src/sftp.c
+++ b/src/sftp.c
 <at>  <at>  -2752,7 +2752,7  <at>  <at>  static int sftp_statvfs(LIBSSH2_SFTP *sftp, const char *path,
                               "Error waiting for FXP EXTENDED REPLY");
     } else if (data_len < 93) {
         LIBSSH2_FREE(session, data);
-        sftp->fstatvfs_state = libssh2_NB_state_idle;
+        sftp->statvfs_state = libssh2_NB_state_idle;
         return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
                               "SFTP Protocol Error: short response");
     }
--

-- 
1.8.1.4

_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Paul Radaz | 3 Apr 2013 19:23
Picon

Transfering files

Hello all, I want to make something like this: http://www.mail-archive.com/libssh2-devel-nuDYylZla2DMSbncWqzJgw@public.gmane.org/msg01481.html but when I trying to create sftp_session instance for C through channel in my app, then libssh2_sftp_init return NULL and error code is set to LIBSSH2_ERROR_INVAL.

_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
libssh2 Trac | 28 Mar 2013 20:03
Picon
Favicon

#262: libssh2_userauth_publickey_fromfile_ex declaration in man missis one parameter

#262: libssh2_userauth_publickey_fromfile_ex declaration in man missis one
parameter
--------------------+--------------------
 Reporter:  pastey  |       Owner:
     Type:  defect  |      Status:  new
 Priority:  low     |   Milestone:  1.4.3
Component:  SFTP    |     Version:  1.4.2
 Keywords:  man     |  Blocked By:
   Blocks:          |
--------------------+--------------------
 in manual entry for libssh2_userauth_publickey_fromfile_ex function
 declaration misses "username_len" parameter (in SYNOPSIS section), however
 "username_len" is described in DESCRIPTION section

--

-- 
Ticket URL: <https://trac.libssh2.org/ticket/262>
libssh2 <https://trac.libssh2.org/>
C library for writing portable SSH2 clients

_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel


Gmane