Commit Graph

1052 Commits

Author SHA1 Message Date
Sami Kerola ff9da8efca setpwnam: use more appropriate allocation size types
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-08-21 15:00:16 +02:00
Karel Zak 9210c0d225 chfn: don't append extra tailing commas
# grep kzak /etc/passwd
 kzak1000:1000::/home/kzak:/bin/bash

 # chfn kzak
 ...
 grep kzak /etc/passwd

old version:
 kzak1000:1000:Karel Zak,,,,:/home/kzak:/bin/bash

fixed version:
 kzak1000:1000:Karel Zak:/home/kzak:/bin/bash

Reported-by: Filip Dvorak <fdvorak@redhat.com>
References: f723cbf544
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-08-19 14:03:07 +02:00
Sami Kerola 1aaee548e3 login: simplify string handling
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-07-24 11:11:29 +02:00
Sami Kerola 0675f52ab5 last: replace strncat() with more robust mem2strcpy()
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-07-24 11:11:10 +02:00
Jakub Hrozek 9a1a982206 su: More descriptive error message on malformed user entry
With users coming from LDAP, it is often the case that the entry in LDAP
does not contain one or more attributes required by su or, because of
misconfigured access control rights, the attribute might not be readable
by the LDAP client. In that case, su just tells the user that the user
does not exist.

It might be more user-friendly to tell the user to check the user entry
for all required fields.
2019-05-31 13:23:57 +02:00
Karel Zak 9c6167c394 login: retire use of __FUNCTION__ macro
This fixes following warning about deprecatd __FUNCTION__ that is another
name for __func__ since GCC (pre 2.95, released July 1999).

    login-utils/login.c:860:10: warning: ISO C does not support
    ‘__FUNCTION__’ predefined identifier [-Wpedantic]

Co-Author: Sami Kerola <kerolasa@iki.fi>
Reference: https://c0x.coding-guidelines.com/6.4.2.2.html
Reference: https://github.com/karelzak/util-linux/pull/802
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-27 11:55:19 +02:00
Karel Zak 124a903002 vipw: use xstrncpy()
It's already used by vipw, so use it everywhere.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-20 12:57:39 +02:00
Karel Zak 002931c485 Merge branch '2019wk19' of https://github.com/kerolasa/util-linux
* '2019wk19' of https://github.com/kerolasa/util-linux:
  lib/colors: remove redundant if statement
  wipefs: fix variable / function shadowing [cppcheck]
  sulogin: fix variable / function shadowing [cppcheck]
  lscpu: remove redundant condition check [cppcheck]
  libmount: avoid possible null pointer dereference [cppcheck]
  lib/mangle: fix possible null pointer dereference [cppcheck]
  sfdisk: remove unnecessary size check [cppcheck]
2019-05-20 12:35:38 +02:00
Sami Kerola ff09a5129a
sulogin: fix variable / function shadowing [cppcheck]
[login-utils/sulogin.c:398] -> [login-utils/sulogin.c:171]: (style) Local
variable set shadows outer function
[login-utils/sulogin.c:398] -> [login-utils/sulogin.c:830]: (style) Local
variable set shadows outer function

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-05-18 22:41:58 +01:00
Karel Zak e868cfb0a6 utmpdump: check ftello() return value
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-16 13:46:03 +02:00
Karel Zak 00749b05b9 su: make comment more friedly to 'make checkxalloc'
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-04-24 12:45:20 +02: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
Karel Zak 99c1ebee21 su: change error message
We use PAM and if pam_strerror() returns nothing we have no clue why
authentication failed. It's mistake to blame incorrect password if
there are many possible reason...

Addresses: https://github.com/karelzak/util-linux/issues/778
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-03-25 16:39:43 +01:00
Karel Zak 64a87be1a4 su: add note about ECHO on --pty
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-03-06 13:12:23 +01:00
Karel Zak 5932ef81de su: be sensitive to another SIGCHLD ssi_codes
See the same issue for script: 27afe50168

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-03-06 12:02:30 +01:00
Karel Zak 282ca3d87b su: fix --pty terminal initialization
* use proper winsize rather than uninitialized variable (Oops...)

