X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Flibldap%2Fgetdn.c;h=f3c60465fd42b44a6bca5f3f58fe3164b1d50d24;hb=959edd88c0dc0ad558d9ebc423996c7a9d0f8cbc;hp=c22ea552bd4f04ee066825dc139a878d22999158;hpb=2d51ad52b3090d8aec17bbd0aa5b2a7634e09f0c;p=openldap diff --git a/libraries/libldap/getdn.c b/libraries/libldap/getdn.c index c22ea552bd..f3c60465fd 100644 --- a/libraries/libldap/getdn.c +++ b/libraries/libldap/getdn.c @@ -598,6 +598,23 @@ ldap_dnfree( LDAPDN *dn ) #define TMP_AVA_SLOTS 8 #define TMP_RDN_SLOTS 32 +int +ldap_bv2dn( struct berval *bv, LDAPDN **dn, unsigned flags ) +{ + assert( bv ); + assert( dn ); + + /* + * FIXME: ldap_bv2dn() and ldap_str2dn() will be swapped, + * i.e. ldap_str2dn() will become a wrapper for ldap_bv2dn() + */ + if ( bv->bv_len != strlen( bv->bv_val ) ) { + return LDAP_INVALID_DN_SYNTAX; + } + + return ldap_str2dn( bv->bv_val, dn, flags ); +} + int ldap_str2dn( LDAP_CONST char *str, LDAPDN **dn, unsigned flags ) { @@ -648,7 +665,12 @@ ldap_str2dn( LDAP_CONST char *str, LDAPDN **dn, unsigned flags ) goto parsing_error; } p++; - + + /* + * actually we do not want to accept by default the DCE form, + * we do not want to auto-detect it + */ +#if 0 } else if ( LDAP_DN_LDAP( flags ) ) { /* * if dn starts with '/' let's make it a DCE dn @@ -657,6 +679,7 @@ ldap_str2dn( LDAP_CONST char *str, LDAPDN **dn, unsigned flags ) flags |= LDAP_DN_FORMAT_DCE; p++; } +#endif } for ( ; p[ 0 ]; p++ ) { @@ -807,7 +830,9 @@ ldap_str2rdn( LDAP_CONST char *str, LDAPRDN **rdn, assert( rdn || flags & LDAP_DN_SKIP ); assert( n ); +#if 0 Debug( LDAP_DEBUG_TRACE, "=> ldap_str2rdn(%s,%u)\n%s", str, flags, "" ); +#endif if ( rdn ) { *rdn = NULL; @@ -1267,8 +1292,10 @@ return_result:; LDAP_FREE( tmpRDN ); } +#if 0 Debug( LDAP_DEBUG_TRACE, "<= ldap_str2rdn(%*s)=%d\n", p - str, str, rc ); +#endif if ( rdn ) { *rdn = newRDN; @@ -1980,7 +2007,12 @@ strval2str( struct berval *val, char *str, unsigned flags, ber_len_t *len ) continue; } - cl = LDAP_UTF8_CHARLEN( &val->bv_val[ s ] ); + /* + * The length was checked in strval2strlen(); + * LDAP_UTF8_CHARLEN() should suffice + */ + cl = LDAP_UTF8_CHARLEN2( &val->bv_val[ s ], cl ); + assert( cl > 0 ); /* * there might be some chars we want to escape in form @@ -2853,7 +2885,6 @@ int ldap_dn2bv( LDAPDN *dn, struct berval *bv, unsigned flags ) int ( *sv2s ) ( struct berval *v, char *s, unsigned f, ber_len_t *l ); assert( bv ); - bv->bv_len = 0; bv->bv_val = NULL; @@ -2872,13 +2903,13 @@ int ldap_dn2bv( LDAPDN *dn, struct berval *bv, unsigned flags ) case LDAP_DN_FORMAT_LDAPV3: sv2l = strval2strlen; sv2s = strval2str; - goto got_funcs; + if( 0 ) { case LDAP_DN_FORMAT_LDAPV2: - sv2l = strval2IA5strlen; - sv2s = strval2IA5str; -got_funcs: - + sv2l = strval2IA5strlen; + sv2s = strval2IA5str; + } + for ( iRDN = 0, len = 0; dn[ 0 ][ iRDN ]; iRDN++ ) { ber_len_t rdnl; LDAPRDN *rdn = dn[ 0 ][ iRDN ]; @@ -2921,7 +2952,6 @@ got_funcs: break; case LDAP_DN_FORMAT_UFN: { - /* * FIXME: quoting from RFC 1781: * @@ -3036,11 +3066,10 @@ got_funcs: #endif /* DC_IN_UFN */ rc = LDAP_SUCCESS; - break; - } - case LDAP_DN_FORMAT_DCE: + } break; + case LDAP_DN_FORMAT_DCE: for ( iRDN = 0, len = 0; dn[ 0 ][ iRDN ]; iRDN++ ) { ber_len_t rdnl; LDAPRDN *rdn = dn[ 0 ][ iRDN ]; @@ -3079,7 +3108,6 @@ got_funcs: break; case LDAP_DN_FORMAT_AD_CANONICAL: { - /* * Sort of UFN for DCE DNs: a slash ('/') separated * global->local DN with no types; strictly speaking, @@ -3161,8 +3189,7 @@ got_funcs: bv->bv_val[ bv->bv_len ] = '\0'; rc = LDAP_SUCCESS; - break; - } + } break; default: return LDAP_PARAM_ERROR; @@ -3170,6 +3197,7 @@ got_funcs: Debug( LDAP_DEBUG_TRACE, "<= ldap_dn2bv(%s,%u)=%d\n", bv->bv_val, flags, rc ); + return_results:; return( rc ); }