[fedfs-utils] [PATCH 12/17] libnsdb: Remove *ldaperr argument from descr and annotate APIs

Chuck Lever chuck.lever at oracle.com
Thu Jan 2 12:28:35 PST 2014


Simplify the libnsdb APIs that update fedfsDescr and fedfsAnnotation
attributes by removing the *ldaperr argument.  When it is needed,
the ldaperr value can be extracted with the new nsdb_ldaperr()
function.

Signed-off-by: Chuck Lever <chuck.lever at oracle.com>
---
 src/include/nsdb.h          |    8 ++++---
 src/libnsdb/administrator.c |   48 +++++++++++++------------------------------
 src/nsdbc/nsdb-annotate.c   |   14 ++++---------
 src/nsdbc/nsdb-describe.c   |   11 ++++------
 4 files changed, 28 insertions(+), 53 deletions(-)

diff --git a/src/include/nsdb.h b/src/include/nsdb.h
index ea765f7..7fec490 100644
--- a/src/include/nsdb.h
+++ b/src/include/nsdb.h
@@ -357,17 +357,17 @@ FedFsStatus	 nsdb_delete_nsdb_s(nsdb_t host, const char *nce,
  * Display or alter an object's fedfsDescription attribute
  */
 FedFsStatus	 nsdb_description_add_s(nsdb_t host, const char *dn,
-				const char *description, unsigned int *ldap_err);
+				const char *description);
 FedFsStatus	 nsdb_description_delete_s(nsdb_t host, const char *dn,
-				const char *description, unsigned int *ldap_err);
+				const char *description);
 
 /**
  * Display or alter an object's fedfsAnnotation attribute
  */
 FedFsStatus	 nsdb_annotation_add_s(nsdb_t host, const char *dn,
-				const char *annotation, unsigned int *ldap_err);
+				const char *annotation);
 FedFsStatus	 nsdb_annotation_delete_s(nsdb_t host, const char *dn,
-				const char *annotation, unsigned int *ldap_err);
+				const char *annotation);
 
 /**
  ** NSDB file server operations defined in the
diff --git a/src/libnsdb/administrator.c b/src/libnsdb/administrator.c
index 8092cce..0b2a3eb 100644
--- a/src/libnsdb/administrator.c
+++ b/src/libnsdb/administrator.c
@@ -1810,7 +1810,6 @@ nsdb_delete_nsdb_s(nsdb_t host, const char *nce, unsigned int *ldap_err)
  * @param dn a NUL-terminated C string containing DN of entry to modify
  * @param attr a NUL-terminated C string containing attribute to modify
  * @param value a NUL-terminated UTF-8 C string containing new value of attribute
- * @param ldap_err OUT: possibly an LDAP error code
  * @return a FedFsStatus code
  *
  * LDIF equivalent:
@@ -1825,7 +1824,7 @@ nsdb_delete_nsdb_s(nsdb_t host, const char *nce, unsigned int *ldap_err)
  */
 static FedFsStatus
 nsdb_attr_add_s(nsdb_t host, const char *dn, const char *attr,
-		const char *value, unsigned int *ldap_err)
+		const char *value)
 {
 	struct berval bval;
 
@@ -1839,17 +1838,13 @@ nsdb_attr_add_s(nsdb_t host, const char *dn, const char *attr,
 		return FEDFS_ERR_INVAL;
 	}
 
-	if (ldap_err == NULL) {
-		xlog(L_ERROR, "%s: Invalid parameter", __func__);
-		return FEDFS_ERR_INVAL;
-	}
-
 	if (value == NULL)
 		return FEDFS_ERR_INVAL;
 
 	bval.bv_val = (char *)value;
 	bval.bv_len = (ber_len_t)strlen(value);
-	return nsdb_add_attribute_s(host->fn_ldap, dn, attr, &bval, ldap_err);
+	return nsdb_add_attribute_s(host->fn_ldap, dn, attr, &bval,
+							&host->fn_ldaperr);
 }
 
 /**
@@ -1859,7 +1854,6 @@ nsdb_attr_add_s(nsdb_t host, const char *dn, const char *attr,
  * @param dn a NUL-terminated C string containing DN of entry to modify
  * @param attr a NUL-terminated C string containing attribute to modify
  * @param value a NUL-terminated UTF-8 C string containing existing value of attribute
- * @param ldap_err OUT: possibly an LDAP error code
  * @return a FedFsStatus code
  *
  * "value" must exactly match a value contained by the target attribute.
@@ -1878,7 +1872,7 @@ nsdb_attr_add_s(nsdb_t host, const char *dn, const char *attr,
  */
 static FedFsStatus
 nsdb_attr_delete_s(nsdb_t host, const char *dn, const char *attr,
-		const char *value, unsigned int *ldap_err)
+		const char *value)
 {
 	struct berval bval;
 
@@ -1892,18 +1886,14 @@ nsdb_attr_delete_s(nsdb_t host, const char *dn, const char *attr,
 		return FEDFS_ERR_INVAL;
 	}
 
-	if (ldap_err == NULL) {
-		xlog(L_ERROR, "%s: Invalid parameter", __func__);
-		return FEDFS_ERR_INVAL;
-	}
-
 	if (value == NULL)
 		return nsdb_delete_attribute_all_s(host->fn_ldap, dn,
-							attr, ldap_err);
+							attr, &host->fn_ldaperr);
 
 	bval.bv_val = (char *)value;
 	bval.bv_len = (ber_len_t)strlen(value);
