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 );
973 for ( i = 0; a->a_vals[i] != NULL; i++ ) {
974 if ( ! access_allowed( be, conn, op, e,
975 desc, a->a_vals[i], ACL_READ ) )
978 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
979 "send_search_entry: conn %d access to %s, value %d not allowed\n",
980 op->o_connid, desc->ad_cname->bv_val, i ));
982 Debug( LDAP_DEBUG_ACL,
983 "acl: access to attribute %s, value %d not allowed\n",
984 desc->ad_cname->bv_val, i, 0 );
991 if (( rc = ber_printf( ber, "O", a->a_vals[i] )) == -1 ) {
993 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
994 "send_search_entry: conn %d ber_printf failed\n",
997 Debug( LDAP_DEBUG_ANY,
998 "ber_printf failed\n", 0, 0, 0 );
1002 send_ldap_result( conn, op, LDAP_OTHER,
1003 NULL, "encoding values error", NULL, NULL );
1010 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
1012 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1013 "send_search_entry: conn %d ber_printf failed\n",
1016 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1020 send_ldap_result( conn, op, LDAP_OTHER,
1021 NULL, "encode end error", NULL, NULL );
1029 rc = ber_printf( ber, /*{{{*/ "}N}N}" );
1031 #ifdef LDAP_CONNECTIONLESS
1032 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2 && rc != -1)
1033 rc = ber_printf( ber, "}" );
1037 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1038 "send_search_entry: conn %d ber_printf failed\n",
1041 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1045 send_ldap_result( conn, op, LDAP_OTHER,
1046 NULL, "encode entry end error", NULL, NULL );
1050 bytes = send_ldap_ber( conn, ber );
1055 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1056 "send_ldap_response: conn %d ber write failed.\n",
1059 Debug( LDAP_DEBUG_ANY,
1060 "send_ldap_response: ber write failed\n",
1067 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1068 num_bytes_sent += bytes;
1071 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1073 Statslog( LDAP_DEBUG_STATS2, "conn=%ld op=%ld ENTRY dn=\"%s\"\n",
1074 (long) conn->c_connid, (long) op->o_opid, e->e_dn, 0, 0 );
1077 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1078 "send_search_entry: conn %d exit.\n",
1081 Debug( LDAP_DEBUG_TRACE, "<= send_search_entry\n", 0, 0, 0 );
1092 send_search_reference(
1097 struct berval **refs,
1099 LDAPControl **ctrls,
1100 struct berval ***v2refs
1107 AttributeDescription *ad_ref = slap_schema.si_ad_ref;
1108 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
1111 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1112 "send_search_reference: conn %d dn=\"%s\"\n",
1113 op->o_connid, e->e_dn ));
1115 Debug( LDAP_DEBUG_TRACE,
1116 "=> send_search_reference: dn=\"%s\"\n",
1121 if ( ! access_allowed( be, conn, op, e,
1122 ad_entry, NULL, ACL_READ ) )
1125 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
1126 "send_search_reference: conn %d access to entry %s not allowed\n",
1127 op->o_connid, e->e_dn ));
1129 Debug( LDAP_DEBUG_ACL,
1130 "send_search_reference: access to entry not allowed\n",
1137 if ( ! access_allowed( be, conn, op, e,
1138 ad_ref, NULL, ACL_READ ) )
1141 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
1142 "send_search_reference: conn %d access to reference not allowed.\n",
1145 Debug( LDAP_DEBUG_ACL,
1146 "send_search_reference: access to reference not allowed\n",
1153 if( refs == NULL ) {
1155 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1156 "send_search_reference: null ref in (%s).\n",
1157 op->o_connid, e->e_dn ));
1159 Debug( LDAP_DEBUG_ANY,
1160 "send_search_reference: null ref in (%s)\n",
1167 if( op->o_protocol < LDAP_VERSION3 ) {
1168 /* save the references for the result */
1169 if( *refs != NULL ) {
1170 value_add( v2refs, refs );
1175 ber = ber_alloc_t( LBER_USE_DER );
1177 if ( ber == NULL ) {
1179 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1180 "send_search_reference: conn %d ber_alloc failed\n",
1183 Debug( LDAP_DEBUG_ANY,
1184 "send_search_reference: ber_alloc failed\n", 0, 0, 0 );
1187 send_ldap_result( conn, op, LDAP_OTHER,
1188 NULL, "alloc BER error", NULL, NULL );
1192 rc = ber_printf( ber, "{it{V}N}", op->o_msgid,
1193 LDAP_RES_SEARCH_REFERENCE, refs );
1197 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1198 "send_search_reference: conn %d ber_printf failed.\n",
1201 Debug( LDAP_DEBUG_ANY,
1202 "send_search_reference: ber_printf failed\n", 0, 0, 0 );
1206 send_ldap_result( conn, op, LDAP_OTHER,
1207 NULL, "encode DN error", NULL, NULL );
1211 bytes = send_ldap_ber( conn, ber );
1214 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1215 num_bytes_sent += bytes;
1218 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1220 Statslog( LDAP_DEBUG_STATS2, "conn=%ld op=%ld REF dn=\"%s\"\n",
1221 (long) conn->c_connid, (long) op->o_opid, e->e_dn, 0, 0 );
1224 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1225 "send_search_reference: conn %d exit.\n", op->o_connid ));
1227 Debug( LDAP_DEBUG_TRACE, "<= send_search_reference\n", 0, 0, 0 );
1246 *code = LDAP_SUCCESS;
1250 if ( strncasecmp( s, "RESULT", 6 ) != 0 ) {
1252 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
1253 "str2result: (%s), expecting \"RESULT\"\n", s ));
1255 Debug( LDAP_DEBUG_ANY, "str2result (%s) expecting \"RESULT\"\n",
1264 while ( (s = strchr( s, '\n' )) != NULL ) {
1269 if ( (c = strchr( s, ':' )) != NULL ) {
1273 if ( strncasecmp( s, "code", 4 ) == 0 ) {
1277 } else if ( strncasecmp( s, "matched", 7 ) == 0 ) {
1281 } else if ( strncasecmp( s, "info", 4 ) == 0 ) {
1287 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
1288 "str2result: (%s) unknown.\n", s ));
1290 Debug( LDAP_DEBUG_ANY, "str2result (%s) unknown\n",