Commit graph

161 commits

Author SHA1 Message Date
Colin Percival
a47542f715 pkg.conf: Use kmod repositories
The kmod repositories were added shortly after 14.2-RELEASE.  Point at
them here so that users don't need to manually add the configuration
in order to get e.g. working graphics.

Approved by:	re (cperciva)
MFC after:	1 minute
Sponsored by:	Amazon
Differential Revision:	https://reviews.freebsd.org/D50583

(cherry picked from commit 29f076ae0cb536d1e891d3375edf28f1bc82df79)
(cherry picked from commit 8a2ce9f9dd6745e77bdfe78f03e96ddc8ad1b9d7)
2025-05-29 12:58:46 -07:00
Christos Margiolis
84ed51c412 pkg.7: Add example for fetching package for different FreeBSD versions
MFC after:	1 week
Reviewed by:	bapt
Differential Revision:	https://reviews.freebsd.org/D49580

(cherry picked from commit 8900283fa37f6555055d8af5ffa1a5a2fbe2940e)
2025-04-08 03:04:51 +02:00
Mark Johnston
69c5f7b4ca pkg: Fix Coverity warnings
- Fix allocation size in config_get_repositories().
- Fix a memory leak in read_conf_file().
- Avoid a null pointer dereference in an error path in
  verify_pubsignature().

Fixes:	e3b4a51580fc ("pkg(7): expand VERSION_MAJOR, VERSION_MINOR, RELEASE and OSNAME")
Fixes:	dc4581589a32 ("pkg: clean support for repositories")
(cherry picked from commit c1557708f1fae1bb9c8e23e3bbb2aa2b055e1211)
2025-03-26 08:48:01 -07:00
Baptiste Daroussin
0bd3f757f9 pkg(7): expand VERSION_MAJOR, VERSION_MINOR, RELEASE and OSNAME
Catchup with pkg(8) by expanding more variable when parsing repositories
The only missing variable now is ARCH, this will have to wait for
pkg 2.0 to be the lowest supported version.

(cherry picked from commit e3b4a51580fcd4a1ddf0d61feb5f325ff1de5420)
2025-03-06 16:39:14 +01:00
Baptiste Daroussin
2b8f8ede6e pkg(7): support configuration overwrite like pkg(8)
with pkg(8) it is possible to overwrite a configuration like adding
FreeBSD {
	enabled: false
}

