2026-03-23 13:13:36 +01:00
|
|
|
|
<!-- spell-checker:ignore reimplementation setuid nscd subuid subgid gshadow -->
|
|
|
|
|
|
<div align="center">
|
|
|
|
|
|
|
2026-06-09 18:28:51 +09:00
|
|
|
|
# shadow
|
2026-03-23 13:13:36 +01:00
|
|
|
|
|
2026-06-09 18:28:51 +09:00
|
|
|
|
[](https://github.com/uutils/shadow/blob/main/LICENSE)
|
|
|
|
|
|
[](https://github.com/uutils/shadow/actions/workflows/ci.yml)
|
|
|
|
|
|
[](https://github.com/uutils/shadow)
|
2026-03-23 13:13:36 +01:00
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
2026-06-09 18:28:51 +09:00
|
|
|
|
A memory-safe reimplementation of the Linux
|
2026-03-23 13:13:36 +01:00
|
|
|
|
[shadow-utils](https://github.com/shadow-maint/shadow) in
|
|
|
|
|
|
[Rust](http://www.rust-lang.org). shadow-utils (`useradd`, `passwd`,
|
|
|
|
|
|
`groupadd`, etc.) is the suite of setuid-root tools that manages user accounts,
|
|
|
|
|
|
passwords, and groups on every Linux system.
|
|
|
|
|
|
|
|
|
|
|
|
## Why
|
|
|
|
|
|
|
|
|
|
|
|
shadow-utils runs as **root or setuid-root on every Linux system**. It parses
|
|
|
|
|
|
user-supplied input, writes to `/etc/passwd`, `/etc/shadow`, `/etc/group`, and
|
|
|
|
|
|
has had recent CVEs (CVE-2023-4641: password leak in memory, CVE-2024-56433:
|
2026-06-09 18:28:51 +09:00
|
|
|
|
subuid collision enabling account takeover). Until this project appear, there was **no
|
2026-04-03 15:16:41 +02:00
|
|
|
|
Rust reimplementation** — not in uutils, not in Prossimo/Trifecta, not on
|
|
|
|
|
|
crates.io.
|
2026-03-23 13:13:36 +01:00
|
|
|
|
|
|
|
|
|
|
[sudo-rs](https://github.com/trifectatechfoundation/sudo-rs) proved the model:
|
|
|
|
|
|
an independent Rust rewrite of a privilege-boundary tool can go from zero to
|
2026-06-09 18:28:51 +09:00
|
|
|
|
default-in-Ubuntu in under 3 years. This project follows that playbook.
|
2026-03-23 13:13:36 +01:00
|
|
|
|
|
|
|
|
|
|
## Goals
|
|
|
|
|
|
|
|
|
|
|
|
- **Drop-in replacement**: same flags, same exit codes, same output format as
|
|
|
|
|
|
GNU shadow-utils. Differences are treated as bugs.
|
2026-03-23 14:11:19 +01:00
|
|
|
|
- **uutils compatible**: built on [`uucore`](https://crates.io/crates/uucore)
|
|
|
|
|
|
with the standard `uumain()` / `uu_app()` API contract. Designed to merge
|
|
|
|
|
|
into the uutils ecosystem.
|
2026-03-23 13:13:36 +01:00
|
|
|
|
- **Memory safe**: eliminate entire classes of vulnerabilities (buffer overflows,
|
2026-03-23 14:11:19 +01:00
|
|
|
|
use-after-free, uninitialized memory) that affect the C original. Passwords
|
|
|
|
|
|
zeroed in memory via `zeroize`.
|
|
|
|
|
|
- **Well-tested**: unit tests, property-based tests (`proptest`), integration
|
|
|
|
|
|
tests, fuzz targets for all parsers. Tested on Debian, Alpine (musl), and
|
|
|
|
|
|
Fedora (SELinux).
|
2026-04-03 15:16:41 +02:00
|
|
|
|
- **Hardened**: Landlock filesystem sandboxing, signal blocking during
|
|
|
|
|
|
critical sections, core dump suppression, environment sanitization,
|
|
|
|
|
|
privilege drop during PAM.
|
2026-03-23 13:13:36 +01:00
|
|
|
|
- **Auditable**: small dependency tree, `cargo-deny` license and advisory
|
|
|
|
|
|
checks, no GPL dependencies.
|
|
|
|
|
|
|
|
|
|
|
|
## Status
|
|
|
|
|
|
|
|
|
|
|
|
| Tool | Status |
|
|
|
|
|
|
|------|--------|
|
2026-04-03 15:16:41 +02:00
|
|
|
|
| `passwd` | **All 16 flags implemented.** Drop-in for GNU passwd. PAM password change, Landlock sandboxing, `--root`, `--quiet`, `--stdin`. Output bit-for-bit identical with GNU. |
|
2026-03-24 09:58:50 +01:00
|
|
|
|
| `pwck` | **All checks implemented.** Drop-in for GNU pwck. Bit-for-bit identical output. |
|
2026-03-24 10:18:43 +01:00
|
|
|
|
| `useradd` | **Implemented.** UID/GID allocation, home dir + skel, shadow entry, group creation. |
|
|
|
|
|
|
| `userdel` | **Implemented.** Remove from all system files, optional home/mail cleanup. |
|
2026-04-03 15:16:41 +02:00
|
|
|
|
| `usermod` | **Implemented.** Modify all properties, group membership, lock/unlock, set pre-hashed password. |
|
2026-03-24 10:18:43 +01:00
|
|
|
|
| `chpasswd` | **Implemented.** Batch password change from stdin. |
|
|
|
|
|
|
| `chage` | **Implemented.** Password aging management, `-l` list mode. |
|
2026-03-24 10:46:23 +01:00
|
|
|
|
| `groupadd` | **Implemented.** Auto GID allocation, system groups, force mode. |
|
|
|
|
|
|
| `groupdel` | **Implemented.** Primary group usage check. |
|
|
|
|
|
|
| `groupmod` | **Implemented.** GID change, rename, password. |
|
|
|
|
|
|
| `grpck` | **Implemented.** Group/gshadow integrity verification. |
|
|
|
|
|
|
| `chfn` | **Implemented.** GECOS sub-field modification. |
|
|
|
|
|
|
| `chsh` | **Implemented.** Shell change with /etc/shells validation. |
|
|
|
|
|
|
| `newgrp` | **Implemented.** Effective group change with crypt verification. |
|
2026-03-23 13:13:36 +01:00
|
|
|
|
|
|
|
|
|
|
## Building
|
|
|
|
|
|
|
|
|
|
|
|
### Requirements
|
|
|
|
|
|
|
|
|
|
|
|
- Rust (stable toolchain)
|
|
|
|
|
|
- Linux (PAM headers, SELinux headers optional)
|
|
|
|
|
|
- Docker + Docker Compose (for testing)
|
|
|
|
|
|
|
|
|
|
|
|
### Build
|
|
|
|
|
|
|
|
|
|
|
|
```shell
|
2026-06-09 18:28:51 +09:00
|
|
|
|
git clone https://github.com/uutils/shadow
|
|
|
|
|
|
cd shadow
|
2026-03-23 13:13:36 +01:00
|
|
|
|
docker compose build debian
|
|
|
|
|
|
docker compose run --rm debian cargo build --release
|
|
|
|
|
|
```
|
|
|
|
|
|
|
2026-04-15 14:19:21 +02:00
|
|
|
|
### Install
|
|
|
|
|
|
|
|
|
|
|
|
Default install: 14 standalone per-tool binaries with least-privilege setuid
|
|
|
|
|
|
layout matching GNU shadow-utils. Only `passwd`, `chfn`, `chsh`, `newgrp` are
|
|
|
|
|
|
installed setuid-root; the other 10 are plain `0755`.
|
|
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
|
sudo make install PREFIX=/usr/local
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
Alternative: single multicall binary with symlinks. Smaller footprint (~14×
|
2026-04-16 10:43:14 +02:00
|
|
|
|
disk savings) but larger setuid attack surface — the binary is installed
|
|
|
|
|
|
setuid-root, so all 14 applets run with `euid=root` when invoked via symlink.
|
|
|
|
|
|
Intended for container/embedded use cases.
|
2026-04-15 14:19:21 +02:00
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
|
sudo make install-multicall PREFIX=/usr/local
|
|
|
|
|
|
```
|
|
|
|
|
|
|
2026-03-23 13:13:36 +01:00
|
|
|
|
### Test
|
|
|
|
|
|
|
|
|
|
|
|
All builds and tests run inside Docker containers to isolate from the host
|
|
|
|
|
|
system. Three distros are tested to catch libc and PAM differences:
|
|
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
|
docker compose run --rm debian cargo test --workspace # Debian Trixie (glibc)
|
|
|
|
|
|
docker compose run --rm alpine cargo test --workspace # Alpine (musl libc)
|
|
|
|
|
|
docker compose run --rm fedora cargo test --workspace # Fedora (SELinux enforcing)
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### Lint
|
|
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
|
docker compose run --rm debian cargo clippy --workspace --all-targets -- -D warnings
|
|
|
|
|
|
docker compose run --rm debian cargo fmt --all --check
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
## Architecture
|
|
|
|
|
|
|
2026-03-23 14:11:19 +01:00
|
|
|
|
Cargo workspace monorepo built on [`uucore`](https://crates.io/crates/uucore):
|
2026-03-23 13:13:36 +01:00
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
src/bin/shadow-rs.rs multicall binary (dispatches by argv[0])
|
|
|
|
|
|
|
|
|
|
|
|
|
src/uu/{tool}/ individual tool crates (passwd, useradd, ...)
|
|
|
|
|
|
|
|
2026-03-23 14:11:19 +01:00
|
|
|
|
┌────┴────┐
|
|
|
|
|
|
uucore shadow-core shared infrastructure + domain library
|
2026-03-23 13:13:36 +01:00
|
|
|
|
```
|
|
|
|
|
|
|
2026-03-23 14:11:19 +01:00
|
|
|
|
Tools use `uucore` for the standard uutils API (`UResult`, `#[uucore::main]`,
|
|
|
|
|
|
`show_error!`) and `shadow-core` for domain-specific functionality.
|
|
|
|
|
|
|
2026-03-23 13:13:36 +01:00
|
|
|
|
**shadow-core** provides:
|
|
|
|
|
|
- File parsers for `/etc/passwd`, `/etc/shadow`, `/etc/group`, `/etc/gshadow`,
|
|
|
|
|
|
`/etc/login.defs`, `/etc/subuid`, `/etc/subgid`
|
|
|
|
|
|
- Atomic file writes (lock, write tmp, fsync, rename, unlock, invalidate nscd)
|
|
|
|
|
|
- PAM integration (feature-gated)
|
|
|
|
|
|
- Username/groupname validation
|
|
|
|
|
|
- UID/GID allocation
|
|
|
|
|
|
- SELinux context handling (feature-gated)
|
|
|
|
|
|
|
|
|
|
|
|
Each **tool crate** exports `uumain()` and `uu_app()`, following
|
|
|
|
|
|
[uutils](https://github.com/uutils/coreutils) conventions exactly so a future
|
|
|
|
|
|
merge is frictionless.
|
|
|
|
|
|
|
|
|
|
|
|
## Docker Test Matrix
|
|
|
|
|
|
|
|
|
|
|
|
| Target | Base | libc | PAM | SELinux |
|
|
|
|
|
|
|--------|------|------|-----|---------|
|
|
|
|
|
|
| `debian` | `rust:latest` (Trixie) | glibc | Linux-PAM | headers |
|
|
|
|
|
|
| `alpine` | `rust:alpine` | musl | Linux-PAM | none |
|
|
|
|
|
|
| `fedora` | `fedora:latest` | glibc | Linux-PAM | enforcing |
|
|
|
|
|
|
|
2026-03-23 16:18:10 +01:00
|
|
|
|
## Credits
|
|
|
|
|
|
|
|
|
|
|
|
Security patterns from [OpenBSD](https://cvsweb.openbsd.org/src/usr.bin/passwd/)
|
|
|
|
|
|
(ISC license). PAM integration patterns from
|
|
|
|
|
|
[sudo-rs](https://github.com/trifectatechfoundation/sudo-rs) (Apache-2.0/MIT).
|
|
|
|
|
|
uutils infrastructure via [`uucore`](https://crates.io/crates/uucore) (MIT).
|
|
|
|
|
|
|
2026-04-03 16:19:35 +02:00
|
|
|
|
Code written by [Claude Code](https://docs.anthropic.com/en/docs/agents-and-tools/claude-code/overview) (Anthropic),
|
|
|
|
|
|
reviewed by [GitHub Copilot](https://github.com/features/copilot) and
|
|
|
|
|
|
[Google Gemini CLI](https://github.com/google-gemini/gemini-cli).
|
2026-03-23 16:18:10 +01:00
|
|
|
|
|
2026-03-23 13:13:36 +01:00
|
|
|
|
## Contributing
|
|
|
|
|
|
|
|
|
|
|
|
See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
|
|
|
|
|
2026-06-09 18:28:51 +09:00
|
|
|
|
**Important**: uutils/shadow is developed under a strict GPL clean-room policy. Do
|
2026-03-23 13:13:36 +01:00
|
|
|
|
**not** read, reference, or feed into an LLM any code from
|
|
|
|
|
|
[shadow-maint/shadow](https://github.com/shadow-maint/shadow) (GPL-2.0+).
|
|
|
|
|
|
Reference only: POSIX specs, man pages, BSD-licensed implementations (FreeBSD,
|
|
|
|
|
|
OpenBSD, musl), and sudo-rs.
|
|
|
|
|
|
|
|
|
|
|
|
## License
|
|
|
|
|
|
|
2026-06-09 18:28:51 +09:00
|
|
|
|
uutils/shadow is licensed under the [MIT License](LICENSE).
|
2026-03-23 13:13:36 +01:00
|
|
|
|
|
|
|
|
|
|
GNU shadow-utils is licensed under the GPL 2.0 or later.
|