From: Kurt Zeilenga Date: Sun, 1 Sep 2002 05:58:13 +0000 (+0000) Subject: Sync with HEAD X-Git-Tag: OPENLDAP_REL_ENG_2_1_5~66 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=18f96ccbed47fdf7deb9bff8ce9984222397d1c1;p=openldap Sync with HEAD --- diff --git a/servers/slapd/back-bdb/add.c b/servers/slapd/back-bdb/add.c index 983ddd9dba..d00d88d0c5 100644 --- a/servers/slapd/back-bdb/add.c +++ b/servers/slapd/back-bdb/add.c @@ -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 ); } diff --git a/servers/slapd/back-bdb/delete.c b/servers/slapd/back-bdb/delete.c index c15662b15d..6052c6ea91 100644 --- a/servers/slapd/back-bdb/delete.c +++ b/servers/slapd/back-bdb/delete.c @@ -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 ); } diff --git a/servers/slapd/back-bdb/init.c b/servers/slapd/back-bdb/init.c index 978835bd91..f5e9b4ead3 100644 --- a/servers/slapd/back-bdb/init.c +++ b/servers/slapd/back-bdb/init.c @@ -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; diff --git a/servers/slapd/back-bdb/modify.c b/servers/slapd/back-bdb/modify.c index 4f052e404c..965bb0b098 100644 --- a/servers/slapd/back-bdb/modify.c +++ b/servers/slapd/back-bdb/modify.c @@ -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 ); } diff --git a/servers/slapd/back-bdb/modrdn.c b/servers/slapd/back-bdb/modrdn.c index fe7c2544ce..54b6de974e 100644 --- a/servers/slapd/back-bdb/modrdn.c +++ b/servers/slapd/back-bdb/modrdn.c @@ -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 ); } diff --git a/servers/slapd/back-sql/config.c b/servers/slapd/back-sql/config.c index 3472496ae6..e26c6b9489 100644 --- a/servers/slapd/back-sql/config.c +++ b/servers/slapd/back-sql/config.c @@ -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, diff --git a/servers/slapd/back-sql/init.c b/servers/slapd/back-sql/init.c index 301646ccda..1fd5512711 100644 --- a/servers/slapd/back-sql/init.c +++ b/servers/slapd/back-sql/init.c @@ -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; diff --git a/servers/slapd/back-sql/search.c b/servers/slapd/back-sql/search.c index 462eba4426..0032f2ffdf 100644 --- a/servers/slapd/back-sql/search.c +++ b/servers/slapd/back-sql/search.c @@ -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: diff --git a/servers/slapd/back-sql/util.c b/servers/slapd/back-sql/util.c index 402d36fbab..1b7e3379ff 100644 --- a/servers/slapd/back-sql/util.c +++ b/servers/slapd/back-sql/util.c @@ -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; }