From 9b2191151d943a43fad905432bf42cf2c173cc1a Mon Sep 17 00:00:00 2001 From: Mark Reynolds Date: Tue, 15 Jul 2014 12:34:02 -0400 Subject: [PATCH] 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: ? --- ldap/servers/plugins/replication/repl5_replica.c | 21 +++++++++++++-------- ldap/servers/slapd/entry.c | 12 +++++++++++- ldap/servers/slapd/slapi-plugin.h | 10 ++++++++++ 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/ldap/servers/plugins/replication/repl5_replica.c b/ldap/servers/plugins/replication/repl5_replica.c index b6e7be0..dab1c4e 100644 --- a/ldap/servers/plugins/replication/repl5_replica.c +++ b/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 " diff --git a/ldap/servers/slapd/entry.c b/ldap/servers/slapd/entry.c index 25549a7..718d78a 100644 --- a/ldap/servers/slapd/entry.c +++ b/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 *) */ { diff --git a/ldap/servers/slapd/slapi-plugin.h b/ldap/servers/slapd/slapi-plugin.h index cd17907..b803f91 100644 --- a/ldap/servers/slapd/slapi-plugin.h +++ b/ldap/servers/slapd/slapi-plugin.h @@ -1983,6 +1983,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. * * The syntax of the attribute type is taken into account when checking -- 1.9.3