2007-10-07 17:17:22 +05:30
|
|
|
/*
|
2008-04-27 06:10:09 +05:30
|
|
|
* Copyright (c) 1990 - 1994, Julianne Frances Haugh
|
|
|
|
* Copyright (c) 2006 , Tomasz Kłoczko
|
|
|
|
* Copyright (c) 2006 , Jonas Meurer
|
|
|
|
* Copyright (c) 2007 - 2008, Nicolas François
|
2007-10-07 17:17:22 +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:17:22 +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:17:22 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-11-11 05:16:11 +05:30
|
|
|
#ident "$Id$"
|
2007-10-07 17:17:22 +05:30
|
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <pwd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#ifdef USE_PAM
|
|
|
|
#include "pam_defs.h"
|
|
|
|
#endif /* USE_PAM */
|
|
|
|
#include "defines.h"
|
2008-08-10 04:57:05 +05:30
|
|
|
#include "exitcodes.h"
|
2007-10-07 17:17:22 +05:30
|
|
|
#include "nscd.h"
|
|
|
|
#include "prototypes.h"
|
|
|
|
#include "groupio.h"
|
2007-10-07 17:17:33 +05:30
|
|
|
#ifdef SHADOWGRP
|
2007-10-07 17:17:22 +05:30
|
|
|
#include "sgroupio.h"
|
2007-10-07 17:17:33 +05:30
|
|
|
#endif
|
2007-10-07 17:17:22 +05:30
|
|
|
/*
|
|
|
|
* Global variables
|
|
|
|
*/
|
|
|
|
static char *Prog;
|
2008-06-10 02:26:03 +05:30
|
|
|
static bool cflg = false;
|
|
|
|
static bool eflg = false;
|
|
|
|
static bool md5flg = false;
|
|
|
|
static bool sflg = false;
|
2007-11-20 15:03:52 +05:30
|
|
|
|
2008-01-06 17:56:20 +05:30
|
|
|
static const char *crypt_method = NULL;
|
2007-11-24 01:39:57 +05:30
|
|
|
static long sha_rounds = 5000;
|
2007-10-07 17:17:22 +05:30
|
|
|
|
2007-10-07 17:17:33 +05:30
|
|
|
#ifdef SHADOWGRP
|
2008-06-10 02:26:03 +05:30
|
|
|
static bool is_shadow_grp;
|
* src/chfn.c, src/chgpasswd.c, src/chpasswd.c, src/gpasswd.c,
src/groupadd.c, src/groupdel.c, src/groupmems.c, src/groupmod.c,
src/grpconv.c, src/grpunconv.c, src/newusers.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c: Harmonize the name
of the variables keeping the lock status, to match the shadow
library prefixes.
2008-08-22 07:52:34 +05:30
|
|
|
static bool sgr_locked = false;
|
2007-10-07 17:17:33 +05:30
|
|
|
#endif
|
* src/chfn.c, src/chgpasswd.c, src/chpasswd.c, src/gpasswd.c,
src/groupadd.c, src/groupdel.c, src/groupmems.c, src/groupmod.c,
src/grpconv.c, src/grpunconv.c, src/newusers.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c: Harmonize the name
of the variables keeping the lock status, to match the shadow
library prefixes.
2008-08-22 07:52:34 +05:30
|
|
|
static bool gr_locked = false;
|
2007-10-07 17:17:22 +05:30
|
|
|
|
2007-12-31 10:27:54 +05:30
|
|
|
#ifdef USE_PAM
|
|
|
|
static pam_handle_t *pamh = NULL;
|
|
|
|
#endif
|
|
|
|
|
2007-10-07 17:17:22 +05:30
|
|
|
/* local function prototypes */
|
2008-08-10 04:52:00 +05:30
|
|
|
static void fail_exit (int code);
|
2007-10-07 17:17:22 +05:30
|
|
|
static void usage (void);
|
2007-12-29 04:24:35 +05:30
|
|
|
static void process_flags (int argc, char **argv);
|
|
|
|
static void check_flags (void);
|
|
|
|
static void check_perms (void);
|
|
|
|
static void open_files (void);
|
|
|
|
static void close_files (void);
|
2007-10-07 17:17:22 +05:30
|
|
|
|
2008-08-10 04:52:00 +05:30
|
|
|
/*
|
|
|
|
* fail_exit - exit with a failure code after unlocking the files
|
|
|
|
*/
|
|
|
|
static void fail_exit (int code)
|
|
|
|
{
|
* src/chfn.c, src/chgpasswd.c, src/chpasswd.c, src/gpasswd.c,
src/groupadd.c, src/groupdel.c, src/groupmems.c, src/groupmod.c,
src/grpconv.c, src/grpunconv.c, src/newusers.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c: Harmonize the name
of the variables keeping the lock status, to match the shadow
library prefixes.
2008-08-22 07:52:34 +05:30
|
|
|
if (gr_locked) {
|
2008-08-10 04:52:00 +05:30
|
|
|
if (gr_unlock () == 0) {
|
|
|
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ());
|
|
|
|
SYSLOG ((LOG_ERR, "failed to unlock %s", gr_dbname ()));
|
|
|
|
/* continue */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SHADOWGRP
|
* src/chfn.c, src/chgpasswd.c, src/chpasswd.c, src/gpasswd.c,
src/groupadd.c, src/groupdel.c, src/groupmems.c, src/groupmod.c,
src/grpconv.c, src/grpunconv.c, src/newusers.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c: Harmonize the name
of the variables keeping the lock status, to match the shadow
library prefixes.
2008-08-22 07:52:34 +05:30
|
|
|
if (sgr_locked) {
|
2008-08-10 04:52:00 +05:30
|
|
|
if (sgr_unlock () == 0) {
|
|
|
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname ());
|
|
|
|
SYSLOG ((LOG_ERR, "failed to unlock %s", sgr_dbname ()));
|
|
|
|
/* continue */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
exit (code);
|
|
|
|
}
|
|
|
|
|
2007-10-07 17:17:22 +05:30
|
|
|
/*
|
|
|
|
* usage - display usage message and exit
|
|
|
|
*/
|
|
|
|
static void usage (void)
|
|
|
|
{
|
2007-11-24 01:39:57 +05:30
|
|
|
fprintf (stderr, _("Usage: %s [options]\n"
|
2007-12-29 04:29:17 +05:30
|
|
|
"\n"
|
|
|
|
"Options:\n"
|
|
|
|
" -c, --crypt-method the crypt method (one of %s)\n"
|
|
|
|
" -e, --encrypted supplied passwords are encrypted\n"
|
|
|
|
" -h, --help display this help message and exit\n"
|
|
|
|
" -m, --md5 encrypt the clear text password using\n"
|
|
|
|
" the MD5 algorithm\n"
|
|
|
|
"%s"
|
|
|
|
"\n"),
|
|
|
|
Prog,
|
* 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
|
|
|
#ifndef USE_SHA_CRYPT
|
2007-12-29 04:29:17 +05:30
|
|
|
"NONE DES MD5", ""
|
2007-11-20 15:03:52 +05:30
|
|
|
#else
|
2007-12-29 04:29:17 +05:30
|
|
|
"NONE DES MD5 SHA256 SHA512",
|
|
|
|
_(" -s, --sha-rounds number of SHA rounds for the SHA*\n"
|
|
|
|
" crypt algorithms\n")
|
2007-11-20 15:03:52 +05:30
|
|
|
#endif
|
2007-12-29 04:29:17 +05:30
|
|
|
);
|
2008-08-10 04:55:49 +05:30
|
|
|
exit (E_USAGE);
|
2007-10-07 17:17:22 +05:30
|
|
|
}
|
|
|
|
|
2007-12-29 04:24:35 +05:30
|
|
|
/*
|
|
|
|
* process_flags - parse the command line options
|
|
|
|
*
|
|
|
|
* It will not return if an error is encountered.
|
|
|
|
*/
|
|
|
|
static void process_flags (int argc, char **argv)
|
2007-10-07 17:17:22 +05:30
|
|
|
{
|
2007-12-29 04:24:35 +05:30
|
|
|
int option_index = 0;
|
|
|
|
int c;
|
|
|
|
static struct option long_options[] = {
|
|
|
|
{"crypt-method", required_argument, NULL, 'c'},
|
|
|
|
{"encrypted", no_argument, NULL, 'e'},
|
|
|
|
{"help", no_argument, NULL, 'h'},
|
|
|
|
{"md5", no_argument, NULL, 'm'},
|
* 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
|
|
|
#ifdef USE_SHA_CRYPT
|
2007-12-29 04:24:35 +05:30
|
|
|
{"sha-rounds", required_argument, NULL, 's'},
|
2007-11-24 05:46:41 +05:30
|
|
|
#endif
|
2007-12-29 04:24:35 +05:30
|
|
|
{NULL, 0, NULL, '\0'}
|
|
|
|
};
|
2007-10-07 17:17:22 +05:30
|
|
|
|
2007-12-29 04:24:35 +05:30
|
|
|
while ((c = getopt_long (argc, argv,
|
* 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
|
|
|
#ifdef USE_SHA_CRYPT
|
2007-12-29 04:24:35 +05:30
|
|
|
"c:ehms:",
|
2007-11-24 05:46:41 +05:30
|
|
|
#else
|
2007-12-29 04:24:35 +05:30
|
|
|
"c:ehm",
|
2007-11-24 05:46:41 +05:30
|
|
|
#endif
|
2007-12-29 04:24:35 +05:30
|
|
|
long_options, &option_index)) != -1) {
|
|
|
|
switch (c) {
|
|
|
|
case 'c':
|
2008-06-10 02:26:03 +05:30
|
|
|
cflg = true;
|
2007-12-29 04:24:35 +05:30
|
|
|
crypt_method = optarg;
|
|
|
|
break;
|
|
|
|
case 'e':
|
2008-06-10 02:26:03 +05:30
|
|
|
eflg = true;
|
2007-12-29 04:24:35 +05:30
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
usage ();
|
|
|
|
break;
|
|
|
|
case 'm':
|
2008-06-10 02:26:03 +05:30
|
|
|
md5flg = true;
|
2007-12-29 04:24:35 +05:30
|
|
|
break;
|
* 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
|
|
|
#ifdef USE_SHA_CRYPT
|
2007-12-29 04:24:35 +05:30
|
|
|
case 's':
|
2008-06-10 02:26:03 +05:30
|
|
|
sflg = true;
|
|
|
|
if (getlong(optarg, &sha_rounds) != 0) {
|
2007-12-29 04:24:35 +05:30
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: invalid numeric argument '%s'\n"),
|
|
|
|
Prog, optarg);
|
2007-10-07 17:17:22 +05:30
|
|
|
usage ();
|
|
|
|
}
|
2007-12-29 04:24:35 +05:30
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case 0:
|
|
|
|
/* long option */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage ();
|
|
|
|
break;
|
2007-10-07 17:17:22 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-20 15:03:52 +05:30
|
|
|
/* validate options */
|
2007-12-29 04:24:35 +05:30
|
|
|
check_flags ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* check_flags - check flags and parameters consistency
|
|
|
|
*
|
|
|
|
* It will not return if an error is encountered.
|
|
|
|
*/
|
|
|
|
static void check_flags (void)
|
|
|
|
{
|
2007-11-20 15:03:52 +05:30
|
|
|
if (sflg && !cflg) {
|
|
|
|
fprintf (stderr,
|
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
Added *_dbname() functions to retrieve the name of the databases.
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
*_name() functions renamed *setname().
* src/grpck.c, src/pwck.c: Likewise.
* lib/groupio.h, lib/pwio.h, lib/sgroupio.h, lib/shadowio.h: Added
the name of the arguments to the prototypes.
* src/chage, src/chfn.c, src/chgpasswd.c, src/chpasswd.c,
src/chsh.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c,
src/newusers.c, src/passwd.c, src/pwck.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c, src/usermod.c:
Harmonize the erro & syslog messages in case of failure of the
*_lock(), *_open(), *_close(), *_unlock(), *_remove() functions.
* src/chgpasswd.c, src/chpasswd.c, src/usermod.c: Avoid
capitalized messages.
* src/chpasswd.c, src/useradd.c, src/usermod.c: Harmonize messages
in case of inexistent entries.
* src/usermod.c: Harmonize messages in case of already existing
entries.
* src/newusers.c, src/useradd.c: Simplify PAM error handling.
* src/useradd.c: Report failures to unlock files (stderr, syslog,
and audit). But do not fail (continue).
* src/useradd.c (open_files): Do not report to syslog & audit
failures to lock or open the databases. This might be harmless,
and the logs were not already informed that a change was
requested.
* src/usermod.c: It's not the account which is unlocked, but its
password.
2008-08-06 21:27:31 +05:30
|
|
|
_("%s: %s flag is only allowed with the %s flag\n"),
|
2007-12-29 04:29:17 +05:30
|
|
|
Prog, "-s", "-c");
|
2007-11-20 15:03:52 +05:30
|
|
|
usage ();
|
|
|
|
}
|
2007-12-29 04:24:35 +05:30
|
|
|
|
2007-11-20 18:39:55 +05:30
|
|
|
if ((eflg && (md5flg || cflg)) ||
|
2007-11-21 01:30:16 +05:30
|
|
|
(md5flg && cflg)) {
|
2007-11-20 15:03:52 +05:30
|
|
|
fprintf (stderr,
|
2007-12-29 04:29:17 +05:30
|
|
|
_("%s: the -c, -e, and -m flags are exclusive\n"),
|
|
|
|
Prog);
|
2007-11-20 15:03:52 +05:30
|
|
|
usage ();
|
|
|
|
}
|
2007-12-29 04:24:35 +05:30
|
|
|
|
2007-11-20 15:03:52 +05:30
|
|
|
if (cflg) {
|
2008-08-10 04:55:49 +05:30
|
|
|
if ( (0 != strcmp (crypt_method, "DES"))
|
|
|
|
&& (0 != strcmp (crypt_method, "MD5"))
|
|
|
|
&& (0 != strcmp (crypt_method, "NONE"))
|
* 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
|
|
|
#ifdef USE_SHA_CRYPT
|
2008-08-10 04:55:49 +05:30
|
|
|
&& (0 != strcmp (crypt_method, "SHA256"))
|
|
|
|
&& (0 != strcmp (crypt_method, "SHA512"))
|
2007-11-20 15:03:52 +05:30
|
|
|
#endif
|
|
|
|
) {
|
|
|
|
fprintf (stderr,
|
2007-11-24 01:39:57 +05:30
|
|
|
_("%s: unsupported crypt method: %s\n"),
|
|
|
|
Prog, crypt_method);
|
2007-11-20 15:03:52 +05:30
|
|
|
usage ();
|
|
|
|
}
|
|
|
|
}
|
2007-12-29 04:24:35 +05:30
|
|
|
}
|
2007-11-20 15:03:52 +05:30
|
|
|
|
2007-12-29 04:24:35 +05:30
|
|
|
/*
|
|
|
|
* check_perms - check if the caller is allowed to add a group
|
|
|
|
*
|
2008-01-02 01:23:02 +05:30
|
|
|
* With PAM support, the setuid bit can be set on chgpasswd to allow
|
2007-12-29 04:24:35 +05:30
|
|
|
* non-root users to groups.
|
|
|
|
* Without PAM support, only users who can write in the group databases
|
|
|
|
* can add groups.
|
|
|
|
*
|
|
|
|
* It will not return if the user is not allowed.
|
|
|
|
*/
|
|
|
|
static void check_perms (void)
|
|
|
|
{
|
2007-10-07 17:17:22 +05:30
|
|
|
#ifdef USE_PAM
|
2007-12-29 04:24:35 +05:30
|
|
|
int retval = PAM_SUCCESS;
|
|
|
|
struct passwd *pampw;
|
2007-12-31 10:27:54 +05:30
|
|
|
|
2007-12-29 04:24:35 +05:30
|
|
|
pampw = getpwuid (getuid ()); /* local, no need for xgetpwuid */
|
2008-08-10 04:52:00 +05:30
|
|
|
if (NULL == pampw) {
|
2007-12-29 04:24:35 +05:30
|
|
|
retval = PAM_USER_UNKNOWN;
|
|
|
|
}
|
2007-10-07 17:17:22 +05:30
|
|
|
|
2008-08-10 04:52:00 +05:30
|
|
|
if (PAM_SUCCESS == retval) {
|
2007-12-29 04:24:35 +05:30
|
|
|
retval = pam_start ("chgpasswd", pampw->pw_name, &conv, &pamh);
|
2007-10-07 17:17:22 +05:30
|
|
|
}
|
|
|
|
|
2008-08-10 04:52:00 +05:30
|
|
|
if (PAM_SUCCESS == retval) {
|
2007-10-07 17:17:22 +05:30
|
|
|
retval = pam_authenticate (pamh, 0);
|
|
|
|
}
|
|
|
|
|
2008-08-10 04:52:00 +05:30
|
|
|
if (PAM_SUCCESS == retval) {
|
2007-10-07 17:17:22 +05:30
|
|
|
retval = pam_acct_mgmt (pamh, 0);
|
|
|
|
}
|
|
|
|
|
2008-08-10 04:52:00 +05:30
|
|
|
if (PAM_SUCCESS != retval) {
|
|
|
|
(void) pam_end (pamh, retval);
|
2007-10-07 17:17:22 +05:30
|
|
|
fprintf (stderr, _("%s: PAM authentication failed\n"), Prog);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
#endif /* USE_PAM */
|
2007-12-29 04:24:35 +05:30
|
|
|
}
|
2007-10-07 17:17:22 +05:30
|
|
|
|
2007-12-29 04:24:35 +05:30
|
|
|
/*
|
|
|
|
* open_files - lock and open the group databases
|
|
|
|
*/
|
|
|
|
static void open_files (void)
|
|
|
|
{
|
2007-10-07 17:17:22 +05:30
|
|
|
/*
|
2007-12-29 04:24:35 +05:30
|
|
|
* Lock the group file and open it for reading and writing. This will
|
|
|
|
* bring all of the entries into memory where they may be updated.
|
2007-10-07 17:17:22 +05:30
|
|
|
*/
|
2007-12-29 04:44:59 +05:30
|
|
|
if (gr_lock () == 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,
|
* 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
|
|
|
_("%s: cannot lock %s; try again later.\n"),
|
|
|
|
Prog, gr_dbname ());
|
2008-08-10 04:52:00 +05:30
|
|
|
fail_exit (1);
|
2007-10-07 17:17:22 +05:30
|
|
|
}
|
* src/chfn.c, src/chgpasswd.c, src/chpasswd.c, src/gpasswd.c,
src/groupadd.c, src/groupdel.c, src/groupmems.c, src/groupmod.c,
src/grpconv.c, src/grpunconv.c, src/newusers.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c: Harmonize the name
of the variables keeping the lock status, to match the shadow
library prefixes.
2008-08-22 07:52:34 +05:30
|
|
|
gr_locked = true;
|
2007-12-29 04:44:59 +05:30
|
|
|
if (gr_open (O_RDWR) == 0) {
|
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
Added *_dbname() functions to retrieve the name of the databases.
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
*_name() functions renamed *setname().
* src/grpck.c, src/pwck.c: Likewise.
* lib/groupio.h, lib/pwio.h, lib/sgroupio.h, lib/shadowio.h: Added
the name of the arguments to the prototypes.
* src/chage, src/chfn.c, src/chgpasswd.c, src/chpasswd.c,
src/chsh.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c,
src/newusers.c, src/passwd.c, src/pwck.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c, src/usermod.c:
Harmonize the erro & syslog messages in case of failure of the
*_lock(), *_open(), *_close(), *_unlock(), *_remove() functions.
* src/chgpasswd.c, src/chpasswd.c, src/usermod.c: Avoid
capitalized messages.
* src/chpasswd.c, src/useradd.c, src/usermod.c: Harmonize messages
in case of inexistent entries.
* src/usermod.c: Harmonize messages in case of already existing
entries.
* src/newusers.c, src/useradd.c: Simplify PAM error handling.
* src/useradd.c: Report failures to unlock files (stderr, syslog,
and audit). But do not fail (continue).
* src/useradd.c (open_files): Do not report to syslog & audit
failures to lock or open the databases. This might be harmless,
and the logs were not already informed that a change was
requested.
* src/usermod.c: It's not the account which is unlocked, but its
password.
2008-08-06 21:27:31 +05:30
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: cannot open %s\n"), Prog, gr_dbname ());
|
2008-08-10 04:52:00 +05:30
|
|
|
fail_exit (1);
|
2007-10-07 17:17:22 +05:30
|
|
|
}
|
2007-12-29 04:24:35 +05:30
|
|
|
|
2007-10-07 17:17:33 +05:30
|
|
|
#ifdef SHADOWGRP
|
2007-12-29 04:24:35 +05:30
|
|
|
/* Do the same for the shadowed database, if it exist */
|
2007-10-07 17:17:33 +05:30
|
|
|
if (is_shadow_grp) {
|
2007-12-29 04:44:59 +05:30
|
|
|
if (sgr_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"),
|
* 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
|
|
|
Prog, sgr_dbname ());
|
2008-08-10 04:52:00 +05:30
|
|
|
fail_exit (1);
|
2007-10-07 17:17:22 +05:30
|
|
|
}
|
* src/chfn.c, src/chgpasswd.c, src/chpasswd.c, src/gpasswd.c,
src/groupadd.c, src/groupdel.c, src/groupmems.c, src/groupmod.c,
src/grpconv.c, src/grpunconv.c, src/newusers.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c: Harmonize the name
of the variables keeping the lock status, to match the shadow
library prefixes.
2008-08-22 07:52:34 +05:30
|
|
|
sgr_locked = true;
|
2007-12-29 04:44:59 +05:30
|
|
|
if (sgr_open (O_RDWR) == 0) {
|
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
Added *_dbname() functions to retrieve the name of the databases.
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
*_name() functions renamed *setname().
* src/grpck.c, src/pwck.c: Likewise.
* lib/groupio.h, lib/pwio.h, lib/sgroupio.h, lib/shadowio.h: Added
the name of the arguments to the prototypes.
* src/chage, src/chfn.c, src/chgpasswd.c, src/chpasswd.c,
src/chsh.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c,
src/newusers.c, src/passwd.c, src/pwck.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c, src/usermod.c:
Harmonize the erro & syslog messages in case of failure of the
*_lock(), *_open(), *_close(), *_unlock(), *_remove() functions.
* src/chgpasswd.c, src/chpasswd.c, src/usermod.c: Avoid
capitalized messages.
* src/chpasswd.c, src/useradd.c, src/usermod.c: Harmonize messages
in case of inexistent entries.
* src/usermod.c: Harmonize messages in case of already existing
entries.
* src/newusers.c, src/useradd.c: Simplify PAM error handling.
* src/useradd.c: Report failures to unlock files (stderr, syslog,
and audit). But do not fail (continue).
* src/useradd.c (open_files): Do not report to syslog & audit
failures to lock or open the databases. This might be harmless,
and the logs were not already informed that a change was
requested.
* src/usermod.c: It's not the account which is unlocked, but its
password.
2008-08-06 21:27:31 +05:30
|
|
|
fprintf (stderr, _("%s: cannot open %s\n"),
|
|
|
|
Prog, sgr_dbname ());
|
2008-08-10 04:52:00 +05:30
|
|
|
fail_exit (1);
|
2007-10-07 17:17:22 +05:30
|
|
|
}
|
|
|
|
}
|
2007-10-07 17:17:33 +05:30
|
|
|
#endif
|
2007-12-29 04:24:35 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* close_files - close and unlock the group databases
|
|
|
|
*/
|
|
|
|
static void close_files (void)
|
|
|
|
{
|
|
|
|
#ifdef SHADOWGRP
|
|
|
|
if (is_shadow_grp) {
|
2007-12-29 04:44:59 +05:30
|
|
|
if (sgr_close () == 0) {
|
2007-12-29 04:24:35 +05:30
|
|
|
fprintf (stderr,
|
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
Added *_dbname() functions to retrieve the name of the databases.
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
*_name() functions renamed *setname().
* src/grpck.c, src/pwck.c: Likewise.
* lib/groupio.h, lib/pwio.h, lib/sgroupio.h, lib/shadowio.h: Added
the name of the arguments to the prototypes.
* src/chage, src/chfn.c, src/chgpasswd.c, src/chpasswd.c,
src/chsh.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c,
src/newusers.c, src/passwd.c, src/pwck.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c, src/usermod.c:
Harmonize the erro & syslog messages in case of failure of the
*_lock(), *_open(), *_close(), *_unlock(), *_remove() functions.
* src/chgpasswd.c, src/chpasswd.c, src/usermod.c: Avoid
capitalized messages.
* src/chpasswd.c, src/useradd.c, src/usermod.c: Harmonize messages
in case of inexistent entries.
* src/usermod.c: Harmonize messages in case of already existing
entries.
* src/newusers.c, src/useradd.c: Simplify PAM error handling.
* src/useradd.c: Report failures to unlock files (stderr, syslog,
and audit). But do not fail (continue).
* src/useradd.c (open_files): Do not report to syslog & audit
failures to lock or open the databases. This might be harmless,
and the logs were not already informed that a change was
requested.
* src/usermod.c: It's not the account which is unlocked, but its
password.
2008-08-06 21:27:31 +05:30
|
|
|
_("%s: failure while writing changes to %s\n"),
|
|
|
|
Prog, sgr_dbname ());
|
2008-08-10 04:52:00 +05:30
|
|
|
SYSLOG ((LOG_ERR, "failure while writing changes to %s", sgr_dbname ()));
|
|
|
|
fail_exit (1);
|
2007-12-29 04:24:35 +05:30
|
|
|
}
|
2008-08-10 04:52:00 +05:30
|
|
|
if (sgr_unlock () == 0) {
|
|
|
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname ());
|
|
|
|
SYSLOG ((LOG_ERR, "failed to unlock %s", sgr_dbname ()));
|
|
|
|
/* continue */
|
|
|
|
}
|
* src/chfn.c, src/chgpasswd.c, src/chpasswd.c, src/gpasswd.c,
src/groupadd.c, src/groupdel.c, src/groupmems.c, src/groupmod.c,
src/grpconv.c, src/grpunconv.c, src/newusers.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c: Harmonize the name
of the variables keeping the lock status, to match the shadow
library prefixes.
2008-08-22 07:52:34 +05:30
|
|
|
sgr_locked = false;
|
2007-12-29 04:24:35 +05:30
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-12-29 04:44:59 +05:30
|
|
|
if (gr_close () == 0) {
|
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
Added *_dbname() functions to retrieve the name of the databases.
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
*_name() functions renamed *setname().
* src/grpck.c, src/pwck.c: Likewise.
* lib/groupio.h, lib/pwio.h, lib/sgroupio.h, lib/shadowio.h: Added
the name of the arguments to the prototypes.
* src/chage, src/chfn.c, src/chgpasswd.c, src/chpasswd.c,
src/chsh.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c,
src/newusers.c, src/passwd.c, src/pwck.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c, src/usermod.c:
Harmonize the erro & syslog messages in case of failure of the
*_lock(), *_open(), *_close(), *_unlock(), *_remove() functions.
* src/chgpasswd.c, src/chpasswd.c, src/usermod.c: Avoid
capitalized messages.
* src/chpasswd.c, src/useradd.c, src/usermod.c: Harmonize messages
in case of inexistent entries.
* src/usermod.c: Harmonize messages in case of already existing
entries.
* src/newusers.c, src/useradd.c: Simplify PAM error handling.
* src/useradd.c: Report failures to unlock files (stderr, syslog,
and audit). But do not fail (continue).
* src/useradd.c (open_files): Do not report to syslog & audit
failures to lock or open the databases. This might be harmless,
and the logs were not already informed that a change was
requested.
* src/usermod.c: It's not the account which is unlocked, but its
password.
2008-08-06 21:27:31 +05:30
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: failure while writing changes to %s\n"),
|
|
|
|
Prog, gr_dbname ());
|
2008-08-10 04:52:00 +05:30
|
|
|
SYSLOG ((LOG_ERR, "failure while writing changes to %s", gr_dbname ()));
|
|
|
|
fail_exit (1);
|
|
|
|
}
|
|
|
|
if (gr_unlock () == 0) {
|
|
|
|
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ());
|
|
|
|
SYSLOG ((LOG_ERR, "failed to unlock %s", gr_dbname ()));
|
|
|
|
/* continue */
|
2007-12-29 04:24:35 +05:30
|
|
|
}
|
* src/chfn.c, src/chgpasswd.c, src/chpasswd.c, src/gpasswd.c,
src/groupadd.c, src/groupdel.c, src/groupmems.c, src/groupmod.c,
src/grpconv.c, src/grpunconv.c, src/newusers.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c: Harmonize the name
of the variables keeping the lock status, to match the shadow
library prefixes.
2008-08-22 07:52:34 +05:30
|
|
|
gr_locked = false;
|
2007-12-29 04:24:35 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
int main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
char buf[BUFSIZ];
|
|
|
|
char *name;
|
|
|
|
char *newpwd;
|
|
|
|
char *cp;
|
|
|
|
|
|
|
|
#ifdef SHADOWGRP
|
|
|
|
const struct sgrp *sg;
|
|
|
|
struct sgrp newsg;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
const struct group *gr;
|
|
|
|
struct group newgr;
|
|
|
|
int errors = 0;
|
|
|
|
int line = 0;
|
|
|
|
int ok;
|
|
|
|
|
|
|
|
Prog = Basename (argv[0]);
|
|
|
|
|
2008-06-10 02:26:03 +05:30
|
|
|
(void) setlocale (LC_ALL, "");
|
|
|
|
(void) bindtextdomain (PACKAGE, LOCALEDIR);
|
|
|
|
(void) textdomain (PACKAGE);
|
2007-12-29 04:24:35 +05:30
|
|
|
|
2008-08-10 04:55:49 +05:30
|
|
|
process_flags (argc, argv);
|
2007-12-29 04:24:35 +05:30
|
|
|
|
2008-08-10 04:52:00 +05:30
|
|
|
OPENLOG ("chgpasswd");
|
|
|
|
|
2007-12-29 04:24:35 +05:30
|
|
|
check_perms ();
|
|
|
|
|
2008-01-26 23:11:20 +05:30
|
|
|
#ifdef SHADOWGRP
|
2007-12-29 04:24:35 +05:30
|
|
|
is_shadow_grp = sgr_file_present ();
|
2008-01-26 23:11:20 +05:30
|
|
|
#endif
|
2007-12-29 04:24:35 +05:30
|
|
|
|
|
|
|
open_files ();
|
2007-10-07 17:17:22 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Read each line, separating the group name from the password. The
|
2007-12-29 04:44:59 +05:30
|
|
|
* group entry for each group will be looked up in the appropriate
|
2007-10-07 17:17:22 +05:30
|
|
|
* file (gshadow or group) and the password changed.
|
|
|
|
*/
|
* libmisc/console.c, libmisc/hushed.c, libmisc/yesno.c,
libmisc/loginprompt.c, libmisc/ttytype.c, libmisc/tz.c,
src/login_nopam.c, src/chpasswd.c, src/chgpasswd.c, lib/port.c:
The size argument of fgets is an int, not a size_t.
* libmisc/loginprompt.c: Ignore the return value from signal()
when the signal handlers are restored.
* src/chpasswd.c: Cast the return value of time() to a long
integer.
* src/chpasswd.c: Use the SCALE macro instead of (24L * 3600L)
for the values to be set in /etc/shadow.
2008-06-13 23:41:09 +05:30
|
|
|
while (fgets (buf, (int) sizeof buf, stdin) != (char *) 0) {
|
2007-10-07 17:17:22 +05:30
|
|
|
line++;
|
2007-12-29 04:44:59 +05:30
|
|
|
cp = strrchr (buf, '\n');
|
|
|
|
if (NULL != cp) {
|
2007-10-07 17:17:22 +05:30
|
|
|
*cp = '\0';
|
|
|
|
} else {
|
|
|
|
fprintf (stderr, _("%s: line %d: line too long\n"),
|
2007-12-29 04:29:17 +05:30
|
|
|
Prog, line);
|
2007-10-07 17:17:22 +05:30
|
|
|
errors++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-12-29 04:44:59 +05:30
|
|
|
* The group's name is the first field. It is separated from
|
|
|
|
* the password with a ":" character which is replaced with a
|
2007-10-07 17:17:22 +05:30
|
|
|
* NUL to give the new password. The new password will then
|
|
|
|
* be encrypted in the normal fashion with a new salt
|
|
|
|
* generated, unless the '-e' is given, in which case it is
|
|
|
|
* assumed to already be encrypted.
|
|
|
|
*/
|
|
|
|
|
|
|
|
name = buf;
|
2007-12-29 04:44:59 +05:30
|
|
|
cp = strchr (name, ':');
|
|
|
|
if (NULL != cp) {
|
|
|
|
*cp = '\0';
|
|
|
|
cp++;
|
2007-10-07 17:17:22 +05:30
|
|
|
} else {
|
|
|
|
fprintf (stderr,
|
2007-12-29 04:29:17 +05:30
|
|
|
_("%s: line %d: missing new password\n"),
|
|
|
|
Prog, line);
|
2007-10-07 17:17:22 +05:30
|
|
|
errors++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
newpwd = cp;
|
2007-11-24 01:39:57 +05:30
|
|
|
if (!eflg &&
|
|
|
|
(NULL == crypt_method ||
|
|
|
|
0 != strcmp(crypt_method, "NONE"))) {
|
2007-11-20 15:03:52 +05:30
|
|
|
void *arg = NULL;
|
2007-12-29 04:44:59 +05:30
|
|
|
if (md5flg) {
|
2007-11-20 15:03:52 +05:30
|
|
|
crypt_method = "MD5";
|
2007-12-29 04:44:59 +05:30
|
|
|
} else if (crypt_method != NULL) {
|
|
|
|
if (sflg) {
|
2007-11-20 15:03:52 +05:30
|
|
|
arg = &sha_rounds;
|
2007-12-29 04:44:59 +05:30
|
|
|
}
|
|
|
|
} else {
|
2007-11-24 05:46:41 +05:30
|
|
|
crypt_method = NULL;
|
2007-12-29 04:44:59 +05:30
|
|
|
}
|
2007-11-20 15:03:52 +05:30
|
|
|
cp = pw_encrypt (newpwd,
|
|
|
|
crypt_make_salt(crypt_method, arg));
|
2007-10-07 17:17:22 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-12-29 04:44:59 +05:30
|
|
|
* Get the group file entry for this group. The group must
|
2007-10-07 17:17:22 +05:30
|
|
|
* already exist.
|
|
|
|
*/
|
|
|
|
gr = gr_locate (name);
|
2007-12-29 04:44:59 +05:30
|
|
|
if (NULL == gr) {
|
2007-10-07 17:17:22 +05:30
|
|
|
fprintf (stderr,
|
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
Added *_dbname() functions to retrieve the name of the databases.
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
*_name() functions renamed *setname().
* src/grpck.c, src/pwck.c: Likewise.
* lib/groupio.h, lib/pwio.h, lib/sgroupio.h, lib/shadowio.h: Added
the name of the arguments to the prototypes.
* src/chage, src/chfn.c, src/chgpasswd.c, src/chpasswd.c,
src/chsh.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c,
src/newusers.c, src/passwd.c, src/pwck.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c, src/usermod.c:
Harmonize the erro & syslog messages in case of failure of the
*_lock(), *_open(), *_close(), *_unlock(), *_remove() functions.
* src/chgpasswd.c, src/chpasswd.c, src/usermod.c: Avoid
capitalized messages.
* src/chpasswd.c, src/useradd.c, src/usermod.c: Harmonize messages
in case of inexistent entries.
* src/usermod.c: Harmonize messages in case of already existing
entries.
* src/newusers.c, src/useradd.c: Simplify PAM error handling.
* src/useradd.c: Report failures to unlock files (stderr, syslog,
and audit). But do not fail (continue).
* src/useradd.c (open_files): Do not report to syslog & audit
failures to lock or open the databases. This might be harmless,
and the logs were not already informed that a change was
requested.
* src/usermod.c: It's not the account which is unlocked, but its
password.
2008-08-06 21:27:31 +05:30
|
|
|
_("%s: line %d: group '%s' does not exist\n"), Prog,
|
2007-12-29 04:29:17 +05:30
|
|
|
line, name);
|
2007-10-07 17:17:22 +05:30
|
|
|
errors++;
|
|
|
|
continue;
|
|
|
|
}
|
2007-10-07 17:17:33 +05:30
|
|
|
#ifdef SHADOWGRP
|
2007-12-29 04:44:59 +05:30
|
|
|
if (is_shadow_grp) {
|
2007-11-21 02:29:42 +05:30
|
|
|
sg = sgr_locate (name);
|
2007-12-29 04:44:59 +05:30
|
|
|
} else {
|
2007-11-21 02:29:42 +05:30
|
|
|
sg = NULL;
|
2007-12-29 04:44:59 +05:30
|
|
|
}
|
2007-10-07 17:17:33 +05:30
|
|
|
#endif
|
2007-10-07 17:17:22 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* The freshly encrypted new password is merged into the
|
2007-12-29 04:44:59 +05:30
|
|
|
* group's entry.
|
2007-10-07 17:17:22 +05:30
|
|
|
*/
|
2007-10-07 17:17:33 +05:30
|
|
|
#ifdef SHADOWGRP
|
2007-12-29 04:44:59 +05:30
|
|
|
if (NULL != sg) {
|
2007-11-21 02:29:42 +05:30
|
|
|
newsg = *sg;
|
|
|
|
newsg.sg_passwd = cp;
|
|
|
|
} else
|
2007-10-07 17:17:33 +05:30
|
|
|
#endif
|
2007-11-21 02:29:42 +05:30
|
|
|
{
|
|
|
|
newgr = *gr;
|
|
|
|
newgr.gr_passwd = cp;
|
|
|
|
}
|
2007-10-07 17:17:22 +05:30
|
|
|
|
|
|
|
/*
|
2007-12-29 04:44:59 +05:30
|
|
|
* The updated group file entry is then put back and will
|
|
|
|
* be written to the group file later, after all the
|
2007-10-07 17:17:22 +05:30
|
|
|
* other entries have been updated as well.
|
|
|
|
*/
|
2007-10-07 17:17:33 +05:30
|
|
|
#ifdef SHADOWGRP
|
2007-12-29 04:44:59 +05:30
|
|
|
if (NULL != sg) {
|
* src/groupmems.c: Check the return value of gr_update().
* src/chage.c, src/chfn.c, src/chgpasswd.c, src/chpasswd.c,
src/chsh.c, src/gpasswd.c, src/groupadd.c, src/groupmems.c,
src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c,
src/passwd.c, src/pwck.c, src/pwconv.c, src/pwunconv.c,
src/useradd.c, src/userdel.c, src/usermod.c: Harmonize the error
message sent to stderr in case of *_update () failure.
* src/chage.c, src/chsh.c, src/groupadd.c, src/passwd.c: Do not
log to syslog when pw_update() or spw_update() fail.
* src/newusers.c: Do not log specific error message to stderr when
sgr_update() fails.
* src/pwconv.c: Remove duplicated definition of Prog.
2008-08-30 23:57:34 +05:30
|
|
|
if (sgr_update (&newsg) == 0) {
|
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: line %d: failed to prepare the new %s entry '%s'\n"),
|
|
|
|
Prog, line, sgr_dbname (), newsg.sg_name);
|
|
|
|
errors++;
|
|
|
|
continue;
|
|
|
|
}
|
2007-12-29 04:44:59 +05:30
|
|
|
} else
|
2007-10-07 17:17:33 +05:30
|
|
|
#endif
|
2007-12-29 04:44:59 +05:30
|
|
|
{
|
* src/groupmems.c: Check the return value of gr_update().
* src/chage.c, src/chfn.c, src/chgpasswd.c, src/chpasswd.c,
src/chsh.c, src/gpasswd.c, src/groupadd.c, src/groupmems.c,
src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c,
src/passwd.c, src/pwck.c, src/pwconv.c, src/pwunconv.c,
src/useradd.c, src/userdel.c, src/usermod.c: Harmonize the error
message sent to stderr in case of *_update () failure.
* src/chage.c, src/chsh.c, src/groupadd.c, src/passwd.c: Do not
log to syslog when pw_update() or spw_update() fail.
* src/newusers.c: Do not log specific error message to stderr when
sgr_update() fails.
* src/pwconv.c: Remove duplicated definition of Prog.
2008-08-30 23:57:34 +05:30
|
|
|
if (gr_update (&newgr) == 0) {
|
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: line %d: failed to prepare the new %s entry '%s'\n"),
|
|
|
|
Prog, line, gr_dbname (), newgr.gr_name);
|
|
|
|
errors++;
|
|
|
|
continue;
|
|
|
|
}
|
2007-10-07 17:17:22 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Any detected errors will cause the entire set of changes to be
|
2007-12-29 04:44:59 +05:30
|
|
|
* aborted. Unlocking the group file will cause all of the
|
2007-10-07 17:17:22 +05:30
|
|
|
* changes to be ignored. Otherwise the file is closed, causing the
|
|
|
|
* changes to be written out all at once, and then unlocked
|
|
|
|
* afterwards.
|
|
|
|
*/
|
2008-06-10 02:26:03 +05:30
|
|
|
if (0 != errors) {
|
2007-10-07 17:17:22 +05:30
|
|
|
fprintf (stderr,
|
2007-12-29 04:29:17 +05:30
|
|
|
_("%s: error detected, changes ignored\n"), Prog);
|
2008-08-10 04:52:00 +05:30
|
|
|
fail_exit (1);
|
2007-10-07 17:17:22 +05:30
|
|
|
}
|
|
|
|
|
2007-12-29 04:24:35 +05:30
|
|
|
close_files ();
|
2007-10-07 17:17:22 +05:30
|
|
|
|
2007-12-29 04:24:35 +05:30
|
|
|
nscd_flush_cache ("group");
|
2007-10-07 17:17:22 +05:30
|
|
|
|
|
|
|
#ifdef USE_PAM
|
2008-08-10 04:52:00 +05:30
|
|
|
(void) pam_end (pamh, PAM_SUCCESS);
|
2007-10-07 17:17:22 +05:30
|
|
|
#endif /* USE_PAM */
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
2007-12-29 04:29:17 +05:30
|
|
|
|