diff options
author | Martin Matuska <mm@FreeBSD.org> | 2024-04-26 10:11:59 +0000 |
---|---|---|
committer | Martin Matuska <mm@FreeBSD.org> | 2024-04-26 10:11:59 +0000 |
commit | d6f77d3cfa8e56aed99e2ea250fdb242f51747df (patch) | |
tree | c54748bd439b0fa85deafd8f4915301a16d1acd7 /libarchive/archive_write_set_passphrase.c | |
parent | a509d68f27b9f114b876bbe3b9caa9d0ee0c5606 (diff) | |
download | src-d6f77d3cfa8e56aed99e2ea250fdb242f51747df.tar.gz src-d6f77d3cfa8e56aed99e2ea250fdb242f51747df.zip |
Diffstat (limited to 'libarchive/archive_write_set_passphrase.c')
-rw-r--r-- | libarchive/archive_write_set_passphrase.c | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/libarchive/archive_write_set_passphrase.c b/libarchive/archive_write_set_passphrase.c index 977fc4a9ee6b..f871c8e2f810 100644 --- a/libarchive/archive_write_set_passphrase.c +++ b/libarchive/archive_write_set_passphrase.c @@ -30,14 +30,9 @@ #endif #include "archive_write_private.h" -int -archive_write_set_passphrase(struct archive *_a, const char *p) +static int +set_passphrase(struct archive_write *a, const char *p) { - struct archive_write *a = (struct archive_write *)_a; - - archive_check_magic(_a, ARCHIVE_WRITE_MAGIC, ARCHIVE_STATE_NEW, - "archive_write_set_passphrase"); - if (p == NULL || p[0] == '\0') { archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Empty passphrase is unacceptable"); @@ -55,6 +50,18 @@ archive_write_set_passphrase(struct archive *_a, const char *p) int +archive_write_set_passphrase(struct archive *_a, const char *p) +{ + struct archive_write *a = (struct archive_write *)_a; + + archive_check_magic(_a, ARCHIVE_WRITE_MAGIC, ARCHIVE_STATE_NEW, + "archive_write_set_passphrase"); + + return (set_passphrase(a, p)); +} + + +int archive_write_set_passphrase_callback(struct archive *_a, void *client_data, archive_passphrase_callback *cb) { @@ -80,15 +87,9 @@ __archive_write_get_passphrase(struct archive_write *a) const char *p; p = a->passphrase_callback(&a->archive, a->passphrase_client_data); - if (p != NULL) { - a->passphrase = strdup(p); - if (a->passphrase == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate data for passphrase"); - return (NULL); - } - return (a->passphrase); - } + set_passphrase(a, p); + a->passphrase_callback = NULL; + a->passphrase_client_data = NULL; } - return (NULL); + return (a->passphrase); } |