Commit 6ef22ccd authored by Pierangelo Masarati's avatar Pierangelo Masarati
Browse files

first cut at grouping rewrite/map stuff; needs work

parent 96e1632d
......@@ -85,6 +85,7 @@ meta_back_add( Operation *op, SlapReply *rs )
Attribute *a;
LDAPMod **attrs;
struct berval mdn = { 0, NULL }, mapped;
dncookie dc;
#ifdef NEW_LOGGING
LDAP_LOG( BACK_META, ENTRY, "meta_back_add: %s\n",
......@@ -113,36 +114,13 @@ meta_back_add( Operation *op, SlapReply *rs )
/*
* Rewrite the add dn, if needed
*/
switch ( rewrite_session( li->targets[ candidate ]->rwinfo,
"addDn", op->o_req_dn.bv_val, op->o_conn,
&mdn.bv_val ) ) {
case REWRITE_REGEXEC_OK:
if ( mdn.bv_val != NULL && mdn.bv_val[ 0 ] != '\0' ) {
mdn.bv_len = strlen( mdn.bv_val );
} else {
mdn = op->o_req_dn;
}
dc.rwmap = &li->targets[ candidate ]->rwmap;
dc.conn = op->o_conn;
dc.rs = rs;
dc.ctx = "addDn";
#ifdef NEW_LOGGING
LDAP_LOG( BACK_META, DETAIL1,
"[rw] addDn: \"%s\" -> \"%s\"\n",
op->o_req_dn.bv_val, mdn.bv_val, 0 );
#else /* !NEW_LOGGING */
Debug( LDAP_DEBUG_ARGS, "rw> addDn: \"%s\" -> \"%s\"\n",
op->o_req_dn.bv_val, mdn.bv_val, 0 );
#endif /* !NEW_LOGGING */
break;
case REWRITE_REGEXEC_UNWILLING:
rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
rs->sr_text = "Operation not allowed";
send_ldap_result( op, rs );
return -1;
case REWRITE_REGEXEC_ERR:
rs->sr_err = LDAP_OTHER;
rs->sr_text = "Rewrite error";
send_ldap_result( op, rs );
if ( ldap_back_dn_massage( &dc, &op->o_req_dn, &mdn ) ) {
send_ldap_result( op, rs );
return -1;
}
......@@ -159,7 +137,7 @@ meta_back_add( Operation *op, SlapReply *rs )
continue;
}
ldap_back_map( &li->targets[ candidate ]->at_map,
ldap_back_map( &li->targets[ candidate ]->rwmap.rwm_at,
&a->a_desc->ad_cname, &mapped, BACKLDAP_MAP );
if ( mapped.bv_val == NULL || mapped.bv_val[0] == '\0' ) {
continue;
......@@ -179,8 +157,7 @@ meta_back_add( Operation *op, SlapReply *rs )
*/
if ( strcmp( a->a_desc->ad_type->sat_syntax->ssyn_oid,
SLAPD_DN_SYNTAX ) == 0 ) {
ldap_dnattr_rewrite( li->targets[ candidate ]->rwinfo,
a->a_vals, op->o_conn );
(void)ldap_dnattr_rewrite( &dc, a->a_vals );
}
for ( j = 0; a->a_vals[ j ].bv_val; j++ );
......
......@@ -125,10 +125,13 @@ struct metatarget {
struct berval pseudorootdn;
struct berval pseudorootpw;
#if 0
struct rewrite_info *rwinfo;
struct ldapmap oc_map;
struct ldapmap at_map;
#endif
struct ldaprwmap rwmap;
};
struct metadncache {
......
......@@ -236,35 +236,19 @@ meta_back_do_single_bind(
struct metainfo *li = ( struct metainfo * )op->o_bd->be_private;
struct berval mdn = { 0, NULL };
ber_int_t msgid;
dncookie dc;
/*
* Rewrite the bind dn if needed
*/
switch ( rewrite_session( li->targets[ candidate ]->rwinfo,
"bindDn", op->o_req_dn.bv_val,
lc->conn, &mdn.bv_val ) ) {
case REWRITE_REGEXEC_OK:
if ( mdn.bv_val == NULL ) {
mdn = op->o_req_dn;
} else {
mdn.bv_len = strlen( mdn.bv_val );
}
#ifdef NEW_LOGGING
LDAP_LOG( BACK_META, DETAIL1,
"[rw] bindDn: \"%s\" -> \"%s\"\n",
op->o_req_dn.bv_val, mdn.bv_val, 0 );
#else /* !NEW_LOGGING */
Debug( LDAP_DEBUG_ARGS,
"rw> bindDn: \"%s\" -> \"%s\"\n%s",
op->o_req_dn.bv_val, mdn.bv_val, "" );
#endif /* !NEW_LOGGING */
break;
case REWRITE_REGEXEC_UNWILLING:
return LDAP_UNWILLING_TO_PERFORM;
dc.rwmap = &li->targets[ candidate ]->rwmap;
dc.conn = op->o_conn;
dc.rs = rs;
dc.ctx = "bindDn";
case REWRITE_REGEXEC_ERR:
return LDAP_OTHER;
if ( ldap_back_dn_massage( &dc, &op->o_req_dn, &mdn ) ) {
send_ldap_result( op, rs );
return -1;
}
if ( op->o_ctrls ) {
......
......@@ -81,10 +81,12 @@ meta_back_compare( Operation *op, SlapReply *rs )
struct metainfo *li = ( struct metainfo * )op->o_bd->be_private;
struct metaconn *lc;
struct metasingleconn *lsc;
char *match = NULL, *err = NULL, *mmatch = NULL;
char *match = NULL, *err = NULL;
struct berval mmatch = { 0, NULL };
int candidates = 0, last = 0, i, count, rc;
int cres = LDAP_SUCCESS, rres = LDAP_SUCCESS;
int *msgid;
dncookie dc;
lc = meta_back_getconn( op, rs, META_OP_ALLOW_MULTIPLE,
&op->o_req_ndn, NULL );
......@@ -107,8 +109,12 @@ meta_back_compare( Operation *op, SlapReply *rs )
/*
* start an asynchronous compare for each candidate target
*/
dc.conn = op->o_conn;
dc.rs = rs;
dc.ctx = "compareDn";
for ( i = 0, lsc = lc->conns; !META_LAST(lsc); ++i, ++lsc ) {
char *mdn = NULL;
struct berval mdn = { 0, NULL };
struct berval mapped_attr = op->oq_compare.rs_ava->aa_desc->ad_cname;
struct berval mapped_value = op->oq_compare.rs_ava->aa_value;
......@@ -120,42 +126,22 @@ meta_back_compare( Operation *op, SlapReply *rs )
/*
* Rewrite the compare dn, if needed
*/
switch ( rewrite_session( li->targets[ i ]->rwinfo,
"compareDn",
op->o_req_dn.bv_val, op->o_conn, &mdn ) ) {
case REWRITE_REGEXEC_OK:
if ( mdn == NULL ) {
mdn = ( char * )op->o_req_dn.bv_val;
}
#ifdef NEW_LOGGING
LDAP_LOG( BACK_META, DETAIL1,
"[rw] compareDn: \"%s\" -> \"%s\"\n",
op->o_req_dn.bv_val, mdn, 0 );
#else /* !NEW_LOGGING */
Debug( LDAP_DEBUG_ARGS,
"rw> compareDn: \"%s\" -> \"%s\"\n",
op->o_req_dn.bv_val, mdn, 0 );
#endif /* !NEW_LOGGING */
dc.rwmap = &li->targets[ i ]->rwmap;
switch ( ldap_back_dn_massage( &dc, &op->o_req_dn, &mdn ) ) {
case LDAP_UNWILLING_TO_PERFORM:
rc = 1;
goto finish;
default:
break;
case REWRITE_REGEXEC_UNWILLING:
rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
rs->sr_text = "Operation not allowed";
send_ldap_result( op, rs );
return -1;
case REWRITE_REGEXEC_ERR:
rs->sr_err = LDAP_OTHER;
rs->sr_text = "Rewrite error";
send_ldap_result( op, rs );
return -1;
}
/*
* if attr is objectClass, try to remap the value
*/
if ( op->oq_compare.rs_ava->aa_desc == slap_schema.si_ad_objectClass ) {
ldap_back_map( &li->targets[ i ]->oc_map,
ldap_back_map( &li->targets[ i ]->rwmap.rwm_oc,
&op->oq_compare.rs_ava->aa_value,
&mapped_value, BACKLDAP_MAP );
......@@ -166,7 +152,7 @@ meta_back_compare( Operation *op, SlapReply *rs )
* else try to remap the attribute
*/
} else {
ldap_back_map( &li->targets[ i ]->at_map,
ldap_back_map( &li->targets[ i ]->rwmap.rwm_at,
&op->oq_compare.rs_ava->aa_desc->ad_cname,
&mapped_attr, BACKLDAP_MAP );
if ( mapped_attr.bv_val == NULL || mapped_attr.bv_val[0] == '\0' ) {
......@@ -179,10 +165,11 @@ meta_back_compare( Operation *op, SlapReply *rs )
* 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.bv_val,
mapped_attr.bv_val, mapped_value.bv_val );
if ( mdn != op->o_req_dn.bv_val ) {
free( mdn );
if ( mdn.bv_val != op->o_req_dn.bv_val ) {
free( mdn.bv_val );
mdn.bv_val = NULL;
}
if ( mapped_attr.bv_val != op->oq_compare.rs_ava->aa_desc->ad_cname.bv_val ) {
free( mapped_attr.bv_val );
......@@ -301,56 +288,28 @@ finish:;
*/
rres = cres;
} else if ( match != NULL ) {
/*
* At least one compare failed with matched portion,
* and none was successful
*/
switch ( rewrite_session( li->targets[ last ]->rwinfo,
"matchedDn", match, op->o_conn,
&mmatch ) ) {
case REWRITE_REGEXEC_OK:
if ( mmatch == NULL ) {
mmatch = ( char * )match;
}
#ifdef NEW_LOGGING
LDAP_LOG( BACK_META, DETAIL1,
"[rw] matchedDn: \"%s\" -> \"%s\"\n",
match, mmatch, 0 );
#else /* !NEW_LOGGING */
Debug( LDAP_DEBUG_ARGS, "rw> matchedDn:"
" \"%s\" -> \"%s\"\n",
match, mmatch, 0 );
#endif /* !NEW_LOGGING */
break;
case REWRITE_REGEXEC_UNWILLING:
rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
rs->sr_text = "Operation not allowed";
send_ldap_result( op, rs );
rc = -1;
goto cleanup;
case REWRITE_REGEXEC_ERR:
rs->sr_err = LDAP_OTHER;
rs->sr_text = "Rewrite error";
send_ldap_result( op, rs );
rc = -1;
goto cleanup;
}
} else if ( match != NULL && match[0] != '\0' ) {
struct berval matched;
matched.bv_val = match;
matched.bv_len = strlen( match );
dc.ctx = "matchedDn";
ldap_back_dn_massage( &dc, &matched, &mmatch );
}
rs->sr_err = rres;
rs->sr_matched = mmatch;
rs->sr_matched = mmatch.bv_val;
send_ldap_result( op, rs );
rs->sr_matched = NULL;
cleanup:;
if ( match != NULL ) {
if ( mmatch != match ) {
free( mmatch );
if ( mmatch.bv_val != match ) {
free( mmatch.bv_val );
}
free( match );
}
......
......@@ -88,13 +88,13 @@ new_target( void )
return NULL;
}
lt->rwinfo = rewrite_info_init( REWRITE_MODE_USE_DEFAULT );
if ( lt->rwinfo == NULL ) {
lt->rwmap.rwm_rw = rewrite_info_init( REWRITE_MODE_USE_DEFAULT );
if ( lt->rwmap.rwm_rw == NULL ) {
free( lt );
return NULL;
}
ldap_back_map_init( &lt->at_map, &mapping );
ldap_back_map_init( &lt->rwmap.rwm_at, &mapping );
return lt;
}
......@@ -499,7 +499,7 @@ meta_back_db_config(
* FIXME: no extra rewrite capabilities should be added
* to the database
*/
return suffix_massage_config( li->targets[ i ]->rwinfo,
return suffix_massage_config( li->targets[ i ]->rwmap.rwm_rw,
&pvnc, &nvnc, &prnc, &nrnc );
/* rewrite stuff ... */
......@@ -520,7 +520,7 @@ meta_back_db_config(
#endif /* LDAP_CACHING */
}
return rewrite_parse( li->targets[ i ]->rwinfo, fname, lineno,
return rewrite_parse( li->targets[ i ]->rwmap.rwm_rw, fname, lineno,
argc, argv );
/* objectclass/attribute mapping */
......@@ -534,8 +534,8 @@ meta_back_db_config(
return 1;
}
return ldap_back_map_config( &li->targets[ i ]->oc_map,
&li->targets[ i ]->at_map,
return ldap_back_map_config( &li->targets[ i ]->rwmap.rwm_oc,
&li->targets[ i ]->rwmap.rwm_at,
fname, lineno, argc, argv );
/* anything else */
} else {
......
......@@ -256,7 +256,7 @@ init_one_conn(
/*
* Sets a cookie for the rewrite session
*/
( void )rewrite_session_init( lt->rwinfo, op->o_conn );
( void )rewrite_session_init( lt->rwmap.rwm_rw, op->o_conn );
/*
* If the connection dn is not null, an attempt to rewrite it is made
......@@ -267,7 +267,7 @@ init_one_conn(
* Rewrite the bind dn if needed
*/
lsc->bound_dn.bv_val = NULL;
switch ( rewrite_session( lt->rwinfo, "bindDn",
switch ( rewrite_session( lt->rwmap.rwm_rw, "bindDn",
op->o_conn->c_dn.bv_val, op->o_conn,
&lsc->bound_dn.bv_val ) ) {
case REWRITE_REGEXEC_OK:
......
......@@ -81,8 +81,8 @@ meta_back_delete( Operation *op, SlapReply *rs )
struct metainfo *li = ( struct metainfo * )op->o_bd->be_private;
struct metaconn *lc;
int candidate = -1;
char *mdn = NULL;
struct berval mdn = { 0, NULL };
dncookie dc;
lc = meta_back_getconn( op, rs, META_OP_REQUIRE_SINGLE,
&op->o_req_ndn, &candidate );
......@@ -101,40 +101,20 @@ meta_back_delete( Operation *op, SlapReply *rs )
/*
* Rewrite the compare dn, if needed
*/
switch ( rewrite_session( li->targets[ candidate ]->rwinfo,
"deleteDn", op->o_req_dn.bv_val,
op->o_conn, &mdn ) ) {
case REWRITE_REGEXEC_OK:
if ( mdn == NULL ) {
mdn = ( char * )op->o_req_dn.bv_val;
}
#ifdef NEW_LOGGING
LDAP_LOG( BACK_META, DETAIL1,
"[rw] deleteDn: \"%s\" -> \"%s\"\n",
op->o_req_dn.bv_val, mdn, 0 );
#else /* !NEW_LOGGING */
Debug( LDAP_DEBUG_ARGS, "rw> deleteDn: \"%s\" -> \"%s\"\n",
op->o_req_dn.bv_val, mdn, 0 );
#endif /* !NEW_LOGGING */
break;
case REWRITE_REGEXEC_UNWILLING:
rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
rs->sr_text = "Operation not allowed";
send_ldap_result( op, rs );
return -1;
dc.rwmap = &li->targets[ candidate ]->rwmap;
dc.conn = op->o_conn;
dc.rs = rs;
dc.ctx = "deleteDn";
case REWRITE_REGEXEC_ERR:
rs->sr_err = LDAP_OTHER;
rs->sr_text = "Rewrite error";
if ( ldap_back_dn_massage( &dc, &op->o_req_dn, &mdn ) ) {
send_ldap_result( op, rs );
return -1;
}
ldap_delete_s( lc->conns[ candidate ].ld, mdn );
if ( mdn != op->o_req_dn.bv_val ) {
free( mdn );
ldap_delete_s( lc->conns[ candidate ].ld, mdn.bv_val );
if ( mdn.bv_val != op->o_req_dn.bv_val ) {
free( mdn.bv_val );
}
return meta_back_op_result( lc, op, rs );
......
......@@ -257,13 +257,13 @@ target_free(
if ( lt->pseudorootpw.bv_val ) {
free( lt->pseudorootpw.bv_val );
}
if ( lt->rwinfo ) {
rewrite_info_delete( lt->rwinfo );
if ( lt->rwmap.rwm_rw ) {
rewrite_info_delete( lt->rwmap.rwm_rw );
}
avl_free( lt->oc_map.remap, NULL );
avl_free( lt->oc_map.map, mapping_free );
avl_free( lt->at_map.remap, NULL );
avl_free( lt->at_map.map, mapping_free );
avl_free( lt->rwmap.rwm_oc.remap, NULL );
avl_free( lt->rwmap.rwm_oc.map, mapping_free );
avl_free( lt->rwmap.rwm_at.remap, NULL );
avl_free( lt->rwmap.rwm_at.map, mapping_free );
}
int
......
......@@ -85,8 +85,9 @@ meta_back_modify( Operation *op, SlapReply *rs )
LDAPMod *mods = NULL;
Modifications *ml;
int candidate = -1, i;
char *mdn;
struct berval mdn = { 0, NULL };
struct berval mapped;
dncookie dc;
lc = meta_back_getconn( op, rs, META_OP_REQUIRE_SINGLE,
&op->o_req_ndn, &candidate );
......@@ -105,32 +106,12 @@ meta_back_modify( Operation *op, SlapReply *rs )
/*
* Rewrite the modify dn, if needed
*/
switch ( rewrite_session( li->targets[ candidate ]->rwinfo,
"modifyDn", op->o_req_dn.bv_val,
op->o_conn, &mdn ) ) {
case REWRITE_REGEXEC_OK:
if ( mdn == NULL ) {
mdn = ( char * )op->o_req_dn.bv_val;
}
#ifdef NEW_LOGGING
LDAP_LOG( BACK_META, DETAIL1,
"[rw] modifyDn: \"%s\" -> \"%s\"\n",
op->o_req_dn.bv_val, mdn, 0 );
#else /* !NEW_LOGGING */
Debug( LDAP_DEBUG_ARGS, "rw> modifyDn: \"%s\" -> \"%s\"\n",
op->o_req_dn.bv_val, mdn, 0 );
#endif /* !NEW_LOGGING */
break;
case REWRITE_REGEXEC_UNWILLING:
rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
rs->sr_text = "Operation not allowed";
rc = -1;
goto cleanup;
dc.rwmap = &li->targets[ candidate ]->rwmap;
dc.conn = op->o_conn;
dc.rs = rs;
dc.ctx = "modifyDn";
case REWRITE_REGEXEC_ERR:
rs->sr_err = LDAP_OTHER;
rs->sr_text = "Rewrite error";
if ( ldap_back_dn_massage( &dc, &op->o_req_dn, &mdn ) ) {
rc = -1;
goto cleanup;
}
......@@ -151,6 +132,7 @@ meta_back_modify( Operation *op, SlapReply *rs )
goto cleanup;
}
dc.ctx = "modifyAttrDN";
for ( i = 0, ml = op->oq_modify.rs_modlist; ml; ml = ml->sml_next ) {
int j;
......@@ -158,7 +140,7 @@ meta_back_modify( Operation *op, SlapReply *rs )
continue;
}
ldap_back_map( &li->targets[ candidate ]->at_map,
ldap_back_map( &li->targets[ candidate ]->rwmap.rwm_at,
&ml->sml_desc->ad_cname, &mapped,
BACKLDAP_MAP );
if ( mapped.bv_val == NULL || mapped.bv_val[0] == '\0' ) {
......@@ -176,9 +158,7 @@ meta_back_modify( Operation *op, SlapReply *rs )
*/
if ( strcmp( ml->sml_desc->ad_type->sat_syntax->ssyn_oid,
SLAPD_DN_SYNTAX ) == 0 ) {
ldap_dnattr_rewrite(
li->targets[ candidate ]->rwinfo,
ml->sml_bvalues, op->o_conn );
( void )ldap_dnattr_rewrite( &dc, ml->sml_bvalues );
}
if ( ml->sml_bvalues != NULL ){
......@@ -197,11 +177,11 @@ meta_back_modify( Operation *op, SlapReply *rs )
}
modv[ i ] = 0;
ldap_modify_s( lc->conns[ candidate ].ld, mdn, modv );
ldap_modify_s( lc->conns[ candidate ].ld, mdn.bv_val, modv );
cleanup:;
if ( mdn != op->o_req_dn.bv_val ) {
free( mdn );
if ( mdn.bv_val != op->o_req_dn.bv_val ) {
free( mdn.bv_val );
}
if ( modv != NULL ) {
for ( i = 0; modv[ i ]; i++) {
......
......@@ -141,7 +141,7 @@ meta_back_modrdn( Operation *op, SlapReply *rs )
/*
* Rewrite the new superior, if defined and required
*/
switch ( rewrite_session( li->targets[ nsCandidate ]->rwinfo,
switch ( rewrite_session( li->targets[ nsCandidate ]->rwmap.rwm_rw,
"newSuperiorDn",
op->oq_modrdn.rs_newSup->bv_val,
op->o_conn,
......@@ -179,7 +179,7 @@ meta_back_modrdn( Operation *op, SlapReply *rs )
/*
* Rewrite the modrdn dn, if required
*/
switch ( rewrite_session( li->targets[ candidate ]->rwinfo,
switch ( rewrite_session( li->targets[ candidate ]->rwmap.rwm_rw,
"modrDn", op->o_req_dn.bv_val,
op->o_conn, &mdn ) ) {
case REWRITE_REGEXEC_OK:
......
......@@ -111,6 +111,7 @@ meta_back_search( Operation *op, SlapReply *rs )
int i, last = 0, candidates = 0;
struct slap_limits_set *limit = NULL;
int isroot = 0;
dncookie dc;
#ifdef LDAP_CACHING
cache_manager* cm = li->cm;
......@@ -205,15 +206,19 @@ meta_back_search( Operation *op, SlapReply *rs )
/* negative hard limit means no limit */
}
dc.conn = op->o_conn;
dc.rs = rs;
/*
* Inits searches
*/
for ( i = 0, lsc = lc->conns; !META_LAST(lsc); ++i, ++lsc ) {
char *realbase = ( char * )op->o_req_dn.bv_val;
struct berval realbase = op->o_req_dn;
int realscope = op->oq_search.rs_scope;
ber_len_t suffixlen = 0;
char *mbase = NULL;
struct berval mfilter = { 0L, NULL };
struct berval mbase = { 0, NULL };
struct berval mfilter = { 0, NULL };
char **mapped_attrs = NULL;
if ( lsc->candidate != META_CANDIDATE ) {
......@@ -235,6 +240,8 @@ meta_back_search( Operation *op, SlapReply *rs )
( void * )&op->oq_search.rs_slimit);
}
dc.rwmap = &li->targets[ i ]->rwmap;
/*
* modifies the base according to the scope, if required
*/
......@@ -250,7 +257,7 @@ meta_back_search( Operation *op, SlapReply *rs )
*/
if ( dnIsSuffix( &li->targets[ i ]->suffix,
&op->o_req_ndn ) ) {
realbase = li->targets[ i ]->suffix.bv_val;
realbase = li->targets[ i ]->suffix;
} else {