2007-10-07 17:14:02 +05:30
|
|
|
/*
|
2008-04-27 06:10:09 +05:30
|
|
|
* Copyright (c) 1989 - 1994, Julianne Frances Haugh
|
|
|
|
* Copyright (c) 1996 - 1999, Marek Michałkiewicz
|
|
|
|
* Copyright (c) 2003 - 2005, 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-10-07 17:16:07 +05:30
|
|
|
#ifndef USE_PAM
|
|
|
|
|
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
|
|
|
|
|
|
|
/*
|
|
|
|
* This version of obscure.c contains modifications to support "cracklib"
|
|
|
|
* by Alec Muffet (alec.muffett@uk.sun.com). You must obtain the Cracklib
|
|
|
|
* library source code for this function to operate.
|
|
|
|
*/
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "prototypes.h"
|
|
|
|
#include "defines.h"
|
|
|
|
#include "getdef.h"
|
|
|
|
/*
|
|
|
|
* can't be a palindrome - like `R A D A R' or `M A D A M'
|
|
|
|
*/
|
2008-08-31 22:58:49 +05:30
|
|
|
static bool palindrome (unused const char *old, const char *new)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2009-04-25 04:34:27 +05:30
|
|
|
size_t i, j;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
i = strlen (new);
|
|
|
|
|
2008-08-31 22:58:49 +05:30
|
|
|
for (j = 0; j < i; j++) {
|
|
|
|
if (new[i - j - 1] != new[j]) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-08-31 22:58:49 +05:30
|
|
|
return true;
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* more than half of the characters are different ones.
|
|
|
|
*/
|
|
|
|
|
2008-08-31 22:58:49 +05:30
|
|
|
static bool similar (const char *old, const char *new)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX - sometimes this fails when changing from a simple password
|
|
|
|
* to a really long one (MD5). For now, I just return success if
|
|
|
|
* the new password is long enough. Please feel free to suggest
|
|
|
|
* something better... --marekm
|
|
|
|
*/
|
2008-08-31 22:58:49 +05:30
|
|
|
if (strlen (new) >= 8) {
|
|
|
|
return false;
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-08-31 22:58:49 +05:30
|
|
|
for (i = j = 0; ('\0' != new[i]) && ('\0' != old[i]); i++) {
|
|
|
|
if (strchr (new, old[i]) != NULL) {
|
2007-10-07 17:14:02 +05:30
|
|
|
j++;
|
2008-08-31 22:58:49 +05:30
|
|
|
}
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-08-31 22:58:49 +05:30
|
|
|
if (i >= j * 2) {
|
|
|
|
return false;
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-08-31 22:58:49 +05:30
|
|
|
return true;
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* a nice mix of characters.
|
|
|
|
*/
|
|
|
|
|
2008-01-06 18:50:25 +05:30
|
|
|
static int simple (unused const char *old, const char *new)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2008-08-31 22:58:49 +05:30
|
|
|
bool digits = false;
|
|
|
|
bool uppers = false;
|
|
|
|
bool lowers = false;
|
|
|
|
bool others = false;
|
2007-10-07 17:15:23 +05:30
|
|
|
int size;
|
|
|
|
int i;
|
|
|
|
|
2008-09-06 21:29:28 +05:30
|
|
|
for (i = 0; '\0' != new[i]; i++) {
|
2008-08-31 22:58:49 +05:30
|
|
|
if (isdigit (new[i])) {
|
|
|
|
digits = true;
|
|
|
|
} else if (isupper (new[i])) {
|
|
|
|
uppers = true;
|
|
|
|
} else if (islower (new[i])) {
|
|
|
|
lowers = true;
|
|
|
|
} else {
|
|
|
|
others = true;
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The scam is this - a password of only one character type
|
|
|
|
* must be 8 letters long. Two types, 7, and so on.
|
|
|
|
*/
|
|
|
|
|
|
|
|
size = 9;
|
2008-08-31 22:58:49 +05:30
|
|
|
if (digits) {
|
2007-10-07 17:15:23 +05:30
|
|
|
size--;
|
2008-08-31 22:58:49 +05:30
|
|
|
}
|
|
|
|
if (uppers) {
|
2007-10-07 17:15:23 +05:30
|
|
|
size--;
|
2008-08-31 22:58:49 +05:30
|
|
|
}
|
|
|
|
if (lowers) {
|
2007-10-07 17:15:23 +05:30
|
|
|
size--;
|
2008-08-31 22:58:49 +05:30
|
|
|
}
|
|
|
|
if (others) {
|
2007-10-07 17:15:23 +05:30
|
|
|
size--;
|
2008-08-31 22:58:49 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-08-31 22:58:49 +05:30
|
|
|
if (size <= i) {
|
|
|
|
return false;
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-08-31 22:58:49 +05:30
|
|
|
return true;
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:15:23 +05:30
|
|
|
static char *str_lower (char *string)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
char *cp;
|
|
|
|
|
2008-09-06 21:29:28 +05:30
|
|
|
for (cp = string; '\0' != *cp; cp++) {
|
2007-10-07 17:15:23 +05:30
|
|
|
*cp = tolower (*cp);
|
2008-08-31 22:58:49 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
2007-10-07 17:15:23 +05:30
|
|
|
static const char *password_check (const char *old, const char *new,
|
|
|
|
const struct passwd *pwdp)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
const char *msg = NULL;
|
|
|
|
char *oldmono, *newmono, *wrapped;
|
2007-10-07 17:15:23 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef HAVE_LIBCRACK
|
|
|
|
char *dictpath;
|
2007-10-07 17:15:23 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef HAVE_LIBCRACK_PW
|
2007-10-07 17:15:23 +05:30
|
|
|
char *FascistCheckPw ();
|
2007-10-07 17:14:02 +05:30
|
|
|
#else
|
2007-10-07 17:15:23 +05:30
|
|
|
char *FascistCheck ();
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2008-08-31 22:58:49 +05:30
|
|
|
if (strcmp (new, old) == 0) {
|
2007-10-07 17:17:01 +05:30
|
|
|
return _("no change");
|
2008-08-31 22:58:49 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:15:23 +05:30
|
|
|
newmono = str_lower (xstrdup (new));
|
|
|
|
oldmono = str_lower (xstrdup (old));
|
|
|
|
wrapped = xmalloc (strlen (oldmono) * 2 + 1);
|
2007-10-07 17:14:02 +05:30
|
|
|
strcpy (wrapped, oldmono);
|
|
|
|
strcat (wrapped, oldmono);
|
|
|
|
|
2008-08-31 22:58:49 +05:30
|
|
|
if (palindrome (oldmono, newmono)) {
|
2007-10-07 17:17:01 +05:30
|
|
|
msg = _("a palindrome");
|
2008-08-31 22:58:49 +05:30
|
|
|
} else if (strcmp (oldmono, newmono) == 0) {
|
2007-10-07 17:17:01 +05:30
|
|
|
msg = _("case changes only");
|
2008-08-31 22:58:49 +05:30
|
|
|
} else if (similar (oldmono, newmono)) {
|
2007-10-07 17:17:01 +05:30
|
|
|
msg = _("too similar");
|
2008-08-31 22:58:49 +05:30
|
|
|
} else if (simple (old, new)) {
|
2007-10-07 17:17:01 +05:30
|
|
|
msg = _("too simple");
|
2008-08-31 22:58:49 +05:30
|
|
|
} else if (strstr (wrapped, newmono) != NULL) {
|
2007-10-07 17:17:01 +05:30
|
|
|
msg = _("rotated");
|
2008-08-31 22:58:49 +05:30
|
|
|
} else {
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef HAVE_LIBCRACK
|
2008-08-31 22:58:49 +05:30
|
|
|
/*
|
|
|
|
* Invoke Alec Muffett's cracklib routines.
|
|
|
|
*/
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-08-31 22:58:49 +05:30
|
|
|
dictpath = getdef_str ("CRACKLIB_DICTPATH");
|
|
|
|
if (NULL != dictpath) {
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef HAVE_LIBCRACK_PW
|
2008-08-31 22:58:49 +05:30
|
|
|
msg = FascistCheckPw (new, dictpath, pwdp);
|
2007-10-07 17:14:02 +05:30
|
|
|
#else
|
2008-08-31 22:58:49 +05:30
|
|
|
msg = FascistCheck (new, dictpath);
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
2008-08-31 22:58:49 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
2008-08-31 22:58:49 +05:30
|
|
|
}
|
2007-10-07 17:15:23 +05:30
|
|
|
strzero (newmono);
|
|
|
|
strzero (oldmono);
|
|
|
|
strzero (wrapped);
|
|
|
|
free (newmono);
|
|
|
|
free (oldmono);
|
|
|
|
free (wrapped);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
2008-08-31 22:58:49 +05:30
|
|
|
/*ARGSUSED*/
|
|
|
|
static const char *obscure_msg (const char *old, const char *new,
|
2007-10-07 17:15:23 +05:30
|
|
|
const struct passwd *pwdp)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2009-04-25 04:34:27 +05:30
|
|
|
size_t maxlen, oldlen, newlen;
|
2007-10-07 17:14:02 +05:30
|
|
|
char *new1, *old1;
|
|
|
|
const char *msg;
|
2007-11-20 03:44:19 +05:30
|
|
|
char *result;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:15:23 +05:30
|
|
|
oldlen = strlen (old);
|
|
|
|
newlen = strlen (new);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2009-04-25 04:34:27 +05:30
|
|
|
if (newlen < (size_t) getdef_num ("PASS_MIN_LEN", 0)) {
|
2007-10-07 17:17:01 +05:30
|
|
|
return _("too short");
|
2008-08-31 22:58:49 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Remaining checks are optional.
|
|
|
|
*/
|
2008-08-31 22:58:49 +05:30
|
|
|
if (!getdef_bool ("OBSCURE_CHECKS_ENAB")) {
|
2007-10-07 17:14:02 +05:30
|
|
|
return NULL;
|
2008-08-31 22:58:49 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:15:23 +05:30
|
|
|
msg = password_check (old, new, pwdp);
|
2008-08-31 22:58:49 +05:30
|
|
|
if (NULL != msg) {
|
2007-10-07 17:14:02 +05:30
|
|
|
return msg;
|
2008-08-31 22:58:49 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-08-31 22:58:49 +05:30
|
|
|
result = getdef_str ("ENCRYPT_METHOD");
|
|
|
|
if (NULL == result) {
|
2007-10-07 17:14:02 +05:30
|
|
|
/* The traditional crypt() truncates passwords to 8 chars. It is
|
|
|
|
possible to circumvent the above checks by choosing an easy
|
|
|
|
8-char password and adding some random characters to it...
|
|
|
|
Example: "password$%^&*123". So check it again, this time
|
|
|
|
truncated to the maximum length. Idea from npasswd. --marekm */
|
|
|
|
|
2008-08-31 22:58:49 +05:30
|
|
|
if (getdef_bool ("MD5_CRYPT_ENAB")) {
|
2007-11-20 03:44:19 +05:30
|
|
|
return NULL;
|
2008-08-31 22:58:49 +05:30
|
|
|
}
|
2007-11-20 03:44:19 +05:30
|
|
|
|
|
|
|
} else {
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-08-31 22:58:49 +05:30
|
|
|
if ( (strcmp (result, "MD5") == 0)
|
* 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-31 22:58:49 +05:30
|
|
|
|| (strcmp (result, "SHA256") == 0)
|
|
|
|
|| (strcmp (result, "SHA512") == 0)
|
* 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
|
|
|
#endif
|
2008-08-31 22:58:49 +05:30
|
|
|
) {
|
2007-11-20 03:44:19 +05:30
|
|
|
return NULL;
|
2008-08-31 22:58:49 +05:30
|
|
|
}
|
2007-11-20 03:44:19 +05:30
|
|
|
|
|
|
|
}
|
2009-04-25 04:34:27 +05:30
|
|
|
maxlen = (size_t) getdef_num ("PASS_MAX_LEN", 8);
|
2008-08-31 22:58:49 +05:30
|
|
|
if ( (oldlen <= maxlen)
|
|
|
|
&& (newlen <= maxlen)) {
|
2007-10-07 17:14:02 +05:30
|
|
|
return NULL;
|
2008-08-31 22:58:49 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:15:23 +05:30
|
|
|
new1 = xstrdup (new);
|
|
|
|
old1 = xstrdup (old);
|
2008-08-31 22:58:49 +05:30
|
|
|
if (newlen > maxlen) {
|
2007-10-07 17:14:02 +05:30
|
|
|
new1[maxlen] = '\0';
|
2008-08-31 22:58:49 +05:30
|
|
|
}
|
|
|
|
if (oldlen > maxlen) {
|
2007-10-07 17:14:02 +05:30
|
|
|
old1[maxlen] = '\0';
|
2008-08-31 22:58:49 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:15:23 +05:30
|
|
|
msg = password_check (old1, new1, pwdp);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:15:23 +05:30
|
|
|
memzero (new1, newlen);
|
|
|
|
memzero (old1, oldlen);
|
|
|
|
free (new1);
|
|
|
|
free (old1);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Obscure - see if password is obscure enough.
|
|
|
|
*
|
|
|
|
* The programmer is encouraged to add as much complexity to this
|
|
|
|
* routine as desired. Included are some of my favorite ways to
|
|
|
|
* check passwords.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:15:23 +05:30
|
|
|
int obscure (const char *old, const char *new, const struct passwd *pwdp)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:15:23 +05:30
|
|
|
const char *msg = obscure_msg (old, new, pwdp);
|
|
|
|
|
2008-08-31 22:58:49 +05:30
|
|
|
if (NULL != msg) {
|
2007-10-07 17:15:23 +05:30
|
|
|
printf (_("Bad password: %s. "), msg);
|
2007-10-07 17:14:02 +05:30
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2007-10-07 17:16:07 +05:30
|
|
|
|
2008-01-01 19:48:55 +05:30
|
|
|
#else /* !USE_PAM */
|
|
|
|
extern int errno; /* warning: ANSI C forbids an empty source file */
|
2007-10-07 17:16:07 +05:30
|
|
|
#endif /* !USE_PAM */
|