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 and 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++ );
740 a_flags = ch_calloc ( j, sizeof(char) );
741 /* If no ValuesReturnFilter control return everything */
742 if ( op->vrFilter == NULL ) {
743 memset(a_flags, 1, j);
748 e_flags[i] = a_flags;
751 if ( op->vrFilter != NULL ) {
752 rc = filter_matched_values(be, conn, op, e->e_attrs, &e_flags) ;
756 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
757 "send_search_entry: conn %lu "
758 "matched values filtering failed\n",
759 conn ? conn->c_connid : 0 ));
761 Debug( LDAP_DEBUG_ANY,
762 "matched values filtering failed\n", 0, 0, 0 );
767 for ( a = e->e_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
772 send_ldap_result( conn, op, LDAP_OTHER,
773 NULL, "matched values filtering error",
779 for ( a = e->e_attrs, j = 0; a != NULL; a = a->a_next, j++ ) {
780 AttributeDescription *desc = a->a_desc;
782 if ( attrs == NULL ) {
783 /* all attrs request, skip operational attributes */
784 if( is_at_operational( desc->ad_type ) ) {
789 /* specific attrs requested */
790 if ( is_at_operational( desc->ad_type ) ) {
791 if( !opattrs && !ad_inlist( desc, attrs ) ) {
796 if (!userattrs && !ad_inlist( desc, attrs ) ) {
802 acl_state = acl_state_init;
804 if ( ! access_allowed( be, conn, op, e, desc, NULL,
805 ACL_READ, &acl_state ) )
808 LDAP_LOG(( "acl", LDAP_LEVEL_INFO, "send_search_entry: "
809 "conn %lu access to attribute %s "
811 op->o_connid, desc->ad_cname.bv_val ));
813 Debug( LDAP_DEBUG_ACL, "acl: "
814 "access to attribute %s not allowed\n",
815 desc->ad_cname.bv_val, 0, 0 );
820 if (( rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname )) == -1 ) {
822 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
823 "send_search_entry: "
824 "conn %lu ber_printf failed\n",
827 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
832 for ( a = e->e_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
836 send_ldap_result( conn, op, LDAP_OTHER,
837 NULL, "encoding description error", NULL, NULL );
842 for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
843 if ( ! access_allowed( be, conn, op, e,
844 desc, &a->a_vals[i], ACL_READ, &acl_state ) )
847 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
848 "send_search_entry: conn %lu "
849 "access to attribute %s, "
850 "value %d not allowed\n",
852 desc->ad_cname.bv_val, i ));
854 Debug( LDAP_DEBUG_ACL,
855 "acl: access to attribute %s, "
856 "value %d not allowed\n",
857 desc->ad_cname.bv_val, i, 0 );
863 if ( e_flags[j][i] == 0 ){
867 if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
869 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
870 "send_search_entry: conn %lu "
871 "ber_printf failed.\n",
874 Debug( LDAP_DEBUG_ANY,
875 "ber_printf failed\n", 0, 0, 0 );
880 for ( a = e->e_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
884 send_ldap_result( conn, op, LDAP_OTHER,
885 NULL, "encoding values error",
892 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
894 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
895 "send_search_entry: conn %lu "
896 "ber_printf failed\n",
899 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
904 for ( a = e->e_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
908 send_ldap_result( conn, op, LDAP_OTHER,
909 NULL, "encode end error", NULL, NULL );
915 for ( a = e->e_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
920 /* eventually will loop through generated operational attributes */
921 /* only have subschemaSubentry implemented */
922 aa = backend_operational( be, conn, op, e, attrs, opattrs );
924 for ( a = aa, i=0; a != NULL; a = a->a_next ) i++;
925 e_flags = ch_malloc ( i * sizeof(a_flags) );
927 for ( a = aa, i=0; a != NULL; a = a->a_next, i++ ) {
928 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ );
930 a_flags = ch_calloc ( j, sizeof(char) );
931 /* If no ValuesReturnFilter control return everything */
932 if ( op->vrFilter == NULL ){
933 memset(a_flags, 1, j);
935 e_flags[i] = a_flags;
938 if ( op->vrFilter != NULL ) {
939 rc = filter_matched_values(be, conn, op, aa, &e_flags) ;
943 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
944 "send_search_entry: conn %lu "
945 "matched values filtering failed\n",
946 conn ? conn->c_connid : 0 ));
948 Debug( LDAP_DEBUG_ANY,
949 "matched values filtering failed\n", 0, 0, 0 );
954 for ( a = aa, i=0; a != NULL; a = a->a_next, i++ ) {
959 send_ldap_result( conn, op, LDAP_OTHER,
960 NULL, "matched values filtering error",
966 for (a = aa, j=0; a != NULL; a = a->a_next, j++ ) {
967 AttributeDescription *desc = a->a_desc;
969 if ( attrs == NULL ) {
970 /* all attrs request, skip operational attributes */
971 if( is_at_operational( desc->ad_type ) ) {
976 /* specific attrs requested */
977 if( is_at_operational( desc->ad_type ) ) {
978 if( !opattrs && !ad_inlist( desc, attrs ) ) {
982 if (!userattrs && !ad_inlist( desc, attrs ) )
989 acl_state = acl_state_init;
991 if ( ! access_allowed( be, conn, op, e, desc, NULL,
992 ACL_READ, &acl_state ) )
995 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
996 "send_search_entry: conn %lu "
997 "access to attribute %s not allowed\n",
998 op->o_connid, desc->ad_cname.bv_val ));
1000 Debug( LDAP_DEBUG_ACL, "acl: access to attribute %s "
1002 desc->ad_cname.bv_val, 0, 0 );
1008 rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname );
1011 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1012 "send_search_entry: conn %lu "
1013 "ber_printf failed\n",
1016 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1019 ber_free_buf( ber );
1020 send_ldap_result( conn, op, LDAP_OTHER,
1021 NULL, "encoding description error", NULL, NULL );
1023 for ( a = aa, i=0; a != NULL; a = a->a_next, i++ ) {
1032 if ( ! attrsonly ) {
1033 for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
1034 if ( ! access_allowed( be, conn, op, e,
1035 desc, &a->a_vals[i], ACL_READ, &acl_state ) )
1038 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
1039 "send_search_entry: conn %lu "
1040 "access to %s, value %d "
1043 desc->ad_cname.bv_val, i ));
1045 Debug( LDAP_DEBUG_ACL,
1046 "acl: access to attribute %s, "
1047 "value %d not allowed\n",
1048 desc->ad_cname.bv_val, i, 0 );
1054 if ( e_flags[j][i] == 0 ){
1058 if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
1060 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1061 "send_search_entry: "
1062 "conn %lu ber_printf "
1066 Debug( LDAP_DEBUG_ANY,
1067 "ber_printf failed\n", 0, 0, 0 );
1070 ber_free_buf( ber );
1071 send_ldap_result( conn, op, LDAP_OTHER,
1072 NULL, "encoding values error",
1075 for ( a = aa, i=0; a != NULL; a = a->a_next, i++ ) {
1086 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
1088 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1089 "send_search_entry: conn %lu "
1090 "ber_printf failed\n",
1093 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1096 ber_free_buf( ber );
1097 send_ldap_result( conn, op, LDAP_OTHER,
1098 NULL, "encode end error", NULL, NULL );
1100 for ( a = aa, i=0; a != NULL; a = a->a_next, i++ ) {
1111 for ( a = aa, i=0; a != NULL; a = a->a_next, i++ ) {
1117 rc = ber_printf( ber, /*{{{*/ "}N}N}" );
1119 #ifdef LDAP_CONNECTIONLESS
1120 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2 && rc != -1)
1121 rc = ber_printf( ber, "}" );
1125 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1126 "send_search_entry: conn %lu ber_printf failed\n",
1129 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1132 ber_free_buf( ber );
1133 send_ldap_result( conn, op, LDAP_OTHER,
1134 NULL, "encode entry end error", NULL, NULL );
1138 bytes = send_ldap_ber( conn, ber );
1139 ber_free_buf( ber );
1143 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1144 "send_search_entry: conn %lu ber write failed.\n",
1147 Debug( LDAP_DEBUG_ANY,
1148 "send_search_entry: ber write failed\n",
1155 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1156 num_bytes_sent += bytes;
1159 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1161 Statslog( LDAP_DEBUG_STATS2, "conn=%lu op=%lu ENTRY dn=\"%s\"\n",
1162 conn->c_connid, op->o_opid, e->e_dn, 0, 0 );
1165 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1166 "send_search_entry: conn %lu exit.\n",
1169 Debug( LDAP_DEBUG_TRACE, "<= send_search_entry\n", 0, 0, 0 );
1179 send_search_reference(
1185 LDAPControl **ctrls,
1190 BerElement *ber = (BerElement *)berbuf;
1194 AttributeDescription *ad_ref = slap_schema.si_ad_ref;
1195 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
1198 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1199 "send_search_reference: conn %lu dn=\"%s\"\n",
1200 op->o_connid, e->e_dn ));
1202 Debug( LDAP_DEBUG_TRACE,
1203 "=> send_search_reference: dn=\"%s\"\n",
1208 if ( ! access_allowed( be, conn, op, e,
1209 ad_entry, NULL, ACL_READ, NULL ) )
1212 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
1213 "send_search_reference: conn %lu "
1214 "access to entry %s not allowed\n",
1215 op->o_connid, e->e_dn ));
1217 Debug( LDAP_DEBUG_ACL,
1218 "send_search_reference: access to entry not allowed\n",
1225 if ( ! access_allowed( be, conn, op, e,
1226 ad_ref, NULL, ACL_READ, NULL ) )
1229 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
1230 "send_search_reference: conn %lu access "
1231 "to reference not allowed.\n",
1234 Debug( LDAP_DEBUG_ACL,
1235 "send_search_reference: access "
1236 "to reference not allowed\n",
1243 if( refs == NULL ) {
1245 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1246 "send_search_reference: conn %lu null ref in (%s).\n",
1247 op->o_connid, e->e_dn ));
1249 Debug( LDAP_DEBUG_ANY,
1250 "send_search_reference: null ref in (%s)\n",
1257 if( op->o_protocol < LDAP_VERSION3 ) {
1258 /* save the references for the result */
1259 if( refs[0].bv_val != NULL ) {
1260 value_add( v2refs, refs );
1265 ber_init_w_nullc( ber, LBER_USE_DER );
1267 rc = ber_printf( ber, "{it{W}N}", op->o_msgid,
1268 LDAP_RES_SEARCH_REFERENCE, refs );
1272 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1273 "send_search_reference: conn %lu "
1274 "ber_printf failed.\n",
1277 Debug( LDAP_DEBUG_ANY,
1278 "send_search_reference: ber_printf failed\n", 0, 0, 0 );
1281 ber_free_buf( ber );
1282 send_ldap_result( conn, op, LDAP_OTHER,
1283 NULL, "encode DN error", NULL, NULL );
1287 bytes = send_ldap_ber( conn, ber );
1288 ber_free_buf( ber );
1290 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1291 num_bytes_sent += bytes;
1294 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1296 Statslog( LDAP_DEBUG_STATS2, "conn=%lu op=%lu REF dn=\"%s\"\n",
1297 conn->c_connid, op->o_opid, e->e_dn, 0, 0 );
1300 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1301 "send_search_reference: conn %lu exit.\n", op->o_connid ));
1303 Debug( LDAP_DEBUG_TRACE, "<= send_search_reference\n", 0, 0, 0 );
1321 *code = LDAP_SUCCESS;
1325 if ( strncasecmp( s, "RESULT", 6 ) != 0 ) {
1327 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
1328 "str2result: (%s), expecting \"RESULT\"\n", s ));
1330 Debug( LDAP_DEBUG_ANY, "str2result (%s) expecting \"RESULT\"\n",
1338 while ( (s = strchr( s, '\n' )) != NULL ) {
1343 if ( (c = strchr( s, ':' )) != NULL ) {
1347 if ( strncasecmp( s, "code", 4 ) == 0 ) {
1351 } else if ( strncasecmp( s, "matched", 7 ) == 0 ) {
1355 } else if ( strncasecmp( s, "info", 4 ) == 0 ) {
1361 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
1362 "str2result: (%s) unknown.\n", s ));
1364 Debug( LDAP_DEBUG_ANY, "str2result (%s) unknown\n",