Commit Graph

187 Commits

Author SHA1 Message Date
Ivan Mironov 5df455dbbc agetty: Allow --init-string on a virtual console
This option has valid use cases on virtual consoles. Example:
enabling screen blanking in the same way as `setterm --blank ...`
does.

Signed-off-by: Ivan Mironov <mironov.ivan@gmail.com>
2021-02-02 00:29:25 +05:00
Karel Zak 31862cde0a fix compiler warnings
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-21 10:26:25 +01:00
Yuri Chornoivan 311e33afef Fix minor typos 2020-07-09 20:14:32 +03:00
Karel Zak 88aefd4c46 agetty: ignore ^C
Danc86 wrote:
 With agetty 2.32.1 and earlier, ^C at the login prompt is ignored. I
 noticed when upgrading to agetty 2.34, typing ^C now causes agetty to
 stop responding for 10 seconds and then it dies (and gets restarted by
 system and a new login prompt is printed).

 It logs this message:

   agetty[46048]: ttyS0: invalid character 0x3 in login name

 Previously the !isprint(ascval) condition would have caused control
 characters like ^C (\x03) to be discarded, whereas now it falls
 through to trying to decode it as part of a UTF-8 sequence, and then
 fails.

Fixes: 5de9751997
Addresses: https://github.com/karelzak/util-linux/issues/1046
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-05-22 10:22:12 +02:00
Karel Zak e327a7acd6 agetty: extend --issue-file to support multiple paths
The current default behavior is to print the first issue file/dir and
all alternative locations are used as a backup solution only. If something
is found than the rest is ignored. The --issue-file allow to overwrite
this default behavior, but currently it supports only one file/dir.

This patch extend --issue-file to support ':' separated list of paths
and *all* the files (if exist and no empty) in the list are printed.

 agetty --issue-file=/etc/issue:/etc/issue.d:/run/issue:/run/issue.d:/usr/lib/issue:/usr/lib/issue.d

Addresses: https://github.com/karelzak/util-linux/issues/1041
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-05-19 10:55:20 +02:00
Karel Zak 0d855a8309 agetty: save the original speed on --keep-baud
agetty cycling through the baud rates specified on command line
(triggered by BREAK). Unfortunately, the original baud rate (probably
the best one) is tried only first time on --keep-baud.

Addresses: https://github.com/karelzak/util-linux/issues/1025
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-05-04 12:27:42 +02:00
Rosen Penev ad296391f9
[clang-tidy] fix wrong *cmp usage
Found with bugprone-suspicious-string-compare

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-20 13:21:00 -07:00
Rosen Penev 042f62dfc5
[clang-tidy] do not use else after return
Found with readability-else-after-return

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-20 13:20:59 -07:00
Sami Kerola 3160589d86
various: use threadsafe versions of time functions [lgtm scan]
Deprecating calls to not-thread safe asctime(), ctime(), and localtime()
calls is pretty close to pointless change.  Lets do it to reduce lgtm scan
warnings with justification it's nicer to use static analysis tools when
they have very few positives.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-02-15 15:23:44 +00:00
Karel Zak 9418ba6d05 agetty: keep freed issue file pointer zeroized
References: https://bugzilla.redhat.com/show_bug.cgi?id=1784536
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-12-20 15:05:33 +01:00
Patrick Steinhardt c0274f8add agetty: return proper value if compiled without ISSUEDIR support
If agetty is compiled without support for ISSUEDIR, then it implements
a stub for `issuedir_read` that simply does nothing. In fact it does
too little, as it doesn't have a proper return statement even though the
function returns an integer.

Fix the issue by always returning `1` from `issuedir_read`. This
is the same error code that the real implementation of that function
returns in case it cannot open the directory and is thus a sensible
default to pretend that the directory doesn't exist.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
2019-12-12 12:22:28 +01:00
Karel Zak 4e666fceda agetty: add --show-issue to review issue output
Let's make life easier for admins and allow to review issue file
output on the current terminal without all full agetty execution. Use
case is pretty simple:

 # $EDITOR /etc/issue
 # agetty --show-issue

Addresses: https://github.com/karelzak/util-linux/issues/828
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-11-12 11:24:40 +01:00
Karel Zak 456bcbca6b agetty: add support for /run/issue and /usr/lib/issue
Addresses: https://github.com/karelzak/util-linux/issues/828
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-11-12 10:26:35 +01:00
Rosen Penev 76b680b1a9
Remove isascii usage
There is a c_isascii function that can be used.

isascii is deprecated and not available with some libcs like uClibc-ng
where it can be compile time disabled.
2019-08-08 12:12:55 -07:00
Sami Kerola 2a952555d2 agetty: simplify code in dolog() preprocessor blocks
Aim is to make dolog() a lot more readable and understandable, with downside
of when (rarely?) USE_SYSLOG it not defined the function will use a bit more
space from stack.  I think that is price well worth paying.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-07-24 11:11:46 +02:00
Stanislav Brabec b0853a08db agetty: Remove superfluous fflush()
eval_issue_file() contains fflush(stdout). It comes from an old code that
used fputs() to write to the console.

