1 /* result.c - routines to send ldap results, errors, and referrals */
4 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
12 #include <ac/socket.h>
14 #include <ac/signal.h>
15 #include <ac/string.h>
18 #include <ac/unistd.h>
22 static char *v2ref( BerVarray ref, const char *text )
24 size_t len = 0, i = 0;
29 return ch_strdup(text);
37 if (text[len-1] != '\n') {
42 v2 = ch_malloc( len+i+sizeof("Referral:") );
49 strcpy( v2+len, "Referral:" );
50 len += sizeof("Referral:");
52 for( i=0; ref[i].bv_val != NULL; i++ ) {
53 v2 = ch_realloc( v2, len + ref[i].bv_len + 1 );
55 AC_MEMCPY(&v2[len], ref[i].bv_val, ref[i].bv_len );
57 if (ref[i].bv_val[ref[i].bv_len-1] != '/') {
66 static ber_tag_t req2res( ber_tag_t tag )
71 case LDAP_REQ_COMPARE:
72 case LDAP_REQ_EXTENDED:
79 tag = LDAP_RES_DELETE;
82 case LDAP_REQ_ABANDON:
88 tag = LDAP_RES_SEARCH_RESULT;
98 static long send_ldap_ber(
104 ber_get_option( ber, LBER_OPT_BER_BYTES_TO_WRITE, &bytes );
106 /* write only one pdu at a time - wait til it's our turn */
107 ldap_pvt_thread_mutex_lock( &conn->c_write_mutex );
109 /* lock the connection */
110 ldap_pvt_thread_mutex_lock( &conn->c_mutex );
117 if ( connection_state_closing( conn ) ) {
118 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
119 ldap_pvt_thread_mutex_unlock( &conn->c_write_mutex );
124 if ( ber_flush( conn->c_sb, ber, 0 ) == 0 ) {
131 * we got an error. if it's ewouldblock, we need to
132 * wait on the socket being writable. otherwise, figure
133 * it's a hard error and return.
137 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
138 "send_ldap_ber: conn %d ber_flush failed err=%d (%s)\n",
139 conn ? conn->c_connid : 0, err, sock_errstr(err) ));
141 Debug( LDAP_DEBUG_CONNS, "ber_flush failed errno=%d reason=\"%s\"\n",
142 err, sock_errstr(err), 0 );
145 if ( err != EWOULDBLOCK && err != EAGAIN ) {
146 connection_closing( conn );
148 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
149 ldap_pvt_thread_mutex_unlock( &conn->c_write_mutex );
154 /* wait for socket to be write-ready */
155 conn->c_writewaiter = 1;
156 ber_sockbuf_ctrl( conn->c_sb, LBER_SB_OPT_GET_FD, &sd );
157 slapd_set_write( sd, 1 );
159 ldap_pvt_thread_cond_wait( &conn->c_write_cv, &conn->c_mutex );
160 conn->c_writewaiter = 0;
163 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
164 ldap_pvt_thread_mutex_unlock( &conn->c_write_mutex );
180 struct berval *resdata,
181 struct berval *sasldata,
186 BerElement *ber = (BerElement *)berbuf;
190 if (op->o_callback && op->o_callback->sc_response) {
191 op->o_callback->sc_response( conn, op, tag, msgid, err, matched,
192 text, ref, resoid, resdata, sasldata, ctrls );
196 assert( ctrls == NULL ); /* ctrls not implemented */
198 ber_init_w_nullc( ber, LBER_USE_DER );
201 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
202 "send_ldap_response: conn %d msgid=%ld tag=%ld err=%ld\n",
203 conn ? conn->c_connid : 0, (long)msgid, (long)tag, (long)err ));
205 Debug( LDAP_DEBUG_TRACE,
206 "send_ldap_response: msgid=%ld tag=%ld err=%ld\n",
207 (long) msgid, (long) tag, (long) err );
212 LDAP_LOG(( "operation", LDAP_LEVEL_ARGS,
213 "send_ldap_response: conn %d ref=\"%s\"\n",
214 conn ? conn->c_connid : 0,
215 ref[0].bv_val ? ref[0].bv_val : "NULL" ));
217 Debug( LDAP_DEBUG_ARGS, "send_ldap_response: ref=\"%s\"\n",
218 ref[0].bv_val ? ref[0].bv_val : "NULL",
224 #ifdef LDAP_CONNECTIONLESS
225 if (conn->c_is_udp) {
226 rc = ber_write(ber, (char *)&op->o_peeraddr, sizeof(struct sockaddr), 0);
227 if (rc != sizeof(struct sockaddr)) {
229 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
230 "send_ldap_response: conn %d ber_write failed\n",
231 conn ? conn->c_connid : 0 ));
233 Debug( LDAP_DEBUG_ANY, "ber_write failed\n", 0, 0, 0 );
239 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2) {
240 rc = ber_printf( ber, "{is{t{ess",
242 matched == NULL ? "" : matched,
243 text == NULL ? "" : text );
247 rc = ber_printf( ber, "{it{ess",
249 matched == NULL ? "" : matched,
250 text == NULL ? "" : text );
255 assert( err == LDAP_REFERRAL );
256 rc = ber_printf( ber, "t{W}",
257 LDAP_TAG_REFERRAL, ref );
259 assert( err != LDAP_REFERRAL );
263 if( rc != -1 && sasldata != NULL ) {
264 rc = ber_printf( ber, "tO",
265 LDAP_TAG_SASL_RES_CREDS, sasldata );
268 if( rc != -1 && resoid != NULL ) {
269 rc = ber_printf( ber, "ts",
270 LDAP_TAG_EXOP_RES_OID, resoid );
273 if( rc != -1 && resdata != NULL ) {
274 rc = ber_printf( ber, "tO",
275 LDAP_TAG_EXOP_RES_VALUE, resdata );
279 rc = ber_printf( ber, "N}N}" );
281 #ifdef LDAP_CONNECTIONLESS
282 if( conn->c_is_udp && op->o_protocol == LDAP_VERSION2 && rc != -1 ) {
283 rc = ber_printf( ber, "N}" );
289 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
290 "send_ldap_response: conn %d ber_printf failed\n",
291 conn ? conn->c_connid : 0 ));
293 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
301 bytes = send_ldap_ber( conn, ber );
306 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
307 "send_ldap_response: conn %d ber write failed\n",
308 conn ? conn->c_connid : 0 ));
310 Debug( LDAP_DEBUG_ANY,
311 "send_ldap_response: ber write failed\n",
318 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
319 num_bytes_sent += bytes;
321 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
327 send_ldap_disconnect(
338 #define LDAP_UNSOLICITED_ERROR(e) \
339 ( (e) == LDAP_PROTOCOL_ERROR \
340 || (e) == LDAP_STRONG_AUTH_REQUIRED \
341 || (e) == LDAP_UNAVAILABLE )
343 assert( LDAP_UNSOLICITED_ERROR( err ) );
346 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
347 "send_ldap_disconnect: conn %d %d:%s\n",
348 conn ? conn->c_connid : 0, err, text ? text : "" ));
350 Debug( LDAP_DEBUG_TRACE,
351 "send_ldap_disconnect %d:%s\n",
352 err, text ? text : "", NULL );
356 if ( op->o_protocol < LDAP_VERSION3 ) {
358 tag = req2res( op->o_tag );
359 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
362 reqoid = LDAP_NOTICE_DISCONNECT;
363 tag = LDAP_RES_EXTENDED;
367 send_ldap_response( conn, op, tag, msgid,
368 err, NULL, text, NULL,
369 reqoid, NULL, NULL, NULL );
371 Statslog( LDAP_DEBUG_STATS,
372 "conn=%ld op=%ld DISCONNECT tag=%lu err=%ld text=%s\n",
373 (long) op->o_connid, (long) op->o_opid,
374 (unsigned long) tag, (long) err, text ? text : "" );
392 assert( !LDAP_API_ERROR( err ) );
395 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
396 "send_ldap_result : conn %ld op=%ld p=%d\n",
397 (long)op->o_connid, (long)op->o_opid, op->o_protocol ));
399 Debug( LDAP_DEBUG_TRACE,
400 "send_ldap_result: conn=%ld op=%ld p=%d\n",
401 (long) op->o_connid, (long) op->o_opid, op->o_protocol );
405 LDAP_LOG(( "operation", LDAP_LEVEL_ARGS,
406 "send_ldap_result: conn=%ld err=%d matched=\"%s\" text=\"%s\"\n",
407 (long)op->o_connid, err, matched ? matched : "", text ? text : "" ));
409 Debug( LDAP_DEBUG_ARGS,
410 "send_ldap_result: err=%d matched=\"%s\" text=\"%s\"\n",
411 err, matched ? matched : "", text ? text : "" );
417 LDAP_LOG(( "operation", LDAP_LEVEL_ARGS,
418 "send_ldap_result: referral=\"%s\"\n",
419 ref[0].bv_val ? ref[0].bv_val : "NULL" ));
421 Debug( LDAP_DEBUG_ARGS,
422 "send_ldap_result: referral=\"%s\"\n",
423 ref[0].bv_val ? ref[0].bv_val : "NULL",
428 assert( err != LDAP_PARTIAL_RESULTS );
430 if ( err == LDAP_REFERRAL ) {
432 err = LDAP_NO_SUCH_OBJECT;
433 } else if ( op->o_protocol < LDAP_VERSION3 ) {
434 err = LDAP_PARTIAL_RESULTS;
438 if ( op->o_protocol < LDAP_VERSION3 ) {
439 tmp = v2ref( ref, text );
444 tag = req2res( op->o_tag );
445 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
447 send_ldap_response( conn, op, tag, msgid,
448 err, matched, text, ref,
449 NULL, NULL, NULL, ctrls );
451 Statslog( LDAP_DEBUG_STATS,
452 "conn=%ld op=%ld RESULT tag=%lu err=%ld text=%s\n",
453 (long) op->o_connid, (long) op->o_opid,
454 (unsigned long) tag, (long) err, text ? text : "" );
477 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
478 "send_ldap_sasl: conn %d err=%ld len=%ld\n",
479 op->o_connid, (long)err, cred ? cred->bv_len : -1 ));
481 Debug( LDAP_DEBUG_TRACE, "send_ldap_sasl: err=%ld len=%ld\n",
482 (long) err, cred ? cred->bv_len : -1, NULL );
486 tag = req2res( op->o_tag );
487 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
489 send_ldap_response( conn, op, tag, msgid,
490 err, matched, text, ref,
491 NULL, NULL, cred, ctrls );
503 struct berval *rspdata,
511 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
512 "send_ldap_extended: conn %d err=%ld oid=%s len=%ld\n",
513 op->o_connid, (long)err, rspoid ? rspoid : "",
514 rspdata != NULL ? (long)rspdata->bv_len : (long)0 ));
516 Debug( LDAP_DEBUG_TRACE,
517 "send_ldap_extended err=%ld oid=%s len=%ld\n",
519 rspoid ? rspoid : "",
520 rspdata != NULL ? (long) rspdata->bv_len : (long) 0 );
524 tag = req2res( op->o_tag );
525 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
527 send_ldap_response( conn, op, tag, msgid,
528 err, matched, text, refs,
529 rspoid, rspdata, NULL, ctrls );
549 assert( !LDAP_API_ERROR( err ) );
551 if (op->o_callback && op->o_callback->sc_sresult) {
552 op->o_callback->sc_sresult(conn, op, err, matched, text, refs,
558 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
559 "send_search_result: conn %d err=%d matched=\"%s\"\n",
560 op->o_connid, err, matched ? matched : "",
563 Debug( LDAP_DEBUG_TRACE,
564 "send_search_result: err=%d matched=\"%s\" text=\"%s\"\n",
565 err, matched ? matched : "", text ? text : "" );
569 assert( err != LDAP_PARTIAL_RESULTS );
571 if( op->o_protocol < LDAP_VERSION3 ) {
572 /* send references in search results */
573 if( err == LDAP_REFERRAL ) {
574 err = LDAP_PARTIAL_RESULTS;
577 tmp = v2ref( refs, text );
582 /* don't send references in search results */
583 assert( refs == NULL );
586 if( err == LDAP_REFERRAL ) {
591 tag = req2res( op->o_tag );
592 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
594 send_ldap_response( conn, op, tag, msgid,
595 err, matched, text, refs,
596 NULL, NULL, NULL, ctrls );
598 Statslog( LDAP_DEBUG_STATS,
599 "conn=%ld op=%ld SEARCH RESULT tag=%lu err=%ld text=%s\n",
600 (long) op->o_connid, (long) op->o_opid,
601 (unsigned long) tag, (long) err, text ? text : "" );
608 static struct berval AllUser = { sizeof(LDAP_ALL_USER_ATTRIBUTES)-1,
609 LDAP_ALL_USER_ATTRIBUTES };
610 static struct berval AllOper = { sizeof(LDAP_ALL_OPERATIONAL_ATTRIBUTES)-1,
611 LDAP_ALL_OPERATIONAL_ATTRIBUTES };
619 AttributeName *attrs,
625 BerElement *ber = (BerElement *)berbuf;
632 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
634 if (op->o_callback && op->o_callback->sc_sendentry) {
635 return op->o_callback->sc_sendentry( be, conn, op, e, attrs,
640 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
641 "send_search_entry: conn %d dn=\"%s\"%s\n",
642 op->o_connid, e->e_dn,
643 attrsonly ? " (attrsOnly)" : "" ));
645 Debug( LDAP_DEBUG_TRACE,
646 "=> send_search_entry: dn=\"%s\"%s\n",
647 e->e_dn, attrsonly ? " (attrsOnly)" : "", 0 );
651 if ( ! access_allowed( be, conn, op, e,
652 ad_entry, NULL, ACL_READ ) )
655 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
656 "send_search_entry: conn %d access to entry (%s) not allowed\n",
657 op->o_connid, e->e_dn ));
659 Debug( LDAP_DEBUG_ACL,
660 "send_search_entry: access to entry not allowed\n",
669 ber_init_w_nullc( ber, LBER_USE_DER );
671 #ifdef LDAP_CONNECTIONLESS
672 if (conn->c_is_udp) {
673 rc = ber_write(ber, (char *)&op->o_peeraddr, sizeof(struct sockaddr), 0);
674 if (rc != sizeof(struct sockaddr)) {
676 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
677 "send_search_entry: conn %d ber_printf failed\n",
678 conn ? conn->c_connid : 0 ));
680 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
686 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2) {
687 rc = ber_printf( ber, "{is{t{O{" /*}}}*/,
688 op->o_msgid, "", LDAP_RES_SEARCH_ENTRY, &e->e_name );
692 rc = ber_printf( ber, "{it{O{" /*}}}*/, op->o_msgid,
693 LDAP_RES_SEARCH_ENTRY, &e->e_name );
698 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
699 "send_search_entry: conn %d ber_printf failed\n",
702 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
706 send_ldap_result( conn, op, LDAP_OTHER,
707 NULL, "encoding DN error", NULL, NULL );
711 /* check for special all user attributes ("*") type */
712 userattrs = ( attrs == NULL ) ? 1
713 : an_find( attrs, &AllUser );
715 /* check for special all operational attributes ("+") type */
716 opattrs = ( attrs == NULL ) ? 0
717 : an_find( attrs, &AllOper );
719 for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
720 AttributeDescription *desc = a->a_desc;
722 if ( attrs == NULL ) {
723 /* all attrs request, skip operational attributes */
724 if( is_at_operational( desc->ad_type ) ) {
729 /* specific attrs requested */
730 if ( is_at_operational( desc->ad_type ) ) {
731 if( !opattrs && !ad_inlist( desc, attrs ) ) {
736 if (!userattrs && !ad_inlist( desc, attrs ) ) {
742 if ( ! access_allowed( be, conn, op, e, desc, NULL, ACL_READ ) ) {
744 LDAP_LOG(( "acl", LDAP_LEVEL_INFO, "send_search_entry: "
745 "conn %d access to attribute %s not allowed\n",
746 op->o_connid, desc->ad_cname.bv_val ));
748 Debug( LDAP_DEBUG_ACL, "acl: "
749 "access to attribute %s not allowed\n",
750 desc->ad_cname.bv_val, 0, 0 );
756 if (( rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname )) == -1 ) {
758 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
759 "send_search_entry: conn %d ber_printf failed\n",
762 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
766 send_ldap_result( conn, op, LDAP_OTHER,
767 NULL, "encoding description error", NULL, NULL );
772 for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
773 if ( ! access_allowed( be, conn, op, e,
774 desc, &a->a_vals[i], ACL_READ ) )
777 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
778 "send_search_entry: conn %d access to attribute %s, value %d not allowed\n",
779 op->o_connid, desc->ad_cname.bv_val, i ));
781 Debug( LDAP_DEBUG_ACL,
782 "acl: access to attribute %s, value %d not allowed\n",
783 desc->ad_cname.bv_val, i, 0 );
789 if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
791 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
792 "send_search_entry: conn %d ber_printf failed.\n",
795 Debug( LDAP_DEBUG_ANY,
796 "ber_printf failed\n", 0, 0, 0 );
800 send_ldap_result( conn, op, LDAP_OTHER,
801 NULL, "encoding values error", NULL, NULL );
807 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
809 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
810 "send_search_entry: conn %d ber_printf failed\n",
813 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
817 send_ldap_result( conn, op, LDAP_OTHER,
818 NULL, "encode end error", NULL, NULL );
823 /* eventually will loop through generated operational attributes */
824 /* only have subschemaSubentry implemented */
825 aa = backend_operational( be, conn, op, e, attrs, opattrs );
827 for (a = aa ; a != NULL; a = a->a_next ) {
828 AttributeDescription *desc = a->a_desc;
830 if ( attrs == NULL ) {
831 /* all attrs request, skip operational attributes */
832 if( is_at_operational( desc->ad_type ) ) {
837 /* specific attrs requested */
838 if( is_at_operational( desc->ad_type ) ) {
839 if( !opattrs && !ad_inlist( desc, attrs ) ) {
843 if (!userattrs && !ad_inlist( desc, attrs ) )
850 if ( ! access_allowed( be, conn, op, e, desc, NULL, ACL_READ ) ) {
852 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
853 "send_search_entry: conn %s access to attribute %s not allowed\n",
854 op->o_connid, desc->ad_cname.bv_val ));
856 Debug( LDAP_DEBUG_ACL, "acl: access to attribute %s not allowed\n",
857 desc->ad_cname.bv_val, 0, 0 );
863 rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname );
866 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
867 "send_search_entry: conn %d ber_printf failed\n",
870 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
874 send_ldap_result( conn, op, LDAP_OTHER,
875 NULL, "encoding description error", NULL, NULL );
881 for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
882 if ( ! access_allowed( be, conn, op, e,
883 desc, &a->a_vals[i], ACL_READ ) )
886 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
887 "send_search_entry: conn %d access to %s, value %d not allowed\n",
888 op->o_connid, desc->ad_cname.bv_val, i ));
890 Debug( LDAP_DEBUG_ACL,
891 "acl: access to attribute %s, value %d not allowed\n",
892 desc->ad_cname.bv_val, i, 0 );
899 if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
901 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
902 "send_search_entry: conn %d ber_printf failed\n",
905 Debug( LDAP_DEBUG_ANY,
906 "ber_printf failed\n", 0, 0, 0 );
910 send_ldap_result( conn, op, LDAP_OTHER,
911 NULL, "encoding values error", NULL, NULL );
918 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
920 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
921 "send_search_entry: conn %d ber_printf failed\n",
924 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
928 send_ldap_result( conn, op, LDAP_OTHER,
929 NULL, "encode end error", NULL, NULL );
937 rc = ber_printf( ber, /*{{{*/ "}N}N}" );
939 #ifdef LDAP_CONNECTIONLESS
940 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2 && rc != -1)
941 rc = ber_printf( ber, "}" );
945 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
946 "send_search_entry: conn %d ber_printf failed\n",
949 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
953 send_ldap_result( conn, op, LDAP_OTHER,
954 NULL, "encode entry end error", NULL, NULL );
958 bytes = send_ldap_ber( conn, ber );
963 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
964 "send_ldap_response: conn %d ber write failed.\n",
967 Debug( LDAP_DEBUG_ANY,
968 "send_ldap_response: ber write failed\n",
975 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
976 num_bytes_sent += bytes;
979 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
981 Statslog( LDAP_DEBUG_STATS2, "conn=%ld op=%ld ENTRY dn=\"%s\"\n",
982 (long) conn->c_connid, (long) op->o_opid, e->e_dn, 0, 0 );
985 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
986 "send_search_entry: conn %d exit.\n",
989 Debug( LDAP_DEBUG_TRACE, "<= send_search_entry\n", 0, 0, 0 );
1000 send_search_reference(
1006 LDAPControl **ctrls,
1011 BerElement *ber = (BerElement *)berbuf;
1015 AttributeDescription *ad_ref = slap_schema.si_ad_ref;
1016 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
1019 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1020 "send_search_reference: conn %d dn=\"%s\"\n",
1021 op->o_connid, e->e_dn ));
1023 Debug( LDAP_DEBUG_TRACE,
1024 "=> send_search_reference: dn=\"%s\"\n",
1029 if ( ! access_allowed( be, conn, op, e,
1030 ad_entry, NULL, ACL_READ ) )
1033 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
1034 "send_search_reference: conn %d access to entry %s not allowed\n",
1035 op->o_connid, e->e_dn ));
1037 Debug( LDAP_DEBUG_ACL,
1038 "send_search_reference: access to entry not allowed\n",
1045 if ( ! access_allowed( be, conn, op, e,
1046 ad_ref, NULL, ACL_READ ) )
1049 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
1050 "send_search_reference: conn %d access to reference not allowed.\n",
1053 Debug( LDAP_DEBUG_ACL,
1054 "send_search_reference: access to reference not allowed\n",
1061 if( refs == NULL ) {
1063 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1064 "send_search_reference: null ref in (%s).\n",
1065 op->o_connid, e->e_dn ));
1067 Debug( LDAP_DEBUG_ANY,
1068 "send_search_reference: null ref in (%s)\n",
1075 if( op->o_protocol < LDAP_VERSION3 ) {
1076 /* save the references for the result */
1077 if( refs[0].bv_val != NULL ) {
1078 value_add( v2refs, refs );
1083 ber_init_w_nullc( ber, LBER_USE_DER );
1085 rc = ber_printf( ber, "{it{W}N}", op->o_msgid,
1086 LDAP_RES_SEARCH_REFERENCE, refs );
1090 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1091 "send_search_reference: conn %d ber_printf failed.\n",
1094 Debug( LDAP_DEBUG_ANY,
1095 "send_search_reference: ber_printf failed\n", 0, 0, 0 );
1098 ber_free_buf( ber );
1099 send_ldap_result( conn, op, LDAP_OTHER,
1100 NULL, "encode DN error", NULL, NULL );
1104 bytes = send_ldap_ber( conn, ber );
1105 ber_free_buf( ber );
1107 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1108 num_bytes_sent += bytes;
1111 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1113 Statslog( LDAP_DEBUG_STATS2, "conn=%ld op=%ld REF dn=\"%s\"\n",
1114 (long) conn->c_connid, (long) op->o_opid, e->e_dn, 0, 0 );
1117 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1118 "send_search_reference: conn %d exit.\n", op->o_connid ));
1120 Debug( LDAP_DEBUG_TRACE, "<= send_search_reference\n", 0, 0, 0 );
1138 *code = LDAP_SUCCESS;
1142 if ( strncasecmp( s, "RESULT", 6 ) != 0 ) {
1144 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
1145 "str2result: (%s), expecting \"RESULT\"\n", s ));
1147 Debug( LDAP_DEBUG_ANY, "str2result (%s) expecting \"RESULT\"\n",
1156 while ( (s = strchr( s, '\n' )) != NULL ) {
1161 if ( (c = strchr( s, ':' )) != NULL ) {
1165 if ( strncasecmp( s, "code", 4 ) == 0 ) {
1169 } else if ( strncasecmp( s, "matched", 7 ) == 0 ) {
1173 } else if ( strncasecmp( s, "info", 4 ) == 0 ) {
1179 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
1180 "str2result: (%s) unknown.\n", s ));
1182 Debug( LDAP_DEBUG_ANY, "str2result (%s) unknown\n",