From ce4b199485de98e563c58e6b7318af3d6dfba06f Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Wed, 22 Oct 2003 05:19:30 +0000 Subject: [PATCH] Syncrepl code cleanup (namely prefix struct field names) --- servers/slapd/add.c | 12 +- servers/slapd/back-bdb/add.c | 4 +- servers/slapd/back-bdb/ctxcsn.c | 16 +- servers/slapd/back-bdb/delete.c | 17 +- servers/slapd/back-bdb/modify.c | 14 +- servers/slapd/back-bdb/modrdn.c | 17 +- servers/slapd/back-ldbm/delete.c | 7 +- servers/slapd/back-ldbm/modify.c | 7 +- servers/slapd/back-ldbm/modrdn.c | 7 +- servers/slapd/back-meta/cache-merge.c | 2 +- servers/slapd/backend.c | 17 +- servers/slapd/config.c | 234 ++++++++------- servers/slapd/delete.c | 11 +- servers/slapd/modify.c | 8 +- servers/slapd/modrdn.c | 12 +- servers/slapd/passwd.c | 4 +- servers/slapd/slap.h | 91 +++--- servers/slapd/syncrepl.c | 402 ++++++++++++++------------ 18 files changed, 469 insertions(+), 413 deletions(-) diff --git a/servers/slapd/add.c b/servers/slapd/add.c index dd8dcb7ac5..cc18e3fc3c 100644 --- a/servers/slapd/add.c +++ b/servers/slapd/add.c @@ -244,10 +244,10 @@ do_add( Operation *op, SlapReply *rs ) /* do the update here */ int repl_user = be_isupdate(op->o_bd, &op->o_ndn ); #ifndef SLAPD_MULTIMASTER - if ( !op->o_bd->syncinfo && - ( !op->o_bd->be_update_ndn.bv_len || repl_user )) + if ( !op->o_bd->be_syncinfo && + ( !op->o_bd->be_update_ndn.bv_len || repl_user )) #else - if ( !op->o_bd->syncinfo ) + if ( !op->o_bd->be_syncinfo ) #endif { int update = op->o_bd->be_update_ndn.bv_len; @@ -324,11 +324,11 @@ do_add( Operation *op, SlapReply *rs ) } #endif /* LDAP_SLAPI */ - if ( op->o_bd->syncinfo ) { - defref = op->o_bd->syncinfo->provideruri_bv; + if ( op->o_bd->be_syncinfo ) { + defref = op->o_bd->be_syncinfo->si_provideruri_bv; } else { defref = op->o_bd->be_update_refs - ? op->o_bd->be_update_refs : default_referral; + ? op->o_bd->be_update_refs : default_referral; } if ( defref != NULL ) { diff --git a/servers/slapd/back-bdb/add.c b/servers/slapd/back-bdb/add.c index 7d5849e0cf..c393cdf968 100644 --- a/servers/slapd/back-bdb/add.c +++ b/servers/slapd/back-bdb/add.c @@ -436,7 +436,7 @@ retry: /* transaction retry */ goto return_results; } - if ( !op->o_bd->syncinfo ) { + if ( !op->o_bd->be_syncinfo ) { rc = bdb_csn_commit( op, rs, ltid, ei, &suffix_ei, &ctxcsn_e, &ctxcsn_added, locker ); switch ( rc ) { @@ -481,7 +481,7 @@ retry: /* transaction retry */ suffix_ei = op->oq_add.rs_e->e_private; } - if ( !op->o_bd->syncinfo ) { + if ( !op->o_bd->be_syncinfo ) { if ( ctxcsn_added ) { bdb_cache_add( bdb, suffix_ei, ctxcsn_e, (struct berval *)&slap_ldapsync_cn_bv, locker ); } diff --git a/servers/slapd/back-bdb/ctxcsn.c b/servers/slapd/back-bdb/ctxcsn.c index 3f9dfc1f61..a2cbadfd77 100644 --- a/servers/slapd/back-bdb/ctxcsn.c +++ b/servers/slapd/back-bdb/ctxcsn.c @@ -264,10 +264,10 @@ bdb_get_commit_csn( int rc; if ( op->o_sync_mode != SLAP_SYNC_NONE ) { - if ( op->o_bd->syncinfo ) { + if ( op->o_bd->be_syncinfo ) { char substr[67]; struct berval bv; - sprintf( substr, "cn=syncrepl%d", op->o_bd->syncinfo->id ); + sprintf( substr, "cn=syncrepl%d", op->o_bd->be_syncinfo->si_id ); ber_str2bv( substr, 0, 0, &bv ); build_new_dn( &ctxcsn_ndn, &op->o_bd->be_nsuffix[0], &bv, NULL ); } else { @@ -292,9 +292,9 @@ ctxcsn_retry : case DB_LOCK_NOTGRANTED: goto ctxcsn_retry; case DB_NOTFOUND: - if ( !op->o_bd->syncinfo ) { + if ( !op->o_bd->be_syncinfo ) { snprintf( gid, sizeof( gid ), "%s-%08lx-%08lx", - bdb_uuid.bv_val, (long) op->o_connid, (long) op->o_opid ); + bdb_uuid.bv_val, (long) op->o_connid, (long) op->o_opid ); slap_get_csn( op, csnbuf, sizeof(csnbuf), &csn, 1 ); @@ -358,10 +358,12 @@ txn_retry: } if ( ctxcsn_e ) { - if ( op->o_bd->syncinfo ) { - csn_a = attr_find( ctxcsn_e->e_attrs, slap_schema.si_ad_syncreplCookie ); + if ( op->o_bd->be_syncinfo ) { + csn_a = attr_find( ctxcsn_e->e_attrs, + slap_schema.si_ad_syncreplCookie ); } else { - csn_a = attr_find( ctxcsn_e->e_attrs, slap_schema.si_ad_contextCSN ); + csn_a = attr_find( ctxcsn_e->e_attrs, + slap_schema.si_ad_contextCSN ); } if ( csn_a ) { *search_context_csn = ber_dupbv( NULL, &csn_a->a_vals[0] ); diff --git a/servers/slapd/back-bdb/delete.c b/servers/slapd/back-bdb/delete.c index 9acab3aa18..5872be64ec 100644 --- a/servers/slapd/back-bdb/delete.c +++ b/servers/slapd/back-bdb/delete.c @@ -251,9 +251,10 @@ retry: /* transaction retry */ matched = NULL; } else { - BerVarray deref = op->o_bd->syncinfo ? - op->o_bd->syncinfo->provideruri_bv : default_referral; - rs->sr_ref = referral_rewrite( deref, NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT ); + BerVarray deref = op->o_bd->be_syncinfo ? + op->o_bd->be_syncinfo->si_provideruri_bv : default_referral; + rs->sr_ref = referral_rewrite( deref, NULL, &op->o_req_dn, + LDAP_SCOPE_DEFAULT ); } rs->sr_err = LDAP_REFERRAL; @@ -471,8 +472,9 @@ retry: /* transaction retry */ ldap_pvt_thread_mutex_unlock( &bdb->bi_lastid_mutex ); #endif - if ( !op->o_bd->syncinfo ) { - rc = bdb_csn_commit( op, rs, ltid, ei, &suffix_ei, &ctxcsn_e, &ctxcsn_added, locker ); + if ( !op->o_bd->be_syncinfo ) { + rc = bdb_csn_commit( op, rs, ltid, ei, &suffix_ei, + &ctxcsn_e, &ctxcsn_added, locker ); switch ( rc ) { case BDB_CSN_ABORT : goto return_results; @@ -492,9 +494,10 @@ retry: /* transaction retry */ bdb_cache_delete( &bdb->bi_cache, e, bdb->bi_dbenv, locker, &lock ); - if ( !op->o_bd->syncinfo ) { + if ( !op->o_bd->be_syncinfo ) { if ( ctxcsn_added ) { - bdb_cache_add( bdb, suffix_ei, ctxcsn_e, (struct berval *)&slap_ldapsync_cn_bv, locker ); + bdb_cache_add( bdb, suffix_ei, + ctxcsn_e, (struct berval *)&slap_ldapsync_cn_bv, locker ); } } diff --git a/servers/slapd/back-bdb/modify.c b/servers/slapd/back-bdb/modify.c index 71c80ec798..79455549d5 100644 --- a/servers/slapd/back-bdb/modify.c +++ b/servers/slapd/back-bdb/modify.c @@ -421,9 +421,10 @@ retry: /* transaction retry */ e = NULL; } else { - BerVarray deref = op->o_bd->syncinfo ? - op->o_bd->syncinfo->provideruri_bv : default_referral; - rs->sr_ref = referral_rewrite( deref, NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT ); + BerVarray deref = op->o_bd->be_syncinfo ? + op->o_bd->be_syncinfo->si_provideruri_bv : default_referral; + rs->sr_ref = referral_rewrite( deref, NULL, &op->o_req_dn, + LDAP_SCOPE_DEFAULT ); } rs->sr_err = LDAP_REFERRAL; @@ -575,7 +576,7 @@ retry: /* transaction retry */ goto return_results; } - if ( !op->o_bd->syncinfo ) { + if ( !op->o_bd->be_syncinfo ) { rc = bdb_csn_commit( op, rs, ltid, ei, &suffix_ei, &ctxcsn_e, &ctxcsn_added, locker ); switch ( rc ) { @@ -598,9 +599,10 @@ retry: /* transaction retry */ bdb_cache_modify( e, dummy.e_attrs, bdb->bi_dbenv, locker, &lock ); - if ( !op->o_bd->syncinfo ) { + if ( !op->o_bd->be_syncinfo ) { if ( ctxcsn_added ) { - bdb_cache_add( bdb, suffix_ei, ctxcsn_e, (struct berval *)&slap_ldapsync_cn_bv, locker ); + bdb_cache_add( bdb, suffix_ei, ctxcsn_e, + (struct berval *)&slap_ldapsync_cn_bv, locker ); } } diff --git a/servers/slapd/back-bdb/modrdn.c b/servers/slapd/back-bdb/modrdn.c index ff4dab5a72..b85d50a0af 100644 --- a/servers/slapd/back-bdb/modrdn.c +++ b/servers/slapd/back-bdb/modrdn.c @@ -173,9 +173,10 @@ retry: /* transaction retry */ e = NULL; } else { - BerVarray deref = op->o_bd->syncinfo ? - op->o_bd->syncinfo->provideruri_bv : default_referral; - rs->sr_ref = referral_rewrite( deref, NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT ); + BerVarray deref = op->o_bd->be_syncinfo ? + op->o_bd->be_syncinfo->si_provideruri_bv : default_referral; + rs->sr_ref = referral_rewrite( deref, NULL, &op->o_req_dn, + LDAP_SCOPE_DEFAULT ); } rs->sr_err = LDAP_REFERRAL; @@ -939,8 +940,9 @@ retry: /* transaction retry */ goto return_results; } - if ( !op->o_bd->syncinfo ) { - rc = bdb_csn_commit( op, rs, ltid, ei, &suffix_ei, &ctxcsn_e, &ctxcsn_added, locker ); + if ( !op->o_bd->be_syncinfo ) { + rc = bdb_csn_commit( op, rs, ltid, ei, &suffix_ei, + &ctxcsn_e, &ctxcsn_added, locker ); switch ( rc ) { case BDB_CSN_ABORT : goto return_results; @@ -970,9 +972,10 @@ retry: /* transaction retry */ bdb_cache_modrdn( save, &op->orr_nnewrdn, e, neip, bdb->bi_dbenv, locker, &lock ); - if ( !op->o_bd->syncinfo ) { + if ( !op->o_bd->be_syncinfo ) { if ( ctxcsn_added ) { - bdb_cache_add( bdb, suffix_ei, ctxcsn_e, (struct berval *)&slap_ldapsync_cn_bv, locker ); + bdb_cache_add( bdb, suffix_ei, ctxcsn_e, + (struct berval *)&slap_ldapsync_cn_bv, locker ); } } diff --git a/servers/slapd/back-ldbm/delete.c b/servers/slapd/back-ldbm/delete.c index edcfbf5be4..ddad52d7a0 100644 --- a/servers/slapd/back-ldbm/delete.c +++ b/servers/slapd/back-ldbm/delete.c @@ -60,9 +60,10 @@ ldbm_back_delete( cache_return_entry_r( &li->li_cache, matched ); } else { - BerVarray deref = op->o_bd->syncinfo ? - op->o_bd->syncinfo->provideruri_bv : default_referral; - rs->sr_ref = referral_rewrite( deref, NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT ); + BerVarray deref = op->o_bd->be_syncinfo ? + op->o_bd->be_syncinfo->si_provideruri_bv : default_referral; + rs->sr_ref = referral_rewrite( deref, NULL, &op->o_req_dn, + LDAP_SCOPE_DEFAULT ); } ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock); diff --git a/servers/slapd/back-ldbm/modify.c b/servers/slapd/back-ldbm/modify.c index 5679f2dadc..bed5eefd8e 100644 --- a/servers/slapd/back-ldbm/modify.c +++ b/servers/slapd/back-ldbm/modify.c @@ -324,9 +324,10 @@ ldbm_back_modify( : NULL; cache_return_entry_r( &li->li_cache, matched ); } else { - BerVarray deref = op->o_bd->syncinfo ? - op->o_bd->syncinfo->provideruri_bv : default_referral; - rs->sr_ref = referral_rewrite( deref, NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT ); + BerVarray deref = op->o_bd->be_syncinfo ? + op->o_bd->be_syncinfo->si_provideruri_bv : default_referral; + rs->sr_ref = referral_rewrite( deref, NULL, &op->o_req_dn, + LDAP_SCOPE_DEFAULT ); } ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock); diff --git a/servers/slapd/back-ldbm/modrdn.c b/servers/slapd/back-ldbm/modrdn.c index 99440e9d45..2c20f1d589 100644 --- a/servers/slapd/back-ldbm/modrdn.c +++ b/servers/slapd/back-ldbm/modrdn.c @@ -92,9 +92,10 @@ ldbm_back_modrdn( : NULL; cache_return_entry_r( &li->li_cache, matched ); } else { - BerVarray deref = op->o_bd->syncinfo ? - op->o_bd->syncinfo->provideruri_bv : default_referral; - rs->sr_ref = referral_rewrite( deref, NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT ); + BerVarray deref = op->o_bd->be_syncinfo ? + op->o_bd->be_syncinfo->si_provideruri_bv : default_referral; + rs->sr_ref = referral_rewrite( deref, NULL, &op->o_req_dn, + LDAP_SCOPE_DEFAULT ); } ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock); diff --git a/servers/slapd/back-meta/cache-merge.c b/servers/slapd/back-meta/cache-merge.c index 211ec672e3..a9592d43d1 100644 --- a/servers/slapd/back-meta/cache-merge.c +++ b/servers/slapd/back-meta/cache-merge.c @@ -256,7 +256,7 @@ normalize_values( Attribute* attr ) { for ( i = 0; i < nvals; i++ ) { rc = attr->a_desc->ad_type->sat_equality->smr_normalize( - 0, + SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX, attr->a_desc->ad_type->sat_syntax, attr->a_desc->ad_type->sat_equality, &attr->a_vals[i], &attr->a_nvals[i], NULL ); diff --git a/servers/slapd/backend.c b/servers/slapd/backend.c index 3a536f4082..313f819a1b 100644 --- a/servers/slapd/backend.c +++ b/servers/slapd/backend.c @@ -336,8 +336,9 @@ int backend_startup(Backend *be) for( i = 0; i < nBackendDB; i++ ) { if ( backendDB[i].be_update_ndn.bv_val && ( !backendDB[i].be_update_refs && - !backendDB[i].syncinfo && - !default_referral ) ) { + !backendDB[i].be_syncinfo && + !default_referral ) ) + { #ifdef NEW_LOGGING LDAP_LOG( BACKEND, CRIT, "backend_startup: slave \"%s\" updateref missing\n", @@ -372,13 +373,13 @@ int backend_startup(Backend *be) } } - if ( backendDB[i].syncinfo != NULL ) { - syncinfo_t *si = ( syncinfo_t * ) backendDB[i].syncinfo; - si->be = &backendDB[i]; + if ( backendDB[i].be_syncinfo != NULL ) { + syncinfo_t *si = ( syncinfo_t * ) backendDB[i].be_syncinfo; + si->si_be = &backendDB[i]; init_syncrepl(si); ldap_pvt_thread_mutex_lock( &syncrepl_rq.rq_mutex ); - ldap_pvt_runqueue_insert( &syncrepl_rq, si->interval, - do_syncrepl, (void *) backendDB[i].syncinfo ); + ldap_pvt_runqueue_insert( &syncrepl_rq, si->si_interval, + do_syncrepl, (void *) backendDB[i].be_syncinfo ); ldap_pvt_thread_mutex_unlock( &syncrepl_rq.rq_mutex ); } } @@ -549,7 +550,7 @@ backend_db_init( ldap_pvt_thread_mutex_init( &be->be_pcl_mutex ); ldap_pvt_thread_mutex_init( &be->be_context_csn_mutex ); - be->syncinfo = NULL; + be->be_syncinfo = NULL; /* assign a default depth limit for alias deref */ be->be_max_deref_depth = SLAPD_DEFAULT_MAXDEREFDEPTH; diff --git a/servers/slapd/config.c b/servers/slapd/config.c index fed67ef677..5f89fab290 100644 --- a/servers/slapd/config.c +++ b/servers/slapd/config.c @@ -2753,7 +2753,7 @@ add_syncrepl( { syncinfo_t *si; - if ( be->syncinfo ) { + if ( be->be_syncinfo ) { #ifdef NEW_LOGGING LDAP_LOG( CONFIG, INFO, "add_syncrepl: multiple syncrepl lines in a database " @@ -2766,7 +2766,7 @@ add_syncrepl( return 1; } - si = be->syncinfo = (syncinfo_t *) ch_calloc( 1, sizeof( syncinfo_t ) ); + si = be->be_syncinfo = (syncinfo_t *) ch_calloc( 1, sizeof( syncinfo_t ) ); if ( si == NULL ) { #ifdef NEW_LOGGING @@ -2777,30 +2777,33 @@ add_syncrepl( return 1; } - si->tls = TLS_OFF; - if ( be->be_rootndn.bv_val ) - ber_dupbv( &si->updatedn, &be->be_rootndn ); - si->bindmethod = LDAP_AUTH_SIMPLE; - si->schemachecking = 0; - ber_str2bv( "(objectclass=*)", sizeof("(objectclass=*)")-1, 0, &si->filterstr ); - if ( be->be_suffix && be->be_suffix[0].bv_val ) - ber_dupbv( &si->base, &be->be_nsuffix[0] ); - si->scope = LDAP_SCOPE_SUBTREE; - si->attrsonly = 0; - si->attrs = (char **) ch_calloc( 1, sizeof( char * )); - si->attrs[0] = NULL; - si->type = LDAP_SYNC_REFRESH_ONLY; - si->interval = 86400; - si->syncCookie = NULL; - si->manageDSAit = 0; - si->tlimit = -1; - si->slimit = -1; - si->syncUUID = NULL; - si->syncUUID_ndn = NULL; - si->sync_mode = LDAP_SYNC_STATE_MODE; - - si->presentlist = NULL; - LDAP_LIST_INIT( &si->nonpresentlist ); + si->si_tls = SYNCINFO_TLS_OFF; + if ( be->be_rootndn.bv_val ) { + ber_dupbv( &si->si_updatedn, &be->be_rootndn ); + } + si->si_bindmethod = LDAP_AUTH_SIMPLE; + si->si_schemachecking = 0; + ber_str2bv( "(objectclass=*)", sizeof("(objectclass=*)")-1, 0, + &si->si_filterstr ); + if ( be->be_suffix && be->be_suffix[0].bv_val ) { + ber_dupbv( &si->si_base, &be->be_nsuffix[0] ); + } + si->si_scope = LDAP_SCOPE_SUBTREE; + si->si_attrsonly = 0; + si->si_attrs = (char **) ch_calloc( 1, sizeof( char * )); + si->si_attrs[0] = NULL; + si->si_type = LDAP_SYNC_REFRESH_ONLY; + si->si_interval = 86400; + si->si_syncCookie = NULL; + si->si_manageDSAit = 0; + si->si_tlimit = -1; + si->si_slimit = -1; + si->si_syncUUID = NULL; + si->si_syncUUID_ndn = NULL; + si->si_sync_mode = LDAP_SYNC_STATE_MODE; + + si->si_presentlist = NULL; + LDAP_LIST_INIT( &si->si_nonpresentlist ); if ( parse_syncrepl_line( cargv, cargc, si ) < 0 ) { /* Something bad happened - back out */ @@ -2810,22 +2813,22 @@ add_syncrepl( Debug( LDAP_DEBUG_ANY, "failed to add syncinfo\n", 0, 0, 0 ); #endif free( si ); - be->syncinfo = NULL; + be->be_syncinfo = NULL; return 1; } else { #ifdef NEW_LOGGING LDAP_LOG ( CONFIG, RESULTS, "add_syncrepl: Config: ** successfully added syncrepl \"%s\"\n", - si->provideruri == NULL ? "(null)" : si->provideruri, 0, 0 ); + si->si_provideruri == NULL ? "(null)" : si->si_provideruri, 0, 0 ); #else Debug( LDAP_DEBUG_CONFIG, "Config: ** successfully added syncrepl \"%s\"\n", - si->provideruri == NULL ? "(null)" : si->provideruri, 0, 0 ); + si->si_provideruri == NULL ? "(null)" : si->si_provideruri, 0, 0 ); #endif - if ( !si->schemachecking ) { + if ( !si->si_schemachecking ) { be->be_flags |= SLAP_BFLAG_NO_SCHEMA_CHECK; } - si->be = be; + si->si_be = be; return 0; } } @@ -2885,155 +2888,164 @@ parse_syncrepl_line( for ( i = 1; i < cargc; i++ ) { if ( !strncasecmp( cargv[ i ], IDSTR, sizeof( IDSTR ) - 1 )) { + int tmp; /* '\0' string terminator accounts for '=' */ val = cargv[ i ] + sizeof( IDSTR ); - si->id = atoi( val ); - if ( si->id >= 1000 ) { + tmp= atoi( val ); + if ( tmp >= 1000 || tmp < 0 ) { fprintf( stderr, "Error: parse_syncrepl_line: " - "syncrepl id %d is out of range [0..999]\n", si->id ); + "syncrepl id %d is out of range [0..999]\n", tmp ); return -1; } + si->si_id = tmp; gots |= GOT_ID; } else if ( !strncasecmp( cargv[ i ], PROVIDERSTR, sizeof( PROVIDERSTR ) - 1 )) { val = cargv[ i ] + sizeof( PROVIDERSTR ); - si->provideruri = ch_strdup( val ); - si->provideruri_bv = (BerVarray) ch_calloc( 2, sizeof( struct berval )); - ber_str2bv( si->provideruri, strlen( si->provideruri ), 0, &si->provideruri_bv[0] ); - si->provideruri_bv[1].bv_len = 0; - si->provideruri_bv[1].bv_val = NULL; + si->si_provideruri = ch_strdup( val ); + si->si_provideruri_bv = (BerVarray) + ch_calloc( 2, sizeof( struct berval )); + ber_str2bv( si->si_provideruri, strlen( si->si_provideruri ), + 0, &si->si_provideruri_bv[0] ); + si->si_provideruri_bv[1].bv_len = 0; + si->si_provideruri_bv[1].bv_val = NULL; gots |= GOT_PROVIDER; } else if ( !strncasecmp( cargv[ i ], STARTTLSSTR, sizeof(STARTTLSSTR) - 1 ) ) { val = cargv[ i ] + sizeof( STARTTLSSTR ); if( !strcasecmp( val, CRITICALSTR ) ) { - si->tls = TLS_CRITICAL; + si->si_tls = SYNCINFO_TLS_CRITICAL; } else { - si->tls = TLS_ON; + si->si_tls = SYNCINFO_TLS_ON; } } else if ( !strncasecmp( cargv[ i ], - UPDATEDNSTR, sizeof( UPDATEDNSTR ) - 1 ) ) { + UPDATEDNSTR, sizeof( UPDATEDNSTR ) - 1 ) ) + { struct berval updatedn = {0, NULL}; val = cargv[ i ] + sizeof( UPDATEDNSTR ); ber_str2bv( val, 0, 0, &updatedn ); - ch_free( si->updatedn.bv_val ); - dnNormalize( 0, NULL, NULL, &updatedn, &si->updatedn, NULL ); + ch_free( si->si_updatedn.bv_val ); + dnNormalize( 0, NULL, NULL, &updatedn, &si->si_updatedn, NULL ); } else if ( !strncasecmp( cargv[ i ], BINDMETHSTR, - sizeof( BINDMETHSTR ) - 1 ) ) { + sizeof( BINDMETHSTR ) - 1 ) ) + { val = cargv[ i ] + sizeof( BINDMETHSTR ); if ( !strcasecmp( val, SIMPLESTR )) { - si->bindmethod = LDAP_AUTH_SIMPLE; + si->si_bindmethod = LDAP_AUTH_SIMPLE; gots |= GOT_METHOD; } else if ( !strcasecmp( val, SASLSTR )) { - si->bindmethod = LDAP_AUTH_SASL; + si->si_bindmethod = LDAP_AUTH_SASL; gots |= GOT_METHOD; } else { - si->bindmethod = -1; + si->si_bindmethod = -1; } } else if ( !strncasecmp( cargv[ i ], BINDDNSTR, sizeof( BINDDNSTR ) - 1 ) ) { val = cargv[ i ] + sizeof( BINDDNSTR ); - si->binddn = ch_strdup( val ); + si->si_binddn = ch_strdup( val ); } else if ( !strncasecmp( cargv[ i ], CREDSTR, sizeof( CREDSTR ) - 1 ) ) { val = cargv[ i ] + sizeof( CREDSTR ); - si->passwd = ch_strdup( val ); + si->si_passwd = ch_strdup( val ); } else if ( !strncasecmp( cargv[ i ], SASLMECHSTR, sizeof( SASLMECHSTR ) - 1 ) ) { val = cargv[ i ] + sizeof( SASLMECHSTR ); - si->saslmech = ch_strdup( val ); + si->si_saslmech = ch_strdup( val ); } else if ( !strncasecmp( cargv[ i ], SECPROPSSTR, sizeof( SECPROPSSTR ) - 1 ) ) { val = cargv[ i ] + sizeof( SECPROPSSTR ); - si->secprops = ch_strdup( val ); + si->si_secprops = ch_strdup( val ); } else if ( !strncasecmp( cargv[ i ], REALMSTR, sizeof( REALMSTR ) - 1 ) ) { val = cargv[ i ] + sizeof( REALMSTR ); - si->realm = ch_strdup( val ); + si->si_realm = ch_strdup( val ); } else if ( !strncasecmp( cargv[ i ], AUTHCSTR, sizeof( AUTHCSTR ) - 1 ) ) { val = cargv[ i ] + sizeof( AUTHCSTR ); - si->authcId = ch_strdup( val ); + si->si_authcId = ch_strdup( val ); } else if ( !strncasecmp( cargv[ i ], OLDAUTHCSTR, sizeof( OLDAUTHCSTR ) - 1 ) ) { /* Old authcID is provided for some backwards compatibility */ val = cargv[ i ] + sizeof( OLDAUTHCSTR ); - si->authcId = ch_strdup( val ); + si->si_authcId = ch_strdup( val ); } else if ( !strncasecmp( cargv[ i ], AUTHZSTR, sizeof( AUTHZSTR ) - 1 ) ) { val = cargv[ i ] + sizeof( AUTHZSTR ); - si->authzId = ch_strdup( val ); - } else if ( !strncasecmp( cargv[ i ], - SRVTABSTR, sizeof( SRVTABSTR ) - 1 ) ) { - val = cargv[ i ] + sizeof( SRVTABSTR ); - if ( si->srvtab != NULL ) { - free( si->srvtab ); - } - si->srvtab = ch_strdup( val ); + si->si_authzId = ch_strdup( val ); } else if ( !strncasecmp( cargv[ i ], - SCHEMASTR, sizeof( SCHEMASTR ) - 1 ) ) { + SCHEMASTR, sizeof( SCHEMASTR ) - 1 ) ) + { val = cargv[ i ] + sizeof( SCHEMASTR ); if ( !strncasecmp( val, "on", sizeof( "on" ) - 1 )) { - si->schemachecking = 1; + si->si_schemachecking = 1; } else if ( !strncasecmp( val, "off", sizeof( "off" ) - 1 ) ) { - si->schemachecking = 0; + si->si_schemachecking = 0; } else { - si->schemachecking = 1; + si->si_schemachecking = 1; } } else if ( !strncasecmp( cargv[ i ], - FILTERSTR, sizeof( FILTERSTR ) - 1 ) ) { + FILTERSTR, sizeof( FILTERSTR ) - 1 ) ) + { val = cargv[ i ] + sizeof( FILTERSTR ); - ber_str2bv( val, 0, 1, &si->filterstr ); + ber_str2bv( val, 0, 1, &si->si_filterstr ); } else if ( !strncasecmp( cargv[ i ], - SEARCHBASESTR, sizeof( SEARCHBASESTR ) - 1 ) ) { + SEARCHBASESTR, sizeof( SEARCHBASESTR ) - 1 ) ) + { struct berval bv; val = cargv[ i ] + sizeof( SEARCHBASESTR ); - ch_free( si->base.bv_val ); + ch_free( si->si_base.bv_val ); ber_str2bv( val, 0, 0, &bv ); - if ( dnNormalize( 0, NULL, NULL, &bv, &si->base, NULL )) { + if ( dnNormalize( 0, NULL, NULL, &bv, &si->si_base, NULL )) { fprintf( stderr, "Invalid base DN \"%s\"\n", val ); return 1; } } else if ( !strncasecmp( cargv[ i ], - SCOPESTR, sizeof( SCOPESTR ) - 1 ) ) { + SCOPESTR, sizeof( SCOPESTR ) - 1 ) ) + { val = cargv[ i ] + sizeof( SCOPESTR ); if ( !strncasecmp( val, "base", sizeof( "base" ) - 1 )) { - si->scope = LDAP_SCOPE_BASE; + si->si_scope = LDAP_SCOPE_BASE; } else if ( !strncasecmp( val, "one", sizeof( "one" ) - 1 )) { - si->scope = LDAP_SCOPE_ONELEVEL; + si->si_scope = LDAP_SCOPE_ONELEVEL; } else if ( !strncasecmp( val, "sub", sizeof( "sub" ) - 1 )) { - si->scope = LDAP_SCOPE_SUBTREE; + si->si_scope = LDAP_SCOPE_SUBTREE; } else { fprintf( stderr, "Error: parse_syncrepl_line: " - "unknown scope \"%s\"\n", val); + "unknown scope \"%s\"\n", val); return 1; } } else if ( !strncasecmp( cargv[ i ], - ATTRSONLYSTR, sizeof( ATTRSONLYSTR ) - 1 ) ) { - si->attrsonly = 1; + ATTRSONLYSTR, sizeof( ATTRSONLYSTR ) - 1 ) ) + { + si->si_attrsonly = 1; } else if ( !strncasecmp( cargv[ i ], - ATTRSSTR, sizeof( ATTRSSTR ) - 1 ) ) { + ATTRSSTR, sizeof( ATTRSSTR ) - 1 ) ) + { val = cargv[ i ] + sizeof( ATTRSSTR ); - str2clist( &si->attrs, val, "," ); + str2clist( &si->si_attrs, val, "," ); } else if ( !strncasecmp( cargv[ i ], - TYPESTR, sizeof( TYPESTR ) - 1 ) ) { + TYPESTR, sizeof( TYPESTR ) - 1 ) ) + { val = cargv[ i ] + sizeof( TYPESTR ); - if ( !strncasecmp( val, "refreshOnly", sizeof( "refreshOnly" ) - 1 )) { - si->type = LDAP_SYNC_REFRESH_ONLY; - } else if ( !strncasecmp( val, "refreshAndPersist", sizeof( "refreshAndPersist" ) - 1 )) { - si->type = LDAP_SYNC_REFRESH_AND_PERSIST; - si->interval = 0; + if ( !strncasecmp( val, "refreshOnly", sizeof("refreshOnly")-1 )) { + si->si_type = LDAP_SYNC_REFRESH_ONLY; + } else if ( !strncasecmp( val, "refreshAndPersist", + sizeof("refreshAndPersist")-1 )) + { + si->si_type = LDAP_SYNC_REFRESH_AND_PERSIST; + si->si_interval = 0; } else { fprintf( stderr, "Error: parse_syncrepl_line: " - "unknown sync type \"%s\"\n", val); + "unknown sync type \"%s\"\n", val); return 1; } } else if ( !strncasecmp( cargv[ i ], - INTERVALSTR, sizeof( INTERVALSTR ) - 1 ) ) { + INTERVALSTR, sizeof( INTERVALSTR ) - 1 ) ) + { val = cargv[ i ] + sizeof( INTERVALSTR ); - if ( si->type == LDAP_SYNC_REFRESH_AND_PERSIST ) { - si->interval = 0; + if ( si->si_type == LDAP_SYNC_REFRESH_AND_PERSIST ) { + si->si_interval = 0; } else { char *dstr; char *hstr; @@ -3042,51 +3054,55 @@ parse_syncrepl_line( hstr = strchr( dstr, ':' ); if ( hstr == NULL ) { fprintf( stderr, "Error: parse_syncrepl_line: " - "invalid interval \"%s\"\n", val ); + "invalid interval \"%s\"\n", val ); return 1; } *hstr++ = '\0'; mstr = strchr( hstr, ':' ); if ( mstr == NULL ) { fprintf( stderr, "Error: parse_syncrepl_line: " - "invalid interval \"%s\"\n", val ); + "invalid interval \"%s\"\n", val ); return 1; } *mstr++ = '\0'; - si->interval = (( atoi( dstr ) * 24 + atoi( hstr )) * 60 - + atoi( mstr )) * 60; + si->si_interval = (( atoi( dstr ) * 24 + atoi( hstr )) * 60 + + atoi( mstr )) * 60; } - if ( si->interval < 0 ) { + if ( si->si_interval < 0 ) { fprintf( stderr, "Error: parse_syncrepl_line: " - "invalid interval \"%ld\"\n", - (long) si->interval); + "invalid interval \"%ld\"\n", + (long) si->si_interval); return 1; } } else if ( !strncasecmp( cargv[ i ], - COOKIESTR, sizeof( COOKIESTR ) - 1 ) ) { + COOKIESTR, sizeof( COOKIESTR ) - 1 ) ) + { val = cargv[ i ] + sizeof( COOKIESTR ); - si->syncCookie = ber_str2bv( val, strlen( val ), 1, NULL ); + si->si_syncCookie = ber_str2bv( val, strlen( val ), 1, NULL ); } else if ( !strncasecmp( cargv[ i ], - MANAGEDSAITSTR, sizeof( MANAGEDSAITSTR ) - 1 ) ) { + MANAGEDSAITSTR, sizeof( MANAGEDSAITSTR ) - 1 ) ) + { val = cargv[ i ] + sizeof( COOKIESTR ); - si->manageDSAit = atoi( val ); + si->si_manageDSAit = atoi( val ); } else if ( !strncasecmp( cargv[ i ], - SLIMITSTR, sizeof( SLIMITSTR ) - 1 ) ) { + SLIMITSTR, sizeof( SLIMITSTR ) - 1 ) ) + { val = cargv[ i ] + sizeof( SLIMITSTR ); - si->slimit = atoi( val ); + si->si_slimit = atoi( val ); } else if ( !strncasecmp( cargv[ i ], - TLIMITSTR, sizeof( TLIMITSTR ) - 1 ) ) { + TLIMITSTR, sizeof( TLIMITSTR ) - 1 ) ) + { val = cargv[ i ] + sizeof( TLIMITSTR ); - si->tlimit = atoi( val ); + si->si_tlimit = atoi( val ); } else { fprintf( stderr, "Error: parse_syncrepl_line: " - "unknown keyword \"%s\"\n", cargv[ i ] ); + "unknown keyword \"%s\"\n", cargv[ i ] ); } } if ( gots != GOT_ALL ) { - fprintf( stderr, "Error: Malformed \"syncrepl\" line in slapd config file" - ); + fprintf( stderr, + "Error: Malformed \"syncrepl\" line in slapd config file" ); return -1; } diff --git a/servers/slapd/delete.c b/servers/slapd/delete.c index 7c46560c4e..5af628095e 100644 --- a/servers/slapd/delete.c +++ b/servers/slapd/delete.c @@ -193,9 +193,10 @@ do_delete( /* do the update here */ int repl_user = be_isupdate( op->o_bd, &op->o_ndn ); #ifndef SLAPD_MULTIMASTER - if ( !op->o_bd->syncinfo && ( !op->o_bd->be_update_ndn.bv_len || repl_user )) + if ( !op->o_bd->be_syncinfo && + ( !op->o_bd->be_update_ndn.bv_len || repl_user )) #else - if ( !op->o_bd->syncinfo ) + if ( !op->o_bd->be_syncinfo ) #endif { @@ -216,11 +217,11 @@ do_delete( #ifndef SLAPD_MULTIMASTER } else { BerVarray defref = NULL; - if ( op->o_bd->syncinfo ) { - defref = op->o_bd->syncinfo->provideruri_bv; + if ( op->o_bd->be_syncinfo ) { + defref = op->o_bd->be_syncinfo->si_provideruri_bv; } else { defref = op->o_bd->be_update_refs - ? op->o_bd->be_update_refs : default_referral; + ? op->o_bd->be_update_refs : default_referral; } if ( defref != NULL ) { rs->sr_ref = referral_rewrite( defref, diff --git a/servers/slapd/modify.c b/servers/slapd/modify.c index d1b72b4aee..89a818fd33 100644 --- a/servers/slapd/modify.c +++ b/servers/slapd/modify.c @@ -453,10 +453,10 @@ do_modify( * because it accepts each modify request */ #ifndef SLAPD_MULTIMASTER - if ( !op->o_bd->syncinfo && + if ( !op->o_bd->be_syncinfo && ( !op->o_bd->be_update_ndn.bv_len || repl_user )) #else - if ( !op->o_bd->syncinfo ) + if ( !op->o_bd->be_syncinfo ) #endif { int update = op->o_bd->be_update_ndn.bv_len; @@ -501,8 +501,8 @@ do_modify( /* send a referral */ } else { BerVarray defref = NULL; - if ( op->o_bd->syncinfo ) { - defref = op->o_bd->syncinfo->provideruri_bv; + if ( op->o_bd->be_syncinfo ) { + defref = op->o_bd->be_syncinfo->si_provideruri_bv; } else { defref = op->o_bd->be_update_refs ? op->o_bd->be_update_refs : default_referral; diff --git a/servers/slapd/modrdn.c b/servers/slapd/modrdn.c index 5ec1418fbb..0d27035499 100644 --- a/servers/slapd/modrdn.c +++ b/servers/slapd/modrdn.c @@ -354,10 +354,10 @@ do_modrdn( /* do the update here */ int repl_user = be_isupdate( op->o_bd, &op->o_ndn ); #ifndef SLAPD_MULTIMASTER - if ( !op->o_bd->syncinfo && - ( !op->o_bd->be_update_ndn.bv_len || repl_user )) + if ( !op->o_bd->be_syncinfo && + ( !op->o_bd->be_update_ndn.bv_len || repl_user )) #else - if ( !op->o_bd->syncinfo ) + if ( !op->o_bd->be_syncinfo ) #endif { op->orr_deleteoldrdn = deloldrdn; @@ -371,11 +371,11 @@ do_modrdn( #ifndef SLAPD_MULTIMASTER } else { BerVarray defref = NULL; - if ( op->o_bd->syncinfo ) { - defref = op->o_bd->syncinfo->provideruri_bv; + if ( op->o_bd->be_syncinfo ) { + defref = op->o_bd->be_syncinfo->si_provideruri_bv; } else { defref = op->o_bd->be_update_refs - ? op->o_bd->be_update_refs : default_referral; + ? op->o_bd->be_update_refs : default_referral; } if ( defref != NULL ) { rs->sr_ref = referral_rewrite( defref, diff --git a/servers/slapd/passwd.c b/servers/slapd/passwd.c index b1c7864fd2..cfd3253f7f 100644 --- a/servers/slapd/passwd.c +++ b/servers/slapd/passwd.c @@ -57,8 +57,8 @@ int passwd_extop( } else if( op->o_bd->be_update_ndn.bv_len ) { /* we SHOULD return a referral in this case */ BerVarray defref = NULL; - if ( op->o_bd->syncinfo ) { - defref = op->o_bd->syncinfo->provideruri_bv; + if ( op->o_bd->be_syncinfo ) { + defref = op->o_bd->be_syncinfo->si_provideruri_bv; } else { defref = referral_rewrite( op->o_bd->be_update_refs, NULL, NULL, LDAP_SCOPE_DEFAULT ); diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index d5e612a8e2..ab8325747f 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -1286,54 +1286,53 @@ typedef BackendDB Backend; #define backends backendDB struct nonpresent_entry { - struct berval *dn; - struct berval *ndn; - LDAP_LIST_ENTRY(nonpresent_entry) np_link; + struct berval *npe_name; + struct berval *npe_nname; + LDAP_LIST_ENTRY(nonpresent_entry) npe_link; }; - /* - * syncinfo structure for syncrepl - */ +/* + * syncinfo structure for syncrepl + */ typedef struct syncinfo_s { - struct slap_conn *conn; - struct slap_backend_db *be; - struct slap_entry *e; - void *ctx; - int id; - char *provideruri; - BerVarray provideruri_bv; -#define TLS_OFF 0 -#define TLS_ON 1 -#define TLS_CRITICAL 2 - int tls; - struct berval updatedn; - int bindmethod; - char *binddn; - char *passwd; - char *saslmech; - char *secprops; - char *realm; - char *authcId; - char *authzId; - char *srvtab; - int schemachecking; - Filter *filter; - struct berval filterstr; - struct berval base; - int scope; - int attrsonly; - char **attrs; - int type; - time_t interval; - struct berval *syncCookie; - int manageDSAit; - int slimit; - int tlimit; - struct berval *syncUUID; - struct berval *syncUUID_ndn; - Avlnode *presentlist; - int sync_mode; - LDAP_LIST_HEAD(np, nonpresent_entry) nonpresentlist; + struct slap_conn *si_conn; + struct slap_backend_db *si_be; + struct slap_entry *si_e; + void *si_ctx; + unsigned int si_id; + char *si_provideruri; + BerVarray si_provideruri_bv; +#define SYNCINFO_TLS_OFF 0 +#define SYNCINFO_TLS_ON 1 +#define SYNCINFO_TLS_CRITICAL 2 + int si_tls; + struct berval si_updatedn; + int si_bindmethod; + char *si_binddn; + char *si_passwd; + char *si_saslmech; + char *si_secprops; + char *si_realm; + char *si_authcId; + char *si_authzId; + int si_schemachecking; + Filter *si_filter; + struct berval si_filterstr; + struct berval si_base; + int si_scope; + int si_attrsonly; + char **si_attrs; + int si_type; + time_t si_interval; + struct berval *si_syncCookie; + int si_manageDSAit; + int si_slimit; + int si_tlimit; + struct berval *si_syncUUID; + struct berval *si_syncUUID_ndn; + Avlnode *si_presentlist; + int si_sync_mode; + LDAP_LIST_HEAD(np, nonpresent_entry) si_nonpresentlist; } syncinfo_t; struct slap_backend_db { @@ -1488,7 +1487,7 @@ struct slap_backend_db { ldap_pvt_thread_mutex_t be_pcl_mutex; struct berval be_context_csn; ldap_pvt_thread_mutex_t be_context_csn_mutex; - syncinfo_t *syncinfo; /* For syncrepl */ + syncinfo_t *be_syncinfo; /* For syncrepl */ }; struct slap_conn; diff --git a/servers/slapd/syncrepl.c b/servers/slapd/syncrepl.c index f097c12dad..733e2e2e4e 100644 --- a/servers/slapd/syncrepl.c +++ b/servers/slapd/syncrepl.c @@ -2,6 +2,10 @@ /* * Replication Engine which uses the LDAP Sync protocol */ +/* + * Copyright 2003 The OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ /* Copyright (c) 2003 by International Business Machines, Inc. * * International Business Machines, Inc. (hereinafter called IBM) grants @@ -75,22 +79,24 @@ init_syncrepl(syncinfo_t *si) sync_descs[3] = NULL; } - for ( n = 0; si->attrs[ n ] != NULL; n++ ) ; + for ( n = 0; si->si_attrs[ n ] != NULL; n++ ) /* empty */; if ( n ) { /* Delete Attributes */ for ( i = 0; sync_descs[i] != NULL; i++ ) { - for ( j = 0; si->attrs[j] != NULL; j++ ) { - if ( !strcmp( si->attrs[j], sync_descs[i]->ad_cname.bv_val )) { - ch_free( si->attrs[j] ); - for ( k = j; si->attrs[k] != NULL; k++ ) { - si->attrs[k] = si->attrs[k+1]; + for ( j = 0; si->si_attrs[j] != NULL; j++ ) { + if ( strcmp( si->si_attrs[j], sync_descs[i]->ad_cname.bv_val ) + == 0 ) + { + ch_free( si->si_attrs[j] ); + for ( k = j; si->si_attrs[k] != NULL; k++ ) { + si->si_attrs[k] = si->si_attrs[k+1]; } } } } - for ( n = 0; si->attrs[ n ] != NULL; n++ ); - tmp = ( char ** ) ch_realloc( si->attrs, ( n + 4 ) * sizeof( char * )); + for ( n = 0; si->si_attrs[ n ] != NULL; n++ ) /* empty */; + tmp = ( char ** ) ch_realloc( si->si_attrs, (n + 4)*sizeof( char * )); if ( tmp == NULL ) { #ifdef NEW_LOGGING LDAP_LOG( OPERATION, ERR, "out of memory\n", 0,0,0 ); @@ -99,7 +105,7 @@ init_syncrepl(syncinfo_t *si) #endif } } else { - tmp = ( char ** ) ch_realloc( si->attrs, 5 * sizeof( char * )); + tmp = ( char ** ) ch_realloc( si->si_attrs, 5 * sizeof( char * )); if ( tmp == NULL ) { #ifdef NEW_LOGGING LDAP_LOG( OPERATION, ERR, "out of memory\n", 0,0,0 ); @@ -110,13 +116,13 @@ init_syncrepl(syncinfo_t *si) tmp[ n++ ] = ch_strdup( "*" ); } - si->attrs = tmp; + si->si_attrs = tmp; /* Add Attributes */ for ( i = 0; sync_descs[ i ] != NULL; i++ ) { - si->attrs[ n++ ] = ch_strdup ( sync_descs[i]->ad_cname.bv_val ); - si->attrs[ n ] = NULL; + si->si_attrs[ n++ ] = ch_strdup ( sync_descs[i]->ad_cname.bv_val ); + si->si_attrs[ n ] = NULL; } } @@ -137,10 +143,10 @@ ldap_sync_search( ber_init2( ber, NULL, LBER_USE_DER ); ber_set_option( ber, LBER_OPT_BER_MEMCTX, &ctx ); - if ( si->syncCookie ) { - ber_printf( ber, "{eO}", abs(si->type), si->syncCookie ); + if ( si->si_syncCookie ) { + ber_printf( ber, "{eO}", abs(si->si_type), si->si_syncCookie ); } else { - ber_printf( ber, "{e}", abs(si->type) ); + ber_printf( ber, "{e}", abs(si->si_type) ); } if ( (rc = ber_flatten2( ber, &c[0].ldctl_value, 0 )) == LBER_ERROR ) { @@ -149,12 +155,12 @@ ldap_sync_search( } c[0].ldctl_oid = LDAP_CONTROL_SYNC; - c[0].ldctl_iscritical = si->type < 0; + c[0].ldctl_iscritical = si->si_type < 0; ctrls[0] = &c[0]; - if ( si->authzId ) { + if ( si->si_authzId ) { c[1].ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ; - ber_str2bv( si->authzId, 0, 0, &c[1].ldctl_value ); + ber_str2bv( si->si_authzId, 0, 0, &c[1].ldctl_value ); c[1].ldctl_iscritical = 1; ctrls[1] = &c[1]; ctrls[2] = NULL; @@ -162,13 +168,13 @@ ldap_sync_search( ctrls[1] = NULL; } - timeout.tv_sec = si->tlimit > 0 ? si->tlimit : 1; + timeout.tv_sec = si->si_tlimit > 0 ? si->si_tlimit : 1; timeout.tv_usec = 0; - rc = ldap_search_ext( ld, si->base.bv_val, si->scope, si->filterstr.bv_val, - si->attrs, si->attrsonly, ctrls, NULL, - si->tlimit < 0 ? NULL : &timeout, - si->slimit, msgidp ); + rc = ldap_search_ext( ld, si->si_base.bv_val, si->si_scope, + si->si_filterstr.bv_val, si->si_attrs, si->si_attrsonly, + ctrls, NULL, si->si_tlimit < 0 ? NULL : &timeout, + si->si_slimit, msgidp ); ber_free_buf( ber ); return rc; @@ -242,25 +248,28 @@ do_syncrepl( if ( si == NULL ) return NULL; - if ( abs(si->type) != LDAP_SYNC_REFRESH_ONLY && - abs(si->type) != LDAP_SYNC_REFRESH_AND_PERSIST ) { + switch( abs( si->si_type )) { + case LDAP_SYNC_REFRESH_ONLY: + case LDAP_SYNC_REFRESH_AND_PERSIST: + break; + default: return NULL; } - si->sync_mode = LDAP_SYNC_STATE_MODE; + si->si_sync_mode = LDAP_SYNC_STATE_MODE; /* Init connection to master */ - rc = ldap_initialize( &ld, si->provideruri ); + rc = ldap_initialize( &ld, si->si_provideruri ); if ( rc != LDAP_SUCCESS ) { #ifdef NEW_LOGGING LDAP_LOG( OPERATION, ERR, "do_syncrepl: ldap_initialize failed (%s)\n", - si->provideruri, 0, 0 ); + si->si_provideruri, 0, 0 ); #else Debug( LDAP_DEBUG_ANY, "do_syncrepl: ldap_initialize failed (%s)\n", - si->provideruri, 0, 0 ); + si->si_provideruri, 0, 0 ); #endif return NULL; } @@ -270,57 +279,53 @@ do_syncrepl( /* Bind to master */ - if ( si->tls ) { + if ( si->si_tls ) { rc = ldap_start_tls_s( ld, NULL, NULL ); if( rc != LDAP_SUCCESS ) { #ifdef NEW_LOGGING LDAP_LOG ( OPERATION, ERR, "do_syncrepl: " "%s: ldap_start_tls failed (%d)\n", - si->tls == TLS_CRITICAL ? "Error" : "Warning", + si->si_tls == SYNCINFO_TLS_CRITICAL ? "Error" : "Warning", rc, 0 ); #else Debug( LDAP_DEBUG_ANY, "%s: ldap_start_tls failed (%d)\n", - si->tls == TLS_CRITICAL ? "Error" : "Warning", + si->si_tls == SYNCINFO_TLS_CRITICAL ? "Error" : "Warning", rc, 0 ); #endif - if( si->tls == TLS_CRITICAL ) - return NULL; + if( si->si_tls == SYNCINFO_TLS_CRITICAL ) return NULL; } } - if ( si->bindmethod == LDAP_AUTH_SASL ) { + if ( si->si_bindmethod == LDAP_AUTH_SASL ) { #ifdef HAVE_CYRUS_SASL void *defaults; - if ( si->secprops != NULL ) { + if ( si->si_secprops != NULL ) { int err = ldap_set_option( ld, - LDAP_OPT_X_SASL_SECPROPS, si->secprops); + LDAP_OPT_X_SASL_SECPROPS, si->si_secprops); if( err != LDAP_OPT_SUCCESS ) { #ifdef NEW_LOGGING LDAP_LOG ( OPERATION, ERR, "do_bind: Error: " "ldap_set_option(%s,SECPROPS,\"%s\") failed!\n", - si->provideruri, si->secprops, 0 ); + si->si_provideruri, si->si_secprops, 0 ); #else Debug( LDAP_DEBUG_ANY, "Error: ldap_set_option " "(%s,SECPROPS,\"%s\") failed!\n", - si->provideruri, si->secprops, NULL ); + si->si_provideruri, si->si_secprops, 0 ); #endif return NULL; } } defaults = lutil_sasl_defaults( ld, - si->saslmech, - si->realm, - si->authcId, - si->passwd, - si->authzId ); + si->si_saslmech, si->si_realm, + si->si_authcId, si->si_passwd, si->si_authzId ); rc = ldap_sasl_interactive_bind_s( ld, - si->binddn, - si->saslmech, + si->si_binddn, + si->si_saslmech, NULL, NULL, LDAP_SASL_QUIET, lutil_sasl_interact, @@ -329,9 +334,9 @@ do_syncrepl( lutil_sasl_freedefs( defaults ); /* FIXME : different error behaviors according to - 1) return code - 2) on err policy : exit, retry, backoff ... - */ + * 1) return code + * 2) on err policy : exit, retry, backoff ... + */ if ( rc != LDAP_SUCCESS ) { #ifdef NEW_LOGGING LDAP_LOG ( OPERATION, ERR, "do_syncrepl: " @@ -349,7 +354,7 @@ do_syncrepl( return NULL; #endif } else { - rc = ldap_bind_s( ld, si->binddn, si->passwd, si->bindmethod ); + rc = ldap_bind_s( ld, si->si_binddn, si->si_passwd, si->si_bindmethod ); if ( rc != LDAP_SUCCESS ) { #ifdef NEW_LOGGING LDAP_LOG ( OPERATION, ERR, "do_syncrepl: " @@ -363,11 +368,11 @@ do_syncrepl( } /* set thread context in syncinfo */ - si->ctx = ctx; + si->si_ctx = ctx; - be = si->be; + be = si->si_be; - si->conn = &conn; + si->si_conn = &conn; conn.c_connid = -1; conn.c_send_ldap_result = slap_send_ldap_result; conn.c_send_search_entry = slap_send_search_entry; @@ -382,11 +387,11 @@ do_syncrepl( op.o_tmpmemctx = memctx; op.o_tmpmfuncs = &sl_mfuncs; - op.o_dn = si->updatedn; - op.o_ndn = si->updatedn; + op.o_dn = si->si_updatedn; + op.o_ndn = si->si_updatedn; op.o_callback = &cb; op.o_time = slap_get_time(); - op.o_threadctx = si->ctx; + op.o_threadctx = si->si_ctx; op.o_managedsait = 1; op.o_bd = be; op.o_conn = &conn; @@ -398,39 +403,43 @@ do_syncrepl( /* get syncrepl cookie of shadow replica from subentry */ + assert( si->si_id < 1000 ); syncrepl_cn_bv.bv_val = syncrepl_cbuf; syncrepl_cn_bv.bv_len = snprintf(syncrepl_cbuf, sizeof(syncrepl_cbuf), - CN_STR "syncrepl%d", si->id ); - build_new_dn( &op.o_req_ndn, &si->base, &syncrepl_cn_bv, op.o_tmpmemctx ); + CN_STR "syncrepl%d", si->si_id ); + build_new_dn( &op.o_req_ndn, &si->si_base, &syncrepl_cn_bv, + op.o_tmpmemctx ); op.o_req_dn = op.o_req_ndn; - si->syncCookie = NULL; + si->si_syncCookie = NULL; backend_attribute( &op, NULL, &op.o_req_ndn, - slap_schema.si_ad_syncreplCookie, &si->syncCookie ); + slap_schema.si_ad_syncreplCookie, &si->si_syncCookie ); - ber_dupbv( &syncCookie_req, &si->syncCookie[0] ); + ber_dupbv( &syncCookie_req, &si->si_syncCookie[0] ); psub = be->be_nsuffix[0]; rc = ldap_sync_search( si, ld, memctx, &msgid ); if( rc != LDAP_SUCCESS ) { #ifdef NEW_LOGGING - LDAP_LOG ( OPERATION, ERR, "do_syncrepl: " - "ldap_search_ext: %s (%d)\n", ldap_err2string( rc ), rc, 0 ); + LDAP_LOG ( OPERATION, ERR, "do_syncrepl: " + "ldap_search_ext: %s (%d)\n", ldap_err2string( rc ), rc, 0 ); #else - Debug( LDAP_DEBUG_ANY, "do_syncrepl: " - "ldap_search_ext: %s (%d)\n", ldap_err2string( rc ), rc, 0 ); + Debug( LDAP_DEBUG_ANY, "do_syncrepl: " + "ldap_search_ext: %s (%d)\n", ldap_err2string( rc ), rc, 0 ); #endif return NULL; } - if ( abs(si->type) == LDAP_SYNC_REFRESH_AND_PERSIST ){ + if ( abs(si->si_type) == LDAP_SYNC_REFRESH_AND_PERSIST ){ tout_p = &tout; } else { tout_p = NULL; } - while (( rc = ldap_result( ld, LDAP_RES_ANY, LDAP_MSG_ONE, tout_p, &res )) >= 0 ) { + while (( rc = ldap_result( ld, LDAP_RES_ANY, LDAP_MSG_ONE, tout_p, &res )) + >= 0 ) + { if ( rc == 0 ) { if ( slapd_abrupt_shutdown ) { break; @@ -439,9 +448,9 @@ do_syncrepl( } } - for ( msg = ldap_first_message( ld, res ); - msg != NULL; - msg = ldap_next_message( ld, msg ) ) + for( msg = ldap_first_message( ld, res ); + msg != NULL; + msg = ldap_next_message( ld, msg ) ) { syncCookie.bv_len = 0; syncCookie.bv_val = NULL; switch( ldap_msgtype( msg ) ) { @@ -472,7 +481,8 @@ do_syncrepl( break; case LDAP_RES_SEARCH_RESULT: - ldap_parse_result( ld, msg, &err, NULL, NULL, NULL, &rctrls, 0 ); + ldap_parse_result( ld, msg, &err, NULL, NULL, NULL, + &rctrls, 0 ); if ( rctrls ) { BerElementBuffer berbuf; BerElement *ctrl_ber; @@ -482,34 +492,38 @@ do_syncrepl( ber_scanf( ctrl_ber, "{" /*"}"*/); if ( ber_peek_tag( ctrl_ber, &len ) - == LDAP_SYNC_TAG_COOKIE ) { + == LDAP_SYNC_TAG_COOKIE ) + { ber_scanf( ctrl_ber, "o", &syncCookie ); } ldap_controls_free( rctrls ); } value_match( &match, slap_schema.si_ad_entryCSN, - slap_schema.si_ad_entryCSN->ad_type->sat_ordering, - SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX, - &syncCookie_req, &syncCookie, &text ); - if (si->type == LDAP_SYNC_REFRESH_AND_PERSIST) { + slap_schema.si_ad_entryCSN->ad_type->sat_ordering, + SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX, + &syncCookie_req, &syncCookie, &text ); + if (si->si_type == LDAP_SYNC_REFRESH_AND_PERSIST) { /* FIXME : different error behaviors according to - 1) err code : LDAP_BUSY ... - 2) on err policy : stop service, stop sync, retry - */ + * 1) err code : LDAP_BUSY ... + * 2) on err policy : stop service, stop sync, retry + */ if ( syncCookie.bv_len && match < 0) { - syncrepl_updateCookie( si, ld, &op, &psub, &syncCookie ); + syncrepl_updateCookie( si, ld, &op, + &psub, &syncCookie ); } goto done; } else { /* FIXME : different error behaviors according to - 1) err code : LDAP_BUSY ... - 2) on err policy : stop service, stop sync, retry - */ + * 1) err code : LDAP_BUSY ... + * 2) on err policy : stop service, stop sync, retry + */ if ( syncCookie.bv_len && match < 0 ) { syncrepl_updateCookie( si, ld, &op, &psub, &syncCookie); } - if ( si->sync_mode == LDAP_SYNC_STATE_MODE && match < 0 ) { - syncrepl_del_nonpresent( ld, &op, si ); + if ( si->si_sync_mode == LDAP_SYNC_STATE_MODE && match + < 0 ) + { + syncrepl_del_nonpresent( ld, &op, si ); } goto done; } @@ -539,9 +553,9 @@ do_syncrepl( } value_match( &match, slap_schema.si_ad_entryCSN, - slap_schema.si_ad_entryCSN->ad_type->sat_ordering, - SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX, - &syncCookie_req, &syncCookie, &text ); + slap_schema.si_ad_entryCSN->ad_type->sat_ordering, + SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX, + &syncCookie_req, &syncCookie, &text ); if ( syncCookie.bv_len && match < 0 ) { syncrepl_updateCookie( si, ld, &op, &psub, &syncCookie); @@ -551,13 +565,14 @@ do_syncrepl( if ( match < 0 ) { syncrepl_del_nonpresent( ld, &op, si ); } - si->sync_mode = LDAP_SYNC_LOG_MODE; + si->si_sync_mode = LDAP_SYNC_LOG_MODE; } else if ( syncstate == LDAP_SYNC_LOG_MODE_DONE ) { - si->sync_mode = LDAP_SYNC_PERSIST_MODE; + si->si_sync_mode = LDAP_SYNC_PERSIST_MODE; } else if ( syncstate == LDAP_SYNC_REFRESH_DONE ) { - si->sync_mode = LDAP_SYNC_PERSIST_MODE; + si->si_sync_mode = LDAP_SYNC_PERSIST_MODE; } else if ( syncstate != LDAP_SYNC_NEW_COOKIE || - syncstate != LDAP_SYNC_LOG_MODE_DONE ) { + syncstate != LDAP_SYNC_LOG_MODE_DONE ) + { #ifdef NEW_LOGGING LDAP_LOG( OPERATION, ERR, "do_syncrepl : unknown sync info\n", 0, 0, 0 ); @@ -638,17 +653,16 @@ done: if ( syncUUID.bv_val ) ch_free( syncUUID.bv_val ); - if ( res ) - ldap_msgfree( res ); + if ( res ) ldap_msgfree( res ); ldap_unbind( ld ); - ber_bvarray_free_x( si->syncCookie, op.o_tmpmemctx ); - si->syncCookie = NULL; + ber_bvarray_free_x( si->si_syncCookie, op.o_tmpmemctx ); + si->si_syncCookie = NULL; ldap_pvt_thread_mutex_lock( &syncrepl_rq.rq_mutex ); ldap_pvt_runqueue_stoptask( &syncrepl_rq, rtask ); - if ( si->type == LDAP_SYNC_REFRESH_ONLY ) { + if ( si->si_type == LDAP_SYNC_REFRESH_ONLY ) { ldap_pvt_runqueue_resched( &syncrepl_rq, rtask ); } else { ldap_pvt_runqueue_remove( &syncrepl_rq, rtask ); @@ -765,7 +779,10 @@ syncrepl_message_to_entry( while ( ber_remaining( ber ) ) { if ( (ber_scanf( ber, "{mW}", &tmp.sml_type, &tmp.sml_values ) == - LBER_ERROR ) || ( tmp.sml_type.bv_val == NULL )) break; + LBER_ERROR ) || ( tmp.sml_type.bv_val == NULL )) + { + break; + } mod = (Modifications *) ch_malloc( sizeof( Modifications )); @@ -855,18 +872,15 @@ syncrepl_entry( int rc = LDAP_SUCCESS; if ( refresh && - ( syncstate == LDAP_SYNC_PRESENT || syncstate == LDAP_SYNC_ADD )) { + ( syncstate == LDAP_SYNC_PRESENT || syncstate == LDAP_SYNC_ADD )) + { syncuuid_bv = ber_dupbv( NULL, syncUUID ); - avl_insert( &si->presentlist, (caddr_t) syncuuid_bv, - syncuuid_cmp, avl_dup_error ); + avl_insert( &si->si_presentlist, (caddr_t) syncuuid_bv, + syncuuid_cmp, avl_dup_error ); } if ( syncstate == LDAP_SYNC_PRESENT ) { - if ( e ) { - return 1; - } else { - return 0; - } + return e ? 1 : 0; } op->ors_filterstr.bv_len = (sizeof("entryUUID=")-1) + syncUUID->bv_len; @@ -877,54 +891,56 @@ syncrepl_entry( syncUUID->bv_val, syncUUID->bv_len ); op->ors_filterstr.bv_val[op->ors_filterstr.bv_len] = '\0'; - si->e = e; - si->syncUUID_ndn = NULL; + si->si_e = e; + si->si_syncUUID_ndn = NULL; op->ors_filter = str2filter_x( op, op->ors_filterstr.bv_val ); op->ors_scope = LDAP_SCOPE_SUBTREE; /* get syncrepl cookie of shadow replica from subentry */ - op->o_req_dn = si->base; - op->o_req_ndn = si->base; + op->o_req_dn = si->si_base; + op->o_req_ndn = si->si_base; /* set callback function */ op->o_callback = &cb; cb.sc_response = dn_callback; cb.sc_private = si; - si->syncUUID_ndn = NULL; + si->si_syncUUID_ndn = NULL; rc = be->be_search( op, &rs ); - if ( op->ors_filter ) - filter_free_x( op, op->ors_filter ); - if ( op->ors_filterstr.bv_val ) + if ( op->ors_filter ) filter_free_x( op, op->ors_filter ); + if ( op->ors_filterstr.bv_val ) { sl_free( op->ors_filterstr.bv_val, op->o_tmpmemctx ); + } cb.sc_response = null_callback; cb.sc_private = si; - if ( rc == LDAP_SUCCESS && si->syncUUID_ndn && si->sync_mode != LDAP_SYNC_LOG_MODE ) { - op->o_req_dn = *si->syncUUID_ndn; - op->o_req_ndn = *si->syncUUID_ndn; + if ( rc == LDAP_SUCCESS && si->si_syncUUID_ndn && + si->si_sync_mode != LDAP_SYNC_LOG_MODE ) + { + op->o_req_dn = *si->si_syncUUID_ndn; + op->o_req_ndn = *si->si_syncUUID_ndn; op->o_tag = LDAP_REQ_DELETE; rc = be->be_delete( op, &rs ); } - if ( si->syncUUID_ndn ) { - ber_bvfree( si->syncUUID_ndn ); + if ( si->si_syncUUID_ndn ) { + ber_bvfree( si->si_syncUUID_ndn ); } switch ( syncstate ) { - case LDAP_SYNC_ADD : - case LDAP_SYNC_MODIFY : - + case LDAP_SYNC_ADD: + case LDAP_SYNC_MODIFY: if ( rc == LDAP_SUCCESS || rc == LDAP_REFERRAL || - rc == LDAP_NO_SUCH_OBJECT ) { - + rc == LDAP_NO_SUCH_OBJECT ) + { attr_delete( &e->e_attrs, slap_schema.si_ad_entryUUID ); - attr_merge_normalize_one( e, slap_schema.si_ad_entryUUID, syncUUID, op->o_tmpmemctx ); + attr_merge_normalize_one( e, slap_schema.si_ad_entryUUID, + syncUUID, op->o_tmpmemctx ); op->o_tag = LDAP_REQ_ADD; op->ora_e = e; @@ -939,7 +955,7 @@ syncrepl_entry( op->o_req_dn = e->e_name; op->o_req_ndn = e->e_nname; rc = be->be_modify( op, &rs ); - si->e = NULL; + si->si_e = NULL; if ( rc != LDAP_SUCCESS ) { #ifdef NEW_LOGGING LDAP_LOG( OPERATION, ERR, @@ -952,12 +968,11 @@ syncrepl_entry( #endif } return 1; - } else if ( rc == LDAP_REFERRAL || - rc == LDAP_NO_SUCH_OBJECT ) { + } else if ( rc == LDAP_REFERRAL || rc == LDAP_NO_SUCH_OBJECT ) { syncrepl_add_glue( si, ld, op, e, modlist, syncstate, syncUUID, syncCookie); - si->e = NULL; + si->si_e = NULL; return 0; } else { #ifdef NEW_LOGGING @@ -969,11 +984,11 @@ syncrepl_entry( "syncrepl_entry : be_add failed (%d)\n", rc, 0, 0 ); #endif - si->e = NULL; + si->si_e = NULL; return 1; } } else { - si->e = NULL; + si->si_e = NULL; be_entry_release_w( op, e ); return 0; } @@ -985,14 +1000,14 @@ syncrepl_entry( Debug( LDAP_DEBUG_ANY, "syncrepl_entry : be_search failed (%d)\n", rc, 0, 0 ); #endif - si->e = NULL; + si->si_e = NULL; return 1; } case LDAP_SYNC_DELETE : - if ( si->sync_mode == LDAP_SYNC_LOG_MODE ) { - op->o_req_dn = *si->syncUUID_ndn; - op->o_req_ndn = *si->syncUUID_ndn; + if ( si->si_sync_mode == LDAP_SYNC_LOG_MODE ) { + op->o_req_dn = *si->si_syncUUID_ndn; + op->o_req_ndn = *si->si_syncUUID_ndn; op->o_tag = LDAP_REQ_DELETE; rc = be->be_delete( op, &rs ); } @@ -1023,45 +1038,44 @@ syncrepl_del_nonpresent( SlapReply rs = {REP_RESULT}; struct nonpresent_entry *np_list, *np_prev; - op->o_req_dn = si->base; - op->o_req_ndn = si->base; + op->o_req_dn = si->si_base; + op->o_req_ndn = si->si_base; cb.sc_response = nonpresent_callback; cb.sc_private = si; op->o_callback = &cb; op->o_tag = LDAP_REQ_SEARCH; - op->ors_scope = si->scope; + op->ors_scope = si->si_scope; op->ors_deref = LDAP_DEREF_NEVER; op->ors_slimit = 0; op->ors_tlimit = 0; op->ors_attrsonly = 0; op->ors_attrs = NULL; - op->ors_filter = str2filter_x( op, si->filterstr.bv_val ); - op->ors_filterstr = si->filterstr; + op->ors_filter = str2filter_x( op, si->si_filterstr.bv_val ); + op->ors_filterstr = si->si_filterstr; op->o_nocaching = 1; be->be_search( op, &rs ); op->o_nocaching = 0; - if ( op->ors_filter ) - filter_free_x( op, op->ors_filter ); + if ( op->ors_filter ) filter_free_x( op, op->ors_filter ); - if ( !LDAP_LIST_EMPTY( &si->nonpresentlist ) ) { - np_list = LDAP_LIST_FIRST( &si->nonpresentlist ); + if ( !LDAP_LIST_EMPTY( &si->si_nonpresentlist ) ) { + np_list = LDAP_LIST_FIRST( &si->si_nonpresentlist ); while ( np_list != NULL ) { - LDAP_LIST_REMOVE( np_list, np_link ); + LDAP_LIST_REMOVE( np_list, npe_link ); np_prev = np_list; - np_list = LDAP_LIST_NEXT( np_list, np_link ); + np_list = LDAP_LIST_NEXT( np_list, npe_link ); op->o_tag = LDAP_REQ_DELETE; op->o_callback = &cb; cb.sc_response = null_callback; cb.sc_private = si; - op->o_req_dn = *np_prev->dn; - op->o_req_ndn = *np_prev->ndn; + op->o_req_dn = *np_prev->npe_name; + op->o_req_ndn = *np_prev->npe_nname; op->o_bd->be_delete( op, &rs ); - ber_bvfree( np_prev->dn ); - ber_bvfree( np_prev->ndn ); + ber_bvfree( np_prev->npe_name ); + ber_bvfree( np_prev->npe_nname ); op->o_req_dn.bv_val = NULL; op->o_req_ndn.bv_val = NULL; ch_free( np_prev ); @@ -1185,11 +1199,18 @@ syncrepl_add_glue( } /* Move to next child */ - for (ptr = dn.bv_val-2; ptr > e->e_name.bv_val && *ptr != ','; ptr--); + for (ptr = dn.bv_val-2; ptr > e->e_name.bv_val && *ptr != ','; ptr--) { + /* empty */ + } if ( ptr == e->e_name.bv_val ) break; dn.bv_val = ++ptr; dn.bv_len = e->e_name.bv_len - (ptr-e->e_name.bv_val); - for (ptr = ndn.bv_val-2; ptr > e->e_nname.bv_val && *ptr != ','; ptr--); + for( ptr = ndn.bv_val-2; + ptr > e->e_nname.bv_val && *ptr != ','; + ptr--) + { + /* empty */ + } ndn.bv_val = ++ptr; ndn.bv_len = e->e_nname.bv_len - (ptr-e->e_nname.bv_val); } @@ -1198,10 +1219,11 @@ syncrepl_add_glue( op->o_req_ndn = e->e_nname; op->ora_e = e; rc = be->be_add ( op, &rs ); - if ( rc == LDAP_SUCCESS ) + if ( rc == LDAP_SUCCESS ) { be_entry_release_w( op, e ); - else + } else { entry_free( e ); + } return; } @@ -1261,12 +1283,12 @@ syncrepl_updateCookie( struct berval *dup_syncCookie = NULL; /* update in memory cookie */ - ber_bvarray_free_x( si->syncCookie, op->o_tmpmemctx ); - si->syncCookie = NULL; + ber_bvarray_free_x( si->si_syncCookie, op->o_tmpmemctx ); + si->si_syncCookie = NULL; /* ber_bvarray_add() doesn't have dup option */ dup_syncCookie = ber_dupbv_x( NULL, syncCookie, op->o_tmpmemctx ); - ber_bvarray_add_x( &si->syncCookie, dup_syncCookie, op->o_tmpmemctx ); + ber_bvarray_add_x( &si->si_syncCookie, dup_syncCookie, op->o_tmpmemctx ); op->o_tmpfree( dup_syncCookie, op->o_tmpmemctx ); mod = (Modifications *) ch_calloc( 1, sizeof( Modifications )); @@ -1278,9 +1300,10 @@ syncrepl_updateCookie( modtail = &mod->sml_next; ber_dupbv( &cnbva[0], (struct berval *) &slap_syncrepl_bvc ); + assert( si->si_id < 1000 ); cnbva[0].bv_len = snprintf( cnbva[0].bv_val, - slap_syncrepl_bvc.bv_len, - "syncrepl%d", si->id ); + slap_syncrepl_bvc.bv_len, + "syncrepl%d", si->si_id ); mod = (Modifications *) ch_calloc( 1, sizeof( Modifications )); mod->sml_op = LDAP_MOD_REPLACE; mod->sml_desc = slap_schema.si_ad_cn; @@ -1290,7 +1313,7 @@ syncrepl_updateCookie( modtail = &mod->sml_next; if ( scbva[0].bv_val ) ch_free( scbva[0].bv_val ); - ber_dupbv( &scbva[0], &si->syncCookie[0] ); + ber_dupbv( &scbva[0], &si->si_syncCookie[0] ); mod = (Modifications *) ch_calloc( 1, sizeof( Modifications )); mod->sml_op = LDAP_MOD_REPLACE; mod->sml_desc = slap_schema.si_ad_syncreplCookie; @@ -1320,7 +1343,7 @@ syncrepl_updateCookie( if( rc != LDAP_SUCCESS ) { #ifdef NEW_LOGGING LDAP_LOG( OPERATION, ERR, - "syncrepl_updateCookie: mods opattrs (%s)\n", text, 0, 0 ); + "syncrepl_updateCookie: mods opattrs (%s)\n", text, 0, 0 ); #else Debug( LDAP_DEBUG_ANY, "syncrepl_updateCookie: mods opattrs (%s)\n", text, 0, 0 ); @@ -1330,16 +1353,19 @@ syncrepl_updateCookie( e = ( Entry * ) ch_calloc( 1, sizeof( Entry )); slap_syncrepl_cn_bv.bv_val = syncrepl_cbuf; + assert( si->si_id < 1000 ); slap_syncrepl_cn_bv.bv_len = snprintf( slap_syncrepl_cn_bv.bv_val, - slap_syncrepl_cn_bvc.bv_len, - "cn=syncrepl%d", si->id ); + slap_syncrepl_cn_bvc.bv_len, + "cn=syncrepl%d", si->si_id ); - build_new_dn( &slap_syncrepl_dn_bv, pdn, &slap_syncrepl_cn_bv, op->o_tmpmemctx ); + build_new_dn( &slap_syncrepl_dn_bv, pdn, &slap_syncrepl_cn_bv, + op->o_tmpmemctx ); ber_dupbv( &e->e_name, &slap_syncrepl_dn_bv ); ber_dupbv( &e->e_nname, &slap_syncrepl_dn_bv ); - if ( slap_syncrepl_dn_bv.bv_val ) + if ( slap_syncrepl_dn_bv.bv_val ) { sl_free( slap_syncrepl_dn_bv.bv_val, op->o_tmpmemctx ); + } e->e_attrs = NULL; @@ -1348,7 +1374,7 @@ syncrepl_updateCookie( if( rc != LDAP_SUCCESS ) { #ifdef NEW_LOGGING LDAP_LOG( OPERATION, ERR, - "syncrepl_updateCookie: mods2entry (%s)\n", text, 0, 0 ); + "syncrepl_updateCookie: mods2entry (%s)\n", text, 0, 0 ); #else Debug( LDAP_DEBUG_ANY, "syncrepl_updateCookie: mods2entry (%s)\n", text, 0, 0 ); @@ -1463,7 +1489,7 @@ dn_callback( syncinfo_t *si = op->o_callback->sc_private; if ( rs->sr_type == REP_SEARCH ) { - if ( si->syncUUID_ndn != NULL ) { + if ( si->si_syncUUID_ndn != NULL ) { #ifdef NEW_LOGGING LDAP_LOG( OPERATION, ERR, "dn_callback : multiple entries match dn\n", 0, 0, 0 ); @@ -1473,9 +1499,9 @@ dn_callback( #endif } else { if ( rs->sr_entry == NULL ) { - si->syncUUID_ndn = NULL; + si->si_syncUUID_ndn = NULL; } else { - si->syncUUID_ndn = ber_dupbv( NULL, &rs->sr_entry->e_nname ); + si->si_syncUUID_ndn = ber_dupbv( NULL, &rs->sr_entry->e_nname ); } } } @@ -1496,34 +1522,32 @@ nonpresent_callback( struct nonpresent_entry *np_entry; if ( rs->sr_type == REP_RESULT ) { - count = avl_free( si->presentlist, avl_ber_bvfree ); - si->presentlist = NULL; - return LDAP_SUCCESS; + count = avl_free( si->si_presentlist, avl_ber_bvfree ); + si->si_presentlist = NULL; + } else if ( rs->sr_type == REP_SEARCH ) { a = attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_entryUUID ); - if ( a == NULL ) - return 0; + if ( a == NULL ) return 0; - present_uuid = avl_find( si->presentlist, &a->a_vals[0], syncuuid_cmp ); + present_uuid = avl_find( si->si_presentlist, &a->a_vals[0], + syncuuid_cmp ); if ( present_uuid == NULL ) { np_entry = (struct nonpresent_entry *) - ch_calloc( 1, sizeof( struct nonpresent_entry )); - np_entry->dn = ber_dupbv( NULL, &rs->sr_entry->e_name ); - np_entry->ndn = ber_dupbv( NULL, &rs->sr_entry->e_nname ); - LDAP_LIST_INSERT_HEAD( &si->nonpresentlist, np_entry, np_link ); + ch_calloc( 1, sizeof( struct nonpresent_entry )); + np_entry->npe_name = ber_dupbv( NULL, &rs->sr_entry->e_name ); + np_entry->npe_nname = ber_dupbv( NULL, &rs->sr_entry->e_nname ); + LDAP_LIST_INSERT_HEAD( &si->si_nonpresentlist, np_entry, npe_link ); + } else { - avl_delete( &si->presentlist, + avl_delete( &si->si_presentlist, &a->a_vals[0], syncuuid_cmp ); ch_free( present_uuid->bv_val ); ch_free( present_uuid ); } - return LDAP_SUCCESS; - } else { - return LDAP_SUCCESS; } - + return LDAP_SUCCESS; } static int @@ -1533,9 +1557,10 @@ null_callback( ) { if ( rs->sr_err != LDAP_SUCCESS && - rs->sr_err != LDAP_REFERRAL && - rs->sr_err != LDAP_ALREADY_EXISTS && - rs->sr_err != LDAP_NO_SUCH_OBJECT ) { + rs->sr_err != LDAP_REFERRAL && + rs->sr_err != LDAP_ALREADY_EXISTS && + rs->sr_err != LDAP_NO_SUCH_OBJECT ) + { #ifdef NEW_LOGGING LDAP_LOG( OPERATION, ERR, "null_callback : error code 0x%x\n", @@ -1565,7 +1590,8 @@ slap_create_syncrepl_entry( attr_merge( e, slap_schema.si_ad_objectClass, ocbva, NULL ); - attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &ocbva[1], NULL ); + attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, + &ocbva[1], NULL ); attr_merge_one( e, slap_schema.si_ad_cn, cn, NULL ); -- 2.39.5