In the new code, we write to a temporary memstream, and
fclose(ie->output) fully replaces possible fflush(ie->output) in this
implementation.

The new print_issue_file() does not need it as well, as it uses
unbuffered write_all().

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2019-06-21 14:38:32 +02:00
Stanislav Brabec dcf03ffb37 agetty: Switch to 8-bit processing in get_logname() for UTF-8 terminals
If the terminal is in the UTF-8 mode, get_logname() should use 8-bit
processing.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
Cc: Lubomir Rintel <lkundrak@v3.sk>
Tested-by: Lubomir Rintel <lkundrak@v3.sk>
2019-03-04 11:38:28 +01:00
Stanislav Brabec 5de9751997 agetty: Fix input of non-ASCII characters in get_logname()
As login supports non-ASCII characters in the logname, agetty should be
consistent.

8b58ffdd re-activated old and ASCII-only get_logname(), which restricted
the input to ASCII only. As the code does not read whole characters,
isascii(ascval) and isprint(ascval) returns nonsenses after entering a
non-ASCII character.

As keyboard maps don't contain unprintable non-control characters, it
seems to be relatively safe to remove both checks.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
Cc: Lubomir Rintel <lkundrak@v3.sk>
Tested-by: Lubomir Rintel <lkundrak@v3.sk>
2019-03-04 11:38:17 +01:00
Sami Kerola 110260830d docs: fix typos [codespell]
Reference: https://github.com/codespell-project/codespell
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-02-18 13:22:43 +01:00
Stanislav Brabec d16afd8d15 agetty: Return old behavior with empty logname
c094fcd37 introduced a behavior change: When Return is entered with empty
logname, nothing happens. As it confuses users, return back the old
behavior: re-prompt.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2018-11-21 10:48:05 +01:00
Christian Hesse f8ee3af9fa agetty: fix output of escaped characters
Signed-off-by: Christian Hesse <mail@eworm.de>
2018-11-12 11:32:28 +01:00
Samuel Thibault d7a412fe0a agetty: fix portability issues
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-11-12 11:31:17 +01:00
Stanislav Brabec c094fcd373 agetty: when logname is erased, re-enable reloads
When user starts to enter logname, 8b58ffdd blocks issue reloads.
Reloads remain blocked even if user deletes all typed characters.

Make things visually consistent: If no characters are entered,
re-enable reloads.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
Signed-off-by: Karel Zak <kzak@redhat.com>
Reviewed-by: Lubomir Rintel <lkundrak@v3.sk>
Tested-by: Lubomir Rintel <lkundrak@v3.sk>
2018-10-31 09:35:48 +01:00
Lubomir Rintel 8b58ffddf4 agetty: don't put the VC into canonical mode
The wait_for_term_input()'s select() needs to be tripped when the user
starts typing. Otherwise the reloads can abort an already in-progress login.

Coupled with \4 and \6 expansions that happen to be there on Fedora Server,
this means reload on every netlink event. With a couple of IPv6 routers
announcing their networks and temporary addresses in use can make it
sometimes virtually impossible to log in.

Seems like zero lflags do the job just fine on a Linux VT. Reset it to
canonical mode before running login.

Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-10-22 11:03:47 +02:00
Karel Zak cdd538e383 agetty: don't use __u32
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-10-11 14:22:08 +02:00
Karel Zak 056a370efb agetty: make output more robust
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-10-11 13:29:39 +02:00
Karel Zak 980a6e431c agetty: cleanup issue output change, remove bool
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-10-11 13:21:23 +02:00
Karel Zak ddbb3067b6 agetty: move all issue variables to struct
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-10-11 13:12:02 +02:00
Stanislav Brabec 6522d88d08 agetty: Reload only if it is really needed
If netlink event arrives and related escapes are part of issue, agetty
reloads and re-display the prompt. Reload is triggered not only by IP
address change, but also by IPv6 RAs. In some environments it causes
reload several times in a minute, and even complicates the login.

To prevent this, reload only if a real change appears.

This consists of:
split print_issue_file() to several functions:

eval_issue_file() prints issue to memory. It does not affect terminal in
any way.

print_issue_file() prints issue file from memory.

cmp_issue_file() compares the issue file and returns true, if reload is
needed.

The implementation requires additional change:

do_prompt() does not evaluate the issue file. It is responsibility of
calling function.

Test suite:

Use issue that contais \4 and/or \6 escape.

After installing new instance, restart agetty by typing a letter and then
Enter 6 times.

