From c6767b51147fd70dda048bd0e31f1ebcbf41de14 Mon Sep 17 00:00:00 2001 From: Claudio Jeker Date: Thu, 13 Jan 2022 13:46:04 +0000 Subject: Alter valid_filehash() to take a file descriptor instead of a path. This is needed so that callers can allow a file to be in multiple locations. Also move mft_check() from mft.c to parser.c. OK tb@ --- usr.sbin/rpki-client/mft.c | 41 +---------------------------------------- 1 file changed, 1 insertion(+), 40 deletions(-) (limited to 'usr.sbin/rpki-client/mft.c') diff --git a/usr.sbin/rpki-client/mft.c b/usr.sbin/rpki-client/mft.c index d9268fda7d6..bd8be3091aa 100644 --- a/usr.sbin/rpki-client/mft.c +++ b/usr.sbin/rpki-client/mft.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mft.c,v 1.44 2022/01/11 13:06:07 claudio Exp $ */ +/* $OpenBSD: mft.c,v 1.45 2022/01/13 13:46:03 claudio Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons * @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include @@ -458,44 +457,6 @@ out: return p.res; } -/* - * Check all files and their hashes in a MFT structure. - * Return zero on failure, non-zero on success. - */ -int -mft_check(const char *fn, struct mft *p) -{ - size_t i; - int rc = 1; - char *cp, *h, *path = NULL; - - /* Check hash of file now, but first build path for it */ - cp = strrchr(fn, '/'); - assert(cp != NULL); - assert(cp - fn < INT_MAX); - - for (i = 0; i < p->filesz; i++) { - const struct mftfile *m = &p->files[i]; - if (!valid_filename(m->file)) { - if (base64_encode(m->hash, sizeof(m->hash), &h) == -1) - errx(1, "base64_encode failed in %s", __func__); - warnx("%s: unsupported filename for %s", fn, h); - free(h); - continue; - } - if (asprintf(&path, "%.*s/%s", (int)(cp - fn), fn, - m->file) == -1) - err(1, NULL); - if (!valid_filehash(path, m->hash, sizeof(m->hash))) { - warnx("%s: bad message digest for %s", fn, m->file); - rc = 0; - } - free(path); - } - - return rc; -} - /* * Free an MFT pointer. * Safe to call with NULL. -- cgit v1.2.3