1 /* result.c - routines to send ldap results, errors, and referrals */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2004 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
16 /* Portions Copyright (c) 1995 Regents of the University of Michigan.
17 * All rights reserved.
19 * Redistribution and use in source and binary forms are permitted
20 * provided that this notice is preserved and that due credit is given
21 * to the University of Michigan at Ann Arbor. The name of the University
22 * may not be used to endorse or promote products derived from this
23 * software without specific prior written permission. This software
24 * is provided ``as is'' without express or implied warranty.
31 #include <ac/socket.h>
33 #include <ac/string.h>
36 #include <ac/unistd.h>
41 #include "slapi/slapi.h"
44 int slap_null_cb( Operation *op, SlapReply *rs )
49 int slap_replog_cb( Operation *op, SlapReply *rs )
51 if ( rs->sr_err == LDAP_SUCCESS ) {
54 return SLAP_CB_CONTINUE;
57 static char *v2ref( BerVarray ref, const char *text )
59 size_t len = 0, i = 0;
64 return ch_strdup(text);
72 if (text[len-1] != '\n') {
77 v2 = SLAP_MALLOC( len+i+sizeof("Referral:") );
80 LDAP_LOG( OPERATION, ERR, "v2ref: SLAP_MALLOC failed", 0, 0, 0 );
82 Debug( LDAP_DEBUG_ANY, "v2ref: SLAP_MALLOC failed", 0, 0, 0 );
93 strcpy( v2+len, "Referral:" );
94 len += sizeof("Referral:");
96 for( i=0; ref[i].bv_val != NULL; i++ ) {
97 v2 = SLAP_REALLOC( v2, len + ref[i].bv_len + 1 );
100 LDAP_LOG( OPERATION, ERR, "v2ref: SLAP_MALLOC failed", 0, 0, 0 );
102 Debug( LDAP_DEBUG_ANY, "v2ref: SLAP_MALLOC failed", 0, 0, 0 );
107 AC_MEMCPY(&v2[len], ref[i].bv_val, ref[i].bv_len );
108 len += ref[i].bv_len;
109 if (ref[i].bv_val[ref[i].bv_len-1] != '/') {
118 static ber_tag_t req2res( ber_tag_t tag )
123 case LDAP_REQ_COMPARE:
124 case LDAP_REQ_EXTENDED:
125 case LDAP_REQ_MODIFY:
126 case LDAP_REQ_MODRDN:
130 case LDAP_REQ_DELETE:
131 tag = LDAP_RES_DELETE;
134 case LDAP_REQ_ABANDON:
135 case LDAP_REQ_UNBIND:
139 case LDAP_REQ_SEARCH:
140 tag = LDAP_RES_SEARCH_RESULT;
150 static long send_ldap_ber(
156 ber_get_option( ber, LBER_OPT_BER_BYTES_TO_WRITE, &bytes );
158 /* write only one pdu at a time - wait til it's our turn */
159 ldap_pvt_thread_mutex_lock( &conn->c_write_mutex );
161 /* lock the connection */
162 ldap_pvt_thread_mutex_lock( &conn->c_mutex );
169 if ( connection_state_closing( conn ) ) {
170 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
171 ldap_pvt_thread_mutex_unlock( &conn->c_write_mutex );
176 if ( ber_flush( conn->c_sb, ber, 0 ) == 0 ) {
183 * we got an error. if it's ewouldblock, we need to
184 * wait on the socket being writable. otherwise, figure
185 * it's a hard error and return.
189 LDAP_LOG( OPERATION, ERR,
190 "send_ldap_ber: conn %lu ber_flush failed err=%d (%s)\n",
191 conn ? conn->c_connid : 0, err, sock_errstr(err) );
193 Debug( LDAP_DEBUG_CONNS, "ber_flush failed errno=%d reason=\"%s\"\n",
194 err, sock_errstr(err), 0 );
197 if ( err != EWOULDBLOCK && err != EAGAIN ) {
198 connection_closing( conn );
200 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
201 ldap_pvt_thread_mutex_unlock( &conn->c_write_mutex );
206 /* wait for socket to be write-ready */
207 conn->c_writewaiter = 1;
208 ber_sockbuf_ctrl( conn->c_sb, LBER_SB_OPT_GET_FD, &sd );
209 slapd_set_write( sd, 1 );
211 ldap_pvt_thread_cond_wait( &conn->c_write_cv, &conn->c_mutex );
212 conn->c_writewaiter = 0;
215 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
216 ldap_pvt_thread_mutex_unlock( &conn->c_write_mutex );
222 send_ldap_control( BerElement *ber, LDAPControl *c )
228 rc = ber_printf( ber, "{s" /*}*/, c->ldctl_oid );
230 if( c->ldctl_iscritical ) {
231 rc = ber_printf( ber, "b",
232 (ber_int_t) c->ldctl_iscritical ) ;
233 if( rc == -1 ) return rc;
236 if( c->ldctl_value.bv_val != NULL ) {
237 rc = ber_printf( ber, "O", &c->ldctl_value );
238 if( rc == -1 ) return rc;
241 rc = ber_printf( ber, /*{*/"N}" );
242 if( rc == -1 ) return rc;
248 send_ldap_controls( Operation *o, BerElement *ber, LDAPControl **c )
252 LDAPControl **sctrls = NULL;
255 * Retrieve any additional controls that may be set by the
259 if ( o->o_pb && slapi_pblock_get( o->o_pb, SLAPI_RESCONTROLS, &sctrls ) != 0 ) {
263 if ( c == NULL && sctrls == NULL ) return 0;
265 if( c == NULL ) return 0;
266 #endif /* LDAP_SLAPI */
268 rc = ber_printf( ber, "t{"/*}*/, LDAP_TAG_CONTROLS );
269 if( rc == -1 ) return rc;
273 #endif /* LDAP_SLAPI */
274 for( ; *c != NULL; c++) {
275 rc = send_ldap_control( ber, *c );
276 if( rc == -1 ) return rc;
280 if ( sctrls != NULL ) {
281 for ( c = sctrls; *c != NULL; c++ ) {
282 rc = send_ldap_control( ber, *c );
283 if( rc == -1 ) return rc;
286 #endif /* LDAP_SLAPI */
288 rc = ber_printf( ber, /*{*/"N}" );
298 BerElementBuffer berbuf;
299 BerElement *ber = (BerElement *) &berbuf;
300 int rc = LDAP_SUCCESS;
303 if (op->o_callback) {
304 slap_callback *sc = op->o_callback;
305 rc = SLAP_CB_CONTINUE;
306 for ( ; op->o_callback; ) {
307 if ( op->o_callback->sc_response ) {
308 rc = op->o_callback->sc_response( op, rs );
309 if ( rc != SLAP_CB_CONTINUE ) break;
311 op->o_callback = op->o_callback->sc_next;
314 if ( rc != SLAP_CB_CONTINUE ) goto clean2;
317 #ifdef LDAP_CONNECTIONLESS
318 if (op->o_conn && op->o_conn->c_is_udp)
323 ber_init_w_nullc( ber, LBER_USE_DER );
324 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
328 LDAP_LOG( OPERATION, ENTRY,
329 "send_ldap_response: msgid=%d tag=%lu err=%d\n",
330 rs->sr_msgid, rs->sr_tag, rs->sr_err );
332 Debug( LDAP_DEBUG_TRACE,
333 "send_ldap_response: msgid=%d tag=%lu err=%d\n",
334 rs->sr_msgid, rs->sr_tag, rs->sr_err );
339 LDAP_LOG( OPERATION, ARGS,
340 "send_ldap_response: conn %lu ref=\"%s\"\n",
342 rs->sr_ref[0].bv_val ? rs->sr_ref[0].bv_val : "NULL" , 0 );
344 Debug( LDAP_DEBUG_ARGS, "send_ldap_response: ref=\"%s\"\n",
345 rs->sr_ref[0].bv_val ? rs->sr_ref[0].bv_val : "NULL",
350 #ifdef LDAP_CONNECTIONLESS
351 if (op->o_conn && op->o_conn->c_is_udp &&
352 op->o_protocol == LDAP_VERSION2 )
354 rc = ber_printf( ber, "t{ess" /*"}"*/,
355 rs->sr_tag, rs->sr_err,
356 rs->sr_matched == NULL ? "" : rs->sr_matched,
357 rs->sr_text == NULL ? "" : rs->sr_text );
360 if ( rs->sr_type == REP_INTERMEDIATE ) {
361 rc = ber_printf( ber, "{it{" /*"}}"*/,
362 rs->sr_msgid, rs->sr_tag );
365 rc = ber_printf( ber, "{it{ess" /*"}}"*/,
366 rs->sr_msgid, rs->sr_tag, rs->sr_err,
367 rs->sr_matched == NULL ? "" : rs->sr_matched,
368 rs->sr_text == NULL ? "" : rs->sr_text );
372 if ( rs->sr_ref != NULL ) {
373 assert( rs->sr_err == LDAP_REFERRAL );
374 rc = ber_printf( ber, "t{W}",
375 LDAP_TAG_REFERRAL, rs->sr_ref );
377 assert( rs->sr_err != LDAP_REFERRAL );
381 if( rc != -1 && rs->sr_type == REP_SASL && rs->sr_sasldata != NULL ) {
382 rc = ber_printf( ber, "tO",
383 LDAP_TAG_SASL_RES_CREDS, rs->sr_sasldata );
387 ( rs->sr_type == REP_EXTENDED || rs->sr_type == REP_INTERMEDIATE ))
389 if ( rs->sr_rspoid != NULL ) {
390 rc = ber_printf( ber, "ts",
391 LDAP_TAG_EXOP_RES_OID, rs->sr_rspoid );
393 if( rc != -1 && rs->sr_rspdata != NULL ) {
394 rc = ber_printf( ber, "tO",
395 LDAP_TAG_EXOP_RES_VALUE, rs->sr_rspdata );
400 rc = ber_printf( ber, /*"{"*/ "N}" );
404 rc = send_ldap_controls( op, ber, rs->sr_ctrls );
408 rc = ber_printf( ber, /*"{"*/ "N}" );
411 #ifdef LDAP_CONNECTIONLESS
412 if( op->o_conn && op->o_conn->c_is_udp && op->o_protocol == LDAP_VERSION2
415 rc = ber_printf( ber, /*"{"*/ "N}" );
421 LDAP_LOG( OPERATION, ERR,
422 "send_ldap_response: conn %lu ber_printf failed\n",
423 op->o_connid, 0, 0 );
425 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
428 #ifdef LDAP_CONNECTIONLESS
429 if (!op->o_conn || op->o_conn->c_is_udp == 0)
438 bytes = send_ldap_ber( op->o_conn, ber );
439 #ifdef LDAP_CONNECTIONLESS
440 if (!op->o_conn || op->o_conn->c_is_udp == 0)
448 LDAP_LOG( OPERATION, ERR,
449 "send_ldap_response: conn %lu ber write failed\n",
450 op->o_connid ? op->o_connid : 0, 0, 0 );
452 Debug( LDAP_DEBUG_ANY,
453 "send_ldap_response: ber write failed\n",
462 slapi_pblock_set( op->o_pb, SLAPI_RESULT_CODE, (void *)rs->sr_err );
463 slapi_pblock_set( op->o_pb, SLAPI_RESULT_MATCHED,
464 (void *)rs->sr_matched );
465 slapi_pblock_set( op->o_pb, SLAPI_RESULT_TEXT, (void *)rs->sr_text );
467 #endif /* LDAP_SLAPI */
469 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
470 num_bytes_sent += bytes;
472 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
475 /* Tell caller that we did this for real, as opposed to being
476 * overridden by a callback
478 rc = SLAP_CB_CONTINUE;
480 if ( rs->sr_matched && rs->sr_flags & REP_MATCHED_MUSTBEFREED ) {
481 free( (char *)rs->sr_matched );
482 rs->sr_matched = NULL;
485 if ( rs->sr_ref && rs->sr_flags & REP_REF_MUSTBEFREED ) {
486 ber_bvarray_free( rs->sr_ref );
491 if (op->o_callback) {
492 slap_callback *sc = op->o_callback;
493 for ( ; op->o_callback; op->o_callback = op->o_callback->sc_next ) {
494 if ( op->o_callback->sc_cleanup ) {
495 op->o_callback->sc_cleanup( op, rs );
506 send_ldap_disconnect( Operation *op, SlapReply *rs )
508 #define LDAP_UNSOLICITED_ERROR(e) \
509 ( (e) == LDAP_PROTOCOL_ERROR \
510 || (e) == LDAP_STRONG_AUTH_REQUIRED \
511 || (e) == LDAP_UNAVAILABLE )
513 assert( LDAP_UNSOLICITED_ERROR( rs->sr_err ) );
515 rs->sr_type = REP_EXTENDED;
518 LDAP_LOG( OPERATION, ENTRY,
519 "send_ldap_disconnect: conn %lu %d:%s\n",
520 op->o_connid, rs->sr_err, rs->sr_text ? rs->sr_text : "" );
522 Debug( LDAP_DEBUG_TRACE,
523 "send_ldap_disconnect %d:%s\n",
524 rs->sr_err, rs->sr_text ? rs->sr_text : "", NULL );
527 if ( op->o_protocol < LDAP_VERSION3 ) {
528 rs->sr_rspoid = NULL;
529 rs->sr_tag = req2res( op->o_tag );
530 rs->sr_msgid = (rs->sr_tag != LBER_SEQUENCE) ? op->o_msgid : 0;
533 rs->sr_rspoid = LDAP_NOTICE_DISCONNECT;
534 rs->sr_tag = LDAP_RES_EXTENDED;
538 if ( send_ldap_response( op, rs ) == SLAP_CB_CONTINUE ) {
539 Statslog( LDAP_DEBUG_STATS,
540 "conn=%lu op=%lu DISCONNECT tag=%lu err=%d text=%s\n",
541 op->o_connid, op->o_opid, rs->sr_tag, rs->sr_err,
542 rs->sr_text ? rs->sr_text : "" );
547 slap_send_ldap_result( Operation *op, SlapReply *rs )
550 const char *otext = rs->sr_text;
551 BerVarray oref = rs->sr_ref;
553 rs->sr_type = REP_RESULT;
555 assert( !LDAP_API_ERROR( rs->sr_err ));
558 LDAP_LOG( OPERATION, ENTRY,
559 "send_ldap_result: conn=%lu op=%lu p=%d\n",
560 op->o_connid, op->o_opid, op->o_protocol );
562 Debug( LDAP_DEBUG_TRACE,
563 "send_ldap_result: conn=%lu op=%lu p=%d\n",
564 op->o_connid, op->o_opid, op->o_protocol );
568 LDAP_LOG( OPERATION, ARGS,
569 "send_ldap_result: err=%d matched=\"%s\" text=\"%s\"\n",
570 rs->sr_err, rs->sr_matched ? rs->sr_matched : "",
571 rs->sr_text ? rs->sr_text : "" );
573 Debug( LDAP_DEBUG_ARGS,
574 "send_ldap_result: err=%d matched=\"%s\" text=\"%s\"\n",
575 rs->sr_err, rs->sr_matched ? rs->sr_matched : "",
576 rs->sr_text ? rs->sr_text : "" );
582 LDAP_LOG( OPERATION, ARGS,
583 "send_ldap_result: referral=\"%s\"\n",
584 rs->sr_ref[0].bv_val ? rs->sr_ref[0].bv_val : "NULL", 0, 0 );
586 Debug( LDAP_DEBUG_ARGS,
587 "send_ldap_result: referral=\"%s\"\n",
588 rs->sr_ref[0].bv_val ? rs->sr_ref[0].bv_val : "NULL",
593 assert( rs->sr_err != LDAP_PARTIAL_RESULTS );
595 if ( rs->sr_err == LDAP_REFERRAL ) {
596 #ifdef LDAP_CONTROL_X_DOMAIN_SCOPE
597 if( op->o_domain_scope ) {
601 if( rs->sr_ref == NULL ) {
602 rs->sr_err = LDAP_NO_SUCH_OBJECT;
603 } else if ( op->o_protocol < LDAP_VERSION3 ) {
604 rs->sr_err = LDAP_PARTIAL_RESULTS;
610 * Call pre-result plugins. To avoid infinite recursion plugins
611 * should just set SLAPI_RESULT_CODE rather than sending a
612 * result if they wish to change the result.
614 if ( op->o_pb != NULL ) {
615 slapi_int_pblock_set_operation( op->o_pb, op );
616 slapi_pblock_set( op->o_pb, SLAPI_RESULT_CODE,
617 (void *)rs->sr_err );
618 slapi_pblock_set( op->o_pb, SLAPI_RESULT_TEXT,
619 (void *)rs->sr_text );
620 slapi_pblock_set( op->o_pb, SLAPI_RESULT_MATCHED,
621 (void *)rs->sr_matched );
623 (void) slapi_int_call_plugins( op->o_bd, SLAPI_PLUGIN_PRE_RESULT_FN,
626 #endif /* LDAP_SLAPI */
628 if ( op->o_protocol < LDAP_VERSION3 ) {
629 tmp = v2ref( rs->sr_ref, rs->sr_text );
634 rs->sr_tag = req2res( op->o_tag );
635 rs->sr_msgid = (rs->sr_tag != LBER_SEQUENCE) ? op->o_msgid : 0;
637 if ( send_ldap_response( op, rs ) == SLAP_CB_CONTINUE ) {
638 if ( op->o_tag == LDAP_REQ_SEARCH ) {
640 snprintf( nbuf, sizeof nbuf, "%d nentries=%d",
641 rs->sr_err, rs->sr_nentries );
643 Statslog( LDAP_DEBUG_STATS,
644 "conn=%lu op=%lu SEARCH RESULT tag=%lu err=%s text=%s\n",
645 op->o_connid, op->o_opid, rs->sr_tag, nbuf,
646 rs->sr_text ? rs->sr_text : "" );
648 Statslog( LDAP_DEBUG_STATS,
649 "conn=%lu op=%lu RESULT tag=%lu err=%d text=%s\n",
650 op->o_connid, op->o_opid, rs->sr_tag, rs->sr_err,
651 rs->sr_text ? rs->sr_text : "" );
655 if( tmp != NULL ) ch_free(tmp);
661 send_ldap_sasl( Operation *op, SlapReply *rs )
663 rs->sr_type = REP_SASL;
665 LDAP_LOG( OPERATION, ENTRY,
666 "send_ldap_sasl: conn %lu err=%d len=%lu\n",
667 op->o_connid, rs->sr_err,
668 rs->sr_sasldata ? rs->sr_sasldata->bv_len : -1 );
670 Debug( LDAP_DEBUG_TRACE, "send_ldap_sasl: err=%d len=%ld\n",
672 rs->sr_sasldata ? (long) rs->sr_sasldata->bv_len : -1, NULL );
675 rs->sr_tag = req2res( op->o_tag );
676 rs->sr_msgid = (rs->sr_tag != LBER_SEQUENCE) ? op->o_msgid : 0;
678 send_ldap_response( op, rs );
682 slap_send_ldap_extended( Operation *op, SlapReply *rs )
684 rs->sr_type = REP_EXTENDED;
687 LDAP_LOG( OPERATION, ENTRY,
688 "send_ldap_extended: err=%d oid=%s len=%ld\n",
689 rs->sr_err, rs->sr_rspoid ? rs->sr_rspoid : "",
690 rs->sr_rspdata != NULL ? rs->sr_rspdata->bv_len : 0 );
692 Debug( LDAP_DEBUG_TRACE,
693 "send_ldap_extended: err=%d oid=%s len=%ld\n",
695 rs->sr_rspoid ? rs->sr_rspoid : "",
696 rs->sr_rspdata != NULL ? rs->sr_rspdata->bv_len : 0 );
699 rs->sr_tag = req2res( op->o_tag );
700 rs->sr_msgid = (rs->sr_tag != LBER_SEQUENCE) ? op->o_msgid : 0;
702 send_ldap_response( op, rs );
706 slap_send_ldap_intermediate( Operation *op, SlapReply *rs )
708 rs->sr_type = REP_INTERMEDIATE;
710 LDAP_LOG( OPERATION, ENTRY,
711 "send_ldap_intermediate: err=%d oid=%s len=%ld\n",
712 rs->sr_err, rs->sr_rspoid ? rs->sr_rspoid : "",
713 rs->sr_rspdata != NULL ? rs->sr_rspdata->bv_len : 0 );
715 Debug( LDAP_DEBUG_TRACE,
716 "send_ldap_intermediate: err=%d oid=%s len=%ld\n",
718 rs->sr_rspoid ? rs->sr_rspoid : "",
719 rs->sr_rspdata != NULL ? rs->sr_rspdata->bv_len : 0 );
721 rs->sr_tag = LDAP_RES_INTERMEDIATE;
722 rs->sr_msgid = op->o_msgid;
723 send_ldap_response( op, rs );
727 slap_send_search_entry( Operation *op, SlapReply *rs )
729 BerElementBuffer berbuf;
730 BerElement *ber = (BerElement *) &berbuf;
732 int i, j, rc=-1, bytes;
736 AccessControlState acl_state = ACL_STATE_INIT;
738 /* Support for computed attribute plugins */
739 computed_attr_context ctx;
742 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
744 /* a_flags: array of flags telling if the i-th element will be
745 * returned or filtered out
746 * e_flags: array of a_flags
748 char **e_flags = NULL;
750 rs->sr_type = REP_SEARCH;
751 if (op->o_callback) {
752 slap_callback *sc = op->o_callback;
753 rc = SLAP_CB_CONTINUE;
754 for ( ; op->o_callback; ) {
755 if ( op->o_callback->sc_response ) {
756 rc = op->o_callback->sc_response( op, rs );
757 if ( rc != SLAP_CB_CONTINUE ) break;
759 op->o_callback = op->o_callback->sc_next;
762 if ( rc != SLAP_CB_CONTINUE ) goto error_return;
766 LDAP_LOG( OPERATION, ENTRY, "send_search_entry: conn %lu dn=\"%s\"%s\n",
767 op->o_connid, rs->sr_entry->e_name.bv_val,
768 op->ors_attrsonly ? " (attrsOnly)" : "" );
770 Debug( LDAP_DEBUG_TRACE, "=> send_search_entry: dn=\"%s\"%s\n",
771 rs->sr_entry->e_name.bv_val,
772 op->ors_attrsonly ? " (attrsOnly)" : "", 0 );
775 if ( !access_allowed( op, rs->sr_entry, ad_entry, NULL, ACL_READ, NULL )) {
778 "send_search_entry: conn %lu access to entry (%s) not allowed\n",
779 op->o_connid, rs->sr_entry->e_name.bv_val, 0 );
781 Debug( LDAP_DEBUG_ACL,
782 "send_search_entry: access to entry not allowed\n",
790 edn = rs->sr_entry->e_nname.bv_val;
792 if ( op->o_res_ber ) {
793 /* read back control or LDAP_CONNECTIONLESS */
799 entry_flatsize( rs->sr_entry, &siz, &len, 0 );
800 bv.bv_len = siz + len;
801 bv.bv_val = op->o_tmpalloc(bv.bv_len, op->o_tmpmemctx );
803 ber_init2( ber, &bv, LBER_USE_DER );
804 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
807 #ifdef LDAP_CONNECTIONLESS
808 if ( op->o_conn && op->o_conn->c_is_udp ) {
810 if ( op->o_protocol == LDAP_VERSION2 ) {
811 rc = ber_printf(ber, "t{O{" /*}}*/,
812 LDAP_RES_SEARCH_ENTRY, &rs->sr_entry->e_name );
814 rc = ber_printf( ber, "{it{O{" /*}}}*/, op->o_msgid,
815 LDAP_RES_SEARCH_ENTRY, &rs->sr_entry->e_name );
819 if ( op->o_res_ber ) {
820 /* read back control */
821 rc = ber_printf( ber, "{O{" /*}}*/, &rs->sr_entry->e_name );
823 rc = ber_printf( ber, "{it{O{" /*}}}*/, op->o_msgid,
824 LDAP_RES_SEARCH_ENTRY, &rs->sr_entry->e_name );
829 LDAP_LOG( OPERATION, ERR,
830 "send_search_entry: conn %lu ber_printf failed\n",
831 op->o_connid, 0, 0 );
833 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
836 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
837 send_ldap_error( op, rs, LDAP_OTHER, "encoding DN error" );
841 /* check for special all user attributes ("*") type */
842 userattrs = ( rs->sr_attrs == NULL ) ? 1
843 : an_find( rs->sr_attrs, &AllUser );
845 /* check for special all operational attributes ("+") type */
846 opattrs = ( rs->sr_attrs == NULL ) ? 0
847 : an_find( rs->sr_attrs, &AllOper );
849 /* create an array of arrays of flags. Each flag corresponds
850 * to particular value of attribute and equals 1 if value matches
851 * to ValuesReturnFilter or 0 if not
853 if ( op->o_vrFilter != NULL ) {
857 for ( a = rs->sr_entry->e_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
858 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ ) k++;
861 size = i * sizeof(char *) + k;
864 e_flags = slap_sl_calloc ( 1, i * sizeof(char *) + k, op->o_tmpmemctx );
865 if( e_flags == NULL ) {
867 LDAP_LOG( OPERATION, ERR,
868 "send_search_entry: conn %lu slap_sl_calloc failed\n",
869 op->o_connid ? op->o_connid : 0, 0, 0 );
871 Debug( LDAP_DEBUG_ANY,
872 "send_search_entry: slap_sl_calloc failed\n", 0, 0, 0 );
876 send_ldap_error( op, rs, LDAP_OTHER, "out of memory" );
879 a_flags = (char *)(e_flags + i);
880 memset( a_flags, 0, k );
881 for ( a=rs->sr_entry->e_attrs, i=0; a != NULL; a=a->a_next, i++ ) {
882 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ );
883 e_flags[i] = a_flags;
887 rc = filter_matched_values(op, rs->sr_entry->e_attrs, &e_flags) ;
890 LDAP_LOG( OPERATION, ERR, "send_search_entry: "
891 "conn %lu matched values filtering failed\n",
892 op->o_connid ? op->o_connid : 0, 0, 0 );
894 Debug( LDAP_DEBUG_ANY,
895 "matched values filtering failed\n", 0, 0, 0 );
897 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
898 send_ldap_error( op, rs, LDAP_OTHER,
899 "matched values filtering error" );
905 for ( a = rs->sr_entry->e_attrs, j = 0; a != NULL; a = a->a_next, j++ ) {
906 AttributeDescription *desc = a->a_desc;
909 if ( rs->sr_attrs == NULL ) {
910 /* all attrs request, skip operational attributes */
911 if( is_at_operational( desc->ad_type ) ) {
916 /* specific attrs requested */
917 if ( is_at_operational( desc->ad_type ) ) {
918 if( !opattrs && !ad_inlist( desc, rs->sr_attrs ) ) {
923 if (!userattrs && !ad_inlist( desc, rs->sr_attrs ) ) {
929 if ( op->ors_attrsonly ) {
930 if ( ! access_allowed( op, rs->sr_entry, desc, NULL,
931 ACL_READ, &acl_state ) )
935 "send_search_entry: conn %lu access to attribute %s not "
936 "allowed\n", op->o_connid, desc->ad_cname.bv_val, 0 );
938 Debug( LDAP_DEBUG_ACL, "acl: "
939 "access to attribute %s not allowed\n",
940 desc->ad_cname.bv_val, 0, 0 );
945 if (( rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname )) == -1 ) {
947 LDAP_LOG( OPERATION, ERR,
948 "send_search_entry: conn %lu ber_printf failed\n",
949 op->o_connid, 0, 0 );
951 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
954 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
955 send_ldap_error( op, rs, LDAP_OTHER,
956 "encoding description error");
963 for ( i = 0; a->a_nvals[i].bv_val != NULL; i++ ) {
964 if ( ! access_allowed( op, rs->sr_entry,
965 desc, &a->a_nvals[i], ACL_READ, &acl_state ) )
969 "send_search_entry: conn %lu "
970 "access to attribute %s, value %d not allowed\n",
971 op->o_connid, desc->ad_cname.bv_val, i );
973 Debug( LDAP_DEBUG_ACL,
974 "acl: access to attribute %s, "
975 "value %d not allowed\n",
976 desc->ad_cname.bv_val, i, 0 );
982 if ( op->o_vrFilter && e_flags[j][i] == 0 ){
989 if (( rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname )) == -1 ) {
991 LDAP_LOG( OPERATION, ERR,
992 "send_search_entry: conn %lu ber_printf failed\n",
993 op->o_connid, 0, 0 );
995 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
998 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
999 send_ldap_error( op, rs, LDAP_OTHER,
1000 "encoding description error");
1004 if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
1006 LDAP_LOG( OPERATION, ERR,
1007 "send_search_entry: conn %lu "
1008 "ber_printf failed.\n", op->o_connid, 0, 0 );
1010 Debug( LDAP_DEBUG_ANY,
1011 "ber_printf failed\n", 0, 0, 0 );
1014 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1015 send_ldap_error( op, rs, LDAP_OTHER,
1016 "encoding values error" );
1022 if ( finish && ( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
1024 LDAP_LOG( OPERATION, ERR,
1025 "send_search_entry: conn %lu ber_printf failed\n",
1026 op->o_connid, 0, 0 );
1028 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1031 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1032 send_ldap_error( op, rs, LDAP_OTHER, "encode end error" );
1037 /* eventually will loop through generated operational attributes */
1038 /* only have subschemaSubentry and numSubordinates are implemented */
1039 aa = backend_operational( op, rs, opattrs );
1041 if ( aa != NULL && op->o_vrFilter != NULL ) {
1045 for ( a = aa, i=0; a != NULL; a = a->a_next, i++ ) {
1046 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ ) k++;
1049 size = i * sizeof(char *) + k;
1051 char *a_flags, **tmp;
1054 * Reuse previous memory - we likely need less space
1055 * for operational attributes
1057 tmp = slap_sl_realloc( e_flags, i * sizeof(char *) + k,
1059 if ( tmp == NULL ) {
1061 LDAP_LOG( OPERATION, ERR,
1062 "send_search_entry: conn %lu "
1063 "not enough memory "
1064 "for matched values filtering\n",
1065 op->o_connid, 0, 0);
1067 Debug( LDAP_DEBUG_ANY,
1068 "send_search_entry: conn %lu "
1069 "not enough memory "
1070 "for matched values filtering\n",
1071 op->o_connid, 0, 0 );
1073 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1074 send_ldap_error( op, rs, LDAP_OTHER,
1075 "not enough memory for matched values filtering" );
1079 a_flags = (char *)(e_flags + i);
1080 memset( a_flags, 0, k );
1081 for ( a = aa, i=0; a != NULL; a = a->a_next, i++ ) {
1082 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ );
1083 e_flags[i] = a_flags;
1086 rc = filter_matched_values(op, aa, &e_flags) ;
1090 LDAP_LOG( OPERATION, ERR,
1091 "send_search_entry: conn %lu "
1092 "matched values filtering failed\n",
1093 op->o_connid ? op->o_connid : 0, 0, 0);
1095 Debug( LDAP_DEBUG_ANY,
1096 "matched values filtering failed\n", 0, 0, 0 );
1098 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1099 send_ldap_error( op, rs, LDAP_OTHER,
1100 "matched values filtering error" );
1106 for (a = aa, j=0; a != NULL; a = a->a_next, j++ ) {
1107 AttributeDescription *desc = a->a_desc;
1109 if ( rs->sr_attrs == NULL ) {
1110 /* all attrs request, skip operational attributes */
1111 if( is_at_operational( desc->ad_type ) ) {
1116 /* specific attrs requested */
1117 if( is_at_operational( desc->ad_type ) ) {
1118 if( !opattrs && !ad_inlist( desc, rs->sr_attrs ) ) {
1122 if (!userattrs && !ad_inlist( desc, rs->sr_attrs ) ) {
1128 if ( ! access_allowed( op, rs->sr_entry, desc, NULL,
1129 ACL_READ, &acl_state ) )
1132 LDAP_LOG( ACL, INFO,
1133 "send_search_entry: conn %lu "
1134 "access to attribute %s not allowed\n",
1135 op->o_connid, desc->ad_cname.bv_val, 0 );
1137 Debug( LDAP_DEBUG_ACL, "send_search_entry: access to attribute %s "
1138 "not allowed\n", desc->ad_cname.bv_val, 0, 0 );
1144 rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname );
1147 LDAP_LOG( OPERATION, ERR,
1148 "send_search_entry: conn %lu "
1149 "ber_printf failed\n", op->o_connid, 0, 0 );
1151 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1154 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1155 send_ldap_error( op, rs, LDAP_OTHER,
1156 "encoding description error" );
1161 if ( ! op->ors_attrsonly ) {
1162 for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
1163 if ( ! access_allowed( op, rs->sr_entry,
1164 desc, &a->a_vals[i], ACL_READ, &acl_state ) )
1167 LDAP_LOG( ACL, INFO,
1168 "send_search_entry: conn %lu "
1169 "access to %s, value %d not allowed\n",
1170 op->o_connid, desc->ad_cname.bv_val, i );
1172 Debug( LDAP_DEBUG_ACL,
1173 "send_search_entry: access to attribute %s, "
1174 "value %d not allowed\n",
1175 desc->ad_cname.bv_val, i, 0 );
1181 if ( op->o_vrFilter && e_flags[j][i] == 0 ){
1185 if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
1187 LDAP_LOG( OPERATION, ERR,
1188 "send_search_entry: conn %lu ber_printf failed\n",
1189 op->o_connid, 0, 0 );
1191 Debug( LDAP_DEBUG_ANY,
1192 "ber_printf failed\n", 0, 0, 0 );
1195 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1196 send_ldap_error( op, rs, LDAP_OTHER,
1197 "encoding values error" );
1204 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
1206 LDAP_LOG( OPERATION, ERR,
1207 "send_search_entry: conn %lu ber_printf failed\n",
1208 op->o_connid, 0, 0 );
1210 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1213 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1214 send_ldap_error( op, rs, LDAP_OTHER, "encode end error" );
1222 * First, setup the computed attribute context that is
1223 * passed to all plugins.
1226 ctx.cac_pb = op->o_pb;
1227 ctx.cac_attrs = rs->sr_attrs;
1228 ctx.cac_attrsonly = op->ors_attrsonly;
1229 ctx.cac_userattrs = userattrs;
1230 ctx.cac_opattrs = opattrs;
1231 ctx.cac_acl_state = acl_state;
1232 ctx.cac_private = (void *)ber;
1235 * For each client requested attribute, call the plugins.
1237 if ( rs->sr_attrs != NULL ) {
1238 for ( anp = rs->sr_attrs; anp->an_name.bv_val != NULL; anp++ ) {
1239 rc = compute_evaluator( &ctx, anp->an_name.bv_val,
1240 rs->sr_entry, slapi_int_compute_output_ber );
1241 if ( rc == 1 ) break;
1245 * Technically we shouldn't be returning operational attributes
1246 * when the user requested only user attributes. We'll let the
1247 * plugin decide whether to be naughty or not.
1249 rc = compute_evaluator( &ctx, "*",
1250 rs->sr_entry, slapi_int_compute_output_ber );
1253 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1254 send_ldap_error( op, rs, LDAP_OTHER, "computed attribute error" );
1258 #endif /* LDAP_SLAPI */
1262 slap_sl_free( e_flags, op->o_tmpmemctx );
1267 rc = ber_printf( ber, /*{{*/ "}N}" );
1270 rc = send_ldap_controls( op, ber, rs->sr_ctrls );
1274 #ifdef LDAP_CONNECTIONLESS
1275 if( op->o_conn && op->o_conn->c_is_udp ) {
1276 if ( op->o_protocol != LDAP_VERSION2 ) {
1277 rc = ber_printf( ber, /*{*/ "N}" );
1281 if ( op->o_res_ber == NULL ) {
1282 rc = ber_printf( ber, /*{*/ "N}" );
1288 LDAP_LOG( OPERATION, ERR,
1289 "send_search_entry: conn %lu ber_printf failed\n",
1290 op->o_connid, 0, 0 );
1292 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1295 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1296 send_ldap_error( op, rs, LDAP_OTHER, "encode entry end error" );
1301 if ( op->o_res_ber == NULL ) {
1302 bytes = send_ldap_ber( op->o_conn, ber );
1303 ber_free_buf( ber );
1307 LDAP_LOG( OPERATION, ERR,
1308 "send_search_entry: conn %lu ber write failed.\n",
1309 op->o_connid, 0, 0 );
1311 Debug( LDAP_DEBUG_ANY,
1312 "send_search_entry: ber write failed\n",
1321 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1322 num_bytes_sent += bytes;
1325 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1328 Statslog( LDAP_DEBUG_STATS2, "conn=%lu op=%lu ENTRY dn=\"%s\"\n",
1329 op->o_connid, op->o_opid, rs->sr_entry->e_dn, 0, 0 );
1332 LDAP_LOG( OPERATION, ENTRY,
1333 "send_search_entry: conn %lu exit.\n", op->o_connid, 0, 0 );
1335 Debug( LDAP_DEBUG_TRACE, "<= send_search_entry\n", 0, 0, 0 );
1341 /* FIXME: I think rs->sr_type should be explicitly set to
1342 * REP_SEARCH here. That's what it was when we entered this
1343 * function. send_ldap_error may have changed it, but we
1344 * should set it back so that the cleanup functions know
1345 * what they're doing.
1347 if ( op->o_tag == LDAP_REQ_SEARCH && rs->sr_type == REP_SEARCH
1349 && (rs->sr_flags & REP_ENTRY_MUSTBEFREED) )
1351 entry_free( rs->sr_entry );
1352 rs->sr_entry = NULL;
1353 rs->sr_flags &= ~REP_ENTRY_MUSTBEFREED;
1356 if ( e_flags ) slap_sl_free( e_flags, op->o_tmpmemctx );
1358 if (op->o_callback) {
1359 slap_callback *sc = op->o_callback;
1360 for ( ; op->o_callback; op->o_callback = op->o_callback->sc_next ) {
1361 if ( op->o_callback->sc_cleanup ) {
1362 op->o_callback->sc_cleanup( op, rs );
1365 op->o_callback = sc;
1371 slap_send_search_reference( Operation *op, SlapReply *rs )
1373 BerElementBuffer berbuf;
1374 BerElement *ber = (BerElement *) &berbuf;
1378 AttributeDescription *ad_ref = slap_schema.si_ad_ref;
1379 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
1381 rs->sr_type = REP_SEARCHREF;
1382 if (op->o_callback) {
1383 slap_callback *sc = op->o_callback;
1384 rc = SLAP_CB_CONTINUE;
1385 for ( ; op->o_callback; ) {
1386 if ( op->o_callback->sc_response ) {
1387 rc = op->o_callback->sc_response( op, rs );
1388 if ( rc != SLAP_CB_CONTINUE ) break;
1390 op->o_callback = op->o_callback->sc_next;
1392 op->o_callback = sc;
1393 if ( rc != SLAP_CB_CONTINUE ) goto rel;
1397 LDAP_LOG( OPERATION, ENTRY,
1398 "send_search_reference: conn %lu dn=\"%s\"\n",
1400 rs->sr_entry ? rs->sr_entry->e_name.bv_val : "(null)", 0 );
1402 Debug( LDAP_DEBUG_TRACE,
1403 "=> send_search_reference: dn=\"%s\"\n",
1404 rs->sr_entry ? rs->sr_entry->e_name.bv_val : "(null)", 0, 0 );
1407 if ( rs->sr_entry && ! access_allowed( op, rs->sr_entry,
1408 ad_entry, NULL, ACL_READ, NULL ) )
1411 LDAP_LOG( ACL, INFO,
1412 "send_search_reference: conn %lu "
1413 "access to entry %s not allowed\n",
1414 op->o_connid, rs->sr_entry->e_dn, 0 );
1416 Debug( LDAP_DEBUG_ACL,
1417 "send_search_reference: access to entry not allowed\n",
1424 if ( rs->sr_entry && ! access_allowed( op, rs->sr_entry,
1425 ad_ref, NULL, ACL_READ, NULL ) )
1428 LDAP_LOG( ACL, INFO,
1429 "send_search_reference: conn %lu access "
1430 "to reference not allowed.\n", op->o_connid, 0, 0 );
1432 Debug( LDAP_DEBUG_ACL,
1433 "send_search_reference: access "
1434 "to reference not allowed\n",
1441 #ifdef LDAP_CONTROL_X_DOMAIN_SCOPE
1442 if( op->o_domain_scope ) {
1444 LDAP_LOG( OPERATION, ERR,
1445 "send_search_reference: conn %lu domainScope control in (%s).\n",
1446 op->o_connid, rs->sr_entry->e_dn, 0 );
1448 Debug( LDAP_DEBUG_ANY,
1449 "send_search_reference: domainScope control in (%s)\n",
1450 rs->sr_entry->e_dn, 0, 0 );
1457 if( rs->sr_ref == NULL ) {
1459 LDAP_LOG( OPERATION, ERR,
1460 "send_search_reference: conn %lu null ref in (%s).\n",
1461 op->o_connid, rs->sr_entry ? rs->sr_entry->e_dn : "(null)", 0 );
1463 Debug( LDAP_DEBUG_ANY,
1464 "send_search_reference: null ref in (%s)\n",
1465 rs->sr_entry ? rs->sr_entry->e_dn : "(null)", 0, 0 );
1471 if( op->o_protocol < LDAP_VERSION3 ) {
1473 /* save the references for the result */
1474 if( rs->sr_ref[0].bv_val != NULL ) {
1475 if( value_add( &rs->sr_v2ref, rs->sr_ref ) )
1481 #ifdef LDAP_CONNECTIONLESS
1482 if( op->o_conn && op->o_conn->c_is_udp ) {
1483 ber = op->o_res_ber;
1487 ber_init_w_nullc( ber, LBER_USE_DER );
1488 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
1491 rc = ber_printf( ber, "{it{W}" /*"}"*/ , op->o_msgid,
1492 LDAP_RES_SEARCH_REFERENCE, rs->sr_ref );
1495 rc = send_ldap_controls( op, ber, rs->sr_ctrls );
1499 rc = ber_printf( ber, /*"{"*/ "N}" );
1504 LDAP_LOG( OPERATION, ERR,
1505 "send_search_reference: conn %lu "
1506 "ber_printf failed.\n", op->o_connid, 0, 0 );
1508 Debug( LDAP_DEBUG_ANY,
1509 "send_search_reference: ber_printf failed\n", 0, 0, 0 );
1512 #ifdef LDAP_CONNECTIONLESS
1513 if (!op->o_conn || op->o_conn->c_is_udp == 0)
1515 ber_free_buf( ber );
1516 send_ldap_error( op, rs, LDAP_OTHER, "encode DN error" );
1520 #ifdef LDAP_CONNECTIONLESS
1521 if (!op->o_conn || op->o_conn->c_is_udp == 0) {
1523 bytes = send_ldap_ber( op->o_conn, ber );
1524 ber_free_buf( ber );
1526 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1527 num_bytes_sent += bytes;
1530 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1531 #ifdef LDAP_CONNECTIONLESS
1535 Statslog( LDAP_DEBUG_STATS2, "conn=%lu op=%lu REF dn=\"%s\"\n",
1536 op->o_connid, op->o_opid, rs->sr_entry ? rs->sr_entry->e_dn : "(null)", 0, 0 );
1539 LDAP_LOG( OPERATION, ENTRY,
1540 "send_search_reference: conn %lu exit.\n", op->o_connid, 0, 0 );
1542 Debug( LDAP_DEBUG_TRACE, "<= send_search_reference\n", 0, 0, 0 );
1546 if (op->o_callback) {
1547 slap_callback *sc = op->o_callback;
1548 for ( ; op->o_callback; op->o_callback = op->o_callback->sc_next ) {
1549 if ( op->o_callback->sc_cleanup ) {
1550 op->o_callback->sc_cleanup( op, rs );
1553 op->o_callback = sc;
1569 *code = LDAP_SUCCESS;
1573 if ( strncasecmp( s, "RESULT", 6 ) != 0 ) {
1575 LDAP_LOG( OPERATION, INFO,
1576 "str2result: (%s), expecting \"RESULT\"\n", s, 0, 0 );
1578 Debug( LDAP_DEBUG_ANY, "str2result (%s) expecting \"RESULT\"\n",
1586 while ( (s = strchr( s, '\n' )) != NULL ) {
1591 if ( (c = strchr( s, ':' )) != NULL ) {
1595 if ( strncasecmp( s, "code", 4 ) == 0 ) {
1599 } else if ( strncasecmp( s, "matched", 7 ) == 0 ) {
1603 } else if ( strncasecmp( s, "info", 4 ) == 0 ) {
1609 LDAP_LOG( OPERATION, INFO, "str2result: (%s) unknown.\n", s, 0, 0 );
1611 Debug( LDAP_DEBUG_ANY, "str2result (%s) unknown\n",
1622 int slap_read_controls(
1626 const struct berval *oid,
1627 LDAPControl **ctrl )
1631 BerElementBuffer berbuf;
1632 BerElement *ber = (BerElement *) &berbuf;
1638 LDAP_LOG( OPERATION, INFO, "slap_read_controls: (%s) %s\n",
1639 oid->bv_val, e->e_dn, 0 );
1641 Debug( LDAP_DEBUG_ANY, "slap_read_controls: (%s) %s\n",
1642 oid->bv_val, e->e_dn, 0 );
1646 rs->sr_attrs = ( oid == &slap_pre_read_bv ) ?
1647 op->o_preread_attrs : op->o_postread_attrs;
1649 entry_flatsize( rs->sr_entry, &siz, &len, 0 );
1650 bv.bv_len = siz + len;
1651 bv.bv_val = op->o_tmpalloc(bv.bv_len, op->o_tmpmemctx );
1653 ber_init2( ber, &bv, LBER_USE_DER );
1654 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
1656 /* create new operation */
1659 myop.o_res_ber = ber;
1661 rc = slap_send_search_entry( &myop, rs );
1664 rc = ber_flatten2( ber, &c.ldctl_value, 0 );
1666 if( rc == LBER_ERROR ) return LDAP_OTHER;
1668 c.ldctl_oid = oid->bv_val;
1669 c.ldctl_iscritical = 0;
1671 *ctrl = slap_sl_calloc( 1, sizeof(LDAPControl), NULL );
1673 return LDAP_SUCCESS;
1676 /* Map API errors to protocol errors... */
1678 slap_map_api2result( SlapReply *rs )
1680 switch(rs->sr_err) {
1681 case LDAP_SERVER_DOWN:
1682 return LDAP_UNAVAILABLE;
1683 case LDAP_LOCAL_ERROR:
1685 case LDAP_ENCODING_ERROR:
1686 case LDAP_DECODING_ERROR:
1687 return LDAP_PROTOCOL_ERROR;
1689 return LDAP_UNAVAILABLE;
1690 case LDAP_AUTH_UNKNOWN:
1691 return LDAP_AUTH_METHOD_NOT_SUPPORTED;
1692 case LDAP_FILTER_ERROR:
1693 rs->sr_text = "Filter error";
1695 case LDAP_USER_CANCELLED:
1696 rs->sr_text = "User cancelled";
1698 case LDAP_PARAM_ERROR:
1699 return LDAP_PROTOCOL_ERROR;
1700 case LDAP_NO_MEMORY:
1702 case LDAP_CONNECT_ERROR:
1703 return LDAP_UNAVAILABLE;
1704 case LDAP_NOT_SUPPORTED:
1705 return LDAP_UNWILLING_TO_PERFORM;
1706 case LDAP_CONTROL_NOT_FOUND:
1707 return LDAP_PROTOCOL_ERROR;
1708 case LDAP_NO_RESULTS_RETURNED:
1709 return LDAP_NO_SUCH_OBJECT;
1710 case LDAP_MORE_RESULTS_TO_RETURN:
1711 rs->sr_text = "More results to return";
1713 case LDAP_CLIENT_LOOP:
1714 case LDAP_REFERRAL_LIMIT_EXCEEDED:
1715 return LDAP_LOOP_DETECT;
1717 if ( LDAP_API_ERROR(rs->sr_err) ) return LDAP_OTHER;