From a23de8844fae544e76edae53f130ca26e93a2d43 Mon Sep 17 00:00:00 2001 From: lutz Date: Wed, 4 Jan 2023 16:36:41 +0100 Subject: [PATCH 1/5] Allow processing of a specific configuration file for the connection Depending on the destination, libssh might need to be configured in a way, that the algorithms and methods need to be adjusted. Instead of adding each possible configuration option into the wrapper, including a config file (as it exists for ordinary OpenSSH) is much easier. This allows ansible to connect to devices with less well supported algorithms. --- src/pylibsshext/includes/libssh.pxd | 1 + src/pylibsshext/session.pyx | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/src/pylibsshext/includes/libssh.pxd b/src/pylibsshext/includes/libssh.pxd index 8862220d5..bf90aed0c 100644 --- a/src/pylibsshext/includes/libssh.pxd +++ b/src/pylibsshext/includes/libssh.pxd @@ -163,6 +163,7 @@ cdef extern from "libssh/libssh.h" nogil: int ssh_options_get(ssh_session session, ssh_options_e type, char **value) int ssh_options_get_port(ssh_session session, unsigned int * port_target) int ssh_options_set(ssh_session session, ssh_options_e type, const void *value) + int ssh_options_parse_config(ssh_session session, const char *filename) int ssh_get_server_publickey(ssh_session session, ssh_key *key) void ssh_key_free(ssh_key key) diff --git a/src/pylibsshext/session.pyx b/src/pylibsshext/session.pyx index 294827c80..77f899a18 100644 --- a/src/pylibsshext/session.pyx +++ b/src/pylibsshext/session.pyx @@ -243,6 +243,16 @@ cdef class Session(object): if (key in OPTS_MAP or key in OPTS_DIR_MAP) and (kwargs[key] is not None): self.set_ssh_options(key, kwargs[key]) + if 'config_file' in kwargs: + file_name = kwargs['config_file'] + rc = libssh.ssh_options_parse_config(self._libssh_session, file_name.encode()) + if rc != libssh.SSH_OK or self._get_session_error_str() != "": + libssh.ssh_disconnect(self._libssh_session) + raise LibsshSessionException( + "parsing ssh config failed: %s: %s" % + (file_name, self._get_session_error_str()) + ) + if libssh.ssh_connect(self._libssh_session) != libssh.SSH_OK: libssh.ssh_disconnect(self._libssh_session) raise LibsshSessionException("ssh connect failed: %s" % self._get_session_error_str()) From acb2128d43a71cb0368416485e9720c275da4379 Mon Sep 17 00:00:00 2001 From: lutz Date: Wed, 4 Jan 2023 17:12:19 +0100 Subject: [PATCH 2/5] Provide changelog-fragment --- docs/changelog-fragments/479.feature.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/changelog-fragments/479.feature.rst diff --git a/docs/changelog-fragments/479.feature.rst b/docs/changelog-fragments/479.feature.rst new file mode 100644 index 000000000..72d60717f --- /dev/null +++ b/docs/changelog-fragments/479.feature.rst @@ -0,0 +1 @@ +- Allowed processing of a specific configuration file for the connection -- by :user:`donnerhacke` \ No newline at end of file From e1903f8623143b9e04a0620e37cdf80cf2685108 Mon Sep 17 00:00:00 2001 From: lutz Date: Wed, 4 Jan 2023 20:58:40 +0100 Subject: [PATCH 3/5] Fix unintended indentation --- docs/changelog-fragments/479.feature.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog-fragments/479.feature.rst b/docs/changelog-fragments/479.feature.rst index 72d60717f..e803a0f44 100644 --- a/docs/changelog-fragments/479.feature.rst +++ b/docs/changelog-fragments/479.feature.rst @@ -1 +1 @@ -- Allowed processing of a specific configuration file for the connection -- by :user:`donnerhacke` \ No newline at end of file +Allowed processing of a specific configuration file for the connection -- by :user:`donnerhacke` \ No newline at end of file From cb43fb21df47fe6b07903a513cb2c35fa97149d4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 4 Jan 2023 19:59:25 +0000 Subject: [PATCH 4/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/changelog-fragments/479.feature.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog-fragments/479.feature.rst b/docs/changelog-fragments/479.feature.rst index e803a0f44..e2b531577 100644 --- a/docs/changelog-fragments/479.feature.rst +++ b/docs/changelog-fragments/479.feature.rst @@ -1 +1 @@ -Allowed processing of a specific configuration file for the connection -- by :user:`donnerhacke` \ No newline at end of file +Allowed processing of a specific configuration file for the connection -- by :user:`donnerhacke` From f3daeea40af82eb7ea0c251e48ab09c56f834928 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sviatoslav=20Sydorenko=20=28=D0=A1=D0=B2=D1=8F=D1=82=D0=BE?= =?UTF-8?q?=D1=81=D0=BB=D0=B0=D0=B2=20=D0=A1=D0=B8=D0=B4=D0=BE=D1=80=D0=B5?= =?UTF-8?q?=D0=BD=D0=BA=D0=BE=29?= Date: Thu, 18 Jan 2024 15:34:22 +0100 Subject: [PATCH 5/5] Make the change note style more clear --- docs/changelog-fragments/479.feature.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog-fragments/479.feature.rst b/docs/changelog-fragments/479.feature.rst index e2b531577..41a315471 100644 --- a/docs/changelog-fragments/479.feature.rst +++ b/docs/changelog-fragments/479.feature.rst @@ -1 +1 @@ -Allowed processing of a specific configuration file for the connection -- by :user:`donnerhacke` +Implemented reading connection details from a config file -- by :user:`donnerhacke`.