Blame SOURCES/0014-Ticket-48006-Missing-warning-for-invalid-replica-bac.patch

081b2d
From 73c72aba0ab31f9d16cdfd8879e9da5f3fb985e0 Mon Sep 17 00:00:00 2001
081b2d
From: Mark Reynolds <mreynolds@redhat.com>
081b2d
Date: Tue, 17 Oct 2017 12:39:18 -0400
081b2d
Subject: [PATCH] Ticket 48006 - Missing warning for invalid replica backoff 
081b2d
 configuration
081b2d
081b2d
Description:  Add warning if you try to set a min backoff time that is
081b2d
              greater than the configured maximum, or the max time that
081b2d
              is less than the minimum.
081b2d
081b2d
              Also fixed compiler warning in ldbm_config.c
081b2d
081b2d
https://pagure.io/389-ds-base/issue/48006
081b2d
081b2d
Reviewed by: firstyear(Thanks!)
081b2d
081b2d
(cherry picked from commit e123acb6987c75f6d7282b32c4f279b976eb6f5e)
081b2d
---
081b2d
 .../plugins/replication/repl5_replica_config.c     | 24 ++++++++++++++++++++--
081b2d
 ldap/servers/slapd/back-ldbm/ldbm_config.c         |  2 +-
081b2d
 2 files changed, 23 insertions(+), 3 deletions(-)
081b2d
081b2d
diff --git a/ldap/servers/plugins/replication/repl5_replica_config.c b/ldap/servers/plugins/replication/repl5_replica_config.c
081b2d
index f28044c19..22d766143 100644
081b2d
--- a/ldap/servers/plugins/replication/repl5_replica_config.c
081b2d
+++ b/ldap/servers/plugins/replication/repl5_replica_config.c
081b2d
@@ -465,7 +465,8 @@ replica_config_modify(Slapi_PBlock *pb,
081b2d
                     }
081b2d
                 } else if (strcasecmp(config_attr, type_replicaBackoffMin) == 0) {
081b2d
                     if (apply_mods) {
081b2d
-                        PRUint64 val = atoll(config_attr_value);
081b2d
+                        uint64_t val = atoll(config_attr_value);
081b2d
+                        uint64_t max;
081b2d
 
081b2d
                         if (val <= 0) {
081b2d
                             *returncode = LDAP_UNWILLING_TO_PERFORM;
081b2d
@@ -475,11 +476,21 @@ replica_config_modify(Slapi_PBlock *pb,
081b2d
                             slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name, "replica_config_modify - %s\n", errortext);
081b2d
                             break;
081b2d
                         }
081b2d
+                        max = replica_get_backoff_max(r);
081b2d
+                        if (val > max){
081b2d
+                            *returncode = LDAP_UNWILLING_TO_PERFORM;
081b2d
+                            PR_snprintf(errortext, SLAPI_DSE_RETURNTEXT_SIZE,
081b2d
+                                        "Attribute %s value (%s) is invalid, must be a number less than the max backoff time (%d).\n",
081b2d
+                                        config_attr, config_attr_value, (int)max);
081b2d
+                            slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name, "replica_config_modify - %s\n", errortext);
081b2d
+                            break;
081b2d
+                        }
081b2d
                         replica_set_backoff_min(r, val);
081b2d
                     }
081b2d
                 } else if (strcasecmp(config_attr, type_replicaBackoffMax) == 0) {
081b2d
                     if (apply_mods) {
081b2d
-                        PRUint64 val = atoll(config_attr_value);
081b2d
+                        uint64_t val = atoll(config_attr_value);
081b2d
+                        uint64_t min;
081b2d
 
081b2d
                         if (val <= 0) {
081b2d
                             *returncode = LDAP_UNWILLING_TO_PERFORM;
081b2d
@@ -490,6 +501,15 @@ replica_config_modify(Slapi_PBlock *pb,
081b2d
                                           errortext);
081b2d
                             break;
081b2d
                         }
081b2d
+                        min = replica_get_backoff_min(r);
081b2d
+                        if (val < min) {
081b2d
+                            *returncode = LDAP_UNWILLING_TO_PERFORM;
081b2d
+                            PR_snprintf(errortext, SLAPI_DSE_RETURNTEXT_SIZE,
081b2d
+                                        "Attribute %s value (%s) is invalid, must be a number more than the min backoff time (%d).\n",
081b2d
+                                        config_attr, config_attr_value, (int)min);
081b2d
+                            slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name, "replica_config_modify - %s\n", errortext);
081b2d
+                            break;
081b2d
+                        }
081b2d
                         replica_set_backoff_max(r, val);
081b2d
                     }
081b2d
                 } else if (strcasecmp(config_attr, type_replicaPrecisePurge) == 0) {
081b2d
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_config.c b/ldap/servers/slapd/back-ldbm/ldbm_config.c
081b2d
index 2ef4652ce..feb993366 100644
081b2d
--- a/ldap/servers/slapd/back-ldbm/ldbm_config.c
081b2d
+++ b/ldap/servers/slapd/back-ldbm/ldbm_config.c
081b2d
@@ -388,7 +388,7 @@ ldbm_config_directory_set(void *arg, void *value, char *errorbuf, int phase, int
081b2d
                     goto done;
081b2d
                 }
081b2d
                 slapi_pblock_destroy(search_pb);
081b2d
-                if (NULL == s || '\0' == s || 0 == PL_strcmp(s, "(null)")) {
081b2d
+                if (NULL == s || '\0' == *s || 0 == PL_strcmp(s, "(null)")) {
081b2d
                     slapi_log_err(SLAPI_LOG_ERR,
081b2d
                                   "ldbm_config_directory_set", "db directory is not set; check %s in the db config: %s\n",
081b2d
                                   CONFIG_DIRECTORY, CONFIG_LDBM_DN);
081b2d
-- 
081b2d
2.13.6
081b2d