From: Pierangelo Masarati Date: Sat, 5 Jan 2002 17:49:59 +0000 (+0000) Subject: leftover ber_bvdup eliminated; rewritten ber_bvdup in terms of ber_dupbv; eliminated... X-Git-Tag: LDBM_PRE_GIANT_RWLOCK~273 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=d0261ee5340213c4aedaa1ae6f5afb15c6915883;p=openldap leftover ber_bvdup eliminated; rewritten ber_bvdup in terms of ber_dupbv; eliminated wrapper macro; other ber_* improvements --- diff --git a/include/lber.h b/include/lber.h index 2a7977c24f..c3bc498509 100644 --- a/include/lber.h +++ b/include/lber.h @@ -558,7 +558,9 @@ LBER_F( struct berval * ) ber_dupbv LDAP_P(( struct berval *dst, LDAP_CONST struct berval *src )); -#define ber_bvdup(bv) ber_dupbv(NULL, bv) +LBER_F( struct berval * ) +ber_bvdup LDAP_P(( + LDAP_CONST struct berval *src )); LBER_F( struct berval * ) ber_str2bv LDAP_P(( diff --git a/libraries/liblber/memory.c b/libraries/liblber/memory.c index b357ca8534..3c660f6a2b 100644 --- a/libraries/liblber/memory.c +++ b/libraries/liblber/memory.c @@ -487,6 +487,15 @@ ber_dupbv( return new; } + +struct berval * +ber_bvdup( + LDAP_CONST struct berval *src ) +{ + return ber_dupbv( NULL, src ); +} + + struct berval * ber_str2bv( LDAP_CONST char *s, ber_len_t len, int dup, struct berval *bv) diff --git a/servers/slapd/back-bdb/search.c b/servers/slapd/back-bdb/search.c index d513b999ff..3106ceae3a 100644 --- a/servers/slapd/back-bdb/search.c +++ b/servers/slapd/back-bdb/search.c @@ -92,12 +92,13 @@ bdb_search( } if ( e == NULL ) { - struct berval *matched_dn = NULL; + struct berval matched_dn = { 0, NULL }; BVarray refs = NULL; if ( matched != NULL ) { BVarray erefs; - matched_dn = ber_bvdup( &matched->e_name ); + + ber_dupbv( &matched_dn, &matched->e_name ); erefs = is_entry_referral( matched ) ? get_entry_referrals( be, conn, op, matched ) @@ -107,7 +108,7 @@ bdb_search( matched = NULL; if( erefs ) { - refs = referral_rewrite( erefs, matched_dn, + refs = referral_rewrite( erefs, &matched_dn, base, scope ); bvarray_free( erefs ); } @@ -118,16 +119,18 @@ bdb_search( } send_ldap_result( conn, op, rc=LDAP_REFERRAL , - matched_dn ? matched_dn->bv_val : NULL, text, refs, NULL ); + matched_dn.bv_val, text, refs, NULL ); if ( refs ) bvarray_free( refs ); - if ( matched_dn ) ber_bvfree( matched_dn ); + if ( matched_dn.bv_val ) ber_memfree( matched_dn.bv_val ); return rc; } if (!manageDSAit && e != &slap_entry_root && is_entry_referral( e ) ) { /* entry is a referral, don't allow add */ - struct berval *matched_dn = ber_bvdup( &e->e_name ); + struct berval matched_dn; + + ber_dupbv( &matched_dn, &e->e_name ); BVarray erefs = get_entry_referrals( be, conn, op, e ); BVarray refs = NULL; @@ -135,7 +138,7 @@ bdb_search( e = NULL; if( erefs ) { - refs = referral_rewrite( erefs, matched_dn, + refs = referral_rewrite( erefs, &matched_dn, base, scope ); bvarray_free( erefs ); } @@ -144,12 +147,12 @@ bdb_search( 0, 0, 0 ); send_ldap_result( conn, op, LDAP_REFERRAL, - matched_dn->bv_val, + matched_dn.bv_val, refs ? NULL : "bad referral object", refs, NULL ); bvarray_free( refs ); - ber_bvfree( matched_dn ); + ber_memfree( matched_dn.bv_val ); return 1; } diff --git a/servers/slapd/back-ldbm/search.c b/servers/slapd/back-ldbm/search.c index 67452f53d0..36f8bc0a7a 100644 --- a/servers/slapd/back-ldbm/search.c +++ b/servers/slapd/back-ldbm/search.c @@ -91,12 +91,12 @@ ldbm_back_search( } if ( e == NULL ) { - struct berval *matched_dn = NULL; + struct berval matched_dn = { 0, NULL }; BVarray refs = NULL; if ( matched != NULL ) { BVarray erefs; - matched_dn = ber_bvdup( &matched->e_name ); + ber_dupbv( &matched_dn, &matched->e_name ); erefs = is_entry_referral( matched ) ? get_entry_referrals( be, conn, op, matched ) @@ -105,7 +105,7 @@ ldbm_back_search( cache_return_entry_r( &li->li_cache, matched ); if( erefs ) { - refs = referral_rewrite( erefs, matched_dn, + refs = referral_rewrite( erefs, &matched_dn, base, scope ); bvarray_free( erefs ); @@ -116,18 +116,19 @@ ldbm_back_search( NULL, base, scope ); } - send_ldap_result( conn, op, err, - matched_dn ? matched_dn->bv_val : NULL, + send_ldap_result( conn, op, err, matched_dn.bv_val, text, refs, NULL ); bvarray_free( refs ); - ber_bvfree( matched_dn ); + ber_memfree( matched_dn.bv_val ); return 1; } if (!manageDSAit && is_entry_referral( e ) ) { /* entry is a referral, don't allow add */ - struct berval *matched_dn = ber_bvdup( &e->e_name ); + struct berval matched_dn; + + ber_dupbv( &matched_dn, &e->e_name ); BVarray erefs = get_entry_referrals( be, conn, op, e ); BVarray refs = NULL; @@ -144,7 +145,7 @@ ldbm_back_search( #endif if( erefs ) { - refs = referral_rewrite( erefs, matched_dn, + refs = referral_rewrite( erefs, &matched_dn, base, scope ); bvarray_free( erefs ); @@ -152,16 +153,16 @@ ldbm_back_search( if( refs ) { send_ldap_result( conn, op, LDAP_REFERRAL, - matched_dn->bv_val, NULL, refs, NULL ); + matched_dn.bv_val, NULL, refs, NULL ); bvarray_free( refs ); } else { send_ldap_result( conn, op, LDAP_OTHER, - matched_dn->bv_val, + matched_dn.bv_val, "bad referral object", NULL, NULL ); } - ber_bvfree( matched_dn ); + ber_memfree( matched_dn.bv_val ); return 1; } diff --git a/servers/slapd/back-meta/back-meta.h b/servers/slapd/back-meta/back-meta.h index dcbe64632c..2862d1c2f8 100644 --- a/servers/slapd/back-meta/back-meta.h +++ b/servers/slapd/back-meta/back-meta.h @@ -89,7 +89,7 @@ struct metasingleconn { #define META_CANDIDATE 1 LDAP *ld; - struct berval *bound_dn; + struct berval bound_dn; int bound; #define META_UNBOUND 0 #define META_BOUND 1 diff --git a/servers/slapd/back-meta/bind.c b/servers/slapd/back-meta/bind.c index 4d54f63580..e988bd0a79 100644 --- a/servers/slapd/back-meta/bind.c +++ b/servers/slapd/back-meta/bind.c @@ -254,7 +254,7 @@ meta_back_do_single_bind( if ( rc != LDAP_SUCCESS ) { rc = ldap_back_map_result( rc ); } else { - lc->conns[ candidate ]->bound_dn = ber_bvdup( dn ); + ber_dupbv( &lc->conns[ candidate ]->bound_dn, dn ); lc->conns[ candidate ]->bound = META_BOUND; lc->bound_target = candidate; @@ -311,7 +311,7 @@ meta_back_dobind( struct metaconn *lc, Operation *op ) * (note: if the target was already bound, the anonymous * bind clears the previous bind). */ - rc = ldap_bind_s( lsc[ 0 ]->ld, lsc[ 0 ]->bound_dn->bv_val, + rc = ldap_bind_s( lsc[ 0 ]->ld, lsc[ 0 ]->bound_dn.bv_val, NULL, LDAP_AUTH_SIMPLE ); if ( rc != LDAP_SUCCESS ) { @@ -320,14 +320,14 @@ meta_back_dobind( struct metaconn *lc, Operation *op ) "meta_back_dobind: (anonymous)" " bind as \"%s\" failed" " with error \"%s\"\n", - lsc[ 0 ]->bound_dn->bv_val, + lsc[ 0 ]->bound_dn.bv_val, ldap_err2string( rc ) )); #else /* !NEW_LOGGING */ Debug( LDAP_DEBUG_ANY, "==>meta_back_dobind: (anonymous)" " bind as \"%s\" failed" " with error \"%s\"\n%s", - lsc[ 0 ]->bound_dn->bv_val, + lsc[ 0 ]->bound_dn.bv_val, ldap_err2string( rc ), "" ); #endif /* !NEW_LOGGING */ diff --git a/servers/slapd/back-meta/candidates.c b/servers/slapd/back-meta/candidates.c index a87dbfbdc4..4fb312dc08 100644 --- a/servers/slapd/back-meta/candidates.c +++ b/servers/slapd/back-meta/candidates.c @@ -242,9 +242,10 @@ meta_clear_one_candidate( lsc->ld = NULL; } - if ( lsc->bound_dn != NULL ) { - ber_bvfree( lsc->bound_dn ); - lsc->bound_dn = NULL; + if ( lsc->bound_dn.bv_val != NULL ) { + ber_memfree( lsc->bound_dn.bv_val ); + lsc->bound_dn.bv_val = NULL; + lsc->bound_dn.bv_len = 0; } return 0; diff --git a/servers/slapd/back-meta/conn.c b/servers/slapd/back-meta/conn.c index b0fbf8e7d8..c665a27165 100644 --- a/servers/slapd/back-meta/conn.c +++ b/servers/slapd/back-meta/conn.c @@ -276,26 +276,26 @@ init_one_conn( * If the connection dn is not null, an attempt to rewrite it is made */ if ( conn->c_cdn != 0 ) { - char *mdn = NULL; /* * Rewrite the bind dn if needed */ - lsc->bound_dn = NULL; + lsc->bound_dn.bv_val = NULL; switch ( rewrite_session( lt->rwinfo, "bindDn", - conn->c_cdn, conn, &mdn ) ) { + conn->c_cdn, conn, + &lsc->bound_dn.bv_val ) ) { case REWRITE_REGEXEC_OK: - if ( mdn == NULL ) { - lsc->bound_dn = ber_bvstrdup( conn->c_cdn ); + if ( lsc->bound_dn.bv_val == NULL ) { + ber_str2bv( conn->c_cdn, 0, 1, &lsc->bound_dn ); } #ifdef NEW_LOGGING LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1, "[rw] bindDn: \"%s\" -> \"%s\"\n", - conn->c_cdn, lsc->bound_dn->bv_val )); + conn->c_cdn, lsc->bound_dn.bv_val )); #else /* !NEW_LOGGING */ Debug( LDAP_DEBUG_ARGS, "rw> bindDn: \"%s\" -> \"%s\"\n", - conn->c_cdn, lsc->bound_dn->bv_val, 0 ); + conn->c_cdn, lsc->bound_dn.bv_val, 0 ); #endif /* !NEW_LOGGING */ break; @@ -314,14 +314,10 @@ init_one_conn( return LDAP_OPERATIONS_ERROR; } - if ( mdn ) { - lsc->bound_dn = ber_bvstr( mdn ); - } else { - lsc->bound_dn = ber_bvstrdup( "" ); - } + assert( lsc->bound_dn.bv_val ); } else { - lsc->bound_dn = ber_bvstrdup( "" ); + ber_str2bv( "", 0, 1, &lsc->bound_dn ); } lsc->bound = META_UNBOUND; diff --git a/servers/slapd/back-meta/init.c b/servers/slapd/back-meta/init.c index 1b63a0b746..a67429367e 100644 --- a/servers/slapd/back-meta/init.c +++ b/servers/slapd/back-meta/init.c @@ -164,8 +164,8 @@ conn_free( if ( lsc[ 0 ]->ld != NULL ) { ldap_unbind( lsc[ 0 ]->ld ); } - if ( lsc[ 0 ]->bound_dn ) { - ber_bvfree( lsc[ 0 ]->bound_dn ); + if ( lsc[ 0 ]->bound_dn.bv_val ) { + ber_memfree( lsc[ 0 ]->bound_dn.bv_val ); } free( lsc[ 0 ] ); } diff --git a/servers/slapd/back-monitor/init.c b/servers/slapd/back-monitor/init.c index 70bd84804c..56b3cb38b3 100644 --- a/servers/slapd/back-monitor/init.c +++ b/servers/slapd/back-monitor/init.c @@ -256,7 +256,7 @@ monitor_back_db_init( return -1; } - ber_bvecadd( &be->be_suffix, ber_bvdup( &dn ) ); + ber_bvecadd( &be->be_suffix, ber_dupbv( NULL, &dn ) ); ber_bvecadd( &be->be_nsuffix, ndn ); mi = ( struct monitorinfo * )ch_calloc( sizeof( struct monitorinfo ), 1 ); diff --git a/servers/slapd/schema_init.c b/servers/slapd/schema_init.c index b34bcb476e..4b49e541a5 100644 --- a/servers/slapd/schema_init.c +++ b/servers/slapd/schema_init.c @@ -222,38 +222,38 @@ nameUIDValidate( struct berval *in ) { int rc; - struct berval *dn; + struct berval dn; if( in->bv_len == 0 ) return LDAP_SUCCESS; - dn = ber_bvdup( in ); - if( !dn ) return LDAP_OTHER; + ber_dupbv( &dn, in ); + if( !dn.bv_val ) return LDAP_OTHER; - if( dn->bv_val[dn->bv_len-1] == 'B' - && dn->bv_val[dn->bv_len-2] == '\'' ) + if( dn.bv_val[dn.bv_len-1] == 'B' + && dn.bv_val[dn.bv_len-2] == '\'' ) { /* assume presence of optional UID */ ber_len_t i; - for(i=dn->bv_len-3; i>1; i--) { - if( dn->bv_val[i] != '0' && dn->bv_val[i] != '1' ) { + for(i=dn.bv_len-3; i>1; i--) { + if( dn.bv_val[i] != '0' && dn.bv_val[i] != '1' ) { break; } } - if( dn->bv_val[i] != '\'' || - dn->bv_val[i-1] != '#' ) { - ber_bvfree( dn ); + if( dn.bv_val[i] != '\'' || + dn.bv_val[i-1] != '#' ) { + ber_memfree( dn.bv_val ); return LDAP_INVALID_SYNTAX; } /* trim the UID to allow use of dnValidate */ - dn->bv_val[i-1] = '\0'; - dn->bv_len = i-1; + dn.bv_val[i-1] = '\0'; + dn.bv_len = i-1; } - rc = dnValidate( NULL, dn ); + rc = dnValidate( NULL, &dn ); - ber_bvfree( dn ); + ber_memfree( &dn ); return rc; } @@ -3575,7 +3575,7 @@ serial_and_issuer_parse( bv.bv_len = end-begin+1; bv.bv_val = begin; - *serial = ber_bvdup(&bv); + *serial = ber_dupbv(NULL, &bv); /* now extract the issuer, remember p was at the dollar sign */ begin = p+1; diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index 6226741198..13c932185d 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -1408,7 +1408,6 @@ typedef struct sasl_regexp { #define FLAG_GETDN_AUTHCID 2 #define FLAG_GETDN_AUTHZID 4 - LDAP_END_DECL #include "proto-slap.h"