use rewrite info instead of ldapinfo for reusability in back-meta; will change soon

This commit is contained in:
Pierangelo Masarati 2003-04-07 12:53:00 +00:00
parent c823f9a995
commit 77c4389f55
10 changed files with 89 additions and 31 deletions

View File

@ -74,12 +74,13 @@ ldap_back_add(
/*
* Rewrite the add dn, if needed
*/
dc.li = li;
#ifdef ENABLE_REWRITE
dc.rw = li->rwinfo;
dc.conn = op->o_conn;
dc.rs = rs;
dc.ctx = "addDn";
#else
dc.li = li;
dc.tofrom = 1;
dc.normalized = 0;
#endif
@ -96,7 +97,7 @@ ldap_back_add(
attrs = (LDAPMod **)ch_malloc(sizeof(LDAPMod *)*i);
#ifdef ENABLE_REWRITE
dc.ctx = "addAttrDN";
dc.ctx = "addDnAttr";
#endif
for (i=0, a=op->oq_add.rs_e->e_attrs; a; a=a->a_next) {
if ( a->a_desc->ad_type->sat_no_user_mod ) {
@ -155,15 +156,38 @@ ldap_dnattr_rewrite(
BerVarray a_vals
)
{
struct berval bv;
struct berval bv;
int i, last;
for ( ; a_vals->bv_val != NULL; a_vals++ ) {
ldap_back_dn_massage( dc, a_vals, &bv );
for ( last = 0; a_vals[last].bv_val != NULL; last++ );
last--;
/* leave attr untouched if massage failed */
if ( bv.bv_val && bv.bv_val != a_vals->bv_val ) {
ch_free( a_vals->bv_val );
*a_vals = bv;
for ( i = 0; a_vals[i].bv_val != NULL; i++ ) {
switch ( ldap_back_dn_massage( dc, &a_vals[i], &bv ) ) {
case LDAP_SUCCESS:
case LDAP_OTHER: /* ? */
default: /* ??? */
/* leave attr untouched if massage failed */
if ( bv.bv_val && bv.bv_val != a_vals[i].bv_val ) {
ch_free( a_vals[i].bv_val );
a_vals[i] = bv;
}
break;
case LDAP_UNWILLING_TO_PERFORM:
/*
* FIXME: need to check if it may be considered
* legal to trim values when adding/modifying;
* it should be when searching (see ACLs).
*/
ch_free( a_vals[i].bv_val );
if (last > i ) {
a_vals[i] = a_vals[last];
}
a_vals[last].bv_len = 0;
a_vals[last].bv_val = NULL;
last--;
break;
}
}

View File

@ -100,12 +100,13 @@ int back_ldap_LTX_init_module(int argc, char *argv[]);
/* Whatever context ldap_back_dn_massage needs... */
typedef struct dncookie {
struct ldapinfo *li;
#ifdef ENABLE_REWRITE
struct rewrite_info *rw;
Connection *conn;
char *ctx;
SlapReply *rs;
#else
struct ldapinfo *li;
int normalized;
int tofrom;
#endif

View File

@ -72,12 +72,13 @@ ldap_back_bind(
/*
* Rewrite the bind dn if needed
*/
dc.li = li;
#ifdef ENABLE_REWRITE
dc.rw = li->rwinfo;
dc.conn = op->o_conn;
dc.rs = rs;
dc.ctx = "bindDn";
#else
dc.li = li;
dc.tofrom = 1;
dc.normalized = 0;
#endif
@ -311,8 +312,8 @@ ldap_back_getconn(Operation *op, SlapReply *rs)
/*
* Rewrite the bind dn if needed
*/
dc.li = li;
#ifdef ENABLE_REWRITE
dc.rw = li->rwinfo;
dc.conn = op->o_conn;
dc.rs = rs;
dc.ctx = "bindDn";
@ -502,12 +503,13 @@ ldap_back_op_result(struct ldapconn *lc, Operation *op, SlapReply *rs,
struct berval dn, mdn;
dncookie dc;
dc.li = li;
#ifdef ENABLE_REWRITE
dc.rw = li->rwinfo;
dc.conn = op->o_conn;
dc.rs = rs;
dc.ctx = "matchedDn";
#else
dc.li = li;
dc.tofrom = 0;
dc.normalized = 0;
#endif

View File

@ -66,12 +66,13 @@ ldap_back_compare(
/*
* Rewrite the compare dn, if needed
*/
dc.li = li;
#ifdef ENABLE_REWRITE
dc.rw = li->rwinfo;
dc.conn = op->o_conn;
dc.rs = rs;
dc.ctx = "compareDn";
#else
dc.li = li;
dc.tofrom = 1;
dc.normalized = 0;
#endif

View File

@ -66,12 +66,13 @@ ldap_back_delete(
/*
* Rewrite the request dn, if needed
*/
dc.li = li;
#ifdef ENABLE_REWRITE
dc.rw = li->rwinfo;
dc.conn = op->o_conn;
dc.rs = rs;
dc.ctx = "deleteDn";
#else
dc.li = li;
dc.tofrom = 1;
dc.normalized = 0;
#endif

View File

@ -85,12 +85,13 @@ ldap_back_exop_passwd(
return LDAP_UNWILLING_TO_PERFORM;
}
if (id.bv_len) {
dc.li = li;
#ifdef ENABLE_REWRITE
dc.rw = li->rwinfo;
dc.conn = op->o_conn;
dc.rs = rs;
dc.ctx = "modifyPwd";
#else
dc.li = li;
dc.tofrom = 1;
dc.normalized = 0;
#endif

View File

@ -69,12 +69,13 @@ ldap_back_modify(
/*
* Rewrite the modify dn, if needed
*/
dc.li = li;
#ifdef ENABLE_REWRITE
dc.rw = li->rwinfo;
dc.conn = op->o_conn;
dc.rs = rs;
dc.ctx = "modifyDn";
#else
dc.li = li;
dc.tofrom = 1;
dc.normalized = 0;
#endif

View File

@ -62,11 +62,12 @@ ldap_back_modrdn(
return( -1 );
}
dc.li = li;
#ifdef ENABLE_REWRITE
dc.rw = li->rwinfo;
dc.conn = op->o_conn;
dc.rs = rs;
#else
dc.li = li;
dc.tofrom = 1;
dc.normalized = 0;
#endif

View File

@ -147,12 +147,13 @@ ldap_back_search(
/*
* Rewrite the search base, if required
*/
dc.li = li;
#ifdef ENABLE_REWRITE
dc.rw = li->rwinfo;
dc.conn = op->o_conn;
dc.rs = rs;
dc.ctx = "searchBase";
#else
dc.li = li;
dc.tofrom = 1;
dc.normalized = 0;
#endif
@ -392,12 +393,13 @@ ldap_build_entry(
/*
* Rewrite the dn of the result, if needed
*/
dc.li = li;
#ifdef ENABLE_REWRITE
dc.rw = li->rwinfo;
dc.conn = op->o_conn;
dc.rs = NULL;
dc.ctx = "searchResult";
#else
dc.li = li;
dc.tofrom = 0;
dc.normalized = 0;
#endif
@ -523,13 +525,35 @@ ldap_build_entry(
*/
} else if ( attr->a_desc->ad_type->sat_syntax ==
slap_schema.si_syn_distinguishedName ) {
for ( bv = attr->a_vals; bv->bv_val; bv++ ) {
struct berval newval = {0,NULL};
ldap_back_dn_massage( &dc, bv, &newval );
if ( newval.bv_val && bv->bv_val != newval.bv_val ) {
int last, i;
/*
* FIXME: should use ldap_dnattr_rewrite(),
* but need a different free() callback ...
*/
for ( last = 0; attr->a_vals[last].bv_val; last++ );
for ( i = 0; attr->a_vals[i].bv_val; i++ ) {
struct berval newval = { 0, NULL };
bv = &attr->a_vals[i];
switch ( ldap_back_dn_massage( &dc, bv, &newval ) ) {
case LDAP_UNWILLING_TO_PERFORM:
LBER_FREE( bv->bv_val );
*bv = newval;
if ( last > i ) {
*bv = attr->a_vals[last];
}
attr->a_vals[last].bv_val = NULL;
last--;
break;
default:
if ( newval.bv_val && bv->bv_val != newval.bv_val ) {
LBER_FREE( bv->bv_val );
*bv = newval;
}
break;
}
}
}
@ -602,12 +626,13 @@ ldap_back_entry_get(
/*
* Rewrite the search base, if required
*/
dc.li = li;
#ifdef ENABLE_REWRITE
dc.rw = li->rwinfo;
dc.conn = op->o_conn;
dc.rs = &rs;
dc.ctx = "searchBase";
#else
dc.li = li;
dc.tofrom = 1;
dc.normalized = 1;
#endif

View File

@ -47,10 +47,10 @@ ldap_back_dn_massage(
{
int rc = 0;
switch (rewrite_session( dc->li->rwinfo, dc->ctx, dn->bv_val, dc->conn,
switch (rewrite_session( dc->rw, dc->ctx, dn->bv_val, dc->conn,
&res->bv_val )) {
case REWRITE_REGEXEC_OK:
if ( res->bv_val != NULL && res->bv_val[ 0 ] != '\0' ) {
if ( res->bv_val != NULL ) {
res->bv_len = strlen( res->bv_val );
} else {
*res = *dn;
@ -62,6 +62,7 @@ ldap_back_dn_massage(
Debug( LDAP_DEBUG_ARGS,
"[rw] %s: \"%s\" -> \"%s\"\n", dc->ctx, dn->bv_val, res->bv_val );
#endif /* !NEW_LOGGING */
rc = LDAP_SUCCESS;
break;
case REWRITE_REGEXEC_UNWILLING:
@ -69,7 +70,7 @@ ldap_back_dn_massage(
dc->rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
dc->rs->sr_text = "Operation not allowed";
}
rc = -1;
rc = LDAP_UNWILLING_TO_PERFORM;
break;
case REWRITE_REGEXEC_ERR:
@ -77,7 +78,7 @@ ldap_back_dn_massage(
dc->rs->sr_err = LDAP_OTHER;
dc->rs->sr_text = "Rewrite error";
}
rc = -1;
rc = LDAP_OTHER;
break;
}
return rc;