View | Details | Raw Unified | Return to bug 244181 | Differences between
and this patch

Collapse All | Expand All

(-)b/unzip.1 (+3 lines)
Lines 81-86 When extracting files from the zipfile, they are written to stdout. Link Here
81
The normal output is suppressed as if
81
The normal output is suppressed as if
82
.Fl q
82
.Fl q
83
was specified.
83
was specified.
84
.It Fl P Ar passphrase
85
Extract encrypted files using a passphrase. Putting a passphrase in
86
plaintext using this option is a bad idea.
84
.It Fl q
87
.It Fl q
85
Quiet: print less information while extracting.
88
Quiet: print less information while extracting.
86
.It Fl t
89
.It Fl t
(-)b/unzip.c (-3 / +47 lines)
Lines 55-60 Link Here
55
55
56
#include <archive.h>
56
#include <archive.h>
57
#include <archive_entry.h>
57
#include <archive_entry.h>
58
#include <readpassphrase.h>
59
58
60
59
/* command-line options */
61
/* command-line options */
60
static int		 a_opt;		/* convert EOL */
62
static int		 a_opt;		/* convert EOL */
Lines 68-73 static int n_opt; /* never overwrite */ Link Here
68
static int		 o_opt;		/* always overwrite */
70
static int		 o_opt;		/* always overwrite */
69
static int		 p_opt;		/* extract to stdout, quiet */
71
static int		 p_opt;		/* extract to stdout, quiet */
70
static int		 q_opt;		/* quiet */
72
static int		 q_opt;		/* quiet */
73
static char	*P_arg;		/* passphrase */
74
static int       P_arg_malloc;
71
static int		 t_opt;		/* test */
75
static int		 t_opt;		/* test */
72
static int		 u_opt;		/* update */
76
static int		 u_opt;		/* update */
73
static int		 v_opt;		/* verbose/list */
77
static int		 v_opt;		/* verbose/list */
Lines 851-856 test(struct archive *a, struct archive_entry *e) Link Here
851
	return error_count;
855
	return error_count;
852
}
856
}
853
857
858
/*
859
 * Callback function for reading one passphrase.
860
 * Originally from cpio.c and passphrase.c, libarchive.
861
 */
862
#define PPBUFF_SIZE 1024
863
static const char *
864
passphrase_callback(struct archive *a, void *_client_data)
865
{
866
	char **passphrase_buf = (char **)_client_data;
867
	char *p;
868
869
	if (*passphrase_buf == NULL) {
870
		*passphrase_buf = malloc(PPBUFF_SIZE);
871
		P_arg_malloc = 1;
872
		if (*passphrase_buf == NULL) {
873
			errno = ENOMEM;
874
			error("malloc()");
875
		}
876
	}
877
878
	p = readpassphrase("Enter passphrase:", *passphrase_buf,
879
		PPBUFF_SIZE, RPP_ECHO_OFF);
880
	
881
	if (p == NULL && errno != EINTR) {
882
		error("readpassphrase()");
883
	}
884
885
	return p;
886
}
887
854
/*
888
/*
855
 * Main loop: open the zipfile, iterate over its contents and decide what
889
 * Main loop: open the zipfile, iterate over its contents and decide what
856
 * to do with each entry.
890
 * to do with each entry.
Lines 881-886 unzip(const char *fn) Link Here
881
		}
915
		}
882
	}
916
	}
883
917
918
	if (P_arg) {
919
		archive_read_add_passphrase(a, P_arg);
920
	} else {
921
		archive_read_set_passphrase_callback(a, &P_arg, &passphrase_callback);
922
	}
923
884
	total_size = 0;
924
	total_size = 0;
885
	file_count = 0;
925
	file_count = 0;
886
	error_count = 0;
926
	error_count = 0;
Lines 953-959 getopts(int argc, char *argv[]) Link Here
953
#else
993
#else
954
	optreset = optind = 1;
994
	optreset = optind = 1;
955
#endif
995
#endif
956
	while ((opt = getopt(argc, argv, "aCcd:fjLlnopqtuvx:yZ1")) != -1)
996
	while ((opt = getopt(argc, argv, "aCcd:fjLlnopP:qtuvx:yZ1")) != -1)
957
		switch (opt) {
997
		switch (opt) {
958
		case '1':
998
		case '1':
959
			Z1_opt = 1;
999
			Z1_opt = 1;
Lines 993-998 getopts(int argc, char *argv[]) Link Here
993
		case 'p':
1033
		case 'p':
994
			p_opt = 1;
1034
			p_opt = 1;
995
			break;
1035
			break;
1036
		case 'P':
1037
			P_arg = optarg;
1038
			break;
996
		case 'q':
1039
		case 'q':
997
			q_opt = 1;
1040
			q_opt = 1;
998
			break;
1041
			break;
Lines 1069-1074 main(int argc, char *argv[]) Link Here
1069
		errorx("-n, -o and -u are contradictory");
1112
		errorx("-n, -o and -u are contradictory");
1070
1113
1071
	unzip(zipfile);
1114
	unzip(zipfile);
1072
1115
	if (P_arg_malloc) {
1116
		free(P_arg);
1117
	}
1073
	exit(0);
1118
	exit(0);
1074
}
1119
}
1075
- 

Return to bug 244181