andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone
Blob Blame History Raw
From 22f6a14281033253b468a88978c582de5fb8a2b0 Mon Sep 17 00:00:00 2001
From: Noriko Hosoi <nhosoi@redhat.com>
Date: Thu, 23 Jan 2014 18:07:56 -0800
Subject: [PATCH 240/243] Ticket #443 - Deleting attribute present in
 nsslapd-allowed-to-delete-attrs returns Operations error

Description: commit 90dd9bb3c1411daca353d055d90618e67aa1fa7e introduced
an Invalid read/write.  The commit meant to allow "on" and "off" as well
as integer 0 and 1 in on/off type of config parameters.  This patch converts
the integers to "on" or "off" and pass it to config set function.

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

Reviewed by rmeggins@redhat.com (Thank you, Rich!!)
(cherry picked from commit c52987d295a9f4a091568d02679765f3a83beb69)
(cherry picked from commit 4266657727fc71afbb6b4f21886ebd86a68b2ed2)
(cherry picked from commit d68dc3235d04caf3736d3587801a3c96cfebccb6)
(cherry picked from commit 84a58b65db55c914a800b0fb31d538bc691c2b13)
(cherry picked from commit 2b08517d8679ecf2b7baa84608c77dea8c417cb3)
---
 ldap/servers/slapd/libglobs.c | 48 ++++++++++++++++++++++++++-----------------
 1 file changed, 29 insertions(+), 19 deletions(-)

diff --git a/ldap/servers/slapd/libglobs.c b/ldap/servers/slapd/libglobs.c
index a4d9546..5eda0f8 100644
--- a/ldap/servers/slapd/libglobs.c
+++ b/ldap/servers/slapd/libglobs.c
@@ -3032,30 +3032,25 @@ config_set_security( const char *attrname, char *value, char *errorbuf, int appl
 }
 
 static int 
-config_set_onoff ( const char *attrname, char *value, int *configvalue,
-		char *errorbuf, int apply )
+config_set_onoff(const char *attrname, char *value, int *configvalue, char *errorbuf, int apply)
 {
   int retVal = LDAP_SUCCESS;
   slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
   
-  if ( config_value_is_null( attrname, value, errorbuf, 0 )) {
-	return LDAP_OPERATIONS_ERROR;
+  if ( config_value_is_null( attrname, value, errorbuf, 1 )) {
+    return LDAP_OPERATIONS_ERROR;
   }
   
-  if ( strcasecmp ( value, "on" ) != 0 &&
-	   strcasecmp ( value, "off") != 0 && 
-	   /* initializing the value */
-	   (*(int *)value != LDAP_ON) &&
-	   (*(int *)value != LDAP_OFF)) {
-	PR_snprintf ( errorbuf, SLAPI_DSE_RETURNTEXT_SIZE,
-			"%s: invalid value \"%s\". Valid values are \"on\" or \"off\".",
-			attrname, value );
-	retVal = LDAP_OPERATIONS_ERROR;
+  if (strcasecmp(value, "on") && strcasecmp(value, "off")) {
+    PR_snprintf ( errorbuf, SLAPI_DSE_RETURNTEXT_SIZE,
+            "%s: invalid value \"%s\". Valid values are \"on\" or \"off\".",
+            attrname, value );
+    retVal = LDAP_OPERATIONS_ERROR;
   }
  
   if ( !apply ) {
-	/* we can return now if we aren't applying the changes */
-	return retVal;
+    /* we can return now if we aren't applying the changes */
+    return retVal;
   }
 
   CFG_LOCK_WRITE(slapdFrontendConfig);
@@ -6596,6 +6591,18 @@ config_set_ignore_time_skew( const char *attrname, char *value,
     return retVal;
 }
 
+static char *
+config_initvalue_to_onoff(struct config_get_and_set *cgas, char *initvalbuf, size_t initvalbufsize)
+{
+	char *retval = NULL;
+	if (cgas->config_var_type == CONFIG_ON_OFF) {
+		int *ival = (int *)(intptr_t)cgas->initvalue;
+		PR_snprintf(initvalbuf, initvalbufsize, "%s", (ival && *ival) ? "on" : "off");
+		retval = initvalbuf;
+	}
+	return retval;
+}
+
 /*
  * This function is intended to be used from the dse code modify callback.  It
  * is "optimized" for that case because it takes a berval** of values, which is
@@ -6644,12 +6651,15 @@ config_set(const char *attr, struct berval **values, char *errorbuf, int apply)
 	default:
 		if ((NULL == values) &&
 			config_allowed_to_delete_attrs(cgas->attr_name)) {
+			char initvalbuf[64];
+			void *initval = cgas->initvalue;
+			if (cgas->config_var_type == CONFIG_ON_OFF) {
+				initval = (void *)config_initvalue_to_onoff(cgas, initvalbuf, sizeof(initvalbuf));
+			}
 			if (cgas->setfunc) {
-				retval = (cgas->setfunc)(cgas->attr_name, cgas->initvalue,
-				                         errorbuf, apply);
+				retval = (cgas->setfunc)(cgas->attr_name, initval, errorbuf, apply);
 			} else if (cgas->logsetfunc) {
-				retval = (cgas->logsetfunc)(cgas->attr_name, cgas->initvalue,
-				                            cgas->whichlog, errorbuf, apply);
+				retval = (cgas->logsetfunc)(cgas->attr_name, initval, cgas->whichlog, errorbuf, apply);
 			} else {
 				LDAPDebug1Arg(LDAP_DEBUG_ANY, 
 				              "config_set: the attribute %s is read only; "
-- 
1.8.1.4