Commit 81c616fd authored by Pierangelo Masarati's avatar Pierangelo Masarati
Browse files

works fine now

parent 6118cb4c
...@@ -83,7 +83,7 @@ meta_back_compare( Operation *op, SlapReply *rs ) ...@@ -83,7 +83,7 @@ meta_back_compare( Operation *op, SlapReply *rs )
struct metasingleconn *lsc; struct metasingleconn *lsc;
char *match = NULL, *err = NULL; char *match = NULL, *err = NULL;
struct berval mmatch = { 0, NULL }; struct berval mmatch = { 0, NULL };
int candidates = 0, last = 0, i, count, rc; int candidates = 0, last = 0, i, count = 0, rc;
int cres = LDAP_SUCCESS, rres = LDAP_SUCCESS; int cres = LDAP_SUCCESS, rres = LDAP_SUCCESS;
int *msgid; int *msgid;
dncookie dc; dncookie dc;
......
...@@ -228,6 +228,7 @@ init_one_conn( ...@@ -228,6 +228,7 @@ init_one_conn(
) )
{ {
int vers; int vers;
dncookie dc;
/* /*
* Already init'ed * Already init'ed
...@@ -262,51 +263,16 @@ init_one_conn( ...@@ -262,51 +263,16 @@ init_one_conn(
* If the connection dn is not null, an attempt to rewrite it is made * If the connection dn is not null, an attempt to rewrite it is made
*/ */
if ( op->o_conn->c_dn.bv_len != 0 ) { if ( op->o_conn->c_dn.bv_len != 0 ) {
dc.rwmap = &lt->rwmap;
dc.conn = op->o_conn;
dc.rs = rs;
dc.ctx = "bindDn";
/* /*
* Rewrite the bind dn if needed * Rewrite the bind dn if needed
*/ */
lsc->bound_dn.bv_val = NULL; if ( ldap_back_dn_massage( &dc, &op->o_conn->c_dn, &lsc->bound_dn) ) {
switch ( rewrite_session( lt->rwmap.rwm_rw, "bindDn", send_ldap_result( op, rs );
op->o_conn->c_dn.bv_val, op->o_conn,
&lsc->bound_dn.bv_val ) ) {
case REWRITE_REGEXEC_OK:
if ( lsc->bound_dn.bv_val == NULL ) {
ber_dupbv( &lsc->bound_dn, &op->o_conn->c_dn );
}
#ifdef NEW_LOGGING
LDAP_LOG( BACK_META, DETAIL1,
"[rw] bindDn: \"%s\" -> \"%s\"\n",
op->o_conn->c_dn.bv_val,
lsc->bound_dn.bv_val, 0 );
#else /* !NEW_LOGGING */
Debug( LDAP_DEBUG_ARGS,
"rw> bindDn: \"%s\" -> \"%s\"\n",
op->o_conn->c_dn.bv_val,
lsc->bound_dn.bv_val, 0 );
#endif /* !NEW_LOGGING */
break;
case REWRITE_REGEXEC_UNWILLING:
rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
rs->sr_text = "Operation not allowed";
#if 0
send_ldap_result( conn, op,
LDAP_UNWILLING_TO_PERFORM,
NULL, "Operation not allowed",
NULL, NULL );
#endif
return rs->sr_err;
case REWRITE_REGEXEC_ERR:
rs->sr_err = LDAP_OTHER;
rs->sr_text = "Rewrite error";
#if 0
send_ldap_result( conn, op,
LDAP_OTHER,
NULL, "Rewrite error",
NULL, NULL );
#endif
return rs->sr_err; return rs->sr_err;
} }
......
...@@ -94,8 +94,9 @@ meta_back_modrdn( Operation *op, SlapReply *rs ) ...@@ -94,8 +94,9 @@ meta_back_modrdn( Operation *op, SlapReply *rs )
struct metaconn *lc; struct metaconn *lc;
int rc = 0; int rc = 0;
int candidate = -1; int candidate = -1;
char *mdn = NULL, struct berval mdn = { 0, NULL },
*mnewSuperior = NULL; mnewSuperior = { 0, NULL };
dncookie dc;
lc = meta_back_getconn( op, rs, META_OP_REQUIRE_SINGLE, lc = meta_back_getconn( op, rs, META_OP_REQUIRE_SINGLE,
&op->o_req_ndn, &candidate ); &op->o_req_ndn, &candidate );
...@@ -111,6 +112,9 @@ meta_back_modrdn( Operation *op, SlapReply *rs ) ...@@ -111,6 +112,9 @@ meta_back_modrdn( Operation *op, SlapReply *rs )
goto cleanup; goto cleanup;
} }
dc.conn = op->o_conn;
dc.rs = rs;
if ( op->oq_modrdn.rs_newSup ) { if ( op->oq_modrdn.rs_newSup ) {
int nsCandidate, version = LDAP_VERSION3; int nsCandidate, version = LDAP_VERSION3;
...@@ -137,40 +141,13 @@ meta_back_modrdn( Operation *op, SlapReply *rs ) ...@@ -137,40 +141,13 @@ meta_back_modrdn( Operation *op, SlapReply *rs )
ldap_set_option( lc->conns[ nsCandidate ].ld, ldap_set_option( lc->conns[ nsCandidate ].ld,
LDAP_OPT_PROTOCOL_VERSION, &version ); LDAP_OPT_PROTOCOL_VERSION, &version );
/* /*
* Rewrite the new superior, if defined and required * Rewrite the new superior, if defined and required
*/ */
switch ( rewrite_session( li->targets[ nsCandidate ]->rwmap.rwm_rw, dc.rwmap = &li->targets[ nsCandidate ]->rwmap;
"newSuperiorDn", dc.ctx = "newSuperiorDN";
op->oq_modrdn.rs_newSup->bv_val, if ( ldap_back_dn_massage( &dc, op->oq_modrdn.rs_newSup, &mnewSuperior ) ) {
op->o_conn,
&mnewSuperior ) ) {
case REWRITE_REGEXEC_OK:
if ( mnewSuperior == NULL ) {
mnewSuperior = ( char * )op->oq_modrdn.rs_newSup;
}
#ifdef NEW_LOGGING
LDAP_LOG( BACK_META, DETAIL1,
"[rw] newSuperiorDn: \"%s\" -> \"%s\"\n",
op->oq_modrdn.rs_newSup, mnewSuperior, 0 );
#else /* !NEW_LOGGING */
Debug( LDAP_DEBUG_ARGS, "rw> newSuperiorDn:"
" \"%s\" -> \"%s\"\n",
op->oq_modrdn.rs_newSup->bv_val,
mnewSuperior, 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;
case REWRITE_REGEXEC_ERR:
rs->sr_err = LDAP_OTHER;
rs->sr_text = "Rewrite error";
rc = -1; rc = -1;
goto cleanup; goto cleanup;
} }
...@@ -179,48 +156,26 @@ meta_back_modrdn( Operation *op, SlapReply *rs ) ...@@ -179,48 +156,26 @@ meta_back_modrdn( Operation *op, SlapReply *rs )
/* /*
* Rewrite the modrdn dn, if required * Rewrite the modrdn dn, if required
*/ */
switch ( rewrite_session( li->targets[ candidate ]->rwmap.rwm_rw, dc.rwmap = &li->targets[ candidate ]->rwmap;
"modrDn", op->o_req_dn.bv_val, dc.ctx = "modrDN";
op->o_conn, &mdn ) ) { if ( ldap_back_dn_massage( &dc, &op->o_req_dn, &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] modrDn: \"%s\" -> \"%s\"\n",
op->o_req_dn.bv_val, mdn, 0 );
#else /* !NEW_LOGGING */
Debug( LDAP_DEBUG_ARGS, "rw> modrDn: \"%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;
case REWRITE_REGEXEC_ERR:
rs->sr_err = LDAP_OTHER;
rs->sr_text = "Rewrite error";
rc = -1; rc = -1;
goto cleanup; goto cleanup;
} }
ldap_rename2_s( lc->conns[ candidate ].ld, mdn, ldap_rename2_s( lc->conns[ candidate ].ld, mdn.bv_val,
op->oq_modrdn.rs_newrdn.bv_val, op->oq_modrdn.rs_newrdn.bv_val,
mnewSuperior, op->oq_modrdn.rs_deleteoldrdn ); mnewSuperior.bv_val,
op->oq_modrdn.rs_deleteoldrdn );
cleanup:; cleanup:;
if ( mdn != op->o_req_dn.bv_val ) { if ( mdn.bv_val != op->o_req_dn.bv_val ) {
free( mdn ); free( mdn.bv_val );
} }
if ( mnewSuperior != NULL if ( mnewSuperior.bv_val != NULL
&& mnewSuperior != op->oq_modrdn.rs_newSup->bv_val ) { && mnewSuperior.bv_val != op->oq_modrdn.rs_newSup->bv_val ) {
free( mnewSuperior ); free( mnewSuperior.bv_val );
} }
if ( rc == 0 ) { if ( rc == 0 ) {
......
...@@ -104,8 +104,8 @@ meta_back_search( Operation *op, SlapReply *rs ) ...@@ -104,8 +104,8 @@ meta_back_search( Operation *op, SlapReply *rs )
struct timeval tv = { 0, 0 }; struct timeval tv = { 0, 0 };
LDAPMessage *res, *e; LDAPMessage *res, *e;
int rc = 0, *msgid, sres = LDAP_NO_SUCH_OBJECT; int rc = 0, *msgid, sres = LDAP_NO_SUCH_OBJECT;
char *match = NULL, *err = NULL; char *err = NULL;
char *mmatch = NULL; struct berval match = { 0, NULL }, mmatch = { 0, NULL };
BerVarray v2refs = NULL; BerVarray v2refs = NULL;
int i, last = 0, candidates = 0; int i, last = 0, candidates = 0;
...@@ -513,22 +513,22 @@ new_candidate:; ...@@ -513,22 +513,22 @@ new_candidate:;
} }
ldap_get_option( lsc->ld, ldap_get_option( lsc->ld,
LDAP_OPT_ERROR_STRING, &err ); LDAP_OPT_ERROR_STRING, &err );
if ( match != NULL ) { if ( match.bv_val != NULL ) {
free( match ); free( match.bv_val );
} }
ldap_get_option( lsc->ld, ldap_get_option( lsc->ld,
LDAP_OPT_MATCHED_DN, &match ); LDAP_OPT_MATCHED_DN, &match.bv_val );
#ifdef NEW_LOGGING #ifdef NEW_LOGGING
LDAP_LOG( BACK_META, ERR, LDAP_LOG( BACK_META, ERR,
"meta_back_search [%d] " "meta_back_search [%d] "
"match=\"%s\" err=\"%s\"\n", "match=\"%s\" err=\"%s\"\n",
i, match, err ); i, match.bv_val, err );
#else /* !NEW_LOGGING */ #else /* !NEW_LOGGING */
Debug( LDAP_DEBUG_ANY, Debug( LDAP_DEBUG_ANY,
"=>meta_back_search [%d] " "=>meta_back_search [%d] "
"match=\"%s\" err=\"%s\"\n", "match=\"%s\" err=\"%s\"\n",
i, match, err ); i, match.bv_val, err );
#endif /* !NEW_LOGGING */ #endif /* !NEW_LOGGING */
last = i; last = i;
...@@ -570,31 +570,12 @@ new_candidate:; ...@@ -570,31 +570,12 @@ new_candidate:;
* *
* FIXME: only the last one gets caught! * FIXME: only the last one gets caught!
*/ */
if ( match != NULL ) { if ( match.bv_val != NULL && *match.bv_val ) {
switch ( rewrite_session( li->targets[ last ]->rwmap.rwm_rw, dc.ctx = "matchedDn";
"matchedDn", match, op->o_conn, dc.rwmap = &li->targets[ last ]->rwmap;
&mmatch ) ) {
case REWRITE_REGEXEC_OK: if ( ldap_back_dn_massage( &dc, &match, &mmatch ) ) {
if ( mmatch == NULL ) { mmatch.bv_val = 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:
case REWRITE_REGEXEC_ERR:
/* FIXME: no error, but no matched ... */
mmatch = NULL;
break;
} }
} }
...@@ -609,7 +590,7 @@ new_candidate:; ...@@ -609,7 +590,7 @@ new_candidate:;
sres = LDAP_REFERRAL; sres = LDAP_REFERRAL;
} }
rs->sr_err = sres; rs->sr_err = sres;
rs->sr_matched = mmatch; rs->sr_matched = mmatch.bv_val;
rs->sr_v2ref = v2refs; rs->sr_v2ref = v2refs;
send_ldap_result( op, rs ); send_ldap_result( op, rs );
rs->sr_matched = NULL; rs->sr_matched = NULL;
...@@ -617,11 +598,11 @@ new_candidate:; ...@@ -617,11 +598,11 @@ new_candidate:;
finish:; finish:;
if ( match ) { if ( match.bv_val ) {
if ( mmatch != match ) { if ( mmatch.bv_val != match.bv_val ) {
free( mmatch ); free( mmatch.bv_val );
} }
free(match); free( match.bv_val );
} }
if ( err ) { if ( err ) {
...@@ -695,6 +676,7 @@ meta_send_entry( ...@@ -695,6 +676,7 @@ meta_send_entry(
ent.e_private = 0; ent.e_private = 0;
attrp = &ent.e_attrs; attrp = &ent.e_attrs;
dc.ctx = "searchAttrDN";
while ( ber_scanf( &ber, "{m", &a ) != LBER_ERROR ) { while ( ber_scanf( &ber, "{m", &a ) != LBER_ERROR ) {
ldap_back_map( &li->targets[ target ]->rwmap.rwm_at, ldap_back_map( &li->targets[ target ]->rwmap.rwm_at,
&a, &mapped, BACKLDAP_REMAP ); &a, &mapped, BACKLDAP_REMAP );
...@@ -727,6 +709,16 @@ meta_send_entry( ...@@ -727,6 +709,16 @@ meta_send_entry(
/* no subschemaSubentry */ /* no subschemaSubentry */
if ( attr->a_desc == slap_schema.si_ad_subschemaSubentry ) { if ( attr->a_desc == slap_schema.si_ad_subschemaSubentry ) {
/*
* We eat target's subschemaSubentry because
* a search for this value is likely not
* to resolve to the appropriate backend;
* later, the local subschemaSubentry is
* added.
*/
( void )ber_scanf( &ber, "x" /* [W] */ );
ch_free(attr); ch_free(attr);
continue; continue;
} }
...@@ -770,61 +762,9 @@ meta_send_entry( ...@@ -770,61 +762,9 @@ meta_send_entry(
* ACLs to the target directory server, and letting * ACLs to the target directory server, and letting
* everything pass thru the ldap backend. * everything pass thru the ldap backend.
*/ */
} else if ( strcmp( attr->a_desc->ad_type->sat_syntax->ssyn_oid, } else if ( attr->a_desc->ad_type->sat_syntax ==
SLAPD_DN_SYNTAX ) == 0 ) { slap_schema.si_syn_distinguishedName ) {
int last; ldap_dnattr_result_rewrite( &dc, attr->a_vals );
for ( last = 0; attr->a_vals[ last ].bv_val; ++last );
for ( bv = attr->a_vals; bv->bv_val; bv++ ) {
char *newval;
switch ( rewrite_session( li->targets[ target ]->rwmap.rwm_rw,
"searchResult",
bv->bv_val,
lc->conn, &newval )) {
case REWRITE_REGEXEC_OK:
/* left as is */
if ( newval == NULL ) {
break;
}
#ifdef NEW_LOGGING
LDAP_LOG( BACK_META, DETAIL1,
"[rw] searchResult on attr=%s: \"%s\" -> \"%s\"\n",
attr->a_desc->ad_type->sat_cname.bv_val,
bv->bv_val, newval );
#else /* !NEW_LOGGING */
Debug( LDAP_DEBUG_ARGS,
"rw> searchResult on attr=%s:"
" \"%s\" -> \"%s\"\n",
attr->a_desc->ad_type->sat_cname.bv_val,
bv->bv_val, newval );
#endif /* !NEW_LOGGING */
free( bv->bv_val );
bv->bv_val = newval;
bv->bv_len = strlen( newval );
break;
case REWRITE_REGEXEC_UNWILLING:
LBER_FREE(bv->bv_val);
bv->bv_val = NULL;
if (--last < 0)
goto next_attr;
*bv = attr->a_vals[last];
attr->a_vals[last].bv_val = NULL;
bv--;
break;
case REWRITE_REGEXEC_ERR:
/*
* FIXME: better give up,
* skip the attribute
* or leave it untouched?
*/
break;
}
}
} }
next_attr:; next_attr:;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment