Commit Graph

86 Commits

Author SHA1 Message Date
Karel Zak d3f77b4b8b sulogin: add missing ifdefs
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-06-16 15:44:02 +02:00
Karel Zak 286865bf7e sulogin: use explicit_bzero() for buffer with password
Reported-by: Jan Pazdziora <jpazdziora@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-06-16 15:39:32 +02:00
Karel Zak 419861d5bf sulogin: fix whitespace error
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-05-24 13:39:53 +02:00
Werner Fink 0d092db5c4 sulogin: ignore none-existing console devices
and also none-functional console devices. Redirect the error
messages to the appropiate console device.

Signed-off-by: Werner Fink <werner@suse.de>
2021-05-24 13:39:53 +02:00
Karel Zak ca27216aa6 build-sys: remove fallback for security_context_t
It seems like overkill to provide this #ifdef. For example coreutils
use "char *" for all selinux contexts (since 2014).

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-13 13:12:19 +01:00
Ville Skyttä 3c56068609 *: spelling and grammar fixes 2020-12-17 23:39:05 +02:00
Karel Zak e522815027 login-utils: don't use deprecated security_context_t
libselinux >= 3.1 makes security_context_t type deprecated. Let's
ifdef it to avoid unwanted warnings.

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-12-14 15:54:08 +01:00
Egor Chelak 1b10fa0ef7 cast NULL to char * when using execl
When calling variadic functions, NULL must be explicitly cast to a
desired type.
This is noted in the exec(3) manpage.

The call in newgrp.c was changed for consistency.

Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
2020-10-29 19:49:07 +02:00
Sami Kerola ff09a5129a
sulogin: fix variable / function shadowing [cppcheck]
[login-utils/sulogin.c:398] -> [login-utils/sulogin.c:171]: (style) Local
variable set shadows outer function
[login-utils/sulogin.c:398] -> [login-utils/sulogin.c:830]: (style) Local
variable set shadows outer function

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-05-18 22:41:58 +01:00
Karel Zak 2c308875a7 misc: consolidate version printing and close_stdout()
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-04-16 15:14:13 +02:00
Karel Zak a8224e8e7e sulogin: restore signals after failed exec() only
* removes unnecessary variable

* the current code restores signals always when shell has not been
  executed -- this is correct as function sushell() modify signal
  mask, but in all another cases we do not need touch the mask.
  Especially when we ask for the  password in endless while() loop...

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-08-16 16:16:40 +02:00
Karel Zak f9915d6db3 sulogin: do not use plain 0 as NULL
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-08-16 15:58:20 +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 b1a294c448 misc: introduce print_usage_help_options()
Consolidate --help and --version descriptions. We are
now able to align them to the other options.

We changed include/c.h. The rest of this patch was
generated by sed, plus manually setting the right
alignment numbers. We do not change anything but
white spaces in the --help output.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-27 12:26:19 +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
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
Karel Zak 626aa65180 sulogin: add missing type
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-09 11:59:53 +02:00
Sami Kerola 71f207a5f5
sulogin: reduce vulnerability surface
Hopefully these changes are unreachable code, but better safe than sorry
when dealing with setuid root code that is installed everywhere.  Quite
obviously the introduced abort() calls protect from impossible inputs.

Secondly set all possible data to be read-only in attempt to make it more
difficult to alter anything at all.

Reference: https://www.securecoding.cert.org/confluence/display/c/DCL00-C.+Const-qualify+immutable+objects
Reviewed-by: Petr Vorel <petr.vorel@gmail.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-05-02 23:22:04 +01:00
Sami Kerola 2ba641e5f3 misc: add static keyword to where needed [smatch scan]
text-utils/rev.c:68:9: warning: symbol 'buf' was not declared. Should it be
static?

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-20 12:58:49 +01:00
Sami Kerola 8791804065 misc: do not use plain 0 as NULL [smatch scan]
text-utils/tailf.c:69:21: warning: Using plain integer as NULL pointer

Since many 'struct option' has used zero as NULL make them more readable in
same go by reindenting, and using named argument requirements.

Reference: https://lwn.net/Articles/93577/
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-20 12:58:49 +01:00
Karel Zak 5d74cf0092 lib/list: remove LIST_HEAD macro
* the variable definition with hidden type is always horrible, for
  example:

	  int func() {
	    LIST_HEAD(foo);
	    ...
	  }

  the more readable is:

          int func() {
            struct list_head foo;

            INIT_LIST_HEAD(&foo);
            ...
          }

