This patch adds a glue layer to enable using libssh2 code with the network client code. As in the original client implementation, shell code is sent to the server to detect correct options for netcat. *src/rpc/virnetclient.c: *src/rpc/virnetclient.h: Add function to handle connection to a libvirt daemon using the libssh2 transport. --- src/rpc/virnetclient.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++ src/rpc/virnetclient.h | 11 ++++++++ 2 files changed, 77 insertions(+), 0 deletions(-) diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c index 4b7d4a9..078bec3 100644 --- a/src/rpc/virnetclient.c +++ b/src/rpc/virnetclient.c @@ -216,6 +216,72 @@ virNetClientPtr virNetClientNewSSH(const char *nodename, return virNetClientNew(sock, NULL); } +virNetClientPtr virNetClientNewLibSSH(const char *host, + const char *port, + const char *username, + const char *password, + const char *netcat, + const char *socketPath, + const char *knownHostsFile, + const char *hostkeyVerify, + const char *privkey, + virConnectAuthPtr auth) +{ + virNetSocketPtr sock; + virBuffer buf = VIR_BUFFER_INITIALIZER; + char *nc = NULL; + + if (!host) + host = "localhost"; + + if (!port) + port = "22"; + + if (!username) + username = "root"; + + if (netcat) { + virBufferEscapeShell(&buf, netcat); + nc = virBufferContentAndReset(&buf); + } else { + nc = strdup("nc"); + } + + if (!nc) { + virReportOOMError(); + return NULL; + } + + virBufferAsprintf(&buf, + "sh -c " + "'if '%s' -q 2>&1 | grep \"requires an argument\" >/dev/null 2>&1; then " + "ARG=-q0;" + "else " + "ARG=;" + "fi;" + "'%s' $ARG -U %s'", + nc, nc, socketPath); + + VIR_FREE(nc); + + if (virBufferError(&buf)) { + virReportOOMError(); + return NULL; + } + + nc = virBufferContentAndReset(&buf); + + if (virNetSocketNewConnectLibSSH(host, port, username, password, nc, + knownHostsFile, hostkeyVerify, + privkey, auth, &sock) < 0) { + VIR_FREE(nc); + return NULL; + } + + VIR_FREE(nc); + return virNetClientNew(sock, NULL); +} + virNetClientPtr virNetClientNewExternal(const char **cmdargv) { virNetSocketPtr sock; diff --git a/src/rpc/virnetclient.h b/src/rpc/virnetclient.h index fb679e8..4b494a1 100644 --- a/src/rpc/virnetclient.h +++ b/src/rpc/virnetclient.h @@ -49,6 +49,17 @@ virNetClientPtr virNetClientNewSSH(const char *nodename, const char *keyfile, const char *path); +virNetClientPtr virNetClientNewLibSSH(const char *host, + const char *port, + const char *username, + const char *password, + const char *netcat, + const char *socketPath, + const char *knownHostsFile, + const char *hostkeyVerify, + const char *privkey, + virConnectAuthPtr auth); + virNetClientPtr virNetClientNewExternal(const char **cmdargv); void virNetClientRef(virNetClientPtr client); -- 1.7.3.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list