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;
46 struct ldapinfo *li = (struct ldapinfo *) op->o_bd->be_private;
49 struct berval mdn = BER_BVNULL;
54 lc = ldap_back_getconn(op, rs);
60 * Rewrite the bind dn if needed
62 dc.rwmap = &li->rwmap;
71 if ( ldap_back_dn_massage( &dc, &op->o_req_dn, &mdn ) ) {
72 send_ldap_result( op, rs );
76 if ( !BER_BVISNULL( &lc->bound_dn ) ) {
77 ch_free( lc->bound_dn.bv_val );
78 BER_BVZERO( &lc->bound_dn );
81 /* method is always LDAP_AUTH_SIMPLE if we got here */
82 rs->sr_err = ldap_sasl_bind(lc->ld, mdn.bv_val, LDAP_SASL_SIMPLE,
83 &op->oq_bind.rb_cred, op->o_ctrls, NULL, &msgid);
84 rc = ldap_back_op_result( lc, op, rs, msgid, 1 );
85 if (rc == LDAP_SUCCESS) {
87 if ( mdn.bv_val != op->o_req_dn.bv_val ) {
90 ber_dupbv( &lc->bound_dn, &op->o_req_dn );
95 if ( !BER_BVISNULL( &lc->cred ) ) {
96 memset( lc->cred.bv_val, 0, lc->cred.bv_len );
97 ch_free( lc->cred.bv_val );
99 ber_dupbv( &lc->cred, &op->oq_bind.rb_cred );
100 ldap_set_rebind_proc( lc->ld, ldap_back_rebind, lc );
104 /* must re-insert if local DN changed as result of bind */
105 if ( lc->bound && !bvmatch(&op->o_req_ndn, &lc->local_dn ) ) {
108 ldap_pvt_thread_mutex_lock( &li->conn_mutex );
109 lc = avl_delete( &li->conntree, (caddr_t)lc,
110 ldap_back_conn_cmp );
111 if ( !BER_BVISNULL( &lc->local_dn ) )
112 ch_free( lc->local_dn.bv_val );
113 ber_dupbv( &lc->local_dn, &op->o_req_ndn );
114 lerr = avl_insert( &li->conntree, (caddr_t)lc,
115 ldap_back_conn_cmp, ldap_back_conn_dup );
116 ldap_pvt_thread_mutex_unlock( &li->conn_mutex );
118 ldap_back_conn_free( lc );
122 if ( !BER_BVISNULL( &mdn ) && mdn.bv_val != op->o_req_dn.bv_val ) {
132 * compares two struct ldapconn based on the value of the conn pointer;
141 const struct ldapconn *lc1 = (const struct ldapconn *)c1;
142 const struct ldapconn *lc2 = (const struct ldapconn *)c2;
145 /* If local DNs don't match, it is definitely not a match */
146 if ( ( rc = ber_bvcmp( &lc1->local_dn, &lc2->local_dn )) )
149 /* For shared sessions, conn is NULL. Only explicitly
150 * bound sessions will have non-NULL conn.
152 return SLAP_PTRCMP(lc1->conn, lc2->conn);
158 * returns -1 in case a duplicate struct ldapconn has been inserted;
167 struct ldapconn *lc1 = (struct ldapconn *)c1;
168 struct ldapconn *lc2 = (struct ldapconn *)c2;
170 /* Cannot have more than one shared session with same DN */
171 if ( dn_match( &lc1->local_dn, &lc2->local_dn ) &&
172 lc1->conn == lc2->conn ) return -1;
177 #if PRINT_CONNTREE > 0
178 static void ravl_print( Avlnode *root, int depth )
186 ravl_print( root->avl_right, depth+1 );
188 for ( i = 0; i < depth; i++ )
192 printf( "lc(%lx) local(%s) conn(%lx) %d\n",
193 lc, lc->local_dn.bv_val, lc->conn, root->avl_bf );
195 ravl_print( root->avl_left, depth+1 );
198 static void myprint( Avlnode *root )
200 printf( "********\n" );
203 printf( "\tNULL\n" );
206 ravl_print( root, 0 );
208 printf( "********\n" );
210 #endif /* PRINT_CONNTREE */
213 ldap_back_getconn(Operation *op, SlapReply *rs)
215 struct ldapinfo *li = (struct ldapinfo *)op->o_bd->be_private;
216 struct ldapconn *lc, lc_curr;
220 /* Searches for a ldapconn in the avl tree */
222 /* Explicit binds must not be shared */
223 if ( op->o_tag == LDAP_REQ_BIND
225 && (op->o_bd == op->o_conn->c_authz_backend ))) {
226 lc_curr.conn = op->o_conn;
232 /* Internal searches are privileged and shared. So is root. */
233 if ( op->o_do_not_cache || be_isroot( op ) ) {
234 lc_curr.local_dn = op->o_bd->be_rootndn;
239 lc_curr.local_dn = op->o_ndn;
242 ldap_pvt_thread_mutex_lock( &li->conn_mutex );
243 lc = (struct ldapconn *)avl_find( li->conntree,
244 (caddr_t)&lc_curr, ldap_back_conn_cmp );
245 ldap_pvt_thread_mutex_unlock( &li->conn_mutex );
247 /* Looks like we didn't get a bind. Open a new session... */
249 int vers = op->o_protocol;
250 rs->sr_err = ldap_initialize(&ld, li->url);
252 if (rs->sr_err != LDAP_SUCCESS) {
253 rs->sr_err = slap_map_api2result( rs );
254 if (rs->sr_text == NULL) {
255 rs->sr_text = "ldap_initialize() failed";
257 if (op->o_conn) send_ldap_result( op, rs );
261 /* Set LDAP version. This will always succeed: If the client
262 * bound with a particular version, then so can we.
264 ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION,
265 (const void *)&vers);
266 /* FIXME: configurable? */
267 ldap_set_option(ld, LDAP_OPT_REFERRALS, LDAP_OPT_ON);
269 lc = (struct ldapconn *)ch_malloc(sizeof(struct ldapconn));
270 lc->conn = lc_curr.conn;
272 ber_dupbv( &lc->local_dn, &lc_curr.local_dn );
274 #ifdef ENABLE_REWRITE
276 * Sets a cookie for the rewrite session
278 * FIXME: the o_conn might be no longer valid,
279 * since we may have different entries
280 * for the same connection
282 ( void )rewrite_session_init( li->rwmap.rwm_rw, op->o_conn );
283 #endif /* ENABLE_REWRITE */
285 ldap_pvt_thread_mutex_init( &lc->lc_mutex );
288 ber_dupbv( &lc->cred, &li->acl_passwd );
289 ber_dupbv( &lc->bound_dn, &li->acl_authcDN );
292 BER_BVZERO( &lc->cred );
293 BER_BVZERO( &lc->bound_dn );
294 if ( op->o_conn && !BER_BVISEMPTY( &op->o_conn->c_dn )
295 && ( op->o_bd == op->o_conn->c_authz_backend ) ) {
301 * Rewrite the bind dn if needed
303 dc.rwmap = &li->rwmap;
304 #ifdef ENABLE_REWRITE
305 dc.conn = op->o_conn;
313 if ( ldap_back_dn_massage( &dc, &op->o_conn->c_dn, &bv ) ) {
314 send_ldap_result( op, rs );
318 if ( bv.bv_val == op->o_conn->c_dn.bv_val ) {
319 ber_dupbv( &lc->bound_dn, &bv );
328 /* Inserts the newly created ldapconn in the avl tree */
329 ldap_pvt_thread_mutex_lock( &li->conn_mutex );
330 rs->sr_err = avl_insert( &li->conntree, (caddr_t)lc,
331 ldap_back_conn_cmp, ldap_back_conn_dup );
333 #if PRINT_CONNTREE > 0
334 myprint( li->conntree );
335 #endif /* PRINT_CONNTREE */
337 ldap_pvt_thread_mutex_unlock( &li->conn_mutex );
340 LDAP_LOG( BACK_LDAP, INFO,
341 "ldap_back_getconn: conn %p inserted\n", (void *) lc, 0, 0);
342 #else /* !NEW_LOGGING */
343 Debug( LDAP_DEBUG_TRACE,
344 "=>ldap_back_getconn: conn %p inserted\n", (void *) lc, 0, 0 );
345 #endif /* !NEW_LOGGING */
347 /* Err could be -1 in case a duplicate ldapconn is inserted */
348 if ( rs->sr_err != 0 ) {
349 ldap_back_conn_free( lc );
351 send_ldap_error( op, rs, LDAP_OTHER,
352 "internal server error" );
358 LDAP_LOG( BACK_LDAP, INFO,
359 "ldap_back_getconn: conn %p fetched\n",
361 #else /* !NEW_LOGGING */
362 Debug( LDAP_DEBUG_TRACE,
363 "=>ldap_back_getconn: conn %p fetched\n", (void *) lc, 0, 0 );
364 #endif /* !NEW_LOGGING */
373 * Note: as the check for the value of lc->bound was already here, I removed
374 * it from all the callers, and I made the function return the flag, so
375 * it can be used to simplify the check.
378 ldap_back_dobind( struct ldapconn *lc, Operation *op, SlapReply *rs )
380 struct ldapinfo *li = (struct ldapinfo *)op->o_bd->be_private;
384 ldap_pvt_thread_mutex_lock( &lc->lc_mutex );
386 #ifdef LDAP_BACK_PROXY_AUTHZ
388 * FIXME: we need to let clients use proxyAuthz
389 * otherwise we cannot do symmetric pools of servers;
390 * we have to live with the fact that a user can
391 * authorize itself as any ID that is allowed
392 * by the authzTo directive of the "proxyauthzdn".
395 * NOTE: current Proxy Authorization specification
396 * and implementation do not allow proxy authorization
397 * control to be provided with Bind requests
400 * if no bind took place yet, but the connection is bound
401 * and the "proxyauthzdn" is set, then bind as
402 * "proxyauthzdn" and explicitly add the proxyAuthz
403 * control to every operation with the dn bound
404 * to the connection as control value.
406 if ( op->o_conn != NULL && ( ( BER_BVISNULL( &lc->bound_dn ) || BER_BVISEMPTY( &lc->bound_dn ) ) ) )
408 struct berval binddn = slap_empty_bv;
409 struct berval bindcred = slap_empty_bv;
412 /* bind as proxyauthzdn only if no idassert mode
413 * is requested, or if the client's identity
415 switch ( li->idassert_mode ) {
416 case LDAP_BACK_IDASSERT_LEGACY:
417 if ( !BER_BVISNULL( &op->o_conn->c_dn ) && !BER_BVISEMPTY( &op->o_conn->c_dn ) ) {
418 if ( !BER_BVISNULL( &li->idassert_authcDN ) && !BER_BVISEMPTY( &li->idassert_authcDN ) )
420 binddn = li->idassert_authcDN;
421 bindcred = li->idassert_passwd;
428 if ( li->idassert_authz ) {
429 struct berval authcDN = BER_BVISNULL( &op->o_conn->c_dn ) ? slap_empty_bv : op->o_conn->c_dn;
431 rs->sr_err = slap_sasl_matches( op, li->idassert_authz,
432 &authcDN, &authcDN );
433 if ( rs->sr_err != LDAP_SUCCESS ) {
434 send_ldap_result( op, rs );
440 binddn = li->idassert_authcDN;
441 bindcred = li->idassert_passwd;
446 if ( dobind && li->idassert_authmethod == LDAP_AUTH_SASL ) {
447 #ifdef HAVE_CYRUS_SASL
448 void *defaults = NULL;
449 struct berval authzID = BER_BVNULL;
452 /* if SASL supports native authz, prepare for it */
453 if ( li->idassert_flags & LDAP_BACK_AUTH_NATIVE_AUTHZ ) {
454 switch ( li->idassert_mode ) {
455 case LDAP_BACK_IDASSERT_OTHERID:
456 case LDAP_BACK_IDASSERT_OTHERDN:
457 authzID = li->idassert_authzID;
460 case LDAP_BACK_IDASSERT_ANONYMOUS:
461 BER_BVSTR( &authzID, "dn:" );
464 case LDAP_BACK_IDASSERT_SELF:
465 if ( BER_BVISNULL( &op->o_conn->c_dn ) ) {
466 /* connection is not authc'd, so don't idassert */
467 /* FIXME: cyrus-sasl doesn't honor empty authzID!
468 * i.e. NULL is equivalent to ""! */
471 authzID.bv_len = STRLENOF( "dn:" ) + op->o_conn->c_dn.bv_len;
472 authzID.bv_val = slap_sl_malloc( authzID.bv_len + 1, op->o_tmpmemctx );
473 AC_MEMCPY( authzID.bv_val, "dn:", STRLENOF( "dn:" ) );
474 AC_MEMCPY( authzID.bv_val + STRLENOF( "dn:" ),
475 op->o_conn->c_dn.bv_val, op->o_conn->c_dn.bv_len + 1 );
484 #if 0 /* will deal with this later... */
485 if ( sasl_secprops != NULL ) {
486 rs->sr_err = ldap_set_option( lc->ld, LDAP_OPT_X_SASL_SECPROPS,
487 (void *) sasl_secprops );
489 if ( rs->sr_err != LDAP_OPT_SUCCESS ) {
490 send_ldap_result( op, rs );
498 defaults = lutil_sasl_defaults( lc->ld,
499 li->idassert_sasl_mech.bv_val,
500 li->idassert_sasl_realm.bv_val,
501 li->idassert_authcID.bv_val,
502 li->idassert_passwd.bv_val,
505 rs->sr_err = ldap_sasl_interactive_bind_s( lc->ld, binddn.bv_val,
506 li->idassert_sasl_mech.bv_val, NULL, NULL,
507 li->idassert_sasl_flags, lutil_sasl_interact,
510 lutil_sasl_freedefs( defaults );
512 slap_sl_free( authzID.bv_val, op->o_tmpmemctx );
515 rs->sr_err = slap_map_api2result( rs );
516 if ( rs->sr_err != LDAP_SUCCESS ) {
518 send_ldap_result( op, rs );
524 #endif /* HAVE_CYRUS_SASL */
527 switch ( li->idassert_authmethod ) {
528 case LDAP_AUTH_SIMPLE:
529 rs->sr_err = ldap_sasl_bind(lc->ld,
530 binddn.bv_val, LDAP_SASL_SIMPLE,
531 &bindcred, NULL, NULL, &msgid);
541 rs->sr_err = LDAP_AUTH_METHOD_NOT_SUPPORTED;
542 send_ldap_result( op, rs );
547 #endif /* LDAP_BACK_PROXY_AUTHZ */
549 rs->sr_err = ldap_sasl_bind(lc->ld, lc->bound_dn.bv_val,
550 LDAP_SASL_SIMPLE, &lc->cred, NULL, NULL, &msgid);
553 rc = ldap_back_op_result( lc, op, rs, msgid, 0 );
554 if (rc == LDAP_SUCCESS) {
561 ldap_pvt_thread_mutex_unlock( &lc->lc_mutex );
568 * This is a callback used for chasing referrals using the same
569 * credentials as the original user on this session.
572 ldap_back_rebind( LDAP *ld, LDAP_CONST char *url, ber_tag_t request,
573 ber_int_t msgid, void *params )
575 struct ldapconn *lc = params;
577 return ldap_bind_s( ld, lc->bound_dn.bv_val, lc->cred.bv_val, LDAP_AUTH_SIMPLE );
580 #if 0 /* deprecated in favour of slap_map_api2result() */
581 /* Map API errors to protocol errors... */
583 ldap_back_map_result( SlapReply *rs )
587 case LDAP_SERVER_DOWN:
588 return LDAP_UNAVAILABLE;
589 case LDAP_LOCAL_ERROR:
591 case LDAP_ENCODING_ERROR:
592 case LDAP_DECODING_ERROR:
593 return LDAP_PROTOCOL_ERROR;
595 return LDAP_UNAVAILABLE;
596 case LDAP_AUTH_UNKNOWN:
597 return LDAP_AUTH_METHOD_NOT_SUPPORTED;
598 case LDAP_FILTER_ERROR:
599 rs->sr_text = "Filter error";
601 case LDAP_USER_CANCELLED:
602 rs->sr_text = "User cancelled";
604 case LDAP_PARAM_ERROR:
605 return LDAP_PROTOCOL_ERROR;
608 case LDAP_CONNECT_ERROR:
609 return LDAP_UNAVAILABLE;
610 case LDAP_NOT_SUPPORTED:
611 return LDAP_UNWILLING_TO_PERFORM;
612 case LDAP_CONTROL_NOT_FOUND:
613 return LDAP_PROTOCOL_ERROR;
614 case LDAP_NO_RESULTS_RETURNED:
615 return LDAP_NO_SUCH_OBJECT;
616 case LDAP_MORE_RESULTS_TO_RETURN:
617 rs->sr_text = "More results to return";
619 case LDAP_CLIENT_LOOP:
620 case LDAP_REFERRAL_LIMIT_EXCEEDED:
621 return LDAP_LOOP_DETECT;
623 if ( LDAP_API_ERROR(rs->sr_err) )
631 ldap_back_op_result(struct ldapconn *lc, Operation *op, SlapReply *rs,
632 ber_int_t msgid, int sendok)
634 struct ldapinfo *li = (struct ldapinfo *)op->o_bd->be_private;
636 LDAPMessage *res = NULL;
639 #define ERR_OK(err) ((err) == LDAP_SUCCESS || (err) == LDAP_COMPARE_FALSE || (err) == LDAP_COMPARE_TRUE)
642 rs->sr_matched = NULL;
644 /* if the error recorded in the reply corresponds
645 * to a successful state, get the error from the
646 * remote server response */
647 if ( ERR_OK( rs->sr_err ) ) {
648 /* if result parsing fails, note the failure reason */
649 if ( ldap_result( lc->ld, msgid, 1, NULL, &res ) == -1 ) {
650 ldap_get_option(lc->ld, LDAP_OPT_ERROR_NUMBER,
653 /* otherwise get the result; if it is not
654 * LDAP_SUCCESS, record it in the reply
655 * structure (this includes
656 * LDAP_COMPARE_{TRUE|FALSE}) */
658 int rc = ldap_parse_result(lc->ld, res, &rs->sr_err,
659 &match, &text, NULL, NULL, 1);
661 if ( rc != LDAP_SUCCESS ) rs->sr_err = rc;
665 /* if the error in the reply structure is not
666 * LDAP_SUCCESS, try to map it from client
668 if ( !ERR_OK( rs->sr_err ) ) {
669 rs->sr_err = slap_map_api2result( rs );
671 /* internal ops ( op->o_conn == NULL )
672 * must not reply to client */
673 if ( op->o_conn && !op->o_do_not_cache && match ) {
674 struct berval dn, mdn;
677 dc.rwmap = &li->rwmap;
678 #ifdef ENABLE_REWRITE
679 dc.conn = op->o_conn;
681 dc.ctx = "matchedDN";
686 ber_str2bv(match, 0, 0, &dn);
687 ldap_back_dn_massage(&dc, &dn, &mdn);
689 /* record the (massaged) matched
690 * DN into the reply structure */
691 rs->sr_matched = mdn.bv_val;
695 if ( op->o_conn && ( sendok || rs->sr_err != LDAP_SUCCESS ) ) {
696 send_ldap_result( op, rs );
699 if ( rs->sr_matched != match ) {
700 free( (char *)rs->sr_matched );
702 rs->sr_matched = NULL;
703 ldap_memfree( match );
706 ldap_memfree( text );
709 return( ERR_OK( rs->sr_err ) ? 0 : -1 );
712 #ifdef LDAP_BACK_PROXY_AUTHZ
714 * ldap_back_proxy_authz_ctrl() prepends a proxyAuthz control
715 * to existing server-side controls if required; if not,
716 * the existing server-side controls are placed in *pctrls.
717 * The caller, after using the controls in client API
718 * operations, if ( *pctrls != op->o_ctrls ), should
719 * free( (*pctrls)[ 0 ] ) and free( *pctrls ).
720 * The function returns success if the control could
721 * be added if required, or if it did nothing; in the future,
722 * it might return some error if it failed.
724 * if no bind took place yet, but the connection is bound
725 * and the "proxyauthzdn" is set, then bind as "proxyauthzdn"
726 * and explicitly add proxyAuthz the control to every operation
727 * with the dn bound to the connection as control value.
729 * If no server-side controls are defined for the operation,
730 * simply add the proxyAuthz control; otherwise, if the
731 * proxyAuthz control is not already set, add it as
732 * the first one (FIXME: is controls order significant
736 ldap_back_proxy_authz_ctrl(
740 LDAPControl ***pctrls )
742 struct ldapinfo *li = (struct ldapinfo *) op->o_bd->be_private;
743 LDAPControl **ctrls = NULL;
745 struct berval assertedID;
749 if ( ( BER_BVISNULL( &li->idassert_authcID ) || BER_BVISEMPTY( &li->idassert_authcID ) )
750 && ( BER_BVISNULL( &li->idassert_authcDN ) || BER_BVISEMPTY( &li->idassert_authcDN ) ) ) {
758 if ( li->idassert_mode == LDAP_BACK_IDASSERT_LEGACY ) {
759 if ( op->o_proxy_authz ) {
761 * FIXME: we do not want to perform proxyAuthz
762 * on behalf of the client, because this would
763 * be performed with "proxyauthzdn" privileges.
765 * This might actually be too strict, since
766 * the "proxyauthzdn" authzTo, and each entry's
767 * authzFrom attributes may be crafted
768 * to avoid unwanted proxyAuthz to take place.
771 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
772 rs->sr_text = "proxyAuthz not allowed within namingContext";
777 if ( !BER_BVISNULL( &lc->bound_dn ) && !BER_BVISEMPTY( &lc->bound_dn ) ) {
781 if ( BER_BVISNULL( &op->o_conn->c_dn ) || BER_BVISEMPTY( &op->o_conn->c_dn ) ) {
785 if ( BER_BVISNULL( &li->idassert_authcDN ) || BER_BVISEMPTY( &li->idassert_authcDN ) ) {
789 } else if ( li->idassert_authmethod == LDAP_AUTH_SASL ) {
790 if ( ( li->idassert_flags & LDAP_BACK_AUTH_NATIVE_AUTHZ )
791 && !BER_BVISNULL( &op->o_conn->c_dn ) && !BER_BVISEMPTY( &op->o_conn->c_dn ) )
793 /* already asserted in SASL via native authz */
797 } else if ( li->idassert_authz ) {
799 struct berval authcDN = BER_BVISNULL( &op->o_conn->c_dn ) ? slap_empty_bv : op->o_conn->c_dn;
802 rc = slap_sasl_matches( op, li->idassert_authz,
803 &authcDN, & authcDN );
804 if ( rc != LDAP_SUCCESS ) {
805 /* op->o_conn->c_dn is not authorized
811 if ( op->o_proxy_authz ) {
814 * 1) ignore the already set proxyAuthz control
815 * 2) leave it in place, and don't set ours
817 * 4) reject the operation
819 * option (4) is very drastic
820 * option (3) will make the remote server reject
821 * the operation, thus being equivalent to (4)
822 * option (2) will likely break the idassert
823 * assumptions, so we cannot accept it;
824 * option (1) means that we are contradicting
825 * the client's reques.
827 * I think (4) is the only correct choice.
829 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
830 rs->sr_text = "proxyAuthz not allowed within namingContext";
833 switch ( li->idassert_mode ) {
834 case LDAP_BACK_IDASSERT_LEGACY:
835 case LDAP_BACK_IDASSERT_SELF:
836 /* original behavior:
837 * assert the client's identity */
838 /* FIXME: we may get here if binding anonymously,
839 * because cyrus sasl doesn't honor empty (i.e. "")
841 assertedID = BER_BVISNULL( &op->o_conn->c_dn ) ? slap_empty_bv : op->o_conn->c_dn;
844 case LDAP_BACK_IDASSERT_ANONYMOUS:
845 /* assert "anonymous" */
846 assertedID = slap_empty_bv;
849 case LDAP_BACK_IDASSERT_NOASSERT:
850 /* don't assert; bind as proxyauthzdn */
853 case LDAP_BACK_IDASSERT_OTHERID:
854 case LDAP_BACK_IDASSERT_OTHERDN:
855 /* assert idassert DN */
856 assertedID = li->idassert_authzID;
863 if ( BER_BVISNULL( &assertedID ) ) {
864 assertedID = slap_empty_bv;
867 ctrls = ch_malloc( sizeof( LDAPControl * ) * (i + 2) );
868 ctrls[ 0 ] = ch_malloc( sizeof( LDAPControl ) );
870 ctrls[ 0 ]->ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
871 ctrls[ 0 ]->ldctl_iscritical = 1;
873 switch ( li->idassert_mode ) {
874 /* already in u:ID or dn:DN form */
875 case LDAP_BACK_IDASSERT_OTHERID:
876 case LDAP_BACK_IDASSERT_OTHERDN:
877 ber_dupbv( &ctrls[ 0 ]->ldctl_value, &assertedID );
880 /* needs the dn: prefix */
882 ctrls[ 0 ]->ldctl_value.bv_len = assertedID.bv_len + STRLENOF( "dn:" );
883 ctrls[ 0 ]->ldctl_value.bv_val = ch_malloc( ctrls[ 0 ]->ldctl_value.bv_len + 1 );
884 AC_MEMCPY( ctrls[ 0 ]->ldctl_value.bv_val, "dn:", STRLENOF( "dn:" ) );
885 AC_MEMCPY( ctrls[ 0 ]->ldctl_value.bv_val + STRLENOF( "dn:" ),
886 assertedID.bv_val, assertedID.bv_len + 1 );
891 for ( i = 0; op->o_ctrls[ i ]; i++ ) {
892 ctrls[ i + 1 ] = op->o_ctrls[ i ];
895 ctrls[ i + 1 ] = NULL;
898 if ( ctrls == NULL ) {
906 #endif /* LDAP_BACK_PROXY_AUTHZ */