Signed-off-by: Katerina Koukiou <kkoukiou(a)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