Index: usr.bin/unzip/unzip.1 =================================================================== --- usr.bin/unzip/unzip.1 +++ usr.bin/unzip/unzip.1 @@ -35,6 +35,7 @@ .Nm .Op Fl aCcfjLlnopqtuvy .Op Fl d Ar dir +.Op Fl P Ar passphrase .Ar zipfile .Sh DESCRIPTION .\" ... @@ -75,6 +76,9 @@ When extracting a file from the zipfile, if a file with the same name already exists on disk, the existing file is replaced with the file from the zipfile. +.It Fl P Ar passphrase +When archive file is encrypted by WinZip or PKWARE encryption, use +passphrase to decrypt it. .It Fl p Extract to stdout. When extracting files from the zipfile, they are written to stdout. Index: usr.bin/unzip/unzip.c =================================================================== --- usr.bin/unzip/unzip.c +++ usr.bin/unzip/unzip.c @@ -62,6 +62,7 @@ static int L_opt; /* lowercase names */ static int n_opt; /* never overwrite */ static int o_opt; /* always overwrite */ +static const char *P_arg; /* passphrase */ static int p_opt; /* extract to stdout, quiet */ static int q_opt; /* quiet */ static int t_opt; /* test */ @@ -869,6 +870,9 @@ if ((a = archive_read_new()) == NULL) error("archive_read_new failed"); + if (P_arg != NULL) + ac(archive_read_add_passphrase(a, P_arg)); + ac(archive_read_support_format_zip(a)); ac(archive_read_open_filename(a, fn, 8192)); @@ -940,7 +944,7 @@ usage(void) { - fprintf(stderr, "Usage: unzip [-aCcfjLlnopqtuvyZ1] [-d dir] [-x pattern] " + fprintf(stderr, "Usage: unzip [-aCcfjLlnopqtuvyZ1] [-d dir] [-P passphrase] [-x pattern] " "zipfile\n"); exit(1); } @@ -951,7 +955,7 @@ int opt; optreset = optind = 1; - while ((opt = getopt(argc, argv, "aCcd:fjLlnopqtuvx:yZ1")) != -1) + while ((opt = getopt(argc, argv, "aCcd:fjLlnoP:pqtuvx:yZ1")) != -1) switch (opt) { case '1': Z1_opt = 1; @@ -991,6 +995,9 @@ case 'p': p_opt = 1; break; + case 'P': + P_arg = optarg; + break; case 'q': q_opt = 1; break;