Commit Graph

103 Commits

Author SHA1 Message Date
Karel Zak 2fc2bb7ebd lslogins: check errno after strto..()
Addresses: https://github.com/karelzak/util-linux/issues/1356
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-06-21 15:31:43 +02:00
Karel Zak e51c9822a9 lslogins: non-Linux fix
Reported-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-04-12 16:20:01 +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
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
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
Rosen Penev bd89499e07
[clang-tidy] do not return in void functions
Found with readability-redundant-control-flow

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-19 14:03:21 -07:00
Karel Zak cd52e392ac lslogins: remove unnecessary brackets
Just to be consistent with the rest of the code.

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-03-31 13:12:11 +02:00
Sami Kerola 3434ac9720
lslogins: use lastlog as wtmp fallback
The wtmp file tends to rotate higher rate than lastlog, so use the later as
fallback in when wtmp tells nothing in LAST-LOGIN column.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-03-29 21:18:48 +01:00
Karel Zak 3b28b4686c lslogins: assume unterminated strings in wtmp/btmp [coverity scan]
Let's use mem2strcpy() to be robust.

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-01-15 13:20:23 +01:00
Stanislav Brabec 0d37969cbe lslogins: Fix discrepancies of SYS_UID_MIN
util-linux does not contain useradd. Its most popular implementation
comes from shadow. SYS_UID_MIN is one of common parameters. Its
hardcoded fallback value is equal to 101 in shadow useradd (see
shadow-4.6/libmisc/find_new_uid.c: get_ranges()), but 201 in
login-utils/lslogins.c.

Let lslogins use the same fallback as useradd from shadow.

Hopefully most distros define its custom value of SYS_UID_MIN in
/etc/login.defs, so this problem is not visible.

login-utils/lslogins.1 does not mention its default at all. Add a
reference and improve text of lslogins(1) to prevent off-by-one
interpretation.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-04-24 11:16:53 +02: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
Sami Kerola 110260830d docs: fix typos [codespell]
Reference: https://github.com/codespell-project/codespell
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-02-18 13:22:43 +01:00
Karel Zak 6245c26ad4 lslogins: make valid_pwd() more robust
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-11 14:20:19 +01:00
Sami Kerola a81a48779b
lslogins: remove duplicate NULL check
Having this excess NULL check in place causes small performance penalty, and
makes compiler to guess wrong if a null should be checked.  To me getting
rid of false positive warning is more useful.

login-utils/lslogins.c:634:7: warning: potential null pointer dereference
[-Wnull-dereference]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-12-10 20:41:18 +00:00
Karel Zak ba1e203497 lslogins: return 1 on "lslogins nonexisting"
The default behavior for -l and -g is to silently ignore unknown login
names, but this is very confusing when you explicitly specify just one
login name.

Note that the current implementation also prints empty "Last log" for
nonexisting user. It seems ugly.

 # lslogins nonexisting

 Last logs:

new version:

 # lslogins nonexisting
 lt-lslogins: cannot found 'nonexisting'
 # echo $?
 1

The -l and -g behaviour has not been changed.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1614967
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-08-13 14:16:28 +02:00
Karel Zak 09a4313ceb lslogins: add info about single-user output mode
The supported command line synopsis is also

	lslogins foo

and it provides different output than

	lslogins -l foo

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-08-13 13:49:26 +02:00
Karel Zak 0f9b25958e setterm: fix compiler warnings [-Wcast-qual]
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-23 11:49:49 +02:00
Karel Zak 4d43029b72 lslogins: remove redundant condition
[util-linux-2.32.1/login-utils/lslogins.c:601]: (style) Redundant condition: If '!EXPR', the comparison 'EXPR != '$'' is always true.

Reported-by: David Binderman <dcb314@hotmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-18 09:54:05 +02:00
Karel Zak fa7709dbad lslogins: add -o+<COLNAME> support
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-05-23 16:44:42 +02:00
Karel Zak bb3d3fd905 lslogins: add PWD-METHOD column
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-05-23 16:32:32 +02:00
Karel Zak 214fbec40a lslogins: fix password verification
Let's follow the standard $id$salt$encrypted password format in
verification code.

The current code is useless and for example PWD-LOCK column is always
FALSE.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1581611
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-05-23 12:45:23 +02:00
Sami Kerola 2ab432effb
lslogins: add --output-all option
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-05-03 19:56:20 +01:00
J William Piggott 4111bb3ab5 lib/timeutils: add common ISO timestamp masks
* Start the ISO format flags at bit 0 instead of bit 1.

* Remove unnecessary _8601 from ISO format flag names to
  avoid line wrapping and to ease readability.

* ISO timestamps have date-time-timzone in common, so move
  the TIMEZONE flag to bit 2 causing all timestamp masks
  to have the first three bits set and the last four bits
  as timestamp 'options'.

* Change the 'SPACE' flag to a 'T' flag, because it makes
  the code and comments more concise.

* Add common ISO timestamp masks.

