1 /* result.c - routines to send ldap results, errors, and referrals */
4 * Copyright 1998-2000 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( struct berval **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] != 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 );
56 len += 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,
190 assert( ctrls == NULL ); /* ctrls not implemented */
192 ber = ber_alloc_t( LBER_USE_DER );
195 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
196 "send_ldap_response: conn %d msgid=%ld tag=%ld err=%ld\n",
197 conn ? conn->c_connid : 0, (long)msgid, (long)tag, (long)err ));
199 Debug( LDAP_DEBUG_TRACE,
200 "send_ldap_response: msgid=%ld tag=%ld err=%ld\n",
201 (long) msgid, (long) tag, (long) err );
207 LDAP_LOG(( "operation", LDAP_LEVEL_ARGS,
208 "send_ldap_response: conn %d ref=\"%s\"\n",
209 conn ? conn->c_connid : 0,
210 ref[0] && ref[0]->bv_val ? ref[0]->bv_val : "NULL" ));
212 Debug( LDAP_DEBUG_ARGS, "send_ldap_response: ref=\"%s\"\n",
213 ref[0] && ref[0]->bv_val ? ref[0]->bv_val : "NULL",
221 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
222 "send_ldap_response: conn %d ber_alloc failed\n",
223 conn ? conn->c_connid : 0 ));
225 Debug( LDAP_DEBUG_ANY, "ber_alloc failed\n", 0, 0, 0 );
231 #ifdef LDAP_CONNECTIONLESS
232 if (conn->c_is_udp) {
233 rc = ber_write(ber, (char *)&op->o_peeraddr, sizeof(struct sockaddr), 0);
234 if (rc != sizeof(struct sockaddr)) {
236 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
237 "send_ldap_response: conn %d ber_write failed\n",
238 conn ? conn->c_connid : 0 ));
240 Debug( LDAP_DEBUG_ANY, "ber_write failed\n", 0, 0, 0 );
246 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2) {
247 rc = ber_printf( ber, "{is{t{ess",
249 matched == NULL ? "" : matched,
250 text == NULL ? "" : text );
254 rc = ber_printf( ber, "{it{ess",
256 matched == NULL ? "" : matched,
257 text == NULL ? "" : text );
262 assert( err == LDAP_REFERRAL );
263 rc = ber_printf( ber, "t{V}",
264 LDAP_TAG_REFERRAL, ref );
266 assert( err != LDAP_REFERRAL );
270 if( rc != -1 && sasldata != NULL ) {
271 rc = ber_printf( ber, "tO",
272 LDAP_TAG_SASL_RES_CREDS, sasldata );
275 if( rc != -1 && resoid != NULL ) {
276 rc = ber_printf( ber, "ts",
277 LDAP_TAG_EXOP_RES_OID, resoid );
280 if( rc != -1 && resdata != NULL ) {
281 rc = ber_printf( ber, "tO",
282 LDAP_TAG_EXOP_RES_VALUE, resdata );
286 rc = ber_printf( ber, "N}N}" );
288 #ifdef LDAP_CONNECTIONLESS
289 if( conn->c_is_udp && op->o_protocol == LDAP_VERSION2 && rc != -1 ) {
290 rc = ber_printf( ber, "N}" );
296 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
297 "send_ldap_response: conn %d ber_printf failed\n",
298 conn ? conn->c_connid : 0 ));
300 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
308 bytes = send_ldap_ber( conn, ber );
313 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
314 "send_ldap_response: conn %d ber write failed\n",
315 conn ? conn->c_connid : 0 ));
317 Debug( LDAP_DEBUG_ANY,
318 "send_ldap_response: ber write failed\n",
325 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
326 num_bytes_sent += bytes;
328 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
334 send_ldap_disconnect(
345 #define LDAP_UNSOLICITED_ERROR(e) \
346 ( (e) == LDAP_PROTOCOL_ERROR \
347 || (e) == LDAP_STRONG_AUTH_REQUIRED \
348 || (e) == LDAP_UNAVAILABLE )
350 assert( LDAP_UNSOLICITED_ERROR( err ) );
353 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
354 "send_ldap_disconnect: conn %d %d:%s\n",
355 conn ? conn->c_connid : 0, err, text ? text : "" ));
357 Debug( LDAP_DEBUG_TRACE,
358 "send_ldap_disconnect %d:%s\n",
359 err, text ? text : "", NULL );
363 if ( op->o_protocol < LDAP_VERSION3 ) {
365 tag = req2res( op->o_tag );
366 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
369 reqoid = LDAP_NOTICE_DISCONNECT;
370 tag = LDAP_RES_EXTENDED;
374 send_ldap_response( conn, op, tag, msgid,
375 err, NULL, text, NULL,
376 reqoid, NULL, NULL, NULL );
378 Statslog( LDAP_DEBUG_STATS,
379 "conn=%ld op=%ld DISCONNECT tag=%lu err=%ld text=%s\n",
380 (long) op->o_connid, (long) op->o_opid,
381 (unsigned long) tag, (long) err, text ? text : "" );
399 assert( !LDAP_API_ERROR( err ) );
402 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
403 "send_ldap_result : conn %ld op=%ld p=%d\n",
404 (long)op->o_connid, (long)op->o_opid, op->o_protocol ));
406 Debug( LDAP_DEBUG_TRACE,
407 "send_ldap_result: conn=%ld op=%ld p=%d\n",
408 (long) op->o_connid, (long) op->o_opid, op->o_protocol );
412 LDAP_LOG(( "operation", LDAP_LEVEL_ARGS,
413 "send_ldap_result: conn=%ld err=%d matched=\"%s\" text=\"%s\"\n",
414 (long)op->o_connid, err, matched ? matched : "", text ? text : "" ));
416 Debug( LDAP_DEBUG_ARGS,
417 "send_ldap_result: err=%d matched=\"%s\" text=\"%s\"\n",
418 err, matched ? matched : "", text ? text : "" );
424 LDAP_LOG(( "operation", LDAP_LEVEL_ARGS,
425 "send_ldap_result: referral=\"%s\"\n",
426 ref[0] && ref[0]->bv_val ? ref[0]->bv_val : "NULL" ));
428 Debug( LDAP_DEBUG_ARGS,
429 "send_ldap_result: referral=\"%s\"\n",
430 ref[0] && ref[0]->bv_val ? ref[0]->bv_val : "NULL",
435 assert( err != LDAP_PARTIAL_RESULTS );
437 if ( err == LDAP_REFERRAL ) {
439 err = LDAP_NO_SUCH_OBJECT;
440 } else if ( op->o_protocol < LDAP_VERSION3 ) {
441 err = LDAP_PARTIAL_RESULTS;
445 if ( op->o_protocol < LDAP_VERSION3 ) {
446 tmp = v2ref( ref, text );
451 tag = req2res( op->o_tag );
452 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
454 send_ldap_response( conn, op, tag, msgid,
455 err, matched, text, ref,
456 NULL, NULL, NULL, ctrls );
458 Statslog( LDAP_DEBUG_STATS,
459 "conn=%ld op=%ld RESULT tag=%lu err=%ld text=%s\n",
460 (long) op->o_connid, (long) op->o_opid,
461 (unsigned long) tag, (long) err, text ? text : "" );
484 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
485 "send_ldap_sasl: conn %d err=%ld len=%ld\n",
486 op->o_connid, (long)err, cred ? cred->bv_len : -1 ));
488 Debug( LDAP_DEBUG_TRACE, "send_ldap_sasl: err=%ld len=%ld\n",
489 (long) err, cred ? cred->bv_len : -1, NULL );
493 tag = req2res( op->o_tag );
494 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
496 send_ldap_response( conn, op, tag, msgid,
497 err, matched, text, ref,
498 NULL, NULL, cred, ctrls );
508 struct berval **refs,
510 struct berval *rspdata,
518 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
519 "send_ldap_extended: conn %d err=%ld oid=%s len=%ld\n",
520 op->o_connid, (long)err, rspoid ? rspoid : "",
521 rspdata != NULL ? (long)rspdata->bv_len : (long)0 ));
523 Debug( LDAP_DEBUG_TRACE,
524 "send_ldap_extended err=%ld oid=%s len=%ld\n",
526 rspoid ? rspoid : "",
527 rspdata != NULL ? (long) rspdata->bv_len : (long) 0 );
531 tag = req2res( op->o_tag );
532 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
534 send_ldap_response( conn, op, tag, msgid,
535 err, matched, text, refs,
536 rspoid, rspdata, NULL, ctrls );
547 struct berval **refs,
555 assert( !LDAP_API_ERROR( err ) );
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 : "" );
627 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
630 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
631 "send_search_entry: conn %d dn=\"%s\"%s\n",
632 op->o_connid, e->e_dn,
633 attrsonly ? " (attrsOnly)" : "" ));
635 Debug( LDAP_DEBUG_TRACE,
636 "=> send_search_entry: dn=\"%s\"%s\n",
637 e->e_dn, attrsonly ? " (attrsOnly)" : "", 0 );
641 if ( ! access_allowed( be, conn, op, e,
642 ad_entry, NULL, ACL_READ ) )
645 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
646 "send_search_entry: conn %d access to entry (%s) not allowed\n",
647 op->o_connid, e->e_dn ));
649 Debug( LDAP_DEBUG_ACL,
650 "send_search_entry: access to entry not allowed\n",
659 ber = ber_alloc_t( LBER_USE_DER );
663 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
664 "send_search_entry: conn %d ber_alloc failed\n",
667 Debug( LDAP_DEBUG_ANY, "ber_alloc failed\n", 0, 0, 0 );
670 send_ldap_result( conn, op, LDAP_OTHER,
671 NULL, "BER allocation error", NULL, NULL );
675 #ifdef LDAP_CONNECTIONLESS
676 if (conn->c_is_udp) {
677 rc = ber_write(ber, (char *)&op->o_peeraddr, sizeof(struct sockaddr), 0);
678 if (rc != sizeof(struct sockaddr)) {
680 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
681 "send_search_entry: conn %d ber_printf failed\n",
682 conn ? conn->c_connid : 0 ));
684 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
690 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2) {
691 rc = ber_printf( ber, "{is{t{s{",
692 op->o_msgid, "", LDAP_RES_SEARCH_ENTRY, e->e_dn );
696 rc = ber_printf( ber, "{it{s{" /*}}}*/, op->o_msgid,
697 LDAP_RES_SEARCH_ENTRY, e->e_dn );
702 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
703 "send_search_entry: conn %d ber_printf failed\n",
706 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
710 send_ldap_result( conn, op, LDAP_OTHER,
711 NULL, "encoding DN error", NULL, NULL );
715 /* check for special all user attributes ("*") type */
716 userattrs = ( attrs == NULL ) ? 1
717 : charray_inlist( attrs, LDAP_ALL_USER_ATTRIBUTES );
719 /* check for special all operational attributes ("+") type */
720 opattrs = ( attrs == NULL ) ? 0
721 : charray_inlist( attrs, LDAP_ALL_OPERATIONAL_ATTRIBUTES );
723 for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
724 AttributeDescription *desc = a->a_desc;
725 char *type = desc->ad_cname.bv_val;
727 if ( attrs == NULL ) {
728 /* all addrs request, skip operational attributes */
729 if( is_at_operational( desc->ad_type ) ) {
734 /* specific addrs requested */
735 if ( is_at_operational( desc->ad_type ) ) {
736 if( !opattrs && !ad_inlist( desc, attrs ) ) {
741 if (!userattrs && !ad_inlist( desc, attrs ) ) {
747 if ( ! access_allowed( be, conn, op, e, desc, NULL, ACL_READ ) ) {
749 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
750 "send_search_entry: conn %d access to attribute %s not allowed\n",
751 op->o_connid, desc->ad_cname.bv_val ));
753 Debug( LDAP_DEBUG_ACL, "acl: access to attribute %s not allowed\n",
754 desc->ad_cname.bv_val, 0, 0 );
760 if (( rc = ber_printf( ber, "{s[" /*]}*/ , type )) == -1 ) {
762 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
763 "send_search_entry: conn %d ber_printf failed\n",
766 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
770 send_ldap_result( conn, op, LDAP_OTHER,
771 NULL, "encoding description error", NULL, NULL );
776 for ( i = 0; a->a_vals[i] != NULL; i++ ) {
777 if ( ! access_allowed( be, conn, op, e,
778 desc, a->a_vals[i], ACL_READ ) )
781 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
782 "send_search_entry: conn %d access to attribute %s, value %d not allowed\n",
783 op->o_connid, desc->ad_cname.bv_val, i ));
785 Debug( LDAP_DEBUG_ACL,
786 "acl: access to attribute %s, value %d not allowed\n",
787 desc->ad_cname.bv_val, i, 0 );
793 if (( rc = ber_printf( ber, "O", a->a_vals[i] )) == -1 ) {
795 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
796 "send_search_entry: conn %d ber_printf failed.\n",
799 Debug( LDAP_DEBUG_ANY,
800 "ber_printf failed\n", 0, 0, 0 );
804 send_ldap_result( conn, op, LDAP_OTHER,
805 NULL, "encoding values error", NULL, NULL );
811 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
813 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
814 "send_search_entry: conn %d ber_printf failed\n",
817 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
821 send_ldap_result( conn, op, LDAP_OTHER,
822 NULL, "encode end error", NULL, NULL );
827 /* eventually will loop through generated operational attributes */
828 /* only have subschemaSubentry implemented */
829 aa = backend_operational( be, conn, op, e );
831 for (a = aa ; a != NULL; a = a->a_next ) {
832 AttributeDescription *desc = a->a_desc;
834 if ( attrs == NULL ) {
835 /* all addrs request, skip operational attributes */
836 if( is_at_operational( desc->ad_type ) ) {
841 /* specific addrs requested */
842 if( is_at_operational( desc->ad_type ) ) {
843 if( !opattrs && !ad_inlist( desc, attrs ) ) {
847 if (!userattrs && !ad_inlist( desc, attrs ) )
854 if ( ! access_allowed( be, conn, op, e, desc, NULL, ACL_READ ) ) {
856 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
857 "send_search_entry: conn %s access to attribute %s not allowed\n",
858 op->o_connid, desc->ad_cname.bv_val ));
860 Debug( LDAP_DEBUG_ACL, "acl: access to attribute %s not allowed\n",
861 desc->ad_cname.bv_val, 0, 0 );
867 rc = ber_printf( ber, "{s[" /*]}*/ , desc->ad_cname.bv_val );
870 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
871 "send_search_entry: conn %d ber_printf failed\n",
874 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
878 send_ldap_result( conn, op, LDAP_OTHER,
879 NULL, "encoding description error", NULL, NULL );
885 for ( i = 0; a->a_vals[i] != NULL; i++ ) {
886 if ( ! access_allowed( be, conn, op, e,
887 desc, a->a_vals[i], ACL_READ ) )
890 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
891 "send_search_entry: conn %d access to %s, value %d not allowed\n",
892 op->o_connid, desc->ad_cname.bv_val, i ));
894 Debug( LDAP_DEBUG_ACL,
895 "acl: access to attribute %s, value %d not allowed\n",
896 desc->ad_cname.bv_val, i, 0 );
903 if (( rc = ber_printf( ber, "O", a->a_vals[i] )) == -1 ) {
905 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
906 "send_search_entry: conn %d ber_printf failed\n",
909 Debug( LDAP_DEBUG_ANY,
910 "ber_printf failed\n", 0, 0, 0 );
914 send_ldap_result( conn, op, LDAP_OTHER,
915 NULL, "encoding values error", NULL, NULL );
922 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
924 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
925 "send_search_entry: conn %d ber_printf failed\n",
928 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
932 send_ldap_result( conn, op, LDAP_OTHER,
933 NULL, "encode end error", NULL, NULL );
941 rc = ber_printf( ber, /*{{{*/ "}N}N}" );
943 #ifdef LDAP_CONNECTIONLESS
944 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2 && rc != -1)
945 rc = ber_printf( ber, "}" );
949 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
950 "send_search_entry: conn %d ber_printf failed\n",
953 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
957 send_ldap_result( conn, op, LDAP_OTHER,
958 NULL, "encode entry end error", NULL, NULL );
962 bytes = send_ldap_ber( conn, ber );
967 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
968 "send_ldap_response: conn %d ber write failed.\n",
971 Debug( LDAP_DEBUG_ANY,
972 "send_ldap_response: ber write failed\n",
979 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
980 num_bytes_sent += bytes;
983 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
985 Statslog( LDAP_DEBUG_STATS2, "conn=%ld op=%ld ENTRY dn=\"%s\"\n",
986 (long) conn->c_connid, (long) op->o_opid, e->e_dn, 0, 0 );
989 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
990 "send_search_entry: conn %d exit.\n",
993 Debug( LDAP_DEBUG_TRACE, "<= send_search_entry\n", 0, 0, 0 );
1004 send_search_reference(
1009 struct berval **refs,
1010 LDAPControl **ctrls,
1011 struct berval ***v2refs
1018 AttributeDescription *ad_ref = slap_schema.si_ad_ref;
1019 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
1022 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1023 "send_search_reference: conn %d dn=\"%s\"\n",
1024 op->o_connid, e->e_dn ));
1026 Debug( LDAP_DEBUG_TRACE,
1027 "=> send_search_reference: dn=\"%s\"\n",
1032 if ( ! access_allowed( be, conn, op, e,
1033 ad_entry, NULL, ACL_READ ) )
1036 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
1037 "send_search_reference: conn %d access to entry %s not allowed\n",
1038 op->o_connid, e->e_dn ));
1040 Debug( LDAP_DEBUG_ACL,
1041 "send_search_reference: access to entry not allowed\n",
1048 if ( ! access_allowed( be, conn, op, e,
1049 ad_ref, NULL, ACL_READ ) )
1052 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
1053 "send_search_reference: conn %d access to reference not allowed.\n",
1056 Debug( LDAP_DEBUG_ACL,
1057 "send_search_reference: access to reference not allowed\n",
1064 if( refs == NULL ) {
1066 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1067 "send_search_reference: null ref in (%s).\n",
1068 op->o_connid, e->e_dn ));
1070 Debug( LDAP_DEBUG_ANY,
1071 "send_search_reference: null ref in (%s)\n",
1078 if( op->o_protocol < LDAP_VERSION3 ) {
1079 /* save the references for the result */
1080 if( *refs != NULL ) {
1081 value_add( v2refs, refs );
1086 ber = ber_alloc_t( LBER_USE_DER );
1088 if ( ber == NULL ) {
1090 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1091 "send_search_reference: conn %d ber_alloc failed\n",
1094 Debug( LDAP_DEBUG_ANY,
1095 "send_search_reference: ber_alloc failed\n", 0, 0, 0 );
1098 send_ldap_result( conn, op, LDAP_OTHER,
1099 NULL, "alloc BER error", NULL, NULL );
1103 rc = ber_printf( ber, "{it{V}N}", op->o_msgid,
1104 LDAP_RES_SEARCH_REFERENCE, refs );
1108 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1109 "send_search_reference: conn %d ber_printf failed.\n",
1112 Debug( LDAP_DEBUG_ANY,
1113 "send_search_reference: ber_printf failed\n", 0, 0, 0 );
1117 send_ldap_result( conn, op, LDAP_OTHER,
1118 NULL, "encode DN error", NULL, NULL );
1122 bytes = send_ldap_ber( conn, ber );
1125 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1126 num_bytes_sent += bytes;
1129 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1131 Statslog( LDAP_DEBUG_STATS2, "conn=%ld op=%ld REF dn=\"%s\"\n",
1132 (long) conn->c_connid, (long) op->o_opid, e->e_dn, 0, 0 );
1135 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1136 "send_search_reference: conn %d exit.\n", op->o_connid ));
1138 Debug( LDAP_DEBUG_TRACE, "<= send_search_reference\n", 0, 0, 0 );
1156 *code = LDAP_SUCCESS;
1160 if ( strncasecmp( s, "RESULT", 6 ) != 0 ) {
1162 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
1163 "str2result: (%s), expecting \"RESULT\"\n", s ));
1165 Debug( LDAP_DEBUG_ANY, "str2result (%s) expecting \"RESULT\"\n",
1174 while ( (s = strchr( s, '\n' )) != NULL ) {
1179 if ( (c = strchr( s, ':' )) != NULL ) {
1183 if ( strncasecmp( s, "code", 4 ) == 0 ) {
1187 } else if ( strncasecmp( s, "matched", 7 ) == 0 ) {
1191 } else if ( strncasecmp( s, "info", 4 ) == 0 ) {
1197 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
1198 "str2result: (%s) unknown.\n", s ));
1200 Debug( LDAP_DEBUG_ANY, "str2result (%s) unknown\n",