Yoichiro Tanaka | 26 Jan 12:49 2015
Picon

Using libssh2_sftp_* functions in multi-threading environment

Hi there,

I'm developing my application to access SFTP server with libssh2. And, I want to give an ability to access the SFTP server from multi-threads to the application, for example, downloading some files simultaneously.

I have some questions about how to use libssh2_sftp_* functions.

(1) Are "libssh2_sftp_*" functions thread-safe?

(2) If yes, what is a value to issue for each thread? Do I need to issue a sftp_session value issued by the libssh2_sftp_init() function for each thread? Or, Can I share the sftp_session value with all threads? That is, do I need to issue a sftp_handle value issued by the libssh2_sftp_open(dir) for each thread with the same value of the sftp_session?

(3) If a lock (ex. mutex) is necessary, where I should apply the lock against my code? From the libssh2_sftp_init() calling to the reading file with the all libssh2_sftp_read() calling? Or, each API calling?

(4) Is there any sample code to use libssh2 in  the multi-threading environment?

Thank you for your advice.

--
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Will Cosgrove | 13 Jan 01:29 2015

diffie-hellman-group-exchange-sha256 key exchange

Hi All,
I’m adding diffie-hellman-group-exchange-sha256 support and have it working.  However, if I am to
submit this patch back to the project I have a couple code style questions.

First, kmdhgGPsha1kex_state_t is coded to be specific to sha1.  No big deal I thought, I could add a sha256
version.  However that leads to key_exchange_state_low_t which is included in key_exchange_state_t. 
So now we’re duplicating three structs and causing a lot of branching, not so great. 

At that point, I decided to change kmdhgGPsha1kex_state_t to support sha256. The following changes were made:

unsigned char h_sig_comp[SHA256_DIGEST_LENGTH]; //SHA1_DIGEST_LENGTH

//libssh2_sha1_ctx exchange_hash;
EVP_MD_CTX exchange_hash;

This isn’t so hot as it hard-codes openssl support instead of using the libssh2_sha1_ctx macro.  On the
flip side, creating three new structures for a couple calls seems excessive.  

Anyone out there have opinions on how to proceed?

Cheers,
Will
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
libssh2 Trac | 16 Dec 22:41 2014
Picon

#293: error in direct_tcpip.c example

#293: error in direct_tcpip.c example
----------------------+--------------------
 Reporter:  bbo       |       Owner:
     Type:  defect    |      Status:  new
 Priority:  normal    |   Milestone:  1.5.0
Component:  examples  |     Version:  1.4.2
 Keywords:            |  Blocked By:
   Blocks:            |
----------------------+--------------------
 The example direct_tcpip.c doesn't take care of EAGAIN case return by
 libssh2_channel_write. This can lead to non transmitted file when this
 error is raised, while this should just delay the transmission because the
 socket are busy.
 To see the error, just run a process with high priority on the receiver of
 data trasnmitted through the libssh2_channel_write.
 Solution is just to retry the call to libssh2_channel_write one (or
 several) other time.

 Here under is the current code taken from the git repo today:
 Git repo code:

 wr = 0;
 do {
   i = libssh2_channel_write(channel, buf, len);
   if (i < 0) {
     fprintf(stderr, "libssh2_channel_write: %d\n", i);
     goto shutdown;
   }
   wr += i;
 } while(i > 0 && wr < len);

 Code patched:
 wr = 0;
 do {
   i = libssh2_channel_write(channel, buf, len);
   if (i >= 0)
   {
     wr += i;
   }
   else if(i == LIBSSH2_ERROR_EAGAIN)
   {
     fprintf(stderr, "libssh2_channel_write: LIBSSH2_ERROR_EAGAIN, retry to
 write\n");
   }
   else {
     fprintf(stderr, "libssh2_channel_write: %d\n", i);
     goto shutdown;
   }
 } while(wr < len);

--

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

_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Marc Hörsken | 15 Dec 12:26 2014
Picon

[PATCH] silence multiple data conversion warnings

Hello everyone,

attached you will find a patch to silence multiple compiler warnings about invalid data conversions with
possible data loss using the VS2012 compiler.

Since these are quite a lot of small changes, I would like someone else to review and push it to the repository.

Thanks in advance.

Best regards,
Marc

_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Marc Hoersken | 15 Dec 01:32 2014
Picon

Additional questions related to my fixes of possible NULL pointer de-references

Hello everyone,

I just posted a bunch of patches to the Git repository that are the
result of running the code analysis feature of VS2012 against libssh2
using the new CMake generated project files.

Most of them are quite basic, but at least the following two patches
raise additional questions that I would like to bring to your attention:
- kex.c: fix possible NULL pointer de-reference with session->kex [1]
- packet.c: fix possible NULL pointer de-reference within listen_state [2]

I think that just catching the possible NULL pointer in those code paths
is actually not enough to make libssh2 behave correctly.
In my opinion some kind of error code needs to be raised if such an
error condition is reached.

What do you think? Patches and ideas are welcome.

Best regards,
Marc

[1]
http://git.libssh2.org/?p=libssh2.git;a=commitdiff;h=1c1699545b0a1114e8ca3e6cd097cc9df1e67201;js=1
[2]
http://git.libssh2.org/?p=libssh2.git;a=commitdiff;h=e57f29f8f65c83063fd8f63c88f88830fc269bd6;js=1

_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Alexander Lamaison | 6 Dec 01:34 2014
Picon

CMake

You may recall that back in March I promised to convert the libssh2
build system to CMake 'soon'.  Well, 9 months later, it is more or
less complete: https://github.com/alamaison/libssh2/tree/cmake.  I
would greatly appreciate your feedback and help with testing on the
platforms that matter to you.

The goal is to match or exceed every relevant feature of the autotools
system like-for-like, so, unless otherwise stated in this email,
assume that any missing functionality is a bug.  Please report it.

CMake, however, is fundamentally different from autotools, so some
features (for example, building source distributions, aka `make dist`)
aren't relevant anymore and aren't specifically catered for.  The
README should get you started but, if you need help getting accustomed
to CMake, I'm very happy to answer any questions you have.

tl;dr
- A version of libssh2 using CMake is available at
  https://github.com/alamaison/libssh2/tree/cmake
- Please test

Platform support
================

I've tested the build with the three major platforms, Linux (GCC
4.6.3, Clang 3.4), Windows (VS2005, VS2008) and MacOS X (AppleClang
6.0.0), in a variety of configurations.  I've also set up continuous
integration using Travis CI [2], so libssh2 is continually tested on
Linux in 32 combinations of OpenSSL/Libgrypt, 32-bit/64-bit,
GCC/Clang, shared/static, with/without zlib.