To check whether reload happens, type a letter. When reload happens,
letter disappears.

1. Unplug network cable. Wait a while and re-plug network cable.
You should see 2 reloads on single stack and 3 reloads on dual stack.

2. Run a loop
while : ; do
	sed -i '$areload_test' /etc/issue
	agetty --reload
	sleep 3
	sed -i '/reload_test/d' /etc/issue
	agetty --reload
	sleep 3
done
You should see regular reload every 3 seconds.

3. Run a loop
while : ; do
	agetty --reload
	sleep 3
done
Before: You see regular reload every 3 seconds.
After: No reloads.

4. Run a loop
while : ; do
	ifconfig lo 127.0.0.1 netmask 255.0.0.0
	sleep 3
	ifconfig lo 127.0.0.2 netmask 255.0.0.0
	sleep 3
done
Before: You see regular reload every 3 seconds.
After: No reloads.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2018-10-11 12:09:25 +02:00
Stanislav Brabec 36c55a8987 agetty: Watch only protocol requested by issue escapes
To decrease number of reloads, watch only protocol requested by \4 and \6
escapes in issue file.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2018-10-11 12:09:25 +02:00
Stanislav Brabec c5955394a8 agetty: rename variable changed to triggered
changed variable name is not correct. It does not say that network
interface changed its address. It just says that the netlink message
processing was triggered.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2018-10-11 12:09:25 +02:00
Karel Zak c0c4feec88 agetty: cleanup code to copy to log strings
man utmp:
  String fields are terminated by a null byte ('\0') if they are shorter
  than the size of the field.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-10-03 17:10:44 +02:00
Karel Zak 2c4d86abda agetty: keep c_iflags unmodified on --autologin
agetty sets c_iflags according to interaction with serial line in
get_logname(). For --autologin it does not read from the line, so we
have no clue how to set the flags.

The current behavior is to zeroize the flags.  Unfortunately, it seems
like bad idea, because the line may be already properly initialized by
kernel (or systemd, etc.).

The new behavior is not touch the flags on --autologin.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1252764
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-06-06 15:57:24 +02:00
Steven Smith d23597a88c agetty: Fix a use of uninitialised memory in an agetty error path.
get_logname() assumes that when it calls read() it initializes c and
errno, which isn't always true if we hit a whitelisted error or end of
file. This occasionally shows up as agetty going into an infinite
loop. Fix it by just delaying ten seconds and exiting when things go
wrong, similarly to the behavior after a non-whitelisted error.

[kzak@redhat.com: - interpret readres == 0 as c = 0
                  - ignore speed configurations for VCONSOLE]

Signed-off-by: Steven Smith <sos22@srcf.ucam.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-21 10:54:39 +01:00
Karel Zak 1fc82a1360 agetty: add support for /etc/issue.d
The /etc/issue file has been originally designed to inform users
about the system (version, name, etc.).

In last years is growing number of additional tools (containers,
maintenance tools and interfaces, ...) and many admins and downstream
maintainer want to add some tool specific hints to the issue file, but
it mess to share one file between more packages and/or scripts. The
solution is /etc/issue.d directory.

The directory is extension to the standard system /etc/issue. The
/etc/issue file has to exist, otherwise the directory will be ignored.
It means "rm /etc/issue" (or --onissue) is still the way how keep our
system silent independently on 3rd-party installed files in the
/etc/issue.d directory.

The content of the files in the directory are printed after content of
the /etc/issue. The files are printed in version-sort order and .issue
file extension is required (00-foo.issue 01-bar.issue ...).

The change is backwardly compatible.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-07 11:32:32 +01:00
Karel Zak e7f9744ef5 agetty: remove unused flag
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-06 14:47:29 +01:00
Karel Zak 949e839979 agetty: fix /etc/os-release parsing
For example /etc/os-release:

	VERSION="26 (Twenty Six)"
	VERSION_ID=26

agetty for \S{VERSION} returns

	_ID=26

because the parser does nor check for '=' after variable name.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1498462
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-10-05 11:07:41 +02:00
Karel Zak 7e6f029448 agetty: keep returns in main()
Don't use list_speeds() as non-return function, it seems better to
keep main() code consistent.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-08-07 09:48:51 +02:00
Sami Kerola 82214f45e9
agetty: fix invalid usage crash
$ agetty
agetty: not enough arguments: Success
Segmentation fault (core dumped)

Reference: 9325dbfd20
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-08-05 16:49:07 +01:00
Sami Kerola 63d94613a8
agetty: add compile time features to --version output
This command has a lot of compile time #ifdef code.  It is time to add
feature listing to --version output so understanding command behavior is
easier.

