summaryrefslogtreecommitdiff
path: root/src/verify.c
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2020-01-11 09:56:42 +0200
committerTimo Teräs <timo.teras@iki.fi>2020-01-11 11:32:51 +0200
commitf123d77e0b903b7459296291e04b6558ceb4c287 (patch)
tree75cc6e28f5f3d86d63922762072a3392d2bb81cb /src/verify.c
parent1de9ef422c087ee8fc302c9d889dd373dc6dde58 (diff)
downloadapk-tools-f123d77e0b903b7459296291e04b6558ceb4c287.tar.gz
apk-tools-f123d77e0b903b7459296291e04b6558ceb4c287.tar.bz2
apk-tools-f123d77e0b903b7459296291e04b6558ceb4c287.tar.xz
apk-tools-f123d77e0b903b7459296291e04b6558ceb4c287.zip
archive: make apk_tar_parse check and close input stream
simplifies other code quite a bit
Diffstat (limited to 'src/verify.c')
-rw-r--r--src/verify.c20
1 files changed, 6 insertions, 14 deletions
diff --git a/src/verify.c b/src/verify.c
index af48297..eb1ca42 100644
--- a/src/verify.c
+++ b/src/verify.c
@@ -20,34 +20,26 @@
static int verify_main(void *ctx, struct apk_database *db, struct apk_string_array *args)
{
struct apk_sign_ctx sctx;
- struct apk_istream *is;
char **parg;
int r, ok, rc = 0;
foreach_array_item(parg, args) {
apk_sign_ctx_init(&sctx, APK_SIGN_VERIFY, NULL, db->keys_fd);
- is = apk_istream_gunzip_mpart(apk_istream_from_file(AT_FDCWD, *parg),
- apk_sign_ctx_mpart_cb, &sctx);
- if (IS_ERR_OR_NULL(is)) {
- if (apk_verbosity >= 1)
- apk_error("%s: %s", *parg, strerror(errno));
- else
- printf("%s\n", *parg);
- apk_sign_ctx_free(&sctx);
- rc++;
- continue;
- }
- r = apk_tar_parse(is, apk_sign_ctx_verify_tar, &sctx, &db->id_cache);
- apk_istream_close(is);
+ r = apk_tar_parse(
+ apk_istream_gunzip_mpart(apk_istream_from_file(AT_FDCWD, *parg),
+ apk_sign_ctx_mpart_cb, &sctx),
+ apk_sign_ctx_verify_tar, &sctx, &db->id_cache);
ok = sctx.control_verified && sctx.data_verified;
if (apk_verbosity >= 1)
apk_message("%s: %d - %s", *parg, r,
+ r < 0 ? apk_error_str(r) :
ok ? "OK" :
!sctx.control_verified ? "UNTRUSTED" : "FAILED");
else if (!ok)
printf("%s\n", *parg);
if (!ok)
rc++;
+
apk_sign_ctx_free(&sctx);
}