* the name LIST_HEAD conflict with /usr/include/sys/queue.h

* we use it only on two places in sulogin

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-01-05 11:54:59 +01:00
Andreas Henriksson 1c4b2d4392 sulogin: bail out from getpasswd(...) on timeout
If timeout happens while waiting in prompt, bail out instead
of retrying.

Reported-by: Bjørn Mork <bjorn@mork.no>
Addresses: http://bugs.debian.org/846107
Signed-off-by: Andreas Henriksson <andreas@fatal.se>
2016-12-07 13:32:42 +01:00
Andreas Henriksson 60dea9d187 sulogin: make getpasswd(...) return NULL on ^D
This makes the caller bail out early instead of evaluating the
input as a password.

Reported-by: Bjørn Mork <bjorn@mork.no>
Addresses: http://bugs.debian.org/846112
Signed-off-by: Andreas Henriksson <andreas@fatal.se>
2016-12-07 13:32:42 +01:00
Ruediger Meier 223939d95b misc: spelling, always use "cannot" instead of "can not"
Just to be consistent ...

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-11-30 14:56:50 +01:00
Sami Kerola 984a60965a
misc: always check setenv(3) return value
At least glibc setenv(3) can fail when system runs out of memory.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-08-12 21:25:36 +01:00
Sami Kerola 74ce680a3e
misc: simplify if clauses [oclint]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-21 21:14:33 +01:00
Sebastian Rasmussen 9e93004171 misc: Fix various typos
Fix various typos in error messages, warnings, debug strings,
comments and names of static functions.

Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
2016-05-31 23:40:21 +02:00
Karel Zak 1eb16fd780 build-sys: add --disable-plymouth-support
The plymouth support depends on Linux specific SOCK_* flags and all
the feature is probably unnecessary in some cases (non-plymouth
distros, etc.)

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-26 15:08:53 +02:00
Werner Fink fe3f7e17aa sulogin: agetty: use the plymouth local protocol instead the plymouth binary
for stopping plymouthd.  That do not depend on the existence of
the plymouth binary if it e.g. becomes uninstalled or an other
service is providing plymouthd facilities.

[kzak@redhat.com: - fix compiler warnings [-Wpointer-sign]
                  - use sizeof() for write_all()
                  - cast to char* for read_all]

Signed-off-by: Werner Fink <werner@suse.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-20 11:21:10 +02:00
Werner Fink 6988998b66 sulogin: Always make echo work after performing getpasswd even if root account is locked
If the root account is locked and no password was provided then the terminal
line is not set back to do echo of the input. This correct a small overlook
in commit 7ff1162e67

Signed-off-by: Werner Fink <werner@suse.de>
2016-03-22 10:50:39 +01:00
Ruediger Meier 36f1200851 sulogin: ignore missing WEXITED, add warning
This happens on Debian kFreeBSD and probably on Hurd too since
cde7699c. One should review this issue to fix it properly.

CC: Werner Fink <werner@suse.de>
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-21 21:03:41 +01:00
Karel Zak 3d0cf042b0 sulogin: fix sigset_t initialization
Reported-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-03-14 13:21:27 +01:00
Karel Zak d0fe12aeb4 sulogin: keep initialization more robust
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-02-12 11:21:50 +01:00
Werner Fink cde7699c27 sulogin: avoid shared memory area usemask but use waitid() for childs
This small patch improves the console detection code and also avoids not
existing device nodes due strdup() which is used in canonicalize_path().
Beside this now the code for emergeny mount does work if enabled at
configure time.

Signed-off-by: Werner Fink <werner@suse.de>
2016-02-12 11:19:21 +01:00
Karel Zak 7ff1162e67 sulogin: improve support for locked root account
Some installations and distributions don't use a root account password
for security reasons and use sudo instead. In that case, asking for the
password makes no sense, and it is not even considered as valid as it's just
"*" or "!".

In these cases --force is required to just start a root shell and no
ask for password.

I don't think it's a good idea to automatically start root shell when
locked account is detected. It's possible that the machine is on
public place and for example Ubuntu uses root account disabled by
default (and also Fedora when installed by yum/dnf without anaconda).

The --force option forces admins to think about it...

