andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone

Blame SOURCES/0084-Ticket-443-Deleting-attribute-present-in-nsslapd-all.patch

cc3dff
From 84a58b65db55c914a800b0fb31d538bc691c2b13 Mon Sep 17 00:00:00 2001
cc3dff
From: Noriko Hosoi <nhosoi@redhat.com>
cc3dff
Date: Thu, 23 Jan 2014 18:07:56 -0800
cc3dff
Subject: [PATCH 84/85] Ticket #443 - Deleting attribute present in
cc3dff
 nsslapd-allowed-to-delete-attrs returns Operations error
cc3dff
cc3dff
Description: commit 90dd9bb3c1411daca353d055d90618e67aa1fa7e introduced
cc3dff
an Invalid read/write.  The commit meant to allow "on" and "off" as well
cc3dff
as integer 0 and 1 in on/off type of config parameters.  This patch converts
cc3dff
the integers to "on" or "off" and pass it to config set function.
cc3dff
cc3dff
https://fedorahosted.org/389/ticket/443
cc3dff
cc3dff
Reviewed by rmeggins@redhat.com (Thank you, Rich!!)
cc3dff
(cherry picked from commit c52987d295a9f4a091568d02679765f3a83beb69)
cc3dff
(cherry picked from commit 4266657727fc71afbb6b4f21886ebd86a68b2ed2)
cc3dff
(cherry picked from commit d68dc3235d04caf3736d3587801a3c96cfebccb6)
cc3dff
---
cc3dff
 ldap/servers/slapd/libglobs.c | 54 +++++++++++++++++++++++++------------------
cc3dff
 1 file changed, 31 insertions(+), 23 deletions(-)
cc3dff
cc3dff
diff --git a/ldap/servers/slapd/libglobs.c b/ldap/servers/slapd/libglobs.c
cc3dff
index bcf7db4..8bd4978 100644
cc3dff
--- a/ldap/servers/slapd/libglobs.c
cc3dff
+++ b/ldap/servers/slapd/libglobs.c
cc3dff
@@ -3176,8 +3176,7 @@ config_set_security( const char *attrname, char *value, char *errorbuf, int appl
cc3dff
 }
cc3dff
 
cc3dff
 static int 