in /usr/local/etc/pkg/repo/overwrite.conf which allows to change any
value which can have been reviously configured in anything in
/etc/pkg/*.conf

now the bootstrap supports the same

MFC After:	3 weeks

(cherry picked from commit 5c341fe5123d4aa6961066542de63dd4431d004d)
2025-03-06 16:38:16 +01:00
Baptiste Daroussin
c7c3f8dbcf pkg: make sure the repositories have at least an url
While here, factorize code to free the repository structure

(cherry picked from commit eccf736c3ce6e9566fa9923080b4c24ee7f9ae2a)
2025-03-06 16:37:51 +01:00
Baptiste Daroussin
7be3ea2e64 pkg: clean support for repositories
Rework the way the bootstrap fetches pkg, by implementing a full support
for the repositories, the boostrap will now loop over all available repo
and try to fetch the full package from there. It will at the first valid
package found.

Fallback to packagesite (which has been deprecated for a while) if needed, by
transforming it into a repo, if no repo is found.

MFC After:	3 weeks

(cherry picked from commit dc4581589a3256667fafd46a30c67abdfd86618f)
2025-03-06 16:31:35 +01:00
Kyle Evans
18790167dc pkg: include missing <string.h>
My local environment seems to be seeing some pollution; we need
<string.h> for strlen.

PR:		284021
Fixes:		2e065d74a5b0e ("pkg: add a pkgsign_verify_data [...]")

(cherry picked from commit b8770ce1dfed52fcb7249cdf3cf4d4d16357b9fd)
2025-01-12 14:12:12 -06:00
Kyle Evans
8aeeab4331 pkg: finish adding the ECC signer and signature type bits
Signature types need to be parsed out of the key/signature information
that we are presented with from the files we download.  We use that to
understand whicher signer we need to dispatch to.

The ECC signer is more-or-less lifted from pkg(8), with some changes to
slim it down for pkg(7).

Reviewed by:	bapt

(cherry picked from commit 3d0a0dda3a7d57bbd4eaf65ba8da0f2a36089c0e)
2025-01-10 20:48:26 -06:00
Kyle Evans
cb09fc9a60 pkg: add a pkgsign_verify_data callback
This will be used to verify raw payloads, as if signed by pkg-key(8).
It will be used specifically in pkg(7) to verify .pubkeysig as published
by poudriere.

Amend verify_pubsignature() now to use it.  For the RSA signer, we need
to verify using a sha256 of the data instead of the data itself.

Reviewed by:	bapt

(cherry picked from commit 2e065d74a5b0ea32db7d4f6e3f78eaa17ee7685e)
2025-01-10 20:48:25 -06:00
Kyle Evans
1e3003bed3 pkg: abstract rsa out behind a pkgsign API
This mirrors a change we made in pkg(8), and will be used to next add
another signer that does ECC.

Reviewed by:	bapt, emaste

(cherry picked from commit 5862580ded35e23581291a2e1052f04428369ead)
2025-01-10 20:48:25 -06:00
Kyle Evans
836f1da80e 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

(cherry picked from commit 2ecfc040a09f8c42f67bbfdcc4bd02ef84dac8b7)
2025-01-10 20:48:25 -06:00
Kyle Evans
292d6586e2 pkg: pull rsa bits out of pkg.c
We'll eventually add a pkgsign abstraction over these similar to how we do
in pkg(8), but start by isolating these parts.

Reviewed by:	bapt, emaste

(cherry picked from commit 2629e90dd05fb69d767525f960101d7d055ffae0)
2025-01-10 20:48:24 -06:00
Ed Maste
2f29060f46 pkg: improve error message
Print the complete list of url that have failed

PR:		281924
Co-authored-by: Baptiste Daroussin <bapt@FreeBSD.org>
Differential Revision: https://reviews.freebsd.org/D46983

(cherry picked from commit be9243409d6be99f5d7815b6d074a85a6e84f7ce)
2024-10-11 11:27:42 -04:00
Ed Maste
fef1f3fecd pkg: prefer .pkg extension
.pkg is the default extension as of commit c244b1d8a3, falling back to
.txz if not found.

PR:		281924
Reviewed by:	bapt
Fixes: a2aac2f5e5 ("pkg(7): when bootstrapping first search for pkg.bsd file then pkg.txz")
Fixes: c244b1d8a3 ("pkg: settle the uniq extension to .pkg instead of .bsd")
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D46977

(cherry picked from commit f5c847ae849aab9354d0956afd683f1c90bfd91e)
2024-10-11 11:27:41 -04:00
John Baldwin
2012748bd7 pkg: Allocate a suitably-sized string for the local ABI
Previously the local ABI string was written to an on-stack buffer and
the pointer to that buffer was saved in a global before the function
returned.  This had two issues: c[ABI].val pointed to a
no-longer-valid on-stack buffer after config_init returned, and the
string could potentially be truncated.  Fix both of those by changing
pkg_get_myabi to return a pointer to a string allocated by asprintf.

Note that the allocated string is left in the global config array
until it is implicitly freed on process exit.

Reported by:	GCC 13 -Wdangling-pointer
Reviewed by:	emaste
Differential Revision:	https://reviews.freebsd.org/D42623

(cherry picked from commit fd9ae9ac04edf9acef4a2ffbf663698a2b8e7ced)
2024-01-03 09:43:48 -08:00
Baptiste Daroussin
c01ee3f859 pkg: use https by default
Switch the repository to use https by default, base is providing a CA
root bundle suitable to validate the certificates used by the project.
This can now be activated without requiring another packages to be installed

Reviewed by:		emaste
Differential Revision:	https://reviews.freebsd.org/D40473

(cherry picked from commit d557a86c879a8515d59e8380b083b2265e9a3547)
2023-12-04 11:20:56 +01:00
Warner Losh
fa9896e082 Remove $FreeBSD$: two-line nroff pattern
Remove /^\.\\"\n\.\\"\s*\$FreeBSD\$$\n/
2023-08-16 11:55:10 -06:00
Warner Losh
d0b2dbfa0e Remove $FreeBSD$: one-line sh pattern
Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
2023-08-16 11:55:03 -06:00
Warner Losh
1d386b48a5 Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:42 -06:00
Warner Losh
b3e7694832 Remove $FreeBSD$: two-line .h pattern
Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
2023-08-16 11:54:16 -06:00
Warner Losh
4d846d260e spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD
The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with:		pfg
MFC After:		3 days
Sponsored by:		Netflix
2023-05-12 10:44:03 -06:00
Simon J. Gerraty
d9a4274795 Update/fix Makefile.depend for userland 2023-04-18 17:14:23 -07:00
Baptiste Daroussin
e5dd5bfa55 pkg(7): now that we do use libmd, use it completly
Use SHA256_Fd and SHA256_Data instead of home made equivalent.
wrap those functions into hash.c to avoid header collition between
openssl and libmd

Suggested by:	kevans
2023-03-09 21:31:30 +01:00
Baptiste Daroussin
b2654064c2 pkg(7): use libmd for sha256 instead of openssl
OpenSSL 3.0 has deprecated the sha256 api, let's use libmd which has the
same API instead.

In order to avoid the collision in definitions (sha256.h cannot be
included in the same file as a file where openssl headers has been
included) let's move the sha256 related code in its own file

PR:		270023
Reported by:	ngie
2023-03-09 17:43:01 +01:00
Kyle Evans
c816aea7ab Revert "grep: remove tautological condition"
This reverts commit f6d6c66889.

Gremlins snuck into my tree and injected some WIP.
2023-03-08 23:52:23 -06:00
Kyle Evans
f6d6c66889 grep: remove tautological condition
st_size is an off_t, it cannot hold values larger than OFF_MAX.

CID:		1008931
2023-03-08 23:34:22 -06:00
Gordon Bergling
990878b07f pkg(8): Remove a double word in a source code comment
- s/that that/that/

MFC after:	3 days
2022-09-04 17:28:16 +02:00
Brooks Davis
e9ad2964f5 pkg: Add limited --debug/-d support
Add an internal debug level global:
 - Level 1 (-d) currently does nothing.

 - Level 2 (-d -d) enables libfetch debugging (quite verbose) so it's
   possible to see what pkg is attempting to download without having
   to sniff traffic.

Reviewed by:	debdrup, bapt
Differential Revision:	https://reviews.freebsd.org/D35756
2022-08-24 18:32:09 +01:00
John Hood
60b92ba932 /usr/sbin/pkg: don't sleep on fetch failure
PR:	263458
2022-07-28 17:55:13 +02:00
Mateusz Piotrowski
3beedc3840 pkg.7: Clean up mdoc
MFC after:	1 week
2022-06-30 16:22:02 +02:00
Ed Maste
f92e0d6acd pkg-bootstrap: use latest package set on arm64 stable branches
As with i386 and amd64, "latest" packages are available on stable
branches for arm64/aarch64.

Reviewed by:	manu
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D35445
2022-06-13 14:57:10 -04:00
Emmanuel Vadot
ec0ea6efa1 pkgbase: Add a FreeBSD-pkg-bootstrap package
And put pkg and its keys in it.
It's easier for small image to depend on this package rather than the
larger utilities one.

MFC after:	2 weeks
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D33458
2021-12-21 10:17:48 +01:00
Gleb Smirnoff
c96b4d87ba pkg: fix regression that breaks bootstrap from not a current directory.
Fixes:		40b9f924b1
Reviewed by:	kevans
2021-09-10 14:49:17 -07:00
Kyle Evans
d35164539b pkg: use specific CONFSNAME_${file} for FreeBSD.conf
Setting CONFSNAME directly is a little more complicated for downstream
consumers, as any additional CONFS that are added here will inherit the
group name by default.  This is perhaps arguably a design flaw in CONFS
because inheriting NAME will never give a good result when additional
files are added, but this is a low-effort change.

While we're here, pull FreeBSD.conf.${branch} out into a PKGCONF
variable so one can just drop a new repo config in entirely with a new
naming scheme. CONFSNAME gets set based on chopping anything off after
".conf", so that, e.g.:

- FooBSD.conf => FooBSD.conf
- FooBSD.conf.internal => FooBSD.conf

Reviewed by:	bapt, manu
Differential Revision:	https://reviews.freebsd.org/D28767
2021-08-06 14:25:45 -05:00
Kyle Evans
40b9f924b1 pkg: allow multiple add arguments again
While pkg(7) add only handles a single 'add' argument, pkg-add(8) fully
handles multiple arguments.

Stop rejecting it, just turn off local-bootstrap mode and proceed to
remote bootstrap if we need it.

While we're here, check if the first argument to pkg add is even a pkg
package. If it's not, also do remote bootstrap instead. Future work
could improve this altogether by picking out a pkg package out of many
and local bootstrap then pass the rest through to the newly installed
pkg.

Reviewed by:	bapt, manu (earlier version)
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D28766
2021-08-06 14:25:07 -05:00
Baptiste Daroussin
cc9a8a116d pkg(7): replace usage of sbuf(9) with open_memstream(3)
open_memstream(3) is a standard way to obtain the same feature we do get
by using sbuf(9) (aka dynamic size buffer), switching to using it makes
pkg(7) more portable, and reduces its number of dependencies.

Reviewed by:	manu
Differential Revision:	https://reviews.freebsd.org/D30005
2021-04-29 06:41:59 +02:00
Baptiste Daroussin
f648d757b7 pkg(7): indentation fixes
Non functional changes
2021-04-29 06:41:34 +02:00
Moritz Schmitt
e869d3c601 Make pkg(7) use environment variables specified in pkg.conf
Modify /usr/sbin/pkg to use environment variables specified in pkg.conf.
This allows control over underlying libraries like fetch(3), which can
be configured by setting HTTP_PROXY.

MFC after:		1 week
Differential Revision:	https://reviews.freebsd.org/D29820
2021-04-27 04:01:49 +02:00
Baptiste Daroussin
c244b1d8a3 pkg: settle the uniq extension to .pkg instead of .bsd
Requested by:	many
2021-03-16 16:19:52 +01:00
Baptiste Daroussin
a2aac2f5e5 pkg(7): when bootstrapping first search for pkg.bsd file then pkg.txz
The package extension is going to be changed to .bsd to be among other
things resilient to the change of compression format used and reduce
the impact of all third party tool of that change.

Ensure the bootstrap knows about it

Reviewed by:	manu
Differential revision:	https://reviews.freebsd.org/D29232
2021-03-15 17:52:22 +01:00
Kyle Evans
b2c4ca8d28 pkg(7): address minor nits (mostly clang-analyze complaints)
- One (1) spurious whitespace.
- One (1) occurrence of "random(3) bad, arc4random(3)" good.
- Three (3) writes that will never be seen.

The latter two points are complaints from clang-analyze. Switching to
arc4random(3) is decidedly a good idea because we weren't doing any kind
of PRNG seeding anyways. The discarded assignments are arguably good
for future-proofing, but it's better to improve the S/N ratio from
clang-analyze.

Reviewed by:	bapt, manu
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D28525
2021-02-11 18:58:27 -06:00
Kyle Evans
18418e1936 pkg(7): add an -r reponame option for bootstrap and add
This is limited to bootstrap/add because some real pkg(8) commands
have -r flags with an incompatible meaning/usage, e.g., pkg-audit.
pkg(7) will still commence the search as it has, but it will ignore any
repo objects without the given name so that overrides and whatnot still
work as expected.

The use of it for add is noted in the manpage; notably, that the
signature config for that repository will be used over global config if
it's specified. i.e., pkg(7) should assume that the given pkg did come
from that repository and treat it appropriately.

Reviewed by:	bapt, manu
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D28524
2021-02-11 18:58:26 -06:00
Alex Richardson
9a0a48b12d usr.sbin/pkg: Don't re-define roundup2
The file already includes sys/param.h and should use that definition.
I found this while testing D28332.

Reviewed By:	bapt
Differential Revision: https://reviews.freebsd.org/D28331
2021-01-28 17:25:53 +00:00
Baptiste Daroussin
ae994fdc5b pkg(7): rework the arguments handling
Rework the arguments handling around using getopt_long:
* add long option support
* add -4 and -6 support to enforce ipv4 or ipv6

While here fix a regression which occured between FreeBSD 12.1 and
FreeBSD 12.2 where pkg bootstrap -y stopped working

PR:		252270
MFC after:	2 weeks
Submitted by:	evilham <contact@evilham.com>
Differential Revision:	https://reviews.freebsd.org/D27860
2021-01-06 11:47:34 +01:00
Stefan Eßer
56d11d4a37 Make use of the getlocalbase() function for run-time adjustment of the
local software base directory, as committed in SVN rev. 367813.

The pkg and mailwrapper programs used the LOCALBASE environment variable
for this purpose and this functionality is preserved by getlocalbase().

After this change, the value of the user.localbase sysctl variable is used
if present (and not overridden in the environment).

The nvmecontrol program gains support of a dynamic path to its plugin
directory with this update.

Differential Revision:	https://reviews.freebsd.org/D27237
2020-11-18 20:00:55 +00:00
Scott Long
8e1031086d Revert the whole getlocalbase() set of changes while a different design is
hashed out.
2020-11-15 20:24:59 +00:00
Scott Long
1b249101df Fix the previous revision, it suffered from an incomplete change to the
getlocalbase API.  Also don't erroneously subtract the lenth from the
buffer a second time.
2020-11-15 07:50:29 +00:00
Scott Long
7ca0d5403e Replace hardcoded references to _PATH_LOCALBASE with calls to getlocalbase.3
Reviewed by:	imp, se
2020-11-14 18:01:14 +00:00
John-Mark Gurney
e771d59074 fix up docs, if signature checking is enabled, the file MUST exist... 2020-11-06 22:11:05 +00:00