|
|
081b2d |
From a85f64d2c4fa2718748a205d4ae0ebab47513199 Mon Sep 17 00:00:00 2001
|
|
|
081b2d |
From: Mark Reynolds <mreynolds@redhat.com>
|
|
|
081b2d |
Date: Mon, 8 Jan 2018 11:34:02 -0500
|
|
|
081b2d |
Subject: [PATCH] Ticket 49524 - Password policy: minimum token length fails
|
|
|
081b2d |
when the token length is equal to attribute length
|
|
|
081b2d |
|
|
|
081b2d |
Bug Description: The token checking breaks when the password is the
|
|
|
081b2d |
exact value of the entry attribute.
|
|
|
081b2d |
|
|
|
081b2d |
Fix Description: Remove the "equal" part of the string comparisons.
|
|
|
081b2d |
|
|
|
081b2d |
https://pagure.io/389-ds-base/issue/49524
|
|
|
081b2d |
|
|
|
081b2d |
Reviewed by: firstyear & spichugi(Thanks!!)
|
|
|
081b2d |
|
|
|
081b2d |
(cherry picked from commit 790be09fc434d394239bf2486d01f212b36cf0e3)
|
|
|
081b2d |
---
|
|
|
081b2d |
.../tests/suites/password/pwdPolicy_token_test.py | 75 ++++++++++++++++++++++
|
|
|
081b2d |
ldap/servers/slapd/pw.c | 2 +-
|
|
|
081b2d |
ldap/servers/slapd/utf8.c | 2 +-
|
|
|
081b2d |
3 files changed, 77 insertions(+), 2 deletions(-)
|
|
|
081b2d |
create mode 100644 dirsrvtests/tests/suites/password/pwdPolicy_token_test.py
|
|
|
081b2d |
|
|
|
081b2d |
diff --git a/dirsrvtests/tests/suites/password/pwdPolicy_token_test.py b/dirsrvtests/tests/suites/password/pwdPolicy_token_test.py
|
|
|
081b2d |
new file mode 100644
|
|
|
081b2d |
index 000000000..7a4de9c85
|
|
|
081b2d |
--- /dev/null
|
|
|
081b2d |
+++ b/dirsrvtests/tests/suites/password/pwdPolicy_token_test.py
|
|
|
081b2d |
@@ -0,0 +1,75 @@
|
|
|
081b2d |
+import logging
|
|
|
081b2d |
+import pytest
|
|
|
081b2d |
+import os
|
|
|
081b2d |
+import time
|
|
|
081b2d |
+import ldap
|
|
|
081b2d |
+from lib389._constants import *
|
|
|
081b2d |
+from lib389.idm.user import UserAccounts
|
|
|
081b2d |
+from lib389.topologies import topology_st as topo
|
|
|
081b2d |
+
|
|
|
081b2d |
+DEBUGGING = os.getenv("DEBUGGING", default=False)
|
|
|
081b2d |
+if DEBUGGING:
|
|
|
081b2d |
+ logging.getLogger(__name__).setLevel(logging.DEBUG)
|
|
|
081b2d |
+else:
|
|
|
081b2d |
+ logging.getLogger(__name__).setLevel(logging.INFO)
|
|
|
081b2d |
+log = logging.getLogger(__name__)
|
|
|
081b2d |
+
|
|
|
081b2d |
+USER_DN = 'uid=Test_user1,ou=People,dc=example,dc=com'
|
|
|
081b2d |
+TOKEN = 'test_user1'
|
|
|
081b2d |
+
|
|
|
081b2d |
+user_properties = {
|
|
|
081b2d |
+ 'uid': 'Test_user1',
|
|
|
081b2d |
+ 'cn': 'test_user1',
|
|
|
081b2d |
+ 'sn': 'test_user1',
|
|
|
081b2d |
+ 'uidNumber': '1001',
|
|
|
081b2d |
+ 'gidNumber': '2001',
|
|
|
081b2d |
+ 'userpassword': PASSWORD,
|
|
|
081b2d |
+ 'description': 'userdesc',
|
|
|
081b2d |
+ 'homeDirectory': '/home/{}'.format('test_user')}
|
|
|
081b2d |
+
|
|
|
081b2d |
+
|
|
|
081b2d |
+def pwd_setup(topo):
|
|
|
081b2d |
+ topo.standalone.config.replace_many(('passwordCheckSyntax', 'on'),
|
|
|
081b2d |
+ ('passwordMinLength', '4'),
|
|
|
081b2d |
+ ('passwordMinCategories', '1'))
|
|
|
081b2d |
+ users = UserAccounts(topo.standalone, DEFAULT_SUFFIX)
|
|
|
081b2d |
+ return users.create(properties=user_properties)
|
|
|
081b2d |
+
|
|
|
081b2d |
+
|
|
|
081b2d |
+def test_token_lengths(topo):
|
|
|
081b2d |
+ """Test that password token length is enforced for various lengths including
|
|
|
081b2d |
+ the same length as the attribute being checked by the policy.
|
|
|
081b2d |
+
|
|
|
081b2d |
+ :id: dae9d916-2a03-4707-b454-9e901d295b13
|
|
|
081b2d |
+ :setup: Standalone instance
|
|
|
081b2d |
+ :steps:
|
|
|
081b2d |
+ 1. Test token length rejects password of the same length as rdn value
|
|
|
081b2d |
+ :expectedresults:
|
|
|
081b2d |
+ 1. Passwords are rejected
|
|
|
081b2d |
+ """
|
|
|
081b2d |
+ user = pwd_setup(topo)
|
|
|
081b2d |
+ for length in ['4', '6', '10']:
|
|
|
081b2d |
+ topo.standalone.simple_bind_s(DN_DM, PASSWORD)
|
|
|
081b2d |
+ topo.standalone.config.set('passwordMinTokenLength', length)
|
|
|
081b2d |
+ topo.standalone.simple_bind_s(USER_DN, PASSWORD)
|
|
|
081b2d |
+ time.sleep(1)
|
|
|
081b2d |
+
|
|
|
081b2d |
+ try:
|
|
|
081b2d |
+ passwd = TOKEN[:int(length)]
|
|
|
081b2d |
+ log.info("Testing password len {} token ({})".format(length, passwd))
|
|
|
081b2d |
+ user.replace('userpassword', passwd)
|
|
|
081b2d |
+ log.fatal('Password incorrectly allowed!')
|
|
|
081b2d |
+ assert False
|
|
|
081b2d |
+ except ldap.CONSTRAINT_VIOLATION as e:
|
|
|
081b2d |
+ log.info('Password correctly rejected: ' + str(e))
|
|
|
081b2d |
+ except ldap.LDAPError as e:
|
|
|
081b2d |
+ log.fatal('Unexpected failure ' + str(e))
|
|
|
081b2d |
+ assert False
|
|
|
081b2d |
+
|
|
|
081b2d |
+
|
|
|
081b2d |
+if __name__ == '__main__':
|
|
|
081b2d |
+ # Run isolated
|
|
|
081b2d |
+ # -s for DEBUG mode
|
|
|
081b2d |
+ CURRENT_FILE = os.path.realpath(__file__)
|
|
|
081b2d |
+ pytest.main("-s %s" % CURRENT_FILE)
|
|
|
081b2d |
+
|
|
|
081b2d |
diff --git a/ldap/servers/slapd/pw.c b/ldap/servers/slapd/pw.c
|
|
|
081b2d |
index e625962e8..0cf795b41 100644
|
|
|
081b2d |
--- a/ldap/servers/slapd/pw.c
|
|
|
081b2d |
+++ b/ldap/servers/slapd/pw.c
|
|
|
081b2d |
@@ -1465,7 +1465,7 @@ check_trivial_words(Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Value **vals, char *
|
|
|
081b2d |
sp = slapi_ch_strdup(slapi_value_get_string(valp));
|
|
|
081b2d |
ep = sp + strlen(sp);
|
|
|
081b2d |
ep = ldap_utf8prevn(sp, ep, toklen);
|
|
|
081b2d |
- if (!ep || (sp >= ep)) {
|
|
|
081b2d |
+ if (!ep || (sp > ep)) {
|
|
|
081b2d |
slapi_ch_free_string(&sp);
|
|
|
081b2d |
continue;
|
|
|
081b2d |
}
|
|
|
081b2d |
diff --git a/ldap/servers/slapd/utf8.c b/ldap/servers/slapd/utf8.c
|
|
|
081b2d |
index b0667c636..4538625b3 100644
|
|
|
081b2d |
--- a/ldap/servers/slapd/utf8.c
|
|
|
081b2d |
+++ b/ldap/servers/slapd/utf8.c
|
|
|
081b2d |
@@ -152,7 +152,7 @@ ldap_utf8prevn(char *s, char *from, int n)
|
|
|
081b2d |
}
|
|
|
081b2d |
for (; n > 0; --n) {
|
|
|
081b2d |
prev = ldap_utf8prev(prev);
|
|
|
081b2d |
- if ((prev <= s) && (n > 0)) {
|
|
|
081b2d |
+ if ((n > 0) && (prev < s)) {
|
|
|
081b2d |
return NULL;
|
|
|
081b2d |
}
|
|
|
081b2d |
}
|
|
|
081b2d |
--
|
|
|
081b2d |
2.13.6
|
|
|
081b2d |
|