From ec46a2f33a602c5603f1cf6415b183f6ff0939d5 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Sun, 6 Jan 2002 06:11:01 +0000 Subject: [PATCH] Use 'm' ber_scanf format where convenient --- servers/slapd/add.c | 6 ++---- servers/slapd/ava.c | 5 +---- servers/slapd/back-bdb/passwd.c | 8 -------- servers/slapd/back-ldap/search.c | 16 ++++------------ servers/slapd/back-ldbm/passwd.c | 8 -------- servers/slapd/back-meta/search.c | 14 ++++---------- servers/slapd/bind.c | 12 ++++-------- servers/slapd/compare.c | 10 ++++------ servers/slapd/delete.c | 3 +-- servers/slapd/filter.c | 13 +++---------- servers/slapd/modify.c | 5 ++--- servers/slapd/modrdn.c | 11 ++++------- servers/slapd/mods.c | 2 ++ servers/slapd/mra.c | 6 ++---- servers/slapd/passwd.c | 6 +++--- servers/slapd/search.c | 8 ++------ 16 files changed, 38 insertions(+), 95 deletions(-) diff --git a/servers/slapd/add.c b/servers/slapd/add.c index e1ad469d70..e167eb5b1a 100644 --- a/servers/slapd/add.c +++ b/servers/slapd/add.c @@ -66,7 +66,7 @@ do_add( Connection *conn, Operation *op ) */ /* get the name */ - if ( ber_scanf( ber, "{o", /*}*/ &dn ) == LBER_ERROR ) { + if ( ber_scanf( ber, "{m", /*}*/ &dn ) == LBER_ERROR ) { #ifdef NEW_LOGGING LDAP_LOG(( "operation", LDAP_LEVEL_ERR, "do_add: conn %d ber_scanf failed\n", conn->c_connid )); @@ -114,7 +114,7 @@ do_add( Connection *conn, Operation *op ) { Modifications *mod; - rc = ber_scanf( ber, "{o{W}}", &tmp.sml_type, &tmp.sml_bvalues ); + rc = ber_scanf( ber, "{m{W}}", &tmp.sml_type, &tmp.sml_bvalues ); if ( rc == LBER_ERROR ) { #ifdef NEW_LOGGING @@ -324,8 +324,6 @@ do_add( Connection *conn, Operation *op ) } done: - free( dn.bv_val ); - if( modlist != NULL ) { slap_mods_free( modlist ); } diff --git a/servers/slapd/ava.c b/servers/slapd/ava.c index 0d96d8bc59..c9c2c1fee9 100644 --- a/servers/slapd/ava.c +++ b/servers/slapd/ava.c @@ -39,7 +39,7 @@ get_ava( struct berval type, value; AttributeAssertion *aa; - rc = ber_scanf( ber, "{oo}", &type, &value ); + rc = ber_scanf( ber, "{mm}", &type, &value ); if( rc == LBER_ERROR ) { #ifdef NEW_LOGGING @@ -57,16 +57,13 @@ get_ava( aa->aa_value.bv_val = NULL; rc = slap_bv2ad( &type, &aa->aa_desc, text ); - ch_free( type.bv_val ); if( rc != LDAP_SUCCESS ) { - ch_free( value.bv_val ); ch_free( aa ); return rc; } rc = value_normalize( aa->aa_desc, usage, &value, &aa->aa_value, text ); - ch_free( value.bv_val ); if( rc != LDAP_SUCCESS ) { ch_free( aa ); diff --git a/servers/slapd/back-bdb/passwd.c b/servers/slapd/back-bdb/passwd.c index c39649bfea..df9223d4d2 100644 --- a/servers/slapd/back-bdb/passwd.c +++ b/servers/slapd/back-bdb/passwd.c @@ -214,14 +214,6 @@ done: bdb_entry_return( be, e ); } - if( id.bv_val != NULL ) { - free( id.bv_val ); - } - - if( new.bv_val != NULL ) { - free( new.bv_val ); - } - if( hash.bv_val != NULL ) { free( hash.bv_val ); } diff --git a/servers/slapd/back-ldap/search.c b/servers/slapd/back-ldap/search.c index def4edbbde..69cb449636 100644 --- a/servers/slapd/back-ldap/search.c +++ b/servers/slapd/back-ldap/search.c @@ -379,7 +379,7 @@ ldap_send_entry( struct berval *bv, bdn; const char *text; - if ( ber_scanf( &ber, "{o{", &bdn ) == LBER_ERROR ) { + if ( ber_scanf( &ber, "{m{", &bdn ) == LBER_ERROR ) { return; } #ifdef ENABLE_REWRITE @@ -392,7 +392,6 @@ ldap_send_entry( case REWRITE_REGEXEC_OK: if ( ent.e_name.bv_val == NULL ) { ent.e_name = bdn; - } else { #ifdef NEW_LOGGING LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1, @@ -402,8 +401,6 @@ ldap_send_entry( Debug( LDAP_DEBUG_ARGS, "rw> searchResult: \"%s\"" " -> \"%s\"\n%s", bdn.bv_val, ent.e_dn, "" ); #endif /* !NEW_LOGGING */ - free( bdn.bv_val ); - bdn.bv_val = NULL; ent.e_name.bv_len = strlen( ent.e_name.bv_val ); } break; @@ -422,11 +419,8 @@ ldap_send_entry( ent.e_private = 0; attrp = &ent.e_attrs; - while ( ber_scanf( &ber, "{o", &a ) != LBER_ERROR ) { + while ( ber_scanf( &ber, "{m", &a ) != LBER_ERROR ) { ldap_back_map(&li->at_map, &a, &mapped, 1); - if ( mapped.bv_val != a.bv_val) { - free( a.bv_val ); - } if (mapped.bv_val == NULL) continue; attr = (Attribute *)ch_malloc( sizeof(Attribute) ); @@ -474,7 +468,7 @@ ldap_send_entry( attr->a_vals[last].bv_val = NULL; i--; } else if ( mapped.bv_val != bv->bv_val ) { - ch_free(bv->bv_val); + free(bv->bv_val); ber_dupbv( bv, &mapped ); } } @@ -520,7 +514,6 @@ ldap_send_entry( attr->a_desc->ad_type->sat_cname.bv_val, bv->bv_val, newval ); #endif /* !NEW_LOGGING */ - free( bv->bv_val ); bv->bv_val = newval; bv->bv_len = strlen( newval ); @@ -553,9 +546,8 @@ ldap_send_entry( free(attr); } - if ( ent.e_dn ) + if ( ent.e_dn && ent.e_dn != bdn.bv_val ) free( ent.e_dn ); if ( ent.e_ndn ) free( ent.e_ndn ); } - diff --git a/servers/slapd/back-ldbm/passwd.c b/servers/slapd/back-ldbm/passwd.c index 0b8dac84a0..7304ae8874 100644 --- a/servers/slapd/back-ldbm/passwd.c +++ b/servers/slapd/back-ldbm/passwd.c @@ -175,14 +175,6 @@ done: cache_return_entry_w( &li->li_cache, e ); } - if( id.bv_val != NULL ) { - free( id.bv_val ); - } - - if( new.bv_val != NULL ) { - free( new.bv_val ); - } - if( hash.bv_val != NULL ) { free( hash.bv_val ); } diff --git a/servers/slapd/back-meta/search.c b/servers/slapd/back-meta/search.c index 0cab9aec93..e475548757 100644 --- a/servers/slapd/back-meta/search.c +++ b/servers/slapd/back-meta/search.c @@ -588,7 +588,7 @@ meta_send_entry( struct berval *bv, bdn; const char *text; - if ( ber_scanf( &ber, "{o{", &bdn ) == LBER_ERROR ) { + if ( ber_scanf( &ber, "{m{", &bdn ) == LBER_ERROR ) { return; } @@ -611,8 +611,6 @@ meta_send_entry( Debug( LDAP_DEBUG_ARGS, "rw> searchResult[%d]: \"%s\"" " -> \"%s\"\n", target, bdn.bv_val, ent.e_name.bv_val ); #endif /* !NEW_LOGGING */ - free( bdn.bv_val ); - bdn.bv_val = NULL; ent.e_name.bv_len = strlen( ent.e_name.bv_val ); } break; @@ -638,12 +636,9 @@ meta_send_entry( ent.e_private = 0; attrp = &ent.e_attrs; - while ( ber_scanf( &ber, "{o", &a ) != LBER_ERROR ) { + while ( ber_scanf( &ber, "{m", &a ) != LBER_ERROR ) { ldap_back_map( &li->targets[ target ]->at_map, &a, &mapped, 1 ); - if ( mapped.bv_val != a.bv_val ) { - free( a.bv_val ); - } if ( mapped.bv_val == NULL ) { continue; } @@ -697,7 +692,7 @@ meta_send_entry( i--; } else if ( mapped.bv_val != bv->bv_val ) { - ch_free( bv->bv_val ); + free( bv->bv_val ); ber_dupbv( bv, &mapped ); } } @@ -742,7 +737,6 @@ meta_send_entry( attr->a_desc->ad_type->sat_cname.bv_val, bv->bv_val, newval ); #endif /* !NEW_LOGGING */ - free( bv->bv_val ); bv->bv_val = newval; bv->bv_len = strlen( newval ); @@ -774,7 +768,7 @@ meta_send_entry( free( attr ); } - if ( ent.e_dn ) { + if ( ent.e_dn && ent.e_dn != bdn.bv_val ) { free( ent.e_dn ); } if ( ent.e_ndn ) { diff --git a/servers/slapd/bind.c b/servers/slapd/bind.c index ac42ed06de..072f812abd 100644 --- a/servers/slapd/bind.c +++ b/servers/slapd/bind.c @@ -92,7 +92,7 @@ do_bind( * } */ - tag = ber_scanf( ber, "{iot" /*}*/, &version, &dn, &method ); + tag = ber_scanf( ber, "{imt" /*}*/, &version, &dn, &method ); if ( tag == LBER_ERROR ) { #ifdef NEW_LOGGING @@ -110,7 +110,7 @@ do_bind( op->o_protocol = version; if( method != LDAP_AUTH_SASL ) { - tag = ber_scanf( ber, /*{*/ "o}", &cred ); + tag = ber_scanf( ber, /*{*/ "m}", &cred ); } else { tag = ber_scanf( ber, "{a" /*}*/, &mech ); @@ -120,7 +120,7 @@ do_bind( tag = ber_peek_tag( ber, &len ); if ( tag == LDAP_TAG_LDAPCRED ) { - tag = ber_scanf( ber, "o", &cred ); + tag = ber_scanf( ber, "m", &cred ); } else { tag = LDAP_TAG_LDAPCRED; cred.bv_val = NULL; @@ -249,7 +249,7 @@ do_bind( goto cleanup; } - if( mech == NULL || *mech == '\0' ) { + if( mech == NULL || mech[0] == '\0' ) { #ifdef NEW_LOGGING LDAP_LOG(( "operation", LDAP_LEVEL_INFO, "do_bind: conn %d no SASL mechanism provided\n", @@ -536,7 +536,6 @@ do_bind( } cleanup: - free( dn.bv_val ); if( pdn.bv_val != NULL ) { free( pdn.bv_val ); } @@ -546,9 +545,6 @@ cleanup: if ( mech != NULL ) { free( mech ); } - if ( cred.bv_val != NULL ) { - free( cred.bv_val ); - } return rc; } diff --git a/servers/slapd/compare.c b/servers/slapd/compare.c index 001b0447ca..f1e88345d6 100644 --- a/servers/slapd/compare.c +++ b/servers/slapd/compare.c @@ -41,7 +41,7 @@ do_compare( struct berval ndn = { 0, NULL }; struct berval desc = { 0, NULL }; struct berval value = { 0, NULL }; - AttributeAssertion ava; + AttributeAssertion ava = { 0 }; Backend *be; int rc = LDAP_SUCCESS; const char *text = NULL; @@ -67,7 +67,7 @@ do_compare( * } */ - if ( ber_scanf( op->o_ber, "{o" /*}*/, &dn ) == LBER_ERROR ) { + if ( ber_scanf( op->o_ber, "{m" /*}*/, &dn ) == LBER_ERROR ) { #ifdef NEW_LOGGING LDAP_LOG(( "operation", LDAP_LEVEL_ERR, "do_compare: conn %d ber_scanf failed\n", conn->c_connid )); @@ -79,7 +79,7 @@ do_compare( return SLAPD_DISCONNECT; } - if ( ber_scanf( op->o_ber, "{oo}", &desc, &value ) == LBER_ERROR ) { + if ( ber_scanf( op->o_ber, "{mm}", &desc, &value ) == LBER_ERROR ) { #ifdef NEW_LOGGING LDAP_LOG(( "operation", LDAP_LEVEL_ERR, "do_compare: conn %d get ava failed\n", conn->c_connid )); @@ -274,11 +274,9 @@ do_compare( } cleanup: - free( dn.bv_val ); free( pdn.bv_val ); free( ndn.bv_val ); - free( desc.bv_val ); - free( value.bv_val ); + if ( ava.aa_value.bv_val ) free( ava.aa_value.bv_val ); return rc; } diff --git a/servers/slapd/delete.c b/servers/slapd/delete.c index 610ed0e786..362f1b915a 100644 --- a/servers/slapd/delete.c +++ b/servers/slapd/delete.c @@ -52,7 +52,7 @@ do_delete( * DelRequest := DistinguishedName */ - if ( ber_scanf( op->o_ber, "o", &dn ) == LBER_ERROR ) { + if ( ber_scanf( op->o_ber, "m", &dn ) == LBER_ERROR ) { #ifdef NEW_LOGGING LDAP_LOG(( "operation", LDAP_LEVEL_ERR, "do_delete: conn: %d ber_scanf failed\n", conn->c_connid )); @@ -197,7 +197,6 @@ do_delete( } cleanup: - free( dn.bv_val ); free( pdn.bv_val ); free( ndn.bv_val ); return rc; diff --git a/servers/slapd/filter.c b/servers/slapd/filter.c index 2b4544cbc0..b31be2c09a 100644 --- a/servers/slapd/filter.c +++ b/servers/slapd/filter.c @@ -204,7 +204,7 @@ get_filter( #else Debug( LDAP_DEBUG_FILTER, "PRESENT\n", 0, 0, 0 ); #endif - if ( ber_scanf( ber, "o", &type ) == LBER_ERROR ) { + if ( ber_scanf( ber, "m", &type ) == LBER_ERROR ) { err = SLAPD_DISCONNECT; *text = "error decoding filter"; break; @@ -219,13 +219,10 @@ get_filter( f->f_result = LDAP_COMPARE_FALSE; ber_str2bv("(unrecognized=*)", sizeof("(unrecognized=*)")-1, 1, fstr); - ch_free( type.bv_val ); err = LDAP_SUCCESS; break; } - ch_free( type.bv_val ); - fstr->bv_len = sizeof("(=*)") - 1 + f->f_desc->ad_cname.bv_len; fstr->bv_val = ch_malloc( fstr->bv_len + 1); @@ -467,7 +464,7 @@ get_substring_filter( #else Debug( LDAP_DEBUG_FILTER, "begin get_substring_filter\n", 0, 0, 0 ); #endif - if ( ber_scanf( ber, "{o" /*}*/, &bv ) == LBER_ERROR ) { + if ( ber_scanf( ber, "{m" /*}*/, &bv ) == LBER_ERROR ) { return SLAPD_DISCONNECT; } @@ -475,8 +472,6 @@ get_substring_filter( f->f_sub_desc = NULL; rc = slap_bv2ad( &bv, &f->f_sub_desc, text ); - ch_free( bv.bv_val ); - if( rc != LDAP_SUCCESS ) { text = NULL; ch_free( f->f_sub ); @@ -500,7 +495,7 @@ get_substring_filter( { unsigned usage; - rc = ber_scanf( ber, "o", &value ); + rc = ber_scanf( ber, "m", &value ); if ( rc == LBER_ERROR ) { rc = SLAPD_DISCONNECT; goto return_error; @@ -536,12 +531,10 @@ get_substring_filter( " unknown substring choice=%ld\n", (long) tag, 0, 0 ); #endif - free( value.bv_val ); goto return_error; } rc = value_normalize( f->f_sub_desc, usage, &value, &bv, text ); - free( value.bv_val ); if( rc != LDAP_SUCCESS ) { goto return_error; diff --git a/servers/slapd/modify.c b/servers/slapd/modify.c index b46a19aaf6..3262b5337a 100644 --- a/servers/slapd/modify.c +++ b/servers/slapd/modify.c @@ -75,7 +75,7 @@ do_modify( * } */ - if ( ber_scanf( op->o_ber, "{o" /*}*/, &dn ) == LBER_ERROR ) { + if ( ber_scanf( op->o_ber, "{m" /*}*/, &dn ) == LBER_ERROR ) { #ifdef NEW_LOGGING LDAP_LOG(( "operation", LDAP_LEVEL_ERR, "do_modify: ber_scanf failed\n" )); @@ -106,7 +106,7 @@ do_modify( Modifications tmp, *mod; - if ( ber_scanf( op->o_ber, "{i{o[W]}}", &mop, + if ( ber_scanf( op->o_ber, "{i{m[W]}}", &mop, &tmp.sml_type, &tmp.sml_bvalues ) == LBER_ERROR ) { @@ -395,7 +395,6 @@ do_modify( } cleanup: - free( dn.bv_val ); free( pdn.bv_val ); free( ndn.bv_val ); if ( modlist != NULL ) diff --git a/servers/slapd/modrdn.c b/servers/slapd/modrdn.c index ba85f247dd..60889b7a54 100644 --- a/servers/slapd/modrdn.c +++ b/servers/slapd/modrdn.c @@ -83,7 +83,7 @@ do_modrdn( * } */ - if ( ber_scanf( op->o_ber, "{oob", &dn, &newrdn, &deloldrdn ) + if ( ber_scanf( op->o_ber, "{mmb", &dn, &newrdn, &deloldrdn ) == LBER_ERROR ) { #ifdef NEW_LOGGING @@ -120,14 +120,14 @@ do_modrdn( goto cleanup; } - if ( ber_scanf( op->o_ber, "o", &newSuperior ) + if ( ber_scanf( op->o_ber, "m", &newSuperior ) == LBER_ERROR ) { #ifdef NEW_LOGGING LDAP_LOG(( "operation", LDAP_LEVEL_ERR, - "do_modrdn: ber_scanf(\"a\") failed\n" )); + "do_modrdn: ber_scanf(\"m\") failed\n" )); #else - Debug( LDAP_DEBUG_ANY, "ber_scanf(\"a\") failed\n", + Debug( LDAP_DEBUG_ANY, "ber_scanf(\"m\") failed\n", 0, 0, 0 ); #endif @@ -375,15 +375,12 @@ do_modrdn( } cleanup: - free( dn.bv_val ); free( pdn.bv_val ); free( ndn.bv_val ); - free( newrdn.bv_val ); free( pnewrdn.bv_val ); free( nnewrdn.bv_val ); - if ( newSuperior.bv_val ) free( newSuperior.bv_val ); if ( pnewSuperior.bv_val ) free( pnewSuperior.bv_val ); if ( nnewSuperior.bv_val ) free( nnewSuperior.bv_val ); diff --git a/servers/slapd/mods.c b/servers/slapd/mods.c index 3f7772fdfe..b2d9566c83 100644 --- a/servers/slapd/mods.c +++ b/servers/slapd/mods.c @@ -24,8 +24,10 @@ slap_mod_free( int freeit ) { +#if 0 if ( mod->sm_type.bv_val) free( mod->sm_type.bv_val ); +#endif if ( mod->sm_bvalues != NULL ) bvarray_free( mod->sm_bvalues ); diff --git a/servers/slapd/mra.c b/servers/slapd/mra.c index 1c650bc7ac..98bf139ddb 100644 --- a/servers/slapd/mra.c +++ b/servers/slapd/mra.c @@ -96,7 +96,7 @@ get_mra( } if ( tag == LDAP_FILTER_EXT_TYPE ) { - rc = ber_scanf( ber, "o", &type ); + rc = ber_scanf( ber, "m", &type ); if ( rc == LBER_ERROR ) { #ifdef NEW_LOGGING LDAP_LOG(( "operation", LDAP_LEVEL_ERR, @@ -110,7 +110,6 @@ get_mra( } rc = slap_bv2ad( &type, &ma->ma_desc, text ); - ch_free( type.bv_val ); if( rc != LDAP_SUCCESS ) { mra_free( ma, 1 ); @@ -146,7 +145,7 @@ get_mra( return SLAPD_DISCONNECT; } - rc = ber_scanf( ber, "o", &value ); + rc = ber_scanf( ber, "m", &value ); if( rc == LBER_ERROR ) { #ifdef NEW_LOGGING @@ -166,7 +165,6 @@ get_mra( * normalize for the matching rule. */ rc = value_normalize( ma->ma_desc, SLAP_MR_EQUALITY, &value, &ma->ma_value, text ); - ch_free( value.bv_val ); if( rc != LDAP_SUCCESS ) { mra_free( ma, 1 ); diff --git a/servers/slapd/passwd.c b/servers/slapd/passwd.c index e9f44db6a0..0c898771ec 100644 --- a/servers/slapd/passwd.c +++ b/servers/slapd/passwd.c @@ -116,7 +116,7 @@ int slap_passwd_parse( struct berval *reqdata, goto done; } - tag = ber_scanf( ber, "o", id ); + tag = ber_scanf( ber, "m", id ); if( tag == LBER_ERROR ) { #ifdef NEW_LOGGING @@ -148,7 +148,7 @@ int slap_passwd_parse( struct berval *reqdata, goto done; } - tag = ber_scanf( ber, "o", oldpass ); + tag = ber_scanf( ber, "m", oldpass ); if( tag == LBER_ERROR ) { #ifdef NEW_LOGGING @@ -180,7 +180,7 @@ int slap_passwd_parse( struct berval *reqdata, goto done; } - tag = ber_scanf( ber, "o", newpass ); + tag = ber_scanf( ber, "m", newpass ); if( tag == LBER_ERROR ) { #ifdef NEW_LOGGING diff --git a/servers/slapd/search.c b/servers/slapd/search.c index c3ce4bd9c9..75795eaabf 100644 --- a/servers/slapd/search.c +++ b/servers/slapd/search.c @@ -76,7 +76,7 @@ do_search( */ /* baseObject, scope, derefAliases, sizelimit, timelimit, attrsOnly */ - if ( ber_scanf( op->o_ber, "{oiiiib" /*}*/, + if ( ber_scanf( op->o_ber, "{miiiib" /*}*/, &base, &scope, &deref, &sizelimit, &timelimit, &attrsonly ) == LBER_ERROR ) { @@ -159,7 +159,7 @@ do_search( /* attributes */ siz = sizeof(AttributeName); off = 0; - if ( ber_scanf( op->o_ber, "{w}}", &an, &siz, off ) == LBER_ERROR ) { + if ( ber_scanf( op->o_ber, "{M}}", &an, &siz, off ) == LBER_ERROR ) { send_ldap_disconnect( conn, op, LDAP_PROTOCOL_ERROR, "decoding attrs error" ); rc = SLAPD_DISCONNECT; @@ -324,15 +324,11 @@ do_search( } return_results:; - free( base.bv_val ); if( pbase.bv_val != NULL) free( pbase.bv_val ); if( nbase.bv_val != NULL) free( nbase.bv_val ); if( fstr.bv_val != NULL) free( fstr.bv_val ); if( filter != NULL) filter_free( filter ); - for (i = 0; i