andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone

Blame SOURCES/0020-Issue-49039-password-min-age-should-be-ignored-if-pa.patch

b69e47
From 578d207cd66e97e9ff8211559c62114a961e35a8 Mon Sep 17 00:00:00 2001
b69e47
From: Mark Reynolds <mreynolds@redhat.com>
b69e47
Date: Tue, 28 Mar 2017 14:21:47 -0400
b69e47
Subject: [PATCH] Issue 49039 - password min age should be ignored if password
b69e47
 needs to be reset
b69e47
b69e47
Description:  Do not check the password minimum age when changing a password
b69e47
              if the password "must" be reset.
b69e47
b69e47
https://pagure.io/389-ds-base/issue/49039
b69e47
b69e47
Reviewed by: firstyear(Thanks!)
b69e47
---
b69e47
 dirsrvtests/tests/tickets/ticket49039_test.py | 79 +++++++++++++++++++++++++++
b69e47
 ldap/servers/slapd/modify.c                   |  4 +-
b69e47
 2 files changed, 81 insertions(+), 2 deletions(-)
b69e47
 create mode 100644 dirsrvtests/tests/tickets/ticket49039_test.py
b69e47
b69e47
diff --git a/dirsrvtests/tests/tickets/ticket49039_test.py b/dirsrvtests/tests/tickets/ticket49039_test.py
b69e47
new file mode 100644
b69e47
index 0000000..e6d4c03
b69e47
--- /dev/null
b69e47
+++ b/dirsrvtests/tests/tickets/ticket49039_test.py
b69e47
@@ -0,0 +1,79 @@
b69e47
+import time
b69e47
+import ldap
b69e47
+import logging
b69e47
+import pytest
b69e47
+from lib389 import Entry
b69e47
+from lib389._constants import *
b69e47
+from lib389.properties import *
b69e47
+from lib389.tasks import *
b69e47
+from lib389.utils import *
b69e47
+from lib389.topologies import topology_st as topo
b69e47
+
b69e47
+DEBUGGING = os.getenv("DEBUGGING", default=False)
b69e47
+if DEBUGGING:
b69e47
+    logging.getLogger(__name__).setLevel(logging.DEBUG)
b69e47
+else:
b69e47
+    logging.getLogger(__name__).setLevel(logging.INFO)
b69e47
+log = logging.getLogger(__name__)
b69e47
+
b69e47
+USER_DN = 'uid=user,dc=example,dc=com'
b69e47
+
b69e47
+
b69e47
+def test_ticket49039(topo):
b69e47
+    """Test "password must change" verses "password min age".  Min age should not
b69e47
+    block password update if the password was reset.
b69e47
+    """
b69e47
+
b69e47
+    # Configure password policy
b69e47
+    try:
b69e47
+        topo.standalone.modify_s("cn=config", [(ldap.MOD_REPLACE, 'nsslapd-pwpolicy-local', 'on'),
b69e47
+                                               (ldap.MOD_REPLACE, 'passwordMustChange', 'on'),
b69e47
+                                               (ldap.MOD_REPLACE, 'passwordExp', 'on'),
b69e47
+                                               (ldap.MOD_REPLACE, 'passwordMaxAge', '86400000'),
b69e47
+                                               (ldap.MOD_REPLACE, 'passwordMinAge', '8640000'),
b69e47
+                                               (ldap.MOD_REPLACE, 'passwordChange', 'on')])
b69e47
+    except ldap.LDAPError as e:
b69e47
+        log.fatal('Failed to set password policy: ' + str(e))
b69e47
+
b69e47
+    # Add user, bind, and set password
b69e47
+    try:
b69e47
+        topo.standalone.add_s(Entry((USER_DN, {
b69e47
+            'objectclass': 'top extensibleObject'.split(),
b69e47
+            'uid': 'user1',
b69e47
+            'userpassword': PASSWORD
b69e47
+        })))
b69e47
+    except ldap.LDAPError as e:
b69e47
+        log.fatal('Failed to add user: error ' + e.message['desc'])
b69e47
+        assert False
b69e47
+
b69e47
+    # Reset password as RootDN
b69e47
+    try:
b69e47
+        topo.standalone.modify_s(USER_DN, [(ldap.MOD_REPLACE, 'userpassword', PASSWORD)])
b69e47
+    except ldap.LDAPError as e:
b69e47
+        log.fatal('Failed to bind: error ' + e.message['desc'])
b69e47
+        assert False
b69e47
+
b69e47
+    time.sleep(1)
b69e47
+
b69e47
+    # Reset password as user
b69e47
+    try:
b69e47
+        topo.standalone.simple_bind_s(USER_DN, PASSWORD)
b69e47
+    except ldap.LDAPError as e:
b69e47
+        log.fatal('Failed to bind: error ' + e.message['desc'])
b69e47
+        assert False
b69e47
+
b69e47
+    try:
b69e47
+        topo.standalone.modify_s(USER_DN, [(ldap.MOD_REPLACE, 'userpassword', PASSWORD)])
b69e47
+    except ldap.LDAPError as e:
b69e47
+        log.fatal('Failed to change password: error ' + e.message['desc'])
b69e47
+        assert False
b69e47
+
b69e47
+    log.info('Test Passed')
b69e47
+
b69e47
+
b69e47
+if __name__ == '__main__':
b69e47
+    # Run isolated
b69e47
+    # -s for DEBUG mode
b69e47
+    CURRENT_FILE = os.path.realpath(__file__)
b69e47
+    pytest.main("-s %s" % CURRENT_FILE)
b69e47
+
b69e47
diff --git a/ldap/servers/slapd/modify.c b/ldap/servers/slapd/modify.c
b69e47
index 4bef90a..32defae 100644
b69e47
--- a/ldap/servers/slapd/modify.c
b69e47
+++ b/ldap/servers/slapd/modify.c
b69e47
@@ -1326,8 +1326,8 @@ static int op_shared_allow_pw_change (Slapi_PBlock *pb, LDAPMod *mod, char **old
b69e47
 	       
b69e47
 	/* check if password is within password minimum age;
b69e47
 	   error result is sent directly from check_pw_minage */	
b69e47
-	if ((internal_op || !pb->pb_conn->c_needpw) && 
b69e47
-         check_pw_minage(pb, &sdn, mod->mod_bvalues) == 1)
b69e47
+	if (!pb->pb_conn->c_needpw &&
b69e47
+	    check_pw_minage(pb, &sdn, mod->mod_bvalues) == 1)
b69e47
 	{
b69e47
 		if (operation_is_flag_set(operation,OP_FLAG_ACTION_LOG_ACCESS))
b69e47
 		{
b69e47
-- 
b69e47
2.9.3
b69e47