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 if (op->o_response) {
191 op->o_response( conn, op, tag, msgid, err, matched,
192 text, ref, resoid, resdata, sasldata, ctrls );
196 assert( ctrls == NULL ); /* ctrls not implemented */
198 ber = ber_alloc_t( 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 );
213 LDAP_LOG(( "operation", LDAP_LEVEL_ARGS,
214 "send_ldap_response: conn %d ref=\"%s\"\n",
215 conn ? conn->c_connid : 0,
216 ref[0] && ref[0]->bv_val ? ref[0]->bv_val : "NULL" ));
218 Debug( LDAP_DEBUG_ARGS, "send_ldap_response: ref=\"%s\"\n",
219 ref[0] && ref[0]->bv_val ? ref[0]->bv_val : "NULL",
227 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
228 "send_ldap_response: conn %d ber_alloc failed\n",
229 conn ? conn->c_connid : 0 ));
231 Debug( LDAP_DEBUG_ANY, "ber_alloc failed\n", 0, 0, 0 );
237 #ifdef LDAP_CONNECTIONLESS
238 if (conn->c_is_udp) {
239 rc = ber_write(ber, (char *)&op->o_peeraddr, sizeof(struct sockaddr), 0);
240 if (rc != sizeof(struct sockaddr)) {
242 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
243 "send_ldap_response: conn %d ber_write failed\n",
244 conn ? conn->c_connid : 0 ));
246 Debug( LDAP_DEBUG_ANY, "ber_write failed\n", 0, 0, 0 );
252 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2) {
253 rc = ber_printf( ber, "{is{t{ess",
255 matched == NULL ? "" : matched,
256 text == NULL ? "" : text );
260 rc = ber_printf( ber, "{it{ess",
262 matched == NULL ? "" : matched,
263 text == NULL ? "" : text );
268 assert( err == LDAP_REFERRAL );
269 rc = ber_printf( ber, "t{V}",
270 LDAP_TAG_REFERRAL, ref );
272 assert( err != LDAP_REFERRAL );
276 if( rc != -1 && sasldata != NULL ) {
277 rc = ber_printf( ber, "tO",
278 LDAP_TAG_SASL_RES_CREDS, sasldata );
281 if( rc != -1 && resoid != NULL ) {
282 rc = ber_printf( ber, "ts",
283 LDAP_TAG_EXOP_RES_OID, resoid );
286 if( rc != -1 && resdata != NULL ) {
287 rc = ber_printf( ber, "tO",
288 LDAP_TAG_EXOP_RES_VALUE, resdata );
292 rc = ber_printf( ber, "N}N}" );
294 #ifdef LDAP_CONNECTIONLESS
295 if( conn->c_is_udp && op->o_protocol == LDAP_VERSION2 && rc != -1 ) {
296 rc = ber_printf( ber, "N}" );
302 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
303 "send_ldap_response: conn %d ber_printf failed\n",
304 conn ? conn->c_connid : 0 ));
306 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
314 bytes = send_ldap_ber( conn, ber );
319 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
320 "send_ldap_response: conn %d ber write failed\n",
321 conn ? conn->c_connid : 0 ));
323 Debug( LDAP_DEBUG_ANY,
324 "send_ldap_response: ber write failed\n",
331 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
332 num_bytes_sent += bytes;
334 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
340 send_ldap_disconnect(
351 #define LDAP_UNSOLICITED_ERROR(e) \
352 ( (e) == LDAP_PROTOCOL_ERROR \
353 || (e) == LDAP_STRONG_AUTH_REQUIRED \
354 || (e) == LDAP_UNAVAILABLE )
356 assert( LDAP_UNSOLICITED_ERROR( err ) );
359 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
360 "send_ldap_disconnect: conn %d %d:%s\n",
361 conn ? conn->c_connid : 0, err, text ? text : "" ));
363 Debug( LDAP_DEBUG_TRACE,
364 "send_ldap_disconnect %d:%s\n",
365 err, text ? text : "", NULL );
369 if ( op->o_protocol < LDAP_VERSION3 ) {
371 tag = req2res( op->o_tag );
372 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
375 reqoid = LDAP_NOTICE_DISCONNECT;
376 tag = LDAP_RES_EXTENDED;
380 send_ldap_response( conn, op, tag, msgid,
381 err, NULL, text, NULL,
382 reqoid, NULL, NULL, NULL );
384 Statslog( LDAP_DEBUG_STATS,
385 "conn=%ld op=%ld DISCONNECT tag=%lu err=%ld text=%s\n",
386 (long) op->o_connid, (long) op->o_opid,
387 (unsigned long) tag, (long) err, text ? text : "" );
405 assert( !LDAP_API_ERROR( err ) );
408 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
409 "send_ldap_result : conn %ld op=%ld p=%d\n",
410 (long)op->o_connid, (long)op->o_opid, op->o_protocol ));
412 Debug( LDAP_DEBUG_TRACE,
413 "send_ldap_result: conn=%ld op=%ld p=%d\n",
414 (long) op->o_connid, (long) op->o_opid, op->o_protocol );
418 LDAP_LOG(( "operation", LDAP_LEVEL_ARGS,
419 "send_ldap_result: conn=%ld err=%d matched=\"%s\" text=\"%s\"\n",
420 (long)op->o_connid, err, matched ? matched : "", text ? text : "" ));
422 Debug( LDAP_DEBUG_ARGS,
423 "send_ldap_result: err=%d matched=\"%s\" text=\"%s\"\n",
424 err, matched ? matched : "", text ? text : "" );
430 LDAP_LOG(( "operation", LDAP_LEVEL_ARGS,
431 "send_ldap_result: referral=\"%s\"\n",
432 ref[0] && ref[0]->bv_val ? ref[0]->bv_val : "NULL" ));
434 Debug( LDAP_DEBUG_ARGS,
435 "send_ldap_result: referral=\"%s\"\n",
436 ref[0] && ref[0]->bv_val ? ref[0]->bv_val : "NULL",
441 assert( err != LDAP_PARTIAL_RESULTS );
443 if ( err == LDAP_REFERRAL ) {
445 err = LDAP_NO_SUCH_OBJECT;
446 } else if ( op->o_protocol < LDAP_VERSION3 ) {
447 err = LDAP_PARTIAL_RESULTS;
451 if ( op->o_protocol < LDAP_VERSION3 ) {
452 tmp = v2ref( ref, text );
457 tag = req2res( op->o_tag );
458 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
460 send_ldap_response( conn, op, tag, msgid,
461 err, matched, text, ref,
462 NULL, NULL, NULL, ctrls );
464 Statslog( LDAP_DEBUG_STATS,
465 "conn=%ld op=%ld RESULT tag=%lu err=%ld text=%s\n",
466 (long) op->o_connid, (long) op->o_opid,
467 (unsigned long) tag, (long) err, text ? text : "" );
490 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
491 "send_ldap_sasl: conn %d err=%ld len=%ld\n",
492 op->o_connid, (long)err, cred ? cred->bv_len : -1 ));
494 Debug( LDAP_DEBUG_TRACE, "send_ldap_sasl: err=%ld len=%ld\n",
495 (long) err, cred ? cred->bv_len : -1, NULL );
499 tag = req2res( op->o_tag );
500 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
502 send_ldap_response( conn, op, tag, msgid,
503 err, matched, text, ref,
504 NULL, NULL, cred, ctrls );
514 struct berval **refs,
516 struct berval *rspdata,
524 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
525 "send_ldap_extended: conn %d err=%ld oid=%s len=%ld\n",
526 op->o_connid, (long)err, rspoid ? rspoid : "",
527 rspdata != NULL ? (long)rspdata->bv_len : (long)0 ));
529 Debug( LDAP_DEBUG_TRACE,
530 "send_ldap_extended err=%ld oid=%s len=%ld\n",
532 rspoid ? rspoid : "",
533 rspdata != NULL ? (long) rspdata->bv_len : (long) 0 );
537 tag = req2res( op->o_tag );
538 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
540 send_ldap_response( conn, op, tag, msgid,
541 err, matched, text, refs,
542 rspoid, rspdata, NULL, ctrls );
553 struct berval **refs,
562 assert( !LDAP_API_ERROR( err ) );
565 op->o_sresult(conn, op, err, matched, text, refs,
571 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
572 "send_search_result: conn %d err=%d matched=\"%s\"\n",
573 op->o_connid, err, matched ? matched : "",
576 Debug( LDAP_DEBUG_TRACE,
577 "send_search_result: err=%d matched=\"%s\" text=\"%s\"\n",
578 err, matched ? matched : "", text ? text : "" );
582 assert( err != LDAP_PARTIAL_RESULTS );
584 if( op->o_protocol < LDAP_VERSION3 ) {
585 /* send references in search results */
586 if( err == LDAP_REFERRAL ) {
587 err = LDAP_PARTIAL_RESULTS;
590 tmp = v2ref( refs, text );
595 /* don't send references in search results */
596 assert( refs == NULL );
599 if( err == LDAP_REFERRAL ) {
604 tag = req2res( op->o_tag );
605 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
607 send_ldap_response( conn, op, tag, msgid,
608 err, matched, text, refs,
609 NULL, NULL, NULL, ctrls );
611 Statslog( LDAP_DEBUG_STATS,
612 "conn=%ld op=%ld SEARCH RESULT tag=%lu err=%ld text=%s\n",
613 (long) op->o_connid, (long) op->o_opid,
614 (unsigned long) tag, (long) err, text ? text : "" );
640 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
643 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
644 "send_search_entry: conn %d dn=\"%s\"%s\n",
645 op->o_connid, e->e_dn,
646 attrsonly ? " (attrsOnly)" : "" ));
648 Debug( LDAP_DEBUG_TRACE,
649 "=> send_search_entry: dn=\"%s\"%s\n",
650 e->e_dn, attrsonly ? " (attrsOnly)" : "", 0 );
654 if ( ! access_allowed( be, conn, op, e,
655 ad_entry, NULL, ACL_READ ) )
658 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
659 "send_search_entry: conn %d access to entry (%s) not allowed\n",
660 op->o_connid, e->e_dn ));
662 Debug( LDAP_DEBUG_ACL,
663 "send_search_entry: access to entry not allowed\n",
672 ber = ber_alloc_t( LBER_USE_DER );
676 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
677 "send_search_entry: conn %d ber_alloc failed\n",
680 Debug( LDAP_DEBUG_ANY, "ber_alloc failed\n", 0, 0, 0 );
683 send_ldap_result( conn, op, LDAP_OTHER,
684 NULL, "BER allocation error", NULL, NULL );
688 #ifdef LDAP_CONNECTIONLESS
689 if (conn->c_is_udp) {
690 rc = ber_write(ber, (char *)&op->o_peeraddr, sizeof(struct sockaddr), 0);
691 if (rc != sizeof(struct sockaddr)) {
693 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
694 "send_search_entry: conn %d ber_printf failed\n",
695 conn ? conn->c_connid : 0 ));
697 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
703 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2) {
704 rc = ber_printf( ber, "{is{t{s{" /*}}}*/,
705 op->o_msgid, "", LDAP_RES_SEARCH_ENTRY, e->e_dn );
709 rc = ber_printf( ber, "{it{s{" /*}}}*/, op->o_msgid,
710 LDAP_RES_SEARCH_ENTRY, e->e_dn );
715 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
716 "send_search_entry: conn %d ber_printf failed\n",
719 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
723 send_ldap_result( conn, op, LDAP_OTHER,
724 NULL, "encoding DN error", NULL, NULL );
728 /* check for special all user attributes ("*") type */
729 userattrs = ( attrs == NULL ) ? 1
730 : charray_inlist( attrs, LDAP_ALL_USER_ATTRIBUTES );
732 /* check for special all operational attributes ("+") type */
733 opattrs = ( attrs == NULL ) ? 0
734 : charray_inlist( attrs, LDAP_ALL_OPERATIONAL_ATTRIBUTES );
736 for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
737 AttributeDescription *desc = a->a_desc;
738 char *type = desc->ad_cname.bv_val;
740 if ( attrs == NULL ) {
741 /* all addrs request, skip operational attributes */
742 if( is_at_operational( desc->ad_type ) ) {
747 /* specific addrs requested */
748 if ( is_at_operational( desc->ad_type ) ) {
749 if( !opattrs && !ad_inlist( desc, attrs ) ) {
754 if (!userattrs && !ad_inlist( desc, attrs ) ) {
760 if ( ! access_allowed( be, conn, op, e, desc, NULL, ACL_READ ) ) {
762 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
763 "send_search_entry: conn %d access to attribute %s not allowed\n",
764 op->o_connid, desc->ad_cname.bv_val ));
766 Debug( LDAP_DEBUG_ACL, "acl: access to attribute %s not allowed\n",
767 desc->ad_cname.bv_val, 0, 0 );
773 if (( rc = ber_printf( ber, "{s[" /*]}*/ , type )) == -1 ) {
775 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
776 "send_search_entry: conn %d ber_printf failed\n",
779 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
783 send_ldap_result( conn, op, LDAP_OTHER,
784 NULL, "encoding description error", NULL, NULL );
789 for ( i = 0; a->a_vals[i] != NULL; i++ ) {
790 if ( ! access_allowed( be, conn, op, e,
791 desc, a->a_vals[i], ACL_READ ) )
794 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
795 "send_search_entry: conn %d access to attribute %s, value %d not allowed\n",
796 op->o_connid, desc->ad_cname.bv_val, i ));
798 Debug( LDAP_DEBUG_ACL,
799 "acl: access to attribute %s, value %d not allowed\n",
800 desc->ad_cname.bv_val, i, 0 );
806 if (( rc = ber_printf( ber, "O", a->a_vals[i] )) == -1 ) {
808 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
809 "send_search_entry: conn %d ber_printf failed.\n",
812 Debug( LDAP_DEBUG_ANY,
813 "ber_printf failed\n", 0, 0, 0 );
817 send_ldap_result( conn, op, LDAP_OTHER,
818 NULL, "encoding values error", NULL, NULL );
824 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
826 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
827 "send_search_entry: conn %d ber_printf failed\n",
830 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
834 send_ldap_result( conn, op, LDAP_OTHER,
835 NULL, "encode end error", NULL, NULL );
840 /* eventually will loop through generated operational attributes */
841 /* only have subschemaSubentry implemented */
842 aa = backend_operational( be, conn, op, e );
844 for (a = aa ; a != NULL; a = a->a_next ) {
845 AttributeDescription *desc = a->a_desc;
847 if ( attrs == NULL ) {
848 /* all addrs request, skip operational attributes */
849 if( is_at_operational( desc->ad_type ) ) {
854 /* specific addrs requested */
855 if( is_at_operational( desc->ad_type ) ) {
856 if( !opattrs && !ad_inlist( desc, attrs ) ) {
860 if (!userattrs && !ad_inlist( desc, attrs ) )
867 if ( ! access_allowed( be, conn, op, e, desc, NULL, ACL_READ ) ) {
869 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
870 "send_search_entry: conn %s access to attribute %s not allowed\n",
871 op->o_connid, desc->ad_cname.bv_val ));
873 Debug( LDAP_DEBUG_ACL, "acl: access to attribute %s not allowed\n",
874 desc->ad_cname.bv_val, 0, 0 );
880 rc = ber_printf( ber, "{s[" /*]}*/ , desc->ad_cname.bv_val );
883 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
884 "send_search_entry: conn %d ber_printf failed\n",
887 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
891 send_ldap_result( conn, op, LDAP_OTHER,
892 NULL, "encoding description error", NULL, NULL );
898 for ( i = 0; a->a_vals[i] != NULL; i++ ) {
899 if ( ! access_allowed( be, conn, op, e,
900 desc, a->a_vals[i], ACL_READ ) )
903 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
904 "send_search_entry: conn %d access to %s, value %d not allowed\n",
905 op->o_connid, desc->ad_cname.bv_val, i ));
907 Debug( LDAP_DEBUG_ACL,
908 "acl: access to attribute %s, value %d not allowed\n",
909 desc->ad_cname.bv_val, i, 0 );
916 if (( rc = ber_printf( ber, "O", a->a_vals[i] )) == -1 ) {
918 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
919 "send_search_entry: conn %d ber_printf failed\n",
922 Debug( LDAP_DEBUG_ANY,
923 "ber_printf failed\n", 0, 0, 0 );
927 send_ldap_result( conn, op, LDAP_OTHER,
928 NULL, "encoding values error", NULL, NULL );
935 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
937 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
938 "send_search_entry: conn %d ber_printf failed\n",
941 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
945 send_ldap_result( conn, op, LDAP_OTHER,
946 NULL, "encode end error", NULL, NULL );
954 rc = ber_printf( ber, /*{{{*/ "}N}N}" );
956 #ifdef LDAP_CONNECTIONLESS
957 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2 && rc != -1)
958 rc = ber_printf( ber, "}" );
962 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
963 "send_search_entry: conn %d ber_printf failed\n",
966 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
970 send_ldap_result( conn, op, LDAP_OTHER,
971 NULL, "encode entry end error", NULL, NULL );
975 bytes = send_ldap_ber( conn, ber );
980 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
981 "send_ldap_response: conn %d ber write failed.\n",
984 Debug( LDAP_DEBUG_ANY,
985 "send_ldap_response: ber write failed\n",
992 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
993 num_bytes_sent += bytes;
996 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
998 Statslog( LDAP_DEBUG_STATS2, "conn=%ld op=%ld ENTRY dn=\"%s\"\n",
999 (long) conn->c_connid, (long) op->o_opid, e->e_dn, 0, 0 );
1002 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1003 "send_search_entry: conn %d exit.\n",
1006 Debug( LDAP_DEBUG_TRACE, "<= send_search_entry\n", 0, 0, 0 );
1017 send_search_reference(
1022 struct berval **refs,
1023 LDAPControl **ctrls,
1024 struct berval ***v2refs
1031 AttributeDescription *ad_ref = slap_schema.si_ad_ref;
1032 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
1035 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1036 "send_search_reference: conn %d dn=\"%s\"\n",
1037 op->o_connid, e->e_dn ));
1039 Debug( LDAP_DEBUG_TRACE,
1040 "=> send_search_reference: dn=\"%s\"\n",
1045 if ( ! access_allowed( be, conn, op, e,
1046 ad_entry, NULL, ACL_READ ) )
1049 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
1050 "send_search_reference: conn %d access to entry %s not allowed\n",
1051 op->o_connid, e->e_dn ));
1053 Debug( LDAP_DEBUG_ACL,
1054 "send_search_reference: access to entry not allowed\n",
1061 if ( ! access_allowed( be, conn, op, e,
1062 ad_ref, NULL, ACL_READ ) )
1065 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
1066 "send_search_reference: conn %d access to reference not allowed.\n",
1069 Debug( LDAP_DEBUG_ACL,
1070 "send_search_reference: access to reference not allowed\n",
1077 if( refs == NULL ) {
1079 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1080 "send_search_reference: null ref in (%s).\n",
1081 op->o_connid, e->e_dn ));
1083 Debug( LDAP_DEBUG_ANY,
1084 "send_search_reference: null ref in (%s)\n",
1091 if( op->o_protocol < LDAP_VERSION3 ) {
1092 /* save the references for the result */
1093 if( *refs != NULL ) {
1094 value_add( v2refs, refs );
1099 ber = ber_alloc_t( LBER_USE_DER );
1101 if ( ber == NULL ) {
1103 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1104 "send_search_reference: conn %d ber_alloc failed\n",
1107 Debug( LDAP_DEBUG_ANY,
1108 "send_search_reference: ber_alloc failed\n", 0, 0, 0 );
1111 send_ldap_result( conn, op, LDAP_OTHER,
1112 NULL, "alloc BER error", NULL, NULL );
1116 rc = ber_printf( ber, "{it{V}N}", op->o_msgid,
1117 LDAP_RES_SEARCH_REFERENCE, refs );
1121 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1122 "send_search_reference: conn %d ber_printf failed.\n",
1125 Debug( LDAP_DEBUG_ANY,
1126 "send_search_reference: ber_printf failed\n", 0, 0, 0 );
1130 send_ldap_result( conn, op, LDAP_OTHER,
1131 NULL, "encode DN error", NULL, NULL );
1135 bytes = send_ldap_ber( conn, ber );
1138 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1139 num_bytes_sent += bytes;
1142 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1144 Statslog( LDAP_DEBUG_STATS2, "conn=%ld op=%ld REF dn=\"%s\"\n",
1145 (long) conn->c_connid, (long) op->o_opid, e->e_dn, 0, 0 );
1148 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1149 "send_search_reference: conn %d exit.\n", op->o_connid ));
1151 Debug( LDAP_DEBUG_TRACE, "<= send_search_reference\n", 0, 0, 0 );
1169 *code = LDAP_SUCCESS;
1173 if ( strncasecmp( s, "RESULT", 6 ) != 0 ) {
1175 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
1176 "str2result: (%s), expecting \"RESULT\"\n", s ));
1178 Debug( LDAP_DEBUG_ANY, "str2result (%s) expecting \"RESULT\"\n",
1187 while ( (s = strchr( s, '\n' )) != NULL ) {
1192 if ( (c = strchr( s, ':' )) != NULL ) {
1196 if ( strncasecmp( s, "code", 4 ) == 0 ) {
1200 } else if ( strncasecmp( s, "matched", 7 ) == 0 ) {
1204 } else if ( strncasecmp( s, "info", 4 ) == 0 ) {
1210 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
1211 "str2result: (%s) unknown.\n", s ));
1213 Debug( LDAP_DEBUG_ANY, "str2result (%s) unknown\n",