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( ber, &sorted.ldctl_value, 0 ) == -1 ) {
309 (void) ber_free_buf( ber );
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;
620 Debug( LDAP_DEBUG_TRACE,
621 "send_ldap_disconnect %d:%s\n",
622 rs->sr_err, rs->sr_text ? rs->sr_text : "", NULL );
624 if ( op->o_protocol < LDAP_VERSION3 ) {
625 rs->sr_rspoid = NULL;
626 rs->sr_tag = slap_req2res( op->o_tag );
627 rs->sr_msgid = (rs->sr_tag != LBER_SEQUENCE) ? op->o_msgid : 0;
630 rs->sr_rspoid = LDAP_NOTICE_DISCONNECT;
631 rs->sr_tag = LDAP_RES_EXTENDED;
632 rs->sr_msgid = LDAP_RES_UNSOLICITED;
635 if ( send_ldap_response( op, rs ) == SLAP_CB_CONTINUE ) {
636 Statslog( LDAP_DEBUG_STATS,
637 "%s DISCONNECT tag=%lu err=%d text=%s\n",
638 op->o_log_prefix, rs->sr_tag, rs->sr_err,
639 rs->sr_text ? rs->sr_text : "", 0 );
644 slap_send_ldap_result( Operation *op, SlapReply *rs )
647 const char *otext = rs->sr_text;
648 BerVarray oref = rs->sr_ref;
650 rs->sr_type = REP_RESULT;
652 /* Propagate Abandons so that cleanup callbacks can be processed */
653 if ( rs->sr_err == SLAPD_ABANDON || op->o_abandon )
656 assert( !LDAP_API_ERROR( rs->sr_err ) );
658 Debug( LDAP_DEBUG_TRACE,
659 "send_ldap_result: %s p=%d\n",
660 op->o_log_prefix, op->o_protocol, 0 );
662 Debug( LDAP_DEBUG_ARGS,
663 "send_ldap_result: err=%d matched=\"%s\" text=\"%s\"\n",
664 rs->sr_err, rs->sr_matched ? rs->sr_matched : "",
665 rs->sr_text ? rs->sr_text : "" );
669 Debug( LDAP_DEBUG_ARGS,
670 "send_ldap_result: referral=\"%s\"\n",
671 rs->sr_ref[0].bv_val ? rs->sr_ref[0].bv_val : "NULL",
675 assert( rs->sr_err != LDAP_PARTIAL_RESULTS );
677 if ( rs->sr_err == LDAP_REFERRAL ) {
678 if( op->o_domain_scope ) rs->sr_ref = NULL;
680 if( rs->sr_ref == NULL ) {
681 rs->sr_err = LDAP_NO_SUCH_OBJECT;
682 } else if ( op->o_protocol < LDAP_VERSION3 ) {
683 rs->sr_err = LDAP_PARTIAL_RESULTS;
687 if ( op->o_protocol < LDAP_VERSION3 ) {
688 tmp = v2ref( rs->sr_ref, rs->sr_text );
694 rs->sr_tag = slap_req2res( op->o_tag );
695 rs->sr_msgid = (rs->sr_tag != LBER_SEQUENCE) ? op->o_msgid : 0;
697 if ( rs->sr_flags & REP_REF_MUSTBEFREED ) {
698 if ( rs->sr_ref == NULL ) {
699 rs->sr_flags ^= REP_REF_MUSTBEFREED;
700 ber_bvarray_free( oref );
702 oref = NULL; /* send_ldap_response() will free rs->sr_ref if != NULL */
705 if ( send_ldap_response( op, rs ) == SLAP_CB_CONTINUE ) {
706 if ( op->o_tag == LDAP_REQ_SEARCH ) {
707 Statslog( LDAP_DEBUG_STATS,
708 "%s SEARCH RESULT tag=%lu err=%d nentries=%d text=%s\n",
709 op->o_log_prefix, rs->sr_tag, rs->sr_err,
710 rs->sr_nentries, rs->sr_text ? rs->sr_text : "" );
712 Statslog( LDAP_DEBUG_STATS,
713 "%s RESULT tag=%lu err=%d text=%s\n",
714 op->o_log_prefix, rs->sr_tag, rs->sr_err,
715 rs->sr_text ? rs->sr_text : "", 0 );
719 if( tmp != NULL ) ch_free(tmp);
725 send_ldap_sasl( Operation *op, SlapReply *rs )
727 rs->sr_type = REP_SASL;
728 Debug( LDAP_DEBUG_TRACE, "send_ldap_sasl: err=%d len=%ld\n",
730 rs->sr_sasldata ? (long) rs->sr_sasldata->bv_len : -1, NULL );
732 rs->sr_tag = slap_req2res( op->o_tag );
733 rs->sr_msgid = (rs->sr_tag != LBER_SEQUENCE) ? op->o_msgid : 0;
735 if ( send_ldap_response( op, rs ) == SLAP_CB_CONTINUE ) {
736 Statslog( LDAP_DEBUG_STATS,
737 "%s RESULT tag=%lu err=%d text=%s\n",
738 op->o_log_prefix, rs->sr_tag, rs->sr_err,
739 rs->sr_text ? rs->sr_text : "", 0 );
744 slap_send_ldap_extended( Operation *op, SlapReply *rs )
746 rs->sr_type = REP_EXTENDED;
748 Debug( LDAP_DEBUG_TRACE,
749 "send_ldap_extended: err=%d oid=%s len=%ld\n",
751 rs->sr_rspoid ? rs->sr_rspoid : "",
752 rs->sr_rspdata != NULL ? rs->sr_rspdata->bv_len : 0 );
754 rs->sr_tag = slap_req2res( op->o_tag );
755 rs->sr_msgid = (rs->sr_tag != LBER_SEQUENCE) ? op->o_msgid : 0;
757 if ( send_ldap_response( op, rs ) == SLAP_CB_CONTINUE ) {
758 Statslog( LDAP_DEBUG_STATS,
759 "%s RESULT oid=%s err=%d text=%s\n",
760 op->o_log_prefix, rs->sr_rspoid ? rs->sr_rspoid : "",
761 rs->sr_err, rs->sr_text ? rs->sr_text : "", 0 );
766 slap_send_ldap_intermediate( Operation *op, SlapReply *rs )
768 rs->sr_type = REP_INTERMEDIATE;
769 Debug( LDAP_DEBUG_TRACE,
770 "send_ldap_intermediate: err=%d oid=%s len=%ld\n",
772 rs->sr_rspoid ? rs->sr_rspoid : "",
773 rs->sr_rspdata != NULL ? rs->sr_rspdata->bv_len : 0 );
774 rs->sr_tag = LDAP_RES_INTERMEDIATE;
775 rs->sr_msgid = op->o_msgid;
776 if ( send_ldap_response( op, rs ) == SLAP_CB_CONTINUE ) {
777 Statslog( LDAP_DEBUG_STATS2,
778 "%s INTERM oid=%s\n",
780 rs->sr_rspoid ? rs->sr_rspoid : "", 0, 0, 0 );
787 * LDAP_SUCCESS entry sent
788 * LDAP_OTHER entry not sent (other)
789 * LDAP_INSUFFICIENT_ACCESS entry not sent (ACL)
790 * LDAP_UNAVAILABLE entry not sent (connection closed)
791 * LDAP_SIZELIMIT_EXCEEDED entry not sent (caller must send sizelimitExceeded)
795 slap_send_search_entry( Operation *op, SlapReply *rs )
797 BerElementBuffer berbuf;
798 BerElement *ber = (BerElement *) &berbuf;
800 int i, j, rc = LDAP_UNAVAILABLE, bytes;
802 AccessControlState acl_state = ACL_STATE_INIT;
804 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
806 /* a_flags: array of flags telling if the i-th element will be
807 * returned or filtered out
808 * e_flags: array of a_flags
810 char **e_flags = NULL;
812 if ( op->ors_slimit >= 0 && rs->sr_nentries >= op->ors_slimit ) {
813 return LDAP_SIZELIMIT_EXCEEDED;
816 /* Every 64 entries, check for thread pool pause */
817 if ( ( ( rs->sr_nentries & 0x3f ) == 0x3f ) &&
818 ldap_pvt_thread_pool_pausing( &connection_pool ) > 0 )
823 rs->sr_type = REP_SEARCH;
825 /* eventually will loop through generated operational attribute types
826 * currently implemented types include:
827 * entryDN, subschemaSubentry, and hasSubordinates */
828 /* NOTE: moved before overlays callback circling because
829 * they may modify entry and other stuff in rs */
830 /* check for special all operational attributes ("+") type */
831 /* FIXME: maybe we could set this flag at the operation level;
832 * however, in principle the caller of send_search_entry() may
833 * change the attribute list at each call */
834 rs->sr_attr_flags = slap_attr_flags( rs->sr_attrs );
836 rc = backend_operational( op, rs );
841 if ( op->o_callback ) {
842 rc = slap_response_play( op, rs );
843 if ( rc != SLAP_CB_CONTINUE ) {
848 Debug( LDAP_DEBUG_TRACE, "=> send_search_entry: conn %lu dn=\"%s\"%s\n",
849 op->o_connid, rs->sr_entry->e_name.bv_val,
850 op->ors_attrsonly ? " (attrsOnly)" : "" );
852 attrsonly = op->ors_attrsonly;
854 if ( !access_allowed( op, rs->sr_entry, ad_entry, NULL, ACL_READ, NULL )) {
855 Debug( LDAP_DEBUG_ACL,
856 "send_search_entry: conn %lu access to entry (%s) not allowed\n",
857 op->o_connid, rs->sr_entry->e_name.bv_val, 0 );
859 rc = LDAP_INSUFFICIENT_ACCESS;
863 if ( op->o_res_ber ) {
864 /* read back control or LDAP_CONNECTIONLESS */
869 bv.bv_len = entry_flatsize( rs->sr_entry, 0 );
870 bv.bv_val = op->o_tmpalloc( bv.bv_len, op->o_tmpmemctx );
872 ber_init2( ber, &bv, LBER_USE_DER );
873 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
876 #ifdef LDAP_CONNECTIONLESS
877 if ( op->o_conn && op->o_conn->c_is_udp ) {
879 if ( op->o_protocol == LDAP_VERSION2 ) {
880 rc = ber_printf(ber, "t{O{" /*}}*/,
881 LDAP_RES_SEARCH_ENTRY, &rs->sr_entry->e_name );
883 rc = ber_printf( ber, "{it{O{" /*}}}*/, op->o_msgid,
884 LDAP_RES_SEARCH_ENTRY, &rs->sr_entry->e_name );
888 if ( op->o_res_ber ) {
889 /* read back control */
890 rc = ber_printf( ber, "{O{" /*}}*/, &rs->sr_entry->e_name );
892 rc = ber_printf( ber, "{it{O{" /*}}}*/, op->o_msgid,
893 LDAP_RES_SEARCH_ENTRY, &rs->sr_entry->e_name );
897 Debug( LDAP_DEBUG_ANY,
898 "send_search_entry: conn %lu ber_printf failed\n",
899 op->o_connid, 0, 0 );
901 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
902 send_ldap_error( op, rs, LDAP_OTHER, "encoding DN error" );
907 /* check for special all user attributes ("*") type */
908 userattrs = SLAP_USERATTRS( rs->sr_attr_flags );
910 /* create an array of arrays of flags. Each flag corresponds
911 * to particular value of attribute and equals 1 if value matches
912 * to ValuesReturnFilter or 0 if not
914 if ( op->o_vrFilter != NULL ) {
918 for ( a = rs->sr_entry->e_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
919 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ ) k++;
922 size = i * sizeof(char *) + k;
925 e_flags = slap_sl_calloc ( 1, i * sizeof(char *) + k, op->o_tmpmemctx );
926 if( e_flags == NULL ) {
927 Debug( LDAP_DEBUG_ANY,
928 "send_search_entry: conn %lu slap_sl_calloc failed\n",
929 op->o_connid ? op->o_connid : 0, 0, 0 );
932 send_ldap_error( op, rs, LDAP_OTHER, "out of memory" );
935 a_flags = (char *)(e_flags + i);
936 memset( a_flags, 0, k );
937 for ( a=rs->sr_entry->e_attrs, i=0; a != NULL; a=a->a_next, i++ ) {
938 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ );
939 e_flags[i] = a_flags;
943 rc = filter_matched_values(op, rs->sr_entry->e_attrs, &e_flags) ;
945 Debug( LDAP_DEBUG_ANY, "send_search_entry: "
946 "conn %lu matched values filtering failed\n",
947 op->o_connid ? op->o_connid : 0, 0, 0 );
948 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
949 send_ldap_error( op, rs, LDAP_OTHER,
950 "matched values filtering error" );
957 for ( a = rs->sr_entry->e_attrs, j = 0; a != NULL; a = a->a_next, j++ ) {
958 AttributeDescription *desc = a->a_desc;
961 if ( rs->sr_attrs == NULL ) {
962 /* all user attrs request, skip operational attributes */
963 if( is_at_operational( desc->ad_type ) ) {
968 /* specific attrs requested */
969 if ( is_at_operational( desc->ad_type ) ) {
970 /* if not explicitly requested */
971 if ( !ad_inlist( desc, rs->sr_attrs )) {
972 /* if not all op attrs requested, skip */
973 if ( !SLAP_OPATTRS( rs->sr_attr_flags ))
975 /* if DSA-specific and replicating, skip */
976 if ( op->o_sync != SLAP_CONTROL_NONE &&
977 desc->ad_type->sat_usage == LDAP_SCHEMA_DSA_OPERATION )
981 if ( !userattrs && !ad_inlist( desc, rs->sr_attrs ) ) {
988 if ( ! access_allowed( op, rs->sr_entry, desc, NULL,
989 ACL_READ, &acl_state ) )
991 Debug( LDAP_DEBUG_ACL, "send_search_entry: "
992 "conn %lu access to attribute %s not allowed\n",
993 op->o_connid, desc->ad_cname.bv_val, 0 );
997 if (( rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname )) == -1 ) {
998 Debug( LDAP_DEBUG_ANY,
999 "send_search_entry: conn %lu ber_printf failed\n",
1000 op->o_connid, 0, 0 );
1002 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1003 send_ldap_error( op, rs, LDAP_OTHER,
1004 "encoding description error");
1012 for ( i = 0; a->a_nvals[i].bv_val != NULL; i++ ) {
1013 if ( ! access_allowed( op, rs->sr_entry,
1014 desc, &a->a_nvals[i], ACL_READ, &acl_state ) )
1016 Debug( LDAP_DEBUG_ACL,
1017 "send_search_entry: conn %lu "
1018 "access to attribute %s, value #%d not allowed\n",
1019 op->o_connid, desc->ad_cname.bv_val, i );
1024 if ( op->o_vrFilter && e_flags[j][i] == 0 ){
1031 if (( rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname )) == -1 ) {
1032 Debug( LDAP_DEBUG_ANY,
1033 "send_search_entry: conn %lu ber_printf failed\n",
1034 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 description error");
1043 if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
1044 Debug( LDAP_DEBUG_ANY,
1045 "send_search_entry: conn %lu "
1046 "ber_printf failed.\n", op->o_connid, 0, 0 );
1048 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1049 send_ldap_error( op, rs, LDAP_OTHER,
1050 "encoding values error" );
1057 if ( finish && ( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
1058 Debug( LDAP_DEBUG_ANY,
1059 "send_search_entry: conn %lu ber_printf failed\n",
1060 op->o_connid, 0, 0 );
1062 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1063 send_ldap_error( op, rs, LDAP_OTHER, "encode end error" );
1069 /* NOTE: moved before overlays callback circling because
1070 * they may modify entry and other stuff in rs */
1071 if ( rs->sr_operational_attrs != NULL && op->o_vrFilter != NULL ) {
1075 for ( a = rs->sr_operational_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
1076 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ ) k++;
1079 size = i * sizeof(char *) + k;
1081 char *a_flags, **tmp;
1084 * Reuse previous memory - we likely need less space
1085 * for operational attributes
1087 tmp = slap_sl_realloc( e_flags, i * sizeof(char *) + k,
1089 if ( tmp == NULL ) {
1090 Debug( LDAP_DEBUG_ANY,
1091 "send_search_entry: conn %lu "
1092 "not enough memory "
1093 "for matched values filtering\n",
1094 op->o_connid, 0, 0 );
1095 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1096 send_ldap_error( op, rs, LDAP_OTHER,
1097 "not enough memory for matched values filtering" );
1101 a_flags = (char *)(e_flags + i);
1102 memset( a_flags, 0, k );
1103 for ( a = rs->sr_operational_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
1104 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ );
1105 e_flags[i] = a_flags;
1108 rc = filter_matched_values(op, rs->sr_operational_attrs, &e_flags) ;
1111 Debug( LDAP_DEBUG_ANY,
1112 "send_search_entry: conn %lu "
1113 "matched values filtering failed\n",
1114 op->o_connid ? op->o_connid : 0, 0, 0);
1115 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1116 send_ldap_error( op, rs, LDAP_OTHER,
1117 "matched values filtering error" );
1124 for (a = rs->sr_operational_attrs, j=0; a != NULL; a = a->a_next, j++ ) {
1125 AttributeDescription *desc = a->a_desc;
1127 if ( rs->sr_attrs == NULL ) {
1128 /* all user attrs request, skip operational attributes */
1129 if( is_at_operational( desc->ad_type ) ) {
1134 /* specific attrs requested */
1135 if( is_at_operational( desc->ad_type ) ) {
1136 if ( !SLAP_OPATTRS( rs->sr_attr_flags ) &&
1137 !ad_inlist( desc, rs->sr_attrs ) )
1142 if ( !userattrs && !ad_inlist( desc, rs->sr_attrs ) ) {
1148 if ( ! access_allowed( op, rs->sr_entry, desc, NULL,
1149 ACL_READ, &acl_state ) )
1151 Debug( LDAP_DEBUG_ACL,
1152 "send_search_entry: conn %lu "
1153 "access to attribute %s not allowed\n",
1154 op->o_connid, desc->ad_cname.bv_val, 0 );
1159 rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname );
1161 Debug( LDAP_DEBUG_ANY,
1162 "send_search_entry: conn %lu "
1163 "ber_printf failed\n", op->o_connid, 0, 0 );
1165 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1166 send_ldap_error( op, rs, LDAP_OTHER,
1167 "encoding description error" );
1172 if ( ! attrsonly ) {
1173 for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
1174 if ( ! access_allowed( op, rs->sr_entry,
1175 desc, &a->a_vals[i], ACL_READ, &acl_state ) )
1177 Debug( LDAP_DEBUG_ACL,
1178 "send_search_entry: conn %lu "
1179 "access to %s, value %d not allowed\n",
1180 op->o_connid, desc->ad_cname.bv_val, i );
1185 if ( op->o_vrFilter && e_flags[j][i] == 0 ){
1189 if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
1190 Debug( LDAP_DEBUG_ANY,
1191 "send_search_entry: conn %lu ber_printf failed\n",
1192 op->o_connid, 0, 0 );
1194 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1195 send_ldap_error( op, rs, LDAP_OTHER,
1196 "encoding values error" );
1203 if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
1204 Debug( LDAP_DEBUG_ANY,
1205 "send_search_entry: conn %lu ber_printf failed\n",
1206 op->o_connid, 0, 0 );
1208 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1209 send_ldap_error( op, rs, LDAP_OTHER, "encode end error" );
1217 slap_sl_free( e_flags, op->o_tmpmemctx );
1221 rc = ber_printf( ber, /*{{*/ "}N}" );
1224 rc = send_ldap_controls( op, ber, rs->sr_ctrls );
1228 #ifdef LDAP_CONNECTIONLESS
1229 if( op->o_conn && op->o_conn->c_is_udp ) {
1230 if ( op->o_protocol != LDAP_VERSION2 ) {
1231 rc = ber_printf( ber, /*{*/ "N}" );
1235 if ( op->o_res_ber == NULL ) {
1236 rc = ber_printf( ber, /*{*/ "N}" );
1241 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
1243 if ( op->o_res_ber == NULL ) ber_free_buf( ber );
1244 send_ldap_error( op, rs, LDAP_OTHER, "encode entry end error" );
1249 Statslog( LDAP_DEBUG_STATS2, "%s ENTRY dn=\"%s\"\n",
1250 op->o_log_prefix, rs->sr_entry->e_nname.bv_val, 0, 0, 0 );
1252 if ( rs->sr_flags & REP_ENTRY_MUSTRELEASE ) {
1253 be_entry_release_rw( op, rs->sr_entry, 0 );
1254 rs->sr_flags ^= REP_ENTRY_MUSTRELEASE;
1255 rs->sr_entry = NULL;
1258 if ( op->o_res_ber == NULL ) {
1259 bytes = send_ldap_ber( op, ber );
1260 ber_free_buf( ber );
1263 Debug( LDAP_DEBUG_ANY,
1264 "send_search_entry: conn %lu ber write failed.\n",
1265 op->o_connid, 0, 0 );
1267 rc = LDAP_UNAVAILABLE;
1272 ldap_pvt_thread_mutex_lock( &op->o_counters->sc_mutex );
1273 ldap_pvt_mp_add_ulong( op->o_counters->sc_bytes, (unsigned long)bytes );
1274 ldap_pvt_mp_add_ulong( op->o_counters->sc_entries, 1 );
1275 ldap_pvt_mp_add_ulong( op->o_counters->sc_pdu, 1 );
1276 ldap_pvt_thread_mutex_unlock( &op->o_counters->sc_mutex );
1279 Debug( LDAP_DEBUG_TRACE,
1280 "<= send_search_entry: conn %lu exit.\n", op->o_connid, 0, 0 );
1285 if ( op->o_callback ) {
1286 (void)slap_cleanup_play( op, rs );
1290 slap_sl_free( e_flags, op->o_tmpmemctx );
1293 if ( rs->sr_operational_attrs ) {
1294 attrs_free( rs->sr_operational_attrs );
1295 rs->sr_operational_attrs = NULL;
1297 rs->sr_attr_flags = SLAP_ATTRS_UNDEFINED;
1299 /* FIXME: I think rs->sr_type should be explicitly set to
1300 * REP_SEARCH here. That's what it was when we entered this
1301 * function. send_ldap_error may have changed it, but we
1302 * should set it back so that the cleanup functions know
1303 * what they're doing.
1305 if ( op->o_tag == LDAP_REQ_SEARCH && rs->sr_type == REP_SEARCH
1307 && ( rs->sr_flags & REP_ENTRY_MUSTBEFREED ) )
1309 entry_free( rs->sr_entry );
1310 rs->sr_entry = NULL;
1311 rs->sr_flags &= ~REP_ENTRY_MUSTBEFREED;
1318 slap_send_search_reference( Operation *op, SlapReply *rs )
1320 BerElementBuffer berbuf;
1321 BerElement *ber = (BerElement *) &berbuf;
1324 char *edn = rs->sr_entry ? rs->sr_entry->e_name.bv_val : "(null)";
1326 AttributeDescription *ad_ref = slap_schema.si_ad_ref;
1327 AttributeDescription *ad_entry = slap_schema.si_ad_entry;
1329 rs->sr_type = REP_SEARCHREF;
1330 if ( op->o_callback ) {
1331 rc = slap_response_play( op, rs );
1332 if ( rc != SLAP_CB_CONTINUE ) {
1337 Debug( LDAP_DEBUG_TRACE,
1338 "=> send_search_reference: dn=\"%s\"\n",
1341 if ( rs->sr_entry && ! access_allowed( op, rs->sr_entry,
1342 ad_entry, NULL, ACL_READ, NULL ) )
1344 Debug( LDAP_DEBUG_ACL,
1345 "send_search_reference: access to entry not allowed\n",
1351 if ( rs->sr_entry && ! access_allowed( op, rs->sr_entry,
1352 ad_ref, NULL, ACL_READ, NULL ) )
1354 Debug( LDAP_DEBUG_ACL,
1355 "send_search_reference: access "
1356 "to reference not allowed\n",
1362 if( op->o_domain_scope ) {
1363 Debug( LDAP_DEBUG_ANY,
1364 "send_search_reference: domainScope control in (%s)\n",
1370 if( rs->sr_ref == NULL ) {
1371 Debug( LDAP_DEBUG_ANY,
1372 "send_search_reference: null ref in (%s)\n",
1378 if( op->o_protocol < LDAP_VERSION3 ) {
1380 /* save the references for the result */
1381 if( rs->sr_ref[0].bv_val != NULL ) {
1382 if( value_add( &rs->sr_v2ref, rs->sr_ref ) )
1388 #ifdef LDAP_CONNECTIONLESS
1389 if( op->o_conn && op->o_conn->c_is_udp ) {
1390 ber = op->o_res_ber;
1394 ber_init_w_nullc( ber, LBER_USE_DER );
1395 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
1398 rc = ber_printf( ber, "{it{W}" /*"}"*/ , op->o_msgid,
1399 LDAP_RES_SEARCH_REFERENCE, rs->sr_ref );
1402 rc = send_ldap_controls( op, ber, rs->sr_ctrls );
1406 rc = ber_printf( ber, /*"{"*/ "N}" );
1410 Debug( LDAP_DEBUG_ANY,
1411 "send_search_reference: ber_printf failed\n", 0, 0, 0 );
1413 #ifdef LDAP_CONNECTIONLESS
1414 if (!op->o_conn || op->o_conn->c_is_udp == 0)
1416 ber_free_buf( ber );
1417 send_ldap_error( op, rs, LDAP_OTHER, "encode DN error" );
1422 if ( rs->sr_flags & REP_ENTRY_MUSTRELEASE ) {
1423 assert( rs->sr_entry != NULL );
1424 be_entry_release_rw( op, rs->sr_entry, 0 );
1425 rs->sr_flags ^= REP_ENTRY_MUSTRELEASE;
1426 rs->sr_entry = NULL;
1429 #ifdef LDAP_CONNECTIONLESS
1430 if (!op->o_conn || op->o_conn->c_is_udp == 0) {
1432 bytes = send_ldap_ber( op, ber );
1433 ber_free_buf( ber );
1436 rc = LDAP_UNAVAILABLE;
1438 ldap_pvt_thread_mutex_lock( &op->o_counters->sc_mutex );
1439 ldap_pvt_mp_add_ulong( op->o_counters->sc_bytes, (unsigned long)bytes );
1440 ldap_pvt_mp_add_ulong( op->o_counters->sc_refs, 1 );
1441 ldap_pvt_mp_add_ulong( op->o_counters->sc_pdu, 1 );
1442 ldap_pvt_thread_mutex_unlock( &op->o_counters->sc_mutex );
1444 #ifdef LDAP_CONNECTIONLESS
1447 if ( rs->sr_ref != NULL ) {
1450 for ( r = 0; !BER_BVISNULL( &rs->sr_ref[ r ] ); r++ ) {
1451 Statslog( LDAP_DEBUG_STATS2, "%s REF #%d \"%s\"\n",
1452 op->o_log_prefix, r, rs->sr_ref[0].bv_val,
1457 Statslog( LDAP_DEBUG_STATS2, "%s REF \"(null)\"\n",
1458 op->o_log_prefix, 0, 0, 0, 0 );
1461 Debug( LDAP_DEBUG_TRACE, "<= send_search_reference\n", 0, 0, 0 );
1464 if ( op->o_callback ) {
1465 (void)slap_cleanup_play( op, rs );
1481 *code = LDAP_SUCCESS;
1485 if ( strncasecmp( s, "RESULT", STRLENOF( "RESULT" ) ) != 0 ) {
1486 Debug( LDAP_DEBUG_ANY, "str2result (%s) expecting \"RESULT\"\n",
1493 while ( (s = strchr( s, '\n' )) != NULL ) {
1498 if ( (c = strchr( s, ':' )) != NULL ) {
1502 if ( strncasecmp( s, "code", STRLENOF( "code" ) ) == 0 ) {
1507 Debug( LDAP_DEBUG_ANY, "str2result (%s) missing value\n",
1513 while ( isspace( (unsigned char) c[ 0 ] ) ) c++;
1514 if ( c[ 0 ] == '\0' ) {
1515 Debug( LDAP_DEBUG_ANY, "str2result (%s) missing or empty value\n",
1521 retcode = strtol( c, &next, 10 );
1522 if ( next == NULL || next == c ) {
1523 Debug( LDAP_DEBUG_ANY, "str2result (%s) unable to parse value\n",
1529 while ( isspace( (unsigned char) next[ 0 ] ) ) next++;
1530 if ( next[ 0 ] != '\0' ) {
1531 Debug( LDAP_DEBUG_ANY, "str2result (%s) extra cruft after value\n",
1537 /* FIXME: what if it's larger that max int? */
1538 *code = (int)retcode;
1540 } else if ( strncasecmp( s, "matched", STRLENOF( "matched" ) ) == 0 ) {
1544 } else if ( strncasecmp( s, "info", STRLENOF( "info" ) ) == 0 ) {
1549 Debug( LDAP_DEBUG_ANY, "str2result (%s) unknown\n",
1559 int slap_read_controls(
1563 const struct berval *oid,
1564 LDAPControl **ctrl )
1568 BerElementBuffer berbuf;
1569 BerElement *ber = (BerElement *) &berbuf;
1573 Debug( LDAP_DEBUG_ANY, "%s slap_read_controls: (%s) %s\n",
1574 op->o_log_prefix, oid->bv_val, e->e_dn );
1577 rs->sr_attrs = ( oid == &slap_pre_read_bv ) ?
1578 op->o_preread_attrs : op->o_postread_attrs;
1580 bv.bv_len = entry_flatsize( rs->sr_entry, 0 );
1581 bv.bv_val = op->o_tmpalloc( bv.bv_len, op->o_tmpmemctx );
1583 ber_init2( ber, &bv, LBER_USE_DER );
1584 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
1586 /* create new operation */
1588 /* FIXME: o_bd needed for ACL */
1589 myop.o_bd = op->o_bd;
1590 myop.o_res_ber = ber;
1591 myop.o_callback = NULL;
1592 myop.ors_slimit = 1;
1594 rc = slap_send_search_entry( &myop, rs );
1597 rc = ber_flatten2( ber, &c.ldctl_value, 0 );
1599 if( rc == -1 ) return LDAP_OTHER;
1601 c.ldctl_oid = oid->bv_val;
1602 c.ldctl_iscritical = 0;
1604 if ( *ctrl == NULL ) {
1606 *ctrl = (LDAPControl *) slap_sl_calloc( 1, sizeof(LDAPControl), NULL );
1608 /* retry: free previous try */
1609 slap_sl_free( (*ctrl)->ldctl_value.bv_val, op->o_tmpmemctx );
1613 return LDAP_SUCCESS;
1616 /* Map API errors to protocol errors... */
1618 slap_map_api2result( SlapReply *rs )
1620 switch(rs->sr_err) {
1621 case LDAP_SERVER_DOWN:
1622 return LDAP_UNAVAILABLE;
1623 case LDAP_LOCAL_ERROR:
1625 case LDAP_ENCODING_ERROR:
1626 case LDAP_DECODING_ERROR:
1627 return LDAP_PROTOCOL_ERROR;
1629 return LDAP_UNAVAILABLE;
1630 case LDAP_AUTH_UNKNOWN:
1631 return LDAP_AUTH_METHOD_NOT_SUPPORTED;
1632 case LDAP_FILTER_ERROR:
1633 rs->sr_text = "Filter error";
1635 case LDAP_USER_CANCELLED:
1636 rs->sr_text = "User cancelled";
1638 case LDAP_PARAM_ERROR:
1639 return LDAP_PROTOCOL_ERROR;
1640 case LDAP_NO_MEMORY:
1642 case LDAP_CONNECT_ERROR:
1643 return LDAP_UNAVAILABLE;
1644 case LDAP_NOT_SUPPORTED:
1645 return LDAP_UNWILLING_TO_PERFORM;
1646 case LDAP_CONTROL_NOT_FOUND:
1647 return LDAP_PROTOCOL_ERROR;
1648 case LDAP_NO_RESULTS_RETURNED:
1649 return LDAP_NO_SUCH_OBJECT;
1650 case LDAP_MORE_RESULTS_TO_RETURN:
1651 rs->sr_text = "More results to return";
1653 case LDAP_CLIENT_LOOP:
1654 case LDAP_REFERRAL_LIMIT_EXCEEDED:
1655 return LDAP_LOOP_DETECT;
1657 if ( LDAP_API_ERROR(rs->sr_err) ) return LDAP_OTHER;
1664 slap_attr_flags( AttributeName *an )
1666 slap_mask_t flags = SLAP_ATTRS_UNDEFINED;
1669 flags |= ( SLAP_OPATTRS_NO | SLAP_USERATTRS_YES );
1672 flags |= an_find( an, slap_bv_all_operational_attrs )
1673 ? SLAP_OPATTRS_YES : SLAP_OPATTRS_NO;
1674 flags |= an_find( an, slap_bv_all_user_attrs )
1675 ? SLAP_USERATTRS_YES : SLAP_USERATTRS_NO;