Blame SOURCES/0009-Disabling-gracelimit-does-not-prevent-LDAP-binds_rhbz#2109236.patch

b90797
From 1316cd8b2252c2543cf2ef2186956a8833037b1e Mon Sep 17 00:00:00 2001
b90797
From: Rob Crittenden <rcritten@redhat.com>
b90797
Date: Thu, 21 Jul 2022 09:28:46 -0400
b90797
Subject: [PATCH] Disabling gracelimit does not prevent LDAP binds
b90797
b90797
Originally the code treated 0 as disabled. This was
b90797
changed during the review process to -1 but one remnant
b90797
was missed effetively allowing gracelimit 0 to also mean
b90797
disabled.
b90797
b90797
Add explicit tests for testing with gracelimit = 0 and
b90797
gracelimit = -1.
b90797
b90797
Also remove some extranous "str(self.master.domain.basedn)"
b90797
lines from some of the tests.
b90797
b90797
Fixes: https://pagure.io/freeipa/issue/9206
b90797
b90797
Signed-off-by: Rob Crittenden <rcritten@redhat.com>
b90797
Reviewed-By: Francisco Trivino <ftrivino@redhat.com>
b90797
---
b90797
 .../ipa-graceperiod/ipa_graceperiod.c         |  2 +-
b90797
 ipatests/test_integration/test_pwpolicy.py    | 55 ++++++++++++++++++-
b90797
 2 files changed, 53 insertions(+), 4 deletions(-)
b90797
b90797
diff --git a/daemons/ipa-slapi-plugins/ipa-graceperiod/ipa_graceperiod.c b/daemons/ipa-slapi-plugins/ipa-graceperiod/ipa_graceperiod.c
b90797
index a3f57cb4b..345e1dee7 100644
b90797
--- a/daemons/ipa-slapi-plugins/ipa-graceperiod/ipa_graceperiod.c
b90797
+++ b/daemons/ipa-slapi-plugins/ipa-graceperiod/ipa_graceperiod.c
b90797
@@ -479,7 +479,7 @@ static int ipagraceperiod_preop(Slapi_PBlock *pb)
b90797
         if (pwresponse_requested) {
b90797
             slapi_pwpolicy_make_response_control(pb, -1, grace_limit - grace_user_time , -1);
b90797
         }
b90797
-    } else if ((grace_limit > 0) && (grace_user_time >= grace_limit)) {
b90797
+    } else if (grace_user_time >= grace_limit) {
b90797
         LOG_TRACE("%s password is expired and out of grace limit\n", dn);
b90797
         errstr = "Password is expired.\n";
b90797
         ret = LDAP_INVALID_CREDENTIALS;
b90797
diff --git a/ipatests/test_integration/test_pwpolicy.py b/ipatests/test_integration/test_pwpolicy.py
b90797
index 6d6698284..41d6e9070 100644
b90797
--- a/ipatests/test_integration/test_pwpolicy.py
b90797
+++ b/ipatests/test_integration/test_pwpolicy.py
b90797
@@ -36,7 +36,7 @@ class TestPWPolicy(IntegrationTest):
b90797
         cls.master.run_command(['ipa', 'group-add-member', POLICY,
b90797
                                 '--users', USER])
b90797
         cls.master.run_command(['ipa', 'pwpolicy-add', POLICY,
b90797
-                                '--priority', '1'])
b90797
+                                '--priority', '1', '--gracelimit', '-1'])
b90797
         cls.master.run_command(['ipa', 'passwd', USER],
b90797
                                stdin_text='{password}\n{password}\n'.format(
b90797
                                password=PASSWORD
b90797
@@ -265,7 +265,6 @@ class TestPWPolicy(IntegrationTest):
b90797
 
b90797
     def test_graceperiod_expired(self):
b90797
         """Test the LDAP bind grace period"""
b90797
-        str(self.master.domain.basedn)
b90797
         dn = "uid={user},cn=users,cn=accounts,{base_dn}".format(
b90797
              user=USER, base_dn=str(self.master.domain.basedn))
b90797
 
b90797
@@ -308,7 +307,6 @@ class TestPWPolicy(IntegrationTest):
b90797
 
b90797
     def test_graceperiod_not_replicated(self):
b90797
         """Test that the grace period is reset on password reset"""
b90797
-        str(self.master.domain.basedn)
b90797
         dn = "uid={user},cn=users,cn=accounts,{base_dn}".format(
b90797
              user=USER, base_dn=str(self.master.domain.basedn))
b90797
 
b90797
@@ -341,3 +339,54 @@ class TestPWPolicy(IntegrationTest):
b90797
         )
b90797
         assert 'passwordgraceusertime: 0' in result.stdout_text.lower()
b90797
         self.reset_password(self.master)
b90797
+
b90797
+    def test_graceperiod_zero(self):
b90797
+        """Test the LDAP bind with zero grace period"""
b90797
+        dn = "uid={user},cn=users,cn=accounts,{base_dn}".format(
b90797
+             user=USER, base_dn=str(self.master.domain.basedn))
b90797
+
b90797
+        self.master.run_command(
b90797
+            ["ipa", "pwpolicy-mod", POLICY, "--gracelimit", "0", ],
b90797
+        )
b90797
+
b90797
+        # Resetting the password will mark it as expired
b90797
+        self.reset_password(self.master)
b90797
+
b90797
+        # Now grace is done and binds should fail.
b90797
+        result = self.master.run_command(
b90797
+            ["ldapsearch", "-e", "ppolicy", "-D", dn,
b90797
+             "-w", PASSWORD, "-b", dn], raiseonerr=False
b90797
+        )
b90797
+        assert result.returncode == 49
b90797
+
b90797
+        assert 'Password is expired' in result.stderr_text
b90797
+        assert 'Password expired, 0 grace logins remain' in result.stderr_text
b90797
+
b90797
+    def test_graceperiod_disabled(self):
b90797
+        """Test the LDAP bind with grace period disabled (-1)"""
b90797
+        str(self.master.domain.basedn)
b90797
+        dn = "uid={user},cn=users,cn=accounts,{base_dn}".format(
b90797
+             user=USER, base_dn=str(self.master.domain.basedn))
b90797
+
b90797
+        # This can fail if gracelimit is already -1 so ignore it
b90797
+        self.master.run_command(
b90797
+            ["ipa", "pwpolicy-mod", POLICY, "--gracelimit", "-1",],
b90797
+            raiseonerr=False,
b90797
+        )
b90797
+
b90797
+        # Ensure the password is expired
b90797
+        self.reset_password(self.master)
b90797
+
b90797
+        result = self.kinit_as_user(self.master, PASSWORD, PASSWORD)
b90797
+
b90797
+        for _i in range(0, 10):
b90797
+            result = self.master.run_command(
b90797
+                ["ldapsearch", "-e", "ppolicy", "-D", dn,
b90797
+                 "-w", PASSWORD, "-b", dn]
b90797
+            )
b90797
+
b90797
+        # With graceperiod disabled it should not increment
b90797
+        result = tasks.ldapsearch_dm(
b90797
+            self.master, dn, ['passwordgraceusertime',],
b90797
+        )
b90797
+        assert 'passwordgraceusertime: 0' in result.stdout_text.lower()
b90797
-- 
b90797
2.37.2
b90797