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 ) {
314 slap_callback *sc = op->o_callback,
315 *sc_next = op->o_callback;
317 rc = SLAP_CB_CONTINUE;
318 for ( sc_next = op->o_callback; sc_next; op->o_callback = sc_next) {
319 sc_next = op->o_callback->sc_next;
320 if ( op->o_callback->sc_response ) {
321 rc = op->o_callback->sc_response( op, rs );
322 if ( rc != SLAP_CB_CONTINUE ) break;
327 if ( rc != SLAP_CB_CONTINUE ) goto clean2;
330 #ifdef LDAP_CONNECTIONLESS
331 if (op->o_conn && op->o_conn->c_is_udp)
336 ber_init_w_nullc( ber, LBER_USE_DER );
337 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
341 LDAP_LOG( OPERATION, ENTRY,
342 "send_ldap_response: msgid=%d tag=%lu err=%d\n",
343 rs->sr_msgid, rs->sr_tag, rs->sr_err );
345 Debug( LDAP_DEBUG_TRACE,
346 "send_ldap_response: msgid=%d tag=%lu err=%d\n",
347 rs->sr_msgid, rs->sr_tag, rs->sr_err );
352 LDAP_LOG( OPERATION, ARGS,
353 "send_ldap_response: conn %lu ref=\"%s\"\n",
355 rs->sr_ref[0].bv_val ? rs->sr_ref[0].bv_val : "NULL" , 0 );
357 Debug( LDAP_DEBUG_ARGS, "send_ldap_response: ref=\"%s\"\n",
358 rs->sr_ref[0].bv_val ? rs->sr_ref[0].bv_val : "NULL",
363 #ifdef LDAP_CONNECTIONLESS
364 if (op->o_conn && op->o_conn->c_is_udp &&
365 op->o_protocol == LDAP_VERSION2 )
367 rc = ber_printf( ber, "t{ess" /*"}"*/,
368 rs->sr_tag, rs->sr_err,
369 rs->sr_matched == NULL ? "" : rs->sr_matched,
370 rs->sr_text == NULL ? "" : rs->sr_text );
373 if ( rs->sr_type == REP_INTERMEDIATE ) {
374 rc = ber_printf( ber, "{it{" /*"}}"*/,
375 rs->sr_msgid, rs->sr_tag );
378 rc = ber_printf( ber, "{it{ess" /*"}}"*/,
379 rs->sr_msgid, rs->sr_tag, rs->sr_err,
380 rs->sr_matched == NULL ? "" : rs->sr_matched,
381 rs->sr_text == NULL ? "" : rs->sr_text );
385 if ( rs->sr_ref != NULL ) {
386 assert( rs->sr_err == LDAP_REFERRAL );
387 rc = ber_printf( ber, "t{W}",
388 LDAP_TAG_REFERRAL, rs->sr_ref );
390 assert( rs->sr_err != LDAP_REFERRAL );
394 if( rc != -1 && rs->sr_type == REP_SASL && rs->sr_sasldata != NULL ) {
395 rc = ber_printf( ber, "tO",
396 LDAP_TAG_SASL_RES_CREDS, rs->sr_sasldata );
400 ( rs->sr_type == REP_EXTENDED || rs->sr_type == REP_INTERMEDIATE ))
402 if ( rs->sr_rspoid != NULL ) {
403 rc = ber_printf( ber, "ts",
404 LDAP_TAG_EXOP_RES_OID, rs->sr_rspoid );
406 if( rc != -1 && rs->sr_rspdata != NULL ) {
407 rc = ber_printf( ber, "tO",
408 LDAP_TAG_EXOP_RES_VALUE, rs->sr_rspdata );
413 rc = ber_printf( ber, /*"{"*/ "N}" );
417 rc = send_ldap_controls( op, ber, rs->sr_ctrls );
421 rc = ber_printf( ber, /*"{"*/ "N}" );
424 #ifdef LDAP_CONNECTIONLESS
425 if( op->o_conn && op->o_conn->c_is_udp && op->o_protocol == LDAP_VERSION2
428 rc = ber_printf( ber, /*"{"*/ "N}" );
434 LDAP_LOG( OPERATION, ERR,
435 "send_ldap_response: conn %lu ber_printf failed\n",
436 op->o_connid, 0, 0 );
438 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
441 #ifdef LDAP_CONNECTIONLESS
442 if (!op->o_conn || op->o_conn->c_is_udp == 0)
451 bytes = send_ldap_ber( op->o_conn, ber );
452 #ifdef LDAP_CONNECTIONLESS
453 if (!op->o_conn || op->o_conn->c_is_udp == 0)
461 LDAP_LOG( OPERATION, ERR,
462 "send_ldap_response: conn %lu ber write failed\n",
463 op->o_connid ? op->o_connid : 0, 0, 0 );
465 Debug( LDAP_DEBUG_ANY,
466 "send_ldap_response: ber write failed\n",
475 slapi_pblock_set( op->o_pb, SLAPI_RESULT_CODE, (void *)rs->sr_err );
476 slapi_pblock_set( op->o_pb, SLAPI_RESULT_MATCHED,
477 (void *)rs->sr_matched );
478 slapi_pblock_set( op->o_pb, SLAPI_RESULT_TEXT, (void *)rs->sr_text );
480 #endif /* LDAP_SLAPI */
482 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
483 num_bytes_sent += bytes;
485 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
488 /* Tell caller that we did this for real, as opposed to being
489 * overridden by a callback
491 rc = SLAP_CB_CONTINUE;
494 if ( op->o_callback ) {
495 slap_callback *sc = op->o_callback,
496 *sc_next = op->o_callback;
498 for ( sc_next = op->o_callback; sc_next; op->o_callback = sc_next) {
499 sc_next = op->o_callback->sc_next;
500 if ( op->o_callback->sc_cleanup ) {
501 (void)op->o_callback->sc_cleanup( op, rs );
509 if ( rs->sr_matched && rs->sr_flags & REP_MATCHED_MUSTBEFREED ) {
510 free( (char *)rs->sr_matched );
511 rs->sr_matched = NULL;
514 if ( rs->sr_ref && rs->sr_flags & REP_REF_MUSTBEFREED ) {
515 ber_bvarray_free( rs->sr_ref );
524 send_ldap_disconnect( Operation *op, SlapReply *rs )
526 #define LDAP_UNSOLICITED_ERROR(e) \
527 ( (e) == LDAP_PROTOCOL_ERROR \
528 || (e) == LDAP_STRONG_AUTH_REQUIRED \
529 || (e) == LDAP_UNAVAILABLE )
531 assert( LDAP_UNSOLICITED_ERROR( rs->sr_err ) );
533 rs->sr_type = REP_EXTENDED;
536 LDAP_LOG( OPERATION, ENTRY,
537 "send_ldap_disconnect: conn %lu %d:%s\n",
538 op->o_connid, rs->sr_err, rs->sr_text ? rs->sr_text : "" );
540 Debug( LDAP_DEBUG_TRACE,
541 "send_ldap_disconnect %d:%s\n",
542 rs->sr_err, rs->sr_text ? rs->sr_text : "", NULL );
545 if ( op->o_protocol < LDAP_VERSION3 ) {
546 rs->sr_rspoid = NULL;
547 rs->sr_tag = req2res( op->o_tag );
548 rs->sr_msgid = (rs->sr_tag != LBER_SEQUENCE) ? op->o_msgid : 0;
551 rs->sr_rspoid = LDAP_NOTICE_DISCONNECT;
552 rs->sr_tag = LDAP_RES_EXTENDED;
556 if ( send_ldap_response( op, rs ) == SLAP_CB_CONTINUE ) {
557 Statslog( LDAP_DEBUG_STATS,
558 "conn=%lu op=%lu DISCONNECT tag=%lu err=%d text=%s\n",
559 op->o_connid, op->o_opid, rs->sr_tag, rs->sr_err,
560 rs->sr_text ? rs->sr_text : "" );
565 slap_send_ldap_result( Operation *op, SlapReply *rs )
568 const char *otext = rs->sr_text;
569 BerVarray oref = rs->sr_ref;
571 rs->sr_type = REP_RESULT;
573 assert( !LDAP_API_ERROR( rs->sr_err ));
576 LDAP_LOG( OPERATION, ENTRY,
577 "send_ldap_result: conn=%lu op=%lu p=%d\n",
578 op->o_connid, op->o_opid, op->o_protocol );
580 Debug( LDAP_DEBUG_TRACE,
581 "send_ldap_result: conn=%lu op=%lu p=%d\n",
582 op->o_connid, op->o_opid, op->o_protocol );
586 LDAP_LOG( OPERATION, ARGS,
587 "send_ldap_result: err=%d matched=\"%s\" text=\"%s\"\n",
588 rs->sr_err, rs->sr_matched ? rs->sr_matched : "",
589 rs->sr_text ? rs->sr_text : "" );
591 Debug( LDAP_DEBUG_ARGS,
592 "send_ldap_result: err=%d matched=\"%s\" text=\"%s\"\n",
593 rs->sr_err, rs->sr_matched ? rs->sr_matched : "",
594 rs->sr_text ? rs->sr_text : "" );
600 LDAP_LOG( OPERATION, ARGS,
601 "send_ldap_result: referral=\"%s\"\n",
602 rs->sr_ref[0].bv_val ? rs->sr_ref[0].bv_val : "NULL", 0, 0 );
604 Debug( LDAP_DEBUG_ARGS,
605 "send_ldap_result: referral=\"%s\"\n",
606 rs->sr_ref[0].bv_val ? rs->sr_ref[0].bv_val : "NULL",
611 assert( rs->sr_err != LDAP_PARTIAL_RESULTS );
613 if ( rs->sr_err == LDAP_REFERRAL ) {
614 #ifdef LDAP_CONTROL_X_DOMAIN_SCOPE
615 if( op->o_domain_scope ) {
619 if( rs->sr_ref == NULL ) {
620 rs->sr_err = LDAP_NO_SUCH_OBJECT;
621 } else if ( op->o_protocol < LDAP_VERSION3 ) {
622 rs->sr_err = LDAP_PARTIAL_RESULTS;
628 * Call pre-result plugins. To avoid infinite recursion plugins
629 * should just set SLAPI_RESULT_CODE rather than sending a
630 * result if they wish to change the result.
632 if ( op->o_pb != NULL ) {
633 slapi_int_pblock_set_operation( op->o_pb, op );
634 slapi_pblock_set( op->o_pb, SLAPI_RESULT_CODE,
635 (void *)rs->sr_err );
636 slapi_pblock_set( op->o_pb, SLAPI_RESULT_TEXT,
637 (void *)rs->sr_text );
638 slapi_pblock_set( op->o_pb, SLAPI_RESULT_MATCHED,
639 (void *)rs->sr_matched );
641 (void) slapi_int_call_plugins( op->o_bd, SLAPI_PLUGIN_PRE_RESULT_FN,
644 #endif /* LDAP_SLAPI */
646 if ( op->o_protocol < LDAP_VERSION3 ) {
647 tmp = v2ref( rs->sr_ref, rs->sr_text );
652 rs->sr_tag = req2res( op->o_tag );
653 rs->sr_msgid = (rs->sr_tag != LBER_SEQUENCE) ? op->o_msgid : 0;
655 if ( send_ldap_response( op, rs ) == SLAP_CB_CONTINUE ) {
656 if ( op->o_tag == LDAP_REQ_SEARCH ) {
658 snprintf( nbuf, sizeof nbuf, "%d nentries=%d",
659 rs->sr_err, rs->sr_nentries );
661 Statslog( LDAP_DEBUG_STATS,
662 "conn=%lu op=%lu SEARCH RESULT tag=%lu err=%s text=%s\n",
663 op->o_connid, op->o_opid, rs->sr_tag, nbuf,
664 rs->sr_text ? rs->sr_text : "" );
666 Statslog( LDAP_DEBUG_STATS,
667 "conn=%lu op=%lu RESULT tag=%lu err=%d text=%s\n",
668 op->o_connid, op->o_opid, rs->sr_tag, rs->sr_err,
669 rs->sr_text ? rs->sr_text : "" );
673 if( tmp != NULL ) ch_free(tmp);
679 send_ldap_sasl( Operation *op, SlapReply *rs )
681 rs->sr_type = REP_SASL;
683 LDAP_LOG( OPERATION, ENTRY,
684 "send_ldap_sasl: conn %lu err=%d len=%lu\n",
685 op->o_connid, rs->sr_err,
686 rs->sr_sasldata ? rs->sr_sasldata->bv_len : -1 );
688 Debug( LDAP_DEBUG_TRACE, "send_ldap_sasl: err=%d len=%ld\n",
690 rs->sr_sasldata ? (long) rs->sr_sasldata->bv_len : -1, NULL );
693 rs->sr_tag = req2res( op->o_tag );
694 rs->sr_msgid = (rs->sr_tag != LBER_SEQUENCE) ? op->o_msgid : 0;
696 send_ldap_response( op, rs );
700 slap_send_ldap_extended( Operation *op, SlapReply *rs )
702 rs->sr_type = REP_EXTENDED;
705 LDAP_LOG( OPERATION, ENTRY,
706 "send_ldap_extended: err=%d oid=%s len=%ld\n",
707 rs->sr_err, rs->sr_rspoid ? rs->sr_rspoid : "",
708 rs->sr_rspdata != NULL ? rs->sr_rspdata->bv_len : 0 );
710 Debug( LDAP_DEBUG_TRACE,
711 "send_ldap_extended: err=%d oid=%s len=%ld\n",
713 rs->sr_rspoid ? rs->sr_rspoid : "",
714 rs->sr_rspdata != NULL ? rs->sr_rspdata->bv_len : 0 );
717 rs->sr_tag = req2res( op->o_tag );
718 rs->sr_msgid = (rs->sr_tag != LBER_SEQUENCE) ? op->o_msgid : 0;
720 send_ldap_response( op, rs );
724 slap_send_ldap_intermediate( Operation *op, SlapReply *rs )
726 rs->sr_type = REP_INTERMEDIATE;
728 LDAP_LOG( OPERATION, ENTRY,
729 "send_ldap_intermediate: err=%d oid=%s len=%ld\n",
730 rs->sr_err, rs->sr_rspoid ? rs->sr_rspoid : "",
731 rs->sr_rspdata != NULL ? rs->sr_rspdata->bv_len : 0 );
733 Debug( LDAP_DEBUG_TRACE,
734 "send_ldap_intermediate: err=%d oid=%s len=%ld\n",
736 rs->sr_rspoid ? rs->sr_rspoid : "",
737 rs->sr_rspdata != NULL ? rs->sr_rspdata->bv_len : 0 );
739 rs->sr_tag = LDAP_RES_INTERMEDIATE;
740 rs->sr_msgid = op->o_msgid;
741 send_ldap_response( op, rs );
745 slap_send_search_entry( Operation *op, SlapReply *rs )
747 BerElementBuffer berbuf;
748 BerElement *ber = (BerElement *) &berbuf;
749 Attribute *a, *aa = NULL;
750 int i, j, rc=-1, bytes;
754 AccessControlState acl_state = ACL_STATE_INIT;
756 /* Support for computed attribute plugins */
757 computed_attr_context ctx;
760 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
762 /* a_flags: array of flags telling if the i-th element will be
763 * returned or filtered out
764 * e_flags: array of a_flags
766 char **e_flags = NULL;
768 /* eventually will loop through generated operational attributes */
769 /* only subschemaSubentry and numSubordinates are implemented */
770 /* NOTE: moved before overlays callback circling because
771 * they may modify entry and other stuff in rs */
772 /* check for special all operational attributes ("+") type */
773 opattrs = ( rs->sr_attrs == NULL ) ? 0
774 : an_find( rs->sr_attrs, &AllOper );
776 aa = backend_operational( op, rs, opattrs );
778 rs->sr_type = REP_SEARCH;
779 if ( op->o_callback ) {
780 slap_callback *sc = op->o_callback,
781 *sc_next = op->o_callback;
783 rc = SLAP_CB_CONTINUE;
784 for ( sc_next = op->o_callback; sc_next; op->o_callback = sc_next) {
785 sc_next = op->o_callback->sc_next;
786 if ( op->o_callback->sc_response ) {
787 rc = op->o_callback->sc_response( op, rs );
788 if ( rc != SLAP_CB_CONTINUE ) break;
793 if ( rc != SLAP_CB_CONTINUE ) goto error_return;
797 LDAP_LOG( OPERATION, ENTRY, "send_search_entry: conn %lu dn=\"%s\"%s\n",
798 op->o_connid, rs->sr_entry->e_name.bv_val,
799 op->ors_attrsonly ? " (attrsOnly)" : "" );
801 Debug( LDAP_DEBUG_TRACE, "=> send_search_entry: conn %lu dn=\"%s\"%s\n",
802 op->o_connid, rs->sr_entry->e_name.bv_val,
803 op->ors_attrsonly ? " (attrsOnly)" : "" );
806 if ( !access_allowed( op, rs->sr_entry, ad_entry, NULL, ACL_READ, NULL )) {
809 "send_search_entry: conn %lu access to entry (%s) not allowed\n",
810 op->o_connid, rs->sr_entry->e_name.bv_val, 0 );
812 Debug( LDAP_DEBUG_ACL,
813 "send_search_entry: conn %lu access to entry (%s) not allowed\n",
814 op->o_connid, rs->sr_entry->e_name.bv_val, 0 );
821 edn = rs->sr_entry->e_nname.bv_val;
823 if ( op->o_res_ber ) {
824 /* read back control or LDAP_CONNECTIONLESS */
830 entry_flatsize( rs->sr_entry, &siz, &len, 0 );
831 bv.bv_len = siz + len;
832 bv.bv_val = op->o_tmpalloc(bv.bv_len, op->o_tmpmemctx );
834 ber_init2( ber, &bv, LBER_USE_DER );
835 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
838 #ifdef LDAP_CONNECTIONLESS
839 if ( op->o_conn && op->o_conn->c_is_udp ) {
841 if ( op->o_protocol == LDAP_VERSION2 ) {
842 rc = ber_printf(ber, "t{O{" /*}}*/,
843 LDAP_RES_SEARCH_ENTRY, &rs->sr_entry->e_name );
845 rc = ber_printf( ber, "{it{O{" /*}}}*/, op->o_msgid,
846 LDAP_RES_SEARCH_ENTRY, &rs->sr_entry->e_name );
850 if ( op->o_res_ber ) {
851 /* read back control */
852 rc = ber_printf( ber, "{O{" /*}}*/, &rs->sr_entry->e_name );
854 rc = ber_printf( ber, "{it{O{" /*}}}*/, op->o_msgid,
855 LDAP_RES_SEARCH_ENTRY, &rs->sr_entry->e_name );
860 LDAP_LOG( OPERATION, ERR,
861 "send_search_entry: conn %lu ber_printf failed\n",
862 op->o_connid, 0, 0 );
864 Debug( LDAP_DEBUG_ANY,
865 "send_search_entry: conn %lu ber_printf failed\n",
866 op->o_connid, 0, 0 );
869 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
870 send_ldap_error( op, rs, LDAP_OTHER, "encoding DN error" );
874 /* check for special all user attributes ("*") type */
875 userattrs = ( rs->sr_attrs == NULL ) ? 1
876 : an_find( rs->sr_attrs, &AllUser );
878 /* create an array of arrays of flags. Each flag corresponds
879 * to particular value of attribute and equals 1 if value matches
880 * to ValuesReturnFilter or 0 if not
882 if ( op->o_vrFilter != NULL ) {
886 for ( a = rs->sr_entry->e_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
887 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ ) k++;
890 size = i * sizeof(char *) + k;
893 e_flags = slap_sl_calloc ( 1, i * sizeof(char *) + k, op->o_tmpmemctx );
894 if( e_flags == NULL ) {
896 LDAP_LOG( OPERATION, ERR,
897 "send_search_entry: conn %lu slap_sl_calloc failed\n",
898 op->o_connid ? op->o_connid : 0, 0, 0 );
900 Debug( LDAP_DEBUG_ANY,
901 "send_search_entry: conn %lu slap_sl_calloc failed\n",
902 op->o_connid ? op->o_connid : 0, 0, 0 );
906 send_ldap_error( op, rs, LDAP_OTHER, "out of memory" );
909 a_flags = (char *)(e_flags + i);
910 memset( a_flags, 0, k );
911 for ( a=rs->sr_entry->e_attrs, i=0; a != NULL; a=a->a_next, i++ ) {
912 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ );
913 e_flags[i] = a_flags;
917 rc = filter_matched_values(op, rs->sr_entry->e_attrs, &e_flags) ;
920 LDAP_LOG( OPERATION, ERR, "send_search_entry: "
921 "conn %lu matched values filtering failed\n",
922 op->o_connid ? op->o_connid : 0, 0, 0 );
924 Debug( LDAP_DEBUG_ANY, "send_search_entry: "
925 "conn %lu matched values filtering failed\n",
926 op->o_connid ? op->o_connid : 0, 0, 0 );
928 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
929 send_ldap_error( op, rs, LDAP_OTHER,
930 "matched values filtering error" );
936 for ( a = rs->sr_entry->e_attrs, j = 0; a != NULL; a = a->a_next, j++ ) {
937 AttributeDescription *desc = a->a_desc;
940 if ( rs->sr_attrs == NULL ) {
941 /* all attrs request, skip operational attributes */
942 if( is_at_operational( desc->ad_type ) ) {
947 /* specific attrs requested */
948 if ( is_at_operational( desc->ad_type ) ) {
949 if( !opattrs && !ad_inlist( desc, rs->sr_attrs ) ) {
954 if (!userattrs && !ad_inlist( desc, rs->sr_attrs ) ) {
960 if ( op->ors_attrsonly ) {
961 if ( ! access_allowed( op, rs->sr_entry, desc, NULL,
962 ACL_READ, &acl_state ) )
966 "send_search_entry: conn %lu access to attribute %s not "
967 "allowed\n", op->o_connid, desc->ad_cname.bv_val, 0 );
969 Debug( LDAP_DEBUG_ACL, "send_search_entry: "
970 "conn %lu access to attribute %s not allowed\n",
971 op->o_connid, desc->ad_cname.bv_val, 0 );
976 if (( rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname )) == -1 ) {
978 LDAP_LOG( OPERATION, ERR,
979 "send_search_entry: conn %lu ber_printf failed\n",
980 op->o_connid, 0, 0 );
982 Debug( LDAP_DEBUG_ANY,
983 "send_search_entry: conn %lu ber_printf failed\n",
984 op->o_connid, 0, 0 );
987 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
988 send_ldap_error( op, rs, LDAP_OTHER,
989 "encoding description error");
996 for ( i = 0; a->a_nvals[i].bv_val != NULL; i++ ) {
997 if ( ! access_allowed( op, rs->sr_entry,
998 desc, &a->a_nvals[i], ACL_READ, &acl_state ) )
1001 LDAP_LOG( ACL, INFO,
1002 "send_search_entry: conn %lu "
1003 "access to attribute %s, value #%d not allowed\n",
1004 op->o_connid, desc->ad_cname.bv_val, i );
1006 Debug( LDAP_DEBUG_ACL,
1007 "send_search_entry: conn %lu "
1008 "access to attribute %s, value #%d not allowed\n",
1009 op->o_connid, desc->ad_cname.bv_val, i );
1015 if ( op->o_vrFilter && e_flags[j][i] == 0 ){
1022 if (( rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname )) == -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,
1029 "send_search_entry: conn %lu ber_printf failed\n",
1030 op->o_connid, 0, 0 );
1033 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1034 send_ldap_error( op, rs, LDAP_OTHER,
1035 "encoding description error");
1039 if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
1041 LDAP_LOG( OPERATION, ERR,
1042 "send_search_entry: conn %lu "
1043 "ber_printf failed.\n", op->o_connid, 0, 0 );
1045 Debug( LDAP_DEBUG_ANY,
1046 "send_search_entry: conn %lu "
1047 "ber_printf failed.\n", op->o_connid, 0, 0 );
1050 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1051 send_ldap_error( op, rs, LDAP_OTHER,
1052 "encoding values error" );
1058 if ( finish && ( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
1060 LDAP_LOG( OPERATION, ERR,
1061 "send_search_entry: conn %lu ber_printf failed\n",
1062 op->o_connid, 0, 0 );
1064 Debug( LDAP_DEBUG_ANY,
1065 "send_search_entry: conn %lu ber_printf failed\n",
1066 op->o_connid, 0, 0 );
1069 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1070 send_ldap_error( op, rs, LDAP_OTHER, "encode end error" );
1075 /* NOTE: moved before overlays callback circling because
1076 * they may modify entry and other stuff in rs */
1077 if ( aa != NULL && op->o_vrFilter != NULL ) {
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++ ) k++;
1085 size = i * sizeof(char *) + k;
1087 char *a_flags, **tmp;
1090 * Reuse previous memory - we likely need less space
1091 * for operational attributes
1093 tmp = slap_sl_realloc( e_flags, i * sizeof(char *) + k,
1095 if ( tmp == NULL ) {
1097 LDAP_LOG( OPERATION, ERR,
1098 "send_search_entry: conn %lu "
1099 "not enough memory "
1100 "for matched values filtering\n",
1101 op->o_connid, 0, 0);
1103 Debug( LDAP_DEBUG_ANY,
1104 "send_search_entry: conn %lu "
1105 "not enough memory "
1106 "for matched values filtering\n",
1107 op->o_connid, 0, 0 );
1109 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1110 send_ldap_error( op, rs, LDAP_OTHER,
1111 "not enough memory for matched values filtering" );
1115 a_flags = (char *)(e_flags + i);
1116 memset( a_flags, 0, k );
1117 for ( a = aa, i=0; a != NULL; a = a->a_next, i++ ) {
1118 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ );
1119 e_flags[i] = a_flags;
1122 rc = filter_matched_values(op, aa, &e_flags) ;
1126 LDAP_LOG( OPERATION, ERR,
1127 "send_search_entry: conn %lu "
1128 "matched values filtering failed\n",
1129 op->o_connid ? op->o_connid : 0, 0, 0);
1131 Debug( LDAP_DEBUG_ANY,
1132 "send_search_entry: conn %lu "
1133 "matched values filtering failed\n",
1134 op->o_connid ? op->o_connid : 0, 0, 0);
1136 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1137 send_ldap_error( op, rs, LDAP_OTHER,
1138 "matched values filtering error" );
1144 for (a = aa, j=0; a != NULL; a = a->a_next, j++ ) {
1145 AttributeDescription *desc = a->a_desc;
1147 if ( rs->sr_attrs == NULL ) {
1148 /* all attrs request, skip operational attributes */
1149 if( is_at_operational( desc->ad_type ) ) {
1154 /* specific attrs requested */
1155 if( is_at_operational( desc->ad_type ) ) {
1156 if( !opattrs && !ad_inlist( desc, rs->sr_attrs ) ) {
1160 if (!userattrs && !ad_inlist( desc, rs->sr_attrs ) ) {
1166 if ( ! access_allowed( op, rs->sr_entry, desc, NULL,
1167 ACL_READ, &acl_state ) )
1170 LDAP_LOG( ACL, INFO,
1171 "send_search_entry: conn %lu "
1172 "access to attribute %s not allowed\n",
1173 op->o_connid, desc->ad_cname.bv_val, 0 );
1175 Debug( LDAP_DEBUG_ACL,
1176 "send_search_entry: conn %lu "
1177 "access to attribute %s not allowed\n",
1178 op->o_connid, desc->ad_cname.bv_val, 0 );
1184 rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname );
1187 LDAP_LOG( OPERATION, ERR,
1188 "send_search_entry: conn %lu "
1189 "ber_printf failed\n", op->o_connid, 0, 0 );
1191 Debug( LDAP_DEBUG_ANY,
1192 "send_search_entry: conn %lu "
1193 "ber_printf failed\n", op->o_connid, 0, 0 );
1196 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1197 send_ldap_error( op, rs, LDAP_OTHER,
1198 "encoding description error" );
1202 if ( ! op->ors_attrsonly ) {
1203 for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
1204 if ( ! access_allowed( op, rs->sr_entry,
1205 desc, &a->a_vals[i], ACL_READ, &acl_state ) )
1208 LDAP_LOG( ACL, INFO,
1209 "send_search_entry: conn %lu "
1210 "access to %s, value %d not allowed\n",
1211 op->o_connid, desc->ad_cname.bv_val, i );
1213 Debug( LDAP_DEBUG_ACL,
1214 "send_search_entry: conn %lu "
1215 "access to %s, value %d not allowed\n",
1216 op->o_connid, desc->ad_cname.bv_val, i );
1222 if ( op->o_vrFilter && e_flags[j][i] == 0 ){
1226 if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
1228 LDAP_LOG( OPERATION, ERR,
1229 "send_search_entry: conn %lu ber_printf failed\n",
1230 op->o_connid, 0, 0 );
1232 Debug( LDAP_DEBUG_ANY,
1233 "send_search_entry: conn %lu ber_printf failed\n",
1234 op->o_connid, 0, 0 );
1237 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1238 send_ldap_error( op, rs, LDAP_OTHER,
1239 "encoding values error" );
1245 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
1247 LDAP_LOG( OPERATION, ERR,
1248 "send_search_entry: conn %lu ber_printf failed\n",
1249 op->o_connid, 0, 0 );
1251 Debug( LDAP_DEBUG_ANY,
1252 "send_search_entry: conn %lu ber_printf failed\n",
1253 op->o_connid, 0, 0 );
1256 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1257 send_ldap_error( op, rs, LDAP_OTHER, "encode end error" );
1264 * First, setup the computed attribute context that is
1265 * passed to all plugins.
1268 ctx.cac_pb = op->o_pb;
1269 ctx.cac_attrs = rs->sr_attrs;
1270 ctx.cac_attrsonly = op->ors_attrsonly;
1271 ctx.cac_userattrs = userattrs;
1272 ctx.cac_opattrs = opattrs;
1273 ctx.cac_acl_state = acl_state;
1274 ctx.cac_private = (void *)ber;
1277 * For each client requested attribute, call the plugins.
1279 if ( rs->sr_attrs != NULL ) {
1280 for ( anp = rs->sr_attrs; anp->an_name.bv_val != NULL; anp++ ) {
1281 rc = compute_evaluator( &ctx, anp->an_name.bv_val,
1282 rs->sr_entry, slapi_int_compute_output_ber );
1283 if ( rc == 1 ) break;
1287 * Technically we shouldn't be returning operational attributes
1288 * when the user requested only user attributes. We'll let the
1289 * plugin decide whether to be naughty or not.
1291 rc = compute_evaluator( &ctx, "*",
1292 rs->sr_entry, slapi_int_compute_output_ber );
1295 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1296 send_ldap_error( op, rs, LDAP_OTHER, "computed attribute error" );
1300 #endif /* LDAP_SLAPI */
1304 slap_sl_free( e_flags, op->o_tmpmemctx );
1308 rc = ber_printf( ber, /*{{*/ "}N}" );
1311 rc = send_ldap_controls( op, ber, rs->sr_ctrls );
1315 #ifdef LDAP_CONNECTIONLESS
1316 if( op->o_conn && op->o_conn->c_is_udp ) {
1317 if ( op->o_protocol != LDAP_VERSION2 ) {
1318 rc = ber_printf( ber, /*{*/ "N}" );
1322 if ( op->o_res_ber == NULL ) {
1323 rc = ber_printf( ber, /*{*/ "N}" );
1329 LDAP_LOG( OPERATION, ERR,
1330 "send_search_entry: conn %lu ber_printf failed\n",
1331 op->o_connid, 0, 0 );
1333 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1336 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1337 send_ldap_error( op, rs, LDAP_OTHER, "encode entry end error" );
1342 if ( op->o_res_ber == NULL ) {
1343 bytes = send_ldap_ber( op->o_conn, ber );
1344 ber_free_buf( ber );
1348 LDAP_LOG( OPERATION, ERR,
1349 "send_search_entry: conn %lu ber write failed.\n",
1350 op->o_connid, 0, 0 );
1352 Debug( LDAP_DEBUG_ANY,
1353 "send_search_entry: conn %lu ber write failed.\n",
1354 op->o_connid, 0, 0 );
1362 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1363 num_bytes_sent += bytes;
1366 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1369 Statslog( LDAP_DEBUG_STATS2, "conn=%lu op=%lu ENTRY dn=\"%s\"\n",
1370 op->o_connid, op->o_opid, rs->sr_entry->e_dn, 0, 0 );
1373 LDAP_LOG( OPERATION, ENTRY,
1374 "send_search_entry: conn %lu exit.\n", op->o_connid, 0, 0 );
1376 Debug( LDAP_DEBUG_TRACE,
1377 "<= send_search_entry: conn %lu exit.\n", op->o_connid, 0, 0 );
1384 slap_sl_free( e_flags, op->o_tmpmemctx );
1391 if ( op->o_callback ) {
1392 slap_callback *sc = op->o_callback,
1393 *sc_next = op->o_callback;
1395 for ( sc_next = op->o_callback; sc_next; op->o_callback = sc_next) {
1396 sc_next = op->o_callback->sc_next;
1397 if ( op->o_callback->sc_cleanup ) {
1398 (void)op->o_callback->sc_cleanup( op, rs );
1402 op->o_callback = sc;
1405 /* FIXME: I think rs->sr_type should be explicitly set to
1406 * REP_SEARCH here. That's what it was when we entered this
1407 * function. send_ldap_error may have changed it, but we
1408 * should set it back so that the cleanup functions know
1409 * what they're doing.
1411 if ( op->o_tag == LDAP_REQ_SEARCH && rs->sr_type == REP_SEARCH
1413 && ( rs->sr_flags & REP_ENTRY_MUSTBEFREED ) )
1415 entry_free( rs->sr_entry );
1416 rs->sr_entry = NULL;
1417 rs->sr_flags &= ~REP_ENTRY_MUSTBEFREED;
1424 slap_send_search_reference( Operation *op, SlapReply *rs )
1426 BerElementBuffer berbuf;
1427 BerElement *ber = (BerElement *) &berbuf;
1431 AttributeDescription *ad_ref = slap_schema.si_ad_ref;
1432 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
1434 rs->sr_type = REP_SEARCHREF;
1435 if ( op->o_callback ) {
1436 slap_callback *sc = op->o_callback,
1437 *sc_next = op->o_callback;
1439 rc = SLAP_CB_CONTINUE;
1440 for ( sc_next = op->o_callback; sc_next; op->o_callback = sc_next) {
1441 sc_next = op->o_callback->sc_next;
1442 if ( op->o_callback->sc_response ) {
1443 rc = op->o_callback->sc_response( op, rs );
1444 if ( rc != SLAP_CB_CONTINUE ) break;
1448 op->o_callback = sc;
1449 if ( rc != SLAP_CB_CONTINUE ) goto rel;
1453 LDAP_LOG( OPERATION, ENTRY,
1454 "send_search_reference: conn %lu dn=\"%s\"\n",
1456 rs->sr_entry ? rs->sr_entry->e_name.bv_val : "(null)", 0 );
1458 Debug( LDAP_DEBUG_TRACE,
1459 "=> send_search_reference: dn=\"%s\"\n",
1460 rs->sr_entry ? rs->sr_entry->e_name.bv_val : "(null)", 0, 0 );
1463 if ( rs->sr_entry && ! access_allowed( op, rs->sr_entry,
1464 ad_entry, NULL, ACL_READ, NULL ) )
1467 LDAP_LOG( ACL, INFO,
1468 "send_search_reference: conn %lu "
1469 "access to entry %s not allowed\n",
1470 op->o_connid, rs->sr_entry->e_dn, 0 );
1472 Debug( LDAP_DEBUG_ACL,
1473 "send_search_reference: access to entry not allowed\n",
1480 if ( rs->sr_entry && ! access_allowed( op, rs->sr_entry,
1481 ad_ref, NULL, ACL_READ, NULL ) )
1484 LDAP_LOG( ACL, INFO,
1485 "send_search_reference: conn %lu access "
1486 "to reference not allowed.\n", op->o_connid, 0, 0 );
1488 Debug( LDAP_DEBUG_ACL,
1489 "send_search_reference: access "
1490 "to reference not allowed\n",
1497 #ifdef LDAP_CONTROL_X_DOMAIN_SCOPE
1498 if( op->o_domain_scope ) {
1500 LDAP_LOG( OPERATION, ERR,
1501 "send_search_reference: conn %lu domainScope control in (%s).\n",
1502 op->o_connid, rs->sr_entry->e_dn, 0 );
1504 Debug( LDAP_DEBUG_ANY,
1505 "send_search_reference: domainScope control in (%s)\n",
1506 rs->sr_entry->e_dn, 0, 0 );
1513 if( rs->sr_ref == NULL ) {
1515 LDAP_LOG( OPERATION, ERR,
1516 "send_search_reference: conn %lu null ref in (%s).\n",
1517 op->o_connid, rs->sr_entry ? rs->sr_entry->e_dn : "(null)", 0 );
1519 Debug( LDAP_DEBUG_ANY,
1520 "send_search_reference: null ref in (%s)\n",
1521 rs->sr_entry ? rs->sr_entry->e_dn : "(null)", 0, 0 );
1527 if( op->o_protocol < LDAP_VERSION3 ) {
1529 /* save the references for the result */
1530 if( rs->sr_ref[0].bv_val != NULL ) {
1531 if( value_add( &rs->sr_v2ref, rs->sr_ref ) )
1537 #ifdef LDAP_CONNECTIONLESS
1538 if( op->o_conn && op->o_conn->c_is_udp ) {
1539 ber = op->o_res_ber;
1543 ber_init_w_nullc( ber, LBER_USE_DER );
1544 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
1547 rc = ber_printf( ber, "{it{W}" /*"}"*/ , op->o_msgid,
1548 LDAP_RES_SEARCH_REFERENCE, rs->sr_ref );
1551 rc = send_ldap_controls( op, ber, rs->sr_ctrls );
1555 rc = ber_printf( ber, /*"{"*/ "N}" );
1560 LDAP_LOG( OPERATION, ERR,
1561 "send_search_reference: conn %lu "
1562 "ber_printf failed.\n", op->o_connid, 0, 0 );
1564 Debug( LDAP_DEBUG_ANY,
1565 "send_search_reference: ber_printf failed\n", 0, 0, 0 );
1568 #ifdef LDAP_CONNECTIONLESS
1569 if (!op->o_conn || op->o_conn->c_is_udp == 0)
1571 ber_free_buf( ber );
1572 send_ldap_error( op, rs, LDAP_OTHER, "encode DN error" );
1576 #ifdef LDAP_CONNECTIONLESS
1577 if (!op->o_conn || op->o_conn->c_is_udp == 0) {
1579 bytes = send_ldap_ber( op->o_conn, ber );
1580 ber_free_buf( ber );
1582 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1583 num_bytes_sent += bytes;
1586 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1587 #ifdef LDAP_CONNECTIONLESS
1591 Statslog( LDAP_DEBUG_STATS2, "conn=%lu op=%lu REF dn=\"%s\"\n",
1592 op->o_connid, op->o_opid, rs->sr_entry ? rs->sr_entry->e_dn : "(null)", 0, 0 );
1595 LDAP_LOG( OPERATION, ENTRY,
1596 "send_search_reference: conn %lu exit.\n", op->o_connid, 0, 0 );
1598 Debug( LDAP_DEBUG_TRACE, "<= send_search_reference\n", 0, 0, 0 );
1602 if ( op->o_callback ) {
1603 slap_callback *sc = op->o_callback,
1604 *sc_next = op->o_callback;
1606 for ( sc_next = op->o_callback; sc_next; op->o_callback = sc_next) {
1607 sc_next = op->o_callback->sc_next;
1608 if ( op->o_callback->sc_cleanup ) {
1609 (void)op->o_callback->sc_cleanup( op, rs );
1613 op->o_callback = sc;
1630 *code = LDAP_SUCCESS;
1634 if ( strncasecmp( s, "RESULT", 6 ) != 0 ) {
1636 LDAP_LOG( OPERATION, INFO,
1637 "str2result: (%s), expecting \"RESULT\"\n", s, 0, 0 );
1639 Debug( LDAP_DEBUG_ANY, "str2result (%s) expecting \"RESULT\"\n",
1647 while ( (s = strchr( s, '\n' )) != NULL ) {
1652 if ( (c = strchr( s, ':' )) != NULL ) {
1656 if ( strncasecmp( s, "code", 4 ) == 0 ) {
1660 } else if ( strncasecmp( s, "matched", 7 ) == 0 ) {
1664 } else if ( strncasecmp( s, "info", 4 ) == 0 ) {
1670 LDAP_LOG( OPERATION, INFO, "str2result: (%s) unknown.\n", s, 0, 0 );
1672 Debug( LDAP_DEBUG_ANY, "str2result (%s) unknown\n",
1683 int slap_read_controls(
1687 const struct berval *oid,
1688 LDAPControl **ctrl )
1692 BerElementBuffer berbuf;
1693 BerElement *ber = (BerElement *) &berbuf;
1699 LDAP_LOG( OPERATION, INFO, "slap_read_controls: (%s) %s\n",
1700 oid->bv_val, e->e_dn, 0 );
1702 Debug( LDAP_DEBUG_ANY, "slap_read_controls: (%s) %s\n",
1703 oid->bv_val, e->e_dn, 0 );
1707 rs->sr_attrs = ( oid == &slap_pre_read_bv ) ?
1708 op->o_preread_attrs : op->o_postread_attrs;
1710 entry_flatsize( rs->sr_entry, &siz, &len, 0 );
1711 bv.bv_len = siz + len;
1712 bv.bv_val = op->o_tmpalloc(bv.bv_len, op->o_tmpmemctx );
1714 ber_init2( ber, &bv, LBER_USE_DER );
1715 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
1717 /* create new operation */
1720 myop.o_res_ber = ber;
1722 rc = slap_send_search_entry( &myop, rs );
1725 rc = ber_flatten2( ber, &c.ldctl_value, 0 );
1727 if( rc == LBER_ERROR ) return LDAP_OTHER;
1729 c.ldctl_oid = oid->bv_val;
1730 c.ldctl_iscritical = 0;
1732 if ( ctrl == NULL ) {
1734 *ctrl = (LDAPControl *) slap_sl_calloc( 1, sizeof(LDAPControl), NULL );
1736 /* retry: free previous try */
1737 slap_sl_free( (*ctrl)->ldctl_value.bv_val, &op->o_tmpmemctx );
1741 return LDAP_SUCCESS;
1744 /* Map API errors to protocol errors... */
1746 slap_map_api2result( SlapReply *rs )
1748 switch(rs->sr_err) {
1749 case LDAP_SERVER_DOWN:
1750 return LDAP_UNAVAILABLE;
1751 case LDAP_LOCAL_ERROR:
1753 case LDAP_ENCODING_ERROR:
1754 case LDAP_DECODING_ERROR:
1755 return LDAP_PROTOCOL_ERROR;
1757 return LDAP_UNAVAILABLE;
1758 case LDAP_AUTH_UNKNOWN:
1759 return LDAP_AUTH_METHOD_NOT_SUPPORTED;
1760 case LDAP_FILTER_ERROR:
1761 rs->sr_text = "Filter error";
1763 case LDAP_USER_CANCELLED:
1764 rs->sr_text = "User cancelled";
1766 case LDAP_PARAM_ERROR:
1767 return LDAP_PROTOCOL_ERROR;
1768 case LDAP_NO_MEMORY:
1770 case LDAP_CONNECT_ERROR:
1771 return LDAP_UNAVAILABLE;
1772 case LDAP_NOT_SUPPORTED:
1773 return LDAP_UNWILLING_TO_PERFORM;
1774 case LDAP_CONTROL_NOT_FOUND:
1775 return LDAP_PROTOCOL_ERROR;
1776 case LDAP_NO_RESULTS_RETURNED:
1777 return LDAP_NO_SUCH_OBJECT;
1778 case LDAP_MORE_RESULTS_TO_RETURN:
1779 rs->sr_text = "More results to return";
1781 case LDAP_CLIENT_LOOP:
1782 case LDAP_REFERRAL_LIMIT_EXCEEDED:
1783 return LDAP_LOOP_DETECT;
1785 if ( LDAP_API_ERROR(rs->sr_err) ) return LDAP_OTHER;