1 /* result.c - routines to send ldap results, errors, and referrals */
4 * Copyright 1998-2002 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( BerVarray 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].bv_val != 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 );
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 );
145 if ( err != EWOULDBLOCK && err != EAGAIN ) {
146 connection_closing( conn );
148 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
149 ldap_pvt_thread_mutex_unlock( &conn->c_write_mutex );
154 /* wait for socket to be write-ready */
155 conn->c_writewaiter = 1;
156 ber_sockbuf_ctrl( conn->c_sb, LBER_SB_OPT_GET_FD, &sd );
157 slapd_set_write( sd, 1 );
159 ldap_pvt_thread_cond_wait( &conn->c_write_cv, &conn->c_mutex );
160 conn->c_writewaiter = 0;
163 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
164 ldap_pvt_thread_mutex_unlock( &conn->c_write_mutex );
180 struct berval *resdata,
181 struct berval *sasldata,
186 BerElement *ber = (BerElement *)berbuf;
190 if (op->o_callback && op->o_callback->sc_response) {
191 op->o_callback->sc_response( conn, op, tag, msgid, err, matched,
192 text, ref, resoid, resdata, sasldata, ctrls );
196 assert( ctrls == NULL ); /* ctrls not implemented */
198 ber_init_w_nullc( ber, LBER_USE_DER );
201 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
202 "send_ldap_response: conn %d msgid=%ld tag=%ld err=%ld\n",
203 conn ? conn->c_connid : 0, (long)msgid, (long)tag, (long)err ));
205 Debug( LDAP_DEBUG_TRACE,
206 "send_ldap_response: msgid=%ld tag=%ld err=%ld\n",
207 (long) msgid, (long) tag, (long) err );
212 LDAP_LOG(( "operation", LDAP_LEVEL_ARGS,
213 "send_ldap_response: conn %d ref=\"%s\"\n",
214 conn ? conn->c_connid : 0,
215 ref[0].bv_val ? ref[0].bv_val : "NULL" ));
217 Debug( LDAP_DEBUG_ARGS, "send_ldap_response: ref=\"%s\"\n",
218 ref[0].bv_val ? ref[0].bv_val : "NULL",
224 #ifdef LDAP_CONNECTIONLESS
225 if (conn->c_is_udp) {
226 rc = ber_write(ber, (char *)&op->o_peeraddr, sizeof(struct sockaddr), 0);
227 if (rc != sizeof(struct sockaddr)) {
229 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
230 "send_ldap_response: conn %d ber_write failed\n",
231 conn ? conn->c_connid : 0 ));
233 Debug( LDAP_DEBUG_ANY, "ber_write failed\n", 0, 0, 0 );
239 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2) {
240 rc = ber_printf( ber, "{is{t{ess",
242 matched == NULL ? "" : matched,
243 text == NULL ? "" : text );
247 rc = ber_printf( ber, "{it{ess",
249 matched == NULL ? "" : matched,
250 text == NULL ? "" : text );
255 assert( err == LDAP_REFERRAL );
256 rc = ber_printf( ber, "t{W}",
257 LDAP_TAG_REFERRAL, ref );
259 assert( err != LDAP_REFERRAL );
263 if( rc != -1 && sasldata != NULL ) {
264 rc = ber_printf( ber, "tO",
265 LDAP_TAG_SASL_RES_CREDS, sasldata );
268 if( rc != -1 && resoid != NULL ) {
269 rc = ber_printf( ber, "ts",
270 LDAP_TAG_EXOP_RES_OID, resoid );
273 if( rc != -1 && resdata != NULL ) {
274 rc = ber_printf( ber, "tO",
275 LDAP_TAG_EXOP_RES_VALUE, resdata );
279 rc = ber_printf( ber, "N}N}" );
281 #ifdef LDAP_CONNECTIONLESS
282 if( conn->c_is_udp && op->o_protocol == LDAP_VERSION2 && rc != -1 ) {
283 rc = ber_printf( ber, "N}" );
289 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
290 "send_ldap_response: conn %d ber_printf failed\n",
291 conn ? conn->c_connid : 0 ));
293 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
301 bytes = send_ldap_ber( conn, ber );
306 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
307 "send_ldap_response: conn %d ber write failed\n",
308 conn ? conn->c_connid : 0 ));
310 Debug( LDAP_DEBUG_ANY,
311 "send_ldap_response: ber write failed\n",
318 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
319 num_bytes_sent += bytes;
321 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
327 send_ldap_disconnect(
338 #define LDAP_UNSOLICITED_ERROR(e) \
339 ( (e) == LDAP_PROTOCOL_ERROR \
340 || (e) == LDAP_STRONG_AUTH_REQUIRED \
341 || (e) == LDAP_UNAVAILABLE )
343 assert( LDAP_UNSOLICITED_ERROR( err ) );
346 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
347 "send_ldap_disconnect: conn %d %d:%s\n",
348 conn ? conn->c_connid : 0, err, text ? text : "" ));
350 Debug( LDAP_DEBUG_TRACE,
351 "send_ldap_disconnect %d:%s\n",
352 err, text ? text : "", NULL );
356 if ( op->o_protocol < LDAP_VERSION3 ) {
358 tag = req2res( op->o_tag );
359 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
362 reqoid = LDAP_NOTICE_DISCONNECT;
363 tag = LDAP_RES_EXTENDED;
367 send_ldap_response( conn, op, tag, msgid,
368 err, NULL, text, NULL,
369 reqoid, NULL, NULL, NULL );
371 Statslog( LDAP_DEBUG_STATS,
372 "conn=%ld op=%ld DISCONNECT tag=%lu err=%ld text=%s\n",
373 (long) op->o_connid, (long) op->o_opid,
374 (unsigned long) tag, (long) err, text ? text : "" );
392 assert( !LDAP_API_ERROR( err ) );
395 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
396 "send_ldap_result : conn %ld op=%ld p=%d\n",
397 (long)op->o_connid, (long)op->o_opid, op->o_protocol ));
399 Debug( LDAP_DEBUG_TRACE,
400 "send_ldap_result: conn=%ld op=%ld p=%d\n",
401 (long) op->o_connid, (long) op->o_opid, op->o_protocol );
405 LDAP_LOG(( "operation", LDAP_LEVEL_ARGS,
406 "send_ldap_result: conn=%ld err=%d matched=\"%s\" text=\"%s\"\n",
407 (long)op->o_connid, err, matched ? matched : "", text ? text : "" ));
409 Debug( LDAP_DEBUG_ARGS,
410 "send_ldap_result: err=%d matched=\"%s\" text=\"%s\"\n",
411 err, matched ? matched : "", text ? text : "" );
417 LDAP_LOG(( "operation", LDAP_LEVEL_ARGS,
418 "send_ldap_result: referral=\"%s\"\n",
419 ref[0].bv_val ? ref[0].bv_val : "NULL" ));
421 Debug( LDAP_DEBUG_ARGS,
422 "send_ldap_result: referral=\"%s\"\n",
423 ref[0].bv_val ? ref[0].bv_val : "NULL",
428 assert( err != LDAP_PARTIAL_RESULTS );
430 if ( err == LDAP_REFERRAL ) {
432 err = LDAP_NO_SUCH_OBJECT;
433 } else if ( op->o_protocol < LDAP_VERSION3 ) {
434 err = LDAP_PARTIAL_RESULTS;
438 if ( op->o_protocol < LDAP_VERSION3 ) {
439 tmp = v2ref( ref, text );
444 tag = req2res( op->o_tag );
445 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
447 send_ldap_response( conn, op, tag, msgid,
448 err, matched, text, ref,
449 NULL, NULL, NULL, ctrls );
451 Statslog( LDAP_DEBUG_STATS,
452 "conn=%ld op=%ld RESULT tag=%lu err=%ld text=%s\n",
453 (long) op->o_connid, (long) op->o_opid,
454 (unsigned long) tag, (long) err, text ? text : "" );
477 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
478 "send_ldap_sasl: conn %d err=%ld len=%ld\n",
479 op->o_connid, (long)err, cred ? cred->bv_len : -1 ));
481 Debug( LDAP_DEBUG_TRACE, "send_ldap_sasl: err=%ld len=%ld\n",
482 (long) err, cred ? cred->bv_len : -1, NULL );
486 tag = req2res( op->o_tag );
487 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
489 send_ldap_response( conn, op, tag, msgid,
490 err, matched, text, ref,
491 NULL, NULL, cred, ctrls );
503 struct berval *rspdata,
511 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
512 "send_ldap_extended: conn %d err=%ld oid=%s len=%ld\n",
513 op->o_connid, (long)err, rspoid ? rspoid : "",
514 rspdata != NULL ? (long)rspdata->bv_len : (long)0 ));
516 Debug( LDAP_DEBUG_TRACE,
517 "send_ldap_extended err=%ld oid=%s len=%ld\n",
519 rspoid ? rspoid : "",
520 rspdata != NULL ? (long) rspdata->bv_len : (long) 0 );
524 tag = req2res( op->o_tag );
525 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
527 send_ldap_response( conn, op, tag, msgid,
528 err, matched, text, refs,
529 rspoid, rspdata, NULL, ctrls );
549 assert( !LDAP_API_ERROR( err ) );
551 if (op->o_callback && op->o_callback->sc_sresult) {
552 op->o_callback->sc_sresult(conn, op, err, matched, text, refs,
558 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
559 "send_search_result: conn %d err=%d matched=\"%s\"\n",
560 op->o_connid, err, matched ? matched : "",
563 Debug( LDAP_DEBUG_TRACE,
564 "send_search_result: err=%d matched=\"%s\" text=\"%s\"\n",
565 err, matched ? matched : "", text ? text : "" );
569 assert( err != LDAP_PARTIAL_RESULTS );
571 if( op->o_protocol < LDAP_VERSION3 ) {
572 /* send references in search results */
573 if( err == LDAP_REFERRAL ) {
574 err = LDAP_PARTIAL_RESULTS;
577 tmp = v2ref( refs, text );
582 /* don't send references in search results */
583 assert( refs == NULL );
586 if( err == LDAP_REFERRAL ) {
591 tag = req2res( op->o_tag );
592 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
594 send_ldap_response( conn, op, tag, msgid,
595 err, matched, text, refs,
596 NULL, NULL, NULL, ctrls );
598 Statslog( LDAP_DEBUG_STATS,
599 "conn=%ld op=%ld SEARCH RESULT tag=%lu err=%ld text=%s\n",
600 (long) op->o_connid, (long) op->o_opid,
601 (unsigned long) tag, (long) err, text ? text : "" );
608 static struct berval AllUser = { sizeof(LDAP_ALL_USER_ATTRIBUTES)-1,
609 LDAP_ALL_USER_ATTRIBUTES };
610 static struct berval AllOper = { sizeof(LDAP_ALL_OPERATIONAL_ATTRIBUTES)-1,
611 LDAP_ALL_OPERATIONAL_ATTRIBUTES };
619 AttributeName *attrs,
625 BerElement *ber = (BerElement *)berbuf;
631 static AccessControlState acl_state_init = ACL_STATE_INIT;
632 AccessControlState acl_state;
634 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
636 if (op->o_callback && op->o_callback->sc_sendentry) {
637 return op->o_callback->sc_sendentry( be, conn, op, e, attrs,
642 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
643 "send_search_entry: conn %d dn=\"%s\"%s\n",
644 op->o_connid, e->e_dn,
645 attrsonly ? " (attrsOnly)" : "" ));
647 Debug( LDAP_DEBUG_TRACE,
648 "=> send_search_entry: dn=\"%s\"%s\n",
649 e->e_dn, attrsonly ? " (attrsOnly)" : "", 0 );
652 if ( ! access_allowed( be, conn, op, e,
653 ad_entry, NULL, ACL_READ, NULL ) )
656 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
657 "send_search_entry: conn %d access to entry (%s) not allowed\n",
658 op->o_connid, e->e_dn ));
660 Debug( LDAP_DEBUG_ACL,
661 "send_search_entry: access to entry not allowed\n",
670 ber_init_w_nullc( ber, LBER_USE_DER );
672 #ifdef LDAP_CONNECTIONLESS
673 if (conn->c_is_udp) {
674 rc = ber_write(ber, (char *)&op->o_peeraddr, sizeof(struct sockaddr), 0);
675 if (rc != sizeof(struct sockaddr)) {
677 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
678 "send_search_entry: conn %d ber_printf failed\n",
679 conn ? conn->c_connid : 0 ));
681 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
687 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2) {
688 rc = ber_printf( ber, "{is{t{O{" /*}}}*/,
689 op->o_msgid, "", LDAP_RES_SEARCH_ENTRY, &e->e_name );
693 rc = ber_printf( ber, "{it{O{" /*}}}*/, op->o_msgid,
694 LDAP_RES_SEARCH_ENTRY, &e->e_name );
699 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
700 "send_search_entry: conn %d ber_printf failed\n",
703 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
707 send_ldap_result( conn, op, LDAP_OTHER,
708 NULL, "encoding DN error", NULL, NULL );
712 /* check for special all user attributes ("*") type */
713 userattrs = ( attrs == NULL ) ? 1
714 : an_find( attrs, &AllUser );
716 /* check for special all operational attributes ("+") type */
717 opattrs = ( attrs == NULL ) ? 0
718 : an_find( attrs, &AllOper );
720 for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
721 AttributeDescription *desc = a->a_desc;
723 if ( attrs == NULL ) {
724 /* all attrs request, skip operational attributes */
725 if( is_at_operational( desc->ad_type ) ) {
730 /* specific attrs requested */
731 if ( is_at_operational( desc->ad_type ) ) {
732 if( !opattrs && !ad_inlist( desc, attrs ) ) {
737 if (!userattrs && !ad_inlist( desc, attrs ) ) {
743 acl_state = acl_state_init;
745 if ( ! access_allowed( be, conn, op, e, desc, NULL,
746 ACL_READ, &acl_state ) )
749 LDAP_LOG(( "acl", LDAP_LEVEL_INFO, "send_search_entry: "
750 "conn %d access to attribute %s not allowed\n",
751 op->o_connid, desc->ad_cname.bv_val ));
753 Debug( LDAP_DEBUG_ACL, "acl: "
754 "access to attribute %s not allowed\n",
755 desc->ad_cname.bv_val, 0, 0 );
760 if (( rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname )) == -1 ) {
762 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
763 "send_search_entry: conn %d ber_printf failed\n",
766 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
770 send_ldap_result( conn, op, LDAP_OTHER,
771 NULL, "encoding description error", NULL, NULL );
776 for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
777 if ( ! access_allowed( be, conn, op, e,
778 desc, &a->a_vals[i], ACL_READ, &acl_state ) )
781 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
782 "send_search_entry: conn %d "
783 "access to attribute %s, value %d not allowed\n",
784 op->o_connid, desc->ad_cname.bv_val, i ));
786 Debug( LDAP_DEBUG_ACL,
787 "acl: access to attribute %s, value %d not allowed\n",
788 desc->ad_cname.bv_val, i, 0 );
794 if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
796 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
797 "send_search_entry: conn %d ber_printf failed.\n",
800 Debug( LDAP_DEBUG_ANY,
801 "ber_printf failed\n", 0, 0, 0 );
805 send_ldap_result( conn, op, LDAP_OTHER,
806 NULL, "encoding values error", NULL, NULL );
812 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
814 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
815 "send_search_entry: conn %d ber_printf failed\n",
818 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
822 send_ldap_result( conn, op, LDAP_OTHER,
823 NULL, "encode end error", NULL, NULL );
828 /* eventually will loop through generated operational attributes */
829 /* only have subschemaSubentry implemented */
830 aa = backend_operational( be, conn, op, e, attrs, opattrs );
832 for (a = aa ; a != NULL; a = a->a_next ) {
833 AttributeDescription *desc = a->a_desc;
835 if ( attrs == NULL ) {
836 /* all attrs request, skip operational attributes */
837 if( is_at_operational( desc->ad_type ) ) {
842 /* specific attrs requested */
843 if( is_at_operational( desc->ad_type ) ) {
844 if( !opattrs && !ad_inlist( desc, attrs ) ) {
848 if (!userattrs && !ad_inlist( desc, attrs ) )
855 acl_state = acl_state_init;
857 if ( ! access_allowed( be, conn, op, e, desc, NULL,
858 ACL_READ, &acl_state ) )
861 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
862 "send_search_entry: conn %s "
863 "access to attribute %s not allowed\n",
864 op->o_connid, desc->ad_cname.bv_val ));
866 Debug( LDAP_DEBUG_ACL, "acl: access to attribute %s not allowed\n",
867 desc->ad_cname.bv_val, 0, 0 );
873 rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname );
876 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
877 "send_search_entry: conn %d ber_printf failed\n",
880 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
884 send_ldap_result( conn, op, LDAP_OTHER,
885 NULL, "encoding description error", NULL, NULL );
891 for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
892 if ( ! access_allowed( be, conn, op, e,
893 desc, &a->a_vals[i], ACL_READ, &acl_state ) )
896 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
897 "send_search_entry: conn %d "
898 "access to %s, value %d not allowed\n",
899 op->o_connid, desc->ad_cname.bv_val, i ));
901 Debug( LDAP_DEBUG_ACL,
902 "acl: access to attribute %s, value %d not allowed\n",
903 desc->ad_cname.bv_val, i, 0 );
909 if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
911 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
912 "send_search_entry: conn %d ber_printf failed\n",
915 Debug( LDAP_DEBUG_ANY,
916 "ber_printf failed\n", 0, 0, 0 );
920 send_ldap_result( conn, op, LDAP_OTHER,
921 NULL, "encoding values error", NULL, NULL );
928 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
930 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
931 "send_search_entry: conn %d ber_printf failed\n",
934 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
938 send_ldap_result( conn, op, LDAP_OTHER,
939 NULL, "encode end error", NULL, NULL );
947 rc = ber_printf( ber, /*{{{*/ "}N}N}" );
949 #ifdef LDAP_CONNECTIONLESS
950 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2 && rc != -1)
951 rc = ber_printf( ber, "}" );
955 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
956 "send_search_entry: conn %d ber_printf failed\n",
959 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
963 send_ldap_result( conn, op, LDAP_OTHER,
964 NULL, "encode entry end error", NULL, NULL );
968 bytes = send_ldap_ber( conn, ber );
973 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
974 "send_ldap_response: conn %d ber write failed.\n",
977 Debug( LDAP_DEBUG_ANY,
978 "send_ldap_response: ber write failed\n",
985 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
986 num_bytes_sent += bytes;
989 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
991 Statslog( LDAP_DEBUG_STATS2, "conn=%ld op=%ld ENTRY dn=\"%s\"\n",
992 (long) conn->c_connid, (long) op->o_opid, e->e_dn, 0, 0 );
995 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
996 "send_search_entry: conn %d exit.\n",
999 Debug( LDAP_DEBUG_TRACE, "<= send_search_entry\n", 0, 0, 0 );
1009 send_search_reference(
1015 LDAPControl **ctrls,
1020 BerElement *ber = (BerElement *)berbuf;
1024 AttributeDescription *ad_ref = slap_schema.si_ad_ref;
1025 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
1028 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1029 "send_search_reference: conn %d dn=\"%s\"\n",
1030 op->o_connid, e->e_dn ));
1032 Debug( LDAP_DEBUG_TRACE,
1033 "=> send_search_reference: dn=\"%s\"\n",
1038 if ( ! access_allowed( be, conn, op, e,
1039 ad_entry, NULL, ACL_READ, NULL ) )
1042 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
1043 "send_search_reference: conn %d access to entry %s not allowed\n",
1044 op->o_connid, e->e_dn ));
1046 Debug( LDAP_DEBUG_ACL,
1047 "send_search_reference: access to entry not allowed\n",
1054 if ( ! access_allowed( be, conn, op, e,
1055 ad_ref, NULL, ACL_READ, NULL ) )
1058 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
1059 "send_search_reference: conn %d access to reference not allowed.\n",
1062 Debug( LDAP_DEBUG_ACL,
1063 "send_search_reference: access to reference not allowed\n",
1070 if( refs == NULL ) {
1072 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1073 "send_search_reference: null ref in (%s).\n",
1074 op->o_connid, e->e_dn ));
1076 Debug( LDAP_DEBUG_ANY,
1077 "send_search_reference: null ref in (%s)\n",
1084 if( op->o_protocol < LDAP_VERSION3 ) {
1085 /* save the references for the result */
1086 if( refs[0].bv_val != NULL ) {
1087 value_add( v2refs, refs );
1092 ber_init_w_nullc( ber, LBER_USE_DER );
1094 rc = ber_printf( ber, "{it{W}N}", op->o_msgid,
1095 LDAP_RES_SEARCH_REFERENCE, refs );
1099 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1100 "send_search_reference: conn %d ber_printf failed.\n",
1103 Debug( LDAP_DEBUG_ANY,
1104 "send_search_reference: ber_printf failed\n", 0, 0, 0 );
1107 ber_free_buf( ber );
1108 send_ldap_result( conn, op, LDAP_OTHER,
1109 NULL, "encode DN error", NULL, NULL );
1113 bytes = send_ldap_ber( conn, ber );
1114 ber_free_buf( ber );
1116 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1117 num_bytes_sent += bytes;
1120 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1122 Statslog( LDAP_DEBUG_STATS2, "conn=%ld op=%ld REF dn=\"%s\"\n",
1123 (long) conn->c_connid, (long) op->o_opid, e->e_dn, 0, 0 );
1126 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1127 "send_search_reference: conn %d exit.\n", op->o_connid ));
1129 Debug( LDAP_DEBUG_TRACE, "<= send_search_reference\n", 0, 0, 0 );
1147 *code = LDAP_SUCCESS;
1151 if ( strncasecmp( s, "RESULT", 6 ) != 0 ) {
1153 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
1154 "str2result: (%s), expecting \"RESULT\"\n", s ));
1156 Debug( LDAP_DEBUG_ANY, "str2result (%s) expecting \"RESULT\"\n",
1165 while ( (s = strchr( s, '\n' )) != NULL ) {
1170 if ( (c = strchr( s, ':' )) != NULL ) {
1174 if ( strncasecmp( s, "code", 4 ) == 0 ) {
1178 } else if ( strncasecmp( s, "matched", 7 ) == 0 ) {
1182 } else if ( strncasecmp( s, "info", 4 ) == 0 ) {
1188 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
1189 "str2result: (%s) unknown.\n", s ));
1191 Debug( LDAP_DEBUG_ANY, "str2result (%s) unknown\n",