]> git.sur5r.net Git - openldap/commitdiff
Sync with HEAD
authorKurt Zeilenga <kurt@openldap.org>
Sun, 1 Sep 2002 05:58:13 +0000 (05:58 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Sun, 1 Sep 2002 05:58:13 +0000 (05:58 +0000)
servers/slapd/back-bdb/add.c
servers/slapd/back-bdb/delete.c
servers/slapd/back-bdb/init.c
servers/slapd/back-bdb/modify.c
servers/slapd/back-bdb/modrdn.c
servers/slapd/back-sql/config.c
servers/slapd/back-sql/init.c
servers/slapd/back-sql/search.c
servers/slapd/back-sql/util.c

index 983ddd9dba9c5c56ab6d25c083c8f70a85c7885c..d00d88d0c5261440e5a1b8df9f6e5c2d15ca1b52 100644 (file)
@@ -23,7 +23,7 @@ bdb_add(
        struct bdb_info *bdb = (struct bdb_info *) be->be_private;
        struct berval   pdn;
        Entry           *p = NULL;
-       int             rc, ret
+       int             rc; 
        const char      *text;
        char textbuf[SLAP_TEXT_BUFLEN];
        size_t textlen = sizeof textbuf;
@@ -39,6 +39,7 @@ bdb_add(
        u_int32_t       lockid;
        DB_LOCK         lock;
 #endif
+       int             noop = 0;
 
 #ifdef NEW_LOGGING
        LDAP_LOG ( OPERATION, ARGS, "==> bdb_add: %s\n", e->e_dn, 0, 0 );
@@ -434,6 +435,7 @@ retry:      /* transaction retry */
                if (( rc=TXN_ABORT( ltid )) != 0 ) {
                        text = "txn_abort (no-op) failed";
                } else {
+                       noop = 1;
                        rc = LDAP_SUCCESS;
                }
 
@@ -447,7 +449,9 @@ retry:      /* transaction retry */
                        text = "txn_prepare failed";
 
                } else {
-                       ret = bdb_cache_add_entry_rw(bdb->bi_dbenv, &bdb->bi_cache, e, CACHE_WRITE_LOCK, locker, &lock);
+                       int ret = bdb_cache_add_entry_rw(bdb->bi_dbenv,
+                                       &bdb->bi_cache, e, CACHE_WRITE_LOCK,
+                                       locker, &lock);
 #if 0
                        if ( bdb_cache_add_entry_rw(&bdb->bi_cache,
                                e, CACHE_WRITE_LOCK) != 0 )
@@ -492,7 +496,9 @@ retry:      /* transaction retry */
                        op->o_noop ? " (no-op)" : "", e->e_id, e->e_dn );
 #endif
                text = NULL;
-               bdb_cache_entry_commit( e );
+               if ( !noop ) {
+                       bdb_cache_entry_commit( e );
+               }
        }
        else {
 #ifdef NEW_LOGGING
@@ -522,5 +528,5 @@ done:
                op->o_private = NULL;
        }
 
-       return rc;
+       return ( ( rc == LDAP_SUCCESS ) ? noop : rc );
 }
index c15662b15d8b494a1c48e5c8b4a00618f71e51c4..6052c6ea91ef40a0b8eeda3f8bee6d8075fa683b 100644 (file)
@@ -41,6 +41,8 @@ bdb_delete(
        DB_LOCK         lock;
 #endif
 
+       int             noop = 0;
+
 #ifdef NEW_LOGGING
        LDAP_LOG ( OPERATION, ARGS,  "==> bdb_delete: %s\n", dn->bv_val, 0, 0 );
 #else
@@ -416,7 +418,12 @@ retry:     /* transaction retry */
 #endif
 
        if( op->o_noop ) {
-               rc = TXN_ABORT( ltid );
+               if ( ( rc = TXN_ABORT( ltid ) ) != 0 ) {
+                       text = "txn_abort (no-op) failed";
+               } else {
+                       noop = 1;
+                       rc = LDAP_SUCCESS;
+               }
        } else {
                rc = TXN_COMMIT( ltid, 0 );
        }
@@ -472,5 +479,5 @@ done:
                op->o_private = NULL;
        }
 
