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 /cpio/cpio.c | |
parent | 96c38181092faa7b76773f00bb3260f87d9ffc0d (diff) | |
download | libarchive-9769e6f7d5683d79511b40c84fb1c60291e1b72d.tar.gz |
Implement reading a passphrase from ttys.
Diffstat (limited to 'cpio/cpio.c')
-rw-r--r-- | cpio/cpio.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/cpio/cpio.c b/cpio/cpio.c index 569e4edd..6dc22378 100644 --- a/cpio/cpio.c +++ b/cpio/cpio.c @@ -82,6 +82,7 @@ __FBSDID("$FreeBSD: src/usr.bin/cpio/cpio.c,v 1.15 2008/12/06 07:30:40 kientzle #include "cpio.h" #include "err.h" #include "line_reader.h" +#include "passphrase.h" /* Fixed size of uname/gname caches. */ #define name_cache_size 101 @@ -123,6 +124,8 @@ static int restore_time(struct cpio *, struct archive_entry *, const char *, int fd); static void usage(void); static void version(void); +static const char * passphrase_callback(struct archive *, void *); +static void passphrase_free(char *); int main(int argc, char *argv[]) @@ -422,6 +425,7 @@ main(int argc, char *argv[]) free_cache(cpio->gname_cache); free_cache(cpio->uname_cache); free(cpio->destdir); + passphrase_free(cpio->ppbuff); return (cpio->return_value); } @@ -580,6 +584,8 @@ mode_out(struct cpio *cpio) lafe_errc(1, 0, "%s", archive_error_string(cpio->archive)); } + archive_write_set_passphrase_callback(cpio->archive, cpio, + &passphrase_callback); /* * The main loop: Copy each file into the output archive. @@ -951,6 +957,7 @@ mode_in(struct cpio *cpio) cpio->passphrase) != ARCHIVE_OK) lafe_errc(1, 0, "%s", archive_error_string(a)); } + archive_read_set_passphrase_callback(a, cpio, &passphrase_callback); if (archive_read_open_filename(a, cpio->filename, cpio->bytes_per_block)) @@ -1059,6 +1066,7 @@ mode_list(struct cpio *cpio) cpio->passphrase) != ARCHIVE_OK) lafe_errc(1, 0, "%s", archive_error_string(a)); } + archive_read_set_passphrase_callback(a, cpio, &passphrase_callback); if (archive_read_open_filename(a, cpio->filename, cpio->bytes_per_block)) @@ -1430,3 +1438,28 @@ cpio_i64toa(int64_t n0) *--p = '-'; return p; } + +#define PPBUFF_SIZE 1024 +static const char * +passphrase_callback(struct archive *a, void *_client_data) +{ + struct cpio *cpio = (struct cpio *)_client_data; + (void)a; /* UNUSED */ + + if (cpio->ppbuff == NULL) { + cpio->ppbuff = malloc(PPBUFF_SIZE); + if (cpio->ppbuff == NULL) + lafe_errc(1, errno, "Out of memory"); + } + return lafe_readpassphrase("Enter passphrase:", + cpio->ppbuff, PPBUFF_SIZE); +} + +static void +passphrase_free(char *ppbuff) +{ + if (ppbuff != NULL) { + memset(ppbuff, 0, PPBUFF_SIZE); + free(ppbuff); + } +} |