diff options
author | Michihiro NAKAJIMA <ggcueroad@gmail.com> | 2014-09-21 17:45:59 +0900 |
---|---|---|
committer | Michihiro NAKAJIMA <ggcueroad@gmail.com> | 2014-09-21 17:45:59 +0900 |
commit | 9769e6f7d5683d79511b40c84fb1c60291e1b72d (patch) | |
tree | 36749ad03a5c6c1284ab36a32980051aeca709b4 /tar/util.c | |
parent | 96c38181092faa7b76773f00bb3260f87d9ffc0d (diff) | |
download | libarchive-9769e6f7d5683d79511b40c84fb1c60291e1b72d.tar.gz |
Implement reading a passphrase from ttys.
Diffstat (limited to 'tar/util.c')
-rw-r--r-- | tar/util.c | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -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); + } +} |