-       return rc;
+       return ( ( rc == LDAP_SUCCESS ) ? noop : rc );
 }
index 978835bd91b895905a271ffc3d9385c663246d25..f5e9b4ead3763da7ace4066997dc0948d45b043c 100644 (file)
@@ -612,7 +612,7 @@ bdb_initialize(
        db_env_set_func_yield( ldap_pvt_thread_yield );
 
        {
-               static char uuidbuf[40];
+               static char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ];
 
                bdb_uuid.bv_len = lutil_uuidstr( uuidbuf, sizeof( uuidbuf ));
                bdb_uuid.bv_val = uuidbuf;
index 4f052e404ce7ad154f40c28389826ffcb1552116..965bb0b0980dc13d514741dd9d355f3062397343 100644 (file)
@@ -166,9 +166,10 @@ int bdb_modify_internal(
                        e->e_ocflags = 0;
                }
 
-               /* check if modified attribute was indexed */
+               /* check if modified attribute was indexed
+                * but not in case of NOOP... */
                err = bdb_index_is_indexed( be, mod->sm_desc );
-               if ( err == LDAP_SUCCESS ) {
+               if ( err == LDAP_SUCCESS && !op->o_noop ) {
                        ap = attr_find( save_attrs, mod->sm_desc );
                        if ( ap ) ap->a_flags |= SLAP_ATTR_IXDEL;
 
@@ -179,17 +180,23 @@ int bdb_modify_internal(
 
        /* check that the entry still obeys the schema */
        rc = entry_schema_check( be, e, save_attrs, text, textbuf, textlen );
-       if ( rc != LDAP_SUCCESS ) {
+       if ( rc != LDAP_SUCCESS || op->o_noop ) {
                attrs_free( e->e_attrs );
                e->e_attrs = save_attrs;
+
+               if ( rc != LDAP_SUCCESS ) {
 #ifdef NEW_LOGGING
-                               LDAP_LOG ( OPERATION, ERR, 
-                                       "bdb_modify_internal: entry failed schema check %s\n", 
-                                       *text, 0, 0 );
+                       LDAP_LOG ( OPERATION, ERR, "bdb_modify_internal: "
+                               "entry failed schema check %s\n", 
+                               *text, 0, 0 );
 #else
-               Debug( LDAP_DEBUG_ANY, "entry failed schema check: %s\n",
-                       *text, 0, 0 );
+                       Debug( LDAP_DEBUG_ANY,
+                               "entry failed schema check: %s\n",
+                               *text, 0, 0 );
 #endif
+               }
+
+               /* if NOOP then silently revert to saved attrs */
                return rc;
        }
 
@@ -268,6 +275,8 @@ bdb_modify(
        u_int32_t       locker;
        DB_LOCK         lock;
 
+       int             noop = 0;
+
 #ifdef NEW_LOGGING
        LDAP_LOG ( OPERATION, ENTRY, "bdb_modify: %s\n", dn->bv_val, 0, 0 );
 #else
@@ -439,7 +448,12 @@ retry:     /* transaction retry */
        }
 
        if( op->o_noop ) {
-               rc = TXN_ABORT( ltid );
+               if ( ( rc = TXN_ABORT( ltid ) ) != 0 ) {
+                       text = "txn_abort (no-op) failed";
+               } else {
+                       noop = 1;
+                       rc = LDAP_SUCCESS;
+               }
        } else {
                rc = TXN_COMMIT( ltid, 0 );
        }
@@ -494,5 +508,5 @@ done:
        if( e != NULL ) {
                bdb_unlocked_cache_return_entry_w (&bdb->bi_cache, e);
        }
-       return rc;
+       return ( ( rc == LDAP_SUCCESS ) ? noop : rc );
 }
index fe7c2544ce560f5eef0bdc0f69f01a9dea766449..54b6de974e690179b9d1611de3692751a5cbc93e 100644 (file)
@@ -59,6 +59,8 @@ bdb_modrdn(
        u_int32_t       locker;
        DB_LOCK         lock;
 
+       int             noop = 0;
+
 #ifdef NEW_LOGGING
        LDAP_LOG ( OPERATION, ENTRY, "==>bdb_modrdn(%s,%s,%s)\n", 
                dn->bv_val,newrdn->bv_val, newSuperior ? newSuperior->bv_val : "NULL" );
@@ -705,6 +707,7 @@ retry:      /* transaction retry */
                if(( rc=TXN_ABORT( ltid )) != 0 ) {
                        text = "txn_abort (no-op) failed";
                } else {
+                       noop = 1;
                        rc = LDAP_SUCCESS;
                }
 
@@ -749,7 +752,9 @@ retry:      /* transaction retry */
                        op->o_noop ? " (no-op)" : "", e->e_id, e->e_dn );
 #endif
                text = NULL;
-               bdb_cache_entry_commit( e );
+               if ( !noop ) {
+                       bdb_cache_entry_commit( e );
+               }
 
        } else {
 #ifdef NEW_LOGGING
@@ -812,5 +817,5 @@ done:
                op->o_private = NULL;
        }
 
-       return rc;
+       return ( ( rc == LDAP_SUCCESS ) ? noop : rc );
 }
index 3472496ae66361e9b3407fa2f080acc2f69314c0..e26c6b94891fedcce8947c83f2c6bd96c302c64b 100644 (file)
@@ -114,6 +114,19 @@ backsql_db_config(
                Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
                        "subtree_cond=%s\n", si->subtree_cond.bv_val, 0, 0 );
 
+       } else if ( !strcasecmp( argv[ 0 ], "children_cond" ) ) {
+               if ( argc < 2 ) {
+                       Debug( LDAP_DEBUG_TRACE, 
+                               "<==backsql_db_config (%s line %d): "
+                               "missing SQL condition "
+                               "in \"children_cond\" directive\n",
+                               fname, lineno, 0 );
+                       return 1;
+               }
+               ber_str2bv( argv[ 1 ], 0, 1, &si->children_cond );
+               Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
+                       "subtree_cond=%s\n", si->children_cond.bv_val, 0, 0 );
+
        } else if ( !strcasecmp( argv[ 0 ], "oc_query" ) ) {
                if ( argc < 2 ) {
                        Debug( LDAP_DEBUG_TRACE, 
index 301646ccdab519c1d86c343cfa541499b7d1adc3..1fd5512711cac6c5701061d4b64676661308d7bd 100644 (file)
@@ -288,31 +288,7 @@ backsql_db_open(
        }
 
        if ( si->children_cond.bv_val == NULL ) {
-               /*
-                * Prepare concat function for children search condition
-                */
-               struct berval   concat;
                ber_len_t       len = 0;
-               struct berval   values[] = {
-                       { sizeof( "'%,'" ) - 1, "'%,'" },
-                       { sizeof( "?" ) - 1,    "?" },
-                       { 0,                    NULL }
-               };
-
-               if ( backsql_prepare_pattern( si->concat_func, values, 
-                               &concat ) ) {
-                       Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): "
-                               "unable to prepare CONCAT pattern", 0, 0, 0 );
-                       return 1;
-               }
-                       
-               Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): "
-                       "children search SQL condition not specified "
-                       "(use \"children_cond\" directive in slapd.conf)\n", 
-                       0, 0, 0);
-
-               si->children_cond.bv_val = NULL;
-               si->children_cond.bv_len = 0;
 
                if ( si->upper_func.bv_val ) {
 
@@ -320,13 +296,12 @@ backsql_db_open(
                         * UPPER(ldap_entries.dn) LIKE UPPER(CONCAT('%,',?))
                         */
 
-                       backsql_strfcat( &si->children_cond, &len, "blbbb",
+                       backsql_strfcat( &si->children_cond, &len, "blbl",
                                        &si->upper_func,
-                                       (ber_len_t)sizeof( "(ldap_entries.dn) LIKE " ) - 1,
-                                               "(ldap_entries.dn) LIKE ",
-                                       &si->upper_func_open,
-                                       &concat,
-                                       &si->upper_func_close );
+                                       (ber_len_t)sizeof( "(ldap_entries.dn)=" ) - 1,
+                                               "(ldap_entries.dn)=",
+                                       &si->upper_func,
+                                       (ber_len_t)sizeof( "(?)" ) - 1, "(?)" );
 
                } else {
 
@@ -334,10 +309,9 @@ backsql_db_open(
                         * ldap_entries.dn LIKE CONCAT('%,',?)
                         */
 
-                       backsql_strfcat( &si->children_cond, &len, "lb",
-                                       (ber_len_t)sizeof( "ldap_entries.dn LIKE " ) - 1,
-                                               "ldap_entries.dn LIKE ",
-                                       &concat );
+                       backsql_strfcat( &si->children_cond, &len, "l",
+                                       (ber_len_t)sizeof( "ldap_entries.dn=?" ) - 1,
+                                               "ldap_entries.dn=?");
                }
                        
                Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): "
@@ -445,8 +419,9 @@ backsql_db_open(
 
        bv.bv_val = NULL;
        bv.bv_len = 0;
-       backsql_strfcat( &bv, &idq_len, "sb", 
-                       "select count(*) from ldap_entries where ",
+       backsql_strfcat( &bv, &idq_len, "sb",
+                       "SELECT COUNT(distinct subordinates.id) FROM ldap_entries,ldap_entries AS subordinates WHERE subordinates.parent=ldap_entries.id AND ",
+
                        &si->children_cond );
        si->has_children_query = bv.bv_val;
  
index 462eba442693becafdd1018ff590c365ab44197a..0032f2ffdf329e0c856bb522ef18f963791b7ecc 100644 (file)
@@ -323,6 +323,7 @@ backsql_process_filter( backsql_srch_info *bsi, Filter *f )
        ber_len_t               len = 0;
        /* TimesTen */
        int                     rc = 0;
+       struct berval           *filter_value = NULL;
 
        Debug( LDAP_DEBUG_TRACE, "==>backsql_process_filter()\n", 0, 0, 0 );
        if ( f == NULL || f->f_choice == SLAPD_FILTER_COMPUTED ) {
@@ -460,6 +461,15 @@ backsql_process_filter( backsql_srch_info *bsi, Filter *f )
 
        switch ( f->f_choice ) {
        case LDAP_FILTER_EQUALITY:
+               filter_value = &f->f_av_value;
+               goto equality_match;
+
+               /* fail over next case */
+               
+       case LDAP_FILTER_EXT:
+               filter_value = &f->f_mra->ma_value;
+
+equality_match:;
                /*
                 * maybe we should check type of at->sel_expr here somehow,
                 * to know whether upper_func is applicable, but for now
@@ -491,7 +501,7 @@ backsql_process_filter( backsql_srch_info *bsi, Filter *f )
 
                        backsql_strfcat( &bsi->flt_where, &bsi->fwhere_len,
                                        "bl",
-                                       &f->f_av_value, 
+                                       filter_value, 
                                        (ber_len_t)sizeof( /* (' */ "')" ) - 1,
                                                /* (' */ "')" );
 
@@ -503,7 +513,7 @@ backsql_process_filter( backsql_srch_info *bsi, Filter *f )
                                        '(',
                                        &at->sel_expr,
                                        (ber_len_t)sizeof( "='" ) - 1, "='",
-                                       &f->f_av_value,
+                                       filter_value,
                                        (ber_len_t)sizeof( /* (' */ "')" ) - 1,
                                                /* (' */ "')" );
                }
@@ -543,6 +553,67 @@ backsql_process_filter( backsql_srch_info *bsi, Filter *f )
        case LDAP_FILTER_SUBSTRINGS:
                backsql_process_sub_filter( bsi, f );
                break;
+
+       case LDAP_FILTER_APPROX:
+               /* we do our best */
+
+               /*
+                * maybe we should check type of at->sel_expr here somehow,
+                * to know whether upper_func is applicable, but for now
+                * upper_func stuff is made for Oracle, where UPPER is
+                * safely applicable to NUMBER etc.
+                */
+               if ( bsi->bi->upper_func.bv_val ) {
+                       size_t  start;
+
+                       if ( at->sel_expr_u.bv_val ) {
+                               backsql_strfcat( &bsi->flt_where,
+                                               &bsi->fwhere_len, "cbl",
+                                               '(',
+                                               &at->sel_expr_u, 
+                                               (ber_len_t)sizeof( " LIKE '%" ) - 1,
+                                                       " LIKE '%" );
+                       } else {
+                               backsql_strfcat( &bsi->flt_where,
+                                               &bsi->fwhere_len, "cbcbl",
+                                               '(' /* ) */ ,
+                                               &bsi->bi->upper_func,
+                                               '(' /* ) */ ,
+                                               &at->sel_expr,
+                                               (ber_len_t)sizeof( /* ( */ ") LIKE '%" ) - 1,
+                                                       /* ( */ ") LIKE '%" );
+                       }
+
+                       start = bsi->flt_where.bv_len;
+
+                       backsql_strfcat( &bsi->flt_where, &bsi->fwhere_len,
+                                       "bl",
+                                       &f->f_av_value, 
+                                       (ber_len_t)sizeof( /* (' */ "%')" ) - 1,
+                                               /* (' */ "%')" );
+
+                       ldap_pvt_str2upper( &bsi->flt_where.bv_val[ start ] );
+
+               } else {
+                       backsql_strfcat( &bsi->flt_where, &bsi->fwhere_len,
+                                       "cblbl",
+                                       '(',
+                                       &at->sel_expr,
+                                       (ber_len_t)sizeof( " LIKE '%" ) - 1,
+                                               " LIKE '%",
+                                       &f->f_av_value,
+                                       (ber_len_t)sizeof( /* (' */ "%')" ) - 1,
+                                               /* (' */ "%')" );
+               }
+               break;
+
+       default:
+               /* unhandled filter type; should not happen */
+               assert( 0 );
+               backsql_strfcat( &bsi->flt_where, &bsi->fwhere_len, "l",
+                               (ber_len_t)sizeof( "1=1" ) - 1, "1=1" );
+               break;
+
        }
 
 done:
