]> git.sur5r.net Git - openldap/commitdiff
use rewrite info instead of ldapinfo for reusability in back-meta; will change soon
authorPierangelo Masarati <ando@openldap.org>
Mon, 7 Apr 2003 12:53:00 +0000 (12:53 +0000)
committerPierangelo Masarati <ando@openldap.org>
Mon, 7 Apr 2003 12:53:00 +0000 (12:53 +0000)
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/delete.c
servers/slapd/back-ldap/extended.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

index 7344aa5605e51e404adf1bd6767d5336adcbe4f4..a9be70d466d6f08e405ab218903670a3f08bdaa6 100644 (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;
-
-       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;
                }
        }
        
index 49592cf1df97df6fe35f7d5c4cccff87bb190fcb..3ef2f6d68be77e95024970a122700453a6e367ea 100644 (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
index 3ba1eb8889dbfb939b10cc6f32b6c15dec80d1b2..6d1cef328c05393a0731b1dafdf579c69153fd62 100644 (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
index f1dfb35b7998c3c216fc9f6102f8d74932940ec4..f1b96becb51adb7f0284db996866c35a6a88e95b 100644 (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
index c48ae217cca88202bbf41ca201fdeb58201a312f..06998681502159b11d5fca71d8086725642207b9 100644 (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
index 8f643e1c9324833e5e05c903037a25124e241260..6ccd37759883904b56030601ae06469e0dd23d99 100644 (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
index 60d77dc6e99bf07479302a21e7458213e2033d91..7375a191cec29e6ab344862b589316a68ed010ee 100644 (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
index 27a87ef0755801d3e93796a47294180e893df032..1e79b450e92ade1b2ab5594289a4065bbd0cffea 100644 (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
index db8c2275448fcec9b1d101c77628a632f32ef48a..8fdc28872ba8445c6bec7e7dd3daefec186a61e6 100644 (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
index 15a8903cf2de27ae097d47de228be19dea5de93e..4cd1a13b4cc011d0240fd885ecdf1bae2198e0b4 100644 (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;