-	return nsdb_delete_attribute_s(host->fn_ldap, dn, attr, &bval, ldap_err);
+	return nsdb_delete_attribute_s(host->fn_ldap, dn, attr,
+						&bval, &host->fn_ldaperr);
 }
 
 /**
@@ -1912,15 +1902,13 @@ nsdb_attr_delete_s(nsdb_t host, const char *dn, const char *attr,
  * @param host an initialized and bound nsdb_t object
  * @param dn a NUL-terminated C string containing DN of entry to modify
  * @param annotation a NUL-terminated UTF-8 C string containing new value of fedfsAnnotation attribute
- * @param ldap_err OUT: possibly an LDAP error code
  * @return a FedFsStatus code
  */
 FedFsStatus
 nsdb_annotation_add_s(nsdb_t host, const char *dn,
-		const char *annotation, unsigned int *ldap_err)
+		const char *annotation)
 {
-	return nsdb_attr_add_s(host, dn, "fedfsAnnotation",
-				annotation, ldap_err);
+	return nsdb_attr_add_s(host, dn, "fedfsAnnotation", annotation);
 }
 
 /**
@@ -1929,7 +1917,6 @@ nsdb_annotation_add_s(nsdb_t host, const char *dn,
  * @param host an initialized and bound nsdb_t object
  * @param dn a NUL-terminated C string containing DN of entry to modify
  * @param annotation a NUL-terminated UTF-8 C string containing existing value of fedfsAnnotation attribute
- * @param ldap_err OUT: possibly an LDAP error code
  * @return a FedFsStatus code
  *
  * The annotation must exactly match a value contained by the fedfsAnnotation
@@ -1940,10 +1927,9 @@ nsdb_annotation_add_s(nsdb_t host, const char *dn,
  */
 FedFsStatus
 nsdb_annotation_delete_s(nsdb_t host, const char *dn,
-		const char *annotation, unsigned int *ldap_err)
+		const char *annotation)
 {
-	return nsdb_attr_delete_s(host, dn, "fedfsAnnotation",
-					annotation, ldap_err);
+	return nsdb_attr_delete_s(host, dn, "fedfsAnnotation", annotation);
 }
 
 /**
@@ -1952,14 +1938,12 @@ nsdb_annotation_delete_s(nsdb_t host, const char *dn,
  * @param host an initialized and bound nsdb_t object
  * @param dn a NUL-terminated C string containing DN of entry to modify
  * @param description a NUL-terminated UTF-8 C string containing new value of fedfsDescr attribute
- * @param ldap_err OUT: possibly an LDAP error code
  * @return a FedFsStatus code
  */
 FedFsStatus
-nsdb_description_add_s(nsdb_t host, const char *dn, const char *description,
-		unsigned int *ldap_err)
+nsdb_description_add_s(nsdb_t host, const char *dn, const char *description)
 {
-	return nsdb_attr_add_s(host, dn, "fedfsDescr", description, ldap_err);
+	return nsdb_attr_add_s(host, dn, "fedfsDescr", description);
 }
 
 /**
@@ -1968,7 +1952,6 @@ nsdb_description_add_s(nsdb_t host, const char *dn, const char *description,
  * @param host an initialized and bound nsdb_t object
  * @param dn a NUL-terminated C string containing DN of entry to modify
  * @param description a NUL-terminated UTF-8 C string containing existing value of fedfsDescr attribute
- * @param ldap_err OUT: possibly an LDAP error code
  * @return a FedFsStatus code
  *
  * "description" must exactly match a value contained by the fedfsDescr
@@ -1978,8 +1961,7 @@ nsdb_description_add_s(nsdb_t host, const char *dn, const char *description,
  * fedfsDescr attribute.
  */
 FedFsStatus
