Skip to content

Commit 95dba71

Browse files
authored
Direct_streamlocal implementation (#229)
* Added direct_streamlocal implementation * Added test * Updated changelog
1 parent 75344a4 commit 95dba71

File tree

5 files changed

+1388
-977
lines changed

5 files changed

+1388
-977
lines changed

Changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Changes
1414
* `ssh2.sftp_handle.SFTPHandle.closed` is now a public property indicating whether `ssh2.sftp_handle.SFTPHandle.close`
1515
was called on a `SFTPHandle` or not.
1616
* Added `ssh2.channel.Channel.signal` function for sending signals over SSH to an open channel - #221
17+
* Added `ssh2.session.Session.direct_streamlocal_ex` for creating `Channel` objects tunneling a local UNIX socket
18+
via the remote host to a third party.
1719

1820

1921
1.1.2

ci/integration_tests/test_session.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,3 +340,21 @@ def test_non_blocking_multi_chan(self):
340340
def test_userauth_kb_with_callback(self):
341341
my_cb = MagicMock()
342342
self.assertRaises(AuthenticationError, self.session.userauth_keyboardinteractive_callback, self.user, my_cb)
343+
344+
def test_direct_streamlocal(self):
345+
unix_sock_path = '/tmp/my_sock'
346+
try:
347+
os.unlink(unix_sock_path)
348+
except OSError:
349+
pass
350+
unix_sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
351+
unix_sock.bind(unix_sock_path)
352+
try:
353+
unix_sock.listen(1)
354+
self.assertEqual(self._auth(), 0)
355+
chan = self.session.direct_streamlocal_ex(unix_sock_path, '127.0.0.1', 12345)
356+
self.assertTrue(chan is not None)
357+
self.assertIsInstance(chan, Channel)
358+
finally:
359+
unix_sock.close()
360+
os.unlink(unix_sock_path)

ssh2/c_ssh2.pxd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ cdef extern from "libssh2.h" nogil:
221221
LIBSSH2_CHANNEL *libssh2_channel_direct_tcpip(
222222
LIBSSH2_SESSION *session, const char *host,
223223
int port)
224+
LIBSSH2_CHANNEL *libssh2_channel_direct_streamlocal_ex(
225+
LIBSSH2_SESSION * session, const char *socket_path,
226+
const char *shost, int sport)
224227
LIBSSH2_LISTENER *libssh2_channel_forward_listen_ex(
225228
LIBSSH2_SESSION *session, const char *host,
226229
int port, int *bound_port, int queue_maxsize)

0 commit comments

Comments
 (0)