Code Monkey home page Code Monkey logo

parallelssh / ssh2-python Goto Github PK

View Code? Open in Web Editor NEW
226.0 19.0 68.0 16.92 MB

Python bindings for libssh2 C library.

Home Page: https://parallel-ssh.org

License: GNU Lesser General Public License v2.1

Python 2.56% Shell 14.80% Batchfile 0.02% Dockerfile 0.15% CMake 1.88% Makefile 8.35% C++ 0.15% M4 2.32% Roff 6.02% C 58.26% Awk 0.03% Clean 0.78% Cython 3.25% RPGLE 1.43%
ssh2 ssh library extension python-library python libssh2 cython

ssh2-python's People

Contributors

brejoc avatar dvolodin7 avatar eliwe avatar kddubb avatar namamishanker avatar odidev avatar pkittenis avatar rasmunk avatar thrasibule avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ssh2-python's Issues

Question regarding the File type

Hi, Thank you for the wonderful library, I'm integrating all my code from paramilo to this library due to it's fast and intuitive way to use!

Just one thing that I couldn't figure out for integration is the way to check the remote file type using such as LIBSSH2_SFTP_S_IFDIR. The main idea is make a replica of
os.path.isdir() for remote server.

I'm trying to use fstat to find the way, but since Im nor familer with libssh2,
struggling to find it out, so hope to ask if there is any simple way to do this using your library.

Thanks!

Segmentation Fault

I am running 50 threads in parallel with 10 ssh connections per thread on a 46 core server. I realize this is a ton of multithreading but I was under the impression this framework is thread safe. Please find the backtrace of segmentation fault below.

parallel-ssh version: 1.3.2
ssh2-python: 0.9.1

Program terminated with signal 11, Segmentation fault.
#0  0x00007fbfd490830f in sha1_block_data_order_avx () from /home/research/.virtualenvs/darwin/lib/python2.7/site-packages/ssh2/.libs/libcrypto-2d5d481c.so.1.0.0
Missing separate debuginfos, use: debuginfo-install bzip2-libs-1.0.5-7.el6_0.x86_64 cyrus-sasl-lib-2.1.23-15.el6_6.2.x86_64 glibc-2.12-1.192.el6.x86_64 keyutils-libs-1.4-5.el6.x86_64 krb5-libs-1.10.3-57.el6.x86_64 libcom_err-1.41.12-22.el6.x86_64 libgcc-4.4.7-18.el6.x86_64 libgcrypt-1.4.5-11.el6_4.x86_64 libgpg-error-1.7-4.el6.x86_64 libselinux-2.0.94-7.el6.x86_64 libstdc++-4.4.7-18.el6.x86_64 libuuid-2.17.2-12.24.el6.x86_64 libxml2-2.7.6-21.el6_8.1.x86_64 libxslt-1.1.26-2.el6_3.1.x86_64 mysql-libs-5.1.73-7.el6.x86_64 ncurses-libs-5.7-4.20090207.el6.x86_64 nspr-4.11.0-1.el6.x86_64 nss-3.21.0-8.el6.x86_64 nss-softokn-freebl-3.14.3-23.3.el6_8.x86_64 nss-util-3.21.0-2.el6.x86_64 openssl-1.0.1e-48.el6_8.3.x86_64 zlib-1.2.3-29.el6.x86_64
(gdb) bt full
#0  0x00007fbfd490830f in sha1_block_data_order_avx () from /home/research/.virtualenvs/darwin/lib/python2.7/site-packages/ssh2/.libs/libcrypto-2d5d481c.so.1.0.0
No symbol table info available.
#1  0xca62c1d6ca62c1d6 in ?? ()
No symbol table info available.
#2  0xca62c1d6ca62c1d6 in ?? ()
No symbol table info available.
#3  0xca62c1d6ca62c1d6 in ?? ()
No symbol table info available.
#4  0xca62c1d6ca62c1d6 in ?? ()
No symbol table info available.
#5  0xca62c1d6ca62c1d6 in ?? ()
No symbol table info available.
#6  0xca62c1d6ca62c1d6 in ?? ()
No symbol table info available.
#7  0xca62c1d6ca62c1d6 in ?? ()
No symbol table info available.
#8  0xca62c1d6ca62c1d6 in ?? ()
No symbol table info available.
#9  0x0000000000000000 in ?? ()
No symbol table info available.
(gdb) info threads
  11 Thread 0x7fc04727a700 (LWP 21356)  0x0000003dae4df283 in poll () from /lib64/libc.so.6
  10 Thread 0x7fbfe3654700 (LWP 21350)  0x0000003dae4df283 in poll () from /lib64/libc.so.6
  9 Thread 0x7fc05427a700 (LWP 21352)  0x0000003dae4df283 in poll () from /lib64/libc.so.6
  8 Thread 0x7fc054c7b700 (LWP 21351)  0x0000003dae4df283 in poll () from /lib64/libc.so.6
  7 Thread 0x7fc063564700 (LWP 20402)  0x0000003dae4e90a3 in epoll_wait () from /lib64/libc.so.6
  6 Thread 0x7fbfe0c53700 (LWP 21349)  0x0000003dae4df283 in poll () from /lib64/libc.so.6
  5 Thread 0x7fc046879700 (LWP 21357)  0x0000003dae80edac in send () from /lib64/libpthread.so.0
  4 Thread 0x7fbfde252700 (LWP 21348)  0x0000003dae4df283 in poll () from /lib64/libc.so.6
  3 Thread 0x7fc049c7b700 (LWP 21355)  0x0000003dae4df283 in poll () from /lib64/libc.so.6
  2 Thread 0x7fc052e78700 (LWP 21354)  0x0000003dae4df283 in poll () from /lib64/libc.so.6
* 1 Thread 0x7fc053879700 (LWP 21353)  0x00007fbfd490830f in sha1_block_data_order_avx () from /home/research/.virtualenvs/darwin/lib/python2.7/site-packages/ssh2/.libs/libcrypto-2d5d481c.so.1.0.0

Any thoughts? I can reproduce this every time so I am open for more debugging.

sftp copy enters exeption Timeout if catched signal (SIGHUP, SIGTERM) received (blocking mode)

Bug reports

I'm writing a service (daemon) that do some tasks in background.
With signal module the service catches SIGHUP to do a reload of the configuration file.

If SIGHUP (or other signal like SIGINT, SIGTERM, SIGUSR1...), the sftp copy (and maybe every task currently in process over a ssh2 session) stops and terminate on exception Timeout.

Steps to reproduce:

  1. Example code that produces error.