The distro maintainers can also use --force in their initscripts or
systemd emergency.service if they believe that promiscuous setting is
the right thing for the distro.

Addresses: https://bugs.debian.org/326678
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-25 14:17:05 +02:00
Karel Zak d681e0956c sulogin: don't use strcpy(), enlarge pwd line buffer
* according to "man getpwnam" 16384 bytes is enough to store one
  passwd entry (let's use 2*BUFSIZE to avoid magic numbers in code)

* don't use strcpy() to set empty password

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-05-25 15:24:13 +02:00
Sami Kerola 559a5b6cf2 sulogin, hwclock: use xusleep() instead of usleep()
As said in include/c.h the usleep() is marked as obsolete, so do the same
that most of the other util-linux calls do with this interface.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-02-10 13:21:24 +01:00
Benno Schulenberg 451dbcfae1 textual: add a docstring to most of the utilities
This adds a concise description of a tool to its usage text.

A first form of this patch was proposed by Steven Honeyman
(see http://www.spinics.net/lists/util-linux-ng/msg09994.html).

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2015-01-06 11:27:38 +01:00
Benno Schulenberg 1d23119072 textual: remove some inconsistent periods from error messages
While doing so, also improve translatability and some wordings.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2014-08-11 14:51:54 +02:00
Karel Zak fa936c9f9b sulogin: don't use uninitialized struct sigaction [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-07-17 14:47:20 +02:00
Karel Zak c210324c67 sulogin: check result of the open() [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-07-17 14:42:00 +02:00
Samuel Thibault 88e0f3df66 build-sys: fixes for non-Linux systems
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-06-19 10:35:23 +02:00
Werner Fink b9c7390948 agetty: beside virtual consoles support xvc and hvc device lines as well
For this approach do not use the ioctl TIOCMGET anymore as this
is for real serial lines only. But switch over to use the ioctl
KDGKBMODE as this is unique to the virtual console lines only.

Signed-off-by: Werner Fink <werner@suse.de>
2014-05-13 10:40:11 +02:00
Werner Fink f2bcda5183 agetty: better support of the special system consoles on S390
That is that there are several consoles, the /dev/ttyS0 which
is type of ibm3215 and a dumb terminal, then there is the device
/dev/3270/tty1 which can handle ANSI color escape sequences and is
a ibm327x terminal, and the /dev/ttyS1 which is a vt220 terminal.

The macro is_speed() in agetty.c allows to distinguish between the
terminal line (/dev)3270/tty1 and the speed options on the command
line used in

/run/systemd/generator/getty.target.wants/serial-getty@3270-tty1.service

which is a symbolic link to /usr/lib/systemd/system/serial-getty@.service

Signed-off-by: Werner Fink <werner@suse.de>
2014-05-13 10:39:40 +02:00
Werner Fink bb280f79f1 agetty: avoid that agetty nor sulogin are fooled by a running plymouth
The nowadays used plymouth locks the devices used for the system
console which causes that agetty as well as sulogin can not modify
the termios settings of e.g. the serial devices of the systenm console.

Signed-off-by: Werner Fink <werner@suse.de>
2014-05-13 10:36:49 +02:00
Karel Zak a5bd793996 include/c.h: prefer nanosleep() over usleep()
Let's use nanosleep() although if usleep() exists. The nanosleep
function does no interact with signals and other timers.

The patch introduces xusleep() as replacement to libc (or our fallback)
usleep(). Yes, we don't want to use struct timespec + nanosleep()
everywhere in code as nano-time resolution is useless for us.

The patch also enlarges delays in some busy wait loops. It seems
enough to try read/write 4x per second.

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-01-24 13:04:14 +01:00
Benno Schulenberg 47481cbd01 textual: standardize some "cannot read" and "seek failed" error messages
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2013-10-09 11:37:38 +02:00
Benno Schulenberg 97b820bffd textual: improve clarity of some error messages
Reported-by: Petr Písař <petr.pisar@atlas.cz>
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2013-06-07 12:29:44 +02:00
Karel Zak 4b3624ca21 sulogin: clean up error messages
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-05-14 23:29:09 +02:00
Karel Zak ad85c7bad9 sulogin: don't run if not found passww entry [coverity scan]
sulogin(8) should not run if there is no /etc/{passwd,shadow} entry
and --force command line option is no specified otherwise NULL pointer
dereference is possible.

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-03-27 14:50:52 +01:00