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 / +48 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 */
71
static int		 t_opt;		/* test */
74
static int		 t_opt;		/* test */
72
static int		 u_opt;		/* update */
75
static int		 u_opt;		/* update */
73
static int		 v_opt;		/* verbose/list */
76
static int		 v_opt;		/* verbose/list */
Lines 851-856 test(struct archive *a, struct archive_entry *e) Link Here
851
	return error_count;
854
	return error_count;
852
}
855
}
853
856
857
/*
858
 * Callback function for reading one passphrase.
859
 * Originally from cpio.c and passphrase.c, libarchive.
860
 */
861
#define PPBUFF_SIZE 1024
862
static const char *
863
passphrase_callback(struct archive *a, void *_client_data)
864
{
865
	char **passphrase_buf = (char **)_client_data;
866
	char *p;
867
868
	if (*passphrase_buf == NULL) {
869
		*passphrase_buf = malloc(PPBUFF_SIZE);
870
		P_arg_malloc = 1;
871
		if (*passphrase_buf == NULL) {
872
			errno = ENOMEM;
873
			error("malloc()");
874
		}
875
	}
876
877
	p = readpassphrase("Enter passphrase:", *passphrase_buf,
878
		PPBUFF_SIZE, RPP_ECHO_OFF);
879
	
880
	if (p == NULL && errno != EINTR) {
881
		error("readpassphrase()");
882
	}
883
884
	return p;
885
}
886
854
/*
887
/*
855
 * Main loop: open the zipfile, iterate over its contents and decide what
888
 * Main loop: open the zipfile, iterate over its contents and decide what
856
 * to do with each entry.
889
 * to do with each entry.
Lines 881-886 unzip(const char *fn) Link Here
881
		}
914
		}
882
	}
915
	}
883
916
917
	if (P_arg) {
918
		archive_read_add_passphrase(a, P_arg);
919
	} else {
920
		archive_read_set_passphrase_callback(a, &P_arg, &passphrase_callback);
921
	}
922
884
	total_size = 0;
923
	total_size = 0;
885
	file_count = 0;
924
	file_count = 0;
886
	error_count = 0;
925
	error_count = 0;
Lines 932-937 unzip(const char *fn) Link Here
932
			       fn);
971
			       fn);
933
		}
972
		}
934
	}
973
	}
974
975
	if (P_arg_malloc) {
976
		free(P_arg);
977
		P_arg = NULL;
978
	}
935
}
979
}
936
980
937
static void
981
static void
Lines 953-959 getopts(int argc, char *argv[]) Link Here
953
#else
997
#else
954
	optreset = optind = 1;
998
	optreset = optind = 1;
955
#endif
999
#endif
956
	while ((opt = getopt(argc, argv, "aCcd:fjLlnopqtuvx:yZ1")) != -1)
1000
	while ((opt = getopt(argc, argv, "aCcd:fjLlnopP:qtuvx:yZ1")) != -1)
957
		switch (opt) {
1001
		switch (opt) {
958
		case '1':
1002
		case '1':
959
			Z1_opt = 1;
1003
			Z1_opt = 1;
Lines 993-998 getopts(int argc, char *argv[]) Link Here
993
		case 'p':
1037
		case 'p':
994
			p_opt = 1;
1038
			p_opt = 1;
995
			break;
1039
			break;
1040
		case 'P':
1041
			P_arg = optarg;
1042
			break;
996
		case 'q':
1043
		case 'q':
997
			q_opt = 1;
1044
			q_opt = 1;
998
			break;
1045
			break;
Lines 1069-1074 main(int argc, char *argv[]) Link Here
1069
		errorx("-n, -o and -u are contradictory");
1116
		errorx("-n, -o and -u are contradictory");
1070
1117
1071
	unzip(zipfile);
1118
	unzip(zipfile);
1072
1073
	exit(0);
1119
	exit(0);
1074
}
1120
}
1075
- 

Return to bug 244181