Commit Graph

14748 Commits

Author SHA1 Message Date
Karel Zak df8a8d1373 Merge branch 'libuuid' of https://github.com/ferivoz/util-linux
* 'libuuid' of https://github.com/ferivoz/util-linux:
  libuuid: check quality of random bytes
2020-11-09 12:31:17 +01:00
Karel Zak bb123ad503 Merge branch 'vipw-shortwrite' of https://github.com/DankRank/util-linux
* 'vipw-shortwrite' of https://github.com/DankRank/util-linux:
  ul_copy_file: make defines for return values
  read_all: return 0 when EOF occurs after 0 bytes
  ul_copy_file: add test program
  ul_copy_file: handle EAGAIN and EINTR
  ul_copy_file: use all_read/all_write
  ul_copy_file: use BUFSSIZ for buffer size
  nologin: use ul_copy_file
  login: use ul_copy_file
  configure.ac: check for sendfile
  ul_copy_file: use sendfile
  vipw: move copyfile to the lib
  vipw: fix short write handling in copyfile
2020-11-09 11:06:27 +01:00
Karel Zak e5781b3d3b flock: keep -E exit status more restrictive
Addresses: https://github.com/karelzak/util-linux/issues/1180
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-09 10:53:23 +01:00
Egor Chelak cabbf61fab ul_copy_file: make defines for return values
Suggested-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
2020-11-09 07:20:14 +02:00
Egor Chelak 418eb09482 read_all: return 0 when EOF occurs after 0 bytes
Originally it would return -1 (without setting errno) if the fd was
already at EOF when you called read_all.

This is already fixed in sendfile_all.

Reviewed-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
2020-11-09 07:19:51 +02:00
Egor Chelak 7951164c1f ul_copy_file: add test program
Suggested-by: Karel Zak <kzak@redhat.com>
Reviewed-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
2020-11-09 07:19:43 +02:00
Egor Chelak 212bde6cf7 ul_copy_file: handle EAGAIN and EINTR
I did this by implementing a function called sendfile_all() similar to
read_all()/write_all().

The manpage for sendfile doesn't mention EINTR, but I decided to check
it anyway, just in case.

Suggested-by: Karel Zak <kzak@redhat.com>
Reviewed-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
2020-11-09 07:19:39 +02:00
Egor Chelak f19a16550a ul_copy_file: use all_read/all_write
Suggested-by: Karel Zak <kzak@redhat.com>
Reviewed-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
2020-11-09 07:19:36 +02:00
Egor Chelak e453099640 ul_copy_file: use BUFSSIZ for buffer size
Suggested-by: Karel Zak <kzak@redhat.com>
Reviewed-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
2020-11-09 07:19:30 +02:00
Egor Chelak 9203b41a4f nologin: use ul_copy_file
Suggested-by: Sami Kerola <kerolasa@iki.fi>
Reviewed-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
2020-11-09 07:19:24 +02:00
Egor Chelak 8fcdbefb7b login: use ul_copy_file
Suggested-by: Karel Zak <kzak@redhat.com>
Reviewed-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
2020-11-09 07:19:15 +02:00
Egor Chelak 360cdaa6c7 configure.ac: check for sendfile
Do note that according to man sendfile, "Other UNIX systems implement
sendfile() with different semantics and prototypes."
If this is something we care about, a better check is needed.

Suggested-by: Karel Zak <kzak@redhat.com>
Reviewed-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
2020-11-09 07:19:00 +02:00
Egor Chelak a8b4e7cad1 ul_copy_file: use sendfile
Suggested-by: Karel Zak <kzak@redhat.com>
Reviewed-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
2020-11-09 07:18:49 +02:00
Egor Chelak b9dcd38462 vipw: move copyfile to the lib
Also, a bug in pw_tmpfile was fixed: copyfile used tmp_file to report
errors, but pw_tmpfile only assigned that variable _after_ calling
copyfile.

Suggested-by: Sami Kerola <kerolasa@iki.fi>
Reviewed-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
2020-11-09 07:18:42 +02:00
Samanta Navarro e4be3ee01d libuuid: check quality of random bytes
If a libuuid application is unable to access /dev/random or /dev/urandom
then uuid generation by uuid_generate falls back to uuid_generate_time.
This could happen in chroot or container environments.

The function ul_random_get_bytes from lib/randutils.c uses getrandom if
it is available. This could either mean that the libuuid application
skips good random bytes because the character special files do not exist
or the application trusts in good random bytes just because these files
are accessible but not necessarily usable, e.g. limit of open file
descriptors reached, lack of data, kernel without getrandom, etc.

This commit modifies ul_random_get_bytes to return an integer which
indicates if random bytes are of good quality (0) or not (1). Callers
can decide based on this information if they want to discard the random
bytes. Only libuuid checks the return value. I decided to return 1
instead of -1 because -1 feels more like an error, but weak random bytes
can be totally fine.

