Blame SOURCES/0004-Only-calculate-LDAP-password-grace-when-the-password_rhbz#782917.patch

99f4a5
From 3675bd1d7aca443832bb9bb2f521cc4d3a088aec Mon Sep 17 00:00:00 2001
99f4a5
From: Rob Crittenden <rcritten@redhat.com>
99f4a5
Date: Wed, 29 Jun 2022 13:25:55 +0000
99f4a5
Subject: [PATCH] Only calculate LDAP password grace when the password is
99f4a5
 expired
99f4a5
99f4a5
The user's pwd expiration was retrieved but inadvertently was never
99f4a5
compared to current time. So any LDAP bind, including from the
99f4a5
IPA API, counted against the grace period. There is no need to go
99f4a5
through the graceperiod code for non-expired passwords.
99f4a5
99f4a5
https://pagure.io/freeipa/issue/1539
99f4a5
99f4a5
Signed-off-by: Rob Crittenden <rcritten@redhat.com>
99f4a5
Reviewed-By: Florence Blanc-Renaud <frenaud@redhat.com>
99f4a5
---
99f4a5
 .../ipa-graceperiod/ipa_graceperiod.c                | 12 +++++++++---
99f4a5
 1 file changed, 9 insertions(+), 3 deletions(-)
99f4a5
99f4a5
diff --git a/daemons/ipa-slapi-plugins/ipa-graceperiod/ipa_graceperiod.c b/daemons/ipa-slapi-plugins/ipa-graceperiod/ipa_graceperiod.c
99f4a5
index 0860b5c20..a3f57cb4b 100644
99f4a5
--- a/daemons/ipa-slapi-plugins/ipa-graceperiod/ipa_graceperiod.c
99f4a5
+++ b/daemons/ipa-slapi-plugins/ipa-graceperiod/ipa_graceperiod.c
99f4a5
@@ -359,7 +359,8 @@ static int ipagraceperiod_preop(Slapi_PBlock *pb)
99f4a5
     Slapi_ValueSet *values = NULL;
99f4a5
     long grace_limit = 0;
99f4a5
     int grace_user_time;
99f4a5
-    char *pwd_expiration = NULL;
99f4a5
+    char *tmpstr = NULL;
99f4a5
+    time_t pwd_expiration;
99f4a5
     int pwresponse_requested = 0;
99f4a5
     Slapi_PBlock *pbtm = NULL;
99f4a5
     Slapi_Mods *smods = NULL;
99f4a5
@@ -414,12 +415,17 @@ static int ipagraceperiod_preop(Slapi_PBlock *pb)
99f4a5
     }
99f4a5
     slapi_value_free(&objectclass);
99f4a5
 
99f4a5
-    pwd_expiration = slapi_entry_attr_get_charptr(target_entry, "krbPasswordExpiration");
99f4a5
-    if (pwd_expiration == NULL) {
99f4a5
+    tmpstr = slapi_entry_attr_get_charptr(target_entry, "krbPasswordExpiration");
99f4a5
+    if (tmpstr == NULL) {
99f4a5
         /* No expiration means nothing to do */
99f4a5
         LOG_TRACE("No krbPasswordExpiration for %s, nothing to do\n", dn);
99f4a5
         goto done;
99f4a5
     }
99f4a5
+    pwd_expiration = ipapwd_gentime_to_time_t(tmpstr);
99f4a5
+    if (pwd_expiration > time(NULL)) {
99f4a5
+        /* Not expired, nothing to see here */
99f4a5
+        goto done;
99f4a5
+    }
99f4a5
 
99f4a5
     ldrc = ipagraceperiod_getpolicy(target_entry, &policy_entry,
99f4a5
                                     &values, &actual_type_name,
99f4a5
-- 
99f4a5
2.36.1
99f4a5