Skip to content
Snippets Groups Projects
Unverified Commit b3b705e4 authored by Recolic Keghart's avatar Recolic Keghart
Browse files

init

parent 92c27a9e
No related branches found
No related tags found
No related merge requests found
*.out
*.gi
bin/unlock_keyrings
[submodule "src/lib/rlib"]
path = src/lib/rlib
url = https://github.com/recolic/rlib.git
#!/bin/bash
filename="$1"
gpg_pubkey_id="$2" # leave empty to use default receipt.
echo '>>> Please type keyring_name and password in the following format:
keyring1:password1
keyring2:password2
# Comment: This is a comment
login:12345678
>>> When you are done, use Ctrl-D to end.'
gpg --encrypt -o "$filename" -a -r "$gpg_pubkey_id"
exit $?
CXX ?= g++
CXXFLAGS := $(shell pkg-config --cflags --libs gnome-keyring-1) -I ./lib -I .
EXTRA_FLAGS ?=
secret: rlib
$(CXX) $(CXXFLAGS) $(EXTRA_FLAGS) unlock_keyrings.cc ./lib/rlib/libr.a -o ../bin/unlock_keyrings
rlib:
cd ./lib/rlib && make
#include <gnome-keyring-1/gnome-keyring.h>
#include <string>
#include <rlib/macro.hpp>
inline GnomeKeyringResult do_unlock(std::string keyring, std::string password) {
return gnome_keyring_unlock_sync(keyring.c_str(), password.c_str());
}
inline std::string keyringResultToString(GnomeKeyringResult res) {
switch(res) {
#define RLIB_IMPL_GEN_RESULT(value) RLIB_IMPL_GEN_RESULT_1(value, RLIB_MACRO_TO_CSTR(value))
#define RLIB_IMPL_GEN_RESULT_1(value, cstr) case (value): return (cstr)
RLIB_IMPL_GEN_RESULT(GNOME_KEYRING_RESULT_OK);
RLIB_IMPL_GEN_RESULT(GNOME_KEYRING_RESULT_DENIED);
RLIB_IMPL_GEN_RESULT(GNOME_KEYRING_RESULT_NO_KEYRING_DAEMON);
RLIB_IMPL_GEN_RESULT(GNOME_KEYRING_RESULT_ALREADY_UNLOCKED);
RLIB_IMPL_GEN_RESULT(GNOME_KEYRING_RESULT_NO_SUCH_KEYRING);
RLIB_IMPL_GEN_RESULT(GNOME_KEYRING_RESULT_BAD_ARGUMENTS);
RLIB_IMPL_GEN_RESULT(GNOME_KEYRING_RESULT_IO_ERROR);
RLIB_IMPL_GEN_RESULT(GNOME_KEYRING_RESULT_CANCELLED);
RLIB_IMPL_GEN_RESULT(GNOME_KEYRING_RESULT_KEYRING_ALREADY_EXISTS);
RLIB_IMPL_GEN_RESULT(GNOME_KEYRING_RESULT_NO_MATCH);
default:
return std::string("Unknown Result Code: ") + std::to_string(res);
}
}
Subproject commit 3a442c6dd8661d45cfe7528112b93c42ffa5d591
#include <rlib/log.hpp>
#include <rlib/opt.hpp>
#include <rlib/stream.hpp>
#include "keyring_op.hpp"
int main(int argc, char **argv) {
rlib::opt_parser args(argc, argv);
rlib::logger rlog(std::cout);
if(args.getBoolArg("-h", "--help")) {
rlog.info("Usage: {} [-h/--help] [-q/--quiet] --secret-file <filename> # use `-` as stdin.");
return 0;
}
if(args.getBoolArg("-q", "--quiet")) {
rlog = rlib::logger(rlib::null_stream);
}
auto secret_file_name = args.getValueArg("--secret-file");
if(secret_file_name == "-")
secret_file_name = "/dev/fd/0";
std::ifstream secret_input (secret_file_name);
if(not secret_input) {
rlog.error("Unable to open file {}. Exiting...", secret_file_name);
return 2;
}
size_t line_num = 0;
bool no_error = true;
while(not secret_input.eof()) {
auto line = rlib::scanln(secret_input).strip("\t\n\r");
auto line_removed_space = line;
line_removed_space.strip(' '); // Remove space may break keyring_name or password.
if(line_removed_space.empty() or line_removed_space[0] == '#')
continue; // Skip comments.
auto keyring_and_pswd = line.split(':');
if(keyring_and_pswd.size() != 2) {
rlog.error("Secret file line {} has wrong format. Expecting `${keyring}:${password}`", line_num);
return 3;
}
auto res = do_unlock(keyring_and_pswd.at(0), keyring_and_pswd.at(1));
auto msg = keyringResultToString(res);
if(res == GNOME_KEYRING_RESULT_OK)
rlog.verbose("line {}: {}.", line_num, msg);
else {
rlog.error("line {}: {}.", line_num, msg);
no_error = false;
}
++line_num;
}
return no_error ? 0 : 4;
}
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