import os
import socket
import signal
from ssh2.session import Session
from ssh2.sftp import LIBSSH2_FXF_CREAT, LIBSSH2_FXF_WRITE, \
    LIBSSH2_SFTP_S_IRUSR, LIBSSH2_SFTP_S_IRGRP, LIBSSH2_SFTP_S_IWUSR, \
    LIBSSH2_SFTP_S_IROTH

def connect():
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect(('10.0.0.1', 22))
    session = Session()
    session.handshake(sock)
    session.userauth_password('user', 'password')
    return (sock, session)

def copy_sftp(session, source, dest):
    sftp = session.sftp_init()
    mode = LIBSSH2_SFTP_S_IRUSR | \
           LIBSSH2_SFTP_S_IWUSR | \
           LIBSSH2_SFTP_S_IRGRP | \
           LIBSSH2_SFTP_S_IROTH
    f_flags = LIBSSH2_FXF_CREAT | LIBSSH2_FXF_WRITE
    with open(source, 'rb') as local_fh, \
            sftp.open(dest, f_flags, mode) as remote_fh:
        for data in local_fh:
            remote_fh.write(data)

def handler(signum, frame):
    print('Signal handler called with signal', signum)

if __name__ == '__main__':
    signal.signal(signal.SIGHUP, handler)
    sock, session = connect()
    copy_sftp(session, 'my_big_file', 'my_big_file')
  1. Stack trace or error messages.
$ ./ssh_test.py 
Signal handler called with signal 1
Signal handler called with signal 1
Traceback (most recent call last):
  File "./ssh_test.py", line 44, in <module>
    copy_sftp(session, 'my_big_file', 'my_big_file')
  File "./ssh_test.py", line 34, in copy_sftp
    remote_fh.write(data)
  File "ssh2/sftp_handle.pyx", line 291, in ssh2.sftp_handle.SFTPHandle.write
  File "ssh2/utils.pyx", line 113, in ssh2.utils.handle_error_codes
ssh2.exceptions.Timeout

Expected behaviour:
I don't know what is the expected behaviour but how could I use signals with ssh2-python ?
When a SIG is catched by python signal, ssh2 should not stop his work with timeout exception.
Is this related to GIL ? May I have work with a non-blocking session ?

Actual behaviour:
sftp transfer failed and terminate with a timeout exception when a signal is received.

Additional info: [Include version of libssh2 and any other relevant information.]
libssh2 1.8.0
ssh2-python installed with pip

Verifying the hostkey_hash?

I've been looking through the code for a way to verify the libssh2_hostkey_hash, but so far, cannot see a way to do this. Am I missing something?

userauth_password takes a long time and not ending

here is my code:

_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
_sock.settimeout(10)
_sock.connect((my_host, 22))

s = Session()
s.handshake(_sock)

s.userauth_password('root', str(my_password))

Public key example incorrect

Minor issue, the public key example in the readme is incorrect:
this:

session.userauth_publickey_fromfile(
    username, 'my_pkey.pub', 'my_pkey', '')

shouldn't it be like this?

session.userauth_publickey_fromfile(
    username, 'pkey', 'optional pkey.pub' , 'optional passphrase')

Can't run ssh2-python with python3-dbg

Bug reports

Steps to reproduce:

  • Install python3-dbg in addition to the standard python installation.
  • Run the python3-dbg command line
  • Try to import ssh2.session and see that it fails
  1. Example code that produces error.
hgst@BUILD:~/src/nile$ python3-dbg 
Python 3.5.2 (default, Nov 12 2018, 13:43:14) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from ssh2.session import Session
  1. Stack trace or error messages.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'ssh2.session'
>>> 

Expected behaviour: [What was expected to happen.]

ssh2-python should work in a python3-dbg environment.

Actual behaviour: [What actually happened.]

An import error is thrown. My guess is that the dbg version of python is expecting access to the debug symbols of the underlying libssh2 library which aren't included (as far as I can tell).

Additional info: [Include version of libssh2 and any other relevant information.]

Unfortunately, part of the reason I need this is that I'm trying to debug core dumps causes by memory corruption using ssh2-python. My guess is that I'm not cleaning up properly, but it's hard to pinpoint the issue when the coredumps are obfuscated libssh2 libraries.

Thanks for looking at this!

feature request - certificate based authentication

ssh2-python + parallel-ssh provides very promising performance results for our usecase of running thousands of commands remotely. However in our particular usecase authentication must happen via certificate. Are there any plans for adding it in ssh2-python.

Because of this we are stuck with paramiko, buggy and poor performer, because it has support for ssh certificates.

Import Error when using pyximport.install()

Setup

$ uname -a
Linux dev 4.4.0-119-generic #143-Ubuntu SMP Mon Apr 2 16:08:24 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
$ virtualenv ssh2python_venv -p `which python2`
Running virtualenv with interpreter /home/dev/adm/venv/bin/python2
Using real prefix '/usr'
New python executable in /home/dev/ssh2python_venv/bin/python2
Not overwriting existing python script /home/dev/ssh2python_venv/bin/python (you must use /home/dev/ssh2python_venv/bin/python2)
Installing setuptools, pip, wheel...done.
$ source ssh2python_venv/bin/activate
(ssh2python_venv) $ which python
/home/dev/ssh2python_venv/bin/python
(ssh2python_venv) $ python --version
Python 2.7.12
(ssh2python_venv) $ pip install Cython
Collecting Cython
  Using cached https://files.pythonhosted.org/packages/f6/23/ef5521e077e9e7ef8e4603e27713ae95fee69e9c19c
Installing collected packages: Cython
Successfully installed Cython-0.28.3
(ssh2python_venv) $ pip install ssh2-python
Collecting ssh2-python
  Using cached https://files.pythonhosted.org/packages/16/f7/fab75dfa5dbb0ee6c56dde04be05c1074b1cafdc6d766b6ef92bcf01240f/ssh2_python-0.13.0.post2-cp27-cp27mu-manylinux1_x86_64.whl
Installing collected packages: ssh2-python
Successfully installed ssh2-python-0.13.0.post2
(ssh2python_venv) $ pip freeze
Cython==0.28.3
ssh2-python==0.13.0.post2

Error

(ssh2python_venv) $ python -c "import ssh2.session"
(ssh2python_venv) $ echo $?
0
(ssh2python_venv) $ python -c "import pyximport;pyximport.install();import ssh2.session" | head
ssh2python_venv/local/lib/python2.7/site-packages/ssh2/session.pyx:483:19: Compile-time name 'EMBEDDED_LIB' not defined

/home/dev/.pyxbld/temp.linux-x86_64-2.7/pyrex/ssh2/session.c:1:2: error: #error Do not use this file, it is the result of a failed Cython compilation. 
 #error Do not use this file, it is the result of a failed Cython compilation.                                                                              
  ^

