X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fsyncrepl.c;h=6e157e700c63926a8dd3083c4f79673934ea0cfe;hb=cb9a4d01bc1ecf1eeb3fb7ef39067b2b30b6c545;hp=0efd4453968ae743c035af1c4b14f21834dee03f;hpb=04ff9674514d4fda39a4ad72d6a79baa0599d8e4;p=openldap diff --git a/servers/slapd/syncrepl.c b/servers/slapd/syncrepl.c index 0efd445396..6e157e700c 100644 --- a/servers/slapd/syncrepl.c +++ b/servers/slapd/syncrepl.c @@ -2,7 +2,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 2003-2015 The OpenLDAP Foundation. + * Copyright 2003-2017 The OpenLDAP Foundation. * Portions Copyright 2003 by IBM Corporation. * Portions Copyright 2003-2008 by Howard Chu, Symas Corporation. * All rights reserved. @@ -82,8 +82,9 @@ typedef struct syncinfo_s { struct berval si_base; struct berval si_logbase; struct berval si_filterstr; - Filter *si_filter; struct berval si_logfilterstr; + Filter *si_filter; + Filter *si_logfilter; struct berval si_contextdn; int si_scope; int si_attrsonly; @@ -161,7 +162,6 @@ static int syncrepl_op_modify( Operation *op, SlapReply *rs ); /* callback functions */ static int dn_callback( Operation *, SlapReply * ); static int nonpresent_callback( Operation *, SlapReply * ); -static int null_callback( Operation *, SlapReply * ); static AttributeDescription *sync_descs[4]; @@ -175,6 +175,7 @@ typedef struct logschema { struct berval ls_newRdn; struct berval ls_delRdn; struct berval ls_newSup; + struct berval ls_controls; } logschema; static logschema changelog_sc = { @@ -183,7 +184,8 @@ static logschema changelog_sc = { BER_BVC("changes"), BER_BVC("newRDN"), BER_BVC("deleteOldRDN"), - BER_BVC("newSuperior") + BER_BVC("newSuperior"), + BER_BVC("controls") }; static logschema accesslog_sc = { @@ -192,7 +194,8 @@ static logschema accesslog_sc = { BER_BVC("reqMod"), BER_BVC("reqNewRDN"), BER_BVC("reqDeleteOldRDN"), - BER_BVC("reqNewSuperior") + BER_BVC("reqNewSuperior"), + BER_BVC("reqControls") }; static const char * @@ -408,7 +411,7 @@ ldap_sync_search( int rc; int rhint; char *base; - char **attrs, *lattrs[8]; + char **attrs, *lattrs[9]; char *filter; int attrsonly; int scope; @@ -437,8 +440,9 @@ ldap_sync_search( lattrs[3] = ls->ls_newRdn.bv_val; lattrs[4] = ls->ls_delRdn.bv_val; lattrs[5] = ls->ls_newSup.bv_val; - lattrs[6] = slap_schema.si_ad_entryCSN->ad_cname.bv_val; - lattrs[7] = NULL; + lattrs[6] = ls->ls_controls.bv_val; + lattrs[7] = slap_schema.si_ad_entryCSN->ad_cname.bv_val; + lattrs[8] = NULL; rhint = 0; base = si->si_logbase.bv_val; @@ -944,6 +948,10 @@ do_syncrep2( check_syncprov( op, si ); ldap_pvt_thread_mutex_lock( &si->si_cookieState->cs_mutex ); for ( i =0; isi_cookieState->cs_num; i++ ) { +#ifdef CHATTY_SYNCLOG + Debug( LDAP_DEBUG_SYNC, "do_syncrep2: %s CSN for sid %d: %s\n", + si->si_ridtxt, i, si->si_cookieState->cs_vals[i].bv_val ); +#endif /* new SID */ if ( sid < si->si_cookieState->cs_sids[i] ) break; @@ -1790,6 +1798,11 @@ syncrepl_accesslog_mods( if ( !colon ) { /* Invalid */ continue; + } else if ( colon == bv.bv_val ) { + /* ITS#6545: An empty attribute signals that a new mod + * is about to start */ + mod = NULL; + continue; } bv.bv_len = colon - bv.bv_val; @@ -2098,6 +2111,33 @@ syncrepl_op_modify( Operation *op, SlapReply *rs ) if ( !mod ) return SLAP_CB_CONTINUE; + { + int i, sid; + sid = slap_parse_csn_sid( &mod->sml_nvalues[0] ); + ldap_pvt_thread_mutex_lock( &si->si_cookieState->cs_mutex ); + for ( i =0; isi_cookieState->cs_num; i++ ) { +#ifdef CHATTY_SYNCLOG + Debug( LDAP_DEBUG_SYNC, "syncrepl_op_modify: %s CSN for sid %d: %s\n", + si->si_ridtxt, i, si->si_cookieState->cs_vals[i].bv_val ); +#endif + /* new SID */ + if ( sid < si->si_cookieState->cs_sids[i] ) + break; + if ( si->si_cookieState->cs_sids[i] == sid ) { + if ( ber_bvcmp( &mod->sml_nvalues[0], &si->si_cookieState->cs_vals[i] ) <= 0 ) { + Debug( LDAP_DEBUG_SYNC, "syncrepl_op_modify: %s entryCSN too old, ignoring %s (%s)\n", + si->si_ridtxt, mod->sml_nvalues[0].bv_val, op->o_req_dn.bv_val ); + ldap_pvt_thread_mutex_unlock( &si->si_cookieState->cs_mutex ); + slap_graduate_commit_csn( op ); + /* tell accesslog this was a failure */ + rs->sr_err = LDAP_TYPE_OR_VALUE_EXISTS; + return LDAP_SUCCESS; + } + } + } + ldap_pvt_thread_mutex_unlock( &si->si_cookieState->cs_mutex ); + } + rc = overlay_entry_get_ov( op, &op->o_req_ndn, NULL, NULL, 0, &e, on ); if ( rc == 0 ) { Attribute *a; @@ -2111,6 +2151,7 @@ syncrepl_op_modify( Operation *op, SlapReply *rs ) } /* equal? Should never happen */ if ( match == 0 ) { + slap_graduate_commit_csn( op ); /* tell accesslog this was a failure */ rs->sr_err = LDAP_TYPE_OR_VALUE_EXISTS; return LDAP_SUCCESS; @@ -2151,14 +2192,13 @@ syncrepl_op_modify( Operation *op, SlapReply *rs ) if ( match < 0 ) { Operation op2 = *op; AttributeName an[2]; - const char *text; struct berval bv; - char *ptr; - Modifications *ml; - int size, rc; + int size; SlapReply rs1 = {0}; resolve_ctxt rx; slap_callback cb = { NULL, syncrepl_resolve_cb, NULL, NULL }; + Filter lf[3] = {0}; + AttributeAssertion aa[2] = {0}; rx.rx_si = si; rx.rx_mods = newlist; @@ -2186,7 +2226,21 @@ syncrepl_op_modify( Operation *op, SlapReply *rs ) op2.ors_filterstr.bv_len = sprintf(op2.ors_filterstr.bv_val, "(&(entryCSN>=%s)(reqDN=%s)%s)", bv.bv_val, op->o_req_ndn.bv_val, si->si_logfilterstr.bv_val ); - op2.ors_filter = str2filter_x( op, op2.ors_filterstr.bv_val ); + + lf[0].f_choice = LDAP_FILTER_AND; + lf[0].f_and = lf+1; + lf[1].f_choice = LDAP_FILTER_GE; + lf[1].f_ava = aa; + lf[1].f_av_desc = slap_schema.si_ad_entryCSN; + lf[1].f_av_value = bv; + lf[1].f_next = lf+2; + lf[2].f_choice = LDAP_FILTER_EQUALITY; + lf[2].f_ava = aa+1; + lf[2].f_av_desc = ad_reqDN; + lf[2].f_av_value = op->o_req_ndn; + lf[2].f_next = si->si_logfilter; + + op2.ors_filter = lf; op2.o_callback = &cb; op2.o_bd = select_backend( &op2.o_req_ndn, 1 ); @@ -2204,6 +2258,7 @@ syncrepl_op_modify( Operation *op, SlapReply *rs ) sc->sc_private = mx; sc->sc_next = op->o_callback; sc->sc_cleanup = NULL; + sc->sc_writewait = NULL; op->o_callback = sc; op->orm_no_opattrs = 1; mx->mx_orig = op->orm_modlist; @@ -2225,6 +2280,34 @@ syncrepl_op_modify( Operation *op, SlapReply *rs ) return SLAP_CB_CONTINUE; } +static int +syncrepl_null_callback( + Operation *op, + SlapReply *rs ) +{ + /* If we're not the last callback in the chain, move to the end */ + if ( op->o_callback->sc_next ) { + slap_callback **sc, *s1; + s1 = op->o_callback; + op->o_callback = op->o_callback->sc_next; + for ( sc = &op->o_callback; *sc; sc = &(*sc)->sc_next ) ; + *sc = s1; + s1->sc_next = NULL; + return SLAP_CB_CONTINUE; + } + 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_NOT_ALLOWED_ON_NONLEAF ) + { + Debug( LDAP_DEBUG_ANY, + "syncrepl_null_callback : error code 0x%x\n", + rs->sr_err, 0, 0 ); + } + return LDAP_SUCCESS; +} + static int syncrepl_message_to_op( syncinfo_t *si, @@ -2236,7 +2319,7 @@ syncrepl_message_to_op( Modifications *modlist = NULL; logschema *ls; SlapReply rs = { REP_RESULT }; - slap_callback cb = { NULL, null_callback, NULL, NULL }; + slap_callback cb = { NULL, syncrepl_null_callback, NULL, NULL }; const char *text; char txtbuf[SLAP_TEXT_BUFLEN]; @@ -2330,6 +2413,22 @@ syncrepl_message_to_op( } } else if ( !ber_bvstrcasecmp( &bv, &ls->ls_newSup ) ) { sup = bvals[0]; + } else if ( !ber_bvstrcasecmp( &bv, &ls->ls_controls ) ) { + int i; + struct berval rel_ctrl_bv; + + (void)ber_str2bv( "{" LDAP_CONTROL_RELAX, 0, 0, &rel_ctrl_bv ); + for ( i = 0; bvals[i].bv_val; i++ ) { + struct berval cbv, tmp; + + ber_bvchr_post( &cbv, &bvals[i], '}' ); + ber_bvchr_post( &tmp, &cbv, '{' ); + ber_bvchr_pre( &cbv, &tmp, ' ' ); + if ( cbv.bv_len == tmp.bv_len ) /* control w/o value */ + ber_bvchr_pre( &cbv, &tmp, '}' ); + if ( !ber_bvcmp( &cbv, &rel_ctrl_bv ) ) + op->o_relax = SLAP_CONTROL_CRITICAL; + } } else if ( !ber_bvstrcasecmp( &bv, &slap_schema.si_ad_entryCSN->ad_cname ) ) { @@ -2951,7 +3050,7 @@ syncrepl_entry( slap_sl_free( op->ors_filterstr.bv_val, op->o_tmpmemctx ); } - cb.sc_response = null_callback; + cb.sc_response = syncrepl_null_callback; cb.sc_private = si; if ( entry && !BER_BVISNULL( &entry->e_name ) ) { @@ -3371,7 +3470,7 @@ retry_modrdn:; op->o_delete_glue_parent = 0; if ( !be_issuffix( be, &op->o_req_ndn ) ) { slap_callback cb = { NULL }; - cb.sc_response = slap_null_cb; + cb.sc_response = syncrepl_null_callback; dnParent( &op->o_req_ndn, &pdn ); op->o_req_dn = pdn; op->o_req_ndn = pdn; @@ -3569,7 +3668,7 @@ syncrepl_del_nonpresent( 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_response = syncrepl_null_callback; cb.sc_private = si; op->o_req_dn = *np_prev->npe_name; op->o_req_ndn = *np_prev->npe_nname; @@ -3611,7 +3710,7 @@ syncrepl_del_nonpresent( op->o_delete_glue_parent = 0; if ( !be_issuffix( be, &op->o_req_ndn ) ) { slap_callback cb = { NULL }; - cb.sc_response = slap_null_cb; + cb.sc_response = syncrepl_null_callback; dnParent( &op->o_req_ndn, &pdn ); op->o_req_dn = pdn; op->o_req_ndn = pdn; @@ -3664,7 +3763,7 @@ syncrepl_add_glue_ancestors( op->o_tag = LDAP_REQ_ADD; op->o_callback = &cb; - cb.sc_response = null_callback; + cb.sc_response = syncrepl_null_callback; cb.sc_private = NULL; dn = e->e_name; @@ -3806,7 +3905,7 @@ syncrepl_add_glue( op->o_tag = LDAP_REQ_ADD; op->o_callback = &cb; - cb.sc_response = null_callback; + cb.sc_response = syncrepl_null_callback; cb.sc_private = NULL; op->o_req_dn = e->e_name; @@ -3918,7 +4017,7 @@ syncrepl_updateCookie( op->o_tag = LDAP_REQ_MODIFY; - cb.sc_response = null_callback; + cb.sc_response = syncrepl_null_callback; cb.sc_private = si; op->o_callback = &cb; @@ -4411,24 +4510,6 @@ nonpresent_callback( return LDAP_SUCCESS; } -static int -null_callback( - Operation* op, - SlapReply* rs ) -{ - 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_NOT_ALLOWED_ON_NONLEAF ) - { - Debug( LDAP_DEBUG_ANY, - "null_callback : error code 0x%x\n", - rs->sr_err, 0, 0 ); - } - return LDAP_SUCCESS; -} - static struct berval * slap_uuidstr_from_normalized( struct berval* uuidstr, @@ -4585,6 +4666,9 @@ syncinfo_free( syncinfo_t *sie, int free_all ) if ( sie->si_logfilterstr.bv_val ) { ch_free( sie->si_logfilterstr.bv_val ); } + if ( sie->si_logfilter ) { + filter_free( sie->si_logfilter ); + } if ( sie->si_base.bv_val ) { ch_free( sie->si_base.bv_val ); } @@ -5306,6 +5390,15 @@ parse_syncrepl_line( return 1; } + if ( si->si_got & GOT_LOGFILTER ) { + si->si_logfilter = str2filter( si->si_logfilterstr.bv_val ); + if ( si->si_logfilter == NULL ) { + Debug( LDAP_DEBUG_ANY, "syncrepl %s " SEARCHBASESTR "=\"%s\": unable to parse logfilter=\"%s\"\n", + si->si_ridtxt, c->be->be_suffix ? c->be->be_suffix[ 0 ].bv_val : "(null)", si->si_logfilterstr.bv_val ); + return 1; + } + } + return 0; } @@ -5707,8 +5800,7 @@ syncrepl_config( ConfigArgs *c ) ldap_pvt_runqueue_stoptask( &slapd_rq, re ); isrunning = 1; } - if ( ldap_pvt_thread_pool_retract( &connection_pool, - re->routine, re ) > 0 ) + if ( ldap_pvt_thread_pool_retract( re->pool_cookie ) > 0 ) isrunning = 0; ldap_pvt_runqueue_remove( &slapd_rq, re );