Blame SOURCES/0057-Ticket-49370-Add-all-the-password-policy-defaults-to.patch

b045b9
From 86efa0314c59550f0660c8d143a52a57b1dffb96 Mon Sep 17 00:00:00 2001
b045b9
From: Mark Reynolds <mreynolds@redhat.com>
b045b9
Date: Thu, 18 Jan 2018 09:56:17 -0500
b045b9
Subject: [PATCH] Ticket 49370 - Add all the password policy defaults to a new 
b045b9
 local policy
b045b9
b045b9
Bug Description:  When processing a local password policy we were not pulling
b045b9
                  in the defaults for the "on/off" settings.  This patch
b045b9
                  addresses that.
b045b9
b045b9
Fix Description:  Create common default init functions for all password policies
b045b9
b045b9
https://pagure.io/389-ds-base/issue/49370
b045b9
b045b9
Reviewed by: tbordaz, wibrown, and spichugi (Thanks!!!)
b045b9
b045b9
(cherry picked from commit c8b388bf9f5269e1e1dc8c7c70ec8e58e825204a)
b045b9
---
b045b9
 .../tests/suites/password/regression_test.py       | 58 +++++++++++++--
b045b9
 ldap/servers/slapd/libglobs.c                      | 84 ++++++++++++++--------
b045b9
 ldap/servers/slapd/pw.c                            | 29 ++------
b045b9
 ldap/servers/slapd/slap.h                          |  2 +
b045b9
 4 files changed, 113 insertions(+), 60 deletions(-)
b045b9
b045b9
diff --git a/dirsrvtests/tests/suites/password/regression_test.py b/dirsrvtests/tests/suites/password/regression_test.py
b045b9
index f6ee16773..800294057 100644
b045b9
--- a/dirsrvtests/tests/suites/password/regression_test.py
b045b9
+++ b/dirsrvtests/tests/suites/password/regression_test.py
b045b9
@@ -6,9 +6,10 @@
b045b9
 # --- END COPYRIGHT BLOCK ---
b045b9
 #
b045b9
 import pytest
b045b9
-from lib389._constants import SUFFIX, PASSWORD
b045b9
+import time
b045b9
+from lib389._constants import SUFFIX, PASSWORD, DN_DM
b045b9
 from lib389.idm.user import UserAccounts
b045b9
-from lib389.utils import ldap, os, logging
b045b9
+from lib389.utils import ldap, os, logging, ensure_bytes
b045b9
 from lib389.topologies import topology_st as topo
b045b9
 
b045b9
 DEBUGGING = os.getenv("DEBUGGING", default=False)
b045b9
@@ -20,6 +21,7 @@ log = logging.getLogger(__name__)
b045b9
 
b045b9
 user_data = {'cn': 'CNpwtest1', 'sn': 'SNpwtest1', 'uid': 'UIDpwtest1', 'mail': 'MAILpwtest1@redhat.com',
b045b9
              'givenname': 'GNpwtest1'}
b045b9
+
b045b9
 TEST_PASSWORDS = list(user_data.values())
b045b9
 # Add substring/token values of "CNpwtest1"
