1 /* result.c - routines to send ldap results, errors, and referrals */
4 * Copyright 1998-2003 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>
22 static char *v2ref( BerVarray ref, const char *text )
24 size_t len = 0, i = 0;
29 return ch_strdup(text);
37 if (text[len-1] != '\n') {
42 v2 = SLAP_MALLOC( len+i+sizeof("Referral:") );
45 LDAP_LOG( OPERATION, ERR, "v2ref: SLAP_MALLOC failed", 0, 0, 0 );
47 Debug( LDAP_DEBUG_ANY, "v2ref: SLAP_MALLOC failed", 0, 0, 0 );
58 strcpy( v2+len, "Referral:" );
59 len += sizeof("Referral:");
61 for( i=0; ref[i].bv_val != NULL; i++ ) {
62 v2 = SLAP_REALLOC( v2, len + ref[i].bv_len + 1 );
65 LDAP_LOG( OPERATION, ERR, "v2ref: SLAP_MALLOC failed", 0, 0, 0 );
67 Debug( LDAP_DEBUG_ANY, "v2ref: SLAP_MALLOC failed", 0, 0, 0 );
72 AC_MEMCPY(&v2[len], ref[i].bv_val, ref[i].bv_len );
74 if (ref[i].bv_val[ref[i].bv_len-1] != '/') {
83 static ber_tag_t req2res( ber_tag_t tag )
88 case LDAP_REQ_COMPARE:
89 case LDAP_REQ_EXTENDED:
96 tag = LDAP_RES_DELETE;
99 case LDAP_REQ_ABANDON:
100 case LDAP_REQ_UNBIND:
104 case LDAP_REQ_SEARCH:
105 tag = LDAP_RES_SEARCH_RESULT;
115 static long send_ldap_ber(
121 ber_get_option( ber, LBER_OPT_BER_BYTES_TO_WRITE, &bytes );
123 /* write only one pdu at a time - wait til it's our turn */
124 ldap_pvt_thread_mutex_lock( &conn->c_write_mutex );
126 /* lock the connection */
127 ldap_pvt_thread_mutex_lock( &conn->c_mutex );
134 if ( connection_state_closing( conn ) ) {
135 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
136 ldap_pvt_thread_mutex_unlock( &conn->c_write_mutex );
141 if ( ber_flush( conn->c_sb, ber, 0 ) == 0 ) {
148 * we got an error. if it's ewouldblock, we need to
149 * wait on the socket being writable. otherwise, figure
150 * it's a hard error and return.
154 LDAP_LOG( OPERATION, ERR,
155 "send_ldap_ber: conn %lu ber_flush failed err=%d (%s)\n",
156 conn ? conn->c_connid : 0, err, sock_errstr(err) );
158 Debug( LDAP_DEBUG_CONNS, "ber_flush failed errno=%d reason=\"%s\"\n",
159 err, sock_errstr(err), 0 );
162 if ( err != EWOULDBLOCK && err != EAGAIN ) {
163 connection_closing( conn );
165 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
166 ldap_pvt_thread_mutex_unlock( &conn->c_write_mutex );
171 /* wait for socket to be write-ready */
172 conn->c_writewaiter = 1;
173 ber_sockbuf_ctrl( conn->c_sb, LBER_SB_OPT_GET_FD, &sd );
174 slapd_set_write( sd, 1 );
176 ldap_pvt_thread_cond_wait( &conn->c_write_cv, &conn->c_mutex );
177 conn->c_writewaiter = 0;
180 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
181 ldap_pvt_thread_mutex_unlock( &conn->c_write_mutex );
187 send_ldap_controls( BerElement *ber, LDAPControl **c )
190 if( c == NULL ) return 0;
192 rc = ber_printf( ber, "t{"/*}*/, LDAP_TAG_CONTROLS );
193 if( rc == -1 ) return rc;
195 for( ; *c != NULL; c++) {
196 rc = ber_printf( ber, "{s" /*}*/, (*c)->ldctl_oid );
198 if( (*c)->ldctl_iscritical ) {
199 rc = ber_printf( ber, "b",
200 (ber_int_t) (*c)->ldctl_iscritical ) ;
201 if( rc == -1 ) return rc;
204 if( (*c)->ldctl_value.bv_val != NULL ) {
205 rc = ber_printf( ber, "O", &((*c)->ldctl_value));
206 if( rc == -1 ) return rc;
209 rc = ber_printf( ber, /*{*/"N}" );
210 if( rc == -1 ) return rc;
213 rc = ber_printf( ber, /*{*/"N}" );
229 struct berval *resdata,
230 struct berval *sasldata,
234 char berbuf[LBER_ELEMENT_SIZEOF];
235 BerElement *ber = (BerElement *)berbuf;
239 if (op->o_callback && op->o_callback->sc_response) {
240 op->o_callback->sc_response( conn, op, tag, msgid, err, matched,
241 text, ref, resoid, resdata, sasldata, ctrls );
245 ber_init_w_nullc( ber, LBER_USE_DER );
248 LDAP_LOG( OPERATION, ENTRY,
249 "send_ldap_response: msgid=%d tag=%lu err=%d\n",
252 Debug( LDAP_DEBUG_TRACE,
253 "send_ldap_response: msgid=%d tag=%lu err=%d\n",
259 LDAP_LOG( OPERATION, ARGS,
260 "send_ldap_response: conn %lu ref=\"%s\"\n",
261 conn ? conn->c_connid : 0,
262 ref[0].bv_val ? ref[0].bv_val : "NULL" , 0 );
264 Debug( LDAP_DEBUG_ARGS, "send_ldap_response: ref=\"%s\"\n",
265 ref[0].bv_val ? ref[0].bv_val : "NULL",
270 #ifdef LDAP_CONNECTIONLESS
271 if( conn->c_is_udp ) {
273 (char *)&op->o_peeraddr, sizeof(struct sockaddr), 0);
274 if (rc != sizeof(struct sockaddr)) {
276 LDAP_LOG( OPERATION, ERR,
277 "send_ldap_response: conn %lu ber_write failed\n",
278 conn ? conn->c_connid : 0 , 0, 0);
280 Debug( LDAP_DEBUG_ANY, "ber_write failed\n", 0, 0, 0 );
286 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2) {
287 rc = ber_printf( ber, "{is{t{ess" /*"}}}"*/,
289 matched == NULL ? "" : matched,
290 text == NULL ? "" : text );
294 rc = ber_printf( ber, "{it{ess" /*"}}"*/,
296 matched == NULL ? "" : matched,
297 text == NULL ? "" : text );
302 assert( err == LDAP_REFERRAL );
303 rc = ber_printf( ber, "t{W}",
304 LDAP_TAG_REFERRAL, ref );
306 assert( err != LDAP_REFERRAL );
310 if( rc != -1 && sasldata != NULL ) {
311 rc = ber_printf( ber, "tO",
312 LDAP_TAG_SASL_RES_CREDS, sasldata );
315 if( rc != -1 && resoid != NULL ) {
316 rc = ber_printf( ber, "ts",
317 LDAP_TAG_EXOP_RES_OID, resoid );
320 if( rc != -1 && resdata != NULL ) {
321 rc = ber_printf( ber, "tO",
322 LDAP_TAG_EXOP_RES_VALUE, resdata );
326 rc = ber_printf( ber, /*"{"*/ "N}" );
329 if( rc != -1 && ctrls != NULL ) {
330 rc = send_ldap_controls( ber, ctrls );
334 rc = ber_printf( ber, /*"{"*/ "N}" );
337 #ifdef LDAP_CONNECTIONLESS
338 if( conn->c_is_udp && op->o_protocol == LDAP_VERSION2 && rc != -1 ) {
339 rc = ber_printf( ber, /*"{"*/ "N}" );
345 LDAP_LOG( OPERATION, ERR,
346 "send_ldap_response: conn %lu ber_printf failed\n",
347 conn ? conn->c_connid : 0, 0, 0 );
349 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
357 bytes = send_ldap_ber( conn, ber );
362 LDAP_LOG( OPERATION, ERR,
363 "send_ldap_response: conn %lu ber write failed\n",
364 conn ? conn->c_connid : 0, 0, 0 );
366 Debug( LDAP_DEBUG_ANY,
367 "send_ldap_response: ber write failed\n",
375 slapi_pblock_set( op->o_pb, SLAPI_RESULT_CODE, (void *)err );
376 slapi_pblock_set( op->o_pb, SLAPI_RESULT_MATCHED, ( matched != NULL ) ? (void *)ch_strdup( matched ) : NULL );
377 slapi_pblock_set( op->o_pb, SLAPI_RESULT_TEXT, ( text != NULL ) ? (void *)ch_strdup( text ) : NULL );
378 #endif /* LDAP_SLAPI */
380 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
381 num_bytes_sent += bytes;
383 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
389 send_ldap_disconnect(
400 #define LDAP_UNSOLICITED_ERROR(e) \
401 ( (e) == LDAP_PROTOCOL_ERROR \
402 || (e) == LDAP_STRONG_AUTH_REQUIRED \
403 || (e) == LDAP_UNAVAILABLE )
405 assert( LDAP_UNSOLICITED_ERROR( err ) );
408 LDAP_LOG( OPERATION, ENTRY,
409 "send_ldap_disconnect: conn %lu %d:%s\n",
410 conn ? conn->c_connid : 0, err, text ? text : "" );
412 Debug( LDAP_DEBUG_TRACE,
413 "send_ldap_disconnect %d:%s\n",
414 err, text ? text : "", NULL );
418 if ( op->o_protocol < LDAP_VERSION3 ) {
420 tag = req2res( op->o_tag );
421 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
424 reqoid = LDAP_NOTICE_DISCONNECT;
425 tag = LDAP_RES_EXTENDED;
429 send_ldap_response( conn, op, tag, msgid,
430 err, NULL, text, NULL,
431 reqoid, NULL, NULL, NULL );
433 Statslog( LDAP_DEBUG_STATS,
434 "conn=%lu op=%lu DISCONNECT tag=%lu err=%d text=%s\n",
435 op->o_connid, op->o_opid, tag, err, text ? text : "" );
439 slap_send_ldap_result(
453 assert( !LDAP_API_ERROR( err ) );
456 LDAP_LOG( OPERATION, ENTRY,
457 "send_ldap_result: conn %lu op=%lu p=%d\n",
458 op->o_connid, op->o_opid, op->o_protocol );
460 Debug( LDAP_DEBUG_TRACE,
461 "send_ldap_result: conn=%lu op=%lu p=%d\n",
462 op->o_connid, op->o_opid, op->o_protocol );
466 LDAP_LOG( OPERATION, ARGS,
467 "send_ldap_result: err=%d matched=\"%s\" text=\"%s\"\n",
468 err, matched ? matched : "", text ? text : "" );
470 Debug( LDAP_DEBUG_ARGS,
471 "send_ldap_result: err=%d matched=\"%s\" text=\"%s\"\n",
472 err, matched ? matched : "", text ? text : "" );
478 LDAP_LOG( OPERATION, ARGS,
479 "send_ldap_result: referral=\"%s\"\n",
480 ref[0].bv_val ? ref[0].bv_val : "NULL", 0, 0 );
482 Debug( LDAP_DEBUG_ARGS,
483 "send_ldap_result: referral=\"%s\"\n",
484 ref[0].bv_val ? ref[0].bv_val : "NULL",
489 assert( err != LDAP_PARTIAL_RESULTS );
491 if ( err == LDAP_REFERRAL ) {
493 err = LDAP_NO_SUCH_OBJECT;
494 } else if ( op->o_protocol < LDAP_VERSION3 ) {
495 err = LDAP_PARTIAL_RESULTS;
499 if ( op->o_protocol < LDAP_VERSION3 ) {
500 tmp = v2ref( ref, text );
505 tag = req2res( op->o_tag );
506 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
508 send_ldap_response( conn, op, tag, msgid,
509 err, matched, text, ref,
510 NULL, NULL, NULL, ctrls );
512 Statslog( LDAP_DEBUG_STATS,
513 "conn=%lu op=%lu RESULT tag=%lu err=%d text=%s\n",
514 op->o_connid, op->o_opid, tag, err, text ? text : "" );
537 LDAP_LOG( OPERATION, ENTRY,
538 "send_ldap_sasl: conn %lu err=%d len=%lu\n",
539 op->o_connid, err, cred ? cred->bv_len : -1 );
541 Debug( LDAP_DEBUG_TRACE, "send_ldap_sasl: err=%d len=%ld\n",
542 err, cred ? (long) cred->bv_len : -1, NULL );
546 tag = req2res( op->o_tag );
547 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
549 send_ldap_response( conn, op, tag, msgid,
550 err, matched, text, ref,
551 NULL, NULL, cred, ctrls );
555 slap_send_ldap_extended(
563 struct berval *rspdata,
571 LDAP_LOG( OPERATION, ENTRY,
572 "send_ldap_extended: err=%d oid=%s len=%ld\n",
573 err, rspoid ? rspoid : "",
574 rspdata != NULL ? rspdata->bv_len : 0 );
576 Debug( LDAP_DEBUG_TRACE,
577 "send_ldap_extended: err=%d oid=%s len=%ld\n",
579 rspoid ? rspoid : "",
580 rspdata != NULL ? rspdata->bv_len : 0 );
583 tag = req2res( op->o_tag );
584 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
586 send_ldap_response( conn, op, tag, msgid,
587 err, matched, text, refs,
588 rspoid, rspdata, NULL, ctrls );
593 slap_send_search_result(
608 assert( !LDAP_API_ERROR( err ) );
610 if (op->o_callback && op->o_callback->sc_sresult) {
611 op->o_callback->sc_sresult(conn, op, err, matched, text, refs,
617 LDAP_LOG( OPERATION, ENTRY,
618 "send_search_result: err=%d matched=\"%s\" text=\"%s\"\n",
619 err, matched ? matched : "", text ? text : "" );
621 Debug( LDAP_DEBUG_TRACE,
622 "send_search_result: err=%d matched=\"%s\" text=\"%s\"\n",
623 err, matched ? matched : "", text ? text : "" );
627 assert( err != LDAP_PARTIAL_RESULTS );
629 if( op->o_protocol < LDAP_VERSION3 ) {
630 /* send references in search results */
631 if( err == LDAP_REFERRAL ) {
632 err = LDAP_PARTIAL_RESULTS;
635 tmp = v2ref( refs, text );
640 /* don't send references in search results */
641 assert( refs == NULL );
644 if( err == LDAP_REFERRAL ) {
649 tag = req2res( op->o_tag );
650 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
652 send_ldap_response( conn, op, tag, msgid,
653 err, matched, text, refs,
654 NULL, NULL, NULL, ctrls );
658 snprintf( nbuf, sizeof nbuf, "%d nentries=%d", err, nentries );
660 Statslog( LDAP_DEBUG_STATS,
661 "conn=%lu op=%lu SEARCH RESULT tag=%lu err=%s text=%s\n",
662 op->o_connid, op->o_opid, tag, nbuf, text ? text : "" );
671 slap_send_search_entry(
676 AttributeName *attrs,
681 char berbuf[LBER_ELEMENT_SIZEOF];
682 BerElement *ber = (BerElement *)berbuf;
684 int i, j, rc=-1, bytes;
688 AccessControlState acl_state = ACL_STATE_INIT;
690 /* Support for computed attribute plugins */
691 computed_attr_context ctx;
695 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
697 /* a_flags: array of flags telling if the i-th element will be
698 * returned or filtered out
699 * e_flags: array of a_flags
701 char **e_flags = NULL;
703 if (op->o_callback && op->o_callback->sc_sendentry) {
704 return op->o_callback->sc_sendentry( be, conn, op, e, attrs,
709 LDAP_LOG( OPERATION, ENTRY,
710 "send_search_entry: conn %lu dn=\"%s\"%s\n",
711 op->o_connid, e->e_dn, attrsonly ? " (attrsOnly)" : "" );
713 Debug( LDAP_DEBUG_TRACE,
714 "=> send_search_entry: dn=\"%s\"%s\n",
715 e->e_dn, attrsonly ? " (attrsOnly)" : "", 0 );
718 if ( ! access_allowed( be, conn, op, e,
719 ad_entry, NULL, ACL_READ, NULL ) )
723 "send_search_entry: conn %lu access to entry (%s) not allowed\n",
724 op->o_connid, e->e_dn, 0 );
726 Debug( LDAP_DEBUG_ACL,
727 "send_search_entry: access to entry not allowed\n",
736 ber_init_w_nullc( ber, LBER_USE_DER );
738 #ifdef LDAP_CONNECTIONLESS
739 if (conn->c_is_udp) {
741 (char *)&op->o_peeraddr, sizeof(struct sockaddr), 0);
742 if (rc != sizeof(struct sockaddr)) {
744 LDAP_LOG( OPERATION, ERR,
745 "send_search_entry: conn %lu ber_write failed\n",
746 conn ? conn->c_connid : 0, 0, 0 );
748 Debug( LDAP_DEBUG_ANY, "ber_write failed\n", 0, 0, 0 );
754 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2) {
755 rc = ber_printf( ber, "{is{t{O{" /*}}}*/,
756 op->o_msgid, "", LDAP_RES_SEARCH_ENTRY, &e->e_name );
758 #endif /* LDAP_CONNECTIONLESS */
760 rc = ber_printf( ber, "{it{O{" /*}}}*/, op->o_msgid,
761 LDAP_RES_SEARCH_ENTRY, &e->e_name );
766 LDAP_LOG( OPERATION, ERR,
767 "send_search_entry: conn %lu ber_printf failed\n",
768 op->o_connid, 0, 0 );
770 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
774 send_ldap_result( conn, op, LDAP_OTHER,
775 NULL, "encoding DN error", NULL, NULL );
779 /* check for special all user attributes ("*") type */
780 userattrs = ( attrs == NULL ) ? 1
781 : an_find( attrs, &AllUser );
783 /* check for special all operational attributes ("+") type */
784 opattrs = ( attrs == NULL ) ? 0
785 : an_find( attrs, &AllOper );
787 /* create an array of arrays of flags. Each flag corresponds
788 * to particular value of attribute and equals 1 if value matches
789 * to ValuesReturnFilter or 0 if not
791 if ( op->vrFilter != NULL ) {
795 for ( a = e->e_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
796 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ ) k++;
799 size = i * sizeof(char *) + k;
802 e_flags = SLAP_CALLOC ( 1, i * sizeof(char *) + k );
803 if( e_flags == NULL ) {
805 LDAP_LOG( OPERATION, ERR,
806 "send_search_entry: conn %lu SLAP_CALLOC failed\n",
807 conn ? conn->c_connid : 0, 0, 0 );
809 Debug( LDAP_DEBUG_ANY,
810 "send_search_entry: SLAP_CALLOC failed\n", 0, 0, 0 );
814 send_ldap_result( conn, op, LDAP_OTHER,
815 NULL, "memory error",
819 a_flags = (char *)(e_flags + i);
820 memset( a_flags, 0, k );
821 for ( a = e->e_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
822 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ );
823 e_flags[i] = a_flags;
827 rc = filter_matched_values(be, conn, op, e->e_attrs, &e_flags) ;
830 LDAP_LOG( OPERATION, ERR,
831 "send_search_entry: conn %lu matched values filtering failed\n",
832 conn ? conn->c_connid : 0, 0, 0 );
834 Debug( LDAP_DEBUG_ANY,
835 "matched values filtering failed\n", 0, 0, 0 );
839 send_ldap_result( conn, op, LDAP_OTHER,
840 NULL, "matched values filtering error",
847 for ( a = e->e_attrs, j = 0; a != NULL; a = a->a_next, j++ ) {
848 AttributeDescription *desc = a->a_desc;
850 if ( attrs == NULL ) {
851 /* all attrs request, skip operational attributes */
852 if( is_at_operational( desc->ad_type ) ) {
857 /* specific attrs requested */
858 if ( is_at_operational( desc->ad_type ) ) {
859 if( !opattrs && !ad_inlist( desc, attrs ) ) {
864 if (!userattrs && !ad_inlist( desc, attrs ) ) {
870 if ( ! access_allowed( be, conn, op, e, desc, NULL,
871 ACL_READ, &acl_state ) )
875 "send_search_entry: conn %lu access to attribute %s not "
876 "allowed\n", op->o_connid, desc->ad_cname.bv_val, 0 );
878 Debug( LDAP_DEBUG_ACL, "acl: "
879 "access to attribute %s not allowed\n",
880 desc->ad_cname.bv_val, 0, 0 );
885 if (( rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname )) == -1 ) {
887 LDAP_LOG( OPERATION, ERR,
888 "send_search_entry: conn %lu ber_printf failed\n",
889 op->o_connid, 0, 0 );
891 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
895 send_ldap_result( conn, op, LDAP_OTHER,
896 NULL, "encoding description error", NULL, NULL );
901 for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
902 if ( ! access_allowed( be, conn, op, e,
903 desc, &a->a_vals[i], ACL_READ, &acl_state ) )
907 "send_search_entry: conn %lu "
908 "access to attribute %s, value %d not allowed\n",
909 op->o_connid, desc->ad_cname.bv_val, i );
911 Debug( LDAP_DEBUG_ACL,
912 "acl: access to attribute %s, "
913 "value %d not allowed\n",
914 desc->ad_cname.bv_val, i, 0 );
920 if ( op->vrFilter && e_flags[j][i] == 0 ){
924 if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
926 LDAP_LOG( OPERATION, ERR,
927 "send_search_entry: conn %lu "
928 "ber_printf failed.\n", op->o_connid, 0, 0 );
930 Debug( LDAP_DEBUG_ANY,
931 "ber_printf failed\n", 0, 0, 0 );
935 send_ldap_result( conn, op, LDAP_OTHER,
936 NULL, "encoding values error",
943 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
945 LDAP_LOG( OPERATION, ERR,
946 "send_search_entry: conn %lu ber_printf failed\n",
947 op->o_connid, 0, 0 );
949 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
953 send_ldap_result( conn, op, LDAP_OTHER,
954 NULL, "encode end error", NULL, NULL );
959 /* eventually will loop through generated operational attributes */
960 /* only have subschemaSubentry implemented */
961 aa = backend_operational( be, conn, op, e, attrs, opattrs );
963 if ( aa != NULL && op->vrFilter != NULL ) {
967 for ( a = aa, i=0; a != NULL; a = a->a_next, i++ ) {
968 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ ) k++;
971 size = i * sizeof(char *) + k;
973 char *a_flags, **tmp;
976 * Reuse previous memory - we likely need less space
977 * for operational attributes
979 tmp = SLAP_REALLOC ( e_flags, i * sizeof(char *) + k );
982 LDAP_LOG( OPERATION, ERR,
983 "send_search_entry: conn %lu "
985 "for matched values filtering\n",
986 conn ? conn->c_connid : 0, 0, 0);
988 Debug( LDAP_DEBUG_ANY,
989 "send_search_entry: conn %lu "
991 "for matched values filtering\n",
992 conn ? conn->c_connid : 0, 0, 0 );
996 send_ldap_result( conn, op, LDAP_NO_MEMORY,
997 NULL, NULL, NULL, NULL );
1001 a_flags = (char *)(e_flags + i);
1002 memset( a_flags, 0, k );
1003 for ( a = aa, i=0; a != NULL; a = a->a_next, i++ ) {
1004 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ );
1005 e_flags[i] = a_flags;
1008 rc = filter_matched_values(be, conn, op, aa, &e_flags) ;
1012 LDAP_LOG( OPERATION, ERR,
1013 "send_search_entry: conn %lu "
1014 "matched values filtering failed\n",
1015 conn ? conn->c_connid : 0, 0, 0);
1017 Debug( LDAP_DEBUG_ANY,
1018 "matched values filtering failed\n", 0, 0, 0 );
1022 send_ldap_result( conn, op, LDAP_OTHER,
1023 NULL, "matched values filtering error",
1030 for (a = aa, j=0; a != NULL; a = a->a_next, j++ ) {
1031 AttributeDescription *desc = a->a_desc;
1033 if ( attrs == NULL ) {
1034 /* all attrs request, skip operational attributes */
1035 if( is_at_operational( desc->ad_type ) ) {
1040 /* specific attrs requested */
1041 if( is_at_operational( desc->ad_type ) ) {
1042 if( !opattrs && !ad_inlist( desc, attrs ) ) {
1046 if (!userattrs && !ad_inlist( desc, attrs ) )
1053 if ( ! access_allowed( be, conn, op, e, desc, NULL,
1054 ACL_READ, &acl_state ) )
1057 LDAP_LOG( ACL, INFO,
1058 "send_search_entry: conn %lu "
1059 "access to attribute %s not allowed\n",
1060 op->o_connid, desc->ad_cname.bv_val, 0 );
1062 Debug( LDAP_DEBUG_ACL, "acl: access to attribute %s "
1064 desc->ad_cname.bv_val, 0, 0 );
1070 rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname );
1073 LDAP_LOG( OPERATION, ERR,
1074 "send_search_entry: conn %lu "
1075 "ber_printf failed\n", op->o_connid, 0, 0 );
1077 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1080 ber_free_buf( ber );
1081 send_ldap_result( conn, op, LDAP_OTHER,
1082 NULL, "encoding description error", NULL, NULL );
1088 if ( ! attrsonly ) {
1089 for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
1090 if ( ! access_allowed( be, conn, op, e,
1091 desc, &a->a_vals[i], ACL_READ, &acl_state ) )
1094 LDAP_LOG( ACL, INFO,
1095 "send_search_entry: conn %lu "
1096 "access to %s, value %d not allowed\n",
1097 op->o_connid, desc->ad_cname.bv_val, i );
1099 Debug( LDAP_DEBUG_ACL,
1100 "acl: access to attribute %s, "
1101 "value %d not allowed\n",
1102 desc->ad_cname.bv_val, i, 0 );
1108 if ( op->vrFilter && e_flags[j][i] == 0 ){
1112 if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
1114 LDAP_LOG( OPERATION, ERR,
1115 "send_search_entry: conn %lu ber_printf failed\n",
1116 op->o_connid, 0, 0 );
1118 Debug( LDAP_DEBUG_ANY,
1119 "ber_printf failed\n", 0, 0, 0 );
1122 ber_free_buf( ber );
1123 send_ldap_result( conn, op, LDAP_OTHER,
1124 NULL, "encoding values error",
1133 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
1135 LDAP_LOG( OPERATION, ERR,
1136 "send_search_entry: conn %lu ber_printf failed\n",
1137 op->o_connid, 0, 0 );
1139 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1142 ber_free_buf( ber );
1143 send_ldap_result( conn, op, LDAP_OTHER,
1144 NULL, "encode end error", NULL, NULL );
1152 /* Support Sun ONE DS 5.x computed attributes */
1155 * First, setup the computed attribute context that is
1156 * passed to all plugins.
1158 ctx.cac_pb = op->o_pb;
1159 ctx.cac_attrs = attrs;
1160 ctx.cac_attrsonly = attrsonly;
1161 ctx.cac_userattrs = userattrs;
1162 ctx.cac_opattrs = opattrs;
1163 ctx.cac_acl_state = acl_state;
1164 ctx.cac_private = (void *)ber;
1167 * For each client requested attribute, call the plugins.
1169 if ( attrs != NULL ) {
1170 for ( anp = attrs; anp->an_name.bv_val != NULL; anp++ ) {
1171 rc = compute_evaluator( &ctx, anp->an_name.bv_val, e, slapi_x_compute_output_ber );
1177 rc = compute_evaluator( &ctx, "*", e, slapi_x_compute_output_ber );
1180 ber_free_buf( ber );
1181 send_ldap_result( conn, op, LDAP_OTHER,
1182 NULL, "computed attribute error", NULL, NULL );
1185 #endif /* LDAP_SLAPI */
1194 rc = ber_printf( ber, /*{{*/ "}N}" );
1196 if( rc != -1 && ctrls != NULL ) {
1197 rc = send_ldap_controls( ber, ctrls );
1201 rc = ber_printf( ber, /*{*/ "N}" );
1204 #ifdef LDAP_CONNECTIONLESS
1205 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2 && rc != -1) {
1206 rc = ber_printf( ber, "}" );
1211 LDAP_LOG( OPERATION, ERR,
1212 "send_search_entry: conn %lu ber_printf failed\n",
1213 op->o_connid, 0, 0 );
1215 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1218 ber_free_buf( ber );
1219 send_ldap_result( conn, op, LDAP_OTHER,
1220 NULL, "encode entry end error", NULL, NULL );
1224 bytes = op->o_noop ? 0 : send_ldap_ber( conn, ber );
1225 ber_free_buf( ber );
1229 LDAP_LOG( OPERATION, ERR,
1230 "send_search_entry: conn %lu ber write failed.\n",
1231 op->o_connid, 0, 0 );
1233 Debug( LDAP_DEBUG_ANY,
1234 "send_search_entry: ber write failed\n",
1241 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1242 num_bytes_sent += bytes;
1245 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1247 Statslog( LDAP_DEBUG_STATS2, "conn=%lu op=%lu ENTRY dn=\"%s\"\n",
1248 conn->c_connid, op->o_opid, e->e_dn, 0, 0 );
1251 LDAP_LOG( OPERATION, ENTRY,
1252 "send_search_entry: conn %lu exit.\n", op->o_connid, 0, 0 );
1254 Debug( LDAP_DEBUG_TRACE, "<= send_search_entry\n", 0, 0, 0 );
1260 if ( e_flags ) free( e_flags );
1265 slap_send_search_reference(
1271 LDAPControl **ctrls,
1275 char berbuf[LBER_ELEMENT_SIZEOF];
1276 BerElement *ber = (BerElement *)berbuf;
1280 AttributeDescription *ad_ref = slap_schema.si_ad_ref;
1281 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
1284 LDAP_LOG( OPERATION, ENTRY,
1285 "send_search_reference: conn %lu dn=\"%s\"\n",
1286 op->o_connid, e ? e->e_dn : "(null)", 0 );
1288 Debug( LDAP_DEBUG_TRACE,
1289 "=> send_search_reference: dn=\"%s\"\n",
1290 e ? e->e_dn : "(null)", 0, 0 );
1294 if ( e && ! access_allowed( be, conn, op, e,
1295 ad_entry, NULL, ACL_READ, NULL ) )
1298 LDAP_LOG( ACL, INFO,
1299 "send_search_reference: conn %lu "
1300 "access to entry %s not allowed\n",
1301 op->o_connid, e->e_dn, 0 );
1303 Debug( LDAP_DEBUG_ACL,
1304 "send_search_reference: access to entry not allowed\n",
1311 if ( e && ! access_allowed( be, conn, op, e,
1312 ad_ref, NULL, ACL_READ, NULL ) )
1315 LDAP_LOG( ACL, INFO,
1316 "send_search_reference: conn %lu access "
1317 "to reference not allowed.\n", op->o_connid, 0, 0 );
1319 Debug( LDAP_DEBUG_ACL,
1320 "send_search_reference: access "
1321 "to reference not allowed\n",
1328 if( refs == NULL ) {
1330 LDAP_LOG( OPERATION, ERR,
1331 "send_search_reference: conn %lu null ref in (%s).\n",
1332 op->o_connid, e ? e->e_dn : "(null)", 0 );
1334 Debug( LDAP_DEBUG_ANY,
1335 "send_search_reference: null ref in (%s)\n",
1336 e ? e->e_dn : "(null)", 0, 0 );
1342 if( op->o_protocol < LDAP_VERSION3 ) {
1343 /* save the references for the result */
1344 if( refs[0].bv_val != NULL ) {
1345 if( value_add( v2refs, refs ) )
1351 ber_init_w_nullc( ber, LBER_USE_DER );
1353 rc = ber_printf( ber, "{it{W}" /*"}"*/ , op->o_msgid,
1354 LDAP_RES_SEARCH_REFERENCE, refs );
1356 if( rc != -1 && ctrls != NULL ) {
1357 rc = send_ldap_controls( ber, ctrls );
1361 rc = ber_printf( ber, /*"{"*/ "N}", op->o_msgid,
1362 LDAP_RES_SEARCH_REFERENCE, refs );
1367 LDAP_LOG( OPERATION, ERR,
1368 "send_search_reference: conn %lu "
1369 "ber_printf failed.\n", op->o_connid, 0, 0 );
1371 Debug( LDAP_DEBUG_ANY,
1372 "send_search_reference: ber_printf failed\n", 0, 0, 0 );
1375 ber_free_buf( ber );
1376 send_ldap_result( conn, op, LDAP_OTHER,
1377 NULL, "encode DN error", NULL, NULL );
1381 bytes = op->o_noop ? 0 : send_ldap_ber( conn, ber );
1382 ber_free_buf( ber );
1384 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1385 num_bytes_sent += bytes;
1388 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1390 Statslog( LDAP_DEBUG_STATS2, "conn=%lu op=%lu REF dn=\"%s\"\n",
1391 conn->c_connid, op->o_opid, e ? e->e_dn : "(null)", 0, 0 );
1394 LDAP_LOG( OPERATION, ENTRY,
1395 "send_search_reference: conn %lu exit.\n", op->o_connid, 0, 0 );
1397 Debug( LDAP_DEBUG_TRACE, "<= send_search_reference\n", 0, 0, 0 );
1415 *code = LDAP_SUCCESS;
1419 if ( strncasecmp( s, "RESULT", 6 ) != 0 ) {
1421 LDAP_LOG( OPERATION, INFO,
1422 "str2result: (%s), expecting \"RESULT\"\n", s, 0, 0 );
1424 Debug( LDAP_DEBUG_ANY, "str2result (%s) expecting \"RESULT\"\n",
1432 while ( (s = strchr( s, '\n' )) != NULL ) {
1437 if ( (c = strchr( s, ':' )) != NULL ) {
1441 if ( strncasecmp( s, "code", 4 ) == 0 ) {
1445 } else if ( strncasecmp( s, "matched", 7 ) == 0 ) {
1449 } else if ( strncasecmp( s, "info", 4 ) == 0 ) {
1455 LDAP_LOG( OPERATION, INFO, "str2result: (%s) unknown.\n", s, 0, 0 );
1457 Debug( LDAP_DEBUG_ANY, "str2result (%s) unknown\n",