LDAPMod **attrs;
struct berval mdn = BER_BVNULL, mapped;
dncookie dc;
- int msgid, do_retry = 1;
+ int do_retry = 1;
Debug(LDAP_DEBUG_ARGS, "==> meta_back_add: %s\n",
op->o_req_dn.bv_val, 0, 0 );
/*
* Rewrite the add dn, if needed
*/
- dc.rwmap = &mi->mi_targets[ candidate ]->mt_rwmap;
+ dc.target = &mi->mi_targets[ candidate ];
dc.conn = op->o_conn;
dc.rs = rs;
dc.ctx = "addDN";
mapped = a->a_desc->ad_cname;
} else {
- ldap_back_map( &mi->mi_targets[ candidate ]->mt_rwmap.rwm_at,
+ ldap_back_map( &mi->mi_targets[ candidate ].mt_rwmap.rwm_at,
&a->a_desc->ad_cname, &mapped, BACKLDAP_MAP );
if ( BER_BVISNULL( &mapped ) || BER_BVISEMPTY( &mapped ) ) {
continue;
for ( j = 0; !BER_BVISNULL( &a->a_vals[ j ] ); ) {
struct ldapmapping *mapping;
- ldap_back_mapping( &mi->mi_targets[ candidate ]->mt_rwmap.rwm_oc,
+ ldap_back_mapping( &mi->mi_targets[ candidate ].mt_rwmap.rwm_oc,
&a->a_vals[ j ], &mapping, BACKLDAP_MAP );
if ( mapping == NULL ) {
- if ( mi->mi_targets[ candidate ]->mt_rwmap.rwm_oc.drop_missing ) {
+ if ( mi->mi_targets[ candidate ].mt_rwmap.rwm_oc.drop_missing ) {
continue;
}
attrs[ i ]->mod_bvalues[ j ] = &a->a_vals[ j ];
/* Whatever context ldap_back_dn_massage needs... */
typedef struct dncookie {
- struct ldaprwmap *rwmap;
+ struct metatarget_t *target;
#ifdef ENABLE_REWRITE
- Connection *conn;
- char *ctx;
- SlapReply *rs;
+ Connection *conn;
+ char *ctx;
+ SlapReply *rs;
#else
- int normalized;
- int tofrom;
+ int normalized;
+ int tofrom;
#endif
} dncookie;
/* (end of) from back-ldap.h before rwm removal */
+struct metainfo_t;
+
typedef struct metasingleconn_t {
int msc_candidate;
#define META_NOT_CANDIDATE ((ber_tag_t)0)
#define META_UNBOUND 0
#define META_BOUND 1
#define META_ANONYMOUS 2
+
+ struct metainfo_t *msc_info;
} metasingleconn_t;
#define META_LAST(msc) ((msc)->msc_candidate == META_LAST_CONN)
typedef struct metatarget_t {
char *mt_uri;
+
struct berval mt_psuffix; /* pretty suffix */
struct berval mt_nsuffix; /* normalized suffix */
+
struct berval mt_binddn;
struct berval mt_bindpw;
#define META_RETRY_DEFAULT (3)
struct ldaprwmap mt_rwmap;
+
+ unsigned mt_flags;
+ int mt_version;
} metatarget_t;
typedef struct metadncache_t {
#define META_DEFAULT_TARGET_NONE (-1)
int mi_nretries;
- metatarget_t **mi_targets;
+ metatarget_t *mi_targets;
SlapReply *mi_candidates;
metadncache_t mi_cache;
#define LDAP_BACK_F_NONE 0x00U
#define LDAP_BACK_F_SAVECRED 0x01U
#define LDAP_BACK_F_USE_TLS 0x02U
-#define LDAP_BACK_F_TLS_CRITICAL ( 0x04U | LDAP_BACK_F_USE_TLS )
-#define LDAP_BACK_F_CHASE_REFERRALS 0x8U
+#define LDAP_BACK_F_PROPAGATE_TLS 0x04U
+#define LDAP_BACK_F_TLS_CRITICAL 0x08U
+#define LDAP_BACK_F_TLS_MASK (LDAP_BACK_F_USE_TLS|LDAP_BACK_F_PROPAGATE_TLS|LDAP_BACK_F_TLS_CRITICAL)
+#define LDAP_BACK_F_CHASE_REFERRALS 0x10U
#endif
+
+ int mi_version;
} metainfo_t;
typedef enum meta_op_type {
0, 0, 0 );
}
- if ( isroot && !BER_BVISNULL( &mi->mi_targets[ i ]->mt_pseudorootdn ) )
+ if ( isroot && !BER_BVISNULL( &mi->mi_targets[ i ].mt_pseudorootdn ) )
{
- op2.o_req_dn = mi->mi_targets[ i ]->mt_pseudorootdn;
- op2.o_req_ndn = mi->mi_targets[ i ]->mt_pseudorootdn;
- op2.orb_cred = mi->mi_targets[ i ]->mt_pseudorootpw;
+ op2.o_req_dn = mi->mi_targets[ i ].mt_pseudorootdn;
+ op2.o_req_ndn = mi->mi_targets[ i ].mt_pseudorootdn;
+ op2.orb_cred = mi->mi_targets[ i ].mt_pseudorootpw;
op2.orb_method = LDAP_AUTH_SIMPLE;
}
int candidate )
{
metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
- metatarget_t *mt = mi->mi_targets[ candidate ];
+ metatarget_t *mt = &mi->mi_targets[ candidate ];
struct berval mdn = BER_BVNULL;
dncookie dc;
metasingleconn_t *msc = &mc->mc_conns[ candidate ];
/*
* Rewrite the bind dn if needed
*/
- dc.rwmap = &mi->mi_targets[ candidate ]->mt_rwmap;
+ dc.target = &mi->mi_targets[ candidate ];
dc.conn = op->o_conn;
dc.rs = rs;
dc.ctx = "bindDN";
int nretries )
{
metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
- metatarget_t *mt = mi->mi_targets[ candidate ];
+ metatarget_t *mt = &mi->mi_targets[ candidate ];
metasingleconn_t *msc = &mc->mc_conns[ candidate ];
int rc;
struct berval cred = BER_BVC( "" );
}
for ( i = 0, msc = &mc->mc_conns[ 0 ]; !META_LAST( msc ); ++i, ++msc ) {
- metatarget_t *mt = mi->mi_targets[ i ];
+ metatarget_t *mt = &mi->mi_targets[ i ];
int rc;
/*
int i, candidate = META_TARGET_NONE;
for ( i = 0; i < mi->mi_ntargets; ++i ) {
- if ( meta_back_is_candidate( &mi->mi_targets[ i ]->mt_nsuffix, ndn, LDAP_SCOPE_BASE ) )
+ if ( meta_back_is_candidate( &mi->mi_targets[ i ].mt_nsuffix, ndn, LDAP_SCOPE_BASE ) )
{
if ( candidate == META_TARGET_NONE ) {
candidate = i;
/*
* Rewrite the compare dn, if needed
*/
- dc.rwmap = &mi->mi_targets[ i ]->mt_rwmap;
+ dc.target = &mi->mi_targets[ i ];
switch ( ldap_back_dn_massage( &dc, &op->o_req_dn, &mdn ) ) {
case LDAP_UNWILLING_TO_PERFORM:
* if attr is objectClass, try to remap the value
*/
if ( op->orc_ava->aa_desc == slap_schema.si_ad_objectClass ) {
- ldap_back_map( &mi->mi_targets[ i ]->mt_rwmap.rwm_oc,
+ ldap_back_map( &mi->mi_targets[ i ].mt_rwmap.rwm_oc,
&op->orc_ava->aa_value,
&mapped_value, BACKLDAP_MAP );
* else try to remap the attribute
*/
} else {
- ldap_back_map( &mi->mi_targets[ i ]->mt_rwmap.rwm_at,
+ ldap_back_map( &mi->mi_targets[ i ].mt_rwmap.rwm_at,
&op->orc_ava->aa_desc->ad_cname,
&mapped_attr, BACKLDAP_MAP );
if ( BER_BVISNULL( &mapped_attr ) || mapped_attr.bv_val[0] == '\0' ) {
#include "../../../libraries/libldap/ldap-int.h"
#include "back-meta.h"
-static metatarget_t *
-new_target( void )
+static int
+new_target(
+ metatarget_t *mt )
{
- metatarget_t *mt;
- struct ldapmapping *mapping;
+ struct ldapmapping *mapping;
+ char *rargv[ 3 ];
- mt = ch_malloc( sizeof( metatarget_t ) );
- if ( mt == NULL ) {
- return NULL;
- }
memset( mt, 0, sizeof( metatarget_t ) );
mt->mt_rwmap.rwm_rw = rewrite_info_init( REWRITE_MODE_USE_DEFAULT );
if ( mt->mt_rwmap.rwm_rw == NULL ) {
- free( mt );
- return NULL;
+ return -1;
}
- {
- char *rargv[3];
- /*
- * the filter rewrite as a string must be disabled
- * by default; it can be re-enabled by adding rules;
- * this creates an empty rewriteContext
- */
- rargv[ 0 ] = "rewriteContext";
- rargv[ 1 ] = "searchFilter";
- rargv[ 2 ] = NULL;
- rewrite_parse( mt->mt_rwmap.rwm_rw, "<suffix massage>",
- 1, 2, rargv );
-
- rargv[ 0 ] = "rewriteContext";
- rargv[ 1 ] = "default";
- rargv[ 2 ] = NULL;
- rewrite_parse( mt->mt_rwmap.rwm_rw, "<suffix massage>",
- 1, 2, rargv );
- }
+ /*
+ * the filter rewrite as a string must be disabled
+ * by default; it can be re-enabled by adding rules;
+ * this creates an empty rewriteContext
+ */
+ rargv[ 0 ] = "rewriteContext";
+ rargv[ 1 ] = "searchFilter";
+ rargv[ 2 ] = NULL;
+ rewrite_parse( mt->mt_rwmap.rwm_rw, "<suffix massage>", 1, 2, rargv );
+
+ rargv[ 0 ] = "rewriteContext";
+ rargv[ 1 ] = "default";
+ rargv[ 2 ] = NULL;
+ rewrite_parse( mt->mt_rwmap.rwm_rw, "<suffix massage>", 1, 2, rargv );
ldap_back_map_init( &mt->mt_rwmap.rwm_at, &mapping );
- return mt;
+ return 0;
}
int
++mi->mi_ntargets;
- mi->mi_targets = ( metatarget_t ** )ch_realloc( mi->mi_targets,
- sizeof( metatarget_t * ) * mi->mi_ntargets );
+ mi->mi_targets = ( metatarget_t * )ch_realloc( mi->mi_targets,
+ sizeof( metatarget_t ) * mi->mi_ntargets );
if ( mi->mi_targets == NULL ) {
fprintf( stderr,
"%s: line %d: out of memory while storing server name"
return 1;
}
- if ( ( mi->mi_targets[ i ] = new_target() ) == NULL ) {
+ if ( new_target( &mi->mi_targets[ i ] ) != 0 ) {
fprintf( stderr,
"%s: line %d: unable to init server"
" in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
return 1;
}
- mi->mi_targets[ i ]->mt_nretries = mi->mi_nretries;
+ mi->mi_targets[ i ].mt_nretries = mi->mi_nretries;
+ mi->mi_targets[ i ].mt_flags = mi->flags;
+ mi->mi_targets[ i ].mt_version = mi->mi_version;
/*
* uri MUST be legal!
dn.bv_val = ludp->lud_dn;
dn.bv_len = strlen( ludp->lud_dn );
- rc = dnPrettyNormal( NULL, &dn, &mi->mi_targets[ i ]->mt_psuffix,
- &mi->mi_targets[ i ]->mt_nsuffix, NULL );
+ rc = dnPrettyNormal( NULL, &dn, &mi->mi_targets[ i ].mt_psuffix,
+ &mi->mi_targets[ i ].mt_nsuffix, NULL );
if( rc != LDAP_SUCCESS ) {
fprintf( stderr, "%s: line %d: "
"target '%s' DN is invalid\n",
}
}
- mi->mi_targets[ i ]->mt_uri = ldap_url_list2urls( ludp );
+ mi->mi_targets[ i ].mt_uri = ldap_url_list2urls( ludp );
ldap_free_urllist( ludp );
- if ( mi->mi_targets[ i ]->mt_uri == NULL) {
+ if ( mi->mi_targets[ i ].mt_uri == NULL) {
fprintf( stderr, "%s: line %d: no memory?\n",
fname, lineno );
return( 1 );
* uri MUST be a branch of suffix!
*/
#if 0 /* too strict a constraint */
- if ( select_backend( &mi->mi_targets[ i ]->suffix, 0, 0 ) != be ) {
+ if ( select_backend( &mi->mi_targets[ i ].suffix, 0, 0 ) != be ) {
fprintf( stderr,
"%s: line %d: <naming context> of URI does not refer to current backend"
" in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
/*
* uri MUST be a branch of a suffix!
*/
- if ( select_backend( &mi->mi_targets[ i ]->mt_nsuffix, 0, 0 ) == NULL ) {
+ if ( select_backend( &mi->mi_targets[ i ].mt_nsuffix, 0, 0 ) == NULL ) {
fprintf( stderr,
"%s: line %d: <naming context> of URI does not resolve to a backend"
" in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
}
#endif
-#if 0
- /*
- * uri MUST not be used by other URIs!
- *
- * FIXME: this limitation may be removed,
- * or worked out, at least, in some manner
- */
- for ( j = 0; j < i-1; j++ ) {
- if ( dn_match( &mi->mi_targets[ i ]->suffix,
- &mi->mi_targets[ j ]->suffix ) ) {
- fprintf( stderr,
- "%s: line %d: naming context \"%s\" already used"
- " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
- fname, lineno, last+1 );
- return 1;
- }
- }
-#endif
-
-#if 0
- fprintf(stderr, "%s: line %d: URI \"%s\", suffix \"%s\"\n",
- fname, lineno, mi->mi_targets[ i ]->uri,
- mi->mi_targets[ i ]->psuffix.bv_val );
-#endif
-
/* default target directive */
} else if ( strcasecmp( argv[ 0 ], "default-target" ) == 0 ) {
int i = mi->mi_ntargets - 1;
dn.bv_val = argv[ 1 ];
dn.bv_len = strlen( argv[ 1 ] );
- if ( dnNormalize( 0, NULL, NULL, &dn, &mi->mi_targets[ i ]->mt_binddn,
+ if ( dnNormalize( 0, NULL, NULL, &dn, &mi->mi_targets[ i ].mt_binddn,
NULL ) != LDAP_SUCCESS )
{
fprintf( stderr, "%s: line %d: "
/* FIXME: some day we'll need to throw an error */
}
- ber_str2bv( argv[ 1 ], 0L, 1, &mi->mi_targets[ i ]->mt_bindpw );
+ ber_str2bv( argv[ 1 ], 0L, 1, &mi->mi_targets[ i ].mt_bindpw );
/* save bind creds for referral rebinds? */
- } else if ( strcasecmp( argv[0], "rebind-as-user" ) == 0 ) {
+ } else if ( strcasecmp( argv[ 0 ], "rebind-as-user" ) == 0 ) {
if (argc != 1) {
fprintf( stderr,
"%s: line %d: rebind-as-user takes no arguments\n",
mi->flags |= LDAP_BACK_F_SAVECRED;
- } else if ( strcasecmp( argv[0], "chase-referrals" ) == 0 ) {
- if ( argc != 1 ) {
+ } else if ( strcasecmp( argv[ 0 ], "chase-referrals" ) == 0 ) {
+ unsigned *flagsp = mi->mi_ntargets ?
+ &mi->mi_targets[ mi->mi_ntargets - 1 ].mt_flags
+ : &mi->flags;
+
+ if ( argc != 2 ) {
fprintf( stderr,
- "%s: line %d: \"chase-referrals\" takes no arguments\n",
+ "%s: line %d: \"chase-referrals\" needs 1 argument.\n",
fname, lineno );
return( 1 );
}
- mi->flags |= LDAP_BACK_F_CHASE_REFERRALS;
+ /* this is the default; we add it because the default might change... */
+ if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
+ *flagsp |= LDAP_BACK_F_CHASE_REFERRALS;
+
+ } else if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
+ *flagsp &= ~LDAP_BACK_F_CHASE_REFERRALS;
- } else if ( strcasecmp( argv[0], "dont-chase-referrals" ) == 0 ) {
- if ( argc != 1 ) {
+ } else {
fprintf( stderr,
- "%s: line %d: \"dont-chase-referrals\" takes no arguments\n",
- fname, lineno );
+ "%s: line %d: \"chase-referrals {yes|no}\": unknown argument \"%s\".\n",
+ fname, lineno, argv[ 1 ] );
return( 1 );
}
+
+ } else if ( strcasecmp( argv[ 0 ], "tls" ) == 0 ) {
+ unsigned *flagsp = mi->mi_ntargets ?
+ &mi->mi_targets[ mi->mi_ntargets - 1 ].mt_flags
+ : &mi->flags;
- mi->flags &= ~LDAP_BACK_F_CHASE_REFERRALS;
-
- } else if ( strncasecmp( argv[0], "tls-", STRLENOF( "tls-" ) ) == 0 ) {
+ if ( argc != 2 ) {
+ fprintf( stderr,
+ "%s: line %d: \"tls <what>\" needs 1 argument.\n",
+ fname, lineno );
+ return( 1 );
+ }
- /* start tls */
- if ( strcasecmp( argv[0], "tls-start" ) == 0 ) {
- if ( argc != 1 ) {
- fprintf( stderr,
- "%s: line %d: tls-start takes no arguments\n",
- fname, lineno );
- return( 1 );
- }
- mi->flags |= ( LDAP_BACK_F_USE_TLS | LDAP_BACK_F_TLS_CRITICAL );
+ /* start */
+ if ( strcasecmp( argv[ 1 ], "start" ) == 0 ) {
+ *flagsp |= ( LDAP_BACK_F_USE_TLS | LDAP_BACK_F_TLS_CRITICAL );
/* try start tls */
- } else if ( strcasecmp( argv[0], "tls-try-start" ) == 0 ) {
- if ( argc != 1 ) {
- fprintf( stderr,
- "%s: line %d: tls-try-start takes no arguments\n",
- fname, lineno );
- return( 1 );
- }
- mi->flags &= ~LDAP_BACK_F_TLS_CRITICAL;
- mi->flags |= LDAP_BACK_F_USE_TLS;
+ } else if ( strcasecmp( argv[ 1 ], "try-start" ) == 0 ) {
+ *flagsp &= ~LDAP_BACK_F_TLS_CRITICAL;
+ *flagsp |= LDAP_BACK_F_USE_TLS;
/* propagate start tls */
- } else if ( strcasecmp( argv[0], "tls-propagate" ) == 0 ) {
- if ( argc != 1 ) {
- fprintf( stderr,
- "%s: line %d: tls-propagate takes no arguments\n",
- fname, lineno );
- return( 1 );
- }
- mi->flags |= ( LDAP_BACK_F_PROPAGATE_TLS | LDAP_BACK_F_TLS_CRITICAL );
+ } else if ( strcasecmp( argv[ 1 ], "propagate" ) == 0 ) {
+ *flagsp |= ( LDAP_BACK_F_PROPAGATE_TLS | LDAP_BACK_F_TLS_CRITICAL );
/* try start tls */
- } else if ( strcasecmp( argv[0], "tls-try-propagate" ) == 0 ) {
- if ( argc != 1 ) {
- fprintf( stderr,
- "%s: line %d: tls-try-propagate takes no arguments\n",
- fname, lineno );
- return( 1 );
- }
- mi->flags &= ~LDAP_BACK_F_TLS_CRITICAL;
- mi->flags |= LDAP_BACK_F_PROPAGATE_TLS;
+ } else if ( strcasecmp( argv[ 1 ], "try-propagate" ) == 0 ) {
+ *flagsp &= ~LDAP_BACK_F_TLS_CRITICAL;
+ *flagsp |= LDAP_BACK_F_PROPAGATE_TLS;
+
+ } else {
+ fprintf( stderr,
+ "%s: line %d: \"tls <what>\": unknown argument \"%s\".\n",
+ fname, lineno, argv[ 1 ] );
+ return( 1 );
}
-
+
+ } else if ( strcasecmp( argv[ 0 ], "t-f-support" ) == 0 ) {
+ unsigned *flagsp = mi->mi_ntargets ?
+ &mi->mi_targets[ mi->mi_ntargets - 1 ].mt_flags
+ : &mi->flags;
+
+ if ( argc != 2 ) {
+ fprintf( stderr,
+ "%s: line %d: \"t-f-support {no|yes|discover}\" needs 1 argument.\n",
+ fname, lineno );
+ return( 1 );
+ }
+
+ if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
+ *flagsp &= ~(LDAP_BACK_F_SUPPORT_T_F|LDAP_BACK_F_SUPPORT_T_F_DISCOVER);
+
+ } else if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
+ *flagsp |= LDAP_BACK_F_SUPPORT_T_F;
+
+ } else if ( strcasecmp( argv[ 1 ], "discover" ) == 0 ) {
+ *flagsp |= LDAP_BACK_F_SUPPORT_T_F_DISCOVER;
+
+ } else {
+ fprintf( stderr,
+ "%s: line %d: unknown value \"%s\" for \"t-f-support {no|yes|discover}\".\n",
+ fname, lineno, argv[ 1 ] );
+ return 1;
+ }
+
/* name to use as pseudo-root dn */
} else if ( strcasecmp( argv[ 0 ], "pseudorootdn" ) == 0 ) {
int i = mi->mi_ntargets - 1;
dn.bv_val = argv[ 1 ];
dn.bv_len = strlen( argv[ 1 ] );
if ( dnNormalize( 0, NULL, NULL, &dn,
- &mi->mi_targets[ i ]->mt_pseudorootdn, NULL ) != LDAP_SUCCESS )
+ &mi->mi_targets[ i ].mt_pseudorootdn, NULL ) != LDAP_SUCCESS )
{
fprintf( stderr, "%s: line %d: "
"pseudoroot DN '%s' is invalid\n",
fname, lineno );
return 1;
}
- ber_str2bv( argv[ 1 ], 0L, 1, &mi->mi_targets[ i ]->mt_pseudorootpw );
+ ber_str2bv( argv[ 1 ], 0L, 1, &mi->mi_targets[ i ].mt_pseudorootpw );
/* dn massaging */
} else if ( strcasecmp( argv[ 0 ], "suffixmassage" ) == 0 ) {
* FIXME: no extra rewrite capabilities should be added
* to the database
*/
- return suffix_massage_config( mi->mi_targets[ i ]->mt_rwmap.rwm_rw,
+ return suffix_massage_config( mi->mi_targets[ i ].mt_rwmap.rwm_rw,
&pvnc, &nvnc, &prnc, &nrnc );
/* rewrite stuff ... */
return 1;
}
- return rewrite_parse( mi->mi_targets[ i ]->mt_rwmap.rwm_rw,
+ return rewrite_parse( mi->mi_targets[ i ].mt_rwmap.rwm_rw,
fname, lineno, argc, argv );
/* objectclass/attribute mapping */
return 1;
}
- return ldap_back_map_config( &mi->mi_targets[ i ]->mt_rwmap.rwm_oc,
- &mi->mi_targets[ i ]->mt_rwmap.rwm_at,
+ return ldap_back_map_config( &mi->mi_targets[ i ].mt_rwmap.rwm_oc,
+ &mi->mi_targets[ i ].mt_rwmap.rwm_at,
fname, lineno, argc, argv );
} else if ( strcasecmp( argv[ 0 ], "nretries" ) == 0 ) {
mi->mi_nretries = nretries;
} else {
- mi->mi_targets[ i ]->mt_nretries = nretries;
+ mi->mi_targets[ i ].mt_nretries = nretries;
}
/* anything else */
return 1;
}
- if ( strcasecmp( argv[1], "objectclass" ) == 0 ) {
+ if ( strcasecmp( argv[ 1 ], "objectclass" ) == 0 ) {
map = oc_map;
is_oc = 1;
- } else if ( strcasecmp( argv[1], "attribute" ) == 0 ) {
+ } else if ( strcasecmp( argv[ 1 ], "attribute" ) == 0 ) {
map = at_map;
} else {
return 1;
}
- if ( strcmp( argv[2], "*" ) == 0 ) {
- if ( argc < 4 || strcmp( argv[3], "*" ) == 0 ) {
+ if ( strcmp( argv[ 2 ], "*" ) == 0 ) {
+ if ( argc < 4 || strcmp( argv[ 3 ], "*" ) == 0 ) {
map->drop_missing = ( argc < 4 );
return 0;
}
- src = dst = argv[3];
+ src = dst = argv[ 3 ];
} else if ( argc < 4 ) {
src = "";
- dst = argv[2];
+ dst = argv[ 2 ];
} else {
- src = argv[2];
- dst = ( strcmp( argv[3], "*" ) == 0 ? src : argv[3] );
+ src = argv[ 2 ];
+ dst = ( strcmp( argv[ 3 ], "*" ) == 0 ? src : argv[ 3 ] );
}
if ( ( map == at_map )
}
ber_str2bv( src, 0, 1, &mapping->src );
ber_str2bv( dst, 0, 1, &mapping->dst );
- mapping[1].src = mapping->dst;
- mapping[1].dst = mapping->src;
+ mapping[ 1 ].src = mapping->dst;
+ mapping[ 1 ].dst = mapping->src;
/*
* schema check
*/
if ( is_oc ) {
- if ( src[0] != '\0' ) {
+ if ( src[ 0 ] != '\0' ) {
if ( oc_bvfind( &mapping->src ) == NULL ) {
fprintf( stderr,
"%s: line %d: warning, source objectClass '%s' "
const char *text = NULL;
AttributeDescription *ad = NULL;
- if ( src[0] != '\0' ) {
+ if ( src[ 0 ] != '\0' ) {
rc = slap_bv2ad( &mapping->src, &ad, &text );
if ( rc != LDAP_SUCCESS ) {
fprintf( stderr,
}
}
- if ( (src[0] != '\0' && avl_find( map->map, (caddr_t)mapping, mapping_cmp ) != NULL)
- || avl_find( map->remap, (caddr_t)&mapping[1], mapping_cmp ) != NULL)
+ if ( (src[ 0 ] != '\0' && avl_find( map->map, (caddr_t)mapping, mapping_cmp ) != NULL)
+ || avl_find( map->remap, (caddr_t)&mapping[ 1 ], mapping_cmp ) != NULL)
{
fprintf( stderr,
"%s: line %d: duplicate mapping found (ignored)\n",
goto error_return;
}
- if ( src[0] != '\0' ) {
+ if ( src[ 0 ] != '\0' ) {
avl_insert( &map->map, (caddr_t)mapping,
mapping_cmp, mapping_dup );
}
- avl_insert( &map->remap, (caddr_t)&mapping[1],
+ avl_insert( &map->remap, (caddr_t)&mapping[ 1 ],
mapping_cmp, mapping_dup );
return 0;
*/
static metaconn_t *
metaconn_alloc(
- int ntargets )
+ Operation *op )
{
+ metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
metaconn_t *mc;
+ int ntargets = mi->mi_ntargets;
assert( ntargets > 0 );
BER_BVZERO( &mc->mc_conns[ ntargets ].msc_bound_ndn );
BER_BVZERO( &mc->mc_conns[ ntargets ].msc_cred );
mc->mc_conns[ ntargets ].msc_bound = META_UNBOUND;
+ mc->mc_conns[ ntargets ].msc_info = mi;
}
mc->mc_auth_target = META_BOUND_NONE;
* If the connection DN is not null, an attempt to rewrite it is made
*/
if ( !BER_BVISEMPTY( &op->o_conn->c_dn ) ) {
- dc.rwmap = &mt->mt_rwmap;
+ dc.target = mt;
dc.conn = op->o_conn;
dc.rs = rs;
dc.ctx = "bindDN";
ldap_back_send_t sendok )
{
metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
- metatarget_t *mt = mi->mi_targets[ candidate ];
+ metatarget_t *mt = &mi->mi_targets[ candidate ];
int rc;
metasingleconn_t *msc = &mc->mc_conns[ candidate ];
* and a default target is defined, and it is
* a candidate, try using it (FIXME: YMMV) */
if ( mi->mi_defaulttarget != META_DEFAULT_TARGET_NONE
- && meta_back_is_candidate( &mi->mi_targets[ mi->mi_defaulttarget ]->mt_nsuffix,
+ && meta_back_is_candidate( &mi->mi_targets[ mi->mi_defaulttarget ].mt_nsuffix,
ndn, op->o_tag == LDAP_REQ_SEARCH ? op->ors_scope : LDAP_SCOPE_BASE ) )
{
candidate = mi->mi_defaulttarget;
/* Looks like we didn't get a bind. Open a new session... */
if ( !mc ) {
- mc = metaconn_alloc( mi->mi_ntargets );
+ mc = metaconn_alloc( op );
mc->mc_conn = op->o_conn;
new_conn = 1;
}
* The target is activated; if needed, it is
* also init'd
*/
- int lerr = meta_back_init_one_conn( op, rs, mi->mi_targets[ i ],
+ int lerr = meta_back_init_one_conn( op, rs, &mi->mi_targets[ i ],
&mc->mc_conns[ i ], sendok );
if ( lerr == LDAP_SUCCESS ) {
candidates[ i ].sr_tag = META_CANDIDATE;
/* Looks like we didn't get a bind. Open a new session... */
if ( !mc ) {
- mc = metaconn_alloc( mi->mi_ntargets );
+ mc = metaconn_alloc( op );
mc->mc_conn = op->o_conn;
new_conn = 1;
}
* also init'd. In case of error, meta_back_init_one_conn
* sends the appropriate result.
*/
- err = meta_back_init_one_conn( op, rs, mi->mi_targets[ i ],
+ err = meta_back_init_one_conn( op, rs, &mi->mi_targets[ i ],
&mc->mc_conns[ i ], sendok );
if ( err == LDAP_SUCCESS ) {
candidates[ i ].sr_tag = META_CANDIDATE;
/* Looks like we didn't get a bind. Open a new session... */
if ( !mc ) {
- mc = metaconn_alloc( mi->mi_ntargets );
+ mc = metaconn_alloc( op );
mc->mc_conn = op->o_conn;
new_conn = 1;
}
for ( i = 0; i < mi->mi_ntargets; i++ ) {
if ( i == cached
- || meta_back_is_candidate( &mi->mi_targets[ i ]->mt_nsuffix,
+ || meta_back_is_candidate( &mi->mi_targets[ i ].mt_nsuffix,
&op->o_req_ndn, LDAP_SCOPE_SUBTREE ) )
{
* also init'd
*/
int lerr = meta_back_init_one_conn( op, rs,
- mi->mi_targets[ i ],
+ &mi->mi_targets[ i ],
&mc->mc_conns[ i ], sendok );
if ( lerr == LDAP_SUCCESS ) {
candidates[ i ].sr_tag = META_CANDIDATE;
int candidate = -1;
struct berval mdn = BER_BVNULL;
dncookie dc;
- int msgid, do_retry = 1;
+ int do_retry = 1;
mc = meta_back_getconn( op, rs, &candidate, LDAP_BACK_SENDERR );
if ( !mc || !meta_back_dobind( op, rs, mc, LDAP_BACK_SENDERR ) ) {
/*
* Rewrite the compare dn, if needed
*/
- dc.rwmap = &mi->mi_targets[ candidate ]->mt_rwmap;
+ dc.target = &mi->mi_targets[ candidate ];
dc.conn = op->o_conn;
dc.rs = rs;
dc.ctx = "deleteDN";
bi->bi_db_init = meta_back_db_init;
bi->bi_db_config = meta_back_db_config;
- bi->bi_db_open = 0;
+ bi->bi_db_open = meta_back_db_open;
bi->bi_db_close = 0;
bi->bi_db_destroy = meta_back_db_destroy;
/* safe default */
mi->mi_nretries = META_RETRY_DEFAULT;
+ mi->mi_version = LDAP_VERSION3;
be->be_private = mi;
return 0;
}
+int
+meta_back_db_open(
+ Backend *be )
+{
+ metainfo_t *mi = (metainfo_t *)be->be_private;
+
+ int i, rc;
+
+ for ( i = 0; i < mi->mi_ntargets; i++ ) {
+ if ( mi->mi_targets[ i ].mt_flags & LDAP_BACK_F_SUPPORT_T_F_DISCOVER ) {
+ mi->mi_targets[ i ].mt_flags &= ~LDAP_BACK_F_SUPPORT_T_F_DISCOVER;
+ rc = ldap_back_discover_t_f_support( mi->mi_targets[ i ].mt_uri,
+ mi->mi_targets[ i ].mt_version );
+ if ( rc == LDAP_COMPARE_TRUE ) {
+ mi->mi_targets[ i ].mt_flags |= LDAP_BACK_F_SUPPORT_T_F;
+ }
+ }
+ }
+
+ return 0;
+}
+
static void
conn_free(
void *v_mc )
* least one ...)
*/
for ( i = 0; i < mi->mi_ntargets; i++ ) {
- target_free( mi->mi_targets[ i ] );
- free( mi->mi_targets[ i ] );
+ target_free( &mi->mi_targets[ i ] );
}
free( mi->mi_targets );
struct berval vtmp;
int freeval = 0;
- ldap_back_map( &dc->rwmap->rwm_at, &ad->ad_cname, mapped_attr, remap );
+ ldap_back_map( &dc->target->mt_rwmap.rwm_at, &ad->ad_cname, mapped_attr, remap );
if ( BER_BVISNULL( mapped_attr ) || BER_BVISEMPTY( mapped_attr ) ) {
/*
* FIXME: are we sure we need to search oc_map if at_map fails?
*/
- ldap_back_map( &dc->rwmap->rwm_oc, &ad->ad_cname, mapped_attr, remap );
+ ldap_back_map( &dc->target->mt_rwmap.rwm_oc, &ad->ad_cname, mapped_attr, remap );
if ( BER_BVISNULL( mapped_attr ) || BER_BVISEMPTY( mapped_attr ) ) {
*mapped_attr = ad->ad_cname;
}
}
} else if ( ad == slap_schema.si_ad_objectClass || ad == slap_schema.si_ad_structuralObjectClass ) {
- ldap_back_map( &dc->rwmap->rwm_oc, value, &vtmp, remap );
+ ldap_back_map( &dc->target->mt_rwmap.rwm_oc, value, &vtmp, remap );
if ( BER_BVISNULL( &vtmp ) || BER_BVISEMPTY( &vtmp ) ) {
vtmp = *value;
}
ber_len_t len;
if ( f == NULL ) {
- ber_str2bv( "No filter!", sizeof("No filter!")-1, 1, fstr );
+ ber_str2bv( "No filter!", STRLENOF( "No filter!" ), 1, fstr );
return -1;
}
break;
- case LDAP_FILTER_EXT: {
+ case LDAP_FILTER_EXT:
if ( f->f_mr_desc ) {
if ( map_attr_value( dc, f->f_mr_desc, &atmp,
&f->f_mr_value, &vtmp, remap ) )
!BER_BVISEMPTY( &f->f_mr_rule_text ) ? f->f_mr_rule_text.bv_val : "",
vtmp.bv_val );
ber_memfree( vtmp.bv_val );
- } break;
+ break;
case SLAPD_FILTER_COMPUTED:
switch ( f->f_result ) {
case LDAP_COMPARE_FALSE:
- ber_str2bv( "(?=false)", STRLENOF( "(?=false)" ), 1, fstr );
+ if ( dc->target->mt_flags & LDAP_BACK_F_SUPPORT_T_F ) {
+ ber_str2bv( "(|)", STRLENOF( "(|)" ), 1, fstr );
+
+ } else {
+#if 0
+ ber_str2bv( "(?=false)", STRLENOF( "(?=false)" ), 1, fstr );
+#endif
+ /* better than nothing... */
+ ber_str2bv( "(!(objectClass=*))", STRLENOF( "(!(objectClass=*))" ), 1, fstr );
+ }
break;
+
case LDAP_COMPARE_TRUE:
- ber_str2bv( "(?=true)", STRLENOF( "(?=true)" ), 1, fstr );
+ if ( dc->target->mt_flags & LDAP_BACK_F_SUPPORT_T_F ) {
+ ber_str2bv( "(&)", STRLENOF( "(&)" ), 1, fstr );
+
+ } else {
+#if 0
+ ber_str2bv( "(?=true)", STRLENOF( "(?=true)" ), 1, fstr );
+#endif
+ /* better than nothing... */
+ ber_str2bv( "(objectClass=*)", STRLENOF( "(objectClass=*)" ), 1, fstr );
+ }
break;
+
case SLAPD_COMPARE_UNDEFINED:
ber_str2bv( "(?=undefined)", STRLENOF( "(?=undefined)" ), 1, fstr );
break;
+
default:
ber_str2bv( "(?=error)", STRLENOF( "(?=error)" ), 1, fstr );
break;
fdc.ctx = "searchFilter";
- switch ( rewrite_session( fdc.rwmap->rwm_rw, fdc.ctx,
+ switch ( rewrite_session( fdc.target->mt_rwmap.rwm_rw, fdc.ctx,
( !BER_BVISEMPTY( &ftmp ) ? ftmp.bv_val : "" ),
fdc.conn, &fstr->bv_val ) )
{
/*
* Rewrite the modify dn, if needed
*/
- dc.rwmap = &mi->mi_targets[ candidate ]->mt_rwmap;
+ dc.target = &mi->mi_targets[ candidate ];
dc.conn = op->o_conn;
dc.rs = rs;
dc.ctx = "modifyDN";
mapped = ml->sml_desc->ad_cname;
} else {
- ldap_back_map( &mi->mi_targets[ candidate ]->mt_rwmap.rwm_at,
+ ldap_back_map( &mi->mi_targets[ candidate ].mt_rwmap.rwm_at,
&ml->sml_desc->ad_cname, &mapped,
BACKLDAP_MAP );
if ( BER_BVISNULL( &mapped ) || BER_BVISEMPTY( &mapped ) ) {
for ( j = 0; !BER_BVISNULL( &ml->sml_values[ j ] ); ) {
struct ldapmapping *mapping;
- ldap_back_mapping( &mi->mi_targets[ candidate ]->mt_rwmap.rwm_oc,
+ ldap_back_mapping( &mi->mi_targets[ candidate ].mt_rwmap.rwm_oc,
&ml->sml_values[ j ], &mapping, BACKLDAP_MAP );
if ( mapping == NULL ) {
- if ( mi->mi_targets[ candidate ]->mt_rwmap.rwm_oc.drop_missing ) {
+ if ( mi->mi_targets[ candidate ].mt_rwmap.rwm_oc.drop_missing ) {
continue;
}
mods[ i ].mod_bvalues[ j ] = &ml->sml_values[ j ];
struct berval mdn = BER_BVNULL,
mnewSuperior = BER_BVNULL;
dncookie dc;
- int msgid, do_retry = 1;
+ int do_retry = 1;
mc = meta_back_getconn( op, rs, &candidate, LDAP_BACK_SENDERR );
if ( !mc || !meta_back_dobind( op, rs, mc, LDAP_BACK_SENDERR ) ) {
}
assert( mc->mc_conns[ candidate ].msc_ld != NULL );
-
+
dc.conn = op->o_conn;
dc.rs = rs;
/*
* Rewrite the new superior, if defined and required
*/
- dc.rwmap = &mi->mi_targets[ candidate ]->mt_rwmap;
+ dc.target = &mi->mi_targets[ candidate ];
dc.ctx = "newSuperiorDN";
if ( ldap_back_dn_massage( &dc, op->orr_newSup, &mnewSuperior ) ) {
rs->sr_err = LDAP_OTHER;
/*
* Rewrite the modrdn dn, if required
*/
- dc.rwmap = &mi->mi_targets[ candidate ]->mt_rwmap;
+ dc.target = &mi->mi_targets[ candidate ];
dc.ctx = "modrDN";
if ( ldap_back_dn_massage( &dc, &op->o_req_dn, &mdn ) ) {
rs->sr_err = LDAP_OTHER;
extern BI_destroy meta_back_destroy;
extern BI_db_init meta_back_db_init;
+extern BI_db_open meta_back_db_open;
extern BI_db_destroy meta_back_db_destroy;
extern BI_db_config meta_back_db_config;
( void * )&op->ors_slimit);
}
- dc->rwmap = &mi->mi_targets[ candidate ]->mt_rwmap;
+ dc->target = &mi->mi_targets[ candidate ];
/*
* modifies the base according to the scope, if required
*/
- suffixlen = mi->mi_targets[ candidate ]->mt_nsuffix.bv_len;
+ suffixlen = mi->mi_targets[ candidate ].mt_nsuffix.bv_len;
if ( suffixlen > op->o_req_ndn.bv_len ) {
switch ( op->ors_scope ) {
case LDAP_SCOPE_SUBTREE:
* the requested searchBase already passed
* thru the candidate analyzer...
*/
- if ( dnIsSuffix( &mi->mi_targets[ candidate ]->mt_nsuffix,
+ if ( dnIsSuffix( &mi->mi_targets[ candidate ].mt_nsuffix,
&op->o_req_ndn ) )
{
- realbase = mi->mi_targets[ candidate ]->mt_nsuffix;
+ realbase = mi->mi_targets[ candidate ].mt_nsuffix;
} else {
/*
case LDAP_SCOPE_ONELEVEL:
{
- struct berval rdn = mi->mi_targets[ candidate ]->mt_nsuffix;
+ struct berval rdn = mi->mi_targets[ candidate ].mt_nsuffix;
rdn.bv_len -= op->o_req_ndn.bv_len + STRLENOF( "," );
if ( dnIsOneLevelRDN( &rdn )
- && dnIsSuffix( &mi->mi_targets[ candidate ]->mt_nsuffix, &op->o_req_ndn ) )
+ && dnIsSuffix( &mi->mi_targets[ candidate ].mt_nsuffix, &op->o_req_ndn ) )
{
/*
* if there is exactly one level,
* make the target suffix the new
* base, and make scope "base"
*/
- realbase = mi->mi_targets[ candidate ]->mt_nsuffix;
+ realbase = mi->mi_targets[ candidate ].mt_nsuffix;
realscope = LDAP_SCOPE_BASE;
break;
} /* else continue with the next case */
/*
* Maps required attributes
*/
- rc = ldap_back_map_attrs( &mi->mi_targets[ candidate ]->mt_rwmap.rwm_at,
+ rc = ldap_back_map_attrs( &mi->mi_targets[ candidate ].mt_rwmap.rwm_at,
op->ors_attrs, BACKLDAP_MAP, &mapped_attrs );
if ( rc != LDAP_SUCCESS ) {
/*
0, 0, &match );
dc.ctx = "matchedDN";
- dc.rwmap = &mi->mi_targets[ i ]->mt_rwmap;
+ dc.target = &mi->mi_targets[ i ];
if ( !ldap_back_dn_massage( &dc, &match, &mmatch ) ) {
if ( mmatch.bv_val == match.bv_val ) {
/*
* Rewrite the dn of the result, if needed
*/
- dc.rwmap = &mi->mi_targets[ target ]->mt_rwmap;
+ dc.target = &mi->mi_targets[ target ];
dc.conn = op->o_conn;
dc.rs = rs;
dc.ctx = "searchResult";
while ( ber_scanf( &ber, "{m", &a ) != LBER_ERROR ) {
int last = 0;
- ldap_back_map( &mi->mi_targets[ target ]->mt_rwmap.rwm_at,
+ ldap_back_map( &mi->mi_targets[ target ].mt_rwmap.rwm_at,
&a, &mapped, BACKLDAP_REMAP );
if ( BER_BVISNULL( &mapped ) || mapped.bv_val[0] == '\0' ) {
continue;
for ( last = 0; !BER_BVISNULL( &attr->a_vals[ last ] ); ++last );
for ( bv = attr->a_vals; !BER_BVISNULL( bv ); bv++ ) {
- ldap_back_map( &mi->mi_targets[ target ]->mt_rwmap.rwm_oc,
+ ldap_back_map( &mi->mi_targets[ target ].mt_rwmap.rwm_oc,
bv, &mapped, BACKLDAP_REMAP );
if ( BER_BVISNULL( &mapped ) || mapped.bv_val[0] == '\0') {
free( bv->bv_val );
int rc = 0;
static char *dmy = "";
- switch ( rewrite_session( dc->rwmap->rwm_rw, dc->ctx,
+ switch ( rewrite_session( dc->target->mt_rwmap.rwm_rw, dc->ctx,
( dn->bv_val ? dn->bv_val : dmy ),
dc->conn, &res->bv_val ) )
{
res->bv_len = 0;
return 0;
}
- if ( dc->rwmap == NULL || dc->rwmap->rwm_suffix_massage == NULL ) {
+ if ( dc->target->mt_rwmap.rwm_suffix_massage == NULL ) {
*res = *dn;
return 0;
}
}
for ( i = 0;
- dc->rwmap->rwm_suffix_massage[i].bv_val != NULL;
+ dc->target->mt_rwmap.rwm_suffix_massage[i].bv_val != NULL;
i += 4 ) {
- int aliasLength = dc->rwmap->rwm_suffix_massage[i+src].bv_len;
+ int aliasLength = dc->target->mt_rwmap.rwm_suffix_massage[i+src].bv_len;
int diff = dn->bv_len - aliasLength;
if ( diff < 0 ) {
/* At a DN Separator */
}
- if ( !strcmp( dc->rwmap->rwm_suffix_massage[i+src].bv_val, &dn->bv_val[diff] ) ) {
- res->bv_len = diff + dc->rwmap->rwm_suffix_massage[i+dst].bv_len;
+ if ( !strcmp( dc->target->mt_rwmap.rwm_suffix_massage[i+src].bv_val, &dn->bv_val[diff] ) ) {
+ res->bv_len = diff + dc->target->mt_rwmap.rwm_suffix_massage[i+dst].bv_len;
res->bv_val = ch_malloc( res->bv_len + 1 );
strncpy( res->bv_val, dn->bv_val, diff );
- strcpy( &res->bv_val[diff], dc->rwmap->rwm_suffix_massage[i+dst].bv_val );
+ strcpy( &res->bv_val[diff], dc->target->mt_rwmap.rwm_suffix_massage[i+dst].bv_val );
Debug( LDAP_DEBUG_ARGS,
"ldap_back_dn_massage:"
" converted \"%s\" to \"%s\"\n",
continue;
}
- rewrite_session_delete( mi->mi_targets[ i ]->mt_rwmap.rwm_rw, conn );
+ rewrite_session_delete( mi->mi_targets[ i ].mt_rwmap.rwm_rw, conn );
meta_clear_one_candidate( &mc->mc_conns[ i ] );
}
meta_back_conn_free( mc );