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 %d 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 %d msgid=%ld tag=%ld err=%ld\n",
202 conn ? conn->c_connid : 0, (long)msgid, (long)tag, (long)err ));
204 Debug( LDAP_DEBUG_TRACE,
205 "send_ldap_response: msgid=%ld tag=%ld err=%ld\n",
206 (long) msgid, (long) tag, (long) err );
211 LDAP_LOG(( "operation", LDAP_LEVEL_ARGS,
212 "send_ldap_response: conn %d 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 %d 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 %d 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 %d 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 %d %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=%ld op=%ld DISCONNECT tag=%lu err=%ld text=%s\n",
372 (long) op->o_connid, (long) op->o_opid,
373 (unsigned long) tag, (long) err, text ? text : "" );
391 assert( !LDAP_API_ERROR( err ) );
394 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
395 "send_ldap_result : conn %ld op=%ld p=%d\n",
396 (long)op->o_connid, (long)op->o_opid, op->o_protocol ));
398 Debug( LDAP_DEBUG_TRACE,
399 "send_ldap_result: conn=%ld op=%ld p=%d\n",
400 (long) op->o_connid, (long) op->o_opid, op->o_protocol );
404 LDAP_LOG(( "operation", LDAP_LEVEL_ARGS,
405 "send_ldap_result: conn=%ld err=%d matched=\"%s\" text=\"%s\"\n",
406 (long)op->o_connid, err, matched ? matched : "", text ? text : "" ));
408 Debug( LDAP_DEBUG_ARGS,
409 "send_ldap_result: err=%d matched=\"%s\" text=\"%s\"\n",
410 err, matched ? matched : "", text ? text : "" );
416 LDAP_LOG(( "operation", LDAP_LEVEL_ARGS,
417 "send_ldap_result: referral=\"%s\"\n",
418 ref[0].bv_val ? ref[0].bv_val : "NULL" ));
420 Debug( LDAP_DEBUG_ARGS,
421 "send_ldap_result: referral=\"%s\"\n",
422 ref[0].bv_val ? ref[0].bv_val : "NULL",
427 assert( err != LDAP_PARTIAL_RESULTS );
429 if ( err == LDAP_REFERRAL ) {
431 err = LDAP_NO_SUCH_OBJECT;
432 } else if ( op->o_protocol < LDAP_VERSION3 ) {
433 err = LDAP_PARTIAL_RESULTS;
437 if ( op->o_protocol < LDAP_VERSION3 ) {
438 tmp = v2ref( ref, text );
443 tag = req2res( op->o_tag );
444 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
446 send_ldap_response( conn, op, tag, msgid,
447 err, matched, text, ref,
448 NULL, NULL, NULL, ctrls );
450 Statslog( LDAP_DEBUG_STATS,
451 "conn=%ld op=%ld RESULT tag=%lu err=%ld text=%s\n",
452 (long) op->o_connid, (long) op->o_opid,
453 (unsigned long) tag, (long) err, text ? text : "" );
476 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
477 "send_ldap_sasl: conn %d err=%ld len=%ld\n",
478 op->o_connid, (long)err, cred ? cred->bv_len : -1 ));
480 Debug( LDAP_DEBUG_TRACE, "send_ldap_sasl: err=%ld len=%ld\n",
481 (long) err, cred ? cred->bv_len : -1, NULL );
485 tag = req2res( op->o_tag );
486 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
488 send_ldap_response( conn, op, tag, msgid,
489 err, matched, text, ref,
490 NULL, NULL, cred, ctrls );
502 struct berval *rspdata,
510 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
511 "send_ldap_extended: conn %d err=%ld oid=%s len=%ld\n",
512 op->o_connid, (long)err, rspoid ? rspoid : "",
513 rspdata != NULL ? (long)rspdata->bv_len : (long)0 ));
515 Debug( LDAP_DEBUG_TRACE,
516 "send_ldap_extended err=%ld oid=%s len=%ld\n",
518 rspoid ? rspoid : "",
519 rspdata != NULL ? (long) rspdata->bv_len : (long) 0 );
523 tag = req2res( op->o_tag );
524 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
526 send_ldap_response( conn, op, tag, msgid,
527 err, matched, text, refs,
528 rspoid, rspdata, NULL, ctrls );
548 assert( !LDAP_API_ERROR( err ) );
550 if (op->o_callback && op->o_callback->sc_sresult) {
551 op->o_callback->sc_sresult(conn, op, err, matched, text, refs,
557 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
558 "send_search_result: conn %d err=%d matched=\"%s\"\n",
559 op->o_connid, err, matched ? matched : "",
562 Debug( LDAP_DEBUG_TRACE,
563 "send_search_result: err=%d matched=\"%s\" text=\"%s\"\n",
564 err, matched ? matched : "", text ? text : "" );
568 assert( err != LDAP_PARTIAL_RESULTS );
570 if( op->o_protocol < LDAP_VERSION3 ) {
571 /* send references in search results */
572 if( err == LDAP_REFERRAL ) {
573 err = LDAP_PARTIAL_RESULTS;
576 tmp = v2ref( refs, text );
581 /* don't send references in search results */
582 assert( refs == NULL );
585 if( err == LDAP_REFERRAL ) {
590 tag = req2res( op->o_tag );
591 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
593 send_ldap_response( conn, op, tag, msgid,
594 err, matched, text, refs,
595 NULL, NULL, NULL, ctrls );
599 sprintf( nbuf, "%ld nentries=%d", (long) err, nentries );
601 Statslog( LDAP_DEBUG_STATS,
602 "conn=%ld op=%ld SEARCH RESULT tag=%lu err=%s text=%s\n",
603 (long) op->o_connid, (long) op->o_opid,
604 (unsigned long) tag, nbuf, text ? text : "" );
612 static struct berval AllUser = { sizeof(LDAP_ALL_USER_ATTRIBUTES)-1,
613 LDAP_ALL_USER_ATTRIBUTES };
614 static struct berval AllOper = { sizeof(LDAP_ALL_OPERATIONAL_ATTRIBUTES)-1,
615 LDAP_ALL_OPERATIONAL_ATTRIBUTES };
623 AttributeName *attrs,
629 BerElement *ber = (BerElement *)berbuf;
631 int i, j, rc=-1, bytes;
635 static AccessControlState acl_state_init = ACL_STATE_INIT;
636 AccessControlState acl_state;
638 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
640 /* a_flags: array of flags telling if the i-th element will be
641 * returned or filtered out
642 * e_flags: array of a_flags
644 char *a_flags, **e_flags;
646 if (op->o_callback && op->o_callback->sc_sendentry) {
647 return op->o_callback->sc_sendentry( be, conn, op, e, attrs,
652 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
653 "send_search_entry: conn %d dn=\"%s\"%s\n",
654 op->o_connid, e->e_dn,
655 attrsonly ? " (attrsOnly)" : "" ));
657 Debug( LDAP_DEBUG_TRACE,
658 "=> send_search_entry: dn=\"%s\"%s\n",
659 e->e_dn, attrsonly ? " (attrsOnly)" : "", 0 );
662 if ( ! access_allowed( be, conn, op, e,
663 ad_entry, NULL, ACL_READ, NULL ) )
666 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
667 "send_search_entry: conn %d access to entry (%s) not allowed\n",
668 op->o_connid, e->e_dn ));
670 Debug( LDAP_DEBUG_ACL,
671 "send_search_entry: access to entry not allowed\n",
680 ber_init_w_nullc( ber, LBER_USE_DER );
682 #ifdef LDAP_CONNECTIONLESS
683 if (conn->c_is_udp) {
684 rc = ber_write(ber, (char *)&op->o_peeraddr, sizeof(struct sockaddr), 0);
685 if (rc != sizeof(struct sockaddr)) {
687 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
688 "send_search_entry: conn %d ber_printf failed\n",
689 conn ? conn->c_connid : 0 ));
691 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
697 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2) {
698 rc = ber_printf( ber, "{is{t{O{" /*}}}*/,
699 op->o_msgid, "", LDAP_RES_SEARCH_ENTRY, &e->e_name );
703 rc = ber_printf( ber, "{it{O{" /*}}}*/, op->o_msgid,
704 LDAP_RES_SEARCH_ENTRY, &e->e_name );
709 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
710 "send_search_entry: conn %d ber_printf failed\n",
713 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
717 send_ldap_result( conn, op, LDAP_OTHER,
718 NULL, "encoding DN error", NULL, NULL );
722 /* check for special all user attributes ("*") type */
723 userattrs = ( attrs == NULL ) ? 1
724 : an_find( attrs, &AllUser );
726 /* check for special all operational attributes ("+") type */
727 opattrs = ( attrs == NULL ) ? 0
728 : an_find( attrs, &AllOper );
730 /* create an array of arrays of flags. Each flag corresponds
731 * to particular value of attribute an equals 1 if value matches
732 * to ValuesReturnFilter or 0 if not
734 for ( a = e->e_attrs; a != NULL; a = a->a_next ) i++;
735 e_flags = ch_malloc ( i * sizeof(a_flags) );
737 for ( a = e->e_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
738 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);
745 e_flags[i] = a_flags;
748 if ( op->vrFilter != NULL ){
750 rc = filter_matched_values(be, conn, op, e, &e_flags) ;
754 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
755 "send_search_entry: conn %d matched values fitering failed\n",
756 conn ? conn->c_connid : 0 ));
758 Debug( LDAP_DEBUG_ANY,
759 "matched values fitering 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 fitering error", NULL, NULL );
775 for ( a = e->e_attrs, j = 0; a != NULL; a = a->a_next, j++ ) {
776 AttributeDescription *desc = a->a_desc;
778 if ( attrs == NULL ) {
779 /* all attrs request, skip operational attributes */
780 if( is_at_operational( desc->ad_type ) ) {
785 /* specific attrs requested */
786 if ( is_at_operational( desc->ad_type ) ) {
787 if( !opattrs && !ad_inlist( desc, attrs ) ) {
792 if (!userattrs && !ad_inlist( desc, attrs ) ) {
798 acl_state = acl_state_init;
800 if ( ! access_allowed( be, conn, op, e, desc, NULL,
801 ACL_READ, &acl_state ) )
804 LDAP_LOG(( "acl", LDAP_LEVEL_INFO, "send_search_entry: "
805 "conn %d access to attribute %s not allowed\n",
806 op->o_connid, desc->ad_cname.bv_val ));
808 Debug( LDAP_DEBUG_ACL, "acl: "
809 "access to attribute %s not allowed\n",
810 desc->ad_cname.bv_val, 0, 0 );
815 if (( rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname )) == -1 ) {
817 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
818 "send_search_entry: conn %d ber_printf failed\n",
821 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
826 for ( a = e->e_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
830 send_ldap_result( conn, op, LDAP_OTHER,
831 NULL, "encoding description error", NULL, NULL );
836 for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
837 if ( ! access_allowed( be, conn, op, e,
838 desc, &a->a_vals[i], ACL_READ, &acl_state ) )
841 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
842 "send_search_entry: conn %d "
843 "access to attribute %s, value %d not allowed\n",
844 op->o_connid, desc->ad_cname.bv_val, i ));
846 Debug( LDAP_DEBUG_ACL,
847 "acl: access to attribute %s, 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", LDAP_LEVEL_ERR,
861 "send_search_entry: conn %d ber_printf failed.\n",
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", NULL, NULL );
881 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
883 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
884 "send_search_entry: conn %d ber_printf failed\n",
887 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
892 for ( a = e->e_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
896 send_ldap_result( conn, op, LDAP_OTHER,
897 NULL, "encode end error", NULL, NULL );
903 for ( a = e->e_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
908 /* eventually will loop through generated operational attributes */
909 /* only have subschemaSubentry implemented */
910 aa = backend_operational( be, conn, op, e, attrs, opattrs );
912 for (a = aa ; a != NULL; a = a->a_next ) {
913 AttributeDescription *desc = a->a_desc;
915 if ( attrs == NULL ) {
916 /* all attrs request, skip operational attributes */
917 if( is_at_operational( desc->ad_type ) ) {
922 /* specific attrs requested */
923 if( is_at_operational( desc->ad_type ) ) {
924 if( !opattrs && !ad_inlist( desc, attrs ) ) {
928 if (!userattrs && !ad_inlist( desc, attrs ) )
935 acl_state = acl_state_init;
937 if ( ! access_allowed( be, conn, op, e, desc, NULL,
938 ACL_READ, &acl_state ) )
941 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
942 "send_search_entry: conn %s "
943 "access to attribute %s not allowed\n",
944 op->o_connid, desc->ad_cname.bv_val ));
946 Debug( LDAP_DEBUG_ACL, "acl: access to attribute %s not allowed\n",
947 desc->ad_cname.bv_val, 0, 0 );
953 rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname );
956 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
957 "send_search_entry: conn %d ber_printf failed\n",
960 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
964 send_ldap_result( conn, op, LDAP_OTHER,
965 NULL, "encoding description error", NULL, NULL );
971 for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
972 if ( ! access_allowed( be, conn, op, e,
973 desc, &a->a_vals[i], ACL_READ, &acl_state ) )
976 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
977 "send_search_entry: conn %d "
978 "access to %s, value %d not allowed\n",
979 op->o_connid, desc->ad_cname.bv_val, i ));
981 Debug( LDAP_DEBUG_ACL,
982 "acl: access to attribute %s, value %d not allowed\n",
983 desc->ad_cname.bv_val, i, 0 );
989 if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
991 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
992 "send_search_entry: conn %d ber_printf failed\n",
995 Debug( LDAP_DEBUG_ANY,
996 "ber_printf failed\n", 0, 0, 0 );
1000 send_ldap_result( conn, op, LDAP_OTHER,
1001 NULL, "encoding values error", NULL, NULL );
1008 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
1010 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1011 "send_search_entry: conn %d 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, "encode end error", NULL, NULL );
1027 rc = ber_printf( ber, /*{{{*/ "}N}N}" );
1029 #ifdef LDAP_CONNECTIONLESS
1030 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2 && rc != -1)
1031 rc = ber_printf( ber, "}" );
1035 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1036 "send_search_entry: conn %d ber_printf failed\n",
1039 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1042 ber_free_buf( ber );
1043 send_ldap_result( conn, op, LDAP_OTHER,
1044 NULL, "encode entry end error", NULL, NULL );
1048 bytes = send_ldap_ber( conn, ber );
1049 ber_free_buf( ber );
1053 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1054 "send_ldap_response: conn %d ber write failed.\n",
1057 Debug( LDAP_DEBUG_ANY,
1058 "send_ldap_response: ber write failed\n",
1065 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1066 num_bytes_sent += bytes;
1069 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1071 Statslog( LDAP_DEBUG_STATS2, "conn=%ld op=%ld ENTRY dn=\"%s\"\n",
1072 (long) conn->c_connid, (long) op->o_opid, e->e_dn, 0, 0 );
1075 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1076 "send_search_entry: conn %d exit.\n",
1079 Debug( LDAP_DEBUG_TRACE, "<= send_search_entry\n", 0, 0, 0 );
1089 send_search_reference(
1095 LDAPControl **ctrls,
1100 BerElement *ber = (BerElement *)berbuf;
1104 AttributeDescription *ad_ref = slap_schema.si_ad_ref;
1105 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
1108 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1109 "send_search_reference: conn %d dn=\"%s\"\n",
1110 op->o_connid, e->e_dn ));
1112 Debug( LDAP_DEBUG_TRACE,
1113 "=> send_search_reference: dn=\"%s\"\n",
1118 if ( ! access_allowed( be, conn, op, e,
1119 ad_entry, NULL, ACL_READ, NULL ) )
1122 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
1123 "send_search_reference: conn %d access to entry %s not allowed\n",
1124 op->o_connid, e->e_dn ));
1126 Debug( LDAP_DEBUG_ACL,
1127 "send_search_reference: access to entry not allowed\n",
1134 if ( ! access_allowed( be, conn, op, e,
1135 ad_ref, NULL, ACL_READ, NULL ) )
1138 LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
1139 "send_search_reference: conn %d access to reference not allowed.\n",
1142 Debug( LDAP_DEBUG_ACL,
1143 "send_search_reference: access to reference not allowed\n",
1150 if( refs == NULL ) {
1152 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1153 "send_search_reference: null ref in (%s).\n",
1154 op->o_connid, e->e_dn ));
1156 Debug( LDAP_DEBUG_ANY,
1157 "send_search_reference: null ref in (%s)\n",
1164 if( op->o_protocol < LDAP_VERSION3 ) {
1165 /* save the references for the result */
1166 if( refs[0].bv_val != NULL ) {
1167 value_add( v2refs, refs );
1172 ber_init_w_nullc( ber, LBER_USE_DER );
1174 rc = ber_printf( ber, "{it{W}N}", op->o_msgid,
1175 LDAP_RES_SEARCH_REFERENCE, refs );
1179 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
1180 "send_search_reference: conn %d ber_printf failed.\n",
1183 Debug( LDAP_DEBUG_ANY,
1184 "send_search_reference: ber_printf failed\n", 0, 0, 0 );
1187 ber_free_buf( ber );
1188 send_ldap_result( conn, op, LDAP_OTHER,
1189 NULL, "encode DN error", NULL, NULL );
1193 bytes = send_ldap_ber( conn, ber );
1194 ber_free_buf( ber );
1196 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1197 num_bytes_sent += bytes;
1200 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1202 Statslog( LDAP_DEBUG_STATS2, "conn=%ld op=%ld REF dn=\"%s\"\n",
1203 (long) conn->c_connid, (long) op->o_opid, e->e_dn, 0, 0 );
1206 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
1207 "send_search_reference: conn %d exit.\n", op->o_connid ));
1209 Debug( LDAP_DEBUG_TRACE, "<= send_search_reference\n", 0, 0, 0 );
1227 *code = LDAP_SUCCESS;
1231 if ( strncasecmp( s, "RESULT", 6 ) != 0 ) {
1233 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
1234 "str2result: (%s), expecting \"RESULT\"\n", s ));
1236 Debug( LDAP_DEBUG_ANY, "str2result (%s) expecting \"RESULT\"\n",
1245 while ( (s = strchr( s, '\n' )) != NULL ) {
1250 if ( (c = strchr( s, ':' )) != NULL ) {
1254 if ( strncasecmp( s, "code", 4 ) == 0 ) {
1258 } else if ( strncasecmp( s, "matched", 7 ) == 0 ) {
1262 } else if ( strncasecmp( s, "info", 4 ) == 0 ) {
1268 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
1269 "str2result: (%s) unknown.\n", s ));
1271 Debug( LDAP_DEBUG_ANY, "str2result (%s) unknown\n",