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 : "" );
621 static struct berval AllUser = { sizeof(LDAP_ALL_USER_ATTRIBUTES)-1,
622 LDAP_ALL_USER_ATTRIBUTES };
623 static struct berval AllOper = { sizeof(LDAP_ALL_OPERATIONAL_ATTRIBUTES)-1,
624 LDAP_ALL_OPERATIONAL_ATTRIBUTES };
632 struct berval **attrs,
644 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
647 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
648 "send_search_entry: conn %d dn=\"%s\"%s\n",
649 op->o_connid, e->e_dn,
650 attrsonly ? " (attrsOnly)" : "" ));
652 Debug( LDAP_DEBUG_TRACE,
653 "=> send_search_entry: dn=\"%s\"%s\n",
654 e->e_dn, attrsonly ? " (attrsOnly)" : "", 0 );
658 if ( ! access_allowed( be, conn, op, e,
659 ad_entry, NULL, ACL_READ ) )
662 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
663 "send_search_entry: conn %d access to entry (%s) not allowed\n",
664 op->o_connid, e->e_dn ));
666 Debug( LDAP_DEBUG_ACL,
667 "send_search_entry: access to entry not allowed\n",
676 ber = ber_alloc_t( LBER_USE_DER );
680 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
681 "send_search_entry: conn %d ber_alloc failed\n",
684 Debug( LDAP_DEBUG_ANY, "ber_alloc failed\n", 0, 0, 0 );
687 send_ldap_result( conn, op, LDAP_OTHER,
688 NULL, "BER allocation error", NULL, NULL );
692 #ifdef LDAP_CONNECTIONLESS
693 if (conn->c_is_udp) {
694 rc = ber_write(ber, (char *)&op->o_peeraddr, sizeof(struct sockaddr), 0);
695 if (rc != sizeof(struct sockaddr)) {
697 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
698 "send_search_entry: conn %d ber_printf failed\n",
699 conn ? conn->c_connid : 0 ));
701 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
707 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2) {
708 rc = ber_printf( ber, "{is{t{O{" /*}}}*/,
709 op->o_msgid, "", LDAP_RES_SEARCH_ENTRY, &e->e_name );
713 rc = ber_printf( ber, "{it{O{" /*}}}*/, op->o_msgid,
714 LDAP_RES_SEARCH_ENTRY, &e->e_name );
719 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
720 "send_search_entry: conn %d ber_printf failed\n",
723 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
727 send_ldap_result( conn, op, LDAP_OTHER,
728 NULL, "encoding DN error", NULL, NULL );
732 /* check for special all user attributes ("*") type */
733 userattrs = ( attrs == NULL ) ? 1
734 : bvec_inlist( attrs, &AllUser );
736 /* check for special all operational attributes ("+") type */
737 opattrs = ( attrs == NULL ) ? 0
738 : bvec_inlist( attrs, &AllOper );
740 for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
741 AttributeDescription *desc = a->a_desc;
743 if ( attrs == NULL ) {
744 /* all attrs request, skip operational attributes */
745 if( is_at_operational( desc->ad_type ) ) {
750 /* specific attrs requested */
751 if ( is_at_operational( desc->ad_type ) ) {
752 if( !opattrs && !ad_inlist( desc, attrs ) ) {
757 if (!userattrs && !ad_inlist( desc, attrs ) ) {
763 if ( ! access_allowed( be, conn, op, e, desc, NULL, ACL_READ ) ) {
765 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
766 "send_search_entry: conn %d access to attribute %s not allowed\n",
767 op->o_connid, desc->ad_cname.bv_val ));
769 Debug( LDAP_DEBUG_ACL, "acl: access to attribute %s not allowed\n",
770 desc->ad_cname.bv_val, 0, 0 );
776 if (( rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname )) == -1 ) {
778 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
779 "send_search_entry: conn %d ber_printf failed\n",
782 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
786 send_ldap_result( conn, op, LDAP_OTHER,
787 NULL, "encoding description error", NULL, NULL );
792 for ( i = 0; a->a_vals[i] != NULL; i++ ) {
793 if ( ! access_allowed( be, conn, op, e,
794 desc, a->a_vals[i], ACL_READ ) )
797 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
798 "send_search_entry: conn %d access to attribute %s, value %d not allowed\n",
799 op->o_connid, desc->ad_cname.bv_val, i ));
801 Debug( LDAP_DEBUG_ACL,
802 "acl: access to attribute %s, value %d not allowed\n",
803 desc->ad_cname.bv_val, i, 0 );
809 if (( rc = ber_printf( ber, "O", a->a_vals[i] )) == -1 ) {
811 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
812 "send_search_entry: conn %d ber_printf failed.\n",
815 Debug( LDAP_DEBUG_ANY,
816 "ber_printf failed\n", 0, 0, 0 );
820 send_ldap_result( conn, op, LDAP_OTHER,
821 NULL, "encoding values error", NULL, NULL );
827 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
829 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
830 "send_search_entry: conn %d ber_printf failed\n",
833 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
837 send_ldap_result( conn, op, LDAP_OTHER,
838 NULL, "encode end error", NULL, NULL );
843 /* eventually will loop through generated operational attributes */
844 /* only have subschemaSubentry implemented */
845 aa = backend_operational( be, conn, op, e, attrs, opattrs );
847 for (a = aa ; a != NULL; a = a->a_next ) {
848 AttributeDescription *desc = a->a_desc;
850 if ( attrs == NULL ) {
851 /* all attrs request, skip operational attributes */
852 if( is_at_operational( desc->ad_type ) ) {
857 /* specific attrs requested */
858 if( is_at_operational( desc->ad_type ) ) {
859 if( !opattrs && !ad_inlist( desc, attrs ) ) {
863 if (!userattrs && !ad_inlist( desc, attrs ) )
870 if ( ! access_allowed( be, conn, op, e, desc, NULL, ACL_READ ) ) {
872 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
873 "send_search_entry: conn %s access to attribute %s not allowed\n",
874 op->o_connid, desc->ad_cname.bv_val ));
876 Debug( LDAP_DEBUG_ACL, "acl: access to attribute %s not allowed\n",
877 desc->ad_cname.bv_val, 0, 0 );
883 rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname );
886 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
887 "send_search_entry: conn %d ber_printf failed\n",
890 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
894 send_ldap_result( conn, op, LDAP_OTHER,
895 NULL, "encoding description error", NULL, NULL );
901 for ( i = 0; a->a_vals[i] != NULL; i++ ) {
902 if ( ! access_allowed( be, conn, op, e,
903 desc, a->a_vals[i], ACL_READ ) )
906 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
907 "send_search_entry: conn %d access to %s, value %d not allowed\n",
908 op->o_connid, desc->ad_cname.bv_val, i ));
910 Debug( LDAP_DEBUG_ACL,
911 "acl: access to attribute %s, value %d not allowed\n",
912 desc->ad_cname.bv_val, i, 0 );
919 if (( rc = ber_printf( ber, "O", a->a_vals[i] )) == -1 ) {
921 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
922 "send_search_entry: conn %d ber_printf failed\n",
925 Debug( LDAP_DEBUG_ANY,
926 "ber_printf failed\n", 0, 0, 0 );
930 send_ldap_result( conn, op, LDAP_OTHER,
931 NULL, "encoding values error", NULL, NULL );
938 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
940 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
941 "send_search_entry: conn %d ber_printf failed\n",
944 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
948 send_ldap_result( conn, op, LDAP_OTHER,
949 NULL, "encode end error", NULL, NULL );
957 rc = ber_printf( ber, /*{{{*/ "}N}N}" );
959 #ifdef LDAP_CONNECTIONLESS
960 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2 && rc != -1)
961 rc = ber_printf( ber, "}" );
965 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
966 "send_search_entry: conn %d ber_printf failed\n",
969 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
973 send_ldap_result( conn, op, LDAP_OTHER,
974 NULL, "encode entry end error", NULL, NULL );
978 bytes = send_ldap_ber( conn, ber );
983 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
984 "send_ldap_response: conn %d ber write failed.\n",
987 Debug( LDAP_DEBUG_ANY,
988 "send_ldap_response: ber write failed\n",
995 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
996 num_bytes_sent += bytes;
999 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1001 Statslog( LDAP_DEBUG_STATS2, "conn=%ld op=%ld ENTRY dn=\"%s\"\n",
1002 (long) conn->c_connid, (long) op->o_opid, e->e_dn, 0, 0 );
1005 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1006 "send_search_entry: conn %d exit.\n",
1009 Debug( LDAP_DEBUG_TRACE, "<= send_search_entry\n", 0, 0, 0 );
1020 send_search_reference(
1025 struct berval **refs,
1026 LDAPControl **ctrls,
1027 struct berval ***v2refs
1034 AttributeDescription *ad_ref = slap_schema.si_ad_ref;
1035 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
1038 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1039 "send_search_reference: conn %d dn=\"%s\"\n",
1040 op->o_connid, e->e_dn ));
1042 Debug( LDAP_DEBUG_TRACE,
1043 "=> send_search_reference: dn=\"%s\"\n",
1048 if ( ! access_allowed( be, conn, op, e,
1049 ad_entry, NULL, ACL_READ ) )
1052 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
1053 "send_search_reference: conn %d access to entry %s not allowed\n",
1054 op->o_connid, e->e_dn ));
1056 Debug( LDAP_DEBUG_ACL,
1057 "send_search_reference: access to entry not allowed\n",
1064 if ( ! access_allowed( be, conn, op, e,
1065 ad_ref, NULL, ACL_READ ) )
1068 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
1069 "send_search_reference: conn %d access to reference not allowed.\n",
1072 Debug( LDAP_DEBUG_ACL,
1073 "send_search_reference: access to reference not allowed\n",
1080 if( refs == NULL ) {
1082 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1083 "send_search_reference: null ref in (%s).\n",
1084 op->o_connid, e->e_dn ));
1086 Debug( LDAP_DEBUG_ANY,
1087 "send_search_reference: null ref in (%s)\n",
1094 if( op->o_protocol < LDAP_VERSION3 ) {
1095 /* save the references for the result */
1096 if( *refs != NULL ) {
1097 value_add( v2refs, refs );
1102 ber = ber_alloc_t( LBER_USE_DER );
1104 if ( ber == NULL ) {
1106 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1107 "send_search_reference: conn %d ber_alloc failed\n",
1110 Debug( LDAP_DEBUG_ANY,
1111 "send_search_reference: ber_alloc failed\n", 0, 0, 0 );
1114 send_ldap_result( conn, op, LDAP_OTHER,
1115 NULL, "alloc BER error", NULL, NULL );
1119 rc = ber_printf( ber, "{it{V}N}", op->o_msgid,
1120 LDAP_RES_SEARCH_REFERENCE, refs );
1124 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1125 "send_search_reference: conn %d ber_printf failed.\n",
1128 Debug( LDAP_DEBUG_ANY,
1129 "send_search_reference: ber_printf failed\n", 0, 0, 0 );
1133 send_ldap_result( conn, op, LDAP_OTHER,
1134 NULL, "encode DN error", NULL, NULL );
1138 bytes = send_ldap_ber( conn, ber );
1141 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1142 num_bytes_sent += bytes;
1145 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1147 Statslog( LDAP_DEBUG_STATS2, "conn=%ld op=%ld REF dn=\"%s\"\n",
1148 (long) conn->c_connid, (long) op->o_opid, e->e_dn, 0, 0 );
1151 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1152 "send_search_reference: conn %d exit.\n", op->o_connid ));
1154 Debug( LDAP_DEBUG_TRACE, "<= send_search_reference\n", 0, 0, 0 );
1172 *code = LDAP_SUCCESS;
1176 if ( strncasecmp( s, "RESULT", 6 ) != 0 ) {
1178 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
1179 "str2result: (%s), expecting \"RESULT\"\n", s ));
1181 Debug( LDAP_DEBUG_ANY, "str2result (%s) expecting \"RESULT\"\n",
1190 while ( (s = strchr( s, '\n' )) != NULL ) {
1195 if ( (c = strchr( s, ':' )) != NULL ) {
1199 if ( strncasecmp( s, "code", 4 ) == 0 ) {
1203 } else if ( strncasecmp( s, "matched", 7 ) == 0 ) {
1207 } else if ( strncasecmp( s, "info", 4 ) == 0 ) {
1213 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
1214 "str2result: (%s) unknown.\n", s ));
1216 Debug( LDAP_DEBUG_ANY, "str2result (%s) unknown\n",