diff options
-rw-r--r-- | pass_util.c | 23 | ||||
-rw-r--r-- | pass_util.h | 3 |
2 files changed, 26 insertions, 0 deletions
diff --git a/pass_util.c b/pass_util.c index 47e72f2..b302c55 100644 --- a/pass_util.c +++ b/pass_util.c @@ -4,6 +4,8 @@ #include <string.h> #include <sys/stat.h> #include <linux/limits.h> +#include <termios.h> +#include <stdio.h> #include "pass_util.h" #include "util.h" @@ -113,3 +115,24 @@ const char *pass_cat(const char *path) r = gpg_decrypt(fpr, pass_path, pass_out, sizeof(pass_out)); return r ? NULL : pass_out; } + +size_t pass_getpass(char **lineptr, size_t *n, FILE *stream) +{ + int r; + struct termios new, old; + + r = tcgetattr(fileno(stream), &old); + if (r) + return -1; + + new = old; + new.c_lflag &= ~ECHO; + r = tcsetattr(fileno(stream), TCSAFLUSH, &new); + if (r) + return -1; + + r = getline (lineptr, n, stream); + (void) tcsetattr (fileno (stream), TCSAFLUSH, &old); + + return r; +} diff --git a/pass_util.h b/pass_util.h index 3ad4eed..1caf6cf 100644 --- a/pass_util.h +++ b/pass_util.h @@ -1,5 +1,8 @@ +#include <stdio.h> + #define PASS_MAX 4096 #define FPR_MAX 128 int pass_init(const char *fpr); const char *pass_cat(const char *path); +size_t pass_getpass(char **lineptr, size_t *n, FILE *stream); |