* set the current terminal to the raw mode

* disable ECHO for non-terminal execution to be compatible with
  non-pty output

Addresses: https://github.com/karelzak/util-linux/issues/767
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-03-06 12:01:18 +01:00
Karel Zak 0b07e2682f su/runuser: don't mark --pty as experimental, add it to runuser.1 too
* let's assume that --pty is stable enough that we do not have to remove it ;-)

* add --pty to the runuser.1 man page

Addresses: https://github.com/karelzak/util-linux/issues/760
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-03-04 13:13:30 +01:00
Patrick Steinhardt 72aa1db70c last: do not use non-standard __UT_NAMESIZE
In commit b22332dd4 (last: fix wtmp user name buffer overflow
[asan], 2019-01-13), we started to make sure that the `ut_user`
field of the `utmpx` struct is always NUL-terminated. The
implementation makes use of the `__UT_NAMESIZE` define to
determine the position of the last character in that array. The
problem is that this is a non-standard define that is not
necessarily available on non-glibc platforms.

As there is no standardized define, we should just use `sizeof`.
This fixes compilation on musl libc based systems.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
2019-03-04 11:38:28 +01: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
Sami Kerola b22332dd4f
last: fix wtmp user name buffer overflow [asan]
Ensure utmp user name field is null terminated.  Without that getpwnam() can
buffer overflow, when wtmp file is malformed.

Addresses: https://github.com/karelzak/util-linux/issues/715
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-01-13 20:00:38 +00:00
Karel Zak 1a83c00d88 login: add support for login.defs(5) LASTLOG_UID_MAX
This new variable allows to keep lastlog file small and filter out
things like huge nfsnobody UIDs.

The variable is also supported by shadow-utils (adduser, etc.).

Addresses: https://github.com/shadow-maint/shadow/pull/142/
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-01-11 12:16:00 +01:00
Karel Zak 623427456e login-utils/logindefs: clenaup API
The default value should be unsigned if the result is also unsigned...

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-01-11 12:15:22 +01:00
Stanislav Brabec 86f42e5a2a su-common.c: prefer ENV_SUPATH over ENV_ROOTPATH
ENV_SUPATH and ENV_ROOTPATH are equivalent and ENV_ROOTPATH takes
precedence in both login and su. It makes no sense. More logical would be
precedence of ENV_SUPATH in su and ENV_ROOTPATH in login.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2019-01-10 12:26:38 +01:00
Stanislav Brabec 15a191f6d3 su-common.c: prefer /etc/default/su over login.defs
su(1) documentation says:
       /etc/default/su  command specific logindef config file
       /etc/login.defs  global logindef config file

It indirectly indicates that /etc/default/su should take precedence
over /etc/login.defs.

But the reverse is true. It is not possible to define ENV_PATH in
/etc/login.defs and then make su specific customization in
/etc/default/su. We need to change read order to match the documented
behavior.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2019-01-10 12:26:38 +01:00
Carlos Santos 7a40136c2f utmpdump: fix word swapping in manual page
From
    The only binary version of the utmp(5) is standardised.
To
    Only the binary version of the utmp(5) is standardised.

Change-Id: I0033f6cf055d569c7dfca5e05e918f735ea72582
Signed-off-by: Carlos Santos <casantos@datacom.com.br>
2019-01-08 14:51:13 +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 7f76bc8a75 su: cleanup code to copy to log strings
man utmp:
  String fields are terminated by a null byte ('\0') if they are shorter
  than the size of the field.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-10-03 17:10:13 +02:00
Karel Zak ac5c12fdc2 login: cleanup code to copy to log strings
man utmp:
  String fields are terminated by a null byte ('\0') if they are shorter
  than the size of the field.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-10-03 17:08:11 +02:00
Karel Zak 22fbfdb8f5 last: make sure domain is zero terminated
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-10-03 17:06:33 +02:00
Karel Zak 64d11d6bb0 su: add note about merged /usr
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-08-22 11:39:13 +02:00
Karel Zak a8224e8e7e sulogin: restore signals after failed exec() only
* removes unnecessary variable

