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
28 #include "../back-ldap/back-ldap.h"
29 #include "back-meta.h"
32 * The meta-directory has one suffix, called <suffix>.
33 * It handles a pool of target servers, each with a branch suffix
34 * of the form <branch X>,<suffix>
36 * When the meta-directory receives a request with a dn that belongs
37 * to a branch, the corresponding target is invoked. When the dn
38 * does not belong to a specific branch, all the targets that
39 * are compatible with the dn are selected as candidates, and
40 * the request is spawned to all the candidate targets
42 * A request is characterized by a dn. The following cases are handled:
43 * - the dn is the suffix: <dn> == <suffix>,
44 * all the targets are candidates (search ...)
45 * - the dn is a branch suffix: <dn> == <branch X>,<suffix>, or
46 * - the dn is a subtree of a branch suffix:
47 * <dn> == <rdn>,<branch X>,<suffix>,
48 * the target is the only candidate.
50 * A possible extension will include the handling of multiple suffixes
54 meta_back_is_candidate_unique(
59 * returns 1 if suffix is candidate for dn, otherwise 0
61 * Note: this function should never be called if dn is the <suffix>.
64 meta_back_is_candidate(
65 struct berval *nsuffix,
69 if ( dnIsSuffix( ndn, nsuffix ) ) {
70 return META_CANDIDATE;
73 if ( scope == LDAP_SCOPE_SUBTREE && dnIsSuffix( nsuffix, ndn ) ) {
75 * suffix longer than dn, but common part matches
77 return META_CANDIDATE;
80 return META_NOT_CANDIDATE;
84 * meta_back_is_candidate_unique
86 * checks whether a candidate is unique
87 * Note: dn MUST be normalized
90 meta_back_is_candidate_unique(
94 switch ( meta_back_select_unique_candidate( mi, ndn ) ) {
95 case META_TARGET_MULTIPLE:
96 case META_TARGET_NONE:
104 * meta_back_select_unique_candidate
106 * returns the index of the candidate in case it is unique, otherwise
107 * META_TARGET_NONE if none matches, or
108 * META_TARGET_MULTIPLE if more than one matches
109 * Note: ndn MUST be normalized.
112 meta_back_select_unique_candidate(
116 int i, candidate = META_TARGET_NONE;
118 for ( i = 0; i < mi->mi_ntargets; ++i ) {
119 if ( meta_back_is_candidate( &mi->mi_targets[ i ].mt_nsuffix, ndn, LDAP_SCOPE_BASE ) )
121 if ( candidate == META_TARGET_NONE ) {
125 return META_TARGET_MULTIPLE;
134 * meta_clear_unused_candidates
136 * clears all candidates except candidate
139 meta_clear_unused_candidates(
143 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
145 SlapReply *candidates = meta_back_candidates_get( op );
147 for ( i = 0; i < mi->mi_ntargets; ++i ) {
148 if ( i == candidate ) {
151 candidates[ i ].sr_tag = META_NOT_CANDIDATE;
158 * meta_clear_one_candidate
160 * clears the selected candidate
163 meta_clear_one_candidate(
164 metasingleconn_t *msc )
167 ldap_unbind_ext_s( msc->msc_ld, NULL, NULL );
171 if ( !BER_BVISNULL( &msc->msc_bound_ndn ) ) {
172 ber_memfree( msc->msc_bound_ndn.bv_val );
173 BER_BVZERO( &msc->msc_bound_ndn );
176 if ( !BER_BVISNULL( &msc->msc_cred ) ) {
177 ber_memfree( msc->msc_cred.bv_val );
178 BER_BVZERO( &msc->msc_cred );