Today I'll describe the rest of Util Linux's login commands!

After initializing internationalization & parsing commandline flags `last` outputs latest logins by iterating over each of the given files defaulting to /var/log/btmp or wtmp. For each (handling fuzzing slightly specially) it retrieves the boot-time from the kernel, it opens the file with a configured buffersize, carefully reads the binary data `fstat`ing on failure, seeks to end, & repeatedlies...


Repeatedlies reads & validates an entry, possibly & extensively reformats (including a DNS lookup) into human readable output, applies some normalization, tweaks locals and/or output additional info in a similar format, & clears state upon seeing shutdown loglines. After which it attempts to output a timestamp from the file, & it cleans up. Including freeing the filepath that was opened.

Upon processing user-process records it may open /proc/?/loginuid to determine if its a "phantom".


After init'ing internationalization alongside some collections & parsing commandline flags `sulogin` validates its running as superuser, ignores various signals, possibly ensures necessary device-filesystems are mounted (upon exit it'll unmount any it mounted), retrieves the commandline arg or $CONSOLE envvar, retrieves possible console devices via /proc, /sys, /proc/cmdline, or an IOCTL with a fallback validating results are returned, reconnects the pipeline files, retrieves root account,


For each console `sulogin` attempts to open one which isn't overloaded & initializing it to support Plymouth (a.k.a. splashscreens), various IOCTLs, locales, & baudrate.

If successful soft-ignoring SIGCHLD signals `sulogin` iterates over those opened console connections. After validation it forks a child which'll repeatedly ask for a password if needed & run a subshell.

Loops waits for subprocesses to end, closes opened consoles, & wait for subprocesses again. Restores signal handlers.


After initializing internationalization, configuring signal handlers & scheduling, & parsing commandline flags + singular arg `login` configures a process group & the terminal, opens the system logger, configures PAM possibly requesting authentication from it, loads the password entry, loads groups, opens a pam session, clears a watchdog timeout, closes the passwords database, logs some info, switches terminal info, configures environment variables, generates a new process title, ...


... logs some more, optionally outputs login messages, forks a subprocess with watchdog parent, drops privileges, cds to home, and runs the appropriate shell.

This command generates the btmp logs consulted by `last`. Can consult a "hushlogin" file via a mini-sharedlib.

And finally... After initializing internationalizing & parsing/validating commandline flags with the aid of libsmartcols checking if at most one arg remains `lslogins` parses wtmp or btmp files to reformat for libsmartcols.


P.S. `lslogins` includes optional systemd logd integration. Maybe there's someone who appreciates this, but I suspect it mostly reinforces systemd's poor reputation.

I'll take a brief break tomorrow to publish these threads, then tackle the next bundle of "miscallaneous" commands.

Sign in to participate in the conversation

For people who care about, support, or build Free, Libre, and Open Source Software (FLOSS).