From: job Date: Fri, 2 Feb 2024 13:40:50 +0000 (+0000) Subject: refactor: move parse_filepath() to avoid pointer indirection X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=09ad02f4b09b245b5ad959302f179ef1c6697863;p=openbsd refactor: move parse_filepath() to avoid pointer indirection OK tb@ --- diff --git a/usr.sbin/rpki-client/parser.c b/usr.sbin/rpki-client/parser.c index 11db25de65a..bd674cda070 100644 --- a/usr.sbin/rpki-client/parser.c +++ b/usr.sbin/rpki-client/parser.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.c,v 1.116 2024/02/02 12:35:15 job Exp $ */ +/* $OpenBSD: parser.c,v 1.117 2024/02/02 13:40:50 job Exp $ */ /* * Copyright (c) 2019 Claudio Jeker * Copyright (c) 2019 Kristaps Dzonsons @@ -257,7 +257,7 @@ parse_load_crl_from_mft(struct entity *entp, struct mft *mft, enum location loc, * Return the mft on success or NULL on failure. */ static struct mft * -proc_parser_mft_pre(struct entity *entp, enum location loc, char **file, +proc_parser_mft_pre(struct entity *entp, enum location loc, char *file, struct crl **crl, char **crlfile, struct mft *cached_mft, const char **errstr) { @@ -273,19 +273,17 @@ proc_parser_mft_pre(struct entity *entp, enum location loc, char **file, *crlfile = NULL; *errstr = NULL; - /* XXX - pull this into proc_parser_mft. */ - *file = parse_filepath(entp->repoid, entp->path, entp->file, loc); - if (*file == NULL) + if (file == NULL) return NULL; if (noop && loc == DIR_TEMP) return NULL; - der = load_file(*file, &len); + der = load_file(file, &len); if (der == NULL && errno != ENOENT) - warn("parse file %s", *file); + warn("parse file %s", file); - if ((mft = mft_parse(&x509, *file, entp->talid, der, len)) == NULL) { + if ((mft = mft_parse(&x509, file, entp->talid, der, len)) == NULL) { free(der); return NULL; } @@ -299,8 +297,8 @@ proc_parser_mft_pre(struct entity *entp, enum location loc, char **file, if (*crl == NULL) *crl = parse_load_crl_from_mft(entp, mft, DIR_VALID, crlfile); - a = valid_ski_aki(*file, &auths, mft->ski, mft->aki, NULL); - if (!valid_x509(*file, ctx, x509, a, *crl, errstr)) + a = valid_ski_aki(file, &auths, mft->ski, mft->aki, NULL); + if (!valid_x509(file, ctx, x509, a, *crl, errstr)) goto err; X509_free(x509); x509 = NULL; @@ -311,13 +309,13 @@ proc_parser_mft_pre(struct entity *entp, enum location loc, char **file, now = get_current_time(); /* check that now is not before from */ if (now < mft->thisupdate) { - warnx("%s: manifest not yet valid %s", *file, + warnx("%s: manifest not yet valid %s", file, time2str(mft->thisupdate)); mft->stale = 1; } /* check that now is not after until */ if (now > mft->nextupdate) { - warnx("%s: manifest expired on %s", *file, + warnx("%s: manifest expired on %s", file, time2str(mft->nextupdate)); mft->stale = 1; } @@ -333,31 +331,31 @@ proc_parser_mft_pre(struct entity *entp, enum location loc, char **file, if ((issued_cmp = mft_compare_issued(mft, cached_mft)) < 0) { warnx("%s: unexpected manifest issuance date (want >= %lld, " - "got %lld)", *file, (long long)cached_mft->thisupdate, + "got %lld)", file, (long long)cached_mft->thisupdate, (long long)mft->thisupdate); goto err; } if ((seqnum_cmp = mft_compare_seqnum(mft, cached_mft)) < 0) { warnx("%s: unexpected manifest number (want >= #%s, got #%s)", - *file, cached_mft->seqnum, mft->seqnum); + file, cached_mft->seqnum, mft->seqnum); goto err; } if (issued_cmp > 0 && seqnum_cmp == 0) { warnx("%s: manifest issued at %lld and %lld with same " - "manifest number #%s", *file, (long long)mft->thisupdate, + "manifest number #%s", file, (long long)mft->thisupdate, (long long)cached_mft->thisupdate, cached_mft->seqnum); goto err; } if (issued_cmp == 0 && seqnum_cmp > 0) { warnx("%s: #%s and #%s were issued at same issuance date %lld", - *file, mft->seqnum, cached_mft->seqnum, + file, mft->seqnum, cached_mft->seqnum, (long long)mft->thisupdate); goto err; } if (issued_cmp == 0 && seqnum_cmp == 0 && memcmp(mft->mfthash, cached_mft->mfthash, SHA256_DIGEST_LENGTH) != 0) { warnx("%s: misissuance, issuance date %lld and manifest number " - "#%s were recycled", *file, (long long)mft->thisupdate, + "#%s were recycled", file, (long long)mft->thisupdate, mft->seqnum); goto err; } @@ -421,9 +419,12 @@ proc_parser_mft(struct entity *entp, struct mft **mp, char **crlfile, *mp = NULL; *crlmtime = 0; - mft2 = proc_parser_mft_pre(entp, DIR_VALID, &file2, &crl2, &crl2file, + file2 = parse_filepath(entp->repoid, entp->path, entp->file, DIR_VALID); + mft2 = proc_parser_mft_pre(entp, DIR_VALID, file2, &crl2, &crl2file, NULL, &err2); - mft1 = proc_parser_mft_pre(entp, DIR_TEMP, &file1, &crl1, &crl1file, + + file1 = parse_filepath(entp->repoid, entp->path, entp->file, DIR_TEMP); + mft1 = proc_parser_mft_pre(entp, DIR_TEMP, file1, &crl1, &crl1file, mft2, &err1); /* overload error from temp file if it is set */