]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Add --passphrase option to bsdtar and bsdcpio.
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Tue, 16 Sep 2014 12:55:20 +0000 (21:55 +0900)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Tue, 16 Sep 2014 13:11:00 +0000 (22:11 +0900)
cpio/bsdcpio.1
cpio/cmdline.c
cpio/cpio.c
cpio/cpio.h
tar/bsdtar.1
tar/bsdtar.c
tar/bsdtar.h
tar/cmdline.c
tar/read.c
tar/write.c

index 9dee0eee8fc9de2824ca384295cf394be20e7dfe..f966aa06bb7f86dc067df4dfe6777a61351a09ea 100644 (file)
@@ -24,7 +24,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd August 14, 2014
+.Dd September 16, 2014
 .Dt CPIO 1
 .Os
 .Sh NAME
@@ -196,6 +196,15 @@ automatically on input.
 Compress the resulting archive with
 .Xr lzop 1 .
 In input mode, this option is ignored.
+.It Fl Fl passphrase Ar passphrase
+The
+.Pa passphrase
+is used to extract or create an encrypted archive.
+Currently, zip is only a format that
+.Nm
+can handle encrypted archives.
+You shouldn't use this option unless you realize how insecure
+use of this option is.
 .It Fl m , Fl Fl preserve-modification-time
 (i and p modes)
 Set file modification time on created files to match
