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 );
1046 #ifndef LDAP_NULL_IS_NULL
1047 if ( match != NULL && match[ 0 ] == '\0' ) {
1048 ldap_memfree( match );
1051 if ( text != NULL && text[ 0 ] == '\0' ) {
1052 ldap_memfree( text );
1055 #endif /* LDAP_NULL_IS_NULL */
1057 if ( rc != LDAP_SUCCESS ) {
1063 /* if the error in the reply structure is not
1064 * LDAP_SUCCESS, try to map it from client
1065 * to server error */
1066 if ( !ERR_OK( rs->sr_err ) ) {
1067 rs->sr_err = slap_map_api2result( rs );
1069 /* internal ops ( op->o_conn == NULL )
1070 * must not reply to client */
1071 if ( op->o_conn && !op->o_do_not_cache && match ) {
1073 /* record the (massaged) matched
1074 * DN into the reply structure */
1075 rs->sr_matched = match;
1079 ( ( sendok & LDAP_BACK_SENDOK )
1080 || ( ( sendok & LDAP_BACK_SENDERR ) && rs->sr_err != LDAP_SUCCESS ) ) )
1082 send_ldap_result( op, rs );
1085 if ( rs->sr_matched != match ) {
1086 free( (char *)rs->sr_matched );
1088 rs->sr_matched = NULL;
1089 ldap_memfree( match );
1092 ldap_memfree( text );
1095 return( ERR_OK( rs->sr_err ) ? LDAP_SUCCESS : rs->sr_err );
1098 /* return true if bound, false if failed */
1100 ldap_back_retry( ldapconn_t **lcp, Operation *op, SlapReply *rs, ldap_back_send_t sendok )
1103 ldapinfo_t *li = (ldapinfo_t *)op->o_bd->be_private;
1105 assert( lcp != NULL );
1106 assert( *lcp != NULL );
1108 ldap_pvt_thread_mutex_lock( &li->li_conninfo.lai_mutex );
1110 if ( (*lcp)->lc_refcnt == 1 ) {
1111 Debug( LDAP_DEBUG_ANY,
1112 "%s ldap_back_retry: retrying URI=\"%s\" DN=\"%s\"\n",
1113 op->o_log_prefix, li->li_uri,
1114 BER_BVISNULL( &(*lcp)->lc_bound_ndn ) ?
1115 "" : (*lcp)->lc_bound_ndn.bv_val );
1117 ldap_unbind_ext( (*lcp)->lc_ld, NULL, NULL );
1118 (*lcp)->lc_ld = NULL;
1119 LDAP_BACK_CONN_ISBOUND_CLEAR( (*lcp) );
1121 /* lc here must be the regular lc, reset and ready for init */
1122 rc = ldap_back_prepare_conn( lcp, op, rs, sendok );
1123 if ( rc != LDAP_SUCCESS ) {
1128 rc = ldap_back_dobind_int( *lcp, op, rs, sendok, 0, 0 );
1135 Debug( LDAP_DEBUG_TRACE,
1136 "ldap_back_retry: conn %p refcnt=%u unable to retry.\n",
1137 (void *)(*lcp), (*lcp)->lc_refcnt, 0 );
1139 ldap_back_release_conn_lock( op, rs, *lcp, 0 );
1143 rs->sr_err = LDAP_UNAVAILABLE;
1144 rs->sr_text = "unable to retry";
1145 send_ldap_result( op, rs );
1149 ldap_pvt_thread_mutex_unlock( &li->li_conninfo.lai_mutex );
1155 ldap_back_proxy_authz_bind( ldapconn_t *lc, Operation *op, SlapReply *rs, ldap_back_send_t sendok )
1157 ldapinfo_t *li = (ldapinfo_t *)op->o_bd->be_private;
1158 struct berval binddn = slap_empty_bv;
1159 struct berval bindcred = slap_empty_bv;
1165 if ( !BER_BVISNULL( &op->o_conn->c_ndn ) ) {
1166 ndn = op->o_conn->c_ndn;
1173 * FIXME: we need to let clients use proxyAuthz
1174 * otherwise we cannot do symmetric pools of servers;
1175 * we have to live with the fact that a user can
1176 * authorize itself as any ID that is allowed
1177 * by the authzTo directive of the "proxyauthzdn".
1180 * NOTE: current Proxy Authorization specification
1181 * and implementation do not allow proxy authorization
1182 * control to be provided with Bind requests
1185 * if no bind took place yet, but the connection is bound
1186 * and the "proxyauthzdn" is set, then bind as
1187 * "proxyauthzdn" and explicitly add the proxyAuthz
1188 * control to every operation with the dn bound
1189 * to the connection as control value.
1192 /* bind as proxyauthzdn only if no idassert mode
1193 * is requested, or if the client's identity
1195 switch ( li->li_idassert_mode ) {
1196 case LDAP_BACK_IDASSERT_LEGACY:
1197 if ( !BER_BVISNULL( &ndn ) && !BER_BVISEMPTY( &ndn ) ) {
1198 if ( !BER_BVISNULL( &li->li_idassert_authcDN ) && !BER_BVISEMPTY( &li->li_idassert_authcDN ) )
1200 binddn = li->li_idassert_authcDN;
1201 bindcred = li->li_idassert_passwd;
1208 /* NOTE: rootdn can always idassert */
1209 if ( BER_BVISNULL( &ndn ) && li->li_idassert_authz == NULL ) {
1210 if ( li->li_idassert_flags & LDAP_BACK_AUTH_PRESCRIPTIVE ) {
1211 rs->sr_err = LDAP_INAPPROPRIATE_AUTH;
1212 if ( sendok & LDAP_BACK_SENDERR ) {
1213 send_ldap_result( op, rs );
1215 LDAP_BACK_CONN_ISBOUND_CLEAR( lc );
1218 rs->sr_err = LDAP_SUCCESS;
1219 binddn = slap_empty_bv;
1220 bindcred = slap_empty_bv;
1226 } else if ( li->li_idassert_authz && !be_isroot( op ) ) {
1227 struct berval authcDN;
1229 if ( BER_BVISNULL( &ndn ) ) {
1230 authcDN = slap_empty_bv;
1235 rs->sr_err = slap_sasl_matches( op, li->li_idassert_authz,
1236 &authcDN, &authcDN );
1237 if ( rs->sr_err != LDAP_SUCCESS ) {
1238 if ( li->li_idassert_flags & LDAP_BACK_AUTH_PRESCRIPTIVE ) {
1239 if ( sendok & LDAP_BACK_SENDERR ) {
1240 send_ldap_result( op, rs );
1242 LDAP_BACK_CONN_ISBOUND_CLEAR( lc );
1245 rs->sr_err = LDAP_SUCCESS;
1246 binddn = slap_empty_bv;
1247 bindcred = slap_empty_bv;
1255 binddn = li->li_idassert_authcDN;
1256 bindcred = li->li_idassert_passwd;
1261 if ( dobind && li->li_idassert_authmethod == LDAP_AUTH_SASL ) {
1262 #ifdef HAVE_CYRUS_SASL
1263 void *defaults = NULL;
1264 struct berval authzID = BER_BVNULL;
1267 /* if SASL supports native authz, prepare for it */
1268 if ( ( !op->o_do_not_cache || !op->o_is_auth_check ) &&
1269 ( li->li_idassert_flags & LDAP_BACK_AUTH_NATIVE_AUTHZ ) )
1271 switch ( li->li_idassert_mode ) {
1272 case LDAP_BACK_IDASSERT_OTHERID:
1273 case LDAP_BACK_IDASSERT_OTHERDN:
1274 authzID = li->li_idassert_authzID;
1277 case LDAP_BACK_IDASSERT_ANONYMOUS:
1278 BER_BVSTR( &authzID, "dn:" );
1281 case LDAP_BACK_IDASSERT_SELF:
1282 if ( BER_BVISNULL( &ndn ) ) {
1283 /* connection is not authc'd, so don't idassert */
1284 BER_BVSTR( &authzID, "dn:" );
1287 authzID.bv_len = STRLENOF( "dn:" ) + ndn.bv_len;
1288 authzID.bv_val = slap_sl_malloc( authzID.bv_len + 1, op->o_tmpmemctx );
1289 AC_MEMCPY( authzID.bv_val, "dn:", STRLENOF( "dn:" ) );
1290 AC_MEMCPY( authzID.bv_val + STRLENOF( "dn:" ),
1291 ndn.bv_val, ndn.bv_len + 1 );
1300 if ( li->li_idassert_secprops != NULL ) {
1301 rs->sr_err = ldap_set_option( lc->lc_ld,
1302 LDAP_OPT_X_SASL_SECPROPS,
1303 (void *)li->li_idassert_secprops );
1305 if ( rs->sr_err != LDAP_OPT_SUCCESS ) {
1306 rs->sr_err = LDAP_OTHER;
1307 if ( sendok & LDAP_BACK_SENDERR ) {
1308 send_ldap_result( op, rs );
1310 LDAP_BACK_CONN_ISBOUND_CLEAR( lc );
1315 defaults = lutil_sasl_defaults( lc->lc_ld,
1316 li->li_idassert_sasl_mech.bv_val,
1317 li->li_idassert_sasl_realm.bv_val,
1318 li->li_idassert_authcID.bv_val,
1319 li->li_idassert_passwd.bv_val,
1322 rs->sr_err = ldap_sasl_interactive_bind_s( lc->lc_ld, binddn.bv_val,
1323 li->li_idassert_sasl_mech.bv_val, NULL, NULL,
1324 LDAP_SASL_QUIET, lutil_sasl_interact,
1327 rs->sr_err = slap_map_api2result( rs );
1328 if ( rs->sr_err != LDAP_SUCCESS ) {
1329 LDAP_BACK_CONN_ISBOUND_CLEAR( lc );
1330 if ( sendok & LDAP_BACK_SENDERR ) {
1331 send_ldap_result( op, rs );
1335 LDAP_BACK_CONN_ISBOUND_SET( lc );
1338 lutil_sasl_freedefs( defaults );
1340 slap_sl_free( authzID.bv_val, op->o_tmpmemctx );
1344 #endif /* HAVE_CYRUS_SASL */
1347 switch ( li->li_idassert_authmethod ) {
1348 case LDAP_AUTH_NONE:
1349 LDAP_BACK_CONN_ISBOUND_SET( lc );
1352 case LDAP_AUTH_SIMPLE:
1353 rs->sr_err = ldap_sasl_bind( lc->lc_ld,
1354 binddn.bv_val, LDAP_SASL_SIMPLE,
1355 &bindcred, NULL, NULL, &msgid );
1360 LDAP_BACK_CONN_ISBOUND_CLEAR( lc );
1361 rs->sr_err = LDAP_AUTH_METHOD_NOT_SUPPORTED;
1362 if ( sendok & LDAP_BACK_SENDERR ) {
1363 send_ldap_result( op, rs );
1368 rc = ldap_back_op_result( lc, op, rs, msgid, 0, sendok );
1369 if ( rc == LDAP_SUCCESS ) {
1370 LDAP_BACK_CONN_ISBOUND_SET( lc );
1373 return LDAP_BACK_CONN_ISBOUND( lc );
1377 * ldap_back_proxy_authz_ctrl() prepends a proxyAuthz control
1378 * to existing server-side controls if required; if not,
1379 * the existing server-side controls are placed in *pctrls.
1380 * The caller, after using the controls in client API
1381 * operations, if ( *pctrls != op->o_ctrls ), should
1382 * free( (*pctrls)[ 0 ] ) and free( *pctrls ).
1383 * The function returns success if the control could
1384 * be added if required, or if it did nothing; in the future,
1385 * it might return some error if it failed.
1387 * if no bind took place yet, but the connection is bound
1388 * and the "proxyauthzdn" is set, then bind as "proxyauthzdn"
1389 * and explicitly add proxyAuthz the control to every operation
1390 * with the dn bound to the connection as control value.
1392 * If no server-side controls are defined for the operation,
1393 * simply add the proxyAuthz control; otherwise, if the
1394 * proxyAuthz control is not already set, add it as
1397 * FIXME: is controls order significant for security?
1398 * ANSWER: controls ordering and interoperability
1399 * must be indicated by the specs of each control; if none
1400 * is specified, the order is irrelevant.
1403 ldap_back_proxy_authz_ctrl(
1407 LDAPControl ***pctrls )
1409 ldapinfo_t *li = (ldapinfo_t *) op->o_bd->be_private;
1410 LDAPControl **ctrls = NULL;
1413 struct berval assertedID,
1418 rs->sr_err = LDAP_SUCCESS;
1420 /* FIXME: SASL/EXTERNAL over ldapi:// doesn't honor the authcID,
1421 * but if it is not set this test fails. We need a different
1422 * means to detect if idassert is enabled */
1423 if ( ( BER_BVISNULL( &li->li_idassert_authcID ) || BER_BVISEMPTY( &li->li_idassert_authcID ) )
1424 && ( BER_BVISNULL( &li->li_idassert_authcDN ) || BER_BVISEMPTY( &li->li_idassert_authcDN ) ) )
1429 if ( !op->o_conn || op->o_do_not_cache || be_isroot( op ) ) {
1433 if ( !BER_BVISNULL( &op->o_conn->c_ndn ) ) {
1434 ndn = op->o_conn->c_ndn;
1440 if ( li->li_idassert_mode == LDAP_BACK_IDASSERT_LEGACY ) {
1441 if ( op->o_proxy_authz ) {
1443 * FIXME: we do not want to perform proxyAuthz
1444 * on behalf of the client, because this would
1445 * be performed with "proxyauthzdn" privileges.
1447 * This might actually be too strict, since
1448 * the "proxyauthzdn" authzTo, and each entry's
1449 * authzFrom attributes may be crafted
1450 * to avoid unwanted proxyAuthz to take place.
1453 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
1454 rs->sr_text = "proxyAuthz not allowed within namingContext";
1459 if ( !BER_BVISNULL( &lc->lc_bound_ndn ) ) {
1463 if ( BER_BVISNULL( &ndn ) ) {
1467 if ( BER_BVISNULL( &li->li_idassert_authcDN ) ) {
1471 } else if ( li->li_idassert_authmethod == LDAP_AUTH_SASL ) {
1472 if ( ( li->li_idassert_flags & LDAP_BACK_AUTH_NATIVE_AUTHZ )
1473 /* && ( !BER_BVISNULL( &ndn )
1474 || LDAP_BACK_CONN_ISBOUND( lc ) ) */ )
1476 /* already asserted in SASL via native authz */
1477 /* NOTE: the test on lc->lc_bound is used to trap
1478 * native authorization of anonymous users,
1479 * since in that case ndn is NULL */
1483 } else if ( li->li_idassert_authz && !be_isroot( op ) ) {
1485 struct berval authcDN;
1487 if ( BER_BVISNULL( &ndn ) ) {
1488 authcDN = slap_empty_bv;
1492 rc = slap_sasl_matches( op, li->li_idassert_authz,
1493 &authcDN, & authcDN );
1494 if ( rc != LDAP_SUCCESS ) {
1495 if ( li->li_idassert_flags & LDAP_BACK_AUTH_PRESCRIPTIVE )
1497 /* ndn is not authorized
1498 * to use idassert */
1505 if ( op->o_proxy_authz ) {
1508 * 1) ignore the already set proxyAuthz control
1509 * 2) leave it in place, and don't set ours
1511 * 4) reject the operation
1513 * option (4) is very drastic
1514 * option (3) will make the remote server reject
1515 * the operation, thus being equivalent to (4)
1516 * option (2) will likely break the idassert
1517 * assumptions, so we cannot accept it;
1518 * option (1) means that we are contradicting
1519 * the client's reques.
1521 * I think (4) is the only correct choice.
1523 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
1524 rs->sr_text = "proxyAuthz not allowed within namingContext";
1527 if ( op->o_is_auth_check ) {
1528 mode = LDAP_BACK_IDASSERT_NOASSERT;
1531 mode = li->li_idassert_mode;
1535 case LDAP_BACK_IDASSERT_SELF:
1536 if ( BER_BVISNULL( &ndn ) ) {
1542 case LDAP_BACK_IDASSERT_LEGACY:
1543 /* original behavior:
1544 * assert the client's identity */
1545 if ( BER_BVISNULL( &ndn ) ) {
1546 assertedID = slap_empty_bv;
1552 case LDAP_BACK_IDASSERT_ANONYMOUS:
1553 /* assert "anonymous" */
1554 assertedID = slap_empty_bv;
1557 case LDAP_BACK_IDASSERT_NOASSERT:
1558 /* don't assert; bind as proxyauthzdn */
1561 case LDAP_BACK_IDASSERT_OTHERID:
1562 case LDAP_BACK_IDASSERT_OTHERDN:
1563 /* assert idassert DN */
1564 assertedID = li->li_idassert_authzID;
1571 if ( BER_BVISNULL( &assertedID ) ) {
1572 assertedID = slap_empty_bv;
1575 if ( op->o_ctrls ) {
1576 for ( i = 0; op->o_ctrls[ i ]; i++ )
1577 /* just count ctrls */ ;
1580 ctrls = op->o_tmpalloc( sizeof( LDAPControl * ) * (i + 2) + sizeof( LDAPControl ),
1582 ctrls[ 0 ] = (LDAPControl *)&ctrls[ i + 2 ];
1584 ctrls[ 0 ]->ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
1585 ctrls[ 0 ]->ldctl_iscritical = 1;
1587 switch ( li->li_idassert_mode ) {
1588 /* already in u:ID or dn:DN form */
1589 case LDAP_BACK_IDASSERT_OTHERID:
1590 case LDAP_BACK_IDASSERT_OTHERDN:
1591 ber_dupbv_x( &ctrls[ 0 ]->ldctl_value, &assertedID, op->o_tmpmemctx );
1594 /* needs the dn: prefix */
1596 ctrls[ 0 ]->ldctl_value.bv_len = assertedID.bv_len + STRLENOF( "dn:" );
1597 ctrls[ 0 ]->ldctl_value.bv_val = op->o_tmpalloc( ctrls[ 0 ]->ldctl_value.bv_len + 1,
1599 AC_MEMCPY( ctrls[ 0 ]->ldctl_value.bv_val, "dn:", STRLENOF( "dn:" ) );
1600 AC_MEMCPY( &ctrls[ 0 ]->ldctl_value.bv_val[ STRLENOF( "dn:" ) ],
1601 assertedID.bv_val, assertedID.bv_len + 1 );
1605 if ( op->o_ctrls ) {
1606 for ( i = 0; op->o_ctrls[ i ]; i++ ) {
1607 ctrls[ i + 1 ] = op->o_ctrls[ i ];
1610 ctrls[ i + 1 ] = NULL;
1613 if ( ctrls == NULL ) {
1614 ctrls = op->o_ctrls;
1623 ldap_back_proxy_authz_ctrl_free( Operation *op, LDAPControl ***pctrls )
1625 LDAPControl **ctrls = *pctrls;
1627 /* we assume that the first control is the proxyAuthz
1628 * added by back-ldap, so it's the only one we explicitly
1630 if ( ctrls && ctrls != op->o_ctrls ) {
1631 assert( ctrls[ 0 ] != NULL );
1633 if ( !BER_BVISNULL( &ctrls[ 0 ]->ldctl_value ) ) {
1634 op->o_tmpfree( ctrls[ 0 ]->ldctl_value.bv_val, op->o_tmpmemctx );
1637 op->o_tmpfree( ctrls, op->o_tmpmemctx );