summaryrefslogtreecommitdiffstats
path: root/login-utils/chsh.c
Commit message (Collapse)AuthorAgeFilesLines
* misc: consolidate version printing and close_stdout()Karel Zak2019-04-161-3/+2Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* chsh: remove local /etc/shells parsing in favour of getusershell(3)Sami Kerola2017-08-301-80/+18Star
| | | | | | | 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>
* misc: consolidate macro style USAGE_HELP_OPTIONSRuediger Meier2017-06-291-1/+1
| | | | | | | | | 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>
* misc: consolidate all --help option descriptionsRuediger Meier2017-06-271-2/+2
| | | | | | | | 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>
* misc: never use usage(stderr)Ruediger Meier2017-06-261-5/+7
| | | | | | | Here we fix all cases where we have usage(FILE*) functions. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* misc: remove superfluous null pointer checks for optargRuediger Meier2017-06-221-2/+0Star
| | | | | | This is only needed for optional arguments. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* chsh: cleanup global_shells usageKarel Zak2017-06-051-26/+39
| | | | | | | | * 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>
* chsh: split get_shell_list()Karel Zak2017-06-051-18/+25
| | | | | | | | 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>
* chsh: make readline completion to propose valid shellsSami Kerola2017-06-051-27/+90
| | | | | | | This is better than default readline completion, that gives paths from current directory onwards. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* chfn, chsh: use readline(3) to receive user inputSami Kerola2017-05-031-3/+12
| | | | | | | 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>
* misc: do not use plain 0 as NULL [smatch scan]Sami Kerola2017-02-201-6/+6
| | | | | | | | | | 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>
* chsh: use -h as shorthand for --help instead of -uAndreas Henriksson2017-01-191-3/+4
| | | | | | The -u is still supported (but no longer documented). (This matches the switches used by shadow chsh.)
* Use --help suggestion on invalid optionKarel Zak2016-12-191-1/+1
| | | | | | | | 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>
* chfn: chsh: use selinux_check_passwd_access()Karel Zak2016-06-141-2/+3
| | | | | | | | | | | * 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>
* chsh, chfn, vipw: fix filenames collisionKarel Zak2015-08-241-1/+1
| | | | | | | | | | | | | | | | | | The utils when compiled WITHOUT libuser then mkostemp()ing "/etc/%s.XXXXXX" where the filename prefix is argv[0] basename. An attacker could repeatedly execute the util with modified argv[0] and after many many attempts mkostemp() may generate suffix which makes sense. The result maybe temporary file with name like rc.status ld.so.preload or krb5.keytab, etc. Note that distros usually use libuser based ch{sh,fn} or stuff from shadow-utils. It's probably very minor security bug. Addresses: CVE-2015-5224 Signed-off-by: Karel Zak <kzak@redhat.com>
* textual: add a docstring to most of the utilitiesBenno Schulenberg2015-01-061-0/+4
| | | | | | | | | 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>
* chsh: keep struct options in .rodataKarel Zak2015-01-061-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* chsh: simplify get_shell_list()Karel Zak2015-01-061-8/+5Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* chsh: fail get_shell_list() check when /etc/shells cannot be openedSami Kerola2015-01-051-5/+3Star
| | | | | | And get rid of stdbool.h true/false usage. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* chsh: simplify check_shell()Sami Kerola2015-01-051-33/+16Star
| | | | | | | | | | | Shell null check is redundant. The shell can be null only after ask_new_shell returned such, and that is checked earlier in program logic. Secondly the check_shell does not need to return values, in such cases the program can simply exit. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* chsh: rewrite function interacting with user to get path to new shellSami Kerola2015-01-051-24/+19Star
| | | | | | | | Rename prompt() to ask_new_shell(). Remove fixed size buffer and allocate path to new shell, that should make Hurd people happy. Use strutils.h for white space trimming. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* chsh: clean up parse_argv()Sami Kerola2015-01-051-8/+3Star
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* chsh: allow user to set shell to /bin/sh if none is setSami Kerola2015-01-051-2/+5
| | | | | | | Earlier setting a /bin/sh was impossible for users that had nothing set as shell, as that was seen as no change. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* chsh: set few variables read-only and rename one of themSami Kerola2015-01-051-19/+13Star
| | | | | | This change also improves couple variable initializations. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* chsh: use getline() to support arbitrarily long linesSami Kerola2015-01-051-7/+8
| | | | | | | | Use of fgets() can make a single long line to be understood as two entries, and someone could play tricks with the remainder part of the buffer. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* chfn, chsh: share illegal_passwd_chars() functionSami Kerola2015-01-051-13/+5Star
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* chsh: remove function prototypesSami Kerola2015-01-051-147/+143Star
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* textual: fix some typos and inconsistencies in various messagesBenno Schulenberg2014-07-231-2/+2
| | | | | | | | Fixing plain typos, miswordings, inconsistent periods, some missing angular brackets, and a proper pluralization (even when it involves a constant, because for some languages the precise value matters). Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* chsh-chfn: fix bugs, improve compilationKarel Zak2013-02-131-4/+7
| | | | | | | | | | | | | | * rename --disable-require-password to --disable-chsh-chfn-password * is_local() is really unnecessary when linked with libuser * fix set_value_libuser() returns codes * fix chfn.c, there is no 'pw', but oldf.pw * don't link with PAM when--disable-chsh-chfn-password Signed-off-by: Karel Zak <kzak@redhat.com>
* chsh: Add libuser supportCody Maloney2013-02-131-1/+21
| | | | | | | | | | This is based directly on lchsh which is a part of libuser. libuser.{c,h} exist because exactly the same code is needed for both chsh and chfn. [kzak@redhat.com: cleanup err() usage] Signed-off-by: Cody Maloney <cmaloney@theoreticalchaos.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* chsh-chfn: Move pam auth to its own function, factoring out common codeCody Maloney2013-02-131-30/+3Star
| | | | | | | This makes it easier to add support for libuser, which needs the same PAM authentication. Also removes duplicate code between chsh and chfn. Signed-off-by: Cody Maloney <cmaloney@theoreticalchaos.com>
* textual: spell and encode the name of Arkadiusz Miƛkiewicz correctlyBenno Schulenberg2013-02-061-1/+1
| | | | Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* chsh: use return rather than exit in main, clean up man pageKarel Zak2012-12-121-9/+8Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* login-utils: verify writing to streams was successfulSami Kerola2012-04-041-0/+2
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* chsh: use pathnames.h for pathsSami Kerola2012-03-181-11/+11
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* login: (and chsh) make pw_shell usage more robustKarel Zak2012-02-021-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* chsh: fix coding styleSami Kerola2011-11-291-275/+290
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* chfn, chsh: new file pamfail.h for error printingSami Kerola2011-11-291-21/+9Star
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* chsh: build bug: do not override config.h definitionSami Kerola2011-11-231-3/+0Star
| | | | | | | The ONLY_LISTED_SHELLS is defined by --disable-chsh-only-listed configuration option. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* chfn, chsh, setpwnam: get true/false from stdbool.hSami Kerola2011-11-231-7/+4Star
| | | | | | Requires C99, which should not be a problem. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* chsh: use libc error printing facilitiesSami Kerola2011-11-231-48/+33Star
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* chsh: align with howto-usage-function.txtSami Kerola2011-11-231-6/+10
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* chsh: remove non-PAM codeKarel Zak2011-11-031-18/+2Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* chsh: fix compiler warnings [-Wsign-compare]Karel Zak2011-08-011-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* textual: improve the wording of some error and usage messagesBenno Schulenberg2011-02-161-3/+3
| | | | | | | | | [kzak@redhat.com: - cleanup lscpu(1) usage text - use <disk> rather than <device> in partx(8) usage text] Signed-off-by: Benno Schulenberg <bensberg@justemail.net> Signed-off-by: Karel Zak <kzak@redhat.com>
* build-sys: provide alternatives for err, errx, warn and warnxFabian Groffen2011-02-141-1/+0Star
| | | | | | | | Solaris lacks err, errx, warn and warnx. This also means the err.h header doesn't exist. Removed err.h include from all files, and included err.h from c.h instead if it exists, otherwise alternatives are provided. Signed-off-by: Fabian Groffen <grobian@gentoo.org>
* build-sys: improve check for cryptFabian Groffen2011-01-171-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | Check for crypt.h existence, and use it if available over using unistd.h for which a certain feature level has to be set to export a definition for crypt. On Solaris this set causes a standards conflict in the headers, because at the time of this check C99 mode is already enabled, which implies certain standards non-compatible with _XOPEN_SOURCE. 92 #define _XOPEN_SOURCE 93 #include <unistd.h> configure:16259: gcc -std=gnu99 -c -g -O2 conftest.c >&5 In file included from /usr/include/unistd.h:18, from conftest.c:93: /prefix/gentoo/usr/lib/gcc/i386-pc-solaris2.10/4.4.5/include-fixed/sys/feature_tests.h:341:2: error: #error "Compiler or options invalid for pre-UNIX 03 X/Open applications and pre-2001 POSIX applications" configure.ac: improve crypt check login-utils/my_crypt.h: replace old GNU_LIBRARY check with autoconf define for crypt.h [kzak@redhat.com: - remove my_crypt.h] Signed-off-by: Fabian Groffen <grobian@gentoo.org> Signed-off-by: Karel Zak <kzak@redhat.com>
* fix __noreturn__ usageKarel Zak2010-12-101-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* chsh: use EXIT_* and err.hKarel Zak2010-12-101-95/+59Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* chsh: don't suggest ypchshKarel Zak2010-07-291-2/+1Star
| | | | | | | | | | $ chsh chsh: can only change local entries; use ypchsh instead. The 'ypchsh' is an external util that does not have to be installed. Addresses: http://bugzilla.redhat.com/show_bug.cgi?id=497329 Signed-off-by: Karel Zak <kzak@redhat.com>