[Date Prev][Date Next] [Chronological] [Thread] [Top]

Re: Simple questions about ldap_controls_free, ber_flatten2, ber_printf formats



At 04:52 AM 6/1/2005, Ames Andreas wrote:
>I've got some questions I couldn't find an answer for in
>draft-ietf-ldapext-ldap-c-api-xx.txt.
>
>1) Is ldap_controls_free(0) supposed to work (say like the runtime's
>   free(0))?  The implementation is somewhat perplexing me because in
>   a debug build it will crash (assert) but in a release build it will
>   do ('if'-statement).

Though it should be noted that portable programs should not call 
ldap_controls_free() with anything but a pointer to a library
allocated LDAPControl structure, calling 0 will only assert
if the library was compiled with LDAP_MEMORY_DEBUG.  That
macro for debugging purposes only and certainly should not
be set in any production libldap/libldap_r.

>2) I'm using ber_flatten2 similarly to the following code:
>
>   ber_printf(ber, "{iON}", size, &cookie);
>   ber_flatten2(ber, &val, 0);
>
>   What makes me a bit nervous is that ber_flatten2 assumes that it
>   can write an additional \x0 to the end of the internal buffer of
>   BerElement 'ber' when I don't want the result to be allocated
>   (third parameter is 0).  How can I assure that this extra byte is
>   always there?

Make sure that BerElement's ber_buf is big enough.

>3) To be honest I have copied the above format string for ber_printf
>   from Luke Howard's page control implementation in nss_ldap.  I've
>   verified that it works but I don't understand the 'N' format
>   specifier.  On one hand I don't understand why an ASN.1 null should
>   be useful at all as it is not specified in RFC 2696, OTOH it uses
>   'N' instead of the documented 'n'.  Could you enlighten me a bit?

N is used to insert NULLs (when lber_int_null is true)
that should be ignored.  This is used in verification
protocol compliance.

Kurt