X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Foverlays%2Fsssvlv.c;h=543d00f2c180b2354878121e1c73fa572d46342a;hb=a255e44bf0fcb703a3a5ac58117fd54a00727fd1;hp=ab52b3a3fe5eed112f22c3954b929ecaaabad7df;hpb=7761c923bab53870802c287611b17bb906ce3a0b;p=openldap diff --git a/servers/slapd/overlays/sssvlv.c b/servers/slapd/overlays/sssvlv.c index ab52b3a3fe..543d00f2c1 100644 --- a/servers/slapd/overlays/sssvlv.c +++ b/servers/slapd/overlays/sssvlv.c @@ -2,7 +2,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 2009-2011 The OpenLDAP Foundation. + * Copyright 2009-2012 The OpenLDAP Foundation. * Portions copyright 2009 Symas Corporation. * All rights reserved. * @@ -341,6 +341,23 @@ static int pack_sss_response_control( return rs->sr_err; } +/* Return the session id or -1 if unknown */ +static int find_session_by_so( + int svi_max_percon, + int conn_id, + sort_op *so ) +{ + int sess_id; + if (so == NULL) { + return -1; + } + for (sess_id = 0; sess_id < svi_max_percon; sess_id++) { + if ( sort_conns[conn_id] && sort_conns[conn_id][sess_id] == so ) + return sess_id; + } + return -1; +} + /* Return the session id or -1 if unknown */ static int find_session_by_context( int svi_max_percon, @@ -379,14 +396,13 @@ static int find_next_session( static void free_sort_op( Connection *conn, sort_op *so ) { int sess_id; - PagedResultsCookie ps_cookie = (PagedResultsCookie) so->so_tree; if ( so->so_tree ) { tavl_free( so->so_tree, ch_free ); so->so_tree = NULL; } ldap_pvt_thread_mutex_lock( &sort_conns_mutex ); - sess_id = find_session_by_context( so->so_info->svi_max_percon, conn->c_conn_idx, so->so_vcontext, ps_cookie ); + sess_id = find_session_by_so( so->so_info->svi_max_percon, conn->c_conn_idx, so ); sort_conns[conn->c_conn_idx][sess_id] = NULL; so->so_info->svi_num--; ldap_pvt_thread_mutex_unlock( &sort_conns_mutex ); @@ -420,6 +436,8 @@ static void send_list( Entry *e; LDAPControl *ctrls[2]; + rs->sr_attrs = op->ors_attrs; + /* FIXME: it may be better to just flatten the tree into * an array before doing all of this... */ @@ -492,15 +510,17 @@ range_err: sc->sc_nkeys * sizeof(struct berval), op->o_tmpmemctx ); sn->sn_vals = (struct berval *)(sn+1); sn->sn_conn = op->o_conn->c_conn_idx; - sn->sn_session = find_session_by_context( so->so_info->svi_max_percon, op->o_conn->c_conn_idx, vc->vc_context, NO_PS_COOKIE ); + sn->sn_session = find_session_by_so( so->so_info->svi_max_percon, op->o_conn->c_conn_idx, so ); sn->sn_vals[0] = bv; for (i=1; isc_nkeys; i++) { BER_BVZERO( &sn->sn_vals[i] ); } cur_node = tavl_find3( so->so_tree, sn, node_cmp, &j ); /* didn't find >= match */ - if ( j > 0 ) - cur_node = NULL; + if ( j > 0 ) { + if ( cur_node ) + cur_node = tavl_next( cur_node, TAVL_DIR_RIGHT ); + } op->o_tmpfree( sn, op->o_tmpmemctx ); if ( !cur_node ) { @@ -518,7 +538,7 @@ range_err: } for (i=0; tmp_node != cur_node; tmp_node = tavl_next( tmp_node, dir ), i++); - so->so_vlv_target = i; + so->so_vlv_target = (dir == TAVL_DIR_RIGHT) ? i+1 : so->so_nentries - i; } if ( bv.bv_val != vc->vc_value.bv_val ) op->o_tmpfree( bv.bv_val, op->o_tmpmemctx ); @@ -568,6 +588,8 @@ static void send_page( Operation *op, SlapReply *rs, sort_op *so ) Entry *e; int rc; + rs->sr_attrs = op->ors_attrs; + while ( cur_node && rs->sr_nentries < so->so_page_size ) { sort_node *sn = cur_node->avl_data; @@ -731,7 +753,7 @@ static int sssvlv_op_response( op->o_tmpfree( sn, op->o_tmpmemctx ); sn = sn2; sn->sn_conn = op->o_conn->c_conn_idx; - sn->sn_session = find_session_by_context( so->so_info->svi_max_percon, op->o_conn->c_conn_idx, so->so_vcontext, (PagedResultsCookie) so->so_tree ); + sn->sn_session = find_session_by_so( so->so_info->svi_max_percon, op->o_conn->c_conn_idx, so ); /* Insert into the AVL tree */ tavl_insert(&(so->so_tree), sn, node_insert, avl_dup_error); @@ -857,6 +879,9 @@ static int sssvlv_op_search( } ldap_pvt_thread_mutex_unlock( &sort_conns_mutex ); if ( ok ) { + /* If we're a global overlay, this check got bypassed */ + if ( !op->ors_limit && limits_check( op, rs )) + return rs->sr_err; /* are we continuing a VLV search? */ if ( so && vc && vc->vc_context ) { so->so_ctrl = sc; @@ -1276,6 +1301,10 @@ static int sssvlv_db_init( if ( rc != LDAP_SUCCESS ) { Debug( LDAP_DEBUG_ANY, "Failed to register VLV Request control '%s' (%d)\n", LDAP_CONTROL_VLVREQUEST, rc, 0 ); +#ifdef SLAP_CONFIG_DELETE + overlay_unregister_control( be, LDAP_CONTROL_SORTREQUEST ); + unregister_supported_control( LDAP_CONTROL_SORTREQUEST ); +#endif /* SLAP_CONFIG_DELETE */ return rc; } } @@ -1300,7 +1329,7 @@ static int sssvlv_db_destroy( slap_overinst *on = (slap_overinst *)be->bd_info; sssvlv_info *si = (sssvlv_info *)on->on_bi.bi_private; int conn_index; - + ov_count--; if ( !ov_count && sort_conns) { sort_conns--; @@ -1311,6 +1340,15 @@ static int sssvlv_db_destroy( ldap_pvt_thread_mutex_destroy( &sort_conns_mutex ); } +#ifdef SLAP_CONFIG_DELETE + overlay_unregister_control( be, LDAP_CONTROL_SORTREQUEST ); + overlay_unregister_control( be, LDAP_CONTROL_VLVREQUEST ); + if ( ov_count == 0 ) { + unregister_supported_control( LDAP_CONTROL_SORTREQUEST ); + unregister_supported_control( LDAP_CONTROL_VLVREQUEST ); + } +#endif /* SLAP_CONFIG_DELETE */ + if ( si ) { ch_free( si ); on->on_bi.bi_private = NULL;