From 6c3715aff99762e7461f358f5b7d8f28e79b255d Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Mon, 29 Nov 2004 09:36:22 +0000 Subject: [PATCH] more on syncprov support --- servers/slapd/back-sql/back-sql.h | 1 + servers/slapd/back-sql/entry-id.c | 14 +++++ servers/slapd/back-sql/search.c | 94 +++++++++++++++++-------------- 3 files changed, 66 insertions(+), 43 deletions(-) diff --git a/servers/slapd/back-sql/back-sql.h b/servers/slapd/back-sql/back-sql.h index af8be8ceba..ae6d02d923 100644 --- a/servers/slapd/back-sql/back-sql.h +++ b/servers/slapd/back-sql/back-sql.h @@ -267,6 +267,7 @@ typedef struct backsql_srch_info { #define BSQL_SF_FILTER_HASSUBORDINATE 0x0002U #define BSQL_SF_FILTER_ENTRYUUID 0x0004U #define BSQL_SF_FILTER_ENTRYCSN 0x0008U +#define BSQL_SF_RETURN_ENTRYUUID (BSQL_SF_FILTER_ENTRYUUID << 8) struct berval *bsi_base_ndn; backsql_entryID bsi_base_id; diff --git a/servers/slapd/back-sql/entry-id.c b/servers/slapd/back-sql/entry-id.c index d359efb577..c229a65c8e 100644 --- a/servers/slapd/back-sql/entry-id.c +++ b/servers/slapd/back-sql/entry-id.c @@ -563,6 +563,20 @@ next:; bsi, 0, AVL_INORDER ); } + if ( bsi->bsi_flags & BSQL_SF_RETURN_ENTRYUUID ) { + Attribute *a_entryUUID, + **ap; + + a_entryUUID = backsql_operational_entryUUID( bi, eid ); + if ( a_entryUUID != NULL ) { + for ( ap = &bsi->bsi_e->e_attrs; + *ap; + ap = &(*ap)->a_next ); + + *ap = a_entryUUID; + } + } + if ( global_schemacheck ) { const char *text = NULL; char textbuf[ 1024 ]; diff --git a/servers/slapd/back-sql/search.c b/servers/slapd/back-sql/search.c index 823fa6bc25..d19633c7e8 100644 --- a/servers/slapd/back-sql/search.c +++ b/servers/slapd/back-sql/search.c @@ -683,15 +683,16 @@ backsql_process_filter( backsql_srch_info *bsi, Filter *f ) goto done; } + /* save for later use in operational attributes */ + bsi->bsi_op->o_private = &f->f_av_value; + + bsi->bsi_flags |= ( BSQL_SF_FILTER_ENTRYCSN | BSQL_SF_RETURN_ENTRYUUID); + /* if doing a syncrepl, try to return as much as possible, * and always match the filter */ backsql_strfcat( &bsi->bsi_flt_where, "l", (ber_len_t)STRLENOF( "1=1" ), "1=1" ); - /* save for later use in operational attributes */ - bsi->bsi_op->o_private = &f->f_av_value; - - bsi->bsi_flags |= BSQL_SF_FILTER_ENTRYCSN; bsi->bsi_status = LDAP_SUCCESS; rc = 1; goto done; @@ -1709,7 +1710,7 @@ backsql_search( Operation *op, SlapReply *rs ) Attribute *a_hasSubordinate = NULL, *a_entryUUID = NULL, *a_entryCSN = NULL, - *a = NULL; + **ap = NULL; Entry *e = NULL; /* check for abandon */ @@ -1741,39 +1742,22 @@ backsql_search( Operation *op, SlapReply *rs ) eid->eid_id, eid->eid_oc_id, eid->eid_keyval ); #endif /* ! BACKSQL_ARBITRARY_KEY */ - /* don't recollect baseObject ... */ - if ( BACKSQL_IS_BASEOBJECT_ID( &eid->eid_id ) ) { - e = bi->sql_baseObject; - - } else { - bsi.bsi_e = &user_entry; - rc = backsql_id2entry( &bsi, eid ); - if ( rc != LDAP_SUCCESS ) { - Debug( LDAP_DEBUG_TRACE, "backsql_search(): " - "error %d in backsql_id2entry() " - "- skipping\n", rc, 0, 0 ); - continue; - } - - e = &user_entry; - } - /* check scope */ switch ( op->ors_scope ) { case LDAP_SCOPE_BASE: case BACKSQL_SCOPE_BASE_LIKE: - if ( !dn_match( &e->e_nname, &op->o_req_ndn ) ) { - goto next_entry; + if ( !dn_match( &eid->eid_ndn, &op->o_req_ndn ) ) { + goto next_entry2; } break; case LDAP_SCOPE_ONE: { - struct berval rdn = user_entry.e_nname; + struct berval rdn = eid->eid_ndn; rdn.bv_len -= op->o_req_ndn.bv_len + STRLENOF( "," ); if ( !dnIsOneLevelRDN( &rdn ) ) { - goto next_entry; + goto next_entry2; } /* fall thru */ } @@ -1781,20 +1765,37 @@ backsql_search( Operation *op, SlapReply *rs ) #ifdef LDAP_SCOPE_SUBORDINATE case LDAP_SCOPE_SUBORDINATE: /* discard the baseObject entry */ - if ( dn_match( &e->e_nname, &op->o_req_ndn ) ) { - goto next_entry; + if ( dn_match( &eid->eid_ndn, &op->o_req_ndn ) ) { + goto next_entry2; } /* FALLTHRU */ #endif /* LDAP_SCOPE_SUBORDINATE */ case LDAP_SCOPE_SUBTREE: /* FIXME: this should never fail... */ - if ( !dnIsSuffix( &e->e_nname, &op->o_req_ndn ) ) { - goto next_entry; + if ( !dnIsSuffix( &eid->eid_ndn, &op->o_req_ndn ) ) { + goto next_entry2; } break; } + /* don't recollect baseObject ... */ + if ( BACKSQL_IS_BASEOBJECT_ID( &eid->eid_id ) ) { + e = bi->sql_baseObject; + + } else { + bsi.bsi_e = &user_entry; + rc = backsql_id2entry( &bsi, eid ); + if ( rc != LDAP_SUCCESS ) { + Debug( LDAP_DEBUG_TRACE, "backsql_search(): " + "error %d in backsql_id2entry() " + "- skipping\n", rc, 0, 0 ); + continue; + } + + e = &user_entry; + } + if ( !manageDSAit && op->ors_scope != LDAP_SCOPE_BASE && op->ors_scope != BACKSQL_SCOPE_BASE_LIKE && @@ -1837,6 +1838,7 @@ backsql_search( Operation *op, SlapReply *rs ) rs->sr_text = "bad_referral object"; } + rs->sr_entry = e; rs->sr_err = LDAP_REFERRAL; rs->sr_matched = user_entry.e_name.bv_val; send_search_reference( op, rs ); @@ -1844,6 +1846,7 @@ backsql_search( Operation *op, SlapReply *rs ) ber_bvarray_free( rs->sr_ref ); rs->sr_ref = NULL; rs->sr_matched = NULL; + rs->sr_entry = NULL; goto next_entry; } @@ -1861,11 +1864,11 @@ backsql_search( Operation *op, SlapReply *rs ) case LDAP_COMPARE_FALSE: a_hasSubordinate = slap_operational_hasSubordinate( rc == LDAP_COMPARE_TRUE ); if ( a_hasSubordinate != NULL ) { - for ( a = user_entry.e_attrs; - a && a->a_next; - a = a->a_next ); + for ( ap = &user_entry.e_attrs; + *ap; + ap = &(*ap)->a_next ); - a->a_next = a_hasSubordinate; + *ap = a_hasSubordinate; } rc = 0; break; @@ -1883,22 +1886,26 @@ backsql_search( Operation *op, SlapReply *rs ) if ( bsi.bsi_flags & BSQL_SF_FILTER_ENTRYUUID ) { a_entryUUID = backsql_operational_entryUUID( bi, eid ); if ( a_entryUUID != NULL ) { - for ( a = user_entry.e_attrs; - a && a->a_next; - a = a->a_next ); + if ( ap == NULL ) { + ap = &user_entry.e_attrs; + } + + for ( ; *ap; ap = &(*ap)->a_next ); - a->a_next = a_entryUUID; + *ap = a_entryUUID; } } if ( bsi.bsi_flags & BSQL_SF_FILTER_ENTRYCSN ) { a_entryCSN = backsql_operational_entryCSN( op ); - if ( a_entryUUID != NULL ) { - for ( a = user_entry.e_attrs; - a && a->a_next; - a = a->a_next ); + if ( a_entryCSN != NULL ) { + if ( ap == NULL ) { + ap = &user_entry.e_attrs; + } + + for ( ; *ap; ap = &(*ap)->a_next ); - a->a_next = a_entryCSN; + *ap = a_entryCSN; } } @@ -1934,6 +1941,7 @@ backsql_search( Operation *op, SlapReply *rs ) next_entry:; entry_clean( &user_entry ); +next_entry2:; if ( op->ors_slimit != SLAP_NO_LIMIT && rs->sr_nentries >= op->ors_slimit ) { -- 2.39.5