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 );
169 send_ldap_controls( BerElement *ber, LDAPControl **c )
172 if( c == NULL ) return 0;
174 rc = ber_printf( ber, "t{"/*}*/, LDAP_TAG_CONTROLS );
175 if( rc == -1 ) return rc;
177 for( ; *c != NULL; c++) {
178 rc = ber_printf( ber, "{s" /*}*/, (*c)->ldctl_oid );
180 if( (*c)->ldctl_iscritical ) {
181 rc = ber_printf( ber, "b",
182 (ber_int_t) (*c)->ldctl_iscritical ) ;
183 if( rc == -1 ) return rc;
186 if( (*c)->ldctl_value.bv_val != NULL ) {
187 rc = ber_printf( ber, "O", &((*c)->ldctl_value));
188 if( rc == -1 ) return rc;
191 rc = ber_printf( ber, /*{*/"N}" );
192 if( rc == -1 ) return rc;
195 rc = ber_printf( ber, /*{*/"N}" );
211 struct berval *resdata,
212 struct berval *sasldata,
217 BerElement *ber = (BerElement *)berbuf;
221 if (op->o_callback && op->o_callback->sc_response) {
222 op->o_callback->sc_response( conn, op, tag, msgid, err, matched,
223 text, ref, resoid, resdata, sasldata, ctrls );
227 assert( ctrls == NULL ); /* ctrls not implemented */
229 ber_init_w_nullc( ber, LBER_USE_DER );
232 LDAP_LOG( OPERATION, ENTRY,
233 "send_ldap_response: msgid=%d tag=%lu err=%d\n",
236 Debug( LDAP_DEBUG_TRACE,
237 "send_ldap_response: msgid=%d tag=%lu err=%d\n",
243 LDAP_LOG( OPERATION, ARGS,
244 "send_ldap_response: conn %lu ref=\"%s\"\n",
245 conn ? conn->c_connid : 0,
246 ref[0].bv_val ? ref[0].bv_val : "NULL" , 0 );
248 Debug( LDAP_DEBUG_ARGS, "send_ldap_response: ref=\"%s\"\n",
249 ref[0].bv_val ? ref[0].bv_val : "NULL",
254 #ifdef LDAP_CONNECTIONLESS
255 if (conn->c_is_udp) {
256 rc = ber_write(ber, (char *)&op->o_peeraddr, sizeof(struct sockaddr), 0);
257 if (rc != sizeof(struct sockaddr)) {
259 LDAP_LOG( OPERATION, ERR,
260 "send_ldap_response: conn %lu ber_write failed\n",
261 conn ? conn->c_connid : 0 , 0, 0);
263 Debug( LDAP_DEBUG_ANY, "ber_write failed\n", 0, 0, 0 );
269 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2) {
270 rc = ber_printf( ber, "{is{t{ess" /*"}}}"*/,
272 matched == NULL ? "" : matched,
273 text == NULL ? "" : text );
277 rc = ber_printf( ber, "{it{ess" /*"}}"*/,
279 matched == NULL ? "" : matched,
280 text == NULL ? "" : text );
285 assert( err == LDAP_REFERRAL );
286 rc = ber_printf( ber, "t{W}",
287 LDAP_TAG_REFERRAL, ref );
289 assert( err != LDAP_REFERRAL );
293 if( rc != -1 && sasldata != NULL ) {
294 rc = ber_printf( ber, "tO",
295 LDAP_TAG_SASL_RES_CREDS, sasldata );
298 if( rc != -1 && resoid != NULL ) {
299 rc = ber_printf( ber, "ts",
300 LDAP_TAG_EXOP_RES_OID, resoid );
303 if( rc != -1 && resdata != NULL ) {
304 rc = ber_printf( ber, "tO",
305 LDAP_TAG_EXOP_RES_VALUE, resdata );
309 rc = ber_printf( ber, /*"{"*/ "N}" );
312 if( rc != -1 && ctrls != NULL ) {
313 rc = send_ldap_controls( ber, ctrls );
317 rc = ber_printf( ber, /*"{"*/ "N}" );
320 #ifdef LDAP_CONNECTIONLESS
321 if( conn->c_is_udp && op->o_protocol == LDAP_VERSION2 && rc != -1 ) {
322 rc = ber_printf( ber, /*"{"*/ "N}" );
328 LDAP_LOG( OPERATION, ERR,
329 "send_ldap_response: conn %lu ber_printf failed\n",
330 conn ? conn->c_connid : 0, 0, 0 );
332 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
340 bytes = send_ldap_ber( conn, ber );
345 LDAP_LOG( OPERATION, ERR,
346 "send_ldap_response: conn %lu ber write failed\n",
347 conn ? conn->c_connid : 0, 0, 0 );
349 Debug( LDAP_DEBUG_ANY,
350 "send_ldap_response: ber write failed\n",
357 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
358 num_bytes_sent += bytes;
360 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
366 send_ldap_disconnect(
377 #define LDAP_UNSOLICITED_ERROR(e) \
378 ( (e) == LDAP_PROTOCOL_ERROR \
379 || (e) == LDAP_STRONG_AUTH_REQUIRED \
380 || (e) == LDAP_UNAVAILABLE )
382 assert( LDAP_UNSOLICITED_ERROR( err ) );
385 LDAP_LOG( OPERATION, ENTRY,
386 "send_ldap_disconnect: conn %lu %d:%s\n",
387 conn ? conn->c_connid : 0, err, text ? text : "" );
389 Debug( LDAP_DEBUG_TRACE,
390 "send_ldap_disconnect %d:%s\n",
391 err, text ? text : "", NULL );
395 if ( op->o_protocol < LDAP_VERSION3 ) {
397 tag = req2res( op->o_tag );
398 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
401 reqoid = LDAP_NOTICE_DISCONNECT;
402 tag = LDAP_RES_EXTENDED;
406 send_ldap_response( conn, op, tag, msgid,
407 err, NULL, text, NULL,
408 reqoid, NULL, NULL, NULL );
410 Statslog( LDAP_DEBUG_STATS,
411 "conn=%lu op=%lu DISCONNECT tag=%lu err=%d text=%s\n",
412 op->o_connid, op->o_opid, tag, err, text ? text : "" );
430 assert( !LDAP_API_ERROR( err ) );
433 LDAP_LOG( OPERATION, ENTRY,
434 "send_ldap_result : conn %lu op=%lu p=%d\n",
435 op->o_connid, op->o_opid, op->o_protocol );
437 Debug( LDAP_DEBUG_TRACE,
438 "send_ldap_result: conn=%lu op=%lu p=%d\n",
439 op->o_connid, op->o_opid, op->o_protocol );
443 LDAP_LOG( OPERATION, ARGS,
444 "send_ldap_result: err=%d matched=\"%s\" text=\"%s\"\n",
445 err, matched ? matched : "", text ? text : "" );
447 Debug( LDAP_DEBUG_ARGS,
448 "send_ldap_result: err=%d matched=\"%s\" text=\"%s\"\n",
449 err, matched ? matched : "", text ? text : "" );
455 LDAP_LOG( OPERATION, ARGS,
456 "send_ldap_result: referral=\"%s\"\n",
457 ref[0].bv_val ? ref[0].bv_val : "NULL", 0, 0 );
459 Debug( LDAP_DEBUG_ARGS,
460 "send_ldap_result: referral=\"%s\"\n",
461 ref[0].bv_val ? ref[0].bv_val : "NULL",
466 assert( err != LDAP_PARTIAL_RESULTS );
468 if ( err == LDAP_REFERRAL ) {
470 err = LDAP_NO_SUCH_OBJECT;
471 } else if ( op->o_protocol < LDAP_VERSION3 ) {
472 err = LDAP_PARTIAL_RESULTS;
476 if ( op->o_protocol < LDAP_VERSION3 ) {
477 tmp = v2ref( ref, text );
482 tag = req2res( op->o_tag );
483 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
485 send_ldap_response( conn, op, tag, msgid,
486 err, matched, text, ref,
487 NULL, NULL, NULL, ctrls );
489 Statslog( LDAP_DEBUG_STATS,
490 "conn=%lu op=%lu RESULT tag=%lu err=%d text=%s\n",
491 op->o_connid, op->o_opid, tag, err, text ? text : "" );
514 LDAP_LOG( OPERATION, ENTRY,
515 "send_ldap_sasl: conn %lu err=%d len=%lu\n",
516 op->o_connid, err, cred ? cred->bv_len : -1 );
518 Debug( LDAP_DEBUG_TRACE, "send_ldap_sasl: err=%d len=%ld\n",
519 err, cred ? (long) cred->bv_len : -1, NULL );
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, ref,
528 NULL, NULL, cred, ctrls );
540 struct berval *rspdata,
548 LDAP_LOG( OPERATION, ENTRY,
549 "send_ldap_extended: err=%d oid=%s len=%ld\n",
550 err, rspoid ? rspoid : "",
551 rspdata != NULL ? rspdata->bv_len : 0 );
553 Debug( LDAP_DEBUG_TRACE,
554 "send_ldap_extended err=%d oid=%s len=%ld\n",
556 rspoid ? rspoid : "",
557 rspdata != NULL ? rspdata->bv_len : 0 );
561 tag = req2res( op->o_tag );
562 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
564 send_ldap_response( conn, op, tag, msgid,
565 err, matched, text, refs,
566 rspoid, rspdata, NULL, ctrls );
586 assert( !LDAP_API_ERROR( err ) );
588 if (op->o_callback && op->o_callback->sc_sresult) {
589 op->o_callback->sc_sresult(conn, op, err, matched, text, refs,
595 LDAP_LOG( OPERATION, ENTRY,
596 "send_search_result: err=%d matched=\"%s\" text=\"%s\"\n",
597 err, matched ? matched : "", text ? text : "" );
599 Debug( LDAP_DEBUG_TRACE,
600 "send_search_result: err=%d matched=\"%s\" text=\"%s\"\n",
601 err, matched ? matched : "", text ? text : "" );
605 assert( err != LDAP_PARTIAL_RESULTS );
607 if( op->o_protocol < LDAP_VERSION3 ) {
608 /* send references in search results */
609 if( err == LDAP_REFERRAL ) {
610 err = LDAP_PARTIAL_RESULTS;
613 tmp = v2ref( refs, text );
618 /* don't send references in search results */
619 assert( refs == NULL );
622 if( err == LDAP_REFERRAL ) {
627 tag = req2res( op->o_tag );
628 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
630 send_ldap_response( conn, op, tag, msgid,
631 err, matched, text, refs,
632 NULL, NULL, NULL, ctrls );
636 snprintf( nbuf, sizeof nbuf, "%d nentries=%d", err, nentries );
638 Statslog( LDAP_DEBUG_STATS,
639 "conn=%lu op=%lu SEARCH RESULT tag=%lu err=%s text=%s\n",
640 op->o_connid, op->o_opid, tag, nbuf, text ? text : "" );
648 static struct berval AllUser = { sizeof(LDAP_ALL_USER_ATTRIBUTES)-1,
649 LDAP_ALL_USER_ATTRIBUTES };
650 static struct berval AllOper = { sizeof(LDAP_ALL_OPERATIONAL_ATTRIBUTES)-1,
651 LDAP_ALL_OPERATIONAL_ATTRIBUTES };
659 AttributeName *attrs,
665 BerElement *ber = (BerElement *)berbuf;
667 int i, j, rc=-1, bytes;
671 static AccessControlState acl_state_init = ACL_STATE_INIT;
672 AccessControlState acl_state;
674 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
676 /* a_flags: array of flags telling if the i-th element will be
677 * returned or filtered out
678 * e_flags: array of a_flags
680 char **e_flags = NULL;
682 if (op->o_callback && op->o_callback->sc_sendentry) {
683 return op->o_callback->sc_sendentry( be, conn, op, e, attrs,
688 LDAP_LOG( OPERATION, ENTRY,
689 "send_search_entry: conn %lu dn=\"%s\"%s\n",
690 op->o_connid, e->e_dn, attrsonly ? " (attrsOnly)" : "" );
692 Debug( LDAP_DEBUG_TRACE,
693 "=> send_search_entry: dn=\"%s\"%s\n",
694 e->e_dn, attrsonly ? " (attrsOnly)" : "", 0 );
697 if ( ! access_allowed( be, conn, op, e,
698 ad_entry, NULL, ACL_READ, NULL ) )
702 "send_search_entry: conn %lu access to entry (%s) not allowed\n",
703 op->o_connid, e->e_dn, 0 );
705 Debug( LDAP_DEBUG_ACL,
706 "send_search_entry: access to entry not allowed\n",
715 ber_init_w_nullc( ber, LBER_USE_DER );
717 #ifdef LDAP_CONNECTIONLESS
718 if (conn->c_is_udp) {
719 rc = ber_write(ber, (char *)&op->o_peeraddr, sizeof(struct sockaddr), 0);
720 if (rc != sizeof(struct sockaddr)) {
722 LDAP_LOG( OPERATION, ERR,
723 "send_search_entry: conn %lu ber_printf failed\n",
724 conn ? conn->c_connid : 0, 0, 0 );
726 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
732 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2) {
733 rc = ber_printf( ber, "{is{t{O{" /*}}}*/,
734 op->o_msgid, "", LDAP_RES_SEARCH_ENTRY, &e->e_name );
736 #endif /* LDAP_CONNECTIONLESS */
738 rc = ber_printf( ber, "{it{O{" /*}}}*/, op->o_msgid,
739 LDAP_RES_SEARCH_ENTRY, &e->e_name );
744 LDAP_LOG( OPERATION, ERR,
745 "send_search_entry: conn %lu ber_printf failed\n",
746 op->o_connid, 0, 0 );
748 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
752 send_ldap_result( conn, op, LDAP_OTHER,
753 NULL, "encoding DN error", NULL, NULL );
757 /* check for special all user attributes ("*") type */
758 userattrs = ( attrs == NULL ) ? 1
759 : an_find( attrs, &AllUser );
761 /* check for special all operational attributes ("+") type */
762 opattrs = ( attrs == NULL ) ? 0
763 : an_find( attrs, &AllOper );
765 /* create an array of arrays of flags. Each flag corresponds
766 * to particular value of attribute and equals 1 if value matches
767 * to ValuesReturnFilter or 0 if not
769 if ( op->vrFilter != NULL ) {
773 for ( a = e->e_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
774 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ ) k++;
776 e_flags = ch_calloc ( 1, i * sizeof(char *) + k );
777 a_flags = (char *)(e_flags + i);
778 for ( a = e->e_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
779 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ );
780 e_flags[i] = a_flags;
784 rc = filter_matched_values(be, conn, op, e->e_attrs, &e_flags) ;
787 LDAP_LOG( OPERATION, ERR,
788 "send_search_entry: conn %lu matched values filtering failed\n",
789 conn ? conn->c_connid : 0, 0, 0 );
791 Debug( LDAP_DEBUG_ANY,
792 "matched values filtering failed\n", 0, 0, 0 );
796 send_ldap_result( conn, op, LDAP_OTHER,
797 NULL, "matched values filtering error",
803 for ( a = e->e_attrs, j = 0; a != NULL; a = a->a_next, j++ ) {
804 AttributeDescription *desc = a->a_desc;
806 if ( attrs == NULL ) {
807 /* all attrs request, skip operational attributes */
808 if( is_at_operational( desc->ad_type ) ) {
813 /* specific attrs requested */
814 if ( is_at_operational( desc->ad_type ) ) {
815 if( !opattrs && !ad_inlist( desc, attrs ) ) {
820 if (!userattrs && !ad_inlist( desc, attrs ) ) {
826 acl_state = acl_state_init;
828 if ( ! access_allowed( be, conn, op, e, desc, NULL,
829 ACL_READ, &acl_state ) )
833 "send_search_entry: conn %lu access to attribute %s not "
834 "allowed\n", op->o_connid, desc->ad_cname.bv_val, 0 );
836 Debug( LDAP_DEBUG_ACL, "acl: "
837 "access to attribute %s not allowed\n",
838 desc->ad_cname.bv_val, 0, 0 );
843 if (( rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname )) == -1 ) {
845 LDAP_LOG( OPERATION, ERR,
846 "send_search_entry: conn %lu ber_printf failed\n",
847 op->o_connid, 0, 0 );
849 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
853 send_ldap_result( conn, op, LDAP_OTHER,
854 NULL, "encoding description error", NULL, NULL );
859 for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
860 if ( ! access_allowed( be, conn, op, e,
861 desc, &a->a_vals[i], ACL_READ, &acl_state ) )
865 "send_search_entry: conn %lu "
866 "access to attribute %s, value %d not allowed\n",
867 op->o_connid, desc->ad_cname.bv_val, i );
869 Debug( LDAP_DEBUG_ACL,
870 "acl: access to attribute %s, "
871 "value %d not allowed\n",
872 desc->ad_cname.bv_val, i, 0 );
878 if ( op->vrFilter && e_flags[j][i] == 0 ){
882 if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
884 LDAP_LOG( OPERATION, ERR,
885 "send_search_entry: conn %lu "
886 "ber_printf failed.\n", op->o_connid, 0, 0 );
888 Debug( LDAP_DEBUG_ANY,
889 "ber_printf failed\n", 0, 0, 0 );
893 send_ldap_result( conn, op, LDAP_OTHER,
894 NULL, "encoding values error",
901 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
903 LDAP_LOG( OPERATION, ERR,
904 "send_search_entry: conn %lu ber_printf failed\n",
905 op->o_connid, 0, 0 );
907 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
911 send_ldap_result( conn, op, LDAP_OTHER,
912 NULL, "encode end error", NULL, NULL );
923 /* eventually will loop through generated operational attributes */
924 /* only have subschemaSubentry implemented */
925 aa = backend_operational( be, conn, op, e, attrs, opattrs );
927 if ( aa != NULL && op->vrFilter != NULL ) {
931 for ( a = aa, i=0; a != NULL; a = a->a_next, i++ ) {
932 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ ) k++;
934 e_flags = ch_calloc ( 1, i * sizeof(char *) + k );
935 a_flags = (char *)(e_flags + i);
936 for ( a = e->e_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
937 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ );
938 e_flags[i] = a_flags;
941 rc = filter_matched_values(be, conn, op, aa, &e_flags) ;
945 LDAP_LOG( OPERATION, ERR,
946 "send_search_entry: conn %lu "
947 "matched values filtering failed\n",
948 conn ? conn->c_connid : 0, 0, 0);
950 Debug( LDAP_DEBUG_ANY,
951 "matched values filtering failed\n", 0, 0, 0 );
955 send_ldap_result( conn, op, LDAP_OTHER,
956 NULL, "matched values filtering error",
962 for (a = aa, j=0; a != NULL; a = a->a_next, j++ ) {
963 AttributeDescription *desc = a->a_desc;
965 if ( attrs == NULL ) {
966 /* all attrs request, skip operational attributes */
967 if( is_at_operational( desc->ad_type ) ) {
972 /* specific attrs requested */
973 if( is_at_operational( desc->ad_type ) ) {
974 if( !opattrs && !ad_inlist( desc, attrs ) ) {
978 if (!userattrs && !ad_inlist( desc, attrs ) )
985 acl_state = acl_state_init;
987 if ( ! access_allowed( be, conn, op, e, desc, NULL,
988 ACL_READ, &acl_state ) )
992 "send_search_entry: conn %lu "
993 "access to attribute %s not allowed\n",
994 op->o_connid, desc->ad_cname.bv_val, 0 );
996 Debug( LDAP_DEBUG_ACL, "acl: access to attribute %s "
998 desc->ad_cname.bv_val, 0, 0 );
1004 rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname );
1007 LDAP_LOG( OPERATION, ERR,
1008 "send_search_entry: conn %lu "
1009 "ber_printf failed\n", op->o_connid, 0, 0 );
1011 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1014 ber_free_buf( ber );
1015 send_ldap_result( conn, op, LDAP_OTHER,
1016 NULL, "encoding description error", NULL, NULL );
1022 if ( ! attrsonly ) {
1023 for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
1024 if ( ! access_allowed( be, conn, op, e,
1025 desc, &a->a_vals[i], ACL_READ, &acl_state ) )
1028 LDAP_LOG( ACL, INFO,
1029 "send_search_entry: conn %lu "
1030 "access to %s, value %d not allowed\n",
1031 op->o_connid, desc->ad_cname.bv_val, i );
1033 Debug( LDAP_DEBUG_ACL,
1034 "acl: access to attribute %s, "
1035 "value %d not allowed\n",
1036 desc->ad_cname.bv_val, i, 0 );
1042 if ( op->vrFilter && e_flags[j][i] == 0 ){
1046 if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
1048 LDAP_LOG( OPERATION, ERR,
1049 "send_search_entry: conn %lu ber_printf failed\n",
1050 op->o_connid, 0, 0 );
1052 Debug( LDAP_DEBUG_ANY,
1053 "ber_printf failed\n", 0, 0, 0 );
1056 ber_free_buf( ber );
1057 send_ldap_result( conn, op, LDAP_OTHER,
1058 NULL, "encoding values error",
1067 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
1069 LDAP_LOG( OPERATION, ERR,
1070 "send_search_entry: conn %lu ber_printf failed\n",
1071 op->o_connid, 0, 0 );
1073 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1076 ber_free_buf( ber );
1077 send_ldap_result( conn, op, LDAP_OTHER,
1078 NULL, "encode end error", NULL, NULL );
1092 rc = ber_printf( ber, /*{{*/ "}N}" );
1094 if( rc != -1 && ctrls != NULL ) {
1095 rc = send_ldap_controls( ber, ctrls );
1099 rc = ber_printf( ber, /*{*/ "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 );
1157 if ( e_flags ) free( e_flags );
1162 send_search_reference(
1168 LDAPControl **ctrls,
1173 BerElement *ber = (BerElement *)berbuf;
1177 AttributeDescription *ad_ref = slap_schema.si_ad_ref;
1178 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
1181 LDAP_LOG( OPERATION, ENTRY,
1182 "send_search_reference: conn %lu dn=\"%s\"\n",
1183 op->o_connid, e->e_dn, 0 );
1185 Debug( LDAP_DEBUG_TRACE,
1186 "=> send_search_reference: dn=\"%s\"\n",
1191 if ( ! access_allowed( be, conn, op, e,
1192 ad_entry, NULL, ACL_READ, NULL ) )
1195 LDAP_LOG( ACL, INFO,
1196 "send_search_reference: conn %lu "
1197 "access to entry %s not allowed\n", op->o_connid, e->e_dn, 0 );
1199 Debug( LDAP_DEBUG_ACL,
1200 "send_search_reference: access to entry not allowed\n",
1207 if ( ! access_allowed( be, conn, op, e,
1208 ad_ref, NULL, ACL_READ, NULL ) )
1211 LDAP_LOG( ACL, INFO,
1212 "send_search_reference: conn %lu access "
1213 "to reference not allowed.\n", op->o_connid, 0, 0 );
1215 Debug( LDAP_DEBUG_ACL,
1216 "send_search_reference: access "
1217 "to reference not allowed\n",
1224 if( refs == NULL ) {
1226 LDAP_LOG( OPERATION, ERR,
1227 "send_search_reference: conn %lu null ref in (%s).\n",
1228 op->o_connid, e->e_dn, 0 );
1230 Debug( LDAP_DEBUG_ANY,
1231 "send_search_reference: null ref in (%s)\n",
1238 if( op->o_protocol < LDAP_VERSION3 ) {
1239 /* save the references for the result */
1240 if( refs[0].bv_val != NULL ) {
1241 value_add( v2refs, refs );
1246 ber_init_w_nullc( ber, LBER_USE_DER );
1248 rc = ber_printf( ber, "{it{W}" /*"}"*/ , op->o_msgid,
1249 LDAP_RES_SEARCH_REFERENCE, refs );
1251 if( rc != -1 && ctrls != NULL ) {
1252 rc = send_ldap_controls( ber, ctrls );
1256 rc = ber_printf( ber, /*"{"*/ "N}", op->o_msgid,
1257 LDAP_RES_SEARCH_REFERENCE, refs );
1262 LDAP_LOG( OPERATION, ERR,
1263 "send_search_reference: conn %lu "
1264 "ber_printf failed.\n", op->o_connid, 0, 0 );
1266 Debug( LDAP_DEBUG_ANY,
1267 "send_search_reference: ber_printf failed\n", 0, 0, 0 );
1270 ber_free_buf( ber );
1271 send_ldap_result( conn, op, LDAP_OTHER,
1272 NULL, "encode DN error", NULL, NULL );
1276 bytes = send_ldap_ber( conn, ber );
1277 ber_free_buf( ber );
1279 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1280 num_bytes_sent += bytes;
1283 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1285 Statslog( LDAP_DEBUG_STATS2, "conn=%lu op=%lu REF dn=\"%s\"\n",
1286 conn->c_connid, op->o_opid, e->e_dn, 0, 0 );
1289 LDAP_LOG( OPERATION, ENTRY,
1290 "send_search_reference: conn %lu exit.\n", op->o_connid, 0, 0 );
1292 Debug( LDAP_DEBUG_TRACE, "<= send_search_reference\n", 0, 0, 0 );
1310 *code = LDAP_SUCCESS;
1314 if ( strncasecmp( s, "RESULT", 6 ) != 0 ) {
1316 LDAP_LOG( OPERATION, INFO,
1317 "str2result: (%s), expecting \"RESULT\"\n", s, 0, 0 );
1319 Debug( LDAP_DEBUG_ANY, "str2result (%s) expecting \"RESULT\"\n",
1327 while ( (s = strchr( s, '\n' )) != NULL ) {
1332 if ( (c = strchr( s, ':' )) != NULL ) {
1336 if ( strncasecmp( s, "code", 4 ) == 0 ) {
1340 } else if ( strncasecmp( s, "matched", 7 ) == 0 ) {
1344 } else if ( strncasecmp( s, "info", 4 ) == 0 ) {
1350 LDAP_LOG( OPERATION, INFO, "str2result: (%s) unknown.\n", s, 0, 0 );
1352 Debug( LDAP_DEBUG_ANY, "str2result (%s) unknown\n",