Skip to content
Snippets Groups Projects
Commit d0806c0e authored by Recolic K's avatar Recolic K
Browse files

poc

parent f22d15cb
No related branches found
No related tags found
No related merge requests found
CXX ?= g++
# Accepts CXXSTD >= C++14
CXXFLAGS := $(shell pkg-config --cflags --libs gnome-keyring-1) $(shell pkg-config --cflags --libs libsecret-1) -I ./lib -I . -std=c++14
CXXFLAGS := -I ./lib -I . -std=c++14
EXTRA_FLAGS ?=
secret:
mkdir -p ../bin/
$(CXX) unlock_keyrings.cc -DUSE_LIBGNOMEKEYRING -o ../bin/unlock_keyrings $(CXXFLAGS) $(EXTRA_FLAGS)
$(CXX) unlock_keyrings.cc -DUSE_LIBGNOMEKEYRING -o ../bin/unlock_keyrings $(CXXFLAGS) $(EXTRA_FLAGS) $(shell pkg-config --cflags --libs gnome-keyring-1)
libsecret_test:
mkdir -p ../bin/
$(CXX) unlock_keyrings.cc -DUSE_LIBSECRET -o ../bin/unlock_keyrings $(CXXFLAGS) $(EXTRA_FLAGS)
$(CXX) unlock_keyrings.cc -DUSE_LIBSECRET -o ../bin/unlock_keyrings $(CXXFLAGS) $(EXTRA_FLAGS) $(shell pkg-config --cflags --libs libsecret-1)
#include <gnome-keyring-1/gnome-keyring.h>
#include <string>
#include <rlib/macro.hpp>
using namespace std::literals;
#if defined(USE_LIBSECRET)
#include <libsecret/secret.h>
#include <gmodule.h>
#include <rlib/stdio.hpp>
#if defined(USE_LIBSECRET)
inline std::string do_unlock(std::string keyring_label, std::string password) {
GError *err = NULL;
SecretService *service_proxy_ptr = secret_service_get_sync(SECRET_SERVICE_LOAD_COLLECTIONS, NULL, &err);
......@@ -28,31 +26,33 @@ inline std::string do_unlock(std::string keyring_label, std::string password) {
auto label = secret_collection_get_label(iter);
if(label == NULL) break;
rlib_defer([&]{g_free(label);});
rlib::println("DEBUG: LABEL=", label);
if(std::string(label) == keyring_label) {
collections_to_unlock = g_list_append(collections_to_unlock, iter);
rlib::println("APPEND!");
}
curr = curr->next;
}
if(g_list_length(collections_to_unlock) == 0) {
return "No such keyring with label: "s + keyring_label;
return "No such keyring with label: "s + keyring_label + ". You need keyring LABEL instead of NAME. ";
}
auto unlocked_count = secret_service_unlock_sync(service_proxy_ptr, collections_to_unlock, NULL, &collections_unlocked, &err);
if(unlocked_count == g_list_length(collections_to_unlock))
return "SUCCESS";
else {
if(err != NULL)
return rlib::string("{}/{} collections(keyrings) successfully unlocked, some of them failed. Error message: {}").format(unlocked_count, g_list_length(collections_to_unlock), err->message);
else
return rlib::string("{}/{} collections(keyrings) successfully unlocked, some of them failed. No error message from libsecret").format(unlocked_count, g_list_length(collections_to_unlock));
std::string err_msg_pass = err == NULL ? "No error message from libsecret" : err->message;
std::string err_msg_stat = unlocked_count == 0 ? "Failed. " :
"Some requested keyrings failed to unlock. "+std::to_string(unlocked_count)+"/"+std::to_string(g_list_length(collections_to_unlock))+" collections(keyrings) successfully unlocked. ";
return err_msg_stat + err_msg_pass;
}
}
#define keyringResultToString(r) (r)
constexpr auto UNLOCK_RESULT_SUCCESS = "SUCCESS";
#elif defined(USE_LIBGNOMEKEYRING)
#include <gnome-keyring-1/gnome-keyring.h>
inline GnomeKeyringResult do_unlock(std::string keyring, std::string password) {
return gnome_keyring_unlock_sync(keyring.c_str(), password.c_str());
}
......@@ -78,7 +78,10 @@ inline std::string keyringResultToString(GnomeKeyringResult res) {
}
}
constexpr auto UNLOCK_RESULT_SUCCESS = GNOME_KEYRING_RESULT_OK;
#else
#error You must define either USE_LIBGNOMEKEYRING(deprecated) or USE_LIBSECRET(new), to select which backend implementation to use
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment