Commit Graph

160 Commits

Author SHA1 Message Date
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 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
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 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
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 075d2c0754 include: move sys/sysmacros.h to c.h
The file is no portable (#ifdef HAVE_SYS_SYSMACROS_H is necessary),
but needed on many places. It seems better to keep it in c.h.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-03-08 14:29:45 +01:00
Ruediger Meier fea1cbf748 misc: never cast void* from malloc(3) and friends
Such cast could hide serious compiler warnings in case we are
missing includes (e.g. <stdlib.h> or "xalloc.h").

See
http://stackoverflow.com/questions/605845/do-i-cast-the-result-of-malloc

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-07 23:29:27 +01: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
Ruediger Meier a365953a24 login-utils: minor utmp cleanup
- consistently use ut->ut_user instead of ut->ut_name
- don't include obsolete lastlog.h BSD header

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-29 13:05:06 +01:00
Ruediger Meier 66daee0765 include: check for sys/sysmacros.h
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-18 16:54:17 +01:00
Ruediger Meier 3fd1f7711e docs: fix typos found by codespell
Using "codespell" from https://github.com/lucasdemarchi/codespell

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-03 15:10:08 +01:00
Karel Zak f7ac9e71b1 login, mount: fix __SC_GETPW_R_SIZE_MAX usage
sysconf(_SC_GETPW_R_SIZE_MAX) returns initial suggested size for pwd
buffer (see getpwnam_r man page or POSIX). This is not large enough in
some cases.

Yes, this sysconf option is misnamed (should be _SC_GETPW_R_SIZE_MIN).

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-12-15 12:33:34 +01:00
Sami Kerola a64e268224 login: fix stat(2) race
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-11-09 09:56:14 +01:00
Chen Qi 1b76608ef8 login: replace siginterrupt with sigaction
[kzak@redhat.com: - POSIX.1-2008 marks siginterrupt() as obsolete]

Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
2015-08-31 11:34:36 +02:00
Karel Zak 86cf1ff42a login: fix mem leak in init_environ() [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-29 11:25:07 +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
Will Johansson ecc5632f09 login: Fix unused variables in login.c if _HAVE_UT_TV isn't defined
Wrap around the variable declaration for `tv' with ifdef so the compilers
don't warn about unused variables if we're compiling without UT_TV. This
happens with the musl libc, since it doesn't define _HAVE_UT_TV, even
though it _does_ have the ut_tv field in the utmp struct.

Signed-off-by: Will Johansson <will.johansson@gmail.com>
2014-12-18 11:02:08 +01:00
Will Johansson fe2c9909cd login-utils: Enable building util-linux against OpenPAM
OpenPAM is compatible with util-linux, with a few changes, namely
using OpenPAM's conversation function, openpam_ttyconv.

We check for Linux-PAM by querying for security/pam_misc.h, and OpenPAM
by querying for security/openpam.h.

Signed-off-by: Will Johansson <will.johansson@gmail.com>
2014-12-15 10:16:03 +01:00
Karel Zak 6f7eba20af login: ignore SIGXFSZ when write to lastlog
the lastlog file is huge and on systems with large UIDs, it's so huge that
it generates SIGXFSZ when the FSIZE limit is too small.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1165702
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-19 15:45:42 +01:00
Lauri Nurmi a5c523a0e7 Fix typo "ioclt" in various files. 2014-07-11 22:52:09 +03:00
Ondrej Oprala 29cc2a5568 lslogins: add functionality
Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
2014-05-15 13:55:59 +02:00
Ondrej Oprala 78dd745089 login: extract get_hushlogin_status
Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
2014-05-15 13:55:59 +02:00
Benno Schulenberg 80591bf61e docs: improve grammar and consistency of comments in login.c
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2013-06-07 11:31:43 +02:00
Benno Schulenberg 63578526a1 textual: standardize synopsis for login, and improve an error message
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2013-06-07 11:31:33 +02:00
Karel Zak c5bb244ea3 login: use TCSANOW to remove HUPCL
Fedora 19, kernel 3.9, systemd 204, telnetd with socket activation.

login(1) code:

        ttt.c_cflag &= ~HUPCL;
        tcsetattr(0, TCSAFLUSH, &ttt);

        close(STDIN_FILENO);
        close(STDOUT_FILENO);
        close(STDERR_FILENO);

        signal(SIGHUP, SIG_IGN);        /* so vhangup() wont kill us */
        vhangup();
        signal(SIGHUP, SIG_DFL);

strace :

	ioctl(0, SNDCTL_TMR_CONTINUE or SNDRV_TIMER_IOCTL_GPARAMS or TCSETSF, {B9600 opost isig icanon echo ...}) = 0
	close(0)                                = 0
	close(1)                                = 0
	close(2)                                = 0
	--- SIGHUP {si_signo=SIGHUP, si_code=SI_KERNEL} ---
	--- SIGTERM {si_signo=SIGTERM, si_code=SI_USER, si_pid=1, si_uid=0} ---
	+++ killed by SIGTERM +++

It seems we get SIGHUP (and SIGTERM from systemd) before vhangup().
The problem occur sometimes.

I guess it's because TCSAFLUSH is not applied immediately, so it would
be probably better to use TCSANOW to make the code more robust.

References: https://bugzilla.redhat.com/show_bug.cgi?id=962145
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-06-05 14:43:21 +02:00
Karel Zak 507341f832 lib/tty: don't hardcode terminal fd in get_terminal_name()
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-05-13 15:40:57 +02:00
Karel Zak 7488d4c068 login: check returns [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-03-27 14:13:00 +01:00
Sami Kerola 747168d444 login: remove file descriptor leak [cppcheck]
[login-utils/login.c:510]: (error) Resource leak: fd

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-03-04 12:28:34 +01:00
Karel Zak 83d02ed293 login: check lastlog lseek return code [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-12-12 11:49:46 +01:00
Karel Zak 70aaa7308b login: use get_terminal_name() from ttyutils.c
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-22 14:42:10 +01:00
Karel Zak b8ac29e80f login: fix compiler warning [-Wunused-result]
It's probably unnecessary paranoia, but let's check if we're able to
restore the original IDs after ~/.hushlogin file check.

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-10-22 13:13:02 +02:00
Karel Zak f0196a13af login: stop using MAXHOSTNAMELEN
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-10-19 16:27:29 +02:00
Karel Zak 98193daa8c login: reuse DEAD_PROCESS utmp entries
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=858009
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-10-05 12:07:10 +02:00
Karel Zak 2e7035646e login: close tty before vhangup()
Let's close all tty file descriptors before vhangup() call.

References: https://lkml.org/lkml/2012/6/5/145
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-07-12 16:35:01 +02:00
Bernhard Voelker 7007991f6f docs: fix typos found by misspellings
The tool misspellings (https://github.com/lyda/misspell-check)
detected several typos. Command used:

  $ git ls-files | grep -v ^po/ | misspellings -f -

* Documentation/releases/v2.18-ReleaseNotes: Fix typo in news entry.
* NEWS: Likewise.
* config/texinfo.tex: Fix typo in comments.
* libmount/src/context.c: Fix typo in comment.
* libmount/src/fs.c: Likewise.
* login-utils/login.c: Likewise.
* login-utils.su.1: Fix typo in man page.
* sys-utils/chcpu.c: Fix typo in error message.

Signed-off-by: Bernhard Voelker <mail@bernhard-voelker.de>
2012-07-09 16:56:30 +02:00
Karel Zak 7d18972b00 login: fix compiler warning [-Wsign-compare]
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-05 16:59:54 +02:00
Sami Kerola 10b3219a5f login: allow TTYGROUP name begin by number
Assuming someone is using a TTYGROUP name beginnign by a digit the
login was misbehaving with 'contains invalid numerical value: %s'
message(s) in syslog.  Please notice that group names that consist
only digits as characters are valid (but likely to cause confusion,
and chaos).

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-06-02 15:10:28 +02:00
Sami Kerola c9baf5da86 logindefs: change getlogindefs_num() to return unsigned long
Where ever getlogindefs_num() is called return value is always
expected to be unsigned, such as sleep() input, gid_t or mode_t.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-06-02 11:57:42 +02:00
Thomas Schwinge cd8c4d033b login: Include <linux/major.h> only if it exists.
It isn't required on non-Linux systems.

Signed-off-by: Thomas Schwinge <thomas@codesourcery.com>
2012-05-29 10:11:35 +02:00
Karel Zak d4cba553f9 login: fix segmentation fault in log_utmp
ctx->tty_number is optional...

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=822705
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-05-21 09:58:42 +02:00
Petr Uzel e12c9866b5 include: rename writeall.h to all-io.h
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
2012-05-15 11:32:27 +02:00
Karel Zak 5759de0c3c login: use get_fd_tabsize()
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-04-23 14:00:29 +02:00
chas williams - CONTRACTOR 1061081619 login: use getdtablesize() correctly in login.c
getdtablesize() is the number of descriptors and since decriptors start
at 0, its value isnt the largest descriptors possible.  One should use
getdtablesize() - 1 instead.

Signed-off-by: Chas Williams - CONTRACTOR <chas@cmf.nrl.navy.mil>
2012-04-23 13:33:00 +02:00
Bernhard Voelker 455fe9a075 Fix typos found by misspellings
The tool misspellings (https://github.com/lyda/misspell-check)
detected several typos. Command used:

  $ git ls-files | grep -v ^po/ | misspellings -f -

* isosize: Fix typo in usage string.
* configure.ac: Fix typo in help string of --enable-most-builds option.
* fdisk: Fix typo in man page.
* libblkid, blkid, mount: Likewise.
* Fix various typos in docs and in source code comments.

Signed-off-by: Bernhard Voelker <mail@bernhard-voelker.de>
2012-04-23 13:16:35 +02:00
Dave Reisner fed52fd5ca login: add USER to initial environment
Add this value from the passwd struct to the environment, as it is
expected by shells, and generally useful to users.

This also clarifies a poorly worded sentence in the vicinity of the
manpage change.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-03-13 12:24:25 +01:00
Karel Zak 2f595c001b login: fix LOGIN_CHOWN_VCS code
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-03-05 16:48:38 +01:00
Karel Zak 607e6b7ce8 login: support crazy shadow-utils syntax in login.defs
standard syntax for FOO=data:

	ENV_FOO   data

additional syntax:

	ENV_FOO  FOO=data

Reported-by: Colin Guthrie colin@mageia.org
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-02-28 11:16:16 +01:00
Karel Zak fab1f6717e login: add LOGIN_RETRIES, cleanup retries check code
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-02-10 14:47:59 +01:00