I think this happens because the binary wheel also includes the .pyx files, instead of just the .so files. Cython picks these up and tries to compile them instead of just using the .so file. If there is no particular reason to include the .pyx files in the wheel, I would ask if they can be excluded.

I've looked to see if I can restrict what pyximport automatically compiles, but haven't found anything so far.

From source builds do not include embedded libssh2 in package

Bug reports

Steps to reproduce:

  1. Run pip install ssh2-python on Travis when using PyPy. (I have tried with both 2.7 and 3.5 versions of PyPy 6.0.
  2. In the pypy interpreter, try to run from ssh2.session import Session.
  3.  from ssh2.session import Session
     E   ImportError: unable to load extension module '/home/travis/virtualenv/pypy2.7-6.0.0/
     site-packages/ssh2/session.pypy-41.so': libssh2.so.1: cannot open shared object file: 
     No such file or directory
    

I also tried installing the libssh2-1-dev package on Travis first, and got a slightly different error message:

ImportError: unable to load extension module '/home/travis/virtualenv/pypy2.7-6.0.0/
             site-packages/ssh2/session.pypy-41.so': /home/travis/virtualenv/pypy2.7-6.0.0/site-
             packages/ssh2/session.pypy-41.so: undefined symbol: libssh2_session_set_last_error

Expected behaviour: Able to import Session properly in PyPy.

Actual behaviour: Exceptions above.

Additional info: Ubuntu 16.04. You can see multiple failed attempts on Travis (as part of a project that was trying to use parallel-ssh here and here.

scp a directory

Hello everyone,

thank you very much for this awesome library. I'm actually moving all paramiko code to ssh2-python and it's incredibly fast.

Now I'm wondering if there's a way to transfer an entire directory using SCP, as scp command does when running scp -r.

Best regards,
Andrea

while size > 0 nevers exits

Im trying to follow the online examples and if I run the following the loop never exits.

If I remove the while loop all is good. If the read() call is waiting then whats the point of the while.

Similar code works fine same server with paramiko using "while not channel.recv_ready() :" etc.

Is this a bug or by design

Code:

import sys
import socket

from ssh2.session import Session

SSH_SERVER_IP ="IPADDRESS"

def main():

    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect((SSH_SERVER_IP, 22))

    session = Session()
    session.handshake(sock)
    session.userauth_password("USERNAME", "PASSWORD")

    channel = session.open_session()

    channel.shell();

    # All I want to do here is display returned banner.

    size, data = channel.read()
    while size > 0:
        print(data.decode())         # <<<< Displays banner fine.
        size, data = channel.read()  # <<<< Sticks here on debug and never exits

    channel.close()

    print("Exit status: %s" % channel.get_exit_status())

if __name__ == '__main__':
    sys.exit(main())

Bug reports

Expected behaviour: Exit the while loop

Actual behaviour: Didn't Exit

Add additional key type flags to hostcheck module - update example

Using Python 3.6 the example host key verification code generates the following error message:
Traceback (most recent call last):
File "example_host_key_verification.py", line 29, in
else LIBSSH2_KNOWNHOST_KEY_SSHDSS
NameError: name 'LIBSSH2_KNOWNHOST_KEY_SSHDSS' is not defined

Easily fixed by adding LIBSSH2_KNOWNHOST_KEY_SSHDSS to the imports but even then it will still not work:
Traceback (most recent call last):
File "example_host_key_verification.py", line 39, in
kh.checkp(host, 22, host_key, type_mask)
TypeError: Argument 'host' has incorrect type (expected bytes, got str)

Now I am not sure what exactly it wants here, converting the host string to bytes is not the answer feeding it the IP that the host resolved as in bytes does not seem to work either.

Using python 2.7 instead (bad, bad, bad, time to migrate already)
Traceback (most recent call last):
File "example_host_key_verification.py", line 39, in
kh.checkp(host, 22, host_key, type_mask)
File "ssh2/knownhost.pyx", line 252, in ssh2.knownhost.KnownHost.checkp
ssh2.exceptions.KnownHostCheckNotFoundError: ('Host %s not found in known hosts collection', 'localhost')

Yet I am 100% certain that localhost is in the known hosts file so I have a feeling that even though there is no complaint about not getting bytes as a first parameter to kh.checkp on line 39 it is not able to deal with the string it gets and check the host/fingerprint correctly against the known hosts file.

Shell usage last read hang

HI
i tried to use execute but i figure out that execute is for single command
i need to run continues commands without initiate new session each time
i tried to use read/write cycles but the read hang on the last iteration

code:

        self.ssh_session.flush()
        self.ssh_session.write(cmd + '\n')
        if delay > 0:
            time.sleep(delay)
        size, data = self.ssh_session.read()
        while size > 0:
            self.report.debug(data)
            size, data = self.ssh_session.read()
        return data

Thanks

sftp open handle failures do not raise exceptions

ran into that today. looks like a libssh2 issue and ru-ssh2 has the same issue. paramiko is fine.

standard chroot setup on Ubuntu 16.04 LTS:
Match group sftponly
    ChrootDirectory /home/%u
    X11Forwarding no
    AllowTcpForwarding no
    ForceCommand internal-sftp

test code:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import socket
from ssh2.session import Session

CHROOT_DIR = 'CHROOT_DIR'
CHROOT_UNAME = 'CHROOT_UNAME'
CHROOT_PASSWD = 'CHROOT_PASSWD'
ADMIN_UNAME = 'ADMIN_UNAME'
ADMIN_PASSWD = 'ADMIN_PASSWD'

host = 'CHROOTED_HOST'

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((host, 22))
sess = Session()
sess.handshake(sock)
sess.userauth_password(ADMIN_UNAME,ADMIN_PASSWD)
# or
# sess.userauth_password(CHROOT_UNAME,CHROOT_PASSWD)
sftp = sess.sftp_init()
with sftp.opendir(CHROOT_DIR) as fd:
    for size, buf, attrs in fd.readdir():
        print(f'{size},{buf},{attrs}')

output:

admin group user:
1,b'.',
2,b'..',
11,b'CHROOTED_DIR',

chrooted user (the error from ru-ssh2 is nearly as cryptic):
Traceback (most recent call last):
  File "py_ssh2_test.py", line 22, in 
    with sftp.opendir(CHROOT_DIR) as fd:
AttributeError: __enter__

Cut command output

The output of the command has more than 110 lines and ends up cutting the output, when I use the while execution hangs, is there any way out? How to make channel.read () read only the last line of the output?

#start interface shell in the channel
channel.shell()

channel.write("config\n")
channel.write("show service-port gpon match vlan vlan-id any\n")
time.sleep(1)
size, data = channel.read()
while size > 0:
    print(data)
    size, data = channel.read()
channel.close()
print("Exit status {0}".format(channel.get_exit_status()))

sftp.open is terribly slow

I have attempted to use ssh2-python to upload large files to an ssh server, but I find that there is something terribly broken here. I'm using version 0.17.0 installed using 'pip' and the example script provided just to get stuff working. Using 'sftp' or 'scp' gives me throughput at around 200-300 Mbps, whereas ssh2-python gives me around 100 Kbps... I thought this was supposed to be fast?

Trying the scp example yields better results, averaging at 27 MB/s.

Incompatible with PyPy

Steps to reproduce:

  1. Try to pip install ssh2-python from a PyPy interpreter.
  2. Build will fail:
  cc -O2 -fPIC -Wimplicit -Ilibssh2/include -I/home/travis/virtualenv/pypy-5.4.1/include -c pssh/native/ssh2.c -o build/temp.linux-x86_64-2.7/pssh/native/ssh2.o -O3
  pssh/native/ssh2.c:845:3: error: unknown type name โ€˜PyBaseExceptionObjectโ€™
     PyBaseExceptionObject __pyx_base;
     ^
  pssh/native/ssh2.c:857:3: error: unknown type name โ€˜PyBaseExceptionObjectโ€™
     PyBaseExceptionObject __pyx_base;
     ^
  pssh/native/ssh2.c:917:3: error: unknown type name โ€˜PyBaseExceptionObjectโ€™
     PyBaseExceptionObject __pyx_base;
     ^
  pssh/native/ssh2.c:929:3: error: unknown type name โ€˜PyBaseExceptionObjectโ€™
     PyBaseExceptionObject __pyx_base;
     ^
  pssh/native/ssh2.c:941:3: error: unknown type name โ€˜PyBaseExceptionObjectโ€™
     PyBaseExceptionObject __pyx_base;
     ^
  pssh/native/ssh2.c:953:3: error: unknown type name โ€˜PyBaseExceptionObjectโ€™
     PyBaseExceptionObject __pyx_base;
     ^
  pssh/native/ssh2.c:965:3: error: unknown type name โ€˜PyBaseExceptionObjectโ€™
     PyBaseExceptionObject __pyx_base;
     ^
  pssh/native/ssh2.c:976:3: error: unknown type name โ€˜PyBaseExceptionObjectโ€™
     PyBaseExceptionObject __pyx_base;
     ^
  error: command 'cc' failed with exit status 1

Expected behaviour: Install would succeed.

Actual behaviour: Compile failed as above.

Additional info: libssh2 1.4.3, Ubuntu 14.04, gcc 4.8.4, PyPy 5.4.1

Error during import of Session

Bug reports

Steps to reproduce:

  1. Example code that produces error.
    from ssh2.session import Session

  2. Stack trace or error messages.
    Error starting: /usr/lib64/python2.7/site-packages/ssh2/session.so: undefined symbol: PyUnicodeUCS4_DecodeUTF8

Expected behaviour: [What was expected to happen.]
Session to be imported

Actual behaviour: [What actually happened.]
see error above

Additional info: [Include version of libssh2 and any other relevant information.]
sys.path = ['/opt/splunk/lib/python2.7/site-packages/splunk/persistconn', '/opt/splunk/lib/python2.7/site-packages', '/opt/splunk/lib/python27.zip', '/opt/splunk/lib/python2.7', '/opt/splunk/lib/python2.7/plat-linux2', '/opt/splunk/lib/python2.7/lib-tk', '/opt/splunk/lib/python2.7/lib-old', '/opt/splunk/lib/python2.7/lib-dynload', '/opt/splunk/etc/apps/cliauto/bin', '/opt/splunk/etc/apps/cliauto/bin/cliautolib', '/usr/lib64/python2.7/site-packages']

Build and Cython compiling instructions

I would like to build ssh2-python (to test code from a branch, and to possibly contribute in the future), but there are no instructions on how to build it. It would also be interesting to have a readme on how to convert Cython code to C. I think I'll find everything I need in the Travis file, so no need to hurry. Thanks in advance.

session.forward_listen_ex bound_port access

When calling forward_listen_ex the third parameter is "bound_port" which is passed by reference in the pyx file to libssh2

With python not having pointers to int values, how would one get access to that resulting port value?

I have tried

session.forward_listen_ex('localhost', 0 , bound_port, 10)

And the forward is created, but bound_port is not updated.

I could add a PR for a forward_listen_ex2 which returns the tuple of the port and Listener? Or is there a way to do this?

session dealloc

Hi,

I have an issue that originates from the usage of dealloc to close and release sessions.
The code in dealloc calls
c_ssh2.libssh2_session_disconnect(self._session, b"end") c_ssh2.libssh2_session_free(self._session)

In session disconnect a message is sent to the other side singling the disconnect. But by the time this function is called (dealloc is called at some point after the object is not used any more) the underlaying socket might have been closed and libssh2 will return and error . Worst yet is that the fileno gets reused for another connection and the message will be sent to a different peer (this happened to me).

I changed the API for session to include a release function. I also removed the free from channel as it shouldn't be called if the session has been release.
see:
https://github.com/eliwe/ssh2-python

I didn't send a pull request as its not a proper fix (it does solve my immediate problem).

I didn't write sample code to recreate the issue as its not 100 reproducible.

Wheels on pypi do not contain static version

Directions

When importing the package I get an error. It looks like it is calling some git commands and trying to create a version. Looking into the code, I think it is supposed to do this only when it is built and replace _version.py with a static version getter.

The windows wheels seem to have the static file, but the linux ones do not (at least the python 2.7 ones I looked at).

Bug reports

Steps to reproduce:

  1. Install ssh2_python-0.6.0-cp27-cp27m-manylinux1_x86_64.whl (newer versions have same problem also)
  2. look at /ssh2/_version.py

from ssh2.session import Session
path-to-site-packages/ssh2/init.py:2: in
version = get_versions()['version']
path-to-site-packages/ssh2/_version.py:507: in get_versions
pieces = git_pieces_from_vcs(cfg.tag_prefix, root, verbose)
path-to-site-packages/ssh2/_version.py:298: in git_pieces_from_vcs
pieces["distance"] = int(count_out) # total number of commits
TypeError: int() argument must be a string or a number, not 'NoneType'

Expected behaviour:
_version.py contains static version, does not require git to be installed

Actual behaviour:
_version.py makes calls to git when ssh2 is imported

Additional info:
Version 0.6.0
Platform: Centos 6
Python version: 2.7.14

Damaged session if direct_tcpip channel open fails

import socket
from ssh2.session import Session
from ssh2.listener import *

username='user'
passwd='password'
serverA='myServerA'
serverB='doesNotExist'

#open socket connection
sock = socket.socket(socket.IF_INET, socket.SOCK_STREAM)
sock.connect((serverA, 22))

#open session and authenticate
session = Session()
session.handshake(sock)
session.userauth_password(username, passwd)
session.set_timeout(2000)

#demonstrate successful channel open and execute command on serverA
chan = session.open_session()
if chan:
    print('successfully opened channel with serverA')
    chan.execute('ls')
    chan.close()
else:
    print('Failed to open channel with serverA')

#Try to open direct tcpip channel, via serverA SSH tunnel, to unreachable serverB
direct_chan = session.direct_tcpip(serverB, 22)
if direct_chan:
    print('ServerB was reached')
else:
    print('ServerB was unreachable')

#Cannot now open channel with serverA - why???
chan = session.open_session()
if chan:
    print('successfully opened channel with serverA')
    chan.execute('ls')
    chan.close()
else:
    print('Failed to open channel with serverA')

session.disconnect()
sock.close()

Expected behaviour:
Assume serverA is a reachable SSH server, and serverB is unreachable. You successfully open a channel and execute a command on serverA. With the same session, you try to open a tunneled direct_tcpip connection to an unreachable serverB. The direct_tcpip channel fails as expected. I would then still expect to be able to use the same session to sucessfully open a channel and execute a command on serverA a second time

Actual behaviour:
The second time you try to open a channel to serverA to execute a command, the open_session fails. It's like the session has been damaged by the failure to open the direct_tcpip connection to serverB.

Note that if serverB is reachable, then the session is still ok, and you can still open a channel to serverA and execute a command.

Why does this happen and is there a fix? I want to continue using a session for communication with serverA even if serverB is unreachable.

( Not sure if my SSH session/channel terminology is exactly correct, but hopefully my meaning is clear from the code )

Local port forwarding example

Could an example be posted to the Examples directory of how one would go about performing local port forwarding? The OpenSSH command I'd like to replicate is as follows:

ssh -L LOCALPORT:HOST2:DESTINATIONPORT HOST1

SFTP False error raised during open

Using git version (master) of the ssh2-python, the sftp open code doesn't handle the LIBSSH2_ERROR_EAGAIN and raise it as an error (since c2e5381)

I made a small patch which fix the issue on my local setup, which was raising all the time an error when trying to use sftp, because of the LIBSSH2_ERROR_EAGAIN, but this is probably but the most efficient way you want to commit (this is why I didn't made any Pull Request).

The patch: maxux@7dc3833

Based on the C exemple here: http://yoyakuweb.com/lib/libssh2-1.4.3/libssh2-1.4.3/example/sftp_nonblock.c
Some waitsocket workaround should be done and not a loop like me.

Anyway, the LIBSSH2_ERROR_EAGAIN should definitively be handled during sftp open call.

From source builds on system libssh2 without Cython installed

Bug reports

Steps to reproduce:

  1. Rebuild the library using the system libssh, with the appropriate flags set (https://ssh2-python.readthedocs.io/en/latest/installation.html#system-library-build)

Expected behaviour: [What was expected to happen.]

  1. Expect to compile the library without the need for agent forwarding logic (ie libssh2_channel_request_auth_agent)

Actual behaviour: [What actually happened.]
Yields a C warning and a runtime error:

ssh2/channel.c:6902:22: warning: implicit declaration of function 'libssh2_channel_request_auth_agent' [-Wimplicit-function-declaration]
           __pyx_v_rc = libssh2_channel_request_auth_agent(__pyx_v_self->_channel);

Very clearly, this function still occurs in the generated output:

__pyx_v_rc = libssh2_channel_request_auth_agent(__pyx_v_self->_channel);

Documentation suggesting incorrect flags for sftp.open()

Steps to reproduce:

Simply use the code in the README file to read a file from SFTP:

sftp = session.sftp_init()
with sftp.open(<remote file to read>, 0, 0) as remote_fh, \
        open(<file to write>, 'wb') as local_fh:
    for size, data in remote_fh:
        local_fh.write(data)

Expected behaviour:

Data is copied from the remote file to the local file.

Actual behaviour:

No data is ever written to <file to write>. The size parameter is set by libssh2 to LIBSSH2_ERROR_SFTP_PROTOCOL (-31) and the calling sftp.last_error() will report LIBSSH2_FX_FAILURE (4). remote_fh.fstat() will succeed without issues (reporting correct data).

Additional info:

Version ssh2-python 0.6.0 with bundled libssh2.

This seems to happen because (at least up to libssh2 1.8.0) 0 and LIBSSH2_FXF_READ are not synonyms, like it is (in my understanding) incorrectly suggested in the documentation and the examples (sftp_read.py, for example). This may be tested using libssh2 directly by changing line 251 of the sftp.c example from:

libssh2_sftp_open(sftp_session, sftppath, LIBSSH2_FXF_READ, 0);

to

libssh2_sftp_open(sftp_session, sftppath, 0, 0);

This will make libssh2_sftp_read() fail in in the same way described in the actual behaviour.

I should be able to send a pull request to fix the documentation and examples if needed (and my understanding of the issue is correct).

Failed at ssh2-python after run the exe files which build by pyinstaller

Hello,

May I have a question. I met issue after used ssh2-python lib when run the exe file which using pyinstaller to build one. with the error info "ImportError: No module named 'ssh2.agent'".
Any suggestion are welcome.

Best Regards,
Harte

File "main.py", line 13, in
File "D:\Python34\lib\site-packages\pyinstaller-3.3.1-py3.4.egg\PyInstaller\lo
ader\pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.dict)
File "SSHcm.py", line 30, in
File "D:\Python34\lib\site-packages\pyinstaller-3.3.1-py3.4.egg\PyInstaller\lo
ader\pyimod03_importers.py", line 714, in load_module
module = loader.load_module(fullname)
File "ssh2\agent.pxd", line 24, in init ssh2.session
ImportError: No module named 'ssh2.agent'
[13140] Failed to execute script main

Please Delete duplicate due to github issues

HI
i tried to use execute but i figure out that execute is for single command
i need to run continues commands without initiate new session each time
i tried to use read/write cycles but the read hang on the last iteration

code:

  # Channel initialise, exec and wait for end
        self.ssh_session.flush()
        self.ssh_session.write(cmd + '\n')
        if delay > 0:
            time.sleep(delay)
        size, data = self.ssh_session.read()
        while size > 0:
            self.report.debug(data)
            size, data = self.ssh_session.read()
        return data

Thanks

Does ssh2-python support Dynamic Port Forwarding?

I manage to create an socks5 using dynamic port forwarding with assynssh library. I tried to use ssh2-python instead but don't know where to begin. It be great if anyone can show me the way. Thank you very much!

Can not get it to run (ImportError: undefined symbol: libssh2_channel_request_auth_agent)

Distributor ID: LinuxMint
Description: Linux Mint 19 Tara
Release: 19
Codename: tara
In a VM

python version: 2.7.15~rc1-1
libssh2-1: 1.8.0-1

I have reinstalled libssh2 tried different versions, just about everything I have ever done before to problem solve. Nothing seems to work

Just trying to run the import causes the error aswell

command producing error:

python perf_test_ssh2.py

Error:
python perf_test_ssh2.py
Traceback (most recent call last):
File "perf_test_ssh2.py", line 11, in
from ssh2.session import Session
File "ssh2/channel.pxd", line 24, in init ssh2.session
ImportError: /home/(MY_USER)/.local/lib/python2.7/site-packages/ssh2/channel.so: undefined symbol: libssh2_channel_request_auth_agent

Fail to open a shell

Bug report

Using libssh2 examples, I tried opening shell inside a channel in ssh2-python and it failed. I need to have a channel and a shell kept open for re-use. I cannot use exec because using exec to run a command closes the channel (which is expected).

Here is an example in the tests of libssh2:
https://github.com/libssh2/libssh2/blob/master/tests/ssh2.c#L152
libssh2_channel_shell is a macro:
https://github.com/libssh2/libssh2/blob/master/include/libssh2.h#L775

I get a LIBSSH2_ERROR_SOCKET_DISCONNECT error code (-13) when trying to open the shell.
https://github.com/libssh2/libssh2/blob/master/include/libssh2.h#L451

Steps to reproduce:

Run the SSH daemon locally and add an SSH public key to the authorized_hosts file of any user (here root)

Run the following Python script.

#!/usr/bin/env python
import socket

from ssh2.session import Session
from ssh2.utils import version

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(("localhost", 22))
session = Session()
session.handshake(sock)
session.userauth_publickey_fromfile(
    "root", "/root/.ssh/id_rsa.pub", "/root/.ssh/id_rsa", ""
)
channel = session.open_session()
print("pty")
err_code = channel.pty()
print(err_code)
print("shell")
err_code = channel.process_startup("shell", "")
print(err_code)

channel.close()
pty
0
shell
-13

Expected behaviour: 0 error code on shell request

Actual behaviour: error on shell request

Additional info:
libssh2-1:amd64 1.5.0-2ubuntu0.1
libssh2-1-dev:amd64 1.5.0-2ubuntu0.1
python-libssh2 1.0.0-1.2

Docker builds not working with older versions of libssh2 and EMBEDDED_LIB=0

Directions

Tried to built native packages for Centos 6/7 as per documentation. But script fails to run setup.py script

Bug reports

Steps to reproduce:

  1. Run ./ci/docker/build-packages.sh

Expected behaviour: [What was expected to happen.]
RPM's are built

Actual behaviour: [What actually happened.]
Erros when runing setup.py

Additional info: [Include version of libssh2 and any other relevant information.]

Centos7 log:

[root@5c04acabe44e src]# python setup.py install
running install
running bdist_egg
running egg_info
writing ssh2_python.egg-info/PKG-INFO
writing top-level names to ssh2_python.egg-info/top_level.txt
writing dependency_links to ssh2_python.egg-info/dependency_links.txt
reading manifest file 'ssh2_python.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no previously-included files matching '*' found under directory 'docker'
warning: no previously-included files found matching '.travis.yml'
writing manifest file 'ssh2_python.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
running build_ext
building 'ssh2.fileinfo' extension
gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -Ilibssh2/include -I/usr/include/python2.7 -c ssh2/fileinfo.c -o build/temp.linux-x86_64-2.7/ssh2/fileinfo.o -O3
ssh2/fileinfo.c:761:3: error: unknown type name 'libssh2_struct_stat'
   libssh2_struct_stat *_stat;
   ^
ssh2/fileinfo.c: In function '__pyx_pf_4ssh2_8fileinfo_8FileInfo___cinit__':
ssh2/fileinfo.c:1110:33: error: 'libssh2_struct_stat' undeclared (first use in this function)
         __pyx_v_self->_stat = ((libssh2_struct_stat *)malloc((sizeof(libssh2_struct_stat))));
                                 ^
ssh2/fileinfo.c:1110:33: note: each undeclared identifier is reported only once for each function it appears in
ssh2/fileinfo.c:1110:54: error: expected expression before ')' token
         __pyx_v_self->_stat = ((libssh2_struct_stat *)malloc((sizeof(libssh2_struct_stat))));
                                                      ^
ssh2/fileinfo.c: In function '__pyx_pf_4ssh2_8fileinfo_8FileInfo_7st_size___get__':
ssh2/fileinfo.c:1296:68: error: request for member 'st_size' in something not a structure or union
   __pyx_t_1 = __Pyx_PyInt_From_libssh2_uint64_t(__pyx_v_self->_stat->st_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 41, __pyx_L1_error)
                                                                    ^
ssh2/fileinfo.c: In function '__pyx_pf_4ssh2_8fileinfo_8FileInfo_7st_mode___get__':
ssh2/fileinfo.c:1356:65: error: request for member 'st_mode' in something not a structure or union
   __pyx_t_1 = __Pyx_PyInt_From_unsigned_long(__pyx_v_self->_stat->st_mode); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 45, __pyx_L1_error)
                                                                 ^
ssh2/fileinfo.c: In function '__pyx_pf_4ssh2_8fileinfo_8FileInfo_6st_ino___get__':
ssh2/fileinfo.c:1416:57: error: request for member 'st_ino' in something not a structure or union
   __pyx_t_1 = __Pyx_PyInt_From_ino_t(__pyx_v_self->_stat->st_ino); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 50, __pyx_L1_error)
                                                         ^
ssh2/fileinfo.c: In function '__pyx_pf_4ssh2_8fileinfo_8FileInfo_8st_nlink___get__':
ssh2/fileinfo.c:1476:59: error: request for member 'st_nlink' in something not a structure or union
   __pyx_t_1 = __Pyx_PyInt_From_nlink_t(__pyx_v_self->_stat->st_nlink); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 54, __pyx_L1_error)
                                                           ^
