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 */
193 return op->o_response( conn, op, tag, msgid, err, matched,
194 text, ref, resoid, resdata, sasldata, ctrls);
196 ber = ber_alloc_t( LBER_USE_DER );
199 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
200 "send_ldap_response: conn %d msgid=%ld tag=%ld err=%ld\n",
201 conn ? conn->c_connid : 0, (long)msgid, (long)tag, (long)err ));
203 Debug( LDAP_DEBUG_TRACE,
204 "send_ldap_response: msgid=%ld tag=%ld err=%ld\n",
205 (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] && ref[0]->bv_val ? ref[0]->bv_val : "NULL" ));
216 Debug( LDAP_DEBUG_ARGS, "send_ldap_response: ref=\"%s\"\n",
217 ref[0] && ref[0]->bv_val ? ref[0]->bv_val : "NULL",
225 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
226 "send_ldap_response: conn %d ber_alloc failed\n",
227 conn ? conn->c_connid : 0 ));
229 Debug( LDAP_DEBUG_ANY, "ber_alloc failed\n", 0, 0, 0 );
235 #ifdef LDAP_CONNECTIONLESS
236 if (conn->c_is_udp) {
237 rc = ber_write(ber, (char *)&op->o_peeraddr, sizeof(struct sockaddr), 0);
238 if (rc != sizeof(struct sockaddr)) {
240 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
241 "send_ldap_response: conn %d ber_write failed\n",
242 conn ? conn->c_connid : 0 ));
244 Debug( LDAP_DEBUG_ANY, "ber_write failed\n", 0, 0, 0 );
250 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2) {
251 rc = ber_printf( ber, "{is{t{ess",
253 matched == NULL ? "" : matched,
254 text == NULL ? "" : text );
258 rc = ber_printf( ber, "{it{ess",
260 matched == NULL ? "" : matched,
261 text == NULL ? "" : text );
266 assert( err == LDAP_REFERRAL );
267 rc = ber_printf( ber, "t{V}",
268 LDAP_TAG_REFERRAL, ref );
270 assert( err != LDAP_REFERRAL );
274 if( rc != -1 && sasldata != NULL ) {
275 rc = ber_printf( ber, "tO",
276 LDAP_TAG_SASL_RES_CREDS, sasldata );
279 if( rc != -1 && resoid != NULL ) {
280 rc = ber_printf( ber, "ts",
281 LDAP_TAG_EXOP_RES_OID, resoid );
284 if( rc != -1 && resdata != NULL ) {
285 rc = ber_printf( ber, "tO",
286 LDAP_TAG_EXOP_RES_VALUE, resdata );
290 rc = ber_printf( ber, "N}N}" );
292 #ifdef LDAP_CONNECTIONLESS
293 if( conn->c_is_udp && op->o_protocol == LDAP_VERSION2 && rc != -1 ) {
294 rc = ber_printf( ber, "N}" );
300 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
301 "send_ldap_response: conn %d ber_printf failed\n",
302 conn ? conn->c_connid : 0 ));
304 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
312 bytes = send_ldap_ber( conn, ber );
317 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
318 "send_ldap_response: conn %d ber write failed\n",
319 conn ? conn->c_connid : 0 ));
321 Debug( LDAP_DEBUG_ANY,
322 "send_ldap_response: ber write failed\n",
329 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
330 num_bytes_sent += bytes;
332 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
338 send_ldap_disconnect(
349 #define LDAP_UNSOLICITED_ERROR(e) \
350 ( (e) == LDAP_PROTOCOL_ERROR \
351 || (e) == LDAP_STRONG_AUTH_REQUIRED \
352 || (e) == LDAP_UNAVAILABLE )
354 assert( LDAP_UNSOLICITED_ERROR( err ) );
357 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
358 "send_ldap_disconnect: conn %d %d:%s\n",
359 conn ? conn->c_connid : 0, err, text ? text : "" ));
361 Debug( LDAP_DEBUG_TRACE,
362 "send_ldap_disconnect %d:%s\n",
363 err, text ? text : "", NULL );
367 if ( op->o_protocol < LDAP_VERSION3 ) {
369 tag = req2res( op->o_tag );
370 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
373 reqoid = LDAP_NOTICE_DISCONNECT;
374 tag = LDAP_RES_EXTENDED;
378 send_ldap_response( conn, op, tag, msgid,
379 err, NULL, text, NULL,
380 reqoid, NULL, NULL, NULL );
382 Statslog( LDAP_DEBUG_STATS,
383 "conn=%ld op=%ld DISCONNECT tag=%lu err=%ld text=%s\n",
384 (long) op->o_connid, (long) op->o_opid,
385 (unsigned long) tag, (long) err, text ? text : "" );
403 assert( !LDAP_API_ERROR( err ) );
406 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
407 "send_ldap_result : conn %ld op=%ld p=%d\n",
408 (long)op->o_connid, (long)op->o_opid, op->o_protocol ));
410 Debug( LDAP_DEBUG_TRACE,
411 "send_ldap_result: conn=%ld op=%ld p=%d\n",
412 (long) op->o_connid, (long) op->o_opid, op->o_protocol );
416 LDAP_LOG(( "operation", LDAP_LEVEL_ARGS,
417 "send_ldap_result: conn=%ld err=%d matched=\"%s\" text=\"%s\"\n",
418 (long)op->o_connid, err, matched ? matched : "", text ? text : "" ));
420 Debug( LDAP_DEBUG_ARGS,
421 "send_ldap_result: err=%d matched=\"%s\" text=\"%s\"\n",
422 err, matched ? matched : "", text ? text : "" );
428 LDAP_LOG(( "operation", LDAP_LEVEL_ARGS,
429 "send_ldap_result: referral=\"%s\"\n",
430 ref[0] && ref[0]->bv_val ? ref[0]->bv_val : "NULL" ));
432 Debug( LDAP_DEBUG_ARGS,
433 "send_ldap_result: referral=\"%s\"\n",
434 ref[0] && ref[0]->bv_val ? ref[0]->bv_val : "NULL",
439 assert( err != LDAP_PARTIAL_RESULTS );
441 if ( err == LDAP_REFERRAL ) {
443 err = LDAP_NO_SUCH_OBJECT;
444 } else if ( op->o_protocol < LDAP_VERSION3 ) {
445 err = LDAP_PARTIAL_RESULTS;
449 if ( op->o_protocol < LDAP_VERSION3 ) {
450 tmp = v2ref( ref, text );
455 tag = req2res( op->o_tag );
456 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
458 send_ldap_response( conn, op, tag, msgid,
459 err, matched, text, ref,
460 NULL, NULL, NULL, ctrls );
462 Statslog( LDAP_DEBUG_STATS,
463 "conn=%ld op=%ld RESULT tag=%lu err=%ld text=%s\n",
464 (long) op->o_connid, (long) op->o_opid,
465 (unsigned long) tag, (long) err, text ? text : "" );
488 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
489 "send_ldap_sasl: conn %d err=%ld len=%ld\n",
490 op->o_connid, (long)err, cred ? cred->bv_len : -1 ));
492 Debug( LDAP_DEBUG_TRACE, "send_ldap_sasl: err=%ld len=%ld\n",
493 (long) err, cred ? cred->bv_len : -1, NULL );
497 tag = req2res( op->o_tag );
498 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
500 send_ldap_response( conn, op, tag, msgid,
501 err, matched, text, ref,
502 NULL, NULL, cred, ctrls );
512 struct berval **refs,
514 struct berval *rspdata,
522 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
523 "send_ldap_extended: conn %d err=%ld oid=%s len=%ld\n",
524 op->o_connid, (long)err, rspoid ? rspoid : "",
525 rspdata != NULL ? (long)rspdata->bv_len : (long)0 ));
527 Debug( LDAP_DEBUG_TRACE,
528 "send_ldap_extended err=%ld oid=%s len=%ld\n",
530 rspoid ? rspoid : "",
531 rspdata != NULL ? (long) rspdata->bv_len : (long) 0 );
535 tag = req2res( op->o_tag );
536 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
538 send_ldap_response( conn, op, tag, msgid,
539 err, matched, text, refs,
540 rspoid, rspdata, NULL, ctrls );
551 struct berval **refs,
559 assert( !LDAP_API_ERROR( err ) );
562 return op->o_sresult(conn, op, err, matched, text, refs,
566 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
567 "send_search_result: conn %d err=%d matched=\"%s\"\n",
568 op->o_connid, err, matched ? matched : "",
571 Debug( LDAP_DEBUG_TRACE,
572 "send_search_result: err=%d matched=\"%s\" text=\"%s\"\n",
573 err, matched ? matched : "", text ? text : "" );
577 assert( err != LDAP_PARTIAL_RESULTS );
579 if( op->o_protocol < LDAP_VERSION3 ) {
580 /* send references in search results */
581 if( err == LDAP_REFERRAL ) {
582 err = LDAP_PARTIAL_RESULTS;
585 tmp = v2ref( refs, text );
590 /* don't send references in search results */
591 assert( refs == NULL );
594 if( err == LDAP_REFERRAL ) {
599 tag = req2res( op->o_tag );
600 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
602 send_ldap_response( conn, op, tag, msgid,
603 err, matched, text, refs,
604 NULL, NULL, NULL, ctrls );
606 Statslog( LDAP_DEBUG_STATS,
607 "conn=%ld op=%ld SEARCH RESULT tag=%lu err=%ld text=%s\n",
608 (long) op->o_connid, (long) op->o_opid,
609 (unsigned long) tag, (long) err, text ? text : "" );
635 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
638 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
639 "send_search_entry: conn %d dn=\"%s\"%s\n",
640 op->o_connid, e->e_dn,
641 attrsonly ? " (attrsOnly)" : "" ));
643 Debug( LDAP_DEBUG_TRACE,
644 "=> send_search_entry: dn=\"%s\"%s\n",
645 e->e_dn, attrsonly ? " (attrsOnly)" : "", 0 );
649 if ( ! access_allowed( be, conn, op, e,
650 ad_entry, NULL, ACL_READ ) )
653 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
654 "send_search_entry: conn %d access to entry (%s) not allowed\n",
655 op->o_connid, e->e_dn ));
657 Debug( LDAP_DEBUG_ACL,
658 "send_search_entry: access to entry not allowed\n",
667 ber = ber_alloc_t( LBER_USE_DER );
671 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
672 "send_search_entry: conn %d ber_alloc failed\n",
675 Debug( LDAP_DEBUG_ANY, "ber_alloc failed\n", 0, 0, 0 );
678 send_ldap_result( conn, op, LDAP_OTHER,
679 NULL, "BER allocation error", NULL, NULL );
683 #ifdef LDAP_CONNECTIONLESS
684 if (conn->c_is_udp) {
685 rc = ber_write(ber, (char *)&op->o_peeraddr, sizeof(struct sockaddr), 0);
686 if (rc != sizeof(struct sockaddr)) {
688 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
689 "send_search_entry: conn %d ber_printf failed\n",
690 conn ? conn->c_connid : 0 ));
692 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
698 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2) {
699 rc = ber_printf( ber, "{is{t{s{" /*}}}*/,
700 op->o_msgid, "", LDAP_RES_SEARCH_ENTRY, e->e_dn );
704 rc = ber_printf( ber, "{it{s{" /*}}}*/, op->o_msgid,
705 LDAP_RES_SEARCH_ENTRY, e->e_dn );
710 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
711 "send_search_entry: conn %d ber_printf failed\n",
714 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
718 send_ldap_result( conn, op, LDAP_OTHER,
719 NULL, "encoding DN error", NULL, NULL );
723 /* check for special all user attributes ("*") type */
724 userattrs = ( attrs == NULL ) ? 1
725 : charray_inlist( attrs, LDAP_ALL_USER_ATTRIBUTES );
727 /* check for special all operational attributes ("+") type */
728 opattrs = ( attrs == NULL ) ? 0
729 : charray_inlist( attrs, LDAP_ALL_OPERATIONAL_ATTRIBUTES );
731 for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
732 AttributeDescription *desc = a->a_desc;
733 char *type = desc->ad_cname.bv_val;
735 if ( attrs == NULL ) {
736 /* all addrs request, skip operational attributes */
737 if( is_at_operational( desc->ad_type ) ) {
742 /* specific addrs requested */
743 if ( is_at_operational( desc->ad_type ) ) {
744 if( !opattrs && !ad_inlist( desc, attrs ) ) {
749 if (!userattrs && !ad_inlist( desc, attrs ) ) {
755 if ( ! access_allowed( be, conn, op, e, desc, NULL, ACL_READ ) ) {
757 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
758 "send_search_entry: conn %d access to attribute %s not allowed\n",
759 op->o_connid, desc->ad_cname.bv_val ));
761 Debug( LDAP_DEBUG_ACL, "acl: access to attribute %s not allowed\n",
762 desc->ad_cname.bv_val, 0, 0 );
768 if (( rc = ber_printf( ber, "{s[" /*]}*/ , type )) == -1 ) {
770 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
771 "send_search_entry: conn %d ber_printf failed\n",
774 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
778 send_ldap_result( conn, op, LDAP_OTHER,
779 NULL, "encoding description error", NULL, NULL );
784 for ( i = 0; a->a_vals[i] != NULL; i++ ) {
785 if ( ! access_allowed( be, conn, op, e,
786 desc, a->a_vals[i], ACL_READ ) )
789 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
790 "send_search_entry: conn %d access to attribute %s, value %d not allowed\n",
791 op->o_connid, desc->ad_cname.bv_val, i ));
793 Debug( LDAP_DEBUG_ACL,
794 "acl: access to attribute %s, value %d not allowed\n",
795 desc->ad_cname.bv_val, i, 0 );
801 if (( rc = ber_printf( ber, "O", a->a_vals[i] )) == -1 ) {
803 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
804 "send_search_entry: conn %d ber_printf failed.\n",
807 Debug( LDAP_DEBUG_ANY,
808 "ber_printf failed\n", 0, 0, 0 );
812 send_ldap_result( conn, op, LDAP_OTHER,
813 NULL, "encoding values error", NULL, NULL );
819 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
821 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
822 "send_search_entry: conn %d ber_printf failed\n",
825 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
829 send_ldap_result( conn, op, LDAP_OTHER,
830 NULL, "encode end error", NULL, NULL );
835 /* eventually will loop through generated operational attributes */
836 /* only have subschemaSubentry implemented */
837 aa = backend_operational( be, conn, op, e );
839 for (a = aa ; a != NULL; a = a->a_next ) {
840 AttributeDescription *desc = a->a_desc;
842 if ( attrs == NULL ) {
843 /* all addrs request, skip operational attributes */
844 if( is_at_operational( desc->ad_type ) ) {
849 /* specific addrs requested */
850 if( is_at_operational( desc->ad_type ) ) {
851 if( !opattrs && !ad_inlist( desc, attrs ) ) {
855 if (!userattrs && !ad_inlist( desc, attrs ) )
862 if ( ! access_allowed( be, conn, op, e, desc, NULL, ACL_READ ) ) {
864 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
865 "send_search_entry: conn %s access to attribute %s not allowed\n",
866 op->o_connid, desc->ad_cname.bv_val ));
868 Debug( LDAP_DEBUG_ACL, "acl: access to attribute %s not allowed\n",
869 desc->ad_cname.bv_val, 0, 0 );
875 rc = ber_printf( ber, "{s[" /*]}*/ , desc->ad_cname.bv_val );
878 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
879 "send_search_entry: conn %d ber_printf failed\n",
882 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
886 send_ldap_result( conn, op, LDAP_OTHER,
887 NULL, "encoding description error", NULL, NULL );
893 for ( i = 0; a->a_vals[i] != NULL; i++ ) {
894 if ( ! access_allowed( be, conn, op, e,
895 desc, a->a_vals[i], ACL_READ ) )
898 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
899 "send_search_entry: conn %d access to %s, value %d not allowed\n",
900 op->o_connid, desc->ad_cname.bv_val, i ));
902 Debug( LDAP_DEBUG_ACL,
903 "acl: access to attribute %s, value %d not allowed\n",
904 desc->ad_cname.bv_val, i, 0 );
911 if (( rc = ber_printf( ber, "O", a->a_vals[i] )) == -1 ) {
913 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
914 "send_search_entry: conn %d ber_printf failed\n",
917 Debug( LDAP_DEBUG_ANY,
918 "ber_printf failed\n", 0, 0, 0 );
922 send_ldap_result( conn, op, LDAP_OTHER,
923 NULL, "encoding values error", NULL, NULL );
930 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
932 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
933 "send_search_entry: conn %d ber_printf failed\n",
936 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
940 send_ldap_result( conn, op, LDAP_OTHER,
941 NULL, "encode end error", NULL, NULL );
949 rc = ber_printf( ber, /*{{{*/ "}N}N}" );
951 #ifdef LDAP_CONNECTIONLESS
952 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2 && rc != -1)
953 rc = ber_printf( ber, "}" );
957 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
958 "send_search_entry: conn %d ber_printf failed\n",
961 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
965 send_ldap_result( conn, op, LDAP_OTHER,
966 NULL, "encode entry end error", NULL, NULL );
970 bytes = send_ldap_ber( conn, ber );
975 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
976 "send_ldap_response: conn %d ber write failed.\n",
979 Debug( LDAP_DEBUG_ANY,
980 "send_ldap_response: ber write failed\n",
987 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
988 num_bytes_sent += bytes;
991 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
993 Statslog( LDAP_DEBUG_STATS2, "conn=%ld op=%ld ENTRY dn=\"%s\"\n",
994 (long) conn->c_connid, (long) op->o_opid, e->e_dn, 0, 0 );
997 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
998 "send_search_entry: conn %d exit.\n",
1001 Debug( LDAP_DEBUG_TRACE, "<= send_search_entry\n", 0, 0, 0 );
1012 send_search_reference(
1017 struct berval **refs,
1018 LDAPControl **ctrls,
1019 struct berval ***v2refs
1026 AttributeDescription *ad_ref = slap_schema.si_ad_ref;
1027 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
1030 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1031 "send_search_reference: conn %d dn=\"%s\"\n",
1032 op->o_connid, e->e_dn ));
1034 Debug( LDAP_DEBUG_TRACE,
1035 "=> send_search_reference: dn=\"%s\"\n",
1040 if ( ! access_allowed( be, conn, op, e,
1041 ad_entry, NULL, ACL_READ ) )
1044 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
1045 "send_search_reference: conn %d access to entry %s not allowed\n",
1046 op->o_connid, e->e_dn ));
1048 Debug( LDAP_DEBUG_ACL,
1049 "send_search_reference: access to entry not allowed\n",
1056 if ( ! access_allowed( be, conn, op, e,
1057 ad_ref, NULL, ACL_READ ) )
1060 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
1061 "send_search_reference: conn %d access to reference not allowed.\n",
1064 Debug( LDAP_DEBUG_ACL,
1065 "send_search_reference: access to reference not allowed\n",
1072 if( refs == NULL ) {
1074 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1075 "send_search_reference: null ref in (%s).\n",
1076 op->o_connid, e->e_dn ));
1078 Debug( LDAP_DEBUG_ANY,
1079 "send_search_reference: null ref in (%s)\n",
1086 if( op->o_protocol < LDAP_VERSION3 ) {
1087 /* save the references for the result */
1088 if( *refs != NULL ) {
1089 value_add( v2refs, refs );
1094 ber = ber_alloc_t( LBER_USE_DER );
1096 if ( ber == NULL ) {
1098 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1099 "send_search_reference: conn %d ber_alloc failed\n",
1102 Debug( LDAP_DEBUG_ANY,
1103 "send_search_reference: ber_alloc failed\n", 0, 0, 0 );
1106 send_ldap_result( conn, op, LDAP_OTHER,
1107 NULL, "alloc BER error", NULL, NULL );
1111 rc = ber_printf( ber, "{it{V}N}", op->o_msgid,
1112 LDAP_RES_SEARCH_REFERENCE, refs );
1116 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1117 "send_search_reference: conn %d ber_printf failed.\n",
1120 Debug( LDAP_DEBUG_ANY,
1121 "send_search_reference: ber_printf failed\n", 0, 0, 0 );
1125 send_ldap_result( conn, op, LDAP_OTHER,
1126 NULL, "encode DN error", NULL, NULL );
1130 bytes = send_ldap_ber( conn, ber );
1133 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1134 num_bytes_sent += bytes;
1137 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1139 Statslog( LDAP_DEBUG_STATS2, "conn=%ld op=%ld REF dn=\"%s\"\n",
1140 (long) conn->c_connid, (long) op->o_opid, e->e_dn, 0, 0 );
1143 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1144 "send_search_reference: conn %d exit.\n", op->o_connid ));
1146 Debug( LDAP_DEBUG_TRACE, "<= send_search_reference\n", 0, 0, 0 );
1164 *code = LDAP_SUCCESS;
1168 if ( strncasecmp( s, "RESULT", 6 ) != 0 ) {
1170 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
1171 "str2result: (%s), expecting \"RESULT\"\n", s ));
1173 Debug( LDAP_DEBUG_ANY, "str2result (%s) expecting \"RESULT\"\n",
1182 while ( (s = strchr( s, '\n' )) != NULL ) {
1187 if ( (c = strchr( s, ':' )) != NULL ) {
1191 if ( strncasecmp( s, "code", 4 ) == 0 ) {
1195 } else if ( strncasecmp( s, "matched", 7 ) == 0 ) {
1199 } else if ( strncasecmp( s, "info", 4 ) == 0 ) {
1205 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
1206 "str2result: (%s) unknown.\n", s ));
1208 Debug( LDAP_DEBUG_ANY, "str2result (%s) unknown\n",