summaryrefslogtreecommitdiff
path: root/pkgtools/pkg_install/files/lib/pkg_signature.c
diff options
context:
space:
mode:
Diffstat (limited to 'pkgtools/pkg_install/files/lib/pkg_signature.c')
-rw-r--r--pkgtools/pkg_install/files/lib/pkg_signature.c41
1 files changed, 18 insertions, 23 deletions
diff --git a/pkgtools/pkg_install/files/lib/pkg_signature.c b/pkgtools/pkg_install/files/lib/pkg_signature.c
index 78b5d0dcab7..b62a8274a22 100644
--- a/pkgtools/pkg_install/files/lib/pkg_signature.c
+++ b/pkgtools/pkg_install/files/lib/pkg_signature.c
@@ -1,4 +1,4 @@
-/* $NetBSD: pkg_signature.c,v 1.12 2015/09/01 12:14:06 jperkin Exp $ */
+/* $NetBSD: pkg_signature.c,v 1.13 2017/04/19 21:42:50 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -7,7 +7,7 @@
#if HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
#endif
-__RCSID("$NetBSD: pkg_signature.c,v 1.12 2015/09/01 12:14:06 jperkin Exp $");
+__RCSID("$NetBSD: pkg_signature.c,v 1.13 2017/04/19 21:42:50 joerg Exp $");
/*-
* Copyright (c) 2008 Joerg Sonnenberger <joerg@NetBSD.org>.
@@ -47,6 +47,7 @@ __RCSID("$NetBSD: pkg_signature.c,v 1.12 2015/09/01 12:14:06 jperkin Exp $");
#endif
#include <errno.h>
#include <fcntl.h>
+#include <limits.h>
#include <stdlib.h>
#ifndef NETBSD
#include <nbcompat/sha2.h>
@@ -159,7 +160,7 @@ verify_signature_close_cb(struct archive *archive, void *cookie)
{
struct signature_archive *state = cookie;
- archive_read_finish(state->archive);
+ archive_read_free(state->archive);
free_signature_int(state);
return 0;
}
@@ -330,7 +331,7 @@ pkg_verify_signature(const char *archive_name, struct archive **archive,
r = read_file_from_archive(archive_name, *archive, entry, HASH_FNAME,
&hash_file, &hash_len);
if (r == -1) {
- archive_read_finish(*archive);
+ archive_read_free(*archive);
*archive = NULL;
free(state);
goto no_valid_signature;
@@ -345,7 +346,7 @@ pkg_verify_signature(const char *archive_name, struct archive **archive,
r = read_file_from_archive(archive_name, *archive, entry, SIGNATURE_FNAME,
&signature_file, &signature_len);
if (r == -1) {
- archive_read_finish(*archive);
+ archive_read_free(*archive);
*archive = NULL;
free(state);
free(hash_file);
@@ -356,7 +357,7 @@ pkg_verify_signature(const char *archive_name, struct archive **archive,
entry, GPG_SIGNATURE_FNAME,
&signature_file, &signature_len);
if (r == -1) {
- archive_read_finish(*archive);
+ archive_read_free(*archive);
*archive = NULL;
free(state);
free(hash_file);
@@ -399,13 +400,11 @@ pkg_verify_signature(const char *archive_name, struct archive **archive,
state->archive = *archive;
- a = archive_read_new();
- archive_read_support_compression_all(a);
- archive_read_support_format_all(a);
+ a = prepare_archive();
if (archive_read_open(a, state, NULL, verify_signature_read_cb,
verify_signature_close_cb)) {
warnx("Can't open signed package file");
- archive_read_finish(a);
+ archive_read_free(a);
goto no_valid_signature;
}
*archive = a;
@@ -448,13 +447,11 @@ extract_pkgname(int fd)
ssize_t len;
int r;
- a = archive_read_new();
- archive_read_support_compression_all(a);
- archive_read_support_format_all(a);
+ a = prepare_archive();
if (archive_read_open_fd(a, fd, 1024)) {
warnx("Cannot open binary package: %s",
archive_error_string(a));
- archive_read_finish(a);
+ archive_read_free(a);
return NULL;
}
@@ -462,17 +459,17 @@ extract_pkgname(int fd)
if (r != ARCHIVE_OK) {
warnx("Cannot extract package name: %s",
r == ARCHIVE_EOF ? "EOF" : archive_error_string(a));
- archive_read_finish(a);
+ archive_read_free(a);
return NULL;
}
if (strcmp(archive_entry_pathname(entry), "+CONTENTS") != 0) {
warnx("Invalid binary package, doesn't start with +CONTENTS");
- archive_read_finish(a);
+ archive_read_free(a);
return NULL;
}
if (archive_entry_size(entry) > SSIZE_MAX - 1) {
warnx("+CONTENTS too large to process");
- archive_read_finish(a);
+ archive_read_free(a);
return NULL;
}
@@ -482,12 +479,12 @@ extract_pkgname(int fd)
if (archive_read_data(a, buf, len) != len) {
warnx("Short read when extracing +CONTENTS");
free(buf);
- archive_read_finish(a);
+ archive_read_free(a);
return NULL;
}
buf[len] = '\0';
- archive_read_finish(a);
+ archive_read_free(a);
parse_plist(&plist, buf);
free(buf);
@@ -579,7 +576,6 @@ pkg_sign_x509(const char *name, const char *output, const char *key_file, const
archive_entry_set_size(sign_entry, signature_len);
pkg = archive_write_new();
- archive_write_set_compression_none(pkg);
archive_write_set_format_ar_bsd(pkg);
archive_write_open_filename(pkg, output);
@@ -608,7 +604,7 @@ pkg_sign_x509(const char *name, const char *output, const char *key_file, const
archive_write_finish_entry(pkg);
archive_entry_free(entry);
- archive_write_finish(pkg);
+ archive_write_free(pkg);
close(fd);
@@ -673,7 +669,6 @@ pkg_sign_gpg(const char *name, const char *output)
archive_entry_set_size(sign_entry, signature_len);
pkg = archive_write_new();
- archive_write_set_compression_none(pkg);
archive_write_set_format_ar_bsd(pkg);
archive_write_open_filename(pkg, output);
@@ -702,7 +697,7 @@ pkg_sign_gpg(const char *name, const char *output)
archive_write_finish_entry(pkg);
archive_entry_free(entry);
- archive_write_finish(pkg);
+ archive_write_free(pkg);
close(fd);