static void send_paged_response(
Operation *op,
SlapReply *rs,
- ID lastid,
+ ID *lastid,
int tentries );
/* Dereference aliases for a single alias entry. Return the final
ID cursora, ida, cursoro, ido, *subscop2;
Entry *matched, *a;
EntryInfo *ei;
- struct berval bv_alias = { sizeof("alias")-1, "alias" };
+ struct berval bv_alias = BER_BVC( "alias" );
AttributeAssertion aa_alias;
Filter af;
DB_LOCK locka, lockr;
ida = bdb_idl_next(curscop, &cursora))
{
ei = NULL;
+retry1:
rs->sr_err = bdb_cache_find_id(op, NULL,
ida, &ei, 0, locker, &lockr );
if (rs->sr_err != LDAP_SUCCESS) {
+ if ( rs->sr_err == DB_LOCK_DEADLOCK ||
+ rs->sr_err == DB_LOCK_NOTGRANTED ) goto retry1;
continue;
}
a = ei->bei_e;
* Set the name so that the scope's IDL can be retrieved.
*/
ei = NULL;
+sameido:
rs->sr_err = bdb_cache_find_id(op, NULL, ido, &ei,
0, locker, &locka );
- if ( rs->sr_err != LDAP_SUCCESS ) goto nextido;
+ if ( rs->sr_err != LDAP_SUCCESS ) {
+ if ( rs->sr_err == DB_LOCK_DEADLOCK ||
+ rs->sr_err == DB_LOCK_NOTGRANTED )
+ goto sameido;
+ goto nextido;
+ }
e = ei->bei_e;
}
return rs->sr_err;
return bdb_do_search( op, rs, op, NULL, 0 );
}
+int bdb_psearch( Operation *op, SlapReply *rs, Operation *sop,
+ Entry *ps_e, int ps_type )
+{
+ int rc;
+
+ sop->o_private = op->o_private;
+ rc = bdb_do_search( op, rs, sop, ps_e, ps_type );
+ sop->o_private = NULL;
+
+ return rc;
+}
+
/* For persistent searches, op is the currently executing operation,
* sop is the persistent search. For regular searches, sop = op.
*/
BerVarray syncUUID_set = NULL;
int syncUUID_set_cnt = 0;
+ struct bdb_op_info *opinfo = NULL;
+ DB_TXN *ltid = NULL;
+
#ifdef NEW_LOGGING
LDAP_LOG( OPERATION, ENTRY, "bdb_search\n", 0, 0, 0 );
#else
- Debug( LDAP_DEBUG_TRACE, "=> bdb_search\n",
- 0, 0, 0);
+ Debug( LDAP_DEBUG_TRACE, "=> bdb_search\n", 0, 0, 0);
#endif
attrs = sop->oq_search.rs_attrs;
+ opinfo = (struct bdb_op_info *) op->o_private;
+
if ( !IS_PSEARCH && sop->o_sync_mode & SLAP_SYNC_REFRESH_AND_PERSIST ) {
struct slap_session_entry *sent;
if ( sop->o_sync_state.sid >= 0 ) {
null_attr.an_desc = NULL;
null_attr.an_oc = NULL;
null_attr.an_oc_exclude = 0;
- null_attr.an_name.bv_len = 0;
- null_attr.an_name.bv_val = NULL;
+ BER_BVZERO( &null_attr.an_name );
for( num_ctrls = 0; num_ctrls < SLAP_MAX_RESPONSE_CONTROLS; num_ctrls++ ) {
ctrls[num_ctrls] = NULL;
attrs[0].an_desc = NULL;
attrs[0].an_oc = NULL;
attrs[0].an_oc_exclude = 0;
- attrs[0].an_name.bv_len = 0;
- attrs[0].an_name.bv_val = NULL;
+ BER_BVZERO( &attrs[0].an_name );
}
manageDSAit = get_manageDSAit( sop );
}
}
- rs->sr_err = LOCK_ID( bdb->bi_dbenv, &locker );
+ if ( opinfo ) {
+ ltid = opinfo->boi_txn;
+ locker = TXN_ID( ltid );
+ } else {
+ rs->sr_err = LOCK_ID( bdb->bi_dbenv, &locker );
- switch(rs->sr_err) {
- case 0:
- break;
- default:
- send_ldap_error( sop, rs, LDAP_OTHER, "internal error" );
- return rs->sr_err;
+ switch(rs->sr_err) {
+ case 0:
+ break;
+ default:
+ send_ldap_error( sop, rs, LDAP_OTHER, "internal error" );
+ return rs->sr_err;
+ }
}
if ( sop->o_req_ndn.bv_len == 0 ) {
ei_root.bei_parent = &ei_root;
e_root.e_private = &ei_root;
e_root.e_id = 0;
- e_root.e_nname.bv_val="";
- e_root.e_name.bv_val="";
+ BER_BVSTR( &e_root.e_nname, "" );
+ BER_BVSTR( &e_root.e_name, "" );
ei = &ei_root;
rs->sr_err = LDAP_SUCCESS;
} else {
dn2entry_retry:
/* get entry with reader lock */
- rs->sr_err = bdb_dn2entry( op, NULL, &sop->o_req_ndn, &ei,
+ rs->sr_err = bdb_dn2entry( op, ltid, &sop->o_req_ndn, &ei,
1, locker, &lock );
}
break;
case LDAP_BUSY:
send_ldap_error( sop, rs, LDAP_BUSY, "ldap server busy" );
- LOCK_ID_FREE (bdb->bi_dbenv, locker );
+ if ( !opinfo )
+ LOCK_ID_FREE (bdb->bi_dbenv, locker );
return LDAP_BUSY;
case DB_LOCK_DEADLOCK:
case DB_LOCK_NOTGRANTED:
goto dn2entry_retry;
default:
send_ldap_error( sop, rs, LDAP_OTHER, "internal error" );
- LOCK_ID_FREE (bdb->bi_dbenv, locker );
+ if ( !opinfo )
+ LOCK_ID_FREE (bdb->bi_dbenv, locker );
return rs->sr_err;
}
rs->sr_matched = matched_dn.bv_val;
send_ldap_result( sop, rs );
- LOCK_ID_FREE (bdb->bi_dbenv, locker );
+ if ( !opinfo )
+ LOCK_ID_FREE (bdb->bi_dbenv, locker );
if ( rs->sr_ref ) {
ber_bvarray_free( rs->sr_ref );
rs->sr_ref = NULL;
rs->sr_matched = matched_dn.bv_val;
send_ldap_result( sop, rs );
- LOCK_ID_FREE (bdb->bi_dbenv, locker );
+ if ( !opinfo )
+ LOCK_ID_FREE (bdb->bi_dbenv, locker );
ber_bvarray_free( rs->sr_ref );
rs->sr_ref = NULL;
ber_memfree( matched_dn.bv_val );
tentries = BDB_IDL_N(candidates);
}
- if ( get_pagedresults(sop) ) {
+ if ( get_pagedresults(sop) > SLAP_NO_CONTROL ) {
if ( (ID)( sop->o_pagedresults_state.ps_cookie ) == 0 ) {
id = bdb_idl_first( candidates, &cursor );
"bdb_search: no paged results candidates\n",
0, 0, 0 );
#endif
- send_paged_response( sop, rs, lastid, 0 );
+ send_paged_response( sop, rs, &lastid, 0 );
rs->sr_err = LDAP_OTHER;
goto done;
id2entry_retry:
/* get the entry with reader lock */
ei = NULL;
- rs->sr_err = bdb_cache_find_id( op, NULL,
+ rs->sr_err = bdb_cache_find_id( op, ltid,
id, &ei, 0, locker, &lock );
if (rs->sr_err == LDAP_BUSY) {
goto done;
}
- if ( get_pagedresults(sop) ) {
+ if ( get_pagedresults(sop) > SLAP_NO_CONTROL ) {
if ( rs->sr_nentries >= sop->o_pagedresults_size ) {
- send_paged_response( sop, rs, lastid, tentries );
+ send_paged_response( sop, rs, &lastid, tentries );
goto done;
}
lastid = id;
rs->sr_ref = rs->sr_v2ref;
rs->sr_err = (rs->sr_v2ref == NULL) ? LDAP_SUCCESS : LDAP_REFERRAL;
rs->sr_rspoid = NULL;
- send_ldap_result( sop, rs );
+ if ( get_pagedresults(sop) > SLAP_NO_CONTROL ) {
+ send_paged_response( sop, rs, NULL, 0 );
+ } else {
+ send_ldap_result( sop, rs );
+ }
}
}
bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
}
- LOCK_ID_FREE( bdb->bi_dbenv, locker );
+ if ( !opinfo )
+ LOCK_ID_FREE( bdb->bi_dbenv, locker );
ber_bvfree( search_context_csn );
{
if( !get_manageDSAit(op) && !get_domainScope(op) ) {
/* match referral objects */
- struct berval bv_ref = { sizeof("referral")-1, "referral" };
+ struct berval bv_ref = BER_BVC( "referral" );
rf.f_choice = LDAP_FILTER_EQUALITY;
rf.f_ava = &aa_ref;
rf.f_av_desc = slap_schema.si_ad_objectClass;
#ifdef BDB_SUBENTRIES
if( get_subentries_visibility( op ) ) {
- struct berval bv_subentry = { sizeof("SUBENTRY")-1, "SUBENTRY" };
+ struct berval bv_subentry = BER_BVC( "SUBENTRY" );
sf.f_choice = LDAP_FILTER_EQUALITY;
sf.f_ava = &aa_subentry;
sf.f_av_desc = slap_schema.si_ad_objectClass;
send_paged_response(
Operation *op,
SlapReply *rs,
- ID lastid,
+ ID *lastid,
int tentries )
{
LDAPControl ctrl, *ctrls[2];
BerElementBuffer berbuf;
BerElement *ber = (BerElement *)&berbuf;
- struct berval cookie = BER_BVNULL;
PagedResultsCookie respcookie;
+ struct berval cookie;
#ifdef NEW_LOGGING
LDAP_LOG ( OPERATION, ENTRY,
- "send_paged_response: lastid: (0x%08lx) "
- "nentries: (0x%081x)\n",
- lastid, rs->sr_nentries, NULL );
+ "send_paged_response: lastid=0x%08lx nentries=%d\n",
+ lastid ? *lastid : 0, rs->sr_nentries, NULL );
#else
- Debug(LDAP_DEBUG_ARGS, "send_paged_response: lastid: (0x%08lx) "
- "nentries: (0x%081x)\n", lastid, rs->sr_nentries, NULL );
+ Debug(LDAP_DEBUG_ARGS,
+ "send_paged_response: lastid=0x%08lx nentries=%d\n",
+ lastid ? *lastid : 0, rs->sr_nentries, NULL );
#endif
- ctrl.ldctl_value.bv_val = NULL;
+ BER_BVZERO( &ctrl.ldctl_value );
ctrls[0] = &ctrl;
ctrls[1] = NULL;
ber_init2( ber, NULL, LBER_USE_DER );
- respcookie = ( PagedResultsCookie )lastid;
+ if ( lastid ) {
+ respcookie = ( PagedResultsCookie )(*lastid);
+ cookie.bv_len = sizeof( respcookie );
+ cookie.bv_val = (char *)&respcookie;
+
+ } else {
+ respcookie = ( PagedResultsCookie )0;
+ BER_BVSTR( &cookie, "" );
+ }
+
op->o_conn->c_pagedresults_state.ps_cookie = respcookie;
op->o_conn->c_pagedresults_state.ps_count =
op->o_pagedresults_state.ps_count + rs->sr_nentries;
- cookie.bv_len = sizeof( respcookie );
- cookie.bv_val = (char *)&respcookie;
- /*
- * FIXME: we should consider sending an estimate of the entries
- * left, after appropriate security check is done
- */
- ber_printf( ber, "{iO}", tentries, &cookie );
+ /* return size of 0 -- no estimate */
+ ber_printf( ber, "{iO}", 0, &cookie );
if ( ber_flatten2( ber, &ctrls[0]->ldctl_value, 0 ) == -1 ) {
goto done;