From 392dbc370ab5ff49d157b417161d6ad57d6e540a Mon Sep 17 00:00:00 2001 From: NilashishC Date: Tue, 10 Dec 2024 16:49:08 +0530 Subject: [PATCH 1/4] support requesting a subsystem on a channel Signed-off-by: NilashishC --- src/pylibsshext/channel.pyx | 5 +++++ src/pylibsshext/includes/libssh.pxd | 1 + src/pylibsshext/session.pyx | 5 +++++ 3 files changed, 11 insertions(+) diff --git a/src/pylibsshext/channel.pyx b/src/pylibsshext/channel.pyx index 64f662e30..c446e9569 100644 --- a/src/pylibsshext/channel.pyx +++ b/src/pylibsshext/channel.pyx @@ -92,6 +92,11 @@ cdef class Channel: if rc != libssh.SSH_OK: raise LibsshChannelException("Failed to request_shell: [%d]" % rc) + def request_subsystem(self, subsystem): + rc = libssh.ssh_channel_request_subsystem(self._libssh_channel, subsystem.encode("utf-8")) + if rc != libssh.SSH_OK: + raise LibsshChannelException("Failed to request subsystem: [%d]" % rc) + def poll(self, timeout=-1, stderr=0): if timeout < 0: rc = libssh.ssh_channel_poll(self._libssh_channel, stderr) diff --git a/src/pylibsshext/includes/libssh.pxd b/src/pylibsshext/includes/libssh.pxd index 3219f1cd9..278210150 100644 --- a/src/pylibsshext/includes/libssh.pxd +++ b/src/pylibsshext/includes/libssh.pxd @@ -202,6 +202,7 @@ cdef extern from "libssh/libssh.h" nogil: int ssh_channel_open_session(ssh_channel channel) int ssh_channel_request_pty(ssh_channel channel) int ssh_channel_request_pty_size(ssh_channel channel, const char *term, int cols, int rows) + int ssh_channel_request_subsystem (ssh_channel channel, const char *subsys ) int ssh_channel_request_shell(ssh_channel channel) int ssh_channel_is_open(ssh_channel channel) int ssh_channel_write(ssh_channel channel, const void *data, uint32_t len) diff --git a/src/pylibsshext/session.pyx b/src/pylibsshext/session.pyx index 294827c80..56cd14b84 100644 --- a/src/pylibsshext/session.pyx +++ b/src/pylibsshext/session.pyx @@ -513,6 +513,11 @@ cdef class Session(object): def invoke_shell(self): return self.new_shell_channel() + def invoke_subsystem(self, subsystem): + channel = self.new_channel() + channel.request_subsystem(subsystem) + return channel + def scp(self): return SCP(self) From 024d433eac9251d6295161d33f308c66265ea3f9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 10 Dec 2024 11:24:23 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/pylibsshext/includes/libssh.pxd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pylibsshext/includes/libssh.pxd b/src/pylibsshext/includes/libssh.pxd index 278210150..949aa2e8f 100644 --- a/src/pylibsshext/includes/libssh.pxd +++ b/src/pylibsshext/includes/libssh.pxd @@ -202,7 +202,7 @@ cdef extern from "libssh/libssh.h" nogil: int ssh_channel_open_session(ssh_channel channel) int ssh_channel_request_pty(ssh_channel channel) int ssh_channel_request_pty_size(ssh_channel channel, const char *term, int cols, int rows) - int ssh_channel_request_subsystem (ssh_channel channel, const char *subsys ) + int ssh_channel_request_subsystem (ssh_channel channel, const char *subsys ) int ssh_channel_request_shell(ssh_channel channel) int ssh_channel_is_open(ssh_channel channel) int ssh_channel_write(ssh_channel channel, const void *data, uint32_t len) From f84934b183ab20327012a55c8d9ccd879d673068 Mon Sep 17 00:00:00 2001 From: NilashishC Date: Tue, 10 Dec 2024 17:01:24 +0530 Subject: [PATCH 3/4] slightly better error message Signed-off-by: NilashishC --- docs/changelog-fragments/669.feature.rst | 1 + src/pylibsshext/channel.pyx | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 docs/changelog-fragments/669.feature.rst diff --git a/docs/changelog-fragments/669.feature.rst b/docs/changelog-fragments/669.feature.rst new file mode 100644 index 000000000..fbb9b2487 --- /dev/null +++ b/docs/changelog-fragments/669.feature.rst @@ -0,0 +1 @@ +Support requesting for a subsystem on a channel -- by :user:`NilashishC` diff --git a/src/pylibsshext/channel.pyx b/src/pylibsshext/channel.pyx index c446e9569..d0c122c0b 100644 --- a/src/pylibsshext/channel.pyx +++ b/src/pylibsshext/channel.pyx @@ -95,7 +95,7 @@ cdef class Channel: def request_subsystem(self, subsystem): rc = libssh.ssh_channel_request_subsystem(self._libssh_channel, subsystem.encode("utf-8")) if rc != libssh.SSH_OK: - raise LibsshChannelException("Failed to request subsystem: [%d]" % rc) + raise LibsshChannelException("Failed to request subsystem %s: [%d]" % (subsystem, rc)) def poll(self, timeout=-1, stderr=0): if timeout < 0: From 0b44367ce4cd36aa359ae6a70a92b02e4e8dc9ff Mon Sep 17 00:00:00 2001 From: NilashishC Date: Tue, 10 Dec 2024 17:03:42 +0530 Subject: [PATCH 4/4] fix cython-lint Signed-off-by: NilashishC --- src/pylibsshext/includes/libssh.pxd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pylibsshext/includes/libssh.pxd b/src/pylibsshext/includes/libssh.pxd index 949aa2e8f..34e18d659 100644 --- a/src/pylibsshext/includes/libssh.pxd +++ b/src/pylibsshext/includes/libssh.pxd @@ -202,7 +202,7 @@ cdef extern from "libssh/libssh.h" nogil: int ssh_channel_open_session(ssh_channel channel) int ssh_channel_request_pty(ssh_channel channel) int ssh_channel_request_pty_size(ssh_channel channel, const char *term, int cols, int rows) - int ssh_channel_request_subsystem (ssh_channel channel, const char *subsys ) + int ssh_channel_request_subsystem(ssh_channel channel, const char *subsys) int ssh_channel_request_shell(ssh_channel channel) int ssh_channel_is_open(ssh_channel channel) int ssh_channel_write(ssh_channel channel, const void *data, uint32_t len)