2007-10-07 17:14:02 +05:30
|
|
|
/*
|
2021-12-05 21:05:27 +05:30
|
|
|
* SPDX-FileCopyrightText: 1989 - 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:16:07 +05:30
|
|
|
#include <ctype.h>
|
2007-10-07 17:14:02 +05:30
|
|
|
#include <fcntl.h>
|
2007-10-07 17:16:25 +05:30
|
|
|
#include <getopt.h>
|
2007-10-07 17:14:02 +05:30
|
|
|
#include <signal.h>
|
2007-10-07 17:16:07 +05:30
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2007-10-07 17:16:25 +05:30
|
|
|
#include <sys/types.h>
|
2007-10-07 17:14:02 +05:30
|
|
|
#include <time.h>
|
* 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
|
|
|
#ifdef ACCT_TOOLS_SETUID
|
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 */
|
* 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 */
|
2007-10-07 17:14:38 +05:30
|
|
|
#include <pwd.h>
|
2007-10-07 17:16:07 +05:30
|
|
|
#include "prototypes.h"
|
|
|
|
#include "defines.h"
|
|
|
|
#include "pwio.h"
|
|
|
|
#include "shadowio.h"
|
2021-11-29 05:07:53 +05:30
|
|
|
#include "shadowlog.h"
|
2010-01-30 Paweł Hajdan, Jr. <phajdan.jr@gentoo.org>
* NEWS: Add support for TCB.
* lib/tcbfuncs.h, lib/tcbfuncs.c, lib/Makefile.am: New library to
support TCB.
* lib/prototypes, libmisc/copydir.c (remove_tree): Add boolean
parameter remove_root.
* configure.in: Add conditional WITH_TCB.
* src/userdel.c, src/usermod.c: Add support for TCB. Update call to
remove_tree().
* src/pwconv.c, src/pwunconv.c: Should not be used with TCB enabled.
* src/vipw.c: Add support for TCB. Update call to remove_tree().
* src/useradd.c: Add support for TCB. Open the shadow file outside
of open_files().
* src/chage.c: Add support for TCB.
* src/Makefile.am: Install passwd sgid shadow when TCB is enabled.
* lib/getdefs.c, man/vipw.8.xml, man/login.defs.5.xml,
man/login.defs/TCB_AUTH_GROUP.xml, man/login.defs/USE_TCB.xml,
man/login.defs/TCB_SYMLINKS.xml, man/generate_mans.mak,
man/generate_mans.deps, man/Makefile.am: New configuration
parameters: TCB_AUTH_GROUP, TCB_SYMLINKS, USE_TCB.
* lib/shadowio.c, lib/commonio.c: Add support for TCB.
2010-03-04 23:41:13 +05:30
|
|
|
#ifdef WITH_TCB
|
|
|
|
#include "tcbfuncs.h"
|
|
|
|
#endif
|
* 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"
|
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Global variables
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
* 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;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-06-10 23:26:53 +05:30
|
|
|
static bool
|
|
|
|
dflg = false, /* set last password change date */
|
|
|
|
Eflg = false, /* set account expiration date */
|
2019-08-07 00:06:42 +05:30
|
|
|
iflg = false, /* set iso8601 date formatting */
|
2008-06-10 23:26:53 +05:30
|
|
|
Iflg = false, /* set password inactive after expiration */
|
|
|
|
lflg = false, /* show account aging information */
|
|
|
|
mflg = false, /* set minimum number of days before password change */
|
|
|
|
Mflg = false, /* set maximum number of days before password change */
|
|
|
|
Wflg = false; /* set expiration warning days */
|
|
|
|
static bool amroot = false;
|
|
|
|
|
|
|
|
static bool pw_locked = false; /* Indicate if the password file is locked */
|
|
|
|
static bool spw_locked = false; /* Indicate if the shadow file is locked */
|
2007-12-31 09:59:30 +05:30
|
|
|
/* The name and UID of the user being worked on */
|
|
|
|
static char user_name[BUFSIZ] = "";
|
|
|
|
static uid_t user_uid = -1;
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
static long mindays;
|
|
|
|
static long maxdays;
|
2009-04-11 04:04:42 +05:30
|
|
|
static long lstchgdate;
|
2007-10-07 17:14:59 +05:30
|
|
|
static long warndays;
|
|
|
|
static long inactdays;
|
2009-04-11 04:04:42 +05:30
|
|
|
static long expdate;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/* local function prototypes */
|
2023-02-08 00:20:36 +05:30
|
|
|
NORETURN static void usage (int status);
|
2007-10-07 17:14:59 +05:30
|
|
|
static int new_fields (void);
|
2008-06-14 02:53:09 +05:30
|
|
|
static void print_date (time_t date);
|
2007-10-07 17:14:59 +05:30
|
|
|
static void list_fields (void);
|
2007-12-29 16:12:25 +05:30
|
|
|
static void process_flags (int argc, char **argv);
|
|
|
|
static void check_flags (int argc, int opt_index);
|
|
|
|
static void check_perms (void);
|
2008-06-10 23:26:53 +05:30
|
|
|
static void open_files (bool readonly);
|
2007-12-29 16:12:25 +05:30
|
|
|
static void close_files (void);
|
2023-02-08 00:20:36 +05:30
|
|
|
NORETURN static void fail_exit (int code);
|
2007-12-31 09:59:30 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* fail_exit - do some cleanup and exit with the given error code
|
|
|
|
*/
|
2023-02-08 00:20:36 +05:30
|
|
|
NORETURN
|
|
|
|
static void
|
|
|
|
fail_exit (int code)
|
2007-12-31 09:59:30 +05:30
|
|
|
{
|
|
|
|
if (spw_locked) {
|
2008-08-07 13:32:52 +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 */
|
|
|
|
}
|
2007-12-31 09:59:30 +05:30
|
|
|
}
|
|
|
|
if (pw_locked) {
|
2008-08-07 13:32:52 +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 */
|
|
|
|
}
|
2007-12-31 09:59:30 +05:30
|
|
|
}
|
|
|
|
closelog ();
|
|
|
|
|
|
|
|
#ifdef WITH_AUDIT
|
|
|
|
if (E_SUCCESS != code) {
|
2008-06-14 02:53:09 +05:30
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
|
|
|
"change age",
|
|
|
|
user_name, (unsigned int) user_uid, 0);
|
2007-12-31 09:59:30 +05:30
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
exit (code);
|
|
|
|
}
|
2007-10-07 17:14:32 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
|
|
|
* usage - print command line syntax and exit
|
|
|
|
*/
|
2023-02-08 00:20:36 +05:30
|
|
|
NORETURN
|
|
|
|
static void
|
|
|
|
usage (int status)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2011-11-07 00:08:57 +05:30
|
|
|
FILE *usageout = (E_SUCCESS != status) ? stderr : stdout;
|
|
|
|
(void) fprintf (usageout,
|
|
|
|
_("Usage: %s [options] LOGIN\n"
|
|
|
|
"\n"
|
|
|
|
"Options:\n"),
|
|
|
|
Prog);
|
|
|
|
(void) fputs (_(" -d, --lastday LAST_DAY set date of last password change to LAST_DAY\n"), usageout);
|
|
|
|
(void) fputs (_(" -E, --expiredate EXPIRE_DATE set account expiration date to EXPIRE_DATE\n"), usageout);
|
|
|
|
(void) fputs (_(" -h, --help display this help message and exit\n"), usageout);
|
2019-08-07 00:06:42 +05:30
|
|
|
(void) fputs (_(" -i, --iso8601 use YYYY-MM-DD when printing dates\n"), usageout);
|
2011-11-07 00:08:57 +05:30
|
|
|
(void) fputs (_(" -I, --inactive INACTIVE set password inactive after expiration\n"
|
|
|
|
" to INACTIVE\n"), usageout);
|
|
|
|
(void) fputs (_(" -l, --list show account aging information\n"), usageout);
|
|
|
|
(void) fputs (_(" -m, --mindays MIN_DAYS set minimum number of days before password\n"
|
|
|
|
" change to MIN_DAYS\n"), usageout);
|
2018-01-17 17:51:48 +05:30
|
|
|
(void) fputs (_(" -M, --maxdays MAX_DAYS set maximum number of days before password\n"
|
2011-11-07 00:08:57 +05:30
|
|
|
" change to MAX_DAYS\n"), usageout);
|
|
|
|
(void) fputs (_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout);
|
|
|
|
(void) fputs (_(" -W, --warndays WARN_DAYS set expiration warning days to WARN_DAYS\n"), usageout);
|
|
|
|
(void) fputs ("\n", usageout);
|
* 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
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* new_fields - change the user's password aging information interactively.
|
|
|
|
*
|
2007-10-07 17:14:59 +05:30
|
|
|
* prompt the user for all of the password age values. set the fields
|
|
|
|
* from the user's response, or leave alone if nothing was entered. The
|
2007-10-07 17:14:02 +05:30
|
|
|
* value (-1) is used to indicate the field should be removed if possible.
|
2007-10-07 17:14:59 +05:30
|
|
|
* any other negative value is an error. very large positive values will
|
2007-10-07 17:14:02 +05:30
|
|
|
* be handled elsewhere.
|
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
static int new_fields (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:14:59 +05:30
|
|
|
char buf[200];
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-07-12 04:01:43 +05:30
|
|
|
(void) puts (_("Enter the new value, or press ENTER for the default"));
|
|
|
|
(void) puts ("");
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2011-10-19 01:53:33 +05:30
|
|
|
(void) snprintf (buf, sizeof buf, "%ld", mindays);
|
2007-10-07 17:14:59 +05:30
|
|
|
change_field (buf, sizeof buf, _("Minimum Password Age"));
|
2009-04-11 04:04:36 +05:30
|
|
|
if ( (getlong (buf, &mindays) == 0)
|
2007-12-29 16:36:35 +05:30
|
|
|
|| (mindays < -1)) {
|
2007-10-07 17:14:02 +05:30
|
|
|
return 0;
|
2007-12-29 16:36:35 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2011-10-19 01:53:33 +05:30
|
|
|
(void) snprintf (buf, sizeof buf, "%ld", maxdays);
|
2007-10-07 17:14:59 +05:30
|
|
|
change_field (buf, sizeof buf, _("Maximum Password Age"));
|
2009-04-11 04:04:36 +05:30
|
|
|
if ( (getlong (buf, &maxdays) == 0)
|
2007-12-29 16:36:35 +05:30
|
|
|
|| (maxdays < -1)) {
|
2007-10-07 17:14:02 +05:30
|
|
|
return 0;
|
2007-12-29 16:36:35 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2020-07-12 21:26:38 +05:30
|
|
|
if (-1 == lstchgdate || lstchgdate > LONG_MAX / SCALE) {
|
2011-09-19 01:54:36 +05:30
|
|
|
strcpy (buf, "-1");
|
|
|
|
} else {
|
2021-12-22 20:02:17 +05:30
|
|
|
date_to_str (sizeof(buf), buf, lstchgdate * SCALE);
|
2011-09-19 01:54:36 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
change_field (buf, sizeof buf, _("Last Password Change (YYYY-MM-DD)"));
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2011-09-19 01:54:36 +05:30
|
|
|
if (strcmp (buf, "-1") == 0) {
|
2009-04-11 04:04:42 +05:30
|
|
|
lstchgdate = -1;
|
2007-12-29 17:04:31 +05:30
|
|
|
} else {
|
2009-04-11 04:04:42 +05:30
|
|
|
lstchgdate = strtoday (buf);
|
2011-09-19 01:54:36 +05:30
|
|
|
if (lstchgdate <= -1) {
|
2007-12-29 17:04:31 +05:30
|
|
|
return 0;
|
|
|
|
}
|
2007-12-29 16:36:35 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2011-10-19 01:53:33 +05:30
|
|
|
(void) snprintf (buf, sizeof buf, "%ld", warndays);
|
2007-10-07 17:14:02 +05:30
|
|
|
change_field (buf, sizeof buf, _("Password Expiration Warning"));
|
2009-04-11 04:04:36 +05:30
|
|
|
if ( (getlong (buf, &warndays) == 0)
|
2007-12-29 16:36:35 +05:30
|
|
|
|| (warndays < -1)) {
|
2007-10-07 17:14:02 +05:30
|
|
|
return 0;
|
2007-12-29 16:36:35 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2011-10-19 01:53:33 +05:30
|
|
|
(void) snprintf (buf, sizeof buf, "%ld", inactdays);
|
2007-10-07 17:14:59 +05:30
|
|
|
change_field (buf, sizeof buf, _("Password Inactive"));
|
2009-04-11 04:04:36 +05:30
|
|
|
if ( (getlong (buf, &inactdays) == 0)
|
2007-12-29 16:36:35 +05:30
|
|
|
|| (inactdays < -1)) {
|
2007-10-07 17:14:02 +05:30
|
|
|
return 0;
|
2007-12-29 16:36:35 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2020-07-12 21:26:38 +05:30
|
|
|
if (-1 == expdate || LONG_MAX / SCALE < expdate) {
|
2011-09-19 01:54:36 +05:30
|
|
|
strcpy (buf, "-1");
|
|
|
|
} else {
|
2021-12-22 20:02:17 +05:30
|
|
|
date_to_str (sizeof(buf), buf, expdate * SCALE);
|
2011-09-19 01:54:36 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
change_field (buf, sizeof buf,
|
2007-12-29 16:49:39 +05:30
|
|
|
_("Account Expiration Date (YYYY-MM-DD)"));
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2011-09-19 01:54:36 +05:30
|
|
|
if (strcmp (buf, "-1") == 0) {
|
2009-04-11 04:04:42 +05:30
|
|
|
expdate = -1;
|
2007-12-29 17:04:31 +05:30
|
|
|
} else {
|
2009-04-11 04:04:42 +05:30
|
|
|
expdate = strtoday (buf);
|
2011-09-19 01:54:36 +05:30
|
|
|
if (expdate <= -1) {
|
2007-12-29 17:04:31 +05:30
|
|
|
return 0;
|
|
|
|
}
|
2007-12-29 16:36:35 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
static void print_date (time_t date)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
struct tm *tp;
|
|
|
|
char buf[80];
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
tp = gmtime (&date);
|
2008-07-12 04:01:43 +05:30
|
|
|
if (NULL == tp) {
|
2011-10-19 01:53:33 +05:30
|
|
|
(void) printf ("time_t: %lu\n", (unsigned long)date);
|
2008-07-12 04:01:43 +05:30
|
|
|
} else {
|
2022-10-05 15:41:28 +05:30
|
|
|
(void) strftime (buf, sizeof buf, iflg ? "%Y-%m-%d" : "%b %d, %Y", tp);
|
2008-07-12 04:01:43 +05:30
|
|
|
(void) puts (buf);
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* list_fields - display the current values of the expiration fields
|
|
|
|
*
|
2007-10-07 17:14:59 +05:30
|
|
|
* display the password age information from the password fields. Date
|
2007-10-07 17:15:40 +05:30
|
|
|
* values will be displayed as a calendar date, or the word "never" if
|
2007-10-07 17:14:02 +05:30
|
|
|
* the date is 1/1/70, which is day number 0.
|
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
static void list_fields (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
long changed = 0;
|
|
|
|
long expires;
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:15:40 +05:30
|
|
|
* The "last change" date is either "never" or the date the password
|
2007-10-07 17:14:59 +05:30
|
|
|
* was last modified. The date is the number of days since 1/1/1970.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2008-07-12 04:01:43 +05:30
|
|
|
(void) fputs (_("Last password change\t\t\t\t\t: "), stdout);
|
2020-07-12 21:26:38 +05:30
|
|
|
if (lstchgdate < 0 || lstchgdate > LONG_MAX / SCALE) {
|
2008-07-12 04:01:43 +05:30
|
|
|
(void) puts (_("never"));
|
2009-04-11 04:04:42 +05:30
|
|
|
} else if (lstchgdate == 0) {
|
2008-07-12 04:01:43 +05:30
|
|
|
(void) puts (_("password must be changed"));
|
2007-10-07 17:14:02 +05:30
|
|
|
} else {
|
2009-04-11 04:04:42 +05:30
|
|
|
changed = lstchgdate * SCALE;
|
2008-06-14 02:53:09 +05:30
|
|
|
print_date ((time_t) changed);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* The password expiration date is determined from the last change
|
|
|
|
* date plus the number of days the password is valid for.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2008-07-12 04:01:43 +05:30
|
|
|
(void) fputs (_("Password expires\t\t\t\t\t: "), stdout);
|
2009-04-11 04:04:42 +05:30
|
|
|
if (lstchgdate == 0) {
|
2009-04-06 02:53:17 +05:30
|
|
|
(void) puts (_("password must be changed"));
|
2009-04-11 04:04:42 +05:30
|
|
|
} else if ( (lstchgdate < 0)
|
2009-04-06 02:53:17 +05:30
|
|
|
|| (maxdays >= (10000 * (DAY / SCALE)))
|
2020-07-12 21:26:38 +05:30
|
|
|
|| (maxdays < 0)
|
|
|
|
|| ((LONG_MAX - changed) / SCALE < maxdays)) {
|
2008-07-12 04:01:43 +05:30
|
|
|
(void) puts (_("never"));
|
2007-10-07 17:14:02 +05:30
|
|
|
} else {
|
|
|
|
expires = changed + maxdays * SCALE;
|
2008-06-14 02:53:09 +05:30
|
|
|
print_date ((time_t) expires);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* The account becomes inactive if the password is expired for more
|
|
|
|
* than "inactdays". The expiration date is calculated and the
|
|
|
|
* number of inactive days is added. The resulting date is when the
|
|
|
|
* active will be disabled.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2008-07-12 04:01:43 +05:30
|
|
|
(void) fputs (_("Password inactive\t\t\t\t\t: "), stdout);
|
2009-04-11 04:04:42 +05:30
|
|
|
if (lstchgdate == 0) {
|
2009-04-06 02:53:17 +05:30
|
|
|
(void) puts (_("password must be changed"));
|
2009-04-11 04:04:42 +05:30
|
|
|
} else if ( (lstchgdate < 0)
|
2009-04-06 02:53:17 +05:30
|
|
|
|| (inactdays < 0)
|
|
|
|
|| (maxdays >= (10000 * (DAY / SCALE)))
|
2020-07-12 21:26:38 +05:30
|
|
|
|| (maxdays < 0)
|
|
|
|
|| (maxdays > LONG_MAX - inactdays)
|
|
|
|
|| ((LONG_MAX - changed) / SCALE < maxdays + inactdays)) {
|
2008-07-12 04:01:43 +05:30
|
|
|
(void) puts (_("never"));
|
2007-10-07 17:14:02 +05:30
|
|
|
} else {
|
|
|
|
expires = changed + (maxdays + inactdays) * SCALE;
|
2008-06-14 02:53:09 +05:30
|
|
|
print_date ((time_t) expires);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The account will expire on the given date regardless of the
|
|
|
|
* password expiring or not.
|
|
|
|
*/
|
2008-07-12 04:01:43 +05:30
|
|
|
(void) fputs (_("Account expires\t\t\t\t\t\t: "), stdout);
|
2020-07-12 21:26:38 +05:30
|
|
|
if (expdate < 0 || LONG_MAX / SCALE < expdate) {
|
2008-07-12 04:01:43 +05:30
|
|
|
(void) puts (_("never"));
|
2007-10-07 17:14:02 +05:30
|
|
|
} else {
|
2009-04-11 04:04:42 +05:30
|
|
|
expires = expdate * SCALE;
|
2008-06-14 02:53:09 +05:30
|
|
|
print_date ((time_t) expires);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:15:40 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Start with the easy numbers - the number of days before the
|
|
|
|
* password can be changed, the number of days after which the
|
2017-10-22 13:54:23 +05:30
|
|
|
* password must be changed, the number of days before the password
|
2007-10-07 17:15:40 +05:30
|
|
|
* expires that the user is told, and the number of days after the
|
|
|
|
* password expires that the account becomes unusable.
|
|
|
|
*/
|
2007-10-07 17:16:07 +05:30
|
|
|
printf (_("Minimum number of days between password change\t\t: %ld\n"),
|
2007-12-29 16:49:39 +05:30
|
|
|
mindays);
|
2007-10-07 17:16:07 +05:30
|
|
|
printf (_("Maximum number of days between password change\t\t: %ld\n"),
|
2007-12-29 16:49:39 +05:30
|
|
|
maxdays);
|
2007-10-07 17:16:07 +05:30
|
|
|
printf (_("Number of days of warning before password expires\t: %ld\n"),
|
2007-12-29 16:49:39 +05:30
|
|
|
warndays);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-12-31 09:59:30 +05:30
|
|
|
/*
|
|
|
|
* process_flags - parse the command line options
|
|
|
|
*
|
|
|
|
* It will not return if an error is encountered.
|
|
|
|
*/
|
2007-12-29 16:12:25 +05:30
|
|
|
static void process_flags (int argc, char **argv)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
/*
|
2007-12-29 16:12:25 +05:30
|
|
|
* Parse the command line options.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-12-29 16:12:25 +05:30
|
|
|
int c;
|
|
|
|
static struct option long_options[] = {
|
* 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
|
|
|
{"lastday", required_argument, NULL, 'd'},
|
2007-12-29 16:12:25 +05:30
|
|
|
{"expiredate", required_argument, NULL, 'E'},
|
* 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
|
|
|
{"help", no_argument, NULL, 'h'},
|
|
|
|
{"inactive", required_argument, NULL, 'I'},
|
|
|
|
{"list", no_argument, NULL, 'l'},
|
|
|
|
{"mindays", required_argument, NULL, 'm'},
|
|
|
|
{"maxdays", required_argument, NULL, 'M'},
|
|
|
|
{"root", required_argument, NULL, 'R'},
|
|
|
|
{"warndays", required_argument, NULL, 'W'},
|
2019-08-07 00:06:42 +05:30
|
|
|
{"iso8601", no_argument, NULL, 'i'},
|
2007-12-29 16:12:25 +05:30
|
|
|
{NULL, 0, NULL, '\0'}
|
|
|
|
};
|
|
|
|
|
2019-08-07 00:06:42 +05:30
|
|
|
while ((c = getopt_long (argc, argv, "d:E:hiI:lm:M:R:W:",
|
2011-11-07 00:08:45 +05:30
|
|
|
long_options, NULL)) != -1) {
|
2007-12-29 16:12:25 +05:30
|
|
|
switch (c) {
|
|
|
|
case 'd':
|
2008-06-10 23:26:53 +05:30
|
|
|
dflg = true;
|
2010-03-18 17:23:49 +05:30
|
|
|
lstchgdate = strtoday (optarg);
|
|
|
|
if (lstchgdate < -1) {
|
2009-04-11 04:04:36 +05:30
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: invalid date '%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-12-29 16:36:35 +05:30
|
|
|
}
|
2007-12-29 16:12:25 +05:30
|
|
|
break;
|
|
|
|
case 'E':
|
2008-06-10 23:26:53 +05:30
|
|
|
Eflg = true;
|
2010-03-18 17:23:49 +05:30
|
|
|
expdate = strtoday (optarg);
|
|
|
|
if (expdate < -1) {
|
2009-04-11 04:04:36 +05:30
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: invalid date '%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-12-29 16:36:35 +05:30
|
|
|
}
|
2007-12-29 16:12:25 +05:30
|
|
|
break;
|
|
|
|
case 'h':
|
* 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_SUCCESS);
|
2011-10-19 01:53:33 +05:30
|
|
|
/*@notreached@*/break;
|
2019-08-07 00:06:42 +05:30
|
|
|
case 'i':
|
|
|
|
iflg = true;
|
|
|
|
break;
|
2007-12-29 16:12:25 +05:30
|
|
|
case 'I':
|
2008-06-10 23:26:53 +05:30
|
|
|
Iflg = true;
|
2009-04-11 04:04:36 +05:30
|
|
|
if ( (getlong (optarg, &inactdays) == 0)
|
|
|
|
|| (inactdays < -1)) {
|
|
|
|
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);
|
2009-04-11 04:04:36 +05:30
|
|
|
}
|
2007-12-29 16:12:25 +05:30
|
|
|
break;
|
|
|
|
case 'l':
|
2008-06-10 23:26:53 +05:30
|
|
|
lflg = true;
|
2007-12-29 16:12:25 +05:30
|
|
|
break;
|
|
|
|
case 'm':
|
2008-06-10 23:26:53 +05:30
|
|
|
mflg = true;
|
2009-04-11 04:04:36 +05:30
|
|
|
if ( (getlong (optarg, &mindays) == 0)
|
|
|
|
|| (mindays < -1)) {
|
|
|
|
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);
|
2009-04-11 04:04:36 +05:30
|
|
|
}
|
2007-12-29 16:12:25 +05:30
|
|
|
break;
|
|
|
|
case 'M':
|
2008-06-10 23:26:53 +05:30
|
|
|
Mflg = true;
|
2009-04-11 04:04:36 +05:30
|
|
|
if ( (getlong (optarg, &maxdays) == 0)
|
|
|
|
|| (maxdays < -1)) {
|
|
|
|
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);
|
2009-04-11 04:04:36 +05:30
|
|
|
}
|
2007-12-29 16:12:25 +05:30
|
|
|
break;
|
2011-11-07 00:08:57 +05:30
|
|
|
case 'R': /* no-op, handled in process_root_flag () */
|
|
|
|
break;
|
2007-12-29 16:12:25 +05:30
|
|
|
case 'W':
|
2008-06-10 23:26:53 +05:30
|
|
|
Wflg = true;
|
2009-04-11 04:04:36 +05:30
|
|
|
if ( (getlong (optarg, &warndays) == 0)
|
|
|
|
|| (warndays < -1)) {
|
|
|
|
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);
|
2009-04-11 04:04:36 +05:30
|
|
|
}
|
2007-12-29 16:12:25 +05:30
|
|
|
break;
|
|
|
|
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);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-29 16:12:25 +05:30
|
|
|
check_flags (argc, optind);
|
|
|
|
}
|
|
|
|
|
2007-12-31 09:59:30 +05:30
|
|
|
/*
|
|
|
|
* check_flags - check flags and parameters consistency
|
|
|
|
*
|
|
|
|
* It will not return if an error is encountered.
|
|
|
|
*/
|
2007-12-29 16:12:25 +05:30
|
|
|
static void check_flags (int argc, int opt_index)
|
|
|
|
{
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Make certain the flags do not conflict and that there is a user
|
|
|
|
* name on the command line.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
2007-12-29 16:12:25 +05:30
|
|
|
if (argc != opt_index + 1) {
|
* 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-12-29 16:12:25 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:15:23 +05:30
|
|
|
if (lflg && (mflg || Mflg || dflg || Wflg || Iflg || Eflg)) {
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr,
|
2007-12-29 16:49:39 +05:30
|
|
|
_("%s: do not include \"l\" with other flags\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-10-07 17:14:02 +05:30
|
|
|
}
|
2007-12-29 16:12:25 +05:30
|
|
|
}
|
|
|
|
|
2007-12-31 09:59:30 +05:30
|
|
|
/*
|
|
|
|
* check_perms - check if the caller is allowed to add a group
|
|
|
|
*
|
|
|
|
* Non-root users are only allowed to display their aging information.
|
|
|
|
* (we will later make sure that the user is only listing her aging
|
|
|
|
* information)
|
|
|
|
*
|
2008-01-02 01:23:33 +05:30
|
|
|
* With PAM support, the setuid bit can be set on chage to allow
|
2007-12-31 09:59:30 +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.
|
|
|
|
*/
|
2007-12-29 16:12:25 +05:30
|
|
|
static void check_perms (void)
|
|
|
|
{
|
* 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
|
|
|
#ifdef ACCT_TOOLS_SETUID
|
2007-12-29 16:12:25 +05:30
|
|
|
#ifdef USE_PAM
|
* 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;
|
2007-12-29 16:49:39 +05:30
|
|
|
struct passwd *pampw;
|
2007-12-29 16:12:25 +05:30
|
|
|
int 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 /* USE_PAM */
|
|
|
|
#endif /* ACCT_TOOLS_SETUID */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* An unprivileged user can ask for their own aging information, but
|
|
|
|
* only root can change it, or list another user's aging
|
2007-10-07 17:14:02 +05:30
|
|
|
* information.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:14 +05:30
|
|
|
if (!amroot && !lflg) {
|
2007-10-07 17:16:25 +05:30
|
|
|
fprintf (stderr, _("%s: Permission denied.\n"), Prog);
|
2007-12-31 09:59:30 +05:30
|
|
|
fail_exit (E_NOPERM);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:16:07 +05:30
|
|
|
|
* 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
|
|
|
#ifdef ACCT_TOOLS_SETUID
|
2007-10-07 17:14:59 +05:30
|
|
|
#ifdef USE_PAM
|
2007-12-29 16:49:39 +05:30
|
|
|
pampw = getpwuid (getuid ()); /* local, no need for xgetpwuid */
|
2008-07-12 04:01:43 +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 (E_NOPERM);
|
2007-10-07 17:14:59 +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 ("chage", pampw->pw_name, &conv, &pamh);
|
|
|
|
|
2008-07-12 04:01:43 +05:30
|
|
|
if (PAM_SUCCESS == retval) {
|
2007-10-07 17:14:59 +05:30
|
|
|
retval = pam_authenticate (pamh, 0);
|
|
|
|
}
|
|
|
|
|
2008-07-12 04:01:43 +05:30
|
|
|
if (PAM_SUCCESS == retval) {
|
2007-10-07 17:14:59 +05:30
|
|
|
retval = pam_acct_mgmt (pamh, 0);
|
|
|
|
}
|
|
|
|
|
2008-07-12 04:01:43 +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-12-31 09:59:30 +05:30
|
|
|
fail_exit (E_NOPERM);
|
2007-10-07 17:14:59 +05:30
|
|
|
}
|
* 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);
|
2007-10-07 17:14:59 +05:30
|
|
|
#endif /* USE_PAM */
|
* 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 */
|
2007-12-29 16:12:25 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-12-31 09:59:30 +05:30
|
|
|
/*
|
|
|
|
* open_files - open the shadow database
|
|
|
|
*
|
2008-01-01 19:42:34 +05:30
|
|
|
* In read-only mode, the databases are not locked and are opened
|
2007-12-31 09:59:30 +05:30
|
|
|
* only for reading.
|
|
|
|
*/
|
2008-06-10 23:26:53 +05:30
|
|
|
static void open_files (bool readonly)
|
2007-12-29 16:12:25 +05:30
|
|
|
{
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
2007-12-31 09:59:30 +05:30
|
|
|
* Lock and open the password file. This loads all of the password
|
2007-10-07 17:14:59 +05:30
|
|
|
* file entries into memory. Then we get a pointer to the password
|
|
|
|
* file entry for the requested user.
|
|
|
|
*/
|
2007-12-31 09:59:30 +05:30
|
|
|
if (!readonly) {
|
* 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
|
|
|
if (pw_lock () == 0) {
|
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: cannot lock %s; try again later.\n"),
|
|
|
|
Prog, pw_dbname ());
|
|
|
|
fail_exit (E_NOPERM);
|
|
|
|
}
|
2008-06-10 23:26:53 +05:30
|
|
|
pw_locked = true;
|
2007-12-31 09:59:30 +05:30
|
|
|
}
|
2015-02-27 18:47:25 +05:30
|
|
|
if (pw_open (readonly ? O_RDONLY: 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 ());
|
* src/chfn.c: Do not exit on pw_unlock failures.
* src/grpconv.c, src/grpunconv.c, src/pwconv.c, src/pwunconv.c,
src/vipw.c: Open syslog with the right identification name.
* src/vipw.c: Log unlock errors to syslog.
* src/vipw.c: Log edits to syslog.
* src/chage.c, src/chfn.c, src/chsh.c, src/gpasswd.c,
src/groupadd.c, src/groupdel.c, src/groupmod.c, src/grpconv.c,
src/grpunconv.c, src/passwd.c, src/pwck.c, src/pwunconv.c,
src/useradd.c, src/usermod.c: Harmonize the syslog levels. Failure
to close or unlock are errors. Failure to open files are warnings.
2008-08-22 08:00:33 +05:30
|
|
|
SYSLOG ((LOG_WARN, "cannot open %s", pw_dbname ()));
|
2007-12-31 09:59:30 +05:30
|
|
|
fail_exit (E_NOPERM);
|
2007-10-07 17:14:59 +05:30
|
|
|
}
|
2007-10-07 17:17:01 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* For shadow password files we have to lock the file and read in
|
|
|
|
* the entries as was done for the password file. The user entries
|
|
|
|
* does not have to exist in this case; a new entry will be created
|
|
|
|
* for this user if one does not exist already.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-12-31 09:59:30 +05:30
|
|
|
if (!readonly) {
|
* 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
|
|
|
if (spw_lock () == 0) {
|
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: cannot lock %s; try again later.\n"),
|
|
|
|
Prog, spw_dbname ());
|
|
|
|
fail_exit (E_NOPERM);
|
|
|
|
}
|
2008-06-10 23:26:53 +05:30
|
|
|
spw_locked = true;
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2015-02-27 18:47:25 +05:30
|
|
|
if (spw_open (readonly ? O_RDONLY: O_CREAT | O_RDWR) == 0) {
|
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: cannot open %s\n"), Prog, spw_dbname ());
|
* src/chfn.c: Do not exit on pw_unlock failures.
* src/grpconv.c, src/grpunconv.c, src/pwconv.c, src/pwunconv.c,
src/vipw.c: Open syslog with the right identification name.
* src/vipw.c: Log unlock errors to syslog.
* src/vipw.c: Log edits to syslog.
* src/chage.c, src/chfn.c, src/chsh.c, src/gpasswd.c,
src/groupadd.c, src/groupdel.c, src/groupmod.c, src/grpconv.c,
src/grpunconv.c, src/passwd.c, src/pwck.c, src/pwunconv.c,
src/useradd.c, src/usermod.c: Harmonize the syslog levels. Failure
to close or unlock are errors. Failure to open files are warnings.
2008-08-22 08:00:33 +05:30
|
|
|
SYSLOG ((LOG_WARN, "cannot open %s", spw_dbname ()));
|
2007-12-31 09:59:30 +05:30
|
|
|
fail_exit (E_NOPERM);
|
2007-10-07 17:14:59 +05:30
|
|
|
}
|
2007-12-29 16:12:25 +05:30
|
|
|
}
|
|
|
|
|
2007-12-31 09:59:30 +05:30
|
|
|
/*
|
|
|
|
* close_files - close and unlock the password/shadow databases
|
|
|
|
*/
|
2007-12-29 16:12:25 +05:30
|
|
|
static void close_files (void)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Now close the shadow password file, which will cause all of the
|
|
|
|
* entries to be re-written.
|
|
|
|
*/
|
2007-12-29 16:36:35 +05:30
|
|
|
if (spw_close () == 0) {
|
2007-12-29 16:12:25 +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 ());
|
|
|
|
SYSLOG ((LOG_ERR, "failure while writing changes to %s", spw_dbname ()));
|
2007-12-31 09:59:30 +05:30
|
|
|
fail_exit (E_NOPERM);
|
2007-12-29 16:12:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Close the password file. If any entries were modified, the file
|
|
|
|
* will be re-written.
|
|
|
|
*/
|
2007-12-29 16:36:35 +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 ());
|
|
|
|
SYSLOG ((LOG_ERR, "failure while writing changes to %s", pw_dbname ()));
|
2007-12-31 09:59:30 +05:30
|
|
|
fail_exit (E_NOPERM);
|
2007-12-29 16:12:25 +05:30
|
|
|
}
|
2008-08-07 13:32:52 +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 */
|
|
|
|
}
|
2008-06-10 23:26:53 +05:30
|
|
|
spw_locked = false;
|
2008-08-07 13:32:52 +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 */
|
|
|
|
}
|
2008-06-10 23:26:53 +05:30
|
|
|
pw_locked = false;
|
2007-12-31 09:59:30 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* update_age - update the aging information in the database
|
|
|
|
*
|
|
|
|
* It will not return in case of error
|
|
|
|
*/
|
2011-10-19 01:53:33 +05:30
|
|
|
static void update_age (/*@null@*/const struct spwd *sp,
|
|
|
|
/*@notnull@*/const struct passwd *pw)
|
2007-12-31 09:59:30 +05:30
|
|
|
{
|
|
|
|
struct spwd spwent;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* There was no shadow entry. The new entry will have the encrypted
|
|
|
|
* password transferred from the normal password file along with the
|
|
|
|
* aging information.
|
|
|
|
*/
|
|
|
|
if (NULL == sp) {
|
|
|
|
struct passwd pwent = *pw;
|
|
|
|
|
|
|
|
memzero (&spwent, sizeof spwent);
|
2011-11-20 03:26:10 +05:30
|
|
|
spwent.sp_namp = xstrdup (pwent.pw_name);
|
|
|
|
spwent.sp_pwdp = xstrdup (pwent.pw_passwd);
|
2008-06-14 02:53:09 +05:30
|
|
|
spwent.sp_flag = SHADOW_SP_FLAG_UNSET;
|
2007-12-31 09:59:30 +05:30
|
|
|
|
|
|
|
pwent.pw_passwd = SHADOW_PASSWD_STRING; /* XXX warning: const */
|
|
|
|
if (pw_update (&pwent) == 0) {
|
|
|
|
fprintf (stderr,
|
* 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
|
|
|
_("%s: failed to prepare the new %s entry '%s'\n"), Prog, pw_dbname (), pwent.pw_name);
|
2007-12-31 09:59:30 +05:30
|
|
|
fail_exit (E_NOPERM);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
spwent.sp_namp = xstrdup (sp->sp_namp);
|
|
|
|
spwent.sp_pwdp = xstrdup (sp->sp_pwdp);
|
|
|
|
spwent.sp_flag = sp->sp_flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy the fields back to the shadow file entry and write the
|
|
|
|
* modified entry back to the shadow file. Closing the shadow and
|
|
|
|
* password files will commit any changes that have been made.
|
|
|
|
*/
|
|
|
|
spwent.sp_max = maxdays;
|
|
|
|
spwent.sp_min = mindays;
|
2009-04-11 04:04:42 +05:30
|
|
|
spwent.sp_lstchg = lstchgdate;
|
2007-12-31 09:59:30 +05:30
|
|
|
spwent.sp_warn = warndays;
|
|
|
|
spwent.sp_inact = inactdays;
|
2009-04-11 04:04:42 +05:30
|
|
|
spwent.sp_expire = expdate;
|
2007-12-31 09:59:30 +05:30
|
|
|
|
|
|
|
if (spw_update (&spwent) == 0) {
|
|
|
|
fprintf (stderr,
|
* 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
|
|
|
_("%s: failed to prepare the new %s entry '%s'\n"), Prog, spw_dbname (), spwent.sp_namp);
|
2007-12-31 09:59:30 +05:30
|
|
|
fail_exit (E_NOPERM);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* get_defaults - get the value of the fields not set from the command line
|
|
|
|
*/
|
2011-10-19 01:53:33 +05:30
|
|
|
static void get_defaults (/*@null@*/const struct spwd *sp)
|
2007-12-31 09:59:30 +05:30
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Set the fields that aren't being set from the command line from
|
|
|
|
* the password file.
|
|
|
|
*/
|
|
|
|
if (NULL != sp) {
|
|
|
|
if (!Mflg) {
|
|
|
|
maxdays = sp->sp_max;
|
|
|
|
}
|
|
|
|
if (!mflg) {
|
|
|
|
mindays = sp->sp_min;
|
|
|
|
}
|
|
|
|
if (!dflg) {
|
2009-04-11 04:04:42 +05:30
|
|
|
lstchgdate = sp->sp_lstchg;
|
2007-12-31 09:59:30 +05:30
|
|
|
}
|
|
|
|
if (!Wflg) {
|
|
|
|
warndays = sp->sp_warn;
|
|
|
|
}
|
|
|
|
if (!Iflg) {
|
|
|
|
inactdays = sp->sp_inact;
|
|
|
|
}
|
|
|
|
if (!Eflg) {
|
2009-04-11 04:04:42 +05:30
|
|
|
expdate = sp->sp_expire;
|
2007-12-31 09:59:30 +05:30
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Use default values that will not change the behavior of the
|
|
|
|
* account.
|
|
|
|
*/
|
|
|
|
if (!Mflg) {
|
|
|
|
maxdays = -1;
|
|
|
|
}
|
|
|
|
if (!mflg) {
|
|
|
|
mindays = -1;
|
|
|
|
}
|
|
|
|
if (!dflg) {
|
2009-04-11 04:04:42 +05:30
|
|
|
lstchgdate = -1;
|
2007-12-31 09:59:30 +05:30
|
|
|
}
|
|
|
|
if (!Wflg) {
|
|
|
|
warndays = -1;
|
|
|
|
}
|
|
|
|
if (!Iflg) {
|
|
|
|
inactdays = -1;
|
|
|
|
}
|
|
|
|
if (!Eflg) {
|
2009-04-11 04:04:42 +05:30
|
|
|
expdate = -1;
|
2007-12-31 09:59:30 +05:30
|
|
|
}
|
|
|
|
}
|
2007-12-29 16:12:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* chage - change a user's password aging information
|
|
|
|
*
|
|
|
|
* This command controls the password aging information.
|
|
|
|
*
|
|
|
|
* The valid options are
|
|
|
|
*
|
|
|
|
* -d set last password change date (*)
|
|
|
|
* -E set account expiration date (*)
|
|
|
|
* -I set password inactive after expiration (*)
|
|
|
|
* -l show account aging information
|
2018-01-17 17:51:48 +05:30
|
|
|
* -M set maximum number of days before password change (*)
|
2007-12-29 16:12:25 +05:30
|
|
|
* -m set minimum number of days before password change (*)
|
|
|
|
* -W set expiration warning days (*)
|
|
|
|
*
|
|
|
|
* (*) requires root permission to execute.
|
|
|
|
*
|
|
|
|
* All of the time fields are entered in the internal format which is
|
|
|
|
* either seconds or days.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
const struct spwd *sp;
|
|
|
|
uid_t ruid;
|
|
|
|
gid_t rgid;
|
|
|
|
const struct passwd *pw;
|
|
|
|
|
2011-11-07 00:08:57 +05:30
|
|
|
/*
|
|
|
|
* Get the program name so that error messages can use it.
|
|
|
|
*/
|
|
|
|
Prog = Basename (argv[0]);
|
2021-11-29 05:07:53 +05:30
|
|
|
log_set_progname(Prog);
|
|
|
|
log_set_logfd(stderr);
|
2011-11-07 00:08:57 +05:30
|
|
|
|
2007-12-29 16:12:25 +05:30
|
|
|
sanitize_env ();
|
2008-06-10 23:26:53 +05:30
|
|
|
(void) setlocale (LC_ALL, "");
|
|
|
|
(void) bindtextdomain (PACKAGE, LOCALEDIR);
|
|
|
|
(void) textdomain (PACKAGE);
|
2007-12-29 16:12:25 +05:30
|
|
|
|
2011-11-07 00:08:57 +05:30
|
|
|
process_root_flag ("-R", argc, argv);
|
|
|
|
|
|
|
|
#ifdef WITH_AUDIT
|
|
|
|
audit_help_open ();
|
|
|
|
#endif
|
|
|
|
OPENLOG ("chage");
|
|
|
|
|
2007-12-29 16:12:25 +05:30
|
|
|
ruid = getuid ();
|
|
|
|
rgid = getgid ();
|
|
|
|
amroot = (ruid == 0);
|
|
|
|
#ifdef WITH_SELINUX
|
2019-10-16 03:03:54 +05:30
|
|
|
if (amroot) {
|
|
|
|
amroot = (check_selinux_permit ("rootok") == 0);
|
2007-12-29 16:36:35 +05:30
|
|
|
}
|
2007-12-29 16:12:25 +05:30
|
|
|
#endif
|
|
|
|
|
|
|
|
process_flags (argc, argv);
|
|
|
|
|
|
|
|
check_perms ();
|
|
|
|
|
|
|
|
if (!spw_file_present ()) {
|
|
|
|
fprintf (stderr,
|
2007-12-29 16:49:39 +05:30
|
|
|
_("%s: the shadow password file is not present\n"),
|
|
|
|
Prog);
|
* src/chfn.c: Do not exit on pw_unlock failures.
* src/grpconv.c, src/grpunconv.c, src/pwconv.c, src/pwunconv.c,
src/vipw.c: Open syslog with the right identification name.
* src/vipw.c: Log unlock errors to syslog.
* src/vipw.c: Log edits to syslog.
* src/chage.c, src/chfn.c, src/chsh.c, src/gpasswd.c,
src/groupadd.c, src/groupdel.c, src/groupmod.c, src/grpconv.c,
src/grpunconv.c, src/passwd.c, src/pwck.c, src/pwunconv.c,
src/useradd.c, src/usermod.c: Harmonize the syslog levels. Failure
to close or unlock are errors. Failure to open files are warnings.
2008-08-22 08:00:33 +05:30
|
|
|
SYSLOG ((LOG_WARN, "can't find the shadow password file"));
|
2007-12-29 16:12:25 +05:30
|
|
|
closelog ();
|
|
|
|
exit (E_SHADOW_NOTFOUND);
|
|
|
|
}
|
|
|
|
|
|
|
|
open_files (lflg);
|
2007-12-31 09:59:30 +05:30
|
|
|
/* Drop privileges */
|
2008-07-12 04:01:43 +05:30
|
|
|
if (lflg && ( (setregid (rgid, rgid) != 0)
|
|
|
|
|| (setreuid (ruid, ruid) != 0))) {
|
2007-12-31 09:59:30 +05:30
|
|
|
fprintf (stderr, _("%s: failed to drop privileges (%s)\n"),
|
|
|
|
Prog, strerror (errno));
|
|
|
|
fail_exit (E_NOPERM);
|
|
|
|
}
|
2007-12-29 16:12:25 +05:30
|
|
|
|
2007-12-29 17:04:31 +05:30
|
|
|
pw = pw_locate (argv[optind]);
|
|
|
|
if (NULL == pw) {
|
* 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: user '%s' does not exist in %s\n"),
|
|
|
|
Prog, argv[optind], pw_dbname ());
|
2007-12-29 16:12:25 +05:30
|
|
|
closelog ();
|
2011-09-19 01:54:36 +05:30
|
|
|
fail_exit (E_NOPERM);
|
2007-12-29 16:12:25 +05:30
|
|
|
}
|
|
|
|
|
2007-12-31 09:59:30 +05:30
|
|
|
STRFCPY (user_name, pw->pw_name);
|
2010-01-30 Paweł Hajdan, Jr. <phajdan.jr@gentoo.org>
* NEWS: Add support for TCB.
* lib/tcbfuncs.h, lib/tcbfuncs.c, lib/Makefile.am: New library to
support TCB.
* lib/prototypes, libmisc/copydir.c (remove_tree): Add boolean
parameter remove_root.
* configure.in: Add conditional WITH_TCB.
* src/userdel.c, src/usermod.c: Add support for TCB. Update call to
remove_tree().
* src/pwconv.c, src/pwunconv.c: Should not be used with TCB enabled.
* src/vipw.c: Add support for TCB. Update call to remove_tree().
* src/useradd.c: Add support for TCB. Open the shadow file outside
of open_files().
* src/chage.c: Add support for TCB.
* src/Makefile.am: Install passwd sgid shadow when TCB is enabled.
* lib/getdefs.c, man/vipw.8.xml, man/login.defs.5.xml,
man/login.defs/TCB_AUTH_GROUP.xml, man/login.defs/USE_TCB.xml,
man/login.defs/TCB_SYMLINKS.xml, man/generate_mans.mak,
man/generate_mans.deps, man/Makefile.am: New configuration
parameters: TCB_AUTH_GROUP, TCB_SYMLINKS, USE_TCB.
* lib/shadowio.c, lib/commonio.c: Add support for TCB.
2010-03-04 23:41:13 +05:30
|
|
|
#ifdef WITH_TCB
|
2010-03-18 14:51:27 +05:30
|
|
|
if (shadowtcb_set_user (pw->pw_name) == SHADOWTCB_FAILURE) {
|
|
|
|
fail_exit (E_NOPERM);
|
|
|
|
}
|
2010-01-30 Paweł Hajdan, Jr. <phajdan.jr@gentoo.org>
* NEWS: Add support for TCB.
* lib/tcbfuncs.h, lib/tcbfuncs.c, lib/Makefile.am: New library to
support TCB.
* lib/prototypes, libmisc/copydir.c (remove_tree): Add boolean
parameter remove_root.
* configure.in: Add conditional WITH_TCB.
* src/userdel.c, src/usermod.c: Add support for TCB. Update call to
remove_tree().
* src/pwconv.c, src/pwunconv.c: Should not be used with TCB enabled.
* src/vipw.c: Add support for TCB. Update call to remove_tree().
* src/useradd.c: Add support for TCB. Open the shadow file outside
of open_files().
* src/chage.c: Add support for TCB.
* src/Makefile.am: Install passwd sgid shadow when TCB is enabled.
* lib/getdefs.c, man/vipw.8.xml, man/login.defs.5.xml,
man/login.defs/TCB_AUTH_GROUP.xml, man/login.defs/USE_TCB.xml,
man/login.defs/TCB_SYMLINKS.xml, man/generate_mans.mak,
man/generate_mans.deps, man/Makefile.am: New configuration
parameters: TCB_AUTH_GROUP, TCB_SYMLINKS, USE_TCB.
* lib/shadowio.c, lib/commonio.c: Add support for TCB.
2010-03-04 23:41:13 +05:30
|
|
|
#endif
|
2007-12-31 09:59:30 +05:30
|
|
|
user_uid = pw->pw_uid;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
sp = spw_locate (argv[optind]);
|
2010-03-18 14:51:27 +05:30
|
|
|
get_defaults (sp);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Print out the expiration fields if the user has requested the
|
|
|
|
* list option.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
if (lflg) {
|
2007-12-31 09:59:30 +05:30
|
|
|
if (!amroot && (ruid != user_uid)) {
|
2007-10-07 17:16:25 +05:30
|
|
|
fprintf (stderr, _("%s: Permission denied.\n"), Prog);
|
2007-12-31 09:59:30 +05:30
|
|
|
fail_exit (E_NOPERM);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:17:01 +05:30
|
|
|
#ifdef WITH_AUDIT
|
2008-06-14 02:53:09 +05:30
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
|
|
|
"display aging info",
|
|
|
|
user_name, (unsigned int) user_uid, 1);
|
2007-10-07 17:17:01 +05:30
|
|
|
#endif
|
2007-10-07 17:14:59 +05:30
|
|
|
list_fields ();
|
2007-12-31 09:59:30 +05:30
|
|
|
fail_exit (E_SUCCESS);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* If none of the fields were changed from the command line, let the
|
|
|
|
* user interactively change them.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-10-07 17:15:23 +05:30
|
|
|
if (!mflg && !Mflg && !dflg && !Wflg && !Iflg && !Eflg) {
|
2007-12-31 09:59:30 +05:30
|
|
|
printf (_("Changing the aging information for %s\n"),
|
|
|
|
user_name);
|
2007-12-29 16:36:35 +05:30
|
|
|
if (new_fields () == 0) {
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr, _("%s: error changing fields\n"),
|
2007-12-29 16:49:39 +05:30
|
|
|
Prog);
|
2007-12-31 09:59:30 +05:30
|
|
|
fail_exit (E_NOPERM);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:17:01 +05:30
|
|
|
#ifdef WITH_AUDIT
|
2007-12-29 16:36:35 +05:30
|
|
|
else {
|
2007-10-07 17:17:01 +05:30
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
2007-12-29 16:49:39 +05:30
|
|
|
"change all aging information",
|
2008-06-14 02:53:09 +05:30
|
|
|
user_name, (unsigned int) user_uid, 1);
|
2007-12-29 16:36:35 +05:30
|
|
|
}
|
2007-10-07 17:17:01 +05:30
|
|
|
#endif
|
2007-12-31 09:59:30 +05:30
|
|
|
} else {
|
2007-10-07 17:17:01 +05:30
|
|
|
#ifdef WITH_AUDIT
|
2007-12-31 09:59:30 +05:30
|
|
|
if (Mflg) {
|
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
2008-06-14 02:53:09 +05:30
|
|
|
"change max age",
|
|
|
|
user_name, (unsigned int) user_uid, 1);
|
2007-12-31 09:59:30 +05:30
|
|
|
}
|
|
|
|
if (mflg) {
|
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
2008-06-14 02:53:09 +05:30
|
|
|
"change min age",
|
|
|
|
user_name, (unsigned int) user_uid, 1);
|
2007-12-31 09:59:30 +05:30
|
|
|
}
|
|
|
|
if (dflg) {
|
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
2008-06-14 02:53:09 +05:30
|
|
|
"change last change date",
|
|
|
|
user_name, (unsigned int) user_uid, 1);
|
2007-12-31 09:59:30 +05:30
|
|
|
}
|
|
|
|
if (Wflg) {
|
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
2008-06-14 02:53:09 +05:30
|
|
|
"change passwd warning",
|
|
|
|
user_name, (unsigned int) user_uid, 1);
|
2007-12-31 09:59:30 +05:30
|
|
|
}
|
|
|
|
if (Iflg) {
|
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
2008-06-14 02:53:09 +05:30
|
|
|
"change inactive days",
|
|
|
|
user_name, (unsigned int) user_uid, 1);
|
2007-12-31 09:59:30 +05:30
|
|
|
}
|
|
|
|
if (Eflg) {
|
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
2008-06-14 02:53:09 +05:30
|
|
|
"change passwd expiration",
|
|
|
|
user_name, (unsigned int) user_uid, 1);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:17:01 +05:30
|
|
|
#endif
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-12-31 09:59:30 +05:30
|
|
|
update_age (sp, pw);
|
|
|
|
|
2007-12-29 16:12:25 +05:30
|
|
|
close_files ();
|
2007-10-07 17:15:40 +05:30
|
|
|
|
2007-12-31 09:59:30 +05:30
|
|
|
SYSLOG ((LOG_INFO, "changed password expiry for %s", user_name));
|
2007-10-07 17:15:23 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
closelog ();
|
2007-10-07 17:16:07 +05:30
|
|
|
exit (E_SUCCESS);
|
2007-10-07 17:15:23 +05:30
|
|
|
}
|
2007-12-29 16:12:25 +05:30
|
|
|
|