Commit Graph

58 Commits

Author SHA1 Message Date
Karel Zak bde91c85bd chsh, chfn, vipw: fix filenames collision
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>
2015-08-24 10:05:55 +02: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
Karel Zak 4a98629b29 chsh: keep struct options in .rodata
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-06 11:00:51 +01:00
Karel Zak 84705c8b89 chsh: simplify get_shell_list()
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-06 10:57:09 +01:00
Sami Kerola 9a5cbe5223 chsh: fail get_shell_list() check when /etc/shells cannot be opened
And get rid of stdbool.h true/false usage.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-01-05 22:52:51 +00:00
Sami Kerola 1df0219f2c chsh: simplify check_shell()
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>
2015-01-05 22:52:51 +00:00
Sami Kerola e323df25f5 chsh: rewrite function interacting with user to get path to new shell
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>
2015-01-05 22:52:51 +00:00
Sami Kerola 68b24d53e1 chsh: clean up parse_argv()
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-01-05 22:52:51 +00:00
Sami Kerola f64979233f chsh: allow user to set shell to /bin/sh if none is set
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>
2015-01-05 22:52:51 +00:00
Sami Kerola 561c48582c chsh: set few variables read-only and rename one of them
This change also improves couple variable initializations.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-01-05 22:52:51 +00:00
Sami Kerola 1cb122d591 chsh: use getline() to support arbitrarily long lines
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>
2015-01-05 22:52:50 +00:00
Sami Kerola 144ae70ef3 chfn, chsh: share illegal_passwd_chars() function
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-01-05 22:52:50 +00:00
Sami Kerola 5eef61296f chsh: remove function prototypes
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-01-05 22:52:50 +00:00
Benno Schulenberg 09af3db48e textual: fix some typos and inconsistencies in various messages
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>
2014-07-23 08:56:00 +02:00
Karel Zak d86918b6eb chsh-chfn: fix bugs, improve compilation
* 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>
2013-02-13 13:44:34 +01:00
Cody Maloney 6adb1ef279 chsh: Add libuser support
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>
2013-02-13 09:37:15 +01:00
Cody Maloney d91ad6ab3c chsh-chfn: Move pam auth to its own function, factoring out common code
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>
2013-02-13 09:28:33 +01:00
Benno Schulenberg b50945d4ac textual: spell and encode the name of Arkadiusz Miśkiewicz correctly
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2013-02-06 11:15:02 +01:00
Karel Zak 36f9133dd2 chsh: use return rather than exit in main, clean up man page
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-12-12 10:48:01 +01:00
Sami Kerola 439cdf1e24 login-utils: verify writing to streams was successful
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-04-04 19:58:34 +02:00
Sami Kerola c900336d8b chsh: use pathnames.h for paths
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-03-18 14:28:04 +01:00
Karel Zak c6f23b3ba1 login: (and chsh) make pw_shell usage more robust
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-02-02 14:13:45 +01:00
Sami Kerola 0a065b7ae6 chsh: fix coding style
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-11-29 17:58:00 +01:00
Sami Kerola 57b35f3ba7 chfn, chsh: new file pamfail.h for error printing
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-11-29 17:57:39 +01:00
Sami Kerola 7299ca031d chsh: build bug: do not override config.h definition
The ONLY_LISTED_SHELLS is defined by --disable-chsh-only-listed
configuration option.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-11-23 21:52:50 +01:00
Sami Kerola 8187b555df chfn, chsh, setpwnam: get true/false from stdbool.h
Requires C99, which should not be a problem.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-11-23 21:50:17 +01:00
Sami Kerola 8fed34e5a1 chsh: use libc error printing facilities
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-11-23 21:37:19 +01:00
Sami Kerola fbff9d7996 chsh: align with howto-usage-function.txt
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-11-23 21:37:19 +01:00
Karel Zak cc0d0cba56 chsh: remove non-PAM code
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-11-03 12:32:50 +01:00
Karel Zak 8ef5b8e66b chsh: fix compiler warnings [-Wsign-compare]
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-08-01 16:20:28 +02:00
Benno Schulenberg e8ab5ce3d0 textual: improve the wording of some error and usage messages
[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>
2011-02-16 15:46:38 +01:00
Fabian Groffen eb76ca98b0 build-sys: provide alternatives for err, errx, warn and warnx
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>
2011-02-14 17:45:24 +01:00
Fabian Groffen 0aeb57aca3 build-sys: improve check for crypt
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>
2011-01-17 16:32:39 +01:00
Karel Zak abafd68667 fix __noreturn__ usage
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-12-10 16:47:18 +01:00
Karel Zak d39d4bf6f5 chsh: use EXIT_* and err.h
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-12-10 13:01:05 +01:00
Karel Zak ae7054723b chsh: don't suggest ypchsh
$ 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>
2010-07-29 16:08:20 +02:00
Karel Zak 4ba66edf82 selinux: is_selinux_enabled() returns 0, 1 and -1
Unfortunately, the current libselinux implementation of
is_selinux_enabled() returns -1 on error. This behavior is
undocumented.

The proper solution is to use "if (is_selinux_enabled() > 0)".

Signed-off-by: Karel Zak <kzak@redhat.com>
2008-07-01 14:32:53 +02:00
Benno Schulenberg 265095a2fe chfn, chsh, login: collapsing three similar messages into a single one
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2008-04-16 00:29:30 +02:00
Benno Schulenberg 6557c51226 docs: tweak a few messages for clarity
Add a missing period, a missing space, a comma and a word for clarity,
plus a period and an uppercase letter to match surrounding messages.
Further add a missing call to gettext, and undo an unneeded linewrap.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2007-10-26 01:02:44 +02:00
Yu Zhiguo f41aff5a67 chsh: should use pam_end function to terminate the PAM transaction
chsh will use PAM transaction if macros 'REQUIRE_PASSWORD' and
'HAVE_SECURITY_PAM_MISC_H' are defined, but there is no pam_end function be
used when the PAM transaction be terminated.

This patch also cleanup PAM code in chsh(1).

Signed-off-by: Yu Zhiguo <yuzg@cn.fujitsu.com>
Co-Author: Karel Zak <kzak@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2007-10-04 00:09:19 +02:00
Karel Zak e93a1aae2f chsh: don't use empty shell field in /etc/passwd
chsh(1) uses empty shell setting (pw->pw_shell="") as a synonym for
/bin/sh. This convention is silly and unnecessary. (The vsftpd server
will not run if the shell assigned to user "ftp" is a null string --
according to bug rh#103004).

Signed-off-by: Karel Zak <kzak@redhat.com>
2007-08-14 12:04:09 +02:00
Karel Zak 7ab59baf58 chsh: remove tailing wihit-spaces and use PATH_BSHELL
Signed-off-by: Karel Zak <kzak@redhat.com>
2007-03-07 10:14:03 +01:00
Karel Zak 48d7b13a1e Imported from util-linux-2.13-pre1 tarball. 2006-12-07 00:26:54 +01:00
Karel Zak 0b0bb92085 Imported from util-linux-2.12i tarball. 2006-12-07 00:26:22 +01:00
Karel Zak c129767e06 Imported from util-linux-2.12b tarball. 2006-12-07 00:26:16 +01:00
Karel Zak d03dd60840 Imported from util-linux-2.12a tarball. 2006-12-07 00:26:14 +01:00
Karel Zak ffc4374869 Imported from util-linux-2.11o tarball. 2006-12-07 00:25:53 +01:00
Karel Zak 364cda4857 Imported from util-linux-2.11f tarball. 2006-12-07 00:25:48 +01:00
Karel Zak c07ebfa1e0 Imported from util-linux-2.11b tarball. 2006-12-07 00:25:46 +01:00
Karel Zak 66ee8158b6 Imported from util-linux-2.10s tarball. 2006-12-07 00:25:44 +01:00