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 rs->sr_attr_flags = slap_attr_flags( rs->sr_attrs );
791 rc = backend_operational( op, rs );
796 if ( op->o_callback ) {
798 slap_callback *sc = op->o_callback,
799 *sc_next = op->o_callback;
801 rc = SLAP_CB_CONTINUE;
802 for ( sc_next = op->o_callback; sc_next; op->o_callback = sc_next) {
803 sc_next = op->o_callback->sc_next;
804 if ( op->o_callback->sc_response ) {
805 rc = op->o_callback->sc_response( op, rs );
806 if ( first && op->o_callback == NULL ) {
809 if ( rc != SLAP_CB_CONTINUE ) break;
815 if ( rc != SLAP_CB_CONTINUE ) goto error_return;
819 LDAP_LOG( OPERATION, ENTRY, "send_search_entry: conn %lu dn=\"%s\"%s\n",
820 op->o_connid, rs->sr_entry->e_name.bv_val,
821 op->ors_attrsonly ? " (attrsOnly)" : "" );
823 Debug( LDAP_DEBUG_TRACE, "=> send_search_entry: conn %lu dn=\"%s\"%s\n",
824 op->o_connid, rs->sr_entry->e_name.bv_val,
825 op->ors_attrsonly ? " (attrsOnly)" : "" );
828 if ( !access_allowed( op, rs->sr_entry, ad_entry, NULL, ACL_READ, NULL )) {
831 "send_search_entry: conn %lu access to entry (%s) not allowed\n",
832 op->o_connid, rs->sr_entry->e_name.bv_val, 0 );
834 Debug( LDAP_DEBUG_ACL,
835 "send_search_entry: conn %lu access to entry (%s) not allowed\n",
836 op->o_connid, rs->sr_entry->e_name.bv_val, 0 );
843 edn = rs->sr_entry->e_nname.bv_val;
845 if ( op->o_res_ber ) {
846 /* read back control or LDAP_CONNECTIONLESS */
852 entry_flatsize( rs->sr_entry, &siz, &len, 0 );
853 bv.bv_len = siz + len;
854 bv.bv_val = op->o_tmpalloc(bv.bv_len, op->o_tmpmemctx );
856 ber_init2( ber, &bv, LBER_USE_DER );
857 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
860 #ifdef LDAP_CONNECTIONLESS
861 if ( op->o_conn && op->o_conn->c_is_udp ) {
863 if ( op->o_protocol == LDAP_VERSION2 ) {
864 rc = ber_printf(ber, "t{O{" /*}}*/,
865 LDAP_RES_SEARCH_ENTRY, &rs->sr_entry->e_name );
867 rc = ber_printf( ber, "{it{O{" /*}}}*/, op->o_msgid,
868 LDAP_RES_SEARCH_ENTRY, &rs->sr_entry->e_name );
872 if ( op->o_res_ber ) {
873 /* read back control */
874 rc = ber_printf( ber, "{O{" /*}}*/, &rs->sr_entry->e_name );
876 rc = ber_printf( ber, "{it{O{" /*}}}*/, op->o_msgid,
877 LDAP_RES_SEARCH_ENTRY, &rs->sr_entry->e_name );
882 LDAP_LOG( OPERATION, ERR,
883 "send_search_entry: conn %lu ber_printf failed\n",
884 op->o_connid, 0, 0 );
886 Debug( LDAP_DEBUG_ANY,
887 "send_search_entry: conn %lu ber_printf failed\n",
888 op->o_connid, 0, 0 );
891 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
892 send_ldap_error( op, rs, LDAP_OTHER, "encoding DN error" );
896 /* check for special all user attributes ("*") type */
897 userattrs = SLAP_USERATTRS( rs->sr_attr_flags );
899 /* create an array of arrays of flags. Each flag corresponds
900 * to particular value of attribute and equals 1 if value matches
901 * to ValuesReturnFilter or 0 if not
903 if ( op->o_vrFilter != NULL ) {
907 for ( a = rs->sr_entry->e_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
908 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ ) k++;
911 size = i * sizeof(char *) + k;
914 e_flags = slap_sl_calloc ( 1, i * sizeof(char *) + k, op->o_tmpmemctx );
915 if( e_flags == NULL ) {
917 LDAP_LOG( OPERATION, ERR,
918 "send_search_entry: conn %lu slap_sl_calloc failed\n",
919 op->o_connid ? op->o_connid : 0, 0, 0 );
921 Debug( LDAP_DEBUG_ANY,
922 "send_search_entry: conn %lu slap_sl_calloc failed\n",
923 op->o_connid ? op->o_connid : 0, 0, 0 );
927 send_ldap_error( op, rs, LDAP_OTHER, "out of memory" );
930 a_flags = (char *)(e_flags + i);
931 memset( a_flags, 0, k );
932 for ( a=rs->sr_entry->e_attrs, i=0; a != NULL; a=a->a_next, i++ ) {
933 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ );
934 e_flags[i] = a_flags;
938 rc = filter_matched_values(op, rs->sr_entry->e_attrs, &e_flags) ;
941 LDAP_LOG( OPERATION, ERR, "send_search_entry: "
942 "conn %lu matched values filtering failed\n",
943 op->o_connid ? op->o_connid : 0, 0, 0 );
945 Debug( LDAP_DEBUG_ANY, "send_search_entry: "
946 "conn %lu matched values filtering failed\n",
947 op->o_connid ? op->o_connid : 0, 0, 0 );
949 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
950 send_ldap_error( op, rs, LDAP_OTHER,
951 "matched values filtering error" );
957 for ( a = rs->sr_entry->e_attrs, j = 0; a != NULL; a = a->a_next, j++ ) {
958 AttributeDescription *desc = a->a_desc;
961 if ( rs->sr_attrs == NULL ) {
962 /* all attrs request, skip operational attributes */
963 if( is_at_operational( desc->ad_type ) ) {
968 /* specific attrs requested */
969 if ( is_at_operational( desc->ad_type ) ) {
970 if ( !SLAP_OPATTRS( rs->sr_attr_flags ) &&
971 !ad_inlist( desc, rs->sr_attrs ) )
977 if ( !userattrs && !ad_inlist( desc, rs->sr_attrs ) )
984 if ( op->ors_attrsonly ) {
985 if ( ! access_allowed( op, rs->sr_entry, desc, NULL,
986 ACL_READ, &acl_state ) )
990 "send_search_entry: conn %lu access to attribute %s not "
991 "allowed\n", op->o_connid, desc->ad_cname.bv_val, 0 );
993 Debug( LDAP_DEBUG_ACL, "send_search_entry: "
994 "conn %lu access to attribute %s not allowed\n",
995 op->o_connid, desc->ad_cname.bv_val, 0 );
1000 if (( rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname )) == -1 ) {
1002 LDAP_LOG( OPERATION, ERR,
1003 "send_search_entry: conn %lu ber_printf failed\n",
1004 op->o_connid, 0, 0 );
1006 Debug( LDAP_DEBUG_ANY,
1007 "send_search_entry: conn %lu ber_printf failed\n",
1008 op->o_connid, 0, 0 );
1011 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1012 send_ldap_error( op, rs, LDAP_OTHER,
1013 "encoding description error");
1020 for ( i = 0; a->a_nvals[i].bv_val != NULL; i++ ) {
1021 if ( ! access_allowed( op, rs->sr_entry,
1022 desc, &a->a_nvals[i], ACL_READ, &acl_state ) )
1025 LDAP_LOG( ACL, INFO,
1026 "send_search_entry: conn %lu "
1027 "access to attribute %s, value #%d not allowed\n",
1028 op->o_connid, desc->ad_cname.bv_val, i );
1030 Debug( LDAP_DEBUG_ACL,
1031 "send_search_entry: conn %lu "
1032 "access to attribute %s, value #%d not allowed\n",
1033 op->o_connid, desc->ad_cname.bv_val, i );
1039 if ( op->o_vrFilter && e_flags[j][i] == 0 ){
1046 if (( rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname )) == -1 ) {
1048 LDAP_LOG( OPERATION, ERR,
1049 "send_search_entry: conn %lu ber_printf failed\n",
1050 op->o_connid, 0, 0 );
1052 Debug( LDAP_DEBUG_ANY,
1053 "send_search_entry: conn %lu ber_printf failed\n",
1054 op->o_connid, 0, 0 );
1057 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1058 send_ldap_error( op, rs, LDAP_OTHER,
1059 "encoding description error");
1063 if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
1065 LDAP_LOG( OPERATION, ERR,
1066 "send_search_entry: conn %lu "
1067 "ber_printf failed.\n", op->o_connid, 0, 0 );
1069 Debug( LDAP_DEBUG_ANY,
1070 "send_search_entry: conn %lu "
1071 "ber_printf failed.\n", op->o_connid, 0, 0 );
1074 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1075 send_ldap_error( op, rs, LDAP_OTHER,
1076 "encoding values error" );
1082 if ( finish && ( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
1084 LDAP_LOG( OPERATION, ERR,
1085 "send_search_entry: conn %lu ber_printf failed\n",
1086 op->o_connid, 0, 0 );
1088 Debug( LDAP_DEBUG_ANY,
1089 "send_search_entry: conn %lu ber_printf failed\n",
1090 op->o_connid, 0, 0 );
1093 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1094 send_ldap_error( op, rs, LDAP_OTHER, "encode end error" );
1099 /* NOTE: moved before overlays callback circling because
1100 * they may modify entry and other stuff in rs */
1101 if ( rs->sr_operational_attrs != NULL && op->o_vrFilter != NULL ) {
1105 for ( a = rs->sr_operational_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
1106 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ ) k++;
1109 size = i * sizeof(char *) + k;
1111 char *a_flags, **tmp;
1114 * Reuse previous memory - we likely need less space
1115 * for operational attributes
1117 tmp = slap_sl_realloc( e_flags, i * sizeof(char *) + k,
1119 if ( tmp == NULL ) {
1121 LDAP_LOG( OPERATION, ERR,
1122 "send_search_entry: conn %lu "
1123 "not enough memory "
1124 "for matched values filtering\n",
1125 op->o_connid, 0, 0);
1127 Debug( LDAP_DEBUG_ANY,
1128 "send_search_entry: conn %lu "
1129 "not enough memory "
1130 "for matched values filtering\n",
1131 op->o_connid, 0, 0 );
1133 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1134 send_ldap_error( op, rs, LDAP_OTHER,
1135 "not enough memory for matched values filtering" );
1139 a_flags = (char *)(e_flags + i);
1140 memset( a_flags, 0, k );
1141 for ( a = rs->sr_operational_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
1142 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ );
1143 e_flags[i] = a_flags;
1146 rc = filter_matched_values(op, rs->sr_operational_attrs, &e_flags) ;
1150 LDAP_LOG( OPERATION, ERR,
1151 "send_search_entry: conn %lu "
1152 "matched values filtering failed\n",
1153 op->o_connid ? op->o_connid : 0, 0, 0);
1155 Debug( LDAP_DEBUG_ANY,
1156 "send_search_entry: conn %lu "
1157 "matched values filtering failed\n",
1158 op->o_connid ? op->o_connid : 0, 0, 0);
1160 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1161 send_ldap_error( op, rs, LDAP_OTHER,
1162 "matched values filtering error" );
1168 for (a = rs->sr_operational_attrs, j=0; a != NULL; a = a->a_next, j++ ) {
1169 AttributeDescription *desc = a->a_desc;
1171 if ( rs->sr_attrs == NULL ) {
1172 /* all attrs request, skip operational attributes */
1173 if( is_at_operational( desc->ad_type ) ) {
1178 /* specific attrs requested */
1179 if( is_at_operational( desc->ad_type ) ) {
1180 if ( !SLAP_OPATTRS( rs->sr_attr_flags ) &&
1181 !ad_inlist( desc, rs->sr_attrs ) )
1186 if ( !userattrs && !ad_inlist( desc, rs->sr_attrs ) ) {
1192 if ( ! access_allowed( op, rs->sr_entry, desc, NULL,
1193 ACL_READ, &acl_state ) )
1196 LDAP_LOG( ACL, INFO,
1197 "send_search_entry: conn %lu "
1198 "access to attribute %s not allowed\n",
1199 op->o_connid, desc->ad_cname.bv_val, 0 );
1201 Debug( LDAP_DEBUG_ACL,
1202 "send_search_entry: conn %lu "
1203 "access to attribute %s not allowed\n",
1204 op->o_connid, desc->ad_cname.bv_val, 0 );
1210 rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname );
1213 LDAP_LOG( OPERATION, ERR,
1214 "send_search_entry: conn %lu "
1215 "ber_printf failed\n", op->o_connid, 0, 0 );
1217 Debug( LDAP_DEBUG_ANY,
1218 "send_search_entry: conn %lu "
1219 "ber_printf failed\n", op->o_connid, 0, 0 );
1222 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1223 send_ldap_error( op, rs, LDAP_OTHER,
1224 "encoding description error" );
1228 if ( ! op->ors_attrsonly ) {
1229 for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
1230 if ( ! access_allowed( op, rs->sr_entry,
1231 desc, &a->a_vals[i], ACL_READ, &acl_state ) )
1234 LDAP_LOG( ACL, INFO,
1235 "send_search_entry: conn %lu "
1236 "access to %s, value %d not allowed\n",
1237 op->o_connid, desc->ad_cname.bv_val, i );
1239 Debug( LDAP_DEBUG_ACL,
1240 "send_search_entry: conn %lu "
1241 "access to %s, value %d not allowed\n",
1242 op->o_connid, desc->ad_cname.bv_val, i );
1248 if ( op->o_vrFilter && e_flags[j][i] == 0 ){
1252 if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
1254 LDAP_LOG( OPERATION, ERR,
1255 "send_search_entry: conn %lu ber_printf failed\n",
1256 op->o_connid, 0, 0 );
1258 Debug( LDAP_DEBUG_ANY,
1259 "send_search_entry: conn %lu ber_printf failed\n",
1260 op->o_connid, 0, 0 );
1263 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1264 send_ldap_error( op, rs, LDAP_OTHER,
1265 "encoding values error" );
1271 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
1273 LDAP_LOG( OPERATION, ERR,
1274 "send_search_entry: conn %lu ber_printf failed\n",
1275 op->o_connid, 0, 0 );
1277 Debug( LDAP_DEBUG_ANY,
1278 "send_search_entry: conn %lu ber_printf failed\n",
1279 op->o_connid, 0, 0 );
1282 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1283 send_ldap_error( op, rs, LDAP_OTHER, "encode end error" );
1290 * First, setup the computed attribute context that is
1291 * passed to all plugins.
1294 ctx.cac_pb = op->o_pb;
1295 ctx.cac_attrs = rs->sr_attrs;
1296 ctx.cac_attrsonly = op->ors_attrsonly;
1297 ctx.cac_userattrs = userattrs;
1298 ctx.cac_opattrs = rs->sr_attr_flags;
1299 ctx.cac_acl_state = acl_state;
1300 ctx.cac_private = (void *)ber;
1303 * For each client requested attribute, call the plugins.
1305 if ( rs->sr_attrs != NULL ) {
1306 for ( anp = rs->sr_attrs; anp->an_name.bv_val != NULL; anp++ ) {
1307 rc = compute_evaluator( &ctx, anp->an_name.bv_val,
1308 rs->sr_entry, slapi_int_compute_output_ber );
1309 if ( rc == 1 ) break;
1313 * Technically we shouldn't be returning operational attributes
1314 * when the user requested only user attributes. We'll let the
1315 * plugin decide whether to be naughty or not.
1317 rc = compute_evaluator( &ctx, "*",
1318 rs->sr_entry, slapi_int_compute_output_ber );
1321 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1322 send_ldap_error( op, rs, LDAP_OTHER, "computed attribute error" );
1326 #endif /* LDAP_SLAPI */
1330 slap_sl_free( e_flags, op->o_tmpmemctx );
1334 rc = ber_printf( ber, /*{{*/ "}N}" );
1337 rc = send_ldap_controls( op, ber, rs->sr_ctrls );
1341 #ifdef LDAP_CONNECTIONLESS
1342 if( op->o_conn && op->o_conn->c_is_udp ) {
1343 if ( op->o_protocol != LDAP_VERSION2 ) {
1344 rc = ber_printf( ber, /*{*/ "N}" );
1348 if ( op->o_res_ber == NULL ) {
1349 rc = ber_printf( ber, /*{*/ "N}" );
1355 LDAP_LOG( OPERATION, ERR,
1356 "send_search_entry: conn %lu ber_printf failed\n",
1357 op->o_connid, 0, 0 );
1359 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1362 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1363 send_ldap_error( op, rs, LDAP_OTHER, "encode entry end error" );
1368 if ( op->o_res_ber == NULL ) {
1369 bytes = send_ldap_ber( op->o_conn, ber );
1370 ber_free_buf( ber );
1374 LDAP_LOG( OPERATION, ERR,
1375 "send_search_entry: conn %lu ber write failed.\n",
1376 op->o_connid, 0, 0 );
1378 Debug( LDAP_DEBUG_ANY,
1379 "send_search_entry: conn %lu ber write failed.\n",
1380 op->o_connid, 0, 0 );
1388 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1389 num_bytes_sent += bytes;
1392 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1395 Statslog( LDAP_DEBUG_STATS2, "conn=%lu op=%lu ENTRY dn=\"%s\"\n",
1396 op->o_connid, op->o_opid, rs->sr_entry->e_dn, 0, 0 );
1399 LDAP_LOG( OPERATION, ENTRY,
1400 "send_search_entry: conn %lu exit.\n", op->o_connid, 0, 0 );
1402 Debug( LDAP_DEBUG_TRACE,
1403 "<= send_search_entry: conn %lu exit.\n", op->o_connid, 0, 0 );
1409 if ( op->o_callback ) {
1411 slap_callback *sc = op->o_callback,
1412 *sc_next = op->o_callback;
1414 for ( sc_next = op->o_callback; sc_next; op->o_callback = sc_next) {
1415 sc_next = op->o_callback->sc_next;
1416 if ( op->o_callback->sc_cleanup ) {
1417 (void)op->o_callback->sc_cleanup( op, rs );
1418 if ( first && op->o_callback == NULL ) {
1425 op->o_callback = sc;
1429 slap_sl_free( e_flags, op->o_tmpmemctx );
1432 if ( rs->sr_operational_attrs ) {
1433 attrs_free( rs->sr_operational_attrs );
1434 rs->sr_operational_attrs = NULL;
1436 rs->sr_attr_flags = SLAP_ATTRS_UNDEFINED;
1438 /* FIXME: I think rs->sr_type should be explicitly set to
1439 * REP_SEARCH here. That's what it was when we entered this
1440 * function. send_ldap_error may have changed it, but we
1441 * should set it back so that the cleanup functions know
1442 * what they're doing.
1444 if ( op->o_tag == LDAP_REQ_SEARCH && rs->sr_type == REP_SEARCH
1446 && ( rs->sr_flags & REP_ENTRY_MUSTBEFREED ) )
1448 entry_free( rs->sr_entry );
1449 rs->sr_entry = NULL;
1450 rs->sr_flags &= ~REP_ENTRY_MUSTBEFREED;
1457 slap_send_search_reference( Operation *op, SlapReply *rs )
1459 BerElementBuffer berbuf;
1460 BerElement *ber = (BerElement *) &berbuf;
1464 AttributeDescription *ad_ref = slap_schema.si_ad_ref;
1465 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
1467 rs->sr_type = REP_SEARCHREF;
1468 if ( op->o_callback ) {
1470 slap_callback *sc = op->o_callback,
1471 *sc_next = op->o_callback;
1473 rc = SLAP_CB_CONTINUE;
1474 for ( sc_next = op->o_callback; sc_next; op->o_callback = sc_next) {
1475 sc_next = op->o_callback->sc_next;
1476 if ( op->o_callback->sc_response ) {
1477 rc = op->o_callback->sc_response( op, rs );
1478 if ( first && op->o_callback == NULL ) {
1481 if ( rc != SLAP_CB_CONTINUE ) break;
1486 op->o_callback = sc;
1487 if ( rc != SLAP_CB_CONTINUE ) goto rel;
1491 LDAP_LOG( OPERATION, ENTRY,
1492 "send_search_reference: conn %lu dn=\"%s\"\n",
1494 rs->sr_entry ? rs->sr_entry->e_name.bv_val : "(null)", 0 );
1496 Debug( LDAP_DEBUG_TRACE,
1497 "=> send_search_reference: dn=\"%s\"\n",
1498 rs->sr_entry ? rs->sr_entry->e_name.bv_val : "(null)", 0, 0 );
1501 if ( rs->sr_entry && ! access_allowed( op, rs->sr_entry,
1502 ad_entry, NULL, ACL_READ, NULL ) )
1505 LDAP_LOG( ACL, INFO,
1506 "send_search_reference: conn %lu "
1507 "access to entry %s not allowed\n",
1508 op->o_connid, rs->sr_entry->e_dn, 0 );
1510 Debug( LDAP_DEBUG_ACL,
1511 "send_search_reference: access to entry not allowed\n",
1518 if ( rs->sr_entry && ! access_allowed( op, rs->sr_entry,
1519 ad_ref, NULL, ACL_READ, NULL ) )
1522 LDAP_LOG( ACL, INFO,
1523 "send_search_reference: conn %lu access "
1524 "to reference not allowed.\n", op->o_connid, 0, 0 );
1526 Debug( LDAP_DEBUG_ACL,
1527 "send_search_reference: access "
1528 "to reference not allowed\n",
1535 #ifdef LDAP_CONTROL_X_DOMAIN_SCOPE
1536 if( op->o_domain_scope ) {
1538 LDAP_LOG( OPERATION, ERR,
1539 "send_search_reference: conn %lu domainScope control in (%s).\n",
1540 op->o_connid, rs->sr_entry->e_dn, 0 );
1542 Debug( LDAP_DEBUG_ANY,
1543 "send_search_reference: domainScope control in (%s)\n",
1544 rs->sr_entry->e_dn, 0, 0 );
1551 if( rs->sr_ref == NULL ) {
1553 LDAP_LOG( OPERATION, ERR,
1554 "send_search_reference: conn %lu null ref in (%s).\n",
1555 op->o_connid, rs->sr_entry ? rs->sr_entry->e_dn : "(null)", 0 );
1557 Debug( LDAP_DEBUG_ANY,
1558 "send_search_reference: null ref in (%s)\n",
1559 rs->sr_entry ? rs->sr_entry->e_dn : "(null)", 0, 0 );
1565 if( op->o_protocol < LDAP_VERSION3 ) {
1567 /* save the references for the result */
1568 if( rs->sr_ref[0].bv_val != NULL ) {
1569 if( value_add( &rs->sr_v2ref, rs->sr_ref ) )
1575 #ifdef LDAP_CONNECTIONLESS
1576 if( op->o_conn && op->o_conn->c_is_udp ) {
1577 ber = op->o_res_ber;
1581 ber_init_w_nullc( ber, LBER_USE_DER );
1582 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
1585 rc = ber_printf( ber, "{it{W}" /*"}"*/ , op->o_msgid,
1586 LDAP_RES_SEARCH_REFERENCE, rs->sr_ref );
1589 rc = send_ldap_controls( op, ber, rs->sr_ctrls );
1593 rc = ber_printf( ber, /*"{"*/ "N}" );
1598 LDAP_LOG( OPERATION, ERR,
1599 "send_search_reference: conn %lu "
1600 "ber_printf failed.\n", op->o_connid, 0, 0 );
1602 Debug( LDAP_DEBUG_ANY,
1603 "send_search_reference: ber_printf failed\n", 0, 0, 0 );
1606 #ifdef LDAP_CONNECTIONLESS
1607 if (!op->o_conn || op->o_conn->c_is_udp == 0)
1609 ber_free_buf( ber );
1610 send_ldap_error( op, rs, LDAP_OTHER, "encode DN error" );
1614 #ifdef LDAP_CONNECTIONLESS
1615 if (!op->o_conn || op->o_conn->c_is_udp == 0) {
1617 bytes = send_ldap_ber( op->o_conn, ber );
1618 ber_free_buf( ber );
1620 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1621 num_bytes_sent += bytes;
1624 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1625 #ifdef LDAP_CONNECTIONLESS
1629 Statslog( LDAP_DEBUG_STATS2, "conn=%lu op=%lu REF dn=\"%s\"\n",
1630 op->o_connid, op->o_opid, rs->sr_entry ? rs->sr_entry->e_dn : "(null)", 0, 0 );
1633 LDAP_LOG( OPERATION, ENTRY,
1634 "send_search_reference: conn %lu exit.\n", op->o_connid, 0, 0 );
1636 Debug( LDAP_DEBUG_TRACE, "<= send_search_reference\n", 0, 0, 0 );
1640 if ( op->o_callback ) {
1642 slap_callback *sc = op->o_callback,
1643 *sc_next = op->o_callback;
1645 for ( sc_next = op->o_callback; sc_next; op->o_callback = sc_next) {
1646 sc_next = op->o_callback->sc_next;
1647 if ( op->o_callback->sc_cleanup ) {
1648 (void)op->o_callback->sc_cleanup( op, rs );
1649 if ( first && op->o_callback == NULL ) {
1656 op->o_callback = sc;
1673 *code = LDAP_SUCCESS;
1677 if ( strncasecmp( s, "RESULT", STRLENOF( "RESULT" ) ) != 0 ) {
1679 LDAP_LOG( OPERATION, INFO,
1680 "str2result: (%s), expecting \"RESULT\"\n", s, 0, 0 );
1682 Debug( LDAP_DEBUG_ANY, "str2result (%s) expecting \"RESULT\"\n",
1690 while ( (s = strchr( s, '\n' )) != NULL ) {
1695 if ( (c = strchr( s, ':' )) != NULL ) {
1699 if ( strncasecmp( s, "code", STRLENOF( "code" ) ) == 0 ) {
1703 } else if ( strncasecmp( s, "matched", STRLENOF( "matched" ) ) == 0 ) {
1707 } else if ( strncasecmp( s, "info", STRLENOF( "info" ) ) == 0 ) {
1713 LDAP_LOG( OPERATION, INFO, "str2result: (%s) unknown.\n", s, 0, 0 );
1715 Debug( LDAP_DEBUG_ANY, "str2result (%s) unknown\n",
1726 int slap_read_controls(
1730 const struct berval *oid,
1731 LDAPControl **ctrl )
1735 BerElementBuffer berbuf;
1736 BerElement *ber = (BerElement *) &berbuf;
1742 LDAP_LOG( OPERATION, INFO, "slap_read_controls: (%s) %s\n",
1743 oid->bv_val, e->e_dn, 0 );
1745 Debug( LDAP_DEBUG_ANY, "slap_read_controls: (%s) %s\n",
1746 oid->bv_val, e->e_dn, 0 );
1750 rs->sr_attrs = ( oid == &slap_pre_read_bv ) ?
1751 op->o_preread_attrs : op->o_postread_attrs;
1753 entry_flatsize( rs->sr_entry, &siz, &len, 0 );
1754 bv.bv_len = siz + len;
1755 bv.bv_val = op->o_tmpalloc(bv.bv_len, op->o_tmpmemctx );
1757 ber_init2( ber, &bv, LBER_USE_DER );
1758 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
1760 /* create new operation */
1763 myop.o_res_ber = ber;
1765 rc = slap_send_search_entry( &myop, rs );
1768 rc = ber_flatten2( ber, &c.ldctl_value, 0 );
1770 if( rc == LBER_ERROR ) return LDAP_OTHER;
1772 c.ldctl_oid = oid->bv_val;
1773 c.ldctl_iscritical = 0;
1775 if ( ctrl == NULL ) {
1777 *ctrl = (LDAPControl *) slap_sl_calloc( 1, sizeof(LDAPControl), NULL );
1779 /* retry: free previous try */
1780 slap_sl_free( (*ctrl)->ldctl_value.bv_val, &op->o_tmpmemctx );
1784 return LDAP_SUCCESS;
1787 /* Map API errors to protocol errors... */
1789 slap_map_api2result( SlapReply *rs )
1791 switch(rs->sr_err) {
1792 case LDAP_SERVER_DOWN:
1793 return LDAP_UNAVAILABLE;
1794 case LDAP_LOCAL_ERROR:
1796 case LDAP_ENCODING_ERROR:
1797 case LDAP_DECODING_ERROR:
1798 return LDAP_PROTOCOL_ERROR;
1800 return LDAP_UNAVAILABLE;
1801 case LDAP_AUTH_UNKNOWN:
1802 return LDAP_AUTH_METHOD_NOT_SUPPORTED;
1803 case LDAP_FILTER_ERROR:
1804 rs->sr_text = "Filter error";
1806 case LDAP_USER_CANCELLED:
1807 rs->sr_text = "User cancelled";
1809 case LDAP_PARAM_ERROR:
1810 return LDAP_PROTOCOL_ERROR;
1811 case LDAP_NO_MEMORY:
1813 case LDAP_CONNECT_ERROR:
1814 return LDAP_UNAVAILABLE;
1815 case LDAP_NOT_SUPPORTED:
1816 return LDAP_UNWILLING_TO_PERFORM;
1817 case LDAP_CONTROL_NOT_FOUND:
1818 return LDAP_PROTOCOL_ERROR;
1819 case LDAP_NO_RESULTS_RETURNED:
1820 return LDAP_NO_SUCH_OBJECT;
1821 case LDAP_MORE_RESULTS_TO_RETURN:
1822 rs->sr_text = "More results to return";
1824 case LDAP_CLIENT_LOOP:
1825 case LDAP_REFERRAL_LIMIT_EXCEEDED:
1826 return LDAP_LOOP_DETECT;
1828 if ( LDAP_API_ERROR(rs->sr_err) ) return LDAP_OTHER;
1835 slap_attr_flags( AttributeName *an )
1837 slap_mask_t flags = SLAP_ATTRS_UNDEFINED;
1840 flags |= ( SLAP_OPATTRS_NO | SLAP_USERATTRS_YES );
1843 flags |= an_find( an, &AllOper ) ? SLAP_OPATTRS_YES : SLAP_OPATTRS_NO;
1844 flags |= an_find( an, &AllUser ) ? SLAP_USERATTRS_YES : SLAP_USERATTRS_NO;