-nsdb_description_delete_s(nsdb_t host, const char *dn, const char *description,
-		unsigned int *ldap_err)
+nsdb_description_delete_s(nsdb_t host, const char *dn, const char *description)
 {
-	return nsdb_attr_delete_s(host, dn, "fedfsDescr", description, ldap_err);
+	return nsdb_attr_delete_s(host, dn, "fedfsDescr", description);
 }
diff --git a/src/nsdbc/nsdb-annotate.c b/src/nsdbc/nsdb-annotate.c
index 6d10465..b3a7617 100644
--- a/src/nsdbc/nsdb-annotate.c
+++ b/src/nsdbc/nsdb-annotate.c
@@ -109,7 +109,6 @@ main(int argc, char **argv)
 	char *progname, *binddn, *nsdbname;
 	char *keyword, *value, *entry, *annotation;
 	unsigned short nsdbport;
-	unsigned int ldap_err;
 	FedFsStatus retval;
 	_Bool delete;
 	nsdb_t host;
@@ -278,8 +277,7 @@ main(int argc, char **argv)
 	}
 
 	if (delete)
-		retval = nsdb_annotation_delete_s(host, entry, annotation,
-							&ldap_err);
+		retval = nsdb_annotation_delete_s(host, entry, annotation);
 	else {
 		if (annotation == NULL) {
 			retval = nsdb_construct_annotation(keyword, value,
@@ -290,12 +288,10 @@ main(int argc, char **argv)
 				goto out_close;
 			}
 
-			retval = nsdb_annotation_add_s(host, entry,
-							annotation, &ldap_err);
+			retval = nsdb_annotation_add_s(host, entry, annotation);
 			free(annotation);
 		} else
-			retval = nsdb_annotation_add_s(host, entry,
-							annotation, &ldap_err);
+			retval = nsdb_annotation_add_s(host, entry, annotation);
 	}
 	switch (retval) {
 	case FEDFS_OK:
@@ -304,7 +300,7 @@ main(int argc, char **argv)
 			delete ? "from" : "for", entry);
 		break;
 	case FEDFS_ERR_NSDB_LDAP_VAL:
-		switch (ldap_err) {
+		switch (nsdb_ldaperr(host)) {
 		case LDAP_REFERRAL:
 			fprintf(stderr, "Encountered LDAP referral on %s:%u\n",
 				nsdbname, nsdbport);
@@ -320,7 +316,7 @@ main(int argc, char **argv)
 		default:
 			fprintf(stderr, "Failed to %s annotation \"%s\" = \"%s\": %s\n",
 				delete ? "remove" : "update",
-				keyword, value, ldap_err2string(ldap_err));
+				keyword, value, nsdb_ldaperr2string(host));
 		}
 		break;
 	default:
diff --git a/src/nsdbc/nsdb-describe.c b/src/nsdbc/nsdb-describe.c
index eca70b1..3b46dec 100644
--- a/src/nsdbc/nsdb-describe.c
+++ b/src/nsdbc/nsdb-describe.c
@@ -104,7 +104,6 @@ main(int argc, char **argv)
 	char *progname, *binddn, *nsdbname;
 	char *description, *entry;
 	unsigned short nsdbport;
-	unsigned int ldap_err;
 	FedFsStatus retval;
 	_Bool delete;
 	nsdb_t host;
@@ -235,11 +234,9 @@ main(int argc, char **argv)
 	}
 
 	if (delete)
-		retval = nsdb_description_delete_s(host, entry,
-							description, &ldap_err);
+		retval = nsdb_description_delete_s(host, entry, description);
 	else
-		retval = nsdb_description_add_s(host, entry,
-							description, &ldap_err);
+		retval = nsdb_description_add_s(host, entry, description);
 	switch (retval) {
 	case FEDFS_OK:
 		printf("Successfully %s description value %s %s\n",
@@ -247,7 +244,7 @@ main(int argc, char **argv)
 			delete ? "from" : "for", entry);
 		break;
 	case FEDFS_ERR_NSDB_LDAP_VAL:
-		switch (ldap_err) {
+		switch (nsdb_ldaperr(host)) {
 		case LDAP_REFERRAL:
 			fprintf(stderr, "Encountered LDAP referral on %s:%u\n",
 				nsdbname, nsdbport);
@@ -266,7 +263,7 @@ main(int argc, char **argv)
 		default:
 			fprintf(stderr, "Failed to %s description value for %s: %s\n",
 				delete ? "remove" : "update", entry,
-				ldap_err2string(ldap_err));
+				nsdb_ldaperr2string(host));
 		}
 		break;
 	default:




More information about the fedfs-utils-devel mailing list