login-banner — chain-load utility for printing login banners
login-banner
[--utmp-filename filename
] {template-filename
} {next-prog
}
login-banner is a chain-loading utility that prints a system banner to its standard output, and then (if successful) chain loads to next-prog
with the execvp(3) function.
Normally, the next-prog
will be (or will eventually chain-load) login(1), which prints the login prompt(s) after the banner.
next-prog
may contain its own command line options, which login-banner will ignore.
login-banner makes no alteration to process state.
The location of the utmp
file is derived at compile time from a system header when the utility is built from source.
To override it at runtime, use the --utmp-filename
option.
login-banner derives information about the number of users logged on from the utmp
file.
It determins the name of the controlling TTY from the value of the TTY
environment variable, if present.
This will be the case if login-banner has been invoked within a chain that has run vc-get-tty(1), pty-get-tty(1), or an equivalent getty(1) program.
If absent, the ttyname(3) library function is called.
With those, and various other, pieces of system information to hand it then displays the contents of template-filename
to its standard output.
The file is displayed as-is, with the exception that a backslash character begins a two-character escape sequence.
The following escape sequences are defined:
\\
A single backslash.
\s
The "system" name, from the uname(2) function.
On FreeBSD/TrueOS, the C library allows this to be overridden by a UNAME_s
environment variable.
\S
The "pretty system" name, from the /etc/os-release
file, if available.
This defaults to the same as \s
.
\n
The "node" name, from the uname(2) function.
\r
The "release" name, from the uname(2) function.
On FreeBSD/TrueOS, the C library allows this to be overridden by a UNAME_r
environment variable.
\v
The "version" name, from the uname(2) function.
On FreeBSD/TrueOS, the C library allows this to be overridden by a UNAME_v
environment variable.
\m
The "machine" name, from the uname(2) function.
On FreeBSD/TrueOS, the C library allows this to be overridden by a UNAME_m
environment variable.
\o
The "domain" name, from the uname(2) or the getdomainname(2) function.
login-banner implements a common (DNS client library) convention of allowing this to be overridden by a LOCALDOMAIN
environment variable.
\l
The "line", i.e. the basename of the controlling TTY name, derived as aforementioned.
\u
The number of users logged on.
\U
The number of users logged on, followed by a space and the string "users" (or "user" if the number is exactly one).
\d
The current date.
\t
The current time.
login-banner doesn't really care if its standard output is not a virtual console, or even a terminal or a character device at all.
It can be used to display login banners to arbitrary destinations, even to sockets and to files.
(Although one must ensure that it always inherits a TTY
environment variable in such cases, so that the \l
escape sequence expands to the appropriate thing, and not to the name of some irrelevant controlling terminal.)
The following nosh(1) script is (roughly) equivalent to what in.telnetd(1) does, except that it doesn't handle the TELNET protocol negotiation or the various debugging options.
#!/bin/nosh pty-get-tty pty-run setsid open-controlling-tty login-banner /etc/issue.net login
This is the sh(1) equivalent:
#!/bin/sh -e exec \ pty-get-tty \ pty-run \ open-controlling-tty \ login-banner /etc/issue.net \ login