2007-10-07 17:14:02 +05:30
|
|
|
/*
|
|
|
|
* Copyright 1989 - 1994, Julianne Frances Haugh
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of Julianne F. Haugh nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY JULIE HAUGH AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
2007-10-07 17:14:59 +05:30
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL JULIE HAUGH OR CONTRIBUTORS BE LIABLE
|
2007-10-07 17:14:02 +05:30
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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>
|
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:14:38 +05:30
|
|
|
#include <pwd.h>
|
2007-10-07 17:16:07 +05:30
|
|
|
#ifdef WITH_SELINUX
|
|
|
|
#include <selinux/selinux.h>
|
|
|
|
#include <selinux/av_permissions.h>
|
|
|
|
#endif
|
2007-10-07 17:16:52 +05:30
|
|
|
#include "exitcodes.h"
|
2007-10-07 17:16:07 +05:30
|
|
|
#include "prototypes.h"
|
|
|
|
#include "defines.h"
|
|
|
|
#include "pwio.h"
|
|
|
|
#include "shadowio.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
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
static char *Prog;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:15:23 +05:30
|
|
|
static int
|
|
|
|
dflg = 0, /* set last password change date */
|
2007-10-07 17:16:07 +05:30
|
|
|
Eflg = 0, /* set account expiration date */
|
|
|
|
Iflg = 0, /* set password inactive after expiration */
|
|
|
|
lflg = 0, /* show account aging information */
|
|
|
|
mflg = 0, /* set minimum number of days before password change */
|
2007-12-31 09:59:30 +05:30
|
|
|
Mflg = 0, /* set maximum number of days before password change */
|
2007-10-07 17:16:07 +05:30
|
|
|
Wflg = 0; /* set expiration warning days */
|
2007-12-29 16:12:25 +05:30
|
|
|
static int amroot = 0;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-12-31 09:59:30 +05:30
|
|
|
static int pw_locked = 0; /* Indicate if the password file is locked */
|
|
|
|
static int spw_locked = 0; /* Indicate if the shadow file is locked */
|
|
|
|
/* 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;
|
|
|
|
static long lastday;
|
|
|
|
static long warndays;
|
|
|
|
static long inactdays;
|
|
|
|
static long expdays;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-12-31 09:59:30 +05:30
|
|
|
#ifdef USE_PAM
|
|
|
|
static pam_handle_t *pamh = NULL;
|
|
|
|
#endif
|
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
#define EPOCH "1969-12-31"
|
|
|
|
|
|
|
|
/* local function prototypes */
|
2008-01-05 19:07:32 +05:30
|
|
|
static int isnum (const char *s);
|
2007-10-07 17:14:59 +05:30
|
|
|
static void usage (void);
|
|
|
|
static void date_to_str (char *, size_t, time_t);
|
|
|
|
static int new_fields (void);
|
|
|
|
static void print_date (time_t);
|
|
|
|
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);
|
|
|
|
static void open_files (int readonly);
|
|
|
|
static void close_files (void);
|
2007-12-31 09:59:30 +05:30
|
|
|
static void fail_exit (int code);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* fail_exit - do some cleanup and exit with the given error code
|
|
|
|
*/
|
|
|
|
static void fail_exit (int code)
|
|
|
|
{
|
|
|
|
if (spw_locked) {
|
|
|
|
spw_unlock ();
|
|
|
|
}
|
|
|
|
if (pw_locked) {
|
|
|
|
pw_unlock ();
|
|
|
|
}
|
|
|
|
closelog ();
|
|
|
|
|
|
|
|
#ifdef WITH_AUDIT
|
|
|
|
if (E_SUCCESS != code) {
|
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "change age",
|
|
|
|
user_name, user_uid, 0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_PAM
|
|
|
|
if (NULL != pamh) {
|
|
|
|
/* If there is a PAM error, pam_end will be called by the
|
|
|
|
* caller.
|
|
|
|
* We always end the pam transaction with PAM_SUCCESS here.
|
|
|
|
*/
|
|
|
|
pam_end (pamh, PAM_SUCCESS);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
exit (code);
|
|
|
|
}
|
2007-10-07 17:14:32 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* isnum - determine whether or not a string is a number
|
|
|
|
*/
|
2008-01-05 19:07:32 +05:30
|
|
|
static int isnum (const char *s)
|
2007-10-07 17:14:32 +05:30
|
|
|
{
|
2007-12-29 16:36:35 +05:30
|
|
|
while ('\0' != *s) {
|
|
|
|
if (!isdigit (*s)) {
|
2007-10-07 17:14:32 +05:30
|
|
|
return 0;
|
2007-12-29 16:36:35 +05:30
|
|
|
}
|
2007-10-07 17:14:32 +05:30
|
|
|
s++;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
|
|
|
* usage - print command line syntax and exit
|
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
static void usage (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2008-01-25 00:09:05 +05:30
|
|
|
fputs (_("Usage: chage [options] [LOGIN]\n"
|
2008-01-25 00:54:03 +05:30
|
|
|
"\n"
|
|
|
|
"Options:\n"
|
|
|
|
" -d, --lastday LAST_DAY set last password change to LAST_DAY\n"
|
|
|
|
" -E, --expiredate EXPIRE_DATE set account expiration date to EXPIRE_DATE\n"
|
|
|
|
" -h, --help display this help message and exit\n"
|
|
|
|
" -I, --inactive INACTIVE set password inactive after expiration\n"
|
|
|
|
" to INACTIVE\n"
|
|
|
|
" -l, --list show account aging information\n"
|
|
|
|
" -m, --mindays MIN_DAYS set minimum number of days before password\n"
|
|
|
|
" change to MIN_DAYS\n"
|
|
|
|
" -M, --maxdays MAX_DAYS set maximim number of days before password\n"
|
|
|
|
" change to MAX_DAYS\n"
|
|
|
|
" -W, --warndays WARN_DAYS set expiration warning days to WARN_DAYS\n"
|
|
|
|
"\n"), stderr);
|
2007-10-07 17:16:34 +05:30
|
|
|
exit (E_USAGE);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
static void date_to_str (char *buf, size_t maxsize, time_t date)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
struct tm *tp;
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
tp = gmtime (&date);
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef HAVE_STRFTIME
|
2007-10-07 17:14:59 +05:30
|
|
|
strftime (buf, maxsize, "%Y-%m-%d", tp);
|
2007-10-07 17:14:02 +05:30
|
|
|
#else
|
2007-10-07 17:14:59 +05:30
|
|
|
snprintf (buf, maxsize, "%04d-%02d-%02d",
|
2007-12-29 16:49:39 +05:30
|
|
|
tp->tm_year + 1900, tp->tm_mon + 1, tp->tm_mday);
|
2007-10-07 17:14:59 +05:30
|
|
|
#endif /* HAVE_STRFTIME */
|
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];
|
|
|
|
char *cp;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
* libmisc/age.c, libmisc/yesno.c, src/lastlog.c, src/grpck.c,
src/chfn.c, src/passwd.c, src/chage.c, src/login.c, src/sulogin.c,
src/chsh.c: Fix call to puts (remove end of line, or use fputs).
* po/*.po: Unfuzzy PO files according to above change.
2008-02-03 21:58:03 +05:30
|
|
|
puts (_("Enter the new value, or press ENTER for the default"));
|
|
|
|
puts ("");
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
snprintf (buf, sizeof buf, "%ld", mindays);
|
|
|
|
change_field (buf, sizeof buf, _("Minimum Password Age"));
|
2007-12-29 17:04:31 +05:30
|
|
|
mindays = strtol (buf, &cp, 10);
|
|
|
|
if ( ((mindays == 0) && ('\0' != *cp))
|
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
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
snprintf (buf, sizeof buf, "%ld", maxdays);
|
|
|
|
change_field (buf, sizeof buf, _("Maximum Password Age"));
|
2007-12-29 17:04:31 +05:30
|
|
|
maxdays = strtol (buf, &cp, 10);
|
|
|
|
if ( ((maxdays == 0) && ('\0' != *cp))
|
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
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
date_to_str (buf, sizeof buf, lastday * SCALE);
|
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
|
|
|
|
2007-12-29 16:36:35 +05:30
|
|
|
if (strcmp (buf, EPOCH) == 0) {
|
2007-10-07 17:14:02 +05:30
|
|
|
lastday = -1;
|
2007-12-29 17:04:31 +05:30
|
|
|
} else {
|
|
|
|
lastday = strtoday (buf);
|
|
|
|
if (lastday == -1) {
|
|
|
|
return 0;
|
|
|
|
}
|
2007-12-29 16:36:35 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
snprintf (buf, sizeof buf, "%ld", warndays);
|
2007-10-07 17:14:02 +05:30
|
|
|
change_field (buf, sizeof buf, _("Password Expiration Warning"));
|
2007-12-29 17:04:31 +05:30
|
|
|
warndays = strtol (buf, &cp, 10);
|
|
|
|
if ( ((warndays == 0) && ('\0' != *cp))
|
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
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
snprintf (buf, sizeof buf, "%ld", inactdays);
|
|
|
|
change_field (buf, sizeof buf, _("Password Inactive"));
|
2007-12-29 17:04:31 +05:30
|
|
|
inactdays = strtol (buf, &cp, 10);
|
|
|
|
if ( ((inactdays == 0) && ('\0' != *cp))
|
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
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
date_to_str (buf, sizeof buf, expdays * SCALE);
|
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
|
|
|
|
2007-12-29 16:36:35 +05:30
|
|
|
if (strcmp (buf, EPOCH) == 0) {
|
2007-10-07 17:14:02 +05:30
|
|
|
expdays = -1;
|
2007-12-29 17:04:31 +05:30
|
|
|
} else {
|
|
|
|
expdays = strtoday (buf);
|
|
|
|
if (expdays == -1) {
|
|
|
|
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
|
|
|
{
|
|
|
|
#ifdef HAVE_STRFTIME
|
|
|
|
struct tm *tp;
|
|
|
|
char buf[80];
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
tp = gmtime (&date);
|
|
|
|
strftime (buf, sizeof buf, "%b %d, %Y", tp);
|
|
|
|
puts (buf);
|
2007-10-07 17:14:02 +05:30
|
|
|
#else
|
|
|
|
struct tm *tp;
|
|
|
|
char *cp;
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
tp = gmtime (&date);
|
|
|
|
cp = asctime (tp);
|
|
|
|
printf ("%6.6s, %4.4s\n", cp + 4, cp + 20);
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
*/
|
* libmisc/age.c, libmisc/yesno.c, src/lastlog.c, src/grpck.c,
src/chfn.c, src/passwd.c, src/chage.c, src/login.c, src/sulogin.c,
src/chsh.c: Fix call to puts (remove end of line, or use fputs).
* po/*.po: Unfuzzy PO files according to above change.
2008-02-03 21:58:03 +05:30
|
|
|
fputs (_("Last password change\t\t\t\t\t: "), stdout);
|
2007-10-07 17:17:11 +05:30
|
|
|
if (lastday < 0) {
|
* libmisc/age.c, libmisc/yesno.c, src/lastlog.c, src/grpck.c,
src/chfn.c, src/passwd.c, src/chage.c, src/login.c, src/sulogin.c,
src/chsh.c: Fix call to puts (remove end of line, or use fputs).
* po/*.po: Unfuzzy PO files according to above change.
2008-02-03 21:58:03 +05:30
|
|
|
puts (_("never"));
|
2007-10-07 17:17:11 +05:30
|
|
|
} else if (lastday == 0) {
|
* libmisc/age.c, libmisc/yesno.c, src/lastlog.c, src/grpck.c,
src/chfn.c, src/passwd.c, src/chage.c, src/login.c, src/sulogin.c,
src/chsh.c: Fix call to puts (remove end of line, or use fputs).
* po/*.po: Unfuzzy PO files according to above change.
2008-02-03 21:58:03 +05:30
|
|
|
puts (_("password must be changed"));
|
2007-10-07 17:14:02 +05:30
|
|
|
} else {
|
|
|
|
changed = lastday * SCALE;
|
2007-10-07 17:14:59 +05:30
|
|
|
print_date (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
|
|
|
*/
|
* libmisc/age.c, libmisc/yesno.c, src/lastlog.c, src/grpck.c,
src/chfn.c, src/passwd.c, src/chage.c, src/login.c, src/sulogin.c,
src/chsh.c: Fix call to puts (remove end of line, or use fputs).
* po/*.po: Unfuzzy PO files according to above change.
2008-02-03 21:58:03 +05:30
|
|
|
fputs (_("Password expires\t\t\t\t\t: "), stdout);
|
2007-12-29 16:36:35 +05:30
|
|
|
if ((lastday <= 0) || (maxdays >= (10000 * (DAY / SCALE)))
|
|
|
|
|| (maxdays < 0)) {
|
* libmisc/age.c, libmisc/yesno.c, src/lastlog.c, src/grpck.c,
src/chfn.c, src/passwd.c, src/chage.c, src/login.c, src/sulogin.c,
src/chsh.c: Fix call to puts (remove end of line, or use fputs).
* po/*.po: Unfuzzy PO files according to above change.
2008-02-03 21:58:03 +05:30
|
|
|
puts (_("never"));
|
2007-10-07 17:14:02 +05:30
|
|
|
} else {
|
|
|
|
expires = changed + maxdays * SCALE;
|
2007-10-07 17:14:59 +05:30
|
|
|
print_date (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
|
|
|
*/
|
* libmisc/age.c, libmisc/yesno.c, src/lastlog.c, src/grpck.c,
src/chfn.c, src/passwd.c, src/chage.c, src/login.c, src/sulogin.c,
src/chsh.c: Fix call to puts (remove end of line, or use fputs).
* po/*.po: Unfuzzy PO files according to above change.
2008-02-03 21:58:03 +05:30
|
|
|
fputs (_("Password inactive\t\t\t\t\t: "), stdout);
|
2007-12-29 16:36:35 +05:30
|
|
|
if ((lastday <= 0) || (inactdays < 0) ||
|
|
|
|
(maxdays >= (10000 * (DAY / SCALE))) || (maxdays < 0)) {
|
* libmisc/age.c, libmisc/yesno.c, src/lastlog.c, src/grpck.c,
src/chfn.c, src/passwd.c, src/chage.c, src/login.c, src/sulogin.c,
src/chsh.c: Fix call to puts (remove end of line, or use fputs).
* po/*.po: Unfuzzy PO files according to above change.
2008-02-03 21:58:03 +05:30
|
|
|
puts (_("never"));
|
2007-10-07 17:14:02 +05:30
|
|
|
} else {
|
|
|
|
expires = changed + (maxdays + inactdays) * SCALE;
|
2007-10-07 17:14:59 +05:30
|
|
|
print_date (expires);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The account will expire on the given date regardless of the
|
|
|
|
* password expiring or not.
|
|
|
|
*/
|
* libmisc/age.c, libmisc/yesno.c, src/lastlog.c, src/grpck.c,
src/chfn.c, src/passwd.c, src/chage.c, src/login.c, src/sulogin.c,
src/chsh.c: Fix call to puts (remove end of line, or use fputs).
* po/*.po: Unfuzzy PO files according to above change.
2008-02-03 21:58:03 +05:30
|
|
|
fputs (_("Account expires\t\t\t\t\t\t: "), stdout);
|
2007-10-07 17:16:52 +05:30
|
|
|
if (expdays < 0) {
|
* libmisc/age.c, libmisc/yesno.c, src/lastlog.c, src/grpck.c,
src/chfn.c, src/passwd.c, src/chage.c, src/login.c, src/sulogin.c,
src/chsh.c: Fix call to puts (remove end of line, or use fputs).
* po/*.po: Unfuzzy PO files according to above change.
2008-02-03 21:58:03 +05:30
|
|
|
puts (_("never"));
|
2007-10-07 17:14:02 +05:30
|
|
|
} else {
|
|
|
|
expires = expdays * SCALE;
|
2007-10-07 17:14:59 +05:30
|
|
|
print_date (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
|
|
|
|
* password must be chaged, the number of days before the password
|
|
|
|
* 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 option_index = 0;
|
|
|
|
int c;
|
|
|
|
static struct option long_options[] = {
|
|
|
|
{"lastday", required_argument, NULL, 'd'},
|
|
|
|
{"expiredate", required_argument, NULL, 'E'},
|
|
|
|
{"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'},
|
|
|
|
{"warndays", required_argument, NULL, 'W'},
|
|
|
|
{NULL, 0, NULL, '\0'}
|
|
|
|
};
|
|
|
|
|
|
|
|
while ((c =
|
|
|
|
getopt_long (argc, argv, "d:E:hI:lm:M:W:", long_options,
|
|
|
|
&option_index)) != -1) {
|
|
|
|
switch (c) {
|
|
|
|
case 'd':
|
|
|
|
dflg++;
|
2007-12-29 16:36:35 +05:30
|
|
|
if (!isnum (optarg)) {
|
2007-12-29 16:12:25 +05:30
|
|
|
lastday = strtoday (optarg);
|
2007-12-29 16:36:35 +05:30
|
|
|
} else {
|
2007-12-29 16:12:25 +05:30
|
|
|
lastday = strtol (optarg, 0, 10);
|
2007-12-29 16:36:35 +05:30
|
|
|
}
|
2007-12-29 16:12:25 +05:30
|
|
|
break;
|
|
|
|
case 'E':
|
|
|
|
Eflg++;
|
2007-12-29 16:36:35 +05:30
|
|
|
if (!isnum (optarg)) {
|
2007-12-29 16:12:25 +05:30
|
|
|
expdays = strtoday (optarg);
|
2007-12-29 16:36:35 +05:30
|
|
|
} else {
|
2007-12-29 16:12:25 +05:30
|
|
|
expdays = strtol (optarg, 0, 10);
|
2007-12-29 16:36:35 +05:30
|
|
|
}
|
2007-12-29 16:12:25 +05:30
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
usage ();
|
|
|
|
break;
|
|
|
|
case 'I':
|
|
|
|
Iflg++;
|
|
|
|
inactdays = strtol (optarg, 0, 10);
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
lflg++;
|
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
mflg++;
|
|
|
|
mindays = strtol (optarg, 0, 10);
|
|
|
|
break;
|
|
|
|
case 'M':
|
|
|
|
Mflg++;
|
|
|
|
maxdays = strtol (optarg, 0, 10);
|
|
|
|
break;
|
|
|
|
case 'W':
|
|
|
|
Wflg++;
|
|
|
|
warndays = strtol (optarg, 0, 10);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
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) {
|
2007-10-07 17:14:02 +05:30
|
|
|
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);
|
2007-10-07 17:14:02 +05:30
|
|
|
usage ();
|
|
|
|
}
|
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)
|
|
|
|
{
|
|
|
|
#ifdef USE_PAM
|
2007-12-29 16:49:39 +05:30
|
|
|
struct passwd *pampw;
|
2007-12-29 16:12:25 +05:30
|
|
|
int retval;
|
|
|
|
#endif
|
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
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
#ifdef USE_PAM
|
|
|
|
retval = PAM_SUCCESS;
|
|
|
|
|
2007-12-29 16:49:39 +05:30
|
|
|
pampw = getpwuid (getuid ()); /* local, no need for xgetpwuid */
|
|
|
|
if (pampw == NULL) {
|
|
|
|
retval = PAM_USER_UNKNOWN;
|
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
|
2007-12-29 16:49:39 +05:30
|
|
|
if (retval == PAM_SUCCESS) {
|
|
|
|
retval = pam_start ("chage", pampw->pw_name, &conv, &pamh);
|
2007-10-07 17:14:59 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
if (retval == PAM_SUCCESS) {
|
|
|
|
retval = pam_authenticate (pamh, 0);
|
|
|
|
if (retval != PAM_SUCCESS) {
|
|
|
|
pam_end (pamh, retval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (retval == PAM_SUCCESS) {
|
|
|
|
retval = pam_acct_mgmt (pamh, 0);
|
|
|
|
if (retval != PAM_SUCCESS) {
|
|
|
|
pam_end (pamh, retval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (retval != PAM_SUCCESS) {
|
2007-10-07 17:16:07 +05:30
|
|
|
fprintf (stderr, _("%s: PAM authentication failed\n"), Prog);
|
2007-12-31 09:59:30 +05:30
|
|
|
pamh = NULL;
|
|
|
|
fail_exit (E_NOPERM);
|
2007-10-07 17:14:59 +05:30
|
|
|
}
|
|
|
|
#endif /* USE_PAM */
|
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.
|
|
|
|
*/
|
2007-12-29 16:12:25 +05:30
|
|
|
static void open_files (int readonly)
|
|
|
|
{
|
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 && (pw_lock () == 0)) {
|
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: can't lock password file\n"), Prog);
|
|
|
|
SYSLOG ((LOG_ERR, "failed locking %s", PASSWD_FILE));
|
|
|
|
fail_exit (E_NOPERM);
|
|
|
|
}
|
|
|
|
if (!readonly) {
|
|
|
|
pw_locked = 1;
|
|
|
|
}
|
|
|
|
if (pw_open (readonly ? O_RDONLY: O_RDWR) == 0) {
|
2007-10-07 17:16:07 +05:30
|
|
|
fprintf (stderr, _("%s: can't open password file\n"), Prog);
|
2007-10-07 17:14:59 +05:30
|
|
|
SYSLOG ((LOG_ERR, "failed opening %s", PASSWD_FILE));
|
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-29 16:36:35 +05:30
|
|
|
if (!readonly && (spw_lock () == 0)) {
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr,
|
2007-12-29 16:49:39 +05:30
|
|
|
_("%s: can't lock shadow password file\n"), Prog);
|
2007-10-07 17:14:59 +05:30
|
|
|
SYSLOG ((LOG_ERR, "failed locking %s", SHADOW_FILE));
|
2007-12-31 09:59:30 +05:30
|
|
|
fail_exit (E_NOPERM);
|
|
|
|
}
|
|
|
|
if (!readonly) {
|
|
|
|
spw_locked = 1;
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-12-29 16:36:35 +05:30
|
|
|
if (spw_open (readonly ? O_RDONLY: O_RDWR) == 0) {
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr,
|
2007-12-29 16:49:39 +05:30
|
|
|
_("%s: can't open shadow password file\n"), Prog);
|
2007-10-07 17:14:59 +05:30
|
|
|
SYSLOG ((LOG_ERR, "failed opening %s", SHADOW_FILE));
|
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,
|
2007-12-29 16:49:39 +05:30
|
|
|
_("%s: can't rewrite shadow password file\n"), Prog);
|
2007-12-29 16:12:25 +05:30
|
|
|
SYSLOG ((LOG_ERR, "failed rewriting %s", SHADOW_FILE));
|
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) {
|
2007-12-29 16:12:25 +05:30
|
|
|
fprintf (stderr, _("%s: can't rewrite password file\n"), Prog);
|
|
|
|
SYSLOG ((LOG_ERR, "failed rewriting %s", PASSWD_FILE));
|
2007-12-31 09:59:30 +05:30
|
|
|
fail_exit (E_NOPERM);
|
2007-12-29 16:12:25 +05:30
|
|
|
}
|
|
|
|
spw_unlock ();
|
2007-12-31 09:59:30 +05:30
|
|
|
spw_locked = 0;
|
|
|
|
pw_unlock ();
|
|
|
|
pw_locked = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* update_age - update the aging information in the database
|
|
|
|
*
|
|
|
|
* It will not return in case of error
|
|
|
|
*/
|
|
|
|
static void update_age (const struct spwd *sp, const struct passwd *pw)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
spwent.sp_namp = xstrdup (pw->pw_name);
|
|
|
|
spwent.sp_pwdp = xstrdup (pw->pw_passwd);
|
|
|
|
spwent.sp_flag = -1;
|
|
|
|
|
|
|
|
pwent.pw_passwd = SHADOW_PASSWD_STRING; /* XXX warning: const */
|
|
|
|
if (pw_update (&pwent) == 0) {
|
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: can't update password file\n"), Prog);
|
|
|
|
SYSLOG ((LOG_ERR, "failed updating %s", PASSWD_FILE));
|
|
|
|
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;
|
|
|
|
spwent.sp_lstchg = lastday;
|
|
|
|
spwent.sp_warn = warndays;
|
|
|
|
spwent.sp_inact = inactdays;
|
|
|
|
spwent.sp_expire = expdays;
|
|
|
|
|
|
|
|
if (spw_update (&spwent) == 0) {
|
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: can't update shadow password file\n"), Prog);
|
|
|
|
SYSLOG ((LOG_ERR, "failed updating %s", SHADOW_FILE));
|
|
|
|
fail_exit (E_NOPERM);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* get_defaults - get the value of the fields not set from the command line
|
|
|
|
*/
|
|
|
|
static void get_defaults (const struct spwd *sp)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* 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) {
|
|
|
|
lastday = sp->sp_lstchg;
|
|
|
|
}
|
|
|
|
if (!Wflg) {
|
|
|
|
warndays = sp->sp_warn;
|
|
|
|
}
|
|
|
|
if (!Iflg) {
|
|
|
|
inactdays = sp->sp_inact;
|
|
|
|
}
|
|
|
|
if (!Eflg) {
|
|
|
|
expdays = sp->sp_expire;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Use default values that will not change the behavior of the
|
|
|
|
* account.
|
|
|
|
*/
|
|
|
|
if (!Mflg) {
|
|
|
|
maxdays = -1;
|
|
|
|
}
|
|
|
|
if (!mflg) {
|
|
|
|
mindays = -1;
|
|
|
|
}
|
|
|
|
if (!dflg) {
|
|
|
|
lastday = 0;
|
|
|
|
}
|
|
|
|
if (!Wflg) {
|
|
|
|
warndays = -1;
|
|
|
|
}
|
|
|
|
if (!Iflg) {
|
|
|
|
inactdays = -1;
|
|
|
|
}
|
|
|
|
if (!Eflg) {
|
|
|
|
expdays = -1;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
* -M set maximim number of days before password change (*)
|
|
|
|
* -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;
|
|
|
|
|
|
|
|
#ifdef WITH_AUDIT
|
|
|
|
audit_help_open ();
|
|
|
|
#endif
|
|
|
|
sanitize_env ();
|
|
|
|
setlocale (LC_ALL, "");
|
|
|
|
bindtextdomain (PACKAGE, LOCALEDIR);
|
|
|
|
textdomain (PACKAGE);
|
|
|
|
|
|
|
|
ruid = getuid ();
|
|
|
|
rgid = getgid ();
|
|
|
|
amroot = (ruid == 0);
|
|
|
|
#ifdef WITH_SELINUX
|
2007-12-29 16:36:35 +05:30
|
|
|
if (amroot && (is_selinux_enabled () > 0)) {
|
2007-12-29 16:12:25 +05:30
|
|
|
amroot = (selinux_check_passwd_access (PASSWD__ROOTOK) == 0);
|
2007-12-29 16:36:35 +05:30
|
|
|
}
|
2007-12-29 16:12:25 +05:30
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the program name so that error messages can use it.
|
|
|
|
*/
|
|
|
|
Prog = Basename (argv[0]);
|
|
|
|
|
|
|
|
process_flags (argc, argv);
|
|
|
|
|
|
|
|
OPENLOG ("chage");
|
|
|
|
|
|
|
|
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);
|
2007-12-29 16:12:25 +05:30
|
|
|
SYSLOG ((LOG_ERR, "can't find the shadow password file"));
|
|
|
|
closelog ();
|
|
|
|
exit (E_SHADOW_NOTFOUND);
|
|
|
|
}
|
|
|
|
|
|
|
|
open_files (lflg);
|
2007-12-31 09:59:30 +05:30
|
|
|
/* Drop privileges */
|
|
|
|
if (lflg && (setregid (rgid, rgid) || setreuid (ruid, ruid))) {
|
|
|
|
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) {
|
2007-12-29 16:12:25 +05:30
|
|
|
fprintf (stderr, _("%s: unknown user %s\n"), Prog,
|
2007-12-29 16:49:39 +05:30
|
|
|
argv[optind]);
|
2007-12-29 16:12:25 +05:30
|
|
|
closelog ();
|
|
|
|
exit (E_NOPERM);
|
|
|
|
}
|
|
|
|
|
2007-12-31 09:59:30 +05:30
|
|
|
STRFCPY (user_name, pw->pw_name);
|
|
|
|
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]);
|
2007-12-31 09:59:30 +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
|
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "display aging info",
|
2007-12-31 09:59:30 +05:30
|
|
|
user_name, 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",
|
2007-12-31 09:59:30 +05:30
|
|
|
user_name, 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,
|
|
|
|
"change max age", user_name,
|
|
|
|
user_uid, 1);
|
|
|
|
}
|
|
|
|
if (mflg) {
|
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
|
|
|
"change min age", user_name,
|
|
|
|
user_uid, 1);
|
|
|
|
}
|
|
|
|
if (dflg) {
|
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
|
|
|
"change last change date", user_name,
|
|
|
|
user_uid, 1);
|
|
|
|
}
|
|
|
|
if (Wflg) {
|
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
|
|
|
"change passwd warning", user_name,
|
|
|
|
user_uid, 1);
|
|
|
|
}
|
|
|
|
if (Iflg) {
|
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
|
|
|
"change inactive days", user_name,
|
|
|
|
user_uid, 1);
|
|
|
|
}
|
|
|
|
if (Eflg) {
|
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
|
|
|
"change passwd expiration", user_name,
|
|
|
|
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:38 +05:30
|
|
|
#ifdef USE_PAM
|
2007-12-29 16:12:25 +05:30
|
|
|
pam_end (pamh, PAM_SUCCESS);
|
2007-10-07 17:14:59 +05:30
|
|
|
#endif /* USE_PAM */
|
2007-10-07 17:14:38 +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
|
|
|
|