Skip to content

Commit 852bfbc

Browse files
author
lutz
committed
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.
1 parent 2a4091c commit 852bfbc

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/pylibsshext/includes/libssh.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ cdef extern from "libssh/libssh.h" nogil:
163163
int ssh_options_get(ssh_session session, ssh_options_e type, char **value)
164164
int ssh_options_get_port(ssh_session session, unsigned int * port_target)
165165
int ssh_options_set(ssh_session session, ssh_options_e type, const void *value)
166+
int ssh_options_parse_config(ssh_session session, const char *filename)
166167

167168
int ssh_get_server_publickey(ssh_session session, ssh_key *key)
168169
void ssh_key_free(ssh_key key)

src/pylibsshext/session.pyx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,16 @@ cdef class Session(object):
241241
if (key in OPTS_MAP or key in OPTS_DIR_MAP) and (kwargs[key] is not None):
242242
self.set_ssh_options(key, kwargs[key])
243243

244+
if 'config_file' in kwargs:
245+
file_name = kwargs['config_file']
246+
rc = libssh.ssh_options_parse_config(self._libssh_session, file_name.encode())
247+
if rc != libssh.SSH_OK or self._get_session_error_str() != "":
248+
libssh.ssh_disconnect(self._libssh_session)
249+
raise LibsshSessionException(
250+
"parsing ssh config failed: %s: %s" %
251+
(file_name, self._get_session_error_str())
252+
)
253+
244254
if libssh.ssh_connect(self._libssh_session) != libssh.SSH_OK:
245255
libssh.ssh_disconnect(self._libssh_session)
246256
raise LibsshSessionException("ssh connect failed: %s" % self._get_session_error_str())

0 commit comments

Comments
 (0)