From d305e8691e15b7eeffdc6099911cb3ea973c4696 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Thu, 2 May 2013 11:05:55 +0100 Subject: [PATCH] Convert Xen domain autostart driver methods to use virDomainDefPtr Introduce use of a virDomainDefPtr in the domain autostart APIs to simplify introduction of ACL security checks. The virDomainPtr cannot be safely used, since the app may have supplied mis-matching name/uuid/id fields. eg the name points to domain X, while the uuid points to domain Y. Resolving the virDomainPtr to a virDomainDefPtr ensures a consistent name/uuid/id set. Signed-off-by: Daniel P. Berrange --- src/xen/xen_driver.c | 26 ++++++++++++++++++++++---- src/xen/xend_internal.c | 14 +++++++++----- src/xen/xend_internal.h | 10 ++++++---- src/xen/xm_internal.c | 22 ++++++++++++---------- src/xen/xm_internal.h | 6 ++++-- 5 files changed, 53 insertions(+), 25 deletions(-) diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c index a7e02523e5..b1d57fd183 100644 --- a/src/xen/xen_driver.c +++ b/src/xen/xen_driver.c @@ -1809,22 +1809,40 @@ static int xenUnifiedDomainGetAutostart(virDomainPtr dom, int *autostart) { xenUnifiedPrivatePtr priv = dom->conn->privateData; + virDomainDefPtr def = NULL; + int ret = -1; + + if (!(def = xenGetDomainDefForDom(dom))) + goto cleanup; if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) - return xenXMDomainGetAutostart(dom, autostart); + ret = xenXMDomainGetAutostart(def, autostart); else - return xenDaemonDomainGetAutostart(dom, autostart); + ret = xenDaemonDomainGetAutostart(dom->conn, def, autostart); + +cleanup: + virDomainDefFree(def); + return ret; } static int xenUnifiedDomainSetAutostart(virDomainPtr dom, int autostart) { xenUnifiedPrivatePtr priv = dom->conn->privateData; + virDomainDefPtr def = NULL; + int ret = -1; + + if (!(def = xenGetDomainDefForDom(dom))) + goto cleanup; if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) - return xenXMDomainSetAutostart(dom, autostart); + ret = xenXMDomainSetAutostart(def, autostart); else - return xenDaemonDomainSetAutostart(dom, autostart); + ret = xenDaemonDomainSetAutostart(dom->conn, def, autostart); + +cleanup: + virDomainDefFree(def); + return ret; } static char * diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c index a654190deb..967350992a 100644 --- a/src/xen/xend_internal.c +++ b/src/xen/xend_internal.c @@ -2562,12 +2562,14 @@ cleanup: } int -xenDaemonDomainGetAutostart(virDomainPtr domain, int *autostart) +xenDaemonDomainGetAutostart(virConnectPtr conn, + virDomainDefPtr def, + int *autostart) { struct sexpr *root; const char *tmp; - root = sexpr_get(domain->conn, "/xend/domain/%s?detail=1", domain->name); + root = sexpr_get(conn, "/xend/domain/%s?detail=1", def->name); if (root == NULL) { virReportError(VIR_ERR_XEN_CALL, "%s", _("xenDaemonGetAutostart failed to find this domain")); @@ -2586,14 +2588,16 @@ xenDaemonDomainGetAutostart(virDomainPtr domain, int *autostart) } int -xenDaemonDomainSetAutostart(virDomainPtr domain, int autostart) +xenDaemonDomainSetAutostart(virConnectPtr conn, + virDomainDefPtr def, + int autostart) { struct sexpr *root, *autonode; virBuffer buffer = VIR_BUFFER_INITIALIZER; char *content = NULL; int ret = -1; - root = sexpr_get(domain->conn, "/xend/domain/%s?detail=1", domain->name); + root = sexpr_get(conn, "/xend/domain/%s?detail=1", def->name); if (root == NULL) { virReportError(VIR_ERR_XEN_CALL, "%s", _("xenDaemonSetAutostart failed to find this domain")); @@ -2632,7 +2636,7 @@ xenDaemonDomainSetAutostart(virDomainPtr domain, int autostart) content = virBufferContentAndReset(&buffer); - if (xend_op(domain->conn, "", "op", "new", "config", content, NULL) != 0) { + if (xend_op(conn, "", "op", "new", "config", content, NULL) != 0) { virReportError(VIR_ERR_XEN_CALL, "%s", _("Failed to redefine sexpr")); goto error; diff --git a/src/xen/xend_internal.h b/src/xen/xend_internal.h index f5b494b5f4..25edc61866 100644 --- a/src/xen/xend_internal.h +++ b/src/xen/xend_internal.h @@ -174,10 +174,12 @@ int xenDaemonUpdateDeviceFlags(virConnectPtr conn, virDomainDefPtr def, const char *xml, unsigned int flags); -int xenDaemonDomainGetAutostart (virDomainPtr dom, - int *autostart); -int xenDaemonDomainSetAutostart (virDomainPtr domain, - int autostart); +int xenDaemonDomainGetAutostart(virConnectPtr conn, + virDomainDefPtr def, + int *autostart); +int xenDaemonDomainSetAutostart(virConnectPtr conn, + virDomainDefPtr def, + int autostart); int xenDaemonCreateXML(virConnectPtr conn, virDomainDefPtr def); virDomainDefPtr xenDaemonLookupByUUID(virConnectPtr conn, const unsigned char *uuid); diff --git a/src/xen/xm_internal.c b/src/xen/xm_internal.c index c9950556be..170b9284e6 100644 --- a/src/xen/xm_internal.c +++ b/src/xen/xm_internal.c @@ -1423,28 +1423,29 @@ xenXMDomainBlockPeek(virDomainPtr dom ATTRIBUTE_UNUSED, static char * -xenXMAutostartLinkName(virDomainPtr dom) +xenXMAutostartLinkName(virDomainDefPtr def) { char *ret; - if (virAsprintf(&ret, "/etc/xen/auto/%s", dom->name) < 0) + if (virAsprintf(&ret, "/etc/xen/auto/%s", def->name) < 0) return NULL; return ret; } static char * -xenXMDomainConfigName(virDomainPtr dom) +xenXMDomainConfigName(virDomainDefPtr def) { char *ret; - if (virAsprintf(&ret, "/etc/xen/%s", dom->name) < 0) + if (virAsprintf(&ret, "/etc/xen/%s", def->name) < 0) return NULL; return ret; } int -xenXMDomainGetAutostart(virDomainPtr dom, int *autostart) +xenXMDomainGetAutostart(virDomainDefPtr def, + int *autostart) { - char *linkname = xenXMAutostartLinkName(dom); - char *config = xenXMDomainConfigName(dom); + char *linkname = xenXMAutostartLinkName(def); + char *config = xenXMDomainConfigName(def); int ret = -1; if (!linkname || !config) { @@ -1470,10 +1471,11 @@ cleanup: int -xenXMDomainSetAutostart(virDomainPtr dom, int autostart) +xenXMDomainSetAutostart(virDomainDefPtr def, + int autostart) { - char *linkname = xenXMAutostartLinkName(dom); - char *config = xenXMDomainConfigName(dom); + char *linkname = xenXMAutostartLinkName(def); + char *config = xenXMDomainConfigName(def); int ret = -1; if (!linkname || !config) { diff --git a/src/xen/xm_internal.h b/src/xen/xm_internal.h index 7d64dc618e..78cd15c8e1 100644 --- a/src/xen/xm_internal.h +++ b/src/xen/xm_internal.h @@ -82,8 +82,10 @@ int xenXMDomainUndefine(virConnectPtr conn, virDomainDefPtr def); int xenXMDomainBlockPeek (virDomainPtr dom, const char *path, unsigned long long offset, size_t size, void *buffer); -int xenXMDomainGetAutostart(virDomainPtr dom, int *autostart); -int xenXMDomainSetAutostart(virDomainPtr dom, int autostart); +int xenXMDomainGetAutostart(virDomainDefPtr def, + int *autostart); +int xenXMDomainSetAutostart(virDomainDefPtr def, + int autostart); int xenXMDomainAttachDeviceFlags(virConnectPtr conn, virDomainDefPtr def, -- GitLab