Compare commits
3
Commits
7b22e3746a
...
ae54f74070
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ae54f74070 | ||
|
|
ee4bcc3b77 | ||
|
|
c432274936 |
No files matched your search
@@ -0,0 +1,16 @@
|
|||||||
|
BasedOnStyle: LLVM
|
||||||
|
|
||||||
|
BreakBeforeBraces: Custom
|
||||||
|
BraceWrapping:
|
||||||
|
AfterFunction: true
|
||||||
|
AfterControlStatement: false
|
||||||
|
AfterEnum: true
|
||||||
|
AfterStruct: true
|
||||||
|
AfterUnion: true
|
||||||
|
AfterClass: true
|
||||||
|
|
||||||
|
AlwaysBreakAfterReturnType: All
|
||||||
|
|
||||||
|
IndentWidth: 8
|
||||||
|
TabWidth: 8
|
||||||
|
UseTab: Always
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
# Build outputs (make; make libglacier-ng)
|
||||||
|
/build/
|
||||||
@@ -0,0 +1,359 @@
|
|||||||
|
+--------------------------------------------+
|
||||||
|
| glacier-bootstrap |
|
||||||
|
+--------------------------------------------+
|
||||||
|
|
||||||
|
STATUS: LOCAL MODE IMPLEMENTED 2026-10-06 (glacier-ng/glacier-bootstrap,
|
||||||
|
tests/bootstrap_alpine.sh; see section 10 for how it differs from the
|
||||||
|
plan below). Remote mode (-r) and the pinning helper are still a plan.
|
||||||
|
Section 9 lists the decisions still open.
|
||||||
|
|
||||||
|
glacier-bootstrap takes a template index and builds a chrootable
|
||||||
|
Everest system in a target directory, from either a local directory of
|
||||||
|
packages or a remote repository. It is the "glacier-bootstrap
|
||||||
|
TEMPLATE_INDEX TARGET" tool named in SECURITY_DESIGN.txt section 10, and
|
||||||
|
the `syspkg --root` step of IMAGE_DESIGN.txt's pipeline.
|
||||||
|
|
||||||
|
Companion documents: IMAGE_DESIGN.txt (why images are bootstrap OUTPUT,
|
||||||
|
the sysroot library change), SECURITY_DESIGN.txt (refusal matrix,
|
||||||
|
syspkg's privilege model), PACKAGE_SCOPES.txt (link routing).
|
||||||
|
|
||||||
|
|
||||||
|
+--------------------------------------------+
|
||||||
|
| 1. What it does |
|
||||||
|
+--------------------------------------------+
|
||||||
|
|
||||||
|
glacier-bootstrap [-n] [-t] (-d PKGDIR | -r URL) TEMPLATE TARGET
|
||||||
|
|
||||||
|
-d PKGDIR packages come from a local directory (gbuild/gworld
|
||||||
|
output: NAME-VER.gpkg plus NAME-VER.gpkg.sha256)
|
||||||
|
-r URL packages come from a remote repository (section 5)
|
||||||
|
-n dry run: parse, resolve, fetch, verify, print the plan;
|
||||||
|
never touch TARGET
|
||||||
|
-t after installing, smoke-test: chroot TARGET /bin/sh -c true
|
||||||
|
|
||||||
|
Sequence:
|
||||||
|
|
||||||
|
1. parse TEMPLATE (section 3)
|
||||||
|
2. resolve: check the package list is complete (section 4)
|
||||||
|
3. fetch into a private cache; verify every hash (section 5)
|
||||||
|
4. doas syspkg --root TARGET -n create the tree
|
||||||
|
5. doas syspkg --root TARGET --strict -l PKG... ONE transaction
|
||||||
|
6. doas syspkg --root TARGET -y TARGET's indexes
|
||||||
|
7. optional smoke test (-t)
|
||||||
|
|
||||||
|
Step 5 is one transaction on purpose: TARGET ends up either the whole
|
||||||
|
system or an empty tree, never half a system.
|
||||||
|
|
||||||
|
|
||||||
|
+--------------------------------------------+
|
||||||
|
| 2. Trust and privilege |
|
||||||
|
+--------------------------------------------+
|
||||||
|
|
||||||
|
glacier-bootstrap NEVER WRITES INTO TARGET ITSELF. Every byte under
|
||||||
|
TARGET goes through `doas syspkg --root TARGET`.
|
||||||
|
|
||||||
|
- SECURITY_DESIGN.txt section 5: syspkg owns ALL system-scope
|
||||||
|
mutation, "one tool to secure, one tool to audit." A bootstrapper
|
||||||
|
that extracted packages itself would be the second, unaudited entry
|
||||||
|
point that section warns about.
|
||||||
|
- glacier-bootstrap runs UNPRIVILEGED. Parsing, resolving, fetching and
|
||||||
|
verifying need no root, so it needs no third copy of the hardened
|
||||||
|
root-loading preamble (syspkg and gstore already carry it; CLAUDE.md
|
||||||
|
flags the duplication). Root is borrowed only for the two syspkg
|
||||||
|
calls.
|
||||||
|
- Its own verification is early-fail, for good error messages. syspkg's
|
||||||
|
is authoritative: syspkg re-hashes every file at the moment it
|
||||||
|
reads it (refusal matrix, SECURITY_DESIGN section 4). So a file
|
||||||
|
swapped in the cache between bootstrap's check and syspkg's read is
|
||||||
|
caught. The cache is the invoking user's (0700). The only party who
|
||||||
|
could swap files there is the person who can already run doas
|
||||||
|
syspkg.
|
||||||
|
|
||||||
|
Where trust comes from, per source:
|
||||||
|
|
||||||
|
local (-d) The sidecar next to each .gpkg, same as syspkg today.
|
||||||
|
INTEGRITY ONLY, which is all the current tree offers
|
||||||
|
anywhere.
|
||||||
|
|
||||||
|
remote, pinned The TEMPLATE pins each package's sha256 (section 3).
|
||||||
|
glacier-bootstrap writes the sidecar FROM THE PIN, not
|
||||||
|
from anything the server sent. So syspkg's existing
|
||||||
|
"sidecar matches file" check enforces the template's
|
||||||
|
hash, with no syspkg change needed. The server is an
|
||||||
|
untrusted blob store. Authenticity is exactly as good
|
||||||
|
as the template file's, which you hold locally and can
|
||||||
|
review or diff.
|
||||||
|
|
||||||
|
remote, signed Later: a signed repo index (the agreed next major item
|
||||||
|
after the checkpoints). Only then may a template name a
|
||||||
|
remote package without a pin.
|
||||||
|
|
||||||
|
remote, unpinned and unsigned: REFUSED. A .gpkg and its .sha256
|
||||||
|
fetched from the same server prove nothing (SECURITY_DESIGN section 1:
|
||||||
|
the hash travelling with the file).
|
||||||
|
|
||||||
|
|
||||||
|
+--------------------------------------------+
|
||||||
|
| 3. Template index format |
|
||||||
|
+--------------------------------------------+
|
||||||
|
|
||||||
|
Extends IMAGE_DESIGN.txt section 5's KEY=value proposal with one line
|
||||||
|
per package, so packages can carry pins:
|
||||||
|
|
||||||
|
# templates/minimal.template
|
||||||
|
NAME=minimal
|
||||||
|
PKG=filesystem 1.0.0
|
||||||
|
PKG=musl 1.2.5 sha256:3a5f...
|
||||||
|
PKG=busybox 1.37.0 sha256:91c0...
|
||||||
|
|
||||||
|
- Exact versions only, no ranges. A template describes ONE system,
|
||||||
|
reproducibly.
|
||||||
|
- A pin is optional for -d (if present, it must ALSO match the
|
||||||
|
sidecar) and required for -r until signed repos exist.
|
||||||
|
- Strict parsing: unknown keys, a duplicate PKG name, a malformed pin
|
||||||
|
and an empty package list are all hard errors. SYS_PROFILE is an
|
||||||
|
unknown key (9b): nothing could check it until manifests record a
|
||||||
|
profile (ROADMAP 3.3). Remember gworld bug
|
||||||
|
10: a field silently never parsing, with a default that looks right.
|
||||||
|
- A `glacier-bootstrap --pin PKGDIR TEMPLATE` helper that fills pins in
|
||||||
|
from local sidecars is the obvious way to produce a pinned template
|
||||||
|
from a gworld build. Pinning then becomes a review step, not
|
||||||
|
hand-copying hex.
|
||||||
|
|
||||||
|
|
||||||
|
+--------------------------------------------+
|
||||||
|
| 4. Resolution |
|
||||||
|
+--------------------------------------------+
|
||||||
|
|
||||||
|
Manifests already carry PKG_DEPS and PKG_CONFS (name + version), and
|
||||||
|
libglacier parses both into gl_pkg_t. Nothing consumes them today, and
|
||||||
|
every existing package leaves them empty. (IMAGE_DESIGN.txt section 5
|
||||||
|
says glacier has no runtime deps at all. The format exists; the use
|
||||||
|
doesn't.)
|
||||||
|
|
||||||
|
Recommendation: CHECK, don't auto-resolve.
|
||||||
|
|
||||||
|
- Every PKG_DEPS entry of every listed package must itself be listed,
|
||||||
|
at that version or later (decided 2026-10-06: the ROADMAP 2.3 rule, so
|
||||||
|
the template check and syspkg's commit check agree). Otherwise error:
|
||||||
|
"base::busybox requires musl >= 1.2.5, which the template does not
|
||||||
|
list." / "..., but the template lists 1.2.4."
|
||||||
|
- No two listed packages may conflict (PKG_CONFS).
|
||||||
|
- Each manifest's PKG_NAME/PKG_VER must match its template line. This
|
||||||
|
catches a mis-named file in -d mode, where there may be no pin.
|
||||||
|
|
||||||
|
Why not pull dependencies in automatically: anything auto-added would be
|
||||||
|
an unpinned package the template's author never reviewed, which defeats
|
||||||
|
the trust model in section 2. Closure resolution can come with signed
|
||||||
|
repos.
|
||||||
|
|
||||||
|
SYS_PROFILE can't be checked against packages yet: manifests don't
|
||||||
|
record which profile they were built under (open item in CLAUDE.md).
|
||||||
|
Once they do, a mismatched package is a resolution error.
|
||||||
|
|
||||||
|
|
||||||
|
+--------------------------------------------+
|
||||||
|
| 5. Package sources |
|
||||||
|
+--------------------------------------------+
|
||||||
|
|
||||||
|
LOCAL (-d PKGDIR): a flat directory, exactly what gbuild emits —
|
||||||
|
NAME-VER.gpkg, NAME-VER.gpkg.sha256. No index file. The template's
|
||||||
|
package list says what to take from the directory.
|
||||||
|
|
||||||
|
REMOTE (-r URL): the same flat layout over HTTPS:
|
||||||
|
|
||||||
|
URL/NAME-VER.gpkg
|
||||||
|
|
||||||
|
- Fetch by shelling out to curl (`--proto =https --fail`), the same
|
||||||
|
way gbuild shells out to git and tar, into
|
||||||
|
$XDG_CACHE_HOME/glacier-bootstrap/ (0700) under a temporary name.
|
||||||
|
Hash it, and only then rename it into place.
|
||||||
|
- Server-provided .sha256 files are never consulted (section 2).
|
||||||
|
- Cache hits are re-hashed against the pin on every run. The cache is
|
||||||
|
a download optimization, not a trusted store.
|
||||||
|
- Later, with signing: URL/repo.idx plus its signature, listing name,
|
||||||
|
version, repo and hash. The fetch path stays the same.
|
||||||
|
|
||||||
|
|
||||||
|
+--------------------------------------------+
|
||||||
|
| 6. What "chrootable" requires |
|
||||||
|
+--------------------------------------------+
|
||||||
|
|
||||||
|
Found while planning, by reading the code and the packages in pkgs/.
|
||||||
|
Each one is a hard blocker for `chroot TARGET /bin/sh` working at all,
|
||||||
|
independent of glacier-bootstrap itself:
|
||||||
|
|
||||||
|
a. [FIXED 2026-10-04 — extraction + linking, with both defenses
|
||||||
|
below; tests/test_package_symlinks.lua] SYMLINKS IN PACKAGES ARE
|
||||||
|
DROPPED. The extraction loop in
|
||||||
|
gl_install_pkg handles only AE_IFDIR and AE_IFREG (istoreutils.c);
|
||||||
|
symlink entries never reach the store. gl_link_pkg likewise links
|
||||||
|
only regular files. Real packages need symlinks:
|
||||||
|
- musl ships lib/ld-musl-x86_64.so.1 -> /usr/lib/libc.so. That is
|
||||||
|
the dynamic loader every musl binary asks the kernel for. It is
|
||||||
|
currently never installed; Alpine-based tests passed only
|
||||||
|
because Alpine provides its own.
|
||||||
|
- shared-library soname links (libz.so.1 -> libz.so.1.3.1);
|
||||||
|
- busybox applets.
|
||||||
|
Fix: extract symlink entries verbatim into the store, and link
|
||||||
|
them like regular files. SECURITY TRAP to design around: an archive
|
||||||
|
shipping `x -> /etc` followed by `x/passwd` writes through the
|
||||||
|
symlink, as root, into the real /etc (classic tar-slip via
|
||||||
|
symlink). Extraction must never write through a symlink: create
|
||||||
|
symlinks only after every regular file, and/or refuse any entry
|
||||||
|
whose parent path is a symlink in the store.
|
||||||
|
|
||||||
|
b. [DONE 2026-10-04 — gl_create_fs_tree, run by syspkg -n; takes a
|
||||||
|
root prefix ready for --root; tests/test_fs_tree.lua] NO TOP-LEVEL
|
||||||
|
TREE. Base packages link only under /usr
|
||||||
|
(PACKAGE_SCOPES section 3), and a leading "usr/" is the only prefix
|
||||||
|
stripped. So musl's lib/ld-musl... would land at /usr/lib, while
|
||||||
|
PT_INTERP says /lib/ld-musl-x86_64.so.1. TARGET needs merged /usr:
|
||||||
|
/bin -> usr/bin /lib -> usr/lib /sbin -> usr/bin
|
||||||
|
plus the mountpoints and dirs nothing ships: /dev /proc /sys /tmp
|
||||||
|
(1777) /run /var /root /home /etc. No package can provide these
|
||||||
|
under the current link rules (everything base goes under /usr).
|
||||||
|
Recommendation: `syspkg -n` creates this skeleton as part of
|
||||||
|
system init (under --root, and on a real system). Creating the
|
||||||
|
system's skeleton is system-scope mutation, so it belongs to
|
||||||
|
syspkg, not to the bootstrapper.
|
||||||
|
|
||||||
|
c. [DONE 2026-10-04 — decision 9c, option 1; tests/test_config_files.lua]
|
||||||
|
/etc HAS NO STORY. A base package's etc/passwd would link to
|
||||||
|
/usr/etc/passwd. And config files can't simply be symlinks into
|
||||||
|
the store anyway: editing them would modify the store and break
|
||||||
|
its hashes. This needs its own decision (section 9c). For the first
|
||||||
|
chroot milestone, the skeleton step can write a minimal
|
||||||
|
/etc/passwd and /etc/group (root only), and /etc/profile.
|
||||||
|
|
||||||
|
d. NO SHELL. The only packages that exist are musl, kilo and sbase,
|
||||||
|
and sbase is coreutils with no sh. A busybox (or mksh/dash) recipe
|
||||||
|
in base is needed.
|
||||||
|
|
||||||
|
e. REPO TIERS. sbase's manifest says PKG_REPO = "core", which is not
|
||||||
|
a tier (base / extra / community). Under system scope it would link
|
||||||
|
into /glacier/sys/links, not /usr/bin. Rebuild it as base.
|
||||||
|
|
||||||
|
f. [sidecars generated for the existing archives 2026-10-04] NO
|
||||||
|
SIDECARS. None of pkgs/*.gpkg has a .sha256. They were built
|
||||||
|
before checkpoint 2. Rebuild them with the current gbuild.
|
||||||
|
|
||||||
|
|
||||||
|
+--------------------------------------------+
|
||||||
|
| 7. Prerequisites, in order |
|
||||||
|
+--------------------------------------------+
|
||||||
|
|
||||||
|
1. [DONE] Hash verification at install time (SECURITY_DESIGN
|
||||||
|
section 4). Pins mean nothing until syspkg actually checks sidecars.
|
||||||
|
2. [DONE] Symlink extraction + linking, with the write-through-symlink
|
||||||
|
defense (6a). Needed for anything to run.
|
||||||
|
3. [DONE 2026-10-05] sysroot in the library (IMAGE_DESIGN section 3), plus the "host
|
||||||
|
/usr and /glacier untouched" test.
|
||||||
|
4. [DONE 2026-10-05, as -R/--root] syspkg --root DIR (IMAGE_DESIGN section 4), --strict (any link
|
||||||
|
refusal fails the transaction), and the skeleton on -n (6b) [the
|
||||||
|
skeleton is DONE; --root and --strict are not].
|
||||||
|
5. [DONE: ~/Projects/everest builds musl, busybox, linux and
|
||||||
|
everest-bootscripts, all base, with sidecars.] Packages: busybox
|
||||||
|
recipe (base), sbase rebuilt as base, every
|
||||||
|
package rebuilt with sidecars (6d-f).
|
||||||
|
6. [DONE 2026-10-06: Everest's `everest.sh initramfs` now builds its
|
||||||
|
tree this way, and the result boots in QEMU.] glacier-bootstrap,
|
||||||
|
local mode.
|
||||||
|
MILESTONE: `glacier-bootstrap -t -d pkgs templates/minimal.template
|
||||||
|
/mnt/everest` succeeds, `chroot /mnt/everest /bin/sh` gives a
|
||||||
|
working shell, and the host is byte-identical before and after.
|
||||||
|
7. Remote mode with pinned templates, plus the --pin helper.
|
||||||
|
8. Signed repo index (separate design pass), then unpinned remote.
|
||||||
|
|
||||||
|
1 and 2 are independent and can go in either order. 3 and 4 are the
|
||||||
|
bulk of the library/syspkg work. 6 itself is small: it's mostly
|
||||||
|
orchestration over things that have to exist anyway.
|
||||||
|
|
||||||
|
|
||||||
|
+--------------------------------------------+
|
||||||
|
| 8. Implementation shape |
|
||||||
|
+--------------------------------------------+
|
||||||
|
|
||||||
|
- LuaJIT, in glacier-ng, alongside gworld. It shares gworld's
|
||||||
|
KEY=value parsing (factor that into lib/ rather than copy it), and
|
||||||
|
reads manifests through libglacier's existing parser via FFI, so
|
||||||
|
PKG_DEPS etc. parse exactly the way syspkg will see them.
|
||||||
|
- Unprivileged, so the CWD-relative require convention is fine here.
|
||||||
|
- Shells out to: curl (remote), doas syspkg, chroot (for -t, via doas).
|
||||||
|
- Exit codes distinguish parse / resolve / fetch / verify / install
|
||||||
|
failure, so an image build script can tell them apart.
|
||||||
|
|
||||||
|
|
||||||
|
+--------------------------------------------+
|
||||||
|
| 9. Open decisions |
|
||||||
|
+--------------------------------------------+
|
||||||
|
|
||||||
|
a. IMAGE_DESIGN.txt section 9a still stands: images are bootstrap
|
||||||
|
OUTPUT, never install INPUT. Everything here assumes yes.
|
||||||
|
b. DECIDED 2026-10-06: NAME= plus one `PKG=name version [sha256:hex]`
|
||||||
|
per package; no SYS_PROFILE until manifests record one (section 3).
|
||||||
|
c. DECIDED 2026-10-04: option 1, copy on install, .new on conflict.
|
||||||
|
Implemented in istoreutils.c (install_config / prune_config): a
|
||||||
|
system-scope package's top-level etc/ is copied into /etc, never
|
||||||
|
linked. An admin-modified, admin-deleted or not-glacier-installed
|
||||||
|
file is never overwritten; package changes to it are offered once
|
||||||
|
as FILE.new. Unmodified files are updated in place and removed with
|
||||||
|
their package. User scope still links etc/ as before (open).
|
||||||
|
d. DECIDED 2026-10-04: syspkg -n creates the top-level tree itself
|
||||||
|
(6b). Implemented as gl_create_fs_tree(root, verbose), called by
|
||||||
|
gl_init_sys before the index is written.
|
||||||
|
e. DECIDED 2026-10-05: automatic closure, once there is a source to
|
||||||
|
resolve from (remote repos, ROADMAP 3.1). Until then a missing
|
||||||
|
dependency refuses; the resolver is written so 3.1 plugs in. The
|
||||||
|
index already records auto vs explicit installs (ROADMAP 2.3).
|
||||||
|
Section 4's template check still applies to bootstrap: a template
|
||||||
|
lists what it installs.
|
||||||
|
f. Pinning helper: part of glacier-bootstrap (--pin) or of gworld
|
||||||
|
(which already knows what it just built).
|
||||||
|
|
||||||
|
|
||||||
|
+--------------------------------------------+
|
||||||
|
| 10. As implemented (local mode, 2026-10-06)|
|
||||||
|
+--------------------------------------------+
|
||||||
|
|
||||||
|
glacier-bootstrap [-hvntV] -d PKGDIR TEMPLATE TARGET
|
||||||
|
|
||||||
|
Where it differs from, or adds to, sections 1-8:
|
||||||
|
|
||||||
|
- syspkg is the one on the caller's PATH (decided 2026-10-06),
|
||||||
|
resolved to an absolute path first and run through doas, or
|
||||||
|
directly when already root. -t runs `doas chroot`.
|
||||||
|
- Order: parse, then verify, then resolve. Manifests are read only
|
||||||
|
from VERIFIED copies: each PKGDIR/NAME-VER.gpkg is copied into a
|
||||||
|
private mktemp -d while being hashed, checked against its sidecar and
|
||||||
|
the pin, and given a sidecar written from that hash. syspkg is handed
|
||||||
|
the copies, so a pin binds syspkg too, and a file swapped in PKGDIR
|
||||||
|
later is never read. The copies are removed on every exit.
|
||||||
|
- TARGET must be absolute, not /, and pass gl_check_sysroot (checked
|
||||||
|
read-only up front). It must be fresh, or initialised by syspkg -n
|
||||||
|
with nothing installed: then -n is skipped, so a run declined at
|
||||||
|
syspkg's prompt can simply be repeated. TARGET with packages is
|
||||||
|
refused.
|
||||||
|
- syspkg's prompt is passed through (it's the review step). It exits 0
|
||||||
|
when declined, so afterwards TARGET's index is read (it's world-
|
||||||
|
readable) and every template package must be listed.
|
||||||
|
- Every problem in a phase is reported before failing. Exit status:
|
||||||
|
1 usage or target, 2 template, 3 verification, 4 resolution,
|
||||||
|
5 installation, 6 smoke test, 7 repositories.
|
||||||
|
- Repositories (2026-10-07; the user: bootstrap must leave a
|
||||||
|
semi-functional system, so it configures repositories, pacstrap
|
||||||
|
style). The configuration comes from a PACKAGE in the template
|
||||||
|
(Everest: everest-repos, shipping /etc/glacier/repos.conf and
|
||||||
|
keys/*.pub), so bootstrap still never writes into TARGET. After the
|
||||||
|
install check, if TARGET's repos.conf gives any repository a url,
|
||||||
|
it runs `syspkg -R TARGET -y`: syspkg reads TARGET's OWN keyring
|
||||||
|
under -R for repository operations (REPO_DESIGN section 6, "Keyrings
|
||||||
|
under -R"), fetches into TARGET/glacier/sys/repos, and so sets
|
||||||
|
TARGET's rollback floor at build time. A failed fetch: exit 7,
|
||||||
|
TARGET stays installed, no "Bootstrapped" line. No repos.conf, or
|
||||||
|
no url: `[!] No remote repositories are configured in TARGET.` and
|
||||||
|
exit 0. Copying the host's repos.conf (pacstrap's mirrorlist copy)
|
||||||
|
is left out for now (user, 2026-10-07).
|
||||||
|
- Its own lib/ is found from its realpath (package.path and ffi.load),
|
||||||
|
not the current directory; no root-ownership checks (unprivileged).
|
||||||
|
- Not implemented: -r (remote) and --pin (9f still open).
|
||||||
@@ -0,0 +1,293 @@
|
|||||||
|
+--------------------------------------------+
|
||||||
|
| Building Everest system images |
|
||||||
|
+--------------------------------------------+
|
||||||
|
|
||||||
|
STATUS: PROPOSAL. Nothing here is implemented, and the items in
|
||||||
|
section 9 are decisions still to be made, not settled ones. This is the
|
||||||
|
"dedicated design pass" SECURITY_DESIGN.txt section 10 says the
|
||||||
|
installer needs, started from the build side rather than the install
|
||||||
|
side.
|
||||||
|
|
||||||
|
Companion documents: SECURITY_DESIGN.txt (refusal matrix, syspkg
|
||||||
|
privilege model, section 10's installer reference material),
|
||||||
|
PACKAGE_SCOPES.txt (symlink routing, why /usr is shared territory).
|
||||||
|
|
||||||
|
|
||||||
|
+--------------------------------------------+
|
||||||
|
| 0. Why now |
|
||||||
|
+--------------------------------------------+
|
||||||
|
|
||||||
|
The first real `syspkg -l musl` (Alpine container, 2026-10-04) worked
|
||||||
|
exactly as designed, and showed why testing on a foreign distro has
|
||||||
|
run out of road: Alpine's own musl-dev already owns 231 of the paths
|
||||||
|
musl links into /usr, so every one was refused, and the -O/--overwrite
|
||||||
|
flag had to be added just to make musl's files the live ones.
|
||||||
|
|
||||||
|
In a system glacier builds itself, /usr starts empty. No conflicts, no
|
||||||
|
need for -O, and every file in /usr is a glacier symlink by
|
||||||
|
construction. That is the actual target. Every test so far has run
|
||||||
|
against a host distro's /usr instead.
|
||||||
|
|
||||||
|
|
||||||
|
+--------------------------------------------+
|
||||||
|
| 1. What "system image" means here |
|
||||||
|
+--------------------------------------------+
|
||||||
|
|
||||||
|
SECURITY_DESIGN.txt section 10 records that the old "system image
|
||||||
|
tarball" idea was DISCARDED in favor of package-list-driven
|
||||||
|
bootstrapping (glacier-bootstrap TEMPLATE_INDEX TARGET). This proposal
|
||||||
|
does not bring it back. The distinction:
|
||||||
|
|
||||||
|
REJECTED an image as the INPUT to an install: a prebuilt rootfs
|
||||||
|
tarball unpacked onto the target. Files arrive without
|
||||||
|
passing through syspkg, so nothing in it is under the
|
||||||
|
integrity guarantee.
|
||||||
|
|
||||||
|
PROPOSED an image as the OUTPUT of a bootstrap: a target root
|
||||||
|
built entirely by `syspkg` installing a defined package
|
||||||
|
list, every package through the normal verified path.
|
||||||
|
Packing that directory (tarball, OCI, disk image) is just
|
||||||
|
shipping a result, not a second way of producing one.
|
||||||
|
|
||||||
|
So "build a system image" = "run the bootstrap against a directory,
|
||||||
|
then optionally pack it". The bootstrap is the thing being designed;
|
||||||
|
the packing formats are thin (section 6).
|
||||||
|
|
||||||
|
DECISION NEEDED (9a): confirm this reading of section 10.
|
||||||
|
|
||||||
|
|
||||||
|
+--------------------------------------------+
|
||||||
|
| 2. Pipeline |
|
||||||
|
+--------------------------------------------+
|
||||||
|
|
||||||
|
image definition (section 5: profile + package list)
|
||||||
|
|
|
||||||
|
gworld -P PROFILE build every recipe the image needs
|
||||||
|
| -> pkgs/*.gpkg + *.gpkg.sha256
|
||||||
|
syspkg --root T -n create T/glacier/sys/...
|
||||||
|
|
|
||||||
|
syspkg --root T -l PKG... install the package list into T
|
||||||
|
| (base -> T/usr, others ->
|
||||||
|
| T/glacier/sys/links)
|
||||||
|
finalize T /etc skeleton, doas.conf, etc.
|
||||||
|
|
|
||||||
|
pack T dir | rootfs tarball | OCI | disk
|
||||||
|
|
||||||
|
Everything above already exists except `--root` (section 3/4), the
|
||||||
|
image definition (section 5), finalize, and pack.
|
||||||
|
|
||||||
|
The bootstrapping-the-bootstrapper problem (PACKAGE_SCOPES.txt section
|
||||||
|
6) mostly dissolves: syspkg, libglacier-ng, luajit and the rest of the
|
||||||
|
glacier tooling are just base-repo packages in the list. The build
|
||||||
|
host's syspkg installs them into T through the same verified path as
|
||||||
|
everything else. The trust edge moves from "whatever lays syspkg down"
|
||||||
|
to "the build host's syspkg". That's an honest edge, but a much smaller
|
||||||
|
and more auditable one than an unverified bootstrap step.
|
||||||
|
|
||||||
|
|
||||||
|
+--------------------------------------------+
|
||||||
|
| 3. Library prerequisite: install root |
|
||||||
|
+--------------------------------------------+
|
||||||
|
|
||||||
|
Every path in the library is a hardcoded absolute path today:
|
||||||
|
pkg.c's gl_root/gl_sys*/gl_usr*, transaction.c's GL_*_BASE and
|
||||||
|
GL_*_INDEX/STORE/LINKS macros, derive_base_paths, the stage and old
|
||||||
|
paths in init/commit, the fsync_dir list, GL_BASE_LINKS_DEST ("/usr").
|
||||||
|
ctx->root_path exists but is always "/glacier" and nothing reads it as
|
||||||
|
a prefix.
|
||||||
|
|
||||||
|
Building into T needs TWO distinct roots, and conflating them is the
|
||||||
|
dangerous mistake:
|
||||||
|
|
||||||
|
install root where bytes are written: T (e.g. /mnt/everest)
|
||||||
|
runtime root what the paths mean once the /
|
||||||
|
image is booted / chrooted
|
||||||
|
|
||||||
|
Symlink TARGETS must use runtime paths (/glacier/sys/store/...), or the
|
||||||
|
image breaks the moment it's booted. Every FILESYSTEM OPERATION must
|
||||||
|
use install-root paths (T/glacier/sys/store/..., T/usr/...).
|
||||||
|
|
||||||
|
The specific trap: prune_stale_links decides a glacier symlink is stale
|
||||||
|
by stat()ing through it. For an absolute target, that resolves against
|
||||||
|
the HOST's filesystem, not T. That would prune live links because the
|
||||||
|
host doesn't have the package, or worse, keep stale ones because it
|
||||||
|
does. is_glacier_symlink is fine: it only compares the readlink()
|
||||||
|
string against the runtime store prefix. But every "does the target
|
||||||
|
exist" check has to become "does T + target exist". The same goes for
|
||||||
|
restore_displaced and for anything else that follows a link.
|
||||||
|
|
||||||
|
Shape (ACCEPTED 2026-10-05):
|
||||||
|
|
||||||
|
- The library refuses a sysroot other than "/" for GL_SCOPE_USR
|
||||||
|
contexts. Only system scope may target another root, for every
|
||||||
|
caller, not just the CLIs (section 4).
|
||||||
|
- gl_context_t gains `char sysroot[PATH_MAX]` ("" == "/"; appended
|
||||||
|
at the end, matched in lib/glacier_cdef.lua and
|
||||||
|
tests/glacier_ffi.lua).
|
||||||
|
- New gl_init_live_context_at / gl_init_stage_context_at /
|
||||||
|
gl_init_sys_at taking a sysroot. The existing functions become
|
||||||
|
wrappers passing "/", so every current caller is unchanged.
|
||||||
|
- One helper, gl_at(ctx, runtime_path, out), used for EVERY
|
||||||
|
filesystem operation. Runtime paths stay what's stored and compared.
|
||||||
|
AS BUILT (2026-10-05): the reverse, same effect. The context stores
|
||||||
|
INSTALL paths, used for every filesystem operation unchanged, and
|
||||||
|
gl_runtime_path() translates only where runtime meaning matters
|
||||||
|
(link targets, is_glacier_symlink, .displaced keys); gl_at() checks
|
||||||
|
a link's target during prune. A missed translation then lands in T,
|
||||||
|
never on the host.
|
||||||
|
- GL_BASE_LINKS_DEST resolves to sysroot + "/usr". Never the host's
|
||||||
|
/usr when a sysroot is set.
|
||||||
|
|
||||||
|
The non-negotiable test: an image build must leave the host's /usr and
|
||||||
|
/glacier byte-for-byte untouched. That is a test assertion, not a code
|
||||||
|
review item. Same class of bug as the old gl_relink_store wipe: a path
|
||||||
|
assumption quietly stops holding.
|
||||||
|
|
||||||
|
|
||||||
|
+--------------------------------------------+
|
||||||
|
| 4. syspkg --root |
|
||||||
|
+--------------------------------------------+
|
||||||
|
|
||||||
|
syspkg gains `-r/--root DIR`, which selects the *_at init variants.
|
||||||
|
gpkg/gstore do NOT get it. Per-user scope has no business in an image
|
||||||
|
build, and section 5 of SECURITY_DESIGN.txt keeps those tools from ever
|
||||||
|
reaching system scope.
|
||||||
|
|
||||||
|
Privilege: still root via doas, still no setuid. New trust check, same
|
||||||
|
reasoning as syspkg's existing self-check: DIR and every ancestor must
|
||||||
|
be root-owned and not group/world-writable. A root process writing into
|
||||||
|
a user-controlled tree is a symlink-swap away from writing somewhere
|
||||||
|
else entirely (replace T/usr with a symlink to the host's /usr between
|
||||||
|
two syscalls). Same refusal style, same message format.
|
||||||
|
|
||||||
|
The hash refusal matrix applies unchanged. Everything in an image is
|
||||||
|
either base (always refuse unverified) or system scope (always refuse
|
||||||
|
unverified), so an image build can only ever contain packages with
|
||||||
|
valid sidecars. That's the property we want; it means section 2's
|
||||||
|
gworld step must produce sidecars for everything (gbuild already does).
|
||||||
|
|
||||||
|
|
||||||
|
+--------------------------------------------+
|
||||||
|
| 5. Image definition = template index |
|
||||||
|
+--------------------------------------------+
|
||||||
|
|
||||||
|
SECURITY_DESIGN.txt section 10 noted that the old guide's "template
|
||||||
|
index" questions (32-bit libs? which libc? SELinux? init system?) are
|
||||||
|
the same axes SYS_PROFILE already encodes. Proposal: a template index
|
||||||
|
IS a profile plus an explicit package list, in the same KEY=value
|
||||||
|
format the recipe parser already reads:
|
||||||
|
|
||||||
|
# images/minimal.image
|
||||||
|
NAME=minimal
|
||||||
|
SYS_PROFILE=x86_64-musl
|
||||||
|
PKGS=musl busybox luajit libarchive zlib libconfig libglacier-ng glacier-ng doas
|
||||||
|
RECIPES=recipes/
|
||||||
|
|
||||||
|
No runtime dependency resolution yet. Manifests DO carry PKG_DEPS and
|
||||||
|
PKG_CONFS, and libglacier parses them, but nothing consumes them and
|
||||||
|
every package leaves them empty. (DEPS in recipes is build ordering.)
|
||||||
|
So the list is explicit and complete. GLACIER_BOOTSTRAP.txt section 4
|
||||||
|
proposes checking it against PKG_DEPS rather than auto-resolving.
|
||||||
|
|
||||||
|
Remember gworld bug 10: a field that silently never parses and falls
|
||||||
|
back to a plausible default. Unknown keys and an empty PKGS must be
|
||||||
|
hard errors.
|
||||||
|
|
||||||
|
|
||||||
|
+--------------------------------------------+
|
||||||
|
| 6. Output formats |
|
||||||
|
+--------------------------------------------+
|
||||||
|
|
||||||
|
In order of usefulness right now:
|
||||||
|
|
||||||
|
a. Directory. What the pipeline produces anyway. chroot-able
|
||||||
|
immediately, which is the first milestone (section 8).
|
||||||
|
|
||||||
|
b. Rootfs tarball -> `docker import`. Replaces the Alpine-based test
|
||||||
|
Dockerfiles with a real Everest userland. Ends the glibc-vs-musl
|
||||||
|
.so mismatch and the missing-linux-headers class of problem,
|
||||||
|
because the test environment is Everest. Every syspkg/gpkg test
|
||||||
|
then runs against a /usr glacier built.
|
||||||
|
|
||||||
|
c. Bootable disk image (kernel, bootloader, partition layout per the
|
||||||
|
old guide's /boot + optional separate /glacier partition). Later,
|
||||||
|
and blocked on there being kernel/bootloader recipes at all.
|
||||||
|
|
||||||
|
Reproducibility, so two builds of the same definition can be compared:
|
||||||
|
index files are named by wall-clock time (make_index_name), and tar
|
||||||
|
records mtimes and ownership. Honour SOURCE_DATE_EPOCH in
|
||||||
|
make_index_name, and pack with sorted entries, clamped mtimes and
|
||||||
|
numeric root:root ownership.
|
||||||
|
|
||||||
|
|
||||||
|
+--------------------------------------------+
|
||||||
|
| 7. Building without a host /usr |
|
||||||
|
+--------------------------------------------+
|
||||||
|
|
||||||
|
Consequences of /usr starting empty that the design has to own:
|
||||||
|
|
||||||
|
- Strict linking. In an image build, any "Refusing to overwrite
|
||||||
|
non-glacier path" means two packages in the list conflict, or
|
||||||
|
finalize wrote somewhere it shouldn't. It should FAIL the build, not
|
||||||
|
warn (an image-build flag on the library, or syspkg treating the
|
||||||
|
warning count as an error under --root). -O must never be used in
|
||||||
|
an image build; with an empty /usr it has nothing legitimate to do.
|
||||||
|
- Paths the system needs that no package ships: /etc (passwd, group,
|
||||||
|
doas.conf), /dev /proc /sys mountpoints, /tmp, /var. Either a `base`
|
||||||
|
package (e.g. `filesystem`, Arch's approach) or the finalize step.
|
||||||
|
Recommendation: a package, so it's verified and owned like
|
||||||
|
everything else. Finalize then shrinks to things that genuinely
|
||||||
|
vary per image (hostname, users).
|
||||||
|
- /bin, /lib, /sbin. PACKAGE_SCOPES routes base to /usr only. Either
|
||||||
|
the filesystem package ships /bin -> usr/bin style merged-usr
|
||||||
|
symlinks, or every #! /bin/sh breaks. Recommendation: merged /usr,
|
||||||
|
shipped by the filesystem package.
|
||||||
|
|
||||||
|
|
||||||
|
+--------------------------------------------+
|
||||||
|
| 8. Milestones |
|
||||||
|
+--------------------------------------------+
|
||||||
|
|
||||||
|
1. [DONE 2026-10-05] sysroot in the library (section 3), plus the
|
||||||
|
host-untouched test (glacier-ng/tests/sysroot_alpine.sh). Implemented
|
||||||
|
with INSTALL paths in the context and runtime translation where a
|
||||||
|
path's meaning matters; see CLAUDE.md "Install root / sysroot".
|
||||||
|
No CLI changes, testable through FFI alone.
|
||||||
|
2. [DONE 2026-10-05] syspkg --root (section 4), with the root-owned-target
|
||||||
|
check, as -R/--root (implies --strict). glacier-ng/tests/root_alpine.sh.
|
||||||
|
3. A `filesystem` base package (section 7).
|
||||||
|
4. images/minimal.image + a driver script (gworld -> syspkg --root
|
||||||
|
-> finalize). Milestone: `chroot T /bin/sh` works, and
|
||||||
|
`chroot T syspkg -l` installs a package from inside.
|
||||||
|
5. Tarball + `docker import`; switch the test suite to run on it.
|
||||||
|
6. Disk images: blocked on kernel/bootloader recipes and on the
|
||||||
|
installer side of section 10 (partitioning, the separate /glacier
|
||||||
|
partition question).
|
||||||
|
|
||||||
|
Hash verification at install time (SECURITY_DESIGN.txt section 4)
|
||||||
|
should land before or alongside milestone 2. An image build is
|
||||||
|
"base-repo packages, the strictest tier" by definition, so it's the
|
||||||
|
first real consumer of the refusal matrix.
|
||||||
|
|
||||||
|
|
||||||
|
+--------------------------------------------+
|
||||||
|
| 9. Open decisions |
|
||||||
|
+--------------------------------------------+
|
||||||
|
|
||||||
|
a. Section 1's reading of SECURITY_DESIGN section 10: images as
|
||||||
|
bootstrap OUTPUT are fine, images as install INPUT stay rejected.
|
||||||
|
b. Template index format: the KEY=value file in section 5, or
|
||||||
|
something else.
|
||||||
|
c. `filesystem` package vs finalize script for /etc and friends, and
|
||||||
|
merged /usr (section 7).
|
||||||
|
d. Build privilege: building as real root inside a throwaway
|
||||||
|
container (works today), or rootless via user namespaces (unshare
|
||||||
|
-r) later. Rootless changes nothing in section 4's checks, since
|
||||||
|
inside the namespace the tree IS root-owned, but it does need the
|
||||||
|
packing step to write numeric root ownership regardless of who
|
||||||
|
built it.
|
||||||
|
e. Whether the image's own index/store should be built with the
|
||||||
|
image's final paths only, or also carry provenance: which
|
||||||
|
SYS_PROFILE and which image definition produced it. CLAUDE.md
|
||||||
|
already lists "manifests don't record SYS_PROFILE" as open. An
|
||||||
|
image is where that gap starts to hurt.
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
include config.mk
|
include config.mk
|
||||||
|
|
||||||
.PHONY: all prepare log log_test rt pkg istoreutils make_conf dag install clean static libglacier.a install_static libglacier-ng sha256 gsha256sum libglacier_verify
|
.PHONY: all prepare log log_test pkg transaction istoreutils install clean static libglacier.a install_static libglacier-ng sha256 gsha256sum libglacier_verify gsign grepo
|
||||||
|
|
||||||
all: prepare log log_test rt pkg transaction istoreutils make_conf dag sha256 libglacier_verify gsha256sum
|
all: prepare log log_test pkg transaction istoreutils sha256 libglacier_verify gsha256sum gsign grepo
|
||||||
@echo "libglacier-ng has finished building"
|
@echo "libglacier-ng has finished building"
|
||||||
|
|
||||||
static: prepare log_static pkg_static istoreutils_static libglacier.a
|
static: prepare log_static pkg_static istoreutils_static libglacier.a
|
||||||
@@ -15,12 +15,14 @@ pkg_static:
|
|||||||
|
|
||||||
istoreutils_static: pkg_static
|
istoreutils_static: pkg_static
|
||||||
$(CC) $(CFLAGS) -c src/istoreutils.c -o build/lib/tmp/istoreutils.o
|
$(CC) $(CFLAGS) -c src/istoreutils.c -o build/lib/tmp/istoreutils.o
|
||||||
|
$(CC) $(CFLAGS) -c src/deps.c -o build/lib/tmp/deps.o
|
||||||
|
|
||||||
libglacier.a:
|
libglacier.a:
|
||||||
ar rcs build/lib/libglacier.a \
|
ar rcs build/lib/libglacier.a \
|
||||||
build/lib/tmp/log.o \
|
build/lib/tmp/log.o \
|
||||||
build/lib/tmp/pkg.o \
|
build/lib/tmp/pkg.o \
|
||||||
build/lib/tmp/istoreutils.o
|
build/lib/tmp/istoreutils.o \
|
||||||
|
build/lib/tmp/deps.o
|
||||||
|
|
||||||
prepare:
|
prepare:
|
||||||
mkdir -p build
|
mkdir -p build
|
||||||
@@ -38,19 +40,30 @@ log:
|
|||||||
log_test:
|
log_test:
|
||||||
$(CC) $(CFLAGS) -shared -fPIC src/log.c -o build/lib/shared/libglacier_log.so
|
$(CC) $(CFLAGS) -shared -fPIC src/log.c -o build/lib/shared/libglacier_log.so
|
||||||
|
|
||||||
rt:
|
|
||||||
$(CC) $(CFLAGS) src/runtime.c -c -o build/lib/tmp/runtime.o
|
|
||||||
|
|
||||||
sha256:
|
sha256:
|
||||||
$(CC) $(CFLAGS) src/sha256.c -c -o build/lib/tmp/sha256.o
|
$(CC) $(CFLAGS) src/sha256.c -c -o build/lib/tmp/sha256.o
|
||||||
|
|
||||||
|
# Monocypher, vendored unmodified (src/monocypher/README): Ed25519 for
|
||||||
|
# sign.c.
|
||||||
|
MONOCYPHER = src/monocypher/monocypher.c src/monocypher/monocypher-ed25519.c
|
||||||
|
|
||||||
libglacier_verify:
|
libglacier_verify:
|
||||||
$(CC) $(CFLAGS) -shared -fPIC src/sha256.c \
|
$(CC) $(CFLAGS) -shared -fPIC src/sha256.c src/sign.c $(MONOCYPHER) \
|
||||||
-o build/lib/shared/libglacier_verify.so
|
-o build/lib/shared/libglacier_verify.so
|
||||||
|
|
||||||
gsha256sum: prepare
|
gsha256sum: prepare
|
||||||
$(CC) $(CFLAGS) src/gsha256sum.c src/sha256.c -o build/bin/gsha256sum
|
$(CC) $(CFLAGS) src/gsha256sum.c src/sha256.c -o build/bin/gsha256sum
|
||||||
|
|
||||||
|
gsign: prepare
|
||||||
|
$(CC) $(CFLAGS) src/gsign.c src/sign.c src/log.c $(MONOCYPHER) -o build/bin/gsign
|
||||||
|
|
||||||
|
# grepo reads packages (manifest, hash) and signs the index: built
|
||||||
|
# from source like gsign, so it needs no rpath to the shared objects.
|
||||||
|
grepo: prepare
|
||||||
|
$(CC) $(CFLAGS) src/grepo.c src/sign.c src/sha256.c src/log.c src/pkg.c \
|
||||||
|
src/istoreutils.c src/deps.c src/transaction.c $(MONOCYPHER) \
|
||||||
|
-larchive -lconfig -o build/bin/grepo
|
||||||
|
|
||||||
transaction: log istoreutils
|
transaction: log istoreutils
|
||||||
$(CC) $(CFLAGS) -shared -fPIC src/transaction.c \
|
$(CC) $(CFLAGS) -shared -fPIC src/transaction.c \
|
||||||
-Lbuild/lib/shared -lglacier_istoreutils -lglacier_log \
|
-Lbuild/lib/shared -lglacier_istoreutils -lglacier_log \
|
||||||
@@ -58,7 +71,7 @@ transaction: log istoreutils
|
|||||||
-o build/lib/shared/libglacier_transaction.so
|
-o build/lib/shared/libglacier_transaction.so
|
||||||
|
|
||||||
istoreutils: pkg
|
istoreutils: pkg
|
||||||
$(CC) $(CFLAGS) -shared -fPIC src/istoreutils.c \
|
$(CC) $(CFLAGS) -shared -fPIC src/istoreutils.c src/deps.c \
|
||||||
-Lbuild/lib/shared -lglacier_log -lglacier_pkg -larchive \
|
-Lbuild/lib/shared -lglacier_log -lglacier_pkg -larchive \
|
||||||
-Wl,-rpath,'$$ORIGIN' \
|
-Wl,-rpath,'$$ORIGIN' \
|
||||||
-o build/lib/shared/libglacier_istoreutils.so
|
-o build/lib/shared/libglacier_istoreutils.so
|
||||||
@@ -69,21 +82,12 @@ pkg:
|
|||||||
-Wl,-rpath,'$$ORIGIN' \
|
-Wl,-rpath,'$$ORIGIN' \
|
||||||
-o build/lib/shared/libglacier_pkg.so
|
-o build/lib/shared/libglacier_pkg.so
|
||||||
|
|
||||||
make_conf:
|
|
||||||
$(CC) $(CFLAGS) src/make_conf.c -c -o build/lib/tmp/make_conf.o
|
|
||||||
|
|
||||||
libglacier-ng: prepare
|
libglacier-ng: prepare
|
||||||
$(CC) $(CFLAGS) -shared -fPIC \
|
$(CC) $(CFLAGS) -shared -fPIC \
|
||||||
src/log.c src/pkg.c src/transaction.c src/istoreutils.c \
|
src/log.c src/pkg.c src/transaction.c src/istoreutils.c src/deps.c \
|
||||||
-larchive -lconfig \
|
-larchive -lconfig \
|
||||||
-o build/lib/shared/libglacier-ng.so
|
-o build/lib/shared/libglacier-ng.so
|
||||||
|
|
||||||
dag:
|
|
||||||
$(CC) $(CFLAGS) -shared -fPIC src/dag.c \
|
|
||||||
-Lbuild/lib/shared -lglacier_log \
|
|
||||||
-Wl,-rpath,'$$ORIGIN' \
|
|
||||||
-o build/lib/shared/libglacier_dag.so
|
|
||||||
|
|
||||||
install:
|
install:
|
||||||
mkdir -p $(PREFIX)/lib/glacier/
|
mkdir -p $(PREFIX)/lib/glacier/
|
||||||
install build/lib/shared/libglacier_log.so $(PREFIX)/lib/glacier/ -m 755
|
install build/lib/shared/libglacier_log.so $(PREFIX)/lib/glacier/ -m 755
|
||||||
@@ -92,14 +96,12 @@ install:
|
|||||||
install build/lib/shared/libglacier_pkg.so $(PREFIX)/lib/glacier -m 755
|
install build/lib/shared/libglacier_pkg.so $(PREFIX)/lib/glacier -m 755
|
||||||
install build/lib/shared/libglacier_verify.so $(PREFIX)/lib/glacier -m 755
|
install build/lib/shared/libglacier_verify.so $(PREFIX)/lib/glacier -m 755
|
||||||
install build/bin/gsha256sum $(PREFIX)/bin/ -m 755
|
install build/bin/gsha256sum $(PREFIX)/bin/ -m 755
|
||||||
|
install build/bin/gsign $(PREFIX)/bin/ -m 755
|
||||||
|
install build/bin/grepo $(PREFIX)/bin/ -m 755
|
||||||
|
|
||||||
install_static:
|
install_static:
|
||||||
mkdir -p $(PREFIX)/lib/glacier
|
mkdir -p $(PREFIX)/lib/glacier
|
||||||
install build/lib/libglacier.a $(PREFIX)/lib/glacier/ -m 644
|
install build/lib/libglacier.a $(PREFIX)/lib/glacier/ -m 644
|
||||||
|
|
||||||
install_test_dir:
|
|
||||||
install build/lib/shared/lg_log.so $(TEST_DIR)
|
|
||||||
install build/lib/shared/
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf build
|
rm -rf build
|
||||||
+31
-9
@@ -15,21 +15,33 @@ up to and including destroying a live /usr.
|
|||||||
+------------------------------------+
|
+------------------------------------+
|
||||||
|
|
||||||
USR (GL_SCOPE_USR)
|
USR (GL_SCOPE_USR)
|
||||||
Per-uid packages. Index/store/links all live under a specific
|
Per-uid packages. Everything a uid's transactions touch lives
|
||||||
uid's tree:
|
under ONE directory that uid owns:
|
||||||
/glacier/usr/index/<uid>
|
/glacier/usr/<uid>/{index,store,links,stage,old,lock}
|
||||||
/glacier/usr/store/<uid>
|
/glacier/usr itself is root-owned (0755) and each /glacier/usr/<uid>
|
||||||
/glacier/usr/links/<uid>
|
is owned by that uid (0700), so every create/rename/lock a
|
||||||
Symlinks always land under /glacier/usr/links/<uid>/{bin,...}.
|
transaction does happens inside the user's own directory — no shared
|
||||||
|
writable parent, so no uid can create or squat another's. Root
|
||||||
|
creates each one: `gstore -n UID` directly, or a user for themselves
|
||||||
|
via a doas rule pinned to `gstore -n` (see gstore's header). The
|
||||||
|
library refuses a base that isn't a real directory owned by its uid
|
||||||
|
with no group/other bits, or whose /glacier/usr is loosened.
|
||||||
|
Symlinks always land under /glacier/usr/<uid>/links/{bin,...}.
|
||||||
There is no base-repo exception for USR scope. Nothing installed
|
There is no base-repo exception for USR scope. Nothing installed
|
||||||
under a per-user scope is ever considered part of the base system,
|
under a per-user scope is ever considered part of the base system,
|
||||||
so nothing here ever touches /usr.
|
so nothing here ever touches /usr.
|
||||||
|
|
||||||
SYS (GL_SCOPE_SYS)
|
SYS (GL_SCOPE_SYS)
|
||||||
System-wide packages, not owned by any particular uid:
|
System-wide packages, not owned by any particular uid:
|
||||||
/glacier/sys/index
|
/glacier/sys/{index,store,links,stage,old,lock}
|
||||||
/glacier/sys/store
|
|
||||||
Symlink destination depends on the package's repo (see section 3).
|
Symlink destination depends on the package's repo (see section 3).
|
||||||
|
Root-owned and world-READABLE, like /usr: index/store/links, the
|
||||||
|
store's repo/name/version dirs and implicit parent dirs are 0755,
|
||||||
|
index files 0644 (gl_scope_dir_mode / gl_scope_file_mode). /usr's
|
||||||
|
links point into the store, so every user must be able to traverse
|
||||||
|
it, and user-scope dependency checks read the system index. The
|
||||||
|
modes are applied explicitly, not left to syspkg's umask. The lock
|
||||||
|
stays 0600; .displaced, .etc-state and backup/ stay 0700.
|
||||||
Requires root. gpkg enforces this via geteuid() before it will
|
Requires root. gpkg enforces this via geteuid() before it will
|
||||||
even attempt a system-scope operation.
|
even attempt a system-scope operation.
|
||||||
|
|
||||||
@@ -69,9 +81,11 @@ decides where that package's activation symlinks physically land.
|
|||||||
| 3. Symlink placement rule |
|
| 3. Symlink placement rule |
|
||||||
+------------------------------------+
|
+------------------------------------+
|
||||||
|
|
||||||
scope == USR -> /glacier/usr/links/<uid>
|
scope == USR -> /glacier/usr/<uid>/links
|
||||||
scope == SYS && repo == "base" -> /usr (*)
|
scope == SYS && repo == "base" -> /usr (*)
|
||||||
scope == SYS && repo != "base" -> /glacier/sys/links
|
scope == SYS && repo != "base" -> /glacier/sys/links
|
||||||
|
scope == SYS, package path etc/... -> COPIED into /etc (any repo;
|
||||||
|
config, not linked — see below)
|
||||||
|
|
||||||
(*) This is the base-system exception. Packages that are part of the
|
(*) This is the base-system exception. Packages that are part of the
|
||||||
minimal working system get their symlinks placed directly into
|
minimal working system get their symlinks placed directly into
|
||||||
@@ -84,6 +98,14 @@ decides where that package's activation symlinks physically land.
|
|||||||
same as it always has. The base system is the exception to the
|
same as it always has. The base system is the exception to the
|
||||||
norm, not the other way around.
|
norm, not the other way around.
|
||||||
|
|
||||||
|
Config files are the exception to linking. Editing a symlink into the
|
||||||
|
store would edit the store itself, so a system-scope package's etc/ is
|
||||||
|
copied into /etc instead. glacier keeps a record of the last version
|
||||||
|
each package offered (<store>/.etc-state/). A file the admin changed,
|
||||||
|
deleted, or that glacier never installed is never overwritten; package
|
||||||
|
changes to it arrive once as FILE.new. Unchanged files are updated in
|
||||||
|
place and removed with their package (pacman-style).
|
||||||
|
|
||||||
This decision is made per-package, at the point where a package's repo
|
This decision is made per-package, at the point where a package's repo
|
||||||
is actually known (inside gl_link_pkg / gl_unlink_pkg / the walk loop
|
is actually known (inside gl_link_pkg / gl_unlink_pkg / the walk loop
|
||||||
in gl_relink_store) — NOT baked into the context at creation time.
|
in gl_relink_store) — NOT baked into the context at creation time.
|
||||||
|
|||||||
+446
@@ -0,0 +1,446 @@
|
|||||||
|
+--------------------------------------------+
|
||||||
|
| Remote repositories and signing |
|
||||||
|
+--------------------------------------------+
|
||||||
|
|
||||||
|
STATUS: DESIGN, 2026-10-06. ROADMAP 3.1. Steps 1 (Ed25519, signify
|
||||||
|
formats, gsign), 2 (keyring, the local base rule, gbuild -k,
|
||||||
|
bootstrap carrying .sig, Everest's key) and 3 (grepo, the index,
|
||||||
|
refresh with -y) of section 9 DONE 2026-10-06, step 4 (-f, -u,
|
||||||
|
dependency closure, the cache) DONE 2026-10-07; sections 7, 5 and 6
|
||||||
|
say how they came out. Step 5 next. See CLAUDE.md.
|
||||||
|
Sections 1 and 10 are decided; the only open item is 10a's TLS library.
|
||||||
|
|
||||||
|
Adds AUTHENTICITY to glacier: SECURITY_DESIGN.txt section 1 deferred it
|
||||||
|
to "a future phase, tied to remote-repo support". This is that phase.
|
||||||
|
It also unblocks gpkg/syspkg -f (ROADMAP 2.2), -u (2.1), automatic
|
||||||
|
dependency closure (2.3) and glacier-bootstrap -r (GLACIER_BOOTSTRAP
|
||||||
|
section 5), and closes Finding 1 of SECURITY_REVIEW_2026-07-16.md (a
|
||||||
|
manifest that says PKG_REPO = "base" gets linked into /usr).
|
||||||
|
|
||||||
|
Companion documents: SECURITY_DESIGN.txt (integrity, refusal matrix),
|
||||||
|
PACKAGE_SCOPES.txt (repo routing), GLACIER_BOOTSTRAP.txt (pins).
|
||||||
|
|
||||||
|
|
||||||
|
+--------------------------------------------+
|
||||||
|
| 1. Decisions (the user, 2026-10-06) |
|
||||||
|
+--------------------------------------------+
|
||||||
|
|
||||||
|
a. Signatures: Ed25519, vendored (Monocypher's Ed25519 variant, which
|
||||||
|
brings its own SHA-512), compiled into the private
|
||||||
|
libglacier_verify.so next to sha256. Key and signature files are
|
||||||
|
signify-compatible, so OpenBSD's signify can make and check them
|
||||||
|
too. No new base dependency.
|
||||||
|
b. What is signed: one INDEX per repository (repo.idx + repo.idx.sig),
|
||||||
|
listing every package it serves with its sha256. Packages are
|
||||||
|
verified through the hash in the signed index, i.e. through the
|
||||||
|
existing sha256 path. The index has a serial; a client refuses an
|
||||||
|
index older than the last one it accepted (rollback).
|
||||||
|
c. Local base packages: once signing exists, `syspkg -l FILE` of a
|
||||||
|
package whose manifest says base requires a signature by a key
|
||||||
|
trusted for base. extra/community local installs stay
|
||||||
|
sidecar-only (integrity). Manual installation keeps working: a
|
||||||
|
builder makes a key and root adds it to the keyring.
|
||||||
|
d. Users may add their own repositories and keys, for their own scope
|
||||||
|
only (gpkg). Never read by syspkg.
|
||||||
|
|
||||||
|
|
||||||
|
+--------------------------------------------+
|
||||||
|
| 2. Keys and signatures (proposal) |
|
||||||
|
+--------------------------------------------+
|
||||||
|
|
||||||
|
signify's formats, byte for byte (two lines: "untrusted comment: ..."
|
||||||
|
then base64):
|
||||||
|
|
||||||
|
public key "Ed" | keynum[8] | pubkey[32]
|
||||||
|
signature "Ed" | keynum[8] | sig[64]
|
||||||
|
secret key "Ed" | "BK" | rounds[4] | salt[16] | checksum[8] |
|
||||||
|
keynum[8] | seckey[64]
|
||||||
|
|
||||||
|
- keynum is a random 8-byte key id; a signature names the key that
|
||||||
|
made it, so verification picks the key by keynum and never tries
|
||||||
|
every key in the keyring.
|
||||||
|
- Signing is pure Ed25519 over the WHOLE message, as signify does. So
|
||||||
|
we never sign a .gpkg directly (it would have to be read into memory
|
||||||
|
whole). What gets signed is small:
|
||||||
|
- a repository's repo.idx;
|
||||||
|
- a local package's SIDECAR (NAME-VER.gpkg.sha256, the one line
|
||||||
|
"sha256:<hex>"), as NAME-VER.gpkg.sha256.sig. Checking the
|
||||||
|
sidecar against the file is the existing path; the signature
|
||||||
|
makes the sidecar authentic. `signify -V -p KEY -m X.sha256`
|
||||||
|
checks the same file.
|
||||||
|
- Secret keys: glacier's tools read and write only UNENCRYPTED secret
|
||||||
|
keys (rounds = 0, what `signify -G -n` makes): passphrase support
|
||||||
|
needs bcrypt_pbkdf, which is more vendored crypto for a build-host
|
||||||
|
convenience. A passphrase-protected key works by signing with
|
||||||
|
signify itself (10b).
|
||||||
|
|
||||||
|
New tool `gsign` (C, built with gsha256sum; a build/maintainer tool,
|
||||||
|
later in "glacier-tools", never in base):
|
||||||
|
|
||||||
|
gsign -G -p KEY.pub -s KEY.sec [-c COMMENT] make a keypair
|
||||||
|
gsign -S -s KEY.sec -m FILE [-x SIGFILE] sign (default FILE.sig)
|
||||||
|
gsign -V -p KEY.pub -m FILE [-x SIGFILE] verify
|
||||||
|
|
||||||
|
gbuild gains `-k KEY.sec`: sign the sidecar it writes.
|
||||||
|
|
||||||
|
|
||||||
|
+--------------------------------------------+
|
||||||
|
| 3. Keyring and repository configuration |
|
||||||
|
+--------------------------------------------+
|
||||||
|
|
||||||
|
System (root-owned; syspkg applies its trust checks to these files and
|
||||||
|
every ancestor, like its own lib/):
|
||||||
|
|
||||||
|
/etc/glacier/keys/NAME.pub
|
||||||
|
/etc/glacier/repos.conf
|
||||||
|
|
||||||
|
repos.conf (libconfig, like glacier.conf):
|
||||||
|
|
||||||
|
repos = (
|
||||||
|
{ name = "base"; url = "https://pkg.example.org/base";
|
||||||
|
keys = [ "everest-2026" ]; },
|
||||||
|
{ name = "extra"; url = "https://pkg.example.org/extra";
|
||||||
|
keys = [ "everest-2026" ]; }
|
||||||
|
);
|
||||||
|
|
||||||
|
- A key is trusted ONLY for the repos that list it. That binding is
|
||||||
|
what makes "base" mean something: the base index must be signed by a
|
||||||
|
key listed for base, and a local base package's sidecar likewise.
|
||||||
|
Several keys per repo allow rotation (old and new side by side).
|
||||||
|
- Order = priority, when one name is served by several repos.
|
||||||
|
- name follows the gl_valid_pkg_ident rules. url is https:// or
|
||||||
|
file:// (local mirrors, tests); http:// is refused.
|
||||||
|
- url is optional: an entry without one only says which keys are
|
||||||
|
trusted for that repo, for a system installed and kept up by hand
|
||||||
|
from signed local files (section 7).
|
||||||
|
- Missing file = no remote repositories; -f/-u then refuse in one
|
||||||
|
line. No defaults, as with KEEP_OLD.
|
||||||
|
|
||||||
|
User (gpkg only):
|
||||||
|
|
||||||
|
~/.config/glacier/repos.conf ($XDG_CONFIG_HOME)
|
||||||
|
~/.config/glacier/keys/NAME.pub
|
||||||
|
|
||||||
|
- Merged AFTER the system list (lower priority).
|
||||||
|
- A user repo named "base", or named like a system repo, is refused.
|
||||||
|
- System keys are trusted for system repos only; a user's keys for the
|
||||||
|
user's repos only.
|
||||||
|
|
||||||
|
|
||||||
|
+--------------------------------------------+
|
||||||
|
| 4. The index |
|
||||||
|
+--------------------------------------------+
|
||||||
|
|
||||||
|
URL/repo.idx and URL/repo.idx.sig. libconfig, parsed only AFTER its
|
||||||
|
signature checks:
|
||||||
|
|
||||||
|
REPO = "base";
|
||||||
|
SERIAL = 2026100601L; # strictly increases with each publish
|
||||||
|
VALID_UNTIL = 1761955200L; # unix time; required (10c)
|
||||||
|
PKGS = (
|
||||||
|
{ NAME = "musl"; VER = "1.2.5"; FILE = "musl-1.2.5.gpkg";
|
||||||
|
SHA256 = "sha256:3a5f..."; SIZE = 812345L;
|
||||||
|
DEPS = (); CONFS = (); },
|
||||||
|
...
|
||||||
|
);
|
||||||
|
|
||||||
|
- REPO must equal the configured name the index was fetched for.
|
||||||
|
- Every version a repo serves is listed (so a pinned or older version
|
||||||
|
can still be fetched by -f NAME=VER later).
|
||||||
|
- DEPS/CONFS repeat the manifest's, so dependency closure can be
|
||||||
|
planned before downloading anything. After download, the manifest
|
||||||
|
must match the entry (NAME, VER, PKG_REPO = REPO, DEPS, CONFS):
|
||||||
|
a mismatch refuses the package. That is the Finding 1 rule for
|
||||||
|
remote packages: a package is "base" because the base index lists
|
||||||
|
it AND it says so, never because it says so.
|
||||||
|
- FILE is a bare file name (gl_valid_pkg_ident rules plus ".gpkg"):
|
||||||
|
no paths, no URLs.
|
||||||
|
|
||||||
|
New tool `grepo` (maintainer side, glacier-tools): `grepo -s KEY.sec
|
||||||
|
-r REPO DIR` reads every NAME-VER.gpkg in DIR (manifests, hashes),
|
||||||
|
writes DIR/repo.idx with SERIAL = the previous one + 1 (or the date
|
||||||
|
form), and signs it. The server is then any static file host.
|
||||||
|
|
||||||
|
|
||||||
|
+--------------------------------------------+
|
||||||
|
| 5. Client state and fetching |
|
||||||
|
+--------------------------------------------+
|
||||||
|
|
||||||
|
Inside each scope's base directory (one more entry beside index, store,
|
||||||
|
...; same ownership and modes as the rest):
|
||||||
|
|
||||||
|
<base>/repos/REPO.idx, REPO.idx.sig the last ACCEPTED index
|
||||||
|
<base>/cache/REPO/FILE downloaded packages
|
||||||
|
|
||||||
|
Refresh (every -f / -u; indexes are small; 10d):
|
||||||
|
1. curl --proto =https --proto-redir =https --fail (or a file:// copy)
|
||||||
|
URL/repo.idx and .sig into a temporary file in <base>/repos/.
|
||||||
|
2. Verify the signature with a key listed for that repo (by keynum).
|
||||||
|
3. Parse. REPO must match. SERIAL must be > the stored one, or equal
|
||||||
|
with identical bytes. VALID_UNTIL must be in the future.
|
||||||
|
4. rename() over the stored copy (never written in place: bug 25).
|
||||||
|
Any failure keeps the old index and refuses the operation in one line:
|
||||||
|
[x] Index for extra is older than the one already accepted.
|
||||||
|
|
||||||
|
Fetch: download FILE into the cache under a temporary name, hash it
|
||||||
|
while downloading, rename into place only if the hash matches the
|
||||||
|
index, then write the sidecar FROM THE INDEX and hand the cached file
|
||||||
|
to the existing install path (which re-hashes it, as today). The cache
|
||||||
|
is a download optimization, not a trusted store: a cache hit is hashed
|
||||||
|
again.
|
||||||
|
|
||||||
|
As implemented (2026-10-06, step 3; the user chose a refresh flag,
|
||||||
|
the date-form SERIAL and grepo in C):
|
||||||
|
- grepo is C (src/grepo.c, libglacier-ng; built from source like
|
||||||
|
gsign, installed to bin; not in base): `grepo -s KEY.sec -r REPO
|
||||||
|
[-n SERIAL] [-e DAYS] DIR`. SERIAL = max(previous + 1, today (UTC)
|
||||||
|
* 100 + 1), e.g. 2026100601; -n must still be above the previous
|
||||||
|
one. VALID_UNTIL = now + DAYS (default 30, 1..3650). Packages are
|
||||||
|
sorted by file name; each must be a regular file, its manifest must
|
||||||
|
say REPO and its name must be NAME-VER.gpkg (VER as the store names
|
||||||
|
versions, "%d.%d.%d"). An existing DIR/repo.idx must be a
|
||||||
|
well-formed index of REPO (its SERIAL is the previous one). It is
|
||||||
|
written to a mkstemp file, signed, and both renamed into place, the
|
||||||
|
.sig first.
|
||||||
|
- The index format is section 4's, with DEPS and CONFS as lists of
|
||||||
|
{ NAME = "x"; VER = "1.0.0"; } (the manifest's PKG_DEPS shape).
|
||||||
|
gl_index_parse (pkg.c) takes the BYTES the signature was checked
|
||||||
|
over, never a path, and is strict: exactly REPO, SERIAL > 0,
|
||||||
|
VALID_UNTIL > 0, PKGS; each package exactly NAME, VER, FILE, SHA256,
|
||||||
|
SIZE >= 0, DEPS, CONFS; FILE must be exactly "NAME-VER.gpkg"; SHA256
|
||||||
|
"sha256:" + 64 lowercase hex; no NAME + VER twice. A NUL or an '@'
|
||||||
|
anywhere is refused before libconfig sees it ('@include').
|
||||||
|
GL_INDEX_ERR_REPO when REPO is not the repo it was fetched for.
|
||||||
|
- `syspkg -y` / `gpkg -y` (--refresh) refresh every repos.conf entry
|
||||||
|
with a url and stop (decision 10d still holds for -f/-u). gpkg
|
||||||
|
reads the SYSTEM repos.conf and keyring until step 6 (user repos),
|
||||||
|
and stores into the user's base. No repos.conf, or no entry with a
|
||||||
|
url: `[x] No remote repositories are configured.` (exit 1).
|
||||||
|
- <base>/repos is made by gl_scope_state_dir (transaction.c): the
|
||||||
|
base must be the scope's; repos is created with the scope's mode
|
||||||
|
(0755 root / 0700 uid) and refused unless it is a real directory
|
||||||
|
with exactly that owner and mode. Files are 0644 / 0600. -y holds
|
||||||
|
the scope's lock (gl_begin_transaction on a live context); under
|
||||||
|
-R the indexes go under the install root, checked with the install
|
||||||
|
root's OWN keyring (DIR/etc/glacier; changed 2026-10-07, see
|
||||||
|
"Keyrings under -R" below).
|
||||||
|
- file:// is read directly (absolute paths only); https:// goes
|
||||||
|
through `curl -sf --proto =https --proto-redir =https`. 64 MiB at
|
||||||
|
most (GL_SIGN_MAX_MSG). Every repo is tried; exit 1 if any failed.
|
||||||
|
- One line per repo:
|
||||||
|
[✓] Index for base: serial 2026100601, 11 packages.
|
||||||
|
[i] Index for base is up to date: serial 2026100601.
|
||||||
|
[x] Cannot fetch the index for base. (a missing .sig too)
|
||||||
|
[x] Index for base is not signed by a key trusted for base.
|
||||||
|
[x] Malformed index for base.
|
||||||
|
[x] Index fetched for base is the index of another repository.
|
||||||
|
[x] Index for base is older than the one already accepted.
|
||||||
|
[x] Index for base has the serial of the one already accepted, but other contents.
|
||||||
|
[x] Index for base has expired.
|
||||||
|
[x] Malformed /glacier/sys/repos/base.idx. (left for the admin)
|
||||||
|
- The accepted copy is trusted by where it lives (root's or the
|
||||||
|
user's private repos dir): it is parsed for its SERIAL, not
|
||||||
|
re-verified.
|
||||||
|
- Test: glacier-ng/tests/repo_alpine.sh (103 checks; 18 mutants, 12 C
|
||||||
|
and 6 Lua, all caught).
|
||||||
|
|
||||||
|
|
||||||
|
+--------------------------------------------+
|
||||||
|
| 6. -f, -u and dependency closure |
|
||||||
|
+--------------------------------------------+
|
||||||
|
|
||||||
|
-f NAME... (ROADMAP 2.2): like -l, with the file found by name in the
|
||||||
|
accepted indexes (highest version, first repo by priority). Missing
|
||||||
|
dependencies are added automatically (ROADMAP 2.3's closure): the
|
||||||
|
highest version satisfying the minimum, recorded `auto`. The
|
||||||
|
summary lists them, marked as dependencies. Conflicts and every
|
||||||
|
2.3 check run as today, before the prompt.
|
||||||
|
-u (ROADMAP 2.1): every installed package whose repo is configured and
|
||||||
|
whose index has a higher version is replaced, as -lO does (backups,
|
||||||
|
KEEP_OLD). Packages from repos not configured are left alone.
|
||||||
|
`-u NAME...` limits it to those names.
|
||||||
|
syspkg -f/-u fetch only from system repos; gpkg -f/-u from system and
|
||||||
|
the user's repos. Base is still refused in user scope (library rule).
|
||||||
|
|
||||||
|
As implemented (2026-10-07, step 4; M.fetch / M.upgrade in
|
||||||
|
glacier-ng/lib/gpkg_common.lua). The user decided three details:
|
||||||
|
- Which repo: the FIRST repo by repos.conf order that serves NAME, at
|
||||||
|
its highest version. A lower-priority repo never wins by publishing
|
||||||
|
a bigger version. -u stays within the installed package's repo.
|
||||||
|
- A dependency installed at too old a version is UPGRADED in the same
|
||||||
|
transaction from its own repo (backed up per KEEP_OLD, like -lO),
|
||||||
|
keeping its auto/explicit mark; the summary shows
|
||||||
|
"old -> new (dependency)".
|
||||||
|
- Cache: downloads stay in <base>/cache/REPO while a run is declined
|
||||||
|
or refused; the files a commit installed are deleted after it.
|
||||||
|
The rest:
|
||||||
|
- Every -f/-u runs -y's refresh first; if any repo fails, the
|
||||||
|
operation is refused (decision 10d). The accepted indexes are then
|
||||||
|
read from <base>/repos (gl_index_parse again; trusted by location).
|
||||||
|
- Closure: for each planned package, each DEPS entry of its INDEX
|
||||||
|
entry is met by a planned package, an installed one at >= VER
|
||||||
|
(this scope; for a user, the system's index too), else upgraded (an
|
||||||
|
installed one too old) or added (pick(): first repo serving it,
|
||||||
|
recorded auto). What can't be met is left to gl_check_plan, which
|
||||||
|
prints the 2.3 refusal. The summary marks additions
|
||||||
|
"(dependency)".
|
||||||
|
- Download: gl_scope_cache_dir (transaction.c) makes and checks
|
||||||
|
<base>/cache and <base>/cache/REPO as gl_scope_state_dir checks
|
||||||
|
repos (owner, exact mode, not a symlink). A cached file whose hash
|
||||||
|
matches the index is reused; otherwise file:// is read, https://
|
||||||
|
goes through `curl -sf --proto =https --proto-redir =https` on a
|
||||||
|
pipe; at most SIZE + 1 bytes are ever read, hashed on the way, into
|
||||||
|
a dot-named temporary, renamed into place only if size and hash
|
||||||
|
match. 0644 / 0600.
|
||||||
|
- No sidecar is written: the index's sha256 is handed to
|
||||||
|
verify_and_copy directly (its `vouched` argument), which re-hashes
|
||||||
|
while copying into the private dir, as for -l. A base package needs
|
||||||
|
no .sig of its own: the base index vouches for it.
|
||||||
|
- The copy's manifest (library-read) must say exactly what the index
|
||||||
|
entry says: NAME, VER, PKG_REPO = the repo, DEPS and CONFS (same
|
||||||
|
order, "NAME MAJ.MIN.PAT"). Else, and for a bad hash or size:
|
||||||
|
[x] extra::evil 1.0.0 does not match its index.
|
||||||
|
and the cached file is deleted. Nothing to download:
|
||||||
|
[x] Cannot fetch extra::foo 1.0.0.
|
||||||
|
No repo serves a name:
|
||||||
|
[x] foo is not in any repository.
|
||||||
|
- -f of a name installed at another version needs -O (as -l);
|
||||||
|
dependency upgrades and -u don't (meta.may_replace). -O still also
|
||||||
|
means displacing foreign files.
|
||||||
|
- -u [NAME...]: a named package not installed, or whose repo has no
|
||||||
|
url, is refused (`[x] foo is not installed.` / `[x] community::foo
|
||||||
|
is not in any configured repository.`); plain -u skips the latter.
|
||||||
|
Nothing newer: `[✓] Nothing to do.`, exit 0.
|
||||||
|
- gpkg: user scope never fetches from base (base indexes are not even
|
||||||
|
considered, so `[x] core is not in any repository.`); the system's
|
||||||
|
repos.conf until step 6; indexes and cache in the user's base.
|
||||||
|
- syspkg -R DIR -f/-u: indexes and cache under DIR, DIR's keyring.
|
||||||
|
|
||||||
|
Keyrings under -R (decided 2026-10-07, for glacier-bootstrap
|
||||||
|
configuring the system's repositories): -y, -f and -u read
|
||||||
|
DIR/etc/glacier/repos.conf and DIR/etc/glacier/keys, with the same
|
||||||
|
trust checks, plus: each file's real path must lie inside DIR
|
||||||
|
(`[x] Refusing P: it resolves outside DIR.`), so a symlink in DIR
|
||||||
|
can't make the host's file stand in for DIR's. The indexes are DIR's
|
||||||
|
state and DIR checks them with its own keys from then on, and a host
|
||||||
|
with no glacier configuration can still bootstrap. A local `-R -l`
|
||||||
|
base package's .sig is still checked with the HOST's keyring (section
|
||||||
|
7). Tests: repo_alpine.sh / fetch_alpine.sh give the image its own
|
||||||
|
keyring; bootstrap_alpine.sh sections 14-16.
|
||||||
|
- Test: glacier-ng/tests/fetch_alpine.sh (84 checks; 16 Lua mutants
|
||||||
|
and 1 C mutant, all caught except the download-level hash check,
|
||||||
|
which is EQUIVALENT: the private copy's re-hash refuses the same
|
||||||
|
package and the mismatch path deletes the cached file. Kept as
|
||||||
|
defence in depth: a bad download never sits in the cache under its
|
||||||
|
final name).
|
||||||
|
- Known gap: a run killed mid-download leaves its dot-named temporary
|
||||||
|
in the cache (never read; the next fetch writes its own).
|
||||||
|
|
||||||
|
|
||||||
|
+--------------------------------------------+
|
||||||
|
| 7. Local installs (decision 1c) |
|
||||||
|
+--------------------------------------------+
|
||||||
|
|
||||||
|
syspkg -l FILE, manifest says base:
|
||||||
|
FILE.sha256 must match (as today) AND FILE.sha256.sig must verify
|
||||||
|
with a key listed for base in repos.conf. Otherwise:
|
||||||
|
[x] base::musl is not signed by a key trusted for base.
|
||||||
|
syspkg -l, other repos; gpkg -l: unchanged (sidecar only).
|
||||||
|
glacier-bootstrap -d: carries each package's .sig into its private
|
||||||
|
copies, so syspkg -R checks it. The keyring checked is the HOST's
|
||||||
|
/etc/glacier (the build host's trust, as KEEP_OLD is today).
|
||||||
|
Consequence for ~/Projects/everest: it needs a key; container.sh signs
|
||||||
|
every base package (gbuild -k); the build host's /etc/glacier/keys and
|
||||||
|
repos.conf list it. The image ships the PUBLIC key and a repos.conf so
|
||||||
|
the installed system trusts its own base (since 2026-10-07 in the
|
||||||
|
everest-repos package, split out of everest-bootscripts).
|
||||||
|
|
||||||
|
As implemented (2026-10-06, step 2):
|
||||||
|
- The repo is the one the LIBRARY reads from the verified copy
|
||||||
|
(gl_read_pkg_manifest, as gl_install_pkg), never gpkg_common's
|
||||||
|
pattern-matching read_manifest_fields: a manifest comment
|
||||||
|
`# PKG_REPO = "extra"` would make that one say extra.
|
||||||
|
- The sidecar is read ONCE; those bytes are both what the copy's hash
|
||||||
|
is checked against and what the signature is checked over. So
|
||||||
|
glacier-bootstrap copies the sidecar's bytes as read (it used to
|
||||||
|
write a new one from the hash) next to the .sig.
|
||||||
|
- The key is the one, among those listed for base, whose keynum the
|
||||||
|
signature names. Any other problem with the signature (missing,
|
||||||
|
malformed, other bytes, other key) is the one-line refusal above,
|
||||||
|
before the prompt; one refused package refuses the batch.
|
||||||
|
- repos.conf is read by gl_conf_repo_keys (pkg.c), strictly: `repos`
|
||||||
|
is the only setting; each entry has name, keys and optionally url,
|
||||||
|
nothing else; names and key names follow gl_valid_pkg_ident; a
|
||||||
|
duplicate name, or a url other than https://X or file://X, is
|
||||||
|
refused. Any of that: `[x] Malformed /etc/glacier/repos.conf.`
|
||||||
|
- repos.conf and each listed key, every ancestor of them and of their
|
||||||
|
real paths, must be root-owned and not group/world-writable:
|
||||||
|
`[x] Refusing F: P is not root-owned, or is group/world-writable.`
|
||||||
|
A listed key that is missing (`Cannot read F.`) or not a public key
|
||||||
|
(`Malformed F.`) stops the run: the admin's configuration is at
|
||||||
|
fault, not the package. Read only if some package is base.
|
||||||
|
- gbuild -k KEY.sec signs the sidecar (gsign from $GSIGN_BIN,
|
||||||
|
build/bin, or PATH), trying the key before building; a build
|
||||||
|
without -k removes a stale .sig. tests/mkpkg -k likewise.
|
||||||
|
- Test images (Dockerfile.*) carry a TEST key, glacier-test, listed for
|
||||||
|
base, its secret at /root/glacier-test.sec. tests/keyring_alpine.sh
|
||||||
|
covers this section (17 mutants, all caught).
|
||||||
|
- KEEP_OLD backups are re-packed from the store, so a base backup has
|
||||||
|
no signature: `syspkg -lO` refuses it until the restore interface
|
||||||
|
exists (decision 10f).
|
||||||
|
|
||||||
|
|
||||||
|
+--------------------------------------------+
|
||||||
|
| 8. Where the checks live |
|
||||||
|
+--------------------------------------------+
|
||||||
|
|
||||||
|
Signature verification is C (libglacier_verify.so). The POLICY (which
|
||||||
|
key for which repo, the base rule, rollback state) lives in the CLIs'
|
||||||
|
shared module, like hash verification today, so a third-party caller of
|
||||||
|
gl_install_pkg still isn't checked. ROADMAP 3.2 (move verification into
|
||||||
|
the library) now covers signatures too.
|
||||||
|
|
||||||
|
|
||||||
|
+--------------------------------------------+
|
||||||
|
| 9. Order of work |
|
||||||
|
+--------------------------------------------+
|
||||||
|
|
||||||
|
1. Vendored Ed25519 + signify formats in libglacier_verify.so; gsign;
|
||||||
|
tests including interop with signify (Alpine's `signify` package)
|
||||||
|
and hostile inputs (bad base64, wrong keynum, truncated files).
|
||||||
|
2. Keyring + repos.conf + the local base rule (section 7); gbuild -k;
|
||||||
|
glacier-bootstrap carries .sig; Everest gets a key.
|
||||||
|
3. Index: grepo; refresh, verify, rollback state. DONE 2026-10-06
|
||||||
|
(section 5, "As implemented"; syspkg/gpkg -y).
|
||||||
|
4. -f with closure; then -u. DONE 2026-10-07 (section 6, "As
|
||||||
|
implemented").
|
||||||
|
5. glacier-bootstrap -r against an index (pins stay optional extra
|
||||||
|
assurance).
|
||||||
|
6. User repos.
|
||||||
|
Each step is tested in Docker (file:// repos need no network) and
|
||||||
|
mutation-checked, as usual.
|
||||||
|
|
||||||
|
|
||||||
|
+--------------------------------------------+
|
||||||
|
| 10. Decisions on the details (2026-10-06) |
|
||||||
|
+--------------------------------------------+
|
||||||
|
|
||||||
|
a. Fetching on Everest: curl plus one TLS library in base. Signatures
|
||||||
|
make packages authentic regardless; TLS also hides WHAT is fetched
|
||||||
|
and stops a network attacker serving a stale (still valid) index.
|
||||||
|
STILL OPEN: which TLS library (BearSSL or LibreSSL); decide when
|
||||||
|
packaging it. Until then, everything is built and tested with
|
||||||
|
file:// repos and Alpine's curl.
|
||||||
|
b. No encrypted secret keys in gsign (no bcrypt_pbkdf). A
|
||||||
|
passphrase-protected key signs with signify itself.
|
||||||
|
c. VALID_UNTIL is REQUIRED; an expired index is refused. The
|
||||||
|
maintainer sets the lifetime; grepo defaults to 30 days.
|
||||||
|
d. Indexes are refreshed on every -f / -u. Offline, they refuse.
|
||||||
|
e. Everest's SECRET key lives outside the project tree:
|
||||||
|
~/.config/everest/keys/everest-2026.sec (EVEREST_KEYS), made by
|
||||||
|
`everest.sh keygen`, mounted read-only into the build container.
|
||||||
|
The public key ships in everest-bootscripts (/etc/glacier/keys).
|
||||||
|
f. Base backups (KEEP_OLD) are refused by `syspkg -lO` for want of a
|
||||||
|
signature; accepted for now. The restore interface (KEEP_OLD's
|
||||||
|
"later") can trust backups glacier made in its root-owned backup
|
||||||
|
dir.
|
||||||
+351
@@ -0,0 +1,351 @@
|
|||||||
|
+--------------------------------------------+
|
||||||
|
| Glacier roadmap |
|
||||||
|
+--------------------------------------------+
|
||||||
|
|
||||||
|
What's left to build, in priority order. Status as of 2026-10-07.
|
||||||
|
Design detail lives in the companion docs; this file says WHAT and in
|
||||||
|
what order, and links to WHERE:
|
||||||
|
|
||||||
|
SECURITY_DESIGN.txt integrity, scope separation, refusal matrix
|
||||||
|
PACKAGE_SCOPES.txt layout, link routing, /etc config handling
|
||||||
|
IMAGE_DESIGN.txt system images as bootstrap output, sysroot
|
||||||
|
REPO_DESIGN.txt remote repositories, signing, keyring
|
||||||
|
GLACIER_BOOTSTRAP.txt glacier-bootstrap plan, prerequisites, decisions
|
||||||
|
|
||||||
|
Mark an item [DONE yyyy-mm-dd] rather than deleting it, so the history
|
||||||
|
stays readable. CLAUDE.md "Known open items" tracks small bugs; this
|
||||||
|
file tracks work.
|
||||||
|
|
||||||
|
|
||||||
|
+--------------------------------------------+
|
||||||
|
| 1. Install Everest with glacier alone |
|
||||||
|
+--------------------------------------------+
|
||||||
|
|
||||||
|
The critical path: from "QEMU boots an initramfs assembled by a script"
|
||||||
|
(~/Projects/everest) to "glacier installs a system".
|
||||||
|
|
||||||
|
1.1 [DONE 2026-10-05: see CLAUDE.md "Install root / sysroot" and
|
||||||
|
tests/sysroot_alpine.sh.]
|
||||||
|
sysroot in the library (IMAGE_DESIGN section 3). Every path is
|
||||||
|
hardcoded to /glacier and /usr. Needs separate install-root
|
||||||
|
(where bytes are written) and runtime-root (what symlink targets
|
||||||
|
say). The trap: prune_stale_links follows absolute links, so a
|
||||||
|
naive prefix would judge the image's links against the HOST's
|
||||||
|
filesystem. Required test: an image build leaves the host's /usr
|
||||||
|
and /glacier byte-identical.
|
||||||
|
|
||||||
|
1.2 [DONE 2026-10-05: -R/--root, strict by default under -R, --strict.]
|
||||||
|
syspkg --root DIR (refuses unless DIR and its ancestors are
|
||||||
|
root-owned and not group/world-writable) and --strict (any link
|
||||||
|
refusal fails the transaction; an image's /usr starts empty).
|
||||||
|
gl_create_fs_tree already takes a root prefix.
|
||||||
|
|
||||||
|
1.3 [DONE 2026-10-06: glacier-ng/glacier-bootstrap, GLACIER_BOOTSTRAP
|
||||||
|
section 10; Everest's initramfs is built with it and boots.]
|
||||||
|
glacier-bootstrap, local mode (GLACIER_BOOTSTRAP.txt sections 1-6).
|
||||||
|
Template index -> resolve -> verify -> syspkg --root, one
|
||||||
|
transaction. Never writes into TARGET itself.
|
||||||
|
[DONE 2026-10-07: repositories. TARGET's repos.conf + keys come
|
||||||
|
from a package (Everest: everest-repos); bootstrap then runs
|
||||||
|
syspkg -R TARGET -y, which reads TARGET's own keyring; exit 7 on
|
||||||
|
a failed fetch. GLACIER_BOOTSTRAP section 10. Later, maybe: an
|
||||||
|
opt-in copy of the host's repos.conf (pacstrap's mirrorlist).]
|
||||||
|
|
||||||
|
1.4 [DONE 2026-10-06: built by ~/Projects/everest/scripts/container.sh,
|
||||||
|
in templates/minimal.template, boot-verified in QEMU; full
|
||||||
|
regression passes.]
|
||||||
|
Packages for glacier itself, so an installed system can manage
|
||||||
|
itself: luajit, libarchive (+ zlib), libconfig, libglacier-ng,
|
||||||
|
glacier-ng (syspkg, gpkg, gstore), doas.
|
||||||
|
Decided 2026-10-06:
|
||||||
|
- base: luajit, zlib, libarchive, libconfig, libglacier-ng,
|
||||||
|
glacier-ng. extra: doas (replaceable, e.g. by sudo).
|
||||||
|
- glacier-ng ships syspkg, gpkg and gstore only. glacier-bootstrap,
|
||||||
|
gbuild, gworld and gsha256sum become a later "glacier-tools"
|
||||||
|
package in extra (after the release, which brings a real
|
||||||
|
install Makefile).
|
||||||
|
- everest-bootscripts ships /etc/doas.conf: `permit :wheel`, plus
|
||||||
|
`permit nopass :wheel as root cmd /usr/bin/gstore args -n`.
|
||||||
|
- Layout: scripts + lib/ in usr/lib/glacier-ng/, usr/bin/{syspkg,
|
||||||
|
gpkg,gstore} symlink into it (realpath lands in the store, lib/
|
||||||
|
beside it); gpkg moves to the same real-path loading.
|
||||||
|
As built: zlib 1.3.2, libarchive 3.8.9 (gzip + tar only; every
|
||||||
|
other codec, crypto library and front-end disabled), libconfig
|
||||||
|
1.8.2 (no C++), luajit 2.1.1788856981 (commit c6ffc141),
|
||||||
|
libglacier-ng 4.0.0, glacier-ng 4.0.0, doas 6.8.2 (OpenDoas, no
|
||||||
|
PAM, no timestamp). The doas.conf rule is given for both `cmd
|
||||||
|
gstore` and `cmd /usr/bin/gstore`: OpenDoas matches what was typed.
|
||||||
|
luajit is linked -static-libgcc, since Everest ships no libgcc_s
|
||||||
|
(see section 6).
|
||||||
|
|
||||||
|
1.5 [DEFERRED 2026-10-06 by the user: manual installation is one of
|
||||||
|
Everest's main features, so the installer comes later. 3.1 is
|
||||||
|
next.]
|
||||||
|
[2026-10-07, the user: a manual install works from a live Everest
|
||||||
|
system or any Linux host; the live system is the preferred,
|
||||||
|
officially supported way. The user is trying the first disk
|
||||||
|
install (QEMU) themselves.]
|
||||||
|
The installer. Undesigned; needs its own design session
|
||||||
|
(SECURITY_DESIGN section 10). Partitioning, a bootloader or an
|
||||||
|
EFI-stub kernel on the ESP, copying the kernel there (a symlink
|
||||||
|
won't do on FAT), a disk image.
|
||||||
|
|
||||||
|
Already done on this path: hash verification, package symlinks, the
|
||||||
|
merged-/usr tree on syspkg -n, /etc config handling, a QEMU-bootable
|
||||||
|
musl + busybox + linux + everest-bootscripts set.
|
||||||
|
|
||||||
|
|
||||||
|
+--------------------------------------------+
|
||||||
|
| 2. Package-manager features |
|
||||||
|
+--------------------------------------------+
|
||||||
|
|
||||||
|
2.1 UPGRADES. Spec (2026-10-04):
|
||||||
|
- Replacing an installed version is `-lO` (local file) — plain
|
||||||
|
-l refuses ("extra::foo 1.0.0 is already installed.", nothing
|
||||||
|
more). [DONE 2026-10-04]
|
||||||
|
- The replaced version is BACKED UP: its files compressed into
|
||||||
|
<scope>/backup/<repo>/<name>/<name>-<ver>.gpkg + .sha256, a
|
||||||
|
complete installable package (saved manifest included).
|
||||||
|
KEEP_OLD in glacier.conf = how many backups to keep per
|
||||||
|
package (0 = none). No default: glacier.conf ships with
|
||||||
|
KEEP_OLD = 1, and an operation that would replace a version
|
||||||
|
refuses if it's missing or invalid. [DONE 2026-10-04]
|
||||||
|
- A restore interface for backups: later. (A backup can already
|
||||||
|
be reinstalled with -lO.)
|
||||||
|
- `gpkg -u` / `syspkg -u` = upgrade from a REMOTE repository;
|
||||||
|
waits for 3.1, like -f. [DONE 2026-10-07: REPO_DESIGN
|
||||||
|
section 6, "As implemented".]
|
||||||
|
- /etc follows the existing config rules regardless.
|
||||||
|
|
||||||
|
2.2 [DONE 2026-10-07: REPO_DESIGN section 6, "As implemented".]
|
||||||
|
gpkg -f / syspkg -f: MERGE. Spec (2026-10-04): exactly like -l,
|
||||||
|
except the package comes from a remote repository by name
|
||||||
|
instead of from a local file. Same summary, verification, scope
|
||||||
|
rules and transaction. Depends on 3.1 (remote repositories +
|
||||||
|
signing): until then there is nothing safe to fetch from.
|
||||||
|
|
||||||
|
2.3 Dependencies. [DONE 2026-10-05; automatic closure DONE
|
||||||
|
2026-10-07 with -f/-u (REPO_DESIGN section 6).] Spec (2026-10-05), all three checks in one pass, no override flag,
|
||||||
|
every problem reported (one line each) before failing:
|
||||||
|
- A dependency's PKG_VER is a MINIMUM (installed >= PKG_VER).
|
||||||
|
Matched by name, any repo.
|
||||||
|
- A user package's dependency may be met by system scope or the
|
||||||
|
user's own scope. syspkg -x checks system-scope dependents
|
||||||
|
only.
|
||||||
|
- Conflicts: both directions (new lists installed, or installed
|
||||||
|
lists new), by name; PKG_VER is ignored.
|
||||||
|
- Missing dependencies REFUSE until 3.1; then automatic closure
|
||||||
|
(GLACIER_BOOTSTRAP 9e).
|
||||||
|
- Index records auto vs explicit now: <ver>/.glacier-auto in the
|
||||||
|
store, index line repo::name::version::auto|explicit.
|
||||||
|
- Messages:
|
||||||
|
extra::foo requires bar >= 1.2.0, which is not installed.
|
||||||
|
Removing base::musl breaks extra::foo.
|
||||||
|
extra::foo conflicts with extra::bar.
|
||||||
|
- install: refuse if a dependency isn't installed (or in the
|
||||||
|
same transaction);
|
||||||
|
- REMOVE: refuse to remove a package others depend on. Today
|
||||||
|
nothing stops `syspkg -x musl` from breaking every binary on
|
||||||
|
the system. Highest-value item in this section;
|
||||||
|
- conflicts: refuse to install a package that conflicts with
|
||||||
|
an installed one.
|
||||||
|
9e DECIDED 2026-10-05: automatic closure, after 3.1 (see above).
|
||||||
|
|
||||||
|
2.4 Queries: list installed packages, show a package's details, find
|
||||||
|
which package owns a file. The index has the data; no CLI shows it.
|
||||||
|
|
||||||
|
2.5 Rollback. Every commit moves the previous state to old/ and then
|
||||||
|
deletes it. Keep it (or the last N), plus a command to return to
|
||||||
|
it. Interacts with 2.1's KEEP_OLD.
|
||||||
|
|
||||||
|
2.6 [DONE 2026-10-05: refused in every scope, before the prompt and at
|
||||||
|
commit (deps.c check_collisions).]
|
||||||
|
File conflicts between packages: two packages shipping the same
|
||||||
|
path — whichever links last silently wins. Detect and refuse.
|
||||||
|
|
||||||
|
2.7 glacier.conf parsing. [DONE 2026-10-04 for integers:
|
||||||
|
gl_conf_get_int, no defaults, missing/unreadable/wrong-type are
|
||||||
|
distinct errors.] Still open: rejecting UNKNOWN keys (CLAUDE.md bug
|
||||||
|
10's lesson — a misspelled KEEP_OLD currently reads as "not set",
|
||||||
|
which at least fails loudly).
|
||||||
|
|
||||||
|
2.8 gstore: -s (sync) is a stub; there's no restore command although
|
||||||
|
gstore -b's output tells you to run -r (gl_restore_istore exists).
|
||||||
|
|
||||||
|
2.9 User-scope config files: user packages still link etc/ into a
|
||||||
|
links tree that's rebuilt on every commit.
|
||||||
|
|
||||||
|
2.10 Hardlink entries in package archives are skipped at extraction.
|
||||||
|
|
||||||
|
|
||||||
|
+--------------------------------------------+
|
||||||
|
| 3. Security |
|
||||||
|
+--------------------------------------------+
|
||||||
|
|
||||||
|
3.1 Remote repositories + signing (authenticity, keyring). The agreed
|
||||||
|
next major item. Design: REPO_DESIGN.txt (2026-10-06; decisions in
|
||||||
|
sections 1 and 10, order of work section 9). [IN PROGRESS
|
||||||
|
2026-10-06: steps 1 and 2 DONE (gsign; the local base rule,
|
||||||
|
repos.conf + keyring, gbuild -k, bootstrap carries .sig, Everest
|
||||||
|
signs with everest-2026) and 3 (grepo; the signed index;
|
||||||
|
syspkg/gpkg -y refresh with rollback state) DONE; step 4 (-f with
|
||||||
|
closure, -u, the cache) DONE 2026-10-07; step 5 (glacier-
|
||||||
|
bootstrap -r) next, then 6 (user repos).] Unblocks remote
|
||||||
|
glacier-bootstrap. Until then, GLACIER_BOOTSTRAP's pinned
|
||||||
|
templates are the safe bridge for remote fetches.
|
||||||
|
|
||||||
|
3.2 Hash verification lives in the CLIs' shared module. A third-party
|
||||||
|
tool calling gl_install_pkg directly isn't verified. Consider
|
||||||
|
moving it into the library, like the base-in-user-scope refusal.
|
||||||
|
|
||||||
|
3.3 Manifests don't record the SYS_PROFILE they were built under, so a
|
||||||
|
package built for the wrong target can't be detected.
|
||||||
|
|
||||||
|
3.4 gstore -n accepts UIDs with no passwd entry (pre-provisions a
|
||||||
|
directory nobody owns yet; a typo creates a stray one).
|
||||||
|
|
||||||
|
|
||||||
|
+--------------------------------------------+
|
||||||
|
| 4. Build tooling |
|
||||||
|
+--------------------------------------------+
|
||||||
|
|
||||||
|
4.1 gbuild system profiles (-P ARCH-LIBC[-FEATURE...]) and gworld's
|
||||||
|
SYS_PROFILE recipe field. CLAUDE.md described both as done; neither
|
||||||
|
exists in the tree (only one gbuild, in glacier-ng). Today the
|
||||||
|
target libc is decided by where gbuild runs (~/Projects/everest
|
||||||
|
builds in Alpine for musl).
|
||||||
|
[2026-10-07, the user: Everest will run under glibc as well as
|
||||||
|
musl, so profiles are a real requirement, not a nicety. The
|
||||||
|
libc is picked at install time (Gentoo/Void style), one per
|
||||||
|
system. Open: how packages are kept apart (section 6).]
|
||||||
|
|
||||||
|
4.2 Move ~/Projects/everest's per-package gbuild commands into gworld
|
||||||
|
recipes once 4.1 lands.
|
||||||
|
|
||||||
|
|
||||||
|
+--------------------------------------------+
|
||||||
|
| 5. Performance (not urgent) |
|
||||||
|
+--------------------------------------------+
|
||||||
|
|
||||||
|
5.1 gl_relink_store / gl_rebuild_index rescan the whole store on every
|
||||||
|
commit. Fine at current scale; a dirty set is the fix.
|
||||||
|
|
||||||
|
|
||||||
|
+--------------------------------------------+
|
||||||
|
| 6. Decisions waiting |
|
||||||
|
+--------------------------------------------+
|
||||||
|
|
||||||
|
- Images are only ever bootstrap OUTPUT (IMAGE_DESIGN 9a /
|
||||||
|
GLACIER_BOOTSTRAP 9a).
|
||||||
|
- Where the pinning helper lives (GLACIER_BOOTSTRAP 9f).
|
||||||
|
- 2.1's open questions a-d (upgrade backups).
|
||||||
|
- extra vs community: should they ever behave differently?
|
||||||
|
- The installer (1.5), deferred.
|
||||||
|
- libgcc (1.4): luajit is built with -static-libgcc because Everest
|
||||||
|
has no libgcc_s. Claude's call, not yet reviewed; the alternative is
|
||||||
|
a GCC runtime package in base, which later C++/unwinding packages
|
||||||
|
would need anyway.
|
||||||
|
- glibc and musl (4.1): DECIDED 2026-10-07 that the user picks the
|
||||||
|
libc at install time, like Gentoo's profiles / Void's glibc and musl
|
||||||
|
ISOs; one libc per system. Still open: how packages are kept apart
|
||||||
|
(Claude recommends both per-libc repos, as Void, AND a libc field in
|
||||||
|
manifest + index that the library refuses on a mismatch with the
|
||||||
|
system's recorded libc).
|
||||||
|
|
||||||
|
|
||||||
|
+--------------------------------------------+
|
||||||
|
| 7. Done |
|
||||||
|
+--------------------------------------------+
|
||||||
|
|
||||||
|
[DONE 2026-10-07] -f and -u from repositories (3.1 step 4; 2.1's -u,
|
||||||
|
2.2, 2.3's closure): first repo serving a name wins; missing deps
|
||||||
|
added auto, too-old ones upgraded; downloads in <base>/cache/REPO,
|
||||||
|
hashed against the signed index, manifest must match the entry,
|
||||||
|
deleted after commit. tests/fetch_alpine.sh (84 checks, 17 mutants).
|
||||||
|
|
||||||
|
[DONE 2026-10-06] Packages for glacier itself (1.4): zlib, libarchive,
|
||||||
|
libconfig, luajit, libglacier-ng, glacier-ng in base, doas in extra;
|
||||||
|
everest-bootscripts 1.1.0 ships /etc/doas.conf. Everest's initramfs
|
||||||
|
installs all 11 packages; in QEMU, syspkg/gpkg run from the store,
|
||||||
|
syspkg -x musl is refused (dependents), a wheel user runs doas
|
||||||
|
gstore -n without a password, then gpkg -l. gpkg loads lib/ from its
|
||||||
|
realpath. tests/installed_alpine.sh (30 checks) installs glacier in
|
||||||
|
that layout and runs it from the store. Found on the way: gbuild's
|
||||||
|
clone warning broke builds from a commit hash (CLAUDE.md bug 28);
|
||||||
|
syspkg/gstore never checked the ancestors of libglacier-ng's store
|
||||||
|
dir, which the installed .so's live in (bug 29; both mutations
|
||||||
|
caught).
|
||||||
|
[DONE 2026-10-07] glacier-bootstrap configures repositories (1.3):
|
||||||
|
syspkg -R's -y/-f/-u use TARGET's own repos.conf and keys (each
|
||||||
|
file's real path must stay inside TARGET); bootstrap runs
|
||||||
|
syspkg -R T -y when T's repos.conf gives a url (exit 7 on failure,
|
||||||
|
a warning when none does). Everest: new base package everest-repos
|
||||||
|
1.0.0 (/etc/glacier/repos.conf + everest-2026.pub), moved out of
|
||||||
|
everest-bootscripts (now 1.3.0). bootstrap_alpine.sh 100 checks
|
||||||
|
(6 mutants, all caught); repo/fetch suites updated; full regression
|
||||||
|
green; Everest rebuilt and booted.
|
||||||
|
[DONE 2026-10-06] glacier-bootstrap, local mode (1.3): template
|
||||||
|
(NAME=, PKG=name ver [sha256:pin]; strict), verified private copies
|
||||||
|
handed to syspkg -R in one transaction, template-level dependency /
|
||||||
|
conflict / name checks, -n, -t. tests/bootstrap_alpine.sh (77
|
||||||
|
checks, 11 mutations caught). ~/Projects/everest's initramfs is now
|
||||||
|
a glacier-installed system (templates/minimal.template), booted in
|
||||||
|
QEMU: /glacier/sys, merged-/usr links into the store, /etc copied,
|
||||||
|
a non-root user runs busybox.
|
||||||
|
|
||||||
|
[DONE 2026-10-05] syspkg -R/--root DIR + --strict (1.2) and file
|
||||||
|
collisions (2.6): gl_check_sysroot (root-owned, non-symlink, not
|
||||||
|
group/world-writable, every ancestor), ctx->strict (a would-be link
|
||||||
|
refusal fails the transaction before the prompt and at commit; -O
|
||||||
|
still displaces), two packages shipping one path refused in every
|
||||||
|
scope. tests/root_alpine.sh (50 checks, 7 mutations caught). gpkg
|
||||||
|
silently ignored unknown flags (CLAUDE.md bug 27).
|
||||||
|
[DONE 2026-10-05] sysroot in the library (1.1): *_at contexts and
|
||||||
|
gl_init_sys_at, install paths in the context with runtime translation
|
||||||
|
at link/prune/displace, /usr and /etc under the sysroot, user scope
|
||||||
|
refuses one. tests/sysroot_alpine.sh (33 checks, 8 mutations caught).
|
||||||
|
Found on the way: live-context removal deleted foreign files
|
||||||
|
(CLAUDE.md bug 26).
|
||||||
|
[DONE 2026-10-05] Dependencies and conflicts (2.3): src/deps.c
|
||||||
|
(gl_check_plan before the prompt; gl_check_txn enforced by
|
||||||
|
gl_commit_transaction; live-context installs/removals checked inside
|
||||||
|
gl_install_pkg/gl_remove_pkg), index field 4 auto|explicit +
|
||||||
|
.glacier-auto + gl_set_pkg_auto, gl_read_pkg_manifest split out of
|
||||||
|
gl_install_pkg. tests/deps_alpine.sh (41 checks, 8 mutations caught).
|
||||||
|
Found on the way: the live index was rewritten through a seeded
|
||||||
|
hardlink (CLAUDE.md bug 25), tests/test_index_abort.lua.
|
||||||
|
[DONE 2026-10-05] System scope world-readable (found while specifying
|
||||||
|
2.3): /glacier/sys was root 0700 throughout, so non-root users could
|
||||||
|
run nothing syspkg installed. Dirs 0755 / index 0644, and created
|
||||||
|
modes no longer depend on the umask. tests/sys_perms_alpine.sh.
|
||||||
|
|
||||||
|
[DONE 2026-10-04] Version replacement + backups (2.1): -lO replaces,
|
||||||
|
KEEP_OLD backups, gl_backup_pkg / gl_prune_backups / gl_conf_get_int,
|
||||||
|
the manifest saved in the store (.glacier-manifest), add_to_archive
|
||||||
|
learns symlinks (gstore -b silently dropped them too), gpkg modifier
|
||||||
|
flags (-O -S -V) order-independent so `gpkg -lO` works.
|
||||||
|
tests/upgrade_alpine.sh (29 checks).
|
||||||
|
[DONE 2026-10-04] Correctness batch:
|
||||||
|
- gbuild: autotools detected before a bare Makefile (bug 8 had
|
||||||
|
regressed); --cross-prefix fixed (its option-table key was
|
||||||
|
misspelled); -v/--version print the version as documented, with
|
||||||
|
--verbose for verbose output.
|
||||||
|
- gpkg -x: summary resolved from the index (was "unknown::pkg
|
||||||
|
0.0.0"); a package that isn't installed fails before the prompt.
|
||||||
|
- gpkg: precise refusal for a missing / squatted / loosened user
|
||||||
|
directory (was "No index found"), via gl_usr_base_status.
|
||||||
|
- gpkg -h lists -l and -S; -f/-u described by the 2.1/2.2 specs.
|
||||||
|
- Up-to-date reinstall logs once.
|
||||||
|
- Link conflicts reported once, by the package that has them, not
|
||||||
|
again on every later system commit (.glacier-fresh marker).
|
||||||
|
- A failed extraction no longer leaves a half-extracted version dir
|
||||||
|
(in a live context, every retry then said "already installed").
|
||||||
|
- Dead old-layout code removed from pkg.c (gl_prepare_pkgdir and the
|
||||||
|
gl_usr_* / gl_sys_* dir_t constants).
|
||||||
|
- tests/glacier_ffi.lua is a wrapper over lib/glacier_cdef.lua; its
|
||||||
|
own copy had already drifted (missing GL_INSTALL_ERR_SCOPE).
|
||||||
|
- Dockerfile.arch / .debian moved to the per-uid layout (root-owned
|
||||||
|
/app, libglacier-ng built from source, the gstore -n doas rule).
|
||||||
|
[DONE 2026-10-04] Hash verification; package symlinks; per-uid user
|
||||||
|
layout + doas gstore -n; syspkg -n top-level tree; /etc config
|
||||||
|
handling (copy + .new); -O/--overwrite; everest-bootscripts.
|
||||||
@@ -27,6 +27,9 @@ it. This phase is INTEGRITY ONLY. Authenticity (signing, a trusted
|
|||||||
keyring) is a deliberate future phase, tied to remote-repo support —
|
keyring) is a deliberate future phase, tied to remote-repo support —
|
||||||
not being designed in detail now, but a few choices below are made to
|
not being designed in detail now, but a few choices below are made to
|
||||||
stay cheap to extend into later.
|
stay cheap to extend into later.
|
||||||
|
[2026-10-06: that phase is REPO_DESIGN.txt. Its first part is in: a
|
||||||
|
base package installed with syspkg -l needs a signed sidecar
|
||||||
|
(REPO_DESIGN section 7).]
|
||||||
|
|
||||||
Everest is a security-focused distro (this is also *why* per-user
|
Everest is a security-focused distro (this is also *why* per-user
|
||||||
package isolation exists in the first place). Two sides of the CIA
|
package isolation exists in the first place). Two sides of the CIA
|
||||||
@@ -179,6 +182,14 @@ is being preserved exactly as-is — gstore stays permanently
|
|||||||
user-scope-only; the fix is removing -N, not touching the bounds
|
user-scope-only; the fix is removing -N, not touching the bounds
|
||||||
check.
|
check.
|
||||||
|
|
||||||
|
LATER AMENDMENT: `gstore -n` does run as root — it creates
|
||||||
|
/glacier/usr/<uid> inside a root-owned parent (PACKAGE_SCOPES.txt
|
||||||
|
section 1). Still user scope only. Root runs it with an explicit UID; a
|
||||||
|
user runs it for themselves through a doas rule pinned to exactly
|
||||||
|
`-n`, which is what stops them naming another UID (same boundary as
|
||||||
|
section 6). Being root-run, gstore follows syspkg's loading rules
|
||||||
|
(pinned paths, -E, root-ownership checks).
|
||||||
|
|
||||||
|
|
||||||
+--------------------------------------------+
|
+--------------------------------------------+
|
||||||
| 6. syspkg privilege model |
|
| 6. syspkg privilege model |
|
||||||
@@ -201,6 +212,17 @@ refusing otherwise. The actual privilege boundary is enforced by doas
|
|||||||
— a hardened, audited, purpose-built tool for exactly this — not
|
— a hardened, audited, purpose-built tool for exactly this — not
|
||||||
reimplemented inside syspkg itself.
|
reimplemented inside syspkg itself.
|
||||||
|
|
||||||
|
LATER AMENDMENT (loading, as built): syspkg and gstore run under
|
||||||
|
`luajit -E`, and pin package.path and every ffi.load to their own
|
||||||
|
realpath's lib/. Before loading anything as root, each file they load
|
||||||
|
(every .lua, every .so, including those pulled in through $ORIGIN) and
|
||||||
|
lib/ itself must be root-owned and not group/world-writable, and so
|
||||||
|
must every ancestor of the script's realpath AND of each loaded file's
|
||||||
|
realpath. The second set matters once installed: lib/glacier is a
|
||||||
|
symlink to /usr/lib/glacier, whose entries link into libglacier-ng's
|
||||||
|
store directory, a tree the script's own ancestors never reach
|
||||||
|
(2026-10-06, CLAUDE.md bug 29).
|
||||||
|
|
||||||
|
|
||||||
+--------------------------------------------+
|
+--------------------------------------------+
|
||||||
| 7. Shared code: gpkg_common.lua |
|
| 7. Shared code: gpkg_common.lua |
|
||||||
|
|||||||
@@ -27,6 +27,12 @@ root, or shadows real `/usr` binaries."
|
|||||||
* **Severity:** High
|
* **Severity:** High
|
||||||
* **Category:** `authorization-bypass`
|
* **Category:** `authorization-bypass`
|
||||||
* **Confidence:** High
|
* **Confidence:** High
|
||||||
|
* **Status (2026-10-06):** closed for local installs by recommendation
|
||||||
|
(b): `syspkg -l` of a package whose manifest says base requires its
|
||||||
|
sidecar signed by a key `/etc/glacier/repos.conf` lists for base
|
||||||
|
(REPO_DESIGN.txt section 7); user scope refuses base outright. Remote
|
||||||
|
packages get (a) with the signed index (REPO_DESIGN section 4). Still
|
||||||
|
open for a third-party caller of `gl_install_pkg` (ROADMAP 3.2).
|
||||||
|
|
||||||
**Description:** System-scope symlink placement into `/usr` is gated only
|
**Description:** System-scope symlink placement into `/usr` is gated only
|
||||||
by a package's manifest self-declaring `PKG_REPO="base"`. There is no
|
by a package's manifest self-declaring `PKG_REPO="base"`. There is no
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
# Security review, 2026-10-06
|
||||||
|
|
||||||
|
Scope: every active source file in libglacier-ng (`src/*.c`, `src/*.h`,
|
||||||
|
not the vendored Monocypher, not the unbuilt early prototypes) and
|
||||||
|
glacier-ng (`gpkg`, `syspkg`, `gstore`, `glacier-bootstrap`, `gbuild`,
|
||||||
|
`gworld`, `lib/*.lua`, `tests/mkpkg`, the Dockerfiles). Read line by line;
|
||||||
|
findings confirmed by running them in Docker where possible; each fix
|
||||||
|
has a regression test, mutation-checked unless noted.
|
||||||
|
|
||||||
|
Tests: `glacier-ng/tests/audit_alpine.sh` (shell, `glacier-alpine_root`)
|
||||||
|
and `glacier-ng/tests/test_abort_unlocked.lua` (FFI suite).
|
||||||
|
|
||||||
|
## Findings and fixes
|
||||||
|
|
||||||
|
| # | Severity | Where | Finding | Fix | Test |
|
||||||
|
|---|---|---|---|---|---|
|
||||||
|
| 1 | **High** | `gl_install_pkg` | A package could ship top-level `files/.glacier-*` entries, glacier's own store files. As a symlink, `.glacier-fresh` made syspkg `open(O_CREAT\|O_TRUNC)` its target as root: an unsigned extra package truncated `/root/victim` to 0 bytes (reproduced). `.glacier-overwrite` granted the package `-O` without the user asking; `.glacier-manifest` rewrote its saved manifest. | Top-level names starting `.glacier-` are refused (`GL_MARKER_PREFIX`, common.h); the marker writes use `O_NOFOLLOW`. | audit_alpine: reserved names (mutants c3, c4 caught) |
|
||||||
|
| 2 | Medium | `gl_rmdir_recursive` (common.h) | `lstat` then `opendir` by path: root deleting a tree a user can write to (`gstore -x UID`) could be steered, by swapping a directory for a symlink between the two calls, into emptying the symlink's target. | fd-relative walk: `openat(O_DIRECTORY\|O_NOFOLLOW)`, `fdopendir`, `unlinkat`; the top path must not be a symlink. | audit_alpine: `gstore -x` race, 40 runs (mutant c1 caught 34-38/40) |
|
||||||
|
| 3 | Medium | `add_to_archive` (istoreutils.c) | Same class: `lstat` then `open`/`opendir` by path, no `O_NOFOLLOW`. Root backing up a user's store (`gstore -b`) could be steered into archiving root-only files. | fd-relative (`fstatat`/`openat(O_NOFOLLOW\|O_NONBLOCK)`/`readlinkat`); the opened descriptor's type is what gets archived. | **No failing-on-old test**: the window is too narrow for a shell race to hit (mutant c2 survived). Verified by review only. |
|
||||||
|
| 4 | Medium | `gl_gpm2gpkg` (pkg.c) | Manifests come from untrusted archives; libconfig honours `@include "FILE"`, so a manifest could make syspkg read any file as root. | A manifest with a line starting `@include` is refused (read into memory first, 1 MiB cap, no NUL). | audit_alpine (mutant c5 caught) |
|
||||||
|
| 5 | Low | `gl_gpm2gpkg` | A dependency/conflict entry without `PKG_NAME` ended the list early (later entries silently ignored, and leaked); names were not checked. | Every entry needs a `gl_valid_pkg_ident` name, else the manifest is refused. | audit_alpine (mutants c6, c7 caught) |
|
||||||
|
| 6 | Low | `gpkg_common.lua` | `read_manifest_fields` pattern-matched the manifest (via `tar` as root) and could disagree with the library: a decoy `// PKG_REPO = "community";` line hid that a package replaced an installed one, skipping the `-O` rule and the KEEP_OLD backup (two versions in the store). The tar extraction itself was not exploitable (GNU and busybox tar strip `..`; checked). | Replaced by `manifest_of`, a wrapper around `gl_read_pkg_manifest`; an unreadable manifest is refused before the prompt. | audit_alpine (old file as mutant l1, caught) |
|
||||||
|
| 7 | Low | `gstore`, `gpkg` | Text concatenated into `lg_printf` format strings: gstore's `argv[0]` and UID (as root), gpkg `-u`'s operand. | Passed as `%s` arguments; the `-u`/`-f`/`-s` stubs now refuse in one line. | audit_alpine (mutants l2, l3 caught) |
|
||||||
|
| 8 | Low | `gstore` | A UID above uid_t's range wrapped around in C to another UID. | Refused (`0..4294967294`). | audit_alpine (mutant l4 caught) |
|
||||||
|
| 9 | Low | `gl_abort_transaction` | Wiped the stage even for a context that never got the lock, i.e. another process's running transaction. | Only the lock holder's abort removes the stage (`GL_TXN_ERR_NO_TXN` otherwise). | test_abort_unlocked.lua (mutant f8 caught) |
|
||||||
|
| 10 | Low | `gpkg_common.lua` | Lua numbers passed to `lg_printf("%d")` (a double into varargs: undefined behaviour). | `%s` + `tostring`. | none (not observable) |
|
||||||
|
| 11 | Low | `gl_parse_semver` | `sscanf("%d")` on an untrusted, oversized number is undefined behaviour. | `strtol`, clamped to `0..INT_MAX`. | none (not observable) |
|
||||||
|
| 12 | Hardening | `is_glacier_symlink` | A plain prefix match: `/glacier/sys/store` also matched `/glacier/sys/store2/...` (only root can create such paths). | The prefix must be followed by `/` or end the target. | none |
|
||||||
|
| 13 | Bug | `join_with_cwd` (pkg.c) | `strlen(cwd + strlen(path) + 2)`: an out-of-bounds read. Unused. | Removed (see below). | n/a |
|
||||||
|
| 14 | Hardening | `lg_printf` | No format checking for C callers. | `__attribute__((format(printf, 2, 3)))`; the build is clean under `-Wformat=2 -Werror`. | the build |
|
||||||
|
|
||||||
|
Reviewed and found sound: signature code (`sign.c`: strict signify
|
||||||
|
parsing, secrets wiped, `O_NOFOLLOW|O_EXCL` writes), the index parser,
|
||||||
|
extraction's tar-slip defences (`is_safe_rel_path`, deferred symlinks,
|
||||||
|
`crosses_symlink`, `O_NOFOLLOW`), the sysroot trust check, syspkg's and
|
||||||
|
gstore's hardened loading, the private-copy verification, shell quoting
|
||||||
|
in every `os.execute`/`io.popen`, `/etc` config handling, `-O` displace
|
||||||
|
and restore.
|
||||||
|
|
||||||
|
## Removed as unused or redundant
|
||||||
|
|
||||||
|
- libglacier-ng: the `dag`, `runtime` and `make_conf` modules (nothing
|
||||||
|
linked them); `gl_pkgver`, `gl_mkdir`, `gl_spawn_pkg`, `gl_cat_dir`,
|
||||||
|
`gl_cat_dir_and_ver`, `gl_return_dir`, `gl_return_dir_and_ver`,
|
||||||
|
`gl_free_path`, `gl_free_dir`, `gl_show_pkg_props`, `join_with_cwd`,
|
||||||
|
`empty`/`null_dep`/`null_conf`, `dir_t`; `gl_parse_index`,
|
||||||
|
`gl_free_index` (and `struct gindex`), `gl_find_pkg_repo` (duplicate of
|
||||||
|
`gl_find_pkg_repos`), `gl_sys_istore_exists`, `gl_restore_istore`
|
||||||
|
(also unsafe: followed symlinks when restoring); `lg_printf_no_newline`,
|
||||||
|
`lg_syslog`, `lg_log` (its declaration and definition disagreed),
|
||||||
|
`p2s`; `GL_CONF_PATH`; the broken `install_test_dir` Makefile target.
|
||||||
|
The marker names, defined twice (deps.c, istoreutils.c), now live once
|
||||||
|
in common.h; log.c includes log.h instead of redefining its enum.
|
||||||
|
- glacier-ng: `M.read_manifest_fields`, `M.extract_pkg_info`,
|
||||||
|
`M.summary`; `install_with_reinstall` is module-local; the matching
|
||||||
|
`glacier_cdef.lua` declarations.
|
||||||
|
|
||||||
|
## Open
|
||||||
|
|
||||||
|
- Finding 3 has no test that fails on the old code (see the table).
|
||||||
|
- Extracted entries keep setuid/setgid bits (known gap, unchanged).
|
||||||
|
- No size limits on extraction (a decompression bomb fills the disk).
|
||||||
Binary file not shown.
@@ -1,41 +0,0 @@
|
|||||||
#ifndef LOG_H_
|
|
||||||
#define LOG_H_
|
|
||||||
|
|
||||||
#define _POSIX_C_SOURCE 200809L
|
|
||||||
#define _DEFAULT_SOURCE
|
|
||||||
#define _XOPEN_SOURCE 700
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <syslog.h>
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
#include "color.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
LG_INFO,
|
|
||||||
LG_WARN,
|
|
||||||
LG_ERR,
|
|
||||||
LG_SUCCESS
|
|
||||||
}
|
|
||||||
loglevel_t;
|
|
||||||
|
|
||||||
int supports_utf8(void);
|
|
||||||
const char *p2s(int priority);
|
|
||||||
|
|
||||||
void lg_printf(loglevel_t loglevel, const char *fmt, ...);
|
|
||||||
void lg_printf_no_newline(loglevel_t loglevel, const char *fmt, ...);
|
|
||||||
void lg_syslog(int priority, const char *fmt, ...);
|
|
||||||
void lg_log(bool use_syslog, FILE *logfile, int priority, const char *fmt, ...);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* LOG_H_ */
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -6,4 +6,3 @@ PREFIX ?= /usr
|
|||||||
|
|
||||||
CFLAGS = -std=c11 -pedantic -O2 -Wall -Wextra -Wshadow -Wformat=2 -Wconversion -Wpedantic -Werror -Wno-format-truncation
|
CFLAGS = -std=c11 -pedantic -O2 -Wall -Wextra -Wshadow -Wformat=2 -Wconversion -Wpedantic -Werror -Wno-format-truncation
|
||||||
|
|
||||||
TEST_DIR = /home/lw/Projects/glacier-ng/lib
|
|
||||||
+204
-33
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include <linux/limits.h>
|
#include <linux/limits.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -13,12 +14,170 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
typedef struct
|
/*
|
||||||
|
* On-disk layout. Each scope keeps everything it ever creates, renames
|
||||||
|
* or locks under ONE base directory it owns:
|
||||||
|
*
|
||||||
|
* /glacier/usr/<uid>/{index,store,links,stage,old,lock} owned by uid, 0700
|
||||||
|
* /glacier/sys/{index,store,links,stage,old,lock} root
|
||||||
|
*
|
||||||
|
* /glacier/usr itself is root-owned and not group/world-writable, so a
|
||||||
|
* user can never create (or squat) another uid's base; root creates
|
||||||
|
* each one (gl_init_user, via `gstore -n` directly or through doas).
|
||||||
|
* Every transaction step — stage, old/, lock, the commit renames — then
|
||||||
|
* happens inside a directory the acting user owns, which is what lets
|
||||||
|
* an unprivileged user run their own transactions at all.
|
||||||
|
*/
|
||||||
|
#define GL_USR_ROOT "/glacier/usr"
|
||||||
|
|
||||||
|
/* In a package's version dir: "installed as a dependency, not by name".
|
||||||
|
* Dot-prefixed like the other store markers, so seeding carries it and
|
||||||
|
* linking skips it; the index's 4th field is derived from it. */
|
||||||
|
#define GL_AUTO_MARKER ".glacier-auto"
|
||||||
|
/* The other files glacier keeps in a version dir (see gl_install_pkg):
|
||||||
|
* the package's saved manifest, and the one-shot markers for the next
|
||||||
|
* link pass (this transaction installed it; it may displace, -O). A
|
||||||
|
* package may not ship any top-level name starting with GL_MARKER_PREFIX:
|
||||||
|
* these are glacier's, and one shipped as a symlink would redirect
|
||||||
|
* glacier's own writes. */
|
||||||
|
#define GL_MARKER_PREFIX ".glacier-"
|
||||||
|
#define GL_MANIFEST_COPY ".glacier-manifest"
|
||||||
|
#define GL_FRESH_MARKER ".glacier-fresh"
|
||||||
|
#define GL_OVERWRITE_MARKER ".glacier-overwrite"
|
||||||
|
#define GL_SYS_ROOT "/glacier/sys"
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
gl_usr_base(uid_t uid, char *out, size_t outsz)
|
||||||
{
|
{
|
||||||
const char *path;
|
snprintf(out, outsz, GL_USR_ROOT "/%u", (unsigned)uid);
|
||||||
mode_t mode;
|
}
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
GL_USR_BASE_OK = 0,
|
||||||
|
GL_USR_BASE_MISSING, /* no /glacier/usr/<uid> yet: run gstore -n */
|
||||||
|
GL_USR_BASE_UNSAFE_ROOT, /* /glacier/usr not root-owned, or group/world-writable */
|
||||||
|
GL_USR_BASE_UNSAFE /* not a real dir, not owned by uid, or not 0700-ish */
|
||||||
|
} gl_usr_base_status_t;
|
||||||
|
|
||||||
|
/* Refuse to operate on a user base we didn't hand out. lstat(), never
|
||||||
|
* stat(): a symlink in place of /glacier/usr/<uid> is exactly what a
|
||||||
|
* squatter would plant. Backstop for the layout invariant above, so a
|
||||||
|
* hand-loosened /glacier/usr can't silently turn into one user writing
|
||||||
|
* another's store. */
|
||||||
|
static inline gl_usr_base_status_t
|
||||||
|
gl_usr_base_check(uid_t uid)
|
||||||
|
{
|
||||||
|
struct stat st;
|
||||||
|
|
||||||
|
if (lstat(GL_USR_ROOT, &st) != 0) { return GL_USR_BASE_MISSING; }
|
||||||
|
if (!S_ISDIR(st.st_mode) || st.st_uid != 0 ||
|
||||||
|
(st.st_mode & (S_IWGRP | S_IWOTH)) != 0) {
|
||||||
|
return GL_USR_BASE_UNSAFE_ROOT;
|
||||||
|
}
|
||||||
|
|
||||||
|
char base[PATH_MAX];
|
||||||
|
gl_usr_base(uid, base, sizeof(base));
|
||||||
|
|
||||||
|
if (lstat(base, &st) != 0) { return GL_USR_BASE_MISSING; }
|
||||||
|
if (!S_ISDIR(st.st_mode) || st.st_uid != uid ||
|
||||||
|
(st.st_mode & (S_IRWXG | S_IRWXO)) != 0) {
|
||||||
|
return GL_USR_BASE_UNSAFE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return GL_USR_BASE_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* An install root (gl_context_t.sysroot) in canonical form: NULL, "" and
|
||||||
|
* "/" mean the running system and give ""; anything else must be an
|
||||||
|
* absolute path with no "." or ".." components, and loses its trailing
|
||||||
|
* slashes. Room is left for the paths built under it. Returns -1 if
|
||||||
|
* it's refused. */
|
||||||
|
static inline int
|
||||||
|
gl_normalize_sysroot(const char *in, char *out, size_t outsz)
|
||||||
|
{
|
||||||
|
out[0] = '\0';
|
||||||
|
if (!in || in[0] == '\0') { return 0; }
|
||||||
|
if (in[0] != '/') { return -1; }
|
||||||
|
|
||||||
|
size_t len = strlen(in);
|
||||||
|
while (len > 0 && in[len - 1] == '/') { len--; }
|
||||||
|
if (len == 0) { return 0; } /* "/" or "//" */
|
||||||
|
if (len + 256 > outsz || len + 256 > PATH_MAX) { return -1; }
|
||||||
|
|
||||||
|
for (size_t i = 0; i < len; ) {
|
||||||
|
size_t j = i + 1; /* in[i] == '/' */
|
||||||
|
while (j < len && in[j] != '/') { j++; }
|
||||||
|
size_t clen = j - i - 1;
|
||||||
|
const char *comp = in + i + 1;
|
||||||
|
if (clen == 0 || (clen == 1 && comp[0] == '.') ||
|
||||||
|
(clen == 2 && comp[0] == '.' && comp[1] == '.')) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
i = j;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(out, in, len);
|
||||||
|
out[len] = '\0';
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Is a (normalized, non-empty) install root safe for root to write into?
|
||||||
|
* It and every directory above it must be a real directory (not a
|
||||||
|
* symlink), owned by root, and not group/world-writable: otherwise a
|
||||||
|
* user could swap part of the tree for a symlink to the host's /usr
|
||||||
|
* between two syscalls (IMAGE_DESIGN section 4). Returns 0 if trusted;
|
||||||
|
* otherwise -1, with the offending path in `bad` and `why` set to
|
||||||
|
* "a symlink", "not a directory", or "not root-owned, or is
|
||||||
|
* group/world-writable". */
|
||||||
|
static inline int
|
||||||
|
gl_sysroot_check_one(const char *path, char *bad, size_t badsz, const char **why)
|
||||||
|
{
|
||||||
|
struct stat st;
|
||||||
|
if (lstat(path, &st) != 0) {
|
||||||
|
*why = "missing";
|
||||||
|
} else if (S_ISLNK(st.st_mode)) {
|
||||||
|
*why = "a symlink";
|
||||||
|
} else if (!S_ISDIR(st.st_mode)) {
|
||||||
|
*why = "not a directory";
|
||||||
|
} else if (st.st_uid != 0 || (st.st_mode & 022) != 0) {
|
||||||
|
*why = "not root-owned, or is group/world-writable";
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
snprintf(bad, badsz, "%s", path);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int
|
||||||
|
gl_sysroot_trusted(const char *root, char *bad, size_t badsz, const char **why)
|
||||||
|
{
|
||||||
|
if (gl_sysroot_check_one("/", bad, badsz, why) != 0) { return -1; }
|
||||||
|
|
||||||
|
char prefix[PATH_MAX];
|
||||||
|
snprintf(prefix, sizeof(prefix), "%s", root);
|
||||||
|
/* each ancestor, shortest first, then root itself */
|
||||||
|
for (char *p = prefix + 1; *p; p++) {
|
||||||
|
if (*p != '/') { continue; }
|
||||||
|
*p = '\0';
|
||||||
|
int rc = gl_sysroot_check_one(prefix, bad, badsz, why);
|
||||||
|
*p = '/';
|
||||||
|
if (rc != 0) { return -1; }
|
||||||
|
}
|
||||||
|
return gl_sysroot_check_one(prefix, bad, badsz, why);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* mkdir -p. Every directory this creates gets exactly `mode`, whatever
|
||||||
|
* the caller's umask: a system store made under umask 077 would otherwise
|
||||||
|
* be unreachable for every user but root. Directories that already exist
|
||||||
|
* are left alone. */
|
||||||
|
static inline int
|
||||||
|
gl_mkdir_exact(const char *path, mode_t mode)
|
||||||
|
{
|
||||||
|
if (mkdir(path, mode) == 0) {
|
||||||
|
return chmod(path, mode);
|
||||||
|
}
|
||||||
|
return errno == EEXIST ? 0 : -1;
|
||||||
}
|
}
|
||||||
dir_t;
|
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
gl_mkdirp(const char *path, mode_t mode)
|
gl_mkdirp(const char *path, mode_t mode)
|
||||||
@@ -30,46 +189,58 @@ gl_mkdirp(const char *path, mode_t mode)
|
|||||||
for (char *p = tmp + 1; *p; p++) {
|
for (char *p = tmp + 1; *p; p++) {
|
||||||
if (*p == '/') {
|
if (*p == '/') {
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
if (mkdir(tmp, mode) == -1 && errno != EEXIST) {
|
if (gl_mkdir_exact(tmp, mode) != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
*p = '/';
|
*p = '/';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mkdir(tmp, mode) == -1 && errno != EEXIST) {
|
return gl_mkdir_exact(tmp, mode);
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Empties the directory open at `fd` (and closes it). Every step is
|
||||||
|
* relative to a descriptor opened with O_NOFOLLOW, so nothing is ever
|
||||||
|
* resolved through a symlink: an entry swapped for a symlink mid-walk
|
||||||
|
* (root deleting a tree a user can write to, gstore -x) is unlinked
|
||||||
|
* itself, never followed into its target. */
|
||||||
|
static inline void
|
||||||
|
gl_empty_dir_fd(int fd)
|
||||||
|
{
|
||||||
|
DIR *dir = fdopendir(fd);
|
||||||
|
if (!dir) {
|
||||||
|
close(fd);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct dirent *ent;
|
||||||
|
while ((ent = readdir(dir))) {
|
||||||
|
/* Only . and ..: dotfiles are content too (a package's own,
|
||||||
|
* the store's .displaced tree). */
|
||||||
|
if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
int sub = openat(dirfd(dir), ent->d_name,
|
||||||
|
O_RDONLY | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC);
|
||||||
|
if (sub >= 0) {
|
||||||
|
gl_empty_dir_fd(sub);
|
||||||
|
unlinkat(dirfd(dir), ent->d_name, AT_REMOVEDIR);
|
||||||
|
} else {
|
||||||
|
unlinkat(dirfd(dir), ent->d_name, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir(dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* rm -r of a directory. `path` itself must be a directory, not a
|
||||||
|
* symlink to one (refused, -1). */
|
||||||
static inline int
|
static inline int
|
||||||
gl_rmdir_recursive(const char *path)
|
gl_rmdir_recursive(const char *path)
|
||||||
{
|
{
|
||||||
DIR *dir = opendir(path);
|
int fd = open(path, O_RDONLY | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC);
|
||||||
if (!dir) { return -1; }
|
if (fd < 0) { return -1; }
|
||||||
|
gl_empty_dir_fd(fd);
|
||||||
struct dirent *ent;
|
return rmdir(path);
|
||||||
while ((ent = readdir(dir))) {
|
|
||||||
if (ent->d_name[0] == '.') { continue; }
|
|
||||||
|
|
||||||
char full[PATH_MAX];
|
|
||||||
snprintf(full, sizeof(full), "%s/%s", path, ent->d_name);
|
|
||||||
|
|
||||||
struct stat st;
|
|
||||||
if (lstat(full, &st) != 0) { continue; }
|
|
||||||
|
|
||||||
if (S_ISDIR(st.st_mode)) {
|
|
||||||
gl_rmdir_recursive(full);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
unlink(full);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
closedir(dir);
|
|
||||||
return rmdir(path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,132 +0,0 @@
|
|||||||
#define _POSIX_C_SOURCE 200809L
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "dag.h"
|
|
||||||
|
|
||||||
graph_t
|
|
||||||
*gl_graph_create(void)
|
|
||||||
{
|
|
||||||
return calloc(1, sizeof(graph_t));
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
gl_graph_free(graph_t *g)
|
|
||||||
{
|
|
||||||
if (!g) { return; }
|
|
||||||
|
|
||||||
for (size_t i = 0; i < g->node_count; i++) {
|
|
||||||
free(g->nodes[i]->edges);
|
|
||||||
free(g->nodes[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(g->nodes);
|
|
||||||
free(g);
|
|
||||||
}
|
|
||||||
|
|
||||||
graph_node_t
|
|
||||||
*gl_graph_add_node(graph_t *g, void *data)
|
|
||||||
{
|
|
||||||
if (!g) { return NULL; }
|
|
||||||
|
|
||||||
graph_node_t *n = calloc(1, sizeof(graph_node_t));
|
|
||||||
if (!n) { return NULL; }
|
|
||||||
n->data = data;
|
|
||||||
|
|
||||||
graph_node_t **tmp = realloc(g->nodes, sizeof(*g->nodes) * (g->node_count + 1));
|
|
||||||
if (!tmp) {
|
|
||||||
free(n);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
g->nodes = tmp;
|
|
||||||
g->nodes[g->node_count++] = n;
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
gl_graph_add_edge(graph_t *g, graph_node_t *from, graph_node_t *to)
|
|
||||||
{
|
|
||||||
if (!g || !from || !to) { return; }
|
|
||||||
graph_node_t **tmp = realloc(from->edges, sizeof(*from->edges) * (from->edge_count + 1));
|
|
||||||
if (!tmp) { return; }
|
|
||||||
from->edges = tmp;
|
|
||||||
from->edges[from->edge_count++] = to;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
|
||||||
dfs_cycle(graph_node_t *n)
|
|
||||||
{
|
|
||||||
n->visited = true;
|
|
||||||
n->in_stack = true;
|
|
||||||
|
|
||||||
for (size_t i = 0; i < n->edge_count; i++) {
|
|
||||||
graph_node_t *child = n->edges[i];
|
|
||||||
if (!child->visited && dfs_cycle(child)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if (child->in_stack) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
n->in_stack = false;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
gl_graph_has_cycle(graph_t *g)
|
|
||||||
{
|
|
||||||
if (!g) { return false; }
|
|
||||||
for (size_t i = 0; i < g->node_count; i++) {
|
|
||||||
g->nodes[i]->visited = false;
|
|
||||||
g->nodes[i]->in_stack = false;
|
|
||||||
}
|
|
||||||
for (size_t i = 0; i < g->node_count; i++) {
|
|
||||||
if (!g->nodes[i]->visited && dfs_cycle(g->nodes[i])) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
dfs_toposort(graph_node_t *n, void **result, size_t *index)
|
|
||||||
{
|
|
||||||
n->visited = true;
|
|
||||||
for (size_t i = 0; i < n->edge_count; i++) {
|
|
||||||
if (!n->edges[i]->visited) {
|
|
||||||
dfs_toposort(n->edges[i], result, index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
result[(*index)++] = n->data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
**gl_graph_toposort(graph_t *g, size_t *out_count)
|
|
||||||
{
|
|
||||||
if (!g || !out_count) { return NULL; }
|
|
||||||
if (gl_graph_has_cycle(g)) {
|
|
||||||
fprintf(stderr, "Error: dependency cycle detected\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
*out_count = g->node_count;
|
|
||||||
void **order = calloc(g->node_count, sizeof(void *));
|
|
||||||
if (!order) { return NULL; }
|
|
||||||
|
|
||||||
for (size_t i = 0; i < g->node_count; i++) {
|
|
||||||
g->nodes[i]->visited = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t index = 0;
|
|
||||||
for (size_t i = 0; i < g->node_count; i++) {
|
|
||||||
if (!g->nodes[i]->visited) {
|
|
||||||
dfs_toposort(g->nodes[i], order, (size_t *)&index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return order;
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
#ifndef DAG_H_
|
|
||||||
#define DAG_H_
|
|
||||||
|
|
||||||
#define _POSIX_C_SOURCE 200809L
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
typedef struct graph_node graph_node_t;
|
|
||||||
typedef struct graph graph_t;
|
|
||||||
|
|
||||||
struct graph_node {
|
|
||||||
void *data;
|
|
||||||
graph_node_t **edges;
|
|
||||||
size_t edge_count;
|
|
||||||
bool visited;
|
|
||||||
bool in_stack;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct graph {
|
|
||||||
graph_node_t **nodes;
|
|
||||||
size_t node_count;
|
|
||||||
};
|
|
||||||
|
|
||||||
graph_t *graph_create(void);
|
|
||||||
void graph_free(graph_t *g);
|
|
||||||
|
|
||||||
graph_node_t *graph_add_node(graph_t *g, void *data);
|
|
||||||
void graph_add_edge(graph_t *g, graph_node_t *from, graph_node_t *to);
|
|
||||||
|
|
||||||
bool graph_has_cycle(graph_t *g);
|
|
||||||
void **graph_toposort(graph_t *g, size_t *out_count);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
+727
@@ -0,0 +1,727 @@
|
|||||||
|
#define _POSIX_C_SOURCE 200809L
|
||||||
|
#define _XOPEN_SOURCE 700
|
||||||
|
|
||||||
|
#include <archive.h>
|
||||||
|
#include <archive_entry.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
#include "deps.h"
|
||||||
|
#include "istoreutils.h"
|
||||||
|
#include "log.h"
|
||||||
|
#include "pkg.h"
|
||||||
|
|
||||||
|
/* Where one entry of a package lands once linked: its RUNTIME path (what
|
||||||
|
* a message names and what two packages are compared by). */
|
||||||
|
struct dest {
|
||||||
|
char *path;
|
||||||
|
bool dir;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* One installed (or about to be installed) package. repo/name/dirname
|
||||||
|
* come from the store layout (store/<repo>/<name>/<name>-<ver>), or from
|
||||||
|
* the manifest for a package that isn't installed yet. deps/confs come
|
||||||
|
* from the manifest; a version dir without one (installed before
|
||||||
|
* manifests were saved) has none. */
|
||||||
|
struct rec {
|
||||||
|
char repo[NAME_MAX + 1];
|
||||||
|
char name[NAME_MAX + 1];
|
||||||
|
char dirname[NAME_MAX + 1];
|
||||||
|
semver_t ver;
|
||||||
|
gl_pkg_t pkg;
|
||||||
|
bool touched; /* added or replaced by this transaction */
|
||||||
|
bool gone; /* removed or replaced: not in the result */
|
||||||
|
|
||||||
|
/* For the file checks: where its files come from (a version dir in
|
||||||
|
* a store, or a .gpkg not installed yet), whether its link pass is
|
||||||
|
* this transaction's (fresh: it reports refusals), whether that
|
||||||
|
* pass may displace foreign files (-O), and, once computed, where
|
||||||
|
* every entry lands. */
|
||||||
|
char src[PATH_MAX];
|
||||||
|
bool from_archive;
|
||||||
|
bool fresh;
|
||||||
|
bool overwrite;
|
||||||
|
struct dest *dests;
|
||||||
|
size_t ndests;
|
||||||
|
bool dests_loaded;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* What the file checks need to know about the transaction's context. */
|
||||||
|
struct env {
|
||||||
|
gl_ctx_scope_t scope;
|
||||||
|
uid_t uid;
|
||||||
|
const char *sysroot;
|
||||||
|
int strict;
|
||||||
|
char store_rt[PATH_MAX]; /* live store, runtime path: link targets */
|
||||||
|
char store_at[PATH_MAX]; /* the store being checked, install path */
|
||||||
|
};
|
||||||
|
|
||||||
|
struct set {
|
||||||
|
struct rec *v;
|
||||||
|
size_t n;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* A package the transaction removes outright (not replaced). */
|
||||||
|
struct removed {
|
||||||
|
char repo[NAME_MAX + 1];
|
||||||
|
char name[NAME_MAX + 1];
|
||||||
|
};
|
||||||
|
|
||||||
|
static void
|
||||||
|
set_free(struct set *s)
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < s->n; i++) {
|
||||||
|
gl_free_pkg(&s->v[i].pkg);
|
||||||
|
gl_free_semver(&s->v[i].ver);
|
||||||
|
for (size_t k = 0; k < s->v[i].ndests; k++) { free(s->v[i].dests[k].path); }
|
||||||
|
free(s->v[i].dests);
|
||||||
|
}
|
||||||
|
free(s->v);
|
||||||
|
s->v = NULL;
|
||||||
|
s->n = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct rec *
|
||||||
|
set_add(struct set *s)
|
||||||
|
{
|
||||||
|
struct rec *grown = realloc(s->v, (s->n + 1) * sizeof(*s->v));
|
||||||
|
if (!grown) { return NULL; }
|
||||||
|
s->v = grown;
|
||||||
|
memset(&s->v[s->n], 0, sizeof(*s->v));
|
||||||
|
return &s->v[s->n++];
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
semver_cmp(const semver_t *a, const semver_t *b)
|
||||||
|
{
|
||||||
|
if (a->maj != b->maj) { return a->maj < b->maj ? -1 : 1; }
|
||||||
|
if (a->min != b->min) { return a->min < b->min ? -1 : 1; }
|
||||||
|
if (a->pat != b->pat) { return a->pat < b->pat ? -1 : 1; }
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Every installed package in `store`. A missing store is empty (nothing
|
||||||
|
* installed); any other failure to read it is an error, unless `lenient`
|
||||||
|
* (the system store as seen from user scope: unreadable means "nothing
|
||||||
|
* there to depend on", and the check then says what's missing). */
|
||||||
|
static int
|
||||||
|
load_store(const char *store, struct set *s, bool lenient)
|
||||||
|
{
|
||||||
|
DIR *sd = opendir(store);
|
||||||
|
if (!sd) {
|
||||||
|
return (errno == ENOENT || lenient) ? 0 : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int rc = 0;
|
||||||
|
struct dirent *re;
|
||||||
|
while (rc == 0 && (re = readdir(sd))) {
|
||||||
|
if (re->d_name[0] == '.') { continue; }
|
||||||
|
|
||||||
|
char repo_path[PATH_MAX];
|
||||||
|
snprintf(repo_path, sizeof(repo_path), "%s/%s", store, re->d_name);
|
||||||
|
DIR *rd = opendir(repo_path);
|
||||||
|
if (!rd) { continue; } /* not a directory */
|
||||||
|
|
||||||
|
struct dirent *ne;
|
||||||
|
while (rc == 0 && (ne = readdir(rd))) {
|
||||||
|
if (ne->d_name[0] == '.') { continue; }
|
||||||
|
|
||||||
|
char name_path[PATH_MAX];
|
||||||
|
snprintf(name_path, sizeof(name_path), "%s/%s", repo_path, ne->d_name);
|
||||||
|
DIR *nd = opendir(name_path);
|
||||||
|
if (!nd) { continue; }
|
||||||
|
|
||||||
|
struct dirent *ve;
|
||||||
|
while ((ve = readdir(nd))) {
|
||||||
|
if (ve->d_name[0] == '.') { continue; }
|
||||||
|
|
||||||
|
struct rec *r = set_add(s);
|
||||||
|
if (!r) { rc = -1; break; }
|
||||||
|
snprintf(r->repo, sizeof(r->repo), "%s", re->d_name);
|
||||||
|
snprintf(r->name, sizeof(r->name), "%s", ne->d_name);
|
||||||
|
snprintf(r->dirname, sizeof(r->dirname), "%s", ve->d_name);
|
||||||
|
snprintf(r->src, sizeof(r->src), "%s/%s", name_path, ve->d_name);
|
||||||
|
|
||||||
|
char manifest[PATH_MAX];
|
||||||
|
snprintf(manifest, sizeof(manifest), "%s/%s/" GL_MANIFEST_COPY,
|
||||||
|
name_path, ve->d_name);
|
||||||
|
if (gl_gpm2gpkg(manifest, &r->pkg) != 0) {
|
||||||
|
gl_free_pkg(&r->pkg);
|
||||||
|
memset(&r->pkg, 0, sizeof(r->pkg));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The version is the dir name minus "<name>-". */
|
||||||
|
size_t prefix = strlen(ne->d_name) + 1;
|
||||||
|
r->ver = gl_parse_semver(strlen(ve->d_name) > prefix
|
||||||
|
? ve->d_name + prefix : NULL);
|
||||||
|
break; /* one version per package */
|
||||||
|
}
|
||||||
|
closedir(nd);
|
||||||
|
}
|
||||||
|
closedir(rd);
|
||||||
|
}
|
||||||
|
closedir(sd);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct rec *
|
||||||
|
find_live(const struct set *s, const char *repo, const char *name)
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < s->n; i++) {
|
||||||
|
if (!s->v[i].gone && strcmp(s->v[i].repo, repo) == 0 &&
|
||||||
|
strcmp(s->v[i].name, name) == 0) {
|
||||||
|
return &s->v[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Is there a package named `name` (any repo) in the result or, from user
|
||||||
|
* scope, the system? With `min`, it must also be at least that version. */
|
||||||
|
static bool
|
||||||
|
provided(const struct set *res, const struct set *sys, const char *name,
|
||||||
|
const semver_t *min)
|
||||||
|
{
|
||||||
|
const struct set *sets[] = { res, sys };
|
||||||
|
for (int k = 0; k < 2; k++) {
|
||||||
|
for (size_t i = 0; i < sets[k]->n; i++) {
|
||||||
|
const struct rec *r = &sets[k]->v[i];
|
||||||
|
if (r->gone || strcmp(r->name, name) != 0) { continue; }
|
||||||
|
if (!min || semver_cmp(&r->ver, min) >= 0) { return true; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
lists_conflict(const struct rec *r, const char *name)
|
||||||
|
{
|
||||||
|
if (!r->pkg.pkg_conflicts) { return false; }
|
||||||
|
for (const conf_t *c = r->pkg.pkg_conflicts; c->conf_name; c++) {
|
||||||
|
if (strcmp(c->conf_name, name) == 0) { return true; }
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Does the transaction touch packages named `name`: add or replace one,
|
||||||
|
* or remove one outright? */
|
||||||
|
static bool
|
||||||
|
name_touched(const struct set *res, const struct removed *rm, size_t nrm,
|
||||||
|
const char *name)
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < res->n; i++) {
|
||||||
|
if (res->v[i].touched && strcmp(res->v[i].name, name) == 0) { return true; }
|
||||||
|
}
|
||||||
|
for (size_t i = 0; i < nrm; i++) {
|
||||||
|
if (strcmp(rm[i].name, name) == 0) { return true; }
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
fmt_ver(const semver_t *v, char *out, size_t outsz)
|
||||||
|
{
|
||||||
|
snprintf(out, outsz, "%d.%d.%d", v->maj, v->min, v->pat);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* File checks (ROADMAP 2.6 and 1.2's --strict).
|
||||||
|
*
|
||||||
|
* Every entry of a package lands somewhere once linked; dest_of mirrors
|
||||||
|
* gl_link_pkg exactly: entries under a dot-prefixed name are never
|
||||||
|
* linked, a leading usr/ is stripped, base-repo packages in system scope
|
||||||
|
* land in /usr and everything else in the scope's links tree, and in
|
||||||
|
* system scope the top-level etc/ is copied into /etc.
|
||||||
|
*/
|
||||||
|
static bool
|
||||||
|
has_dot_component(const char *rel)
|
||||||
|
{
|
||||||
|
for (const char *c = rel; c; c = strchr(c, '/')) {
|
||||||
|
if (*c == '/') { c++; }
|
||||||
|
if (*c == '.') { return true; }
|
||||||
|
if (!*c) { break; }
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
dest_of(const struct env *e, const char *repo, const char *rel, char *out, size_t outsz)
|
||||||
|
{
|
||||||
|
if (e->scope == GL_SCOPE_SYS &&
|
||||||
|
(strcmp(rel, "etc") == 0 || strncmp(rel, "etc/", 4) == 0)) {
|
||||||
|
return snprintf(out, outsz, "/%s", rel) >= (int)outsz ? -1 : 0;
|
||||||
|
}
|
||||||
|
if (strncmp(rel, "usr/", 4) == 0) { rel += 4; }
|
||||||
|
|
||||||
|
char base[PATH_MAX];
|
||||||
|
if (e->scope == GL_SCOPE_SYS) {
|
||||||
|
snprintf(base, sizeof(base), "%s", strcmp(repo, "base") == 0
|
||||||
|
? "/usr" : GL_SYS_ROOT "/links");
|
||||||
|
} else {
|
||||||
|
char ub[PATH_MAX];
|
||||||
|
gl_usr_base(e->uid, ub, sizeof(ub));
|
||||||
|
snprintf(base, sizeof(base), "%s/links", ub);
|
||||||
|
}
|
||||||
|
return snprintf(out, outsz, "%s/%s", base, rel) >= (int)outsz ? -1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
add_dest(struct rec *r, const char *path, bool dir)
|
||||||
|
{
|
||||||
|
for (size_t k = 0; k < r->ndests; k++) {
|
||||||
|
if (strcmp(r->dests[k].path, path) == 0) {
|
||||||
|
if (!dir) { r->dests[k].dir = false; }
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
struct dest *grown = realloc(r->dests, (r->ndests + 1) * sizeof(*grown));
|
||||||
|
if (!grown) { return -1; }
|
||||||
|
r->dests = grown;
|
||||||
|
r->dests[r->ndests].path = strdup(path);
|
||||||
|
if (!r->dests[r->ndests].path) { return -1; }
|
||||||
|
r->dests[r->ndests].dir = dir;
|
||||||
|
r->ndests++;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* `rel` (and, for an archive entry, its parents, which tar needn't list) */
|
||||||
|
static int
|
||||||
|
add_rel(const struct env *e, struct rec *r, const char *rel, bool dir, bool parents)
|
||||||
|
{
|
||||||
|
if (rel[0] == '\0' || has_dot_component(rel)) { return 0; }
|
||||||
|
|
||||||
|
char d[PATH_MAX];
|
||||||
|
if (parents) {
|
||||||
|
char buf[PATH_MAX];
|
||||||
|
snprintf(buf, sizeof(buf), "%s", rel);
|
||||||
|
for (char *p = buf; (p = strchr(p, '/')); p++) {
|
||||||
|
*p = '\0';
|
||||||
|
if (dest_of(e, r->repo, buf, d, sizeof(d)) != 0 || add_dest(r, d, true) != 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
*p = '/';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (dest_of(e, r->repo, rel, d, sizeof(d)) != 0) { return -1; }
|
||||||
|
return add_dest(r, d, dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
walk_store_dir(const struct env *e, struct rec *r, const char *dir, size_t strip)
|
||||||
|
{
|
||||||
|
DIR *d = opendir(dir);
|
||||||
|
if (!d) { return 0; }
|
||||||
|
int rc = 0;
|
||||||
|
struct dirent *ent;
|
||||||
|
while (rc == 0 && (ent = readdir(d))) {
|
||||||
|
if (ent->d_name[0] == '.') { continue; }
|
||||||
|
char full[PATH_MAX];
|
||||||
|
snprintf(full, sizeof(full), "%s/%s", dir, ent->d_name);
|
||||||
|
struct stat st;
|
||||||
|
if (lstat(full, &st) != 0) { continue; }
|
||||||
|
const char *rel = full + strip;
|
||||||
|
if (S_ISDIR(st.st_mode)) {
|
||||||
|
rc = add_rel(e, r, rel, true, false);
|
||||||
|
if (rc == 0) { rc = walk_store_dir(e, r, full, strip); }
|
||||||
|
} else if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)) {
|
||||||
|
rc = add_rel(e, r, rel, false, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir(d);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
walk_archive(const struct env *e, struct rec *r)
|
||||||
|
{
|
||||||
|
char prefix[PATH_MAX];
|
||||||
|
snprintf(prefix, sizeof(prefix), "%s-%d.%d.%d/files/", r->name,
|
||||||
|
r->pkg.pkg_ver.maj, r->pkg.pkg_ver.min, r->pkg.pkg_ver.pat);
|
||||||
|
size_t plen = strlen(prefix);
|
||||||
|
|
||||||
|
struct archive *a = archive_read_new();
|
||||||
|
archive_read_support_filter_gzip(a);
|
||||||
|
archive_read_support_format_tar(a);
|
||||||
|
if (archive_read_open_filename(a, r->src, 10240) != ARCHIVE_OK) {
|
||||||
|
archive_read_free(a);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int rc = 0;
|
||||||
|
struct archive_entry *entry;
|
||||||
|
while (rc == 0 && archive_read_next_header(a, &entry) == ARCHIVE_OK) {
|
||||||
|
const char *path = archive_entry_pathname(entry);
|
||||||
|
if (strncmp(path, prefix, plen) == 0) {
|
||||||
|
char rel[PATH_MAX];
|
||||||
|
snprintf(rel, sizeof(rel), "%s", path + plen);
|
||||||
|
size_t len = strlen(rel);
|
||||||
|
while (len > 0 && rel[len - 1] == '/') { rel[--len] = '\0'; }
|
||||||
|
mode_t type = archive_entry_filetype(entry);
|
||||||
|
if (type == AE_IFDIR) {
|
||||||
|
rc = add_rel(e, r, rel, true, true);
|
||||||
|
} else if (type == AE_IFREG || type == AE_IFLNK) {
|
||||||
|
rc = add_rel(e, r, rel, false, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
archive_read_data_skip(a);
|
||||||
|
}
|
||||||
|
archive_read_free(a);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
load_dests(const struct env *e, struct rec *r)
|
||||||
|
{
|
||||||
|
if (r->dests_loaded) { return 0; }
|
||||||
|
r->dests_loaded = true;
|
||||||
|
if (r->from_archive) { return walk_archive(e, r); }
|
||||||
|
return walk_store_dir(e, r, r->src, strlen(r->src) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct item {
|
||||||
|
const char *path;
|
||||||
|
bool dir;
|
||||||
|
size_t rec;
|
||||||
|
};
|
||||||
|
|
||||||
|
static int
|
||||||
|
item_cmp(const void *a, const void *b)
|
||||||
|
{
|
||||||
|
const struct item *x = a, *y = b;
|
||||||
|
int c = strcmp(x->path, y->path);
|
||||||
|
if (c != 0) { return c; }
|
||||||
|
return x->rec < y->rec ? -1 : x->rec > y->rec;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Two packages shipping the same path (ROADMAP 2.6): whichever linked
|
||||||
|
* last used to win silently. Refused when either package is part of
|
||||||
|
* this transaction; at least one of the two entries must be a file or
|
||||||
|
* symlink (sharing a directory is normal). */
|
||||||
|
static int
|
||||||
|
check_collisions(const struct env *e, struct set *res)
|
||||||
|
{
|
||||||
|
size_t n = 0;
|
||||||
|
for (size_t i = 0; i < res->n; i++) {
|
||||||
|
if (res->v[i].gone) { continue; }
|
||||||
|
if (load_dests(e, &res->v[i]) != 0) { return -1; }
|
||||||
|
n += res->v[i].ndests;
|
||||||
|
}
|
||||||
|
if (n == 0) { return 0; }
|
||||||
|
|
||||||
|
struct item *items = malloc(n * sizeof(*items));
|
||||||
|
if (!items) { return -1; }
|
||||||
|
size_t k = 0;
|
||||||
|
for (size_t i = 0; i < res->n; i++) {
|
||||||
|
if (res->v[i].gone) { continue; }
|
||||||
|
for (size_t j = 0; j < res->v[i].ndests; j++) {
|
||||||
|
items[k++] = (struct item){ res->v[i].dests[j].path, res->v[i].dests[j].dir, i };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
qsort(items, n, sizeof(*items), item_cmp);
|
||||||
|
|
||||||
|
int problems = 0;
|
||||||
|
for (size_t start = 0; start < n; ) {
|
||||||
|
size_t end = start + 1;
|
||||||
|
while (end < n && strcmp(items[end].path, items[start].path) == 0) { end++; }
|
||||||
|
for (size_t a = start; a < end; a++) {
|
||||||
|
const struct rec *ra = &res->v[items[a].rec];
|
||||||
|
if (!ra->touched && !ra->fresh) { continue; }
|
||||||
|
for (size_t b = start; b < end; b++) {
|
||||||
|
if (b == a || (items[a].dir && items[b].dir)) { continue; }
|
||||||
|
const struct rec *rb = &res->v[items[b].rec];
|
||||||
|
/* two of this transaction's packages: report once */
|
||||||
|
if ((rb->touched || rb->fresh) && b < a) { continue; }
|
||||||
|
lg_printf(2, "%s::%s and %s::%s both ship %s.",
|
||||||
|
ra->repo, ra->name, rb->repo, rb->name, items[a].path);
|
||||||
|
problems++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
start = end;
|
||||||
|
}
|
||||||
|
free(items);
|
||||||
|
return problems;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --strict: what the post-commit link pass would refuse, refused now
|
||||||
|
* instead, before anything is committed. Same rules as gl_link_pkg, for
|
||||||
|
* this transaction's packages only (the ones whose refusals it reports).
|
||||||
|
* User scope never has a foreign file in its links tree (rebuilt on
|
||||||
|
* every commit), and config in /etc is offered as .new, never refused. */
|
||||||
|
static int
|
||||||
|
check_links(const struct env *e, struct set *res)
|
||||||
|
{
|
||||||
|
if (!e->strict || e->scope != GL_SCOPE_SYS) { return 0; }
|
||||||
|
|
||||||
|
char store_prefix[PATH_MAX];
|
||||||
|
snprintf(store_prefix, sizeof(store_prefix), "%s/", e->store_rt);
|
||||||
|
size_t splen = strlen(store_prefix);
|
||||||
|
|
||||||
|
int problems = 0;
|
||||||
|
for (size_t i = 0; i < res->n; i++) {
|
||||||
|
struct rec *r = &res->v[i];
|
||||||
|
if (r->gone || !(r->touched || r->fresh)) { continue; }
|
||||||
|
if (load_dests(e, r) != 0) { return -1; }
|
||||||
|
|
||||||
|
for (size_t k = 0; k < r->ndests; k++) {
|
||||||
|
const struct dest *d = &r->dests[k];
|
||||||
|
if (strcmp(d->path, "/etc") == 0 || strncmp(d->path, "/etc/", 5) == 0) { continue; }
|
||||||
|
|
||||||
|
char at[PATH_MAX];
|
||||||
|
snprintf(at, sizeof(at), "%s%s", e->sysroot, d->path);
|
||||||
|
struct stat st;
|
||||||
|
if (lstat(at, &st) != 0) {
|
||||||
|
if (errno == ENOTDIR) {
|
||||||
|
lg_printf(2, "Refusing to overwrite non-glacier path: %s", at);
|
||||||
|
problems++;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ours = false;
|
||||||
|
if (S_ISLNK(st.st_mode)) {
|
||||||
|
char target[PATH_MAX];
|
||||||
|
ssize_t tn = readlink(at, target, sizeof(target) - 1);
|
||||||
|
ours = tn >= 0 && (size_t)tn >= splen &&
|
||||||
|
strncmp(target, store_prefix, splen) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (d->dir) {
|
||||||
|
/* a foreign symlink here (usr/sbin -> bin) is followed,
|
||||||
|
* like gl_link_pkg does; one of glacier's isn't */
|
||||||
|
if (S_ISDIR(st.st_mode) || (S_ISLNK(st.st_mode) && !ours)) { continue; }
|
||||||
|
if (ours) {
|
||||||
|
lg_printf(2, "Refusing to merge directory %s into another package's symlink", at);
|
||||||
|
} else {
|
||||||
|
lg_printf(2, "Refusing to overwrite non-glacier path: %s", at);
|
||||||
|
}
|
||||||
|
problems++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ours) { continue; }
|
||||||
|
if (r->overwrite && (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode))) {
|
||||||
|
char kept[PATH_MAX];
|
||||||
|
snprintf(kept, sizeof(kept), "%s/.displaced%s", e->store_at, d->path);
|
||||||
|
struct stat kst;
|
||||||
|
if (lstat(kept, &kst) != 0) { continue; } /* -O moves it aside */
|
||||||
|
}
|
||||||
|
lg_printf(2, "Refusing to overwrite non-glacier path: %s", at);
|
||||||
|
problems++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return problems;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The checks themselves, on the result of a transaction. */
|
||||||
|
static int
|
||||||
|
check(const struct env *e, struct set *res, const struct set *sys,
|
||||||
|
const struct removed *rm, size_t nrm)
|
||||||
|
{
|
||||||
|
int problems = 0;
|
||||||
|
char ver[64];
|
||||||
|
|
||||||
|
for (size_t i = 0; i < res->n; i++) {
|
||||||
|
const struct rec *p = &res->v[i];
|
||||||
|
if (p->gone) { continue; }
|
||||||
|
|
||||||
|
const dep_t *deps = p->pkg.pkg_dependencies;
|
||||||
|
for (const dep_t *d = deps; d && d->dep_name; d++) {
|
||||||
|
/* An added package: all its deps. An untouched one:
|
||||||
|
* only deps on something this transaction changes. */
|
||||||
|
if (!p->touched && !name_touched(res, rm, nrm, d->dep_name)) { continue; }
|
||||||
|
if (provided(res, sys, d->dep_name, &d->dep_ver)) { continue; }
|
||||||
|
|
||||||
|
const struct removed *gone = NULL;
|
||||||
|
for (size_t k = 0; !p->touched && k < nrm; k++) {
|
||||||
|
if (strcmp(rm[k].name, d->dep_name) == 0) { gone = &rm[k]; break; }
|
||||||
|
}
|
||||||
|
if (gone && !provided(res, sys, d->dep_name, NULL)) {
|
||||||
|
lg_printf(2, "Removing %s::%s breaks %s::%s.",
|
||||||
|
gone->repo, gone->name, p->repo, p->name);
|
||||||
|
} else {
|
||||||
|
fmt_ver(&d->dep_ver, ver, sizeof(ver));
|
||||||
|
lg_printf(2, "%s::%s requires %s >= %s, which is not installed.",
|
||||||
|
p->repo, p->name, d->dep_name, ver);
|
||||||
|
}
|
||||||
|
problems++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!p->touched) { continue; }
|
||||||
|
for (size_t j = 0; j < res->n; j++) {
|
||||||
|
const struct rec *q = &res->v[j];
|
||||||
|
if (j == i || q->gone) { continue; }
|
||||||
|
/* Two added packages: report the pair once. */
|
||||||
|
if (q->touched && j < i) { continue; }
|
||||||
|
if (lists_conflict(p, q->name) || lists_conflict(q, p->name)) {
|
||||||
|
lg_printf(2, "%s::%s conflicts with %s::%s.",
|
||||||
|
p->repo, p->name, q->repo, q->name);
|
||||||
|
problems++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int files = check_collisions(e, res);
|
||||||
|
if (files < 0) { return -1; }
|
||||||
|
problems += files;
|
||||||
|
|
||||||
|
files = check_links(e, res);
|
||||||
|
if (files < 0) { return -1; }
|
||||||
|
return problems + files;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The runtime path of the live store for a context's scope and root. */
|
||||||
|
static void
|
||||||
|
env_init(struct env *e, const gl_context_t *ctx, const char *store_at)
|
||||||
|
{
|
||||||
|
e->scope = ctx->scope;
|
||||||
|
e->uid = ctx->uid;
|
||||||
|
e->sysroot = ctx->sysroot;
|
||||||
|
e->strict = ctx->strict;
|
||||||
|
if (ctx->scope == GL_SCOPE_USR) {
|
||||||
|
char ub[PATH_MAX];
|
||||||
|
gl_usr_base(ctx->uid, ub, sizeof(ub));
|
||||||
|
snprintf(e->store_rt, sizeof(e->store_rt), "%s/store", ub);
|
||||||
|
} else {
|
||||||
|
snprintf(e->store_rt, sizeof(e->store_rt), "%s/store", GL_SYS_ROOT);
|
||||||
|
}
|
||||||
|
snprintf(e->store_at, sizeof(e->store_at), "%s", store_at);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The system store, which a user-scope transaction's deps may rely on.
|
||||||
|
* Always the running system's: user scope never has an install root. */
|
||||||
|
static int
|
||||||
|
load_sys(gl_ctx_scope_t scope, struct set *sys)
|
||||||
|
{
|
||||||
|
if (scope != GL_SCOPE_USR) { return 0; }
|
||||||
|
return load_store(GL_SYS_ROOT "/store", sys, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
gl_check_plan(const gl_context_t *live,
|
||||||
|
const char *const *add_paths, size_t n_add,
|
||||||
|
const char *const *remove_ids, size_t n_remove)
|
||||||
|
{
|
||||||
|
if (!live) { return -1; }
|
||||||
|
|
||||||
|
struct set res = { NULL, 0 }, sys = { NULL, 0 };
|
||||||
|
struct removed *rm = calloc(n_remove + 1, sizeof(*rm));
|
||||||
|
size_t nrm = 0;
|
||||||
|
int rc = -1;
|
||||||
|
|
||||||
|
if (!rm || load_store(live->store_path, &res, false) != 0 ||
|
||||||
|
load_sys(live->scope, &sys) != 0) {
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < n_remove; i++) {
|
||||||
|
const char *sep = strstr(remove_ids[i], "::");
|
||||||
|
if (!sep) { goto out; }
|
||||||
|
char repo[NAME_MAX + 1];
|
||||||
|
snprintf(repo, sizeof(repo), "%.*s", (int)(sep - remove_ids[i]), remove_ids[i]);
|
||||||
|
struct rec *r = (struct rec *)find_live(&res, repo, sep + 2);
|
||||||
|
if (!r) { continue; } /* not installed: nothing to break */
|
||||||
|
r->gone = true;
|
||||||
|
snprintf(rm[nrm].repo, sizeof(rm[nrm].repo), "%s", r->repo);
|
||||||
|
snprintf(rm[nrm].name, sizeof(rm[nrm].name), "%s", r->name);
|
||||||
|
nrm++;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < n_add; i++) {
|
||||||
|
gl_pkg_t pkg = {0};
|
||||||
|
if (gl_read_pkg_manifest(add_paths[i], &pkg) != GL_INSTALL_OK) { goto out; }
|
||||||
|
|
||||||
|
/* Same repo::name installed: this replaces it. */
|
||||||
|
struct rec *old = (struct rec *)find_live(&res, pkg.pkg_repo, pkg.pkg_name);
|
||||||
|
if (old) { old->gone = true; }
|
||||||
|
|
||||||
|
struct rec *r = set_add(&res);
|
||||||
|
if (!r) { gl_free_pkg(&pkg); goto out; }
|
||||||
|
snprintf(r->repo, sizeof(r->repo), "%s", pkg.pkg_repo);
|
||||||
|
snprintf(r->name, sizeof(r->name), "%s", pkg.pkg_name);
|
||||||
|
r->ver = (semver_t){ pkg.pkg_ver.maj, pkg.pkg_ver.min, pkg.pkg_ver.pat, NULL };
|
||||||
|
r->pkg = pkg;
|
||||||
|
r->touched = true;
|
||||||
|
r->fresh = true;
|
||||||
|
r->overwrite = live->overwrite != 0;
|
||||||
|
r->from_archive = true;
|
||||||
|
snprintf(r->src, sizeof(r->src), "%s", add_paths[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct env e;
|
||||||
|
env_init(&e, live, live->store_path);
|
||||||
|
rc = check(&e, &res, &sys, rm, nrm);
|
||||||
|
out:
|
||||||
|
set_free(&res);
|
||||||
|
set_free(&sys);
|
||||||
|
free(rm);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
gl_check_txn(const gl_context_t *stage)
|
||||||
|
{
|
||||||
|
if (!stage || stage->mode != GL_CTX_STAGE) { return -1; }
|
||||||
|
|
||||||
|
char base[PATH_MAX], live_store[PATH_MAX];
|
||||||
|
if (stage->scope == GL_SCOPE_USR) {
|
||||||
|
gl_usr_base(stage->uid, base, sizeof(base));
|
||||||
|
} else {
|
||||||
|
snprintf(base, sizeof(base), "%s%s", stage->sysroot, GL_SYS_ROOT);
|
||||||
|
}
|
||||||
|
snprintf(live_store, sizeof(live_store), "%s/store", base);
|
||||||
|
|
||||||
|
struct set res = { NULL, 0 }, live = { NULL, 0 }, sys = { NULL, 0 };
|
||||||
|
struct removed *rm = NULL;
|
||||||
|
size_t nrm = 0;
|
||||||
|
int rc = -1;
|
||||||
|
|
||||||
|
if (load_store(stage->store_path, &res, false) != 0 ||
|
||||||
|
load_store(live_store, &live, false) != 0 ||
|
||||||
|
load_sys(stage->scope, &sys) != 0) {
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
rm = calloc(live.n + 1, sizeof(*rm));
|
||||||
|
if (!rm) { goto out; }
|
||||||
|
|
||||||
|
/* Touched: in the stage, but not as this exact version in live.
|
||||||
|
* Fresh: installed by this transaction (a reinstall of the same
|
||||||
|
* version is fresh but not touched); its link pass is this one's. */
|
||||||
|
for (size_t i = 0; i < res.n; i++) {
|
||||||
|
struct rec *r = &res.v[i];
|
||||||
|
const struct rec *l = find_live(&live, r->repo, r->name);
|
||||||
|
r->touched = !l || strcmp(l->dirname, r->dirname) != 0;
|
||||||
|
|
||||||
|
char marker[PATH_MAX];
|
||||||
|
struct stat mst;
|
||||||
|
snprintf(marker, sizeof(marker), "%s/" GL_FRESH_MARKER, r->src);
|
||||||
|
r->fresh = lstat(marker, &mst) == 0;
|
||||||
|
snprintf(marker, sizeof(marker), "%s/" GL_OVERWRITE_MARKER, r->src);
|
||||||
|
r->overwrite = lstat(marker, &mst) == 0;
|
||||||
|
}
|
||||||
|
/* Removed: in live, and no longer in the stage under that repo::name. */
|
||||||
|
for (size_t i = 0; i < live.n; i++) {
|
||||||
|
if (find_live(&res, live.v[i].repo, live.v[i].name)) { continue; }
|
||||||
|
snprintf(rm[nrm].repo, sizeof(rm[nrm].repo), "%s", live.v[i].repo);
|
||||||
|
snprintf(rm[nrm].name, sizeof(rm[nrm].name), "%s", live.v[i].name);
|
||||||
|
nrm++;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct env e;
|
||||||
|
env_init(&e, stage, stage->store_path);
|
||||||
|
rc = check(&e, &res, &sys, rm, nrm);
|
||||||
|
out:
|
||||||
|
set_free(&res);
|
||||||
|
set_free(&live);
|
||||||
|
set_free(&sys);
|
||||||
|
free(rm);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
+55
@@ -0,0 +1,55 @@
|
|||||||
|
#ifndef DEPS_H_
|
||||||
|
#define DEPS_H_
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#include "transaction.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Dependency and conflict checks (ROADMAP 2.3). Built into
|
||||||
|
* libglacier_istoreutils.so.
|
||||||
|
*
|
||||||
|
* Rules:
|
||||||
|
* - A PKG_DEPS entry {name, ver} is met by any installed package of
|
||||||
|
* that name (any repo) at version >= ver.
|
||||||
|
* - In user scope, a dependency may also be met by a system package.
|
||||||
|
* System scope never looks at user scopes.
|
||||||
|
* - PKG_CONFS is matched by name, both ways (either package listing
|
||||||
|
* the other is a conflict); its version is ignored. Only packages in
|
||||||
|
* the same scope conflict.
|
||||||
|
* - Only what a transaction CHANGES is checked: the packages it adds
|
||||||
|
* (deps and conflicts), and the installed packages that depend on
|
||||||
|
* something it removes or replaces. A store that was already
|
||||||
|
* inconsistent doesn't block unrelated work.
|
||||||
|
* - Two packages may not ship the same path (ROADMAP 2.6), compared by
|
||||||
|
* where each entry lands once linked; sharing a directory is fine.
|
||||||
|
* Checked whenever either package is part of the transaction.
|
||||||
|
* - With ctx->strict (syspkg --strict, implied by -R), anything the
|
||||||
|
* post-commit link pass would refuse (a foreign file in the way, a
|
||||||
|
* directory over another package's symlink) is refused up front,
|
||||||
|
* unless -O will move it aside. System scope only: a user's links
|
||||||
|
* tree is rebuilt on every commit.
|
||||||
|
* - Every problem is reported with lg_printf, one line each:
|
||||||
|
* extra::foo requires bar >= 1.2.0, which is not installed.
|
||||||
|
* Removing base::musl breaks extra::foo.
|
||||||
|
* extra::foo conflicts with extra::bar.
|
||||||
|
* extra::foo and extra::bar both ship /glacier/sys/links/bin/x.
|
||||||
|
* Refusing to overwrite non-glacier path: /usr/bin/x
|
||||||
|
*
|
||||||
|
* Both return the number of problems (0 = fine), or -1 if a store or a
|
||||||
|
* manifest couldn't be read.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Before a transaction: `live` is a live context; add_paths are .gpkg
|
||||||
|
* files to install (a package already installed under the same
|
||||||
|
* repo::name is replaced); remove_ids are "repo::name" strings. */
|
||||||
|
int gl_check_plan(const gl_context_t *live,
|
||||||
|
const char *const *add_paths, size_t n_add,
|
||||||
|
const char *const *remove_ids, size_t n_remove);
|
||||||
|
|
||||||
|
/* At commit: compares the stage against live. gl_commit_transaction
|
||||||
|
* calls this itself and refuses with GL_TXN_ERR_DEPS, so a caller that
|
||||||
|
* skips gl_check_plan is still held to the rules. */
|
||||||
|
int gl_check_txn(const gl_context_t *stage);
|
||||||
|
|
||||||
|
#endif
|
||||||
+389
@@ -0,0 +1,389 @@
|
|||||||
|
/*
|
||||||
|
* grepo: write and sign a repository index (REPO_DESIGN.txt section 4).
|
||||||
|
* A maintainer tool, like gsign.
|
||||||
|
*
|
||||||
|
* grepo -s KEY.sec -r REPO [-n SERIAL] [-e DAYS] DIR
|
||||||
|
*
|
||||||
|
* Reads every NAME-VER.gpkg in DIR (its manifest, sha256 and size) and
|
||||||
|
* writes DIR/repo.idx plus DIR/repo.idx.sig, signed with KEY.sec. Each
|
||||||
|
* package's manifest must say REPO, and its file name must be
|
||||||
|
* NAME-VER.gpkg as the manifest names it. The server is then any static
|
||||||
|
* file host serving DIR.
|
||||||
|
*
|
||||||
|
* SERIAL (decided 2026-10-06) is the date form YYYYMMDDNN: the larger
|
||||||
|
* of the previous DIR/repo.idx's SERIAL + 1 and today (UTC) * 100 + 1.
|
||||||
|
* -n sets it explicitly; it must still be above the previous one, or
|
||||||
|
* clients would refuse the index. VALID_UNTIL is now + DAYS days
|
||||||
|
* (default 30; decision 10c).
|
||||||
|
*
|
||||||
|
* Exit 0 on success, 1 otherwise.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _POSIX_C_SOURCE 200809L
|
||||||
|
#define _XOPEN_SOURCE 700
|
||||||
|
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <getopt.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "istoreutils.h"
|
||||||
|
#include "log.h"
|
||||||
|
#include "pkg.h"
|
||||||
|
#include "sha256.h"
|
||||||
|
#include "sign.h"
|
||||||
|
|
||||||
|
#define DEFAULT_DAYS 30
|
||||||
|
#define MAX_DAYS 3650
|
||||||
|
|
||||||
|
#define USAGE "usage: grepo [-hv] -s KEY.sec -r REPO [-n SERIAL] [-e DAYS] DIR\n"
|
||||||
|
|
||||||
|
static const struct option longopts[] = {
|
||||||
|
{ "help", no_argument, NULL, 'h' },
|
||||||
|
{ "version", no_argument, NULL, 'v' },
|
||||||
|
{ "seckey", required_argument, NULL, 's' },
|
||||||
|
{ "repo", required_argument, NULL, 'r' },
|
||||||
|
{ "serial", required_argument, NULL, 'n' },
|
||||||
|
{ "expire", required_argument, NULL, 'e' },
|
||||||
|
{ NULL, 0, NULL, 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
static void
|
||||||
|
usage(void)
|
||||||
|
{
|
||||||
|
fprintf(stderr, USAGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
help(void)
|
||||||
|
{
|
||||||
|
printf("grepo: Write and sign a repository index\n");
|
||||||
|
printf(USAGE);
|
||||||
|
printf("\n");
|
||||||
|
printf("%-25s %s\n", "{-h --help}", "Show this message");
|
||||||
|
printf("%-25s %s\n", "{-v --version}", "Show the current version");
|
||||||
|
printf("%-25s %s\n", "{-s --seckey} KEY.sec", "Sign the index with this secret key");
|
||||||
|
printf("%-25s %s\n", "{-r --repo} REPO", "Repository the packages in DIR belong to");
|
||||||
|
printf("%-25s %s\n", "{-n --serial} SERIAL", "Index serial (default: YYYYMMDDNN)");
|
||||||
|
printf("%-25s Days until the index expires (default: %d)\n", "{-e --expire} DAYS", DEFAULT_DAYS);
|
||||||
|
printf("\n");
|
||||||
|
printf("This program is free software.\n");
|
||||||
|
printf("See the GNU GPL version 3 for details.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
by_name(const void *a, const void *b)
|
||||||
|
{
|
||||||
|
return strcmp(*(char *const *)a, *(char *const *)b);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* sha256 ("sha256:<hex>") and size of a regular file, read once. */
|
||||||
|
static int
|
||||||
|
hash_file(const char *path, char sha[72], int64_t *size)
|
||||||
|
{
|
||||||
|
int fd = open(path, O_RDONLY | O_NOFOLLOW);
|
||||||
|
if (fd < 0)
|
||||||
|
return -1;
|
||||||
|
gl_sha256_ctx_t h;
|
||||||
|
gl_sha256_init(&h);
|
||||||
|
uint8_t buf[65536];
|
||||||
|
ssize_t n;
|
||||||
|
int64_t total = 0;
|
||||||
|
while ((n = read(fd, buf, sizeof buf)) > 0) {
|
||||||
|
gl_sha256_update(&h, buf, (size_t)n);
|
||||||
|
total += n;
|
||||||
|
}
|
||||||
|
close(fd);
|
||||||
|
if (n < 0)
|
||||||
|
return -1;
|
||||||
|
uint8_t digest[32];
|
||||||
|
char hex[65];
|
||||||
|
gl_sha256_final(&h, digest);
|
||||||
|
gl_sha256_to_hex(digest, hex);
|
||||||
|
snprintf(sha, 72, "sha256:%s", hex);
|
||||||
|
*size = total;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Reads a whole file (an index: at most GL_SIGN_MAX_MSG). NULL if it
|
||||||
|
* doesn't exist (errno ENOENT) or can't be read. */
|
||||||
|
static char *
|
||||||
|
slurp(const char *path, size_t *len)
|
||||||
|
{
|
||||||
|
FILE *f = fopen(path, "rb");
|
||||||
|
if (!f)
|
||||||
|
return NULL;
|
||||||
|
char *buf = malloc(GL_SIGN_MAX_MSG + 1);
|
||||||
|
size_t n = buf ? fread(buf, 1, GL_SIGN_MAX_MSG + 1, f) : 0;
|
||||||
|
int bad = !buf || ferror(f) || n > GL_SIGN_MAX_MSG;
|
||||||
|
fclose(f);
|
||||||
|
if (bad) {
|
||||||
|
free(buf);
|
||||||
|
errno = EIO;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
*len = n;
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* One DEPS/CONFS element. 0 having said why if the name is unsafe. */
|
||||||
|
static int
|
||||||
|
relation(FILE *f, const char *path, const char *what, const char *name,
|
||||||
|
const semver_t *v, int first)
|
||||||
|
{
|
||||||
|
if (!gl_valid_pkg_ident(name)) {
|
||||||
|
lg_printf(LG_ERR, "%s has a %s that is not a safe name.", path, what);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
fprintf(f, "%s { NAME = \"%s\"; VER = \"%d.%d.%d\"; }", first ? "" : ",",
|
||||||
|
name, v->maj, v->min, v->pat);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* One package's PKGS entry, appended to f. 0, or -1 having said why. */
|
||||||
|
static int
|
||||||
|
write_entry(FILE *f, const char *dir, const char *file, const char *repo)
|
||||||
|
{
|
||||||
|
char path[PATH_MAX];
|
||||||
|
snprintf(path, sizeof path, "%s/%s", dir, file);
|
||||||
|
|
||||||
|
struct stat st;
|
||||||
|
if (lstat(path, &st) != 0 || !S_ISREG(st.st_mode)) {
|
||||||
|
lg_printf(LG_ERR, "Refusing %s: not a regular file.", path);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
gl_pkg_t pkg = {0};
|
||||||
|
if (gl_read_pkg_manifest(path, &pkg) != 0) {
|
||||||
|
lg_printf(LG_ERR, "Cannot read the manifest of %s.", path);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int rc = -1;
|
||||||
|
char ver[64], want[PATH_MAX];
|
||||||
|
snprintf(ver, sizeof ver, "%d.%d.%d", pkg.pkg_ver.maj, pkg.pkg_ver.min,
|
||||||
|
pkg.pkg_ver.pat);
|
||||||
|
snprintf(want, sizeof want, "%s-%s.gpkg", pkg.pkg_name, ver);
|
||||||
|
if (strcmp(pkg.pkg_repo, repo) != 0) {
|
||||||
|
lg_printf(LG_ERR, "%s is a %s package, not %s.", path, pkg.pkg_repo, repo);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
if (strcmp(file, want) != 0) {
|
||||||
|
lg_printf(LG_ERR, "%s must be named %s, as its manifest says.", path, want);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
char sha[72];
|
||||||
|
int64_t size;
|
||||||
|
if (hash_file(path, sha, &size) != 0) {
|
||||||
|
lg_printf(LG_ERR, "Cannot read %s.", path);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(f, "\t{ NAME = \"%s\"; VER = \"%s\"; FILE = \"%s\";\n"
|
||||||
|
"\t SHA256 = \"%s\"; SIZE = %" PRId64 "L;\n\t DEPS = (",
|
||||||
|
pkg.pkg_name, ver, file, sha, size);
|
||||||
|
int first = 1;
|
||||||
|
for (dep_t *d = pkg.pkg_dependencies; d && d->dep_name; d++) {
|
||||||
|
if (!relation(f, path, "dependency", d->dep_name, &d->dep_ver, first))
|
||||||
|
goto out;
|
||||||
|
first = 0;
|
||||||
|
}
|
||||||
|
fprintf(f, "%s); CONFS = (", first ? "" : " ");
|
||||||
|
first = 1;
|
||||||
|
for (conf_t *k = pkg.pkg_conflicts; k && k->conf_name; k++) {
|
||||||
|
if (!relation(f, path, "conflict", k->conf_name, &k->conf_ver, first))
|
||||||
|
goto out;
|
||||||
|
first = 0;
|
||||||
|
}
|
||||||
|
fprintf(f, "%s); }", first ? "" : " ");
|
||||||
|
rc = 0;
|
||||||
|
out:
|
||||||
|
gl_free_pkg(&pkg);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
const char *sec = NULL, *repo = NULL;
|
||||||
|
int64_t serial = 0;
|
||||||
|
long days = DEFAULT_DAYS;
|
||||||
|
int c;
|
||||||
|
|
||||||
|
while ((c = getopt_long(argc, argv, "hvs:r:n:e:", longopts, NULL)) != -1) {
|
||||||
|
char *end;
|
||||||
|
switch (c) {
|
||||||
|
case 'h':
|
||||||
|
help();
|
||||||
|
return 0;
|
||||||
|
case 'v':
|
||||||
|
printf("v4.0.0\n");
|
||||||
|
return 0;
|
||||||
|
case 's': sec = optarg; break;
|
||||||
|
case 'r': repo = optarg; break;
|
||||||
|
case 'n':
|
||||||
|
errno = 0;
|
||||||
|
serial = strtoll(optarg, &end, 10);
|
||||||
|
if (errno || *end || end == optarg || serial <= 0) {
|
||||||
|
lg_printf(LG_ERR, "SERIAL must be a whole number above 0.");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'e':
|
||||||
|
errno = 0;
|
||||||
|
days = strtol(optarg, &end, 10);
|
||||||
|
if (errno || *end || end == optarg || days < 1 || days > MAX_DAYS) {
|
||||||
|
lg_printf(LG_ERR, "DAYS must be a whole number from 1 to %d.", MAX_DAYS);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
usage();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!sec || !repo || optind != argc - 1) {
|
||||||
|
usage();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
const char *dir = argv[optind];
|
||||||
|
if (!gl_valid_pkg_ident(repo)) {
|
||||||
|
lg_printf(LG_ERR, "Repository name %s is not a safe name ([A-Za-z0-9._-]).", repo);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int st = gl_sign_check_seckey(sec);
|
||||||
|
if (st != GL_SIGN_OK) {
|
||||||
|
lg_printf(LG_ERR, "Secret key %s %s.", sec,
|
||||||
|
st == GL_SIGN_ERR_ENCRYPTED ? "is encrypted: sign with signify" :
|
||||||
|
st == GL_SIGN_ERR_FORMAT ? "is malformed" : "cannot be read");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
char idx_path[PATH_MAX], sig_path[PATH_MAX];
|
||||||
|
if ((size_t)snprintf(idx_path, sizeof idx_path, "%s/repo.idx", dir) >= sizeof idx_path ||
|
||||||
|
(size_t)snprintf(sig_path, sizeof sig_path, "%s/repo.idx.sig", dir) >= sizeof sig_path) {
|
||||||
|
lg_printf(LG_ERR, "Path too long: %s", dir);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The previous index, for its SERIAL. The maintainer's own file:
|
||||||
|
* parsed, not verified, but it must be a well-formed index for
|
||||||
|
* this repo (a mixed-up DIR is better caught here). */
|
||||||
|
int64_t prev = 0;
|
||||||
|
size_t plen;
|
||||||
|
char *ptext = slurp(idx_path, &plen);
|
||||||
|
if (!ptext && errno != ENOENT) {
|
||||||
|
lg_printf(LG_ERR, "Cannot read %s.", idx_path);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (ptext) {
|
||||||
|
gl_index_t old;
|
||||||
|
gl_index_status_t ist = gl_index_parse(ptext, plen, repo, &old);
|
||||||
|
free(ptext);
|
||||||
|
if (ist == GL_INDEX_ERR_REPO) {
|
||||||
|
lg_printf(LG_ERR, "%s is the index of another repository.", idx_path);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (ist != GL_INDEX_OK) {
|
||||||
|
lg_printf(LG_ERR, "Malformed %s.", idx_path);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
prev = old.serial;
|
||||||
|
gl_index_free(&old);
|
||||||
|
}
|
||||||
|
|
||||||
|
time_t now = time(NULL);
|
||||||
|
if (serial == 0) {
|
||||||
|
struct tm tm;
|
||||||
|
gmtime_r(&now, &tm);
|
||||||
|
int64_t today = ((int64_t)(tm.tm_year + 1900) * 10000 +
|
||||||
|
(tm.tm_mon + 1) * 100 + tm.tm_mday) * 100 + 1;
|
||||||
|
serial = prev + 1 > today ? prev + 1 : today;
|
||||||
|
} else if (serial <= prev) {
|
||||||
|
lg_printf(LG_ERR, "SERIAL must be above %" PRId64 ", the previous index's.", prev);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
DIR *d = opendir(dir);
|
||||||
|
if (!d) {
|
||||||
|
lg_printf(LG_ERR, "Cannot open %s: %s", dir, strerror(errno));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
char **names = NULL;
|
||||||
|
size_t n = 0;
|
||||||
|
struct dirent *de;
|
||||||
|
while ((de = readdir(d))) {
|
||||||
|
size_t l = strlen(de->d_name);
|
||||||
|
if (de->d_name[0] == '.' || l < 6 || strcmp(de->d_name + l - 5, ".gpkg") != 0)
|
||||||
|
continue;
|
||||||
|
char **grown = realloc(names, (n + 1) * sizeof *names);
|
||||||
|
if (!grown || !(grown[n] = strdup(de->d_name))) {
|
||||||
|
lg_printf(LG_ERR, "Out of memory.");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
names = grown;
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
closedir(d);
|
||||||
|
qsort(names, n, sizeof *names, by_name);
|
||||||
|
|
||||||
|
/* Written beside the result, then renamed over it: never in place. */
|
||||||
|
char tmp_idx[PATH_MAX], tmp_sig[PATH_MAX];
|
||||||
|
snprintf(tmp_idx, sizeof tmp_idx, "%s/.repo.idx.XXXXXX", dir);
|
||||||
|
int fd = mkstemp(tmp_idx);
|
||||||
|
FILE *f = fd < 0 ? NULL : fdopen(fd, "w");
|
||||||
|
if (!f) {
|
||||||
|
lg_printf(LG_ERR, "Cannot write in %s: %s", dir, strerror(errno));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
snprintf(tmp_sig, sizeof tmp_sig, "%s.sig", tmp_idx);
|
||||||
|
|
||||||
|
fprintf(f, "# Repository index written by grepo. Signed: repo.idx.sig.\n"
|
||||||
|
"REPO = \"%s\";\nSERIAL = %" PRId64 "L;\nVALID_UNTIL = %" PRId64 "L;\n"
|
||||||
|
"PKGS = (\n", repo, serial, (int64_t)now + (int64_t)days * 86400);
|
||||||
|
int rc = 0;
|
||||||
|
for (size_t i = 0; i < n && rc == 0; i++) {
|
||||||
|
if (i)
|
||||||
|
fprintf(f, ",\n");
|
||||||
|
rc = write_entry(f, dir, names[i], repo);
|
||||||
|
}
|
||||||
|
fprintf(f, "%s);\n", n ? "\n" : "");
|
||||||
|
if (fchmod(fd, 0644) != 0 || fflush(f) != 0 || fsync(fd) != 0)
|
||||||
|
rc = rc ? rc : (lg_printf(LG_ERR, "Cannot write %s.", tmp_idx), -1);
|
||||||
|
if (fclose(f) != 0 && rc == 0) {
|
||||||
|
lg_printf(LG_ERR, "Cannot write %s.", tmp_idx);
|
||||||
|
rc = -1;
|
||||||
|
}
|
||||||
|
for (size_t i = 0; i < n; i++)
|
||||||
|
free(names[i]);
|
||||||
|
free(names);
|
||||||
|
|
||||||
|
if (rc == 0 && (st = gl_sign_file(sec, tmp_idx, tmp_sig)) != GL_SIGN_OK) {
|
||||||
|
lg_printf(LG_ERR, "Cannot sign %s.", tmp_idx);
|
||||||
|
rc = -1;
|
||||||
|
}
|
||||||
|
/* The signature first: a client that fetches between the renames
|
||||||
|
* gets a new .sig with the old index, which fails to verify and is
|
||||||
|
* refused, never an index accepted under the wrong signature. */
|
||||||
|
if (rc == 0 && (rename(tmp_sig, sig_path) != 0 || rename(tmp_idx, idx_path) != 0)) {
|
||||||
|
lg_printf(LG_ERR, "Cannot replace %s: %s", idx_path, strerror(errno));
|
||||||
|
rc = -1;
|
||||||
|
}
|
||||||
|
if (rc != 0) {
|
||||||
|
unlink(tmp_idx);
|
||||||
|
unlink(tmp_sig);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
lg_printf(LG_SUCCESS, "Wrote %s: %zu %s, serial %" PRId64 ".", idx_path, n,
|
||||||
|
n == 1 ? "package" : "packages", serial);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
+40
-4
@@ -1,18 +1,54 @@
|
|||||||
|
#include <getopt.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "sha256.h"
|
#include "sha256.h"
|
||||||
|
|
||||||
|
#define USAGE "usage: gsha256sum [-hv] FILE\n"
|
||||||
|
|
||||||
|
static const struct option longopts[] = {
|
||||||
|
{ "help", no_argument, NULL, 'h' },
|
||||||
|
{ "version", no_argument, NULL, 'v' },
|
||||||
|
{ NULL, 0, NULL, 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
static void
|
||||||
|
help(void)
|
||||||
|
{
|
||||||
|
printf("gsha256sum: Print a file's sha256 as a Glacier sidecar line\n");
|
||||||
|
printf(USAGE);
|
||||||
|
printf("\n");
|
||||||
|
printf("%-25s %s\n", "{-h --help}", "Show this message");
|
||||||
|
printf("%-25s %s\n", "{-v --version}", "Show the current version");
|
||||||
|
printf("\n");
|
||||||
|
printf("This program is free software.\n");
|
||||||
|
printf("See the GNU GPL version 3 for details.\n");
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
if (argc != 2) {
|
int c;
|
||||||
fprintf(stderr, "usage: %s FILE\n", argv[0]);
|
while ((c = getopt_long(argc, argv, "hv", longopts, NULL)) != -1) {
|
||||||
|
switch (c) {
|
||||||
|
case 'h':
|
||||||
|
help();
|
||||||
|
return 0;
|
||||||
|
case 'v':
|
||||||
|
printf("v4.0.0\n");
|
||||||
|
return 0;
|
||||||
|
default:
|
||||||
|
fprintf(stderr, USAGE);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (optind != argc - 1) {
|
||||||
|
fprintf(stderr, USAGE);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char hex[GL_SHA256_HEX_SIZE];
|
char hex[GL_SHA256_HEX_SIZE];
|
||||||
if (gl_sha256_file(argv[1], hex) != 0) {
|
if (gl_sha256_file(argv[optind], hex) != 0) {
|
||||||
perror(argv[1]);
|
perror(argv[optind]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+212
@@ -0,0 +1,212 @@
|
|||||||
|
/*
|
||||||
|
* gsign: make signify-compatible Ed25519 keys and signatures
|
||||||
|
* (REPO_DESIGN.txt section 2). A build/maintainer tool, like
|
||||||
|
* gsha256sum.
|
||||||
|
*
|
||||||
|
* gsign -G -p KEY.pub -s KEY.sec [-c COMMENT]
|
||||||
|
* gsign -S -s KEY.sec -m FILE [-x SIGFILE]
|
||||||
|
* gsign -V -p KEY.pub -m FILE [-x SIGFILE]
|
||||||
|
*
|
||||||
|
* SIGFILE defaults to FILE.sig. Exit 0 on success, 1 otherwise.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _POSIX_C_SOURCE 200809L
|
||||||
|
|
||||||
|
#include <getopt.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "log.h"
|
||||||
|
#include "sign.h"
|
||||||
|
|
||||||
|
#define USAGE \
|
||||||
|
"usage: gsign [-hv]\n" \
|
||||||
|
" gsign -G -p KEY.pub -s KEY.sec [-c COMMENT]\n" \
|
||||||
|
" gsign -S -s KEY.sec -m FILE [-x SIGFILE]\n" \
|
||||||
|
" gsign -V -p KEY.pub -m FILE [-x SIGFILE]\n"
|
||||||
|
|
||||||
|
static const struct option longopts[] = {
|
||||||
|
{ "help", no_argument, NULL, 'h' },
|
||||||
|
{ "version", no_argument, NULL, 'v' },
|
||||||
|
{ "generate", no_argument, NULL, 'G' },
|
||||||
|
{ "sign", no_argument, NULL, 'S' },
|
||||||
|
{ "verify", no_argument, NULL, 'V' },
|
||||||
|
{ "pubkey", required_argument, NULL, 'p' },
|
||||||
|
{ "seckey", required_argument, NULL, 's' },
|
||||||
|
{ "message", required_argument, NULL, 'm' },
|
||||||
|
{ "sig", required_argument, NULL, 'x' },
|
||||||
|
{ "comment", required_argument, NULL, 'c' },
|
||||||
|
{ NULL, 0, NULL, 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
static void
|
||||||
|
usage(void)
|
||||||
|
{
|
||||||
|
fprintf(stderr, USAGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
help(void)
|
||||||
|
{
|
||||||
|
printf("gsign: Make and check signify-compatible signatures\n");
|
||||||
|
printf(USAGE);
|
||||||
|
printf("\n");
|
||||||
|
printf("%-25s %s\n", "{-h --help}", "Show this message");
|
||||||
|
printf("%-25s %s\n", "{-v --version}", "Show the current version");
|
||||||
|
printf("%-25s %s\n", "{-G --generate}", "Generate a new key pair");
|
||||||
|
printf("%-25s %s\n", "{-S --sign}", "Sign a file");
|
||||||
|
printf("%-25s %s\n", "{-V --verify}", "Verify a file's signature");
|
||||||
|
printf("%-25s %s\n", "{-p --pubkey} KEY.pub", "Public key file");
|
||||||
|
printf("%-25s %s\n", "{-s --seckey} KEY.sec", "Secret key file");
|
||||||
|
printf("%-25s %s\n", "{-m --message} FILE", "File to sign or verify");
|
||||||
|
printf("%-25s %s\n", "{-x --sig} SIGFILE", "Signature file (default: FILE.sig)");
|
||||||
|
printf("%-25s %s\n", "{-c --comment} COMMENT", "Comment for a new key pair (default: gsign)");
|
||||||
|
printf("\n");
|
||||||
|
printf("This program is free software.\n");
|
||||||
|
printf("See the GNU GPL version 3 for details.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* "<what> <path> <problem>." about one file. */
|
||||||
|
static int
|
||||||
|
fail(const char *what, const char *path, int st)
|
||||||
|
{
|
||||||
|
const char *problem;
|
||||||
|
switch (st) {
|
||||||
|
case GL_SIGN_ERR_FORMAT: problem = "is malformed"; break;
|
||||||
|
case GL_SIGN_ERR_ENCRYPTED: problem = "is encrypted: sign with signify"; break;
|
||||||
|
case GL_SIGN_ERR_TOOBIG: problem = "is too large"; break;
|
||||||
|
case GL_SIGN_ERR_EXISTS: problem = "already exists"; break;
|
||||||
|
case GL_SIGN_ERR_WRITE: problem = "cannot be written"; break;
|
||||||
|
default: problem = "cannot be read"; break;
|
||||||
|
}
|
||||||
|
lg_printf(LG_ERR, "%s %s %s.", what, path, problem);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
char mode = 0;
|
||||||
|
const char *pub = NULL, *sec = NULL, *msg = NULL, *sig = NULL;
|
||||||
|
const char *comment = "gsign";
|
||||||
|
int c;
|
||||||
|
|
||||||
|
while ((c = getopt_long(argc, argv, "hvGSVp:s:m:x:c:", longopts, NULL)) != -1) {
|
||||||
|
switch (c) {
|
||||||
|
case 'h':
|
||||||
|
help();
|
||||||
|
return 0;
|
||||||
|
case 'v':
|
||||||
|
printf("v4.0.0\n");
|
||||||
|
return 0;
|
||||||
|
case 'G': case 'S': case 'V':
|
||||||
|
if (mode && mode != c) {
|
||||||
|
usage();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
mode = (char)c;
|
||||||
|
break;
|
||||||
|
case 'p': pub = optarg; break;
|
||||||
|
case 's': sec = optarg; break;
|
||||||
|
case 'm': msg = optarg; break;
|
||||||
|
case 'x': sig = optarg; break;
|
||||||
|
case 'c': comment = optarg; break;
|
||||||
|
default:
|
||||||
|
usage();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (optind != argc) {
|
||||||
|
usage();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
char sigbuf[PATH_MAX];
|
||||||
|
if (msg && !sig) {
|
||||||
|
if ((size_t)snprintf(sigbuf, sizeof sigbuf, "%s.sig", msg) >= sizeof sigbuf) {
|
||||||
|
lg_printf(LG_ERR, "Path too long: %s", msg);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
sig = sigbuf;
|
||||||
|
}
|
||||||
|
|
||||||
|
int st;
|
||||||
|
switch (mode) {
|
||||||
|
case 'G':
|
||||||
|
if (!pub || !sec || msg) {
|
||||||
|
usage();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
/* The library refuses these too (O_EXCL); this names which. */
|
||||||
|
struct stat sb;
|
||||||
|
if (lstat(sec, &sb) == 0)
|
||||||
|
return fail("Secret key", sec, GL_SIGN_ERR_EXISTS);
|
||||||
|
if (lstat(pub, &sb) == 0)
|
||||||
|
return fail("Public key", pub, GL_SIGN_ERR_EXISTS);
|
||||||
|
st = gl_sign_generate(pub, sec, comment);
|
||||||
|
if (st == GL_SIGN_ERR_FORMAT) {
|
||||||
|
lg_printf(LG_ERR, "Comment must be one line, at most %d characters.",
|
||||||
|
GL_SIGN_MAX_COMMENT - 11);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (st == GL_SIGN_ERR_RANDOM) {
|
||||||
|
lg_printf(LG_ERR, "Cannot get random bytes for a new key.");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (st != GL_SIGN_OK) {
|
||||||
|
lg_printf(LG_ERR, "Cannot write %s and %s.", pub, sec);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
lg_printf(LG_SUCCESS, "Wrote %s and %s.", pub, sec);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
case 'S':
|
||||||
|
if (!sec || !msg || pub) {
|
||||||
|
usage();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if ((st = gl_sign_check_seckey(sec)) != GL_SIGN_OK)
|
||||||
|
return fail("Secret key", sec, st);
|
||||||
|
st = gl_sign_file(sec, msg, sig);
|
||||||
|
if (st == GL_SIGN_ERR_WRITE)
|
||||||
|
return fail("Signature", sig, st);
|
||||||
|
if (st != GL_SIGN_OK)
|
||||||
|
return fail("File", msg, st);
|
||||||
|
lg_printf(LG_SUCCESS, "Signed %s: %s.", msg, sig);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
case 'V': {
|
||||||
|
if (!pub || !msg || sec) {
|
||||||
|
usage();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
gl_sign_pubkey_t pk;
|
||||||
|
gl_sign_sig_t sg;
|
||||||
|
if ((st = gl_sign_read_pubkey(pub, &pk)) != GL_SIGN_OK)
|
||||||
|
return fail("Public key", pub, st);
|
||||||
|
if ((st = gl_sign_read_sig(sig, &sg)) != GL_SIGN_OK)
|
||||||
|
return fail("Signature", sig, st);
|
||||||
|
st = gl_sign_verify_file(pub, msg, sig);
|
||||||
|
switch (st) {
|
||||||
|
case GL_SIGN_OK:
|
||||||
|
lg_printf(LG_SUCCESS, "Signature verified: %s.", msg);
|
||||||
|
return 0;
|
||||||
|
case GL_SIGN_ERR_KEYNUM:
|
||||||
|
lg_printf(LG_ERR, "%s was signed by a different key than %s.", msg, pub);
|
||||||
|
return 1;
|
||||||
|
case GL_SIGN_ERR_BAD:
|
||||||
|
lg_printf(LG_ERR, "Signature does not verify: %s.", msg);
|
||||||
|
return 1;
|
||||||
|
default:
|
||||||
|
return fail("File", msg, st);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
usage();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
+1476
-582
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -1,302 +0,0 @@
|
|||||||
--- istoreutils.c.orig 2026-06-01 19:43:00.493773073 +0000
|
|
||||||
+++ istoreutils.c.new 2026-06-01 19:43:00.573469330 +0000
|
|
||||||
@@ -21,6 +21,7 @@
|
|
||||||
#include "istoreutils.h"
|
|
||||||
#include "log.h"
|
|
||||||
#include "pkg.h"
|
|
||||||
+#include "transaction.h"
|
|
||||||
|
|
||||||
static const dir_t usr_index = { "/glacier/usr/index", 0700 };
|
|
||||||
static const dir_t sys_index = { "/glacier/sys/index", 0700 };
|
|
||||||
@@ -29,6 +30,7 @@
|
|
||||||
static const dir_t sys_store = { "/glacier/sys/store", 0700 };
|
|
||||||
|
|
||||||
static const dir_t usr_links = { "/glacier/usr/links", 0700 };
|
|
||||||
+static const dir_t sys_links = { "/glacier/sys/links", 0700 };
|
|
||||||
|
|
||||||
bool
|
|
||||||
gl_usr_istore_exists(index_store_t index_or_store, int uid)
|
|
||||||
@@ -253,6 +255,46 @@
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
+int
|
|
||||||
+gl_init_sys(bool isVerbose)
|
|
||||||
+{
|
|
||||||
+ const char *paths[] = {
|
|
||||||
+ sys_index.path,
|
|
||||||
+ sys_store.path,
|
|
||||||
+ sys_links.path,
|
|
||||||
+ };
|
|
||||||
+ mode_t modes[] = {
|
|
||||||
+ sys_index.mode,
|
|
||||||
+ sys_store.mode,
|
|
||||||
+ sys_links.mode,
|
|
||||||
+ };
|
|
||||||
+
|
|
||||||
+ for (int i = 0; i < 3; i++) {
|
|
||||||
+ if (isVerbose) { lg_printf(0, "Creating %s", paths[i]); }
|
|
||||||
+
|
|
||||||
+ if (mkdir(paths[i], modes[i]) == -1) {
|
|
||||||
+ switch (errno) {
|
|
||||||
+ case EEXIST:
|
|
||||||
+ break;
|
|
||||||
+ case EACCES:
|
|
||||||
+ lg_printf(2, "Cannot create %s: permission denied", paths[i]);
|
|
||||||
+ return 1;
|
|
||||||
+ case ENOSPC:
|
|
||||||
+ lg_printf(2, "Cannot create %s: no space left on device", paths[i]);
|
|
||||||
+ return 1;
|
|
||||||
+ case EROFS:
|
|
||||||
+ lg_printf(2, "Cannot create %s: read-only filesystem", paths[i]);
|
|
||||||
+ return 1;
|
|
||||||
+ default:
|
|
||||||
+ lg_printf(2, "Cannot create %s: mkdir failed", paths[i]);
|
|
||||||
+ return -1;
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ return 0;
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
static void
|
|
||||||
trim(char *s)
|
|
||||||
{
|
|
||||||
@@ -409,12 +451,11 @@
|
|
||||||
*/
|
|
||||||
|
|
||||||
int
|
|
||||||
-gl_rebuild_index(uid_t uid, const char *out_dir)
|
|
||||||
+gl_rebuild_index(gl_context_t *ctx)
|
|
||||||
{
|
|
||||||
- char store_path[PATH_MAX];
|
|
||||||
- snprintf(store_path, sizeof(store_path), "%s/%d", usr_store.path, uid);
|
|
||||||
+ if (!ctx) { return -1; }
|
|
||||||
|
|
||||||
- DIR *store_dir = opendir(store_path);
|
|
||||||
+ DIR *store_dir = opendir(ctx->store_path);
|
|
||||||
if (!store_dir) return -1;
|
|
||||||
|
|
||||||
/* Write to a new timestamped index file */
|
|
||||||
@@ -422,7 +463,8 @@
|
|
||||||
make_index_name(fname, sizeof(fname));
|
|
||||||
|
|
||||||
char new_index_path[PATH_MAX];
|
|
||||||
- snprintf(new_index_path, sizeof(new_index_path), "%s/%s", out_dir, fname);
|
|
||||||
+ snprintf(new_index_path, sizeof(new_index_path), "%s/%s",
|
|
||||||
+ ctx->index_path, fname);
|
|
||||||
|
|
||||||
FILE *out = fopen(new_index_path, "w");
|
|
||||||
if (!out) {
|
|
||||||
@@ -438,7 +480,7 @@
|
|
||||||
|
|
||||||
char repo_path[PATH_MAX];
|
|
||||||
snprintf(repo_path, sizeof(repo_path), "%s/%s",
|
|
||||||
- store_path, repo_ent->d_name);
|
|
||||||
+ ctx->store_path, repo_ent->d_name);
|
|
||||||
|
|
||||||
struct stat rst;
|
|
||||||
if (stat(repo_path, &rst) != 0 || !S_ISDIR(rst.st_mode)) {
|
|
||||||
@@ -476,14 +518,15 @@
|
|
||||||
if (!tmp_in) return -1;
|
|
||||||
|
|
||||||
char tmp_path[PATH_MAX];
|
|
||||||
- snprintf(tmp_path, sizeof(tmp_path), "%s/.index_tmp_XXXXXX", out_dir);
|
|
||||||
+ snprintf(tmp_path, sizeof(tmp_path), "%s/.index_tmp_XXXXXX",
|
|
||||||
+ ctx->index_path);
|
|
||||||
int tmp_fd = mkstemp(tmp_path);
|
|
||||||
if (tmp_fd < 0) { fclose(tmp_in); return -1; }
|
|
||||||
|
|
||||||
FILE *tmp_out = fdopen(tmp_fd, "w");
|
|
||||||
if (!tmp_out) { close(tmp_fd); fclose(tmp_in); return -1; }
|
|
||||||
|
|
||||||
- fprintf(tmp_out, "uid = %d\n", uid);
|
|
||||||
+ fprintf(tmp_out, "uid = %d\n", ctx->uid);
|
|
||||||
fprintf(tmp_out, "listed = %zu\n\n", listed);
|
|
||||||
|
|
||||||
char line[512];
|
|
||||||
@@ -494,15 +537,15 @@
|
|
||||||
fclose(tmp_out);
|
|
||||||
|
|
||||||
rename(tmp_path, new_index_path);
|
|
||||||
- chown(new_index_path, uid, (gid_t)-1);
|
|
||||||
+ chown(new_index_path, ctx->uid, (gid_t)-1);
|
|
||||||
|
|
||||||
/* Update the "current" symlink to point at the new index */
|
|
||||||
char link_path[PATH_MAX];
|
|
||||||
- snprintf(link_path, sizeof(link_path), "%s/current", out_dir);
|
|
||||||
+ snprintf(link_path, sizeof(link_path), "%s/current", ctx->index_path);
|
|
||||||
unlink(link_path);
|
|
||||||
|
|
||||||
if (symlink(fname, link_path) != 0) { return -1; }
|
|
||||||
- lchown(link_path, uid, (gid_t)-1);
|
|
||||||
+ lchown(link_path, ctx->uid, (gid_t)-1);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -672,10 +715,10 @@
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
-gl_unlink_pkg(const char *pkg_store_final, uid_t uid)
|
|
||||||
+gl_unlink_pkg(gl_context_t *ctx, const char *pkg_store_final)
|
|
||||||
{
|
|
||||||
char links_base[PATH_MAX];
|
|
||||||
- snprintf(links_base, sizeof(links_base), "%s/%d", usr_links.path, uid);
|
|
||||||
+ strncpy(links_base, ctx->links_path, PATH_MAX - 1);
|
|
||||||
|
|
||||||
size_t strip_len = strlen(pkg_store_final);
|
|
||||||
|
|
||||||
@@ -729,12 +772,14 @@
|
|
||||||
}
|
|
||||||
|
|
||||||
gl_remove_status_t
|
|
||||||
-gl_remove_pkg(const char *pkg_name, const char *pkg_repo, uid_t uid)
|
|
||||||
+gl_remove_pkg(gl_context_t *ctx, const char *pkg_name, const char *pkg_repo)
|
|
||||||
{
|
|
||||||
+ if (!ctx) { return GL_REMOVE_ERR_NOT_FOUND; }
|
|
||||||
+
|
|
||||||
/* find the package base directory in the store */
|
|
||||||
char pkg_store_base[PATH_MAX];
|
|
||||||
snprintf(pkg_store_base, sizeof(pkg_store_base),
|
|
||||||
- "%s/%d/%s/%s", usr_store.path, uid, pkg_repo, pkg_name);
|
|
||||||
+ "%s/%s/%s", ctx->store_path, pkg_repo, pkg_name);
|
|
||||||
|
|
||||||
struct stat st;
|
|
||||||
if (stat(pkg_store_base, &st) != 0 || !S_ISDIR(st.st_mode)) {
|
|
||||||
@@ -760,7 +805,7 @@
|
|
||||||
}
|
|
||||||
|
|
||||||
/* remove symlinks from links tree */
|
|
||||||
- if (gl_unlink_pkg(pkg_store_final, uid) != 0) {
|
|
||||||
+ if (gl_unlink_pkg(ctx, pkg_store_final) != 0) {
|
|
||||||
return GL_REMOVE_ERR_UNLINK;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -770,10 +815,7 @@
|
|
||||||
}
|
|
||||||
|
|
||||||
/* rebuild index */
|
|
||||||
- char index_dir[PATH_MAX];
|
|
||||||
- snprintf(index_dir, sizeof(index_dir), "%s/%d", usr_index.path, uid);
|
|
||||||
-
|
|
||||||
- if (gl_rebuild_index(uid, index_dir) != 0) {
|
|
||||||
+ if (gl_rebuild_index(ctx) != 0) {
|
|
||||||
return GL_REMOVE_ERR_INDEX;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -781,10 +823,10 @@
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
-gl_link_pkg(const char *pkg_store_final, uid_t uid)
|
|
||||||
+gl_link_pkg(gl_context_t *ctx, const char *pkg_store_final)
|
|
||||||
{
|
|
||||||
char links_base[PATH_MAX];
|
|
||||||
- snprintf(links_base, sizeof(links_base), "%s/%d", usr_links.path, uid);
|
|
||||||
+ strncpy(links_base, ctx->links_path, PATH_MAX - 1);
|
|
||||||
|
|
||||||
size_t strip_len = strlen(pkg_store_final);
|
|
||||||
|
|
||||||
@@ -854,7 +896,7 @@
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
- lchown(link_path, uid, (gid_t)-1);
|
|
||||||
+ lchown(link_path, ctx->uid, (gid_t)-1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -898,11 +940,10 @@
|
|
||||||
}
|
|
||||||
|
|
||||||
char
|
|
||||||
-*gl_find_pkg_repo(const char *pkg_name, uid_t uid)
|
|
||||||
+*gl_find_pkg_repo(gl_context_t *ctx, const char *pkg_name)
|
|
||||||
{
|
|
||||||
char store_path[PATH_MAX];
|
|
||||||
- snprintf(store_path, sizeof(store_path),
|
|
||||||
-"/glacier/usr/store/%u", uid);
|
|
||||||
+ strncpy(store_path, ctx->store_path, PATH_MAX - 1);
|
|
||||||
|
|
||||||
DIR *uid_dir = opendir(store_path);
|
|
||||||
if (!uid_dir) { return NULL; }
|
|
||||||
@@ -927,13 +968,12 @@
|
|
||||||
}
|
|
||||||
|
|
||||||
gl_repo_list_t
|
|
||||||
-gl_find_pkg_repos(const char *pkg_name, uid_t uid)
|
|
||||||
+gl_find_pkg_repos(gl_context_t *ctx, const char *pkg_name)
|
|
||||||
{
|
|
||||||
gl_repo_list_t result = { NULL, 0 };
|
|
||||||
|
|
||||||
char store_path[PATH_MAX];
|
|
||||||
- snprintf(store_path, sizeof(store_path),
|
|
||||||
- "/glacier/usr/store/%u", uid);
|
|
||||||
+ strncpy(store_path, ctx->store_path, PATH_MAX - 1);
|
|
||||||
|
|
||||||
DIR *uid_dir = opendir(store_path);
|
|
||||||
if (!uid_dir) { return result; }
|
|
||||||
@@ -1033,8 +1073,9 @@
|
|
||||||
}
|
|
||||||
|
|
||||||
gl_install_status_t
|
|
||||||
-gl_install_pkg(const char *gpkg_path, uid_t uid)
|
|
||||||
+gl_install_pkg(gl_context_t *ctx, const char *gpkg_path)
|
|
||||||
{
|
|
||||||
+ if (!ctx) { return GL_INSTALL_ERR_OPEN; }
|
|
||||||
char original_cwd[PATH_MAX];
|
|
||||||
if (getcwd(original_cwd, sizeof(original_cwd)) == NULL) {
|
|
||||||
return GL_INSTALL_ERR_OPEN;
|
|
||||||
@@ -1108,7 +1149,7 @@
|
|
||||||
|
|
||||||
/* construct the directory for the package in the store */
|
|
||||||
snprintf(pkg_store_base, sizeof(pkg_store_base),
|
|
||||||
- "%s/%d/%s/%s", usr_store.path, uid, pkg.pkg_repo, pkg.pkg_name);
|
|
||||||
+ "%s/%s/%s", ctx->store_path, pkg.pkg_repo, pkg.pkg_name);
|
|
||||||
|
|
||||||
snprintf(pkg_store_final, sizeof(pkg_store_final),
|
|
||||||
"%s/%s-%d.%d.%d", pkg_store_base, pkg.pkg_name,
|
|
||||||
@@ -1208,15 +1249,9 @@
|
|
||||||
archive_read_free(a2);
|
|
||||||
|
|
||||||
/* now the index will be updated */
|
|
||||||
-
|
|
||||||
- /* now the index will be updated */
|
|
||||||
- char index_dir[PATH_MAX];
|
|
||||||
- snprintf(index_dir, sizeof(index_dir),
|
|
||||||
- "%s/%d", usr_index.path, uid);
|
|
||||||
-
|
|
||||||
/* Resolve "current" symlink to find the actual index file to append to */
|
|
||||||
char current_link[PATH_MAX];
|
|
||||||
- snprintf(current_link, sizeof(current_link), "%s/current", index_dir);
|
|
||||||
+ snprintf(current_link, sizeof(current_link), "%s/current", ctx->index_path);
|
|
||||||
|
|
||||||
char current_target[PATH_MAX];
|
|
||||||
ssize_t len = readlink(current_link, current_target, sizeof(current_target) - 1);
|
|
||||||
@@ -1227,7 +1262,8 @@
|
|
||||||
current_target[len] = '\0';
|
|
||||||
|
|
||||||
char index_path[PATH_MAX];
|
|
||||||
- snprintf(index_path, sizeof(index_path), "%s/%s", index_dir, current_target);
|
|
||||||
+ snprintf(index_path, sizeof(index_path), "%s/%s",
|
|
||||||
+ ctx->index_path, current_target);
|
|
||||||
|
|
||||||
FILE *idx = fopen(index_path, "a");
|
|
||||||
if (!idx) {
|
|
||||||
@@ -1238,12 +1274,12 @@
|
|
||||||
fprintf(idx, "%s::%s\n", pkg.pkg_repo, pkg.pkg_name);
|
|
||||||
fclose(idx);
|
|
||||||
|
|
||||||
- if (gl_rebuild_index(uid, index_dir) != 0) {
|
|
||||||
+ if (gl_rebuild_index(ctx) != 0) {
|
|
||||||
gl_free_pkg(&pkg);
|
|
||||||
return GL_INSTALL_ERR_INDEX;
|
|
||||||
}
|
|
||||||
|
|
||||||
- if (gl_link_pkg(pkg_store_final, uid) != 0) {
|
|
||||||
+ if (gl_link_pkg(ctx, pkg_store_final) != 0) {
|
|
||||||
gl_free_pkg(&pkg);
|
|
||||||
return GL_INSTALL_ERR_EXTRACT;
|
|
||||||
}
|
|
||||||
+14
-26
@@ -5,6 +5,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include "pkg.h"
|
||||||
#include "transaction.h"
|
#include "transaction.h"
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@@ -24,12 +25,6 @@ typedef enum {
|
|||||||
}
|
}
|
||||||
gl_backup_status_t;
|
gl_backup_status_t;
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
GL_RESTORE_OK = 0,
|
|
||||||
GL_RESTORE_ERR_OPEN = 1,
|
|
||||||
GL_RESTORE_ERR_EXTRACT = 2
|
|
||||||
} gl_restore_status_t;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* GL_INSTALL_OK: installation successful
|
* GL_INSTALL_OK: installation successful
|
||||||
* GL_INSTALL_ERR_OPEN: unable to open .gpkg file
|
* GL_INSTALL_ERR_OPEN: unable to open .gpkg file
|
||||||
@@ -37,6 +32,9 @@ typedef enum {
|
|||||||
* GL_INSTALL_ERR_EXTRACT: unable to extract files
|
* GL_INSTALL_ERR_EXTRACT: unable to extract files
|
||||||
* GL_INSTALL_ERR_INDEX: unable to update index
|
* GL_INSTALL_ERR_INDEX: unable to update index
|
||||||
* GL_INSTALL_ERR_ALREADY_INSTALLED: package already installed
|
* GL_INSTALL_ERR_ALREADY_INSTALLED: package already installed
|
||||||
|
* GL_INSTALL_ERR_SCOPE: base-repo package under user scope
|
||||||
|
* GL_INSTALL_ERR_DEPS: unmet dependency or conflict (live context only;
|
||||||
|
* a staged install is checked at commit, GL_TXN_ERR_DEPS)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@@ -47,6 +45,8 @@ typedef enum {
|
|||||||
GL_INSTALL_ERR_INDEX = 4,
|
GL_INSTALL_ERR_INDEX = 4,
|
||||||
GL_INSTALL_ERR_ALREADY_INSTALLED = 5,
|
GL_INSTALL_ERR_ALREADY_INSTALLED = 5,
|
||||||
GL_INSTALL_SKIPPED = 6,
|
GL_INSTALL_SKIPPED = 6,
|
||||||
|
GL_INSTALL_ERR_SCOPE = 7,
|
||||||
|
GL_INSTALL_ERR_DEPS = 8, /* live context only; see deps.h */
|
||||||
}
|
}
|
||||||
gl_install_status_t;
|
gl_install_status_t;
|
||||||
|
|
||||||
@@ -55,35 +55,22 @@ typedef enum {
|
|||||||
GL_REMOVE_ERR_NOT_FOUND = 1,
|
GL_REMOVE_ERR_NOT_FOUND = 1,
|
||||||
GL_REMOVE_ERR_UNLINK = 2,
|
GL_REMOVE_ERR_UNLINK = 2,
|
||||||
GL_REMOVE_ERR_INDEX = 3,
|
GL_REMOVE_ERR_INDEX = 3,
|
||||||
|
GL_REMOVE_ERR_DEPS = 4, /* live context only; see deps.h */
|
||||||
} gl_remove_status_t;
|
} gl_remove_status_t;
|
||||||
|
|
||||||
struct gpkg_entry {
|
|
||||||
char *repo;
|
|
||||||
char *pkg;
|
|
||||||
char *ver;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct gindex {
|
|
||||||
int uid;
|
|
||||||
int listed;
|
|
||||||
struct gpkg_entry *entries;
|
|
||||||
size_t count;
|
|
||||||
};
|
|
||||||
|
|
||||||
bool gl_usr_istore_exists(index_store_t index_or_store, int uid);
|
bool gl_usr_istore_exists(index_store_t index_or_store, int uid);
|
||||||
bool gl_sys_istore_exists(index_store_t index_or_store);
|
int gl_usr_base_status(uid_t uid);
|
||||||
|
int gl_backup_pkg(gl_context_t *ctx, const char *repo, const char *name, const char *out_path);
|
||||||
|
int gl_prune_backups(const char *dir, int keep);
|
||||||
|
|
||||||
int gl_init_user(uid_t uid, bool isVerbose);
|
int gl_init_user(uid_t uid, bool isVerbose);
|
||||||
int gl_init_sys(bool isVerbose);
|
int gl_init_sys(bool isVerbose);
|
||||||
|
int gl_init_sys_at(const char *sysroot, bool isVerbose);
|
||||||
|
int gl_create_fs_tree(const char *root, bool isVerbose);
|
||||||
int gl_delete_user(uid_t uid, bool isVerbose);
|
int gl_delete_user(uid_t uid, bool isVerbose);
|
||||||
|
|
||||||
int gl_parse_index(struct gindex *idx, FILE *f);
|
|
||||||
void gl_free_index(struct gindex *idx);
|
|
||||||
|
|
||||||
int gl_rebuild_index(gl_context_t *ctx);
|
int gl_rebuild_index(gl_context_t *ctx);
|
||||||
|
|
||||||
char *gl_find_pkg_repo(gl_context_t *ctx, const char *pkg_name);
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char **repos;
|
char **repos;
|
||||||
size_t count;
|
size_t count;
|
||||||
@@ -95,9 +82,10 @@ void gl_free_repo_list(gl_repo_list_t *list);
|
|||||||
|
|
||||||
gl_backup_status_t gl_backup_istore(const char *tar_path, const char *glacier_root,
|
gl_backup_status_t gl_backup_istore(const char *tar_path, const char *glacier_root,
|
||||||
const char *uid);
|
const char *uid);
|
||||||
gl_restore_status_t gl_restore_istore(const char *tar_path, const char *glacier_root, const char *uid);
|
|
||||||
|
|
||||||
|
int gl_read_pkg_manifest(const char *gpkg_path, gl_pkg_t *pkg);
|
||||||
gl_install_status_t gl_install_pkg(gl_context_t *ctx, const char *gpkg_path);
|
gl_install_status_t gl_install_pkg(gl_context_t *ctx, const char *gpkg_path);
|
||||||
|
int gl_set_pkg_auto(gl_context_t *ctx, const char *repo, const char *name, bool automatic);
|
||||||
gl_remove_status_t gl_remove_pkg(gl_context_t *ctx, const char *pkg_name, const char *pkg_repo);
|
gl_remove_status_t gl_remove_pkg(gl_context_t *ctx, const char *pkg_name, const char *pkg_repo);
|
||||||
|
|
||||||
int gl_relink_store(gl_context_t *ctx);
|
int gl_relink_store(gl_context_t *ctx);
|
||||||
|
|||||||
@@ -1,101 +0,0 @@
|
|||||||
#ifndef ISTOREUTILS_H_
|
|
||||||
#define ISTOREUTILS_H_
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
INDEX,
|
|
||||||
STORE
|
|
||||||
}
|
|
||||||
index_store_t;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
GL_BACKUP_OK = 0,
|
|
||||||
GL_BACKUP_ERR_ALLOC = 1,
|
|
||||||
GL_BACKUP_ERR_OPEN = 2,
|
|
||||||
GL_BACKUP_ERR_ADD_INDEX = 3,
|
|
||||||
GL_BACKUP_ERR_ADD_STORE = 4,
|
|
||||||
GL_BACKUP_ERR_ADD_LINKS = 5,
|
|
||||||
GL_BACKUP_ERR_CLOSE = 6
|
|
||||||
}
|
|
||||||
gl_backup_status_t;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
GL_RESTORE_OK = 0,
|
|
||||||
GL_RESTORE_ERR_OPEN = 1,
|
|
||||||
GL_RESTORE_ERR_EXTRACT = 2
|
|
||||||
} gl_restore_status_t;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* GL_INSTALL_OK: installation successful
|
|
||||||
* GL_INSTALL_ERR_OPEN: unable to open .gpkg file
|
|
||||||
* GL_INSTALL_ERR_MANIFEST: manifest is missing or unparseable
|
|
||||||
* GL_INSTALL_ERR_EXTRACT: unable to extract files
|
|
||||||
* GL_INSTALL_ERR_INDEX: unable to update index
|
|
||||||
* GL_INSTALL_ERR_ALREADY_INSTALLED: package already installed
|
|
||||||
*/
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
GL_INSTALL_OK = 0,
|
|
||||||
GL_INSTALL_ERR_OPEN = 1,
|
|
||||||
GL_INSTALL_ERR_MANIFEST = 2,
|
|
||||||
GL_INSTALL_ERR_EXTRACT = 3,
|
|
||||||
GL_INSTALL_ERR_INDEX = 4,
|
|
||||||
GL_INSTALL_ERR_ALREADY_INSTALLED = 5,
|
|
||||||
GL_INSTALL_SKIPPED = 6,
|
|
||||||
}
|
|
||||||
gl_install_status_t;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
GL_REMOVE_OK = 0,
|
|
||||||
GL_REMOVE_ERR_NOT_FOUND = 1,
|
|
||||||
GL_REMOVE_ERR_UNLINK = 2,
|
|
||||||
GL_REMOVE_ERR_INDEX = 3,
|
|
||||||
} gl_remove_status_t;
|
|
||||||
|
|
||||||
struct gpkg_entry {
|
|
||||||
char *repo;
|
|
||||||
char *pkg;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct gindex {
|
|
||||||
int uid;
|
|
||||||
int listed;
|
|
||||||
struct gpkg_entry *entries;
|
|
||||||
size_t count;
|
|
||||||
};
|
|
||||||
|
|
||||||
bool gl_usr_istore_exists(index_store_t index_or_store, int uid);
|
|
||||||
bool gl_sys_istore_exists(index_store_t index_or_store);
|
|
||||||
|
|
||||||
int gl_init_user(uid_t uid, bool isVerbose);
|
|
||||||
int gl_delete_user(uid_t uid, bool isVerbose);
|
|
||||||
|
|
||||||
int gl_parse_index(struct gindex *idx, FILE *f);
|
|
||||||
void gl_free_index(struct gindex *idx);
|
|
||||||
|
|
||||||
int gl_rebuild_index(uid_t uid, const char *out_dir);
|
|
||||||
|
|
||||||
char *gl_find_pkg_repo(const char *pkg_name, uid_t uid);
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
char **repos;
|
|
||||||
size_t count;
|
|
||||||
}
|
|
||||||
gl_repo_list_t;
|
|
||||||
|
|
||||||
gl_repo_list_t gl_find_pkg_repos(const char *pkg_name, uid_t uid);
|
|
||||||
void gl_free_repo_list(gl_repo_list_t *list);
|
|
||||||
|
|
||||||
gl_backup_status_t gl_backup_istore(const char *tar_path, const char *glacier_root,
|
|
||||||
const char *uid);
|
|
||||||
gl_restore_status_t gl_restore_istore(const char *tar_path, const char *glacier_root, const char *uid);
|
|
||||||
|
|
||||||
gl_install_status_t gl_install_pkg(const char *gpkg_path, uid_t uid);
|
|
||||||
gl_remove_status_t gl_remove_pkg(const char *pkg_name, const char *pkg_repo, uid_t uid);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -8,19 +8,8 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <syslog.h>
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
#include "color.h"
|
#include "log.h"
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
LG_INFO,
|
|
||||||
LG_WARN,
|
|
||||||
LG_ERR,
|
|
||||||
LG_SUCCESS
|
|
||||||
}
|
|
||||||
loglevel_t;
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
supports_utf8(void)
|
supports_utf8(void)
|
||||||
@@ -34,26 +23,6 @@ supports_utf8(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Converts priority integer to string */
|
|
||||||
const char
|
|
||||||
*p2s(int priority)
|
|
||||||
{
|
|
||||||
switch (priority)
|
|
||||||
{
|
|
||||||
case LOG_EMERG: return "EMERG"; break;
|
|
||||||
case LOG_ALERT: return "ALERT"; break;
|
|
||||||
case LOG_CRIT: return "CRIT"; break;
|
|
||||||
case LOG_ERR: return "ERR"; break;
|
|
||||||
case LOG_WARNING: return "WARN"; break;
|
|
||||||
case LOG_NOTICE: return "NOTICE"; break;
|
|
||||||
case LOG_INFO: return "INFO"; break;
|
|
||||||
case LOG_DEBUG: return "DEBUG"; break;
|
|
||||||
default: return "UNKNOWN"; break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
lg_printf(loglevel_t loglevel, const char *fmt, ...)
|
lg_printf(loglevel_t loglevel, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
@@ -92,102 +61,23 @@ lg_printf(loglevel_t loglevel, const char *fmt, ...)
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
lg_printf_no_newline(loglevel_t loglevel, const char *fmt, ...)
|
|
||||||
{
|
|
||||||
const char *prefix;
|
|
||||||
|
|
||||||
int utf8_ok = supports_utf8();
|
|
||||||
|
|
||||||
switch (loglevel) {
|
|
||||||
case LG_INFO:
|
|
||||||
prefix = COL_BLUE "[i]" COL_RESET " ";
|
|
||||||
break;
|
|
||||||
case LG_WARN:
|
|
||||||
prefix = COL_YELLOW "[!]" COL_RESET " ";
|
|
||||||
break;
|
|
||||||
case LG_ERR:
|
|
||||||
prefix = COL_RED "[x]" COL_RESET " ";
|
|
||||||
break;
|
|
||||||
case LG_SUCCESS:
|
|
||||||
if (utf8_ok) {
|
|
||||||
prefix = COL_GREEN "[" "\xE2\x9C\x93" "]" COL_RESET " ";
|
|
||||||
} else {
|
|
||||||
prefix = COL_GREEN "[*]" COL_RESET " ";
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
prefix = "[?] ";
|
|
||||||
}
|
|
||||||
|
|
||||||
fputs(prefix, stdout);
|
|
||||||
|
|
||||||
va_list args;
|
|
||||||
va_start(args, fmt);
|
|
||||||
vprintf(fmt, args);
|
|
||||||
va_end(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
lg_syslog(int priority, const char *fmt, ...)
|
|
||||||
{
|
|
||||||
va_list args;
|
|
||||||
va_start(args, fmt);
|
|
||||||
vsyslog(priority, fmt, args);
|
|
||||||
va_end(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
lg_log(bool use_syslog, const char *logfile, int priority, const char *fmt, ...)
|
|
||||||
{
|
|
||||||
FILE *log = fopen(logfile, "a");
|
|
||||||
if (!log) {
|
|
||||||
perror("fopen");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
time_t now = time(NULL);
|
|
||||||
struct tm *t = localtime(&now);
|
|
||||||
|
|
||||||
char timestamp[20];
|
|
||||||
strftime(timestamp, sizeof(timestamp), "%Y-%m-%d %H:%M:%S", t);
|
|
||||||
|
|
||||||
fprintf(log, "[%s] [%s] ", timestamp, p2s(priority));
|
|
||||||
|
|
||||||
va_list args;
|
|
||||||
va_start(args, fmt);
|
|
||||||
vfprintf(log, fmt, args);
|
|
||||||
va_end(args);
|
|
||||||
|
|
||||||
fputc('\n', log);
|
|
||||||
fflush(log);
|
|
||||||
|
|
||||||
if (use_syslog) {
|
|
||||||
va_list args2;
|
|
||||||
va_start(args2, fmt);
|
|
||||||
vsyslog(priority, fmt, args2);
|
|
||||||
va_end(args2);
|
|
||||||
fclose(log);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
fclose(log);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
lg_gpkg_help(int argc, char *argv[])
|
lg_gpkg_help(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
(void)argc;
|
(void)argc;
|
||||||
|
|
||||||
printf("%s: Install, update, and remove packages\n", argv[0]);
|
printf("%s: Install, update, and remove packages\n", argv[0]);
|
||||||
printf("usage: %s [-hv] [-fux PKG] [-V]\n", argv[0]);
|
printf("usage: %s [-hv] [-y] [-flux PKG] [-OSV]\n", argv[0]);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("%-25s %s\n", "{-h --help}", "Show this message");
|
printf("%-25s %s\n", "{-h --help}", "Show this message");
|
||||||
printf("%-25s %s\n", "{-v --version}", "Show the current version");
|
printf("%-25s %s\n", "{-v --version}", "Show the current version");
|
||||||
printf("%-25s %s\n", "{-f --merge} PKG...", "Merge a package into the index and store");
|
printf("%-25s %s\n", "{-l --local} FILE...", "Install local package files");
|
||||||
printf("%-25s %s\n", "{-u --update} PKG...", "Upgrade a merged package");
|
printf("%-25s %s\n", "{-f --merge} PKG...", "Install packages from a remote repository");
|
||||||
printf("%-25s %s\n", "{-x --remove} PKG...", "Remove a package from the index and store");
|
printf("%-25s %s\n", "{-u --update} [PKG...]", "Update system or individual packages");
|
||||||
|
printf("%-25s %s\n", "{-x --remove} PKG...", "Remove installed packages");
|
||||||
|
printf("%-25s %s\n", "{-y --refresh}", "Fetch and verify the remote repositories' indexes");
|
||||||
|
printf("%-25s %s\n", "{-O --overwrite}", "Allow Glacier to overwrite existing files");
|
||||||
|
printf("%-25s %s\n", "{-S --skip-installed}", "Skip packages that are already up to date");
|
||||||
printf("%-25s %s\n", "{-V --verbose}", "Log events more verbosely");
|
printf("%-25s %s\n", "{-V --verbose}", "Log events more verbosely");
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("This program is free software.\n");
|
printf("This program is free software.\n");
|
||||||
@@ -200,17 +90,24 @@ lg_syspkg_help(int argc, char *argv[])
|
|||||||
(void)argc;
|
(void)argc;
|
||||||
|
|
||||||
printf("%s: Manage the system package index\n", argv[0]);
|
printf("%s: Manage the system package index\n", argv[0]);
|
||||||
printf("usage: %s [-hv] [-fux PKG]\n", argv[0]);
|
printf("usage: %s [-hv] [-n] [-y] [-flux PKG] [-OSV] [-R DIR] [--strict]\n", argv[0]);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("{-h}\tShow this message\n"
|
printf("%-25s %s\n", "{-h --help}", "Show this message");
|
||||||
"{-v}\tShow the current version\n"
|
printf("%-25s %s\n", "{-v --version}", "Show the current version");
|
||||||
"{-f} PKG...\tMerge a package into the user index\n"
|
printf("%-25s %s\n", "{-n --new}", "Create the system index and store");
|
||||||
"{-u} PKG...\tUpgrade a merged package\n"
|
printf("%-25s %s\n", "{-l --local} PKG...", "Install a local package into the system index and store");
|
||||||
"{-x} PKG...\tRemove a merged package\n"
|
printf("%-25s %s\n", "{-f --merge} PKG...", "Install packages from a remote repository");
|
||||||
"\n"
|
printf("%-25s %s\n", "{-u --update} [PKG...]", "Update system or individual packages");
|
||||||
"This program is free software.\n"
|
printf("%-25s %s\n", "{-x --remove} PKG...", "Remove a package from the system index and store");
|
||||||
"See the GNU GPL version 3 for details.\n"
|
printf("%-25s %s\n", "{-y --refresh}", "Fetch and verify the remote repositories' indexes");
|
||||||
);
|
printf("%-25s %s\n", "{-O --overwrite}", "Allow Glacier to overwrite existing files");
|
||||||
|
printf("%-25s %s\n", "{-S --skip-installed}", "Skip packages that are already up to date");
|
||||||
|
printf("%-25s %s\n", "{-V --verbose}", "Log events more verbosely");
|
||||||
|
printf("%-25s %s\n", "{-R --root} DIR", "Operate on the system installed under DIR (implies --strict)");
|
||||||
|
printf("%-25s %s\n", "{--strict}", "Refuse the whole transaction if any path can't be linked");
|
||||||
|
printf("\n");
|
||||||
|
printf("This program is free software.\n");
|
||||||
|
printf("See the GNU GPL version 3 for details.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -219,12 +116,12 @@ lg_gstore_help(int argc, char *argv[])
|
|||||||
(void)argc;
|
(void)argc;
|
||||||
|
|
||||||
printf("%s: Manage Glacier packages indexes/stores\n", argv[0]);
|
printf("%s: Manage Glacier packages indexes/stores\n", argv[0]);
|
||||||
printf("usage: %s [-hv] [-snbx UID] [-V]\n", argv[0]);
|
printf("usage: %s [-hv] [-n [UID]] [-sbx UID] [-V]\n", argv[0]);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("%-25s %s\n", "{-h --help}", "Show this message");
|
printf("%-25s %s\n", "{-h --help}", "Show this message");
|
||||||
printf("%-25s %s\n", "{-v --version}", "Show the current version");
|
printf("%-25s %s\n", "{-v --version}", "Show the current version");
|
||||||
printf("%-25s %s\n", "{-s --sync} UID", "Sync UID's store with their index");
|
printf("%-25s %s\n", "{-s --sync} UID", "Sync UID's store with their index");
|
||||||
printf("%-25s %s\n", "{-n --new} UID", "Create new store and index for UID");
|
printf("%-25s %s\n", "{-n --new} [UID]", "Create store and index for UID (as root), or for yourself (doas gstore -n)");
|
||||||
printf("%-25s %s\n", "{-b --backup} UID OUTFILE", "Create tar backup of UID's index and store at OUTFILE");
|
printf("%-25s %s\n", "{-b --backup} UID OUTFILE", "Create tar backup of UID's index and store at OUTFILE");
|
||||||
printf("%-25s %s\n", "{-x --delete} UID", "Delete UID's store and index");
|
printf("%-25s %s\n", "{-x --delete} UID", "Delete UID's store and index");
|
||||||
printf("%-25s %s\n", "{-V --verbose}", "Log events more verbosely");
|
printf("%-25s %s\n", "{-V --verbose}", "Log events more verbosely");
|
||||||
|
|||||||
@@ -7,9 +7,6 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdbool.h>
|
|
||||||
#include <syslog.h>
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
#include "color.h"
|
#include "color.h"
|
||||||
|
|
||||||
@@ -26,13 +23,13 @@ typedef enum
|
|||||||
}
|
}
|
||||||
loglevel_t;
|
loglevel_t;
|
||||||
|
|
||||||
int supports_utf8(void);
|
void lg_printf(loglevel_t loglevel, const char *fmt, ...)
|
||||||
const char *p2s(int priority);
|
__attribute__((format(printf, 2, 3)));
|
||||||
|
|
||||||
void lg_printf(loglevel_t loglevel, const char *fmt, ...);
|
/* The CLIs' -h output. */
|
||||||
void lg_printf_no_newline(loglevel_t loglevel, const char *fmt, ...);
|
void lg_gpkg_help(int argc, char *argv[]);
|
||||||
void lg_syslog(int priority, const char *fmt, ...);
|
void lg_syspkg_help(int argc, char *argv[]);
|
||||||
void lg_log(bool use_syslog, FILE *logfile, int priority, const char *fmt, ...);
|
void lg_gstore_help(int argc, char *argv[]);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,95 +0,0 @@
|
|||||||
#define _POSIX_C_SOURcE 200809L
|
|
||||||
#define _DEFAULT_SOURCE
|
|
||||||
#define _XOPEN_SOURCE 700
|
|
||||||
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#define MAX_LINE 1024
|
|
||||||
|
|
||||||
static char
|
|
||||||
*trim(char *s) {
|
|
||||||
char *end;
|
|
||||||
while (isspace((unsigned char)*s)) { s++; }
|
|
||||||
if (*s == 0) { return s; }
|
|
||||||
end = s + strlen(s) - 1;
|
|
||||||
while (end > s && isspace((unsigned char)*end)) { *end-- = 0; }
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char
|
|
||||||
*expand(char *value)
|
|
||||||
{
|
|
||||||
size_t cap = strlen(value) + 1;
|
|
||||||
char *buffer = malloc(cap);
|
|
||||||
if (!buffer) { return NULL; }
|
|
||||||
char *out = buffer;
|
|
||||||
|
|
||||||
char *p = value;
|
|
||||||
|
|
||||||
while (*p) {
|
|
||||||
if (*p == '$') {
|
|
||||||
p++;
|
|
||||||
char var[128], *vp = var;
|
|
||||||
while (*p && (isalnum((unsigned char)*p) || *p == '_')) {
|
|
||||||
*vp++ = *p++;
|
|
||||||
}
|
|
||||||
|
|
||||||
*vp = '\0';
|
|
||||||
char *val = getenv(var);
|
|
||||||
if (val) {
|
|
||||||
size_t len = strlen(val);
|
|
||||||
size_t used = (size_t)(out - buffer);
|
|
||||||
if (used + len + 1 > cap) {
|
|
||||||
cap = used + len + 1;
|
|
||||||
buffer = realloc(buffer, cap);
|
|
||||||
if (!buffer) { return NULL; }
|
|
||||||
out = buffer + used;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(out, val, len);
|
|
||||||
out += len;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
*out++ = *p++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
*out = '\0';
|
|
||||||
return buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
parse_makeconf(const char *filename)
|
|
||||||
{
|
|
||||||
FILE *make_conf = fopen(filename, "r");
|
|
||||||
if (!make_conf) {
|
|
||||||
perror("fopen");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
char line[MAX_LINE];
|
|
||||||
while (fgets(line, sizeof(line), make_conf)) {
|
|
||||||
char *p = trim(line);
|
|
||||||
if (*p == '\0' || *p == '#') { continue; }
|
|
||||||
|
|
||||||
char *eq = strchr(p, '=');
|
|
||||||
if (!eq) { continue; }
|
|
||||||
|
|
||||||
*eq = '\0';
|
|
||||||
char *key = trim(p);
|
|
||||||
char *val = trim(eq + 1);
|
|
||||||
|
|
||||||
char *expanded = expand(val);
|
|
||||||
if (expanded) {
|
|
||||||
setenv(key, expanded, 1);
|
|
||||||
free(expanded);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose(make_conf);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,167 @@
|
|||||||
|
Monocypher as a whole is dual-licensed. Choose whichever licence you
|
||||||
|
want from the two licences listed below.
|
||||||
|
|
||||||
|
The first licence is a regular 2-clause BSD licence. The second licence
|
||||||
|
is the CC-0 from Creative Commons. It is intended to release Monocypher
|
||||||
|
to the public domain. The BSD licence serves as a fallback option.
|
||||||
|
|
||||||
|
See the individual files for specific information about who contributed
|
||||||
|
to what file during which years. See below for special notes.
|
||||||
|
|
||||||
|
Licence 1 (2-clause BSD)
|
||||||
|
------------------------
|
||||||
|
|
||||||
|
Copyright (c) 2017-2023, Loup Vaillant
|
||||||
|
Copyright (c) 2017-2019, Michael Savage
|
||||||
|
Copyright (c) 2017-2023, Fabio Scotoni
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are
|
||||||
|
met:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the
|
||||||
|
distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
|
||||||
|
Licence 2 (CC-0)
|
||||||
|
----------------
|
||||||
|
|
||||||
|
> CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
|
||||||
|
> LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
|
||||||
|
> ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
|
||||||
|
> INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
|
||||||
|
> REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
|
||||||
|
> PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
|
||||||
|
> THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
|
||||||
|
> HEREUNDER.
|
||||||
|
|
||||||
|
### Statement of Purpose
|
||||||
|
|
||||||
|
The laws of most jurisdictions throughout the world automatically confer
|
||||||
|
exclusive Copyright and Related Rights (defined below) upon the creator
|
||||||
|
and subsequent owner(s) (each and all, an "owner") of an original work
|
||||||
|
of authorship and/or a database (each, a "Work").
|
||||||
|
|
||||||
|
Certain owners wish to permanently relinquish those rights to a Work for
|
||||||
|
the purpose of contributing to a commons of creative, cultural and
|
||||||
|
scientific works ("Commons") that the public can reliably and without
|
||||||
|
fear of later claims of infringement build upon, modify, incorporate in
|
||||||
|
other works, reuse and redistribute as freely as possible in any form
|
||||||
|
whatsoever and for any purposes, including without limitation commercial
|
||||||
|
purposes. These owners may contribute to the Commons to promote the
|
||||||
|
ideal of a free culture and the further production of creative, cultural
|
||||||
|
and scientific works, or to gain reputation or greater distribution for
|
||||||
|
their Work in part through the use and efforts of others.
|
||||||
|
|
||||||
|
For these and/or other purposes and motivations, and without any
|
||||||
|
expectation of additional consideration or compensation, the person
|
||||||
|
associating CC0 with a Work (the "Affirmer"), to the extent that he or
|
||||||
|
she is an owner of Copyright and Related Rights in the Work, voluntarily
|
||||||
|
elects to apply CC0 to the Work and publicly distribute the Work under
|
||||||
|
its terms, with knowledge of his or her Copyright and Related Rights in
|
||||||
|
the Work and the meaning and intended legal effect of CC0 on those
|
||||||
|
rights.
|
||||||
|
|
||||||
|
1. **Copyright and Related Rights.** A Work made available under CC0 may
|
||||||
|
be protected by copyright and related or neighboring rights
|
||||||
|
("Copyright and Related Rights"). Copyright and Related Rights
|
||||||
|
include, but are not limited to, the following:
|
||||||
|
|
||||||
|
- the right to reproduce, adapt, distribute, perform, display,
|
||||||
|
communicate, and translate a Work;
|
||||||
|
- moral rights retained by the original author(s) and/or
|
||||||
|
performer(s); publicity and privacy rights pertaining to a person's
|
||||||
|
image or likeness depicted in a Work;
|
||||||
|
- rights protecting against unfair competition in regards to a Work,
|
||||||
|
subject to the limitations in paragraph 4(a), below;
|
||||||
|
- rights protecting the extraction, dissemination, use and reuse of
|
||||||
|
data in a Work;
|
||||||
|
- database rights (such as those arising under Directive 96/9/EC of
|
||||||
|
the European Parliament and of the Council of 11 March 1996 on the
|
||||||
|
legal protection of databases, and under any national
|
||||||
|
implementation thereof, including any amended or successor version
|
||||||
|
of such directive); and
|
||||||
|
- other similar, equivalent or corresponding rights throughout the
|
||||||
|
world based on applicable law or treaty, and any national
|
||||||
|
implementations thereof.
|
||||||
|
|
||||||
|
2. **Waiver.** To the greatest extent permitted by, but not in
|
||||||
|
contravention of, applicable law, Affirmer hereby overtly, fully,
|
||||||
|
permanently, irrevocably and unconditionally waives, abandons, and
|
||||||
|
surrenders all of Affirmer's Copyright and Related Rights and
|
||||||
|
associated claims and causes of action, whether now known or unknown
|
||||||
|
(including existing as well as future claims and causes of action),
|
||||||
|
in the Work (i) in all territories worldwide, (ii) for the maximum
|
||||||
|
duration provided by applicable law or treaty (including future time
|
||||||
|
extensions), (iii) in any current or future medium and for any number
|
||||||
|
of copies, and (iv) for any purpose whatsoever, including without
|
||||||
|
limitation commercial, advertising or promotional purposes (the
|
||||||
|
"Waiver"). Affirmer makes the Waiver for the benefit of each member
|
||||||
|
of the public at large and to the detriment of Affirmer's heirs and
|
||||||
|
successors, fully intending that such Waiver shall not be subject to
|
||||||
|
revocation, rescission, cancellation, termination, or any other legal
|
||||||
|
or equitable action to disrupt the quiet enjoyment of the Work by the
|
||||||
|
public as contemplated by Affirmer's express Statement of Purpose.
|
||||||
|
|
||||||
|
3. **Public License Fallback.** Should any part of the Waiver for any
|
||||||
|
reason be judged legally invalid or ineffective under applicable law,
|
||||||
|
then the Waiver shall be preserved to the maximum extent permitted
|
||||||
|
taking into account Affirmer's express Statement of Purpose. In
|
||||||
|
addition, to the extent the Waiver is so judged Affirmer hereby
|
||||||
|
grants to each affected person a royalty-free, non transferable, non
|
||||||
|
sublicensable, non exclusive, irrevocable and unconditional license
|
||||||
|
to exercise Affirmer's Copyright and Related Rights in the Work (i)
|
||||||
|
in all territories worldwide, (ii) for the maximum duration provided
|
||||||
|
by applicable law or treaty (including future time extensions), (iii)
|
||||||
|
in any current or future medium and for any number of copies, and
|
||||||
|
(iv) for any purpose whatsoever, including without limitation
|
||||||
|
commercial, advertising or promotional purposes (the "License"). The
|
||||||
|
License shall be deemed effective as of the date CC0 was applied by
|
||||||
|
Affirmer to the Work. Should any part of the License for any reason
|
||||||
|
be judged legally invalid or ineffective under applicable law, such
|
||||||
|
partial invalidity or ineffectiveness shall not invalidate the
|
||||||
|
remainder of the License, and in such case Affirmer hereby affirms
|
||||||
|
that he or she will not (i) exercise any of his or her remaining
|
||||||
|
Copyright and Related Rights in the Work or (ii) assert any
|
||||||
|
associated claims and causes of action with respect to the Work, in
|
||||||
|
either case contrary to Affirmer's express Statement of Purpose.
|
||||||
|
|
||||||
|
4. **Limitations and Disclaimers.**
|
||||||
|
|
||||||
|
- No trademark or patent rights held by Affirmer are waived,
|
||||||
|
abandoned, surrendered, licensed or otherwise affected by this
|
||||||
|
document.
|
||||||
|
- Affirmer offers the Work as-is and makes no representations or
|
||||||
|
warranties of any kind concerning the Work, express, implied,
|
||||||
|
statutory or otherwise, including without limitation warranties of
|
||||||
|
title, merchantability, fitness for a particular purpose, non
|
||||||
|
infringement, or the absence of latent or other defects, accuracy,
|
||||||
|
or the present or absence of errors, whether or not discoverable,
|
||||||
|
all to the greatest extent permissible under applicable law.
|
||||||
|
- Affirmer disclaims responsibility for clearing rights of other
|
||||||
|
persons that may apply to the Work or any use thereof, including
|
||||||
|
without limitation any person's Copyright and Related Rights in the
|
||||||
|
Work. Further, Affirmer disclaims responsibility for obtaining any
|
||||||
|
necessary consents, permissions or other rights required for any
|
||||||
|
use of the Work.
|
||||||
|
- Affirmer understands and acknowledges that Creative Commons is not
|
||||||
|
a party to this document and has no duty or obligation with respect
|
||||||
|
to this CC0 or use of the Work.
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
Monocypher 4.0.3, vendored UNMODIFIED (REPO_DESIGN.txt section 1a).
|
||||||
|
|
||||||
|
monocypher.c, monocypher.h from src/
|
||||||
|
monocypher-ed25519.c, monocypher-ed25519.h from src/optional/
|
||||||
|
LICENCE.md BSD-2-Clause or CC0
|
||||||
|
|
||||||
|
Source: monocypher-4.0.3.tar.gz, fetched 2026-10-06 from both
|
||||||
|
https://github.com/LoupVaillant/Monocypher/releases/download/4.0.3/
|
||||||
|
and https://monocypher.org/download/ ; identical, sha512
|
||||||
|
40904ada5c7ee4f7741733e38b69a30a4b0561cbffba5ffe7c2dce16136d540251ec0d9056ff606510d3b5b708fb8a40db7e0870d4a0b2dc17ba2bfb880f8965
|
||||||
|
|
||||||
|
Only Ed25519 (with its SHA-512) is used, through src/sign.c. Never
|
||||||
|
edit these files: replace them with a newer release, and update this
|
||||||
|
note.
|
||||||
@@ -0,0 +1,503 @@
|
|||||||
|
// Monocypher version 4.0.3
|
||||||
|
//
|
||||||
|
// This file is dual-licensed. Choose whichever licence you want from
|
||||||
|
// the two licences listed below.
|
||||||
|
//
|
||||||
|
// The first licence is a regular 2-clause BSD licence. The second licence
|
||||||
|
// is the CC-0 from Creative Commons. It is intended to release Monocypher
|
||||||
|
// to the public domain. The BSD licence serves as a fallback option.
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: BSD-2-Clause OR CC0-1.0
|
||||||
|
//
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Copyright (c) 2017-2019, Loup Vaillant
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions are
|
||||||
|
// met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright
|
||||||
|
// notice, this list of conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
// notice, this list of conditions and the following disclaimer in the
|
||||||
|
// documentation and/or other materials provided with the
|
||||||
|
// distribution.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Written in 2017-2019 by Loup Vaillant
|
||||||
|
//
|
||||||
|
// To the extent possible under law, the author(s) have dedicated all copyright
|
||||||
|
// and related neighboring rights to this software to the public domain
|
||||||
|
// worldwide. This software is distributed without any warranty.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the CC0 Public Domain Dedication along
|
||||||
|
// with this software. If not, see
|
||||||
|
// <https://creativecommons.org/publicdomain/zero/1.0/>
|
||||||
|
|
||||||
|
#include "monocypher-ed25519.h"
|
||||||
|
|
||||||
|
#ifdef MONOCYPHER_CPP_NAMESPACE
|
||||||
|
namespace MONOCYPHER_CPP_NAMESPACE {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/////////////////
|
||||||
|
/// Utilities ///
|
||||||
|
/////////////////
|
||||||
|
#define FOR(i, min, max) for (size_t i = min; i < max; i++)
|
||||||
|
#define COPY(dst, src, size) FOR(_i_, 0, size) (dst)[_i_] = (src)[_i_]
|
||||||
|
#define ZERO(buf, size) FOR(_i_, 0, size) (buf)[_i_] = 0
|
||||||
|
#define WIPE_CTX(ctx) crypto_wipe(ctx , sizeof(*(ctx)))
|
||||||
|
#define WIPE_BUFFER(buffer) crypto_wipe(buffer, sizeof(buffer))
|
||||||
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b))
|
||||||
|
typedef uint8_t u8;
|
||||||
|
typedef uint64_t u64;
|
||||||
|
|
||||||
|
// Returns the smallest positive integer y such that
|
||||||
|
// (x + y) % pow_2 == 0
|
||||||
|
// Basically, it's how many bytes we need to add to "align" x.
|
||||||
|
// Only works when pow_2 is a power of 2.
|
||||||
|
// Note: we use ~x+1 instead of -x to avoid compiler warnings
|
||||||
|
static size_t align(size_t x, size_t pow_2)
|
||||||
|
{
|
||||||
|
return (~x + 1) & (pow_2 - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static u64 load64_be(const u8 s[8])
|
||||||
|
{
|
||||||
|
return((u64)s[0] << 56)
|
||||||
|
| ((u64)s[1] << 48)
|
||||||
|
| ((u64)s[2] << 40)
|
||||||
|
| ((u64)s[3] << 32)
|
||||||
|
| ((u64)s[4] << 24)
|
||||||
|
| ((u64)s[5] << 16)
|
||||||
|
| ((u64)s[6] << 8)
|
||||||
|
| (u64)s[7];
|
||||||
|
}
|
||||||
|
|
||||||
|
static void store64_be(u8 out[8], u64 in)
|
||||||
|
{
|
||||||
|
out[0] = (u8)(in >> 56);
|
||||||
|
out[1] = (u8)(in >> 48);
|
||||||
|
out[2] = (u8)(in >> 40);
|
||||||
|
out[3] = (u8)(in >> 32);
|
||||||
|
out[4] = (u8)(in >> 24);
|
||||||
|
out[5] = (u8)(in >> 16);
|
||||||
|
out[6] = (u8)(in >> 8);
|
||||||
|
out[7] = (u8) in ;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void load64_be_buf (u64 *dst, const u8 *src, size_t size) {
|
||||||
|
FOR(i, 0, size) { dst[i] = load64_be(src + i*8); }
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////
|
||||||
|
/// SHA 512 ///
|
||||||
|
///////////////
|
||||||
|
static u64 rot(u64 x, int c ) { return (x >> c) | (x << (64 - c)); }
|
||||||
|
static u64 ch (u64 x, u64 y, u64 z) { return (x & y) ^ (~x & z); }
|
||||||
|
static u64 maj(u64 x, u64 y, u64 z) { return (x & y) ^ ( x & z) ^ (y & z); }
|
||||||
|
static u64 big_sigma0(u64 x) { return rot(x, 28) ^ rot(x, 34) ^ rot(x, 39); }
|
||||||
|
static u64 big_sigma1(u64 x) { return rot(x, 14) ^ rot(x, 18) ^ rot(x, 41); }
|
||||||
|
static u64 lit_sigma0(u64 x) { return rot(x, 1) ^ rot(x, 8) ^ (x >> 7); }
|
||||||
|
static u64 lit_sigma1(u64 x) { return rot(x, 19) ^ rot(x, 61) ^ (x >> 6); }
|
||||||
|
|
||||||
|
static const u64 K[80] = {
|
||||||
|
0x428a2f98d728ae22,0x7137449123ef65cd,0xb5c0fbcfec4d3b2f,0xe9b5dba58189dbbc,
|
||||||
|
0x3956c25bf348b538,0x59f111f1b605d019,0x923f82a4af194f9b,0xab1c5ed5da6d8118,
|
||||||
|
0xd807aa98a3030242,0x12835b0145706fbe,0x243185be4ee4b28c,0x550c7dc3d5ffb4e2,
|
||||||
|
0x72be5d74f27b896f,0x80deb1fe3b1696b1,0x9bdc06a725c71235,0xc19bf174cf692694,
|
||||||
|
0xe49b69c19ef14ad2,0xefbe4786384f25e3,0x0fc19dc68b8cd5b5,0x240ca1cc77ac9c65,
|
||||||
|
0x2de92c6f592b0275,0x4a7484aa6ea6e483,0x5cb0a9dcbd41fbd4,0x76f988da831153b5,
|
||||||
|
0x983e5152ee66dfab,0xa831c66d2db43210,0xb00327c898fb213f,0xbf597fc7beef0ee4,
|
||||||
|
0xc6e00bf33da88fc2,0xd5a79147930aa725,0x06ca6351e003826f,0x142929670a0e6e70,
|
||||||
|
0x27b70a8546d22ffc,0x2e1b21385c26c926,0x4d2c6dfc5ac42aed,0x53380d139d95b3df,
|
||||||
|
0x650a73548baf63de,0x766a0abb3c77b2a8,0x81c2c92e47edaee6,0x92722c851482353b,
|
||||||
|
0xa2bfe8a14cf10364,0xa81a664bbc423001,0xc24b8b70d0f89791,0xc76c51a30654be30,
|
||||||
|
0xd192e819d6ef5218,0xd69906245565a910,0xf40e35855771202a,0x106aa07032bbd1b8,
|
||||||
|
0x19a4c116b8d2d0c8,0x1e376c085141ab53,0x2748774cdf8eeb99,0x34b0bcb5e19b48a8,
|
||||||
|
0x391c0cb3c5c95a63,0x4ed8aa4ae3418acb,0x5b9cca4f7763e373,0x682e6ff3d6b2b8a3,
|
||||||
|
0x748f82ee5defb2fc,0x78a5636f43172f60,0x84c87814a1f0ab72,0x8cc702081a6439ec,
|
||||||
|
0x90befffa23631e28,0xa4506cebde82bde9,0xbef9a3f7b2c67915,0xc67178f2e372532b,
|
||||||
|
0xca273eceea26619c,0xd186b8c721c0c207,0xeada7dd6cde0eb1e,0xf57d4f7fee6ed178,
|
||||||
|
0x06f067aa72176fba,0x0a637dc5a2c898a6,0x113f9804bef90dae,0x1b710b35131c471b,
|
||||||
|
0x28db77f523047d84,0x32caab7b40c72493,0x3c9ebe0a15c9bebc,0x431d67c49c100d4c,
|
||||||
|
0x4cc5d4becb3e42b6,0x597f299cfc657e2a,0x5fcb6fab3ad6faec,0x6c44198c4a475817
|
||||||
|
};
|
||||||
|
|
||||||
|
static void sha512_compress(crypto_sha512_ctx *ctx)
|
||||||
|
{
|
||||||
|
u64 a = ctx->hash[0]; u64 b = ctx->hash[1];
|
||||||
|
u64 c = ctx->hash[2]; u64 d = ctx->hash[3];
|
||||||
|
u64 e = ctx->hash[4]; u64 f = ctx->hash[5];
|
||||||
|
u64 g = ctx->hash[6]; u64 h = ctx->hash[7];
|
||||||
|
|
||||||
|
FOR (j, 0, 16) {
|
||||||
|
u64 in = K[j] + ctx->input[j];
|
||||||
|
u64 t1 = big_sigma1(e) + ch (e, f, g) + h + in;
|
||||||
|
u64 t2 = big_sigma0(a) + maj(a, b, c);
|
||||||
|
h = g; g = f; f = e; e = d + t1;
|
||||||
|
d = c; c = b; b = a; a = t1 + t2;
|
||||||
|
}
|
||||||
|
size_t i16 = 0;
|
||||||
|
FOR(i, 1, 5) {
|
||||||
|
i16 += 16;
|
||||||
|
FOR (j, 0, 16) {
|
||||||
|
ctx->input[j] += lit_sigma1(ctx->input[(j- 2) & 15]);
|
||||||
|
ctx->input[j] += lit_sigma0(ctx->input[(j-15) & 15]);
|
||||||
|
ctx->input[j] += ctx->input[(j- 7) & 15];
|
||||||
|
u64 in = K[i16 + j] + ctx->input[j];
|
||||||
|
u64 t1 = big_sigma1(e) + ch (e, f, g) + h + in;
|
||||||
|
u64 t2 = big_sigma0(a) + maj(a, b, c);
|
||||||
|
h = g; g = f; f = e; e = d + t1;
|
||||||
|
d = c; c = b; b = a; a = t1 + t2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx->hash[0] += a; ctx->hash[1] += b;
|
||||||
|
ctx->hash[2] += c; ctx->hash[3] += d;
|
||||||
|
ctx->hash[4] += e; ctx->hash[5] += f;
|
||||||
|
ctx->hash[6] += g; ctx->hash[7] += h;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write 1 input byte
|
||||||
|
static void sha512_set_input(crypto_sha512_ctx *ctx, u8 input)
|
||||||
|
{
|
||||||
|
size_t word = ctx->input_idx >> 3;
|
||||||
|
size_t byte = ctx->input_idx & 7;
|
||||||
|
ctx->input[word] |= (u64)input << (8 * (7 - byte));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Increment a 128-bit "word".
|
||||||
|
static void sha512_incr(u64 x[2], u64 y)
|
||||||
|
{
|
||||||
|
x[1] += y;
|
||||||
|
if (x[1] < y) {
|
||||||
|
x[0]++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void crypto_sha512_init(crypto_sha512_ctx *ctx)
|
||||||
|
{
|
||||||
|
ctx->hash[0] = 0x6a09e667f3bcc908;
|
||||||
|
ctx->hash[1] = 0xbb67ae8584caa73b;
|
||||||
|
ctx->hash[2] = 0x3c6ef372fe94f82b;
|
||||||
|
ctx->hash[3] = 0xa54ff53a5f1d36f1;
|
||||||
|
ctx->hash[4] = 0x510e527fade682d1;
|
||||||
|
ctx->hash[5] = 0x9b05688c2b3e6c1f;
|
||||||
|
ctx->hash[6] = 0x1f83d9abfb41bd6b;
|
||||||
|
ctx->hash[7] = 0x5be0cd19137e2179;
|
||||||
|
ctx->input_size[0] = 0;
|
||||||
|
ctx->input_size[1] = 0;
|
||||||
|
ctx->input_idx = 0;
|
||||||
|
ZERO(ctx->input, 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
void crypto_sha512_update(crypto_sha512_ctx *ctx,
|
||||||
|
const u8 *message, size_t message_size)
|
||||||
|
{
|
||||||
|
// Avoid undefined NULL pointer increments with empty messages
|
||||||
|
if (message_size == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Align ourselves with word boundaries
|
||||||
|
if ((ctx->input_idx & 7) != 0) {
|
||||||
|
size_t nb_bytes = MIN(align(ctx->input_idx, 8), message_size);
|
||||||
|
FOR (i, 0, nb_bytes) {
|
||||||
|
sha512_set_input(ctx, message[i]);
|
||||||
|
ctx->input_idx++;
|
||||||
|
}
|
||||||
|
message += nb_bytes;
|
||||||
|
message_size -= nb_bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Align ourselves with block boundaries
|
||||||
|
if ((ctx->input_idx & 127) != 0) {
|
||||||
|
size_t nb_words = MIN(align(ctx->input_idx, 128), message_size) >> 3;
|
||||||
|
load64_be_buf(ctx->input + (ctx->input_idx >> 3), message, nb_words);
|
||||||
|
ctx->input_idx += nb_words << 3;
|
||||||
|
message += nb_words << 3;
|
||||||
|
message_size -= nb_words << 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compress block if needed
|
||||||
|
if (ctx->input_idx == 128) {
|
||||||
|
sha512_incr(ctx->input_size, 1024); // size is in bits
|
||||||
|
sha512_compress(ctx);
|
||||||
|
ctx->input_idx = 0;
|
||||||
|
ZERO(ctx->input, 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process the message block by block
|
||||||
|
FOR (i, 0, message_size >> 7) { // number of blocks
|
||||||
|
load64_be_buf(ctx->input, message, 16);
|
||||||
|
sha512_incr(ctx->input_size, 1024); // size is in bits
|
||||||
|
sha512_compress(ctx);
|
||||||
|
ctx->input_idx = 0;
|
||||||
|
ZERO(ctx->input, 16);
|
||||||
|
message += 128;
|
||||||
|
}
|
||||||
|
message_size &= 127;
|
||||||
|
|
||||||
|
if (message_size != 0) {
|
||||||
|
// Remaining words
|
||||||
|
size_t nb_words = message_size >> 3;
|
||||||
|
load64_be_buf(ctx->input, message, nb_words);
|
||||||
|
ctx->input_idx += nb_words << 3;
|
||||||
|
message += nb_words << 3;
|
||||||
|
message_size -= nb_words << 3;
|
||||||
|
|
||||||
|
// Remaining bytes
|
||||||
|
FOR (i, 0, message_size) {
|
||||||
|
sha512_set_input(ctx, message[i]);
|
||||||
|
ctx->input_idx++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void crypto_sha512_final(crypto_sha512_ctx *ctx, u8 hash[64])
|
||||||
|
{
|
||||||
|
// Add padding bit
|
||||||
|
if (ctx->input_idx == 0) {
|
||||||
|
ZERO(ctx->input, 16);
|
||||||
|
}
|
||||||
|
sha512_set_input(ctx, 128);
|
||||||
|
|
||||||
|
// Update size
|
||||||
|
sha512_incr(ctx->input_size, ctx->input_idx * 8);
|
||||||
|
|
||||||
|
// Compress penultimate block (if any)
|
||||||
|
if (ctx->input_idx > 111) {
|
||||||
|
sha512_compress(ctx);
|
||||||
|
ZERO(ctx->input, 14);
|
||||||
|
}
|
||||||
|
// Compress last block
|
||||||
|
ctx->input[14] = ctx->input_size[0];
|
||||||
|
ctx->input[15] = ctx->input_size[1];
|
||||||
|
sha512_compress(ctx);
|
||||||
|
|
||||||
|
// Copy hash to output (big endian)
|
||||||
|
FOR (i, 0, 8) {
|
||||||
|
store64_be(hash + i*8, ctx->hash[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
WIPE_CTX(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
void crypto_sha512(u8 hash[64], const u8 *message, size_t message_size)
|
||||||
|
{
|
||||||
|
crypto_sha512_ctx ctx;
|
||||||
|
crypto_sha512_init (&ctx);
|
||||||
|
crypto_sha512_update(&ctx, message, message_size);
|
||||||
|
crypto_sha512_final (&ctx, hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////
|
||||||
|
/// HMAC SHA 512 ///
|
||||||
|
////////////////////
|
||||||
|
void crypto_sha512_hmac_init(crypto_sha512_hmac_ctx *ctx,
|
||||||
|
const u8 *key, size_t key_size)
|
||||||
|
{
|
||||||
|
// hash key if it is too long
|
||||||
|
if (key_size > 128) {
|
||||||
|
crypto_sha512(ctx->key, key, key_size);
|
||||||
|
key = ctx->key;
|
||||||
|
key_size = 64;
|
||||||
|
}
|
||||||
|
// Compute inner key: padded key XOR 0x36
|
||||||
|
FOR (i, 0, key_size) { ctx->key[i] = key[i] ^ 0x36; }
|
||||||
|
FOR (i, key_size, 128) { ctx->key[i] = 0x36; }
|
||||||
|
// Start computing inner hash
|
||||||
|
crypto_sha512_init (&ctx->ctx);
|
||||||
|
crypto_sha512_update(&ctx->ctx, ctx->key, 128);
|
||||||
|
}
|
||||||
|
|
||||||
|
void crypto_sha512_hmac_update(crypto_sha512_hmac_ctx *ctx,
|
||||||
|
const u8 *message, size_t message_size)
|
||||||
|
{
|
||||||
|
crypto_sha512_update(&ctx->ctx, message, message_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void crypto_sha512_hmac_final(crypto_sha512_hmac_ctx *ctx, u8 hmac[64])
|
||||||
|
{
|
||||||
|
// Finish computing inner hash
|
||||||
|
crypto_sha512_final(&ctx->ctx, hmac);
|
||||||
|
// Compute outer key: padded key XOR 0x5c
|
||||||
|
FOR (i, 0, 128) {
|
||||||
|
ctx->key[i] ^= 0x36 ^ 0x5c;
|
||||||
|
}
|
||||||
|
// Compute outer hash
|
||||||
|
crypto_sha512_init (&ctx->ctx);
|
||||||
|
crypto_sha512_update(&ctx->ctx, ctx->key , 128);
|
||||||
|
crypto_sha512_update(&ctx->ctx, hmac, 64);
|
||||||
|
crypto_sha512_final (&ctx->ctx, hmac); // outer hash
|
||||||
|
WIPE_CTX(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
void crypto_sha512_hmac(u8 hmac[64], const u8 *key, size_t key_size,
|
||||||
|
const u8 *message, size_t message_size)
|
||||||
|
{
|
||||||
|
crypto_sha512_hmac_ctx ctx;
|
||||||
|
crypto_sha512_hmac_init (&ctx, key, key_size);
|
||||||
|
crypto_sha512_hmac_update(&ctx, message, message_size);
|
||||||
|
crypto_sha512_hmac_final (&ctx, hmac);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////
|
||||||
|
/// HKDF SHA 512 ///
|
||||||
|
////////////////////
|
||||||
|
void crypto_sha512_hkdf_expand(u8 *okm, size_t okm_size,
|
||||||
|
const u8 *prk, size_t prk_size,
|
||||||
|
const u8 *info, size_t info_size)
|
||||||
|
{
|
||||||
|
int not_first = 0;
|
||||||
|
u8 ctr = 1;
|
||||||
|
u8 blk[64];
|
||||||
|
|
||||||
|
while (okm_size > 0) {
|
||||||
|
size_t out_size = MIN(okm_size, sizeof(blk));
|
||||||
|
|
||||||
|
crypto_sha512_hmac_ctx ctx;
|
||||||
|
crypto_sha512_hmac_init(&ctx, prk , prk_size);
|
||||||
|
if (not_first) {
|
||||||
|
// For some reason HKDF uses some kind of CBC mode.
|
||||||
|
// For some reason CTR mode alone wasn't enough.
|
||||||
|
// Like what, they didn't trust HMAC in 2010? Really??
|
||||||
|
crypto_sha512_hmac_update(&ctx, blk , sizeof(blk));
|
||||||
|
}
|
||||||
|
crypto_sha512_hmac_update(&ctx, info, info_size);
|
||||||
|
crypto_sha512_hmac_update(&ctx, &ctr, 1);
|
||||||
|
crypto_sha512_hmac_final(&ctx, blk);
|
||||||
|
|
||||||
|
COPY(okm, blk, out_size);
|
||||||
|
|
||||||
|
not_first = 1;
|
||||||
|
okm += out_size;
|
||||||
|
okm_size -= out_size;
|
||||||
|
ctr++;
|
||||||
|
}
|
||||||
|
WIPE_BUFFER(blk);
|
||||||
|
}
|
||||||
|
|
||||||
|
void crypto_sha512_hkdf(u8 *okm , size_t okm_size,
|
||||||
|
const u8 *ikm , size_t ikm_size,
|
||||||
|
const u8 *salt, size_t salt_size,
|
||||||
|
const u8 *info, size_t info_size)
|
||||||
|
{
|
||||||
|
// Extract
|
||||||
|
u8 prk[64];
|
||||||
|
crypto_sha512_hmac(prk, salt, salt_size, ikm, ikm_size);
|
||||||
|
|
||||||
|
// Expand
|
||||||
|
crypto_sha512_hkdf_expand(okm, okm_size, prk, sizeof(prk), info, info_size);
|
||||||
|
|
||||||
|
WIPE_BUFFER(prk);
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////
|
||||||
|
/// Ed25519 ///
|
||||||
|
///////////////
|
||||||
|
void crypto_ed25519_key_pair(u8 secret_key[64], u8 public_key[32], u8 seed[32])
|
||||||
|
{
|
||||||
|
u8 a[64];
|
||||||
|
COPY(a, seed, 32); // a[ 0..31] = seed
|
||||||
|
crypto_wipe(seed, 32);
|
||||||
|
COPY(secret_key, a, 32); // secret key = seed
|
||||||
|
crypto_sha512(a, a, 32); // a[ 0..31] = scalar
|
||||||
|
crypto_eddsa_trim_scalar(a, a); // a[ 0..31] = trimmed scalar
|
||||||
|
crypto_eddsa_scalarbase(public_key, a); // public key = [trimmed scalar]B
|
||||||
|
COPY(secret_key + 32, public_key, 32); // secret key includes public half
|
||||||
|
WIPE_BUFFER(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void hash_reduce(u8 h[32],
|
||||||
|
const u8 *a, size_t a_size,
|
||||||
|
const u8 *b, size_t b_size,
|
||||||
|
const u8 *c, size_t c_size,
|
||||||
|
const u8 *d, size_t d_size)
|
||||||
|
{
|
||||||
|
u8 hash[64];
|
||||||
|
crypto_sha512_ctx ctx;
|
||||||
|
crypto_sha512_init (&ctx);
|
||||||
|
crypto_sha512_update(&ctx, a, a_size);
|
||||||
|
crypto_sha512_update(&ctx, b, b_size);
|
||||||
|
crypto_sha512_update(&ctx, c, c_size);
|
||||||
|
crypto_sha512_update(&ctx, d, d_size);
|
||||||
|
crypto_sha512_final (&ctx, hash);
|
||||||
|
crypto_eddsa_reduce(h, hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ed25519_dom_sign(u8 signature[64], const u8 secret_key[64],
|
||||||
|
const u8 *dom, size_t dom_size,
|
||||||
|
const u8 *message, size_t message_size)
|
||||||
|
{
|
||||||
|
u8 a[64]; // secret scalar and prefix
|
||||||
|
u8 r[32]; // secret deterministic "random" nonce
|
||||||
|
u8 h[32]; // publically verifiable hash of the message (not wiped)
|
||||||
|
u8 R[32]; // first half of the signature (allows overlapping inputs)
|
||||||
|
const u8 *pk = secret_key + 32;
|
||||||
|
|
||||||
|
crypto_sha512(a, secret_key, 32);
|
||||||
|
crypto_eddsa_trim_scalar(a, a);
|
||||||
|
hash_reduce(r, dom, dom_size, a + 32, 32, message, message_size, 0, 0);
|
||||||
|
crypto_eddsa_scalarbase(R, r);
|
||||||
|
hash_reduce(h, dom, dom_size, R, 32, pk, 32, message, message_size);
|
||||||
|
COPY(signature, R, 32);
|
||||||
|
crypto_eddsa_mul_add(signature + 32, h, a, r);
|
||||||
|
|
||||||
|
WIPE_BUFFER(a);
|
||||||
|
WIPE_BUFFER(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
void crypto_ed25519_sign(u8 signature [64], const u8 secret_key[64],
|
||||||
|
const u8 *message, size_t message_size)
|
||||||
|
{
|
||||||
|
ed25519_dom_sign(signature, secret_key, 0, 0, message, message_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
int crypto_ed25519_check(const u8 signature[64], const u8 public_key[32],
|
||||||
|
const u8 *msg, size_t msg_size)
|
||||||
|
{
|
||||||
|
u8 h_ram[32];
|
||||||
|
hash_reduce(h_ram, signature, 32, public_key, 32, msg, msg_size, 0, 0);
|
||||||
|
return crypto_eddsa_check_equation(signature, public_key, h_ram);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const u8 domain[34] = "SigEd25519 no Ed25519 collisions\1";
|
||||||
|
|
||||||
|
void crypto_ed25519_ph_sign(uint8_t signature[64], const uint8_t secret_key[64],
|
||||||
|
const uint8_t message_hash[64])
|
||||||
|
{
|
||||||
|
ed25519_dom_sign(signature, secret_key, domain, sizeof(domain),
|
||||||
|
message_hash, 64);
|
||||||
|
}
|
||||||
|
|
||||||
|
int crypto_ed25519_ph_check(const uint8_t sig[64], const uint8_t pk[32],
|
||||||
|
const uint8_t msg_hash[64])
|
||||||
|
{
|
||||||
|
u8 h_ram[32];
|
||||||
|
hash_reduce(h_ram, domain, sizeof(domain), sig, 32, pk, 32, msg_hash, 64);
|
||||||
|
return crypto_eddsa_check_equation(sig, pk, h_ram);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef MONOCYPHER_CPP_NAMESPACE
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,140 @@
|
|||||||
|
// Monocypher version 4.0.3
|
||||||
|
//
|
||||||
|
// This file is dual-licensed. Choose whichever licence you want from
|
||||||
|
// the two licences listed below.
|
||||||
|
//
|
||||||
|
// The first licence is a regular 2-clause BSD licence. The second licence
|
||||||
|
// is the CC-0 from Creative Commons. It is intended to release Monocypher
|
||||||
|
// to the public domain. The BSD licence serves as a fallback option.
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: BSD-2-Clause OR CC0-1.0
|
||||||
|
//
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Copyright (c) 2017-2019, Loup Vaillant
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions are
|
||||||
|
// met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright
|
||||||
|
// notice, this list of conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
// notice, this list of conditions and the following disclaimer in the
|
||||||
|
// documentation and/or other materials provided with the
|
||||||
|
// distribution.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Written in 2017-2019 by Loup Vaillant
|
||||||
|
//
|
||||||
|
// To the extent possible under law, the author(s) have dedicated all copyright
|
||||||
|
// and related neighboring rights to this software to the public domain
|
||||||
|
// worldwide. This software is distributed without any warranty.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the CC0 Public Domain Dedication along
|
||||||
|
// with this software. If not, see
|
||||||
|
// <https://creativecommons.org/publicdomain/zero/1.0/>
|
||||||
|
|
||||||
|
#ifndef ED25519_H
|
||||||
|
#define ED25519_H
|
||||||
|
|
||||||
|
#include "monocypher.h"
|
||||||
|
|
||||||
|
#ifdef MONOCYPHER_CPP_NAMESPACE
|
||||||
|
namespace MONOCYPHER_CPP_NAMESPACE {
|
||||||
|
#elif defined(__cplusplus)
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
////////////////////////
|
||||||
|
/// Type definitions ///
|
||||||
|
////////////////////////
|
||||||
|
|
||||||
|
// Do not rely on the size or content on any of those types,
|
||||||
|
// they may change without notice.
|
||||||
|
typedef struct {
|
||||||
|
uint64_t hash[8];
|
||||||
|
uint64_t input[16];
|
||||||
|
uint64_t input_size[2];
|
||||||
|
size_t input_idx;
|
||||||
|
} crypto_sha512_ctx;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t key[128];
|
||||||
|
crypto_sha512_ctx ctx;
|
||||||
|
} crypto_sha512_hmac_ctx;
|
||||||
|
|
||||||
|
|
||||||
|
// SHA 512
|
||||||
|
// -------
|
||||||
|
void crypto_sha512_init (crypto_sha512_ctx *ctx);
|
||||||
|
void crypto_sha512_update(crypto_sha512_ctx *ctx,
|
||||||
|
const uint8_t *message, size_t message_size);
|
||||||
|
void crypto_sha512_final (crypto_sha512_ctx *ctx, uint8_t hash[64]);
|
||||||
|
void crypto_sha512(uint8_t hash[64],
|
||||||
|
const uint8_t *message, size_t message_size);
|
||||||
|
|
||||||
|
// SHA 512 HMAC
|
||||||
|
// ------------
|
||||||
|
void crypto_sha512_hmac_init(crypto_sha512_hmac_ctx *ctx,
|
||||||
|
const uint8_t *key, size_t key_size);
|
||||||
|
void crypto_sha512_hmac_update(crypto_sha512_hmac_ctx *ctx,
|
||||||
|
const uint8_t *message, size_t message_size);
|
||||||
|
void crypto_sha512_hmac_final(crypto_sha512_hmac_ctx *ctx, uint8_t hmac[64]);
|
||||||
|
void crypto_sha512_hmac(uint8_t hmac[64],
|
||||||
|
const uint8_t *key , size_t key_size,
|
||||||
|
const uint8_t *message, size_t message_size);
|
||||||
|
|
||||||
|
// SHA 512 HKDF
|
||||||
|
// ------------
|
||||||
|
void crypto_sha512_hkdf_expand(uint8_t *okm, size_t okm_size,
|
||||||
|
const uint8_t *prk, size_t prk_size,
|
||||||
|
const uint8_t *info, size_t info_size);
|
||||||
|
void crypto_sha512_hkdf(uint8_t *okm , size_t okm_size,
|
||||||
|
const uint8_t *ikm , size_t ikm_size,
|
||||||
|
const uint8_t *salt, size_t salt_size,
|
||||||
|
const uint8_t *info, size_t info_size);
|
||||||
|
|
||||||
|
// Ed25519
|
||||||
|
// -------
|
||||||
|
// Signatures (EdDSA with curve25519 + SHA-512)
|
||||||
|
// --------------------------------------------
|
||||||
|
void crypto_ed25519_key_pair(uint8_t secret_key[64],
|
||||||
|
uint8_t public_key[32],
|
||||||
|
uint8_t seed[32]);
|
||||||
|
void crypto_ed25519_sign(uint8_t signature [64],
|
||||||
|
const uint8_t secret_key[64],
|
||||||
|
const uint8_t *message, size_t message_size);
|
||||||
|
int crypto_ed25519_check(const uint8_t signature [64],
|
||||||
|
const uint8_t public_key[32],
|
||||||
|
const uint8_t *message, size_t message_size);
|
||||||
|
|
||||||
|
// Pre-hash variants
|
||||||
|
void crypto_ed25519_ph_sign(uint8_t signature [64],
|
||||||
|
const uint8_t secret_key [64],
|
||||||
|
const uint8_t message_hash[64]);
|
||||||
|
int crypto_ed25519_ph_check(const uint8_t signature [64],
|
||||||
|
const uint8_t public_key [32],
|
||||||
|
const uint8_t message_hash[64]);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // ED25519_H
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,321 @@
|
|||||||
|
// Monocypher version 4.0.3
|
||||||
|
//
|
||||||
|
// This file is dual-licensed. Choose whichever licence you want from
|
||||||
|
// the two licences listed below.
|
||||||
|
//
|
||||||
|
// The first licence is a regular 2-clause BSD licence. The second licence
|
||||||
|
// is the CC-0 from Creative Commons. It is intended to release Monocypher
|
||||||
|
// to the public domain. The BSD licence serves as a fallback option.
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: BSD-2-Clause OR CC0-1.0
|
||||||
|
//
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Copyright (c) 2017-2019, Loup Vaillant
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions are
|
||||||
|
// met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright
|
||||||
|
// notice, this list of conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
// notice, this list of conditions and the following disclaimer in the
|
||||||
|
// documentation and/or other materials provided with the
|
||||||
|
// distribution.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Written in 2017-2019 by Loup Vaillant
|
||||||
|
//
|
||||||
|
// To the extent possible under law, the author(s) have dedicated all copyright
|
||||||
|
// and related neighboring rights to this software to the public domain
|
||||||
|
// worldwide. This software is distributed without any warranty.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the CC0 Public Domain Dedication along
|
||||||
|
// with this software. If not, see
|
||||||
|
// <https://creativecommons.org/publicdomain/zero/1.0/>
|
||||||
|
|
||||||
|
#ifndef MONOCYPHER_H
|
||||||
|
#define MONOCYPHER_H
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#ifdef MONOCYPHER_CPP_NAMESPACE
|
||||||
|
namespace MONOCYPHER_CPP_NAMESPACE {
|
||||||
|
#elif defined(__cplusplus)
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Constant time comparisons
|
||||||
|
// -------------------------
|
||||||
|
|
||||||
|
// Return 0 if a and b are equal, -1 otherwise
|
||||||
|
int crypto_verify16(const uint8_t a[16], const uint8_t b[16]);
|
||||||
|
int crypto_verify32(const uint8_t a[32], const uint8_t b[32]);
|
||||||
|
int crypto_verify64(const uint8_t a[64], const uint8_t b[64]);
|
||||||
|
|
||||||
|
|
||||||
|
// Erase sensitive data
|
||||||
|
// --------------------
|
||||||
|
void crypto_wipe(void *secret, size_t size);
|
||||||
|
|
||||||
|
|
||||||
|
// Authenticated encryption
|
||||||
|
// ------------------------
|
||||||
|
void crypto_aead_lock(uint8_t *cipher_text,
|
||||||
|
uint8_t mac [16],
|
||||||
|
const uint8_t key [32],
|
||||||
|
const uint8_t nonce[24],
|
||||||
|
const uint8_t *ad, size_t ad_size,
|
||||||
|
const uint8_t *plain_text, size_t text_size);
|
||||||
|
int crypto_aead_unlock(uint8_t *plain_text,
|
||||||
|
const uint8_t mac [16],
|
||||||
|
const uint8_t key [32],
|
||||||
|
const uint8_t nonce[24],
|
||||||
|
const uint8_t *ad, size_t ad_size,
|
||||||
|
const uint8_t *cipher_text, size_t text_size);
|
||||||
|
|
||||||
|
// Authenticated stream
|
||||||
|
// --------------------
|
||||||
|
typedef struct {
|
||||||
|
uint64_t counter;
|
||||||
|
uint8_t key[32];
|
||||||
|
uint8_t nonce[8];
|
||||||
|
} crypto_aead_ctx;
|
||||||
|
|
||||||
|
void crypto_aead_init_x(crypto_aead_ctx *ctx,
|
||||||
|
const uint8_t key[32], const uint8_t nonce[24]);
|
||||||
|
void crypto_aead_init_djb(crypto_aead_ctx *ctx,
|
||||||
|
const uint8_t key[32], const uint8_t nonce[8]);
|
||||||
|
void crypto_aead_init_ietf(crypto_aead_ctx *ctx,
|
||||||
|
const uint8_t key[32], const uint8_t nonce[12]);
|
||||||
|
|
||||||
|
void crypto_aead_write(crypto_aead_ctx *ctx,
|
||||||
|
uint8_t *cipher_text,
|
||||||
|
uint8_t mac[16],
|
||||||
|
const uint8_t *ad , size_t ad_size,
|
||||||
|
const uint8_t *plain_text, size_t text_size);
|
||||||
|
int crypto_aead_read(crypto_aead_ctx *ctx,
|
||||||
|
uint8_t *plain_text,
|
||||||
|
const uint8_t mac[16],
|
||||||
|
const uint8_t *ad , size_t ad_size,
|
||||||
|
const uint8_t *cipher_text, size_t text_size);
|
||||||
|
|
||||||
|
|
||||||
|
// General purpose hash (BLAKE2b)
|
||||||
|
// ------------------------------
|
||||||
|
|
||||||
|
// Direct interface
|
||||||
|
void crypto_blake2b(uint8_t *hash, size_t hash_size,
|
||||||
|
const uint8_t *message, size_t message_size);
|
||||||
|
|
||||||
|
void crypto_blake2b_keyed(uint8_t *hash, size_t hash_size,
|
||||||
|
const uint8_t *key, size_t key_size,
|
||||||
|
const uint8_t *message, size_t message_size);
|
||||||
|
|
||||||
|
// Incremental interface
|
||||||
|
typedef struct {
|
||||||
|
// Do not rely on the size or contents of this type,
|
||||||
|
// for they may change without notice.
|
||||||
|
uint64_t hash[8];
|
||||||
|
uint64_t input_offset[2];
|
||||||
|
uint64_t input[16];
|
||||||
|
size_t input_idx;
|
||||||
|
size_t hash_size;
|
||||||
|
} crypto_blake2b_ctx;
|
||||||
|
|
||||||
|
void crypto_blake2b_init(crypto_blake2b_ctx *ctx, size_t hash_size);
|
||||||
|
void crypto_blake2b_keyed_init(crypto_blake2b_ctx *ctx, size_t hash_size,
|
||||||
|
const uint8_t *key, size_t key_size);
|
||||||
|
void crypto_blake2b_update(crypto_blake2b_ctx *ctx,
|
||||||
|
const uint8_t *message, size_t message_size);
|
||||||
|
void crypto_blake2b_final(crypto_blake2b_ctx *ctx, uint8_t *hash);
|
||||||
|
|
||||||
|
|
||||||
|
// Password key derivation (Argon2)
|
||||||
|
// --------------------------------
|
||||||
|
#define CRYPTO_ARGON2_D 0
|
||||||
|
#define CRYPTO_ARGON2_I 1
|
||||||
|
#define CRYPTO_ARGON2_ID 2
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint32_t algorithm; // Argon2d, Argon2i, Argon2id
|
||||||
|
uint32_t nb_blocks; // memory hardness, >= 8 * nb_lanes
|
||||||
|
uint32_t nb_passes; // CPU hardness, >= 1 (>= 3 recommended for Argon2i)
|
||||||
|
uint32_t nb_lanes; // parallelism level (single threaded anyway)
|
||||||
|
} crypto_argon2_config;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
const uint8_t *pass;
|
||||||
|
const uint8_t *salt;
|
||||||
|
uint32_t pass_size;
|
||||||
|
uint32_t salt_size; // 16 bytes recommended
|
||||||
|
} crypto_argon2_inputs;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
const uint8_t *key; // may be NULL if no key
|
||||||
|
const uint8_t *ad; // may be NULL if no additional data
|
||||||
|
uint32_t key_size; // 0 if no key (32 bytes recommended otherwise)
|
||||||
|
uint32_t ad_size; // 0 if no additional data
|
||||||
|
} crypto_argon2_extras;
|
||||||
|
|
||||||
|
extern const crypto_argon2_extras crypto_argon2_no_extras;
|
||||||
|
|
||||||
|
void crypto_argon2(uint8_t *hash, uint32_t hash_size, void *work_area,
|
||||||
|
crypto_argon2_config config,
|
||||||
|
crypto_argon2_inputs inputs,
|
||||||
|
crypto_argon2_extras extras);
|
||||||
|
|
||||||
|
|
||||||
|
// Key exchange (X-25519)
|
||||||
|
// ----------------------
|
||||||
|
|
||||||
|
// Shared secrets are not quite random.
|
||||||
|
// Hash them to derive an actual shared key.
|
||||||
|
void crypto_x25519_public_key(uint8_t public_key[32],
|
||||||
|
const uint8_t secret_key[32]);
|
||||||
|
void crypto_x25519(uint8_t raw_shared_secret[32],
|
||||||
|
const uint8_t your_secret_key [32],
|
||||||
|
const uint8_t their_public_key [32]);
|
||||||
|
|
||||||
|
// Conversion to EdDSA
|
||||||
|
void crypto_x25519_to_eddsa(uint8_t eddsa[32], const uint8_t x25519[32]);
|
||||||
|
|
||||||
|
// scalar "division"
|
||||||
|
// Used for OPRF. Be aware that exponential blinding is less secure
|
||||||
|
// than Diffie-Hellman key exchange.
|
||||||
|
void crypto_x25519_inverse(uint8_t blind_salt [32],
|
||||||
|
const uint8_t private_key[32],
|
||||||
|
const uint8_t curve_point[32]);
|
||||||
|
|
||||||
|
// "Dirty" versions of x25519_public_key().
|
||||||
|
// Use with crypto_elligator_rev().
|
||||||
|
// Leaks 3 bits of the private key.
|
||||||
|
void crypto_x25519_dirty_small(uint8_t pk[32], const uint8_t sk[32]);
|
||||||
|
void crypto_x25519_dirty_fast (uint8_t pk[32], const uint8_t sk[32]);
|
||||||
|
|
||||||
|
|
||||||
|
// Signatures
|
||||||
|
// ----------
|
||||||
|
|
||||||
|
// EdDSA with curve25519 + BLAKE2b
|
||||||
|
void crypto_eddsa_key_pair(uint8_t secret_key[64],
|
||||||
|
uint8_t public_key[32],
|
||||||
|
uint8_t seed[32]);
|
||||||
|
void crypto_eddsa_sign(uint8_t signature [64],
|
||||||
|
const uint8_t secret_key[64],
|
||||||
|
const uint8_t *message, size_t message_size);
|
||||||
|
int crypto_eddsa_check(const uint8_t signature [64],
|
||||||
|
const uint8_t public_key[32],
|
||||||
|
const uint8_t *message, size_t message_size);
|
||||||
|
|
||||||
|
// Conversion to X25519
|
||||||
|
void crypto_eddsa_to_x25519(uint8_t x25519[32], const uint8_t eddsa[32]);
|
||||||
|
|
||||||
|
// EdDSA building blocks
|
||||||
|
void crypto_eddsa_trim_scalar(uint8_t out[32], const uint8_t in[32]);
|
||||||
|
void crypto_eddsa_reduce(uint8_t reduced[32], const uint8_t expanded[64]);
|
||||||
|
void crypto_eddsa_mul_add(uint8_t r[32],
|
||||||
|
const uint8_t a[32],
|
||||||
|
const uint8_t b[32],
|
||||||
|
const uint8_t c[32]);
|
||||||
|
void crypto_eddsa_scalarbase(uint8_t point[32], const uint8_t scalar[32]);
|
||||||
|
int crypto_eddsa_check_equation(const uint8_t signature[64],
|
||||||
|
const uint8_t public_key[32],
|
||||||
|
const uint8_t h_ram[32]);
|
||||||
|
|
||||||
|
|
||||||
|
// Chacha20
|
||||||
|
// --------
|
||||||
|
|
||||||
|
// Specialised hash.
|
||||||
|
// Used to hash X25519 shared secrets.
|
||||||
|
void crypto_chacha20_h(uint8_t out[32],
|
||||||
|
const uint8_t key[32],
|
||||||
|
const uint8_t in [16]);
|
||||||
|
|
||||||
|
// Unauthenticated stream cipher.
|
||||||
|
// Don't forget to add authentication.
|
||||||
|
uint64_t crypto_chacha20_djb(uint8_t *cipher_text,
|
||||||
|
const uint8_t *plain_text,
|
||||||
|
size_t text_size,
|
||||||
|
const uint8_t key[32],
|
||||||
|
const uint8_t nonce[8],
|
||||||
|
uint64_t ctr);
|
||||||
|
uint32_t crypto_chacha20_ietf(uint8_t *cipher_text,
|
||||||
|
const uint8_t *plain_text,
|
||||||
|
size_t text_size,
|
||||||
|
const uint8_t key[32],
|
||||||
|
const uint8_t nonce[12],
|
||||||
|
uint32_t ctr);
|
||||||
|
uint64_t crypto_chacha20_x(uint8_t *cipher_text,
|
||||||
|
const uint8_t *plain_text,
|
||||||
|
size_t text_size,
|
||||||
|
const uint8_t key[32],
|
||||||
|
const uint8_t nonce[24],
|
||||||
|
uint64_t ctr);
|
||||||
|
|
||||||
|
|
||||||
|
// Poly 1305
|
||||||
|
// ---------
|
||||||
|
|
||||||
|
// This is a *one time* authenticator.
|
||||||
|
// Disclosing the mac reveals the key.
|
||||||
|
// See crypto_lock() on how to use it properly.
|
||||||
|
|
||||||
|
// Direct interface
|
||||||
|
void crypto_poly1305(uint8_t mac[16],
|
||||||
|
const uint8_t *message, size_t message_size,
|
||||||
|
const uint8_t key[32]);
|
||||||
|
|
||||||
|
// Incremental interface
|
||||||
|
typedef struct {
|
||||||
|
// Do not rely on the size or contents of this type,
|
||||||
|
// for they may change without notice.
|
||||||
|
uint8_t c[16]; // chunk of the message
|
||||||
|
size_t c_idx; // How many bytes are there in the chunk.
|
||||||
|
uint32_t r [4]; // constant multiplier (from the secret key)
|
||||||
|
uint32_t pad[4]; // random number added at the end (from the secret key)
|
||||||
|
uint32_t h [5]; // accumulated hash
|
||||||
|
} crypto_poly1305_ctx;
|
||||||
|
|
||||||
|
void crypto_poly1305_init (crypto_poly1305_ctx *ctx, const uint8_t key[32]);
|
||||||
|
void crypto_poly1305_update(crypto_poly1305_ctx *ctx,
|
||||||
|
const uint8_t *message, size_t message_size);
|
||||||
|
void crypto_poly1305_final (crypto_poly1305_ctx *ctx, uint8_t mac[16]);
|
||||||
|
|
||||||
|
|
||||||
|
// Elligator 2
|
||||||
|
// -----------
|
||||||
|
|
||||||
|
// Elligator mappings proper
|
||||||
|
void crypto_elligator_map(uint8_t curve [32], const uint8_t hidden[32]);
|
||||||
|
int crypto_elligator_rev(uint8_t hidden[32], const uint8_t curve [32],
|
||||||
|
uint8_t tweak);
|
||||||
|
|
||||||
|
// Easy to use key pair generation
|
||||||
|
void crypto_elligator_key_pair(uint8_t hidden[32], uint8_t secret_key[32],
|
||||||
|
uint8_t seed[32]);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // MONOCYPHER_H
|
||||||
@@ -15,74 +15,35 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "pkg.h"
|
#include "pkg.h"
|
||||||
|
|
||||||
/* directory definitions */
|
/* "MAJ.MIN.PAT[-TAG]". Each number is read with strtol and clamped to
|
||||||
const dir_t gl_root = { "/glacier", 0750 };
|
* 0..INT_MAX (a manifest is untrusted: sscanf's %d overflowing is
|
||||||
|
* undefined); anything missing or unparseable is 0. */
|
||||||
const dir_t gl_usr = { "/glacier/usr", 0700 };
|
|
||||||
const dir_t gl_usr_index = { "/glacier/usr/index", 0700 };
|
|
||||||
const dir_t gl_usr_store = { "/glacier/usr/store", 0700 };
|
|
||||||
|
|
||||||
const dir_t gl_sys = { "/glacier/sys", 0700 };
|
|
||||||
const dir_t gl_sys_index = { "/glacier/sys/index", 0700 };
|
|
||||||
const dir_t gl_sys_store = { "/glacier/sys/store", 0700 };
|
|
||||||
|
|
||||||
/* null dependencies/conflicts for error throwing */
|
|
||||||
dep_t null_dep = { "null", {-1, -1, -1, NULL} };
|
|
||||||
conf_t null_conf = { "null", {-1, -1, -1, NULL} };
|
|
||||||
|
|
||||||
char
|
|
||||||
*join_with_cwd(const char *path)
|
|
||||||
{
|
|
||||||
char cwd[PATH_MAX];
|
|
||||||
|
|
||||||
if (!getcwd(cwd, sizeof(cwd))) {
|
|
||||||
perror("getcwd");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t length = strlen(cwd + strlen(path) + 2);
|
|
||||||
char *result = malloc(length);
|
|
||||||
if (!result) { return NULL; }
|
|
||||||
|
|
||||||
snprintf(result, length, "%s/%s", cwd, path);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* gl_pkgver
|
|
||||||
* DESCRIPTION: takes three integers and formats them as a semver_t struct
|
|
||||||
* PARAMETERS:
|
|
||||||
* ~ int major (the MAJOR number)
|
|
||||||
* ~ int minor (the MINOR number)
|
|
||||||
* ~ int patch (the PATCH number)
|
|
||||||
* RETURNS:
|
|
||||||
* ~ a pointer to a semver_t struct
|
|
||||||
*/
|
|
||||||
semver_t
|
|
||||||
gl_pkgver(int major, int minor, int patch)
|
|
||||||
{
|
|
||||||
semver_t pkgver = {major, minor, patch, NULL};
|
|
||||||
return pkgver;
|
|
||||||
}
|
|
||||||
|
|
||||||
semver_t
|
semver_t
|
||||||
gl_parse_semver(const char *str)
|
gl_parse_semver(const char *str)
|
||||||
{
|
{
|
||||||
semver_t v = {0, 0, 0, NULL};
|
semver_t v = {0, 0, 0, NULL};
|
||||||
if (!str) { return v; }
|
if (!str) { return v; }
|
||||||
|
|
||||||
char buffer[64];
|
char buffer[64];
|
||||||
strncpy(buffer, str, sizeof(buffer) - 1);
|
snprintf(buffer, sizeof(buffer), "%s", str);
|
||||||
buffer[sizeof(buffer) - 1] = '\0';
|
|
||||||
|
|
||||||
char *dash = strchr(buffer, '-');
|
char *dash = strchr(buffer, '-');
|
||||||
if (dash) {
|
if (dash) {
|
||||||
*dash = '\0';
|
*dash = '\0';
|
||||||
dash++;
|
v.tag = strdup(dash + 1);
|
||||||
v.tag = strdup(dash);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sscanf(buffer, "%d.%d.%d", &v.maj, &v.min, &v.pat);
|
int *parts[] = { &v.maj, &v.min, &v.pat };
|
||||||
|
const char *p = buffer;
|
||||||
|
for (int i = 0; i < 3 && *p; i++) {
|
||||||
|
char *end;
|
||||||
|
errno = 0;
|
||||||
|
long n = strtol(p, &end, 10);
|
||||||
|
if (end == p) { break; }
|
||||||
|
*parts[i] = (errno || n < 0) ? 0 : n > INT_MAX ? INT_MAX : (int)n;
|
||||||
|
if (*end != '.') { break; }
|
||||||
|
p = end + 1;
|
||||||
|
}
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,163 +53,174 @@ gl_free_semver(semver_t *v)
|
|||||||
if (v && v->tag) { free (v->tag); };
|
if (v && v->tag) { free (v->tag); };
|
||||||
}
|
}
|
||||||
|
|
||||||
gl_pkg_t empty = {
|
/*
|
||||||
"null",
|
* gl_valid_pkg_ident
|
||||||
{-1, -1, -1, NULL},
|
* DESCRIPTION: checks that a package name or repo name is safe to use as a
|
||||||
"Null package for internal use. Returned upon an error.",
|
* single path component: non-empty, only [A-Za-z0-9._-], and not
|
||||||
"null@null.null",
|
* "." or "..". Both come straight out of an untrusted manifest (or
|
||||||
"null",
|
* off a command line) and get spliced into store paths, so
|
||||||
"null",
|
* anything else could escape ctx->store_path.
|
||||||
&null_dep,
|
* PARAMETERS:
|
||||||
&null_conf
|
* ~ const char *s (the identifier to check; NULL is invalid)
|
||||||
};
|
* RETURNS:
|
||||||
|
* ~ true if safe, false otherwise
|
||||||
int
|
*/
|
||||||
gl_mkdir(dir_t *dir)
|
bool
|
||||||
|
gl_valid_pkg_ident(const char *s)
|
||||||
{
|
{
|
||||||
if (mkdir(dir -> path, dir -> mode) == 0) {
|
if (!s || s[0] == '\0') { return false; }
|
||||||
return 0;
|
if (strcmp(s, ".") == 0 || strcmp(s, "..") == 0) { return false; }
|
||||||
|
|
||||||
|
for (const char *p = s; *p; p++) {
|
||||||
|
char c = *p;
|
||||||
|
if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') ||
|
||||||
|
(c >= '0' && c <= '9') || c == '.' || c == '_' || c == '-')) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errno == EEXIST) { return 0; }
|
return true;
|
||||||
perror("libglacier: mkdir");
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gl_pkg_t
|
/* A manifest comes out of an untrusted archive. libconfig honours
|
||||||
*gl_spawn_pkg(char *name, semver_t *ver, char *desc, char *maint, char *copy, char *repo, dep_t *dep, conf_t *conf)
|
* `@include "FILE"` at the start of a line, which would have it read any
|
||||||
|
* file (as root, under syspkg): such a manifest is refused. */
|
||||||
|
static char *
|
||||||
|
read_manifest_text(const char *filename)
|
||||||
{
|
{
|
||||||
gl_pkg_t *new_pkg = malloc(sizeof(gl_pkg_t));
|
FILE *f = fopen(filename, "rb");
|
||||||
if (!new_pkg) { return NULL; }
|
if (!f) { return NULL; }
|
||||||
|
enum { MAX_MANIFEST = 1024 * 1024 };
|
||||||
|
char *buf = malloc(MAX_MANIFEST + 1);
|
||||||
|
size_t n = buf ? fread(buf, 1, MAX_MANIFEST + 1, f) : 0;
|
||||||
|
bool bad = !buf || ferror(f) || n > MAX_MANIFEST || memchr(buf, '\0', n);
|
||||||
|
fclose(f);
|
||||||
|
if (bad) {
|
||||||
|
free(buf);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
buf[n] = '\0';
|
||||||
|
for (const char *line = buf; line; line = strchr(line, '\n')) {
|
||||||
|
if (*line == '\n') { line++; }
|
||||||
|
while (*line == ' ' || *line == '\t') { line++; }
|
||||||
|
if (strncmp(line, "@include", 8) == 0) {
|
||||||
|
free(buf);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
new_pkg -> pkg_name = name;
|
/* PKG_DEPS / PKG_CONFS: a list of { PKG_NAME; PKG_VER; }, each name a
|
||||||
new_pkg -> pkg_ver = *ver;
|
* gl_valid_pkg_ident, into a NULL-name-terminated array of
|
||||||
new_pkg -> pkg_desc = desc;
|
* (name, version) pairs, names and vers parallel. false if malformed. */
|
||||||
new_pkg -> pkg_maint = maint;
|
static bool
|
||||||
new_pkg -> pkg_copyright = copy;
|
manifest_relations(config_t *cfg, const char *key, char ***names, semver_t **vers)
|
||||||
new_pkg -> pkg_repo = repo;
|
{
|
||||||
new_pkg -> pkg_dependencies = dep;
|
*names = NULL;
|
||||||
new_pkg -> pkg_conflicts = conf;
|
*vers = NULL;
|
||||||
|
config_setting_t *l = config_lookup(cfg, key);
|
||||||
|
if (!l) { return true; }
|
||||||
|
if (!config_setting_is_list(l)) { return false; }
|
||||||
|
|
||||||
return new_pkg;
|
int count = config_setting_length(l);
|
||||||
|
*names = calloc((size_t)count + 1, sizeof(**names));
|
||||||
|
*vers = calloc((size_t)count + 1, sizeof(**vers));
|
||||||
|
if (!*names || !*vers) { return false; }
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
config_setting_t *d = config_setting_get_elem(l, (unsigned)i);
|
||||||
|
const char *name = NULL, *ver = NULL;
|
||||||
|
config_setting_lookup_string(d, "PKG_NAME", &name);
|
||||||
|
config_setting_lookup_string(d, "PKG_VER", &ver);
|
||||||
|
if (!gl_valid_pkg_ident(name) || !((*names)[i] = strdup(name))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
(*vers)[i] = gl_parse_semver(ver);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
free_relations(char **names, semver_t *vers)
|
||||||
|
{
|
||||||
|
for (size_t i = 0; names && names[i]; i++) {
|
||||||
|
free(names[i]);
|
||||||
|
gl_free_semver(&vers[i]);
|
||||||
|
}
|
||||||
|
free(names);
|
||||||
|
free(vers);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
gl_gpm2gpkg(const char *filename, gl_pkg_t *pkg)
|
gl_gpm2gpkg(const char *filename, gl_pkg_t *pkg)
|
||||||
{
|
{
|
||||||
|
char *text = read_manifest_text(filename);
|
||||||
|
if (!text) { return ENOENT; }
|
||||||
|
|
||||||
config_t cfg;
|
config_t cfg;
|
||||||
config_setting_t *deps, *confs;
|
|
||||||
const char *tmp_str;
|
|
||||||
|
|
||||||
config_init(&cfg);
|
config_init(&cfg);
|
||||||
|
int parsed = config_read_string(&cfg, text);
|
||||||
if (!config_read_file(&cfg, filename)) {
|
free(text);
|
||||||
|
if (!parsed) {
|
||||||
|
config_destroy(&cfg);
|
||||||
return ENOENT;
|
return ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config_lookup_string(&cfg, "PKG_NAME", &tmp_str)) { pkg->pkg_name = strdup(tmp_str); }
|
/* Validate before anything is strdup'd, so a rejected manifest leaves
|
||||||
|
* pkg untouched and the caller has nothing to free. */
|
||||||
|
const char *tmp_str, *name = NULL, *repo = NULL;
|
||||||
|
char **dnames, **cnames;
|
||||||
|
semver_t *dvers, *cvers;
|
||||||
|
config_lookup_string(&cfg, "PKG_NAME", &name);
|
||||||
|
config_lookup_string(&cfg, "PKG_REPO", &repo);
|
||||||
|
bool ok = gl_valid_pkg_ident(name) && gl_valid_pkg_ident(repo);
|
||||||
|
bool rels = manifest_relations(&cfg, "PKG_DEPS", &dnames, &dvers);
|
||||||
|
rels = manifest_relations(&cfg, "PKG_CONFS", &cnames, &cvers) && rels;
|
||||||
|
if (!ok || !rels) {
|
||||||
|
free_relations(dnames, dvers);
|
||||||
|
free_relations(cnames, cvers);
|
||||||
|
config_destroy(&cfg);
|
||||||
|
return EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
pkg->pkg_name = strdup(name);
|
||||||
|
pkg->pkg_repo = strdup(repo);
|
||||||
if (config_lookup_string(&cfg, "PKG_DESC", &tmp_str)) { pkg->pkg_desc = strdup(tmp_str); }
|
if (config_lookup_string(&cfg, "PKG_DESC", &tmp_str)) { pkg->pkg_desc = strdup(tmp_str); }
|
||||||
if (config_lookup_string(&cfg, "PKG_MAINT", &tmp_str)) { pkg->pkg_maint = strdup(tmp_str); }
|
if (config_lookup_string(&cfg, "PKG_MAINT", &tmp_str)) { pkg->pkg_maint = strdup(tmp_str); }
|
||||||
if (config_lookup_string(&cfg, "PKG_COPYRIGHT", &tmp_str)) { pkg->pkg_copyright = strdup(tmp_str); }
|
if (config_lookup_string(&cfg, "PKG_COPYRIGHT", &tmp_str)) { pkg->pkg_copyright = strdup(tmp_str); }
|
||||||
if (config_lookup_string(&cfg, "PKG_REPO", &tmp_str)) { pkg->pkg_repo = strdup(tmp_str); }
|
|
||||||
if (config_lookup_string(&cfg, "PKG_VER", &tmp_str)) { pkg->pkg_ver = gl_parse_semver(tmp_str); }
|
if (config_lookup_string(&cfg, "PKG_VER", &tmp_str)) { pkg->pkg_ver = gl_parse_semver(tmp_str); }
|
||||||
|
|
||||||
deps = config_lookup(&cfg, "PKG_DEPS");
|
if (dnames) {
|
||||||
if (deps && config_setting_is_list(deps)) {
|
size_t n = 0;
|
||||||
int count = config_setting_length(deps);
|
while (dnames[n]) { n++; }
|
||||||
pkg->pkg_dependencies = calloc((size_t)(count + 1), sizeof(dep_t));
|
pkg->pkg_dependencies = calloc(n + 1, sizeof(dep_t));
|
||||||
|
for (size_t i = 0; pkg->pkg_dependencies && i < n; i++) {
|
||||||
for (int i = 0; i < count; i++) {
|
pkg->pkg_dependencies[i].dep_name = dnames[i];
|
||||||
config_setting_t *d = config_setting_get_elem(deps, (unsigned int)i);
|
pkg->pkg_dependencies[i].dep_ver = dvers[i];
|
||||||
const char *dep_name = NULL;
|
dnames[i] = NULL;
|
||||||
const char *dep_ver = NULL;
|
|
||||||
|
|
||||||
config_setting_lookup_string(d, "PKG_NAME", &dep_name);
|
|
||||||
config_setting_lookup_string(d, "PKG_VER", &dep_ver);
|
|
||||||
|
|
||||||
pkg->pkg_dependencies[i].dep_name = dep_name ? strdup(dep_name) : NULL;
|
|
||||||
pkg->pkg_dependencies[i].dep_ver = gl_parse_semver(dep_ver);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (cnames) {
|
||||||
confs = config_lookup(&cfg, "PKG_CONFS");
|
size_t n = 0;
|
||||||
if (confs && config_setting_is_list(confs)) {
|
while (cnames[n]) { n++; }
|
||||||
int count = config_setting_length(confs);
|
pkg->pkg_conflicts = calloc(n + 1, sizeof(conf_t));
|
||||||
pkg->pkg_conflicts = calloc((size_t)(count + 1), sizeof(conf_t));
|
for (size_t i = 0; pkg->pkg_conflicts && i < n; i++) {
|
||||||
|
pkg->pkg_conflicts[i].conf_name = cnames[i];
|
||||||
for (int i = 0; i < count; i++) {
|
pkg->pkg_conflicts[i].conf_ver = cvers[i];
|
||||||
config_setting_t *c = config_setting_get_elem(confs, (unsigned int)i);
|
cnames[i] = NULL;
|
||||||
const char *conf_name = NULL;
|
|
||||||
const char *conf_ver = NULL;
|
|
||||||
|
|
||||||
config_setting_lookup_string(c, "PKG_NAME", &conf_name);
|
|
||||||
config_setting_lookup_string(c, "PKG_VER", &conf_ver);
|
|
||||||
|
|
||||||
pkg->pkg_conflicts[i].conf_name = conf_name ? strdup(conf_name) : NULL;
|
|
||||||
pkg->pkg_conflicts[i].conf_ver = gl_parse_semver(conf_ver);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
free_relations(dnames, dvers);
|
||||||
|
free_relations(cnames, cvers);
|
||||||
config_destroy(&cfg);
|
config_destroy(&cfg);
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
char
|
if (!pkg->pkg_name || !pkg->pkg_repo || (dnames && !pkg->pkg_dependencies) ||
|
||||||
*gl_cat_dir(const dir_t *a, const dir_t *b)
|
(cnames && !pkg->pkg_conflicts)) {
|
||||||
{
|
gl_free_pkg(pkg);
|
||||||
size_t length = strlen(a->path) + strlen(b->path) + 2;
|
memset(pkg, 0, sizeof(*pkg));
|
||||||
char *result = malloc(length);
|
return ENOMEM;
|
||||||
|
|
||||||
if (!result) { return NULL; }
|
|
||||||
|
|
||||||
snprintf(result, length, "%s/%s", a->path, b-> path);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
char
|
|
||||||
*gl_cat_dir_and_ver(const dir_t *base, const gl_pkg_t *pkg)
|
|
||||||
{
|
|
||||||
char version[32];
|
|
||||||
snprintf(version, sizeof(version), "%d.%d.%d",
|
|
||||||
pkg->pkg_ver.maj, pkg->pkg_ver.min, pkg->pkg_ver.pat);
|
|
||||||
|
|
||||||
size_t length = strlen(base->path) + strlen(pkg->pkg_name) + strlen(version) + 3;
|
|
||||||
char *result = malloc(length);
|
|
||||||
if (!result) { return NULL; }
|
|
||||||
|
|
||||||
snprintf(result, length, "%s/%s-%s", base->path, pkg->pkg_name, version);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
dir_t
|
|
||||||
gl_return_dir(const dir_t *a, const dir_t *b, mode_t mode)
|
|
||||||
{
|
|
||||||
char *path = gl_cat_dir(a, b);
|
|
||||||
dir_t result = { path, mode };
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
dir_t
|
|
||||||
gl_return_dir_and_ver(const dir_t *base, gl_pkg_t *pkg, mode_t mode)
|
|
||||||
{
|
|
||||||
char *path = gl_cat_dir_and_ver(base, pkg);
|
|
||||||
dir_t result = { path, mode };
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
gl_free_path(char *path)
|
|
||||||
{
|
|
||||||
free(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
gl_free_dir(dir_t *dir)
|
|
||||||
{
|
|
||||||
if (dir && dir->path) {
|
|
||||||
free((char *)dir->path);
|
|
||||||
dir->path = NULL;
|
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -281,68 +253,454 @@ gl_free_pkg(gl_pkg_t *pkg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
/*
|
||||||
gl_prepare_pkgdir(gl_pkg_t *pkg, bool is_syspkg)
|
* Read integer `key` from a libconfig file (glacier.conf). Distinguishes
|
||||||
|
* the failures a caller has to report differently:
|
||||||
|
* GL_CONF_OK *out set
|
||||||
|
* GL_CONF_ERR_READ file missing, unreadable, or not valid libconfig
|
||||||
|
* GL_CONF_ERR_MISSING file fine, key absent
|
||||||
|
* GL_CONF_ERR_TYPE key present but not an integer
|
||||||
|
* There are deliberately no defaults here: a setting the caller needs and
|
||||||
|
* the file doesn't have is an error, not a silent fallback (CLAUDE.md bug
|
||||||
|
* 10 is what a plausible default hides).
|
||||||
|
*/
|
||||||
|
gl_conf_status_t
|
||||||
|
gl_conf_get_int(const char *path, const char *key, int *out)
|
||||||
{
|
{
|
||||||
|
config_t cfg;
|
||||||
|
config_init(&cfg);
|
||||||
|
|
||||||
dir_t pkg_root = { pkg -> pkg_name, 0750 };
|
if (!config_read_file(&cfg, path)) {
|
||||||
dir_t pkg_store_final;
|
config_destroy(&cfg);
|
||||||
dir_t pkg_index_final;
|
return GL_CONF_ERR_READ;
|
||||||
|
|
||||||
if (!is_syspkg) {
|
|
||||||
dir_t pkg_store_initial = gl_return_dir(&gl_usr_store, &pkg_root, 0750);
|
|
||||||
pkg_store_final = gl_return_dir_and_ver(&pkg_store_initial, pkg, 0750);
|
|
||||||
dir_t pkg_index_initial = gl_return_dir(&gl_usr_index, &pkg_root, 0750);
|
|
||||||
pkg_index_final = gl_return_dir_and_ver(&pkg_index_initial, pkg, 0750);
|
|
||||||
}
|
|
||||||
else if (is_syspkg) {
|
|
||||||
dir_t pkg_store_initial = gl_return_dir(&gl_sys_store, &pkg_root, 0750);
|
|
||||||
pkg_store_final = gl_return_dir_and_ver(&pkg_store_initial, pkg, 0750);
|
|
||||||
dir_t pkg_index_initial = gl_return_dir(&gl_sys_index, &pkg_root, 0750);
|
|
||||||
pkg_index_final = gl_return_dir_and_ver(&pkg_index_initial, pkg, 0750);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("%s\n%s\n", pkg_index_final.path, pkg_store_final.path);
|
config_setting_t *setting = config_lookup(&cfg, key);
|
||||||
gl_free_dir(&pkg_index_final);
|
if (!setting) {
|
||||||
gl_free_dir(&pkg_store_final);
|
config_destroy(&cfg);
|
||||||
|
return GL_CONF_ERR_MISSING;
|
||||||
|
}
|
||||||
|
if (config_setting_type(setting) != CONFIG_TYPE_INT) {
|
||||||
|
config_destroy(&cfg);
|
||||||
|
return GL_CONF_ERR_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
*out = config_setting_get_int(setting);
|
||||||
|
config_destroy(&cfg);
|
||||||
|
return GL_CONF_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* A repos.conf url: https:// or file://, then at least one printable,
|
||||||
|
* non-space ASCII character. http:// and everything else are refused. */
|
||||||
|
static bool
|
||||||
|
valid_repo_url(const char *u)
|
||||||
|
{
|
||||||
|
const char *rest;
|
||||||
|
if (strncmp(u, "https://", 8) == 0)
|
||||||
|
rest = u + 8;
|
||||||
|
else if (strncmp(u, "file://", 7) == 0)
|
||||||
|
rest = u + 7;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
if (*rest == '\0')
|
||||||
|
return false;
|
||||||
|
for (; *rest; rest++)
|
||||||
|
if (*rest < 0x21 || *rest > 0x7e)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Read and check a whole repos.conf (format: gl_conf_repo_keys). On
|
||||||
|
* GL_CONF_OK, *cfg is open (the caller config_destroy()s it) and *repos
|
||||||
|
* is its `repos` list; on anything else nothing is left open.
|
||||||
|
*/
|
||||||
|
static gl_conf_status_t
|
||||||
|
read_repos_conf(const char *path, config_t *cfg, config_setting_t **repos)
|
||||||
|
{
|
||||||
|
config_init(cfg);
|
||||||
|
if (!config_read_file(cfg, path)) {
|
||||||
|
config_destroy(cfg);
|
||||||
|
return GL_CONF_ERR_READ;
|
||||||
|
}
|
||||||
|
|
||||||
|
config_setting_t *root = config_root_setting(cfg);
|
||||||
|
config_setting_t *list = config_setting_get_member(root, "repos");
|
||||||
|
if (config_setting_length(root) != 1 || !list ||
|
||||||
|
config_setting_type(list) != CONFIG_TYPE_LIST)
|
||||||
|
goto invalid;
|
||||||
|
|
||||||
|
int n = config_setting_length(list);
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
config_setting_t *e = config_setting_get_elem(list, (unsigned)i);
|
||||||
|
if (config_setting_type(e) != CONFIG_TYPE_GROUP)
|
||||||
|
goto invalid;
|
||||||
|
|
||||||
|
config_setting_t *name = config_setting_get_member(e, "name");
|
||||||
|
config_setting_t *url = config_setting_get_member(e, "url");
|
||||||
|
config_setting_t *keys = config_setting_get_member(e, "keys");
|
||||||
|
if (!name || !keys ||
|
||||||
|
config_setting_length(e) != (url ? 3 : 2))
|
||||||
|
goto invalid;
|
||||||
|
const char *nm = config_setting_get_string(name);
|
||||||
|
if (!nm || !gl_valid_pkg_ident(nm))
|
||||||
|
goto invalid;
|
||||||
|
if (url) {
|
||||||
|
const char *u = config_setting_get_string(url);
|
||||||
|
if (!u || !valid_repo_url(u))
|
||||||
|
goto invalid;
|
||||||
|
}
|
||||||
|
for (int j = 0; j < i; j++) {
|
||||||
|
config_setting_t *prev = config_setting_get_member(
|
||||||
|
config_setting_get_elem(list, (unsigned)j), "name");
|
||||||
|
if (strcmp(config_setting_get_string(prev), nm) == 0)
|
||||||
|
goto invalid;
|
||||||
|
}
|
||||||
|
if (config_setting_type(keys) != CONFIG_TYPE_ARRAY &&
|
||||||
|
config_setting_type(keys) != CONFIG_TYPE_LIST)
|
||||||
|
goto invalid;
|
||||||
|
int nk = config_setting_length(keys);
|
||||||
|
for (int k = 0; k < nk; k++) {
|
||||||
|
const char *key = config_setting_get_string(
|
||||||
|
config_setting_get_elem(keys, (unsigned)k));
|
||||||
|
if (!key || !gl_valid_pkg_ident(key))
|
||||||
|
goto invalid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*repos = list;
|
||||||
|
return GL_CONF_OK;
|
||||||
|
invalid:
|
||||||
|
config_destroy(cfg);
|
||||||
|
return GL_CONF_ERR_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The names of the keys repos.conf trusts for `repo` (REPO_DESIGN.txt
|
||||||
|
* section 3), '\n'-separated (each followed by '\n') into out.
|
||||||
|
* GL_CONF_OK out set (possibly "": the repo lists no keys)
|
||||||
|
* GL_CONF_ERR_READ file missing, unreadable, or not valid libconfig
|
||||||
|
* GL_CONF_ERR_MISSING the file is valid, but doesn't list `repo`
|
||||||
|
* GL_CONF_ERR_INVALID anything else than the format below
|
||||||
|
* GL_CONF_ERR_SPACE the names don't fit in outlen
|
||||||
|
* The WHOLE file is checked on every call, not only `repo`'s entry, and
|
||||||
|
* nothing unknown is ignored (a setting that silently never parses is
|
||||||
|
* CLAUDE.md bug 10's class):
|
||||||
|
* repos = ( { name = "base"; url = "https://..."; keys = [ "k" ]; }, ... );
|
||||||
|
* `repos` is the only top-level setting; each entry is a group with a
|
||||||
|
* name (a gl_valid_pkg_ident, unique), an optional url (valid_repo_url)
|
||||||
|
* and keys (an array or list of gl_valid_pkg_ident strings).
|
||||||
|
*/
|
||||||
|
gl_conf_status_t
|
||||||
|
gl_conf_repo_keys(const char *path, const char *repo, char *out, size_t outlen)
|
||||||
|
{
|
||||||
|
if (!out || outlen == 0)
|
||||||
|
return GL_CONF_ERR_SPACE;
|
||||||
|
out[0] = '\0';
|
||||||
|
|
||||||
|
config_t cfg;
|
||||||
|
config_setting_t *repos;
|
||||||
|
gl_conf_status_t st = read_repos_conf(path, &cfg, &repos);
|
||||||
|
if (st != GL_CONF_OK)
|
||||||
|
return st;
|
||||||
|
|
||||||
|
st = GL_CONF_ERR_MISSING;
|
||||||
|
int n = config_setting_length(repos);
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
config_setting_t *e = config_setting_get_elem(repos, (unsigned)i);
|
||||||
|
if (strcmp(config_setting_get_string(
|
||||||
|
config_setting_get_member(e, "name")), repo) != 0)
|
||||||
|
continue;
|
||||||
|
config_setting_t *keys = config_setting_get_member(e, "keys");
|
||||||
|
size_t used = 0;
|
||||||
|
int nk = config_setting_length(keys);
|
||||||
|
for (int k = 0; k < nk; k++) {
|
||||||
|
const char *key = config_setting_get_string(
|
||||||
|
config_setting_get_elem(keys, (unsigned)k));
|
||||||
|
size_t len = strlen(key);
|
||||||
|
if (used + len + 2 > outlen) {
|
||||||
|
out[0] = '\0';
|
||||||
|
st = GL_CONF_ERR_SPACE;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
memcpy(out + used, key, len);
|
||||||
|
out[used + len] = '\n';
|
||||||
|
used += len + 1;
|
||||||
|
out[used] = '\0';
|
||||||
|
}
|
||||||
|
st = GL_CONF_OK;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
out:
|
||||||
|
config_destroy(&cfg);
|
||||||
|
return st;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Every repository repos.conf lists, in its order (= priority), one
|
||||||
|
* "NAME\tURL\n" line each into out; URL is empty for an entry without
|
||||||
|
* one. The whole file is checked as by gl_conf_repo_keys.
|
||||||
|
* GL_CONF_OK out set (possibly "": no repositories)
|
||||||
|
* GL_CONF_ERR_READ file missing, unreadable, or not valid libconfig
|
||||||
|
* GL_CONF_ERR_INVALID not the format gl_conf_repo_keys describes
|
||||||
|
* GL_CONF_ERR_SPACE the lines don't fit in outlen
|
||||||
|
*/
|
||||||
|
gl_conf_status_t
|
||||||
|
gl_conf_repos(const char *path, char *out, size_t outlen)
|
||||||
|
{
|
||||||
|
if (!out || outlen == 0)
|
||||||
|
return GL_CONF_ERR_SPACE;
|
||||||
|
out[0] = '\0';
|
||||||
|
|
||||||
|
config_t cfg;
|
||||||
|
config_setting_t *repos;
|
||||||
|
gl_conf_status_t st = read_repos_conf(path, &cfg, &repos);
|
||||||
|
if (st != GL_CONF_OK)
|
||||||
|
return st;
|
||||||
|
|
||||||
|
size_t used = 0;
|
||||||
|
int n = config_setting_length(repos);
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
config_setting_t *e = config_setting_get_elem(repos, (unsigned)i);
|
||||||
|
const char *nm = config_setting_get_string(
|
||||||
|
config_setting_get_member(e, "name"));
|
||||||
|
config_setting_t *url = config_setting_get_member(e, "url");
|
||||||
|
const char *u = url ? config_setting_get_string(url) : "";
|
||||||
|
int len = snprintf(out + used, outlen - used, "%s\t%s\n", nm, u);
|
||||||
|
if (len < 0 || (size_t)len >= outlen - used) {
|
||||||
|
out[0] = '\0';
|
||||||
|
st = GL_CONF_ERR_SPACE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
used += (size_t)len;
|
||||||
|
}
|
||||||
|
config_destroy(&cfg);
|
||||||
|
return st;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------ */
|
||||||
|
/* Repository indexes (REPO_DESIGN.txt section 4) */
|
||||||
|
/* ------------------------------------------------------------------ */
|
||||||
|
|
||||||
|
/* A version as the store names it: "%d.%d.%d", each part decimal
|
||||||
|
* without leading zeros and fitting an int. Anything else would name a
|
||||||
|
* version directory the store never makes. */
|
||||||
|
static bool
|
||||||
|
valid_index_ver(const char *v)
|
||||||
|
{
|
||||||
|
for (int part = 0; part < 3; part++) {
|
||||||
|
const char *start = v;
|
||||||
|
long n = 0;
|
||||||
|
while (*v >= '0' && *v <= '9') {
|
||||||
|
n = n * 10 + (*v - '0');
|
||||||
|
if (n > INT_MAX)
|
||||||
|
return false;
|
||||||
|
v++;
|
||||||
|
}
|
||||||
|
if (v == start || (*start == '0' && v - start > 1))
|
||||||
|
return false;
|
||||||
|
if (part < 2 && *v++ != '.')
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return *v == '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
valid_sha256_field(const char *s)
|
||||||
|
{
|
||||||
|
if (strncmp(s, "sha256:", 7) != 0 || strlen(s) != 7 + 64)
|
||||||
|
return false;
|
||||||
|
for (s += 7; *s; s++)
|
||||||
|
if (!((*s >= '0' && *s <= '9') || (*s >= 'a' && *s <= 'f')))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* A group with exactly the members named in `names` (NULL-terminated). */
|
||||||
|
static bool
|
||||||
|
has_exactly(config_setting_t *g, const char *const *names)
|
||||||
|
{
|
||||||
|
if (!g || config_setting_type(g) != CONFIG_TYPE_GROUP)
|
||||||
|
return false;
|
||||||
|
int n = 0;
|
||||||
|
for (; names[n]; n++)
|
||||||
|
if (!config_setting_get_member(g, names[n]))
|
||||||
|
return false;
|
||||||
|
return config_setting_length(g) == n;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char *
|
||||||
|
str_member(config_setting_t *g, const char *name)
|
||||||
|
{
|
||||||
|
config_setting_t *m = config_setting_get_member(g, name);
|
||||||
|
return m && config_setting_type(m) == CONFIG_TYPE_STRING ?
|
||||||
|
config_setting_get_string(m) : NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* An integer member (int or int64), or false. */
|
||||||
|
static bool
|
||||||
|
int_member(config_setting_t *g, const char *name, int64_t *out)
|
||||||
|
{
|
||||||
|
config_setting_t *m = config_setting_get_member(g, name);
|
||||||
|
if (!m || (config_setting_type(m) != CONFIG_TYPE_INT &&
|
||||||
|
config_setting_type(m) != CONFIG_TYPE_INT64))
|
||||||
|
return false;
|
||||||
|
*out = (int64_t)config_setting_get_int64(m);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* DEPS or CONFS: a list of { NAME; VER; } groups, as "NAME VER\n" lines
|
||||||
|
* into a new string (*out; "" for an empty list). */
|
||||||
|
static bool
|
||||||
|
read_relations(config_setting_t *pkg, const char *name, char **out)
|
||||||
|
{
|
||||||
|
static const char *const members[] = { "NAME", "VER", NULL };
|
||||||
|
config_setting_t *l = config_setting_get_member(pkg, name);
|
||||||
|
if (!l || config_setting_type(l) != CONFIG_TYPE_LIST)
|
||||||
|
return false;
|
||||||
|
int n = config_setting_length(l);
|
||||||
|
size_t cap = 1, used = 0;
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
config_setting_t *r = config_setting_get_elem(l, (unsigned)i);
|
||||||
|
const char *nm, *ver;
|
||||||
|
if (!has_exactly(r, members) || !(nm = str_member(r, "NAME")) ||
|
||||||
|
!(ver = str_member(r, "VER")) || !gl_valid_pkg_ident(nm) ||
|
||||||
|
!valid_index_ver(ver))
|
||||||
|
return false;
|
||||||
|
cap += strlen(nm) + strlen(ver) + 2;
|
||||||
|
}
|
||||||
|
if (!(*out = malloc(cap)))
|
||||||
|
return false;
|
||||||
|
(*out)[0] = '\0';
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
config_setting_t *r = config_setting_get_elem(l, (unsigned)i);
|
||||||
|
used += (size_t)snprintf(*out + used, cap - used, "%s %s\n",
|
||||||
|
str_member(r, "NAME"), str_member(r, "VER"));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gl_show_pkg_props(const gl_pkg_t *pkg)
|
gl_index_free(gl_index_t *idx)
|
||||||
{
|
{
|
||||||
if (!pkg) {
|
if (!idx)
|
||||||
printf("(null pkg)\n");
|
|
||||||
return;
|
return;
|
||||||
|
for (size_t i = 0; i < idx->npkgs; i++) {
|
||||||
|
gl_index_pkg_t *p = &idx->pkgs[i];
|
||||||
|
free(p->name);
|
||||||
|
free(p->ver);
|
||||||
|
free(p->file);
|
||||||
|
free(p->sha256);
|
||||||
|
free(p->deps);
|
||||||
|
free(p->confs);
|
||||||
}
|
}
|
||||||
|
free(idx->pkgs);
|
||||||
printf("Package: %s\n", pkg->pkg_name);
|
free(idx->repo);
|
||||||
printf("Version: %d.%d.%d\n", pkg->pkg_ver.maj, pkg->pkg_ver.min, pkg->pkg_ver.pat);
|
memset(idx, 0, sizeof(*idx));
|
||||||
printf("Description: %s\n", pkg->pkg_desc);
|
|
||||||
printf("Maintainer: %s\n", pkg->pkg_maint);
|
|
||||||
printf("Copyright: %s\n", pkg->pkg_copyright);
|
|
||||||
|
|
||||||
if (pkg->pkg_dependencies) {
|
|
||||||
printf("Dependencies:\n");
|
|
||||||
dep_t *dep = pkg->pkg_dependencies;
|
|
||||||
printf("\t~ %s (%d.%d.%d)\n",
|
|
||||||
dep->dep_name,
|
|
||||||
dep->dep_ver.maj, dep->dep_ver.min, dep->dep_ver.pat);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
printf("Dependencies: (none)\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pkg->pkg_conflicts) {
|
|
||||||
printf("Conflicting packages:\n");
|
|
||||||
conf_t *conf = pkg->pkg_conflicts;
|
|
||||||
printf("\t~ %s (%d.%d.%d)\n",
|
|
||||||
conf->conf_name,
|
|
||||||
conf->conf_ver.maj, conf->conf_ver.min, conf->conf_ver.pat);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
printf("Conflicting packages: (none)\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Parse an index's bytes (text[0..len)) into *out, which is zeroed
|
||||||
|
* first; free it with gl_index_free on GL_INDEX_OK. The caller checks
|
||||||
|
* the signature over the SAME bytes first: nothing here is trusted
|
||||||
|
* otherwise, and nothing here checks SERIAL or VALID_UNTIL against
|
||||||
|
* anything (that is the caller's rollback/expiry policy).
|
||||||
|
*
|
||||||
|
* Strict, like repos.conf: exactly REPO, SERIAL (> 0), VALID_UNTIL
|
||||||
|
* (> 0) and PKGS at the top; each package exactly NAME, VER, FILE,
|
||||||
|
* SHA256, SIZE (>= 0), DEPS, CONFS; NAME a gl_valid_pkg_ident; VER as
|
||||||
|
* the store names versions; FILE exactly "NAME-VER.gpkg"; SHA256
|
||||||
|
* "sha256:" + 64 lowercase hex; DEPS/CONFS lists of { NAME; VER; }; no
|
||||||
|
* NAME + VER twice. A NUL or '@' anywhere is refused before parsing:
|
||||||
|
* an index never has one, and '@' is how libconfig spells @include.
|
||||||
|
* GL_INDEX_OK, GL_INDEX_ERR_FORMAT, GL_INDEX_ERR_REPO (well formed,
|
||||||
|
* but REPO is not `repo`), GL_INDEX_ERR_NOMEM
|
||||||
|
*/
|
||||||
|
gl_index_status_t
|
||||||
|
gl_index_parse(const char *text, size_t len, const char *repo, gl_index_t *out)
|
||||||
|
{
|
||||||
|
static const char *const top[] = { "REPO", "SERIAL", "VALID_UNTIL", "PKGS", NULL };
|
||||||
|
static const char *const fields[] = { "NAME", "VER", "FILE", "SHA256",
|
||||||
|
"SIZE", "DEPS", "CONFS", NULL };
|
||||||
|
|
||||||
|
if (!out)
|
||||||
|
return GL_INDEX_ERR_FORMAT;
|
||||||
|
memset(out, 0, sizeof(*out));
|
||||||
|
if (!text || !repo || memchr(text, '\0', len) || memchr(text, '@', len))
|
||||||
|
return GL_INDEX_ERR_FORMAT;
|
||||||
|
|
||||||
|
char *buf = malloc(len + 1);
|
||||||
|
if (!buf)
|
||||||
|
return GL_INDEX_ERR_NOMEM;
|
||||||
|
memcpy(buf, text, len);
|
||||||
|
buf[len] = '\0';
|
||||||
|
|
||||||
|
config_t cfg;
|
||||||
|
config_init(&cfg);
|
||||||
|
int ok = config_read_string(&cfg, buf);
|
||||||
|
free(buf);
|
||||||
|
if (!ok) {
|
||||||
|
config_destroy(&cfg);
|
||||||
|
return GL_INDEX_ERR_FORMAT;
|
||||||
|
}
|
||||||
|
|
||||||
|
gl_index_status_t st = GL_INDEX_ERR_FORMAT;
|
||||||
|
config_setting_t *root = config_root_setting(&cfg);
|
||||||
|
const char *r = str_member(root, "REPO");
|
||||||
|
config_setting_t *pkgs = config_setting_get_member(root, "PKGS");
|
||||||
|
if (config_setting_length(root) != 4 || !has_exactly(root, top) ||
|
||||||
|
!r || !gl_valid_pkg_ident(r) ||
|
||||||
|
!int_member(root, "SERIAL", &out->serial) || out->serial <= 0 ||
|
||||||
|
!int_member(root, "VALID_UNTIL", &out->valid_until) ||
|
||||||
|
out->valid_until <= 0 ||
|
||||||
|
config_setting_type(pkgs) != CONFIG_TYPE_LIST)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
size_t n = (size_t)config_setting_length(pkgs);
|
||||||
|
if (n && !(out->pkgs = calloc(n, sizeof(*out->pkgs)))) {
|
||||||
|
st = GL_INDEX_ERR_NOMEM;
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
for (size_t i = 0; i < n; i++) {
|
||||||
|
config_setting_t *e = config_setting_get_elem(pkgs, (unsigned)i);
|
||||||
|
gl_index_pkg_t *p = &out->pkgs[i];
|
||||||
|
out->npkgs = i + 1;
|
||||||
|
const char *nm, *ver, *file, *sha;
|
||||||
|
if (!has_exactly(e, fields) ||
|
||||||
|
!(nm = str_member(e, "NAME")) || !gl_valid_pkg_ident(nm) ||
|
||||||
|
!(ver = str_member(e, "VER")) || !valid_index_ver(ver) ||
|
||||||
|
!(file = str_member(e, "FILE")) ||
|
||||||
|
!(sha = str_member(e, "SHA256")) || !valid_sha256_field(sha) ||
|
||||||
|
!int_member(e, "SIZE", &p->size) || p->size < 0)
|
||||||
|
goto fail;
|
||||||
|
char want[PATH_MAX];
|
||||||
|
snprintf(want, sizeof want, "%s-%s.gpkg", nm, ver);
|
||||||
|
if (strcmp(file, want) != 0)
|
||||||
|
goto fail;
|
||||||
|
for (size_t j = 0; j < i; j++)
|
||||||
|
if (strcmp(out->pkgs[j].name, nm) == 0 &&
|
||||||
|
strcmp(out->pkgs[j].ver, ver) == 0)
|
||||||
|
goto fail;
|
||||||
|
if (!(p->name = strdup(nm)) || !(p->ver = strdup(ver)) ||
|
||||||
|
!(p->file = strdup(file)) || !(p->sha256 = strdup(sha))) {
|
||||||
|
st = GL_INDEX_ERR_NOMEM;
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
if (!read_relations(e, "DEPS", &p->deps) ||
|
||||||
|
!read_relations(e, "CONFS", &p->confs))
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
if (strcmp(r, repo) != 0) {
|
||||||
|
st = GL_INDEX_ERR_REPO;
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
if (!(out->repo = strdup(r))) {
|
||||||
|
st = GL_INDEX_ERR_NOMEM;
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
config_destroy(&cfg);
|
||||||
|
return GL_INDEX_OK;
|
||||||
|
fail:
|
||||||
|
config_destroy(&cfg);
|
||||||
|
gl_index_free(out);
|
||||||
|
return st;
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
#include <libconfig.h>
|
#include <libconfig.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
@@ -43,43 +44,57 @@ typedef struct {
|
|||||||
}
|
}
|
||||||
gl_pkg_t;
|
gl_pkg_t;
|
||||||
|
|
||||||
extern const dir_t gl_root;
|
|
||||||
|
|
||||||
extern const dir_t gl_usr;
|
|
||||||
extern const dir_t gl_usr_index;
|
|
||||||
extern const dir_t gl_usr_store;
|
|
||||||
|
|
||||||
extern const dir_t gl_sys;
|
|
||||||
extern const dir_t gl_sys_index;
|
|
||||||
extern const dir_t gl_sys_store;
|
|
||||||
|
|
||||||
extern dep_t null_dep;
|
|
||||||
extern conf_t null_conf;
|
|
||||||
extern gl_pkg_t empty;
|
|
||||||
|
|
||||||
semver_t gl_pkgver(int major, int minor, int patch);
|
|
||||||
semver_t gl_parse_semver(const char *str);
|
semver_t gl_parse_semver(const char *str);
|
||||||
void gl_free_semver(semver_t *v);
|
void gl_free_semver(semver_t *v);
|
||||||
|
|
||||||
gl_pkg_t *gl_spawn_pkg(
|
|
||||||
char *name, semver_t *ver, char *desc,
|
|
||||||
char *maint, char *copy, char *repo,
|
|
||||||
dep_t *dep, conf_t *conf
|
|
||||||
);
|
|
||||||
|
|
||||||
void gl_show_pkg_props(const gl_pkg_t *pkg);
|
|
||||||
void gl_free_pkg(gl_pkg_t *pkg);
|
void gl_free_pkg(gl_pkg_t *pkg);
|
||||||
|
|
||||||
int gl_mkdir(dir_t *dir);
|
typedef enum {
|
||||||
char *gl_cat_dir(const dir_t *a, const dir_t *b);
|
GL_CONF_OK = 0,
|
||||||
char *gl_cat_dir_and_ver(const dir_t *base, const gl_pkg_t *pkg);
|
GL_CONF_ERR_READ = 1,
|
||||||
dir_t gl_return_dir(const dir_t *a, const dir_t *b, mode_t mode);
|
GL_CONF_ERR_MISSING = 2,
|
||||||
dir_t gl_return_dir_and_ver(const dir_t *base, gl_pkg_t *pkg, mode_t mode);
|
GL_CONF_ERR_TYPE = 3,
|
||||||
void gl_free_path(char *path);
|
GL_CONF_ERR_INVALID = 4,
|
||||||
void gl_free_dir(dir_t *dir);
|
GL_CONF_ERR_SPACE = 5
|
||||||
|
} gl_conf_status_t;
|
||||||
|
|
||||||
|
|
||||||
|
gl_conf_status_t gl_conf_get_int(const char *path, const char *key, int *out);
|
||||||
|
gl_conf_status_t gl_conf_repo_keys(const char *path, const char *repo,
|
||||||
|
char *out, size_t outlen);
|
||||||
|
gl_conf_status_t gl_conf_repos(const char *path, char *out, size_t outlen);
|
||||||
|
|
||||||
|
/* A repository index (REPO_DESIGN.txt section 4), as gl_index_parse
|
||||||
|
* reads it. deps/confs are "NAME VER\n" lines ("" for none). */
|
||||||
|
typedef struct {
|
||||||
|
char *name;
|
||||||
|
char *ver;
|
||||||
|
char *file;
|
||||||
|
char *sha256;
|
||||||
|
int64_t size;
|
||||||
|
char *deps;
|
||||||
|
char *confs;
|
||||||
|
} gl_index_pkg_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char *repo;
|
||||||
|
int64_t serial;
|
||||||
|
int64_t valid_until;
|
||||||
|
size_t npkgs;
|
||||||
|
gl_index_pkg_t *pkgs;
|
||||||
|
} gl_index_t;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
GL_INDEX_OK = 0,
|
||||||
|
GL_INDEX_ERR_FORMAT = 1,
|
||||||
|
GL_INDEX_ERR_REPO = 2,
|
||||||
|
GL_INDEX_ERR_NOMEM = 3
|
||||||
|
} gl_index_status_t;
|
||||||
|
|
||||||
|
gl_index_status_t gl_index_parse(const char *text, size_t len,
|
||||||
|
const char *repo, gl_index_t *out);
|
||||||
|
void gl_index_free(gl_index_t *idx);
|
||||||
|
|
||||||
|
bool gl_valid_pkg_ident(const char *s);
|
||||||
int gl_gpm2gpkg(const char *filename, gl_pkg_t *pkg);
|
int gl_gpm2gpkg(const char *filename, gl_pkg_t *pkg);
|
||||||
int gl_prepare_pkgdir(gl_pkg_t *pkg, bool is_syspkg);
|
|
||||||
char *join_with_cwd(const char *path);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
#define _POSIX_C_SOURCE 200809L
|
|
||||||
#define _DEFAULT_SOURCE
|
|
||||||
#define _XOPEN_SOURCE 700
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "color.h"
|
|
||||||
|
|
||||||
bool
|
|
||||||
lg_is_root(void)
|
|
||||||
{
|
|
||||||
if (getuid() != 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else if (getuid() == 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
lg_runtime_exists(void)
|
|
||||||
{
|
|
||||||
const char *rt_files[] = {
|
|
||||||
"/etc/glacier/glacier.conf",
|
|
||||||
"/etc/glacier/make.conf"
|
|
||||||
};
|
|
||||||
|
|
||||||
size_t num_of_files = sizeof(rt_files) / sizeof(rt_files[0]);
|
|
||||||
|
|
||||||
for (size_t f_index = 0; f_index < num_of_files; f_index++) {
|
|
||||||
if (access(rt_files[f_index], F_OK) == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
+428
@@ -0,0 +1,428 @@
|
|||||||
|
/*
|
||||||
|
* gl_sign: Ed25519 signatures in signify's file formats. See sign.h.
|
||||||
|
*
|
||||||
|
* Parsing is strict: exactly two lines, the "untrusted comment: "
|
||||||
|
* prefix, canonical base64 of exactly the expected length, the right
|
||||||
|
* algorithm bytes. Anything else is GL_SIGN_ERR_FORMAT.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _POSIX_C_SOURCE 200809L
|
||||||
|
#define _DEFAULT_SOURCE
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/random.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "sign.h"
|
||||||
|
#include "monocypher/monocypher.h"
|
||||||
|
#include "monocypher/monocypher-ed25519.h"
|
||||||
|
|
||||||
|
#define COMMENT_PREFIX "untrusted comment: "
|
||||||
|
#define COMMENT_PREFIX_LEN (sizeof COMMENT_PREFIX - 1)
|
||||||
|
|
||||||
|
/* Decoded sizes of the three kinds of file. */
|
||||||
|
#define PUBKEY_BYTES 42
|
||||||
|
#define SIG_BYTES 74
|
||||||
|
#define SECKEY_BYTES 104
|
||||||
|
|
||||||
|
/* A key or signature file is a few hundred bytes at most. */
|
||||||
|
#define MAX_KEYFILE (COMMENT_PREFIX_LEN + GL_SIGN_MAX_COMMENT + 1 + 4 * ((SECKEY_BYTES + 2) / 3) + 1)
|
||||||
|
|
||||||
|
/* Reads all of a regular file (at most `max` bytes) into a malloc'd
|
||||||
|
* buffer. */
|
||||||
|
static int
|
||||||
|
read_all(const char *path, size_t max, uint8_t **out, size_t *len)
|
||||||
|
{
|
||||||
|
int fd = open(path, O_RDONLY | O_CLOEXEC);
|
||||||
|
if (fd < 0)
|
||||||
|
return GL_SIGN_ERR_IO;
|
||||||
|
|
||||||
|
struct stat st;
|
||||||
|
if (fstat(fd, &st) != 0 || !S_ISREG(st.st_mode)) {
|
||||||
|
close(fd);
|
||||||
|
return GL_SIGN_ERR_IO;
|
||||||
|
}
|
||||||
|
if (st.st_size < 0 || (uintmax_t)st.st_size > max) {
|
||||||
|
close(fd);
|
||||||
|
return GL_SIGN_ERR_TOOBIG;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t size = (size_t)st.st_size;
|
||||||
|
uint8_t *buf = malloc(size ? size : 1);
|
||||||
|
if (!buf) {
|
||||||
|
close(fd);
|
||||||
|
return GL_SIGN_ERR_IO;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t got = 0;
|
||||||
|
while (got < size) {
|
||||||
|
ssize_t n = read(fd, buf + got, size - got);
|
||||||
|
if (n < 0 && errno == EINTR)
|
||||||
|
continue;
|
||||||
|
if (n <= 0)
|
||||||
|
break;
|
||||||
|
got += (size_t)n;
|
||||||
|
}
|
||||||
|
/* The file must not have grown or shrunk under us. */
|
||||||
|
uint8_t extra;
|
||||||
|
ssize_t more = read(fd, &extra, 1);
|
||||||
|
close(fd);
|
||||||
|
if (got != size || more != 0) {
|
||||||
|
free(buf);
|
||||||
|
return GL_SIGN_ERR_IO;
|
||||||
|
}
|
||||||
|
|
||||||
|
*out = buf;
|
||||||
|
*len = size;
|
||||||
|
return GL_SIGN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
b64_value(uint8_t c)
|
||||||
|
{
|
||||||
|
if (c >= 'A' && c <= 'Z') return c - 'A';
|
||||||
|
if (c >= 'a' && c <= 'z') return c - 'a' + 26;
|
||||||
|
if (c >= '0' && c <= '9') return c - '0' + 52;
|
||||||
|
if (c == '+') return 62;
|
||||||
|
if (c == '/') return 63;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Decodes canonical, padded base64 that must yield exactly `outlen`
|
||||||
|
* bytes. Returns 0 on success. */
|
||||||
|
static int
|
||||||
|
b64_decode_exact(const uint8_t *in, size_t n, uint8_t *out, size_t outlen)
|
||||||
|
{
|
||||||
|
if (n != (outlen + 2) / 3 * 4)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
size_t o = 0;
|
||||||
|
for (size_t i = 0; i < n; i += 4) {
|
||||||
|
uint32_t t = 0;
|
||||||
|
size_t pad = 0;
|
||||||
|
for (size_t j = 0; j < 4; j++) {
|
||||||
|
uint8_t c = in[i + j];
|
||||||
|
int v;
|
||||||
|
if (c == '=') {
|
||||||
|
/* Padding only in the last quartet's last two places. */
|
||||||
|
if (i + 4 != n || j < 2)
|
||||||
|
return -1;
|
||||||
|
pad++;
|
||||||
|
v = 0;
|
||||||
|
} else {
|
||||||
|
if (pad)
|
||||||
|
return -1;
|
||||||
|
v = b64_value(c);
|
||||||
|
if (v < 0)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
t = (t << 6) | (uint32_t)v;
|
||||||
|
}
|
||||||
|
/* Canonical: the bits padding drops must be zero. */
|
||||||
|
if ((pad == 1 && (t & 0xffu)) || (pad == 2 && (t & 0xffffu)))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
size_t bytes = 3 - pad;
|
||||||
|
if (o + bytes > outlen)
|
||||||
|
return -1;
|
||||||
|
uint8_t b[3] = { (uint8_t)(t >> 16), (uint8_t)(t >> 8), (uint8_t)t };
|
||||||
|
memcpy(out + o, b, bytes);
|
||||||
|
o += bytes;
|
||||||
|
}
|
||||||
|
return o == outlen ? 0 : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
b64_encode(const uint8_t *in, size_t n, char *out)
|
||||||
|
{
|
||||||
|
static const char tab[] =
|
||||||
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||||
|
size_t o = 0;
|
||||||
|
for (size_t i = 0; i < n; i += 3) {
|
||||||
|
uint32_t t = (uint32_t)in[i] << 16;
|
||||||
|
if (i + 1 < n) t |= (uint32_t)in[i + 1] << 8;
|
||||||
|
if (i + 2 < n) t |= in[i + 2];
|
||||||
|
out[o++] = tab[(t >> 18) & 63];
|
||||||
|
out[o++] = tab[(t >> 12) & 63];
|
||||||
|
out[o++] = i + 1 < n ? tab[(t >> 6) & 63] : '=';
|
||||||
|
out[o++] = i + 2 < n ? tab[t & 63] : '=';
|
||||||
|
}
|
||||||
|
out[o] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Reads a signify file and decodes its payload into out[0..outlen). */
|
||||||
|
static int
|
||||||
|
read_signify(const char *path, uint8_t *out, size_t outlen)
|
||||||
|
{
|
||||||
|
uint8_t *buf;
|
||||||
|
size_t len;
|
||||||
|
int st = read_all(path, MAX_KEYFILE, &buf, &len);
|
||||||
|
if (st == GL_SIGN_ERR_TOOBIG)
|
||||||
|
return GL_SIGN_ERR_FORMAT;
|
||||||
|
if (st != GL_SIGN_OK)
|
||||||
|
return st;
|
||||||
|
|
||||||
|
st = GL_SIGN_ERR_FORMAT;
|
||||||
|
if (len < COMMENT_PREFIX_LEN || memcmp(buf, COMMENT_PREFIX, COMMENT_PREFIX_LEN) != 0)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
uint8_t *nl = memchr(buf, '\n', len);
|
||||||
|
if (!nl || memchr(buf, '\0', (size_t)(nl - buf)))
|
||||||
|
goto out;
|
||||||
|
if ((size_t)(nl - buf) - COMMENT_PREFIX_LEN > GL_SIGN_MAX_COMMENT)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
/* The base64 line runs to a final newline that ends the file. */
|
||||||
|
uint8_t *b64 = nl + 1;
|
||||||
|
uint8_t *end = buf + len;
|
||||||
|
if (b64 >= end || end[-1] != '\n')
|
||||||
|
goto out;
|
||||||
|
if (b64_decode_exact(b64, (size_t)(end - 1 - b64), out, outlen) != 0)
|
||||||
|
goto out;
|
||||||
|
if (out[0] != 'E' || out[1] != 'd')
|
||||||
|
goto out;
|
||||||
|
st = GL_SIGN_OK;
|
||||||
|
out:
|
||||||
|
crypto_wipe(buf, len);
|
||||||
|
free(buf);
|
||||||
|
return st;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
gl_sign_read_pubkey(const char *path, gl_sign_pubkey_t *out)
|
||||||
|
{
|
||||||
|
uint8_t raw[PUBKEY_BYTES];
|
||||||
|
int st = read_signify(path, raw, sizeof raw);
|
||||||
|
if (st != GL_SIGN_OK)
|
||||||
|
return st;
|
||||||
|
memcpy(out->keynum, raw + 2, GL_SIGN_KEYNUM_SIZE);
|
||||||
|
memcpy(out->key, raw + 10, sizeof out->key);
|
||||||
|
return GL_SIGN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
gl_sign_read_sig(const char *path, gl_sign_sig_t *out)
|
||||||
|
{
|
||||||
|
uint8_t raw[SIG_BYTES];
|
||||||
|
int st = read_signify(path, raw, sizeof raw);
|
||||||
|
if (st != GL_SIGN_OK)
|
||||||
|
return st;
|
||||||
|
memcpy(out->keynum, raw + 2, GL_SIGN_KEYNUM_SIZE);
|
||||||
|
memcpy(out->sig, raw + 10, sizeof out->sig);
|
||||||
|
return GL_SIGN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* sec[0..64) = seed | public key, as signify and Monocypher both lay
|
||||||
|
* it out. */
|
||||||
|
static int
|
||||||
|
read_seckey(const char *path, uint8_t keynum[GL_SIGN_KEYNUM_SIZE], uint8_t sec[64])
|
||||||
|
{
|
||||||
|
uint8_t raw[SECKEY_BYTES];
|
||||||
|
int st = read_signify(path, raw, sizeof raw);
|
||||||
|
if (st != GL_SIGN_OK)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
st = GL_SIGN_ERR_FORMAT;
|
||||||
|
if (raw[2] != 'B' || raw[3] != 'K')
|
||||||
|
goto out;
|
||||||
|
uint32_t rounds = (uint32_t)raw[4] << 24 | (uint32_t)raw[5] << 16
|
||||||
|
| (uint32_t)raw[6] << 8 | raw[7];
|
||||||
|
if (rounds != 0) {
|
||||||
|
st = GL_SIGN_ERR_ENCRYPTED;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* checksum = the first 8 bytes of SHA-512(seckey) */
|
||||||
|
uint8_t digest[64];
|
||||||
|
crypto_sha512(digest, raw + 40, 64);
|
||||||
|
int ok = memcmp(digest, raw + 24, 8) == 0;
|
||||||
|
crypto_wipe(digest, sizeof digest);
|
||||||
|
if (!ok)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
memcpy(keynum, raw + 32, GL_SIGN_KEYNUM_SIZE);
|
||||||
|
memcpy(sec, raw + 40, 64);
|
||||||
|
st = GL_SIGN_OK;
|
||||||
|
out:
|
||||||
|
crypto_wipe(raw, sizeof raw);
|
||||||
|
return st;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
gl_sign_check_seckey(const char *path)
|
||||||
|
{
|
||||||
|
uint8_t keynum[GL_SIGN_KEYNUM_SIZE], sec[64];
|
||||||
|
int st = read_seckey(path, keynum, sec);
|
||||||
|
crypto_wipe(sec, sizeof sec);
|
||||||
|
return st;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
gl_sign_verify(const gl_sign_pubkey_t *pub, const gl_sign_sig_t *sig,
|
||||||
|
const uint8_t *msg, size_t len)
|
||||||
|
{
|
||||||
|
if (memcmp(pub->keynum, sig->keynum, GL_SIGN_KEYNUM_SIZE) != 0)
|
||||||
|
return GL_SIGN_ERR_KEYNUM;
|
||||||
|
return crypto_ed25519_check(sig->sig, pub->key, msg, len) == 0
|
||||||
|
? GL_SIGN_OK : GL_SIGN_ERR_BAD;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
gl_sign_verify_file(const char *pubkey_path, const char *msg_path,
|
||||||
|
const char *sig_path)
|
||||||
|
{
|
||||||
|
gl_sign_pubkey_t pub;
|
||||||
|
gl_sign_sig_t sig;
|
||||||
|
int st = gl_sign_read_pubkey(pubkey_path, &pub);
|
||||||
|
if (st != GL_SIGN_OK)
|
||||||
|
return st;
|
||||||
|
st = gl_sign_read_sig(sig_path, &sig);
|
||||||
|
if (st != GL_SIGN_OK)
|
||||||
|
return st;
|
||||||
|
/* Cheap mismatch first: no need to read the message. */
|
||||||
|
if (memcmp(pub.keynum, sig.keynum, GL_SIGN_KEYNUM_SIZE) != 0)
|
||||||
|
return GL_SIGN_ERR_KEYNUM;
|
||||||
|
|
||||||
|
uint8_t *msg;
|
||||||
|
size_t len;
|
||||||
|
st = read_all(msg_path, GL_SIGN_MAX_MSG, &msg, &len);
|
||||||
|
if (st != GL_SIGN_OK)
|
||||||
|
return st;
|
||||||
|
st = gl_sign_verify(&pub, &sig, msg, len);
|
||||||
|
free(msg);
|
||||||
|
return st;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Writes "untrusted comment: COMMENT\n" + base64(raw) + "\n" to an fd
|
||||||
|
* opened with `flags`. */
|
||||||
|
static int
|
||||||
|
write_signify(const char *path, int flags, mode_t mode, const char *comment,
|
||||||
|
const uint8_t *raw, size_t rawlen)
|
||||||
|
{
|
||||||
|
char b64[4 * ((SECKEY_BYTES + 2) / 3) + 1];
|
||||||
|
if (rawlen > SECKEY_BYTES)
|
||||||
|
return GL_SIGN_ERR_WRITE;
|
||||||
|
b64_encode(raw, rawlen, b64);
|
||||||
|
|
||||||
|
int fd = open(path, O_WRONLY | O_CREAT | O_NOFOLLOW | O_CLOEXEC | flags, mode);
|
||||||
|
if (fd < 0)
|
||||||
|
return errno == EEXIST ? GL_SIGN_ERR_EXISTS : GL_SIGN_ERR_WRITE;
|
||||||
|
/* Exactly `mode`, whatever the umask: a secret key 0600, a public
|
||||||
|
* key 0644 (users' gpkg reads the system's keys). */
|
||||||
|
if (fchmod(fd, mode) != 0) {
|
||||||
|
close(fd);
|
||||||
|
return GL_SIGN_ERR_WRITE;
|
||||||
|
}
|
||||||
|
|
||||||
|
FILE *f = fdopen(fd, "w");
|
||||||
|
if (!f) {
|
||||||
|
close(fd);
|
||||||
|
return GL_SIGN_ERR_WRITE;
|
||||||
|
}
|
||||||
|
int bad = fprintf(f, COMMENT_PREFIX "%s\n%s\n", comment, b64) < 0;
|
||||||
|
crypto_wipe(b64, sizeof b64);
|
||||||
|
if (fclose(f) != 0 || bad)
|
||||||
|
return GL_SIGN_ERR_WRITE;
|
||||||
|
return GL_SIGN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
gl_sign_file(const char *seckey_path, const char *msg_path, const char *sig_path)
|
||||||
|
{
|
||||||
|
uint8_t keynum[GL_SIGN_KEYNUM_SIZE], sec[64];
|
||||||
|
int st = read_seckey(seckey_path, keynum, sec);
|
||||||
|
if (st != GL_SIGN_OK)
|
||||||
|
return st;
|
||||||
|
|
||||||
|
uint8_t *msg;
|
||||||
|
size_t len;
|
||||||
|
st = read_all(msg_path, GL_SIGN_MAX_MSG, &msg, &len);
|
||||||
|
if (st != GL_SIGN_OK) {
|
||||||
|
crypto_wipe(sec, sizeof sec);
|
||||||
|
return st;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t raw[SIG_BYTES] = { 'E', 'd' };
|
||||||
|
memcpy(raw + 2, keynum, GL_SIGN_KEYNUM_SIZE);
|
||||||
|
crypto_ed25519_sign(raw + 10, sec, msg, len);
|
||||||
|
crypto_wipe(sec, sizeof sec);
|
||||||
|
free(msg);
|
||||||
|
|
||||||
|
/* "verify with NAME.pub", NAME = the secret key's name minus .sec */
|
||||||
|
const char *base = strrchr(seckey_path, '/');
|
||||||
|
base = base ? base + 1 : seckey_path;
|
||||||
|
size_t blen = strlen(base);
|
||||||
|
if (blen > 4 && strcmp(base + blen - 4, ".sec") == 0)
|
||||||
|
blen -= 4;
|
||||||
|
if (blen > GL_SIGN_MAX_COMMENT - 16)
|
||||||
|
blen = GL_SIGN_MAX_COMMENT - 16;
|
||||||
|
char comment[GL_SIGN_MAX_COMMENT + 1];
|
||||||
|
snprintf(comment, sizeof comment, "verify with %.*s.pub", (int)blen, base);
|
||||||
|
|
||||||
|
return write_signify(sig_path, O_TRUNC, 0644, comment, raw, sizeof raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
random_bytes(uint8_t *buf, size_t n)
|
||||||
|
{
|
||||||
|
while (n > 0) {
|
||||||
|
ssize_t got = getrandom(buf, n, 0);
|
||||||
|
if (got < 0 && errno == EINTR)
|
||||||
|
continue;
|
||||||
|
if (got <= 0)
|
||||||
|
return -1;
|
||||||
|
buf += got;
|
||||||
|
n -= (size_t)got;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
gl_sign_generate(const char *pubkey_path, const char *seckey_path,
|
||||||
|
const char *comment)
|
||||||
|
{
|
||||||
|
if (strchr(comment, '\n') || strlen(comment) > GL_SIGN_MAX_COMMENT - 11)
|
||||||
|
return GL_SIGN_ERR_FORMAT;
|
||||||
|
|
||||||
|
/* rand = seed[32] | keynum[8] | salt[16] */
|
||||||
|
uint8_t rand[56];
|
||||||
|
if (random_bytes(rand, sizeof rand) != 0)
|
||||||
|
return GL_SIGN_ERR_RANDOM;
|
||||||
|
|
||||||
|
uint8_t sec[64], pub[32];
|
||||||
|
crypto_ed25519_key_pair(sec, pub, rand); /* wipes the seed */
|
||||||
|
|
||||||
|
uint8_t sraw[SECKEY_BYTES] = { 'E', 'd', 'B', 'K', 0, 0, 0, 0 };
|
||||||
|
memcpy(sraw + 8, rand + 40, 16); /* salt (unused at 0 rounds) */
|
||||||
|
uint8_t digest[64];
|
||||||
|
crypto_sha512(digest, sec, sizeof sec);
|
||||||
|
memcpy(sraw + 24, digest, 8); /* checksum */
|
||||||
|
memcpy(sraw + 32, rand + 32, GL_SIGN_KEYNUM_SIZE);
|
||||||
|
memcpy(sraw + 40, sec, sizeof sec);
|
||||||
|
|
||||||
|
uint8_t praw[PUBKEY_BYTES] = { 'E', 'd' };
|
||||||
|
memcpy(praw + 2, rand + 32, GL_SIGN_KEYNUM_SIZE);
|
||||||
|
memcpy(praw + 10, pub, sizeof pub);
|
||||||
|
|
||||||
|
char c[GL_SIGN_MAX_COMMENT + 1];
|
||||||
|
snprintf(c, sizeof c, "%s secret key", comment);
|
||||||
|
int st = write_signify(seckey_path, O_EXCL, 0600, c, sraw, sizeof sraw);
|
||||||
|
if (st == GL_SIGN_OK) {
|
||||||
|
snprintf(c, sizeof c, "%s public key", comment);
|
||||||
|
st = write_signify(pubkey_path, O_EXCL, 0644, c, praw, sizeof praw);
|
||||||
|
/* Never leave a secret key without its public half. */
|
||||||
|
if (st != GL_SIGN_OK)
|
||||||
|
unlink(seckey_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
crypto_wipe(rand, sizeof rand);
|
||||||
|
crypto_wipe(sec, sizeof sec);
|
||||||
|
crypto_wipe(sraw, sizeof sraw);
|
||||||
|
crypto_wipe(digest, sizeof digest);
|
||||||
|
return st;
|
||||||
|
}
|
||||||
+82
@@ -0,0 +1,82 @@
|
|||||||
|
#ifndef GL_SIGN_H_
|
||||||
|
#define GL_SIGN_H_
|
||||||
|
|
||||||
|
/*
|
||||||
|
* gl_sign: Ed25519 signatures in OpenBSD signify's file formats
|
||||||
|
* (REPO_DESIGN.txt section 2). Private to libglacier_verify.so, like
|
||||||
|
* sha256.h: no public header is installed.
|
||||||
|
*
|
||||||
|
* Every file is two lines, "untrusted comment: ..." and base64 of:
|
||||||
|
* public key "Ed" | keynum[8] | pubkey[32]
|
||||||
|
* signature "Ed" | keynum[8] | sig[64]
|
||||||
|
* secret key "Ed" | "BK" | rounds[4, big-endian] | salt[16] |
|
||||||
|
* checksum[8] | keynum[8] | seckey[64]
|
||||||
|
* Only unencrypted secret keys (rounds == 0, `signify -G -n`) are
|
||||||
|
* read; an encrypted one is GL_SIGN_ERR_ENCRYPTED.
|
||||||
|
*
|
||||||
|
* Signatures are pure Ed25519 over the whole message, as signify's, so
|
||||||
|
* `signify -V -p KEY.pub -m FILE` checks what gl_sign_file makes and
|
||||||
|
* gl_sign_verify_file checks what signify makes.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define GL_SIGN_KEYNUM_SIZE 8
|
||||||
|
/* Largest message signed or verified: the whole file is read. */
|
||||||
|
#define GL_SIGN_MAX_MSG (64u * 1024u * 1024u)
|
||||||
|
/* Longest comment signify accepts. */
|
||||||
|
#define GL_SIGN_MAX_COMMENT 1024
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
GL_SIGN_OK = 0,
|
||||||
|
GL_SIGN_ERR_IO = 1, /* a file can't be opened or read */
|
||||||
|
GL_SIGN_ERR_FORMAT = 2, /* not a well-formed file of the expected kind */
|
||||||
|
GL_SIGN_ERR_ENCRYPTED = 3, /* a passphrase-protected secret key */
|
||||||
|
GL_SIGN_ERR_KEYNUM = 4, /* the signature was made by another key */
|
||||||
|
GL_SIGN_ERR_BAD = 5, /* the signature does not verify */
|
||||||
|
GL_SIGN_ERR_TOOBIG = 6, /* message larger than GL_SIGN_MAX_MSG */
|
||||||
|
GL_SIGN_ERR_RANDOM = 7, /* no randomness for a new key */
|
||||||
|
GL_SIGN_ERR_EXISTS = 8, /* a key file to create already exists */
|
||||||
|
GL_SIGN_ERR_WRITE = 9, /* a file to write can't be created or written */
|
||||||
|
} gl_sign_status_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t keynum[GL_SIGN_KEYNUM_SIZE];
|
||||||
|
uint8_t key[32];
|
||||||
|
} gl_sign_pubkey_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t keynum[GL_SIGN_KEYNUM_SIZE];
|
||||||
|
uint8_t sig[64];
|
||||||
|
} gl_sign_sig_t;
|
||||||
|
|
||||||
|
int gl_sign_read_pubkey(const char *path, gl_sign_pubkey_t *out);
|
||||||
|
/* Reads a secret key only to check it (then wipes it). */
|
||||||
|
int gl_sign_check_seckey(const char *path);
|
||||||
|
int gl_sign_read_sig(const char *path, gl_sign_sig_t *out);
|
||||||
|
|
||||||
|
/* Checks `sig` over msg[0..len) with `pub`: GL_SIGN_ERR_KEYNUM before
|
||||||
|
* any crypto if the keynums differ, else GL_SIGN_OK or GL_SIGN_ERR_BAD. */
|
||||||
|
int gl_sign_verify(const gl_sign_pubkey_t *pub, const gl_sign_sig_t *sig,
|
||||||
|
const uint8_t *msg, size_t len);
|
||||||
|
|
||||||
|
/* Reads all three files and verifies. The status names the first
|
||||||
|
* problem found, in the order: public key, signature, message, check. */
|
||||||
|
int gl_sign_verify_file(const char *pubkey_path, const char *msg_path,
|
||||||
|
const char *sig_path);
|
||||||
|
|
||||||
|
/* Signs msg_path with the secret key, writing sig_path (replaced if it
|
||||||
|
* exists, never followed if it's a symlink). The signature's comment
|
||||||
|
* is "verify with NAME.pub", NAME being the secret key's file name
|
||||||
|
* without ".sec", as signify writes it. */
|
||||||
|
int gl_sign_file(const char *seckey_path, const char *msg_path,
|
||||||
|
const char *sig_path);
|
||||||
|
|
||||||
|
/* Makes a new keypair. Neither file may exist (GL_SIGN_ERR_EXISTS).
|
||||||
|
* The secret key is created 0600 and unencrypted; the comments are
|
||||||
|
* "COMMENT public key" / "COMMENT secret key". */
|
||||||
|
int gl_sign_generate(const char *pubkey_path, const char *seckey_path,
|
||||||
|
const char *comment);
|
||||||
|
|
||||||
|
#endif
|
||||||
+275
-113
@@ -12,21 +12,75 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "deps.h"
|
||||||
#include "istoreutils.h"
|
#include "istoreutils.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "transaction.h"
|
#include "transaction.h"
|
||||||
|
|
||||||
#define GL_STAGE_BASE "/glacier/usr/stage"
|
/* The one directory a scope owns; everything below derives from it.
|
||||||
#define GL_LOCK_BASE "/glacier/usr/lock"
|
* See the layout comment in common.h. */
|
||||||
#define GL_OLD_BASE "/glacier/usr/old"
|
/* `sysroot` is the install root ("" for the running system, see
|
||||||
|
* gl_context_t). User scope never has one (set_sysroot refuses it). */
|
||||||
|
static void
|
||||||
|
scope_base(gl_ctx_scope_t scope, uid_t uid, const char *sysroot, char *out)
|
||||||
|
{
|
||||||
|
switch (scope) {
|
||||||
|
case GL_SCOPE_USR:
|
||||||
|
gl_usr_base(uid, out, PATH_MAX);
|
||||||
|
break;
|
||||||
|
case GL_SCOPE_SYS:
|
||||||
|
snprintf(out, PATH_MAX, "%s%s", sysroot, GL_SYS_ROOT);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#define GL_USR_INDEX "/glacier/usr/index"
|
static void
|
||||||
#define GL_USR_STORE "/glacier/usr/store"
|
scope_subdir(gl_ctx_scope_t scope, uid_t uid, const char *sysroot,
|
||||||
#define GL_USR_LINKS "/glacier/usr/links"
|
const char *name, char *out)
|
||||||
|
{
|
||||||
|
char base[PATH_MAX];
|
||||||
|
scope_base(scope, uid, sysroot, base);
|
||||||
|
snprintf(out, PATH_MAX, "%s/%s", base, name);
|
||||||
|
}
|
||||||
|
|
||||||
#define GL_SYS_INDEX "/glacier/sys/index"
|
int
|
||||||
#define GL_SYS_STORE "/glacier/sys/store"
|
gl_check_sysroot(const char *sysroot)
|
||||||
#define GL_SYS_LINKS "/glacier/sys/links"
|
{
|
||||||
|
char root[PATH_MAX];
|
||||||
|
if (gl_normalize_sysroot(sysroot, root, sizeof(root)) != 0) {
|
||||||
|
lg_printf(2, "Refusing install root %s: not an absolute path without . or .. components.",
|
||||||
|
sysroot ? sysroot : "(null)");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (root[0] == '\0') { return 0; }
|
||||||
|
|
||||||
|
char bad[PATH_MAX];
|
||||||
|
const char *why = "";
|
||||||
|
if (gl_sysroot_trusted(root, bad, sizeof(bad), &why) != 0) {
|
||||||
|
lg_printf(2, "Refusing install root %s: %s is %s.", root, bad, why);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Store the install root (gl_normalize_sysroot). Only system scope may
|
||||||
|
* have one (IMAGE_DESIGN section 3): per-user scope has no business in
|
||||||
|
* an image. */
|
||||||
|
static int
|
||||||
|
set_sysroot(gl_context_t *ctx, gl_ctx_scope_t scope, const char *sysroot)
|
||||||
|
{
|
||||||
|
ctx->sysroot[0] = '\0';
|
||||||
|
if (gl_check_sysroot(sysroot) != 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
gl_normalize_sysroot(sysroot, ctx->sysroot, sizeof(ctx->sysroot));
|
||||||
|
if (scope == GL_SCOPE_USR && ctx->sysroot[0] != '\0') {
|
||||||
|
lg_printf(2, "Refusing a user-scope context with install root %s.", ctx->sysroot);
|
||||||
|
ctx->sysroot[0] = '\0';
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
fsync_dir(const char *path)
|
fsync_dir(const char *path)
|
||||||
@@ -56,28 +110,19 @@ atomic_swap(const char *live, const char *stage, const char *backup)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
derive_base_paths(gl_ctx_scope_t scope, uid_t uid, char *index_out,
|
derive_base_paths(gl_ctx_scope_t scope, uid_t uid, const char *sysroot,
|
||||||
char *store_out, char *links_out)
|
char *index_out, char *store_out, char *links_out)
|
||||||
{
|
{
|
||||||
switch (scope) {
|
scope_subdir(scope, uid, sysroot, "index", index_out);
|
||||||
case GL_SCOPE_USR:
|
scope_subdir(scope, uid, sysroot, "store", store_out);
|
||||||
snprintf(index_out, PATH_MAX, "/glacier/usr/index/%u", uid);
|
/* For system scope this is the DEFAULT links location — for
|
||||||
snprintf(store_out, PATH_MAX, "/glacier/usr/store/%u", uid);
|
* packages the operator explicitly installs under system scope that
|
||||||
snprintf(links_out, PATH_MAX, "/glacier/usr/links/%u", uid);
|
* aren't part of the base system. Base-repo packages get routed to
|
||||||
break;
|
* /usr instead, but that's a per-package decision made in
|
||||||
case GL_SCOPE_SYS:
|
* gl_link_pkg/gl_relink_store (which know a package's repo), not
|
||||||
strncpy(index_out, "/glacier/sys/index", PATH_MAX - 1);
|
* something the context can decide up front. See GL_BASE_REPO in
|
||||||
strncpy(store_out, "/glacier/sys/store", PATH_MAX - 1);
|
* istoreutils.c. */
|
||||||
/* This is the DEFAULT system-scope links location — for
|
scope_subdir(scope, uid, sysroot, "links", links_out);
|
||||||
* packages the operator explicitly installs under system
|
|
||||||
* scope that aren't part of the base system. Base-repo
|
|
||||||
* packages get routed to /usr instead, but that's a
|
|
||||||
* per-package decision made in gl_link_pkg/gl_relink_store
|
|
||||||
* (which know a package's repo), not something the context
|
|
||||||
* can decide up front. See GL_BASE_REPO in istoreutils.c. */
|
|
||||||
strncpy(links_out, "/glacier/sys/links", PATH_MAX - 1);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@@ -100,7 +145,13 @@ hardlink_tree(const char *src, const char *dest)
|
|||||||
|
|
||||||
struct dirent *ent;
|
struct dirent *ent;
|
||||||
while ((ent = readdir(dir))) {
|
while ((ent = readdir(dir))) {
|
||||||
if (ent->d_name[0] == '.') { continue; }
|
/* Only . and .. — dotfiles are real content here: a package's
|
||||||
|
* own dotfiles, and the store's .displaced originals (see
|
||||||
|
* gl_link_pkg), both of which would otherwise be dropped from
|
||||||
|
* the stage and lost on commit. */
|
||||||
|
if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
char s[PATH_MAX], d[PATH_MAX];
|
char s[PATH_MAX], d[PATH_MAX];
|
||||||
snprintf(s, sizeof(s), "%s/%s", src, ent->d_name);
|
snprintf(s, sizeof(s), "%s/%s", src, ent->d_name);
|
||||||
@@ -110,7 +161,9 @@ hardlink_tree(const char *src, const char *dest)
|
|||||||
if(lstat(s, &st) != 0) { continue; }
|
if(lstat(s, &st) != 0) { continue; }
|
||||||
|
|
||||||
if (S_ISDIR(st.st_mode)) {
|
if (S_ISDIR(st.st_mode)) {
|
||||||
if (mkdir(d, st.st_mode & 0777) != 0 && errno != EEXIST) {
|
/* Exact mode, not umask-filtered: the stage becomes
|
||||||
|
* live, so seeding must not tighten what it copies. */
|
||||||
|
if (gl_mkdir_exact(d, st.st_mode & 07777) != 0) {
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -140,6 +193,13 @@ hardlink_tree(const char *src, const char *dest)
|
|||||||
|
|
||||||
int
|
int
|
||||||
gl_init_live_context(gl_context_t *ctx, gl_ctx_scope_t scope, uid_t uid)
|
gl_init_live_context(gl_context_t *ctx, gl_ctx_scope_t scope, uid_t uid)
|
||||||
|
{
|
||||||
|
return gl_init_live_context_at(ctx, scope, uid, "/");
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
gl_init_live_context_at(gl_context_t *ctx, gl_ctx_scope_t scope, uid_t uid,
|
||||||
|
const char *sysroot)
|
||||||
{
|
{
|
||||||
if (!ctx) {
|
if (!ctx) {
|
||||||
return -1;
|
return -1;
|
||||||
@@ -149,16 +209,29 @@ gl_init_live_context(gl_context_t *ctx, gl_ctx_scope_t scope, uid_t uid)
|
|||||||
ctx->mode = GL_CTX_LIVE;
|
ctx->mode = GL_CTX_LIVE;
|
||||||
ctx->scope = scope;
|
ctx->scope = scope;
|
||||||
ctx->lock_fd = -1;
|
ctx->lock_fd = -1;
|
||||||
|
ctx->overwrite = 0;
|
||||||
|
ctx->link_refusals = 0;
|
||||||
|
ctx->strict = 0;
|
||||||
|
if (set_sysroot(ctx, scope, sysroot) != 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
strncpy(ctx->root_path, "/glacier", PATH_MAX - 1);
|
snprintf(ctx->root_path, PATH_MAX, "%s/glacier", ctx->sysroot);
|
||||||
derive_base_paths(scope, uid, ctx->index_path, ctx->store_path,
|
derive_base_paths(scope, uid, ctx->sysroot, ctx->index_path,
|
||||||
ctx->links_path);
|
ctx->store_path, ctx->links_path);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
gl_txn_status_t
|
gl_txn_status_t
|
||||||
gl_init_stage_context(gl_context_t *ctx, gl_ctx_scope_t scope, uid_t uid)
|
gl_init_stage_context(gl_context_t *ctx, gl_ctx_scope_t scope, uid_t uid)
|
||||||
|
{
|
||||||
|
return gl_init_stage_context_at(ctx, scope, uid, "/");
|
||||||
|
}
|
||||||
|
|
||||||
|
gl_txn_status_t
|
||||||
|
gl_init_stage_context_at(gl_context_t *ctx, gl_ctx_scope_t scope, uid_t uid,
|
||||||
|
const char *sysroot)
|
||||||
{
|
{
|
||||||
if (!ctx) {
|
if (!ctx) {
|
||||||
return GL_TXN_ERR_NO_TXN;
|
return GL_TXN_ERR_NO_TXN;
|
||||||
@@ -168,51 +241,77 @@ gl_init_stage_context(gl_context_t *ctx, gl_ctx_scope_t scope, uid_t uid)
|
|||||||
ctx->mode = GL_CTX_STAGE;
|
ctx->mode = GL_CTX_STAGE;
|
||||||
ctx->scope = scope;
|
ctx->scope = scope;
|
||||||
ctx->lock_fd = -1;
|
ctx->lock_fd = -1;
|
||||||
|
ctx->overwrite = 0;
|
||||||
|
ctx->link_refusals = 0;
|
||||||
|
ctx->strict = 0;
|
||||||
|
if (set_sysroot(ctx, scope, sysroot) != 0) {
|
||||||
|
return GL_TXN_ERR_PERM;
|
||||||
|
}
|
||||||
|
|
||||||
strncpy(ctx->root_path, "/glacier", PATH_MAX - 1);
|
snprintf(ctx->root_path, PATH_MAX, "%s/glacier", ctx->sysroot);
|
||||||
|
|
||||||
|
if (scope == GL_SCOPE_USR) {
|
||||||
|
switch (gl_usr_base_check(uid)) {
|
||||||
|
case GL_USR_BASE_OK:
|
||||||
|
break;
|
||||||
|
case GL_USR_BASE_MISSING:
|
||||||
|
lg_printf(2, "No Glacier directory for UID %u. Run doas gstore -n first.", uid);
|
||||||
|
return GL_TXN_ERR_PERM;
|
||||||
|
case GL_USR_BASE_UNSAFE_ROOT:
|
||||||
|
lg_printf(2, "Refusing to run: %s is not root-owned, or is group/world-writable.",
|
||||||
|
GL_USR_ROOT);
|
||||||
|
return GL_TXN_ERR_PERM;
|
||||||
|
case GL_USR_BASE_UNSAFE:
|
||||||
|
lg_printf(2, "Refusing to run: %s/%u is not a directory owned by UID %u with mode 0700.",
|
||||||
|
GL_USR_ROOT, uid, uid);
|
||||||
|
return GL_TXN_ERR_PERM;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
char stage_base[PATH_MAX - 7];
|
char stage_base[PATH_MAX - 7];
|
||||||
|
scope_subdir(scope, uid, ctx->sysroot, "stage", stage_base);
|
||||||
switch (scope) {
|
|
||||||
case GL_SCOPE_USR:
|
|
||||||
snprintf(stage_base, sizeof(stage_base), "/glacier/usr/stage/%u", uid);
|
|
||||||
break;
|
|
||||||
case GL_SCOPE_SYS:
|
|
||||||
strncpy(stage_base, "/glacier/sys/stage", sizeof(stage_base));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
snprintf(ctx->index_path, PATH_MAX, "%s/index", stage_base);
|
snprintf(ctx->index_path, PATH_MAX, "%s/index", stage_base);
|
||||||
snprintf(ctx->store_path, PATH_MAX, "%s/store", stage_base);
|
snprintf(ctx->store_path, PATH_MAX, "%s/store", stage_base);
|
||||||
snprintf(ctx->links_path, PATH_MAX, "%s/links", stage_base);
|
snprintf(ctx->links_path, PATH_MAX, "%s/links", stage_base);
|
||||||
|
|
||||||
struct stat st;
|
/* Lock BEFORE clearing a leftover stage: the other order let a
|
||||||
if (stat(stage_base, &st) == 0) {
|
* second invocation wipe a running transaction's stage and only
|
||||||
if (gl_rmdir_recursive(stage_base) != 0) {
|
* then discover it couldn't get the lock. */
|
||||||
return GL_TXN_ERR_MKDIR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gl_mkdirp(GL_LOCK_BASE, 0700) != 0 && errno != EEXIST) {
|
|
||||||
return GL_TXN_ERR_MKDIR;
|
|
||||||
}
|
|
||||||
|
|
||||||
gl_txn_status_t lock_status = gl_begin_transaction(ctx);
|
gl_txn_status_t lock_status = gl_begin_transaction(ctx);
|
||||||
if (lock_status != GL_TXN_OK) {
|
if (lock_status != GL_TXN_OK) {
|
||||||
return lock_status;
|
return lock_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gl_mkdirp(ctx->index_path, 0700) != 0) {
|
/* EBUSY: stage_base is itself a mount point. Its contents are gone
|
||||||
|
* and the directory stays, which is all a fresh stage needs (the
|
||||||
|
* mkdirps below tolerate it existing). Commit then reports
|
||||||
|
* GL_TXN_ERR_XDEV, as it should for a stage on another filesystem. */
|
||||||
|
struct stat st;
|
||||||
|
if (stat(stage_base, &st) == 0) {
|
||||||
|
if (gl_rmdir_recursive(stage_base) != 0 && errno != EBUSY) {
|
||||||
|
gl_abort_transaction(ctx);
|
||||||
|
return GL_TXN_ERR_MKDIR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* chmod, not just mkdir's mode: the stage becomes live on commit,
|
||||||
|
* and a system store must be 0755 whatever syspkg's umask is. */
|
||||||
|
mode_t dir_mode = gl_scope_dir_mode(scope);
|
||||||
|
if (gl_mkdirp(ctx->index_path, dir_mode) != 0 ||
|
||||||
|
chmod(ctx->index_path, dir_mode) != 0) {
|
||||||
gl_abort_transaction(ctx);
|
gl_abort_transaction(ctx);
|
||||||
return GL_TXN_ERR_MKDIR;
|
return GL_TXN_ERR_MKDIR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gl_mkdirp(ctx->store_path, 0700) != 0) {
|
if (gl_mkdirp(ctx->store_path, dir_mode) != 0 ||
|
||||||
|
chmod(ctx->store_path, dir_mode) != 0) {
|
||||||
gl_abort_transaction(ctx);
|
gl_abort_transaction(ctx);
|
||||||
return GL_TXN_ERR_MKDIR;
|
return GL_TXN_ERR_MKDIR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gl_mkdirp(ctx->links_path, 0700) != 0) {
|
if (gl_mkdirp(ctx->links_path, dir_mode) != 0 ||
|
||||||
|
chmod(ctx->links_path, dir_mode) != 0) {
|
||||||
gl_abort_transaction(ctx);
|
gl_abort_transaction(ctx);
|
||||||
return GL_TXN_ERR_MKDIR;
|
return GL_TXN_ERR_MKDIR;
|
||||||
}
|
}
|
||||||
@@ -223,7 +322,7 @@ gl_init_stage_context(gl_context_t *ctx, gl_ctx_scope_t scope, uid_t uid)
|
|||||||
}
|
}
|
||||||
|
|
||||||
char live_index[PATH_MAX], live_store[PATH_MAX], live_links[PATH_MAX];
|
char live_index[PATH_MAX], live_store[PATH_MAX], live_links[PATH_MAX];
|
||||||
derive_base_paths(scope, uid, live_index, live_store, live_links);
|
derive_base_paths(scope, uid, ctx->sysroot, live_index, live_store, live_links);
|
||||||
/* live_links is populated (derive_base_paths always fills all
|
/* live_links is populated (derive_base_paths always fills all
|
||||||
* three) but intentionally unused below — see the comment on the
|
* three) but intentionally unused below — see the comment on the
|
||||||
* hardlink_tree call. */
|
* hardlink_tree call. */
|
||||||
@@ -239,13 +338,97 @@ gl_init_stage_context(gl_context_t *ctx, gl_ctx_scope_t scope, uid_t uid)
|
|||||||
* area are on different filesystems. */
|
* area are on different filesystems. */
|
||||||
if (hardlink_tree(live_index, ctx->index_path) != 0 ||
|
if (hardlink_tree(live_index, ctx->index_path) != 0 ||
|
||||||
hardlink_tree(live_store, ctx->store_path) != 0) {
|
hardlink_tree(live_store, ctx->store_path) != 0) {
|
||||||
|
/* link() can't cross filesystems: a stage on a different
|
||||||
|
* fs than live is caught here, before anything is staged,
|
||||||
|
* rather than at commit's rename. Same condition, same
|
||||||
|
* status as commit's check. */
|
||||||
|
int seed_errno = errno;
|
||||||
gl_abort_transaction(ctx);
|
gl_abort_transaction(ctx);
|
||||||
return GL_TXN_ERR_MKDIR;
|
return seed_errno == EXDEV ? GL_TXN_ERR_XDEV : GL_TXN_ERR_MKDIR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return GL_TXN_OK;
|
return GL_TXN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* parent/name into out (PATH_MAX), created with `mode` if missing, then
|
||||||
|
* refused unless it is a real directory owned by `owner` with exactly
|
||||||
|
* that mode. 0, or -1 having printed why. */
|
||||||
|
static int
|
||||||
|
checked_subdir(const char *parent, const char *name, uid_t owner, mode_t mode,
|
||||||
|
char *out)
|
||||||
|
{
|
||||||
|
struct stat st;
|
||||||
|
snprintf(out, PATH_MAX, "%s/%s", parent, name);
|
||||||
|
if (gl_mkdir_exact(out, mode) != 0 && errno != EEXIST) {
|
||||||
|
lg_printf(2, "Cannot create %s: %s", out, strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (lstat(out, &st) != 0 || !S_ISDIR(st.st_mode) || st.st_uid != owner ||
|
||||||
|
(st.st_mode & 07777) != mode) {
|
||||||
|
lg_printf(2, "Refusing %s: not a directory owned by UID %u with mode %o.",
|
||||||
|
out, owner, (unsigned)mode);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* <base>/NAME: a directory for state a scope keeps beside its index and
|
||||||
|
* store ("repos": the accepted repository indexes, REPO_DESIGN.txt
|
||||||
|
* section 5). The base must already exist and be the scope's (owned by
|
||||||
|
* root, or by the uid for user scope; no group/world write). NAME is
|
||||||
|
* created if missing with the scope's mode, and is then refused unless
|
||||||
|
* it is a real directory owned like the base with exactly that mode.
|
||||||
|
* The path goes to out (PATH_MAX). 0, or -1 having printed why.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
gl_scope_state_dir(const gl_context_t *ctx, const char *name, char *out)
|
||||||
|
{
|
||||||
|
if (!ctx || !out || !gl_valid_pkg_ident(name)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
uid_t owner = ctx->scope == GL_SCOPE_SYS ? 0 : ctx->uid;
|
||||||
|
mode_t mode = gl_scope_dir_mode(ctx->scope);
|
||||||
|
|
||||||
|
char base[PATH_MAX];
|
||||||
|
scope_base(ctx->scope, ctx->uid, ctx->sysroot, base);
|
||||||
|
struct stat st;
|
||||||
|
if (ctx->scope == GL_SCOPE_USR && gl_usr_base_check(ctx->uid) != GL_USR_BASE_OK) {
|
||||||
|
lg_printf(2, "Cannot open %s: not a private directory owned by UID %u.",
|
||||||
|
base, ctx->uid);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (lstat(base, &st) != 0) {
|
||||||
|
lg_printf(2, "Cannot open %s: %s", base, strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (!S_ISDIR(st.st_mode) || st.st_uid != owner || (st.st_mode & 022)) {
|
||||||
|
lg_printf(2, "Refusing %s: not a directory owned by UID %u, or group/world-writable.",
|
||||||
|
base, owner);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return checked_subdir(base, name, owner, mode, out);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* <base>/cache/REPO: where packages fetched from REPO are downloaded
|
||||||
|
* (REPO_DESIGN.txt section 5). Both levels are made and checked as
|
||||||
|
* gl_scope_state_dir makes and checks NAME. 0, or -1 having printed why.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
gl_scope_cache_dir(const gl_context_t *ctx, const char *repo, char *out)
|
||||||
|
{
|
||||||
|
char cache[PATH_MAX];
|
||||||
|
if (!ctx || !out || !gl_valid_pkg_ident(repo) ||
|
||||||
|
gl_scope_state_dir(ctx, "cache", cache) != 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return checked_subdir(cache, repo,
|
||||||
|
ctx->scope == GL_SCOPE_SYS ? 0 : ctx->uid,
|
||||||
|
gl_scope_dir_mode(ctx->scope), out);
|
||||||
|
}
|
||||||
|
|
||||||
gl_txn_status_t
|
gl_txn_status_t
|
||||||
gl_begin_transaction(gl_context_t *ctx)
|
gl_begin_transaction(gl_context_t *ctx)
|
||||||
{
|
{
|
||||||
@@ -254,15 +437,7 @@ gl_begin_transaction(gl_context_t *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
char lock_path[PATH_MAX];
|
char lock_path[PATH_MAX];
|
||||||
switch (ctx->scope) {
|
scope_subdir(ctx->scope, ctx->uid, ctx->sysroot, "lock", lock_path);
|
||||||
case GL_SCOPE_USR:
|
|
||||||
snprintf(lock_path, PATH_MAX, "%s/%u.lock", GL_LOCK_BASE,
|
|
||||||
ctx->uid);
|
|
||||||
break;
|
|
||||||
case GL_SCOPE_SYS:
|
|
||||||
snprintf(lock_path, PATH_MAX, "%s/sys.lock", GL_LOCK_BASE);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
int fd = open(lock_path, O_WRONLY | O_CREAT, 0600);
|
int fd = open(lock_path, O_WRONLY | O_CREAT, 0600);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
@@ -288,17 +463,20 @@ gl_commit_transaction(gl_context_t *ctx)
|
|||||||
return GL_TXN_ERR_NO_TXN;
|
return GL_TXN_ERR_NO_TXN;
|
||||||
}
|
}
|
||||||
|
|
||||||
char stage_base[PATH_MAX];
|
/* Dependencies and conflicts (ROADMAP 2.3). The CLIs check the plan
|
||||||
switch (ctx->scope) {
|
* before prompting; this holds every other caller of the library to
|
||||||
case GL_SCOPE_USR:
|
* the same rules. gl_check_txn reports each problem itself. */
|
||||||
snprintf(stage_base, PATH_MAX, "/glacier/usr/stage/%u",
|
int dep_problems = gl_check_txn(ctx);
|
||||||
ctx->uid);
|
if (dep_problems != 0) {
|
||||||
break;
|
if (dep_problems < 0) {
|
||||||
case GL_SCOPE_SYS:
|
lg_printf(2, "Cannot read the package store to check dependencies.");
|
||||||
strncpy(stage_base, "/glacier/sys/stage", PATH_MAX - 1);
|
}
|
||||||
break;
|
return GL_TXN_ERR_DEPS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char stage_base[PATH_MAX];
|
||||||
|
scope_subdir(ctx->scope, ctx->uid, ctx->sysroot, "stage", stage_base);
|
||||||
|
|
||||||
int same = check_same_filesystem(ctx->root_path, stage_base);
|
int same = check_same_filesystem(ctx->root_path, stage_base);
|
||||||
if (same < 0) {
|
if (same < 0) {
|
||||||
return GL_TXN_ERR_RENAME; /* failed to stat either side */
|
return GL_TXN_ERR_RENAME; /* failed to stat either side */
|
||||||
@@ -309,19 +487,12 @@ gl_commit_transaction(gl_context_t *ctx)
|
|||||||
|
|
||||||
/* Derive live paths the same way gl_init_live_context would */
|
/* Derive live paths the same way gl_init_live_context would */
|
||||||
char live_index[PATH_MAX], live_store[PATH_MAX], live_links[PATH_MAX];
|
char live_index[PATH_MAX], live_store[PATH_MAX], live_links[PATH_MAX];
|
||||||
derive_base_paths(ctx->scope, ctx->uid, live_index, live_store,
|
derive_base_paths(ctx->scope, ctx->uid, ctx->sysroot, live_index,
|
||||||
live_links);
|
live_store, live_links);
|
||||||
|
|
||||||
/* Derive old/backup paths */
|
/* Derive old/backup paths */
|
||||||
char old_base[PATH_MAX];
|
char old_base[PATH_MAX];
|
||||||
switch (ctx->scope) {
|
scope_subdir(ctx->scope, ctx->uid, ctx->sysroot, "old", old_base);
|
||||||
case GL_SCOPE_USR:
|
|
||||||
snprintf(old_base, PATH_MAX, "/glacier/usr/old/%u", ctx->uid);
|
|
||||||
break;
|
|
||||||
case GL_SCOPE_SYS:
|
|
||||||
strncpy(old_base, "/glacier/sys/old", PATH_MAX - 1);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
char old_index[PATH_MAX], old_store[PATH_MAX], old_links[PATH_MAX];
|
char old_index[PATH_MAX], old_store[PATH_MAX], old_links[PATH_MAX];
|
||||||
snprintf(old_index, PATH_MAX, "%s/index", old_base);
|
snprintf(old_index, PATH_MAX, "%s/index", old_base);
|
||||||
@@ -355,27 +526,24 @@ gl_commit_transaction(gl_context_t *ctx)
|
|||||||
return GL_TXN_ERR_RENAME;
|
return GL_TXN_ERR_RENAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* fsync the parent directories, not the uid subdirs */
|
/* fsync the directory the renames happened in */
|
||||||
switch (ctx->scope) {
|
char base[PATH_MAX];
|
||||||
case GL_SCOPE_USR:
|
scope_base(ctx->scope, ctx->uid, ctx->sysroot, base);
|
||||||
fsync_dir("/glacier/usr/index");
|
fsync_dir(base);
|
||||||
fsync_dir("/glacier/usr/store");
|
if (ctx->scope == GL_SCOPE_SYS) {
|
||||||
fsync_dir("/glacier/usr/links");
|
char usr[PATH_MAX];
|
||||||
break;
|
snprintf(usr, sizeof(usr), "%s/usr", ctx->sysroot);
|
||||||
case GL_SCOPE_SYS:
|
fsync_dir(usr); /* base-repo packages land here instead */
|
||||||
fsync_dir("/glacier/sys/index");
|
|
||||||
fsync_dir("/glacier/sys/store");
|
|
||||||
fsync_dir("/glacier/sys/links");
|
|
||||||
fsync_dir("/usr"); /* base-repo packages land here instead */
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gl_context_t live_ctx;
|
gl_context_t live_ctx;
|
||||||
gl_init_live_context(&live_ctx, ctx->scope, ctx->uid);
|
gl_init_live_context_at(&live_ctx, ctx->scope, ctx->uid,
|
||||||
|
ctx->sysroot[0] ? ctx->sysroot : "/");
|
||||||
|
|
||||||
if (gl_relink_store(&live_ctx) != 0) {
|
if (gl_relink_store(&live_ctx) != 0) {
|
||||||
lg_printf(2, "Post-commit relink incomplete for uid %u", ctx->uid);
|
lg_printf(2, "Post-commit relink incomplete for uid %u", ctx->uid);
|
||||||
}
|
}
|
||||||
|
ctx->link_refusals = live_ctx.link_refusals;
|
||||||
|
|
||||||
gl_rmdir_recursive(old_base);
|
gl_rmdir_recursive(old_base);
|
||||||
|
|
||||||
@@ -391,21 +559,15 @@ gl_commit_transaction(gl_context_t *ctx)
|
|||||||
gl_txn_status_t
|
gl_txn_status_t
|
||||||
gl_abort_transaction(gl_context_t *ctx)
|
gl_abort_transaction(gl_context_t *ctx)
|
||||||
{
|
{
|
||||||
if (!ctx) {
|
/* Only the lock holder's stage is its own to remove: without the
|
||||||
|
* lock, this would wipe another process's running transaction. */
|
||||||
|
if (!ctx || ctx->lock_fd < 0) {
|
||||||
return GL_TXN_ERR_NO_TXN;
|
return GL_TXN_ERR_NO_TXN;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Remove stage area — live is untouched */
|
/* Remove stage area — live is untouched */
|
||||||
char stage_uid[PATH_MAX];
|
char stage_uid[PATH_MAX];
|
||||||
switch (ctx->scope) {
|
scope_subdir(ctx->scope, ctx->uid, ctx->sysroot, "stage", stage_uid);
|
||||||
case GL_SCOPE_USR:
|
|
||||||
snprintf(stage_uid, PATH_MAX, "/glacier/usr/stage/%u",
|
|
||||||
ctx->uid);
|
|
||||||
break;
|
|
||||||
case GL_SCOPE_SYS:
|
|
||||||
strncpy(stage_uid, "/glacier/sys/stage", PATH_MAX - 1);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
gl_rmdir_recursive(stage_uid); /* best-effort; ignore errors */
|
gl_rmdir_recursive(stage_uid); /* best-effort; ignore errors */
|
||||||
|
|
||||||
|
|||||||
+82
-1
@@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#define GL_UID_NONE ((uid_t)0)
|
#define GL_UID_NONE ((uid_t)0)
|
||||||
@@ -19,6 +21,22 @@ typedef enum {
|
|||||||
GL_SCOPE_SYS
|
GL_SCOPE_SYS
|
||||||
} gl_ctx_scope_t;
|
} gl_ctx_scope_t;
|
||||||
|
|
||||||
|
/* Modes for what glacier creates in a scope. System scope is
|
||||||
|
* world-readable, like /usr: its store is where /usr's links point, so
|
||||||
|
* every user must be able to traverse it, and user-scope dependency
|
||||||
|
* checks read its index. User scope stays private to its uid. */
|
||||||
|
static inline mode_t
|
||||||
|
gl_scope_dir_mode(gl_ctx_scope_t scope)
|
||||||
|
{
|
||||||
|
return scope == GL_SCOPE_SYS ? 0755 : 0700;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline mode_t
|
||||||
|
gl_scope_file_mode(gl_ctx_scope_t scope)
|
||||||
|
{
|
||||||
|
return scope == GL_SCOPE_SYS ? 0644 : 0600;
|
||||||
|
}
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uid_t uid;
|
uid_t uid;
|
||||||
|
|
||||||
@@ -31,8 +49,59 @@ typedef struct {
|
|||||||
gl_ctx_scope_t scope;
|
gl_ctx_scope_t scope;
|
||||||
|
|
||||||
int lock_fd;
|
int lock_fd;
|
||||||
|
|
||||||
|
/* Set by the caller after gl_init_*_context (which zero it).
|
||||||
|
* Packages installed while this is non-zero may displace
|
||||||
|
* existing non-glacier files at their link destinations; see
|
||||||
|
* gl_link_pkg. */
|
||||||
|
int overwrite;
|
||||||
|
|
||||||
|
/* Install root (IMAGE_DESIGN section 3), set by the *_at init
|
||||||
|
* functions: "" for the running system, else e.g. "/mnt/everest".
|
||||||
|
* The paths above are INSTALL paths, already under it: every
|
||||||
|
* filesystem operation uses them as they are. What a path MEANS
|
||||||
|
* once the image is booted (a symlink target, a .displaced key)
|
||||||
|
* is its runtime path, gl_runtime_path(). System scope only. */
|
||||||
|
char sysroot[PATH_MAX];
|
||||||
|
|
||||||
|
/* Paths the link pass refused to link (a foreign file in the
|
||||||
|
* way, say), counted only for packages installed in this
|
||||||
|
* transaction. Zeroed by the init functions; after
|
||||||
|
* gl_commit_transaction, the post-commit relink's count. A
|
||||||
|
* non-zero count means the transaction committed but did not
|
||||||
|
* fully succeed. */
|
||||||
|
int link_refusals;
|
||||||
|
|
||||||
|
/* Set by the caller after gl_init_*_context (which zero it).
|
||||||
|
* Non-zero: a path the link pass would refuse (a foreign file in
|
||||||
|
* the way, say) fails the transaction before anything is
|
||||||
|
* committed, instead of being counted in link_refusals after.
|
||||||
|
* See deps.h. */
|
||||||
|
int strict;
|
||||||
} gl_context_t;
|
} gl_context_t;
|
||||||
|
|
||||||
|
/* An install path's runtime meaning: sysroot stripped. A path not under
|
||||||
|
* the sysroot is returned unchanged. */
|
||||||
|
static inline const char *
|
||||||
|
gl_runtime_path(const gl_context_t *ctx, const char *install_path)
|
||||||
|
{
|
||||||
|
size_t n = strlen(ctx->sysroot);
|
||||||
|
if (n > 0 && strncmp(install_path, ctx->sysroot, n) == 0 &&
|
||||||
|
install_path[n] == '/') {
|
||||||
|
return install_path + n;
|
||||||
|
}
|
||||||
|
return install_path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The install path of a runtime path (a symlink's absolute target, say):
|
||||||
|
* sysroot prepended. Returns -1 if it doesn't fit. */
|
||||||
|
static inline int
|
||||||
|
gl_at(const gl_context_t *ctx, const char *runtime_path, char *out, size_t outsz)
|
||||||
|
{
|
||||||
|
int n = snprintf(out, outsz, "%s%s", ctx->sysroot, runtime_path);
|
||||||
|
return (n < 0 || (size_t)n >= outsz) ? -1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
GL_TXN_OK = 0, /* success */
|
GL_TXN_OK = 0, /* success */
|
||||||
GL_TXN_ERR_LOCK = 1, /* unable to acquire lock */
|
GL_TXN_ERR_LOCK = 1, /* unable to acquire lock */
|
||||||
@@ -42,13 +111,25 @@ typedef enum {
|
|||||||
GL_TXN_ERR_SYNC = 5, /* fsync failed */
|
GL_TXN_ERR_SYNC = 5, /* fsync failed */
|
||||||
GL_TXN_ERR_CLEANUP = 6, /* cleanup failed */
|
GL_TXN_ERR_CLEANUP = 6, /* cleanup failed */
|
||||||
GL_TXN_ERR_NO_TXN = 7, /* aborted without beginning */
|
GL_TXN_ERR_NO_TXN = 7, /* aborted without beginning */
|
||||||
GL_TXN_ERR_XDEV = 8 /* stage and live on different filesystems */
|
GL_TXN_ERR_XDEV = 8, /* stage and live on different filesystems */
|
||||||
|
GL_TXN_ERR_DEPS = 9 /* unmet dependency, conflict, file collision,
|
||||||
|
* or (strict) a link refusal: see deps.h */
|
||||||
} gl_txn_status_t;
|
} gl_txn_status_t;
|
||||||
|
|
||||||
|
/* Is `sysroot` acceptable as an install root (absolute, no . or ..,
|
||||||
|
* trusted: see gl_sysroot_trusted)? Logs why not. 0 if so. "/" is. */
|
||||||
|
int gl_check_sysroot(const char *sysroot);
|
||||||
|
|
||||||
int gl_init_live_context(gl_context_t *ctx, gl_ctx_scope_t scope, uid_t uid);
|
int gl_init_live_context(gl_context_t *ctx, gl_ctx_scope_t scope, uid_t uid);
|
||||||
|
int gl_init_live_context_at(gl_context_t *ctx, gl_ctx_scope_t scope, uid_t uid,
|
||||||
|
const char *sysroot);
|
||||||
|
|
||||||
gl_txn_status_t gl_init_stage_context(gl_context_t *ctx, gl_ctx_scope_t scope, uid_t uid);
|
gl_txn_status_t gl_init_stage_context(gl_context_t *ctx, gl_ctx_scope_t scope, uid_t uid);
|
||||||
|
gl_txn_status_t gl_init_stage_context_at(gl_context_t *ctx, gl_ctx_scope_t scope, uid_t uid,
|
||||||
|
const char *sysroot);
|
||||||
gl_txn_status_t gl_begin_transaction(gl_context_t *ctx);
|
gl_txn_status_t gl_begin_transaction(gl_context_t *ctx);
|
||||||
|
int gl_scope_state_dir(const gl_context_t *ctx, const char *name, char *out);
|
||||||
|
int gl_scope_cache_dir(const gl_context_t *ctx, const char *repo, char *out);
|
||||||
gl_txn_status_t gl_commit_transaction(gl_context_t *ctx);
|
gl_txn_status_t gl_commit_transaction(gl_context_t *ctx);
|
||||||
gl_txn_status_t gl_abort_transaction(gl_context_t *ctx);
|
gl_txn_status_t gl_abort_transaction(gl_context_t *ctx);
|
||||||
|
|
||||||
|
|||||||
BIN
Binary file not shown.
Reference in new issue
Block a user