index da44574f00e31a15b8e37d988485516d1a55df79..7e59536957a40806ff0a78ac6e106e3eceaa1b11 100644 (file)
@@ -81,6 +81,7 @@ static const struct option {
        { "null",                       0, '0' },
        { "numeric-uid-gid",            0, 'n' },
        { "owner",                      1, 'R' },
+       { "passphrase",                 1, OPTION_PASSPHRASE },
        { "pass-through",               0, 'p' },
        { "preserve-modification-time", 0, 'm' },
        { "preserve-owner",             0, OPTION_PRESERVE_OWNER },
index f1317505a673a348a86d5926ce90339943594b2b..569e4edd414f0d6bc134db1c57534fa684f5d894 100644 (file)
@@ -291,6 +291,9 @@ main(int argc, char *argv[])
                        cpio->mode = opt;
                        cpio->extract_flags &= ~ARCHIVE_EXTRACT_SECURE_NODOTDOT;
                        break;
+               case OPTION_PASSPHRASE:
+                       cpio->passphrase = cpio->argument;
+                       break;
                case OPTION_PRESERVE_OWNER:
                        cpio->extract_flags |= ARCHIVE_EXTRACT_OWNER;
                        break;
@@ -571,6 +574,12 @@ mode_out(struct cpio *cpio)
        cpio->linkresolver = archive_entry_linkresolver_new();
        archive_entry_linkresolver_set_strategy(cpio->linkresolver,
            archive_format(cpio->archive));
+       if (cpio->passphrase != NULL) {
+               if (archive_write_set_passphrase(cpio->archive,
+                   cpio->passphrase) != ARCHIVE_OK)
+                       lafe_errc(1, 0, "%s",
+                           archive_error_string(cpio->archive));
+       }
 
        /*
         * The main loop:  Copy each file into the output archive.
@@ -937,6 +946,11 @@ mode_in(struct cpio *cpio)
                lafe_errc(1, 0, "Couldn't allocate archive object");
        archive_read_support_filter_all(a);
        archive_read_support_format_all(a);
+       if (cpio->passphrase != NULL) {
+               if (archive_read_add_passphrase(a,
+                   cpio->passphrase) != ARCHIVE_OK)
+                       lafe_errc(1, 0, "%s", archive_error_string(a));
+       }
 
        if (archive_read_open_filename(a, cpio->filename,
                                        cpio->bytes_per_block))
@@ -1040,6 +1054,11 @@ mode_list(struct cpio *cpio)
                lafe_errc(1, 0, "Couldn't allocate archive object");
        archive_read_support_filter_all(a);
        archive_read_support_format_all(a);
+       if (cpio->passphrase != NULL) {
+               if (archive_read_add_passphrase(a,
+                   cpio->passphrase) != ARCHIVE_OK)
+                       lafe_errc(1, 0, "%s", archive_error_string(a));
+       }
 
        if (archive_read_open_filename(a, cpio->filename,
                                        cpio->bytes_per_block))
index c70ec5781a5d608e89230f0a2bd82d60bb6f803c..227ba53fe9bec9619d9d129d6cc61496ae1163d2 100644 (file)
@@ -71,6 +71,7 @@ struct cpio {
        int               gid_override;
        char             *gname_override;
        int               day_first; /* true if locale prefers day/mon */
+       const char       *passphrase;
 
        /* If >= 0, then close this when done. */
        int               fd;
@@ -104,6 +105,7 @@ enum {
        OPTION_LZ4,
        OPTION_LZMA,
        OPTION_LZOP,
+       OPTION_PASSPHRASE,
        OPTION_NO_PRESERVE_OWNER,
        OPTION_PRESERVE_OWNER,
        OPTION_QUIET,
index 4926245e92b8d2fb36df7f6817ac7c159a58f6d6..09402400f77225a24dfaadf3a9b58db5b9421e51 100644 (file)
@@ -24,7 +24,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd September 10, 2014
+.Dd September 16, 2014
 .Dt TAR 1
 .Os
 .Sh NAME
@@ -587,6 +587,15 @@ is being run by root and can be overridden by also specifying
 .Fl Fl no-same-owner
 and
 .Fl Fl no-same-permissions .
+.It Fl Fl passphrase Ar passphrase
+The
+.Pa passphrase
+is used to extract or create an encrypted archive.
+Currently, zip is only a format that
+.Nm
+can handle encrypted archives.
+You shouldn't use this option unless you realize how insecure
+use of this option is.
 .It Fl Fl posix
 (c, r, u mode only)
 Synonym for
index 30fbe0d7aa7570092832e78a98248811c6722b82..68c36579caf4587c38378c37079eb47e2f23dbd9 100644 (file)
@@ -549,6 +549,9 @@ main(int argc, char **argv)
                        bsdtar->extract_flags |= ARCHIVE_EXTRACT_FFLAGS;
                        bsdtar->extract_flags |= ARCHIVE_EXTRACT_MAC_METADATA;
                        break;
+               case OPTION_PASSPHRASE:
+                       bsdtar->passphrase = bsdtar->argument;
+                       break;
                case OPTION_POSIX: /* GNU tar */
                        cset_set_format(bsdtar->cset, "pax");
                        break;
index 53745adfa3251ac730cb293f72465b623deddb85..43893ca214278b0a347df73a41b0bb6423435ccd 100644 (file)
@@ -57,6 +57,7 @@ struct bsdtar {
        const char       *gname; /* --gname */
        int               uid;  /* --uid */
        const char       *uname; /* --uname */
+       const char       *passphrase; /* --passphrase */
        char              mode; /* Program mode: 'c', 't', 'r', 'u', 'x' */
        char              symlink_mode; /* H or L, per BSD conventions */
        char              option_absolute_paths; /* -P */
@@ -149,6 +150,7 @@ enum {
        OPTION_OLDER_MTIME_THAN,
        OPTION_ONE_FILE_SYSTEM,
        OPTION_OPTIONS,
+       OPTION_PASSPHRASE,
        OPTION_POSIX,
        OPTION_SAME_OWNER,
        OPTION_STRIP_COMPONENTS,
index a3562ffcd6be19152591409ea3b3744c06287744..974b6af89fc117247f171812d8f9583513673c95 100644 (file)
@@ -129,6 +129,7 @@ static const struct bsdtar_option {
        { "older-than",           1, OPTION_OLDER_CTIME_THAN },
        { "one-file-system",      0, OPTION_ONE_FILE_SYSTEM },
        { "options",              1, OPTION_OPTIONS },
+       { "passphrase",           1, OPTION_PASSPHRASE },
        { "posix",                0, OPTION_POSIX },
        { "preserve-permissions", 0, 'p' },
        { "read-full-blocks",     0, 'B' },
index fdf34b887b6b0b0cebfe99ced2d1f61f60f87786..9ae33a6456f5b19230b57262dc3a387abcc3a12c 100644 (file)
@@ -205,6 +205,11 @@ read_archive(struct bsdtar *bsdtar, char mode, struct archive *writer)
                if (archive_read_set_options(a,
                    "read_concatenated_archives") != ARCHIVE_OK)
                        lafe_errc(1, 0, "%s", archive_error_string(a));
+       if (bsdtar->passphrase != NULL) {
+               if (archive_read_add_passphrase(a,
+                   bsdtar->passphrase) != ARCHIVE_OK)
+                       lafe_errc(1, 0, "%s", archive_error_string(a));
+       }
        if (archive_read_open_filename(a, bsdtar->filename,
                                        bsdtar->bytes_per_block))
                lafe_errc(1, 0, "Error opening archive: %s",
index 7e8cb13f8ce1f8cd404621c1634e81645ceaf5ce..dd326bd7046398e07706560de02f862e34b0ce1d 100644 (file)
@@ -236,6 +236,11 @@ tar_mode_c(struct bsdtar *bsdtar)
        }
 
        set_writer_options(bsdtar, a);
+       if (bsdtar->passphrase != NULL) {
+               if (archive_write_set_passphrase(a,
+                   bsdtar->passphrase) != ARCHIVE_OK)
+                       lafe_errc(1, 0, "%s", archive_error_string(a));
+       }
        if (ARCHIVE_OK != archive_write_open_filename(a, bsdtar->filename))
                lafe_errc(1, 0, "%s", archive_error_string(a));
        write_archive(a, bsdtar);
@@ -649,6 +654,11 @@ append_archive_filename(struct bsdtar *bsdtar, struct archive *a,
        archive_read_support_filter_all(ina);
        set_reader_options(bsdtar, a);
        archive_read_set_options(ina, "mtree:checkfs");
+       if (bsdtar->passphrase != NULL) {
+               if (archive_read_add_passphrase(a,
+                   bsdtar->passphrase) != ARCHIVE_OK)
+                       lafe_errc(1, 0, "%s", archive_error_string(a));
+       }
        if (archive_read_open_filename(ina, filename,
                                        bsdtar->bytes_per_block)) {
                lafe_warnc(0, "%s", archive_error_string(ina));