summaryrefslogtreecommitdiff
path: root/tar/util.c
diff options
context:
space:
mode:
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>2014-09-21 17:45:59 +0900
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>2014-09-21 17:45:59 +0900
commit9769e6f7d5683d79511b40c84fb1c60291e1b72d (patch)
tree36749ad03a5c6c1284ab36a32980051aeca709b4 /tar/util.c
parent96c38181092faa7b76773f00bb3260f87d9ffc0d (diff)
downloadlibarchive-9769e6f7d5683d79511b40c84fb1c60291e1b72d.tar.gz
Implement reading a passphrase from ttys.
Diffstat (limited to 'tar/util.c')
-rw-r--r--tar/util.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/tar/util.c b/tar/util.c
index b1b9b93d..45a912a8 100644
--- a/tar/util.c
+++ b/tar/util.c
@@ -61,6 +61,7 @@ __FBSDID("$FreeBSD: src/usr.bin/tar/util.c,v 1.23 2008/12/15 06:00:25 kientzle E
#include "bsdtar.h"
#include "err.h"
+#include "passphrase.h"
static size_t bsdtar_expand_char(char *, size_t, char);
static const char *strip_components(const char *path, int elements);
@@ -581,3 +582,28 @@ pathcmp(const char *a, const char *b)
/* They're really different, return the correct sign. */
return (*(const unsigned char *)a - *(const unsigned char *)b);
}
+
+#define PPBUFF_SIZE 1024
+const char *
+passphrase_callback(struct archive *a, void *_client_data)
+{
+ struct bsdtar *bsdtar = (struct bsdtar *)_client_data;
+ (void)a; /* UNUSED */
+
+ if (bsdtar->ppbuff == NULL) {
+ bsdtar->ppbuff = malloc(PPBUFF_SIZE);
+ if (bsdtar->ppbuff == NULL)
+ lafe_errc(1, errno, "Out of memory");
+ }
+ return lafe_readpassphrase("Enter passphrase:",
+ bsdtar->ppbuff, PPBUFF_SIZE);
+}
+
+void
+passphrase_free(char *ppbuff)
+{
+ if (ppbuff != NULL) {
+ memset(ppbuff, 0, PPBUFF_SIZE);
+ free(ppbuff);
+ }
+}