From 392dbc370ab5ff49d157b417161d6ad57d6e540a Mon Sep 17 00:00:00 2001 From: NilashishC Date: Tue, 10 Dec 2024 16:49:08 +0530 Subject: [PATCH] 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)