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-2005 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;
481 if ( op->o_callback ) {
483 slap_callback *sc = op->o_callback, *sc_next;
485 for ( sc_next = op->o_callback; sc_next; op->o_callback = sc_next) {
486 sc_next = op->o_callback->sc_next;
487 if ( op->o_callback->sc_cleanup ) {
488 (void)op->o_callback->sc_cleanup( op, rs );
489 if ( first && op->o_callback != sc ) {
498 if ( rs->sr_matched && rs->sr_flags & REP_MATCHED_MUSTBEFREED ) {
499 free( (char *)rs->sr_matched );
500 rs->sr_matched = NULL;
503 if ( rs->sr_ref && rs->sr_flags & REP_REF_MUSTBEFREED ) {
504 ber_bvarray_free( rs->sr_ref );
513 send_ldap_disconnect( Operation *op, SlapReply *rs )
515 #define LDAP_UNSOLICITED_ERROR(e) \
516 ( (e) == LDAP_PROTOCOL_ERROR \
517 || (e) == LDAP_STRONG_AUTH_REQUIRED \
518 || (e) == LDAP_UNAVAILABLE )
520 assert( LDAP_UNSOLICITED_ERROR( rs->sr_err ) );
522 rs->sr_type = REP_EXTENDED;
525 LDAP_LOG( OPERATION, ENTRY,
526 "send_ldap_disconnect: conn %lu %d:%s\n",
527 op->o_connid, rs->sr_err, rs->sr_text ? rs->sr_text : "" );
529 Debug( LDAP_DEBUG_TRACE,
530 "send_ldap_disconnect %d:%s\n",
531 rs->sr_err, rs->sr_text ? rs->sr_text : "", NULL );
534 if ( op->o_protocol < LDAP_VERSION3 ) {
535 rs->sr_rspoid = NULL;
536 rs->sr_tag = req2res( op->o_tag );
537 rs->sr_msgid = (rs->sr_tag != LBER_SEQUENCE) ? op->o_msgid : 0;
540 rs->sr_rspoid = LDAP_NOTICE_DISCONNECT;
541 rs->sr_tag = LDAP_RES_EXTENDED;
545 if ( send_ldap_response( op, rs ) == SLAP_CB_CONTINUE ) {
546 Statslog( LDAP_DEBUG_STATS,
547 "conn=%lu op=%lu DISCONNECT tag=%lu err=%d text=%s\n",
548 op->o_connid, op->o_opid, rs->sr_tag, rs->sr_err,
549 rs->sr_text ? rs->sr_text : "" );
554 slap_send_ldap_result( Operation *op, SlapReply *rs )
557 const char *otext = rs->sr_text;
558 BerVarray oref = rs->sr_ref;
560 rs->sr_type = REP_RESULT;
562 assert( !LDAP_API_ERROR( rs->sr_err ));
565 LDAP_LOG( OPERATION, ENTRY,
566 "send_ldap_result: conn=%lu op=%lu p=%d\n",
567 op->o_connid, op->o_opid, op->o_protocol );
569 Debug( LDAP_DEBUG_TRACE,
570 "send_ldap_result: conn=%lu op=%lu p=%d\n",
571 op->o_connid, op->o_opid, op->o_protocol );
575 LDAP_LOG( OPERATION, ARGS,
576 "send_ldap_result: err=%d matched=\"%s\" text=\"%s\"\n",
577 rs->sr_err, rs->sr_matched ? rs->sr_matched : "",
578 rs->sr_text ? rs->sr_text : "" );
580 Debug( LDAP_DEBUG_ARGS,
581 "send_ldap_result: err=%d matched=\"%s\" text=\"%s\"\n",
582 rs->sr_err, rs->sr_matched ? rs->sr_matched : "",
583 rs->sr_text ? rs->sr_text : "" );
589 LDAP_LOG( OPERATION, ARGS,
590 "send_ldap_result: referral=\"%s\"\n",
591 rs->sr_ref[0].bv_val ? rs->sr_ref[0].bv_val : "NULL", 0, 0 );
593 Debug( LDAP_DEBUG_ARGS,
594 "send_ldap_result: referral=\"%s\"\n",
595 rs->sr_ref[0].bv_val ? rs->sr_ref[0].bv_val : "NULL",
600 assert( rs->sr_err != LDAP_PARTIAL_RESULTS );
602 if ( rs->sr_err == LDAP_REFERRAL ) {
603 #ifdef LDAP_CONTROL_X_DOMAIN_SCOPE
604 if( op->o_domain_scope ) {
608 if( rs->sr_ref == NULL ) {
609 rs->sr_err = LDAP_NO_SUCH_OBJECT;
610 } else if ( op->o_protocol < LDAP_VERSION3 ) {
611 rs->sr_err = LDAP_PARTIAL_RESULTS;
617 * Call pre-result plugins. To avoid infinite recursion plugins
618 * should just set SLAPI_RESULT_CODE rather than sending a
619 * result if they wish to change the result.
621 if ( op->o_callback == NULL && op->o_pb != NULL ) {
622 slapi_int_pblock_set_operation( op->o_pb, op );
623 slapi_pblock_set( op->o_pb, SLAPI_RESULT_CODE,
624 (void *)rs->sr_err );
625 slapi_pblock_set( op->o_pb, SLAPI_RESULT_TEXT,
626 (void *)rs->sr_text );
627 slapi_pblock_set( op->o_pb, SLAPI_RESULT_MATCHED,
628 (void *)rs->sr_matched );
630 (void) slapi_int_call_plugins( op->o_bd, SLAPI_PLUGIN_PRE_RESULT_FN,
633 #endif /* LDAP_SLAPI */
635 if ( op->o_protocol < LDAP_VERSION3 ) {
636 tmp = v2ref( rs->sr_ref, rs->sr_text );
641 rs->sr_tag = req2res( op->o_tag );
642 rs->sr_msgid = (rs->sr_tag != LBER_SEQUENCE) ? op->o_msgid : 0;
644 if ( send_ldap_response( op, rs ) == SLAP_CB_CONTINUE ) {
645 if ( op->o_tag == LDAP_REQ_SEARCH ) {
647 snprintf( nbuf, sizeof nbuf, "%d nentries=%d",
648 rs->sr_err, rs->sr_nentries );
650 Statslog( LDAP_DEBUG_STATS,
651 "conn=%lu op=%lu SEARCH RESULT tag=%lu err=%s text=%s\n",
652 op->o_connid, op->o_opid, rs->sr_tag, nbuf,
653 rs->sr_text ? rs->sr_text : "" );
655 Statslog( LDAP_DEBUG_STATS,
656 "conn=%lu op=%lu RESULT tag=%lu err=%d text=%s\n",
657 op->o_connid, op->o_opid, rs->sr_tag, rs->sr_err,
658 rs->sr_text ? rs->sr_text : "" );
662 if( tmp != NULL ) ch_free(tmp);
668 send_ldap_sasl( Operation *op, SlapReply *rs )
670 rs->sr_type = REP_SASL;
672 LDAP_LOG( OPERATION, ENTRY,
673 "send_ldap_sasl: conn %lu err=%d len=%lu\n",
674 op->o_connid, rs->sr_err,
675 rs->sr_sasldata ? rs->sr_sasldata->bv_len : -1 );
677 Debug( LDAP_DEBUG_TRACE, "send_ldap_sasl: err=%d len=%ld\n",
679 rs->sr_sasldata ? (long) rs->sr_sasldata->bv_len : -1, NULL );
682 rs->sr_tag = req2res( op->o_tag );
683 rs->sr_msgid = (rs->sr_tag != LBER_SEQUENCE) ? op->o_msgid : 0;
685 send_ldap_response( op, rs );
689 slap_send_ldap_extended( Operation *op, SlapReply *rs )
691 rs->sr_type = REP_EXTENDED;
694 LDAP_LOG( OPERATION, ENTRY,
695 "send_ldap_extended: err=%d oid=%s len=%ld\n",
696 rs->sr_err, rs->sr_rspoid ? rs->sr_rspoid : "",
697 rs->sr_rspdata != NULL ? rs->sr_rspdata->bv_len : 0 );
699 Debug( LDAP_DEBUG_TRACE,
700 "send_ldap_extended: err=%d oid=%s len=%ld\n",
702 rs->sr_rspoid ? rs->sr_rspoid : "",
703 rs->sr_rspdata != NULL ? rs->sr_rspdata->bv_len : 0 );
706 rs->sr_tag = req2res( op->o_tag );
707 rs->sr_msgid = (rs->sr_tag != LBER_SEQUENCE) ? op->o_msgid : 0;
709 send_ldap_response( op, rs );
713 slap_send_ldap_intermediate( Operation *op, SlapReply *rs )
715 rs->sr_type = REP_INTERMEDIATE;
717 LDAP_LOG( OPERATION, ENTRY,
718 "send_ldap_intermediate: err=%d oid=%s len=%ld\n",
719 rs->sr_err, rs->sr_rspoid ? rs->sr_rspoid : "",
720 rs->sr_rspdata != NULL ? rs->sr_rspdata->bv_len : 0 );
722 Debug( LDAP_DEBUG_TRACE,
723 "send_ldap_intermediate: err=%d oid=%s len=%ld\n",
725 rs->sr_rspoid ? rs->sr_rspoid : "",
726 rs->sr_rspdata != NULL ? rs->sr_rspdata->bv_len : 0 );
728 rs->sr_tag = LDAP_RES_INTERMEDIATE;
729 rs->sr_msgid = op->o_msgid;
730 send_ldap_response( op, rs );
734 slap_send_search_entry( Operation *op, SlapReply *rs )
736 BerElementBuffer berbuf;
737 BerElement *ber = (BerElement *) &berbuf;
739 int i, j, rc=-1, bytes;
743 AccessControlState acl_state = ACL_STATE_INIT;
745 /* Support for computed attribute plugins */
746 computed_attr_context ctx;
749 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
751 /* a_flags: array of flags telling if the i-th element will be
752 * returned or filtered out
753 * e_flags: array of a_flags
755 char **e_flags = NULL;
757 rs->sr_type = REP_SEARCH;
758 if (op->o_callback) {
759 slap_callback *sc = op->o_callback;
760 rc = SLAP_CB_CONTINUE;
761 for ( ; op->o_callback; ) {
762 if ( op->o_callback->sc_response ) {
763 rc = op->o_callback->sc_response( op, rs );
764 if ( rc != SLAP_CB_CONTINUE ) break;
766 op->o_callback = op->o_callback->sc_next;
769 if ( rc != SLAP_CB_CONTINUE ) goto error_return;
773 LDAP_LOG( OPERATION, ENTRY, "send_search_entry: conn %lu dn=\"%s\"%s\n",
774 op->o_connid, rs->sr_entry->e_name.bv_val,
775 op->ors_attrsonly ? " (attrsOnly)" : "" );
777 Debug( LDAP_DEBUG_TRACE, "=> send_search_entry: dn=\"%s\"%s\n",
778 rs->sr_entry->e_name.bv_val,
779 op->ors_attrsonly ? " (attrsOnly)" : "", 0 );
782 if ( !access_allowed( op, rs->sr_entry, ad_entry, NULL, ACL_READ, NULL )) {
785 "send_search_entry: conn %lu access to entry (%s) not allowed\n",
786 op->o_connid, rs->sr_entry->e_name.bv_val, 0 );
788 Debug( LDAP_DEBUG_ACL,
789 "send_search_entry: access to entry not allowed\n",
797 edn = rs->sr_entry->e_nname.bv_val;
799 if ( op->o_res_ber ) {
800 /* read back control or LDAP_CONNECTIONLESS */
806 entry_flatsize( rs->sr_entry, &siz, &len, 0 );
807 bv.bv_len = siz + len;
808 bv.bv_val = op->o_tmpalloc(bv.bv_len, op->o_tmpmemctx );
810 ber_init2( ber, &bv, LBER_USE_DER );
811 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
814 #ifdef LDAP_CONNECTIONLESS
815 if ( op->o_conn && op->o_conn->c_is_udp ) {
817 if ( op->o_protocol == LDAP_VERSION2 ) {
818 rc = ber_printf(ber, "t{O{" /*}}*/,
819 LDAP_RES_SEARCH_ENTRY, &rs->sr_entry->e_name );
821 rc = ber_printf( ber, "{it{O{" /*}}}*/, op->o_msgid,
822 LDAP_RES_SEARCH_ENTRY, &rs->sr_entry->e_name );
826 if ( op->o_res_ber ) {
827 /* read back control */
828 rc = ber_printf( ber, "{O{" /*}}*/, &rs->sr_entry->e_name );
830 rc = ber_printf( ber, "{it{O{" /*}}}*/, op->o_msgid,
831 LDAP_RES_SEARCH_ENTRY, &rs->sr_entry->e_name );
836 LDAP_LOG( OPERATION, ERR,
837 "send_search_entry: conn %lu ber_printf failed\n",
838 op->o_connid, 0, 0 );
840 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
843 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
844 send_ldap_error( op, rs, LDAP_OTHER, "encoding DN error" );
848 /* check for special all user attributes ("*") type */
849 userattrs = ( rs->sr_attrs == NULL ) ? 1
850 : an_find( rs->sr_attrs, &AllUser );
852 /* check for special all operational attributes ("+") type */
853 opattrs = ( rs->sr_attrs == NULL ) ? 0
854 : an_find( rs->sr_attrs, &AllOper );
856 /* create an array of arrays of flags. Each flag corresponds
857 * to particular value of attribute and equals 1 if value matches
858 * to ValuesReturnFilter or 0 if not
860 if ( op->o_vrFilter != NULL ) {
864 for ( a = rs->sr_entry->e_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
865 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ ) k++;
868 size = i * sizeof(char *) + k;
871 e_flags = sl_calloc ( 1, i * sizeof(char *) + k, op->o_tmpmemctx );
872 if( e_flags == NULL ) {
874 LDAP_LOG( OPERATION, ERR,
875 "send_search_entry: conn %lu sl_calloc failed\n",
876 op->o_connid ? op->o_connid : 0, 0, 0 );
878 Debug( LDAP_DEBUG_ANY,
879 "send_search_entry: sl_calloc failed\n", 0, 0, 0 );
883 send_ldap_error( op, rs, LDAP_OTHER, "out of memory" );
886 a_flags = (char *)(e_flags + i);
887 memset( a_flags, 0, k );
888 for ( a=rs->sr_entry->e_attrs, i=0; a != NULL; a=a->a_next, i++ ) {
889 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ );
890 e_flags[i] = a_flags;
894 rc = filter_matched_values(op, rs->sr_entry->e_attrs, &e_flags) ;
897 LDAP_LOG( OPERATION, ERR, "send_search_entry: "
898 "conn %lu matched values filtering failed\n",
899 op->o_connid ? op->o_connid : 0, 0, 0 );
901 Debug( LDAP_DEBUG_ANY,
902 "matched values filtering failed\n", 0, 0, 0 );
904 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
905 send_ldap_error( op, rs, LDAP_OTHER,
906 "matched values filtering error" );
912 for ( a = rs->sr_entry->e_attrs, j = 0; a != NULL; a = a->a_next, j++ ) {
913 AttributeDescription *desc = a->a_desc;
916 if ( rs->sr_attrs == NULL ) {
917 /* all attrs request, skip operational attributes */
918 if( is_at_operational( desc->ad_type ) ) {
923 /* specific attrs requested */
924 if ( is_at_operational( desc->ad_type ) ) {
925 if( !opattrs && !ad_inlist( desc, rs->sr_attrs ) ) {
930 if (!userattrs && !ad_inlist( desc, rs->sr_attrs ) ) {
936 if ( op->ors_attrsonly ) {
937 if ( ! access_allowed( op, rs->sr_entry, desc, NULL,
938 ACL_READ, &acl_state ) )
942 "send_search_entry: conn %lu access to attribute %s not "
943 "allowed\n", op->o_connid, desc->ad_cname.bv_val, 0 );
945 Debug( LDAP_DEBUG_ACL, "send_search_entry: "
946 "conn %lu access to attribute %s not allowed\n",
947 op->o_connid, desc->ad_cname.bv_val, 0 );
952 if (( rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname )) == -1 ) {
954 LDAP_LOG( OPERATION, ERR,
955 "send_search_entry: conn %lu ber_printf failed\n",
956 op->o_connid, 0, 0 );
958 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
961 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
962 send_ldap_error( op, rs, LDAP_OTHER,
963 "encoding description error");
970 for ( i = 0; a->a_nvals[i].bv_val != NULL; i++ ) {
971 if ( ! access_allowed( op, rs->sr_entry,
972 desc, &a->a_nvals[i], ACL_READ, &acl_state ) )
976 "send_search_entry: conn %lu "
977 "access to attribute %s, value #%d not allowed\n",
978 op->o_connid, desc->ad_cname.bv_val, i );
980 Debug( LDAP_DEBUG_ACL,
981 "send_search_entry: conn %lu "
982 "access to attribute %s, value #%d not allowed\n",
983 op->o_connid, desc->ad_cname.bv_val, i );
989 if ( op->o_vrFilter && e_flags[j][i] == 0 ){
996 if (( rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname )) == -1 ) {
998 LDAP_LOG( OPERATION, ERR,
999 "send_search_entry: conn %lu ber_printf failed\n",
1000 op->o_connid, 0, 0 );
1002 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1005 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1006 send_ldap_error( op, rs, LDAP_OTHER,
1007 "encoding description error");
1011 if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
1013 LDAP_LOG( OPERATION, ERR,
1014 "send_search_entry: conn %lu "
1015 "ber_printf failed.\n", op->o_connid, 0, 0 );
1017 Debug( LDAP_DEBUG_ANY,
1018 "ber_printf failed\n", 0, 0, 0 );
1021 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1022 send_ldap_error( op, rs, LDAP_OTHER,
1023 "encoding values error" );
1029 if ( finish && ( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
1031 LDAP_LOG( OPERATION, ERR,
1032 "send_search_entry: conn %lu ber_printf failed\n",
1033 op->o_connid, 0, 0 );
1035 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1038 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1039 send_ldap_error( op, rs, LDAP_OTHER, "encode end error" );
1044 /* eventually will loop through generated operational attributes */
1045 /* only have subschemaSubentry and numSubordinates are implemented */
1046 aa = backend_operational( op, rs, opattrs );
1048 if ( aa != NULL && op->o_vrFilter != NULL ) {
1052 for ( a = aa, i=0; a != NULL; a = a->a_next, i++ ) {
1053 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ ) k++;
1056 size = i * sizeof(char *) + k;
1058 char *a_flags, **tmp;
1061 * Reuse previous memory - we likely need less space
1062 * for operational attributes
1064 tmp = sl_realloc( e_flags, i * sizeof(char *) + k,
1066 if ( tmp == NULL ) {
1068 LDAP_LOG( OPERATION, ERR,
1069 "send_search_entry: conn %lu "
1070 "not enough memory "
1071 "for matched values filtering\n",
1072 op->o_connid, 0, 0);
1074 Debug( LDAP_DEBUG_ANY,
1075 "send_search_entry: conn %lu "
1076 "not enough memory "
1077 "for matched values filtering\n",
1078 op->o_connid, 0, 0 );
1080 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1081 send_ldap_error( op, rs, LDAP_OTHER,
1082 "not enough memory for matched values filtering" );
1086 a_flags = (char *)(e_flags + i);
1087 memset( a_flags, 0, k );
1088 for ( a = aa, i=0; a != NULL; a = a->a_next, i++ ) {
1089 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ );
1090 e_flags[i] = a_flags;
1093 rc = filter_matched_values(op, aa, &e_flags) ;
1097 LDAP_LOG( OPERATION, ERR,
1098 "send_search_entry: conn %lu "
1099 "matched values filtering failed\n",
1100 op->o_connid ? op->o_connid : 0, 0, 0);
1102 Debug( LDAP_DEBUG_ANY,
1103 "matched values filtering failed\n", 0, 0, 0 );
1105 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1106 send_ldap_error( op, rs, LDAP_OTHER,
1107 "matched values filtering error" );
1113 for (a = aa, j=0; a != NULL; a = a->a_next, j++ ) {
1114 AttributeDescription *desc = a->a_desc;
1116 if ( rs->sr_attrs == NULL ) {
1117 /* all attrs request, skip operational attributes */
1118 if( is_at_operational( desc->ad_type ) ) {
1123 /* specific attrs requested */
1124 if( is_at_operational( desc->ad_type ) ) {
1125 if( !opattrs && !ad_inlist( desc, rs->sr_attrs ) ) {
1129 if (!userattrs && !ad_inlist( desc, rs->sr_attrs ) ) {
1135 if ( ! access_allowed( op, rs->sr_entry, desc, NULL,
1136 ACL_READ, &acl_state ) )
1139 LDAP_LOG( ACL, INFO,
1140 "send_search_entry: conn %lu "
1141 "access to attribute %s not allowed\n",
1142 op->o_connid, desc->ad_cname.bv_val, 0 );
1144 Debug( LDAP_DEBUG_ACL,
1145 "send_search_entry: conn %lu "
1146 "access to attribute %s not allowed\n",
1147 op->o_connid, desc->ad_cname.bv_val, 0 );
1153 rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname );
1156 LDAP_LOG( OPERATION, ERR,
1157 "send_search_entry: conn %lu "
1158 "ber_printf failed\n", op->o_connid, 0, 0 );
1160 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1163 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1164 send_ldap_error( op, rs, LDAP_OTHER,
1165 "encoding description error" );
1170 if ( ! op->ors_attrsonly ) {
1171 for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
1172 if ( ! access_allowed( op, rs->sr_entry,
1173 desc, &a->a_vals[i], ACL_READ, &acl_state ) )
1176 LDAP_LOG( ACL, INFO,
1177 "send_search_entry: conn %lu "
1178 "access to %s, value %d not allowed\n",
1179 op->o_connid, desc->ad_cname.bv_val, i );
1181 Debug( LDAP_DEBUG_ACL,
1182 "send_search_entry: access to attribute %s, "
1183 "value %d not allowed\n",
1184 desc->ad_cname.bv_val, i, 0 );
1190 if ( op->o_vrFilter && e_flags[j][i] == 0 ){
1194 if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
1196 LDAP_LOG( OPERATION, ERR,
1197 "send_search_entry: conn %lu ber_printf failed\n",
1198 op->o_connid, 0, 0 );
1200 Debug( LDAP_DEBUG_ANY,
1201 "ber_printf failed\n", 0, 0, 0 );
1204 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1205 send_ldap_error( op, rs, LDAP_OTHER,
1206 "encoding values error" );
1213 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
1215 LDAP_LOG( OPERATION, ERR,
1216 "send_search_entry: conn %lu ber_printf failed\n",
1217 op->o_connid, 0, 0 );
1219 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1222 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1223 send_ldap_error( op, rs, LDAP_OTHER, "encode end error" );
1231 * First, setup the computed attribute context that is
1232 * passed to all plugins.
1235 ctx.cac_pb = op->o_pb;
1236 ctx.cac_attrs = rs->sr_attrs;
1237 ctx.cac_attrsonly = op->ors_attrsonly;
1238 ctx.cac_userattrs = userattrs;
1239 ctx.cac_opattrs = opattrs;
1240 ctx.cac_acl_state = acl_state;
1241 ctx.cac_private = (void *)ber;
1244 * For each client requested attribute, call the plugins.
1246 if ( rs->sr_attrs != NULL ) {
1247 for ( anp = rs->sr_attrs; anp->an_name.bv_val != NULL; anp++ ) {
1248 rc = compute_evaluator( &ctx, anp->an_name.bv_val,
1249 rs->sr_entry, slapi_int_compute_output_ber );
1250 if ( rc == 1 ) break;
1254 * Technically we shouldn't be returning operational attributes
1255 * when the user requested only user attributes. We'll let the
1256 * plugin decide whether to be naughty or not.
1258 rc = compute_evaluator( &ctx, "*",
1259 rs->sr_entry, slapi_int_compute_output_ber );
1262 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1263 send_ldap_error( op, rs, LDAP_OTHER, "computed attribute error" );
1267 #endif /* LDAP_SLAPI */
1271 sl_free( e_flags, op->o_tmpmemctx );
1276 rc = ber_printf( ber, /*{{*/ "}N}" );
1279 rc = send_ldap_controls( op, ber, rs->sr_ctrls );
1283 #ifdef LDAP_CONNECTIONLESS
1284 if( op->o_conn && op->o_conn->c_is_udp ) {
1285 if ( op->o_protocol != LDAP_VERSION2 ) {
1286 rc = ber_printf( ber, /*{*/ "N}" );
1290 if ( op->o_res_ber == NULL ) {
1291 rc = ber_printf( ber, /*{*/ "N}" );
1297 LDAP_LOG( OPERATION, ERR,
1298 "send_search_entry: conn %lu ber_printf failed\n",
1299 op->o_connid, 0, 0 );
1301 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1304 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1305 send_ldap_error( op, rs, LDAP_OTHER, "encode entry end error" );
1310 if ( op->o_res_ber == NULL ) {
1311 bytes = send_ldap_ber( op->o_conn, ber );
1312 ber_free_buf( ber );
1316 LDAP_LOG( OPERATION, ERR,
1317 "send_search_entry: conn %lu ber write failed.\n",
1318 op->o_connid, 0, 0 );
1320 Debug( LDAP_DEBUG_ANY,
1321 "send_search_entry: ber write failed\n",
1330 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1331 num_bytes_sent += bytes;
1334 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1337 Statslog( LDAP_DEBUG_STATS2, "conn=%lu op=%lu ENTRY dn=\"%s\"\n",
1338 op->o_connid, op->o_opid, rs->sr_entry->e_dn, 0, 0 );
1341 LDAP_LOG( OPERATION, ENTRY,
1342 "send_search_entry: conn %lu exit.\n", op->o_connid, 0, 0 );
1344 Debug( LDAP_DEBUG_TRACE, "<= send_search_entry\n", 0, 0, 0 );
1350 if ( op->o_callback ) {
1352 slap_callback *sc = op->o_callback, *sc_next;
1354 for ( sc_next = op->o_callback; sc_next; op->o_callback = sc_next) {
1355 sc_next = op->o_callback->sc_next;
1356 if ( op->o_callback->sc_cleanup ) {
1357 (void)op->o_callback->sc_cleanup( op, rs );
1358 if ( first && op->o_callback != sc ) {
1359 sc = op->o_callback;
1364 op->o_callback = sc;
1368 slap_sl_free( e_flags, op->o_tmpmemctx );
1371 /* FIXME: I think rs->sr_type should be explicitly set to
1372 * REP_SEARCH here. That's what it was when we entered this
1373 * function. send_ldap_error may have changed it, but we
1374 * should set it back so that the cleanup functions know
1375 * what they're doing.
1377 if ( op->o_tag == LDAP_REQ_SEARCH && rs->sr_type == REP_SEARCH
1379 && (rs->sr_flags & REP_ENTRY_MUSTBEFREED) )
1381 entry_free( rs->sr_entry );
1382 rs->sr_entry = NULL;
1383 rs->sr_flags &= ~REP_ENTRY_MUSTBEFREED;
1390 slap_send_search_reference( Operation *op, SlapReply *rs )
1392 BerElementBuffer berbuf;
1393 BerElement *ber = (BerElement *) &berbuf;
1397 AttributeDescription *ad_ref = slap_schema.si_ad_ref;
1398 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
1400 rs->sr_type = REP_SEARCHREF;
1401 if (op->o_callback) {
1402 slap_callback *sc = op->o_callback;
1403 rc = SLAP_CB_CONTINUE;
1404 for ( ; op->o_callback; ) {
1405 if ( op->o_callback->sc_response ) {
1406 rc = op->o_callback->sc_response( op, rs );
1407 if ( rc != SLAP_CB_CONTINUE ) break;
1409 op->o_callback = op->o_callback->sc_next;
1411 op->o_callback = sc;
1412 if ( rc != SLAP_CB_CONTINUE ) goto rel;
1416 LDAP_LOG( OPERATION, ENTRY,
1417 "send_search_reference: conn %lu dn=\"%s\"\n",
1419 rs->sr_entry ? rs->sr_entry->e_name.bv_val : "(null)", 0 );
1421 Debug( LDAP_DEBUG_TRACE,
1422 "=> send_search_reference: dn=\"%s\"\n",
1423 rs->sr_entry ? rs->sr_entry->e_name.bv_val : "(null)", 0, 0 );
1426 if ( rs->sr_entry && ! access_allowed( op, rs->sr_entry,
1427 ad_entry, NULL, ACL_READ, NULL ) )
1430 LDAP_LOG( ACL, INFO,
1431 "send_search_reference: conn %lu "
1432 "access to entry %s not allowed\n",
1433 op->o_connid, rs->sr_entry->e_dn, 0 );
1435 Debug( LDAP_DEBUG_ACL,
1436 "send_search_reference: access to entry not allowed\n",
1443 if ( rs->sr_entry && ! access_allowed( op, rs->sr_entry,
1444 ad_ref, NULL, ACL_READ, NULL ) )
1447 LDAP_LOG( ACL, INFO,
1448 "send_search_reference: conn %lu access "
1449 "to reference not allowed.\n", op->o_connid, 0, 0 );
1451 Debug( LDAP_DEBUG_ACL,
1452 "send_search_reference: access "
1453 "to reference not allowed\n",
1460 #ifdef LDAP_CONTROL_X_DOMAIN_SCOPE
1461 if( op->o_domain_scope ) {
1463 LDAP_LOG( OPERATION, ERR,
1464 "send_search_reference: conn %lu domainScope control in (%s).\n",
1465 op->o_connid, rs->sr_entry->e_dn, 0 );
1467 Debug( LDAP_DEBUG_ANY,
1468 "send_search_reference: domainScope control in (%s)\n",
1469 rs->sr_entry->e_dn, 0, 0 );
1476 if( rs->sr_ref == NULL ) {
1478 LDAP_LOG( OPERATION, ERR,
1479 "send_search_reference: conn %lu null ref in (%s).\n",
1480 op->o_connid, rs->sr_entry ? rs->sr_entry->e_dn : "(null)", 0 );
1482 Debug( LDAP_DEBUG_ANY,
1483 "send_search_reference: null ref in (%s)\n",
1484 rs->sr_entry ? rs->sr_entry->e_dn : "(null)", 0, 0 );
1490 if( op->o_protocol < LDAP_VERSION3 ) {
1492 /* save the references for the result */
1493 if( rs->sr_ref[0].bv_val != NULL ) {
1494 if( value_add( &rs->sr_v2ref, rs->sr_ref ) )
1500 #ifdef LDAP_CONNECTIONLESS
1501 if( op->o_conn && op->o_conn->c_is_udp ) {
1502 ber = op->o_res_ber;
1506 ber_init_w_nullc( ber, LBER_USE_DER );
1507 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
1510 rc = ber_printf( ber, "{it{W}" /*"}"*/ , op->o_msgid,
1511 LDAP_RES_SEARCH_REFERENCE, rs->sr_ref );
1514 rc = send_ldap_controls( op, ber, rs->sr_ctrls );
1518 rc = ber_printf( ber, /*"{"*/ "N}" );
1523 LDAP_LOG( OPERATION, ERR,
1524 "send_search_reference: conn %lu "
1525 "ber_printf failed.\n", op->o_connid, 0, 0 );
1527 Debug( LDAP_DEBUG_ANY,
1528 "send_search_reference: ber_printf failed\n", 0, 0, 0 );
1531 #ifdef LDAP_CONNECTIONLESS
1532 if (!op->o_conn || op->o_conn->c_is_udp == 0)
1534 ber_free_buf( ber );
1535 send_ldap_error( op, rs, LDAP_OTHER, "encode DN error" );
1540 #ifdef LDAP_CONNECTIONLESS
1541 if (!op->o_conn || op->o_conn->c_is_udp == 0) {
1543 bytes = send_ldap_ber( op->o_conn, ber );
1544 ber_free_buf( ber );
1546 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1547 num_bytes_sent += bytes;
1550 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1551 #ifdef LDAP_CONNECTIONLESS
1555 Statslog( LDAP_DEBUG_STATS2, "conn=%lu op=%lu REF dn=\"%s\"\n",
1556 op->o_connid, op->o_opid, rs->sr_entry ? rs->sr_entry->e_dn : "(null)", 0, 0 );
1559 LDAP_LOG( OPERATION, ENTRY,
1560 "send_search_reference: conn %lu exit.\n", op->o_connid, 0, 0 );
1562 Debug( LDAP_DEBUG_TRACE, "<= send_search_reference\n", 0, 0, 0 );
1566 if ( op->o_callback ) {
1568 slap_callback *sc = op->o_callback, *sc_next;
1570 for ( sc_next = op->o_callback; sc_next; op->o_callback = sc_next ) {
1571 sc_next = op->o_callback->sc_next;
1572 if ( op->o_callback->sc_cleanup ) {
1573 (void)op->o_callback->sc_cleanup( op, rs );
1574 if ( first && op->o_callback != sc ) {
1575 sc = op->o_callback;
1580 op->o_callback = sc;
1596 *code = LDAP_SUCCESS;
1600 if ( strncasecmp( s, "RESULT", 6 ) != 0 ) {
1602 LDAP_LOG( OPERATION, INFO,
1603 "str2result: (%s), expecting \"RESULT\"\n", s, 0, 0 );
1605 Debug( LDAP_DEBUG_ANY, "str2result (%s) expecting \"RESULT\"\n",
1613 while ( (s = strchr( s, '\n' )) != NULL ) {
1618 if ( (c = strchr( s, ':' )) != NULL ) {
1622 if ( strncasecmp( s, "code", 4 ) == 0 ) {
1626 } else if ( strncasecmp( s, "matched", 7 ) == 0 ) {
1630 } else if ( strncasecmp( s, "info", 4 ) == 0 ) {
1636 LDAP_LOG( OPERATION, INFO, "str2result: (%s) unknown.\n", s, 0, 0 );
1638 Debug( LDAP_DEBUG_ANY, "str2result (%s) unknown\n",
1649 int slap_read_controls(
1653 const struct berval *oid,
1654 LDAPControl **ctrl )
1658 BerElementBuffer berbuf;
1659 BerElement *ber = (BerElement *) &berbuf;
1665 LDAP_LOG( OPERATION, INFO, "slap_read_controls: (%s) %s\n",
1666 oid->bv_val, e->e_dn, 0 );
1668 Debug( LDAP_DEBUG_ANY, "slap_read_controls: (%s) %s\n",
1669 oid->bv_val, e->e_dn, 0 );
1673 rs->sr_attrs = ( oid == &slap_pre_read_bv ) ?
1674 op->o_preread_attrs : op->o_postread_attrs;
1676 entry_flatsize( rs->sr_entry, &siz, &len, 0 );
1677 bv.bv_len = siz + len;
1678 bv.bv_val = op->o_tmpalloc(bv.bv_len, op->o_tmpmemctx );
1680 ber_init2( ber, &bv, LBER_USE_DER );
1681 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
1683 /* create new operation */
1686 myop.o_res_ber = ber;
1688 rc = slap_send_search_entry( &myop, rs );
1691 rc = ber_flatten2( ber, &c.ldctl_value, 0 );
1693 if( rc == LBER_ERROR ) return LDAP_OTHER;
1695 c.ldctl_oid = oid->bv_val;
1696 c.ldctl_iscritical = 0;
1698 if ( ctrl == NULL ) {
1700 *ctrl = (LDAPControl *) sl_calloc( 1, sizeof(LDAPControl), NULL );
1702 /* retry: free previous try */
1703 slap_sl_free( (*ctrl)->ldctl_value.bv_val, &op->o_tmpmemctx );
1707 return LDAP_SUCCESS;
1710 /* Map API errors to protocol errors... */
1712 slap_map_api2result( SlapReply *rs )
1714 switch(rs->sr_err) {
1715 case LDAP_SERVER_DOWN:
1716 return LDAP_UNAVAILABLE;
1717 case LDAP_LOCAL_ERROR:
1719 case LDAP_ENCODING_ERROR:
1720 case LDAP_DECODING_ERROR:
1721 return LDAP_PROTOCOL_ERROR;
1723 return LDAP_UNAVAILABLE;
1724 case LDAP_AUTH_UNKNOWN:
1725 return LDAP_AUTH_METHOD_NOT_SUPPORTED;
1726 case LDAP_FILTER_ERROR:
1727 rs->sr_text = "Filter error";
1729 case LDAP_USER_CANCELLED:
1730 rs->sr_text = "User cancelled";
1732 case LDAP_PARAM_ERROR:
1733 return LDAP_PROTOCOL_ERROR;
1734 case LDAP_NO_MEMORY:
1736 case LDAP_CONNECT_ERROR:
1737 return LDAP_UNAVAILABLE;
1738 case LDAP_NOT_SUPPORTED:
1739 return LDAP_UNWILLING_TO_PERFORM;
1740 case LDAP_CONTROL_NOT_FOUND:
1741 return LDAP_PROTOCOL_ERROR;
1742 case LDAP_NO_RESULTS_RETURNED:
1743 return LDAP_NO_SUCH_OBJECT;
1744 case LDAP_MORE_RESULTS_TO_RETURN:
1745 rs->sr_text = "More results to return";
1747 case LDAP_CLIENT_LOOP:
1748 case LDAP_REFERRAL_LIMIT_EXCEEDED:
1749 return LDAP_LOOP_DETECT;
1751 if ( LDAP_API_ERROR(rs->sr_err) ) return LDAP_OTHER;