pass

A stripped down version of the standard unix password manager "pass"
git clone git://nocebo.space/pass
Log | Files | Refs | LICENSE

commit 0edfc8fcfbcbdaed791d2e865edb8f0cbe0f1b57
parent 2803e5bcc8a53c200a80730c5176cb47e661069e
Author: Naveen Narayanan zerous <zerous@nocebo.space>
Date:   Fri, 29 Dec 2017 13:07:17 +0300

add global const char *home

Diffstat:
pass.c | 39++++++++++++++++-----------------------
1 file changed, 16 insertions(+), 23 deletions(-)

diff --git a/pass.c b/pass.c @@ -17,6 +17,7 @@ #define MAX_BUFSIZ 512 static char file[PATH_MAX]; +const char *home; void initgpgme(void) @@ -31,18 +32,25 @@ initgpgme(void) } void +gethomedir(void) +{ + if (!(home = getenv("HOME"))) + fatalx("$HOME not set, cannot determine password-store location"); +} + + +void delete(char *item) { - char *home, *l; + char *l; int r; - if (!(home = getenv("HOME"))) - fatalx("$HOME not set, cannot determine password-store location"); + gethomedir(); snprintf(file, sizeof(file), "%s/.password-store/%s.gpg", home, item); printf("Are you sure you would like to delete %s? [y/N] ", item); - if ((r = getchar()) == 'N') + if ((r = getchar()) == 'N' || r == 'n') exit(0); - else if (r == 'y' && !remove(file)) { + else if ((r == 'y' || r == 'Y') && !remove(file)) { printf("removed '%s'\n", file); if ((l = strrchr(file, '/'))) *l = '\0'; @@ -104,11 +112,9 @@ void printpass(char *item) { char buf[MAX_BUFSIZ]; - const char* home; int fin; - if (!(home = getenv("HOME"))) - fatalx("$HOME not set, cannot determine password-store location"); + gethomedir(); snprintf(file, sizeof(file), "%s/.password-store/%s.gpg", home, item); /* Check if file exists */ fin = open(file, O_RDONLY); @@ -123,12 +129,9 @@ void getuserid(char *u, int usize) { char file[PATH_MAX]; - const char* home; FILE *fp; int i; - if (!(home = getenv("HOME"))) - fatalx("$HOME not set, cannot determine password-store location"); snprintf(file, sizeof(file), "%s/.password-store/.gpg-id", home); fp = fopen(file, "r"); if (!fp) @@ -217,7 +220,6 @@ void insert(char *item) { char *filename, t[PATH_MAX]; - const char *home; FILE *fp; char pass[MAX_BUFSIZ]; int c, fd; @@ -225,8 +227,7 @@ insert(char *item) c = 'y'; fd = fileno(stdin); - if (!(home = getenv("HOME"))) - fatalx("$HOME not set, cannot determine password-store location"); + gethomedir(); snprintf(file, sizeof(file), "%s/.password-store", home); filename = basename(item); mkdirp(item); @@ -277,12 +278,9 @@ int isinit(void) { int fp; - const char *home; - char file[PATH_MAX]; struct stat sb; - if (!(home = getenv("HOME"))) - fatalx("$HOME not set, cannot determine password-store location"); + gethomedir(); snprintf(file, sizeof(file), "%s/.password-store", home); if ((fp = open(file, O_RDONLY)) != -1 && (!fstat(fp, &sb)) && @@ -296,8 +294,6 @@ isinit(void) void initpass(char *pgpid) { - char file[PATH_MAX]; - const char* home; FILE *gpg; mode_t mode = S_IRWXU; @@ -306,9 +302,6 @@ initpass(char *pgpid) } if (!isinit()) { - if (!(home = getenv("HOME"))) - fatalx("$HOME not set, cannot determine password-store location"); - snprintf(file, sizeof(file), "%s/.password-store", home); if (mkdir(file, mode)) fatal("mkdir"); snprintf(file, sizeof(file), "%s/.password-store/.gpg-id", home);