From: "Daniel P. Berrange" <berrange(a)redhat.com>
Currently the virGetHostname() API has a bogus virConnectPtr
parameter. This is because virtualization drivers directly
reference this API in their virDriverPtr tables, tieing its
API design to the public virConnectGetHostname API design.
This also causes problems for access control checks since
these must only be done for invocations from the public
API, not internal invocation.
Remove the bogus virConnectPtr parameter, and make each
hypervisor driver provide a dedicated function for the
driver API impl. This will allow access control checks
to be easily inserted later.
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
daemon/libvirtd-config.c | 2 +-
src/check-driverimpls.pl | 1 -
src/libxl/libxl_driver.c | 9 ++++++++-
src/lxc/lxc_driver.c | 9 ++++++++-
src/openvz/openvz_driver.c | 9 ++++++++-
src/parallels/parallels_driver.c | 9 ++++++++-
src/qemu/qemu_driver.c | 9 ++++++++-
src/qemu/qemu_migration.c | 4 ++--
src/test/test_driver.c | 8 +++++++-
src/uml/uml_driver.c | 9 ++++++++-
src/util/virutil.c | 2 +-
src/util/virutil.h | 2 +-
src/vbox/vbox_tmpl.c | 9 ++++++++-
src/xen/xen_driver.c | 9 ++++++++-
src/xen/xend_internal.c | 4 ++--
15 files changed, 78 insertions(+), 17 deletions(-)
diff --git a/daemon/libvirtd-config.c b/daemon/libvirtd-config.c
index 5e3ae21..bebd826 100644
--- a/daemon/libvirtd-config.c
+++ b/daemon/libvirtd-config.c
@@ -290,7 +290,7 @@ daemonConfigNew(bool privileged ATTRIBUTE_UNUSED)
data->keepalive_count = 5;
data->keepalive_required = 0;
- localhost = virGetHostname(NULL);
+ localhost = virGetHostname();
if (localhost == NULL) {
/* we couldn't resolve the hostname; assume that we are
* running in disconnected operation, and report a less
diff --git a/src/check-driverimpls.pl b/src/check-driverimpls.pl
index 2ba4864..52b14e4 100755
--- a/src/check-driverimpls.pl
+++ b/src/check-driverimpls.pl
@@ -44,7 +44,6 @@ while (<>) {
# External impls
next if $prefix eq "node";
- next if $prefix eq "vir";
if (defined $mainprefix) {
if ($mainprefix ne $prefix) {
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 212d0fc..69dd1e4 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -1410,6 +1410,13 @@ libxlConnectGetVersion(virConnectPtr conn, unsigned long *version)
return 0;
}
+
+static char *libxlConnectGetHostname(virConnectPtr conn ATTRIBUTE_UNUSED)
+{
+ return virGetHostname();
+}
+
+
static int
libxlConnectGetMaxVcpus(virConnectPtr conn, const char *type ATTRIBUTE_UNUSED)
{
@@ -4202,7 +4209,7 @@ static virDriver libxlDriver = {
.connectClose = libxlConnectClose, /* 0.9.0 */
.connectGetType = libxlConnectGetType, /* 0.9.0 */
.connectGetVersion = libxlConnectGetVersion, /* 0.9.0 */
- .connectGetHostname = virGetHostname, /* 0.9.0 */
+ .connectGetHostname = libxlConnectGetHostname, /* 0.9.0 */
.connectGetMaxVcpus = libxlConnectGetMaxVcpus, /* 0.9.0 */
.nodeGetInfo = libxlNodeGetInfo, /* 0.9.0 */
.connectGetCapabilities = libxlConnectGetCapabilities, /* 0.9.0 */
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 0becdc7..1475d04 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -1562,6 +1562,13 @@ static int lxcConnectGetVersion(virConnectPtr conn
ATTRIBUTE_UNUSED, unsigned lo
}
+static char *lxcConnectGetHostname(virConnectPtr conn ATTRIBUTE_UNUSED)
+{
+ return virGetHostname();
+}
+
+
+
/*
* check whether the host supports CFS bandwidth
*
@@ -4402,7 +4409,7 @@ static virDriver lxcDriver = {
.connectOpen = lxcConnectOpen, /* 0.4.2 */
.connectClose = lxcConnectClose, /* 0.4.2 */
.connectGetVersion = lxcConnectGetVersion, /* 0.4.6 */
- .connectGetHostname = virGetHostname, /* 0.6.3 */
+ .connectGetHostname = lxcConnectGetHostname, /* 0.6.3 */
.connectGetSysinfo = lxcConnectGetSysinfo, /* 1.0.5 */
.nodeGetInfo = nodeGetInfo, /* 0.6.5 */
.connectGetCapabilities = lxcConnectGetCapabilities, /* 0.6.5 */
diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index f8bec62..9de36f4 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -343,6 +343,13 @@ static int openvzConnectGetVersion(virConnectPtr conn, unsigned long
*version) {
return 0;
}
+
+static char *openvzConnectGetHostname(virConnectPtr conn ATTRIBUTE_UNUSED)
+{
+ return virGetHostname();
+}
+
+
static char *openvzDomainGetOSType(virDomainPtr dom)
{
struct openvz_driver *driver = dom->conn->privateData;
@@ -2182,7 +2189,7 @@ static virDriver openvzDriver = {
.connectClose = openvzConnectClose, /* 0.3.1 */
.connectGetType = openvzConnectGetType, /* 0.3.1 */
.connectGetVersion = openvzConnectGetVersion, /* 0.5.0 */
- .connectGetHostname = virGetHostname, /* 0.9.12 */
+ .connectGetHostname = openvzConnectGetHostname, /* 0.9.12 */
.connectGetMaxVcpus = openvzConnectGetMaxVcpus, /* 0.4.6 */
.nodeGetInfo = nodeGetInfo, /* 0.3.2 */
.nodeGetCPUStats = nodeGetCPUStats, /* 0.9.12 */
diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c
index e126967..f7e953a 100644
--- a/src/parallels/parallels_driver.c
+++ b/src/parallels/parallels_driver.c
@@ -1043,6 +1043,13 @@ cleanup:
return ret;
}
+
+static char *parallelsConnectGetHostname(virConnectPtr conn ATTRIBUTE_UNUSED)
+{
+ return virGetHostname();
+}
+
+
static int
parallelsConnectListDomains(virConnectPtr conn, int *ids, int maxids)
{
@@ -2393,7 +2400,7 @@ static virDriver parallelsDriver = {
.connectOpen = parallelsConnectOpen, /* 0.10.0 */
.connectClose = parallelsConnectClose, /* 0.10.0 */
.connectGetVersion = parallelsConnectGetVersion, /* 0.10.0 */
- .connectGetHostname = virGetHostname, /* 0.10.0 */
+ .connectGetHostname = parallelsConnectGetHostname, /* 0.10.0 */
.nodeGetInfo = nodeGetInfo, /* 0.10.0 */
.connectGetCapabilities = parallelsConnectGetCapabilities, /* 0.10.0 */
.connectListDomains = parallelsConnectListDomains, /* 0.10.0 */
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 9492850..c42e7b7 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1412,6 +1412,13 @@ cleanup:
return ret;
}
+
+static char *qemuConnectGetHostname(virConnectPtr conn ATTRIBUTE_UNUSED)
+{
+ return virGetHostname();
+}
+
+
static int qemuConnectListDomains(virConnectPtr conn, int *ids, int nids) {
virQEMUDriverPtr driver = conn->privateData;
int n;
@@ -14651,7 +14658,7 @@ static virDriver qemuDriver = {
.connectSupportsFeature = qemuConnectSupportsFeature, /* 0.5.0 */
.connectGetType = qemuConnectGetType, /* 0.2.0 */
.connectGetVersion = qemuConnectGetVersion, /* 0.2.0 */
- .connectGetHostname = virGetHostname, /* 0.3.3 */
+ .connectGetHostname = qemuConnectGetHostname, /* 0.3.3 */
.connectGetSysinfo = qemuConnectGetSysinfo, /* 0.8.8 */
.connectGetMaxVcpus = qemuConnectGetMaxVcpus, /* 0.2.1 */
.nodeGetInfo = nodeGetInfo, /* 0.2.0 */
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 6ad1c30..c0b6453 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -405,7 +405,7 @@ qemuMigrationCookieNew(virDomainObjPtr dom)
goto no_memory;
memcpy(mig->uuid, dom->def->uuid, VIR_UUID_BUFLEN);
- if (!(mig->localHostname = virGetHostname(NULL)))
+ if (!(mig->localHostname = virGetHostname()))
goto error;
if (virGetHostUUID(mig->localHostuuid) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -2373,7 +2373,7 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
if (port == QEMUD_MIGRATION_NUM_PORTS) port = 0;
/* Get hostname */
- if ((hostname = virGetHostname(NULL)) == NULL)
+ if ((hostname = virGetHostname()) == NULL)
goto cleanup;
if (STRPREFIX(hostname, "localhost")) {
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index d964fb2..26439e8 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -1223,6 +1223,12 @@ static int testConnectGetVersion(virConnectPtr conn
ATTRIBUTE_UNUSED,
return 0;
}
+static char *testConnectGetHostname(virConnectPtr conn ATTRIBUTE_UNUSED)
+{
+ return virGetHostname();
+}
+
+
static int testConnectIsSecure(virConnectPtr conn ATTRIBUTE_UNUSED)
{
return 1;
@@ -5796,7 +5802,7 @@ static virDriver testDriver = {
.connectOpen = testConnectOpen, /* 0.1.1 */
.connectClose = testConnectClose, /* 0.1.1 */
.connectGetVersion = testConnectGetVersion, /* 0.1.1 */
- .connectGetHostname = virGetHostname, /* 0.6.3 */
+ .connectGetHostname = testConnectGetHostname, /* 0.6.3 */
.connectGetMaxVcpus = testConnectGetMaxVcpus, /* 0.3.2 */
.nodeGetInfo = testNodeGetInfo, /* 0.1.1 */
.connectGetCapabilities = testConnectGetCapabilities, /* 0.2.1 */
diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c
index 9b0aba6..55cf204 100644
--- a/src/uml/uml_driver.c
+++ b/src/uml/uml_driver.c
@@ -1494,6 +1494,13 @@ cleanup:
return ret;
}
+
+static char *umlConnectGetHostname(virConnectPtr conn ATTRIBUTE_UNUSED)
+{
+ return virGetHostname();
+}
+
+
static int umlConnectListDomains(virConnectPtr conn, int *ids, int nids) {
struct uml_driver *driver = conn->privateData;
int n;
@@ -2597,7 +2604,7 @@ static virDriver umlDriver = {
.connectClose = umlConnectClose, /* 0.5.0 */
.connectGetType = umlConnectGetType, /* 0.5.0 */
.connectGetVersion = umlConnectGetVersion, /* 0.5.0 */
- .connectGetHostname = virGetHostname, /* 0.5.0 */
+ .connectGetHostname = umlConnectGetHostname, /* 0.5.0 */
.nodeGetInfo = nodeGetInfo, /* 0.5.0 */
.connectGetCapabilities = umlConnectGetCapabilities, /* 0.5.0 */
.connectListDomains = umlConnectListDomains, /* 0.5.0 */
diff --git a/src/util/virutil.c b/src/util/virutil.c
index b9de33c..879b0b4 100644
--- a/src/util/virutil.c
+++ b/src/util/virutil.c
@@ -2273,7 +2273,7 @@ char *virIndexToDiskName(int idx, const char *prefix)
* we got from getaddrinfo(). Return the value from gethostname()
* and hope for the best.
*/
-char *virGetHostname(virConnectPtr conn ATTRIBUTE_UNUSED)
+char *virGetHostname(void)
{
int r;
char hostname[HOST_NAME_MAX+1], *result;
diff --git a/src/util/virutil.h b/src/util/virutil.h
index 39033db..341c734 100644
--- a/src/util/virutil.h
+++ b/src/util/virutil.h
@@ -260,7 +260,7 @@ static inline int geteuid (void) { return 0; }
static inline int getgid (void) { return 0; }
# endif
-char *virGetHostname(virConnectPtr conn);
+char *virGetHostname(void);
char *virGetUserDirectory(void);
char *virGetUserConfigDirectory(void);
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 315ba9c..6112dd9 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -1089,6 +1089,13 @@ static int vboxConnectGetVersion(virConnectPtr conn, unsigned long
*version) {
return 0;
}
+
+static char *vboxConnectGetHostname(virConnectPtr conn ATTRIBUTE_UNUSED)
+{
+ return virGetHostname();
+}
+
+
static int vboxConnectIsSecure(virConnectPtr conn ATTRIBUTE_UNUSED) {
/* Driver is using local, non-network based transport */
return 1;
@@ -9408,7 +9415,7 @@ virDriver NAME(Driver) = {
.connectOpen = vboxConnectOpen, /* 0.6.3 */
.connectClose = vboxConnectClose, /* 0.6.3 */
.connectGetVersion = vboxConnectGetVersion, /* 0.6.3 */
- .connectGetHostname = virGetHostname, /* 0.6.3 */
+ .connectGetHostname = vboxConnectGetHostname, /* 0.6.3 */
.connectGetMaxVcpus = vboxConnectGetMaxVcpus, /* 0.6.3 */
.nodeGetInfo = nodeGetInfo, /* 0.6.3 */
.connectGetCapabilities = vboxConnectGetCapabilities, /* 0.6.3 */
diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index 0642edb..c6164b6 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
@@ -546,6 +546,13 @@ xenUnifiedConnectGetVersion(virConnectPtr conn, unsigned long
*hvVer)
return -1;
}
+
+static char *xenUnifiedConnectGetHostname(virConnectPtr conn ATTRIBUTE_UNUSED)
+{
+ return virGetHostname();
+}
+
+
static int
xenUnifiedConnectIsEncrypted(virConnectPtr conn ATTRIBUTE_UNUSED)
{
@@ -2353,7 +2360,7 @@ static virDriver xenUnifiedDriver = {
.connectSupportsFeature = xenUnifiedConnectSupportsFeature, /* 0.3.2 */
.connectGetType = xenUnifiedConnectGetType, /* 0.0.3 */
.connectGetVersion = xenUnifiedConnectGetVersion, /* 0.0.3 */
- .connectGetHostname = virGetHostname, /* 0.7.3 */
+ .connectGetHostname = xenUnifiedConnectGetHostname, /* 0.7.3 */
.connectGetMaxVcpus = xenUnifiedConnectGetMaxVcpus, /* 0.2.1 */
.nodeGetInfo = xenUnifiedNodeGetInfo, /* 0.1.0 */
.connectGetCapabilities = xenUnifiedConnectGetCapabilities, /* 0.2.1 */
diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c
index 860bf11..e1f0708 100644
--- a/src/xen/xend_internal.c
+++ b/src/xen/xend_internal.c
@@ -2926,7 +2926,7 @@ xenDaemonDomainSetAutostart(virDomainPtr domain, int autostart)
}
int
-xenDaemonDomainMigratePrepare(virConnectPtr dconn,
+xenDaemonDomainMigratePrepare(virConnectPtr dconn ATTRIBUTE_UNUSED,
char **cookie ATTRIBUTE_UNUSED,
int *cookielen ATTRIBUTE_UNUSED,
const char *uri_in,
@@ -2942,7 +2942,7 @@ xenDaemonDomainMigratePrepare(virConnectPtr dconn,
* deallocates this string.
*/
if (uri_in == NULL) {
- *uri_out = virGetHostname(dconn);
+ *uri_out = virGetHostname();
if (*uri_out == NULL)
return -1;
}
--
1.8.1.4