pass

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

commit 035fb0bc5019ec15044538ba94874e82a236bdcb
parent 2a8575caa345795b2b831ab19dc90cdc7d9fb168
Author: Naveen Narayanan zerous <zerous@nocebo.space>
Date:   Tue, 26 Dec 2017 18:06:06 +0300

Delete empty dir. Accept i/p from pipe.

Diffstat:
pass.c | 71+++++++++++++++++++++++++++++++++++++++++------------------------------
1 file changed, 41 insertions(+), 30 deletions(-)

diff --git a/pass.c b/pass.c @@ -32,9 +32,8 @@ initgpgme(void) void delete(char *item) { - char *home; + char *home, *l; int r; - struct sb; if (!(home = getenv("HOME"))) fatalx("$HOME not set, cannot determine password-store location"); @@ -42,12 +41,13 @@ delete(char *item) printf("Are you sure you would like to delete %s? [y/N] ", item); if ((r = getchar()) == 'N') exit(0); - else if (r == 'y') { - if (remove(file)) { - logwarn("rm %s", item); - } - } + else if (r == 'y' && !remove(file)) { printf("removed '%s'\n", file); + + if ((l = strrchr(file, '/'))) + *l = '\0'; + rmdir(file); /* remove folder if empty */ + } } void @@ -178,8 +178,11 @@ insert(char *item) const char *home; FILE *fp, *fin, *fout; char uid[128], pass[128]; + int c, fd; key = NULL; + c = 'y'; + fd = fileno(stdin); if (!(home = getenv("HOME"))) fatalx("$HOME not set, cannot determine password-store location"); @@ -189,35 +192,46 @@ insert(char *item) mkdirp(item); memcpy(t, file, strlen(file) + 1); snprintf(file, sizeof(file), "%s/%s", t, filename); - snprintf(t, sizeof(t), "%s.gpg", file); if ((fp = fopen(t, "r"))) { - printf("An entry already exists for %s. Overwrite it? [y/N] ", filename); - if (getchar() == 'N') { - logdbgx("Don't overwrite"); - exit(1); + if (isatty(fd)) { + printf("An entry already exists for %s. Overwrite it? [y/N] ", filename); + if ((c = getchar()) == 'N') { + fclose(fp); + logdbgx("Don't overwrite"); + exit(1); + } + } else { + /* Assuming user knows what he/she is doing */ + printf("Overwriting %s\n", filename); + c = 'y'; } } - printf("file: %s\n", file); + if (c != 'Y' && c != 'y') + exit(1); if (!(fp = fopen(file, "w+b"))) fatal("fopen: %s", file); - readpassphrase("Enter password: ", pass, 128, RPP_ECHO_OFF); - memcpy(t, pass, strlen(pass) + 1); - readpassphrase("Retype password: ", pass, 128, RPP_ECHO_OFF); - if (!strcmp(pass, t)) - { - int i = 0; - while(t[i] != '\0') { - if (fputc(t[i], fp) == EOF) - fatal("fputc: %s", file); - i++; + if (isatty(fd)) { + printf("2\n"); + readpassphrase("Enter password: ", pass, 128, RPP_ECHO_OFF); + memcpy(t, pass, strlen(pass) + 1); + readpassphrase("Retype password: ", pass, 128, RPP_ECHO_OFF); + if (!strcmp(pass, t)) + { + int i = 0; + while(t[i] != '\0') { + if (fputc(t[i], fp) == EOF) + fatal("fputc: %s", file); + i++; + } + } else { + fatalx("Passwords don't match."); } } else { - if (debug) - fatalx("Passwords don't match."); - else - fatalx("Passwords don't match."); + int c; + while ((c = getchar()) != EOF && c != '\n') + fputc(c, fp); } fclose(fp); getuserid(uid); @@ -326,9 +340,6 @@ initpass(char *pgpid) fatal("mkdir"); snprintf(file, sizeof(file), "%s/.password-store/.gpg-id", home); -#ifdef DEBUG - printf("file: %s", file); -#endif if (!(gpg = fopen(file, "a"))) fatal("fopen");