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 );
326 rc = ber_printf( ber, "{is{t{ess",
328 matched == NULL ? "" : matched,
329 text == NULL ? "" : text );
333 rc = ber_printf( ber, "{it{ess",
335 matched == NULL ? "" : matched,
336 text == NULL ? "" : text );
341 assert( err == LDAP_REFERRAL );
342 rc = ber_printf( ber, "t{V}",
343 LDAP_TAG_REFERRAL, ref );
345 assert( err != LDAP_REFERRAL );
349 if( rc != -1 && sasldata != NULL ) {
350 rc = ber_printf( ber, "tO",
351 LDAP_TAG_SASL_RES_CREDS, sasldata );
354 if( rc != -1 && resoid != NULL ) {
355 rc = ber_printf( ber, "ts",
356 LDAP_TAG_EXOP_RES_OID, resoid );
359 if( rc != -1 && resdata != NULL ) {
360 rc = ber_printf( ber, "tO",
361 LDAP_TAG_EXOP_RES_VALUE, resdata );
365 rc = ber_printf( ber, "N}N}" );
367 #ifdef LDAP_CONNECTIONLESS
368 if( conn->c_is_udp && rc != -1 ) {
369 rc = ber_printf( ber, "N}" );
375 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
376 "send_ldap_response: conn %d ber_printf failed\n",
377 conn ? conn->c_connid : 0 ));
379 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
387 bytes = send_ldap_ber( conn, ber );
392 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
393 "send_ldap_response: conn %d ber write failed\n",
394 conn ? conn->c_connid : 0 ));
396 Debug( LDAP_DEBUG_ANY,
397 "send_ldap_response: ber write failed\n",
404 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
405 num_bytes_sent += bytes;
407 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
413 send_ldap_disconnect(
424 #define LDAP_UNSOLICITED_ERROR(e) \
425 ( (e) == LDAP_PROTOCOL_ERROR \
426 || (e) == LDAP_STRONG_AUTH_REQUIRED \
427 || (e) == LDAP_UNAVAILABLE )
429 assert( LDAP_UNSOLICITED_ERROR( err ) );
432 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
433 "send_ldap_disconnect: conn %d %d:%s\n",
434 conn ? conn->c_connid : 0, err, text ? text : "" ));
436 Debug( LDAP_DEBUG_TRACE,
437 "send_ldap_disconnect %d:%s\n",
438 err, text ? text : "", NULL );
442 if ( op->o_protocol < LDAP_VERSION3 ) {
444 tag = req2res( op->o_tag );
445 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
448 reqoid = LDAP_NOTICE_DISCONNECT;
449 tag = LDAP_RES_EXTENDED;
453 send_ldap_response( conn, op, tag, msgid,
454 err, NULL, text, NULL,
455 reqoid, NULL, NULL, NULL );
457 Statslog( LDAP_DEBUG_STATS,
458 "conn=%ld op=%ld DISCONNECT tag=%lu err=%ld text=%s\n",
459 (long) op->o_connid, (long) op->o_opid,
460 (unsigned long) tag, (long) err, text ? text : "" );
478 assert( !LDAP_API_ERROR( err ) );
481 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
482 "send_ldap_result : conn %ld op=%ld p=%d\n",
483 (long)op->o_connid, (long)op->o_opid, op->o_protocol ));
485 Debug( LDAP_DEBUG_TRACE,
486 "send_ldap_result: conn=%ld op=%ld p=%d\n",
487 (long) op->o_connid, (long) op->o_opid, op->o_protocol );
491 LDAP_LOG(( "operation", LDAP_LEVEL_ARGS,
492 "send_ldap_result: conn=%ld err=%d matched=\"%s\" text=\"%s\"\n",
493 (long)op->o_connid, err, matched ? matched : "", text ? text : "" ));
495 Debug( LDAP_DEBUG_ARGS,
496 "send_ldap_result: err=%d matched=\"%s\" text=\"%s\"\n",
497 err, matched ? matched : "", text ? text : "" );
503 LDAP_LOG(( "operation", LDAP_LEVEL_ARGS,
504 "send_ldap_result: referral=\"%s\"\n",
505 ref[0] && ref[0]->bv_val ? ref[0]->bv_val : "NULL" ));
507 Debug( LDAP_DEBUG_ARGS,
508 "send_ldap_result: referral=\"%s\"\n",
509 ref[0] && ref[0]->bv_val ? ref[0]->bv_val : "NULL",
515 assert( err != LDAP_PARTIAL_RESULTS );
517 if( op->o_tag != LDAP_REQ_SEARCH ) {
518 trim_refs_urls( ref );
521 if ( err == LDAP_REFERRAL ) {
523 err = LDAP_NO_SUCH_OBJECT;
524 } else if ( op->o_protocol < LDAP_VERSION3 ) {
525 err = LDAP_PARTIAL_RESULTS;
529 if ( op->o_protocol < LDAP_VERSION3 ) {
530 tmp = v2ref( ref, text );
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, ref,
540 NULL, NULL, NULL, ctrls );
542 Statslog( LDAP_DEBUG_STATS,
543 "conn=%ld op=%ld RESULT tag=%lu err=%ld text=%s\n",
544 (long) op->o_connid, (long) op->o_opid,
545 (unsigned long) tag, (long) err, text ? text : "" );
568 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
569 "send_ldap_sasl: conn %d err=%ld len=%ld\n",
570 op->o_connid, (long)err, cred ? cred->bv_len : -1 ));
572 Debug( LDAP_DEBUG_TRACE, "send_ldap_sasl: err=%ld len=%ld\n",
573 (long) err, cred ? cred->bv_len : -1, NULL );
577 tag = req2res( op->o_tag );
578 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
580 send_ldap_response( conn, op, tag, msgid,
581 err, matched, text, ref,
582 NULL, NULL, cred, ctrls );
592 struct berval **refs,
594 struct berval *rspdata,
602 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
603 "send_ldap_extended: conn %d err=%ld oid=%s len=%ld\n",
604 op->o_connid, (long)err, rspoid ? rspoid : "",
605 rspdata != NULL ? (long)rspdata->bv_len : (long)0 ));
607 Debug( LDAP_DEBUG_TRACE,
608 "send_ldap_extended err=%ld oid=%s len=%ld\n",
610 rspoid ? rspoid : "",
611 rspdata != NULL ? (long) rspdata->bv_len : (long) 0 );
615 tag = req2res( op->o_tag );
616 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
618 send_ldap_response( conn, op, tag, msgid,
619 err, matched, text, refs,
620 rspoid, rspdata, NULL, ctrls );
631 struct berval **refs,
639 assert( !LDAP_API_ERROR( err ) );
642 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
643 "send_search_result: conn %d err=%d matched=\"%s\"\n",
644 op->o_connid, err, matched ? matched : "",
647 Debug( LDAP_DEBUG_TRACE,
648 "send_search_result: err=%d matched=\"%s\" text=\"%s\"\n",
649 err, matched ? matched : "", text ? text : "" );
653 assert( err != LDAP_PARTIAL_RESULTS );
655 trim_refs_urls( refs );
657 if( op->o_protocol < LDAP_VERSION3 ) {
658 /* send references in search results */
659 if( err == LDAP_REFERRAL ) {
660 err = LDAP_PARTIAL_RESULTS;
663 tmp = v2ref( refs, text );
668 /* don't send references in search results */
669 assert( refs == NULL );
672 if( err == LDAP_REFERRAL ) {
677 tag = req2res( op->o_tag );
678 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
680 send_ldap_response( conn, op, tag, msgid,
681 err, matched, text, refs,
682 NULL, NULL, NULL, ctrls );
684 Statslog( LDAP_DEBUG_STATS,
685 "conn=%ld op=%ld SEARCH RESULT tag=%lu err=%ld text=%s\n",
686 (long) op->o_connid, (long) op->o_opid,
687 (unsigned long) tag, (long) err, text ? text : "" );
713 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
716 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
717 "send_search_entry: conn %d dn=\"%s\"%s\n",
718 op->o_connid, e->e_dn,
719 attrsonly ? " (attrsOnly)" : "" ));
721 Debug( LDAP_DEBUG_TRACE,
722 "=> send_search_entry: dn=\"%s\"%s\n",
723 e->e_dn, attrsonly ? " (attrsOnly)" : "", 0 );
727 if ( ! access_allowed( be, conn, op, e,
728 ad_entry, NULL, ACL_READ ) )
731 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
732 "send_search_entry: conn %d access to entry (%s) not allowed\n",
733 op->o_connid, e->e_dn ));
735 Debug( LDAP_DEBUG_ACL,
736 "send_search_entry: access to entry not allowed\n",
745 ber = ber_alloc_t( LBER_USE_DER );
749 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
750 "send_search_entry: conn %d ber_alloc failed\n",
753 Debug( LDAP_DEBUG_ANY, "ber_alloc failed\n", 0, 0, 0 );
756 send_ldap_result( conn, op, LDAP_OTHER,
757 NULL, "BER allocation error", NULL, NULL );
761 #ifdef LDAP_CONNECTIONLESS
762 if (conn->c_is_udp) {
763 rc = ber_write(ber, (char *)&op->o_peeraddr, sizeof(struct sockaddr), 0);
764 if (rc != sizeof(struct sockaddr)) {
766 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
767 "send_search_entry: conn %d ber_printf failed\n",
768 conn ? conn->c_connid : 0 ));
770 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
775 rc = ber_printf( ber, "{is{t{s{",
776 op->o_msgid, "", LDAP_RES_SEARCH_ENTRY, e->e_dn );
780 rc = ber_printf( ber, "{it{s{" /*}}}*/, op->o_msgid,
781 LDAP_RES_SEARCH_ENTRY, e->e_dn );
786 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
787 "send_search_entry: conn %d ber_printf failed\n",
790 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
794 send_ldap_result( conn, op, LDAP_OTHER,
795 NULL, "encoding DN error", NULL, NULL );
799 /* check for special all user attributes ("*") type */
800 userattrs = ( attrs == NULL ) ? 1
801 : charray_inlist( attrs, LDAP_ALL_USER_ATTRIBUTES );
803 /* check for special all operational attributes ("+") type */
804 opattrs = ( attrs == NULL ) ? 0
805 : charray_inlist( attrs, LDAP_ALL_OPERATIONAL_ATTRIBUTES );
807 for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
808 AttributeDescription *desc = a->a_desc;
809 char *type = desc->ad_cname->bv_val;
811 if ( attrs == NULL ) {
812 /* all addrs request, skip operational attributes */
813 if( is_at_operational( desc->ad_type ) ) {
818 /* specific addrs requested */
819 if ( is_at_operational( desc->ad_type ) ) {
820 if( !opattrs && !ad_inlist( desc, attrs ) ) {
825 if (!userattrs && !ad_inlist( desc, attrs ) ) {
831 if ( ! access_allowed( be, conn, op, e, desc, NULL, ACL_READ ) ) {
833 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
834 "send_search_entry: conn %d access to attribute %s not allowed\n",
835 op->o_connid, desc->ad_cname->bv_val ));
837 Debug( LDAP_DEBUG_ACL, "acl: access to attribute %s not allowed\n",
838 desc->ad_cname->bv_val, 0, 0 );
844 if (( rc = ber_printf( ber, "{s[" /*]}*/ , type )) == -1 ) {
846 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
847 "send_search_entry: conn %d ber_printf failed\n",
850 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
854 send_ldap_result( conn, op, LDAP_OTHER,
855 NULL, "encoding description error", NULL, NULL );
860 for ( i = 0; a->a_vals[i] != NULL; i++ ) {
861 if ( ! access_allowed( be, conn, op, e,
862 desc, a->a_vals[i], ACL_READ ) )
865 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
866 "send_search_entry: conn %d access to attribute %s, value %d not allowed\n",
867 op->o_connid, desc->ad_cname->bv_val, i ));
869 Debug( LDAP_DEBUG_ACL,
870 "acl: access to attribute %s, value %d not allowed\n",
871 desc->ad_cname->bv_val, i, 0 );
877 if (( rc = ber_printf( ber, "O", a->a_vals[i] )) == -1 ) {
879 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
880 "send_search_entry: conn %d ber_printf failed.\n",
883 Debug( LDAP_DEBUG_ANY,
884 "ber_printf failed\n", 0, 0, 0 );
888 send_ldap_result( conn, op, LDAP_OTHER,
889 NULL, "encoding values error", NULL, NULL );
895 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
897 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
898 "send_search_entry: conn %d ber_printf failed\n",
901 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
905 send_ldap_result( conn, op, LDAP_OTHER,
906 NULL, "encode end error", NULL, NULL );
911 /* eventually will loop through generated operational attributes */
912 /* only have subschemaSubentry implemented */
913 aa = backend_operational( be, conn, op, e );
915 for (a = aa ; a != NULL; a = a->a_next ) {
916 AttributeDescription *desc = a->a_desc;
918 if ( attrs == NULL ) {
919 /* all addrs request, skip operational attributes */
920 if( is_at_operational( desc->ad_type ) ) {
925 /* specific addrs requested */
926 if( is_at_operational( desc->ad_type ) ) {
927 if( !opattrs && !ad_inlist( desc, attrs ) ) {
931 if (!userattrs && !ad_inlist( desc, attrs ) )
938 if ( ! access_allowed( be, conn, op, e, desc, NULL, ACL_READ ) ) {
940 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
941 "send_search_entry: conn %s access to attribute %s not allowed\n",
942 op->o_connid, desc->ad_cname->bv_val ));
944 Debug( LDAP_DEBUG_ACL, "acl: access to attribute %s not allowed\n",
945 desc->ad_cname->bv_val, 0, 0 );
951 rc = ber_printf( ber, "{s[" /*]}*/ , desc->ad_cname->bv_val );
954 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
955 "send_search_entry: conn %d ber_printf failed\n",
958 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
962 send_ldap_result( conn, op, LDAP_OTHER,
963 NULL, "encoding description error", NULL, NULL );
968 for ( i = 0; a->a_vals[i] != NULL; i++ ) {
969 if ( ! access_allowed( be, conn, op, e,
970 desc, a->a_vals[i], ACL_READ ) )
973 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
974 "send_search_entry: conn %d access to %s, value %d not allowed\n",
975 op->o_connid, desc->ad_cname->bv_val, i ));
977 Debug( LDAP_DEBUG_ACL,
978 "acl: access to attribute %s, value %d not allowed\n",
979 desc->ad_cname->bv_val, i, 0 );
986 if (( rc = ber_printf( ber, "O", a->a_vals[i] )) == -1 ) {
988 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
989 "send_search_entry: conn %d ber_printf failed\n",
992 Debug( LDAP_DEBUG_ANY,
993 "ber_printf failed\n", 0, 0, 0 );
997 send_ldap_result( conn, op, LDAP_OTHER,
998 NULL, "encoding values error", NULL, NULL );
1004 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
1006 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1007 "send_search_entry: conn %d ber_printf failed\n",
1010 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1014 send_ldap_result( conn, op, LDAP_OTHER,
1015 NULL, "encode end error", NULL, NULL );
1022 rc = ber_printf( ber, /*{{{*/ "}N}N}" );
1024 #ifdef LDAP_CONNECTIONLESS
1025 if (conn->c_is_udp && rc != -1)
1026 rc = ber_printf( ber, "}" );
1030 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1031 "send_search_entry: conn %d ber_printf failed\n",
1034 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1038 send_ldap_result( conn, op, LDAP_OTHER,
1039 NULL, "encode entry end error", NULL, NULL );
1043 bytes = send_ldap_ber( conn, ber );
1048 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1049 "send_ldap_response: conn %d ber write failed.\n",
1052 Debug( LDAP_DEBUG_ANY,
1053 "send_ldap_response: ber write failed\n",
1060 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1061 num_bytes_sent += bytes;
1064 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1066 Statslog( LDAP_DEBUG_STATS2, "conn=%ld op=%ld ENTRY dn=\"%s\"\n",
1067 (long) conn->c_connid, (long) op->o_opid, e->e_dn, 0, 0 );
1070 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1071 "send_search_entry: conn %d exit.\n",
1074 Debug( LDAP_DEBUG_TRACE, "<= send_search_entry\n", 0, 0, 0 );
1085 send_search_reference(
1090 struct berval **refs,
1092 LDAPControl **ctrls,
1093 struct berval ***v2refs
1100 AttributeDescription *ad_ref = slap_schema.si_ad_ref;
1101 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
1104 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1105 "send_search_reference: conn %d dn=\"%s\"\n",
1106 op->o_connid, e->e_dn ));
1108 Debug( LDAP_DEBUG_TRACE,
1109 "=> send_search_reference: dn=\"%s\"\n",
1114 if ( ! access_allowed( be, conn, op, e,
1115 ad_entry, NULL, ACL_READ ) )
1118 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
1119 "send_search_reference: conn %d access to entry %s not allowed\n",
1120 op->o_connid, e->e_dn ));
1122 Debug( LDAP_DEBUG_ACL,
1123 "send_search_reference: access to entry not allowed\n",
1130 if ( ! access_allowed( be, conn, op, e,
1131 ad_ref, NULL, ACL_READ ) )
1134 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
1135 "send_search_reference: conn %d access to reference not allowed.\n",
1138 Debug( LDAP_DEBUG_ACL,
1139 "send_search_reference: access to reference not allowed\n",
1146 if( refs == NULL ) {
1148 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1149 "send_search_reference: null ref in (%s).\n",
1150 op->o_connid, e->e_dn ));
1152 Debug( LDAP_DEBUG_ANY,
1153 "send_search_reference: null ref in (%s)\n",
1160 if( op->o_protocol < LDAP_VERSION3 ) {
1161 /* save the references for the result */
1162 if( *refs != NULL ) {
1163 value_add( v2refs, refs );
1168 ber = ber_alloc_t( LBER_USE_DER );
1170 if ( ber == NULL ) {
1172 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1173 "send_search_reference: conn %d ber_alloc failed\n",
1176 Debug( LDAP_DEBUG_ANY,
1177 "send_search_reference: ber_alloc failed\n", 0, 0, 0 );
1180 send_ldap_result( conn, op, LDAP_OTHER,
1181 NULL, "alloc BER error", NULL, NULL );
1185 rc = ber_printf( ber, "{it{V}N}", op->o_msgid,
1186 LDAP_RES_SEARCH_REFERENCE, refs );
1190 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1191 "send_search_reference: conn %d ber_printf failed.\n",
1194 Debug( LDAP_DEBUG_ANY,
1195 "send_search_reference: ber_printf failed\n", 0, 0, 0 );
1199 send_ldap_result( conn, op, LDAP_OTHER,
1200 NULL, "encode DN error", NULL, NULL );
1204 bytes = send_ldap_ber( conn, ber );
1207 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1208 num_bytes_sent += bytes;
1211 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1213 Statslog( LDAP_DEBUG_STATS2, "conn=%ld op=%ld ENTRY dn=\"%s\"\n",
1214 (long) conn->c_connid, (long) op->o_opid, e->e_dn, 0, 0 );
1217 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1218 "send_search_reference: conn %d exit.\n", op->o_connid ));
1220 Debug( LDAP_DEBUG_TRACE, "<= send_search_reference\n", 0, 0, 0 );
1239 *code = LDAP_SUCCESS;
1243 if ( strncasecmp( s, "RESULT", 6 ) != 0 ) {
1245 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
1246 "str2result: (%s), expecting \"RESULT\"\n", s ));
1248 Debug( LDAP_DEBUG_ANY, "str2result (%s) expecting \"RESULT\"\n",
1257 while ( (s = strchr( s, '\n' )) != NULL ) {
1262 if ( (c = strchr( s, ':' )) != NULL ) {
1266 if ( strncasecmp( s, "code", 4 ) == 0 ) {
1270 } else if ( strncasecmp( s, "matched", 7 ) == 0 ) {
1274 } else if ( strncasecmp( s, "info", 4 ) == 0 ) {
1280 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
1281 "str2result: (%s) unknown.\n", s ));
1283 Debug( LDAP_DEBUG_ANY, "str2result (%s) unknown\n",