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, "send_search_entry: "
766 "conn %d access to attribute %s not allowed\n",
767 op->o_connid, desc->ad_cname.bv_val ));
769 Debug( LDAP_DEBUG_ACL, "acl: "
770 "access to attribute %s not allowed\n",
771 desc->ad_cname.bv_val, 0, 0 );
777 if (( rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname )) == -1 ) {
779 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
780 "send_search_entry: conn %d ber_printf failed\n",
783 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
787 send_ldap_result( conn, op, LDAP_OTHER,
788 NULL, "encoding description error", NULL, NULL );
793 for ( i = 0; a->a_vals[i] != NULL; i++ ) {
794 if ( ! access_allowed( be, conn, op, e,
795 desc, a->a_vals[i], ACL_READ ) )
798 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
799 "send_search_entry: conn %d access to attribute %s, value %d not allowed\n",
800 op->o_connid, desc->ad_cname.bv_val, i ));
802 Debug( LDAP_DEBUG_ACL,
803 "acl: access to attribute %s, value %d not allowed\n",
804 desc->ad_cname.bv_val, i, 0 );
810 if (( rc = ber_printf( ber, "O", a->a_vals[i] )) == -1 ) {
812 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
813 "send_search_entry: conn %d ber_printf failed.\n",
816 Debug( LDAP_DEBUG_ANY,
817 "ber_printf failed\n", 0, 0, 0 );
821 send_ldap_result( conn, op, LDAP_OTHER,
822 NULL, "encoding values error", NULL, NULL );
828 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
830 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
831 "send_search_entry: conn %d ber_printf failed\n",
834 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
838 send_ldap_result( conn, op, LDAP_OTHER,
839 NULL, "encode end error", NULL, NULL );
844 /* eventually will loop through generated operational attributes */
845 /* only have subschemaSubentry implemented */
846 aa = backend_operational( be, conn, op, e, attrs, opattrs );
848 for (a = aa ; a != NULL; a = a->a_next ) {
849 AttributeDescription *desc = a->a_desc;
851 if ( attrs == NULL ) {
852 /* all attrs request, skip operational attributes */
853 if( is_at_operational( desc->ad_type ) ) {
858 /* specific attrs requested */
859 if( is_at_operational( desc->ad_type ) ) {
860 if( !opattrs && !ad_inlist( desc, attrs ) ) {
864 if (!userattrs && !ad_inlist( desc, attrs ) )
871 if ( ! access_allowed( be, conn, op, e, desc, NULL, ACL_READ ) ) {
873 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
874 "send_search_entry: conn %s access to attribute %s not allowed\n",
875 op->o_connid, desc->ad_cname.bv_val ));
877 Debug( LDAP_DEBUG_ACL, "acl: access to attribute %s not allowed\n",
878 desc->ad_cname.bv_val, 0, 0 );
884 rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname );
887 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
888 "send_search_entry: conn %d ber_printf failed\n",
891 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
895 send_ldap_result( conn, op, LDAP_OTHER,
896 NULL, "encoding description error", NULL, NULL );
902 for ( i = 0; a->a_vals[i] != NULL; i++ ) {
903 if ( ! access_allowed( be, conn, op, e,
904 desc, a->a_vals[i], ACL_READ ) )
907 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
908 "send_search_entry: conn %d access to %s, value %d not allowed\n",
909 op->o_connid, desc->ad_cname.bv_val, i ));
911 Debug( LDAP_DEBUG_ACL,
912 "acl: access to attribute %s, value %d not allowed\n",
913 desc->ad_cname.bv_val, i, 0 );
920 if (( rc = ber_printf( ber, "O", a->a_vals[i] )) == -1 ) {
922 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
923 "send_search_entry: conn %d ber_printf failed\n",
926 Debug( LDAP_DEBUG_ANY,
927 "ber_printf failed\n", 0, 0, 0 );
931 send_ldap_result( conn, op, LDAP_OTHER,
932 NULL, "encoding values error", NULL, NULL );
939 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
941 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
942 "send_search_entry: conn %d ber_printf failed\n",
945 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
949 send_ldap_result( conn, op, LDAP_OTHER,
950 NULL, "encode end error", NULL, NULL );
958 rc = ber_printf( ber, /*{{{*/ "}N}N}" );
960 #ifdef LDAP_CONNECTIONLESS
961 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2 && rc != -1)
962 rc = ber_printf( ber, "}" );
966 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
967 "send_search_entry: conn %d ber_printf failed\n",
970 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
974 send_ldap_result( conn, op, LDAP_OTHER,
975 NULL, "encode entry end error", NULL, NULL );
979 bytes = send_ldap_ber( conn, ber );
984 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
985 "send_ldap_response: conn %d ber write failed.\n",
988 Debug( LDAP_DEBUG_ANY,
989 "send_ldap_response: ber write failed\n",
996 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
997 num_bytes_sent += bytes;
1000 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1002 Statslog( LDAP_DEBUG_STATS2, "conn=%ld op=%ld ENTRY dn=\"%s\"\n",
1003 (long) conn->c_connid, (long) op->o_opid, e->e_dn, 0, 0 );
1006 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1007 "send_search_entry: conn %d exit.\n",
1010 Debug( LDAP_DEBUG_TRACE, "<= send_search_entry\n", 0, 0, 0 );
1021 send_search_reference(
1026 struct berval **refs,
1027 LDAPControl **ctrls,
1028 struct berval ***v2refs
1035 AttributeDescription *ad_ref = slap_schema.si_ad_ref;
1036 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
1039 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1040 "send_search_reference: conn %d dn=\"%s\"\n",
1041 op->o_connid, e->e_dn ));
1043 Debug( LDAP_DEBUG_TRACE,
1044 "=> send_search_reference: dn=\"%s\"\n",
1049 if ( ! access_allowed( be, conn, op, e,
1050 ad_entry, NULL, ACL_READ ) )
1053 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
1054 "send_search_reference: conn %d access to entry %s not allowed\n",
1055 op->o_connid, e->e_dn ));
1057 Debug( LDAP_DEBUG_ACL,
1058 "send_search_reference: access to entry not allowed\n",
1065 if ( ! access_allowed( be, conn, op, e,
1066 ad_ref, NULL, ACL_READ ) )
1069 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
1070 "send_search_reference: conn %d access to reference not allowed.\n",
1073 Debug( LDAP_DEBUG_ACL,
1074 "send_search_reference: access to reference not allowed\n",
1081 if( refs == NULL ) {
1083 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1084 "send_search_reference: null ref in (%s).\n",
1085 op->o_connid, e->e_dn ));
1087 Debug( LDAP_DEBUG_ANY,
1088 "send_search_reference: null ref in (%s)\n",
1095 if( op->o_protocol < LDAP_VERSION3 ) {
1096 /* save the references for the result */
1097 if( *refs != NULL ) {
1098 value_add( v2refs, refs );
1103 ber = ber_alloc_t( LBER_USE_DER );
1105 if ( ber == NULL ) {
1107 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1108 "send_search_reference: conn %d ber_alloc failed\n",
1111 Debug( LDAP_DEBUG_ANY,
1112 "send_search_reference: ber_alloc failed\n", 0, 0, 0 );
1115 send_ldap_result( conn, op, LDAP_OTHER,
1116 NULL, "alloc BER error", NULL, NULL );
1120 rc = ber_printf( ber, "{it{V}N}", op->o_msgid,
1121 LDAP_RES_SEARCH_REFERENCE, refs );
1125 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1126 "send_search_reference: conn %d ber_printf failed.\n",
1129 Debug( LDAP_DEBUG_ANY,
1130 "send_search_reference: ber_printf failed\n", 0, 0, 0 );
1134 send_ldap_result( conn, op, LDAP_OTHER,
1135 NULL, "encode DN error", NULL, NULL );
1139 bytes = send_ldap_ber( conn, ber );
1142 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1143 num_bytes_sent += bytes;
1146 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1148 Statslog( LDAP_DEBUG_STATS2, "conn=%ld op=%ld REF dn=\"%s\"\n",
1149 (long) conn->c_connid, (long) op->o_opid, e->e_dn, 0, 0 );
1152 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1153 "send_search_reference: conn %d exit.\n", op->o_connid ));
1155 Debug( LDAP_DEBUG_TRACE, "<= send_search_reference\n", 0, 0, 0 );
1173 *code = LDAP_SUCCESS;
1177 if ( strncasecmp( s, "RESULT", 6 ) != 0 ) {
1179 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
1180 "str2result: (%s), expecting \"RESULT\"\n", s ));
1182 Debug( LDAP_DEBUG_ANY, "str2result (%s) expecting \"RESULT\"\n",
1191 while ( (s = strchr( s, '\n' )) != NULL ) {
1196 if ( (c = strchr( s, ':' )) != NULL ) {
1200 if ( strncasecmp( s, "code", 4 ) == 0 ) {
1204 } else if ( strncasecmp( s, "matched", 7 ) == 0 ) {
1208 } else if ( strncasecmp( s, "info", 4 ) == 0 ) {
1214 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
1215 "str2result: (%s) unknown.\n", s ));
1217 Debug( LDAP_DEBUG_ANY, "str2result (%s) unknown\n",