knownhosts: Check if the hosts file exists
Fixes T135 Reported-by: Jan Pazdziora <jpazdziora@redhat.com> Signed-off-by: Andreas Schneider <asn@cryptomilk.org> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Этот коммит содержится в:
родитель
cc536377f9
Коммит
3e8bdb122f
@ -557,6 +557,7 @@ enum ssh_known_hosts_e ssh_session_has_known_hosts_entry(ssh_session session)
|
||||
struct ssh_list *entry_list = NULL;
|
||||
struct ssh_iterator *it = NULL;
|
||||
char *host_port = NULL;
|
||||
bool ok;
|
||||
int rc;
|
||||
|
||||
if (session->opts.knownhosts == NULL) {
|
||||
@ -569,6 +570,25 @@ enum ssh_known_hosts_e ssh_session_has_known_hosts_entry(ssh_session session)
|
||||
}
|
||||
}
|
||||
|
||||
if (session->opts.knownhosts == NULL &&
|
||||
session->opts.global_knownhosts == NULL) {
|
||||
return SSH_KNOWN_HOSTS_NOT_FOUND;
|
||||
}
|
||||
|
||||
if (session->opts.knownhosts != NULL) {
|
||||
ok = ssh_file_readaccess_ok(session->opts.knownhosts);
|
||||
if (!ok) {
|
||||
return SSH_KNOWN_HOSTS_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
if (session->opts.global_knownhosts != NULL) {
|
||||
ok = ssh_file_readaccess_ok(session->opts.global_knownhosts);
|
||||
if (!ok) {
|
||||
return SSH_KNOWN_HOSTS_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
host_port = ssh_session_get_host_port(session);
|
||||
if (host_port == NULL) {
|
||||
return SSH_KNOWN_HOSTS_ERROR;
|
||||
|
@ -256,6 +256,7 @@ static void torture_knownhosts_read_file(void **state)
|
||||
ssh_list_free(entry_list);
|
||||
}
|
||||
|
||||
#ifndef _WIN32 /* There is no /dev/null on Windows */
|
||||
static void torture_knownhosts_host_exists(void **state)
|
||||
{
|
||||
const char *knownhosts_file = *state;
|
||||
@ -365,6 +366,7 @@ torture_knownhosts_algorithms_global(void **state)
|
||||
|
||||
ssh_free(session);
|
||||
}
|
||||
#endif
|
||||
|
||||
int torture_run_tests(void) {
|
||||
int rc;
|
||||
@ -378,6 +380,7 @@ int torture_run_tests(void) {
|
||||
cmocka_unit_test_setup_teardown(torture_knownhosts_read_file,
|
||||
setup_knownhosts_file,
|
||||
teardown_knownhosts_file),
|
||||
#ifndef _WIN32
|
||||
cmocka_unit_test_setup_teardown(torture_knownhosts_host_exists,
|
||||
setup_knownhosts_file,
|
||||
teardown_knownhosts_file),
|
||||
@ -390,6 +393,7 @@ int torture_run_tests(void) {
|
||||
cmocka_unit_test_setup_teardown(torture_knownhosts_algorithms_global,
|
||||
setup_knownhosts_file,
|
||||
teardown_knownhosts_file),
|
||||
#endif
|
||||
};
|
||||
|
||||
ssh_init();
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user