aboutsummaryrefslogtreecommitdiff
path: root/src/libnpass/libnpass.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libnpass/libnpass.c')
-rw-r--r--src/libnpass/libnpass.c80
1 files changed, 40 insertions, 40 deletions
diff --git a/src/libnpass/libnpass.c b/src/libnpass/libnpass.c
index 779a42a..fd6e447 100644
--- a/src/libnpass/libnpass.c
+++ b/src/libnpass/libnpass.c
@@ -58,7 +58,7 @@ static int set_pass_dir(void)
r = snprintf(pass_dir, sizeof(pass_dir), "%s/%s", env,
".password-store");
if (r < 0 || (size_t)r > sizeof(pass_dir))
- err_ret(-ENAMETOOLONG, "Path exceeded PATH_MAX");
+ return_err(-ENAMETOOLONG, "Path exceeded PATH_MAX");
r = stat(pass_dir, &statbuf);
if (!r)
@@ -70,7 +70,7 @@ static int set_pass_dir(void)
r = snprintf(pass_dir, sizeof(pass_dir), "%s/%s", env,
DEF_PASS_DIR);
if (r < 0 || (size_t)r > sizeof(pass_dir))
- err_ret(-ENAMETOOLONG, "Path exceeded PATH_MAX");
+ return_err(-ENAMETOOLONG, "Path exceeded PATH_MAX");
return 0;
}
@@ -79,7 +79,7 @@ static int set_pass_dir(void)
r = snprintf(pass_dir, sizeof(pass_dir), "%s/%s/%s", env,
".local/share", DEF_PASS_DIR);
if (r < 0 || (size_t)r > sizeof(pass_dir))
- err_ret(-ENAMETOOLONG, "Path exceeded PATH_MAX");
+ return_err(-ENAMETOOLONG, "Path exceeded PATH_MAX");
return 0;
}
@@ -130,27 +130,27 @@ int pass_store_type(const char *spath)
r = set_pass_dir();
if (r < 0)
- err_ret(-EINVAL, "PASSWORD_STORE_DIR must be set");
+ return_err(-EINVAL, "PASSWORD_STORE_DIR must be set");
r = snprintf(abs_path, sizeof(abs_path), "%s/%s", pass_dir,
(spath) ? spath : "");
if (r < 0 || (size_t)r >= sizeof(abs_path))
- err_ret(-ENAMETOOLONG, "Path exceeded PATH_MAX");
+ return_err(-ENAMETOOLONG, "Path exceeded PATH_MAX");
r = stat(abs_path, &sbuf);
if (!r && (sbuf.st_mode & S_IFMT) == S_IFDIR)
return PASS_STORE_DIR;
r = snprintf(abs_path, sizeof(abs_path), "%s/%s.gpg", pass_dir, spath);
if (r < 0 || (size_t)r >= sizeof(abs_path))
- err_ret(-ENAMETOOLONG, "Path exceeded PATH_MAX");
+ return_err(-ENAMETOOLONG, "Path exceeded PATH_MAX");
r = stat(abs_path, &sbuf);
if (r < 0)
- err_ret(-errno, "%s", strerror(errno));
+ return_err(-errno, "%s", strerror(errno));
if ((sbuf.st_mode & S_IFMT) == S_IFREG) {
return PASS_STORE_ENC;
} else {
- err_ret(-EINVAL, "%s Not a regular file", abs_path);
+ return_err(-EINVAL, "%s Not a regular file", abs_path);
}
}
@@ -163,13 +163,13 @@ static int openstore(const char *spath, DIR **dirp)
store_type = pass_store_type(spath);
if (store_type != PASS_STORE_DIR)
- err_ret(-EINVAL, "%s Not a passwordstore path", spath);
+ return_err(-EINVAL, "%s Not a passwordstore path", spath);
if (spath) {
r = snprintf(abs_path, sizeof(abs_path), "%s/%s", pass_dir,
spath);
if (r < 0 || (size_t)r >= sizeof(abs_path))
- err_ret(-ENAMETOOLONG, "Path exceeded PATH_MAX");
+ return_err(-ENAMETOOLONG, "Path exceeded PATH_MAX");
path = abs_path;
} else {
@@ -178,7 +178,7 @@ static int openstore(const char *spath, DIR **dirp)
*dirp = opendir(path);
if (!*dirp)
- err_ret(-errno, "%s", strerror(errno));
+ return_err(-errno, "%s", strerror(errno));
return 0;
}
@@ -196,7 +196,7 @@ static int readstore(DIR *dirp, struct store *s)
if (dir == NULL) {
if (errno)
- err_ret(-errno, "%s", strerror(errno));
+ return_err(-errno, "%s", strerror(errno));
return 1;
}
@@ -229,7 +229,7 @@ int readstore_all(const char *path, struct store **stor)
size = DEF_STOR_SIZE;
*stor = malloc(sizeof(struct store) * size);
if (!*stor)
- err_ret(-errno, "%s", strerror(errno));
+ return_err(-errno, "%s", strerror(errno));
ret = openstore(path, &dirp);
if (ret < 0) {
@@ -247,7 +247,7 @@ int readstore_all(const char *path, struct store **stor)
*stor = p;
} else {
free(*stor);
- err_ret(-errno, "%s", strerror(errno));
+ return_err(-errno, "%s", strerror(errno));
}
}
if (len == 0)
@@ -264,30 +264,30 @@ int pass_init(const char *fpr)
r = set_pass_dir();
if (r < 0)
- err_ret(r, "PASSWORD_STORE_DIR must be set");
+ return_err(r, "PASSWORD_STORE_DIR must be set");
r = gpg_key_validate(fpr);
if (r < 0)
- err_ret(r, "Try gpg --full-generate-key");
+ return_err(r, "Try gpg --full-generate-key");
r = r_mkdir(pass_dir, S_IRWXU);
if (r < 0)
- err_ret(r, "%s %s", pass_dir, strerror(errno));
+ return_err(r, "%s %s", pass_dir, strerror(errno));
r = snprintf(gpg_id_path, sizeof(gpg_id_path), "%s/%s", pass_dir,
".gpg-id");
if (r < 0 || (size_t)r >= sizeof(gpg_id_path))
- err_ret(-ENAMETOOLONG, "Path exceeded PATH_MAX");
+ return_err(-ENAMETOOLONG, "Path exceeded PATH_MAX");
gpg_id = fopen(gpg_id_path, "w");
if (!gpg_id)
- err_ret(-errno, "%s %s", gpg_id_path, strerror(errno));
+ return_err(-errno, "%s %s", gpg_id_path, strerror(errno));
fpr_len = strlen(fpr);
r = fwrite(fpr, sizeof(*fpr), fpr_len, gpg_id);
fclose(gpg_id);
if (r != fpr_len)
- err_ret(-EPERM, "%s %s", gpg_id_path, "Write failed");
+ return_err(-EPERM, "%s %s", gpg_id_path, "Write failed");
return 0;
}
@@ -301,12 +301,12 @@ int pass_cat(FILE *out, const char *path)
if (ret < 0)
return ret;
if (ret != PASS_STORE_ENC)
- err_ret(-EINVAL, "%s is Not a password", path);
+ return_err(-EINVAL, "%s is Not a password", path);
ret = snprintf(pass_path, sizeof(pass_path), "%s/%s.gpg", pass_dir,
path);
if (ret < 0 || (size_t)ret >= sizeof(pass_path))
- err_ret(-ENAMETOOLONG, "Path exceeded PATH_MAX");
+ return_err(-ENAMETOOLONG, "Path exceeded PATH_MAX");
return gpg_decrypt(out, pass_path);
}
@@ -325,13 +325,13 @@ ssize_t pass_getpass(char **lineptr, FILE *stream)
new.c_lflag &= ~ECHO;
ret = tcsetattr(fileno(stream), TCSAFLUSH, &new);
if (ret < 0)
- err_ret(-errno, "%s", strerror(errno));
+ return_err(-errno, "%s", strerror(errno));
len = 0;
*lineptr = NULL;
ret = getline(lineptr, &len, stream);
if (ret < 0)
- err_ret(-errno, "%s", strerror(errno));
+ return_err(-errno, "%s", strerror(errno));
else if (ret > 0 && (*lineptr)[ret - 1] == '\n')
(*lineptr)[--ret] = '\0';
len = ret;
@@ -339,7 +339,7 @@ ssize_t pass_getpass(char **lineptr, FILE *stream)
ret = tcsetattr(fileno(stream), TCSAFLUSH, &old);
if (ret < 0) {
free(*lineptr);
- err_ret(-errno, "%s", strerror(errno));
+ return_err(-errno, "%s", strerror(errno));
}
return len;
@@ -352,15 +352,15 @@ int pass_gen(pass_gen_t gen, char *pass, int len)
int ret;
if (len <= 0)
- err_ret(-EINVAL, "Small password");
+ return_err(-EINVAL, "Small password");
rand = fopen("/dev/urandom", "r");
if (!rand)
- err_ret(-errno, "%s", strerror(errno));
+ return_err(-errno, "%s", strerror(errno));
ret = fread(pass, sizeof(pass[0]), len, rand);
if (ret != len)
- err_ret(-EPERM, "Failed to read /dev/urandom");
+ return_err(-EPERM, "Failed to read /dev/urandom");
pass_gen_len = strlen(pass_gen_set[gen]);
for (int i = 0; i < len; i++)
@@ -378,32 +378,32 @@ int pass_add(const char *path, const char *pass, size_t n)
ret = set_pass_dir();
if (ret < 0)
- err_ret(ret, "PASSWORD_STORE_DIR must be set");
+ return_err(ret, "PASSWORD_STORE_DIR must be set");
ret = snprintf(gpg_id_path, sizeof(gpg_id_path), "%s/%s", pass_dir,
".gpg-id");
if (ret < 0 || (size_t)ret >= sizeof(gpg_id_path))
- err_ret(-EINVAL, "Path exceeded PATH_MAX");
+ return_err(-EINVAL, "Path exceeded PATH_MAX");
gpg_id = fopen(gpg_id_path, "r");
if (!gpg_id)
- err_ret(-errno, "%s %s", gpg_id_path, strerror(errno));
+ return_err(-errno, "%s %s", gpg_id_path, strerror(errno));
p = fgets(fpr, sizeof(fpr), gpg_id);
if (!p)
- err_ret(-EPERM, "Failed to read %s", gpg_id_path);
+ return_err(-EPERM, "Failed to read %s", gpg_id_path);
fclose(gpg_id);
util_strtrim(fpr);
ret = gpg_key_validate(fpr);
if (ret < 0)
- err_ret(ret, "Invalid key , try gpg --list-keys");
+ return_err(ret, "Invalid key , try gpg --list-keys");
/* TODO: guard against .*\.gpg\.gpg[/$] */
ret = snprintf(pass_path, sizeof(pass_path), "%s/%s.gpg", pass_dir,
path);
if (ret < 0 || (size_t)ret >= sizeof(pass_path))
- err_ret(-errno, "Path exceeded PATH_MAX");
+ return_err(-errno, "Path exceeded PATH_MAX");
ret = r_mkdir(dirname(p), S_IRWXU);
if (ret < 0)
@@ -412,11 +412,11 @@ int pass_add(const char *path, const char *pass, size_t n)
errno = 0;
ret = access(pass_path, F_OK);
if (errno != ENOENT)
- err_ret(-EEXIST, "%s %s", path, strerror(EEXIST));
+ return_err(-EEXIST, "%s %s", path, strerror(EEXIST));
out_stream = fopen(pass_path, "w");
if (!out_stream)
- err_ret(-errno, "%s", strerror(errno));
+ return_err(-errno, "%s", strerror(errno));
ret = gpg_encrypt(out_stream, fpr, pass, n);
fclose(out_stream);
@@ -431,20 +431,20 @@ int pass_rm(const char *path)
ret = set_pass_dir();
if (ret < 0)
- err_ret(ret, "PASSWORD_STORE_DIR must be set");
+ return_err(ret, "PASSWORD_STORE_DIR must be set");
ret = snprintf(gpg_path, sizeof(gpg_path), "%s.gpg", path);
if (ret < 0 || (size_t)ret >= sizeof(gpg_path))
- err_ret(-EINVAL, "Path exceeded PATH_MAX");
+ return_err(-EINVAL, "Path exceeded PATH_MAX");
ret = snprintf(abs_path, sizeof(gpg_path), "%s/%s", pass_dir, gpg_path);
if (ret < 0 || (size_t)ret >= sizeof(abs_path))
- err_ret(-EINVAL, "Path exceeded PATH_MAX");
+ return_err(-EINVAL, "Path exceeded PATH_MAX");
/* TODO: guard against .*\.gpg\.gpg[/$] */
ret = unlink(abs_path);
if (ret < 0)
- err_ret(-errno, "%s %s", abs_path, strerror(errno));
+ return_err(-errno, "%s %s", abs_path, strerror(errno));
return r_rmdir_empty(pass_dir, dirname(gpg_path));
}