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 ) {
494 rs->sr_err = slap_map_api2result( rs );
500 /* RFC 4511: referrals can only appear
501 * if result code is LDAP_REFERRAL */
504 && references[ 0 ][ 0 ] )
506 if ( rs->sr_err != LDAP_REFERRAL ) {
507 Debug( LDAP_DEBUG_ANY,
508 "%s ldap_back_search: "
509 "got referrals with err=%d\n",
516 for ( cnt = 0; references[ cnt ]; cnt++ )
519 rs->sr_ref = op->o_tmpalloc( ( cnt + 1 ) * sizeof( struct berval ),
522 for ( cnt = 0; references[ cnt ]; cnt++ ) {
524 ber_str2bv( references[ cnt ], 0, 0, &rs->sr_ref[ cnt ] );
526 BER_BVZERO( &rs->sr_ref[ cnt ] );
529 } else if ( rs->sr_err == LDAP_REFERRAL ) {
530 Debug( LDAP_DEBUG_ANY,
531 "%s ldap_back_search: "
532 "got err=%d with null "
533 "or empty referrals\n",
537 rs->sr_err = LDAP_NO_SUCH_OBJECT;
540 if ( match.bv_val != NULL ) {
541 match.bv_len = strlen( match.bv_val );
548 /* if needed, restore timeout */
549 if ( li->li_timeout[ SLAP_OP_SEARCH ] ) {
550 if ( tv.tv_sec == 0 || tv.tv_sec > li->li_timeout[ SLAP_OP_SEARCH ] ) {
551 tv.tv_sec = li->li_timeout[ SLAP_OP_SEARCH ];
557 if ( rc == -1 && dont_retry == 0 ) {
560 if ( ldap_back_retry( &lc, op, rs, LDAP_BACK_DONTSEND ) ) {
564 rs->sr_err = LDAP_SERVER_DOWN;
565 rs->sr_err = slap_map_api2result( rs );
570 * Rewrite the matched portion of the search base, if required
572 if ( !BER_BVISNULL( &match ) && !BER_BVISEMPTY( &match ) ) {
573 struct berval pmatch;
575 if ( dnPretty( NULL, &match, &pmatch, op->o_tmpmemctx ) == LDAP_SUCCESS ) {
576 rs->sr_matched = pmatch.bv_val;
577 LDAP_FREE( match.bv_val );
580 rs->sr_matched = match.bv_val;
584 if ( rs->sr_v2ref ) {
585 rs->sr_err = LDAP_REFERRAL;
589 if ( LDAP_BACK_QUARANTINE( li ) ) {
590 ldap_back_quarantine( op, rs );
593 if ( freefilter && filter.bv_val != op->ors_filterstr.bv_val ) {
594 op->o_tmpfree( filter.bv_val, op->o_tmpmemctx );
598 /* let send_ldap_result play cleanup handlers (ITS#4645) */
599 if ( rc != SLAPD_ABANDON )
602 send_ldap_result( op, rs );
605 (void)ldap_back_controls_free( op, rs, &ctrls );
607 if ( rs->sr_ctrls ) {
608 ldap_controls_free( rs->sr_ctrls );
612 if ( rs->sr_matched != NULL && rs->sr_matched != save_matched ) {
613 if ( rs->sr_matched != match.bv_val ) {
614 ber_memfree_x( (char *)rs->sr_matched, op->o_tmpmemctx );
617 LDAP_FREE( match.bv_val );
619 rs->sr_matched = save_matched;
624 LDAP_FREE( (char *)rs->sr_text );
630 op->o_tmpfree( rs->sr_ref, op->o_tmpmemctx );
635 ber_memvfree( (void **)references );
639 op->o_tmpfree( attrs, op->o_tmpmemctx );
643 ldap_back_release_conn( li, lc );
657 BerElement ber = *e->lm_ber;
658 Attribute *attr, **attrp;
664 /* safe assumptions ... */
665 assert( ent != NULL );
666 BER_BVZERO( &ent->e_bv );
668 if ( ber_scanf( &ber, "{m", bdn ) == LBER_ERROR ) {
669 return LDAP_DECODING_ERROR;
673 * Note: this may fail if the target host(s) schema differs
674 * from the one known to the meta, and a DN with unknown
675 * attributes is returned.
677 * FIXME: should we log anything, or delegate to dnNormalize?
679 /* Note: if the distinguished values or the naming attributes
680 * change, should we massage them as well?
682 if ( dnPrettyNormal( NULL, bdn, &ent->e_name, &ent->e_nname,
683 op->o_tmpmemctx ) != LDAP_SUCCESS )
685 return LDAP_INVALID_DN_SYNTAX;
689 if ( ber_first_element( &ber, &len, &lastb ) != LBER_SEQUENCE ) {
693 attrp = &ent->e_attrs;
694 while ( ber_next_element( &ber, &len, lastb ) == LBER_SEQUENCE &&
695 ber_scanf( &ber, "{m", &a ) != LBER_ERROR ) {
697 slap_syntax_validate_func *validate;
698 slap_syntax_transform_func *pretty;
700 attr = attr_alloc( NULL );
701 if ( attr == NULL ) {
704 if ( slap_bv2ad( &a, &attr->a_desc, &text )
707 if ( slap_bv2undef_ad( &a, &attr->a_desc, &text,
708 SLAP_AD_PROXIED ) != LDAP_SUCCESS )
710 Debug( LDAP_DEBUG_ANY,
711 "%s ldap_build_entry: "
712 "slap_bv2undef_ad(%s): %s\n",
713 op->o_log_prefix, a.bv_val, text );
715 ( void )ber_scanf( &ber, "x" /* [W] */ );
721 /* no subschemaSubentry */
722 if ( attr->a_desc == slap_schema.si_ad_subschemaSubentry
723 || attr->a_desc == slap_schema.si_ad_entryDN )
727 * We eat target's subschemaSubentry because
728 * a search for this value is likely not
729 * to resolve to the appropriate backend;
730 * later, the local subschemaSubentry is
733 * We also eat entryDN because the frontend
734 * will reattach it without checking if already
737 ( void )ber_scanf( &ber, "x" /* [W] */ );
742 if ( ber_scanf( &ber, "[W]", &attr->a_vals ) == LBER_ERROR
743 || attr->a_vals == NULL )
746 * Note: attr->a_vals can be null when using
747 * values result filter
749 attr->a_vals = (struct berval *)&slap_dummy_bv;
752 validate = attr->a_desc->ad_type->sat_syntax->ssyn_validate;
753 pretty = attr->a_desc->ad_type->sat_syntax->ssyn_pretty;
755 if ( !validate && !pretty ) {
756 attr->a_nvals = NULL;
761 for ( i = 0; !BER_BVISNULL( &attr->a_vals[i] ); i++ ) ;
765 * check that each value is valid per syntax
766 * and pretty if appropriate
768 for ( i = 0; i<last; i++ ) {
773 rc = ordered_value_pretty( attr->a_desc,
774 &attr->a_vals[i], &pval, NULL );
777 rc = ordered_value_validate( attr->a_desc,
778 &attr->a_vals[i], 0 );
781 if ( rc != LDAP_SUCCESS ) {
784 /* check if, by chance, it's an undefined objectClass */
785 if ( attr->a_desc == slap_schema.si_ad_objectClass &&
786 ( oc = oc_bvfind_undef( &attr->a_vals[i] ) ) != NULL )
788 ber_dupbv( &pval, &oc->soc_cname );
792 LBER_FREE( attr->a_vals[i].bv_val );
794 BER_BVZERO( &attr->a_vals[i] );
797 attr->a_vals[i] = attr->a_vals[last];
798 BER_BVZERO( &attr->a_vals[last] );
803 if ( rc == LDAP_SUCCESS && pretty ) {
804 LBER_FREE( attr->a_vals[i].bv_val );
805 attr->a_vals[i] = pval;
808 attr->a_numvals = last = i;
809 if ( last == 0 && attr->a_vals != &slap_dummy_bv ) {
810 attr->a_nvals = NULL;
815 if ( last && attr->a_desc->ad_type->sat_equality &&
816 attr->a_desc->ad_type->sat_equality->smr_normalize )
818 attr->a_nvals = ch_malloc( ( last + 1 )*sizeof( struct berval ) );
819 for ( i = 0; i < last; i++ ) {
822 rc = ordered_value_normalize(
823 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
825 attr->a_desc->ad_type->sat_equality,
826 &attr->a_vals[i], &attr->a_nvals[i],
829 if ( rc != LDAP_SUCCESS ) {
830 LBER_FREE( attr->a_vals[i].bv_val );
832 BER_BVZERO( &attr->a_vals[i] );
835 attr->a_vals[i] = attr->a_vals[last];
836 BER_BVZERO( &attr->a_vals[last] );
840 BER_BVZERO( &attr->a_nvals[i] );
847 attr->a_nvals = attr->a_vals;
850 attr->a_numvals = last;
852 /* Handle sorted vals, strip dups but keep the attr */
853 if ( attr->a_desc->ad_type->sat_flags & SLAP_AT_SORTED_VAL ) {
854 while ( attr->a_numvals > 1 ) {
855 int rc = slap_sort_vals( (Modifications *)attr, &text, &i, op->o_tmpmemctx );
856 if ( rc != LDAP_TYPE_OR_VALUE_EXISTS )
859 /* Strip duplicate values */
860 if ( attr->a_nvals != attr->a_vals )
861 LBER_FREE( attr->a_nvals[i].bv_val );
862 LBER_FREE( attr->a_vals[i].bv_val );
866 if ( (unsigned)i < attr->a_numvals ) {
867 attr->a_vals[i] = attr->a_vals[attr->a_numvals];
868 if ( attr->a_nvals != attr->a_vals )
869 attr->a_nvals[i] = attr->a_nvals[attr->a_numvals];
871 BER_BVZERO(&attr->a_vals[attr->a_numvals]);
872 if ( attr->a_nvals != attr->a_vals )
873 BER_BVZERO(&attr->a_nvals[attr->a_numvals]);
875 attr->a_flags |= SLAP_ATTR_SORTED_VALS;
879 attrp = &attr->a_next;
887 /* return 0 IFF we can retrieve the entry with ndn
894 AttributeDescription *at,
898 ldapinfo_t *li = (ldapinfo_t *) op->o_bd->be_private;
900 ldapconn_t *lc = NULL;
905 LDAPMessage *result = NULL,
907 char *attr[3], **attrp = NULL;
911 LDAPControl **ctrls = NULL;
915 /* Tell getconn this is a privileged op */
916 do_not_cache = op->o_do_not_cache;
919 op->o_do_not_cache = 1;
920 /* ldap_back_entry_get() is an entry lookup, so it does not need
921 * to know what the entry is being looked up for */
922 op->o_tag = LDAP_REQ_SEARCH;
923 rc = ldap_back_dobind( &lc, op, &rs, LDAP_BACK_DONTSEND );
924 op->o_do_not_cache = do_not_cache;
932 if ( oc && at != slap_schema.si_ad_objectClass ) {
933 attr[0] = slap_schema.si_ad_objectClass->ad_cname.bv_val;
934 attr[1] = at->ad_cname.bv_val;
938 attr[0] = at->ad_cname.bv_val;
946 filter = op->o_tmpalloc( STRLENOF( "(objectClass=" ")" )
947 + oc->soc_cname.bv_len + 1, op->o_tmpmemctx );
948 ptr = lutil_strcopy( filter, "(objectClass=" );
949 ptr = lutil_strcopy( ptr, oc->soc_cname.bv_val );
956 rc = ldap_back_controls_add( op, &rs, lc, &ctrls );
957 if ( rc != LDAP_SUCCESS ) {
962 rc = ldap_pvt_search_s( lc->lc_ld, ndn->bv_val, LDAP_SCOPE_BASE, filter,
963 attrp, LDAP_DEREF_NEVER, ctrls, NULL,
964 NULL, LDAP_NO_LIMIT, 0, &result );
965 if ( rc != LDAP_SUCCESS ) {
966 if ( rc == LDAP_SERVER_DOWN && do_retry ) {
968 if ( ldap_back_retry( &lc, op, &rs, LDAP_BACK_DONTSEND ) ) {
969 /* if the identity changed, there might be need to re-authz */
970 (void)ldap_back_controls_free( op, &rs, &ctrls );
977 e = ldap_first_entry( lc->lc_ld, result );
979 /* the entry exists, but it doesn't match the filter? */
983 *ent = entry_alloc();
984 if ( *ent == NULL ) {
989 rc = ldap_build_entry( op, e, *ent, &bdn );
991 if ( rc != LDAP_SUCCESS ) {
997 (void)ldap_back_controls_free( op, &rs, &ctrls );
1000 ldap_msgfree( result );
1004 op->o_tmpfree( filter, op->o_tmpmemctx );
1008 ldap_back_release_conn( li, lc );