id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	blockedby	blocking	branch_state	votes
3590	[musl alpinelinux] sftp vfs connects to localhost or another alpinelinux-host only	vaka		"I add sftp finctionality to [http://alpinelinux.org alpinelinux] 'mc' package and have a problem with connecting to non-alpinelinux hosts.

- cd /sftp://localhost -- connects ok
- cd /sftp://other.alpinelinux.host -- connects ok

connect to gentoo host:
- cd /sftp://192.168.122.1:22 -- error ''""Cannot chdir to ""/sftp://192.168.122.1:22"" (null) (11)""
''
if I describe gentoo host in .ssh/config
{{{
Host gentoo
HostName 192.168.122.1
}}}

- cd /sftp://gentoo -- error ''""Cannot chdir to ""/sftp://gentoo/"" (null) (11)""''

connect to freebsd server crashes while reading it from config
{{{
Host came
HostName freebsd.domain.com
User camedev
Port 1254
}}}

- cd /sftp://came -- error ''""25: sftp: an error occurred while reading ~/.ssh/config: Not a tty""'', then next error: ''""Cannot chdir to ""/sftp://camedev@xx.xx.xx.xx:1254/"" Invalid argument (22)""'' and then mc silently hangs :(
As you see, in this case cannot chdir to ip.ad.dr.es not to hostname as in gentoo-case.

The same server without .ssh/config:
- cd /sftp://camedev@freebsd.domain.com:1254 -- ''""Cannot chdir to ""/sftp://camedev@freebsd.domain.com:1254/"" Resource temporarily unavailable (11)""''

The same strange problems with any other non-alpinelinux server.

I try to check if it is a libssh2 bug and run simple php libssh2-based script which connects to server and shows remote directory listing. And it works well on any host.

So the problem somewhere in mc.

I deploy patches from mc-3406 and mc-3581, and make a small type_of_socket fixup.
But it didn't help.

a patch to fix type of socket below:
{{{
--- a/src/vfs/sftpfs/connection.c
+++ b/src/vfs/sftpfs/connection.c
@@ -63,11 +63,11 @@
  * @return socket descriptor number, -1 if any error was occurred
  */

-static int
+static libssh2_socket_t
 sftpfs_open_socket (struct vfs_s_super *super, GError ** mcerror)
 {
     struct addrinfo hints, *res = NULL, *curr_res;
-    int my_socket = 0;
+    libssh2_socket_t my_socket = 0;
     char port[BUF_TINY];
     int e;

@@ -388,9 +388,7 @@
     /* ... start it up. This will trade welcome banners, exchange keys,
      * and setup crypto, compression, and MAC layers
      */
-    /* FIXME: Starting in libssh2 version 1.2.8  this function is considered deprecated.
-       Use libssh2_session_handshake instead. */
-    rc = libssh2_session_startup (super_data->session, super_data->socket_handle);
+    rc = libssh2_session_handshake (super_data->session, super_data->socket_handle);
     if (rc != 0)
     {
         mc_propagate_error (mcerror, -1, _(""sftp: Failure establishing SSH session: (%d)""), rc);
--- a/src/vfs/sftpfs/internal.h
+++ b/src/vfs/sftpfs/internal.h
@@ -41,7 +41,7 @@
     char *pubkey;
     char *privkey;

-    int socket_handle;
+    libssh2_socket_t socket_handle;
     const char *fingerprint;
     vfs_path_element_t *original_connection_info;
 } sftpfs_super_data_t;
}}}

-----
$ mc -V
GNU Midnight Commander 4.8.15
Built with GLib 2.46.2
Using the ncurses library
With builtin Editor
With subshell support as default
With support for background operations
With mouse support on xterm
With multiple codepages support
Virtual File Systems: cpiofs, tarfs, sfs, extfs, ftpfs, sftpfs, fish
Data types: char: 8; int: 32; long: 32; void *: 32; size_t: 32; off_t: 64;

$ mc -F
Root directory: /home/vaka

[System data]
    Config directory: /etc/mc/
    Data directory:   /usr/share/mc/
    File extension handlers: /usr/lib/mc/ext.d/
    VFS plugins and scripts: /usr/lib/mc/
	extfs.d:        /usr/lib/mc/extfs.d/
	fish:           /usr/lib/mc/fish/

[User data]
    Config directory: /home/vaka/.config/mc/
    Data directory:   /home/vaka/.local/share/mc/

$ mc --configure-options
 '--build=i586-alpine-linux-musl' '--host=i586-alpine-linux-musl' '--prefix=/usr' '--libexecdir=/usr/lib' '--mandir=/usr/share/man' '--sysconfdir=/etc' '--enable-background' '--enable-charset' '--enable-largefile' '--enable-vfs-sftp' '--with-edit' '--with-mmap' '--with-screen=ncurses' '--with-subshell' '--with-vfs' '--without-debug' '--without-gnome' '--without-gpm-mouse' '--without-included-gettext' '--without-samba' '--without-x' 'build_alias=i586-alpine-linux-musl' 'host_alias=i586-alpine-linux-musl' 'CC=gcc' 'CFLAGS=-Os -fomit-frame-pointer' 'LDFLAGS=-Wl,--as-needed' 'CPPFLAGS=-Os -fomit-frame-pointer'

alpinelinux use musl-libc (1.1.12) not glibc.
$ uname -a
Linux alpine 4.1.15-5-grsec 6-Alpine SMP Wed Jan 20 14:05:19 GMT 2016 i686 Linux
"	defect	closed	major		mc-vfs	master	duplicate	sftp musl alpinelinux				no branch	
