From nobody Wed Jan 01 21:11:42 2025 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4YNjFW361vz5jCrZ; Wed, 01 Jan 2025 21:11:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YNjFV5xn4z4k97; Wed, 1 Jan 2025 21:11:42 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1735765902; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=L/AzMtGpiVjw9rT4o+XmnzmtOOZf3eNWvwkfMKowPbI=; b=VFewQ0YZiZgT0PmIrOmAmLfim0OqqwTWBM2z93Y38/qmJalnzSw4z610xqU0qetmI6y1Yr FAidTkq6Gnc0xE/YygiZRCCuncXajphCQGOvc1Bt8ldUZey+vvQQ6XMIt1lSTDVoWAxjo7 cnfp7VJ3gsrYdsTCd3112FL1n/HLqwxVyHYuHm5hLuvj/MXTusOgH5LWSa4wJUhYSjZM8I Quyfnn6AuHYsLuHyC0zEzEy67zjunwmZTAbP95062WaVd2I9eKXxpoIAg1L4p0SNTA9Pr1 VHORVY4VbuqkZrAueNcN2b5tNH380A/0o2/hnxZLvjjqN7tODvL0Jp33QDFpAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1735765902; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=L/AzMtGpiVjw9rT4o+XmnzmtOOZf3eNWvwkfMKowPbI=; b=pqA5bnNEhpdh2e58a/UFt487OCME8Mv21TFmgi9VR58zBloQIgnHbq2wqfb8ES55c1gRxS kus6wZtmEWWJG+H1Cx+AIJEjtzA9OY1zx/joDiP7KcAN/35ReqHycAxIGCiW5eSv2/NMBb 46FhF4SOkJQrmToxIcL1tF5Pw5gKknsomyAwwLRm542PjvKRn/h4aM66T41VusP8iSMJjP HP0f/25jpQtxsU65/eSpKglwnkEvHT0P8ss9wRE0LJ+mPJAoiNVnAM2/QlvUu8QNmVqxvz v/miyh2GTm91QGVCA1n88tZlyOQeGqwMgLIKCoOKLTgIwE0KvRGJ7TwxX0WQzA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1735765902; a=rsa-sha256; cv=none; b=bVSSnD/5LXw0hejUdHj37HMnP8VJLGFQBbpwRGUqyzQ8DINH2IRLcCZXrtYZA5elYryM+g fqxHKY2LsqyQB7fadQeSkTCRQUzI85wbRJ3/WbJ9JAlcQV1Wl122KwPnZCiiysBAMBETpk 661Cj0wkYCuWsRQNuOFqWkfXwuJWkgd/Sqi+6j+sCYs5Ue0E+6e15d2aJI9CDbnZaWBo8j 4SDf6ARJn1WIdXssCF4IKeFI/JJQK6oojJXrGPOleSE1C0W0BVRukOcVrDnRXJXZHTX9eX bvUEFLFJ98NNVdQgmWsAZ5QonbNEhc/a+aO7/rR2vz7kreQ+jwvsVN4cG474+Q== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4YNjFV5K29zgJ7; Wed, 1 Jan 2025 21:11:42 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 501LBgPB080116; Wed, 1 Jan 2025 21:11:42 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 501LBgf9080113; Wed, 1 Jan 2025 21:11:42 GMT (envelope-from git) Date: Wed, 1 Jan 2025 21:11:42 GMT Message-Id: <202501012111.501LBgf9080113@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: 2ecfc040a09f - main - pkg: refactor out a pkg_read_fd() List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 2ecfc040a09f8c42f67bbfdcc4bd02ef84dac8b7 Auto-Submitted: auto-generated The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=2ecfc040a09f8c42f67bbfdcc4bd02ef84dac8b7 commit 2ecfc040a09f8c42f67bbfdcc4bd02ef84dac8b7 Author: Kyle Evans AuthorDate: 2025-01-01 21:10:28 +0000 Commit: Kyle Evans CommitDate: 2025-01-01 21:11:23 +0000 pkg: refactor out a pkg_read_fd() We already have to do this for reading the pubkey, just pull it out for other uses. The ECC signer will use this to verify the bootstrap if the PUBKEY mechanism is used. Reviewed by: bapt, emaste Differential Revision: https://reviews.freebsd.org/D48107 --- usr.sbin/pkg/pkg.c | 40 +++++++++++++++++++++++++++------------- usr.sbin/pkg/pkg.h | 2 ++ 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/usr.sbin/pkg/pkg.c b/usr.sbin/pkg/pkg.c index 4d476f7653f7..6d0a75d2786a 100644 --- a/usr.sbin/pkg/pkg.c +++ b/usr.sbin/pkg/pkg.c @@ -451,32 +451,46 @@ load_fingerprints(const char *path, int *count) return (fingerprints); } +char * +pkg_read_fd(int fd, size_t *osz) +{ + char *obuf; + char buf[4096]; + FILE *fp; + ssize_t r; + + obuf = NULL; + *osz = 0; + fp = open_memstream(&obuf, osz); + if (fp == NULL) + err(EXIT_FAILURE, "open_memstream()"); + + while ((r = read(fd, buf, sizeof(buf))) >0) { + fwrite(buf, 1, r, fp); + } + + if (ferror(fp)) + errx(EXIT_FAILURE, "reading file"); + + fclose(fp); + + return (obuf); +} + static struct pubkey * read_pubkey(int fd) { struct pubkey *pk; char *sigb; size_t sigsz; - FILE *sig; - char buf[4096]; - int r; if (lseek(fd, 0, 0) == -1) { warn("lseek"); return (NULL); } - sigsz = 0; - sigb = NULL; - sig = open_memstream(&sigb, &sigsz); - if (sig == NULL) - err(EXIT_FAILURE, "open_memstream()"); - - while ((r = read(fd, buf, sizeof(buf))) >0) { - fwrite(buf, 1, r, sig); - } + sigb = pkg_read_fd(fd, &sigsz); - fclose(sig); pk = calloc(1, sizeof(struct pubkey)); pk->siglen = sigsz; pk->sig = calloc(1, pk->siglen); diff --git a/usr.sbin/pkg/pkg.h b/usr.sbin/pkg/pkg.h index d42f5a95d327..2d0dab96a20f 100644 --- a/usr.sbin/pkg/pkg.h +++ b/usr.sbin/pkg/pkg.h @@ -63,4 +63,6 @@ struct pubkey { int siglen; }; +char *pkg_read_fd(int fd, size_t *osz); + #endif /* _PKG_H */