@@ -665,8 +736,26 @@ backsql_srch_query( backsql_srch_info *bsi, struct berval *query )
                break;
 
        case LDAP_SCOPE_SUBTREE:
+               if ( bsi->bi->upper_func.bv_val ) {
+                       backsql_strfcat( &bsi->join_where, &bsi->jwhere_len, 
+                                       "blbcb",
+                                       &bsi->bi->upper_func,
+                                       (ber_len_t)sizeof( "(ldap_entries.dn) LIKE " ) - 1,
+                                               "(ldap_entries.dn) LIKE ",
+                                       &bsi->bi->upper_func_open,
+                                       '?', 
+                                       &bsi->bi->upper_func_close );
+               } else {
+                       backsql_strfcat( &bsi->join_where, &bsi->jwhere_len,
+                                       "l",
+                                       (ber_len_t)sizeof( "ldap_entries.dn LIKE ?" ) - 1,
+                                               "ldap_entries.dn LIKE ?" );
+               }
+
+#if 0
                backsql_strfcat( &bsi->join_where, &bsi->jwhere_len, "b",
                                &bsi->bi->subtree_cond );
+#endif
                break;
 
        default:
index 402d36fbab5aa077fa292080e8129bc5fcd5aa50..1b7e3379ff742b1272ed7ec9ab387e60fbe49fe9 100644 (file)
@@ -212,6 +212,8 @@ backsql_strfcat( struct berval *dest, ber_len_t *buflen, const char *fmt, ... )
 #endif /* BACKSQL_TRACE */
                }
 
+               assert( cstr );
+               
                AC_MEMCPY( dest->bv_val + cdlen, cstr, cslen + 1 );
                cdlen += cslen;
        }