2007-10-07 17:14:02 +05:30
|
|
|
/*
|
2021-12-05 21:05:27 +05:30
|
|
|
* SPDX-FileCopyrightText: 1990 - 1994, Julianne Frances Haugh
|
|
|
|
* SPDX-FileCopyrightText: 1996 - 2000, Marek Michałkiewicz
|
|
|
|
* SPDX-FileCopyrightText: 2000 - 2006, Tomasz Kłoczko
|
|
|
|
* SPDX-FileCopyrightText: 2007 - 2011, Nicolas François
|
2007-10-07 17:14:02 +05:30
|
|
|
*
|
2021-12-05 21:05:27 +05:30
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-11-11 05:16:11 +05:30
|
|
|
#ident "$Id$"
|
2007-10-07 17:17:01 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
#include <fcntl.h>
|
2007-10-07 17:15:58 +05:30
|
|
|
#include <getopt.h>
|
2007-10-07 17:16:07 +05:30
|
|
|
#include <pwd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2007-10-07 17:14:38 +05:30
|
|
|
#ifdef USE_PAM
|
2007-10-07 17:17:11 +05:30
|
|
|
#include "pam_defs.h"
|
2007-10-07 17:14:59 +05:30
|
|
|
#endif /* USE_PAM */
|
2007-10-07 17:16:07 +05:30
|
|
|
#include "defines.h"
|
|
|
|
#include "nscd.h"
|
Flush sssd caches in addition to nscd caches
Some distributions, notably Fedora, have the following order of nsswitch
modules by default:
passwd: sss files
group: sss files
The advantage of serving local users through SSSD is that the nss_sss
module has a fast mmapped-cache that speeds up NSS lookups compared to
accessing the disk an opening the files on each NSS request.
Traditionally, this has been done with the help of nscd, but using nscd
in parallel with sssd is cumbersome, as both SSSD and nscd use their own
independent caching, so using nscd in setups where sssd is also serving
users from some remote domain (LDAP, AD, ...) can result in a bit of
unpredictability.
More details about why Fedora chose to use sss before files can be found
on e.g.:
https://fedoraproject.org//wiki/Changes/SSSDCacheForLocalUsers
or:
https://docs.pagure.org/SSSD.sssd/design_pages/files_provider.html
Now, even though sssd watches the passwd and group files with the help
of inotify, there can still be a small window where someone requests a
user or a group, finds that it doesn't exist, adds the entry and checks
again. Without some support in shadow-utils that would explicitly drop
the sssd caches, the inotify watch can fire a little late, so a
combination of commands like this:
getent passwd user || useradd user; getent passwd user
can result in the second getent passwd not finding the newly added user
as the racy behaviour might still return the cached negative hit from
the first getent passwd.
This patch more or less copies the already existing support that
shadow-utils had for dropping nscd caches, except using the "sss_cache"
tool that sssd ships.
2018-09-12 17:52:11 +05:30
|
|
|
#include "sssd.h"
|
2011-07-28 20:47:28 +05:30
|
|
|
#include "getdef.h"
|
2007-10-07 17:17:01 +05:30
|
|
|
#include "prototypes.h"
|
|
|
|
#include "pwio.h"
|
2007-10-07 17:16:07 +05:30
|
|
|
#include "shadowio.h"
|
* src/newgrp.c, src/chfn.c, src/groupmems.c, src/usermod.c,
src/userdel.c, src/chpasswd.c, src/grpck.c, src/gpasswd.c,
src/groupdel.c, src/chgpasswd.c, src/vipw.c, src/useradd.c,
src/su.c, src/groupmod.c, src/passwd.c, src/pwck.c,
src/groupadd.c, src/chage.c, src/login.c, src/faillog.c,
src/sulogin.c, src/chsh.c, src/pwconv.c: Added splint annotations.
* src/userdel.c, src/pwconv.c, src/lastlog.c, src/grpck.c,
src/vipw.c, src/groupmod.c, src/passwd.c, src/pwck.c, src/login.c,
src/sulogin.c, src/usermod.c: Use return instead of exit at the
end of main().
* src/gpasswd.c, src/passwd.c, src/faillog.c: Use the exitcodes.h
exit codes.
* src/chpasswd.c: Added missing ||.
* src/nologin.c: Do not include exitcodes.h.
* src/nologin.c: Added brackets.
* src/nologin.c: Avoid assignments in comparisons.
2009-05-01 03:09:38 +05:30
|
|
|
/*@-exitarg@*/
|
|
|
|
#include "exitcodes.h"
|
2021-11-29 05:07:53 +05:30
|
|
|
#include "shadowlog.h"
|
* src/newgrp.c, src/chfn.c, src/groupmems.c, src/usermod.c,
src/userdel.c, src/chpasswd.c, src/grpck.c, src/gpasswd.c,
src/groupdel.c, src/chgpasswd.c, src/vipw.c, src/useradd.c,
src/su.c, src/groupmod.c, src/passwd.c, src/pwck.c,
src/groupadd.c, src/chage.c, src/login.c, src/faillog.c,
src/sulogin.c, src/chsh.c, src/pwconv.c: Added splint annotations.
* src/userdel.c, src/pwconv.c, src/lastlog.c, src/grpck.c,
src/vipw.c, src/groupmod.c, src/passwd.c, src/pwck.c, src/login.c,
src/sulogin.c, src/usermod.c: Use return instead of exit at the
end of main().
* src/gpasswd.c, src/passwd.c, src/faillog.c: Use the exitcodes.h
exit codes.
* src/chpasswd.c: Added missing ||.
* src/nologin.c: Do not include exitcodes.h.
* src/nologin.c: Added brackets.
* src/nologin.c: Avoid assignments in comparisons.
2009-05-01 03:09:38 +05:30
|
|
|
|
2022-04-02 09:18:51 +05:30
|
|
|
#define IS_CRYPT_METHOD(str) ((crypt_method != NULL && strcmp(crypt_method, str) == 0) ? true : false)
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
/*
|
|
|
|
* Global variables
|
|
|
|
*/
|
* src/newgrp.c, src/userdel.c, src/grpck.c, src/gpasswd.c,
src/newusers.c, src/pwconv.c, src/chpasswd.c, src/logoutd.c,
src/chfn.c, src/groupmems.c, src/usermod.c, src/pwunconv.c,
src/expiry.c, src/groupdel.c, src/chgpasswd.c, src/useradd.c,
src/su.c, src/groupmod.c, src/passwd.c, src/pwck.c, src/chage.c,
src/groupadd.c, src/login.c, src/grpconv.c, src/groups.c,
src/grpunconv.c, src/chsh.c: Prog changed to a constant string.
2010-08-23 01:06:09 +05:30
|
|
|
const char *Prog;
|
2008-08-10 04:55:18 +05:30
|
|
|
static bool eflg = false;
|
2008-06-10 01:16:11 +05:30
|
|
|
static bool md5flg = false;
|
2020-12-28 01:39:25 +05:30
|
|
|
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT) || defined(USE_YESCRYPT)
|
2008-08-10 04:55:18 +05:30
|
|
|
static bool sflg = false;
|
2019-09-17 00:24:56 +05:30
|
|
|
#endif
|
2007-11-20 15:03:52 +05:30
|
|
|
|
2011-08-14 20:07:17 +05:30
|
|
|
static /*@null@*//*@observer@*/const char *crypt_method = NULL;
|
2011-08-14 20:14:35 +05:30
|
|
|
#define cflg (NULL != crypt_method)
|
2009-03-14 03:58:27 +05:30
|
|
|
#ifdef USE_SHA_CRYPT
|
2007-11-24 01:39:57 +05:30
|
|
|
static long sha_rounds = 5000;
|
2019-09-17 00:24:56 +05:30
|
|
|
#endif
|
|
|
|
#ifdef USE_BCRYPT
|
|
|
|
static long bcrypt_rounds = 13;
|
|
|
|
#endif
|
2020-12-28 01:39:25 +05:30
|
|
|
#ifdef USE_YESCRYPT
|
|
|
|
static long yescrypt_cost = 5;
|
|
|
|
#endif
|
2007-10-07 17:14:59 +05:30
|
|
|
|
2008-06-10 01:16:11 +05:30
|
|
|
static bool is_shadow_pwd;
|
* src/chfn.c, src/chgpasswd.c, src/chpasswd.c, src/gpasswd.c,
src/groupadd.c, src/groupdel.c, src/groupmems.c, src/groupmod.c,
src/grpconv.c, src/grpunconv.c, src/newusers.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c: Harmonize the name
of the variables keeping the lock status, to match the shadow
library prefixes.
2008-08-22 07:52:34 +05:30
|
|
|
static bool pw_locked = false;
|
|
|
|
static bool spw_locked = false;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/* local function prototypes */
|
2008-08-10 04:55:18 +05:30
|
|
|
static void fail_exit (int code);
|
2023-02-08 00:20:36 +05:30
|
|
|
NORETURN static void usage (int status);
|
2007-12-29 03:35:51 +05:30
|
|
|
static void process_flags (int argc, char **argv);
|
|
|
|
static void check_flags (void);
|
|
|
|
static void check_perms (void);
|
2007-12-29 03:48:55 +05:30
|
|
|
static void open_files (void);
|
|
|
|
static void close_files (void);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-08-10 04:55:18 +05:30
|
|
|
/*
|
|
|
|
* fail_exit - exit with a failure code after unlocking the files
|
|
|
|
*/
|
|
|
|
static void fail_exit (int code)
|
|
|
|
{
|
* src/chfn.c, src/chgpasswd.c, src/chpasswd.c, src/gpasswd.c,
src/groupadd.c, src/groupdel.c, src/groupmems.c, src/groupmod.c,
src/grpconv.c, src/grpunconv.c, src/newusers.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c: Harmonize the name
of the variables keeping the lock status, to match the shadow
library prefixes.
2008-08-22 07:52:34 +05:30
|
|
|
if (pw_locked) {
|
2008-08-10 04:55:18 +05:30
|
|
|
if (pw_unlock () == 0) {
|
|
|
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ());
|
|
|
|
SYSLOG ((LOG_ERR, "failed to unlock %s", pw_dbname ()));
|
|
|
|
/* continue */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
* src/chfn.c, src/chgpasswd.c, src/chpasswd.c, src/gpasswd.c,
src/groupadd.c, src/groupdel.c, src/groupmems.c, src/groupmod.c,
src/grpconv.c, src/grpunconv.c, src/newusers.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c: Harmonize the name
of the variables keeping the lock status, to match the shadow
library prefixes.
2008-08-22 07:52:34 +05:30
|
|
|
if (spw_locked) {
|
2008-08-10 04:55:18 +05:30
|
|
|
if (spw_unlock () == 0) {
|
|
|
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ());
|
|
|
|
SYSLOG ((LOG_ERR, "failed to unlock %s", spw_dbname ()));
|
|
|
|
/* continue */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exit (code);
|
|
|
|
}
|
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
|
|
|
* usage - display usage message and exit
|
|
|
|
*/
|
2023-02-08 00:20:36 +05:30
|
|
|
NORETURN
|
|
|
|
static void
|
|
|
|
usage (int status)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
* src/userdel.c, src/lastlog.c, src/gpasswd.c, src/newusers.c,
src/chpasswd.c, src/groupmems.c, src/usermod.c, src/chgpasswd.c,
src/vipw.c, src/su.c, src/useradd.c, src/groupmod.c, src/passwd.c,
src/groupadd.c, src/chage.c, src/faillog.c, src/chsh.c: Use
booleans for tests.
* src/userdel.c, src/gpasswd.c, src/groupmems.c, src/usermod.c,
src/groupmod.c, src/passwd.c: Use a break even after usage().
2009-09-06 04:01:29 +05:30
|
|
|
FILE *usageout = (E_SUCCESS != status) ? stderr : stdout;
|
* NEWS, src/userdel.c, src/lastlog.c, src/gpasswd.c,
src/newusers.c, src/chpasswd.c, src/groupmems.c, src/usermod.c,
src/chgpasswd.c, src/vipw.c, src/su.c, src/useradd.c,
src/groupmod.c, src/passwd.c, src/groupadd.c, src/chage.c,
src/faillog.c, src/chsh.c: If someone uses the -h/--help options,
the usage should not go to stderr nor should the utility exit with
non-zero status. All of the shadow utils do just this
unfortunately, so convert them over to sanity.
* man/groupmems.8.xml, man/gpasswd.1.xml: Added option -h/--help.
2009-09-05 04:32:33 +05:30
|
|
|
(void) fprintf (usageout,
|
2009-04-29 03:15:38 +05:30
|
|
|
_("Usage: %s [options]\n"
|
|
|
|
"\n"
|
|
|
|
"Options:\n"),
|
|
|
|
Prog);
|
* NEWS, src/userdel.c, src/lastlog.c, src/gpasswd.c,
src/newusers.c, src/chpasswd.c, src/groupmems.c, src/usermod.c,
src/chgpasswd.c, src/vipw.c, src/su.c, src/useradd.c,
src/groupmod.c, src/passwd.c, src/groupadd.c, src/chage.c,
src/faillog.c, src/chsh.c: If someone uses the -h/--help options,
the usage should not go to stderr nor should the utility exit with
non-zero status. All of the shadow utils do just this
unfortunately, so convert them over to sanity.
* man/groupmems.8.xml, man/gpasswd.1.xml: Added option -h/--help.
2009-09-05 04:32:33 +05:30
|
|
|
(void) fprintf (usageout,
|
2011-12-10 03:01:39 +05:30
|
|
|
_(" -c, --crypt-method METHOD the crypt method (one of %s)\n"),
|
2009-04-29 03:15:38 +05:30
|
|
|
"NONE DES MD5"
|
2020-12-28 01:39:25 +05:30
|
|
|
#if defined(USE_SHA_CRYPT)
|
|
|
|
" SHA256 SHA512"
|
|
|
|
#endif
|
|
|
|
#if defined(USE_BCRYPT)
|
|
|
|
" BCRYPT"
|
|
|
|
#endif
|
|
|
|
#if defined(USE_YESCRYPT)
|
|
|
|
" YESCRYPT"
|
2019-09-17 00:24:56 +05:30
|
|
|
#endif
|
2009-04-29 03:15:38 +05:30
|
|
|
);
|
* NEWS, src/userdel.c, src/lastlog.c, src/gpasswd.c,
src/newusers.c, src/chpasswd.c, src/groupmems.c, src/usermod.c,
src/chgpasswd.c, src/vipw.c, src/su.c, src/useradd.c,
src/groupmod.c, src/passwd.c, src/groupadd.c, src/chage.c,
src/faillog.c, src/chsh.c: If someone uses the -h/--help options,
the usage should not go to stderr nor should the utility exit with
non-zero status. All of the shadow utils do just this
unfortunately, so convert them over to sanity.
* man/groupmems.8.xml, man/gpasswd.1.xml: Added option -h/--help.
2009-09-05 04:32:33 +05:30
|
|
|
(void) fputs (_(" -e, --encrypted supplied passwords are encrypted\n"), usageout);
|
|
|
|
(void) fputs (_(" -h, --help display this help message and exit\n"), usageout);
|
2009-04-29 03:15:38 +05:30
|
|
|
(void) fputs (_(" -m, --md5 encrypt the clear text password using\n"
|
|
|
|
" the MD5 algorithm\n"),
|
* NEWS, src/userdel.c, src/lastlog.c, src/gpasswd.c,
src/newusers.c, src/chpasswd.c, src/groupmems.c, src/usermod.c,
src/chgpasswd.c, src/vipw.c, src/su.c, src/useradd.c,
src/groupmod.c, src/passwd.c, src/groupadd.c, src/chage.c,
src/faillog.c, src/chsh.c: If someone uses the -h/--help options,
the usage should not go to stderr nor should the utility exit with
non-zero status. All of the shadow utils do just this
unfortunately, so convert them over to sanity.
* man/groupmems.8.xml, man/gpasswd.1.xml: Added option -h/--help.
2009-09-05 04:32:33 +05:30
|
|
|
usageout);
|
2011-11-07 00:08:10 +05:30
|
|
|
(void) fputs (_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout);
|
2020-12-28 01:39:25 +05:30
|
|
|
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT) || defined(USE_YESCRYPT)
|
|
|
|
(void) fputs (_(" -s, --sha-rounds number of rounds for the SHA, BCRYPT\n"
|
|
|
|
" or YESCRYPT crypt algorithms\n"),
|
* NEWS, src/userdel.c, src/lastlog.c, src/gpasswd.c,
src/newusers.c, src/chpasswd.c, src/groupmems.c, src/usermod.c,
src/chgpasswd.c, src/vipw.c, src/su.c, src/useradd.c,
src/groupmod.c, src/passwd.c, src/groupadd.c, src/chage.c,
src/faillog.c, src/chsh.c: If someone uses the -h/--help options,
the usage should not go to stderr nor should the utility exit with
non-zero status. All of the shadow utils do just this
unfortunately, so convert them over to sanity.
* man/groupmems.8.xml, man/gpasswd.1.xml: Added option -h/--help.
2009-09-05 04:32:33 +05:30
|
|
|
usageout);
|
2020-12-28 01:39:25 +05:30
|
|
|
#endif /* USE_SHA_CRYPT || USE_BCRYPT || USE_YESCRYPT */
|
* NEWS, src/userdel.c, src/lastlog.c, src/gpasswd.c,
src/newusers.c, src/chpasswd.c, src/groupmems.c, src/usermod.c,
src/chgpasswd.c, src/vipw.c, src/su.c, src/useradd.c,
src/groupmod.c, src/passwd.c, src/groupadd.c, src/chage.c,
src/faillog.c, src/chsh.c: If someone uses the -h/--help options,
the usage should not go to stderr nor should the utility exit with
non-zero status. All of the shadow utils do just this
unfortunately, so convert them over to sanity.
* man/groupmems.8.xml, man/gpasswd.1.xml: Added option -h/--help.
2009-09-05 04:32:33 +05:30
|
|
|
(void) fputs ("\n", usageout);
|
2009-04-29 03:15:38 +05:30
|
|
|
|
* NEWS, src/userdel.c, src/lastlog.c, src/gpasswd.c,
src/newusers.c, src/chpasswd.c, src/groupmems.c, src/usermod.c,
src/chgpasswd.c, src/vipw.c, src/su.c, src/useradd.c,
src/groupmod.c, src/passwd.c, src/groupadd.c, src/chage.c,
src/faillog.c, src/chsh.c: If someone uses the -h/--help options,
the usage should not go to stderr nor should the utility exit with
non-zero status. All of the shadow utils do just this
unfortunately, so convert them over to sanity.
* man/groupmems.8.xml, man/gpasswd.1.xml: Added option -h/--help.
2009-09-05 04:32:33 +05:30
|
|
|
exit (status);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-12-29 03:35:51 +05:30
|
|
|
/*
|
|
|
|
* process_flags - parse the command line options
|
|
|
|
*
|
|
|
|
* It will not return if an error is encountered.
|
|
|
|
*/
|
|
|
|
static void process_flags (int argc, char **argv)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-12-29 03:35:51 +05:30
|
|
|
int c;
|
2020-12-28 01:39:25 +05:30
|
|
|
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT) || defined(USE_YESCRYPT)
|
|
|
|
int bad_s;
|
|
|
|
#endif /* USE_SHA_CRYPT || USE_BCRYPT || USE_YESCRYPT */
|
2007-12-29 03:35:51 +05:30
|
|
|
static struct option long_options[] = {
|
|
|
|
{"crypt-method", required_argument, NULL, 'c'},
|
* src/chage.c, src/chgpasswd.c, src/chpasswd.c, src/chsh.c,
src/faillog.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmems.c, src/groupmod.c, src/grpconv.c, src/grpunconv.c,
src/lastlog.c, src/newusers.c, src/passwd.c, src/pwconv.c,
src/pwunconv.c, src/su.c, src/useradd.c, src/userdel.c,
src/usermod.c, src/vipw.c: Align and sort options.
2011-11-07 00:09:59 +05:30
|
|
|
{"encrypted", no_argument, NULL, 'e'},
|
|
|
|
{"help", no_argument, NULL, 'h'},
|
|
|
|
{"md5", no_argument, NULL, 'm'},
|
|
|
|
{"root", required_argument, NULL, 'R'},
|
2020-12-28 01:39:25 +05:30
|
|
|
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT) || defined(USE_YESCRYPT)
|
* src/chage.c, src/chgpasswd.c, src/chpasswd.c, src/chsh.c,
src/faillog.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmems.c, src/groupmod.c, src/grpconv.c, src/grpunconv.c,
src/lastlog.c, src/newusers.c, src/passwd.c, src/pwconv.c,
src/pwunconv.c, src/su.c, src/useradd.c, src/userdel.c,
src/usermod.c, src/vipw.c: Align and sort options.
2011-11-07 00:09:59 +05:30
|
|
|
{"sha-rounds", required_argument, NULL, 's'},
|
2020-12-28 01:39:25 +05:30
|
|
|
#endif /* USE_SHA_CRYPT || USE_BCRYPT || USE_YESCRYPT */
|
2007-12-29 03:35:51 +05:30
|
|
|
{NULL, 0, NULL, '\0'}
|
|
|
|
};
|
2007-10-07 17:15:58 +05:30
|
|
|
|
2007-12-29 03:35:51 +05:30
|
|
|
while ((c = getopt_long (argc, argv,
|
2020-12-28 01:39:25 +05:30
|
|
|
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT) || defined(USE_YESCRYPT)
|
2011-11-07 00:08:10 +05:30
|
|
|
"c:ehmR:s:",
|
2019-09-17 00:24:56 +05:30
|
|
|
#else
|
2011-11-07 00:08:10 +05:30
|
|
|
"c:ehmR:",
|
2019-09-17 00:24:56 +05:30
|
|
|
#endif
|
2011-11-07 00:08:10 +05:30
|
|
|
long_options, NULL)) != -1) {
|
2007-12-29 03:35:51 +05:30
|
|
|
switch (c) {
|
|
|
|
case 'c':
|
|
|
|
crypt_method = optarg;
|
|
|
|
break;
|
|
|
|
case 'e':
|
2008-06-10 01:16:11 +05:30
|
|
|
eflg = true;
|
2007-12-29 03:35:51 +05:30
|
|
|
break;
|
* src/chage.c, src/chgpasswd.c, src/chpasswd.c, src/chsh.c,
src/faillog.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmems.c, src/groupmod.c, src/grpconv.c, src/grpunconv.c,
src/lastlog.c, src/newusers.c, src/passwd.c, src/pwconv.c,
src/pwunconv.c, src/su.c, src/useradd.c, src/userdel.c,
src/usermod.c, src/vipw.c: Align and sort options.
2011-11-07 00:09:59 +05:30
|
|
|
case 'h':
|
|
|
|
usage (E_SUCCESS);
|
|
|
|
/*@notreached@*/break;
|
2007-12-29 03:35:51 +05:30
|
|
|
case 'm':
|
2008-06-10 01:16:11 +05:30
|
|
|
md5flg = true;
|
2007-12-29 03:35:51 +05:30
|
|
|
break;
|
2011-11-07 00:08:10 +05:30
|
|
|
case 'R': /* no-op, handled in process_root_flag () */
|
|
|
|
break;
|
2020-12-28 01:39:25 +05:30
|
|
|
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT) || defined(USE_YESCRYPT)
|
2007-12-29 03:35:51 +05:30
|
|
|
case 's':
|
2008-06-10 01:16:11 +05:30
|
|
|
sflg = true;
|
2020-12-28 01:39:25 +05:30
|
|
|
bad_s = 0;
|
|
|
|
#if defined(USE_SHA_CRYPT)
|
2022-04-02 09:18:51 +05:30
|
|
|
if ((IS_CRYPT_METHOD("SHA256") || IS_CRYPT_METHOD("SHA512"))
|
|
|
|
&& (0 == getlong(optarg, &sha_rounds))) {
|
2020-12-28 01:39:25 +05:30
|
|
|
bad_s = 1;
|
|
|
|
}
|
|
|
|
#endif /* USE_SHA_CRYPT */
|
|
|
|
#if defined(USE_BCRYPT)
|
2022-04-02 09:18:51 +05:30
|
|
|
if (IS_CRYPT_METHOD("BCRYPT")
|
|
|
|
&& (0 == getlong(optarg, &bcrypt_rounds))) {
|
2020-12-28 01:39:25 +05:30
|
|
|
bad_s = 1;
|
|
|
|
}
|
|
|
|
#endif /* USE_BCRYPT */
|
|
|
|
#if defined(USE_YESCRYPT)
|
2022-04-02 09:18:51 +05:30
|
|
|
if (IS_CRYPT_METHOD("YESCRYPT")
|
|
|
|
&& (0 == getlong(optarg, &yescrypt_cost))) {
|
2020-12-28 01:39:25 +05:30
|
|
|
bad_s = 1;
|
|
|
|
}
|
|
|
|
#endif /* USE_YESCRYPT */
|
|
|
|
if (bad_s != 0) {
|
2007-12-29 03:35:51 +05:30
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: invalid numeric argument '%s'\n"),
|
|
|
|
Prog, optarg);
|
* NEWS, src/userdel.c, src/lastlog.c, src/gpasswd.c,
src/newusers.c, src/chpasswd.c, src/groupmems.c, src/usermod.c,
src/chgpasswd.c, src/vipw.c, src/su.c, src/useradd.c,
src/groupmod.c, src/passwd.c, src/groupadd.c, src/chage.c,
src/faillog.c, src/chsh.c: If someone uses the -h/--help options,
the usage should not go to stderr nor should the utility exit with
non-zero status. All of the shadow utils do just this
unfortunately, so convert them over to sanity.
* man/groupmems.8.xml, man/gpasswd.1.xml: Added option -h/--help.
2009-09-05 04:32:33 +05:30
|
|
|
usage (E_USAGE);
|
2007-10-07 17:15:58 +05:30
|
|
|
}
|
2007-12-29 03:35:51 +05:30
|
|
|
break;
|
2020-12-28 01:39:25 +05:30
|
|
|
#endif /* USE_SHA_CRYPT || USE_BCRYPT || USE_YESCRYPT */
|
2019-09-17 00:24:56 +05:30
|
|
|
|
2007-12-29 03:35:51 +05:30
|
|
|
default:
|
* NEWS, src/userdel.c, src/lastlog.c, src/gpasswd.c,
src/newusers.c, src/chpasswd.c, src/groupmems.c, src/usermod.c,
src/chgpasswd.c, src/vipw.c, src/su.c, src/useradd.c,
src/groupmod.c, src/passwd.c, src/groupadd.c, src/chage.c,
src/faillog.c, src/chsh.c: If someone uses the -h/--help options,
the usage should not go to stderr nor should the utility exit with
non-zero status. All of the shadow utils do just this
unfortunately, so convert them over to sanity.
* man/groupmems.8.xml, man/gpasswd.1.xml: Added option -h/--help.
2009-09-05 04:32:33 +05:30
|
|
|
usage (E_USAGE);
|
2011-07-23 13:44:15 +05:30
|
|
|
/*@notreached@*/break;
|
2007-10-07 17:15:58 +05:30
|
|
|
}
|
|
|
|
}
|
2007-10-07 17:15:40 +05:30
|
|
|
|
2007-11-20 15:03:52 +05:30
|
|
|
/* validate options */
|
2007-12-29 03:35:51 +05:30
|
|
|
check_flags ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* check_flags - check flags and parameters consistency
|
|
|
|
*
|
|
|
|
* It will not return if an error is encountered.
|
|
|
|
*/
|
2007-12-31 10:27:54 +05:30
|
|
|
static void check_flags (void)
|
2007-12-29 03:35:51 +05:30
|
|
|
{
|
2020-12-28 01:39:25 +05:30
|
|
|
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT) || defined(USE_YESCRYPT)
|
2007-11-20 15:03:52 +05:30
|
|
|
if (sflg && !cflg) {
|
|
|
|
fprintf (stderr,
|
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
Added *_dbname() functions to retrieve the name of the databases.
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
*_name() functions renamed *setname().
* src/grpck.c, src/pwck.c: Likewise.
* lib/groupio.h, lib/pwio.h, lib/sgroupio.h, lib/shadowio.h: Added
the name of the arguments to the prototypes.
* src/chage, src/chfn.c, src/chgpasswd.c, src/chpasswd.c,
src/chsh.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c,
src/newusers.c, src/passwd.c, src/pwck.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c, src/usermod.c:
Harmonize the erro & syslog messages in case of failure of the
*_lock(), *_open(), *_close(), *_unlock(), *_remove() functions.
* src/chgpasswd.c, src/chpasswd.c, src/usermod.c: Avoid
capitalized messages.
* src/chpasswd.c, src/useradd.c, src/usermod.c: Harmonize messages
in case of inexistent entries.
* src/usermod.c: Harmonize messages in case of already existing
entries.
* src/newusers.c, src/useradd.c: Simplify PAM error handling.
* src/useradd.c: Report failures to unlock files (stderr, syslog,
and audit). But do not fail (continue).
* src/useradd.c (open_files): Do not report to syslog & audit
failures to lock or open the databases. This might be harmless,
and the logs were not already informed that a change was
requested.
* src/usermod.c: It's not the account which is unlocked, but its
password.
2008-08-06 21:27:31 +05:30
|
|
|
_("%s: %s flag is only allowed with the %s flag\n"),
|
2007-12-29 03:35:51 +05:30
|
|
|
Prog, "-s", "-c");
|
* NEWS, src/userdel.c, src/lastlog.c, src/gpasswd.c,
src/newusers.c, src/chpasswd.c, src/groupmems.c, src/usermod.c,
src/chgpasswd.c, src/vipw.c, src/su.c, src/useradd.c,
src/groupmod.c, src/passwd.c, src/groupadd.c, src/chage.c,
src/faillog.c, src/chsh.c: If someone uses the -h/--help options,
the usage should not go to stderr nor should the utility exit with
non-zero status. All of the shadow utils do just this
unfortunately, so convert them over to sanity.
* man/groupmems.8.xml, man/gpasswd.1.xml: Added option -h/--help.
2009-09-05 04:32:33 +05:30
|
|
|
usage (E_USAGE);
|
2007-11-20 15:03:52 +05:30
|
|
|
}
|
2009-03-14 03:58:27 +05:30
|
|
|
#endif
|
2007-12-29 03:35:51 +05:30
|
|
|
|
2007-11-20 18:39:55 +05:30
|
|
|
if ((eflg && (md5flg || cflg)) ||
|
2007-11-21 01:30:16 +05:30
|
|
|
(md5flg && cflg)) {
|
2007-11-20 15:03:52 +05:30
|
|
|
fprintf (stderr,
|
2007-12-29 03:35:51 +05:30
|
|
|
_("%s: the -c, -e, and -m flags are exclusive\n"),
|
|
|
|
Prog);
|
* NEWS, src/userdel.c, src/lastlog.c, src/gpasswd.c,
src/newusers.c, src/chpasswd.c, src/groupmems.c, src/usermod.c,
src/chgpasswd.c, src/vipw.c, src/su.c, src/useradd.c,
src/groupmod.c, src/passwd.c, src/groupadd.c, src/chage.c,
src/faillog.c, src/chsh.c: If someone uses the -h/--help options,
the usage should not go to stderr nor should the utility exit with
non-zero status. All of the shadow utils do just this
unfortunately, so convert them over to sanity.
* man/groupmems.8.xml, man/gpasswd.1.xml: Added option -h/--help.
2009-09-05 04:32:33 +05:30
|
|
|
usage (E_USAGE);
|
2007-11-20 15:03:52 +05:30
|
|
|
}
|
2007-12-29 03:35:51 +05:30
|
|
|
|
2007-11-20 15:03:52 +05:30
|
|
|
if (cflg) {
|
2022-04-02 09:18:51 +05:30
|
|
|
if ((!IS_CRYPT_METHOD("DES"))
|
|
|
|
&&(!IS_CRYPT_METHOD("MD5"))
|
|
|
|
&&(!IS_CRYPT_METHOD("NONE"))
|
* configure.in: New configure option: --with-sha-crypt enabled by
default. Keeping the feature enabled is safe. Disabling it permits
to disable the references to the SHA256 and SHA512 password
encryption algorithms from the usage help and manuals (in addition
to the support for these algorithms in the code).
* libmisc/obscure.c, libmisc/salt.c, src/newusers.c,
src/chpasswd.c, src/chgpasswd.c, src/passwd.c: ENCRYPT_METHOD is
always supported in login.defs. Remove the ENCRYPTMETHOD_SELECT
preprocessor condition.
* libmisc/obscure.c, libmisc/salt.c, src/newusers.c,
src/chpasswd.c, src/chgpasswd.c, src/passwd.c: Disable SHA256 and
SHA512 if USE_SHA_CRYPT is not defined (this corresponds to a
subset of the ENCRYPTMETHOD_SELECT sections).
2007-11-24 18:38:08 +05:30
|
|
|
#ifdef USE_SHA_CRYPT
|
2022-04-02 09:18:51 +05:30
|
|
|
&&(!IS_CRYPT_METHOD("SHA256"))
|
|
|
|
&&(!IS_CRYPT_METHOD("SHA512"))
|
2010-03-26 02:05:59 +05:30
|
|
|
#endif /* USE_SHA_CRYPT */
|
2019-09-17 00:24:56 +05:30
|
|
|
#ifdef USE_BCRYPT
|
2022-04-02 09:18:51 +05:30
|
|
|
&&(!IS_CRYPT_METHOD("BCRYPT"))
|
2019-09-17 00:24:56 +05:30
|
|
|
#endif /* USE_BCRYPT */
|
2020-12-28 01:39:25 +05:30
|
|
|
#ifdef USE_YESCRYPT
|
2022-04-02 09:18:51 +05:30
|
|
|
&&(!IS_CRYPT_METHOD("YESCRYPT"))
|
2020-12-28 01:39:25 +05:30
|
|
|
#endif /* USE_YESCRYPT */
|
2007-11-20 15:03:52 +05:30
|
|
|
) {
|
|
|
|
fprintf (stderr,
|
2007-11-24 01:39:57 +05:30
|
|
|
_("%s: unsupported crypt method: %s\n"),
|
|
|
|
Prog, crypt_method);
|
* NEWS, src/userdel.c, src/lastlog.c, src/gpasswd.c,
src/newusers.c, src/chpasswd.c, src/groupmems.c, src/usermod.c,
src/chgpasswd.c, src/vipw.c, src/su.c, src/useradd.c,
src/groupmod.c, src/passwd.c, src/groupadd.c, src/chage.c,
src/faillog.c, src/chsh.c: If someone uses the -h/--help options,
the usage should not go to stderr nor should the utility exit with
non-zero status. All of the shadow utils do just this
unfortunately, so convert them over to sanity.
* man/groupmems.8.xml, man/gpasswd.1.xml: Added option -h/--help.
2009-09-05 04:32:33 +05:30
|
|
|
usage (E_USAGE);
|
2007-11-20 15:03:52 +05:30
|
|
|
}
|
|
|
|
}
|
2007-12-29 03:35:51 +05:30
|
|
|
}
|
2007-11-20 15:03:52 +05:30
|
|
|
|
2007-12-29 03:35:51 +05:30
|
|
|
/*
|
|
|
|
* check_perms - check if the caller is allowed to add a group
|
|
|
|
*
|
2008-01-02 01:26:29 +05:30
|
|
|
* With PAM support, the setuid bit can be set on chpasswd to allow
|
2007-12-29 03:35:51 +05:30
|
|
|
* non-root users to groups.
|
|
|
|
* Without PAM support, only users who can write in the group databases
|
|
|
|
* can add groups.
|
|
|
|
*
|
|
|
|
* It will not return if the user is not allowed.
|
|
|
|
*/
|
|
|
|
static void check_perms (void)
|
|
|
|
{
|
2007-10-07 17:14:38 +05:30
|
|
|
#ifdef USE_PAM
|
2009-04-29 03:15:38 +05:30
|
|
|
#ifdef ACCT_TOOLS_SETUID
|
2010-03-26 02:05:59 +05:30
|
|
|
/* If chpasswd uses PAM and is SUID, check the permissions,
|
|
|
|
* otherwise, the permissions are enforced by the access to the
|
|
|
|
* passwd and shadow files.
|
|
|
|
*/
|
* src/userdel.c, src/newusers.c, src/chpasswd.c, src/chfn.c,
src/groupmems.c, src/usermod.c, src/groupdel.c, src/chgpasswd.c,
src/useradd.c, src/groupmod.c, src/groupadd.c, src/chage.c,
src/chsh.c: Simplify the PAM error handling. Do not keep the pamh
handle, but terminate the PAM transaction as soon as possible if
there are no PAM session opened.
2008-09-06 18:58:02 +05:30
|
|
|
pam_handle_t *pamh = NULL;
|
|
|
|
int retval;
|
2007-12-29 03:35:51 +05:30
|
|
|
struct passwd *pampw;
|
2008-08-10 04:55:18 +05:30
|
|
|
|
2007-12-29 03:35:51 +05:30
|
|
|
pampw = getpwuid (getuid ()); /* local, no need for xgetpwuid */
|
2008-08-10 04:55:18 +05:30
|
|
|
if (NULL == pampw) {
|
Additional PAM cleanup:
* src/userdel.c, src/newusers.c, src/chpasswd.c, src/chfn.c,
src/groupmems.c, src/usermod.c, src/groupdel.c, src/chgpasswd.c,
src/useradd.c, src/groupmod.c, src/groupadd.c, src/chage.c,
src/chsh.c: If the username cannot be determined, report it as
such (not a PAM authentication failure).
2008-09-07 05:16:44 +05:30
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: Cannot determine your user name.\n"),
|
|
|
|
Prog);
|
|
|
|
exit (1);
|
2007-10-07 17:14:38 +05:30
|
|
|
}
|
|
|
|
|
Additional PAM cleanup:
* src/userdel.c, src/newusers.c, src/chpasswd.c, src/chfn.c,
src/groupmems.c, src/usermod.c, src/groupdel.c, src/chgpasswd.c,
src/useradd.c, src/groupmod.c, src/groupadd.c, src/chage.c,
src/chsh.c: If the username cannot be determined, report it as
such (not a PAM authentication failure).
2008-09-07 05:16:44 +05:30
|
|
|
retval = pam_start ("chpasswd", pampw->pw_name, &conv, &pamh);
|
|
|
|
|
2008-08-10 04:55:18 +05:30
|
|
|
if (PAM_SUCCESS == retval) {
|
2007-10-07 17:14:59 +05:30
|
|
|
retval = pam_authenticate (pamh, 0);
|
2007-10-07 17:14:38 +05:30
|
|
|
}
|
|
|
|
|
2008-08-10 04:55:18 +05:30
|
|
|
if (PAM_SUCCESS == retval) {
|
2007-10-07 17:14:59 +05:30
|
|
|
retval = pam_acct_mgmt (pamh, 0);
|
2007-10-07 17:14:38 +05:30
|
|
|
}
|
|
|
|
|
* src/userdel.c, src/newusers.c, src/chpasswd.c, src/chfn.c,
src/groupmems.c, src/usermod.c, src/groupdel.c, src/chgpasswd.c,
src/useradd.c, src/groupmod.c, src/groupadd.c, src/chage.c,
src/chsh.c: Simplify the PAM error handling. Do not keep the pamh
handle, but terminate the PAM transaction as soon as possible if
there are no PAM session opened.
2008-09-06 18:58:02 +05:30
|
|
|
if (PAM_SUCCESS != retval) {
|
* src/chage.c, src/chfn.c, src/chgpasswd.c, src/chpasswd.c,
src/chsh.c, src/groupadd.c, src/groupdel.c, src/groupmems.c,
src/groupmod.c, src/newusers.c, src/useradd.c, src/userdel.c,
src/usermod.c: Provide the PAM error
message instead of our own, and log error to syslog.
* src/groupmems.c: Exit with exit rather than fail_exit in usage().
* src/newusers.c: Check the number of arguments.
* src/newusers.c: Do not create the home directory when it is not
changed.
* src/useradd.c: Set the group password to "!" rather "x" if there
are no gshadow file.
2011-11-13 21:54:57 +05:30
|
|
|
fprintf (stderr, _("%s: PAM: %s\n"),
|
|
|
|
Prog, pam_strerror (pamh, retval));
|
|
|
|
SYSLOG((LOG_ERR, "%s", pam_strerror (pamh, retval)));
|
|
|
|
if (NULL != pamh) {
|
|
|
|
(void) pam_end (pamh, retval);
|
|
|
|
}
|
2007-10-07 17:14:38 +05:30
|
|
|
exit (1);
|
|
|
|
}
|
* src/chage.c, src/chfn.c, src/chgpasswd.c, src/chpasswd.c,
src/chsh.c, src/groupadd.c, src/groupdel.c, src/groupmems.c,
src/groupmod.c, src/newusers.c, src/useradd.c, src/userdel.c,
src/usermod.c: Provide the PAM error
message instead of our own, and log error to syslog.
* src/groupmems.c: Exit with exit rather than fail_exit in usage().
* src/newusers.c: Check the number of arguments.
* src/newusers.c: Do not create the home directory when it is not
changed.
* src/useradd.c: Set the group password to "!" rather "x" if there
are no gshadow file.
2011-11-13 21:54:57 +05:30
|
|
|
(void) pam_end (pamh, retval);
|
* configure.in: Added option --enable-account-tools-setuid to
enable/disable the usage of PAM to authenticate the callers of
account management tools: chage, chgpasswd, chpasswd, groupadd,
groupdel, groupmod, useradd, userdel, usermod.
* src/Makefile.am: Do not link the above tools with libpam if
account-tools-setuid is disabled.
* src/userdel.c, src/newusers.c, src/chpasswd.c, src/usermod.c,
src/groupdel.c, src/chgpasswd.c, src/useradd.c, src/groupmod.c,
src/groupadd.c, src/chage.c: Implement ACCT_TOOLS_SETUID
(--enable-account-tools-setuid).
* etc/pam.d/Makefile.am: Install the pam service file for the
above tools only when needed.
* src/useradd.c, src/userdel.c, src/usermod.c: It is no more
needed to initialize retval to PAM_SUCCESS.
2008-09-07 03:05:37 +05:30
|
|
|
#endif /* ACCT_TOOLS_SETUID */
|
2009-04-29 03:15:38 +05:30
|
|
|
#endif /* USE_PAM */
|
2007-12-29 03:35:51 +05:30
|
|
|
}
|
|
|
|
|
2007-12-29 03:48:55 +05:30
|
|
|
/*
|
|
|
|
* open_files - lock and open the password databases
|
|
|
|
*/
|
|
|
|
static void open_files (void)
|
2007-12-29 03:35:51 +05:30
|
|
|
{
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
2007-12-29 03:48:55 +05:30
|
|
|
* Lock the password file and open it for reading and writing. This
|
|
|
|
* will bring all of the entries into memory where they may be updated.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-12-31 10:27:54 +05:30
|
|
|
if (pw_lock () == 0) {
|
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
Added *_dbname() functions to retrieve the name of the databases.
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
*_name() functions renamed *setname().
* src/grpck.c, src/pwck.c: Likewise.
* lib/groupio.h, lib/pwio.h, lib/sgroupio.h, lib/shadowio.h: Added
the name of the arguments to the prototypes.
* src/chage, src/chfn.c, src/chgpasswd.c, src/chpasswd.c,
src/chsh.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c,
src/newusers.c, src/passwd.c, src/pwck.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c, src/usermod.c:
Harmonize the erro & syslog messages in case of failure of the
*_lock(), *_open(), *_close(), *_unlock(), *_remove() functions.
* src/chgpasswd.c, src/chpasswd.c, src/usermod.c: Avoid
capitalized messages.
* src/chpasswd.c, src/useradd.c, src/usermod.c: Harmonize messages
in case of inexistent entries.
* src/usermod.c: Harmonize messages in case of already existing
entries.
* src/newusers.c, src/useradd.c: Simplify PAM error handling.
* src/useradd.c: Report failures to unlock files (stderr, syslog,
and audit). But do not fail (continue).
* src/useradd.c (open_files): Do not report to syslog & audit
failures to lock or open the databases. This might be harmless,
and the logs were not already informed that a change was
requested.
* src/usermod.c: It's not the account which is unlocked, but its
password.
2008-08-06 21:27:31 +05:30
|
|
|
fprintf (stderr,
|
* src/chage.c, src/chgpasswd.c, src/chpasswd.c, src/chsh.c,
src/gpasswd.c, src/groupadd.c, src/groupdel.c, src/groupmems.c,
src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c,
src/newusers.c, src/passwd.c, src/pwck.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c, src/usermod.c: In
case of a lock failure, indicate to the user that she can try
again later. Do not log to syslog.
2008-08-22 07:50:53 +05:30
|
|
|
_("%s: cannot lock %s; try again later.\n"),
|
|
|
|
Prog, pw_dbname ());
|
2008-08-10 04:55:18 +05:30
|
|
|
fail_exit (1);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
* src/chfn.c, src/chgpasswd.c, src/chpasswd.c, src/gpasswd.c,
src/groupadd.c, src/groupdel.c, src/groupmems.c, src/groupmod.c,
src/grpconv.c, src/grpunconv.c, src/newusers.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c: Harmonize the name
of the variables keeping the lock status, to match the shadow
library prefixes.
2008-08-22 07:52:34 +05:30
|
|
|
pw_locked = true;
|
2015-02-27 18:47:25 +05:30
|
|
|
if (pw_open (O_CREAT | O_RDWR) == 0) {
|
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
Added *_dbname() functions to retrieve the name of the databases.
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
*_name() functions renamed *setname().
* src/grpck.c, src/pwck.c: Likewise.
* lib/groupio.h, lib/pwio.h, lib/sgroupio.h, lib/shadowio.h: Added
the name of the arguments to the prototypes.
* src/chage, src/chfn.c, src/chgpasswd.c, src/chpasswd.c,
src/chsh.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c,
src/newusers.c, src/passwd.c, src/pwck.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c, src/usermod.c:
Harmonize the erro & syslog messages in case of failure of the
*_lock(), *_open(), *_close(), *_unlock(), *_remove() functions.
* src/chgpasswd.c, src/chpasswd.c, src/usermod.c: Avoid
capitalized messages.
* src/chpasswd.c, src/useradd.c, src/usermod.c: Harmonize messages
in case of inexistent entries.
* src/usermod.c: Harmonize messages in case of already existing
entries.
* src/newusers.c, src/useradd.c: Simplify PAM error handling.
* src/useradd.c: Report failures to unlock files (stderr, syslog,
and audit). But do not fail (continue).
* src/useradd.c (open_files): Do not report to syslog & audit
failures to lock or open the databases. This might be harmless,
and the logs were not already informed that a change was
requested.
* src/usermod.c: It's not the account which is unlocked, but its
password.
2008-08-06 21:27:31 +05:30
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: cannot open %s\n"), Prog, pw_dbname ());
|
2008-08-10 04:55:18 +05:30
|
|
|
fail_exit (1);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:16:25 +05:30
|
|
|
|
2007-12-29 03:48:55 +05:30
|
|
|
/* Do the same for the shadowed database, if it exist */
|
2007-10-07 17:14:02 +05:30
|
|
|
if (is_shadow_pwd) {
|
2007-12-31 10:27:54 +05:30
|
|
|
if (spw_lock () == 0) {
|
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
Added *_dbname() functions to retrieve the name of the databases.
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
*_name() functions renamed *setname().
* src/grpck.c, src/pwck.c: Likewise.
* lib/groupio.h, lib/pwio.h, lib/sgroupio.h, lib/shadowio.h: Added
the name of the arguments to the prototypes.
* src/chage, src/chfn.c, src/chgpasswd.c, src/chpasswd.c,
src/chsh.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c,
src/newusers.c, src/passwd.c, src/pwck.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c, src/usermod.c:
Harmonize the erro & syslog messages in case of failure of the
*_lock(), *_open(), *_close(), *_unlock(), *_remove() functions.
* src/chgpasswd.c, src/chpasswd.c, src/usermod.c: Avoid
capitalized messages.
* src/chpasswd.c, src/useradd.c, src/usermod.c: Harmonize messages
in case of inexistent entries.
* src/usermod.c: Harmonize messages in case of already existing
entries.
* src/newusers.c, src/useradd.c: Simplify PAM error handling.
* src/useradd.c: Report failures to unlock files (stderr, syslog,
and audit). But do not fail (continue).
* src/useradd.c (open_files): Do not report to syslog & audit
failures to lock or open the databases. This might be harmless,
and the logs were not already informed that a change was
requested.
* src/usermod.c: It's not the account which is unlocked, but its
password.
2008-08-06 21:27:31 +05:30
|
|
|
fprintf (stderr,
|
* src/chage.c, src/chgpasswd.c, src/chpasswd.c, src/chsh.c,
src/gpasswd.c, src/groupadd.c, src/groupdel.c, src/groupmems.c,
src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c,
src/newusers.c, src/passwd.c, src/pwck.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c, src/usermod.c: In
case of a lock failure, indicate to the user that she can try
again later. Do not log to syslog.
2008-08-22 07:50:53 +05:30
|
|
|
_("%s: cannot lock %s; try again later.\n"),
|
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
Added *_dbname() functions to retrieve the name of the databases.
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
*_name() functions renamed *setname().
* src/grpck.c, src/pwck.c: Likewise.
* lib/groupio.h, lib/pwio.h, lib/sgroupio.h, lib/shadowio.h: Added
the name of the arguments to the prototypes.
* src/chage, src/chfn.c, src/chgpasswd.c, src/chpasswd.c,
src/chsh.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c,
src/newusers.c, src/passwd.c, src/pwck.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c, src/usermod.c:
Harmonize the erro & syslog messages in case of failure of the
*_lock(), *_open(), *_close(), *_unlock(), *_remove() functions.
* src/chgpasswd.c, src/chpasswd.c, src/usermod.c: Avoid
capitalized messages.
* src/chpasswd.c, src/useradd.c, src/usermod.c: Harmonize messages
in case of inexistent entries.
* src/usermod.c: Harmonize messages in case of already existing
entries.
* src/newusers.c, src/useradd.c: Simplify PAM error handling.
* src/useradd.c: Report failures to unlock files (stderr, syslog,
and audit). But do not fail (continue).
* src/useradd.c (open_files): Do not report to syslog & audit
failures to lock or open the databases. This might be harmless,
and the logs were not already informed that a change was
requested.
* src/usermod.c: It's not the account which is unlocked, but its
password.
2008-08-06 21:27:31 +05:30
|
|
|
Prog, spw_dbname ());
|
2008-08-10 04:55:18 +05:30
|
|
|
fail_exit (1);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
* src/chfn.c, src/chgpasswd.c, src/chpasswd.c, src/gpasswd.c,
src/groupadd.c, src/groupdel.c, src/groupmems.c, src/groupmod.c,
src/grpconv.c, src/grpunconv.c, src/newusers.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c: Harmonize the name
of the variables keeping the lock status, to match the shadow
library prefixes.
2008-08-22 07:52:34 +05:30
|
|
|
spw_locked = true;
|
2015-02-27 18:47:25 +05:30
|
|
|
if (spw_open (O_CREAT | O_RDWR) == 0) {
|
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
Added *_dbname() functions to retrieve the name of the databases.
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
*_name() functions renamed *setname().
* src/grpck.c, src/pwck.c: Likewise.
* lib/groupio.h, lib/pwio.h, lib/sgroupio.h, lib/shadowio.h: Added
the name of the arguments to the prototypes.
* src/chage, src/chfn.c, src/chgpasswd.c, src/chpasswd.c,
src/chsh.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c,
src/newusers.c, src/passwd.c, src/pwck.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c, src/usermod.c:
Harmonize the erro & syslog messages in case of failure of the
*_lock(), *_open(), *_close(), *_unlock(), *_remove() functions.
* src/chgpasswd.c, src/chpasswd.c, src/usermod.c: Avoid
capitalized messages.
* src/chpasswd.c, src/useradd.c, src/usermod.c: Harmonize messages
in case of inexistent entries.
* src/usermod.c: Harmonize messages in case of already existing
entries.
* src/newusers.c, src/useradd.c: Simplify PAM error handling.
* src/useradd.c: Report failures to unlock files (stderr, syslog,
and audit). But do not fail (continue).
* src/useradd.c (open_files): Do not report to syslog & audit
failures to lock or open the databases. This might be harmless,
and the logs were not already informed that a change was
requested.
* src/usermod.c: It's not the account which is unlocked, but its
password.
2008-08-06 21:27:31 +05:30
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: cannot open %s\n"),
|
|
|
|
Prog, spw_dbname ());
|
2008-08-10 04:55:18 +05:30
|
|
|
fail_exit (1);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
}
|
2007-12-29 03:48:55 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* close_files - close and unlock the password databases
|
|
|
|
*/
|
|
|
|
static void close_files (void)
|
|
|
|
{
|
|
|
|
if (is_shadow_pwd) {
|
2007-12-31 10:27:54 +05:30
|
|
|
if (spw_close () == 0) {
|
2007-12-29 03:48:55 +05:30
|
|
|
fprintf (stderr,
|
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
Added *_dbname() functions to retrieve the name of the databases.
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
*_name() functions renamed *setname().
* src/grpck.c, src/pwck.c: Likewise.
* lib/groupio.h, lib/pwio.h, lib/sgroupio.h, lib/shadowio.h: Added
the name of the arguments to the prototypes.
* src/chage, src/chfn.c, src/chgpasswd.c, src/chpasswd.c,
src/chsh.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c,
src/newusers.c, src/passwd.c, src/pwck.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c, src/usermod.c:
Harmonize the erro & syslog messages in case of failure of the
*_lock(), *_open(), *_close(), *_unlock(), *_remove() functions.
* src/chgpasswd.c, src/chpasswd.c, src/usermod.c: Avoid
capitalized messages.
* src/chpasswd.c, src/useradd.c, src/usermod.c: Harmonize messages
in case of inexistent entries.
* src/usermod.c: Harmonize messages in case of already existing
entries.
* src/newusers.c, src/useradd.c: Simplify PAM error handling.
* src/useradd.c: Report failures to unlock files (stderr, syslog,
and audit). But do not fail (continue).
* src/useradd.c (open_files): Do not report to syslog & audit
failures to lock or open the databases. This might be harmless,
and the logs were not already informed that a change was
requested.
* src/usermod.c: It's not the account which is unlocked, but its
password.
2008-08-06 21:27:31 +05:30
|
|
|
_("%s: failure while writing changes to %s\n"),
|
|
|
|
Prog, spw_dbname ());
|
2008-08-10 04:55:18 +05:30
|
|
|
SYSLOG ((LOG_ERR, "failure while writing changes to %s", spw_dbname ()));
|
|
|
|
fail_exit (1);
|
|
|
|
}
|
|
|
|
if (spw_unlock () == 0) {
|
|
|
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ());
|
|
|
|
SYSLOG ((LOG_ERR, "failed to unlock %s", spw_dbname ()));
|
|
|
|
/* continue */
|
2007-12-29 03:48:55 +05:30
|
|
|
}
|
* src/chfn.c, src/chgpasswd.c, src/chpasswd.c, src/gpasswd.c,
src/groupadd.c, src/groupdel.c, src/groupmems.c, src/groupmod.c,
src/grpconv.c, src/grpunconv.c, src/newusers.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c: Harmonize the name
of the variables keeping the lock status, to match the shadow
library prefixes.
2008-08-22 07:52:34 +05:30
|
|
|
spw_locked = false;
|
2007-12-29 03:48:55 +05:30
|
|
|
}
|
|
|
|
|
2007-12-31 10:27:54 +05:30
|
|
|
if (pw_close () == 0) {
|
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
Added *_dbname() functions to retrieve the name of the databases.
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
*_name() functions renamed *setname().
* src/grpck.c, src/pwck.c: Likewise.
* lib/groupio.h, lib/pwio.h, lib/sgroupio.h, lib/shadowio.h: Added
the name of the arguments to the prototypes.
* src/chage, src/chfn.c, src/chgpasswd.c, src/chpasswd.c,
src/chsh.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c,
src/newusers.c, src/passwd.c, src/pwck.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c, src/usermod.c:
Harmonize the erro & syslog messages in case of failure of the
*_lock(), *_open(), *_close(), *_unlock(), *_remove() functions.
* src/chgpasswd.c, src/chpasswd.c, src/usermod.c: Avoid
capitalized messages.
* src/chpasswd.c, src/useradd.c, src/usermod.c: Harmonize messages
in case of inexistent entries.
* src/usermod.c: Harmonize messages in case of already existing
entries.
* src/newusers.c, src/useradd.c: Simplify PAM error handling.
* src/useradd.c: Report failures to unlock files (stderr, syslog,
and audit). But do not fail (continue).
* src/useradd.c (open_files): Do not report to syslog & audit
failures to lock or open the databases. This might be harmless,
and the logs were not already informed that a change was
requested.
* src/usermod.c: It's not the account which is unlocked, but its
password.
2008-08-06 21:27:31 +05:30
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: failure while writing changes to %s\n"),
|
|
|
|
Prog, pw_dbname ());
|
2008-08-10 04:55:18 +05:30
|
|
|
SYSLOG ((LOG_ERR, "failure while writing changes to %s", pw_dbname ()));
|
|
|
|
fail_exit (1);
|
|
|
|
}
|
|
|
|
if (pw_unlock () == 0) {
|
|
|
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ());
|
|
|
|
SYSLOG ((LOG_ERR, "failed to unlock %s", pw_dbname ()));
|
|
|
|
/* continue */
|
2007-12-29 03:48:55 +05:30
|
|
|
}
|
* src/chfn.c, src/chgpasswd.c, src/chpasswd.c, src/gpasswd.c,
src/groupadd.c, src/groupdel.c, src/groupmems.c, src/groupmod.c,
src/grpconv.c, src/grpunconv.c, src/newusers.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c: Harmonize the name
of the variables keeping the lock status, to match the shadow
library prefixes.
2008-08-22 07:52:34 +05:30
|
|
|
pw_locked = false;
|
2007-12-29 03:48:55 +05:30
|
|
|
}
|
|
|
|
|
2022-03-31 14:15:19 +05:30
|
|
|
static const char *get_salt(void)
|
|
|
|
{
|
2022-04-01 06:56:29 +05:30
|
|
|
void *arg = NULL;
|
2022-03-31 14:15:19 +05:30
|
|
|
|
2022-04-02 09:18:51 +05:30
|
|
|
if (eflg || IS_CRYPT_METHOD("NONE")) {
|
2022-04-01 06:56:29 +05:30
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (md5flg) {
|
|
|
|
crypt_method = "MD5";
|
|
|
|
}
|
2022-03-31 14:15:19 +05:30
|
|
|
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT) || defined(USE_YESCRYPT)
|
2022-04-01 06:56:29 +05:30
|
|
|
if (sflg) {
|
2022-03-31 14:15:19 +05:30
|
|
|
#if defined(USE_SHA_CRYPT)
|
2022-04-02 09:18:51 +05:30
|
|
|
if (IS_CRYPT_METHOD("SHA256") || IS_CRYPT_METHOD("SHA512")) {
|
2022-04-01 06:56:29 +05:30
|
|
|
arg = &sha_rounds;
|
|
|
|
}
|
2022-03-31 14:15:19 +05:30
|
|
|
#endif /* USE_SHA_CRYPT */
|
|
|
|
#if defined(USE_BCRYPT)
|
2022-04-02 09:18:51 +05:30
|
|
|
if (IS_CRYPT_METHOD("BCRYPT")) {
|
2022-04-01 06:56:29 +05:30
|
|
|
arg = &bcrypt_rounds;
|
|
|
|
}
|
2022-03-31 14:15:19 +05:30
|
|
|
#endif /* USE_BCRYPT */
|
|
|
|
#if defined(USE_YESCRYPT)
|
2022-04-02 09:18:51 +05:30
|
|
|
if (IS_CRYPT_METHOD("YESCRYPT")) {
|
2022-04-01 06:56:29 +05:30
|
|
|
arg = &yescrypt_cost;
|
2022-03-31 14:15:19 +05:30
|
|
|
}
|
2022-04-01 06:56:29 +05:30
|
|
|
#endif /* USE_YESCRYPT */
|
2022-03-31 14:15:19 +05:30
|
|
|
}
|
2022-04-01 06:56:29 +05:30
|
|
|
#endif
|
|
|
|
return crypt_make_salt (crypt_method, arg);
|
2022-03-31 14:15:19 +05:30
|
|
|
}
|
|
|
|
|
2007-12-29 03:48:55 +05:30
|
|
|
int main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
char buf[BUFSIZ];
|
|
|
|
char *name;
|
|
|
|
char *newpwd;
|
|
|
|
char *cp;
|
2022-03-31 14:15:19 +05:30
|
|
|
const char *salt;
|
2007-12-29 03:48:55 +05:30
|
|
|
|
2010-03-26 02:05:59 +05:30
|
|
|
#ifdef USE_PAM
|
|
|
|
bool use_pam = true;
|
|
|
|
#endif /* USE_PAM */
|
2009-04-29 03:15:38 +05:30
|
|
|
|
2007-12-29 03:48:55 +05:30
|
|
|
int errors = 0;
|
|
|
|
int line = 0;
|
|
|
|
|
|
|
|
Prog = Basename (argv[0]);
|
2021-11-29 05:07:53 +05:30
|
|
|
log_set_progname(Prog);
|
|
|
|
log_set_logfd(stderr);
|
2007-12-29 03:48:55 +05:30
|
|
|
|
2008-06-10 01:16:11 +05:30
|
|
|
(void) setlocale (LC_ALL, "");
|
|
|
|
(void) bindtextdomain (PACKAGE, LOCALEDIR);
|
|
|
|
(void) textdomain (PACKAGE);
|
2007-12-29 03:48:55 +05:30
|
|
|
|
|
|
|
process_flags (argc, argv);
|
|
|
|
|
2022-03-31 14:18:52 +05:30
|
|
|
salt = get_salt();
|
|
|
|
process_root_flag ("-R", argc, argv);
|
|
|
|
|
2010-03-26 02:05:59 +05:30
|
|
|
#ifdef USE_PAM
|
|
|
|
if (md5flg || eflg || cflg) {
|
|
|
|
use_pam = false;
|
|
|
|
}
|
|
|
|
#endif /* USE_PAM */
|
|
|
|
|
2008-08-10 04:55:18 +05:30
|
|
|
OPENLOG ("chpasswd");
|
|
|
|
|
2007-12-29 03:48:55 +05:30
|
|
|
check_perms ();
|
|
|
|
|
2010-03-26 02:05:59 +05:30
|
|
|
#ifdef USE_PAM
|
|
|
|
if (!use_pam)
|
|
|
|
#endif /* USE_PAM */
|
|
|
|
{
|
|
|
|
is_shadow_pwd = spw_file_present ();
|
2007-12-29 03:48:55 +05:30
|
|
|
|
2010-03-26 02:05:59 +05:30
|
|
|
open_files ();
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Read each line, separating the user name from the password. The
|
|
|
|
* password entry for each user will be looked up in the appropriate
|
|
|
|
* file (shadow or passwd) and the password changed. For shadow
|
|
|
|
* files the last change date is set directly, for passwd files the
|
|
|
|
* last change date is set in the age only if aging information is
|
|
|
|
* present.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2023-02-01 18:20:48 +05:30
|
|
|
while (fgets (buf, sizeof buf, stdin) != NULL) {
|
2007-10-07 17:14:02 +05:30
|
|
|
line++;
|
2007-12-29 03:54:02 +05:30
|
|
|
cp = strrchr (buf, '\n');
|
|
|
|
if (NULL != cp) {
|
2007-10-07 17:14:02 +05:30
|
|
|
*cp = '\0';
|
|
|
|
} else {
|
2009-05-10 19:19:03 +05:30
|
|
|
if (feof (stdin) == 0) {
|
2018-11-16 11:11:30 +05:30
|
|
|
|
|
|
|
// Drop all remaining characters on this line.
|
2023-02-01 18:20:48 +05:30
|
|
|
while (fgets (buf, sizeof buf, stdin) != NULL) {
|
2018-11-16 11:11:30 +05:30
|
|
|
cp = strchr (buf, '\n');
|
|
|
|
if (cp != NULL) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-10 19:19:03 +05:30
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: line %d: line too long\n"),
|
|
|
|
Prog, line);
|
|
|
|
errors++;
|
|
|
|
continue;
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* The username is the first field. It is separated from the
|
|
|
|
* password with a ":" character which is replaced with a
|
|
|
|
* NUL to give the new password. The new password will then
|
|
|
|
* be encrypted in the normal fashion with a new salt
|
|
|
|
* generated, unless the '-e' is given, in which case it is
|
|
|
|
* assumed to already be encrypted.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
name = buf;
|
2007-12-29 03:54:02 +05:30
|
|
|
cp = strchr (name, ':');
|
|
|
|
if (NULL != cp) {
|
|
|
|
*cp = '\0';
|
|
|
|
cp++;
|
2007-10-07 17:14:02 +05:30
|
|
|
} else {
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr,
|
2007-12-29 04:00:02 +05:30
|
|
|
_("%s: line %d: missing new password\n"),
|
|
|
|
Prog, line);
|
2007-10-07 17:14:02 +05:30
|
|
|
errors++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
newpwd = cp;
|
2009-04-29 03:15:38 +05:30
|
|
|
|
|
|
|
#ifdef USE_PAM
|
2021-08-18 23:36:02 +05:30
|
|
|
if (use_pam) {
|
2017-10-23 01:54:32 +05:30
|
|
|
if (do_pam_passwd_non_interactive ("chpasswd", name, newpwd) != 0) {
|
2011-07-23 13:44:15 +05:30
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: (line %d, user %s) password not changed\n"),
|
|
|
|
Prog, line, name);
|
|
|
|
errors++;
|
|
|
|
}
|
2010-03-26 02:05:59 +05:30
|
|
|
} else
|
|
|
|
#endif /* USE_PAM */
|
|
|
|
{
|
|
|
|
const struct spwd *sp;
|
|
|
|
struct spwd newsp;
|
|
|
|
const struct passwd *pw;
|
|
|
|
struct passwd newpw;
|
|
|
|
|
2022-03-31 14:15:19 +05:30
|
|
|
if (salt) {
|
2013-08-04 02:37:06 +05:30
|
|
|
cp = pw_encrypt (newpwd, salt);
|
|
|
|
if (NULL == cp) {
|
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: failed to crypt password with salt '%s': %s\n"),
|
|
|
|
Prog, salt, strerror (errno));
|
|
|
|
fail_exit (1);
|
2013-07-28 22:11:11 +05:30
|
|
|
}
|
2007-10-07 17:15:58 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Get the password file entry for this user. The user must
|
|
|
|
* already exist.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
pw = pw_locate (name);
|
2007-12-31 10:27:54 +05:30
|
|
|
if (NULL == pw) {
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr,
|
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
Added *_dbname() functions to retrieve the name of the databases.
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
*_name() functions renamed *setname().
* src/grpck.c, src/pwck.c: Likewise.
* lib/groupio.h, lib/pwio.h, lib/sgroupio.h, lib/shadowio.h: Added
the name of the arguments to the prototypes.
* src/chage, src/chfn.c, src/chgpasswd.c, src/chpasswd.c,
src/chsh.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c,
src/newusers.c, src/passwd.c, src/pwck.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c, src/usermod.c:
Harmonize the erro & syslog messages in case of failure of the
*_lock(), *_open(), *_close(), *_unlock(), *_remove() functions.
* src/chgpasswd.c, src/chpasswd.c, src/usermod.c: Avoid
capitalized messages.
* src/chpasswd.c, src/useradd.c, src/usermod.c: Harmonize messages
in case of inexistent entries.
* src/usermod.c: Harmonize messages in case of already existing
entries.
* src/newusers.c, src/useradd.c: Simplify PAM error handling.
* src/useradd.c: Report failures to unlock files (stderr, syslog,
and audit). But do not fail (continue).
* src/useradd.c (open_files): Do not report to syslog & audit
failures to lock or open the databases. This might be harmless,
and the logs were not already informed that a change was
requested.
* src/usermod.c: It's not the account which is unlocked, but its
password.
2008-08-06 21:27:31 +05:30
|
|
|
_("%s: line %d: user '%s' does not exist\n"), Prog,
|
2007-12-29 04:00:02 +05:30
|
|
|
line, name);
|
2007-10-07 17:14:02 +05:30
|
|
|
errors++;
|
|
|
|
continue;
|
|
|
|
}
|
2007-12-29 04:04:14 +05:30
|
|
|
if (is_shadow_pwd) {
|
2011-07-28 20:47:28 +05:30
|
|
|
/* The shadow entry should be updated if the
|
|
|
|
* passwd entry has a password set to 'x'.
|
|
|
|
* But on the other hand, if there is already both
|
|
|
|
* a passwd and a shadow password, it's preferable
|
|
|
|
* to update both.
|
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
sp = spw_locate (name);
|
2011-07-28 20:47:28 +05:30
|
|
|
|
|
|
|
if ( (NULL == sp)
|
|
|
|
&& (strcmp (pw->pw_passwd,
|
|
|
|
SHADOW_PASSWD_STRING) == 0)) {
|
|
|
|
/* If the password is set to 'x' in
|
|
|
|
* passwd, but there are no entries in
|
|
|
|
* shadow, create one.
|
|
|
|
*/
|
|
|
|
newsp.sp_namp = name;
|
|
|
|
/* newsp.sp_pwdp = NULL; will be set later */
|
|
|
|
/* newsp.sp_lstchg= 0; will be set later */
|
|
|
|
newsp.sp_min = getdef_num ("PASS_MIN_DAYS", -1);
|
|
|
|
newsp.sp_max = getdef_num ("PASS_MAX_DAYS", -1);
|
|
|
|
newsp.sp_warn = getdef_num ("PASS_WARN_AGE", -1);
|
|
|
|
newsp.sp_inact = -1;
|
|
|
|
newsp.sp_expire= -1;
|
|
|
|
newsp.sp_flag = SHADOW_SP_FLAG_UNSET;
|
|
|
|
sp = &newsp;
|
|
|
|
}
|
2007-12-29 04:04:14 +05:30
|
|
|
} else {
|
2007-10-07 17:14:02 +05:30
|
|
|
sp = NULL;
|
2007-12-29 04:04:14 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* The freshly encrypted new password is merged into the
|
|
|
|
* user's password file entry and the last password change
|
|
|
|
* date is set to the current date.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-12-31 10:27:54 +05:30
|
|
|
if (NULL != sp) {
|
2007-10-07 17:14:02 +05:30
|
|
|
newsp = *sp;
|
|
|
|
newsp.sp_pwdp = cp;
|
2023-02-01 18:20:48 +05:30
|
|
|
newsp.sp_lstchg = gettime () / SCALE;
|
* libmisc/pwd2spwd.c, src/chpasswd.c, src/newusers.c,
src/passwd.c, src/pwck.c, src/pwconv.c, src/useradd.c,
src/usermod.c: On Jan 01, 1970, do not set the sp_lstchg field to
0 (which means that the password shall be changed during the next
login), but use -1 (password aging disabled).
* src/passwd.c: Do not check sp_min if sp_lstchg is null or -1.
2009-04-06 02:53:27 +05:30
|
|
|
if (0 == newsp.sp_lstchg) {
|
|
|
|
/* Better disable aging than requiring a
|
|
|
|
* password change */
|
2009-04-06 03:26:37 +05:30
|
|
|
newsp.sp_lstchg = -1;
|
* libmisc/pwd2spwd.c, src/chpasswd.c, src/newusers.c,
src/passwd.c, src/pwck.c, src/pwconv.c, src/useradd.c,
src/usermod.c: On Jan 01, 1970, do not set the sp_lstchg field to
0 (which means that the password shall be changed during the next
login), but use -1 (password aging disabled).
* src/passwd.c: Do not check sp_min if sp_lstchg is null or -1.
2009-04-06 02:53:27 +05:30
|
|
|
}
|
2011-07-28 20:47:28 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
if ( (NULL == sp)
|
|
|
|
|| (strcmp (pw->pw_passwd, SHADOW_PASSWD_STRING) != 0)) {
|
2007-10-07 17:14:02 +05:30
|
|
|
newpw = *pw;
|
|
|
|
newpw.pw_passwd = cp;
|
|
|
|
}
|
|
|
|
|
2021-08-18 23:36:02 +05:30
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* The updated password file entry is then put back and will
|
|
|
|
* be written to the password file later, after all the
|
|
|
|
* other entries have been updated as well.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-12-31 10:27:54 +05:30
|
|
|
if (NULL != sp) {
|
* src/groupmems.c: Check the return value of gr_update().
* src/chage.c, src/chfn.c, src/chgpasswd.c, src/chpasswd.c,
src/chsh.c, src/gpasswd.c, src/groupadd.c, src/groupmems.c,
src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c,
src/passwd.c, src/pwck.c, src/pwconv.c, src/pwunconv.c,
src/useradd.c, src/userdel.c, src/usermod.c: Harmonize the error
message sent to stderr in case of *_update () failure.
* src/chage.c, src/chsh.c, src/groupadd.c, src/passwd.c: Do not
log to syslog when pw_update() or spw_update() fail.
* src/newusers.c: Do not log specific error message to stderr when
sgr_update() fails.
* src/pwconv.c: Remove duplicated definition of Prog.
2008-08-30 23:57:34 +05:30
|
|
|
if (spw_update (&newsp) == 0) {
|
|
|
|
fprintf (stderr,
|
2008-08-30 23:57:59 +05:30
|
|
|
_("%s: line %d: failed to prepare the new %s entry '%s'\n"),
|
|
|
|
Prog, line, spw_dbname (), newsp.sp_namp);
|
* src/groupmems.c: Check the return value of gr_update().
* src/chage.c, src/chfn.c, src/chgpasswd.c, src/chpasswd.c,
src/chsh.c, src/gpasswd.c, src/groupadd.c, src/groupmems.c,
src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c,
src/passwd.c, src/pwck.c, src/pwconv.c, src/pwunconv.c,
src/useradd.c, src/userdel.c, src/usermod.c: Harmonize the error
message sent to stderr in case of *_update () failure.
* src/chage.c, src/chsh.c, src/groupadd.c, src/passwd.c: Do not
log to syslog when pw_update() or spw_update() fail.
* src/newusers.c: Do not log specific error message to stderr when
sgr_update() fails.
* src/pwconv.c: Remove duplicated definition of Prog.
2008-08-30 23:57:34 +05:30
|
|
|
errors++;
|
|
|
|
continue;
|
|
|
|
}
|
2011-07-28 20:47:28 +05:30
|
|
|
}
|
|
|
|
if ( (NULL == sp)
|
|
|
|
|| (strcmp (pw->pw_passwd, SHADOW_PASSWD_STRING) != 0)) {
|
2008-08-30 23:57:59 +05:30
|
|
|
if (pw_update (&newpw) == 0) {
|
* src/groupmems.c: Check the return value of gr_update().
* src/chage.c, src/chfn.c, src/chgpasswd.c, src/chpasswd.c,
src/chsh.c, src/gpasswd.c, src/groupadd.c, src/groupmems.c,
src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c,
src/passwd.c, src/pwck.c, src/pwconv.c, src/pwunconv.c,
src/useradd.c, src/userdel.c, src/usermod.c: Harmonize the error
message sent to stderr in case of *_update () failure.
* src/chage.c, src/chsh.c, src/groupadd.c, src/passwd.c: Do not
log to syslog when pw_update() or spw_update() fail.
* src/newusers.c: Do not log specific error message to stderr when
sgr_update() fails.
* src/pwconv.c: Remove duplicated definition of Prog.
2008-08-30 23:57:34 +05:30
|
|
|
fprintf (stderr,
|
2008-08-30 23:57:59 +05:30
|
|
|
_("%s: line %d: failed to prepare the new %s entry '%s'\n"),
|
|
|
|
Prog, line, pw_dbname (), newpw.pw_name);
|
* src/groupmems.c: Check the return value of gr_update().
* src/chage.c, src/chfn.c, src/chgpasswd.c, src/chpasswd.c,
src/chsh.c, src/gpasswd.c, src/groupadd.c, src/groupmems.c,
src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c,
src/passwd.c, src/pwck.c, src/pwconv.c, src/pwunconv.c,
src/useradd.c, src/userdel.c, src/usermod.c: Harmonize the error
message sent to stderr in case of *_update () failure.
* src/chage.c, src/chsh.c, src/groupadd.c, src/passwd.c: Do not
log to syslog when pw_update() or spw_update() fail.
* src/newusers.c: Do not log specific error message to stderr when
sgr_update() fails.
* src/pwconv.c: Remove duplicated definition of Prog.
2008-08-30 23:57:34 +05:30
|
|
|
errors++;
|
|
|
|
continue;
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2010-03-26 02:05:59 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Any detected errors will cause the entire set of changes to be
|
|
|
|
* aborted. Unlocking the password file will cause all of the
|
|
|
|
* changes to be ignored. Otherwise the file is closed, causing the
|
|
|
|
* changes to be written out all at once, and then unlocked
|
|
|
|
* afterwards.
|
2009-05-09 18:44:37 +05:30
|
|
|
*
|
|
|
|
* With PAM, it is not possible to delay the update of the
|
|
|
|
* password database.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2008-06-10 01:16:11 +05:30
|
|
|
if (0 != errors) {
|
2010-03-26 02:05:59 +05:30
|
|
|
#ifdef USE_PAM
|
|
|
|
if (!use_pam)
|
|
|
|
#endif /* USE_PAM */
|
|
|
|
{
|
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: error detected, changes ignored\n"),
|
|
|
|
Prog);
|
|
|
|
}
|
2008-08-10 04:55:18 +05:30
|
|
|
fail_exit (1);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:15:23 +05:30
|
|
|
|
2010-03-26 02:05:59 +05:30
|
|
|
#ifdef USE_PAM
|
|
|
|
if (!use_pam)
|
|
|
|
#endif /* USE_PAM */
|
|
|
|
{
|
2009-05-09 18:44:37 +05:30
|
|
|
/* Save the changes */
|
2010-03-26 02:05:59 +05:30
|
|
|
close_files ();
|
|
|
|
}
|
2007-10-07 17:15:23 +05:30
|
|
|
|
2007-12-29 03:48:55 +05:30
|
|
|
nscd_flush_cache ("passwd");
|
Flush sssd caches in addition to nscd caches
Some distributions, notably Fedora, have the following order of nsswitch
modules by default:
passwd: sss files
group: sss files
The advantage of serving local users through SSSD is that the nss_sss
module has a fast mmapped-cache that speeds up NSS lookups compared to
accessing the disk an opening the files on each NSS request.
Traditionally, this has been done with the help of nscd, but using nscd
in parallel with sssd is cumbersome, as both SSSD and nscd use their own
independent caching, so using nscd in setups where sssd is also serving
users from some remote domain (LDAP, AD, ...) can result in a bit of
unpredictability.
More details about why Fedora chose to use sss before files can be found
on e.g.:
https://fedoraproject.org//wiki/Changes/SSSDCacheForLocalUsers
or:
https://docs.pagure.org/SSSD.sssd/design_pages/files_provider.html
Now, even though sssd watches the passwd and group files with the help
of inotify, there can still be a small window where someone requests a
user or a group, finds that it doesn't exist, adds the entry and checks
again. Without some support in shadow-utils that would explicitly drop
the sssd caches, the inotify watch can fire a little late, so a
combination of commands like this:
getent passwd user || useradd user; getent passwd user
can result in the second getent passwd not finding the newly added user
as the racy behaviour might still return the cached negative hit from
the first getent passwd.
This patch more or less copies the already existing support that
shadow-utils had for dropping nscd caches, except using the "sss_cache"
tool that sssd ships.
2018-09-12 17:52:11 +05:30
|
|
|
sssd_flush_cache (SSSD_DB_PASSWD);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
2007-12-29 04:00:02 +05:30
|
|
|
|