ssh2/fileinfo.c: In function '__pyx_pf_4ssh2_8fileinfo_8FileInfo_6st_uid___get__':
ssh2/fileinfo.c:1536:57: error: request for member 'st_uid' in something not a structure or union
   __pyx_t_1 = __Pyx_PyInt_From_uid_t(__pyx_v_self->_stat->st_uid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 58, __pyx_L1_error)
                                                         ^
ssh2/fileinfo.c: In function '__pyx_pf_4ssh2_8fileinfo_8FileInfo_6st_gid___get__':
ssh2/fileinfo.c:1596:57: error: request for member 'st_gid' in something not a structure or union
   __pyx_t_1 = __Pyx_PyInt_From_gid_t(__pyx_v_self->_stat->st_gid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 62, __pyx_L1_error)
                                                         ^
ssh2/fileinfo.c: In function '__pyx_pf_4ssh2_8fileinfo_8FileInfo_7st_rdev___get__':
ssh2/fileinfo.c:1656:57: error: request for member 'st_rdev' in something not a structure or union
   __pyx_t_1 = __Pyx_PyInt_From_dev_t(__pyx_v_self->_stat->st_rdev); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 66, __pyx_L1_error)
                                                         ^
ssh2/fileinfo.c: In function '__pyx_pf_4ssh2_8fileinfo_8FileInfo_10st_blksize___get__':
ssh2/fileinfo.c:1716:61: error: request for member 'st_blksize' in something not a structure or union
   __pyx_t_1 = __Pyx_PyInt_From_blksize_t(__pyx_v_self->_stat->st_blksize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 70, __pyx_L1_error)
                                                             ^
