Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion nixos/modules/security/pam.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,7 @@ let
name = "lastlog";
enable = cfg.updateWtmp;
control = "required";
modulePath = "${package}/lib/security/pam_lastlog.so";
modulePath = "${pkgs.util-linux.lastlog}/lib/security/pam_lastlog2.so";
settings = {
silent = true;
};
Expand Down Expand Up @@ -2311,6 +2311,12 @@ in

environment.etc = lib.mapAttrs' makePAMService enabledServices;

systemd = lib.optionalAttrs config.security.pam.services.login.updateWtmp {
tmpfiles.packages = [ pkgs.util-linux.lastlog ]; # /lib/tmpfiles.d/lastlog2-tmpfiles.conf
services.lastlog2-import.enable = true;
packages = [ pkgs.util-linux.lastlog ]; # lib/systemd/system/lastlog2-import.service
};

Comment on lines +2314 to +2319
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had marked this PR to review more closely, but I see it was merged before I got the chance.

As noted on the previous attempt, this shouldn't privilege the login service here, but should instead check the updateWtmp option on all PAM services. You can use the enabledServices attrset for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair enough, i can do that in a follow-up. Any changes to the modules here at least won't be mass-rebuilds.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proposed #432567 as a fix, waiting for builds to finish before undrafting.

security.pam.services = {
other.text = ''
auth required pam_warn.so
Expand Down
1 change: 1 addition & 0 deletions nixos/tests/all-tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,7 @@ in
packagekit = runTest ./packagekit.nix;
paisa = runTest ./paisa.nix;
pam-file-contents = runTest ./pam/pam-file-contents.nix;
pam-lastlog = runTest ./pam/pam-lastlog.nix;
pam-oath-login = runTest ./pam/pam-oath-login.nix;
pam-u2f = runTest ./pam/pam-u2f.nix;
pam-ussh = runTest ./pam/pam-ussh.nix;
Expand Down
21 changes: 21 additions & 0 deletions nixos/tests/pam/pam-lastlog.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{ ... }:

{
name = "pam-lastlog";

nodes.machine =
{ ... }:
{
# we abuse run0 for a quick login as root as to not require setting up accounts and passwords
security.pam.services.systemd-run0 = {
updateWtmp = true; # enable lastlog
};
};

testScript = ''
machine.wait_for_unit("multi-user.target")
machine.succeed("run0 --pty true") # perform full login
print(machine.succeed("lastlog2 --active --user root"))
machine.succeed("stat /var/lib/lastlog/lastlog2.db")
'';
}
1 change: 1 addition & 0 deletions pkgs/by-name/li/linux-pam/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ stdenv.mkDerivation rec {
inherit (nixosTests)
pam-oath-login
pam-u2f
pam-lastlog
shadow
sssd-ldap
;
Expand Down
33 changes: 28 additions & 5 deletions pkgs/by-name/ut/util-linux/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
installShellFiles,
writeSupport ? stdenv.hostPlatform.isLinux,
shadowSupport ? stdenv.hostPlatform.isLinux,
# Doesn't build on Darwin, also doesn't really make sense on Darwin
withLastlog ? !stdenv.hostPlatform.isDarwin,
gitUpdater,
nixosTests,
}:

let
Expand Down Expand Up @@ -72,10 +75,15 @@ stdenv.mkDerivation (finalPackage: rec {
"out"
"lib"
"man"
"login"
]
++ lib.optionals stdenv.hostPlatform.isLinux [ "mount" ]
++ [ "login" ]
++ lib.optionals stdenv.hostPlatform.isLinux [ "swap" ];
++ lib.optionals stdenv.hostPlatform.isLinux [
"mount"
"swap"
]
++ lib.optionals withLastlog [
"lastlog"
];
separateDebugInfo = true;

postPatch = ''
Expand Down Expand Up @@ -129,8 +137,7 @@ stdenv.mkDerivation (finalPackage: rec {
"--disable-ipcrm"
"--disable-ipcs"
]
++ lib.optionals stdenv.hostPlatform.isDarwin [
# Doesn't build on Darwin, also doesn't really make sense on Darwin
++ lib.optionals (!withLastlog) [
"--disable-liblastlog2"
]
++ lib.optionals stdenv.hostPlatform.isStatic [
Expand Down Expand Up @@ -183,6 +190,18 @@ stdenv.mkDerivation (finalPackage: rec {
prefix=$login _moveSbin
ln -svf "$login/bin/"* $bin/bin/
''
+ lib.optionalString withLastlog ''
# moveToOutput "lib/liblastlog2*" "$lastlog"
${lib.optionalString (!stdenv.hostPlatform.isStatic) ''moveToOutput "lib/security" "$lastlog"''}
moveToOutput "lib/tmpfiles.d/lastlog2-tmpfiles.conf" "$lastlog"

moveToOutput "lib/systemd/system/lastlog2-import.service" "$lastlog"
substituteInPlace $lastlog/lib/systemd/system/lastlog2-import.service \
--replace-fail "$bin/bin/lastlog2" "$lastlog/bin/lastlog2"

moveToOutput "bin/lastlog2" "$lastlog"
ln -svf "$lastlog/bin/"* $bin/bin/
''
+ lib.optionalString stdenv.hostPlatform.isLinux ''

moveToOutput sbin/swapon "$swap"
Expand All @@ -209,6 +228,10 @@ stdenv.mkDerivation (finalPackage: rec {
# encode upstream assumption to be used in man-db
# https://github.com/util-linux/util-linux/commit/8886d84e25a457702b45194d69a47313f76dc6bc
hasCol = stdenv.hostPlatform.libc == "glibc";

tests = {
inherit (nixosTests) pam-lastlog;
};
};

meta = {
Expand Down
1 change: 1 addition & 0 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11387,6 +11387,7 @@ with pkgs;
shadowSupport = false;
systemdSupport = false;
translateManpages = false;
withLastlog = false;
};

v4l-utils = qt6.callPackage ../os-specific/linux/v4l-utils { };
Expand Down
Loading