#include "slap.h"
#include "back-ldap.h"
+#include "lutil.h"
int
ldap_back_db_config(
* walk the filter looking for DN-valued attributes,
* and only rewrite those that require rewriting
*/
- char vbuf[LDAP_FILT_MAXSIZ], rbuf[LDAP_FILT_MAXSIZ];
+ char vbuf_[BUFSIZ], *vbuf = vbuf_,
+ rbuf_[BUFSIZ], *rbuf = rbuf_;
+ int len;
+
+ len = snprintf( vbuf, sizeof( vbuf_ ),
+ "(.*)%s\\)(.*)", nvnc->bv_val );
+ if ( len == -1 ) {
+ /*
+ * traditional behavior: snprintf returns -1
+ * if buffer is insufficient
+ */
+ return -1;
+
+ } else if ( len >= sizeof( vbuf_ ) ) {
+ /*
+ * C99: snprintf returns the required size
+ */
+ vbuf = ch_malloc( len + 1 );
+ len = snprintf( vbuf, len,
+ "(.*)%s\\)(.*)", nvnc->bv_val );
+ assert( len > 0 );
+ }
+
+ len = snprintf( rbuf, sizeof( rbuf_ ), "%%1%s)%%2",
+ nrnc->bv_val );
+ if ( len == -1 ) {
+ return -1;
- snprintf( vbuf, sizeof( vbuf ), "(.*)%s\\)(.*)", nvnc->bv_val );
- snprintf( rbuf, sizeof( rbuf ), "%%1%s)%%2", nrnc->bv_val );
+ } else if ( len >= sizeof( rbuf_ ) ) {
+ rbuf = ch_malloc( len + 1 );
+ len = snprintf( rbuf, sizeof( rbuf_ ), "%%1%s)%%2",
+ nrnc->bv_val );
+ assert( len > 0 );
+ }
rargv[ 0 ] = "rewriteRule";
rargv[ 1 ] = vbuf;
rargv[ 3 ] = ":";
rargv[ 4 ] = NULL;
rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
+
+ if ( vbuf != vbuf_ ) {
+ ch_free( vbuf );
+ }
+
+ if ( rbuf != rbuf_ ) {
+ ch_free( rbuf );
+ }
}
#endif /* rewrite filters */
#include "slap.h"
#include "back-ldap.h"
-
+#include "lutil.h"
/* return 0 IFF op_dn is a value in group_at (member) attribute
* of entry with gr_dn AND that entry has an objectClass
}
attrs[ i ] = NULL;
- ldap_add_s( lc->conns[ candidate ]->ld, mdn.bv_val, attrs );
+ ldap_add_s( lc->conns[ candidate ].ld, mdn.bv_val, attrs );
for ( --i; i >= 0; --i ) {
free( attrs[ i ]->mod_vals.modv_bvals );
free( attrs[ i ] );
--- /dev/null
+/*
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ *
+ * Copyright 1999, Howard Chu, All rights reserved. <hyc@highlandsun.com>
+ *
+ * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
+ *
+ * This work has been developed to fulfill the requirements
+ * of SysNet s.n.c. <http:www.sys-net.it> and it has been donated
+ * to the OpenLDAP Foundation in the hope that it may be useful
+ * to the Open Source community, but WITHOUT ANY WARRANTY.
+ *
+ * Permission is granted to anyone to use this software for any purpose
+ * on any computer system, and to alter it and redistribute it, subject
+ * to the following restrictions:
+ *
+ * 1. The author and SysNet s.n.c. are not responsible for the consequences
+ * of use of this software, no matter how awful, even if they arise from
+ * flaws in it.
+ *
+ * 2. The origin of this software must not be misrepresented, either by
+ * explicit claim or by omission. Since few users ever read sources,
+ * credits should appear in the documentation.
+ *
+ * 3. Altered versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software. Since few users
+ * ever read sources, credits should appear in the documentation.
+ * SysNet s.n.c. cannot be responsible for the consequences of the
+ * alterations.
+ *
+ * 4. This notice may not be removed or altered.
+ *
+ *
+ * This software is based on the backend back-ldap, implemented
+ * by Howard Chu <hyc@highlandsun.com>, and modified by Mark Valence
+ * <kurash@sassafras.com>, Pierangelo Masarati <ando@sys-net.it> and other
+ * contributors. The contribution of the original software to the present
+ * implementation is acknowledged in this copyright statement.
+ *
+ * A special acknowledgement goes to Howard for the overall architecture
+ * (and for borrowing large pieces of code), and to Mark, who implemented
+ * from scratch the attribute/objectclass mapping.
+ *
+ * The original copyright statement follows.
+ *
+ * Copyright 1999, Howard Chu, All rights reserved. <hyc@highlandsun.com>
+ *
+ * Permission is granted to anyone to use this software for any purpose
+ * on any computer system, and to alter it and redistribute it, subject
+ * to the following restrictions:
+ *
+ * 1. The author is not responsible for the consequences of use of this
+ * software, no matter how awful, even if they arise from flaws in it.
+ *
+ * 2. The origin of this software must not be misrepresented, either by
+ * explicit claim or by omission. Since few users ever read sources,
+ * credits should appear in the documentation.
+ *
+ * 3. Altered versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software. Since few users
+ * ever read sources, credits should appear in the
+ * documentation.
+ *
+ * 4. This notice may not be removed or altered.
+ *
+ */
+
+#ifndef SLAPD_LDAP_H
+#error "include servers/slapd/back-ldap/back-ldap.h before this file!"
+#endif /* SLAPD_LDAP_H */
+
+#ifndef SLAPD_META_H
+#define SLAPD_META_H
+
+#include "external.h"
+
+/* String rewrite library */
+#include "rewrite.h"
+
+LDAP_BEGIN_DECL
+
+struct slap_conn;
+struct slap_op;
+
+struct metasingleconn {
+ int candidate;
+#define META_NOT_CANDIDATE 0
+#define META_CANDIDATE 1
+#define META_LAST_CONN -1
+
+ LDAP *ld;
+ struct berval bound_dn;
+ int bound;
+#define META_UNBOUND 0
+#define META_BOUND 1
+#define META_ANONYMOUS 2
+};
+
+#define META_LAST(lsc) ((lsc)->candidate == META_LAST_CONN)
+
+struct metaconn {
+ struct slap_conn *conn;
+ struct rewrite_info *rwinfo;
+
+ /*
+ * means that the connection is bound;
+ * of course only one target actually is ...
+ */
+ int bound_target;
+#define META_BOUND_NONE -1
+#define META_BOUND_ALL -2
+ /* supersedes the connection stuff */
+ struct metasingleconn *conns;
+};
+
+struct metatarget {
+ char *uri;
+ struct berval psuffix; /* pretty suffix */
+ struct berval suffix; /* normalized suffix */
+ struct berval binddn;
+ struct berval bindpw;
+
+ struct berval pseudorootdn;
+ struct berval pseudorootpw;
+
+ struct rewrite_info *rwinfo;
+
+ struct ldapmap oc_map;
+ struct ldapmap at_map;
+};
+
+struct metadncache {
+ ldap_pvt_thread_mutex_t mutex;
+ Avlnode *tree;
+
+#define META_DNCACHE_DISABLED 0
+#define META_DNCACHE_FOREVER -1
+ long int ttl; /* seconds; 0: no cache, -1: no expiry */
+};
+
+struct metainfo {
+ int ntargets;
+ int defaulttarget;
+#define META_DEFAULT_TARGET_NONE -1
+ struct metatarget **targets;
+
+ struct metadncache cache;
+
+ ldap_pvt_thread_mutex_t conn_mutex;
+ Avlnode *conntree;
+};
+
+extern int
+meta_back_do_single_bind(
+ struct metainfo *li,
+ struct metaconn *lc,
+ struct berval *dn,
+ struct berval *ndn,
+ struct berval *cred,
+ int method,
+ int candidate
+);
+
+
+#define META_OP_ALLOW_MULTIPLE 0x00
+#define META_OP_REQUIRE_SINGLE 0x01
+#define META_OP_REQUIRE_ALL 0x02
+extern struct metaconn *
+meta_back_getconn(
+ struct metainfo *li,
+ struct slap_conn *conn,
+ struct slap_op *op,
+ int op_type,
+ struct berval *dn,
+ int *candidate
+);
+
+extern int
+meta_back_dobind(
+ struct metaconn *lc,
+ Operation *op
+);
+
+extern int
+meta_back_is_valid(
+ struct metaconn *lc,
+ int candidate
+);
+
+extern int
+meta_back_op_result(
+ struct metaconn *lc,
+ Operation *op
+);
+
+extern int
+back_meta_LTX_init_module(
+ int argc,
+ char *argv[]
+);
+
+extern int
+meta_back_conn_cmp(
+ const void *c1,
+ const void *c2
+);
+
+extern int
+meta_back_conn_dup(
+ void *c1,
+ void *c2
+);
+
+/*
+ * Candidate stuff
+ */
+extern int
+meta_back_is_candidate(
+ struct berval *nsuffix,
+ struct berval *ndn
+);
+
+extern int
+meta_back_count_candidates(
+ struct metainfo *li,
+ struct berval *ndn
+);
+
+extern int
+meta_back_is_candidate_unique(
+ struct metainfo *li,
+ struct berval *ndn
+);
+
+extern int
+meta_back_select_unique_candidate(
+ struct metainfo *li,
+ struct berval *ndn
+);
+
+extern int
+meta_clear_unused_candidates(
+ struct metainfo *li,
+ struct metaconn *lc,
+ int candidate,
+ int reallyclean
+);
+
+extern int
+meta_clear_one_candidate(
+ struct metasingleconn *lc,
+ int reallyclean
+);
+
+/*
+ * Dn cache stuff (experimental)
+ */
+extern int
+meta_dncache_cmp(
+ const void *c1,
+ const void *c2
+);
+
+extern int
+meta_dncache_dup(
+ void *c1,
+ void *c2
+);
+
+extern int
+meta_dncache_get_target(
+ struct metadncache *cache,
+ struct berval *ndn
+);
+
+extern int
+meta_dncache_update_entry(
+ struct metadncache *cache,
+ struct berval *ndn,
+ int target
+);
+
+extern int
+meta_dncache_delete_entry(
+ struct metadncache *cache,
+ struct berval *ndn
+);
+
+extern void
+meta_dncache_free(
+ void *entry
+);
+
+LDAP_END_DECL
+
+#endif /* SLAPD_META_H */
+
/*
* Skip non-candidates
*/
- if ( lc->conns[ i ]->candidate != META_CANDIDATE ) {
+ if ( lc->conns[ i ].candidate != META_CANDIDATE ) {
continue;
}
realdn, realndn, realcred, realmethod, i );
if ( lerr != LDAP_SUCCESS ) {
err = lerr;
- ( void )meta_clear_one_candidate( lc->conns[ i ], 1 );
+ ( void )meta_clear_one_candidate( &lc->conns[ i ], 1 );
} else {
rc = LDAP_SUCCESS;
}
return LDAP_OTHER;
}
- rc = ldap_bind_s( lc->conns[ candidate ]->ld, mdn.bv_val, cred->bv_val, method );
+ rc = ldap_bind_s( lc->conns[ candidate ].ld, mdn.bv_val, cred->bv_val, method );
if ( rc != LDAP_SUCCESS ) {
rc = ldap_back_map_result( rc );
} else {
- ber_dupbv( &lc->conns[ candidate ]->bound_dn, dn );
- lc->conns[ candidate ]->bound = META_BOUND;
+ ber_dupbv( &lc->conns[ candidate ].bound_dn, dn );
+ lc->conns[ candidate ].bound = META_BOUND;
lc->bound_target = candidate;
if ( li->cache.ttl != META_DNCACHE_DISABLED
int
meta_back_dobind( struct metaconn *lc, Operation *op )
{
- struct metasingleconn **lsc;
+ struct metasingleconn *lsc;
int bound = 0, i;
/*
return 1;
}
- for ( i = 0, lsc = lc->conns; lsc[ 0 ] != NULL; ++i, ++lsc ) {
+ for ( i = 0, lsc = lc->conns; !META_LAST(lsc); ++i, ++lsc ) {
int rc;
/*
* Not a candidate or something wrong with this target ...
*/
- if ( lsc[ 0 ]->ld == NULL ) {
+ if ( lsc->ld == NULL ) {
continue;
}
/*
* If the target is already bound it is skipped
*/
- if ( lsc[ 0 ]->bound == META_BOUND && lc->bound_target == i ) {
+ if ( lsc->bound == META_BOUND && lc->bound_target == i ) {
++bound;
continue;
}
* (note: if the target was already bound, the anonymous
* bind clears the previous bind).
*/
- if ( lsc[ 0 ]->bound_dn.bv_val ) {
- ch_free( lsc[ 0 ]->bound_dn.bv_val );
- lsc[ 0 ]->bound_dn.bv_val = NULL;
- lsc[ 0 ]->bound_dn.bv_len = 0;
+ if ( lsc->bound_dn.bv_val ) {
+ ch_free( lsc->bound_dn.bv_val );
+ lsc->bound_dn.bv_val = NULL;
+ lsc->bound_dn.bv_len = 0;
}
- rc = ldap_bind_s( lsc[ 0 ]->ld, 0, NULL, LDAP_AUTH_SIMPLE );
+ rc = ldap_bind_s( lsc->ld, 0, NULL, LDAP_AUTH_SIMPLE );
if ( rc != LDAP_SUCCESS ) {
#ifdef NEW_LOGGING
"meta_back_dobind: (anonymous)"
" bind as \"%s\" failed"
" with error \"%s\"\n",
- lsc[ 0 ]->bound_dn.bv_val,
+ lsc->bound_dn.bv_val,
ldap_err2string( rc ), 0 );
#else /* !NEW_LOGGING */
Debug( LDAP_DEBUG_ANY,
"==>meta_back_dobind: (anonymous)"
" bind as \"%s\" failed"
" with error \"%s\"\n%s",
- lsc[ 0 ]->bound_dn.bv_val,
+ lsc->bound_dn.bv_val,
ldap_err2string( rc ), "" );
#endif /* !NEW_LOGGING */
* due to technical reasons (remote host down?)
* so better clear the handle
*/
- ( void )meta_clear_one_candidate( lsc[ 0 ], 1 );
+ ( void )meta_clear_one_candidate( lsc, 1 );
continue;
} /* else */
- lsc[ 0 ]->bound = META_ANONYMOUS;
+ lsc->bound = META_ANONYMOUS;
++bound;
}
int
meta_back_is_valid( struct metaconn *lc, int candidate )
{
- struct metasingleconn **lsc;
+ struct metasingleconn *lsc;
int i;
assert( lc );
return 0;
}
- for ( i = 0, lsc = lc->conns;
- lsc[ 0 ] != NULL && i < candidate;
+ for ( i = 0, lsc = lc->conns; !META_LAST(lsc) && i < candidate;
++i, ++lsc );
- if ( lsc[ 0 ] ) {
- return( lsc[ 0 ]->ld != NULL );
+ if ( !META_LAST(lsc) ) {
+ return( lsc->ld != NULL );
}
return 0;
meta_back_op_result( struct metaconn *lc, Operation *op )
{
int i, rerr = LDAP_SUCCESS;
- struct metasingleconn **lsc;
+ struct metasingleconn *lsc;
char *rmsg = NULL;
char *rmatch = NULL;
- for ( i = 0, lsc = lc->conns; lsc[ 0 ] != NULL; ++i, ++lsc ) {
+ for ( i = 0, lsc = lc->conns; !META_LAST(lsc); ++i, ++lsc ) {
int err = LDAP_SUCCESS;
char *msg = NULL;
char *match = NULL;
- ldap_get_option( lsc[ 0 ]->ld, LDAP_OPT_ERROR_NUMBER, &err );
+ ldap_get_option( lsc->ld, LDAP_OPT_ERROR_NUMBER, &err );
if ( err != LDAP_SUCCESS ) {
/*
* better check the type of error. In some cases
* success if at least one of the targets gave
* positive result ...
*/
- ldap_get_option( lsc[ 0 ]->ld,
+ ldap_get_option( lsc->ld,
LDAP_OPT_ERROR_STRING, &msg );
- ldap_get_option( lsc[ 0 ]->ld,
+ ldap_get_option( lsc->ld,
LDAP_OPT_MATCHED_DN, &match );
err = ldap_back_map_result( err );
--- /dev/null
+/*
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ *
+ * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
+ *
+ * This work has been developed to fulfill the requirements
+ * of SysNet s.n.c. <http:www.sys-net.it> and it has been donated
+ * to the OpenLDAP Foundation in the hope that it may be useful
+ * to the Open Source community, but WITHOUT ANY WARRANTY.
+ *
+ * Permission is granted to anyone to use this software for any purpose
+ * on any computer system, and to alter it and redistribute it, subject
+ * to the following restrictions:
+ *
+ * 1. The author and SysNet s.n.c. are not responsible for the consequences
+ * of use of this software, no matter how awful, even if they arise from
+ * flaws in it.
+ *
+ * 2. The origin of this software must not be misrepresented, either by
+ * explicit claim or by omission. Since few users ever read sources,
+ * credits should appear in the documentation.
+ *
+ * 3. Altered versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software. Since few users
+ * ever read sources, credits should appear in the documentation.
+ * SysNet s.n.c. cannot be responsible for the consequences of the
+ * alterations.
+ *
+ * 4. This notice may not be removed or altered.
+ *
+ *
+ * This software is based on the backend back-ldap, implemented
+ * by Howard Chu <hyc@highlandsun.com>, and modified by Mark Valence
+ * <kurash@sassafras.com>, Pierangelo Masarati <ando@sys-net.it> and other
+ * contributors. The contribution of the original software to the present
+ * implementation is acknowledged in this copyright statement.
+ *
+ * A special acknowledgement goes to Howard for the overall architecture
+ * (and for borrowing large pieces of code), and to Mark, who implemented
+ * from scratch the attribute/objectclass mapping.
+ *
+ * The original copyright statement follows.
+ *
+ * Copyright 1999, Howard Chu, All rights reserved. <hyc@highlandsun.com>
+ *
+ * Permission is granted to anyone to use this software for any purpose
+ * on any computer system, and to alter it and redistribute it, subject
+ * to the following restrictions:
+ *
+ * 1. The author is not responsible for the consequences of use of this
+ * software, no matter how awful, even if they arise from flaws in it.
+ *
+ * 2. The origin of this software must not be misrepresented, either by
+ * explicit claim or by omission. Since few users ever read sources,
+ * credits should appear in the documentation.
+ *
+ * 3. Altered versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software. Since few users
+ * ever read sources, credits should appear in the
+ * documentation.
+ *
+ * 4. This notice may not be removed or altered.
+ *
+ */
+
+#include "portable.h"
+
+#include <stdio.h>
+
+#include "slap.h"
+#include "../back-ldap/back-ldap.h"
+#include "back-meta.h"
+
+/*
+ * The meta-directory has one suffix, called <suffix>.
+ * It handles a pool of target servers, each with a branch suffix
+ * of the form <branch X>,<suffix>
+ *
+ * When the meta-directory receives a request with a dn that belongs
+ * to a branch, the corresponding target is invoked. When the dn
+ * does not belong to a specific branch, all the targets that
+ * are compatible with the dn are selected as candidates, and
+ * the request is spawned to all the candidate targets
+ *
+ * A request is characterized by a dn. The following cases are handled:
+ * - the dn is the suffix: <dn> == <suffix>,
+ * all the targets are candidates (search ...)
+ * - the dn is a branch suffix: <dn> == <branch X>,<suffix>, or
+ * - the dn is a subtree of a branch suffix:
+ * <dn> == <rdn>,<branch X>,<suffix>,
+ * the target is the only candidate.
+ *
+ * A possible extension will include the handling of multiple suffixes
+ */
+
+/*
+ * returns 1 if suffix is candidate for dn, otherwise 0
+ *
+ * Note: this function should never be called if dn is the <suffix>.
+ */
+int
+meta_back_is_candidate(
+ struct berval *nsuffix,
+ struct berval *ndn
+)
+{
+ if ( dnIsSuffix( nsuffix, ndn ) || dnIsSuffix( ndn, nsuffix ) ) {
+ /*
+ * suffix longer than dn
+ */
+ return META_CANDIDATE;
+ }
+
+ return META_NOT_CANDIDATE;
+}
+
+/*
+ * meta_back_count_candidates
+ *
+ * returns a count of the possible candidate targets
+ * Note: dn MUST be normalized
+ */
+
+int
+meta_back_count_candidates(
+ struct metainfo *li,
+ struct berval *ndn
+)
+{
+ int i, cnt = 0;
+
+ /*
+ * I know assertions should not check run-time values;
+ * at present I didn't find a place for such checks
+ * after config.c
+ */
+ assert( li->targets != NULL );
+ assert( li->ntargets != 0 );
+
+ for ( i = 0; i < li->ntargets; ++i ) {
+ if ( meta_back_is_candidate( &li->targets[ i ]->suffix, ndn ) ) {
+ ++cnt;
+ }
+ }
+
+ return cnt;
+}
+
+/*
+ * meta_back_is_candidate_unique
+ *
+ * checks whether a candidate is unique
+ * Note: dn MUST be normalized
+ */
+int
+meta_back_is_candidate_unique(
+ struct metainfo *li,
+ struct berval *ndn
+)
+{
+ return ( meta_back_count_candidates( li, ndn ) == 1 );
+}
+
+/*
+ * meta_back_select_unique_candidate
+ *
+ * returns the index of the candidate in case it is unique, otherwise -1
+ * Note: dn MUST be normalized.
+ * Note: if defined, the default candidate is returned in case of no match.
+ */
+int
+meta_back_select_unique_candidate(
+ struct metainfo *li,
+ struct berval *ndn
+)
+{
+ int i;
+
+ switch ( meta_back_count_candidates( li, ndn ) ) {
+ case 1:
+ break;
+ case 0:
+ default:
+ return ( li->defaulttarget == META_DEFAULT_TARGET_NONE
+ ? -1 : li->defaulttarget );
+ }
+
+ for ( i = 0; i < li->ntargets; ++i ) {
+ if ( meta_back_is_candidate( &li->targets[ i ]->suffix, ndn ) ) {
+ return i;
+ }
+ }
+
+ return -1;
+}
+
+/*
+ * meta_clear_unused_candidates
+ *
+ * clears all candidates except candidate
+ */
+int
+meta_clear_unused_candidates(
+ struct metainfo *li,
+ struct metaconn *lc,
+ int candidate,
+ int reallyclean
+)
+{
+ int i;
+
+ for ( i = 0; i < li->ntargets; ++i ) {
+ if ( i == candidate ) {
+ continue;
+ }
+ meta_clear_one_candidate( &lc->conns[ i ], reallyclean );
+ }
+
+ return 0;
+}
+
+/*
+ * meta_clear_one_candidate
+ *
+ * clears the selected candidate
+ */
+int
+meta_clear_one_candidate(
+ struct metasingleconn *lsc,
+ int reallyclean
+)
+{
+ lsc->candidate = META_NOT_CANDIDATE;
+
+ if ( !reallyclean ) {
+ return 0;
+ }
+
+ if ( lsc->ld ) {
+ ldap_unbind( lsc->ld );
+ lsc->ld = NULL;
+ }
+
+ if ( lsc->bound_dn.bv_val != NULL ) {
+ ber_memfree( lsc->bound_dn.bv_val );
+ lsc->bound_dn.bv_val = NULL;
+ lsc->bound_dn.bv_len = 0;
+ }
+
+ return 0;
+}
+
{
struct metainfo *li = ( struct metainfo * )be->be_private;
struct metaconn *lc;
- struct metasingleconn **lsc;
+ struct metasingleconn *lsc;
char *match = NULL, *err = NULL, *mmatch = NULL;
int candidates = 0, last = 0, i, count, rc;
int cres = LDAP_SUCCESS, rres = LDAP_SUCCESS;
/*
* start an asynchronous compare for each candidate target
*/
- for ( i = 0, lsc = lc->conns; lsc[ 0 ] != NULL; ++i, ++lsc ) {
+ for ( i = 0, lsc = lc->conns; !META_LAST(lsc); ++i, ++lsc ) {
char *mdn = NULL;
struct berval mapped_attr = ava->aa_desc->ad_cname;
struct berval mapped_value = ava->aa_value;
- if ( lsc[ 0 ]->candidate != META_CANDIDATE ) {
+ if ( lsc->candidate != META_CANDIDATE ) {
continue;
}
&ava->aa_value, &mapped_value, 0 );
if ( mapped_value.bv_val == NULL ) {
- lsc[ 0 ]->candidate = META_NOT_CANDIDATE;
+ lsc->candidate = META_NOT_CANDIDATE;
continue;
}
/*
ldap_back_map( &li->targets[ i ]->at_map,
&ava->aa_desc->ad_cname, &mapped_attr, 0 );
if ( mapped_attr.bv_val == NULL ) {
- lsc[ 0 ]->candidate = META_NOT_CANDIDATE;
+ lsc->candidate = META_NOT_CANDIDATE;
continue;
}
}
* that returns determines the result; a constraint on unicity
* of the result ought to be enforced
*/
- msgid[ i ] = ldap_compare( lc->conns[ i ]->ld, mdn,
+ msgid[ i ] = ldap_compare( lc->conns[ i ].ld, mdn,
mapped_attr.bv_val, mapped_value.bv_val );
if ( msgid[ i ] == -1 ) {
- lsc[ 0 ]->candidate = META_NOT_CANDIDATE;
+ lsc->candidate = META_NOT_CANDIDATE;
continue;
}
/*
* FIXME: should we check for abandon?
*/
- for ( i = 0, lsc = lc->conns; lsc[ 0 ] != NULL; lsc++, i++ ) {
+ for ( i = 0, lsc = lc->conns; !META_LAST(lsc); lsc++, i++ ) {
int lrc;
LDAPMessage *res = NULL;
- if ( lsc[ 0 ]->candidate != META_CANDIDATE ) {
+ if ( lsc->candidate != META_CANDIDATE ) {
continue;
}
- lrc = ldap_result( lsc[ 0 ]->ld, msgid[ i ],
+ lrc = ldap_result( lsc->ld, msgid[ i ],
0, NULL, &res );
if ( lrc == 0 ) {
goto finish;
}
- cres = ldap_result2error( lsc[ 0 ]->ld,
- res, 1 );
+ cres = ldap_result2error( lsc->ld, res, 1 );
switch ( cres ) {
case LDAP_COMPARE_TRUE:
case LDAP_COMPARE_FALSE:
if ( err != NULL ) {
free( err );
}
- ldap_get_option( lsc[ 0 ]->ld,
+ ldap_get_option( lsc->ld,
LDAP_OPT_ERROR_STRING, &err );
if ( match != NULL ) {
free( match );
}
- ldap_get_option( lsc[ 0 ]->ld,
+ ldap_get_option( lsc->ld,
LDAP_OPT_MATCHED_DN, &match );
last = i;
break;
}
- lsc[ 0 ]->candidate = META_NOT_CANDIDATE;
+ lsc->candidate = META_NOT_CANDIDATE;
--candidates;
} else {
- lsc[ 0 ]->candidate = META_NOT_CANDIDATE;
+ lsc->candidate = META_NOT_CANDIDATE;
--candidates;
if ( res ) {
ldap_msgfree( res );
metaconn_alloc( int ntargets )
{
struct metaconn *lc;
- int i;
assert( ntargets > 0 );
/*
* make it a null-terminated array ...
*/
- lc->conns = ch_calloc( sizeof( struct metasingleconn * ), ntargets+1 );
+ lc->conns = ch_calloc( sizeof( struct metasingleconn ), ntargets+1 );
if ( lc->conns == NULL ) {
free( lc );
return NULL;
}
-
- for ( i = 0; i < ntargets; i++ ) {
- lc->conns[ i ] =
- ch_calloc( sizeof( struct metasingleconn ), 1 );
- if ( lc->conns[ i ] == NULL ) {
- charray_free( ( char ** )lc->conns );
- free( lc->conns );
- free( lc );
- return NULL;
- }
- }
+ lc->conns[ ntargets ].candidate = META_LAST_CONN;
lc->bound_target = META_BOUND_NONE;
}
if ( lc->conns ) {
- int i;
-
- for ( i = 0; lc->conns[ i ] != NULL; ++i ) {
- free( lc->conns[ i ] );
- }
- charray_free( ( char ** )lc->conns );
+ ch_free( lc->conns );
}
free( lc );
* sends the appropriate result.
*/
err = init_one_conn( conn, op, li->targets[ i ],
- vers, lc->conns[ i ] );
+ vers, &lc->conns[ i ] );
if ( err != LDAP_SUCCESS ) {
/*
* be init'd, should the other ones
* be tried?
*/
- ( void )meta_clear_one_candidate( lc->conns[ i ], 1 );
+ ( void )meta_clear_one_candidate( &lc->conns[ i ], 1 );
if ( new_conn ) {
metaconn_free( lc );
}
* also init'd
*/
int lerr = init_one_conn( conn, op, li->targets[ i ],
- vers, lc->conns[ i ] );
+ vers, &lc->conns[ i ] );
if ( lerr != LDAP_SUCCESS ) {
/*
* be init'd, should the other ones
* be tried?
*/
- ( void )meta_clear_one_candidate( lc->conns[ i ], 1 );
+ ( void )meta_clear_one_candidate( &lc->conns[ i ], 1 );
err = lerr;
continue;
}
*/
int lerr = init_one_conn( conn, op,
li->targets[ i ],
- vers, lc->conns[ i ] );
+ vers, &lc->conns[ i ] );
if ( lerr != LDAP_SUCCESS ) {
/*
* be init'd, should the other ones
* be tried?
*/
- ( void )meta_clear_one_candidate( lc->conns[ i ], 1 );
+ ( void )meta_clear_one_candidate( &lc->conns[ i ], 1 );
err = lerr;
continue;
}
return -1;
}
- ldap_delete_s( lc->conns[ candidate ]->ld, mdn );
+ ldap_delete_s( lc->conns[ candidate ].ld, mdn );
if ( mdn != dn->bv_val ) {
free( mdn );
#include "slap.h"
#include "../back-ldap/back-ldap.h"
#include "back-meta.h"
+#include "lutil.h"
/* return 0 IFF op_dn is a value in group_at (member) attribute
* of entry with gr_dn AND that entry has an objectClass
struct metaconn *lc
)
{
- struct metasingleconn **lsc;
+ struct metasingleconn *lsc;
- for ( lsc = lc->conns; lsc[ 0 ] != NULL; lsc++ ) {
- if ( lsc[ 0 ]->ld != NULL ) {
- ldap_unbind( lsc[ 0 ]->ld );
+ for ( lsc = lc->conns; !META_LAST(lsc); lsc++ ) {
+ if ( lsc->ld != NULL ) {
+ ldap_unbind( lsc->ld );
}
- if ( lsc[ 0 ]->bound_dn.bv_val ) {
- ber_memfree( lsc[ 0 ]->bound_dn.bv_val );
+ if ( lsc->bound_dn.bv_val ) {
+ ber_memfree( lsc->bound_dn.bv_val );
}
- free( lsc[ 0 ] );
+ free( lsc );
}
free( lc->conns );
free( lc );
}
modv[ i ] = 0;
- ldap_modify_s( lc->conns[ candidate ]->ld, mdn, modv );
+ ldap_modify_s( lc->conns[ candidate ].ld, mdn, modv );
if ( mdn != dn->bv_val ) {
free( mdn );
return -1;
}
- ldap_set_option( lc->conns[ nsCandidate ]->ld,
+ ldap_set_option( lc->conns[ nsCandidate ].ld,
LDAP_OPT_PROTOCOL_VERSION, &version );
/*
return -1;
}
- ldap_rename2_s( lc->conns[ candidate ]->ld, mdn, newrdn->bv_val,
+ ldap_rename2_s( lc->conns[ candidate ].ld, mdn, newrdn->bv_val,
mnewSuperior, deleteoldrdn );
if ( mdn != dn->bv_val ) {
{
struct metainfo *li = ( struct metainfo * )be->be_private;
struct metaconn *lc;
- struct metasingleconn **lsc;
+ struct metasingleconn *lsc;
struct timeval tv;
LDAPMessage *res, *e;
int count, rc = 0, *msgid, sres = LDAP_NO_SUCH_OBJECT;
/*
* Inits searches
*/
- for ( i = 0, lsc = lc->conns; lsc[ 0 ] != NULL; ++i, ++lsc ) {
+ for ( i = 0, lsc = lc->conns; !META_LAST(lsc); ++i, ++lsc ) {
char *realbase = ( char * )base->bv_val;
int realscope = scope;
ber_len_t suffixlen;
char *mapped_filter, **mapped_attrs;
- if ( lsc[ 0 ]->candidate != META_CANDIDATE ) {
+ if ( lsc->candidate != META_CANDIDATE ) {
continue;
}
if ( deref != -1 ) {
- ldap_set_option( lsc[ 0 ]->ld, LDAP_OPT_DEREF,
+ ldap_set_option( lsc->ld, LDAP_OPT_DEREF,
( void * )&deref);
}
if ( tlimit != -1 ) {
- ldap_set_option( lsc[ 0 ]->ld, LDAP_OPT_TIMELIMIT,
+ ldap_set_option( lsc->ld, LDAP_OPT_TIMELIMIT,
( void * )&tlimit);
}
if ( slimit != -1 ) {
- ldap_set_option( lsc[ 0 ]->ld, LDAP_OPT_SIZELIMIT,
+ ldap_set_option( lsc->ld, LDAP_OPT_SIZELIMIT,
( void * )&slimit);
}
/*
* this target is no longer candidate
*/
- lsc[ 0 ]->candidate = META_NOT_CANDIDATE;
+ lsc->candidate = META_NOT_CANDIDATE;
continue;
}
break;
/*
* this target is no longer candidate
*/
- lsc[ 0 ]->candidate = META_NOT_CANDIDATE;
+ lsc->candidate = META_NOT_CANDIDATE;
continue;
}
/*
* Starts the search
*/
- msgid[ i ] = ldap_search( lsc[ 0 ]->ld, mbase, realscope,
+ msgid[ i ] = ldap_search( lsc->ld, mbase, realscope,
mapped_filter, mapped_attrs, attrsonly );
if ( msgid[ i ] == -1 ) {
- lsc[ 0 ]->candidate = META_NOT_CANDIDATE;
+ lsc->candidate = META_NOT_CANDIDATE;
continue;
}
/* check for abandon */
ab = op->o_abandon;
- for ( i = 0, lsc = lc->conns; lsc[ 0 ] != NULL; lsc++, i++ ) {
- if ( lsc[ 0 ]->candidate != META_CANDIDATE ) {
+ for ( i = 0, lsc = lc->conns; !META_LAST(lsc); lsc++, i++ ) {
+ if ( lsc->candidate != META_CANDIDATE ) {
continue;
}
if ( ab ) {
- ldap_abandon( lsc[ 0 ]->ld, msgid[ i ] );
+ ldap_abandon( lsc->ld, msgid[ i ] );
rc = 0;
break;
}
goto finish;
}
- rc = ldap_result( lsc[ 0 ]->ld, msgid[ i ],
+ rc = ldap_result( lsc->ld, msgid[ i ],
0, &tv, &res );
if ( rc == 0 ) {
/* anything else needs be done? */
goto finish;
} else if ( rc == LDAP_RES_SEARCH_ENTRY ) {
- e = ldap_first_entry( lsc[ 0 ]->ld, res );
+ e = ldap_first_entry( lsc->ld, res );
meta_send_entry(be, op, lc, i, e, attrs,
attrsonly);
count++;
ldap_msgfree( res );
gotit = 1;
} else {
- sres = ldap_result2error( lsc[ 0 ]->ld,
+ sres = ldap_result2error( lsc->ld,
res, 1 );
sres = ldap_back_map_result( sres );
if ( err != NULL ) {
free( err );
}
- ldap_get_option( lsc[ 0 ]->ld,
+ ldap_get_option( lsc->ld,
LDAP_OPT_ERROR_STRING, &err );
if ( match != NULL ) {
free( match );
}
- ldap_get_option( lsc[ 0 ]->ld,
+ ldap_get_option( lsc->ld,
LDAP_OPT_MATCHED_DN, &match );
#ifdef NEW_LOGGING
* When no candidates are left,
* the outer cycle finishes
*/
- lsc[ 0 ]->candidate = META_NOT_CANDIDATE;
+ lsc->candidate = META_NOT_CANDIDATE;
--candidates;
}
}
* Cleanup rewrite session
*/
for ( i = 0; i < li->ntargets; ++i ) {
- if ( lc->conns[ i ]->ld == NULL ) {
- free( lc->conns[ i ] );
+ if ( lc->conns[ i ].ld == NULL ) {
continue;
}
rewrite_session_delete( li->targets[ i ]->rwinfo, conn );
- meta_clear_one_candidate( lc->conns[ i ], 1 );
- free( lc->conns[ i ] );
+ meta_clear_one_candidate( &lc->conns[ i ], 1 );
}
free( lc->conns );
#include "portable.h"
#include <stdio.h>
+#include "lutil.h"
#include "slap.h"
#include "back-monitor.h"