提交 45c4a70c 编写于 作者: P Pino Toscano 提交者: Peter Krempa

remote: fix logic for known_hosts and keyfile checks

If any of them is specified for the libssh and libssh2 drivers, there is
no need to depend on checks based on other paths: in particular, a
specified path for known_hosts was ignored if the local config directory
could not be determined, and the path for keyfile was ignored if the
home could not be determined.

Instead, lazily determine and use these two paths only in case they are
needed.
上级 408a1ce5
...@@ -450,32 +450,34 @@ virNetClientPtr virNetClientNewLibSSH2(const char *host, ...@@ -450,32 +450,34 @@ virNetClientPtr virNetClientNewLibSSH2(const char *host,
char *nc = NULL; char *nc = NULL;
char *command = NULL; char *command = NULL;
char *homedir = virGetUserDirectory(); char *homedir = NULL;
char *confdir = virGetUserConfigDirectory(); char *confdir = NULL;
char *knownhosts = NULL; char *knownhosts = NULL;
char *privkey = NULL; char *privkey = NULL;
/* Use default paths for known hosts an public keys if not provided */ /* Use default paths for known hosts an public keys if not provided */
if (knownHostsPath) {
if (VIR_STRDUP(knownhosts, knownHostsPath) < 0)
goto cleanup;
} else {
confdir = virGetUserConfigDirectory();
if (confdir) { if (confdir) {
if (!knownHostsPath) {
if (virFileExists(confdir)) { if (virFileExists(confdir)) {
virBufferAsprintf(&buf, "%s/known_hosts", confdir); virBufferAsprintf(&buf, "%s/known_hosts", confdir);
if (!(knownhosts = virBufferContentAndReset(&buf))) if (!(knownhosts = virBufferContentAndReset(&buf)))
goto no_memory; goto no_memory;
} }
} else {
if (VIR_STRDUP(knownhosts, knownHostsPath) < 0)
goto cleanup;
} }
} }
if (privkeyPath) {
if (VIR_STRDUP(privkey, privkeyPath) < 0)
goto cleanup;
} else {
homedir = virGetUserDirectory();
if (homedir) { if (homedir) {
if (!privkeyPath) {
if (virNetClientFindDefaultSshKey(homedir, &privkey) < 0) if (virNetClientFindDefaultSshKey(homedir, &privkey) < 0)
goto no_memory; goto no_memory;
} else {
if (VIR_STRDUP(privkey, privkeyPath) < 0)
goto cleanup;
} }
} }
...@@ -559,31 +561,33 @@ virNetClientPtr virNetClientNewLibssh(const char *host, ...@@ -559,31 +561,33 @@ virNetClientPtr virNetClientNewLibssh(const char *host,
char *nc = NULL; char *nc = NULL;
char *command = NULL; char *command = NULL;
char *homedir = virGetUserDirectory(); char *homedir = NULL;
char *confdir = virGetUserConfigDirectory(); char *confdir = NULL;
char *knownhosts = NULL; char *knownhosts = NULL;
char *privkey = NULL; char *privkey = NULL;
/* Use default paths for known hosts an public keys if not provided */ /* Use default paths for known hosts an public keys if not provided */
if (knownHostsPath) {
if (VIR_STRDUP(knownhosts, knownHostsPath) < 0)
goto cleanup;
} else {
confdir = virGetUserConfigDirectory();
if (confdir) { if (confdir) {
if (!knownHostsPath) {
if (virFileExists(confdir)) { if (virFileExists(confdir)) {
if (virAsprintf(&knownhosts, "%s/known_hosts", confdir) < 0) if (virAsprintf(&knownhosts, "%s/known_hosts", confdir) < 0)
goto cleanup; goto cleanup;
} }
} else {
if (VIR_STRDUP(knownhosts, knownHostsPath) < 0)
goto cleanup;
} }
} }
if (privkeyPath) {
if (VIR_STRDUP(privkey, privkeyPath) < 0)
goto cleanup;
} else {
homedir = virGetUserDirectory();
if (homedir) { if (homedir) {
if (!privkeyPath) {
if (virNetClientFindDefaultSshKey(homedir, &privkey) < 0) if (virNetClientFindDefaultSshKey(homedir, &privkey) < 0)
goto no_memory; goto no_memory;
} else {
if (VIR_STRDUP(privkey, privkeyPath) < 0)
goto cleanup;
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册