diff --git a/Makefile b/Makefile index e0387b2..0355f5c 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,7 @@ export KERNEL_VERSION ?= 7.1 export BUSYBOX_VERSION ?= 1.38.0 export SYSTEMD_VERSION ?= 260 export DBUS_VERSION ?= 1.16.2 +export PAM_VERSION ?= 1.7.2 export DESKTOP ?= console export ENABLE_DESKTOP ?= 0 export ROOT_LABEL ?= FORGE_ROOT @@ -19,7 +20,7 @@ export SECURE_BOOT_CERT ?= export GNOME_SUITE ?= trixie export GNOME_MIRROR ?= http://deb.debian.org/debian -.PHONY: help deps image-deps fetch kernel busybox systemd dbus rootfs gnome-rootfs image gnome-image secure-boot-keys run run-image run-desktop run-gnome list-disks install clean distclean +.PHONY: help deps image-deps fetch kernel busybox pam systemd dbus rootfs gnome-rootfs image gnome-image secure-boot-keys run run-image run-desktop run-gnome list-disks install clean distclean help: @printf '%s\n' \ @@ -28,6 +29,7 @@ help: ' make image-deps - install Debian/Ubuntu host deps for image + run-image' \ ' make fetch - download upstream source tarballs' \ ' make kernel - build the Linux kernel and stage modules' \ + ' make pam - build Linux-PAM for login/session tracking' \ ' make busybox - build BusyBox rescue utilities' \ ' make systemd - build systemd PID 1' \ ' make dbus - build the D-Bus system bus daemon' \ @@ -61,6 +63,9 @@ kernel: fetch busybox: fetch @./scripts/build-busybox.sh +pam: fetch + @./scripts/build-pam.sh + systemd: fetch @./scripts/build-systemd.sh diff --git a/README.md b/README.md index b1f33a7..9404372 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ As of `2026-06-16`, the project defaults to: - systemd `260` - D-Bus `1.16.2` - BusyBox `1.38.0` +- Linux-PAM `1.7.2` - `amd64` / `x86_64` only - 64-bit only - UEFI boot @@ -39,7 +40,9 @@ make rootfs make run ``` -That dependency script is for Debian/Ubuntu hosts and installs only the packages needed for the console rootfs plus direct QEMU boot path. The build path then builds the kernel, systemd, D-Bus, BusyBox rescue tools, and a compressed initramfs, then boots it directly in QEMU over serial. +That dependency script is for Debian/Ubuntu hosts and installs only the packages needed for the console rootfs plus direct QEMU boot path. The build path then builds the kernel, Linux-PAM, systemd, D-Bus, BusyBox rescue tools, and a compressed initramfs, then boots it directly in QEMU over serial. + +The default console accounts are `forge` and `root`; both use the password `forge`. Console logins go through BusyBox `login`, Linux-PAM, and `pam_systemd.so`, so `systemd-logind` tracks real per-user sessions. To build a UEFI disk image: @@ -58,7 +61,7 @@ ENABLE_DESKTOP=1 make image ENABLE_DESKTOP=1 make run-desktop ``` -This keeps the regular ForgeOS rootfs path and stages Openbox, tint2, PCManFM, Xorg, fonts, icons, and a terminal into it. The serial root shell remains on `ttyS0`; `tty1` starts the desktop session. +This keeps the regular ForgeOS rootfs path and stages Openbox, tint2, PCManFM, Xorg, fonts, icons, and a terminal into it. The serial login prompt remains on `ttyS0`; `tty1` starts the desktop session. To build a GNOME desktop image, install `mmdebstrap` on the host and use the GNOME targets: @@ -86,16 +89,16 @@ sudo make install DISK=/dev/nvme0n1 ## Build Notes -- The root filesystem is not copied from a distro. It is assembled from upstream systemd, upstream D-Bus, upstream BusyBox rescue tools, copied runtime library dependencies for systemd and D-Bus, and the files in `overlay/rootfs/`. +- The root filesystem is not copied from a distro. It is assembled from upstream systemd, upstream D-Bus, upstream Linux-PAM, upstream BusyBox rescue tools, copied runtime library dependencies for systemd, D-Bus, PAM, and BusyBox, and the files in `overlay/rootfs/`. - The default removable-media boot path uses GRUB at `EFI/BOOT/BOOTX64.EFI` and keeps the kernel EFI stub at `EFI/BOOT/FORGEOS.EFI`. - The built-in kernel command line targets `PARTLABEL=root` and keeps Intel graphics modesetting enabled, with a couple of laptop display workarounds for newer firmware. - For default direct QEMU testing, `scripts/run-qemu.sh direct` uses the generated `rootfs.cpio.gz`. - The host-side installer expands the root partition to fill larger target disks. -- systemd is installed as `/sbin/init`. BusyBox remains available for `/bin/sh`, early switch-root support, and emergency command-line tools. +- systemd is installed as `/sbin/init`. BusyBox remains available for `/bin/sh`, PAM-backed `/bin/login`, early switch-root support, and emergency command-line tools. - A ForgeOS-native `neofetch` command is included in the overlay with a custom ForgeOS ASCII logo at `/usr/share/neofetch/ascii/distro/forgeos`. -- The console starts an immediate root shell on `tty1` and `ttyS0` through native systemd units instead of BusyBox `inittab`. +- The console starts PAM-backed login prompts on `tty1` and `ttyS0` through native systemd units instead of BusyBox `inittab`. - The system bus is provided by source-built `dbus-daemon` and socket-activated at `/run/dbus/system_bus_socket`. -- `systemd-logind` is included in the source-built systemd layer, owns `org.freedesktop.login1` on the system bus, and provides `loginctl` plus the logind varlink socket. +- `systemd-logind` is included in the source-built systemd layer, owns `org.freedesktop.login1` on the system bus, and provides `loginctl` plus the logind varlink socket. `pam_systemd.so` registers console logins as logind sessions. - DHCP networking is handled by `systemd-networkd`; DNS is handled by `systemd-resolved`, with `/etc/resolv.conf` linked to `/run/systemd/resolve/resolv.conf`. - `ENABLE_DESKTOP=1` adds an Openbox/tint2/PCManFM desktop layer to the normal ForgeOS rootfs by extracting a minimal Debian package payload while preserving the source-built systemd and D-Bus daemons. - `DESKTOP=gnome` switches rootfs assembly to a Debian package bootstrap because GNOME depends on a large desktop stack that ForgeOS does not source-build yet. @@ -127,21 +130,7 @@ The host needs `sbsign` for signed builds. Enroll `out/secure-boot/ForgeOS.cer` ## Toolchain Notes -BusyBox is configured as a static rescue binary by default. If the host toolchain does not provide static libc support, use a musl-capable compiler for the BusyBox part, for example: - -```bash -cd /home/joe/forgeos -CC=musl-gcc make rootfs -``` - -or: - -```bash -cd /home/joe/forgeos -CROSS_COMPILE=x86_64-linux-musl- make rootfs -``` - -systemd and D-Bus are built with Meson/Ninja and staged dynamically. The build copies the ELF runtime library closure from the native build host into the root filesystem, so cross-building the systemd userspace is not supported yet. +Linux-PAM, systemd, and D-Bus are built with Meson/Ninja and staged dynamically. BusyBox is also built dynamically so its `login` applet can load PAM modules. The build copies the ELF runtime library closure from the native build host into the root filesystem, so cross-building the userspace is not supported yet. ## Current Limits @@ -149,6 +138,7 @@ systemd and D-Bus are built with Meson/Ninja and staged dynamically. The build c - The kernel config includes common desktop, laptop, and QEMU storage/input paths, but not every vendor driver. - Wireless firmware, GPU acceleration, stock Microsoft-trusted Secure Boot/shim integration, audio, and power-management polish are not bundled yet. - There is no package manager yet. +- Account management is limited to the built-in `forge` and `root` accounts. - The Openbox desktop layer is a staged runtime payload, not an in-OS package manager. - GNOME support is currently a package-bootstrapped desktop flavor, not a source-built ForgeOS desktop stack. - The installer is host-side only; there is no in-OS guided installer yet. diff --git a/config/busybox.fragment b/config/busybox.fragment index bb9a689..2fa1b31 100644 --- a/config/busybox.fragment +++ b/config/busybox.fragment @@ -1,4 +1,5 @@ -CONFIG_STATIC=y +# CONFIG_STATIC is not set +CONFIG_PAM=y CONFIG_FEATURE_INSTALLER=y CONFIG_FEATURE_SH_STANDALONE=y CONFIG_FEATURE_PREFER_APPLETS=y @@ -34,6 +35,7 @@ CONFIG_KLOGD=y CONFIG_LESS=y CONFIG_LN=y CONFIG_LOGIN=y +CONFIG_LOGIN_SESSION_AS_CHILD=y CONFIG_LS=y CONFIG_MDEV=y CONFIG_FEATURE_MDEV_CONF=y @@ -71,3 +73,7 @@ CONFIG_UNZIP=y CONFIG_VI=y CONFIG_XARGS=y CONFIG_GETTY=y +CONFIG_FEATURE_UTMP=y +CONFIG_FEATURE_WTMP=y +CONFIG_FEATURE_SHADOWPASSWDS=y +CONFIG_USE_BB_SHADOW=y diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index e0fb444..4ec5ac8 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -7,6 +7,7 @@ ForgeOS defaults to a CLI-only operating system for `x86_64` desktops and laptop - Linux kernel for the kernel layer - systemd for PID 1 and service supervision - D-Bus for the system message bus +- Linux-PAM for local login authentication and session hooks - BusyBox for `/bin/sh`, early switch-root support, and compact rescue tools - custom units and configuration files from this repository @@ -24,7 +25,7 @@ ForgeOS currently targets UEFI systems. 4. The built kernel EFI stub is copied to `EFI/BOOT/FORGEOS.EFI`. 5. UEFI firmware executes GRUB from `EFI/BOOT/BOOTX64.EFI`, and GRUB starts the kernel. 6. The built-in kernel command line mounts `PARTLABEL=root` as the real root filesystem. -7. systemd starts as `/sbin/init`, activates the D-Bus system bus, starts `systemd-logind`, `systemd-resolved`, and `systemd-networkd`, reaches `multi-user.target`, and launches ForgeOS root-shell services on `tty1` and `ttyS0`. +7. systemd starts as `/sbin/init`, activates the D-Bus system bus, starts `systemd-logind`, `systemd-resolved`, and `systemd-networkd`, reaches `multi-user.target`, and launches PAM-backed login prompts on `tty1` and `ttyS0`. ## Root Filesystem Model @@ -32,12 +33,13 @@ The root filesystem is assembled in `staging/rootfs` from: - systemd install output from `staging/systemd` - D-Bus install output from `staging/dbus` -- runtime library dependencies copied from the native build host for systemd and D-Bus binaries +- Linux-PAM install output from `staging/pam` +- runtime library dependencies copied from the native build host for systemd, D-Bus, PAM, and BusyBox binaries - BusyBox install output for shell and rescue utilities - kernel modules from the kernel build - the repository overlay in `overlay/rootfs` -The default network path uses DHCP through `systemd-networkd`. DNS servers learned from DHCP are exposed through `systemd-resolved`, and `/etc/resolv.conf` is a symlink to the resolved-managed compatibility file at `/run/systemd/resolve/resolv.conf`. Tools that query systemd over D-Bus use the system bus at `/run/dbus/system_bus_socket`. The source-built systemd layer also includes `systemd-logind`, `loginctl`, the `org.freedesktop.login1` system-bus policy, and the logind varlink socket. +The default network path uses DHCP through `systemd-networkd`. DNS servers learned from DHCP are exposed through `systemd-resolved`, and `/etc/resolv.conf` is a symlink to the resolved-managed compatibility file at `/run/systemd/resolve/resolv.conf`. Tools that query systemd over D-Bus use the system bus at `/run/dbus/system_bus_socket`. The source-built systemd layer also includes `systemd-logind`, `loginctl`, `pam_systemd.so`, the `org.freedesktop.login1` system-bus policy, and the logind varlink socket. Console login uses BusyBox `getty` and `login`; `/etc/pam.d/login` authenticates against `/etc/shadow` with `pam_unix.so` and registers sessions with `pam_systemd.so`. The default console build also generates `out/rootfs.cpio.gz` for quick QEMU smoke tests. Desktop-enabled rootfs builds skip the initramfs artifact and boot through the ext4 root partition image. @@ -88,7 +90,7 @@ This is enough for a first CLI OS image and a development boot path, but not yet - source-built GNOME and graphical desktop dependency closure - source-built Openbox/Xorg/GTK graphical dependency closure - source-built dependency closure for systemd and D-Bus runtime libraries -- user management beyond the root shell +- account management beyond the built-in `forge` and `root` users - in-OS guided installer and update system - hardening review of the kernel and userspace defaults diff --git a/overlay/rootfs/etc/group b/overlay/rootfs/etc/group index 85cd812..c1a1c51 100644 --- a/overlay/rootfs/etc/group +++ b/overlay/rootfs/etc/group @@ -1,9 +1,14 @@ root:x:0: tty:x:5: disk:x:6: +audio:x:29:forge utmp:x:43: +video:x:44:forge messagebus:x:81: +users:x:100:forge +input:x:104:forge systemd-journal:x:190: systemd-network:x:192: systemd-resolve:x:193: +forge:x:1000: nobody:x:65534: diff --git a/overlay/rootfs/etc/gshadow b/overlay/rootfs/etc/gshadow new file mode 100644 index 0000000..1216c93 --- /dev/null +++ b/overlay/rootfs/etc/gshadow @@ -0,0 +1,14 @@ +root:*:: +tty:*:: +disk:*:: +audio:*::forge +utmp:*:: +video:*::forge +messagebus:*:: +users:*::forge +input:*::forge +systemd-journal:*:: +systemd-network:*:: +systemd-resolve:*:: +forge:!:: +nobody:*:: diff --git a/overlay/rootfs/etc/nsswitch.conf b/overlay/rootfs/etc/nsswitch.conf new file mode 100644 index 0000000..23cd111 --- /dev/null +++ b/overlay/rootfs/etc/nsswitch.conf @@ -0,0 +1,11 @@ +passwd: files +group: files +shadow: files + +hosts: files dns +networks: files + +protocols: files +services: files +ethers: files +rpc: files diff --git a/overlay/rootfs/etc/pam.d/login b/overlay/rootfs/etc/pam.d/login new file mode 100644 index 0000000..23804dd --- /dev/null +++ b/overlay/rootfs/etc/pam.d/login @@ -0,0 +1,7 @@ +#%PAM-1.0 + +auth required pam_unix.so nullok +account required pam_unix.so +password required pam_unix.so sha512 shadow +session required pam_unix.so +session optional pam_systemd.so diff --git a/overlay/rootfs/etc/pam.d/other b/overlay/rootfs/etc/pam.d/other new file mode 100644 index 0000000..aac3fc7 --- /dev/null +++ b/overlay/rootfs/etc/pam.d/other @@ -0,0 +1,6 @@ +#%PAM-1.0 + +auth required pam_deny.so +account required pam_deny.so +password required pam_deny.so +session required pam_deny.so diff --git a/overlay/rootfs/etc/pam.d/systemd-user b/overlay/rootfs/etc/pam.d/systemd-user new file mode 100644 index 0000000..e6d6808 --- /dev/null +++ b/overlay/rootfs/etc/pam.d/systemd-user @@ -0,0 +1,4 @@ +#%PAM-1.0 + +account required pam_unix.so no_pass_expiry +session optional pam_systemd.so diff --git a/overlay/rootfs/etc/passwd b/overlay/rootfs/etc/passwd index e56db57..b468607 100644 --- a/overlay/rootfs/etc/passwd +++ b/overlay/rootfs/etc/passwd @@ -1,4 +1,5 @@ -root::0:0:root:/root:/bin/sh +root:x:0:0:root:/root:/bin/sh +forge:x:1000:1000:ForgeOS User:/home/forge:/bin/sh systemd-network:x:192:192:systemd Network Management:/:/bin/sh systemd-resolve:x:193:193:systemd Resolver:/:/bin/sh messagebus:x:81:81:System Message Bus:/:/bin/sh diff --git a/overlay/rootfs/etc/shadow b/overlay/rootfs/etc/shadow new file mode 100644 index 0000000..4dd701f --- /dev/null +++ b/overlay/rootfs/etc/shadow @@ -0,0 +1,6 @@ +root:$6$forgeos$gPbch8oHqLnms/ljQGrpqE5btu4FY8J9ryX.9/CfzBY6CyakPaoEkHapeKRjkZbg3BdAdZz6eDzPD0YOV3CYK0:20620:0:99999:7::: +forge:$6$forgeos$gPbch8oHqLnms/ljQGrpqE5btu4FY8J9ryX.9/CfzBY6CyakPaoEkHapeKRjkZbg3BdAdZz6eDzPD0YOV3CYK0:20620:0:99999:7::: +systemd-network:*:20620:0:99999:7::: +systemd-resolve:*:20620:0:99999:7::: +messagebus:*:20620:0:99999:7::: +nobody:*:20620:0:99999:7::: diff --git a/overlay/rootfs/etc/shells b/overlay/rootfs/etc/shells new file mode 100644 index 0000000..c2cdaa0 --- /dev/null +++ b/overlay/rootfs/etc/shells @@ -0,0 +1 @@ +/bin/sh diff --git a/overlay/rootfs/etc/systemd/system-preset/00-forgeos.preset b/overlay/rootfs/etc/systemd/system-preset/00-forgeos.preset index 2c2ccff..42a055a 100644 --- a/overlay/rootfs/etc/systemd/system-preset/00-forgeos.preset +++ b/overlay/rootfs/etc/systemd/system-preset/00-forgeos.preset @@ -1,6 +1,6 @@ disable * -enable forgeos-shell@tty1.service -enable forgeos-shell@ttyS0.service +enable forgeos-login@tty1.service +enable forgeos-login@ttyS0.service enable forgeos-bootdiag.service enable forgeos-console-banner.service enable dbus.service diff --git a/overlay/rootfs/etc/systemd/system/forgeos-login@.service b/overlay/rootfs/etc/systemd/system/forgeos-login@.service new file mode 100644 index 0000000..991fa41 --- /dev/null +++ b/overlay/rootfs/etc/systemd/system/forgeos-login@.service @@ -0,0 +1,26 @@ +[Unit] +Description=ForgeOS login prompt on %I +Documentation=man:systemd.service(5) +Wants=systemd-logind.service +After=systemd-logind.service systemd-user-sessions.service getty-pre.target +Before=getty.target +ConditionPathExists=/dev/%I +IgnoreOnIsolate=yes + +[Service] +ExecStart=-/sbin/getty -L 0 %I linux +Type=idle +Restart=always +RestartSec=0 +UtmpIdentifier=%I +StandardInput=tty +StandardOutput=tty +TTYPath=/dev/%I +TTYReset=yes +TTYVHangup=yes +TTYVTDisallocate=yes +IgnoreSIGPIPE=no +SendSIGHUP=yes + +[Install] +WantedBy=getty.target diff --git a/overlay/rootfs/sbin/forgeos-console-banner b/overlay/rootfs/sbin/forgeos-console-banner index 0f274e6..745b02e 100755 --- a/overlay/rootfs/sbin/forgeos-console-banner +++ b/overlay/rootfs/sbin/forgeos-console-banner @@ -8,7 +8,7 @@ for tty in /dev/tty0 /dev/tty1 /dev/ttyS0 /dev/console; do { echo echo "ForgeOS boot complete: $(uname -r) on $(uname -m)" - echo "Root shell is available on tty1 and ttyS0." + echo "Login prompts are available on tty1 and ttyS0." echo } > "$tty" 2>/dev/null || true done diff --git a/overlay/rootfs/usr/lib/tmpfiles.d/forgeos.conf b/overlay/rootfs/usr/lib/tmpfiles.d/forgeos.conf new file mode 100644 index 0000000..c98959d --- /dev/null +++ b/overlay/rootfs/usr/lib/tmpfiles.d/forgeos.conf @@ -0,0 +1,5 @@ +d /home/forge 0700 forge forge - +z /home/forge 0700 forge forge - +z /root 0700 root root - +z /etc/shadow 0600 root root - +z /etc/gshadow 0600 root root - diff --git a/scripts/build-busybox.sh b/scripts/build-busybox.sh index 4654ba0..5190d76 100755 --- a/scripts/build-busybox.sh +++ b/scripts/build-busybox.sh @@ -8,6 +8,7 @@ require_cmd make "$CC" bzip2 ensure_dirs [[ -d "$BUSYBOX_SRC_DIR" ]] || "$ROOT_DIR/scripts/fetch-sources.sh" +[[ -f "$PAM_STAGING_DIR/.forgeos-pam-complete" ]] || "$ROOT_DIR/scripts/build-pam.sh" msg "configuring BusyBox ${BUSYBOX_VERSION}" rm -rf "$BUSYBOX_BUILD_DIR" @@ -17,7 +18,12 @@ make -C "$BUSYBOX_SRC_DIR" O="$BUSYBOX_BUILD_DIR" defconfig apply_kconfig_fragment "$BUSYBOX_BUILD_DIR/.config" "$ROOT_DIR/config/busybox.fragment" msg "building BusyBox ${BUSYBOX_VERSION}" -make -C "$BUSYBOX_SRC_DIR" O="$BUSYBOX_BUILD_DIR" CROSS_COMPILE="$CROSS_COMPILE" -j"$JOBS" CC="$CC" +make -C "$BUSYBOX_SRC_DIR" O="$BUSYBOX_BUILD_DIR" \ + CROSS_COMPILE="$CROSS_COMPILE" \ + CC="$CC" \ + EXTRA_CFLAGS="-I$PAM_STAGING_DIR/usr/include" \ + EXTRA_LDFLAGS="-L$PAM_STAGING_DIR/usr/lib" \ + -j"$JOBS" install -Dm755 "$BUSYBOX_BUILD_DIR/busybox" "$OUT_DIR/busybox" install -Dm644 "$BUSYBOX_BUILD_DIR/.config" "$OUT_DIR/busybox.config" diff --git a/scripts/build-pam.sh b/scripts/build-pam.sh new file mode 100755 index 0000000..804a49c --- /dev/null +++ b/scripts/build-pam.sh @@ -0,0 +1,107 @@ +#!/usr/bin/env bash + +set -euo pipefail + +source "$(dirname "$0")/common.sh" + +require_cmd meson ninja pkg-config "$CC" file ldd ldconfig install bison flex +ensure_dirs + +[[ -z "$CROSS_COMPILE" ]] || die "Linux-PAM rootfs staging currently requires a native build; CROSS_COMPILE is not supported" +[[ "$ARCH" == "x86_64" ]] || die "Linux-PAM rootfs staging currently supports ARCH=x86_64 only" +[[ -d "$PAM_SRC_DIR" ]] || "$ROOT_DIR/scripts/fetch-sources.sh" + +copy_runtime_dep() { + local dep=$1 + local dest + + [[ -e "$dep" ]] || return 0 + dest="$PAM_STAGING_DIR$dep" + mkdir -p "$(dirname "$dest")" + install -Dm755 "$dep" "$dest" +} + +copy_elf_deps() { + local elf=$1 + local line dep + + LD_LIBRARY_PATH="$PAM_STAGING_DIR/usr/lib:${LD_LIBRARY_PATH:-}" ldd "$elf" 2>/dev/null | while IFS= read -r line; do + dep= + case "$line" in + *"=>"*"/"*) + dep=${line#*=> } + dep=${dep%% *} + ;; + [[:space:]]/*) + dep=${line#"${line%%[![:space:]]*}"} + dep=${dep%% *} + ;; + esac + [[ -n "${dep:-}" && "$dep" = /* ]] || continue + case "$dep" in + "$PAM_STAGING_DIR"/*) + continue + ;; + esac + copy_runtime_dep "$dep" + done +} + +msg "configuring Linux-PAM ${PAM_VERSION}" +rm -rf "$PAM_BUILD_DIR" "$PAM_STAGING_DIR" +mkdir -p "$PAM_BUILD_DIR" "$PAM_STAGING_DIR" + +meson setup "$PAM_BUILD_DIR" "$PAM_SRC_DIR" \ + --prefix=/usr \ + --libdir=lib \ + --sysconfdir=/etc \ + --localstatedir=/var \ + -Ddocs=disabled \ + -Di18n=disabled \ + -Daudit=disabled \ + -Deconf=disabled \ + -Dlogind=disabled \ + -Delogind=disabled \ + -Dopenssl=disabled \ + -Dpwaccess=disabled \ + -Dselinux=disabled \ + -Dnis=disabled \ + -Dexamples=false \ + -Dxtests=false \ + -Dpam_userdb=disabled \ + -Dpam_lastlog=disabled \ + -Dpam_unix=enabled \ + -Dsecuredir=/usr/lib/security \ + -Dsconfigdir=/etc/security \ + -Dvendordir=/usr/share/pam + +msg "building Linux-PAM ${PAM_VERSION}" +meson compile -C "$PAM_BUILD_DIR" -j "$JOBS" + +msg "installing Linux-PAM ${PAM_VERSION}" +DESTDIR="$PAM_STAGING_DIR" meson install -C "$PAM_BUILD_DIR" --no-rebuild + +mkdir -p "$PAM_BUILD_DIR/pkgconfig" +for pc in pam pam_misc pamc; do + sed "s|^prefix=.*|prefix=$PAM_STAGING_DIR/usr|" \ + "$PAM_STAGING_DIR/usr/lib/pkgconfig/$pc.pc" > "$PAM_BUILD_DIR/pkgconfig/$pc.pc" +done + +msg "copying Linux-PAM runtime library dependencies" +while IFS= read -r -d '' elf; do + file_type=$(file -b "$elf" 2>/dev/null || true) + case "$file_type" in + *ELF*) copy_elf_deps "$elf" ;; + esac +done < <(find "$PAM_STAGING_DIR" -type f \( -perm /111 -o -name '*.so' -o -name '*.so.*' \) -print0) + +[[ -e "$PAM_STAGING_DIR/usr/lib/libpam.so" ]] || die "libpam was not installed" +[[ -e "$PAM_STAGING_DIR/usr/lib/libpam_misc.so" ]] || die "libpam_misc was not installed" +[[ -f "$PAM_STAGING_DIR/usr/include/security/pam_appl.h" ]] || die "PAM headers were not installed" +[[ -f "$PAM_STAGING_DIR/usr/lib/pkgconfig/pam.pc" ]] || die "PAM pkg-config file was not installed" +[[ -f "$PAM_STAGING_DIR/usr/lib/security/pam_unix.so" ]] || die "pam_unix module was not installed" +[[ -f "$PAM_STAGING_DIR/usr/lib/security/pam_deny.so" ]] || die "pam_deny module was not installed" +[[ -f "$PAM_STAGING_DIR/usr/lib/security/pam_permit.so" ]] || die "pam_permit module was not installed" + +touch "$PAM_STAGING_DIR/.forgeos-pam-complete" +msg "Linux-PAM staging tree: $PAM_STAGING_DIR" diff --git a/scripts/build-rootfs.sh b/scripts/build-rootfs.sh index a619544..b394440 100755 --- a/scripts/build-rootfs.sh +++ b/scripts/build-rootfs.sh @@ -4,6 +4,54 @@ set -euo pipefail source "$(dirname "$0")/common.sh" +copy_runtime_dep() { + local dep=$1 + local dest + + [[ -e "$dep" ]] || return 0 + case "$dep" in + "$PAM_STAGING_DIR"/*) + dest="$ROOTFS_STAGING_DIR/${dep#"$PAM_STAGING_DIR"/}" + ;; + "$ROOTFS_STAGING_DIR"/*) + dest="$dep" + ;; + "$SYSTEMD_STAGING_DIR"/*) + dest="$ROOTFS_STAGING_DIR/${dep#"$SYSTEMD_STAGING_DIR"/}" + ;; + "$DBUS_STAGING_DIR"/*) + dest="$ROOTFS_STAGING_DIR/${dep#"$DBUS_STAGING_DIR"/}" + ;; + *) + dest="$ROOTFS_STAGING_DIR$dep" + ;; + esac + + [[ -e "$dest" ]] && return 0 + mkdir -p "$(dirname "$dest")" + install -Dm755 "$dep" "$dest" +} + +copy_busybox_deps() { + local line dep + + LD_LIBRARY_PATH="$ROOTFS_STAGING_DIR/usr/lib:$PAM_STAGING_DIR/usr/lib:$SYSTEMD_STAGING_DIR/usr/lib:$DBUS_STAGING_DIR/usr/lib:${LD_LIBRARY_PATH:-}" ldd "$BUSYBOX_BUILD_DIR/busybox" 2>/dev/null | while IFS= read -r line; do + dep= + case "$line" in + *"=>"*"/"*) + dep=${line#*=> } + dep=${dep%% *} + ;; + [[:space:]]/*) + dep=${line#"${line%%[![:space:]]*}"} + dep=${dep%% *} + ;; + esac + [[ -n "${dep:-}" && "$dep" = /* ]] || continue + copy_runtime_dep "$dep" + done +} + if [[ "$DESKTOP" == "gnome" ]]; then exec "$ROOT_DIR/scripts/build-gnome-rootfs.sh" fi @@ -11,8 +59,11 @@ fi require_cmd make rsync cpio gzip ensure_dirs -[[ -x "$BUSYBOX_BUILD_DIR/busybox" ]] || "$ROOT_DIR/scripts/build-busybox.sh" -[[ -x "$SYSTEMD_STAGING_DIR/usr/lib/systemd/systemd" && -x "$SYSTEMD_STAGING_DIR/usr/lib/systemd/systemd-logind" && -f "$SYSTEMD_STAGING_DIR/.forgeos-systemd-complete" ]] || "$ROOT_DIR/scripts/build-systemd.sh" +[[ -f "$PAM_STAGING_DIR/.forgeos-pam-complete" ]] || "$ROOT_DIR/scripts/build-pam.sh" +[[ -x "$BUSYBOX_BUILD_DIR/busybox" && -f "$OUT_DIR/busybox.config" ]] || "$ROOT_DIR/scripts/build-busybox.sh" +grep -qx 'CONFIG_PAM=y' "$OUT_DIR/busybox.config" || "$ROOT_DIR/scripts/build-busybox.sh" +grep -qx 'CONFIG_LOGIN_SESSION_AS_CHILD=y' "$OUT_DIR/busybox.config" || "$ROOT_DIR/scripts/build-busybox.sh" +[[ -x "$SYSTEMD_STAGING_DIR/usr/lib/systemd/systemd" && -x "$SYSTEMD_STAGING_DIR/usr/lib/systemd/systemd-logind" && -f "$SYSTEMD_STAGING_DIR/usr/lib/security/pam_systemd.so" && -f "$SYSTEMD_STAGING_DIR/.forgeos-systemd-complete" ]] || "$ROOT_DIR/scripts/build-systemd.sh" [[ -x "$DBUS_STAGING_DIR/usr/bin/dbus-daemon" && -f "$DBUS_STAGING_DIR/.forgeos-dbus-complete" ]] || "$ROOT_DIR/scripts/build-dbus.sh" [[ -f "$OUT_DIR/bzImage" ]] || "$ROOT_DIR/scripts/build-kernel.sh" @@ -20,17 +71,24 @@ msg "assembling root filesystem" rm -rf "$ROOTFS_STAGING_DIR" mkdir -p "$ROOTFS_STAGING_DIR" -make -C "$BUSYBOX_SRC_DIR" O="$BUSYBOX_BUILD_DIR" CONFIG_PREFIX="$ROOTFS_STAGING_DIR" install +make -C "$BUSYBOX_SRC_DIR" O="$BUSYBOX_BUILD_DIR" \ + CONFIG_PREFIX="$ROOTFS_STAGING_DIR" \ + EXTRA_CFLAGS="-I$PAM_STAGING_DIR/usr/include" \ + EXTRA_LDFLAGS="-L$PAM_STAGING_DIR/usr/lib" \ + install +rsync -a "$PAM_STAGING_DIR"/ "$ROOTFS_STAGING_DIR"/ rsync -a "$SYSTEMD_STAGING_DIR"/ "$ROOTFS_STAGING_DIR"/ rsync -a "$DBUS_STAGING_DIR"/ "$ROOTFS_STAGING_DIR"/ +copy_busybox_deps -mkdir -p "$ROOTFS_STAGING_DIR"/{proc,sys,dev,run/dbus,tmp,var/lib/dbus,var/log,root,boot,mnt,etc/systemd/system} +mkdir -p "$ROOTFS_STAGING_DIR"/{proc,sys,dev,run/dbus,tmp,var/lib/dbus,var/log,root,home/forge,boot,mnt,etc/systemd/system} rsync -a "$OVERLAY_DIR"/ "$ROOTFS_STAGING_DIR"/ rm -f "$ROOTFS_STAGING_DIR/sbin/init" ln -s ../usr/lib/systemd/systemd "$ROOTFS_STAGING_DIR/sbin/init" ln -sfn ../../sbin/modprobe "$ROOTFS_STAGING_DIR/usr/bin/modprobe" ln -sfn ../run/systemd/resolve/resolv.conf "$ROOTFS_STAGING_DIR/etc/resolv.conf" +ln -sfn ../run "$ROOTFS_STAGING_DIR/var/run" mkdir -p \ "$ROOTFS_STAGING_DIR/etc/systemd/system/getty.target.wants" \ @@ -40,10 +98,10 @@ mkdir -p \ ln -sfn /usr/lib/systemd/system/multi-user.target \ "$ROOTFS_STAGING_DIR/etc/systemd/system/default.target" -ln -sfn /etc/systemd/system/forgeos-shell@.service \ - "$ROOTFS_STAGING_DIR/etc/systemd/system/getty.target.wants/forgeos-shell@tty1.service" -ln -sfn /etc/systemd/system/forgeos-shell@.service \ - "$ROOTFS_STAGING_DIR/etc/systemd/system/getty.target.wants/forgeos-shell@ttyS0.service" +ln -sfn /etc/systemd/system/forgeos-login@.service \ + "$ROOTFS_STAGING_DIR/etc/systemd/system/getty.target.wants/forgeos-login@tty1.service" +ln -sfn /etc/systemd/system/forgeos-login@.service \ + "$ROOTFS_STAGING_DIR/etc/systemd/system/getty.target.wants/forgeos-login@ttyS0.service" ln -sfn /etc/systemd/system/forgeos-bootdiag.service \ "$ROOTFS_STAGING_DIR/etc/systemd/system/multi-user.target.wants/forgeos-bootdiag.service" ln -sfn /etc/systemd/system/forgeos-console-banner.service \ @@ -95,6 +153,10 @@ chmod 755 \ "$ROOTFS_STAGING_DIR/sbin/forgeos-switch-root" \ "$ROOTFS_STAGING_DIR/usr/bin/neofetch" \ "$ROOTFS_STAGING_DIR/usr/share/udhcpc/default.script" +chmod 700 "$ROOTFS_STAGING_DIR/root" "$ROOTFS_STAGING_DIR/home/forge" +chown 1000:1000 "$ROOTFS_STAGING_DIR/home/forge" +[[ ! -f "$ROOTFS_STAGING_DIR/etc/shadow" ]] || chmod 600 "$ROOTFS_STAGING_DIR/etc/shadow" +[[ ! -f "$ROOTFS_STAGING_DIR/etc/gshadow" ]] || chmod 600 "$ROOTFS_STAGING_DIR/etc/gshadow" find "$ROOTFS_STAGING_DIR" -printf '%P\n' | LC_ALL=C sort > "$OUT_DIR/rootfs.manifest" diff --git a/scripts/build-systemd.sh b/scripts/build-systemd.sh index 569c843..5493a3c 100755 --- a/scripts/build-systemd.sh +++ b/scripts/build-systemd.sh @@ -10,13 +10,21 @@ ensure_dirs [[ -z "$CROSS_COMPILE" ]] || die "systemd rootfs staging currently requires a native build; CROSS_COMPILE is not supported" [[ "$ARCH" == "x86_64" ]] || die "systemd rootfs staging currently supports ARCH=x86_64 only" [[ -d "$SYSTEMD_SRC_DIR" ]] || "$ROOT_DIR/scripts/fetch-sources.sh" +[[ -f "$PAM_STAGING_DIR/.forgeos-pam-complete" && -f "$PAM_BUILD_DIR/pkgconfig/pam.pc" ]] || "$ROOT_DIR/scripts/build-pam.sh" copy_runtime_dep() { local dep=$1 local dest [[ -e "$dep" ]] || return 0 - dest="$SYSTEMD_STAGING_DIR$dep" + case "$dep" in + "$PAM_STAGING_DIR"/*) + dest="$SYSTEMD_STAGING_DIR/${dep#"$PAM_STAGING_DIR"/}" + ;; + *) + dest="$SYSTEMD_STAGING_DIR$dep" + ;; + esac mkdir -p "$(dirname "$dest")" install -Dm755 "$dep" "$dest" } @@ -25,7 +33,7 @@ copy_elf_deps() { local elf=$1 local line dep - ldd "$elf" 2>/dev/null | while IFS= read -r line; do + LD_LIBRARY_PATH="$PAM_STAGING_DIR/usr/lib:${LD_LIBRARY_PATH:-}" ldd "$elf" 2>/dev/null | while IFS= read -r line; do dep= case "$line" in *"=>"*"/"*) @@ -57,6 +65,8 @@ msg "configuring systemd ${SYSTEMD_VERSION}" rm -rf "$SYSTEMD_BUILD_DIR" "$SYSTEMD_STAGING_DIR" mkdir -p "$SYSTEMD_BUILD_DIR" "$SYSTEMD_STAGING_DIR" +PKG_CONFIG_PATH="$PAM_BUILD_DIR/pkgconfig:${PKG_CONFIG_PATH:-}" \ +LD_LIBRARY_PATH="$PAM_STAGING_DIR/usr/lib:${LD_LIBRARY_PATH:-}" \ meson setup "$SYSTEMD_BUILD_DIR" "$SYSTEMD_SRC_DIR" \ --prefix=/usr \ --libdir=lib \ @@ -112,6 +122,8 @@ meson setup "$SYSTEMD_BUILD_DIR" "$SYSTEMD_SRC_DIR" \ -Dmountfsd=false \ -Duserdb=false \ -Dhomed=disabled \ + -Dpamlibdir=/usr/lib/security \ + -Dpamconfdir=/etc/pam.d \ -Dnetworkd=true \ -Ddefault-network=false \ -Dtimedated=false \ @@ -143,7 +155,7 @@ meson setup "$SYSTEMD_BUILD_DIR" "$SYSTEMD_SRC_DIR" \ -Daudit=disabled \ -Dfdisk=disabled \ -Dkmod=disabled \ - -Dpam=disabled \ + -Dpam=enabled \ -Dpasswdqc=disabled \ -Dpwquality=disabled \ -Dmicrohttpd=disabled \ @@ -179,9 +191,11 @@ meson setup "$SYSTEMD_BUILD_DIR" "$SYSTEMD_SRC_DIR" \ -Ddefault-user-shell=/bin/sh msg "building systemd ${SYSTEMD_VERSION}" +LD_LIBRARY_PATH="$PAM_STAGING_DIR/usr/lib:${LD_LIBRARY_PATH:-}" \ meson compile -C "$SYSTEMD_BUILD_DIR" -j "$JOBS" msg "installing systemd ${SYSTEMD_VERSION}" +LD_LIBRARY_PATH="$PAM_STAGING_DIR/usr/lib:${LD_LIBRARY_PATH:-}" \ DESTDIR="$SYSTEMD_STAGING_DIR" meson install -C "$SYSTEMD_BUILD_DIR" --no-rebuild msg "copying systemd runtime library dependencies" @@ -197,6 +211,8 @@ copy_named_library libmount.so.1 [[ -x "$SYSTEMD_STAGING_DIR/usr/lib/systemd/systemd" ]] || die "systemd binary was not installed" [[ -x "$SYSTEMD_STAGING_DIR/usr/lib/systemd/systemd-logind" ]] || die "systemd-logind binary was not installed" [[ -x "$SYSTEMD_STAGING_DIR/usr/bin/loginctl" ]] || die "loginctl binary was not installed" +[[ -f "$SYSTEMD_STAGING_DIR/usr/lib/security/pam_systemd.so" ]] || die "pam_systemd module was not installed" +[[ -x "$SYSTEMD_STAGING_DIR/usr/lib/systemd/systemd-user-runtime-dir" ]] || die "systemd-user-runtime-dir was not installed" [[ -f "$SYSTEMD_STAGING_DIR/usr/share/dbus-1/system.d/org.freedesktop.login1.conf" ]] || die "logind D-Bus policy was not installed" touch "$SYSTEMD_STAGING_DIR/.forgeos-systemd-complete" msg "systemd staging tree: $SYSTEMD_STAGING_DIR" diff --git a/scripts/common.sh b/scripts/common.sh index ccacf1a..a5970f8 100755 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -15,6 +15,7 @@ KERNEL_VERSION=${KERNEL_VERSION:-7.1} BUSYBOX_VERSION=${BUSYBOX_VERSION:-1.38.0} SYSTEMD_VERSION=${SYSTEMD_VERSION:-260} DBUS_VERSION=${DBUS_VERSION:-1.16.2} +PAM_VERSION=${PAM_VERSION:-1.7.2} DESKTOP=${DESKTOP:-console} ENABLE_DESKTOP=${ENABLE_DESKTOP:-0} ROOT_LABEL=${ROOT_LABEL:-FORGE_ROOT} @@ -55,6 +56,8 @@ SYSTEMD_TARBALL="systemd-v${SYSTEMD_VERSION}.tar.gz" SYSTEMD_URL="https://github.com/systemd/systemd/archive/refs/tags/v${SYSTEMD_VERSION}.tar.gz" DBUS_TARBALL="dbus-${DBUS_VERSION}.tar.xz" DBUS_URL="https://dbus.freedesktop.org/releases/dbus/${DBUS_TARBALL}" +PAM_TARBALL="linux-pam-${PAM_VERSION}.tar.gz" +PAM_URL="https://github.com/linux-pam/linux-pam/archive/refs/tags/v${PAM_VERSION}.tar.gz" GNOME_SUITE=${GNOME_SUITE:-trixie} GNOME_MIRROR=${GNOME_MIRROR:-http://deb.debian.org/debian} OPENBOX_DESKTOP_PACKAGES=${OPENBOX_DESKTOP_PACKAGES:-openbox tint2 pcmanfm xinit xserver-xorg-core xserver-xorg-input-libinput xserver-xorg-video-fbdev xserver-xorg-video-vesa xserver-xorg-video-vmware lxterminal fonts-dejavu adwaita-icon-theme hicolor-icon-theme shared-mime-info} @@ -64,13 +67,16 @@ KERNEL_SRC_DIR="$SOURCE_DIR/linux-${KERNEL_VERSION}" BUSYBOX_SRC_DIR="$SOURCE_DIR/busybox-${BUSYBOX_VERSION}" SYSTEMD_SRC_DIR="$SOURCE_DIR/systemd-${SYSTEMD_VERSION}" DBUS_SRC_DIR="$SOURCE_DIR/dbus-${DBUS_VERSION}" +PAM_SRC_DIR="$SOURCE_DIR/linux-pam-${PAM_VERSION}" KERNEL_BUILD_DIR="$BUILD_DIR/linux-${KERNEL_VERSION}" BUSYBOX_BUILD_DIR="$BUILD_DIR/busybox-${BUSYBOX_VERSION}" SYSTEMD_BUILD_DIR="$BUILD_DIR/systemd-${SYSTEMD_VERSION}" DBUS_BUILD_DIR="$BUILD_DIR/dbus-${DBUS_VERSION}" +PAM_BUILD_DIR="$BUILD_DIR/linux-pam-${PAM_VERSION}" MODULES_STAGING_DIR="$STAGING_DIR/modules" SYSTEMD_STAGING_DIR="$STAGING_DIR/systemd" DBUS_STAGING_DIR="$STAGING_DIR/dbus" +PAM_STAGING_DIR="$STAGING_DIR/pam" ROOTFS_STAGING_DIR="$STAGING_DIR/rootfs" OPENBOX_DESKTOP_DEB_DIR=${OPENBOX_DESKTOP_DEB_DIR:-"$DOWNLOAD_DIR/openbox-desktop-debs"} OPENBOX_DESKTOP_APT_STATE_DIR=${OPENBOX_DESKTOP_APT_STATE_DIR:-"$BUILD_DIR/openbox-desktop-apt-state"} diff --git a/scripts/fetch-sources.sh b/scripts/fetch-sources.sh index 2b3cd28..d1b7824 100755 --- a/scripts/fetch-sources.sh +++ b/scripts/fetch-sources.sh @@ -11,10 +11,12 @@ download "$KERNEL_URL" "$DOWNLOAD_DIR/$KERNEL_TARBALL" download "$BUSYBOX_URL" "$DOWNLOAD_DIR/$BUSYBOX_TARBALL" download "$SYSTEMD_URL" "$DOWNLOAD_DIR/$SYSTEMD_TARBALL" download "$DBUS_URL" "$DOWNLOAD_DIR/$DBUS_TARBALL" +download "$PAM_URL" "$DOWNLOAD_DIR/$PAM_TARBALL" extract_tarball "$DOWNLOAD_DIR/$KERNEL_TARBALL" "$KERNEL_SRC_DIR" extract_tarball "$DOWNLOAD_DIR/$BUSYBOX_TARBALL" "$BUSYBOX_SRC_DIR" extract_tarball_into "$DOWNLOAD_DIR/$SYSTEMD_TARBALL" "$SYSTEMD_SRC_DIR" extract_tarball "$DOWNLOAD_DIR/$DBUS_TARBALL" "$DBUS_SRC_DIR" +extract_tarball_into "$DOWNLOAD_DIR/$PAM_TARBALL" "$PAM_SRC_DIR" msg "sources are ready" diff --git a/scripts/install-deps.sh b/scripts/install-deps.sh index fdbcd0c..c4e647b 100755 --- a/scripts/install-deps.sh +++ b/scripts/install-deps.sh @@ -30,6 +30,7 @@ packages=( perl kmod openssl + libcrypt-dev libcap-dev libmount-dev libblkid-dev diff --git a/scripts/stage-openbox-desktop.sh b/scripts/stage-openbox-desktop.sh index ebbe24f..57ee148 100755 --- a/scripts/stage-openbox-desktop.sh +++ b/scripts/stage-openbox-desktop.sh @@ -185,7 +185,7 @@ EOF Description=ForgeOS Openbox desktop Wants=dbus.service systemd-logind.service systemd-udevd.service After=dbus.service systemd-logind.service systemd-udevd.service systemd-user-sessions.service -Conflicts=forgeos-shell@tty1.service getty@tty1.service +Conflicts=forgeos-login@tty1.service forgeos-shell@tty1.service getty@tty1.service [Service] Type=simple @@ -212,6 +212,7 @@ EOF ln -sfn /etc/systemd/system/forgeos-desktop.service \ "$ROOTFS_STAGING_DIR/etc/systemd/system/multi-user.target.wants/forgeos-desktop.service" + rm -f "$ROOTFS_STAGING_DIR/etc/systemd/system/getty.target.wants/forgeos-login@tty1.service" rm -f "$ROOTFS_STAGING_DIR/etc/systemd/system/getty.target.wants/forgeos-shell@tty1.service" if [[ -e "$ROOTFS_STAGING_DIR/usr/lib/systemd/system/dbus.socket" ]]; then