Proposed-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-08-05 16:46:55 +01:00
Sami Kerola 11841430c9
agetty: add --list-speeds option
Proposed-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-08-05 16:04:37 +01:00
Sami Kerola 43a1709e3b
agetty: remove dead DO_DEVFS_FIDDLING code segment
There is no ./configure option to enable this, and it is unlikely any
distribution hot patching to enable fiddling when building package.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-08-05 09:58:25 +01:00
Karel Zak fe63c8a649 agetty: fix --login-pause logic
Let's "eat" ENTER key when pressed after login pause prompt.

Addresses: https://github.com/karelzak/util-linux/issues/491
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-31 10:27:20 +02:00
Karel Zak a273d83db9 agetty: print /etc/issue on --skip-login
The current --skip-login implementation disables also issue file
printing. This is unexpected behavior as /etc/issue may contains
important information and we have --noissue for admins who don't want
it.

This patch forces /etc/issue printing if --noissue no specified.

Addresses: https://github.com/karelzak/util-linux/issues/480
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-10 10:42:49 +02:00
Ruediger Meier f45f3ec34a misc: consolidate macro style USAGE_HELP_OPTIONS
changed in include/c.h and applied via sed:

  sed -i 's/fprintf.*\(USAGE_MAN_TAIL.*\)/printf(\1/' $(git ls-files -- "*.c")
  sed -i 's/print_usage_help_options\(.*\);/printf(USAGE_HELP_OPTIONS\1);/' $(git ls-files -- "*.c")

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-29 16:54:33 +02:00
Ruediger Meier b305445495 misc: consolidate all --help option descriptions
Now we are always using the same text also for commands
which had still hardcoded descriptions or where we can't
use the standard print_usage_help_options macro.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-27 12:28:36 +02:00
Ruediger Meier 9325dbfd20 misc: cleanup and fix --unknownopt issues
Fixed checkusage.sh warnings:

  rtcwake: --unknownopt, non-empty stdout

  rtcwake: --unknownopt, stderr too long: 21
  blockdev: --unknownopt, stderr too long: 28
  lsipc: --unknownopt, stderr too long: 77
  pg: --unknownopt, stderr too long: 23
  renice: --unknownopt, stderr too long: 18
  sulogin: --unknownopt, stderr too long: 17
  write: --unknownopt, stderr too long: 12

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-26 14:38:24 +02:00
Karel Zak 2a14beb4e9 agetty: fix login name DEL/CTRL^U issue
agetty refresh prompt (/etc/issue file etc.) when requested by inotify
or netlink. For this purpose we monitor some file descriptors by
select().

The terminal input file descriptor is switched to non-canonical mode before
select(). The goal is to be informed about user activity before
new-line. The FD is immediately switched back to canonical mode when
activity is detected. The side effect is that all not-read-yet chars in
the input buffer are lost ... so we need to call read() before switch
to canonical mode to save the chars.

The original implementation has been based on TIOCSTI ioctl. It
returns already read chars back to the terminal input buffer to make
them useful for canonical mode. The problem was race (agetty writes to
input buffer in the same time as user) and result was reordered chars
in login name... so useless.

This issue has been later fixed by extra buffer (commit
790119b885) for already read data.  And
TIOCSTI ioctl has been removed. Unfortunately this solution is also
wrong, because the buffer is maintained only by agetty and
inaccessible for terminal when user edit (by DEL/CTRL^U) login name in
canonical mode.

The solution is simple -- just don't try to be smart and keep terminal
in canonical mode all time (so terminal controls DEL, CTRL^U, etc) and
flush input buffer (=discard unread data) and ask user for login name
again after prompt reload.

The agetty reload is very rarely situation and for user it's pretty
obvious that he has to type login name again (as all terminal has been
clear+redraw).

Addresses: https://github.com/karelzak/util-linux/issues/454
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1464148
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-23 14:26:47 +02:00
Sami Kerola b1557fe981 misc: fix ggc-7 fallthrough warnings
(Original patch and commit message edited by Rudi.)

gcc-7 adds -Wimplicit-fallthrough=3 to our default flag -Wextra.
This warning can be silenced by using comment /* fallthrough */
which is also recognized by other tools like coverity. There are
also other valid comments (see man gcc-7) but we consolidate this
style now.

We could have also used __attribute__((fallthrough)) but the comment
looks nice and does not need to be ifdef'ed for compatibility.

Reference: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=7652
Reference: https://developers.redhat.com/blog/2017/03/10/wimplicit-fallthrough-in-gcc-7/
Reviewed-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Suggested-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-06-14 11:48:22 +02:00
Sami Kerola 343cc27559
agetty: make --remote to forward --nohostname as -H to login
Without this change an attempt to remove hostname printing required following
rather clumsy agetty invocation.

  /sbin/agetty --nohostname --login-options '/bin/login -H -- \u'

After the change --nohostname behaves similar way with --host option, that
is when combined with --remote the effect is passed to login(1).

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-04-03 19:55:15 +01:00