andykimpe / rpms / 389-ds-base

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