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/string.h>
17 #include <ac/unistd.h>
21 static char *v2ref( BerVarray ref, const char *text )
23 size_t len = 0, i = 0;
28 return ch_strdup(text);
36 if (text[len-1] != '\n') {
41 v2 = ch_malloc( len+i+sizeof("Referral:") );
48 strcpy( v2+len, "Referral:" );
49 len += sizeof("Referral:");
51 for( i=0; ref[i].bv_val != NULL; i++ ) {
52 v2 = ch_realloc( v2, len + ref[i].bv_len + 1 );
54 AC_MEMCPY(&v2[len], ref[i].bv_val, ref[i].bv_len );
56 if (ref[i].bv_val[ref[i].bv_len-1] != '/') {
65 static ber_tag_t req2res( ber_tag_t tag )
70 case LDAP_REQ_COMPARE:
71 case LDAP_REQ_EXTENDED:
78 tag = LDAP_RES_DELETE;
81 case LDAP_REQ_ABANDON:
87 tag = LDAP_RES_SEARCH_RESULT;
97 static long send_ldap_ber(
103 ber_get_option( ber, LBER_OPT_BER_BYTES_TO_WRITE, &bytes );
105 /* write only one pdu at a time - wait til it's our turn */
106 ldap_pvt_thread_mutex_lock( &conn->c_write_mutex );
108 /* lock the connection */
109 ldap_pvt_thread_mutex_lock( &conn->c_mutex );
116 if ( connection_state_closing( conn ) ) {
117 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
118 ldap_pvt_thread_mutex_unlock( &conn->c_write_mutex );
123 if ( ber_flush( conn->c_sb, ber, 0 ) == 0 ) {
130 * we got an error. if it's ewouldblock, we need to
131 * wait on the socket being writable. otherwise, figure
132 * it's a hard error and return.
136 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
137 "send_ldap_ber: conn %d ber_flush failed err=%d (%s)\n",
138 conn ? conn->c_connid : 0, err, sock_errstr(err) ));
140 Debug( LDAP_DEBUG_CONNS, "ber_flush failed errno=%d reason=\"%s\"\n",
141 err, sock_errstr(err), 0 );
144 if ( err != EWOULDBLOCK && err != EAGAIN ) {
145 connection_closing( conn );
147 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
148 ldap_pvt_thread_mutex_unlock( &conn->c_write_mutex );
153 /* wait for socket to be write-ready */
154 conn->c_writewaiter = 1;
155 ber_sockbuf_ctrl( conn->c_sb, LBER_SB_OPT_GET_FD, &sd );
156 slapd_set_write( sd, 1 );
158 ldap_pvt_thread_cond_wait( &conn->c_write_cv, &conn->c_mutex );
159 conn->c_writewaiter = 0;
162 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
163 ldap_pvt_thread_mutex_unlock( &conn->c_write_mutex );
179 struct berval *resdata,
180 struct berval *sasldata,
185 BerElement *ber = (BerElement *)berbuf;
189 if (op->o_callback && op->o_callback->sc_response) {
190 op->o_callback->sc_response( conn, op, tag, msgid, err, matched,
191 text, ref, resoid, resdata, sasldata, ctrls );
195 assert( ctrls == NULL ); /* ctrls not implemented */
197 ber_init_w_nullc( ber, LBER_USE_DER );
200 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
201 "send_ldap_response: conn %d msgid=%ld tag=%ld err=%ld\n",
202 conn ? conn->c_connid : 0, (long)msgid, (long)tag, (long)err ));
204 Debug( LDAP_DEBUG_TRACE,
205 "send_ldap_response: msgid=%ld tag=%ld err=%ld\n",
206 (long) msgid, (long) tag, (long) err );
211 LDAP_LOG(( "operation", LDAP_LEVEL_ARGS,
212 "send_ldap_response: conn %d ref=\"%s\"\n",
213 conn ? conn->c_connid : 0,
214 ref[0].bv_val ? ref[0].bv_val : "NULL" ));
216 Debug( LDAP_DEBUG_ARGS, "send_ldap_response: ref=\"%s\"\n",
217 ref[0].bv_val ? ref[0].bv_val : "NULL",
223 #ifdef LDAP_CONNECTIONLESS
224 if (conn->c_is_udp) {
225 rc = ber_write(ber, (char *)&op->o_peeraddr, sizeof(struct sockaddr), 0);
226 if (rc != sizeof(struct sockaddr)) {
228 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
229 "send_ldap_response: conn %d ber_write failed\n",
230 conn ? conn->c_connid : 0 ));
232 Debug( LDAP_DEBUG_ANY, "ber_write failed\n", 0, 0, 0 );
238 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2) {
239 rc = ber_printf( ber, "{is{t{ess",
241 matched == NULL ? "" : matched,
242 text == NULL ? "" : text );
246 rc = ber_printf( ber, "{it{ess",
248 matched == NULL ? "" : matched,
249 text == NULL ? "" : text );
254 assert( err == LDAP_REFERRAL );
255 rc = ber_printf( ber, "t{W}",
256 LDAP_TAG_REFERRAL, ref );
258 assert( err != LDAP_REFERRAL );
262 if( rc != -1 && sasldata != NULL ) {
263 rc = ber_printf( ber, "tO",
264 LDAP_TAG_SASL_RES_CREDS, sasldata );
267 if( rc != -1 && resoid != NULL ) {
268 rc = ber_printf( ber, "ts",
269 LDAP_TAG_EXOP_RES_OID, resoid );
272 if( rc != -1 && resdata != NULL ) {
273 rc = ber_printf( ber, "tO",
274 LDAP_TAG_EXOP_RES_VALUE, resdata );
278 rc = ber_printf( ber, "N}N}" );
280 #ifdef LDAP_CONNECTIONLESS
281 if( conn->c_is_udp && op->o_protocol == LDAP_VERSION2 && rc != -1 ) {
282 rc = ber_printf( ber, "N}" );
288 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
289 "send_ldap_response: conn %d ber_printf failed\n",
290 conn ? conn->c_connid : 0 ));
292 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
300 bytes = send_ldap_ber( conn, ber );
305 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
306 "send_ldap_response: conn %d ber write failed\n",
307 conn ? conn->c_connid : 0 ));
309 Debug( LDAP_DEBUG_ANY,
310 "send_ldap_response: ber write failed\n",
317 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
318 num_bytes_sent += bytes;
320 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
326 send_ldap_disconnect(
337 #define LDAP_UNSOLICITED_ERROR(e) \
338 ( (e) == LDAP_PROTOCOL_ERROR \
339 || (e) == LDAP_STRONG_AUTH_REQUIRED \
340 || (e) == LDAP_UNAVAILABLE )
342 assert( LDAP_UNSOLICITED_ERROR( err ) );
345 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
346 "send_ldap_disconnect: conn %d %d:%s\n",
347 conn ? conn->c_connid : 0, err, text ? text : "" ));
349 Debug( LDAP_DEBUG_TRACE,
350 "send_ldap_disconnect %d:%s\n",
351 err, text ? text : "", NULL );
355 if ( op->o_protocol < LDAP_VERSION3 ) {
357 tag = req2res( op->o_tag );
358 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
361 reqoid = LDAP_NOTICE_DISCONNECT;
362 tag = LDAP_RES_EXTENDED;
366 send_ldap_response( conn, op, tag, msgid,
367 err, NULL, text, NULL,
368 reqoid, NULL, NULL, NULL );
370 Statslog( LDAP_DEBUG_STATS,
371 "conn=%ld op=%ld DISCONNECT tag=%lu err=%ld text=%s\n",
372 (long) op->o_connid, (long) op->o_opid,
373 (unsigned long) tag, (long) err, text ? text : "" );
391 assert( !LDAP_API_ERROR( err ) );
394 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
395 "send_ldap_result : conn %ld op=%ld p=%d\n",
396 (long)op->o_connid, (long)op->o_opid, op->o_protocol ));
398 Debug( LDAP_DEBUG_TRACE,
399 "send_ldap_result: conn=%ld op=%ld p=%d\n",
400 (long) op->o_connid, (long) op->o_opid, op->o_protocol );
404 LDAP_LOG(( "operation", LDAP_LEVEL_ARGS,
405 "send_ldap_result: conn=%ld err=%d matched=\"%s\" text=\"%s\"\n",
406 (long)op->o_connid, err, matched ? matched : "", text ? text : "" ));
408 Debug( LDAP_DEBUG_ARGS,
409 "send_ldap_result: err=%d matched=\"%s\" text=\"%s\"\n",
410 err, matched ? matched : "", text ? text : "" );
416 LDAP_LOG(( "operation", LDAP_LEVEL_ARGS,
417 "send_ldap_result: referral=\"%s\"\n",
418 ref[0].bv_val ? ref[0].bv_val : "NULL" ));
420 Debug( LDAP_DEBUG_ARGS,
421 "send_ldap_result: referral=\"%s\"\n",
422 ref[0].bv_val ? ref[0].bv_val : "NULL",
427 assert( err != LDAP_PARTIAL_RESULTS );
429 if ( err == LDAP_REFERRAL ) {
431 err = LDAP_NO_SUCH_OBJECT;
432 } else if ( op->o_protocol < LDAP_VERSION3 ) {
433 err = LDAP_PARTIAL_RESULTS;
437 if ( op->o_protocol < LDAP_VERSION3 ) {
438 tmp = v2ref( ref, text );
443 tag = req2res( op->o_tag );
444 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
446 send_ldap_response( conn, op, tag, msgid,
447 err, matched, text, ref,
448 NULL, NULL, NULL, ctrls );
450 Statslog( LDAP_DEBUG_STATS,
451 "conn=%ld op=%ld RESULT tag=%lu err=%ld text=%s\n",
452 (long) op->o_connid, (long) op->o_opid,
453 (unsigned long) tag, (long) err, text ? text : "" );
476 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
477 "send_ldap_sasl: conn %d err=%ld len=%ld\n",
478 op->o_connid, (long)err, cred ? cred->bv_len : -1 ));
480 Debug( LDAP_DEBUG_TRACE, "send_ldap_sasl: err=%ld len=%ld\n",
481 (long) err, cred ? cred->bv_len : -1, NULL );
485 tag = req2res( op->o_tag );
486 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
488 send_ldap_response( conn, op, tag, msgid,
489 err, matched, text, ref,
490 NULL, NULL, cred, ctrls );
502 struct berval *rspdata,
510 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
511 "send_ldap_extended: conn %d err=%ld oid=%s len=%ld\n",
512 op->o_connid, (long)err, rspoid ? rspoid : "",
513 rspdata != NULL ? (long)rspdata->bv_len : (long)0 ));
515 Debug( LDAP_DEBUG_TRACE,
516 "send_ldap_extended err=%ld oid=%s len=%ld\n",
518 rspoid ? rspoid : "",
519 rspdata != NULL ? (long) rspdata->bv_len : (long) 0 );
523 tag = req2res( op->o_tag );
524 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
526 send_ldap_response( conn, op, tag, msgid,
527 err, matched, text, refs,
528 rspoid, rspdata, NULL, ctrls );
548 assert( !LDAP_API_ERROR( err ) );
550 if (op->o_callback && op->o_callback->sc_sresult) {
551 op->o_callback->sc_sresult(conn, op, err, matched, text, refs,
557 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
558 "send_search_result: conn %d err=%d matched=\"%s\"\n",
559 op->o_connid, err, matched ? matched : "",
562 Debug( LDAP_DEBUG_TRACE,
563 "send_search_result: err=%d matched=\"%s\" text=\"%s\"\n",
564 err, matched ? matched : "", text ? text : "" );
568 assert( err != LDAP_PARTIAL_RESULTS );
570 if( op->o_protocol < LDAP_VERSION3 ) {
571 /* send references in search results */
572 if( err == LDAP_REFERRAL ) {
573 err = LDAP_PARTIAL_RESULTS;
576 tmp = v2ref( refs, text );
581 /* don't send references in search results */
582 assert( refs == NULL );
585 if( err == LDAP_REFERRAL ) {
590 tag = req2res( op->o_tag );
591 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
593 send_ldap_response( conn, op, tag, msgid,
594 err, matched, text, refs,
595 NULL, NULL, NULL, ctrls );
599 sprintf( nbuf, "%ld nentries=%d", (long) err, nentries );
601 Statslog( LDAP_DEBUG_STATS,
602 "conn=%ld op=%ld SEARCH RESULT tag=%lu err=%s text=%s\n",
603 (long) op->o_connid, (long) op->o_opid,
604 (unsigned long) tag, nbuf, text ? text : "" );
612 static struct berval AllUser = { sizeof(LDAP_ALL_USER_ATTRIBUTES)-1,
613 LDAP_ALL_USER_ATTRIBUTES };
614 static struct berval AllOper = { sizeof(LDAP_ALL_OPERATIONAL_ATTRIBUTES)-1,
615 LDAP_ALL_OPERATIONAL_ATTRIBUTES };
623 AttributeName *attrs,
629 BerElement *ber = (BerElement *)berbuf;
635 static AccessControlState acl_state_init = ACL_STATE_INIT;
636 AccessControlState acl_state;
638 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
640 if (op->o_callback && op->o_callback->sc_sendentry) {
641 return op->o_callback->sc_sendentry( be, conn, op, e, attrs,
646 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
647 "send_search_entry: conn %d dn=\"%s\"%s\n",
648 op->o_connid, e->e_dn,
649 attrsonly ? " (attrsOnly)" : "" ));
651 Debug( LDAP_DEBUG_TRACE,
652 "=> send_search_entry: dn=\"%s\"%s\n",
653 e->e_dn, attrsonly ? " (attrsOnly)" : "", 0 );
656 if ( ! access_allowed( be, conn, op, e,
657 ad_entry, NULL, ACL_READ, NULL ) )
660 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
661 "send_search_entry: conn %d access to entry (%s) not allowed\n",
662 op->o_connid, e->e_dn ));
664 Debug( LDAP_DEBUG_ACL,
665 "send_search_entry: access to entry not allowed\n",
674 ber_init_w_nullc( ber, LBER_USE_DER );
676 #ifdef LDAP_CONNECTIONLESS
677 if (conn->c_is_udp) {
678 rc = ber_write(ber, (char *)&op->o_peeraddr, sizeof(struct sockaddr), 0);
679 if (rc != sizeof(struct sockaddr)) {
681 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
682 "send_search_entry: conn %d ber_printf failed\n",
683 conn ? conn->c_connid : 0 ));
685 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
691 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2) {
692 rc = ber_printf( ber, "{is{t{O{" /*}}}*/,
693 op->o_msgid, "", LDAP_RES_SEARCH_ENTRY, &e->e_name );
697 rc = ber_printf( ber, "{it{O{" /*}}}*/, op->o_msgid,
698 LDAP_RES_SEARCH_ENTRY, &e->e_name );
703 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
704 "send_search_entry: conn %d ber_printf failed\n",
707 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
711 send_ldap_result( conn, op, LDAP_OTHER,
712 NULL, "encoding DN error", NULL, NULL );
716 /* check for special all user attributes ("*") type */
717 userattrs = ( attrs == NULL ) ? 1
718 : an_find( attrs, &AllUser );
720 /* check for special all operational attributes ("+") type */
721 opattrs = ( attrs == NULL ) ? 0
722 : an_find( attrs, &AllOper );
724 for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
725 AttributeDescription *desc = a->a_desc;
727 if ( attrs == NULL ) {
728 /* all attrs request, skip operational attributes */
729 if( is_at_operational( desc->ad_type ) ) {
734 /* specific attrs requested */
735 if ( is_at_operational( desc->ad_type ) ) {
736 if( !opattrs && !ad_inlist( desc, attrs ) ) {
741 if (!userattrs && !ad_inlist( desc, attrs ) ) {
747 acl_state = acl_state_init;
749 if ( ! access_allowed( be, conn, op, e, desc, NULL,
750 ACL_READ, &acl_state ) )
753 LDAP_LOG(( "acl", LDAP_LEVEL_INFO, "send_search_entry: "
754 "conn %d access to attribute %s not allowed\n",
755 op->o_connid, desc->ad_cname.bv_val ));
757 Debug( LDAP_DEBUG_ACL, "acl: "
758 "access to attribute %s not allowed\n",
759 desc->ad_cname.bv_val, 0, 0 );
764 if (( rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname )) == -1 ) {
766 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
767 "send_search_entry: conn %d ber_printf failed\n",
770 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
774 send_ldap_result( conn, op, LDAP_OTHER,
775 NULL, "encoding description error", NULL, NULL );
780 for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
781 if ( ! access_allowed( be, conn, op, e,
782 desc, &a->a_vals[i], ACL_READ, &acl_state ) )
785 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
786 "send_search_entry: conn %d "
787 "access to attribute %s, value %d not allowed\n",
788 op->o_connid, desc->ad_cname.bv_val, i ));
790 Debug( LDAP_DEBUG_ACL,
791 "acl: access to attribute %s, value %d not allowed\n",
792 desc->ad_cname.bv_val, i, 0 );
798 if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
800 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
801 "send_search_entry: conn %d ber_printf failed.\n",
804 Debug( LDAP_DEBUG_ANY,
805 "ber_printf failed\n", 0, 0, 0 );
809 send_ldap_result( conn, op, LDAP_OTHER,
810 NULL, "encoding values error", NULL, NULL );
816 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
818 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
819 "send_search_entry: conn %d ber_printf failed\n",
822 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
826 send_ldap_result( conn, op, LDAP_OTHER,
827 NULL, "encode end error", NULL, NULL );
832 /* eventually will loop through generated operational attributes */
833 /* only have subschemaSubentry implemented */
834 aa = backend_operational( be, conn, op, e, attrs, opattrs );
836 for (a = aa ; a != NULL; a = a->a_next ) {
837 AttributeDescription *desc = a->a_desc;
839 if ( attrs == NULL ) {
840 /* all attrs request, skip operational attributes */
841 if( is_at_operational( desc->ad_type ) ) {
846 /* specific attrs requested */
847 if( is_at_operational( desc->ad_type ) ) {
848 if( !opattrs && !ad_inlist( desc, attrs ) ) {
852 if (!userattrs && !ad_inlist( desc, attrs ) )
859 acl_state = acl_state_init;
861 if ( ! access_allowed( be, conn, op, e, desc, NULL,
862 ACL_READ, &acl_state ) )
865 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
866 "send_search_entry: conn %s "
867 "access to attribute %s not allowed\n",
868 op->o_connid, desc->ad_cname.bv_val ));
870 Debug( LDAP_DEBUG_ACL, "acl: access to attribute %s not allowed\n",
871 desc->ad_cname.bv_val, 0, 0 );
877 rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname );
880 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
881 "send_search_entry: conn %d ber_printf failed\n",
884 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
888 send_ldap_result( conn, op, LDAP_OTHER,
889 NULL, "encoding description error", NULL, NULL );
895 for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
896 if ( ! access_allowed( be, conn, op, e,
897 desc, &a->a_vals[i], ACL_READ, &acl_state ) )
900 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
901 "send_search_entry: conn %d "
902 "access to %s, value %d not allowed\n",
903 op->o_connid, desc->ad_cname.bv_val, i ));
905 Debug( LDAP_DEBUG_ACL,
906 "acl: access to attribute %s, value %d not allowed\n",
907 desc->ad_cname.bv_val, i, 0 );
913 if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
915 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
916 "send_search_entry: conn %d ber_printf failed\n",
919 Debug( LDAP_DEBUG_ANY,
920 "ber_printf failed\n", 0, 0, 0 );
924 send_ldap_result( conn, op, LDAP_OTHER,
925 NULL, "encoding values error", NULL, NULL );
932 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
934 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
935 "send_search_entry: conn %d ber_printf failed\n",
938 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
942 send_ldap_result( conn, op, LDAP_OTHER,
943 NULL, "encode end error", NULL, NULL );
951 rc = ber_printf( ber, /*{{{*/ "}N}N}" );
953 #ifdef LDAP_CONNECTIONLESS
954 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2 && rc != -1)
955 rc = ber_printf( ber, "}" );
959 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
960 "send_search_entry: conn %d ber_printf failed\n",
963 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
967 send_ldap_result( conn, op, LDAP_OTHER,
968 NULL, "encode entry end error", NULL, NULL );
972 bytes = send_ldap_ber( conn, ber );
977 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
978 "send_ldap_response: conn %d ber write failed.\n",
981 Debug( LDAP_DEBUG_ANY,
982 "send_ldap_response: ber write failed\n",
989 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
990 num_bytes_sent += bytes;
993 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
995 Statslog( LDAP_DEBUG_STATS2, "conn=%ld op=%ld ENTRY dn=\"%s\"\n",
996 (long) conn->c_connid, (long) op->o_opid, e->e_dn, 0, 0 );
999 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1000 "send_search_entry: conn %d exit.\n",
1003 Debug( LDAP_DEBUG_TRACE, "<= send_search_entry\n", 0, 0, 0 );
1013 send_search_reference(
1019 LDAPControl **ctrls,
1024 BerElement *ber = (BerElement *)berbuf;
1028 AttributeDescription *ad_ref = slap_schema.si_ad_ref;
1029 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
1032 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1033 "send_search_reference: conn %d dn=\"%s\"\n",
1034 op->o_connid, e->e_dn ));
1036 Debug( LDAP_DEBUG_TRACE,
1037 "=> send_search_reference: dn=\"%s\"\n",
1042 if ( ! access_allowed( be, conn, op, e,
1043 ad_entry, NULL, ACL_READ, NULL ) )
1046 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
1047 "send_search_reference: conn %d access to entry %s not allowed\n",
1048 op->o_connid, e->e_dn ));
1050 Debug( LDAP_DEBUG_ACL,
1051 "send_search_reference: access to entry not allowed\n",
1058 if ( ! access_allowed( be, conn, op, e,
1059 ad_ref, NULL, ACL_READ, NULL ) )
1062 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
1063 "send_search_reference: conn %d access to reference not allowed.\n",
1066 Debug( LDAP_DEBUG_ACL,
1067 "send_search_reference: access to reference not allowed\n",
1074 if( refs == NULL ) {
1076 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1077 "send_search_reference: null ref in (%s).\n",
1078 op->o_connid, e->e_dn ));
1080 Debug( LDAP_DEBUG_ANY,
1081 "send_search_reference: null ref in (%s)\n",
1088 if( op->o_protocol < LDAP_VERSION3 ) {
1089 /* save the references for the result */
1090 if( refs[0].bv_val != NULL ) {
1091 value_add( v2refs, refs );
1096 ber_init_w_nullc( ber, LBER_USE_DER );
1098 rc = ber_printf( ber, "{it{W}N}", op->o_msgid,
1099 LDAP_RES_SEARCH_REFERENCE, refs );
1103 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1104 "send_search_reference: conn %d ber_printf failed.\n",
1107 Debug( LDAP_DEBUG_ANY,
1108 "send_search_reference: ber_printf failed\n", 0, 0, 0 );
1111 ber_free_buf( ber );
1112 send_ldap_result( conn, op, LDAP_OTHER,
1113 NULL, "encode DN error", NULL, NULL );
1117 bytes = send_ldap_ber( conn, ber );
1118 ber_free_buf( ber );
1120 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1121 num_bytes_sent += bytes;
1124 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1126 Statslog( LDAP_DEBUG_STATS2, "conn=%ld op=%ld REF dn=\"%s\"\n",
1127 (long) conn->c_connid, (long) op->o_opid, e->e_dn, 0, 0 );
1130 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1131 "send_search_reference: conn %d exit.\n", op->o_connid ));
1133 Debug( LDAP_DEBUG_TRACE, "<= send_search_reference\n", 0, 0, 0 );
1151 *code = LDAP_SUCCESS;
1155 if ( strncasecmp( s, "RESULT", 6 ) != 0 ) {
1157 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
1158 "str2result: (%s), expecting \"RESULT\"\n", s ));
1160 Debug( LDAP_DEBUG_ANY, "str2result (%s) expecting \"RESULT\"\n",
1169 while ( (s = strchr( s, '\n' )) != NULL ) {
1174 if ( (c = strchr( s, ':' )) != NULL ) {
1178 if ( strncasecmp( s, "code", 4 ) == 0 ) {
1182 } else if ( strncasecmp( s, "matched", 7 ) == 0 ) {
1186 } else if ( strncasecmp( s, "info", 4 ) == 0 ) {
1192 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
1193 "str2result: (%s) unknown.\n", s ));
1195 Debug( LDAP_DEBUG_ANY, "str2result (%s) unknown\n",