mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 11:31:16 +00:00
secret: Introduce virSecretObj{Get|Set}Def
Introduce fetch and set accessor to the secretObj->def field for usage by the driver to avoid the driver needing to know the format of virSecretObj
This commit is contained in:
parent
ac9ffd607e
commit
9e1e56216f
@ -740,6 +740,21 @@ virSecretObjSaveData(virSecretObjPtr secret)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
virSecretDefPtr
|
||||||
|
virSecretObjGetDef(virSecretObjPtr secret)
|
||||||
|
{
|
||||||
|
return secret->def;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
virSecretObjSetDef(virSecretObjPtr secret,
|
||||||
|
virSecretDefPtr def)
|
||||||
|
{
|
||||||
|
secret->def = def;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virSecretLoadValidateUUID(virSecretDefPtr def,
|
virSecretLoadValidateUUID(virSecretDefPtr def,
|
||||||
const char *file)
|
const char *file)
|
||||||
|
@ -101,6 +101,10 @@ int virSecretObjSaveConfig(virSecretObjPtr secret);
|
|||||||
|
|
||||||
int virSecretObjSaveData(virSecretObjPtr secret);
|
int virSecretObjSaveData(virSecretObjPtr secret);
|
||||||
|
|
||||||
|
virSecretDefPtr virSecretObjGetDef(virSecretObjPtr secret);
|
||||||
|
|
||||||
|
void virSecretObjSetDef(virSecretObjPtr secret, virSecretDefPtr def);
|
||||||
|
|
||||||
int virSecretLoadAllConfigs(virSecretObjListPtr secrets,
|
int virSecretLoadAllConfigs(virSecretObjListPtr secrets,
|
||||||
const char *configDir);
|
const char *configDir);
|
||||||
#endif /* __VIRSECRETOBJ_H__ */
|
#endif /* __VIRSECRETOBJ_H__ */
|
||||||
|
@ -899,6 +899,7 @@ virSecretLoadAllConfigs;
|
|||||||
virSecretObjDeleteConfig;
|
virSecretObjDeleteConfig;
|
||||||
virSecretObjDeleteData;
|
virSecretObjDeleteData;
|
||||||
virSecretObjEndAPI;
|
virSecretObjEndAPI;
|
||||||
|
virSecretObjGetDef;
|
||||||
virSecretObjListAdd;
|
virSecretObjListAdd;
|
||||||
virSecretObjListExport;
|
virSecretObjListExport;
|
||||||
virSecretObjListFindByUsage;
|
virSecretObjListFindByUsage;
|
||||||
@ -909,6 +910,7 @@ virSecretObjListNumOfSecrets;
|
|||||||
virSecretObjListRemove;
|
virSecretObjListRemove;
|
||||||
virSecretObjSaveConfig;
|
virSecretObjSaveConfig;
|
||||||
virSecretObjSaveData;
|
virSecretObjSaveData;
|
||||||
|
virSecretObjSetDef;
|
||||||
|
|
||||||
|
|
||||||
# cpu/cpu.h
|
# cpu/cpu.h
|
||||||
|
@ -153,6 +153,7 @@ secretLookupByUUID(virConnectPtr conn,
|
|||||||
{
|
{
|
||||||
virSecretPtr ret = NULL;
|
virSecretPtr ret = NULL;
|
||||||
virSecretObjPtr secret;
|
virSecretObjPtr secret;
|
||||||
|
virSecretDefPtr def;
|
||||||
|
|
||||||
if (!(secret = virSecretObjListFindByUUID(driver->secrets, uuid))) {
|
if (!(secret = virSecretObjListFindByUUID(driver->secrets, uuid))) {
|
||||||
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
||||||
@ -162,13 +163,14 @@ secretLookupByUUID(virConnectPtr conn,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virSecretLookupByUUIDEnsureACL(conn, secret->def) < 0)
|
def = virSecretObjGetDef(secret);
|
||||||
|
if (virSecretLookupByUUIDEnsureACL(conn, def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
ret = virGetSecret(conn,
|
ret = virGetSecret(conn,
|
||||||
secret->def->uuid,
|
def->uuid,
|
||||||
secret->def->usage_type,
|
def->usage_type,
|
||||||
virSecretUsageIDForDef(secret->def));
|
virSecretUsageIDForDef(def));
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virSecretObjEndAPI(&secret);
|
virSecretObjEndAPI(&secret);
|
||||||
@ -183,6 +185,7 @@ secretLookupByUsage(virConnectPtr conn,
|
|||||||
{
|
{
|
||||||
virSecretPtr ret = NULL;
|
virSecretPtr ret = NULL;
|
||||||
virSecretObjPtr secret;
|
virSecretObjPtr secret;
|
||||||
|
virSecretDefPtr def;
|
||||||
|
|
||||||
if (!(secret = virSecretObjListFindByUsage(driver->secrets,
|
if (!(secret = virSecretObjListFindByUsage(driver->secrets,
|
||||||
usageType, usageID))) {
|
usageType, usageID))) {
|
||||||
@ -191,13 +194,14 @@ secretLookupByUsage(virConnectPtr conn,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virSecretLookupByUsageEnsureACL(conn, secret->def) < 0)
|
def = virSecretObjGetDef(secret);
|
||||||
|
if (virSecretLookupByUsageEnsureACL(conn, def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
ret = virGetSecret(conn,
|
ret = virGetSecret(conn,
|
||||||
secret->def->uuid,
|
def->uuid,
|
||||||
secret->def->usage_type,
|
def->usage_type,
|
||||||
virSecretUsageIDForDef(secret->def));
|
virSecretUsageIDForDef(def));
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virSecretObjEndAPI(&secret);
|
virSecretObjEndAPI(&secret);
|
||||||
@ -250,22 +254,22 @@ secretDefineXML(virConnectPtr conn,
|
|||||||
virSecretObjDeleteData(secret);
|
virSecretObjDeleteData(secret);
|
||||||
}
|
}
|
||||||
/* Saved successfully - drop old values */
|
/* Saved successfully - drop old values */
|
||||||
new_attrs = NULL;
|
|
||||||
virSecretDefFree(backup);
|
virSecretDefFree(backup);
|
||||||
|
|
||||||
ret = virGetSecret(conn,
|
ret = virGetSecret(conn,
|
||||||
secret->def->uuid,
|
new_attrs->uuid,
|
||||||
secret->def->usage_type,
|
new_attrs->usage_type,
|
||||||
virSecretUsageIDForDef(secret->def));
|
virSecretUsageIDForDef(new_attrs));
|
||||||
|
new_attrs = NULL;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
restore_backup:
|
restore_backup:
|
||||||
/* If we have a backup, then secret was defined before, so just restore
|
/* If we have a backup, then secret was defined before, so just restore
|
||||||
* the backup. The current secret->def (new_attrs) will be handled below.
|
* the backup. The current (new_attrs) will be handled below.
|
||||||
* Otherwise, this is a new secret, thus remove it.
|
* Otherwise, this is a new secret, thus remove it.
|
||||||
*/
|
*/
|
||||||
if (backup)
|
if (backup)
|
||||||
secret->def = backup;
|
virSecretObjSetDef(secret, backup);
|
||||||
else
|
else
|
||||||
virSecretObjListRemove(driver->secrets, secret);
|
virSecretObjListRemove(driver->secrets, secret);
|
||||||
|
|
||||||
@ -282,16 +286,18 @@ secretGetXMLDesc(virSecretPtr obj,
|
|||||||
{
|
{
|
||||||
char *ret = NULL;
|
char *ret = NULL;
|
||||||
virSecretObjPtr secret;
|
virSecretObjPtr secret;
|
||||||
|
virSecretDefPtr def;
|
||||||
|
|
||||||
virCheckFlags(0, NULL);
|
virCheckFlags(0, NULL);
|
||||||
|
|
||||||
if (!(secret = secretObjFromSecret(obj)))
|
if (!(secret = secretObjFromSecret(obj)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virSecretGetXMLDescEnsureACL(obj->conn, secret->def) < 0)
|
def = virSecretObjGetDef(secret);
|
||||||
|
if (virSecretGetXMLDescEnsureACL(obj->conn, def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
ret = virSecretDefFormat(secret->def);
|
ret = virSecretDefFormat(def);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virSecretObjEndAPI(&secret);
|
virSecretObjEndAPI(&secret);
|
||||||
@ -309,6 +315,7 @@ secretSetValue(virSecretPtr obj,
|
|||||||
unsigned char *old_value, *new_value;
|
unsigned char *old_value, *new_value;
|
||||||
size_t old_value_size;
|
size_t old_value_size;
|
||||||
virSecretObjPtr secret;
|
virSecretObjPtr secret;
|
||||||
|
virSecretDefPtr def;
|
||||||
|
|
||||||
virCheckFlags(0, -1);
|
virCheckFlags(0, -1);
|
||||||
|
|
||||||
@ -318,7 +325,8 @@ secretSetValue(virSecretPtr obj,
|
|||||||
if (!(secret = secretObjFromSecret(obj)))
|
if (!(secret = secretObjFromSecret(obj)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virSecretSetValueEnsureACL(obj->conn, secret->def) < 0)
|
def = virSecretObjGetDef(secret);
|
||||||
|
if (virSecretSetValueEnsureACL(obj->conn, def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
old_value = secret->value;
|
old_value = secret->value;
|
||||||
@ -327,7 +335,7 @@ secretSetValue(virSecretPtr obj,
|
|||||||
memcpy(new_value, value, value_size);
|
memcpy(new_value, value, value_size);
|
||||||
secret->value = new_value;
|
secret->value = new_value;
|
||||||
secret->value_size = value_size;
|
secret->value_size = value_size;
|
||||||
if (!secret->def->ephemeral) {
|
if (!def->ephemeral) {
|
||||||
if (secretEnsureDirectory() < 0)
|
if (secretEnsureDirectory() < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
@ -366,13 +374,15 @@ secretGetValue(virSecretPtr obj,
|
|||||||
{
|
{
|
||||||
unsigned char *ret = NULL;
|
unsigned char *ret = NULL;
|
||||||
virSecretObjPtr secret;
|
virSecretObjPtr secret;
|
||||||
|
virSecretDefPtr def;
|
||||||
|
|
||||||
virCheckFlags(0, NULL);
|
virCheckFlags(0, NULL);
|
||||||
|
|
||||||
if (!(secret = secretObjFromSecret(obj)))
|
if (!(secret = secretObjFromSecret(obj)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virSecretGetValueEnsureACL(obj->conn, secret->def) < 0)
|
def = virSecretObjGetDef(secret);
|
||||||
|
if (virSecretGetValueEnsureACL(obj->conn, def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (secret->value == NULL) {
|
if (secret->value == NULL) {
|
||||||
@ -384,7 +394,7 @@ secretGetValue(virSecretPtr obj,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((internalFlags & VIR_SECRET_GET_VALUE_INTERNAL_CALL) == 0 &&
|
if ((internalFlags & VIR_SECRET_GET_VALUE_INTERNAL_CALL) == 0 &&
|
||||||
secret->def->private) {
|
def->private) {
|
||||||
virReportError(VIR_ERR_INVALID_SECRET, "%s",
|
virReportError(VIR_ERR_INVALID_SECRET, "%s",
|
||||||
_("secret is private"));
|
_("secret is private"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -406,11 +416,13 @@ secretUndefine(virSecretPtr obj)
|
|||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
virSecretObjPtr secret;
|
virSecretObjPtr secret;
|
||||||
|
virSecretDefPtr def;
|
||||||
|
|
||||||
if (!(secret = secretObjFromSecret(obj)))
|
if (!(secret = secretObjFromSecret(obj)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virSecretUndefineEnsureACL(obj->conn, secret->def) < 0)
|
def = virSecretObjGetDef(secret);
|
||||||
|
if (virSecretUndefineEnsureACL(obj->conn, def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virSecretObjDeleteConfig(secret) < 0)
|
if (virSecretObjDeleteConfig(secret) < 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user