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

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