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 const struct berval slap_dummy_bv = BER_BVNULL;
46 int slap_null_cb( Operation *op, SlapReply *rs )
51 int slap_freeself_cb( Operation *op, SlapReply *rs )
53 assert( op->o_callback );
55 op->o_tmpfree( op->o_callback, op->o_tmpmemctx );
56 op->o_callback = NULL;
58 return SLAP_CB_CONTINUE;
61 int slap_replog_cb( Operation *op, SlapReply *rs )
63 if ( rs->sr_err == LDAP_SUCCESS ) {
66 return SLAP_CB_CONTINUE;
69 static char *v2ref( BerVarray ref, const char *text )
71 size_t len = 0, i = 0;
76 return ch_strdup(text);
84 if (text[len-1] != '\n') {
89 v2 = SLAP_MALLOC( len+i+sizeof("Referral:") );
92 LDAP_LOG( OPERATION, ERR, "v2ref: SLAP_MALLOC failed", 0, 0, 0 );
94 Debug( LDAP_DEBUG_ANY, "v2ref: SLAP_MALLOC failed", 0, 0, 0 );
105 strcpy( v2+len, "Referral:" );
106 len += sizeof("Referral:");
108 for( i=0; ref[i].bv_val != NULL; i++ ) {
109 v2 = SLAP_REALLOC( v2, len + ref[i].bv_len + 1 );
112 LDAP_LOG( OPERATION, ERR, "v2ref: SLAP_MALLOC failed", 0, 0, 0 );
114 Debug( LDAP_DEBUG_ANY, "v2ref: SLAP_MALLOC failed", 0, 0, 0 );
119 AC_MEMCPY(&v2[len], ref[i].bv_val, ref[i].bv_len );
120 len += ref[i].bv_len;
121 if (ref[i].bv_val[ref[i].bv_len-1] != '/') {
130 static ber_tag_t req2res( ber_tag_t tag )
135 case LDAP_REQ_COMPARE:
136 case LDAP_REQ_EXTENDED:
137 case LDAP_REQ_MODIFY:
138 case LDAP_REQ_MODRDN:
142 case LDAP_REQ_DELETE:
143 tag = LDAP_RES_DELETE;
146 case LDAP_REQ_ABANDON:
147 case LDAP_REQ_UNBIND:
151 case LDAP_REQ_SEARCH:
152 tag = LDAP_RES_SEARCH_RESULT;
162 static long send_ldap_ber(
168 ber_get_option( ber, LBER_OPT_BER_BYTES_TO_WRITE, &bytes );
170 /* write only one pdu at a time - wait til it's our turn */
171 ldap_pvt_thread_mutex_lock( &conn->c_write_mutex );
173 /* lock the connection */
174 ldap_pvt_thread_mutex_lock( &conn->c_mutex );
181 if ( connection_state_closing( conn ) ) {
182 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
183 ldap_pvt_thread_mutex_unlock( &conn->c_write_mutex );
188 if ( ber_flush( conn->c_sb, ber, 0 ) == 0 ) {
195 * we got an error. if it's ewouldblock, we need to
196 * wait on the socket being writable. otherwise, figure
197 * it's a hard error and return.
201 LDAP_LOG( OPERATION, ERR,
202 "send_ldap_ber: conn %lu ber_flush failed err=%d (%s)\n",
203 conn ? conn->c_connid : 0, err, sock_errstr(err) );
205 Debug( LDAP_DEBUG_CONNS, "ber_flush failed errno=%d reason=\"%s\"\n",
206 err, sock_errstr(err), 0 );
209 if ( err != EWOULDBLOCK && err != EAGAIN ) {
210 connection_closing( conn );
212 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
213 ldap_pvt_thread_mutex_unlock( &conn->c_write_mutex );
218 /* wait for socket to be write-ready */
219 conn->c_writewaiter = 1;
220 ber_sockbuf_ctrl( conn->c_sb, LBER_SB_OPT_GET_FD, &sd );
221 slapd_set_write( sd, 1 );
223 ldap_pvt_thread_cond_wait( &conn->c_write_cv, &conn->c_mutex );
224 conn->c_writewaiter = 0;
227 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
228 ldap_pvt_thread_mutex_unlock( &conn->c_write_mutex );
234 send_ldap_control( BerElement *ber, LDAPControl *c )
240 rc = ber_printf( ber, "{s" /*}*/, c->ldctl_oid );
242 if( c->ldctl_iscritical ) {
243 rc = ber_printf( ber, "b",
244 (ber_int_t) c->ldctl_iscritical ) ;
245 if( rc == -1 ) return rc;
248 if( c->ldctl_value.bv_val != NULL ) {
249 rc = ber_printf( ber, "O", &c->ldctl_value );
250 if( rc == -1 ) return rc;
253 rc = ber_printf( ber, /*{*/"N}" );
254 if( rc == -1 ) return rc;
260 send_ldap_controls( Operation *o, BerElement *ber, LDAPControl **c )
264 LDAPControl **sctrls = NULL;
267 * Retrieve any additional controls that may be set by the
271 if ( o->o_pb && slapi_pblock_get( o->o_pb, SLAPI_RESCONTROLS, &sctrls ) != 0 ) {
275 if ( c == NULL && sctrls == NULL ) return 0;
277 if( c == NULL ) return 0;
278 #endif /* LDAP_SLAPI */
280 rc = ber_printf( ber, "t{"/*}*/, LDAP_TAG_CONTROLS );
281 if( rc == -1 ) return rc;
285 #endif /* LDAP_SLAPI */
286 for( ; *c != NULL; c++) {
287 rc = send_ldap_control( ber, *c );
288 if( rc == -1 ) return rc;
292 if ( sctrls != NULL ) {
293 for ( c = sctrls; *c != NULL; c++ ) {
294 rc = send_ldap_control( ber, *c );
295 if( rc == -1 ) return rc;
298 #endif /* LDAP_SLAPI */
300 rc = ber_printf( ber, /*{*/"N}" );
310 BerElementBuffer berbuf;
311 BerElement *ber = (BerElement *) &berbuf;
312 int rc = LDAP_SUCCESS;
315 if ( op->o_callback ) {
317 slap_callback *sc = op->o_callback,
318 *sc_next = op->o_callback;
320 rc = SLAP_CB_CONTINUE;
321 for ( sc_next = op->o_callback; sc_next; op->o_callback = sc_next) {
322 sc_next = op->o_callback->sc_next;
323 if ( op->o_callback->sc_response ) {
324 rc = op->o_callback->sc_response( op, rs );
325 if ( first && op->o_callback == NULL ) {
328 if ( rc != SLAP_CB_CONTINUE ) break;
334 if ( rc != SLAP_CB_CONTINUE ) goto clean2;
337 #ifdef LDAP_CONNECTIONLESS
338 if (op->o_conn && op->o_conn->c_is_udp)
343 ber_init_w_nullc( ber, LBER_USE_DER );
344 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
348 LDAP_LOG( OPERATION, ENTRY,
349 "send_ldap_response: msgid=%d tag=%lu err=%d\n",
350 rs->sr_msgid, rs->sr_tag, rs->sr_err );
352 Debug( LDAP_DEBUG_TRACE,
353 "send_ldap_response: msgid=%d tag=%lu err=%d\n",
354 rs->sr_msgid, rs->sr_tag, rs->sr_err );
359 LDAP_LOG( OPERATION, ARGS,
360 "send_ldap_response: conn %lu ref=\"%s\"\n",
362 rs->sr_ref[0].bv_val ? rs->sr_ref[0].bv_val : "NULL" , 0 );
364 Debug( LDAP_DEBUG_ARGS, "send_ldap_response: ref=\"%s\"\n",
365 rs->sr_ref[0].bv_val ? rs->sr_ref[0].bv_val : "NULL",
370 #ifdef LDAP_CONNECTIONLESS
371 if (op->o_conn && op->o_conn->c_is_udp &&
372 op->o_protocol == LDAP_VERSION2 )
374 rc = ber_printf( ber, "t{ess" /*"}"*/,
375 rs->sr_tag, rs->sr_err,
376 rs->sr_matched == NULL ? "" : rs->sr_matched,
377 rs->sr_text == NULL ? "" : rs->sr_text );
380 if ( rs->sr_type == REP_INTERMEDIATE ) {
381 rc = ber_printf( ber, "{it{" /*"}}"*/,
382 rs->sr_msgid, rs->sr_tag );
385 rc = ber_printf( ber, "{it{ess" /*"}}"*/,
386 rs->sr_msgid, rs->sr_tag, rs->sr_err,
387 rs->sr_matched == NULL ? "" : rs->sr_matched,
388 rs->sr_text == NULL ? "" : rs->sr_text );
392 if ( rs->sr_ref != NULL ) {
393 assert( rs->sr_err == LDAP_REFERRAL );
394 rc = ber_printf( ber, "t{W}",
395 LDAP_TAG_REFERRAL, rs->sr_ref );
397 assert( rs->sr_err != LDAP_REFERRAL );
401 if( rc != -1 && rs->sr_type == REP_SASL && rs->sr_sasldata != NULL ) {
402 rc = ber_printf( ber, "tO",
403 LDAP_TAG_SASL_RES_CREDS, rs->sr_sasldata );
407 ( rs->sr_type == REP_EXTENDED || rs->sr_type == REP_INTERMEDIATE ))
409 if ( rs->sr_rspoid != NULL ) {
410 rc = ber_printf( ber, "ts",
411 LDAP_TAG_EXOP_RES_OID, rs->sr_rspoid );
413 if( rc != -1 && rs->sr_rspdata != NULL ) {
414 rc = ber_printf( ber, "tO",
415 LDAP_TAG_EXOP_RES_VALUE, rs->sr_rspdata );
420 rc = ber_printf( ber, /*"{"*/ "N}" );
424 rc = send_ldap_controls( op, ber, rs->sr_ctrls );
428 rc = ber_printf( ber, /*"{"*/ "N}" );
431 #ifdef LDAP_CONNECTIONLESS
432 if( op->o_conn && op->o_conn->c_is_udp && op->o_protocol == LDAP_VERSION2
435 rc = ber_printf( ber, /*"{"*/ "N}" );
441 LDAP_LOG( OPERATION, ERR,
442 "send_ldap_response: conn %lu ber_printf failed\n",
443 op->o_connid, 0, 0 );
445 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
448 #ifdef LDAP_CONNECTIONLESS
449 if (!op->o_conn || op->o_conn->c_is_udp == 0)
458 bytes = send_ldap_ber( op->o_conn, ber );
459 #ifdef LDAP_CONNECTIONLESS
460 if (!op->o_conn || op->o_conn->c_is_udp == 0)
468 LDAP_LOG( OPERATION, ERR,
469 "send_ldap_response: conn %lu ber write failed\n",
470 op->o_connid ? op->o_connid : 0, 0, 0 );
472 Debug( LDAP_DEBUG_ANY,
473 "send_ldap_response: ber write failed\n",
482 slapi_pblock_set( op->o_pb, SLAPI_RESULT_CODE, (void *)rs->sr_err );
483 slapi_pblock_set( op->o_pb, SLAPI_RESULT_MATCHED,
484 (void *)rs->sr_matched );
485 slapi_pblock_set( op->o_pb, SLAPI_RESULT_TEXT, (void *)rs->sr_text );
487 #endif /* LDAP_SLAPI */
489 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
490 num_bytes_sent += bytes;
492 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
495 /* Tell caller that we did this for real, as opposed to being
496 * overridden by a callback
498 rc = SLAP_CB_CONTINUE;
501 if ( op->o_callback ) {
503 slap_callback *sc = op->o_callback,
504 *sc_next = op->o_callback;
506 for ( sc_next = op->o_callback; sc_next; op->o_callback = sc_next) {
507 sc_next = op->o_callback->sc_next;
508 if ( op->o_callback->sc_cleanup ) {
509 (void)op->o_callback->sc_cleanup( op, rs );
510 if ( first && op->o_callback == NULL ) {
521 if ( rs->sr_matched && rs->sr_flags & REP_MATCHED_MUSTBEFREED ) {
522 free( (char *)rs->sr_matched );
523 rs->sr_matched = NULL;
526 if ( rs->sr_ref && rs->sr_flags & REP_REF_MUSTBEFREED ) {
527 ber_bvarray_free( rs->sr_ref );
536 send_ldap_disconnect( Operation *op, SlapReply *rs )
538 #define LDAP_UNSOLICITED_ERROR(e) \
539 ( (e) == LDAP_PROTOCOL_ERROR \
540 || (e) == LDAP_STRONG_AUTH_REQUIRED \
541 || (e) == LDAP_UNAVAILABLE )
543 assert( LDAP_UNSOLICITED_ERROR( rs->sr_err ) );
545 rs->sr_type = REP_EXTENDED;
548 LDAP_LOG( OPERATION, ENTRY,
549 "send_ldap_disconnect: conn %lu %d:%s\n",
550 op->o_connid, rs->sr_err, rs->sr_text ? rs->sr_text : "" );
552 Debug( LDAP_DEBUG_TRACE,
553 "send_ldap_disconnect %d:%s\n",
554 rs->sr_err, rs->sr_text ? rs->sr_text : "", NULL );
557 if ( op->o_protocol < LDAP_VERSION3 ) {
558 rs->sr_rspoid = NULL;
559 rs->sr_tag = req2res( op->o_tag );
560 rs->sr_msgid = (rs->sr_tag != LBER_SEQUENCE) ? op->o_msgid : 0;
563 rs->sr_rspoid = LDAP_NOTICE_DISCONNECT;
564 rs->sr_tag = LDAP_RES_EXTENDED;
568 if ( send_ldap_response( op, rs ) == SLAP_CB_CONTINUE ) {
569 Statslog( LDAP_DEBUG_STATS,
570 "conn=%lu op=%lu DISCONNECT tag=%lu err=%d text=%s\n",
571 op->o_connid, op->o_opid, rs->sr_tag, rs->sr_err,
572 rs->sr_text ? rs->sr_text : "" );
577 slap_send_ldap_result( Operation *op, SlapReply *rs )
580 const char *otext = rs->sr_text;
581 BerVarray oref = rs->sr_ref;
583 rs->sr_type = REP_RESULT;
585 assert( !LDAP_API_ERROR( rs->sr_err ));
588 LDAP_LOG( OPERATION, ENTRY,
589 "send_ldap_result: conn=%lu op=%lu p=%d\n",
590 op->o_connid, op->o_opid, op->o_protocol );
592 Debug( LDAP_DEBUG_TRACE,
593 "send_ldap_result: conn=%lu op=%lu p=%d\n",
594 op->o_connid, op->o_opid, op->o_protocol );
598 LDAP_LOG( OPERATION, ARGS,
599 "send_ldap_result: err=%d matched=\"%s\" text=\"%s\"\n",
600 rs->sr_err, rs->sr_matched ? rs->sr_matched : "",
601 rs->sr_text ? rs->sr_text : "" );
603 Debug( LDAP_DEBUG_ARGS,
604 "send_ldap_result: err=%d matched=\"%s\" text=\"%s\"\n",
605 rs->sr_err, rs->sr_matched ? rs->sr_matched : "",
606 rs->sr_text ? rs->sr_text : "" );
612 LDAP_LOG( OPERATION, ARGS,
613 "send_ldap_result: referral=\"%s\"\n",
614 rs->sr_ref[0].bv_val ? rs->sr_ref[0].bv_val : "NULL", 0, 0 );
616 Debug( LDAP_DEBUG_ARGS,
617 "send_ldap_result: referral=\"%s\"\n",
618 rs->sr_ref[0].bv_val ? rs->sr_ref[0].bv_val : "NULL",
623 assert( rs->sr_err != LDAP_PARTIAL_RESULTS );
625 if ( rs->sr_err == LDAP_REFERRAL ) {
626 #ifdef LDAP_CONTROL_X_DOMAIN_SCOPE
627 if( op->o_domain_scope ) {
631 if( rs->sr_ref == NULL ) {
632 rs->sr_err = LDAP_NO_SUCH_OBJECT;
633 } else if ( op->o_protocol < LDAP_VERSION3 ) {
634 rs->sr_err = LDAP_PARTIAL_RESULTS;
640 * Call pre-result plugins. To avoid infinite recursion plugins
641 * should just set SLAPI_RESULT_CODE rather than sending a
642 * result if they wish to change the result.
644 if ( op->o_pb != NULL ) {
645 slapi_int_pblock_set_operation( op->o_pb, op );
646 slapi_pblock_set( op->o_pb, SLAPI_RESULT_CODE,
647 (void *)rs->sr_err );
648 slapi_pblock_set( op->o_pb, SLAPI_RESULT_TEXT,
649 (void *)rs->sr_text );
650 slapi_pblock_set( op->o_pb, SLAPI_RESULT_MATCHED,
651 (void *)rs->sr_matched );
653 (void) slapi_int_call_plugins( op->o_bd, SLAPI_PLUGIN_PRE_RESULT_FN,
656 #endif /* LDAP_SLAPI */
658 if ( op->o_protocol < LDAP_VERSION3 ) {
659 tmp = v2ref( rs->sr_ref, rs->sr_text );
664 rs->sr_tag = req2res( op->o_tag );
665 rs->sr_msgid = (rs->sr_tag != LBER_SEQUENCE) ? op->o_msgid : 0;
667 if ( send_ldap_response( op, rs ) == SLAP_CB_CONTINUE ) {
668 if ( op->o_tag == LDAP_REQ_SEARCH ) {
670 snprintf( nbuf, sizeof nbuf, "%d nentries=%d",
671 rs->sr_err, rs->sr_nentries );
673 Statslog( LDAP_DEBUG_STATS,
674 "conn=%lu op=%lu SEARCH RESULT tag=%lu err=%s text=%s\n",
675 op->o_connid, op->o_opid, rs->sr_tag, nbuf,
676 rs->sr_text ? rs->sr_text : "" );
678 Statslog( LDAP_DEBUG_STATS,
679 "conn=%lu op=%lu RESULT tag=%lu err=%d text=%s\n",
680 op->o_connid, op->o_opid, rs->sr_tag, rs->sr_err,
681 rs->sr_text ? rs->sr_text : "" );
685 if( tmp != NULL ) ch_free(tmp);
691 send_ldap_sasl( Operation *op, SlapReply *rs )
693 rs->sr_type = REP_SASL;
695 LDAP_LOG( OPERATION, ENTRY,
696 "send_ldap_sasl: conn %lu err=%d len=%lu\n",
697 op->o_connid, rs->sr_err,
698 rs->sr_sasldata ? rs->sr_sasldata->bv_len : -1 );
700 Debug( LDAP_DEBUG_TRACE, "send_ldap_sasl: err=%d len=%ld\n",
702 rs->sr_sasldata ? (long) rs->sr_sasldata->bv_len : -1, NULL );
705 rs->sr_tag = req2res( op->o_tag );
706 rs->sr_msgid = (rs->sr_tag != LBER_SEQUENCE) ? op->o_msgid : 0;
708 send_ldap_response( op, rs );
712 slap_send_ldap_extended( Operation *op, SlapReply *rs )
714 rs->sr_type = REP_EXTENDED;
717 LDAP_LOG( OPERATION, ENTRY,
718 "send_ldap_extended: 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_extended: 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 );
729 rs->sr_tag = req2res( op->o_tag );
730 rs->sr_msgid = (rs->sr_tag != LBER_SEQUENCE) ? op->o_msgid : 0;
732 send_ldap_response( op, rs );
736 slap_send_ldap_intermediate( Operation *op, SlapReply *rs )
738 rs->sr_type = REP_INTERMEDIATE;
740 LDAP_LOG( OPERATION, ENTRY,
741 "send_ldap_intermediate: err=%d oid=%s len=%ld\n",
742 rs->sr_err, rs->sr_rspoid ? rs->sr_rspoid : "",
743 rs->sr_rspdata != NULL ? rs->sr_rspdata->bv_len : 0 );
745 Debug( LDAP_DEBUG_TRACE,
746 "send_ldap_intermediate: err=%d oid=%s len=%ld\n",
748 rs->sr_rspoid ? rs->sr_rspoid : "",
749 rs->sr_rspdata != NULL ? rs->sr_rspdata->bv_len : 0 );
751 rs->sr_tag = LDAP_RES_INTERMEDIATE;
752 rs->sr_msgid = op->o_msgid;
753 send_ldap_response( op, rs );
757 slap_send_search_entry( Operation *op, SlapReply *rs )
759 BerElementBuffer berbuf;
760 BerElement *ber = (BerElement *) &berbuf;
762 int i, j, rc=-1, bytes;
765 AccessControlState acl_state = ACL_STATE_INIT;
767 /* Support for computed attribute plugins */
768 computed_attr_context ctx;
771 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
773 /* a_flags: array of flags telling if the i-th element will be
774 * returned or filtered out
775 * e_flags: array of a_flags
777 char **e_flags = NULL;
779 rs->sr_type = REP_SEARCH;
781 /* eventually will loop through generated operational attributes */
782 /* only subschemaSubentry and numSubordinates are implemented */
783 /* NOTE: moved before overlays callback circling because
784 * they may modify entry and other stuff in rs */
785 /* check for special all operational attributes ("+") type */
786 /* FIXME: maybe we could se this flag at the operation level;
787 * however, in principle the caller of send_search_entry() may
788 * change the attribute list at each call */
789 if ( rs->sr_attrs == NULL ) {
790 rs->sr_attr_flags = ( SLAP_OPATTRS_NO | SLAP_USERATTRS_YES );
793 rs->sr_attr_flags |= an_find( rs->sr_attrs, &AllOper ) ?
794 SLAP_OPATTRS_YES : SLAP_OPATTRS_NO;
795 rs->sr_attr_flags |= an_find( rs->sr_attrs, &AllUser ) ?
796 SLAP_USERATTRS_YES : SLAP_USERATTRS_NO;
799 rc = backend_operational( op, rs );
804 if ( op->o_callback ) {
806 slap_callback *sc = op->o_callback,
807 *sc_next = op->o_callback;
809 rc = SLAP_CB_CONTINUE;
810 for ( sc_next = op->o_callback; sc_next; op->o_callback = sc_next) {
811 sc_next = op->o_callback->sc_next;
812 if ( op->o_callback->sc_response ) {
813 rc = op->o_callback->sc_response( op, rs );
814 if ( first && op->o_callback == NULL ) {
817 if ( rc != SLAP_CB_CONTINUE ) break;
823 if ( rc != SLAP_CB_CONTINUE ) goto error_return;
827 LDAP_LOG( OPERATION, ENTRY, "send_search_entry: conn %lu dn=\"%s\"%s\n",
828 op->o_connid, rs->sr_entry->e_name.bv_val,
829 op->ors_attrsonly ? " (attrsOnly)" : "" );
831 Debug( LDAP_DEBUG_TRACE, "=> send_search_entry: conn %lu dn=\"%s\"%s\n",
832 op->o_connid, rs->sr_entry->e_name.bv_val,
833 op->ors_attrsonly ? " (attrsOnly)" : "" );
836 if ( !access_allowed( op, rs->sr_entry, ad_entry, NULL, ACL_READ, NULL )) {
839 "send_search_entry: conn %lu access to entry (%s) not allowed\n",
840 op->o_connid, rs->sr_entry->e_name.bv_val, 0 );
842 Debug( LDAP_DEBUG_ACL,
843 "send_search_entry: conn %lu access to entry (%s) not allowed\n",
844 op->o_connid, rs->sr_entry->e_name.bv_val, 0 );
851 edn = rs->sr_entry->e_nname.bv_val;
853 if ( op->o_res_ber ) {
854 /* read back control or LDAP_CONNECTIONLESS */
860 entry_flatsize( rs->sr_entry, &siz, &len, 0 );
861 bv.bv_len = siz + len;
862 bv.bv_val = op->o_tmpalloc(bv.bv_len, op->o_tmpmemctx );
864 ber_init2( ber, &bv, LBER_USE_DER );
865 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
868 #ifdef LDAP_CONNECTIONLESS
869 if ( op->o_conn && op->o_conn->c_is_udp ) {
871 if ( op->o_protocol == LDAP_VERSION2 ) {
872 rc = ber_printf(ber, "t{O{" /*}}*/,
873 LDAP_RES_SEARCH_ENTRY, &rs->sr_entry->e_name );
875 rc = ber_printf( ber, "{it{O{" /*}}}*/, op->o_msgid,
876 LDAP_RES_SEARCH_ENTRY, &rs->sr_entry->e_name );
880 if ( op->o_res_ber ) {
881 /* read back control */
882 rc = ber_printf( ber, "{O{" /*}}*/, &rs->sr_entry->e_name );
884 rc = ber_printf( ber, "{it{O{" /*}}}*/, op->o_msgid,
885 LDAP_RES_SEARCH_ENTRY, &rs->sr_entry->e_name );
890 LDAP_LOG( OPERATION, ERR,
891 "send_search_entry: conn %lu ber_printf failed\n",
892 op->o_connid, 0, 0 );
894 Debug( LDAP_DEBUG_ANY,
895 "send_search_entry: conn %lu ber_printf failed\n",
896 op->o_connid, 0, 0 );
899 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
900 send_ldap_error( op, rs, LDAP_OTHER, "encoding DN error" );
904 /* check for special all user attributes ("*") type */
905 userattrs = SLAP_USERATTRS( rs->sr_attr_flags );
907 /* create an array of arrays of flags. Each flag corresponds
908 * to particular value of attribute and equals 1 if value matches
909 * to ValuesReturnFilter or 0 if not
911 if ( op->o_vrFilter != NULL ) {
915 for ( a = rs->sr_entry->e_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
916 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ ) k++;
919 size = i * sizeof(char *) + k;
922 e_flags = slap_sl_calloc ( 1, i * sizeof(char *) + k, op->o_tmpmemctx );
923 if( e_flags == NULL ) {
925 LDAP_LOG( OPERATION, ERR,
926 "send_search_entry: conn %lu slap_sl_calloc failed\n",
927 op->o_connid ? op->o_connid : 0, 0, 0 );
929 Debug( LDAP_DEBUG_ANY,
930 "send_search_entry: conn %lu slap_sl_calloc failed\n",
931 op->o_connid ? op->o_connid : 0, 0, 0 );
935 send_ldap_error( op, rs, LDAP_OTHER, "out of memory" );
938 a_flags = (char *)(e_flags + i);
939 memset( a_flags, 0, k );
940 for ( a=rs->sr_entry->e_attrs, i=0; a != NULL; a=a->a_next, i++ ) {
941 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ );
942 e_flags[i] = a_flags;
946 rc = filter_matched_values(op, rs->sr_entry->e_attrs, &e_flags) ;
949 LDAP_LOG( OPERATION, ERR, "send_search_entry: "
950 "conn %lu matched values filtering failed\n",
951 op->o_connid ? op->o_connid : 0, 0, 0 );
953 Debug( LDAP_DEBUG_ANY, "send_search_entry: "
954 "conn %lu matched values filtering failed\n",
955 op->o_connid ? op->o_connid : 0, 0, 0 );
957 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
958 send_ldap_error( op, rs, LDAP_OTHER,
959 "matched values filtering error" );
965 for ( a = rs->sr_entry->e_attrs, j = 0; a != NULL; a = a->a_next, j++ ) {
966 AttributeDescription *desc = a->a_desc;
969 if ( rs->sr_attrs == NULL ) {
970 /* all attrs request, skip operational attributes */
971 if( is_at_operational( desc->ad_type ) ) {
976 /* specific attrs requested */
977 if ( is_at_operational( desc->ad_type ) ) {
978 if ( !SLAP_OPATTRS( rs->sr_attr_flags ) &&
979 !ad_inlist( desc, rs->sr_attrs ) )
985 if ( !userattrs && !ad_inlist( desc, rs->sr_attrs ) )
992 if ( op->ors_attrsonly ) {
993 if ( ! access_allowed( op, rs->sr_entry, desc, NULL,
994 ACL_READ, &acl_state ) )
998 "send_search_entry: conn %lu access to attribute %s not "
999 "allowed\n", op->o_connid, desc->ad_cname.bv_val, 0 );
1001 Debug( LDAP_DEBUG_ACL, "send_search_entry: "
1002 "conn %lu access to attribute %s not allowed\n",
1003 op->o_connid, desc->ad_cname.bv_val, 0 );
1008 if (( rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname )) == -1 ) {
1010 LDAP_LOG( OPERATION, ERR,
1011 "send_search_entry: conn %lu ber_printf failed\n",
1012 op->o_connid, 0, 0 );
1014 Debug( LDAP_DEBUG_ANY,
1015 "send_search_entry: conn %lu ber_printf failed\n",
1016 op->o_connid, 0, 0 );
1019 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1020 send_ldap_error( op, rs, LDAP_OTHER,
1021 "encoding description error");
1028 for ( i = 0; a->a_nvals[i].bv_val != NULL; i++ ) {
1029 if ( ! access_allowed( op, rs->sr_entry,
1030 desc, &a->a_nvals[i], ACL_READ, &acl_state ) )
1033 LDAP_LOG( ACL, INFO,
1034 "send_search_entry: conn %lu "
1035 "access to attribute %s, value #%d not allowed\n",
1036 op->o_connid, desc->ad_cname.bv_val, i );
1038 Debug( LDAP_DEBUG_ACL,
1039 "send_search_entry: conn %lu "
1040 "access to attribute %s, value #%d not allowed\n",
1041 op->o_connid, desc->ad_cname.bv_val, i );
1047 if ( op->o_vrFilter && e_flags[j][i] == 0 ){
1054 if (( rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname )) == -1 ) {
1056 LDAP_LOG( OPERATION, ERR,
1057 "send_search_entry: conn %lu ber_printf failed\n",
1058 op->o_connid, 0, 0 );
1060 Debug( LDAP_DEBUG_ANY,
1061 "send_search_entry: conn %lu ber_printf failed\n",
1062 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 description error");
1071 if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
1073 LDAP_LOG( OPERATION, ERR,
1074 "send_search_entry: conn %lu "
1075 "ber_printf failed.\n", op->o_connid, 0, 0 );
1077 Debug( LDAP_DEBUG_ANY,
1078 "send_search_entry: conn %lu "
1079 "ber_printf failed.\n", op->o_connid, 0, 0 );
1082 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1083 send_ldap_error( op, rs, LDAP_OTHER,
1084 "encoding values error" );
1090 if ( finish && ( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
1092 LDAP_LOG( OPERATION, ERR,
1093 "send_search_entry: conn %lu ber_printf failed\n",
1094 op->o_connid, 0, 0 );
1096 Debug( LDAP_DEBUG_ANY,
1097 "send_search_entry: conn %lu ber_printf failed\n",
1098 op->o_connid, 0, 0 );
1101 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1102 send_ldap_error( op, rs, LDAP_OTHER, "encode end error" );
1107 /* NOTE: moved before overlays callback circling because
1108 * they may modify entry and other stuff in rs */
1109 if ( rs->sr_operational_attrs != NULL && op->o_vrFilter != NULL ) {
1113 for ( a = rs->sr_operational_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
1114 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ ) k++;
1117 size = i * sizeof(char *) + k;
1119 char *a_flags, **tmp;
1122 * Reuse previous memory - we likely need less space
1123 * for operational attributes
1125 tmp = slap_sl_realloc( e_flags, i * sizeof(char *) + k,
1127 if ( tmp == NULL ) {
1129 LDAP_LOG( OPERATION, ERR,
1130 "send_search_entry: conn %lu "
1131 "not enough memory "
1132 "for matched values filtering\n",
1133 op->o_connid, 0, 0);
1135 Debug( LDAP_DEBUG_ANY,
1136 "send_search_entry: conn %lu "
1137 "not enough memory "
1138 "for matched values filtering\n",
1139 op->o_connid, 0, 0 );
1141 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1142 send_ldap_error( op, rs, LDAP_OTHER,
1143 "not enough memory for matched values filtering" );
1147 a_flags = (char *)(e_flags + i);
1148 memset( a_flags, 0, k );
1149 for ( a = rs->sr_operational_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
1150 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ );
1151 e_flags[i] = a_flags;
1154 rc = filter_matched_values(op, rs->sr_operational_attrs, &e_flags) ;
1158 LDAP_LOG( OPERATION, ERR,
1159 "send_search_entry: conn %lu "
1160 "matched values filtering failed\n",
1161 op->o_connid ? op->o_connid : 0, 0, 0);
1163 Debug( LDAP_DEBUG_ANY,
1164 "send_search_entry: conn %lu "
1165 "matched values filtering failed\n",
1166 op->o_connid ? op->o_connid : 0, 0, 0);
1168 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1169 send_ldap_error( op, rs, LDAP_OTHER,
1170 "matched values filtering error" );
1176 for (a = rs->sr_operational_attrs, j=0; a != NULL; a = a->a_next, j++ ) {
1177 AttributeDescription *desc = a->a_desc;
1179 if ( rs->sr_attrs == NULL ) {
1180 /* all attrs request, skip operational attributes */
1181 if( is_at_operational( desc->ad_type ) ) {
1186 /* specific attrs requested */
1187 if( is_at_operational( desc->ad_type ) ) {
1188 if ( !SLAP_OPATTRS( rs->sr_attr_flags ) &&
1189 !ad_inlist( desc, rs->sr_attrs ) )
1194 if ( !userattrs && !ad_inlist( desc, rs->sr_attrs ) ) {
1200 if ( ! access_allowed( op, rs->sr_entry, desc, NULL,
1201 ACL_READ, &acl_state ) )
1204 LDAP_LOG( ACL, INFO,
1205 "send_search_entry: conn %lu "
1206 "access to attribute %s not allowed\n",
1207 op->o_connid, desc->ad_cname.bv_val, 0 );
1209 Debug( LDAP_DEBUG_ACL,
1210 "send_search_entry: conn %lu "
1211 "access to attribute %s not allowed\n",
1212 op->o_connid, desc->ad_cname.bv_val, 0 );
1218 rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname );
1221 LDAP_LOG( OPERATION, ERR,
1222 "send_search_entry: conn %lu "
1223 "ber_printf failed\n", op->o_connid, 0, 0 );
1225 Debug( LDAP_DEBUG_ANY,
1226 "send_search_entry: conn %lu "
1227 "ber_printf failed\n", op->o_connid, 0, 0 );
1230 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1231 send_ldap_error( op, rs, LDAP_OTHER,
1232 "encoding description error" );
1236 if ( ! op->ors_attrsonly ) {
1237 for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
1238 if ( ! access_allowed( op, rs->sr_entry,
1239 desc, &a->a_vals[i], ACL_READ, &acl_state ) )
1242 LDAP_LOG( ACL, INFO,
1243 "send_search_entry: conn %lu "
1244 "access to %s, value %d not allowed\n",
1245 op->o_connid, desc->ad_cname.bv_val, i );
1247 Debug( LDAP_DEBUG_ACL,
1248 "send_search_entry: conn %lu "
1249 "access to %s, value %d not allowed\n",
1250 op->o_connid, desc->ad_cname.bv_val, i );
1256 if ( op->o_vrFilter && e_flags[j][i] == 0 ){
1260 if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -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,
1273 "encoding values error" );
1279 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
1281 LDAP_LOG( OPERATION, ERR,
1282 "send_search_entry: conn %lu ber_printf failed\n",
1283 op->o_connid, 0, 0 );
1285 Debug( LDAP_DEBUG_ANY,
1286 "send_search_entry: conn %lu ber_printf failed\n",
1287 op->o_connid, 0, 0 );
1290 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1291 send_ldap_error( op, rs, LDAP_OTHER, "encode end error" );
1298 * First, setup the computed attribute context that is
1299 * passed to all plugins.
1302 ctx.cac_pb = op->o_pb;
1303 ctx.cac_attrs = rs->sr_attrs;
1304 ctx.cac_attrsonly = op->ors_attrsonly;
1305 ctx.cac_userattrs = userattrs;
1306 ctx.cac_opattrs = rs->sr_attr_flags;
1307 ctx.cac_acl_state = acl_state;
1308 ctx.cac_private = (void *)ber;
1311 * For each client requested attribute, call the plugins.
1313 if ( rs->sr_attrs != NULL ) {
1314 for ( anp = rs->sr_attrs; anp->an_name.bv_val != NULL; anp++ ) {
1315 rc = compute_evaluator( &ctx, anp->an_name.bv_val,
1316 rs->sr_entry, slapi_int_compute_output_ber );
1317 if ( rc == 1 ) break;
1321 * Technically we shouldn't be returning operational attributes
1322 * when the user requested only user attributes. We'll let the
1323 * plugin decide whether to be naughty or not.
1325 rc = compute_evaluator( &ctx, "*",
1326 rs->sr_entry, slapi_int_compute_output_ber );
1329 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1330 send_ldap_error( op, rs, LDAP_OTHER, "computed attribute error" );
1334 #endif /* LDAP_SLAPI */
1338 slap_sl_free( e_flags, op->o_tmpmemctx );
1342 rc = ber_printf( ber, /*{{*/ "}N}" );
1345 rc = send_ldap_controls( op, ber, rs->sr_ctrls );
1349 #ifdef LDAP_CONNECTIONLESS
1350 if( op->o_conn && op->o_conn->c_is_udp ) {
1351 if ( op->o_protocol != LDAP_VERSION2 ) {
1352 rc = ber_printf( ber, /*{*/ "N}" );
1356 if ( op->o_res_ber == NULL ) {
1357 rc = ber_printf( ber, /*{*/ "N}" );
1363 LDAP_LOG( OPERATION, ERR,
1364 "send_search_entry: conn %lu ber_printf failed\n",
1365 op->o_connid, 0, 0 );
1367 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1370 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1371 send_ldap_error( op, rs, LDAP_OTHER, "encode entry end error" );
1376 if ( op->o_res_ber == NULL ) {
1377 bytes = send_ldap_ber( op->o_conn, ber );
1378 ber_free_buf( ber );
1382 LDAP_LOG( OPERATION, ERR,
1383 "send_search_entry: conn %lu ber write failed.\n",
1384 op->o_connid, 0, 0 );
1386 Debug( LDAP_DEBUG_ANY,
1387 "send_search_entry: conn %lu ber write failed.\n",
1388 op->o_connid, 0, 0 );
1396 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1397 num_bytes_sent += bytes;
1400 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1403 Statslog( LDAP_DEBUG_STATS2, "conn=%lu op=%lu ENTRY dn=\"%s\"\n",
1404 op->o_connid, op->o_opid, rs->sr_entry->e_dn, 0, 0 );
1407 LDAP_LOG( OPERATION, ENTRY,
1408 "send_search_entry: conn %lu exit.\n", op->o_connid, 0, 0 );
1410 Debug( LDAP_DEBUG_TRACE,
1411 "<= send_search_entry: conn %lu exit.\n", op->o_connid, 0, 0 );
1417 if ( op->o_callback ) {
1419 slap_callback *sc = op->o_callback,
1420 *sc_next = op->o_callback;
1422 for ( sc_next = op->o_callback; sc_next; op->o_callback = sc_next) {
1423 sc_next = op->o_callback->sc_next;
1424 if ( op->o_callback->sc_cleanup ) {
1425 (void)op->o_callback->sc_cleanup( op, rs );
1426 if ( first && op->o_callback == NULL ) {
1433 op->o_callback = sc;
1437 slap_sl_free( e_flags, op->o_tmpmemctx );
1440 if ( rs->sr_operational_attrs ) {
1441 attrs_free( rs->sr_operational_attrs );
1442 rs->sr_operational_attrs = NULL;
1444 rs->sr_attr_flags = SLAP_ATTRS_UNDEFINED;
1446 /* FIXME: I think rs->sr_type should be explicitly set to
1447 * REP_SEARCH here. That's what it was when we entered this
1448 * function. send_ldap_error may have changed it, but we
1449 * should set it back so that the cleanup functions know
1450 * what they're doing.
1452 if ( op->o_tag == LDAP_REQ_SEARCH && rs->sr_type == REP_SEARCH
1454 && ( rs->sr_flags & REP_ENTRY_MUSTBEFREED ) )
1456 entry_free( rs->sr_entry );
1457 rs->sr_entry = NULL;
1458 rs->sr_flags &= ~REP_ENTRY_MUSTBEFREED;
1465 slap_send_search_reference( Operation *op, SlapReply *rs )
1467 BerElementBuffer berbuf;
1468 BerElement *ber = (BerElement *) &berbuf;
1472 AttributeDescription *ad_ref = slap_schema.si_ad_ref;
1473 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
1475 rs->sr_type = REP_SEARCHREF;
1476 if ( op->o_callback ) {
1478 slap_callback *sc = op->o_callback,
1479 *sc_next = op->o_callback;
1481 rc = SLAP_CB_CONTINUE;
1482 for ( sc_next = op->o_callback; sc_next; op->o_callback = sc_next) {
1483 sc_next = op->o_callback->sc_next;
1484 if ( op->o_callback->sc_response ) {
1485 rc = op->o_callback->sc_response( op, rs );
1486 if ( first && op->o_callback == NULL ) {
1489 if ( rc != SLAP_CB_CONTINUE ) break;
1494 op->o_callback = sc;
1495 if ( rc != SLAP_CB_CONTINUE ) goto rel;
1499 LDAP_LOG( OPERATION, ENTRY,
1500 "send_search_reference: conn %lu dn=\"%s\"\n",
1502 rs->sr_entry ? rs->sr_entry->e_name.bv_val : "(null)", 0 );
1504 Debug( LDAP_DEBUG_TRACE,
1505 "=> send_search_reference: dn=\"%s\"\n",
1506 rs->sr_entry ? rs->sr_entry->e_name.bv_val : "(null)", 0, 0 );
1509 if ( rs->sr_entry && ! access_allowed( op, rs->sr_entry,
1510 ad_entry, NULL, ACL_READ, NULL ) )
1513 LDAP_LOG( ACL, INFO,
1514 "send_search_reference: conn %lu "
1515 "access to entry %s not allowed\n",
1516 op->o_connid, rs->sr_entry->e_dn, 0 );
1518 Debug( LDAP_DEBUG_ACL,
1519 "send_search_reference: access to entry not allowed\n",
1526 if ( rs->sr_entry && ! access_allowed( op, rs->sr_entry,
1527 ad_ref, NULL, ACL_READ, NULL ) )
1530 LDAP_LOG( ACL, INFO,
1531 "send_search_reference: conn %lu access "
1532 "to reference not allowed.\n", op->o_connid, 0, 0 );
1534 Debug( LDAP_DEBUG_ACL,
1535 "send_search_reference: access "
1536 "to reference not allowed\n",
1543 #ifdef LDAP_CONTROL_X_DOMAIN_SCOPE
1544 if( op->o_domain_scope ) {
1546 LDAP_LOG( OPERATION, ERR,
1547 "send_search_reference: conn %lu domainScope control in (%s).\n",
1548 op->o_connid, rs->sr_entry->e_dn, 0 );
1550 Debug( LDAP_DEBUG_ANY,
1551 "send_search_reference: domainScope control in (%s)\n",
1552 rs->sr_entry->e_dn, 0, 0 );
1559 if( rs->sr_ref == NULL ) {
1561 LDAP_LOG( OPERATION, ERR,
1562 "send_search_reference: conn %lu null ref in (%s).\n",
1563 op->o_connid, rs->sr_entry ? rs->sr_entry->e_dn : "(null)", 0 );
1565 Debug( LDAP_DEBUG_ANY,
1566 "send_search_reference: null ref in (%s)\n",
1567 rs->sr_entry ? rs->sr_entry->e_dn : "(null)", 0, 0 );
1573 if( op->o_protocol < LDAP_VERSION3 ) {
1575 /* save the references for the result */
1576 if( rs->sr_ref[0].bv_val != NULL ) {
1577 if( value_add( &rs->sr_v2ref, rs->sr_ref ) )
1583 #ifdef LDAP_CONNECTIONLESS
1584 if( op->o_conn && op->o_conn->c_is_udp ) {
1585 ber = op->o_res_ber;
1589 ber_init_w_nullc( ber, LBER_USE_DER );
1590 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
1593 rc = ber_printf( ber, "{it{W}" /*"}"*/ , op->o_msgid,
1594 LDAP_RES_SEARCH_REFERENCE, rs->sr_ref );
1597 rc = send_ldap_controls( op, ber, rs->sr_ctrls );
1601 rc = ber_printf( ber, /*"{"*/ "N}" );
1606 LDAP_LOG( OPERATION, ERR,
1607 "send_search_reference: conn %lu "
1608 "ber_printf failed.\n", op->o_connid, 0, 0 );
1610 Debug( LDAP_DEBUG_ANY,
1611 "send_search_reference: ber_printf failed\n", 0, 0, 0 );
1614 #ifdef LDAP_CONNECTIONLESS
1615 if (!op->o_conn || op->o_conn->c_is_udp == 0)
1617 ber_free_buf( ber );
1618 send_ldap_error( op, rs, LDAP_OTHER, "encode DN error" );
1622 #ifdef LDAP_CONNECTIONLESS
1623 if (!op->o_conn || op->o_conn->c_is_udp == 0) {
1625 bytes = send_ldap_ber( op->o_conn, ber );
1626 ber_free_buf( ber );
1628 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1629 num_bytes_sent += bytes;
1632 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1633 #ifdef LDAP_CONNECTIONLESS
1637 Statslog( LDAP_DEBUG_STATS2, "conn=%lu op=%lu REF dn=\"%s\"\n",
1638 op->o_connid, op->o_opid, rs->sr_entry ? rs->sr_entry->e_dn : "(null)", 0, 0 );
1641 LDAP_LOG( OPERATION, ENTRY,
1642 "send_search_reference: conn %lu exit.\n", op->o_connid, 0, 0 );
1644 Debug( LDAP_DEBUG_TRACE, "<= send_search_reference\n", 0, 0, 0 );
1648 if ( op->o_callback ) {
1650 slap_callback *sc = op->o_callback,
1651 *sc_next = op->o_callback;
1653 for ( sc_next = op->o_callback; sc_next; op->o_callback = sc_next) {
1654 sc_next = op->o_callback->sc_next;
1655 if ( op->o_callback->sc_cleanup ) {
1656 (void)op->o_callback->sc_cleanup( op, rs );
1657 if ( first && op->o_callback == NULL ) {
1664 op->o_callback = sc;
1681 *code = LDAP_SUCCESS;
1685 if ( strncasecmp( s, "RESULT", STRLENOF( "RESULT" ) ) != 0 ) {
1687 LDAP_LOG( OPERATION, INFO,
1688 "str2result: (%s), expecting \"RESULT\"\n", s, 0, 0 );
1690 Debug( LDAP_DEBUG_ANY, "str2result (%s) expecting \"RESULT\"\n",
1698 while ( (s = strchr( s, '\n' )) != NULL ) {
1703 if ( (c = strchr( s, ':' )) != NULL ) {
1707 if ( strncasecmp( s, "code", STRLENOF( "code" ) ) == 0 ) {
1711 } else if ( strncasecmp( s, "matched", STRLENOF( "matched" ) ) == 0 ) {
1715 } else if ( strncasecmp( s, "info", STRLENOF( "info" ) ) == 0 ) {
1721 LDAP_LOG( OPERATION, INFO, "str2result: (%s) unknown.\n", s, 0, 0 );
1723 Debug( LDAP_DEBUG_ANY, "str2result (%s) unknown\n",
1734 int slap_read_controls(
1738 const struct berval *oid,
1739 LDAPControl **ctrl )
1743 BerElementBuffer berbuf;
1744 BerElement *ber = (BerElement *) &berbuf;
1750 LDAP_LOG( OPERATION, INFO, "slap_read_controls: (%s) %s\n",
1751 oid->bv_val, e->e_dn, 0 );
1753 Debug( LDAP_DEBUG_ANY, "slap_read_controls: (%s) %s\n",
1754 oid->bv_val, e->e_dn, 0 );
1758 rs->sr_attrs = ( oid == &slap_pre_read_bv ) ?
1759 op->o_preread_attrs : op->o_postread_attrs;
1761 entry_flatsize( rs->sr_entry, &siz, &len, 0 );
1762 bv.bv_len = siz + len;
1763 bv.bv_val = op->o_tmpalloc(bv.bv_len, op->o_tmpmemctx );
1765 ber_init2( ber, &bv, LBER_USE_DER );
1766 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
1768 /* create new operation */
1771 myop.o_res_ber = ber;
1773 rc = slap_send_search_entry( &myop, rs );
1776 rc = ber_flatten2( ber, &c.ldctl_value, 0 );
1778 if( rc == LBER_ERROR ) return LDAP_OTHER;
1780 c.ldctl_oid = oid->bv_val;
1781 c.ldctl_iscritical = 0;
1783 if ( ctrl == NULL ) {
1785 *ctrl = (LDAPControl *) slap_sl_calloc( 1, sizeof(LDAPControl), NULL );
1787 /* retry: free previous try */
1788 slap_sl_free( (*ctrl)->ldctl_value.bv_val, &op->o_tmpmemctx );
1792 return LDAP_SUCCESS;
1795 /* Map API errors to protocol errors... */
1797 slap_map_api2result( SlapReply *rs )
1799 switch(rs->sr_err) {
1800 case LDAP_SERVER_DOWN:
1801 return LDAP_UNAVAILABLE;
1802 case LDAP_LOCAL_ERROR:
1804 case LDAP_ENCODING_ERROR:
1805 case LDAP_DECODING_ERROR:
1806 return LDAP_PROTOCOL_ERROR;
1808 return LDAP_UNAVAILABLE;
1809 case LDAP_AUTH_UNKNOWN:
1810 return LDAP_AUTH_METHOD_NOT_SUPPORTED;
1811 case LDAP_FILTER_ERROR:
1812 rs->sr_text = "Filter error";
1814 case LDAP_USER_CANCELLED:
1815 rs->sr_text = "User cancelled";
1817 case LDAP_PARAM_ERROR:
1818 return LDAP_PROTOCOL_ERROR;
1819 case LDAP_NO_MEMORY:
1821 case LDAP_CONNECT_ERROR:
1822 return LDAP_UNAVAILABLE;
1823 case LDAP_NOT_SUPPORTED:
1824 return LDAP_UNWILLING_TO_PERFORM;
1825 case LDAP_CONTROL_NOT_FOUND:
1826 return LDAP_PROTOCOL_ERROR;
1827 case LDAP_NO_RESULTS_RETURNED:
1828 return LDAP_NO_SUCH_OBJECT;
1829 case LDAP_MORE_RESULTS_TO_RETURN:
1830 rs->sr_text = "More results to return";
1832 case LDAP_CLIENT_LOOP:
1833 case LDAP_REFERRAL_LIMIT_EXCEEDED:
1834 return LDAP_LOOP_DETECT;
1836 if ( LDAP_API_ERROR(rs->sr_err) ) return LDAP_OTHER;