Another issue is that getrandom sets errno to specific values only in
case of an error, i.e. with return value -1. Set errno to 0 explicitly
if getrandom succeeds so we do not enter the fallback routine for
ENOSYS by mistake. I do not think that this is likely to happen, but it
really depends on possible wrapper function supplied by a C library.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2020-11-08 11:48:23 +00:00
Karel Zak ee7f4bee9b sfdisk: fix backward --move-data
* fix final message where number of moved sectors overflow number of
  all moved sectors

* align last step size before we use it for backward mode source and
  destination offsets calculation

Addresses: https://github.com/karelzak/util-linux/issues/1176
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-06 11:38:51 +01:00
Karel Zak de9cbcdcef Merge branch 'whereis' of https://github.com/ferivoz/util-linux
* 'whereis' of https://github.com/ferivoz/util-linux:
  whereis: extend test case
  whereis: filter bin, man and src differently
  whereis: do not strip suffixes
  whereis: do not ignore trailing numbers
  whereis: add --disable-whereis to configure
  whereis: add lib32 directories
  whereis: support zst compressed man pages
  whereis: fix out of boundary read
2020-11-06 09:44:52 +01:00
Karel Zak 028043c2d5 Merge branch 'sfdisk-json-dump' of https://github.com/xnox/util-linux 2020-11-05 11:37:51 +01:00
Dimitri John Ledkov d7101e5911
sfdisk: correct --json --dump false exclusive
`--json` implies `--dump`, thus `--json --dump` must be
allowed. `--list-free` is incompatible with `--dump`, and thus also
with `--json`. Currently `--json --dump` is prohibited, even though
`--list-free` is not specified at all.

Regression introduced in 03154d2cf2.

Signed-off-by: Dimitri John Ledkov <xnox@ubuntu.com>
2020-11-04 12:47:55 +00:00
Samanta Navarro 062e6a3945 whereis: extend test case
Previous commits are covered with these test cases.

Removed dependency on system layout.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2020-11-04 11:43:09 +00:00
Samanta Navarro 653f672ab6 whereis: filter bin, man and src differently
Consider "s." prefixes for source code files only (even though I do not
know which VCS does that), compression suffixes for manual pages and
strict matching for executables.

Calling "whereis python3" is kind of okay to return python3.8 next to
python3, but python3.8-config is not the same tool as python3.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2020-11-04 11:43:09 +00:00
Samanta Navarro 117ddbeedc whereis: do not strip suffixes
The whereis implementations of FreeBSD, macOS, NetBSD, and OpenBSD do
not strip suffixes. Although whereis is not a POSIX tool and has no
shared standard, even its manual page indicates that the supplied names
are command names.

Commands do not have a suffix on Linux systems.

Stripping suffixes actually leads to issues with tools like fsck.ext4,
since fsck.ext4 is not the same tool as fsck and definitely not the same
tool as fsck.minix.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2020-11-04 11:43:09 +00:00
Samanta Navarro d95ee9fd75 whereis: do not ignore trailing numbers
The commands diff and diff3 are so distinct that their manual pages
should not be mixed in whereis output.

Theoretically this works for commands and binaries with links to each
other, e.g. gpg and gpg2, but if gpg is version 1 and gpg2 is version 2
then manual pages do not match either.

Also the while loop does not decrement "i" while incrementing "dp". The
effect of this is that the output of whereis depends on manual pages
being compressed or not.

The easiest solution is to not ignore trailing numbers.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2020-11-04 11:43:09 +00:00
Samanta Navarro b7fc158a2e whereis: add --disable-whereis to configure
Allow a build of util-linux without whereis.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2020-11-04 11:43:09 +00:00
Samanta Navarro 74b7c01fa6 whereis: add lib32 directories
These directories are sometimes used by Linux distributions.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2020-11-04 11:43:09 +00:00
Samanta Navarro 6065250a4d whereis: support zst compressed man pages
Add zst as extension for manual pages. Current version of man-db
supports zst extension out of the box.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2020-11-04 11:43:09 +00:00
Samanta Navarro cd4142f7c3 whereis: fix out of boundary read
If whereis encounters a short file name then an out of boundary
read can occur.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2020-11-04 11:43:09 +00:00
Samanta Navarro bd0f347f86 misc: fix typos
Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2020-11-04 11:42:28 +00:00
Samanta Navarro cb77628876 misc: fix typos [codespell]
Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2020-11-04 11:42:25 +00:00
Karel Zak ebb5ca72f4 sfdisk: (docs) add more information about GPT attribute bits
Addresses: https://github.com/karelzak/util-linux/issues/1171
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-04 10:29:30 +01:00
Karel Zak 1ab5f9b705 docs: rename to getopt-example
Addresses: 27114b2974 (commitcomment-43591002)
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-03 15:23:03 +01:00
Karel Zak 1d6e1b62e5 Merge branch 'execl-null' of https://github.com/DankRank/util-linux
* 'execl-null' of https://github.com/DankRank/util-linux:
  cast NULL to char * when using execl
