238 Commits
Author SHA1 Message Date
Pierre Warnier e33793cc74 release: 0.4.0 (#289)
gpasswd is a fifteenth tool, so a minor bump rather than a patch.

Also corrects the three static-musl sections for it. gpasswd is setuid
and authenticates a group administrator against the group password
through crypt(3) rather than PAM, so unlike chfn and chsh it keeps
working in the musl build; it resolves the caller through getpwuid_r, so
it joins the five tools that do not see directory users there; and it can
neither verify nor set a yescrypt group password. The counts around those
paragraphs were left at fourteen tools.

The README's multicall paragraph still named four setuid applets.
0.4.0
2026-09-06 11:47:43 +02:00
Pierre Warnier cd2e1571ad docs: record gpasswd in the changelog (#288)
The tool merged in #282 without an entry, and the Unreleased section was
empty. Credited to its author.
2026-09-06 11:22:56 +02:00
Pierre Warnier f3a20b2043 tests: cover gpasswd as a group administrator (#287)
The reason gpasswd is setuid is that someone who is not root, but is
named an administrator of one group, manages that group's membership.
Nothing in the suite exercised a non-root caller of it, and that is the
only place the omission shows: the multicall binary drops privilege for
every applet not on its setuid list, so leaving gpasswd off that list
produces a permission error there and nowhere else. It was off the list
when the tool arrived.

Twelve assertions: an administrator adds a member without being root and
the change lands in both group and gshadow; a plain member may not change
the membership, may not appoint administrators and may not use --root;
and the administrator list is unchanged after all three refusals.

Checked that the test bites by taking gpasswd back off the setuid list
and rebuilding -- the administrator is then refused and the group file is
untouched. Worth saying that the first attempt at that check appeared to
show the fix was unnecessary; the build output had been suppressed and a
stale binary was installed.
2026-09-06 11:15:09 +02:00
Jocelyn Le SageandPierre Warnier 8361bf512b gpasswd: added implementation of gpasswd (#282)
* gpasswd: added implementation of gpasswd

* gpasswd: rebase onto main and port to the current APIs

Rebases jlesage's implementation onto a main that moved a long way under
it, and carries it onto the interfaces that landed since the branch was
cut. The tool's behaviour is unchanged and still matches GNU on every
path probed.

What the rebase had to resolve:

  - shadow-rs.spec and debian/ were revived by the merge; both were
    deleted because neither could build.
  - The standalone dispatch() and hand-written --list predate the single
    applets() table, which now drives both. gpasswd joins the table.
  - The five shadow-core parser features it asked for no longer exist.
  - The fourteen [[test]] targets are one; test_gpasswd joins it.
  - README, Makefile and PLATFORM-SUPPORT described the pre-#239
    privilege model, in which every applet ran with euid 0.

What changed beyond the rebase:

  - gpasswd keeps its privilege in the multicall build. It is setuid in
    GNU and the branch marks it setuid for the per-tool install, but
    SETUID_APPLETS still listed four names, so the multicall build would
    have dropped privilege and no group administrator could have used it
    -- silently.
  - Comments in /etc/group survive. It read entries only and wrote them
    back, which erases every comment, blank line and NIS compatibility
    line in the file. The locked-file transaction keeps them, and commits
    group and gshadow together so a bad value cannot leave the pair
    disagreeing.
  - The duplicated EchoGuard and password reader are gone, replaced by
    shadow_core::tty, which blocks interrupts for the read so Ctrl-C at
    the prompt cannot leave the terminal with echo off.
  - The print macros are replaced. They panic when the stream is closed,
    which a setuid-root tool must not do part way through a change.
    These were the only five in the repository and no lint caught them,
    so clippy::print_stdout and print_stderr are now denied
    workspace-wide, with the test crate exempt.

The GNU comparison suite gains gpasswd: the unknown-group, unknown-user
and non-member exit codes, all three of which match.

CONTRIBUTING's licence list also said ISC, BSD-2-Clause, CC0-1.0, Zlib
and MPL-2.0 were acceptable, which stopped being true when deny.toml was
narrowed to the graph. It now says what deny.toml enforces.

---------

Co-authored-by: Pierre Warnier <pierre@warnier.net>
2026-09-06 11:03:53 +02:00
Pierre Warnier 72d73276a6 release: tell dist the container is apt-based and arm64-native (#286)
Two more things the container needed, both visible in `dist plan` and
neither in the generated workflow.

The dependency install step was emitted empty: dist infers a package
manager only for images it knows, and for anything else leaves it unset
and installs nothing, so the build failed on -lpam. The container entry
now says package-manager = "apt".

The arm64 entry also has to say host = aarch64-unknown-linux-musl.
Left at the default it describes an x86-64 container, so dist concluded
it was cross-compiling and added a cargo-zigbuild install that shells out
to dnf, which an apt image has not got.

Checked by reading the install script dist plans for each target rather
than by tagging again.
0.3.1
2026-09-05 15:29:40 +02:00
Pierre Warnier 5c3f58b875 release: give the build container the tools the workflow needs (#285)
The 0.3.1 pipeline failed before it compiled anything: a bare
ubuntu:22.04 has no git, and the generated workflow runs `git config` as
its first step, then installs Rust with curl.

buildpack-deps:22.04 carries git, curl and a C toolchain, is still
Ubuntu 22.04, and produces the same GLIBC_2.34 floor -- verified by
building in it and dumping the versioned symbols, and by running the
result on a glibc 2.35 host.

No release was published for the 0.3.1 tag, so the tag is moved rather
than the version burned.
2026-09-05 15:09:42 +02:00
Pierre Warnier e09e4bccac release: build the glibc archives on 22.04, and drop a test that could hang (#284)
Two defects in what shipped yesterday.

0.3.0's glibc archives require GLIBC_2.39 and will not start on Debian
12, Ubuntu 22.04 or RHEL 9 -- all of which ran 0.2.2. Pinning the release
runner to Ubuntu 24.04 in #272 let Rust's std link pidfd_spawnp and
pidfd_getpid; those two are the only symbols in the binary above 2.34.
The build now happens inside an ubuntu:22.04 container on the same
runner, which is where the container support in dist earns its keep: the
runner stays current while the floor goes back to GLIBC_2.34, exactly
what 0.2.2 required. Verified by building in that container and dumping
the versioned symbols, and by running the result on a glibc 2.35 host
where the 0.3.0 archive refuses to start. The static musl archive was
never affected.

The PAM test for an unconfigured service could hang rather than fail. On
Debian /etc/pam.d/other falls through to common-auth, which is pam_unix,
so it prompts: the conversation then blocks reading stdin. CI never saw
it because its stdin is not a terminal, but `make check` on a developer's
machine hung indefinitely. The test is removed with a note saying why,
and the permit and deny tests -- which are the ones that matter and which
never converse -- stay.
2026-09-05 14:51:02 +02:00
Pierre Warnier 84402354a4 release: 0.3.0 (#283)
Thirty-eight commits since 0.2.2, none of them in the changelog: the
Unreleased section described the musl archive and nothing else. It now
covers the lot, under the headings the file already uses.

The release itself is the reason to do this now. The aarch64 archive
support merged on Friday and has never run: the configuration is
verified and dist plan lists all three archives, but no tag has yet
driven the pipeline.

Highlights, all documented in full in the changelog:

  - --root performs a real chroot(2) in every tool, where eight of the
    thirteen treated it as a path prefix.
  - passwd -l is idempotent, and chage -l prints what chage(1) prints.
  - chpasswd takes its hashing scheme from ENCRYPT_METHOD.
  - chsh no longer answers differently for a path that exists and one
    that does not, which made a setuid-root tool a filesystem oracle.
  - login.defs numbers are read in octal and hexadecimal as documented.
  - ID allocation consults the name service.
  - An aarch64 archive, and the user-facing tools install into bin.
0.3.0
2026-09-05 14:18:20 +02:00
renovate[bot] 921f8551f6 Update fedora Docker tag to v46 (#274)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2026-09-04 18:31:15 +02:00
Pierre Warnier acc1771bc2 tests: exercise the PAM stack against known permit and deny services (#281)
The only PAM coverage was the deployment image authenticating a real
account. That cannot exercise a *refusal* without relying on a wrong
password being wrong, and it cannot tell a refusal apart from a
conversation that never reached the stack -- which is exactly the failure
that broke password changes earlier this week and took three rounds to
find.

The glibc images now define two throwaway services, one backed by
pam_permit and one by pam_deny, and shadow-core tests the wrapper against
both: the permit stack authenticates and passes account management, the
deny stack refuses with the stack's own answer rather than a conversation
error, and a service with no configuration at all does not authenticate.
The tests skip where the services are absent, which is any machine but
the containers.

CI also gains an all-features clippy pass. The completions feature and
the shadow-core feature gates were compiled by no job, so a lint or a
compile error in them could reach main unnoticed. make check runs it too.
2026-09-04 18:25:33 +02:00
Pierre Warnier 64abc1197a shadow-core: one generic record reader and writer (#280)
read_*_file and write_* were the same twenty lines five times over, once
per record type, differing only in which type they parsed. They delegate
to records::read_entries and records::write_entries now, and keep their
names because eighteen call sites read better for them.

The read_*_with_layout and write_*_with_layout wrappers are gone
entirely: each was a single line forwarding to records::, and after the
transaction landed only one caller was left, a test that did not need the
layout at all.

Net: 200 lines out of shadow-core, and one place where a change to how a
record file is read or written now has to be made.
2026-09-04 18:01:30 +02:00
Pierre Warnier d34ab6f605 shadow-core: commit several files together, and convert the last six tools (#279)
group and gshadow have to agree: a group present in one and absent from
the other is a broken system, and every tool that touches a group touches
both. Committing them one at a time leaves a window in which they
disagree, and a failure in the second makes that permanent.

commit_all validates every file before writing any, which closes the
failure this actually hits -- a value that would corrupt a record is
rejected while nothing has been touched, instead of after the first file
is already on disk. A genuine I/O error partway through can still leave
the set half applied; there is no journal, and a rollback that can itself
fail would not be an improvement. All the locks are held until the last
write finishes, so no other process sees the intermediate state.

A commit that would write the same bytes now writes nothing. A rewrite is
not free: it replaces the inode and moves the mtime, and for an unchanged
empty file it failed outright, since the atomic writer refuses to produce
a zero-length file. Every tool used to carry its own 'did anything
change' flag to work around that; those are gone. Found by usermod's
tests, whose fixture has an empty gshadow that -G does not touch.

groupmod, useradd, usermod, userdel, pwck and grpck are converted, and
there is no longer a single FileLock::acquire left in any tool. userdel
loses its hand-rolled line filter, which had its own idea of which lines
were comments next to the parser that already knows; one consequence is
that a comment above a removed account now moves to the end of the file
rather than staying in place, which is what every other tool already did.

Exit codes are preserved, including the two pwck keeps for a failed
write: 6 'can not sort' and 5 'can not update the files' stay distinct by
matching on the file the error names.

Verified against a prefix tree for each tool: useradd creating an account
with a user group, supplementary groups, aging and subid; usermod
renaming across four files and replacing a group list; groupmod moving a
GID and following it into passwd; userdel removing an account from six
files; grpck sorting group and gshadow together, keeping each comment
with its group, and writing nothing on a second run.
2026-09-04 17:55:36 +02:00
Pierre Warnier fee24971d6 shadow-core: a locked-file transaction, and seven tools using it (#278)
Every tool repeats the same five steps: take the lock, read under it,
change the entries, write atomically, release. Written out by hand at
each of the thirty-odd call sites the order is easy to get wrong, and it
was -- pwck -s sorted entries it had read before taking the lock, so a
change another process made in between was silently reverted.

LockedFile makes the correct order the only one available. open() locks
and then reads; entries_mut() hands out the data; commit() validates,
writes atomically and releases; dropping without committing releases
without writing. Reading outside the lock and writing after releasing it
are not expressible. Signals are blocked for the value's lifetime, so a
SIGINT between the lock and the write cannot leave a stale lock file for
every later run to wait out.

Two variants earn their place rather than being conveniences:

  - open_or_empty, for a tool that creates a record file where there was
    none, such as groupadd into a fresh --prefix tree. open() stays
    strict, because for passwd and chage a missing /etc/shadow is its own
    error with its own exit code, and reading it as 'no accounts' would
    report every login as unknown instead.
  - commit_or_remove, for the files where an absent file and an empty one
    mean the same thing -- group, gshadow, subid. The atomic writer
    refuses zero length, since a truncated account file is a far more
    common failure than a deliberately empty one, so deleting the last
    group has to unlink. Not for passwd or shadow.

chfn, chsh, chage, passwd, chpasswd, groupdel and groupadd use it, and
lose 212 lines between them. The exit codes are unchanged: a locked file
is still 5 and a missing shadow file still 4, mapped explicitly where the
three cases were previously distinguished by which line failed.

groupmod, useradd, usermod, userdel, pwck and grpck keep their
hand-written sequences: each commits several files that have to agree,
which needs a transaction over more than one file. That is the rest of
this item.
2026-09-04 17:50:11 +02:00
Pierre Warnier eb940c0b46 --root is a real chroot in every tool, not a path prefix in eight of them (#277)
* --root is a real chroot in every tool, not a path prefix in eight of them

Five tools called chroot(2) for --root. The other eight -- groupadd,
groupdel, groupmod, grpck, pwck, useradd, userdel, usermod -- folded the
argument into the same resolver --prefix uses, so it only prepended the
directory to the files the tool itself opened.

The difference shows whenever an absolute path is read out of a record
rather than being one of the tool's own files:

    useradd -R /mnt/sysroot -m alice

created the home on the *host*, at /home/alice, because the path came
back from login.defs as /home/alice and nothing prefixed it. The skeleton
was copied from the host's /etc/skel. userdel -r -R had the mirror-image
problem and resolved the home to delete against /.

All thirteen now chroot, through one helper in shadow-core rather than
five copies of it, and refuse --root for anyone but root: a setuid-root
binary pointed at a tree of the caller's choosing would read and write
account files that caller controls.

pwck and grpck have no --prefix, matching GNU, so their tests move to a
spawned process: --root cannot be exercised in-process at all now, since
a chroot in the test binary takes every later test into the tree with it,
where /tmp does not exist. That is how this was caught. The other tools'
in-process tests use -P, which is what they meant.

Verified in the deployment container against a minimal target tree: the
account, its home and the skeleton all land inside it, groupadd/groupmod/
groupdel operate on the tree's group file, pwck and grpck read the tree,
userdel -r removes the home from the tree, and the host is untouched
throughout.

Closes #270.

* pwck: name the shadow file in the bad-entry test

The test passed only the passwd file, so the shadow path defaulted to the
host's /etc/shadow. Unprivileged, that cannot be read, and the test
reported 'cannot open' (exit 3) instead of the bad entry it is about
(exit 2). It passed in the containers, which run as root, and failed on
the host runner.

It was --root that hid this: as a path prefix it pointed the default at
the fixture. --root is a chroot now, so the fixture has to name both
files.

* tests: guard the pwck tests that chroot

They spawn 'pwck --root', and chroot(2) needs root: the tool refuses the
option for anyone else. The containers run as root so they passed there,
and the host runner failed them.
2026-09-04 17:27:13 +02:00
Pierre Warnier 02fefda42c ci: compare against GNU for real, pin the actions by digest, one make check (#275)
* ci: pin the actions by digest

A tag is a moving pointer. Whoever controls the action's repository can
repoint v7 at any commit, and every workflow in the project runs it on
the next push with write access to the checkout. A digest cannot be
repointed.

The tag stays in a trailing comment so the version is still readable, and
Renovate's pinGitHubActionDigests preset is enabled so the digests are
kept current the same way every other dependency is -- as a pull request
that CI has run, rather than silently.

* tests: make the GNU comparison real, and run it in CI

The suite compared full output for exactly two commands and, for the
other twelve, only that both tools exit 0 on --help. It ran nowhere.

It now compares what is actually a contract. 'passwd -S' and 'chage -l'
are parsed by monitoring and provisioning scripts, so their output is
compared byte for byte across eleven aging configurations -- including
the cases this project got wrong until recently: a last change of 0, the
threshold above which a maximum age reads never, and cleared fields. Exit
codes are compared on ten error paths. --help output is deliberately not
compared: ours comes from clap and is meant to differ.

One difference is deliberate and now asserted as such, so it cannot be
mistaken for a regression the day it changes by accident. GNU parses
dates leniently and rolls them over -- 'chage -d 2025-02-29' stores 1
March and '-d 2025-13-01' stores 1 January 2026. An administrator who
typed one of those made a mistake, and silently storing a different date
than the one they wrote is a poor answer for a field that decides when an
account stops working. We refuse it; chage(1) says so.

38 comparisons, all as expected, and a CI job runs them.

'make check' is now the single definition of what CI gates on -- fmt,
clippy with and without pam, and the tests in both configurations. The
pre-push hook and CONTRIBUTING refer to it instead of each carrying their
own copy of the command list, and the two hook systems are documented as
the non-overlapping things they are.
2026-09-04 16:58:54 +02:00
Pierre Warnier cf7ecb4a0f tests: one binary, spawn the real tool, and assert on what it prints (#273)
* tests: one binary, spawn the real tool, assert on what it prints

Fourteen [[test]] targets each linked all fourteen tool crates and
carried its own copy of the helpers through a #[path] include, so the
suite was compiled and linked fourteen times over. It is one target now,
the layout the rest of uutils uses.

More importantly the tests called uumain in-process and asserted on an
exit code and nothing else. Not one assertion in the suite looked at a
byte of output, so 'bit-for-bit identical to GNU' was never checked. A
shared process also let harden_process, setuid, Landlock and umask
changes leak from one test into the next.

common now offers a spawned-binary helper with assertions on the exit
code and both streams, and the tests use it. Three findings came out of
that within the hour:

  - chage exited 3 for an invalid date where GNU exits 2; 3 is for an
    unexpected failure, not for an argument the caller got wrong.
  - passwd -l was not idempotent. Eight concurrent locks left eight
    markers, and since passwd -u refuses to unlock an account that would
    stay locked, an account locked twice could not be unlocked with the
    tool at all. GNU leaves a single marker however many times it is
    asked; two unit tests that encoded the old behaviour are rewritten
    to the verified one.
  - pwck's duplicate-UID test accepted either 0 or 2, so it asserted
    nothing. Two accounts may deliberately share a UID (useradd -o), and
    GNU reports nothing; a duplicate *name* is the fault, and that is now
    what is checked, message included.

test_chage and test_chpasswd never invoked their tool at all -- they set
a field through shadow-core and read it back, testing the parser twice.
Both now drive the binary through --prefix, which those tools have since
gained, and cover the aging-field writes, the -l wording and thresholds,
the batch rules, ENCRYPT_METHOD and the flag pairs the man page forbids.

The concurrency test raced four threads through uumain against a lock
keyed on the process id, which same-process threads never contend for,
and discarded all eight return codes. It spawns eight processes now and
checks every one.

New: the multicall binary is tested for the property one table now
guarantees -- every applet listed is reachable, and the help text is
identical through the argument and the symlink.

* passwd: make -l idempotent

Locking prepended '!' unconditionally, so locking an account twice left
'!!'. One unlock then removed one marker and left the account locked --
and passwd -u refuses to unlock an account that would stay locked, so
the tool could not undo its own second lock.

GNU shadow 4.17 leaves a single marker however many times it is asked:
three locks give one '!', which one unlock removes. Unlocking a field
that already carries two markers still removes exactly one, which is
also what GNU does; that case is reachable only from a file some other
tool wrote.

Found by running eight concurrent passwd -l processes against one
account and looking at the result, which is a thing the suite could not
do while it called uumain in-process. Two unit tests asserted the old
behaviour and now assert the verified one, and the deployment suite
locks twice and checks the marker did not double.

* ci: make root-only skips visible, and test root together with pam

Roughly three quarters of the integration suite is root-only, and a
skipped test is reported ok, so a run that exercised almost nothing
looked exactly like a run that exercised everything.

SHADOW_TEST_REQUIRE_ROOT turns a skip into a failure. The Docker images
set it, since they run as root: 27 useradd tests that reported ok off-root
fail loudly there now if the suite ever stops running as root.

The matrix also runs with pam. The feature changes which code paths
exist -- chfn and chsh refuse every non-root call without it, and passwd
loses its interactive path -- so root and PAM together had never been
exercised by any job.

* fuzz: assert a real invariant, add a subid target, build in CI

The targets asserted only that parsing does not panic. For a record file
the property that matters is that a parsed entry survives being written
back: if Display can emit a line that parses differently, a tool
rewriting the file silently changes an account. Each target now checks
that the rendered line carries exactly the separators its format has --
one more would shift every following field on the next read, which is
how an injected account appears -- and that parsing it again renders
identically. /etc/subuid had no target at all.

The crate is a separate workspace nothing else builds, so it had rotted:
its manifest asked shadow-core for features that no longer exist. A
stable 'cargo check --bins' in CI catches that without nightly.

The corpus was both gitignored and tracked. It is kept: 667 accumulated
inputs are worth carrying between runs, and the main suite now replays
them through the same two properties on every pull request, so a
regression a fuzzer once found is caught on stable without a fuzzing
session.

* chage: an invalid date is a bad argument, not an unexpected failure

'chage -E 2025-02-29' exited 3, which chage(1) uses for something going
wrong that the caller did not ask for. A date the caller typed wrongly is
exit 2, which is what GNU shadow 4.17 answers -- 'chage -d -5 u' prints
"invalid date '-5'" and exits 2.

Found by the integration tests once they ran the real binary and looked
at its exit code.

* tests: guard the chage tests that need root, and let an empty flag mean off

The chage tests drive the tool against a --prefix tree, but 'chage -l' on
an account other than the caller's, and every modification, are refused
for a non-root caller before any file is opened. The host runner is not
root, so those tests failed there.

SHADOW_TEST_REQUIRE_ROOT also treated an empty value as set, so
'-e SHADOW_TEST_REQUIRE_ROOT=' turned the requirement mysteriously on
rather than off. An empty value now counts as unset, which is the
conventional reading.

* ci: do not ask Alpine for a pam build

Alpine's Rust image targets musl with crt-static, where shadow-core
refuses the pam feature at compile time on purpose: Linux-PAM loads its
modules with dlopen(3), which a static binary cannot do, so a build that
compiled would produce an authentication path that never works.

The new 'with pam' matrix step ran on all three distros and so hit that
guard. It runs on the glibc images now. The static musl job already
asserts that requesting pam there is rejected, and Alpine is in the
matrix for musl's libc behaviour, not for PAM.
2026-09-04 16:46:07 +02:00
Pierre Warnier 9cd5eef4ac Install layout, aarch64 archives, pinned images, and a pre-push hook worth keeping (#272)
* hooks: stop reproducing CI in pre-push

The hook ran fmt, clippy and the test suite on Debian, Alpine and Fedora
in series, on every push. That is several minutes for a push that may
carry nothing: pushing the 0.2.2 tag moved one object and still blocked
for over two minutes. The predictable result was that every push in the
last batch of work used --no-verify, and a hook that is always skipped
protects nothing while still costing time whenever someone forgets to
skip it.

It now runs the workspace tests once, on Debian, and returns immediately
for a push that carries no new commits -- a tag, a branch deletion, or a
branch the remote already has. git hands the hook one line per ref on
stdin; the ranges it names are asked for a single commit, and if there
are none there is nothing to test.

Everything the hook dropped is already a required check on the pull
request, running in parallel with retries: fmt, clippy and the tests with
and without pam, MSRV, cargo-deny, the static musl archive, the
three-distro matrix as root, and the end-to-end deployment image.

Closes #231.

* install: put the user-facing tools in bin, not sbin

All fourteen binaries went to $(PREFIX)/sbin, which is not on a normal
user's PATH: passwd was 'command not found' for exactly the people it is
setuid for. GNU shadow splits them, verified against the Debian package
-- passwd, chage, chfn, chsh and newgrp in /usr/bin, the other nine in
/usr/sbin. Both install targets do the same now, and the multicall
symlinks in bin point at the absolute path of the binary in sbin. chage
is in bin for 'chage -l', the one mode a user may run on their own
account.

The deployment suite follows each tool to the directory it belongs in,
and asserts that all five are reachable by name for an unprivileged
user, which is the property the split exists for.

make test also runs the suite with pam now. install ships binaries built
with it, so a run without it covered a build nobody ships.

* docker: pin the base images, drop the unused nextest download

rust:latest, rust:alpine and fedora:latest meant a new toolchain or
distro release landed on main with no pull request and no signal, and
clippy gains lints between Rust releases. They are pinned to what the
images resolve to today -- rust 1.98 on Trixie and Alpine 3.23, Fedora 44
-- and Renovate's Dockerfile manager proposes the bumps, so a toolchain
change arrives as a reviewable PR that CI has run.

Each image also downloaded cargo-nextest from get.nexte.st/latest on
every build: unpinned, unverified, and never invoked -- nothing in the
repository runs 'cargo nextest'. cargo-deny, which is used, keeps its
pinned version and checksum.

* deny: allow exactly the licences the graph uses

The allow list carried ISC, BSD-2-Clause, CC0-1.0 and Zlib, none of which
appears anywhere in the dependency graph. A list wider than the graph
means a crate arriving under a new licence passes silently; the point of
the check is that such an arrival is a decision someone records.

It is now MIT, Apache-2.0, BSD-3-Clause (subtle, for the constant-time
comparison in shadow-core::crypt) and Unicode-3.0 (tinystr and
unicode-ident, via uucore's fluent stack), taken from
'cargo deny --all-features list'.

Two crates carry a copyleft option in a dual licence and are accepted
under the other half; that is now written down rather than left for the
next reader to work out. All four checks pass with the narrower list.

* ci: run the advisory workflow on a schedule only

It also ran on every push touching a manifest or the lockfile, where the
Cargo Deny job in ci.yml had already checked the same advisory database
alongside licences and bans. Two tools reporting the same finding on the
same commit is noise.

What the pull request job cannot do is notice an advisory published
against code nobody has touched, which is the reason to keep a scheduled
run. That is now all this workflow does, plus manual dispatch.

* packaging: remove the RPM spec and debian directory

Neither can build. debian/ has no changelog at all, so dpkg-buildpackage
stops before it starts:

    dpkg-buildpackage: error: cannot open file debian/changelog

and shadow-rs.spec pins version 0.2.0 against a 0.2.2 workspace, points
at the pre-transfer repository URL, and lists a %files layout that
'make install' does not produce -- it names the multicall binary, which
only install-multicall builds, and puts every tool in sbin, which is no
longer where half of them go.

Shipping packaging that claims to work and does not is worse than
shipping none, and this would have produced a package declaring
'Provides: passwd, login' on a system whose real passwd it replaced.
Releases are the archives dist publishes; a distribution packager writes
these against their own policy anyway.

* release: publish an aarch64 archive

The pipeline shipped x86_64 only. arm64 servers and Apple-silicon
containers are common enough that a missing archive is a real gap.

It builds on a native arm64 runner rather than cross-compiling, which is
what makes it straightforward: shadow-core::crypt links crypt(3) and the
pam feature links libpam, so a cross build would need an arm64 sysroot
carrying both, while a native runner installs them from apt like any
other build. dist has picked a native runner for aarch64 since 0.30.

Both runners are pinned to 24.04. dist's defaults are ubuntu-22.04 and
ubuntu-22.04-arm, and 22.04 enters deprecation on 2026-09-17 with the
image unsupported from 2027-04-17; the pin keeps the two archives on the
same generation and off an image that is about to start failing. The
higher runner raises the glibc floor for the dynamically linked
archives, which is what the static musl archive is there for.

release.yml is regenerated by 'dist generate'; 'dist plan' now lists
three archives and resolves ubuntu-24.04-arm for the arm64 job.

Closes #222.
2026-09-04 16:28:57 +02:00
Pierre Warnier 4e539357a1 shadow-core: remove duplicated lookups, fix login.defs radices, allocate around NSS (#271)
* shadow-core: delete the duplicated NSS entry type and the unused surface

process::PwEntry was a field-by-field twin of passwd::PasswdEntry,
copied across at every NSS lookup. getpwuid now returns the parser's own
type: an NSS entry and a file entry describe the same account, and a
second struct for it only bought a copy per call. lookup_username goes
with it, and lookup_username_by_uid becomes one line.

The tty module had its own signal-mask guard beside hardening's
SignalBlocker, and the PAM conversation had its own controlling-terminal
lookup. There is now one of each.

error::ShadowResult and ShadowError::Permission had no users at all, and
display_message carried an _is_error parameter it never read.

harden_process returned a sanitized environment that every one of its
thirteen callers discarded, which read as though the process environment
had been dealt with. It has not been and is not: the in-process PAM and
NSS modules still see what the caller set. The function no longer claims
otherwise, and the callers no longer bind a value to throw away.

Adds gid_exists, the group-side companion to getpwuid, for the allocator.

* shadow-core: read login.defs numbers in the radices the man page documents

login.defs(5) writes numbers 'in decimal, or in octal with a leading 0,
or in hexadecimal with a leading 0x'. get_i64 parsed decimal only, which
is not a rejection but a silent misreading: UID_MIN 01000 means 512 and
came back as 1000, so useradd would allocate from a range the
administrator had reserved. UMASK 022 and HOME_MODE 0750 have the same
shape and will be read the day they are honoured.

LoginDefs also gains Default, an empty configuration, which is what a
caller wants when the file is missing: every lookup returns None and the
tool falls back to its own default.

* useradd, groupadd: never allocate an ID the name service already knows

/etc/passwd is not the only source of accounts. An ID that is free in the
file may belong to an LDAP, SSSD or systemd-homed user, and handing it
out gives two accounts one ID -- which the kernel cannot tell apart, so
the new local user ends up owning the directory user's files.

Allocation now asks NSS as well as the file. Which sources count is an
explicit Scope rather than a hidden default, because a --prefix or --root
run manages another system's files: the name service running here
describes this one, so asking it would skip IDs that are free on the
target and claim none that are taken there. SysRoot::is_prefixed decides.

uid_range and gid_range were the same function twice over different keys
and are now one, the system ranges being the same keys with a SYS_
prefix.

The allocation tests moved from next_uid to next_free. Once next_uid
consults NSS its answer depends on which accounts exist on the machine
running the test, and on a typical container 1000 and 1001 do. The policy
is tested where it lives, and two tests assert the property that actually
matters against the live system: an allocated ID is in range, not in the
entries given, and unknown to NSS.

* audit: write to /dev/log instead of forking logger for every event

Each account event spawned /usr/bin/logger and waited for it, to write a
few dozen bytes to a socket. A setuid-root tool should spawn as little as
it can: the fork inherited the process state, depended on a binary being
installed at a fixed path, and blocked the caller. The record now goes
straight to /dev/log as an RFC 3164 datagram, and carries the terminal it
came from instead of a literal '?'.

Failure stays silent in every direction. A machine with no syslog daemon
is a normal machine, and a record that cannot be written must not fail
the operation that produced it.

The deployment suite runs rsyslogd and greps the log for the creation and
deletion records, so this is covered rather than assumed.

Also corrects atomic's claim that its temp-file names are unique 'across
threads' in a single-threaded crate; what they separate is successive
writes within one process, which usermod does four of in a row.

* docs: record the hardening changes and what --root really does

sysroot's module documentation said every tool offering --root performs a
real chroot. Five of the thirteen do; the other eight fold it into the
same resolver --prefix uses, so an absolute path read out of a record
resolves against / rather than the target. That is a real divergence
worth its own change and is filed as #270; the documentation now says
which tools do which and points there.

* cargo: only gate what changes linkage; stop forcing applets in with pam

Five of shadow-core's features -- shadow, group, gshadow, login-defs,
subid -- gated modules that pull in no dependency. Gating them bought
nothing and cost real confusion: cargo test -p shadow-core compiled a
fraction of the crate and reported a pass for it. It runs 181 tests now
where it ran 20, without a single one being written. uid_alloc loses its
cfg(all(group, login-defs)) with them.

What remains behind a feature is what actually changes the build: pam
(links libpam), crypt (links libcrypt on glibc, and now pulls subtle,
which nothing else uses) and landlock.

In the root manifest, pam = ["passwd/pam", ...] force-enabled the three
applets that can use PAM, so asking for PAM in a build that had
deliberately left them out dragged them back in. The optional-dependency
form pam = ["passwd?/pam", ...] applies the feature if the applet is
there and does nothing if it is not.

The feat_* aliases and the feat_phase* groups are gone. Every one was a
rename of a feature cargo already provides -- feat_passwd = ["passwd"] --
and nothing outside the manifest had referred to them since the phases
they were named for finished.

Verified against all four delivery paths: make build and
make build-multicall still link libpam, the static musl archive still
builds and reports all fourteen applets, and a --no-default-features
--features pam build now produces a binary with no applets at all and no
warnings, which is the case the ? was added for.
2026-09-04 16:04:34 +02:00
Pierre Warnier 6442faf970 chage/passwd/chpasswd/newgrp: aging bounds, input rules and newgrp - (#269)
* chage, passwd: one date module, GNU's -l output, and exit 1 for an unknown login

The Hinnant calendar algorithms were written out three times. They now
live in shadow-core::date, which also gained the inverse direction and
the two display forms, with the arithmetic checked.

That matters here: 'chage -l' adds lastchg + max + inactive, three values
read from a file anyone who can write /etc/shadow chooses. Plain addition
wraps in release builds and panics in debug ones. The sum is now bounded
and an unrepresentable date shows as 'never', which is what GNU displays
for a field it cannot make sense of.

Two -l rules were wrong, both verified against GNU shadow 4.17 in the
Debian image:

  - A last change of 0 is passwd -e's 'must change at next login' marker,
    not a date. GNU prints 'password must be changed' on all three
    password lines; we printed 1970 dates for the two derived ones.
  - Expiry is disabled at a maximum age of 10000 days, not 99999. -M 9999
    shows a date, -M 10000 shows never.

Both tools also exited the wrong code for an unknown login: chage 15,
which chage(1) reserves for 'can't find the shadow password file', and
passwd 3, which is for an unexpected failure. GNU exits 1 for both.

chage gains --prefix, so its behaviour can be exercised without touching
the live files. The display tests, which asserted only that a string
contained '1970' and that printing did not panic, now assert the exact
output line by line.

* chpasswd: honour ENCRYPT_METHOD, reject the flag pairs the man page forbids

The default hashing scheme was hard-coded SHA-512 while ENCRYPT_METHOD in
login.defs is how a distribution picks one for the whole system. On
Debian, which sets YESCRYPT, every password set through this tool was
weaker than the one the same user would get from passwd. -c still
overrides, and an unreadable or unusable configuration falls back to
SHA-512 rather than refusing to set a password.

Two flag combinations chpasswd(8) documents as errors were accepted and
quietly did nothing: -s without -c (a rounds count with no scheme to
apply it to) and -e with -c (a scheme for input that is already hashed).
Both are now usage errors, and usage errors exit 2 as the man page says.

The batch is also resolved before it is applied: an unknown login in the
middle of a list used to leave the first half written. Membership is
looked up through an index rather than a scan per pair, which took the
critical section -- held with signals blocked -- out of quadratic time.

Also drops the setuid(0) before the write, which raised the real uid and
made caller_is_root() answer true for the rest of the process, and owns
each input line in a zeroizing buffer: every one of them holds a
password.

Adds --prefix.

* newgrp: implement '-', and stop making every shell a login shell

newgrp(1) is 'newgrp [-] [group]'. The dash was not implemented, so
'newgrp - docker' looked for a group called '-' and reported it missing.

Worse, every invocation execd a login shell (argv[0] = -sh) whether or
not the dash was given. newgrp(1) says the current environment and
working directory are kept without it, so the profile files were being
re-read on each 'newgrp docker', in an environment they had already been
applied to.

Now: without '-', a non-login shell inheriting the environment; with '-',
a login shell, chdir to the home directory, and an environment built
explicitly (HOME, SHELL, USER, LOGNAME, PATH, plus TERM and the locale
variables a real login inherits from the terminal). That needs execve,
added to shadow-core::process, because std::env::set_var is unsafe and
process-global in edition 2024.

Membership and password sources were checked against GNU shadow 4.17
rather than changed on assumption, with four groups covering the cases:
membership comes from /etc/group and the password from /etc/gshadow, and
a user listed only in gshadow's member list is not admitted. That is what
this already did, so it stays.

The duplicated EchoGuard is gone; the prompt goes through the shared
terminal helper, which blocks interrupts for the read. The env
sanitization call that computed a value and dropped it is gone too, with
a note on why newgrp deliberately does not sanitize.

The parse tests now exercise the operand grammar instead of asserting
that clap stores a string.

* shadow-core: scrub the crypt(3) password copy, identify the caller to PAM

crypt(3) takes C strings, so a copy of the password has to exist.
CString::new made that copy on the heap and freed it without zeroing:
the caller's Zeroizing<String> scrubs its own buffer and never learns
about this one. The copy is now owned in a zeroizing buffer whose
capacity is reserved exactly, since a reallocation would leave a first
copy behind unzeroed.

The PAM response cleanup zeroed with ptr::write_bytes immediately before
free(). That is a dead store, and the optimiser is entitled to delete it,
leaving the password in the heap. Volatile writes and a compiler fence
cannot be elided.

PAM_TTY and PAM_RUSER were never set, so pam_unix and pam_faillock logged
tty=? with no requesting user, which makes their records useless for
tracing a failed authentication and stops pam_faillock's per-tty handling
from working at all. Both are now set when the handle is created, best
effort: a tool with no controlling terminal must still be able to
authenticate.

* docs: rewrite the chage, chpasswd and newgrp man pages; cover the rules end to end

None of the three explained the rules that actually decide what happens:
what a last change of 0 means in the chage output and where the 'never'
threshold sits, that chpasswd takes its scheme from ENCRYPT_METHOD and
which flag pairs are errors, or what newgrp's dash does and where
membership and the group password are each read from. All three now carry
value restrictions, configuration, exit status, files and worked
examples.

The deployment suite gains thirty-five assertions against the real
binaries: the three 'password must be changed' lines, a date at -M 9999
and 'never' at -M 10000, -1 clearing a field while -5 is refused, exit 1
for an unknown login from both chage and passwd, chpasswd following
ENCRYPT_METHOD through two changes and -c overriding it, the two usage
errors, --prefix on both tools leaving the live files untouched, and
newgrp keeping the environment without '-' and reinitializing it with.
2026-09-04 14:20:46 +02:00
Pierre Warnier b6c318d1d5 chfn/chsh: interactive mode, and fix a setuid path oracle (#268)
* shadow-core: add a shared terminal helper

Reading a line and reading a password were open-coded in pam.rs, and
every prompt outside a PAM conversation had no helper at all.

tty.rs holds all of it: prompt_line, read_password and read_stdin_line,
with the EchoGuard that restores the terminal. Ctrl-C at a password
prompt used to leave echo disabled -- the signal terminates the process
without unwinding, so the guard's destructor never ran. The read now
blocks SIGINT, SIGQUIT and SIGTSTP for its duration, which is what
readpassphrase(3) does, and restores the mask on the way out.

The prompt prefers /dev/tty and falls back to stderr and stdin when
there is no controlling terminal (ENXIO/ENODEV), the case that broke
password changes under su -c.

* chfn: prompt for fields, and check values before asking for a password

chfn(1) with no field option prompts for each field with its current
value; ours refused with 'no flags specified'. It now prompts, and an
empty answer keeps the field.

Three fixes come with it:

  - CHFN_RESTRICT is enforced on the values, not on which options were
    passed. Interactive input went through unrestricted, and a field the
    caller may not change is now not prompted for at all.
  - Values are validated before the PAM conversation, so a rejected
    value no longer costs the caller a password prompt.
  - mutate_passwd no longer calls setuid(0). euid 0 is all the lock and
    the atomic write need; raising the real uid made caller_is_root(),
    which is deliberately real-uid based, answer true for everyone.

The five sub-fields are now one Changes value with the collect,
validate, permission and apply steps on it, which is what let uumain
shrink rather than grow.

* chsh: prompt for the shell, and stop leaking path existence

Three changes to the self-service path.

chsh(1) with no -s prompts for the new shell with the current one in
brackets; ours refused with 'no shell specified'. Pressing ENTER, or
repeating the current value, is now a successful no-op.

An empty shell is accepted. passwd(5) gives the field no meaning of its
own and login falls back to /bin/sh, so -s '' selects the system default
rather than naming a program that does not exist.

The order of the two checks on a shell now matters and is documented.
chsh is setuid-root, so Path::exists answers with root's view of the
filesystem: testing existence first made the tool an oracle for paths
the caller cannot stat, one probe at a time --

    chsh -s /root/.ssh/id_ed25519

answering 'is not listed in /etc/shells' for a file that exists and
'does not exist' for one that does not. For a non-root caller the
membership test now runs first and discloses nothing, /etc/shells being
world-readable. Root still bypasses the list but not existence.

Validation also moved ahead of the PAM conversation, so a refused shell
no longer costs a password prompt, and mutate_passwd no longer calls
setuid(0): euid 0 is enough, and raising the real uid made
caller_is_root() answer true for every caller.

* docs: rewrite the chfn and chsh man pages; cover self-service end to end

The man pages documented neither interactive mode, nor CHFN_RESTRICT,
nor the restricted-account rule, nor what an empty shell field means,
and chfn's still said a field option was mandatory. Both now carry
permissions, value restrictions, configuration, files and worked
examples, and chsh explains why the two shell checks run in the order
they do.

The deployment suite gains eighteen assertions against the real setuid
binaries: interactive chfn and chsh through PAM, an empty answer as a
no-op, CHFN_RESTRICT enforced on interactive input, the empty shell
field, and the oracle itself -- an existing and a missing path under
/root must give a non-root caller the same answer, with no password
prompt before it.
2026-09-04 13:53:30 +02:00
Pierre Warnier 5bb637da38 pwck, grpck: report what the man pages say they report (#267)
grpck -q is documented as 'report errors only', but every error print was
gated on !quiet along with the warnings, so -q silenced the one thing it
is supposed to keep. Errors are now always shown.

A gshadow file that could not be parsed was turned into an empty list and
a warning, and the group/gshadow consistency check then ran only when that
list was non-empty -- so a malformed or empty gshadow beside a populated
group file reported nothing at all. The check is driven by the file
existing, and a parse failure is an error. grpck also verifies what its
man page calls 'a valid list of members and administrators': a name in
either list that no account carries is now reported.

pwck resolved a relative home or shell against its own working directory,
so it reported on whatever happened to be there; a relative path is itself
the fault and is reported as one. The exit code for a sort that cannot be
written was defined and never emitted; it is now used. The home and shell
checks move into their own function, which is also what keeps the entry
loop readable.
2026-09-04 13:18:15 +02:00
Pierre Warnier 90e5043fd3 group tools: close the groupadd race and add the missing options (#266)
groupadd read /etc/group before taking its lock, then checked the name and
allocated a GID from that snapshot. Two concurrent 'groupadd -r' runs could
therefore pick the same GID, and two 'groupadd www' could both conclude the
name was free. The lock is now taken first and the file read under it.

Four documented options were a usage error: groupadd -U and groupmod -U/-a
manage a group's member list, and groupdel -f removes a group even when it
is a user's primary group and succeeds when the group is already gone.

groupmod -p was a silent no-op on a system without /etc/gshadow; the
password now goes into the group file, which is where such a system keeps
it. groupdel left the deleted group in /etc/gshadow whenever it was the
only entry there -- the write was skipped for an empty result -- and could
not delete the last group in /etc/group at all, because the atomic writer
refuses a zero-length file. Both now unlink the file instead, an absent
file meaning the same as an empty one.
2026-09-04 13:10:35 +02:00
Pierre Warnier a1ca5d448e usermod: fix the group handling and report the documented exit codes (#265)
-g accepted only a numeric GID and wrote it through unchecked, so
'usermod -g 12345' left the account with a primary group that does not
exist. It now takes a name or a GID and requires the group to exist,
exiting 6 as usermod(8) documents.

-G '' split into one empty name and was rejected as a group that does not
exist; the man page defines it as removing every supplementary membership.
It does that now, -G accepts GIDs as well as names, and -a requires -G.

-l combined with -G added the *old* login to the groups, after the rename
had already happened -- a member naming no account. The new login is used.

/etc/gshadow was never updated by -G or -l, which is precisely what grpck
reports as 'members differ'. Both now keep it in step with /etc/group, and
it is only written when something actually changed.

-L prepended a second '!' to an already-locked password, which one -U
could not undo; it is now idempotent. -U refuses to leave an account with
no password instead of silently doing nothing. Group failures report 6 and
10 rather than the catch-all 1.
2026-09-04 13:02:56 +02:00
Pierre Warnier d48d19c749 useradd: honour /etc/default/useradd, add -b and -P, close the home chown race (#264)
* shadow-core: read and write /etc/default/useradd

useradd's own defaults live in /etc/default/useradd as KEY=VALUE, a
different format from login.defs and a different set of keys (GROUP, HOME,
INACTIVE, EXPIRE, SHELL, SKEL, CREATE_MAIL_SPOOL). Nothing read it, so a
site that set SHELL there had it ignored. A missing file reads as no
values, and the writer replaces the file atomically.

* useradd: honour /etc/default/useradd, add -b and -P, close the home chown race

useradd -D with a value printed the defaults and exited 0 without saving
anything, and nothing ever read /etc/default/useradd, so a site's
configured SHELL, SKEL or HOME base was silently ignored. -D now persists
what it is given, the file takes precedence over login.defs for the keys
it holds, and a new account uses those values.

-b/--base-dir and -P/--prefix are added, both documented in useradd(8) and
both previously a usage error. A UID of 4294967295 is rejected: that is
(uid_t)-1, the 'no change' sentinel of chown and setresuid.

The new home directory is chowned through a descriptor opened with
O_NOFOLLOW instead of by path. Between the mkdir and the chown, anyone
able to write the parent -- a home under /tmp, or a shared base directory
-- could replace the directory with a symlink and be handed its target.
2026-09-04 12:56:26 +02:00
Pierre Warnier 968c2d8bf2 useradd: follow useradd(8) for system accounts, groups, ID allocation and home creation (#263)
* shadow-core: match shadow-utils on name rules and ID allocation

Two behaviours verified against shadow-utils rather than assumed:

Names. 'useradd Alice' and 'useradd MACHINE$' both succeed there, so
rejecting upper case and a trailing dollar meant refusing accounts that
exist on real systems -- the dollar is how Samba names machine accounts.
Both are accepted now; the length cap and the rest of the character rules
are unchanged.

Allocation. Creating a, then b, deleting a, then creating c gives c the ID
after b's, not a's. We handed out the lowest free ID, so a new account
inherited a deleted one's ID and with it any files left behind. Allocation
now starts past the highest ID in use within the range and falls back to
the first gap only once the top of the range is taken.

* useradd: follow useradd(8) for system accounts, groups and home creation

System accounts (-r), all three verified against shadow-utils: no home
directory even when CREATE_HOME is yes, no aging information in
/etc/shadow (it writes 'svc:!:20700::::::'), and no subordinate UID/GID
ranges.

Groups: -g and -G now require the group to exist, named or numbered, and
report exit 6 when it does not. A numeric GID naming no group was
accepted, leaving the account with a primary group that does not exist --
id(1) then prints a bare number and new files get an unnamed group. -G
also refused the numeric form the man page allows.

Home directories: HOME_MODE from login.defs is honoured instead of a
hardcoded 0700, and a missing parent of the home is created (0755,
root-owned) instead of failing with ENOENT.
2026-09-04 12:47:31 +02:00