zrhoffman / rpms / 389-ds-base

Forked from rpms/389-ds-base 3 years ago
Clone

Blame SOURCES/0062-Ticket-49082-Fix-password-expiration-related-shadow-.patch

723150
From 96ad7ec4fa84dd32439e3473c0128612dd5f9d49 Mon Sep 17 00:00:00 2001
723150
From: Noriko Hosoi <nhosoi@redhat.com>
723150
Date: Wed, 11 Jan 2017 15:04:42 -0800
723150
Subject: [PATCH 62/67] Ticket #49082 - Fix password expiration related shadow
723150
 attributes
723150
723150
The original patch was provided by Gordon Messmer (gordon.messmer@gmail.com)
723150
with the description:
723150
  Bug description:
723150
  Shadow attributes (in /etc/shadow and in LDAP) are typically unset when no
723150
  policy is in place. 389-ds will incorrectly return values (possibly set to 0)
723150
  when there is no policy.
723150
723150
  Fix description:
723150
  Only auto-fill shadow attributes when a password policy is available.  These
723150
  are empty when no policy is in place.
723150
723150
  Don't auto-fill expiration related shadow attributes if passwords never expire.
723150
723150
Reviewed by William Brown <wibrown@redhat.com> (Thanks!!).
723150
723150
(cherry picked from commit 5bcd966b73708f6b558f01e6b11a7a11e8d3b126)
723150
(cherry picked from commit faae0fa5a4a6b3d590c1a9e068d9436965cc49c9)
723150
---
723150
 ldap/servers/slapd/pw.c | 74 +++++++++++++++++++++++++------------------------
723150
 1 file changed, 38 insertions(+), 36 deletions(-)
723150
723150
diff --git a/ldap/servers/slapd/pw.c b/ldap/servers/slapd/pw.c
723150
index ce1ca2a..30a2cb9 100644
723150
--- a/ldap/servers/slapd/pw.c
723150
+++ b/ldap/servers/slapd/pw.c
723150
@@ -2802,7 +2802,7 @@ add_shadow_ext_password_attrs(Slapi_PBlock *pb, Slapi_Entry **e)
723150
 {
723150
     const char *dn = NULL;
723150
     passwdPolicy *pwpolicy = NULL;
723150
-    long long shadowval = 0;
723150
+    long long shadowval = -1;
723150
     Slapi_Mods *smods = NULL;
723150
     LDAPMod **mods;
723150
     long long sval;
723150
@@ -2840,64 +2840,66 @@ add_shadow_ext_password_attrs(Slapi_PBlock *pb, Slapi_Entry **e)
723150
         if (shadowval > _MAX_SHADOW) {
723150
             shadowval = _MAX_SHADOW;
723150
         }
723150
-    } else {
723150
-        shadowval = 0;
723150
     }
723150
-    shmin = slapi_entry_attr_get_charptr(*e, "shadowMin");
723150
-    if (shmin) {
723150
-        sval = strtoll(shmin, NULL, 0);
723150
-        if (sval != shadowval) {
723150
-            slapi_ch_free_string(&shmin);
723150
-            shmin = slapi_ch_smprintf("%lld", shadowval);
723150
+    if (shadowval > 0) {
723150
+        shmin = slapi_entry_attr_get_charptr(*e, "shadowMin");
723150
+        if (shmin) {
723150
+            sval = strtoll(shmin, NULL, 0);
723150
+            if (sval != shadowval) {
723150
+                slapi_ch_free_string(&shmin);
723150
+                shmin = slapi_ch_smprintf("%lld", shadowval);
723150
+                mod_num++;
723150
+            }
723150
+        } else {
723150
             mod_num++;
723150
+            shmin = slapi_ch_smprintf("%lld", shadowval);
723150
         }
723150
-    } else {
723150
-        mod_num++;
723150
-        shmin = slapi_ch_smprintf("%lld", shadowval);
723150
     }
723150
 
723150
     /* shadowMax - the maximum number of days for which the user password remains valid. */
723150
-    if (pwpolicy->pw_maxage > 0) {
723150
+    shadowval = -1;
723150
+    if (pwpolicy->pw_exp == 1 && pwpolicy->pw_maxage > 0) {
723150
         shadowval = pwpolicy->pw_maxage / _SEC_PER_DAY;
723150
         if (shadowval > _MAX_SHADOW) {
723150
             shadowval = _MAX_SHADOW;
723150
         }
723150
-    } else {
723150
-        shadowval = _MAX_SHADOW;
723150
     }
723150
-    shmax = slapi_entry_attr_get_charptr(*e, "shadowMax");
723150
-    if (shmax) {
723150
-        sval = strtoll(shmax, NULL, 0);
723150
-        if (sval != shadowval) {
723150
-            slapi_ch_free_string(&shmax);
723150
-            shmax = slapi_ch_smprintf("%lld", shadowval);
723150
+    if (shadowval > 0) {
723150
+        shmax = slapi_entry_attr_get_charptr(*e, "shadowMax");
723150
+        if (shmax) {
723150
+            sval = strtoll(shmax, NULL, 0);
723150
+            if (sval != shadowval) {
723150
+                slapi_ch_free_string(&shmax);
723150
+                shmax = slapi_ch_smprintf("%lld", shadowval);
723150
+                mod_num++;
723150
+            }
723150
+        } else {
723150
             mod_num++;
723150
+            shmax = slapi_ch_smprintf("%lld", shadowval);
723150
         }
723150
-    } else {
723150
-        mod_num++;
723150
-        shmax = slapi_ch_smprintf("%lld", shadowval);
723150
     }
723150
 
723150
     /* shadowWarning - the number of days of advance warning given to the user before the user password expires. */
723150
-    if (pwpolicy->pw_warning > 0) {
723150
+    shadowval = -1;
723150
+    if (pwpolicy->pw_exp == 1 && pwpolicy->pw_warning > 0) {
723150
         shadowval = pwpolicy->pw_warning / _SEC_PER_DAY;
723150
         if (shadowval > _MAX_SHADOW) {
723150
             shadowval = _MAX_SHADOW;
723150
         }
723150
-    } else {
723150
-        shadowval = 0;
723150
     }
723150
-    shwarn = slapi_entry_attr_get_charptr(*e, "shadowWarning");
723150
-    if (shwarn) {
723150
-        sval = strtoll(shwarn, NULL, 0);
723150
-        if (sval != shadowval) {
723150
-            slapi_ch_free_string(&shwarn);
723150
-            shwarn = slapi_ch_smprintf("%lld", shadowval);
723150
+    if (shadowval > 0) {
723150
+        shwarn = slapi_entry_attr_get_charptr(*e, "shadowWarning");
723150
+        if (shwarn) {
723150
+            sval = strtoll(shwarn, NULL, 0);
723150
+            if (sval != shadowval) {
723150
+                slapi_ch_free_string(&shwarn);
723150
+                shwarn = slapi_ch_smprintf("%lld", shadowval);
723150
+                mod_num++;
723150
+            }
723150
+        } else {
723150
             mod_num++;
723150
+            shwarn = slapi_ch_smprintf("%lld", shadowval);
723150
         }
723150
-    } else {
723150
-        mod_num++;
723150
-        shwarn = slapi_ch_smprintf("%lld", shadowval);
723150
     }
723150
 
723150
     smods = slapi_mods_new();
723150
-- 
723150
2.9.3
723150