* get the current connection
*/
lc = meta_back_getconn( li, conn, op, META_OP_REQUIRE_SINGLE,
- e->e_ndn, &candidate );
- if ( !lc || !meta_back_dobind( lc, op ) ) {
+ &e->e_nname, &candidate );
+ if ( !lc || !meta_back_dobind( lc, op ) || !meta_back_is_valid( lc, candidate ) ) {
+ send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
+ NULL, NULL, NULL, NULL );
return -1;
}
Connection *conn,
Operation *op,
Entry *target,
- const char *ndn,
+ struct berval *ndn,
AttributeDescription *entry_at,
struct berval ***vals
)
LDAP *ld;
*vals = NULL;
- if ( target != NULL && strcmp( target->e_ndn, ndn ) == 0 ) {
+ if ( target != NULL && strcmp( target->e_ndn, ndn->bv_val ) == 0 ) {
/* we already have a copy of the entry */
/* attribute and objectclass mapping has already been done */
attr = attr_find( target->e_attrs, entry_at );
return 1;
}
- rc = ldap_bind_s( ld, li->targets[ candidate ]->binddn,
- li->targets[ candidate ]->bindpw, LDAP_AUTH_SIMPLE );
+ rc = ldap_bind_s( ld, li->targets[ candidate ]->binddn->bv_val,
+ li->targets[ candidate ]->bindpw->bv_val, LDAP_AUTH_SIMPLE );
if ( rc != LDAP_SUCCESS) {
return 1;
}
gattr[ 0 ] = mapped;
gattr[ 1 ] = NULL;
- if ( ldap_search_ext_s( ld, ndn, LDAP_SCOPE_BASE, "(objectclass=*)",
+ if ( ldap_search_ext_s( ld, ndn->bv_val, LDAP_SCOPE_BASE,
+ "(objectclass=*)",
gattr, 0, NULL, NULL, LDAP_NO_LIMIT,
LDAP_NO_LIMIT, &result) == LDAP_SUCCESS) {
if ( ( e = ldap_first_entry( ld, result ) ) != NULL ) {
#define META_CANDIDATE 1
LDAP *ld;
- char *bound_dn;
+ struct berval *bound_dn;
int bound;
#define META_UNBOUND 0
#define META_BOUND 1
struct metatarget {
char *uri;
- char *suffix;/* normalized suffix */
- char *binddn;
- char *bindpw;
+ struct berval *psuffix; /* pretty suffix */
+ struct berval *suffix; /* normalized suffix */
+ struct berval *binddn;
+ struct berval *bindpw;
- char *pseudorootdn;
- char *pseudorootpw;
+ struct berval *pseudorootdn;
+ struct berval *pseudorootpw;
struct rewrite_info *rwinfo;
meta_back_do_single_bind(
struct metainfo *li,
struct metaconn *lc,
- const char *dn,
- const char *ndn,
- const char *cred,
+ struct berval *dn,
+ struct berval *ndn,
+ struct berval *cred,
int method,
int candidate
);
struct slap_conn *conn,
struct slap_op *op,
int op_type,
- const char *dn,
+ struct berval *dn,
int *candidate
);
Operation *op
);
+extern int
+meta_back_is_valid(
+ struct metaconn *lc,
+ int candidate
+);
+
extern int
meta_back_op_result(
struct metaconn *lc,
*/
extern int
meta_back_is_candidate(
- const char *nsuffix,
- const char *ndn,
- int ndnlen
+ struct berval *nsuffix,
+ struct berval *ndn
);
extern int
meta_back_count_candidates(
struct metainfo *li,
- const char *ndn
+ struct berval *ndn
);
extern int
meta_back_is_candidate_unique(
struct metainfo *li,
- const char *ndn
+ struct berval *ndn
);
extern int
meta_back_select_unique_candidate(
struct metainfo *li,
- const char *ndn
+ struct berval *ndn
);
extern int
extern int
meta_dncache_get_target(
struct metadncache *cache,
- const char *ndn
+ struct berval *ndn
);
extern int
meta_dncache_update_entry(
struct metadncache *cache,
- const char *ndn,
+ struct berval *ndn,
int target
);
extern int
meta_dncache_delete_entry(
struct metadncache *cache,
- const char *ndn
+ struct berval *ndn
);
extern void
int op_type = META_OP_ALLOW_MULTIPLE;
int err = LDAP_SUCCESS;
- char *realdn = (char *)dn->bv_val;
- char *realndn = (char *)ndn->bv_val;
- char *realcred = cred->bv_val;
+ struct berval *realdn = dn;
+ struct berval *realndn = ndn;
+ struct berval *realcred = cred;
int realmethod = method;
#ifdef NEW_LOGGING
ber_dupbv( edn, be_root_dn( be ) );
op_type = META_OP_REQUIRE_ALL;
}
- lc = meta_back_getconn( li, conn, op, op_type, ndn->bv_val, NULL );
+ lc = meta_back_getconn( li, conn, op, op_type, ndn, NULL );
if ( !lc ) {
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_NOTICE,
meta_back_do_single_bind(
struct metainfo *li,
struct metaconn *lc,
- const char *dn,
- const char *ndn,
- const char *cred,
+ struct berval *dn,
+ struct berval *ndn,
+ struct berval *cred,
int method,
int candidate
)
* Rewrite the bind dn if needed
*/
switch ( rewrite_session( li->targets[ candidate ]->rwinfo,
- "bindDn", dn, lc->conn, &mdn ) ) {
+ "bindDn", dn->bv_val, lc->conn, &mdn ) ) {
case REWRITE_REGEXEC_OK:
if ( mdn == NULL ) {
- mdn = ( char * )dn;
+ mdn = ( char * )dn->bv_val;
}
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
- "[rw] bindDn: \"%s\" -> \"%s\"\n", dn, mdn ));
+ "[rw] bindDn: \"%s\" -> \"%s\"\n", dn->bv_val, mdn ));
#else /* !NEW_LOGGING */
Debug( LDAP_DEBUG_ARGS,
"rw> bindDn: \"%s\" -> \"%s\"\n%s",
- dn, mdn, "" );
+ dn->bv_val, mdn, "" );
#endif /* !NEW_LOGGING */
break;
return LDAP_OPERATIONS_ERROR;
}
- rc = ldap_bind_s( lc->conns[ candidate ]->ld, mdn, cred, method );
+ rc = ldap_bind_s( lc->conns[ candidate ]->ld, mdn, cred->bv_val, method );
if ( rc != LDAP_SUCCESS ) {
rc = ldap_back_map_result( rc );
} else {
- lc->conns[ candidate ]->bound_dn = ch_strdup( dn );
+ lc->conns[ candidate ]->bound_dn = ber_bvdup( dn );
lc->conns[ candidate ]->bound = META_BOUND;
lc->bound_target = candidate;
if ( li->cache.ttl != META_DNCACHE_DISABLED
- && ndn[ 0 ] != '\0' ) {
+ && ndn->bv_len != 0 ) {
( void )meta_dncache_update_entry( &li->cache,
- ch_strdup( ndn ), candidate );
+ ber_bvdup( ndn ), candidate );
}
}
- if ( mdn != dn ) {
+ if ( mdn != dn->bv_val ) {
free( mdn );
}
* (note: if the target was already bound, the anonymous
* bind clears the previous bind).
*/
- rc = ldap_bind_s( lsc[ 0 ]->ld, lsc[ 0 ]->bound_dn,
+ rc = ldap_bind_s( lsc[ 0 ]->ld, lsc[ 0 ]->bound_dn->bv_val,
NULL, LDAP_AUTH_SIMPLE );
if ( rc != LDAP_SUCCESS ) {
"meta_back_dobind: (anonymous)"
" bind as \"%s\" failed"
" with error \"%s\"\n",
- lsc[ 0 ]->bound_dn,
+ lsc[ 0 ]->bound_dn->bv_val,
ldap_err2string( rc ) ));
#else /* !NEW_LOGGING */
Debug( LDAP_DEBUG_ANY,
"==>meta_back_dobind: (anonymous)"
" bind as \"%s\" failed"
" with error \"%s\"\n%s",
- lsc[ 0 ]->bound_dn,
+ lsc[ 0 ]->bound_dn->bv_val,
ldap_err2string( rc ), "" );
#endif /* !NEW_LOGGING */
return( bound > 0 );
}
+/*
+ *
+ */
+int
+meta_back_is_valid( struct metaconn *lc, int candidate )
+{
+ struct metasingleconn **lsc;
+ int i;
+
+ assert( lc );
+
+ if ( candidate < 0 ) {
+ return 0;
+ }
+
+ for ( i = 0, lsc = lc->conns;
+ lsc[ 0 ] != NULL && i < candidate;
+ ++i, ++lsc );
+
+ if ( lsc[ 0 ] ) {
+ return( lsc[ 0 ]->ld != NULL );
+ }
+
+ return 0;
+}
+
/*
* FIXME: error return must be handled in a cleaner way ...
*/
*/
int
meta_back_is_candidate(
- const char *nsuffix,
- const char *ndn,
- int ndnlen
+ struct berval *nsuffix,
+ struct berval *ndn
)
{
- int len = strlen( nsuffix );
-
- if ( len > ndnlen ) {
+ if ( dnIsSuffix( nsuffix, ndn ) || dnIsSuffix( ndn, nsuffix ) ) {
/*
* suffix longer than dn
*/
- if ( ! DN_SEPARATOR( nsuffix[ ( len - ndnlen ) - 1 ] ) ) {
- /*
- * not a separator begins the possible common part
- */
- return META_NOT_CANDIDATE;
- }
-
- if ( strcmp( &nsuffix[ len - ndnlen ] , ndn ) == 0 ) {
- /*
- * Got it!
- */
- return META_CANDIDATE;
- }
- }
-
- if ( len < ndnlen && ! DN_SEPARATOR( ndn[ ( ndnlen - len ) - 1 ] ) ) {
- /*
- * not a separator begins the possible common part
- */
- return META_NOT_CANDIDATE;
- }
-
- if ( strcmp( nsuffix, &ndn[ ndnlen - len ] ) == 0 ) {
- /*
- * Got it!
- */
return META_CANDIDATE;
}
int
meta_back_count_candidates(
struct metainfo *li,
- const char *ndn
+ struct berval *ndn
)
{
- int i, cnt = 0, ndnlen = strlen( ndn );
+ int i, cnt = 0;
/*
* I know assertions should not check run-time values;
assert( li->ntargets != 0 );
for ( i = 0; i < li->ntargets; ++i ) {
- if ( meta_back_is_candidate( li->targets[ i ]->suffix,
- ndn, ndnlen ) ) {
+ if ( meta_back_is_candidate( li->targets[ i ]->suffix, ndn ) ) {
++cnt;
}
}
int
meta_back_is_candidate_unique(
struct metainfo *li,
- const char *ndn
+ struct berval *ndn
)
{
return ( meta_back_count_candidates( li, ndn ) == 1 );
int
meta_back_select_unique_candidate(
struct metainfo *li,
- const char *ndn
+ struct berval *ndn
)
{
- int i, ndnlen;
+ int i;
switch ( meta_back_count_candidates( li, ndn ) ) {
case 1:
? -1 : li->defaulttarget );
}
- ndnlen = strlen( ndn );
for ( i = 0; i < li->ntargets; ++i ) {
- if ( meta_back_is_candidate( li->targets[ i ]->suffix,
- ndn, ndnlen ) ) {
+ if ( meta_back_is_candidate( li->targets[ i ]->suffix, ndn ) ) {
return i;
}
}
}
if ( lsc->bound_dn != NULL ) {
- free( lsc->bound_dn );
+ ber_bvfree( lsc->bound_dn );
lsc->bound_dn = NULL;
}
Backend *be,
Connection *conn,
Operation *op,
- const char *dn,
- const char *ndn,
+ struct berval *dn,
+ struct berval *ndn,
AttributeAssertion *ava
)
{
* Rewrite the compare dn, if needed
*/
switch ( rewrite_session( li->targets[ i ]->rwinfo,
- "compareDn", dn, conn, &mdn ) ) {
+ "compareDn",
+ dn->bv_val, conn, &mdn ) ) {
case REWRITE_REGEXEC_OK:
if ( mdn == NULL ) {
- mdn = ( char * )dn;
+ mdn = ( char * )dn->bv_val;
}
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
"[rw] compareDn: \"%s\" -> \"%s\"\n",
- dn, mdn ));
+ dn->bv_val, mdn ));
#else /* !NEW_LOGGING */
Debug( LDAP_DEBUG_ARGS,
"rw> compareDn: \"%s\" -> \"%s\"\n%s",
- dn, mdn, "" );
+ dn->bv_val, mdn, "" );
#endif /* !NEW_LOGGING */
break;
continue;
}
- if ( mdn != dn ) {
+ if ( mdn != dn->bv_val ) {
free( mdn );
}
if ( mapped_attr != ava->aa_desc->ad_cname.bv_val ) {
* sending to cache ...
*/
if ( li->cache.ttl != META_DNCACHE_DISABLED ) {
- ( void )meta_dncache_update_entry( &li->cache, ch_strdup( ndn ), i );
+ ( void )meta_dncache_update_entry( &li->cache, ber_bvdup( ndn ), i );
}
count++;
/* URI of server to query */
if ( strcasecmp( argv[ 0 ], "uri" ) == 0 ) {
- int i = li->ntargets;
+ int i = li->ntargets;
#if 0
- int j;
+ int j;
#endif /* uncomment if uri MUST be a branch of suffix */
- LDAPURLDesc *ludp;
- char *last;
+ LDAPURLDesc *ludp;
+ char *last;
+ struct berval dn, *pdn = NULL, *ndn = NULL;
+ int rc;
if ( argc != 2 ) {
fprintf( stderr,
/*
* copies and stores uri and suffix
*/
- li->targets[ i ]->suffix = ch_strdup( ludp->lud_dn );
+ dn.bv_val = ludp->lud_dn;
+ dn.bv_len = strlen( ludp->lud_dn );
+
+ rc = dnPretty( NULL, &dn, &pdn );
+ if( rc != LDAP_SUCCESS ) {
+ fprintf( stderr, "%s: line %d: "
+ "target '%s' DN is invalid\n",
+ fname, lineno, argv[ 1 ] );
+ return( 1 );
+ }
+
+ rc = dnNormalize( NULL, &dn, &ndn );
+ if( rc != LDAP_SUCCESS ) {
+ fprintf( stderr, "%s: line %d: "
+ "target '%s' DN is invalid\n",
+ fname, lineno, argv[ 1 ] );
+ ber_bvfree( ndn );
+ return( 1 );
+ }
+
+ li->targets[ i ]->psuffix = pdn;
+ li->targets[ i ]->suffix = ndn;
+
li->targets[ i ]->uri = ch_strdup( argv[ 1 ] );
- last = strstr( li->targets[ i ]->uri,
- li->targets[ i ]->suffix );
+ last = strstr( li->targets[ i ]->uri, ludp->lud_dn );
assert( last != NULL );
- last[ 0 ] = '\0'; /* wasting memory ... */
-
- /*
- * Need to store the suffix in normalized form
- */
- (void) dn_normalize( li->targets[ i ]->suffix );
+ last[ 0 ] = '\0';
/*
* uri MUST be a branch of suffix!
* or worked out, at least, in some manner
*/
for ( j = 0; j < i-1; j++ ) {
- if ( strcmp( li->targets[ i ]->suffix,
- li->targets[ j ]->suffix ) == 0 ) {
+ if ( strcmp( li->targets[ i ]->suffix->bv_val,
+ li->targets[ j ]->suffix->bv_val ) == 0 ) {
fprintf( stderr,
"%s: line %d: naming context \"%s\" already used"
" in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
ldap_free_urldesc( ludp );
-#ifdef NEW_LOGGING
- LDAP_LOG(( "config", LDAP_LEVEL_INFO,
- "meta_back_db_config:"
- " URI \"%s\", suffix \"%s\"\n",
- li->targets[ i ]->uri,
- li->targets[ i ]->suffix ));
-#else /* !NEW_LOGGING */
- Debug( LDAP_DEBUG_CONFIG,
- "==>meta_back_db_config: URI \"%s\", suffix \"%s\"\n%s",
- li->targets[ i ]->uri, li->targets[ i ]->suffix, "" );
-#endif /* !NEW_LOGGING */
+ fprintf(stderr, "%s: line %d: URI \"%s\", suffix \"%s\"\n",
+ fname, lineno, li->targets[ i ]->uri,
+ li->targets[ i ]->psuffix->bv_val );
/* default target directive */
} else if ( strcasecmp( argv[ 0 ], "default-target" ) == 0 ) {
- int i = li->ntargets-1;
+ int i = li->ntargets-1;
if ( argc == 1 ) {
if ( i < 0 ) {
/* name to use for meta_back_group */
} else if ( strcasecmp( argv[ 0 ], "binddn" ) == 0 ) {
- int i = li->ntargets-1;
+ int i = li->ntargets-1;
+ struct berval dn, *ndn = NULL;
if ( i < 0 ) {
fprintf( stderr,
fname, lineno );
return 1;
}
- li->targets[ i ]->binddn = ch_strdup( argv[ 1 ] );
+
+ dn.bv_val = argv[ 1 ];
+ dn.bv_len = strlen( argv[ 1 ] );
+ if ( dnNormalize( NULL, &dn, &ndn ) != LDAP_SUCCESS ) {
+ fprintf( stderr, "%s: line %d: "
+ "bind DN '%s' is invalid\n",
+ fname, lineno, argv[ 1 ] );
+ return( 1 );
+ }
+
+ li->targets[ i ]->binddn = ndn;
/* password to use for meta_back_group */
} else if ( strcasecmp( argv[ 0 ], "bindpw" ) == 0 ) {
- int i = li->ntargets-1;
+ int i = li->ntargets-1;
if ( i < 0 ) {
fprintf( stderr,
fname, lineno );
return 1;
}
- li->targets[ i ]->bindpw = ch_strdup( argv[ 1 ] );
+ li->targets[ i ]->bindpw = ber_bvstrdup( argv[ 1 ] );
/* name to use as pseudo-root dn */
} else if ( strcasecmp( argv[ 0 ], "pseudorootdn" ) == 0 ) {
- int i = li->ntargets-1;
+ int i = li->ntargets-1;
+ struct berval dn, *ndn = NULL;
if ( i < 0 ) {
fprintf( stderr,
fname, lineno );
return 1;
}
- li->targets[ i ]->pseudorootdn = ch_strdup( argv[ 1 ] );
+
+ dn.bv_val = argv[ 1 ];
+ dn.bv_len = strlen( argv[ 1 ] );
+ if ( dnNormalize( NULL, &dn, &ndn ) != LDAP_SUCCESS ) {
+ fprintf( stderr, "%s: line %d: "
+ "pseudoroot DN '%s' is invalid\n",
+ fname, lineno, argv[ 1 ] );
+ return( 1 );
+ }
+
+ li->targets[ i ]->pseudorootdn = ndn;
/* password to use as pseudo-root */
} else if ( strcasecmp( argv[ 0 ], "pseudorootpw" ) == 0 ) {
- int i = li->ntargets-1;
+ int i = li->ntargets-1;
if ( i < 0 ) {
fprintf( stderr,
fname, lineno );
return 1;
}
- li->targets[ i ]->pseudorootpw = ch_strdup( argv[ 1 ] );
+ li->targets[ i ]->pseudorootpw = ber_bvstrdup( argv[ 1 ] );
/* dn massaging */
} else if ( strcasecmp( argv[ 0 ], "suffixmassage" ) == 0 ) {
- BackendDB *tmp_be;
- int i = li->ntargets-1;
+ BackendDB *tmp_be;
+ int i = li->ntargets-1;
+ struct berval dn, *ndn = NULL;
if ( i < 0 ) {
fprintf( stderr,
fname, lineno );
return 1;
}
+
+ dn.bv_val = argv[ 1 ];
+ dn.bv_len = strlen( argv[ 1 ] );
+ if ( dnNormalize( NULL, &dn, &ndn ) != LDAP_SUCCESS ) {
+ fprintf( stderr, "%s: line %d: "
+ "suffix '%s' is invalid\n",
+ fname, lineno, argv[ 1 ] );
+ return 1;
+ }
- tmp_be = select_backend( argv[ 1 ], 0, 0 );
+ tmp_be = select_backend( ndn, 0, 0 );
+ ber_bvfree( ndn );
if ( tmp_be != NULL && tmp_be != be ) {
fprintf( stderr,
"%s: line %d: suffix already in use by another backend in"
return 1;
}
- tmp_be = select_backend( argv[ 2 ], 0, 0 );
+ dn.bv_val = argv[ 2 ];
+ dn.bv_len = strlen( argv[ 2 ] );
+ ndn = NULL;
+ if ( dnNormalize( NULL, &dn, &ndn ) != LDAP_SUCCESS ) {
+ fprintf( stderr, "%s: line %d: "
+ "massaged suffix '%s' is invalid\n",
+ fname, lineno, argv[ 2 ] );
+ return 1;
+ }
+
+ tmp_be = select_backend( ndn, 0, 0 );
+ ber_bvfree( ndn );
if ( tmp_be != NULL ) {
fprintf( stderr,
"%s: line %d: massaged suffix already in use by another backend in"
/* rewrite stuff ... */
} else if ( strncasecmp( argv[ 0 ], "rewrite", 7 ) == 0 ) {
- int i = li->ntargets-1;
+ int i = li->ntargets-1;
if ( i < 0 ) {
fprintf( stderr,
struct ldapmap *map;
struct ldapmapping *mapping;
char *src, *dst;
- int i = li->ntargets-1;
+ int i = li->ntargets-1;
if ( i < 0 ) {
fprintf( stderr,
/*
* If the connection dn is not null, an attempt to rewrite it is made
*/
- if ( conn->c_cdn != NULL && conn->c_cdn[ 0 ] != '\0' ) {
+ if ( conn->c_cdn != 0 ) {
+ char *mdn = NULL;
+
/*
* Rewrite the bind dn if needed
*/
lsc->bound_dn = NULL;
switch ( rewrite_session( lt->rwinfo, "bindDn",
- conn->c_cdn, conn,
- &lsc->bound_dn ) ) {
+ conn->c_cdn, conn, &mdn ) ) {
case REWRITE_REGEXEC_OK:
- if ( lsc->bound_dn == NULL ) {
- lsc->bound_dn = ch_strdup( conn->c_cdn );
+ if ( mdn == NULL ) {
+ lsc->bound_dn = ber_bvstrdup( conn->c_cdn );
}
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
"[rw] bindDn: \"%s\" -> \"%s\"\n",
- conn->c_cdn, lsc->bound_dn ));
+ conn->c_cdn, lsc->bound_dn->bv_val ));
#else /* !NEW_LOGGING */
Debug( LDAP_DEBUG_ARGS,
- "rw> bindDn: \"%s\" -> \"%s\"\n%s",
- conn->c_cdn, lsc->bound_dn, "" );
+ "rw> bindDn: \"%s\" -> \"%s\"\n",
+ conn->c_cdn, lsc->bound_dn->bv_val, 0 );
#endif /* !NEW_LOGGING */
break;
NULL, NULL );
return LDAP_OPERATIONS_ERROR;
}
+
+ if ( mdn ) {
+ lsc->bound_dn = ber_bvstr( mdn );
+ } else {
+ lsc->bound_dn = ber_bvstrdup( "" );
+ }
+
} else {
- lsc->bound_dn = NULL;
+ lsc->bound_dn = ber_bvstrdup( "" );
}
lsc->bound = META_UNBOUND;
struct metaconn *
meta_back_getconn(
struct metainfo *li,
- Connection *conn,
- Operation *op,
- int op_type,
- const char *ndn,
- int *candidate
- )
+ Connection *conn,
+ Operation *op,
+ int op_type,
+ struct berval *ndn,
+ int *candidate )
{
struct metaconn *lc, lc_curr;
int vers, cached = -1, i = -1, err = LDAP_SUCCESS;
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
"meta_back_getconn: got target %d"
- " for ndn=\"%s\" from cache\n", i, ndn ));
+ " for ndn=\"%s\" from cache\n",
+ i, ndn->bv_val ));
#else /* !NEW_LOGGING */
Debug( LDAP_DEBUG_CACHE,
"==>meta_back_getconn: got target %d for ndn=\"%s\" from cache\n%s",
- i, ndn, "" );
+ i, ndn->bv_val, "" );
#endif /* !NEW_LOGGING */
/*
* if no unique candidate ...
*/
} else {
- int ndnlen = strlen( ndn );
for ( i = 0; i < li->ntargets; i++ ) {
if ( i == cached
- || meta_back_is_candidate( li->targets[ i ]->suffix,
- ndn, ndnlen ) ) {
+ || meta_back_is_candidate( li->targets[ i ]->suffix, ndn ) ) {
/*
* The target is activated; if needed, it is
-dn: ou=People, dc=foo, dc=example, dc=com
+dn: ou=People,dc=foo,dc=example,dc=com
objectClass: top
+objectClass: organizationalUnit
+ou: People
-dn: cn=Ando, ou=People, dc=foo, dc=example, dc=com
+dn: cn=Ando,ou=People,dc=foo,dc=example,dc=com
objectClass: top
objectClass: person
cn: Ando
-dn: ou=People, dc=bar, dc=example, dc=com
+dn: ou=People,dc=bar,dc=example,dc=com
objectClass: top
+objectClass: organizationalUnit
+ou: People
-dn: cn=Ando, ou=People, dc=bar, dc=example, dc=com
+dn: cn=Ando,ou=People,dc=bar,dc=example,dc=com
objectClass: top
objectClass: person
cn: Ando
-dn: ou=Groups, dc=bar, dc=example, dc=com
+dn: ou=Groups,dc=bar,dc=example,dc=com
objectClass: top
+objectClass: organizationalUnit
+ou: Groups
-dn: cn=Users, ou=Groups, dc=bar, dc=example, dc=com
+dn: cn=Users,ou=Groups,dc=bar,dc=example,dc=com
objectClass: top
objectClass: groupOfNames
objectClass: simpleSecurityObject
cn: Users
-member: cn=Users, ou=Groups, dc=bar, dc=example, dc=com
-member: cn=Ando, ou=People, dc=bar, dc=example, dc=com
+member: cn=Users,ou=Groups,dc=bar,dc=example,dc=com
+member: cn=Ando,ou=People,dc=bar,dc=example,dc=com
userPassword: users
for i in 1 2 3 ; do
echo "Feeding directory $i"
mkdir -p "$METADBDIR/$i"
- $SLAPADD -f $ADDCONF -n $i -l meta-$i.ldif
+ $SLAPADD -f $ADDCONF -n `expr $i + 1` -l meta-$i.ldif
done
echo ""
database ldap
uri "ldap://localhost:@PORT@/"
-suffix "o=FB, c=US"
-suffixmassage "o=FB, c=US" "ou=Groups, dc=bar, dc=example, dc=com"
+suffix "o=FB,c=US"
+suffixmassage "o=FB,c=US" "ou=Groups,dc=bar,dc=example,dc=com"
lastmod off
access to dn.regex="[^,]+,o=FB,c=US" attr=cn
#######################################################################
database ldbm
-suffix "ou=People, dc=foo, dc=example, dc=com"
-rootdn "cn=Root, ou=People, dc=foo, dc=example, dc=com"
+suffix "ou=People,dc=foo,dc=example,dc=com"
+rootdn "cn=Root,ou=People,dc=foo,dc=example,dc=com"
rootpw ldap
directory ./meta-db/1
lastmod on
index objectClass pres,eq
database ldbm
-suffix "ou=People, dc=bar, dc=example, dc=com"
-rootdn "cn=Root, ou=People, dc=bar, dc=example, dc=com"
+suffix "ou=People,dc=bar,dc=example,dc=com"
+rootdn "cn=Root,ou=People,dc=bar,dc=example,dc=com"
rootpw ldap
directory ./meta-db/2
index objectClass pres,eq
database ldbm
-suffix "ou=Groups, dc=bar, dc=example, dc=com"
-rootdn "cn=Root, ou=Groups, dc=bar, dc=example, dc=com"
+suffix "ou=Groups,dc=bar,dc=example,dc=com"
+rootdn "cn=Root,ou=Groups,dc=bar,dc=example,dc=com"
rootpw ldap
directory ./meta-db/3
index objectClass pres,eq
#######################################################################
database meta
-suffix "dc=example, dc=com"
+suffix "dc=example,dc=com"
dncache-ttl forever
-uri "ldap://localhost:@PORT@/ou=People, dc=foo, dc=example, dc=com"
-uri "ldap://localhost:@PORT@/ou=People, dc=bar, dc=example, dc=com"
-uri "ldap://localhost:@PORT@/ou=Groups, dc=bar, dc=example, dc=com"
+uri "ldap://localhost:@PORT@/ou=People,dc=foo,dc=example,dc=com"
+uri "ldap://localhost:@PORT@/ou=People,dc=bar,dc=example,dc=com"
+uri "ldap://localhost:@PORT@/ou=Groups,dc=bar,dc=example,dc=com"
by * read
#######################################################################
-# ldbm database definitions
+# ldap database with suffix massage definitions
#######################################################################
-include ./slapd-ldbm.conf
+include ./slapd-ldap.conf
#######################################################################
-# ldap database with suffix massage definitions
+# ldbm database definitions
#######################################################################
-include ./slapd-ldap.conf
+include ./slapd-ldbm.conf
#######################################################################
# meta database definitions
#######################################################################
database meta
-suffix "o=Foo Bar, c=US"
+suffix "o=Foo Bar,c=US"
dncache-ttl forever
lastmod off
rootdn "cn=root,o=Foo Bar,c=US"
rootpw foo
-uri "ldap://localhost:@PORT@/ou=People, dc=foo, o=Foo Bar, c=US"
-pseudorootdn "cn=Root, ou=People, dc=foo, dc=example, dc=com"
+uri "ldap://localhost:@PORT@/ou=People,dc=foo,o=Foo Bar,c=US"
+pseudorootdn "cn=Root,ou=People,dc=foo,dc=example,dc=com"
pseudorootpw ldap
rewriteEngine on
rewriteContext default
-rewriteRule "(.*)o=Foo Bar,[ ]?c=US" "%1dc=example, dc=com"
+rewriteRule "(.*)o=Foo Bar,[ ]?c=US" "%1dc=example,dc=com"
rewriteContext searchResult
-rewriteRule "(.*)dc=example,[ ]?dc=com" "%1o=Foo Bar, c=US"
+rewriteRule "(.*)dc=example,[ ]?dc=com" "%1o=Foo Bar,c=US"
rewriteContext searchFilter
rewriteRule "(.*)member=([^)]+),o=Foo Bar,[ ]?c=US(.*)" "%1member=%2,dc=example,dc=com%3"
-uri "ldap://localhost:@PORT@/ou=People, dc=bar, o=Foo Bar, c=US"
-pseudorootdn "cn=Root, ou=People, dc=bar, dc=example, dc=com"
+uri "ldap://localhost:@PORT@/ou=People,dc=bar,o=Foo Bar,c=US"
+pseudorootdn "cn=Root,ou=People,dc=bar,dc=example,dc=com"
pseudorootpw ldap
rewriteEngine on
rewriteContext default
-rewriteRule "(.*)o=Foo Bar,[ ]?c=US" "%1dc=example, dc=com"
+rewriteRule "(.*)o=Foo Bar,[ ]?c=US" "%1dc=example,dc=com"
rewriteContext searchResult
-rewriteRule "(.*)dc=example,[ ]?dc=com" "%1o=Foo Bar, c=US"
+rewriteRule "(.*)dc=example,[ ]?dc=com" "%1o=Foo Bar,c=US"
rewriteContext searchFilter
rewriteRule "(.*)member=([^)]+),o=Foo Bar,[ ]?c=US(.*)" "%1member=%2,dc=example,dc=com%3"
default-target
map attribute givenName sn
-uri "ldap://localhost:@PORT@/ou=Groups, dc=bar, o=Foo Bar, c=US"
+uri "ldap://localhost:@PORT@/ou=Groups,dc=bar,o=Foo Bar,c=US"
rewriteEngine on
rewriteContext default
-rewriteRule "(.*)o=Foo Bar,[ ]?c=US" "%1dc=example, dc=com"
+rewriteRule "(.*)o=Foo Bar,[ ]?c=US" "%1dc=example,dc=com"
rewriteContext searchResult
-rewriteRule "(.*)dc=example,[ ]?dc=com" "%1o=Foo Bar, c=US"
+rewriteRule "(.*)dc=example,[ ]?dc=com" "%1o=Foo Bar,c=US"
rewriteContext searchFilter
rewriteRule "(.*)member=([^)]+),o=Foo Bar,[ ]?c=US(.*)" "%1member=%2,dc=example,dc=com%3"
Backend *be,
Connection *conn,
Operation *op,
- const char *dn,
- const char *ndn
+ struct berval *dn,
+ struct berval *ndn
)
{
struct metainfo *li = ( struct metainfo * )be->be_private;
lc = meta_back_getconn( li, conn, op, META_OP_REQUIRE_SINGLE,
ndn, &candidate );
- if ( !lc || !meta_back_dobind( lc, op ) ) {
+ if ( !lc || !meta_back_dobind( lc, op ) || !meta_back_is_valid( lc, candidate ) ) {
+ send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
+ NULL, NULL, NULL, NULL );
return -1;
}
* Rewrite the compare dn, if needed
*/
switch ( rewrite_session( li->targets[ candidate ]->rwinfo,
- "deleteDn", dn, conn, &mdn ) ) {
+ "deleteDn", dn->bv_val, conn, &mdn ) ) {
case REWRITE_REGEXEC_OK:
if ( mdn == NULL ) {
- mdn = ( char * )dn;
+ mdn = ( char * )dn->bv_val;
}
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
"[rw] deleteDn: \"%s\" -> \"%s\"\n",
- dn, mdn ));
+ dn->bv_val, mdn ));
#else /* !NEW_LOGGING */
Debug( LDAP_DEBUG_ARGS, "rw> deleteDn: \"%s\" -> \"%s\"\n%s",
- dn, mdn, "" );
+ dn->bv_val, mdn, "" );
#endif /* !NEW_LOGGING */
break;
ldap_delete_s( lc->conns[ candidate ]->ld, mdn );
- if ( mdn != dn ) {
+ if ( mdn != dn->bv_val ) {
free( mdn );
}
*/
struct metadncacheentry {
- char *dn;
- int target;
+ struct berval *dn;
+ int target;
- time_t lastupdated;
+ time_t lastupdated;
};
/*
{
struct metadncacheentry *cc1 = ( struct metadncacheentry * )c1;
struct metadncacheentry *cc2 = ( struct metadncacheentry * )c2;
+
+ int d = cc1->dn->bv_len - cc2->dn->bv_len;
/*
* case sensitive, because the dn MUST be normalized
*/
- return strcmp( cc1->dn, cc2->dn );
+ return d != 0 ? d : strcmp( cc1->dn->bv_val, cc2->dn->bv_val );
}
/*
struct metadncacheentry *cc1 = ( struct metadncacheentry * )c1;
struct metadncacheentry *cc2 = ( struct metadncacheentry * )c2;
+ int d = cc1->dn->bv_len - cc2->dn->bv_len;
+ int cmp;
+
/*
* case sensitive, because the dn MUST be normalized
*/
- return ( strcmp( cc1->dn, cc2->dn ) == 0 ) ? -1 : 0;
+ cmp = d != 0 ? d : strcmp( cc1->dn->bv_val, cc2->dn->bv_val );
+
+ return ( cmp == 0 ) ? -1 : 0;
}
/*
int
meta_dncache_get_target(
struct metadncache *cache,
- const char *ndn
+ struct berval *ndn
)
{
struct metadncacheentry tmp_entry, *entry;
time_t curr_time;
int target = -1;
- tmp_entry.dn = ( char * )ndn;
+ tmp_entry.dn = ndn;
ldap_pvt_thread_mutex_lock( &cache->mutex );
entry = ( struct metadncacheentry * )avl_find( cache->tree,
( caddr_t )&tmp_entry, meta_dncache_cmp );
int
meta_dncache_update_entry(
struct metadncache *cache,
- const char *ndn,
+ struct berval *ndn,
int target
)
{
curr_time = time( NULL );
}
- tmp_entry.dn = ( char * )ndn;
+ tmp_entry.dn = ndn;
ldap_pvt_thread_mutex_lock( &cache->mutex );
entry = ( struct metadncacheentry * )avl_find( cache->tree,
return -1;
}
- entry->dn = ch_strdup( ndn );
+ entry->dn = ber_bvdup( ndn );
if ( entry->dn == NULL ) {
ldap_pvt_thread_mutex_unlock( &cache->mutex );
return -1;
int
meta_dncache_delete_entry(
struct metadncache *cache,
- const char *ndn
+ struct berval *ndn
)
{
struct metadncacheentry *entry, tmp_entry;
- tmp_entry.dn = ( char * )ndn;
+ tmp_entry.dn = ndn;
ldap_pvt_thread_mutex_lock( &cache->mutex );
entry = avl_delete( &cache->tree, ( caddr_t )&tmp_entry,
{
struct metadncacheentry *entry = ( struct metadncacheentry * )e;
- free( entry->dn );
+ ber_bvfree( entry->dn );
}
Connection *conn,
Operation *op,
Entry *target,
- const char *gr_ndn,
- const char *op_ndn,
+ struct berval *gr_ndn,
+ struct berval *op_ndn,
ObjectClass *group_oc,
AttributeDescription *group_at
)
struct metainfo *li = ( struct metainfo * )be->be_private;
int rc = 1, candidate;
Attribute *attr;
- struct berval bv;
-
AttributeDescription *ad_objectClass = slap_schema.si_ad_objectClass;
LDAPMessage *result;
char *gattr[ 2 ];
group_oc_name = group_oc->soc_oid;
}
- if ( target != NULL && strcmp( target->e_ndn, gr_ndn ) == 0 ) {
+ if ( target != NULL && strcmp( target->e_nname.bv_val, gr_ndn->bv_val ) == 0 ) {
/* we already have a copy of the entry */
/* attribute and objectclass mapping has already been done */
*/
attr = attr_find( target->e_attrs, group_at );
if ( attr != NULL ) {
- bv.bv_val = ( char * )op_ndn;
- bv.bv_len = strlen( op_ndn );
- rc = value_find( group_at, attr->a_vals, &bv );
+ rc = value_find( group_at, attr->a_vals,
+ op_ndn );
if ( rc != LDAP_SUCCESS ) {
return 1;
}
* Rewrite the op ndn if needed
*/
switch ( rewrite_session( li->targets[ candidate ]->rwinfo, "bindDn",
- op_ndn, conn, &mop_ndn ) ) {
+ op_ndn->bv_val, conn, &mop_ndn ) ) {
case REWRITE_REGEXEC_OK:
if ( mop_ndn == NULL ) {
- mop_ndn = ( char * )op_ndn;
+ mop_ndn = ( char * )op_ndn->bv_val;
}
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
"[rw] bindDn (op ndn in group):"
\"%s\" -> \"%s\"\n",
- op_ndn, mop_ndn ));
+ op_ndn->bv_val, mop_ndn));
#else /* !NEW_LOGGING */
Debug( LDAP_DEBUG_ARGS,
"rw> bindDn (op ndn in group):"
" \"%s\" -> \"%s\"\n%s",
- op_ndn, mop_ndn, "" );
+ op_ndn->bv_val, mop_ndn, "" );
#endif /* !NEW_LOGGING */
break;
*/
switch ( rewrite_session( li->targets[ candidate ]->rwinfo,
"searchBase",
- gr_ndn, conn, &mgr_ndn ) ) {
+ gr_ndn->bv_val, conn, &mgr_ndn ) ) {
case REWRITE_REGEXEC_OK:
if ( mgr_ndn == NULL ) {
- mgr_ndn = ( char * )gr_ndn;
+ mgr_ndn = ( char * )gr_ndn->bv_val;
}
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
"[rw] searchBase (gr ndn in group):"
" \"%s\" -> \"%s\"\n",
- gr_ndn, mgr_ndn ));
+ gr_ndn->bv_val, mgr_ndn ));
#else /* !NEW_LOGGING */
Debug( LDAP_DEBUG_ARGS,
"rw> searchBase (gr ndn in group):"
" \"%s\" -> \"%s\"\n%s",
- gr_ndn, mgr_ndn, "" );
+ gr_ndn->bv_val, mgr_ndn, "" );
#endif /* !NEW_LOGGING */
break;
goto cleanup;
}
- rc = ldap_bind_s( ld, li->targets[ candidate ]->binddn,
- li->targets[ candidate ]->bindpw, LDAP_AUTH_SIMPLE );
+ rc = ldap_bind_s( ld, li->targets[ candidate ]->binddn->bv_val,
+ li->targets[ candidate ]->bindpw->bv_val,
+ LDAP_AUTH_SIMPLE );
if ( rc != LDAP_SUCCESS ) {
goto cleanup;
}
if ( filter != NULL ) {
ch_free( filter );
}
- if ( mop_ndn != op_ndn ) {
+ if ( mop_ndn != op_ndn->bv_val ) {
free( mop_ndn );
}
- if ( mgr_ndn != gr_ndn ) {
+ if ( mgr_ndn != gr_ndn->bv_val ) {
free( mgr_ndn );
}
ldap_unbind( lsc[ 0 ]->ld );
}
if ( lsc[ 0 ]->bound_dn ) {
- free( lsc[ 0 ]->bound_dn );
+ ber_bvfree( lsc[ 0 ]->bound_dn );
}
free( lsc[ 0 ] );
}
if ( lt->uri ) {
free( lt->uri );
}
+ if ( lt->psuffix ) {
+ ber_bvfree( lt->psuffix );
+ }
+ if ( lt->suffix ) {
+ ber_bvfree( lt->suffix );
+ }
if ( lt->binddn ) {
- free( lt->binddn );
+ ber_bvfree( lt->binddn );
}
if ( lt->bindpw ) {
- free( lt->bindpw );
+ ber_bvfree( lt->bindpw );
+ }
+ if ( lt->pseudorootdn ) {
+ ber_bvfree( lt->pseudorootdn );
+ }
+ if ( lt->pseudorootpw ) {
+ ber_bvfree( lt->pseudorootpw );
}
if ( lt->rwinfo ) {
rewrite_info_delete( lt->rwinfo );
Backend *be,
Connection *conn,
Operation *op,
- const char *dn,
- const char *ndn,
+ struct berval *dn,
+ struct berval *ndn,
Modifications *modlist
)
{
lc = meta_back_getconn( li, conn, op, META_OP_REQUIRE_SINGLE,
ndn, &candidate );
- if ( !lc || !meta_back_dobind( lc, op ) ) {
+ if ( !lc || !meta_back_dobind( lc, op ) || !meta_back_is_valid( lc, candidate ) ) {
+ send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
+ NULL, NULL, NULL, NULL );
return -1;
}
* Rewrite the modify dn, if needed
*/
switch ( rewrite_session( li->targets[ candidate ]->rwinfo,
- "modifyDn", dn, conn, &mdn ) ) {
+ "modifyDn", dn->bv_val, conn, &mdn ) ) {
case REWRITE_REGEXEC_OK:
if ( mdn == NULL ) {
- mdn = ( char * )dn;
+ mdn = ( char * )dn->bv_val;
}
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
"[rw] modifyDn: \"%s\" -> \"%s\"\n",
- dn, mdn ));
+ dn->bv_val, mdn ));
#else /* !NEW_LOGGING */
Debug( LDAP_DEBUG_ARGS, "rw> modifyDn: \"%s\" -> \"%s\"\n%s",
- dn, mdn, "" );
+ dn->bv_val, mdn, "" );
#endif /* !NEW_LOGGING */
break;
mods = ch_malloc( sizeof( LDAPMod )*i );
if ( mods == NULL ) {
- if ( mdn != dn ) {
+ if ( mdn != dn->bv_val ) {
free( mdn );
}
return -1;
modv = ( LDAPMod ** )ch_malloc( ( i + 1 )*sizeof( LDAPMod * ) );
if ( modv == NULL ) {
free( mods );
- if ( mdn != dn ) {
+ if ( mdn != dn->bv_val ) {
free( mdn );
}
return -1;
ldap_modify_s( lc->conns[ candidate ]->ld, mdn, modv );
- if ( mdn != dn ) {
+ if ( mdn != dn->bv_val ) {
free( mdn );
}
free( mods );
Backend *be,
Connection *conn,
Operation *op,
- const char *dn,
- const char *ndn,
- const char *newrdn,
+ struct berval *dn,
+ struct berval *ndn,
+ struct berval *newrdn,
+ struct berval *nnewrdn,
int deleteoldrdn,
- const char *newSuperior
+ struct berval *newSuperior,
+ struct berval *nnewSuperior
)
{
struct metainfo *li = ( struct metainfo * )be->be_private;
lc = meta_back_getconn( li, conn, op, META_OP_REQUIRE_SINGLE,
ndn, &candidate );
- if ( !lc || !meta_back_dobind( lc, op ) ) {
+ if ( !lc || !meta_back_dobind( lc, op ) || !meta_back_is_valid( lc, candidate ) ) {
+ send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
+ NULL, NULL, NULL, NULL );
return -1;
}
*/
switch ( rewrite_session( li->targets[ nsCandidate ]->rwinfo,
"newSuperiorDn",
- newSuperior, conn, &mnewSuperior ) ) {
+ newSuperior->bv_val,
+ conn,
+ &mnewSuperior ) ) {
case REWRITE_REGEXEC_OK:
if ( mnewSuperior == NULL ) {
mnewSuperior = ( char * )newSuperior;
#else /* !NEW_LOGGING */
Debug( LDAP_DEBUG_ARGS, "rw> newSuperiorDn:"
" \"%s\" -> \"%s\"\n%s",
- newSuperior, mnewSuperior, "" );
+ newSuperior->bv_val, mnewSuperior, "" );
#endif /* !NEW_LOGGING */
break;
* Rewrite the modrdn dn, if required
*/
switch ( rewrite_session( li->targets[ candidate ]->rwinfo,
- "modrDn", dn, conn, &mdn ) ) {
+ "modrDn", dn->bv_val, conn, &mdn ) ) {
case REWRITE_REGEXEC_OK:
if ( mdn == NULL ) {
- mdn = ( char * )dn;
+ mdn = ( char * )dn->bv_val;
}
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
"[rw] modrDn: \"%s\" -> \"%s\"\n",
- dn, mdn ));
+ dn->bv_val, mdn ));
#else /* !NEW_LOGGING */
Debug( LDAP_DEBUG_ARGS, "rw> modrDn: \"%s\" -> \"%s\"\n%s",
- dn, mdn, "" );
+ dn->bv_val, mdn, "" );
#endif /* !NEW_LOGGING */
break;
return -1;
}
- ldap_rename2_s( lc->conns[ candidate ]->ld, mdn, newrdn,
+ ldap_rename2_s( lc->conns[ candidate ]->ld, mdn, newrdn->bv_val,
mnewSuperior, deleteoldrdn );
- if ( mdn != dn ) {
+ if ( mdn != dn->bv_val ) {
free( mdn );
}
- if ( mnewSuperior != NULL && mnewSuperior != newSuperior ) {
+ if ( mnewSuperior != NULL && mnewSuperior != newSuperior->bv_val ) {
free( mnewSuperior );
}
struct metaconn *lc,
int i,
LDAPMessage *e,
- struct berval **attrs,
+ struct berval **attrs,
int attrsonly
);
static int
is_one_level_rdn(
- const char *rdn,
- int len
+ const char *rdn,
+ int from
);
int
Backend *be,
Connection *conn,
Operation *op,
- const char *base,
- const char *nbase,
+ struct berval *base,
+ struct berval *nbase,
int scope,
int deref,
int slimit,
int tlimit,
Filter *filter,
const char *filterstr,
- struct berval **attrs,
+ struct berval **attrs,
int attrsonly
)
{
char *mbase = NULL, *mfilter = NULL, *mmatch = NULL,
*mapped_filter = NULL, **mapped_attrs = NULL;
- int i, last = 0, candidates = 0, nbaselen, op_type;
+ int i, last = 0, candidates = 0, op_type;
struct slap_limits_set *limit = NULL;
int isroot = 0;
return -1;
}
- nbaselen = strlen( nbase );
-
/* if not root, get appropriate limits */
if ( be_isroot( be, &op->o_ndn ) ) {
isroot = 1;
* Inits searches
*/
for ( i = 0, lsc = lc->conns; lsc[ 0 ] != NULL; ++i, ++lsc ) {
- char *realbase = ( char * )base;
+ char *realbase = ( char * )base->bv_val;
int realscope = scope;
int suffixlen;
/*
* modifies the base according to the scope, if required
*/
- suffixlen = strlen( li->targets[ i ]->suffix );
- if ( suffixlen > nbaselen ) {
+ suffixlen = li->targets[ i ]->suffix->bv_len;
+ if ( suffixlen > nbase->bv_len ) {
switch ( scope ) {
case LDAP_SCOPE_SUBTREE:
/*
* illegal bases may be turned into
* the suffix of the target.
*/
- if ( dn_issuffix( li->targets[ i ]->suffix,
+ if ( dnIsSuffix( li->targets[ i ]->suffix,
nbase ) ) {
- realbase = li->targets[ i ]->suffix;
+ realbase = li->targets[ i ]->suffix->bv_val;
} else {
/*
* this target is no longer candidate
break;
case LDAP_SCOPE_ONELEVEL:
- if ( is_one_level_rdn( li->targets[ i ]->suffix,
- suffixlen-nbaselen-1)
- && dn_issuffix( li->targets[ i ]->suffix, nbase ) ) {
+ if ( is_one_level_rdn( li->targets[ i ]->suffix->bv_val,
+ suffixlen - nbase->bv_len - 1 )
+ && dnIsSuffix( li->targets[ i ]->suffix, nbase ) ) {
/*
* if there is exactly one level,
* make the target suffix the new
* base, and make scope "base"
*/
- realbase = li->targets[ i ]->suffix;
+ realbase = li->targets[ i ]->suffix->bv_val;
realscope = LDAP_SCOPE_BASE;
break;
} /* else continue with the next case */
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
"[rw] searchBase: \"%s\" -> \"%s\"\n",
- base, mbase ));
+ base->bv_val, mbase ));
#else /* !NEW_LOGGING */
Debug( LDAP_DEBUG_ARGS, "rw> searchBase: \"%s\" -> \"%s\"\n%s",
- base, mbase, "" );
+ base->bv_val, mbase, "" );
#endif /* !NEW_LOGGING */
break;
*/
mapped_attrs = ldap_back_map_attrs( &li->targets[ i ]->at_map,
attrs, 0 );
- if ( mapped_attrs == NULL ) {
- mapped_attrs = attrs;
+ if ( mapped_attrs == NULL && attrs) {
+ for ( count = 0; attrs[ count ]; count++ );
+ mapped_attrs = ch_malloc( ( count + 1 ) * sizeof(char *));
+ for ( count = 0; attrs[ count ]; count++ ) {
+ mapped_attrs[ count ] = attrs[ count ]->bv_val;
+ }
+ mapped_attrs[ count ] = NULL;
}
/*
continue;
}
- if ( mapped_attrs != attrs ) {
- charray_free( mapped_attrs );
+ if ( mapped_attrs ) {
+ free( mapped_attrs );
mapped_attrs = NULL;
}
if ( mapped_filter != mfilter ) {
static void
meta_send_entry(
- Backend *be,
- Operation *op,
+ Backend *be,
+ Operation *op,
struct metaconn *lc,
- int target,
- LDAPMessage *e,
- struct berval **attrs,
- int attrsonly
+ int target,
+ LDAPMessage *e,
+ struct berval **attrs,
+ int attrsonly
)
{
- struct metainfo *li = ( struct metainfo * )be->be_private;
- char *a, *mapped;
- Entry ent;
- BerElement *ber = NULL;
- Attribute *attr, **attrp;
- struct berval *dummy = NULL;
- struct berval *bv;
- const char *text;
- char *dn;
+ struct metainfo *li = ( struct metainfo * )be->be_private;
+ char *a, *mapped;
+ Entry ent;
+ BerElement *ber = NULL;
+ Attribute *attr, **attrp;
+ struct berval *dummy = NULL;
+ struct berval *bv;
+ const char *text;
+ char *dn, *edn = NULL;
+ struct berval tdn, *pdn = NULL, *ndn = NULL;
struct metasingleconn *lsc = lc->conns[ target ];
* Rewrite the dn of the result, if needed
*/
switch ( rewrite_session( li->targets[ target ]->rwinfo,
- "searchResult", dn, lc->conn, &ent.e_dn ) ) {
+ "searchResult", dn, lc->conn, &edn ) ) {
case REWRITE_REGEXEC_OK:
- if ( ent.e_dn == NULL ) {
- ent.e_dn = dn;
+ if ( edn == NULL ) {
+ edn = dn;
+
} else {
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
"[rw] searchResult[%d]:"
" \"%s\" -> \"%s\"\n",
- target, dn, ent.e_dn ));
+ target, dn, edn ));
#else /* !NEW_LOGGING */
Debug( LDAP_DEBUG_ARGS, "rw> searchResult[%d]: \"%s\""
- " -> \"%s\"\n", target, dn, ent.e_dn );
+ " -> \"%s\"\n", target, dn, edn );
#endif /* !NEW_LOGGING */
free( dn );
dn = NULL;
return;
}
- ent.e_ndn = ch_strdup( ent.e_dn );
- ( void )dn_normalize( ent.e_ndn );
+ tdn.bv_val = edn;
+ tdn.bv_len = strlen( edn );
+ if ( dnPretty( NULL, &tdn, &pdn ) != LDAP_SUCCESS ) {
+
+ }
+
+ if ( dnNormalize( NULL, &tdn, &ndn ) != LDAP_SUCCESS ) {
+
+ }
+
+ ent.e_name = *pdn;
+ free( pdn );
+ ent.e_nname = *ndn;
+ free( ndn );
/*
* cache dn
*/
if ( li->cache.ttl != META_DNCACHE_DISABLED ) {
( void )meta_dncache_update_entry( &li->cache,
- ch_strdup( ent.e_ndn ),
+ ber_bvdup( &ent.e_nname ),
target );
}
static int
is_one_level_rdn(
- const char *rdn,
- int len
+ const char *rdn,
+ int from
)
{
- for ( ; len--; ) {
- if ( DN_SEPARATOR( rdn[ len ] ) ) {
+ for ( ; from--; ) {
+ if ( DN_SEPARATOR( rdn[ from ] )
+ && ! DN_ESCAPE( rdn[ from ] - 1 ) ) {
return 0;
}
}