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 #ifdef LDAP_CONNECTIONLESS
251 ber_init_w_nullc( ber, LBER_USE_DER );
254 LDAP_LOG( OPERATION, ENTRY,
255 "send_ldap_response: msgid=%d tag=%lu err=%d\n",
258 Debug( LDAP_DEBUG_TRACE,
259 "send_ldap_response: msgid=%d tag=%lu err=%d\n",
265 LDAP_LOG( OPERATION, ARGS,
266 "send_ldap_response: conn %lu ref=\"%s\"\n",
267 conn ? conn->c_connid : 0,
268 ref[0].bv_val ? ref[0].bv_val : "NULL" , 0 );
270 Debug( LDAP_DEBUG_ARGS, "send_ldap_response: ref=\"%s\"\n",
271 ref[0].bv_val ? ref[0].bv_val : "NULL",
276 #ifdef LDAP_CONNECTIONLESS
277 if (conn->c_is_udp && conn->c_protocol == LDAP_VERSION2) {
278 rc = ber_printf( ber, "t{ess" /*"}}"*/,
280 matched == NULL ? "" : matched,
281 text == NULL ? "" : text );
285 rc = ber_printf( ber, "{it{ess" /*"}}"*/,
287 matched == NULL ? "" : matched,
288 text == NULL ? "" : text );
293 assert( err == LDAP_REFERRAL );
294 rc = ber_printf( ber, "t{W}",
295 LDAP_TAG_REFERRAL, ref );
297 assert( err != LDAP_REFERRAL );
301 if( rc != -1 && sasldata != NULL ) {
302 rc = ber_printf( ber, "tO",
303 LDAP_TAG_SASL_RES_CREDS, sasldata );
306 if( rc != -1 && resoid != NULL ) {
307 rc = ber_printf( ber, "ts",
308 LDAP_TAG_EXOP_RES_OID, resoid );
311 if( rc != -1 && resdata != NULL ) {
312 rc = ber_printf( ber, "tO",
313 LDAP_TAG_EXOP_RES_VALUE, resdata );
317 rc = ber_printf( ber, /*"{"*/ "N}" );
320 if( rc != -1 && ctrls != NULL ) {
321 rc = send_ldap_controls( ber, ctrls );
325 rc = ber_printf( ber, /*"{"*/ "N}" );
330 LDAP_LOG( OPERATION, ERR,
331 "send_ldap_response: conn %lu ber_printf failed\n",
332 conn ? conn->c_connid : 0, 0, 0 );
334 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
337 #ifdef LDAP_CONNECTIONLESS
338 if (conn->c_is_udp == 0)
345 bytes = send_ldap_ber( conn, ber );
346 #ifdef LDAP_CONNECTIONLESS
347 if (conn->c_is_udp == 0)
353 LDAP_LOG( OPERATION, ERR,
354 "send_ldap_response: conn %lu ber write failed\n",
355 conn ? conn->c_connid : 0, 0, 0 );
357 Debug( LDAP_DEBUG_ANY,
358 "send_ldap_response: ber write failed\n",
366 slapi_pblock_set( op->o_pb, SLAPI_RESULT_CODE, (void *)err );
367 slapi_pblock_set( op->o_pb, SLAPI_RESULT_MATCHED, ( matched != NULL ) ? (void *)ch_strdup( matched ) : NULL );
368 slapi_pblock_set( op->o_pb, SLAPI_RESULT_TEXT, ( text != NULL ) ? (void *)ch_strdup( text ) : NULL );
369 #endif /* LDAP_SLAPI */
371 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
372 num_bytes_sent += bytes;
374 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
380 send_ldap_disconnect(
391 #define LDAP_UNSOLICITED_ERROR(e) \
392 ( (e) == LDAP_PROTOCOL_ERROR \
393 || (e) == LDAP_STRONG_AUTH_REQUIRED \
394 || (e) == LDAP_UNAVAILABLE )
396 assert( LDAP_UNSOLICITED_ERROR( err ) );
399 LDAP_LOG( OPERATION, ENTRY,
400 "send_ldap_disconnect: conn %lu %d:%s\n",
401 conn ? conn->c_connid : 0, err, text ? text : "" );
403 Debug( LDAP_DEBUG_TRACE,
404 "send_ldap_disconnect %d:%s\n",
405 err, text ? text : "", NULL );
409 if ( op->o_protocol < LDAP_VERSION3 ) {
411 tag = req2res( op->o_tag );
412 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
415 reqoid = LDAP_NOTICE_DISCONNECT;
416 tag = LDAP_RES_EXTENDED;
420 send_ldap_response( conn, op, tag, msgid,
421 err, NULL, text, NULL,
422 reqoid, NULL, NULL, NULL );
424 Statslog( LDAP_DEBUG_STATS,
425 "conn=%lu op=%lu DISCONNECT tag=%lu err=%d text=%s\n",
426 op->o_connid, op->o_opid, tag, err, text ? text : "" );
430 slap_send_ldap_result(
444 assert( !LDAP_API_ERROR( err ) );
447 LDAP_LOG( OPERATION, ENTRY,
448 "send_ldap_result: conn %lu op=%lu p=%d\n",
449 op->o_connid, op->o_opid, op->o_protocol );
451 Debug( LDAP_DEBUG_TRACE,
452 "send_ldap_result: conn=%lu op=%lu p=%d\n",
453 op->o_connid, op->o_opid, op->o_protocol );
457 LDAP_LOG( OPERATION, ARGS,
458 "send_ldap_result: err=%d matched=\"%s\" text=\"%s\"\n",
459 err, matched ? matched : "", text ? text : "" );
461 Debug( LDAP_DEBUG_ARGS,
462 "send_ldap_result: err=%d matched=\"%s\" text=\"%s\"\n",
463 err, matched ? matched : "", text ? text : "" );
469 LDAP_LOG( OPERATION, ARGS,
470 "send_ldap_result: referral=\"%s\"\n",
471 ref[0].bv_val ? ref[0].bv_val : "NULL", 0, 0 );
473 Debug( LDAP_DEBUG_ARGS,
474 "send_ldap_result: referral=\"%s\"\n",
475 ref[0].bv_val ? ref[0].bv_val : "NULL",
480 assert( err != LDAP_PARTIAL_RESULTS );
482 if ( err == LDAP_REFERRAL ) {
483 if( op->o_noreferrals ) {
487 err = LDAP_NO_SUCH_OBJECT;
488 } else if ( op->o_protocol < LDAP_VERSION3 ) {
489 err = LDAP_PARTIAL_RESULTS;
493 if ( op->o_protocol < LDAP_VERSION3 ) {
494 tmp = v2ref( ref, text );
499 tag = req2res( op->o_tag );
500 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
502 send_ldap_response( conn, op, tag, msgid,
503 err, matched, text, ref,
504 NULL, NULL, NULL, ctrls );
506 Statslog( LDAP_DEBUG_STATS,
507 "conn=%lu op=%lu RESULT tag=%lu err=%d text=%s\n",
508 op->o_connid, op->o_opid, tag, err, text ? text : "" );
531 LDAP_LOG( OPERATION, ENTRY,
532 "send_ldap_sasl: conn %lu err=%d len=%lu\n",
533 op->o_connid, err, cred ? cred->bv_len : -1 );
535 Debug( LDAP_DEBUG_TRACE, "send_ldap_sasl: err=%d len=%ld\n",
536 err, cred ? (long) cred->bv_len : -1, NULL );
540 tag = req2res( op->o_tag );
541 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
543 send_ldap_response( conn, op, tag, msgid,
544 err, matched, text, ref,
545 NULL, NULL, cred, ctrls );
549 slap_send_ldap_extended(
557 struct berval *rspdata,
565 LDAP_LOG( OPERATION, ENTRY,
566 "send_ldap_extended: err=%d oid=%s len=%ld\n",
567 err, rspoid ? rspoid : "",
568 rspdata != NULL ? rspdata->bv_len : 0 );
570 Debug( LDAP_DEBUG_TRACE,
571 "send_ldap_extended: err=%d oid=%s len=%ld\n",
573 rspoid ? rspoid : "",
574 rspdata != NULL ? rspdata->bv_len : 0 );
577 tag = req2res( op->o_tag );
578 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
580 send_ldap_response( conn, op, tag, msgid,
581 err, matched, text, refs,
582 rspoid, rspdata, NULL, ctrls );
587 slap_send_search_result(
602 assert( !LDAP_API_ERROR( err ) );
604 if (op->o_callback && op->o_callback->sc_sresult) {
605 op->o_callback->sc_sresult(conn, op, err, matched, text, refs,
611 LDAP_LOG( OPERATION, ENTRY,
612 "send_search_result: err=%d matched=\"%s\" text=\"%s\"\n",
613 err, matched ? matched : "", text ? text : "" );
615 Debug( LDAP_DEBUG_TRACE,
616 "send_search_result: err=%d matched=\"%s\" text=\"%s\"\n",
617 err, matched ? matched : "", text ? text : "" );
621 assert( err != LDAP_PARTIAL_RESULTS );
623 if( op->o_protocol < LDAP_VERSION3 ) {
624 /* send references in search results */
625 if( err == LDAP_REFERRAL ) {
626 err = LDAP_PARTIAL_RESULTS;
629 tmp = v2ref( refs, text );
634 /* don't send references in search results */
635 assert( refs == NULL );
638 if( err == LDAP_REFERRAL ) {
643 tag = req2res( op->o_tag );
644 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
646 send_ldap_response( conn, op, tag, msgid,
647 err, matched, text, refs,
648 NULL, NULL, NULL, ctrls );
652 snprintf( nbuf, sizeof nbuf, "%d nentries=%d", err, nentries );
654 Statslog( LDAP_DEBUG_STATS,
655 "conn=%lu op=%lu SEARCH RESULT tag=%lu err=%s text=%s\n",
656 op->o_connid, op->o_opid, tag, nbuf, text ? text : "" );
665 slap_send_search_entry(
670 AttributeName *attrs,
675 char berbuf[LBER_ELEMENT_SIZEOF];
676 BerElement *ber = (BerElement *)berbuf;
678 int i, j, rc=-1, bytes;
682 AccessControlState acl_state = ACL_STATE_INIT;
684 /* Support for computed attribute plugins */
685 computed_attr_context ctx;
689 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
691 /* a_flags: array of flags telling if the i-th element will be
692 * returned or filtered out
693 * e_flags: array of a_flags
695 char **e_flags = NULL;
697 if (op->o_callback && op->o_callback->sc_sendentry) {
698 return op->o_callback->sc_sendentry( be, conn, op, e, attrs,
703 LDAP_LOG( OPERATION, ENTRY,
704 "send_search_entry: conn %lu dn=\"%s\"%s\n",
705 op->o_connid, e->e_dn, attrsonly ? " (attrsOnly)" : "" );
707 Debug( LDAP_DEBUG_TRACE,
708 "=> send_search_entry: dn=\"%s\"%s\n",
709 e->e_dn, attrsonly ? " (attrsOnly)" : "", 0 );
712 if ( ! access_allowed( be, conn, op, e,
713 ad_entry, NULL, ACL_READ, NULL ) )
717 "send_search_entry: conn %lu access to entry (%s) not allowed\n",
718 op->o_connid, e->e_dn, 0 );
720 Debug( LDAP_DEBUG_ACL,
721 "send_search_entry: access to entry not allowed\n",
730 #ifdef LDAP_CONNECTIONLESS
735 ber_init_w_nullc( ber, LBER_USE_DER );
737 #ifdef LDAP_CONNECTIONLESS
738 if (conn->c_is_udp && conn->c_protocol == LDAP_VERSION2) {
739 rc = ber_printf(ber, "t{0{" /*}}*/,
740 LDAP_RES_SEARCH_ENTRY, &e->e_name);
744 rc = ber_printf( ber, "{it{O{" /*}}}*/, op->o_msgid,
745 LDAP_RES_SEARCH_ENTRY, &e->e_name );
750 LDAP_LOG( OPERATION, ERR,
751 "send_search_entry: conn %lu ber_printf failed\n",
752 op->o_connid, 0, 0 );
754 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
757 #ifdef LDAP_CONNECTIONLESS
758 if (conn->c_is_udp == 0)
761 send_ldap_result( conn, op, LDAP_OTHER,
762 NULL, "encoding DN error", NULL, NULL );
766 /* check for special all user attributes ("*") type */
767 userattrs = ( attrs == NULL ) ? 1
768 : an_find( attrs, &AllUser );
770 /* check for special all operational attributes ("+") type */
771 opattrs = ( attrs == NULL ) ? 0
772 : an_find( attrs, &AllOper );
774 /* create an array of arrays of flags. Each flag corresponds
775 * to particular value of attribute and equals 1 if value matches
776 * to ValuesReturnFilter or 0 if not
778 if ( op->vrFilter != NULL ) {
782 for ( a = e->e_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
783 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ ) k++;
786 size = i * sizeof(char *) + k;
789 e_flags = SLAP_CALLOC ( 1, i * sizeof(char *) + k );
790 if( e_flags == NULL ) {
792 LDAP_LOG( OPERATION, ERR,
793 "send_search_entry: conn %lu SLAP_CALLOC failed\n",
794 conn ? conn->c_connid : 0, 0, 0 );
796 Debug( LDAP_DEBUG_ANY,
797 "send_search_entry: SLAP_CALLOC failed\n", 0, 0, 0 );
801 send_ldap_result( conn, op, LDAP_OTHER,
802 NULL, "memory error",
806 a_flags = (char *)(e_flags + i);
807 memset( a_flags, 0, k );
808 for ( a = e->e_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
809 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ );
810 e_flags[i] = a_flags;
814 rc = filter_matched_values(be, conn, op, e->e_attrs, &e_flags) ;
817 LDAP_LOG( OPERATION, ERR,
818 "send_search_entry: conn %lu matched values filtering failed\n",
819 conn ? conn->c_connid : 0, 0, 0 );
821 Debug( LDAP_DEBUG_ANY,
822 "matched values filtering failed\n", 0, 0, 0 );
824 #ifdef LDAP_CONNECTIONLESS
825 if (conn->c_is_udp == 0)
829 send_ldap_result( conn, op, LDAP_OTHER,
830 NULL, "matched values filtering error",
837 for ( a = e->e_attrs, j = 0; a != NULL; a = a->a_next, j++ ) {
838 AttributeDescription *desc = a->a_desc;
840 if ( attrs == NULL ) {
841 /* all attrs request, skip operational attributes */
842 if( is_at_operational( desc->ad_type ) ) {
847 /* specific attrs requested */
848 if ( is_at_operational( desc->ad_type ) ) {
849 if( !opattrs && !ad_inlist( desc, attrs ) ) {
854 if (!userattrs && !ad_inlist( desc, attrs ) ) {
860 if ( ! access_allowed( be, conn, op, e, desc, NULL,
861 ACL_READ, &acl_state ) )
865 "send_search_entry: conn %lu access to attribute %s not "
866 "allowed\n", op->o_connid, desc->ad_cname.bv_val, 0 );
868 Debug( LDAP_DEBUG_ACL, "acl: "
869 "access to attribute %s not allowed\n",
870 desc->ad_cname.bv_val, 0, 0 );
875 if (( rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname )) == -1 ) {
877 LDAP_LOG( OPERATION, ERR,
878 "send_search_entry: conn %lu ber_printf failed\n",
879 op->o_connid, 0, 0 );
881 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
884 #ifdef LDAP_CONNECTIONLESS
885 if (conn->c_is_udp == 0)
888 send_ldap_result( conn, op, LDAP_OTHER,
889 NULL, "encoding description error", NULL, NULL );
894 for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
895 if ( ! access_allowed( be, conn, op, e,
896 desc, &a->a_vals[i], ACL_READ, &acl_state ) )
900 "send_search_entry: conn %lu "
901 "access to attribute %s, value %d not allowed\n",
902 op->o_connid, desc->ad_cname.bv_val, i );
904 Debug( LDAP_DEBUG_ACL,
905 "acl: access to attribute %s, "
906 "value %d not allowed\n",
907 desc->ad_cname.bv_val, i, 0 );
913 if ( op->vrFilter && e_flags[j][i] == 0 ){
917 if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
919 LDAP_LOG( OPERATION, ERR,
920 "send_search_entry: conn %lu "
921 "ber_printf failed.\n", op->o_connid, 0, 0 );
923 Debug( LDAP_DEBUG_ANY,
924 "ber_printf failed\n", 0, 0, 0 );
927 #ifdef LDAP_CONNECTIONLESS
928 if (conn->c_is_udp == 0)
931 send_ldap_result( conn, op, LDAP_OTHER,
932 NULL, "encoding values error",
939 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
941 LDAP_LOG( OPERATION, ERR,
942 "send_search_entry: conn %lu ber_printf failed\n",
943 op->o_connid, 0, 0 );
945 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
948 #ifdef LDAP_CONNECTIONLESS
949 if (conn->c_is_udp == 0)
952 send_ldap_result( conn, op, LDAP_OTHER,
953 NULL, "encode end error", NULL, NULL );
958 /* eventually will loop through generated operational attributes */
959 /* only have subschemaSubentry implemented */
960 aa = backend_operational( be, conn, op, e, attrs, opattrs );
962 if ( aa != NULL && op->vrFilter != NULL ) {
966 for ( a = aa, i=0; a != NULL; a = a->a_next, i++ ) {
967 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ ) k++;
970 size = i * sizeof(char *) + k;
972 char *a_flags, **tmp;
975 * Reuse previous memory - we likely need less space
976 * for operational attributes
978 tmp = SLAP_REALLOC ( e_flags, i * sizeof(char *) + k );
981 LDAP_LOG( OPERATION, ERR,
982 "send_search_entry: conn %lu "
984 "for matched values filtering\n",
985 conn ? conn->c_connid : 0, 0, 0);
987 Debug( LDAP_DEBUG_ANY,
988 "send_search_entry: conn %lu "
990 "for matched values filtering\n",
991 conn ? conn->c_connid : 0, 0, 0 );
995 send_ldap_result( conn, op, LDAP_NO_MEMORY,
996 NULL, NULL, NULL, NULL );
1000 a_flags = (char *)(e_flags + i);
1001 memset( a_flags, 0, k );
1002 for ( a = aa, i=0; a != NULL; a = a->a_next, i++ ) {
1003 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ );
1004 e_flags[i] = a_flags;
1007 rc = filter_matched_values(be, conn, op, aa, &e_flags) ;
1011 LDAP_LOG( OPERATION, ERR,
1012 "send_search_entry: conn %lu "
1013 "matched values filtering failed\n",
1014 conn ? conn->c_connid : 0, 0, 0);
1016 Debug( LDAP_DEBUG_ANY,
1017 "matched values filtering failed\n", 0, 0, 0 );
1019 #ifdef LDAP_CONNECTIONLESS
1020 if (conn->c_is_udp == 0)
1024 send_ldap_result( conn, op, LDAP_OTHER,
1025 NULL, "matched values filtering error",
1032 for (a = aa, j=0; a != NULL; a = a->a_next, j++ ) {
1033 AttributeDescription *desc = a->a_desc;
1035 if ( attrs == NULL ) {
1036 /* all attrs request, skip operational attributes */
1037 if( is_at_operational( desc->ad_type ) ) {
1042 /* specific attrs requested */
1043 if( is_at_operational( desc->ad_type ) ) {
1044 if( !opattrs && !ad_inlist( desc, attrs ) ) {
1048 if (!userattrs && !ad_inlist( desc, attrs ) )
1055 if ( ! access_allowed( be, conn, op, e, desc, NULL,
1056 ACL_READ, &acl_state ) )
1059 LDAP_LOG( ACL, INFO,
1060 "send_search_entry: conn %lu "
1061 "access to attribute %s not allowed\n",
1062 op->o_connid, desc->ad_cname.bv_val, 0 );
1064 Debug( LDAP_DEBUG_ACL, "acl: access to attribute %s "
1066 desc->ad_cname.bv_val, 0, 0 );
1072 rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname );
1075 LDAP_LOG( OPERATION, ERR,
1076 "send_search_entry: conn %lu "
1077 "ber_printf failed\n", op->o_connid, 0, 0 );
1079 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1082 #ifdef LDAP_CONNECTIONLESS
1083 if (conn->c_is_udp == 0)
1085 ber_free_buf( ber );
1086 send_ldap_result( conn, op, LDAP_OTHER,
1087 NULL, "encoding description error", NULL, NULL );
1093 if ( ! attrsonly ) {
1094 for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
1095 if ( ! access_allowed( be, conn, op, e,
1096 desc, &a->a_vals[i], ACL_READ, &acl_state ) )
1099 LDAP_LOG( ACL, INFO,
1100 "send_search_entry: conn %lu "
1101 "access to %s, value %d not allowed\n",
1102 op->o_connid, desc->ad_cname.bv_val, i );
1104 Debug( LDAP_DEBUG_ACL,
1105 "acl: access to attribute %s, "
1106 "value %d not allowed\n",
1107 desc->ad_cname.bv_val, i, 0 );
1113 if ( op->vrFilter && e_flags[j][i] == 0 ){
1117 if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
1119 LDAP_LOG( OPERATION, ERR,
1120 "send_search_entry: conn %lu ber_printf failed\n",
1121 op->o_connid, 0, 0 );
1123 Debug( LDAP_DEBUG_ANY,
1124 "ber_printf failed\n", 0, 0, 0 );
1127 #ifdef LDAP_CONNECTIONLESS
1128 if (conn->c_is_udp == 0)
1130 ber_free_buf( ber );
1131 send_ldap_result( conn, op, LDAP_OTHER,
1132 NULL, "encoding values error",
1141 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
1143 LDAP_LOG( OPERATION, ERR,
1144 "send_search_entry: conn %lu ber_printf failed\n",
1145 op->o_connid, 0, 0 );
1147 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1150 #ifdef LDAP_CONNECTIONLESS
1151 if (conn->c_is_udp == 0)
1153 ber_free_buf( ber );
1154 send_ldap_result( conn, op, LDAP_OTHER,
1155 NULL, "encode end error", NULL, NULL );
1164 * First, setup the computed attribute context that is
1165 * passed to all plugins.
1167 ctx.cac_pb = op->o_pb;
1168 ctx.cac_attrs = attrs;
1169 ctx.cac_attrsonly = attrsonly;
1170 ctx.cac_userattrs = userattrs;
1171 ctx.cac_opattrs = opattrs;
1172 ctx.cac_acl_state = acl_state;
1173 ctx.cac_private = (void *)ber;
1176 * For each client requested attribute, call the plugins.
1178 if ( attrs != NULL ) {
1179 for ( anp = attrs; anp->an_name.bv_val != NULL; anp++ ) {
1180 rc = compute_evaluator( &ctx, anp->an_name.bv_val, e, slapi_x_compute_output_ber );
1187 * Technically we shouldn't be returning operational attributes
1188 * when the user requested only user attributes. We'll let the
1189 * plugin decide whether to be naughty or not.
1191 rc = compute_evaluator( &ctx, "*", e, slapi_x_compute_output_ber );
1194 ber_free_buf( ber );
1195 send_ldap_result( conn, op, LDAP_OTHER,
1196 NULL, "computed attribute error", NULL, NULL );
1199 #endif /* LDAP_SLAPI */
1208 rc = ber_printf( ber, /*{{*/ "}N}" );
1210 if( rc != -1 && ctrls != NULL ) {
1211 rc = send_ldap_controls( ber, ctrls );
1215 rc = ber_printf( ber, /*{*/ "N}" );
1220 LDAP_LOG( OPERATION, ERR,
1221 "send_search_entry: conn %lu ber_printf failed\n",
1222 op->o_connid, 0, 0 );
1224 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1227 #ifdef LDAP_CONNECTIONLESS
1228 if (conn->c_is_udp == 0)
1230 ber_free_buf( ber );
1231 send_ldap_result( conn, op, LDAP_OTHER,
1232 NULL, "encode entry end error", NULL, NULL );
1236 #ifdef LDAP_CONNECTIONLESS
1237 if (conn->c_is_udp == 0) {
1239 bytes = op->o_noop ? 0 : send_ldap_ber( conn, ber );
1240 ber_free_buf( ber );
1244 LDAP_LOG( OPERATION, ERR,
1245 "send_search_entry: conn %lu ber write failed.\n",
1246 op->o_connid, 0, 0 );
1248 Debug( LDAP_DEBUG_ANY,
1249 "send_search_entry: ber write failed\n",
1256 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1257 num_bytes_sent += bytes;
1260 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1262 #ifdef LDAP_CONNECTIONLESS
1266 Statslog( LDAP_DEBUG_STATS2, "conn=%lu op=%lu ENTRY dn=\"%s\"\n",
1267 conn->c_connid, op->o_opid, e->e_dn, 0, 0 );
1270 LDAP_LOG( OPERATION, ENTRY,
1271 "send_search_entry: conn %lu exit.\n", op->o_connid, 0, 0 );
1273 Debug( LDAP_DEBUG_TRACE, "<= send_search_entry\n", 0, 0, 0 );
1279 if ( e_flags ) free( e_flags );
1284 slap_send_search_reference(
1290 LDAPControl **ctrls,
1294 char berbuf[LBER_ELEMENT_SIZEOF];
1295 BerElement *ber = (BerElement *)berbuf;
1299 AttributeDescription *ad_ref = slap_schema.si_ad_ref;
1300 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
1302 if (op->o_callback && op->o_callback->sc_sendreference) {
1303 return op->o_callback->sc_sendreference( be, conn, op, e, refs, ctrls, v2refs );
1307 LDAP_LOG( OPERATION, ENTRY,
1308 "send_search_reference: conn %lu dn=\"%s\"\n",
1309 op->o_connid, e ? e->e_dn : "(null)", 0 );
1311 Debug( LDAP_DEBUG_TRACE,
1312 "=> send_search_reference: dn=\"%s\"\n",
1313 e ? e->e_dn : "(null)", 0, 0 );
1316 if ( e && ! access_allowed( be, conn, op, e,
1317 ad_entry, NULL, ACL_READ, NULL ) )
1320 LDAP_LOG( ACL, INFO,
1321 "send_search_reference: conn %lu "
1322 "access to entry %s not allowed\n",
1323 op->o_connid, e->e_dn, 0 );
1325 Debug( LDAP_DEBUG_ACL,
1326 "send_search_reference: access to entry not allowed\n",
1333 if ( e && ! access_allowed( be, conn, op, e,
1334 ad_ref, NULL, ACL_READ, NULL ) )
1337 LDAP_LOG( ACL, INFO,
1338 "send_search_reference: conn %lu access "
1339 "to reference not allowed.\n", op->o_connid, 0, 0 );
1341 Debug( LDAP_DEBUG_ACL,
1342 "send_search_reference: access "
1343 "to reference not allowed\n",
1350 if( op->o_noreferrals ) {
1352 LDAP_LOG( OPERATION, ERR,
1353 "send_search_reference: conn %lu noreferrals control in (%s).\n",
1354 op->o_connid, e->e_dn, 0 );
1356 Debug( LDAP_DEBUG_ANY,
1357 "send_search_reference: noreferrals control in (%s)\n",
1364 if( refs == NULL ) {
1366 LDAP_LOG( OPERATION, ERR,
1367 "send_search_reference: conn %lu null ref in (%s).\n",
1368 op->o_connid, e ? e->e_dn : "(null)", 0 );
1370 Debug( LDAP_DEBUG_ANY,
1371 "send_search_reference: null ref in (%s)\n",
1372 e ? e->e_dn : "(null)", 0, 0 );
1378 if( op->o_protocol < LDAP_VERSION3 ) {
1379 /* save the references for the result */
1380 if( refs[0].bv_val != NULL ) {
1381 if( value_add( v2refs, refs ) )
1387 #ifdef LDAP_CONNECTIONLESS
1389 ber = op->o_res_ber;
1392 ber_init_w_nullc( ber, LBER_USE_DER );
1394 rc = ber_printf( ber, "{it{W}" /*"}"*/ , op->o_msgid,
1395 LDAP_RES_SEARCH_REFERENCE, refs );
1397 if( rc != -1 && ctrls != NULL ) {
1398 rc = send_ldap_controls( ber, ctrls );
1402 rc = ber_printf( ber, /*"{"*/ "N}", op->o_msgid,
1403 LDAP_RES_SEARCH_REFERENCE, refs );
1408 LDAP_LOG( OPERATION, ERR,
1409 "send_search_reference: conn %lu "
1410 "ber_printf failed.\n", op->o_connid, 0, 0 );
1412 Debug( LDAP_DEBUG_ANY,
1413 "send_search_reference: ber_printf failed\n", 0, 0, 0 );
1416 #ifdef LDAP_CONNECTIONLESS
1417 if (conn->c_is_udp == 0)
1419 ber_free_buf( ber );
1420 send_ldap_result( conn, op, LDAP_OTHER,
1421 NULL, "encode DN error", NULL, NULL );
1425 #ifdef LDAP_CONNECTIONLESS
1426 if (conn->c_is_udp == 0) {
1428 bytes = op->o_noop ? 0 : send_ldap_ber( conn, ber );
1429 ber_free_buf( ber );
1431 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1432 num_bytes_sent += bytes;
1435 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1436 #ifdef LDAP_CONNECTIONLESS
1440 Statslog( LDAP_DEBUG_STATS2, "conn=%lu op=%lu REF dn=\"%s\"\n",
1441 conn->c_connid, op->o_opid, e ? e->e_dn : "(null)", 0, 0 );
1444 LDAP_LOG( OPERATION, ENTRY,
1445 "send_search_reference: conn %lu exit.\n", op->o_connid, 0, 0 );
1447 Debug( LDAP_DEBUG_TRACE, "<= send_search_reference\n", 0, 0, 0 );
1465 *code = LDAP_SUCCESS;
1469 if ( strncasecmp( s, "RESULT", 6 ) != 0 ) {
1471 LDAP_LOG( OPERATION, INFO,
1472 "str2result: (%s), expecting \"RESULT\"\n", s, 0, 0 );
1474 Debug( LDAP_DEBUG_ANY, "str2result (%s) expecting \"RESULT\"\n",
1482 while ( (s = strchr( s, '\n' )) != NULL ) {
1487 if ( (c = strchr( s, ':' )) != NULL ) {
1491 if ( strncasecmp( s, "code", 4 ) == 0 ) {
1495 } else if ( strncasecmp( s, "matched", 7 ) == 0 ) {
1499 } else if ( strncasecmp( s, "info", 4 ) == 0 ) {
1505 LDAP_LOG( OPERATION, INFO, "str2result: (%s) unknown.\n", s, 0, 0 );
1507 Debug( LDAP_DEBUG_ANY, "str2result (%s) unknown\n",