至少在我的Ubuntu中,“太相似”消息出来了 时间:“ ...超过一半的字符是不同的字符...。”(有关详细信息,请参见下文)。 感谢PAM的支持,正如@slhck答案中明确说明的那样。
对于不使用PAM的其他平台,在以下情况下会显示“过于相似”消息:“ ...超过一半的字符是不同的字符...。”(请参见下文以了解详细信息)
要自己进一步检查该语句,可以检查源代码。这是怎么回事。
passwd软件包中包含“ passwd”程序:
verzulli@iMac:~$ which passwd
/usr/bin/passwd
verzulli@iMac:~$ dpkg -S /usr/bin/passwd
passwd: /usr/bin/passwd
在处理开源技术时,我们可以不受限制地访问源代码。获得它很简单:
verzulli@iMac:/usr/local/src/passwd$ apt-get source passwd
之后,很容易找到相关的代码片段:
verzulli@iMac:/usr/local/src/passwd$ grep -i -r 'too similar' .
[...]
./shadow-4.1.5.1/NEWS:- new password is not "too similar" if it is long enough
./shadow-4.1.5.1/libmisc/obscure.c: msg = _("too similar");
快速检查一下“ obscure.c”就可以了(我只剪切并粘贴了相关的代码):
static const char *password_check (
const char *old,
const char *new,
const struct passwd *pwdp)
{
const char *msg = NULL;
char *oldmono, *newmono, *wrapped;
if (strcmp (new, old) == 0) {
return _("no change");
}
[...]
if (palindrome (oldmono, newmono)) {
msg = _("a palindrome");
} else if (strcmp (oldmono, newmono) == 0) {
msg = _("case changes only");
} else if (similar (oldmono, newmono)) {
msg = _("too similar");
} else if (simple (old, new)) {
msg = _("too simple");
} else if (strstr (wrapped, newmono) != NULL) {
msg = _("rotated");
} else {
}
[...]
return msg;
}
因此,现在,我们知道有一个“相似”功能,该功能基于旧的和新的检查两者是否相似。这是代码段:
/*
* more than half of the characters are different ones.
*/
static bool similar (const char *old, const char *new)
{
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
*/
if (strlen (new) >= 8) {
return false;
}
for (i = j = 0; ('\0' != new[i]) && ('\0' != old[i]); i++) {
if (strchr (new, old[i]) != NULL) {
j++;
}
}
if (i >= j * 2) {
return false;
}
return true;
}
我还没有审查过C代码。我限制了我对函数定义之前的注释的信任:-)
在“ obscure.c”文件中定义了PAM和NON-PAM感知平台之间的区别,其结构如下:
#include
#ifndef USE_PAM
[...lots of things, including all the above...]
#else /* !USE_PAM */
extern int errno; /* warning: ANSI C forbids an empty source file */
#endif /* !USE_PAM */