ssh2/fileinfo.c: In function '__pyx_pf_4ssh2_8fileinfo_8FileInfo_9st_blocks___get__':
ssh2/fileinfo.c:1776:60: error: request for member 'st_blocks' in something not a structure or union
   __pyx_t_1 = __Pyx_PyInt_From_blkcnt_t(__pyx_v_self->_stat->st_blocks); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 74, __pyx_L1_error)
                                                            ^
ssh2/fileinfo.c: In function '__pyx_pf_4ssh2_8fileinfo_8FileInfo_8st_atime___get__':
ssh2/fileinfo.c:1836:58: error: request for member 'st_atim' in something not a structure or union
   __pyx_t_1 = __Pyx_PyInt_From_time_t(__pyx_v_self->_stat->st_atime); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 78, __pyx_L1_error)
                                                          ^
ssh2/fileinfo.c: In function '__pyx_pf_4ssh2_8fileinfo_8FileInfo_8st_mtime___get__':
ssh2/fileinfo.c:1896:58: error: request for member 'st_mtim' in something not a structure or union
   __pyx_t_1 = __Pyx_PyInt_From_time_t(__pyx_v_self->_stat->st_mtime); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 82, __pyx_L1_error)
                                                          ^
ssh2/fileinfo.c: In function '__pyx_pf_4ssh2_8fileinfo_8FileInfo_8st_ctime___get__':
ssh2/fileinfo.c:1953:58: error: request for member 'st_ctim' in something not a structure or union
   __pyx_t_1 = __Pyx_PyInt_From_time_t(__pyx_v_self->_stat->st_ctime); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 86, __pyx_L1_error)

