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_freeself_cb( Operation *op, SlapReply *rs )
51 assert( op->o_callback );
53 op->o_tmpfree( op->o_callback, op->o_tmpmemctx );
54 op->o_callback = NULL;
56 return SLAP_CB_CONTINUE;
59 int slap_replog_cb( Operation *op, SlapReply *rs )
61 if ( rs->sr_err == LDAP_SUCCESS ) {
64 return SLAP_CB_CONTINUE;
67 static char *v2ref( BerVarray ref, const char *text )
69 size_t len = 0, i = 0;
74 return ch_strdup(text);
82 if (text[len-1] != '\n') {
87 v2 = SLAP_MALLOC( len+i+sizeof("Referral:") );
90 LDAP_LOG( OPERATION, ERR, "v2ref: SLAP_MALLOC failed", 0, 0, 0 );
92 Debug( LDAP_DEBUG_ANY, "v2ref: SLAP_MALLOC failed", 0, 0, 0 );
103 strcpy( v2+len, "Referral:" );
104 len += sizeof("Referral:");
106 for( i=0; ref[i].bv_val != NULL; i++ ) {
107 v2 = SLAP_REALLOC( v2, len + ref[i].bv_len + 1 );
110 LDAP_LOG( OPERATION, ERR, "v2ref: SLAP_MALLOC failed", 0, 0, 0 );
112 Debug( LDAP_DEBUG_ANY, "v2ref: SLAP_MALLOC failed", 0, 0, 0 );
117 AC_MEMCPY(&v2[len], ref[i].bv_val, ref[i].bv_len );
118 len += ref[i].bv_len;
119 if (ref[i].bv_val[ref[i].bv_len-1] != '/') {
128 static ber_tag_t req2res( ber_tag_t tag )
133 case LDAP_REQ_COMPARE:
134 case LDAP_REQ_EXTENDED:
135 case LDAP_REQ_MODIFY:
136 case LDAP_REQ_MODRDN:
140 case LDAP_REQ_DELETE:
141 tag = LDAP_RES_DELETE;
144 case LDAP_REQ_ABANDON:
145 case LDAP_REQ_UNBIND:
149 case LDAP_REQ_SEARCH:
150 tag = LDAP_RES_SEARCH_RESULT;
160 static long send_ldap_ber(
166 ber_get_option( ber, LBER_OPT_BER_BYTES_TO_WRITE, &bytes );
168 /* write only one pdu at a time - wait til it's our turn */
169 ldap_pvt_thread_mutex_lock( &conn->c_write_mutex );
171 /* lock the connection */
172 ldap_pvt_thread_mutex_lock( &conn->c_mutex );
179 if ( connection_state_closing( conn ) ) {
180 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
181 ldap_pvt_thread_mutex_unlock( &conn->c_write_mutex );
186 if ( ber_flush( conn->c_sb, ber, 0 ) == 0 ) {
193 * we got an error. if it's ewouldblock, we need to
194 * wait on the socket being writable. otherwise, figure
195 * it's a hard error and return.
199 LDAP_LOG( OPERATION, ERR,
200 "send_ldap_ber: conn %lu ber_flush failed err=%d (%s)\n",
201 conn ? conn->c_connid : 0, err, sock_errstr(err) );
203 Debug( LDAP_DEBUG_CONNS, "ber_flush failed errno=%d reason=\"%s\"\n",
204 err, sock_errstr(err), 0 );
207 if ( err != EWOULDBLOCK && err != EAGAIN ) {
208 connection_closing( conn );
210 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
211 ldap_pvt_thread_mutex_unlock( &conn->c_write_mutex );
216 /* wait for socket to be write-ready */
217 conn->c_writewaiter = 1;
218 ber_sockbuf_ctrl( conn->c_sb, LBER_SB_OPT_GET_FD, &sd );
219 slapd_set_write( sd, 1 );
221 ldap_pvt_thread_cond_wait( &conn->c_write_cv, &conn->c_mutex );
222 conn->c_writewaiter = 0;
225 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
226 ldap_pvt_thread_mutex_unlock( &conn->c_write_mutex );
232 send_ldap_control( BerElement *ber, LDAPControl *c )
238 rc = ber_printf( ber, "{s" /*}*/, c->ldctl_oid );
240 if( c->ldctl_iscritical ) {
241 rc = ber_printf( ber, "b",
242 (ber_int_t) c->ldctl_iscritical ) ;
243 if( rc == -1 ) return rc;
246 if( c->ldctl_value.bv_val != NULL ) {
247 rc = ber_printf( ber, "O", &c->ldctl_value );
248 if( rc == -1 ) return rc;
251 rc = ber_printf( ber, /*{*/"N}" );
252 if( rc == -1 ) return rc;
258 send_ldap_controls( Operation *o, BerElement *ber, LDAPControl **c )
262 LDAPControl **sctrls = NULL;
265 * Retrieve any additional controls that may be set by the
269 if ( o->o_pb && slapi_pblock_get( o->o_pb, SLAPI_RESCONTROLS, &sctrls ) != 0 ) {
273 if ( c == NULL && sctrls == NULL ) return 0;
275 if( c == NULL ) return 0;
276 #endif /* LDAP_SLAPI */
278 rc = ber_printf( ber, "t{"/*}*/, LDAP_TAG_CONTROLS );
279 if( rc == -1 ) return rc;
283 #endif /* LDAP_SLAPI */
284 for( ; *c != NULL; c++) {
285 rc = send_ldap_control( ber, *c );
286 if( rc == -1 ) return rc;
290 if ( sctrls != NULL ) {
291 for ( c = sctrls; *c != NULL; c++ ) {
292 rc = send_ldap_control( ber, *c );
293 if( rc == -1 ) return rc;
296 #endif /* LDAP_SLAPI */
298 rc = ber_printf( ber, /*{*/"N}" );
308 BerElementBuffer berbuf;
309 BerElement *ber = (BerElement *) &berbuf;
310 int rc = LDAP_SUCCESS;
313 if ( op->o_callback ) {
315 slap_callback *sc = op->o_callback,
316 *sc_next = op->o_callback;
318 rc = SLAP_CB_CONTINUE;
319 for ( sc_next = op->o_callback; sc_next; op->o_callback = sc_next) {
320 sc_next = op->o_callback->sc_next;
321 if ( op->o_callback->sc_response ) {
322 rc = op->o_callback->sc_response( op, rs );
323 if ( first && op->o_callback == NULL ) {
326 if ( rc != SLAP_CB_CONTINUE ) break;
332 if ( rc != SLAP_CB_CONTINUE ) goto clean2;
335 #ifdef LDAP_CONNECTIONLESS
336 if (op->o_conn && op->o_conn->c_is_udp)
341 ber_init_w_nullc( ber, LBER_USE_DER );
342 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
346 LDAP_LOG( OPERATION, ENTRY,
347 "send_ldap_response: msgid=%d tag=%lu err=%d\n",
348 rs->sr_msgid, rs->sr_tag, rs->sr_err );
350 Debug( LDAP_DEBUG_TRACE,
351 "send_ldap_response: msgid=%d tag=%lu err=%d\n",
352 rs->sr_msgid, rs->sr_tag, rs->sr_err );
357 LDAP_LOG( OPERATION, ARGS,
358 "send_ldap_response: conn %lu ref=\"%s\"\n",
360 rs->sr_ref[0].bv_val ? rs->sr_ref[0].bv_val : "NULL" , 0 );
362 Debug( LDAP_DEBUG_ARGS, "send_ldap_response: ref=\"%s\"\n",
363 rs->sr_ref[0].bv_val ? rs->sr_ref[0].bv_val : "NULL",
368 #ifdef LDAP_CONNECTIONLESS
369 if (op->o_conn && op->o_conn->c_is_udp &&
370 op->o_protocol == LDAP_VERSION2 )
372 rc = ber_printf( ber, "t{ess" /*"}"*/,
373 rs->sr_tag, rs->sr_err,
374 rs->sr_matched == NULL ? "" : rs->sr_matched,
375 rs->sr_text == NULL ? "" : rs->sr_text );
378 if ( rs->sr_type == REP_INTERMEDIATE ) {
379 rc = ber_printf( ber, "{it{" /*"}}"*/,
380 rs->sr_msgid, rs->sr_tag );
383 rc = ber_printf( ber, "{it{ess" /*"}}"*/,
384 rs->sr_msgid, rs->sr_tag, rs->sr_err,
385 rs->sr_matched == NULL ? "" : rs->sr_matched,
386 rs->sr_text == NULL ? "" : rs->sr_text );
390 if ( rs->sr_ref != NULL ) {
391 assert( rs->sr_err == LDAP_REFERRAL );
392 rc = ber_printf( ber, "t{W}",
393 LDAP_TAG_REFERRAL, rs->sr_ref );
395 assert( rs->sr_err != LDAP_REFERRAL );
399 if( rc != -1 && rs->sr_type == REP_SASL && rs->sr_sasldata != NULL ) {
400 rc = ber_printf( ber, "tO",
401 LDAP_TAG_SASL_RES_CREDS, rs->sr_sasldata );
405 ( rs->sr_type == REP_EXTENDED || rs->sr_type == REP_INTERMEDIATE ))
407 if ( rs->sr_rspoid != NULL ) {
408 rc = ber_printf( ber, "ts",
409 LDAP_TAG_EXOP_RES_OID, rs->sr_rspoid );
411 if( rc != -1 && rs->sr_rspdata != NULL ) {
412 rc = ber_printf( ber, "tO",
413 LDAP_TAG_EXOP_RES_VALUE, rs->sr_rspdata );
418 rc = ber_printf( ber, /*"{"*/ "N}" );
422 rc = send_ldap_controls( op, ber, rs->sr_ctrls );
426 rc = ber_printf( ber, /*"{"*/ "N}" );
429 #ifdef LDAP_CONNECTIONLESS
430 if( op->o_conn && op->o_conn->c_is_udp && op->o_protocol == LDAP_VERSION2
433 rc = ber_printf( ber, /*"{"*/ "N}" );
439 LDAP_LOG( OPERATION, ERR,
440 "send_ldap_response: conn %lu ber_printf failed\n",
441 op->o_connid, 0, 0 );
443 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
446 #ifdef LDAP_CONNECTIONLESS
447 if (!op->o_conn || op->o_conn->c_is_udp == 0)
456 bytes = send_ldap_ber( op->o_conn, ber );
457 #ifdef LDAP_CONNECTIONLESS
458 if (!op->o_conn || op->o_conn->c_is_udp == 0)
466 LDAP_LOG( OPERATION, ERR,
467 "send_ldap_response: conn %lu ber write failed\n",
468 op->o_connid ? op->o_connid : 0, 0, 0 );
470 Debug( LDAP_DEBUG_ANY,
471 "send_ldap_response: ber write failed\n",
480 slapi_pblock_set( op->o_pb, SLAPI_RESULT_CODE, (void *)rs->sr_err );
481 slapi_pblock_set( op->o_pb, SLAPI_RESULT_MATCHED,
482 (void *)rs->sr_matched );
483 slapi_pblock_set( op->o_pb, SLAPI_RESULT_TEXT, (void *)rs->sr_text );
485 #endif /* LDAP_SLAPI */
487 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
488 num_bytes_sent += bytes;
490 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
493 /* Tell caller that we did this for real, as opposed to being
494 * overridden by a callback
496 rc = SLAP_CB_CONTINUE;
499 if ( op->o_callback ) {
501 slap_callback *sc = op->o_callback,
502 *sc_next = op->o_callback;
504 for ( sc_next = op->o_callback; sc_next; op->o_callback = sc_next) {
505 sc_next = op->o_callback->sc_next;
506 if ( op->o_callback->sc_cleanup ) {
507 (void)op->o_callback->sc_cleanup( op, rs );
508 if ( first && op->o_callback == NULL ) {
519 if ( rs->sr_matched && rs->sr_flags & REP_MATCHED_MUSTBEFREED ) {
520 free( (char *)rs->sr_matched );
521 rs->sr_matched = NULL;
524 if ( rs->sr_ref && rs->sr_flags & REP_REF_MUSTBEFREED ) {
525 ber_bvarray_free( rs->sr_ref );
534 send_ldap_disconnect( Operation *op, SlapReply *rs )
536 #define LDAP_UNSOLICITED_ERROR(e) \
537 ( (e) == LDAP_PROTOCOL_ERROR \
538 || (e) == LDAP_STRONG_AUTH_REQUIRED \
539 || (e) == LDAP_UNAVAILABLE )
541 assert( LDAP_UNSOLICITED_ERROR( rs->sr_err ) );
543 rs->sr_type = REP_EXTENDED;
546 LDAP_LOG( OPERATION, ENTRY,
547 "send_ldap_disconnect: conn %lu %d:%s\n",
548 op->o_connid, rs->sr_err, rs->sr_text ? rs->sr_text : "" );
550 Debug( LDAP_DEBUG_TRACE,
551 "send_ldap_disconnect %d:%s\n",
552 rs->sr_err, rs->sr_text ? rs->sr_text : "", NULL );
555 if ( op->o_protocol < LDAP_VERSION3 ) {
556 rs->sr_rspoid = NULL;
557 rs->sr_tag = req2res( op->o_tag );
558 rs->sr_msgid = (rs->sr_tag != LBER_SEQUENCE) ? op->o_msgid : 0;
561 rs->sr_rspoid = LDAP_NOTICE_DISCONNECT;
562 rs->sr_tag = LDAP_RES_EXTENDED;
566 if ( send_ldap_response( op, rs ) == SLAP_CB_CONTINUE ) {
567 Statslog( LDAP_DEBUG_STATS,
568 "conn=%lu op=%lu DISCONNECT tag=%lu err=%d text=%s\n",
569 op->o_connid, op->o_opid, rs->sr_tag, rs->sr_err,
570 rs->sr_text ? rs->sr_text : "" );
575 slap_send_ldap_result( Operation *op, SlapReply *rs )
578 const char *otext = rs->sr_text;
579 BerVarray oref = rs->sr_ref;
581 rs->sr_type = REP_RESULT;
583 assert( !LDAP_API_ERROR( rs->sr_err ));
586 LDAP_LOG( OPERATION, ENTRY,
587 "send_ldap_result: conn=%lu op=%lu p=%d\n",
588 op->o_connid, op->o_opid, op->o_protocol );
590 Debug( LDAP_DEBUG_TRACE,
591 "send_ldap_result: conn=%lu op=%lu p=%d\n",
592 op->o_connid, op->o_opid, op->o_protocol );
596 LDAP_LOG( OPERATION, ARGS,
597 "send_ldap_result: err=%d matched=\"%s\" text=\"%s\"\n",
598 rs->sr_err, rs->sr_matched ? rs->sr_matched : "",
599 rs->sr_text ? rs->sr_text : "" );
601 Debug( LDAP_DEBUG_ARGS,
602 "send_ldap_result: err=%d matched=\"%s\" text=\"%s\"\n",
603 rs->sr_err, rs->sr_matched ? rs->sr_matched : "",
604 rs->sr_text ? rs->sr_text : "" );
610 LDAP_LOG( OPERATION, ARGS,
611 "send_ldap_result: referral=\"%s\"\n",
612 rs->sr_ref[0].bv_val ? rs->sr_ref[0].bv_val : "NULL", 0, 0 );
614 Debug( LDAP_DEBUG_ARGS,
615 "send_ldap_result: referral=\"%s\"\n",
616 rs->sr_ref[0].bv_val ? rs->sr_ref[0].bv_val : "NULL",
621 assert( rs->sr_err != LDAP_PARTIAL_RESULTS );
623 if ( rs->sr_err == LDAP_REFERRAL ) {
624 #ifdef LDAP_CONTROL_X_DOMAIN_SCOPE
625 if( op->o_domain_scope ) {
629 if( rs->sr_ref == NULL ) {
630 rs->sr_err = LDAP_NO_SUCH_OBJECT;
631 } else if ( op->o_protocol < LDAP_VERSION3 ) {
632 rs->sr_err = LDAP_PARTIAL_RESULTS;
638 * Call pre-result plugins. To avoid infinite recursion plugins
639 * should just set SLAPI_RESULT_CODE rather than sending a
640 * result if they wish to change the result.
642 if ( op->o_pb != NULL ) {
643 slapi_int_pblock_set_operation( op->o_pb, op );
644 slapi_pblock_set( op->o_pb, SLAPI_RESULT_CODE,
645 (void *)rs->sr_err );
646 slapi_pblock_set( op->o_pb, SLAPI_RESULT_TEXT,
647 (void *)rs->sr_text );
648 slapi_pblock_set( op->o_pb, SLAPI_RESULT_MATCHED,
649 (void *)rs->sr_matched );
651 (void) slapi_int_call_plugins( op->o_bd, SLAPI_PLUGIN_PRE_RESULT_FN,
654 #endif /* LDAP_SLAPI */
656 if ( op->o_protocol < LDAP_VERSION3 ) {
657 tmp = v2ref( rs->sr_ref, rs->sr_text );
662 rs->sr_tag = req2res( op->o_tag );
663 rs->sr_msgid = (rs->sr_tag != LBER_SEQUENCE) ? op->o_msgid : 0;
665 if ( send_ldap_response( op, rs ) == SLAP_CB_CONTINUE ) {
666 if ( op->o_tag == LDAP_REQ_SEARCH ) {
668 snprintf( nbuf, sizeof nbuf, "%d nentries=%d",
669 rs->sr_err, rs->sr_nentries );
671 Statslog( LDAP_DEBUG_STATS,
672 "conn=%lu op=%lu SEARCH RESULT tag=%lu err=%s text=%s\n",
673 op->o_connid, op->o_opid, rs->sr_tag, nbuf,
674 rs->sr_text ? rs->sr_text : "" );
676 Statslog( LDAP_DEBUG_STATS,
677 "conn=%lu op=%lu RESULT tag=%lu err=%d text=%s\n",
678 op->o_connid, op->o_opid, rs->sr_tag, rs->sr_err,
679 rs->sr_text ? rs->sr_text : "" );
683 if( tmp != NULL ) ch_free(tmp);
689 send_ldap_sasl( Operation *op, SlapReply *rs )
691 rs->sr_type = REP_SASL;
693 LDAP_LOG( OPERATION, ENTRY,
694 "send_ldap_sasl: conn %lu err=%d len=%lu\n",
695 op->o_connid, rs->sr_err,
696 rs->sr_sasldata ? rs->sr_sasldata->bv_len : -1 );
698 Debug( LDAP_DEBUG_TRACE, "send_ldap_sasl: err=%d len=%ld\n",
700 rs->sr_sasldata ? (long) rs->sr_sasldata->bv_len : -1, NULL );
703 rs->sr_tag = req2res( op->o_tag );
704 rs->sr_msgid = (rs->sr_tag != LBER_SEQUENCE) ? op->o_msgid : 0;
706 send_ldap_response( op, rs );
710 slap_send_ldap_extended( Operation *op, SlapReply *rs )
712 rs->sr_type = REP_EXTENDED;
715 LDAP_LOG( OPERATION, ENTRY,
716 "send_ldap_extended: err=%d oid=%s len=%ld\n",
717 rs->sr_err, rs->sr_rspoid ? rs->sr_rspoid : "",
718 rs->sr_rspdata != NULL ? rs->sr_rspdata->bv_len : 0 );
720 Debug( LDAP_DEBUG_TRACE,
721 "send_ldap_extended: err=%d oid=%s len=%ld\n",
723 rs->sr_rspoid ? rs->sr_rspoid : "",
724 rs->sr_rspdata != NULL ? rs->sr_rspdata->bv_len : 0 );
727 rs->sr_tag = req2res( op->o_tag );
728 rs->sr_msgid = (rs->sr_tag != LBER_SEQUENCE) ? op->o_msgid : 0;
730 send_ldap_response( op, rs );
734 slap_send_ldap_intermediate( Operation *op, SlapReply *rs )
736 rs->sr_type = REP_INTERMEDIATE;
738 LDAP_LOG( OPERATION, ENTRY,
739 "send_ldap_intermediate: err=%d oid=%s len=%ld\n",
740 rs->sr_err, rs->sr_rspoid ? rs->sr_rspoid : "",
741 rs->sr_rspdata != NULL ? rs->sr_rspdata->bv_len : 0 );
743 Debug( LDAP_DEBUG_TRACE,
744 "send_ldap_intermediate: err=%d oid=%s len=%ld\n",
746 rs->sr_rspoid ? rs->sr_rspoid : "",
747 rs->sr_rspdata != NULL ? rs->sr_rspdata->bv_len : 0 );
749 rs->sr_tag = LDAP_RES_INTERMEDIATE;
750 rs->sr_msgid = op->o_msgid;
751 send_ldap_response( op, rs );
755 slap_send_search_entry( Operation *op, SlapReply *rs )
757 BerElementBuffer berbuf;
758 BerElement *ber = (BerElement *) &berbuf;
759 Attribute *a, *aa = NULL;
760 int i, j, rc=-1, bytes;
764 AccessControlState acl_state = ACL_STATE_INIT;
766 /* Support for computed attribute plugins */
767 computed_attr_context ctx;
770 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
772 /* a_flags: array of flags telling if the i-th element will be
773 * returned or filtered out
774 * e_flags: array of a_flags
776 char **e_flags = NULL;
778 /* eventually will loop through generated operational attributes */
779 /* only subschemaSubentry and numSubordinates are implemented */
780 /* NOTE: moved before overlays callback circling because
781 * they may modify entry and other stuff in rs */
782 /* check for special all operational attributes ("+") type */
783 opattrs = ( rs->sr_attrs == NULL ) ? 0
784 : an_find( rs->sr_attrs, &AllOper );
786 aa = backend_operational( op, rs, opattrs );
788 rs->sr_type = REP_SEARCH;
789 if ( op->o_callback ) {
791 slap_callback *sc = op->o_callback,
792 *sc_next = op->o_callback;
794 rc = SLAP_CB_CONTINUE;
795 for ( sc_next = op->o_callback; sc_next; op->o_callback = sc_next) {
796 sc_next = op->o_callback->sc_next;
797 if ( op->o_callback->sc_response ) {
798 rc = op->o_callback->sc_response( op, rs );
799 if ( first && op->o_callback == NULL ) {
802 if ( rc != SLAP_CB_CONTINUE ) break;
808 if ( rc != SLAP_CB_CONTINUE ) goto error_return;
812 LDAP_LOG( OPERATION, ENTRY, "send_search_entry: conn %lu dn=\"%s\"%s\n",
813 op->o_connid, rs->sr_entry->e_name.bv_val,
814 op->ors_attrsonly ? " (attrsOnly)" : "" );
816 Debug( LDAP_DEBUG_TRACE, "=> send_search_entry: conn %lu dn=\"%s\"%s\n",
817 op->o_connid, rs->sr_entry->e_name.bv_val,
818 op->ors_attrsonly ? " (attrsOnly)" : "" );
821 if ( !access_allowed( op, rs->sr_entry, ad_entry, NULL, ACL_READ, NULL )) {
824 "send_search_entry: conn %lu access to entry (%s) not allowed\n",
825 op->o_connid, rs->sr_entry->e_name.bv_val, 0 );
827 Debug( LDAP_DEBUG_ACL,
828 "send_search_entry: conn %lu access to entry (%s) not allowed\n",
829 op->o_connid, rs->sr_entry->e_name.bv_val, 0 );
836 edn = rs->sr_entry->e_nname.bv_val;
838 if ( op->o_res_ber ) {
839 /* read back control or LDAP_CONNECTIONLESS */
845 entry_flatsize( rs->sr_entry, &siz, &len, 0 );
846 bv.bv_len = siz + len;
847 bv.bv_val = op->o_tmpalloc(bv.bv_len, op->o_tmpmemctx );
849 ber_init2( ber, &bv, LBER_USE_DER );
850 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
853 #ifdef LDAP_CONNECTIONLESS
854 if ( op->o_conn && op->o_conn->c_is_udp ) {
856 if ( op->o_protocol == LDAP_VERSION2 ) {
857 rc = ber_printf(ber, "t{O{" /*}}*/,
858 LDAP_RES_SEARCH_ENTRY, &rs->sr_entry->e_name );
860 rc = ber_printf( ber, "{it{O{" /*}}}*/, op->o_msgid,
861 LDAP_RES_SEARCH_ENTRY, &rs->sr_entry->e_name );
865 if ( op->o_res_ber ) {
866 /* read back control */
867 rc = ber_printf( ber, "{O{" /*}}*/, &rs->sr_entry->e_name );
869 rc = ber_printf( ber, "{it{O{" /*}}}*/, op->o_msgid,
870 LDAP_RES_SEARCH_ENTRY, &rs->sr_entry->e_name );
875 LDAP_LOG( OPERATION, ERR,
876 "send_search_entry: conn %lu ber_printf failed\n",
877 op->o_connid, 0, 0 );
879 Debug( LDAP_DEBUG_ANY,
880 "send_search_entry: conn %lu ber_printf failed\n",
881 op->o_connid, 0, 0 );
884 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
885 send_ldap_error( op, rs, LDAP_OTHER, "encoding DN error" );
889 /* check for special all user attributes ("*") type */
890 userattrs = ( rs->sr_attrs == NULL ) ? 1
891 : an_find( rs->sr_attrs, &AllUser );
893 /* create an array of arrays of flags. Each flag corresponds
894 * to particular value of attribute and equals 1 if value matches
895 * to ValuesReturnFilter or 0 if not
897 if ( op->o_vrFilter != NULL ) {
901 for ( a = rs->sr_entry->e_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
902 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ ) k++;
905 size = i * sizeof(char *) + k;
908 e_flags = slap_sl_calloc ( 1, i * sizeof(char *) + k, op->o_tmpmemctx );
909 if( e_flags == NULL ) {
911 LDAP_LOG( OPERATION, ERR,
912 "send_search_entry: conn %lu slap_sl_calloc failed\n",
913 op->o_connid ? op->o_connid : 0, 0, 0 );
915 Debug( LDAP_DEBUG_ANY,
916 "send_search_entry: conn %lu slap_sl_calloc failed\n",
917 op->o_connid ? op->o_connid : 0, 0, 0 );
921 send_ldap_error( op, rs, LDAP_OTHER, "out of memory" );
924 a_flags = (char *)(e_flags + i);
925 memset( a_flags, 0, k );
926 for ( a=rs->sr_entry->e_attrs, i=0; a != NULL; a=a->a_next, i++ ) {
927 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ );
928 e_flags[i] = a_flags;
932 rc = filter_matched_values(op, rs->sr_entry->e_attrs, &e_flags) ;
935 LDAP_LOG( OPERATION, ERR, "send_search_entry: "
936 "conn %lu matched values filtering failed\n",
937 op->o_connid ? op->o_connid : 0, 0, 0 );
939 Debug( LDAP_DEBUG_ANY, "send_search_entry: "
940 "conn %lu matched values filtering failed\n",
941 op->o_connid ? op->o_connid : 0, 0, 0 );
943 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
944 send_ldap_error( op, rs, LDAP_OTHER,
945 "matched values filtering error" );
951 for ( a = rs->sr_entry->e_attrs, j = 0; a != NULL; a = a->a_next, j++ ) {
952 AttributeDescription *desc = a->a_desc;
955 if ( rs->sr_attrs == NULL ) {
956 /* all attrs request, skip operational attributes */
957 if( is_at_operational( desc->ad_type ) ) {
962 /* specific attrs requested */
963 if ( is_at_operational( desc->ad_type ) ) {
964 if( !opattrs && !ad_inlist( desc, rs->sr_attrs ) ) {
969 if (!userattrs && !ad_inlist( desc, rs->sr_attrs ) ) {
975 if ( op->ors_attrsonly ) {
976 if ( ! access_allowed( op, rs->sr_entry, desc, NULL,
977 ACL_READ, &acl_state ) )
981 "send_search_entry: conn %lu access to attribute %s not "
982 "allowed\n", op->o_connid, desc->ad_cname.bv_val, 0 );
984 Debug( LDAP_DEBUG_ACL, "send_search_entry: "
985 "conn %lu access to attribute %s not allowed\n",
986 op->o_connid, desc->ad_cname.bv_val, 0 );
991 if (( rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname )) == -1 ) {
993 LDAP_LOG( OPERATION, ERR,
994 "send_search_entry: conn %lu ber_printf failed\n",
995 op->o_connid, 0, 0 );
997 Debug( LDAP_DEBUG_ANY,
998 "send_search_entry: conn %lu ber_printf failed\n",
999 op->o_connid, 0, 0 );
1002 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1003 send_ldap_error( op, rs, LDAP_OTHER,
1004 "encoding description error");
1011 for ( i = 0; a->a_nvals[i].bv_val != NULL; i++ ) {
1012 if ( ! access_allowed( op, rs->sr_entry,
1013 desc, &a->a_nvals[i], ACL_READ, &acl_state ) )
1016 LDAP_LOG( ACL, INFO,
1017 "send_search_entry: conn %lu "
1018 "access to attribute %s, value #%d not allowed\n",
1019 op->o_connid, desc->ad_cname.bv_val, i );
1021 Debug( LDAP_DEBUG_ACL,
1022 "send_search_entry: conn %lu "
1023 "access to attribute %s, value #%d not allowed\n",
1024 op->o_connid, desc->ad_cname.bv_val, i );
1030 if ( op->o_vrFilter && e_flags[j][i] == 0 ){
1037 if (( rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname )) == -1 ) {
1039 LDAP_LOG( OPERATION, ERR,
1040 "send_search_entry: conn %lu ber_printf failed\n",
1041 op->o_connid, 0, 0 );
1043 Debug( LDAP_DEBUG_ANY,
1044 "send_search_entry: conn %lu ber_printf failed\n",
1045 op->o_connid, 0, 0 );
1048 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1049 send_ldap_error( op, rs, LDAP_OTHER,
1050 "encoding description error");
1054 if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
1056 LDAP_LOG( OPERATION, ERR,
1057 "send_search_entry: conn %lu "
1058 "ber_printf failed.\n", op->o_connid, 0, 0 );
1060 Debug( LDAP_DEBUG_ANY,
1061 "send_search_entry: conn %lu "
1062 "ber_printf failed.\n", op->o_connid, 0, 0 );
1065 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1066 send_ldap_error( op, rs, LDAP_OTHER,
1067 "encoding values error" );
1073 if ( finish && ( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
1075 LDAP_LOG( OPERATION, ERR,
1076 "send_search_entry: conn %lu ber_printf failed\n",
1077 op->o_connid, 0, 0 );
1079 Debug( LDAP_DEBUG_ANY,
1080 "send_search_entry: conn %lu ber_printf failed\n",
1081 op->o_connid, 0, 0 );
1084 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1085 send_ldap_error( op, rs, LDAP_OTHER, "encode end error" );
1090 /* NOTE: moved before overlays callback circling because
1091 * they may modify entry and other stuff in rs */
1092 if ( aa != NULL && op->o_vrFilter != NULL ) {
1096 for ( a = aa, i=0; a != NULL; a = a->a_next, i++ ) {
1097 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ ) k++;
1100 size = i * sizeof(char *) + k;
1102 char *a_flags, **tmp;
1105 * Reuse previous memory - we likely need less space
1106 * for operational attributes
1108 tmp = slap_sl_realloc( e_flags, i * sizeof(char *) + k,
1110 if ( tmp == NULL ) {
1112 LDAP_LOG( OPERATION, ERR,
1113 "send_search_entry: conn %lu "
1114 "not enough memory "
1115 "for matched values filtering\n",
1116 op->o_connid, 0, 0);
1118 Debug( LDAP_DEBUG_ANY,
1119 "send_search_entry: conn %lu "
1120 "not enough memory "
1121 "for matched values filtering\n",
1122 op->o_connid, 0, 0 );
1124 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1125 send_ldap_error( op, rs, LDAP_OTHER,
1126 "not enough memory for matched values filtering" );
1130 a_flags = (char *)(e_flags + i);
1131 memset( a_flags, 0, k );
1132 for ( a = aa, i=0; a != NULL; a = a->a_next, i++ ) {
1133 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ );
1134 e_flags[i] = a_flags;
1137 rc = filter_matched_values(op, aa, &e_flags) ;
1141 LDAP_LOG( OPERATION, ERR,
1142 "send_search_entry: conn %lu "
1143 "matched values filtering failed\n",
1144 op->o_connid ? op->o_connid : 0, 0, 0);
1146 Debug( LDAP_DEBUG_ANY,
1147 "send_search_entry: conn %lu "
1148 "matched values filtering failed\n",
1149 op->o_connid ? op->o_connid : 0, 0, 0);
1151 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1152 send_ldap_error( op, rs, LDAP_OTHER,
1153 "matched values filtering error" );
1159 for (a = aa, j=0; a != NULL; a = a->a_next, j++ ) {
1160 AttributeDescription *desc = a->a_desc;
1162 if ( rs->sr_attrs == NULL ) {
1163 /* all attrs request, skip operational attributes */
1164 if( is_at_operational( desc->ad_type ) ) {
1169 /* specific attrs requested */
1170 if( is_at_operational( desc->ad_type ) ) {
1171 if( !opattrs && !ad_inlist( desc, rs->sr_attrs ) ) {
1175 if (!userattrs && !ad_inlist( desc, rs->sr_attrs ) ) {
1181 if ( ! access_allowed( op, rs->sr_entry, desc, NULL,
1182 ACL_READ, &acl_state ) )
1185 LDAP_LOG( ACL, INFO,
1186 "send_search_entry: conn %lu "
1187 "access to attribute %s not allowed\n",
1188 op->o_connid, desc->ad_cname.bv_val, 0 );
1190 Debug( LDAP_DEBUG_ACL,
1191 "send_search_entry: conn %lu "
1192 "access to attribute %s not allowed\n",
1193 op->o_connid, desc->ad_cname.bv_val, 0 );
1199 rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname );
1202 LDAP_LOG( OPERATION, ERR,
1203 "send_search_entry: conn %lu "
1204 "ber_printf failed\n", op->o_connid, 0, 0 );
1206 Debug( LDAP_DEBUG_ANY,
1207 "send_search_entry: conn %lu "
1208 "ber_printf failed\n", op->o_connid, 0, 0 );
1211 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1212 send_ldap_error( op, rs, LDAP_OTHER,
1213 "encoding description error" );
1217 if ( ! op->ors_attrsonly ) {
1218 for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
1219 if ( ! access_allowed( op, rs->sr_entry,
1220 desc, &a->a_vals[i], ACL_READ, &acl_state ) )
1223 LDAP_LOG( ACL, INFO,
1224 "send_search_entry: conn %lu "
1225 "access to %s, value %d not allowed\n",
1226 op->o_connid, desc->ad_cname.bv_val, i );
1228 Debug( LDAP_DEBUG_ACL,
1229 "send_search_entry: conn %lu "
1230 "access to %s, value %d not allowed\n",
1231 op->o_connid, desc->ad_cname.bv_val, i );
1237 if ( op->o_vrFilter && e_flags[j][i] == 0 ){
1241 if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
1243 LDAP_LOG( OPERATION, ERR,
1244 "send_search_entry: conn %lu ber_printf failed\n",
1245 op->o_connid, 0, 0 );
1247 Debug( LDAP_DEBUG_ANY,
1248 "send_search_entry: conn %lu ber_printf failed\n",
1249 op->o_connid, 0, 0 );
1252 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1253 send_ldap_error( op, rs, LDAP_OTHER,
1254 "encoding values error" );
1260 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
1262 LDAP_LOG( OPERATION, ERR,
1263 "send_search_entry: conn %lu ber_printf failed\n",
1264 op->o_connid, 0, 0 );
1266 Debug( LDAP_DEBUG_ANY,
1267 "send_search_entry: conn %lu ber_printf failed\n",
1268 op->o_connid, 0, 0 );
1271 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1272 send_ldap_error( op, rs, LDAP_OTHER, "encode end error" );
1279 * First, setup the computed attribute context that is
1280 * passed to all plugins.
1283 ctx.cac_pb = op->o_pb;
1284 ctx.cac_attrs = rs->sr_attrs;
1285 ctx.cac_attrsonly = op->ors_attrsonly;
1286 ctx.cac_userattrs = userattrs;
1287 ctx.cac_opattrs = opattrs;
1288 ctx.cac_acl_state = acl_state;
1289 ctx.cac_private = (void *)ber;
1292 * For each client requested attribute, call the plugins.
1294 if ( rs->sr_attrs != NULL ) {
1295 for ( anp = rs->sr_attrs; anp->an_name.bv_val != NULL; anp++ ) {
1296 rc = compute_evaluator( &ctx, anp->an_name.bv_val,
1297 rs->sr_entry, slapi_int_compute_output_ber );
1298 if ( rc == 1 ) break;
1302 * Technically we shouldn't be returning operational attributes
1303 * when the user requested only user attributes. We'll let the
1304 * plugin decide whether to be naughty or not.
1306 rc = compute_evaluator( &ctx, "*",
1307 rs->sr_entry, slapi_int_compute_output_ber );
1310 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1311 send_ldap_error( op, rs, LDAP_OTHER, "computed attribute error" );
1315 #endif /* LDAP_SLAPI */
1319 slap_sl_free( e_flags, op->o_tmpmemctx );
1323 rc = ber_printf( ber, /*{{*/ "}N}" );
1326 rc = send_ldap_controls( op, ber, rs->sr_ctrls );
1330 #ifdef LDAP_CONNECTIONLESS
1331 if( op->o_conn && op->o_conn->c_is_udp ) {
1332 if ( op->o_protocol != LDAP_VERSION2 ) {
1333 rc = ber_printf( ber, /*{*/ "N}" );
1337 if ( op->o_res_ber == NULL ) {
1338 rc = ber_printf( ber, /*{*/ "N}" );
1344 LDAP_LOG( OPERATION, ERR,
1345 "send_search_entry: conn %lu ber_printf failed\n",
1346 op->o_connid, 0, 0 );
1348 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1351 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1352 send_ldap_error( op, rs, LDAP_OTHER, "encode entry end error" );
1357 if ( op->o_res_ber == NULL ) {
1358 bytes = send_ldap_ber( op->o_conn, ber );
1359 ber_free_buf( ber );
1363 LDAP_LOG( OPERATION, ERR,
1364 "send_search_entry: conn %lu ber write failed.\n",
1365 op->o_connid, 0, 0 );
1367 Debug( LDAP_DEBUG_ANY,
1368 "send_search_entry: conn %lu ber write failed.\n",
1369 op->o_connid, 0, 0 );
1377 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1378 num_bytes_sent += bytes;
1381 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1384 Statslog( LDAP_DEBUG_STATS2, "conn=%lu op=%lu ENTRY dn=\"%s\"\n",
1385 op->o_connid, op->o_opid, rs->sr_entry->e_dn, 0, 0 );
1388 LDAP_LOG( OPERATION, ENTRY,
1389 "send_search_entry: conn %lu exit.\n", op->o_connid, 0, 0 );
1391 Debug( LDAP_DEBUG_TRACE,
1392 "<= send_search_entry: conn %lu exit.\n", op->o_connid, 0, 0 );
1399 slap_sl_free( e_flags, op->o_tmpmemctx );
1406 if ( op->o_callback ) {
1408 slap_callback *sc = op->o_callback,
1409 *sc_next = op->o_callback;
1411 for ( sc_next = op->o_callback; sc_next; op->o_callback = sc_next) {
1412 sc_next = op->o_callback->sc_next;
1413 if ( op->o_callback->sc_cleanup ) {
1414 (void)op->o_callback->sc_cleanup( op, rs );
1415 if ( first && op->o_callback == NULL ) {
1422 op->o_callback = sc;
1425 /* FIXME: I think rs->sr_type should be explicitly set to
1426 * REP_SEARCH here. That's what it was when we entered this
1427 * function. send_ldap_error may have changed it, but we
1428 * should set it back so that the cleanup functions know
1429 * what they're doing.
1431 if ( op->o_tag == LDAP_REQ_SEARCH && rs->sr_type == REP_SEARCH
1433 && ( rs->sr_flags & REP_ENTRY_MUSTBEFREED ) )
1435 entry_free( rs->sr_entry );
1436 rs->sr_entry = NULL;
1437 rs->sr_flags &= ~REP_ENTRY_MUSTBEFREED;
1444 slap_send_search_reference( Operation *op, SlapReply *rs )
1446 BerElementBuffer berbuf;
1447 BerElement *ber = (BerElement *) &berbuf;
1451 AttributeDescription *ad_ref = slap_schema.si_ad_ref;
1452 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
1454 rs->sr_type = REP_SEARCHREF;
1455 if ( op->o_callback ) {
1457 slap_callback *sc = op->o_callback,
1458 *sc_next = op->o_callback;
1460 rc = SLAP_CB_CONTINUE;
1461 for ( sc_next = op->o_callback; sc_next; op->o_callback = sc_next) {
1462 sc_next = op->o_callback->sc_next;
1463 if ( op->o_callback->sc_response ) {
1464 rc = op->o_callback->sc_response( op, rs );
1465 if ( first && op->o_callback == NULL ) {
1468 if ( rc != SLAP_CB_CONTINUE ) break;
1473 op->o_callback = sc;
1474 if ( rc != SLAP_CB_CONTINUE ) goto rel;
1478 LDAP_LOG( OPERATION, ENTRY,
1479 "send_search_reference: conn %lu dn=\"%s\"\n",
1481 rs->sr_entry ? rs->sr_entry->e_name.bv_val : "(null)", 0 );
1483 Debug( LDAP_DEBUG_TRACE,
1484 "=> send_search_reference: dn=\"%s\"\n",
1485 rs->sr_entry ? rs->sr_entry->e_name.bv_val : "(null)", 0, 0 );
1488 if ( rs->sr_entry && ! access_allowed( op, rs->sr_entry,
1489 ad_entry, NULL, ACL_READ, NULL ) )
1492 LDAP_LOG( ACL, INFO,
1493 "send_search_reference: conn %lu "
1494 "access to entry %s not allowed\n",
1495 op->o_connid, rs->sr_entry->e_dn, 0 );
1497 Debug( LDAP_DEBUG_ACL,
1498 "send_search_reference: access to entry not allowed\n",
1505 if ( rs->sr_entry && ! access_allowed( op, rs->sr_entry,
1506 ad_ref, NULL, ACL_READ, NULL ) )
1509 LDAP_LOG( ACL, INFO,
1510 "send_search_reference: conn %lu access "
1511 "to reference not allowed.\n", op->o_connid, 0, 0 );
1513 Debug( LDAP_DEBUG_ACL,
1514 "send_search_reference: access "
1515 "to reference not allowed\n",
1522 #ifdef LDAP_CONTROL_X_DOMAIN_SCOPE
1523 if( op->o_domain_scope ) {
1525 LDAP_LOG( OPERATION, ERR,
1526 "send_search_reference: conn %lu domainScope control in (%s).\n",
1527 op->o_connid, rs->sr_entry->e_dn, 0 );
1529 Debug( LDAP_DEBUG_ANY,
1530 "send_search_reference: domainScope control in (%s)\n",
1531 rs->sr_entry->e_dn, 0, 0 );
1538 if( rs->sr_ref == NULL ) {
1540 LDAP_LOG( OPERATION, ERR,
1541 "send_search_reference: conn %lu null ref in (%s).\n",
1542 op->o_connid, rs->sr_entry ? rs->sr_entry->e_dn : "(null)", 0 );
1544 Debug( LDAP_DEBUG_ANY,
1545 "send_search_reference: null ref in (%s)\n",
1546 rs->sr_entry ? rs->sr_entry->e_dn : "(null)", 0, 0 );
1552 if( op->o_protocol < LDAP_VERSION3 ) {
1554 /* save the references for the result */
1555 if( rs->sr_ref[0].bv_val != NULL ) {
1556 if( value_add( &rs->sr_v2ref, rs->sr_ref ) )
1562 #ifdef LDAP_CONNECTIONLESS
1563 if( op->o_conn && op->o_conn->c_is_udp ) {
1564 ber = op->o_res_ber;
1568 ber_init_w_nullc( ber, LBER_USE_DER );
1569 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
1572 rc = ber_printf( ber, "{it{W}" /*"}"*/ , op->o_msgid,
1573 LDAP_RES_SEARCH_REFERENCE, rs->sr_ref );
1576 rc = send_ldap_controls( op, ber, rs->sr_ctrls );
1580 rc = ber_printf( ber, /*"{"*/ "N}" );
1585 LDAP_LOG( OPERATION, ERR,
1586 "send_search_reference: conn %lu "
1587 "ber_printf failed.\n", op->o_connid, 0, 0 );
1589 Debug( LDAP_DEBUG_ANY,
1590 "send_search_reference: ber_printf failed\n", 0, 0, 0 );
1593 #ifdef LDAP_CONNECTIONLESS
1594 if (!op->o_conn || op->o_conn->c_is_udp == 0)
1596 ber_free_buf( ber );
1597 send_ldap_error( op, rs, LDAP_OTHER, "encode DN error" );
1601 #ifdef LDAP_CONNECTIONLESS
1602 if (!op->o_conn || op->o_conn->c_is_udp == 0) {
1604 bytes = send_ldap_ber( op->o_conn, ber );
1605 ber_free_buf( ber );
1607 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1608 num_bytes_sent += bytes;
1611 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1612 #ifdef LDAP_CONNECTIONLESS
1616 Statslog( LDAP_DEBUG_STATS2, "conn=%lu op=%lu REF dn=\"%s\"\n",
1617 op->o_connid, op->o_opid, rs->sr_entry ? rs->sr_entry->e_dn : "(null)", 0, 0 );
1620 LDAP_LOG( OPERATION, ENTRY,
1621 "send_search_reference: conn %lu exit.\n", op->o_connid, 0, 0 );
1623 Debug( LDAP_DEBUG_TRACE, "<= send_search_reference\n", 0, 0, 0 );
1627 if ( op->o_callback ) {
1629 slap_callback *sc = op->o_callback,
1630 *sc_next = op->o_callback;
1632 for ( sc_next = op->o_callback; sc_next; op->o_callback = sc_next) {
1633 sc_next = op->o_callback->sc_next;
1634 if ( op->o_callback->sc_cleanup ) {
1635 (void)op->o_callback->sc_cleanup( op, rs );
1636 if ( first && op->o_callback == NULL ) {
1643 op->o_callback = sc;
1660 *code = LDAP_SUCCESS;
1664 if ( strncasecmp( s, "RESULT", STRLENOF( "RESULT" ) ) != 0 ) {
1666 LDAP_LOG( OPERATION, INFO,
1667 "str2result: (%s), expecting \"RESULT\"\n", s, 0, 0 );
1669 Debug( LDAP_DEBUG_ANY, "str2result (%s) expecting \"RESULT\"\n",
1677 while ( (s = strchr( s, '\n' )) != NULL ) {
1682 if ( (c = strchr( s, ':' )) != NULL ) {
1686 if ( strncasecmp( s, "code", STRLENOF( "code" ) ) == 0 ) {
1690 } else if ( strncasecmp( s, "matched", STRLENOF( "matched" ) ) == 0 ) {
1694 } else if ( strncasecmp( s, "info", STRLENOF( "info" ) ) == 0 ) {
1700 LDAP_LOG( OPERATION, INFO, "str2result: (%s) unknown.\n", s, 0, 0 );
1702 Debug( LDAP_DEBUG_ANY, "str2result (%s) unknown\n",
1713 int slap_read_controls(
1717 const struct berval *oid,
1718 LDAPControl **ctrl )
1722 BerElementBuffer berbuf;
1723 BerElement *ber = (BerElement *) &berbuf;
1729 LDAP_LOG( OPERATION, INFO, "slap_read_controls: (%s) %s\n",
1730 oid->bv_val, e->e_dn, 0 );
1732 Debug( LDAP_DEBUG_ANY, "slap_read_controls: (%s) %s\n",
1733 oid->bv_val, e->e_dn, 0 );
1737 rs->sr_attrs = ( oid == &slap_pre_read_bv ) ?
1738 op->o_preread_attrs : op->o_postread_attrs;
1740 entry_flatsize( rs->sr_entry, &siz, &len, 0 );
1741 bv.bv_len = siz + len;
1742 bv.bv_val = op->o_tmpalloc(bv.bv_len, op->o_tmpmemctx );
1744 ber_init2( ber, &bv, LBER_USE_DER );
1745 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
1747 /* create new operation */
1750 myop.o_res_ber = ber;
1752 rc = slap_send_search_entry( &myop, rs );
1755 rc = ber_flatten2( ber, &c.ldctl_value, 0 );
1757 if( rc == LBER_ERROR ) return LDAP_OTHER;
1759 c.ldctl_oid = oid->bv_val;
1760 c.ldctl_iscritical = 0;
1762 if ( ctrl == NULL ) {
1764 *ctrl = (LDAPControl *) slap_sl_calloc( 1, sizeof(LDAPControl), NULL );
1766 /* retry: free previous try */
1767 slap_sl_free( (*ctrl)->ldctl_value.bv_val, &op->o_tmpmemctx );
1771 return LDAP_SUCCESS;
1774 /* Map API errors to protocol errors... */
1776 slap_map_api2result( SlapReply *rs )
1778 switch(rs->sr_err) {
1779 case LDAP_SERVER_DOWN:
1780 return LDAP_UNAVAILABLE;
1781 case LDAP_LOCAL_ERROR:
1783 case LDAP_ENCODING_ERROR:
1784 case LDAP_DECODING_ERROR:
1785 return LDAP_PROTOCOL_ERROR;
1787 return LDAP_UNAVAILABLE;
1788 case LDAP_AUTH_UNKNOWN:
1789 return LDAP_AUTH_METHOD_NOT_SUPPORTED;
1790 case LDAP_FILTER_ERROR:
1791 rs->sr_text = "Filter error";
1793 case LDAP_USER_CANCELLED:
1794 rs->sr_text = "User cancelled";
1796 case LDAP_PARAM_ERROR:
1797 return LDAP_PROTOCOL_ERROR;
1798 case LDAP_NO_MEMORY:
1800 case LDAP_CONNECT_ERROR:
1801 return LDAP_UNAVAILABLE;
1802 case LDAP_NOT_SUPPORTED:
1803 return LDAP_UNWILLING_TO_PERFORM;
1804 case LDAP_CONTROL_NOT_FOUND:
1805 return LDAP_PROTOCOL_ERROR;
1806 case LDAP_NO_RESULTS_RETURNED:
1807 return LDAP_NO_SUCH_OBJECT;
1808 case LDAP_MORE_RESULTS_TO_RETURN:
1809 rs->sr_text = "More results to return";
1811 case LDAP_CLIENT_LOOP:
1812 case LDAP_REFERRAL_LIMIT_EXCEEDED:
1813 return LDAP_LOOP_DETECT;
1815 if ( LDAP_API_ERROR(rs->sr_err) ) return LDAP_OTHER;