]> git.ipfire.org Git - thirdparty/util-linux.git/log
thirdparty/util-linux.git
3 years agoMerge branch 'master' of https://github.com/panchenbo/util-linux
Karel Zak [Tue, 17 Aug 2021 11:55:02 +0000 (13:55 +0200)] 
Merge branch 'master' of https://github.com/panchenbo/util-linux

3 years agoagetty: (adoc) double hyphen replaced by dash in man pages
Karel Zak [Tue, 17 Aug 2021 11:50:52 +0000 (13:50 +0200)] 
agetty: (adoc) double hyphen replaced by dash in man pages

Fixes: https://github.com/karelzak/util-linux/issues/1411
Signed-off-by: Karel Zak <kzak@redhat.com>
3 years agozramctl: improve usage() output
Karel Zak [Tue, 17 Aug 2021 11:32:10 +0000 (13:32 +0200)] 
zramctl: improve usage() output

Signed-off-by: Karel Zak <kzak@redhat.com>
3 years agofix error ft_part 0x662
panchenbo [Tue, 17 Aug 2021 03:29:12 +0000 (11:29 +0800)] 
fix error ft_part 0x662

3 years agozramctl: add zstd compression algorithm option
Jan Samek [Mon, 16 Aug 2021 19:22:15 +0000 (21:22 +0200)] 
zramctl: add zstd compression algorithm option

