aboutsummaryrefslogtreecommitdiff
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
parented6dbc0f80adb0db3d7206464b8a66c3417d972a (diff)
pass_util/getpass: init
-rw-r--r--pass_util.c23
-rw-r--r--pass_util.h3
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);