X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Foverlays%2Frwmdn.c;h=9af52112c6142cfb97e3fdaeb6391eab0eb270e7;hb=a255e44bf0fcb703a3a5ac58117fd54a00727fd1;hp=5cdf0522eed17a4c32847542a4ec89fa9c35018b;hpb=81ecb0b1536785c830a264243c969e03a3858af6;p=openldap diff --git a/servers/slapd/overlays/rwmdn.c b/servers/slapd/overlays/rwmdn.c index 5cdf0522ee..9af52112c6 100644 --- a/servers/slapd/overlays/rwmdn.c +++ b/servers/slapd/overlays/rwmdn.c @@ -2,7 +2,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 1999-2005 The OpenLDAP Foundation. + * Copyright 1999-2012 The OpenLDAP Foundation. * Portions Copyright 1999-2003 Howard Chu. * Portions Copyright 2000-2003 Pierangelo Masarati. * All rights reserved. @@ -142,7 +142,6 @@ rwm_dn_massage_pretty_normalize( return rc; } -#ifdef ENABLE_REWRITE /* * massages "in" into "dn" * @@ -158,27 +157,31 @@ rwm_dn_massage( int rc = 0; struct berval mdn; static char *dmy = ""; + char *in_val; assert( dc != NULL ); assert( in != NULL ); assert( dn != NULL ); + /* protect from NULL berval */ + in_val = in->bv_val ? in->bv_val : dmy; + rc = rewrite_session( dc->rwmap->rwm_rw, dc->ctx, - ( in->bv_val ? in->bv_val : dmy ), - dc->conn, &mdn.bv_val ); + in_val, dc->conn, &mdn.bv_val ); switch ( rc ) { case REWRITE_REGEXEC_OK: - if ( !BER_BVISNULL( &mdn ) && mdn.bv_val != in->bv_val ) { + if ( !BER_BVISNULL( &mdn ) && mdn.bv_val != in_val ) { mdn.bv_len = strlen( mdn.bv_val ); *dn = mdn; } else { - *dn = *in; + dn->bv_len = in->bv_len; + dn->bv_val = in_val; } rc = LDAP_SUCCESS; Debug( LDAP_DEBUG_ARGS, "[rw] %s: \"%s\" -> \"%s\"\n", - dc->ctx, in->bv_val, dn->bv_val ); + dc->ctx, in_val, dn->bv_val ); break; case REWRITE_REGEXEC_UNWILLING: @@ -202,114 +205,11 @@ rwm_dn_massage( BER_BVZERO( &mdn ); } - return rc; -} - -#else /* ! ENABLE_REWRITE */ -/* - * rwm_dn_massage - * - * Aliases the suffix; based on suffix_alias (servers/slapd/suffixalias.c). - */ -int -rwm_dn_massage( - dncookie *dc, - struct berval *in, - struct berval *dn -) -{ - int i, src, dst; - struct berval tmpin; - - assert( dc != NULL ); - assert( in != NULL ); - assert( dn != NULL ); - - BER_BVZERO( dn ); - - if ( BER_BVISNULL( in ) ) { - return LDAP_SUCCESS; - } - - if ( dc->rwmap == NULL || dc->rwmap->rwm_suffix_massage == NULL ) { - *dn = *in; - return LDAP_SUCCESS; - } - - if ( dc->tofrom ) { - src = 0 + dc->normalized; - dst = 2 + dc->normalized; - - tmpin = *in; - - } else { - int rc; - - src = 2 + dc->normalized; - dst = 0 + dc->normalized; - - /* DN from remote server may be in arbitrary form. - * Pretty it so we can parse reliably. - */ - if ( dc->normalized ) { - rc = dnNormalize( 0, NULL, NULL, in, &tmpin, NULL ); - - } else { - rc = dnPretty( NULL, in, &tmpin, NULL ); - } - - if ( rc != LDAP_SUCCESS ) { - return rc; - } + if ( dn->bv_val == dmy ) { + BER_BVZERO( dn ); } - for ( i = 0; - !BER_BVISNULL( &dc->rwmap->rwm_suffix_massage[i] ); - i += 4 ) - { - int aliasLength = dc->rwmap->rwm_suffix_massage[i+src].bv_len; - int diff = tmpin.bv_len - aliasLength; - - if ( diff < 0 ) { - /* alias is longer than dn */ - continue; - - } else if ( diff > 0 && ( !DN_SEPARATOR(tmpin.bv_val[diff-1]))) - { - /* FIXME: DN_SEPARATOR() is intended to work - * on a normalized/pretty DN, so that ';' - * is never used as a DN separator */ - continue; - /* At a DN Separator */ - } - - if ( !strcmp( dc->rwmap->rwm_suffix_massage[i+src].bv_val, - &tmpin.bv_val[diff] ) ) - { - dn->bv_len = diff + dc->rwmap->rwm_suffix_massage[i+dst].bv_len; - dn->bv_val = ch_malloc( dn->bv_len + 1 ); - strncpy( dn->bv_val, tmpin.bv_val, diff ); - strcpy( &dn->bv_val[diff], dc->rwmap->rwm_suffix_massage[i+dst].bv_val ); - Debug( LDAP_DEBUG_ARGS, - "rwm_dn_massage:" - " converted \"%s\" to \"%s\"\n", - in->bv_val, dn->bv_val, 0 ); - - break; - } - } - - if ( tmpin.bv_val != in->bv_val ) { - ch_free( tmpin.bv_val ); - } - - /* Nothing matched, just return the original DN */ - if ( BER_BVISNULL( dn ) ) { - *dn = *in; - } - - return LDAP_SUCCESS; + return rc; } -#endif /* ! ENABLE_REWRITE */ #endif /* SLAPD_OVER_RWM */