support parsing the authz xml element in vnc. Signed-off-by: Zihao Chang <changzihao1@xxxxxxxxxx> --- src/conf/domain_conf.c | 99 ++++++++++++++++++++++++++++++++++++++--- src/conf/domain_conf.h | 7 +++ src/conf/virconftypes.h | 3 ++ 3 files changed, 104 insertions(+), 5 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 540f1706fd23..e303bd76b779 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -12751,9 +12751,9 @@ virDomainTimerDefParseXML(xmlNodePtr node, static int -virDomainGraphicsAuthDefParseXML(xmlNodePtr node, - virDomainGraphicsAuthDefPtr def, - int type) +virDomainGraphicsPasswdDefParseXML(xmlNodePtr node, + virDomainGraphicsAuthDefPtr def, + int type) { g_autofree char *validTo = NULL; g_autofree char *connected = virXMLPropString(node, "connected"); @@ -12819,6 +12819,95 @@ virDomainGraphicsAuthDefParseXML(xmlNodePtr node, } +static int +virDomainGraphicsAuthzDefParseXML(virDomainGraphicsAuthzDefPtr def, + xmlNodePtr node) +{ + int ret = -1; + g_autofree char *type = virXMLPropString(node, "type"); + g_autofree char *id = virXMLPropString(node, "index"); + unsigned int idVal; + int typeVal; + + if (!type || !id) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("graphics authz type and id must be specified")); + goto error; + } + + if ((typeVal = virDomainAuthzTypeTypeFromString(type)) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown graphics authz type '%s'"), type); + goto error; + } + + if ((virStrToLong_uip(id, NULL, 10, &idVal) < 0)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("invalid graphics authz index: %s"), id); + goto error; + } + + def->type = typeVal; + def->index = idVal; + + ret = 0; + error: + return ret; +} + + +static int +virDomainGraphicsAuthzsDefParseXML(xmlNodePtr node, + virDomainGraphicsAuthDefPtr def, + xmlXPathContextPtr ctxt) +{ + VIR_XPATH_NODE_AUTORESTORE(ctxt) + int nAuthzs; + int ret = -1; + g_autofree xmlNodePtr *authzNodes = NULL; + + ctxt->node = node; + + /* parse the <authz> subelements for graphics types that support it */ + nAuthzs = virXPathNodeSet("./authz", ctxt, &authzNodes); + if (nAuthzs < 0) { + goto cleanup; + } + + if (nAuthzs > 0) { + size_t i; + + def->authzs = g_new0(virDomainGraphicsAuthzDef, nAuthzs); + + for (i = 0; i < nAuthzs; i++) { + if (virDomainGraphicsAuthzDefParseXML(&def->authzs[i], + authzNodes[i]) < 0) + goto cleanup; + + def->nAuthzs++; + } + } + + ret = 0; + + cleanup: + return ret; +} + + +static int +virDomainGraphicsAuthDefParseXML(xmlNodePtr node, + virDomainGraphicsAuthDefPtr def, + xmlXPathContextPtr ctxt, + int type) +{ + if (virDomainGraphicsPasswdDefParseXML(node, def, type) || + virDomainGraphicsAuthzsDefParseXML(node, def, ctxt)) + return -1; + return 0; +} + + /** * virDomainGraphicsListenDefParseXML: * @def: listen def pointer to be filled @@ -13126,7 +13215,7 @@ virDomainGraphicsDefParseXMLVNC(virDomainGraphicsDefPtr def, def->data.vnc.keymap = virXMLPropString(node, "keymap"); if (virDomainGraphicsAuthDefParseXML(node, &def->data.vnc.auth, - def->type) < 0) + ctxt, def->type) < 0) return -1; return 0; @@ -13312,7 +13401,7 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, def->data.spice.keymap = virXMLPropString(node, "keymap"); if (virDomainGraphicsAuthDefParseXML(node, &def->data.spice.auth, - def->type) < 0) + ctxt, def->type) < 0) return -1; cur = node->children; diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 01e04250c28b..8cf7440f08aa 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1613,11 +1613,18 @@ typedef enum { VIR_DOMAIN_GRAPHICS_AUTH_CONNECTED_LAST } virDomainGraphicsAuthConnectedType; +struct _virDomainGraphicsAuthzDef { + virDomainAuthzType type; + unsigned long index; +}; + struct _virDomainGraphicsAuthDef { char *passwd; bool expires; /* Whether there is an expiry time set */ time_t validTo; /* seconds since epoch */ int connected; /* action if connected */ + size_t nAuthzs; + virDomainGraphicsAuthzDefPtr authzs; }; typedef enum { diff --git a/src/conf/virconftypes.h b/src/conf/virconftypes.h index 697bd60a04e2..e66f3c5124e7 100644 --- a/src/conf/virconftypes.h +++ b/src/conf/virconftypes.h @@ -162,6 +162,9 @@ typedef virDomainGraphicsDef *virDomainGraphicsDefPtr; typedef struct _virDomainGraphicsListenDef virDomainGraphicsListenDef; typedef virDomainGraphicsListenDef *virDomainGraphicsListenDefPtr; +typedef struct _virDomainGraphicsAuthzDef virDomainGraphicsAuthzDef; +typedef virDomainGraphicsAuthzDef *virDomainGraphicsAuthzDefPtr; + typedef struct _virDomainHostdevCaps virDomainHostdevCaps; typedef virDomainHostdevCaps *virDomainHostdevCapsPtr; -- 2.28.0