-
Notifications
You must be signed in to change notification settings - Fork 31
Description
Running the following code snippet raises an exception:
from ssh.session import Session
from ssh import options
HOST = 'localhost'
s = Session()
assert s.options_set(options.HOST, HOST) == 0
assert s.options_parse_config("~/.ssh/config") == 0
print(s.options_get(options.HOST) == 0)$ ssh-python/examples/exec.py
[2024/11/08 09:45:07.728363, 1] ssh_options_get: Invalid argument in ssh_options_get
Traceback (most recent call last):
File "ssh-python/examples/exec.py", line 20, in <module>
print(s.options_get(options.HOST) == 0)
File "ssh/session.pyx", line 341, in ssh.session.Session.options_get
raise OptionError
ssh.exceptions.OptionErrorThe installed version is:
$ pip list | grep ssh-python
ssh-python 1.0.0This should work because HOST option is a string and should therefore be usable as arg.
Tested with: ssh-python version 1.0.0
Analysis
def options_get(self, Option option):
"""Get option value. This function can only be used for string options.
For numeric or other options use the individual functions.
"""
cdef char *_value
cdef char **value = NULL
cdef int rc
cdef bytes b_value
with nogil:
rc = c_ssh.ssh_options_get(
self._session, option._option, value)
if rc < 0:
raise OptionError
_value = value[0]
b_value = _value
c_ssh.ssh_string_free_char(_value)
return to_str(b_value)The exception is therefore thrown because the rc was less than 0.
Testing the underlying c code does not showed any problem. As the following code snippet executes without a problem for libssh found via cmake with libssh version 0.9.6. Where SSH_OK is equal to 0.
char *host_option;
assert(ssh_options_get(session, SSH_OPTIONS_HOST, (char **)&host_option) == SSH_OK);The installed libs are:
$ apt list | grep libssh-
libssh-4/jammy-updates,jammy-security,now 0.9.6-2ubuntu0.22.04.3 amd64 [installed,automatic]
libssh-dev/jammy-updates,jammy-security,now 0.9.6-2ubuntu0.22.04.3 amd64 [installed]
libssh-doc/jammy-updates,jammy-security 0.9.6-2ubuntu0.22.04.3 all
libssh-gcrypt-4/jammy-updates,jammy-security 0.9.6-2ubuntu0.22.04.3 amd64
libssh-gcrypt-dev/jammy-updates,jammy-security 0.9.6-2ubuntu0.22.04.3 amd64looking deeper into the repository in found the definition of ssh_option_get which supports SSH_OPTIONS_HOST as a valid argument.
Also there are unittests for the libssh and especially for ssh_option_get in torture_options_get_host. But all of them are passing:
$ ./build/tests/unittests/torture_options
[==========] Running 24 test(s).
[ RUN ] torture_options_set_host
[ OK ] torture_options_set_host
[ RUN ] torture_options_get_host
[ OK ] torture_options_get_host
[ RUN ] torture_options_set_port
[ OK ] torture_options_set_port
[ RUN ] torture_options_get_port
[ OK ] torture_options_get_port
[ RUN ] torture_options_set_fd
[ OK ] torture_options_set_fd
[ RUN ] torture_options_set_user
[ OK ] torture_options_set_user
[ RUN ] torture_options_get_user
[ OK ] torture_options_get_user
[ RUN ] torture_options_set_identity
[ OK ] torture_options_set_identity
[ RUN ] torture_options_get_identity
[ OK ] torture_options_get_identity
[ RUN ] torture_options_set_global_knownhosts
[ OK ] torture_options_set_global_knownhosts
[ RUN ] torture_options_get_global_knownhosts
[ OK ] torture_options_get_global_knownhosts
[ RUN ] torture_options_set_knownhosts
[ OK ] torture_options_set_knownhosts
[ RUN ] torture_options_get_knownhosts
[ OK ] torture_options_get_knownhosts
[ RUN ] torture_options_proxycommand
[ OK ] torture_options_proxycommand
[ RUN ] torture_options_set_ciphers
[ OK ] torture_options_set_ciphers
[ RUN ] torture_options_set_key_exchange
[ OK ] torture_options_set_key_exchange
[ RUN ] torture_options_set_hostkey
[ OK ] torture_options_set_hostkey
[ RUN ] torture_options_set_pubkey_accepted_types
[ OK ] torture_options_set_pubkey_accepted_types
[ RUN ] torture_options_set_macs
[ OK ] torture_options_set_macs
[ RUN ] torture_options_copy
[ OK ] torture_options_copy
[ RUN ] torture_options_config_host
[ OK ] torture_options_config_host
[ RUN ] torture_options_config_match
[ OK ] torture_options_config_match
[ RUN ] torture_options_config_match_multi
[ OK ] torture_options_config_match_multi
[ RUN ] torture_options_getopt
[ OK ] torture_options_getopt
[==========] 24 test(s) run.
[ PASSED ] 24 test(s).
[==========] Running 17 test(s).
[ RUN ] torture_bind_options_import_key
Changed directory to: temp_dir_6m8feI
[ OK ] torture_bind_options_import_key
[ RUN ] torture_bind_options_hostkey
Changed directory to: temp_dir_zOa06C
[ OK ] torture_bind_options_hostkey
[ RUN ] torture_bind_options_bindaddr
Changed directory to: temp_dir_P9JiyE
[ OK ] torture_bind_options_bindaddr
[ RUN ] torture_bind_options_bindport
Changed directory to: temp_dir_rVKRtu
[ OK ] torture_bind_options_bindport
[ RUN ] torture_bind_options_bindport_str
Changed directory to: temp_dir_LBM3Ng
[ OK ] torture_bind_options_bindport_str
[ RUN ] torture_bind_options_log_verbosity
Changed directory to: temp_dir_KY2Gn4
[ OK ] torture_bind_options_log_verbosity
[ RUN ] torture_bind_options_log_verbosity_str
Changed directory to: temp_dir_3abnsb
[ OK ] torture_bind_options_log_verbosity_str
[ RUN ] torture_bind_options_rsakey
Changed directory to: temp_dir_i4JMEP
[ OK ] torture_bind_options_rsakey
[ RUN ] torture_bind_options_ecdsakey
Changed directory to: temp_dir_vCiinR
[ OK ] torture_bind_options_ecdsakey
[ RUN ] torture_bind_options_banner
Changed directory to: temp_dir_MhjchD
[ OK ] torture_bind_options_banner
[ RUN ] torture_bind_options_set_ciphers
Changed directory to: temp_dir_h8cvKn
[ OK ] torture_bind_options_set_ciphers
[ RUN ] torture_bind_options_set_key_exchange
Changed directory to: temp_dir_NC2lFF
[ OK ] torture_bind_options_set_key_exchange
[ RUN ] torture_bind_options_set_macs
Changed directory to: temp_dir_667NhP
[ OK ] torture_bind_options_set_macs
[ RUN ] torture_bind_options_parse_config
Changed directory to: temp_dir_veocnN
[ OK ] torture_bind_options_parse_config
[ RUN ] torture_bind_options_config_dir
Changed directory to: temp_dir_t03DKj
[ OK ] torture_bind_options_config_dir
[ RUN ] torture_bind_options_set_pubkey_accepted_key_types
Changed directory to: temp_dir_X6HGwg
[ OK ] torture_bind_options_set_pubkey_accepted_key_types
[ RUN ] torture_bind_options_set_hostkey_algorithms
Changed directory to: temp_dir_SmofOs
[ OK ] torture_bind_options_set_hostkey_algorithms
[==========] 17 test(s) run.
[ PASSED ] 17 test(s).Unfortunately, I have no experience with c bindings in python and therefore cannot analyse the problem any further.