diff mbox

[3/7] libnsdb: Library fails to parse LDAP boolean results correctly

Message ID 20111103152833.2445.26927.stgit@degas.1015granger.net
State Accepted
Headers show

Commit Message

Chuck Lever Nov. 3, 2011, 3:28 p.m. UTC
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(-)
diff mbox

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;
 }
 
 /**