2007-10-07 17:14:02 +05:30
|
|
|
/*
|
2008-04-27 06:10:09 +05:30
|
|
|
* Copyright (c) 1992 - 1994, Julianne Frances Haugh
|
|
|
|
* Copyright (c) 1996 - 2000, Marek Michałkiewicz
|
|
|
|
* Copyright (c) 2001 , Michał Moskal
|
|
|
|
* 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
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
#include <fcntl.h>
|
|
|
|
#include <grp.h>
|
|
|
|
#include <pwd.h>
|
2007-10-07 17:17:01 +05:30
|
|
|
#include <stdio.h>
|
|
|
|
#include "chkname.h"
|
2007-10-07 17:14:02 +05:30
|
|
|
#include "commonio.h"
|
2007-10-07 17:17:01 +05:30
|
|
|
#include "defines.h"
|
|
|
|
#include "prototypes.h"
|
2007-10-07 17:14:02 +05:30
|
|
|
#include "pwio.h"
|
2007-10-07 17:17:01 +05:30
|
|
|
#include "shadowio.h"
|
2007-10-07 17:17:33 +05:30
|
|
|
#include "getdef.h"
|
2007-10-07 17:17:22 +05:30
|
|
|
#include "nscd.h"
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
2008-08-10 05:03:26 +05:30
|
|
|
#define E_CANTSORT 6
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
2007-10-07 17:17:01 +05:30
|
|
|
* Global variables
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
static char *Prog;
|
|
|
|
static const char *pwd_file = PASSWD_FILE;
|
2008-06-10 23:21:30 +05:30
|
|
|
static bool use_system_pw_file = true;
|
2007-10-07 17:14:02 +05:30
|
|
|
static const char *spw_file = SHADOW_FILE;
|
2008-06-10 23:21:30 +05:30
|
|
|
static bool use_system_spw_file = true;
|
2008-01-01 20:37:41 +05:30
|
|
|
|
2008-06-10 23:21:30 +05:30
|
|
|
static bool is_shadow = false;
|
2008-01-01 20:37:41 +05:30
|
|
|
|
2008-08-10 05:03:26 +05:30
|
|
|
static bool pw_locked = false;
|
|
|
|
static bool spw_locked = false;
|
|
|
|
|
2008-01-01 20:37:41 +05:30
|
|
|
/* Options */
|
2008-06-10 23:21:30 +05:30
|
|
|
static bool read_only = false;
|
|
|
|
static bool sort_mode = false;
|
|
|
|
static bool quiet = false; /* don't report warnings, only errors */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/* local function prototypes */
|
2008-08-10 05:03:26 +05:30
|
|
|
static void fail_exit (int code);
|
2007-10-07 17:14:59 +05:30
|
|
|
static void usage (void);
|
2008-01-01 20:37:41 +05:30
|
|
|
static void process_flags (int argc, char **argv);
|
2008-01-01 20:59:47 +05:30
|
|
|
static void open_files (void);
|
2008-06-11 03:39:12 +05:30
|
|
|
static void close_files (bool changed);
|
|
|
|
static void check_pw_file (int *errors, bool *changed);
|
|
|
|
static void check_spw_file (int *errors, bool *changed);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-08-10 05:03:26 +05:30
|
|
|
/*
|
|
|
|
* fail_exit - do some cleanup and exit with the given error code
|
|
|
|
*/
|
|
|
|
static void fail_exit (int code)
|
|
|
|
{
|
|
|
|
if (spw_locked) {
|
|
|
|
if (spw_unlock () == 0) {
|
|
|
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ());
|
|
|
|
SYSLOG ((LOG_ERR, "failed to unlock %s", spw_dbname ()));
|
|
|
|
/* continue */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pw_locked) {
|
|
|
|
if (pw_unlock () == 0) {
|
|
|
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ());
|
|
|
|
SYSLOG ((LOG_ERR, "failed to unlock %s", pw_dbname ()));
|
|
|
|
/* continue */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
closelog ();
|
|
|
|
|
|
|
|
exit (code);
|
|
|
|
}
|
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
|
|
|
{
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr, _("Usage: %s [-q] [-r] [-s] [passwd [shadow]]\n"),
|
2008-01-01 23:26:33 +05:30
|
|
|
Prog);
|
2007-10-07 17:14:59 +05:30
|
|
|
exit (E_USAGE);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2008-01-01 20:37:41 +05:30
|
|
|
* process_flags - parse the command line options
|
|
|
|
*
|
|
|
|
* It will not return if an error is encountered.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2008-01-01 20:37:41 +05:30
|
|
|
static void process_flags (int argc, char **argv)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:14:59 +05:30
|
|
|
int arg;
|
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':
|
2008-06-10 23:21:30 +05:30
|
|
|
quiet = true;
|
2007-10-07 17:14:02 +05:30
|
|
|
break;
|
|
|
|
case 'r':
|
2008-06-10 23:21:30 +05:30
|
|
|
read_only = true;
|
2007-10-07 17:14:02 +05:30
|
|
|
break;
|
2007-10-07 17:14:51 +05:30
|
|
|
case 's':
|
2008-06-10 23:21:30 +05:30
|
|
|
sort_mode = true;
|
2007-10-07 17:14:51 +05:30
|
|
|
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
|
|
|
|
*/
|
2008-01-01 23:34:46 +05:30
|
|
|
if ((argc < optind) || (argc > (optind + 2))) {
|
2007-10-07 17:14:59 +05:30
|
|
|
usage ();
|
2008-01-01 23:34:46 +05:30
|
|
|
}
|
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];
|
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
Added *_dbname() functions to retrieve the name of the databases.
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
*_name() functions renamed *setname().
* src/grpck.c, src/pwck.c: Likewise.
* lib/groupio.h, lib/pwio.h, lib/sgroupio.h, lib/shadowio.h: Added
the name of the arguments to the prototypes.
* src/chage, src/chfn.c, src/chgpasswd.c, src/chpasswd.c,
src/chsh.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c,
src/newusers.c, src/passwd.c, src/pwck.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c, src/usermod.c:
Harmonize the erro & syslog messages in case of failure of the
*_lock(), *_open(), *_close(), *_unlock(), *_remove() functions.
* src/chgpasswd.c, src/chpasswd.c, src/usermod.c: Avoid
capitalized messages.
* src/chpasswd.c, src/useradd.c, src/usermod.c: Harmonize messages
in case of inexistent entries.
* src/usermod.c: Harmonize messages in case of already existing
entries.
* src/newusers.c, src/useradd.c: Simplify PAM error handling.
* src/useradd.c: Report failures to unlock files (stderr, syslog,
and audit). But do not fail (continue).
* src/useradd.c (open_files): Do not report to syslog & audit
failures to lock or open the databases. This might be harmless,
and the logs were not already informed that a change was
requested.
* src/usermod.c: It's not the account which is unlocked, but its
password.
2008-08-06 21:27:31 +05:30
|
|
|
pw_setdbname (pwd_file);
|
2008-06-10 23:21:30 +05:30
|
|
|
use_system_pw_file = false;
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2008-01-01 23:57:40 +05:30
|
|
|
if ((optind + 2) == argc) {
|
2007-10-07 17:14:02 +05:30
|
|
|
spw_file = argv[optind + 1];
|
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
Added *_dbname() functions to retrieve the name of the databases.
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
*_name() functions renamed *setname().
* src/grpck.c, src/pwck.c: Likewise.
* lib/groupio.h, lib/pwio.h, lib/sgroupio.h, lib/shadowio.h: Added
the name of the arguments to the prototypes.
* src/chage, src/chfn.c, src/chgpasswd.c, src/chpasswd.c,
src/chsh.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c,
src/newusers.c, src/passwd.c, src/pwck.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c, src/usermod.c:
Harmonize the erro & syslog messages in case of failure of the
*_lock(), *_open(), *_close(), *_unlock(), *_remove() functions.
* src/chgpasswd.c, src/chpasswd.c, src/usermod.c: Avoid
capitalized messages.
* src/chpasswd.c, src/useradd.c, src/usermod.c: Harmonize messages
in case of inexistent entries.
* src/usermod.c: Harmonize messages in case of already existing
entries.
* src/newusers.c, src/useradd.c: Simplify PAM error handling.
* src/useradd.c: Report failures to unlock files (stderr, syslog,
and audit). But do not fail (continue).
* src/useradd.c (open_files): Do not report to syslog & audit
failures to lock or open the databases. This might be harmless,
and the logs were not already informed that a change was
requested.
* src/usermod.c: It's not the account which is unlocked, but its
password.
2008-08-06 21:27:31 +05:30
|
|
|
spw_setdbname (spw_file);
|
2008-06-10 23:21:30 +05:30
|
|
|
is_shadow = true;
|
|
|
|
use_system_spw_file = false;
|
2008-01-01 23:34:46 +05:30
|
|
|
} else if (optind == argc) {
|
2007-10-07 17:14:59 +05:30
|
|
|
is_shadow = spw_file_present ();
|
2008-01-01 23:34:46 +05:30
|
|
|
}
|
2008-01-01 20:37:41 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2008-01-01 20:59:47 +05:30
|
|
|
* open_files - open the shadow database
|
|
|
|
*
|
|
|
|
* In read-only mode, the databases are not locked and are opened
|
|
|
|
* only for reading.
|
2008-01-01 20:37:41 +05:30
|
|
|
*/
|
2008-01-01 20:59:47 +05:30
|
|
|
static void open_files (void)
|
2008-01-01 20:37:41 +05:30
|
|
|
{
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
|
|
|
* Lock the files if we aren't in "read-only" mode
|
|
|
|
*/
|
|
|
|
if (!read_only) {
|
2008-01-01 23:57:40 +05:30
|
|
|
if (pw_lock () == 0) {
|
* src/chage.c, src/chgpasswd.c, src/chpasswd.c, src/chsh.c,
src/gpasswd.c, src/groupadd.c, src/groupdel.c, src/groupmems.c,
src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c,
src/newusers.c, src/passwd.c, src/pwck.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c, src/usermod.c: In
case of a lock failure, indicate to the user that she can try
again later. Do not log to syslog.
2008-08-22 07:50:53 +05:30
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: cannot lock %s; try again later.\n"),
|
2008-01-01 23:26:33 +05:30
|
|
|
Prog, pwd_file);
|
2008-08-10 05:03:26 +05:30
|
|
|
fail_exit (E_CANTLOCK);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2008-08-10 05:03:26 +05:30
|
|
|
pw_locked = true;
|
|
|
|
if (is_shadow) {
|
|
|
|
if (spw_lock () == 0) {
|
* src/chage.c, src/chgpasswd.c, src/chpasswd.c, src/chsh.c,
src/gpasswd.c, src/groupadd.c, src/groupdel.c, src/groupmems.c,
src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c,
src/newusers.c, src/passwd.c, src/pwck.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c, src/usermod.c: In
case of a lock failure, indicate to the user that she can try
again later. Do not log to syslog.
2008-08-22 07:50:53 +05:30
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: cannot lock %s; try again later.\n"),
|
2008-08-10 05:03:26 +05:30
|
|
|
Prog, spw_file);
|
|
|
|
fail_exit (E_CANTLOCK);
|
2008-01-01 23:34:46 +05:30
|
|
|
}
|
2008-08-10 05:03:26 +05:30
|
|
|
spw_locked = true;
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
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
|
|
|
*/
|
2008-01-01 23:57:40 +05:30
|
|
|
if (pw_open (read_only ? O_RDONLY : O_RDWR) == 0) {
|
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
Added *_dbname() functions to retrieve the name of the databases.
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
*_name() functions renamed *setname().
* src/grpck.c, src/pwck.c: Likewise.
* lib/groupio.h, lib/pwio.h, lib/sgroupio.h, lib/shadowio.h: Added
the name of the arguments to the prototypes.
* src/chage, src/chfn.c, src/chgpasswd.c, src/chpasswd.c,
src/chsh.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c,
src/newusers.c, src/passwd.c, src/pwck.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c, src/usermod.c:
Harmonize the erro & syslog messages in case of failure of the
*_lock(), *_open(), *_close(), *_unlock(), *_remove() functions.
* src/chgpasswd.c, src/chpasswd.c, src/usermod.c: Avoid
capitalized messages.
* src/chpasswd.c, src/useradd.c, src/usermod.c: Harmonize messages
in case of inexistent entries.
* src/usermod.c: Harmonize messages in case of already existing
entries.
* src/newusers.c, src/useradd.c: Simplify PAM error handling.
* src/useradd.c: Report failures to unlock files (stderr, syslog,
and audit). But do not fail (continue).
* src/useradd.c (open_files): Do not report to syslog & audit
failures to lock or open the databases. This might be harmless,
and the logs were not already informed that a change was
requested.
* src/usermod.c: It's not the account which is unlocked, but its
password.
2008-08-06 21:27:31 +05:30
|
|
|
fprintf (stderr, _("%s: cannot open %s\n"),
|
2008-01-01 23:26:33 +05:30
|
|
|
Prog, pwd_file);
|
2008-01-01 23:34:46 +05:30
|
|
|
if (use_system_pw_file) {
|
2007-10-07 17:14:59 +05:30
|
|
|
SYSLOG ((LOG_WARN, "cannot open %s", pwd_file));
|
2008-01-01 23:34:46 +05:30
|
|
|
}
|
2008-08-10 05:03:26 +05:30
|
|
|
fail_exit (E_CANTOPEN);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2008-01-01 23:57:40 +05:30
|
|
|
if (is_shadow && (spw_open (read_only ? O_RDONLY : O_RDWR) == 0)) {
|
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
Added *_dbname() functions to retrieve the name of the databases.
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
*_name() functions renamed *setname().
* src/grpck.c, src/pwck.c: Likewise.
* lib/groupio.h, lib/pwio.h, lib/sgroupio.h, lib/shadowio.h: Added
the name of the arguments to the prototypes.
* src/chage, src/chfn.c, src/chgpasswd.c, src/chpasswd.c,
src/chsh.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c,
src/newusers.c, src/passwd.c, src/pwck.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c, src/usermod.c:
Harmonize the erro & syslog messages in case of failure of the
*_lock(), *_open(), *_close(), *_unlock(), *_remove() functions.
* src/chgpasswd.c, src/chpasswd.c, src/usermod.c: Avoid
capitalized messages.
* src/chpasswd.c, src/useradd.c, src/usermod.c: Harmonize messages
in case of inexistent entries.
* src/usermod.c: Harmonize messages in case of already existing
entries.
* src/newusers.c, src/useradd.c: Simplify PAM error handling.
* src/useradd.c: Report failures to unlock files (stderr, syslog,
and audit). But do not fail (continue).
* src/useradd.c (open_files): Do not report to syslog & audit
failures to lock or open the databases. This might be harmless,
and the logs were not already informed that a change was
requested.
* src/usermod.c: It's not the account which is unlocked, but its
password.
2008-08-06 21:27:31 +05:30
|
|
|
fprintf (stderr, _("%s: cannot open %s\n"),
|
2008-01-01 23:26:33 +05:30
|
|
|
Prog, spw_file);
|
2008-01-01 23:34:46 +05:30
|
|
|
if (use_system_spw_file) {
|
2007-10-07 17:14:59 +05:30
|
|
|
SYSLOG ((LOG_WARN, "cannot open %s", spw_file));
|
2008-01-01 23:34:46 +05:30
|
|
|
}
|
2008-08-10 05:03:26 +05:30
|
|
|
fail_exit (E_CANTOPEN);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2008-01-01 20:59:47 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* close_files - close and unlock the password/shadow databases
|
|
|
|
*
|
|
|
|
* If changed is not set, the databases are not closed, and no
|
|
|
|
* changes are committed in the databases. The databases are
|
|
|
|
* unlocked anyway.
|
|
|
|
*/
|
2008-06-11 03:39:12 +05:30
|
|
|
static void close_files (bool changed)
|
2008-01-01 20:59:47 +05:30
|
|
|
{
|
|
|
|
/*
|
|
|
|
* All done. If there were no change we can just abandon any
|
|
|
|
* changes to the files.
|
|
|
|
*/
|
|
|
|
if (changed) {
|
2008-01-01 23:57:40 +05:30
|
|
|
if (pw_close () == 0) {
|
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
Added *_dbname() functions to retrieve the name of the databases.
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
*_name() functions renamed *setname().
* src/grpck.c, src/pwck.c: Likewise.
* lib/groupio.h, lib/pwio.h, lib/sgroupio.h, lib/shadowio.h: Added
the name of the arguments to the prototypes.
* src/chage, src/chfn.c, src/chgpasswd.c, src/chpasswd.c,
src/chsh.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c,
src/newusers.c, src/passwd.c, src/pwck.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c, src/usermod.c:
Harmonize the erro & syslog messages in case of failure of the
*_lock(), *_open(), *_close(), *_unlock(), *_remove() functions.
* src/chgpasswd.c, src/chpasswd.c, src/usermod.c: Avoid
capitalized messages.
* src/chpasswd.c, src/useradd.c, src/usermod.c: Harmonize messages
in case of inexistent entries.
* src/usermod.c: Harmonize messages in case of already existing
entries.
* src/newusers.c, src/useradd.c: Simplify PAM error handling.
* src/useradd.c: Report failures to unlock files (stderr, syslog,
and audit). But do not fail (continue).
* src/useradd.c (open_files): Do not report to syslog & audit
failures to lock or open the databases. This might be harmless,
and the logs were not already informed that a change was
requested.
* src/usermod.c: It's not the account which is unlocked, but its
password.
2008-08-06 21:27:31 +05:30
|
|
|
fprintf (stderr, _("%s: failure while writing changes to %s\n"),
|
2008-01-01 23:26:33 +05:30
|
|
|
Prog, pwd_file);
|
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
Added *_dbname() functions to retrieve the name of the databases.
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
*_name() functions renamed *setname().
* src/grpck.c, src/pwck.c: Likewise.
* lib/groupio.h, lib/pwio.h, lib/sgroupio.h, lib/shadowio.h: Added
the name of the arguments to the prototypes.
* src/chage, src/chfn.c, src/chgpasswd.c, src/chpasswd.c,
src/chsh.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c,
src/newusers.c, src/passwd.c, src/pwck.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c, src/usermod.c:
Harmonize the erro & syslog messages in case of failure of the
*_lock(), *_open(), *_close(), *_unlock(), *_remove() functions.
* src/chgpasswd.c, src/chpasswd.c, src/usermod.c: Avoid
capitalized messages.
* src/chpasswd.c, src/useradd.c, src/usermod.c: Harmonize messages
in case of inexistent entries.
* src/usermod.c: Harmonize messages in case of already existing
entries.
* src/newusers.c, src/useradd.c: Simplify PAM error handling.
* src/useradd.c: Report failures to unlock files (stderr, syslog,
and audit). But do not fail (continue).
* src/useradd.c (open_files): Do not report to syslog & audit
failures to lock or open the databases. This might be harmless,
and the logs were not already informed that a change was
requested.
* src/usermod.c: It's not the account which is unlocked, but its
password.
2008-08-06 21:27:31 +05:30
|
|
|
SYSLOG ((LOG_WARN, "failure while writing changes to %s", pwd_file));
|
2008-08-10 05:03:26 +05:30
|
|
|
fail_exit (E_CANTUPDATE);
|
2008-01-01 20:59:47 +05:30
|
|
|
}
|
2008-01-01 23:57:40 +05:30
|
|
|
if (is_shadow && (spw_close () == 0)) {
|
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
Added *_dbname() functions to retrieve the name of the databases.
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
*_name() functions renamed *setname().
* src/grpck.c, src/pwck.c: Likewise.
* lib/groupio.h, lib/pwio.h, lib/sgroupio.h, lib/shadowio.h: Added
the name of the arguments to the prototypes.
* src/chage, src/chfn.c, src/chgpasswd.c, src/chpasswd.c,
src/chsh.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c,
src/newusers.c, src/passwd.c, src/pwck.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c, src/usermod.c:
Harmonize the erro & syslog messages in case of failure of the
*_lock(), *_open(), *_close(), *_unlock(), *_remove() functions.
* src/chgpasswd.c, src/chpasswd.c, src/usermod.c: Avoid
capitalized messages.
* src/chpasswd.c, src/useradd.c, src/usermod.c: Harmonize messages
in case of inexistent entries.
* src/usermod.c: Harmonize messages in case of already existing
entries.
* src/newusers.c, src/useradd.c: Simplify PAM error handling.
* src/useradd.c: Report failures to unlock files (stderr, syslog,
and audit). But do not fail (continue).
* src/useradd.c (open_files): Do not report to syslog & audit
failures to lock or open the databases. This might be harmless,
and the logs were not already informed that a change was
requested.
* src/usermod.c: It's not the account which is unlocked, but its
password.
2008-08-06 21:27:31 +05:30
|
|
|
fprintf (stderr, _("%s: failure while writing changes to %s\n"),
|
2008-01-01 23:26:33 +05:30
|
|
|
Prog, spw_file);
|
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
Added *_dbname() functions to retrieve the name of the databases.
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
*_name() functions renamed *setname().
* src/grpck.c, src/pwck.c: Likewise.
* lib/groupio.h, lib/pwio.h, lib/sgroupio.h, lib/shadowio.h: Added
the name of the arguments to the prototypes.
* src/chage, src/chfn.c, src/chgpasswd.c, src/chpasswd.c,
src/chsh.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c,
src/newusers.c, src/passwd.c, src/pwck.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c, src/usermod.c:
Harmonize the erro & syslog messages in case of failure of the
*_lock(), *_open(), *_close(), *_unlock(), *_remove() functions.
* src/chgpasswd.c, src/chpasswd.c, src/usermod.c: Avoid
capitalized messages.
* src/chpasswd.c, src/useradd.c, src/usermod.c: Harmonize messages
in case of inexistent entries.
* src/usermod.c: Harmonize messages in case of already existing
entries.
* src/newusers.c, src/useradd.c: Simplify PAM error handling.
* src/useradd.c: Report failures to unlock files (stderr, syslog,
and audit). But do not fail (continue).
* src/useradd.c (open_files): Do not report to syslog & audit
failures to lock or open the databases. This might be harmless,
and the logs were not already informed that a change was
requested.
* src/usermod.c: It's not the account which is unlocked, but its
password.
2008-08-06 21:27:31 +05:30
|
|
|
SYSLOG ((LOG_WARN, "failure while writing changes to %s", spw_file));
|
2008-08-10 05:03:26 +05:30
|
|
|
fail_exit (E_CANTUPDATE);
|
2008-01-01 20:59:47 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't be anti-social - unlock the files when you're done.
|
|
|
|
*/
|
2008-01-01 23:34:46 +05:30
|
|
|
if (is_shadow) {
|
2008-08-10 05:03:26 +05:30
|
|
|
if (spw_unlock () == 0) {
|
|
|
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ());
|
|
|
|
SYSLOG ((LOG_ERR, "failed to unlock %s", spw_dbname ()));
|
|
|
|
/* continue */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
spw_locked = false;
|
|
|
|
if (pw_unlock () == 0) {
|
|
|
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ());
|
|
|
|
SYSLOG ((LOG_ERR, "failed to unlock %s", pw_dbname ()));
|
|
|
|
/* continue */
|
2008-01-01 23:34:46 +05:30
|
|
|
}
|
2008-08-10 05:03:26 +05:30
|
|
|
pw_locked = false;
|
2008-01-01 20:59:47 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2008-01-01 21:19:33 +05:30
|
|
|
* check_pw_file - check the content of the passwd file
|
2008-01-01 20:59:47 +05:30
|
|
|
*/
|
2008-06-11 03:39:12 +05:30
|
|
|
static void check_pw_file (int *errors, bool *changed)
|
2008-01-01 20:59:47 +05:30
|
|
|
{
|
|
|
|
struct commonio_entry *pfe, *tpfe;
|
|
|
|
struct passwd *pwd;
|
|
|
|
struct spwd *spw;
|
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
|
|
|
* Loop through the entire password file.
|
|
|
|
*/
|
2008-01-01 23:57:40 +05:30
|
|
|
for (pfe = __pw_get_head (); NULL != 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
|
|
|
*/
|
2008-06-11 03:39:12 +05:30
|
|
|
if (('+' == pfe->line[0]) || ('-' == pfe->line[0])) {
|
2007-10-07 17:14:02 +05:30
|
|
|
continue;
|
2008-01-01 23:34:46 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
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
|
|
|
*/
|
2008-01-01 23:57:40 +05:30
|
|
|
if (NULL == 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
|
|
|
*/
|
* 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 (_("invalid password file entry"));
|
2007-10-07 17:17:33 +05:30
|
|
|
printf (_("delete line '%s'? "), pfe->line);
|
2008-01-01 21:19:33 +05:30
|
|
|
*errors += 1;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* prompt the user to delete the entry or not
|
|
|
|
*/
|
2008-01-01 23:34:46 +05:30
|
|
|
if (!yes_or_no (read_only)) {
|
2007-10-07 17:14:02 +05:30
|
|
|
continue;
|
2008-01-01 23:34:46 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
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:
|
* src/chfn.c, src/chsh.c, src/groupdel.c, src/groupmems.c,
src/groupmod.c, src/grpck.c, src/login.c, src/logoutd.c,
src/newgrp.c, src/newusers.c, src/passwd.c, src/pwck.c,
src/suauth.c, src/useradd.c, src/userdel.c, src/usermod.c,
src/vipw.c: Complete the switch from the `' quotation style to ''.
Do it also in SYSLOG messages. Quote some parameters. All this
permits to merge some messages.
2008-08-06 21:21:52 +05:30
|
|
|
SYSLOG ((LOG_INFO, "delete passwd line '%s'",
|
2008-01-01 23:26:33 +05:30
|
|
|
pfe->line));
|
2008-06-11 03:39:12 +05:30
|
|
|
*changed = true;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
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.
|
|
|
|
*/
|
2008-01-01 23:57:40 +05:30
|
|
|
for (tpfe = __pw_get_head (); NULL != 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
|
|
|
|
*/
|
2008-01-01 23:34:46 +05:30
|
|
|
if (tpfe == pfe) {
|
2007-10-07 17:14:02 +05:30
|
|
|
continue;
|
2008-01-01 23:34:46 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't check invalid entries.
|
|
|
|
*/
|
2008-01-01 23:57:40 +05:30
|
|
|
if (NULL == ent) {
|
2007-10-07 17:14:02 +05:30
|
|
|
continue;
|
2008-01-01 23:34:46 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-01-01 23:34:46 +05:30
|
|
|
if (strcmp (pwd->pw_name, ent->pw_name) != 0) {
|
2007-10-07 17:14:02 +05:30
|
|
|
continue;
|
2008-01-01 23:34:46 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Tell the user this entry is a duplicate of
|
|
|
|
* another and ask them to delete it.
|
|
|
|
*/
|
* 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 (_("duplicate password entry"));
|
2007-10-07 17:17:33 +05:30
|
|
|
printf (_("delete line '%s'? "), pfe->line);
|
2008-01-01 21:19:33 +05:30
|
|
|
*errors += 1;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* prompt the user to delete the entry or not
|
|
|
|
*/
|
2008-01-01 23:34:46 +05:30
|
|
|
if (yes_or_no (read_only)) {
|
2007-10-07 17:14:02 +05:30
|
|
|
goto delete_pw;
|
2008-01-01 23:34:46 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for invalid usernames. --marekm
|
|
|
|
*/
|
2008-05-26 02:28:16 +05:30
|
|
|
if (!is_valid_user_name (pwd->pw_name)) {
|
2007-10-07 17:16:07 +05:30
|
|
|
printf (_("invalid user name '%s'\n"), pwd->pw_name);
|
2008-01-01 21:19:33 +05:30
|
|
|
*errors += 1;
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure the primary group exists
|
|
|
|
*/
|
* 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
|
|
|
/* local, no need for xgetgrgid */
|
2008-01-01 23:57:40 +05:30
|
|
|
if (!quiet && (NULL == getgrgid (pwd->pw_gid))) {
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* No primary group, just give a warning
|
|
|
|
*/
|
|
|
|
|
2008-06-14 02:46:01 +05:30
|
|
|
printf (_("user %s: no group %lu\n"),
|
|
|
|
pwd->pw_name, (unsigned long) pwd->pw_gid);
|
2008-01-01 21:19:33 +05:30
|
|
|
*errors += 1;
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure the home directory exists
|
|
|
|
*/
|
2008-01-01 23:57:40 +05:30
|
|
|
if (!quiet && (access (pwd->pw_dir, F_OK) != 0)) {
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
|
|
|
* Home directory doesn't exist, give a warning
|
|
|
|
*/
|
* src/chfn.c, src/chsh.c, src/groupdel.c, src/groupmems.c,
src/groupmod.c, src/grpck.c, src/login.c, src/logoutd.c,
src/newgrp.c, src/newusers.c, src/passwd.c, src/pwck.c,
src/suauth.c, src/useradd.c, src/userdel.c, src/usermod.c,
src/vipw.c: Complete the switch from the `' quotation style to ''.
Do it also in SYSLOG messages. Quote some parameters. All this
permits to merge some messages.
2008-08-06 21:21:52 +05:30
|
|
|
printf (_("user '%s': directory '%s' does not exist\n"),
|
2008-01-01 23:26:33 +05:30
|
|
|
pwd->pw_name, pwd->pw_dir);
|
2008-01-01 21:19:33 +05:30
|
|
|
*errors += 1;
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure the login shell is executable
|
|
|
|
*/
|
2008-01-01 23:57:40 +05:30
|
|
|
if ( !quiet
|
|
|
|
&& ('\0' != pwd->pw_shell[0])
|
|
|
|
&& (access (pwd->pw_shell, F_OK) != 0)) {
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Login shell doesn't exist, give a warning
|
|
|
|
*/
|
* src/chfn.c, src/chsh.c, src/groupdel.c, src/groupmems.c,
src/groupmod.c, src/grpck.c, src/login.c, src/logoutd.c,
src/newgrp.c, src/newusers.c, src/passwd.c, src/pwck.c,
src/suauth.c, src/useradd.c, src/userdel.c, src/usermod.c,
src/vipw.c: Complete the switch from the `' quotation style to ''.
Do it also in SYSLOG messages. Quote some parameters. All this
permits to merge some messages.
2008-08-06 21:21:52 +05:30
|
|
|
printf (_("user '%s': program '%s' does not exist\n"),
|
2008-01-01 23:26:33 +05:30
|
|
|
pwd->pw_name, pwd->pw_shell);
|
2008-01-01 21:19:33 +05:30
|
|
|
*errors += 1;
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-11-17 22:20:26 +05:30
|
|
|
|
2007-10-07 17:17:33 +05:30
|
|
|
/*
|
2008-01-01 21:55:57 +05:30
|
|
|
* Make sure this entry exists in the /etc/shadow file.
|
2007-10-07 17:17:33 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
if (is_shadow) {
|
|
|
|
spw = (struct spwd *) spw_locate (pwd->pw_name);
|
2008-06-11 03:39:12 +05:30
|
|
|
if (NULL == spw) {
|
2008-01-01 23:26:33 +05:30
|
|
|
printf (_("no matching password file entry in %s\n"),
|
|
|
|
spw_file);
|
2007-10-07 17:17:33 +05:30
|
|
|
printf (_("add user '%s' in %s? "),
|
2008-01-01 23:26:33 +05:30
|
|
|
pwd->pw_name, spw_file);
|
2008-01-01 21:19:33 +05:30
|
|
|
*errors += 1;
|
2007-12-26 22:20:38 +05:30
|
|
|
if (yes_or_no (read_only)) {
|
2007-10-07 17:17:33 +05:30
|
|
|
struct spwd sp;
|
|
|
|
struct passwd pw;
|
|
|
|
|
2008-06-14 02:46:01 +05:30
|
|
|
sp.sp_namp = pwd->pw_name;
|
|
|
|
sp.sp_pwdp = pwd->pw_passwd;
|
|
|
|
sp.sp_min =
|
2007-10-07 17:17:33 +05:30
|
|
|
getdef_num ("PASS_MIN_DAYS", -1);
|
2008-06-14 02:46:01 +05:30
|
|
|
sp.sp_max =
|
2007-10-07 17:17:33 +05:30
|
|
|
getdef_num ("PASS_MAX_DAYS", -1);
|
2008-06-14 02:46:01 +05:30
|
|
|
sp.sp_warn =
|
2007-10-07 17:17:33 +05:30
|
|
|
getdef_num ("PASS_WARN_AGE", -1);
|
2008-06-14 02:46:01 +05:30
|
|
|
sp.sp_inact = -1;
|
2007-10-07 17:17:33 +05:30
|
|
|
sp.sp_expire = -1;
|
2008-06-14 02:46:01 +05:30
|
|
|
sp.sp_flag = SHADOW_SP_FLAG_UNSET;
|
|
|
|
sp.sp_lstchg = (long) time ((time_t *) 0) / SCALE;
|
2008-06-11 03:39:12 +05:30
|
|
|
*changed = true;
|
2007-10-07 17:17:33 +05:30
|
|
|
|
2008-01-01 23:57:40 +05:30
|
|
|
if (spw_update (&sp) == 0) {
|
2007-10-07 17:17:33 +05:30
|
|
|
fprintf (stderr,
|
2008-01-01 23:26:33 +05:30
|
|
|
_("%s: can't update shadow entry for %s\n"),
|
|
|
|
Prog, sp.sp_namp);
|
2007-10-07 17:17:33 +05:30
|
|
|
exit (E_CANTUPDATE);
|
|
|
|
}
|
|
|
|
/* remove password from /etc/passwd */
|
|
|
|
pw = *pwd;
|
|
|
|
pw.pw_passwd = SHADOW_PASSWD_STRING; /* XXX warning: const */
|
2008-01-01 23:57:40 +05:30
|
|
|
if (pw_update (&pw) == 0) {
|
2007-10-07 17:17:33 +05:30
|
|
|
fprintf (stderr,
|
2008-01-01 23:26:33 +05:30
|
|
|
_("%s: can't update passwd entry for %s\n"),
|
|
|
|
Prog, pw.pw_name);
|
2007-10-07 17:17:33 +05:30
|
|
|
exit (E_CANTUPDATE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2008-01-01 21:19:33 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-01-01 21:19:33 +05:30
|
|
|
/*
|
|
|
|
* check_spw_file - check the content of the shadowed password file (shadow)
|
|
|
|
*/
|
2008-06-11 03:39:12 +05:30
|
|
|
static void check_spw_file (int *errors, bool *changed)
|
2008-01-01 21:19:33 +05:30
|
|
|
{
|
|
|
|
struct commonio_entry *spe, *tspe;
|
|
|
|
struct spwd *spw;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Loop through the entire shadow password file.
|
|
|
|
*/
|
2008-01-01 23:57:40 +05:30
|
|
|
for (spe = __spw_get_head (); NULL != spe; spe = spe->next) {
|
2007-10-07 17:17:33 +05:30
|
|
|
/*
|
2008-01-01 21:55:57 +05:30
|
|
|
* Do not treat lines which were missing in shadow
|
2007-10-07 17:17:33 +05:30
|
|
|
* and were added earlier.
|
|
|
|
*/
|
2008-06-11 03:39:12 +05:30
|
|
|
if (NULL == spe->line) {
|
2007-10-07 17:17:33 +05:30
|
|
|
continue;
|
2008-01-01 23:34:46 +05:30
|
|
|
}
|
2007-10-07 17:17:33 +05:30
|
|
|
|
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
|
|
|
*/
|
2008-06-11 03:39:12 +05:30
|
|
|
if (('+' == spe->line[0]) || ('-' == spe->line[0])) {
|
2007-10-07 17:14:02 +05:30
|
|
|
continue;
|
2008-01-01 23:34:46 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
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
|
|
|
*/
|
2008-01-01 23:57:40 +05:30
|
|
|
if (NULL == 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
|
|
|
*/
|
* 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 (_("invalid shadow password file entry"));
|
2007-10-07 17:17:33 +05:30
|
|
|
printf (_("delete line '%s'? "), spe->line);
|
2008-01-01 21:19:33 +05:30
|
|
|
*errors += 1;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* prompt the user to delete the entry or not
|
|
|
|
*/
|
2008-01-01 23:34:46 +05:30
|
|
|
if (!yes_or_no (read_only)) {
|
2007-10-07 17:14:02 +05:30
|
|
|
continue;
|
2008-01-01 23:34:46 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
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:
|
* src/chfn.c, src/chsh.c, src/groupdel.c, src/groupmems.c,
src/groupmod.c, src/grpck.c, src/login.c, src/logoutd.c,
src/newgrp.c, src/newusers.c, src/passwd.c, src/pwck.c,
src/suauth.c, src/useradd.c, src/userdel.c, src/usermod.c,
src/vipw.c: Complete the switch from the `' quotation style to ''.
Do it also in SYSLOG messages. Quote some parameters. All this
permits to merge some messages.
2008-08-06 21:21:52 +05:30
|
|
|
SYSLOG ((LOG_INFO, "delete shadow line '%s'",
|
2008-01-01 23:26:33 +05:30
|
|
|
spe->line));
|
2008-06-11 03:39:12 +05:30
|
|
|
*changed = true;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
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.
|
|
|
|
*/
|
2008-01-01 23:57:40 +05:30
|
|
|
for (tspe = __spw_get_head (); NULL != 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
|
|
|
|
*/
|
2008-01-01 23:34:46 +05:30
|
|
|
if (tspe == spe) {
|
2007-10-07 17:14:02 +05:30
|
|
|
continue;
|
2008-01-01 23:34:46 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't check invalid entries.
|
|
|
|
*/
|
2008-01-01 23:57:40 +05:30
|
|
|
if (NULL == ent) {
|
2007-10-07 17:14:02 +05:30
|
|
|
continue;
|
2008-01-01 23:34:46 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-01-01 23:34:46 +05:30
|
|
|
if (strcmp (spw->sp_namp, ent->sp_namp) != 0) {
|
2007-10-07 17:14:02 +05:30
|
|
|
continue;
|
2008-01-01 23:34:46 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Tell the user this entry is a duplicate of
|
|
|
|
* another and ask them to delete it.
|
|
|
|
*/
|
* 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 (_("duplicate shadow password entry"));
|
2007-10-07 17:17:33 +05:30
|
|
|
printf (_("delete line '%s'? "), spe->line);
|
2008-01-01 21:19:33 +05:30
|
|
|
*errors += 1;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* prompt the user to delete the entry or not
|
|
|
|
*/
|
2008-01-01 23:34:46 +05:30
|
|
|
if (yes_or_no (read_only)) {
|
2007-10-07 17:14:02 +05:30
|
|
|
goto delete_spw;
|
2008-01-01 23:34:46 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure this entry exists in the /etc/passwd
|
|
|
|
* file.
|
|
|
|
*/
|
2008-01-01 23:57:40 +05:30
|
|
|
if (pw_locate (spw->sp_namp) == NULL) {
|
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:17:33 +05:30
|
|
|
printf (_("no matching password file entry in %s\n"),
|
2008-01-01 23:26:33 +05:30
|
|
|
pwd_file);
|
2007-10-07 17:17:33 +05:30
|
|
|
printf (_("delete line '%s'? "), spe->line);
|
2008-01-01 21:19:33 +05:30
|
|
|
*errors += 1;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* prompt the user to delete the entry or not
|
|
|
|
*/
|
2008-01-01 23:34:46 +05:30
|
|
|
if (yes_or_no (read_only)) {
|
2007-10-07 17:14:02 +05:30
|
|
|
goto delete_spw;
|
2008-01-01 23:34:46 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Warn if last password change in the future. --marekm
|
|
|
|
*/
|
2008-06-10 23:21:30 +05:30
|
|
|
if ( !quiet
|
2008-06-14 02:46:01 +05:30
|
|
|
&& (spw->sp_lstchg > (long) time ((time_t *) 0) / SCALE)) {
|
2008-01-01 23:26:33 +05:30
|
|
|
printf (_("user %s: last password change in the future\n"),
|
|
|
|
spw->sp_namp);
|
2008-01-01 21:19:33 +05:30
|
|
|
*errors += 1;
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
}
|
2008-01-01 21:19:33 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* pwck - verify password file integrity
|
|
|
|
*/
|
|
|
|
int main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
int errors = 0;
|
2008-06-11 03:39:12 +05:30
|
|
|
bool changed = false;
|
2008-01-01 21:19:33 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Get my name so that I can use it to report errors.
|
|
|
|
*/
|
|
|
|
Prog = Basename (argv[0]);
|
|
|
|
|
2008-06-10 23:21:30 +05:30
|
|
|
(void) setlocale (LC_ALL, "");
|
|
|
|
(void) bindtextdomain (PACKAGE, LOCALEDIR);
|
|
|
|
(void) textdomain (PACKAGE);
|
2008-01-01 21:19:33 +05:30
|
|
|
|
|
|
|
OPENLOG ("pwck");
|
|
|
|
|
|
|
|
/* Parse the command line arguments */
|
|
|
|
process_flags (argc, argv);
|
|
|
|
|
|
|
|
open_files ();
|
|
|
|
|
|
|
|
if (sort_mode) {
|
2008-08-10 05:03:26 +05:30
|
|
|
if (pw_sort () != 0) {
|
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: cannot sort entries in %s\n"),
|
|
|
|
Prog, pw_dbname ());
|
|
|
|
fail_exit (E_CANTSORT);
|
|
|
|
}
|
2008-01-01 23:34:46 +05:30
|
|
|
if (is_shadow) {
|
2008-08-10 05:03:26 +05:30
|
|
|
if (spw_sort () != 0) {
|
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: cannot sort entries in %s\n"),
|
|
|
|
Prog, spw_dbname ());
|
|
|
|
fail_exit (E_CANTSORT);
|
|
|
|
}
|
2008-01-01 23:34:46 +05:30
|
|
|
}
|
2008-06-11 03:39:12 +05:30
|
|
|
changed = true;
|
2008-01-01 21:22:07 +05:30
|
|
|
} else {
|
|
|
|
check_pw_file (&errors, &changed);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-01-01 21:22:07 +05:30
|
|
|
if (is_shadow) {
|
|
|
|
check_spw_file (&errors, &changed);
|
|
|
|
}
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-01-01 20:59:47 +05:30
|
|
|
close_files (changed);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:16:52 +05:30
|
|
|
nscd_flush_cache ("passwd");
|
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
|
|
|
* Tell the user what we did and exit.
|
|
|
|
*/
|
2008-06-11 03:39:12 +05:30
|
|
|
if (0 != errors) {
|
2007-10-07 17:17:33 +05:30
|
|
|
printf (changed ?
|
2008-01-01 23:26:33 +05:30
|
|
|
_("%s: the files have been updated\n") :
|
|
|
|
_("%s: no changes\n"), Prog);
|
2008-01-01 23:34:46 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
closelog ();
|
2008-06-11 03:39:12 +05:30
|
|
|
exit ((0 != errors) ? E_BADENTRY : E_OKAY);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2008-01-01 23:26:33 +05:30
|
|
|
|