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;
143 ber_get_option( ber, LBER_OPT_BER_BYTES_TO_WRITE, &bytes );
145 /* write only one pdu at a time - wait til it's our turn */
146 ldap_pvt_thread_mutex_lock( &conn->c_write1_mutex );
147 if (( op->o_abandon && !op->o_cancel ) || !connection_valid( conn ) ||
148 conn->c_writers < 0 ) {
149 ldap_pvt_thread_mutex_unlock( &conn->c_write1_mutex );
155 while ( conn->c_writers > 0 && conn->c_writing ) {
156 ldap_pvt_thread_cond_wait( &conn->c_write1_cv, &conn->c_write1_mutex );
159 /* connection was closed under us */
160 if ( conn->c_writers < 0 ) {
161 /* we're the last waiter, let the closer continue */
162 if ( conn->c_writers == -1 )
163 ldap_pvt_thread_cond_signal( &conn->c_write1_cv );
165 ldap_pvt_thread_mutex_unlock( &conn->c_write1_mutex );
176 /* lock the connection */
177 if ( ldap_pvt_thread_mutex_trylock( &conn->c_mutex )) {
178 if ( !connection_valid(conn)) {
182 ldap_pvt_thread_mutex_unlock( &conn->c_write1_mutex );
183 ldap_pvt_thread_mutex_lock( &conn->c_write1_mutex );
184 if ( conn->c_writers < 0 ) {
191 if ( ber_flush2( conn->c_sb, ber, LBER_FLUSH_FREE_NEVER ) == 0 ) {
192 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
200 * we got an error. if it's ewouldblock, we need to
201 * wait on the socket being writable. otherwise, figure
202 * it's a hard error and return.
205 Debug( LDAP_DEBUG_CONNS, "ber_flush2 failed errno=%d reason=\"%s\"\n",
206 err, sock_errstr(err), 0 );
208 if ( err != EWOULDBLOCK && err != EAGAIN ) {
211 ldap_pvt_thread_mutex_unlock( &conn->c_write1_mutex );
212 connection_closing( conn, "connection lost on write" );
214 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
218 /* wait for socket to be write-ready */
219 ldap_pvt_thread_mutex_lock( &conn->c_write2_mutex );
220 conn->c_writewaiter = 1;
221 slapd_set_write( conn->c_sd, 2 );
223 ldap_pvt_thread_mutex_unlock( &conn->c_write1_mutex );
224 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
225 ldap_pvt_thread_cond_wait( &conn->c_write2_cv, &conn->c_write2_mutex );
226 conn->c_writewaiter = 0;
227 ldap_pvt_thread_mutex_unlock( &conn->c_write2_mutex );
228 ldap_pvt_thread_mutex_lock( &conn->c_write1_mutex );
229 if ( conn->c_writers < 0 ) {
236 if ( conn->c_writers < 0 ) {
238 if ( !conn->c_writers )
239 ldap_pvt_thread_cond_signal( &conn->c_write1_cv );
242 ldap_pvt_thread_cond_signal( &conn->c_write1_cv );
244 ldap_pvt_thread_mutex_unlock( &conn->c_write1_mutex );
250 send_ldap_control( BerElement *ber, LDAPControl *c )
256 rc = ber_printf( ber, "{s" /*}*/, c->ldctl_oid );
258 if( c->ldctl_iscritical ) {
259 rc = ber_printf( ber, "b",
260 (ber_int_t) c->ldctl_iscritical ) ;
261 if( rc == -1 ) return rc;
264 if( c->ldctl_value.bv_val != NULL ) {
265 rc = ber_printf( ber, "O", &c->ldctl_value );
266 if( rc == -1 ) return rc;
269 rc = ber_printf( ber, /*{*/"N}" );
270 if( rc == -1 ) return rc;
276 send_ldap_controls( Operation *o, BerElement *ber, LDAPControl **c )
283 rc = ber_printf( ber, "t{"/*}*/, LDAP_TAG_CONTROLS );
284 if( rc == -1 ) return rc;
286 for( ; *c != NULL; c++) {
287 rc = send_ldap_control( ber, *c );
288 if( rc == -1 ) return rc;
291 #ifdef SLAP_CONTROL_X_SORTEDRESULTS
292 /* this is a hack to avoid having to modify op->s_ctrls */
293 if( o->o_sortedresults ) {
294 BerElementBuffer berbuf;
295 BerElement *sber = (BerElement *) &berbuf;
297 BER_BVZERO( &sorted.ldctl_value );
298 sorted.ldctl_oid = LDAP_CONTROL_SORTRESPONSE;
299 sorted.ldctl_iscritical = 0;
301 ber_init2( sber, NULL, LBER_USE_DER );
303 ber_printf( sber, "{e}", LDAP_UNWILLING_TO_PERFORM );
305 if( ber_flatten2( sber, &sorted.ldctl_value, 0 ) == -1 ) {
309 (void) ber_free_buf( sber );
311 rc = send_ldap_control( ber, &sorted );
312 if( rc == -1 ) return rc;
316 rc = ber_printf( ber, /*{*/"N}" );
322 * slap_response_play()
324 * plays the callback list; rationale: a callback can
325 * - remove itself from the list, by setting op->o_callback = NULL;
326 * malloc()'ed callbacks should free themselves from inside the
327 * sc_response() function.
328 * - replace itself with another (list of) callback(s), by setting
329 * op->o_callback = a new (list of) callback(s); in this case, it
330 * is the callback's responsibility to to append existing subsequent
331 * callbacks to the end of the list that is passed to the sc_response()
333 * - modify the list of subsequent callbacks by modifying the value
334 * of the sc_next field from inside the sc_response() function; this
335 * case does not require any handling from inside slap_response_play()
337 * To stop execution of the playlist, the sc_response() function must return
338 * a value different from SLAP_SC_CONTINUE.
340 * The same applies to slap_cleanup_play(); only, there is no means to stop
341 * execution of the playlist, since all cleanup functions must be called.
350 slap_callback *sc = op->o_callback, **scp;
352 rc = SLAP_CB_CONTINUE;
353 for ( scp = ≻ *scp; ) {
354 slap_callback *sc_next = (*scp)->sc_next, **sc_nextp = &(*scp)->sc_next;
356 op->o_callback = *scp;
357 if ( op->o_callback->sc_response ) {
358 rc = op->o_callback->sc_response( op, rs );
359 if ( op->o_callback == NULL ) {
360 /* the callback has been removed;
365 } else if ( op->o_callback != *scp ) {
366 /* a new callback has been inserted
367 * in place of the existing one; repair the list */
368 *scp = op->o_callback;
371 if ( rc != SLAP_CB_CONTINUE ) break;
385 slap_callback *sc = op->o_callback, **scp;
387 for ( scp = ≻ *scp; ) {
388 slap_callback *sc_next = (*scp)->sc_next, **sc_nextp = &(*scp)->sc_next;
390 op->o_callback = *scp;
391 if ( op->o_callback->sc_cleanup ) {
392 (void)op->o_callback->sc_cleanup( op, rs );
393 if ( op->o_callback == NULL ) {
394 /* the callback has been removed;
399 } else if ( op->o_callback != *scp ) {
400 /* a new callback has been inserted
401 * after the existing one; repair the list */
402 /* a new callback has been inserted
403 * in place of the existing one; repair the list */
404 *scp = op->o_callback;
407 /* don't care about the result; do all cleanup */
421 BerElementBuffer berbuf;
422 BerElement *ber = (BerElement *) &berbuf;
423 int rc = LDAP_SUCCESS;
426 if (( rs->sr_err == SLAPD_ABANDON || op->o_abandon ) && !op->o_cancel ) {
431 if ( op->o_callback ) {
432 rc = slap_response_play( op, rs );
433 if ( rc != SLAP_CB_CONTINUE ) {
438 #ifdef LDAP_CONNECTIONLESS
439 if (op->o_conn && op->o_conn->c_is_udp)
444 ber_init_w_nullc( ber, LBER_USE_DER );
445 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
449 if ( rc == SLAPD_ABANDON && op->o_cancel )
452 Debug( LDAP_DEBUG_TRACE,
453 "send_ldap_response: msgid=%d tag=%lu err=%d\n",
454 rs->sr_msgid, rs->sr_tag, rc );
457 Debug( LDAP_DEBUG_ARGS, "send_ldap_response: ref=\"%s\"\n",
458 rs->sr_ref[0].bv_val ? rs->sr_ref[0].bv_val : "NULL",
462 #ifdef LDAP_CONNECTIONLESS
463 if (op->o_conn && op->o_conn->c_is_udp &&
464 op->o_protocol == LDAP_VERSION2 )
466 rc = ber_printf( ber, "t{ess" /*"}"*/,
468 rs->sr_matched == NULL ? "" : rs->sr_matched,
469 rs->sr_text == NULL ? "" : rs->sr_text );
472 if ( rs->sr_type == REP_INTERMEDIATE ) {
473 rc = ber_printf( ber, "{it{" /*"}}"*/,
474 rs->sr_msgid, rs->sr_tag );
477 rc = ber_printf( ber, "{it{ess" /*"}}"*/,
478 rs->sr_msgid, rs->sr_tag, rc,
479 rs->sr_matched == NULL ? "" : rs->sr_matched,
480 rs->sr_text == NULL ? "" : rs->sr_text );
484 if ( rs->sr_ref != NULL ) {
485 assert( rs->sr_err == LDAP_REFERRAL );
486 rc = ber_printf( ber, "t{W}",
487 LDAP_TAG_REFERRAL, rs->sr_ref );
489 assert( rs->sr_err != LDAP_REFERRAL );
493 if( rc != -1 && rs->sr_type == REP_SASL && rs->sr_sasldata != NULL ) {
494 rc = ber_printf( ber, "tO",
495 LDAP_TAG_SASL_RES_CREDS, rs->sr_sasldata );
499 ( rs->sr_type == REP_EXTENDED || rs->sr_type == REP_INTERMEDIATE ))
501 if ( rs->sr_rspoid != NULL ) {
502 rc = ber_printf( ber, "ts",
503 rs->sr_type == REP_EXTENDED
504 ? LDAP_TAG_EXOP_RES_OID : LDAP_TAG_IM_RES_OID,
507 if( rc != -1 && rs->sr_rspdata != NULL ) {
508 rc = ber_printf( ber, "tO",
509 rs->sr_type == REP_EXTENDED
510 ? LDAP_TAG_EXOP_RES_VALUE : LDAP_TAG_IM_RES_VALUE,
516 rc = ber_printf( ber, /*"{"*/ "N}" );
520 rc = send_ldap_controls( op, ber, rs->sr_ctrls );
524 rc = ber_printf( ber, /*"{"*/ "N}" );
527 #ifdef LDAP_CONNECTIONLESS
528 if( op->o_conn && op->o_conn->c_is_udp && op->o_protocol == LDAP_VERSION2
531 rc = ber_printf( ber, /*"{"*/ "N}" );
536 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
538 #ifdef LDAP_CONNECTIONLESS
539 if (!op->o_conn || op->o_conn->c_is_udp == 0)
548 bytes = send_ldap_ber( op, ber );
549 #ifdef LDAP_CONNECTIONLESS
550 if (!op->o_conn || op->o_conn->c_is_udp == 0)
557 Debug( LDAP_DEBUG_ANY,
558 "send_ldap_response: ber write failed\n",
564 ldap_pvt_thread_mutex_lock( &op->o_counters->sc_mutex );
565 ldap_pvt_mp_add_ulong( op->o_counters->sc_pdu, 1 );
566 ldap_pvt_mp_add_ulong( op->o_counters->sc_bytes, (unsigned long)bytes );
567 ldap_pvt_thread_mutex_unlock( &op->o_counters->sc_mutex );
570 /* Tell caller that we did this for real, as opposed to being
571 * overridden by a callback
573 rc = SLAP_CB_CONTINUE;
576 if ( op->o_callback ) {
577 (void)slap_cleanup_play( op, rs );
580 if ( rs->sr_flags & REP_MATCHED_MUSTBEFREED ) {
581 rs->sr_flags ^= REP_MATCHED_MUSTBEFREED; /* paranoia */
582 if ( rs->sr_matched ) {
583 free( (char *)rs->sr_matched );
584 rs->sr_matched = NULL;
588 if ( rs->sr_flags & REP_REF_MUSTBEFREED ) {
589 rs->sr_flags ^= REP_REF_MUSTBEFREED; /* paranoia */
591 ber_bvarray_free( rs->sr_ref );
596 if ( rs->sr_flags & REP_CTRLS_MUSTBEFREED ) {
597 rs->sr_flags ^= REP_CTRLS_MUSTBEFREED; /* paranoia */
598 if ( rs->sr_ctrls ) {
599 slap_free_ctrls( op, rs->sr_ctrls );
609 send_ldap_disconnect( Operation *op, SlapReply *rs )
611 #define LDAP_UNSOLICITED_ERROR(e) \
612 ( (e) == LDAP_PROTOCOL_ERROR \
613 || (e) == LDAP_STRONG_AUTH_REQUIRED \
614 || (e) == LDAP_UNAVAILABLE )
616 assert( LDAP_UNSOLICITED_ERROR( rs->sr_err ) );
618 rs->sr_type = REP_EXTENDED;
619 rs->sr_rspdata = NULL;
621 Debug( LDAP_DEBUG_TRACE,
622 "send_ldap_disconnect %d:%s\n",
623 rs->sr_err, rs->sr_text ? rs->sr_text : "", NULL );
625 if ( op->o_protocol < LDAP_VERSION3 ) {
626 rs->sr_rspoid = NULL;
627 rs->sr_tag = slap_req2res( op->o_tag );
628 rs->sr_msgid = (rs->sr_tag != LBER_SEQUENCE) ? op->o_msgid : 0;
631 rs->sr_rspoid = LDAP_NOTICE_DISCONNECT;
632 rs->sr_tag = LDAP_RES_EXTENDED;
633 rs->sr_msgid = LDAP_RES_UNSOLICITED;
636 if ( send_ldap_response( op, rs ) == SLAP_CB_CONTINUE ) {
637 Statslog( LDAP_DEBUG_STATS,
638 "%s DISCONNECT tag=%lu err=%d text=%s\n",
639 op->o_log_prefix, rs->sr_tag, rs->sr_err,
640 rs->sr_text ? rs->sr_text : "", 0 );
645 slap_send_ldap_result( Operation *op, SlapReply *rs )
648 const char *otext = rs->sr_text;
649 BerVarray oref = rs->sr_ref;
651 rs->sr_type = REP_RESULT;
653 /* Propagate Abandons so that cleanup callbacks can be processed */
654 if ( rs->sr_err == SLAPD_ABANDON || op->o_abandon )
657 assert( !LDAP_API_ERROR( rs->sr_err ) );
659 Debug( LDAP_DEBUG_TRACE,
660 "send_ldap_result: %s p=%d\n",
661 op->o_log_prefix, op->o_protocol, 0 );
663 Debug( LDAP_DEBUG_ARGS,
664 "send_ldap_result: err=%d matched=\"%s\" text=\"%s\"\n",
665 rs->sr_err, rs->sr_matched ? rs->sr_matched : "",
666 rs->sr_text ? rs->sr_text : "" );
670 Debug( LDAP_DEBUG_ARGS,
671 "send_ldap_result: referral=\"%s\"\n",
672 rs->sr_ref[0].bv_val ? rs->sr_ref[0].bv_val : "NULL",
676 assert( rs->sr_err != LDAP_PARTIAL_RESULTS );
678 if ( rs->sr_err == LDAP_REFERRAL ) {
679 if( op->o_domain_scope ) rs->sr_ref = NULL;
681 if( rs->sr_ref == NULL ) {
682 rs->sr_err = LDAP_NO_SUCH_OBJECT;
683 } else if ( op->o_protocol < LDAP_VERSION3 ) {
684 rs->sr_err = LDAP_PARTIAL_RESULTS;
688 if ( op->o_protocol < LDAP_VERSION3 ) {
689 tmp = v2ref( rs->sr_ref, rs->sr_text );
695 rs->sr_tag = slap_req2res( op->o_tag );
696 rs->sr_msgid = (rs->sr_tag != LBER_SEQUENCE) ? op->o_msgid : 0;
698 if ( rs->sr_flags & REP_REF_MUSTBEFREED ) {
699 if ( rs->sr_ref == NULL ) {
700 rs->sr_flags ^= REP_REF_MUSTBEFREED;
701 ber_bvarray_free( oref );
703 oref = NULL; /* send_ldap_response() will free rs->sr_ref if != NULL */
706 if ( send_ldap_response( op, rs ) == SLAP_CB_CONTINUE ) {
707 if ( op->o_tag == LDAP_REQ_SEARCH ) {
708 Statslog( LDAP_DEBUG_STATS,
709 "%s SEARCH RESULT tag=%lu err=%d nentries=%d text=%s\n",
710 op->o_log_prefix, rs->sr_tag, rs->sr_err,
711 rs->sr_nentries, rs->sr_text ? rs->sr_text : "" );
713 Statslog( LDAP_DEBUG_STATS,
714 "%s RESULT tag=%lu err=%d text=%s\n",
715 op->o_log_prefix, rs->sr_tag, rs->sr_err,
716 rs->sr_text ? rs->sr_text : "", 0 );
720 if( tmp != NULL ) ch_free(tmp);
726 send_ldap_sasl( Operation *op, SlapReply *rs )
728 rs->sr_type = REP_SASL;
729 Debug( LDAP_DEBUG_TRACE, "send_ldap_sasl: err=%d len=%ld\n",
731 rs->sr_sasldata ? (long) rs->sr_sasldata->bv_len : -1, NULL );
733 rs->sr_tag = slap_req2res( op->o_tag );
734 rs->sr_msgid = (rs->sr_tag != LBER_SEQUENCE) ? op->o_msgid : 0;
736 if ( send_ldap_response( op, rs ) == SLAP_CB_CONTINUE ) {
737 Statslog( LDAP_DEBUG_STATS,
738 "%s RESULT tag=%lu err=%d text=%s\n",
739 op->o_log_prefix, rs->sr_tag, rs->sr_err,
740 rs->sr_text ? rs->sr_text : "", 0 );
745 slap_send_ldap_extended( Operation *op, SlapReply *rs )
747 rs->sr_type = REP_EXTENDED;
749 Debug( LDAP_DEBUG_TRACE,
750 "send_ldap_extended: err=%d oid=%s len=%ld\n",
752 rs->sr_rspoid ? rs->sr_rspoid : "",
753 rs->sr_rspdata != NULL ? rs->sr_rspdata->bv_len : 0 );
755 rs->sr_tag = slap_req2res( op->o_tag );
756 rs->sr_msgid = (rs->sr_tag != LBER_SEQUENCE) ? op->o_msgid : 0;
758 if ( send_ldap_response( op, rs ) == SLAP_CB_CONTINUE ) {
759 Statslog( LDAP_DEBUG_STATS,
760 "%s RESULT oid=%s err=%d text=%s\n",
761 op->o_log_prefix, rs->sr_rspoid ? rs->sr_rspoid : "",
762 rs->sr_err, rs->sr_text ? rs->sr_text : "", 0 );
767 slap_send_ldap_intermediate( Operation *op, SlapReply *rs )
769 rs->sr_type = REP_INTERMEDIATE;
770 Debug( LDAP_DEBUG_TRACE,
771 "send_ldap_intermediate: err=%d oid=%s len=%ld\n",
773 rs->sr_rspoid ? rs->sr_rspoid : "",
774 rs->sr_rspdata != NULL ? rs->sr_rspdata->bv_len : 0 );
775 rs->sr_tag = LDAP_RES_INTERMEDIATE;
776 rs->sr_msgid = op->o_msgid;
777 if ( send_ldap_response( op, rs ) == SLAP_CB_CONTINUE ) {
778 Statslog( LDAP_DEBUG_STATS2,
779 "%s INTERM oid=%s\n",
781 rs->sr_rspoid ? rs->sr_rspoid : "", 0, 0, 0 );
788 * LDAP_SUCCESS entry sent
789 * LDAP_OTHER entry not sent (other)
790 * LDAP_INSUFFICIENT_ACCESS entry not sent (ACL)
791 * LDAP_UNAVAILABLE entry not sent (connection closed)
792 * LDAP_SIZELIMIT_EXCEEDED entry not sent (caller must send sizelimitExceeded)
796 slap_send_search_entry( Operation *op, SlapReply *rs )
798 BerElementBuffer berbuf;
799 BerElement *ber = (BerElement *) &berbuf;
801 int i, j, rc = LDAP_UNAVAILABLE, bytes;
803 AccessControlState acl_state = ACL_STATE_INIT;
805 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
807 /* a_flags: array of flags telling if the i-th element will be
808 * returned or filtered out
809 * e_flags: array of a_flags
811 char **e_flags = NULL;
813 if ( op->ors_slimit >= 0 && rs->sr_nentries >= op->ors_slimit ) {
814 return LDAP_SIZELIMIT_EXCEEDED;
817 /* Every 64 entries, check for thread pool pause */
818 if ( ( ( rs->sr_nentries & 0x3f ) == 0x3f ) &&
819 ldap_pvt_thread_pool_pausing( &connection_pool ) > 0 )
824 rs->sr_type = REP_SEARCH;
826 /* eventually will loop through generated operational attribute types
827 * currently implemented types include:
828 * entryDN, subschemaSubentry, and hasSubordinates */
829 /* NOTE: moved before overlays callback circling because
830 * they may modify entry and other stuff in rs */
831 /* check for special all operational attributes ("+") type */
832 /* FIXME: maybe we could set this flag at the operation level;
833 * however, in principle the caller of send_search_entry() may
834 * change the attribute list at each call */
835 rs->sr_attr_flags = slap_attr_flags( rs->sr_attrs );
837 rc = backend_operational( op, rs );
842 if ( op->o_callback ) {
843 rc = slap_response_play( op, rs );
844 if ( rc != SLAP_CB_CONTINUE ) {
849 Debug( LDAP_DEBUG_TRACE, "=> send_search_entry: conn %lu dn=\"%s\"%s\n",
850 op->o_connid, rs->sr_entry->e_name.bv_val,
851 op->ors_attrsonly ? " (attrsOnly)" : "" );
853 attrsonly = op->ors_attrsonly;
855 if ( !access_allowed( op, rs->sr_entry, ad_entry, NULL, ACL_READ, NULL )) {
856 Debug( LDAP_DEBUG_ACL,
857 "send_search_entry: conn %lu access to entry (%s) not allowed\n",
858 op->o_connid, rs->sr_entry->e_name.bv_val, 0 );
860 rc = LDAP_INSUFFICIENT_ACCESS;
864 if ( op->o_res_ber ) {
865 /* read back control or LDAP_CONNECTIONLESS */
870 bv.bv_len = entry_flatsize( rs->sr_entry, 0 );
871 bv.bv_val = op->o_tmpalloc( bv.bv_len, op->o_tmpmemctx );
873 ber_init2( ber, &bv, LBER_USE_DER );
874 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
877 #ifdef LDAP_CONNECTIONLESS
878 if ( op->o_conn && op->o_conn->c_is_udp ) {
880 if ( op->o_protocol == LDAP_VERSION2 ) {
881 rc = ber_printf(ber, "t{O{" /*}}*/,
882 LDAP_RES_SEARCH_ENTRY, &rs->sr_entry->e_name );
884 rc = ber_printf( ber, "{it{O{" /*}}}*/, op->o_msgid,
885 LDAP_RES_SEARCH_ENTRY, &rs->sr_entry->e_name );
889 if ( op->o_res_ber ) {
890 /* read back control */
891 rc = ber_printf( ber, "{O{" /*}}*/, &rs->sr_entry->e_name );
893 rc = ber_printf( ber, "{it{O{" /*}}}*/, op->o_msgid,
894 LDAP_RES_SEARCH_ENTRY, &rs->sr_entry->e_name );
898 Debug( LDAP_DEBUG_ANY,
899 "send_search_entry: conn %lu ber_printf failed\n",
900 op->o_connid, 0, 0 );
902 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
903 send_ldap_error( op, rs, LDAP_OTHER, "encoding DN error" );
908 /* check for special all user attributes ("*") type */
909 userattrs = SLAP_USERATTRS( rs->sr_attr_flags );
911 /* create an array of arrays of flags. Each flag corresponds
912 * to particular value of attribute and equals 1 if value matches
913 * to ValuesReturnFilter or 0 if not
915 if ( op->o_vrFilter != NULL ) {
919 for ( a = rs->sr_entry->e_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
920 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ ) k++;
923 size = i * sizeof(char *) + k;
926 e_flags = slap_sl_calloc ( 1, i * sizeof(char *) + k, op->o_tmpmemctx );
927 if( e_flags == NULL ) {
928 Debug( LDAP_DEBUG_ANY,
929 "send_search_entry: conn %lu slap_sl_calloc failed\n",
930 op->o_connid ? op->o_connid : 0, 0, 0 );
933 send_ldap_error( op, rs, LDAP_OTHER, "out of memory" );
936 a_flags = (char *)(e_flags + i);
937 memset( a_flags, 0, k );
938 for ( a=rs->sr_entry->e_attrs, i=0; a != NULL; a=a->a_next, i++ ) {
939 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ );
940 e_flags[i] = a_flags;
944 rc = filter_matched_values(op, rs->sr_entry->e_attrs, &e_flags) ;
946 Debug( LDAP_DEBUG_ANY, "send_search_entry: "
947 "conn %lu matched values filtering failed\n",
948 op->o_connid ? op->o_connid : 0, 0, 0 );
949 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
950 send_ldap_error( op, rs, LDAP_OTHER,
951 "matched values filtering error" );
958 for ( a = rs->sr_entry->e_attrs, j = 0; a != NULL; a = a->a_next, j++ ) {
959 AttributeDescription *desc = a->a_desc;
962 if ( rs->sr_attrs == NULL ) {
963 /* all user attrs request, skip operational attributes */
964 if( is_at_operational( desc->ad_type ) ) {
969 /* specific attrs requested */
970 if ( is_at_operational( desc->ad_type ) ) {
971 /* if not explicitly requested */
972 if ( !ad_inlist( desc, rs->sr_attrs )) {
973 /* if not all op attrs requested, skip */
974 if ( !SLAP_OPATTRS( rs->sr_attr_flags ))
976 /* if DSA-specific and replicating, skip */
977 if ( op->o_sync != SLAP_CONTROL_NONE &&
978 desc->ad_type->sat_usage == LDAP_SCHEMA_DSA_OPERATION )
982 if ( !userattrs && !ad_inlist( desc, rs->sr_attrs ) ) {
989 if ( ! access_allowed( op, rs->sr_entry, desc, NULL,
990 ACL_READ, &acl_state ) )
992 Debug( LDAP_DEBUG_ACL, "send_search_entry: "
993 "conn %lu access to attribute %s not allowed\n",
994 op->o_connid, desc->ad_cname.bv_val, 0 );
998 if (( rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname )) == -1 ) {
999 Debug( LDAP_DEBUG_ANY,
1000 "send_search_entry: conn %lu ber_printf failed\n",
1001 op->o_connid, 0, 0 );
1003 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1004 send_ldap_error( op, rs, LDAP_OTHER,
1005 "encoding description error");
1013 for ( i = 0; a->a_nvals[i].bv_val != NULL; i++ ) {
1014 if ( ! access_allowed( op, rs->sr_entry,
1015 desc, &a->a_nvals[i], ACL_READ, &acl_state ) )
1017 Debug( LDAP_DEBUG_ACL,
1018 "send_search_entry: conn %lu "
1019 "access to attribute %s, value #%d not allowed\n",
1020 op->o_connid, desc->ad_cname.bv_val, i );
1025 if ( op->o_vrFilter && e_flags[j][i] == 0 ){
1032 if (( rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname )) == -1 ) {
1033 Debug( LDAP_DEBUG_ANY,
1034 "send_search_entry: conn %lu ber_printf failed\n",
1035 op->o_connid, 0, 0 );
1037 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1038 send_ldap_error( op, rs, LDAP_OTHER,
1039 "encoding description error");
1044 if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
1045 Debug( LDAP_DEBUG_ANY,
1046 "send_search_entry: conn %lu "
1047 "ber_printf failed.\n", op->o_connid, 0, 0 );
1049 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1050 send_ldap_error( op, rs, LDAP_OTHER,
1051 "encoding values error" );
1058 if ( finish && ( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
1059 Debug( LDAP_DEBUG_ANY,
1060 "send_search_entry: conn %lu ber_printf failed\n",
1061 op->o_connid, 0, 0 );
1063 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1064 send_ldap_error( op, rs, LDAP_OTHER, "encode end error" );
1070 /* NOTE: moved before overlays callback circling because
1071 * they may modify entry and other stuff in rs */
1072 if ( rs->sr_operational_attrs != NULL && op->o_vrFilter != NULL ) {
1076 for ( a = rs->sr_operational_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
1077 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ ) k++;
1080 size = i * sizeof(char *) + k;
1082 char *a_flags, **tmp;
1085 * Reuse previous memory - we likely need less space
1086 * for operational attributes
1088 tmp = slap_sl_realloc( e_flags, i * sizeof(char *) + k,
1090 if ( tmp == NULL ) {
1091 Debug( LDAP_DEBUG_ANY,
1092 "send_search_entry: conn %lu "
1093 "not enough memory "
1094 "for matched values filtering\n",
1095 op->o_connid, 0, 0 );
1096 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1097 send_ldap_error( op, rs, LDAP_OTHER,
1098 "not enough memory for matched values filtering" );
1102 a_flags = (char *)(e_flags + i);
1103 memset( a_flags, 0, k );
1104 for ( a = rs->sr_operational_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
1105 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ );
1106 e_flags[i] = a_flags;
1109 rc = filter_matched_values(op, rs->sr_operational_attrs, &e_flags) ;
1112 Debug( LDAP_DEBUG_ANY,
1113 "send_search_entry: conn %lu "
1114 "matched values filtering failed\n",
1115 op->o_connid ? op->o_connid : 0, 0, 0);
1116 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1117 send_ldap_error( op, rs, LDAP_OTHER,
1118 "matched values filtering error" );
1125 for (a = rs->sr_operational_attrs, j=0; a != NULL; a = a->a_next, j++ ) {
1126 AttributeDescription *desc = a->a_desc;
1128 if ( rs->sr_attrs == NULL ) {
1129 /* all user attrs request, skip operational attributes */
1130 if( is_at_operational( desc->ad_type ) ) {
1135 /* specific attrs requested */
1136 if( is_at_operational( desc->ad_type ) ) {
1137 if ( !SLAP_OPATTRS( rs->sr_attr_flags ) &&
1138 !ad_inlist( desc, rs->sr_attrs ) )
1143 if ( !userattrs && !ad_inlist( desc, rs->sr_attrs ) ) {
1149 if ( ! access_allowed( op, rs->sr_entry, desc, NULL,
1150 ACL_READ, &acl_state ) )
1152 Debug( LDAP_DEBUG_ACL,
1153 "send_search_entry: conn %lu "
1154 "access to attribute %s not allowed\n",
1155 op->o_connid, desc->ad_cname.bv_val, 0 );
1160 rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname );
1162 Debug( LDAP_DEBUG_ANY,
1163 "send_search_entry: conn %lu "
1164 "ber_printf failed\n", op->o_connid, 0, 0 );
1166 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1167 send_ldap_error( op, rs, LDAP_OTHER,
1168 "encoding description error" );
1173 if ( ! attrsonly ) {
1174 for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
1175 if ( ! access_allowed( op, rs->sr_entry,
1176 desc, &a->a_vals[i], ACL_READ, &acl_state ) )
1178 Debug( LDAP_DEBUG_ACL,
1179 "send_search_entry: conn %lu "
1180 "access to %s, value %d not allowed\n",
1181 op->o_connid, desc->ad_cname.bv_val, i );
1186 if ( op->o_vrFilter && e_flags[j][i] == 0 ){
1190 if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
1191 Debug( LDAP_DEBUG_ANY,
1192 "send_search_entry: conn %lu ber_printf failed\n",
1193 op->o_connid, 0, 0 );
1195 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1196 send_ldap_error( op, rs, LDAP_OTHER,
1197 "encoding values error" );
1204 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
1205 Debug( LDAP_DEBUG_ANY,
1206 "send_search_entry: conn %lu ber_printf failed\n",
1207 op->o_connid, 0, 0 );
1209 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1210 send_ldap_error( op, rs, LDAP_OTHER, "encode end error" );
1218 slap_sl_free( e_flags, op->o_tmpmemctx );
1222 rc = ber_printf( ber, /*{{*/ "}N}" );
1225 rc = send_ldap_controls( op, ber, rs->sr_ctrls );
1229 #ifdef LDAP_CONNECTIONLESS
1230 if( op->o_conn && op->o_conn->c_is_udp ) {
1231 if ( op->o_protocol != LDAP_VERSION2 ) {
1232 rc = ber_printf( ber, /*{*/ "N}" );
1236 if ( op->o_res_ber == NULL ) {
1237 rc = ber_printf( ber, /*{*/ "N}" );
1242 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1244 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1245 send_ldap_error( op, rs, LDAP_OTHER, "encode entry end error" );
1250 Statslog( LDAP_DEBUG_STATS2, "%s ENTRY dn=\"%s\"\n",
1251 op->o_log_prefix, rs->sr_entry->e_nname.bv_val, 0, 0, 0 );
1253 if ( rs->sr_flags & REP_ENTRY_MUSTRELEASE ) {
1254 be_entry_release_rw( op, rs->sr_entry, 0 );
1255 rs->sr_flags ^= REP_ENTRY_MUSTRELEASE;
1256 rs->sr_entry = NULL;
1259 if ( op->o_res_ber == NULL ) {
1260 bytes = send_ldap_ber( op, ber );
1261 ber_free_buf( ber );
1264 Debug( LDAP_DEBUG_ANY,
1265 "send_search_entry: conn %lu ber write failed.\n",
1266 op->o_connid, 0, 0 );
1268 rc = LDAP_UNAVAILABLE;
1273 ldap_pvt_thread_mutex_lock( &op->o_counters->sc_mutex );
1274 ldap_pvt_mp_add_ulong( op->o_counters->sc_bytes, (unsigned long)bytes );
1275 ldap_pvt_mp_add_ulong( op->o_counters->sc_entries, 1 );
1276 ldap_pvt_mp_add_ulong( op->o_counters->sc_pdu, 1 );
1277 ldap_pvt_thread_mutex_unlock( &op->o_counters->sc_mutex );
1280 Debug( LDAP_DEBUG_TRACE,
1281 "<= send_search_entry: conn %lu exit.\n", op->o_connid, 0, 0 );
1286 if ( op->o_callback ) {
1287 (void)slap_cleanup_play( op, rs );
1291 slap_sl_free( e_flags, op->o_tmpmemctx );
1294 if ( rs->sr_operational_attrs ) {
1295 attrs_free( rs->sr_operational_attrs );
1296 rs->sr_operational_attrs = NULL;
1298 rs->sr_attr_flags = SLAP_ATTRS_UNDEFINED;
1300 /* FIXME: I think rs->sr_type should be explicitly set to
1301 * REP_SEARCH here. That's what it was when we entered this
1302 * function. send_ldap_error may have changed it, but we
1303 * should set it back so that the cleanup functions know
1304 * what they're doing.
1306 if ( op->o_tag == LDAP_REQ_SEARCH && rs->sr_type == REP_SEARCH
1308 && ( rs->sr_flags & REP_ENTRY_MUSTBEFREED ) )
1310 entry_free( rs->sr_entry );
1311 rs->sr_entry = NULL;
1312 rs->sr_flags &= ~REP_ENTRY_MUSTBEFREED;
1319 slap_send_search_reference( Operation *op, SlapReply *rs )
1321 BerElementBuffer berbuf;
1322 BerElement *ber = (BerElement *) &berbuf;
1325 char *edn = rs->sr_entry ? rs->sr_entry->e_name.bv_val : "(null)";
1327 AttributeDescription *ad_ref = slap_schema.si_ad_ref;
1328 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
1330 rs->sr_type = REP_SEARCHREF;
1331 if ( op->o_callback ) {
1332 rc = slap_response_play( op, rs );
1333 if ( rc != SLAP_CB_CONTINUE ) {
1338 Debug( LDAP_DEBUG_TRACE,
1339 "=> send_search_reference: dn=\"%s\"\n",
1342 if ( rs->sr_entry && ! access_allowed( op, rs->sr_entry,
1343 ad_entry, NULL, ACL_READ, NULL ) )
1345 Debug( LDAP_DEBUG_ACL,
1346 "send_search_reference: access to entry not allowed\n",
1352 if ( rs->sr_entry && ! access_allowed( op, rs->sr_entry,
1353 ad_ref, NULL, ACL_READ, NULL ) )
1355 Debug( LDAP_DEBUG_ACL,
1356 "send_search_reference: access "
1357 "to reference not allowed\n",
1363 if( op->o_domain_scope ) {
1364 Debug( LDAP_DEBUG_ANY,
1365 "send_search_reference: domainScope control in (%s)\n",
1371 if( rs->sr_ref == NULL ) {
1372 Debug( LDAP_DEBUG_ANY,
1373 "send_search_reference: null ref in (%s)\n",
1379 if( op->o_protocol < LDAP_VERSION3 ) {
1381 /* save the references for the result */
1382 if( rs->sr_ref[0].bv_val != NULL ) {
1383 if( value_add( &rs->sr_v2ref, rs->sr_ref ) )
1389 #ifdef LDAP_CONNECTIONLESS
1390 if( op->o_conn && op->o_conn->c_is_udp ) {
1391 ber = op->o_res_ber;
1395 ber_init_w_nullc( ber, LBER_USE_DER );
1396 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
1399 rc = ber_printf( ber, "{it{W}" /*"}"*/ , op->o_msgid,
1400 LDAP_RES_SEARCH_REFERENCE, rs->sr_ref );
1403 rc = send_ldap_controls( op, ber, rs->sr_ctrls );
1407 rc = ber_printf( ber, /*"{"*/ "N}" );
1411 Debug( LDAP_DEBUG_ANY,
1412 "send_search_reference: ber_printf failed\n", 0, 0, 0 );
1414 #ifdef LDAP_CONNECTIONLESS
1415 if (!op->o_conn || op->o_conn->c_is_udp == 0)
1417 ber_free_buf( ber );
1418 send_ldap_error( op, rs, LDAP_OTHER, "encode DN error" );
1423 if ( rs->sr_flags & REP_ENTRY_MUSTRELEASE ) {
1424 assert( rs->sr_entry != NULL );
1425 be_entry_release_rw( op, rs->sr_entry, 0 );
1426 rs->sr_flags ^= REP_ENTRY_MUSTRELEASE;
1427 rs->sr_entry = NULL;
1430 #ifdef LDAP_CONNECTIONLESS
1431 if (!op->o_conn || op->o_conn->c_is_udp == 0) {
1433 bytes = send_ldap_ber( op, ber );
1434 ber_free_buf( ber );
1437 rc = LDAP_UNAVAILABLE;
1439 ldap_pvt_thread_mutex_lock( &op->o_counters->sc_mutex );
1440 ldap_pvt_mp_add_ulong( op->o_counters->sc_bytes, (unsigned long)bytes );
1441 ldap_pvt_mp_add_ulong( op->o_counters->sc_refs, 1 );
1442 ldap_pvt_mp_add_ulong( op->o_counters->sc_pdu, 1 );
1443 ldap_pvt_thread_mutex_unlock( &op->o_counters->sc_mutex );
1445 #ifdef LDAP_CONNECTIONLESS
1448 if ( rs->sr_ref != NULL ) {
1451 for ( r = 0; !BER_BVISNULL( &rs->sr_ref[ r ] ); r++ ) {
1452 Statslog( LDAP_DEBUG_STATS2, "%s REF #%d \"%s\"\n",
1453 op->o_log_prefix, r, rs->sr_ref[0].bv_val,
1458 Statslog( LDAP_DEBUG_STATS2, "%s REF \"(null)\"\n",
1459 op->o_log_prefix, 0, 0, 0, 0 );
1462 Debug( LDAP_DEBUG_TRACE, "<= send_search_reference\n", 0, 0, 0 );
1465 if ( op->o_callback ) {
1466 (void)slap_cleanup_play( op, rs );
1482 *code = LDAP_SUCCESS;
1486 if ( strncasecmp( s, "RESULT", STRLENOF( "RESULT" ) ) != 0 ) {
1487 Debug( LDAP_DEBUG_ANY, "str2result (%s) expecting \"RESULT\"\n",
1494 while ( (s = strchr( s, '\n' )) != NULL ) {
1499 if ( (c = strchr( s, ':' )) != NULL ) {
1503 if ( strncasecmp( s, "code", STRLENOF( "code" ) ) == 0 ) {
1508 Debug( LDAP_DEBUG_ANY, "str2result (%s) missing value\n",
1514 while ( isspace( (unsigned char) c[ 0 ] ) ) c++;
1515 if ( c[ 0 ] == '\0' ) {
1516 Debug( LDAP_DEBUG_ANY, "str2result (%s) missing or empty value\n",
1522 retcode = strtol( c, &next, 10 );
1523 if ( next == NULL || next == c ) {
1524 Debug( LDAP_DEBUG_ANY, "str2result (%s) unable to parse value\n",
1530 while ( isspace( (unsigned char) next[ 0 ] ) ) next++;
1531 if ( next[ 0 ] != '\0' ) {
1532 Debug( LDAP_DEBUG_ANY, "str2result (%s) extra cruft after value\n",
1538 /* FIXME: what if it's larger that max int? */
1539 *code = (int)retcode;
1541 } else if ( strncasecmp( s, "matched", STRLENOF( "matched" ) ) == 0 ) {
1545 } else if ( strncasecmp( s, "info", STRLENOF( "info" ) ) == 0 ) {
1550 Debug( LDAP_DEBUG_ANY, "str2result (%s) unknown\n",
1560 int slap_read_controls(
1564 const struct berval *oid,
1565 LDAPControl **ctrl )
1569 BerElementBuffer berbuf;
1570 BerElement *ber = (BerElement *) &berbuf;
1574 Debug( LDAP_DEBUG_ANY, "%s slap_read_controls: (%s) %s\n",
1575 op->o_log_prefix, oid->bv_val, e->e_dn );
1578 rs->sr_attrs = ( oid == &slap_pre_read_bv ) ?
1579 op->o_preread_attrs : op->o_postread_attrs;
1581 bv.bv_len = entry_flatsize( rs->sr_entry, 0 );
1582 bv.bv_val = op->o_tmpalloc( bv.bv_len, op->o_tmpmemctx );
1584 ber_init2( ber, &bv, LBER_USE_DER );
1585 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
1587 /* create new operation */
1589 /* FIXME: o_bd needed for ACL */
1590 myop.o_bd = op->o_bd;
1591 myop.o_res_ber = ber;
1592 myop.o_callback = NULL;
1593 myop.ors_slimit = 1;
1595 rc = slap_send_search_entry( &myop, rs );
1598 rc = ber_flatten2( ber, &c.ldctl_value, 0 );
1600 if( rc == -1 ) return LDAP_OTHER;
1602 c.ldctl_oid = oid->bv_val;
1603 c.ldctl_iscritical = 0;
1605 if ( *ctrl == NULL ) {
1607 *ctrl = (LDAPControl *) slap_sl_calloc( 1, sizeof(LDAPControl), NULL );
1609 /* retry: free previous try */
1610 slap_sl_free( (*ctrl)->ldctl_value.bv_val, op->o_tmpmemctx );
1614 return LDAP_SUCCESS;
1617 /* Map API errors to protocol errors... */
1619 slap_map_api2result( SlapReply *rs )
1621 switch(rs->sr_err) {
1622 case LDAP_SERVER_DOWN:
1623 return LDAP_UNAVAILABLE;
1624 case LDAP_LOCAL_ERROR:
1626 case LDAP_ENCODING_ERROR:
1627 case LDAP_DECODING_ERROR:
1628 return LDAP_PROTOCOL_ERROR;
1630 return LDAP_UNAVAILABLE;
1631 case LDAP_AUTH_UNKNOWN:
1632 return LDAP_AUTH_METHOD_NOT_SUPPORTED;
1633 case LDAP_FILTER_ERROR:
1634 rs->sr_text = "Filter error";
1636 case LDAP_USER_CANCELLED:
1637 rs->sr_text = "User cancelled";
1639 case LDAP_PARAM_ERROR:
1640 return LDAP_PROTOCOL_ERROR;
1641 case LDAP_NO_MEMORY:
1643 case LDAP_CONNECT_ERROR:
1644 return LDAP_UNAVAILABLE;
1645 case LDAP_NOT_SUPPORTED:
1646 return LDAP_UNWILLING_TO_PERFORM;
1647 case LDAP_CONTROL_NOT_FOUND:
1648 return LDAP_PROTOCOL_ERROR;
1649 case LDAP_NO_RESULTS_RETURNED:
1650 return LDAP_NO_SUCH_OBJECT;
1651 case LDAP_MORE_RESULTS_TO_RETURN:
1652 rs->sr_text = "More results to return";
1654 case LDAP_CLIENT_LOOP:
1655 case LDAP_REFERRAL_LIMIT_EXCEEDED:
1656 return LDAP_LOOP_DETECT;
1658 if ( LDAP_API_ERROR(rs->sr_err) ) return LDAP_OTHER;
1665 slap_attr_flags( AttributeName *an )
1667 slap_mask_t flags = SLAP_ATTRS_UNDEFINED;
1670 flags |= ( SLAP_OPATTRS_NO | SLAP_USERATTRS_YES );
1673 flags |= an_find( an, slap_bv_all_operational_attrs )
1674 ? SLAP_OPATTRS_YES : SLAP_OPATTRS_NO;
1675 flags |= an_find( an, slap_bv_all_user_attrs )
1676 ? SLAP_USERATTRS_YES : SLAP_USERATTRS_NO;