about summary refs log tree commit diff
path: root/nixos/modules/config/users-groups.nix
diff options
context:
space:
mode:
authorBenjamin Staffin <benley@gmail.com>2020-06-17 17:22:24 -0400
committerGitHub <noreply@github.com>2020-06-17 17:22:24 -0400
commit19d3665b75f59eb98ca656c2b643a4adc0f0744e (patch)
tree455aed025973e748f264df336d5dc0e7ae40dad5 /nixos/modules/config/users-groups.nix
parent13a14e2bfe4ff3b7da222624ce5749218105e465 (diff)
parent19dfc1b01149e5d60860cd0f4b0f8abcb3faabbf (diff)
downloadnixlib-19d3665b75f59eb98ca656c2b643a4adc0f0744e.tar
nixlib-19d3665b75f59eb98ca656c2b643a4adc0f0744e.tar.gz
nixlib-19d3665b75f59eb98ca656c2b643a4adc0f0744e.tar.bz2
nixlib-19d3665b75f59eb98ca656c2b643a4adc0f0744e.tar.lz
nixlib-19d3665b75f59eb98ca656c2b643a4adc0f0744e.tar.xz
nixlib-19d3665b75f59eb98ca656c2b643a4adc0f0744e.tar.zst
nixlib-19d3665b75f59eb98ca656c2b643a4adc0f0744e.zip
Merge branch 'master' into benley/melonDS
Diffstat (limited to 'nixos/modules/config/users-groups.nix')
-rw-r--r--nixos/modules/config/users-groups.nix32
1 files changed, 32 insertions, 0 deletions
diff --git a/nixos/modules/config/users-groups.nix b/nixos/modules/config/users-groups.nix
index 141e43fec39b..7fbbfcec7510 100644
--- a/nixos/modules/config/users-groups.nix
+++ b/nixos/modules/config/users-groups.nix
@@ -600,6 +600,38 @@ in {
       }
     ];
 
+    warnings =
+      builtins.filter (x: x != null) (
+        flip mapAttrsToList cfg.users (name: user:
+        # This regex matches a subset of the Modular Crypto Format (MCF)[1]
+        # informal standard. Since this depends largely on the OS or the
+        # specific implementation of crypt(3) we only support the (sane)
+        # schemes implemented by glibc and BSDs. In particular the original
+        # DES hash is excluded since, having no structure, it would validate
+        # common mistakes like typing the plaintext password.
+        #
+        # [1]: https://en.wikipedia.org/wiki/Crypt_(C)
+        let
+          sep = "\\$";
+          base64 = "[a-zA-Z0-9./]+";
+          id = "[a-z0-9-]+";
+          value = "[a-zA-Z0-9/+.-]+";
+          options = "${id}(=${value})?(,${id}=${value})*";
+          scheme  = "${id}(${sep}${options})?";
+          content = "${base64}${sep}${base64}";
+          mcf = "^${sep}${scheme}${sep}${content}$";
+        in
+        if (user.hashedPassword != null
+            && builtins.match mcf user.hashedPassword == null)
+        then
+        ''
+          The password hash of user "${name}" may be invalid. You must set a
+          valid hash or the user will be locked out of his account. Please
+          check the value of option `users.users."${name}".hashedPassword`.
+        ''
+        else null
+      ));
+
   };
 
 }