From 5ce15da2f0ea4ebc33da1f9a5c3d49e66e437bb3 Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Sat, 30 Dec 2023 12:43:01 +0530 Subject: pass_util/getpass: init --- pass_util.c | 23 +++++++++++++++++++++++ pass_util.h | 3 +++ 2 files changed, 26 insertions(+) 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 #include #include +#include +#include #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 + #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); -- cgit v1.2.3