Commit Graph

1196 Commits

Author SHA1 Message Date
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
Sami Kerola 2ab432effb
lslogins: add --output-all option
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-05-03 19:56:20 +01:00
Ruediger Meier 73afd3f8e8 misc: fix typos using codespell
Some more funny typos, please review carefully.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2018-02-16 11:12:52 +01:00
Samuel Thibault 4365c8107f su: build fix for the case where USE_PTY is not defined
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-02-12 12:09:40 +01:00
Karel Zak 7bc5eeee44 vipw: use errexec()
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-02-01 15:41:42 +01:00
Karel Zak 856fcfd104 newgrp: use errexec()
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-02-01 15:41:23 +01:00
Karel Zak 3c29b695dd su: use errexec()
The new macro is fully compatible with original (coreutils) code.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-02-01 15:37:22 +01:00
Karel Zak a15dca2f6d include/debug: introduce __UL_INIT_DEBUG_FROM_STRING()
Let's make it possible to use debug.h without environment variables.

Suggested-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-17 13:58:29 +01:00
Sami Kerola a16f45d4f6 vipw: do not let editor to inherit open file descriptors
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-12-04 13:04:11 +01:00
Karel Zak e6b32e7d1a login: add LOGIN_PLAIN_PROMPT to login.defs
We have command line option -H to disable hostname in login prompt.
Unfortunately, in same cases (e.g. telnetd) it's impossible to specify
login(1) command line options due to hardcoded execl()...

This patch introduces LOGIN_PLAIN_PROMPT boolean for /etc/login.defs
to suppress hostname in the prompt.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-12-04 12:31:29 +01:00
Karel Zak f4b03edb73 login-utils: use free_getlogindefs_data()
It seems better to deallocate logindefs.conf stuff in long time
running (=waiting) processes like login(1) and su(1).

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-28 14:49:05 +01:00
Sami Kerola fcf841f8d3 misc: fix typos
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-28 14:39:13 +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
J William Piggott 9fd0a7a96c lib/timeutils: add get_gmtoff()
This new function returns the GMT offset relative to its
argument. It is used in this patch to fix two bugs:

1) On platforms that the tm struct excludes tm_gmtoff,
   hwclock assumes a one hour DST offset. This can cause
   an incorrect kernel timezone setting. For example:

 Master branch tested with tm_gmtoff illustrates the correct offset:
$ TZ="Australia/Lord_Howe" hwclock --hctosys --test | grep settimeofday
Calling settimeofday(1507494204.192398, -660)

 Master branch tested without tm_gmtoff has an incorrect offset:
$ TZ="Australia/Lord_Howe" hwclock --hctosys --test | grep settimeofday
Calling settimeofday(1507494249.193852, -690)

 Patched tested without tm_gmtoff has the correct offset:
$ TZ="Australia/Lord_Howe" hwclock --hctosys --test | grep settimeofday
Calling settimeofday(1507494260.194208, -660)

2) ISO 8601 'extended' format requires all time elements
   to use a colon (:).

Current invalid ISO 8601:
$ hwclock
2017-10-08 16:25:17.895462-0400

Patched:
$ hwclock
2017-10-08 16:25:34.141895-04:00

Also required by this change:
login-utils/last.c: increase ISO out_len and in_len by one to
                    accommodate the addition of the timezone colon.

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-11-10 16:14:04 -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
Tobias Stoeckmann f17bda66bd login: fix signal race
The functions warnx(3) and gettext(3) are not safe to use within signal
handlers and should be avoided. Preparing the message beforehand and
calling write(2) as well as calling _exit(2) solves the problem.

[kzak@redhat.com: - use program_invocation_short_name rather than argv[0],
                  - use ignore_result() to keep compiler happy]

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-26 12:03:24 +02:00
Karel Zak e9fde3e900 su: (pty) improve SIGSTOP/SIGCONT semantic
We want to use waitpid() only when child is terminated or stopped to
pick up child status, otherwise PTY proxy has to be active. This is
difference between "su" and "su --pty". For "su" we keep parent all
time in waitpid().

It would be possible to use separate code based on signalfd_siginfo,
but it seems better to keep all this stuff on one place -- it  means
wait_for_child().

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:49:11 +02:00
Karel Zak 13ee2f4d78 su: (pty) save child status
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:49:11 +02:00
Karel Zak 5328d8e7e8 su: (pty) simplify stdin usage in poll()
Not sure why I have problem with this years ago for script(1), but it
seems .fd=-1 is really enough to the ignore the FD.

