Commit Graph

15134 Commits

Author SHA1 Message Date
Sami Kerola f0649c0d83
login: use close_range() system call when possible
This system call was added while back, but does not have glibc support yet.
Lets try to use the new facility early on.  The promise in reference link is
that the new call is faster, and works when /proc is not mounted.

Reference: https://lwn.net/Articles/789000/
Reference: https://lwn.net/Articles/789023/
Reference: https://kernelnewbies.org/LinuxChanges#Linux_5.9.New_close_range.28.29_system_call_for_easier_closing_of_file_descriptors
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-12-03 20:09:14 +00:00
Sami Kerola 931e60982e
login: move message printing out from main()
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-12-03 20:09:14 +00:00
Sami Kerola b04f183578
login: use xalloc memory allocation helpers everywhere
Apart two function calls login(1) already used xalloc functions.  If there
was a time when login tried to gracefully handle allocation errors that has
not been true for long time.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-12-03 20:07:30 +00:00
Sami Kerola 7679a2c5ca
login: fix coding style issues
Couple function had spaces instead of tabs in indent.  This change uses tabs
everywhere, and does handful of other spacing additions and removals.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-12-03 20:07:30 +00:00
Sami Kerola d515381901
login: use system definitions to determine maxium login name length
Allocating stack for about 10x more than longest possible user name is
wasteful, even if it happens for reletively short period of time.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-12-03 20:07:29 +00:00
Sami Kerola 5941a0db06
login: use calloc() when memory needs to be cleared
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-12-03 20:07:29 +00:00
Sami Kerola 0da0a5ed3b
login: use explicit_bzero() to get rid of confidental memory
Earlier code was most probably correct, but it is best to be safe than sorry
when dealing with confidental data removals.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-12-03 20:07:29 +00:00
Sami Kerola 5dd0896aa8
login: add initialize() function to have less stack allocated in main()
And move couple variables to the narrow scope they are used.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-12-03 20:07:28 +00:00
Sami Kerola 79a8afeb8f
login: replace function like definitions with inline functions
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-12-03 20:06:51 +00:00
Sami Kerola fb038d27a1
login: move getlogindefs_num() after localization init
There are translations in getlogindefs_num() and they will not take effect
unless the function call is after the setlocale(), bindtextdomain(), and
textdomain().

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-12-03 20:06:51 +00:00
Sami Kerola 0b4d75fae5
login: move timeout from global to local scope
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-12-03 20:06:47 +00:00
Sami Kerola bfcba3f586
login: stop keeping timeout message in memory forever
When the timeout is cancelled the message can be removed from memory.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-12-03 19:54:29 +00:00
Sami Kerola 42ccc9cfb4
login: use sig_atomic_t type for variable accessed from signal handler
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-12-03 19:54:29 +00:00
Karel Zak 9efa805cd7 Merge branch 'col-bug1198' of https://github.com/kerolasa/util-linux
* 'col-bug1198' of https://github.com/kerolasa/util-linux:
  col: make input to tolerate invalid wide characters
2020-12-03 15:09:19 +01:00
Karel Zak 58b510e580 libsmartcols: sanitize variable names on export output
The shells are very restrictive about variable names, only [:alnum:]
chars are allowed (and alphabetic chars as the first char).  The
library will replace "bad" chars with "_". The char '%' at the end is
replaced by _PCT.

Addresses: https://github.com/karelzak/util-linux/issues/1201
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-12-03 12:14:10 +01:00
Sami Kerola 14a36f96ee
col: make input to tolerate invalid wide characters
The getwchar(3) will choke and exit if invalid character is encountered.
This change will make col(1) to print broken multibyte characters as
\x{hex} string.

