diff options
| author | tv <tv@krebsco.de> | 2026-12-04 01:56:12 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-12-04 15:44:35 +0000 |
| commit | f269fdc2626228534c39292c288a63c19a4c779d (patch) | |
| tree | 48d88407f3c1285b02b0233e8e7f4b1c491dcd23 /modules/slock.nix | |
| parent | 6d2f40458c8ffd623f29ff6722cdcd9fc8c57415 (diff) | |
slock: password hash from enstate, else setuid
The hash no longer goes into the store. With enstate, it can come from
the slot secrets/slock.hashed-password: then slock runs as its user, with
that hash. Without a hash, the credential falls back to "none" and
slock runs setuid root, reading /etc/shadow.
A validator for text/x-crypt-hash checks the hash the way slock uses
it, with crypt. The slot is optional, so enstate leaves out a hash the
validator objects to, and slock runs setuid instead of locking with a
hash no password matches.
Diffstat (limited to 'modules/slock.nix')
| -rw-r--r-- | modules/slock.nix | 72 |
1 files changed, 0 insertions, 72 deletions
diff --git a/modules/slock.nix b/modules/slock.nix deleted file mode 100644 index 14513347..00000000 --- a/modules/slock.nix +++ /dev/null @@ -1,72 +0,0 @@ -{ config, lib, mylib, pkgs, ... }: let - cfg = config.hrm.slock; -in { - options.hrm.slock = { - enable = lib.mkEnableOption "hrm.slock"; - package = lib.mkOption { - default = pkgs.writeDashBin "slock" '' - set -efu - display=''${DISPLAY#:} - service=slock-$LOGNAME@$display.service - exec ${pkgs.systemd}/bin/systemctl start "$service" - ''; - type = lib.types.package; - }; - user = lib.mkOption { - type = mylib.types.user; - }; - }; - config = lib.mkIf cfg.enable { - security.polkit.extraConfig = /* js */ '' - polkit.addRule(function(action, subject) { - if (action.id === "org.freedesktop.systemd1.manage-units" && - subject.user === ${builtins.toJSON cfg.user.name} && - /^slock-${cfg.user.name}@[0-9]+\.service$/.test(action.lookup("unit")) ) { - return polkit.Result.YES; - } - }); - ''; - systemd.services."slock-${cfg.user.name}@" = { - environment = { - DISPLAY = ":%I"; - LD_PRELOAD = pkgs.runCommandCC "slock-${cfg.user.name}.so" { - passAsFile = ["text"]; - text = /* c */ '' - #include <shadow.h> - #include <unistd.h> - - static struct spwd entry = { - .sp_namp = "", - .sp_pwdp = - ${mylib.toC config.users.users.${cfg.user.name}.hashedPassword}, - .sp_lstchg = 0, - .sp_min = 0, - .sp_max = 0, - .sp_warn = 0, - .sp_inact = 0, - .sp_expire = 0, - .sp_flag = 0, - }; - - extern struct spwd *getspnam(const char *name) { return &entry; } - extern int setgroups(size_t size, const gid_t *list) { return 0; } - extern int setgid(gid_t gid) { return 0; } - extern int setuid(uid_t uid) { return 0; } - ''; - } /* sh */ '' - gcc -Wall -shared -o $out -xc "$textPath" - ''; - }; - restartIfChanged = false; - serviceConfig = { - ExecStart = "${pkgs.slock}/bin/slock"; - OOMScoreAdjust = -1000; - Restart = "on-failure"; - RestartSec = "100ms"; - StartLimitBurst = 0; - SyslogIdentifier = "slock"; - User = cfg.user.name; - }; - }; - }; -} |
