提交 408a1ce5 编写于 作者: P Pino Toscano 提交者: Peter Krempa

rpc: libssh: allow a NULL known_hosts file

Make sure that virNetLibsshSessionSetHostKeyVerification accepts a NULL
value for the path to the known_hosts file:
- call ssh_options_set(SSH_OPTIONS_KNOWNHOSTS) anyway, using /dev/null,
  otherwise libssh will use its default path
- do not call ssh_write_knownhost when no known hosts file was set

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1406457
上级 97dbf2b6
...@@ -382,14 +382,16 @@ virNetLibsshCheckHostKey(virNetLibsshSessionPtr sess) ...@@ -382,14 +382,16 @@ virNetLibsshCheckHostKey(virNetLibsshSessionPtr sess)
VIR_FREE(askKey.result); VIR_FREE(askKey.result);
} }
/* write the host key file */ /* write the host key file, if specified */
if (ssh_write_knownhost(sess->session) < 0) { if (sess->knownHostsFile) {
errmsg = ssh_get_error(sess->session); if (ssh_write_knownhost(sess->session) < 0) {
virReportError(VIR_ERR_LIBSSH, errmsg = ssh_get_error(sess->session);
_("failed to write known_host file '%s': %s"), virReportError(VIR_ERR_LIBSSH,
sess->knownHostsFile, _("failed to write known_host file '%s': %s"),
errmsg); sess->knownHostsFile,
return -1; errmsg);
return -1;
}
} }
/* key was accepted and added */ /* key was accepted and added */
return 0; return 0;
...@@ -1172,13 +1174,20 @@ virNetLibsshSessionSetHostKeyVerification(virNetLibsshSessionPtr sess, ...@@ -1172,13 +1174,20 @@ virNetLibsshSessionSetHostKeyVerification(virNetLibsshSessionPtr sess,
goto error; goto error;
} }
/* set the known hosts file */ /* set the known hosts file, if specified */
if (ssh_options_set(sess->session, SSH_OPTIONS_KNOWNHOSTS, hostsfile) < 0) if (hostsfile) {
goto error; if (ssh_options_set(sess->session, SSH_OPTIONS_KNOWNHOSTS, hostsfile) < 0)
goto error;
VIR_FREE(sess->knownHostsFile); VIR_FREE(sess->knownHostsFile);
if (VIR_STRDUP(sess->knownHostsFile, hostsfile) < 0) if (VIR_STRDUP(sess->knownHostsFile, hostsfile) < 0)
goto error; goto error;
} else {
/* libssh does not support trying no known_host file at all:
* hence use /dev/null here, without storing it as file */
if (ssh_options_set(sess->session, SSH_OPTIONS_KNOWNHOSTS, "/dev/null") < 0)
goto error;
}
virObjectUnlock(sess); virObjectUnlock(sess);
return 0; return 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册