From ab7a459cbf4490dcd647513534197662f63a34ea Mon Sep 17 00:00:00 2001 From: Recolic K <bensl@microsoft.com> Date: Mon, 21 Jun 2021 19:01:52 +0800 Subject: [PATCH] playing libsecret --- src/Makefile | 2 +- src/keyring_op.hpp | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/Makefile b/src/Makefile index 5ee5a07..a6f861c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,7 +1,7 @@ CXX ?= g++ # Accepts CXXSTD >= C++14 -CXXFLAGS := $(shell pkg-config --cflags --libs gnome-keyring-1) -I ./lib -I . -std=c++14 +CXXFLAGS := $(shell pkg-config --cflags --libs gnome-keyring-1) $(shell pkg-config --cflags --libs libsecret-1) -I ./lib -I . -std=c++14 EXTRA_FLAGS ?= secret: diff --git a/src/keyring_op.hpp b/src/keyring_op.hpp index de9d1da..d610340 100644 --- a/src/keyring_op.hpp +++ b/src/keyring_op.hpp @@ -2,6 +2,35 @@ #include <string> #include <rlib/macro.hpp> +#include <libsecret/secret.h> +#include <gmodule.h> +#include <rlib/stdio.hpp> + +inline std::string do_unlock_2(std::string keyring, std::string password) { + GError *err = NULL; + SecretService *service_proxy_ptr = secret_service_get_sync(SECRET_SERVICE_LOAD_COLLECTIONS, NULL, &err); + if(err != NULL or service_proxy_ptr == NULL) { + return err->message; + } + rlib_defer([&]{g_object_unref(service_proxy_ptr);}); + + GList *collections = secret_service_get_collections(service_proxy_ptr); + if(collections == NULL) return "collection gg"; + + auto curr = collections; + while (curr != NULL) + { + auto iter = reinterpret_cast<SecretCollection *>(curr->data); + auto label = secret_collection_get_label(iter); + if(label == NULL) break; + rlib_defer([&]{g_free(label);}); + rlib::println("DEBUG: LABEL=", label); + + curr = curr->next; + } + return ""; +} + inline GnomeKeyringResult do_unlock(std::string keyring, std::string password) { return gnome_keyring_unlock_sync(keyring.c_str(), password.c_str()); } -- GitLab