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 #ifdef LDAP_CONNECTIONLESS
313 if (conn->c_is_udp) {
314 rc = ber_write(ber, (char *)&op->o_peeraddr, sizeof(struct sockaddr), 0);
315 if (rc != sizeof(struct sockaddr)) {
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, "ber_write failed\n", 0, 0, 0 );
327 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2) {
328 rc = ber_printf( ber, "{is{t{ess",
330 matched == NULL ? "" : matched,
331 text == NULL ? "" : text );
335 rc = ber_printf( ber, "{it{ess",
337 matched == NULL ? "" : matched,
338 text == NULL ? "" : text );
343 assert( err == LDAP_REFERRAL );
344 rc = ber_printf( ber, "t{V}",
345 LDAP_TAG_REFERRAL, ref );
347 assert( err != LDAP_REFERRAL );
351 if( rc != -1 && sasldata != NULL ) {
352 rc = ber_printf( ber, "tO",
353 LDAP_TAG_SASL_RES_CREDS, sasldata );
356 if( rc != -1 && resoid != NULL ) {
357 rc = ber_printf( ber, "ts",
358 LDAP_TAG_EXOP_RES_OID, resoid );
361 if( rc != -1 && resdata != NULL ) {
362 rc = ber_printf( ber, "tO",
363 LDAP_TAG_EXOP_RES_VALUE, resdata );
367 rc = ber_printf( ber, "N}N}" );
369 #ifdef LDAP_CONNECTIONLESS
370 if( conn->c_is_udp && op->o_protocol == LDAP_VERSION2 && rc != -1 ) {
371 rc = ber_printf( ber, "N}" );
377 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
378 "send_ldap_response: conn %d ber_printf failed\n",
379 conn ? conn->c_connid : 0 ));
381 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
389 bytes = send_ldap_ber( conn, ber );
394 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
395 "send_ldap_response: conn %d ber write failed\n",
396 conn ? conn->c_connid : 0 ));
398 Debug( LDAP_DEBUG_ANY,
399 "send_ldap_response: ber write failed\n",
406 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
407 num_bytes_sent += bytes;
409 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
415 send_ldap_disconnect(
426 #define LDAP_UNSOLICITED_ERROR(e) \
427 ( (e) == LDAP_PROTOCOL_ERROR \
428 || (e) == LDAP_STRONG_AUTH_REQUIRED \
429 || (e) == LDAP_UNAVAILABLE )
431 assert( LDAP_UNSOLICITED_ERROR( err ) );
434 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
435 "send_ldap_disconnect: conn %d %d:%s\n",
436 conn ? conn->c_connid : 0, err, text ? text : "" ));
438 Debug( LDAP_DEBUG_TRACE,
439 "send_ldap_disconnect %d:%s\n",
440 err, text ? text : "", NULL );
444 if ( op->o_protocol < LDAP_VERSION3 ) {
446 tag = req2res( op->o_tag );
447 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
450 reqoid = LDAP_NOTICE_DISCONNECT;
451 tag = LDAP_RES_EXTENDED;
455 send_ldap_response( conn, op, tag, msgid,
456 err, NULL, text, NULL,
457 reqoid, NULL, NULL, NULL );
459 Statslog( LDAP_DEBUG_STATS,
460 "conn=%ld op=%ld DISCONNECT tag=%lu err=%ld text=%s\n",
461 (long) op->o_connid, (long) op->o_opid,
462 (unsigned long) tag, (long) err, text ? text : "" );
480 assert( !LDAP_API_ERROR( err ) );
483 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
484 "send_ldap_result : conn %ld op=%ld p=%d\n",
485 (long)op->o_connid, (long)op->o_opid, op->o_protocol ));
487 Debug( LDAP_DEBUG_TRACE,
488 "send_ldap_result: conn=%ld op=%ld p=%d\n",
489 (long) op->o_connid, (long) op->o_opid, op->o_protocol );
493 LDAP_LOG(( "operation", LDAP_LEVEL_ARGS,
494 "send_ldap_result: conn=%ld err=%d matched=\"%s\" text=\"%s\"\n",
495 (long)op->o_connid, err, matched ? matched : "", text ? text : "" ));
497 Debug( LDAP_DEBUG_ARGS,
498 "send_ldap_result: err=%d matched=\"%s\" text=\"%s\"\n",
499 err, matched ? matched : "", text ? text : "" );
505 LDAP_LOG(( "operation", LDAP_LEVEL_ARGS,
506 "send_ldap_result: referral=\"%s\"\n",
507 ref[0] && ref[0]->bv_val ? ref[0]->bv_val : "NULL" ));
509 Debug( LDAP_DEBUG_ARGS,
510 "send_ldap_result: referral=\"%s\"\n",
511 ref[0] && ref[0]->bv_val ? ref[0]->bv_val : "NULL",
517 assert( err != LDAP_PARTIAL_RESULTS );
519 if( op->o_tag != LDAP_REQ_SEARCH ) {
520 trim_refs_urls( ref );
523 if ( err == LDAP_REFERRAL ) {
525 err = LDAP_NO_SUCH_OBJECT;
526 } else if ( op->o_protocol < LDAP_VERSION3 ) {
527 err = LDAP_PARTIAL_RESULTS;
531 if ( op->o_protocol < LDAP_VERSION3 ) {
532 tmp = v2ref( ref, text );
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, ref,
542 NULL, NULL, NULL, ctrls );
544 Statslog( LDAP_DEBUG_STATS,
545 "conn=%ld op=%ld RESULT tag=%lu err=%ld text=%s\n",
546 (long) op->o_connid, (long) op->o_opid,
547 (unsigned long) tag, (long) err, text ? text : "" );
570 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
571 "send_ldap_sasl: conn %d err=%ld len=%ld\n",
572 op->o_connid, (long)err, cred ? cred->bv_len : -1 ));
574 Debug( LDAP_DEBUG_TRACE, "send_ldap_sasl: err=%ld len=%ld\n",
575 (long) err, cred ? cred->bv_len : -1, NULL );
579 tag = req2res( op->o_tag );
580 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
582 send_ldap_response( conn, op, tag, msgid,
583 err, matched, text, ref,
584 NULL, NULL, cred, ctrls );
594 struct berval **refs,
596 struct berval *rspdata,
604 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
605 "send_ldap_extended: conn %d err=%ld oid=%s len=%ld\n",
606 op->o_connid, (long)err, rspoid ? rspoid : "",
607 rspdata != NULL ? (long)rspdata->bv_len : (long)0 ));
609 Debug( LDAP_DEBUG_TRACE,
610 "send_ldap_extended err=%ld oid=%s len=%ld\n",
612 rspoid ? rspoid : "",
613 rspdata != NULL ? (long) rspdata->bv_len : (long) 0 );
617 tag = req2res( op->o_tag );
618 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
620 send_ldap_response( conn, op, tag, msgid,
621 err, matched, text, refs,
622 rspoid, rspdata, NULL, ctrls );
633 struct berval **refs,
641 assert( !LDAP_API_ERROR( err ) );
644 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
645 "send_search_result: conn %d err=%d matched=\"%s\"\n",
646 op->o_connid, err, matched ? matched : "",
649 Debug( LDAP_DEBUG_TRACE,
650 "send_search_result: err=%d matched=\"%s\" text=\"%s\"\n",
651 err, matched ? matched : "", text ? text : "" );
655 assert( err != LDAP_PARTIAL_RESULTS );
657 trim_refs_urls( refs );
659 if( op->o_protocol < LDAP_VERSION3 ) {
660 /* send references in search results */
661 if( err == LDAP_REFERRAL ) {
662 err = LDAP_PARTIAL_RESULTS;
665 tmp = v2ref( refs, text );
670 /* don't send references in search results */
671 assert( refs == NULL );
674 if( err == LDAP_REFERRAL ) {
679 tag = req2res( op->o_tag );
680 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
682 send_ldap_response( conn, op, tag, msgid,
683 err, matched, text, refs,
684 NULL, NULL, NULL, ctrls );
686 Statslog( LDAP_DEBUG_STATS,
687 "conn=%ld op=%ld SEARCH RESULT tag=%lu err=%ld text=%s\n",
688 (long) op->o_connid, (long) op->o_opid,
689 (unsigned long) tag, (long) err, text ? text : "" );
715 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
718 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
719 "send_search_entry: conn %d dn=\"%s\"%s\n",
720 op->o_connid, e->e_dn,
721 attrsonly ? " (attrsOnly)" : "" ));
723 Debug( LDAP_DEBUG_TRACE,
724 "=> send_search_entry: dn=\"%s\"%s\n",
725 e->e_dn, attrsonly ? " (attrsOnly)" : "", 0 );
729 if ( ! access_allowed( be, conn, op, e,
730 ad_entry, NULL, ACL_READ ) )
733 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
734 "send_search_entry: conn %d access to entry (%s) not allowed\n",
735 op->o_connid, e->e_dn ));
737 Debug( LDAP_DEBUG_ACL,
738 "send_search_entry: access to entry not allowed\n",
747 ber = ber_alloc_t( LBER_USE_DER );
751 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
752 "send_search_entry: conn %d ber_alloc failed\n",
755 Debug( LDAP_DEBUG_ANY, "ber_alloc failed\n", 0, 0, 0 );
758 send_ldap_result( conn, op, LDAP_OTHER,
759 NULL, "BER allocation error", NULL, NULL );
763 #ifdef LDAP_CONNECTIONLESS
764 if (conn->c_is_udp) {
765 rc = ber_write(ber, (char *)&op->o_peeraddr, sizeof(struct sockaddr), 0);
766 if (rc != sizeof(struct sockaddr)) {
768 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
769 "send_search_entry: conn %d ber_printf failed\n",
770 conn ? conn->c_connid : 0 ));
772 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
778 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2) {
779 rc = ber_printf( ber, "{is{t{s{",
780 op->o_msgid, "", LDAP_RES_SEARCH_ENTRY, e->e_dn );
784 rc = ber_printf( ber, "{it{s{" /*}}}*/, op->o_msgid,
785 LDAP_RES_SEARCH_ENTRY, e->e_dn );
790 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
791 "send_search_entry: conn %d ber_printf failed\n",
794 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
798 send_ldap_result( conn, op, LDAP_OTHER,
799 NULL, "encoding DN error", NULL, NULL );
803 /* check for special all user attributes ("*") type */
804 userattrs = ( attrs == NULL ) ? 1
805 : charray_inlist( attrs, LDAP_ALL_USER_ATTRIBUTES );
807 /* check for special all operational attributes ("+") type */
808 opattrs = ( attrs == NULL ) ? 0
809 : charray_inlist( attrs, LDAP_ALL_OPERATIONAL_ATTRIBUTES );
811 for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
812 AttributeDescription *desc = a->a_desc;
813 char *type = desc->ad_cname->bv_val;
815 if ( attrs == NULL ) {
816 /* all addrs request, skip operational attributes */
817 if( is_at_operational( desc->ad_type ) ) {
822 /* specific addrs requested */
823 if ( is_at_operational( desc->ad_type ) ) {
824 if( !opattrs && !ad_inlist( desc, attrs ) ) {
829 if (!userattrs && !ad_inlist( desc, attrs ) ) {
835 if ( ! access_allowed( be, conn, op, e, desc, NULL, ACL_READ ) ) {
837 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
838 "send_search_entry: conn %d access to attribute %s not allowed\n",
839 op->o_connid, desc->ad_cname->bv_val ));
841 Debug( LDAP_DEBUG_ACL, "acl: access to attribute %s not allowed\n",
842 desc->ad_cname->bv_val, 0, 0 );
848 if (( rc = ber_printf( ber, "{s[" /*]}*/ , type )) == -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, "encoding description error", NULL, NULL );
864 for ( i = 0; a->a_vals[i] != NULL; i++ ) {
865 if ( ! access_allowed( be, conn, op, e,
866 desc, a->a_vals[i], ACL_READ ) )
869 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
870 "send_search_entry: conn %d access to attribute %s, value %d not allowed\n",
871 op->o_connid, desc->ad_cname->bv_val, i ));
873 Debug( LDAP_DEBUG_ACL,
874 "acl: access to attribute %s, value %d not allowed\n",
875 desc->ad_cname->bv_val, i, 0 );
881 if (( rc = ber_printf( ber, "O", a->a_vals[i] )) == -1 ) {
883 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
884 "send_search_entry: conn %d ber_printf failed.\n",
887 Debug( LDAP_DEBUG_ANY,
888 "ber_printf failed\n", 0, 0, 0 );
892 send_ldap_result( conn, op, LDAP_OTHER,
893 NULL, "encoding values error", NULL, NULL );
899 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
901 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
902 "send_search_entry: conn %d ber_printf failed\n",
905 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
909 send_ldap_result( conn, op, LDAP_OTHER,
910 NULL, "encode end error", NULL, NULL );
915 /* eventually will loop through generated operational attributes */
916 /* only have subschemaSubentry implemented */
917 aa = backend_operational( be, conn, op, e );
919 for (a = aa ; a != NULL; a = a->a_next ) {
920 AttributeDescription *desc = a->a_desc;
922 if ( attrs == NULL ) {
923 /* all addrs request, skip operational attributes */
924 if( is_at_operational( desc->ad_type ) ) {
929 /* specific addrs requested */
930 if( is_at_operational( desc->ad_type ) ) {
931 if( !opattrs && !ad_inlist( desc, attrs ) ) {
935 if (!userattrs && !ad_inlist( desc, attrs ) )
942 if ( ! access_allowed( be, conn, op, e, desc, NULL, ACL_READ ) ) {
944 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
945 "send_search_entry: conn %s access to attribute %s not allowed\n",
946 op->o_connid, desc->ad_cname->bv_val ));
948 Debug( LDAP_DEBUG_ACL, "acl: access to attribute %s not allowed\n",
949 desc->ad_cname->bv_val, 0, 0 );
955 rc = ber_printf( ber, "{s[" /*]}*/ , desc->ad_cname->bv_val );
958 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
959 "send_search_entry: conn %d ber_printf failed\n",
962 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
966 send_ldap_result( conn, op, LDAP_OTHER,
967 NULL, "encoding description error", NULL, NULL );
972 for ( i = 0; a->a_vals[i] != NULL; i++ ) {
973 if ( ! access_allowed( be, conn, op, e,
974 desc, a->a_vals[i], ACL_READ ) )
977 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
978 "send_search_entry: conn %d access to %s, value %d not allowed\n",
979 op->o_connid, desc->ad_cname->bv_val, i ));
981 Debug( LDAP_DEBUG_ACL,
982 "acl: access to attribute %s, value %d not allowed\n",
983 desc->ad_cname->bv_val, i, 0 );
990 if (( rc = ber_printf( ber, "O", a->a_vals[i] )) == -1 ) {
992 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
993 "send_search_entry: conn %d ber_printf failed\n",
996 Debug( LDAP_DEBUG_ANY,
997 "ber_printf failed\n", 0, 0, 0 );
1001 send_ldap_result( conn, op, LDAP_OTHER,
1002 NULL, "encoding values error", NULL, NULL );
1008 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
1010 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1011 "send_search_entry: conn %d ber_printf failed\n",
1014 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1018 send_ldap_result( conn, op, LDAP_OTHER,
1019 NULL, "encode end error", NULL, NULL );
1026 rc = ber_printf( ber, /*{{{*/ "}N}N}" );
1028 #ifdef LDAP_CONNECTIONLESS
1029 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2 && rc != -1)
1030 rc = ber_printf( ber, "}" );
1034 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1035 "send_search_entry: conn %d ber_printf failed\n",
1038 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1042 send_ldap_result( conn, op, LDAP_OTHER,
1043 NULL, "encode entry end error", NULL, NULL );
1047 bytes = send_ldap_ber( conn, ber );
1052 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1053 "send_ldap_response: conn %d ber write failed.\n",
1056 Debug( LDAP_DEBUG_ANY,
1057 "send_ldap_response: ber write failed\n",
1064 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1065 num_bytes_sent += bytes;
1068 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1070 Statslog( LDAP_DEBUG_STATS2, "conn=%ld op=%ld ENTRY dn=\"%s\"\n",
1071 (long) conn->c_connid, (long) op->o_opid, e->e_dn, 0, 0 );
1074 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1075 "send_search_entry: conn %d exit.\n",
1078 Debug( LDAP_DEBUG_TRACE, "<= send_search_entry\n", 0, 0, 0 );
1089 send_search_reference(
1094 struct berval **refs,
1096 LDAPControl **ctrls,
1097 struct berval ***v2refs
1104 AttributeDescription *ad_ref = slap_schema.si_ad_ref;
1105 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
1108 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1109 "send_search_reference: conn %d dn=\"%s\"\n",
1110 op->o_connid, e->e_dn ));
1112 Debug( LDAP_DEBUG_TRACE,
1113 "=> send_search_reference: dn=\"%s\"\n",
1118 if ( ! access_allowed( be, conn, op, e,
1119 ad_entry, NULL, ACL_READ ) )
1122 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
1123 "send_search_reference: conn %d access to entry %s not allowed\n",
1124 op->o_connid, e->e_dn ));
1126 Debug( LDAP_DEBUG_ACL,
1127 "send_search_reference: access to entry not allowed\n",
1134 if ( ! access_allowed( be, conn, op, e,
1135 ad_ref, NULL, ACL_READ ) )
1138 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
1139 "send_search_reference: conn %d access to reference not allowed.\n",
1142 Debug( LDAP_DEBUG_ACL,
1143 "send_search_reference: access to reference not allowed\n",
1150 if( refs == NULL ) {
1152 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1153 "send_search_reference: null ref in (%s).\n",
1154 op->o_connid, e->e_dn ));
1156 Debug( LDAP_DEBUG_ANY,
1157 "send_search_reference: null ref in (%s)\n",
1164 if( op->o_protocol < LDAP_VERSION3 ) {
1165 /* save the references for the result */
1166 if( *refs != NULL ) {
1167 value_add( v2refs, refs );
1172 ber = ber_alloc_t( LBER_USE_DER );
1174 if ( ber == NULL ) {
1176 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1177 "send_search_reference: conn %d ber_alloc failed\n",
1180 Debug( LDAP_DEBUG_ANY,
1181 "send_search_reference: ber_alloc failed\n", 0, 0, 0 );
1184 send_ldap_result( conn, op, LDAP_OTHER,
1185 NULL, "alloc BER error", NULL, NULL );
1189 rc = ber_printf( ber, "{it{V}N}", op->o_msgid,
1190 LDAP_RES_SEARCH_REFERENCE, refs );
1194 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1195 "send_search_reference: conn %d ber_printf failed.\n",
1198 Debug( LDAP_DEBUG_ANY,
1199 "send_search_reference: ber_printf failed\n", 0, 0, 0 );
1203 send_ldap_result( conn, op, LDAP_OTHER,
1204 NULL, "encode DN error", NULL, NULL );
1208 bytes = send_ldap_ber( conn, ber );
1211 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1212 num_bytes_sent += bytes;
1215 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1217 Statslog( LDAP_DEBUG_STATS2, "conn=%ld op=%ld REF dn=\"%s\"\n",
1218 (long) conn->c_connid, (long) op->o_opid, e->e_dn, 0, 0 );
1221 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1222 "send_search_reference: conn %d exit.\n", op->o_connid ));
1224 Debug( LDAP_DEBUG_TRACE, "<= send_search_reference\n", 0, 0, 0 );
1243 *code = LDAP_SUCCESS;
1247 if ( strncasecmp( s, "RESULT", 6 ) != 0 ) {
1249 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
1250 "str2result: (%s), expecting \"RESULT\"\n", s ));
1252 Debug( LDAP_DEBUG_ANY, "str2result (%s) expecting \"RESULT\"\n",
1261 while ( (s = strchr( s, '\n' )) != NULL ) {
1266 if ( (c = strchr( s, ':' )) != NULL ) {
1270 if ( strncasecmp( s, "code", 4 ) == 0 ) {
1274 } else if ( strncasecmp( s, "matched", 7 ) == 0 ) {
1278 } else if ( strncasecmp( s, "info", 4 ) == 0 ) {
1284 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
1285 "str2result: (%s) unknown.\n", s ));
1287 Debug( LDAP_DEBUG_ANY, "str2result (%s) unknown\n",