diff options
author | Timo Teräs <timo.teras@iki.fi> | 2020-02-14 13:49:41 +0200 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2020-02-14 16:49:55 +0200 |
commit | 60b87557e57ca4e23126bf8c25b1cb978e380dfd (patch) | |
tree | ca2469a61c3badb5f4054f387b7059c2bb6c5db7 /src/app_verify.c | |
parent | 72be8139303d55463e470ee608a27eb4af950aff (diff) | |
download | apk-tools-60b87557e57ca4e23126bf8c25b1cb978e380dfd.tar.gz apk-tools-60b87557e57ca4e23126bf8c25b1cb978e380dfd.tar.bz2 apk-tools-60b87557e57ca4e23126bf8c25b1cb978e380dfd.tar.xz apk-tools-60b87557e57ca4e23126bf8c25b1cb978e380dfd.zip |
rename all applets sources to app_*.c
Diffstat (limited to 'src/app_verify.c')
-rw-r--r-- | src/app_verify.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/app_verify.c b/src/app_verify.c new file mode 100644 index 0000000..296253c --- /dev/null +++ b/src/app_verify.c @@ -0,0 +1,59 @@ +/* app_verify.c - Alpine Package Keeper (APK) + * + * Copyright (C) 2008-2011 Timo Teräs <timo.teras@iki.fi> + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation. See http://www.gnu.org/ for details. + */ + +#include <errno.h> +#include <stdio.h> +#include <fcntl.h> +#include <unistd.h> + +#include "apk_applet.h" +#include "apk_database.h" +#include "apk_print.h" + +static int verify_main(void *ctx, struct apk_database *db, struct apk_string_array *args) +{ + struct apk_sign_ctx sctx; + char **parg; + int r, ok, rc = 0; + + foreach_array_item(parg, args) { + apk_sign_ctx_init(&sctx, APK_SIGN_VERIFY, NULL, db->keys_fd); + 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); + } + + return rc; +} + +static struct apk_applet apk_verify = { + .name = "verify", + .arguments = "FILE...", + .open_flags = APK_OPENF_READ | APK_OPENF_NO_STATE, + .command_groups = APK_COMMAND_GROUP_REPO, + .forced_flags = APK_ALLOW_UNTRUSTED, + .main = verify_main, +}; + +APK_DEFINE_APPLET(apk_verify); + |