I've not been able to test with VMS or Netware, two of the more
unusual platforms that we support.  I don't have access to that kind
of hardware, so any help testing would be greatly appreciated.

Why?
====

If you are wondering what benefits this change brings, there is plenty
of discussion about this out there about the merits of CMake, but the
main reasons that it makes sense for libssh2 are:

1) We were trying (failing?) to maintain build files by hand for
   non-autotool platforms such as Windows.  As well as being a waste
   of effort, these custom jobds rarely kept up with libssh2
   development.  For example, they are hardcoded to use OpenSSL even
   though libssh2 supports multiple crypto backends.  Using CMake we
   are now able to build libssh2 for all the common platforms and
   crypto backends using a single build configuration.  When it is
   updated to accomodate a new feature, all platforms feel the
   benefit simultaneously.

2) Even if we supported your _platform_, our build setup restricted
   your choice of development environment to GNU Makefiles on Unix or
   Visual Studio 6 on Windows.  Using CMake we can now generate the
   necessary files for your choosen environment: GNU Makefiles, Visual
   Studio 2005-2014, Xcode, Eclipse CDT ... and many more [1].

3) CMake makes it easy to automatically fetch and build a projects as
   a component of a larger CMake project.  This a big deal for a
   library.

4) For better or worse, CMake has won the latest war of the C/C++
   build systems.  This makes it the focus of new innovation and the
   support community is very active.  As more and more projects are
   adopting it, they can take advantage of 3).

What doesn't work yet?
======================

I've already mentioned that I've not been able to test VMS or Netware,
so I'm going to assume that doesn't work simply because I've not done
anything with the code in the `vms` and `nw` directories yet.  It's
possible that that code is redunant for CMake but, if not, I'll adjust
the build files if a VMS/Netware user can explain to me what they
need.

Compiling with OpenWatcom works but I'm having trouble linking against
OpenSSL.  Using WinCNG also doesn't compile and it seems to be a SDK
issue.  Can anyone familiar with that compiler help me understand what
extra steps are necessary?  Another issue with OpenWatcom is that
version 1.9 doesn't work if CMake is installed in a path containing
spaces or parentheses.  The bug is with the compiler, but I've filed a
CMake issue to request a workaround [3].

Libssh2 inherited some complex compiler warning settings from cURL.
I've not ported this to CMake yet because I want to understand the
goal first, so that I can do this in a cross-platform way.  For now,
I've turned on -Wall or /W4.  Would anyone like other warnings
enabled?  If so, which?

Any changes committed to develop since I branched are not yet
integrated into the cmake branch.  That's the next job.

Thanks for listening.  Fire away.

Alex

[1] http://www.cmake.org/cmake/help/v3.1/manual/cmake-generators.7.html
[2] https://travis-ci.org/alamaison/libssh2
[3] http://www.cmake.org/Bug/view.php?id=15279

--

