From 3a2526a29301a31b277d3116be933df592764055 Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Thu, 11 Apr 2024 22:27:41 +0530 Subject: libnpass: improve backward compatibility with original pass --- src/libnpass/libnpass.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/libnpass/libnpass.c b/src/libnpass/libnpass.c index 34b95ec..b7a0ded 100644 --- a/src/libnpass/libnpass.c +++ b/src/libnpass/libnpass.c @@ -40,6 +40,7 @@ static int set_pass_dir(void) { int r; const char *env; + struct stat statbuf; env = getenv("PASSWORD_STORE_DIR"); if (env) { @@ -47,6 +48,21 @@ static int set_pass_dir(void) return 0; } + /* + * for backward compatibility with original pass + */ + env = getenv("HOME"); + if (env) { + r = snprintf(pass_dir, sizeof(pass_dir), "%s/%s", env, + ".password-store"); + if ((size_t)r > sizeof(pass_dir)) + err_ret(PASS_STORE_INV, "path exceeded PATH_MAX"); + + r = stat(pass_dir, &statbuf); + if (!r) + return 0; + } + env = getenv("XDG_DATA_HOME"); if (env) { r = snprintf(pass_dir, sizeof(pass_dir), "%s/%s", env, -- cgit v1.2.3