Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

users: Fix truncated "From" in account logs #21418

Merged
merged 4 commits into from
Dec 10, 2024
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
2 changes: 1 addition & 1 deletion pkg/users/account-logs-panel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const _ = cockpit.gettext;
export function AccountLogs({ name }) {
const [logins, setLogins] = useState([]);
useInit(() => {
cockpit.spawn(["last", "--time-format", "iso", "-n", 25, name], { environ: ["LC_ALL=C"] })
cockpit.spawn(["last", "--time-format", "iso", "-n25", "--fullnames", name], { environ: ["LC_ALL=C"] })
Copy link
Member

Choose a reason for hiding this comment

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

Was confused for a bit, why isn't this -w, but that's the same thing :) I guess for historical raisins.

Copy link
Member Author

Choose a reason for hiding this comment

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

I prefer long options in code for better readability. But -w is the same thing indeed.

.then(data => {
let logins = [];
data.split('\n').forEach(line => {
Expand Down
3 changes: 2 additions & 1 deletion src/session/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,8 @@ on_authorize_timeout (int signo)
{
/* Can't use errx() here: https://man7.org/linux/man-pages/man7/signal-safety.7.html */
static const char msg[] = "timed out waiting for authorize response\n";
write (STDERR_FILENO, msg, sizeof (msg) - 1);
/* ignore write errors(-Wunused-result); if that fails, we can do absolutely nothing about it */
(void) !write (STDERR_FILENO, msg, sizeof (msg) - 1);
_exit(EX);
}

Expand Down
4 changes: 3 additions & 1 deletion test/verify/check-static-login
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@ account required pam_succeed_if.so user ingroup %s""" % m.get_admin_group
def assert_messages(has_last, n_fail):
if has_last:
b.wait_in_text('#system_last_login', "Last successful login")
b.wait_in_text('#system_last_login_from', "from") # only present if IP was logged
b.wait_in_text('#system_last_login_from',
# this is the correct IP for our CI, and we don't run this on tmt
"from ::ffff:172.27.0.2 on web console") # only present if IP was logged

if n_fail:
b.wait_in_text('#system_last_login', f'{n_fail} failed login')
Expand Down
18 changes: 15 additions & 3 deletions test/verify/check-users
Original file line number Diff line number Diff line change
Expand Up @@ -1079,14 +1079,26 @@ class TestAccounts(testlib.MachineCase):
m.execute("truncate -s0 /var/log/{[bw]tmp,lastlog} /run/utmp")
m.execute("rm -f /var/lib/lastlog/lastlog2.db /var/lib/wtmpdb/wtmp.db")

# Login once to create an entry
self.login_and_go("/users")
# First login: no entries yet
self.login_and_go("/users#/admin")
# just the header, nothing else
b.wait_text("#account-logs", "Login history")
self.assertFalse(b.is_present("#account-logs tr"))
b.logout()

year = m.execute("date +%Y").strip()

# second login: one entry from the first one
self.login_and_go("/users#/admin")
b.wait_visible("#account-logs")
# Header + one line of logins
b.wait_js_func("ph_count_check", "#account-logs tr", 2)
started = b.text("#account-logs [data-label='Started']")
ended = b.text("#account-logs [data-label='Ended']")
self.assertIn(year, started)
self.assertIn(year, ended)
Comment on lines +1097 to +1098
Copy link
Member Author

Choose a reason for hiding this comment

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

This of course assumes that this test doesn't run at precisely mightnight on new year. But if you send a PR around that time, shame on you 😁 I tried to parse the shown date with date, but it's a custom format which date -d doesn't understand, so I gave up.

Copy link
Member

Choose a reason for hiding this comment

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

With this comment it feels like "challenge accepted". But maybe more for dependabot :)

self.assertGreaterEqual(ended, started)
# this is the correct IP for our CI, and we don't run this on tmt
b.wait_text("#account-logs [data-label='From']", "::ffff:172.27.0.2")

def testGroups(self):
b = self.browser
Expand Down
Loading