From 84f1e50cb1a959f3a835b8ba265159cc6e75635a Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Sun, 31 Dec 2023 00:36:01 +0530 Subject: pass/rm: init --- pass_util.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'pass_util.c') diff --git a/pass_util.c b/pass_util.c index 3ce3784..de8308a 100644 --- a/pass_util.c +++ b/pass_util.c @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include @@ -151,8 +150,9 @@ int pass_add(const char *path, const char *pass, size_t n) if (r) err_die(1, "invalid key , try gpg --list-keys"); + // TODO: guard against .*\.gpg\.gpg[/$] r = snprintf(pass_path, sizeof(pass_path), "%s/%s.gpg", pass_dir, path); - if (r > (int) sizeof(gpg_id_path)) + if (r > (int) sizeof(pass_path)) err_die(1, "path exceeded PATH_MAX"); rc = strdup(pass_path); @@ -174,3 +174,29 @@ int pass_add(const char *path, const char *pass, size_t n) fclose(out_stream); return r; } + +int pass_rm(const char *path) +{ + + int r = 0; + char gpg_path[PATH_MAX], abs_path[PATH_MAX]; + + r = set_pass_dir(); + if (r) + err_die(1, "PASSWORD_STORE_DIR not set"); + + r = snprintf(gpg_path, sizeof(gpg_path), "%s.gpg", path); + if (r > (int) sizeof(gpg_path)) + err_die(1, "path exceeded PATH_MAX"); + + r = snprintf(abs_path, sizeof(gpg_path), "%s/%s", pass_dir, gpg_path); + if (r > (int) sizeof(abs_path)) + err_die(1, "path exceeded PATH_MAX"); + + // TODO: guard against .*\.gpg\.gpg[/$] + r = unlink(abs_path); + if (r) + err_die(1, "%s %s", abs_path, strerror(errno)); + + return r_rmdir(pass_dir, dirname(gpg_path)); +} -- cgit v1.2.3