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 #ifndef LDAP_CLIENT_UPDATE
228 assert( ctrls == NULL ); /* ctrls not implemented */
229 #endif /* LDAP_CLIENT_UPDATE */
231 ber_init_w_nullc( ber, LBER_USE_DER );
234 LDAP_LOG( OPERATION, ENTRY,
235 "send_ldap_response: msgid=%d tag=%lu err=%d\n",
238 Debug( LDAP_DEBUG_TRACE,
239 "send_ldap_response: msgid=%d tag=%lu err=%d\n",
245 LDAP_LOG( OPERATION, ARGS,
246 "send_ldap_response: conn %lu ref=\"%s\"\n",
247 conn ? conn->c_connid : 0,
248 ref[0].bv_val ? ref[0].bv_val : "NULL" , 0 );
250 Debug( LDAP_DEBUG_ARGS, "send_ldap_response: ref=\"%s\"\n",
251 ref[0].bv_val ? ref[0].bv_val : "NULL",
256 #ifdef LDAP_CONNECTIONLESS
257 if (conn->c_is_udp) {
258 rc = ber_write(ber, (char *)&op->o_peeraddr, sizeof(struct sockaddr), 0);
259 if (rc != sizeof(struct sockaddr)) {
261 LDAP_LOG( OPERATION, ERR,
262 "send_ldap_response: conn %lu ber_write failed\n",
263 conn ? conn->c_connid : 0 , 0, 0);
265 Debug( LDAP_DEBUG_ANY, "ber_write failed\n", 0, 0, 0 );
271 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2) {
272 rc = ber_printf( ber, "{is{t{ess" /*"}}}"*/,
274 matched == NULL ? "" : matched,
275 text == NULL ? "" : text );
279 rc = ber_printf( ber, "{it{ess" /*"}}"*/,
281 matched == NULL ? "" : matched,
282 text == NULL ? "" : text );
287 assert( err == LDAP_REFERRAL );
288 rc = ber_printf( ber, "t{W}",
289 LDAP_TAG_REFERRAL, ref );
291 assert( err != LDAP_REFERRAL );
295 if( rc != -1 && sasldata != NULL ) {
296 rc = ber_printf( ber, "tO",
297 LDAP_TAG_SASL_RES_CREDS, sasldata );
300 if( rc != -1 && resoid != NULL ) {
301 rc = ber_printf( ber, "ts",
302 LDAP_TAG_EXOP_RES_OID, resoid );
305 if( rc != -1 && resdata != NULL ) {
306 rc = ber_printf( ber, "tO",
307 LDAP_TAG_EXOP_RES_VALUE, resdata );
311 rc = ber_printf( ber, /*"{"*/ "N}" );
314 if( rc != -1 && ctrls != NULL ) {
315 rc = send_ldap_controls( ber, ctrls );
319 rc = ber_printf( ber, /*"{"*/ "N}" );
322 #ifdef LDAP_CONNECTIONLESS
323 if( conn->c_is_udp && op->o_protocol == LDAP_VERSION2 && rc != -1 ) {
324 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 );
342 bytes = send_ldap_ber( conn, ber );
347 LDAP_LOG( OPERATION, ERR,
348 "send_ldap_response: conn %lu ber write failed\n",
349 conn ? conn->c_connid : 0, 0, 0 );
351 Debug( LDAP_DEBUG_ANY,
352 "send_ldap_response: ber write failed\n",
359 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
360 num_bytes_sent += bytes;
362 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
368 send_ldap_disconnect(
379 #define LDAP_UNSOLICITED_ERROR(e) \
380 ( (e) == LDAP_PROTOCOL_ERROR \
381 || (e) == LDAP_STRONG_AUTH_REQUIRED \
382 || (e) == LDAP_UNAVAILABLE )
384 assert( LDAP_UNSOLICITED_ERROR( err ) );
387 LDAP_LOG( OPERATION, ENTRY,
388 "send_ldap_disconnect: conn %lu %d:%s\n",
389 conn ? conn->c_connid : 0, err, text ? text : "" );
391 Debug( LDAP_DEBUG_TRACE,
392 "send_ldap_disconnect %d:%s\n",
393 err, text ? text : "", NULL );
397 if ( op->o_protocol < LDAP_VERSION3 ) {
399 tag = req2res( op->o_tag );
400 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
403 reqoid = LDAP_NOTICE_DISCONNECT;
404 tag = LDAP_RES_EXTENDED;
408 send_ldap_response( conn, op, tag, msgid,
409 err, NULL, text, NULL,
410 reqoid, NULL, NULL, NULL );
412 Statslog( LDAP_DEBUG_STATS,
413 "conn=%lu op=%lu DISCONNECT tag=%lu err=%d text=%s\n",
414 op->o_connid, op->o_opid, tag, err, text ? text : "" );
432 assert( !LDAP_API_ERROR( err ) );
435 LDAP_LOG( OPERATION, ENTRY,
436 "send_ldap_result : conn %lu op=%lu p=%d\n",
437 op->o_connid, op->o_opid, op->o_protocol );
439 Debug( LDAP_DEBUG_TRACE,
440 "send_ldap_result: conn=%lu op=%lu p=%d\n",
441 op->o_connid, op->o_opid, op->o_protocol );
445 LDAP_LOG( OPERATION, ARGS,
446 "send_ldap_result: err=%d matched=\"%s\" text=\"%s\"\n",
447 err, matched ? matched : "", text ? text : "" );
449 Debug( LDAP_DEBUG_ARGS,
450 "send_ldap_result: err=%d matched=\"%s\" text=\"%s\"\n",
451 err, matched ? matched : "", text ? text : "" );
457 LDAP_LOG( OPERATION, ARGS,
458 "send_ldap_result: referral=\"%s\"\n",
459 ref[0].bv_val ? ref[0].bv_val : "NULL", 0, 0 );
461 Debug( LDAP_DEBUG_ARGS,
462 "send_ldap_result: referral=\"%s\"\n",
463 ref[0].bv_val ? ref[0].bv_val : "NULL",
468 assert( err != LDAP_PARTIAL_RESULTS );
470 if ( err == LDAP_REFERRAL ) {
472 err = LDAP_NO_SUCH_OBJECT;
473 } else if ( op->o_protocol < LDAP_VERSION3 ) {
474 err = LDAP_PARTIAL_RESULTS;
478 if ( op->o_protocol < LDAP_VERSION3 ) {
479 tmp = v2ref( ref, text );
484 tag = req2res( op->o_tag );
485 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
487 send_ldap_response( conn, op, tag, msgid,
488 err, matched, text, ref,
489 NULL, NULL, NULL, ctrls );
491 Statslog( LDAP_DEBUG_STATS,
492 "conn=%lu op=%lu RESULT tag=%lu err=%d text=%s\n",
493 op->o_connid, op->o_opid, tag, err, text ? text : "" );
516 LDAP_LOG( OPERATION, ENTRY,
517 "send_ldap_sasl: conn %lu err=%d len=%lu\n",
518 op->o_connid, err, cred ? cred->bv_len : -1 );
520 Debug( LDAP_DEBUG_TRACE, "send_ldap_sasl: err=%d len=%ld\n",
521 err, cred ? (long) cred->bv_len : -1, NULL );
525 tag = req2res( op->o_tag );
526 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
528 send_ldap_response( conn, op, tag, msgid,
529 err, matched, text, ref,
530 NULL, NULL, cred, ctrls );
542 struct berval *rspdata,
550 LDAP_LOG( OPERATION, ENTRY,
551 "send_ldap_extended: err=%d oid=%s len=%ld\n",
552 err, rspoid ? rspoid : "",
553 rspdata != NULL ? rspdata->bv_len : 0 );
555 Debug( LDAP_DEBUG_TRACE,
556 "send_ldap_extended err=%d oid=%s len=%ld\n",
558 rspoid ? rspoid : "",
559 rspdata != NULL ? rspdata->bv_len : 0 );
563 tag = req2res( op->o_tag );
564 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
566 send_ldap_response( conn, op, tag, msgid,
567 err, matched, text, refs,
568 rspoid, rspdata, NULL, ctrls );
588 assert( !LDAP_API_ERROR( err ) );
590 if (op->o_callback && op->o_callback->sc_sresult) {
591 op->o_callback->sc_sresult(conn, op, err, matched, text, refs,
597 LDAP_LOG( OPERATION, ENTRY,
598 "send_search_result: err=%d matched=\"%s\" text=\"%s\"\n",
599 err, matched ? matched : "", text ? text : "" );
601 Debug( LDAP_DEBUG_TRACE,
602 "send_search_result: err=%d matched=\"%s\" text=\"%s\"\n",
603 err, matched ? matched : "", text ? text : "" );
607 assert( err != LDAP_PARTIAL_RESULTS );
609 if( op->o_protocol < LDAP_VERSION3 ) {
610 /* send references in search results */
611 if( err == LDAP_REFERRAL ) {
612 err = LDAP_PARTIAL_RESULTS;
615 tmp = v2ref( refs, text );
620 /* don't send references in search results */
621 assert( refs == NULL );
624 if( err == LDAP_REFERRAL ) {
629 tag = req2res( op->o_tag );
630 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
632 send_ldap_response( conn, op, tag, msgid,
633 err, matched, text, refs,
634 NULL, NULL, NULL, ctrls );
638 snprintf( nbuf, sizeof nbuf, "%d nentries=%d", err, nentries );
640 Statslog( LDAP_DEBUG_STATS,
641 "conn=%lu op=%lu SEARCH RESULT tag=%lu err=%s text=%s\n",
642 op->o_connid, op->o_opid, tag, nbuf, text ? text : "" );
656 AttributeName *attrs,
662 BerElement *ber = (BerElement *)berbuf;
664 int i, j, rc=-1, bytes;
668 static AccessControlState acl_state_init = ACL_STATE_INIT;
669 AccessControlState acl_state;
671 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
673 /* a_flags: array of flags telling if the i-th element will be
674 * returned or filtered out
675 * e_flags: array of a_flags
677 char **e_flags = NULL;
679 if (op->o_callback && op->o_callback->sc_sendentry) {
680 return op->o_callback->sc_sendentry( be, conn, op, e, attrs,
685 LDAP_LOG( OPERATION, ENTRY,
686 "send_search_entry: conn %lu dn=\"%s\"%s\n",
687 op->o_connid, e->e_dn, attrsonly ? " (attrsOnly)" : "" );
689 Debug( LDAP_DEBUG_TRACE,
690 "=> send_search_entry: dn=\"%s\"%s\n",
691 e->e_dn, attrsonly ? " (attrsOnly)" : "", 0 );
694 if ( ! access_allowed( be, conn, op, e,
695 ad_entry, NULL, ACL_READ, NULL ) )
699 "send_search_entry: conn %lu access to entry (%s) not allowed\n",
700 op->o_connid, e->e_dn, 0 );
702 Debug( LDAP_DEBUG_ACL,
703 "send_search_entry: access to entry not allowed\n",
712 ber_init_w_nullc( ber, LBER_USE_DER );
714 #ifdef LDAP_CONNECTIONLESS
715 if (conn->c_is_udp) {
716 rc = ber_write(ber, (char *)&op->o_peeraddr, sizeof(struct sockaddr), 0);
717 if (rc != sizeof(struct sockaddr)) {
719 LDAP_LOG( OPERATION, ERR,
720 "send_search_entry: conn %lu ber_printf failed\n",
721 conn ? conn->c_connid : 0, 0, 0 );
723 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
729 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2) {
730 rc = ber_printf( ber, "{is{t{O{" /*}}}*/,
731 op->o_msgid, "", LDAP_RES_SEARCH_ENTRY, &e->e_name );
733 #endif /* LDAP_CONNECTIONLESS */
735 rc = ber_printf( ber, "{it{O{" /*}}}*/, op->o_msgid,
736 LDAP_RES_SEARCH_ENTRY, &e->e_name );
741 LDAP_LOG( OPERATION, ERR,
742 "send_search_entry: conn %lu ber_printf failed\n",
743 op->o_connid, 0, 0 );
745 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
749 send_ldap_result( conn, op, LDAP_OTHER,
750 NULL, "encoding DN error", NULL, NULL );
754 /* check for special all user attributes ("*") type */
755 userattrs = ( attrs == NULL ) ? 1
756 : an_find( attrs, &AllUser );
758 /* check for special all operational attributes ("+") type */
759 opattrs = ( attrs == NULL ) ? 0
760 : an_find( attrs, &AllOper );
762 /* create an array of arrays of flags. Each flag corresponds
763 * to particular value of attribute and equals 1 if value matches
764 * to ValuesReturnFilter or 0 if not
766 if ( op->vrFilter != NULL ) {
770 for ( a = e->e_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
771 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ ) k++;
774 size = i * sizeof(char *) + k;
777 e_flags = ch_calloc ( 1, i * sizeof(char *) + k );
778 a_flags = (char *)(e_flags + i);
779 memset( a_flags, 0, k );
780 for ( a = e->e_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
781 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ );
782 e_flags[i] = a_flags;
786 rc = filter_matched_values(be, conn, op, e->e_attrs, &e_flags) ;
789 LDAP_LOG( OPERATION, ERR,
790 "send_search_entry: conn %lu matched values filtering failed\n",
791 conn ? conn->c_connid : 0, 0, 0 );
793 Debug( LDAP_DEBUG_ANY,
794 "matched values filtering failed\n", 0, 0, 0 );
798 send_ldap_result( conn, op, LDAP_OTHER,
799 NULL, "matched values filtering error",
806 for ( a = e->e_attrs, j = 0; a != NULL; a = a->a_next, j++ ) {
807 AttributeDescription *desc = a->a_desc;
809 if ( attrs == NULL ) {
810 /* all attrs request, skip operational attributes */
811 if( is_at_operational( desc->ad_type ) ) {
816 /* specific attrs requested */
817 if ( is_at_operational( desc->ad_type ) ) {
818 if( !opattrs && !ad_inlist( desc, attrs ) ) {
823 if (!userattrs && !ad_inlist( desc, attrs ) ) {
829 acl_state = acl_state_init;
831 if ( ! access_allowed( be, conn, op, e, desc, NULL,
832 ACL_READ, &acl_state ) )
836 "send_search_entry: conn %lu access to attribute %s not "
837 "allowed\n", op->o_connid, desc->ad_cname.bv_val, 0 );
839 Debug( LDAP_DEBUG_ACL, "acl: "
840 "access to attribute %s not allowed\n",
841 desc->ad_cname.bv_val, 0, 0 );
846 if (( rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname )) == -1 ) {
848 LDAP_LOG( OPERATION, ERR,
849 "send_search_entry: conn %lu ber_printf failed\n",
850 op->o_connid, 0, 0 );
852 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
856 send_ldap_result( conn, op, LDAP_OTHER,
857 NULL, "encoding description error", NULL, NULL );
862 for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
863 if ( ! access_allowed( be, conn, op, e,
864 desc, &a->a_vals[i], ACL_READ, &acl_state ) )
868 "send_search_entry: conn %lu "
869 "access to attribute %s, value %d not allowed\n",
870 op->o_connid, desc->ad_cname.bv_val, i );
872 Debug( LDAP_DEBUG_ACL,
873 "acl: access to attribute %s, "
874 "value %d not allowed\n",
875 desc->ad_cname.bv_val, i, 0 );
881 if ( op->vrFilter && e_flags[j][i] == 0 ){
885 if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
887 LDAP_LOG( OPERATION, ERR,
888 "send_search_entry: conn %lu "
889 "ber_printf failed.\n", op->o_connid, 0, 0 );
891 Debug( LDAP_DEBUG_ANY,
892 "ber_printf failed\n", 0, 0, 0 );
896 send_ldap_result( conn, op, LDAP_OTHER,
897 NULL, "encoding values error",
904 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
906 LDAP_LOG( OPERATION, ERR,
907 "send_search_entry: conn %lu ber_printf failed\n",
908 op->o_connid, 0, 0 );
910 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
914 send_ldap_result( conn, op, LDAP_OTHER,
915 NULL, "encode end error", NULL, NULL );
920 /* eventually will loop through generated operational attributes */
921 /* only have subschemaSubentry implemented */
922 aa = backend_operational( be, conn, op, e, attrs, opattrs );
924 if ( aa != NULL && op->vrFilter != NULL ) {
928 for ( a = aa, i=0; a != NULL; a = a->a_next, i++ ) {
929 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ ) k++;
932 size = i * sizeof(char *) + k;
934 char *a_flags, **tmp;
937 * Reuse previous memory - we likely need less space
938 * for operational attributes
940 tmp = ch_realloc ( e_flags, i * sizeof(char *) + k );
943 LDAP_LOG( OPERATION, ERR,
944 "send_search_entry: conn %lu "
946 "for matched values filtering\n",
947 conn ? conn->c_connid : 0, 0, 0);
949 Debug( LDAP_DEBUG_ANY,
950 "send_search_entry: conn %lu "
952 "for matched values filtering\n",
953 conn ? conn->c_connid : 0, 0, 0 );
957 send_ldap_result( conn, op, LDAP_NO_MEMORY,
958 NULL, NULL, NULL, NULL );
962 a_flags = (char *)(e_flags + i);
963 memset( a_flags, 0, k );
964 for ( a = aa, i=0; a != NULL; a = a->a_next, i++ ) {
965 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ );
966 e_flags[i] = a_flags;
969 rc = filter_matched_values(be, conn, op, aa, &e_flags) ;
973 LDAP_LOG( OPERATION, ERR,
974 "send_search_entry: conn %lu "
975 "matched values filtering failed\n",
976 conn ? conn->c_connid : 0, 0, 0);
978 Debug( LDAP_DEBUG_ANY,
979 "matched values filtering failed\n", 0, 0, 0 );
983 send_ldap_result( conn, op, LDAP_OTHER,
984 NULL, "matched values filtering error",
991 for (a = aa, j=0; a != NULL; a = a->a_next, j++ ) {
992 AttributeDescription *desc = a->a_desc;
994 if ( attrs == NULL ) {
995 /* all attrs request, skip operational attributes */
996 if( is_at_operational( desc->ad_type ) ) {
1001 /* specific attrs requested */
1002 if( is_at_operational( desc->ad_type ) ) {
1003 if( !opattrs && !ad_inlist( desc, attrs ) ) {
1007 if (!userattrs && !ad_inlist( desc, attrs ) )
1014 acl_state = acl_state_init;
1016 if ( ! access_allowed( be, conn, op, e, desc, NULL,
1017 ACL_READ, &acl_state ) )
1020 LDAP_LOG( ACL, INFO,
1021 "send_search_entry: conn %lu "
1022 "access to attribute %s not allowed\n",
1023 op->o_connid, desc->ad_cname.bv_val, 0 );
1025 Debug( LDAP_DEBUG_ACL, "acl: access to attribute %s "
1027 desc->ad_cname.bv_val, 0, 0 );
1033 rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname );
1036 LDAP_LOG( OPERATION, ERR,
1037 "send_search_entry: conn %lu "
1038 "ber_printf failed\n", op->o_connid, 0, 0 );
1040 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1043 ber_free_buf( ber );
1044 send_ldap_result( conn, op, LDAP_OTHER,
1045 NULL, "encoding description error", NULL, NULL );
1051 if ( ! attrsonly ) {
1052 for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
1053 if ( ! access_allowed( be, conn, op, e,
1054 desc, &a->a_vals[i], ACL_READ, &acl_state ) )
1057 LDAP_LOG( ACL, INFO,
1058 "send_search_entry: conn %lu "
1059 "access to %s, value %d not allowed\n",
1060 op->o_connid, desc->ad_cname.bv_val, i );
1062 Debug( LDAP_DEBUG_ACL,
1063 "acl: access to attribute %s, "
1064 "value %d not allowed\n",
1065 desc->ad_cname.bv_val, i, 0 );
1071 if ( op->vrFilter && e_flags[j][i] == 0 ){
1075 if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
1077 LDAP_LOG( OPERATION, ERR,
1078 "send_search_entry: conn %lu ber_printf failed\n",
1079 op->o_connid, 0, 0 );
1081 Debug( LDAP_DEBUG_ANY,
1082 "ber_printf failed\n", 0, 0, 0 );
1085 ber_free_buf( ber );
1086 send_ldap_result( conn, op, LDAP_OTHER,
1087 NULL, "encoding values error",
1096 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
1098 LDAP_LOG( OPERATION, ERR,
1099 "send_search_entry: conn %lu ber_printf failed\n",
1100 op->o_connid, 0, 0 );
1102 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1105 ber_free_buf( ber );
1106 send_ldap_result( conn, op, LDAP_OTHER,
1107 NULL, "encode end error", NULL, NULL );
1121 rc = ber_printf( ber, /*{{*/ "}N}" );
1123 if( rc != -1 && ctrls != NULL ) {
1124 rc = send_ldap_controls( ber, ctrls );
1128 rc = ber_printf( ber, /*{*/ "N}" );
1131 #ifdef LDAP_CONNECTIONLESS
1132 if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2 && rc != -1)
1133 rc = ber_printf( ber, "}" );
1137 LDAP_LOG( OPERATION, ERR,
1138 "send_search_entry: conn %lu ber_printf failed\n",
1139 op->o_connid, 0, 0 );
1141 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1144 ber_free_buf( ber );
1145 send_ldap_result( conn, op, LDAP_OTHER,
1146 NULL, "encode entry end error", NULL, NULL );
1150 bytes = op->o_noop ? 0 : send_ldap_ber( conn, ber );
1151 ber_free_buf( ber );
1155 LDAP_LOG( OPERATION, ERR,
1156 "send_search_entry: conn %lu ber write failed.\n",
1157 op->o_connid, 0, 0 );
1159 Debug( LDAP_DEBUG_ANY,
1160 "send_search_entry: ber write failed\n",
1167 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1168 num_bytes_sent += bytes;
1171 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1173 Statslog( LDAP_DEBUG_STATS2, "conn=%lu op=%lu ENTRY dn=\"%s\"\n",
1174 conn->c_connid, op->o_opid, e->e_dn, 0, 0 );
1177 LDAP_LOG( OPERATION, ENTRY,
1178 "send_search_entry: conn %lu exit.\n", op->o_connid, 0, 0 );
1180 Debug( LDAP_DEBUG_TRACE, "<= send_search_entry\n", 0, 0, 0 );
1186 if ( e_flags ) free( e_flags );
1191 send_search_reference(
1197 LDAPControl **ctrls,
1202 BerElement *ber = (BerElement *)berbuf;
1206 AttributeDescription *ad_ref = slap_schema.si_ad_ref;
1207 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
1210 LDAP_LOG( OPERATION, ENTRY,
1211 "send_search_reference: conn %lu dn=\"%s\"\n",
1212 op->o_connid, e ? e->e_dn : "(null)", 0 );
1214 Debug( LDAP_DEBUG_TRACE,
1215 "=> send_search_reference: dn=\"%s\"\n",
1216 e ? e->e_dn : "(null)", 0, 0 );
1220 if ( e && ! access_allowed( be, conn, op, e,
1221 ad_entry, NULL, ACL_READ, NULL ) )
1224 LDAP_LOG( ACL, INFO,
1225 "send_search_reference: conn %lu "
1226 "access to entry %s not allowed\n",
1227 op->o_connid, e->e_dn, 0 );
1229 Debug( LDAP_DEBUG_ACL,
1230 "send_search_reference: access to entry not allowed\n",
1237 if ( e && ! access_allowed( be, conn, op, e,
1238 ad_ref, NULL, ACL_READ, NULL ) )
1241 LDAP_LOG( ACL, INFO,
1242 "send_search_reference: conn %lu access "
1243 "to reference not allowed.\n", op->o_connid, 0, 0 );
1245 Debug( LDAP_DEBUG_ACL,
1246 "send_search_reference: access "
1247 "to reference not allowed\n",
1254 if( refs == NULL ) {
1256 LDAP_LOG( OPERATION, ERR,
1257 "send_search_reference: conn %lu null ref in (%s).\n",
1258 op->o_connid, e ? e->e_dn : "(null)", 0 );
1260 Debug( LDAP_DEBUG_ANY,
1261 "send_search_reference: null ref in (%s)\n",
1262 e ? e->e_dn : "(null)", 0, 0 );
1268 if( op->o_protocol < LDAP_VERSION3 ) {
1269 /* save the references for the result */
1270 if( refs[0].bv_val != NULL ) {
1271 value_add( v2refs, refs );
1276 ber_init_w_nullc( ber, LBER_USE_DER );
1278 rc = ber_printf( ber, "{it{W}" /*"}"*/ , op->o_msgid,
1279 LDAP_RES_SEARCH_REFERENCE, refs );
1281 if( rc != -1 && ctrls != NULL ) {
1282 rc = send_ldap_controls( ber, ctrls );
1286 rc = ber_printf( ber, /*"{"*/ "N}", op->o_msgid,
1287 LDAP_RES_SEARCH_REFERENCE, refs );
1292 LDAP_LOG( OPERATION, ERR,
1293 "send_search_reference: conn %lu "
1294 "ber_printf failed.\n", op->o_connid, 0, 0 );
1296 Debug( LDAP_DEBUG_ANY,
1297 "send_search_reference: ber_printf failed\n", 0, 0, 0 );
1300 ber_free_buf( ber );
1301 send_ldap_result( conn, op, LDAP_OTHER,
1302 NULL, "encode DN error", NULL, NULL );
1306 bytes = op->o_noop ? 0 : send_ldap_ber( conn, ber );
1307 ber_free_buf( ber );
1309 ldap_pvt_thread_mutex_lock( &num_sent_mutex );
1310 num_bytes_sent += bytes;
1313 ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
1315 Statslog( LDAP_DEBUG_STATS2, "conn=%lu op=%lu REF dn=\"%s\"\n",
1316 conn->c_connid, op->o_opid, e ? e->e_dn : "(null)", 0, 0 );
1319 LDAP_LOG( OPERATION, ENTRY,
1320 "send_search_reference: conn %lu exit.\n", op->o_connid, 0, 0 );
1322 Debug( LDAP_DEBUG_TRACE, "<= send_search_reference\n", 0, 0, 0 );
1340 *code = LDAP_SUCCESS;
1344 if ( strncasecmp( s, "RESULT", 6 ) != 0 ) {
1346 LDAP_LOG( OPERATION, INFO,
1347 "str2result: (%s), expecting \"RESULT\"\n", s, 0, 0 );
1349 Debug( LDAP_DEBUG_ANY, "str2result (%s) expecting \"RESULT\"\n",
1357 while ( (s = strchr( s, '\n' )) != NULL ) {
1362 if ( (c = strchr( s, ':' )) != NULL ) {
1366 if ( strncasecmp( s, "code", 4 ) == 0 ) {
1370 } else if ( strncasecmp( s, "matched", 7 ) == 0 ) {
1374 } else if ( strncasecmp( s, "info", 4 ) == 0 ) {
1380 LDAP_LOG( OPERATION, INFO, "str2result: (%s) unknown.\n", s, 0, 0 );
1382 Debug( LDAP_DEBUG_ANY, "str2result (%s) unknown\n",