driver: enforce a non-NULL URI scheme

Now that the legacy Xen driver has been dropped, we no longer need to
support URIs such as "/path/to/xend/socket", and so can mandate that a
URI scheme must always be present.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrangé 2018-04-09 16:33:22 +01:00
parent 4c8574c85c
commit 91dd1b0f02
2 changed files with 40 additions and 47 deletions

View File

@ -905,7 +905,7 @@ virConnectGetDefaultURI(virConfPtr conf,
static int
virConnectCheckURIMissingSlash(const char *uristr, virURIPtr uri)
{
if (!uri->scheme || !uri->path || !uri->server)
if (!uri->path || !uri->server)
return 0;
/* To avoid false positives, only check drivers that mandate
@ -1018,6 +1018,13 @@ virConnectOpenInternal(const char *name,
NULLSTR(ret->uri->user), ret->uri->port,
NULLSTR(ret->uri->path));
if (ret->uri->scheme == NULL) {
virReportError(VIR_ERR_NO_CONNECT,
_("URI '%s' does not include a driver name"),
name);
goto failed;
}
if (virConnectCheckURIMissingSlash(uristr,
ret->uri) < 0) {
goto failed;
@ -1038,7 +1045,7 @@ virConnectOpenInternal(const char *name,
* not being able to connect to libvirtd or not being able to find
* certificates. */
if (STREQ(virConnectDriverTab[i]->hypervisorDriver->name, "remote") &&
ret->uri != NULL && ret->uri->scheme != NULL &&
ret->uri != NULL &&
(
#ifndef WITH_PHYP
STRCASEEQ(ret->uri->scheme, "phyp") ||
@ -1081,10 +1088,6 @@ virConnectOpenInternal(const char *name,
VIR_DEBUG("No URI, skipping driver with URI whitelist");
continue;
}
if (!ret->uri->scheme) {
VIR_DEBUG("No URI scheme, skipping driver with URI whitelist");
continue;
}
VIR_DEBUG("Checking for supported URI schemes");
for (s = 0; virConnectDriverTab[i]->uriSchemes[s] != NULL; s++) {
if (STREQ(ret->uri->scheme, virConnectDriverTab[i]->uriSchemes[s])) {

View File

@ -738,51 +738,41 @@ doRemoteOpen(virConnectPtr conn,
* URIs we don't care about */
if (conn->uri) {
if (!conn->uri->scheme) {
/* This is the ///var/lib/xen/xend-socket local path style */
if (!conn->uri->path)
return VIR_DRV_OPEN_DECLINED;
if (conn->uri->path[0] != '/')
return VIR_DRV_OPEN_DECLINED;
transport_str = get_transport_from_scheme(conn->uri->scheme);
transport = trans_unix;
if (!transport_str) {
if (conn->uri->server)
transport = trans_tls;
else
transport = trans_unix;
} else {
transport_str = get_transport_from_scheme(conn->uri->scheme);
if (!transport_str) {
if (conn->uri->server)
transport = trans_tls;
else
transport = trans_unix;
} else {
if (STRCASEEQ(transport_str, "tls")) {
transport = trans_tls;
} else if (STRCASEEQ(transport_str, "unix")) {
if (conn->uri->server) {
virReportError(VIR_ERR_INVALID_ARG,
_("using unix socket and remote "
"server '%s' is not supported."),
conn->uri->server);
return VIR_DRV_OPEN_ERROR;
} else {
transport = trans_unix;
}
} else if (STRCASEEQ(transport_str, "ssh")) {
transport = trans_ssh;
} else if (STRCASEEQ(transport_str, "libssh2")) {
transport = trans_libssh2;
} else if (STRCASEEQ(transport_str, "ext")) {
transport = trans_ext;
} else if (STRCASEEQ(transport_str, "tcp")) {
transport = trans_tcp;
} else if (STRCASEEQ(transport_str, "libssh")) {
transport = trans_libssh;
} else {
virReportError(VIR_ERR_INVALID_ARG, "%s",
_("remote_open: transport in URL not recognised "
"(should be tls|unix|ssh|ext|tcp|libssh2)"));
if (STRCASEEQ(transport_str, "tls")) {
transport = trans_tls;
} else if (STRCASEEQ(transport_str, "unix")) {
if (conn->uri->server) {
virReportError(VIR_ERR_INVALID_ARG,
_("using unix socket and remote "
"server '%s' is not supported."),
conn->uri->server);
return VIR_DRV_OPEN_ERROR;
} else {
transport = trans_unix;
}
} else if (STRCASEEQ(transport_str, "ssh")) {
transport = trans_ssh;
} else if (STRCASEEQ(transport_str, "libssh2")) {
transport = trans_libssh2;
} else if (STRCASEEQ(transport_str, "ext")) {
transport = trans_ext;
} else if (STRCASEEQ(transport_str, "tcp")) {
transport = trans_tcp;
} else if (STRCASEEQ(transport_str, "libssh")) {
transport = trans_libssh;
} else {
virReportError(VIR_ERR_INVALID_ARG, "%s",
_("remote_open: transport in URL not recognised "
"(should be tls|unix|ssh|ext|tcp|libssh2)"));
return VIR_DRV_OPEN_ERROR;
}
}
} else {