]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldap/search.c
fix previous commit :)
[openldap] / servers / slapd / back-ldap / search.c
1 /* search.c - ldap backend search function */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 1999-2005 The OpenLDAP Foundation.
6  * Portions Copyright 1999-2003 Howard Chu.
7  * Portions Copyright 2000-2003 Pierangelo Masarati.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted only as authorized by the OpenLDAP
12  * Public License.
13  *
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>.
17  */
18 /* ACKNOWLEDGEMENTS:
19  * This work was initially developed by the Howard Chu for inclusion
20  * in OpenLDAP Software and subsequently enhanced by Pierangelo
21  * Masarati.
22  */
23
24 #include "portable.h"
25
26 #include <stdio.h>
27
28 #include <ac/socket.h>
29 #include <ac/string.h>
30 #include <ac/time.h>
31
32 #include "slap.h"
33 #include "back-ldap.h"
34 #undef ldap_debug       /* silence a warning in ldap-int.h */
35 #include "../../../libraries/libldap/ldap-int.h"
36
37 #include "lutil.h"
38
39 static int
40 ldap_build_entry( Operation *op, LDAPMessage *e, Entry *ent,
41          struct berval *bdn );
42
43 /*
44  * Quick'n'dirty rewrite of filter in case of error, to deal with
45  * <draft-zeilenga-ldap-t-f>.
46  */
47 static int
48 ldap_back_munge_filter(
49         Operation       *op,
50         struct berval   *filter )
51 {
52         struct ldapinfo *li = (struct ldapinfo *) op->o_bd->be_private;
53
54         char            *ptr;
55         int             gotit = 0;
56
57         Debug( LDAP_DEBUG_ARGS, "=> ldap_back_munge_filter \"%s\"\n",
58                         filter->bv_val, 0, 0 );
59
60         for ( ptr = strstr( filter->bv_val, "(?=" ); 
61                         ptr;
62                         ptr = strstr( ptr, "(?=" ) )
63         {
64                 static struct berval
65                         bv_true = BER_BVC( "(?=true)" ),
66                         bv_false = BER_BVC( "(?=false)" ),
67                         bv_t = BER_BVC( "(&)" ),
68                         bv_f = BER_BVC( "(|)" ),
69                         bv_T = BER_BVC( "(objectClass=*)" ),
70                         bv_F = BER_BVC( "(!(objectClass=*))" );
71                 struct berval   *oldbv = NULL,
72                                 *newbv = NULL,
73                                 oldfilter = BER_BVNULL;
74
75                 if ( strncmp( ptr, bv_true.bv_val, bv_true.bv_len ) == 0 ) {
76                         oldbv = &bv_true;
77                         if ( li->flags & LDAP_BACK_F_SUPPORT_T_F ) {
78                                 newbv = &bv_t;
79
80                         } else {
81                                 newbv = &bv_T;
82                         }
83
84                 } else if ( strncmp( ptr, bv_false.bv_val, bv_false.bv_len ) == 0 )
85                 {
86                         oldbv = &bv_false;
87                         if ( li->flags & LDAP_BACK_F_SUPPORT_T_F ) {
88                                 newbv = &bv_f;
89
90                         } else {
91                                 newbv = &bv_F;
92                         }
93
94                 } else {
95                         gotit = 0;
96                         goto done;
97                 }
98
99                 oldfilter = *filter;
100                 if ( !( li->flags & LDAP_BACK_F_SUPPORT_T_F ) ) {
101                         filter->bv_len += newbv->bv_len - oldbv->bv_len;
102                         if ( filter->bv_val == op->ors_filterstr.bv_val ) {
103                                 filter->bv_val = op->o_tmpalloc( filter->bv_len + 1,
104                                                 op->o_tmpmemctx );
105
106                                 AC_MEMCPY( filter->bv_val, op->ors_filterstr.bv_val,
107                                                 op->ors_filterstr.bv_len + 1 );
108
109                         } else {
110                                 filter->bv_val = op->o_tmprealloc( filter->bv_val,
111                                                 filter->bv_len + 1, op->o_tmpmemctx );
112                         }
113
114                         ptr = filter->bv_val + ( ptr - oldfilter.bv_val );
115                 }
116
117                 AC_MEMCPY( &ptr[ newbv->bv_len ],
118                                 &ptr[ oldbv->bv_len ], 
119                                 oldfilter.bv_len - ( ptr - filter->bv_val ) - oldbv->bv_len + 1 );
120                 AC_MEMCPY( ptr, newbv->bv_val, newbv->bv_len );
121
122                 ptr += newbv->bv_len;
123                 gotit = 1;
124         }
125
126 done:;
127         Debug( LDAP_DEBUG_ARGS, "<= ldap_back_munge_filter \"%s\" (%d)\n",
128                         filter->bv_val, gotit, 0 );
129
130         return gotit;
131 }
132
133 int
134 ldap_back_search(
135                 Operation       *op,
136                 SlapReply       *rs )
137 {
138         struct ldapconn *lc;
139         struct timeval  tv;
140         LDAPMessage     *res,
141                         *e;
142         int             rc = 0,
143                         msgid; 
144         struct berval   match = BER_BVNULL,
145                         filter = BER_BVNULL;
146         int             i;
147         char            **attrs = NULL;
148         int             dontfreetext = 0;
149         int             do_retry = 1;
150         LDAPControl     **ctrls = NULL;
151
152         lc = ldap_back_getconn( op, rs, LDAP_BACK_SENDERR );
153         if ( !lc ) {
154                 return rs->sr_err;
155         }
156
157         /*
158          * FIXME: in case of values return filter, we might want
159          * to map attrs and maybe rewrite value
160          */
161         if ( !ldap_back_dobind( lc, op, rs, LDAP_BACK_SENDERR ) ) {
162                 return rs->sr_err;
163         }
164
165         /* should we check return values? */
166         if ( op->ors_deref != -1 ) {
167                 ldap_set_option( lc->lc_ld, LDAP_OPT_DEREF,
168                                 (void *)&op->ors_deref );
169         }
170
171         if ( op->ors_tlimit != SLAP_NO_LIMIT ) {
172                 tv.tv_sec = op->ors_tlimit;
173                 tv.tv_usec = 0;
174
175         } else {
176                 tv.tv_sec = 0;
177         }
178
179         if ( op->ors_attrs ) {
180                 for ( i = 0; !BER_BVISNULL( &op->ors_attrs[i].an_name ); i++ )
181                         /* just count attrs */ ;
182
183                 attrs = ch_malloc( ( i + 1 )*sizeof( char * ) );
184                 if ( attrs == NULL ) {
185                         rs->sr_err = LDAP_NO_MEMORY;
186                         rc = -1;
187                         goto finish;
188                 }
189         
190                 for ( i = 0; !BER_BVISNULL( &op->ors_attrs[i].an_name ); i++ ) {
191                         attrs[ i ] = op->ors_attrs[i].an_name.bv_val;
192                 }
193                 attrs[ i ] = NULL;
194         }
195
196         ctrls = op->o_ctrls;
197         rc = ldap_back_proxy_authz_ctrl( lc, op, rs, &ctrls );
198         if ( rc != LDAP_SUCCESS ) {
199                 dontfreetext = 1;
200                 goto finish;
201         }
202
203         /* deal with <draft-zeilenga-ldap-t-f> filters */
204         filter = op->ors_filterstr;
205 retry:
206         rs->sr_err = ldap_search_ext( lc->lc_ld, op->o_req_ndn.bv_val,
207                         op->ors_scope, filter.bv_val,
208                         attrs, op->ors_attrsonly, ctrls, NULL,
209                         tv.tv_sec ? &tv : NULL,
210                         op->ors_slimit, &msgid );
211
212         if ( rs->sr_err != LDAP_SUCCESS ) {
213 fail:;
214                 switch ( rs->sr_err ) {
215                 case LDAP_SERVER_DOWN:
216                         if ( do_retry ) {
217                                 do_retry = 0;
218                                 if ( ldap_back_retry( lc, op, rs, LDAP_BACK_DONTSEND ) ) {
219                                         goto retry;
220                                 }
221                         }
222                         rc = ldap_back_op_result( lc, op, rs, msgid, LDAP_BACK_DONTSEND );
223                         ldap_back_freeconn( op, lc );
224                         lc = NULL;
225                         goto finish;
226
227                 case LDAP_FILTER_ERROR:
228                         if ( ldap_back_munge_filter( op, &filter ) ) {
229                                 goto retry;
230                         }
231
232                         /* invalid filters return success with no data */
233                         rs->sr_err = LDAP_SUCCESS;
234                         rs->sr_text = NULL;
235                         goto finish;
236                 
237                 default:
238                         rs->sr_err = slap_map_api2result( rs );
239                         rs->sr_text = NULL;
240                         goto finish;
241                 }
242         }
243
244         /* We pull apart the ber result, stuff it into a slapd entry, and
245          * let send_search_entry stuff it back into ber format. Slow & ugly,
246          * but this is necessary for version matching, and for ACL processing.
247          */
248
249         for ( rc = 0; rc != -1; rc = ldap_result( lc->lc_ld, msgid, 0, &tv, &res ) )
250         {
251                 /* check for abandon */
252                 if ( op->o_abandon ) {
253                         ldap_abandon_ext( lc->lc_ld, msgid, NULL, NULL );
254                         rc = SLAPD_ABANDON;
255                         goto finish;
256                 }
257
258                 if ( rc == 0 ) {
259                         tv.tv_sec = 0;
260                         tv.tv_usec = 100000;
261                         ldap_pvt_thread_yield();
262
263                 } else if ( rc == LDAP_RES_SEARCH_ENTRY ) {
264                         Entry           ent = {0};
265                         struct berval   bdn;
266                         int             abort = 0;
267
268                         do_retry = 0;
269
270                         e = ldap_first_entry( lc->lc_ld, res );
271                         rc = ldap_build_entry( op, e, &ent, &bdn );
272                        if ( rc == LDAP_SUCCESS ) {
273                                 rs->sr_entry = &ent;
274                                 rs->sr_attrs = op->ors_attrs;
275                                 rs->sr_operational_attrs = NULL;
276                                 rs->sr_flags = 0;
277                                 abort = send_search_entry( op, rs );
278                                 if ( !BER_BVISNULL( &ent.e_name ) ) {
279                                         assert( ent.e_name.bv_val != bdn.bv_val );
280                                         free( ent.e_name.bv_val );
281                                         BER_BVZERO( &ent.e_name );
282                                 }
283                                 if ( !BER_BVISNULL( &ent.e_nname ) ) {
284                                         free( ent.e_nname.bv_val );
285                                         BER_BVZERO( &ent.e_nname );
286                                 }
287                                 entry_clean( &ent );
288                         }
289                         ldap_msgfree( res );
290                         if ( abort ) {
291                                 ldap_abandon_ext( lc->lc_ld, msgid, NULL, NULL );
292                                 goto finish;
293                         }
294
295                 } else if ( rc == LDAP_RES_SEARCH_REFERENCE ) {
296                         char            **references = NULL;
297                         int             cnt;
298
299                         do_retry = 0;
300                         rc = ldap_parse_reference( lc->lc_ld, res,
301                                         &references, &rs->sr_ctrls, 1 );
302
303                         if ( rc != LDAP_SUCCESS ) {
304                                 continue;
305                         }
306
307                         if ( references == NULL ) {
308                                 continue;
309                         }
310
311                         for ( cnt = 0; references[ cnt ]; cnt++ )
312                                 /* NO OP */ ;
313                                 
314                         rs->sr_ref = ch_calloc( cnt + 1, sizeof( struct berval ) );
315
316                         for ( cnt = 0; references[ cnt ]; cnt++ ) {
317                                 ber_str2bv( references[ cnt ], 0, 0, &rs->sr_ref[ cnt ] );
318                         }
319
320                         /* ignore return value by now */
321                         ( void )send_search_reference( op, rs );
322
323                         /* cleanup */
324                         if ( references ) {
325                                 ldap_value_free( references );
326                                 ch_free( rs->sr_ref );
327                                 rs->sr_ref = NULL;
328                         }
329
330                         if ( rs->sr_ctrls ) {
331                                 ldap_controls_free( rs->sr_ctrls );
332                                 rs->sr_ctrls = NULL;
333                         }
334
335                 } else {
336                         char            **references = NULL;
337
338                         rc = ldap_parse_result( lc->lc_ld, res, &rs->sr_err,
339                                         &match.bv_val, (char **)&rs->sr_text,
340                                         &references, &rs->sr_ctrls, 1 );
341                         if ( rc != LDAP_SUCCESS ) {
342                                 rs->sr_err = rc;
343                         }
344                         rs->sr_err = slap_map_api2result( rs );
345
346                         if ( references ) {
347                                 int     cnt;
348
349                                 for ( cnt = 0; references[ cnt ]; cnt++ )
350                                         /* NO OP */ ;
351                                 
352                                 rs->sr_ref = ch_calloc( cnt + 1, sizeof( struct berval ) );
353
354                                 for ( cnt = 0; references[ cnt ]; cnt++ ) {
355                                         ber_str2bv( references[ cnt ], 0, 1, &rs->sr_ref[ cnt ] );
356                                 }
357
358                                 /* cleanup */
359                                 if ( references ) {
360                                         ldap_value_free( references );
361                                 }
362                         }
363
364                         rc = 0;
365                         break;
366                 }
367         }
368
369         if ( rc == -1 ) {
370                 if ( do_retry ) {
371                         do_retry = 0;
372                         if ( ldap_back_retry( lc, op, rs, LDAP_BACK_SENDERR ) ) {
373                                 goto retry;
374                         }
375                 }
376                 rs->sr_err = LDAP_SERVER_DOWN;
377                 goto fail;
378         }
379
380         /*
381          * Rewrite the matched portion of the search base, if required
382          */
383         if ( !BER_BVISNULL( &match ) && !BER_BVISEMPTY( &match ) ) {
384                 rs->sr_matched = match.bv_val;
385         }
386         if ( rs->sr_v2ref ) {
387                 rs->sr_err = LDAP_REFERRAL;
388         }
389
390 finish:;
391         if ( rc != SLAPD_ABANDON ) {
392                 send_ldap_result( op, rs );
393         }
394
395         (void)ldap_back_proxy_authz_ctrl_free( op, &ctrls );
396
397         if ( rs->sr_ctrls ) {
398                 ldap_controls_free( rs->sr_ctrls );
399                 rs->sr_ctrls = NULL;
400         }
401
402         if ( match.bv_val ) {
403                 rs->sr_matched = NULL;
404                 LDAP_FREE( match.bv_val );
405         }
406
407         if ( !BER_BVISNULL( &filter ) && filter.bv_val != op->ors_filterstr.bv_val ) {
408                 op->o_tmpfree( filter.bv_val, op->o_tmpmemctx );
409         }
410
411         if ( rs->sr_text ) {
412                 if ( !dontfreetext ) {
413                         LDAP_FREE( (char *)rs->sr_text );
414                 }
415                 rs->sr_text = NULL;
416         }
417
418         if ( rs->sr_ref ) {
419                 ber_bvarray_free( rs->sr_ref );
420                 rs->sr_ref = NULL;
421         }
422
423         if ( attrs ) {
424                 ch_free( attrs );
425         }
426
427         return rc;
428 }
429
430 static int
431 ldap_build_entry(
432                 Operation       *op,
433                 LDAPMessage     *e,
434                 Entry           *ent,
435                 struct berval   *bdn )
436 {
437         struct berval   a;
438         BerElement      ber = *e->lm_ber;
439         Attribute       *attr, **attrp;
440         const char      *text;
441         int             last;
442
443         /* safe assumptions ... */
444         assert( ent );
445         BER_BVZERO( &ent->e_bv );
446
447         if ( ber_scanf( &ber, "{m{", bdn ) == LBER_ERROR ) {
448                 return LDAP_DECODING_ERROR;
449         }
450
451         /*
452          * Note: this may fail if the target host(s) schema differs
453          * from the one known to the meta, and a DN with unknown
454          * attributes is returned.
455          * 
456          * FIXME: should we log anything, or delegate to dnNormalize?
457          */
458         /* Note: if the distinguished values or the naming attributes
459          * change, should we massage them as well?
460          */
461         if ( dnPrettyNormal( NULL, bdn, &ent->e_name, &ent->e_nname,
462                 op->o_tmpmemctx ) != LDAP_SUCCESS )
463         {
464                 return LDAP_INVALID_DN_SYNTAX;
465         }
466
467         attrp = &ent->e_attrs;
468
469         while ( ber_scanf( &ber, "{m", &a ) != LBER_ERROR ) {
470                 int                             i;
471                 slap_syntax_validate_func       *validate;
472                 slap_syntax_transform_func      *pretty;
473
474                 attr = (Attribute *)ch_malloc( sizeof( Attribute ) );
475                 if ( attr == NULL ) {
476                         continue;
477                 }
478                 attr->a_flags = 0;
479                 attr->a_next = 0;
480                 attr->a_desc = NULL;
481                 if ( slap_bv2ad( &a, &attr->a_desc, &text ) 
482                                 != LDAP_SUCCESS )
483                 {
484                         if ( slap_bv2undef_ad( &a, &attr->a_desc, &text ) 
485                                         != LDAP_SUCCESS )
486                         {
487                                 Debug( LDAP_DEBUG_ANY, 
488                                         "slap_bv2undef_ad(%s):  %s\n",
489                                         a.bv_val, text, 0 );
490                                 ch_free( attr );
491                                 continue;
492                         }
493                 }
494
495                 /* no subschemaSubentry */
496                 if ( attr->a_desc == slap_schema.si_ad_subschemaSubentry ) {
497
498                         /* 
499                          * We eat target's subschemaSubentry because
500                          * a search for this value is likely not
501                          * to resolve to the appropriate backend;
502                          * later, the local subschemaSubentry is
503                          * added.
504                          */
505                         ( void )ber_scanf( &ber, "x" /* [W] */ );
506
507                         ch_free( attr );
508                         continue;
509                 }
510                 
511                 if ( ber_scanf( &ber, "[W]", &attr->a_vals ) == LBER_ERROR
512                                 || attr->a_vals == NULL )
513                 {
514                         /*
515                          * Note: attr->a_vals can be null when using
516                          * values result filter
517                          */
518                         attr->a_vals = (struct berval *)&slap_dummy_bv;
519                         last = 0;
520
521                 } else {
522                         for ( last = 0; !BER_BVISNULL( &attr->a_vals[ last ] ); last++ )
523                                 /* just count vals */ ;
524                 }
525
526                 validate = attr->a_desc->ad_type->sat_syntax->ssyn_validate;
527                 pretty = attr->a_desc->ad_type->sat_syntax->ssyn_pretty;
528
529                 if ( !validate && !pretty ) {
530                         attr->a_nvals = NULL;
531                         attr_free( attr );
532                         goto next_attr;
533                 }
534
535                 for ( i = 0; i < last; i++ ) {
536                         struct berval   pval;
537                         int             rc;
538
539                         if ( pretty ) {
540                                 rc = pretty( attr->a_desc->ad_type->sat_syntax,
541                                         &attr->a_vals[i], &pval, NULL );
542
543                         } else {
544                                 rc = validate( attr->a_desc->ad_type->sat_syntax,
545                                         &attr->a_vals[i] );
546                         }
547
548                         if ( rc != LDAP_SUCCESS ) {
549                                 /* check if, by chance, it's an undefined objectClass */
550                                 if ( attr->a_desc == slap_schema.si_ad_objectClass &&
551                                                 oc_bvfind_undef( &attr->a_vals[i] ) != NULL )
552                                 {
553                                         ber_dupbv( &pval, &attr->a_vals[i] );
554
555                                 } else {
556                                         attr->a_nvals = NULL;
557                                         attr_free( attr );
558                                         goto next_attr;
559                                 }
560                         }
561
562                         if ( pretty ) {
563                                 LBER_FREE( attr->a_vals[i].bv_val );
564                                 attr->a_vals[i] = pval;
565                         }
566                 }
567
568                 if ( last && attr->a_desc->ad_type->sat_equality &&
569                                 attr->a_desc->ad_type->sat_equality->smr_normalize )
570                 {
571                         attr->a_nvals = ch_malloc( ( last + 1 )*sizeof( struct berval ) );
572                         for ( i = 0; i < last; i++ ) {
573                                 int             rc;
574
575                                 /*
576                                  * check that each value is valid per syntax
577                                  * and pretty if appropriate
578                                  */
579                                 rc = attr->a_desc->ad_type->sat_equality->smr_normalize(
580                                         SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
581                                         attr->a_desc->ad_type->sat_syntax,
582                                         attr->a_desc->ad_type->sat_equality,
583                                         &attr->a_vals[i], &attr->a_nvals[i],
584                                         NULL );
585
586                                 if ( rc != LDAP_SUCCESS ) {
587                                         BER_BVZERO( &attr->a_nvals[i] );
588                                         ch_free( attr );
589                                         goto next_attr;
590                                 }
591                         }
592                         BER_BVZERO( &attr->a_nvals[i] );
593
594                 } else {
595                         attr->a_nvals = attr->a_vals;
596                 }
597                 *attrp = attr;
598                 attrp = &attr->a_next;
599
600 next_attr:;
601         }
602
603         return LDAP_SUCCESS;
604 }
605
606 /* return 0 IFF we can retrieve the entry with ndn
607  */
608 int
609 ldap_back_entry_get(
610                 Operation               *op,
611                 struct berval           *ndn,
612                 ObjectClass             *oc,
613                 AttributeDescription    *at,
614                 int                     rw,
615                 Entry                   **ent
616 )
617 {
618         struct ldapconn *lc;
619         int             rc = 1,
620                         do_not_cache;
621         struct berval   bdn;
622         LDAPMessage     *result = NULL,
623                         *e = NULL;
624         char            *gattr[3];
625         char            *filter = NULL;
626         SlapReply       rs;
627         int             do_retry = 1;
628         LDAPControl     **ctrls = NULL;
629
630         /* Tell getconn this is a privileged op */
631         do_not_cache = op->o_do_not_cache;
632         op->o_do_not_cache = 1;
633         lc = ldap_back_getconn( op, &rs, LDAP_BACK_DONTSEND );
634         if ( !lc || !ldap_back_dobind( lc, op, &rs, LDAP_BACK_DONTSEND ) ) {
635                 op->o_do_not_cache = do_not_cache;
636                 return rs.sr_err;
637         }
638         op->o_do_not_cache = do_not_cache;
639
640         if ( at ) {
641                 if ( oc && at != slap_schema.si_ad_objectClass ) {
642                         gattr[0] = slap_schema.si_ad_objectClass->ad_cname.bv_val;
643                         gattr[1] = at->ad_cname.bv_val;
644                         gattr[2] = NULL;
645
646                 } else {
647                         gattr[0] = at->ad_cname.bv_val;
648                         gattr[1] = NULL;
649                 }
650         }
651
652         if ( oc ) {
653                 char    *ptr;
654
655                 filter = ch_malloc( STRLENOF( "(objectclass=)" ) 
656                                 + oc->soc_cname.bv_len + 1 );
657                 ptr = lutil_strcopy( filter, "(objectclass=" );
658                 ptr = lutil_strcopy( ptr, oc->soc_cname.bv_val );
659                 *ptr++ = ')';
660                 *ptr++ = '\0';
661         }
662
663         ctrls = op->o_ctrls;
664         rc = ldap_back_proxy_authz_ctrl( lc, op, &rs, &ctrls );
665         if ( rc != LDAP_SUCCESS ) {
666                 goto cleanup;
667         }
668         
669 retry:
670         rc = ldap_search_ext_s( lc->lc_ld, ndn->bv_val, LDAP_SCOPE_BASE, filter,
671                                 at ? gattr : NULL, 0, ctrls, NULL,
672                                 LDAP_NO_LIMIT, LDAP_NO_LIMIT, &result );
673         if ( rc != LDAP_SUCCESS ) {
674                 if ( rc == LDAP_SERVER_DOWN && do_retry ) {
675                         do_retry = 0;
676                         if ( ldap_back_retry( lc, op, &rs, LDAP_BACK_DONTSEND ) ) {
677                                 goto retry;
678                         }
679                 }
680                 goto cleanup;
681         }
682
683         e = ldap_first_entry( lc->lc_ld, result );
684         if ( e == NULL ) {
685                 goto cleanup;
686         }
687
688         *ent = ch_calloc( 1, sizeof( Entry ) );
689
690         rc = ldap_build_entry( op, e, *ent, &bdn );
691
692         if ( rc != LDAP_SUCCESS ) {
693                 ch_free( *ent );
694                 *ent = NULL;
695         }
696
697 cleanup:
698         (void)ldap_back_proxy_authz_ctrl_free( op, &ctrls );
699
700         if ( result ) {
701                 ldap_msgfree( result );
702         }
703
704         if ( filter ) {
705                 ch_free( filter );
706         }
707
708         return rc;
709 }
710