X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Flibldap%2Fgetdn.c;h=0dee28d71f9134f3962030ac9e8413ee99dc2b39;hb=df312502ac486d78fb67ad53a02742f18ea6fcec;hp=e66f6175be5689413aea883efc141c6afe1d83ff;hpb=159de0f1359459371c590ac770cc30edbade58d5;p=openldap diff --git a/libraries/libldap/getdn.c b/libraries/libldap/getdn.c index e66f6175be..0dee28d71f 100644 --- a/libraries/libldap/getdn.c +++ b/libraries/libldap/getdn.c @@ -1,7 +1,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 1998-2003 The OpenLDAP Foundation. + * Copyright 1998-2004 The OpenLDAP Foundation. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -3227,6 +3227,8 @@ int ldap_dn2bv_x( LDAPDN dn, struct berval *bv, unsigned flags, void *ctx ) break; case LDAP_DN_FORMAT_AD_CANONICAL: { + int trailing_slash = 1; + /* * Sort of UFN for DCE DNs: a slash ('/') separated * global->local DN with no types; strictly speaking, @@ -3251,7 +3253,7 @@ int ldap_dn2bv_x( LDAPDN dn, struct berval *bv, unsigned flags, void *ctx ) len += rdnl; } - if ( ( bv->bv_val = LDAP_MALLOCX( len + 1, ctx ) ) == NULL ) { + if ( ( bv->bv_val = LDAP_MALLOCX( len + 2, ctx ) ) == NULL ) { rc = LDAP_NO_MEMORY; break; } @@ -3260,6 +3262,8 @@ int ldap_dn2bv_x( LDAPDN dn, struct berval *bv, unsigned flags, void *ctx ) if ( iRDN && dn2domain( dn, bv, 0, &iRDN ) != 0 ) { for ( l = bv->bv_len; iRDN >= 0 ; iRDN-- ) { ber_len_t rdnl; + + trailing_slash = 0; if ( rdn2ADstr( dn[ iRDN ], &bv->bv_val[ l ], flags, &rdnl, 0 ) ) { @@ -3301,9 +3305,15 @@ int ldap_dn2bv_x( LDAPDN dn, struct berval *bv, unsigned flags, void *ctx ) } } + if ( trailing_slash ) { + bv->bv_val[ len ] = '/'; + len++; + } + bv->bv_len = len; bv->bv_val[ bv->bv_len ] = '\0'; + rc = LDAP_SUCCESS; } break;