[fedfs-utils] [PATCH 04/17] libnsdb: Add nsdb_ldaperr() to get LDAP operation error status
Chuck Lever
chuck.lever at oracle.com
Thu Jan 2 12:27:28 PST 2014
I'd like to get rid of the *ldaperr argument for libnsdb function
calls. Start by introducing a couple of functions that can extract
this value from an nsdb_t object.
The new nsdb_ldaperr() returns a signed integer, same as is returned
from the LDAP library, but unlike the existing *ldaperr argument to
most of the libnsdb API.
Signed-off-by: Chuck Lever <chuck.lever at oracle.com>
---
src/include/nsdb.h | 2 ++
src/libnsdb/nsdb-internal.h | 1 +
src/libnsdb/nsdb.c | 24 ++++++++++++++++++++++++
3 files changed, 27 insertions(+)
diff --git a/src/include/nsdb.h b/src/include/nsdb.h
index 4f6aadc..d1aafe1 100644
--- a/src/include/nsdb.h
+++ b/src/include/nsdb.h
@@ -270,6 +270,8 @@ const char *nsdb_default_binddn(const nsdb_t host);
const char *nsdb_default_nce(const nsdb_t host);
_Bool nsdb_follow_referrals(const nsdb_t host);
const char *nsdb_referred_to(const nsdb_t host);
+int nsdb_ldaperr(const nsdb_t host);
+const char *nsdb_ldaperr2string(const nsdb_t host);
/**
* Data type helpers for nsdb_t objects
diff --git a/src/libnsdb/nsdb-internal.h b/src/libnsdb/nsdb-internal.h
index 9875fd4..4746704 100644
--- a/src/libnsdb/nsdb-internal.h
+++ b/src/libnsdb/nsdb-internal.h
@@ -46,6 +46,7 @@ struct fedfs_nsdb {
char * fn_default_nce;
_Bool fn_follow_referrals;
char ** fn_referrals;
+ int fn_ldaperr;
};
/**
diff --git a/src/libnsdb/nsdb.c b/src/libnsdb/nsdb.c
index 090647a..31cf5ce 100644
--- a/src/libnsdb/nsdb.c
+++ b/src/libnsdb/nsdb.c
@@ -486,6 +486,30 @@ nsdb_referred_to(const nsdb_t host)
}
/**
+ * Return ldap error code from most recent LDAP operation
+ *
+ * @param host an instantiated nsdb_t object
+ * @return an LDAP error code
+ */
+int
+nsdb_ldaperr(const nsdb_t host)
+{
+ return host->fn_ldaperr;
+}
+
+/**
+ * Return ldap error message from most recent LDAP operation
+ *
+ * @param host an instantiated nsdb_t object
+ * @return NUL-terminated C string containing LDAP error message
+ */
+const char *
+nsdb_ldaperr2string(const nsdb_t host)
+{
+ return ldap_err2string(host->fn_ldaperr);
+}
+
+/**
* Retrieve NSDB-related environment variables
*
* @param nsdbname OUT: pointer to statically allocated NUL-terminated C string containing NSDB hostname
More information about the fedfs-utils-devel
mailing list