2007-10-07 17:14:02 +05:30
|
|
|
/*
|
2021-12-05 21:05:27 +05:30
|
|
|
* SPDX-FileCopyrightText: 1989 - 1994, Julianne Frances Haugh
|
|
|
|
* SPDX-FileCopyrightText: 1996 - 1999, Marek Michałkiewicz
|
|
|
|
* SPDX-FileCopyrightText: 2003 - 2005, Tomasz Kłoczko
|
|
|
|
* SPDX-FileCopyrightText: 2007 - 2010, Nicolas François
|
2007-10-07 17:14:02 +05:30
|
|
|
*
|
2021-12-05 21:05:27 +05:30
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
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.
|
|
|
|
*/
|
|
|
|
|
* libmisc/limits.c: Avoid implicit conversion of integer to
boolean.
* libmisc/basename.c: Avoid implicit conversion of pointer to
boolean.
* libmisc/basename.c, lib/prototypes.h (Basename): Return a
constant string.
* libmisc/basename.c, libmisc/obscure.c, lib/prototypes.h,
libmisc/xmalloc.c, libmisc/getdate.h, libmisc/system.c,
libmisc/getgr_nam_gid.c, libmisc/failure.c, libmisc/valid.c: Add
splint annotations.
* libmisc/chowndir.c: Avoid memory leak.
* libmisc/chowndir.c: Do not check *printf/*puts return value.
* libmisc/chowntty.c: Avoid implicit conversion between integer
types.
* libmisc/obscure.c: Return a bool when possible instead of int.
* libmisc/shell.c: Do not check *printf/*puts return value.
* libmisc/shell.c: Do not check execle return value.
* libmisc/setupenv.c: Avoid implicit conversion between integer
types.
* libmisc/xmalloc.c: size should not be zero to avoid returning
NULL pointers.
* libmisc/hushed.c: Do not check *printf/*puts return value.
* libmisc/system.c: Avoid implicit conversion of integer to
boolean. safe_system last argument is a boolean.
* libmisc/system.c: Check return value of dup2.
* libmisc/system.c: Do not check *printf/*puts return value.
* libmisc/system.c: Do not check execve return value.
* libmisc/salt.c: Do not check *printf/*puts return value.
* libmisc/loginprompt.c: Do not check gethostname return value.
* libmisc/find_new_gid.c, libmisc/find_new_uid.c: Do not check
gr_rewind/pw_rewind return value.
* libmisc/ttytype.c: Limit the number of parsed characters in the
sscanf format.
* libmisc/ttytype.c: Test if a type was really read.
* libmisc/sub.c: Do not check *printf/*puts return value.
* libmisc/sub.c: Avoid implicit conversion of integer to boolean.
* src/userdel.c: Fix typo in comment.
* src/userdel.c: Avoid implicit conversion of boolean to integer.
* src/userdel.c: safe_system last argument is a boolean.
* src/newusers.c: Avoid implicit conversion of boolean to integer.
* src/newusers.c: Avoid implicit conversion of integer to boolean.
* src/usermod.c: Add brackets.
* src/usermod.c: Avoid implicit conversion of characters or
integers to booleans.
* src/vipw.c: Avoid implicit conversion of integer to boolean.
* src/su.c: Avoid implicit conversion of integer to boolean.
* src/su.c: Add brackets.
* src/useradd.c: Avoid implicit conversion of characters or
integers to booleans.
2010-08-23 00:43:53 +05:30
|
|
|
static bool similar (/*@notnull@*/const char *old, /*@notnull@*/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.
|
|
|
|
*/
|
|
|
|
|
* libmisc/limits.c: Avoid implicit conversion of integer to
boolean.
* libmisc/basename.c: Avoid implicit conversion of pointer to
boolean.
* libmisc/basename.c, lib/prototypes.h (Basename): Return a
constant string.
* libmisc/basename.c, libmisc/obscure.c, lib/prototypes.h,
libmisc/xmalloc.c, libmisc/getdate.h, libmisc/system.c,
libmisc/getgr_nam_gid.c, libmisc/failure.c, libmisc/valid.c: Add
splint annotations.
* libmisc/chowndir.c: Avoid memory leak.
* libmisc/chowndir.c: Do not check *printf/*puts return value.
* libmisc/chowntty.c: Avoid implicit conversion between integer
types.
* libmisc/obscure.c: Return a bool when possible instead of int.
* libmisc/shell.c: Do not check *printf/*puts return value.
* libmisc/shell.c: Do not check execle return value.
* libmisc/setupenv.c: Avoid implicit conversion between integer
types.
* libmisc/xmalloc.c: size should not be zero to avoid returning
NULL pointers.
* libmisc/hushed.c: Do not check *printf/*puts return value.
* libmisc/system.c: Avoid implicit conversion of integer to
boolean. safe_system last argument is a boolean.
* libmisc/system.c: Check return value of dup2.
* libmisc/system.c: Do not check *printf/*puts return value.
* libmisc/system.c: Do not check execve return value.
* libmisc/salt.c: Do not check *printf/*puts return value.
* libmisc/loginprompt.c: Do not check gethostname return value.
* libmisc/find_new_gid.c, libmisc/find_new_uid.c: Do not check
gr_rewind/pw_rewind return value.
* libmisc/ttytype.c: Limit the number of parsed characters in the
sscanf format.
* libmisc/ttytype.c: Test if a type was really read.
* libmisc/sub.c: Do not check *printf/*puts return value.
* libmisc/sub.c: Avoid implicit conversion of integer to boolean.
* src/userdel.c: Fix typo in comment.
* src/userdel.c: Avoid implicit conversion of boolean to integer.
* src/userdel.c: safe_system last argument is a boolean.
* src/newusers.c: Avoid implicit conversion of boolean to integer.
* src/newusers.c: Avoid implicit conversion of integer to boolean.
* src/usermod.c: Add brackets.
* src/usermod.c: Avoid implicit conversion of characters or
integers to booleans.
* src/vipw.c: Avoid implicit conversion of integer to boolean.
* src/su.c: Avoid implicit conversion of integer to boolean.
* src/su.c: Add brackets.
* src/useradd.c: Avoid implicit conversion of characters or
integers to booleans.
2010-08-23 00:43:53 +05:30
|
|
|
static bool 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
|
|
|
}
|
|
|
|
|
* libmisc/limits.c: Avoid implicit conversion of integer to
boolean.
* libmisc/basename.c: Avoid implicit conversion of pointer to
boolean.
* libmisc/basename.c, lib/prototypes.h (Basename): Return a
constant string.
* libmisc/basename.c, libmisc/obscure.c, lib/prototypes.h,
libmisc/xmalloc.c, libmisc/getdate.h, libmisc/system.c,
libmisc/getgr_nam_gid.c, libmisc/failure.c, libmisc/valid.c: Add
splint annotations.
* libmisc/chowndir.c: Avoid memory leak.
* libmisc/chowndir.c: Do not check *printf/*puts return value.
* libmisc/chowntty.c: Avoid implicit conversion between integer
types.
* libmisc/obscure.c: Return a bool when possible instead of int.
* libmisc/shell.c: Do not check *printf/*puts return value.
* libmisc/shell.c: Do not check execle return value.
* libmisc/setupenv.c: Avoid implicit conversion between integer
types.
* libmisc/xmalloc.c: size should not be zero to avoid returning
NULL pointers.
* libmisc/hushed.c: Do not check *printf/*puts return value.
* libmisc/system.c: Avoid implicit conversion of integer to
boolean. safe_system last argument is a boolean.
* libmisc/system.c: Check return value of dup2.
* libmisc/system.c: Do not check *printf/*puts return value.
* libmisc/system.c: Do not check execve return value.
* libmisc/salt.c: Do not check *printf/*puts return value.
* libmisc/loginprompt.c: Do not check gethostname return value.
* libmisc/find_new_gid.c, libmisc/find_new_uid.c: Do not check
gr_rewind/pw_rewind return value.
* libmisc/ttytype.c: Limit the number of parsed characters in the
sscanf format.
* libmisc/ttytype.c: Test if a type was really read.
* libmisc/sub.c: Do not check *printf/*puts return value.
* libmisc/sub.c: Avoid implicit conversion of integer to boolean.
* src/userdel.c: Fix typo in comment.
* src/userdel.c: Avoid implicit conversion of boolean to integer.
* src/userdel.c: safe_system last argument is a boolean.
* src/newusers.c: Avoid implicit conversion of boolean to integer.
* src/newusers.c: Avoid implicit conversion of integer to boolean.
* src/usermod.c: Add brackets.
* src/usermod.c: Avoid implicit conversion of characters or
integers to booleans.
* src/vipw.c: Avoid implicit conversion of integer to boolean.
* src/su.c: Avoid implicit conversion of integer to boolean.
* src/su.c: Add brackets.
* src/useradd.c: Avoid implicit conversion of characters or
integers to booleans.
2010-08-23 00:43:53 +05:30
|
|
|
static char *str_lower (/*@returned@*/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;
|
|
|
|
}
|
|
|
|
|
* libmisc/limits.c: Avoid implicit conversion of integer to
boolean.
* libmisc/basename.c: Avoid implicit conversion of pointer to
boolean.
* libmisc/basename.c, lib/prototypes.h (Basename): Return a
constant string.
* libmisc/basename.c, libmisc/obscure.c, lib/prototypes.h,
libmisc/xmalloc.c, libmisc/getdate.h, libmisc/system.c,
libmisc/getgr_nam_gid.c, libmisc/failure.c, libmisc/valid.c: Add
splint annotations.
* libmisc/chowndir.c: Avoid memory leak.
* libmisc/chowndir.c: Do not check *printf/*puts return value.
* libmisc/chowntty.c: Avoid implicit conversion between integer
types.
* libmisc/obscure.c: Return a bool when possible instead of int.
* libmisc/shell.c: Do not check *printf/*puts return value.
* libmisc/shell.c: Do not check execle return value.
* libmisc/setupenv.c: Avoid implicit conversion between integer
types.
* libmisc/xmalloc.c: size should not be zero to avoid returning
NULL pointers.
* libmisc/hushed.c: Do not check *printf/*puts return value.
* libmisc/system.c: Avoid implicit conversion of integer to
boolean. safe_system last argument is a boolean.
* libmisc/system.c: Check return value of dup2.
* libmisc/system.c: Do not check *printf/*puts return value.
* libmisc/system.c: Do not check execve return value.
* libmisc/salt.c: Do not check *printf/*puts return value.
* libmisc/loginprompt.c: Do not check gethostname return value.
* libmisc/find_new_gid.c, libmisc/find_new_uid.c: Do not check
gr_rewind/pw_rewind return value.
* libmisc/ttytype.c: Limit the number of parsed characters in the
sscanf format.
* libmisc/ttytype.c: Test if a type was really read.
* libmisc/sub.c: Do not check *printf/*puts return value.
* libmisc/sub.c: Avoid implicit conversion of integer to boolean.
* src/userdel.c: Fix typo in comment.
* src/userdel.c: Avoid implicit conversion of boolean to integer.
* src/userdel.c: safe_system last argument is a boolean.
* src/newusers.c: Avoid implicit conversion of boolean to integer.
* src/newusers.c: Avoid implicit conversion of integer to boolean.
* src/usermod.c: Add brackets.
* src/usermod.c: Avoid implicit conversion of characters or
integers to booleans.
* src/vipw.c: Avoid implicit conversion of integer to boolean.
* src/su.c: Avoid implicit conversion of integer to boolean.
* src/su.c: Add brackets.
* src/useradd.c: Avoid implicit conversion of characters or
integers to booleans.
2010-08-23 00:43:53 +05:30
|
|
|
static /*@observer@*//*@null@*/const char *password_check (
|
|
|
|
/*@notnull@*/const char *old,
|
|
|
|
/*@notnull@*/const char *new,
|
|
|
|
/*@notnull@*/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;
|
|
|
|
}
|
|
|
|
|
* libmisc/limits.c: Avoid implicit conversion of integer to
boolean.
* libmisc/basename.c: Avoid implicit conversion of pointer to
boolean.
* libmisc/basename.c, lib/prototypes.h (Basename): Return a
constant string.
* libmisc/basename.c, libmisc/obscure.c, lib/prototypes.h,
libmisc/xmalloc.c, libmisc/getdate.h, libmisc/system.c,
libmisc/getgr_nam_gid.c, libmisc/failure.c, libmisc/valid.c: Add
splint annotations.
* libmisc/chowndir.c: Avoid memory leak.
* libmisc/chowndir.c: Do not check *printf/*puts return value.
* libmisc/chowntty.c: Avoid implicit conversion between integer
types.
* libmisc/obscure.c: Return a bool when possible instead of int.
* libmisc/shell.c: Do not check *printf/*puts return value.
* libmisc/shell.c: Do not check execle return value.
* libmisc/setupenv.c: Avoid implicit conversion between integer
types.
* libmisc/xmalloc.c: size should not be zero to avoid returning
NULL pointers.
* libmisc/hushed.c: Do not check *printf/*puts return value.
* libmisc/system.c: Avoid implicit conversion of integer to
boolean. safe_system last argument is a boolean.
* libmisc/system.c: Check return value of dup2.
* libmisc/system.c: Do not check *printf/*puts return value.
* libmisc/system.c: Do not check execve return value.
* libmisc/salt.c: Do not check *printf/*puts return value.
* libmisc/loginprompt.c: Do not check gethostname return value.
* libmisc/find_new_gid.c, libmisc/find_new_uid.c: Do not check
gr_rewind/pw_rewind return value.
* libmisc/ttytype.c: Limit the number of parsed characters in the
sscanf format.
* libmisc/ttytype.c: Test if a type was really read.
* libmisc/sub.c: Do not check *printf/*puts return value.
* libmisc/sub.c: Avoid implicit conversion of integer to boolean.
* src/userdel.c: Fix typo in comment.
* src/userdel.c: Avoid implicit conversion of boolean to integer.
* src/userdel.c: safe_system last argument is a boolean.
* src/newusers.c: Avoid implicit conversion of boolean to integer.
* src/newusers.c: Avoid implicit conversion of integer to boolean.
* src/usermod.c: Add brackets.
* src/usermod.c: Avoid implicit conversion of characters or
integers to booleans.
* src/vipw.c: Avoid implicit conversion of integer to boolean.
* src/su.c: Avoid implicit conversion of integer to boolean.
* src/su.c: Add brackets.
* src/useradd.c: Avoid implicit conversion of characters or
integers to booleans.
2010-08-23 00:43:53 +05:30
|
|
|
static /*@observer@*//*@null@*/const char *obscure_msg (
|
|
|
|
/*@notnull@*/const char *old,
|
|
|
|
/*@notnull@*/const char *new,
|
|
|
|
/*@notnull@*/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;
|
2010-08-22 00:52:32 +05:30
|
|
|
const 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)
|
2019-09-17 00:24:56 +05:30
|
|
|
#endif
|
|
|
|
#ifdef USE_BCRYPT
|
|
|
|
|| (strcmp (result, "BCRYPT") == 0)
|
2020-12-28 01:39:25 +05:30
|
|
|
#endif
|
|
|
|
#ifdef USE_YESCRYPT
|
|
|
|
|| (strcmp (result, "YESCRYPT") == 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
|
|
|
|
2023-02-02 00:59:29 +05:30
|
|
|
freezero (new1, newlen);
|
|
|
|
freezero (old1, oldlen);
|
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.
|
|
|
|
*/
|
|
|
|
|
2010-08-22 18:19:07 +05:30
|
|
|
bool 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);
|
2010-08-22 18:19:07 +05:30
|
|
|
return false;
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2010-08-22 18:19:07 +05:30
|
|
|
return true;
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:16:07 +05:30
|
|
|
|
2008-01-01 19:48:55 +05:30
|
|
|
#else /* !USE_PAM */
|
2022-12-21 23:32:25 +05:30
|
|
|
extern int ISO_C_forbids_an_empty_translation_unit;
|
2007-10-07 17:16:07 +05:30
|
|
|
#endif /* !USE_PAM */
|