2026-03-24 14:30:22 +01:00
|
|
|
PREFIX ?= /usr/local
|
|
|
|
|
BINDIR ?= $(PREFIX)/sbin
|
|
|
|
|
|
2026-04-15 14:19:21 +02:00
|
|
|
# Tools that need setuid-root to allow non-root callers (change own password,
|
|
|
|
|
# GECOS, shell, effective group).
|
|
|
|
|
SETUID_TOOLS = passwd chfn chsh newgrp
|
2026-03-24 14:30:22 +01:00
|
|
|
|
2026-04-15 14:19:21 +02:00
|
|
|
# Root-only tools (no setuid; fail at getuid() check for non-root callers).
|
|
|
|
|
ROOT_TOOLS = useradd userdel usermod chpasswd chage \
|
|
|
|
|
groupadd groupdel groupmod pwck grpck
|
|
|
|
|
|
|
|
|
|
ALL_TOOLS = $(SETUID_TOOLS) $(ROOT_TOOLS)
|
|
|
|
|
|
|
|
|
|
.PHONY: all build build-multicall test install install-multicall uninstall clean
|
2026-03-24 14:30:22 +01:00
|
|
|
|
|
|
|
|
all: build
|
|
|
|
|
|
|
|
|
|
build:
|
2026-04-16 10:43:14 +02:00
|
|
|
cargo build --release --workspace --bins --exclude shadow-rs
|
2026-04-15 14:19:21 +02:00
|
|
|
|
|
|
|
|
build-multicall:
|
2026-04-16 10:43:14 +02:00
|
|
|
cargo build --release --bin shadow-rs
|
2026-03-24 14:30:22 +01:00
|
|
|
|
|
|
|
|
test:
|
|
|
|
|
cargo test --workspace
|
|
|
|
|
|
2026-04-15 14:19:21 +02:00
|
|
|
# Default install: 14 standalone per-tool binaries with least-privilege setuid
|
|
|
|
|
# layout matching GNU shadow-utils. Only passwd/chfn/chsh/newgrp are setuid.
|
2026-03-24 14:30:22 +01:00
|
|
|
install: build
|
2026-04-15 14:19:21 +02:00
|
|
|
@for tool in $(SETUID_TOOLS); do \
|
2026-04-16 10:43:14 +02:00
|
|
|
install -Dm4755 target/release/$$tool $(DESTDIR)$(BINDIR)/$$tool || exit 1; \
|
2026-04-15 14:40:52 +02:00
|
|
|
done
|
|
|
|
|
@for tool in $(ROOT_TOOLS); do \
|
2026-04-16 10:43:14 +02:00
|
|
|
install -Dm0755 target/release/$$tool $(DESTDIR)$(BINDIR)/$$tool || exit 1; \
|
2026-03-24 15:15:21 +01:00
|
|
|
done
|
2026-04-15 14:19:21 +02:00
|
|
|
@echo "Installed $(words $(ALL_TOOLS)) standalone binaries to $(DESTDIR)$(BINDIR)/"
|
|
|
|
|
@echo " setuid (4755): $(SETUID_TOOLS)"
|
|
|
|
|
@echo " root-only (0755): $(ROOT_TOOLS)"
|
|
|
|
|
|
|
|
|
|
# Opt-in install: single multicall binary with symlinks. Smaller footprint but
|
2026-04-16 10:43:14 +02:00
|
|
|
# larger setuid attack surface — the binary is installed setuid-root, so all 14
|
|
|
|
|
# applets run with euid=root when invoked via symlink. Intended for
|
2026-04-15 14:19:21 +02:00
|
|
|
# container/embedded use where disk savings matter and attack surface does not.
|
|
|
|
|
install-multicall: build-multicall
|
2026-04-16 10:43:14 +02:00
|
|
|
install -Dm4755 target/release/shadow-rs $(DESTDIR)$(BINDIR)/shadow-rs
|
2026-04-15 14:19:21 +02:00
|
|
|
@for tool in $(ALL_TOOLS); do \
|
|
|
|
|
ln -sf shadow-rs $(DESTDIR)$(BINDIR)/$$tool; \
|
|
|
|
|
done
|
|
|
|
|
@echo "Installed multicall shadow-rs + $(words $(ALL_TOOLS)) symlinks to $(DESTDIR)$(BINDIR)/"
|
2026-03-24 14:30:22 +01:00
|
|
|
|
|
|
|
|
uninstall:
|
2026-04-15 14:19:21 +02:00
|
|
|
@for tool in $(ALL_TOOLS); do \
|
2026-03-24 14:30:22 +01:00
|
|
|
rm -f $(DESTDIR)$(BINDIR)/$$tool; \
|
|
|
|
|
done
|
|
|
|
|
rm -f $(DESTDIR)$(BINDIR)/shadow-rs
|
|
|
|
|
@echo "Uninstalled shadow-rs from $(DESTDIR)$(BINDIR)/"
|
|
|
|
|
|
|
|
|
|
clean:
|
|
|
|
|
cargo clean
|