Commit Graph

78 Commits

Author SHA1 Message Date
Karel Zak 0735d0efe1 lib/selinux-utils: tiny cleanup
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-13 15:04:02 +01:00
Karel Zak e1de70b3c3 chfs-chfn: remove deprecated selinux_check_passwd_access()
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-13 14:27:15 +01:00
Karel Zak b5debf7105 lib/selinux-utils: cleanup function names
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-13 13:33:41 +01:00
Karel Zak 68f4aa2a2f build-sys: move selinux_utils.c
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-13 13:30:31 +01:00
Karel Zak ca27216aa6 build-sys: remove fallback for security_context_t
It seems like overkill to provide this #ifdef. For example coreutils
use "char *" for all selinux contexts (since 2014).

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-13 13:12:19 +01:00
Karel Zak e522815027 login-utils: don't use deprecated security_context_t
libselinux >= 3.1 makes security_context_t type deprecated. Let's
ifdef it to avoid unwanted warnings.

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-12-14 15:54:08 +01:00
Damien Goutte-Gattat 49848aa53a chfn: Make readline prompt for each field on a separate line
When readline is called to get user input, it is called without
a prompt argument. As a result, if the user does not enter anything
for a given field, then the next field is displayed on the same
line, yielding the following output:

  $ chfn
  Changing finger information for user.
  Password:
  Name []: Office []: Office Phone []: Home Phone []:

instead of the expected:

  $ chfn
  Changing finger information for user.
  Password:
  Full Name []:
  Room Number []:
  Work Phone []:
  Home Phone []:

This patch restores the expected behavior by feeding readline with
a character to display as "prompt".

[kzak@redhat.com: - do the same change in chsh
                  - use ' ' rather than '\n' for non-readline code]

Signed-off-by: Damien Goutte-Gattat <dgouttegattat@incenp.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-06-29 11:57:26 +02:00
Rosen Penev bd89499e07
[clang-tidy] do not return in void functions
Found with readability-redundant-control-flow

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-19 14:03:21 -07:00
Karel Zak 9210c0d225 chfn: don't append extra tailing commas
# grep kzak /etc/passwd
 kzak1000:1000::/home/kzak:/bin/bash

 # chfn kzak
 ...
 grep kzak /etc/passwd

old version:
 kzak1000:1000:Karel Zak,,,,:/home/kzak:/bin/bash

fixed version:
 kzak1000:1000:Karel Zak:/home/kzak:/bin/bash

Reported-by: Filip Dvorak <fdvorak@redhat.com>
References: f723cbf544
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-08-19 14:03:07 +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
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 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 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
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
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 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
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
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
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
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
Karel Zak bf6c15ed4a chfn: fix compilation without libuser
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-12-19 15:05:04 +01:00
Sami Kerola e88f005949 chfn: make command to obey login.defs CHFN_RESTRICT instructions
Reference: http://man7.org/linux/man-pages/man5/login.defs.5.html
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=138519
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-12-19 09:11:04 +00:00
Sami Kerola f723cbf544 chfn: remove set_changed_data() and add add_missing()
The add_missing() and find_field() functions are needed when input data
is incomplete, such as in case when chfn is instructed to change only
selected fields with command line options.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-12-19 09:11:04 +00:00
Sami Kerola d9e1ac99e4 chfn: rename prompt() to ask_new_field()
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-12-19 09:11:04 +00:00
Sami Kerola 5fe1c32f61 chfn: move new and old finger structs to chfn control struct
This change is a little bit messy, and requires a comment the struct
finfo should not have 'struct passwd *pw' as it's member.  The earlier
struct design would have been burden to maintain, and confusing to use.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-12-19 09:11:04 +00:00
Sami Kerola e4efecc4db chfn: clean up parse_argv()
Use switch() case ?: for all option parsing, as in most of the other
source files.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-12-19 09:11:04 +00:00
Sami Kerola d5fdba0346 chfn: add minimalistic struct chfn_control
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-12-19 09:11:04 +00:00
Sami Kerola 58985f6712 chfn: simplify parse_passwd() by using strsep()
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-12-19 09:11:03 +00:00
Sami Kerola 496083bad6 chfn: fix usage() regression
Commit db433bf737 changed -u for --help to
-h, that is not true.  The -h is short hand for --home-phone.  And the
--version is accompanied with -v not -V.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-12-19 09:11:03 +00:00
Sami Kerola 1b7a19ebbb chfn: use xasprintf() rather than bunch of strlen() and malloc() calls
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-12-19 09:11:03 +00:00
Sami Kerola 5a57c00af0 chfn: rewrite prompt() to use strutils
The left and right white space trimming can be done with strutils.h
[lr]trim_whitespace() functions.

As a minor fix when user input exceeds maxium allowed gecos field length
the remaining characters in stdin are purged so that re-prompting works
correctly.

Additionally the prompt() is made to add message to check_gecos_string(),
so that there are less similar strings for translation project to deal.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-12-19 09:11:03 +00:00
Sami Kerola 2401633559 chfn: remove function prototypes
Requires resuffling functions order they work without issues.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-12-19 09:11:03 +00:00
Sami Kerola db433bf737 textual: use usage() text element macros
Translating these text elements should happen only once, which is
more likely when the text macros are used properly.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-10-01 12:33:26 +02: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
Sami Kerola 467ca0b214 chfn: assigned value is never read [clang-analyzer]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-07-09 14:25:11 +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 8c24b6aa2c chfn: Add libuser support
Signed-off-by: Cody Maloney <cmaloney@theoreticalchaos.com>
2013-02-13 09:39:12 +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 6affea028b chfn: always use return rather than exit() in main
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-12-12 10:41:44 +01:00
Karel Zak 97da60c64e chfn: clean up exit status
The old version in some cases (but not always) returns -1 (255) on
error. It seems better to cleanup the code and don't return internal
return codes by exit().

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-12-12 10:36:32 +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 8c3221890a chfn: use pathnames.h for paths
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-03-18 14:28:04 +01:00
Sami Kerola 3ca1029905 chfn: fix coding style
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-11-29 17:58:00 +01:00
Sami Kerola e55b7a8f2f chfn, setpwnam: let config.h be in control of extensions in use
The autotools will set _GNU_SOURCE which removes necessity to have
any _*_SOURCE definition in *.c files.

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 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 b9364124f8 chfn: use libc error printing facilities
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-11-23 21:35:26 +01:00
Sami Kerola 85b6104da5 chfn: align with howto-usage-function.txt
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-11-23 21:20:11 +01:00