git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/users-groups: handle password hashes with special meaning
commitc37347af7eaa0177e3a374dd94158ff546f20fdb authorrnhmjoj <rnhmjoj@inventati.org> dateThu 25 Jun 2020, 02:02 (6 years ago) parent99899e2
1 file changed+14−6
nixos/modules/config/users-groups.nix+14−6
nixos/modules/config/users-groups.nix+14−6
@@ -6,6 +6,16 @@ let
66 ids = config.ids;
77 cfg = config.users;
88
9+ # Check whether a password hash will allow login.
10+ allowsLogin = hash:
11+ hash == "" # login without password
12+ || !(lib.elem hash
13+ [ null # password login disabled
14+ "!" # password login disabled
15+ "!!" # a variant of "!"
16+ "*" # password unset
17+ ]);
18+
919 passwordDescription = ''
1020 The options <option>hashedPassword</option>,
1121 <option>password</option> and <option>passwordFile</option>
@@ -596,7 +606,7 @@ in {
596606 || cfg.group == "wheel"
597607 || elem "wheel" cfg.extraGroups)
598608 &&
599− (cfg.hashedPassword != null
609+ (allowsLogin cfg.hashedPassword
600610 || cfg.password != null
601611 || cfg.passwordFile != null
602612 || cfg.openssh.authorizedKeys.keys != []
@@ -639,15 +649,13 @@ in {
639649 content = "${base64}${sep}${base64}";
640650 mcf = "^${sep}${scheme}${sep}${content}$";
641651 in
642− if (user.hashedPassword != null # login disabled
652+ if (allowsLogin user.hashedPassword
643653 && user.hashedPassword != "" # login without password
644654 && builtins.match mcf user.hashedPassword == null)
645− then
646− ''
655+ then ''
647656 The password hash of user "${name}" may be invalid. You must set a
648657 valid hash or the user will be locked out of their account. Please
649− check the value of option `users.users."${name}".hashedPassword`.
650− ''
658+ check the value of option `users.users."${name}".hashedPassword`.''
651659 else null
652660 ));
653661