From 93abccdee3bfba64079dce8ba6f2e13cd117059f Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Mon, 7 Apr 2003 16:52:59 +0000 Subject: [PATCH] group rewrite/map stuff in one structure and optimize more function calls --- servers/slapd/back-ldap/add.c | 5 +- servers/slapd/back-ldap/back-ldap.h | 51 ++++-- servers/slapd/back-ldap/bind.c | 10 +- servers/slapd/back-ldap/compare.c | 10 +- servers/slapd/back-ldap/config.c | 9 +- servers/slapd/back-ldap/delete.c | 3 +- servers/slapd/back-ldap/extended.c | 3 +- servers/slapd/back-ldap/init.c | 19 +- servers/slapd/back-ldap/map.c | 223 +++--------------------- servers/slapd/back-ldap/modify.c | 65 +++++-- servers/slapd/back-ldap/modrdn.c | 3 +- servers/slapd/back-ldap/search.c | 32 ++-- servers/slapd/back-ldap/suffixmassage.c | 2 +- servers/slapd/back-ldap/unbind.c | 2 +- 14 files changed, 150 insertions(+), 287 deletions(-) diff --git a/servers/slapd/back-ldap/add.c b/servers/slapd/back-ldap/add.c index a9be70d466..f4cf8af1e9 100644 --- a/servers/slapd/back-ldap/add.c +++ b/servers/slapd/back-ldap/add.c @@ -74,13 +74,12 @@ ldap_back_add( /* * Rewrite the add dn, if needed */ + dc.rwmap = &li->rwmap; #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 @@ -104,7 +103,7 @@ ldap_back_add( continue; } - ldap_back_map(&li->at_map, &a->a_desc->ad_cname, &mapped, + ldap_back_map(&li->rwmap.rwm_at, &a->a_desc->ad_cname, &mapped, BACKLDAP_MAP); if (mapped.bv_val == NULL || mapped.bv_val[0] == '\0') { continue; diff --git a/servers/slapd/back-ldap/back-ldap.h b/servers/slapd/back-ldap/back-ldap.h index 3ef2f6d68b..d605d694f8 100644 --- a/servers/slapd/back-ldap/back-ldap.h +++ b/servers/slapd/back-ldap/back-ldap.h @@ -73,6 +73,25 @@ struct ldapmapping { struct berval dst; }; +struct ldaprwmap { + /* + * DN rewriting + */ +#ifdef ENABLE_REWRITE + struct rewrite_info *rwm_rw; +#else /* !ENABLE_REWRITE */ + /* some time the suffix massaging without librewrite + * will be disabled */ + BerVarray rwm_suffix_massage; +#endif /* !ENABLE_REWRITE */ + + /* + * Attribute/objectClass mapping + */ + struct ldapmap rwm_oc; + struct ldapmap rwm_at; +}; + struct ldapinfo { struct slap_backend_db *be; char *url; @@ -81,6 +100,8 @@ struct ldapinfo { ldap_pvt_thread_mutex_t conn_mutex; int savecred; Avlnode *conntree; + +#if 0 #ifdef ENABLE_REWRITE struct rewrite_info *rwinfo; #else /* !ENABLE_REWRITE */ @@ -89,29 +110,32 @@ struct ldapinfo { struct ldapmap oc_map; struct ldapmap at_map; -}; +#endif -struct ldapconn *ldap_back_getconn(struct slap_op *op, struct slap_rep *rs); -int ldap_back_dobind(struct ldapconn *lc, Operation *op, SlapReply *rs); -int ldap_back_map_result(SlapReply *rs); -int ldap_back_op_result(struct ldapconn *lc, Operation *op, SlapReply *rs, - ber_int_t msgid, int sendok); -int back_ldap_LTX_init_module(int argc, char *argv[]); + struct ldaprwmap rwmap; +}; /* Whatever context ldap_back_dn_massage needs... */ typedef struct dncookie { + struct ldaprwmap *rwmap; + #ifdef ENABLE_REWRITE - struct rewrite_info *rw; Connection *conn; char *ctx; SlapReply *rs; #else - struct ldapinfo *li; int normalized; int tofrom; #endif } dncookie; +struct ldapconn *ldap_back_getconn(struct slap_op *op, struct slap_rep *rs); +int ldap_back_dobind(struct ldapconn *lc, Operation *op, SlapReply *rs); +int ldap_back_map_result(SlapReply *rs); +int ldap_back_op_result(struct ldapconn *lc, Operation *op, SlapReply *rs, + ber_int_t msgid, int sendok); +int back_ldap_LTX_init_module(int argc, char *argv[]); + int ldap_back_dn_massage(dncookie *dc, struct berval *dn, struct berval *res); @@ -155,13 +179,8 @@ extern int ldap_back_map_config( char **argv ); extern int -ldap_back_filter_map_rewrite_( -#ifdef ENABLE_REWRITE - struct rewrite_info *info, - void *cookie, -#endif /* ENABLE_REWRITE */ - struct ldapmap *at_map, - struct ldapmap *oc_map, +ldap_back_filter_map_rewrite( + dncookie *dc, Filter *f, struct berval *fstr, int remap ); diff --git a/servers/slapd/back-ldap/bind.c b/servers/slapd/back-ldap/bind.c index 6d1cef328c..66c797d2e8 100644 --- a/servers/slapd/back-ldap/bind.c +++ b/servers/slapd/back-ldap/bind.c @@ -72,13 +72,12 @@ ldap_back_bind( /* * Rewrite the bind dn if needed */ + dc.rwmap = &li->rwmap; #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 @@ -290,7 +289,7 @@ ldap_back_getconn(Operation *op, SlapReply *rs) * since we may have different entries * for the same connection */ - ( void )rewrite_session_init( li->rwinfo, op->o_conn ); + ( void )rewrite_session_init( li->rwmap.rwm_rw, op->o_conn ); #endif /* ENABLE_REWRITE */ ldap_pvt_thread_mutex_init( &lc->lc_mutex ); @@ -312,8 +311,8 @@ ldap_back_getconn(Operation *op, SlapReply *rs) /* * Rewrite the bind dn if needed */ + dc.rwmap = &li->rwmap; #ifdef ENABLE_REWRITE - dc.rw = li->rwinfo; dc.conn = op->o_conn; dc.rs = rs; dc.ctx = "bindDn"; @@ -503,13 +502,12 @@ ldap_back_op_result(struct ldapconn *lc, Operation *op, SlapReply *rs, struct berval dn, mdn; dncookie dc; + dc.rwmap = &li->rwmap; #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 diff --git a/servers/slapd/back-ldap/compare.c b/servers/slapd/back-ldap/compare.c index f1b96becb5..fdf17a74df 100644 --- a/servers/slapd/back-ldap/compare.c +++ b/servers/slapd/back-ldap/compare.c @@ -66,13 +66,12 @@ ldap_back_compare( /* * Rewrite the compare dn, if needed */ + dc.rwmap = &li->rwmap; #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 @@ -82,14 +81,15 @@ ldap_back_compare( } if ( op->oq_compare.rs_ava->aa_desc == slap_schema.si_ad_objectClass ) { - ldap_back_map(&li->oc_map, &op->orc_ava->aa_value, &mapped_val, - BACKLDAP_MAP); + ldap_back_map(&li->rwmap.rwm_oc, &op->orc_ava->aa_value, + &mapped_val, BACKLDAP_MAP); if (mapped_val.bv_val == NULL || mapped_val.bv_val[0] == '\0') { return( -1 ); } mapped_at = op->orc_ava->aa_desc->ad_cname; } else { - ldap_back_map(&li->at_map, &op->orc_ava->aa_desc->ad_cname, &mapped_at, + ldap_back_map(&li->rwmap.rwm_at, + &op->orc_ava->aa_desc->ad_cname, &mapped_at, BACKLDAP_MAP); if (mapped_at.bv_val == NULL || mapped_at.bv_val[0] == '\0') { return( -1 ); diff --git a/servers/slapd/back-ldap/config.c b/servers/slapd/back-ldap/config.c index 2c6d3ee554..e3174d74c4 100644 --- a/servers/slapd/back-ldap/config.c +++ b/servers/slapd/back-ldap/config.c @@ -211,7 +211,8 @@ ldap_back_db_config( * FIXME: no extra rewrite capabilities should be added * to the database */ - rc = suffix_massage_config( li->rwinfo, &pvnc, &nvnc, &prnc, &nrnc ); + rc = suffix_massage_config( li->rwmap.rwm_rw, + &pvnc, &nvnc, &prnc, &nrnc ); free( nvnc.bv_val ); free( pvnc.bv_val ); free( nrnc.bv_val ); @@ -230,7 +231,8 @@ ldap_back_db_config( /* rewrite stuff ... */ } else if ( strncasecmp( argv[0], "rewrite", 7 ) == 0 ) { #ifdef ENABLE_REWRITE - return rewrite_parse( li->rwinfo, fname, lineno, argc, argv ); + return rewrite_parse( li->rwmap.rwm_rw, + fname, lineno, argc, argv ); #else /* !ENABLE_REWRITE */ fprintf( stderr, "%s: line %d: rewrite capabilities " @@ -239,7 +241,8 @@ ldap_back_db_config( /* objectclass/attribute mapping */ } else if ( strcasecmp( argv[0], "map" ) == 0 ) { - return ldap_back_map_config( &li->oc_map, &li->at_map, + return ldap_back_map_config( &li->rwmap.rwm_oc, + &li->rwmap.rwm_at, fname, lineno, argc, argv ); /* anything else */ diff --git a/servers/slapd/back-ldap/delete.c b/servers/slapd/back-ldap/delete.c index 0699868150..7e9c56e999 100644 --- a/servers/slapd/back-ldap/delete.c +++ b/servers/slapd/back-ldap/delete.c @@ -66,13 +66,12 @@ ldap_back_delete( /* * Rewrite the request dn, if needed */ + dc.rwmap = &li->rwmap; #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 diff --git a/servers/slapd/back-ldap/extended.c b/servers/slapd/back-ldap/extended.c index 6ccd377598..5a8b7535b3 100644 --- a/servers/slapd/back-ldap/extended.c +++ b/servers/slapd/back-ldap/extended.c @@ -85,13 +85,12 @@ ldap_back_exop_passwd( return LDAP_UNWILLING_TO_PERFORM; } if (id.bv_len) { + dc.rwmap = &li->rwmap; #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 diff --git a/servers/slapd/back-ldap/init.c b/servers/slapd/back-ldap/init.c index f0fbb962e3..e2ccceebf8 100644 --- a/servers/slapd/back-ldap/init.c +++ b/servers/slapd/back-ldap/init.c @@ -117,8 +117,8 @@ ldap_back_db_init( li->bindpw.bv_len = 0; #ifdef ENABLE_REWRITE - li->rwinfo = rewrite_info_init( REWRITE_MODE_USE_DEFAULT ); - if ( li->rwinfo == NULL ) { + li->rwmap.rwm_rw = rewrite_info_init( REWRITE_MODE_USE_DEFAULT ); + if ( li->rwmap.rwm_rw == NULL ) { ch_free( li ); return -1; } @@ -126,7 +126,8 @@ ldap_back_db_init( ldap_pvt_thread_mutex_init( &li->conn_mutex ); - ldap_back_map_init( &li->at_map, &mapping ); + ldap_back_map_init( &li->rwmap.rwm_oc, &mapping ); + ldap_back_map_init( &li->rwmap.rwm_at, &mapping ); li->be = be; be->be_private = li; @@ -192,8 +193,8 @@ ldap_back_db_destroy( avl_free( li->conntree, ldap_back_conn_free ); } #ifdef ENABLE_REWRITE - if (li->rwinfo) { - rewrite_info_delete( li->rwinfo ); + if (li->rwmap.rwm_rw) { + rewrite_info_delete( li->rwmap.rwm_rw ); } #else /* !ENABLE_REWRITE */ if (li->suffix_massage) { @@ -201,10 +202,10 @@ ldap_back_db_destroy( } #endif /* !ENABLE_REWRITE */ - avl_free( li->oc_map.remap, NULL ); - avl_free( li->oc_map.map, mapping_free ); - avl_free( li->at_map.remap, NULL ); - avl_free( li->at_map.map, mapping_free ); + avl_free( li->rwmap.rwm_oc.remap, NULL ); + avl_free( li->rwmap.rwm_oc.map, mapping_free ); + avl_free( li->rwmap.rwm_at.remap, NULL ); + avl_free( li->rwmap.rwm_at.map, mapping_free ); ldap_pvt_thread_mutex_unlock( &li->conn_mutex ); ldap_pvt_thread_mutex_destroy( &li->conn_mutex ); diff --git a/servers/slapd/back-ldap/map.c b/servers/slapd/back-ldap/map.c index 0896cc6342..b08ca5539e 100644 --- a/servers/slapd/back-ldap/map.c +++ b/servers/slapd/back-ldap/map.c @@ -118,102 +118,6 @@ ldap_back_map ( struct ldapmap *map, struct berval *s, struct berval *bv, return; } -char * -ldap_back_map_filter( - struct ldapmap *at_map, - struct ldapmap *oc_map, - struct berval *f, - int remap -) -{ - char *nf, *p, *q, *s, c; - int len, extra, plen, in_quote; - struct berval m, tmp; - - if (f == NULL) - return(NULL); - - len = f->bv_len; - extra = len; - len *= 2; - nf = ch_malloc( len + 1 ); - if (nf == NULL) - return(NULL); - - /* this loop assumes the filter ends with one - * of the delimiter chars -- probably ')'. - */ - - s = nf; - q = NULL; - in_quote = 0; - for (p = f->bv_val; (c = *p); p++) { - if (c == '"') { - in_quote = !in_quote; - if (q != NULL) { - plen = p - q; - AC_MEMCPY(s, q, plen); - s += plen; - q = NULL; - } - *s++ = c; - } else if (in_quote) { - /* ignore everything in quotes -- - * what about attrs in DNs? - */ - *s++ = c; - } else if (c != '(' && c != ')' - && c != '=' && c != '>' && c != '<' - && c != '|' && c != '&') - { - if (q == NULL) - q = p; - } else { - if (q != NULL) { - *p = 0; - tmp.bv_len = p - q; - tmp.bv_val = q; - ldap_back_map(at_map, &tmp, &m, remap); - if (m.bv_val == NULL || m.bv_val[0] == '\0') { - /* - * FIXME: are we sure we need to search - * oc_map if at_map fails? - */ - ldap_back_map(oc_map, &tmp, &m, remap); - if (m.bv_val == NULL || m.bv_val[0] == '\0') { - m = tmp; - } - } - extra += p - q; - plen = m.bv_len; - extra -= plen; - if (extra < 0) { - char *tmpnf; - while (extra < 0) { - extra += len; - len *= 2; - } - s -= (long)nf; - tmpnf = ch_realloc(nf, len + 1); - if (tmpnf == NULL) { - ch_free(nf); - return(NULL); - } - nf = tmpnf; - s += (long)nf; - } - AC_MEMCPY(s, m.bv_val, plen); - s += plen; - *p = c; - q = NULL; - } - *s++ = c; - } - } - *s = 0; - return(nf); -} - int ldap_back_map_attrs( struct ldapmap *at_map, @@ -254,14 +158,9 @@ ldap_back_map_attrs( return LDAP_SUCCESS; } -#ifdef ENABLE_REWRITE - -static int -map_attr_value_( - struct rewrite_info *info, - void *cookie, - struct ldapmap *at_map, - struct ldapmap *oc_map, +int +map_attr_value( + dncookie *dc, AttributeDescription *ad, struct berval *mapped_attr, struct berval *value, @@ -271,12 +170,12 @@ map_attr_value_( struct berval vtmp; int freeval = 0; - ldap_back_map( at_map, &ad->ad_cname, mapped_attr, remap ); + ldap_back_map( &dc->rwmap->rwm_at, &ad->ad_cname, mapped_attr, remap ); if ( mapped_attr->bv_val == NULL || mapped_attr->bv_val[0] == '\0') { /* * FIXME: are we sure we need to search oc_map if at_map fails? */ - ldap_back_map( oc_map, &ad->ad_cname, mapped_attr, remap ); + ldap_back_map( &dc->rwmap->rwm_oc, &ad->ad_cname, mapped_attr, remap ); if ( mapped_attr->bv_val == NULL || mapped_attr->bv_val[0] == '\0' ) { *mapped_attr = ad->ad_cname; } @@ -288,25 +187,16 @@ map_attr_value_( if ( strcmp( ad->ad_type->sat_syntax->ssyn_oid, SLAPD_DN_SYNTAX ) == 0 ) { - switch ( rewrite_session( info, "searchFilter", - value->bv_val, cookie, &vtmp.bv_val ) ) { + dncookie fdc = *dc; + + fdc.ctx = "searchFilter"; + + switch ( ldap_back_dn_massage( &fdc, value, &vtmp ) ) { case REWRITE_REGEXEC_OK: - if ( vtmp.bv_val == NULL ) { - vtmp = *value; - } else { - vtmp.bv_len = strlen( vtmp.bv_val ); + if ( vtmp.bv_val != value->bv_val ) { freeval = 1; } -#ifdef NEW_LOGGING - LDAP_LOG( BACK_LDAP, DETAIL1, - "[rw] searchFilter: \"%s\" -> \"%s\"\n", - value->bv_val, vtmp.bv_val, 0 ); -#else /* !NEW_LOGGING */ - Debug( LDAP_DEBUG_ARGS, "rw> searchFilter: \"%s\" -> \"%s\"\n%s", - value->bv_val, vtmp.bv_val, "" ); -#endif /* !NEW_LOGGING */ break; - case REWRITE_REGEXEC_UNWILLING: return -1; @@ -316,7 +206,7 @@ map_attr_value_( } } else if ( ad == slap_schema.si_ad_objectClass || ad == slap_schema.si_ad_structuralObjectClass ) { - ldap_back_map( oc_map, value, &vtmp, remap ); + ldap_back_map( &dc->rwmap->rwm_oc, value, &vtmp, remap ); if ( vtmp.bv_val == NULL || vtmp.bv_val[0] == '\0' ) { vtmp = *value; } @@ -334,75 +224,9 @@ map_attr_value_( return 0; } -#define map_attr_value(at_map, oc_map, ad, mapped_attr, value, mapped_value, remap) \ - map_attr_value_(info, cookie, (at_map), (oc_map), (ad), (mapped_attr), (value), (mapped_value), (remap)) -#define ldap_back_filter_map_rewrite(at_map, oc_map, f, fstr, remap) \ - ldap_back_filter_map_rewrite_(info, cookie, (at_map), (oc_map), (f), (fstr), (remap)) - -#else /* ! ENABLE_REWRITE */ - -static int -map_attr_value_( - struct ldapmap *at_map, - struct ldapmap *oc_map, - AttributeDescription *ad, - struct berval *mapped_attr, - struct berval *value, - struct berval *mapped_value, - int remap ) -{ - struct berval vtmp; - - ldap_back_map( at_map, &ad->ad_cname, mapped_attr, remap ); - if ( mapped_attr->bv_val == NULL || mapped_attr->bv_val[0] == '\0') { - /* - * FIXME: are we sure we need to search oc_map if at_map fails? - */ - ldap_back_map( oc_map, &ad->ad_cname, mapped_attr, remap ); - if ( mapped_attr->bv_val == NULL || mapped_attr->bv_val[0] == '\0' ) { - *mapped_attr = ad->ad_cname; - } - } - - if ( value == NULL ) { - return 0; - } - - if ( strcmp( ad->ad_type->sat_syntax->ssyn_oid, SLAPD_DN_SYNTAX ) == 0 ) - { - /* FIXME: use suffix massage capabilities */ - vtmp = *value; - - } else if ( ad == slap_schema.si_ad_objectClass || ad == slap_schema.si_ad_structuralObjectClass ) { - ldap_back_map( oc_map, value, &vtmp, remap ); - if ( vtmp.bv_val == NULL || vtmp.bv_val[0] == '\0' ) { - vtmp = *value; - } - - } else { - vtmp = *value; - } - - filter_escape_value( &vtmp, mapped_value ); - - return 0; -} - -#define map_attr_value(at_map, oc_map, ad, mapped_attr, value, mapped_value, remap) \ - map_attr_value_((at_map), (oc_map), (ad), (mapped_attr), (value), (mapped_value), (remap)) -#define ldap_back_filter_map_rewrite(at_map, oc_map, f, fstr, remap) \ - ldap_back_filter_map_rewrite_((at_map), (oc_map), (f), (fstr), (remap)) - -#endif /* ! ENABLE_REWRITE */ - int -ldap_back_filter_map_rewrite_( -#ifdef ENABLE_REWRITE - struct rewrite_info *info, - void *cookie, -#endif /* ENABLE_REWRITE */ - struct ldapmap *at_map, - struct ldapmap *oc_map, +ldap_back_filter_map_rewrite( + dncookie *dc, Filter *f, struct berval *fstr, int remap ) @@ -420,7 +244,7 @@ ldap_back_filter_map_rewrite_( switch ( f->f_choice ) { case LDAP_FILTER_EQUALITY: - if ( map_attr_value( at_map, oc_map, f->f_av_desc, &atmp, + if ( map_attr_value( dc, f->f_av_desc, &atmp, &f->f_av_value, &vtmp, remap ) ) { return -1; @@ -437,8 +261,8 @@ ldap_back_filter_map_rewrite_( break; case LDAP_FILTER_GE: - if ( map_attr_value( at_map, oc_map, f->f_av_desc, &atmp, - &f->f_av_value, &vtmp, remap ) ) + if ( map_attr_value( dc, f->f_av_desc, &atmp, + &f->f_av_value, &vtmp, remap ) ) { return -1; } @@ -454,7 +278,7 @@ ldap_back_filter_map_rewrite_( break; case LDAP_FILTER_LE: - if ( map_attr_value( at_map, oc_map, f->f_av_desc, &atmp, + if ( map_attr_value( dc, f->f_av_desc, &atmp, &f->f_av_value, &vtmp, remap ) ) { return -1; @@ -471,7 +295,7 @@ ldap_back_filter_map_rewrite_( break; case LDAP_FILTER_APPROX: - if ( map_attr_value( at_map, oc_map, f->f_av_desc, &atmp, + if ( map_attr_value( dc, f->f_av_desc, &atmp, &f->f_av_value, &vtmp, remap ) ) { return -1; @@ -488,7 +312,7 @@ ldap_back_filter_map_rewrite_( break; case LDAP_FILTER_SUBSTRINGS: - if ( map_attr_value( at_map, oc_map, f->f_sub_desc, &atmp, + if ( map_attr_value( dc, f->f_sub_desc, &atmp, NULL, NULL, remap ) ) { return -1; @@ -550,7 +374,7 @@ ldap_back_filter_map_rewrite_( break; case LDAP_FILTER_PRESENT: - if ( map_attr_value( at_map, oc_map, f->f_desc, &atmp, + if ( map_attr_value( dc, f->f_desc, &atmp, NULL, NULL, remap ) ) { return -1; @@ -576,7 +400,7 @@ ldap_back_filter_map_rewrite_( for ( p = f->f_list; p != NULL; p = p->f_next ) { len = fstr->bv_len; - if ( ldap_back_filter_map_rewrite( at_map, oc_map, p, &vtmp, remap ) ) + if ( ldap_back_filter_map_rewrite( dc, p, &vtmp, remap ) ) { return -1; } @@ -594,7 +418,7 @@ ldap_back_filter_map_rewrite_( case LDAP_FILTER_EXT: { if ( f->f_mr_desc ) { - if ( map_attr_value( at_map, oc_map, f->f_mr_desc, &atmp, + if ( map_attr_value( dc, f->f_mr_desc, &atmp, &f->f_mr_value, &vtmp, remap ) ) { return -1; @@ -643,3 +467,4 @@ ldap_back_filter_map_rewrite_( return 0; } + diff --git a/servers/slapd/back-ldap/modify.c b/servers/slapd/back-ldap/modify.c index 7375a191ce..134213de67 100644 --- a/servers/slapd/back-ldap/modify.c +++ b/servers/slapd/back-ldap/modify.c @@ -69,13 +69,12 @@ ldap_back_modify( /* * Rewrite the modify dn, if needed */ + dc.rwmap = &li->rwmap; #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 @@ -102,32 +101,64 @@ ldap_back_modify( dc.ctx = "modifyAttrDN"; #endif for (i=0, ml=op->oq_modify.rs_modlist; ml; ml=ml->sml_next) { + int is_oc = 0; + if ( ml->sml_desc->ad_type->sat_no_user_mod ) { continue; } - ldap_back_map(&li->at_map, &ml->sml_desc->ad_cname, &mapped, - BACKLDAP_MAP); - if (mapped.bv_val == NULL || mapped.bv_val[0] == '\0') { - continue; + if ( ml->sml_desc == slap_schema.si_ad_objectClass + || ml->sml_desc == slap_schema.si_ad_structuralObjectClass ) { + is_oc = 1; + mapped = ml->sml_desc->ad_cname; + + } else { + ldap_back_map(&li->rwmap.rwm_at, + &ml->sml_desc->ad_cname, + &mapped, BACKLDAP_MAP); + if (mapped.bv_val == NULL || mapped.bv_val[0] == '\0') { + continue; + } } modv[i] = &mods[i]; mods[i].mod_op = ml->sml_op | LDAP_MOD_BVALUES; mods[i].mod_type = mapped.bv_val; - if ( ml->sml_desc->ad_type->sat_syntax == - slap_schema.si_syn_distinguishedName ) { - ldap_dnattr_rewrite( &dc, ml->sml_bvalues ); - } + if ( ml->sml_bvalues != NULL ) { + if ( is_oc ) { + for (j = 0; ml->sml_bvalues[j].bv_val; j++); + mods[i].mod_bvalues = (struct berval **)ch_malloc((j+1) * + sizeof(struct berval *)); + for (j = 0; ml->sml_bvalues[j].bv_val; j++) { + ldap_back_map(&li->rwmap.rwm_oc, + &ml->sml_bvalues[j], + &mapped, BACKLDAP_MAP); + if (mapped.bv_val == NULL || mapped.bv_val[0] == '\0') { + continue; + } + mods[i].mod_bvalues[j] = &mapped; + } + mods[i].mod_bvalues[j] = NULL; + + } else { + if ( ml->sml_desc->ad_type->sat_syntax == + slap_schema.si_syn_distinguishedName ) { + ldap_dnattr_rewrite( &dc, ml->sml_bvalues ); + } + + if ( ml->sml_bvalues == NULL ) { + continue; + } + + for (j = 0; ml->sml_bvalues[j].bv_val; j++); + mods[i].mod_bvalues = (struct berval **)ch_malloc((j+1) * + sizeof(struct berval *)); + for (j = 0; ml->sml_bvalues[j].bv_val; j++) + mods[i].mod_bvalues[j] = &ml->sml_bvalues[j]; + mods[i].mod_bvalues[j] = NULL; + } - if ( ml->sml_bvalues != NULL ) { - for (j = 0; ml->sml_bvalues[j].bv_val; j++); - mods[i].mod_bvalues = (struct berval **)ch_malloc((j+1) * - sizeof(struct berval *)); - for (j = 0; ml->sml_bvalues[j].bv_val; j++) - mods[i].mod_bvalues[j] = &ml->sml_bvalues[j]; - mods[i].mod_bvalues[j] = NULL; } else { mods[i].mod_bvalues = NULL; } diff --git a/servers/slapd/back-ldap/modrdn.c b/servers/slapd/back-ldap/modrdn.c index 1e79b450e9..660fb511c6 100644 --- a/servers/slapd/back-ldap/modrdn.c +++ b/servers/slapd/back-ldap/modrdn.c @@ -62,12 +62,11 @@ ldap_back_modrdn( return( -1 ); } + dc.rwmap = &li->rwmap; #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 diff --git a/servers/slapd/back-ldap/search.c b/servers/slapd/back-ldap/search.c index 8fdc28872b..01e6a2bdcd 100644 --- a/servers/slapd/back-ldap/search.c +++ b/servers/slapd/back-ldap/search.c @@ -147,13 +147,12 @@ ldap_back_search( /* * Rewrite the search base, if required */ + dc.rwmap = &li->rwmap; #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 @@ -162,14 +161,8 @@ ldap_back_search( return -1; } -#ifdef ENABLE_REWRITE - rc = ldap_back_filter_map_rewrite_( li->rwinfo, op->o_conn, - &li->at_map, &li->oc_map, op->oq_search.rs_filter, &mfilter, - BACKLDAP_MAP ); -#else /* ! ENABLE_REWRITE */ - rc = ldap_back_filter_map_rewrite_( &li->at_map, &li->oc_map, - op->oq_search.rs_filter, &mfilter, BACKLDAP_MAP ); -#endif /* ! ENABLE_REWRITE */ + rc = ldap_back_filter_map_rewrite( &dc, op->oq_search.rs_filter, + &mfilter, BACKLDAP_MAP ); if ( rc ) { rs->sr_err = LDAP_OTHER; @@ -178,7 +171,8 @@ ldap_back_search( goto finish; } - rs->sr_err = ldap_back_map_attrs( &li->at_map, op->oq_search.rs_attrs, + rs->sr_err = ldap_back_map_attrs( &li->rwmap.rwm_at, + op->oq_search.rs_attrs, BACKLDAP_MAP, &mapped_attrs ); if ( rs->sr_err ) { rc = -1; @@ -393,13 +387,12 @@ ldap_build_entry( /* * Rewrite the dn of the result, if needed */ + dc.rwmap = &li->rwmap; #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 @@ -427,7 +420,7 @@ ldap_build_entry( dc.ctx = "searchAttrDN"; #endif while ( ber_scanf( &ber, "{m", &a ) != LBER_ERROR ) { - ldap_back_map(&li->at_map, &a, &mapped, BACKLDAP_REMAP); + ldap_back_map(&li->rwmap.rwm_at, &a, &mapped, BACKLDAP_REMAP); if (mapped.bv_val == NULL || mapped.bv_val[0] == '\0') continue; attr = (Attribute *)ch_malloc( sizeof(Attribute) ); @@ -490,7 +483,7 @@ ldap_build_entry( } else if ( attr->a_desc == slap_schema.si_ad_objectClass || attr->a_desc == slap_schema.si_ad_structuralObjectClass ) { for ( bv = attr->a_vals; bv->bv_val; bv++ ) { - ldap_back_map(&li->oc_map, bv, &mapped, + ldap_back_map(&li->rwmap.rwm_oc, bv, &mapped, BACKLDAP_REMAP); if (mapped.bv_val == NULL || mapped.bv_val[0] == '\0') { LBER_FREE(bv->bv_val); @@ -558,8 +551,6 @@ ldap_build_entry( } } -next_attr:; - if ( normalize && last && attr->a_desc->ad_type->sat_equality && attr->a_desc->ad_type->sat_equality->smr_normalize ) { int i; @@ -626,13 +617,12 @@ ldap_back_entry_get( /* * Rewrite the search base, if required */ + dc.rwmap = &li->rwmap; #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 @@ -640,7 +630,7 @@ ldap_back_entry_get( return 1; } - ldap_back_map(&li->at_map, &at->ad_cname, &mapped, BACKLDAP_MAP); + ldap_back_map(&li->rwmap.rwm_at, &at->ad_cname, &mapped, BACKLDAP_MAP); if (mapped.bv_val == NULL || mapped.bv_val[0] == '\0') { rc = 1; goto cleanup; @@ -657,7 +647,7 @@ ldap_back_entry_get( } if (oc) { char *ptr; - ldap_back_map(&li->oc_map, &oc->soc_cname, &mapped, + ldap_back_map(&li->rwmap.rwm_oc, &oc->soc_cname, &mapped, BACKLDAP_MAP); filter = ch_malloc(sizeof("(objectclass=)") + mapped.bv_len); ptr = lutil_strcopy(filter, "(objectclass="); diff --git a/servers/slapd/back-ldap/suffixmassage.c b/servers/slapd/back-ldap/suffixmassage.c index 4cd1a13b4c..5e108b186c 100644 --- a/servers/slapd/back-ldap/suffixmassage.c +++ b/servers/slapd/back-ldap/suffixmassage.c @@ -47,7 +47,7 @@ ldap_back_dn_massage( { int rc = 0; - switch (rewrite_session( dc->rw, dc->ctx, dn->bv_val, dc->conn, + switch (rewrite_session( dc->rwmap->rwm_rw, dc->ctx, dn->bv_val, dc->conn, &res->bv_val )) { case REWRITE_REGEXEC_OK: if ( res->bv_val != NULL ) { diff --git a/servers/slapd/back-ldap/unbind.c b/servers/slapd/back-ldap/unbind.c index 523657ef24..5197c0e907 100644 --- a/servers/slapd/back-ldap/unbind.c +++ b/servers/slapd/back-ldap/unbind.c @@ -85,7 +85,7 @@ ldap_back_conn_destroy( /* * Cleanup rewrite session */ - rewrite_session_delete( li->rwinfo, conn ); + rewrite_session_delete( li->rwmap.rwm_rw, conn ); #endif /* ENABLE_REWRITE */ /* -- 2.39.5