2009-08-14 19:48:55 +00:00
|
|
|
/*
|
|
|
|
* secret_driver.c: local driver for secret manipulation API
|
|
|
|
*
|
2016-02-23 18:44:12 +00:00
|
|
|
* Copyright (C) 2009-2016 Red Hat, Inc.
|
2009-08-14 19:48:55 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2009-08-14 19:48:55 +00:00
|
|
|
*
|
|
|
|
* Red Hat Author: Miloslav Trmač <mitr@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "internal.h"
|
|
|
|
#include "base64.h"
|
|
|
|
#include "datatypes.h"
|
|
|
|
#include "driver.h"
|
2012-12-12 17:59:27 +00:00
|
|
|
#include "virlog.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2009-08-14 19:48:55 +00:00
|
|
|
#include "secret_conf.h"
|
2016-02-27 11:49:12 +00:00
|
|
|
#include "virsecretobj.h"
|
2009-08-14 19:48:55 +00:00
|
|
|
#include "secret_driver.h"
|
2012-12-13 15:49:48 +00:00
|
|
|
#include "virthread.h"
|
2012-12-13 18:01:25 +00:00
|
|
|
#include "viruuid.h"
|
2012-12-13 18:21:53 +00:00
|
|
|
#include "virerror.h"
|
2011-07-19 18:32:58 +00:00
|
|
|
#include "virfile.h"
|
2010-11-16 14:54:17 +00:00
|
|
|
#include "configmake.h"
|
2013-04-03 10:36:23 +00:00
|
|
|
#include "virstring.h"
|
2013-04-23 10:56:22 +00:00
|
|
|
#include "viraccessapicheck.h"
|
2009-08-14 19:48:55 +00:00
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_SECRET
|
|
|
|
|
2014-02-28 12:16:17 +00:00
|
|
|
VIR_LOG_INIT("secret.secret_driver");
|
|
|
|
|
2009-08-14 19:48:55 +00:00
|
|
|
enum { SECRET_MAX_XML_FILE = 10*1024*1024 };
|
|
|
|
|
2016-02-23 18:44:12 +00:00
|
|
|
/* Internal driver state */
|
2009-08-14 19:48:55 +00:00
|
|
|
|
|
|
|
typedef struct _virSecretDriverState virSecretDriverState;
|
|
|
|
typedef virSecretDriverState *virSecretDriverStatePtr;
|
|
|
|
struct _virSecretDriverState {
|
|
|
|
virMutex lock;
|
2016-02-25 11:30:39 +00:00
|
|
|
virSecretObjListPtr secrets;
|
2016-02-23 23:27:21 +00:00
|
|
|
char *configDir;
|
2009-08-14 19:48:55 +00:00
|
|
|
};
|
|
|
|
|
2014-11-07 10:28:58 +00:00
|
|
|
static virSecretDriverStatePtr driver;
|
2009-08-14 19:48:55 +00:00
|
|
|
|
|
|
|
static void
|
2014-11-07 10:28:58 +00:00
|
|
|
secretDriverLock(void)
|
2009-08-14 19:48:55 +00:00
|
|
|
{
|
|
|
|
virMutexLock(&driver->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-11-07 10:28:58 +00:00
|
|
|
secretDriverUnlock(void)
|
2009-08-14 19:48:55 +00:00
|
|
|
{
|
|
|
|
virMutexUnlock(&driver->lock);
|
|
|
|
}
|
|
|
|
|
2016-02-24 15:52:30 +00:00
|
|
|
|
2016-02-29 22:15:26 +00:00
|
|
|
|
|
|
|
static virSecretObjPtr
|
|
|
|
secretObjFromSecret(virSecretPtr secret)
|
|
|
|
{
|
|
|
|
virSecretObjPtr obj;
|
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
|
2016-02-25 11:30:39 +00:00
|
|
|
if (!(obj = virSecretObjListFindByUUID(driver->secrets, secret->uuid))) {
|
2016-02-29 22:15:26 +00:00
|
|
|
virUUIDFormat(secret->uuid, uuidstr);
|
|
|
|
virReportError(VIR_ERR_NO_SECRET,
|
|
|
|
_("no secret with matching uuid '%s'"), uuidstr);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-14 19:48:55 +00:00
|
|
|
static int
|
2014-11-07 10:28:58 +00:00
|
|
|
secretEnsureDirectory(void)
|
2009-08-14 19:48:55 +00:00
|
|
|
{
|
2016-02-23 23:27:21 +00:00
|
|
|
if (mkdir(driver->configDir, S_IRWXU) < 0 && errno != EEXIST) {
|
2010-02-04 20:02:58 +00:00
|
|
|
virReportSystemError(errno, _("cannot create '%s'"),
|
2016-02-23 23:27:21 +00:00
|
|
|
driver->configDir);
|
2009-08-14 19:48:55 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-02-23 18:44:12 +00:00
|
|
|
/* Driver functions */
|
2009-08-14 19:48:55 +00:00
|
|
|
|
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
secretConnectNumOfSecrets(virConnectPtr conn)
|
2009-08-14 19:48:55 +00:00
|
|
|
{
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virConnectNumOfSecretsEnsureACL(conn) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2016-02-25 11:30:39 +00:00
|
|
|
return virSecretObjListNumOfSecrets(driver->secrets,
|
|
|
|
virConnectNumOfSecretsCheckACL,
|
|
|
|
conn);
|
2009-08-14 19:48:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2016-02-23 18:44:12 +00:00
|
|
|
secretConnectListSecrets(virConnectPtr conn,
|
|
|
|
char **uuids,
|
|
|
|
int maxuuids)
|
2009-08-14 19:48:55 +00:00
|
|
|
{
|
|
|
|
memset(uuids, 0, maxuuids * sizeof(*uuids));
|
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virConnectListSecretsEnsureACL(conn) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2016-02-25 11:30:39 +00:00
|
|
|
return virSecretObjListGetUUIDs(driver->secrets, uuids, maxuuids,
|
|
|
|
virConnectListSecretsCheckACL, conn);
|
2009-08-14 19:48:55 +00:00
|
|
|
}
|
|
|
|
|
Add usage type/id as a public API property of virSecret
* include/libvirt/libvirt.h, include/libvirt/libvirt.h.in: Add
virSecretGetUsageType, virSecretGetUsageID and virLookupSecretByUsage
* python/generator.py: Mark virSecretGetUsageType, virSecretGetUsageID
as not throwing exceptions
* qemud/remote.c: Implement dispatch for virLookupSecretByUsage
* qemud/remote_protocol.x: Add usage type & ID as attributes of
remote_nonnull_secret. Add RPC calls for new public APIs
* qemud/remote_dispatch_args.h, qemud/remote_dispatch_prototypes.h,
qemud/remote_dispatch_ret.h, qemud/remote_dispatch_table.h,
qemud/remote_protocol.c, qemud/remote_protocol.h: Re-generate
* src/datatypes.c, src/datatypes.h: Add usageType and usageID as
properties of virSecretPtr
* src/driver.h: Add virLookupSecretByUsage driver entry point
* src/libvirt.c: Implement virSecretGetUsageType, virSecretGetUsageID
and virLookupSecretByUsage
* src/libvirt_public.syms: Export virSecretGetUsageType, virSecretGetUsageID
and virLookupSecretByUsage
* src/remote_internal.c: Implement virLookupSecretByUsage entry
* src/secret_conf.c, src/secret_conf.h: Remove the
virSecretUsageType enum, now in public API. Make volume
path mandatory when parsing XML
* src/secret_driver.c: Enforce usage uniqueness when defining secrets.
Implement virSecretLookupByUsage api method
* src/virsh.c: Include usage for secret-list command
2009-09-11 13:06:15 +00:00
|
|
|
|
2012-09-14 08:38:50 +00:00
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
secretConnectListAllSecrets(virConnectPtr conn,
|
|
|
|
virSecretPtr **secrets,
|
2014-03-18 08:19:33 +00:00
|
|
|
unsigned int flags)
|
|
|
|
{
|
2012-09-14 08:38:50 +00:00
|
|
|
virCheckFlags(VIR_CONNECT_LIST_SECRETS_FILTERS_ALL, -1);
|
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virConnectListAllSecretsEnsureACL(conn) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2016-02-25 11:30:39 +00:00
|
|
|
return virSecretObjListExport(conn, driver->secrets, secrets,
|
|
|
|
virConnectListAllSecretsCheckACL,
|
|
|
|
flags);
|
2012-09-14 08:38:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-14 19:48:55 +00:00
|
|
|
static virSecretPtr
|
2016-02-23 18:44:12 +00:00
|
|
|
secretLookupByUUID(virConnectPtr conn,
|
|
|
|
const unsigned char *uuid)
|
2009-08-14 19:48:55 +00:00
|
|
|
{
|
|
|
|
virSecretPtr ret = NULL;
|
2016-02-23 22:40:37 +00:00
|
|
|
virSecretObjPtr secret;
|
2016-03-08 00:22:04 +00:00
|
|
|
virSecretDefPtr def;
|
2009-08-14 19:48:55 +00:00
|
|
|
|
2016-02-25 11:30:39 +00:00
|
|
|
if (!(secret = virSecretObjListFindByUUID(driver->secrets, uuid))) {
|
Fix UUID handling in secrets/storage encryption APIs
Convert all the secret/storage encryption APIs / wire format to
handle UUIDs in raw format instead of non-canonical printable
format. Guarentees data format correctness.
* docs/schemas/storageencryption.rng: Make UUID mandatory for a secret
and validate fully
* docs/schemas/secret.rng: Fully validate UUID
* include/libvirt/libvirt.h, include/libvirt/libvirt.h.in, Add
virSecretLookupByUUID and virSecretGetUUID. Make
virSecretGetUUIDString follow normal API design pattern
* python/generator.py: Skip generation of virSecretGetUUID,
virSecretGetUUIDString and virSecretLookupByUUID
* python/libvir.c, python/libvirt-python-api.xml: Manual impl
of virSecretGetUUID,virSecretGetUUIDString and virSecretLookupByUUID
* qemud/remote.c: s/virSecretLookupByUUIDString/virSecretLookupByUUID/
Fix get_nonnull_secret/make_nonnull_secret to use unsigned char
* qemud/remote_protocol.x: Fix remote_nonnull_secret to use a
remote_uuid instead of remote_nonnull_string for UUID field.
Rename REMOTE_PROC_SECRET_LOOKUP_BY_UUID_STRING to
REMOTE_PROC_SECRET_LOOKUP_BY_UUID_STRING and make it take an
remote_uuid value
* qemud/remote_dispatch_args.h, qemud/remote_dispatch_prototypes.h,
qemud/remote_dispatch_ret.h, qemud/remote_dispatch_table.h,
qemud/remote_protocol.c, qemud/remote_protocol.h: Re-generate
* src/datatypes.h, src/datatypes.c: Store UUID in raw format instead
of printable. Change virGetSecret to use raw format UUID
* src/driver.h: Rename virDrvSecretLookupByUUIDString to
virDrvSecretLookupByUUID and use raw format UUID
* src/libvirt.c: Add virSecretLookupByUUID and virSecretGetUUID
and re-implement virSecretLookupByUUIDString and
virSecretGetUUIDString in terms of those
* src/libvirt_public.syms: Add virSecretLookupByUUID and
virSecretGetUUID
* src/remote_internal.c: Rename remoteSecretLookupByUUIDString
to remoteSecretLookupByUUID. Fix typo in args for
remoteSecretDefineXML impl. Use raw UUID format for
get_nonnull_secret and make_nonnull_secret
* src/storage_encryption_conf.c, src/storage_encryption_conf.h:
Storage UUID in raw format, and require it to be present in
XML. Use UUID parser to validate.
* secret_conf.h, secret_conf.c: Generate a UUID if none is provided.
Storage UUID in raw format.
* src/secret_driver.c: Adjust to deal with raw UUIDs. Save secrets
in a filed with printable UUID, instead of base64 UUID.
* src/virsh.c: Adjust for changed public API contract of
virSecretGetUUIDString.
* src/storage_Backend.c: DOn't undefine secret we just generated
upon successful volume creation. Fix to handle raw UUIDs. Generate
a non-clashing UUID
* src/qemu_driver.c: Change to use lookupByUUID instead of
lookupByUUIDString
2009-09-10 16:44:12 +00:00
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
virUUIDFormat(uuid, uuidstr);
|
2012-07-18 11:40:16 +00:00
|
|
|
virReportError(VIR_ERR_NO_SECRET,
|
|
|
|
_("no secret with matching uuid '%s'"), uuidstr);
|
2009-08-14 19:48:55 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2016-03-08 00:22:04 +00:00
|
|
|
def = virSecretObjGetDef(secret);
|
|
|
|
if (virSecretLookupByUUIDEnsureACL(conn, def) < 0)
|
2013-04-23 10:56:22 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
Add usage type/id as a public API property of virSecret
* include/libvirt/libvirt.h, include/libvirt/libvirt.h.in: Add
virSecretGetUsageType, virSecretGetUsageID and virLookupSecretByUsage
* python/generator.py: Mark virSecretGetUsageType, virSecretGetUsageID
as not throwing exceptions
* qemud/remote.c: Implement dispatch for virLookupSecretByUsage
* qemud/remote_protocol.x: Add usage type & ID as attributes of
remote_nonnull_secret. Add RPC calls for new public APIs
* qemud/remote_dispatch_args.h, qemud/remote_dispatch_prototypes.h,
qemud/remote_dispatch_ret.h, qemud/remote_dispatch_table.h,
qemud/remote_protocol.c, qemud/remote_protocol.h: Re-generate
* src/datatypes.c, src/datatypes.h: Add usageType and usageID as
properties of virSecretPtr
* src/driver.h: Add virLookupSecretByUsage driver entry point
* src/libvirt.c: Implement virSecretGetUsageType, virSecretGetUsageID
and virLookupSecretByUsage
* src/libvirt_public.syms: Export virSecretGetUsageType, virSecretGetUsageID
and virLookupSecretByUsage
* src/remote_internal.c: Implement virLookupSecretByUsage entry
* src/secret_conf.c, src/secret_conf.h: Remove the
virSecretUsageType enum, now in public API. Make volume
path mandatory when parsing XML
* src/secret_driver.c: Enforce usage uniqueness when defining secrets.
Implement virSecretLookupByUsage api method
* src/virsh.c: Include usage for secret-list command
2009-09-11 13:06:15 +00:00
|
|
|
ret = virGetSecret(conn,
|
2016-03-08 00:22:04 +00:00
|
|
|
def->uuid,
|
|
|
|
def->usage_type,
|
|
|
|
virSecretUsageIDForDef(def));
|
Add usage type/id as a public API property of virSecret
* include/libvirt/libvirt.h, include/libvirt/libvirt.h.in: Add
virSecretGetUsageType, virSecretGetUsageID and virLookupSecretByUsage
* python/generator.py: Mark virSecretGetUsageType, virSecretGetUsageID
as not throwing exceptions
* qemud/remote.c: Implement dispatch for virLookupSecretByUsage
* qemud/remote_protocol.x: Add usage type & ID as attributes of
remote_nonnull_secret. Add RPC calls for new public APIs
* qemud/remote_dispatch_args.h, qemud/remote_dispatch_prototypes.h,
qemud/remote_dispatch_ret.h, qemud/remote_dispatch_table.h,
qemud/remote_protocol.c, qemud/remote_protocol.h: Re-generate
* src/datatypes.c, src/datatypes.h: Add usageType and usageID as
properties of virSecretPtr
* src/driver.h: Add virLookupSecretByUsage driver entry point
* src/libvirt.c: Implement virSecretGetUsageType, virSecretGetUsageID
and virLookupSecretByUsage
* src/libvirt_public.syms: Export virSecretGetUsageType, virSecretGetUsageID
and virLookupSecretByUsage
* src/remote_internal.c: Implement virLookupSecretByUsage entry
* src/secret_conf.c, src/secret_conf.h: Remove the
virSecretUsageType enum, now in public API. Make volume
path mandatory when parsing XML
* src/secret_driver.c: Enforce usage uniqueness when defining secrets.
Implement virSecretLookupByUsage api method
* src/virsh.c: Include usage for secret-list command
2009-09-11 13:06:15 +00:00
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2016-02-25 11:30:39 +00:00
|
|
|
virSecretObjEndAPI(&secret);
|
Add usage type/id as a public API property of virSecret
* include/libvirt/libvirt.h, include/libvirt/libvirt.h.in: Add
virSecretGetUsageType, virSecretGetUsageID and virLookupSecretByUsage
* python/generator.py: Mark virSecretGetUsageType, virSecretGetUsageID
as not throwing exceptions
* qemud/remote.c: Implement dispatch for virLookupSecretByUsage
* qemud/remote_protocol.x: Add usage type & ID as attributes of
remote_nonnull_secret. Add RPC calls for new public APIs
* qemud/remote_dispatch_args.h, qemud/remote_dispatch_prototypes.h,
qemud/remote_dispatch_ret.h, qemud/remote_dispatch_table.h,
qemud/remote_protocol.c, qemud/remote_protocol.h: Re-generate
* src/datatypes.c, src/datatypes.h: Add usageType and usageID as
properties of virSecretPtr
* src/driver.h: Add virLookupSecretByUsage driver entry point
* src/libvirt.c: Implement virSecretGetUsageType, virSecretGetUsageID
and virLookupSecretByUsage
* src/libvirt_public.syms: Export virSecretGetUsageType, virSecretGetUsageID
and virLookupSecretByUsage
* src/remote_internal.c: Implement virLookupSecretByUsage entry
* src/secret_conf.c, src/secret_conf.h: Remove the
virSecretUsageType enum, now in public API. Make volume
path mandatory when parsing XML
* src/secret_driver.c: Enforce usage uniqueness when defining secrets.
Implement virSecretLookupByUsage api method
* src/virsh.c: Include usage for secret-list command
2009-09-11 13:06:15 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static virSecretPtr
|
2016-02-23 18:44:12 +00:00
|
|
|
secretLookupByUsage(virConnectPtr conn,
|
|
|
|
int usageType,
|
|
|
|
const char *usageID)
|
Add usage type/id as a public API property of virSecret
* include/libvirt/libvirt.h, include/libvirt/libvirt.h.in: Add
virSecretGetUsageType, virSecretGetUsageID and virLookupSecretByUsage
* python/generator.py: Mark virSecretGetUsageType, virSecretGetUsageID
as not throwing exceptions
* qemud/remote.c: Implement dispatch for virLookupSecretByUsage
* qemud/remote_protocol.x: Add usage type & ID as attributes of
remote_nonnull_secret. Add RPC calls for new public APIs
* qemud/remote_dispatch_args.h, qemud/remote_dispatch_prototypes.h,
qemud/remote_dispatch_ret.h, qemud/remote_dispatch_table.h,
qemud/remote_protocol.c, qemud/remote_protocol.h: Re-generate
* src/datatypes.c, src/datatypes.h: Add usageType and usageID as
properties of virSecretPtr
* src/driver.h: Add virLookupSecretByUsage driver entry point
* src/libvirt.c: Implement virSecretGetUsageType, virSecretGetUsageID
and virLookupSecretByUsage
* src/libvirt_public.syms: Export virSecretGetUsageType, virSecretGetUsageID
and virLookupSecretByUsage
* src/remote_internal.c: Implement virLookupSecretByUsage entry
* src/secret_conf.c, src/secret_conf.h: Remove the
virSecretUsageType enum, now in public API. Make volume
path mandatory when parsing XML
* src/secret_driver.c: Enforce usage uniqueness when defining secrets.
Implement virSecretLookupByUsage api method
* src/virsh.c: Include usage for secret-list command
2009-09-11 13:06:15 +00:00
|
|
|
{
|
|
|
|
virSecretPtr ret = NULL;
|
2016-02-23 22:40:37 +00:00
|
|
|
virSecretObjPtr secret;
|
2016-03-08 00:22:04 +00:00
|
|
|
virSecretDefPtr def;
|
Add usage type/id as a public API property of virSecret
* include/libvirt/libvirt.h, include/libvirt/libvirt.h.in: Add
virSecretGetUsageType, virSecretGetUsageID and virLookupSecretByUsage
* python/generator.py: Mark virSecretGetUsageType, virSecretGetUsageID
as not throwing exceptions
* qemud/remote.c: Implement dispatch for virLookupSecretByUsage
* qemud/remote_protocol.x: Add usage type & ID as attributes of
remote_nonnull_secret. Add RPC calls for new public APIs
* qemud/remote_dispatch_args.h, qemud/remote_dispatch_prototypes.h,
qemud/remote_dispatch_ret.h, qemud/remote_dispatch_table.h,
qemud/remote_protocol.c, qemud/remote_protocol.h: Re-generate
* src/datatypes.c, src/datatypes.h: Add usageType and usageID as
properties of virSecretPtr
* src/driver.h: Add virLookupSecretByUsage driver entry point
* src/libvirt.c: Implement virSecretGetUsageType, virSecretGetUsageID
and virLookupSecretByUsage
* src/libvirt_public.syms: Export virSecretGetUsageType, virSecretGetUsageID
and virLookupSecretByUsage
* src/remote_internal.c: Implement virLookupSecretByUsage entry
* src/secret_conf.c, src/secret_conf.h: Remove the
virSecretUsageType enum, now in public API. Make volume
path mandatory when parsing XML
* src/secret_driver.c: Enforce usage uniqueness when defining secrets.
Implement virSecretLookupByUsage api method
* src/virsh.c: Include usage for secret-list command
2009-09-11 13:06:15 +00:00
|
|
|
|
2016-02-25 11:30:39 +00:00
|
|
|
if (!(secret = virSecretObjListFindByUsage(driver->secrets,
|
|
|
|
usageType, usageID))) {
|
2012-07-18 11:40:16 +00:00
|
|
|
virReportError(VIR_ERR_NO_SECRET,
|
|
|
|
_("no secret with matching usage '%s'"), usageID);
|
Add usage type/id as a public API property of virSecret
* include/libvirt/libvirt.h, include/libvirt/libvirt.h.in: Add
virSecretGetUsageType, virSecretGetUsageID and virLookupSecretByUsage
* python/generator.py: Mark virSecretGetUsageType, virSecretGetUsageID
as not throwing exceptions
* qemud/remote.c: Implement dispatch for virLookupSecretByUsage
* qemud/remote_protocol.x: Add usage type & ID as attributes of
remote_nonnull_secret. Add RPC calls for new public APIs
* qemud/remote_dispatch_args.h, qemud/remote_dispatch_prototypes.h,
qemud/remote_dispatch_ret.h, qemud/remote_dispatch_table.h,
qemud/remote_protocol.c, qemud/remote_protocol.h: Re-generate
* src/datatypes.c, src/datatypes.h: Add usageType and usageID as
properties of virSecretPtr
* src/driver.h: Add virLookupSecretByUsage driver entry point
* src/libvirt.c: Implement virSecretGetUsageType, virSecretGetUsageID
and virLookupSecretByUsage
* src/libvirt_public.syms: Export virSecretGetUsageType, virSecretGetUsageID
and virLookupSecretByUsage
* src/remote_internal.c: Implement virLookupSecretByUsage entry
* src/secret_conf.c, src/secret_conf.h: Remove the
virSecretUsageType enum, now in public API. Make volume
path mandatory when parsing XML
* src/secret_driver.c: Enforce usage uniqueness when defining secrets.
Implement virSecretLookupByUsage api method
* src/virsh.c: Include usage for secret-list command
2009-09-11 13:06:15 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2016-03-08 00:22:04 +00:00
|
|
|
def = virSecretObjGetDef(secret);
|
|
|
|
if (virSecretLookupByUsageEnsureACL(conn, def) < 0)
|
2013-04-23 10:56:22 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
Add usage type/id as a public API property of virSecret
* include/libvirt/libvirt.h, include/libvirt/libvirt.h.in: Add
virSecretGetUsageType, virSecretGetUsageID and virLookupSecretByUsage
* python/generator.py: Mark virSecretGetUsageType, virSecretGetUsageID
as not throwing exceptions
* qemud/remote.c: Implement dispatch for virLookupSecretByUsage
* qemud/remote_protocol.x: Add usage type & ID as attributes of
remote_nonnull_secret. Add RPC calls for new public APIs
* qemud/remote_dispatch_args.h, qemud/remote_dispatch_prototypes.h,
qemud/remote_dispatch_ret.h, qemud/remote_dispatch_table.h,
qemud/remote_protocol.c, qemud/remote_protocol.h: Re-generate
* src/datatypes.c, src/datatypes.h: Add usageType and usageID as
properties of virSecretPtr
* src/driver.h: Add virLookupSecretByUsage driver entry point
* src/libvirt.c: Implement virSecretGetUsageType, virSecretGetUsageID
and virLookupSecretByUsage
* src/libvirt_public.syms: Export virSecretGetUsageType, virSecretGetUsageID
and virLookupSecretByUsage
* src/remote_internal.c: Implement virLookupSecretByUsage entry
* src/secret_conf.c, src/secret_conf.h: Remove the
virSecretUsageType enum, now in public API. Make volume
path mandatory when parsing XML
* src/secret_driver.c: Enforce usage uniqueness when defining secrets.
Implement virSecretLookupByUsage api method
* src/virsh.c: Include usage for secret-list command
2009-09-11 13:06:15 +00:00
|
|
|
ret = virGetSecret(conn,
|
2016-03-08 00:22:04 +00:00
|
|
|
def->uuid,
|
|
|
|
def->usage_type,
|
|
|
|
virSecretUsageIDForDef(def));
|
2009-08-14 19:48:55 +00:00
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2016-02-25 11:30:39 +00:00
|
|
|
virSecretObjEndAPI(&secret);
|
2009-08-14 19:48:55 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static virSecretPtr
|
2016-02-23 18:44:12 +00:00
|
|
|
secretDefineXML(virConnectPtr conn,
|
|
|
|
const char *xml,
|
2011-07-06 22:29:02 +00:00
|
|
|
unsigned int flags)
|
2009-08-14 19:48:55 +00:00
|
|
|
{
|
|
|
|
virSecretPtr ret = NULL;
|
2016-02-24 15:52:30 +00:00
|
|
|
virSecretObjPtr secret = NULL;
|
Add usage type/id as a public API property of virSecret
* include/libvirt/libvirt.h, include/libvirt/libvirt.h.in: Add
virSecretGetUsageType, virSecretGetUsageID and virLookupSecretByUsage
* python/generator.py: Mark virSecretGetUsageType, virSecretGetUsageID
as not throwing exceptions
* qemud/remote.c: Implement dispatch for virLookupSecretByUsage
* qemud/remote_protocol.x: Add usage type & ID as attributes of
remote_nonnull_secret. Add RPC calls for new public APIs
* qemud/remote_dispatch_args.h, qemud/remote_dispatch_prototypes.h,
qemud/remote_dispatch_ret.h, qemud/remote_dispatch_table.h,
qemud/remote_protocol.c, qemud/remote_protocol.h: Re-generate
* src/datatypes.c, src/datatypes.h: Add usageType and usageID as
properties of virSecretPtr
* src/driver.h: Add virLookupSecretByUsage driver entry point
* src/libvirt.c: Implement virSecretGetUsageType, virSecretGetUsageID
and virLookupSecretByUsage
* src/libvirt_public.syms: Export virSecretGetUsageType, virSecretGetUsageID
and virLookupSecretByUsage
* src/remote_internal.c: Implement virLookupSecretByUsage entry
* src/secret_conf.c, src/secret_conf.h: Remove the
virSecretUsageType enum, now in public API. Make volume
path mandatory when parsing XML
* src/secret_driver.c: Enforce usage uniqueness when defining secrets.
Implement virSecretLookupByUsage api method
* src/virsh.c: Include usage for secret-list command
2009-09-11 13:06:15 +00:00
|
|
|
virSecretDefPtr backup = NULL;
|
|
|
|
virSecretDefPtr new_attrs;
|
2009-08-14 19:48:55 +00:00
|
|
|
|
2011-07-06 22:29:02 +00:00
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
2016-02-23 18:44:12 +00:00
|
|
|
if (!(new_attrs = virSecretDefParseString(xml)))
|
2009-08-14 19:48:55 +00:00
|
|
|
return NULL;
|
|
|
|
|
2013-04-23 10:56:22 +00:00
|
|
|
if (virSecretDefineXMLEnsureACL(conn, new_attrs) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2016-02-25 11:30:39 +00:00
|
|
|
if (!(secret = virSecretObjListAdd(driver->secrets, new_attrs,
|
|
|
|
driver->configDir, &backup)))
|
|
|
|
goto cleanup;
|
2009-08-14 19:48:55 +00:00
|
|
|
|
|
|
|
if (!new_attrs->ephemeral) {
|
2016-03-18 14:17:25 +00:00
|
|
|
if (secretEnsureDirectory() < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
Add usage type/id as a public API property of virSecret
* include/libvirt/libvirt.h, include/libvirt/libvirt.h.in: Add
virSecretGetUsageType, virSecretGetUsageID and virLookupSecretByUsage
* python/generator.py: Mark virSecretGetUsageType, virSecretGetUsageID
as not throwing exceptions
* qemud/remote.c: Implement dispatch for virLookupSecretByUsage
* qemud/remote_protocol.x: Add usage type & ID as attributes of
remote_nonnull_secret. Add RPC calls for new public APIs
* qemud/remote_dispatch_args.h, qemud/remote_dispatch_prototypes.h,
qemud/remote_dispatch_ret.h, qemud/remote_dispatch_table.h,
qemud/remote_protocol.c, qemud/remote_protocol.h: Re-generate
* src/datatypes.c, src/datatypes.h: Add usageType and usageID as
properties of virSecretPtr
* src/driver.h: Add virLookupSecretByUsage driver entry point
* src/libvirt.c: Implement virSecretGetUsageType, virSecretGetUsageID
and virLookupSecretByUsage
* src/libvirt_public.syms: Export virSecretGetUsageType, virSecretGetUsageID
and virLookupSecretByUsage
* src/remote_internal.c: Implement virLookupSecretByUsage entry
* src/secret_conf.c, src/secret_conf.h: Remove the
virSecretUsageType enum, now in public API. Make volume
path mandatory when parsing XML
* src/secret_driver.c: Enforce usage uniqueness when defining secrets.
Implement virSecretLookupByUsage api method
* src/virsh.c: Include usage for secret-list command
2009-09-11 13:06:15 +00:00
|
|
|
if (backup && backup->ephemeral) {
|
2016-03-18 14:17:25 +00:00
|
|
|
if (virSecretObjSaveData(secret) < 0)
|
2009-08-14 19:48:55 +00:00
|
|
|
goto restore_backup;
|
|
|
|
}
|
2016-03-18 14:17:25 +00:00
|
|
|
|
|
|
|
if (virSecretObjSaveConfig(secret) < 0) {
|
Add usage type/id as a public API property of virSecret
* include/libvirt/libvirt.h, include/libvirt/libvirt.h.in: Add
virSecretGetUsageType, virSecretGetUsageID and virLookupSecretByUsage
* python/generator.py: Mark virSecretGetUsageType, virSecretGetUsageID
as not throwing exceptions
* qemud/remote.c: Implement dispatch for virLookupSecretByUsage
* qemud/remote_protocol.x: Add usage type & ID as attributes of
remote_nonnull_secret. Add RPC calls for new public APIs
* qemud/remote_dispatch_args.h, qemud/remote_dispatch_prototypes.h,
qemud/remote_dispatch_ret.h, qemud/remote_dispatch_table.h,
qemud/remote_protocol.c, qemud/remote_protocol.h: Re-generate
* src/datatypes.c, src/datatypes.h: Add usageType and usageID as
properties of virSecretPtr
* src/driver.h: Add virLookupSecretByUsage driver entry point
* src/libvirt.c: Implement virSecretGetUsageType, virSecretGetUsageID
and virLookupSecretByUsage
* src/libvirt_public.syms: Export virSecretGetUsageType, virSecretGetUsageID
and virLookupSecretByUsage
* src/remote_internal.c: Implement virLookupSecretByUsage entry
* src/secret_conf.c, src/secret_conf.h: Remove the
virSecretUsageType enum, now in public API. Make volume
path mandatory when parsing XML
* src/secret_driver.c: Enforce usage uniqueness when defining secrets.
Implement virSecretLookupByUsage api method
* src/virsh.c: Include usage for secret-list command
2009-09-11 13:06:15 +00:00
|
|
|
if (backup && backup->ephemeral) {
|
2016-03-18 14:17:25 +00:00
|
|
|
/* Undo the virSecretObjSaveData() above; ignore errors */
|
|
|
|
virSecretObjDeleteData(secret);
|
2009-08-14 19:48:55 +00:00
|
|
|
}
|
|
|
|
goto restore_backup;
|
|
|
|
}
|
Add usage type/id as a public API property of virSecret
* include/libvirt/libvirt.h, include/libvirt/libvirt.h.in: Add
virSecretGetUsageType, virSecretGetUsageID and virLookupSecretByUsage
* python/generator.py: Mark virSecretGetUsageType, virSecretGetUsageID
as not throwing exceptions
* qemud/remote.c: Implement dispatch for virLookupSecretByUsage
* qemud/remote_protocol.x: Add usage type & ID as attributes of
remote_nonnull_secret. Add RPC calls for new public APIs
* qemud/remote_dispatch_args.h, qemud/remote_dispatch_prototypes.h,
qemud/remote_dispatch_ret.h, qemud/remote_dispatch_table.h,
qemud/remote_protocol.c, qemud/remote_protocol.h: Re-generate
* src/datatypes.c, src/datatypes.h: Add usageType and usageID as
properties of virSecretPtr
* src/driver.h: Add virLookupSecretByUsage driver entry point
* src/libvirt.c: Implement virSecretGetUsageType, virSecretGetUsageID
and virLookupSecretByUsage
* src/libvirt_public.syms: Export virSecretGetUsageType, virSecretGetUsageID
and virLookupSecretByUsage
* src/remote_internal.c: Implement virLookupSecretByUsage entry
* src/secret_conf.c, src/secret_conf.h: Remove the
virSecretUsageType enum, now in public API. Make volume
path mandatory when parsing XML
* src/secret_driver.c: Enforce usage uniqueness when defining secrets.
Implement virSecretLookupByUsage api method
* src/virsh.c: Include usage for secret-list command
2009-09-11 13:06:15 +00:00
|
|
|
} else if (backup && !backup->ephemeral) {
|
2016-03-07 23:06:57 +00:00
|
|
|
if (virSecretObjDeleteConfig(secret) < 0)
|
2009-08-14 19:48:55 +00:00
|
|
|
goto restore_backup;
|
2016-03-07 23:06:57 +00:00
|
|
|
|
|
|
|
virSecretObjDeleteData(secret);
|
2009-08-14 19:48:55 +00:00
|
|
|
}
|
2009-10-01 14:42:40 +00:00
|
|
|
/* Saved successfully - drop old values */
|
2009-08-14 19:48:55 +00:00
|
|
|
virSecretDefFree(backup);
|
|
|
|
|
Add usage type/id as a public API property of virSecret
* include/libvirt/libvirt.h, include/libvirt/libvirt.h.in: Add
virSecretGetUsageType, virSecretGetUsageID and virLookupSecretByUsage
* python/generator.py: Mark virSecretGetUsageType, virSecretGetUsageID
as not throwing exceptions
* qemud/remote.c: Implement dispatch for virLookupSecretByUsage
* qemud/remote_protocol.x: Add usage type & ID as attributes of
remote_nonnull_secret. Add RPC calls for new public APIs
* qemud/remote_dispatch_args.h, qemud/remote_dispatch_prototypes.h,
qemud/remote_dispatch_ret.h, qemud/remote_dispatch_table.h,
qemud/remote_protocol.c, qemud/remote_protocol.h: Re-generate
* src/datatypes.c, src/datatypes.h: Add usageType and usageID as
properties of virSecretPtr
* src/driver.h: Add virLookupSecretByUsage driver entry point
* src/libvirt.c: Implement virSecretGetUsageType, virSecretGetUsageID
and virLookupSecretByUsage
* src/libvirt_public.syms: Export virSecretGetUsageType, virSecretGetUsageID
and virLookupSecretByUsage
* src/remote_internal.c: Implement virLookupSecretByUsage entry
* src/secret_conf.c, src/secret_conf.h: Remove the
virSecretUsageType enum, now in public API. Make volume
path mandatory when parsing XML
* src/secret_driver.c: Enforce usage uniqueness when defining secrets.
Implement virSecretLookupByUsage api method
* src/virsh.c: Include usage for secret-list command
2009-09-11 13:06:15 +00:00
|
|
|
ret = virGetSecret(conn,
|
2016-03-08 00:22:04 +00:00
|
|
|
new_attrs->uuid,
|
|
|
|
new_attrs->usage_type,
|
|
|
|
virSecretUsageIDForDef(new_attrs));
|
|
|
|
new_attrs = NULL;
|
2009-08-14 19:48:55 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
restore_backup:
|
2016-02-25 11:30:39 +00:00
|
|
|
/* If we have a backup, then secret was defined before, so just restore
|
2016-03-08 00:22:04 +00:00
|
|
|
* the backup. The current (new_attrs) will be handled below.
|
2016-02-25 11:30:39 +00:00
|
|
|
* Otherwise, this is a new secret, thus remove it.
|
|
|
|
*/
|
|
|
|
if (backup)
|
2016-03-08 00:22:04 +00:00
|
|
|
virSecretObjSetDef(secret, backup);
|
2016-02-25 11:30:39 +00:00
|
|
|
else
|
|
|
|
virSecretObjListRemove(driver->secrets, secret);
|
2009-08-14 19:48:55 +00:00
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2009-08-14 19:48:55 +00:00
|
|
|
virSecretDefFree(new_attrs);
|
2016-02-25 11:30:39 +00:00
|
|
|
virSecretObjEndAPI(&secret);
|
2009-08-14 19:48:55 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
2016-02-23 18:44:12 +00:00
|
|
|
secretGetXMLDesc(virSecretPtr obj,
|
|
|
|
unsigned int flags)
|
2009-08-14 19:48:55 +00:00
|
|
|
{
|
|
|
|
char *ret = NULL;
|
2016-02-23 22:40:37 +00:00
|
|
|
virSecretObjPtr secret;
|
2016-03-08 00:22:04 +00:00
|
|
|
virSecretDefPtr def;
|
2009-08-14 19:48:55 +00:00
|
|
|
|
2011-07-06 22:29:02 +00:00
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
2016-02-29 22:15:26 +00:00
|
|
|
if (!(secret = secretObjFromSecret(obj)))
|
2009-08-14 19:48:55 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2016-03-08 00:22:04 +00:00
|
|
|
def = virSecretObjGetDef(secret);
|
|
|
|
if (virSecretGetXMLDescEnsureACL(obj->conn, def) < 0)
|
2013-04-23 10:56:22 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2016-03-08 00:22:04 +00:00
|
|
|
ret = virSecretDefFormat(def);
|
2009-08-14 19:48:55 +00:00
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2016-02-25 11:30:39 +00:00
|
|
|
virSecretObjEndAPI(&secret);
|
2009-08-14 19:48:55 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2016-02-23 18:44:12 +00:00
|
|
|
secretSetValue(virSecretPtr obj,
|
|
|
|
const unsigned char *value,
|
|
|
|
size_t value_size,
|
|
|
|
unsigned int flags)
|
2009-08-14 19:48:55 +00:00
|
|
|
{
|
|
|
|
int ret = -1;
|
2016-02-23 22:40:37 +00:00
|
|
|
virSecretObjPtr secret;
|
2016-03-08 00:22:04 +00:00
|
|
|
virSecretDefPtr def;
|
2009-08-14 19:48:55 +00:00
|
|
|
|
2011-07-06 22:29:02 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2016-02-29 22:15:26 +00:00
|
|
|
if (!(secret = secretObjFromSecret(obj)))
|
2009-08-14 19:48:55 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2016-03-08 00:22:04 +00:00
|
|
|
def = virSecretObjGetDef(secret);
|
|
|
|
if (virSecretSetValueEnsureACL(obj->conn, def) < 0)
|
2013-04-23 10:56:22 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2016-03-08 00:40:58 +00:00
|
|
|
if (secretEnsureDirectory() < 0)
|
|
|
|
goto cleanup;
|
2016-03-18 14:17:25 +00:00
|
|
|
|
2016-03-08 00:40:58 +00:00
|
|
|
if (virSecretObjSetValue(secret, value, value_size) < 0)
|
|
|
|
goto cleanup;
|
2009-08-14 19:48:55 +00:00
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2016-02-25 11:30:39 +00:00
|
|
|
virSecretObjEndAPI(&secret);
|
2009-08-14 19:48:55 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned char *
|
2016-02-23 18:44:12 +00:00
|
|
|
secretGetValue(virSecretPtr obj,
|
|
|
|
size_t *value_size,
|
|
|
|
unsigned int flags,
|
libvirt: do not mix internal flags into public API
There were two API in driver.c that were silently masking flags
bits prior to calling out to the drivers, and several others
that were explicitly masking flags bits. This is not
forward-compatible - if we ever have that many flags in the
future, then talking to an old server that masks out the
flags would be indistinguishable from talking to a new server
that can honor the flag. In general, libvirt.c should forward
_all_ flags on to drivers, and only the drivers should reject
unknown flags.
In the case of virDrvSecretGetValue, the solution is to separate
the internal driver callback function to have two parameters
instead of one, with only one parameter affected by the public
API. In the case of virDomainGetXMLDesc, it turns out that
no one was ever mixing VIR_DOMAIN_XML_INTERNAL_STATUS with
the dumpxml path in the first place; that internal flag was
only used in saving and restoring state files, which happened
to be in functions internal to a single file, so there is no
mixing of the internal flag with a public flags argument.
Additionally, virDomainMemoryStats passed a flags argument
over RPC, but not to the driver.
* src/driver.h (VIR_DOMAIN_XML_FLAGS_MASK)
(VIR_SECRET_GET_VALUE_FLAGS_MASK): Delete.
(virDrvSecretGetValue): Separate out internal flags.
(virDrvDomainMemoryStats): Provide missing flags argument.
* src/driver.c (verify): Drop unused check.
* src/conf/domain_conf.h (virDomainObjParseFile): Delete
declaration.
(virDomainXMLInternalFlags): Move...
* src/conf/domain_conf.c: ...here. Delete redundant include.
(virDomainObjParseFile): Make static.
* src/libvirt.c (virDomainGetXMLDesc, virSecretGetValue): Update
clients.
(virDomainMemoryPeek, virInterfaceGetXMLDesc)
(virDomainMemoryStats, virDomainBlockPeek, virNetworkGetXMLDesc)
(virStoragePoolGetXMLDesc, virStorageVolGetXMLDesc)
(virNodeNumOfDevices, virNodeListDevices, virNWFilterGetXMLDesc):
Don't mask unknown flags.
* src/interface/netcf_driver.c (interfaceGetXMLDesc): Reject
unknown flags.
* src/secret/secret_driver.c (secretGetValue): Update clients.
* src/remote/remote_driver.c (remoteSecretGetValue)
(remoteDomainMemoryStats): Likewise.
* src/qemu/qemu_process.c (qemuProcessGetVolumeQcowPassphrase):
Likewise.
* src/qemu/qemu_driver.c (qemudDomainMemoryStats): Likewise.
* daemon/remote.c (remoteDispatchDomainMemoryStats): Likewise.
2011-07-13 21:31:56 +00:00
|
|
|
unsigned int internalFlags)
|
2009-08-14 19:48:55 +00:00
|
|
|
{
|
|
|
|
unsigned char *ret = NULL;
|
2016-02-23 22:40:37 +00:00
|
|
|
virSecretObjPtr secret;
|
2016-03-08 00:22:04 +00:00
|
|
|
virSecretDefPtr def;
|
2009-08-14 19:48:55 +00:00
|
|
|
|
libvirt: do not mix internal flags into public API
There were two API in driver.c that were silently masking flags
bits prior to calling out to the drivers, and several others
that were explicitly masking flags bits. This is not
forward-compatible - if we ever have that many flags in the
future, then talking to an old server that masks out the
flags would be indistinguishable from talking to a new server
that can honor the flag. In general, libvirt.c should forward
_all_ flags on to drivers, and only the drivers should reject
unknown flags.
In the case of virDrvSecretGetValue, the solution is to separate
the internal driver callback function to have two parameters
instead of one, with only one parameter affected by the public
API. In the case of virDomainGetXMLDesc, it turns out that
no one was ever mixing VIR_DOMAIN_XML_INTERNAL_STATUS with
the dumpxml path in the first place; that internal flag was
only used in saving and restoring state files, which happened
to be in functions internal to a single file, so there is no
mixing of the internal flag with a public flags argument.
Additionally, virDomainMemoryStats passed a flags argument
over RPC, but not to the driver.
* src/driver.h (VIR_DOMAIN_XML_FLAGS_MASK)
(VIR_SECRET_GET_VALUE_FLAGS_MASK): Delete.
(virDrvSecretGetValue): Separate out internal flags.
(virDrvDomainMemoryStats): Provide missing flags argument.
* src/driver.c (verify): Drop unused check.
* src/conf/domain_conf.h (virDomainObjParseFile): Delete
declaration.
(virDomainXMLInternalFlags): Move...
* src/conf/domain_conf.c: ...here. Delete redundant include.
(virDomainObjParseFile): Make static.
* src/libvirt.c (virDomainGetXMLDesc, virSecretGetValue): Update
clients.
(virDomainMemoryPeek, virInterfaceGetXMLDesc)
(virDomainMemoryStats, virDomainBlockPeek, virNetworkGetXMLDesc)
(virStoragePoolGetXMLDesc, virStorageVolGetXMLDesc)
(virNodeNumOfDevices, virNodeListDevices, virNWFilterGetXMLDesc):
Don't mask unknown flags.
* src/interface/netcf_driver.c (interfaceGetXMLDesc): Reject
unknown flags.
* src/secret/secret_driver.c (secretGetValue): Update clients.
* src/remote/remote_driver.c (remoteSecretGetValue)
(remoteDomainMemoryStats): Likewise.
* src/qemu/qemu_process.c (qemuProcessGetVolumeQcowPassphrase):
Likewise.
* src/qemu/qemu_driver.c (qemudDomainMemoryStats): Likewise.
* daemon/remote.c (remoteDispatchDomainMemoryStats): Likewise.
2011-07-13 21:31:56 +00:00
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
2016-02-29 22:15:26 +00:00
|
|
|
if (!(secret = secretObjFromSecret(obj)))
|
2009-08-14 19:48:55 +00:00
|
|
|
goto cleanup;
|
Add usage type/id as a public API property of virSecret
* include/libvirt/libvirt.h, include/libvirt/libvirt.h.in: Add
virSecretGetUsageType, virSecretGetUsageID and virLookupSecretByUsage
* python/generator.py: Mark virSecretGetUsageType, virSecretGetUsageID
as not throwing exceptions
* qemud/remote.c: Implement dispatch for virLookupSecretByUsage
* qemud/remote_protocol.x: Add usage type & ID as attributes of
remote_nonnull_secret. Add RPC calls for new public APIs
* qemud/remote_dispatch_args.h, qemud/remote_dispatch_prototypes.h,
qemud/remote_dispatch_ret.h, qemud/remote_dispatch_table.h,
qemud/remote_protocol.c, qemud/remote_protocol.h: Re-generate
* src/datatypes.c, src/datatypes.h: Add usageType and usageID as
properties of virSecretPtr
* src/driver.h: Add virLookupSecretByUsage driver entry point
* src/libvirt.c: Implement virSecretGetUsageType, virSecretGetUsageID
and virLookupSecretByUsage
* src/libvirt_public.syms: Export virSecretGetUsageType, virSecretGetUsageID
and virLookupSecretByUsage
* src/remote_internal.c: Implement virLookupSecretByUsage entry
* src/secret_conf.c, src/secret_conf.h: Remove the
virSecretUsageType enum, now in public API. Make volume
path mandatory when parsing XML
* src/secret_driver.c: Enforce usage uniqueness when defining secrets.
Implement virSecretLookupByUsage api method
* src/virsh.c: Include usage for secret-list command
2009-09-11 13:06:15 +00:00
|
|
|
|
2016-03-08 00:22:04 +00:00
|
|
|
def = virSecretObjGetDef(secret);
|
|
|
|
if (virSecretGetValueEnsureACL(obj->conn, def) < 0)
|
2013-04-23 10:56:22 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
libvirt: do not mix internal flags into public API
There were two API in driver.c that were silently masking flags
bits prior to calling out to the drivers, and several others
that were explicitly masking flags bits. This is not
forward-compatible - if we ever have that many flags in the
future, then talking to an old server that masks out the
flags would be indistinguishable from talking to a new server
that can honor the flag. In general, libvirt.c should forward
_all_ flags on to drivers, and only the drivers should reject
unknown flags.
In the case of virDrvSecretGetValue, the solution is to separate
the internal driver callback function to have two parameters
instead of one, with only one parameter affected by the public
API. In the case of virDomainGetXMLDesc, it turns out that
no one was ever mixing VIR_DOMAIN_XML_INTERNAL_STATUS with
the dumpxml path in the first place; that internal flag was
only used in saving and restoring state files, which happened
to be in functions internal to a single file, so there is no
mixing of the internal flag with a public flags argument.
Additionally, virDomainMemoryStats passed a flags argument
over RPC, but not to the driver.
* src/driver.h (VIR_DOMAIN_XML_FLAGS_MASK)
(VIR_SECRET_GET_VALUE_FLAGS_MASK): Delete.
(virDrvSecretGetValue): Separate out internal flags.
(virDrvDomainMemoryStats): Provide missing flags argument.
* src/driver.c (verify): Drop unused check.
* src/conf/domain_conf.h (virDomainObjParseFile): Delete
declaration.
(virDomainXMLInternalFlags): Move...
* src/conf/domain_conf.c: ...here. Delete redundant include.
(virDomainObjParseFile): Make static.
* src/libvirt.c (virDomainGetXMLDesc, virSecretGetValue): Update
clients.
(virDomainMemoryPeek, virInterfaceGetXMLDesc)
(virDomainMemoryStats, virDomainBlockPeek, virNetworkGetXMLDesc)
(virStoragePoolGetXMLDesc, virStorageVolGetXMLDesc)
(virNodeNumOfDevices, virNodeListDevices, virNWFilterGetXMLDesc):
Don't mask unknown flags.
* src/interface/netcf_driver.c (interfaceGetXMLDesc): Reject
unknown flags.
* src/secret/secret_driver.c (secretGetValue): Update clients.
* src/remote/remote_driver.c (remoteSecretGetValue)
(remoteDomainMemoryStats): Likewise.
* src/qemu/qemu_process.c (qemuProcessGetVolumeQcowPassphrase):
Likewise.
* src/qemu/qemu_driver.c (qemudDomainMemoryStats): Likewise.
* daemon/remote.c (remoteDispatchDomainMemoryStats): Likewise.
2011-07-13 21:31:56 +00:00
|
|
|
if ((internalFlags & VIR_SECRET_GET_VALUE_INTERNAL_CALL) == 0 &&
|
2016-03-08 00:22:04 +00:00
|
|
|
def->private) {
|
2012-09-18 10:01:46 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_SECRET, "%s",
|
2012-07-18 11:40:16 +00:00
|
|
|
_("secret is private"));
|
2009-08-14 19:48:55 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2016-03-08 00:40:58 +00:00
|
|
|
if (!(ret = virSecretObjGetValue(secret)))
|
2009-08-14 19:48:55 +00:00
|
|
|
goto cleanup;
|
2016-03-08 00:40:58 +00:00
|
|
|
|
|
|
|
*value_size = virSecretObjGetValueSize(secret);
|
2009-08-14 19:48:55 +00:00
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2016-02-25 11:30:39 +00:00
|
|
|
virSecretObjEndAPI(&secret);
|
2009-08-14 19:48:55 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
secretUndefine(virSecretPtr obj)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
2016-02-23 22:40:37 +00:00
|
|
|
virSecretObjPtr secret;
|
2016-03-08 00:22:04 +00:00
|
|
|
virSecretDefPtr def;
|
2009-08-14 19:48:55 +00:00
|
|
|
|
2016-02-29 22:15:26 +00:00
|
|
|
if (!(secret = secretObjFromSecret(obj)))
|
2009-08-14 19:48:55 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2016-03-08 00:22:04 +00:00
|
|
|
def = virSecretObjGetDef(secret);
|
|
|
|
if (virSecretUndefineEnsureACL(obj->conn, def) < 0)
|
2013-04-23 10:56:22 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2016-03-07 23:06:57 +00:00
|
|
|
if (virSecretObjDeleteConfig(secret) < 0)
|
Add usage type/id as a public API property of virSecret
* include/libvirt/libvirt.h, include/libvirt/libvirt.h.in: Add
virSecretGetUsageType, virSecretGetUsageID and virLookupSecretByUsage
* python/generator.py: Mark virSecretGetUsageType, virSecretGetUsageID
as not throwing exceptions
* qemud/remote.c: Implement dispatch for virLookupSecretByUsage
* qemud/remote_protocol.x: Add usage type & ID as attributes of
remote_nonnull_secret. Add RPC calls for new public APIs
* qemud/remote_dispatch_args.h, qemud/remote_dispatch_prototypes.h,
qemud/remote_dispatch_ret.h, qemud/remote_dispatch_table.h,
qemud/remote_protocol.c, qemud/remote_protocol.h: Re-generate
* src/datatypes.c, src/datatypes.h: Add usageType and usageID as
properties of virSecretPtr
* src/driver.h: Add virLookupSecretByUsage driver entry point
* src/libvirt.c: Implement virSecretGetUsageType, virSecretGetUsageID
and virLookupSecretByUsage
* src/libvirt_public.syms: Export virSecretGetUsageType, virSecretGetUsageID
and virLookupSecretByUsage
* src/remote_internal.c: Implement virLookupSecretByUsage entry
* src/secret_conf.c, src/secret_conf.h: Remove the
virSecretUsageType enum, now in public API. Make volume
path mandatory when parsing XML
* src/secret_driver.c: Enforce usage uniqueness when defining secrets.
Implement virSecretLookupByUsage api method
* src/virsh.c: Include usage for secret-list command
2009-09-11 13:06:15 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2016-03-07 23:06:57 +00:00
|
|
|
virSecretObjDeleteData(secret);
|
|
|
|
|
2016-02-25 11:30:39 +00:00
|
|
|
virSecretObjListRemove(driver->secrets, secret);
|
2009-08-14 19:48:55 +00:00
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2016-02-25 11:30:39 +00:00
|
|
|
virSecretObjEndAPI(&secret);
|
2009-08-14 19:48:55 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
secretStateCleanup(void)
|
2009-08-14 19:48:55 +00:00
|
|
|
{
|
2016-02-25 11:30:39 +00:00
|
|
|
if (!driver)
|
2009-08-14 19:48:55 +00:00
|
|
|
return -1;
|
|
|
|
|
2014-11-07 10:28:58 +00:00
|
|
|
secretDriverLock();
|
2009-08-14 19:48:55 +00:00
|
|
|
|
2016-02-25 11:30:39 +00:00
|
|
|
virObjectUnref(driver->secrets);
|
2016-02-23 23:27:21 +00:00
|
|
|
VIR_FREE(driver->configDir);
|
2009-08-14 19:48:55 +00:00
|
|
|
|
2014-11-07 10:28:58 +00:00
|
|
|
secretDriverUnlock();
|
|
|
|
virMutexDestroy(&driver->lock);
|
|
|
|
VIR_FREE(driver);
|
2009-08-14 19:48:55 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
secretStateInitialize(bool privileged,
|
|
|
|
virStateInhibitCallback callback ATTRIBUTE_UNUSED,
|
|
|
|
void *opaque ATTRIBUTE_UNUSED)
|
2009-08-14 19:48:55 +00:00
|
|
|
{
|
|
|
|
char *base = NULL;
|
|
|
|
|
2014-11-07 10:28:58 +00:00
|
|
|
if (VIR_ALLOC(driver) < 0)
|
2009-08-14 19:48:55 +00:00
|
|
|
return -1;
|
|
|
|
|
2014-11-07 10:28:58 +00:00
|
|
|
if (virMutexInit(&driver->lock) < 0) {
|
|
|
|
VIR_FREE(driver);
|
2009-08-14 19:48:55 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2014-11-07 10:28:58 +00:00
|
|
|
secretDriverLock();
|
2009-08-14 19:48:55 +00:00
|
|
|
|
|
|
|
if (privileged) {
|
2013-05-03 12:48:16 +00:00
|
|
|
if (VIR_STRDUP(base, SYSCONFDIR "/libvirt") < 0)
|
|
|
|
goto error;
|
2009-08-14 19:48:55 +00:00
|
|
|
} else {
|
2016-02-23 18:44:12 +00:00
|
|
|
if (!(base = virGetUserConfigDirectory()))
|
2009-08-14 19:48:55 +00:00
|
|
|
goto error;
|
|
|
|
}
|
2016-02-23 23:27:21 +00:00
|
|
|
if (virAsprintf(&driver->configDir, "%s/secrets", base) < 0)
|
2013-07-04 10:15:29 +00:00
|
|
|
goto error;
|
2009-08-14 19:48:55 +00:00
|
|
|
VIR_FREE(base);
|
|
|
|
|
2016-02-25 11:30:39 +00:00
|
|
|
if (!(driver->secrets = virSecretObjListNew()))
|
|
|
|
goto error;
|
|
|
|
|
2016-03-02 18:10:54 +00:00
|
|
|
if (virSecretLoadAllConfigs(driver->secrets, driver->configDir) < 0)
|
2009-08-14 19:48:55 +00:00
|
|
|
goto error;
|
|
|
|
|
2014-11-07 10:28:58 +00:00
|
|
|
secretDriverUnlock();
|
2009-08-14 19:48:55 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
error:
|
|
|
|
VIR_FREE(base);
|
2014-11-07 10:28:58 +00:00
|
|
|
secretDriverUnlock();
|
2013-04-23 12:50:18 +00:00
|
|
|
secretStateCleanup();
|
2009-08-14 19:48:55 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
secretStateReload(void)
|
2009-08-14 19:48:55 +00:00
|
|
|
{
|
2014-11-07 10:28:58 +00:00
|
|
|
if (!driver)
|
2009-08-14 19:48:55 +00:00
|
|
|
return -1;
|
|
|
|
|
2014-11-07 10:28:58 +00:00
|
|
|
secretDriverLock();
|
2009-08-14 19:48:55 +00:00
|
|
|
|
2016-03-02 18:10:54 +00:00
|
|
|
ignore_value(virSecretLoadAllConfigs(driver->secrets, driver->configDir));
|
2009-08-14 19:48:55 +00:00
|
|
|
|
2014-11-07 10:28:58 +00:00
|
|
|
secretDriverUnlock();
|
2009-08-14 19:48:55 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virSecretDriver secretDriver = {
|
|
|
|
.name = "secret",
|
2013-04-23 12:50:18 +00:00
|
|
|
.connectNumOfSecrets = secretConnectNumOfSecrets, /* 0.7.1 */
|
|
|
|
.connectListSecrets = secretConnectListSecrets, /* 0.7.1 */
|
|
|
|
.connectListAllSecrets = secretConnectListAllSecrets, /* 0.10.2 */
|
2013-04-22 17:26:01 +00:00
|
|
|
.secretLookupByUUID = secretLookupByUUID, /* 0.7.1 */
|
|
|
|
.secretLookupByUsage = secretLookupByUsage, /* 0.7.1 */
|
|
|
|
.secretDefineXML = secretDefineXML, /* 0.7.1 */
|
|
|
|
.secretGetXMLDesc = secretGetXMLDesc, /* 0.7.1 */
|
|
|
|
.secretSetValue = secretSetValue, /* 0.7.1 */
|
|
|
|
.secretGetValue = secretGetValue, /* 0.7.1 */
|
|
|
|
.secretUndefine = secretUndefine, /* 0.7.1 */
|
2009-08-14 19:48:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static virStateDriver stateDriver = {
|
2015-01-20 16:16:26 +00:00
|
|
|
.name = "secret",
|
2013-04-23 12:50:18 +00:00
|
|
|
.stateInitialize = secretStateInitialize,
|
|
|
|
.stateCleanup = secretStateCleanup,
|
|
|
|
.stateReload = secretStateReload,
|
2009-08-14 19:48:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int
|
|
|
|
secretRegister(void)
|
|
|
|
{
|
2015-01-20 16:16:26 +00:00
|
|
|
if (virSetSharedSecretDriver(&secretDriver) < 0)
|
2014-03-17 13:35:42 +00:00
|
|
|
return -1;
|
|
|
|
if (virRegisterStateDriver(&stateDriver) < 0)
|
|
|
|
return -1;
|
2009-08-14 19:48:55 +00:00
|
|
|
return 0;
|
|
|
|
}
|