aboutsummaryrefslogtreecommitdiff
path: root/src/npassd/service.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/npassd/service.c')
-rw-r--r--src/npassd/service.c91
1 files changed, 90 insertions, 1 deletions
diff --git a/src/npassd/service.c b/src/npassd/service.c
index b179735..e57fefe 100644
--- a/src/npassd/service.c
+++ b/src/npassd/service.c
@@ -13,6 +13,8 @@ static int handle_open_session(sd_bus_message *msg, void *data,
sd_bus_error *ret_error);
static int handle_search_items(sd_bus_message *msg, void *data,
sd_bus_error *ret_error);
+static int handle_create_collection(sd_bus_message *msg, void *data,
+ sd_bus_error *ret_error);
static const sd_bus_vtable service_vtable[] = {
SD_BUS_VTABLE_START(0),
@@ -20,6 +22,8 @@ static const sd_bus_vtable service_vtable[] = {
SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("SearchItems", "a{ss}", "aoao", handle_search_items,
SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_METHOD("CreateCollection", "a{sv}s", "oo",
+ handle_create_collection, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_VTABLE_END,
};
@@ -30,6 +34,84 @@ static int handle_search_items(__attribute__((unused)) sd_bus_message *msg,
return sd_bus_reply_method_return(msg, "aoao", 0, 0);
}
+static int handle_create_collection(sd_bus_message *msg, void *data,
+ __attribute__((unused))
+ sd_bus_error *ret_error)
+{
+ const char *label, *alias, *key;
+ struct service *service = data;
+ struct collection *collection;
+ char *root;
+ int ret;
+
+ ret = sd_bus_message_enter_container(msg, SD_BUS_TYPE_ARRAY, "{sv}");
+ if (ret <= 0) {
+ print_err("%s", strerror(ret < 0 ? -ret : EINVAL));
+ return ret < 0 ? ret : -EINVAL;
+ }
+
+ ret = sd_bus_message_enter_container(msg, SD_BUS_TYPE_DICT_ENTRY, "sv");
+ if (ret <= 0) {
+ print_err("%s", strerror(ret < 0 ? -ret : EINVAL));
+ return ret < 0 ? ret : -EINVAL;
+ }
+
+ ret = sd_bus_message_read(msg, "s", &key);
+ if (ret < 0) {
+ print_err("%s", strerror(-ret));
+ return ret;
+ }
+
+ ret = strcmp("org.freedesktop.Secret.Collection.Label", key);
+ if (ret) {
+ print_err("Unsupported property key: %s", key);
+ return -EINVAL;
+ }
+
+ ret = sd_bus_message_read(msg, "v", "s", &label);
+ if (ret < 0) {
+ print_err("%s", strerror(-ret));
+ return ret;
+ }
+
+ ret = sd_bus_message_exit_container(msg);
+ if (ret < 0) {
+ print_err("%s", strerror(-ret));
+ return ret;
+ }
+
+ ret = sd_bus_message_exit_container(msg);
+ if (ret < 0) {
+ print_err("%s", strerror(-ret));
+ return ret;
+ }
+
+ ret = sd_bus_message_read(msg, "s", &alias);
+ if (ret < 0) {
+ print_err("%s", strerror(-ret));
+ return ret;
+ }
+
+ ret = collection_root_make(label, alias, &root);
+ if (ret < 0)
+ return ret;
+
+ ret = collection_new(service->bus, service->db, &collection, alias,
+ label, root);
+ free(root);
+ if (ret < 0)
+ return ret;
+
+ ret = sd_bus_reply_method_return(msg, "oo", collection->path, "/");
+ if (ret < 0) {
+ print_err("%s", strerror(-ret));
+ return ret;
+ }
+
+ LIST_INSERT_HEAD(&service->collections, collection, dlist);
+ return ret;
+}
+
static int handle_open_session(sd_bus_message *msg, void *data,
sd_bus_error *ret_error)
{
@@ -55,8 +137,14 @@ static int handle_open_session(sd_bus_message *msg, void *data,
if (ret < 0)
return ret;
+ ret = sd_bus_reply_method_return(msg, "vo", "s", NULL, session->path);
+ if (ret < 0) {
+ print_err("%s", strerror(-ret));
+ return ret;
+ }
+
LIST_INSERT_HEAD(&service->sessions, session, dlist);
- return sd_bus_reply_method_return(msg, "vo", "s", NULL, session->path);
+ return ret;
}
void service_free(struct service *service)
@@ -75,6 +163,7 @@ int service_init(sd_bus *bus, struct service *service)
service->bus = bus;
LIST_INIT(&service->sessions);
+ LIST_INIT(&service->collections);
ret = sd_bus_add_object_vtable(service->bus, &service->slot,
DBUS_OBJECT_PATH, SERVICE_IFACE,