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