aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsinanmohd <sinan@sinanmohd.com>2024-04-09 22:24:51 +0530
committersinanmohd <sinan@sinanmohd.com>2024-04-09 22:32:50 +0530
commit5a1bcb408180b4659dbb4aee4a1cac494e7e6cba (patch)
treecdee352231e61a7db3c03ee770339cb4f3fa3fea /src
parent4fcff492c978e1d355373978170dac5ebdef26cd (diff)
libnpass: better error messages
Diffstat (limited to 'src')
-rw-r--r--src/libnpass/libnpass.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/libnpass/libnpass.c b/src/libnpass/libnpass.c
index 37fc40c..b9ce58e 100644
--- a/src/libnpass/libnpass.c
+++ b/src/libnpass/libnpass.c
@@ -105,7 +105,7 @@ pass_store_t pass_store_type(const char *spath) {
err_ret(PASS_STORE_INV, "PASSWORD_STORE_DIR not set");
r = snprintf(abs_path, sizeof(abs_path) - 1, "%s/%s",
- pass_dir, spath);
+ pass_dir, (spath) ? spath : "");
if (r >= (int) sizeof(abs_path))
err_ret(PASS_STORE_INV, "path exceeded PATH_MAX");
r = stat(abs_path, &sbuf);
@@ -132,10 +132,11 @@ DIR *openstore(const char *spath) {
DIR *d;
const char *path;
char abs_path[PATH_MAX];
+ pass_store_t store_type;
- r = set_pass_dir();
- if (r)
- err_ret(NULL, "PASSWORD_STORE_DIR not set");
+ store_type = pass_store_type(spath);
+ if (store_type != PASS_STORE_DIR)
+ err_ret(NULL, "%s is not a passwordstore directory", spath);
if (spath) {
r = snprintf(abs_path, sizeof(abs_path) - 1, "%s/%s",
@@ -263,8 +264,13 @@ int pass_init(const char *fpr)
int pass_cat(FILE *out, const char *path)
{
int r;
+ pass_store_t store_type;
char pass_path[PATH_MAX];
+ store_type = pass_store_type(path);
+ if (store_type != PASS_STORE_ENC)
+ err_ret(1, "%s is not a passwordstore file", path);
+
r = set_pass_dir();
if (r)
err_ret(1, "PASSWORD_STORE_DIR not set");