Преглед изворни кода

Ticket 47710 - Missing warning for invalid replica backoff configuration

Bug Description:  If you manaully edit the dse.ldif and set the minimum or
                  maximum backoff time to zero, a warning/error is not given.
                  At server startup the server thinks zero means the attribute
                  is not set, and then sets it to the default value without
                  logging a message.

Fix Description:  Properly check if the attribute is present, and log an error
                  accordingly.

https://fedorahosted.org/389/ticket/47710

Jenkins: passed

Reviewed by: nhosoi(Thanks!)
Mark Reynolds пре 11 година
родитељ
комит
eb5fde9fec

+ 13 - 8
ldap/servers/plugins/replication/repl5_replica.c

@@ -1839,23 +1839,28 @@ _replica_init_from_config (Replica *r, Slapi_Entry *e, char *errortext)
     }
 
     /* grab and validate the backoff retry settings */
-    backoff_min = slapi_entry_attr_get_int(e, type_replicaBackoffMin);
-    if(backoff_min <= 0){
-        if (backoff_min != 0){
+    if(slapi_entry_attr_exists(e, type_replicaBackoffMin)){
+        backoff_min = slapi_entry_attr_get_int(e, type_replicaBackoffMin);
+        if(backoff_min <= 0){
             slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "Invalid value for %s: %d  Using default value (%d)\n",
-                type_replicaBackoffMin, backoff_min, PROTOCOL_BACKOFF_MINIMUM );
+                    type_replicaBackoffMin, backoff_min, PROTOCOL_BACKOFF_MINIMUM );
+            backoff_min = PROTOCOL_BACKOFF_MINIMUM;
         }
+    } else {
         backoff_min = PROTOCOL_BACKOFF_MINIMUM;
     }
 
-    backoff_max = slapi_entry_attr_get_int(e, type_replicaBackoffMax);
-    if(backoff_max <= 0){
-        if(backoff_max != 0) {
+    if(slapi_entry_attr_exists(e, type_replicaBackoffMax)){
+        backoff_max = slapi_entry_attr_get_int(e, type_replicaBackoffMax);
+        if(backoff_max <= 0){
             slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "Invalid value for %s: %d  Using default value (%d)\n",
-                type_replicaBackoffMax, backoff_max, PROTOCOL_BACKOFF_MAXIMUM );
+                    type_replicaBackoffMax, backoff_max, PROTOCOL_BACKOFF_MAXIMUM );
+            backoff_max = PROTOCOL_BACKOFF_MAXIMUM;
         }
+    } else {
         backoff_max = PROTOCOL_BACKOFF_MAXIMUM;
     }
+
     if(backoff_min > backoff_max){
         /* Ok these values are invalid, reset back the defaults */
         slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "Backoff minimum (%d) can not be greater than "

+ 11 - 1
ldap/servers/slapd/entry.c

@@ -3123,11 +3123,21 @@ slapi_entry_attr_set_ulong( Slapi_Entry* e, const char *type, unsigned long l)
     slapi_entry_attr_replace( e, type, bvals );
 }
 
+int
+slapi_entry_attr_exists(Slapi_Entry *e, const char *type)
+{
+    Slapi_Attr *attr;
+
+    if(slapi_entry_attr_find(e, type, &attr) == 0){
+        return 1;
+    }
+    return 0;
+}
+
 /* JCM: The strcasecmp below should really be a bervalcmp
  * deprecatred in favour of slapi_entry_attr_has_syntax_value
  * which does respect the syntax of the attribute type.
 */
-
 SLAPI_DEPRECATED int
 slapi_entry_attr_hasvalue(const Slapi_Entry *e, const char *type, const char *value) /* JCM - (const char *) => (struct berval *) */
 {

+ 10 - 0
ldap/servers/slapd/slapi-plugin.h

@@ -1982,6 +1982,16 @@ void slapi_entry_attr_set_longlong( Slapi_Entry* e, const char *type, long long
  */
 void slapi_entry_attr_set_ulong(Slapi_Entry* e, const char *type, unsigned long l);
 
+/**
+ * Check if an attribute is set in the entry
+ *
+ * \param e Entry that you want to check.
+ * \param type Attribute type that you want to test for the value specified.
+ * \return 1 if attribute is present in the entry
+ * \return 0 if the attribute is not present in the entry.
+ */
+int slapi_entry_attr_exists(Slapi_Entry *e, const char *type);
+
 /**
  * Determines if an attribute in an entry contains a specified value.
  *