Subject: Detecting errors in ldap_get_values

From: Julio Sánchez Fernández <[email-masked]>
Date: Wed, 22 Mar 2000 10:50:57 +0100

According to the C API draft, NULL is returned both when no values for
the attribute type are present in the entry and when some kind of error
happened.  I have seen code in sendmail 8.10.0 that tries to tell which
is it by calling ldap_get_option with LDAP_OPT_ERROR_NUMBER and checking
if the returned value is LDAP_SUCCESS.

However, it might not be because of an earlier error.  Apparently, the
code I am looking at is working correctly with the Netscape libraries,
but fails with the OpenLDAP development version.  I am about to fix this
problem, but I don't know what is the correct solution.

Should the hidden stored field that LDAP_OPT_ERROR_NUMBER manages be set
to LDAP_SUCCESS before calling ldap_get_values and then, if NULL is
returned, LDAP_OPT_ERROR_NUMBER will be LDAP_SUCCESS indicating no
values were retrieved and something else if an error happened?

Thanks in advance,

Julio

---

From: Julio Sánchez Fernández <[email-masked]>
Date: Wed, 22 Mar 2000 12:15:03 +0100

> if the returned value is LDAP_SUCCESS.

Well, silly me, it was not ldap_get_values, but ldap_first_entry and
ldap_next_entry.

Still, the question stands and is a general API question: When a function
uses the same return value to indicate data exhaustion and error, a program
making use of that API *must* clear the error number before calling such a
function?

Or should the API implementation set the error number to LDAP_SUCCESS
on all successful calls to such functions?

Which is it?  Do I fix OpenLDAP or should I make a patch to send the
sendmail maintainers?

Thanks in advance,

Julio

---

From: "Kurt D. Zeilenga" <[email-masked]>
Date: Wed, 22 Mar 2000 06:20:23 -0800

Julio,

The current draft is somewhat unclear as to the behavior of
LDAP_OPT_ERROR_NUMBER, however it does describe the value as:
       The code of the most recent LDAP error that
	occurred for this session

Also, each of the routines that return NULL say something like:

	ldap_first/next_XXX will return NULL when no more XXX
	exist in the result set to be returned.  NULL is also 
	returned if an error occurs while stepping through the
	entries, in which case the error parameters in the
	session handle ld will be set to indicate the error.

Given these statements, I believe it inappropriate for an API
to set LDAP_OPT_ERROR_NUMBER unless an API error has occurred.
So, much like POSIX errno, I believe the caller has the
responsibility to clear past error codes.

The document should avoid the term "LDAP error" and, instead
use "LDAP resultCode" and "API error code".  The latter being
described as being LDAP resultCodes which are reserved by 
for API use.

At 12:15 PM 3/22/00 +0100, Julio Sánchez Fernández wrote:
>Do I fix OpenLDAP or should I make a patch to send the
>sendmail maintainers?

<<insert disclaimer concerning early adoptation of I-D>>

I suggest applications experimenting with implementations
of LDAP C APIs clear LDAP_OPT_ERROR_NUMBER.