Reported-by: Vaclav Dolezal <vdolezal@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:49:11 +02:00
Karel Zak 61b3106ba3 su: (pty) fix slave terminal attributes initialization
Reported-by: Vaclav Dolezal <vdolezal@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:49:11 +02:00
Karel Zak 0214f438a6 su: (pty) fix child signal mask usage
The signal mask is used by pty_init_slave(), but it has never been
uninitialized before fork(), so child gets 0 as a mask :-(

Note that script(1) has no this issue because it opens signal-fd
before fork().

Reported-by: Vaclav Dolezal <vdolezal@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:49:11 +02:00
Sami Kerola 204aa7714d runuser: fix linking
Add conditional -lutil to runuser when needed to avoid linking error.

login-utils/su-common.o: In function `pty_create':
login-utils/su-common.c:269: undefined reference to `openpty'
login-utils/su-common.c:273: undefined reference to `openpty'

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-09-18 11:49:11 +02:00
Karel Zak ae6e2537ff su: fix non-pty compilation
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:49:11 +02:00
Karel Zak 927ded6be6 su: enable TIOCSCTTY and minor changes
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:49:11 +02:00
Karel Zak 6461eeecd7 su: add more informartion to man page
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:49:11 +02:00
Karel Zak eb7d0ad0fe su: add PTY support
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:49:11 +02:00
Karel Zak 04845ec766 su: add --pty option
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:49:11 +02:00
Karel Zak 305ef556d6 su: move parent signals setup to separate function
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:49:11 +02:00
Karel Zak b55e712816 su: make wait_for_child() usable in arbitrary situation
For example if called more than once; to keep PTY code simple and
robust.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:49:11 +02:00
Karel Zak 665f36bed9 su: keep old sigactions in control struct
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:49:11 +02:00
Karel Zak f6e8b23658 su: fix refactoring bug in child PID usage
Fix child pid cleanup according to commit 0076012563ff34e294a6166d605118bcdd35f7e1.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak 44f36ad1ed su: add child to control struct
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak e192de658b su: fix compiler warnings [-Wimplicit-fallthrough=]
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak b09e7ea851 su: add wait_for_child()
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak 8ce9c38690 su: unblock signals is all initialized
This patch a little bit reorders signals initialization. The original
code unblocks SIGINT SIGQUIT before signal handler is set for the
signals. It means there is a small possible race.

It seems better to compose wanted mask, setup handlers and then
unblock all the wanted signals.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak 5fc211d217 su: clean up signals usage
- don't use magic numbers to index old actions
- don't use if () if ()
- make if() conditions more readable

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak feab56878a su: clean up const usage
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak e19db0449e su: fix debug message
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak 6b28328255 su: properly clear child PID
The patch from master branch, somehow lost during su refactoring
rebase.

Reported-by: Tobias Stöckmann <tobias@stoeckmann.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak 242708de5b su: improve some debug messages
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak 2260e493d6 su: add debug.h stuff
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak c34865b96d su: use switch() to split after fork
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak a4440cd1f1 su: move PAM session initialization to separate function
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak 13de9b2194 su: rename evaluate_uid()
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak e402d13746 su: cosmetic code changes
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak 9303158534 su: cleanup setuid/gid related code
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak 13396b1046 su: cleanup setenv related code
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak 581ddd373a su: cleanup shell related code
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak 94c6730bb9 su: cleanup usernames usage
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak 032d759a10 su: cleanup pwd struct usage
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak 4f5f35fc83 login: add xgetpwnam()
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak 302b7b65e4 su: consolidate tty name usage
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak dc5bfb71ff su: reorder functions
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak b9a92282e5 su: cleanup PAM stuff
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak 42be9bda5b su: cleanup usage()
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak 832f5cd524 su: add control struct
* setup logindefs loader by function rather than by global pointer

* move basic booleans to the su_context struct

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak b1195aa07d su: cosmetic changes after indent
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Karel Zak 983652abc1 su: fix indention
Yes, I know... this patch is horrible. We all hate this in git
history, but the original indention from coreutils has been so
crazy...

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-18 11:48:56 +02:00
Sami Kerola a1f5bb9d1f chsh: remove local /etc/shells parsing in favour of getusershell(3)
Less code, less bugs.  And if there are bugs at least share them with all
other programs that use getusershell(3) from libc.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-08-30 11:21:59 +02:00
Karel Zak 6047c6db9c lslogins: be more explicit with -g in man page
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-08-18 10:29:54 +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
Sami Kerola 46df3aaae8
vipw: use explicit_bzero() to clear buffer after copy
This should make leaking end of /etc/shadow file more unlikely.

Notice that there is now way to tell to editors they should ensure none it
does not leak any buffers, drop cores, and so on, when editing sensitive
data.  In short this change is addressing the issue only partially.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-08-05 09:58:25 +01:00
Sami Kerola 6766397932
include: move pamfail.h to auth.c
This removes one small header file, and makes inline function to static to
only file it is used in.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-08-05 09:58:18 +01:00
Karel Zak 6d53d1f99a Merge branch 'help' of https://github.com/rudimeier/util-linux
* 'help' of https://github.com/rudimeier/util-linux:
  setpriv: silence compiler warning
  misc: consolidate macro style USAGE_HELP_OPTIONS
  blockdev: correct man page name in --help
2017-07-10 10:15:22 +02:00
coastal-hiker 62f3e71597 last: condition (secs == 0) - now handled correctly
Changed comparison "if (secs > 0)" to "if (secs >= 0)" to handle
condition (secs == 0) correctly.  Suggestions to improve the
less-than-elegant if-else chain are welcome.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-10 10:03:41 +02:00
coastal-hiker e1787b1a85 last: don't show negative time
Under strange circumstances, the output of command 'last reboot'
showed the last time as a negative time, with both the hours and the
mins value having a minus sign. Example, taken from my workstation:

$last reboot
[...]
reboot   system boot  4.4.0-79-generic Wed Jun 14 09:20 - 07:33  (-1:-47)
[...]

I am aware this should happen only infrequently. Nevertheless, I
propose a more robust behaviour: show a minus sign only for the most
significant value (days or hours) and show the rest always as
positive. In the special case of ((secs < 0) && (secs >= -59)), print
mins as "-00".

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-10 10:02:38 +02:00
Karel Zak 1c8792f1ae login: use IPv4 on IPv4-mapping-to-IPv6
It seems that on some systems (e.g. RHEL7) the libc function
getaddrinfo() is not able to translate ::ffff: address to IPv4. The
result is 0.0.0.0 host address in the last(1) and utmpdump(1) output.

 /sbin/login -h "::ffff:192.168.1.7"

utmpdump:

  [7] [03926] [1   ] [user1   ] [pts/1       ] [::ffff:192.168.1.7  ] [0.0.0.0        ] [Thu May 12 17:49:50 2016    ]

Not sure if this is about order of the getaddrinfo() results, system
configuration or libc version. It's irrelevant for login(1). We have
to be robust enough to write usable address to log files everywhere.

The solution is to detect IPv4-mapping-to-IPv6 and use IPv4 for utmp.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1296233
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-04 13:03:08 +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 62cd916f1e login: add --help text
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-27 12:29:06 +02:00
Ruediger Meier b305445495 misc: consolidate all --help option descriptions
Now we are always using the same text also for commands
which had still hardcoded descriptions or where we can't
use the standard print_usage_help_options macro.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-27 12:28:36 +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
Ruediger Meier 6e1eda6f22 misc: never use usage(stderr)
Here we fix all cases where we have usage(FILE*)
functions.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-26 14:38:24 +02:00
Ruediger Meier 5118d1be2a misc: never use usage(ERROR)
We are using better/shorter error messages and somtimes
also errtryhelp().

Here we fix all cases where the usage function took
an int argument for exit_code.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-26 14:38:24 +02:00
Ruediger Meier 9325dbfd20 misc: cleanup and fix --unknownopt issues
Fixed checkusage.sh warnings:

  rtcwake: --unknownopt, non-empty stdout

  rtcwake: --unknownopt, stderr too long: 21
  blockdev: --unknownopt, stderr too long: 28
  lsipc: --unknownopt, stderr too long: 77
  pg: --unknownopt, stderr too long: 23
  renice: --unknownopt, stderr too long: 18
  sulogin: --unknownopt, stderr too long: 17
  write: --unknownopt, stderr too long: 12

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 7491906df6 login: add --help and --version
Also we don't print the usage text on stderr anymore.

Note, the usage text could be improved, currently it
does not describe any options. I have only added a
pointer to the man page.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-22 21:34:54 +02: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 a65041b5ae build-sys: make chown usage more robust
* add --disable-makeinstall-chown to travis non-root mode

* use "if MAKEINSTALL_DO_SETUID" for chown root:root

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-21 11:12:04 +02:00
Karel Zak 8c1979948c build-sys: chown before chmod for SUIDs
Make sure SUIDs are really owned by root.

Reported-by: L A Walsh <lkml@tlinx.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-20 13:12:43 +02:00
Sami Kerola b1557fe981 misc: fix ggc-7 fallthrough warnings
(Original patch and commit message edited by Rudi.)

gcc-7 adds -Wimplicit-fallthrough=3 to our default flag -Wextra.
This warning can be silenced by using comment /* fallthrough */
which is also recognized by other tools like coverity. There are
also other valid comments (see man gcc-7) but we consolidate this
style now.

We could have also used __attribute__((fallthrough)) but the comment
looks nice and does not need to be ifdef'ed for compatibility.

Reference: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=7652
Reference: https://developers.redhat.com/blog/2017/03/10/wimplicit-fallthrough-in-gcc-7/
Reviewed-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Suggested-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-06-14 11:48:22 +02:00
Ruediger Meier f64ddc95f3 misc: fix gcc-7 sprintf warnings -Wformat-overflow
../login-utils/last.c: In function ‘main’:
../login-utils/last.c:624:23: warning: ‘%s’ directive writing up to 31 bytes into a region of size 27 [-Wformat-overflow=]
   sprintf(path, "/dev/%s", ut->ut_line);
                       ^~   ~~
../login-utils/last.c:624:3: note: ‘sprintf’ output between 6 and 37 bytes into a destination of size 32
   sprintf(path, "/dev/%s", ut->ut_line);

../libblkid/src/devname.c: In function 'probe_one':
../libblkid/src/devname.c:166:29: warning: '%s' directive writing up to 255 bytes into a region of size 245 [-Wformat-overflow=]
   sprintf(path, "/sys/block/%s/slaves", de->d_name);
                             ^~
../libblkid/src/devname.c:166:3: note: 'sprintf' output between 19 and 274 bytes into a destination of size 256
   sprintf(path, "/sys/block/%s/slaves", de->d_name);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-14 11:48:22 +02:00
Karel Zak 5f032ae4bb chsh: cleanup global_shells usage
* global variables are always initialized by NULL
* it seems we need it as global variable due to libreadline, then use it as
  global everywhere in the same .c file.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-05 13:29:20 +02:00
Karel Zak 54373fb9b9 chsh: split get_shell_list()
Let's use two functions is_known_shell() and print_shells() to make
the code more readable and to avoid complex semantic of the original
get_shell_list().

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-05 13:15:59 +02:00
Sami Kerola d1818b9e12 chsh: make readline completion to propose valid shells
This is better than default readline completion, that gives paths from
current directory onwards.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-06-05 12:58:52 +02:00
Ruediger Meier f2ff0adf5d misc: fix some warnings
sys-utils/prlimit.c: In function 'do_prlimit':
sys-utils/prlimit.c:367:16: warning: format '%ju' expects argument of type 'uintmax_t', but argument 2 has type 'rlim_t {aka long long unsigned int}' [-Wformat=]
     printf("<%ju", new->rlim_cur);

lib/plymouth-ctrl.c: In function 'open_un_socket_and_connect':
lib/plymouth-ctrl.c:88:20: warning: passing argument 2 of 'connect' from incompatible pointer type [-Wincompatible-pointer-types]
  ret = connect(fd, &su, offsetof(struct sockaddr_un, sun_path) + 1 + strlen(su.sun_path+1));
                    ^
In file included from lib/plymouth-ctrl.c:35:0:
/usr/include/sys/socket.h:314:5: note: expected 'const struct sockaddr *' but argument is of type 'struct sockaddr_un *'
 int connect (int, const struct sockaddr *, socklen_t);

login-utils/last.c: In function 'list':
login-utils/last.c:506:54: warning: pointer targets in passing argument 4 of 'dns_lookup' differ in signedness [-Wpointer-sign]
   r = dns_lookup(domain, sizeof(domain), ctl->useip, p->ut_addr_v6);
                                                      ^
login-utils/last.c:291:12: note: expected 'int32_t * {aka int *}' but argument is of type 'unsigned int *'
 static int dns_lookup(char *result, int size, int useip, int32_t *a)
            ^~~~~~~~~~

In file included from sys-utils/hwclock-cmos.c:92:0:
sys-utils/hwclock.h:67:32: warning: 'struct timeval' declared inside parameter list will not be visible outside of this definition or declaration
 extern double time_diff(struct timeval subtrahend, struct timeval subtractor);

misc-utils/test_uuidd.c: In function 'create_nthreads':
misc-utils/test_uuidd.c:187:19: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
        proc->pid, (int) th->tid, th->index));

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-01 10:28:18 +02:00
Sami Kerola 36b608417b chfn: disable tab completion
The default readline tab completion that offers file listing from current
directory does not make any sense in this context.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-05-19 11:43:34 +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 dd732fa251 nologin: don't call fstat() after failed open() [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-17 12:59:33 +02:00
Sami Kerola 90936fafb4 su: remove duplicate const declaration
login-utils/su-common.c:619:14: warning: duplicate 'const' declaration
specifier [-Wduplicate-decl-specifier]
   const char const **args = xcalloc (n_args, sizeof *args);

Regression-from: 71f207a5f5
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-05-16 14:55:32 +02:00
Karel Zak b8af37d767 build-sys: remove duplicate includes
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-12 11:17:02 +02:00
Sami Kerola 6c9f102f3e vipw: use getopt_long() to parse options
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-05-10 10:53:28 +02:00
Karel Zak 626aa65180 sulogin: add missing type
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-09 11:59:53 +02:00
Sami Kerola e41ae45093
chfn, chsh: use readline(3) to receive user input
The readline offers editing capabilities while the user is entering the
line, unlike fgets(3) and getline(3) that were used earlier.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-05-02 23:22:05 +01:00
Sami Kerola 71f207a5f5
sulogin: reduce vulnerability surface
Hopefully these changes are unreachable code, but better safe than sorry
when dealing with setuid root code that is installed everywhere.  Quite
obviously the introduced abort() calls protect from impossible inputs.

Secondly set all possible data to be read-only in attempt to make it more
difficult to alter anything at all.

Reference: https://www.securecoding.cert.org/confluence/display/c/DCL00-C.+Const-qualify+immutable+objects
Reviewed-by: Petr Vorel <petr.vorel@gmail.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-05-02 23:22:04 +01:00
Sami Kerola 34a9766b0e utmpdump: remove unnecessary variable
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-03-31 12:58:13 +02:00
Karel Zak bd2aece45e last: use domain string more carefully
Use xstrcpy() to explicitly terminate the domain string.

Reported-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-03-13 12:55:44 +01:00
Tobias Stoeckmann b0f97de5a4 login: prevent OOB read on illegal /etc/hushlogins
If the file /etc/hushlogins exists and a line starts with '\0', the
login tools are prone to an off-by-one read.

I see no reliability issue with this, as it would clearly need a
hostile action from a system administrator. But for the sake of
correctness, I've sent this patch nonetheless.
2017-03-13 12:46:49 +01:00
Sami Kerola 2ba641e5f3 misc: add static keyword to where needed [smatch scan]
text-utils/rev.c:68:9: warning: symbol 'buf' was not declared. Should it be
static?

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-20 12:58:49 +01:00
Sami Kerola 8791804065 misc: do not use plain 0 as NULL [smatch scan]
text-utils/tailf.c:69:21: warning: Using plain integer as NULL pointer

Since many 'struct option' has used zero as NULL make them more readable in
same go by reindenting, and using named argument requirements.

Reference: https://lwn.net/Articles/93577/
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-20 12:58:49 +01:00
Yuri Chornoivan a7349ee315 docs: Fix word repetitions 2017-02-13 14:10:12 +01:00
Sami Kerola b72a75e993
lib: add timegm() portability function to lib/timeutils.c
Local timegm() is a replacement function in cases it is missing from libc
implementation.  Hopefully the replacement is never, or very rarely, used.

CC: Ruediger Meier <ruediger.meier@ga-group.nl>
Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-03 22:31:18 +00:00
Karel Zak dffab154d2 su: properly clear child PID
Reported-by: Tobias Stöckmann <tobias@stoeckmann.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-01 11:58:09 +01:00
Karel Zak 344d861d83 Merge branch 'shadow-man' of https://github.com/andhe/util-linux
* 'shadow-man' of https://github.com/andhe/util-linux:
  chsh: use -h as shorthand for --help instead of -u
  man: chsh(1): add login.defs to SEE ALSO
  man: chfn(1): add chsh and login.defs to SEE ALSO
2017-01-20 13:12:57 +01:00
Karel Zak 37410713b2 su, runuser: fix typo in the /etc/default path
Reported-by: Andreas Henriksson <andreas@fatal.se>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-01-20 11:02:23 +01:00
Andreas Henriksson 631a195412 chsh: use -h as shorthand for --help instead of -u
The -u is still supported (but no longer documented).

(This matches the switches used by shadow chsh.)
2017-01-19 23:11:42 +01:00
Andreas Henriksson d0f9990bfb man: chsh(1): add login.defs to SEE ALSO
(The shadow equivalent manpage lists it.)
2017-01-19 22:52:57 +01:00
Andreas Henriksson 4c49db948a man: chfn(1): add chsh and login.defs to SEE ALSO
(The shadow version of the same manpage mentions these utils,
but does not mention finger.)
2017-01-19 22:52:57 +01:00
Karel Zak 281873b874 runuser: add "--" to SYNOPSIS
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-01-19 12:04:05 +01:00
Sami Kerola 78acfddd1d
last: use --time-format instruction when printing wtmp creation time
This makes --time-format=iso timestamp to look the same as login/logout
times.  When --time-format=noformat is used the file creation time not
printed.  There is no change to default format.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-01-16 22:31:36 +00:00
Sami Kerola 875834381d newgrp: use libc explicit_bzero() when it is available
This currently new function will be part of glibc 2.25.

Reference: https://sourceware.org/git/?p=glibc.git;a=commit;h=ea1bd74defcf9d5291d14972e63105168ca9eb4f
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-01-16 12:30:09 +01:00
Karel Zak 5d74cf0092 lib/list: remove LIST_HEAD macro
* the variable definition with hidden type is always horrible, for
  example:

	  int func() {
	    LIST_HEAD(foo);
	    ...
	  }

  the more readable is:

          int func() {
            struct list_head foo;

            INIT_LIST_HEAD(&foo);
            ...
          }

* the name LIST_HEAD conflict with /usr/include/sys/queue.h

* we use it only on two places in sulogin

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-01-05 11:54:59 +01: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
Sébastien Helleu d673b74e9d docs: replace FTP by HTTPS in kernel.org URLs
The links to ftp://ftp.kernel.org/ are replaced by
https://www.kernel.org/.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-12-19 11:22:26 +01:00
Michael Kerrisk fd17733fcb docs: last(1): Eliminate oddball formatting
\s-2...\s0 is unused anywhere else. Remove it.

Signed-off-by: Michael Kerrisk <mtk.man-pages@gmail.com>
2016-12-09 13:45:09 +01:00
Michael Kerrisk 22a1c10ba1 docs: last(1): SEE ALSO: add reference to wtmp(5)
Signed-off-by: Michael Kerrisk <mtk.man-pages@gmail.com>
2016-12-09 13:45:09 +01:00
Michael Kerrisk aedd46f66e docs: various pages: Use consistent terminology (set-user-ID and set-group-ID)
Use consistent terminology for set-user-ID and set-group-ID bits.

There's much inconsistency in the pages. "suid",
"set-user-identifier", "setuid". Stick with one terminology,
"set-user-ID" and set-grout-ID, as suggested in man-pages(7).

Signed-off-by: <mtk.man-pages@gmail.com>
2016-12-09 13:45:09 +01:00
Michael Kerrisk 46f057ed37 docs: various pages: Format pathnames as italic (.I)
In the majority of pages, pathnames are formatted as Italic,
which is the norm. However, there are several cases where they
are formatted as bold. This patch fixes a number of those
exceptions.

Signed-off-by: Michael Kerrisk <mtk.man-pages@gmail.com>
2016-12-09 13:45:09 +01:00
Andreas Henriksson 1c4b2d4392 sulogin: bail out from getpasswd(...) on timeout
If timeout happens while waiting in prompt, bail out instead
of retrying.

Reported-by: Bjørn Mork <bjorn@mork.no>
Addresses: http://bugs.debian.org/846107
Signed-off-by: Andreas Henriksson <andreas@fatal.se>
2016-12-07 13:32:42 +01:00
Andreas Henriksson 60dea9d187 sulogin: make getpasswd(...) return NULL on ^D
This makes the caller bail out early instead of evaluating the
input as a password.

Reported-by: Bjørn Mork <bjorn@mork.no>
Addresses: http://bugs.debian.org/846112
Signed-off-by: Andreas Henriksson <andreas@fatal.se>
2016-12-07 13:32:42 +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 6578ced75c login: re-add lastlog.h header
This include was removed in a365953a but we will need it again
when we move from utmp.h to utmpx.h.

On Linux (glibc, musl) the struct lastlog is defined in utmp.h
and lastlog.h just includes utmp.h.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>

Conflicts:
	login-utils/login.c

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-12-07 12:35:24 +01:00
Ruediger Meier a924b4004c login-utils: avoid using the defined utmp sizes.
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-12-07 12:35:24 +01:00
Ruediger Meier f718c2fc7f utmpdump: code formatting for readability
BTW avoid using the defined sizes.

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
Ruediger Meier 55771f5409 login-utils: remove _HAVE_UT_TV fallback
_HAVE_UT_TV is glibc only. Moreover we want to move to utmpx where
timeval is standard.

Now utmp/subsecond (1173d0a6) should work on all supported systems.

CC: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-12-07 12:35:24 +01:00
Ruediger Meier c6ba16c6a4 last: include libgen.h for basename(3p)
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-12-07 12:35:24 +01:00
Ruediger Meier 223939d95b misc: spelling, always use "cannot" instead of "can not"
Just to be consistent ...

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-11-30 14:56:50 +01:00
Michael Kerrisk (man-pages) 42632a90c1 Correctly format page cross references
Most pages in util-linux follow the standard convention
of formatting page cross references in bold. Fix the
few exceptions that use italic.

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2016-11-29 10:44:19 +01:00
Michael Kerrisk (man-pages) f053ff1e3a Place SEE ALSO entries in order
This patch does only the following:

* Order SEE ALSO entries first by section name, then alphabetically
  within section
* Adds one or two missing commas in SEE ALSO lists
* Removes one or two periods that were (inconsistently) used
  at the end of SEE ALSO lists.

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2016-11-29 10:44:19 +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
Karel Zak 23f7509326 Revert "su,runuser: add libseccomp based workaround for TIOCSTI ioctl"
This reverts commit 8e49250168.

Stupid hack...
2016-10-03 16:56:56 +02:00
Karel Zak 8e49250168 su,runuser: add libseccomp based workaround for TIOCSTI ioctl
This patch add libseccomp based syscalls filter to disable TIOCSTI
ioctl in su/runuser children.

IMHO it is not elegant solution due to dependence on libseccomp
(--without-seccomp if hate it)... but there is nothing better for now.

Addresses: CVE-2016-2779
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-09-29 16:32:33 +02:00
Karel Zak c424fd834b su, runuser, setpriv: create links between man pages
.. and add notes about differences between the utuils.

Reported-by: Lennart Poettering <lennart@poettering.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-18 11:12:44 +02:00
Karel Zak 05d8868d86 include/env: minor fixes and clean ups
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-16 12:35:57 +02:00
Sami Kerola 984a60965a
misc: always check setenv(3) return value
At least glibc setenv(3) can fail when system runs out of memory.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-08-12 21:25:36 +01: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
Sami Kerola 74ce680a3e
misc: simplify if clauses [oclint]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-21 21:14:33 +01:00
Karel Zak 85a37ca8d1 Merge branch 'write-improvements' of git://github.com/kerolasa/lelux-utiliteetit
* 'write-improvements' of git://github.com/kerolasa/lelux-utiliteetit:
  lib: try to find tty in get_terminal_name()
  write: stop removing and adding /dev/ in front of tty string
  write: tell when effective gid and tty path group mismatch
  write: improve coding style
  write: remove PUTC macro
  write: make timestamp to be obviously just a clock time
  write: remove unnecessary utmp variables
  write: improve function and variable names
  write: add control structure to clarify what is going on
  write: run atexit() checks at the end of execution
  write: use xstrncpy() from strutils.h
  write: set atime value in term_chk() only when needed
  write: remove pointless fileno(3) calls
  write: get rid of function prototypes
  write: remove unused variable
2016-07-14 13:07:25 +02:00
Sami Kerola b236e43ef0 sulogin: remove __nonnull__ function attribute
This change fixes compiler option -Werror=nonnull option warning:

login-utils/sulogin-consoles.c: In function 'append_console':
login-utils/sulogin-consoles.c:324:14: warning: nonnull argument 'consoles'
compared to NULL [-Wnonnull-compare]

The NULL check done with list_empty() looks valid, so  it is best to remove
the function attribute that allows compiler to optimize the check away.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-14 12:28:53 +02:00
Sami Kerola 285c1f3a3e
lib: try to find tty in get_terminal_name()
Try all standard terminal input/output file descriptors when finding tty
name in get_germinal_name().  This should make all invocations of the
function as robust as they can get.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-03 23:35:10 +01:00
Sami Kerola 3d47107de5
docs: add file format note to utmpdump manual page
Tell that the old textual format that does not use full utmp time precision,
and has issues with timezones.  Warn also that the textual format may become
incompatible, although there are no plans in foreseeable future to do so.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-06-27 20:40:37 +01:00
Sami Kerola 1173d0a6bf
utmpdump: use iso-8601 timestamp format with subsecond accuracy
Newer 'struct utmp' is using 'struct timeval' to represent login and logout
times, so include the maximum accuracy to textual utmp format.  Notice that
this change does not remove support of converting earlier textual formats
back to binary.  But conversions from binary to former format will no longer
be available.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-06-26 21:58:18 +01:00
Sami Kerola 3749bdcecf
utmpdump: use always UTC-0 timezone in textual output
Converting a time structure from text format that has timezone markup is
practically impossible.  See reference links for more information.  This
leads to situation where multiple utmpdump(1) conversions from binary to
text and back make timestamps to shift amount of timezone offset to UTC-0.

The easiest way to make multiple conversions to work without timeshifts is
to always use UTC-0 timezone.  Downside of this approach is that the textual
format is less human readable than local timestamps would be.

Reference: http://www.catb.org/esr/time-programming/#_strptime_3_and_getdate_3
Reference: http://man7.org/linux/man-pages/man3/strptime.3.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-06-26 21:58:18 +01:00
Karel Zak dd5ef107ad chfn: chsh: use selinux_check_passwd_access()
* selinux/av_permissions.h and magic constants are deprecated, the
  recommended solution is to use string_to_security_class() and
  string_to_av_perm() to get access vector

* it also seems that selinux_check_passwd_access() does exactly the
  same as our checkAccess(), let's use it.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-06-14 13:38:13 +02: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
Sebastian Rasmussen d35df4db5b docs: Fix various typos
Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
2016-05-31 23:40:21 +02:00
Karel Zak 1eb16fd780 build-sys: add --disable-plymouth-support
The plymouth support depends on Linux specific SOCK_* flags and all
the feature is probably unnecessary in some cases (non-plymouth
distros, etc.)

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-26 15:08:53 +02:00
Karel Zak c4482f7b3b last: fix logout time
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-24 14:08:57 +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
Karel Zak c7eb14d325 last: cleanup time formatting code
- describe difference between login and logout time formats in struct last_timefmt
- use strtime_iso()
- rename LAST_TIMEFTM_SHORT_CTIME to LAST_TIMEFTM_SHORT
- rename LAST_TIMEFTM_FULL_CTIME to LAST_TIMEFTM_CTIME
- add LAST_TIMEFTM_HHMM for internal purpose (logout format for "--time-format short")

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-24 11:07:08 +02:00
Werner Fink fe3f7e17aa sulogin: agetty: use the plymouth local protocol instead the plymouth binary
for stopping plymouthd.  That do not depend on the existence of
the plymouth binary if it e.g. becomes uninstalled or an other
service is providing plymouthd facilities.

[kzak@redhat.com: - fix compiler warnings [-Wpointer-sign]
                  - use sizeof() for write_all()
                  - cast to char* for read_all]

Signed-off-by: Werner Fink <werner@suse.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-20 11:21:10 +02:00
Sami Kerola 31af559e30
setpwnam: fix memory leak
Found with scan-build.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-04-19 21:27:54 +01:00
Sami Kerola 400423824a
sulogin: make fopen O_CLOEXEC specifier usage portable
The close at exit specifier "e" is glibc extension, so use it only if when
the extension is available.

Proposed-by: Ruediger Meier <sweet_f_a@gmx.de>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-04-16 23:09:26 +01:00