summaryrefslogtreecommitdiffstats
path: root/login-utils/login.c
Commit message (Collapse)AuthorAgeFilesLines
* login: simplify string handlingSami Kerola2019-07-241-4/+1Star
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* login: retire use of __FUNCTION__ macroKarel Zak2019-05-271-4/+3Star
| | | | | | | | | | | | | | 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>
* misc: consolidate version printing and close_stdout()Karel Zak2019-04-161-2/+1Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* login: add support for login.defs(5) LASTLOG_UID_MAXKarel Zak2019-01-111-0/+3
| | | | | | | | | | 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>
* login: cleanup code to copy to log stringsKarel Zak2018-10-031-12/+12
| | | | | | | | 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>
* login: use const qualifier for username from PAM or struct passwd [-Wcast-qual]Karel Zak2018-07-231-6/+11
| | | | | | | | | 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>
* login: add LOGIN_PLAIN_PROMPT to login.defsKarel Zak2017-12-041-3/+9
| | | | | | | | | | | 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>
* login-utils: use free_getlogindefs_data()Karel Zak2017-11-281-0/+2
| | | | | | | 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>
* login: fix signal raceTobias Stoeckmann2017-09-261-7/+12
| | | | | | | | | | | 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>
* login: add xgetpwnam()Karel Zak2017-09-181-24/+5Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* login: use IPv4 on IPv4-mapping-to-IPv6Karel Zak2017-07-041-1/+8
| | | | | | | | | | | | | | | | | | | | | 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>
* login: add --help textRuediger Meier2017-06-271-0/+8
| | | | Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* login: add --help and --versionRuediger Meier2017-06-221-6/+22
| | | | | | | | | | 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>
* login-utils: switch to utmpx.hRuediger Meier2016-12-071-15/+15
| | | | | | | | 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>
* login: re-add lastlog.h headerRuediger Meier2016-12-071-0/+3
| | | | | | | | | | | | | | | 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>
* login-utils: remove _HAVE_UT_TV fallbackRuediger Meier2016-12-071-19/+0Star
| | | | | | | | | | _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>
* include/env: minor fixes and clean upsKarel Zak2016-08-161-3/+4
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: always check setenv(3) return valueSami Kerola2016-08-121-8/+11
| | | | | | At least glibc setenv(3) can fail when system runs out of memory. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* lib: try to find tty in get_terminal_name()Sami Kerola2016-07-041-1/+1
| | | | | | | | 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>
* misc: Fix various typosSebastian Rasmussen2016-05-311-2/+2
| | | | | | | Fix various typos in error messages, warnings, debug strings, comments and names of static functions. Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
* include: move sys/sysmacros.h to c.hKarel Zak2016-03-081-3/+0Star
| | | | | | | 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>
* misc: never cast void* from malloc(3) and friendsRuediger Meier2016-03-071-1/+1
| | | | | | | | | | 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>
* misc: safer (and uniform) handling of return valueYuriy M. Kaminskiy2016-03-071-1/+1
| | | | | | When `rc` is `INT_MAX`, `rc + 1` result in signed integer overflow. Signed-off-by: Karel Zak <kzak@redhat.com>
* login-utils: minor utmp cleanupRuediger Meier2016-02-291-1/+0Star
| | | | | | | - 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>
* include: check for sys/sysmacros.hRuediger Meier2016-02-181-0/+2
| | | | Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* docs: fix typos found by codespellRuediger Meier2016-02-031-1/+1
| | | | | | Using "codespell" from https://github.com/lucasdemarchi/codespell Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* login, mount: fix __SC_GETPW_R_SIZE_MAX usageKarel Zak2015-12-151-10/+2Star
| | | | | | | | | | 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>
* login: fix stat(2) raceSami Kerola2015-11-091-4/+2Star
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* login: replace siginterrupt with sigactionChen Qi2015-08-311-1/+4
| | | | | | [kzak@redhat.com: - POSIX.1-2008 marks siginterrupt() as obsolete] Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
* login: fix mem leak in init_environ() [coverity scan]Karel Zak2015-01-291-3/+5
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* textual: add a docstring to most of the utilitiesBenno Schulenberg2015-01-061-0/+2
| | | | | | | | | 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>
* login: Fix unused variables in login.c if _HAVE_UT_TV isn't definedWill Johansson2014-12-181-0/+2
| | | | | | | | | 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>
* login-utils: Enable building util-linux against OpenPAMWill Johansson2014-12-151-4/+13
| | | | | | | | | | 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>
* login: ignore SIGXFSZ when write to lastlogKarel Zak2014-11-191-2/+11
| | | | | | | | 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>
* Fix typo "ioclt" in various files.Lauri Nurmi2014-07-111-1/+1
|
* lslogins: add functionalityOndrej Oprala2014-05-151-1/+1
| | | | Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
* login: extract get_hushlogin_statusOndrej Oprala2014-05-151-118/+0Star
| | | | Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
* docs: improve grammar and consistency of comments in login.cBenno Schulenberg2013-06-071-85/+77Star
| | | | Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* textual: standardize synopsis for login, and improve an error messageBenno Schulenberg2013-06-071-2/+2
| | | | Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* login: use TCSANOW to remove HUPCLKarel Zak2013-06-051-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* lib/tty: don't hardcode terminal fd in get_terminal_name()Karel Zak2013-05-131-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* login: check returns [coverity scan]Karel Zak2013-03-271-6/+5Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* login: remove file descriptor leak [cppcheck]Sami Kerola2013-03-041-1/+3
| | | | | | [login-utils/login.c:510]: (error) Resource leak: fd Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* login: check lastlog lseek return code [coverity scan]Karel Zak2012-12-121-1/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* login: use get_terminal_name() from ttyutils.cKarel Zak2012-11-221-14/+2Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* login: fix compiler warning [-Wunused-result]Karel Zak2012-10-221-6/+10
| | | | | | | 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>
* login: stop using MAXHOSTNAMELENKarel Zak2012-10-191-4/+4
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* login: reuse DEAD_PROCESS utmp entriesKarel Zak2012-10-051-3/+11
| | | | | Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=858009 Signed-off-by: Karel Zak <kzak@redhat.com>
* login: close tty before vhangup()Karel Zak2012-07-121-0/+8
| | | | | | | 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>
* docs: fix typos found by misspellingsBernhard Voelker2012-07-091-2/+2
| | | | | | | | | | | | | | | | | | 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>