Blame SOURCES/0018-Issue-5221-User-with-expired-password-can-still-logi.patch

07ea61
From ad7573252147770c66ff3761add0f04fc8fa6f6c Mon Sep 17 00:00:00 2001
07ea61
From: Mark Reynolds <mreynolds@redhat.com>
07ea61
Date: Thu, 3 Mar 2022 16:29:41 -0500
07ea61
Subject: [PATCH 1/2] Issue 5221 - User with expired password can still login
07ea61
 with full privledges
07ea61
07ea61
Bug Description:
07ea61
07ea61
A user with an expired password can still login and perform operations
07ea61
with its typical access perimssions.  But an expired password means the
07ea61
account should be considered anonymous.
07ea61
07ea61
Fix Description:
07ea61
07ea61
Clear the bind credentials if the password is expired
07ea61
07ea61
relates: https://github.com/389ds/389-ds-base/issues/5221
07ea61
07ea61
Reviewed by: progier(Thanks!)
07ea61
---
07ea61
 .../suites/password/pw_expired_access_test.py | 62 +++++++++++++++++++
07ea61
 ldap/servers/slapd/pw_mgmt.c                  |  1 +
07ea61
 2 files changed, 63 insertions(+)
07ea61
 create mode 100644 dirsrvtests/tests/suites/password/pw_expired_access_test.py
07ea61
07ea61
diff --git a/dirsrvtests/tests/suites/password/pw_expired_access_test.py b/dirsrvtests/tests/suites/password/pw_expired_access_test.py
07ea61
new file mode 100644
07ea61
index 000000000..fb0afb190
07ea61
--- /dev/null
07ea61
+++ b/dirsrvtests/tests/suites/password/pw_expired_access_test.py
07ea61
@@ -0,0 +1,62 @@
07ea61
+import ldap
07ea61
+import logging
07ea61
+import pytest
07ea61
+import os
07ea61
+import time
07ea61
+from lib389._constants import DEFAULT_SUFFIX, PASSWORD
07ea61
+from lib389.idm.domain import Domain
07ea61
+from lib389.idm.user import UserAccounts
07ea61
+from lib389.topologies import topology_st as topo
07ea61
+
07ea61
+log = logging.getLogger(__name__)
07ea61
+
07ea61
+def test_expired_user_has_no_privledge(topo):
07ea61
+    """Specify a test case purpose or name here
07ea61
+
07ea61
+    :id: 3df86b45-9929-414b-9bf6-06c25301d207
07ea61
+    :setup: Standalone Instance
07ea61
+    :steps:
07ea61
+        1. Set short password expiration time
07ea61
+        2. Add user and wait for expiration time to run out
07ea61
+        3. Set one aci that allows authenticated users full access
07ea61
+        4. Bind as user (password should be expired)
07ea61
+        5. Attempt modify
07ea61
+    :expectedresults:
07ea61
+        1. Success
07ea61
+        2. Success
07ea61
+        3. Success
07ea61
+        4. Success
07ea61
+        5. Success
07ea61
+    """
07ea61
+
07ea61
+    # Configured password epxiration
07ea61
+    topo.standalone.config.replace_many(('passwordexp', 'on'), ('passwordmaxage', '1'))
07ea61
+
07ea61
+    # Set aci
07ea61
+    suffix = Domain(topo.standalone, DEFAULT_SUFFIX)
07ea61
+    ACI_TEXT = '(targetattr="*")(version 3.0; acl "test aci"; allow (all) (userdn="ldap:///all");)'
07ea61
+    suffix.replace('aci', ACI_TEXT)
07ea61
+
07ea61
+    # Add user
07ea61
+    user = UserAccounts(topo.standalone, DEFAULT_SUFFIX, rdn=None).create_test_user()
07ea61
+    user.replace('userpassword', PASSWORD)
07ea61
+    time.sleep(2)
07ea61
+
07ea61
+    # Bind as user with expired password.  Need to use raw ldap calls because
07ea61
+    # lib389 will close the connection when an error 49 is encountered.
07ea61
+    ldap_object = ldap.initialize(topo.standalone.toLDAPURL())
07ea61
+    with pytest.raises(ldap.INVALID_CREDENTIALS):
07ea61
+        res_type, res_data, res_msgid, res_ctrls = ldap_object.simple_bind_s(
07ea61
+            user.dn, PASSWORD)
07ea61
+
07ea61
+    # Try modify
07ea61
+    with pytest.raises(ldap.INSUFFICIENT_ACCESS):
07ea61
+        modlist = [ (ldap.MOD_REPLACE, 'description', b'Should not work!') ]
07ea61
+        ldap_object.modify_ext_s(DEFAULT_SUFFIX, modlist)
07ea61
+
07ea61
+
07ea61
+if __name__ == '__main__':
07ea61
+    # Run isolated
07ea61
+    # -s for DEBUG mode
07ea61
+    CURRENT_FILE = os.path.realpath(__file__)
07ea61
+    pytest.main(["-s", CURRENT_FILE])
07ea61
diff --git a/ldap/servers/slapd/pw_mgmt.c b/ldap/servers/slapd/pw_mgmt.c
07ea61
index 59b90dfa6..b67c2c8c0 100644
07ea61
--- a/ldap/servers/slapd/pw_mgmt.c
07ea61
+++ b/ldap/servers/slapd/pw_mgmt.c
07ea61
@@ -208,6 +208,7 @@ skip:
07ea61
             slapi_pwpolicy_make_response_control(pb, -1, -1, LDAP_PWPOLICY_PWDEXPIRED);
07ea61
         }
07ea61
         slapi_add_pwd_control(pb, LDAP_CONTROL_PWEXPIRED, 0);
07ea61
+        bind_credentials_clear(pb_conn, PR_FALSE, PR_TRUE);
07ea61
         slapi_send_ldap_result(pb, LDAP_INVALID_CREDENTIALS, NULL,
07ea61
                                "password expired!", 0, NULL);
07ea61
 
07ea61
-- 
07ea61
2.31.1
07ea61