1 /* search.c - ldap backend search function */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1999-2009 The OpenLDAP Foundation.
6 * Portions Copyright 1999-2003 Howard Chu.
7 * Portions Copyright 2000-2003 Pierangelo Masarati.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted only as authorized by the OpenLDAP
14 * A copy of this license is available in the file LICENSE in the
15 * top-level directory of the distribution or, alternatively, at
16 * <http://www.OpenLDAP.org/license.html>.
19 * This work was initially developed by the Howard Chu for inclusion
20 * in OpenLDAP Software and subsequently enhanced by Pierangelo
28 #include <ac/socket.h>
29 #include <ac/string.h>
33 #include "back-ldap.h"
34 #undef ldap_debug /* silence a warning in ldap-int.h */
35 #include "../../../libraries/libldap/ldap-int.h"
40 ldap_build_entry( Operation *op, LDAPMessage *e, Entry *ent,
44 * Quick'n'dirty rewrite of filter in case of error, to deal with
45 * <draft-zeilenga-ldap-t-f>.
48 ldap_back_munge_filter(
50 struct berval *filter,
53 ldapinfo_t *li = (ldapinfo_t *) op->o_bd->be_private;
58 Debug( LDAP_DEBUG_ARGS, "=> ldap_back_munge_filter \"%s\"\n",
59 filter->bv_val, 0, 0 );
61 for ( ptr = strstr( filter->bv_val, "(?=" );
63 ptr = strstr( ptr, "(?=" ) )
66 bv_true = BER_BVC( "(?=true)" ),
67 bv_false = BER_BVC( "(?=false)" ),
68 bv_undefined = BER_BVC( "(?=undefined)" ),
69 bv_t = BER_BVC( "(&)" ),
70 bv_f = BER_BVC( "(|)" ),
71 bv_T = BER_BVC( "(objectClass=*)" ),
72 bv_F = BER_BVC( "(!(objectClass=*))" );
73 struct berval *oldbv = NULL,
75 oldfilter = BER_BVNULL;
77 if ( strncmp( ptr, bv_true.bv_val, bv_true.bv_len ) == 0 ) {
79 if ( LDAP_BACK_T_F( li ) ) {
86 } else if ( strncmp( ptr, bv_false.bv_val, bv_false.bv_len ) == 0 )
89 if ( LDAP_BACK_T_F( li ) ) {
96 } else if ( strncmp( ptr, bv_undefined.bv_val, bv_undefined.bv_len ) == 0 )
98 /* if undef or invalid filter is not allowed,
99 * don't rewrite filter */
100 if ( LDAP_BACK_NOUNDEFFILTER( li ) ) {
101 if ( filter->bv_val != op->ors_filterstr.bv_val ) {
102 op->o_tmpfree( filter->bv_val, op->o_tmpmemctx );
104 BER_BVZERO( filter );
109 oldbv = &bv_undefined;
118 filter->bv_len += newbv->bv_len - oldbv->bv_len;
119 if ( filter->bv_val == op->ors_filterstr.bv_val ) {
120 filter->bv_val = op->o_tmpalloc( filter->bv_len + 1,
123 AC_MEMCPY( filter->bv_val, op->ors_filterstr.bv_val,
124 op->ors_filterstr.bv_len + 1 );
128 filter->bv_val = op->o_tmprealloc( filter->bv_val,
129 filter->bv_len + 1, op->o_tmpmemctx );
132 ptr = filter->bv_val + ( ptr - oldfilter.bv_val );
134 AC_MEMCPY( &ptr[ newbv->bv_len ],
135 &ptr[ oldbv->bv_len ],
136 oldfilter.bv_len - ( ptr - filter->bv_val ) - oldbv->bv_len + 1 );
137 AC_MEMCPY( ptr, newbv->bv_val, newbv->bv_len );
139 ptr += newbv->bv_len;
144 Debug( LDAP_DEBUG_ARGS, "<= ldap_back_munge_filter \"%s\" (%d)\n",
145 filter->bv_val, gotit, 0 );
155 ldapinfo_t *li = (ldapinfo_t *) op->o_bd->be_private;
157 ldapconn_t *lc = NULL;
159 time_t stoptime = (time_t)(-1);
164 struct berval match = BER_BVNULL,
168 int freetext = 0, freefilter = 0;
169 int do_retry = 1, dont_retry = 0;
170 LDAPControl **ctrls = NULL;
171 char **references = NULL;
173 /* FIXME: shouldn't this be null? */
174 const char *save_matched = rs->sr_matched;
176 if ( !ldap_back_dobind( &lc, op, rs, LDAP_BACK_SENDERR ) ) {
181 * FIXME: in case of values return filter, we might want
182 * to map attrs and maybe rewrite value
185 if ( op->ors_tlimit != SLAP_NO_LIMIT ) {
186 tv.tv_sec = op->ors_tlimit;
188 stoptime = op->o_time + op->ors_tlimit;
191 LDAP_BACK_TV_SET( &tv );
194 if ( op->ors_attrs ) {
195 for ( i = 0; !BER_BVISNULL( &op->ors_attrs[i].an_name ); i++ )
196 /* just count attrs */ ;
198 attrs = ch_malloc( ( i + 1 )*sizeof( char * ) );
199 if ( attrs == NULL ) {
200 rs->sr_err = LDAP_NO_MEMORY;
205 for ( i = 0; !BER_BVISNULL( &op->ors_attrs[i].an_name ); i++ ) {
206 attrs[ i ] = op->ors_attrs[i].an_name.bv_val;
212 rc = ldap_back_controls_add( op, rs, lc, &ctrls );
213 if ( rc != LDAP_SUCCESS ) {
217 /* deal with <draft-zeilenga-ldap-t-f> filters */
218 filter = op->ors_filterstr;
220 rs->sr_err = ldap_pvt_search( lc->lc_ld, op->o_req_dn.bv_val,
221 op->ors_scope, filter.bv_val,
222 attrs, op->ors_attrsonly, ctrls, NULL,
223 tv.tv_sec ? &tv : NULL,
224 op->ors_slimit, op->ors_deref, &msgid );
226 if ( rs->sr_err != LDAP_SUCCESS ) {
227 switch ( rs->sr_err ) {
228 case LDAP_SERVER_DOWN:
231 if ( ldap_back_retry( &lc, op, rs, LDAP_BACK_DONTSEND ) ) {
237 /* reset by ldap_back_retry ... */
238 rs->sr_err = slap_map_api2result( rs );
241 rc = ldap_back_op_result( lc, op, rs, msgid, 0, LDAP_BACK_DONTSEND );
246 case LDAP_FILTER_ERROR:
247 if (ldap_back_munge_filter( op, &filter, &freefilter ) > 0 ) {
251 /* invalid filters return success with no data */
252 rs->sr_err = LDAP_SUCCESS;
257 rs->sr_err = slap_map_api2result( rs );
263 /* if needed, initialize timeout */
264 if ( li->li_timeout[ SLAP_OP_SEARCH ] ) {
265 if ( tv.tv_sec == 0 || tv.tv_sec > li->li_timeout[ SLAP_OP_SEARCH ] ) {
266 tv.tv_sec = li->li_timeout[ SLAP_OP_SEARCH ];
271 /* We pull apart the ber result, stuff it into a slapd entry, and
272 * let send_search_entry stuff it back into ber format. Slow & ugly,
273 * but this is necessary for version matching, and for ACL processing.
276 for ( rc = -2; rc != -1; rc = ldap_result( lc->lc_ld, msgid, LDAP_MSG_ONE, &tv, &res ) )
278 /* check for abandon */
279 if ( op->o_abandon || LDAP_BACK_CONN_ABANDON( lc ) ) {
283 (void)ldap_back_cancel( lc, op, rs, msgid, LDAP_BACK_DONTSEND );
288 if ( rc == 0 || rc == -2 ) {
289 ldap_pvt_thread_yield();
292 if ( li->li_timeout[ SLAP_OP_SEARCH ] ) {
294 (void)ldap_back_cancel( lc, op, rs, msgid, LDAP_BACK_DONTSEND );
295 rs->sr_text = "Operation timed out";
296 rc = rs->sr_err = op->o_protocol >= LDAP_VERSION3 ?
297 LDAP_ADMINLIMIT_EXCEEDED : LDAP_OTHER;
302 LDAP_BACK_TV_SET( &tv );
305 /* check time limit */
306 if ( op->ors_tlimit != SLAP_NO_LIMIT
307 && slap_get_time() > stoptime )
309 (void)ldap_back_cancel( lc, op, rs, msgid, LDAP_BACK_DONTSEND );
310 rc = rs->sr_err = LDAP_TIMELIMIT_EXCEEDED;
316 /* only touch when activity actually took place... */
317 if ( li->li_idle_timeout && lc ) {
318 lc->lc_time = op->o_time;
321 /* don't retry any more */
326 if ( rc == LDAP_RES_SEARCH_ENTRY ) {
328 struct berval bdn = BER_BVNULL;
332 e = ldap_first_entry( lc->lc_ld, res );
333 rc = ldap_build_entry( op, e, &ent, &bdn );
334 if ( rc == LDAP_SUCCESS ) {
335 ldap_get_entry_controls( lc->lc_ld, res, &rs->sr_ctrls );
337 rs->sr_attrs = op->ors_attrs;
338 rs->sr_operational_attrs = NULL;
340 rs->sr_err = LDAP_SUCCESS;
341 rc = rs->sr_err = send_search_entry( op, rs );
342 if ( rs->sr_ctrls ) {
343 ldap_controls_free( rs->sr_ctrls );
347 if ( !BER_BVISNULL( &ent.e_name ) ) {
348 assert( ent.e_name.bv_val != bdn.bv_val );
349 op->o_tmpfree( ent.e_name.bv_val, op->o_tmpmemctx );
350 BER_BVZERO( &ent.e_name );
352 if ( !BER_BVISNULL( &ent.e_nname ) ) {
353 op->o_tmpfree( ent.e_nname.bv_val, op->o_tmpmemctx );
354 BER_BVZERO( &ent.e_nname );
361 case LDAP_INSUFFICIENT_ACCESS:
365 if ( rc == LDAP_UNAVAILABLE ) {
366 rc = rs->sr_err = LDAP_OTHER;
368 (void)ldap_back_cancel( lc, op, rs, msgid, LDAP_BACK_DONTSEND );
373 } else if ( rc == LDAP_RES_SEARCH_REFERENCE ) {
374 if ( LDAP_BACK_NOREFS( li ) ) {
380 rc = ldap_parse_reference( lc->lc_ld, res,
381 &references, &rs->sr_ctrls, 1 );
383 if ( rc != LDAP_SUCCESS ) {
387 /* FIXME: there MUST be at least one */
388 if ( references && references[ 0 ] && references[ 0 ][ 0 ] ) {
391 for ( cnt = 0; references[ cnt ]; cnt++ )
394 /* FIXME: there MUST be at least one */
395 rs->sr_ref = op->o_tmpalloc( ( cnt + 1 ) * sizeof( struct berval ),
398 for ( cnt = 0; references[ cnt ]; cnt++ ) {
399 ber_str2bv( references[ cnt ], 0, 0, &rs->sr_ref[ cnt ] );
401 BER_BVZERO( &rs->sr_ref[ cnt ] );
403 /* ignore return value by now */
405 ( void )send_search_reference( op, rs );
408 Debug( LDAP_DEBUG_ANY,
409 "%s ldap_back_search: "
410 "got SEARCH_REFERENCE "
411 "with no referrals\n",
412 op->o_log_prefix, 0, 0 );
417 ber_memvfree( (void **)references );
418 op->o_tmpfree( rs->sr_ref, op->o_tmpmemctx );
423 if ( rs->sr_ctrls ) {
424 ldap_controls_free( rs->sr_ctrls );
428 } else if ( rc == LDAP_RES_INTERMEDIATE ) {
429 /* FIXME: response controls
430 * are passed without checks */
431 rc = ldap_parse_intermediate( lc->lc_ld,
433 (char **)&rs->sr_rspoid,
437 if ( rc != LDAP_SUCCESS ) {
441 slap_send_ldap_intermediate( op, rs );
443 if ( rs->sr_rspoid != NULL ) {
444 ber_memfree( (char *)rs->sr_rspoid );
445 rs->sr_rspoid = NULL;
448 if ( rs->sr_rspdata != NULL ) {
449 ber_bvfree( rs->sr_rspdata );
450 rs->sr_rspdata = NULL;
453 if ( rs->sr_ctrls != NULL ) {
454 ldap_controls_free( rs->sr_ctrls );
461 rc = ldap_parse_result( lc->lc_ld, res, &rs->sr_err,
463 &references, &rs->sr_ctrls, 1 );
464 if ( rc != LDAP_SUCCESS ) {
467 rs->sr_err = slap_map_api2result( rs );
473 /* RFC 4511: referrals can only appear
474 * if result code is LDAP_REFERRAL */
477 && references[ 0 ][ 0 ] )
479 if ( rs->sr_err != LDAP_REFERRAL ) {
480 Debug( LDAP_DEBUG_ANY,
481 "%s ldap_back_search: "
482 "got referrals with err=%d\n",
489 for ( cnt = 0; references[ cnt ]; cnt++ )
492 rs->sr_ref = op->o_tmpalloc( ( cnt + 1 ) * sizeof( struct berval ),
495 for ( cnt = 0; references[ cnt ]; cnt++ ) {
497 ber_str2bv( references[ cnt ], 0, 0, &rs->sr_ref[ cnt ] );
499 BER_BVZERO( &rs->sr_ref[ cnt ] );
502 } else if ( rs->sr_err == LDAP_REFERRAL ) {
503 Debug( LDAP_DEBUG_ANY,
504 "%s ldap_back_search: "
505 "got err=%d with null "
506 "or empty referrals\n",
510 rs->sr_err = LDAP_NO_SUCH_OBJECT;
513 if ( match.bv_val != NULL ) {
514 match.bv_len = strlen( match.bv_val );
521 /* if needed, restore timeout */
522 if ( li->li_timeout[ SLAP_OP_SEARCH ] ) {
523 if ( tv.tv_sec == 0 || tv.tv_sec > li->li_timeout[ SLAP_OP_SEARCH ] ) {
524 tv.tv_sec = li->li_timeout[ SLAP_OP_SEARCH ];
530 if ( rc == -1 && dont_retry == 0 ) {
533 if ( ldap_back_retry( &lc, op, rs, LDAP_BACK_DONTSEND ) ) {
537 rs->sr_err = LDAP_SERVER_DOWN;
538 rs->sr_err = slap_map_api2result( rs );
543 * Rewrite the matched portion of the search base, if required
545 if ( !BER_BVISNULL( &match ) && !BER_BVISEMPTY( &match ) ) {
546 struct berval pmatch;
548 if ( dnPretty( NULL, &match, &pmatch, op->o_tmpmemctx ) == LDAP_SUCCESS ) {
549 rs->sr_matched = pmatch.bv_val;
550 LDAP_FREE( match.bv_val );
553 rs->sr_matched = match.bv_val;
557 if ( rs->sr_v2ref ) {
558 rs->sr_err = LDAP_REFERRAL;
562 if ( LDAP_BACK_QUARANTINE( li ) ) {
563 ldap_back_quarantine( op, rs );
566 if ( freefilter && filter.bv_val != op->ors_filterstr.bv_val ) {
567 op->o_tmpfree( filter.bv_val, op->o_tmpmemctx );
571 /* let send_ldap_result play cleanup handlers (ITS#4645) */
572 if ( rc != SLAPD_ABANDON )
575 send_ldap_result( op, rs );
578 (void)ldap_back_controls_free( op, rs, &ctrls );
580 if ( rs->sr_ctrls ) {
581 ldap_controls_free( rs->sr_ctrls );
585 if ( rs->sr_matched != NULL && rs->sr_matched != save_matched ) {
586 if ( rs->sr_matched != match.bv_val ) {
587 ber_memfree_x( (char *)rs->sr_matched, op->o_tmpmemctx );
590 LDAP_FREE( match.bv_val );
592 rs->sr_matched = save_matched;
597 LDAP_FREE( (char *)rs->sr_text );
603 op->o_tmpfree( rs->sr_ref, op->o_tmpmemctx );
608 ber_memvfree( (void **)references );
616 ldap_back_release_conn( li, lc );
630 BerElement ber = *e->lm_ber;
631 Attribute *attr, **attrp;
637 /* safe assumptions ... */
638 assert( ent != NULL );
639 BER_BVZERO( &ent->e_bv );
641 if ( ber_scanf( &ber, "{m", bdn ) == LBER_ERROR ) {
642 return LDAP_DECODING_ERROR;
646 * Note: this may fail if the target host(s) schema differs
647 * from the one known to the meta, and a DN with unknown
648 * attributes is returned.
650 * FIXME: should we log anything, or delegate to dnNormalize?
652 /* Note: if the distinguished values or the naming attributes
653 * change, should we massage them as well?
655 if ( dnPrettyNormal( NULL, bdn, &ent->e_name, &ent->e_nname,
656 op->o_tmpmemctx ) != LDAP_SUCCESS )
658 return LDAP_INVALID_DN_SYNTAX;
662 if ( ber_first_element( &ber, &len, &lastb ) != LBER_SEQUENCE ) {
666 attrp = &ent->e_attrs;
667 while ( ber_next_element( &ber, &len, lastb ) == LBER_SEQUENCE &&
668 ber_scanf( &ber, "{m", &a ) != LBER_ERROR ) {
670 slap_syntax_validate_func *validate;
671 slap_syntax_transform_func *pretty;
673 attr = attr_alloc( NULL );
674 if ( attr == NULL ) {
677 if ( slap_bv2ad( &a, &attr->a_desc, &text )
680 if ( slap_bv2undef_ad( &a, &attr->a_desc, &text,
681 SLAP_AD_PROXIED ) != LDAP_SUCCESS )
683 Debug( LDAP_DEBUG_ANY,
684 "%s ldap_build_entry: "
685 "slap_bv2undef_ad(%s): %s\n",
686 op->o_log_prefix, a.bv_val, text );
688 ( void )ber_scanf( &ber, "x" /* [W] */ );
694 /* no subschemaSubentry */
695 if ( attr->a_desc == slap_schema.si_ad_subschemaSubentry
696 || attr->a_desc == slap_schema.si_ad_entryDN )
700 * We eat target's subschemaSubentry because
701 * a search for this value is likely not
702 * to resolve to the appropriate backend;
703 * later, the local subschemaSubentry is
706 * We also eat entryDN because the frontend
707 * will reattach it without checking if already
710 ( void )ber_scanf( &ber, "x" /* [W] */ );
715 if ( ber_scanf( &ber, "[W]", &attr->a_vals ) == LBER_ERROR
716 || attr->a_vals == NULL )
719 * Note: attr->a_vals can be null when using
720 * values result filter
722 attr->a_vals = (struct berval *)&slap_dummy_bv;
725 validate = attr->a_desc->ad_type->sat_syntax->ssyn_validate;
726 pretty = attr->a_desc->ad_type->sat_syntax->ssyn_pretty;
728 if ( !validate && !pretty ) {
729 attr->a_nvals = NULL;
734 for ( i = 0; !BER_BVISNULL( &attr->a_vals[i] ); i++ ) ;
738 * check that each value is valid per syntax
739 * and pretty if appropriate
741 for ( i = 0; i<last; i++ ) {
746 rc = pretty( attr->a_desc->ad_type->sat_syntax,
747 &attr->a_vals[i], &pval, NULL );
750 rc = validate( attr->a_desc->ad_type->sat_syntax,
754 if ( rc != LDAP_SUCCESS ) {
757 /* check if, by chance, it's an undefined objectClass */
758 if ( attr->a_desc == slap_schema.si_ad_objectClass &&
759 ( oc = oc_bvfind_undef( &attr->a_vals[i] ) ) != NULL )
761 ber_dupbv( &pval, &oc->soc_cname );
764 LBER_FREE( attr->a_vals[i].bv_val );
766 BER_BVZERO( &attr->a_vals[i] );
769 attr->a_vals[i] = attr->a_vals[last];
770 BER_BVZERO( &attr->a_vals[last] );
774 } else if ( pretty ) {
775 LBER_FREE( attr->a_vals[i].bv_val );
776 attr->a_vals[i] = pval;
779 attr->a_numvals = last = i;
780 if ( last == 0 && attr->a_vals != &slap_dummy_bv ) {
781 attr->a_nvals = NULL;
786 if ( last && attr->a_desc->ad_type->sat_equality &&
787 attr->a_desc->ad_type->sat_equality->smr_normalize )
789 attr->a_nvals = ch_malloc( ( last + 1 )*sizeof( struct berval ) );
790 for ( i = 0; i < last; i++ ) {
793 rc = attr->a_desc->ad_type->sat_equality->smr_normalize(
794 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
795 attr->a_desc->ad_type->sat_syntax,
796 attr->a_desc->ad_type->sat_equality,
797 &attr->a_vals[i], &attr->a_nvals[i],
800 if ( rc != LDAP_SUCCESS ) {
801 LBER_FREE( attr->a_vals[i].bv_val );
803 BER_BVZERO( &attr->a_vals[i] );
806 attr->a_vals[i] = attr->a_vals[last];
807 BER_BVZERO( &attr->a_vals[last] );
811 BER_BVZERO( &attr->a_nvals[i] );
818 attr->a_nvals = attr->a_vals;
821 attr->a_numvals = last;
823 /* Handle sorted vals, strip dups but keep the attr */
824 if ( attr->a_desc->ad_type->sat_flags & SLAP_AT_SORTED_VAL ) {
825 while ( attr->a_numvals > 1 ) {
826 int rc = slap_sort_vals( (Modifications *)attr, &text, &i, op->o_tmpmemctx );
827 if ( rc != LDAP_TYPE_OR_VALUE_EXISTS )
830 /* Strip duplicate values */
831 if ( attr->a_nvals != attr->a_vals )
832 LBER_FREE( attr->a_nvals[i].bv_val );
833 LBER_FREE( attr->a_vals[i].bv_val );
835 if ( i < attr->a_numvals ) {
836 attr->a_vals[i] = attr->a_vals[attr->a_numvals];
837 if ( attr->a_nvals != attr->a_vals )
838 attr->a_nvals[i] = attr->a_nvals[attr->a_numvals];
840 BER_BVZERO(&attr->a_vals[attr->a_numvals]);
841 if ( attr->a_nvals != attr->a_vals )
842 BER_BVZERO(&attr->a_nvals[attr->a_numvals]);
844 attr->a_flags |= SLAP_ATTR_SORTED_VALS;
848 attrp = &attr->a_next;
856 /* return 0 IFF we can retrieve the entry with ndn
863 AttributeDescription *at,
867 ldapinfo_t *li = (ldapinfo_t *) op->o_bd->be_private;
869 ldapconn_t *lc = NULL;
874 LDAPMessage *result = NULL,
876 char *attr[3], **attrp = NULL;
880 LDAPControl **ctrls = NULL;
884 /* Tell getconn this is a privileged op */
885 do_not_cache = op->o_do_not_cache;
888 op->o_do_not_cache = 1;
889 /* ldap_back_entry_get() is an entry lookup, so it does not need
890 * to know what the entry is being looked up for */
891 op->o_tag = LDAP_REQ_SEARCH;
892 rc = ldap_back_dobind( &lc, op, &rs, LDAP_BACK_DONTSEND );
893 op->o_do_not_cache = do_not_cache;
901 if ( oc && at != slap_schema.si_ad_objectClass ) {
902 attr[0] = slap_schema.si_ad_objectClass->ad_cname.bv_val;
903 attr[1] = at->ad_cname.bv_val;
907 attr[0] = at->ad_cname.bv_val;
915 filter = op->o_tmpalloc( STRLENOF( "(objectClass=" ")" )
916 + oc->soc_cname.bv_len + 1, op->o_tmpmemctx );
917 ptr = lutil_strcopy( filter, "(objectClass=" );
918 ptr = lutil_strcopy( ptr, oc->soc_cname.bv_val );
925 rc = ldap_back_controls_add( op, &rs, lc, &ctrls );
926 if ( rc != LDAP_SUCCESS ) {
931 rc = ldap_pvt_search_s( lc->lc_ld, ndn->bv_val, LDAP_SCOPE_BASE, filter,
932 attrp, LDAP_DEREF_NEVER, ctrls, NULL,
933 NULL, LDAP_NO_LIMIT, 0, &result );
934 if ( rc != LDAP_SUCCESS ) {
935 if ( rc == LDAP_SERVER_DOWN && do_retry ) {
937 if ( ldap_back_retry( &lc, op, &rs, LDAP_BACK_DONTSEND ) ) {
938 /* if the identity changed, there might be need to re-authz */
939 (void)ldap_back_controls_free( op, &rs, &ctrls );
946 e = ldap_first_entry( lc->lc_ld, result );
948 /* the entry exists, but it doesn't match the filter? */
952 *ent = entry_alloc();
953 if ( *ent == NULL ) {
958 rc = ldap_build_entry( op, e, *ent, &bdn );
960 if ( rc != LDAP_SUCCESS ) {
966 (void)ldap_back_controls_free( op, &rs, &ctrls );
969 ldap_msgfree( result );
973 op->o_tmpfree( filter, op->o_tmpmemctx );
977 ldap_back_release_conn( li, lc );