1 /* bind.c - ldap backend bind function */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1999-2006 The OpenLDAP Foundation.
6 * Portions Copyright 2000-2003 Pierangelo Masarati.
7 * Portions Copyright 1999-2003 Howard Chu.
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 Howard Chu for inclusion
20 * in OpenLDAP Software and subsequently enhanced by Pierangelo
29 #include <ac/socket.h>
30 #include <ac/string.h>
34 #include "back-ldap.h"
36 #include <lutil_ldap.h>
38 #ifndef PRINT_CONNTREE
39 #define PRINT_CONNTREE 0
40 #endif /* !PRINT_CONNTREE */
42 #define LDAP_CONTROL_OBSOLETE_PROXY_AUTHZ "2.16.840.1.113730.3.4.12"
44 static LDAP_REBIND_PROC ldap_back_default_rebind;
46 LDAP_REBIND_PROC *ldap_back_rebind_f = ldap_back_default_rebind;
49 ldap_back_proxy_authz_bind( ldapconn_t *lc, Operation *op, SlapReply *rs, ldap_back_send_t sendok );
52 ldap_back_prepare_conn( ldapconn_t **lcp, Operation *op, SlapReply *rs, ldap_back_send_t sendok );
55 ldap_back_bind( Operation *op, SlapReply *rs )
57 ldapinfo_t *li = (ldapinfo_t *) op->o_bd->be_private;
63 lc = ldap_back_getconn( op, rs, LDAP_BACK_BIND_SERR );
68 if ( !BER_BVISNULL( &lc->lc_bound_ndn ) ) {
69 ch_free( lc->lc_bound_ndn.bv_val );
70 BER_BVZERO( &lc->lc_bound_ndn );
72 LDAP_BACK_CONN_ISBOUND_CLEAR( lc );
74 /* method is always LDAP_AUTH_SIMPLE if we got here */
75 rs->sr_err = ldap_sasl_bind( lc->lc_ld, op->o_req_dn.bv_val,
77 &op->orb_cred, op->o_ctrls, NULL, &msgid );
78 rc = ldap_back_op_result( lc, op, rs, msgid, 0, LDAP_BACK_SENDERR );
80 if ( rc == LDAP_SUCCESS ) {
81 /* If defined, proxyAuthz will be used also when
82 * back-ldap is the authorizing backend; for this
83 * purpose, a successful bind is followed by a
84 * bind with the configured identity assertion */
85 /* NOTE: use with care */
86 if ( li->li_idassert_flags & LDAP_BACK_AUTH_OVERRIDE ) {
87 ldap_back_proxy_authz_bind( lc, op, rs, LDAP_BACK_SENDERR );
88 if ( !LDAP_BACK_CONN_ISBOUND( lc ) ) {
94 LDAP_BACK_CONN_ISBOUND_SET( lc );
95 ber_dupbv( &lc->lc_bound_ndn, &op->o_req_ndn );
97 if ( LDAP_BACK_SAVECRED( li ) ) {
98 if ( !BER_BVISNULL( &lc->lc_cred ) ) {
99 memset( lc->lc_cred.bv_val, 0,
100 lc->lc_cred.bv_len );
102 ber_bvreplace( &lc->lc_cred, &op->orb_cred );
103 ldap_set_rebind_proc( lc->lc_ld, ldap_back_rebind_f, lc );
108 assert( lc->lc_binding == 1 );
111 /* must re-insert if local DN changed as result of bind */
112 if ( !LDAP_BACK_CONN_ISBOUND( lc )
113 || ( LDAP_BACK_CONN_ISBOUND( lc )
114 && !dn_match( &op->o_req_ndn, &lc->lc_local_ndn ) ) )
118 /* wait for all other ops to release the connection */
120 ldap_pvt_thread_mutex_lock( &li->li_conninfo.lai_mutex );
121 if ( lc->lc_refcnt > 1 ) {
122 ldap_pvt_thread_mutex_unlock( &li->li_conninfo.lai_mutex );
123 ldap_pvt_thread_yield();
127 assert( lc->lc_refcnt == 1 );
128 lc = avl_delete( &li->li_conninfo.lai_tree, (caddr_t)lc,
129 ldap_back_conndn_cmp );
130 assert( lc != NULL );
132 if ( LDAP_BACK_CONN_ISBOUND( lc ) ) {
133 ber_bvreplace( &lc->lc_local_ndn, &op->o_req_ndn );
134 lerr = avl_insert( &li->li_conninfo.lai_tree, (caddr_t)lc,
135 ldap_back_conndn_cmp, ldap_back_conndn_dup );
138 ldap_pvt_thread_mutex_unlock( &li->li_conninfo.lai_mutex );
140 /* we can do this because lc_refcnt == 1 */
141 ldap_back_conn_free( lc );
147 ldap_back_release_conn( op, rs, lc );
154 * ldap_back_conndn_cmp
156 * compares two ldapconn_t based on the value of the conn pointer
157 * and of the local DN; used by avl stuff for insert, lookup
161 ldap_back_conndn_cmp( const void *c1, const void *c2 )
163 const ldapconn_t *lc1 = (const ldapconn_t *)c1;
164 const ldapconn_t *lc2 = (const ldapconn_t *)c2;
167 /* If local DNs don't match, it is definitely not a match */
168 /* For shared sessions, conn is NULL. Only explicitly
169 * bound sessions will have non-NULL conn.
171 rc = SLAP_PTRCMP( lc1->lc_conn, lc2->lc_conn );
173 rc = ber_bvcmp( &lc1->lc_local_ndn, &lc2->lc_local_ndn );
180 * ldap_back_conndnlc_cmp
182 * compares two ldapconn_t based on the value of the conn pointer,
183 * the local DN and the lc pointer; used by avl stuff for insert, lookup
187 ldap_back_conndnlc_cmp( const void *c1, const void *c2 )
189 const ldapconn_t *lc1 = (const ldapconn_t *)c1;
190 const ldapconn_t *lc2 = (const ldapconn_t *)c2;
193 /* If local DNs don't match, it is definitely not a match */
194 /* For shared sessions, conn is NULL. Only explicitly
195 * bound sessions will have non-NULL conn.
197 rc = SLAP_PTRCMP( lc1->lc_conn, lc2->lc_conn );
199 rc = ber_bvcmp( &lc1->lc_local_ndn, &lc2->lc_local_ndn );
201 rc = SLAP_PTRCMP( lc1, lc2 );
211 * compares two ldapconn_t based on the value of the conn pointer;
212 * used by avl stuff for delete of all conns with the same connid
215 ldap_back_conn_cmp( const void *c1, const void *c2 )
217 const ldapconn_t *lc1 = (const ldapconn_t *)c1;
218 const ldapconn_t *lc2 = (const ldapconn_t *)c2;
220 /* For shared sessions, conn is NULL. Only explicitly
221 * bound sessions will have non-NULL conn.
223 return SLAP_PTRCMP( lc1->lc_conn, lc2->lc_conn );
227 * ldap_back_conndn_dup
229 * returns -1 in case a duplicate ldapconn_t has been inserted;
233 ldap_back_conndn_dup( void *c1, void *c2 )
235 ldapconn_t *lc1 = (ldapconn_t *)c1;
236 ldapconn_t *lc2 = (ldapconn_t *)c2;
238 /* Cannot have more than one shared session with same DN */
239 if ( lc1->lc_conn == lc2->lc_conn &&
240 dn_match( &lc1->lc_local_ndn, &lc2->lc_local_ndn ) )
248 #if PRINT_CONNTREE > 0
250 ravl_print( Avlnode *root, int depth )
259 ravl_print( root->avl_right, depth+1 );
261 for ( i = 0; i < depth; i++ ) {
262 fprintf( stderr, "-" );
266 fprintf( stderr, "lc=%p local=\"%s\" conn=%p %s refcnt=%d\n",
267 (void *)lc, lc->lc_local_ndn.bv_val, (void *)lc->lc_conn,
268 avl_bf2str( root->avl_bf ), lc->lc_refcnt );
270 ravl_print( root->avl_left, depth+1 );
274 myprint( Avlnode *root )
276 fprintf( stderr, "========>\n" );
279 fprintf( stderr, "\tNULL\n" );
282 ravl_print( root, 0 );
285 fprintf( stderr, "<========\n" );
287 #endif /* PRINT_CONNTREE */
290 ldap_back_freeconn( Operation *op, ldapconn_t *lc, int dolock )
292 ldapinfo_t *li = (ldapinfo_t *) op->o_bd->be_private;
295 ldap_pvt_thread_mutex_lock( &li->li_conninfo.lai_mutex );
298 assert( lc->lc_refcnt > 0 );
299 if ( --lc->lc_refcnt == 0 ) {
300 lc = avl_delete( &li->li_conninfo.lai_tree, (caddr_t)lc,
301 ldap_back_conndn_cmp );
302 assert( lc != NULL );
304 ldap_back_conn_free( (void *)lc );
308 ldap_pvt_thread_mutex_unlock( &li->li_conninfo.lai_mutex );
325 int rc = LDAP_SUCCESS;
328 /* this is ridiculous... */
329 dummy.li_flags = flags;
331 /* start TLS ("tls-[try-]{start,propagate}" statements) */
332 if ( ( LDAP_BACK_USE_TLS( &dummy ) || ( *is_tls && LDAP_BACK_PROPAGATE_TLS( &dummy ) ) )
333 && !ldap_is_ldaps_url( url ) )
335 #ifdef SLAP_STARTTLS_ASYNCHRONOUS
337 * use asynchronous StartTLS
338 * in case, chase referral (not implemented yet)
342 if ( protocol == 0 ) {
343 ldap_get_option( ld, LDAP_OPT_PROTOCOL_VERSION,
347 if ( protocol < LDAP_VERSION3 ) {
348 protocol = LDAP_VERSION3;
349 /* Set LDAP version */
350 ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION,
351 (const void *)&protocol );
354 rc = ldap_start_tls( ld, NULL, NULL, &msgid );
355 if ( rc == LDAP_SUCCESS ) {
356 LDAPMessage *res = NULL;
359 LDAP_BACK_TV_SET( &tv );
362 rc = ldap_result( ld, msgid, LDAP_MSG_ALL, &tv, &res );
364 rc = LDAP_UNAVAILABLE;
366 } else if ( rc == 0 ) {
367 if ( retries != LDAP_BACK_RETRY_NEVER ) {
368 ldap_pvt_thread_yield();
372 LDAP_BACK_TV_SET( &tv );
375 rc = LDAP_UNAVAILABLE;
377 } else if ( rc == LDAP_RES_EXTENDED ) {
378 struct berval *data = NULL;
380 rc = ldap_parse_extended_result( ld, res,
382 if ( rc == LDAP_SUCCESS ) {
384 rc = ldap_parse_result( ld, res, &err,
385 NULL, NULL, NULL, NULL, 1 );
386 if ( rc == LDAP_SUCCESS ) {
391 /* FIXME: in case a referral
392 * is returned, should we try
393 * using it instead of the
395 if ( rc == LDAP_SUCCESS ) {
396 rc = ldap_install_tls( ld );
398 } else if ( rc == LDAP_REFERRAL ) {
399 rc = LDAP_UNWILLING_TO_PERFORM;
400 *text = "unwilling to chase referral returned by Start TLS exop";
404 if ( data->bv_val ) {
405 ber_memfree( data->bv_val );
419 #else /* ! SLAP_STARTTLS_ASYNCHRONOUS */
421 * use synchronous StartTLS
423 rc = ldap_start_tls_s( ld, NULL, NULL );
424 #endif /* ! SLAP_STARTTLS_ASYNCHRONOUS */
426 /* if StartTLS is requested, only attempt it if the URL
427 * is not "ldaps://"; this may occur not only in case
428 * of misconfiguration, but also when used in the chain
429 * overlay, where the "uri" can be parsed out of a referral */
435 case LDAP_SERVER_DOWN:
439 if ( LDAP_BACK_TLS_CRITICAL( &dummy ) ) {
440 *text = "could not start TLS";
444 /* in case Start TLS is not critical */
456 #endif /* HAVE_TLS */
459 ldap_back_prepare_conn( ldapconn_t **lcp, Operation *op, SlapReply *rs, ldap_back_send_t sendok )
461 ldapinfo_t *li = (ldapinfo_t *)op->o_bd->be_private;
462 int vers = op->o_protocol;
465 int is_tls = op->o_conn->c_is_tls;
466 #endif /* HAVE_TLS */
468 assert( lcp != NULL );
470 rs->sr_err = ldap_initialize( &ld, li->li_uri );
471 if ( rs->sr_err != LDAP_SUCCESS ) {
475 /* Set LDAP version. This will always succeed: If the client
476 * bound with a particular version, then so can we.
479 /* assume it's an internal op; set to LDAPv3 */
480 vers = LDAP_VERSION3;
482 ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, (const void *)&vers );
484 /* automatically chase referrals ("chase-referrals [{yes|no}]" statement) */
485 ldap_set_option( ld, LDAP_OPT_REFERRALS,
486 LDAP_BACK_CHASE_REFERRALS( li ) ? LDAP_OPT_ON : LDAP_OPT_OFF );
489 rs->sr_err = ldap_back_start_tls( ld, op->o_protocol, &is_tls,
490 li->li_uri, li->li_flags, li->li_nretries, &rs->sr_text );
491 if ( rs->sr_err != LDAP_SUCCESS ) {
492 ldap_unbind_ext( ld, NULL, NULL );
495 #endif /* HAVE_TLS */
497 if ( *lcp == NULL ) {
498 *lcp = (ldapconn_t *)ch_calloc( 1, sizeof( ldapconn_t ) );
499 (*lcp)->lc_flags= li->li_flags;
502 (*lcp)->lc_refcnt = 1;
503 (*lcp)->lc_binding = 1;
506 LDAP_BACK_CONN_ISTLS_SET( *lcp );
508 LDAP_BACK_CONN_ISTLS_CLEAR( *lcp );
510 #endif /* HAVE_TLS */
513 if ( rs->sr_err != LDAP_SUCCESS ) {
514 rs->sr_err = slap_map_api2result( rs );
515 if ( sendok & LDAP_BACK_SENDERR ) {
516 if ( rs->sr_text == NULL ) {
517 rs->sr_text = "ldap_initialize() failed";
519 send_ldap_result( op, rs );
524 if ( li->li_conn_ttl > 0 ) {
525 (*lcp)->lc_create_time = op->o_time;
533 ldap_back_getconn( Operation *op, SlapReply *rs, ldap_back_send_t sendok )
535 ldapinfo_t *li = (ldapinfo_t *)op->o_bd->be_private;
536 ldapconn_t *lc = NULL,
538 int refcnt = 1, binding = 1;
540 /* Internal searches are privileged and shared. So is root. */
541 if ( op->o_do_not_cache || be_isroot( op ) ) {
542 LDAP_BACK_CONN_ISPRIV_SET( &lc_curr );
543 lc_curr.lc_local_ndn = op->o_bd->be_rootndn;
544 lc_curr.lc_conn = LDAP_BACK_PCONN_SET( op );
547 lc_curr.lc_local_ndn = op->o_ndn;
548 /* Explicit binds must not be shared */
549 if ( op->o_tag == LDAP_REQ_BIND || SLAP_IS_AUTHZ_BACKEND( op ) ) {
550 lc_curr.lc_conn = op->o_conn;
553 lc_curr.lc_conn = LDAP_BACK_PCONN_SET( op );
557 /* Explicit Bind requests always get their own conn */
558 if ( !( sendok & LDAP_BACK_BINDING ) ) {
559 /* Searches for a ldapconn in the avl tree */
561 ldap_pvt_thread_mutex_lock( &li->li_conninfo.lai_mutex );
563 lc = (ldapconn_t *)avl_find( li->li_conninfo.lai_tree,
564 (caddr_t)&lc_curr, ldap_back_conndn_cmp );
566 /* Don't reuse connections while they're still binding */
567 if ( LDAP_BACK_CONN_BINDING( lc ) ) {
568 ldap_pvt_thread_mutex_unlock( &li->li_conninfo.lai_mutex );
569 ldap_pvt_thread_yield();
572 refcnt = ++lc->lc_refcnt;
573 binding = ++lc->lc_binding;
575 ldap_pvt_thread_mutex_unlock( &li->li_conninfo.lai_mutex );
578 /* Looks like we didn't get a bind. Open a new session... */
580 if ( ldap_back_prepare_conn( &lc, op, rs, sendok ) != LDAP_SUCCESS ) {
583 if ( sendok & LDAP_BACK_BINDING ) {
584 LDAP_BACK_CONN_BINDING_SET( lc );
586 lc->lc_conn = lc_curr.lc_conn;
587 ber_dupbv( &lc->lc_local_ndn, &lc_curr.lc_local_ndn );
589 if ( LDAP_BACK_CONN_ISPRIV( &lc_curr ) ) {
590 ber_dupbv( &lc->lc_cred, &li->li_acl_passwd );
591 ber_dupbv( &lc->lc_bound_ndn, &li->li_acl_authcDN );
592 LDAP_BACK_CONN_ISPRIV_SET( lc );
595 BER_BVZERO( &lc->lc_cred );
596 BER_BVZERO( &lc->lc_bound_ndn );
598 /* FIXME: if we set lc_bound_ndn = o_ndn
599 * we end up with a bind with DN but no password! */
600 if ( !BER_BVISEMPTY( &op->o_ndn )
601 && SLAP_IS_AUTHZ_BACKEND( op ) )
603 ber_dupbv( &lc->lc_bound_ndn, &op->o_ndn );
609 /* if start TLS failed but it was not mandatory,
610 * check if the non-TLS connection was already
611 * in cache; in case, destroy the newly created
612 * connection and use the existing one */
613 if ( lc->lc_conn == LDAP_BACK_PCONN_TLS
614 && !ldap_tls_inplace( lc->lc_ld ) )
618 lc_curr.lc_conn = LDAP_BACK_PCONN;
619 ldap_pvt_thread_mutex_lock( &li->li_conninfo.lai_mutex );
620 tmplc = (ldapconn_t *)avl_find( li->li_conninfo.lai_tree,
621 (caddr_t)&lc_curr, ldap_back_conndn_cmp );
622 if ( tmplc != NULL ) {
623 refcnt = ++tmplc->lc_refcnt;
624 binding = ++tmplc->lc_binding;
625 ldap_back_conn_free( lc );
628 ldap_pvt_thread_mutex_unlock( &li->li_conninfo.lai_mutex );
630 if ( tmplc != NULL ) {
634 #endif /* HAVE_TLS */
636 LDAP_BACK_CONN_ISBOUND_CLEAR( lc );
638 /* Inserts the newly created ldapconn in the avl tree */
639 ldap_pvt_thread_mutex_lock( &li->li_conninfo.lai_mutex );
641 assert( lc->lc_refcnt == 1 );
642 assert( lc->lc_binding == 1 );
643 rs->sr_err = avl_insert( &li->li_conninfo.lai_tree, (caddr_t)lc,
644 ldap_back_conndn_cmp, ldap_back_conndn_dup );
646 #if PRINT_CONNTREE > 0
647 myprint( li->li_conninfo.lai_tree );
648 #endif /* PRINT_CONNTREE */
650 ldap_pvt_thread_mutex_unlock( &li->li_conninfo.lai_mutex );
652 Debug( LDAP_DEBUG_TRACE,
653 "=>ldap_back_getconn: conn %p inserted refcnt=%u binding=%u\n",
654 (void *)lc, refcnt, binding );
656 /* Err could be -1 in case a duplicate ldapconn is inserted */
657 if ( rs->sr_err != 0 ) {
658 ldap_back_conn_free( lc );
659 rs->sr_err = LDAP_OTHER;
660 if ( op->o_conn && ( sendok & LDAP_BACK_SENDERR ) ) {
661 send_ldap_error( op, rs, LDAP_OTHER,
662 "internal server error" );
668 char buf[ SLAP_TEXT_BUFLEN ];
671 if ( ( li->li_idle_timeout != 0 && op->o_time > lc->lc_time + li->li_idle_timeout )
672 || ( li->li_conn_ttl != 0 && op->o_time > lc->lc_create_time + li->li_conn_ttl ) )
676 /* let it be used, but taint/delete it so that
677 * no-one else can look it up any further */
678 ldap_pvt_thread_mutex_lock( &li->li_conninfo.lai_mutex );
679 (void *)avl_delete( &li->li_conninfo.lai_tree, (caddr_t)lc,
680 ldap_back_conndnlc_cmp );
681 ldap_pvt_thread_mutex_unlock( &li->li_conninfo.lai_mutex );
684 if ( LogTest( LDAP_DEBUG_TRACE ) ) {
685 snprintf( buf, sizeof( buf ),
686 "conn %p fetched refcnt=%u binding=%u%s",
687 (void *)lc, refcnt, binding, expiring ? " expiring" : "" );
688 Debug( LDAP_DEBUG_TRACE,
689 "=>ldap_back_getconn: %s.\n", buf, 0, 0 );
694 if ( li->li_idle_timeout && lc ) {
695 lc->lc_time = op->o_time;
703 ldap_back_release_conn_lock(
709 ldapinfo_t *li = (ldapinfo_t *)op->o_bd->be_private;
712 ldap_pvt_thread_mutex_lock( &li->li_conninfo.lai_mutex );
714 assert( lc->lc_refcnt > 0 );
716 LDAP_BACK_CONN_BINDING_CLEAR( lc );
718 ldap_pvt_thread_mutex_unlock( &li->li_conninfo.lai_mutex );
725 * Note: as the check for the value of lc->lc_bound was already here, I removed
726 * it from all the callers, and I made the function return the flag, so
727 * it can be used to simplify the check.
729 * Note: dolock indicates whether li->li_conninfo.lai_mutex must be locked or not
732 ldap_back_dobind_int(
736 ldap_back_send_t sendok,
740 ldapinfo_t *li = (ldapinfo_t *)op->o_bd->be_private;
745 assert( retries >= 0 );
749 ldap_pvt_thread_mutex_lock( &li->li_conninfo.lai_mutex );
752 if ( binding == 0 ) {
753 /* check if already bound */
754 rc = LDAP_BACK_CONN_ISBOUND( lc );
758 ldap_pvt_thread_mutex_unlock( &li->li_conninfo.lai_mutex );
763 if ( LDAP_BACK_CONN_BINDING( lc ) ) {
764 /* if someone else is about to bind it, give up and retry */
766 ldap_pvt_thread_mutex_unlock( &li->li_conninfo.lai_mutex );
768 ldap_pvt_thread_yield();
772 /* otherwise this thread will bind it */
773 LDAP_BACK_CONN_BINDING_SET( lc );
778 /* wait for pending operations to finish */
779 /* FIXME: may become a bottleneck! */
780 if ( lc->lc_refcnt != lc->lc_binding ) {
782 ldap_pvt_thread_mutex_unlock( &li->li_conninfo.lai_mutex );
784 ldap_pvt_thread_yield();
789 ldap_pvt_thread_mutex_unlock( &li->li_conninfo.lai_mutex );
793 while ( lc->lc_refcnt > 1 ) {
794 ldap_pvt_thread_yield();
795 rc = LDAP_BACK_CONN_ISBOUND( lc );
802 ldap_pvt_thread_mutex_lock( &li->li_conninfo.lai_mutex );
804 LDAP_BACK_CONN_BINDING_SET( lc );
806 ldap_pvt_thread_mutex_unlock( &li->li_conninfo.lai_mutex );
811 * FIXME: we need to let clients use proxyAuthz
812 * otherwise we cannot do symmetric pools of servers;
813 * we have to live with the fact that a user can
814 * authorize itself as any ID that is allowed
815 * by the authzTo directive of the "proxyauthzdn".
818 * NOTE: current Proxy Authorization specification
819 * and implementation do not allow proxy authorization
820 * control to be provided with Bind requests
823 * if no bind took place yet, but the connection is bound
824 * and the "idassert-authcDN" (or other ID) is set,
825 * then bind as the asserting identity and explicitly
826 * add the proxyAuthz control to every operation with the
827 * dn bound to the connection as control value.
828 * This is done also if this is the authrizing backend,
829 * but the "override" flag is given to idassert.
830 * It allows to use SASL bind and yet proxyAuthz users
832 if ( op->o_conn != NULL &&
833 !op->o_do_not_cache &&
834 ( BER_BVISNULL( &lc->lc_bound_ndn ) ||
835 ( li->li_idassert_flags & LDAP_BACK_AUTH_OVERRIDE ) ) )
837 (void)ldap_back_proxy_authz_bind( lc, op, rs, sendok );
841 #ifdef HAVE_CYRUS_SASL
842 if ( LDAP_BACK_CONN_ISPRIV( lc )
843 && li->li_acl_authmethod == LDAP_AUTH_SASL )
845 void *defaults = NULL;
847 if ( li->li_acl_secprops != NULL ) {
848 rc = ldap_set_option( lc->lc_ld,
849 LDAP_OPT_X_SASL_SECPROPS, li->li_acl_secprops);
851 if ( rc != LDAP_OPT_SUCCESS ) {
852 Debug( LDAP_DEBUG_ANY, "Error: ldap_set_option "
853 "(%s,SECPROPS,\"%s\") failed!\n",
854 li->li_uri, li->li_acl_secprops, 0 );
859 defaults = lutil_sasl_defaults( lc->lc_ld,
860 li->li_acl_sasl_mech.bv_val,
861 li->li_acl_sasl_realm.bv_val,
862 li->li_acl_authcID.bv_val,
863 li->li_acl_passwd.bv_val,
866 rs->sr_err = ldap_sasl_interactive_bind_s( lc->lc_ld,
867 li->li_acl_authcDN.bv_val,
868 li->li_acl_sasl_mech.bv_val, NULL, NULL,
869 LDAP_SASL_QUIET, lutil_sasl_interact,
872 lutil_sasl_freedefs( defaults );
874 rs->sr_err = slap_map_api2result( rs );
875 if ( rs->sr_err != LDAP_SUCCESS ) {
876 LDAP_BACK_CONN_ISBOUND_CLEAR( lc );
877 send_ldap_result( op, rs );
880 LDAP_BACK_CONN_ISBOUND_SET( lc );
884 #endif /* HAVE_CYRUS_SASL */
887 rs->sr_err = ldap_sasl_bind( lc->lc_ld,
888 lc->lc_bound_ndn.bv_val,
889 LDAP_SASL_SIMPLE, &lc->lc_cred,
890 NULL, NULL, &msgid );
892 if ( rs->sr_err == LDAP_SERVER_DOWN ) {
893 if ( retries != LDAP_BACK_RETRY_NEVER ) {
895 ldap_pvt_thread_mutex_lock( &li->li_conninfo.lai_mutex );
898 assert( lc->lc_refcnt > 0 );
899 if ( lc->lc_refcnt == 1 ) {
900 ldap_unbind_ext( lc->lc_ld, NULL, NULL );
903 /* lc here must be the regular lc, reset and ready for init */
904 rs->sr_err = ldap_back_prepare_conn( &lc, op, rs, sendok );
907 ldap_pvt_thread_mutex_unlock( &li->li_conninfo.lai_mutex );
909 if ( rs->sr_err == LDAP_SUCCESS ) {
918 ldap_back_freeconn( op, lc, dolock );
919 rs->sr_err = slap_map_api2result( rs );
924 rc = ldap_back_op_result( lc, op, rs, msgid, 0, sendok );
925 if ( rc == LDAP_SUCCESS ) {
926 LDAP_BACK_CONN_ISBOUND_SET( lc );
931 LDAP_BACK_CONN_BINDING_CLEAR( lc );
932 rc = LDAP_BACK_CONN_ISBOUND( lc );
934 ldap_back_release_conn_lock( op, rs, lc, dolock );
941 ldap_back_dobind( ldapconn_t *lc, Operation *op, SlapReply *rs, ldap_back_send_t sendok )
943 ldapinfo_t *li = (ldapinfo_t *)op->o_bd->be_private;
945 return ldap_back_dobind_int( lc, op, rs, sendok, li->li_nretries, 1 );
949 * ldap_back_default_rebind
951 * This is a callback used for chasing referrals using the same
952 * credentials as the original user on this session.
955 ldap_back_default_rebind( LDAP *ld, LDAP_CONST char *url, ber_tag_t request,
956 ber_int_t msgid, void *params )
958 ldapconn_t *lc = (ldapconn_t *)params;
961 /* ... otherwise we couldn't get here */
962 assert( lc != NULL );
964 if ( !ldap_tls_inplace( ld ) ) {
965 int is_tls = LDAP_BACK_CONN_ISTLS( lc ),
967 const char *text = NULL;
969 rc = ldap_back_start_tls( ld, 0, &is_tls, url, lc->lc_flags,
970 LDAP_BACK_RETRY_DEFAULT, &text );
971 if ( rc != LDAP_SUCCESS ) {
975 #endif /* HAVE_TLS */
977 /* FIXME: add checks on the URL/identity? */
979 return ldap_sasl_bind_s( ld, lc->lc_bound_ndn.bv_val,
980 LDAP_SASL_SIMPLE, &lc->lc_cred, NULL, NULL, NULL );
990 ldap_back_send_t sendok )
993 LDAPMessage *res = NULL;
996 #define ERR_OK(err) ((err) == LDAP_SUCCESS || (err) == LDAP_COMPARE_FALSE || (err) == LDAP_COMPARE_TRUE)
999 rs->sr_matched = NULL;
1001 /* if the error recorded in the reply corresponds
1002 * to a successful state, get the error from the
1003 * remote server response */
1004 if ( ERR_OK( rs->sr_err ) ) {
1009 tv.tv_sec = timeout;
1013 LDAP_BACK_TV_SET( &tv );
1017 /* if result parsing fails, note the failure reason */
1018 rc = ldap_result( lc->lc_ld, msgid, LDAP_MSG_ALL, &tv, &res );
1022 (void)ldap_abandon_ext( lc->lc_ld, msgid, NULL, NULL );
1023 rs->sr_err = op->o_protocol >= LDAP_VERSION3 ?
1024 LDAP_ADMINLIMIT_EXCEEDED : LDAP_OPERATIONS_ERROR;
1025 rs->sr_text = "Operation timed out";
1029 LDAP_BACK_TV_SET( &tv );
1030 ldap_pvt_thread_yield();
1034 ldap_get_option( lc->lc_ld, LDAP_OPT_ERROR_NUMBER,
1039 /* otherwise get the result; if it is not
1040 * LDAP_SUCCESS, record it in the reply
1041 * structure (this includes
1042 * LDAP_COMPARE_{TRUE|FALSE}) */
1044 rc = ldap_parse_result( lc->lc_ld, res, &rs->sr_err,
1045 &match, &text, NULL, NULL, 1 );
1047 if ( rc != LDAP_SUCCESS ) {
1053 /* if the error in the reply structure is not
1054 * LDAP_SUCCESS, try to map it from client
1055 * to server error */
1056 if ( !ERR_OK( rs->sr_err ) ) {
1057 rs->sr_err = slap_map_api2result( rs );
1059 /* internal ops ( op->o_conn == NULL )
1060 * must not reply to client */
1061 if ( op->o_conn && !op->o_do_not_cache && match ) {
1063 /* record the (massaged) matched
1064 * DN into the reply structure */
1065 rs->sr_matched = match;
1069 ( ( sendok & LDAP_BACK_SENDOK )
1070 || ( ( sendok & LDAP_BACK_SENDERR ) && rs->sr_err != LDAP_SUCCESS ) ) )
1072 send_ldap_result( op, rs );
1075 if ( rs->sr_matched != match ) {
1076 free( (char *)rs->sr_matched );
1078 rs->sr_matched = NULL;
1079 ldap_memfree( match );
1082 ldap_memfree( text );
1085 return( ERR_OK( rs->sr_err ) ? LDAP_SUCCESS : rs->sr_err );
1088 /* return true if bound, false if failed */
1090 ldap_back_retry( ldapconn_t **lcp, Operation *op, SlapReply *rs, ldap_back_send_t sendok )
1093 ldapinfo_t *li = (ldapinfo_t *)op->o_bd->be_private;
1095 assert( lcp != NULL );
1096 assert( *lcp != NULL );
1098 ldap_pvt_thread_mutex_lock( &li->li_conninfo.lai_mutex );
1100 if ( (*lcp)->lc_refcnt == 1 ) {
1101 Debug( LDAP_DEBUG_ANY,
1102 "%s ldap_back_retry: retrying URI=\"%s\" DN=\"%s\"\n",
1103 op->o_log_prefix, li->li_uri,
1104 BER_BVISNULL( &(*lcp)->lc_bound_ndn ) ?
1105 "" : (*lcp)->lc_bound_ndn.bv_val );
1107 ldap_unbind_ext( (*lcp)->lc_ld, NULL, NULL );
1108 (*lcp)->lc_ld = NULL;
1109 LDAP_BACK_CONN_ISBOUND_CLEAR( (*lcp) );
1111 /* lc here must be the regular lc, reset and ready for init */
1112 rc = ldap_back_prepare_conn( lcp, op, rs, sendok );
1113 if ( rc != LDAP_SUCCESS ) {
1118 rc = ldap_back_dobind_int( *lcp, op, rs, sendok, 0, 0 );
1125 Debug( LDAP_DEBUG_TRACE,
1126 "ldap_back_retry: conn %p refcnt=%u unable to retry.\n",
1127 (void *)(*lcp), (*lcp)->lc_refcnt, 0 );
1129 ldap_back_release_conn_lock( op, rs, *lcp, 0 );
1133 rs->sr_err = LDAP_UNAVAILABLE;
1134 rs->sr_text = "unable to retry";
1135 send_ldap_result( op, rs );
1139 ldap_pvt_thread_mutex_unlock( &li->li_conninfo.lai_mutex );
1145 ldap_back_proxy_authz_bind( ldapconn_t *lc, Operation *op, SlapReply *rs, ldap_back_send_t sendok )
1147 ldapinfo_t *li = (ldapinfo_t *)op->o_bd->be_private;
1148 struct berval binddn = slap_empty_bv;
1149 struct berval bindcred = slap_empty_bv;
1155 if ( !BER_BVISNULL( &op->o_conn->c_ndn ) ) {
1156 ndn = op->o_conn->c_ndn;
1163 * FIXME: we need to let clients use proxyAuthz
1164 * otherwise we cannot do symmetric pools of servers;
1165 * we have to live with the fact that a user can
1166 * authorize itself as any ID that is allowed
1167 * by the authzTo directive of the "proxyauthzdn".
1170 * NOTE: current Proxy Authorization specification
1171 * and implementation do not allow proxy authorization
1172 * control to be provided with Bind requests
1175 * if no bind took place yet, but the connection is bound
1176 * and the "proxyauthzdn" is set, then bind as
1177 * "proxyauthzdn" and explicitly add the proxyAuthz
1178 * control to every operation with the dn bound
1179 * to the connection as control value.
1182 /* bind as proxyauthzdn only if no idassert mode
1183 * is requested, or if the client's identity
1185 switch ( li->li_idassert_mode ) {
1186 case LDAP_BACK_IDASSERT_LEGACY:
1187 if ( !BER_BVISNULL( &ndn ) && !BER_BVISEMPTY( &ndn ) ) {
1188 if ( !BER_BVISNULL( &li->li_idassert_authcDN ) && !BER_BVISEMPTY( &li->li_idassert_authcDN ) )
1190 binddn = li->li_idassert_authcDN;
1191 bindcred = li->li_idassert_passwd;
1198 /* NOTE: rootdn can always idassert */
1199 if ( BER_BVISNULL( &ndn ) && li->li_idassert_authz == NULL ) {
1200 if ( li->li_idassert_flags & LDAP_BACK_AUTH_PRESCRIPTIVE ) {
1201 rs->sr_err = LDAP_INAPPROPRIATE_AUTH;
1202 if ( sendok & LDAP_BACK_SENDERR ) {
1203 send_ldap_result( op, rs );
1205 LDAP_BACK_CONN_ISBOUND_CLEAR( lc );
1208 rs->sr_err = LDAP_SUCCESS;
1209 binddn = slap_empty_bv;
1210 bindcred = slap_empty_bv;
1216 } else if ( li->li_idassert_authz && !be_isroot( op ) ) {
1217 struct berval authcDN;
1219 if ( BER_BVISNULL( &ndn ) ) {
1220 authcDN = slap_empty_bv;
1225 rs->sr_err = slap_sasl_matches( op, li->li_idassert_authz,
1226 &authcDN, &authcDN );
1227 if ( rs->sr_err != LDAP_SUCCESS ) {
1228 if ( li->li_idassert_flags & LDAP_BACK_AUTH_PRESCRIPTIVE ) {
1229 if ( sendok & LDAP_BACK_SENDERR ) {
1230 send_ldap_result( op, rs );
1232 LDAP_BACK_CONN_ISBOUND_CLEAR( lc );
1235 rs->sr_err = LDAP_SUCCESS;
1236 binddn = slap_empty_bv;
1237 bindcred = slap_empty_bv;
1245 binddn = li->li_idassert_authcDN;
1246 bindcred = li->li_idassert_passwd;
1251 if ( dobind && li->li_idassert_authmethod == LDAP_AUTH_SASL ) {
1252 #ifdef HAVE_CYRUS_SASL
1253 void *defaults = NULL;
1254 struct berval authzID = BER_BVNULL;
1257 /* if SASL supports native authz, prepare for it */
1258 if ( ( !op->o_do_not_cache || !op->o_is_auth_check ) &&
1259 ( li->li_idassert_flags & LDAP_BACK_AUTH_NATIVE_AUTHZ ) )
1261 switch ( li->li_idassert_mode ) {
1262 case LDAP_BACK_IDASSERT_OTHERID:
1263 case LDAP_BACK_IDASSERT_OTHERDN:
1264 authzID = li->li_idassert_authzID;
1267 case LDAP_BACK_IDASSERT_ANONYMOUS:
1268 BER_BVSTR( &authzID, "dn:" );
1271 case LDAP_BACK_IDASSERT_SELF:
1272 if ( BER_BVISNULL( &ndn ) ) {
1273 /* connection is not authc'd, so don't idassert */
1274 BER_BVSTR( &authzID, "dn:" );
1277 authzID.bv_len = STRLENOF( "dn:" ) + ndn.bv_len;
1278 authzID.bv_val = slap_sl_malloc( authzID.bv_len + 1, op->o_tmpmemctx );
1279 AC_MEMCPY( authzID.bv_val, "dn:", STRLENOF( "dn:" ) );
1280 AC_MEMCPY( authzID.bv_val + STRLENOF( "dn:" ),
1281 ndn.bv_val, ndn.bv_len + 1 );
1290 if ( li->li_idassert_secprops != NULL ) {
1291 rs->sr_err = ldap_set_option( lc->lc_ld,
1292 LDAP_OPT_X_SASL_SECPROPS,
1293 (void *)li->li_idassert_secprops );
1295 if ( rs->sr_err != LDAP_OPT_SUCCESS ) {
1296 rs->sr_err = LDAP_OTHER;
1297 if ( sendok & LDAP_BACK_SENDERR ) {
1298 send_ldap_result( op, rs );
1300 LDAP_BACK_CONN_ISBOUND_CLEAR( lc );
1305 defaults = lutil_sasl_defaults( lc->lc_ld,
1306 li->li_idassert_sasl_mech.bv_val,
1307 li->li_idassert_sasl_realm.bv_val,
1308 li->li_idassert_authcID.bv_val,
1309 li->li_idassert_passwd.bv_val,
1312 rs->sr_err = ldap_sasl_interactive_bind_s( lc->lc_ld, binddn.bv_val,
1313 li->li_idassert_sasl_mech.bv_val, NULL, NULL,
1314 LDAP_SASL_QUIET, lutil_sasl_interact,
1317 rs->sr_err = slap_map_api2result( rs );
1318 if ( rs->sr_err != LDAP_SUCCESS ) {
1319 LDAP_BACK_CONN_ISBOUND_CLEAR( lc );
1320 if ( sendok & LDAP_BACK_SENDERR ) {
1321 send_ldap_result( op, rs );
1325 LDAP_BACK_CONN_ISBOUND_SET( lc );
1328 lutil_sasl_freedefs( defaults );
1330 slap_sl_free( authzID.bv_val, op->o_tmpmemctx );
1334 #endif /* HAVE_CYRUS_SASL */
1337 switch ( li->li_idassert_authmethod ) {
1338 case LDAP_AUTH_NONE:
1339 LDAP_BACK_CONN_ISBOUND_SET( lc );
1342 case LDAP_AUTH_SIMPLE:
1343 rs->sr_err = ldap_sasl_bind( lc->lc_ld,
1344 binddn.bv_val, LDAP_SASL_SIMPLE,
1345 &bindcred, NULL, NULL, &msgid );
1350 LDAP_BACK_CONN_ISBOUND_CLEAR( lc );
1351 rs->sr_err = LDAP_AUTH_METHOD_NOT_SUPPORTED;
1352 if ( sendok & LDAP_BACK_SENDERR ) {
1353 send_ldap_result( op, rs );
1358 rc = ldap_back_op_result( lc, op, rs, msgid, 0, sendok );
1359 if ( rc == LDAP_SUCCESS ) {
1360 LDAP_BACK_CONN_ISBOUND_SET( lc );
1363 return LDAP_BACK_CONN_ISBOUND( lc );
1367 * ldap_back_proxy_authz_ctrl() prepends a proxyAuthz control
1368 * to existing server-side controls if required; if not,
1369 * the existing server-side controls are placed in *pctrls.
1370 * The caller, after using the controls in client API
1371 * operations, if ( *pctrls != op->o_ctrls ), should
1372 * free( (*pctrls)[ 0 ] ) and free( *pctrls ).
1373 * The function returns success if the control could
1374 * be added if required, or if it did nothing; in the future,
1375 * it might return some error if it failed.
1377 * if no bind took place yet, but the connection is bound
1378 * and the "proxyauthzdn" is set, then bind as "proxyauthzdn"
1379 * and explicitly add proxyAuthz the control to every operation
1380 * with the dn bound to the connection as control value.
1382 * If no server-side controls are defined for the operation,
1383 * simply add the proxyAuthz control; otherwise, if the
1384 * proxyAuthz control is not already set, add it as
1387 * FIXME: is controls order significant for security?
1388 * ANSWER: controls ordering and interoperability
1389 * must be indicated by the specs of each control; if none
1390 * is specified, the order is irrelevant.
1393 ldap_back_proxy_authz_ctrl(
1397 LDAPControl ***pctrls )
1399 ldapinfo_t *li = (ldapinfo_t *) op->o_bd->be_private;
1400 LDAPControl **ctrls = NULL;
1403 struct berval assertedID,
1408 rs->sr_err = LDAP_SUCCESS;
1410 /* FIXME: SASL/EXTERNAL over ldapi:// doesn't honor the authcID,
1411 * but if it is not set this test fails. We need a different
1412 * means to detect if idassert is enabled */
1413 if ( ( BER_BVISNULL( &li->li_idassert_authcID ) || BER_BVISEMPTY( &li->li_idassert_authcID ) )
1414 && ( BER_BVISNULL( &li->li_idassert_authcDN ) || BER_BVISEMPTY( &li->li_idassert_authcDN ) ) )
1419 if ( !op->o_conn || op->o_do_not_cache || be_isroot( op ) ) {
1423 if ( !BER_BVISNULL( &op->o_conn->c_ndn ) ) {
1424 ndn = op->o_conn->c_ndn;
1430 if ( li->li_idassert_mode == LDAP_BACK_IDASSERT_LEGACY ) {
1431 if ( op->o_proxy_authz ) {
1433 * FIXME: we do not want to perform proxyAuthz
1434 * on behalf of the client, because this would
1435 * be performed with "proxyauthzdn" privileges.
1437 * This might actually be too strict, since
1438 * the "proxyauthzdn" authzTo, and each entry's
1439 * authzFrom attributes may be crafted
1440 * to avoid unwanted proxyAuthz to take place.
1443 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
1444 rs->sr_text = "proxyAuthz not allowed within namingContext";
1449 if ( !BER_BVISNULL( &lc->lc_bound_ndn ) ) {
1453 if ( BER_BVISNULL( &ndn ) ) {
1457 if ( BER_BVISNULL( &li->li_idassert_authcDN ) ) {
1461 } else if ( li->li_idassert_authmethod == LDAP_AUTH_SASL ) {
1462 if ( ( li->li_idassert_flags & LDAP_BACK_AUTH_NATIVE_AUTHZ )
1463 /* && ( !BER_BVISNULL( &ndn )
1464 || LDAP_BACK_CONN_ISBOUND( lc ) ) */ )
1466 /* already asserted in SASL via native authz */
1467 /* NOTE: the test on lc->lc_bound is used to trap
1468 * native authorization of anonymous users,
1469 * since in that case ndn is NULL */
1473 } else if ( li->li_idassert_authz && !be_isroot( op ) ) {
1475 struct berval authcDN;
1477 if ( BER_BVISNULL( &ndn ) ) {
1478 authcDN = slap_empty_bv;
1482 rc = slap_sasl_matches( op, li->li_idassert_authz,
1483 &authcDN, & authcDN );
1484 if ( rc != LDAP_SUCCESS ) {
1485 if ( li->li_idassert_flags & LDAP_BACK_AUTH_PRESCRIPTIVE )
1487 /* ndn is not authorized
1488 * to use idassert */
1495 if ( op->o_proxy_authz ) {
1498 * 1) ignore the already set proxyAuthz control
1499 * 2) leave it in place, and don't set ours
1501 * 4) reject the operation
1503 * option (4) is very drastic
1504 * option (3) will make the remote server reject
1505 * the operation, thus being equivalent to (4)
1506 * option (2) will likely break the idassert
1507 * assumptions, so we cannot accept it;
1508 * option (1) means that we are contradicting
1509 * the client's reques.
1511 * I think (4) is the only correct choice.
1513 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
1514 rs->sr_text = "proxyAuthz not allowed within namingContext";
1517 if ( op->o_is_auth_check ) {
1518 mode = LDAP_BACK_IDASSERT_NOASSERT;
1521 mode = li->li_idassert_mode;
1525 case LDAP_BACK_IDASSERT_SELF:
1526 if ( BER_BVISNULL( &ndn ) ) {
1532 case LDAP_BACK_IDASSERT_LEGACY:
1533 /* original behavior:
1534 * assert the client's identity */
1535 if ( BER_BVISNULL( &ndn ) ) {
1536 assertedID = slap_empty_bv;
1542 case LDAP_BACK_IDASSERT_ANONYMOUS:
1543 /* assert "anonymous" */
1544 assertedID = slap_empty_bv;
1547 case LDAP_BACK_IDASSERT_NOASSERT:
1548 /* don't assert; bind as proxyauthzdn */
1551 case LDAP_BACK_IDASSERT_OTHERID:
1552 case LDAP_BACK_IDASSERT_OTHERDN:
1553 /* assert idassert DN */
1554 assertedID = li->li_idassert_authzID;
1561 if ( BER_BVISNULL( &assertedID ) ) {
1562 assertedID = slap_empty_bv;
1565 if ( op->o_ctrls ) {
1566 for ( i = 0; op->o_ctrls[ i ]; i++ )
1567 /* just count ctrls */ ;
1570 ctrls = op->o_tmpalloc( sizeof( LDAPControl * ) * (i + 2) + sizeof( LDAPControl ),
1572 ctrls[ 0 ] = (LDAPControl *)&ctrls[ i + 2 ];
1574 ctrls[ 0 ]->ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
1575 ctrls[ 0 ]->ldctl_iscritical = 1;
1577 switch ( li->li_idassert_mode ) {
1578 /* already in u:ID or dn:DN form */
1579 case LDAP_BACK_IDASSERT_OTHERID:
1580 case LDAP_BACK_IDASSERT_OTHERDN:
1581 ber_dupbv_x( &ctrls[ 0 ]->ldctl_value, &assertedID, op->o_tmpmemctx );
1584 /* needs the dn: prefix */
1586 ctrls[ 0 ]->ldctl_value.bv_len = assertedID.bv_len + STRLENOF( "dn:" );
1587 ctrls[ 0 ]->ldctl_value.bv_val = op->o_tmpalloc( ctrls[ 0 ]->ldctl_value.bv_len + 1,
1589 AC_MEMCPY( ctrls[ 0 ]->ldctl_value.bv_val, "dn:", STRLENOF( "dn:" ) );
1590 AC_MEMCPY( &ctrls[ 0 ]->ldctl_value.bv_val[ STRLENOF( "dn:" ) ],
1591 assertedID.bv_val, assertedID.bv_len + 1 );
1595 if ( op->o_ctrls ) {
1596 for ( i = 0; op->o_ctrls[ i ]; i++ ) {
1597 ctrls[ i + 1 ] = op->o_ctrls[ i ];
1600 ctrls[ i + 1 ] = NULL;
1603 if ( ctrls == NULL ) {
1604 ctrls = op->o_ctrls;
1613 ldap_back_proxy_authz_ctrl_free( Operation *op, LDAPControl ***pctrls )
1615 LDAPControl **ctrls = *pctrls;
1617 /* we assume that the first control is the proxyAuthz
1618 * added by back-ldap, so it's the only one we explicitly
1620 if ( ctrls && ctrls != op->o_ctrls ) {
1621 assert( ctrls[ 0 ] != NULL );
1623 if ( !BER_BVISNULL( &ctrls[ 0 ]->ldctl_value ) ) {
1624 op->o_tmpfree( ctrls[ 0 ]->ldctl_value.bv_val, op->o_tmpmemctx );
1627 op->o_tmpfree( ctrls, op->o_tmpmemctx );