cc3dff
-config_set_onoff ( const char *attrname, char *value, int *configvalue,
cc3dff
-		char *errorbuf, int apply )
cc3dff
+config_set_onoff(const char *attrname, char *value, int *configvalue, char *errorbuf, int apply)
cc3dff
 {
cc3dff
   int retVal = LDAP_SUCCESS;
cc3dff
   slapi_onoff_t newval = -1;
cc3dff
@@ -3185,33 +3184,27 @@ config_set_onoff ( const char *attrname, char *value, int *configvalue,
cc3dff
   slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
cc3dff
 #endif 
cc3dff
   
cc3dff
-  if ( config_value_is_null( attrname, value, errorbuf, 0 )) {
cc3dff
-	return LDAP_OPERATIONS_ERROR;
cc3dff
+  if ( config_value_is_null( attrname, value, errorbuf, 1 )) {
cc3dff
+    return LDAP_OPERATIONS_ERROR;
cc3dff
   }
cc3dff
   
cc3dff
   CFG_ONOFF_LOCK_WRITE(slapdFrontendConfig);
cc3dff
-  if ( strcasecmp ( value, "on" ) != 0 &&
cc3dff
-	   strcasecmp ( value, "off") != 0 && 
cc3dff
-	   /* initializing the value */
cc3dff
-	   (*(int *)value != LDAP_ON) &&
cc3dff
-	   (*(int *)value != LDAP_OFF)) {
cc3dff
-	PR_snprintf ( errorbuf, SLAPI_DSE_RETURNTEXT_SIZE,
cc3dff
-			"%s: invalid value \"%s\". Valid values are \"on\" or \"off\".",
cc3dff
-			attrname, value );
cc3dff
-	retVal = LDAP_OPERATIONS_ERROR;
cc3dff
+  if (strcasecmp(value, "on") && strcasecmp(value, "off")) {
cc3dff
+    PR_snprintf ( errorbuf, SLAPI_DSE_RETURNTEXT_SIZE,
cc3dff
+            "%s: invalid value \"%s\". Valid values are \"on\" or \"off\".",
cc3dff
+            attrname, value );
cc3dff
+    retVal = LDAP_OPERATIONS_ERROR;
cc3dff
   }
cc3dff
  
cc3dff
   if ( !apply ) {
cc3dff
-	/* we can return now if we aren't applying the changes */
cc3dff
-	return retVal;
cc3dff
+    /* we can return now if we aren't applying the changes */
cc3dff
+    return retVal;
cc3dff
   }
cc3dff
   
cc3dff
   if ( strcasecmp ( value, "on" ) == 0 ) {
cc3dff
-	newval = LDAP_ON;
cc3dff
+    newval = LDAP_ON;
cc3dff
   } else if ( strcasecmp ( value, "off" ) == 0 ) {
cc3dff
-	newval = LDAP_OFF;
cc3dff
-  } else { /* assume it is an integer */
cc3dff
-	newval = *(slapi_onoff_t *)value;
cc3dff
+    newval = LDAP_OFF;
cc3dff
   }
cc3dff
   
cc3dff
 #ifdef ATOMIC_GETSET_ONOFF
cc3dff
@@ -7000,6 +6993,18 @@ config_get_listen_backlog_size()
cc3dff
   return retVal; 
cc3dff
 }
cc3dff
 
cc3dff
+static char *
cc3dff
+config_initvalue_to_onoff(struct config_get_and_set *cgas, char *initvalbuf, size_t initvalbufsize)
cc3dff
+{
cc3dff
+	char *retval = NULL;
cc3dff
+	if (cgas->config_var_type == CONFIG_ON_OFF) {
cc3dff
+		slapi_onoff_t *ival = (slapi_onoff_t *)(intptr_t)cgas->initvalue;
cc3dff
+		PR_snprintf(initvalbuf, initvalbufsize, "%s", (ival && *ival) ? "on" : "off");
cc3dff
+		retval = initvalbuf;
cc3dff
+	}
cc3dff
+	return retval;
cc3dff
+}
cc3dff
+
cc3dff
 /*
cc3dff
  * This function is intended to be used from the dse code modify callback.  It
cc3dff
  * is "optimized" for that case because it takes a berval** of values, which is
cc3dff
@@ -7048,12 +7053,15 @@ config_set(const char *attr, struct berval **values, char *errorbuf, int apply)
cc3dff
 	default:
cc3dff
 		if ((NULL == values) &&
cc3dff
 			config_allowed_to_delete_attrs(cgas->attr_name)) {
cc3dff
+			char initvalbuf[64];
cc3dff
+			void *initval = cgas->initvalue;
cc3dff
+			if (cgas->config_var_type == CONFIG_ON_OFF) {
cc3dff
+				initval = (void *)config_initvalue_to_onoff(cgas, initvalbuf, sizeof(initvalbuf));
cc3dff
+			}
cc3dff
 			if (cgas->setfunc) {
cc3dff
-				retval = (cgas->setfunc)(cgas->attr_name, cgas->initvalue,
cc3dff
-				                         errorbuf, apply);
cc3dff
+				retval = (cgas->setfunc)(cgas->attr_name, initval, errorbuf, apply);
cc3dff
 			} else if (cgas->logsetfunc) {
cc3dff
-				retval = (cgas->logsetfunc)(cgas->attr_name, cgas->initvalue,
cc3dff
-				                            cgas->whichlog, errorbuf, apply);
cc3dff
+				retval = (cgas->logsetfunc)(cgas->attr_name, initval, cgas->whichlog, errorbuf, apply);
cc3dff
 			} else {
cc3dff
 				LDAPDebug1Arg(LDAP_DEBUG_ANY, 
cc3dff
 				              "config_set: the attribute %s is read only; "
cc3dff
-- 
cc3dff
1.8.1.4
cc3dff