X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fdn.c;h=c3669d64067967f7c2bcad40ff39c223bac0760d;hb=384f23f59d4f586c82d2626dde5ebf72518e73be;hp=509adb76e3ac3272a8c6bfda8706b6bdcda4a01f;hpb=da6d9eb0463255782f3fa70c61fd958d94c048cf;p=openldap diff --git a/servers/slapd/dn.c b/servers/slapd/dn.c index 509adb76e3..c3669d6406 100644 --- a/servers/slapd/dn.c +++ b/servers/slapd/dn.c @@ -2,7 +2,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 1998-2007 The OpenLDAP Foundation. + * Copyright 1998-2009 The OpenLDAP Foundation. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -228,81 +228,62 @@ rdnValidate( * Note: the sorting can be slightly improved by sorting first * by attribute type length, then by alphabetical order. * - * uses a linear search; should be fine since the number of AVAs in + * uses an insertion sort; should be fine since the number of AVAs in * a RDN should be limited. */ -static void -AVA_Sort( LDAPRDN rdn, int iAVA ) +static int +AVA_Sort( LDAPRDN rdn, int nAVAs ) { + LDAPAVA *ava_i; int i; - LDAPAVA *ava_in = rdn[ iAVA ]; assert( rdn != NULL ); - assert( ava_in != NULL ); - - for ( i = 0; i < iAVA; i++ ) { - LDAPAVA *ava = rdn[ i ]; - int a, j; - assert( ava != NULL ); + for ( i = 1; i < nAVAs; i++ ) { + LDAPAVA *ava_j; + int j; - a = strcmp( ava_in->la_attr.bv_val, ava->la_attr.bv_val ); + ava_i = rdn[ i ]; + for ( j = i-1; j >=0; j-- ) { + int a; - if ( a > 0 ) { - break; - } + ava_j = rdn[ j ]; + a = strcmp( ava_i->la_attr.bv_val, ava_j->la_attr.bv_val ); - while ( a == 0 ) { - int v, d; + if ( a == 0 ) { + int d; - d = ava_in->la_value.bv_len - ava->la_value.bv_len; + d = ava_i->la_value.bv_len - ava_j->la_value.bv_len; - v = memcmp( ava_in->la_value.bv_val, - ava->la_value.bv_val, - d <= 0 ? ava_in->la_value.bv_len - : ava->la_value.bv_len ); + a = memcmp( ava_i->la_value.bv_val, + ava_j->la_value.bv_val, + d <= 0 ? ava_i->la_value.bv_len + : ava_j->la_value.bv_len ); - if ( v == 0 && d != 0 ) { - v = d; + if ( a == 0 ) { + a = d; + } } + /* Duplicates are not allowed */ + if ( a == 0 ) + return LDAP_INVALID_DN_SYNTAX; - if ( v <= 0 ) { - /* - * got it! - */ + if ( a > 0 ) break; - } - if ( ++i == iAVA ) { - /* - * already sorted - */ - return; - } - - ava = rdn[ i ]; - a = strcmp( ava_in->la_attr.bv_val, - ava->la_attr.bv_val ); - } - - /* - * move ahead - */ - for ( j = iAVA; j > i; j-- ) { - rdn[ j ] = rdn[ j - 1 ]; + rdn[ j+1 ] = rdn[ j ]; } - rdn[ i ] = ava_in; - - return; + rdn[ j+1 ] = ava_i; } + return LDAP_SUCCESS; } static int LDAPRDN_rewrite( LDAPRDN rdn, unsigned flags, void *ctx ) { - int rc; - int iAVA; + int rc, iAVA, do_sort = 0; + for ( iAVA = 0; rdn[ iAVA ]; iAVA++ ) { LDAPAVA *ava = rdn[ iAVA ]; AttributeDescription *ad; @@ -311,7 +292,6 @@ LDAPRDN_rewrite( LDAPRDN rdn, unsigned flags, void *ctx ) slap_syntax_transform_func *transf = NULL; MatchingRule *mr = NULL; struct berval bv = BER_BVNULL; - int do_sort = 0; assert( ava != NULL ); @@ -415,10 +395,14 @@ LDAPRDN_rewrite( LDAPRDN rdn, unsigned flags, void *ctx ) ava->la_value = bv; ava->la_flags |= LDAP_AVA_FREE_VALUE; } + } + rc = LDAP_SUCCESS; - if( do_sort ) AVA_Sort( rdn, iAVA ); + if ( do_sort ) { + rc = AVA_Sort( rdn, iAVA ); } - return LDAP_SUCCESS; + + return rc; } /* @@ -455,7 +439,7 @@ dnNormalize( assert( val != NULL ); assert( out != NULL ); - Debug( LDAP_DEBUG_TRACE, ">>> dnNormalize: <%s>\n", val->bv_val, 0, 0 ); + Debug( LDAP_DEBUG_TRACE, ">>> dnNormalize: <%s>\n", val->bv_val ? val->bv_val : "", 0, 0 ); if ( val->bv_len != 0 ) { LDAPDN dn = NULL; @@ -494,7 +478,7 @@ dnNormalize( ber_dupbv_x( out, val, ctx ); } - Debug( LDAP_DEBUG_TRACE, "<<< dnNormalize: <%s>\n", out->bv_val, 0, 0 ); + Debug( LDAP_DEBUG_TRACE, "<<< dnNormalize: <%s>\n", out->bv_val ? out->bv_val : "", 0, 0 ); return LDAP_SUCCESS; } @@ -511,7 +495,7 @@ rdnNormalize( assert( val != NULL ); assert( out != NULL ); - Debug( LDAP_DEBUG_TRACE, ">>> dnNormalize: <%s>\n", val->bv_val, 0, 0 ); + Debug( LDAP_DEBUG_TRACE, ">>> dnNormalize: <%s>\n", val->bv_val ? val->bv_val : "", 0, 0 ); if ( val->bv_len != 0 ) { LDAPRDN rdn = NULL; int rc; @@ -552,7 +536,7 @@ rdnNormalize( ber_dupbv_x( out, val, ctx ); } - Debug( LDAP_DEBUG_TRACE, "<<< dnNormalize: <%s>\n", out->bv_val, 0, 0 ); + Debug( LDAP_DEBUG_TRACE, "<<< dnNormalize: <%s>\n", out->bv_val ? out->bv_val : "", 0, 0 ); return LDAP_SUCCESS; } @@ -567,7 +551,7 @@ dnPretty( assert( val != NULL ); assert( out != NULL ); - Debug( LDAP_DEBUG_TRACE, ">>> dnPretty: <%s>\n", val->bv_val, 0, 0 ); + Debug( LDAP_DEBUG_TRACE, ">>> dnPretty: <%s>\n", val->bv_val ? val->bv_val : "", 0, 0 ); if ( val->bv_len == 0 ) { ber_dupbv_x( out, val, ctx ); @@ -609,7 +593,7 @@ dnPretty( } } - Debug( LDAP_DEBUG_TRACE, "<<< dnPretty: <%s>\n", out->bv_val, 0, 0 ); + Debug( LDAP_DEBUG_TRACE, "<<< dnPretty: <%s>\n", out->bv_val ? out->bv_val : "", 0, 0 ); return LDAP_SUCCESS; } @@ -624,7 +608,7 @@ rdnPretty( assert( val != NULL ); assert( out != NULL ); - Debug( LDAP_DEBUG_TRACE, ">>> dnPretty: <%s>\n", val->bv_val, 0, 0 ); + Debug( LDAP_DEBUG_TRACE, ">>> rdnPretty: <%s>\n", val->bv_val ? val->bv_val : "", 0, 0 ); if ( val->bv_len == 0 ) { ber_dupbv_x( out, val, ctx ); @@ -668,7 +652,7 @@ rdnPretty( } } - Debug( LDAP_DEBUG_TRACE, "<<< dnPretty: <%s>\n", out->bv_val, 0, 0 ); + Debug( LDAP_DEBUG_TRACE, "<<< dnPretty: <%s>\n", out->bv_val ? out->bv_val : "", 0, 0 ); return LDAP_SUCCESS; } @@ -687,7 +671,7 @@ dnPrettyNormalDN( Debug( LDAP_DEBUG_TRACE, ">>> dn%sDN: <%s>\n", flags == SLAP_LDAPDN_PRETTY ? "Pretty" : "Normal", - val->bv_val, 0 ); + val->bv_val ? val->bv_val : "", 0 ); if ( val->bv_len == 0 ) { return LDAP_SUCCESS; @@ -734,7 +718,7 @@ dnPrettyNormal( struct berval *normal, void *ctx) { - Debug( LDAP_DEBUG_TRACE, ">>> dnPrettyNormal: <%s>\n", val->bv_val, 0, 0 ); + Debug( LDAP_DEBUG_TRACE, ">>> dnPrettyNormal: <%s>\n", val->bv_val ? val->bv_val : "", 0, 0 ); assert( val != NULL ); assert( pretty != NULL ); @@ -802,7 +786,8 @@ dnPrettyNormal( } Debug( LDAP_DEBUG_TRACE, "<<< dnPrettyNormal: <%s>, <%s>\n", - pretty->bv_val, normal->bv_val, 0 ); + pretty->bv_val ? pretty->bv_val : "", + normal->bv_val ? normal->bv_val : "", 0 ); return LDAP_SUCCESS; } @@ -1092,7 +1077,7 @@ dn_rdnlen( p = ber_bvchr( dn_in, ',' ); - return p ? p - dn_in->bv_val : dn_in->bv_len; + return p ? (ber_len_t) (p - dn_in->bv_val) : dn_in->bv_len; } @@ -1257,7 +1242,6 @@ int register_certificate_map_function(SLAP_CERT_MAP_FN *fn) return -1; } -#ifdef HAVE_TLS /* * Convert an X.509 DN into a normalized LDAP DN */ @@ -1274,6 +1258,7 @@ dnX509normalize( void *x509_name, struct berval *out ) return rc; } +#ifdef HAVE_TLS /* * Get the TLS session's peer's DN into a normalized LDAP DN */