* Implement the ISO timestamp masks in all applicable code
  using the strxxx_iso() functions.

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-11-10 16:34:55 -05:00
Karel Zak be64282665 lslogins: fix possible memory leak [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-10-11 15:13:44 +02:00
Karel Zak f4513f27c2 lslogins: ignore non-existing users
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-08-18 10:23:38 +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 86be6a32d3 misc: cosmetics, remove argument from usage(FILE*)
This patch is trivial and changes nothing, because
we were always using usage(stdout)

Now all our usage() functions look very similar. If wanted we
could auto-generate another big cosmetical patch to remove all
the useless "FILE *out" constants and use printf and puts
rather than their f* friends. Such patch could be automatically
synchronized with the translation project (newlines!) to not
make the translators sick.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-26 14:38:24 +02:00
Karel Zak d6ec64e824 Merge branch '170622' of github.com:jwpi/util-linux
* '170622' of github.com:jwpi/util-linux:
  Docs: move option naming to howto-contribute.txt
  Docs: update howto-usage-function.txt
  Docs: add a comment for constants to boilerplate.c
  include/c.h: add USAGE_COMMANDS and USAGE_COLUMNS
2017-06-26 13:56:45 +02:00
J William Piggott 6e2d5a4460 include/c.h: add USAGE_COMMANDS and USAGE_COLUMNS
* login-utils/lslogins.c: all uses changed
* misc-utils/findmnt.c: likewise
* sys-utils/blkzone.c: likewise
* disk-utils/sfdisk.c: likewise
* sys-utils/lscpu.c: likewise
* sys-utils/lsmem.c: likewise
* sys-utils/wdctl.c: likewise

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-06-24 13:57:12 -04:00
Ruediger Meier 0caad87fdb misc: remove superfluous null pointer checks for optarg
This is only needed for optional arguments.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-22 02:56:57 +02:00
Karel Zak 780ce22cda misc: consolidate smartcols error messages
... just to keep translators happy

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-18 11:39:34 +02:00
Karel Zak 677ec86cef Use --help suggestion on invalid option
The current default is to print all usage() output. This is overkill
in many case.

Addresses: https://github.com/karelzak/util-linux/issues/338
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-12-19 13:13:34 +01:00
Ruediger Meier b4b919fe5e login-utils: switch to utmpx.h
Now the build will fail on many non-Linux systems because
utmpx.h is available everywhere but we still use non-POSIX
features. We'll fix this next commit.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-12-07 12:35:24 +01:00
Ruediger Meier 77f5a94586 lslogins: remove useless strlen()
strlen() is not smarter than strncpy(). Bytes that follow a null byte
are not compared anyway.

BTW avoid using the defined sizes.

CC: Ondrej Oprala <ooprala@redhat.com>
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-12-07 12:35:24 +01:00
Karel Zak bae57b5a3c misc: fix unsigned int usage for ctype.h functions
Reported-by: "Yuriy M. Kaminskiy" <yumkam@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-10-26 10:13:47 +02:00
Sami Kerola eb2306e675
misc: fix declarations shadowing variables in the global scope [oclint]
Fixes multiple occurences of 'optarg' overwrites.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-21 21:14:33 +01:00
Sami Kerola 01e6b621e4
lslogins: simplify if clause and move definition and comments [oclint]
The if clause change is pretty trivial.  Moving the macro near to where it
is used makes sense to people who want to read the code.  And finally the
comment about user list was at wrong spot.

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 cb5b52882e lslogins: use strtime_short()
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-24 13:22:23 +02:00
Karel Zak 88134ee208 lslogins: use strtm_iso()
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-24 11:08:10 +02:00
Yuriy M. Kaminskiy 06fa581748 misc: safer (and uniform) handling of return value
When `rc` is `INT_MAX`, `rc + 1` result in signed integer overflow.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-03-07 15:11:06 +01:00
Karel Zak 8b7ef91689 lslogins: fix getgrouplist() usage for 64BE
on ppc64:
 $ lslogins kzak
 $ lslogins: cannot allocate 85899345920 bytes: Cannot allocate memory

because

  (int *) len

where len is pointer to size_t is bad idea...

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-12-21 15:50:58 +01:00
Karel Zak f686b9980a lslogins: remove duplicate [make checkincludes]
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-07-29 12:57:22 +02:00
Karel Zak a6bf40ee77 lslogins: merge read_utmp() code
The code is used only in lslogins, so it does not make sense to
maintain it in libcommon.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-07-16 11:26:14 +02:00
Sami Kerola 7ee26cbf02 maint: fix shadow declaration
This change fixes all shadow declarations.  The worth while to mention
fix is with libfdisk sun geometry.  It comes from bitops.h cpu_to_be16
macro that further expands from include/bits/byteswap.h that has the
shadowing.

libfdisk/src/sun.c:961:173: warning: declaration of '__v' shadows a previous local [-Wshadow]
libfdisk/src/sun.c:961:69: warning: shadowed declaration is here [-Wshadow]
libfdisk/src/sun.c:961:178: warning: declaration of '__x' shadows a previous local [-Wshadow]
libfdisk/src/sun.c:961:74: warning: shadowed declaration is here [-Wshadow]

That could have caused earlier some unexpected results.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-01-07 10:08:21 +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
Sami Kerola 4ecc6dbb53 lslogins: use hardcoded paths from pathnames.h
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-12-19 09:11:03 +00:00
Sami Kerola 77006d95db lslogins: add space to systemd journal header and message
This commit changes journal messages in individual user printout the
following way.

Dec 13 16:02:05 systemd[324]:Time has been changed	(old)
Dec 13 16:02:05 systemd[324]: Time has been changed	(new)

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-12-19 09:11:02 +00:00
Sami Kerola cdf3896a05 lslogins: reject unknown time format arguments
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-12-19 09:11:02 +00:00