]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Do not ask passphrases when a passphrase was already specified with
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Sat, 4 Oct 2014 06:55:34 +0000 (15:55 +0900)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Sat, 4 Oct 2014 10:33:46 +0000 (19:33 +0900)
--passphrase option.

cpio/cpio.c
tar/read.c
tar/write.c

index 6dc22378fef15326fbcec21c372a59935153f7b9..c2f6f20decaa0f6e518bcb2c8e42fa1206f0b46e 100644 (file)
@@ -578,14 +578,14 @@ 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));
-       }
-       archive_write_set_passphrase_callback(cpio->archive, cpio,
-               &passphrase_callback);
+       if (cpio->passphrase != NULL)
+               r = archive_write_set_passphrase(cpio->archive,
+                       cpio->passphrase);
+       else
+               r = archive_write_set_passphrase_callback(cpio->archive, cpio,
+                       &passphrase_callback);
+       if (r != ARCHIVE_OK)
+               lafe_errc(1, 0, "%s", archive_error_string(cpio->archive));
 
        /*
         * The main loop:  Copy each file into the output archive.
@@ -952,12 +952,13 @@ 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));
-       }
-       archive_read_set_passphrase_callback(a, cpio, &passphrase_callback);
+       if (cpio->passphrase != NULL)
+               r = archive_read_add_passphrase(a, cpio->passphrase);
+       else
+               r = archive_read_set_passphrase_callback(a, cpio,
+                       &passphrase_callback);
+       if (r != ARCHIVE_OK)
+               lafe_errc(1, 0, "%s", archive_error_string(a));
 
        if (archive_read_open_filename(a, cpio->filename,
                                        cpio->bytes_per_block))
@@ -1061,12 +1062,13 @@ 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));
-       }
-       archive_read_set_passphrase_callback(a, cpio, &passphrase_callback);
+       if (cpio->passphrase != NULL)
+               r = archive_read_add_passphrase(a, cpio->passphrase);
+       else
+               r = archive_read_set_passphrase_callback(a, cpio,
+                       &passphrase_callback);
+       if (r != ARCHIVE_OK)
+               lafe_errc(1, 0, "%s", archive_error_string(a));
 
        if (archive_read_open_filename(a, cpio->filename,
                                        cpio->bytes_per_block))
index 1085771d4071f9add121cacb4e8e9212a76989c9..83815eda21700ffc778e71739b62961ce7e1263d 100644 (file)
@@ -205,12 +205,13 @@ 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));
-       }
-       archive_read_set_passphrase_callback(a, bsdtar, &passphrase_callback);
+       if (bsdtar->passphrase != NULL)
+               r = archive_read_add_passphrase(a, bsdtar->passphrase);
+       else
+               r = archive_read_set_passphrase_callback(a, bsdtar,
+                       &passphrase_callback);
+       if (r != 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 10342e48e524280ed47ccd1e67e5c5cd2996cce6..beaf98a0b4368ac60b329584286a5eecc7836ecc 100644 (file)
@@ -236,12 +236,13 @@ 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));
-       }
-       archive_write_set_passphrase_callback(a, bsdtar, &passphrase_callback);
+       if (bsdtar->passphrase != NULL)
+               r = archive_write_set_passphrase(a, bsdtar->passphrase);
+       else
+               r = archive_write_set_passphrase_callback(a, bsdtar,
+                       &passphrase_callback);
+       if (r != 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);
@@ -655,12 +656,13 @@ append_archive_filename(struct bsdtar *bsdtar, struct archive *a,
        archive_read_support_filter_all(ina);
        set_reader_options(bsdtar, ina);
        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));
-       }
-       archive_read_set_passphrase_callback(ina, bsdtar, &passphrase_callback);
+       if (bsdtar->passphrase != NULL)
+               rc = archive_read_add_passphrase(a, bsdtar->passphrase);
+       else
+               rc = archive_read_set_passphrase_callback(ina, bsdtar,
+                       &passphrase_callback);
+       if (rc != 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));