* the current code restores signals always when shell has not been
  executed -- this is correct as function sushell() modify signal
  mask, but in all another cases we do not need touch the mask.
  Especially when we ask for the  password in endless while() loop...

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-08-16 16:16:40 +02:00
Karel Zak f9915d6db3 sulogin: do not use plain 0 as NULL
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-08-16 15:58:20 +02:00
Jakub Wilk b9c3b903fe Fix man page typos
Signed-off-by: Jakub Wilk <jwilk@jwilk.net>
2018-08-16 11:09:15 +02:00
Karel Zak 75efef98d4 su: add --whitelist-environment
* usable with --login to whitelist specified environment variables

* the list is ignored for the core variables like HOME, SHELL, USER,
  LOGNAME and PATH (su --login always resets these variables)

Note that su(1) requires password and after successful authentication
user has full control over the session, so he can set arbitrary
environment variables. The whitelist makes things more user friendly
only.

The patch removes unnecessary optimization when allocate environ[]. It
seems better to keep all in glibc hands and just reset the environment
array only.

Addresses: https://github.com/karelzak/util-linux/issues/221
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-08-15 13:03:21 +02: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
Bjarni Ingi Gislason 934a6fa80b man pages: Remove "left" (or change to "l") in the column formats of tables
A developmental version of "groff" issued a warning, for example with
"test-groff -b -e -mandoc -T utf8 -rF0 -t -w w -z":

troff: <logger.1>:299: warning: can't find font 't'

Signed-off-by: Bjarni Ingi Gislason <bjarniig@rhi.hi.is>
2018-08-06 08:58:57 +02:00
Karel Zak 0dc7598323 su: add note about SIGKILL to the man page
Addresses: https://github.com/karelzak/util-linux/issues/443
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-08-03 14:08:00 +02:00
Karel Zak 088d487612 login: use const qualifier for username from PAM or struct passwd [-Wcast-qual]
It seems more robust to use 'const' qualifier for username if this
variable points to external resources like PAM or struct passwd. The
patch introduces new variable cmd_username for username specified on
login(1) command line.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-23 12:21:33 +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
Bjarni Ingi Gislason 3fe5e8ec09 man: Change the only argument to two for the two-fonts macros
Punctuation marks have been left in the only argument of two-fonts
macros, instead of being separated from it to make the second one.

Signed-off-by: Bjarni Ingi Gislason <bjarniig@rhi.hi.is>
2018-05-23 10:43:27 +02:00
Bjarni Ingi Gislason 0bb7e904d7 man: Use the correct macro for a font change of one argument
Use the correct macro (I, B) for the font change of one argument, not
those that are used for alternating two fonts, like "BR", "IR", "RB",
or "RI".

Signed-off-by: Bjarni Ingi Gislason <bjarniig@rhi.hi.is>
2018-05-23 10:43:27 +02:00
Karel Zak c9fdebcf54 Merge branch 'output-all' of https://github.com/kerolasa/lelux-utiliteetit
* 'output-all' of https://github.com/kerolasa/lelux-utiliteetit:
  zramctl: add --output-all option
  swapon: add --output-all option
  rfkill: add --output-all option
  partx: add --output-all option
  lsns: add --output-all option
  lsmem: add --output-all option
  lslogins: add --output-all option
  lslocks: add --output-all option
  lscpu: add --output-all option
  losetup: add --output-all option
  findmnt: add --output-all option
2018-05-10 12:15:32 +02:00
Sami Kerola e4077e0e44 last: fix false positive compiler warning
login-utils/last.c: In function ‘list’:
login-utils/last.c:398:36: warning: argument to ‘sizeof’ in ‘strncat’ call
is the same expression as the source; did you mean to use the size of the
destination?  [-Wsizeof-pointer-memaccess]
  strncat(utline, p->ut_line, sizeof(p->ut_line));

The sizeof(utline) is defined as sizeof(p->ut_line) + 1, so the compiler got
that wrong.  Lets truncate strncat() otherway around to keep gcc 8.1 happy.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-05-10 11:29:17 +02:00