From: Michihiro NAKAJIMA Date: Sat, 4 Oct 2014 06:55:34 +0000 (+0900) Subject: Do not ask passphrases when a passphrase was already specified with X-Git-Tag: v3.1.900a~199 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b5af190b7eb85efebcd06c971fa03549436572f2;p=thirdparty%2Flibarchive.git Do not ask passphrases when a passphrase was already specified with --passphrase option. --- diff --git a/cpio/cpio.c b/cpio/cpio.c index 6dc22378f..c2f6f20de 100644 --- a/cpio/cpio.c +++ b/cpio/cpio.c @@ -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)) diff --git a/tar/read.c b/tar/read.c index 1085771d4..83815eda2 100644 --- a/tar/read.c +++ b/tar/read.c @@ -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", diff --git a/tar/write.c b/tar/write.c index 10342e48e..beaf98a0b 100644 --- a/tar/write.c +++ b/tar/write.c @@ -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));