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/string.h>
17 #include <ac/unistd.h>
21 static char *v2ref( BerVarray ref, const char *text )
23 size_t len = 0, i = 0;
28 return ch_strdup(text);
36 if (text[len-1] != '\n') {
41 v2 = ch_malloc( len+i+sizeof("Referral:") );
48 strcpy( v2+len, "Referral:" );
49 len += sizeof("Referral:");
51 for( i=0; ref[i].bv_val != NULL; i++ ) {
52 v2 = ch_realloc( v2, len + ref[i].bv_len + 1 );
54 AC_MEMCPY(&v2[len], ref[i].bv_val, ref[i].bv_len );
56 if (ref[i].bv_val[ref[i].bv_len-1] != '/') {
65 static ber_tag_t req2res( ber_tag_t tag )
70 case LDAP_REQ_COMPARE:
71 case LDAP_REQ_EXTENDED:
78 tag = LDAP_RES_DELETE;
81 case LDAP_REQ_ABANDON:
87 tag = LDAP_RES_SEARCH_RESULT;
97 static long send_ldap_ber(
103 ber_get_option( ber, LBER_OPT_BER_BYTES_TO_WRITE, &bytes );
105 /* write only one pdu at a time - wait til it's our turn */
106 ldap_pvt_thread_mutex_lock( &conn->c_write_mutex );
108 /* lock the connection */
109 ldap_pvt_thread_mutex_lock( &conn->c_mutex );
116 if ( connection_state_closing( conn ) ) {
117 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
118 ldap_pvt_thread_mutex_unlock( &conn->c_write_mutex );
123 if ( ber_flush( conn->c_sb, ber, 0 ) == 0 ) {
130 * we got an error. if it's ewouldblock, we need to
131 * wait on the socket being writable. otherwise, figure
132 * it's a hard error and return.
136 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
137 "send_ldap_ber: conn %lu ber_flush failed err=%d (%s)\n",
138 conn ? conn->c_connid : 0, err, sock_errstr(err) ));
140 Debug( LDAP_DEBUG_CONNS, "ber_flush failed errno=%d reason=\"%s\"\n",
141 err, sock_errstr(err), 0 );
144 if ( err != EWOULDBLOCK && err != EAGAIN ) {
145 connection_closing( conn );
147 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
148 ldap_pvt_thread_mutex_unlock( &conn->c_write_mutex );
153 /* wait for socket to be write-ready */
154 conn->c_writewaiter = 1;
155 ber_sockbuf_ctrl( conn->c_sb, LBER_SB_OPT_GET_FD, &sd );
156 slapd_set_write( sd, 1 );
158 ldap_pvt_thread_cond_wait( &conn->c_write_cv, &conn->c_mutex );
159 conn->c_writewaiter = 0;
162 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
163 ldap_pvt_thread_mutex_unlock( &conn->c_write_mutex );
179 struct berval *resdata,
180 struct berval *sasldata,
185 BerElement *ber = (BerElement *)berbuf;
189 if (op->o_callback && op->o_callback->sc_response) {
190 op->o_callback->sc_response( conn, op, tag, msgid, err, matched,
191 text, ref, resoid, resdata, sasldata, ctrls );
195 assert( ctrls == NULL ); /* ctrls not implemented */
197 ber_init_w_nullc( ber, LBER_USE_DER );
200 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
201 "send_ldap_response: conn %lu msgid=%d tag=%lu err=%d\n",
202 conn ? conn->c_connid : 0, msgid, tag, err ));
204 Debug( LDAP_DEBUG_TRACE,
205 "send_ldap_response: msgid=%d tag=%lu err=%d\n",
211 LDAP_LOG(( "operation", LDAP_LEVEL_ARGS,
212 "send_ldap_response: conn %lu ref=\"%s\"\n",
213 conn ? conn->c_connid : 0,
214 ref[0].bv_val ? ref[0].bv_val : "NULL" ));
216 Debug( LDAP_DEBUG_ARGS, "send_ldap_response: ref=\"%s\"\n",
217 ref[0].bv_val ? ref[0].bv_val : "NULL",
223 #ifdef LDAP_CONNECTIONLESS
224 if (conn->c_is_udp) {
225 rc = ber_write(ber, (char *)&op->o_peeraddr, sizeof(struct sockaddr), 0);
226 if (rc != sizeof(struct sockaddr)) {
228 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
229 "send_ldap_response: conn %lu ber_write failed\n",
230 conn ? conn->c_connid : 0 ));
232 Debug( LDAP_DEBUG_ANY, "ber_write failed\n", 0, 0, 0 );
238 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2) {
239 rc = ber_printf( ber, "{is{t{ess",
241 matched == NULL ? "" : matched,
242 text == NULL ? "" : text );
246 rc = ber_printf( ber, "{it{ess",
248 matched == NULL ? "" : matched,
249 text == NULL ? "" : text );
254 assert( err == LDAP_REFERRAL );
255 rc = ber_printf( ber, "t{W}",
256 LDAP_TAG_REFERRAL, ref );
258 assert( err != LDAP_REFERRAL );
262 if( rc != -1 && sasldata != NULL ) {
263 rc = ber_printf( ber, "tO",
264 LDAP_TAG_SASL_RES_CREDS, sasldata );
267 if( rc != -1 && resoid != NULL ) {
268 rc = ber_printf( ber, "ts",
269 LDAP_TAG_EXOP_RES_OID, resoid );
272 if( rc != -1 && resdata != NULL ) {
273 rc = ber_printf( ber, "tO",
274 LDAP_TAG_EXOP_RES_VALUE, resdata );
278 rc = ber_printf( ber, "N}N}" );
280 #ifdef LDAP_CONNECTIONLESS
281 if( conn->c_is_udp && op->o_protocol == LDAP_VERSION2 && rc != -1 ) {
282 rc = ber_printf( ber, "N}" );
288 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
289 "send_ldap_response: conn %lu ber_printf failed\n",
290 conn ? conn->c_connid : 0 ));
292 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
300 bytes = send_ldap_ber( conn, ber );
305 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
306 "send_ldap_response: conn %lu ber write failed\n",
307 conn ? conn->c_connid : 0 ));
309 Debug( LDAP_DEBUG_ANY,
310 "send_ldap_response: ber write failed\n",
317 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
318 num_bytes_sent += bytes;
320 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
326 send_ldap_disconnect(
337 #define LDAP_UNSOLICITED_ERROR(e) \
338 ( (e) == LDAP_PROTOCOL_ERROR \
339 || (e) == LDAP_STRONG_AUTH_REQUIRED \
340 || (e) == LDAP_UNAVAILABLE )
342 assert( LDAP_UNSOLICITED_ERROR( err ) );
345 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
346 "send_ldap_disconnect: conn %lu %d:%s\n",
347 conn ? conn->c_connid : 0, err, text ? text : "" ));
349 Debug( LDAP_DEBUG_TRACE,
350 "send_ldap_disconnect %d:%s\n",
351 err, text ? text : "", NULL );
355 if ( op->o_protocol < LDAP_VERSION3 ) {
357 tag = req2res( op->o_tag );
358 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
361 reqoid = LDAP_NOTICE_DISCONNECT;
362 tag = LDAP_RES_EXTENDED;
366 send_ldap_response( conn, op, tag, msgid,
367 err, NULL, text, NULL,
368 reqoid, NULL, NULL, NULL );
370 Statslog( LDAP_DEBUG_STATS,
371 "conn=%lu op=%lu DISCONNECT tag=%lu err=%d text=%s\n",
372 op->o_connid, op->o_opid, tag, err, text ? text : "" );
390 assert( !LDAP_API_ERROR( err ) );
393 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
394 "send_ldap_result : conn %lu op=%lu p=%d\n",
395 op->o_connid, op->o_opid, op->o_protocol ));
397 Debug( LDAP_DEBUG_TRACE,
398 "send_ldap_result: conn=%lu op=%lu p=%d\n",
399 op->o_connid, op->o_opid, op->o_protocol );
403 LDAP_LOG(( "operation", LDAP_LEVEL_ARGS,
404 "send_ldap_result: conn=%lu err=%d matched=\"%s\" text=\"%s\"\n",
405 op->o_connid, err, matched ? matched : "", text ? text : "" ));
407 Debug( LDAP_DEBUG_ARGS,
408 "send_ldap_result: err=%d matched=\"%s\" text=\"%s\"\n",
409 err, matched ? matched : "", text ? text : "" );
415 LDAP_LOG(( "operation", LDAP_LEVEL_ARGS,
416 "send_ldap_result: referral=\"%s\"\n",
417 ref[0].bv_val ? ref[0].bv_val : "NULL" ));
419 Debug( LDAP_DEBUG_ARGS,
420 "send_ldap_result: referral=\"%s\"\n",
421 ref[0].bv_val ? ref[0].bv_val : "NULL",
426 assert( err != LDAP_PARTIAL_RESULTS );
428 if ( err == LDAP_REFERRAL ) {
430 err = LDAP_NO_SUCH_OBJECT;
431 } else if ( op->o_protocol < LDAP_VERSION3 ) {
432 err = LDAP_PARTIAL_RESULTS;
436 if ( op->o_protocol < LDAP_VERSION3 ) {
437 tmp = v2ref( ref, text );
442 tag = req2res( op->o_tag );
443 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
445 send_ldap_response( conn, op, tag, msgid,
446 err, matched, text, ref,
447 NULL, NULL, NULL, ctrls );
449 Statslog( LDAP_DEBUG_STATS,
450 "conn=%lu op=%lu RESULT tag=%lu err=%d text=%s\n",
451 op->o_connid, op->o_opid, tag, err, text ? text : "" );
474 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
475 "send_ldap_sasl: conn %lu err=%d len=%lu\n",
476 op->o_connid, err, cred ? cred->bv_len : -1 ));
478 Debug( LDAP_DEBUG_TRACE, "send_ldap_sasl: err=%d len=%ld\n",
479 err, cred ? (long) cred->bv_len : -1, NULL );
483 tag = req2res( op->o_tag );
484 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
486 send_ldap_response( conn, op, tag, msgid,
487 err, matched, text, ref,
488 NULL, NULL, cred, ctrls );
500 struct berval *rspdata,
508 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
509 "send_ldap_extended: conn %lu err=%d oid=%s len=%ld\n",
510 op->o_connid, err, rspoid ? rspoid : "",
511 rspdata != NULL ? rspdata->bv_len : 0 ));
513 Debug( LDAP_DEBUG_TRACE,
514 "send_ldap_extended err=%d oid=%s len=%ld\n",
516 rspoid ? rspoid : "",
517 rspdata != NULL ? rspdata->bv_len : 0 );
521 tag = req2res( op->o_tag );
522 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
524 send_ldap_response( conn, op, tag, msgid,
525 err, matched, text, refs,
526 rspoid, rspdata, NULL, ctrls );
546 assert( !LDAP_API_ERROR( err ) );
548 if (op->o_callback && op->o_callback->sc_sresult) {
549 op->o_callback->sc_sresult(conn, op, err, matched, text, refs,
555 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
556 "send_search_result: conn %lu err=%d "
557 "matched=\"%s\" text=\"%s\"\n",
558 op->o_connid, err, matched ? matched : "",
561 Debug( LDAP_DEBUG_TRACE,
562 "send_search_result: err=%d matched=\"%s\" text=\"%s\"\n",
563 err, matched ? matched : "", text ? text : "" );
567 assert( err != LDAP_PARTIAL_RESULTS );
569 if( op->o_protocol < LDAP_VERSION3 ) {
570 /* send references in search results */
571 if( err == LDAP_REFERRAL ) {
572 err = LDAP_PARTIAL_RESULTS;
575 tmp = v2ref( refs, text );
580 /* don't send references in search results */
581 assert( refs == NULL );
584 if( err == LDAP_REFERRAL ) {
589 tag = req2res( op->o_tag );
590 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
592 send_ldap_response( conn, op, tag, msgid,
593 err, matched, text, refs,
594 NULL, NULL, NULL, ctrls );
598 sprintf( nbuf, "%d nentries=%d", err, nentries );
600 Statslog( LDAP_DEBUG_STATS,
601 "conn=%lu op=%lu SEARCH RESULT tag=%lu err=%s text=%s\n",
602 op->o_connid, op->o_opid, tag, nbuf, text ? text : "" );
610 static struct berval AllUser = { sizeof(LDAP_ALL_USER_ATTRIBUTES)-1,
611 LDAP_ALL_USER_ATTRIBUTES };
612 static struct berval AllOper = { sizeof(LDAP_ALL_OPERATIONAL_ATTRIBUTES)-1,
613 LDAP_ALL_OPERATIONAL_ATTRIBUTES };
621 AttributeName *attrs,
627 BerElement *ber = (BerElement *)berbuf;
629 int i, j, rc=-1, bytes;
633 static AccessControlState acl_state_init = ACL_STATE_INIT;
634 AccessControlState acl_state;
636 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
638 /* a_flags: array of flags telling if the i-th element will be
639 * returned or filtered out
640 * e_flags: array of a_flags
642 char *a_flags, **e_flags;
644 if (op->o_callback && op->o_callback->sc_sendentry) {
645 return op->o_callback->sc_sendentry( be, conn, op, e, attrs,
650 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
651 "send_search_entry: conn %lu dn=\"%s\"%s\n",
652 op->o_connid, e->e_dn,
653 attrsonly ? " (attrsOnly)" : "" ));
655 Debug( LDAP_DEBUG_TRACE,
656 "=> send_search_entry: dn=\"%s\"%s\n",
657 e->e_dn, attrsonly ? " (attrsOnly)" : "", 0 );
660 if ( ! access_allowed( be, conn, op, e,
661 ad_entry, NULL, ACL_READ, NULL ) )
664 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
665 "send_search_entry: conn %lu access "
666 "to entry (%s) not allowed\n",
667 op->o_connid, e->e_dn ));
669 Debug( LDAP_DEBUG_ACL,
670 "send_search_entry: access to entry not allowed\n",
679 ber_init_w_nullc( ber, LBER_USE_DER );
681 #ifdef LDAP_CONNECTIONLESS
682 if (conn->c_is_udp) {
683 rc = ber_write(ber, (char *)&op->o_peeraddr, sizeof(struct sockaddr), 0);
684 if (rc != sizeof(struct sockaddr)) {
686 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
687 "send_search_entry: conn %lu ber_printf failed\n",
688 conn ? conn->c_connid : 0 ));
690 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
696 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2) {
697 rc = ber_printf( ber, "{is{t{O{" /*}}}*/,
698 op->o_msgid, "", LDAP_RES_SEARCH_ENTRY, &e->e_name );
700 #endif /* LDAP_CONNECTIONLESS */
702 rc = ber_printf( ber, "{it{O{" /*}}}*/, op->o_msgid,
703 LDAP_RES_SEARCH_ENTRY, &e->e_name );
708 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
709 "send_search_entry: conn %lu ber_printf failed\n",
712 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
716 send_ldap_result( conn, op, LDAP_OTHER,
717 NULL, "encoding DN error", NULL, NULL );
721 /* check for special all user attributes ("*") type */
722 userattrs = ( attrs == NULL ) ? 1
723 : an_find( attrs, &AllUser );
725 /* check for special all operational attributes ("+") type */
726 opattrs = ( attrs == NULL ) ? 0
727 : an_find( attrs, &AllOper );
729 /* create an array of arrays of flags. Each flag corresponds
730 * to particular value of attribute an equals 1 if value matches
731 * to ValuesReturnFilter or 0 if not
733 for ( a = e->e_attrs, i=0; a != NULL; a = a->a_next ) i++;
734 e_flags = ch_malloc ( i * sizeof(a_flags) );
736 for ( a = e->e_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
737 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ );
739 a_flags = ch_calloc ( j, sizeof(char) );
740 /* If no ValuesReturnFilter control return everything */
741 if ( op->vrFilter == NULL ){
742 memset(a_flags, 1, j);
744 e_flags[i] = a_flags;
747 if ( op->vrFilter != NULL ){
749 rc = filter_matched_values(be, conn, op, e->e_attrs, &e_flags) ;
753 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
754 "send_search_entry: conn %lu "
755 "matched values filtering failed\n",
756 conn ? conn->c_connid : 0 ));
758 Debug( LDAP_DEBUG_ANY,
759 "matched values filtering failed\n", 0, 0, 0 );
764 for ( a = e->e_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
769 send_ldap_result( conn, op, LDAP_OTHER,
770 NULL, "matched values filtering error",
776 for ( a = e->e_attrs, j = 0; a != NULL; a = a->a_next, j++ ) {
777 AttributeDescription *desc = a->a_desc;
779 if ( attrs == NULL ) {
780 /* all attrs request, skip operational attributes */
781 if( is_at_operational( desc->ad_type ) ) {
786 /* specific attrs requested */
787 if ( is_at_operational( desc->ad_type ) ) {
788 if( !opattrs && !ad_inlist( desc, attrs ) ) {
793 if (!userattrs && !ad_inlist( desc, attrs ) ) {
799 acl_state = acl_state_init;
801 if ( ! access_allowed( be, conn, op, e, desc, NULL,
802 ACL_READ, &acl_state ) )
805 LDAP_LOG(( "acl", LDAP_LEVEL_INFO, "send_search_entry: "
806 "conn %lu access to attribute %s "
808 op->o_connid, desc->ad_cname.bv_val ));
810 Debug( LDAP_DEBUG_ACL, "acl: "
811 "access to attribute %s not allowed\n",
812 desc->ad_cname.bv_val, 0, 0 );
817 if (( rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname )) == -1 ) {
819 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
820 "send_search_entry: "
821 "conn %lu ber_printf failed\n",
824 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
829 for ( a = e->e_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
833 send_ldap_result( conn, op, LDAP_OTHER,
834 NULL, "encoding description error", NULL, NULL );
839 for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
840 if ( ! access_allowed( be, conn, op, e,
841 desc, &a->a_vals[i], ACL_READ, &acl_state ) )
844 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
845 "send_search_entry: conn %lu "
846 "access to attribute %s, "
847 "value %d not allowed\n",
849 desc->ad_cname.bv_val, i ));
851 Debug( LDAP_DEBUG_ACL,
852 "acl: access to attribute %s, "
853 "value %d not allowed\n",
854 desc->ad_cname.bv_val, i, 0 );
860 if ( e_flags[j][i] == 0 ){
864 if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
866 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
867 "send_search_entry: conn %lu "
868 "ber_printf failed.\n",
871 Debug( LDAP_DEBUG_ANY,
872 "ber_printf failed\n", 0, 0, 0 );
877 for ( a = e->e_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
881 send_ldap_result( conn, op, LDAP_OTHER,
882 NULL, "encoding values error",
889 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
891 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
892 "send_search_entry: conn %lu "
893 "ber_printf failed\n",
896 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
901 for ( a = e->e_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
905 send_ldap_result( conn, op, LDAP_OTHER,
906 NULL, "encode end error", NULL, NULL );
912 for ( a = e->e_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
917 /* eventually will loop through generated operational attributes */
918 /* only have subschemaSubentry implemented */
919 aa = backend_operational( be, conn, op, e, attrs, opattrs );
921 for ( a = aa, i=0; a != NULL; a = a->a_next ) i++;
922 e_flags = ch_malloc ( i * sizeof(a_flags) );
924 for ( a = aa, i=0; a != NULL; a = a->a_next, i++ ) {
925 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ );
927 a_flags = ch_calloc ( j, sizeof(char) );
928 /* If no ValuesReturnFilter control return everything */
929 if ( op->vrFilter == NULL ){
930 memset(a_flags, 1, j);
932 e_flags[i] = a_flags;
935 if ( op->vrFilter != NULL ){
937 rc = filter_matched_values(be, conn, op, aa, &e_flags) ;
941 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
942 "send_search_entry: conn %lu "
943 "matched values filtering failed\n",
944 conn ? conn->c_connid : 0 ));
946 Debug( LDAP_DEBUG_ANY,
947 "matched values filtering failed\n", 0, 0, 0 );
952 for ( a = aa, i=0; a != NULL; a = a->a_next, i++ ) {
957 send_ldap_result( conn, op, LDAP_OTHER,
958 NULL, "matched values filtering error",
964 for (a = aa, j=0; a != NULL; a = a->a_next, j++ ) {
965 AttributeDescription *desc = a->a_desc;
967 if ( attrs == NULL ) {
968 /* all attrs request, skip operational attributes */
969 if( is_at_operational( desc->ad_type ) ) {
974 /* specific attrs requested */
975 if( is_at_operational( desc->ad_type ) ) {
976 if( !opattrs && !ad_inlist( desc, attrs ) ) {
980 if (!userattrs && !ad_inlist( desc, attrs ) )
987 acl_state = acl_state_init;
989 if ( ! access_allowed( be, conn, op, e, desc, NULL,
990 ACL_READ, &acl_state ) )
993 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
994 "send_search_entry: conn %lu "
995 "access to attribute %s not allowed\n",
996 op->o_connid, desc->ad_cname.bv_val ));
998 Debug( LDAP_DEBUG_ACL, "acl: access to attribute %s "
1000 desc->ad_cname.bv_val, 0, 0 );
1006 rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname );
1009 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1010 "send_search_entry: conn %lu "
1011 "ber_printf failed\n",
1014 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1017 ber_free_buf( ber );
1018 send_ldap_result( conn, op, LDAP_OTHER,
1019 NULL, "encoding description error", NULL, NULL );
1021 for ( a = aa, i=0; a != NULL; a = a->a_next, i++ ) {
1030 if ( ! attrsonly ) {
1031 for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
1032 if ( ! access_allowed( be, conn, op, e,
1033 desc, &a->a_vals[i], ACL_READ, &acl_state ) )
1036 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
1037 "send_search_entry: conn %lu "
1038 "access to %s, value %d "
1041 desc->ad_cname.bv_val, i ));
1043 Debug( LDAP_DEBUG_ACL,
1044 "acl: access to attribute %s, "
1045 "value %d not allowed\n",
1046 desc->ad_cname.bv_val, i, 0 );
1052 if ( e_flags[j][i] == 0 ){
1056 if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
1058 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1059 "send_search_entry: "
1060 "conn %lu ber_printf "
1064 Debug( LDAP_DEBUG_ANY,
1065 "ber_printf failed\n", 0, 0, 0 );
1068 ber_free_buf( ber );
1069 send_ldap_result( conn, op, LDAP_OTHER,
1070 NULL, "encoding values error",
1073 for ( a = aa, i=0; a != NULL; a = a->a_next, i++ ) {
1084 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
1086 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1087 "send_search_entry: conn %lu "
1088 "ber_printf failed\n",
1091 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1094 ber_free_buf( ber );
1095 send_ldap_result( conn, op, LDAP_OTHER,
1096 NULL, "encode end error", NULL, NULL );
1098 for ( a = aa, i=0; a != NULL; a = a->a_next, i++ ) {
1109 for ( a = aa, i=0; a != NULL; a = a->a_next, i++ ) {
1115 rc = ber_printf( ber, /*{{{*/ "}N}N}" );
1117 #ifdef LDAP_CONNECTIONLESS
1118 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2 && rc != -1)
1119 rc = ber_printf( ber, "}" );
1123 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1124 "send_search_entry: conn %lu ber_printf failed\n",
1127 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1130 ber_free_buf( ber );
1131 send_ldap_result( conn, op, LDAP_OTHER,
1132 NULL, "encode entry end error", NULL, NULL );
1136 bytes = send_ldap_ber( conn, ber );
1137 ber_free_buf( ber );
1141 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1142 "send_search_entry: conn %lu ber write failed.\n",
1145 Debug( LDAP_DEBUG_ANY,
1146 "send_search_entry: ber write failed\n",
1153 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1154 num_bytes_sent += bytes;
1157 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1159 Statslog( LDAP_DEBUG_STATS2, "conn=%lu op=%lu ENTRY dn=\"%s\"\n",
1160 conn->c_connid, op->o_opid, e->e_dn, 0, 0 );
1163 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1164 "send_search_entry: conn %lu exit.\n",
1167 Debug( LDAP_DEBUG_TRACE, "<= send_search_entry\n", 0, 0, 0 );
1177 send_search_reference(
1183 LDAPControl **ctrls,
1188 BerElement *ber = (BerElement *)berbuf;
1192 AttributeDescription *ad_ref = slap_schema.si_ad_ref;
1193 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
1196 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1197 "send_search_reference: conn %lu dn=\"%s\"\n",
1198 op->o_connid, e->e_dn ));
1200 Debug( LDAP_DEBUG_TRACE,
1201 "=> send_search_reference: dn=\"%s\"\n",
1206 if ( ! access_allowed( be, conn, op, e,
1207 ad_entry, NULL, ACL_READ, NULL ) )
1210 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
1211 "send_search_reference: conn %lu "
1212 "access to entry %s not allowed\n",
1213 op->o_connid, e->e_dn ));
1215 Debug( LDAP_DEBUG_ACL,
1216 "send_search_reference: access to entry not allowed\n",
1223 if ( ! access_allowed( be, conn, op, e,
1224 ad_ref, NULL, ACL_READ, NULL ) )
1227 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
1228 "send_search_reference: conn %lu access "
1229 "to reference not allowed.\n",
1232 Debug( LDAP_DEBUG_ACL,
1233 "send_search_reference: access "
1234 "to reference not allowed\n",
1241 if( refs == NULL ) {
1243 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1244 "send_search_reference: conn %lu null ref in (%s).\n",
1245 op->o_connid, e->e_dn ));
1247 Debug( LDAP_DEBUG_ANY,
1248 "send_search_reference: null ref in (%s)\n",
1255 if( op->o_protocol < LDAP_VERSION3 ) {
1256 /* save the references for the result */
1257 if( refs[0].bv_val != NULL ) {
1258 value_add( v2refs, refs );
1263 ber_init_w_nullc( ber, LBER_USE_DER );
1265 rc = ber_printf( ber, "{it{W}N}", op->o_msgid,
1266 LDAP_RES_SEARCH_REFERENCE, refs );
1270 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1271 "send_search_reference: conn %lu "
1272 "ber_printf failed.\n",
1275 Debug( LDAP_DEBUG_ANY,
1276 "send_search_reference: ber_printf failed\n", 0, 0, 0 );
1279 ber_free_buf( ber );
1280 send_ldap_result( conn, op, LDAP_OTHER,
1281 NULL, "encode DN error", NULL, NULL );
1285 bytes = send_ldap_ber( conn, ber );
1286 ber_free_buf( ber );
1288 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1289 num_bytes_sent += bytes;
1292 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1294 Statslog( LDAP_DEBUG_STATS2, "conn=%lu op=%lu REF dn=\"%s\"\n",
1295 conn->c_connid, op->o_opid, e->e_dn, 0, 0 );
1298 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1299 "send_search_reference: conn %lu exit.\n", op->o_connid ));
1301 Debug( LDAP_DEBUG_TRACE, "<= send_search_reference\n", 0, 0, 0 );
1319 *code = LDAP_SUCCESS;
1323 if ( strncasecmp( s, "RESULT", 6 ) != 0 ) {
1325 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
1326 "str2result: (%s), expecting \"RESULT\"\n", s ));
1328 Debug( LDAP_DEBUG_ANY, "str2result (%s) expecting \"RESULT\"\n",
1337 while ( (s = strchr( s, '\n' )) != NULL ) {
1342 if ( (c = strchr( s, ':' )) != NULL ) {
1346 if ( strncasecmp( s, "code", 4 ) == 0 ) {
1350 } else if ( strncasecmp( s, "matched", 7 ) == 0 ) {
1354 } else if ( strncasecmp( s, "info", 4 ) == 0 ) {
1360 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
1361 "str2result: (%s) unknown.\n", s ));
1363 Debug( LDAP_DEBUG_ANY, "str2result (%s) unknown\n",