Please Delete duplicate due to github issues

HI
i tried to use shell implementation
i want to run several commands one after the other
for example

ls
cd a
ls

i figure out that session.execute(cmd) is for one command use only
otherwise i get BadUsageError
when i try to use write / read cycle as in the examples
the last read is always hangs

Please Help

this is my code:

    def execute(self, cmd, delay=0):
        self.ssh_session.flush()
        self.ssh_session.write(cmd + '\n')
        if delay > 0:
            time.sleep(delay)
        size, data = self.ssh_session.read()
        while size > 0:
            self.report.debug(data)
            size, data = self.ssh_session.read()
        return data

Doc: Please provide an example for continuous data reading

Thank you for an awesome library, havin' fun with it now ;)

The one thing I can't seem to figure out is how to do the equivalent of
ssh -t myhost 'less +F /var/log/messages'

(as in, allocate a TTY and keep feeding the command output into it)

would you be so kind as to provide an example on how to do something like that?

Update publickey authentication from file example

I found ssh2-python after trying to use Paramiko to log in using a new OpenSSH key and realizing it doesn't support that format.

The keys start with: -----BEGIN OPENSSH PRIVATE KEY-----

Would it be possible to get an example to start a session using one of these keys and executing a command on a remote machine?

keyboard-interactive authentication

