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

Re: ldap_explode_dn question



At 04:53 PM 2/28/2005, Jason Townsend wrote:
>This sample code generates an output / string that seems incorrect:
>
>Snippet
>=======================
>#include <stdio.h>
>#include <ldap.h>
>
>int main (int argc, const char * argv[])
>{
>    const char    *testDN = "cn=LastName\\, FirstName,dc=test,dc=com";
>    char **dn = ldap_explode_dn( testDN, 1 );
>
>    printf( "rdn = %s\n", dn[0] );
>
>    return 0;
>}
>
>Outputs:
>==========================
>rdn = LastName\2C FirstName

This is correct.  See ldap_explode_dn(3).


>Expected:
>==========================
>rdn = LastName, FirstName
>
>Hex 2C is obviously a comma, but a string in that form is not really usable for routines expecting the actual value.

Well, that's where you went wrong.  If you want the attribute
values, then you need to explode the RDNs. 

>Is this expected behavior

Yes.  ldap_explode_dn produces RDNs not AVAs.

>or is there some other routine you are expected to use to unescape the string?

ldap_explode_rdn(3)...

or, preferred, ldap_str2dn(3).


>This is on OpenLDAP 2.2.19 (but it doesn't look like there were any changes to this code in later 2.2.x releases).
>
>Thanks,
>-Jason
>
>