From 1d5795567263ba3c57da2964e2d7e6cf2c63f6f0 Mon Sep 17 00:00:00 2001 From: Ilia Ross Date: Tue, 22 Oct 2024 19:19:47 +0300 Subject: [PATCH] Fix to call `last` command for the given user if no `lastlog` available --- useradmin/user-lib.pl | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/useradmin/user-lib.pl b/useradmin/user-lib.pl index 9cd2700a7..b506bc30e 100755 --- a/useradmin/user-lib.pl +++ b/useradmin/user-lib.pl @@ -2377,8 +2377,9 @@ print &ui_columns_start([ $lshow ? ( $text{'lastlogin'} ) : ( ) ], 100, 0, \@tds); local $llogin; +my $os_most_recent_logins = defined(&os_most_recent_logins); if ($lshow) { - $llogin = &get_recent_logins(); + $llogin = &get_recent_logins() if ($os_most_recent_logins); if (&foreign_check("mailboxes")) { &foreign_require("mailboxes"); } @@ -2398,6 +2399,8 @@ if (@$users) { push(@cols, &html_escape($u->{'shell'})); if ($lshow) { # Show last login, in local format after Unix time conversion + $llogin = &get_recent_logins($u->{'user'}, 1) + if (!$os_most_recent_logins); my $ll = $llogin->{$u->{'user'}}; if (defined(&mailboxes::parse_mail_date)) { my $tm = &mailboxes::parse_mail_date($ll); @@ -2566,19 +2569,20 @@ close(LAST); return @rv; } -=head2 get_recent_logins() +=head2 get_recent_logins([user], [max]) Returns a hash ref from username to most recent login time/date =cut sub get_recent_logins { +my ($user, $max) = @_; if (defined(&os_most_recent_logins)) { return &os_most_recent_logins(); } else { my %rv; - foreach my $l (&list_last_logins()) { + foreach my $l (&list_last_logins($user, $max)) { $rv{$l->[0]} ||= $l->[3]; } return \%rv;