mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-25 10:03:49 +03:00
remote: extract logic for determining daemon to connect to
We'll shortly want to reuse code for determining whether to connect to the system or session daemon from places outside the remote driver client. Pulling it out into a self contained function facilitates reuse. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
7ce887989a
commit
1ba30bc1e5
@ -1197,7 +1197,8 @@ remoteConnectOpen(virConnectPtr conn,
|
||||
struct private_data *priv;
|
||||
int ret = VIR_DRV_OPEN_ERROR;
|
||||
int rflags = 0;
|
||||
const char *autostart = getenv("LIBVIRT_AUTOSTART");
|
||||
bool user;
|
||||
bool autostart;
|
||||
char *driver = NULL;
|
||||
remoteDriverTransport transport;
|
||||
|
||||
@ -1236,51 +1237,11 @@ remoteConnectOpen(virConnectPtr conn,
|
||||
if (flags & VIR_CONNECT_RO)
|
||||
rflags |= VIR_DRV_OPEN_REMOTE_RO;
|
||||
|
||||
/*
|
||||
* User session daemon is used for
|
||||
*
|
||||
* - Any URI with /session suffix
|
||||
* - Test driver, if a protocol is given
|
||||
*
|
||||
* provided we are running non-root
|
||||
*/
|
||||
if (conn->uri &&
|
||||
conn->uri->path &&
|
||||
conn->uri->scheme &&
|
||||
(STREQ(conn->uri->path, "/session") ||
|
||||
STRPREFIX(conn->uri->scheme, "test+")) &&
|
||||
geteuid() > 0) {
|
||||
VIR_DEBUG("User session daemon required");
|
||||
remoteGetURIDaemonInfo(conn->uri, transport, &user, &autostart);
|
||||
if (user)
|
||||
rflags |= VIR_DRV_OPEN_REMOTE_USER;
|
||||
|
||||
/*
|
||||
* Furthermore if no servername is given,
|
||||
* and the transport is unix,
|
||||
* and uid is unprivileged then auto-spawn a daemon.
|
||||
*/
|
||||
if (!conn->uri->server &&
|
||||
(transport == REMOTE_DRIVER_TRANSPORT_UNIX) &&
|
||||
(!autostart ||
|
||||
STRNEQ(autostart, "0"))) {
|
||||
VIR_DEBUG("Try daemon autostart");
|
||||
rflags |= VIR_DRV_OPEN_REMOTE_AUTOSTART;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If URI is NULL, then do a UNIX connection possibly auto-spawning
|
||||
* unprivileged server and probe remote server for URI.
|
||||
*/
|
||||
if (!conn->uri) {
|
||||
VIR_DEBUG("Auto-probe remote URI");
|
||||
if (geteuid() > 0) {
|
||||
VIR_DEBUG("Auto-spawn user daemon instance");
|
||||
rflags |= VIR_DRV_OPEN_REMOTE_USER;
|
||||
if (!autostart ||
|
||||
STRNEQ(autostart, "0"))
|
||||
rflags |= VIR_DRV_OPEN_REMOTE_AUTOSTART;
|
||||
}
|
||||
}
|
||||
if (autostart)
|
||||
rflags |= VIR_DRV_OPEN_REMOTE_AUTOSTART;
|
||||
|
||||
ret = doRemoteOpen(conn, priv, driver, transport, auth, conf, rflags);
|
||||
if (ret != VIR_DRV_OPEN_SUCCESS) {
|
||||
|
@ -224,3 +224,62 @@ remoteGetUNIXSocket(remoteDriverTransport transport,
|
||||
ro, session);
|
||||
return sock_name;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
remoteGetURIDaemonInfo(virURIPtr uri,
|
||||
remoteDriverTransport transport,
|
||||
bool *session,
|
||||
bool *autostart)
|
||||
{
|
||||
const char *autostart_str = getenv("LIBVIRT_AUTOSTART");
|
||||
|
||||
*session = false;
|
||||
*autostart = false;
|
||||
|
||||
/*
|
||||
* User session daemon is used for
|
||||
*
|
||||
* - Any URI with /session suffix
|
||||
* - Test driver, if a protocol is given
|
||||
*
|
||||
* provided we are running non-root
|
||||
*/
|
||||
if (uri &&
|
||||
uri->path &&
|
||||
uri->scheme &&
|
||||
(STREQ(uri->path, "/session") ||
|
||||
STRPREFIX(uri->scheme, "test+")) &&
|
||||
geteuid() > 0) {
|
||||
VIR_DEBUG("User session daemon required");
|
||||
*session = true;
|
||||
|
||||
/*
|
||||
* Furthermore if no servername is given,
|
||||
* and the transport is unix,
|
||||
* and uid is unprivileged then auto-spawn a daemon.
|
||||
*/
|
||||
if (!uri->server &&
|
||||
(transport == REMOTE_DRIVER_TRANSPORT_UNIX) &&
|
||||
(!autostart_str ||
|
||||
STRNEQ(autostart_str, "0"))) {
|
||||
VIR_DEBUG("Try daemon autostart");
|
||||
*autostart = true;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If URI is NULL, then do a UNIX connection possibly auto-spawning
|
||||
* unprivileged server and probe remote server for URI.
|
||||
*/
|
||||
if (!uri) {
|
||||
VIR_DEBUG("Auto-probe remote URI");
|
||||
if (geteuid() > 0) {
|
||||
VIR_DEBUG("Auto-spawn user daemon instance");
|
||||
*session = true;
|
||||
if (!autostart_str ||
|
||||
STRNEQ(autostart_str, "0"))
|
||||
*autostart = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -62,3 +62,9 @@ remoteGetUNIXSocket(remoteDriverTransport transport,
|
||||
bool ro,
|
||||
bool session,
|
||||
char **daemon);
|
||||
|
||||
void
|
||||
remoteGetURIDaemonInfo(virURIPtr uri,
|
||||
remoteDriverTransport transport,
|
||||
bool *session,
|
||||
bool *autostart);
|
||||
|
Loading…
x
Reference in New Issue
Block a user