Patchwork [13/15] libnsdb: Library fails to parse LDAP boolean results correctly

login
register
mail settings
Submitter Chuck Lever
Date Oct. 25, 2011, 4:50 p.m.
Message ID <20111025165016.18584.3107.stgit@seurat.1015granger.net>
Download mbox | patch
Permalink /patch/121770/
State Accepted
Headers show

Comments

Chuck Lever - Oct. 25, 2011, 4:50 p.m.
All boolean FSL values returned from the NSDB appear to be FALSE.

The code in nsdb_parse_singlevalue_bool() must have been a placeholder
implementation, as it doesn't work.  Replace it with something that
actually does work.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---

 src/libnsdb/ldap.c |   23 ++++++++++++++++-------
 1 files changed, 16 insertions(+), 7 deletions(-)

Patch

diff --git a/src/libnsdb/ldap.c b/src/libnsdb/ldap.c
index dc84753..acd9672 100644
--- a/src/libnsdb/ldap.c
+++ b/src/libnsdb/ldap.c
@@ -179,21 +179,30 @@  nsdb_free_string_array(char **strings)
 FedFsStatus
 nsdb_parse_singlevalue_bool(char *attr, struct berval **values, _Bool *result)
 {
+	struct berval *value;
+
 	if (values[1] != NULL) {
 		xlog(L_ERROR, "%s: Expecting only one value for attribute %s",
 			__func__, attr);
 		return FEDFS_ERR_NSDB_RESPONSE;
 	}
-
-	/* XXX: Better value type checking, please */
-	if (atoi(values[0]->bv_val)) {
-		xlog(D_CALL, "%s: Attribute %s contains TRUE", __func__, attr);
+	value = values[0];
+	
+	if (strncmp(value->bv_val, "TRUE", value->bv_len) == 0) {
+		xlog(D_CALL, "%s: Attribute %s contains TRUE",
+			__func__, attr);
 		*result = true;
-	} else {
-		xlog(D_CALL, "%s: Attribute %s contains FALSE", __func__, attr);
+		return FEDFS_OK;
+	} else if (strncmp(value->bv_val, "FALSE", value->bv_len) == 0) {
+		xlog(D_CALL, "%s: Attribute %s contains FALSE",
+			__func__, attr);
 		*result = false;
+		return FEDFS_OK;
 	}
-	return FEDFS_OK;
+
+	xlog(D_CALL, "%s: Attribute %s contains out-of-range value: %.*s",
+		__func__, attr, value->bv_len, value->bv_val);
+	return FEDFS_ERR_NSDB_RESPONSE;
 }
 
 /**