mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
remote: Convert SSH tunnel to virCommand
This commit is contained in:
parent
b3ecd78064
commit
028c30885e
@ -426,8 +426,8 @@ doRemoteOpen (virConnectPtr conn,
|
|||||||
char *name = NULL, *command = NULL, *sockname = NULL, *netcat = NULL;
|
char *name = NULL, *command = NULL, *sockname = NULL, *netcat = NULL;
|
||||||
char *port = NULL, *authtype = NULL, *username = NULL;
|
char *port = NULL, *authtype = NULL, *username = NULL;
|
||||||
int no_verify = 0, no_tty = 0;
|
int no_verify = 0, no_tty = 0;
|
||||||
char **cmd_argv = NULL;
|
|
||||||
char *pkipath = NULL;
|
char *pkipath = NULL;
|
||||||
|
virCommandPtr cmd = NULL;
|
||||||
|
|
||||||
/* Return code from this function, and the private data. */
|
/* Return code from this function, and the private data. */
|
||||||
int retcode = VIR_DRV_OPEN_ERROR;
|
int retcode = VIR_DRV_OPEN_ERROR;
|
||||||
@ -741,50 +741,26 @@ doRemoteOpen (virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
case trans_ssh: {
|
case trans_ssh: {
|
||||||
int j, nr_args = 6;
|
cmd = virCommandNew(command ? command : "ssh");
|
||||||
|
|
||||||
if (username) nr_args += 2; /* For -l username */
|
|
||||||
if (no_tty) nr_args += 5; /* For -T -o BatchMode=yes -e none */
|
|
||||||
if (port) nr_args += 2; /* For -p port */
|
|
||||||
|
|
||||||
command = command ? command : strdup ("ssh");
|
|
||||||
if (command == NULL)
|
|
||||||
goto out_of_memory;
|
|
||||||
|
|
||||||
/* Generate the final command argv[] array.
|
/* Generate the final command argv[] array.
|
||||||
* ssh [-p $port] [-l $username] $hostname $netcat -U $sockname [NULL] */
|
* ssh [-p $port] [-l $username] $hostname $netcat -U $sockname */
|
||||||
if (VIR_ALLOC_N(cmd_argv, nr_args) < 0)
|
|
||||||
goto out_of_memory;
|
|
||||||
|
|
||||||
j = 0;
|
|
||||||
cmd_argv[j++] = strdup (command);
|
|
||||||
if (port) {
|
if (port) {
|
||||||
cmd_argv[j++] = strdup ("-p");
|
virCommandAddArgList(cmd, "-p", port, NULL);
|
||||||
cmd_argv[j++] = strdup (port);
|
|
||||||
}
|
}
|
||||||
if (username) {
|
if (username) {
|
||||||
cmd_argv[j++] = strdup ("-l");
|
virCommandAddArgList(cmd, "-l", username, NULL);
|
||||||
cmd_argv[j++] = strdup (username);
|
|
||||||
}
|
}
|
||||||
if (no_tty) {
|
if (no_tty) {
|
||||||
cmd_argv[j++] = strdup ("-T");
|
virCommandAddArgList(cmd, "-T", "-o", "BatchMode=yes", "-e",
|
||||||
cmd_argv[j++] = strdup ("-o");
|
"none", NULL);
|
||||||
cmd_argv[j++] = strdup ("BatchMode=yes");
|
|
||||||
cmd_argv[j++] = strdup ("-e");
|
|
||||||
cmd_argv[j++] = strdup ("none");
|
|
||||||
}
|
}
|
||||||
cmd_argv[j++] = strdup (priv->hostname);
|
virCommandAddArgList(cmd, priv->hostname, netcat ? netcat : "nc",
|
||||||
cmd_argv[j++] = strdup (netcat ? netcat : "nc");
|
"-U", (sockname ? sockname :
|
||||||
cmd_argv[j++] = strdup ("-U");
|
|
||||||
cmd_argv[j++] = strdup (sockname ? sockname :
|
|
||||||
(flags & VIR_CONNECT_RO
|
(flags & VIR_CONNECT_RO
|
||||||
? LIBVIRTD_PRIV_UNIX_SOCKET_RO
|
? LIBVIRTD_PRIV_UNIX_SOCKET_RO
|
||||||
: LIBVIRTD_PRIV_UNIX_SOCKET));
|
: LIBVIRTD_PRIV_UNIX_SOCKET)), NULL);
|
||||||
cmd_argv[j++] = 0;
|
|
||||||
assert (j == nr_args);
|
|
||||||
for (j = 0; j < (nr_args-1); j++)
|
|
||||||
if (cmd_argv[j] == NULL)
|
|
||||||
goto out_of_memory;
|
|
||||||
|
|
||||||
priv->is_secure = 1;
|
priv->is_secure = 1;
|
||||||
}
|
}
|
||||||
@ -811,9 +787,11 @@ doRemoteOpen (virConnectPtr conn,
|
|||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virExec((const char**)cmd_argv, NULL, NULL,
|
virCommandSetInputFD(cmd, sv[1]);
|
||||||
&pid, sv[1], &(sv[1]), &(errfd[1]),
|
virCommandSetOutputFD(cmd, &(sv[1]));
|
||||||
VIR_EXEC_CLEAR_CAPS) < 0)
|
virCommandSetErrorFD(cmd, &(errfd[1]));
|
||||||
|
virCommandClearCaps(cmd);
|
||||||
|
if (virCommandRunAsync(cmd, &pid) < 0)
|
||||||
goto failed;
|
goto failed;
|
||||||
|
|
||||||
/* Parent continues here. */
|
/* Parent continues here. */
|
||||||
@ -942,14 +920,7 @@ doRemoteOpen (virConnectPtr conn,
|
|||||||
VIR_FREE(netcat);
|
VIR_FREE(netcat);
|
||||||
VIR_FREE(username);
|
VIR_FREE(username);
|
||||||
VIR_FREE(port);
|
VIR_FREE(port);
|
||||||
if (cmd_argv) {
|
virCommandFree(cmd);
|
||||||
char **cmd_argv_ptr = cmd_argv;
|
|
||||||
while (*cmd_argv_ptr) {
|
|
||||||
VIR_FREE(*cmd_argv_ptr);
|
|
||||||
cmd_argv_ptr++;
|
|
||||||
}
|
|
||||||
VIR_FREE(cmd_argv);
|
|
||||||
}
|
|
||||||
VIR_FREE(pkipath);
|
VIR_FREE(pkipath);
|
||||||
|
|
||||||
return retcode;
|
return retcode;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user