b045b9
 TEST_PASSWORDS += ['CNpwtest1ZZZZ', 'ZZZZZCNpwtest1',
b045b9
@@ -37,13 +39,20 @@ def passw_policy(topo, request):
b045b9
     """Configure password policy with PasswordCheckSyntax attribute set to on"""
b045b9
 
b045b9
     log.info('Configure Pwpolicy with PasswordCheckSyntax and nsslapd-pwpolicy-local set to on')
b045b9
+    topo.standalone.simple_bind_s(DN_DM, PASSWORD)
b045b9
     topo.standalone.config.set('PasswordExp', 'on')
b045b9
     topo.standalone.config.set('PasswordCheckSyntax', 'off')
b045b9
     topo.standalone.config.set('nsslapd-pwpolicy-local', 'on')
b045b9
 
b045b9
     subtree = 'ou=people,{}'.format(SUFFIX)
b045b9
     log.info('Configure subtree password policy for {}'.format(subtree))
b045b9
-    topo.standalone.subtreePwdPolicy(subtree, {'passwordchange': 'on', 'passwordCheckSyntax': 'on'})
b045b9
+    topo.standalone.subtreePwdPolicy(subtree, {'passwordchange': ensure_bytes('on'),
b045b9
+                                               'passwordCheckSyntax': ensure_bytes('on'),
b045b9
+                                               'passwordLockout': ensure_bytes('on'),
b045b9
+                                               'passwordResetFailureCount': ensure_bytes('3'),
b045b9
+                                               'passwordLockoutDuration': ensure_bytes('3'),
b045b9
+                                               'passwordMaxFailure': ensure_bytes('2')})
b045b9
+    time.sleep(1)
b045b9
 
b045b9
     def fin():
b045b9
         log.info('Reset pwpolicy configuration settings')
b045b9
@@ -76,6 +85,47 @@ def test_user(topo, request):
b045b9
     return tuser
b045b9
 
b045b9
 
b045b9
+def test_pwp_local_unlock(topo, passw_policy, test_user):
b045b9
+    """Test subtree policies use the same global default for passwordUnlock
b045b9
+
b045b9
+    :id: 741a8417-5f65-4012-b9ed-87987ce3ca1b
b045b9
+    :setup: Standalone instance
b045b9
+    :steps:
b045b9
+        1. Test user can bind
b045b9
+        2. Bind with bad passwords to lockout account, and verify account is locked
b045b9
+        3. Wait for lockout interval, and bind with valid password
b045b9
+    :expectedresults:
b045b9
+        1. Bind successful
b045b9
+        2. Entry is locked
b045b9
+        3. Entry can bind with correct password
b045b9
+    """
b045b9
+
b045b9
+    log.info("Verify user can bind...")
b045b9
+    test_user.bind(PASSWORD)
b045b9
+
b045b9
+    log.info('Test passwordUnlock default - user should be able to reset password after lockout')
b045b9
+    for i in range(0,2):
b045b9
+        try:
b045b9
+            test_user.bind("bad-password")
b045b9
+        except ldap.INVALID_CREDENTIALS:
b045b9
+            # expected
b045b9
+            pass
b045b9
+        except ldap.LDAPError as e:
b045b9
+            log.fatal("Got unexpected failure: " + atr(e))
b045b9
+            raise e
b045b9
+
b045b9
+
b045b9
+    log.info('Verify account is locked')
b045b9
+    with pytest.raises(ldap.CONSTRAINT_VIOLATION):
b045b9
+        test_user.bind(PASSWORD)
b045b9
+
b045b9
+    log.info('Wait for lockout duration...')
b045b9
+    time.sleep(4)
b045b9
+
b045b9
+    log.info('Check if user can now bind with correct password')
b045b9
+    test_user.bind(PASSWORD)
b045b9
+
b045b9
+
b045b9
 @pytest.mark.bz1465600
b045b9
 @pytest.mark.parametrize("user_pasw", TEST_PASSWORDS)
b045b9
 def test_trivial_passw_check(topo, passw_policy, test_user, user_pasw):
b045b9
@@ -143,4 +193,4 @@ if __name__ == '__main__':
b045b9
     # Run isolated
b045b9
     # -s for DEBUG mode
b045b9
     CURRENT_FILE = os.path.realpath(__file__)
b045b9
-    pytest.main("-s {}".format(CURRENT_FILE))
b045b9
+    pytest.main(["-s", CURRENT_FILE])
b045b9
diff --git a/ldap/servers/slapd/libglobs.c b/ldap/servers/slapd/libglobs.c
b045b9
index 1ba30002f..c1a765aca 100644
b045b9
--- a/ldap/servers/slapd/libglobs.c
b045b9
+++ b/ldap/servers/slapd/libglobs.c
b045b9
@@ -1401,6 +1401,56 @@ getFrontendConfig(void)
b045b9
  */
b045b9
 
b045b9
 void
b045b9
+pwpolicy_init_defaults (passwdPolicy *pw_policy)
b045b9
+{
b045b9
+    pw_policy->pw_change = LDAP_ON;
b045b9
+    pw_policy->pw_must_change = LDAP_OFF;
b045b9
+    pw_policy->pw_syntax = LDAP_OFF;
b045b9
+    pw_policy->pw_exp = LDAP_OFF;
b045b9
+    pw_policy->pw_send_expiring = LDAP_OFF;
b045b9
+    pw_policy->pw_minlength = SLAPD_DEFAULT_PW_MINLENGTH;
b045b9
+    pw_policy->pw_mindigits = SLAPD_DEFAULT_PW_MINDIGITS;
b045b9
+    pw_policy->pw_minalphas = SLAPD_DEFAULT_PW_MINALPHAS;
b045b9
+    pw_policy->pw_minuppers = SLAPD_DEFAULT_PW_MINUPPERS;
b045b9
+    pw_policy->pw_minlowers = SLAPD_DEFAULT_PW_MINLOWERS;
b045b9
+    pw_policy->pw_minspecials = SLAPD_DEFAULT_PW_MINSPECIALS;
b045b9
+    pw_policy->pw_min8bit = SLAPD_DEFAULT_PW_MIN8BIT;
b045b9
+    pw_policy->pw_maxrepeats = SLAPD_DEFAULT_PW_MAXREPEATS;
b045b9
+    pw_policy->pw_mincategories = SLAPD_DEFAULT_PW_MINCATEGORIES;
b045b9
+    pw_policy->pw_mintokenlength = SLAPD_DEFAULT_PW_MINTOKENLENGTH;
b045b9
+    pw_policy->pw_maxage = SLAPD_DEFAULT_PW_MAXAGE;
b045b9
+    pw_policy->pw_minage = SLAPD_DEFAULT_PW_MINAGE;
b045b9
+    pw_policy->pw_warning = SLAPD_DEFAULT_PW_WARNING;
b045b9
+    pw_policy->pw_history = LDAP_OFF;
b045b9
+    pw_policy->pw_inhistory = SLAPD_DEFAULT_PW_INHISTORY;
b045b9
+    pw_policy->pw_lockout = LDAP_OFF;
b045b9
+    pw_policy->pw_maxfailure = SLAPD_DEFAULT_PW_MAXFAILURE;
b045b9
+    pw_policy->pw_unlock = LDAP_ON;
b045b9
+    pw_policy->pw_lockduration = SLAPD_DEFAULT_PW_LOCKDURATION;
b045b9
+    pw_policy->pw_resetfailurecount = SLAPD_DEFAULT_PW_RESETFAILURECOUNT;
b045b9
+    pw_policy->pw_gracelimit = SLAPD_DEFAULT_PW_GRACELIMIT;
b045b9
+    pw_policy->pw_admin = NULL;
b045b9
+    pw_policy->pw_admin_user = NULL;
b045b9
+    pw_policy->pw_is_legacy = LDAP_ON;
b045b9
+    pw_policy->pw_track_update_time = LDAP_OFF;
b045b9
+}
b045b9
+
b045b9
+static void
b045b9
+pwpolicy_fe_init_onoff(passwdPolicy *pw_policy)
b045b9
+{
b045b9
+    init_pw_change = pw_policy->pw_change;
b045b9
+    init_pw_must_change = pw_policy->pw_must_change;
b045b9
+    init_pw_syntax = pw_policy->pw_syntax;
b045b9
+    init_pw_exp = pw_policy->pw_exp;
b045b9
+    init_pw_send_expiring = pw_policy->pw_send_expiring;
b045b9
+    init_pw_history = pw_policy->pw_history;
b045b9
+    init_pw_lockout = pw_policy->pw_lockout;
b045b9
+    init_pw_unlock = pw_policy->pw_unlock;
b045b9
+    init_pw_is_legacy = pw_policy->pw_is_legacy;
b045b9
+    init_pw_track_update_time = pw_policy->pw_track_update_time;
b045b9
+}
b045b9
+
b045b9
+void
b045b9
 FrontendConfig_init(void)
b045b9
 {
b045b9
     slapdFrontendConfig_t *cfg = getFrontendConfig();
b045b9
@@ -1511,41 +1561,13 @@ FrontendConfig_init(void)
b045b9
     * let clients abide by the LDAP standards and send us a SASL/EXTERNAL bind
b045b9
     * if that's what they want to do */
b045b9
     init_force_sasl_external = cfg->force_sasl_external = LDAP_OFF;
b045b9
-
b045b9
     init_readonly = cfg->readonly = LDAP_OFF;
b045b9
+
b045b9
+    pwpolicy_init_defaults(&cfg->pw_policy);
b045b9
+    pwpolicy_fe_init_onoff(&cfg->pw_policy);
b045b9
     init_pwpolicy_local = cfg->pwpolicy_local = LDAP_OFF;
b045b9
     init_pwpolicy_inherit_global = cfg->pwpolicy_inherit_global = LDAP_OFF;
b045b9
-    init_pw_change = cfg->pw_policy.pw_change = LDAP_ON;
b045b9
-    init_pw_must_change = cfg->pw_policy.pw_must_change = LDAP_OFF;
b045b9
     init_allow_hashed_pw = cfg->allow_hashed_pw = LDAP_OFF;
b045b9
-    init_pw_syntax = cfg->pw_policy.pw_syntax = LDAP_OFF;
b045b9
-    init_pw_exp = cfg->pw_policy.pw_exp = LDAP_OFF;
b045b9
-    init_pw_send_expiring = cfg->pw_policy.pw_send_expiring = LDAP_OFF;
b045b9
-    cfg->pw_policy.pw_minlength = SLAPD_DEFAULT_PW_MINLENGTH;
b045b9
-    cfg->pw_policy.pw_mindigits = SLAPD_DEFAULT_PW_MINDIGITS;
b045b9
-    cfg->pw_policy.pw_minalphas = SLAPD_DEFAULT_PW_MINALPHAS;
b045b9
-    cfg->pw_policy.pw_minuppers = SLAPD_DEFAULT_PW_MINUPPERS;
b045b9
-    cfg->pw_policy.pw_minlowers = SLAPD_DEFAULT_PW_MINLOWERS;
b045b9
-    cfg->pw_policy.pw_minspecials = SLAPD_DEFAULT_PW_MINSPECIALS;
b045b9
-    cfg->pw_policy.pw_min8bit = SLAPD_DEFAULT_PW_MIN8BIT;
b045b9
-    cfg->pw_policy.pw_maxrepeats = SLAPD_DEFAULT_PW_MAXREPEATS;
b045b9
-    cfg->pw_policy.pw_mincategories = SLAPD_DEFAULT_PW_MINCATEGORIES;
b045b9
-    cfg->pw_policy.pw_mintokenlength = SLAPD_DEFAULT_PW_MINTOKENLENGTH;
b045b9
-    cfg->pw_policy.pw_maxage = SLAPD_DEFAULT_PW_MAXAGE;
b045b9
-    cfg->pw_policy.pw_minage = SLAPD_DEFAULT_PW_MINAGE;
b045b9
-    cfg->pw_policy.pw_warning = SLAPD_DEFAULT_PW_WARNING;
b045b9
-    init_pw_history = cfg->pw_policy.pw_history = LDAP_OFF;
b045b9
-    cfg->pw_policy.pw_inhistory = SLAPD_DEFAULT_PW_INHISTORY;
b045b9
-    init_pw_lockout = cfg->pw_policy.pw_lockout = LDAP_OFF;
b045b9
-    cfg->pw_policy.pw_maxfailure = SLAPD_DEFAULT_PW_MAXFAILURE;
b045b9
-    init_pw_unlock = cfg->pw_policy.pw_unlock = LDAP_ON;
b045b9
-    cfg->pw_policy.pw_lockduration = SLAPD_DEFAULT_PW_LOCKDURATION;
b045b9
-    cfg->pw_policy.pw_resetfailurecount = SLAPD_DEFAULT_PW_RESETFAILURECOUNT;
b045b9
-    cfg->pw_policy.pw_gracelimit = SLAPD_DEFAULT_PW_GRACELIMIT;
b045b9
-    cfg->pw_policy.pw_admin = NULL;
b045b9
-    cfg->pw_policy.pw_admin_user = NULL;
b045b9
-    init_pw_is_legacy = cfg->pw_policy.pw_is_legacy = LDAP_ON;
b045b9
-    init_pw_track_update_time = cfg->pw_policy.pw_track_update_time = LDAP_OFF;
b045b9
     init_pw_is_global_policy = cfg->pw_is_global_policy = LDAP_OFF;
b045b9
 
b045b9
     init_accesslog_logging_enabled = cfg->accesslog_logging_enabled = LDAP_ON;
b045b9
diff --git a/ldap/servers/slapd/pw.c b/ldap/servers/slapd/pw.c
b045b9
index 53464c64a..3a545e12e 100644
b045b9
--- a/ldap/servers/slapd/pw.c
b045b9
+++ b/ldap/servers/slapd/pw.c
b045b9
@@ -1730,32 +1730,11 @@ new_passwdPolicy(Slapi_PBlock *pb, const char *dn)
b045b9
                 goto done;
b045b9
             }
b045b9
 
b045b9
-            /* Set the default values */
b045b9
-            pwdpolicy->pw_mintokenlength = SLAPD_DEFAULT_PW_MINTOKENLENGTH;
b045b9
-            pwdpolicy->pw_minlength = SLAPD_DEFAULT_PW_MINLENGTH;
b045b9
-            pwdpolicy->pw_mindigits = SLAPD_DEFAULT_PW_MINDIGITS;
b045b9
-            pwdpolicy->pw_minalphas = SLAPD_DEFAULT_PW_MINALPHAS;
b045b9
-            pwdpolicy->pw_minuppers = SLAPD_DEFAULT_PW_MINUPPERS;
b045b9
-            pwdpolicy->pw_minlowers = SLAPD_DEFAULT_PW_MINLOWERS;
b045b9
-            pwdpolicy->pw_minspecials = SLAPD_DEFAULT_PW_MINSPECIALS;
b045b9
-            pwdpolicy->pw_min8bit = SLAPD_DEFAULT_PW_MIN8BIT;
b045b9
-            pwdpolicy->pw_maxrepeats = SLAPD_DEFAULT_PW_MAXREPEATS;
b045b9
-            pwdpolicy->pw_mincategories = SLAPD_DEFAULT_PW_MINCATEGORIES;
b045b9
-            pwdpolicy->pw_maxage = SLAPD_DEFAULT_PW_MAXAGE;
b045b9
-            pwdpolicy->pw_minage = SLAPD_DEFAULT_PW_MINAGE;
b045b9
-            pwdpolicy->pw_warning = SLAPD_DEFAULT_PW_WARNING;
b045b9
-            pwdpolicy->pw_inhistory = SLAPD_DEFAULT_PW_INHISTORY;
b045b9
-            pwdpolicy->pw_maxfailure = SLAPD_DEFAULT_PW_MAXFAILURE;
b045b9
-            pwdpolicy->pw_lockduration = SLAPD_DEFAULT_PW_LOCKDURATION;
b045b9
-            pwdpolicy->pw_resetfailurecount = SLAPD_DEFAULT_PW_RESETFAILURECOUNT;
b045b9
-            pwdpolicy->pw_gracelimit = SLAPD_DEFAULT_PW_GRACELIMIT;
b045b9
-
b045b9
-            /* set the default passwordLegacyPolicy setting */
b045b9
-            pwdpolicy->pw_is_legacy = 1;
b045b9
-
b045b9
-            /* set passwordTrackUpdateTime */
b045b9
-            pwdpolicy->pw_track_update_time = slapdFrontendConfig->pw_policy.pw_track_update_time;
b045b9
+            /* Set the default values (from libglobs.c) */
b045b9
+            pwpolicy_init_defaults(pwdpolicy);
b045b9
+            pwdpolicy->pw_storagescheme = slapdFrontendConfig->pw_storagescheme;
b045b9
 
b045b9
+            /* Set the defined values now */
b045b9
             for (slapi_entry_first_attr(pw_entry, &attr); attr;
b045b9
                  slapi_entry_next_attr(pw_entry, attr, &attr)) {
b045b9
                 slapi_attr_get_type(attr, &attr_name);
b045b9
diff --git a/ldap/servers/slapd/slap.h b/ldap/servers/slapd/slap.h
b045b9
index 08754d8fb..f6fc374a4 100644
b045b9
--- a/ldap/servers/slapd/slap.h
b045b9
+++ b/ldap/servers/slapd/slap.h
b045b9
@@ -1773,6 +1773,8 @@ typedef struct passwordpolicyarray
b045b9
     Slapi_DN **pw_admin_user;
b045b9
 } passwdPolicy;
b045b9
 
b045b9
+void pwpolicy_init_defaults (passwdPolicy *pw_policy);
b045b9
+
b045b9
 Slapi_PBlock *slapi_pblock_clone(Slapi_PBlock *pb); /* deprecated */
b045b9
 
b045b9
 passwdPolicy *slapi_pblock_get_pwdpolicy(Slapi_PBlock *pb);
b045b9
-- 
b045b9
2.13.6
b045b9