-- 
Swish - Easy SFTP for Windows Explorer (http://www.swish-sftp.org)
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Niels Larsen | 4 Dec 20:36 2014
Picon

gcc -V causes ubuntu 14.04 compile failure?

Libssh2 people,

On stock Ubuntu 14.04 (Linux 64 bit) I get:

~/BION/Software/Package_sources/Utilities/libssh2-1.4.3> ./configure 
checking whether to enable maintainer-specific portions of Makefiles...
no
checking for sed... /bin/sed
checking for a BSD-compatible
install... /home/bion/BION/Software/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir
-p... /home/bion/BION/Software/bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking libssh2 version... 1.4.3
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
configure: autobuild project... libssh2
configure: autobuild revision... 1.4.3
configure: autobuild hostname... bion-VirtualBox
configure: autobuild timestamp... 20141204-202652
checking for style of include used by make... GNU
checking for gcc... gcc
checking whether the C compiler works... no
configure: error: in
`/home/bion/BION/Software/Package_sources/Utilities/libssh2-1.4.3':
configure: error: C compiler cannot create executables
See `config.log' for more details
~/BION/Software/Package_sources/Utilities/libssh2-1.4.3> 

and config.log is attached. It looks as if gcc is given the -V argument,
which 
gcc does not understand anymore. The latest daily snapshot (december 4)
behaves the same. Can someone tell me where to edit if there is an easy 
fix, or better, post an update with the fix?

Niels L

Attachment (config.log): text/x-log, 10 KiB
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
libssh2 Trac | 3 Dec 20:18 2014
Picon

#290: segfault in diffie_hellman_sha1

#290: segfault in diffie_hellman_sha1
--------------------+--------------------
 Reporter:  mstrsn  |       Owner:
     Type:  defect  |      Status:  new
 Priority:  normal  |   Milestone:  1.4.3
Component:  crypto  |     Version:  1.4.2
 Keywords:          |  Blocked By:
   Blocks:          |
--------------------+--------------------
 If an application happens to call the OpenSSL routine EVP_cleanup, then
 libssh2 will generate a segfault at the call to libssh2_sh1_update at line
 249 in kex.c. Of course, the application should not call EVP_cleanup
 prematurely, but to avoid crashes in your library, I suggest you guard
 against this possibility in a manner similar to your guard around the call
 to libssh2_md5_update at line 222 in kex.c.

--

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

_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
libssh2 Trac | 3 Dec 20:17 2014
Picon

#289: Configure check for EVP_aes_128_ctr does not work properly

#289: Configure check for EVP_aes_128_ctr does not work properly
--------------------------------------+--------------------
 Reporter:  maurerpe                  |       Owner:
     Type:  defect                    |      Status:  new
 Priority:  normal                    |   Milestone:  1.4.3
Component:  misc                      |     Version:  1.4.2
 Keywords:  autoconf EVP_aes_128_ctr  |  Blocked By:
   Blocks:                            |
--------------------------------------+--------------------
 configure never detects EVP_aes_128_ctr even when it is present in
 openssl.  I have confirmed this in libssh2 1.4.3 using both openssl 1.0.1h
 and libressl 2.0.5.

 The issue seems to be the order in which libraries appear on the command
 line for the configure test.  I have a simple patch that resolves the
 issue and causes libssh2 to properly detect EVP_aes_128_ctr for both
 openssl and libressl.

 The solution is to use put the libs (-lcrypto -lssl) in the LIBS variable
 and not the LDFLAGS variable.  Patch attached.

--

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

_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
libssh2 Trac | 3 Dec 20:18 2014
Picon

#291: libssh2_agent_connect always returns -39 when using in on iOS

#291: libssh2_agent_connect always returns -39 when using in on iOS
--------------------+--------------------
 Reporter:  ali312  |       Owner:
     Type:  defect  |      Status:  new
 Priority:  normal  |   Milestone:  1.4.3
Component:  API     |     Version:  1.4.2
 Keywords:          |  Blocked By:
   Blocks:          |
--------------------+--------------------
 I'm trying to use lissh2 agent in my iOS app

 I've tried several different ways, even completely copy&paste in an empty
 http://www.libssh2.org/examples/ssh2_agent.html

 And when I get to libssh2_agent_connect it always returns -39

 All other methods work good

--

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

_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
libssh2 Trac | 3 Dec 20:18 2014
Picon

#292: Wrap all uses of socket with callbacks for better compatibility

#292: Wrap all uses of socket with callbacks for better compatibility
-------------------------+------------------
 Reporter:  Eschaton     |       Owner:
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:
Component:  API          |     Version:
 Keywords:               |  Blocked By:
   Blocks:               |
-------------------------+------------------
 Only a subset of the functions used on a socket/fd passed into libssh2 are
 wrapped in standard callbacks. For example, libssh2 will still invoke the
 stock select/poll and ioctl functions on a socket it's passed, to do
 things like check for I/O and control non-blocking behavior.

 This makes it between difficult and impossible to use libssh2 (without
 significant modification) over another transport, or even over a socket
 where full control can't be given to the library (such as a socket managed
 via dispatch I/O on OS X or iOS).

 If all calls on the socket used by libssh2 always went through semantic
 callback wrappers (eg "set non blocking," "set reusable" and so on, rather
 than "do an ioctl") then it would be possible to use libssh2 with an
 entirely-application-layer transport. It might also make it easier to
 abstract

--

-- 
Ticket URL: <https://trac.libssh2.org/ticket/292>
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