]> git.sur5r.net Git - openldap/commitdiff
group rewrite/map stuff in one structure and optimize more function calls
authorPierangelo Masarati <ando@openldap.org>
Mon, 7 Apr 2003 16:52:59 +0000 (16:52 +0000)
committerPierangelo Masarati <ando@openldap.org>
Mon, 7 Apr 2003 16:52:59 +0000 (16:52 +0000)
14 files changed:
servers/slapd/back-ldap/add.c
servers/slapd/back-ldap/back-ldap.h
servers/slapd/back-ldap/bind.c
servers/slapd/back-ldap/compare.c
servers/slapd/back-ldap/config.c
servers/slapd/back-ldap/delete.c
servers/slapd/back-ldap/extended.c
servers/slapd/back-ldap/init.c
servers/slapd/back-ldap/map.c
servers/slapd/back-ldap/modify.c
servers/slapd/back-ldap/modrdn.c
servers/slapd/back-ldap/search.c
servers/slapd/back-ldap/suffixmassage.c
servers/slapd/back-ldap/unbind.c

index a9be70d466d6f08e405ab218903670a3f08bdaa6..f4cf8af1e9ac6e18650289e751b9a107b8dfd287 100644 (file)
@@ -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;
index 3ef2f6d68be77e95024970a122700453a6e367ea..d605d694f8cd6e1c35ccb7587135c1d16ab3aa04 100644 (file)
@@ -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 );
index 6d1cef328c05393a0731b1dafdf579c69153fd62..66c797d2e8e0bdea195a3496b2ef0bbcd1271f6b 100644 (file)
@@ -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
index f1b96becb51adb7f0284db996866c35a6a88e95b..fdf17a74df50bed42c40697019afc58f31bb3339 100644 (file)
@@ -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 );
index 2c6d3ee554ceb852353768434cb2a27df6da1891..e3174d74c4ad6d6e4e33a4fc76124b2acc342232 100644 (file)
@@ -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 */
index 06998681502159b11d5fca71d8086725642207b9..7e9c56e9990234b294230397a81cecfde2f3a8e9 100644 (file)
@@ -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
index 6ccd37759883904b56030601ae06469e0dd23d99..5a8b7535b3f5ce12746f493fb8241c3e951e6def 100644 (file)
@@ -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
index f0fbb962e38ed37b1ec718901bdee2630fdc007e..e2ccceebf8c5b9f89b64e172b94cad2703e09c92 100644 (file)
@@ -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 );
index 0896cc63422c8077a17c878ed6bf7768ecb5e119..b08ca5539e77956c4f96574471529752fe151b65 100644 (file)
@@ -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;
 }
+
index 7375a191cec29e6ab344862b589316a68ed010ee..134213de6717c480099cd33936bb11325ce76393 100644 (file)
@@ -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;
                }
index 1e79b450e92ade1b2ab5594289a4065bbd0cffea..660fb511c67077df2621c1439ba28844ad080704 100644 (file)
@@ -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
index 8fdc28872ba8445c6bec7e7dd3daefec186a61e6..01e6a2bdcdab5277ffc6114d2b65ccbf1c8b7c92 100644 (file)
@@ -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=");
index 4cd1a13b4cc011d0240fd885ecdf1bae2198e0b4..5e108b186c41bcb3f94a88ecfe3b9cb5bce05c82 100644 (file)
@@ -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 ) {
index 523657ef240fd7af71e99e17823bb3ad4a1b4a91..5197c0e90704d64dacbbd1f9bb0037f74be4abb8 100644 (file)
@@ -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 */
 
                /*