2007-10-07 17:14:02 +05:30
|
|
|
/*
|
|
|
|
* Copyright 1992 - 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>
|
|
|
|
|
|
|
|
#include "rcsid.h"
|
2007-10-07 17:16:07 +05:30
|
|
|
RCSID (PKG_VER "$Id: pwck.c,v 1.26 2005/04/06 04:26:06 kloczek Exp $")
|
2007-10-07 17:14:02 +05:30
|
|
|
#include <stdio.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <grp.h>
|
|
|
|
#include "prototypes.h"
|
|
|
|
#include "defines.h"
|
|
|
|
#include "chkname.h"
|
|
|
|
#include <pwd.h>
|
|
|
|
#include "commonio.h"
|
|
|
|
#include "pwio.h"
|
2007-10-07 17:14:59 +05:30
|
|
|
extern void __pw_del_entry (const struct commonio_entry *);
|
|
|
|
extern struct commonio_entry *__pw_get_head (void);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
#ifdef SHADOWPWD
|
|
|
|
#include "shadowio.h"
|
2007-10-07 17:14:59 +05:30
|
|
|
extern void __spw_del_entry (const struct commonio_entry *);
|
|
|
|
extern struct commonio_entry *__spw_get_head (void);
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Exit codes
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define E_OKAY 0
|
|
|
|
#define E_USAGE 1
|
|
|
|
#define E_BADENTRY 2
|
|
|
|
#define E_CANTOPEN 3
|
|
|
|
#define E_CANTLOCK 4
|
|
|
|
#define E_CANTUPDATE 5
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables
|
|
|
|
*/
|
|
|
|
|
|
|
|
static char *Prog;
|
|
|
|
static const char *pwd_file = PASSWD_FILE;
|
2007-10-07 17:14:59 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef SHADOWPWD
|
|
|
|
static const char *spw_file = SHADOW_FILE;
|
|
|
|
#endif
|
|
|
|
static int read_only = 0;
|
2007-10-07 17:14:59 +05:30
|
|
|
static int quiet = 0; /* don't report warnings, only errors */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/* local function prototypes */
|
2007-10-07 17:14:59 +05:30
|
|
|
static void usage (void);
|
|
|
|
static int yes_or_no (void);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* usage - print syntax message and exit
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
static void usage (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
#ifdef SHADOWPWD
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr, _("Usage: %s [-q] [-r] [-s] [passwd [shadow]]\n"),
|
|
|
|
Prog);
|
2007-10-07 17:14:02 +05:30
|
|
|
#else
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr, _("Usage: %s [-q] [-r] [-s] [passwd]\n"), Prog);
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
2007-10-07 17:14:59 +05:30
|
|
|
exit (E_USAGE);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* yes_or_no - get answer to question from the user
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
static int yes_or_no (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
char buf[80];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* In read-only mode all questions are answered "no".
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (read_only) {
|
2007-10-07 17:14:59 +05:30
|
|
|
puts (_("No"));
|
2007-10-07 17:14:02 +05:30
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get a line and see what the first character is.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (fgets (buf, sizeof buf, stdin))
|
2007-10-07 17:14:02 +05:30
|
|
|
return buf[0] == 'y' || buf[0] == 'Y';
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* pwck - verify password file integrity
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
int main (int argc, char **argv)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:14:59 +05:30
|
|
|
int arg;
|
|
|
|
int errors = 0;
|
|
|
|
int deleted = 0;
|
|
|
|
struct commonio_entry *pfe, *tpfe;
|
|
|
|
struct passwd *pwd;
|
|
|
|
int sort_mode = 0;
|
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef SHADOWPWD
|
2007-10-07 17:14:59 +05:30
|
|
|
struct commonio_entry *spe, *tspe;
|
|
|
|
struct spwd *spw;
|
|
|
|
int is_shadow = 0;
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get my name so that I can use it to report errors.
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
setlocale (LC_ALL, "");
|
|
|
|
bindtextdomain (PACKAGE, LOCALEDIR);
|
|
|
|
textdomain (PACKAGE);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:15:40 +05:30
|
|
|
OPENLOG ("pwsk");
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Parse the command line arguments
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
while ((arg = getopt (argc, argv, "eqrs")) != EOF) {
|
2007-10-07 17:14:02 +05:30
|
|
|
switch (arg) {
|
2007-10-07 17:14:59 +05:30
|
|
|
case 'e': /* added for Debian shadow-961025-2 compatibility */
|
2007-10-07 17:14:02 +05:30
|
|
|
case 'q':
|
|
|
|
quiet = 1;
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
read_only = 1;
|
|
|
|
break;
|
2007-10-07 17:14:51 +05:30
|
|
|
case 's':
|
|
|
|
sort_mode = 1;
|
|
|
|
break;
|
2007-10-07 17:14:02 +05:30
|
|
|
default:
|
2007-10-07 17:14:59 +05:30
|
|
|
usage ();
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-07 17:14:51 +05:30
|
|
|
if (sort_mode && read_only) {
|
2007-10-07 17:16:07 +05:30
|
|
|
fprintf (stderr, _("%s: -s and -r are incompatibile\n"), Prog);
|
2007-10-07 17:14:59 +05:30
|
|
|
exit (E_USAGE);
|
2007-10-07 17:14:51 +05:30
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
|
|
|
* Make certain we have the right number of arguments
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef SHADOWPWD
|
|
|
|
if (optind != argc && optind + 1 != argc && optind + 2 != argc)
|
|
|
|
#else
|
|
|
|
if (optind != argc && optind + 1 != argc)
|
|
|
|
#endif
|
2007-10-07 17:14:59 +05:30
|
|
|
usage ();
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* If there are two left over filenames, use those as the password
|
|
|
|
* and shadow password filenames.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
if (optind != argc) {
|
|
|
|
pwd_file = argv[optind];
|
2007-10-07 17:14:59 +05:30
|
|
|
pw_name (pwd_file);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
#ifdef SHADOWPWD
|
|
|
|
if (optind + 2 == argc) {
|
|
|
|
spw_file = argv[optind + 1];
|
2007-10-07 17:14:59 +05:30
|
|
|
spw_name (spw_file);
|
2007-10-07 17:14:02 +05:30
|
|
|
is_shadow = 1;
|
|
|
|
} else if (optind == argc)
|
2007-10-07 17:14:59 +05:30
|
|
|
is_shadow = spw_file_present ();
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Lock the files if we aren't in "read-only" mode
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!read_only) {
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!pw_lock ()) {
|
|
|
|
fprintf (stderr, _("%s: cannot lock file %s\n"),
|
|
|
|
Prog, pwd_file);
|
2007-10-07 17:14:02 +05:30
|
|
|
if (optind == argc)
|
2007-10-07 17:16:07 +05:30
|
|
|
SYSLOG ((LOG_WARN, "cannot lock %s", pwd_file));
|
2007-10-07 17:14:59 +05:30
|
|
|
closelog ();
|
|
|
|
exit (E_CANTLOCK);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
#ifdef SHADOWPWD
|
2007-10-07 17:14:59 +05:30
|
|
|
if (is_shadow && !spw_lock ()) {
|
|
|
|
fprintf (stderr, _("%s: cannot lock file %s\n"),
|
|
|
|
Prog, spw_file);
|
2007-10-07 17:14:02 +05:30
|
|
|
if (optind == argc)
|
2007-10-07 17:16:07 +05:30
|
|
|
SYSLOG ((LOG_WARN, "cannot lock %s", spw_file));
|
2007-10-07 17:14:59 +05:30
|
|
|
closelog ();
|
|
|
|
exit (E_CANTLOCK);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Open the files. Use O_RDONLY if we are in read_only mode, O_RDWR
|
|
|
|
* otherwise.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!pw_open (read_only ? O_RDONLY : O_RDWR)) {
|
|
|
|
fprintf (stderr, _("%s: cannot open file %s\n"),
|
|
|
|
Prog, pwd_file);
|
2007-10-07 17:14:02 +05:30
|
|
|
if (optind == argc)
|
2007-10-07 17:14:59 +05:30
|
|
|
SYSLOG ((LOG_WARN, "cannot open %s", pwd_file));
|
|
|
|
closelog ();
|
|
|
|
exit (E_CANTOPEN);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
#ifdef SHADOWPWD
|
2007-10-07 17:14:59 +05:30
|
|
|
if (is_shadow && !spw_open (read_only ? O_RDONLY : O_RDWR)) {
|
|
|
|
fprintf (stderr, _("%s: cannot open file %s\n"),
|
|
|
|
Prog, spw_file);
|
2007-10-07 17:14:02 +05:30
|
|
|
if (optind == argc)
|
2007-10-07 17:14:59 +05:30
|
|
|
SYSLOG ((LOG_WARN, "cannot open %s", spw_file));
|
|
|
|
closelog ();
|
|
|
|
exit (E_CANTOPEN);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-10-07 17:14:51 +05:30
|
|
|
if (sort_mode) {
|
2007-10-07 17:14:59 +05:30
|
|
|
pw_sort ();
|
2007-10-07 17:14:51 +05:30
|
|
|
#ifdef SHADOWPWD
|
|
|
|
if (is_shadow)
|
2007-10-07 17:14:59 +05:30
|
|
|
spw_sort ();
|
2007-10-07 17:14:51 +05:30
|
|
|
#endif
|
|
|
|
goto write_and_bye;
|
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
|
|
|
* Loop through the entire password file.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
for (pfe = __pw_get_head (); pfe; pfe = pfe->next) {
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* If this is a NIS line, skip it. You can't "know" what NIS
|
|
|
|
* is going to do without directly asking NIS ...
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
if (pfe->line[0] == '+' || pfe->line[0] == '-')
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Start with the entries that are completely corrupt. They
|
|
|
|
* have no (struct passwd) entry because they couldn't be
|
|
|
|
* parsed properly.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:14 +05:30
|
|
|
if (!pfe->eptr) {
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Tell the user this entire line is bogus and ask
|
|
|
|
* them to delete it.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
printf (_("invalid password file entry\n"));
|
|
|
|
printf (_("delete line `%s'? "), pfe->line);
|
2007-10-07 17:14:02 +05:30
|
|
|
errors++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* prompt the user to delete the entry or not
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!yes_or_no ())
|
2007-10-07 17:14:02 +05:30
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* All password file deletions wind up here. This
|
2007-10-07 17:14:02 +05:30
|
|
|
* code removes the current entry from the linked
|
2007-10-07 17:14:59 +05:30
|
|
|
* list. When done, it skips back to the top of the
|
|
|
|
* loop to try out the next list element.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
delete_pw:
|
|
|
|
SYSLOG ((LOG_INFO, "delete passwd line `%s'",
|
|
|
|
pfe->line));
|
2007-10-07 17:14:02 +05:30
|
|
|
deleted++;
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
__pw_del_entry (pfe);
|
2007-10-07 17:14:02 +05:30
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Password structure is good, start using it.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:14 +05:30
|
|
|
pwd = pfe->eptr;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure this entry has a unique name.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
for (tpfe = __pw_get_head (); tpfe; tpfe = tpfe->next) {
|
2007-10-07 17:14:14 +05:30
|
|
|
const struct passwd *ent = tpfe->eptr;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't check this entry
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (tpfe == pfe)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't check invalid entries.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!ent)
|
|
|
|
continue;
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (strcmp (pwd->pw_name, ent->pw_name) != 0)
|
2007-10-07 17:14:02 +05:30
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Tell the user this entry is a duplicate of
|
|
|
|
* another and ask them to delete it.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
puts (_("duplicate password entry\n"));
|
|
|
|
printf (_("delete line `%s'? "), pfe->line);
|
2007-10-07 17:14:02 +05:30
|
|
|
errors++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* prompt the user to delete the entry or not
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (yes_or_no ())
|
2007-10-07 17:14:02 +05:30
|
|
|
goto delete_pw;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for invalid usernames. --marekm
|
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!check_user_name (pwd->pw_name)) {
|
2007-10-07 17:16:07 +05:30
|
|
|
printf (_("invalid user name '%s'\n"), pwd->pw_name);
|
2007-10-07 17:14:02 +05:30
|
|
|
errors++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure the primary group exists
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!quiet && !getgrgid (pwd->pw_gid)) {
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* No primary group, just give a warning
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
printf (_("user %s: no group %u\n"),
|
|
|
|
pwd->pw_name, pwd->pw_gid);
|
2007-10-07 17:14:02 +05:30
|
|
|
errors++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure the home directory exists
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!quiet && access (pwd->pw_dir, F_OK)) {
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Home directory doesn't exist, give a warning
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
printf (_
|
|
|
|
("user %s: directory %s does not exist\n"),
|
2007-10-07 17:14:02 +05:30
|
|
|
pwd->pw_name, pwd->pw_dir);
|
|
|
|
errors++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure the login shell is executable
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!quiet && pwd->pw_shell[0]
|
|
|
|
&& access (pwd->pw_shell, F_OK)) {
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Login shell doesn't exist, give a warning
|
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
|
|
|
|
printf (_("user %s: program %s does not exist\n"),
|
2007-10-07 17:14:02 +05:30
|
|
|
pwd->pw_name, pwd->pw_shell);
|
|
|
|
errors++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SHADOWPWD
|
|
|
|
if (!is_shadow)
|
|
|
|
goto shadow_done;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Loop through the entire shadow password file.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
for (spe = __spw_get_head (); spe; spe = spe->next) {
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* If this is a NIS line, skip it. You can't "know" what NIS
|
|
|
|
* is going to do without directly asking NIS ...
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
if (spe->line[0] == '+' || spe->line[0] == '-')
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Start with the entries that are completely corrupt. They
|
|
|
|
* have no (struct spwd) entry because they couldn't be
|
|
|
|
* parsed properly.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:14 +05:30
|
|
|
if (!spe->eptr) {
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Tell the user this entire line is bogus and ask
|
|
|
|
* them to delete it.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
printf (_("invalid shadow password file entry\n"));
|
|
|
|
printf (_("delete line `%s'? "), spe->line);
|
2007-10-07 17:14:02 +05:30
|
|
|
errors++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* prompt the user to delete the entry or not
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!yes_or_no ())
|
2007-10-07 17:14:02 +05:30
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* All shadow file deletions wind up here. This code
|
|
|
|
* removes the current entry from the linked list.
|
|
|
|
* When done, it skips back to the top of the loop
|
|
|
|
* to try out the next list element.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
delete_spw:
|
|
|
|
SYSLOG ((LOG_INFO, "delete shadow line `%s'",
|
|
|
|
spe->line));
|
2007-10-07 17:14:02 +05:30
|
|
|
deleted++;
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
__spw_del_entry (spe);
|
2007-10-07 17:14:02 +05:30
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Shadow password structure is good, start using it.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:14 +05:30
|
|
|
spw = spe->eptr;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure this entry has a unique name.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
for (tspe = __spw_get_head (); tspe; tspe = tspe->next) {
|
2007-10-07 17:14:14 +05:30
|
|
|
const struct spwd *ent = tspe->eptr;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't check this entry
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (tspe == spe)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't check invalid entries.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!ent)
|
|
|
|
continue;
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (strcmp (spw->sp_namp, ent->sp_namp) != 0)
|
2007-10-07 17:14:02 +05:30
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Tell the user this entry is a duplicate of
|
|
|
|
* another and ask them to delete it.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
puts (_("duplicate shadow password entry\n"));
|
|
|
|
printf (_("delete line `%s'? "), spe->line);
|
2007-10-07 17:14:02 +05:30
|
|
|
errors++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* prompt the user to delete the entry or not
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (yes_or_no ())
|
2007-10-07 17:14:02 +05:30
|
|
|
goto delete_spw;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure this entry exists in the /etc/passwd
|
|
|
|
* file.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!pw_locate (spw->sp_namp)) {
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Tell the user this entry has no matching
|
|
|
|
* /etc/passwd entry and ask them to delete it.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
puts (_("no matching password file entry\n"));
|
|
|
|
printf (_("delete line `%s'? "), spe->line);
|
2007-10-07 17:14:02 +05:30
|
|
|
errors++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* prompt the user to delete the entry or not
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (yes_or_no ())
|
2007-10-07 17:14:02 +05:30
|
|
|
goto delete_spw;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Warn if last password change in the future. --marekm
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!quiet && spw->sp_lstchg > time ((time_t *) 0) / SCALE) {
|
|
|
|
printf (_
|
|
|
|
("user %s: last password change in the future\n"),
|
|
|
|
spw->sp_namp);
|
2007-10-07 17:14:02 +05:30
|
|
|
errors++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
shadow_done:
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* All done. If there were no deletions we can just abandon any
|
2007-10-07 17:14:02 +05:30
|
|
|
* changes to the files.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (deleted) {
|
2007-10-07 17:14:59 +05:30
|
|
|
write_and_bye:
|
|
|
|
if (!pw_close ()) {
|
|
|
|
fprintf (stderr, _("%s: cannot update file %s\n"),
|
|
|
|
Prog, pwd_file);
|
|
|
|
SYSLOG ((LOG_WARN, "cannot update %s", pwd_file));
|
|
|
|
closelog ();
|
|
|
|
exit (E_CANTUPDATE);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
#ifdef SHADOWPWD
|
2007-10-07 17:14:59 +05:30
|
|
|
if (is_shadow && !spw_close ()) {
|
|
|
|
fprintf (stderr, _("%s: cannot update file %s\n"),
|
|
|
|
Prog, spw_file);
|
|
|
|
SYSLOG ((LOG_WARN, "cannot update %s", spw_file));
|
|
|
|
closelog ();
|
|
|
|
exit (E_CANTUPDATE);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't be anti-social - unlock the files when you're done.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef SHADOWPWD
|
|
|
|
if (is_shadow)
|
2007-10-07 17:14:59 +05:30
|
|
|
spw_unlock ();
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
2007-10-07 17:14:59 +05:30
|
|
|
(void) pw_unlock ();
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Tell the user what we did and exit.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (errors)
|
2007-10-07 17:14:59 +05:30
|
|
|
printf (deleted ?
|
2007-10-07 17:14:02 +05:30
|
|
|
_("%s: the files have been updated\n") :
|
|
|
|
_("%s: no changes\n"), Prog);
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
closelog ();
|
|
|
|
exit (errors ? E_BADENTRY : E_OKAY);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|