Do you have any plans to implement this functionality?

Some systems e.g. FreeBSD use this for a simple username/password authentication and do not use the 'password' method. I have tried authenticating with 'userauth_password' but it fails with an 'Unrecognized authentication method: password' error.

Cheers

pr0pane

fatal error occurs

Bug reports

__Actual behaviour:
the following error occurs some times.

__Additional info:

libssh2 - libssh2 1.8.0
ssh2-python 0.6.0

*** glibc detected *** python: double free or corruption (fasttop): 0x000000000110c170 ***
======= Backtrace: =========
/lib64/libc.so.6[0x3080a75e66]
/usr/lib64/libcrypto.so.10(CRYPTO_free+0x1d)[0x3d0c06ad5d]
/usr/lib64/libcrypto.so.10(OBJ_NAME_add+0x92)[0x3d0c06ddc2]
/usr/lib64/libcrypto.so.10(EVP_add_cipher+0x27)[0x3d0c0f0fe7]
/usr/lib64/libcrypto.so.10(OpenSSL_add_all_ciphers+0x3eb)[0x3d0c0f559b]
/usr/lib64/libcrypto.so.10(OPENSSL_add_all_algorithms_noconf+0xe)[0x3d0c0f519e]
/usr/lib64/libssh2.so.1(libssh2_init+0x39)[0x361221e5b9]
/usr/lib64/libssh2.so.1(libssh2_session_init_ex+0xae)[0x3612212e4e]
/home/jobcenter/python-env/lib/python2.7/site-packages/ssh2/session.so(+0x65b7)[0x7faf5440f5b7]
python[0x46ded3]
python(PyObject_Call+0x47)[0x419ba7]
python(PyEval_EvalFrameEx+0x6a0b)[0x4aa8bb]
python(PyEval_EvalCodeEx+0x877)[0x4ad257]
python[0x5114a8]
python(PyObject_Call+0x47)[0x419ba7]
python(PyEval_EvalFrameEx+0x5c91)[0x4a9b41]
python(PyEval_EvalFrameEx+0x7e42)[0x4abcf2]
python(PyEval_EvalCodeEx+0x877)[0x4ad257]
python[0x5114a8]
python(PyObject_Call+0x47)[0x419ba7]
python(PyEval_EvalFrameEx+0x5c91)[0x4a9b41]
python(PyEval_EvalFrameEx+0x7e42)[0x4abcf2]
python(PyEval_EvalFrameEx+0x7e42)[0x4abcf2]
python(PyEval_EvalCodeEx+0x877)[0x4ad257]
python[0x5113ae]
python(PyObject_Call+0x47)[0x419ba7]
python[0x42296f]
python(PyObject_Call+0x47)[0x419ba7]
python(PyEval_CallObjectWithKeywords+0x43)[0x4a2d83]
python[0x4e59e2]
/lib64/libpthread.so.0[0x34802079d1]
/lib64/libc.so.6(clone+0x6d)[0x3080ae89dd]
======= Memory map: ========
00400000-0057b000 r-xp 00000000 08:02 917739 /home/jobcenter/python-env/bin/python
0077b000-007b7000 rw-p 0017b000 08:02 917739 /home/jobcenter/python-env/bin/python
007b7000-007c6000 rw-p 00000000 00:00 0
01034000-018e3000 rw-p 00000000 00:00 0 [heap]
3080200000-3080220000 r-xp 00000000 08:02 262555 /lib64/ld-2.12.so
308041f000-3080420000 r--p 0001f000 08:02 262555 /lib64/ld-2.12.so
3080420000-3080421000 rw-p 00020000 08:02 262555 /lib64/ld-2.12.so
3080421000-3080422000 rw-p 00000000 00:00 0
3080600000-3080602000 r-xp 00000000 08:02 262558 /lib64/libdl-2.12.so
3080602000-3080802000 ---p 00002000 08:02 262558 /lib64/libdl-2.12.so
3080802000-3080803000 r--p 00002000 08:02 262558 /lib64/libdl-2.12.so
3080803000-3080804000 rw-p 00003000 08:02 262558 /lib64/libdl-2.12.so
3080a00000-3080b8a000 r-xp 00000000 08:02 262556 /lib64/libc-2.12.so
3080b8a000-3080d8a000 ---p 0018a000 08:02 262556 /lib64/libc-2.12.so
3080d8a000-3080d8e000 r--p 0018a000 08:02 262556 /lib64/libc-2.12.so
3080d8e000-3080d8f000 rw-p 0018e000 08:02 262556 /lib64/libc-2.12.so
3080d8f000-3080d94000 rw-p 00000000 00:00 0
3081600000-3081615000 r-xp 00000000 08:02 262568 /lib64/libz.so.1.2.3
3081615000-3081814000 ---p 00015000 08:02 262568 /lib64/libz.so.1.2.3
3081814000-3081815000 r--p 00014000 08:02 262568 /lib64/libz.so.1.2.3
3081815000-3081816000 rw-p 00015000 08:02 262568 /lib64/libz.so.1.2.3
3081a00000-3081a83000 r-xp 00000000 08:02 262569 /lib64/libm-2.12.so
3081a83000-3081c82000 ---p 00083000 08:02 262569 /lib64/libm-2.12.so
3081c82000-3081c83000 r--p 00082000 08:02 262569 /lib64/libm-2.12.so
3081c83000-3081c84000 rw-p 00083000 08:02 262569 /lib64/libm-2.12.so
3082600000-3082604000 r-xp 00000000 08:02 262571 /lib64/libuuid.so.1.3.0
3082604000-3082803000 ---p 00004000 08:02 262571 /lib64/libuuid.so.1.3.0
3082803000-3082804000 rw-p 00003000 08:02 262571 /lib64/libuuid.so.1.3.0
3082a00000-3082a16000 r-xp 00000000 08:02 262580 /lib64/libresolv-2.12.so
3082a16000-3082c16000 ---p 00016000 08:02 262580 /lib64/libresolv-2.12.so
3082c16000-3082c17000 r--p 00016000 08:02 262580 /lib64/libresolv-2.12.so
3082c17000-3082c18000 rw-p 00017000 08:02 262580 /lib64/libresolv-2.12.so
3082c18000-3082c1a000 rw-p 00000000 00:00 0
3082e00000-3082e02000 r-xp 00000000 08:02 262234 /lib64/libutil-2.12.so
3082e02000-3083001000 ---p 00002000 08:02 262234 /lib64/libutil-2.12.so
3083001000-3083002000 r--p 00001000 08:02 262234 /lib64/libutil-2.12.so
3083002000-3083003000 rw-p 00002000 08:02 262234 /lib64/libutil-2.12.so
3086e00000-3086e02000 r-xp 00000000 08:02 262506 /lib64/libkeyutils.so.1.3
3086e02000-3087001000 ---p 00002000 08:02 262506 /lib64/libkeyutils.so.1.3
3087001000-3087002000 r--p 00001000 08:02 262506 /lib64/libkeyutils.so.1.3
3087002000-3087003000 rw-p 00002000 08:02 262506 /lib64/libkeyutils.so.1.3
3480200000-3480217000 r-xp 00000000 08:02 262195 /lib64/libpthread-2.12.so
3480217000-3480417000 ---p 00017000 08:02 262195 /lib64/libpthread-2.12.so
3480417000-3480418000 r--p 00017000 08:02 262195 /lib64/libpthread-2.12.so
3480418000-3480419000 rw-p 00018000 08:02 262195 /lib64/libpthread-2.12.so
3480419000-348041d000 rw-p 00000000 00:00 0
360f200000-360f203000 r-xp 00000000 08:02 262369 /lib64/libcom_err.so.2.1
360f203000-360f402000 ---p 00003000 08:02 262369 /lib64/libcom_err.so.2.1
360f402000-360f403000 r--p 00002000 08:02 262369 /lib64/libcom_err.so.2.1
360f403000-360f404000 rw-p 00003000 08:02 262369 /lib64/libcom_err.so.2.1
3611200000-36112db000 r-xp 00000000 08:02 262371 /lib64/libkrb5.so.3.3
36112db000-36114db000 ---p 000db000 08:02 262371 /lib64/libkrb5.so.3.3
36114db000-36114e5000 r--p 000db000 08:02 262371 /lib64/libkrb5.so.3.3
36114e5000-36114e7000 rw-p 000e5000 08:02 262371 /lib64/libkrb5.so.3.3
3611600000-3611641000 r-xp 00000000 08:02 262380 /lib64/libgssapi_krb5.so.2.2Aborted

Enhancement: libssh2_channel_direct_streamlocal

I noticed this has been added recently added to the libssh2 library and was wondering if it could be wrapped and accessible through this as well.

Here is the pull request to show the changes in libssh2: libssh2/libssh2#216

I have never worked with cpython before, otherwise i would make a pull request with the changes myself but i imagine the code in session.pyx would look something like this:

def channel_direct_streamlocal(self, socket_path not None, shost not None, int sport):
        cdef c_ssh2.LIBSSH2_CHANNEL *channel
        cdef bytes b_shost = to_bytes(shost)
        cdef bytes b_socket_path = to_bytes(socket_path)
        cdef char *_shost = b_shost
        cdef char *_socket_path = b_socket_path
        with nogil:
            channel = c_ssh2.libssh2_channel_direct_streamlocal(
                self._session, _socket_path, _shost, sport)
        if channel is NULL:
            return handle_error_codes(c_ssh2.libssh2_session_last_errno(
                self._session))
        return PyChannel(channel, self)

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.