Reported-by: Vitaly Lipatov <lav@etersoft.ru>
Addresses: https://github.com/karelzak/util-linux/issues/1198
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-12-02 22:12:32 +00:00
Karel Zak 77d44c1e51 Merge branch 'dankamongmen/libblkid-manual-fix' of https://github.com/dankamongmen/util-linux 2020-12-02 12:06:25 +01:00
Karel Zak 8f25830c9b travis: disable OSX for now
For weeks we have a problem with timeout on OSX on travis, not sure
how to fix it ... volunteer wanted :-)

 ==> ./bootstrap --prefix=/usr/local/Cellar/cmake/3.19.1 --no-system-libs --paral
 ==> make

 No output has been received in the last 10m0s, this potentially indicates a stalled build or something wrong with the build itself.
 Check the details on how to adjust your build configuration on: https://docs.travis-ci.com/user/common-build-problems/#Build-times-out-because-no-output-was-received

 The build has been terminated

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-12-01 11:44:09 +01:00
Karel Zak cd588d6653 fuzzers: make tests setup more robust
- use robust functions like write_all()
- don't use assert() to check write/open/etc return values, because oss-fuzz.com
  report foreign (system, libc, ...) issues as our fails

Addresses: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=28009
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-12-01 11:35:02 +01:00
Karel Zak abd7815501 tests: (blkid) add support for multisession images
This commit adds support for multisession filesystem images to
standard low-probe blkid tests. The expected image name is

 <name>-multi-<offset>[-<offset> ...][-<something>].img

For example:
  iso-multi-0-174-348-genisoimage.img.xz

triggers three sub-tests:
  : iso-multi-genisoimage-0     ... OK
  : iso-multi-genisoimage-174   ... OK
  : iso-multi-genisoimage-348   ... OK

Addresses: https://github.com/karelzak/util-linux/issues/1161
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-30 10:33:20 +01:00
nick black 4d8fb3c063
libblkid: fix some typos in function comments 2020-11-26 22:52:20 -05:00
Karel Zak 0e0a3b59da libblkid: initialize magic strings in robust way
It is the worst habit to depend on the order of the members of the
structure ...

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-25 15:45:23 +01:00
Karel Zak c175692050 Merge remote-tracking branch 'pali/multisesssion'
* pali/multisesssion:
  libblkid: udf: add support for unclosed sequential Write-Once media
  libblkid: udf: add support for multisession via session_offset hint
  libblkid: iso9660: add support for multisession via session_offset hint
  libblkid: fix blkid_probe_get_sb() to use hint offset calculation
  libblkid: allow to specify offset defined by hint for blkid_probe_get_idmag()
  libblkid: detect session_offset hint for optical discs
  libblkid: do size correction of optical discs also by last written sector
  libblkid: detect CD/DVD discs in packet writing mode
  libblkid: overwrite existing hint
  libblkid: export blkid_probe_reset_hints()
  blkid: add --hint <name>=value
  libblkid: add blkid_probe_{set,get}_hint()
