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, 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, ENTRY,
201 "send_ldap_response: msgid=%d tag=%lu err=%d\n",
204 Debug( LDAP_DEBUG_TRACE,
205 "send_ldap_response: msgid=%d tag=%lu err=%d\n",
211 LDAP_LOG( OPERATION, 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" , 0 );
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, ERR,
229 "send_ldap_response: conn %lu ber_write failed\n",
230 conn ? conn->c_connid : 0 , 0, 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, ERR,
289 "send_ldap_response: conn %lu ber_printf failed\n",
290 conn ? conn->c_connid : 0, 0, 0 );
292 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
300 bytes = send_ldap_ber( conn, ber );
305 LDAP_LOG( OPERATION, ERR,
306 "send_ldap_response: conn %lu ber write failed\n",
307 conn ? conn->c_connid : 0, 0, 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, 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, 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, ARGS,
404 "send_ldap_result: err=%d matched=\"%s\" text=\"%s\"\n",
405 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, ARGS,
416 "send_ldap_result: referral=\"%s\"\n",
417 ref[0].bv_val ? ref[0].bv_val : "NULL", 0, 0 );
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, 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, ENTRY,
509 "send_ldap_extended: err=%d oid=%s len=%ld\n",
510 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, ENTRY,
556 "send_search_result: err=%d matched=\"%s\" text=\"%s\"\n",
557 err, matched ? matched : "", text ? text : "" );
559 Debug( LDAP_DEBUG_TRACE,
560 "send_search_result: err=%d matched=\"%s\" text=\"%s\"\n",
561 err, matched ? matched : "", text ? text : "" );
565 assert( err != LDAP_PARTIAL_RESULTS );
567 if( op->o_protocol < LDAP_VERSION3 ) {
568 /* send references in search results */
569 if( err == LDAP_REFERRAL ) {
570 err = LDAP_PARTIAL_RESULTS;
573 tmp = v2ref( refs, text );
578 /* don't send references in search results */
579 assert( refs == NULL );
582 if( err == LDAP_REFERRAL ) {
587 tag = req2res( op->o_tag );
588 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
590 send_ldap_response( conn, op, tag, msgid,
591 err, matched, text, refs,
592 NULL, NULL, NULL, ctrls );
596 sprintf( nbuf, "%d nentries=%d", err, nentries );
598 Statslog( LDAP_DEBUG_STATS,
599 "conn=%lu op=%lu SEARCH RESULT tag=%lu err=%s text=%s\n",
600 op->o_connid, op->o_opid, tag, nbuf, 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;
627 int i, j, rc=-1, bytes;
631 static AccessControlState acl_state_init = ACL_STATE_INIT;
632 AccessControlState acl_state;
634 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
636 /* a_flags: array of flags telling if the i-th element will be
637 * returned or filtered out
638 * e_flags: array of a_flags
640 char *a_flags, **e_flags;
642 if (op->o_callback && op->o_callback->sc_sendentry) {
643 return op->o_callback->sc_sendentry( be, conn, op, e, attrs,
648 LDAP_LOG( OPERATION, ENTRY,
649 "send_search_entry: conn %lu dn=\"%s\"%s\n",
650 op->o_connid, e->e_dn, attrsonly ? " (attrsOnly)" : "" );
652 Debug( LDAP_DEBUG_TRACE,
653 "=> send_search_entry: dn=\"%s\"%s\n",
654 e->e_dn, attrsonly ? " (attrsOnly)" : "", 0 );
657 if ( ! access_allowed( be, conn, op, e,
658 ad_entry, NULL, ACL_READ, NULL ) )
662 "send_search_entry: conn %lu access to entry (%s) not allowed\n",
663 op->o_connid, e->e_dn, 0 );
665 Debug( LDAP_DEBUG_ACL,
666 "send_search_entry: access to entry not allowed\n",
675 ber_init_w_nullc( ber, LBER_USE_DER );
677 #ifdef LDAP_CONNECTIONLESS
678 if (conn->c_is_udp) {
679 rc = ber_write(ber, (char *)&op->o_peeraddr, sizeof(struct sockaddr), 0);
680 if (rc != sizeof(struct sockaddr)) {
682 LDAP_LOG( OPERATION, ERR,
683 "send_search_entry: conn %lu ber_printf failed\n",
684 conn ? conn->c_connid : 0, 0, 0 );
686 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
692 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2) {
693 rc = ber_printf( ber, "{is{t{O{" /*}}}*/,
694 op->o_msgid, "", LDAP_RES_SEARCH_ENTRY, &e->e_name );
696 #endif /* LDAP_CONNECTIONLESS */
698 rc = ber_printf( ber, "{it{O{" /*}}}*/, op->o_msgid,
699 LDAP_RES_SEARCH_ENTRY, &e->e_name );
704 LDAP_LOG( OPERATION, ERR,
705 "send_search_entry: conn %lu ber_printf failed\n",
706 op->o_connid, 0, 0 );
708 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
712 send_ldap_result( conn, op, LDAP_OTHER,
713 NULL, "encoding DN error", NULL, NULL );
717 /* check for special all user attributes ("*") type */
718 userattrs = ( attrs == NULL ) ? 1
719 : an_find( attrs, &AllUser );
721 /* check for special all operational attributes ("+") type */
722 opattrs = ( attrs == NULL ) ? 0
723 : an_find( attrs, &AllOper );
725 /* create an array of arrays of flags. Each flag corresponds
726 * to particular value of attribute and equals 1 if value matches
727 * to ValuesReturnFilter or 0 if not
729 for ( a = e->e_attrs, i=0; a != NULL; a = a->a_next ) i++;
730 e_flags = ch_malloc ( i * sizeof(a_flags) );
732 for ( a = e->e_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
733 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ );
736 a_flags = ch_calloc ( j, sizeof(char) );
737 /* If no ValuesReturnFilter control return everything */
738 if ( op->vrFilter == NULL ) {
739 memset(a_flags, 1, j);
744 e_flags[i] = a_flags;
747 if ( op->vrFilter != NULL ) {
748 rc = filter_matched_values(be, conn, op, e->e_attrs, &e_flags) ;
752 LDAP_LOG( OPERATION, ERR,
753 "send_search_entry: conn %lu matched values filtering failed\n",
754 conn ? conn->c_connid : 0, 0, 0 );
756 Debug( LDAP_DEBUG_ANY,
757 "matched values filtering failed\n", 0, 0, 0 );
762 for ( a = e->e_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
767 send_ldap_result( conn, op, LDAP_OTHER,
768 NULL, "matched values filtering error",
774 for ( a = e->e_attrs, j = 0; a != NULL; a = a->a_next, j++ ) {
775 AttributeDescription *desc = a->a_desc;
777 if ( attrs == NULL ) {
778 /* all attrs request, skip operational attributes */
779 if( is_at_operational( desc->ad_type ) ) {
784 /* specific attrs requested */
785 if ( is_at_operational( desc->ad_type ) ) {
786 if( !opattrs && !ad_inlist( desc, attrs ) ) {
791 if (!userattrs && !ad_inlist( desc, attrs ) ) {
797 acl_state = acl_state_init;
799 if ( ! access_allowed( be, conn, op, e, desc, NULL,
800 ACL_READ, &acl_state ) )
804 "send_search_entry: conn %lu access to attribute %s not "
805 "allowed\n", op->o_connid, desc->ad_cname.bv_val, 0 );
807 Debug( LDAP_DEBUG_ACL, "acl: "
808 "access to attribute %s not allowed\n",
809 desc->ad_cname.bv_val, 0, 0 );
814 if (( rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname )) == -1 ) {
816 LDAP_LOG( OPERATION, ERR,
817 "send_search_entry: conn %lu ber_printf failed\n",
818 op->o_connid, 0, 0 );
820 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
825 for ( a = e->e_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
829 send_ldap_result( conn, op, LDAP_OTHER,
830 NULL, "encoding description error", NULL, NULL );
835 for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
836 if ( ! access_allowed( be, conn, op, e,
837 desc, &a->a_vals[i], ACL_READ, &acl_state ) )
841 "send_search_entry: conn %lu "
842 "access to attribute %s, value %d not allowed\n",
843 op->o_connid, desc->ad_cname.bv_val, i );
845 Debug( LDAP_DEBUG_ACL,
846 "acl: access to attribute %s, "
847 "value %d not allowed\n",
848 desc->ad_cname.bv_val, i, 0 );
854 if ( e_flags[j][i] == 0 ){
858 if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
860 LDAP_LOG( OPERATION, ERR,
861 "send_search_entry: conn %lu "
862 "ber_printf failed.\n", op->o_connid, 0, 0 );
864 Debug( LDAP_DEBUG_ANY,
865 "ber_printf failed\n", 0, 0, 0 );
870 for ( a = e->e_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
874 send_ldap_result( conn, op, LDAP_OTHER,
875 NULL, "encoding values error",
882 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
884 LDAP_LOG( OPERATION, ERR,
885 "send_search_entry: conn %lu ber_printf failed\n",
886 op->o_connid, 0, 0 );
888 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
893 for ( a = e->e_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
897 send_ldap_result( conn, op, LDAP_OTHER,
898 NULL, "encode end error", NULL, NULL );
904 for ( a = e->e_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
909 /* eventually will loop through generated operational attributes */
910 /* only have subschemaSubentry implemented */
911 aa = backend_operational( be, conn, op, e, attrs, opattrs );
913 for ( a = aa, i=0; a != NULL; a = a->a_next ) i++;
914 e_flags = ch_malloc ( i * sizeof(a_flags) );
916 for ( a = aa, i=0; a != NULL; a = a->a_next, i++ ) {
917 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ );
919 a_flags = ch_calloc ( j, sizeof(char) );
920 /* If no ValuesReturnFilter control return everything */
921 if ( op->vrFilter == NULL ){
922 memset(a_flags, 1, j);
924 e_flags[i] = a_flags;
927 if ( op->vrFilter != NULL ) {
928 rc = filter_matched_values(be, conn, op, aa, &e_flags) ;
932 LDAP_LOG( OPERATION, ERR,
933 "send_search_entry: conn %lu "
934 "matched values filtering failed\n",
935 conn ? conn->c_connid : 0, 0, 0);
937 Debug( LDAP_DEBUG_ANY,
938 "matched values filtering failed\n", 0, 0, 0 );
943 for ( a = aa, i=0; a != NULL; a = a->a_next, i++ ) {
948 send_ldap_result( conn, op, LDAP_OTHER,
949 NULL, "matched values filtering error",
955 for (a = aa, j=0; a != NULL; a = a->a_next, j++ ) {
956 AttributeDescription *desc = a->a_desc;
958 if ( attrs == NULL ) {
959 /* all attrs request, skip operational attributes */
960 if( is_at_operational( desc->ad_type ) ) {
965 /* specific attrs requested */
966 if( is_at_operational( desc->ad_type ) ) {
967 if( !opattrs && !ad_inlist( desc, attrs ) ) {
971 if (!userattrs && !ad_inlist( desc, attrs ) )
978 acl_state = acl_state_init;
980 if ( ! access_allowed( be, conn, op, e, desc, NULL,
981 ACL_READ, &acl_state ) )
985 "send_search_entry: conn %lu "
986 "access to attribute %s not allowed\n",
987 op->o_connid, desc->ad_cname.bv_val, 0 );
989 Debug( LDAP_DEBUG_ACL, "acl: access to attribute %s "
991 desc->ad_cname.bv_val, 0, 0 );
997 rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname );
1000 LDAP_LOG( OPERATION, ERR,
1001 "send_search_entry: conn %lu "
1002 "ber_printf failed\n", op->o_connid, 0, 0 );
1004 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1007 ber_free_buf( ber );
1008 send_ldap_result( conn, op, LDAP_OTHER,
1009 NULL, "encoding description error", NULL, NULL );
1011 for ( a = aa, i=0; a != NULL; a = a->a_next, i++ ) {
1020 if ( ! attrsonly ) {
1021 for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
1022 if ( ! access_allowed( be, conn, op, e,
1023 desc, &a->a_vals[i], ACL_READ, &acl_state ) )
1026 LDAP_LOG( ACL, INFO,
1027 "send_search_entry: conn %lu "
1028 "access to %s, value %d not allowed\n",
1029 op->o_connid, desc->ad_cname.bv_val, i );
1031 Debug( LDAP_DEBUG_ACL,
1032 "acl: access to attribute %s, "
1033 "value %d not allowed\n",
1034 desc->ad_cname.bv_val, i, 0 );
1040 if ( e_flags[j][i] == 0 ){
1044 if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
1046 LDAP_LOG( OPERATION, ERR,
1047 "send_search_entry: conn %lu ber_printf failed\n",
1048 op->o_connid, 0, 0 );
1050 Debug( LDAP_DEBUG_ANY,
1051 "ber_printf failed\n", 0, 0, 0 );
1054 ber_free_buf( ber );
1055 send_ldap_result( conn, op, LDAP_OTHER,
1056 NULL, "encoding values error",
1059 for ( a = aa, i=0; a != NULL; a = a->a_next, i++ ) {
1070 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
1072 LDAP_LOG( OPERATION, ERR,
1073 "send_search_entry: conn %lu ber_printf failed\n",
1074 op->o_connid, 0, 0 );
1076 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1079 ber_free_buf( ber );
1080 send_ldap_result( conn, op, LDAP_OTHER,
1081 NULL, "encode end error", NULL, NULL );
1083 for ( a = aa, i=0; a != NULL; a = a->a_next, i++ ) {
1094 for ( a = aa, i=0; a != NULL; a = a->a_next, i++ ) {
1100 rc = ber_printf( ber, /*{{{*/ "}N}N}" );
1102 #ifdef LDAP_CONNECTIONLESS
1103 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2 && rc != -1)
1104 rc = ber_printf( ber, "}" );
1108 LDAP_LOG( OPERATION, ERR,
1109 "send_search_entry: conn %lu ber_printf failed\n",
1110 op->o_connid, 0, 0 );
1112 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1115 ber_free_buf( ber );
1116 send_ldap_result( conn, op, LDAP_OTHER,
1117 NULL, "encode entry end error", NULL, NULL );
1121 bytes = send_ldap_ber( conn, ber );
1122 ber_free_buf( ber );
1126 LDAP_LOG( OPERATION, ERR,
1127 "send_search_entry: conn %lu ber write failed.\n",
1128 op->o_connid, 0, 0 );
1130 Debug( LDAP_DEBUG_ANY,
1131 "send_search_entry: ber write failed\n",
1138 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1139 num_bytes_sent += bytes;
1142 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1144 Statslog( LDAP_DEBUG_STATS2, "conn=%lu op=%lu ENTRY dn=\"%s\"\n",
1145 conn->c_connid, op->o_opid, e->e_dn, 0, 0 );
1148 LDAP_LOG( OPERATION, ENTRY,
1149 "send_search_entry: conn %lu exit.\n", op->o_connid, 0, 0 );
1151 Debug( LDAP_DEBUG_TRACE, "<= send_search_entry\n", 0, 0, 0 );
1161 send_search_reference(
1167 LDAPControl **ctrls,
1172 BerElement *ber = (BerElement *)berbuf;
1176 AttributeDescription *ad_ref = slap_schema.si_ad_ref;
1177 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
1180 LDAP_LOG( OPERATION, ENTRY,
1181 "send_search_reference: conn %lu dn=\"%s\"\n",
1182 op->o_connid, e->e_dn, 0 );
1184 Debug( LDAP_DEBUG_TRACE,
1185 "=> send_search_reference: dn=\"%s\"\n",
1190 if ( ! access_allowed( be, conn, op, e,
1191 ad_entry, NULL, ACL_READ, NULL ) )
1194 LDAP_LOG( ACL, INFO,
1195 "send_search_reference: conn %lu "
1196 "access to entry %s not allowed\n", op->o_connid, e->e_dn, 0 );
1198 Debug( LDAP_DEBUG_ACL,
1199 "send_search_reference: access to entry not allowed\n",
1206 if ( ! access_allowed( be, conn, op, e,
1207 ad_ref, NULL, ACL_READ, NULL ) )
1210 LDAP_LOG( ACL, INFO,
1211 "send_search_reference: conn %lu access "
1212 "to reference not allowed.\n", op->o_connid, 0, 0 );
1214 Debug( LDAP_DEBUG_ACL,
1215 "send_search_reference: access "
1216 "to reference not allowed\n",
1223 if( refs == NULL ) {
1225 LDAP_LOG( OPERATION, ERR,
1226 "send_search_reference: conn %lu null ref in (%s).\n",
1227 op->o_connid, e->e_dn, 0 );
1229 Debug( LDAP_DEBUG_ANY,
1230 "send_search_reference: null ref in (%s)\n",
1237 if( op->o_protocol < LDAP_VERSION3 ) {
1238 /* save the references for the result */
1239 if( refs[0].bv_val != NULL ) {
1240 value_add( v2refs, refs );
1245 ber_init_w_nullc( ber, LBER_USE_DER );
1247 rc = ber_printf( ber, "{it{W}N}", op->o_msgid,
1248 LDAP_RES_SEARCH_REFERENCE, refs );
1252 LDAP_LOG( OPERATION, ERR,
1253 "send_search_reference: conn %lu "
1254 "ber_printf failed.\n", op->o_connid, 0, 0 );
1256 Debug( LDAP_DEBUG_ANY,
1257 "send_search_reference: ber_printf failed\n", 0, 0, 0 );
1260 ber_free_buf( ber );
1261 send_ldap_result( conn, op, LDAP_OTHER,
1262 NULL, "encode DN error", NULL, NULL );
1266 bytes = send_ldap_ber( conn, ber );
1267 ber_free_buf( ber );
1269 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1270 num_bytes_sent += bytes;
1273 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1275 Statslog( LDAP_DEBUG_STATS2, "conn=%lu op=%lu REF dn=\"%s\"\n",
1276 conn->c_connid, op->o_opid, e->e_dn, 0, 0 );
1279 LDAP_LOG( OPERATION, ENTRY,
1280 "send_search_reference: conn %lu exit.\n", op->o_connid, 0, 0 );
1282 Debug( LDAP_DEBUG_TRACE, "<= send_search_reference\n", 0, 0, 0 );
1300 *code = LDAP_SUCCESS;
1304 if ( strncasecmp( s, "RESULT", 6 ) != 0 ) {
1306 LDAP_LOG( OPERATION, INFO,
1307 "str2result: (%s), expecting \"RESULT\"\n", s, 0, 0 );
1309 Debug( LDAP_DEBUG_ANY, "str2result (%s) expecting \"RESULT\"\n",
1317 while ( (s = strchr( s, '\n' )) != NULL ) {
1322 if ( (c = strchr( s, ':' )) != NULL ) {
1326 if ( strncasecmp( s, "code", 4 ) == 0 ) {
1330 } else if ( strncasecmp( s, "matched", 7 ) == 0 ) {
1334 } else if ( strncasecmp( s, "info", 4 ) == 0 ) {
1340 LDAP_LOG( OPERATION, INFO, "str2result: (%s) unknown.\n", s, 0, 0 );
1342 Debug( LDAP_DEBUG_ANY, "str2result (%s) unknown\n",