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;
41 #ifdef LDAP_BACK_PROXY_AUTHZ
43 ldap_back_proxy_authz_bind( struct ldapconn *lc, Operation *op, SlapReply *rs );
44 #endif /* LDAP_BACK_PROXY_AUTHZ */
47 ldap_back_bind( Operation *op, SlapReply *rs )
49 struct ldapinfo *li = (struct ldapinfo *) op->o_bd->be_private;
55 lc = ldap_back_getconn( op, rs );
60 if ( !BER_BVISNULL( &lc->lc_bound_ndn ) ) {
61 ch_free( lc->lc_bound_ndn.bv_val );
62 BER_BVZERO( &lc->lc_bound_ndn );
66 /* method is always LDAP_AUTH_SIMPLE if we got here */
67 rs->sr_err = ldap_sasl_bind( lc->lc_ld, op->o_req_dn.bv_val,
69 &op->orb_cred, op->o_ctrls, NULL, &msgid );
70 rc = ldap_back_op_result( lc, op, rs, msgid, 1 );
72 if ( rc == LDAP_SUCCESS ) {
73 #if defined(LDAP_BACK_PROXY_AUTHZ)
74 if ( li->idassert_flags & LDAP_BACK_AUTH_OVERRIDE ) {
75 ldap_back_proxy_authz_bind( lc, op, rs );
76 if ( lc->lc_bound == 0 ) {
81 #endif /* LDAP_BACK_PROXY_AUTHZ */
84 ber_dupbv( &lc->lc_bound_ndn, &op->o_req_ndn );
87 if ( !BER_BVISNULL( &lc->lc_cred ) ) {
88 memset( lc->lc_cred.bv_val, 0,
90 ch_free( lc->lc_cred.bv_val );
92 ber_dupbv( &lc->lc_cred, &op->orb_cred );
93 ldap_set_rebind_proc( lc->lc_ld, ldap_back_rebind, lc );
98 /* must re-insert if local DN changed as result of bind */
99 if ( lc->lc_bound && !dn_match( &op->o_req_ndn, &lc->lc_local_ndn ) ) {
102 ldap_pvt_thread_mutex_lock( &li->conn_mutex );
103 lc = avl_delete( &li->conntree, (caddr_t)lc,
104 ldap_back_conn_cmp );
105 if ( !BER_BVISNULL( &lc->lc_local_ndn ) ) {
106 ch_free( lc->lc_local_ndn.bv_val );
108 ber_dupbv( &lc->lc_local_ndn, &op->o_req_ndn );
109 lerr = avl_insert( &li->conntree, (caddr_t)lc,
110 ldap_back_conn_cmp, ldap_back_conn_dup );
111 ldap_pvt_thread_mutex_unlock( &li->conn_mutex );
113 ldap_back_conn_free( lc );
123 * compares two struct ldapconn based on the value of the conn pointer;
127 ldap_back_conn_cmp( const void *c1, const void *c2 )
129 const struct ldapconn *lc1 = (const struct ldapconn *)c1;
130 const struct ldapconn *lc2 = (const struct ldapconn *)c2;
133 /* If local DNs don't match, it is definitely not a match */
134 rc = ber_bvcmp( &lc1->lc_local_ndn, &lc2->lc_local_ndn );
139 /* For shared sessions, conn is NULL. Only explicitly
140 * bound sessions will have non-NULL conn.
142 return SLAP_PTRCMP( lc1->lc_conn, lc2->lc_conn );
148 * returns -1 in case a duplicate struct ldapconn has been inserted;
152 ldap_back_conn_dup( void *c1, void *c2 )
154 struct ldapconn *lc1 = (struct ldapconn *)c1;
155 struct ldapconn *lc2 = (struct ldapconn *)c2;
157 /* Cannot have more than one shared session with same DN */
158 if ( dn_match( &lc1->lc_local_ndn, &lc2->lc_local_ndn ) &&
159 lc1->lc_conn == lc2->lc_conn )
167 #if PRINT_CONNTREE > 0
169 ravl_print( Avlnode *root, int depth )
178 ravl_print( root->avl_right, depth+1 );
180 for ( i = 0; i < depth; i++ ) {
185 printf( "lc(%lx) local(%s) conn(%lx) %d\n",
186 lc, lc->lc_local_ndn.bv_val, lc->lc_conn, root->avl_bf );
188 ravl_print( root->avl_left, depth+1 );
192 myprint( Avlnode *root )
194 printf( "********\n" );
197 printf( "\tNULL\n" );
200 ravl_print( root, 0 );
203 printf( "********\n" );
205 #endif /* PRINT_CONNTREE */
208 ldap_back_freeconn( Operation *op, struct ldapconn *lc )
210 struct ldapinfo *li = (struct ldapinfo *) op->o_bd->be_private;
212 ldap_pvt_thread_mutex_lock( &li->conn_mutex );
213 lc = avl_delete( &li->conntree, (caddr_t)lc,
214 ldap_back_conn_cmp );
215 ldap_back_conn_free( (void *)lc );
216 ldap_pvt_thread_mutex_unlock( &li->conn_mutex );
222 ldap_back_getconn( Operation *op, SlapReply *rs )
224 struct ldapinfo *li = (struct ldapinfo *)op->o_bd->be_private;
225 struct ldapconn *lc, lc_curr;
229 /* Searches for a ldapconn in the avl tree */
231 /* Explicit binds must not be shared */
232 if ( op->o_tag == LDAP_REQ_BIND
234 && op->o_conn->c_authz_backend
235 && op->o_bd->be_private == op->o_conn->c_authz_backend->be_private ) )
237 lc_curr.lc_conn = op->o_conn;
240 lc_curr.lc_conn = NULL;
243 /* Internal searches are privileged and shared. So is root. */
244 if ( op->o_do_not_cache || be_isroot( op ) ) {
245 lc_curr.lc_local_ndn = op->o_bd->be_rootndn;
246 lc_curr.lc_conn = NULL;
250 lc_curr.lc_local_ndn = op->o_ndn;
253 ldap_pvt_thread_mutex_lock( &li->conn_mutex );
254 lc = (struct ldapconn *)avl_find( li->conntree,
255 (caddr_t)&lc_curr, ldap_back_conn_cmp );
256 ldap_pvt_thread_mutex_unlock( &li->conn_mutex );
258 /* Looks like we didn't get a bind. Open a new session... */
260 int vers = op->o_protocol;
261 rs->sr_err = ldap_initialize( &ld, li->url );
263 if ( rs->sr_err != LDAP_SUCCESS ) {
264 rs->sr_err = slap_map_api2result( rs );
265 if ( rs->sr_text == NULL ) {
266 rs->sr_text = "ldap_initialize() failed";
269 send_ldap_result( op, rs );
274 /* Set LDAP version. This will always succeed: If the client
275 * bound with a particular version, then so can we.
277 ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION,
278 (const void *)&vers );
279 /* FIXME: configurable? */
280 ldap_set_option( ld, LDAP_OPT_REFERRALS, LDAP_OPT_ON );
282 lc = (struct ldapconn *)ch_malloc( sizeof( struct ldapconn ) );
283 lc->lc_conn = lc_curr.lc_conn;
285 ber_dupbv( &lc->lc_local_ndn, &lc_curr.lc_local_ndn );
287 ldap_pvt_thread_mutex_init( &lc->lc_mutex );
290 ber_dupbv( &lc->lc_cred, &li->acl_passwd );
291 ber_dupbv( &lc->lc_bound_ndn, &li->acl_authcDN );
294 BER_BVZERO( &lc->lc_cred );
295 BER_BVZERO( &lc->lc_bound_ndn );
296 if ( op->o_conn && !BER_BVISEMPTY( &op->o_ndn )
297 && op->o_bd == op->o_conn->c_authz_backend )
299 ber_dupbv( &lc->lc_bound_ndn, &op->o_ndn );
305 /* Inserts the newly created ldapconn in the avl tree */
306 ldap_pvt_thread_mutex_lock( &li->conn_mutex );
307 rs->sr_err = avl_insert( &li->conntree, (caddr_t)lc,
308 ldap_back_conn_cmp, ldap_back_conn_dup );
310 #if PRINT_CONNTREE > 0
311 myprint( li->conntree );
312 #endif /* PRINT_CONNTREE */
314 ldap_pvt_thread_mutex_unlock( &li->conn_mutex );
316 Debug( LDAP_DEBUG_TRACE,
317 "=>ldap_back_getconn: conn %p inserted\n", (void *) lc, 0, 0 );
319 /* Err could be -1 in case a duplicate ldapconn is inserted */
320 if ( rs->sr_err != 0 ) {
321 ldap_back_conn_free( lc );
323 send_ldap_error( op, rs, LDAP_OTHER,
324 "internal server error" );
329 Debug( LDAP_DEBUG_TRACE,
330 "=>ldap_back_getconn: conn %p fetched\n", (void *) lc, 0, 0 );
339 * Note: as the check for the value of lc->lc_bound was already here, I removed
340 * it from all the callers, and I made the function return the flag, so
341 * it can be used to simplify the check.
344 ldap_back_dobind( struct ldapconn *lc, Operation *op, SlapReply *rs )
349 ldap_pvt_thread_mutex_lock( &lc->lc_mutex );
350 if ( !lc->lc_bound ) {
351 #ifdef LDAP_BACK_PROXY_AUTHZ
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 "proxyauthzdn" is set, then bind as
367 * "proxyauthzdn" and explicitly add the proxyAuthz
368 * control to every operation with the dn bound
369 * 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 );
375 #endif /* LDAP_BACK_PROXY_AUTHZ */
377 rs->sr_err = ldap_sasl_bind( lc->lc_ld,
378 lc->lc_bound_ndn.bv_val,
379 LDAP_SASL_SIMPLE, &lc->lc_cred,
380 NULL, NULL, &msgid );
382 rc = ldap_back_op_result( lc, op, rs, msgid, 0 );
383 if ( rc == LDAP_SUCCESS ) {
390 ldap_pvt_thread_mutex_unlock( &lc->lc_mutex );
397 * This is a callback used for chasing referrals using the same
398 * credentials as the original user on this session.
401 ldap_back_rebind( LDAP *ld, LDAP_CONST char *url, ber_tag_t request,
402 ber_int_t msgid, void *params )
404 struct ldapconn *lc = params;
406 return ldap_sasl_bind_s( ld, lc->lc_bound_ndn.bv_val,
407 LDAP_SASL_SIMPLE, &lc->lc_cred, NULL, NULL, NULL );
419 LDAPMessage *res = NULL;
422 #define ERR_OK(err) ((err) == LDAP_SUCCESS || (err) == LDAP_COMPARE_FALSE || (err) == LDAP_COMPARE_TRUE)
425 rs->sr_matched = NULL;
427 /* if the error recorded in the reply corresponds
428 * to a successful state, get the error from the
429 * remote server response */
430 if ( ERR_OK( rs->sr_err ) ) {
432 struct timeval tv = { 0, 0 };
435 /* if result parsing fails, note the failure reason */
436 switch ( ldap_result( lc->lc_ld, msgid, 1, &tv, &res ) ) {
439 tv.tv_usec = 100000; /* 0.1 s */
440 ldap_pvt_thread_yield();
444 ldap_get_option( lc->lc_ld, LDAP_OPT_ERROR_NUMBER,
449 /* otherwise get the result; if it is not
450 * LDAP_SUCCESS, record it in the reply
451 * structure (this includes
452 * LDAP_COMPARE_{TRUE|FALSE}) */
454 rc = ldap_parse_result( lc->lc_ld, res, &rs->sr_err,
455 &match, &text, NULL, NULL, 1 );
457 if ( rc != LDAP_SUCCESS ) {
463 /* if the error in the reply structure is not
464 * LDAP_SUCCESS, try to map it from client
466 if ( !ERR_OK( rs->sr_err ) ) {
467 rs->sr_err = slap_map_api2result( rs );
469 /* internal ops ( op->o_conn == NULL )
470 * must not reply to client */
471 if ( op->o_conn && !op->o_do_not_cache && match ) {
473 /* record the (massaged) matched
474 * DN into the reply structure */
475 rs->sr_matched = match;
478 if ( op->o_conn && ( sendok || rs->sr_err != LDAP_SUCCESS ) ) {
479 send_ldap_result( op, rs );
482 if ( rs->sr_matched != match ) {
483 free( (char *)rs->sr_matched );
485 rs->sr_matched = NULL;
486 ldap_memfree( match );
489 ldap_memfree( text );
492 return( ERR_OK( rs->sr_err ) ? 0 : -1 );
495 /* return true if bound, false if failed */
497 ldap_back_retry( struct ldapconn *lc, Operation *op, SlapReply *rs )
499 struct ldapinfo *li = (struct ldapinfo *)op->o_bd->be_private;
500 int vers = op->o_protocol;
503 ldap_pvt_thread_mutex_lock( &lc->lc_mutex );
504 ldap_unbind_ext_s( lc->lc_ld, NULL, NULL );
506 rs->sr_err = ldap_initialize( &ld, li->url );
508 if ( rs->sr_err != LDAP_SUCCESS ) {
509 rs->sr_err = slap_map_api2result( rs );
510 if ( rs->sr_text == NULL ) {
511 rs->sr_text = "ldap_initialize() failed";
514 send_ldap_result( op, rs );
519 /* Set LDAP version. This will always succeed: If the client
520 * bound with a particular version, then so can we.
522 ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, (const void *)&vers );
523 /* FIXME: configurable? */
524 ldap_set_option( ld, LDAP_OPT_REFERRALS, LDAP_OPT_ON );
526 ldap_pvt_thread_mutex_unlock( &lc->lc_mutex );
527 return ldap_back_dobind( lc, op, rs );
530 #ifdef LDAP_BACK_PROXY_AUTHZ
532 ldap_back_proxy_authz_bind( struct ldapconn *lc, Operation *op, SlapReply *rs )
534 struct ldapinfo *li = (struct ldapinfo *)op->o_bd->be_private;
535 struct berval binddn = slap_empty_bv;
536 struct berval bindcred = slap_empty_bv;
542 * FIXME: we need to let clients use proxyAuthz
543 * otherwise we cannot do symmetric pools of servers;
544 * we have to live with the fact that a user can
545 * authorize itself as any ID that is allowed
546 * by the authzTo directive of the "proxyauthzdn".
549 * NOTE: current Proxy Authorization specification
550 * and implementation do not allow proxy authorization
551 * control to be provided with Bind requests
554 * if no bind took place yet, but the connection is bound
555 * and the "proxyauthzdn" is set, then bind as
556 * "proxyauthzdn" and explicitly add the proxyAuthz
557 * control to every operation with the dn bound
558 * to the connection as control value.
561 /* bind as proxyauthzdn only if no idassert mode
562 * is requested, or if the client's identity
564 switch ( li->idassert_mode ) {
565 case LDAP_BACK_IDASSERT_LEGACY:
566 if ( !BER_BVISNULL( &op->o_conn->c_ndn ) && !BER_BVISEMPTY( &op->o_conn->c_ndn ) ) {
567 if ( !BER_BVISNULL( &li->idassert_authcDN ) && !BER_BVISEMPTY( &li->idassert_authcDN ) )
569 binddn = li->idassert_authcDN;
570 bindcred = li->idassert_passwd;
577 if ( li->idassert_authz ) {
578 struct berval authcDN;
580 if ( BER_BVISNULL( &op->o_conn->c_ndn ) ) {
581 authcDN = slap_empty_bv;
583 authcDN = op->o_conn->c_ndn;
585 rs->sr_err = slap_sasl_matches( op, li->idassert_authz,
586 &authcDN, &authcDN );
587 if ( rs->sr_err != LDAP_SUCCESS ) {
588 send_ldap_result( op, rs );
594 binddn = li->idassert_authcDN;
595 bindcred = li->idassert_passwd;
600 if ( dobind && li->idassert_authmethod == LDAP_AUTH_SASL ) {
601 #ifdef HAVE_CYRUS_SASL
602 void *defaults = NULL;
603 struct berval authzID = BER_BVNULL;
606 /* if SASL supports native authz, prepare for it */
607 if ( ( !op->o_do_not_cache || !op->o_is_auth_check ) &&
608 ( li->idassert_flags & LDAP_BACK_AUTH_NATIVE_AUTHZ ) )
610 switch ( li->idassert_mode ) {
611 case LDAP_BACK_IDASSERT_OTHERID:
612 case LDAP_BACK_IDASSERT_OTHERDN:
613 authzID = li->idassert_authzID;
616 case LDAP_BACK_IDASSERT_ANONYMOUS:
617 BER_BVSTR( &authzID, "dn:" );
620 case LDAP_BACK_IDASSERT_SELF:
621 if ( BER_BVISNULL( &op->o_conn->c_ndn ) ) {
622 /* connection is not authc'd, so don't idassert */
623 BER_BVSTR( &authzID, "dn:" );
626 authzID.bv_len = STRLENOF( "dn:" ) + op->o_conn->c_ndn.bv_len;
627 authzID.bv_val = slap_sl_malloc( authzID.bv_len + 1, op->o_tmpmemctx );
628 AC_MEMCPY( authzID.bv_val, "dn:", STRLENOF( "dn:" ) );
629 AC_MEMCPY( authzID.bv_val + STRLENOF( "dn:" ),
630 op->o_conn->c_ndn.bv_val, op->o_conn->c_ndn.bv_len + 1 );
639 #if 0 /* will deal with this later... */
640 if ( sasl_secprops != NULL ) {
641 rs->sr_err = ldap_set_option( lc->lc_ld, LDAP_OPT_X_SASL_SECPROPS,
642 (void *) sasl_secprops );
644 if ( rs->sr_err != LDAP_OPT_SUCCESS ) {
645 send_ldap_result( op, rs );
652 defaults = lutil_sasl_defaults( lc->lc_ld,
653 li->idassert_sasl_mech.bv_val,
654 li->idassert_sasl_realm.bv_val,
655 li->idassert_authcID.bv_val,
656 li->idassert_passwd.bv_val,
659 rs->sr_err = ldap_sasl_interactive_bind_s( lc->lc_ld, binddn.bv_val,
660 li->idassert_sasl_mech.bv_val, NULL, NULL,
661 li->idassert_sasl_flags, lutil_sasl_interact,
664 lutil_sasl_freedefs( defaults );
666 slap_sl_free( authzID.bv_val, op->o_tmpmemctx );
669 rs->sr_err = slap_map_api2result( rs );
670 if ( rs->sr_err != LDAP_SUCCESS ) {
672 send_ldap_result( op, rs );
678 #endif /* HAVE_CYRUS_SASL */
681 switch ( li->idassert_authmethod ) {
682 case LDAP_AUTH_SIMPLE:
683 rs->sr_err = ldap_sasl_bind( lc->lc_ld,
684 binddn.bv_val, LDAP_SASL_SIMPLE,
685 &bindcred, NULL, NULL, &msgid );
695 rs->sr_err = LDAP_AUTH_METHOD_NOT_SUPPORTED;
696 send_ldap_result( op, rs );
700 rc = ldap_back_op_result( lc, op, rs, msgid, 0 );
701 if ( rc == LDAP_SUCCESS ) {
709 * ldap_back_proxy_authz_ctrl() prepends a proxyAuthz control
710 * to existing server-side controls if required; if not,
711 * the existing server-side controls are placed in *pctrls.
712 * The caller, after using the controls in client API
713 * operations, if ( *pctrls != op->o_ctrls ), should
714 * free( (*pctrls)[ 0 ] ) and free( *pctrls ).
715 * The function returns success if the control could
716 * be added if required, or if it did nothing; in the future,
717 * it might return some error if it failed.
719 * if no bind took place yet, but the connection is bound
720 * and the "proxyauthzdn" is set, then bind as "proxyauthzdn"
721 * and explicitly add proxyAuthz the control to every operation
722 * with the dn bound to the connection as control value.
724 * If no server-side controls are defined for the operation,
725 * simply add the proxyAuthz control; otherwise, if the
726 * proxyAuthz control is not already set, add it as
727 * the first one (FIXME: is controls order significant
731 ldap_back_proxy_authz_ctrl(
735 LDAPControl ***pctrls )
737 struct ldapinfo *li = (struct ldapinfo *) op->o_bd->be_private;
738 LDAPControl **ctrls = NULL;
741 struct berval assertedID;
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 if ( ctrls && ctrls != op->o_ctrls ) {
929 assert( ctrls[ 0 ] );
931 if ( !BER_BVISNULL( &ctrls[ 0 ]->ldctl_value ) ) {
932 free( ctrls[ 0 ]->ldctl_value.bv_val );
943 #endif /* LDAP_BACK_PROXY_AUTHZ */