2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1999-2005 The OpenLDAP Foundation.
5 * Portions Copyright 2001-2003 Pierangelo Masarati.
6 * Portions Copyright 1999-2003 Howard Chu.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in the file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
18 * This work was initially developed by the Howard Chu for inclusion
19 * in OpenLDAP Software and subsequently enhanced by Pierangelo
27 #include <ac/socket.h>
28 #include <ac/string.h>
32 #include "../back-ldap/back-ldap.h"
33 #include "back-meta.h"
34 #undef ldap_debug /* silence a warning in ldap-int.h */
36 #include "../../../libraries/libldap/ldap-int.h"
47 meta_back_search_start(
51 metasingleconn_t *msc,
56 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
57 struct berval realbase = op->o_req_dn;
58 int realscope = op->ors_scope;
59 ber_len_t suffixlen = 0;
60 struct berval mbase = BER_BVNULL;
61 struct berval mfilter = BER_BVNULL;
62 char **mapped_attrs = NULL;
65 /* should we check return values? */
66 if ( op->ors_deref != -1 ) {
67 ldap_set_option( msc->msc_ld, LDAP_OPT_DEREF,
68 ( void * )&op->ors_deref);
70 if ( op->ors_tlimit != SLAP_NO_LIMIT ) {
71 ldap_set_option( msc->msc_ld, LDAP_OPT_TIMELIMIT,
72 ( void * )&op->ors_tlimit);
74 if ( op->ors_slimit != SLAP_NO_LIMIT ) {
75 ldap_set_option( msc->msc_ld, LDAP_OPT_SIZELIMIT,
76 ( void * )&op->ors_slimit);
79 dc->target = &mi->mi_targets[ candidate ];
82 * modifies the base according to the scope, if required
84 suffixlen = mi->mi_targets[ candidate ].mt_nsuffix.bv_len;
85 if ( suffixlen > op->o_req_ndn.bv_len ) {
86 switch ( op->ors_scope ) {
87 case LDAP_SCOPE_SUBTREE:
89 * make the target suffix the new base
90 * FIXME: this is very forgiving, because
91 * "illegal" searchBases may be turned
92 * into the suffix of the target; however,
93 * the requested searchBase already passed
94 * thru the candidate analyzer...
96 if ( dnIsSuffix( &mi->mi_targets[ candidate ].mt_nsuffix,
99 realbase = mi->mi_targets[ candidate ].mt_nsuffix;
100 #ifdef LDAP_SCOPE_SUBORDINATE
101 if ( mi->mi_targets[ candidate ].mt_scope == LDAP_SCOPE_SUBORDINATE ) {
102 realscope = LDAP_SCOPE_SUBORDINATE;
104 #endif /* LDAP_SCOPE_SUBORDINATE */
108 * this target is no longer candidate
114 #ifdef LDAP_SCOPE_SUBORDINATE
115 case LDAP_SCOPE_SUBORDINATE:
116 #endif /* LDAP_SCOPE_SUBORDINATE */
117 case LDAP_SCOPE_ONELEVEL:
119 struct berval rdn = mi->mi_targets[ candidate ].mt_nsuffix;
120 rdn.bv_len -= op->o_req_ndn.bv_len + STRLENOF( "," );
121 if ( dnIsOneLevelRDN( &rdn )
122 && dnIsSuffix( &mi->mi_targets[ candidate ].mt_nsuffix, &op->o_req_ndn ) )
125 * if there is exactly one level,
126 * make the target suffix the new
127 * base, and make scope "base"
129 realbase = mi->mi_targets[ candidate ].mt_nsuffix;
130 #ifdef LDAP_SCOPE_SUBORDINATE
131 if ( op->ors_scope == LDAP_SCOPE_SUBORDINATE ) {
132 if ( mi->mi_targets[ candidate ].mt_scope == LDAP_SCOPE_SUBORDINATE ) {
133 realscope = LDAP_SCOPE_SUBORDINATE;
135 realscope = LDAP_SCOPE_SUBTREE;
138 #endif /* LDAP_SCOPE_SUBORDINATE */
140 realscope = LDAP_SCOPE_BASE;
143 } /* else continue with the next case */
146 case LDAP_SCOPE_BASE:
148 * this target is no longer candidate
155 * Rewrite the search base, if required
157 dc->ctx = "searchBase";
158 switch ( ldap_back_dn_massage( dc, &realbase, &mbase ) ) {
162 case REWRITE_REGEXEC_UNWILLING:
163 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
164 rs->sr_text = "Operation not allowed";
165 send_ldap_result( op, rs );
168 case REWRITE_REGEXEC_ERR:
171 * this target is no longer candidate
179 rc = ldap_back_filter_map_rewrite( dc, op->ors_filter,
180 &mfilter, BACKLDAP_MAP );
185 case LDAP_COMPARE_FALSE:
188 * this target is no longer candidate
195 * Maps required attributes
197 rc = ldap_back_map_attrs( &mi->mi_targets[ candidate ].mt_rwmap.rwm_at,
198 op->ors_attrs, BACKLDAP_MAP, &mapped_attrs );
199 if ( rc != LDAP_SUCCESS ) {
201 * this target is no longer candidate
210 rc = ldap_search_ext( msc->msc_ld,
211 mbase.bv_val, realscope, mfilter.bv_val,
212 mapped_attrs, op->ors_attrsonly,
213 op->o_ctrls, NULL, NULL, op->ors_slimit,
214 &candidates[ candidate ].sr_msgid );
215 if ( rc == LDAP_SUCCESS ) {
219 candidates[ candidate ].sr_msgid = -1;
224 if ( mapped_attrs ) {
225 free( mapped_attrs );
227 if ( mfilter.bv_val != op->ors_filterstr.bv_val ) {
228 free( mfilter.bv_val );
230 if ( mbase.bv_val != realbase.bv_val ) {
231 free( mbase.bv_val );
238 meta_back_search( Operation *op, SlapReply *rs )
240 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
242 struct timeval tv = { 0, 0 };
244 LDAPMessage *res = NULL, *e;
245 int rc = 0, sres = LDAP_SUCCESS;
246 char *matched = NULL;
247 int i, last = 0, ncandidates = 0,
248 initial_candidates = 0, candidate_match = 0;
252 SlapReply *candidates = meta_back_candidates_get( op );
255 * controls are set in ldap_back_dobind()
257 * FIXME: in case of values return filter, we might want
258 * to map attrs and maybe rewrite value
260 mc = meta_back_getconn( op, rs, NULL, LDAP_BACK_SENDERR );
261 if ( !mc || !meta_back_dobind( op, rs, mc, LDAP_BACK_SENDERR ) ) {
265 dc.conn = op->o_conn;
271 for ( i = 0; i < mi->mi_ntargets; i++ ) {
272 metasingleconn_t *msc = &mc->mc_conns[ i ];
274 candidates[ i ].sr_msgid = -1;
275 candidates[ i ].sr_matched = NULL;
276 candidates[ i ].sr_text = NULL;
277 candidates[ i ].sr_ref = NULL;
278 candidates[ i ].sr_ctrls = NULL;
280 if ( candidates[ i ].sr_tag != META_CANDIDATE
281 || candidates[ i ].sr_err != LDAP_SUCCESS )
286 switch ( meta_back_search_start( op, rs, &dc, msc, i, candidates ) )
301 initial_candidates = ncandidates;
308 for ( i = 0; i < mi->mi_ntargets; i++ ) {
309 if ( candidates[ i ].sr_tag == META_CANDIDATE ) {
317 Debug( LDAP_DEBUG_ANY, "%s meta_back_search: ncandidates=%d "
318 "cnd=\"%s\"\n", op->o_log_prefix, ncandidates, cnd );
322 if ( initial_candidates == 0 ) {
323 /* NOTE: here we are not sending any matchedDN;
324 * this is intended, because if the back-meta
325 * is serving this search request, but no valid
326 * candidate could be looked up, it means that
327 * there is a hole in the mapping of the targets
328 * and thus no knowledge of any remote superior
330 Debug( LDAP_DEBUG_ANY, "%s meta_back_search: "
331 "base=\"%s\" scope=%d: "
332 "no candidate could be selected\n",
333 op->o_log_prefix, op->o_req_dn.bv_val,
336 /* FIXME: we're sending the first error we encounter;
337 * maybe we should pick the worst... */
338 rc = LDAP_NO_SUCH_OBJECT;
339 for ( i = 0; i < mi->mi_ntargets; i++ ) {
340 if ( candidates[ i ].sr_tag == META_CANDIDATE
341 && candidates[ i ].sr_err != LDAP_SUCCESS )
343 rc = candidates[ i ].sr_err;
348 send_ldap_error( op, rs, rc, NULL );
353 /* We pull apart the ber result, stuff it into a slapd entry, and
354 * let send_search_entry stuff it back into ber format. Slow & ugly,
355 * but this is necessary for version matching, and for ACL processing.
358 if ( op->ors_tlimit != SLAP_NO_LIMIT ) {
359 stoptime = op->o_time + op->ors_tlimit;
364 * In case there are no candidates, no cycle takes place...
366 * FIXME: we might use a queue, to better balance the load
367 * among the candidates
369 for ( rc = 0; ncandidates > 0; ) {
370 int gotit = 0, doabandon = 0;
372 for ( i = 0; i < mi->mi_ntargets; i++ ) {
373 metasingleconn_t *msc = &mc->mc_conns[ i ];
375 if ( candidates[ i ].sr_msgid == -1 ) {
379 /* check for abandon */
380 if ( op->o_abandon ) {
385 * FIXME: handle time limit as well?
386 * Note that target servers are likely
387 * to handle it, so at some time we'll
388 * get a LDAP_TIMELIMIT_EXCEEDED from
391 rc = ldap_result( msc->msc_ld, candidates[ i ].sr_msgid,
395 /* FIXME: res should not need to be freed */
396 assert( res == NULL );
398 /* check time limit */
399 if ( op->ors_tlimit != SLAP_NO_LIMIT
400 && slap_get_time() > stoptime )
403 rc = rs->sr_err = LDAP_TIMELIMIT_EXCEEDED;
404 savepriv = op->o_private;
405 op->o_private = (void *)i;
406 send_ldap_result( op, rs );
407 op->o_private = savepriv;
413 } else if ( rc == -1 ) {
415 /* something REALLY bad happened! */
416 ( void )meta_clear_unused_candidates( op, -1 );
417 rs->sr_err = LDAP_OTHER;
418 savepriv = op->o_private;
419 op->o_private = (void *)i;
420 send_ldap_result( op, rs );
421 op->o_private = savepriv;
423 /* anything else needs be done? */
425 /* FIXME: res should not need to be freed */
426 assert( res == NULL );
430 } else if ( rc == LDAP_RES_SEARCH_ENTRY ) {
431 if ( --op->ors_slimit == -1 ) {
435 rs->sr_err = LDAP_SIZELIMIT_EXCEEDED;
436 savepriv = op->o_private;
437 op->o_private = (void *)i;
438 send_ldap_result( op, rs );
439 op->o_private = savepriv;
445 e = ldap_first_entry( msc->msc_ld, res );
446 savepriv = op->o_private;
447 op->o_private = (void *)i;
448 meta_send_entry( op, rs, mc, i, e );
449 op->o_private = savepriv;
458 * If scope is BASE, we need to jump out
459 * as soon as one entry is found; if
460 * the target pool is properly crafted,
461 * this should correspond to the sole
462 * entry that has the base DN
464 /* FIXME: this defeats the purpose of
465 * doing a search with scope == base and
466 * sizelimit = 1 to determine if a
467 * candidate is actually unique */
468 if ( op->ors_scope == LDAP_SCOPE_BASE
469 && rs->sr_nentries > 0 )
478 } else if ( rc == LDAP_RES_SEARCH_REFERENCE ) {
479 char **references = NULL;
484 rc = ldap_parse_reference( msc->msc_ld, res,
485 &references, &rs->sr_ctrls, 1 );
488 if ( rc != LDAP_SUCCESS ) {
492 if ( references == NULL ) {
496 #ifdef ENABLE_REWRITE
497 dc.ctx = "referralDN";
498 #else /* ! ENABLE_REWRITE */
501 #endif /* ! ENABLE_REWRITE */
503 /* FIXME: merge all and return at the end */
505 for ( cnt = 0; references[ cnt ]; cnt++ )
508 rs->sr_ref = ch_calloc( sizeof( struct berval ), cnt + 1 );
510 for ( cnt = 0; references[ cnt ]; cnt++ ) {
511 ber_str2bv( references[ cnt ], 0, 1, &rs->sr_ref[ cnt ] );
513 BER_BVZERO( &rs->sr_ref[ cnt ] );
515 ( void )ldap_back_referral_result_rewrite( &dc, rs->sr_ref );
517 if ( rs->sr_ref != NULL && !BER_BVISNULL( &rs->sr_ref[ 0 ] ) ) {
518 /* ignore return value by now */
519 savepriv = op->o_private;
520 op->o_private = (void *)i;
521 ( void )send_search_reference( op, rs );
522 op->o_private = savepriv;
524 ber_bvarray_free( rs->sr_ref );
530 ldap_value_free( references );
533 if ( rs->sr_ctrls ) {
534 ldap_controls_free( rs->sr_ctrls );
538 } else if ( rc == LDAP_RES_SEARCH_RESULT ) {
539 char buf[ SLAP_TEXT_BUFLEN ];
540 char **references = NULL;
542 if ( ldap_parse_result( msc->msc_ld,
544 &candidates[ i ].sr_err,
545 (char **)&candidates[ i ].sr_matched,
546 NULL /* (char **)&candidates[ i ].sr_text */ ,
548 &candidates[ i ].sr_ctrls, 1 ) != LDAP_SUCCESS )
551 ldap_get_option( msc->msc_ld,
552 LDAP_OPT_ERROR_NUMBER,
554 sres = slap_map_api2result( rs );
558 rs->sr_err = candidates[ i ].sr_err;
559 sres = slap_map_api2result( rs );
562 /* massage matchedDN if need be */
563 if ( candidates[ i ].sr_matched != NULL ) {
564 if ( candidates[ i ].sr_matched[ 0 ] == '\0' ) {
565 ldap_memfree( (char *)candidates[ i ].sr_matched );
566 candidates[ i ].sr_matched = NULL;
569 struct berval match, mmatch;
571 ber_str2bv( candidates[ i ].sr_matched,
574 dc.ctx = "matchedDN";
575 dc.target = &mi->mi_targets[ i ];
577 if ( !ldap_back_dn_massage( &dc, &match, &mmatch ) ) {
578 if ( mmatch.bv_val == match.bv_val ) {
579 candidates[ i ].sr_matched = ch_strdup( mmatch.bv_val );
582 candidates[ i ].sr_matched = mmatch.bv_val;
587 ldap_memfree( match.bv_val );
591 /* just get rid of the error message, if any */
592 if ( candidates[ i ].sr_text && candidates[ i ].sr_text[ 0 ] == '\0' )
594 ldap_memfree( (char *)candidates[ i ].sr_text );
595 candidates[ i ].sr_text = NULL;
598 /* add references to array */
603 for ( cnt = 0; references[ cnt ]; cnt++ )
606 sr_ref = ch_calloc( sizeof( struct berval ), cnt + 1 );
608 for ( cnt = 0; references[ cnt ]; cnt++ ) {
609 ber_str2bv( references[ cnt ], 0, 1, &sr_ref[ cnt ] );
611 BER_BVZERO( &sr_ref[ cnt ] );
613 ( void )ldap_back_referral_result_rewrite( &dc, sr_ref );
616 ldap_value_free( references );
618 if ( rs->sr_v2ref == NULL ) {
619 rs->sr_v2ref = sr_ref;
622 for ( cnt = 0; !BER_BVISNULL( &sr_ref[ cnt ] ); cnt++ ) {
623 ber_bvarray_add( &rs->sr_v2ref, &sr_ref[ cnt ] );
625 ber_memfree( sr_ref );
629 rs->sr_err = candidates[ i ].sr_err;
630 sres = slap_map_api2result( rs );
632 snprintf( buf, sizeof( buf ),
633 "%s meta_back_search[%d] "
634 "match=\"%s\" err=%d\n",
636 candidates[ i ].sr_matched ? candidates[ i ].sr_matched : "",
637 candidates[ i ].sr_err );
638 Debug( LDAP_DEBUG_ANY, "%s", buf, 0, 0 );
641 case LDAP_NO_SUCH_OBJECT:
642 /* is_ok is touched any time a valid
643 * (even intermediate) result is
644 * returned; as a consequence, if
645 * a candidate returns noSuchObject
646 * it is ignored and the candidate
647 * is simply demoted. */
659 if ( META_BACK_ONERR_STOP( mi ) ) {
660 savepriv = op->o_private;
661 op->o_private = (void *)i;
662 send_ldap_result( op, rs );
663 op->o_private = savepriv;
673 * When no candidates are left,
674 * the outer cycle finishes
676 candidates[ i ].sr_msgid = -1;
685 /* check for abandon */
686 if ( op->o_abandon || doabandon ) {
687 for ( i = 0; i < mi->mi_ntargets; i++ ) {
688 metasingleconn_t *msc = &mc->mc_conns[ i ];
690 if ( candidates[ i ].sr_msgid != -1 ) {
691 ldap_abandon_ext( msc->msc_ld,
692 candidates[ i ].sr_msgid,
694 candidates[ i ].sr_msgid = -1;
698 if ( op->o_abandon ) {
706 tv.tv_usec = 100000; /* 0.1 s */
707 ldap_pvt_thread_yield();
717 * FIXME: need a better strategy to handle errors
719 rc = meta_back_op_result( mc, op, rs, META_TARGET_NONE );
724 * Rewrite the matched portion of the search base, if required
726 * FIXME: only the last one gets caught!
728 savepriv = op->o_private;
729 op->o_private = (void *)mi->mi_ntargets;
730 if ( candidate_match > 0 ) {
731 struct berval pmatched = BER_BVNULL;
733 /* we use the first one */
734 for ( i = 0; i < mi->mi_ntargets; i++ ) {
735 if ( candidates[ i ].sr_tag == META_CANDIDATE
736 && candidates[ i ].sr_matched )
738 struct berval bv, pbv;
741 ber_str2bv( candidates[ i ].sr_matched, 0, 0, &bv );
742 rc = dnPretty( NULL, &bv, &pbv, op->o_tmpmemctx );
744 if ( rc == LDAP_SUCCESS ) {
746 /* NOTE: if they all are superiors
747 * of the baseDN, the shorter is also
748 * superior of the longer... */
749 if ( pbv.bv_len > pmatched.bv_len ) {
750 if ( !BER_BVISNULL( &pmatched ) ) {
751 op->o_tmpfree( pmatched.bv_val, op->o_tmpmemctx );
754 op->o_private = (void *)i;
757 op->o_tmpfree( pbv.bv_val, op->o_tmpmemctx );
761 if ( candidates[ i ].sr_matched != NULL ) {
762 free( (char *)candidates[ i ].sr_matched );
763 candidates[ i ].sr_matched = NULL;
768 if ( !BER_BVISNULL( &pmatched ) ) {
769 matched = pmatched.bv_val;
772 } else if ( sres == LDAP_NO_SUCH_OBJECT ) {
773 matched = op->o_bd->be_suffix[ 0 ].bv_val;
782 for ( i = 0; i < mi->mi_ntargets; i++ ) {
783 if ( candidates[ i ].sr_tag == META_CANDIDATE ) {
791 snprintf( buf, sizeof( buf ), "%s meta_back_search: is_scope=%d is_ok=%d cnd=\"%s\"\n",
792 op->o_log_prefix, initial_candidates, is_ok, cnd );
794 Debug( LDAP_DEBUG_ANY, "%s", buf, 0, 0 );
799 * In case we returned at least one entry, we return LDAP_SUCCESS
800 * otherwise, the latter error code we got
802 * FIXME: we should handle error codes and return the more
803 * important/reasonable
806 if ( sres == LDAP_SUCCESS && rs->sr_v2ref ) {
807 sres = LDAP_REFERRAL;
810 rs->sr_matched = matched;
811 rs->sr_ref = ( sres == LDAP_REFERRAL ? rs->sr_v2ref : NULL );
812 send_ldap_result( op, rs );
813 op->o_private = savepriv;
814 rs->sr_matched = NULL;
818 if ( matched && matched != op->o_bd->be_suffix[ 0 ].bv_val ) {
819 op->o_tmpfree( matched, op->o_tmpmemctx );
822 if ( rs->sr_v2ref ) {
823 ber_bvarray_free( rs->sr_v2ref );
826 for ( i = 0; i < mi->mi_ntargets; i++ ) {
827 if ( candidates[ i ].sr_tag != META_CANDIDATE ) {
831 if ( candidates[ i ].sr_matched ) {
832 free( (char *)candidates[ i ].sr_matched );
833 candidates[ i ].sr_matched = NULL;
836 if ( candidates[ i ].sr_text ) {
837 ldap_memfree( (char *)candidates[ i ].sr_text );
838 candidates[ i ].sr_text = NULL;
841 if ( candidates[ i ].sr_ref ) {
842 ber_bvarray_free( candidates[ i ].sr_ref );
843 candidates[ i ].sr_ref = NULL;
846 if ( candidates[ i ].sr_ctrls ) {
847 ldap_controls_free( candidates[ i ].sr_ctrls );
848 candidates[ i ].sr_ctrls = NULL;
852 meta_back_release_conn( op, mc );
865 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
866 struct berval a, mapped;
868 BerElement ber = *e->lm_ber;
869 Attribute *attr, **attrp;
876 if ( ber_scanf( &ber, "{m{", &bdn ) == LBER_ERROR ) {
877 return LDAP_DECODING_ERROR;
881 * Rewrite the dn of the result, if needed
883 dc.target = &mi->mi_targets[ target ];
884 dc.conn = op->o_conn;
886 dc.ctx = "searchResult";
888 rs->sr_err = ldap_back_dn_massage( &dc, &bdn, &dn );
889 if ( rs->sr_err != LDAP_SUCCESS) {
894 * Note: this may fail if the target host(s) schema differs
895 * from the one known to the meta, and a DN with unknown
896 * attributes is returned.
898 * FIXME: should we log anything, or delegate to dnNormalize?
900 rc = dnPrettyNormal( NULL, &dn, &ent.e_name, &ent.e_nname,
902 if ( dn.bv_val != bdn.bv_val ) {
907 if ( rc != LDAP_SUCCESS ) {
908 return LDAP_INVALID_DN_SYNTAX;
914 if ( mi->mi_cache.ttl != META_DNCACHE_DISABLED ) {
915 ( void )meta_dncache_update_entry( &mi->mi_cache,
916 &ent.e_nname, target );
919 attrp = &ent.e_attrs;
921 dc.ctx = "searchAttrDN";
922 while ( ber_scanf( &ber, "{m", &a ) != LBER_ERROR ) {
924 slap_syntax_validate_func *validate;
925 slap_syntax_transform_func *pretty;
927 ldap_back_map( &mi->mi_targets[ target ].mt_rwmap.rwm_at,
928 &a, &mapped, BACKLDAP_REMAP );
929 if ( BER_BVISNULL( &mapped ) || mapped.bv_val[0] == '\0' ) {
932 attr = ( Attribute * )ch_malloc( sizeof( Attribute ) );
933 if ( attr == NULL ) {
939 if ( slap_bv2ad( &mapped, &attr->a_desc, &text )
941 if ( slap_bv2undef_ad( &mapped, &attr->a_desc, &text,
942 SLAP_AD_PROXIED ) != LDAP_SUCCESS )
944 char buf[ SLAP_TEXT_BUFLEN ];
946 snprintf( buf, sizeof( buf ),
947 "%s meta_send_entry(\"%s\"): "
948 "slap_bv2undef_ad(%s): %s\n",
949 op->o_log_prefix, ent.e_name.bv_val,
950 mapped.bv_val, text );
952 Debug( LDAP_DEBUG_ANY, "%s", buf, 0, 0 );
958 /* no subschemaSubentry */
959 if ( attr->a_desc == slap_schema.si_ad_subschemaSubentry
960 || attr->a_desc == slap_schema.si_ad_entryDN )
964 * We eat target's subschemaSubentry because
965 * a search for this value is likely not
966 * to resolve to the appropriate backend;
967 * later, the local subschemaSubentry is
970 * We also eat entryDN because the frontend
971 * will reattach it without checking if already
974 ( void )ber_scanf( &ber, "x" /* [W] */ );
980 if ( ber_scanf( &ber, "[W]", &attr->a_vals ) == LBER_ERROR
981 || attr->a_vals == NULL )
983 attr->a_vals = (struct berval *)&slap_dummy_bv;
986 for ( last = 0; !BER_BVISNULL( &attr->a_vals[ last ] ); ++last )
990 validate = attr->a_desc->ad_type->sat_syntax->ssyn_validate;
991 pretty = attr->a_desc->ad_type->sat_syntax->ssyn_pretty;
993 if ( !validate && !pretty ) {
994 attr->a_nvals = NULL;
999 if ( attr->a_desc == slap_schema.si_ad_objectClass
1000 || attr->a_desc == slap_schema.si_ad_structuralObjectClass )
1004 for ( bv = attr->a_vals; !BER_BVISNULL( bv ); bv++ ) {
1005 ldap_back_map( &mi->mi_targets[ target ].mt_rwmap.rwm_oc,
1006 bv, &mapped, BACKLDAP_REMAP );
1007 if ( BER_BVISNULL( &mapped ) || mapped.bv_val[0] == '\0') {
1013 *bv = attr->a_vals[ last ];
1014 BER_BVZERO( &attr->a_vals[ last ] );
1017 } else if ( mapped.bv_val != bv->bv_val ) {
1019 ber_dupbv( bv, &mapped );
1023 * It is necessary to try to rewrite attributes with
1024 * dn syntax because they might be used in ACLs as
1025 * members of groups; since ACLs are applied to the
1026 * rewritten stuff, no dn-based subecj clause could
1027 * be used at the ldap backend side (see
1028 * http://www.OpenLDAP.org/faq/data/cache/452.html)
1029 * The problem can be overcome by moving the dn-based
1030 * ACLs to the target directory server, and letting
1031 * everything pass thru the ldap backend.
1033 } else if ( attr->a_desc->ad_type->sat_syntax ==
1034 slap_schema.si_syn_distinguishedName )
1036 ldap_dnattr_result_rewrite( &dc, attr->a_vals );
1038 } else if ( attr->a_desc == slap_schema.si_ad_ref ) {
1039 ldap_back_referral_result_rewrite( &dc, attr->a_vals );
1044 for ( i = 0; i < last; i++ ) {
1049 rc = pretty( attr->a_desc->ad_type->sat_syntax,
1050 &attr->a_vals[i], &pval, NULL );
1053 rc = validate( attr->a_desc->ad_type->sat_syntax,
1058 LBER_FREE( attr->a_vals[i].bv_val );
1059 if ( --last == i ) {
1060 BER_BVZERO( &attr->a_vals[ i ] );
1063 attr->a_vals[i] = attr->a_vals[last];
1064 BER_BVZERO( &attr->a_vals[last] );
1070 LBER_FREE( attr->a_vals[i].bv_val );
1071 attr->a_vals[i] = pval;
1076 ch_free( attr->a_vals );
1082 if ( last && attr->a_desc->ad_type->sat_equality &&
1083 attr->a_desc->ad_type->sat_equality->smr_normalize )
1087 attr->a_nvals = ch_malloc( ( last + 1 ) * sizeof( struct berval ) );
1088 for ( i = 0; i<last; i++ ) {
1089 attr->a_desc->ad_type->sat_equality->smr_normalize(
1090 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
1091 attr->a_desc->ad_type->sat_syntax,
1092 attr->a_desc->ad_type->sat_equality,
1093 &attr->a_vals[i], &attr->a_nvals[i],
1096 BER_BVZERO( &attr->a_nvals[i] );
1099 attr->a_nvals = attr->a_vals;
1103 attrp = &attr->a_next;
1106 rs->sr_entry = &ent;
1107 rs->sr_attrs = op->ors_attrs;
1109 send_search_entry( op, rs );
1110 rs->sr_entry = NULL;
1111 rs->sr_attrs = NULL;
1113 if ( !BER_BVISNULL( &ent.e_name ) ) {
1114 free( ent.e_name.bv_val );
1115 BER_BVZERO( &ent.e_name );
1117 if ( !BER_BVISNULL( &ent.e_nname ) ) {
1118 free( ent.e_nname.bv_val );
1119 BER_BVZERO( &ent.e_nname );
1121 entry_clean( &ent );
1123 return LDAP_SUCCESS;