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 void trim_refs_urls(
99 struct berval **refs )
103 if( refs == NULL ) return;
105 for( i=0; refs[i] != NULL; i++ ) {
106 if( refs[i]->bv_len > sizeof("ldap://")-1 &&
107 strncasecmp( refs[i]->bv_val, "ldap://",
108 sizeof("ldap://")-1 ) == 0 )
111 for( j=sizeof("ldap://")-1; j<refs[i]->bv_len ; j++ ) {
112 if( refs[i]->bv_val[j] == '/' ) {
113 refs[i]->bv_val[j] = '\0';
122 struct berval **get_entry_referrals(
129 struct berval **refs;
132 AttributeDescription *ad_ref = slap_schema.si_ad_ref;
134 attr = attr_find( e->e_attrs, ad_ref );
136 if( attr == NULL ) return NULL;
138 for( i=0; attr->a_vals[i] != NULL; i++ ) {
139 /* count references */
142 if( i < 1 ) return NULL;
144 refs = ch_malloc( (i + 1) * sizeof(struct berval *));
146 for( i=0, j=0; attr->a_vals[i] != NULL; i++ ) {
148 struct berval *ref = ber_bvdup( attr->a_vals[i] );
151 for( k=0; k<ref->bv_len; k++ ) {
152 if( isspace(ref->bv_val[k]) ) {
153 ref->bv_val[k] = '\0';
159 if( ref->bv_len > 0 ) {
170 ber_bvecfree( refs );
174 /* we should check that a referral value exists... */
179 static long send_ldap_ber(
185 ber_get_option( ber, LBER_OPT_BER_BYTES_TO_WRITE, &bytes );
187 /* write only one pdu at a time - wait til it's our turn */
188 ldap_pvt_thread_mutex_lock( &conn->c_write_mutex );
190 /* lock the connection */
191 ldap_pvt_thread_mutex_lock( &conn->c_mutex );
198 if ( connection_state_closing( conn ) ) {
199 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
200 ldap_pvt_thread_mutex_unlock( &conn->c_write_mutex );
205 if ( ber_flush( conn->c_sb, ber, 0 ) == 0 ) {
212 * we got an error. if it's ewouldblock, we need to
213 * wait on the socket being writable. otherwise, figure
214 * it's a hard error and return.
218 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
219 "send_ldap_ber: conn %d ber_flush failed err=%d (%s)\n",
220 conn ? conn->c_connid : 0, err, sock_errstr(err) ));
222 Debug( LDAP_DEBUG_CONNS, "ber_flush failed errno=%d reason=\"%s\"\n",
223 err, sock_errstr(err), 0 );
227 if ( err != EWOULDBLOCK && err != EAGAIN ) {
228 connection_closing( conn );
230 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
231 ldap_pvt_thread_mutex_unlock( &conn->c_write_mutex );
236 /* wait for socket to be write-ready */
237 conn->c_writewaiter = 1;
238 ber_sockbuf_ctrl( conn->c_sb, LBER_SB_OPT_GET_FD, &sd );
239 slapd_set_write( sd, 1 );
241 ldap_pvt_thread_cond_wait( &conn->c_write_cv, &conn->c_mutex );
242 conn->c_writewaiter = 0;
245 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
246 ldap_pvt_thread_mutex_unlock( &conn->c_write_mutex );
262 struct berval *resdata,
263 struct berval *sasldata,
271 assert( ctrls == NULL ); /* ctrls not implemented */
273 ber = ber_alloc_t( LBER_USE_DER );
276 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
277 "send_ldap_response: conn %d msgid=%ld tag=%ld err=%ld\n",
278 conn ? conn->c_connid : 0, (long)msgid, (long)tag, (long)err ));
280 Debug( LDAP_DEBUG_TRACE,
281 "send_ldap_response: msgid=%ld tag=%ld err=%ld\n",
282 (long) msgid, (long) tag, (long) err );
288 LDAP_LOG(( "operation", LDAP_LEVEL_ARGS,
289 "send_ldap_response: conn %d ref=\"%s\"\n",
290 conn ? conn->c_connid : 0,
291 ref[0] && ref[0]->bv_val ? ref[0]->bv_val : "NULL" ));
293 Debug( LDAP_DEBUG_ARGS, "send_ldap_response: ref=\"%s\"\n",
294 ref[0] && ref[0]->bv_val ? ref[0]->bv_val : "NULL",
302 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
303 "send_ldap_response: conn %d ber_alloc failed\n",
304 conn ? conn->c_connid : 0 ));
306 Debug( LDAP_DEBUG_ANY, "ber_alloc failed\n", 0, 0, 0 );
312 rc = ber_printf( ber, "{it{ess",
314 matched == NULL ? "" : matched,
315 text == NULL ? "" : text );
319 assert( err == LDAP_REFERRAL );
320 rc = ber_printf( ber, "t{V}",
321 LDAP_TAG_REFERRAL, ref );
323 assert( err != LDAP_REFERRAL );
327 if( rc != -1 && sasldata != NULL ) {
328 rc = ber_printf( ber, "tO",
329 LDAP_TAG_SASL_RES_CREDS, sasldata );
332 if( rc != -1 && resoid != NULL ) {
333 rc = ber_printf( ber, "ts",
334 LDAP_TAG_EXOP_RES_OID, resoid );
337 if( rc != -1 && resdata != NULL ) {
338 rc = ber_printf( ber, "tO",
339 LDAP_TAG_EXOP_RES_VALUE, resdata );
343 rc = ber_printf( ber, "N}N}" );
348 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
349 "send_ldap_response: conn %d ber_printf failed\n",
350 conn ? conn->c_connid : 0 ));
352 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
360 bytes = send_ldap_ber( conn, ber );
365 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
366 "send_ldap_response: conn %d ber write failed\n",
367 conn ? conn->c_connid : 0 ));
369 Debug( LDAP_DEBUG_ANY,
370 "send_ldap_response: ber write failed\n",
377 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
378 num_bytes_sent += bytes;
380 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
386 send_ldap_disconnect(
397 #define LDAP_UNSOLICITED_ERROR(e) \
398 ( (e) == LDAP_PROTOCOL_ERROR \
399 || (e) == LDAP_STRONG_AUTH_REQUIRED \
400 || (e) == LDAP_UNAVAILABLE )
402 assert( LDAP_UNSOLICITED_ERROR( err ) );
405 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
406 "send_ldap_disconnect: conn %d %d:%s\n",
407 conn ? conn->c_connid : 0, err, text ? text : "" ));
409 Debug( LDAP_DEBUG_TRACE,
410 "send_ldap_disconnect %d:%s\n",
411 err, text ? text : "", NULL );
415 if ( op->o_protocol < LDAP_VERSION3 ) {
417 tag = req2res( op->o_tag );
418 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
421 reqoid = LDAP_NOTICE_DISCONNECT;
422 tag = LDAP_RES_EXTENDED;
426 send_ldap_response( conn, op, tag, msgid,
427 err, NULL, text, NULL,
428 reqoid, NULL, NULL, NULL );
430 Statslog( LDAP_DEBUG_STATS,
431 "conn=%ld op=%ld DISCONNECT err=%ld tag=%lu text=%s\n",
432 (long) op->o_connid, (long) op->o_opid,
433 (long) tag, (long) err, text ? text : "" );
451 assert( !LDAP_API_ERROR( err ) );
454 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
455 "send_ldap_result : conn %ld op=%ld p=%d\n",
456 (long)op->o_connid, (long)op->o_opid, op->o_protocol ));
458 Debug( LDAP_DEBUG_TRACE,
459 "send_ldap_result: conn=%ld op=%ld p=%d\n",
460 (long) op->o_connid, (long) op->o_opid, op->o_protocol );
464 LDAP_LOG(( "operation", LDAP_LEVEL_ARGS,
465 "send_ldap_result: conn=%ld err=%d matched=\"%s\" text=\"%s\"\n",
466 (long)op->o_connid, err, matched ? matched : "", text ? text : "" ));
468 Debug( LDAP_DEBUG_ARGS,
469 "send_ldap_result: err=%d matched=\"%s\" text=\"%s\"\n",
470 err, matched ? matched : "", text ? text : "" );
476 LDAP_LOG(( "operation", LDAP_LEVEL_ARGS,
477 "send_ldap_result: referral=\"%s\"\n",
478 ref[0] && ref[0]->bv_val ? ref[0]->bv_val : "NULL" ));
480 Debug( LDAP_DEBUG_ARGS,
481 "send_ldap_result: referral=\"%s\"\n",
482 ref[0] && ref[0]->bv_val ? ref[0]->bv_val : "NULL",
488 assert( err != LDAP_PARTIAL_RESULTS );
490 if( op->o_tag != LDAP_REQ_SEARCH ) {
491 trim_refs_urls( ref );
494 if ( err == LDAP_REFERRAL ) {
496 err = LDAP_NO_SUCH_OBJECT;
497 } else if ( op->o_protocol < LDAP_VERSION3 ) {
498 err = LDAP_PARTIAL_RESULTS;
502 if ( op->o_protocol < LDAP_VERSION3 ) {
503 tmp = v2ref( ref, text );
508 tag = req2res( op->o_tag );
509 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
511 send_ldap_response( conn, op, tag, msgid,
512 err, matched, text, ref,
513 NULL, NULL, NULL, ctrls );
515 Statslog( LDAP_DEBUG_STATS,
516 "conn=%ld op=%ld RESULT tag=%lu err=%ld text=%s\n",
517 (long) op->o_connid, (long) op->o_opid,
518 (long) tag, (long) err, text ? text : "" );
541 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
542 "send_ldap_sasl: conn %d err=%ld len=%ld\n",
543 op->o_connid, (long)err, cred ? cred->bv_len : -1 ));
545 Debug( LDAP_DEBUG_TRACE, "send_ldap_sasl: err=%ld len=%ld\n",
546 (long) err, cred ? cred->bv_len : -1, NULL );
550 tag = req2res( op->o_tag );
551 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
553 send_ldap_response( conn, op, tag, msgid,
554 err, matched, text, ref,
555 NULL, NULL, cred, ctrls );
565 struct berval **refs,
567 struct berval *rspdata,
575 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
576 "send_ldap_extended: conn %d err=%ld oid=%s len=%ld\n",
577 op->o_connid, (long)err, rspoid ? rspoid : "",
578 rspdata != NULL ? (long)rspdata->bv_len : (long)0 ));
580 Debug( LDAP_DEBUG_TRACE,
581 "send_ldap_extended err=%ld oid=%s len=%ld\n",
583 rspoid ? rspoid : "",
584 rspdata != NULL ? (long) rspdata->bv_len : (long) 0 );
588 tag = req2res( op->o_tag );
589 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
591 send_ldap_response( conn, op, tag, msgid,
592 err, matched, text, refs,
593 rspoid, rspdata, NULL, ctrls );
604 struct berval **refs,
612 assert( !LDAP_API_ERROR( err ) );
615 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
616 "send_search_result: conn %d err=%d matched=\"%s\"\n",
617 op->o_connid, err, matched ? matched : "",
620 Debug( LDAP_DEBUG_TRACE,
621 "send_search_result: err=%d matched=\"%s\" text=\"%s\"\n",
622 err, matched ? matched : "", text ? text : "" );
626 assert( err != LDAP_PARTIAL_RESULTS );
628 trim_refs_urls( refs );
630 if( op->o_protocol < LDAP_VERSION3 ) {
631 /* send references in search results */
632 if( err == LDAP_REFERRAL ) {
633 err = LDAP_PARTIAL_RESULTS;
636 tmp = v2ref( refs, text );
641 /* don't send references in search results */
642 assert( refs == NULL );
645 if( err == LDAP_REFERRAL ) {
650 tag = req2res( op->o_tag );
651 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
653 send_ldap_response( conn, op, tag, msgid,
654 err, matched, text, refs,
655 NULL, NULL, NULL, ctrls );
657 Statslog( LDAP_DEBUG_STATS,
658 "conn=%ld op=%ld SEARCH RESULT tag=%lu err=%ld text=%s\n",
659 (long) op->o_connid, (long) op->o_opid,
660 (long) tag, (long) err, text ? text : "" );
686 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
689 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
690 "send_search_entry: conn %d dn=\"%s\"%s\n",
691 op->o_connid, e->e_dn,
692 attrsonly ? " (attrsOnly)" : "" ));
694 Debug( LDAP_DEBUG_TRACE,
695 "=> send_search_entry: dn=\"%s\"%s\n",
696 e->e_dn, attrsonly ? " (attrsOnly)" : "", 0 );
700 if ( ! access_allowed( be, conn, op, e,
701 ad_entry, NULL, ACL_READ ) )
704 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
705 "send_search_entry: conn %d access to entry (%s) not allowed\n",
706 op->o_connid, e->e_dn ));
708 Debug( LDAP_DEBUG_ACL,
709 "send_search_entry: access to entry not allowed\n",
718 ber = ber_alloc_t( LBER_USE_DER );
722 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
723 "send_search_entry: conn %d ber_alloc failed\n",
726 Debug( LDAP_DEBUG_ANY, "ber_alloc failed\n", 0, 0, 0 );
729 send_ldap_result( conn, op, LDAP_OTHER,
730 NULL, "BER allocation error", NULL, NULL );
734 rc = ber_printf( ber, "{it{s{" /*}}}*/, op->o_msgid,
735 LDAP_RES_SEARCH_ENTRY, e->e_dn );
739 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
740 "send_search_entry: conn %d ber_printf failed\n",
743 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
747 send_ldap_result( conn, op, LDAP_OTHER,
748 NULL, "encoding DN error", NULL, NULL );
752 /* check for special all user attributes ("*") type */
753 userattrs = ( attrs == NULL ) ? 1
754 : charray_inlist( attrs, LDAP_ALL_USER_ATTRIBUTES );
756 /* check for special all operational attributes ("+") type */
757 opattrs = ( attrs == NULL ) ? 0
758 : charray_inlist( attrs, LDAP_ALL_OPERATIONAL_ATTRIBUTES );
760 for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
761 AttributeDescription *desc = a->a_desc;
762 char *type = desc->ad_cname->bv_val;
764 if ( attrs == NULL ) {
765 /* all addrs request, skip operational attributes */
766 if( is_at_operational( desc->ad_type ) ) {
771 /* specific addrs requested */
772 if ( is_at_operational( desc->ad_type ) ) {
773 if( !opattrs && !ad_inlist( desc, attrs ) ) {
778 if (!userattrs && !ad_inlist( desc, attrs ) ) {
784 if ( ! access_allowed( be, conn, op, e, desc, NULL, ACL_READ ) ) {
786 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
787 "send_search_entry: conn %d access to attribute %s not allowed\n",
788 op->o_connid, desc->ad_cname->bv_val ));
790 Debug( LDAP_DEBUG_ACL, "acl: access to attribute %s not allowed\n",
791 desc->ad_cname->bv_val, 0, 0 );
797 if (( rc = ber_printf( ber, "{s[" /*]}*/ , type )) == -1 ) {
799 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
800 "send_search_entry: conn %d ber_printf failed\n",
803 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
807 send_ldap_result( conn, op, LDAP_OTHER,
808 NULL, "encoding description error", NULL, NULL );
813 for ( i = 0; a->a_vals[i] != NULL; i++ ) {
814 if ( ! access_allowed( be, conn, op, e,
815 desc, a->a_vals[i], ACL_READ ) )
818 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
819 "send_search_entry: conn %d access to attribute %s, value %d not allowed\n",
820 op->o_connid, desc->ad_cname->bv_val, i ));
822 Debug( LDAP_DEBUG_ACL,
823 "acl: access to attribute %s, value %d not allowed\n",
824 desc->ad_cname->bv_val, i, 0 );
830 if (( rc = ber_printf( ber, "O", a->a_vals[i] )) == -1 ) {
832 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
833 "send_search_entry: conn %d ber_printf failed.\n",
836 Debug( LDAP_DEBUG_ANY,
837 "ber_printf failed\n", 0, 0, 0 );
841 send_ldap_result( conn, op, LDAP_OTHER,
842 NULL, "encoding values error", NULL, NULL );
848 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
850 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
851 "send_search_entry: conn %d ber_printf failed\n",
854 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
858 send_ldap_result( conn, op, LDAP_OTHER,
859 NULL, "encode end error", NULL, NULL );
864 /* eventually will loop through generated operational attributes */
865 /* only have subschemaSubentry implemented */
866 aa = backend_operational( be, conn, op, e );
868 for (a = aa ; a != NULL; a = a->a_next ) {
869 AttributeDescription *desc = a->a_desc;
871 if ( attrs == NULL ) {
872 /* all addrs request, skip operational attributes */
873 if( is_at_operational( desc->ad_type ) ) {
878 /* specific addrs requested */
879 if( is_at_operational( desc->ad_type ) ) {
880 if( !opattrs && !ad_inlist( desc, attrs ) ) {
884 if (!userattrs && !ad_inlist( desc, attrs ) )
891 if ( ! access_allowed( be, conn, op, e, desc, NULL, ACL_READ ) ) {
893 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
894 "send_search_entry: conn %s access to attribute %s not allowed\n",
895 op->o_connid, desc->ad_cname->bv_val ));
897 Debug( LDAP_DEBUG_ACL, "acl: access to attribute %s not allowed\n",
898 desc->ad_cname->bv_val, 0, 0 );
904 rc = ber_printf( ber, "{s[" /*]}*/ , desc->ad_cname->bv_val );
907 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
908 "send_search_entry: conn %d ber_printf failed\n",
911 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
915 send_ldap_result( conn, op, LDAP_OTHER,
916 NULL, "encoding description error", NULL, NULL );
921 for ( i = 0; a->a_vals[i] != NULL; i++ ) {
922 if ( ! access_allowed( be, conn, op, e,
923 desc, a->a_vals[i], ACL_READ ) )
926 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
927 "send_search_entry: conn %d access to %s, value %d not allowed\n",
928 op->o_connid, desc->ad_cname->bv_val, i ));
930 Debug( LDAP_DEBUG_ACL,
931 "acl: access to attribute %s, value %d not allowed\n",
932 desc->ad_cname->bv_val, i, 0 );
939 if (( rc = ber_printf( ber, "O", a->a_vals[i] )) == -1 ) {
941 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
942 "send_search_entry: conn %d ber_printf failed\n",
945 Debug( LDAP_DEBUG_ANY,
946 "ber_printf failed\n", 0, 0, 0 );
950 send_ldap_result( conn, op, LDAP_OTHER,
951 NULL, "encoding values error", NULL, NULL );
957 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
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 end error", NULL, NULL );
975 rc = ber_printf( ber, /*{{{*/ "}N}N}" );
979 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
980 "send_search_entry: conn %d ber_printf failed\n",
983 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
987 send_ldap_result( conn, op, LDAP_OTHER,
988 NULL, "encode entry end error", NULL, NULL );
992 bytes = send_ldap_ber( conn, ber );
997 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
998 "send_ldap_response: conn %d ber write failed.\n",
1001 Debug( LDAP_DEBUG_ANY,
1002 "send_ldap_response: ber write failed\n",
1009 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1010 num_bytes_sent += bytes;
1013 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1015 Statslog( LDAP_DEBUG_STATS2, "conn=%ld op=%ld ENTRY dn=\"%s\"\n",
1016 (long) conn->c_connid, (long) op->o_opid, e->e_dn, 0, 0 );
1019 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1020 "send_search_entry: conn %d exit.\n",
1023 Debug( LDAP_DEBUG_TRACE, "<= send_search_entry\n", 0, 0, 0 );
1034 send_search_reference(
1039 struct berval **refs,
1041 LDAPControl **ctrls,
1042 struct berval ***v2refs
1049 AttributeDescription *ad_ref = slap_schema.si_ad_ref;
1050 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
1053 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1054 "send_search_reference: conn %d dn=\"%s\"\n",
1055 op->o_connid, e->e_dn ));
1057 Debug( LDAP_DEBUG_TRACE,
1058 "=> send_search_reference: dn=\"%s\"\n",
1063 if ( ! access_allowed( be, conn, op, e,
1064 ad_entry, NULL, ACL_READ ) )
1067 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
1068 "send_search_reference: conn %d access to entry %s not allowed\n",
1069 op->o_connid, e->e_dn ));
1071 Debug( LDAP_DEBUG_ACL,
1072 "send_search_reference: access to entry not allowed\n",
1079 if ( ! access_allowed( be, conn, op, e,
1080 ad_ref, NULL, ACL_READ ) )
1083 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
1084 "send_search_reference: conn %d access to reference not allowed.\n",
1087 Debug( LDAP_DEBUG_ACL,
1088 "send_search_reference: access to reference not allowed\n",
1095 if( refs == NULL ) {
1097 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1098 "send_search_reference: null ref in (%s).\n",
1099 op->o_connid, e->e_dn ));
1101 Debug( LDAP_DEBUG_ANY,
1102 "send_search_reference: null ref in (%s)\n",
1109 if( op->o_protocol < LDAP_VERSION3 ) {
1110 /* save the references for the result */
1111 if( *refs != NULL ) {
1112 value_add( v2refs, refs );
1117 ber = ber_alloc_t( LBER_USE_DER );
1119 if ( ber == NULL ) {
1121 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1122 "send_search_reference: conn %d ber_alloc failed\n",
1125 Debug( LDAP_DEBUG_ANY,
1126 "send_search_reference: ber_alloc failed\n", 0, 0, 0 );
1129 send_ldap_result( conn, op, LDAP_OTHER,
1130 NULL, "alloc BER error", NULL, NULL );
1134 rc = ber_printf( ber, "{it{V}N}", op->o_msgid,
1135 LDAP_RES_SEARCH_REFERENCE, refs );
1139 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1140 "send_search_reference: conn %d ber_printf failed.\n",
1143 Debug( LDAP_DEBUG_ANY,
1144 "send_search_reference: ber_printf failed\n", 0, 0, 0 );
1148 send_ldap_result( conn, op, LDAP_OTHER,
1149 NULL, "encode DN error", NULL, NULL );
1153 bytes = send_ldap_ber( conn, ber );
1156 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1157 num_bytes_sent += bytes;
1160 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1162 Statslog( LDAP_DEBUG_STATS2, "conn=%ld op=%ld ENTRY dn=\"%s\"\n",
1163 (long) conn->c_connid, (long) op->o_opid, e->e_dn, 0, 0 );
1166 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1167 "send_search_reference: conn %d exit.\n", op->o_connid ));
1169 Debug( LDAP_DEBUG_TRACE, "<= send_search_reference\n", 0, 0, 0 );
1188 *code = LDAP_SUCCESS;
1192 if ( strncasecmp( s, "RESULT", 6 ) != 0 ) {
1194 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
1195 "str2result: (%s), expecting \"RESULT\"\n", s ));
1197 Debug( LDAP_DEBUG_ANY, "str2result (%s) expecting \"RESULT\"\n",
1206 while ( (s = strchr( s, '\n' )) != NULL ) {
1211 if ( (c = strchr( s, ':' )) != NULL ) {
1215 if ( strncasecmp( s, "code", 4 ) == 0 ) {
1219 } else if ( strncasecmp( s, "matched", 7 ) == 0 ) {
1223 } else if ( strncasecmp( s, "info", 4 ) == 0 ) {
1229 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
1230 "str2result: (%s) unknown.\n", s ));
1232 Debug( LDAP_DEBUG_ANY, "str2result (%s) unknown\n",