2
* Copyright 1989 - 1994, Julianne Frances Haugh
2
* Copyright (c) 1989 - 1994, Julianne Frances Haugh
3
* Copyright (c) 1996 - 1999, Marek Michałkiewicz
4
* Copyright (c) 2003 - 2005, Tomasz Kłoczko
5
* Copyright (c) 2007 - 2008, Nicolas François
3
6
* All rights reserved.
5
8
* Redistribution and use in source and binary forms, with or without
10
13
* 2. Redistributions in binary form must reproduce the above copyright
11
14
* notice, this list of conditions and the following disclaimer in the
12
15
* documentation and/or other materials provided with the distribution.
13
* 3. Neither the name of Julianne F. Haugh nor the names of its contributors
14
* may be used to endorse or promote products derived from this software
15
* without specific prior written permission.
16
* 3. The name of the copyright holders or contributors may not be used to
17
* endorse or promote products derived from this software without
18
* specific prior written permission.
17
* THIS SOFTWARE IS PROVIDED BY JULIE HAUGH AND CONTRIBUTORS ``AS IS'' AND
18
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
* ARE DISCLAIMED. IN NO EVENT SHALL JULIE HAUGH OR CONTRIBUTORS BE LIABLE
21
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
20
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
33
#include <config.h>
34
#ident "$Id: obscure.c 1668 2008-01-06 13:20:25Z nekral-guest $"
37
#ident "$Id: obscure.c 2352 2008-09-06 15:59:28Z nekral-guest $"
48
51
* can't be a palindrome - like `R A D A R' or `M A D A M'
50
static int palindrome (unused const char *old, const char *new)
53
static bool palindrome (unused const char *old, const char *new)
56
for (j = 0; j < i; j++)
57
if (new[i - j - 1] != new[j])
59
for (j = 0; j < i; j++) {
60
if (new[i - j - 1] != new[j]) {
64
69
* more than half of the characters are different ones.
67
static int similar (const char *old, const char *new)
72
static bool similar (const char *old, const char *new)
74
79
* the new password is long enough. Please feel free to suggest
75
80
* something better... --marekm
77
if (strlen (new) >= 8)
82
if (strlen (new) >= 8) {
80
for (i = j = 0; new[i] && old[i]; i++)
81
if (strchr (new, old[i]))
86
for (i = j = 0; ('\0' != new[i]) && ('\0' != old[i]); i++) {
87
if (strchr (new, old[i]) != NULL) {
94
103
static int simple (unused const char *old, const char *new)
103
for (i = 0; new[i]; i++) {
104
if (isdigit (new[i]))
106
else if (isupper (new[i]))
108
else if (islower (new[i]))
112
for (i = 0; '\0' != new[i]; i++) {
113
if (isdigit (new[i])) {
115
} else if (isupper (new[i])) {
117
} else if (islower (new[i])) {
166
183
strcpy (wrapped, oldmono);
167
184
strcat (wrapped, oldmono);
169
if (palindrome (oldmono, newmono))
186
if (palindrome (oldmono, newmono)) {
170
187
msg = _("a palindrome");
172
if (!msg && strcmp (oldmono, newmono) == 0)
188
} else if (strcmp (oldmono, newmono) == 0) {
173
189
msg = _("case changes only");
175
if (!msg && similar (oldmono, newmono))
190
} else if (similar (oldmono, newmono)) {
176
191
msg = _("too similar");
178
if (!msg && simple (old, new))
192
} else if (simple (old, new)) {
179
193
msg = _("too simple");
181
if (!msg && strstr (wrapped, newmono))
194
} else if (strstr (wrapped, newmono) != NULL) {
182
195
msg = _("rotated");
184
197
#ifdef HAVE_LIBCRACK
186
* Invoke Alec Muffett's cracklib routines.
199
* Invoke Alec Muffett's cracklib routines.
189
if (!msg && (dictpath = getdef_str ("CRACKLIB_DICTPATH")))
202
dictpath = getdef_str ("CRACKLIB_DICTPATH");
203
if (NULL != dictpath) {
190
204
#ifdef HAVE_LIBCRACK_PW
191
msg = FascistCheckPw (new, dictpath, pwdp);
205
msg = FascistCheckPw (new, dictpath, pwdp);
193
msg = FascistCheck (new, dictpath);
207
msg = FascistCheck (new, dictpath);
196
212
strzero (newmono);
197
213
strzero (oldmono);
198
214
strzero (wrapped);
207
static const char *obscure_msg (const char *old, const char *new,
223
static const char *obscure_msg (const char *old, const char *new,
208
224
const struct passwd *pwdp)
210
226
int maxlen, oldlen, newlen;
215
231
oldlen = strlen (old);
216
232
newlen = strlen (new);
218
if (newlen < getdef_num ("PASS_MIN_LEN", 0))
234
if (newlen < getdef_num ("PASS_MIN_LEN", 0)) {
219
235
return _("too short");
222
239
* Remaining checks are optional.
224
if (!getdef_bool ("OBSCURE_CHECKS_ENAB"))
241
if (!getdef_bool ("OBSCURE_CHECKS_ENAB")) {
227
245
msg = password_check (old, new, pwdp);
231
if ((result = getdef_str ("ENCRYPT_METHOD")) == NULL) {
250
result = getdef_str ("ENCRYPT_METHOD");
251
if (NULL == result) {
232
252
/* The traditional crypt() truncates passwords to 8 chars. It is
233
253
possible to circumvent the above checks by choosing an easy
234
254
8-char password and adding some random characters to it...
235
255
Example: "password$%^&*123". So check it again, this time
236
256
truncated to the maximum length. Idea from npasswd. --marekm */
238
if (getdef_bool ("MD5_CRYPT_ENAB"))
258
if (getdef_bool ("MD5_CRYPT_ENAB")) {
243
if ( !strcmp (result, "MD5")
264
if ( (strcmp (result, "MD5") == 0)
244
265
#ifdef USE_SHA_CRYPT
245
|| !strcmp (result, "SHA256")
246
|| !strcmp (result, "SHA512")
266
|| (strcmp (result, "SHA256") == 0)
267
|| (strcmp (result, "SHA512") == 0)
252
274
maxlen = getdef_num ("PASS_MAX_LEN", 8);
253
if (oldlen <= maxlen && newlen <= maxlen)
275
if ( (oldlen <= maxlen)
276
&& (newlen <= maxlen)) {
256
280
new1 = xstrdup (new);
257
281
old1 = xstrdup (old);
282
if (newlen > maxlen) {
259
283
new1[maxlen] = '\0';
285
if (oldlen > maxlen) {
261
286
old1[maxlen] = '\0';
263
289
msg = password_check (old1, new1, pwdp);