2020-11-03 12:40:35 +01:00
Sami Kerola 364de8f4f5 lib/randutils: rename random_get_bytes()
Rename random_get_bytes() to avoid colliding a Solaris library function that
has the same name.

Reported-by: Sad Clouds <cryintothebluesky@gmail.com>
Reference: https://lore.kernel.org/util-linux/20201101141608.ba365cf67d92ee3973226de9@gmail.com/
Reference: https://blogs.oracle.com/solaris/solaris-random-number-generation-v2
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-11-03 12:38:45 +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
Egor Chelak 12235ef107 vipw: fix short write handling in copyfile
Since `off` and `nr` approach each other, the for-loop ends prematurely
when at least half of the buffer was written.  I think under certain
conditions this could cause the copy to be incomplete.

Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
2020-10-29 19:06:13 +02:00
Karel Zak 9210db64a6 ul: fix use of unsigned number
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-10-21 12:45:02 +02:00
Karel Zak 732d75945e dmesg: add --since and --until
$ date
Wed 21 Oct 2020 12:05:07 PM CEST

$ dmesg --ctime --since '1 hour ago'
[Wed Oct 21 11:47:13 2020] AAA
[Wed Oct 21 11:55:48 2020] BBB

$ dmesg --ctime --since '1 hour ago' --until '10 minutes ago'
[Wed Oct 21 11:47:13 2020] AAA

Addresses: https://github.com/karelzak/util-linux/issues/1166
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-10-21 12:09:18 +02:00
Karel Zak 5064635395 ul: small coding changes
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-10-21 11:16:34 +02:00
Karel Zak 9c4762cb6b Merge branch 'ul-refactor' of https://github.com/kerolasa/util-linux
* 'ul-refactor' of https://github.com/kerolasa/util-linux:
  ul: flip comparisons to lesser to greater order
  ul: use size_t to measure memory allocation size
  ul: improve function and variable names
  ul: rename enumerated mode symbols
  ul: remove function like putwp preprocessor define
  ul: free most allocations ncurses did during setupterm()
  ul: replace global runtime variables with a control structure
  ul: add a term capabilities tracking structure
  ul: remove function prototypes
  ul: tidy up coding style
  ul: add basic tests
2020-10-21 11:08:11 +02:00
Karel Zak 07c8462fb7 cal: do not use putp(), directly use stdio functions
It seems our putp() based output is not portable as some ncurses
implementations strictly follow POSIX where putp() accepts only
terminfo capability strings and nothing else.

We already use standard stdio.h functions to output terminfo strings
(e.g.  for colors). It seems we can do the same for cal(1) to
highlight the current day.

Note that mix putp() and fputs() is bad idea due to different
buffering ways in some cases (see cal.c git log for more details).

This patch also reduces complexity of the code as we can directly
output to stdout without snprintf to string.

Addresses: https://github.com/karelzak/util-linux/pull/1167
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-10-21 10:19:26 +02:00
Sami Kerola 1a3f71b292
ul: flip comparisons to lesser to greater order
1 < 2 < x < 4 is the order is the natural of values.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-20 21:13:25 +01:00
Sami Kerola 0186ff364d
ul: use size_t to measure memory allocation size
The size_t is the type libc memory allocation functions use.  The size_t
also provides allocation range that is enough not to a simple tool like this
to perform paranoia size checks.  Just let the realloc(3) fail if there is
not enough memory available to handle the requested line size.  That is a
lot more straightforward.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-20 21:13:24 +01:00
Sami Kerola 9a59ee6525
ul: improve function and variable names
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-20 21:13:24 +01:00
Sami Kerola 580c63259b
ul: rename enumerated mode symbols
First two are are ISO/IEC 2022 graphic character sets G0 (normal) and G1
(alternative), that one has to Switch In (SI) and Switch Out (SO).  The rest
are about how ul(1) is interacting with various text emphasis.

Reference: https://tldp.org/HOWTO/Keyboard-and-Console-HOWTO-6.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-20 21:12:49 +01:00
Sami Kerola 52e3ce0097
ul: remove function like putwp preprocessor define
The #ifdef HAVE_WIDECHAR can be removed, because the command already is
using wide character functions elsewhere without fallbacks.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-20 20:29:27 +01:00
Sami Kerola 1962d5cfca
ul: free most allocations ncurses did during setupterm()
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-20 20:29:27 +01:00
Sami Kerola eaf68e3083
ul: replace global runtime variables with a control structure
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-20 20:29:27 +01:00
Sami Kerola 4942193926
ul: add a term capabilities tracking structure
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-20 20:29:27 +01:00
Sami Kerola a2811907e9
ul: remove function prototypes
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-20 20:29:27 +01:00
Sami Kerola 5b627d8496
ul: tidy up coding style
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-20 20:29:27 +01:00