1 /* bind.c - ldap backend bind function */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1999-2004 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 #ifdef 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 ) ) {
431 /* if result parsing fails, note the failure reason */
432 if ( ldap_result( lc->lc_ld, msgid, 1, NULL, &res ) == -1 ) {
433 ldap_get_option( lc->lc_ld, LDAP_OPT_ERROR_NUMBER,
436 /* otherwise get the result; if it is not
437 * LDAP_SUCCESS, record it in the reply
438 * structure (this includes
439 * LDAP_COMPARE_{TRUE|FALSE}) */
441 int rc = ldap_parse_result( lc->lc_ld, res, &rs->sr_err,
442 &match, &text, NULL, NULL, 1 );
444 if ( rc != LDAP_SUCCESS ) {
450 /* if the error in the reply structure is not
451 * LDAP_SUCCESS, try to map it from client
453 if ( !ERR_OK( rs->sr_err ) ) {
454 rs->sr_err = slap_map_api2result( rs );
456 /* internal ops ( op->o_conn == NULL )
457 * must not reply to client */
458 if ( op->o_conn && !op->o_do_not_cache && match ) {
460 /* record the (massaged) matched
461 * DN into the reply structure */
462 rs->sr_matched = match;
465 if ( op->o_conn && ( sendok || rs->sr_err != LDAP_SUCCESS ) ) {
466 send_ldap_result( op, rs );
469 if ( rs->sr_matched != match ) {
470 free( (char *)rs->sr_matched );
472 rs->sr_matched = NULL;
473 ldap_memfree( match );
476 ldap_memfree( text );
479 return( ERR_OK( rs->sr_err ) ? 0 : -1 );
482 /* return true if bound, false if failed */
484 ldap_back_retry( struct ldapconn *lc, Operation *op, SlapReply *rs )
486 struct ldapinfo *li = (struct ldapinfo *)op->o_bd->be_private;
487 int vers = op->o_protocol;
490 ldap_pvt_thread_mutex_lock( &lc->lc_mutex );
491 ldap_unbind_ext_s( lc->lc_ld, NULL, NULL );
493 rs->sr_err = ldap_initialize( &ld, li->url );
495 if ( rs->sr_err != LDAP_SUCCESS ) {
496 rs->sr_err = slap_map_api2result( rs );
497 if ( rs->sr_text == NULL ) {
498 rs->sr_text = "ldap_initialize() failed";
501 send_ldap_result( op, rs );
506 /* Set LDAP version. This will always succeed: If the client
507 * bound with a particular version, then so can we.
509 ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, (const void *)&vers );
510 /* FIXME: configurable? */
511 ldap_set_option( ld, LDAP_OPT_REFERRALS, LDAP_OPT_ON );
513 ldap_pvt_thread_mutex_unlock( &lc->lc_mutex );
514 return ldap_back_dobind( lc, op, rs );
517 #ifdef LDAP_BACK_PROXY_AUTHZ
519 ldap_back_proxy_authz_bind( struct ldapconn *lc, Operation *op, SlapReply *rs )
521 struct ldapinfo *li = (struct ldapinfo *)op->o_bd->be_private;
522 struct berval binddn = slap_empty_bv;
523 struct berval bindcred = slap_empty_bv;
529 * FIXME: we need to let clients use proxyAuthz
530 * otherwise we cannot do symmetric pools of servers;
531 * we have to live with the fact that a user can
532 * authorize itself as any ID that is allowed
533 * by the authzTo directive of the "proxyauthzdn".
536 * NOTE: current Proxy Authorization specification
537 * and implementation do not allow proxy authorization
538 * control to be provided with Bind requests
541 * if no bind took place yet, but the connection is bound
542 * and the "proxyauthzdn" is set, then bind as
543 * "proxyauthzdn" and explicitly add the proxyAuthz
544 * control to every operation with the dn bound
545 * to the connection as control value.
548 /* bind as proxyauthzdn only if no idassert mode
549 * is requested, or if the client's identity
551 switch ( li->idassert_mode ) {
552 case LDAP_BACK_IDASSERT_LEGACY:
553 if ( !BER_BVISNULL( &op->o_conn->c_ndn ) && !BER_BVISEMPTY( &op->o_conn->c_ndn ) ) {
554 if ( !BER_BVISNULL( &li->idassert_authcDN ) && !BER_BVISEMPTY( &li->idassert_authcDN ) )
556 binddn = li->idassert_authcDN;
557 bindcred = li->idassert_passwd;
564 if ( li->idassert_authz ) {
565 struct berval authcDN = BER_BVISNULL( &op->o_conn->c_ndn ) ? slap_empty_bv : op->o_conn->c_ndn;
567 rs->sr_err = slap_sasl_matches( op, li->idassert_authz,
568 &authcDN, &authcDN );
569 if ( rs->sr_err != LDAP_SUCCESS ) {
570 send_ldap_result( op, rs );
576 binddn = li->idassert_authcDN;
577 bindcred = li->idassert_passwd;
582 if ( dobind && li->idassert_authmethod == LDAP_AUTH_SASL ) {
583 #ifdef HAVE_CYRUS_SASL
584 void *defaults = NULL;
585 struct berval authzID = BER_BVNULL;
588 /* if SASL supports native authz, prepare for it */
589 if ( ( !op->o_do_not_cache || !op->o_is_auth_check ) &&
590 ( li->idassert_flags & LDAP_BACK_AUTH_NATIVE_AUTHZ ) )
592 switch ( li->idassert_mode ) {
593 case LDAP_BACK_IDASSERT_OTHERID:
594 case LDAP_BACK_IDASSERT_OTHERDN:
595 authzID = li->idassert_authzID;
598 case LDAP_BACK_IDASSERT_ANONYMOUS:
599 BER_BVSTR( &authzID, "dn:" );
602 case LDAP_BACK_IDASSERT_SELF:
603 if ( BER_BVISNULL( &op->o_conn->c_ndn ) ) {
604 /* connection is not authc'd, so don't idassert */
605 BER_BVSTR( &authzID, "dn:" );
608 authzID.bv_len = STRLENOF( "dn:" ) + op->o_conn->c_ndn.bv_len;
609 authzID.bv_val = slap_sl_malloc( authzID.bv_len + 1, op->o_tmpmemctx );
610 AC_MEMCPY( authzID.bv_val, "dn:", STRLENOF( "dn:" ) );
611 AC_MEMCPY( authzID.bv_val + STRLENOF( "dn:" ),
612 op->o_conn->c_ndn.bv_val, op->o_conn->c_ndn.bv_len + 1 );
621 #if 0 /* will deal with this later... */
622 if ( sasl_secprops != NULL ) {
623 rs->sr_err = ldap_set_option( lc->lc_ld, LDAP_OPT_X_SASL_SECPROPS,
624 (void *) sasl_secprops );
626 if ( rs->sr_err != LDAP_OPT_SUCCESS ) {
627 send_ldap_result( op, rs );
634 defaults = lutil_sasl_defaults( lc->lc_ld,
635 li->idassert_sasl_mech.bv_val,
636 li->idassert_sasl_realm.bv_val,
637 li->idassert_authcID.bv_val,
638 li->idassert_passwd.bv_val,
641 rs->sr_err = ldap_sasl_interactive_bind_s( lc->lc_ld, binddn.bv_val,
642 li->idassert_sasl_mech.bv_val, NULL, NULL,
643 li->idassert_sasl_flags, lutil_sasl_interact,
646 lutil_sasl_freedefs( defaults );
648 slap_sl_free( authzID.bv_val, op->o_tmpmemctx );
651 rs->sr_err = slap_map_api2result( rs );
652 if ( rs->sr_err != LDAP_SUCCESS ) {
654 send_ldap_result( op, rs );
660 #endif /* HAVE_CYRUS_SASL */
663 switch ( li->idassert_authmethod ) {
664 case LDAP_AUTH_SIMPLE:
665 rs->sr_err = ldap_sasl_bind( lc->lc_ld,
666 binddn.bv_val, LDAP_SASL_SIMPLE,
667 &bindcred, NULL, NULL, &msgid );
677 rs->sr_err = LDAP_AUTH_METHOD_NOT_SUPPORTED;
678 send_ldap_result( op, rs );
682 rc = ldap_back_op_result( lc, op, rs, msgid, 0 );
683 if ( rc == LDAP_SUCCESS ) {
691 * ldap_back_proxy_authz_ctrl() prepends a proxyAuthz control
692 * to existing server-side controls if required; if not,
693 * the existing server-side controls are placed in *pctrls.
694 * The caller, after using the controls in client API
695 * operations, if ( *pctrls != op->o_ctrls ), should
696 * free( (*pctrls)[ 0 ] ) and free( *pctrls ).
697 * The function returns success if the control could
698 * be added if required, or if it did nothing; in the future,
699 * it might return some error if it failed.
701 * if no bind took place yet, but the connection is bound
702 * and the "proxyauthzdn" is set, then bind as "proxyauthzdn"
703 * and explicitly add proxyAuthz the control to every operation
704 * with the dn bound to the connection as control value.
706 * If no server-side controls are defined for the operation,
707 * simply add the proxyAuthz control; otherwise, if the
708 * proxyAuthz control is not already set, add it as
709 * the first one (FIXME: is controls order significant
713 ldap_back_proxy_authz_ctrl(
717 LDAPControl ***pctrls )
719 struct ldapinfo *li = (struct ldapinfo *) op->o_bd->be_private;
720 LDAPControl **ctrls = NULL;
723 struct berval assertedID;
727 if ( ( BER_BVISNULL( &li->idassert_authcID ) || BER_BVISEMPTY( &li->idassert_authcID ) )
728 && ( BER_BVISNULL( &li->idassert_authcDN ) || BER_BVISEMPTY( &li->idassert_authcDN ) ) ) {
736 if ( li->idassert_mode == LDAP_BACK_IDASSERT_LEGACY ) {
737 if ( op->o_proxy_authz ) {
739 * FIXME: we do not want to perform proxyAuthz
740 * on behalf of the client, because this would
741 * be performed with "proxyauthzdn" privileges.
743 * This might actually be too strict, since
744 * the "proxyauthzdn" authzTo, and each entry's
745 * authzFrom attributes may be crafted
746 * to avoid unwanted proxyAuthz to take place.
749 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
750 rs->sr_text = "proxyAuthz not allowed within namingContext";
755 if ( !BER_BVISNULL( &lc->lc_bound_ndn ) ) {
759 if ( BER_BVISNULL( &op->o_conn->c_ndn ) ) {
763 if ( BER_BVISNULL( &li->idassert_authcDN ) ) {
767 } else if ( li->idassert_authmethod == LDAP_AUTH_SASL ) {
768 if ( ( li->idassert_flags & LDAP_BACK_AUTH_NATIVE_AUTHZ )
769 /* && ( !BER_BVISNULL( &op->o_conn->c_ndn ) || lc->lc_bound ) */ )
771 /* already asserted in SASL via native authz */
772 /* NOTE: the test on lc->lc_bound is used to trap
773 * native authorization of anonymous users,
774 * since in that case op->o_conn->c_ndn is NULL */
778 } else if ( li->idassert_authz ) {
780 struct berval authcDN = BER_BVISNULL( &op->o_conn->c_ndn ) ? slap_empty_bv : op->o_conn->c_ndn;
783 rc = slap_sasl_matches( op, li->idassert_authz,
784 &authcDN, & authcDN );
785 if ( rc != LDAP_SUCCESS ) {
786 /* op->o_conn->c_ndn is not authorized
792 if ( op->o_proxy_authz ) {
795 * 1) ignore the already set proxyAuthz control
796 * 2) leave it in place, and don't set ours
798 * 4) reject the operation
800 * option (4) is very drastic
801 * option (3) will make the remote server reject
802 * the operation, thus being equivalent to (4)
803 * option (2) will likely break the idassert
804 * assumptions, so we cannot accept it;
805 * option (1) means that we are contradicting
806 * the client's reques.
808 * I think (4) is the only correct choice.
810 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
811 rs->sr_text = "proxyAuthz not allowed within namingContext";
814 if ( op->o_do_not_cache && op->o_is_auth_check ) {
815 mode = LDAP_BACK_IDASSERT_NOASSERT;
818 mode = li->idassert_mode;
822 case LDAP_BACK_IDASSERT_LEGACY:
823 case LDAP_BACK_IDASSERT_SELF:
824 /* original behavior:
825 * assert the client's identity */
826 assertedID = BER_BVISNULL( &op->o_conn->c_ndn ) ? slap_empty_bv : op->o_conn->c_ndn;
829 case LDAP_BACK_IDASSERT_ANONYMOUS:
830 /* assert "anonymous" */
831 assertedID = slap_empty_bv;
834 case LDAP_BACK_IDASSERT_NOASSERT:
835 /* don't assert; bind as proxyauthzdn */
838 case LDAP_BACK_IDASSERT_OTHERID:
839 case LDAP_BACK_IDASSERT_OTHERDN:
840 /* assert idassert DN */
841 assertedID = li->idassert_authzID;
848 if ( BER_BVISNULL( &assertedID ) ) {
849 assertedID = slap_empty_bv;
853 for ( i = 0; op->o_ctrls[ i ]; i++ )
854 /* just count ctrls */ ;
857 ctrls = ch_malloc( sizeof( LDAPControl * ) * (i + 2) );
858 ctrls[ 0 ] = ch_malloc( sizeof( LDAPControl ) );
860 ctrls[ 0 ]->ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
861 ctrls[ 0 ]->ldctl_iscritical = 1;
863 switch ( li->idassert_mode ) {
864 /* already in u:ID or dn:DN form */
865 case LDAP_BACK_IDASSERT_OTHERID:
866 case LDAP_BACK_IDASSERT_OTHERDN:
867 ber_dupbv( &ctrls[ 0 ]->ldctl_value, &assertedID );
870 /* needs the dn: prefix */
872 ctrls[ 0 ]->ldctl_value.bv_len = assertedID.bv_len + STRLENOF( "dn:" );
873 ctrls[ 0 ]->ldctl_value.bv_val = ch_malloc( ctrls[ 0 ]->ldctl_value.bv_len + 1 );
874 AC_MEMCPY( ctrls[ 0 ]->ldctl_value.bv_val, "dn:", STRLENOF( "dn:" ) );
875 AC_MEMCPY( ctrls[ 0 ]->ldctl_value.bv_val + STRLENOF( "dn:" ),
876 assertedID.bv_val, assertedID.bv_len + 1 );
881 for ( i = 0; op->o_ctrls[ i ]; i++ ) {
882 ctrls[ i + 1 ] = op->o_ctrls[ i ];
885 ctrls[ i + 1 ] = NULL;
888 if ( ctrls == NULL ) {
898 ldap_back_proxy_authz_ctrl_free( Operation *op, LDAPControl ***pctrls )
900 LDAPControl **ctrls = *pctrls;
902 if ( ctrls && ctrls != op->o_ctrls ) {
903 assert( ctrls[ 0 ] );
905 if ( !BER_BVISNULL( &ctrls[ 0 ]->ldctl_value ) ) {
906 free( ctrls[ 0 ]->ldctl_value.bv_val );
917 #endif /* LDAP_BACK_PROXY_AUTHZ */