1 /* result.c - routines to send ldap results, errors, and referrals */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2009 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
16 /* Portions Copyright (c) 1995 Regents of the University of Michigan.
17 * All rights reserved.
19 * Redistribution and use in source and binary forms are permitted
20 * provided that this notice is preserved and that due credit is given
21 * to the University of Michigan at Ann Arbor. The name of the University
22 * may not be used to endorse or promote products derived from this
23 * software without specific prior written permission. This software
24 * is provided ``as is'' without express or implied warranty.
31 #include <ac/socket.h>
33 #include <ac/string.h>
36 #include <ac/unistd.h>
40 const struct berval slap_dummy_bv = BER_BVNULL;
42 int slap_null_cb( Operation *op, SlapReply *rs )
47 int slap_freeself_cb( Operation *op, SlapReply *rs )
49 assert( op->o_callback != NULL );
51 op->o_tmpfree( op->o_callback, op->o_tmpmemctx );
52 op->o_callback = NULL;
54 return SLAP_CB_CONTINUE;
57 static char *v2ref( BerVarray ref, const char *text )
59 size_t len = 0, i = 0;
64 return ch_strdup(text);
72 if (text[len-1] != '\n') {
77 v2 = ch_malloc( len+i+sizeof("Referral:") );
85 strcpy( v2+len, "Referral:" );
86 len += sizeof("Referral:");
88 for( i=0; ref[i].bv_val != NULL; i++ ) {
89 v2 = ch_realloc( v2, len + ref[i].bv_len + 1 );
91 AC_MEMCPY(&v2[len], ref[i].bv_val, ref[i].bv_len );
93 if (ref[i].bv_val[ref[i].bv_len-1] != '/') {
103 slap_req2res( ber_tag_t tag )
108 case LDAP_REQ_COMPARE:
109 case LDAP_REQ_EXTENDED:
110 case LDAP_REQ_MODIFY:
111 case LDAP_REQ_MODRDN:
115 case LDAP_REQ_DELETE:
116 tag = LDAP_RES_DELETE;
119 case LDAP_REQ_ABANDON:
120 case LDAP_REQ_UNBIND:
124 case LDAP_REQ_SEARCH:
125 tag = LDAP_RES_SEARCH_RESULT;
135 static long send_ldap_ber(
139 Connection *conn = op->o_conn;
144 ber_get_option( ber, LBER_OPT_BER_BYTES_TO_WRITE, &bytes );
146 /* write only one pdu at a time - wait til it's our turn */
147 ldap_pvt_thread_mutex_lock( &conn->c_write1_mutex );
148 if ( op->o_abandon || connection_state_closing( conn )) {
149 ldap_pvt_thread_mutex_unlock( &conn->c_write1_mutex );
152 while ( conn->c_writers > 0 ) {
153 ldap_pvt_thread_cond_wait( &conn->c_write1_cv, &conn->c_write1_mutex );
155 /* connection was closed under us */
156 if ( conn->c_writers < 0 ) {
158 /* we're the last waiter, let the closer continue */
159 if ( conn->c_writers == -1 )
160 ldap_pvt_thread_cond_signal( &conn->c_write1_cv );
166 ldap_pvt_thread_mutex_unlock( &conn->c_write1_mutex );
174 /* lock the connection */
175 if ( ldap_pvt_thread_mutex_trylock( &conn->c_mutex )) {
176 ldap_pvt_thread_mutex_unlock( &conn->c_write1_mutex );
177 ldap_pvt_thread_mutex_lock( &conn->c_write1_mutex );
178 if ( conn->c_writers < 0 ) {
185 if ( ber_flush2( conn->c_sb, ber, LBER_FLUSH_FREE_NEVER ) == 0 ) {
186 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
194 * we got an error. if it's ewouldblock, we need to
195 * wait on the socket being writable. otherwise, figure
196 * it's a hard error and return.
199 Debug( LDAP_DEBUG_CONNS, "ber_flush2 failed errno=%d reason=\"%s\"\n",
200 err, sock_errstr(err), 0 );
202 if ( err != EWOULDBLOCK && err != EAGAIN ) {
204 ldap_pvt_thread_mutex_unlock( &conn->c_write1_mutex );
205 connection_closing( conn, "connection lost on write" );
207 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
211 /* wait for socket to be write-ready */
212 ldap_pvt_thread_mutex_lock( &conn->c_write2_mutex );
213 conn->c_writewaiter = 1;
214 slapd_set_write( conn->c_sd, 2 );
216 ldap_pvt_thread_mutex_unlock( &conn->c_write1_mutex );
217 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
218 ldap_pvt_thread_cond_wait( &conn->c_write2_cv, &conn->c_write2_mutex );
219 conn->c_writewaiter = 0;
220 ldap_pvt_thread_mutex_unlock( &conn->c_write2_mutex );
221 ldap_pvt_thread_mutex_lock( &conn->c_write1_mutex );
222 if ( conn->c_writers < 0 ) {
228 if ( conn->c_writers < 0 ) {
230 if ( !conn->c_writers )
231 ldap_pvt_thread_cond_signal( &conn->c_write1_cv );
234 ldap_pvt_thread_cond_signal( &conn->c_write1_cv );
236 ldap_pvt_thread_mutex_unlock( &conn->c_write1_mutex );
242 send_ldap_control( BerElement *ber, LDAPControl *c )
248 rc = ber_printf( ber, "{s" /*}*/, c->ldctl_oid );
250 if( c->ldctl_iscritical ) {
251 rc = ber_printf( ber, "b",
252 (ber_int_t) c->ldctl_iscritical ) ;
253 if( rc == -1 ) return rc;
256 if( c->ldctl_value.bv_val != NULL ) {
257 rc = ber_printf( ber, "O", &c->ldctl_value );
258 if( rc == -1 ) return rc;
261 rc = ber_printf( ber, /*{*/"N}" );
262 if( rc == -1 ) return rc;
268 send_ldap_controls( Operation *o, BerElement *ber, LDAPControl **c )
275 rc = ber_printf( ber, "t{"/*}*/, LDAP_TAG_CONTROLS );
276 if( rc == -1 ) return rc;
278 for( ; *c != NULL; c++) {
279 rc = send_ldap_control( ber, *c );
280 if( rc == -1 ) return rc;
283 #ifdef SLAP_CONTROL_X_SORTEDRESULTS
284 /* this is a hack to avoid having to modify op->s_ctrls */
285 if( o->o_sortedresults ) {
286 BerElementBuffer berbuf;
287 BerElement *sber = (BerElement *) &berbuf;
289 BER_BVZERO( &sorted.ldctl_value );
290 sorted.ldctl_oid = LDAP_CONTROL_SORTRESPONSE;
291 sorted.ldctl_iscritical = 0;
293 ber_init2( sber, NULL, LBER_USE_DER );
295 ber_printf( sber, "{e}", LDAP_UNWILLING_TO_PERFORM );
297 if( ber_flatten2( ber, &sorted.ldctl_value, 0 ) == -1 ) {
301 (void) ber_free_buf( ber );
303 rc = send_ldap_control( ber, &sorted );
304 if( rc == -1 ) return rc;
308 rc = ber_printf( ber, /*{*/"N}" );
314 * slap_response_play()
316 * plays the callback list; rationale: a callback can
317 * - remove itself from the list, by setting op->o_callback = NULL;
318 * malloc()'ed callbacks should free themselves from inside the
319 * sc_response() function.
320 * - replace itself with another (list of) callback(s), by setting
321 * op->o_callback = a new (list of) callback(s); in this case, it
322 * is the callback's responsibility to to append existing subsequent
323 * callbacks to the end of the list that is passed to the sc_response()
325 * - modify the list of subsequent callbacks by modifying the value
326 * of the sc_next field from inside the sc_response() function; this
327 * case does not require any handling from inside slap_response_play()
329 * To stop execution of the playlist, the sc_response() function must return
330 * a value different from SLAP_SC_CONTINUE.
332 * The same applies to slap_cleanup_play(); only, there is no means to stop
333 * execution of the playlist, since all cleanup functions must be called.
342 slap_callback *sc = op->o_callback, **scp;
344 rc = SLAP_CB_CONTINUE;
345 for ( scp = ≻ *scp; ) {
346 slap_callback *sc_next = (*scp)->sc_next, **sc_nextp = &(*scp)->sc_next;
348 op->o_callback = *scp;
349 if ( op->o_callback->sc_response ) {
350 rc = op->o_callback->sc_response( op, rs );
351 if ( op->o_callback == NULL ) {
352 /* the callback has been removed;
357 } else if ( op->o_callback != *scp ) {
358 /* a new callback has been inserted
359 * in place of the existing one; repair the list */
360 *scp = op->o_callback;
363 if ( rc != SLAP_CB_CONTINUE ) break;
377 slap_callback *sc = op->o_callback, **scp;
379 for ( scp = ≻ *scp; ) {
380 slap_callback *sc_next = (*scp)->sc_next, **sc_nextp = &(*scp)->sc_next;
382 op->o_callback = *scp;
383 if ( op->o_callback->sc_cleanup ) {
384 (void)op->o_callback->sc_cleanup( op, rs );
385 if ( op->o_callback == NULL ) {
386 /* the callback has been removed;
391 } else if ( op->o_callback != *scp ) {
392 /* a new callback has been inserted
393 * after the existing one; repair the list */
394 /* a new callback has been inserted
395 * in place of the existing one; repair the list */
396 *scp = op->o_callback;
399 /* don't care about the result; do all cleanup */
413 BerElementBuffer berbuf;
414 BerElement *ber = (BerElement *) &berbuf;
415 int rc = LDAP_SUCCESS;
418 if ( rs->sr_err == SLAPD_ABANDON || op->o_abandon ) {
423 if ( op->o_callback ) {
424 rc = slap_response_play( op, rs );
425 if ( rc != SLAP_CB_CONTINUE ) {
430 #ifdef LDAP_CONNECTIONLESS
431 if (op->o_conn && op->o_conn->c_is_udp)
436 ber_init_w_nullc( ber, LBER_USE_DER );
437 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
440 Debug( LDAP_DEBUG_TRACE,
441 "send_ldap_response: msgid=%d tag=%lu err=%d\n",
442 rs->sr_msgid, rs->sr_tag, rs->sr_err );
445 Debug( LDAP_DEBUG_ARGS, "send_ldap_response: ref=\"%s\"\n",
446 rs->sr_ref[0].bv_val ? rs->sr_ref[0].bv_val : "NULL",
450 #ifdef LDAP_CONNECTIONLESS
451 if (op->o_conn && op->o_conn->c_is_udp &&
452 op->o_protocol == LDAP_VERSION2 )
454 rc = ber_printf( ber, "t{ess" /*"}"*/,
455 rs->sr_tag, rs->sr_err,
456 rs->sr_matched == NULL ? "" : rs->sr_matched,
457 rs->sr_text == NULL ? "" : rs->sr_text );
460 if ( rs->sr_type == REP_INTERMEDIATE ) {
461 rc = ber_printf( ber, "{it{" /*"}}"*/,
462 rs->sr_msgid, rs->sr_tag );
465 rc = ber_printf( ber, "{it{ess" /*"}}"*/,
466 rs->sr_msgid, rs->sr_tag, rs->sr_err,
467 rs->sr_matched == NULL ? "" : rs->sr_matched,
468 rs->sr_text == NULL ? "" : rs->sr_text );
472 if ( rs->sr_ref != NULL ) {
473 assert( rs->sr_err == LDAP_REFERRAL );
474 rc = ber_printf( ber, "t{W}",
475 LDAP_TAG_REFERRAL, rs->sr_ref );
477 assert( rs->sr_err != LDAP_REFERRAL );
481 if( rc != -1 && rs->sr_type == REP_SASL && rs->sr_sasldata != NULL ) {
482 rc = ber_printf( ber, "tO",
483 LDAP_TAG_SASL_RES_CREDS, rs->sr_sasldata );
487 ( rs->sr_type == REP_EXTENDED || rs->sr_type == REP_INTERMEDIATE ))
489 if ( rs->sr_rspoid != NULL ) {
490 rc = ber_printf( ber, "ts",
491 rs->sr_type == REP_EXTENDED
492 ? LDAP_TAG_EXOP_RES_OID : LDAP_TAG_IM_RES_OID,
495 if( rc != -1 && rs->sr_rspdata != NULL ) {
496 rc = ber_printf( ber, "tO",
497 rs->sr_type == REP_EXTENDED
498 ? LDAP_TAG_EXOP_RES_VALUE : LDAP_TAG_IM_RES_VALUE,
504 rc = ber_printf( ber, /*"{"*/ "N}" );
508 rc = send_ldap_controls( op, ber, rs->sr_ctrls );
512 rc = ber_printf( ber, /*"{"*/ "N}" );
515 #ifdef LDAP_CONNECTIONLESS
516 if( op->o_conn && op->o_conn->c_is_udp && op->o_protocol == LDAP_VERSION2
519 rc = ber_printf( ber, /*"{"*/ "N}" );
524 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
526 #ifdef LDAP_CONNECTIONLESS
527 if (!op->o_conn || op->o_conn->c_is_udp == 0)
536 bytes = send_ldap_ber( op, ber );
537 #ifdef LDAP_CONNECTIONLESS
538 if (!op->o_conn || op->o_conn->c_is_udp == 0)
545 Debug( LDAP_DEBUG_ANY,
546 "send_ldap_response: ber write failed\n",
552 ldap_pvt_thread_mutex_lock( &op->o_counters->sc_mutex );
553 ldap_pvt_mp_add_ulong( op->o_counters->sc_pdu, 1 );
554 ldap_pvt_mp_add_ulong( op->o_counters->sc_bytes, (unsigned long)bytes );
555 ldap_pvt_thread_mutex_unlock( &op->o_counters->sc_mutex );
558 /* Tell caller that we did this for real, as opposed to being
559 * overridden by a callback
561 rc = SLAP_CB_CONTINUE;
564 if ( op->o_callback ) {
565 (void)slap_cleanup_play( op, rs );
568 if ( rs->sr_flags & REP_MATCHED_MUSTBEFREED ) {
569 rs->sr_flags ^= REP_MATCHED_MUSTBEFREED; /* paranoia */
570 if ( rs->sr_matched ) {
571 free( (char *)rs->sr_matched );
572 rs->sr_matched = NULL;
576 if ( rs->sr_flags & REP_REF_MUSTBEFREED ) {
577 rs->sr_flags ^= REP_REF_MUSTBEFREED; /* paranoia */
579 ber_bvarray_free( rs->sr_ref );
584 if ( rs->sr_flags & REP_CTRLS_MUSTBEFREED ) {
585 rs->sr_flags ^= REP_CTRLS_MUSTBEFREED; /* paranoia */
586 if ( rs->sr_ctrls ) {
587 slap_free_ctrls( op, rs->sr_ctrls );
597 send_ldap_disconnect( Operation *op, SlapReply *rs )
599 #define LDAP_UNSOLICITED_ERROR(e) \
600 ( (e) == LDAP_PROTOCOL_ERROR \
601 || (e) == LDAP_STRONG_AUTH_REQUIRED \
602 || (e) == LDAP_UNAVAILABLE )
604 assert( LDAP_UNSOLICITED_ERROR( rs->sr_err ) );
606 rs->sr_type = REP_EXTENDED;
608 Debug( LDAP_DEBUG_TRACE,
609 "send_ldap_disconnect %d:%s\n",
610 rs->sr_err, rs->sr_text ? rs->sr_text : "", NULL );
612 if ( op->o_protocol < LDAP_VERSION3 ) {
613 rs->sr_rspoid = NULL;
614 rs->sr_tag = slap_req2res( op->o_tag );
615 rs->sr_msgid = (rs->sr_tag != LBER_SEQUENCE) ? op->o_msgid : 0;
618 rs->sr_rspoid = LDAP_NOTICE_DISCONNECT;
619 rs->sr_tag = LDAP_RES_EXTENDED;
620 rs->sr_msgid = LDAP_RES_UNSOLICITED;
623 if ( send_ldap_response( op, rs ) == SLAP_CB_CONTINUE ) {
624 Statslog( LDAP_DEBUG_STATS,
625 "%s DISCONNECT tag=%lu err=%d text=%s\n",
626 op->o_log_prefix, rs->sr_tag, rs->sr_err,
627 rs->sr_text ? rs->sr_text : "", 0 );
632 slap_send_ldap_result( Operation *op, SlapReply *rs )
635 const char *otext = rs->sr_text;
636 BerVarray oref = rs->sr_ref;
638 rs->sr_type = REP_RESULT;
640 /* Propagate Abandons so that cleanup callbacks can be processed */
641 if ( rs->sr_err == SLAPD_ABANDON || op->o_abandon )
644 assert( !LDAP_API_ERROR( rs->sr_err ) );
646 Debug( LDAP_DEBUG_TRACE,
647 "send_ldap_result: %s p=%d\n",
648 op->o_log_prefix, op->o_protocol, 0 );
650 Debug( LDAP_DEBUG_ARGS,
651 "send_ldap_result: err=%d matched=\"%s\" text=\"%s\"\n",
652 rs->sr_err, rs->sr_matched ? rs->sr_matched : "",
653 rs->sr_text ? rs->sr_text : "" );
657 Debug( LDAP_DEBUG_ARGS,
658 "send_ldap_result: referral=\"%s\"\n",
659 rs->sr_ref[0].bv_val ? rs->sr_ref[0].bv_val : "NULL",
663 assert( rs->sr_err != LDAP_PARTIAL_RESULTS );
665 if ( rs->sr_err == LDAP_REFERRAL ) {
666 if( op->o_domain_scope ) rs->sr_ref = NULL;
668 if( rs->sr_ref == NULL ) {
669 rs->sr_err = LDAP_NO_SUCH_OBJECT;
670 } else if ( op->o_protocol < LDAP_VERSION3 ) {
671 rs->sr_err = LDAP_PARTIAL_RESULTS;
675 if ( op->o_protocol < LDAP_VERSION3 ) {
676 tmp = v2ref( rs->sr_ref, rs->sr_text );
682 rs->sr_tag = slap_req2res( op->o_tag );
683 rs->sr_msgid = (rs->sr_tag != LBER_SEQUENCE) ? op->o_msgid : 0;
685 if ( rs->sr_flags & REP_REF_MUSTBEFREED ) {
686 if ( rs->sr_ref == NULL ) {
687 rs->sr_flags ^= REP_REF_MUSTBEFREED;
688 ber_bvarray_free( oref );
690 oref = NULL; /* send_ldap_response() will free rs->sr_ref if != NULL */
693 if ( send_ldap_response( op, rs ) == SLAP_CB_CONTINUE ) {
694 if ( op->o_tag == LDAP_REQ_SEARCH ) {
695 Statslog( LDAP_DEBUG_STATS,
696 "%s SEARCH RESULT tag=%lu err=%d nentries=%d text=%s\n",
697 op->o_log_prefix, rs->sr_tag, rs->sr_err,
698 rs->sr_nentries, rs->sr_text ? rs->sr_text : "" );
700 Statslog( LDAP_DEBUG_STATS,
701 "%s RESULT tag=%lu err=%d text=%s\n",
702 op->o_log_prefix, rs->sr_tag, rs->sr_err,
703 rs->sr_text ? rs->sr_text : "", 0 );
707 if( tmp != NULL ) ch_free(tmp);
713 send_ldap_sasl( Operation *op, SlapReply *rs )
715 rs->sr_type = REP_SASL;
716 Debug( LDAP_DEBUG_TRACE, "send_ldap_sasl: err=%d len=%ld\n",
718 rs->sr_sasldata ? (long) rs->sr_sasldata->bv_len : -1, NULL );
720 rs->sr_tag = slap_req2res( op->o_tag );
721 rs->sr_msgid = (rs->sr_tag != LBER_SEQUENCE) ? op->o_msgid : 0;
723 if ( send_ldap_response( op, rs ) == SLAP_CB_CONTINUE ) {
724 Statslog( LDAP_DEBUG_STATS,
725 "%s RESULT tag=%lu err=%d text=%s\n",
726 op->o_log_prefix, rs->sr_tag, rs->sr_err,
727 rs->sr_text ? rs->sr_text : "", 0 );
732 slap_send_ldap_extended( Operation *op, SlapReply *rs )
734 rs->sr_type = REP_EXTENDED;
736 Debug( LDAP_DEBUG_TRACE,
737 "send_ldap_extended: err=%d oid=%s len=%ld\n",
739 rs->sr_rspoid ? rs->sr_rspoid : "",
740 rs->sr_rspdata != NULL ? rs->sr_rspdata->bv_len : 0 );
742 rs->sr_tag = slap_req2res( op->o_tag );
743 rs->sr_msgid = (rs->sr_tag != LBER_SEQUENCE) ? op->o_msgid : 0;
745 if ( send_ldap_response( op, rs ) == SLAP_CB_CONTINUE ) {
746 Statslog( LDAP_DEBUG_STATS,
747 "%s RESULT oid=%s err=%d text=%s\n",
748 op->o_log_prefix, rs->sr_rspoid ? rs->sr_rspoid : "",
749 rs->sr_err, rs->sr_text ? rs->sr_text : "", 0 );
754 slap_send_ldap_intermediate( Operation *op, SlapReply *rs )
756 rs->sr_type = REP_INTERMEDIATE;
757 Debug( LDAP_DEBUG_TRACE,
758 "send_ldap_intermediate: err=%d oid=%s len=%ld\n",
760 rs->sr_rspoid ? rs->sr_rspoid : "",
761 rs->sr_rspdata != NULL ? rs->sr_rspdata->bv_len : 0 );
762 rs->sr_tag = LDAP_RES_INTERMEDIATE;
763 rs->sr_msgid = op->o_msgid;
764 if ( send_ldap_response( op, rs ) == SLAP_CB_CONTINUE ) {
765 Statslog( LDAP_DEBUG_STATS2,
766 "%s INTERM oid=%s\n",
768 rs->sr_rspoid ? rs->sr_rspoid : "", 0, 0, 0 );
775 * LDAP_SUCCESS entry sent
776 * LDAP_OTHER entry not sent (other)
777 * LDAP_INSUFFICIENT_ACCESS entry not sent (ACL)
778 * LDAP_UNAVAILABLE entry not sent (connection closed)
779 * LDAP_SIZELIMIT_EXCEEDED entry not sent (caller must send sizelimitExceeded)
783 slap_send_search_entry( Operation *op, SlapReply *rs )
785 BerElementBuffer berbuf;
786 BerElement *ber = (BerElement *) &berbuf;
788 int i, j, rc = LDAP_UNAVAILABLE, bytes;
790 AccessControlState acl_state = ACL_STATE_INIT;
792 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
794 /* a_flags: array of flags telling if the i-th element will be
795 * returned or filtered out
796 * e_flags: array of a_flags
798 char **e_flags = NULL;
800 if ( op->ors_slimit >= 0 && rs->sr_nentries >= op->ors_slimit ) {
801 return LDAP_SIZELIMIT_EXCEEDED;
804 /* Every 64 entries, check for thread pool pause */
805 if ( ( ( rs->sr_nentries & 0x3f ) == 0x3f ) &&
806 ldap_pvt_thread_pool_pausing( &connection_pool ) > 0 )
811 rs->sr_type = REP_SEARCH;
813 /* eventually will loop through generated operational attribute types
814 * currently implemented types include:
815 * entryDN, subschemaSubentry, and hasSubordinates */
816 /* NOTE: moved before overlays callback circling because
817 * they may modify entry and other stuff in rs */
818 /* check for special all operational attributes ("+") type */
819 /* FIXME: maybe we could set this flag at the operation level;
820 * however, in principle the caller of send_search_entry() may
821 * change the attribute list at each call */
822 rs->sr_attr_flags = slap_attr_flags( rs->sr_attrs );
824 rc = backend_operational( op, rs );
829 if ( op->o_callback ) {
830 rc = slap_response_play( op, rs );
831 if ( rc != SLAP_CB_CONTINUE ) {
836 Debug( LDAP_DEBUG_TRACE, "=> send_search_entry: conn %lu dn=\"%s\"%s\n",
837 op->o_connid, rs->sr_entry->e_name.bv_val,
838 op->ors_attrsonly ? " (attrsOnly)" : "" );
840 attrsonly = op->ors_attrsonly;
842 if ( !access_allowed( op, rs->sr_entry, ad_entry, NULL, ACL_READ, NULL )) {
843 Debug( LDAP_DEBUG_ACL,
844 "send_search_entry: conn %lu access to entry (%s) not allowed\n",
845 op->o_connid, rs->sr_entry->e_name.bv_val, 0 );
847 rc = LDAP_INSUFFICIENT_ACCESS;
851 if ( op->o_res_ber ) {
852 /* read back control or LDAP_CONNECTIONLESS */
857 bv.bv_len = entry_flatsize( rs->sr_entry, 0 );
858 bv.bv_val = op->o_tmpalloc( bv.bv_len, op->o_tmpmemctx );
860 ber_init2( ber, &bv, LBER_USE_DER );
861 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
864 #ifdef LDAP_CONNECTIONLESS
865 if ( op->o_conn && op->o_conn->c_is_udp ) {
867 if ( op->o_protocol == LDAP_VERSION2 ) {
868 rc = ber_printf(ber, "t{O{" /*}}*/,
869 LDAP_RES_SEARCH_ENTRY, &rs->sr_entry->e_name );
871 rc = ber_printf( ber, "{it{O{" /*}}}*/, op->o_msgid,
872 LDAP_RES_SEARCH_ENTRY, &rs->sr_entry->e_name );
876 if ( op->o_res_ber ) {
877 /* read back control */
878 rc = ber_printf( ber, "{O{" /*}}*/, &rs->sr_entry->e_name );
880 rc = ber_printf( ber, "{it{O{" /*}}}*/, op->o_msgid,
881 LDAP_RES_SEARCH_ENTRY, &rs->sr_entry->e_name );
885 Debug( LDAP_DEBUG_ANY,
886 "send_search_entry: conn %lu ber_printf failed\n",
887 op->o_connid, 0, 0 );
889 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
890 send_ldap_error( op, rs, LDAP_OTHER, "encoding DN error" );
895 /* check for special all user attributes ("*") type */
896 userattrs = SLAP_USERATTRS( rs->sr_attr_flags );
898 /* create an array of arrays of flags. Each flag corresponds
899 * to particular value of attribute and equals 1 if value matches
900 * to ValuesReturnFilter or 0 if not
902 if ( op->o_vrFilter != NULL ) {
906 for ( a = rs->sr_entry->e_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
907 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ ) k++;
910 size = i * sizeof(char *) + k;
913 e_flags = slap_sl_calloc ( 1, i * sizeof(char *) + k, op->o_tmpmemctx );
914 if( e_flags == NULL ) {
915 Debug( LDAP_DEBUG_ANY,
916 "send_search_entry: conn %lu slap_sl_calloc failed\n",
917 op->o_connid ? op->o_connid : 0, 0, 0 );
920 send_ldap_error( op, rs, LDAP_OTHER, "out of memory" );
923 a_flags = (char *)(e_flags + i);
924 memset( a_flags, 0, k );
925 for ( a=rs->sr_entry->e_attrs, i=0; a != NULL; a=a->a_next, i++ ) {
926 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ );
927 e_flags[i] = a_flags;
931 rc = filter_matched_values(op, rs->sr_entry->e_attrs, &e_flags) ;
933 Debug( LDAP_DEBUG_ANY, "send_search_entry: "
934 "conn %lu matched values filtering failed\n",
935 op->o_connid ? op->o_connid : 0, 0, 0 );
936 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
937 send_ldap_error( op, rs, LDAP_OTHER,
938 "matched values filtering error" );
945 for ( a = rs->sr_entry->e_attrs, j = 0; a != NULL; a = a->a_next, j++ ) {
946 AttributeDescription *desc = a->a_desc;
949 if ( rs->sr_attrs == NULL ) {
950 /* all user attrs request, skip operational attributes */
951 if( is_at_operational( desc->ad_type ) ) {
956 /* specific attrs requested */
957 if ( is_at_operational( desc->ad_type ) ) {
958 /* if not explicitly requested */
959 if ( !ad_inlist( desc, rs->sr_attrs )) {
960 /* if not all op attrs requested, skip */
961 if ( !SLAP_OPATTRS( rs->sr_attr_flags ))
963 /* if DSA-specific and replicating, skip */
964 if ( op->o_sync != SLAP_CONTROL_NONE &&
965 desc->ad_type->sat_usage == LDAP_SCHEMA_DSA_OPERATION )
969 if ( !userattrs && !ad_inlist( desc, rs->sr_attrs ) ) {
976 if ( ! access_allowed( op, rs->sr_entry, desc, NULL,
977 ACL_READ, &acl_state ) )
979 Debug( LDAP_DEBUG_ACL, "send_search_entry: "
980 "conn %lu access to attribute %s not allowed\n",
981 op->o_connid, desc->ad_cname.bv_val, 0 );
985 if (( rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname )) == -1 ) {
986 Debug( LDAP_DEBUG_ANY,
987 "send_search_entry: conn %lu ber_printf failed\n",
988 op->o_connid, 0, 0 );
990 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
991 send_ldap_error( op, rs, LDAP_OTHER,
992 "encoding description error");
1000 for ( i = 0; a->a_nvals[i].bv_val != NULL; i++ ) {
1001 if ( ! access_allowed( op, rs->sr_entry,
1002 desc, &a->a_nvals[i], ACL_READ, &acl_state ) )
1004 Debug( LDAP_DEBUG_ACL,
1005 "send_search_entry: conn %lu "
1006 "access to attribute %s, value #%d not allowed\n",
1007 op->o_connid, desc->ad_cname.bv_val, i );
1012 if ( op->o_vrFilter && e_flags[j][i] == 0 ){
1019 if (( rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname )) == -1 ) {
1020 Debug( LDAP_DEBUG_ANY,
1021 "send_search_entry: conn %lu ber_printf failed\n",
1022 op->o_connid, 0, 0 );
1024 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1025 send_ldap_error( op, rs, LDAP_OTHER,
1026 "encoding description error");
1031 if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
1032 Debug( LDAP_DEBUG_ANY,
1033 "send_search_entry: conn %lu "
1034 "ber_printf failed.\n", op->o_connid, 0, 0 );
1036 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1037 send_ldap_error( op, rs, LDAP_OTHER,
1038 "encoding values error" );
1045 if ( finish && ( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
1046 Debug( LDAP_DEBUG_ANY,
1047 "send_search_entry: conn %lu ber_printf failed\n",
1048 op->o_connid, 0, 0 );
1050 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1051 send_ldap_error( op, rs, LDAP_OTHER, "encode end error" );
1057 /* NOTE: moved before overlays callback circling because
1058 * they may modify entry and other stuff in rs */
1059 if ( rs->sr_operational_attrs != NULL && op->o_vrFilter != NULL ) {
1063 for ( a = rs->sr_operational_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
1064 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ ) k++;
1067 size = i * sizeof(char *) + k;
1069 char *a_flags, **tmp;
1072 * Reuse previous memory - we likely need less space
1073 * for operational attributes
1075 tmp = slap_sl_realloc( e_flags, i * sizeof(char *) + k,
1077 if ( tmp == NULL ) {
1078 Debug( LDAP_DEBUG_ANY,
1079 "send_search_entry: conn %lu "
1080 "not enough memory "
1081 "for matched values filtering\n",
1082 op->o_connid, 0, 0 );
1083 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1084 send_ldap_error( op, rs, LDAP_OTHER,
1085 "not enough memory for matched values filtering" );
1089 a_flags = (char *)(e_flags + i);
1090 memset( a_flags, 0, k );
1091 for ( a = rs->sr_operational_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
1092 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ );
1093 e_flags[i] = a_flags;
1096 rc = filter_matched_values(op, rs->sr_operational_attrs, &e_flags) ;
1099 Debug( LDAP_DEBUG_ANY,
1100 "send_search_entry: conn %lu "
1101 "matched values filtering failed\n",
1102 op->o_connid ? op->o_connid : 0, 0, 0);
1103 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1104 send_ldap_error( op, rs, LDAP_OTHER,
1105 "matched values filtering error" );
1112 for (a = rs->sr_operational_attrs, j=0; a != NULL; a = a->a_next, j++ ) {
1113 AttributeDescription *desc = a->a_desc;
1115 if ( rs->sr_attrs == NULL ) {
1116 /* all user attrs request, skip operational attributes */
1117 if( is_at_operational( desc->ad_type ) ) {
1122 /* specific attrs requested */
1123 if( is_at_operational( desc->ad_type ) ) {
1124 if ( !SLAP_OPATTRS( rs->sr_attr_flags ) &&
1125 !ad_inlist( desc, rs->sr_attrs ) )
1130 if ( !userattrs && !ad_inlist( desc, rs->sr_attrs ) ) {
1136 if ( ! access_allowed( op, rs->sr_entry, desc, NULL,
1137 ACL_READ, &acl_state ) )
1139 Debug( LDAP_DEBUG_ACL,
1140 "send_search_entry: conn %lu "
1141 "access to attribute %s not allowed\n",
1142 op->o_connid, desc->ad_cname.bv_val, 0 );
1147 rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname );
1149 Debug( LDAP_DEBUG_ANY,
1150 "send_search_entry: conn %lu "
1151 "ber_printf failed\n", op->o_connid, 0, 0 );
1153 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1154 send_ldap_error( op, rs, LDAP_OTHER,
1155 "encoding description error" );
1160 if ( ! attrsonly ) {
1161 for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
1162 if ( ! access_allowed( op, rs->sr_entry,
1163 desc, &a->a_vals[i], ACL_READ, &acl_state ) )
1165 Debug( LDAP_DEBUG_ACL,
1166 "send_search_entry: conn %lu "
1167 "access to %s, value %d not allowed\n",
1168 op->o_connid, desc->ad_cname.bv_val, i );
1173 if ( op->o_vrFilter && e_flags[j][i] == 0 ){
1177 if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
1178 Debug( LDAP_DEBUG_ANY,
1179 "send_search_entry: conn %lu ber_printf failed\n",
1180 op->o_connid, 0, 0 );
1182 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1183 send_ldap_error( op, rs, LDAP_OTHER,
1184 "encoding values error" );
1191 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
1192 Debug( LDAP_DEBUG_ANY,
1193 "send_search_entry: conn %lu ber_printf failed\n",
1194 op->o_connid, 0, 0 );
1196 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1197 send_ldap_error( op, rs, LDAP_OTHER, "encode end error" );
1205 slap_sl_free( e_flags, op->o_tmpmemctx );
1209 rc = ber_printf( ber, /*{{*/ "}N}" );
1212 rc = send_ldap_controls( op, ber, rs->sr_ctrls );
1216 #ifdef LDAP_CONNECTIONLESS
1217 if( op->o_conn && op->o_conn->c_is_udp ) {
1218 if ( op->o_protocol != LDAP_VERSION2 ) {
1219 rc = ber_printf( ber, /*{*/ "N}" );
1223 if ( op->o_res_ber == NULL ) {
1224 rc = ber_printf( ber, /*{*/ "N}" );
1229 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1231 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1232 send_ldap_error( op, rs, LDAP_OTHER, "encode entry end error" );
1237 Statslog( LDAP_DEBUG_STATS2, "%s ENTRY dn=\"%s\"\n",
1238 op->o_log_prefix, rs->sr_entry->e_nname.bv_val, 0, 0, 0 );
1240 if ( rs->sr_flags & REP_ENTRY_MUSTRELEASE ) {
1241 be_entry_release_rw( op, rs->sr_entry, 0 );
1242 rs->sr_flags ^= REP_ENTRY_MUSTRELEASE;
1243 rs->sr_entry = NULL;
1246 if ( op->o_res_ber == NULL ) {
1247 bytes = send_ldap_ber( op, ber );
1248 ber_free_buf( ber );
1251 Debug( LDAP_DEBUG_ANY,
1252 "send_search_entry: conn %lu ber write failed.\n",
1253 op->o_connid, 0, 0 );
1255 rc = LDAP_UNAVAILABLE;
1260 ldap_pvt_thread_mutex_lock( &op->o_counters->sc_mutex );
1261 ldap_pvt_mp_add_ulong( op->o_counters->sc_bytes, (unsigned long)bytes );
1262 ldap_pvt_mp_add_ulong( op->o_counters->sc_entries, 1 );
1263 ldap_pvt_mp_add_ulong( op->o_counters->sc_pdu, 1 );
1264 ldap_pvt_thread_mutex_unlock( &op->o_counters->sc_mutex );
1267 Debug( LDAP_DEBUG_TRACE,
1268 "<= send_search_entry: conn %lu exit.\n", op->o_connid, 0, 0 );
1273 if ( op->o_callback ) {
1274 (void)slap_cleanup_play( op, rs );
1278 slap_sl_free( e_flags, op->o_tmpmemctx );
1281 if ( rs->sr_operational_attrs ) {
1282 attrs_free( rs->sr_operational_attrs );
1283 rs->sr_operational_attrs = NULL;
1285 rs->sr_attr_flags = SLAP_ATTRS_UNDEFINED;
1287 /* FIXME: I think rs->sr_type should be explicitly set to
1288 * REP_SEARCH here. That's what it was when we entered this
1289 * function. send_ldap_error may have changed it, but we
1290 * should set it back so that the cleanup functions know
1291 * what they're doing.
1293 if ( op->o_tag == LDAP_REQ_SEARCH && rs->sr_type == REP_SEARCH
1295 && ( rs->sr_flags & REP_ENTRY_MUSTBEFREED ) )
1297 entry_free( rs->sr_entry );
1298 rs->sr_entry = NULL;
1299 rs->sr_flags &= ~REP_ENTRY_MUSTBEFREED;
1306 slap_send_search_reference( Operation *op, SlapReply *rs )
1308 BerElementBuffer berbuf;
1309 BerElement *ber = (BerElement *) &berbuf;
1312 char *edn = rs->sr_entry ? rs->sr_entry->e_name.bv_val : "(null)";
1314 AttributeDescription *ad_ref = slap_schema.si_ad_ref;
1315 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
1317 rs->sr_type = REP_SEARCHREF;
1318 if ( op->o_callback ) {
1319 rc = slap_response_play( op, rs );
1320 if ( rc != SLAP_CB_CONTINUE ) {
1325 Debug( LDAP_DEBUG_TRACE,
1326 "=> send_search_reference: dn=\"%s\"\n",
1329 if ( rs->sr_entry && ! access_allowed( op, rs->sr_entry,
1330 ad_entry, NULL, ACL_READ, NULL ) )
1332 Debug( LDAP_DEBUG_ACL,
1333 "send_search_reference: access to entry not allowed\n",
1339 if ( rs->sr_entry && ! access_allowed( op, rs->sr_entry,
1340 ad_ref, NULL, ACL_READ, NULL ) )
1342 Debug( LDAP_DEBUG_ACL,
1343 "send_search_reference: access "
1344 "to reference not allowed\n",
1350 if( op->o_domain_scope ) {
1351 Debug( LDAP_DEBUG_ANY,
1352 "send_search_reference: domainScope control in (%s)\n",
1358 if( rs->sr_ref == NULL ) {
1359 Debug( LDAP_DEBUG_ANY,
1360 "send_search_reference: null ref in (%s)\n",
1366 if( op->o_protocol < LDAP_VERSION3 ) {
1368 /* save the references for the result */
1369 if( rs->sr_ref[0].bv_val != NULL ) {
1370 if( value_add( &rs->sr_v2ref, rs->sr_ref ) )
1376 #ifdef LDAP_CONNECTIONLESS
1377 if( op->o_conn && op->o_conn->c_is_udp ) {
1378 ber = op->o_res_ber;
1382 ber_init_w_nullc( ber, LBER_USE_DER );
1383 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
1386 rc = ber_printf( ber, "{it{W}" /*"}"*/ , op->o_msgid,
1387 LDAP_RES_SEARCH_REFERENCE, rs->sr_ref );
1390 rc = send_ldap_controls( op, ber, rs->sr_ctrls );
1394 rc = ber_printf( ber, /*"{"*/ "N}" );
1398 Debug( LDAP_DEBUG_ANY,
1399 "send_search_reference: ber_printf failed\n", 0, 0, 0 );
1401 #ifdef LDAP_CONNECTIONLESS
1402 if (!op->o_conn || op->o_conn->c_is_udp == 0)
1404 ber_free_buf( ber );
1405 send_ldap_error( op, rs, LDAP_OTHER, "encode DN error" );
1410 if ( rs->sr_flags & REP_ENTRY_MUSTRELEASE ) {
1411 assert( rs->sr_entry != NULL );
1412 be_entry_release_rw( op, rs->sr_entry, 0 );
1413 rs->sr_flags ^= REP_ENTRY_MUSTRELEASE;
1414 rs->sr_entry = NULL;
1417 #ifdef LDAP_CONNECTIONLESS
1418 if (!op->o_conn || op->o_conn->c_is_udp == 0) {
1420 bytes = send_ldap_ber( op, ber );
1421 ber_free_buf( ber );
1424 rc = LDAP_UNAVAILABLE;
1426 ldap_pvt_thread_mutex_lock( &op->o_counters->sc_mutex );
1427 ldap_pvt_mp_add_ulong( op->o_counters->sc_bytes, (unsigned long)bytes );
1428 ldap_pvt_mp_add_ulong( op->o_counters->sc_refs, 1 );
1429 ldap_pvt_mp_add_ulong( op->o_counters->sc_pdu, 1 );
1430 ldap_pvt_thread_mutex_unlock( &op->o_counters->sc_mutex );
1432 #ifdef LDAP_CONNECTIONLESS
1435 if ( rs->sr_ref != NULL ) {
1438 for ( r = 0; !BER_BVISNULL( &rs->sr_ref[ r ] ); r++ ) {
1439 Statslog( LDAP_DEBUG_STATS2, "%s REF #%d \"%s\"\n",
1440 op->o_log_prefix, r, rs->sr_ref[0].bv_val,
1445 Statslog( LDAP_DEBUG_STATS2, "%s REF \"(null)\"\n",
1446 op->o_log_prefix, 0, 0, 0, 0 );
1449 Debug( LDAP_DEBUG_TRACE, "<= send_search_reference\n", 0, 0, 0 );
1452 if ( op->o_callback ) {
1453 (void)slap_cleanup_play( op, rs );
1469 *code = LDAP_SUCCESS;
1473 if ( strncasecmp( s, "RESULT", STRLENOF( "RESULT" ) ) != 0 ) {
1474 Debug( LDAP_DEBUG_ANY, "str2result (%s) expecting \"RESULT\"\n",
1481 while ( (s = strchr( s, '\n' )) != NULL ) {
1486 if ( (c = strchr( s, ':' )) != NULL ) {
1490 if ( strncasecmp( s, "code", STRLENOF( "code" ) ) == 0 ) {
1495 Debug( LDAP_DEBUG_ANY, "str2result (%s) missing value\n",
1501 while ( isspace( (unsigned char) c[ 0 ] ) ) c++;
1502 if ( c[ 0 ] == '\0' ) {
1503 Debug( LDAP_DEBUG_ANY, "str2result (%s) missing or empty value\n",
1509 retcode = strtol( c, &next, 10 );
1510 if ( next == NULL || next == c ) {
1511 Debug( LDAP_DEBUG_ANY, "str2result (%s) unable to parse value\n",
1517 while ( isspace( (unsigned char) next[ 0 ] ) ) next++;
1518 if ( next[ 0 ] != '\0' ) {
1519 Debug( LDAP_DEBUG_ANY, "str2result (%s) extra cruft after value\n",
1525 /* FIXME: what if it's larger that max int? */
1526 *code = (int)retcode;
1528 } else if ( strncasecmp( s, "matched", STRLENOF( "matched" ) ) == 0 ) {
1532 } else if ( strncasecmp( s, "info", STRLENOF( "info" ) ) == 0 ) {
1537 Debug( LDAP_DEBUG_ANY, "str2result (%s) unknown\n",
1547 int slap_read_controls(
1551 const struct berval *oid,
1552 LDAPControl **ctrl )
1556 BerElementBuffer berbuf;
1557 BerElement *ber = (BerElement *) &berbuf;
1561 Debug( LDAP_DEBUG_ANY, "%s slap_read_controls: (%s) %s\n",
1562 op->o_log_prefix, oid->bv_val, e->e_dn );
1565 rs->sr_attrs = ( oid == &slap_pre_read_bv ) ?
1566 op->o_preread_attrs : op->o_postread_attrs;
1568 bv.bv_len = entry_flatsize( rs->sr_entry, 0 );
1569 bv.bv_val = op->o_tmpalloc( bv.bv_len, op->o_tmpmemctx );
1571 ber_init2( ber, &bv, LBER_USE_DER );
1572 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
1574 /* create new operation */
1576 /* FIXME: o_bd needed for ACL */
1577 myop.o_bd = op->o_bd;
1578 myop.o_res_ber = ber;
1579 myop.o_callback = NULL;
1580 myop.ors_slimit = 1;
1582 rc = slap_send_search_entry( &myop, rs );
1585 rc = ber_flatten2( ber, &c.ldctl_value, 0 );
1587 if( rc == -1 ) return LDAP_OTHER;
1589 c.ldctl_oid = oid->bv_val;
1590 c.ldctl_iscritical = 0;
1592 if ( *ctrl == NULL ) {
1594 *ctrl = (LDAPControl *) slap_sl_calloc( 1, sizeof(LDAPControl), NULL );
1596 /* retry: free previous try */
1597 slap_sl_free( (*ctrl)->ldctl_value.bv_val, op->o_tmpmemctx );
1601 return LDAP_SUCCESS;
1604 /* Map API errors to protocol errors... */
1606 slap_map_api2result( SlapReply *rs )
1608 switch(rs->sr_err) {
1609 case LDAP_SERVER_DOWN:
1610 return LDAP_UNAVAILABLE;
1611 case LDAP_LOCAL_ERROR:
1613 case LDAP_ENCODING_ERROR:
1614 case LDAP_DECODING_ERROR:
1615 return LDAP_PROTOCOL_ERROR;
1617 return LDAP_UNAVAILABLE;
1618 case LDAP_AUTH_UNKNOWN:
1619 return LDAP_AUTH_METHOD_NOT_SUPPORTED;
1620 case LDAP_FILTER_ERROR:
1621 rs->sr_text = "Filter error";
1623 case LDAP_USER_CANCELLED:
1624 rs->sr_text = "User cancelled";
1626 case LDAP_PARAM_ERROR:
1627 return LDAP_PROTOCOL_ERROR;
1628 case LDAP_NO_MEMORY:
1630 case LDAP_CONNECT_ERROR:
1631 return LDAP_UNAVAILABLE;
1632 case LDAP_NOT_SUPPORTED:
1633 return LDAP_UNWILLING_TO_PERFORM;
1634 case LDAP_CONTROL_NOT_FOUND:
1635 return LDAP_PROTOCOL_ERROR;
1636 case LDAP_NO_RESULTS_RETURNED:
1637 return LDAP_NO_SUCH_OBJECT;
1638 case LDAP_MORE_RESULTS_TO_RETURN:
1639 rs->sr_text = "More results to return";
1641 case LDAP_CLIENT_LOOP:
1642 case LDAP_REFERRAL_LIMIT_EXCEEDED:
1643 return LDAP_LOOP_DETECT;
1645 if ( LDAP_API_ERROR(rs->sr_err) ) return LDAP_OTHER;
1652 slap_attr_flags( AttributeName *an )
1654 slap_mask_t flags = SLAP_ATTRS_UNDEFINED;
1657 flags |= ( SLAP_OPATTRS_NO | SLAP_USERATTRS_YES );
1660 flags |= an_find( an, slap_bv_all_operational_attrs )
1661 ? SLAP_OPATTRS_YES : SLAP_OPATTRS_NO;
1662 flags |= an_find( an, slap_bv_all_user_attrs )
1663 ? SLAP_USERATTRS_YES : SLAP_USERATTRS_NO;