Karel Zak [Tue, 19 Nov 2019 13:58:20 +0000 (14:58 +0100)]
mount: no exit on EPERM, continue without suid
The current libmount assumes that mount(8) and umount(8) are suid
binaries. For this reason it implements internal rules which
restrict what is allowed for non-root users. Unfortunately, it's
out of reality for some use-cases where root permissions are no
required. Nice example are fuse filesystems.
So, the current situation is to call exit() always when mount, umount or
libmount are unsure with non-root user rights. This patch removes the
exit() call and replaces it with suid permissions drop, after that it
continues as usually. It means after suid-drop all depend on kernel
and no another security rule is used by libmount (simply because any
rule is no more necessary).
Example:
old version:
$ mount -t fuse.sshfs kzak@192.168.111.1:/home/kzak /home/kzak/mnt
mount: only root can use "--types" option
new version:
$ mount -t fuse.sshfs kzak@192.168.111.1:/home/kzak /home/kzak/mnt
kzak@192.168.111.1's password:
Sami Kerola [Sun, 17 Nov 2019 08:33:04 +0000 (08:33 +0000)]
nologin: silently ignore well known shell command-line options
nologin is typically used in /etc/passwd as a shell replacement. Hence it
is reasonable to ignore well known command-line options silently to avoid
unwanted ugly error messages.
Addresses: https://github.com/karelzak/util-linux/issues/895 Requested-by: Lennart Poettering <lennart@poettering.net> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Evan Green [Tue, 12 Nov 2019 22:17:37 +0000 (14:17 -0800)]
libfdisk: Space before first partition may not be aligned
libfdisk chooses a grain of 1MB fairly arbitrarily, and this granule
may not be honored by other utilities. GPT disks formatted elsewhere
may have space before the first partition, AND a partition that exists
solely below 1MB. If this occurs, cfdisk ends up adding a free space
region where end < start, resulting in a 16 Exabyte free region.
That's too many exabytes.
This happens because the start gets rounded up to the granule size in
new_freespace() but the end is left alone. The logs show it best:
Karel Zak [Tue, 12 Nov 2019 10:15:38 +0000 (11:15 +0100)]
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>
Karel Zak [Thu, 7 Nov 2019 08:02:23 +0000 (09:02 +0100)]
build-sys: use parse-date() only for hwclock
The parse-date.y is used only for hwclock, let's keep it together.
Note that the file (originally from gnulib) has GPLv3 license, so it's
better to make it obvious that we use it really only for hwclock (also
GPL).
Michal Suchanek [Mon, 4 Nov 2019 20:23:15 +0000 (21:23 +0100)]
libblkid: open device in nonblock mode.
When autoclose is set (kernel default but many distributions reverse the
setting) opening a CD-rom device causes the tray to close.
The function of blkid is to report the current state of the device and
not to change it. Hence it should use O_NONBLOCK when opening the
device to avoid closing a CD-rom tray.
blkid is used liberally in scripts so it can potentially interfere with
the user operating the CD-rom hardware.
[kzak@redhat.com: add O_NONBLOCK also to:
- wipefs
- blkid_new_probe_from_filename()
- blkid_evaluate_tag()]
Signed-off-by: Michal Suchanek <msuchanek@suse.de> Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Thu, 31 Oct 2019 12:51:29 +0000 (13:51 +0100)]
libmount: make sure optsmode is initialized
Since 34333e5244167a8f6385faa350938ed5cb6d5c0a we apply fstab options
manually by mnt_context_apply_fs() on --all. The function does not
work correctly when optsmode is zero.
Karel Zak [Thu, 31 Oct 2019 09:34:12 +0000 (10:34 +0100)]
libmount: fix mnt_context_next_remount()
The current implementation works, but the remount operation is done in
the cloned context and the original context (and calling application)
has no information about the final status/errors. This is mistake.
This new implementation works like mnt_context_next_mount(), it means
the same context (as used by application) is reused for all remounts.
The original setting is restored by mnt_context_apply_template().
Karel Zak [Thu, 31 Oct 2019 09:31:53 +0000 (10:31 +0100)]
libmount: save current FS setting as template
This commit adds new functions to save and reuse the current FS
setting (mount options from command line, etc) after context reset.
It's usable for example in "mount --all" when we use the same context
for more times for more mount operations.
Karel Zak [Wed, 23 Oct 2019 10:02:33 +0000 (12:02 +0200)]
libmount: cleanup strdup() use in context, add reg.test
* don't ignore strdup() result
* cleanup mnt_context_prepare_helper() to have only one return point
(due to mnt_context_switch_ns())
* add mnt_context_prepare_helper() test program
Karel Zak [Tue, 29 Oct 2019 11:59:08 +0000 (12:59 +0100)]
libmount: don't use /proc/mounts fallback if filename specified
The current solution is to use /proc/mounts if previous attempt to
open /proc/self/mountinfo failed. The fallback should not be used when
mount table path is explicitly specified by application. The default
is NULL, only in this case libmount should be try to be smart.
Reported-by: Alasdair G Kergon <agk@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
Anatoly Pugachev [Wed, 23 Oct 2019 08:26:19 +0000 (11:26 +0300)]
tests: fixes blkid/md-raidX-whole on Sparc
Since SPARC is using 'sun' partition table by default, make test not to
assume that disk has 'dos' partition table, so write 'dos' partition
table on disk, before proceeding any further.
In commit b1418ed14 (lib/path: add ul_path_stat(), fix absolute paths,
2019-10-15), a new function `ul_path_stat()` was added to "path.h". This
new function prototype causes a compiler warning on musl libc based
systems due to one of the parameters having the unknown type `struct
stat` due to the <sys/stat.h> header not being included.
Karel Zak [Thu, 17 Oct 2019 08:36:27 +0000 (10:36 +0200)]
lib/fileutils: add close_all_fds()
The classic way which is based on file-descriptors table size is
pretty expensive (due to table size) and forces code to do many
unnecessary close() calls. It seems better to use /proc/self/fds and
close used descriptors only.
Addresses: https://github.com/karelzak/util-linux/issues/883 Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Tue, 15 Oct 2019 10:36:16 +0000 (12:36 +0200)]
lsblk: on --sysroot read attributes from /dev/<devname> text file
The option --sysroot is used to read information from dumps rather
than from the current system. This patch allows to read also udev
attributes from text file in location /sysroot/dev/<devname>. The file
is text file in format NAME=value\n.
Suggested-by: Alasdair G Kergon <agk@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Tue, 15 Oct 2019 09:59:16 +0000 (11:59 +0200)]
lib/path: add ul_path_stat(), fix absolute paths
* add ul_path_stat()
* make sure all paths for ul_path_..() functions are always
interpreted relatively to the context directory and prefix. This is
difference between ul_path_ API and standard libc "at" functions. We
do not use any exception for absolute paths. The reason is that we
need to read from prefixed paths although application assume absolute
path (/dev/sda1 means /prefix/dev/sda1 if a /prefix is defined).
Karel Zak [Thu, 10 Oct 2019 06:57:30 +0000 (08:57 +0200)]
lib/pty-session: fix compilation
lib/test_pty-monotonic.o: In function `get_boot_time':
/home/travis/build/karelzak/util-linux/lib/monotonic.c:29: undefined reference to `clock_gettime'
lib/test_pty-monotonic.o: In function `gettime_monotonic':
/home/travis/build/karelzak/util-linux/lib/monotonic.c:56: undefined reference to `clock_gettime'
Karel Zak [Wed, 9 Oct 2019 10:31:28 +0000 (12:31 +0200)]
build-sys: cleanup prefixed used for tests
It's ugly to use the same TS_ prefix in tests as well as in
build-system (e.g. make check), because then some env. variable can be
interpreted by our regression tests. For example TS_PARALLEL=.
It's seems better to use TS_ exclusively for tests and TESTS_ for
build-system.
Karel Zak [Mon, 7 Oct 2019 10:24:43 +0000 (12:24 +0200)]
lib/pty-session: make wait_child callback optional
Now the code is duplicate on many places, but all we usually need is to
remember child status. It seems good enough to have very simple
callback child_die() to inform application about a change.
The patch also add PID to all signal related callbacks.
Karel Zak [Thu, 3 Oct 2019 12:33:25 +0000 (14:33 +0200)]
script: use lib/pty-session
This patch consolidate pseudo-terminal stuff in util-linux. From now
there is only one implementation used in su(1) --pty, scriptlive(1)
and script(1).
The new stuff is based on the original script(1) -- it means poll()
and signalfd() based.
Note that script(1) code does not provide fallback for systems/libc
where is no openpty().
Karel Zak [Tue, 30 Jul 2019 12:32:13 +0000 (14:32 +0200)]
scriptlive: run shell in PTY
After this change shell executed by scriptlive(1) is going to behave
like shell in script(1). It means that the shell stdin is a
pseudo-terminal rather than pipe. This allows live replay of
interactive applications, ssh sessions, etc.
Karel Zak [Tue, 2 Jul 2019 15:03:53 +0000 (17:03 +0200)]
scriptlive: add new command to re-execute script(1) typescript
The old good scriptreplay(1) just display your recorded session, the
scriptlive(1) uses stdin typescript (from new script(1)) to execute
your commands again.