Add information about the possible value 'zstd' for the 'zramctl --algorithm'
option to 'zramctl --help' and zramctl (8) manpage. The kernel supports zram
with zstd compression starting with 4.15 (see
https://lore.kernel.org/lkml/20170912050005.3247-1-sergey.senozhatsky@gmail.com/#r).

Signed-off-by: Jan Samek <samekh@email.cz>
3 years agomount: add -m,--mkdir as shortcut for X-mount.mkdir
Karel Zak [Thu, 12 Aug 2021 11:51:57 +0000 (13:51 +0200)] 
mount: add -m,--mkdir as shortcut for X-mount.mkdir

Suggested-by: Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Signed-off-by: Karel Zak <kzak@redhat.com>
3 years agolibmount: support quotes in X-mount options
Karel Zak [Thu, 12 Aug 2021 11:44:19 +0000 (13:44 +0200)] 
libmount: support quotes in X-mount options

Signed-off-by: Karel Zak <kzak@redhat.com>
3 years agolibmount: show options string on parse error
Karel Zak [Thu, 12 Aug 2021 11:41:56 +0000 (13:41 +0200)] 
libmount: show options string on parse error

Signed-off-by: Karel Zak <kzak@redhat.com>
3 years agolibmount: allow X-* options more than once
Karel Zak [Thu, 12 Aug 2021 11:39:39 +0000 (13:39 +0200)] 
libmount: allow X-* options more than once

Signed-off-by: Karel Zak <kzak@redhat.com>
3 years agolibmount: change propagation of /run for X-mount.subdir
Karel Zak [Thu, 12 Aug 2021 10:12:39 +0000 (12:12 +0200)] 
libmount: change propagation of /run for X-mount.subdir

We do not need to create a new mount node from /run/mount/tmptgt
(where we mount filesystem root), because /run is already mount
node in all mainstream distros, and we can use MS_PRIVATE for
this top-level directory. There is still fallback if /run is
on root filesystem.

This solution reduces number of mount operations, with the patch the
subdir implementation is:

 * open current namespace from /proc/self/ns/mnt
 * mkdir /run/mount/tmptg (if it does not exist)
 * make /run private by mount(MS_PRIVATE)
 * mount filesystem to /run/mount/tmptg
 * bind mount /run/mount/tmptg/<subdir> to <target>
 * umount /run/mount/tmptg
 * setns() to the original namespace

Signed-off-by: Karel Zak <kzak@redhat.com>
3 years agolibmount: use /run/mount/tmptgt rather than /tmp/mount/mount.<pid>
Karel Zak [Thu, 12 Aug 2021 08:58:18 +0000 (10:58 +0200)] 
libmount: use /run/mount/tmptgt rather than /tmp/mount/mount.<pid>

The unshared namespace is per-process, so we can use the same
directory in all mount(8) instances. It's unnecessary to create
and remove process specific directory.

Signed-off-by: Karel Zak <kzak@redhat.com>
3 years agolibmount: remove support for obsolete /dev/.mount/utab
Karel Zak [Thu, 12 Aug 2021 08:44:03 +0000 (10:44 +0200)] 
libmount: remove support for obsolete /dev/.mount/utab

The default is /run/mount/utab for years.

Signed-off-by: Karel Zak <kzak@redhat.com>
3 years agoMerge branch 'master' of https://github.com/panchenbo/util-linux
Karel Zak [Wed, 11 Aug 2021 14:22:39 +0000 (16:22 +0200)] 
Merge branch 'master' of https://github.com/panchenbo/util-linux

* 'master' of https://github.com/panchenbo/util-linux:
  lscpu:Add Phytium FT-2000+ & S2500 support

3 years agomount.8: don't consider additional mounts as experimental
Karel Zak [Wed, 11 Aug 2021 14:18:29 +0000 (16:18 +0200)] 
mount.8: don't consider additional mounts as experimental

This is bug, we have "EXPERIMENTAL" flag in the man page since v2.23.

Signed-off-by: Karel Zak <kzak@redhat.com>
3 years agolibmount: add X-mount.subdir=
Karel Zak [Wed, 11 Aug 2021 13:57:37 +0000 (15:57 +0200)] 
libmount: add X-mount.subdir=

Like btrfs subvol=, but more generic and for all filesystems. This
feature is marked as EXPERIMENTAL (may be removed).

 # mount /dev/sdc /mnt/test -o X-mount.subdir=AAA

 # findmnt /dev/sdc
 TARGET    SOURCE         FSTYPE OPTIONS
 /mnt/test /dev/sdc[/AAA] ext4   rw,relatime,stripe=512

Implemented as:

 * open current namespace from /proc/self/ns/mnt
 * mkdir /tmp/mount/mount.<pid>
 * unshare mount namespace
 * create mount node from /tmp/mount/mount.<pid> by mount(MS_BIND)
 * mark /tmp/mount/mount.<pid> private by mount(MS_PRIVATE|MS_REC)
 * bind mount /tmp/mount/mount.<pid>/subdir to <target>
 * umount /tmp/mount/mount.<pid>
 * rmdir /tmp/mount/mount.<pid>
 * setns() to the original namespace

Note that /tmp/mount/mount.<pid> conversion to mount node and call for
MS_PRIVATE are visible (propagated to the system) if /tmp is a shared
filesystem, the rest (all operations with the desired filesystem) is
atomic for a parental namespace.

Maybe one day it will be possible to reimplement it in more
elegant way with new mount kernel APIs (open_tree(), etc.).

Fixes: https://github.com/karelzak/util-linux/issues/1103
Signed-off-by: Karel Zak <kzak@redhat.com>
3 years agolscpu:Add Phytium FT-2000+ & S2500 support
panchenbo [Wed, 11 Aug 2021 11:33:31 +0000 (19:33 +0800)] 
lscpu:Add Phytium FT-2000+ & S2500 support

3 years agoMerge branch 'master' of https://github.com/panchenbo/util-linux
Karel Zak [Wed, 11 Aug 2021 08:04:35 +0000 (10:04 +0200)] 
Merge branch 'master' of https://github.com/panchenbo/util-linux

* 'master' of https://github.com/panchenbo/util-linux:
  lscpu:Add Phytium aarch64 cpupart

3 years agolscpu:Add Phytium aarch64 cpupart
panchenbo [Wed, 11 Aug 2021 05:00:08 +0000 (13:00 +0800)] 
lscpu:Add Phytium aarch64 cpupart

3 years agodocs: fix info about LIBSMARTCOLS_DEBUG_PADDING
Karel Zak [Tue, 10 Aug 2021 08:12:26 +0000 (10:12 +0200)] 
docs: fix info about LIBSMARTCOLS_DEBUG_PADDING

Signed-off-by: Karel Zak <kzak@redhat.com>
3 years agoMerge branch 'whereis-bash-complete' of https://github.com/Smittyvb/util-linux
Karel Zak [Mon, 9 Aug 2021 09:58:42 +0000 (11:58 +0200)] 
Merge branch 'whereis-bash-complete' of https://github.com/Smittyvb/util-linux

* 'whereis-bash-complete' of https://github.com/Smittyvb/util-linux:
  whereis: use commands for Bash completions

3 years agolib/buffer: fix buffer reset
Karel Zak [Mon, 9 Aug 2021 09:07:17 +0000 (11:07 +0200)] 
lib/buffer: fix buffer reset

Signed-off-by: Karel Zak <kzak@redhat.com>
3 years agolscpu: fix compilation against librtas
Karel Zak [Mon, 9 Aug 2021 07:52:46 +0000 (09:52 +0200)] 
lscpu: fix compilation against librtas

Fixes: https://github.com/karelzak/util-linux/issues/1406
Signed-off-by: Karel Zak <kzak@redhat.com>
3 years agoprlimit: fix compiler warning [-Wmaybe-uninitialized]
Karel Zak [Mon, 9 Aug 2021 07:45:21 +0000 (09:45 +0200)] 
prlimit: fix compiler warning [-Wmaybe-uninitialized]

sys-utils/prlimit.c:467:16: warning: 'hard' may be used uninitialized in this function [-Wmaybe-uninitialized]
  lim->rlim_max = hard;
  ~~~~~~~~~~~~~~^~~~~~
sys-utils/prlimit.c:456:15: note: 'hard' was declared here
  rlim_t soft, hard;
               ^~~~
sys-utils/prlimit.c:466:16: warning: 'soft' may be used uninitialized in this function [-Wmaybe-uninitialized]
  lim->rlim_cur = soft;
  ~~~~~~~~~~~~~~^~~~~~
sys-utils/prlimit.c:456:9: note: 'soft' was declared here
  rlim_t soft, hard;
         ^~~~

References: https://github.com/karelzak/util-linux/issues/1406
Signed-off-by: Karel Zak <kzak@redhat.com>
3 years agowhereis: use commands for Bash completions
Smitty [Sun, 8 Aug 2021 22:04:30 +0000 (18:04 -0400)] 
whereis: use commands for Bash completions

Currently, the Bash completions for `whereis <TAB>` gives
`whereis file` ("file" is not a placeholder here, it literally expands
to that). This fixes that by passing the `-c` flag to `compgen` to
request completions for command names.

Signed-off-by: Smitty van Bodegom <me@smitop.com>
3 years agolibsmartcols: use lib/buffer, remove local implementation
Karel Zak [Fri, 6 Aug 2021 10:04:05 +0000 (12:04 +0200)] 
libsmartcols: use lib/buffer, remove local implementation

Signed-off-by: Karel Zak <kzak@redhat.com>
3 years agolib/buffer: add support for "safe" encoding
Karel Zak [Fri, 6 Aug 2021 10:02:39 +0000 (12:02 +0200)] 
lib/buffer: add support for "safe" encoding

Signed-off-by: Karel Zak <kzak@redhat.com>
3 years agolib/buffer: add possibility to save position in the buffer
Karel Zak [Thu, 5 Aug 2021 14:45:07 +0000 (16:45 +0200)] 
lib/buffer: add possibility to save position in the buffer

This is necessary to use lib/buffer.c in libsmart cols.

Signed-off-by: Karel Zak <kzak@redhat.com>
3 years agolib/buffer: retun size of the buffer and data
Karel Zak [Thu, 5 Aug 2021 14:05:58 +0000 (16:05 +0200)] 
lib/buffer: retun size of the buffer and data

Signed-off-by: Karel Zak <kzak@redhat.com>
3 years agolib/strutils: add strappend()
Karel Zak [Thu, 5 Aug 2021 13:42:15 +0000 (15:42 +0200)] 
lib/strutils: add strappend()

Signed-off-by: Karel Zak <kzak@redhat.com>
3 years agolib/strutils: rename strappend() to strconcat()
Karel Zak [Thu, 5 Aug 2021 09:25:54 +0000 (11:25 +0200)] 
lib/strutils: rename strappend() to strconcat()

It concatenates two strings to a new string. It's something else than
"append".

Signed-off-by: Karel Zak <kzak@redhat.com>
3 years agolibuuid: include c.h to cover restrict keyword
Karel Zak [Thu, 5 Aug 2021 07:46:21 +0000 (09:46 +0200)] 
libuuid: include c.h to cover restrict keyword

References: https://github.com/karelzak/util-linux/issues/1405
Signed-off-by: Karel Zak <kzak@redhat.com>
3 years agolibblkid: (btrfs) add debug messages to zoned support
Karel Zak [Tue, 3 Aug 2021 11:29:16 +0000 (13:29 +0200)] 
libblkid: (btrfs) add debug messages to zoned support

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolibfdisk: (dos) index partition from zero for DBG()
Karel Zak [Mon, 2 Aug 2021 13:49:10 +0000 (15:49 +0200)] 
libfdisk: (dos) index partition from zero for DBG()

References: https://github.com/karelzak/util-linux/pull/1394
Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolibfdisk: add new Linux GPT partition types
WANG Xuerui [Mon, 2 Aug 2021 09:55:19 +0000 (17:55 +0800)] 
libfdisk: add new Linux GPT partition types

Add new partition type UUIDs introduced in the following systemd PRs:

- https://github.com/systemd/systemd/pull/17700
- https://github.com/systemd/systemd/pull/20087

[kzak@redhat.com: - add missing commas]

Signed-off-by: WANG Xuerui <git@xen0n.name>
Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolibmount: assert() is enough [lgtm scan]
Karel Zak [Mon, 2 Aug 2021 08:58:56 +0000 (10:58 +0200)] 
libmount: assert() is enough [lgtm scan]

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agoMerge branch 'chs' of https://github.com/pali/util-linux
Karel Zak [Mon, 2 Aug 2021 08:40:10 +0000 (10:40 +0200)] 
Merge branch 'chs' of https://github.com/pali/util-linux

* 'chs' of https://github.com/pali/util-linux:
  fdisk: Add support for fixing MBR partitions CHS values
  libfdisk: (dos) Add function fdisk_dos_fix_chs() for fixing CHS values for all partitions
  libfdisk: (dos) Add function dos_partition_sync_chs() for updating CHS values

4 years agoForward value of sector_size instead of its address in blkdev_get_physector_size
Nicolas Melot [Sun, 1 Aug 2021 17:20:58 +0000 (19:20 +0200)] 
Forward value of sector_size instead of its address in blkdev_get_physector_size

4 years agotests: add rv64 lscpu test
Karel Zak [Fri, 30 Jul 2021 13:32:24 +0000 (15:32 +0200)] 
tests: add rv64 lscpu test

References: https://github.com/karelzak/util-linux/issues/1401
Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolscpu: fix NULL dereference
Karel Zak [Fri, 30 Jul 2021 12:35:25 +0000 (14:35 +0200)] 
lscpu: fix NULL dereference

Fixes: https://github.com/karelzak/util-linux/issues/1401
Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agoRevert "sulogin: fix getpasswd()"
Karel Zak [Fri, 30 Jul 2021 12:16:03 +0000 (14:16 +0200)] 
Revert "sulogin: fix getpasswd()"

This patch is unnecessary in the master branch.

This reverts commit 2d8a9fcee2e3d63deb6bcba650894ff14d8e2d3b.

References: https://github.com/karelzak/util-linux/issues/1400

4 years agofdisk: Add support for fixing MBR partitions CHS values
Pali Rohár [Fri, 30 Jul 2021 09:19:20 +0000 (11:19 +0200)] 
fdisk: Add support for fixing MBR partitions CHS values

Add a new extended option 'F' to fdisk which recalculates and fixes CHS
values for each partition in MBR table according to current fdisk settings
for number of heads and sectors per track.

This allows in interactive mode to repair existing partitions to be
compatible with CHS addressing after changing extended option 'h' (number
of heads) or 's' (sectors per track) as these options do not modify content
of existing partitions.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
4 years agolibfdisk: (dos) Add function fdisk_dos_fix_chs() for fixing CHS values for all partitions
Pali Rohár [Fri, 30 Jul 2021 09:15:15 +0000 (11:15 +0200)] 
libfdisk: (dos) Add function fdisk_dos_fix_chs() for fixing CHS values for all partitions

This function fixes beginning and ending CHS values for every partition
according to LBA relative offset, relative beginning and size and fdisk
idea of disk geometry (sectors per track and number of heads). This
function may be used for repairing existing partitions to be compatible
with CHS addressing.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
4 years agoagetty: use CTRL+C to erase username
Karel Zak [Fri, 30 Jul 2021 09:50:46 +0000 (11:50 +0200)] 
agetty: use CTRL+C to erase username

aggety(8) from the beginning ignores ^C (the small exception was
between 2.32 and 2.34 when this char has been misinterpreted).

This patch forces agetty to interpret ^C like ^U, it means to
erase the user's input and wait for a completely new username.
The small difference is that for ^C it does not set 'kill character'.

This change does not affect serial lines where ^C is still ignored like
in previous decades. I'd like to avoid any regression as I have
no clue if any serial lines do not send this control char in some
context ...

Fixes: https://github.com/karelzak/util-linux/issues/1399
References: https://github.com/karelzak/util-linux/issues/1046
Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolibfdisk: (dos) Add function dos_partition_sync_chs() for updating CHS values
Pali Rohár [Fri, 30 Jul 2021 09:01:36 +0000 (11:01 +0200)] 
libfdisk: (dos) Add function dos_partition_sync_chs() for updating CHS values

Call this function everytime after changing either relative LBA partition
offset or LBA partition size to ensure that CHS values are in sync with
LBA.

This should fix partition CHS values after moving or deleting partition.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
4 years agoMerge branch 'xget' of https://github.com/ericonr/util-linux
Karel Zak [Thu, 29 Jul 2021 19:34:20 +0000 (21:34 +0200)] 
Merge branch 'xget' of https://github.com/ericonr/util-linux

* 'xget' of https://github.com/ericonr/util-linux:
  lib/pwdutils: use assert to check correct usage.
  logger: use xgetlogin from pwdutils.
  wall: use xgetlogin.
  lib/pwdutils: don't use getlogin(3).

4 years agosulogin: fix getpasswd()
Karel Zak [Thu, 29 Jul 2021 19:28:00 +0000 (21:28 +0200)] 
sulogin: fix getpasswd()

Fixes: https://github.com/karelzak/util-linux/issues/1400
Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolibmount: don't use setgroups at all()
Karel Zak [Thu, 29 Jul 2021 18:37:32 +0000 (20:37 +0200)] 
libmount: don't use setgroups at all()

It's probably good idea to call setgroups() to cleanup groups,
but it introduces a regression as some mount helpers depend on
supplementary groups like "network" etc.

Fixes: https://github.com/karelzak/util-linux/issues/1398
Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolib/pwdutils: use assert to check correct usage.
Érico Nogueira [Wed, 28 Jul 2021 02:58:26 +0000 (23:58 -0300)] 
lib/pwdutils: use assert to check correct usage.

Since these functions are only used internally, we can make sure they
are being used correctly, and assert() helps in catching remaining
issues. Usage of each changed function has been reviewed:

For xgetpwnam:

- chsh(1) only calls it if a username has been set
- login(1) only calls it if username has been set and is not empty
- su(1) always initializes new_user to "root"
- unshare(1) calls get_user with optarg, so always set as well

For xgetgrnam:

- unshare(1) calls get_group with optarg

For xgetpwuid:

- chsh(1) passes a stack allocated struct for struct passwd

Signed-off-by: Érico Nogueira <erico.erc@gmail.com>
4 years agologger: use xgetlogin from pwdutils.
Érico Nogueira [Wed, 28 Jul 2021 02:54:42 +0000 (23:54 -0300)] 
logger: use xgetlogin from pwdutils.

It defined its own xgetlogin, which queried geteuid() instead of getuid(),
with a fallback to "<someone>" when lookup fails. This has been the case
since the function was introduced in
019b97024fde3f07eaf541eef990762483369a11, so geteuid() has always been
used. Since using geteuid for identification isn't consistent with the
rest of util-linux, switching to xgetlogin(), which uses getuid(),
should be correct.

Signed-off-by: Érico Nogueira <erico.erc@gmail.com>
4 years agowall: use xgetlogin.
Érico Nogueira [Wed, 28 Jul 2021 02:51:34 +0000 (23:51 -0300)] 
wall: use xgetlogin.

getlogin(3) shouldn't be used for identification here. This also removes
the bug where a missing entry for getuid() in passwd database wouldn't
print a warning, because whom would be set to "???".

For consistency, switch to "<someone>" when pw look up fails.

Signed-off-by: Érico Nogueira <erico.erc@gmail.com>
4 years agolib/pwdutils: don't use getlogin(3).
Érico Nogueira [Wed, 28 Jul 2021 02:41:30 +0000 (23:41 -0300)] 
lib/pwdutils: don't use getlogin(3).

Per the man page, it shouldn't be used for security purposes. This is an
issue especially on musl, where getlogin is implemented as
getenv("LOGNAME"). Since xgetlogin is being used as user identity in su(1), to
set PAM_RUSER, we simply switch to always using getpwuid(getuid()).

Signed-off-by: Érico Nogueira <erico.erc@gmail.com>
4 years agolibmount: fix setgroups() use
Karel Zak [Thu, 29 Jul 2021 09:50:48 +0000 (11:50 +0200)] 
libmount: fix setgroups() use

* keep process in single supplementary group, which is the real group ID for the process

* make sure we have rights to call setgroups(), requires group permissions

Fixes: https://github.com/karelzak/util-linux/issues/1398
Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agoMerge branch 'procmnt-fix' of https://github.com/benaryorg/util-linux
Karel Zak [Wed, 28 Jul 2021 09:17:59 +0000 (11:17 +0200)] 
Merge branch 'procmnt-fix' of https://github.com/benaryorg/util-linux

* 'procmnt-fix' of https://github.com/benaryorg/util-linux:
  fix #648 by ignoring EINVAL on-remount of proc

4 years agolosetup: use LOOP_CONFIGURE in a more robust way
Karel Zak [Wed, 28 Jul 2021 09:05:36 +0000 (11:05 +0200)] 
losetup: use LOOP_CONFIGURE in a more robust way

32-bit userspace returns ENOTTY:
 ioctl(4, LOOP_CONFIGURE, {fd=3, block_size=0, info={lo_offset=0, lo_number=0, lo_flags=LO_FLAGS_AUTOCLEAR, lo_file_name="/usr/install/iso/systemrescue-8.04-amd64.iso", ...}}) = -1 ENOTTY (Inappropriate ioctl for device)

64-bit userspace returns EINVAL:
 ioctl(4, LOOP_CONFIGURE, {fd=3, block_size=0, info={lo_offset=0, lo_number=0, lo_flags=LO_FLAGS_AUTOCLEAR, lo_file_name="/usr/src/PACKAGES/systemrescue-8.04-amd64.iso", ...}}) = -1 EINVAL (Invalid argument)

The correct return value for an unknown ioctl is ENOTTY, but we need
to support already released kernels, so let's support both errnos.

Reported-by: Krzysztof Olędzki <ole@ans.pl>
Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agotests: fix fdisk/bsd on big endian systems (tested on sparc64 and ppc64)
Anatoly Pugachev [Tue, 27 Jul 2021 16:33:03 +0000 (19:33 +0300)] 
tests: fix fdisk/bsd on big endian systems (tested on sparc64 and ppc64)

Fixes: 5d0f0ca56
Closes #1392

Signed-off-by: Anatoly Pugachev <matorola@gmail.com>
4 years agoMerge branch 'rename-all' of https://github.com/utoddl/util-linux
Karel Zak [Tue, 27 Jul 2021 12:14:51 +0000 (14:14 +0200)] 
Merge branch 'rename-all' of https://github.com/utoddl/util-linux

* 'rename-all' of https://github.com/utoddl/util-linux:
  rename: size_t, mutually exclusive parameters
  rename: stop after count changes
  rename: add --all and --last parameters

4 years agoMerge branch 'patch-1' of https://github.com/cfinnberg/util-linux
Karel Zak [Tue, 27 Jul 2021 11:34:16 +0000 (13:34 +0200)] 
Merge branch 'patch-1' of https://github.com/cfinnberg/util-linux

4 years agoreadprofile: use snprintf() rather than sprintf()
Karel Zak [Tue, 27 Jul 2021 11:31:57 +0000 (13:31 +0200)] 
readprofile: use snprintf() rather than sprintf()

4 years agoipcs: use snprintf() rather than sprintf()
Karel Zak [Tue, 27 Jul 2021 11:31:47 +0000 (13:31 +0200)] 
ipcs: use snprintf() rather than sprintf()

4 years agowrite: use snprintf() rather than sprintf()
Karel Zak [Tue, 27 Jul 2021 11:31:30 +0000 (13:31 +0200)] 
write: use snprintf() rather than sprintf()

4 years agomore: use snprintf() rather than sprintf()
Karel Zak [Tue, 27 Jul 2021 11:31:18 +0000 (13:31 +0200)] 
more: use snprintf() rather than sprintf()

4 years agolslocks: use snprintf() rather than sprintf()
Karel Zak [Tue, 27 Jul 2021 11:30:56 +0000 (13:30 +0200)] 
lslocks: use snprintf() rather than sprintf()

4 years agouuidd: use snprintf() rather than sprintf()
Karel Zak [Tue, 27 Jul 2021 11:30:42 +0000 (13:30 +0200)] 
uuidd: use snprintf() rather than sprintf()

4 years agovipw: use snprintf() rather than sprintf()
Karel Zak [Tue, 27 Jul 2021 11:30:14 +0000 (13:30 +0200)] 
vipw: use snprintf() rather than sprintf()

4 years agologindefs: use snprintf() rather than sprintf()
Karel Zak [Tue, 27 Jul 2021 11:30:01 +0000 (13:30 +0200)] 
logindefs: use snprintf() rather than sprintf()

4 years agolast: use snprintf() rather than sprintf()
Karel Zak [Tue, 27 Jul 2021 11:29:36 +0000 (13:29 +0200)] 
last: use snprintf() rather than sprintf()

4 years agolib: use snprintf() rather than sprintf()
Karel Zak [Tue, 27 Jul 2021 11:29:19 +0000 (13:29 +0200)] 
lib: use snprintf() rather than sprintf()

4 years agolibblkid: use snprintf() rather than sprintf()
Karel Zak [Tue, 27 Jul 2021 11:29:05 +0000 (13:29 +0200)] 
libblkid: use snprintf() rather than sprintf()

4 years agolibsmartcols: use snprintf() rather than sprintf()
Karel Zak [Tue, 27 Jul 2021 11:28:52 +0000 (13:28 +0200)] 
libsmartcols: use snprintf() rather than sprintf()

4 years agoblockdev: use snprintf() rather than sprintf()
Karel Zak [Tue, 27 Jul 2021 10:51:43 +0000 (12:51 +0200)] 
blockdev: use snprintf() rather than sprintf()

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agoMerge branch 'master' of https://github.com/tabraham/util-linux
Karel Zak [Tue, 27 Jul 2021 10:49:59 +0000 (12:49 +0200)] 
Merge branch 'master' of https://github.com/tabraham/util-linux

4 years agosys-utils/ipcutils: be careful when call calloc() for uint64 nmembs
Karel Zak [Tue, 27 Jul 2021 09:58:31 +0000 (11:58 +0200)] 
sys-utils/ipcutils: be careful when call calloc() for uint64 nmembs

Fix: https://github.com/karelzak/util-linux/issues/1395
Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolibfdisk: (dos) support partition and MBR overlap
Karel Zak [Tue, 27 Jul 2021 09:40:32 +0000 (11:40 +0200)] 
libfdisk: (dos) support partition and MBR overlap

Let's support this crazy use-case in expert menu, because it's normal
for removable FAT disks, etc.

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolibfdisk: (dos) don't ignore MBR+FAT use-case
Karel Zak [Tue, 27 Jul 2021 09:10:53 +0000 (11:10 +0200)] 
libfdisk: (dos) don't ignore MBR+FAT use-case

Since libblkid commit 751eca28fcfa1e325770904d7181b22e48c72b29 it does
not ignore FAT on whole-disks, so now libfdisk sees collision between
FAT and MBR. It's fine to report the collision to users, but we should
not ignore the MBR.

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agoblockdev: allow for larger values for start sector
Thomas Abraham [Thu, 22 Jul 2021 19:43:13 +0000 (15:43 -0400)] 
blockdev: allow for larger values for start sector

commit 9147d2ad8a ("blockdev: Don't fail on missing start sector") limits
the size of the start sector to 10 digits.

Multi-terrabyte devices can have partitions with a start sector larger than
10 digits, which will cause an sprintf() to abort due to overflowing the buffer.

It causes:
  # blockdev --report /dev/sda4
  RO    RA   SSZ   BSZ   StartSec            Size   Device
  *** buffer overflow detected ***: terminated
  Aborted (core dumped)

4 years agoFix typo
Christian Finnberg [Thu, 22 Jul 2021 16:03:54 +0000 (19:03 +0300)] 
Fix typo

4 years agolslogins: fix memory leak [asan]
Karel Zak [Thu, 22 Jul 2021 09:34:11 +0000 (11:34 +0200)] 
lslogins: fix memory leak [asan]

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolslogins: ask for supplementary groups only once [asan]
Karel Zak [Thu, 22 Jul 2021 09:30:22 +0000 (11:30 +0200)] 
lslogins: ask for supplementary groups only once [asan]

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolslogins: use sd_journal_get_data() in proper way
Karel Zak [Thu, 22 Jul 2021 09:03:54 +0000 (11:03 +0200)] 
lslogins: use sd_journal_get_data() in proper way

man sd_journal_get_data:
    The returned data is in a read-only memory map and is only valid until the next invocation
    of sd_journal_get_data().

It means that use data after 3x sd_journal_get_data() is really bad
idea. It also seems better to not assume the fields are zero
terminated as journal API works with void* and size_t to address the
data.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1984704
Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agoMerge branch 'chs' of https://github.com/pali/util-linux
Karel Zak [Mon, 19 Jul 2021 11:34:24 +0000 (13:34 +0200)] 
Merge branch 'chs' of https://github.com/pali/util-linux

* 'chs' of https://github.com/pali/util-linux:
  tests: fdisk: Update CHS values in MBR partitions
  libfdisk: (dos) Fix determining number of heads and sectors per track from MBR
  libfdisk: (dos) Fix upper bound cylinder check in check_consistency()
  libfdisk: (dos) Fix upper bound cylinder check in check()
  libfdisk: (dos) Fix setting CHS values when creating new partition
  libfdisk: (dos) Use helper macros cylinder() and sector() in check_consistency()
  libfdisk: (dos) Put number of CHS check_consistency errors into summart message
  libfdisk: (dos) Add check both begin and end CHS partition parameters
  libfdisk: (dos) Fix check error message when CHS calculated sector does not match LBA
  libfdisk: (dos) Fix printing number of CHS sectors in check error message
  libfdisk: (dos) Recalculate number of cylinders after changing number of heads and sectors

4 years agotests: fdisk: Update CHS values in MBR partitions
Pali Rohár [Fri, 16 Jul 2021 20:26:38 +0000 (22:26 +0200)] 
tests: fdisk: Update CHS values in MBR partitions

It looks like that old CHS values prior this change in test data are
incorrect. Possible explanation why CHS values are incorrect is in commit
message 9cade4fbf8c4 ("libfdisk: (dos) Fix determining number of heads and
sectors per track from MBR").

This change updates test data to pass test suite after applying mentioned
commit.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
4 years agoMerge branch 'verity_exp' of https://github.com/bluca/util-linux
Karel Zak [Fri, 16 Jul 2021 12:17:19 +0000 (14:17 +0200)] 
Merge branch 'verity_exp' of https://github.com/bluca/util-linux

* 'verity_exp' of https://github.com/bluca/util-linux:
  verity: remove experimental tag from mount manpage

4 years agoverity: remove experimental tag from mount manpage
Luca Boccassi [Fri, 16 Jul 2021 10:52:44 +0000 (11:52 +0100)] 
verity: remove experimental tag from mount manpage

It has been around for a year and a half, and 3 releases.

4 years agolibfdisk: (dos) Fix determining number of heads and sectors per track from MBR
Pali Rohár [Tue, 6 Jul 2021 17:43:56 +0000 (19:43 +0200)] 
libfdisk: (dos) Fix determining number of heads and sectors per track from MBR

Current algorithm implemented in get_partition_table_geometry() function
is wrong. It take head bits from CHS position from the end of the last
partition and proclaim that this value is number of heads on disk. Same
does for sectors bits from CHS and proclaim that this value is number of
sectors per tracks. As number of disk heads and head bits in CHS position
are different things this just results in bogus detected disk geometry.

Implement a new algorithm to determinate number of heads and sectors per
track from partition sector offsets. In MBR table for every partition is
stored every sector offset in two formats: one as CHS and one as LBA.

Conversion from CHS to LBA is defined by formula:

   LBA = (c * N_heads + h) * N_sectors + (s - 1)

So if we have two different offsets in both CHS and LBA formats, written as
(LBA1, c1, h1, s1) and (LBA2, c2, h2, s2) then we can calculate number of
heads and sectors per tracks by solving linear equations as:

   N_heads = (o1 * h2 - o2 * h1) / (o2 * c1 - o1 * c2)
   N_sectors = (o2 * c1 - o1 * c2) / (c1 * h2 - c2 * h1)

where

   o = LBA - (s - 1)

Integer division also verifies that offsets were calculated from same
number of heads and sectors per track as division must be always positive
with no reminder.

There is a special case when either numerator or denominator is zero. This
indicates that comparing partition offsets have also same CHS offset
divisor which leads to fact that calculation of number of heads and sector
per tracks is not possible.

In MBR table are stored up to 8 offset numbers, so it means there are up
to the 28 of candidates which can expose number of disk heads and number of
disk sectors per track. Start with offsets which belongs to same partition
and start from the first partition. As the first partition in most cases
was used by BIOS for booting.

It is required to skip CHS values 1023/254/63 and 1023/255/63 as these
indicates that values are invalid or overflowed.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
4 years agolibfdisk: (dos) Fix upper bound cylinder check in check_consistency()
Pali Rohár [Tue, 6 Jul 2021 16:29:10 +0000 (18:29 +0200)] 
libfdisk: (dos) Fix upper bound cylinder check in check_consistency()

To determinate if CHS values are valid for consistency check and not
overflowed, it is needed to check current CHS cylinder value and not total
disk cylinder values. It is possible that also on "big" disk there is first
small partition which can be represented by CHS tuple.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
4 years agolibfdisk: (dos) Fix upper bound cylinder check in check()
Pali Rohár [Tue, 6 Jul 2021 16:26:52 +0000 (18:26 +0200)] 
libfdisk: (dos) Fix upper bound cylinder check in check()

To check if LBA sector can be represented in CHS without overflow it is
required to check for cylinder value which belongs to the LBA sector. And
not the total number of disk cylinders. Note that maximal representable
total number of disk cylinders is 1024 and therefore the last cylinder
which which can be stored in CHS tuple is 1023. Hence strict inequality is
used.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
4 years agolibfdisk: (dos) Fix setting CHS values when creating new partition
Pali Rohár [Tue, 6 Jul 2021 15:12:13 +0000 (17:12 +0200)] 
libfdisk: (dos) Fix setting CHS values when creating new partition

It does not matter if dos compatibility flag is turned on or off. CHS
values in partition entry can overflow also when dos compatibility flag is
turned off. In this case maximal representable CHS values should be used.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
4 years agolibfdisk: (dos) Use helper macros cylinder() and sector() in check_consistency()
Pali Rohár [Tue, 6 Jul 2021 13:03:21 +0000 (15:03 +0200)] 
libfdisk: (dos) Use helper macros cylinder() and sector() in check_consistency()

Helper macros are already used there and make code more readable.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
4 years agolibfdisk: (dos) Put number of CHS check_consistency errors into summart message
Pali Rohár [Tue, 6 Jul 2021 12:57:13 +0000 (14:57 +0200)] 
libfdisk: (dos) Put number of CHS check_consistency errors into summart message

Function check_consistency() prints errors to console output but does not
calculate correct error numbers in summary error message. Fix it, so fdisk
prints correct number in summary message "N errors detected.".

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
4 years agolibfdisk: (dos) Add check both begin and end CHS partition parameters
Pali Rohár [Tue, 6 Jul 2021 12:54:40 +0000 (14:54 +0200)] 
libfdisk: (dos) Add check both begin and end CHS partition parameters

There is no reason to check only end CHS partition parameters. Check also
begin values and correctly count errors in nerrors variable. fdisk then
print correctly summary message "N errors detected.".

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
4 years agolibfdisk: (dos) Fix check error message when CHS calculated sector does not match LBA
Pali Rohár [Tue, 6 Jul 2021 12:08:42 +0000 (14:08 +0200)] 
libfdisk: (dos) Fix check error message when CHS calculated sector does not match LBA

Function check() checks that LBA addresses sector number matches CHS sector
number. But error message contains information about "previous sectors" and
"total sectors" which is misleading so change it.

Also rename variables 'start' and 'total' to make it clear what value is
stored in them. Note that in 'start' variable is currently stored last LBA
partition sector and in 'total' is stored last CHS partition sector. So
neither sector where partition starts nor total sectors of partition.

Code and check logic looks to be correct, just error message and variable
names are misleading. Therefore no functional changes in this patch.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
4 years agolibfdisk: (dos) Fix printing number of CHS sectors in check error message
Pali Rohár [Tue, 6 Jul 2021 11:51:22 +0000 (13:51 +0200)] 
libfdisk: (dos) Fix printing number of CHS sectors in check error message

Number of CHS sectors (indexed from zero) is stored in variable 'real_s'.
In variable 's' is stored in high 2 bits number of CHS cylinders.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
4 years agolibfdisk: (dos) Recalculate number of cylinders after changing number of heads and...
Pali Rohár [Mon, 5 Jul 2021 20:13:11 +0000 (22:13 +0200)] 
libfdisk: (dos) Recalculate number of cylinders after changing number of heads and sectors

After geometry is changes it is required to recalculate total number of
cylinders. Otherwise total disk capacity is either reduced or extended.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
4 years agorename: size_t, mutually exclusive parameters
Todd Lewis [Thu, 15 Jul 2021 13:58:45 +0000 (09:58 -0400)] 
rename: size_t, mutually exclusive parameters

Use size_t for strlen-like stuff.

Use optutils.h to detect, error out when mutually exclusive
flags are given.

4 years agologin: add callback for close_range()
Karel Zak [Thu, 15 Jul 2021 10:51:39 +0000 (12:51 +0200)] 
login: add callback for close_range()

Let's make it more robust for old kernels where is no close_range() or
in cases when it's unsuccessful.

Reported-by: Florian Weimer <fweimer@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolslogins: consolidate and optimize utmp files use
Karel Zak [Thu, 15 Jul 2021 10:24:07 +0000 (12:24 +0200)] 
lslogins: consolidate and optimize utmp files use

* the original read_utmp() code is from GPLv3+, but lslogins is GPLv2+
  (see https://github.com/karelzak/util-linux/commit/a6bf40ee77a85f5108208dc764b5d023a07998f5#commitcomment-53407151)

* remove redundant parse_btmp() and parse_wtmp() as it does not
  provide anything

* reduce realloc() calls, allocate all in one step

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agoMerge branch 'fdisk-tests-more-details' of https://github.com/pali/util-linux
Karel Zak [Thu, 15 Jul 2021 08:20:09 +0000 (10:20 +0200)] 
Merge branch 'fdisk-tests-more-details' of https://github.com/pali/util-linux

* 'fdisk-tests-more-details' of https://github.com/pali/util-linux:
  tests: fdisk: Layout with more details

4 years agorename: stop after count changes
Todd Lewis [Thu, 15 Jul 2021 05:34:00 +0000 (01:34 -0400)] 
rename: stop after count changes

4 years agorename: add --all and --last parameters
Todd Lewis [Thu, 15 Jul 2021 04:15:55 +0000 (00:15 -0400)] 
rename: add --all and --last parameters

Renaming files with rename often involves multiple passes in order
to, say, replace all spaces with underscores because traditionally
rename only replaces the first occurrence of the expression. The
--all parameter makes this task simple.

With the addition of --last, rename becomes much safer to use when
replacing file extensions, whereas before it would mangle a file
which had its extension also embedded elsewhere in its name.

The implied --first, together with --all and --last, round out the
common cases for renaming files.

4 years agohardlink: remove pcre2posix.h support
Karel Zak [Wed, 14 Jul 2021 15:51:07 +0000 (17:51 +0200)] 
hardlink: remove pcre2posix.h support

It's deprecated for years. Let's rely on old good libc regex.h for now.

Signed-off-by: Karel Zak <kzak@redhat.com>