1 /* search.c - ldap backend search function */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1999-2010 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 );
195 if ( op->ors_attrs ) {
196 for ( ; !BER_BVISNULL( &op->ors_attrs[i].an_name ); i++ )
197 /* just count attrs */ ;
201 if ( op->o_bd->be_extra_anlist ) {
202 for ( ; !BER_BVISNULL( &op->o_bd->be_extra_anlist[x].an_name ); x++ )
203 /* just count attrs */ ;
206 if ( i > 0 || x > 0 ) {
209 attrs = op->o_tmpalloc( ( i + x + 1 )*sizeof( char * ),
211 if ( attrs == NULL ) {
212 rs->sr_err = LDAP_NO_MEMORY;
218 for ( i = 0; !BER_BVISNULL( &op->ors_attrs[i].an_name ); i++, j++ ) {
219 attrs[ j ] = op->ors_attrs[i].an_name.bv_val;
224 for ( x = 0; !BER_BVISNULL( &op->o_bd->be_extra_anlist[x].an_name ); x++, j++ ) {
225 if ( op->o_bd->be_extra_anlist[x].an_desc &&
226 ad_inlist( op->o_bd->be_extra_anlist[x].an_desc, op->ors_attrs ) )
231 attrs[ j ] = op->o_bd->be_extra_anlist[x].an_name.bv_val;
239 rc = ldap_back_controls_add( op, rs, lc, &ctrls );
240 if ( rc != LDAP_SUCCESS ) {
244 /* deal with <draft-zeilenga-ldap-t-f> filters */
245 filter = op->ors_filterstr;
247 rs->sr_err = ldap_pvt_search( lc->lc_ld, op->o_req_dn.bv_val,
248 op->ors_scope, filter.bv_val,
249 attrs, op->ors_attrsonly, ctrls, NULL,
250 tv.tv_sec ? &tv : NULL,
251 op->ors_slimit, op->ors_deref, &msgid );
253 if ( rs->sr_err != LDAP_SUCCESS ) {
254 switch ( rs->sr_err ) {
255 case LDAP_SERVER_DOWN:
258 if ( ldap_back_retry( &lc, op, rs, LDAP_BACK_DONTSEND ) ) {
264 /* reset by ldap_back_retry ... */
265 rs->sr_err = slap_map_api2result( rs );
268 rc = ldap_back_op_result( lc, op, rs, msgid, 0, LDAP_BACK_DONTSEND );
273 case LDAP_FILTER_ERROR:
274 if (ldap_back_munge_filter( op, &filter, &freefilter ) > 0 ) {
278 /* invalid filters return success with no data */
279 rs->sr_err = LDAP_SUCCESS;
284 rs->sr_err = slap_map_api2result( rs );
290 /* if needed, initialize timeout */
291 if ( li->li_timeout[ SLAP_OP_SEARCH ] ) {
292 if ( tv.tv_sec == 0 || tv.tv_sec > li->li_timeout[ SLAP_OP_SEARCH ] ) {
293 tv.tv_sec = li->li_timeout[ SLAP_OP_SEARCH ];
298 /* We pull apart the ber result, stuff it into a slapd entry, and
299 * let send_search_entry stuff it back into ber format. Slow & ugly,
300 * but this is necessary for version matching, and for ACL processing.
303 for ( rc = -2; rc != -1; rc = ldap_result( lc->lc_ld, msgid, LDAP_MSG_ONE, &tv, &res ) )
305 /* check for abandon */
306 if ( op->o_abandon || LDAP_BACK_CONN_ABANDON( lc ) ) {
310 (void)ldap_back_cancel( lc, op, rs, msgid, LDAP_BACK_DONTSEND );
315 if ( rc == 0 || rc == -2 ) {
316 ldap_pvt_thread_yield();
319 if ( li->li_timeout[ SLAP_OP_SEARCH ] ) {
321 (void)ldap_back_cancel( lc, op, rs, msgid, LDAP_BACK_DONTSEND );
322 rs->sr_text = "Operation timed out";
323 rc = rs->sr_err = op->o_protocol >= LDAP_VERSION3 ?
324 LDAP_ADMINLIMIT_EXCEEDED : LDAP_OTHER;
329 LDAP_BACK_TV_SET( &tv );
332 /* check time limit */
333 if ( op->ors_tlimit != SLAP_NO_LIMIT
334 && slap_get_time() > stoptime )
336 (void)ldap_back_cancel( lc, op, rs, msgid, LDAP_BACK_DONTSEND );
337 rc = rs->sr_err = LDAP_TIMELIMIT_EXCEEDED;
343 /* only touch when activity actually took place... */
344 if ( li->li_idle_timeout && lc ) {
345 lc->lc_time = op->o_time;
348 /* don't retry any more */
353 if ( rc == LDAP_RES_SEARCH_ENTRY ) {
355 struct berval bdn = BER_BVNULL;
359 e = ldap_first_entry( lc->lc_ld, res );
360 rc = ldap_build_entry( op, e, &ent, &bdn );
361 if ( rc == LDAP_SUCCESS ) {
362 ldap_get_entry_controls( lc->lc_ld, res, &rs->sr_ctrls );
364 rs->sr_attrs = op->ors_attrs;
365 rs->sr_operational_attrs = NULL;
367 rs->sr_err = LDAP_SUCCESS;
368 rc = rs->sr_err = send_search_entry( op, rs );
369 if ( rs->sr_ctrls ) {
370 ldap_controls_free( rs->sr_ctrls );
374 if ( !BER_BVISNULL( &ent.e_name ) ) {
375 assert( ent.e_name.bv_val != bdn.bv_val );
376 op->o_tmpfree( ent.e_name.bv_val, op->o_tmpmemctx );
377 BER_BVZERO( &ent.e_name );
379 if ( !BER_BVISNULL( &ent.e_nname ) ) {
380 op->o_tmpfree( ent.e_nname.bv_val, op->o_tmpmemctx );
381 BER_BVZERO( &ent.e_nname );
388 case LDAP_INSUFFICIENT_ACCESS:
392 if ( rc == LDAP_UNAVAILABLE ) {
393 rc = rs->sr_err = LDAP_OTHER;
395 (void)ldap_back_cancel( lc, op, rs, msgid, LDAP_BACK_DONTSEND );
400 } else if ( rc == LDAP_RES_SEARCH_REFERENCE ) {
401 if ( LDAP_BACK_NOREFS( li ) ) {
407 rc = ldap_parse_reference( lc->lc_ld, res,
408 &references, &rs->sr_ctrls, 1 );
410 if ( rc != LDAP_SUCCESS ) {
414 /* FIXME: there MUST be at least one */
415 if ( references && references[ 0 ] && references[ 0 ][ 0 ] ) {
418 for ( cnt = 0; references[ cnt ]; cnt++ )
421 /* FIXME: there MUST be at least one */
422 rs->sr_ref = op->o_tmpalloc( ( cnt + 1 ) * sizeof( struct berval ),
425 for ( cnt = 0; references[ cnt ]; cnt++ ) {
426 ber_str2bv( references[ cnt ], 0, 0, &rs->sr_ref[ cnt ] );
428 BER_BVZERO( &rs->sr_ref[ cnt ] );
430 /* ignore return value by now */
432 ( void )send_search_reference( op, rs );
435 Debug( LDAP_DEBUG_ANY,
436 "%s ldap_back_search: "
437 "got SEARCH_REFERENCE "
438 "with no referrals\n",
439 op->o_log_prefix, 0, 0 );
444 ber_memvfree( (void **)references );
445 op->o_tmpfree( rs->sr_ref, op->o_tmpmemctx );
450 if ( rs->sr_ctrls ) {
451 ldap_controls_free( rs->sr_ctrls );
455 } else if ( rc == LDAP_RES_INTERMEDIATE ) {
456 /* FIXME: response controls
457 * are passed without checks */
458 rc = ldap_parse_intermediate( lc->lc_ld,
460 (char **)&rs->sr_rspoid,
464 if ( rc != LDAP_SUCCESS ) {
468 slap_send_ldap_intermediate( op, rs );
470 if ( rs->sr_rspoid != NULL ) {
471 ber_memfree( (char *)rs->sr_rspoid );
472 rs->sr_rspoid = NULL;
475 if ( rs->sr_rspdata != NULL ) {
476 ber_bvfree( rs->sr_rspdata );
477 rs->sr_rspdata = NULL;
480 if ( rs->sr_ctrls != NULL ) {
481 ldap_controls_free( rs->sr_ctrls );
488 rc = ldap_parse_result( lc->lc_ld, res, &rs->sr_err,
490 &references, &rs->sr_ctrls, 1 );
491 if ( rc == LDAP_SUCCESS ) {
499 rs->sr_err = slap_map_api2result( rs );
501 /* RFC 4511: referrals can only appear
502 * if result code is LDAP_REFERRAL */
505 && references[ 0 ][ 0 ] )
507 if ( rs->sr_err != LDAP_REFERRAL ) {
508 Debug( LDAP_DEBUG_ANY,
509 "%s ldap_back_search: "
510 "got referrals with err=%d\n",
517 for ( cnt = 0; references[ cnt ]; cnt++ )
520 rs->sr_ref = op->o_tmpalloc( ( cnt + 1 ) * sizeof( struct berval ),
523 for ( cnt = 0; references[ cnt ]; cnt++ ) {
525 ber_str2bv( references[ cnt ], 0, 0, &rs->sr_ref[ cnt ] );
527 BER_BVZERO( &rs->sr_ref[ cnt ] );
530 } else if ( rs->sr_err == LDAP_REFERRAL ) {
531 Debug( LDAP_DEBUG_ANY,
532 "%s ldap_back_search: "
533 "got err=%d with null "
534 "or empty referrals\n",
538 rs->sr_err = LDAP_NO_SUCH_OBJECT;
541 if ( match.bv_val != NULL ) {
542 match.bv_len = strlen( match.bv_val );
549 /* if needed, restore timeout */
550 if ( li->li_timeout[ SLAP_OP_SEARCH ] ) {
551 if ( tv.tv_sec == 0 || tv.tv_sec > li->li_timeout[ SLAP_OP_SEARCH ] ) {
552 tv.tv_sec = li->li_timeout[ SLAP_OP_SEARCH ];
558 if ( rc == -1 && dont_retry == 0 ) {
561 if ( ldap_back_retry( &lc, op, rs, LDAP_BACK_DONTSEND ) ) {
565 rs->sr_err = LDAP_SERVER_DOWN;
566 rs->sr_err = slap_map_api2result( rs );
571 * Rewrite the matched portion of the search base, if required
573 if ( !BER_BVISNULL( &match ) && !BER_BVISEMPTY( &match ) ) {
574 struct berval pmatch;
576 if ( dnPretty( NULL, &match, &pmatch, op->o_tmpmemctx ) == LDAP_SUCCESS ) {
577 rs->sr_matched = pmatch.bv_val;
578 ber_memfree( match.bv_val );
581 rs->sr_matched = match.bv_val;
585 if ( rs->sr_v2ref ) {
586 rs->sr_err = LDAP_REFERRAL;
590 if ( LDAP_BACK_QUARANTINE( li ) ) {
591 ldap_back_quarantine( op, rs );
594 if ( freefilter && filter.bv_val != op->ors_filterstr.bv_val ) {
595 op->o_tmpfree( filter.bv_val, op->o_tmpmemctx );
599 /* let send_ldap_result play cleanup handlers (ITS#4645) */
600 if ( rc != SLAPD_ABANDON )
603 send_ldap_result( op, rs );
606 (void)ldap_back_controls_free( op, rs, &ctrls );
608 if ( rs->sr_ctrls ) {
609 ldap_controls_free( rs->sr_ctrls );
613 if ( rs->sr_matched != NULL && rs->sr_matched != save_matched ) {
614 if ( rs->sr_matched != match.bv_val ) {
615 ber_memfree_x( (char *)rs->sr_matched, op->o_tmpmemctx );
618 ber_memfree( match.bv_val );
620 rs->sr_matched = save_matched;
625 ber_memfree( (char *)rs->sr_text );
631 op->o_tmpfree( rs->sr_ref, op->o_tmpmemctx );
636 ber_memvfree( (void **)references );
640 op->o_tmpfree( attrs, op->o_tmpmemctx );
644 ldap_back_release_conn( li, lc );
658 BerElement ber = *ldap_get_message_ber( e );
659 Attribute *attr, **attrp;
665 /* safe assumptions ... */
666 assert( ent != NULL );
667 BER_BVZERO( &ent->e_bv );
669 if ( ber_scanf( &ber, "{m", bdn ) == LBER_ERROR ) {
670 return LDAP_DECODING_ERROR;
674 * Note: this may fail if the target host(s) schema differs
675 * from the one known to the meta, and a DN with unknown
676 * attributes is returned.
678 * FIXME: should we log anything, or delegate to dnNormalize?
680 /* Note: if the distinguished values or the naming attributes
681 * change, should we massage them as well?
683 if ( dnPrettyNormal( NULL, bdn, &ent->e_name, &ent->e_nname,
684 op->o_tmpmemctx ) != LDAP_SUCCESS )
686 return LDAP_INVALID_DN_SYNTAX;
690 if ( ber_first_element( &ber, &len, &lastb ) != LBER_SEQUENCE ) {
694 attrp = &ent->e_attrs;
695 while ( ber_next_element( &ber, &len, lastb ) == LBER_SEQUENCE &&
696 ber_scanf( &ber, "{m", &a ) != LBER_ERROR ) {
698 slap_syntax_validate_func *validate;
699 slap_syntax_transform_func *pretty;
701 attr = attr_alloc( NULL );
702 if ( attr == NULL ) {
705 if ( slap_bv2ad( &a, &attr->a_desc, &text )
708 if ( slap_bv2undef_ad( &a, &attr->a_desc, &text,
709 SLAP_AD_PROXIED ) != LDAP_SUCCESS )
711 Debug( LDAP_DEBUG_ANY,
712 "%s ldap_build_entry: "
713 "slap_bv2undef_ad(%s): %s\n",
714 op->o_log_prefix, a.bv_val, text );
716 ( void )ber_scanf( &ber, "x" /* [W] */ );
722 /* no subschemaSubentry */
723 if ( attr->a_desc == slap_schema.si_ad_subschemaSubentry
724 || attr->a_desc == slap_schema.si_ad_entryDN )
728 * We eat target's subschemaSubentry because
729 * a search for this value is likely not
730 * to resolve to the appropriate backend;
731 * later, the local subschemaSubentry is
734 * We also eat entryDN because the frontend
735 * will reattach it without checking if already
738 ( void )ber_scanf( &ber, "x" /* [W] */ );
743 if ( ber_scanf( &ber, "[W]", &attr->a_vals ) == LBER_ERROR
744 || attr->a_vals == NULL )
747 * Note: attr->a_vals can be null when using
748 * values result filter
750 attr->a_vals = (struct berval *)&slap_dummy_bv;
753 validate = attr->a_desc->ad_type->sat_syntax->ssyn_validate;
754 pretty = attr->a_desc->ad_type->sat_syntax->ssyn_pretty;
756 if ( !validate && !pretty ) {
757 attr->a_nvals = NULL;
762 for ( i = 0; !BER_BVISNULL( &attr->a_vals[i] ); i++ ) ;
766 * check that each value is valid per syntax
767 * and pretty if appropriate
769 for ( i = 0; i<last; i++ ) {
774 rc = ordered_value_pretty( attr->a_desc,
775 &attr->a_vals[i], &pval, NULL );
778 rc = ordered_value_validate( attr->a_desc,
779 &attr->a_vals[i], 0 );
782 if ( rc != LDAP_SUCCESS ) {
785 /* check if, by chance, it's an undefined objectClass */
786 if ( attr->a_desc == slap_schema.si_ad_objectClass &&
787 ( oc = oc_bvfind_undef( &attr->a_vals[i] ) ) != NULL )
789 ber_dupbv( &pval, &oc->soc_cname );
793 ber_memfree( attr->a_vals[i].bv_val );
795 BER_BVZERO( &attr->a_vals[i] );
798 attr->a_vals[i] = attr->a_vals[last];
799 BER_BVZERO( &attr->a_vals[last] );
804 if ( rc == LDAP_SUCCESS && pretty ) {
805 ber_memfree( attr->a_vals[i].bv_val );
806 attr->a_vals[i] = pval;
809 attr->a_numvals = last = i;
810 if ( last == 0 && attr->a_vals != &slap_dummy_bv ) {
811 attr->a_nvals = NULL;
816 if ( last && attr->a_desc->ad_type->sat_equality &&
817 attr->a_desc->ad_type->sat_equality->smr_normalize )
819 attr->a_nvals = ch_malloc( ( last + 1 )*sizeof( struct berval ) );
820 for ( i = 0; i < last; i++ ) {
823 rc = ordered_value_normalize(
824 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
826 attr->a_desc->ad_type->sat_equality,
827 &attr->a_vals[i], &attr->a_nvals[i],
830 if ( rc != LDAP_SUCCESS ) {
831 ber_memfree( attr->a_vals[i].bv_val );
833 BER_BVZERO( &attr->a_vals[i] );
836 attr->a_vals[i] = attr->a_vals[last];
837 BER_BVZERO( &attr->a_vals[last] );
841 BER_BVZERO( &attr->a_nvals[i] );
848 attr->a_nvals = attr->a_vals;
851 attr->a_numvals = last;
853 /* Handle sorted vals, strip dups but keep the attr */
854 if ( attr->a_desc->ad_type->sat_flags & SLAP_AT_SORTED_VAL ) {
855 while ( attr->a_numvals > 1 ) {
856 int rc = slap_sort_vals( (Modifications *)attr, &text, &i, op->o_tmpmemctx );
857 if ( rc != LDAP_TYPE_OR_VALUE_EXISTS )
860 /* Strip duplicate values */
861 if ( attr->a_nvals != attr->a_vals )
862 ber_memfree( attr->a_nvals[i].bv_val );
863 ber_memfree( attr->a_vals[i].bv_val );
867 if ( (unsigned)i < attr->a_numvals ) {
868 attr->a_vals[i] = attr->a_vals[attr->a_numvals];
869 if ( attr->a_nvals != attr->a_vals )
870 attr->a_nvals[i] = attr->a_nvals[attr->a_numvals];
872 BER_BVZERO(&attr->a_vals[attr->a_numvals]);
873 if ( attr->a_nvals != attr->a_vals )
874 BER_BVZERO(&attr->a_nvals[attr->a_numvals]);
876 attr->a_flags |= SLAP_ATTR_SORTED_VALS;
880 attrp = &attr->a_next;
888 /* return 0 IFF we can retrieve the entry with ndn
895 AttributeDescription *at,
899 ldapinfo_t *li = (ldapinfo_t *) op->o_bd->be_private;
901 ldapconn_t *lc = NULL;
906 LDAPMessage *result = NULL,
908 char *attr[3], **attrp = NULL;
912 LDAPControl **ctrls = NULL;
916 /* Tell getconn this is a privileged op */
917 do_not_cache = op->o_do_not_cache;
920 op->o_do_not_cache = 1;
921 /* ldap_back_entry_get() is an entry lookup, so it does not need
922 * to know what the entry is being looked up for */
923 op->o_tag = LDAP_REQ_SEARCH;
924 rc = ldap_back_dobind( &lc, op, &rs, LDAP_BACK_DONTSEND );
925 op->o_do_not_cache = do_not_cache;
933 if ( oc && at != slap_schema.si_ad_objectClass ) {
934 attr[0] = slap_schema.si_ad_objectClass->ad_cname.bv_val;
935 attr[1] = at->ad_cname.bv_val;
939 attr[0] = at->ad_cname.bv_val;
947 filter = op->o_tmpalloc( STRLENOF( "(objectClass=" ")" )
948 + oc->soc_cname.bv_len + 1, op->o_tmpmemctx );
949 ptr = lutil_strcopy( filter, "(objectClass=" );
950 ptr = lutil_strcopy( ptr, oc->soc_cname.bv_val );
957 rc = ldap_back_controls_add( op, &rs, lc, &ctrls );
958 if ( rc != LDAP_SUCCESS ) {
963 rc = ldap_pvt_search_s( lc->lc_ld, ndn->bv_val, LDAP_SCOPE_BASE, filter,
964 attrp, LDAP_DEREF_NEVER, ctrls, NULL,
965 NULL, LDAP_NO_LIMIT, 0, &result );
966 if ( rc != LDAP_SUCCESS ) {
967 if ( rc == LDAP_SERVER_DOWN && do_retry ) {
969 if ( ldap_back_retry( &lc, op, &rs, LDAP_BACK_DONTSEND ) ) {
970 /* if the identity changed, there might be need to re-authz */
971 (void)ldap_back_controls_free( op, &rs, &ctrls );
978 e = ldap_first_entry( lc->lc_ld, result );
980 /* the entry exists, but it doesn't match the filter? */
984 *ent = entry_alloc();
985 if ( *ent == NULL ) {
990 rc = ldap_build_entry( op, e, *ent, &bdn );
992 if ( rc != LDAP_SUCCESS ) {
998 (void)ldap_back_controls_free( op, &rs, &ctrls );
1001 ldap_msgfree( result );
1005 op->o_tmpfree( filter, op->o_tmpmemctx );
1009 ldap_back_release_conn( li, lc );