1 /* bind.c - ldap backend bind function */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1999-2005 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 the Howard Chu for inclusion
20 * in OpenLDAP Software and subsequently enhanced by Pierangelo
28 #include <ac/socket.h>
29 #include <ac/string.h>
33 #include "back-ldap.h"
35 #include <lutil_ldap.h>
37 #define PRINT_CONNTREE 0
39 static LDAP_REBIND_PROC ldap_back_rebind;
42 ldap_back_proxy_authz_bind( struct ldapconn *lc, Operation *op, SlapReply *rs );
45 ldap_back_bind( Operation *op, SlapReply *rs )
47 struct ldapinfo *li = (struct ldapinfo *) op->o_bd->be_private;
53 lc = ldap_back_getconn( op, rs );
58 if ( !BER_BVISNULL( &lc->lc_bound_ndn ) ) {
59 ch_free( lc->lc_bound_ndn.bv_val );
60 BER_BVZERO( &lc->lc_bound_ndn );
64 /* method is always LDAP_AUTH_SIMPLE if we got here */
65 rs->sr_err = ldap_sasl_bind( lc->lc_ld, op->o_req_dn.bv_val,
67 &op->orb_cred, op->o_ctrls, NULL, &msgid );
68 rc = ldap_back_op_result( lc, op, rs, msgid, 1 );
70 if ( rc == LDAP_SUCCESS ) {
71 /* If defined, proxyAuthz will be used also when
72 * back-ldap is the authorizing backend; for this
73 * purpose, a successful bind is followed by a
74 * bind with the configured identity assertion */
75 /* NOTE: use with care */
76 if ( li->idassert_flags & LDAP_BACK_AUTH_OVERRIDE ) {
77 ldap_back_proxy_authz_bind( lc, op, rs );
78 if ( lc->lc_bound == 0 ) {
85 ber_dupbv( &lc->lc_bound_ndn, &op->o_req_ndn );
88 if ( !BER_BVISNULL( &lc->lc_cred ) ) {
89 memset( lc->lc_cred.bv_val, 0,
91 ch_free( lc->lc_cred.bv_val );
93 ber_dupbv( &lc->lc_cred, &op->orb_cred );
94 ldap_set_rebind_proc( lc->lc_ld, ldap_back_rebind, lc );
99 /* must re-insert if local DN changed as result of bind */
100 if ( lc->lc_bound && !dn_match( &op->o_req_ndn, &lc->lc_local_ndn ) ) {
103 ldap_pvt_thread_mutex_lock( &li->conn_mutex );
104 lc = avl_delete( &li->conntree, (caddr_t)lc,
105 ldap_back_conn_cmp );
106 if ( !BER_BVISNULL( &lc->lc_local_ndn ) ) {
107 ch_free( lc->lc_local_ndn.bv_val );
109 ber_dupbv( &lc->lc_local_ndn, &op->o_req_ndn );
110 lerr = avl_insert( &li->conntree, (caddr_t)lc,
111 ldap_back_conn_cmp, ldap_back_conn_dup );
112 ldap_pvt_thread_mutex_unlock( &li->conn_mutex );
114 ldap_back_conn_free( lc );
124 * compares two struct ldapconn based on the value of the conn pointer;
128 ldap_back_conn_cmp( const void *c1, const void *c2 )
130 const struct ldapconn *lc1 = (const struct ldapconn *)c1;
131 const struct ldapconn *lc2 = (const struct ldapconn *)c2;
134 /* If local DNs don't match, it is definitely not a match */
135 rc = ber_bvcmp( &lc1->lc_local_ndn, &lc2->lc_local_ndn );
140 /* For shared sessions, conn is NULL. Only explicitly
141 * bound sessions will have non-NULL conn.
143 return SLAP_PTRCMP( lc1->lc_conn, lc2->lc_conn );
149 * returns -1 in case a duplicate struct ldapconn has been inserted;
153 ldap_back_conn_dup( void *c1, void *c2 )
155 struct ldapconn *lc1 = (struct ldapconn *)c1;
156 struct ldapconn *lc2 = (struct ldapconn *)c2;
158 /* Cannot have more than one shared session with same DN */
159 if ( dn_match( &lc1->lc_local_ndn, &lc2->lc_local_ndn ) &&
160 lc1->lc_conn == lc2->lc_conn )
168 #if PRINT_CONNTREE > 0
170 ravl_print( Avlnode *root, int depth )
179 ravl_print( root->avl_right, depth+1 );
181 for ( i = 0; i < depth; i++ ) {
186 printf( "lc(%lx) local(%s) conn(%lx) %d\n",
187 lc, lc->lc_local_ndn.bv_val, lc->lc_conn, root->avl_bf );
189 ravl_print( root->avl_left, depth+1 );
193 myprint( Avlnode *root )
195 printf( "********\n" );
198 printf( "\tNULL\n" );
201 ravl_print( root, 0 );
204 printf( "********\n" );
206 #endif /* PRINT_CONNTREE */
209 ldap_back_freeconn( Operation *op, struct ldapconn *lc )
211 struct ldapinfo *li = (struct ldapinfo *) op->o_bd->be_private;
213 ldap_pvt_thread_mutex_lock( &li->conn_mutex );
214 lc = avl_delete( &li->conntree, (caddr_t)lc,
215 ldap_back_conn_cmp );
216 ldap_back_conn_free( (void *)lc );
217 ldap_pvt_thread_mutex_unlock( &li->conn_mutex );
223 ldap_back_getconn( Operation *op, SlapReply *rs )
225 struct ldapinfo *li = (struct ldapinfo *)op->o_bd->be_private;
226 struct ldapconn *lc, lc_curr;
230 /* Searches for a ldapconn in the avl tree */
232 /* Explicit binds must not be shared */
233 if ( op->o_tag == LDAP_REQ_BIND
235 && op->o_conn->c_authz_backend
236 && op->o_bd->be_private == op->o_conn->c_authz_backend->be_private ) )
238 lc_curr.lc_conn = op->o_conn;
241 lc_curr.lc_conn = NULL;
244 /* Internal searches are privileged and shared. So is root. */
245 if ( op->o_do_not_cache || be_isroot( op ) ) {
246 lc_curr.lc_local_ndn = op->o_bd->be_rootndn;
247 lc_curr.lc_conn = NULL;
251 lc_curr.lc_local_ndn = op->o_ndn;
254 ldap_pvt_thread_mutex_lock( &li->conn_mutex );
255 lc = (struct ldapconn *)avl_find( li->conntree,
256 (caddr_t)&lc_curr, ldap_back_conn_cmp );
257 ldap_pvt_thread_mutex_unlock( &li->conn_mutex );
259 /* Looks like we didn't get a bind. Open a new session... */
261 int vers = op->o_protocol;
262 rs->sr_err = ldap_initialize( &ld, li->url );
264 if ( rs->sr_err != LDAP_SUCCESS ) {
265 rs->sr_err = slap_map_api2result( rs );
266 if ( rs->sr_text == NULL ) {
267 rs->sr_text = "ldap_initialize() failed";
270 send_ldap_result( op, rs );
275 /* Set LDAP version. This will always succeed: If the client
276 * bound with a particular version, then so can we.
278 ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION,
279 (const void *)&vers );
280 /* FIXME: configurable? */
281 ldap_set_option( ld, LDAP_OPT_REFERRALS, LDAP_OPT_ON );
283 lc = (struct ldapconn *)ch_malloc( sizeof( struct ldapconn ) );
284 lc->lc_conn = lc_curr.lc_conn;
286 ber_dupbv( &lc->lc_local_ndn, &lc_curr.lc_local_ndn );
288 ldap_pvt_thread_mutex_init( &lc->lc_mutex );
291 ber_dupbv( &lc->lc_cred, &li->acl_passwd );
292 ber_dupbv( &lc->lc_bound_ndn, &li->acl_authcDN );
295 BER_BVZERO( &lc->lc_cred );
296 BER_BVZERO( &lc->lc_bound_ndn );
297 if ( op->o_conn && !BER_BVISEMPTY( &op->o_ndn )
298 && op->o_bd == op->o_conn->c_authz_backend )
300 ber_dupbv( &lc->lc_bound_ndn, &op->o_ndn );
306 /* Inserts the newly created ldapconn in the avl tree */
307 ldap_pvt_thread_mutex_lock( &li->conn_mutex );
308 rs->sr_err = avl_insert( &li->conntree, (caddr_t)lc,
309 ldap_back_conn_cmp, ldap_back_conn_dup );
311 #if PRINT_CONNTREE > 0
312 myprint( li->conntree );
313 #endif /* PRINT_CONNTREE */
315 ldap_pvt_thread_mutex_unlock( &li->conn_mutex );
317 Debug( LDAP_DEBUG_TRACE,
318 "=>ldap_back_getconn: conn %p inserted\n", (void *) lc, 0, 0 );
320 /* Err could be -1 in case a duplicate ldapconn is inserted */
321 if ( rs->sr_err != 0 ) {
322 ldap_back_conn_free( lc );
324 send_ldap_error( op, rs, LDAP_OTHER,
325 "internal server error" );
330 Debug( LDAP_DEBUG_TRACE,
331 "=>ldap_back_getconn: conn %p fetched\n", (void *) lc, 0, 0 );
340 * Note: as the check for the value of lc->lc_bound was already here, I removed
341 * it from all the callers, and I made the function return the flag, so
342 * it can be used to simplify the check.
345 ldap_back_dobind( struct ldapconn *lc, Operation *op, SlapReply *rs )
350 ldap_pvt_thread_mutex_lock( &lc->lc_mutex );
351 if ( !lc->lc_bound ) {
353 * FIXME: we need to let clients use proxyAuthz
354 * otherwise we cannot do symmetric pools of servers;
355 * we have to live with the fact that a user can
356 * authorize itself as any ID that is allowed
357 * by the authzTo directive of the "proxyauthzdn".
360 * NOTE: current Proxy Authorization specification
361 * and implementation do not allow proxy authorization
362 * control to be provided with Bind requests
365 * if no bind took place yet, but the connection is bound
366 * and the "idassert-authcDN" (or other ID) is set,
367 * then bind as the asserting ideintity and explicitly
368 * add the proxyAuthz control to every operation with the
369 * dn bound to the connection as control value.
371 if ( op->o_conn != NULL && BER_BVISNULL( &lc->lc_bound_ndn ) ) {
372 (void)ldap_back_proxy_authz_bind( lc, op, rs );
376 rs->sr_err = ldap_sasl_bind( lc->lc_ld,
377 lc->lc_bound_ndn.bv_val,
378 LDAP_SASL_SIMPLE, &lc->lc_cred,
379 NULL, NULL, &msgid );
381 rc = ldap_back_op_result( lc, op, rs, msgid, 0 );
382 if ( rc == LDAP_SUCCESS ) {
389 ldap_pvt_thread_mutex_unlock( &lc->lc_mutex );
396 * This is a callback used for chasing referrals using the same
397 * credentials as the original user on this session.
400 ldap_back_rebind( LDAP *ld, LDAP_CONST char *url, ber_tag_t request,
401 ber_int_t msgid, void *params )
403 struct ldapconn *lc = params;
405 return ldap_sasl_bind_s( ld, lc->lc_bound_ndn.bv_val,
406 LDAP_SASL_SIMPLE, &lc->lc_cred, NULL, NULL, NULL );
418 LDAPMessage *res = NULL;
421 #define ERR_OK(err) ((err) == LDAP_SUCCESS || (err) == LDAP_COMPARE_FALSE || (err) == LDAP_COMPARE_TRUE)
424 rs->sr_matched = NULL;
426 /* if the error recorded in the reply corresponds
427 * to a successful state, get the error from the
428 * remote server response */
429 if ( ERR_OK( rs->sr_err ) ) {
431 struct timeval tv = { 0, 0 };
434 /* if result parsing fails, note the failure reason */
435 switch ( ldap_result( lc->lc_ld, msgid, 1, &tv, &res ) ) {
438 tv.tv_usec = 100000; /* 0.1 s */
439 ldap_pvt_thread_yield();
443 ldap_get_option( lc->lc_ld, LDAP_OPT_ERROR_NUMBER,
448 /* otherwise get the result; if it is not
449 * LDAP_SUCCESS, record it in the reply
450 * structure (this includes
451 * LDAP_COMPARE_{TRUE|FALSE}) */
453 rc = ldap_parse_result( lc->lc_ld, res, &rs->sr_err,
454 &match, &text, NULL, NULL, 1 );
456 if ( rc != LDAP_SUCCESS ) {
462 /* if the error in the reply structure is not
463 * LDAP_SUCCESS, try to map it from client
465 if ( !ERR_OK( rs->sr_err ) ) {
466 rs->sr_err = slap_map_api2result( rs );
468 /* internal ops ( op->o_conn == NULL )
469 * must not reply to client */
470 if ( op->o_conn && !op->o_do_not_cache && match ) {
472 /* record the (massaged) matched
473 * DN into the reply structure */
474 rs->sr_matched = match;
477 if ( op->o_conn && ( sendok || rs->sr_err != LDAP_SUCCESS ) ) {
478 send_ldap_result( op, rs );
481 if ( rs->sr_matched != match ) {
482 free( (char *)rs->sr_matched );
484 rs->sr_matched = NULL;
485 ldap_memfree( match );
488 ldap_memfree( text );
491 return( ERR_OK( rs->sr_err ) ? 0 : -1 );
494 /* return true if bound, false if failed */
496 ldap_back_retry( struct ldapconn *lc, Operation *op, SlapReply *rs )
498 struct ldapinfo *li = (struct ldapinfo *)op->o_bd->be_private;
499 int vers = op->o_protocol;
502 ldap_pvt_thread_mutex_lock( &lc->lc_mutex );
503 ldap_unbind_ext_s( lc->lc_ld, NULL, NULL );
505 rs->sr_err = ldap_initialize( &ld, li->url );
507 if ( rs->sr_err != LDAP_SUCCESS ) {
508 rs->sr_err = slap_map_api2result( rs );
509 if ( rs->sr_text == NULL ) {
510 rs->sr_text = "ldap_initialize() failed";
513 send_ldap_result( op, rs );
518 /* Set LDAP version. This will always succeed: If the client
519 * bound with a particular version, then so can we.
521 ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, (const void *)&vers );
522 /* FIXME: configurable? */
523 ldap_set_option( ld, LDAP_OPT_REFERRALS, LDAP_OPT_ON );
525 ldap_pvt_thread_mutex_unlock( &lc->lc_mutex );
526 return ldap_back_dobind( lc, op, rs );
530 ldap_back_proxy_authz_bind( struct ldapconn *lc, Operation *op, SlapReply *rs )
532 struct ldapinfo *li = (struct ldapinfo *)op->o_bd->be_private;
533 struct berval binddn = slap_empty_bv;
534 struct berval bindcred = slap_empty_bv;
540 * FIXME: we need to let clients use proxyAuthz
541 * otherwise we cannot do symmetric pools of servers;
542 * we have to live with the fact that a user can
543 * authorize itself as any ID that is allowed
544 * by the authzTo directive of the "proxyauthzdn".
547 * NOTE: current Proxy Authorization specification
548 * and implementation do not allow proxy authorization
549 * control to be provided with Bind requests
552 * if no bind took place yet, but the connection is bound
553 * and the "proxyauthzdn" is set, then bind as
554 * "proxyauthzdn" and explicitly add the proxyAuthz
555 * control to every operation with the dn bound
556 * to the connection as control value.
559 /* bind as proxyauthzdn only if no idassert mode
560 * is requested, or if the client's identity
562 switch ( li->idassert_mode ) {
563 case LDAP_BACK_IDASSERT_LEGACY:
564 if ( !BER_BVISNULL( &op->o_conn->c_ndn ) && !BER_BVISEMPTY( &op->o_conn->c_ndn ) ) {
565 if ( !BER_BVISNULL( &li->idassert_authcDN ) && !BER_BVISEMPTY( &li->idassert_authcDN ) )
567 binddn = li->idassert_authcDN;
568 bindcred = li->idassert_passwd;
575 if ( li->idassert_authz ) {
576 struct berval authcDN;
578 if ( BER_BVISNULL( &op->o_conn->c_ndn ) ) {
579 authcDN = slap_empty_bv;
581 authcDN = op->o_conn->c_ndn;
583 rs->sr_err = slap_sasl_matches( op, li->idassert_authz,
584 &authcDN, &authcDN );
585 if ( rs->sr_err != LDAP_SUCCESS ) {
586 send_ldap_result( op, rs );
592 binddn = li->idassert_authcDN;
593 bindcred = li->idassert_passwd;
598 if ( dobind && li->idassert_authmethod == LDAP_AUTH_SASL ) {
599 #ifdef HAVE_CYRUS_SASL
600 void *defaults = NULL;
601 struct berval authzID = BER_BVNULL;
604 /* if SASL supports native authz, prepare for it */
605 if ( ( !op->o_do_not_cache || !op->o_is_auth_check ) &&
606 ( li->idassert_flags & LDAP_BACK_AUTH_NATIVE_AUTHZ ) )
608 switch ( li->idassert_mode ) {
609 case LDAP_BACK_IDASSERT_OTHERID:
610 case LDAP_BACK_IDASSERT_OTHERDN:
611 authzID = li->idassert_authzID;
614 case LDAP_BACK_IDASSERT_ANONYMOUS:
615 BER_BVSTR( &authzID, "dn:" );
618 case LDAP_BACK_IDASSERT_SELF:
619 if ( BER_BVISNULL( &op->o_conn->c_ndn ) ) {
620 /* connection is not authc'd, so don't idassert */
621 BER_BVSTR( &authzID, "dn:" );
624 authzID.bv_len = STRLENOF( "dn:" ) + op->o_conn->c_ndn.bv_len;
625 authzID.bv_val = slap_sl_malloc( authzID.bv_len + 1, op->o_tmpmemctx );
626 AC_MEMCPY( authzID.bv_val, "dn:", STRLENOF( "dn:" ) );
627 AC_MEMCPY( authzID.bv_val + STRLENOF( "dn:" ),
628 op->o_conn->c_ndn.bv_val, op->o_conn->c_ndn.bv_len + 1 );
637 #if 0 /* will deal with this later... */
638 if ( sasl_secprops != NULL ) {
639 rs->sr_err = ldap_set_option( lc->lc_ld, LDAP_OPT_X_SASL_SECPROPS,
640 (void *) sasl_secprops );
642 if ( rs->sr_err != LDAP_OPT_SUCCESS ) {
643 send_ldap_result( op, rs );
650 defaults = lutil_sasl_defaults( lc->lc_ld,
651 li->idassert_sasl_mech.bv_val,
652 li->idassert_sasl_realm.bv_val,
653 li->idassert_authcID.bv_val,
654 li->idassert_passwd.bv_val,
657 rs->sr_err = ldap_sasl_interactive_bind_s( lc->lc_ld, binddn.bv_val,
658 li->idassert_sasl_mech.bv_val, NULL, NULL,
659 li->idassert_sasl_flags, lutil_sasl_interact,
662 lutil_sasl_freedefs( defaults );
664 slap_sl_free( authzID.bv_val, op->o_tmpmemctx );
667 rs->sr_err = slap_map_api2result( rs );
668 if ( rs->sr_err != LDAP_SUCCESS ) {
670 send_ldap_result( op, rs );
676 #endif /* HAVE_CYRUS_SASL */
679 switch ( li->idassert_authmethod ) {
680 case LDAP_AUTH_SIMPLE:
681 rs->sr_err = ldap_sasl_bind( lc->lc_ld,
682 binddn.bv_val, LDAP_SASL_SIMPLE,
683 &bindcred, NULL, NULL, &msgid );
693 rs->sr_err = LDAP_AUTH_METHOD_NOT_SUPPORTED;
694 send_ldap_result( op, rs );
698 rc = ldap_back_op_result( lc, op, rs, msgid, 0 );
699 if ( rc == LDAP_SUCCESS ) {
707 * ldap_back_proxy_authz_ctrl() prepends a proxyAuthz control
708 * to existing server-side controls if required; if not,
709 * the existing server-side controls are placed in *pctrls.
710 * The caller, after using the controls in client API
711 * operations, if ( *pctrls != op->o_ctrls ), should
712 * free( (*pctrls)[ 0 ] ) and free( *pctrls ).
713 * The function returns success if the control could
714 * be added if required, or if it did nothing; in the future,
715 * it might return some error if it failed.
717 * if no bind took place yet, but the connection is bound
718 * and the "proxyauthzdn" is set, then bind as "proxyauthzdn"
719 * and explicitly add proxyAuthz the control to every operation
720 * with the dn bound to the connection as control value.
722 * If no server-side controls are defined for the operation,
723 * simply add the proxyAuthz control; otherwise, if the
724 * proxyAuthz control is not already set, add it as
725 * the first one (FIXME: is controls order significant
729 ldap_back_proxy_authz_ctrl(
733 LDAPControl ***pctrls )
735 struct ldapinfo *li = (struct ldapinfo *) op->o_bd->be_private;
736 LDAPControl **ctrls = NULL;
739 struct berval assertedID;
743 rs->sr_err = LDAP_SUCCESS;
745 if ( ( BER_BVISNULL( &li->idassert_authcID ) || BER_BVISEMPTY( &li->idassert_authcID ) )
746 && ( BER_BVISNULL( &li->idassert_authcDN ) || BER_BVISEMPTY( &li->idassert_authcDN ) ) ) {
754 if ( li->idassert_mode == LDAP_BACK_IDASSERT_LEGACY ) {
755 if ( op->o_proxy_authz ) {
757 * FIXME: we do not want to perform proxyAuthz
758 * on behalf of the client, because this would
759 * be performed with "proxyauthzdn" privileges.
761 * This might actually be too strict, since
762 * the "proxyauthzdn" authzTo, and each entry's
763 * authzFrom attributes may be crafted
764 * to avoid unwanted proxyAuthz to take place.
767 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
768 rs->sr_text = "proxyAuthz not allowed within namingContext";
773 if ( !BER_BVISNULL( &lc->lc_bound_ndn ) ) {
777 if ( BER_BVISNULL( &op->o_conn->c_ndn ) ) {
781 if ( BER_BVISNULL( &li->idassert_authcDN ) ) {
785 } else if ( li->idassert_authmethod == LDAP_AUTH_SASL ) {
786 if ( ( li->idassert_flags & LDAP_BACK_AUTH_NATIVE_AUTHZ )
787 /* && ( !BER_BVISNULL( &op->o_conn->c_ndn ) || lc->lc_bound ) */ )
789 /* already asserted in SASL via native authz */
790 /* NOTE: the test on lc->lc_bound is used to trap
791 * native authorization of anonymous users,
792 * since in that case op->o_conn->c_ndn is NULL */
796 } else if ( li->idassert_authz ) {
798 struct berval authcDN;
800 if ( BER_BVISNULL( &op->o_conn->c_ndn ) ) {
801 authcDN = slap_empty_bv;
803 authcDN = op->o_conn->c_ndn;
805 rc = slap_sasl_matches( op, li->idassert_authz,
806 &authcDN, & authcDN );
807 if ( rc != LDAP_SUCCESS ) {
808 /* op->o_conn->c_ndn is not authorized
814 if ( op->o_proxy_authz ) {
817 * 1) ignore the already set proxyAuthz control
818 * 2) leave it in place, and don't set ours
820 * 4) reject the operation
822 * option (4) is very drastic
823 * option (3) will make the remote server reject
824 * the operation, thus being equivalent to (4)
825 * option (2) will likely break the idassert
826 * assumptions, so we cannot accept it;
827 * option (1) means that we are contradicting
828 * the client's reques.
830 * I think (4) is the only correct choice.
832 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
833 rs->sr_text = "proxyAuthz not allowed within namingContext";
836 if ( op->o_do_not_cache && op->o_is_auth_check ) {
837 mode = LDAP_BACK_IDASSERT_NOASSERT;
840 mode = li->idassert_mode;
844 case LDAP_BACK_IDASSERT_LEGACY:
845 case LDAP_BACK_IDASSERT_SELF:
846 /* original behavior:
847 * assert the client's identity */
848 if ( BER_BVISNULL( &op->o_conn->c_ndn ) ) {
849 assertedID = slap_empty_bv;
851 assertedID = op->o_conn->c_ndn;
855 case LDAP_BACK_IDASSERT_ANONYMOUS:
856 /* assert "anonymous" */
857 assertedID = slap_empty_bv;
860 case LDAP_BACK_IDASSERT_NOASSERT:
861 /* don't assert; bind as proxyauthzdn */
864 case LDAP_BACK_IDASSERT_OTHERID:
865 case LDAP_BACK_IDASSERT_OTHERDN:
866 /* assert idassert DN */
867 assertedID = li->idassert_authzID;
874 if ( BER_BVISNULL( &assertedID ) ) {
875 assertedID = slap_empty_bv;
879 for ( i = 0; op->o_ctrls[ i ]; i++ )
880 /* just count ctrls */ ;
883 ctrls = ch_malloc( sizeof( LDAPControl * ) * (i + 2) );
884 ctrls[ 0 ] = ch_malloc( sizeof( LDAPControl ) );
886 ctrls[ 0 ]->ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
887 ctrls[ 0 ]->ldctl_iscritical = 1;
889 switch ( li->idassert_mode ) {
890 /* already in u:ID or dn:DN form */
891 case LDAP_BACK_IDASSERT_OTHERID:
892 case LDAP_BACK_IDASSERT_OTHERDN:
893 ber_dupbv( &ctrls[ 0 ]->ldctl_value, &assertedID );
896 /* needs the dn: prefix */
898 ctrls[ 0 ]->ldctl_value.bv_len = assertedID.bv_len + STRLENOF( "dn:" );
899 ctrls[ 0 ]->ldctl_value.bv_val = ch_malloc( ctrls[ 0 ]->ldctl_value.bv_len + 1 );
900 AC_MEMCPY( ctrls[ 0 ]->ldctl_value.bv_val, "dn:", STRLENOF( "dn:" ) );
901 AC_MEMCPY( ctrls[ 0 ]->ldctl_value.bv_val + STRLENOF( "dn:" ),
902 assertedID.bv_val, assertedID.bv_len + 1 );
907 for ( i = 0; op->o_ctrls[ i ]; i++ ) {
908 ctrls[ i + 1 ] = op->o_ctrls[ i ];
911 ctrls[ i + 1 ] = NULL;
914 if ( ctrls == NULL ) {
924 ldap_back_proxy_authz_ctrl_free( Operation *op, LDAPControl ***pctrls )
926 LDAPControl **ctrls = *pctrls;
928 /* we assume that the first control is the proxyAuthz
929 * added by back-ldap, so it's the only one we explicitly
931 if ( ctrls && ctrls != op->o_ctrls ) {
932 assert( ctrls[ 0 ] );
934 if ( !BER_BVISNULL( &ctrls[ 0 ]->ldctl_value ) ) {
935 free( ctrls[ 0 ]->ldctl_value.bv_val );