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( BVarray 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 );
146 if ( err != EWOULDBLOCK && err != EAGAIN ) {
147 connection_closing( conn );
149 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
150 ldap_pvt_thread_mutex_unlock( &conn->c_write_mutex );
155 /* wait for socket to be write-ready */
156 conn->c_writewaiter = 1;
157 ber_sockbuf_ctrl( conn->c_sb, LBER_SB_OPT_GET_FD, &sd );
158 slapd_set_write( sd, 1 );
160 ldap_pvt_thread_cond_wait( &conn->c_write_cv, &conn->c_mutex );
161 conn->c_writewaiter = 0;
164 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
165 ldap_pvt_thread_mutex_unlock( &conn->c_write_mutex );
181 struct berval *resdata,
182 struct berval *sasldata,
187 BerElement *ber = (BerElement *)berbuf;
191 if (op->o_response) {
192 op->o_response( conn, op, tag, msgid, err, matched,
193 text, ref, resoid, resdata, sasldata, ctrls );
197 assert( ctrls == NULL ); /* ctrls not implemented */
199 ber_init_w_nullc( ber, LBER_USE_DER );
202 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
203 "send_ldap_response: conn %d msgid=%ld tag=%ld err=%ld\n",
204 conn ? conn->c_connid : 0, (long)msgid, (long)tag, (long)err ));
206 Debug( LDAP_DEBUG_TRACE,
207 "send_ldap_response: msgid=%ld tag=%ld err=%ld\n",
208 (long) msgid, (long) tag, (long) err );
214 LDAP_LOG(( "operation", LDAP_LEVEL_ARGS,
215 "send_ldap_response: conn %d ref=\"%s\"\n",
216 conn ? conn->c_connid : 0,
217 ref[0].bv_val ? ref[0].bv_val : "NULL" ));
219 Debug( LDAP_DEBUG_ARGS, "send_ldap_response: ref=\"%s\"\n",
220 ref[0].bv_val ? ref[0].bv_val : "NULL",
226 #ifdef LDAP_CONNECTIONLESS
227 if (conn->c_is_udp) {
228 rc = ber_write(ber, (char *)&op->o_peeraddr, sizeof(struct sockaddr), 0);
229 if (rc != sizeof(struct sockaddr)) {
231 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
232 "send_ldap_response: conn %d ber_write failed\n",
233 conn ? conn->c_connid : 0 ));
235 Debug( LDAP_DEBUG_ANY, "ber_write failed\n", 0, 0, 0 );
241 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2) {
242 rc = ber_printf( ber, "{is{t{ess",
244 matched == NULL ? "" : matched,
245 text == NULL ? "" : text );
249 rc = ber_printf( ber, "{it{ess",
251 matched == NULL ? "" : matched,
252 text == NULL ? "" : text );
257 assert( err == LDAP_REFERRAL );
258 rc = ber_printf( ber, "t{W}",
259 LDAP_TAG_REFERRAL, ref );
261 assert( err != LDAP_REFERRAL );
265 if( rc != -1 && sasldata != NULL ) {
266 rc = ber_printf( ber, "tO",
267 LDAP_TAG_SASL_RES_CREDS, sasldata );
270 if( rc != -1 && resoid != NULL ) {
271 rc = ber_printf( ber, "ts",
272 LDAP_TAG_EXOP_RES_OID, resoid );
275 if( rc != -1 && resdata != NULL ) {
276 rc = ber_printf( ber, "tO",
277 LDAP_TAG_EXOP_RES_VALUE, resdata );
281 rc = ber_printf( ber, "N}N}" );
283 #ifdef LDAP_CONNECTIONLESS
284 if( conn->c_is_udp && op->o_protocol == LDAP_VERSION2 && rc != -1 ) {
285 rc = ber_printf( ber, "N}" );
291 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
292 "send_ldap_response: conn %d ber_printf failed\n",
293 conn ? conn->c_connid : 0 ));
295 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
303 bytes = send_ldap_ber( conn, ber );
308 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
309 "send_ldap_response: conn %d ber write failed\n",
310 conn ? conn->c_connid : 0 ));
312 Debug( LDAP_DEBUG_ANY,
313 "send_ldap_response: ber write failed\n",
320 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
321 num_bytes_sent += bytes;
323 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
329 send_ldap_disconnect(
340 #define LDAP_UNSOLICITED_ERROR(e) \
341 ( (e) == LDAP_PROTOCOL_ERROR \
342 || (e) == LDAP_STRONG_AUTH_REQUIRED \
343 || (e) == LDAP_UNAVAILABLE )
345 assert( LDAP_UNSOLICITED_ERROR( err ) );
348 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
349 "send_ldap_disconnect: conn %d %d:%s\n",
350 conn ? conn->c_connid : 0, err, text ? text : "" ));
352 Debug( LDAP_DEBUG_TRACE,
353 "send_ldap_disconnect %d:%s\n",
354 err, text ? text : "", NULL );
358 if ( op->o_protocol < LDAP_VERSION3 ) {
360 tag = req2res( op->o_tag );
361 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
364 reqoid = LDAP_NOTICE_DISCONNECT;
365 tag = LDAP_RES_EXTENDED;
369 send_ldap_response( conn, op, tag, msgid,
370 err, NULL, text, NULL,
371 reqoid, NULL, NULL, NULL );
373 Statslog( LDAP_DEBUG_STATS,
374 "conn=%ld op=%ld DISCONNECT tag=%lu err=%ld text=%s\n",
375 (long) op->o_connid, (long) op->o_opid,
376 (unsigned long) tag, (long) err, text ? text : "" );
394 assert( !LDAP_API_ERROR( err ) );
397 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
398 "send_ldap_result : conn %ld op=%ld p=%d\n",
399 (long)op->o_connid, (long)op->o_opid, op->o_protocol ));
401 Debug( LDAP_DEBUG_TRACE,
402 "send_ldap_result: conn=%ld op=%ld p=%d\n",
403 (long) op->o_connid, (long) op->o_opid, op->o_protocol );
407 LDAP_LOG(( "operation", LDAP_LEVEL_ARGS,
408 "send_ldap_result: conn=%ld err=%d matched=\"%s\" text=\"%s\"\n",
409 (long)op->o_connid, err, matched ? matched : "", text ? text : "" ));
411 Debug( LDAP_DEBUG_ARGS,
412 "send_ldap_result: err=%d matched=\"%s\" text=\"%s\"\n",
413 err, matched ? matched : "", text ? text : "" );
419 LDAP_LOG(( "operation", LDAP_LEVEL_ARGS,
420 "send_ldap_result: referral=\"%s\"\n",
421 ref[0].bv_val ? ref[0].bv_val : "NULL" ));
423 Debug( LDAP_DEBUG_ARGS,
424 "send_ldap_result: referral=\"%s\"\n",
425 ref[0].bv_val ? ref[0].bv_val : "NULL",
430 assert( err != LDAP_PARTIAL_RESULTS );
432 if ( err == LDAP_REFERRAL ) {
434 err = LDAP_NO_SUCH_OBJECT;
435 } else if ( op->o_protocol < LDAP_VERSION3 ) {
436 err = LDAP_PARTIAL_RESULTS;
440 if ( op->o_protocol < LDAP_VERSION3 ) {
441 tmp = v2ref( ref, text );
446 tag = req2res( op->o_tag );
447 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
449 send_ldap_response( conn, op, tag, msgid,
450 err, matched, text, ref,
451 NULL, NULL, NULL, ctrls );
453 Statslog( LDAP_DEBUG_STATS,
454 "conn=%ld op=%ld RESULT tag=%lu err=%ld text=%s\n",
455 (long) op->o_connid, (long) op->o_opid,
456 (unsigned long) tag, (long) err, text ? text : "" );
479 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
480 "send_ldap_sasl: conn %d err=%ld len=%ld\n",
481 op->o_connid, (long)err, cred ? cred->bv_len : -1 ));
483 Debug( LDAP_DEBUG_TRACE, "send_ldap_sasl: err=%ld len=%ld\n",
484 (long) err, cred ? cred->bv_len : -1, NULL );
488 tag = req2res( op->o_tag );
489 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
491 send_ldap_response( conn, op, tag, msgid,
492 err, matched, text, ref,
493 NULL, NULL, cred, ctrls );
505 struct berval *rspdata,
513 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
514 "send_ldap_extended: conn %d err=%ld oid=%s len=%ld\n",
515 op->o_connid, (long)err, rspoid ? rspoid : "",
516 rspdata != NULL ? (long)rspdata->bv_len : (long)0 ));
518 Debug( LDAP_DEBUG_TRACE,
519 "send_ldap_extended err=%ld oid=%s len=%ld\n",
521 rspoid ? rspoid : "",
522 rspdata != NULL ? (long) rspdata->bv_len : (long) 0 );
526 tag = req2res( op->o_tag );
527 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
529 send_ldap_response( conn, op, tag, msgid,
530 err, matched, text, refs,
531 rspoid, rspdata, NULL, ctrls );
551 assert( !LDAP_API_ERROR( err ) );
554 op->o_sresult(conn, op, err, matched, text, refs,
560 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
561 "send_search_result: conn %d err=%d matched=\"%s\"\n",
562 op->o_connid, err, matched ? matched : "",
565 Debug( LDAP_DEBUG_TRACE,
566 "send_search_result: err=%d matched=\"%s\" text=\"%s\"\n",
567 err, matched ? matched : "", text ? text : "" );
571 assert( err != LDAP_PARTIAL_RESULTS );
573 if( op->o_protocol < LDAP_VERSION3 ) {
574 /* send references in search results */
575 if( err == LDAP_REFERRAL ) {
576 err = LDAP_PARTIAL_RESULTS;
579 tmp = v2ref( refs, text );
584 /* don't send references in search results */
585 assert( refs == NULL );
588 if( err == LDAP_REFERRAL ) {
593 tag = req2res( op->o_tag );
594 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
596 send_ldap_response( conn, op, tag, msgid,
597 err, matched, text, refs,
598 NULL, NULL, NULL, ctrls );
600 Statslog( LDAP_DEBUG_STATS,
601 "conn=%ld op=%ld SEARCH RESULT tag=%lu err=%ld text=%s\n",
602 (long) op->o_connid, (long) op->o_opid,
603 (unsigned long) tag, (long) err, text ? text : "" );
610 static struct berval AllUser = { sizeof(LDAP_ALL_USER_ATTRIBUTES)-1,
611 LDAP_ALL_USER_ATTRIBUTES };
612 static struct berval AllOper = { sizeof(LDAP_ALL_OPERATIONAL_ATTRIBUTES)-1,
613 LDAP_ALL_OPERATIONAL_ATTRIBUTES };
621 AttributeName *attrs,
627 BerElement *ber = (BerElement *)berbuf;
634 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
637 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
638 "send_search_entry: conn %d dn=\"%s\"%s\n",
639 op->o_connid, e->e_dn,
640 attrsonly ? " (attrsOnly)" : "" ));
642 Debug( LDAP_DEBUG_TRACE,
643 "=> send_search_entry: dn=\"%s\"%s\n",
644 e->e_dn, attrsonly ? " (attrsOnly)" : "", 0 );
648 if ( ! access_allowed( be, conn, op, e,
649 ad_entry, NULL, ACL_READ ) )
652 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
653 "send_search_entry: conn %d access to entry (%s) not allowed\n",
654 op->o_connid, e->e_dn ));
656 Debug( LDAP_DEBUG_ACL,
657 "send_search_entry: access to entry not allowed\n",
666 ber_init_w_nullc( ber, LBER_USE_DER );
668 #ifdef LDAP_CONNECTIONLESS
669 if (conn->c_is_udp) {
670 rc = ber_write(ber, (char *)&op->o_peeraddr, sizeof(struct sockaddr), 0);
671 if (rc != sizeof(struct sockaddr)) {
673 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
674 "send_search_entry: conn %d ber_printf failed\n",
675 conn ? conn->c_connid : 0 ));
677 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
683 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2) {
684 rc = ber_printf( ber, "{is{t{O{" /*}}}*/,
685 op->o_msgid, "", LDAP_RES_SEARCH_ENTRY, &e->e_name );
689 rc = ber_printf( ber, "{it{O{" /*}}}*/, op->o_msgid,
690 LDAP_RES_SEARCH_ENTRY, &e->e_name );
695 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
696 "send_search_entry: conn %d ber_printf failed\n",
699 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
703 send_ldap_result( conn, op, LDAP_OTHER,
704 NULL, "encoding DN error", NULL, NULL );
708 /* check for special all user attributes ("*") type */
709 userattrs = ( attrs == NULL ) ? 1
710 : an_find( attrs, &AllUser );
712 /* check for special all operational attributes ("+") type */
713 opattrs = ( attrs == NULL ) ? 0
714 : an_find( attrs, &AllOper );
716 for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
717 AttributeDescription *desc = a->a_desc;
719 if ( attrs == NULL ) {
720 /* all attrs request, skip operational attributes */
721 if( is_at_operational( desc->ad_type ) ) {
726 /* specific attrs requested */
727 if ( is_at_operational( desc->ad_type ) ) {
728 if( !opattrs && !ad_inlist( desc, attrs ) ) {
733 if (!userattrs && !ad_inlist( desc, attrs ) ) {
739 if ( ! access_allowed( be, conn, op, e, desc, NULL, ACL_READ ) ) {
741 LDAP_LOG(( "acl", LDAP_LEVEL_INFO, "send_search_entry: "
742 "conn %d access to attribute %s not allowed\n",
743 op->o_connid, desc->ad_cname.bv_val ));
745 Debug( LDAP_DEBUG_ACL, "acl: "
746 "access to attribute %s not allowed\n",
747 desc->ad_cname.bv_val, 0, 0 );
753 if (( rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname )) == -1 ) {
755 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
756 "send_search_entry: conn %d ber_printf failed\n",
759 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
763 send_ldap_result( conn, op, LDAP_OTHER,
764 NULL, "encoding description error", NULL, NULL );
769 for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
770 if ( ! access_allowed( be, conn, op, e,
771 desc, &a->a_vals[i], ACL_READ ) )
774 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
775 "send_search_entry: conn %d access to attribute %s, value %d not allowed\n",
776 op->o_connid, desc->ad_cname.bv_val, i ));
778 Debug( LDAP_DEBUG_ACL,
779 "acl: access to attribute %s, value %d not allowed\n",
780 desc->ad_cname.bv_val, i, 0 );
786 if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
788 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
789 "send_search_entry: conn %d ber_printf failed.\n",
792 Debug( LDAP_DEBUG_ANY,
793 "ber_printf failed\n", 0, 0, 0 );
797 send_ldap_result( conn, op, LDAP_OTHER,
798 NULL, "encoding values error", NULL, NULL );
804 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
806 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
807 "send_search_entry: conn %d ber_printf failed\n",
810 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
814 send_ldap_result( conn, op, LDAP_OTHER,
815 NULL, "encode end error", NULL, NULL );
820 /* eventually will loop through generated operational attributes */
821 /* only have subschemaSubentry implemented */
822 aa = backend_operational( be, conn, op, e, attrs, opattrs );
824 for (a = aa ; a != NULL; a = a->a_next ) {
825 AttributeDescription *desc = a->a_desc;
827 if ( attrs == NULL ) {
828 /* all attrs request, skip operational attributes */
829 if( is_at_operational( desc->ad_type ) ) {
834 /* specific attrs requested */
835 if( is_at_operational( desc->ad_type ) ) {
836 if( !opattrs && !ad_inlist( desc, attrs ) ) {
840 if (!userattrs && !ad_inlist( desc, attrs ) )
847 if ( ! access_allowed( be, conn, op, e, desc, NULL, ACL_READ ) ) {
849 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
850 "send_search_entry: conn %s access to attribute %s not allowed\n",
851 op->o_connid, desc->ad_cname.bv_val ));
853 Debug( LDAP_DEBUG_ACL, "acl: access to attribute %s not allowed\n",
854 desc->ad_cname.bv_val, 0, 0 );
860 rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname );
863 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
864 "send_search_entry: conn %d ber_printf failed\n",
867 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
871 send_ldap_result( conn, op, LDAP_OTHER,
872 NULL, "encoding description error", NULL, NULL );
878 for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
879 if ( ! access_allowed( be, conn, op, e,
880 desc, &a->a_vals[i], ACL_READ ) )
883 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
884 "send_search_entry: conn %d access to %s, value %d not allowed\n",
885 op->o_connid, desc->ad_cname.bv_val, i ));
887 Debug( LDAP_DEBUG_ACL,
888 "acl: access to attribute %s, value %d not allowed\n",
889 desc->ad_cname.bv_val, i, 0 );
896 if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
898 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
899 "send_search_entry: conn %d ber_printf failed\n",
902 Debug( LDAP_DEBUG_ANY,
903 "ber_printf failed\n", 0, 0, 0 );
907 send_ldap_result( conn, op, LDAP_OTHER,
908 NULL, "encoding values error", NULL, NULL );
915 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
917 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
918 "send_search_entry: conn %d ber_printf failed\n",
921 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
925 send_ldap_result( conn, op, LDAP_OTHER,
926 NULL, "encode end error", NULL, NULL );
934 rc = ber_printf( ber, /*{{{*/ "}N}N}" );
936 #ifdef LDAP_CONNECTIONLESS
937 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2 && rc != -1)
938 rc = ber_printf( ber, "}" );
942 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
943 "send_search_entry: conn %d ber_printf failed\n",
946 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
950 send_ldap_result( conn, op, LDAP_OTHER,
951 NULL, "encode entry end error", NULL, NULL );
955 bytes = send_ldap_ber( conn, ber );
960 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
961 "send_ldap_response: conn %d ber write failed.\n",
964 Debug( LDAP_DEBUG_ANY,
965 "send_ldap_response: ber write failed\n",
972 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
973 num_bytes_sent += bytes;
976 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
978 Statslog( LDAP_DEBUG_STATS2, "conn=%ld op=%ld ENTRY dn=\"%s\"\n",
979 (long) conn->c_connid, (long) op->o_opid, e->e_dn, 0, 0 );
982 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
983 "send_search_entry: conn %d exit.\n",
986 Debug( LDAP_DEBUG_TRACE, "<= send_search_entry\n", 0, 0, 0 );
997 send_search_reference(
1003 LDAPControl **ctrls,
1008 BerElement *ber = (BerElement *)berbuf;
1012 AttributeDescription *ad_ref = slap_schema.si_ad_ref;
1013 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
1016 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1017 "send_search_reference: conn %d dn=\"%s\"\n",
1018 op->o_connid, e->e_dn ));
1020 Debug( LDAP_DEBUG_TRACE,
1021 "=> send_search_reference: dn=\"%s\"\n",
1026 if ( ! access_allowed( be, conn, op, e,
1027 ad_entry, NULL, ACL_READ ) )
1030 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
1031 "send_search_reference: conn %d access to entry %s not allowed\n",
1032 op->o_connid, e->e_dn ));
1034 Debug( LDAP_DEBUG_ACL,
1035 "send_search_reference: access to entry not allowed\n",
1042 if ( ! access_allowed( be, conn, op, e,
1043 ad_ref, NULL, ACL_READ ) )
1046 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
1047 "send_search_reference: conn %d access to reference not allowed.\n",
1050 Debug( LDAP_DEBUG_ACL,
1051 "send_search_reference: access to reference not allowed\n",
1058 if( refs == NULL ) {
1060 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1061 "send_search_reference: null ref in (%s).\n",
1062 op->o_connid, e->e_dn ));
1064 Debug( LDAP_DEBUG_ANY,
1065 "send_search_reference: null ref in (%s)\n",
1072 if( op->o_protocol < LDAP_VERSION3 ) {
1073 /* save the references for the result */
1074 if( refs[0].bv_val != NULL ) {
1075 value_add( v2refs, refs );
1080 ber_init_w_nullc( ber, LBER_USE_DER );
1082 rc = ber_printf( ber, "{it{W}N}", op->o_msgid,
1083 LDAP_RES_SEARCH_REFERENCE, refs );
1087 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1088 "send_search_reference: conn %d ber_printf failed.\n",
1091 Debug( LDAP_DEBUG_ANY,
1092 "send_search_reference: ber_printf failed\n", 0, 0, 0 );
1095 ber_free_buf( ber );
1096 send_ldap_result( conn, op, LDAP_OTHER,
1097 NULL, "encode DN error", NULL, NULL );
1101 bytes = send_ldap_ber( conn, ber );
1102 ber_free_buf( ber );
1104 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1105 num_bytes_sent += bytes;
1108 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1110 Statslog( LDAP_DEBUG_STATS2, "conn=%ld op=%ld REF dn=\"%s\"\n",
1111 (long) conn->c_connid, (long) op->o_opid, e->e_dn, 0, 0 );
1114 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1115 "send_search_reference: conn %d exit.\n", op->o_connid ));
1117 Debug( LDAP_DEBUG_TRACE, "<= send_search_reference\n", 0, 0, 0 );
1135 *code = LDAP_SUCCESS;
1139 if ( strncasecmp( s, "RESULT", 6 ) != 0 ) {
1141 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
1142 "str2result: (%s), expecting \"RESULT\"\n", s ));
1144 Debug( LDAP_DEBUG_ANY, "str2result (%s) expecting \"RESULT\"\n",
1153 while ( (s = strchr( s, '\n' )) != NULL ) {
1158 if ( (c = strchr( s, ':' )) != NULL ) {
1162 if ( strncasecmp( s, "code", 4 ) == 0 ) {
1166 } else if ( strncasecmp( s, "matched", 7 ) == 0 ) {
1170 } else if ( strncasecmp( s, "info", 4 ) == 0 ) {
1176 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
1177 "str2result: (%s) unknown.\n", s ));
1179 Debug( LDAP_DEBUG_ANY, "str2result (%s) unknown\n",