aboutsummaryrefslogtreecommitdiff
path: root/pass_util.c
diff options
context:
space:
mode:
authorsinanmohd <sinan@sinanmohd.com>2023-12-30 12:43:01 +0530
committersinanmohd <sinan@sinanmohd.com>2023-12-30 12:43:01 +0530
commit5ce15da2f0ea4ebc33da1f9a5c3d49e66e437bb3 (patch)
tree26890299397a7317d9f5c32c1442d503776c08d6 /pass_util.c
parented6dbc0f80adb0db3d7206464b8a66c3417d972a (diff)
pass_util/getpass: init
Diffstat (limited to 'pass_util.c')
-rw-r--r--pass_util.c23
1 files changed, 23 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;
+}