[fedfs-utils] [PATCH 03/17] libnsdb: LDAP result codes are signed integers

Chuck Lever chuck.lever at oracle.com
Thu Jan 2 12:27:20 PST 2014


Clean up: Have the functions in ldap.c return LDAP errors as signed
integers, matching the return value type of the LDAP client API.

For the moment, compilation will throw a bunch of warnings, but
we will get to that presently.

Signed-off-by: Chuck Lever <chuck.lever at oracle.com>
---
 src/libnsdb/ldap.c          |   46 ++++++++++++++++++-------------------------
 src/libnsdb/nsdb-internal.h |   22 ++++++++++-----------
 2 files changed, 30 insertions(+), 38 deletions(-)

diff --git a/src/libnsdb/ldap.c b/src/libnsdb/ldap.c
index 0c00bff..57fbf4a 100644
--- a/src/libnsdb/ldap.c
+++ b/src/libnsdb/ldap.c
@@ -97,11 +97,10 @@ nsdb_printable_ldap_mod_op(int op)
  */
 static int
 __nsdb_modify_nsdb_s(const char *func, LDAP *ld, const char *dn, LDAPMod *mod,
-		unsigned int *ldap_err)
+		int *ldap_err)
 {
 	char *uri, *attribute = mod->mod_type;
 	LDAPMod *mods[] = { mod, NULL };
-	int rc;
 
 	if (ldap_get_option(ld, LDAP_OPT_URI, &uri) == LDAP_OPT_SUCCESS) {
 		xlog(D_CALL, "%s: modifying %s (%s) at %s",
@@ -111,12 +110,11 @@ __nsdb_modify_nsdb_s(const char *func, LDAP *ld, const char *dn, LDAPMod *mod,
 		xlog(D_CALL, "%s: modifying %s (%s)",
 			func, dn, attribute);
 
-	rc = ldap_modify_ext_s(ld, dn, mods, NULL, NULL);
-	if (rc != LDAP_SUCCESS) {
+	*ldap_err = ldap_modify_ext_s(ld, dn, mods, NULL, NULL);
+	if (*ldap_err != LDAP_SUCCESS) {
 		xlog(D_GENERAL, "%s: failed to %s attribute %s: %s",
 				func, nsdb_printable_ldap_mod_op(mod->mod_op),
-				attribute, ldap_err2string(rc));
-		*ldap_err = (unsigned int)rc;
+				attribute, ldap_err2string(*ldap_err));
 		return FEDFS_ERR_NSDB_LDAP_VAL;
 	}
 	return FEDFS_OK;
@@ -462,7 +460,7 @@ nsdb_parse_multivalue_str(char *attr, struct berval **values, char ***result)
  */
 FedFsStatus
 nsdb_open(const char *hostname, const unsigned short port, LDAP **ld,
-		unsigned int *ldap_err)
+		int *ldap_err)
 {
 	int ldap_version, rc;
 	LDAPURLDesc url;
@@ -548,7 +546,7 @@ out_ldap_err:
  */
 FedFsStatus
 nsdb_bind(LDAP *ld, const char *binddn, const char *passwd,
-		unsigned int *ldap_err)
+		int *ldap_err)
 {
 	char *secret = (char *)passwd;
 	struct berval cred;
@@ -588,7 +586,7 @@ nsdb_bind(LDAP *ld, const char *binddn, const char *passwd,
  * @return a FedFsStatus code
  */
 FedFsStatus
-nsdb_start_tls(LDAP *ld, const char *certfile, unsigned int *ldap_err)
+nsdb_start_tls(LDAP *ld, const char *certfile, int *ldap_err)
 {
 	int value, rc;
 	char *uri;
@@ -668,7 +666,7 @@ out_ldap_err:
 FedFsStatus
 nsdb_add_attribute_s(LDAP *ld, const char *dn,
 		const char *attribute, struct berval *value,
-		unsigned int *ldap_err)
+		int *ldap_err)
 {
 	struct berval *attrvals[] = { value, NULL };
 	LDAPMod mod = {
@@ -705,7 +703,7 @@ nsdb_add_attribute_s(LDAP *ld, const char *dn,
  */
 FedFsStatus
 nsdb_modify_attribute_s(LDAP *ld, const char *dn, const char *attribute,
-		struct berval *value, unsigned int *ldap_err)
+		struct berval *value, int *ldap_err)
 {
 	struct berval *attrvals[] = { value, NULL };
 	LDAPMod mod = {
@@ -745,7 +743,7 @@ nsdb_modify_attribute_s(LDAP *ld, const char *dn, const char *attribute,
  */
 FedFsStatus
 nsdb_delete_attribute_s(LDAP *ld, const char *dn, const char *attribute,
-		struct berval *value, unsigned int *ldap_err)
+		struct berval *value, int *ldap_err)
 {
 	struct berval *attrvals[] = { value, NULL };
 	LDAPMod mod = {
@@ -787,7 +785,7 @@ nsdb_delete_attribute_s(LDAP *ld, const char *dn, const char *attribute,
  */
 FedFsStatus
 nsdb_delete_attribute_all_s(LDAP *ld, const char *dn,
-		const char *attribute, unsigned int *ldap_err)
+		const char *attribute, int *ldap_err)
 {
 	LDAPMod mod = {
 		.mod_op		= LDAP_MOD_DELETE,
@@ -853,24 +851,18 @@ nsdb_copy_referrals_array(char **refs, char ***referrals)
  */
 FedFsStatus
 nsdb_parse_result(LDAP *ld, LDAPMessage *result, char ***referrals,
-		unsigned int *ldap_err)
+		int *ldap_err)
 {
 	char *matched_dn = NULL, *error_msg = NULL;
-	int rc, result_code;
 	char **refs = NULL;
 	FedFsStatus retval;
+	int result_code;
 
-	if (ld == NULL || result == NULL || ldap_err == NULL) {
-		xlog(L_ERROR, "%s: Invalid parameter", __func__);
-		return FEDFS_ERR_INVAL;
-	}
-
-	rc = ldap_parse_result(ld, result, &result_code,
+	*ldap_err = ldap_parse_result(ld, result, &result_code,
 				&matched_dn, &error_msg, &refs, NULL, 0);
-	if (rc != LDAP_SUCCESS) {
+	if (*ldap_err != LDAP_SUCCESS) {
 		xlog(D_GENERAL, "%s: Failed to parse result: %s",
-			__func__, ldap_err2string(rc));
-		*ldap_err = rc;
+			__func__, ldap_err2string(*ldap_err));
 		return FEDFS_ERR_NSDB_LDAP_VAL;
 	}
 
@@ -1002,7 +994,7 @@ nsdb_compare_dns(LDAPDN dn1, LDAPDN dn2)
  */
 _Bool
 nsdb_compare_dn_string(LDAPDN dn1, const char *dn2_in,
-		unsigned int *ldap_err)
+		int *ldap_err)
 {
 	LDAPDN dn2 = NULL;
 	_Bool result;
@@ -1042,7 +1034,7 @@ out:
  */
 _Bool
 nsdb_compare_dn_strings(const char *dn1_in, const char *dn2_in,
-		unsigned int *ldap_err)
+		int *ldap_err)
 {
 	LDAPDN dn1 = NULL;
 	LDAPDN dn2 = NULL;
@@ -1114,7 +1106,7 @@ nsdb_ends_with(LDAPDN dn, LDAPDN suffix)
  */
 _Bool
 nsdb_dn_ends_with(const char *dn_in, const char *suffix_in,
-		unsigned int *ldap_err)
+		int *ldap_err)
 {
 	LDAPDN dn = NULL;
 	LDAPDN suffix = NULL;
diff --git a/src/libnsdb/nsdb-internal.h b/src/libnsdb/nsdb-internal.h
index a152524..9875fd4 100644
--- a/src/libnsdb/nsdb-internal.h
+++ b/src/libnsdb/nsdb-internal.h
@@ -78,38 +78,38 @@ FedFsStatus	 nsdb_parse_multivalue_str(char *attr,
 
 FedFsStatus	 nsdb_open(const char *hostname,
 				const unsigned short port, LDAP **ld,
-				unsigned int *ldap_err);
+				int *ldap_err);
 FedFsStatus	 nsdb_bind(LDAP *ld, const char *binddn,
 				const char *passwd,
-				unsigned int *ldap_err);
+				int *ldap_err);
 FedFsStatus	 nsdb_start_tls(LDAP *ld, const char *certfile,
-				unsigned int *ldap_err);
+				int *ldap_err);
 
 FedFsStatus	 nsdb_add_attribute_s(LDAP *ld, const char *dn,
 				const char *attribute,
 				struct berval *value,
-				unsigned int *ldap_err);
+				int *ldap_err);
 FedFsStatus	 nsdb_modify_attribute_s(LDAP *ld, const char *dn,
 				const char *attribute,
 				struct berval *value,
-				unsigned int *ldap_err);
+				int *ldap_err);
 FedFsStatus	 nsdb_delete_attribute_s(LDAP *ld, const char *dn,
 				const char *attribute,
 				struct berval *value,
-				unsigned int *ldap_err);
+				int *ldap_err);
 FedFsStatus	 nsdb_delete_attribute_all_s(LDAP *ld, const char *dn,
 				const char *attribute,
-				unsigned int *ldap_err);
+				int *ldap_err);
 FedFsStatus	 nsdb_parse_result(LDAP *ld, LDAPMessage *result,
-				char ***referrals, unsigned int *ldap_err);
+				char ***referrals, int *ldap_err);
 _Bool		 nsdb_compare_dns(LDAPDN dn1, LDAPDN dn2);
 _Bool		 nsdb_compare_dn_string(LDAPDN dn1, const char *dn2_in,
-				unsigned int *ldap_err);
+				int *ldap_err);
 _Bool		 nsdb_compare_dn_strings(const char *dn1_in,
 				const char *dn2_in,
-				unsigned int *ldap_err);
+				int *ldap_err);
 _Bool		 nsdb_dn_ends_with(const char *dn_in, const char *suffix_in,
-				unsigned int *ldap_err);
+				int *ldap_err);
 
 
 /**




More information about the fedfs-utils-devel mailing list