[libvirt] [dbus PATCH 00/13] Secret APIs

Katerina Koukiou (13): Introduce Secret Interface Implement ListSecrets method for Connect Interface Register Secret Lifecycle Events Implement UUID property for Secret Interface Implement UsageID property for Secret Interface Implement UsageType property for Secret Interface Implement GetXMLDesc method for Secret Interface Implement SecretLookupByUUID method for Connect Interface Implement SecretLookupByUsage method for Connect Interface Implement Undefine method for Secret Interface Implement GetValue method for Secret Interface Implement SetValue method for Secret Interface Implement SecretDefineXML method for Connect Interface data/Makefile.am | 1 + data/org.libvirt.Connect.xml | 33 ++++++ data/org.libvirt.Secret.xml | 44 +++++++ src/Makefile.am | 1 + src/connect.c | 145 +++++++++++++++++++++++ src/connect.h | 2 + src/events.c | 42 +++++++ src/secret.c | 270 +++++++++++++++++++++++++++++++++++++++++++ src/secret.h | 9 ++ src/util.c | 33 ++++++ src/util.h | 16 +++ 11 files changed, 596 insertions(+) create mode 100644 data/org.libvirt.Secret.xml create mode 100644 src/secret.c create mode 100644 src/secret.h -- 2.15.0

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/Makefile.am | 1 + data/org.libvirt.Secret.xml | 7 +++++ src/Makefile.am | 1 + src/connect.c | 6 +++++ src/connect.h | 1 + src/secret.c | 64 +++++++++++++++++++++++++++++++++++++++++++++ src/secret.h | 9 +++++++ src/util.c | 33 +++++++++++++++++++++++ src/util.h | 16 ++++++++++++ 9 files changed, 138 insertions(+) create mode 100644 data/org.libvirt.Secret.xml create mode 100644 src/secret.c create mode 100644 src/secret.h diff --git a/data/Makefile.am b/data/Makefile.am index 4d2af45..5a085cd 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -22,6 +22,7 @@ interfaces_files = \ org.libvirt.Connect.xml \ org.libvirt.Domain.xml \ org.libvirt.Network.xml \ + org.libvirt.Secret.xml \ org.libvirt.StoragePool.xml interfacesdir = $(DBUS_INTERFACES_DIR) interfaces_DATA = $(interfaces_files) diff --git a/data/org.libvirt.Secret.xml b/data/org.libvirt.Secret.xml new file mode 100644 index 0000000..1cc1e31 --- /dev/null +++ b/data/org.libvirt.Secret.xml @@ -0,0 +1,7 @@ +<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" +"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> + +<node name="/org/libvirt/secret"> + <interface name="org.libvirt.Secret"> + </interface> +</node> diff --git a/src/Makefile.am b/src/Makefile.am index 5e082da..6b2887b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -10,6 +10,7 @@ DAEMON_SOURCES = \ events.c events.h \ gdbus.c gdbus.h \ network.c network.h \ + secret.c secret.h \ storagepool.c storagepool.h EXTRA_DIST = \ diff --git a/src/connect.c b/src/connect.c index 79b5d8f..e56089a 100644 --- a/src/connect.c +++ b/src/connect.c @@ -2,6 +2,7 @@ #include "domain.h" #include "events.h" #include "network.h" +#include "secret.h" #include "storagepool.h" #include "util.h" @@ -1217,6 +1218,7 @@ virtDBusConnectFree(virtDBusConnect *connect) g_free(connect->domainPath); g_free(connect->networkPath); + g_free(connect->secretPath); g_free(connect->storagePoolPath); g_free(connect); } @@ -1270,6 +1272,10 @@ virtDBusConnectNew(virtDBusConnect **connectp, if (error && *error) return; + virtDBusSecretRegister(connect, error); + if (error && *error) + return; + virtDBusStoragePoolRegister(connect, error); if (error && *error) return; diff --git a/src/connect.h b/src/connect.h index b4df048..5c83cc6 100644 --- a/src/connect.h +++ b/src/connect.h @@ -14,6 +14,7 @@ struct virtDBusConnect { const gchar *connectPath; gchar *domainPath; gchar *networkPath; + gchar *secretPath; gchar *storagePoolPath; virConnectPtr connection; GMutex lock; diff --git a/src/secret.c b/src/secret.c new file mode 100644 index 0000000..c7cbb02 --- /dev/null +++ b/src/secret.c @@ -0,0 +1,64 @@ +#include "secret.h" +#include "util.h" + +#include <libvirt/libvirt.h> + +static virtDBusGDBusPropertyTable virtDBusSecretPropertyTable[] = { + { 0 } +}; + +static virtDBusGDBusMethodTable virtDBusSecretMethodTable[] = { + { 0 } +}; + +static gchar ** +virtDBusSecretEnumerate(gpointer userData) +{ + virtDBusConnect *connect = userData; + g_autoptr(virSecretPtr) secrets = NULL; + gint num = 0; + gchar **ret = NULL; + + if (!virtDBusConnectOpen(connect, NULL)) + return NULL; + + num = virConnectListAllSecrets(connect->connection, &secrets, 0); + if (num < 0) + return NULL; + + if (num == 0) + return NULL; + + ret = g_new0(gchar *, num + 1); + + for (gint i = 0; i < num; i++) { + ret[i] = virtDBusUtilBusPathForVirSecret(secrets[i], + connect->secretPath); + } + + return ret; +} + +static GDBusInterfaceInfo *interfaceInfo; + +void +virtDBusSecretRegister(virtDBusConnect *connect, + GError **error) +{ + connect->secretPath = g_strdup_printf("%s/secret", connect->connectPath); + + if (!interfaceInfo) { + interfaceInfo = virtDBusGDBusLoadIntrospectData(VIRT_DBUS_SECRET_INTERFACE, + error); + if (!interfaceInfo) + return; + } + + virtDBusGDBusRegisterSubtree(connect->bus, + connect->secretPath, + interfaceInfo, + virtDBusSecretEnumerate, + virtDBusSecretMethodTable, + virtDBusSecretPropertyTable, + connect); +} diff --git a/src/secret.h b/src/secret.h new file mode 100644 index 0000000..4b3846b --- /dev/null +++ b/src/secret.h @@ -0,0 +1,9 @@ +#pragma once + +#include "connect.h" + +#define VIRT_DBUS_SECRET_INTERFACE "org.libvirt.Secret" + +void +virtDBusSecretRegister(virtDBusConnect *connect, + GError **error); diff --git a/src/util.c b/src/util.c index e90be3b..9dd901c 100644 --- a/src/util.c +++ b/src/util.c @@ -256,6 +256,39 @@ virtDBusUtilStringListFree(virtDBusCharArray *item) g_free(item); } +virSecretPtr +virtDBusUtilVirSecretFromBusPath(virConnectPtr connection, + const gchar *path, + const gchar *secretPath) +{ + g_autofree gchar *name = NULL; + gsize prefixLen = strlen(secretPath) + 1; + + name = virtDBusUtilDecodeUUID(path + prefixLen); + + return virSecretLookupByUUIDString(connection, name); +} + +gchar * +virtDBusUtilBusPathForVirSecret(virSecretPtr secret, + const gchar *secretPath) +{ + gchar uuid[VIR_UUID_STRING_BUFLEN] = ""; + g_autofree gchar *newUuid = NULL; + virSecretGetUUIDString(secret, uuid); + newUuid = virtDBusUtilEncodeUUID(uuid); + return g_strdup_printf("%s/%s", secretPath, newUuid); +} + +void +virtDBusUtilVirSecretListFree(virSecretPtr *secrets) +{ + for (gint i = 0; secrets[i] != NULL; i++) + virSecretFree(secrets[i]); + + g_free(secrets); +} + virStoragePoolPtr virtDBusUtilVirStoragePoolFromBusPath(virConnectPtr connection, const gchar *path, diff --git a/src/util.h b/src/util.h index d932b66..2f37933 100644 --- a/src/util.h +++ b/src/util.h @@ -79,6 +79,22 @@ virtDBusUtilStringListFree(virtDBusCharArray *item); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virtDBusCharArray, virtDBusUtilStringListFree); +virSecretPtr +virtDBusUtilVirSecretFromBusPath(virConnectPtr connection, + const gchar *path, + const gchar *secretPath); + +gchar * +virtDBusUtilBusPathForVirSecret(virSecretPtr secret, + const gchar *secretPath); + +void +virtDBusUtilVirSecretListFree(virSecretPtr *secrets); + +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virSecret, virSecretFree); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virSecretPtr, + virtDBusUtilVirSecretListFree); + virStoragePoolPtr virtDBusUtilVirStoragePoolFromBusPath(virConnectPtr connection, const gchar *path, -- 2.15.0

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 6 ++++++ src/connect.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index 0c009cd..df91108 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -145,6 +145,12 @@ <arg name="flags" type="u" direction="in"/> <arg name="networks" type="ao" direction="out"/> </method> + <method name="ListSecrets"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-secret.html#virConnectListAllSecrets"/> + <arg name="flags" type="u" direction="in"/> + <arg name="secrets" type="ao" direction="out"/> + </method> <method name="ListStoragePools"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virConnectListAllStoragePools"/> diff --git a/src/connect.c b/src/connect.c index e56089a..5732d8a 100644 --- a/src/connect.c +++ b/src/connect.c @@ -720,6 +720,42 @@ virtDBusConnectListNetworks(GVariant *inArgs, *outArgs = g_variant_new_tuple(&gnetworks, 1); } +static void +virtDBusConnectListSecrets(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath G_GNUC_UNUSED, + gpointer userData, + GVariant **outArgs, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virSecretPtr) secrets = NULL; + guint flags; + GVariantBuilder builder; + GVariant *gsecrets; + + g_variant_get(inArgs, "(u)", &flags); + + if (!virtDBusConnectOpen(connect, error)) + return; + + if (virConnectListAllSecrets(connect->connection, &secrets, flags) < 0) + return virtDBusUtilSetLastVirtError(error); + + g_variant_builder_init(&builder, G_VARIANT_TYPE("ao")); + + for (gint i = 0; secrets[i]; i++) { + g_autofree gchar *path = NULL; + path = virtDBusUtilBusPathForVirSecret(secrets[i], connect->secretPath); + + g_variant_builder_add(&builder, "o", path); + } + + gsecrets = g_variant_builder_end(&builder); + *outArgs = g_variant_new_tuple(&gsecrets, 1); +} + static void virtDBusConnectListStoragePools(GVariant *inArgs, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -1191,6 +1227,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = { { "GetSysinfo", virtDBusConnectGetSysinfo }, { "ListDomains", virtDBusConnectListDomains }, { "ListNetworks", virtDBusConnectListNetworks }, + { "ListSecrets", virtDBusConnectListSecrets }, { "ListStoragePools", virtDBusConnectListStoragePools }, { "NetworkCreateXML", virtDBusConnectNetworkCreateXML }, { "NetworkDefineXML", virtDBusConnectNetworkDefineXML }, -- 2.15.0

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 7 +++++++ src/connect.c | 13 +++++++++++++ src/connect.h | 1 + src/events.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index df91108..3aae9fe 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -248,6 +248,13 @@ <arg name="network" type="o"/> <arg name="event" type="u"/> </signal> + <signal name="SecretEvent"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-secret.html#virConnectSecretEventLifecycleCallback"/> + <arg name="secret" type="o"/> + <arg name="event" type="u"/> + <arg name="detail" type="u"/> + </signal> <signal name="StoragePoolEvent"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virConnectStoragePoolEventLifecycleCallback"/> diff --git a/src/connect.c b/src/connect.c index 5732d8a..6b96888 100644 --- a/src/connect.c +++ b/src/connect.c @@ -61,6 +61,16 @@ virtDBusConnectClose(virtDBusConnect *connect, } } + for (gint i = 0; i < VIR_SECRET_EVENT_ID_LAST; i++) { + if (connect->secretCallbackIds[i] >= 0) { + if (deregisterEvents) { + virConnectSecretEventDeregisterAny(connect->connection, + connect->secretCallbackIds[i]); + } + connect->secretCallbackIds[i] = -1; + } + } + for (gint i = 0; i < VIR_STORAGE_POOL_EVENT_ID_LAST; i++) { if (connect->storagePoolCallbackIds[i] >= 0) { if (deregisterEvents) { @@ -1287,6 +1297,9 @@ virtDBusConnectNew(virtDBusConnect **connectp, for (gint i = 0; i < VIR_NETWORK_EVENT_ID_LAST; i++) connect->networkCallbackIds[i] = -1; + for (gint i = 0; i < VIR_SECRET_EVENT_ID_LAST; i++) + connect->secretCallbackIds[i] = -1; + for (gint i = 0; i < VIR_STORAGE_POOL_EVENT_ID_LAST; i++) connect->storagePoolCallbackIds[i] = -1; diff --git a/src/connect.h b/src/connect.h index 5c83cc6..08e1b68 100644 --- a/src/connect.h +++ b/src/connect.h @@ -21,6 +21,7 @@ struct virtDBusConnect { gint domainCallbackIds[VIR_DOMAIN_EVENT_ID_LAST]; gint networkCallbackIds[VIR_NETWORK_EVENT_ID_LAST]; + gint secretCallbackIds[VIR_SECRET_EVENT_ID_LAST]; gint storagePoolCallbackIds[VIR_STORAGE_POOL_EVENT_ID_LAST]; }; typedef struct virtDBusConnect virtDBusConnect; diff --git a/src/events.c b/src/events.c index 04967c2..53cd725 100644 --- a/src/events.c +++ b/src/events.c @@ -143,6 +143,29 @@ virtDBusEventsNetworkLifecycle(virConnectPtr connection G_GNUC_UNUSED, return 0; } +static gint +virtDBusEventsSecretLifecycle(virConnectPtr connection G_GNUC_UNUSED, + virSecretPtr secret, + gint event, + gint detail, + gpointer opaque) +{ + virtDBusConnect *connect = opaque; + g_autofree gchar *path = NULL; + + path = virtDBusUtilBusPathForVirSecret(secret, connect->secretPath); + + g_dbus_connection_emit_signal(connect->bus, + NULL, + connect->connectPath, + VIRT_DBUS_CONNECT_INTERFACE, + "SecretEvent", + g_variant_new("(ouu)", path, event, detail), + NULL); + + return 0; +} + static gint virtDBusEventsStoragePoolLifecycle(virConnectPtr connection G_GNUC_UNUSED, virStoragePoolPtr storagePool, @@ -197,6 +220,21 @@ virtDBusEventsRegisterNetworkEvent(virtDBusConnect *connect, NULL); } +static void +virtDBusEventsRegisterSecretEvent(virtDBusConnect *connect, + gint id, + virConnectSecretEventGenericCallback callback) +{ + g_assert(connect->secretCallbackIds[id] == -1); + + connect->secretCallbackIds[id] = virConnectSecretEventRegisterAny(connect->connection, + NULL, + id, + VIR_SECRET_EVENT_CALLBACK(callback), + connect, + NULL); +} + static void virtDBusEventsRegisterStoragePoolEvent(virtDBusConnect *connect, gint id, @@ -239,6 +277,10 @@ virtDBusEventsRegister(virtDBusConnect *connect) VIR_NETWORK_EVENT_ID_LIFECYCLE, VIR_NETWORK_EVENT_CALLBACK(virtDBusEventsNetworkLifecycle)); + virtDBusEventsRegisterSecretEvent(connect, + VIR_SECRET_EVENT_ID_LIFECYCLE, + VIR_SECRET_EVENT_CALLBACK(virtDBusEventsSecretLifecycle)); + virtDBusEventsRegisterStoragePoolEvent(connect, VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE, VIR_STORAGE_POOL_EVENT_CALLBACK(virtDBusEventsStoragePoolLifecycle)); -- 2.15.0

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Secret.xml | 5 +++++ src/secret.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/data/org.libvirt.Secret.xml b/data/org.libvirt.Secret.xml index 1cc1e31..8ee6f0c 100644 --- a/data/org.libvirt.Secret.xml +++ b/data/org.libvirt.Secret.xml @@ -3,5 +3,10 @@ <node name="/org/libvirt/secret"> <interface name="org.libvirt.Secret"> + <property name="UUID" type="s" access="read"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretGetUUIDString"/> + <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/> + </property> </interface> </node> diff --git a/src/secret.c b/src/secret.c index c7cbb02..1780d96 100644 --- a/src/secret.c +++ b/src/secret.c @@ -3,7 +3,49 @@ #include <libvirt/libvirt.h> +static virSecretPtr +virtDBusSecretGetVirSecret(virtDBusConnect *connect, + const gchar *objectPath, + GError **error) +{ + virSecretPtr secret; + + if (virtDBusConnectOpen(connect, error) < 0) + return NULL; + + secret = virtDBusUtilVirSecretFromBusPath(connect->connection, + objectPath, + connect->secretPath); + if (!secret) { + virtDBusUtilSetLastVirtError(error); + return NULL; + } + + return secret; +} + +static void +virtDBusSecretGetUUID(const gchar *objectPath, + gpointer userData, + GVariant **value, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virSecret) secret = NULL; + gchar uuid[VIR_UUID_STRING_BUFLEN] = ""; + + secret = virtDBusSecretGetVirSecret(connect, objectPath, error); + if (!secret) + return; + + if (virSecretGetUUIDString(secret, uuid) < 0) + return virtDBusUtilSetLastVirtError(error); + + *value = g_variant_new("s", uuid); +} + static virtDBusGDBusPropertyTable virtDBusSecretPropertyTable[] = { + { "UUID", virtDBusSecretGetUUID, NULL }, { 0 } }; -- 2.15.0

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Secret.xml | 5 +++++ src/secret.c | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/data/org.libvirt.Secret.xml b/data/org.libvirt.Secret.xml index 8ee6f0c..5cce9d3 100644 --- a/data/org.libvirt.Secret.xml +++ b/data/org.libvirt.Secret.xml @@ -8,5 +8,10 @@ value="See https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretGetUUIDString"/> <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/> </property> + <property name="UsageID" type="s" access="read"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretGetUsageID"/> + <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/> + </property> </interface> </node> diff --git a/src/secret.c b/src/secret.c index 1780d96..ef0ebcd 100644 --- a/src/secret.c +++ b/src/secret.c @@ -44,8 +44,30 @@ virtDBusSecretGetUUID(const gchar *objectPath, *value = g_variant_new("s", uuid); } +static void +virtDBusSecretGetUsageID(const gchar *objectPath, + gpointer userData, + GVariant **value, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virSecret) secret = NULL; + const gchar *usageID; + + secret = virtDBusSecretGetVirSecret(connect, objectPath, error); + if (!secret) + return; + + usageID = virSecretGetUsageID(secret); + if (!usageID) + return virtDBusUtilSetLastVirtError(error); + + *value = g_variant_new("s", usageID); +} + static virtDBusGDBusPropertyTable virtDBusSecretPropertyTable[] = { { "UUID", virtDBusSecretGetUUID, NULL }, + { "UsageID", virtDBusSecretGetUsageID, NULL }, { 0 } }; -- 2.15.0

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Secret.xml | 5 +++++ src/secret.c | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/data/org.libvirt.Secret.xml b/data/org.libvirt.Secret.xml index 5cce9d3..4270182 100644 --- a/data/org.libvirt.Secret.xml +++ b/data/org.libvirt.Secret.xml @@ -13,5 +13,10 @@ value="See https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretGetUsageID"/> <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/> </property> + <property name="UsageType" type="u" access="read"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretGetUsageType"/> + <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/> + </property> </interface> </node> diff --git a/src/secret.c b/src/secret.c index ef0ebcd..25b1934 100644 --- a/src/secret.c +++ b/src/secret.c @@ -65,9 +65,31 @@ virtDBusSecretGetUsageID(const gchar *objectPath, *value = g_variant_new("s", usageID); } +static void +virtDBusSecretGetUsageType(const gchar *objectPath, + gpointer userData, + GVariant **value, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virSecret) secret = NULL; + gint usageType; + + secret = virtDBusSecretGetVirSecret(connect, objectPath, error); + if (!secret) + return; + + usageType = virSecretGetUsageType(secret); + if (usageType < 0) + return virtDBusUtilSetLastVirtError(error); + + *value = g_variant_new("u", usageType); +} + static virtDBusGDBusPropertyTable virtDBusSecretPropertyTable[] = { { "UUID", virtDBusSecretGetUUID, NULL }, { "UsageID", virtDBusSecretGetUsageID, NULL }, + { "UsageType", virtDBusSecretGetUsageType, NULL }, { 0 } }; -- 2.15.0

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Secret.xml | 6 ++++++ src/secret.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/data/org.libvirt.Secret.xml b/data/org.libvirt.Secret.xml index 4270182..d35af38 100644 --- a/data/org.libvirt.Secret.xml +++ b/data/org.libvirt.Secret.xml @@ -18,5 +18,11 @@ value="See https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretGetUsageType"/> <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/> </property> + <method name="GetXMLDesc"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretGetXMLDesc"/> + <arg name="flags" type="u" direction="in"/> + <arg name="xml" type="s" direction="out"/> + </method> </interface> </node> diff --git a/src/secret.c b/src/secret.c index 25b1934..28b1852 100644 --- a/src/secret.c +++ b/src/secret.c @@ -86,6 +86,33 @@ virtDBusSecretGetUsageType(const gchar *objectPath, *value = g_variant_new("u", usageType); } +static void +virtDBusSecretGetXMLDesc(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath, + gpointer userData, + GVariant **outArgs, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virSecret) secret = NULL; + g_autofree gchar *xml = NULL; + guint flags; + + g_variant_get(inArgs, "(u)", &flags); + + secret = virtDBusSecretGetVirSecret(connect, objectPath, error); + if (!secret) + return; + + xml = virSecretGetXMLDesc(secret, flags); + if (!xml) + return virtDBusUtilSetLastVirtError(error); + + *outArgs = g_variant_new("(s)", xml); +} + static virtDBusGDBusPropertyTable virtDBusSecretPropertyTable[] = { { "UUID", virtDBusSecretGetUUID, NULL }, { "UsageID", virtDBusSecretGetUsageID, NULL }, @@ -94,6 +121,7 @@ static virtDBusGDBusPropertyTable virtDBusSecretPropertyTable[] = { }; static virtDBusGDBusMethodTable virtDBusSecretMethodTable[] = { + { "GetXMLDesc", virtDBusSecretGetXMLDesc }, { 0 } }; -- 2.15.0

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 6 ++++++ src/connect.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index 3aae9fe..cb70af9 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -223,6 +223,12 @@ <arg name="params" type="a{sv}" direction="in"/> <arg name="flags" type="u" direction="in"/> </method> + <method name="SecretLookupByUUID"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretLookupByUUIDString"/> + <arg name="uuid" type="s" direction="in"/> + <arg name="secret" type="o" direction="out"/> + </method> <method name="StoragePoolLookupByName"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolLookupByName"/> diff --git a/src/connect.c b/src/connect.c index 6b96888..70b2ee8 100644 --- a/src/connect.c +++ b/src/connect.c @@ -1151,6 +1151,34 @@ virtDBusConnectNodeSetMemoryParameters(GVariant *inArgs, } } +static void +virtDBusConnectSecretLookupByUUID(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath G_GNUC_UNUSED, + gpointer userData, + GVariant **outArgs, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virSecret) secret = NULL; + g_autofree gchar *path = NULL; + const gchar *uuidstr; + + g_variant_get(inArgs, "(s)", &uuidstr); + + if (!virtDBusConnectOpen(connect, error)) + return; + + secret = virSecretLookupByUUIDString(connect->connection, uuidstr); + if (!secret) + return virtDBusUtilSetLastVirtError(error); + + path = virtDBusUtilBusPathForVirSecret(secret, connect->secretPath); + + *outArgs = g_variant_new("(o)", path); +} + static void virtDBusConnectStoragePoolLookupByName(GVariant *inArgs, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -1250,6 +1278,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = { { "NodeGetMemoryStats", virtDBusConnectNodeGetMemoryStats }, { "NodeGetSecurityModel", virtDBusConnectNodeGetSecurityModel }, { "NodeSetMemoryParameters", virtDBusConnectNodeSetMemoryParameters }, + { "SecretLookupByUUID", virtDBusConnectSecretLookupByUUID }, { "StoragePoolLookupByName", virtDBusConnectStoragePoolLookupByName }, { "StoragePoolLookupByUUID", virtDBusConnectStoragePoolLookupByUUID }, { 0 } -- 2.15.0

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 7 +++++++ src/connect.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index cb70af9..fc29165 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -229,6 +229,13 @@ <arg name="uuid" type="s" direction="in"/> <arg name="secret" type="o" direction="out"/> </method> + <method name="SecretLookupByUsage"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretLookupByUsage"/> + <arg name="usageType" type="i" direction="in"/> + <arg name="usageID" type="s" direction="in"/> + <arg name="secret" type="o" direction="out"/> + </method> <method name="StoragePoolLookupByName"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolLookupByName"/> diff --git a/src/connect.c b/src/connect.c index 70b2ee8..3ef068f 100644 --- a/src/connect.c +++ b/src/connect.c @@ -1179,6 +1179,35 @@ virtDBusConnectSecretLookupByUUID(GVariant *inArgs, *outArgs = g_variant_new("(o)", path); } +static void +virtDBusConnectSecretLookupByUsage(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath G_GNUC_UNUSED, + gpointer userData, + GVariant **outArgs, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virSecret) secret = NULL; + g_autofree gchar *path = NULL; + gint usageType; + const gchar *usageID; + + g_variant_get(inArgs, "(i&s)", &usageType, &usageID); + + if (!virtDBusConnectOpen(connect, error)) + return; + + secret = virSecretLookupByUsage(connect->connection, usageType, usageID); + if (!secret) + return virtDBusUtilSetLastVirtError(error); + + path = virtDBusUtilBusPathForVirSecret(secret, connect->secretPath); + + *outArgs = g_variant_new("(o)", path); +} + static void virtDBusConnectStoragePoolLookupByName(GVariant *inArgs, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -1279,6 +1308,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = { { "NodeGetSecurityModel", virtDBusConnectNodeGetSecurityModel }, { "NodeSetMemoryParameters", virtDBusConnectNodeSetMemoryParameters }, { "SecretLookupByUUID", virtDBusConnectSecretLookupByUUID }, + { "SecretLookupByUsage", virtDBusConnectSecretLookupByUsage }, { "StoragePoolLookupByName", virtDBusConnectStoragePoolLookupByName }, { "StoragePoolLookupByUUID", virtDBusConnectStoragePoolLookupByUUID }, { 0 } -- 2.15.0

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Secret.xml | 4 ++++ src/secret.c | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/data/org.libvirt.Secret.xml b/data/org.libvirt.Secret.xml index d35af38..509c46a 100644 --- a/data/org.libvirt.Secret.xml +++ b/data/org.libvirt.Secret.xml @@ -24,5 +24,9 @@ <arg name="flags" type="u" direction="in"/> <arg name="xml" type="s" direction="out"/> </method> + <method name="Undefine"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretUndefine"/> + </method> </interface> </node> diff --git a/src/secret.c b/src/secret.c index 28b1852..ecbd809 100644 --- a/src/secret.c +++ b/src/secret.c @@ -113,6 +113,26 @@ virtDBusSecretGetXMLDesc(GVariant *inArgs, *outArgs = g_variant_new("(s)", xml); } +static void +virtDBusSecretUndefine(GVariant *inArgs G_GNUC_UNUSED, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath, + gpointer userData, + GVariant **outArgs G_GNUC_UNUSED, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virSecret) secret = NULL; + + secret = virtDBusSecretGetVirSecret(connect, objectPath, error); + if (!secret) + return; + + if (virSecretUndefine(secret) < 0) + virtDBusUtilSetLastVirtError(error); +} + static virtDBusGDBusPropertyTable virtDBusSecretPropertyTable[] = { { "UUID", virtDBusSecretGetUUID, NULL }, { "UsageID", virtDBusSecretGetUsageID, NULL }, @@ -122,6 +142,7 @@ static virtDBusGDBusPropertyTable virtDBusSecretPropertyTable[] = { static virtDBusGDBusMethodTable virtDBusSecretMethodTable[] = { { "GetXMLDesc", virtDBusSecretGetXMLDesc }, + { "Undefine", virtDBusSecretUndefine }, { 0 } }; -- 2.15.0

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Secret.xml | 6 ++++++ src/secret.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/data/org.libvirt.Secret.xml b/data/org.libvirt.Secret.xml index 509c46a..563167b 100644 --- a/data/org.libvirt.Secret.xml +++ b/data/org.libvirt.Secret.xml @@ -18,6 +18,12 @@ value="See https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretGetUsageType"/> <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/> </property> + <method name="GetValue"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretGetValue"/> + <arg name="flags" type="u" direction="in"/> + <arg name="value" type="ay" direction="out"/> + </method> <method name="GetXMLDesc"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretGetXMLDesc"/> diff --git a/src/secret.c b/src/secret.c index ecbd809..653dc5c 100644 --- a/src/secret.c +++ b/src/secret.c @@ -86,6 +86,42 @@ virtDBusSecretGetUsageType(const gchar *objectPath, *value = g_variant_new("u", usageType); } +static void +virtDBusSecretGetValue(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath, + gpointer userData, + GVariant **outArgs, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virSecret) secret = NULL; + g_autofree guchar *value = NULL; + gsize size; + guint flags; + GVariantBuilder builder; + GVariant *res; + + g_variant_get(inArgs, "(u)", &flags); + + secret = virtDBusSecretGetVirSecret(connect, objectPath, error); + if (!secret) + return; + + value = virSecretGetValue(secret, &size, flags); + if (!value) + return virtDBusUtilSetLastVirtError(error); + + g_variant_builder_init(&builder, G_VARIANT_TYPE("ay")); + for (unsigned int i = 0; i < size; i++) + g_variant_builder_add(&builder, "y", value[i]); + + res = g_variant_builder_end(&builder); + + *outArgs = g_variant_new_tuple(&res, 1); +} + static void virtDBusSecretGetXMLDesc(GVariant *inArgs, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -143,6 +179,7 @@ static virtDBusGDBusPropertyTable virtDBusSecretPropertyTable[] = { static virtDBusGDBusMethodTable virtDBusSecretMethodTable[] = { { "GetXMLDesc", virtDBusSecretGetXMLDesc }, { "Undefine", virtDBusSecretUndefine }, + { "GetValue", virtDBusSecretGetValue }, { 0 } }; -- 2.15.0

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Secret.xml | 6 ++++++ src/secret.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/data/org.libvirt.Secret.xml b/data/org.libvirt.Secret.xml index 563167b..3a5d742 100644 --- a/data/org.libvirt.Secret.xml +++ b/data/org.libvirt.Secret.xml @@ -30,6 +30,12 @@ <arg name="flags" type="u" direction="in"/> <arg name="xml" type="s" direction="out"/> </method> + <method name="SetValue"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretSetValue"/> + <arg name="value" type="ay" direction="in"/> + <arg name="flags" type="u" direction="in"/> + </method> <method name="Undefine"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretUndefine"/> diff --git a/src/secret.c b/src/secret.c index 653dc5c..028a7b4 100644 --- a/src/secret.c +++ b/src/secret.c @@ -149,6 +149,39 @@ virtDBusSecretGetXMLDesc(GVariant *inArgs, *outArgs = g_variant_new("(s)", xml); } +static void +virtDBusSecretSetValue(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath, + gpointer userData, + GVariant **outArgs G_GNUC_UNUSED, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virSecret) secret = NULL; + g_autoptr(GVariantIter) iter = NULL; + guint flags; + g_autofree guchar *value = NULL; + guchar *tmp; + gsize size; + + g_variant_get(inArgs, "(ayu)", &iter, &flags); + + secret = virtDBusSecretGetVirSecret(connect, objectPath, error); + if (!secret) + return; + + size = g_variant_iter_n_children(iter); + value = g_new0(guchar, size); + tmp = value; + while (g_variant_iter_next(iter, "y", tmp)) + tmp++; + + if (virSecretSetValue(secret, value, size, flags) < 0) + virtDBusUtilSetLastVirtError(error); +} + static void virtDBusSecretUndefine(GVariant *inArgs G_GNUC_UNUSED, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -180,6 +213,7 @@ static virtDBusGDBusMethodTable virtDBusSecretMethodTable[] = { { "GetXMLDesc", virtDBusSecretGetXMLDesc }, { "Undefine", virtDBusSecretUndefine }, { "GetValue", virtDBusSecretGetValue }, + { "SetValue", virtDBusSecretSetValue }, { 0 } }; -- 2.15.0

On Wed, May 09, 2018 at 04:59:37PM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Secret.xml | 6 ++++++ src/secret.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+)
[...]
diff --git a/src/secret.c b/src/secret.c index 653dc5c..028a7b4 100644 --- a/src/secret.c +++ b/src/secret.c @@ -149,6 +149,39 @@ virtDBusSecretGetXMLDesc(GVariant *inArgs, *outArgs = g_variant_new("(s)", xml); }
+static void +virtDBusSecretSetValue(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath, + gpointer userData, + GVariant **outArgs G_GNUC_UNUSED, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virSecret) secret = NULL; + g_autoptr(GVariantIter) iter = NULL; + guint flags; + g_autofree guchar *value = NULL; + guchar *tmp; + gsize size; + + g_variant_get(inArgs, "(ayu)", &iter, &flags); + + secret = virtDBusSecretGetVirSecret(connect, objectPath, error); + if (!secret) + return; + + size = g_variant_iter_n_children(iter); + value = g_new0(guchar, size); + tmp = value; + while (g_variant_iter_next(iter, "y", tmp)) + tmp++;
Swap these two block, parse the array before getting secret object. Pavel

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 7 +++++++ src/connect.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index fc29165..8691762 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -223,6 +223,13 @@ <arg name="params" type="a{sv}" direction="in"/> <arg name="flags" type="u" direction="in"/> </method> + <method name="SecretDefineXML"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretDefineXML"/> + <arg name="xml" type="s" direction="in"/> + <arg name="flags" type="u" direction="in"/> + <arg name="secret" type="o" direction="out"/> + </method> <method name="SecretLookupByUUID"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretLookupByUUIDString"/> diff --git a/src/connect.c b/src/connect.c index 3ef068f..05381de 100644 --- a/src/connect.c +++ b/src/connect.c @@ -1151,6 +1151,35 @@ virtDBusConnectNodeSetMemoryParameters(GVariant *inArgs, } } +static void +virtDBusConnectSecretDefineXML(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath G_GNUC_UNUSED, + gpointer userData, + GVariant **outArgs, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virSecret) secret = NULL; + g_autofree gchar *path = NULL; + const gchar *xml; + guint flags; + + g_variant_get(inArgs, "(&su)", &xml, &flags); + + if (!virtDBusConnectOpen(connect, error)) + return; + + secret = virSecretDefineXML(connect->connection, xml, flags); + if (!secret) + return virtDBusUtilSetLastVirtError(error); + + path = virtDBusUtilBusPathForVirSecret(secret, connect->secretPath); + + *outArgs = g_variant_new("(o)", path); +} + static void virtDBusConnectSecretLookupByUUID(GVariant *inArgs, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -1307,6 +1336,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = { { "NodeGetMemoryStats", virtDBusConnectNodeGetMemoryStats }, { "NodeGetSecurityModel", virtDBusConnectNodeGetSecurityModel }, { "NodeSetMemoryParameters", virtDBusConnectNodeSetMemoryParameters }, + { "SecretDefineXML", virtDBusConnectSecretDefineXML }, { "SecretLookupByUUID", virtDBusConnectSecretLookupByUUID }, { "SecretLookupByUsage", virtDBusConnectSecretLookupByUsage }, { "StoragePoolLookupByName", virtDBusConnectStoragePoolLookupByName }, -- 2.15.0

On Wed, May 09, 2018 at 04:59:25PM +0200, Katerina Koukiou wrote:
Katerina Koukiou (13): Introduce Secret Interface Implement ListSecrets method for Connect Interface Register Secret Lifecycle Events Implement UUID property for Secret Interface Implement UsageID property for Secret Interface Implement UsageType property for Secret Interface Implement GetXMLDesc method for Secret Interface Implement SecretLookupByUUID method for Connect Interface Implement SecretLookupByUsage method for Connect Interface Implement Undefine method for Secret Interface Implement GetValue method for Secret Interface Implement SetValue method for Secret Interface Implement SecretDefineXML method for Connect Interface
See the note for PATCH 12 Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
participants (2)
-
Katerina Koukiou
-
Pavel Hrdina