2007-10-07 17:14:02 +05:30
|
|
|
/*
|
2008-04-27 06:10:09 +05:30
|
|
|
* Copyright (c) 1989 - 1994, Julianne Frances Haugh
|
|
|
|
* Copyright (c) 1996 - 2000, Marek Michałkiewicz
|
|
|
|
* Copyright (c) 2001 - 2006, Tomasz Kłoczko
|
|
|
|
* Copyright (c) 2007 - 2008, Nicolas François
|
2007-10-07 17:14:02 +05:30
|
|
|
* 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.
|
2008-04-27 06:10:09 +05:30
|
|
|
* 3. The name of the copyright holders or contributors may not be used to
|
|
|
|
* endorse or promote products derived from this software without
|
|
|
|
* specific prior written permission.
|
2007-10-07 17:14:02 +05:30
|
|
|
*
|
2008-04-27 06:10:09 +05:30
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* HOLDERS OR CONTRIBUTORS BE LIABLE 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.
|
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
|
|
|
|
|
|
|
#include <errno.h>
|
2007-10-07 17:14:02 +05:30
|
|
|
#include <fcntl.h>
|
2007-10-07 17:17:01 +05:30
|
|
|
#include <getopt.h>
|
|
|
|
#include <pwd.h>
|
2007-10-07 17:14:02 +05:30
|
|
|
#include <signal.h>
|
2007-10-07 17:17:01 +05:30
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#ifdef WITH_SELINUX
|
|
|
|
#include <selinux/selinux.h>
|
2008-03-27 03:30:50 +05:30
|
|
|
#include <selinux/flask.h>
|
2007-10-07 17:17:01 +05:30
|
|
|
#include <selinux/av_permissions.h>
|
2008-03-27 03:30:50 +05:30
|
|
|
#include <selinux/context.h>
|
2007-10-07 17:17:01 +05:30
|
|
|
#endif
|
|
|
|
#include <time.h>
|
|
|
|
#include "defines.h"
|
|
|
|
#include "getdef.h"
|
|
|
|
#include "nscd.h"
|
|
|
|
#include "prototypes.h"
|
|
|
|
#include "pwauth.h"
|
|
|
|
#include "pwio.h"
|
|
|
|
#include "shadowio.h"
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
|
|
|
* exit status values
|
|
|
|
*/
|
|
|
|
#define E_SUCCESS 0 /* success */
|
|
|
|
#define E_NOPERM 1 /* permission denied */
|
|
|
|
#define E_USAGE 2 /* invalid combination of options */
|
|
|
|
#define E_FAILURE 3 /* unexpected failure, nothing done */
|
|
|
|
#define E_MISSING 4 /* unexpected failure, passwd file missing */
|
|
|
|
#define E_PWDBUSY 5 /* passwd file busy, try again later */
|
|
|
|
#define E_BAD_ARG 6 /* invalid argument to option */
|
|
|
|
/*
|
|
|
|
* Global variables
|
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
static char *name; /* The name of user whose password is being changed */
|
|
|
|
static char *myname; /* The current user's name */
|
2007-10-07 17:14:02 +05:30
|
|
|
static char *Prog; /* Program name */
|
2008-06-10 23:20:21 +05:30
|
|
|
static bool amroot; /* The caller's real UID was 0 */
|
|
|
|
|
|
|
|
static bool
|
|
|
|
aflg = false, /* -a - show status for all users */
|
|
|
|
dflg = false, /* -d - delete password */
|
|
|
|
eflg = false, /* -e - force password change */
|
|
|
|
iflg = false, /* -i - set inactive days */
|
|
|
|
kflg = false, /* -k - change only if expired */
|
|
|
|
lflg = false, /* -l - lock account */
|
|
|
|
nflg = false, /* -n - set minimum days */
|
|
|
|
qflg = false, /* -q - quiet mode */
|
|
|
|
Sflg = false, /* -S - show password status */
|
|
|
|
uflg = false, /* -u - unlock account */
|
|
|
|
wflg = false, /* -w - set warning days */
|
|
|
|
xflg = false; /* -x - set maximum days */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* set to 1 if there are any flags which require root privileges,
|
|
|
|
* and require username to be specified
|
|
|
|
*/
|
2008-06-10 23:20:21 +05:30
|
|
|
static bool anyflag = false;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
static long age_min = 0; /* Minimum days before change */
|
|
|
|
static long age_max = 0; /* Maximum days until change */
|
|
|
|
static long warn = 0; /* Warning days before change */
|
2007-10-07 17:14:02 +05:30
|
|
|
static long inact = 0; /* Days without change before locked */
|
|
|
|
|
2008-06-10 23:20:21 +05:30
|
|
|
static bool do_update_age = false;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
#ifndef USE_PAM
|
2007-11-20 17:48:36 +05:30
|
|
|
/*
|
|
|
|
* Size of the biggest passwd:
|
|
|
|
* $6$ 3
|
|
|
|
* rounds= 7
|
|
|
|
* 999999999 9
|
|
|
|
* $ 1
|
|
|
|
* salt 16
|
|
|
|
* $ 1
|
|
|
|
* SHA512 123
|
|
|
|
* nul 1
|
|
|
|
*
|
|
|
|
* total 161
|
|
|
|
*/
|
|
|
|
static char crypt_passwd[256];
|
2008-06-10 23:20:21 +05:30
|
|
|
static bool do_update_pwd = false;
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* External identifiers
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* local function prototypes */
|
2007-10-07 17:14:59 +05:30
|
|
|
static void usage (int);
|
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifndef USE_PAM
|
2007-10-07 17:14:59 +05:30
|
|
|
static int reuse (const char *, const struct passwd *);
|
|
|
|
static int new_password (const struct passwd *);
|
|
|
|
|
|
|
|
static void check_password (const struct passwd *, const struct spwd *);
|
|
|
|
static char *insert_crypt_passwd (const char *, const char *);
|
|
|
|
#endif /* !USE_PAM */
|
|
|
|
static char *date_to_str (time_t);
|
|
|
|
static const char *pw_status (const char *);
|
|
|
|
static void print_status (const struct passwd *);
|
|
|
|
static void fail_exit (int);
|
|
|
|
static void oom (void);
|
|
|
|
static char *update_crypt_pw (char *);
|
|
|
|
static void update_noshadow (void);
|
|
|
|
|
|
|
|
static void update_shadow (void);
|
|
|
|
static long getnumber (const char *);
|
2008-05-24 18:38:58 +05:30
|
|
|
#ifdef WITH_SELINUX
|
|
|
|
static int check_selinux_access (const char *changed_user,
|
|
|
|
uid_t changed_uid,
|
|
|
|
access_vector_t requested_access);
|
|
|
|
#endif
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* usage - print command usage and exit
|
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
static void usage (int status)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2008-01-25 02:12:12 +05:30
|
|
|
fputs (_("Usage: passwd [options] [LOGIN]\n"
|
2008-01-25 02:24:42 +05:30
|
|
|
"\n"
|
|
|
|
"Options:\n"
|
|
|
|
" -a, --all report password status on all accounts\n"
|
|
|
|
" -d, --delete delete the password for the named account\n"
|
|
|
|
" -e, --expire force expire the password for the named account\n"
|
|
|
|
" -h, --help display this help message and exit\n"
|
|
|
|
" -k, --keep-tokens change password only if expired\n"
|
|
|
|
" -i, --inactive INACTIVE set password inactive after expiration\n"
|
|
|
|
" to INACTIVE\n"
|
|
|
|
" -l, --lock lock the named account\n"
|
|
|
|
" -n, --mindays MIN_DAYS set minimum number of days before password\n"
|
|
|
|
" change to MIN_DAYS\n"
|
|
|
|
" -q, --quiet quiet mode\n"
|
|
|
|
" -r, --repository REPOSITORY change password in REPOSITORY repository\n"
|
|
|
|
" -S, --status report password status on the named account\n"
|
|
|
|
" -u, --unlock unlock the named account\n"
|
|
|
|
" -w, --warndays WARN_DAYS set expiration warning days to WARN_DAYS\n"
|
|
|
|
" -x, --maxdays MAX_DAYS set maximim number of days before password\n"
|
|
|
|
" change to MAX_DAYS\n"
|
|
|
|
"\n"), stderr);
|
2007-10-07 17:14:59 +05:30
|
|
|
exit (status);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef USE_PAM
|
2007-10-07 17:14:59 +05:30
|
|
|
static int reuse (const char *pass, const struct passwd *pw)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
#ifdef HAVE_LIBCRACK_HIST
|
|
|
|
const char *reason;
|
2007-10-07 17:14:59 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef HAVE_LIBCRACK_PW
|
2007-10-07 17:14:59 +05:30
|
|
|
const char *FascistHistoryPw (const char *, const struct passwd *);
|
|
|
|
|
|
|
|
reason = FascistHistory (pass, pw);
|
2007-10-07 17:14:02 +05:30
|
|
|
#else
|
2007-10-07 17:14:59 +05:30
|
|
|
const char *FascistHistory (const char *, int);
|
|
|
|
|
|
|
|
reason = FascistHistory (pass, pw->pw_uid);
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
|
|
|
if (reason) {
|
2007-10-07 17:14:59 +05:30
|
|
|
printf (_("Bad password: %s. "), reason);
|
2007-10-07 17:14:02 +05:30
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* new_password - validate old password and replace with new (both old and
|
|
|
|
* new in global "char crypt_passwd[128]")
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-10-07 17:17:01 +05:30
|
|
|
static int new_password (const struct passwd *pw)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:14:59 +05:30
|
|
|
char *clear; /* Pointer to clear text */
|
|
|
|
char *cipher; /* Pointer to cipher text */
|
|
|
|
char *cp; /* Pointer to getpass() response */
|
|
|
|
char orig[200]; /* Original password */
|
|
|
|
char pass[200]; /* New password */
|
|
|
|
int i; /* Counter for retries */
|
|
|
|
int warned;
|
2007-11-20 03:44:19 +05:30
|
|
|
int pass_max_len = -1;
|
|
|
|
char *method;
|
2007-10-07 17:14:59 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef HAVE_LIBCRACK_HIST
|
2007-10-07 17:14:59 +05:30
|
|
|
int HistUpdate (const char *, const char *);
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Authenticate the user. The user will be prompted for their own
|
|
|
|
* password.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!amroot && crypt_passwd[0]) {
|
|
|
|
if (!(clear = getpass (_("Old password: "))))
|
2007-10-07 17:14:02 +05:30
|
|
|
return -1;
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
cipher = pw_encrypt (clear, crypt_passwd);
|
|
|
|
if (strcmp (cipher, crypt_passwd) != 0) {
|
2007-10-07 17:17:01 +05:30
|
|
|
SYSLOG ((LOG_WARN, "incorrect password for %s",
|
2007-10-07 17:14:59 +05:30
|
|
|
pw->pw_name));
|
|
|
|
sleep (1);
|
|
|
|
fprintf (stderr,
|
2007-10-07 17:17:01 +05:30
|
|
|
_("Incorrect password for %s.\n"),
|
2007-10-07 17:14:59 +05:30
|
|
|
pw->pw_name);
|
2007-10-07 17:14:02 +05:30
|
|
|
return -1;
|
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
STRFCPY (orig, clear);
|
|
|
|
strzero (clear);
|
|
|
|
strzero (cipher);
|
2007-10-07 17:14:02 +05:30
|
|
|
} else {
|
|
|
|
orig[0] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Get the new password. The user is prompted for the new password
|
|
|
|
* and has five tries to get it right. The password will be tested
|
|
|
|
* for strength, unless it is the root user. This provides an escape
|
2007-10-07 17:14:02 +05:30
|
|
|
* for initial login passwords.
|
|
|
|
*/
|
2007-11-20 03:44:19 +05:30
|
|
|
if ((method = getdef_str ("ENCRYPT_METHOD")) == NULL) {
|
|
|
|
if (!getdef_bool ("MD5_CRYPT_ENAB"))
|
|
|
|
pass_max_len = getdef_num ("PASS_MAX_LEN", 8);
|
|
|
|
} else {
|
* configure.in: New configure option: --with-sha-crypt enabled by
default. Keeping the feature enabled is safe. Disabling it permits
to disable the references to the SHA256 and SHA512 password
encryption algorithms from the usage help and manuals (in addition
to the support for these algorithms in the code).
* libmisc/obscure.c, libmisc/salt.c, src/newusers.c,
src/chpasswd.c, src/chgpasswd.c, src/passwd.c: ENCRYPT_METHOD is
always supported in login.defs. Remove the ENCRYPTMETHOD_SELECT
preprocessor condition.
* libmisc/obscure.c, libmisc/salt.c, src/newusers.c,
src/chpasswd.c, src/chgpasswd.c, src/passwd.c: Disable SHA256 and
SHA512 if USE_SHA_CRYPT is not defined (this corresponds to a
subset of the ENCRYPTMETHOD_SELECT sections).
2007-11-24 18:38:08 +05:30
|
|
|
if ( !strcmp (method, "MD5")
|
|
|
|
#ifdef USE_SHA_CRYPT
|
|
|
|
|| !strcmp (method, "SHA256")
|
|
|
|
|| !strcmp (method, "SHA512")
|
|
|
|
#endif
|
|
|
|
)
|
2007-11-20 03:44:19 +05:30
|
|
|
pass_max_len = -1;
|
|
|
|
else
|
|
|
|
pass_max_len = getdef_num ("PASS_MAX_LEN", 8);
|
|
|
|
}
|
|
|
|
if (!qflg) {
|
|
|
|
if (pass_max_len == -1) {
|
|
|
|
printf (_(
|
|
|
|
"Enter the new password (minimum of %d characters)\n"
|
|
|
|
"Please use a combination of upper and lower case letters and numbers.\n"),
|
|
|
|
getdef_num ("PASS_MIN_LEN", 5));
|
|
|
|
} else {
|
|
|
|
printf (_(
|
|
|
|
"Enter the new password (minimum of %d, maximum of %d characters)\n"
|
|
|
|
"Please use a combination of upper and lower case letters and numbers.\n"),
|
|
|
|
getdef_num ("PASS_MIN_LEN", 5), pass_max_len);
|
|
|
|
}
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
warned = 0;
|
2007-10-07 17:14:59 +05:30
|
|
|
for (i = getdef_num ("PASS_CHANGE_TRIES", 5); i > 0; i--) {
|
|
|
|
if (!(cp = getpass (_("New password: ")))) {
|
|
|
|
memzero (orig, sizeof orig);
|
2007-10-07 17:14:02 +05:30
|
|
|
return -1;
|
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
if (warned && strcmp (pass, cp) != 0)
|
2007-10-07 17:14:02 +05:30
|
|
|
warned = 0;
|
2007-10-07 17:14:59 +05:30
|
|
|
STRFCPY (pass, cp);
|
|
|
|
strzero (cp);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
if (!amroot && (!obscure (orig, pass, pw) || reuse (pass, pw))) {
|
* 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 (_("Try again."));
|
2007-10-07 17:14:02 +05:30
|
|
|
continue;
|
|
|
|
}
|
2007-10-07 17:17:01 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* If enabled, warn about weak passwords even if you are
|
|
|
|
* root (enter this password again to use it anyway).
|
|
|
|
* --marekm
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
if (amroot && !warned && getdef_bool ("PASS_ALWAYS_WARN")
|
|
|
|
&& (!obscure (orig, pass, pw) || reuse (pass, pw))) {
|
* 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 (_("\nWarning: weak password (enter it again to use it anyway)."));
|
2007-10-07 17:14:02 +05:30
|
|
|
warned++;
|
|
|
|
continue;
|
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!(cp = getpass (_("Re-enter new password: ")))) {
|
|
|
|
memzero (orig, sizeof orig);
|
2007-10-07 17:14:02 +05:30
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (strcmp (cp, pass))
|
2008-01-25 02:12:12 +05:30
|
|
|
fputs (_("They don't match; try again.\n"), stderr);
|
2007-10-07 17:14:02 +05:30
|
|
|
else {
|
2007-10-07 17:14:59 +05:30
|
|
|
strzero (cp);
|
2007-10-07 17:14:02 +05:30
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
memzero (orig, sizeof orig);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
if (i == 0) {
|
2007-10-07 17:14:59 +05:30
|
|
|
memzero (pass, sizeof pass);
|
2007-10-07 17:14:02 +05:30
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Encrypt the password, then wipe the cleartext password.
|
|
|
|
*/
|
2007-11-20 15:21:36 +05:30
|
|
|
cp = pw_encrypt (pass, crypt_make_salt (NULL, NULL));
|
2007-10-07 17:14:59 +05:30
|
|
|
memzero (pass, sizeof pass);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
#ifdef HAVE_LIBCRACK_HIST
|
2007-10-07 17:14:59 +05:30
|
|
|
HistUpdate (pw->pw_name, crypt_passwd);
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
2007-10-07 17:14:59 +05:30
|
|
|
STRFCPY (crypt_passwd, cp);
|
2007-10-07 17:14:02 +05:30
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* check_password - test a password to see if it can be changed
|
|
|
|
*
|
|
|
|
* check_password() sees if the invoker has permission to change the
|
|
|
|
* password for the given user.
|
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
static void check_password (const struct passwd *pw, const struct spwd *sp)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
time_t now, last, ok;
|
|
|
|
int exp_status;
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
exp_status = isexpired (pw, sp);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* If not expired and the "change only if expired" option (idea from
|
|
|
|
* PAM) was specified, do nothing. --marekm
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
if (kflg && exp_status == 0)
|
2007-10-07 17:14:59 +05:30
|
|
|
exit (E_SUCCESS);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Root can change any password any time.
|
|
|
|
*/
|
2008-06-10 23:20:21 +05:30
|
|
|
if (amroot) {
|
2007-10-07 17:14:02 +05:30
|
|
|
return;
|
2008-06-10 23:20:21 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-06-14 02:39:14 +05:30
|
|
|
(void) time (&now);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Expired accounts cannot be changed ever. Passwords which are
|
|
|
|
* locked may not be changed. Passwords where min > max may not be
|
|
|
|
* changed. Passwords which have been inactive too long cannot be
|
|
|
|
* changed.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
if (sp->sp_pwdp[0] == '!' || exp_status > 1 ||
|
|
|
|
(sp->sp_max >= 0 && sp->sp_min > sp->sp_max)) {
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr,
|
|
|
|
_("The password for %s cannot be changed.\n"),
|
|
|
|
sp->sp_namp);
|
2007-10-07 17:16:07 +05:30
|
|
|
SYSLOG ((LOG_WARN, "password locked for `%s'", sp->sp_namp));
|
2007-10-07 17:14:59 +05:30
|
|
|
closelog ();
|
|
|
|
exit (E_NOPERM);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Passwords may only be changed after sp_min time is up.
|
|
|
|
*/
|
|
|
|
last = sp->sp_lstchg * SCALE;
|
|
|
|
ok = last + (sp->sp_min > 0 ? sp->sp_min * SCALE : 0);
|
|
|
|
|
|
|
|
if (now < ok) {
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr,
|
|
|
|
_
|
2007-10-27 18:16:30 +05:30
|
|
|
("The password for %s cannot be changed yet.\n"),
|
2007-10-07 17:14:59 +05:30
|
|
|
pw->pw_name);
|
2007-10-07 17:16:07 +05:30
|
|
|
SYSLOG ((LOG_WARN, "now < minimum age for `%s'", pw->pw_name));
|
2007-10-07 17:14:59 +05:30
|
|
|
closelog ();
|
|
|
|
exit (E_NOPERM);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* insert_crypt_passwd - add an "old-style" password to authentication
|
|
|
|
* string result now malloced to avoid overflow, just in case. --marekm
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
static char *insert_crypt_passwd (const char *string, const char *passwd)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:14:59 +05:30
|
|
|
return xstrdup (passwd);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
#endif /* !USE_PAM */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
static char *date_to_str (time_t t)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
static char buf[80];
|
|
|
|
struct tm *tm;
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
tm = gmtime (&t);
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef HAVE_STRFTIME
|
2007-10-07 17:14:59 +05:30
|
|
|
strftime (buf, sizeof buf, "%m/%d/%Y", tm);
|
2007-10-07 17:14:02 +05:30
|
|
|
#else
|
2007-10-07 17:14:59 +05:30
|
|
|
snprintf (buf, sizeof buf, "%02d/%02d/%04d",
|
|
|
|
tm->tm_mon + 1, tm->tm_mday, tm->tm_year + 1900);
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
static const char *pw_status (const char *pass)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2008-06-10 23:20:21 +05:30
|
|
|
if (*pass == '*' || *pass == '!') {
|
2007-10-07 17:14:02 +05:30
|
|
|
return "L";
|
2008-06-10 23:20:21 +05:30
|
|
|
}
|
|
|
|
if (*pass == '\0') {
|
2007-10-07 17:14:02 +05:30
|
|
|
return "NP";
|
2008-06-10 23:20:21 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
return "P";
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* print_status - print current password status
|
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
static void print_status (const struct passwd *pw)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
struct spwd *sp;
|
|
|
|
|
* lib/prototypes.h, configure.in, libmisc/Makefile.am,
libmisc/xgetXXbyYY.c, libmisc/xgetpwnam.c, libmisc/xgetpwuid.c,
libmisc/xgetgrnam.c, libmisc/xgetgrgid.c, libmisc/xgetspnam.c:
Added functions xgetpwnam(), xgetpwuid(), xgetgrnam(),
xgetgrgid(), and xgetspnam(). They allocate memory for the
returned structure and are more robust to successive calls. They
are implemented with the libc's getxxyyy_r() functions if
available.
* libmisc/limits.c, libmisc/entry.c, libmisc/chowntty.c,
libmisc/addgrps.c, libmisc/myname.c, libmisc/rlogin.c,
libmisc/pwdcheck.c, src/newgrp.c, src/login_nopam.c,
src/userdel.c, src/lastlog.c, src/grpck.c, src/gpasswd.c,
src/newusers.c, src/chpasswd.c, src/chfn.c, src/groupmems.c,
src/usermod.c, src/expiry.c, src/groupdel.c, src/chgpasswd.c,
src/su.c, src/useradd.c, src/groupmod.c, src/passwd.c, src/pwck.c,
src/groupadd.c, src/chage.c, src/login.c, src/suauth.c,
src/faillog.c, src/groups.c, src/chsh.c, src/id.c: Review all the
usage of one of the getpwnam(), getpwuid(), getgrnam(),
getgrgid(), and getspnam() functions. It was noticed on
http://bugs.debian.org/341230 that chfn and chsh use a passwd
structure after calling a pam function, which result in using
information from the passwd structure requested by pam, not the
original one. It is much easier to use the new xget... functions
to avoid these issues. I've checked which call to the original
get... functions could be left (reducing the scope of the
structure if possible), and I've left comments to ease future
reviews (e.g. /* local, no need for xgetpwnam */).
Note: the getpwent/getgrent calls should probably be checked also.
* src/groupdel.c, src/expiry.c: Fix typos in comments.
* src/groupmod.c: Re-indent.
* libmisc/Makefile.am, lib/groupmem.c, lib/groupio.c, lib/pwmem.c,
lib/pwio.c, lib/shadowmem.c, lib/shadowio.c: Move the __<xx>_dup
functions (used by the xget... functions) from the <xx>io.c files
to the new <xx>mem.c files. This avoid linking some utils against
the SELinux library.
2007-11-19 04:45:26 +05:30
|
|
|
sp = getspnam (pw->pw_name); /* local, no need for xgetspnam */
|
2008-06-10 23:20:21 +05:30
|
|
|
if (NULL != sp) {
|
2007-10-07 17:14:59 +05:30
|
|
|
printf ("%s %s %s %ld %ld %ld %ld\n",
|
2007-10-07 17:14:02 +05:30
|
|
|
pw->pw_name,
|
2007-10-07 17:14:59 +05:30
|
|
|
pw_status (sp->sp_pwdp),
|
|
|
|
date_to_str (sp->sp_lstchg * SCALE),
|
2007-10-07 17:14:02 +05:30
|
|
|
(sp->sp_min * SCALE) / DAY,
|
|
|
|
(sp->sp_max * SCALE) / DAY,
|
|
|
|
(sp->sp_warn * SCALE) / DAY,
|
|
|
|
(sp->sp_inact * SCALE) / DAY);
|
2007-10-07 17:16:25 +05:30
|
|
|
} else {
|
2007-10-07 17:14:59 +05:30
|
|
|
printf ("%s %s\n", pw->pw_name, pw_status (pw->pw_passwd));
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
static void fail_exit (int status)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:14:59 +05:30
|
|
|
pw_unlock ();
|
|
|
|
spw_unlock ();
|
|
|
|
exit (status);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
static void oom (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr, _("%s: out of memory\n"), Prog);
|
|
|
|
fail_exit (E_FAILURE);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
static char *update_crypt_pw (char *cp)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
#ifndef USE_PAM
|
2008-06-10 23:20:21 +05:30
|
|
|
if (do_update_pwd) {
|
2007-10-07 17:14:59 +05:30
|
|
|
cp = insert_crypt_passwd (cp, crypt_passwd);
|
2008-06-10 23:20:21 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
|
|
|
|
2008-06-10 23:20:21 +05:30
|
|
|
if (dflg) {
|
2008-01-07 00:56:58 +05:30
|
|
|
*cp = '\0';
|
2008-06-10 23:20:21 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-11-18 03:35:31 +05:30
|
|
|
if (uflg && *cp == '!') {
|
|
|
|
if (cp[1] == '\0') {
|
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: unlocking the user would result in a passwordless account.\n"
|
|
|
|
"You should set a password with usermod -p to unlock this user account.\n"),
|
|
|
|
Prog);
|
|
|
|
} else {
|
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
if (lflg && *cp != '!') {
|
2007-10-07 17:14:59 +05:30
|
|
|
char *newpw = xmalloc (strlen (cp) + 2);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
strcpy (newpw, "!");
|
|
|
|
strcat (newpw, cp);
|
2007-10-07 17:14:02 +05:30
|
|
|
cp = newpw;
|
|
|
|
}
|
|
|
|
return cp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
static void update_noshadow (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
const struct passwd *pw;
|
|
|
|
struct passwd *npw;
|
2007-10-07 17:14:59 +05:30
|
|
|
|
2008-06-10 23:20:21 +05:30
|
|
|
if (pw_lock () == 0) {
|
2008-01-25 02:12:12 +05:30
|
|
|
fputs (_("Cannot lock the password file; try again later.\n"),
|
|
|
|
stderr);
|
2007-10-07 17:14:59 +05:30
|
|
|
SYSLOG ((LOG_WARN, "can't lock password file"));
|
|
|
|
exit (E_PWDBUSY);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2008-06-10 23:20:21 +05:30
|
|
|
if (pw_open (O_RDWR) == 0) {
|
2008-01-25 02:12:12 +05:30
|
|
|
fputs (_("Cannot open the password file.\n"), stderr);
|
2007-10-07 17:14:59 +05:30
|
|
|
SYSLOG ((LOG_ERR, "can't open password file"));
|
|
|
|
fail_exit (E_MISSING);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
pw = pw_locate (name);
|
2008-06-10 23:20:21 +05:30
|
|
|
if (NULL == pw) {
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr, _("%s: %s not found in /etc/passwd\n"),
|
|
|
|
Prog, name);
|
|
|
|
fail_exit (E_NOPERM);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
npw = __pw_dup (pw);
|
2008-06-10 23:20:21 +05:30
|
|
|
if (NULL == npw) {
|
2007-10-07 17:14:59 +05:30
|
|
|
oom ();
|
2008-06-10 23:20:21 +05:30
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
npw->pw_passwd = update_crypt_pw (npw->pw_passwd);
|
2008-06-10 23:20:21 +05:30
|
|
|
if (pw_update (npw) == 0) {
|
2008-01-25 02:12:12 +05:30
|
|
|
fputs (_("Error updating the password entry.\n"), stderr);
|
2007-10-07 17:14:59 +05:30
|
|
|
SYSLOG ((LOG_ERR, "error updating password entry"));
|
|
|
|
fail_exit (E_FAILURE);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2008-06-10 23:20:21 +05:30
|
|
|
if (pw_close () == 0) {
|
2008-01-25 02:12:12 +05:30
|
|
|
fputs (_("Cannot commit password file changes.\n"), stderr);
|
2007-10-07 17:14:59 +05:30
|
|
|
SYSLOG ((LOG_ERR, "can't rewrite password file"));
|
|
|
|
fail_exit (E_FAILURE);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
pw_unlock ();
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
static void update_shadow (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
const struct spwd *sp;
|
|
|
|
struct spwd *nsp;
|
|
|
|
|
2008-06-10 23:20:21 +05:30
|
|
|
if (spw_lock () == 0) {
|
2008-01-25 02:12:12 +05:30
|
|
|
fputs (_("Cannot lock the password file; try again later.\n"),
|
|
|
|
stderr);
|
2007-10-07 17:14:59 +05:30
|
|
|
SYSLOG ((LOG_WARN, "can't lock password file"));
|
|
|
|
exit (E_PWDBUSY);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2008-06-10 23:20:21 +05:30
|
|
|
if (spw_open (O_RDWR) == 0) {
|
2008-01-25 02:12:12 +05:30
|
|
|
fputs (_("Cannot open the password file.\n"), stderr);
|
2007-10-07 17:14:59 +05:30
|
|
|
SYSLOG ((LOG_ERR, "can't open password file"));
|
|
|
|
fail_exit (E_FAILURE);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
sp = spw_locate (name);
|
2008-06-10 23:20:21 +05:30
|
|
|
if (NULL == sp) {
|
2007-10-07 17:14:59 +05:30
|
|
|
/* Try to update the password in /etc/passwd instead. */
|
|
|
|
spw_close ();
|
|
|
|
update_noshadow ();
|
|
|
|
spw_unlock ();
|
2007-10-07 17:14:02 +05:30
|
|
|
return;
|
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
nsp = __spw_dup (sp);
|
2008-06-10 23:20:21 +05:30
|
|
|
if (NULL == nsp) {
|
2007-10-07 17:14:59 +05:30
|
|
|
oom ();
|
2008-06-10 23:20:21 +05:30
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
nsp->sp_pwdp = update_crypt_pw (nsp->sp_pwdp);
|
2008-06-10 23:20:21 +05:30
|
|
|
if (xflg) {
|
2007-10-07 17:14:02 +05:30
|
|
|
nsp->sp_max = (age_max * DAY) / SCALE;
|
2008-06-10 23:20:21 +05:30
|
|
|
}
|
|
|
|
if (nflg) {
|
2007-10-07 17:14:02 +05:30
|
|
|
nsp->sp_min = (age_min * DAY) / SCALE;
|
2008-06-10 23:20:21 +05:30
|
|
|
}
|
|
|
|
if (wflg) {
|
2007-10-07 17:14:02 +05:30
|
|
|
nsp->sp_warn = (warn * DAY) / SCALE;
|
2008-06-10 23:20:21 +05:30
|
|
|
}
|
|
|
|
if (iflg) {
|
2007-10-07 17:14:02 +05:30
|
|
|
nsp->sp_inact = (inact * DAY) / SCALE;
|
2008-06-10 23:20:21 +05:30
|
|
|
}
|
|
|
|
if (do_update_age) {
|
2008-06-14 02:39:14 +05:30
|
|
|
nsp->sp_lstchg = (long) time ((time_t *) 0) / SCALE;
|
2008-06-10 23:20:21 +05:30
|
|
|
}
|
2007-11-17 22:10:39 +05:30
|
|
|
if (lflg) {
|
|
|
|
/* Set the account expiry field to 1.
|
|
|
|
* Some PAM implementation consider zero as a non expired
|
|
|
|
* account.
|
|
|
|
*/
|
|
|
|
nsp->sp_expire = 1;
|
|
|
|
}
|
|
|
|
if (uflg)
|
|
|
|
nsp->sp_expire = -1;
|
2007-10-07 17:17:01 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Force change on next login, like SunOS 4.x passwd -e or Solaris
|
|
|
|
* 2.x passwd -f. Solaris 2.x seems to do the same thing (set
|
|
|
|
* sp_lstchg to 0).
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
if (eflg)
|
|
|
|
nsp->sp_lstchg = 0;
|
|
|
|
|
2008-06-10 23:20:21 +05:30
|
|
|
if (spw_update (nsp) == 0) {
|
2008-01-25 02:12:12 +05:30
|
|
|
fputs (_("Error updating the password entry.\n"), stderr);
|
2007-10-07 17:14:59 +05:30
|
|
|
SYSLOG ((LOG_ERR, "error updating password entry"));
|
|
|
|
fail_exit (E_FAILURE);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2008-06-10 23:20:21 +05:30
|
|
|
if (spw_close () == 0) {
|
2008-01-25 02:12:12 +05:30
|
|
|
fputs (_("Cannot commit password file changes.\n"), stderr);
|
2007-10-07 17:14:59 +05:30
|
|
|
SYSLOG ((LOG_ERR, "can't rewrite password file"));
|
|
|
|
fail_exit (E_FAILURE);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
spw_unlock ();
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:17:57 +05:30
|
|
|
static long getnumber (const char *numstr)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
long val;
|
2007-10-07 17:17:57 +05:30
|
|
|
char *errptr;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:17:57 +05:30
|
|
|
val = strtol (numstr, &errptr, 10);
|
2008-06-10 23:20:21 +05:30
|
|
|
if (('\0' != *errptr) || (ERANGE == errno)) {
|
2007-10-07 17:17:57 +05:30
|
|
|
fprintf (stderr, _("%s: invalid numeric argument '%s'\n"), Prog,
|
|
|
|
numstr);
|
|
|
|
exit (E_BAD_ARG);
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2008-03-27 03:30:50 +05:30
|
|
|
#ifdef WITH_SELINUX
|
2008-05-24 18:38:58 +05:30
|
|
|
static int check_selinux_access (const char *changed_user,
|
|
|
|
uid_t changed_uid,
|
|
|
|
access_vector_t requested_access)
|
2008-03-27 03:30:50 +05:30
|
|
|
{
|
|
|
|
int status = -1;
|
|
|
|
security_context_t user_context;
|
2008-06-10 23:20:21 +05:30
|
|
|
context_t c;
|
2008-03-27 03:30:50 +05:30
|
|
|
const char *user;
|
|
|
|
|
|
|
|
/* if in permissive mode then allow the operation */
|
2008-06-10 23:20:21 +05:30
|
|
|
if (security_getenforce() == 0) {
|
2008-03-27 03:30:50 +05:30
|
|
|
return 0;
|
2008-06-10 23:20:21 +05:30
|
|
|
}
|
2008-03-27 03:30:50 +05:30
|
|
|
|
|
|
|
/* get the context of the process which executed passwd */
|
2008-06-10 23:20:21 +05:30
|
|
|
if (getprevcon(&user_context) != 0) {
|
2008-03-27 03:30:50 +05:30
|
|
|
return -1;
|
2008-06-10 23:20:21 +05:30
|
|
|
}
|
2008-03-27 03:30:50 +05:30
|
|
|
|
|
|
|
/* get the "user" portion of the context (the part before the first
|
|
|
|
colon) */
|
|
|
|
c = context_new(user_context);
|
|
|
|
user = context_user_get(c);
|
|
|
|
|
|
|
|
/* if changing a password for an account with UID==0 or for an account
|
|
|
|
where the identity matches then return success */
|
2008-05-24 18:38:58 +05:30
|
|
|
if (changed_uid != 0 && strcmp(changed_user, user) == 0) {
|
2008-03-27 03:30:50 +05:30
|
|
|
status = 0;
|
|
|
|
} else {
|
|
|
|
struct av_decision avd;
|
|
|
|
int retval;
|
2008-05-24 18:38:58 +05:30
|
|
|
retval = security_compute_av(user_context,
|
|
|
|
user_context,
|
|
|
|
SECCLASS_PASSWD,
|
|
|
|
requested_access,
|
|
|
|
&avd);
|
2008-03-27 03:30:50 +05:30
|
|
|
if ((retval == 0) &&
|
2008-05-24 18:38:58 +05:30
|
|
|
((requested_access & avd.allowed) == requested_access)) {
|
2008-03-27 03:30:50 +05:30
|
|
|
status = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
context_free(c);
|
|
|
|
freecon(user_context);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
|
|
|
* passwd - change a user's password file information
|
|
|
|
*
|
2007-10-07 17:14:59 +05:30
|
|
|
* This command controls the password file and commands which are used
|
|
|
|
* to modify it.
|
2007-10-07 17:14:02 +05:30
|
|
|
*
|
|
|
|
* The valid options are
|
|
|
|
*
|
|
|
|
* -d delete the password for the named account (*)
|
|
|
|
* -e expire the password for the named account (*)
|
|
|
|
* -f execute chfn command to interpret flags
|
2007-10-07 17:17:01 +05:30
|
|
|
* -g execute gpasswd command to interpret flags
|
|
|
|
* -i # set sp_inact to # days (*)
|
2007-10-07 17:14:02 +05:30
|
|
|
* -k change password only if expired
|
2007-10-07 17:17:01 +05:30
|
|
|
* -l lock the named account (*)
|
|
|
|
* -n # set sp_min to # days (*)
|
|
|
|
* -r # change password in # repository
|
|
|
|
* -s execute chsh command to interpret flags
|
|
|
|
* -S show password status of named account
|
|
|
|
* -u unlock the named account (*)
|
|
|
|
* -w # set sp_warn to # days (*)
|
|
|
|
* -x # set sp_max to # days (*)
|
2007-10-07 17:14:02 +05:30
|
|
|
*
|
|
|
|
* (*) requires root permission to execute.
|
|
|
|
*
|
|
|
|
* All of the time fields are entered in days and converted to the
|
2007-10-07 17:14:59 +05:30
|
|
|
* appropriate internal format. For finer resolute the chage
|
2007-10-07 17:14:02 +05:30
|
|
|
* command must be used.
|
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
int main (int argc, char **argv)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
const struct passwd *pw; /* Password file entry for user */
|
2007-10-07 17:14:59 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifndef USE_PAM
|
2007-10-07 17:14:59 +05:30
|
|
|
char *cp; /* Miscellaneous character pointing */
|
|
|
|
|
|
|
|
const struct spwd *sp; /* Shadow file entry for user */
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
|
|
|
|
2008-06-10 23:20:21 +05:30
|
|
|
(void) setlocale (LC_ALL, "");
|
|
|
|
(void) bindtextdomain (PACKAGE, LOCALEDIR);
|
|
|
|
(void) textdomain (PACKAGE);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* The program behaves differently when executed by root than when
|
|
|
|
* executed by a normal user.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
amroot = (getuid () == 0);
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Get the program name. The program name is used as a prefix to
|
|
|
|
* most error messages.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
Prog = Basename (argv[0]);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
sanitize_env ();
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
OPENLOG ("passwd");
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:17:01 +05:30
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Parse the command line options.
|
|
|
|
*/
|
|
|
|
int option_index = 0;
|
|
|
|
int c;
|
|
|
|
static struct option long_options[] = {
|
|
|
|
{"all", no_argument, NULL, 'a'},
|
|
|
|
{"delete", no_argument, NULL, 'd'},
|
|
|
|
{"expire", no_argument, NULL, 'e'},
|
|
|
|
{"help", no_argument, NULL, 'h'},
|
|
|
|
{"inactive", required_argument, NULL, 'i'},
|
|
|
|
{"keep-tokens", no_argument, NULL, 'k'},
|
|
|
|
{"lock", no_argument, NULL, 'l'},
|
|
|
|
{"mindays", required_argument, NULL, 'n'},
|
|
|
|
{"quiet", no_argument, NULL, 'q'},
|
|
|
|
{"repository", required_argument, NULL, 'r'},
|
|
|
|
{"status", no_argument, NULL, 'S'},
|
|
|
|
{"unlock", no_argument, NULL, 'u'},
|
2007-11-17 22:27:37 +05:30
|
|
|
{"warndays", required_argument, NULL, 'w'},
|
2007-10-07 17:17:01 +05:30
|
|
|
{"maxdays", required_argument, NULL, 'x'},
|
|
|
|
{NULL, 0, NULL, '\0'}
|
|
|
|
};
|
|
|
|
|
|
|
|
while ((c =
|
|
|
|
getopt_long (argc, argv, "adei:kln:qr:Suw:x:",
|
|
|
|
long_options, &option_index)) != -1) {
|
|
|
|
switch (c) {
|
|
|
|
case 'a':
|
2008-06-10 23:20:21 +05:30
|
|
|
aflg = true;
|
2007-10-07 17:17:01 +05:30
|
|
|
break;
|
|
|
|
case 'd':
|
2008-06-10 23:20:21 +05:30
|
|
|
dflg = true;
|
|
|
|
anyflag = true;
|
2007-10-07 17:17:01 +05:30
|
|
|
break;
|
|
|
|
case 'e':
|
2008-06-10 23:20:21 +05:30
|
|
|
eflg = true;
|
|
|
|
anyflag = true;
|
2007-10-07 17:17:01 +05:30
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
inact = getnumber (optarg);
|
|
|
|
if (inact >= -1)
|
2008-06-10 23:20:21 +05:30
|
|
|
iflg = true;
|
|
|
|
anyflag = true;
|
2007-10-07 17:17:01 +05:30
|
|
|
break;
|
|
|
|
case 'k':
|
|
|
|
/* change only if expired, like Linux-PAM passwd -k. */
|
2008-06-10 23:20:21 +05:30
|
|
|
kflg = true; /* ok for users */
|
2007-10-07 17:17:01 +05:30
|
|
|
break;
|
|
|
|
case 'l':
|
2008-06-10 23:20:21 +05:30
|
|
|
lflg = true;
|
|
|
|
anyflag = true;
|
2007-10-07 17:17:01 +05:30
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
age_min = getnumber (optarg);
|
2008-06-10 23:20:21 +05:30
|
|
|
nflg = true;
|
|
|
|
anyflag = true;
|
2007-10-07 17:17:01 +05:30
|
|
|
break;
|
|
|
|
case 'q':
|
2008-06-10 23:20:21 +05:30
|
|
|
qflg = true; /* ok for users */
|
2007-10-07 17:17:01 +05:30
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
/* -r repository (files|nis|nisplus) */
|
|
|
|
/* only "files" supported for now */
|
|
|
|
if (strcmp (optarg, "files") != 0) {
|
|
|
|
fprintf (stderr,
|
|
|
|
_
|
|
|
|
("%s: repository %s not supported\n"),
|
|
|
|
Prog, optarg);
|
|
|
|
exit (E_BAD_ARG);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'S':
|
2008-06-10 23:20:21 +05:30
|
|
|
Sflg = true; /* ok for users */
|
2007-10-07 17:17:01 +05:30
|
|
|
break;
|
|
|
|
case 'u':
|
2008-06-10 23:20:21 +05:30
|
|
|
uflg = true;
|
|
|
|
anyflag = true;
|
2007-10-07 17:17:01 +05:30
|
|
|
break;
|
|
|
|
case 'w':
|
|
|
|
warn = getnumber (optarg);
|
2008-06-10 23:20:21 +05:30
|
|
|
if (warn >= -1) {
|
|
|
|
wflg = true;
|
|
|
|
}
|
|
|
|
anyflag = true;
|
2007-10-07 17:17:01 +05:30
|
|
|
break;
|
|
|
|
case 'x':
|
|
|
|
age_max = getnumber (optarg);
|
2008-06-10 23:20:21 +05:30
|
|
|
xflg = true;
|
|
|
|
anyflag = true;
|
2007-10-07 17:17:01 +05:30
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage (E_BAD_ARG);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Now I have to get the user name. The name will be gotten from the
|
|
|
|
* command line if possible. Otherwise it is figured out from the
|
|
|
|
* environment.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
pw = get_my_pwent ();
|
2008-06-10 23:20:21 +05:30
|
|
|
if (NULL == pw) {
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr,
|
2007-10-07 17:16:07 +05:30
|
|
|
_("%s: Cannot determine your user name.\n"), Prog);
|
2007-10-07 17:14:59 +05:30
|
|
|
exit (E_NOPERM);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
myname = xstrdup (pw->pw_name);
|
2008-06-10 23:20:21 +05:30
|
|
|
if (optind < argc) {
|
2007-10-07 17:14:02 +05:30
|
|
|
name = argv[optind];
|
2008-06-10 23:20:21 +05:30
|
|
|
} else {
|
2007-10-07 17:14:02 +05:30
|
|
|
name = myname;
|
2008-06-10 23:20:21 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-12-27 03:47:13 +05:30
|
|
|
/*
|
|
|
|
* Make sure that at most one username was specified.
|
|
|
|
*/
|
2008-06-10 23:20:21 +05:30
|
|
|
if (argc > (optind+1)) {
|
2007-12-27 03:47:13 +05:30
|
|
|
usage (E_USAGE);
|
2008-06-10 23:20:21 +05:30
|
|
|
}
|
2007-12-27 03:47:13 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
|
|
|
* The -a flag requires -S, no other flags, no username, and
|
|
|
|
* you must be root. --marekm
|
|
|
|
*/
|
|
|
|
if (aflg) {
|
2008-06-10 23:20:21 +05:30
|
|
|
if (anyflag || !Sflg || (optind < argc)) {
|
2007-10-07 17:14:59 +05:30
|
|
|
usage (E_USAGE);
|
2008-06-10 23:20:21 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
if (!amroot) {
|
2007-10-07 17:16:25 +05:30
|
|
|
fprintf (stderr, _("%s: Permission denied.\n"), Prog);
|
2007-10-07 17:14:59 +05:30
|
|
|
exit (E_NOPERM);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
setpwent ();
|
Ensure that getpwent() is used in setpwent(), getpwent(),
endpwend() sequences (ditto for getgrent(), getspent(), and
getsgent()). The only real (minor) issue was in login, which kept
the passwd file open.
* libmisc/entry.c: Remove unneeded setspent() and endspent() (only
getspnam is called in the middle).
* libmisc/find_new_ids.c: Make sure to close the password and
group files with endpwent() and endgrent().
* libmisc/pwdcheck.c: Remove unneeded endspent() (only getspnam()
is called before).
* src/lastlog.c, src/passwd.c, src/groupmod.c, src/faillog.c,
src/groups.c: Make sure to close
the password file with endpwent().
* src/login.c: Remove unneeded setpwent() (only xgetpwnam is
called before).
* src/login.c, src/newgrp.c: Fix typos in comments.
2008-04-17 03:22:46 +05:30
|
|
|
while ( (pw = getpwent ()) != NULL ) {
|
2007-10-07 17:14:59 +05:30
|
|
|
print_status (pw);
|
Ensure that getpwent() is used in setpwent(), getpwent(),
endpwend() sequences (ditto for getgrent(), getspent(), and
getsgent()). The only real (minor) issue was in login, which kept
the passwd file open.
* libmisc/entry.c: Remove unneeded setspent() and endspent() (only
getspnam is called in the middle).
* libmisc/find_new_ids.c: Make sure to close the password and
group files with endpwent() and endgrent().
* libmisc/pwdcheck.c: Remove unneeded endspent() (only getspnam()
is called before).
* src/lastlog.c, src/passwd.c, src/groupmod.c, src/faillog.c,
src/groups.c: Make sure to close
the password file with endpwent().
* src/login.c: Remove unneeded setpwent() (only xgetpwnam is
called before).
* src/login.c, src/newgrp.c: Fix typos in comments.
2008-04-17 03:22:46 +05:30
|
|
|
}
|
|
|
|
endpwent ();
|
2007-10-07 17:14:59 +05:30
|
|
|
exit (E_SUCCESS);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
/*
|
|
|
|
* Allow certain users (administrators) to change passwords of
|
2007-10-07 17:14:59 +05:30
|
|
|
* certain users. Not implemented yet. --marekm
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
if (may_change_passwd (myname, name))
|
2007-10-07 17:14:02 +05:30
|
|
|
amroot = 1;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* If any of the flags were given, a user name must be supplied on
|
|
|
|
* the command line. Only an unadorned command line doesn't require
|
|
|
|
* the user's name be given. Also, -x, -n, -w, -i, -e, -d,
|
|
|
|
* -l, -u may appear with each other. -S, -k must appear alone.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* -S now ok for normal users (check status of my own account), and
|
|
|
|
* doesn't require username. --marekm
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2008-06-10 23:20:21 +05:30
|
|
|
if (anyflag && optind >= argc) {
|
2007-10-07 17:14:59 +05:30
|
|
|
usage (E_USAGE);
|
2008-06-10 23:20:21 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-06-10 23:20:21 +05:30
|
|
|
if ( (Sflg && kflg)
|
|
|
|
|| (anyflag && (Sflg || kflg))) {
|
2007-10-07 17:14:59 +05:30
|
|
|
usage (E_USAGE);
|
2008-06-10 23:20:21 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
if (anyflag && !amroot) {
|
2007-10-07 17:16:25 +05:30
|
|
|
fprintf (stderr, _("%s: Permission denied.\n"), Prog);
|
2007-10-07 17:14:59 +05:30
|
|
|
exit (E_NOPERM);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
* lib/prototypes.h, configure.in, libmisc/Makefile.am,
libmisc/xgetXXbyYY.c, libmisc/xgetpwnam.c, libmisc/xgetpwuid.c,
libmisc/xgetgrnam.c, libmisc/xgetgrgid.c, libmisc/xgetspnam.c:
Added functions xgetpwnam(), xgetpwuid(), xgetgrnam(),
xgetgrgid(), and xgetspnam(). They allocate memory for the
returned structure and are more robust to successive calls. They
are implemented with the libc's getxxyyy_r() functions if
available.
* libmisc/limits.c, libmisc/entry.c, libmisc/chowntty.c,
libmisc/addgrps.c, libmisc/myname.c, libmisc/rlogin.c,
libmisc/pwdcheck.c, src/newgrp.c, src/login_nopam.c,
src/userdel.c, src/lastlog.c, src/grpck.c, src/gpasswd.c,
src/newusers.c, src/chpasswd.c, src/chfn.c, src/groupmems.c,
src/usermod.c, src/expiry.c, src/groupdel.c, src/chgpasswd.c,
src/su.c, src/useradd.c, src/groupmod.c, src/passwd.c, src/pwck.c,
src/groupadd.c, src/chage.c, src/login.c, src/suauth.c,
src/faillog.c, src/groups.c, src/chsh.c, src/id.c: Review all the
usage of one of the getpwnam(), getpwuid(), getgrnam(),
getgrgid(), and getspnam() functions. It was noticed on
http://bugs.debian.org/341230 that chfn and chsh use a passwd
structure after calling a pam function, which result in using
information from the passwd structure requested by pam, not the
original one. It is much easier to use the new xget... functions
to avoid these issues. I've checked which call to the original
get... functions could be left (reducing the scope of the
structure if possible), and I've left comments to ease future
reviews (e.g. /* local, no need for xgetpwnam */).
Note: the getpwent/getgrent calls should probably be checked also.
* src/groupdel.c, src/expiry.c: Fix typos in comments.
* src/groupmod.c: Re-indent.
* libmisc/Makefile.am, lib/groupmem.c, lib/groupio.c, lib/pwmem.c,
lib/pwio.c, lib/shadowmem.c, lib/shadowio.c: Move the __<xx>_dup
functions (used by the xget... functions) from the <xx>io.c files
to the new <xx>mem.c files. This avoid linking some utils against
the SELinux library.
2007-11-19 04:45:26 +05:30
|
|
|
pw = xgetpwnam (name);
|
2008-06-10 23:20:21 +05:30
|
|
|
if (NULL == pw) {
|
2007-10-07 17:15:58 +05:30
|
|
|
fprintf (stderr, _("%s: unknown user %s\n"), Prog, name);
|
2007-10-07 17:14:59 +05:30
|
|
|
exit (E_NOPERM);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:16:07 +05:30
|
|
|
#ifdef WITH_SELINUX
|
2008-03-27 03:30:50 +05:30
|
|
|
/* only do this check when getuid()==0 because it's a pre-condition for
|
|
|
|
changing a password without entering the old one */
|
|
|
|
if ((is_selinux_enabled() > 0) && (getuid() == 0) &&
|
2008-05-24 18:38:58 +05:30
|
|
|
(check_selinux_access (name, pw->pw_uid, PASSWD__PASSWD) != 0)) {
|
2008-03-27 03:30:50 +05:30
|
|
|
security_context_t user_context;
|
|
|
|
if (getprevcon(&user_context) < 0) {
|
|
|
|
user_context = strdup("Unknown user context");
|
|
|
|
}
|
|
|
|
syslog(LOG_ALERT,
|
2008-05-24 18:38:58 +05:30
|
|
|
"%s is not authorized to change the password of %s",
|
|
|
|
user_context, name);
|
|
|
|
fprintf(stderr,
|
|
|
|
_("%s: %s is not authorized to change the password of %s\n"),
|
|
|
|
Prog, user_context, name);
|
2008-03-27 03:30:50 +05:30
|
|
|
freecon(user_context);
|
|
|
|
exit(1);
|
|
|
|
}
|
2008-05-24 18:38:58 +05:30
|
|
|
#endif /* WITH_SELINUX */
|
2008-03-27 03:30:50 +05:30
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
/*
|
|
|
|
* If the UID of the user does not match the current real UID,
|
|
|
|
* check if I'm root.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2008-06-10 23:20:21 +05:30
|
|
|
if (!amroot && (pw->pw_uid != getuid ())) {
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr,
|
2007-10-07 17:16:07 +05:30
|
|
|
_
|
|
|
|
("%s: You may not view or modify password information for %s.\n"),
|
|
|
|
Prog, name);
|
|
|
|
SYSLOG ((LOG_WARN,
|
|
|
|
"%s: can't view or modify password information for %s",
|
|
|
|
Prog, name));
|
2007-10-07 17:14:59 +05:30
|
|
|
closelog ();
|
|
|
|
exit (E_NOPERM);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
if (Sflg) {
|
2007-10-07 17:14:59 +05:30
|
|
|
print_status (pw);
|
|
|
|
exit (E_SUCCESS);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
#ifndef USE_PAM
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* The user name is valid, so let's get the shadow file entry.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
* lib/prototypes.h, configure.in, libmisc/Makefile.am,
libmisc/xgetXXbyYY.c, libmisc/xgetpwnam.c, libmisc/xgetpwuid.c,
libmisc/xgetgrnam.c, libmisc/xgetgrgid.c, libmisc/xgetspnam.c:
Added functions xgetpwnam(), xgetpwuid(), xgetgrnam(),
xgetgrgid(), and xgetspnam(). They allocate memory for the
returned structure and are more robust to successive calls. They
are implemented with the libc's getxxyyy_r() functions if
available.
* libmisc/limits.c, libmisc/entry.c, libmisc/chowntty.c,
libmisc/addgrps.c, libmisc/myname.c, libmisc/rlogin.c,
libmisc/pwdcheck.c, src/newgrp.c, src/login_nopam.c,
src/userdel.c, src/lastlog.c, src/grpck.c, src/gpasswd.c,
src/newusers.c, src/chpasswd.c, src/chfn.c, src/groupmems.c,
src/usermod.c, src/expiry.c, src/groupdel.c, src/chgpasswd.c,
src/su.c, src/useradd.c, src/groupmod.c, src/passwd.c, src/pwck.c,
src/groupadd.c, src/chage.c, src/login.c, src/suauth.c,
src/faillog.c, src/groups.c, src/chsh.c, src/id.c: Review all the
usage of one of the getpwnam(), getpwuid(), getgrnam(),
getgrgid(), and getspnam() functions. It was noticed on
http://bugs.debian.org/341230 that chfn and chsh use a passwd
structure after calling a pam function, which result in using
information from the passwd structure requested by pam, not the
original one. It is much easier to use the new xget... functions
to avoid these issues. I've checked which call to the original
get... functions could be left (reducing the scope of the
structure if possible), and I've left comments to ease future
reviews (e.g. /* local, no need for xgetpwnam */).
Note: the getpwent/getgrent calls should probably be checked also.
* src/groupdel.c, src/expiry.c: Fix typos in comments.
* src/groupmod.c: Re-indent.
* libmisc/Makefile.am, lib/groupmem.c, lib/groupio.c, lib/pwmem.c,
lib/pwio.c, lib/shadowmem.c, lib/shadowio.c: Move the __<xx>_dup
functions (used by the xget... functions) from the <xx>io.c files
to the new <xx>mem.c files. This avoid linking some utils against
the SELinux library.
2007-11-19 04:45:26 +05:30
|
|
|
sp = getspnam (name); /* !USE_PAM, no need for xgetspnam */
|
2008-06-10 23:20:21 +05:30
|
|
|
if (NULL == sp) {
|
2007-10-07 17:14:59 +05:30
|
|
|
sp = pwd_to_spwd (pw);
|
2008-06-10 23:20:21 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
cp = sp->sp_pwdp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If there are no other flags, just change the password.
|
|
|
|
*/
|
|
|
|
if (!anyflag) {
|
2007-10-07 17:15:23 +05:30
|
|
|
STRFCPY (crypt_passwd, cp);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* See if the user is permitted to change the password.
|
2007-10-07 17:14:02 +05:30
|
|
|
* Otherwise, go ahead and set a new password.
|
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
check_password (pw, sp);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Let the user know whose password is being changed.
|
|
|
|
*/
|
2008-06-10 23:20:21 +05:30
|
|
|
if (!qflg) {
|
2007-10-07 17:14:59 +05:30
|
|
|
printf (_("Changing password for %s\n"), name);
|
2008-06-10 23:20:21 +05:30
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
|
|
|
|
if (new_password (pw)) {
|
|
|
|
fprintf (stderr,
|
|
|
|
_("The password for %s is unchanged.\n"),
|
|
|
|
name);
|
|
|
|
closelog ();
|
|
|
|
exit (E_NOPERM);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2008-06-10 23:20:21 +05:30
|
|
|
do_update_pwd = true;
|
|
|
|
do_update_age = true;
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
#endif /* !USE_PAM */
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Before going any further, raise the ulimit to prevent colliding
|
|
|
|
* into a lowered ulimit, and set the real UID to root to protect
|
|
|
|
* against unexpected signals. Any keyboard signals are set to be
|
|
|
|
* ignored.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
pwd_init ();
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:17:01 +05:30
|
|
|
#ifdef USE_PAM
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
|
|
|
* Don't set the real UID for PAM...
|
|
|
|
*/
|
|
|
|
if (!anyflag) {
|
2007-10-07 17:14:59 +05:30
|
|
|
do_pam_passwd (name, qflg, kflg);
|
|
|
|
exit (E_SUCCESS);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:16:25 +05:30
|
|
|
#endif /* USE_PAM */
|
2008-06-10 23:20:21 +05:30
|
|
|
if (setuid (0) != 0) {
|
2008-01-25 02:12:12 +05:30
|
|
|
fputs (_("Cannot change ID to root.\n"), stderr);
|
2007-10-07 17:14:59 +05:30
|
|
|
SYSLOG ((LOG_ERR, "can't setuid(0)"));
|
|
|
|
closelog ();
|
|
|
|
exit (E_NOPERM);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2008-06-10 23:20:21 +05:30
|
|
|
if (spw_file_present ()) {
|
2007-10-07 17:14:59 +05:30
|
|
|
update_shadow ();
|
2008-06-10 23:20:21 +05:30
|
|
|
} else {
|
2007-10-07 17:14:59 +05:30
|
|
|
update_noshadow ();
|
2008-06-10 23:20:21 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:15:23 +05:30
|
|
|
nscd_flush_cache ("passwd");
|
|
|
|
nscd_flush_cache ("group");
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
SYSLOG ((LOG_INFO, "password for `%s' changed by `%s'", name, myname));
|
2007-10-07 17:14:59 +05:30
|
|
|
closelog ();
|
2007-10-07 17:17:22 +05:30
|
|
|
if (!qflg) {
|
2008-06-10 23:20:21 +05:30
|
|
|
if (!eflg) {
|
* 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 changed."));
|
2008-06-10 23:20:21 +05:30
|
|
|
} else {
|
* 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 set to expire."));
|
2008-06-10 23:20:21 +05:30
|
|
|
}
|
2007-10-07 17:17:22 +05:30
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
exit (E_SUCCESS);
|
2007-10-07 17:15:23 +05:30
|
|
|
/* NOT REACHED */
|
|
|
|
}
|
2008-06-10 23:20:21 +05:30
|
|
|
|