/*
* 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
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 ) {
BerVarray a_vals
)
{
- struct berval bv;
-
- for ( ; a_vals->bv_val != NULL; a_vals++ ) {
- ldap_back_dn_massage( dc, a_vals, &bv );
-
- /* 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;
+ struct berval bv;
+ int i, last;
+
+ for ( last = 0; a_vals[last].bv_val != NULL; last++ );
+ last--;
+
+ 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;
}
}
/* 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
/*
* 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
/*
* 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";
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
/*
* 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
/*
* 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
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
/*
* 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
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
/*
* 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
/*
* 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
*/
} 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;
}
}
}
/*
* 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
{
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;
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:
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:
dc->rs->sr_err = LDAP_OTHER;
dc->rs->sr_text = "Rewrite error";
}
- rc = -1;
+ rc = LDAP_OTHER;
break;
}
return rc;