2020-11-25 14:48:30 +01:00
Karel Zak 30e8df968f lslogins: call close() for usable FD [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-25 14:02:11 +01:00
Karel Zak 665d79e793 Merge remote-tracking branch 'sami/uuidd-work'
* sami/uuidd-work:
  uuidd: fix misleading indentation
  uuidd: make timeout to take effect when debug is not defined
  uuidd: remove unnecessary bulk request size limit
  uuidd: add uuidd specific data types that are used in protocol
  uuidd: reorder bulk time and random generation code
  uuidd: document uuidd protocol
  uuidd: override operation type when performing bulk request
  uuidd: move option parsing to separate function
  uuidd: add command-line option values struct
  uuidd: use pid_t type when referring to process id
2020-11-24 13:12:22 +01:00
Karel Zak 7ffd3b0ef6 build-sys: do not use extra subdir for getopt examples
This is unnecessary, we have ${docsdir}/util-linux which is good
enough for these two getopt examples. I guess the "getopt"
subdirectory is legacy from time getopt has been merged into
util-linux.

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-24 12:46:03 +01:00
Karel Zak 7fa2d7fc6c travis: try update to xcode10.1
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-24 11:31:45 +01:00
Karel Zak 94ebe1d3e4 lsblk: add dependence between CD/DVD block and packet devices
This dependence is defined by

  $ cat /sys/class/pktcdvd/device_map
  pktcdvd0 252:0 11:0

Unfortunately, there is not any direct sysfs way how to refer this
relationship in /sys/{block,dev/block}. So, we have to read the
device_map file and then compare device numbers with the list.

$ lsblk /dev/sr0
NAME       MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0         11:0    1 1024M  0 rom
└─pktcdvd0 252:0    1    0B  0 disk

Addresses: https://github.com/karelzak/util-linux/issues/1185
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-24 10:44:46 +01:00
Sami Kerola ef6ac59689
uuidd: fix misleading indentation
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-11-23 22:48:08 +00:00
Sami Kerola f187035d73
uuidd: make timeout to take effect when debug is not defined
The trailing comma made code to compile without issues, but meant all_done()
was called only when --debug was in defined in command-line.

Fixes: 3d6250e96b
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-11-23 22:48:08 +00:00
Sami Kerola 0453925535
uuidd: remove unnecessary bulk request size limit
Limiting random query to 1000 uuid's was pointless when the next line will
further restrict upper limit to 63 entries.  The 63 entries is what fits to
the uuidd communication buffer with the header.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-11-23 22:48:07 +00:00
Sami Kerola b491161819
uuidd: add uuidd specific data types that are used in protocol
Use a typedef for types that are sensitive what comes to uuidd protocol
field widths, read write sizes, and related checks.

Proposed-by: Karel Zak <kzak@redhat.com>
Reference: https://github.com/karelzak/util-linux/pull/1196#discussion_r528595794
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-11-23 22:48:07 +00:00
Sami Kerola ea9416925c
uuidd: reorder bulk time and random generation code
Write the data and response length values in same close to order they appear
in protocol.  This should make code a little easier to read.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-11-23 22:47:13 +00:00
Sami Kerola 2049075a79
uuidd: document uuidd protocol
Seeing what can be expected should make it easier to understand what the
code does.

Notice that simply writing down the resposes one can start wondering deeper
questions, such as, why does the time bulk response reply only one uuid
followed by number how many were requested?  Was that a some type of TODO
note?

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-11-23 22:33:33 +00:00
Sami Kerola 77a54655bb
uuidd: override operation type when performing bulk request
Relying to single vs bulk requests to be exactly two steps away from each
other was an unnecessary dirty trick.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-11-23 21:34:40 +00:00
Sami Kerola 084efcee43
uuidd: move option parsing to separate function
Moving the option parsing to a separate function will allow moving some
variables from main() heap to be in scope that free them later.  That should
make the uuidd to have a little bit smaller runtime memory allocation.

The static long options is changed to be local variable.  That should make
it to be part of heap for a bit, until removed.  Earlier the variable was in
data segment and permanently in runtime memory.  Whether this makes any
impact either way is not entirely clear, but hope is the runtime memory
allocation is tiny bit smaller.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-11-23 21:34:40 +00:00
Sami Kerola b03ffec18c
uuidd: add command-line option values struct
The struct will help seeing where the variable values are coming from.  This
will also help upcoming refactoring.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-11-23 21:34:40 +00:00
Sami Kerola c14e0f6239
uuidd: use pid_t type when referring to process id
Earlier use of a variable that holds switch enabling boolean to hold process
id was a little bit strange, and not exactly correct.  An int should be good
enough to hold any pid, but it is better to be precise and use the type that
is meant for the job.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-11-23 21:34:39 +00:00
Karel Zak 1e416dc0b9 Merge branch 'master' of https://github.com/pali/util-linux
* 'master' of https://github.com/pali/util-linux:
  libblkid: drbdmanage: use blkid_probe_strncpy_uuid instead of blkid_probe_set_id_label
2020-11-23 10:21:17 +01:00
Karel Zak 9b9954a9c4 Merge branch 'privfix' of https://github.com/ericonr/util-linux 2020-11-23 10:19:01 +01:00
Pali Rohár 3a9a6036a4 libblkid: drbdmanage: use blkid_probe_strncpy_uuid instead of blkid_probe_set_id_label
Function blkid_probe_strncpy_uuid() is better suitable for setting UUID
than function blkid_probe_set_id_label().

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
2020-11-22 19:44:09 +01:00
Érico Rolim 93de9f687d setpriv: allow using [-+]all for capabilities.
The initial change to lib/caputils that allowed this was commit
5d95818757, which made it possible to
trust the value returned by cap_last_cap().

The error message was also somewhat misleading, since cap_last_cap()
being smaller than CAP_LAST_CAP happens when setpriv itself is built
with kernel headers older than the currently running kernel, not due to
libcap-ng.
2020-11-20 12:45:39 -03:00
Érico Rolim 0eba195d9e setpriv: small clean-up.
- Add _() calls for some strings which were missing it.
- In print_caps(), use the same error checking done in
  list_known_caps(); it is expected that libcap-ng will always return a
  string, even if it's only "cap_%d".
2020-11-20 12:33:23 -03:00
Karel Zak 57b74b0dcb Merge branch 'w45'
* w45:
  fdformat: remove command from default build
  more: improve error messaging when input file is directory
  ul: make set_column() zero check more obvious
  colrm: fix argument parsing
  rfkill: stop execution when rfkill device cannot be opened
  cifuzz: reindent yaml file
  man: make tilde and caret characters to render correctly
2020-11-20 12:01:22 +01:00
Karel Zak 966420219c lib/caputils: split to multiple functions, add test
Let's split the code to make it possible to test separately bsearch as
well as procfs based cap_last_cap().

 $ ./test_caputils --last-by-bsearch
 last cap: 39
 $ ./test_caputils --last-by-procfs
 last cap: 39
 $ ./test_caputils --last
 last cap: 39

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-20 11:21:41 +01:00
Karel Zak 1b54a74e86 lib/procutils: improve proc_is_procfs(), add test
* add delay between attempts
* zeroize errno and check for EAGAIN (like in other code)
* add small test program
   ./test_procutils --is-procfs [<dir>]

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-20 10:40:31 +01:00
Karel Zak 61dc5ae39a Merge branch 'caps' of https://github.com/ericonr/util-linux
* 'caps' of https://github.com/ericonr/util-linux:
  lib/caputils: add fall back for last cap using prctl.
  lib/procutils: add proc_is_procfs helper.
2020-11-20 10:21:19 +01:00
Masayoshi Mizuma f42f105b07 lscpu: show the number of physical socket on aarch64 machine without ACPI PPTT
Show the number of the number of physical socket even if the sysfs doesn't
have the physical socket information.

Note, lscpu shows the number of physical socket as 'Socket(s):' only if
root user runs it because accessing the DMI table requires root
privilege.

Signed-off-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
2020-11-20 09:17:12 +01:00
Masayoshi Mizuma 788f90d69a lscpu: add helper to get physical sockets
Add a helper function, get_number_of_physical_sockets_from_dmi(),
to get physical sockets from DMI table in case of the sysfs for
cpu topology doesn't have the physical socket information.

get_number_of_physical_sockets_from_dmi() parse the DMI table
and counts the number of SMBIOS Processor Information (Type04)
structure.

Signed-off-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
2020-11-20 09:17:12 +01:00
Masayoshi Mizuma 3cd676f5ec lscpu-dmi: Move some functions related to DMI to lscpu-dmi
Move some functions related to DMI to lscpu-dmi.

Signed-off-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
2020-11-20 09:17:12 +01:00