Lines 51-56
Link Here
|
51 |
|
51 |
|
52 |
#include <archive.h> |
52 |
#include <archive.h> |
53 |
#include <archive_entry.h> |
53 |
#include <archive_entry.h> |
|
|
54 |
#include <readpassphrase.h> |
54 |
|
55 |
|
55 |
/* command-line options */ |
56 |
/* command-line options */ |
56 |
static int a_opt; /* convert EOL */ |
57 |
static int a_opt; /* convert EOL */ |
Lines 64-69
Link Here
|
64 |
static int o_opt; /* always overwrite */ |
65 |
static int o_opt; /* always overwrite */ |
65 |
static int p_opt; /* extract to stdout, quiet */ |
66 |
static int p_opt; /* extract to stdout, quiet */ |
66 |
static int q_opt; /* quiet */ |
67 |
static int q_opt; /* quiet */ |
|
|
68 |
static char *P_arg; /* passphrase */ |
67 |
static int t_opt; /* test */ |
69 |
static int t_opt; /* test */ |
68 |
static int u_opt; /* update */ |
70 |
static int u_opt; /* update */ |
69 |
static int v_opt; /* verbose/list */ |
71 |
static int v_opt; /* verbose/list */ |
Lines 95-100
Link Here
|
95 |
*/ |
97 |
*/ |
96 |
static int noeol; |
98 |
static int noeol; |
97 |
|
99 |
|
|
|
100 |
/* for an interactive passphrase input */ |
101 |
static char *passphrase_buf; |
102 |
|
98 |
/* fatal error message + errno */ |
103 |
/* fatal error message + errno */ |
99 |
static void |
104 |
static void |
100 |
error(const char *fmt, ...) |
105 |
error(const char *fmt, ...) |
Lines 848-853
Link Here
|
848 |
} |
853 |
} |
849 |
|
854 |
|
850 |
/* |
855 |
/* |
|
|
856 |
* Callback function for reading passphrase. |
857 |
* Originally from cpio.c and passphrase.c, libarchive. |
858 |
*/ |
859 |
#define PPBUFF_SIZE 1024 |
860 |
static const char * |
861 |
passphrase_callback(struct archive *a, void *_client_data) |
862 |
{ |
863 |
char *passphrase_buf = _client_data; |
864 |
char *p; |
865 |
|
866 |
(void)a; /* UNUSED */ |
867 |
|
868 |
if (passphrase_buf == NULL) { |
869 |
passphrase_buf = malloc(PPBUFF_SIZE); |
870 |
if (passphrase_buf == NULL) { |
871 |
errno = ENOMEM; |
872 |
error("malloc()"); |
873 |
} |
874 |
} |
875 |
|
876 |
p = readpassphrase("\nEnter passphrase:", passphrase_buf, |
877 |
PPBUFF_SIZE, RPP_ECHO_OFF); |
878 |
|
879 |
if (p == NULL && errno != EINTR) |
880 |
error("readpassphrase()"); |
881 |
|
882 |
return p; |
883 |
} |
884 |
|
885 |
/* |
851 |
* Main loop: open the zipfile, iterate over its contents and decide what |
886 |
* Main loop: open the zipfile, iterate over its contents and decide what |
852 |
* to do with each entry. |
887 |
* to do with each entry. |
853 |
*/ |
888 |
*/ |
Lines 863-868
Link Here
|
863 |
error("archive_read_new failed"); |
898 |
error("archive_read_new failed"); |
864 |
|
899 |
|
865 |
ac(archive_read_support_format_zip(a)); |
900 |
ac(archive_read_support_format_zip(a)); |
|
|
901 |
|
902 |
if (P_arg) |
903 |
archive_read_add_passphrase(a, P_arg); |
904 |
else |
905 |
archive_read_set_passphrase_callback(a, passphrase_buf, &passphrase_callback); |
906 |
|
866 |
ac(archive_read_open_filename(a, fn, 8192)); |
907 |
ac(archive_read_open_filename(a, fn, 8192)); |
867 |
|
908 |
|
868 |
if (!zipinfo_mode) { |
909 |
if (!zipinfo_mode) { |
Lines 919-924
Link Here
|
919 |
ac(archive_read_close(a)); |
960 |
ac(archive_read_close(a)); |
920 |
(void)archive_read_free(a); |
961 |
(void)archive_read_free(a); |
921 |
|
962 |
|
|
|
963 |
if (passphrase_buf != NULL) { |
964 |
memset(passphrase_buf, 0, PPBUFF_SIZE); |
965 |
free(passphrase_buf); |
966 |
} |
967 |
|
922 |
if (t_opt) { |
968 |
if (t_opt) { |
923 |
if (error_count > 0) { |
969 |
if (error_count > 0) { |
924 |
errorx("%ju checksum error(s) found.", error_count); |
970 |
errorx("%ju checksum error(s) found.", error_count); |
Lines 934-940
Link Here
|
934 |
usage(void) |
980 |
usage(void) |
935 |
{ |
981 |
{ |
936 |
|
982 |
|
937 |
fprintf(stderr, "Usage: unzip [-aCcfjLlnopqtuvyZ1] [-d dir] [-x pattern] " |
983 |
fprintf(stderr, "Usage: unzip [-aCcfjLlnopPqtuvyZ1] [-d dir] [-x pattern] " |
938 |
"zipfile\n"); |
984 |
"zipfile\n"); |
939 |
exit(1); |
985 |
exit(1); |
940 |
} |
986 |
} |
Lines 945-951
Link Here
|
945 |
int opt; |
991 |
int opt; |
946 |
|
992 |
|
947 |
optreset = optind = 1; |
993 |
optreset = optind = 1; |
948 |
while ((opt = getopt(argc, argv, "aCcd:fjLlnopqtuvx:yZ1")) != -1) |
994 |
while ((opt = getopt(argc, argv, "aCcd:fjLlnopP:qtuvx:yZ1")) != -1) |
949 |
switch (opt) { |
995 |
switch (opt) { |
950 |
case '1': |
996 |
case '1': |
951 |
Z1_opt = 1; |
997 |
Z1_opt = 1; |
Lines 984-989
Link Here
|
984 |
break; |
1030 |
break; |
985 |
case 'p': |
1031 |
case 'p': |
986 |
p_opt = 1; |
1032 |
p_opt = 1; |
|
|
1033 |
break; |
1034 |
case 'P': |
1035 |
P_arg = optarg; |
987 |
break; |
1036 |
break; |
988 |
case 'q': |
1037 |
case 'q': |
989 |
q_opt = 1; |
1038 |
q_opt = 1; |