From: Howard Chu Date: Fri, 12 Sep 2003 18:52:34 +0000 (+0000) Subject: Construct ctxcsn entries directly, plug memory leaks, remove X-Git-Tag: OPENLDAP_REL_ENG_2_1_MP~736 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=72adc38cdfa4e4f42e0d5c8db70fff921c529c6f;p=openldap Construct ctxcsn entries directly, plug memory leaks, remove dependency on slap_mods_check and slap_mods2entry --- diff --git a/servers/slapd/back-bdb/ctxcsn.c b/servers/slapd/back-bdb/ctxcsn.c index a222d0ff1a..ddd908499e 100644 --- a/servers/slapd/back-bdb/ctxcsn.c +++ b/servers/slapd/back-bdb/ctxcsn.c @@ -44,7 +44,6 @@ bdb_csn_commit( ) { struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private; - struct berval ctxcsn_rdn = { 0, NULL }; struct berval ctxcsn_ndn = { 0, NULL }; EntryInfo *ctxcsn_ei = NULL; DB_LOCK ctxcsn_lock; @@ -55,17 +54,14 @@ bdb_csn_commit( Entry *e; char textbuf[SLAP_TEXT_BUFLEN]; size_t textlen = sizeof textbuf; - Modifications *ml, *mlnext, *mod, *modlist; - Modifications **modtail = &modlist; - struct berval *csnbva = NULL; EntryInfo *eip = NULL; if ( ei ) { e = ei->bei_e; } - ber_str2bv( "cn=ldapsync", strlen("cn=ldapsync"), 0, &ctxcsn_rdn ); - build_new_dn( &ctxcsn_ndn, &op->o_bd->be_nsuffix[0], &ctxcsn_rdn ); + build_new_dn( &ctxcsn_ndn, &op->o_bd->be_nsuffix[0], + (struct berval *)&slap_ldapsync_cn_bv ); rc = bdb_dn2entry( op, tid, &ctxcsn_ndn, &ctxcsn_ei, 1, locker, &ctxcsn_lock ); @@ -88,31 +84,24 @@ bdb_csn_commit( ber_bvfree( max_committed_csn ); return BDB_CSN_ABORT; } else { - csnbva = ( struct berval * ) ch_calloc( 2, sizeof( struct berval )); - ber_dupbv( &csnbva[0], max_committed_csn ); - mod = (Modifications *) ch_calloc( 1, sizeof( Modifications )); - mod->sml_op = LDAP_MOD_REPLACE; - ber_str2bv( "contextCSN", strlen("contextCSN"), 1, &mod->sml_type ); - mod->sml_bvalues = csnbva; - *modtail = mod; - modtail = &mod->sml_next; + Modifications mod; + struct berval modvals[2]; - ret = slap_mods_check( modlist, 1, &rs->sr_text, textbuf, textlen, NULL ); + modvals[0] = *max_committed_csn; + modvals[1].bv_val = NULL; + modvals[1].bv_len = 0; - if ( ret != LDAP_SUCCESS ) { -#ifdef NEW_LOGGING - LDAP_LOG( OPERATION, ERR, - "bdb_csn_commit: mods check (%s)\n", rs->sr_text, 0, 0 ); -#else - Debug( LDAP_DEBUG_ANY, - "bdb_csn_commit: mods check (%s)\n", rs->sr_text, 0, 0 ); -#endif - } + mod.sml_op = LDAP_MOD_REPLACE; + mod.sml_bvalues = modvals; + mod.sml_desc = slap_schema.si_ad_contextCSN; + mod.sml_type = mod.sml_desc->ad_cname; + mod.sml_next = NULL; bdb_cache_entry_db_relock( bdb->bi_dbenv, locker, ctxcsn_ei, 1, 0, &ctxcsn_lock ); - ret = bdb_modify_internal( op, tid, modlist, *ctxcsn_e, + ret = bdb_modify_internal( op, tid, &mod, *ctxcsn_e, &rs->sr_text, textbuf, textlen ); + ber_bvfree( max_committed_csn ); if ( ret != LDAP_SUCCESS ) { #ifdef NEW_LOGGING LDAP_LOG ( OPERATION, ERR, @@ -130,11 +119,6 @@ bdb_csn_commit( } } - for ( ml = modlist; ml != NULL; ml = mlnext ) { - mlnext = ml->sml_next; - free( ml ); - } - ret = bdb_id2entry_update( op->o_bd, tid, *ctxcsn_e ); switch ( ret ) { case 0 : diff --git a/servers/slapd/ctxcsn.c b/servers/slapd/ctxcsn.c index c74c14f096..3a6127d916 100644 --- a/servers/slapd/ctxcsn.c +++ b/servers/slapd/ctxcsn.c @@ -110,139 +110,47 @@ slap_graduate_commit_csn( Operation *op ) return; } +static struct berval ocbva[] = { + BER_BVC("top"), + BER_BVC("subentry"), + BER_BVC("syncProviderSubentry"), + {0,NULL} +}; + Entry * slap_create_context_csn_entry( Backend *be, struct berval *context_csn ) { - Modifications *ml; - Modifications *mlnext; - Modifications *mod; - Modifications *modlist; - Modifications **modtail = &modlist; - - struct berval* ocbva = NULL; - struct berval* socbva = NULL; - struct berval* cnbva = NULL; - struct berval* ssbva = NULL; - struct berval* scbva = NULL; - - char substr[64]; - char rdnstr[67]; - const char *text; - char txtbuf[SLAP_TEXT_BUFLEN]; - size_t textlen = sizeof txtbuf; - Entry* e; int rc; - struct berval sub_bv = { 0, NULL }; - struct berval psubrdn = { 0, NULL }; - - slap_callback cb; - SlapReply rs = {REP_RESULT}; - - struct berval rdn = { 0, NULL }; - int match = 0; - char *def_filter_str = NULL; - - ocbva = ( struct berval * ) ch_calloc( 4, sizeof( struct berval )); - socbva = ( struct berval * ) ch_calloc( 2, sizeof( struct berval )); - cnbva = ( struct berval * ) ch_calloc( 2, sizeof( struct berval )); - ssbva = ( struct berval * ) ch_calloc( 2, sizeof( struct berval )); - scbva = ( struct berval * ) ch_calloc( 2, sizeof( struct berval )); - - ber_str2bv( "top", strlen("top"), 1, &ocbva[0] ); - ber_str2bv( "subentry", strlen("subentry"), 1, &ocbva[1] ); - ber_str2bv( "syncProviderSubentry", - strlen("syncProviderSubentry"), 1, &ocbva[2] ); - - mod = (Modifications *) ch_calloc( 1, sizeof( Modifications )); - mod->sml_op = LDAP_MOD_REPLACE; - ber_str2bv( "objectClass", strlen("objectClass"), 1, &mod->sml_type ); - mod->sml_bvalues = ocbva; - *modtail = mod; - modtail = &mod->sml_next; - - ber_str2bv( "subentry", - strlen("subentry"), 1, &socbva[0] ); - - mod = (Modifications *) ch_calloc( 1, sizeof( Modifications )); - mod->sml_op = LDAP_MOD_REPLACE; - ber_str2bv( "structuralObjectClass", strlen("structuralObjectClass"), 1, &mod->sml_type ); - mod->sml_bvalues = socbva; - *modtail = mod; - modtail = &mod->sml_next; - - sprintf( substr, "ldapsync" ); - sprintf( rdnstr, "cn=%s", substr ); - ber_str2bv( substr, strlen( substr ), 1, &cnbva[0] ); - ber_str2bv( rdnstr, strlen( rdnstr ), 1, &psubrdn ); - mod = (Modifications *) ch_calloc( 1, sizeof( Modifications )); - mod->sml_op = LDAP_MOD_REPLACE; - ber_str2bv( "cn", strlen("cn"), 1, &mod->sml_type ); - mod->sml_bvalues = cnbva; - *modtail = mod; - modtail = &mod->sml_next; - - if ( context_csn ) { - ber_dupbv( &scbva[0], context_csn ); - mod = (Modifications *) ch_calloc( 1, sizeof( Modifications )); - mod->sml_op = LDAP_MOD_REPLACE; - ber_str2bv( "contextCSN", strlen("contextCSN"), 1, &mod->sml_type ); - mod->sml_bvalues = scbva; - *modtail = mod; - modtail = &mod->sml_next; - } - - ber_str2bv( "{}", strlen("{}"), 1, &ssbva[0] ); - mod = (Modifications *) ch_calloc( 1, sizeof( Modifications )); - mod->sml_op = LDAP_MOD_REPLACE; - ber_str2bv( "subtreeSpecification", - strlen("subtreeSpecification"), 1, &mod->sml_type ); - mod->sml_bvalues = ssbva; - *modtail = mod; - modtail = &mod->sml_next; - - rc = slap_mods_check( modlist, 1, &text, txtbuf, textlen, NULL ); - - if ( rc != LDAP_SUCCESS ) { -#ifdef NEW_LOGGING - LDAP_LOG( OPERATION, ERR, - "create_context_csn_entry: mods check (%s)\n", text, 0, 0 ); -#else - Debug( LDAP_DEBUG_ANY, "create_context_csn_entry: mods check (%s)\n", - text, 0, 0 ); -#endif - } + struct berval bv; e = ( Entry * ) ch_calloc( 1, sizeof( Entry )); - build_new_dn( &sub_bv, &be->be_nsuffix[0], &psubrdn ); - dnPrettyNormal( NULL, &sub_bv, &e->e_name, &e->e_nname, NULL ); - ch_free( sub_bv.bv_val ); - ch_free( psubrdn.bv_val ); + attr_merge( e, slap_schema.si_ad_objectClass, ocbva, NULL ); - e->e_attrs = NULL; + bv.bv_val = "subentry"; + bv.bv_len = sizeof("subentry")-1; - rc = slap_mods2entry( modlist, &e, 1, 1, &text, txtbuf, textlen ); + attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &bv, NULL ); - if( rc != LDAP_SUCCESS ) { -#ifdef NEW_LOGGING - LDAP_LOG( OPERATION, ERR, - "create_context_csn_entry: mods2entry (%s)\n", text, 0, 0 ); -#else - Debug( LDAP_DEBUG_ANY, "create_context_csn_entry: mods2entry (%s)\n", - text, 0, 0 ); -#endif - } + attr_merge_one( e, slap_schema.si_ad_cn, &slap_ldapsync_bv, NULL ); - for ( ml = modlist; ml != NULL; ml = mlnext ) { - mlnext = ml->sml_next; - free( ml ); + if ( context_csn ) { + attr_merge_one( e, slap_schema.si_ad_contextCSN, + context_csn, NULL ); } + bv.bv_val = "{}"; + bv.bv_len = sizeof("{}")-1; + attr_merge_one( e, slap_schema.si_ad_subtreeSpecification, &bv, NULL ); + + build_new_dn( &e->e_name, &be->be_nsuffix[0], &slap_ldapsync_cn_bv ); + ber_dupbv( &e->e_name, &e->e_nname ); + return e; } diff --git a/servers/slapd/globals.c b/servers/slapd/globals.c index 6176244710..f21065908f 100644 --- a/servers/slapd/globals.c +++ b/servers/slapd/globals.c @@ -26,3 +26,6 @@ const struct berval slap_unknown_bv = BER_BVC("unknown"); const struct berval slap_true_bv = BER_BVC("TRUE"); const struct berval slap_false_bv = BER_BVC("FALSE"); +/* ldapsync items */ +const struct berval slap_ldapsync_bv = BER_BVC("ldapsync"); +const struct berval slap_ldapsync_cn_bv = BER_BVC("cn=ldapsync"); diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index 4118782c21..ef1afa7cd7 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -532,6 +532,8 @@ LDAP_SLAPD_V( const struct berval ) slap_empty_bv; LDAP_SLAPD_V( const struct berval ) slap_unknown_bv; LDAP_SLAPD_V( const struct berval ) slap_true_bv; LDAP_SLAPD_V( const struct berval ) slap_false_bv; +LDAP_SLAPD_V( const struct berval ) slap_ldapsync_bv; +LDAP_SLAPD_V( const struct berval ) slap_ldapsync_cn_bv; /* * index.c diff --git a/servers/slapd/tools/Makefile.in b/servers/slapd/tools/Makefile.in index f0cac09139..dbddeb02c0 100644 --- a/servers/slapd/tools/Makefile.in +++ b/servers/slapd/tools/Makefile.in @@ -46,7 +46,7 @@ SLAPD_OBJS = ../globals.o ../config.o ../ch_malloc.o ../cr.o ../backend.o \ ../init.o ../controls.o ../kerberos.o ../passwd.o \ ../index.o ../extended.o ../starttls.o ../sets.o ../mra.o \ ../referral.o ../backglue.o ../oidm.o ../mods.o ../operation.o \ - ../cancel.o ../sl_malloc.o ../backover.o ../ctxcsn.o ../add.o ../modify.o + ../cancel.o ../sl_malloc.o ../backover.o ../ctxcsn.o SLAPOBJS = $(SLAPD_OBJS) slapcommon.o mimic.o