mirror of
https://github.com/libvirt/libvirt.git
synced 2026-10-02 12:20:06 -05:00
util: Move and rename virStorageAuthDefParseSecret
Move to virsecret.c and rename to virSecretLookupParseSecret. Also convert to usage xmlNodePtr and virXMLPropString rather than virXPathString. Signed-off-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
1 parent
1eca5f6581
commit
ecd45ced0e
5 files changed
+67
-55
No files matched your search
@@ -233,6 +233,7 @@ src/util/virqemu.c
|
|||||||
src/util/virrandom.c
|
src/util/virrandom.c
|
||||||
src/util/virrotatingfile.c
|
src/util/virrotatingfile.c
|
||||||
src/util/virscsi.c
|
src/util/virscsi.c
|
||||||
|
src/util/virsecret.c
|
||||||
src/util/virsexpr.c
|
src/util/virsexpr.c
|
||||||
src/util/virsocketaddr.c
|
src/util/virsocketaddr.c
|
||||||
src/util/virstats.c
|
src/util/virstats.c
|
||||||
|
|||||||
@@ -2221,6 +2221,7 @@ virSecurityLabelDefNew;
|
|||||||
# util/virsecret.h
|
# util/virsecret.h
|
||||||
virSecretLookupDefClear;
|
virSecretLookupDefClear;
|
||||||
virSecretLookupDefCopy;
|
virSecretLookupDefCopy;
|
||||||
|
virSecretLookupParseSecret;
|
||||||
|
|
||||||
|
|
||||||
# util/virsexpr.h
|
# util/virsexpr.h
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
#include "virlog.h"
|
#include "virlog.h"
|
||||||
#include "virsecret.h"
|
#include "virsecret.h"
|
||||||
#include "virstring.h"
|
#include "virstring.h"
|
||||||
|
#include "viruuid.h"
|
||||||
|
|
||||||
#define VIR_FROM_THIS VIR_FROM_NONE
|
#define VIR_FROM_THIS VIR_FROM_NONE
|
||||||
|
|
||||||
@@ -55,3 +56,46 @@ virSecretLookupDefCopy(virSecretLookupTypeDefPtr dst,
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
virSecretLookupParseSecret(xmlNodePtr secretnode,
|
||||||
|
virSecretLookupTypeDefPtr def)
|
||||||
|
{
|
||||||
|
char *uuid;
|
||||||
|
char *usage;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
uuid = virXMLPropString(secretnode, "uuid");
|
||||||
|
usage = virXMLPropString(secretnode, "usage");
|
||||||
|
if (uuid == NULL && usage == NULL) {
|
||||||
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||||
|
_("missing secret uuid or usage attribute"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (uuid && usage) {
|
||||||
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||||
|
_("either secret uuid or usage expected"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (uuid) {
|
||||||
|
if (virUUIDParse(uuid, def->u.uuid) < 0) {
|
||||||
|
virReportError(VIR_ERR_XML_ERROR,
|
||||||
|
_("invalid secret uuid '%s'"), uuid);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
def->type = VIR_SECRET_LOOKUP_TYPE_UUID;
|
||||||
|
} else {
|
||||||
|
def->u.usage = usage;
|
||||||
|
usage = NULL;
|
||||||
|
def->type = VIR_SECRET_LOOKUP_TYPE_USAGE;
|
||||||
|
}
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
VIR_FREE(uuid);
|
||||||
|
VIR_FREE(usage);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
@@ -24,6 +24,8 @@
|
|||||||
|
|
||||||
# include "internal.h"
|
# include "internal.h"
|
||||||
|
|
||||||
|
# include "virxml.h"
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
VIR_SECRET_LOOKUP_TYPE_NONE,
|
VIR_SECRET_LOOKUP_TYPE_NONE,
|
||||||
VIR_SECRET_LOOKUP_TYPE_UUID,
|
VIR_SECRET_LOOKUP_TYPE_UUID,
|
||||||
@@ -46,5 +48,6 @@ struct _virSecretLookupTypeDef {
|
|||||||
void virSecretLookupDefClear(virSecretLookupTypeDefPtr def);
|
void virSecretLookupDefClear(virSecretLookupTypeDefPtr def);
|
||||||
int virSecretLookupDefCopy(virSecretLookupTypeDefPtr dst,
|
int virSecretLookupDefCopy(virSecretLookupTypeDefPtr dst,
|
||||||
const virSecretLookupTypeDef *src);
|
const virSecretLookupTypeDef *src);
|
||||||
|
int virSecretLookupParseSecret(xmlNodePtr secretnode,
|
||||||
|
virSecretLookupTypeDefPtr def);
|
||||||
#endif /* __VIR_SECRET_H__ */
|
#endif /* __VIR_SECRET_H__ */
|
||||||
+17
-54
@@ -1537,62 +1537,11 @@ virStorageAuthDefCopy(const virStorageAuthDef *src)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
|
||||||
virStorageAuthDefParseSecret(xmlXPathContextPtr ctxt,
|
|
||||||
virStorageAuthDefPtr authdef)
|
|
||||||
{
|
|
||||||
char *uuid;
|
|
||||||
char *usage;
|
|
||||||
int ret = -1;
|
|
||||||
|
|
||||||
/* Used by the domain disk xml parsing in order to ensure the
|
|
||||||
* <secret type='%s' value matches the expected secret type for
|
|
||||||
* the style of disk (iscsi is chap, nbd is ceph). For some reason
|
|
||||||
* the virSecretUsageType{From|To}String() cannot be linked here
|
|
||||||
* and because only the domain parsing code cares - just keep
|
|
||||||
* it as a string.
|
|
||||||
*/
|
|
||||||
authdef->secrettype = virXPathString("string(./secret/@type)", ctxt);
|
|
||||||
|
|
||||||
uuid = virXPathString("string(./secret/@uuid)", ctxt);
|
|
||||||
usage = virXPathString("string(./secret/@usage)", ctxt);
|
|
||||||
if (uuid == NULL && usage == NULL) {
|
|
||||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
||||||
_("missing auth secret uuid or usage attribute"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (uuid && usage) {
|
|
||||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
||||||
_("either auth secret uuid or usage expected"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (uuid) {
|
|
||||||
if (virUUIDParse(uuid, authdef->seclookupdef.u.uuid) < 0) {
|
|
||||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
||||||
_("invalid auth secret uuid"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
authdef->seclookupdef.type = VIR_SECRET_LOOKUP_TYPE_UUID;
|
|
||||||
} else {
|
|
||||||
authdef->seclookupdef.u.usage = usage;
|
|
||||||
usage = NULL;
|
|
||||||
authdef->seclookupdef.type = VIR_SECRET_LOOKUP_TYPE_USAGE;
|
|
||||||
}
|
|
||||||
ret = 0;
|
|
||||||
|
|
||||||
cleanup:
|
|
||||||
VIR_FREE(uuid);
|
|
||||||
VIR_FREE(usage);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static virStorageAuthDefPtr
|
static virStorageAuthDefPtr
|
||||||
virStorageAuthDefParseXML(xmlXPathContextPtr ctxt)
|
virStorageAuthDefParseXML(xmlXPathContextPtr ctxt)
|
||||||
{
|
{
|
||||||
virStorageAuthDefPtr authdef = NULL;
|
virStorageAuthDefPtr authdef = NULL;
|
||||||
|
xmlNodePtr secretnode = NULL;
|
||||||
char *username = NULL;
|
char *username = NULL;
|
||||||
char *authtype = NULL;
|
char *authtype = NULL;
|
||||||
|
|
||||||
@@ -1621,8 +1570,22 @@ virStorageAuthDefParseXML(xmlXPathContextPtr ctxt)
|
|||||||
VIR_FREE(authtype);
|
VIR_FREE(authtype);
|
||||||
}
|
}
|
||||||
|
|
||||||
authdef->seclookupdef.type = VIR_SECRET_LOOKUP_TYPE_NONE;
|
if (!(secretnode = virXPathNode("./secret ", ctxt))) {
|
||||||
if (virStorageAuthDefParseSecret(ctxt, authdef) < 0)
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||||
|
_("Missing <secret> element in auth"));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Used by the domain disk xml parsing in order to ensure the
|
||||||
|
* <secret type='%s' value matches the expected secret type for
|
||||||
|
* the style of disk (iscsi is chap, nbd is ceph). For some reason
|
||||||
|
* the virSecretUsageType{From|To}String() cannot be linked here
|
||||||
|
* and because only the domain parsing code cares - just keep
|
||||||
|
* it as a string.
|
||||||
|
*/
|
||||||
|
authdef->secrettype = virXMLPropString(secretnode, "type");
|
||||||
|
|
||||||
|
if (virSecretLookupParseSecret(secretnode, &authdef->seclookupdef) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
return authdef;
|
return authdef;
|
||||||
|
|||||||
Reference in new issue
Block a user