Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow processing of a specific configuration file for the connection #479

Open
wants to merge 5 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog-fragments/479.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Implemented reading connection details from a config file -- by :user:`donnerhacke`.
1 change: 1 addition & 0 deletions src/pylibsshext/includes/libssh.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions src/pylibsshext/session.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new key needs to be documented in the doc text above with the description of how the corner cases are handled.

The libssh itself reads the OpenSSH configuration files by default and the openssh configuration files have awkward precedence, so this documentation needs to clarify if this configuration file is parsed before the openssh ones, after them and if the same option is specified in both config and direct option, which one is effective.

@donnerhacke Please, let me know if you plan to get back to make this working or you abandoned this PR in favor of different solution (such as using the OpenSSH config directly).

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the disconnect here is not needed as we did not connect yet.

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())
Expand Down
Loading