From aaf8b230692fb6d555c116babd7641e0e138fe9f Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Mon, 12 Apr 2004 20:20:12 +0000 Subject: [PATCH] From HEAD: New module build stuff updateref updates, new SHADOW DBFLAGS, etc. paging control updates limits updates fixed duplicate value checks fixed permissive modify sasl auxprop propname changes back-bdb "" suffix fixes fixed back-bdb/ldbm approx non-indexing fixings updated back-sql --- servers/slapd/add.c | 49 +-- servers/slapd/back-bdb/Makefile.in | 1 - servers/slapd/back-bdb/add.c | 4 +- servers/slapd/back-bdb/attr.c | 7 +- servers/slapd/back-bdb/config.c | 4 +- servers/slapd/back-bdb/ctxcsn.c | 4 +- servers/slapd/back-bdb/delete.c | 2 +- servers/slapd/back-bdb/index.c | 9 +- servers/slapd/back-bdb/init.c | 8 +- servers/slapd/back-bdb/modrdn.c | 2 +- servers/slapd/back-bdb/search.c | 39 +- servers/slapd/back-dnssrv/Makefile.in | 1 - servers/slapd/back-dnssrv/init.c | 4 +- servers/slapd/back-hdb/Makefile.in | 1 - servers/slapd/back-ldap/Makefile.in | 1 - servers/slapd/back-ldap/init.c | 4 +- servers/slapd/back-ldap/modify.c | 36 +- servers/slapd/back-ldbm/Makefile.in | 1 - servers/slapd/back-ldbm/add.c | 4 +- servers/slapd/back-ldbm/attr.c | 7 +- servers/slapd/back-ldbm/delete.c | 3 +- servers/slapd/back-ldbm/index.c | 9 +- servers/slapd/back-ldbm/init.c | 4 +- servers/slapd/back-ldbm/modrdn.c | 10 +- servers/slapd/back-meta/Makefile.in | 1 - servers/slapd/back-meta/init.c | 4 +- servers/slapd/back-monitor/Makefile.in | 1 - servers/slapd/back-monitor/README | 2 +- servers/slapd/back-monitor/init.c | 6 +- servers/slapd/back-monitor/log.c | 63 ++-- servers/slapd/back-monitor/operation.c | 2 +- servers/slapd/back-null/Makefile.in | 1 - servers/slapd/back-null/null.c | 6 +- servers/slapd/back-passwd/Makefile.in | 1 - servers/slapd/back-passwd/init.c | 4 +- servers/slapd/back-perl/Makefile.in | 1 - servers/slapd/back-perl/init.c | 4 +- servers/slapd/back-shell/Makefile.in | 1 - servers/slapd/back-shell/init.c | 4 +- servers/slapd/back-sql/Makefile.in | 5 +- servers/slapd/back-sql/add.c | 115 +++++- servers/slapd/back-sql/back-sql.h | 51 ++- servers/slapd/back-sql/bind.c | 38 +- servers/slapd/back-sql/compare.c | 23 +- servers/slapd/back-sql/config.c | 9 + servers/slapd/back-sql/delete.c | 20 +- servers/slapd/back-sql/entry-id.c | 122 ++++--- servers/slapd/back-sql/init.c | 24 +- servers/slapd/back-sql/modify.c | 12 +- servers/slapd/back-sql/modrdn.c | 57 ++- servers/slapd/back-sql/operational.c | 2 +- servers/slapd/back-sql/proto-sql.h | 10 +- servers/slapd/back-sql/schema-map.c | 52 +-- servers/slapd/back-sql/search.c | 483 +++++++++++++++++++------ servers/slapd/back-sql/sql-wrap.c | 4 +- servers/slapd/back-sql/util.c | 14 +- servers/slapd/backend.c | 80 ++-- servers/slapd/config.c | 15 +- servers/slapd/controls.c | 14 +- servers/slapd/delete.c | 14 +- servers/slapd/limits.c | 382 ++++++++++++++----- servers/slapd/modify.c | 83 ++++- servers/slapd/modrdn.c | 22 +- servers/slapd/mods.c | 188 ++++------ servers/slapd/overlays/pcache.c | 8 +- servers/slapd/proto-slap.h | 11 +- servers/slapd/result.c | 7 +- servers/slapd/sasl.c | 33 +- servers/slapd/saslauthz.c | 11 +- servers/slapd/slap.h | 13 +- servers/slapd/slapi/slapi_ops.c | 36 +- servers/slapd/slapi/slapi_utils.c | 54 +-- servers/slapd/syncrepl.c | 72 ++-- 73 files changed, 1584 insertions(+), 815 deletions(-) diff --git a/servers/slapd/add.c b/servers/slapd/add.c index ffa94168b6..f7bcc117fd 100644 --- a/servers/slapd/add.c +++ b/servers/slapd/add.c @@ -36,7 +36,8 @@ #ifdef LDAP_SLAPI #include "slapi/slapi.h" -static void init_add_pblock( Operation *op, struct berval *dn, Entry *e, int manageDSAit ); +static void init_add_pblock( Operation *op, struct berval *dn, Entry *e, + int manageDSAit ); static int call_add_preop_plugins( Operation *op ); static void call_add_postop_plugins( Operation *op ); #endif /* LDAP_SLAPI */ @@ -46,7 +47,7 @@ do_add( Operation *op, SlapReply *rs ) { BerElement *ber = op->o_ber; char *last; - struct berval dn = { 0, NULL }; + struct berval dn = BER_BVNULL; ber_len_t len; ber_tag_t tag; Entry *e; @@ -86,7 +87,8 @@ do_add( Operation *op, SlapReply *rs ) e = (Entry *) ch_calloc( 1, sizeof(Entry) ); - rs->sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, op->o_tmpmemctx ); + rs->sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, + op->o_tmpmemctx ); if( rs->sr_err != LDAP_SUCCESS ) { #ifdef NEW_LOGGING @@ -253,8 +255,6 @@ do_add( Operation *op, SlapReply *rs ) int repl_user = be_isupdate( op ); #ifndef SLAPD_MULTIMASTER if ( !SLAP_SHADOW(op->o_bd) || repl_user ) -#else - if ( LDAP_STAILQ_EMPTY( &op->o_bd->be_syncinfo )) #endif { int update = op->o_bd->be_update_ndn.bv_len; @@ -485,11 +485,12 @@ slap_mods2entry( /* check if the values we're adding already exist */ if( mr == NULL || !mr->smr_match ) { - for ( i = 0; mods->sml_bvalues[i].bv_val != NULL; i++ ) { + for ( i = 1; mods->sml_values[i].bv_val != NULL; i++ ) { /* test asserted values against themselves */ for( j = 0; j < i; j++ ) { - if ( bvmatch( &mods->sml_bvalues[i], - &mods->sml_bvalues[j] ) ) { + if ( bvmatch( &mods->sml_values[i], + &mods->sml_values[j] ) ) + { /* value exists already */ snprintf( textbuf, textlen, "%s: value #%d provided more than once", @@ -503,11 +504,12 @@ slap_mods2entry( int rc = LDAP_SUCCESS; int match; - for ( i = 0; mods->sml_values[i].bv_val != NULL; i++ ) { + for ( i = 1; mods->sml_values[i].bv_val != NULL; i++ ) { /* test asserted values against themselves */ for( j = 0; j < i; j++ ) { rc = value_match( &match, mods->sml_desc, mr, - SLAP_MR_EQUALITY | SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX + SLAP_MR_EQUALITY + | SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX | SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH | SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH, mods->sml_nvalues @@ -536,17 +538,17 @@ slap_mods2entry( /* move ad to attr structure */ attr->a_desc = mods->sml_desc; - if ( !dup ) - mods->sml_desc = NULL; + if ( !dup ) mods->sml_desc = NULL; /* move values to attr structure */ /* should check for duplicates */ if ( dup ) { int i; - for ( i = 0; mods->sml_values[i].bv_val; i++ ) ; + for ( i = 0; mods->sml_values[i].bv_val; i++ ) /* EMPTY */; attr->a_vals = (BerVarray) ch_calloc( i+1, sizeof( BerValue )); - for ( i = 0; mods->sml_values[i].bv_val; i++ ) + for ( i = 0; mods->sml_values[i].bv_val; i++ ) { ber_dupbv( &attr->a_vals[i], &mods->sml_values[i] ); + } attr->a_vals[i].bv_len = 0; attr->a_vals[i].bv_val = NULL; } else { @@ -557,10 +559,11 @@ slap_mods2entry( if ( mods->sml_nvalues ) { if ( dup ) { int i; - for ( i = 0; mods->sml_nvalues[i].bv_val; i++ ) ; + for ( i = 0; mods->sml_nvalues[i].bv_val; i++ ) /* EMPTY */; attr->a_nvals = (BerVarray) ch_calloc( i+1, sizeof( BerValue )); - for ( i = 0; mods->sml_nvalues[i].bv_val; i++ ) + for ( i = 0; mods->sml_nvalues[i].bv_val; i++ ) { ber_dupbv( &attr->a_nvals[i], &mods->sml_nvalues[i] ); + } attr->a_nvals[i].bv_len = 0; attr->a_nvals[i].bv_val = NULL; } else { @@ -602,10 +605,10 @@ slap_entry2mods( mod->sml_type = a_new_desc->ad_cname; - for ( count = 0; a_new->a_vals[count].bv_val; count++ ); + for ( count = 0; a_new->a_vals[count].bv_val; count++ ) /* EMPTY */; - mod->sml_bvalues = (struct berval*) malloc( - (count+1) * sizeof( struct berval) ); + mod->sml_values = (struct berval*) malloc( + (count+1) * sizeof( struct berval) ); /* see slap_mods_check() comments... * if a_vals == a_nvals, there is no normalizer. @@ -619,17 +622,17 @@ slap_entry2mods( } for ( i = 0; i < count; i++ ) { - ber_dupbv(mod->sml_bvalues+i, a_new->a_vals+i); + ber_dupbv(mod->sml_values+i, a_new->a_vals+i); if ( mod->sml_nvalues ) { ber_dupbv( mod->sml_nvalues+i, a_new->a_vals+i ); } } - mod->sml_bvalues[count].bv_val = 0; - mod->sml_bvalues[count].bv_len = 0; + mod->sml_values[count].bv_val = NULL; + mod->sml_values[count].bv_len = 0; if ( mod->sml_nvalues ) { - mod->sml_nvalues[count].bv_val = 0; + mod->sml_nvalues[count].bv_val = NULL; mod->sml_nvalues[count].bv_len = 0; } diff --git a/servers/slapd/back-bdb/Makefile.in b/servers/slapd/back-bdb/Makefile.in index 2d83a900eb..120c24855c 100644 --- a/servers/slapd/back-bdb/Makefile.in +++ b/servers/slapd/back-bdb/Makefile.in @@ -32,7 +32,6 @@ LDAP_LIBDIR= ../../../libraries BUILD_OPT = "--enable-bdb" BUILD_MOD = @BUILD_BDB@ -BUILD_MOD_DYNAMIC = @BUILD_BDB_DYNAMIC@ mod_DEFS = -DSLAPD_IMPORT MOD_DEFS = $(@BUILD_BDB@_DEFS) diff --git a/servers/slapd/back-bdb/add.c b/servers/slapd/back-bdb/add.c index 6e7ccdb9b0..476043febe 100644 --- a/servers/slapd/back-bdb/add.c +++ b/servers/slapd/back-bdb/add.c @@ -298,8 +298,8 @@ retry: /* transaction retry */ * no parent! * if not attempting to add entry at suffix or with parent "" */ - if ((( !be_isroot( op ) && !be_isupdate(op)) || pdn.bv_len > 0 ) - && !is_entry_glue( op->oq_add.rs_e )) + if ((( !be_isroot( op ) && !be_shadow_update(op) ) + || pdn.bv_len > 0 ) && !is_entry_glue( op->oq_add.rs_e )) { #ifdef NEW_LOGGING LDAP_LOG ( OPERATION, DETAIL1, "bdb_add: %s denied\n", diff --git a/servers/slapd/back-bdb/attr.c b/servers/slapd/back-bdb/attr.c index 5540aef86d..dd545d2602 100644 --- a/servers/slapd/back-bdb/attr.c +++ b/servers/slapd/back-bdb/attr.c @@ -156,12 +156,9 @@ bdb_attr_index_config( } if( IS_SLAP_INDEX( mask, SLAP_INDEX_APPROX ) && !( - ( ad->ad_type->sat_approx + ad->ad_type->sat_approx && ad->ad_type->sat_approx->smr_indexer - && ad->ad_type->sat_approx->smr_filter ) - && ( ad->ad_type->sat_equality - && ad->ad_type->sat_equality->smr_indexer - && ad->ad_type->sat_equality->smr_filter ) ) ) + && ad->ad_type->sat_approx->smr_filter ) ) { fprintf( stderr, "%s: line %d: " "approx index of attribute \"%s\" disallowed\n", diff --git a/servers/slapd/back-bdb/config.c b/servers/slapd/back-bdb/config.c index 032472962c..31164d91c7 100644 --- a/servers/slapd/back-bdb/config.c +++ b/servers/slapd/back-bdb/config.c @@ -202,7 +202,6 @@ bdb_db_config( } se_id = atoi( argv[1] ); - se_size = atoi( argv[2] ); if ( se_id < 0 || se_id > 999 ) { #ifdef NEW_LOGGING @@ -217,7 +216,8 @@ bdb_db_config( return( 1 ); } - if ( se_size < 0 || se_size > 999 ) { + se_size = atoi( argv[2] ); + if ( se_size < 0 ) { #ifdef NEW_LOGGING LDAP_LOG( CONFIG, CRIT, "%s: line %d: session log size %d is negative\n", diff --git a/servers/slapd/back-bdb/ctxcsn.c b/servers/slapd/back-bdb/ctxcsn.c index 104ed0d86c..1b4706b0bd 100644 --- a/servers/slapd/back-bdb/ctxcsn.c +++ b/servers/slapd/back-bdb/ctxcsn.c @@ -39,7 +39,7 @@ bdb_csn_commit( ) { struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private; - struct berval ctxcsn_ndn = { 0, NULL }; + struct berval ctxcsn_ndn = BER_BVNULL; EntryInfo *ctxcsn_ei = NULL; DB_LOCK ctxcsn_lock; struct berval max_committed_csn; @@ -90,7 +90,7 @@ bdb_csn_commit( modvals[1].bv_len = 0; mod.sml_op = LDAP_MOD_REPLACE; - mod.sml_bvalues = modvals; + mod.sml_values = modvals; mod.sml_nvalues = NULL; mod.sml_desc = slap_schema.si_ad_contextCSN; mod.sml_type = mod.sml_desc->ad_cname; diff --git a/servers/slapd/back-bdb/delete.c b/servers/slapd/back-bdb/delete.c index 4f9bff15a1..84758b89f8 100644 --- a/servers/slapd/back-bdb/delete.c +++ b/servers/slapd/back-bdb/delete.c @@ -246,7 +246,7 @@ retry: /* transaction retry */ /* no parent, must be root to delete */ if( ! be_isroot( op ) ) { if ( be_issuffix( op->o_bd, (struct berval *)&slap_empty_bv ) - || be_isupdate( op ) ) { + || be_shadow_update( op ) ) { p = (Entry *)&slap_entry_root; /* check parent for "children" acl */ diff --git a/servers/slapd/back-bdb/index.c b/servers/slapd/back-bdb/index.c index f2d807eb52..e1f09f6fdc 100644 --- a/servers/slapd/back-bdb/index.c +++ b/servers/slapd/back-bdb/index.c @@ -121,9 +121,14 @@ int bdb_index_param( break; case LDAP_FILTER_APPROX: - if( IS_SLAP_INDEX( mask, SLAP_INDEX_APPROX ) ) { - goto done; + if ( desc->ad_type->sat_approx ) { + if( IS_SLAP_INDEX( mask, SLAP_INDEX_APPROX ) ) { + goto done; + } + break; } + + /* Use EQUALITY rule and index for approximate match */ /* fall thru */ case LDAP_FILTER_EQUALITY: diff --git a/servers/slapd/back-bdb/init.c b/servers/slapd/back-bdb/init.c index cd9d9a7c26..3bc535b211 100644 --- a/servers/slapd/back-bdb/init.c +++ b/servers/slapd/back-bdb/init.c @@ -36,7 +36,7 @@ static const struct bdbi_database { { NULL, NULL, 0, 0 } }; -struct berval bdb_uuid = { 0, NULL }; +struct berval bdb_uuid = BER_BVNULL; typedef void * db_malloc(size_t); typedef void * db_realloc(void *, size_t); @@ -553,8 +553,8 @@ bdb_db_destroy( BackendDB *be ) return 0; } -#if (defined(SLAPD_BDB_DYNAMIC) && !defined(BDB_HIER)) || \ - (defined(SLAPD_HDB_DYNAMIC) && defined(BDB_HIER)) +#if (SLAPD_BDB == SLAPD_MOD_DYNAMIC && !defined(BDB_HIER)) || \ + (SLAPD_HDB == SLAPD_MOD_DYNAMIC && defined(BDB_HIER)) int init_module( int argc, char *argv[] ) { BackendInfo bi; @@ -569,7 +569,7 @@ int init_module( int argc, char *argv[] ) { backend_add( &bi ); return 0; } -#endif /* SLAPD_BDB_DYNAMIC */ +#endif /* SLAPD_BDB */ int bdb_initialize( diff --git a/servers/slapd/back-bdb/modrdn.c b/servers/slapd/back-bdb/modrdn.c index b950479151..ed817dedb8 100644 --- a/servers/slapd/back-bdb/modrdn.c +++ b/servers/slapd/back-bdb/modrdn.c @@ -396,7 +396,7 @@ retry: /* transaction retry */ isroot = be_isroot( op ); if ( ! isroot ) { if ( be_issuffix( op->o_bd, (struct berval *)&slap_empty_bv ) - || be_isupdate( op ) ) { + || be_shadow_update( op ) ) { p = (Entry *)&slap_entry_root; diff --git a/servers/slapd/back-bdb/search.c b/servers/slapd/back-bdb/search.c index 97da998b23..170059eaed 100644 --- a/servers/slapd/back-bdb/search.c +++ b/servers/slapd/back-bdb/search.c @@ -373,20 +373,19 @@ bdb_do_search( Operation *op, SlapReply *rs, Operation *sop, ID id, cursor; ID candidates[BDB_IDL_UM_SIZE]; ID scopes[BDB_IDL_DB_SIZE]; - Entry *e = NULL, base; - Entry *matched = NULL; - EntryInfo *ei; - struct berval realbase = { 0, NULL }; + Entry *e = NULL, base, e_root = {0}; + Entry *matched = NULL; + EntryInfo *ei, ei_root = {0}; + struct berval realbase = BER_BVNULL; int manageDSAit; int tentries = 0; ID lastid = NOID; AttributeName *attrs; - Filter contextcsnand, contextcsnle, cookief, csnfnot, - csnfeq, csnfand, csnfge; + Filter contextcsnand, contextcsnle, cookief, csnfnot, + csnfeq, csnfand, csnfge; AttributeAssertion aa_ge, aa_eq, aa_le; - int entry_count = 0; - struct berval *search_context_csn = NULL; + struct berval *search_context_csn = NULL; DB_LOCK ctxcsn_lock; LDAPControl *ctrls[SLAP_MAX_RESPONSE_CONTROLS]; int num_ctrls = 0; @@ -522,7 +521,11 @@ bdb_do_search( Operation *op, SlapReply *rs, Operation *sop, if ( sop->o_req_ndn.bv_len == 0 ) { /* DIT root special case */ - e = (Entry *) &slap_entry_root; + ei_root.bei_e = &e_root; + ei_root.bei_parent = &ei_root; + e_root.e_private = &ei_root; + e_root.e_id = 1; + ei = &ei_root; rs->sr_err = LDAP_SUCCESS; } else { dn2entry_retry: @@ -558,7 +561,7 @@ dn2entry_retry: } if ( e == NULL ) { - struct berval matched_dn = { 0, NULL }; + struct berval matched_dn = BER_BVNULL; if ( matched != NULL ) { BerVarray erefs; @@ -599,7 +602,7 @@ dn2entry_retry: return rs->sr_err; } - if ( !manageDSAit && e != &slap_entry_root && is_entry_referral( e ) ) { + if ( !manageDSAit && e != &e_root && is_entry_referral( e ) ) { /* entry is a referral, don't allow add */ struct berval matched_dn; BerVarray erefs; @@ -658,7 +661,7 @@ dn2entry_retry: base.e_nname = realbase; base.e_id = e->e_id; - if ( e != &slap_entry_root ) { + if ( e != &e_root ) { bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, e, &lock); } e = NULL; @@ -751,6 +754,7 @@ dn2entry_retry: if ( get_pagedresults(sop) ) { if ( sop->o_pagedresults_state.ps_cookie == 0 ) { id = 0; + } else { if ( sop->o_pagedresults_size == 0 ) { rs->sr_err = LDAP_SUCCESS; @@ -1100,8 +1104,8 @@ id2entry_retry: if ( rs->sr_err == LDAP_COMPARE_TRUE ) { /* check size limit */ - if ( --sop->ors_slimit == -1 && - sop->o_sync_slog_size == -1 ) + if ( --sop->ors_slimit == -1 && + sop->o_sync_slog_size == -1 ) { if (!IS_PSEARCH) { bdb_cache_return_entry_r( bdb->bi_dbenv, @@ -1263,6 +1267,7 @@ id2entry_retry: rs->sr_attrs = sop->oq_search.rs_attrs; rs->sr_ctrls = NULL; rs->sr_flags = 0; + rs->sr_err = LDAP_SUCCESS; result = send_search_entry( sop, rs ); } } @@ -1674,7 +1679,7 @@ send_pagerequest_response( LDAPControl ctrl, *ctrls[2]; BerElementBuffer berbuf; BerElement *ber = (BerElement *)&berbuf; - struct berval cookie = { 0, NULL }; + struct berval cookie = BER_BVNULL; PagedResultsCookie respcookie; #ifdef NEW_LOGGING @@ -1695,6 +1700,7 @@ send_pagerequest_response( respcookie = ( PagedResultsCookie )lastid; op->o_conn->c_pagedresults_state.ps_cookie = respcookie; + op->o_conn->c_pagedresults_state.ps_count = op->o_pagedresults_state.ps_count + rs->sr_nentries; cookie.bv_len = sizeof( respcookie ); cookie.bv_val = (char *)&respcookie; @@ -1717,4 +1723,5 @@ send_pagerequest_response( done: (void) ber_free_buf( ber ); -} +} + diff --git a/servers/slapd/back-dnssrv/Makefile.in b/servers/slapd/back-dnssrv/Makefile.in index 2d0b5b3cc1..214e9f7073 100644 --- a/servers/slapd/back-dnssrv/Makefile.in +++ b/servers/slapd/back-dnssrv/Makefile.in @@ -26,7 +26,6 @@ LDAP_LIBDIR= ../../../libraries BUILD_OPT = "--enable-dnssrv" BUILD_MOD = @BUILD_DNSSRV@ -BUILD_MOD_DYNAMIC = @BUILD_DNSSRV_DYNAMIC@ mod_DEFS = -DSLAPD_IMPORT MOD_DEFS = $(@BUILD_DNSSRV@_DEFS) diff --git a/servers/slapd/back-dnssrv/init.c b/servers/slapd/back-dnssrv/init.c index c6a994bd0c..fc8e99146f 100644 --- a/servers/slapd/back-dnssrv/init.c +++ b/servers/slapd/back-dnssrv/init.c @@ -28,7 +28,7 @@ #include "slap.h" #include "external.h" -#ifdef SLAPD_DNSSRV_DYNAMIC +#if SLAPD_DNSSRV == SLAPD_MOD_DYNAMIC int init_module(int argc, char *argv[]) { @@ -42,7 +42,7 @@ int init_module(int argc, char *argv[]) return 0; } -#endif /* SLAPD_DNSSRV_DYNAMIC */ +#endif /* SLAPD_DNSSRV */ int dnssrv_back_initialize( diff --git a/servers/slapd/back-hdb/Makefile.in b/servers/slapd/back-hdb/Makefile.in index e3587b412b..bfde2be32c 100644 --- a/servers/slapd/back-hdb/Makefile.in +++ b/servers/slapd/back-hdb/Makefile.in @@ -34,7 +34,6 @@ LDAP_LIBDIR= ../../../libraries BUILD_OPT = "--enable-hdb" BUILD_MOD = @BUILD_HDB@ -BUILD_MOD_DYNAMIC = @BUILD_HDB_DYNAMIC@ mod_DEFS = -DSLAPD_IMPORT MOD_DEFS = $(@BUILD_HDB@_DEFS) diff --git a/servers/slapd/back-ldap/Makefile.in b/servers/slapd/back-ldap/Makefile.in index 6e20734bde..df71666651 100644 --- a/servers/slapd/back-ldap/Makefile.in +++ b/servers/slapd/back-ldap/Makefile.in @@ -25,7 +25,6 @@ LDAP_LIBDIR= ../../../libraries BUILD_OPT = "--enable-ldap" BUILD_MOD = @BUILD_LDAP@ -BUILD_MOD_DYNAMIC = @BUILD_LDAP_DYNAMIC@ mod_DEFS = -DSLAPD_IMPORT MOD_DEFS = $(@BUILD_LDAP@_DEFS) diff --git a/servers/slapd/back-ldap/init.c b/servers/slapd/back-ldap/init.c index 8fb695fe12..a9d11f7105 100644 --- a/servers/slapd/back-ldap/init.c +++ b/servers/slapd/back-ldap/init.c @@ -31,7 +31,7 @@ #include "slap.h" #include "back-ldap.h" -#ifdef SLAPD_LDAP_DYNAMIC +#if SLAPD_LDAP == SLAPD_MOD_DYNAMIC int init_module(int argc, char *argv[]) { BackendInfo bi; @@ -44,7 +44,7 @@ int init_module(int argc, char *argv[]) { return 0; } -#endif /* SLAPD_LDAP_DYNAMIC */ +#endif /* SLAPD_LDAP */ int ldap_back_initialize( diff --git a/servers/slapd/back-ldap/modify.c b/servers/slapd/back-ldap/modify.c index b40664261f..95247cbeef 100644 --- a/servers/slapd/back-ldap/modify.c +++ b/servers/slapd/back-ldap/modify.c @@ -43,7 +43,7 @@ ldap_back_modify( Modifications *ml; int i, j, rc; struct berval mapped; - struct berval mdn = { 0, NULL }; + struct berval mdn = BER_BVNULL; ber_int_t msgid; dncookie dc; int isupdate; @@ -91,7 +91,7 @@ ldap_back_modify( dc.ctx = "modifyAttrDN"; #endif - isupdate = be_isupdate( op ); + isupdate = be_shadow_update( op ); for (i=0, ml=op->oq_modify.rs_modlist; ml; ml=ml->sml_next) { int is_oc = 0; @@ -117,42 +117,42 @@ ldap_back_modify( mods[i].mod_op = ml->sml_op | LDAP_MOD_BVALUES; mods[i].mod_type = mapped.bv_val; - if ( ml->sml_bvalues != NULL ) { + if ( ml->sml_values != NULL ) { if ( is_oc ) { - for (j = 0; ml->sml_bvalues[j].bv_val; j++); - mods[i].mod_bvalues = (struct berval **)ch_malloc((j+1) * + for (j = 0; ml->sml_values[j].bv_val; j++); + mods[i].mod_values = (struct berval **)ch_malloc((j+1) * sizeof(struct berval *)); - for (j = 0; ml->sml_bvalues[j].bv_val; j++) { + for (j = 0; ml->sml_values[j].bv_val; j++) { ldap_back_map(&li->rwmap.rwm_oc, - &ml->sml_bvalues[j], + &ml->sml_values[j], &mapped, BACKLDAP_MAP); if (mapped.bv_val == NULL || mapped.bv_val[0] == '\0') { continue; } - mods[i].mod_bvalues[j] = &mapped; + mods[i].mod_values[j] = &mapped; } - mods[i].mod_bvalues[j] = NULL; + mods[i].mod_values[j] = NULL; } else { if ( ml->sml_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName ) { - ldap_dnattr_rewrite( &dc, ml->sml_bvalues ); + ldap_dnattr_rewrite( &dc, ml->sml_values ); } - if ( ml->sml_bvalues == NULL ) { + if ( ml->sml_values == NULL ) { continue; } - for (j = 0; ml->sml_bvalues[j].bv_val; j++); - mods[i].mod_bvalues = (struct berval **)ch_malloc((j+1) * + for (j = 0; ml->sml_values[j].bv_val; j++); + mods[i].mod_values = (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; + for (j = 0; ml->sml_values[j].bv_val; j++) + mods[i].mod_values[j] = &ml->sml_values[j]; + mods[i].mod_values[j] = NULL; } } else { - mods[i].mod_bvalues = NULL; + mods[i].mod_values = NULL; } i++; @@ -186,7 +186,7 @@ cleanup:; free( mdn.bv_val ); } for (i=0; modv[i]; i++) { - ch_free(modv[i]->mod_bvalues); + ch_free(modv[i]->mod_values); } ch_free( mods ); ch_free( modv ); diff --git a/servers/slapd/back-ldbm/Makefile.in b/servers/slapd/back-ldbm/Makefile.in index 235c2661a9..14057f42b6 100644 --- a/servers/slapd/back-ldbm/Makefile.in +++ b/servers/slapd/back-ldbm/Makefile.in @@ -31,7 +31,6 @@ LDAP_LIBDIR= ../../../libraries BUILD_OPT = "--enable-ldbm" BUILD_MOD = @BUILD_LDBM@ -BUILD_MOD_DYNAMIC = @BUILD_LDBM_DYNAMIC@ mod_DEFS = -DSLAPD_IMPORT MOD_DEFS = $(@BUILD_LDBM@_DEFS) diff --git a/servers/slapd/back-ldbm/add.c b/servers/slapd/back-ldbm/add.c index d621eeb2a8..e1dfbbbb8f 100644 --- a/servers/slapd/back-ldbm/add.c +++ b/servers/slapd/back-ldbm/add.c @@ -247,8 +247,8 @@ ldbm_back_add( } else { assert( pdn.bv_val == NULL || *pdn.bv_val == '\0' ); - if (( !be_isroot( op ) && !be_isupdate( op )) && - !is_entry_glue( op->oq_add.rs_e )) + if (( !be_isroot(op) && !be_shadow_update(op) ) + && !is_entry_glue( op->oq_add.rs_e )) { ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock); diff --git a/servers/slapd/back-ldbm/attr.c b/servers/slapd/back-ldbm/attr.c index 1ce058b966..bb49d279c2 100644 --- a/servers/slapd/back-ldbm/attr.c +++ b/servers/slapd/back-ldbm/attr.c @@ -156,12 +156,9 @@ attr_index_config( } if( IS_SLAP_INDEX( mask, SLAP_INDEX_APPROX ) && !( - ( ad->ad_type->sat_approx + ad->ad_type->sat_approx && ad->ad_type->sat_approx->smr_indexer - && ad->ad_type->sat_approx->smr_filter ) - && ( ad->ad_type->sat_equality - && ad->ad_type->sat_equality->smr_indexer - && ad->ad_type->sat_equality->smr_filter ) ) ) + && ad->ad_type->sat_approx->smr_filter ) ) { fprintf( stderr, "%s: line %d: " "approx index of attribute \"%s\" disallowed\n", diff --git a/servers/slapd/back-ldbm/delete.c b/servers/slapd/back-ldbm/delete.c index 7acf90ac89..234b30a3ab 100644 --- a/servers/slapd/back-ldbm/delete.c +++ b/servers/slapd/back-ldbm/delete.c @@ -195,7 +195,8 @@ ldbm_back_delete( } else { /* no parent, must be root to delete */ if( ! be_isroot( op ) ) { - if ( be_issuffix( op->o_bd, (struct berval *)&slap_empty_bv ) || be_isupdate( op ) ) { + if ( be_issuffix( op->o_bd, (struct berval *)&slap_empty_bv ) + || be_shadow_update( op ) ) { p = (Entry *)&slap_entry_root; rc = access_allowed( op, p, diff --git a/servers/slapd/back-ldbm/index.c b/servers/slapd/back-ldbm/index.c index 13956bbc1e..90911d36ad 100644 --- a/servers/slapd/back-ldbm/index.c +++ b/servers/slapd/back-ldbm/index.c @@ -115,9 +115,14 @@ int index_param( break; case LDAP_FILTER_APPROX: - if( IS_SLAP_INDEX( mask, SLAP_INDEX_APPROX ) ) { - goto done; + if ( desc->ad_type->sat_approx ) { + if( IS_SLAP_INDEX( mask, SLAP_INDEX_APPROX ) ) { + goto done; + } + break; } + + /* Use EQUALITY rule and index for approximate match */ /* fall thru */ case LDAP_FILTER_EQUALITY: diff --git a/servers/slapd/back-ldbm/init.c b/servers/slapd/back-ldbm/init.c index 3a24c9f81a..eb5a5afc58 100644 --- a/servers/slapd/back-ldbm/init.c +++ b/servers/slapd/back-ldbm/init.c @@ -24,7 +24,7 @@ #include "slap.h" #include "back-ldbm.h" -#ifdef SLAPD_LDBM_DYNAMIC +#if SLAPD_LDBM == SLAPD_MOD_DYNAMIC int init_module(int argc, char *argv[]) { BackendInfo bi; @@ -37,7 +37,7 @@ int init_module(int argc, char *argv[]) { return 0; } -#endif /* SLAPD_LDBM_DYNAMIC */ +#endif /* SLAPD_LDBM */ int ldbm_back_initialize( diff --git a/servers/slapd/back-ldbm/modrdn.c b/servers/slapd/back-ldbm/modrdn.c index 9a404409ca..ccc7bf9233 100644 --- a/servers/slapd/back-ldbm/modrdn.c +++ b/servers/slapd/back-ldbm/modrdn.c @@ -42,8 +42,8 @@ ldbm_back_modrdn( AttributeDescription *entry = slap_schema.si_ad_entry; struct ldbminfo *li = (struct ldbminfo *) op->o_bd->be_private; struct berval p_dn, p_ndn; - struct berval new_dn = { 0, NULL}, new_ndn = { 0, NULL }; - struct berval old_ndn = { 0, NULL }; + struct berval new_dn = BER_BVNULL, new_ndn = BER_BVNULL; + struct berval old_ndn = BER_BVNULL; Entry *e, *p = NULL; Entry *matched; /* LDAP v2 supporting correct attribute handling. */ @@ -248,7 +248,8 @@ ldbm_back_modrdn( /* no parent, must be root to modify rdn */ isroot = be_isroot( op ); if ( ! isroot ) { - if ( be_issuffix( op->o_bd, (struct berval *)&slap_empty_bv ) || be_isupdate( op ) ) { + if ( be_issuffix( op->o_bd, (struct berval *)&slap_empty_bv ) + || be_shadow_update( op ) ) { int can_access; p = (Entry *)&slap_entry_root; @@ -422,7 +423,8 @@ ldbm_back_modrdn( } if ( ! isroot ) { - if ( be_issuffix( op->o_bd, (struct berval *)&slap_empty_bv ) || be_isupdate( op ) ) { + if ( be_issuffix( op->o_bd, (struct berval *)&slap_empty_bv ) + || be_shadow_update( op ) ) { int can_access; np = (Entry *)&slap_entry_root; diff --git a/servers/slapd/back-meta/Makefile.in b/servers/slapd/back-meta/Makefile.in index 7a74370b8c..2b31e51000 100644 --- a/servers/slapd/back-meta/Makefile.in +++ b/servers/slapd/back-meta/Makefile.in @@ -25,7 +25,6 @@ LDAP_LIBDIR= ../../../libraries BUILD_OPT = "--enable-meta" BUILD_MOD = @BUILD_META@ -BUILD_MOD_DYNAMIC = @BUILD_META_DYNAMIC@ mod_DEFS = -DSLAPD_IMPORT MOD_DEFS = $(@BUILD_META@_DEFS) diff --git a/servers/slapd/back-meta/init.c b/servers/slapd/back-meta/init.c index 43ad07873f..8ed7cb7379 100644 --- a/servers/slapd/back-meta/init.c +++ b/servers/slapd/back-meta/init.c @@ -26,7 +26,7 @@ #include "../back-ldap/back-ldap.h" #include "back-meta.h" -#ifdef SLAPD_META_DYNAMIC +#if SLAPD_META == SLAPD_MOD_DYNAMIC int init_module( int argc, char *argv[] ) { @@ -40,7 +40,7 @@ init_module( int argc, char *argv[] ) { return 0; } -#endif /* SLAPD_META_DYNAMIC */ +#endif /* SLAPD_META */ int meta_back_initialize( diff --git a/servers/slapd/back-monitor/Makefile.in b/servers/slapd/back-monitor/Makefile.in index 8d96a56407..3d14f33318 100644 --- a/servers/slapd/back-monitor/Makefile.in +++ b/servers/slapd/back-monitor/Makefile.in @@ -29,7 +29,6 @@ LDAP_LIBDIR= ../../../libraries BUILD_OPT = "--enable-monitor" BUILD_MOD = @BUILD_MONITOR@ -BUILD_MOD_DYNAMIC = @BUILD_MONITOR_DYNAMIC@ mod_DEFS = -DSLAPD_IMPORT MOD_DEFS = $(@BUILD_MONITOR@_DEFS) diff --git a/servers/slapd/back-monitor/README b/servers/slapd/back-monitor/README index 24216eba7e..dc1d9f72df 100644 --- a/servers/slapd/back-monitor/README +++ b/servers/slapd/back-monitor/README @@ -209,7 +209,7 @@ It shows some statistics on the data sent by the server: -TIME SUBSISTEM +TIME SUBSYSTEM It contains two subentries with the start time and the current time of the server. diff --git a/servers/slapd/back-monitor/init.c b/servers/slapd/back-monitor/init.c index 92e90f7880..6173c12949 100644 --- a/servers/slapd/back-monitor/init.c +++ b/servers/slapd/back-monitor/init.c @@ -147,7 +147,7 @@ struct monitorsubsys monitor_subsys[] = { }, { -1, NULL } }; -#ifdef SLAPD_MONITOR_DYNAMIC +#if SLAPD_MONITOR == SLAPD_MOD_DYNAMIC int init_module( int argc, char *argv[] ) @@ -161,7 +161,7 @@ init_module( int argc, char *argv[] ) return 0; } -#endif /* SLAPD_MONITOR_DYNAMIC */ +#endif /* SLAPD_MONITOR */ int monitor_back_initialize( @@ -251,7 +251,7 @@ monitor_back_db_init( be_monitor = be; /* indicate system schema supported */ - SLAP_DBFLAGS(be) |= SLAP_BFLAG_MONITOR; + SLAP_BFLAGS(be) |= SLAP_BFLAG_MONITOR; dn.bv_val = SLAPD_MONITOR_DN; dn.bv_len = sizeof( SLAPD_MONITOR_DN ) - 1; diff --git a/servers/slapd/back-monitor/log.c b/servers/slapd/back-monitor/log.c index 7fa5f548b0..9e99fb1eed 100644 --- a/servers/slapd/back-monitor/log.c +++ b/servers/slapd/back-monitor/log.c @@ -41,21 +41,21 @@ static struct { struct berval s; struct berval n; } int_2_level[] = { - { LDAP_DEBUG_TRACE, BER_BVC("Trace"), { 0, NULL } }, - { LDAP_DEBUG_PACKETS, BER_BVC("Packets"), { 0, NULL } }, - { LDAP_DEBUG_ARGS, BER_BVC("Args"), { 0, NULL } }, - { LDAP_DEBUG_CONNS, BER_BVC("Conns"), { 0, NULL } }, - { LDAP_DEBUG_BER, BER_BVC("BER"), { 0, NULL } }, - { LDAP_DEBUG_FILTER, BER_BVC("Filter"), { 0, NULL } }, - { LDAP_DEBUG_CONFIG, BER_BVC("Config"), { 0, NULL } }, /* useless */ - { LDAP_DEBUG_ACL, BER_BVC("ACL"), { 0, NULL } }, - { LDAP_DEBUG_STATS, BER_BVC("Stats"), { 0, NULL } }, - { LDAP_DEBUG_STATS2, BER_BVC("Stats2"), { 0, NULL } }, - { LDAP_DEBUG_SHELL, BER_BVC("Shell"), { 0, NULL } }, - { LDAP_DEBUG_PARSE, BER_BVC("Parse"), { 0, NULL } }, - { LDAP_DEBUG_CACHE, BER_BVC("Cache"), { 0, NULL } }, - { LDAP_DEBUG_INDEX, BER_BVC("Index"), { 0, NULL } }, - { 0, { 0, NULL }, { 0, NULL } } + { LDAP_DEBUG_TRACE, BER_BVC("Trace"), BER_BVNULL }, + { LDAP_DEBUG_PACKETS, BER_BVC("Packets"), BER_BVNULL }, + { LDAP_DEBUG_ARGS, BER_BVC("Args"), BER_BVNULL }, + { LDAP_DEBUG_CONNS, BER_BVC("Conns"), BER_BVNULL }, + { LDAP_DEBUG_BER, BER_BVC("BER"), BER_BVNULL }, + { LDAP_DEBUG_FILTER, BER_BVC("Filter"), BER_BVNULL }, + { LDAP_DEBUG_CONFIG, BER_BVC("Config"), BER_BVNULL }, /* useless */ + { LDAP_DEBUG_ACL, BER_BVC("ACL"), BER_BVNULL }, + { LDAP_DEBUG_STATS, BER_BVC("Stats"), BER_BVNULL }, + { LDAP_DEBUG_STATS2, BER_BVC("Stats2"), BER_BVNULL }, + { LDAP_DEBUG_SHELL, BER_BVC("Shell"), BER_BVNULL }, + { LDAP_DEBUG_PARSE, BER_BVC("Parse"), BER_BVNULL }, + { LDAP_DEBUG_CACHE, BER_BVC("Cache"), BER_BVNULL }, + { LDAP_DEBUG_INDEX, BER_BVC("Index"), BER_BVNULL }, + { 0, BER_BVNULL, BER_BVNULL } }; static int loglevel2int( struct berval *l ); @@ -79,7 +79,7 @@ monitor_subsys_log_init( struct berval desc[] = { BER_BVC("This entry allows to set the log level runtime."), BER_BVC("Set the attribute 'managedInfo' to the desired log levels."), - { 0, NULL } + BER_BVNULL }; ldap_pvt_thread_mutex_init( &monitor_log_mutex ); @@ -160,8 +160,7 @@ monitor_subsys_log_modify( */ if ( is_at_operational( mod->sm_desc->ad_type ) ) { ( void ) attr_delete( &e->e_attrs, mod->sm_desc ); - rc = attr_merge( e, mod->sm_desc, mod->sm_bvalues, - mod->sm_nvalues ); + rc = attr_merge( e, mod->sm_desc, mod->sm_values, mod->sm_nvalues ); if ( rc != 0 ) { rc = LDAP_OTHER; break; @@ -283,10 +282,10 @@ check_constraints( Modification *mod, int *newlevel ) { int i; - for ( i = 0; mod->sm_bvalues && mod->sm_bvalues[i].bv_val != NULL; i++ ) { + for ( i = 0; mod->sm_values && mod->sm_values[i].bv_val != NULL; i++ ) { int l; - l = loglevel2int( &mod->sm_bvalues[i] ); + l = loglevel2int( &mod->sm_values[i] ); if ( !l ) { return LDAP_CONSTRAINT_VIOLATION; } @@ -296,9 +295,9 @@ check_constraints( Modification *mod, int *newlevel ) } assert( int_2_level[ l ].s.bv_len - == mod->sm_bvalues[i].bv_len ); + == mod->sm_values[i].bv_len ); - AC_MEMCPY( mod->sm_bvalues[i].bv_val, + AC_MEMCPY( mod->sm_values[i].bv_val, int_2_level[ l ].s.bv_val, int_2_level[ l ].s.bv_len ); @@ -332,7 +331,7 @@ add_values( Entry *e, Modification *mod, int *newlevel ) return LDAP_INAPPROPRIATE_MATCHING; } - for ( i = 0; mod->sm_bvalues[i].bv_val != NULL; i++ ) { + for ( i = 0; mod->sm_values[i].bv_val != NULL; i++ ) { int rc; int j; const char *text = NULL; @@ -340,7 +339,7 @@ add_values( Entry *e, Modification *mod, int *newlevel ) rc = asserted_value_validate_normalize( mod->sm_desc, mr, SLAP_MR_EQUALITY, - &mod->sm_bvalues[i], &asserted, &text, NULL ); + &mod->sm_values[i], &asserted, &text, NULL ); if ( rc != LDAP_SUCCESS ) { return rc; @@ -349,8 +348,7 @@ add_values( Entry *e, Modification *mod, int *newlevel ) for ( j = 0; a->a_vals[j].bv_val != NULL; j++ ) { int match; int rc = value_match( &match, mod->sm_desc, mr, - 0, - &a->a_vals[j], &asserted, &text ); + 0, &a->a_vals[j], &asserted, &text ); if ( rc == LDAP_SUCCESS && match == 0 ) { free( asserted.bv_val ); @@ -363,7 +361,7 @@ add_values( Entry *e, Modification *mod, int *newlevel ) } /* no - add them */ - rc = attr_merge( e, mod->sm_desc, mod->sm_bvalues, mod->sm_nvalues ); + rc = attr_merge( e, mod->sm_desc, mod->sm_values, mod->sm_nvalues ); if ( rc != LDAP_SUCCESS ) { /* this should return result of attr_mergeit */ return rc; @@ -387,7 +385,7 @@ delete_values( Entry *e, Modification *mod, int *newlevel ) *newlevel &= ~nl; /* delete the entire attribute */ - if ( mod->sm_bvalues == NULL ) { + if ( mod->sm_values == NULL ) { int rc = attr_delete( &e->e_attrs, mod->sm_desc ); if ( rc ) { @@ -411,7 +409,7 @@ delete_values( Entry *e, Modification *mod, int *newlevel ) } /* find each value to delete */ - for ( i = 0; mod->sm_bvalues[i].bv_val != NULL; i++ ) { + for ( i = 0; mod->sm_values[i].bv_val != NULL; i++ ) { int rc; const char *text = NULL; @@ -419,7 +417,7 @@ delete_values( Entry *e, Modification *mod, int *newlevel ) rc = asserted_value_validate_normalize( mod->sm_desc, mr, SLAP_MR_EQUALITY, - &mod->sm_bvalues[i], &asserted, &text, NULL ); + &mod->sm_values[i], &asserted, &text, NULL ); if( rc != LDAP_SUCCESS ) return rc; @@ -485,9 +483,8 @@ replace_values( Entry *e, Modification *mod, int *newlevel ) return rc; } - if ( mod->sm_bvalues != NULL ) { - rc = attr_merge( e, mod->sm_desc, mod->sm_bvalues, - mod->sm_nvalues ); + if ( mod->sm_values != NULL ) { + rc = attr_merge( e, mod->sm_desc, mod->sm_values, mod->sm_nvalues ); if ( rc != LDAP_SUCCESS ) { return rc; } diff --git a/servers/slapd/back-monitor/operation.c b/servers/slapd/back-monitor/operation.c index 0c23b779eb..8d9982bd89 100644 --- a/servers/slapd/back-monitor/operation.c +++ b/servers/slapd/back-monitor/operation.c @@ -40,7 +40,7 @@ static struct berval BER_BVC( "Search" ), BER_BVC( "Abandon" ), BER_BVC( "Extended" ), - { 0, NULL } + BER_BVNULL }; int diff --git a/servers/slapd/back-null/Makefile.in b/servers/slapd/back-null/Makefile.in index df952e312e..0c5b9df8a1 100644 --- a/servers/slapd/back-null/Makefile.in +++ b/servers/slapd/back-null/Makefile.in @@ -21,7 +21,6 @@ LDAP_LIBDIR= ../../../libraries BUILD_OPT = "--enable-null" BUILD_MOD = @BUILD_NULL@ -BUILD_MOD_DYNAMIC = @BUILD_NULL_DYNAMIC@ mod_DEFS = -DSLAPD_IMPORT MOD_DEFS = $(@BUILD_NULL@_DEFS) diff --git a/servers/slapd/back-null/null.c b/servers/slapd/back-null/null.c index d8d6c47e4b..e87575862c 100644 --- a/servers/slapd/back-null/null.c +++ b/servers/slapd/back-null/null.c @@ -156,8 +156,8 @@ null_back_initialize( return 0; } -#ifdef SLAPD_NULL_DYNAMIC -int back_null_LTX_init_module( +#if SLAPD_NULL == SLAPD_MOD_DYNAMIC +int init_module( int argc, char *argv[] ) { @@ -170,4 +170,4 @@ int back_null_LTX_init_module( backend_add(&bi); return 0; } -#endif /* SLAPD_NULL_DYNAMIC */ +#endif /* SLAPD_NULL */ diff --git a/servers/slapd/back-passwd/Makefile.in b/servers/slapd/back-passwd/Makefile.in index d53dd54451..0cdf61d86c 100644 --- a/servers/slapd/back-passwd/Makefile.in +++ b/servers/slapd/back-passwd/Makefile.in @@ -21,7 +21,6 @@ LDAP_LIBDIR= ../../../libraries BUILD_OPT = "--enable-passwd" BUILD_MOD = @BUILD_PASSWD@ -BUILD_MOD_DYNAMIC = @BUILD_PASSWD_DYNAMIC@ mod_DEFS = -DSLAPD_IMPORT MOD_DEFS = $(@BUILD_PASSWD@_DEFS) diff --git a/servers/slapd/back-passwd/init.c b/servers/slapd/back-passwd/init.c index 5c5e416102..1ef59c31e6 100644 --- a/servers/slapd/back-passwd/init.c +++ b/servers/slapd/back-passwd/init.c @@ -25,7 +25,7 @@ ldap_pvt_thread_mutex_t passwd_mutex; -#ifdef SLAPD_PASSWD_DYNAMIC +#if SLAPD_PASSWD == SLAPD_MOD_DYNAMIC int init_module(int argc, char *argv[]) { BackendInfo bi; @@ -38,7 +38,7 @@ int init_module(int argc, char *argv[]) { return 0; } -#endif /* SLAPD_PASSWD_DYNAMIC */ +#endif /* SLAPD_PASSWD */ int passwd_back_initialize( diff --git a/servers/slapd/back-perl/Makefile.in b/servers/slapd/back-perl/Makefile.in index 72adf62ade..ef536c7b6d 100644 --- a/servers/slapd/back-perl/Makefile.in +++ b/servers/slapd/back-perl/Makefile.in @@ -24,7 +24,6 @@ LDAP_LIBDIR= ../../../libraries BUILD_OPT = "--enable-perl" BUILD_MOD = @BUILD_PERL@ -BUILD_MOD_DYNAMIC = @BUILD_PERL_DYNAMIC@ PERL_CPPFLAGS = @PERL_CPPFLAGS@ mod_DEFS = -DSLAPD_IMPORT diff --git a/servers/slapd/back-perl/init.c b/servers/slapd/back-perl/init.c index 634d4932f8..59dc3a06bc 100644 --- a/servers/slapd/back-perl/init.c +++ b/servers/slapd/back-perl/init.c @@ -38,7 +38,7 @@ EXT void boot_DynaLoader LDAP_P((PERL_BACK_BOOT_DYNALOADER_PARAMS)); PerlInterpreter *PERL_INTERPRETER = NULL; ldap_pvt_thread_mutex_t perl_interpreter_mutex; -#ifdef SLAPD_PERL_DYNAMIC +#if SLAPD_PERL == SLAPD_MOD_DYNAMIC int init_module(int argc, char *argv[]) { @@ -52,7 +52,7 @@ int init_module(int argc, char *argv[]) return 0; } -#endif /* SLAPD_PERL_DYNAMIC */ +#endif /* SLAPD_PERL */ /********************************************************** diff --git a/servers/slapd/back-shell/Makefile.in b/servers/slapd/back-shell/Makefile.in index 105a58af23..b8e94e7cbc 100644 --- a/servers/slapd/back-shell/Makefile.in +++ b/servers/slapd/back-shell/Makefile.in @@ -23,7 +23,6 @@ LDAP_LIBDIR= ../../../libraries BUILD_OPT = "--enable-shell" BUILD_MOD = @BUILD_SHELL@ -BUILD_MOD_DYNAMIC = @BUILD_SHELL_DYNAMIC@ mod_DEFS = -DSLAPD_IMPORT MOD_DEFS = $(@BUILD_SHELL@_DEFS) diff --git a/servers/slapd/back-shell/init.c b/servers/slapd/back-shell/init.c index eb684c2bb1..56f4b75a8d 100644 --- a/servers/slapd/back-shell/init.c +++ b/servers/slapd/back-shell/init.c @@ -37,7 +37,7 @@ #include "slap.h" #include "shell.h" -#ifdef SLAPD_SHELL_DYNAMIC +#if SLAPD_SHELL == SLAPD_MOD_DYNAMIC int init_module(int argc, char *argv[]) { BackendInfo bi; @@ -50,7 +50,7 @@ int init_module(int argc, char *argv[]) { return 0; } -#endif /* SLAPD_SHELL_DYNAMIC */ +#endif /* SLAPD_SHELL */ int shell_back_initialize( diff --git a/servers/slapd/back-sql/Makefile.in b/servers/slapd/back-sql/Makefile.in index 7037bdea3b..fe32d8bd34 100644 --- a/servers/slapd/back-sql/Makefile.in +++ b/servers/slapd/back-sql/Makefile.in @@ -15,17 +15,16 @@ SRCS = init.c config.c search.c bind.c compare.c operational.c \ entry-id.c schema-map.c sql-wrap.c modify.c util.c \ - add.c delete.c modrdn.c + add.c delete.c modrdn.c api.c OBJS = init.lo config.lo search.lo bind.lo compare.lo operational.lo \ entry-id.lo schema-map.lo sql-wrap.lo modify.lo util.lo \ - add.lo delete.lo modrdn.lo + add.lo delete.lo modrdn.lo api.lo LDAP_INCDIR= ../../../include LDAP_LIBDIR= ../../../libraries BUILD_OPT = "--enable-sql" BUILD_MOD = @BUILD_SQL@ -BUILD_MOD_DYNAMIC = @BUILD_SQL_DYNAMIC@ mod_DEFS = -DSLAPD_IMPORT MOD_DEFS = $(@BUILD_SQL@_DEFS) diff --git a/servers/slapd/back-sql/add.c b/servers/slapd/back-sql/add.c index 1ce39b93b3..f09cdcd4d3 100644 --- a/servers/slapd/back-sql/add.c +++ b/servers/slapd/back-sql/add.c @@ -89,7 +89,7 @@ backsql_modify_internal( "mappings for objectClass \"%s\"\n", ad->ad_cname.bv_val, BACKSQL_OC_NAME( oc ), 0 ); - if ( backsql_attr_skip( ad, c_mod->sm_bvalues ) ) { + if ( backsql_attr_skip( ad, c_mod->sm_values ) ) { continue; } @@ -179,7 +179,13 @@ del_all: break; } - rc = backsql_BindParamID( asth, 1, &e_id->keyval ); +#ifdef BACKSQL_ARBITRARY_KEY + rc = backsql_BindParamStr( asth, 1, + e_id->eid_keyval.bv_val, + BACKSQL_MAX_KEY_LEN ); +#else /* ! BACKSQL_ARBITRARY_KEY */ + rc = backsql_BindParamID( asth, 1, &e_id->eid_keyval ); +#endif /* ! BACKSQL_ARBITRARY_KEY */ if ( rc != SQL_SUCCESS ) { Debug( LDAP_DEBUG_TRACE, " backsql_modify_internal(): " @@ -232,10 +238,18 @@ del_all: pno = 0; } po = ( BACKSQL_IS_DEL( at->bam_param_order ) ) > 0; +#ifdef BACKSQL_ARBITRARY_KEY + SQLBindParameter( sth, pno + 1 + po, + SQL_PARAM_INPUT, + SQL_C_CHAR, SQL_VARCHAR, + 0, 0, e_id->eid_keyval.bv_val, + 0, 0 ); +#else /* ! BACKSQL_ARBITRARY_KEY */ SQLBindParameter( sth, pno + 1 + po, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER, - 0, 0, &e_id->keyval, 0, 0 ); + 0, 0, &e_id->eid_keyval, 0, 0 ); +#endif /* ! BACKSQL_ARBITRARY_KEY */ /* * check for syntax needed here @@ -304,7 +318,7 @@ add_only:; Debug( LDAP_DEBUG_TRACE, " backsql_modify_internal(): " "adding new values for attribute \"%s\"\n", at->bam_ad->ad_cname.bv_val, 0, 0 ); - for ( i = 0, at_val = c_mod->sm_bvalues; + for ( i = 0, at_val = c_mod->sm_values; at_val->bv_val != NULL; i++, at_val++ ) { if ( BACKSQL_IS_ADD( at->bam_expect_return ) ) { @@ -317,10 +331,17 @@ add_only:; pno = 0; } po = ( BACKSQL_IS_ADD( at->bam_param_order ) ) > 0; +#ifdef BACKSQL_ARBITRARY_KEY + SQLBindParameter( sth, pno + 1 + po, + SQL_PARAM_INPUT, + SQL_C_CHAR, SQL_VARCHAR, + 0, 0, e_id->eid_keyval.bv_val, 0, 0 ); +#else /* ! BACKSQL_ARBITRARY_KEY */ SQLBindParameter( sth, pno + 1 + po, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER, - 0, 0, &e_id->keyval, 0, 0 ); + 0, 0, &e_id->eid_keyval, 0, 0 ); +#endif /* ! BACKSQL_ARBITRARY_KEY */ /* * check for syntax needed here @@ -377,7 +398,7 @@ add_only:; break; } - if ( c_mod->sm_bvalues == NULL ) { + if ( c_mod->sm_values == NULL ) { Debug( LDAP_DEBUG_TRACE, " backsql_modify_internal(): " "no values given to delete " @@ -391,7 +412,7 @@ add_only:; "deleting values for attribute \"%s\"\n", at->bam_ad->ad_cname.bv_val, 0, 0 ); - for ( i = 0, at_val = c_mod->sm_bvalues; + for ( i = 0, at_val = c_mod->sm_values; at_val->bv_val != NULL; i++, at_val++ ) { if ( BACKSQL_IS_DEL( at->bam_expect_return ) ) { @@ -404,10 +425,17 @@ add_only:; pno = 0; } po = ( BACKSQL_IS_DEL( at->bam_param_order ) ) > 0; +#ifdef BACKSQL_ARBITRARY_KEY + SQLBindParameter( sth, pno + 1 + po, + SQL_PARAM_INPUT, + SQL_C_CHAR, SQL_VARCHAR, + 0, 0, e_id->eid_keyval.bv_val, 0, 0 ); +#else /* ! BACKSQL_ARBITRARY_KEY */ SQLBindParameter( sth, pno + 1 + po, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER, - 0, 0, &e_id->keyval, 0, 0 ); + 0, 0, &e_id->eid_keyval, 0, 0 ); +#endif /* ! BACKSQL_ARBITRARY_KEY */ /* * check for syntax needed here @@ -479,7 +507,7 @@ backsql_add( Operation *op, SlapReply *rs ) RETCODE rc; backsql_oc_map_rec *oc = NULL; backsql_at_map_rec *at_rec = NULL; - backsql_entryID e_id, parent_id; + backsql_entryID parent_id = BACKSQL_ENTRYID_INIT; Entry p; Attribute *at; struct berval *at_val; @@ -488,6 +516,7 @@ backsql_add( Operation *op, SlapReply *rs ) SQLUSMALLINT pno, po; /* procedure return code */ int prc; + struct berval realdn, realpdn; Debug( LDAP_DEBUG_TRACE, "==>backsql_add(): adding entry \"%s\"\n", op->oq_add.rs_e->e_name.bv_val, 0, 0 ); @@ -560,7 +589,17 @@ backsql_add( Operation *op, SlapReply *rs ) /* * Check if entry exists */ - rs->sr_err = backsql_dn2id( bi, &e_id, dbh, &op->oq_add.rs_e->e_name ); + realdn = op->oq_add.rs_e->e_name; + if ( backsql_api_dn2odbc( op, rs, &realdn ) ) { + Debug( LDAP_DEBUG_TRACE, "backsql_search(): " + "backsql_api_dn2odbc failed\n", + 0, 0, 0 ); + rs->sr_err = LDAP_OTHER; + rs->sr_text = "SQL-backend error"; + goto done; + } + + rs->sr_err = backsql_dn2id( bi, NULL, dbh, &realdn ); if ( rs->sr_err == LDAP_SUCCESS ) { Debug( LDAP_DEBUG_TRACE, " backsql_add(): " "entry \"%s\" exists\n", @@ -573,7 +612,17 @@ backsql_add( Operation *op, SlapReply *rs ) * Check if parent exists */ dnParent( &op->oq_add.rs_e->e_name, &pdn ); - rs->sr_err = backsql_dn2id( bi, &parent_id, dbh, &pdn ); + realpdn = pdn; + if ( backsql_api_dn2odbc( op, rs, &realpdn ) ) { + Debug( LDAP_DEBUG_TRACE, "backsql_search(): " + "backsql_api_dn2odbc failed\n", + 0, 0, 0 ); + rs->sr_err = LDAP_OTHER; + rs->sr_text = "SQL-backend error"; + goto done; + } + + rs->sr_err = backsql_dn2id( bi, &parent_id, dbh, &realpdn ); if ( rs->sr_err != LDAP_SUCCESS ) { Debug( LDAP_DEBUG_TRACE, " backsql_add(): " "could not lookup parent entry for new record \"%s\"\n", @@ -590,13 +639,27 @@ backsql_add( Operation *op, SlapReply *rs ) struct berval dn; char *matched = NULL; + if ( realpdn.bv_val != pdn.bv_val ) { + ch_free( realpdn.bv_val ); + } + dn = pdn; dnParent( &dn, &pdn ); /* * Empty DN ("") defaults to LDAP_SUCCESS */ - rs->sr_err = backsql_dn2id( bi, &parent_id, dbh, &pdn ); + realpdn = pdn; + if ( backsql_api_dn2odbc( op, rs, &realpdn ) ) { + Debug( LDAP_DEBUG_TRACE, "backsql_add(): " + "backsql_api_dn2odbc failed\n", + 0, 0, 0 ); + rs->sr_err = LDAP_OTHER; + rs->sr_text = "SQL-backend error"; + goto done; + } + + rs->sr_err = backsql_dn2id( bi, NULL, dbh, &realpdn ); switch ( rs->sr_err ) { case LDAP_NO_SUCH_OBJECT: if ( pdn.bv_len > 0 ) { @@ -908,15 +971,27 @@ backsql_add( Operation *op, SlapReply *rs ) BACKSQL_MAX_DN_LEN ); SQLBindParameter( sth, 2, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &oc->bom_id, 0, 0 ); +#ifdef BACKSQL_ARBITRARY_KEY + SQLBindParameter( sth, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, + 0, 0, parent_id.eid_id.bv_val, 0, 0 ); +#else /* ! BACKSQL_ARBITRARY_KEY */ SQLBindParameter( sth, 3, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, - 0, 0, &parent_id.id, 0, 0 ); + 0, 0, &parent_id.eid_id, 0, 0 ); +#endif /* ! BACKSQL_ARBITRARY_KEY */ SQLBindParameter( sth, 4, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &new_keyval, 0, 0 ); Debug( LDAP_DEBUG_TRACE, " backsql_add(): executing \"%s\" for dn \"%s\"\n", bi->insentry_query, op->oq_add.rs_e->e_name.bv_val, 0 ); - Debug( LDAP_DEBUG_TRACE, " for oc_map_id=%ld, parent_id=%ld, " - "keyval=%ld\n", oc->bom_id, parent_id.id, new_keyval ); +#ifdef BACKSQL_ARBITRARY_KEY + Debug( LDAP_DEBUG_TRACE, " for oc_map_id=%ld, " + "parent_id=%s, keyval=%ld\n", + oc->bom_id, parent_id.eid_id.bv_val, new_keyval ); +#else /* ! BACKSQL_ARBITRARY_KEY */ + Debug( LDAP_DEBUG_TRACE, " for oc_map_id=%ld, " + "parent_id=%ld, keyval=%ld\n", + oc->bom_id, parent_id.eid_id, new_keyval ); +#endif /* ! BACKSQL_ARBITRARY_KEY */ #ifndef BACKSQL_REALLOC_STMT rc = SQLExecDirect( sth, bi->insentry_query, SQL_NTS ); #else /* BACKSQL_REALLOC_STMT */ @@ -958,6 +1033,16 @@ backsql_add( Operation *op, SlapReply *rs ) done:; send_ldap_result( op, rs ); + if ( realdn.bv_val != op->oq_add.rs_e->e_name.bv_val ) { + ch_free( realdn.bv_val ); + } + if ( realpdn.bv_val != pdn.bv_val ) { + ch_free( realpdn.bv_val ); + } + if ( parent_id.eid_dn.bv_val != NULL ) { + backsql_free_entryID( &parent_id, 0 ); + } + Debug( LDAP_DEBUG_TRACE, "<==backsql_add(): %d%s%s\n", rs->sr_err, rs->sr_text ? ": " : "", diff --git a/servers/slapd/back-sql/back-sql.h b/servers/slapd/back-sql/back-sql.h index 0241eeb170..4046bb3057 100644 --- a/servers/slapd/back-sql/back-sql.h +++ b/servers/slapd/back-sql/back-sql.h @@ -93,17 +93,51 @@ */ #undef BACKSQL_TRACE +/* + * define to enable varchars as unique keys in user tables + */ +#undef BACKSQL_ARBITRARY_KEY + +/* + * API + */ +typedef struct backsql_api { + char *ba_name; + int (*ba_dn2odbc)( Operation *op, SlapReply *rs, struct berval *dn ); + int (*ba_odbc2dn)( Operation *op, SlapReply *rs, struct berval *dn ); + struct backsql_api *ba_next; +} backsql_api; + /* * Entry ID structure */ typedef struct backsql_entryID { - unsigned long id; - unsigned long keyval; - unsigned long oc_id; - struct berval dn; - struct backsql_entryID *next; + /* #define BACKSQL_ARBITRARY_KEY to allow a non-numeric key. + * It is required by some special applications that use + * strings as keys for the main table. + * In this case, #define BACKSQL_MAX_KEY_LEN consistently + * with the key size definition */ +#ifdef BACKSQL_ARBITRARY_KEY + struct berval eid_id; + struct berval eid_keyval; +#define BACKSQL_MAX_KEY_LEN 64 +#else /* ! BACKSQL_ARBITRARY_KEY */ + /* The original numeric key is maintained as default. */ + unsigned long eid_id; + unsigned long eid_keyval; +#endif /* ! BACKSQL_ARBITRARY_KEY */ + + unsigned long eid_oc_id; + struct berval eid_dn; + struct backsql_entryID *eid_next; } backsql_entryID; +#ifdef BACKSQL_ARBITRARY_KEY +#define BACKSQL_ENTRYID_INIT { BER_BVNULL, BER_BVNULL, 0, BER_BVNULL, NULL } +#else /* ! BACKSQL_ARBITRARY_KEY */ +#define BACKSQL_ENTRYID_INIT { 0, 0, 0, BER_BVNULL, NULL } +#endif /* BACKSQL_ARBITRARY_KEY */ + /* * "structural" objectClass mapping structure */ @@ -201,6 +235,7 @@ typedef struct berbuf { typedef struct backsql_srch_info { Operation *bsi_op; + SlapReply *bsi_rs; int bsi_flags; #define BSQL_SF_ALL_OPER 0x0001 @@ -208,6 +243,7 @@ typedef struct backsql_srch_info { struct berval *bsi_base_dn; int bsi_scope; +#define BACKSQL_SCOPE_BASE_LIKE ( LDAP_SCOPE_BASE | 0x1000 ) Filter *bsi_filter; int bsi_slimit, bsi_tlimit; @@ -253,6 +289,7 @@ typedef struct { char *has_children_query; MatchingRule *bi_caseIgnoreMatch; + MatchingRule *bi_telephoneNumberMatch; struct berval upper_func; struct berval upper_func_open; @@ -282,6 +319,8 @@ typedef struct { ((si)->bsql_flags & BSQLF_DONTCHECK_LDAPINFO_DN_RU) #define BACKSQL_USE_REVERSE_DN(si) \ ((si)->bsql_flags & BSQLF_USE_REVERSE_DN) +#define BACKSQL_CANUPPERCASE(si) \ + ((si)->upper_func.bv_val) struct berval strcast_func; Avlnode *db_conns; @@ -290,6 +329,8 @@ typedef struct { ldap_pvt_thread_mutex_t dbconn_mutex; ldap_pvt_thread_mutex_t schema_mutex; SQLHENV db_env; + + backsql_api *si_api; } backsql_info; #define BACKSQL_SUCCESS( rc ) \ diff --git a/servers/slapd/back-sql/bind.c b/servers/slapd/back-sql/bind.c index 82da5b9be2..21906b22f4 100644 --- a/servers/slapd/back-sql/bind.c +++ b/servers/slapd/back-sql/bind.c @@ -32,7 +32,7 @@ int backsql_bind( Operation *op, SlapReply *rs ) { backsql_info *bi = (backsql_info*)op->o_bd->be_private; - backsql_entryID user_id; + backsql_entryID user_id = BACKSQL_ENTRYID_INIT; SQLHDBC dbh; AttributeDescription *password = slap_schema.si_ad_userPassword; Entry *e, user_entry; @@ -40,6 +40,7 @@ backsql_bind( Operation *op, SlapReply *rs ) backsql_srch_info bsi; AttributeName anlist[2]; int rc; + struct berval dn; Debug( LDAP_DEBUG_TRACE, "==>backsql_bind()\n", 0, 0, 0 ); @@ -74,7 +75,17 @@ backsql_bind( Operation *op, SlapReply *rs ) return 1; } - rc = backsql_dn2id( bi, &user_id, dbh, &op->o_req_ndn ); + dn = op->o_req_dn; + if ( backsql_api_dn2odbc( op, rs, &dn ) ) { + Debug( LDAP_DEBUG_TRACE, "backsql_search(): " + "backsql_api_dn2odbc failed\n", + 0, 0, 0 ); + rs->sr_err = LDAP_OTHER; + rs->sr_text = "SQL-backend error"; + goto error_return; + } + + rc = backsql_dn2id( bi, &user_id, dbh, &dn ); if ( rc != LDAP_SUCCESS ) { Debug( LDAP_DEBUG_TRACE, "backsql_bind(): " "could not retrieve bind dn id - no such entry\n", @@ -87,35 +98,42 @@ backsql_bind( Operation *op, SlapReply *rs ) anlist[0].an_name = password->ad_cname; anlist[0].an_desc = password; anlist[1].an_name.bv_val = NULL; - backsql_init_search( &bsi, &op->o_req_ndn, LDAP_SCOPE_BASE, - -1, -1, -1, NULL, dbh, op, anlist ); + + backsql_init_search( &bsi, &dn, LDAP_SCOPE_BASE, + -1, -1, -1, NULL, dbh, op, rs, anlist ); e = backsql_id2entry( &bsi, &user_entry, &user_id ); if ( e == NULL ) { Debug( LDAP_DEBUG_TRACE, "backsql_bind(): " "error in backsql_id2entry() - auth failed\n", 0, 0, 0 ); rs->sr_err = LDAP_OTHER; - send_ldap_result( op, rs ); - return 1; + goto error_return; } if ( ! access_allowed( op, e, password, NULL, ACL_AUTH, NULL ) ) { rs->sr_err = LDAP_INSUFFICIENT_ACCESS; - send_ldap_result( op, rs ); - return 1; + goto error_return; } if ( ( a = attr_find( e->e_attrs, password ) ) == NULL ) { rs->sr_err = LDAP_INAPPROPRIATE_AUTH; - send_ldap_result( op, rs ); - return 1; + goto error_return; } if ( slap_passwd_check( op->o_conn, a, &op->oq_bind.rb_cred, &rs->sr_text ) != 0 ) { rs->sr_err = LDAP_INVALID_CREDENTIALS; + goto error_return; + } + +error_return:; + if ( rs->sr_err ) { send_ldap_result( op, rs ); return 1; } + + if ( dn.bv_val != op->o_req_dn.bv_val ) { + ch_free( dn.bv_val ); + } Debug(LDAP_DEBUG_TRACE,"<==backsql_bind()\n",0,0,0); return 0; diff --git a/servers/slapd/back-sql/compare.c b/servers/slapd/back-sql/compare.c index 43ebc9c7b9..3526389a42 100644 --- a/servers/slapd/back-sql/compare.c +++ b/servers/slapd/back-sql/compare.c @@ -32,13 +32,14 @@ int backsql_compare( Operation *op, SlapReply *rs ) { backsql_info *bi = (backsql_info*)op->o_bd->be_private; - backsql_entryID user_id; + backsql_entryID user_id = BACKSQL_ENTRYID_INIT; SQLHDBC dbh; Entry *e = NULL, user_entry; Attribute *a = NULL, *a_op = NULL; backsql_srch_info bsi; int rc; AttributeName anlist[2]; + struct berval dn; user_entry.e_name.bv_val = NULL; user_entry.e_name.bv_len = 0; @@ -59,7 +60,17 @@ backsql_compare( Operation *op, SlapReply *rs ) goto return_results; } - rc = backsql_dn2id( bi, &user_id, dbh, &op->o_req_ndn ); + dn = op->o_req_dn; + if ( backsql_api_dn2odbc( op, rs, &dn ) ) { + Debug( LDAP_DEBUG_TRACE, "backsql_search(): " + "backsql_api_dn2odbc failed\n", + 0, 0, 0 ); + rs->sr_err = LDAP_OTHER; + rs->sr_text = "SQL-backend error"; + goto return_results; + } + + rc = backsql_dn2id( bi, &user_id, dbh, &dn ); if ( rc != LDAP_SUCCESS ) { Debug( LDAP_DEBUG_TRACE, "backsql_compare(): " "could not retrieve compare dn id - no such entry\n", @@ -106,8 +117,8 @@ backsql_compare( Operation *op, SlapReply *rs ) e = &user_entry; } else { - backsql_init_search( &bsi, &op->o_req_ndn, LDAP_SCOPE_BASE, - -1, -1, -1, NULL, dbh, op, anlist ); + backsql_init_search( &bsi, &dn, LDAP_SCOPE_BASE, + -1, -1, -1, NULL, dbh, op, rs, anlist ); e = backsql_id2entry( &bsi, &user_entry, &user_id ); if ( e == NULL ) { Debug( LDAP_DEBUG_TRACE, "backsql_compare(): " @@ -146,6 +157,10 @@ backsql_compare( Operation *op, SlapReply *rs ) return_results:; send_ldap_result( op, rs ); + if ( dn.bv_val != op->o_req_dn.bv_val ) { + ch_free( dn.bv_val ); + } + if ( e != NULL ) { if ( e->e_name.bv_val != NULL ) { free( e->e_name.bv_val ); diff --git a/servers/slapd/back-sql/config.c b/servers/slapd/back-sql/config.c index 10f934a321..bce6198045 100644 --- a/servers/slapd/back-sql/config.c +++ b/servers/slapd/back-sql/config.c @@ -334,6 +334,15 @@ backsql_db_config( "fail_if_no_mapping=%s\n", BACKSQL_FAIL_IF_NO_MAPPING( si ) ? "yes" : "no", 0, 0 ); + } else if ( !strcasecmp( argv[ 0 ], "sqllayer") ) { + if ( backsql_api_config( si, argv[ 1 ] ) ) { + Debug( LDAP_DEBUG_TRACE, + "<==backsql_db_config (%s line %d): " + "unable to load sqllayer \"%s\"\n", + fname, lineno, argv[ 1 ] ); + return 1; + } + } else { return SLAP_CONF_UNKNOWN; } diff --git a/servers/slapd/back-sql/delete.c b/servers/slapd/back-sql/delete.c index a5cf700462..3f4cfb99a4 100644 --- a/servers/slapd/back-sql/delete.c +++ b/servers/slapd/back-sql/delete.c @@ -38,7 +38,7 @@ backsql_delete( Operation *op, SlapReply *rs ) SQLHSTMT sth; RETCODE rc; backsql_oc_map_rec *oc = NULL; - backsql_entryID e_id; + backsql_entryID e_id = BACKSQL_ENTRYID_INIT; Entry e; /* first parameter no */ SQLUSMALLINT pno; @@ -95,7 +95,7 @@ backsql_delete( Operation *op, SlapReply *rs ) goto done; } - oc = backsql_id2oc( bi, e_id.oc_id ); + oc = backsql_id2oc( bi, e_id.eid_oc_id ); if ( oc == NULL ) { Debug( LDAP_DEBUG_TRACE, " backsql_delete(): " "cannot determine objectclass of entry -- aborting\n", @@ -137,8 +137,15 @@ backsql_delete( Operation *op, SlapReply *rs ) pno = 0; } +#ifdef BACKSQL_ARBITRARY_KEY SQLBindParameter( sth, pno + 1, SQL_PARAM_INPUT, - SQL_C_ULONG, SQL_INTEGER, 0, 0, &e_id.keyval, 0, 0 ); + SQL_C_CHAR, SQL_VARCHAR, 0, 0, e_id.eid_keyval.bv_val, + 0, 0 ); +#else /* ! BACKSQL_ARBITRARY_KEY */ + SQLBindParameter( sth, pno + 1, SQL_PARAM_INPUT, + SQL_C_ULONG, SQL_INTEGER, 0, 0, &e_id.eid_keyval, + 0, 0 ); +#endif /* ! BACKSQL_ARBITRARY_KEY */ rc = SQLExecute( sth ); if ( rc != SQL_SUCCESS ) { @@ -170,8 +177,13 @@ backsql_delete( Operation *op, SlapReply *rs ) goto done; } +#ifdef BACKSQL_ARBITRARY_KEY + SQLBindParameter( sth, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, + 0, 0, e_id.eid_id.bv_val, 0, 0 ); +#else /* ! BACKSQL_ARBITRARY_KEY */ SQLBindParameter( sth, 1, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER, - 0, 0, &e_id.id, 0, 0 ); + 0, 0, &e_id.eid_id, 0, 0 ); +#endif /* ! BACKSQL_ARBITRARY_KEY */ rc = SQLExecute( sth ); if ( rc != SQL_SUCCESS ) { Debug( LDAP_DEBUG_TRACE, " backsql_delete(): " diff --git a/servers/slapd/back-sql/entry-id.c b/servers/slapd/back-sql/entry-id.c index 55a4f55d7c..051e4f12ad 100644 --- a/servers/slapd/back-sql/entry-id.c +++ b/servers/slapd/back-sql/entry-id.c @@ -38,12 +38,22 @@ backsql_free_entryID( backsql_entryID *id, int freeit ) assert( id ); - next = id->next; + next = id->eid_next; - if ( id->dn.bv_val != NULL ) { - free( id->dn.bv_val ); + if ( id->eid_dn.bv_val != NULL ) { + free( id->eid_dn.bv_val ); } +#ifdef BACKSQL_ARBITRARY_KEY + if ( id->eid_id.bv_val ) { + free( id->eid_id.bv_val ); + } + + if ( id->eid_keyval.bv_val ) { + free( id->eid_keyval.bv_val ); + } +#endif /* BACKSQL_ARBITRARY_KEY */ + if ( freeit ) { free( id ); } @@ -65,13 +75,18 @@ backsql_dn2id( /* TimesTen */ char upperdn[ BACKSQL_MAX_DN_LEN + 1 ]; - char *toBind; + struct berval toBind; int i, j; - Debug( LDAP_DEBUG_TRACE, "==>backsql_dn2id(): dn='%s'\n", - dn->bv_val, 0, 0 ); + /* + * NOTE: id can be NULL; in this case, the function + * simply checks whether the DN can be successfully + * turned into an ID, returning LDAP_SUCCESS for + * positive cases, or the most appropriate error + */ - assert( id ); + Debug( LDAP_DEBUG_TRACE, "==>backsql_dn2id(): dn=\"%s\"%s\n", + dn->bv_val, id == NULL ? " (no ID)" : "", 0 ); if ( dn->bv_len > BACKSQL_MAX_DN_LEN ) { Debug( LDAP_DEBUG_TRACE, @@ -82,7 +97,7 @@ backsql_dn2id( } /* begin TimesTen */ - Debug(LDAP_DEBUG_TRACE, "id_query '%s'\n", bi->id_query, 0, 0); + Debug(LDAP_DEBUG_TRACE, "id_query \"%s\"\n", bi->id_query, 0, 0); assert( bi->id_query ); rc = backsql_Prepare( dbh, &sth, bi->id_query, 0 ); if ( rc != SQL_SUCCESS ) { @@ -106,29 +121,30 @@ backsql_dn2id( upperdn[ i ] = '\0'; ldap_pvt_str2upper( upperdn ); - Debug( LDAP_DEBUG_TRACE, "==>backsql_dn2id(): upperdn='%s'\n", + Debug( LDAP_DEBUG_TRACE, "==>backsql_dn2id(): upperdn=\"%s\"\n", upperdn, 0, 0 ); - toBind = upperdn; + ber_str2bv( upperdn, 0, 0, &toBind ); + } else { if ( BACKSQL_USE_REVERSE_DN( bi ) ) { AC_MEMCPY( upperdn, dn->bv_val, dn->bv_len + 1 ); ldap_pvt_str2upper( upperdn ); Debug( LDAP_DEBUG_TRACE, - "==>backsql_dn2id(): upperdn='%s'\n", + "==>backsql_dn2id(): upperdn=\"%s\"\n", upperdn, 0, 0 ); - toBind = upperdn; + ber_str2bv( upperdn, 0, 0, &toBind ); } else { - toBind = dn->bv_val; + toBind = *dn; } } - rc = backsql_BindParamStr( sth, 1, toBind, BACKSQL_MAX_DN_LEN ); + rc = backsql_BindParamStr( sth, 1, toBind.bv_val, BACKSQL_MAX_DN_LEN ); if ( rc != SQL_SUCCESS) { /* end TimesTen */ Debug( LDAP_DEBUG_TRACE, "backsql_dn2id(): " "error binding dn=\"%s\" parameter:\n", - toBind, 0, 0 ); + toBind.bv_val, 0, 0 ); backsql_PrintErrors( SQL_NULL_HENV, dbh, sth, rc ); SQLFreeStmt( sth, SQL_DROP ); return LDAP_OTHER; @@ -138,7 +154,7 @@ backsql_dn2id( if ( rc != SQL_SUCCESS ) { Debug( LDAP_DEBUG_TRACE, "backsql_dn2id(): " "error executing query (\"%s\", \"%s\"):\n", - bi->id_query, toBind, 0 ); + bi->id_query, toBind.bv_val, 0 ); backsql_PrintErrors( SQL_NULL_HENV, dbh, sth, rc ); SQLFreeStmt( sth, SQL_DROP ); return LDAP_OTHER; @@ -147,27 +163,32 @@ backsql_dn2id( backsql_BindRowAsStrings( sth, &row ); rc = SQLFetch( sth ); if ( BACKSQL_SUCCESS( rc ) ) { - id->id = strtol( row.cols[ 0 ], NULL, 0 ); - id->keyval = strtol( row.cols[ 1 ], NULL, 0 ); - id->oc_id = strtol( row.cols[ 2 ], NULL, 0 ); - ber_dupbv( &id->dn, dn ); - id->next = NULL; - res = LDAP_SUCCESS; + Debug( LDAP_DEBUG_TRACE, "<==backsql_dn2id(): id=%s keyval=%s oc_id=%s\n", + row.cols[ 0 ], row.cols[ 1 ], row.cols[ 2 ] ); + + if ( id != NULL ) { +#ifdef BACKSQL_ARBITRARY_KEY + ber_str2bv( row.cols[ 0 ], 0, 1, &id->eid_id ); + ber_str2bv( row.cols[ 1 ], 0, 1, &id->eid_keyval ); +#else /* ! BACKSQL_ARBITRARY_KEY */ + id->eid_id = strtol( row.cols[ 0 ], NULL, 0 ); + id->eid_keyval = strtol( row.cols[ 1 ], NULL, 0 ); +#endif /* ! BACKSQL_ARBITRARY_KEY */ + id->eid_oc_id = strtol( row.cols[ 2 ], NULL, 0 ); + + ber_dupbv( &id->eid_dn, dn ); + id->eid_next = NULL; + } } else { res = LDAP_NO_SUCH_OBJECT; + Debug( LDAP_DEBUG_TRACE, "<==backsql_dn2id(): no match\n", + 0, 0, 0 ); } backsql_FreeRow( &row ); SQLFreeStmt( sth, SQL_DROP ); - if ( res == LDAP_SUCCESS ) { - Debug( LDAP_DEBUG_TRACE, "<==backsql_dn2id(): id=%ld\n", - id->id, 0, 0 ); - } else { - Debug( LDAP_DEBUG_TRACE, "<==backsql_dn2id(): no match\n", - 0, 0, 0 ); - } return res; } @@ -183,7 +204,7 @@ backsql_count_children( RETCODE rc; int res = LDAP_SUCCESS; - Debug( LDAP_DEBUG_TRACE, "==>backsql_count_children(): dn='%s'\n", + Debug( LDAP_DEBUG_TRACE, "==>backsql_count_children(): dn=\"%s\"\n", dn->bv_val, 0, 0 ); if ( dn->bv_len > BACKSQL_MAX_DN_LEN ) { @@ -195,7 +216,7 @@ backsql_count_children( } /* begin TimesTen */ - Debug(LDAP_DEBUG_TRACE, "children id query '%s'\n", + Debug(LDAP_DEBUG_TRACE, "children id query \"%s\"\n", bi->has_children_query, 0, 0); assert( bi->has_children_query ); rc = backsql_Prepare( dbh, &sth, bi->has_children_query, 0 ); @@ -287,11 +308,18 @@ backsql_get_attr_vals( void *v_at, void *v_bsi ) assert( at ); assert( bsi ); - + +#ifdef BACKSQL_ARBITRARY_KEY + Debug( LDAP_DEBUG_TRACE, "==>backsql_get_attr_vals(): " + "oc=\"%s\" attr=\"%s\" keyval=%s\n", + BACKSQL_OC_NAME( bsi->bsi_oc ), at->bam_ad->ad_cname.bv_val, + bsi->bsi_c_eid->eid_keyval.bv_val ); +#else /* ! BACKSQL_ARBITRARY_KEY */ Debug( LDAP_DEBUG_TRACE, "==>backsql_get_attr_vals(): " - "oc='%s' attr='%s' keyval=%ld\n", + "oc=\"%s\" attr=\"%s\" keyval=%ld\n", BACKSQL_OC_NAME( bsi->bsi_oc ), at->bam_ad->ad_cname.bv_val, - bsi->bsi_c_eid->keyval ); + bsi->bsi_c_eid->eid_keyval ); +#endif /* ! BACKSQL_ARBITRARY_KEY */ rc = backsql_Prepare( bsi->bsi_dbh, &sth, at->bam_query, 0 ); if ( rc != SQL_SUCCESS ) { @@ -301,7 +329,12 @@ backsql_get_attr_vals( void *v_at, void *v_bsi ) return 1; } - rc = backsql_BindParamID( sth, 1, &bsi->bsi_c_eid->keyval ); +#ifdef BACKSQL_ARBITRARY_KEY + rc = backsql_BindParamStr( sth, 1, bsi->bsi_c_eid->eid_keyval.bv_val, + BACKSQL_MAX_KEY_LEN ); +#else /* ! BACKSQL_ARBITRARY_KEY */ + rc = backsql_BindParamID( sth, 1, &bsi->bsi_c_eid->eid_keyval ); +#endif /* ! BACKSQL_ARBITRARY_KEY */ if ( rc != SQL_SUCCESS ) { Debug( LDAP_DEBUG_TRACE, "backsql_get_attr_values(): " "error binding key value parameter\n", 0, 0, 0 ); @@ -311,7 +344,7 @@ backsql_get_attr_vals( void *v_at, void *v_bsi ) rc = SQLExecute( sth ); if ( ! BACKSQL_SUCCESS( rc ) ) { Debug( LDAP_DEBUG_TRACE, "backsql_get_attr_values(): " - "error executing attribute query '%s'\n", + "error executing attribute query \"%s\"\n", at->bam_query, 0, 0 ); backsql_PrintErrors( bi->db_env, bsi->bsi_dbh, sth, rc ); SQLFreeStmt( sth, SQL_DROP ); @@ -345,7 +378,7 @@ backsql_get_attr_vals( void *v_at, void *v_bsi ) (int)row.col_prec[ i ], 0, 0 ); } else { Debug( LDAP_DEBUG_TRACE, "NULL value " - "in this row for attribute '%s'\n", + "in this row for attribute \"%s\"\n", row.col_names[ i ].bv_val, 0, 0 ); #endif /* BACKSQL_TRACE */ } @@ -372,19 +405,22 @@ backsql_id2entry( backsql_srch_info *bsi, Entry *e, backsql_entryID *eid ) Debug( LDAP_DEBUG_TRACE, "==>backsql_id2entry()\n", 0, 0, 0 ); - rc = dnPrettyNormal( NULL, &eid->dn, &e->e_name, &e->e_nname, + rc = dnPrettyNormal( NULL, &eid->eid_dn, &e->e_name, &e->e_nname, bsi->bsi_op->o_tmpmemctx ); if ( rc != LDAP_SUCCESS ) { return NULL; } - bsi->bsi_oc = backsql_id2oc( bsi->bsi_op->o_bd->be_private, eid->oc_id ); + bsi->bsi_oc = backsql_id2oc( bsi->bsi_op->o_bd->be_private, + eid->eid_oc_id ); bsi->bsi_e = e; bsi->bsi_c_eid = eid; e->e_attrs = NULL; e->e_private = NULL; - - e->e_id = eid->id; + +#ifndef BACKSQL_ARBITRARY_KEY + e->e_id = eid->eid_id; +#endif /* ! BACKSQL_ARBITRARY_KEY */ if ( bsi->bsi_attrs != NULL ) { Debug( LDAP_DEBUG_TRACE, "backsql_id2entry(): " @@ -419,8 +455,8 @@ backsql_id2entry( backsql_srch_info *bsi, Entry *e, backsql_entryID *eid ) rc = backsql_supad2at( bsi->bsi_oc, attr->an_desc, &vat ); if ( rc != 0 || vat == NULL ) { Debug( LDAP_DEBUG_TRACE, "backsql_id2entry(): " - "attribute '%s' is not defined " - "for objectlass '%s'\n", + "attribute \"%s\" is not defined " + "for objectlass \"%s\"\n", attr->an_name.bv_val, BACKSQL_OC_NAME( bsi->bsi_oc ), 0 ); continue; diff --git a/servers/slapd/back-sql/init.c b/servers/slapd/back-sql/init.c index 8de4c64208..b188a679df 100644 --- a/servers/slapd/back-sql/init.c +++ b/servers/slapd/back-sql/init.c @@ -29,7 +29,7 @@ #include "ldap_pvt.h" #include "proto-sql.h" -#ifdef SLAPD_SQL_DYNAMIC +#if SLAPD_SQL == SLAPD_MOD_DYNAMIC int init_module( @@ -46,7 +46,7 @@ init_module( return 0; } -#endif /* SLAPD_SQL_DYNAMIC */ +#endif /* SLAPD_SQL == SLAPD_MOD_DYNAMIC */ int sql_back_initialize( @@ -94,7 +94,7 @@ sql_back_initialize( bi->bi_connection_init = 0; bi->bi_connection_destroy = backsql_connection_destroy; - + Debug( LDAP_DEBUG_TRACE,"<==backsql_initialize()\n", 0, 0, 0 ); return 0; } @@ -195,7 +195,7 @@ backsql_db_open( if ( backsql_split_pattern( backsql_def_concat_func, &si->concat_func, 2 ) ) { Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): " - "unable to parse pattern '%s'", + "unable to parse pattern \"%s\"", backsql_def_concat_func, 0, 0 ); return 1; } @@ -229,6 +229,10 @@ backsql_db_open( /* normalize filter values only if necessary */ si->bi_caseIgnoreMatch = mr_find( "caseIgnoreMatch" ); + assert( si->bi_caseIgnoreMatch ); + + si->bi_telephoneNumberMatch = mr_find( "telephoneNumberMatch" ); + assert( si->bi_telephoneNumberMatch ); if ( si->dbuser == NULL ) { Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): " @@ -290,7 +294,7 @@ backsql_db_open( si->subtree_cond = bb.bb_val; Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): " - "setting '%s' as default\n", + "setting \"%s\" as default\n", si->subtree_cond.bv_val, 0, 0 ); } @@ -324,7 +328,7 @@ backsql_db_open( si->children_cond = bb.bb_val; Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): " - "setting '%s' as default\n", + "setting \"%s\" as default\n", si->children_cond.bv_val, 0, 0 ); } @@ -342,7 +346,7 @@ backsql_db_open( "(use \"oc_query\" directive in slapd.conf)\n", 0, 0, 0 ); Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): " - "setting '%s' by default\n", si->oc_query, 0, 0 ); + "setting \"%s\" by default\n", si->oc_query, 0, 0 ); } if ( si->at_query == NULL ) { @@ -351,7 +355,7 @@ backsql_db_open( "(use \"at_query\" directive in slapd.conf)\n", 0, 0, 0 ); Debug(LDAP_DEBUG_TRACE, "backsql_db_open(): " - "setting '%s' by default\n", + "setting \"%s\" by default\n", backsql_def_at_query, 0, 0 ); si->at_query = ch_strdup( backsql_def_at_query ); } @@ -362,7 +366,7 @@ backsql_db_open( "(use \"insentry_query\" directive in slapd.conf)\n", 0, 0, 0 ); Debug(LDAP_DEBUG_TRACE, "backsql_db_open(): " - "setting '%s' by default\n", + "setting \"%s\" by default\n", backsql_def_insentry_query, 0, 0 ); si->insentry_query = ch_strdup( backsql_def_insentry_query ); } @@ -373,7 +377,7 @@ backsql_db_open( "(use \"delentry_query\" directive in slapd.conf)\n", 0, 0, 0 ); Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): " - "setting '%s' by default\n", + "setting \"%s\" by default\n", backsql_def_delentry_query, 0, 0 ); si->delentry_query = ch_strdup( backsql_def_delentry_query ); } diff --git a/servers/slapd/back-sql/modify.c b/servers/slapd/back-sql/modify.c index c36db54f4c..1a528091d8 100644 --- a/servers/slapd/back-sql/modify.c +++ b/servers/slapd/back-sql/modify.c @@ -36,7 +36,7 @@ backsql_modify( Operation *op, SlapReply *rs ) backsql_info *bi = (backsql_info*)op->o_bd->be_private; SQLHDBC dbh; backsql_oc_map_rec *oc = NULL; - backsql_entryID e_id; + backsql_entryID e_id = BACKSQL_ENTRYID_INIT; Entry e; /* @@ -72,11 +72,17 @@ backsql_modify( Operation *op, SlapReply *rs ) return 1; } +#ifdef BACKSQL_ARBITRARY_KEY + Debug( LDAP_DEBUG_TRACE, " backsql_modify(): " + "modifying entry \"%s\" (id=%s)\n", + e_id.eid_dn.bv_val, e_id.eid_id.bv_val, 0 ); +#else /* ! BACKSQL_ARBITRARY_KEY */ Debug( LDAP_DEBUG_TRACE, " backsql_modify(): " "modifying entry \"%s\" (id=%ld)\n", - e_id.dn.bv_val, e_id.id, 0 ); + e_id.eid_dn.bv_val, e_id.eid_id, 0 ); +#endif /* ! BACKSQL_ARBITRARY_KEY */ - oc = backsql_id2oc( bi, e_id.oc_id ); + oc = backsql_id2oc( bi, e_id.eid_oc_id ); if ( oc == NULL ) { Debug( LDAP_DEBUG_TRACE, " backsql_modify(): " "cannot determine objectclass of entry -- aborting\n", diff --git a/servers/slapd/back-sql/modrdn.c b/servers/slapd/back-sql/modrdn.c index 8dcc1cc6fc..ee05c7d8f1 100644 --- a/servers/slapd/back-sql/modrdn.c +++ b/servers/slapd/back-sql/modrdn.c @@ -37,7 +37,9 @@ backsql_modrdn( Operation *op, SlapReply *rs ) SQLHDBC dbh; SQLHSTMT sth; RETCODE rc; - backsql_entryID e_id, pe_id, new_pid; + backsql_entryID e_id = BACKSQL_ENTRYID_INIT, + pe_id = BACKSQL_ENTRYID_INIT, + new_pid = BACKSQL_ENTRYID_INIT; backsql_oc_map_rec *oc = NULL; struct berval p_dn, p_ndn, *new_pdn = NULL, *new_npdn = NULL, @@ -73,8 +75,13 @@ backsql_modrdn( Operation *op, SlapReply *rs ) return 1; } +#ifdef BACKSQL_ARBITRARY_KEY + Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): entry id=%s\n", + e_id.eid_id.bv_val, 0, 0 ); +#else /* ! BACKSQL_ARBITRARY_KEY */ Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): entry id=%ld\n", - e_id.id, 0, 0 ); + e_id.eid_id, 0, 0 ); +#endif /* ! BACKSQL_ARBITRARY_KEY */ if ( backsql_has_children( bi, dbh, &op->o_req_ndn ) == LDAP_COMPARE_TRUE ) { Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): " @@ -192,8 +199,15 @@ backsql_modrdn( Operation *op, SlapReply *rs ) goto modrdn_return; } +#ifdef BACKSQL_ARBITRARY_KEY Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): " - "old parent entry id is %ld\n", pe_id.id, 0, 0 ); + "old parent entry id is %s\n", pe_id.eid_id.bv_val, 0, 0 ); +#else /* ! BACKSQL_ARBITRARY_KEY */ + Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): " + "old parent entry id is %ld\n", pe_id.eid_id, 0, 0 ); +#endif /* ! BACKSQL_ARBITRARY_KEY */ + + backsql_free_entryID( &pe_id, 0 ); rs->sr_err = backsql_dn2id( bi, &new_pid, dbh, new_npdn ); if ( rs->sr_err != LDAP_SUCCESS ) { @@ -204,16 +218,26 @@ backsql_modrdn( Operation *op, SlapReply *rs ) send_ldap_result( op, rs ); goto modrdn_return; } - + +#ifdef BACKSQL_ARBITRARY_KEY Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): " - "new parent entry id=%ld\n", new_pid.id, 0, 0 ); + "new parent entry id=%s\n", new_pid.eid_id.bv_val, 0, 0 ); +#else /* ! BACKSQL_ARBITRARY_KEY */ + Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): " + "new parent entry id=%ld\n", new_pid.eid_id, 0, 0 ); +#endif /* ! BACKSQL_ARBITRARY_KEY */ Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): " "executing delentry_query\n", 0, 0, 0 ); SQLAllocStmt( dbh, &sth ); +#ifdef BACKSQL_ARBITRARY_KEY + SQLBindParameter( sth, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, + 0, 0, e_id.eid_id.bv_val, 0, 0 ); +#else /* ! BACKSQL_ARBITRARY_KEY */ SQLBindParameter( sth, 1, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER, - 0, 0, &e_id.id, 0, 0 ); + 0, 0, &e_id.eid_id, 0, 0 ); +#endif /* ! BACKSQL_ARBITRARY_KEY */ rc = SQLExecDirect( sth, bi->delentry_query, SQL_NTS ); if ( rc != SQL_SUCCESS ) { Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): " @@ -232,11 +256,18 @@ backsql_modrdn( Operation *op, SlapReply *rs ) "executing insentry_query\n", 0, 0, 0 ); backsql_BindParamStr( sth, 1, new_dn.bv_val, BACKSQL_MAX_DN_LEN ); SQLBindParameter( sth, 2, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, - 0, 0, &e_id.oc_id, 0, 0 ); + 0, 0, &e_id.eid_oc_id, 0, 0 ); +#ifdef BACKSQL_ARBITRARY_KEY + SQLBindParameter( sth, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, + 0, 0, new_pid.eid_id.bv_val, 0, 0 ); + SQLBindParameter( sth, 4, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, + 0, 0, e_id.eid_keyval.bv_val, 0, 0 ); +#else /* ! BACKSQL_ARBITRARY_KEY */ SQLBindParameter( sth, 3, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, - 0, 0, &new_pid.id, 0, 0 ); + 0, 0, &new_pid.eid_id, 0, 0 ); SQLBindParameter( sth, 4, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, - 0, 0, &e_id.keyval, 0, 0 ); + 0, 0, &e_id.eid_keyval, 0, 0 ); +#endif /* ! BACKSQL_ARBITRARY_KEY */ rc = SQLExecDirect( sth, bi->insentry_query, SQL_NTS ); if ( rc != SQL_SUCCESS ) { Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): " @@ -316,7 +347,7 @@ backsql_modrdn( Operation *op, SlapReply *rs ) goto modrdn_return; } - oc = backsql_id2oc( bi, e_id.oc_id ); + oc = backsql_id2oc( bi, e_id.eid_oc_id ); rs->sr_err = backsql_modify_internal( op, rs, dbh, oc, &e_id, mod ); if ( rs->sr_err == LDAP_SUCCESS ) { @@ -346,7 +377,7 @@ modrdn_return: if ( old_rdn != NULL ) { ldap_rdnfree( old_rdn ); } - if( mod != NULL ) { + if ( mod != NULL ) { Modifications *tmp; for (; mod; mod=tmp ) { tmp = mod->sml_next; @@ -354,6 +385,10 @@ modrdn_return: } } + if ( new_pid.eid_dn.bv_val ) { + backsql_free_entryID( &pe_id, 0 ); + } + send_ldap_result( op, rs ); Debug( LDAP_DEBUG_TRACE, "<==backsql_modrdn()\n", 0, 0, 0 ); diff --git a/servers/slapd/back-sql/operational.c b/servers/slapd/back-sql/operational.c index f495d051d8..c4527d36ff 100644 --- a/servers/slapd/back-sql/operational.c +++ b/servers/slapd/back-sql/operational.c @@ -45,7 +45,7 @@ backsql_operational( Attribute **aa = a; int rc = 0; - Debug( LDAP_DEBUG_TRACE, "==>backsql_operational(): entry '%s'\n", + Debug( LDAP_DEBUG_TRACE, "==>backsql_operational(): entry \"%s\"\n", rs->sr_entry->e_nname.bv_val, 0, 0 ); diff --git a/servers/slapd/back-sql/proto-sql.h b/servers/slapd/back-sql/proto-sql.h index 19b7518887..e57e9b4d4f 100644 --- a/servers/slapd/back-sql/proto-sql.h +++ b/servers/slapd/back-sql/proto-sql.h @@ -87,6 +87,14 @@ int backsql_modify_internal( backsql_entryID *e_id, Modifications *modlist ); +/* + * api.c + */ +int backsql_api_config( backsql_info *si, const char *name ); +int backsql_api_register( backsql_api *ba ); +int backsql_api_dn2odbc( Operation *op, SlapReply *rs, struct berval *dn ); +int backsql_api_odbc2dn( Operation *op, SlapReply *rs, struct berval *dn ); + /* * entry-id.c */ @@ -138,7 +146,7 @@ int backsql_destroy_schema_map( backsql_info *si ); void backsql_init_search( backsql_srch_info *bsi, struct berval *nbase, int scope, int slimit, int tlimit, time_t stoptime, Filter *filter, SQLHDBC dbh, - Operation *op, AttributeName *attrs ); + Operation *op, SlapReply *rs, AttributeName *attrs ); /* * sql-wrap.h diff --git a/servers/slapd/back-sql/schema-map.c b/servers/slapd/back-sql/schema-map.c index 1de778c5c6..e62948adc5 100644 --- a/servers/slapd/back-sql/schema-map.c +++ b/servers/slapd/back-sql/schema-map.c @@ -241,18 +241,18 @@ backsql_load_schema_map( backsql_info *si, SQLHDBC dbh ) rc = backsql_Prepare( dbh, &oc_sth, si->oc_query, 0 ); if ( rc != SQL_SUCCESS ) { Debug( LDAP_DEBUG_TRACE, "backsql_load_schema_map(): " - "error preparing oc_query: '%s'\n", + "error preparing oc_query: \"%s\"\n", si->oc_query, 0, 0 ); backsql_PrintErrors( si->db_env, dbh, oc_sth, rc ); return LDAP_OTHER; } - Debug( LDAP_DEBUG_TRACE, "backsql_load_schema_map(): at_query '%s'\n", + Debug( LDAP_DEBUG_TRACE, "backsql_load_schema_map(): at_query \"%s\"\n", si->at_query, 0, 0 ); rc = backsql_Prepare( dbh, &at_sth, si->at_query, 0 ); if ( rc != SQL_SUCCESS ) { Debug( LDAP_DEBUG_TRACE, "backsql_load_schema_map(): " - "error preparing at_query: '%s'\n", + "error preparing at_query: \"%s\"\n", si->at_query, 0, 0 ); backsql_PrintErrors( si->db_env, dbh, at_sth, rc ); return LDAP_OTHER; @@ -287,7 +287,7 @@ backsql_load_schema_map( backsql_info *si, SQLHDBC dbh ) oc_map->bom_oc = oc_find( oc_row.cols[ 1 ] ); if ( oc_map->bom_oc == NULL ) { Debug( LDAP_DEBUG_TRACE, "backsql_load_schema_map(): " - "objectClass '%s' is not defined in schema\n", + "objectClass \"%s\" is not defined in schema\n", oc_row.cols[ 1 ], 0, 0 ); return LDAP_OTHER; /* undefined objectClass ? */ } @@ -328,19 +328,19 @@ backsql_load_schema_map( backsql_info *si, SQLHDBC dbh ) } oc_id = oc_map->bom_id; Debug( LDAP_DEBUG_TRACE, "backsql_load_schema_map(): " - "objectClass '%s': keytbl='%s' keycol='%s'\n", + "objectClass \"%s\": keytbl=\"%s\" keycol=\"%s\"\n", BACKSQL_OC_NAME( oc_map ), oc_map->bom_keytbl.bv_val, oc_map->bom_keycol.bv_val ); if ( oc_map->bom_create_proc ) { - Debug( LDAP_DEBUG_TRACE, "create_proc='%s'\n", + Debug( LDAP_DEBUG_TRACE, "create_proc=\"%s\"\n", oc_map->bom_create_proc, 0, 0 ); } if ( oc_map->bom_create_keyval ) { - Debug( LDAP_DEBUG_TRACE, "create_keyval='%s'\n", + Debug( LDAP_DEBUG_TRACE, "create_keyval=\"%s\"\n", oc_map->bom_create_keyval, 0, 0 ); } if ( oc_map->bom_delete_proc ) { - Debug( LDAP_DEBUG_TRACE, "delete_proc='%s'\n", + Debug( LDAP_DEBUG_TRACE, "delete_proc=\"%s\"\n", oc_map->bom_delete_proc, 0, 0 ); } Debug( LDAP_DEBUG_TRACE, "expect_return: " @@ -369,19 +369,19 @@ backsql_load_schema_map( backsql_info *si, SQLHDBC dbh ) Debug( LDAP_DEBUG_TRACE, "attributeType:\n" - "\tname='%s'\n" - "\tsel_expr='%s'\n" - "\tfrom='%s'\n", + "\tname=\"%s\"\n" + "\tsel_expr=\"%s\"\n" + "\tfrom=\"%s\"\n", at_row.cols[ 0 ], at_row.cols[ 1 ], at_row.cols[ 2 ] ); Debug( LDAP_DEBUG_TRACE, - "\tjoin_where='%s'\n" - "\tadd_proc='%s'\n" - "\tdelete_proc='%s'\n", + "\tjoin_where=\"%s\"\n" + "\tadd_proc=\"%s\"\n" + "\tdelete_proc=\"%s\"\n", at_row.cols[ 3 ], at_row.cols[ 4 ], at_row.cols[ 5 ]); /* TimesTen */ - Debug( LDAP_DEBUG_TRACE, "\tsel_expr_u='%s'\n", + Debug( LDAP_DEBUG_TRACE, "\tsel_expr_u=\"%s\"\n", at_row.cols[ 8 ], 0, 0 ); at_map = (backsql_at_map_rec *)ch_calloc( 1, sizeof( backsql_at_map_rec ) ); @@ -389,7 +389,7 @@ backsql_load_schema_map( backsql_info *si, SQLHDBC dbh ) &at_map->bam_ad, &text ); if ( rc != LDAP_SUCCESS ) { Debug( LDAP_DEBUG_TRACE, "backsql_load_schema_map(): " - "attribute '%s' for objectClass '%s' " + "attribute \"%s\" for objectClass \"%s\" " "is not defined in schema: %s\n", at_row.cols[ 0 ], BACKSQL_OC_NAME( oc_map ), text ); @@ -429,7 +429,7 @@ backsql_load_schema_map( backsql_info *si, SQLHDBC dbh ) NULL, 0 ); backsql_make_attr_query( oc_map, at_map ); Debug( LDAP_DEBUG_TRACE, "backsql_load_schema_map(): " - "preconstructed query '%s'\n", + "preconstructed query \"%s\"\n", at_map->bam_query, 0, 0 ); at_map->bam_next = NULL; if ( avl_insert( &oc_map->bom_attrs, at_map, backsql_cmp_attr, backsql_dup_attr ) == BACKSQL_DUPLICATE ) { @@ -469,7 +469,7 @@ backsql_oc2oc( backsql_info *si, ObjectClass *oc ) #ifdef BACKSQL_TRACE Debug( LDAP_DEBUG_TRACE, "==>backsql_oc2oc(): " - "searching for objectclass with name='%s'\n", + "searching for objectclass with name=\"%s\"\n", objclass, 0, 0 ); #endif /* BACKSQL_TRACE */ @@ -478,7 +478,7 @@ backsql_oc2oc( backsql_info *si, ObjectClass *oc ) #ifdef BACKSQL_TRACE if ( res != NULL ) { Debug( LDAP_DEBUG_TRACE, "<==backsql_oc2oc(): " - "found name='%s', id=%d\n", + "found name=\"%s\", id=%d\n", BACKSQL_OC_NAME( res ), res->id, 0 ); } else { Debug( LDAP_DEBUG_TRACE, "<==backsql_oc2oc(): " @@ -496,7 +496,7 @@ backsql_name2oc( backsql_info *si, struct berval *oc_name ) #ifdef BACKSQL_TRACE Debug( LDAP_DEBUG_TRACE, "==>oc_with_name(): " - "searching for objectclass with name='%s'\n", + "searching for objectclass with name=\"%s\"\n", objclass, 0, 0 ); #endif /* BACKSQL_TRACE */ @@ -509,7 +509,7 @@ backsql_name2oc( backsql_info *si, struct berval *oc_name ) #ifdef BACKSQL_TRACE if ( res != NULL ) { Debug( LDAP_DEBUG_TRACE, "<==oc_with_name(): " - "found name='%s', id=%d\n", + "found name=\"%s\", id=%d\n", BACKSQL_OC_NAME( res ), res->bom_id, 0 ); } else { Debug( LDAP_DEBUG_TRACE, "<==oc_with_name(): " @@ -537,7 +537,7 @@ backsql_id2oc( backsql_info *si, unsigned long id ) #ifdef BACKSQL_TRACE if ( res != NULL ) { Debug( LDAP_DEBUG_TRACE, "<==oc_with_name(): " - "found name='%s', id=%d\n", + "found name=\"%s\", id=%d\n", BACKSQL_OC_NAME( res ), res->bom_id, 0 ); } else { Debug( LDAP_DEBUG_TRACE, "<==oc_with_name(): " @@ -555,7 +555,7 @@ backsql_ad2at( backsql_oc_map_rec* objclass, AttributeDescription *ad ) #ifdef BACKSQL_TRACE Debug( LDAP_DEBUG_TRACE, "==>backsql_ad2at(): " - "searching for attribute '%s' for objectclass '%s'\n", + "searching for attribute \"%s\" for objectclass \"%s\"\n", attr, BACKSQL_OC_NAME( objclass ), 0 ); #endif /* BACKSQL_TRACE */ @@ -566,7 +566,7 @@ backsql_ad2at( backsql_oc_map_rec* objclass, AttributeDescription *ad ) #ifdef BACKSQL_TRACE if ( res != NULL ) { Debug( LDAP_DEBUG_TRACE, "<==backsql_ad2at(): " - "found name='%s', sel_expr='%s'\n", + "found name=\"%s\", sel_expr=\"%s\"\n", res->bam_ad->ad_cname.bv_val, res->bam_sel_expr.bv_val, 0 ); } else { @@ -664,7 +664,7 @@ backsql_free_attr( void *v_at ) { backsql_at_map_rec *at = v_at; - Debug( LDAP_DEBUG_TRACE, "==>free_attr(): '%s'\n", + Debug( LDAP_DEBUG_TRACE, "==>free_attr(): \"%s\"\n", at->bam_ad->ad_cname.bv_val, 0, 0 ); ch_free( at->bam_sel_expr.bv_val ); if ( at->bam_from_tbls.bv_val != NULL ) { @@ -702,7 +702,7 @@ backsql_free_oc( void *v_oc ) { backsql_oc_map_rec *oc = v_oc; - Debug( LDAP_DEBUG_TRACE, "==>free_oc(): '%s'\n", + Debug( LDAP_DEBUG_TRACE, "==>free_oc(): \"%s\"\n", BACKSQL_OC_NAME( oc ), 0, 0 ); avl_free( oc->bom_attrs, backsql_free_attr ); ch_free( oc->bom_keytbl.bv_val ); diff --git a/servers/slapd/back-sql/search.c b/servers/slapd/back-sql/search.c index 0eca1f703b..4f91920423 100644 --- a/servers/slapd/back-sql/search.c +++ b/servers/slapd/back-sql/search.c @@ -35,7 +35,12 @@ #define BACKSQL_CONTINUE 1 static int backsql_process_filter( backsql_srch_info *bsi, Filter *f ); - +static int backsql_process_filter_eq( backsql_srch_info *bsi, + backsql_at_map_rec *at, + int casefold, struct berval *filter_value ); +static int backsql_process_filter_like( backsql_srch_info *bsi, + backsql_at_map_rec *at, + int casefold, struct berval *filter_value ); static int backsql_process_filter_attr( backsql_srch_info *bsi, Filter *f, backsql_at_map_rec *at ); @@ -62,7 +67,7 @@ backsql_attrlist_add( backsql_srch_info *bsi, AttributeDescription *ad ) an = &bsi->bsi_attrs[ n_attrs ]; Debug( LDAP_DEBUG_TRACE, "==>backsql_attrlist_add(): " - "attribute '%s' is in list\n", + "attribute \"%s\" is in list\n", an->an_name.bv_val, 0, 0 ); /* * We can live with strcmp because the attribute @@ -74,7 +79,7 @@ backsql_attrlist_add( backsql_srch_info *bsi, AttributeDescription *ad ) } Debug( LDAP_DEBUG_TRACE, "==>backsql_attrlist_add(): " - "adding '%s' to list\n", ad->ad_cname.bv_val, 0, 0 ); + "adding \"%s\" to list\n", ad->ad_cname.bv_val, 0, 0 ); an = (AttributeName *)ch_realloc( bsi->bsi_attrs, sizeof( AttributeName ) * ( n_attrs + 2 ) ); @@ -103,10 +108,11 @@ backsql_init_search( Filter *filter, SQLHDBC dbh, Operation *op, + SlapReply *rs, AttributeName *attrs ) { AttributeName *p; - + bsi->bsi_base_dn = base; bsi->bsi_scope = scope; bsi->bsi_slimit = slimit; @@ -114,6 +120,7 @@ backsql_init_search( bsi->bsi_filter = filter; bsi->bsi_dbh = dbh; bsi->bsi_op = op; + bsi->bsi_rs = rs; bsi->bsi_flags = 0; /* @@ -215,9 +222,7 @@ static int backsql_process_sub_filter( backsql_srch_info *bsi, Filter *f, backsql_at_map_rec *at ) { -#ifdef BACKSQL_UPPERCASE_FILTER backsql_info *bi = (backsql_info *)bsi->bsi_op->o_bd->be_private; -#endif /* BACKSQL_UPPERCASE_FILTER */ int i; int casefold = 0; @@ -234,6 +239,77 @@ backsql_process_sub_filter( backsql_srch_info *bsi, Filter *f, casefold = 1; } + if ( SLAP_MR_ASSOCIATED( f->f_sub_desc->ad_type->sat_substr, + bi->bi_telephoneNumberMatch ) ) + { + + struct berval bv; + ber_len_t i, s, a; + + /* + * to check for matching telephone numbers + * with intermixed chars, e.g. val='1234' + * use + * + * val LIKE '%1%2%3%4%' + */ + + bv.bv_len = 0; + if ( f->f_sub_initial.bv_val ) { + bv.bv_len += f->f_sub_initial.bv_len; + } + if ( f->f_sub_any != NULL ) { + for ( a = 0; f->f_sub_any[ a ].bv_val != NULL; a++ ) { + bv.bv_len += f->f_sub_any[ a ].bv_len; + } + } + if ( f->f_sub_final.bv_val ) { + bv.bv_len += f->f_sub_final.bv_len; + } + bv.bv_len = 2 * bv.bv_len - 1; + bv.bv_val = ch_malloc( bv.bv_len + 1 ); + + s = 0; + if ( f->f_sub_initial.bv_val ) { + bv.bv_val[ s ] = f->f_sub_initial.bv_val[ 0 ]; + for ( i = 1; i < f->f_sub_initial.bv_len; i++ ) { + bv.bv_val[ s + 2 * i - 1 ] = '%'; + bv.bv_val[ s + 2 * i ] = f->f_sub_initial.bv_val[ i ]; + } + bv.bv_val[ s + 2 * i - 1 ] = '%'; + s += 2 * i; + } + + if ( f->f_sub_any != NULL ) { + for ( a = 0; f->f_sub_any[ a ].bv_val != NULL; a++ ) { + bv.bv_val[ s ] = f->f_sub_any[ a ].bv_val[ 0 ]; + for ( i = 1; i < f->f_sub_any[ a ].bv_len; i++ ) { + bv.bv_val[ s + 2 * i - 1 ] = '%'; + bv.bv_val[ s + 2 * i ] = f->f_sub_any[ a ].bv_val[ i ]; + } + bv.bv_val[ s + 2 * i - 1 ] = '%'; + s += 2 * i; + } + } + + if ( f->f_sub_final.bv_val ) { + bv.bv_val[ s ] = f->f_sub_final.bv_val[ 0 ]; + for ( i = 1; i < f->f_sub_final.bv_len; i++ ) { + bv.bv_val[ s + 2 * i - 1 ] = '%'; + bv.bv_val[ s + 2 * i ] = f->f_sub_final.bv_val[ i ]; + } + bv.bv_val[ s + 2 * i - 1 ] = '%'; + s += 2 * i; + } + + bv.bv_val[ s - 1 ] = '\0'; + + (void)backsql_process_filter_like( bsi, at, casefold, &bv ); + ch_free( bv.bv_val ); + + return 1; + } + /* * When dealing with case-sensitive strings * we may omit normalization; however, normalized @@ -243,7 +319,9 @@ backsql_process_sub_filter( backsql_srch_info *bsi, Filter *f, backsql_strfcat( &bsi->bsi_flt_where, "c", '(' /* ) */ ); /* TimesTen */ - Debug( LDAP_DEBUG_TRACE, "expr: '%s%s%s'\n", at->bam_sel_expr.bv_val, + Debug( LDAP_DEBUG_TRACE, "backsql_process_sub_filter(%s):\n", + at->bam_ad->ad_cname.bv_val, 0, 0 ); + Debug(LDAP_DEBUG_TRACE, " expr: '%s%s%s'\n", at->bam_sel_expr.bv_val, at->bam_sel_expr_u.bv_val ? "' '" : "", at->bam_sel_expr_u.bv_val ? at->bam_sel_expr_u.bv_val : "" ); if ( casefold && BACKSQL_AT_CANUPPERCASE( at ) ) { @@ -266,6 +344,13 @@ backsql_process_sub_filter( backsql_srch_info *bsi, Filter *f, if ( f->f_sub_initial.bv_val != NULL ) { ber_len_t start; +#ifdef BACKSQL_TRACE + Debug( LDAP_DEBUG_TRACE, + "==>backsql_process_sub_filter(%s): " + "sub_initial=\"%s\"\n", at->bam_ad->ad_cname.bv_val, + f->f_sub_initial.bv_val, 0 ); +#endif /* BACKSQL_TRACE */ + start = bsi->bsi_flt_where.bb_val.bv_len; backsql_strfcat( &bsi->bsi_flt_where, "b", &f->f_sub_initial ); @@ -283,8 +368,8 @@ backsql_process_sub_filter( backsql_srch_info *bsi, Filter *f, #ifdef BACKSQL_TRACE Debug( LDAP_DEBUG_TRACE, "==>backsql_process_sub_filter(%s): " - "sub_any='%s'\n", at->bam_ad->ad_cname.bv_val, - f->f_sub_any[ i ].bv_val, 0 ); + "sub_any[%d]=\"%s\"\n", at->bam_ad->ad_cname.bv_val, + i, f->f_sub_any[ i ].bv_val ); #endif /* BACKSQL_TRACE */ start = bsi->bsi_flt_where.bb_val.bv_len; @@ -299,16 +384,23 @@ backsql_process_sub_filter( backsql_srch_info *bsi, Filter *f, ldap_pvt_str2upper( &bsi->bsi_flt_where.bb_val.bv_val[ start ] ); } } + } - if ( f->f_sub_final.bv_val != NULL ) { - ber_len_t start; + if ( f->f_sub_final.bv_val != NULL ) { + ber_len_t start; - start = bsi->bsi_flt_where.bb_val.bv_len; - backsql_strfcat( &bsi->bsi_flt_where, "b", - &f->f_sub_final ); - if ( casefold && BACKSQL_AT_CANUPPERCASE( at ) ) { - ldap_pvt_str2upper( &bsi->bsi_flt_where.bb_val.bv_val[ start ] ); - } +#ifdef BACKSQL_TRACE + Debug( LDAP_DEBUG_TRACE, + "==>backsql_process_sub_filter(%s): " + "sub_final=\"%s\"\n", at->bam_ad->ad_cname.bv_val, + f->f_sub_final.bv_val, 0 ); +#endif /* BACKSQL_TRACE */ + + start = bsi->bsi_flt_where.bb_val.bv_len; + backsql_strfcat( &bsi->bsi_flt_where, "b", + &f->f_sub_final ); + if ( casefold && BACKSQL_AT_CANUPPERCASE( at ) ) { + ldap_pvt_str2upper( &bsi->bsi_flt_where.bb_val.bv_val[ start ] ); } } @@ -556,9 +648,93 @@ done:; return rc; } +static int +backsql_process_filter_eq( backsql_srch_info *bsi, backsql_at_map_rec *at, + int casefold, struct berval *filter_value ) +{ + /* + * 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 ( casefold && BACKSQL_AT_CANUPPERCASE( at ) ) { + ber_len_t start; + + backsql_strfcat( &bsi->bsi_flt_where, "cbl", + '(', /* ) */ + &at->bam_sel_expr_u, + (ber_len_t)sizeof( "='" ) - 1, + "='" ); + + start = bsi->bsi_flt_where.bb_val.bv_len; + + backsql_strfcat( &bsi->bsi_flt_where, "bl", + filter_value, + (ber_len_t)sizeof( /* (' */ "')" ) - 1, + /* (' */ "')" ); + + ldap_pvt_str2upper( &bsi->bsi_flt_where.bb_val.bv_val[ start ] ); + + } else { + backsql_strfcat( &bsi->bsi_flt_where, "cblbl", + '(', /* ) */ + &at->bam_sel_expr, + (ber_len_t)sizeof( "='" ) - 1, "='", + filter_value, + (ber_len_t)sizeof( /* (' */ "')" ) - 1, + /* (' */ "')" ); + } + + return 1; +} + +static int +backsql_process_filter_like( backsql_srch_info *bsi, backsql_at_map_rec *at, + int casefold, struct berval *filter_value ) +{ + /* + * 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 ( casefold && BACKSQL_AT_CANUPPERCASE( at ) ) { + ber_len_t start; + + backsql_strfcat( &bsi->bsi_flt_where, "cbl", + '(', /* ) */ + &at->bam_sel_expr_u, + (ber_len_t)sizeof( " LIKE '%" ) - 1, + " LIKE '%" ); + + start = bsi->bsi_flt_where.bb_val.bv_len; + + backsql_strfcat( &bsi->bsi_flt_where, "bl", + filter_value, + (ber_len_t)sizeof( /* (' */ "%')" ) - 1, + /* (' */ "%')" ); + + ldap_pvt_str2upper( &bsi->bsi_flt_where.bb_val.bv_val[ start ] ); + + } else { + backsql_strfcat( &bsi->bsi_flt_where, "cblbl", + '(', /* ) */ + &at->bam_sel_expr, + (ber_len_t)sizeof( " LIKE '%" ) - 1, + " LIKE '%", + filter_value, + (ber_len_t)sizeof( /* (' */ "%')" ) - 1, + /* (' */ "%')" ); + } + + return 1; +} + static int backsql_process_filter_attr( backsql_srch_info *bsi, Filter *f, backsql_at_map_rec *at ) { + backsql_info *bi = (backsql_info *)bsi->bsi_op->o_bd->be_private; int casefold = 0; struct berval *filter_value = NULL; MatchingRule *matching_rule = NULL; @@ -605,39 +781,43 @@ equality_match:; casefold = 1; } - /* - * 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 ( casefold && BACKSQL_AT_CANUPPERCASE( at ) ) { - ber_len_t start; + if ( SLAP_MR_ASSOCIATED( matching_rule, + bi->bi_telephoneNumberMatch ) ) + { + struct berval bv; + ber_len_t i; - backsql_strfcat( &bsi->bsi_flt_where, "cbl", - '(', /* ) */ - &at->bam_sel_expr_u, - (ber_len_t)sizeof( "='" ) - 1, - "='" ); + /* + * to check for matching telephone numbers + * with intermized chars, e.g. val='1234' + * use + * + * val LIKE '%1%2%3%4%' + */ - start = bsi->bsi_flt_where.bb_val.bv_len; + bv.bv_len = 2 * filter_value->bv_len - 1; + bv.bv_val = ch_malloc( bv.bv_len + 1 ); - backsql_strfcat( &bsi->bsi_flt_where, "bl", - filter_value, - (ber_len_t)sizeof( /* (' */ "')" ) - 1, - /* (' */ "')" ); + bv.bv_val[ 0 ] = filter_value->bv_val[ 0 ]; + for ( i = 1; i < filter_value->bv_len; i++ ) { + bv.bv_val[ 2 * i - 1 ] = '%'; + bv.bv_val[ 2 * i ] = filter_value->bv_val[ i ]; + } + bv.bv_val[ 2 * i - 1 ] = '\0'; - ldap_pvt_str2upper( &bsi->bsi_flt_where.bb_val.bv_val[ start ] ); + (void)backsql_process_filter_like( bsi, at, casefold, &bv ); + ch_free( bv.bv_val ); - } else { - backsql_strfcat( &bsi->bsi_flt_where, "cblbl", - '(', /* ) */ - &at->bam_sel_expr, - (ber_len_t)sizeof( "='" ) - 1, "='", - filter_value, - (ber_len_t)sizeof( /* (' */ "')" ) - 1, - /* (' */ "')" ); + break; } + + /* + * 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. + */ + (void)backsql_process_filter_eq( bsi, at, casefold, filter_value ); break; case LDAP_FILTER_GE: @@ -710,34 +890,7 @@ equality_match:; * upper_func stuff is made for Oracle, where UPPER is * safely applicable to NUMBER etc. */ - if ( at->bam_sel_expr_u.bv_val ) { - ber_len_t start; - - backsql_strfcat( &bsi->bsi_flt_where, "cbl", - '(', /* ) */ - &at->bam_sel_expr_u, - (ber_len_t)sizeof( " LIKE '%" ) - 1, - " LIKE '%" ); - - start = bsi->bsi_flt_where.bb_val.bv_len; - - backsql_strfcat( &bsi->bsi_flt_where, "bl", - &f->f_av_value, - (ber_len_t)sizeof( /* (' */ "%')" ) - 1, - /* (' */ "%')" ); - - ldap_pvt_str2upper( &bsi->bsi_flt_where.bb_val.bv_val[ start ] ); - - } else { - backsql_strfcat( &bsi->bsi_flt_where, "cblbl", - '(', /* ) */ - &at->bam_sel_expr, - (ber_len_t)sizeof( " LIKE '%" ) - 1, - " LIKE '%", - &f->f_av_value, - (ber_len_t)sizeof( /* (' */ "%')" ) - 1, - /* (' */ "%')" ); - } + (void)backsql_process_filter_like( bsi, at, 1, &f->f_av_value ); break; default: @@ -820,14 +973,11 @@ backsql_srch_query( backsql_srch_info *bsi, struct berval *query ) switch ( bsi->bsi_scope ) { case LDAP_SCOPE_BASE: - if ( bi->upper_func.bv_val ) { - backsql_strfcat( &bsi->bsi_join_where, "blbcb", + if ( BACKSQL_CANUPPERCASE( bi ) ) { + backsql_strfcat( &bsi->bsi_join_where, "bl", &bi->upper_func, - (ber_len_t)sizeof( "(ldap_entries.dn)=" ) - 1, - "(ldap_entries.dn)=", - &bi->upper_func_open, - '?', - &bi->upper_func_close ); + (ber_len_t)sizeof( "(ldap_entries.dn)=?" ) - 1, + "(ldap_entries.dn)=?" ); } else { backsql_strfcat( &bsi->bsi_join_where, "l", (ber_len_t)sizeof( "ldap_entries.dn=?" ) - 1, @@ -835,6 +985,19 @@ backsql_srch_query( backsql_srch_info *bsi, struct berval *query ) } break; + case BACKSQL_SCOPE_BASE_LIKE: + if ( BACKSQL_CANUPPERCASE( bi ) ) { + backsql_strfcat( &bsi->bsi_join_where, "bl", + &bi->upper_func, + (ber_len_t)sizeof( "(ldap_entries.dn) LIKE ?" ) - 1, + "(ldap_entries.dn) LIKE ?" ); + } else { + backsql_strfcat( &bsi->bsi_join_where, "l", + (ber_len_t)sizeof( "ldap_entries.dn LIKE ?" ) - 1, + "ldap_entries.dn LIKE ?" ); + } + break; + case LDAP_SCOPE_ONELEVEL: backsql_strfcat( &bsi->bsi_join_where, "l", (ber_len_t)sizeof( "ldap_entries.parent=?" ) - 1, @@ -842,14 +1005,11 @@ backsql_srch_query( backsql_srch_info *bsi, struct berval *query ) break; case LDAP_SCOPE_SUBTREE: - if ( bi->upper_func.bv_val ) { - backsql_strfcat( &bsi->bsi_join_where, "blbcb", + if ( BACKSQL_CANUPPERCASE( bi ) ) { + backsql_strfcat( &bsi->bsi_join_where, "bl", &bi->upper_func, - (ber_len_t)sizeof( "(ldap_entries.dn) LIKE " ) - 1, - "(ldap_entries.dn) LIKE ", - &bi->upper_func_open, - '?', - &bi->upper_func_close ); + (ber_len_t)sizeof( "(ldap_entries.dn) LIKE ?" ) - 1, + "(ldap_entries.dn) LIKE ?" ); } else { backsql_strfcat( &bsi->bsi_join_where, "l", (ber_len_t)sizeof( "ldap_entries.dn LIKE ?" ) - 1, @@ -912,17 +1072,23 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi ) struct berval query; SQLHSTMT sth; RETCODE rc; - backsql_entryID base_id, *c_id; + backsql_entryID base_id = BACKSQL_ENTRYID_INIT; int res; BACKSQL_ROW_NTS row; int i; int j; - int n_candidates = bsi->bsi_n_candidates; + /* + * + 1 because we need room for '%'; this makes a subtree + * search for a DN BACKSQL_MAX_DN_LEN long legal + * if it returns that DN only + */ + char temp_base_dn[ BACKSQL_MAX_DN_LEN + 1 + 1 ]; + bsi->bsi_status = LDAP_SUCCESS; - Debug( LDAP_DEBUG_TRACE, "==>backsql_oc_get_candidates(): oc='%s'\n", + Debug( LDAP_DEBUG_TRACE, "==>backsql_oc_get_candidates(): oc=\"%s\"\n", BACKSQL_OC_NAME( oc ), 0, 0 ); if ( bsi->bsi_n_candidates == -1 ) { @@ -938,7 +1104,7 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi ) res = backsql_srch_query( bsi, &query ); if ( res ) { Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): " - "error while constructing query for objectclass '%s'\n", + "error while constructing query for objectclass \"%s\"\n", oc->bom_oc->soc_cname.bv_val, 0, 0 ); /* * FIXME: need to separate errors from legally @@ -963,7 +1129,7 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi ) if ( query.bv_val == NULL ) { Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): " - "could not construct query for objectclass '%s'\n", + "could not construct query for objectclass \"%s\"\n", oc->bom_oc->soc_cname.bv_val, 0, 0 ); bsi->bsi_status = LDAP_SUCCESS; return BACKSQL_CONTINUE; @@ -993,10 +1159,29 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi ) switch ( bsi->bsi_scope ) { case LDAP_SCOPE_BASE: - Debug( LDAP_DEBUG_TRACE, "(base)dn: '%s'\n", - bsi->bsi_base_dn->bv_val, 0, 0 ); + case BACKSQL_SCOPE_BASE_LIKE: + /* + * We do not accept DNs longer than BACKSQL_MAX_DN_LEN; + * however this should be handled earlier + */ + if ( bsi->bsi_base_dn->bv_len > BACKSQL_MAX_DN_LEN ) { + bsi->bsi_status = LDAP_OTHER; + return BACKSQL_CONTINUE; + } - rc = backsql_BindParamStr( sth, 2, bsi->bsi_base_dn->bv_val, + AC_MEMCPY( temp_base_dn, bsi->bsi_base_dn->bv_val, + bsi->bsi_base_dn->bv_len + 1 ); + + /* uppercase DN only if the stored DN can be uppercased + * for comparison */ + if ( BACKSQL_CANUPPERCASE( bi ) ) { + ldap_pvt_str2upper( temp_base_dn ); + } + + Debug( LDAP_DEBUG_TRACE, "(base)dn: \"%s\"\n", + temp_base_dn, 0, 0 ); + + rc = backsql_BindParamStr( sth, 2, temp_base_dn, BACKSQL_MAX_DN_LEN ); if ( rc != SQL_SUCCESS ) { Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): " @@ -1009,20 +1194,15 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi ) break; case LDAP_SCOPE_SUBTREE: { - - /* - * + 1 because we need room for '%'; this makes a subtree - * search for a DN BACKSQL_MAX_DN_LEN long legal - * if it returns that DN only - */ - char temp_base_dn[ BACKSQL_MAX_DN_LEN + 1 + 1 ]; - /* * We do not accept DNs longer than BACKSQL_MAX_DN_LEN; * however this should be handled earlier */ - assert( bsi->bsi_base_dn->bv_len <= BACKSQL_MAX_DN_LEN ); - + if ( bsi->bsi_base_dn->bv_len > BACKSQL_MAX_DN_LEN ) { + bsi->bsi_status = LDAP_OTHER; + return BACKSQL_CONTINUE; + } + /* * Sets the parameters for the SQL built earlier * NOTE that all the databases could actually use @@ -1050,9 +1230,14 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi ) AC_MEMCPY( &temp_base_dn[ 1 ], bsi->bsi_base_dn->bv_val, bsi->bsi_base_dn->bv_len + 1 ); } - ldap_pvt_str2upper( temp_base_dn ); - Debug( LDAP_DEBUG_TRACE, "(sub)dn: '%s'\n", temp_base_dn, + /* uppercase DN only if the stored DN can be uppercased + * for comparison */ + if ( BACKSQL_CANUPPERCASE( bi ) ) { + ldap_pvt_str2upper( temp_base_dn ); + } + + Debug( LDAP_DEBUG_TRACE, "(sub)dn: \"%s\"\n", temp_base_dn, 0, 0 ); rc = backsql_BindParamStr( sth, 2, temp_base_dn, @@ -1080,11 +1265,19 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi ) bsi->bsi_status = res; return BACKSQL_CONTINUE; } - - Debug( LDAP_DEBUG_TRACE, "(one)id: '%lu'\n", base_id.id, + +#ifdef BACKSQL_ARBITRARY_KEY + Debug( LDAP_DEBUG_TRACE, "(one)id: \"%s\"\n", + base_id.eid_id.bv_val, 0, 0 ); + + rc = backsql_BindParamStr( sth, 2, base_id.eid_id.bv_val, + BACKSQL_MAX_KEY_LEN ); +#else /* ! BACKSQL_ARBITRARY_KEY */ + Debug( LDAP_DEBUG_TRACE, "(one)id: '%lu'\n", base_id.eid_id, 0, 0 ); - rc = backsql_BindParamID( sth, 2, &base_id.id ); + rc = backsql_BindParamID( sth, 2, &base_id.eid_id ); +#endif /* ! BACKSQL_ARBITRARY_KEY */ backsql_free_entryID( &base_id, 0 ); if ( rc != SQL_SUCCESS ) { Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): " @@ -1108,19 +1301,46 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi ) backsql_BindRowAsStrings( sth, &row ); rc = SQLFetch( sth ); for ( ; BACKSQL_SUCCESS( rc ); rc = SQLFetch( sth ) ) { + struct berval dn; + backsql_entryID *c_id = NULL; + + ber_str2bv( row.cols[ 3 ], 0, 0, &dn ); + + if ( backsql_api_odbc2dn( bsi->bsi_op, bsi->bsi_rs, &dn ) ) { + continue; + } + c_id = (backsql_entryID *)ch_calloc( 1, sizeof( backsql_entryID ) ); - c_id->id = strtol( row.cols[ 0 ], NULL, 0 ); - c_id->keyval = strtol( row.cols[ 1 ], NULL, 0 ); - c_id->oc_id = bsi->bsi_oc->bom_id; - ber_str2bv( row.cols[ 3 ], 0, 1, &c_id->dn ); - c_id->next = bsi->bsi_id_list; +#ifdef BACKSQL_ARBITRARY_KEY + ber_str2bv( row.cols[ 0 ], 0, 1, &c_id->eid_id ); + ber_str2bv( row.cols[ 1 ], 0, 1, &c_id->eid_keyval ); +#else /* ! BACKSQL_ARBITRARY_KEY */ + c_id->eid_id = strtol( row.cols[ 0 ], NULL, 0 ); + c_id->eid_keyval = strtol( row.cols[ 1 ], NULL, 0 ); +#endif /* ! BACKSQL_ARBITRARY_KEY */ + c_id->eid_oc_id = bsi->bsi_oc->bom_id; + + if ( dn.bv_val == row.cols[ 3 ] ) { + ber_dupbv( &c_id->eid_dn, &dn ); + } else { + c_id->eid_dn = dn; + } + + c_id->eid_next = bsi->bsi_id_list; bsi->bsi_id_list = c_id; bsi->bsi_n_candidates--; +#ifdef BACKSQL_ARBITRARY_KEY Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): " - "added entry id=%ld, keyval=%ld dn='%s'\n", - c_id->id, c_id->keyval, row.cols[ 3 ] ); + "added entry id=%s, keyval=%s dn=\"%s\"\n", + c_id->eid_id.bv_val, c_id->eid_keyval.bv_val, + row.cols[ 3 ] ); +#else /* ! BACKSQL_ARBITRARY_KEY */ + Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): " + "added entry id=%ld, keyval=%ld dn=\"%s\"\n", + c_id->eid_id, c_id->eid_keyval, row.cols[ 3 ] ); +#endif /* ! BACKSQL_ARBITRARY_KEY */ if ( bsi->bsi_n_candidates == -1 ) { break; @@ -1146,11 +1366,12 @@ backsql_search( Operation *op, SlapReply *rs ) time_t stoptime = 0; backsql_srch_info srch_info; backsql_entryID *eid = NULL; + struct berval base; manageDSAit = get_manageDSAit( op ); Debug( LDAP_DEBUG_TRACE, "==>backsql_search(): " - "base='%s', filter='%s', scope=%d,", + "base=\"%s\", filter=\"%s\", scope=%d,", op->o_req_ndn.bv_val, op->ors_filterstr.bv_val, op->ors_scope ); @@ -1188,11 +1409,22 @@ backsql_search( Operation *op, SlapReply *rs ) /* compute it anyway; root does not use it */ stoptime = op->o_time + op->ors_tlimit; - backsql_init_search( &srch_info, &op->o_req_dn, + base = op->o_req_dn; + if ( backsql_api_dn2odbc( op, rs, &base ) ) { + Debug( LDAP_DEBUG_TRACE, "backsql_search(): " + "backsql_api_dn2odbc failed\n", + 0, 0, 0 ); + rs->sr_err = LDAP_OTHER; + rs->sr_text = "SQL-backend error"; + send_ldap_result( op, rs ); + return 1; + } + + backsql_init_search( &srch_info, &base, op->ors_scope, op->ors_slimit, op->ors_tlimit, stoptime, op->ors_filter, - dbh, op, op->ors_attrs ); + dbh, op, rs, op->ors_attrs ); /* * for each objectclass we try to construct query which gets IDs @@ -1240,9 +1472,16 @@ backsql_search( Operation *op, SlapReply *rs ) goto end_of_search; } +#ifdef BACKSQL_ARBITRARY_KEY + Debug(LDAP_DEBUG_TRACE, "backsql_search(): loading data " + "for entry id=%s, oc_id=%ld, keyval=%s\n", + eid->eid_id.bv_val, eid->eid_oc_id, + eid->eid_keyval.bv_val ); +#else /* ! BACKSQL_ARBITRARY_KEY */ Debug(LDAP_DEBUG_TRACE, "backsql_search(): loading data " "for entry id=%ld, oc_id=%ld, keyval=%ld\n", - eid->id, eid->oc_id, eid->keyval ); + eid->eid_id, eid->eid_oc_id, eid->eid_keyval ); +#endif /* ! BACKSQL_ARBITRARY_KEY */ entry = (Entry *)ch_calloc( sizeof( Entry ), 1 ); res = backsql_id2entry( &srch_info, entry, eid ); @@ -1255,6 +1494,7 @@ backsql_search( Operation *op, SlapReply *rs ) if ( !manageDSAit && op->ors_scope != LDAP_SCOPE_BASE && + op->ors_scope != BACKSQL_SCOPE_BASE_LIKE && is_entry_referral( entry ) ) { BerVarray refs; struct berval matched_dn; @@ -1390,6 +1630,9 @@ end_of_search:; done:; ch_free( srch_info.bsi_attrs ); + if ( base.bv_val != op->o_req_ndn.bv_val ) { + ch_free( base.bv_val ); + } Debug( LDAP_DEBUG_TRACE, "<==backsql_search()\n", 0, 0, 0 ); return 0; diff --git a/servers/slapd/back-sql/sql-wrap.c b/servers/slapd/back-sql/sql-wrap.c index e86477c1ba..91df43f3a5 100644 --- a/servers/slapd/back-sql/sql-wrap.c +++ b/servers/slapd/back-sql/sql-wrap.c @@ -80,7 +80,7 @@ backsql_Prepare( SQLHDBC dbh, SQLHSTMT *sth, char *query, int timeout ) SQLGetInfo( dbh, SQL_DRIVER_NAME, drv_name, sizeof( drv_name ), &len ); #ifdef BACKSQL_TRACE - Debug( LDAP_DEBUG_TRACE, "backsql_Prepare(): driver name='%s'\n", + Debug( LDAP_DEBUG_TRACE, "backsql_Prepare(): driver name=\"%s\"\n", drv_name, 0, 0 ); #endif /* BACKSQL_TRACE */ @@ -333,7 +333,7 @@ backsql_open_db_conn( backsql_info *si, int ldap_cid, backsql_db_conn **pdbc ) SQL_NTS, si->dbpasswd, SQL_NTS ); if ( rc != SQL_SUCCESS ) { Debug( LDAP_DEBUG_TRACE, "backsql_open_db_conn: " - "SQLConnect() to database '%s' as user '%s' " + "SQLConnect() to database \"%s\" as user \"%s\" " "%s:\n", si->dbname, si->dbuser, rc == SQL_SUCCESS_WITH_INFO ? "succeeded with info" : "failed" ); diff --git a/servers/slapd/back-sql/util.c b/servers/slapd/back-sql/util.c index a138989c59..4523b31377 100644 --- a/servers/slapd/back-sql/util.c +++ b/servers/slapd/back-sql/util.c @@ -119,7 +119,7 @@ backsql_strcat( struct berbuf *dest, ... ) va_end( strs ); #ifdef BACKSQL_TRACE - Debug( LDAP_DEBUG_TRACE, "<==backsql_strcat() (dest='%s')\n", + Debug( LDAP_DEBUG_TRACE, "<==backsql_strcat() (dest=\"%s\")\n", dest, 0, 0 ); #endif /* BACKSQL_TRACE */ @@ -230,7 +230,7 @@ backsql_strfcat( struct berbuf *dest, const char *fmt, ... ) va_end( strs ); #ifdef BACKSQL_TRACE - Debug( LDAP_DEBUG_TRACE, "<==backsql_strfcat() (dest='%s')\n", + Debug( LDAP_DEBUG_TRACE, "<==backsql_strfcat() (dest=\"%s\")\n", dest, 0, 0 ); #endif /* BACKSQL_TRACE */ @@ -252,7 +252,7 @@ backsql_entry_addattr( #ifdef BACKSQL_TRACE Debug( LDAP_DEBUG_TRACE, "backsql_entry_addattr(): " - "at_name='%s', at_val='%s'\n", + "at_name=\"%s\", at_val=\"%s\"\n", at_name->bv_val, at_val->bv_val, 0 ); #endif /* BACKSQL_TRACE */ @@ -260,7 +260,7 @@ backsql_entry_addattr( rc = slap_bv2ad( at_name, &ad, &text ); if ( rc != LDAP_SUCCESS ) { Debug( LDAP_DEBUG_TRACE, "backsql_entry_addattr(): " - "failed to find AttributeDescription for '%s'\n", + "failed to find AttributeDescription for \"%s\"\n", at_name->bv_val, 0, 0 ); return 0; } @@ -269,7 +269,7 @@ backsql_entry_addattr( if ( rc != 0 ) { Debug( LDAP_DEBUG_TRACE, "backsql_entry_addattr(): " - "failed to merge value '%s' for attribute '%s'\n", + "failed to merge value \"%s\" for attribute \"%s\"\n", at_val->bv_val, at_name->bv_val, 0 ); return 0; } @@ -339,7 +339,7 @@ backsql_merge_from_clause( #ifdef BACKSQL_TRACE Debug( LDAP_DEBUG_TRACE, "==>backsql_merge_from_clause(): " - "dest_from='%s',src_from='%s'\n", + "dest_from=\"%s\",src_from=\"%s\"\n", dest_from ? dest_from->bb_val.bv_val : "", src_from, 0 ); #endif /* BACKSQL_TRACE */ @@ -355,7 +355,7 @@ backsql_merge_from_clause( #ifdef BACKSQL_TRACE Debug( LDAP_DEBUG_TRACE, "backsql_merge_from_clause(): " - "p='%s' s='%s'\n", p, s, 0 ); + "p=\"%s\" s=\"%s\"\n", p, s, 0 ); #endif /* BACKSQL_TRACE */ if ( res.bb_val.bv_val == NULL ) { diff --git a/servers/slapd/backend.c b/servers/slapd/backend.c index 54249eebc4..b8f4b17d00 100644 --- a/servers/slapd/backend.c +++ b/servers/slapd/backend.c @@ -51,97 +51,97 @@ * imported into slapd without appropriate __declspec(dllimport) directives. */ -#if defined(SLAPD_BDB) && !defined(SLAPD_BDB_DYNAMIC) +#if SLAPD_BDB == SLAPD_MOD_STATIC #include "back-bdb/external.h" #endif -#if defined(SLAPD_DNSSRV) && !defined(SLAPD_DNSSRV_DYNAMIC) +#if SLAPD_DNSSRV == SLAPD_MOD_STATIC #include "back-dnssrv/external.h" #endif -#if defined(SLAPD_HDB) && !defined(SLAPD_HDB_DYNAMIC) +#if SLAPD_HDB == SLAPD_MOD_STATIC #include "back-hdb/external.h" #endif -#if defined(SLAPD_LDAP) && !defined(SLAPD_LDAP_DYNAMIC) +#if SLAPD_LDAP == SLAPD_MOD_STATIC #include "back-ldap/external.h" #endif -#if defined(SLAPD_LDBM) && !defined(SLAPD_LDBM_DYNAMIC) +#if SLAPD_LDBM == SLAPD_MOD_STATIC #include "back-ldbm/external.h" #endif -#if defined(SLAPD_META) && !defined(SLAPD_META_DYNAMIC) +#if SLAPD_META == SLAPD_MOD_STATIC #include "back-meta/external.h" #endif -#if defined(SLAPD_MONITOR) && !defined(SLAPD_MONITOR_DYNAMIC) +#if SLAPD_MONITOR == SLAPD_MOD_STATIC #include "back-monitor/external.h" #endif -#if defined(SLAPD_NULL) && !defined(SLAPD_NULL_DYNAMIC) +#if SLAPD_NULL == SLAPD_MOD_STATIC #include "back-null/external.h" #endif -#if defined(SLAPD_PASSWD) && !defined(SLAPD_PASSWD_DYNAMIC) +#if SLAPD_PASSWD == SLAPD_MOD_STATIC #include "back-passwd/external.h" #endif -#if defined(SLAPD_PERL) && !defined(SLAPD_PERL_DYNAMIC) +#if SLAPD_PERL == SLAPD_MOD_STATIC #include "back-perl/external.h" #endif -#if defined(SLAPD_RELAY) && !defined(SLAPD_RELAY_DYNAMIC) +#if SLAPD_RELAY == SLAPD_MOD_STATIC #include "back-relay/external.h" #endif -#if defined(SLAPD_SHELL) && !defined(SLAPD_SHELL_DYNAMIC) +#if SLAPD_SHELL == SLAPD_MOD_STATIC #include "back-shell/external.h" #endif -#if defined(SLAPD_TCL) && !defined(SLAPD_TCL_DYNAMIC) +#if SLAPD_TCL == SLAPD_MOD_STATIC #include "back-tcl/external.h" #endif -#if defined(SLAPD_SQL) && !defined(SLAPD_SQL_DYNAMIC) +#if SLAPD_SQL == SLAPD_MOD_STATIC #include "back-sql/external.h" #endif -#if defined(SLAPD_PRIVATE) && !defined(SLAPD_PRIVATE_DYNAMIC) +#if SLAPD_PRIVATE == SLAPD_MOD_STATIC #include "private/external.h" #endif static BackendInfo binfo[] = { -#if defined(SLAPD_BDB) && !defined(SLAPD_BDB_DYNAMIC) +#if SLAPD_BDB == SLAPD_MOD_STATIC {"bdb", bdb_initialize}, #endif -#if defined(SLAPD_DNSSRV) && !defined(SLAPD_DNSSRV_DYNAMIC) +#if SLAPD_DNSSRV == SLAPD_MOD_STATIC {"dnssrv", dnssrv_back_initialize}, #endif -#if defined(SLAPD_HDB) && !defined(SLAPD_HDB_DYNAMIC) +#if SLAPD_HDB == SLAPD_MOD_STATIC {"hdb", hdb_initialize}, #endif -#if defined(SLAPD_LDAP) && !defined(SLAPD_LDAP_DYNAMIC) +#if SLAPD_LDAP == SLAPD_MOD_STATIC {"ldap", ldap_back_initialize}, #endif -#if defined(SLAPD_LDBM) && !defined(SLAPD_LDBM_DYNAMIC) +#if SLAPD_LDBM == SLAPD_MOD_STATIC {"ldbm", ldbm_back_initialize}, #endif -#if defined(SLAPD_META) && !defined(SLAPD_META_DYNAMIC) +#if SLAPD_META == SLAPD_MOD_STATIC {"meta", meta_back_initialize}, #endif -#if defined(SLAPD_MONITOR) && !defined(SLAPD_MONITOR_DYNAMIC) +#if SLAPD_MONITOR == SLAPD_MOD_STATIC {"monitor", monitor_back_initialize}, #endif -#if defined(SLAPD_NULL) && !defined(SLAPD_NULL_DYNAMIC) +#if SLAPD_NULL == SLAPD_MOD_STATIC {"null", null_back_initialize}, #endif -#if defined(SLAPD_PASSWD) && !defined(SLAPD_PASSWD_DYNAMIC) +#if SLAPD_PASSWD == SLAPD_MOD_STATIC {"passwd", passwd_back_initialize}, #endif -#if defined(SLAPD_PERL) && !defined(SLAPD_PERL_DYNAMIC) +#if SLAPD_PERL == SLAPD_MOD_STATIC {"perl", perl_back_initialize}, #endif -#if defined(SLAPD_RELAY) && !defined(SLAPD_RELAY_DYNAMIC) +#if SLAPD_RELAY == SLAPD_MOD_STATIC {"relay", relay_back_initialize}, #endif -#if defined(SLAPD_SHELL) && !defined(SLAPD_SHELL_DYNAMIC) +#if SLAPD_SHELL == SLAPD_MOD_STATIC {"shell", shell_back_initialize}, #endif -#if defined(SLAPD_TCL) && !defined(SLAPD_TCL_DYNAMIC) +#if SLAPD_TCL == SLAPD_MOD_STATIC {"tcl", tcl_back_initialize}, #endif -#if defined(SLAPD_SQL) && !defined(SLAPD_SQL_DYNAMIC) +#if SLAPD_SQL == SLAPD_MOD_STATIC {"sql", sql_back_initialize}, #endif /* for any private backend */ -#if defined(SLAPD_PRIVATE) && !defined(SLAPD_PRIVATE_DYNAMIC) +#if SLAPD_PRIVATE == SLAPD_MOD_STATIC {"private", private_back_initialize}, #endif {NULL} @@ -728,9 +728,25 @@ be_isroot_dn( Backend *be, struct berval *ndn ) } int -be_isupdate( Operation *op ) +be_sync_update( Operation *op ) { - return be_isupdate_dn( op->o_bd, &op->o_ndn ); + return ( SLAP_SYNC_SHADOW( op->o_bd ) && syncrepl_isupdate( op ) ); +} + +int +be_slurp_update( Operation *op ) +{ + return ( SLAP_SLURP_SHADOW( op->o_bd ) && be_isupdate_dn( op->o_bd, &op->o_ndn )); +} + +int +be_shadow_update( Operation *op ) +{ +#if 0 + return ( be_sync_update( op ) || be_slurp_update( op ) ); +#endif + /* NOTE: this is slightly more efficient */ + return ( SLAP_SHADOW( op->o_bd ) && ( syncrepl_isupdate( op ) || be_isupdate_dn( op->o_bd, &op->o_ndn ) ) ); } int diff --git a/servers/slapd/config.c b/servers/slapd/config.c index 3f9db3e69f..2edeab448a 100644 --- a/servers/slapd/config.c +++ b/servers/slapd/config.c @@ -54,7 +54,8 @@ struct slap_limits_set deflimit = { 0, -1, /* no limit on unchecked size */ 0, /* page limit */ - 0 /* hide number of entries left */ + 0, /* hide number of entries left */ + 0 /* number of total entries returned by pagedResults equal to hard limit */ }; AccessControl *global_acl = NULL; @@ -73,11 +74,11 @@ char *ldap_srvtab = ""; char **default_passwd_hash = NULL; int cargc = 0, cargv_size = 0; char **cargv; -struct berval default_search_base = { 0, NULL }; -struct berval default_search_nbase = { 0, NULL }; +struct berval default_search_base = BER_BVNULL; +struct berval default_search_nbase = BER_BVNULL; unsigned num_subordinates = 0; -struct berval global_schemadn = { 0, NULL }; -struct berval global_schemandn = { 0, NULL }; +struct berval global_schemadn = BER_BVNULL; +struct berval global_schemandn = BER_BVNULL; ber_len_t sockbuf_max_incoming = SLAP_SB_MAX_INCOMING_DEFAULT; ber_len_t sockbuf_max_incoming_auth= SLAP_SB_MAX_INCOMING_AUTH; @@ -1818,7 +1819,7 @@ read_config( const char *fname, int depth ) return 1; } - SLAP_DBFLAGS(be) |= SLAP_DBFLAG_SHADOW; + SLAP_DBFLAGS(be) |= ( SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SYNC_SHADOW ); /* list of replicas of the data in this backend (master only) */ } else if ( strcasecmp( cargv[0], "replica" ) == 0 ) { @@ -2058,7 +2059,7 @@ read_config( const char *fname, int depth ) } } - SLAP_DBFLAGS(be) |= SLAP_DBFLAG_SHADOW; + SLAP_DBFLAGS(be) |= ( SLAP_DBFLAG_SHADOW | SLAP_DBFLAG_SLURP_SHADOW ); } else if ( strcasecmp( cargv[0], "updateref" ) == 0 ) { if ( cargc < 2 ) { diff --git a/servers/slapd/controls.c b/servers/slapd/controls.c index 2651c1e405..6ad3dc8c95 100644 --- a/servers/slapd/controls.c +++ b/servers/slapd/controls.c @@ -714,7 +714,7 @@ static int parseProxyAuthz ( LDAPControl *ctrl ) { int rc; - struct berval dn = { 0, NULL }; + struct berval dn = BER_BVNULL; if ( op->o_proxy_authz != SLAP_NO_CONTROL ) { rs->sr_text = "proxy authorization control specified multiple times"; @@ -840,7 +840,7 @@ static int parsePagedResults ( ber_tag_t tag; ber_int_t size; BerElement *ber; - struct berval cookie = { 0, NULL }; + struct berval cookie = BER_BVNULL; if ( op->o_pagedresults != SLAP_NO_CONTROL ) { rs->sr_text = "paged results control specified multiple times"; @@ -889,19 +889,21 @@ static int parsePagedResults ( AC_MEMCPY( &reqcookie, cookie.bv_val, sizeof( reqcookie )); - if( reqcookie > op->o_pagedresults_state.ps_cookie ) { + if ( reqcookie > op->o_pagedresults_state.ps_cookie ) { /* bad cookie */ rs->sr_text = "paged results cookie is invalid"; return LDAP_PROTOCOL_ERROR; - } else if( reqcookie < op->o_pagedresults_state.ps_cookie ) { + } else if ( reqcookie < op->o_pagedresults_state.ps_cookie ) { rs->sr_text = "paged results cookie is invalid or old"; return LDAP_UNWILLING_TO_PERFORM; } + } else { /* Initial request. Initialize state. */ op->o_pagedresults_state.ps_cookie = 0; op->o_pagedresults_state.ps_id = NOID; + op->o_pagedresults_state.ps_count = 0; } op->o_pagedresults_size = size; @@ -919,7 +921,7 @@ static int parseAssert ( LDAPControl *ctrl ) { BerElement *ber; - struct berval fstr = { 0, NULL }; + struct berval fstr = BER_BVNULL; const char *err_msg = ""; if ( op->o_assert != SLAP_NO_CONTROL ) { @@ -1094,7 +1096,7 @@ int parseValuesReturnFilter ( LDAPControl *ctrl ) { BerElement *ber; - struct berval fstr = { 0, NULL }; + struct berval fstr = BER_BVNULL; const char *err_msg = ""; if ( op->o_valuesreturnfilter != SLAP_NO_CONTROL ) { diff --git a/servers/slapd/delete.c b/servers/slapd/delete.c index 4e701eaa31..70f4cee5e0 100644 --- a/servers/slapd/delete.c +++ b/servers/slapd/delete.c @@ -45,12 +45,12 @@ do_delete( SlapReply *rs ) { - struct berval dn = { 0, NULL }; - struct berval pdn = { 0, NULL }; - struct berval org_req_dn = { 0, NULL }; - struct berval org_req_ndn = { 0, NULL }; - struct berval org_dn = { 0, NULL }; - struct berval org_ndn = { 0, NULL }; + struct berval dn = BER_BVNULL; + struct berval pdn = BER_BVNULL; + struct berval org_req_dn = BER_BVNULL; + struct berval org_req_ndn = BER_BVNULL; + struct berval org_dn = BER_BVNULL; + struct berval org_ndn = BER_BVNULL; int org_managedsait; int manageDSAit; @@ -208,8 +208,6 @@ do_delete( int repl_user = be_isupdate( op ); #ifndef SLAPD_MULTIMASTER if ( !SLAP_SHADOW(op->o_bd) || repl_user ) -#else - if ( LDAP_STAILQ_EMPTY( &op->o_bd->be_syncinfo )) #endif { slap_callback cb = { NULL, slap_replog_cb, NULL, NULL }; diff --git a/servers/slapd/limits.c b/servers/slapd/limits.c index 291824ac95..d287795883 100644 --- a/servers/slapd/limits.c +++ b/servers/slapd/limits.c @@ -341,23 +341,23 @@ limits_parse( } else if ( strcasecmp( pattern, "users" ) == 0 ) { flags = SLAP_LIMITS_USERS; - } else if ( strncasecmp( pattern, "dn", sizeof( "dn" ) - 1 ) == 0 ) { - pattern += sizeof( "dn" ) - 1; + } else if ( strncasecmp( pattern, "dn", STRLENOF( "dn" ) ) == 0 ) { + pattern += STRLENOF( "dn" ); if ( pattern[0] == '.' ) { pattern++; - if ( strncasecmp( pattern, "exact", sizeof( "exact" ) - 1 ) == 0 ) { + if ( strncasecmp( pattern, "exact", STRLENOF( "exact" )) == 0 ) { flags = SLAP_LIMITS_EXACT; - pattern += sizeof( "exact" ) - 1; + pattern += STRLENOF( "exact" ); - } else if ( strncasecmp( pattern, "base", sizeof( "base" ) - 1 ) == 0 ) { + } else if ( strncasecmp( pattern, "base", STRLENOF( "base" ) ) == 0 ) { flags = SLAP_LIMITS_BASE; - pattern += sizeof( "base" ) - 1; + pattern += STRLENOF( "base" ); - } else if ( strncasecmp( pattern, "one", sizeof( "one" ) - 1 ) == 0 ) { + } else if ( strncasecmp( pattern, "one", STRLENOF( "one" ) ) == 0 ) { flags = SLAP_LIMITS_ONE; - pattern += sizeof( "one" ) - 1; - if ( strncasecmp( pattern, "level", sizeof( "level" ) - 1 ) == 0 ) { - pattern += sizeof( "level" ) - 1; + pattern += STRLENOF( "one" ); + if ( strncasecmp( pattern, "level", STRLENOF( "level" ) ) == 0 ) { + pattern += STRLENOF( "level" ); } else { #ifdef NEW_LOGGING @@ -373,11 +373,11 @@ limits_parse( #endif } - } else if ( strncasecmp( pattern, "sub", sizeof( "sub" ) - 1 ) == 0 ) { + } else if ( strncasecmp( pattern, "sub", STRLENOF( "sub" ) ) == 0 ) { flags = SLAP_LIMITS_SUBTREE; - pattern += sizeof( "sub" ) - 1; - if ( strncasecmp( pattern, "tree", sizeof( "tree" ) - 1 ) == 0 ) { - pattern += sizeof( "tree" ) - 1; + pattern += STRLENOF( "sub" ); + if ( strncasecmp( pattern, "tree", STRLENOF( "tree" ) ) == 0 ) { + pattern += STRLENOF( "tree" ); } else { #ifdef NEW_LOGGING @@ -393,19 +393,19 @@ limits_parse( #endif } - } else if ( strncasecmp( pattern, "children", sizeof( "children" ) - 1 ) == 0 ) { + } else if ( strncasecmp( pattern, "children", STRLENOF( "children" ) ) == 0 ) { flags = SLAP_LIMITS_CHILDREN; - pattern += sizeof( "children" ) - 1; + pattern += STRLENOF( "children" ); - } else if ( strncasecmp( pattern, "regex", sizeof( "regex" ) - 1 ) == 0 ) { + } else if ( strncasecmp( pattern, "regex", STRLENOF( "regex" ) ) == 0 ) { flags = SLAP_LIMITS_REGEX; - pattern += sizeof( "regex" ) - 1; + pattern += STRLENOF( "regex" ); /* * this could be deprecated in favour * of the pattern = "anonymous" form */ - } else if ( strncasecmp( pattern, "anonymous", sizeof( "anonymous" ) - 1 ) == 0 ) { + } else if ( strncasecmp( pattern, "anonymous", STRLENOF( "anonymous" ) ) == 0 ) { flags = SLAP_LIMITS_ANONYMOUS; pattern = NULL; } @@ -456,8 +456,8 @@ limits_parse( } } - } else if (strncasecmp( pattern, "group", sizeof( "group" ) - 1 ) == 0 ) { - pattern += sizeof( "group" ) - 1; + } else if (strncasecmp( pattern, "group", STRLENOF( "group" ) ) == 0 ) { + pattern += STRLENOF( "group" ); if ( pattern[0] == '/' ) { struct berval oc, ad; @@ -571,7 +571,22 @@ no_ad:; || limit.lms_s_soft == -1 ) ) { limit.lms_s_hard = limit.lms_s_soft; } - + + /* + * defaults ... + */ + if ( limit.lms_t_hard == 0 ) { + limit.lms_t_hard = limit.lms_t_soft; + } + + if ( limit.lms_s_hard == 0 ) { + limit.lms_s_hard = limit.lms_s_soft; + } + + if ( limit.lms_s_pr_total == 0 ) { + limit.lms_s_pr_total = limit.lms_s_hard; + } + rc = limits_add( be, flags, pattern, group_oc, group_ad, &limit ); if ( rc ) { @@ -600,47 +615,64 @@ limits_parse_one( assert( arg ); assert( limit ); - if ( strncasecmp( arg, "time", sizeof( "time" ) - 1 ) == 0 ) { - arg += 4; + if ( strncasecmp( arg, "time", STRLENOF( "time" ) ) == 0 ) { + arg += STRLENOF( "time" ); if ( arg[0] == '.' ) { arg++; - if ( strncasecmp( arg, "soft", sizeof( "soft" ) - 1 ) == 0 ) { - arg += 4; - if ( arg[0] != '=' ) { - return( 1 ); - } - arg++; + if ( strncasecmp( arg, "soft=", STRLENOF( "soft=" ) ) == 0 ) { + arg += STRLENOF( "soft=" ); if ( strcasecmp( arg, "none" ) == 0 ) { limit->lms_t_soft = -1; + } else { char *next = NULL; + int soft = strtol( arg, &next, 10 ); - limit->lms_t_soft = - strtol( arg, &next, 10 ); - if ( next == arg || limit->lms_t_soft < -1 ) { + if ( next == arg || next[ 0 ] != '\0' ) { return( 1 ); } + + if ( soft < -1 ) { + return( 1 ); + } + + if ( soft == -1 ) { + /* FIXME: use "none" instead */ + } + + limit->lms_t_soft = soft; } - } else if ( strncasecmp( arg, "hard", sizeof( "hard" ) - 1 ) == 0 ) { - arg += 4; - if ( arg[0] != '=' ) { - return( 1 ); - } - arg++; + } else if ( strncasecmp( arg, "hard=", STRLENOF( "hard=" ) ) == 0 ) { + arg += STRLENOF( "hard=" ); if ( strcasecmp( arg, "soft" ) == 0 ) { limit->lms_t_hard = 0; + } else if ( strcasecmp( arg, "none" ) == 0 ) { limit->lms_t_hard = -1; + } else { char *next = NULL; + int hard = strtol( arg, &next, 10 ); - limit->lms_t_hard = - strtol( arg, &next, 10 ); - if ( next == arg || limit->lms_t_hard < -1 ) { + if ( next == arg || next[ 0 ] != '\0' ) { return( 1 ); } + + if ( hard < -1 ) { + return( 1 ); + } + + if ( hard == -1 ) { + /* FIXME: use "none" instead */ + } + + if ( hard == 0 ) { + /* FIXME: use "soft" instead */ + } + + limit->lms_t_hard = hard; } } else { @@ -665,85 +697,155 @@ limits_parse_one( return( 1 ); } - } else if ( strncasecmp( arg, "size", sizeof( "size" ) - 1 ) == 0 ) { - arg += 4; + } else if ( strncasecmp( arg, "size", STRLENOF( "size" ) ) == 0 ) { + arg += STRLENOF( "size" ); if ( arg[0] == '.' ) { arg++; - if ( strncasecmp( arg, "soft", sizeof( "soft" ) - 1 ) == 0 ) { - arg += 4; - if ( arg[0] != '=' ) { - return( 1 ); - } - arg++; + if ( strncasecmp( arg, "soft=", STRLENOF( "soft=" ) ) == 0 ) { + arg += STRLENOF( "soft=" ); if ( strcasecmp( arg, "none" ) == 0 ) { limit->lms_s_soft = -1; } else { char *next = NULL; + int soft = strtol( arg, &next, 10 ); + + if ( next == arg || next[ 0 ] != '\0' ) { + return( 1 ); + } - limit->lms_s_soft = - strtol( arg, &next, 10 ); - if ( next == arg || limit->lms_s_soft < -1 ) { + if ( soft < -1 ) { return( 1 ); } + + if ( soft == -1 ) { + /* FIXME: use "none" instead */ + } + + limit->lms_s_soft = soft; } - } else if ( strncasecmp( arg, "hard", sizeof( "hard" ) - 1 ) == 0 ) { - arg += 4; - if ( arg[0] != '=' ) { - return( 1 ); - } - arg++; + } else if ( strncasecmp( arg, "hard=", STRLENOF( "hard=" ) ) == 0 ) { + arg += STRLENOF( "hard=" ); if ( strcasecmp( arg, "soft" ) == 0 ) { limit->lms_s_hard = 0; + } else if ( strcasecmp( arg, "none" ) == 0 ) { limit->lms_s_hard = -1; + } else { char *next = NULL; + int hard = strtol( arg, &next, 10 ); + + if ( next == arg || next[ 0 ] != '\0' ) { + return( 1 ); + } - limit->lms_s_hard = - strtol( arg, &next, 10 ); - if ( next == arg || limit->lms_s_hard < -1 ) { + if ( hard < -1 ) { return( 1 ); } + + if ( hard == -1 ) { + /* FIXME: use "none" instead */ + } + + if ( hard == 0 ) { + /* FIXME: use "soft" instead */ + } + + limit->lms_s_hard = hard; } - } else if ( strncasecmp( arg, "unchecked", sizeof( "unchecked" ) - 1 ) == 0 ) { - arg += 9; - if ( arg[0] != '=' ) { - return( 1 ); - } - arg++; + } else if ( strncasecmp( arg, "unchecked=", STRLENOF( "unchecked=" ) ) == 0 ) { + arg += STRLENOF( "unchecked=" ); if ( strcasecmp( arg, "none" ) == 0 ) { limit->lms_s_unchecked = -1; + + } else if ( strcasecmp( arg, "disabled" ) == 0 ) { + limit->lms_s_unchecked = 0; + } else { char *next = NULL; + int unchecked = strtol( arg, &next, 10 ); - limit->lms_s_unchecked = - strtol( arg, &next, 10 ); - if ( next == arg || limit->lms_s_unchecked < -1 ) { + if ( next == arg || next[ 0 ] != '\0' ) { return( 1 ); } - } - } else if ( strncasecmp( arg, "pr", sizeof( "pr" ) - 1 ) == 0 ) { - arg += sizeof( "pr" ) - 1; - if ( arg[0] != '=' ) { - return( 1 ); + if ( unchecked < -1 ) { + return( 1 ); + } + + if ( unchecked == -1 ) { + /* FIXME: use "none" instead */ + } + + limit->lms_s_unchecked = unchecked; } - arg++; + + } else if ( strncasecmp( arg, "pr=", STRLENOF( "pr=" ) ) == 0 ) { + arg += STRLENOF( "pr=" ); if ( strcasecmp( arg, "noEstimate" ) == 0 ) { limit->lms_s_pr_hide = 1; + + } else if ( strcasecmp( arg, "none" ) == 0 ) { + limit->lms_s_pr = -1; + + } else if ( strcasecmp( arg, "disabled" ) == 0 ) { + limit->lms_s_pr_total = -2; + } else { char *next = NULL; + int pr = strtol( arg, &next, 10 ); - limit->lms_s_pr = - strtol( arg, &next, 10 ); - if ( next == arg || limit->lms_s_pr < -1 ) { + if ( next == arg || next[ 0 ] != '\0' ) { return( 1 ); } + + if ( pr < -1 ) { + return( 1 ); + } + + if ( pr == -1 ) { + /* FIXME: use "none" instead */ + } + + limit->lms_s_pr = pr; } - + + } else if ( strncasecmp( arg, "prtotal=", STRLENOF( "prtotal=" ) ) == 0 ) { + arg += STRLENOF( "prtotal=" ); + + if ( strcasecmp( arg, "none" ) == 0 ) { + limit->lms_s_pr_total = -1; + + } else if ( strcasecmp( arg, "hard" ) == 0 ) { + limit->lms_s_pr_total = 0; + + } else { + char *next = NULL; + int total; + + total = strtol( arg, &next, 10 ); + if ( next == arg || next[ 0 ] != '\0' ) { + return( 1 ); + } + + if ( total < -1 ) { + return( 1 ); + } + + if ( total == -1 ) { + /* FIXME: use "none" instead */ + } + + if ( total == 0 ) { + /* FIXME: use "pr=disable" instead */ + } + + limit->lms_s_pr_total = total; + } + } else { return( 1 ); } @@ -819,13 +921,118 @@ limits_check( Operation *op, SlapReply *rs ) /* negative hard limit means no limit */ } + + /* don't even get to backend if candidate check is disabled */ + if ( op->ors_limit->lms_s_unchecked == 0 ) { + rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED; + send_ldap_result( op, rs ); + rs->sr_err = LDAP_SUCCESS; + return -1; + } + + /* if paged results is requested */ + if ( get_pagedresults( op ) ) { + int slimit = -2; + + /* paged results is not allowed */ + if ( op->ors_limit->lms_s_pr_total == -2 ) { + rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED; + rs->sr_text = "pagedResults control not allowed"; + send_ldap_result( op, rs ); + rs->sr_err = LDAP_SUCCESS; + rs->sr_text = NULL; + return -1; - /* if no limit is required, use soft limit */ - if ( op->ors_slimit <= 0 ) { - if ( get_pagedresults( op ) && op->ors_limit->lms_s_pr != 0 ) { - op->ors_slimit = op->ors_limit->lms_s_pr; } else { - op->ors_slimit = op->ors_limit->lms_s_soft; + /* if no limit is required, use soft limit */ + int total; + int slimit2 = -1; + + /* first round of pagedResults: set count to any appropriate limit */ + + /* if the limit is set, check that it does not violate any limit */ + if ( op->ors_slimit > 0 ) { + slimit2 = op->ors_slimit; + if ( op->ors_limit->lms_s_pr_total > 0 ) { + if ( op->ors_slimit > op->ors_limit->lms_s_pr_total ) { + slimit2 = -2; + } + + } else if ( op->ors_limit->lms_s_hard > 0 ) { + if ( op->ors_slimit > op->ors_limit->lms_s_hard ) { + slimit2 = -2; + } + + } else if ( op->ors_limit->lms_s_soft > 0 && op->ors_slimit > op->ors_limit->lms_s_soft ) { + if ( op->ors_slimit > op->ors_limit->lms_s_soft ) { + slimit2 = -2; + } + } + + if ( slimit2 == -2 ) { + rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED; + send_ldap_result( op, rs ); + rs->sr_err = LDAP_SUCCESS; + return -1; + } + + } else { + if ( op->ors_limit->lms_s_pr_total > 0 ) { + slimit2 = op->ors_limit->lms_s_pr_total; + + } else if ( op->ors_limit->lms_s_hard > 0 ) { + slimit2 = op->ors_limit->lms_s_hard; + + } else if ( op->ors_limit->lms_s_soft > 0 ) { + slimit2 = op->ors_limit->lms_s_soft; + } + } + + total = slimit2 - op->o_pagedresults_state.ps_count; + + if ( total >= 0 && op->ors_limit->lms_s_pr > 0 ) { + /* use the smallest limit set by total/per page */ + if ( total < op->ors_limit->lms_s_pr ) { + slimit = total; + + } else { + /* use the perpage limit if any + * NOTE: + 1 because the given value must be legal */ + slimit = op->ors_limit->lms_s_pr + 1; + } + + } else if ( total >= 0 ) { + /* use the total limit if any */ + slimit = total; + + } else if ( op->ors_limit->lms_s_pr != 0 ) { + /* use the perpage limit if any + * NOTE: + 1 because the given value must be legal */ + slimit = op->ors_limit->lms_s_pr + 1; + + } else { + /* use the standard hard/soft limit if any */ + slimit = op->ors_limit->lms_s_hard; + } + } + + /* if got any limit, use it */ + if ( slimit != -2 ) { + if ( op->ors_slimit <= 0 ) { + op->ors_slimit = slimit; + + } else if ( op->ors_slimit - op->o_pagedresults_state.ps_count > slimit ) { + rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED; + send_ldap_result( op, rs ); + rs->sr_err = LDAP_SUCCESS; + return -1; + } else { + op->ors_slimit = slimit; + } + + } else { + /* use the standard hard/soft limit if any */ + op->ors_slimit = op->ors_limit->lms_s_hard; } /* if requested limit higher than hard limit, abort */ @@ -845,6 +1052,9 @@ limits_check( Operation *op, SlapReply *rs ) } /* negative hard limit means no limit */ + + } else if ( op->ors_slimit == 0 ) { + op->ors_slimit = op->ors_limit->lms_s_soft; } } diff --git a/servers/slapd/modify.c b/servers/slapd/modify.c index ea498a0f06..b9e38eb17c 100644 --- a/servers/slapd/modify.c +++ b/servers/slapd/modify.c @@ -44,7 +44,7 @@ do_modify( Operation *op, SlapReply *rs ) { - struct berval dn = { 0, NULL }; + struct berval dn = BER_BVNULL; char *last; ber_tag_t tag; ber_len_t len; @@ -101,9 +101,7 @@ do_modify( Debug( LDAP_DEBUG_ARGS, "do_modify: dn (%s)\n", dn.bv_val, 0, 0 ); #endif - /* collect modifications & save for later */ - for ( tag = ber_first_element( op->o_ber, &len, &last ); tag != LBER_DEFAULT; tag = ber_next_element( op->o_ber, &len, last ) ) @@ -114,10 +112,10 @@ do_modify( tmp.sml_nvalues = NULL; if ( ber_scanf( op->o_ber, "{i{m[W]}}", &mop, - &tmp.sml_type, &tmp.sml_values ) - == LBER_ERROR ) + &tmp.sml_type, &tmp.sml_values ) == LBER_ERROR ) { - send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding modlist error" ); + send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, + "decoding modlist error" ); rs->sr_err = SLAPD_DISCONNECT; goto cleanup; } @@ -468,8 +466,6 @@ do_modify( */ #ifndef SLAPD_MULTIMASTER if ( !SLAP_SHADOW(op->o_bd) || repl_user ) -#else - if ( LDAP_STAILQ_EMPTY( &op->o_bd->be_syncinfo )) #endif { int update = op->o_bd->be_update_ndn.bv_len; @@ -541,19 +537,20 @@ do_modify( #if defined( LDAP_SLAPI ) } /* modlist != NULL */ - if ( pb != NULL && slapi_int_call_plugins( op->o_bd, SLAPI_PLUGIN_POST_MODIFY_FN, pb ) < 0 ) { + if ( pb != NULL && slapi_int_call_plugins( op->o_bd, + SLAPI_PLUGIN_POST_MODIFY_FN, pb ) < 0 ) + { #ifdef NEW_LOGGING - LDAP_LOG( OPERATION, INFO, "do_modify: modify postoperation plugins " - "failed\n", 0, 0, 0 ); + LDAP_LOG( OPERATION, INFO, + "do_modify: modify postoperation plugins failed\n", 0, 0, 0 ); #else - Debug(LDAP_DEBUG_TRACE, "do_modify: modify postoperation plugins " - "failed.\n", 0, 0, 0); + Debug(LDAP_DEBUG_TRACE, + "do_modify: modify postoperation plugins failed.\n", 0, 0, 0); #endif } #endif /* defined( LDAP_SLAPI ) */ cleanup: - slap_graduate_commit_csn( op ); op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx ); @@ -768,6 +765,64 @@ int slap_mods_check( ml->sml_nvalues[nvals].bv_val = NULL; ml->sml_nvalues[nvals].bv_len = 0; } + + if( nvals ) { + /* check for duplicates */ + int i, j; + MatchingRule *mr = ad->ad_type->sat_equality; + + /* check if the values we're adding already exist */ + if( mr == NULL || !mr->smr_match ) { + for ( i = 1; ml->sml_values[i].bv_val != NULL; i++ ) { + /* test asserted values against themselves */ + for( j = 0; j < i; j++ ) { + if ( bvmatch( &ml->sml_values[i], + &ml->sml_values[j] ) ) + { + /* value exists already */ + snprintf( textbuf, textlen, + "%s: value #%d provided more than once", + ml->sml_desc->ad_cname.bv_val, j ); + *text = textbuf; + return LDAP_TYPE_OR_VALUE_EXISTS; + } + } + } + + } else { + int rc = LDAP_SUCCESS; + int match; + + for ( i = 1; ml->sml_values[i].bv_val != NULL; i++ ) { + /* test asserted values against themselves */ + for( j = 0; j < i; j++ ) { + rc = value_match( &match, ml->sml_desc, mr, + SLAP_MR_EQUALITY + | SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX + | SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH + | SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH, + ml->sml_nvalues + ? &ml->sml_nvalues[i] + : &ml->sml_values[i], + ml->sml_nvalues + ? &ml->sml_nvalues[j] + : &ml->sml_values[j], + text ); + if ( rc == LDAP_SUCCESS && match == 0 ) { + /* value exists already */ + snprintf( textbuf, textlen, + "%s: value #%d provided more than once", + ml->sml_desc->ad_cname.bv_val, j ); + *text = textbuf; + return LDAP_TYPE_OR_VALUE_EXISTS; + } + } + } + + if ( rc != LDAP_SUCCESS ) return rc; + } + } + } } diff --git a/servers/slapd/modrdn.c b/servers/slapd/modrdn.c index ae45b32a7c..9f184ada3c 100644 --- a/servers/slapd/modrdn.c +++ b/servers/slapd/modrdn.c @@ -50,24 +50,24 @@ do_modrdn( SlapReply *rs ) { - struct berval dn = { 0, NULL }; - struct berval newrdn = { 0, NULL }; - struct berval newSuperior = { 0, NULL }; + struct berval dn = BER_BVNULL; + struct berval newrdn = BER_BVNULL; + struct berval newSuperior = BER_BVNULL; ber_int_t deloldrdn; - struct berval pnewSuperior = { 0, NULL }; + struct berval pnewSuperior = BER_BVNULL; - struct berval nnewSuperior = { 0, NULL }; + struct berval nnewSuperior = BER_BVNULL; Backend *newSuperior_be = NULL; ber_len_t length; int manageDSAit; - struct berval pdn = { 0, NULL }; - struct berval org_req_dn = { 0, NULL }; - struct berval org_req_ndn = { 0, NULL }; - struct berval org_dn = { 0, NULL }; - struct berval org_ndn = { 0, NULL }; + struct berval pdn = BER_BVNULL; + struct berval org_req_dn = BER_BVNULL; + struct berval org_req_ndn = BER_BVNULL; + struct berval org_dn = BER_BVNULL; + struct berval org_ndn = BER_BVNULL; int org_managedsait; #ifdef NEW_LOGGING @@ -365,8 +365,6 @@ do_modrdn( int repl_user = be_isupdate( op ); #ifndef SLAPD_MULTIMASTER if ( !SLAP_SHADOW(op->o_bd) || repl_user ) -#else - if ( LDAP_STAILQ_EMPTY( &op->o_bd->be_syncinfo )) #endif { slap_callback cb = { NULL, slap_replog_cb, NULL, NULL }; diff --git a/servers/slapd/mods.c b/servers/slapd/mods.c index c2d74ba4d6..7844d6381e 100644 --- a/servers/slapd/mods.c +++ b/servers/slapd/mods.c @@ -29,22 +29,6 @@ #include "slap.h" -int -modify_check_duplicates( - AttributeDescription *ad, - MatchingRule *mr, - BerVarray vals, - BerVarray mods, - int permissive, - const char **text, - char *textbuf, size_t textlen ) -{ - int i, j, numvals = 0, nummods, - rc = LDAP_SUCCESS, matched; - /* this function is no longer used */ - return rc; -} - int modify_add_values( Entry *e, @@ -53,11 +37,10 @@ modify_add_values( const char **text, char *textbuf, size_t textlen ) { - int i, j; - int matched; - Attribute *a; - MatchingRule *mr = mod->sm_desc->ad_type->sat_equality; + int rc; const char *op; + Attribute *a; + Modification pmod = *mod; switch( mod->sm_op ) { case LDAP_MOD_ADD: @@ -72,16 +55,12 @@ modify_add_values( } a = attr_find( e->e_attrs, mod->sm_desc ); + if( a != NULL ) { /* check if values to add exist in attribute */ + int rc, i, j, p; + MatchingRule *mr; - /* - * With permissive set, as long as the attribute being added - * has the same value(s?) as the existing attribute, then the - * modify will succeed. - */ - - /* check if the values we're adding already exist */ - if( mr == NULL || !mr->smr_match ) { - if ( a != NULL ) { + mr = mod->sm_desc->ad_type->sat_equality; + if( mr == NULL || !mr->smr_match ) { /* do not allow add of additional attribute if no equality rule exists */ *text = textbuf; @@ -91,116 +70,74 @@ modify_add_values( return LDAP_INAPPROPRIATE_MATCHING; } - for ( i = 0; mod->sm_bvalues[i].bv_val != NULL; i++ ) { - /* test asserted values against existing values */ - if( a ) { - for( matched = 0, j = 0; a->a_vals[j].bv_val != NULL; j++ ) { - if ( bvmatch( &mod->sm_bvalues[i], &a->a_vals[j] ) ) { - if ( permissive ) { - matched++; - continue; - } - /* value exists already */ - *text = textbuf; - snprintf( textbuf, textlen, - "modify/%s: %s: value #%i already exists", - op, mod->sm_desc->ad_cname.bv_val, j ); - return LDAP_TYPE_OR_VALUE_EXISTS; - } - } - if ( permissive && matched == j ) { - /* values already exist; do nothing */ - return LDAP_SUCCESS; - } - } - - /* test asserted values against themselves */ - for( j = 0; j < i; j++ ) { - if ( bvmatch( &mod->sm_bvalues[i], &mod->sm_bvalues[j] ) ) { - /* value exists already */ - *text = textbuf; - snprintf( textbuf, textlen, - "modify/%s: %s: value #%i already exists", - op, mod->sm_desc->ad_cname.bv_val, j ); - return LDAP_TYPE_OR_VALUE_EXISTS; - } + if( permissive ) { + for ( i=0; mod->sm_values[i].bv_val; i++ ) /* count 'em */; + pmod.sm_values = (BerVarray) ch_malloc( i*sizeof( struct berval )); + if( pmod.sm_nvalues != NULL ) { + pmod.sm_nvalues = (BerVarray) ch_malloc( + i*sizeof( struct berval )); } } - } else { /* no normalization is done in this routine nor * in the matching routines called by this routine. * values are now normalized once on input to the * server (whether from LDAP or from the underlying * database). - * This should outperform the old code. No numbers - * are available yet. */ - - int rc; - - if ( mod->sm_bvalues[1].bv_val == 0 ) { - if ( a != NULL ) { - int i; - - for ( matched = 0, i = 0; a->a_vals[ i ].bv_val; i++ ) { - int match; - - if( mod->sm_nvalues ) { - rc = value_match( &match, mod->sm_desc, mr, - SLAP_MR_EQUALITY - | SLAP_MR_VALUE_OF_ASSERTION_SYNTAX - | SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH - | SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH, - &a->a_nvals[i], - &mod->sm_nvalues[0], - text ); - - } else { - rc = value_match( &match, mod->sm_desc, mr, - SLAP_MR_EQUALITY - | SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX, - &a->a_vals[i], - &mod->sm_values[0], - text ); - } - - - if( rc == LDAP_SUCCESS && match == 0 ) { - if ( permissive ) { - matched++; - continue; - } - *text = textbuf; - snprintf( textbuf, textlen, - "modify/%s: %s: value #0 already exists", - op, mod->sm_desc->ad_cname.bv_val ); - return LDAP_TYPE_OR_VALUE_EXISTS; - } + for ( p=i=0; mod->sm_values[i].bv_val; i++ ) { + int match; + assert( a->a_vals[0].bv_val ); + for ( j=0; a->a_vals[j].bv_val; j++ ) { + if( mod->sm_nvalues ) { + rc = value_match( &match, mod->sm_desc, mr, + SLAP_MR_EQUALITY | SLAP_MR_VALUE_OF_ASSERTION_SYNTAX + | SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH + | SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH, + &a->a_nvals[j], &mod->sm_nvalues[i], text ); + } else { + rc = value_match( &match, mod->sm_desc, mr, + SLAP_MR_EQUALITY | SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX, + &a->a_vals[j], &mod->sm_values[i], text ); } - if ( permissive && matched == i ) { - /* values already exist; do nothing */ - return LDAP_SUCCESS; - } - } - } else { - rc = modify_check_duplicates( mod->sm_desc, mr, - a ? a->a_vals : NULL, mod->sm_bvalues, - permissive, text, textbuf, textlen ); + if( rc == LDAP_SUCCESS && match == 0 ) { + if( permissive ) break; - if ( permissive && rc == LDAP_TYPE_OR_VALUE_EXISTS ) { - return LDAP_SUCCESS; + /* value already exists */ + *text = textbuf; + snprintf( textbuf, textlen, + "modify/%s: %s: value #%d already exists", + op, mod->sm_desc->ad_cname.bv_val, i ); + return LDAP_TYPE_OR_VALUE_EXISTS; + } } - if ( rc != LDAP_SUCCESS ) { - return rc; + if( permissive && !match ) { + if( pmod.sm_nvalues ) { + pmod.sm_nvalues[p] = mod->sm_nvalues[i]; + } + pmod.sm_values[p++] = mod->sm_values[i]; } } + + if( permissive && p == 0 ) { + /* all new values match exist */ + ch_free( pmod.sm_values ); + if( pmod.sm_nvalues ) ch_free( pmod.sm_nvalues ); + return LDAP_SUCCESS; + } } /* no - add them */ - if( attr_merge( e, mod->sm_desc, mod->sm_values, mod->sm_nvalues ) != 0 ) { + rc = attr_merge( e, mod->sm_desc, pmod.sm_values, pmod.sm_nvalues ); + + if( a != NULL && permissive ) { + ch_free( pmod.sm_values ); + if( pmod.sm_nvalues ) ch_free( pmod.sm_nvalues ); + } + + if( rc != 0 ) { /* this should return result of attr_merge */ *text = textbuf; snprintf( textbuf, textlen, @@ -218,8 +155,7 @@ modify_delete_values( Modification *mod, int permissive, const char **text, - char *textbuf, size_t textlen -) + char *textbuf, size_t textlen ) { int i, j, k, rc = LDAP_SUCCESS; Attribute *a; @@ -233,7 +169,7 @@ modify_delete_values( */ /* delete the entire attribute */ - if ( mod->sm_bvalues == NULL ) { + if ( mod->sm_values == NULL ) { rc = attr_delete( &e->e_attrs, mod->sm_desc ); if( permissive ) { @@ -270,7 +206,6 @@ modify_delete_values( return LDAP_NO_SUCH_ATTRIBUTE; } - for ( i = 0; mod->sm_values[i].bv_val != NULL; i++ ) { int found = 0; for ( j = 0; a->a_vals[j].bv_val != NULL; j++ ) { @@ -380,7 +315,7 @@ modify_replace_values( { (void) attr_delete( &e->e_attrs, mod->sm_desc ); - if ( mod->sm_bvalues ) { + if ( mod->sm_values ) { return modify_add_values( e, mod, permissive, text, textbuf, textlen ); } @@ -406,11 +341,10 @@ modify_increment_values( return LDAP_NO_SUCH_ATTRIBUTE; } - if ( !strcmp( a->a_desc->ad_type->sat_syntax_oid, SLAPD_INTEGER_SYNTAX )) { int i; char str[sizeof(long)*3 + 2]; /* overly long */ - long incr = atol( mod->sm_bvalues[0].bv_val ); + long incr = atol( mod->sm_values[0].bv_val ); /* treat zero and errors as a no-op */ if( incr == 0 ) { diff --git a/servers/slapd/overlays/pcache.c b/servers/slapd/overlays/pcache.c index ff1964b7fc..0a7bd86190 100644 --- a/servers/slapd/overlays/pcache.c +++ b/servers/slapd/overlays/pcache.c @@ -205,7 +205,7 @@ static int base_scope_compare( int scope_stored, int scope_incoming ) { - struct berval pdn_incoming = { 0, NULL }; + struct berval pdn_incoming = BER_BVNULL; if (scope_stored < scope_incoming) return 0; @@ -869,8 +869,8 @@ remove_query_data ( op->o_req_ndn = op->o_bd->be_nsuffix[0]; op->ors_scope = LDAP_SCOPE_SUBTREE; op->ors_deref = LDAP_DEREF_NEVER; - op->ors_slimit = 0; - op->ors_tlimit = 0; + op->ors_slimit = -1; + op->ors_tlimit = -1; op->ors_filter = &filter; op->ors_filterstr.bv_val = filter_str; op->ors_filterstr.bv_len = strlen(filter_str); @@ -910,7 +910,7 @@ remove_query_data ( mod.sml_op = LDAP_MOD_DELETE; mod.sml_desc = ad_queryid; mod.sml_type = ad_queryid->ad_cname; - mod.sml_bvalues = vals; + mod.sml_values = vals; mod.sml_next = NULL; #ifdef NEW_LOGGING LDAP_LOG( BACK_META, DETAIL1, diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index d1c05ebc7a..0400c5282a 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -225,7 +225,10 @@ LDAP_SLAPD_F (int) be_issuffix LDAP_P(( Backend *be, LDAP_SLAPD_F (int) be_isroot LDAP_P(( Operation *op )); LDAP_SLAPD_F (int) be_isroot_dn LDAP_P(( Backend *be, struct berval *ndn )); LDAP_SLAPD_F (int) be_isroot_pw LDAP_P(( Operation *op )); -LDAP_SLAPD_F (int) be_isupdate LDAP_P(( Operation *op )); +LDAP_SLAPD_F (int) be_sync_update LDAP_P(( Operation *op )); +LDAP_SLAPD_F (int) be_slurp_update LDAP_P(( Operation *op )); +#define be_isupdate( op ) be_slurp_update( (op) ) +LDAP_SLAPD_F (int) be_shadow_update LDAP_P(( Operation *op )); LDAP_SLAPD_F (int) be_isupdate_dn LDAP_P(( Backend *be, struct berval *ndn )); LDAP_SLAPD_F (struct berval *) be_root_dn LDAP_P(( Backend *be )); LDAP_SLAPD_F (int) be_entry_get_rw LDAP_P(( struct slap_op *o, @@ -688,10 +691,6 @@ LDAP_SLAPD_F( int ) slap_mods_opattrs( /* * mods.c */ -LDAP_SLAPD_F( int ) modify_check_duplicates( - AttributeDescription *ad, MatchingRule *mr, - BerVarray vals, BerVarray mods, int permissive, - const char **text, char *textbuf, size_t textlen ); LDAP_SLAPD_F( int ) modify_add_values( Entry *e, Modification *mod, int permissive, @@ -1136,6 +1135,8 @@ LDAP_SLAPD_F (Entry*) slap_create_syncrepl_entry LDAP_P(( struct berval *, struct berval * )); LDAP_SLAPD_F (struct berval *) slap_uuidstr_from_normalized LDAP_P(( struct berval *, struct berval *, void * )); +LDAP_SLAPD_F (int) syncrepl_isupdate LDAP_P(( Operation * )); +LDAP_SLAPD_F (int) syncrepl_isupdate_dn LDAP_P(( Backend *, struct berval * )); /* syntax.c */ LDAP_SLAPD_F (Syntax *) syn_find LDAP_P(( diff --git a/servers/slapd/result.c b/servers/slapd/result.c index ad555812ac..f591b5e6c2 100644 --- a/servers/slapd/result.c +++ b/servers/slapd/result.c @@ -538,8 +538,9 @@ send_ldap_disconnect( Operation *op, SlapReply *rs ) if ( send_ldap_response( op, rs ) == SLAP_CB_CONTINUE ) { Statslog( LDAP_DEBUG_STATS, - "conn=%lu op=%lu DISCONNECT tag=%lu err=%d text=%s\n", - op->o_connid, op->o_opid, rs->sr_tag, rs->sr_err, rs->sr_text ? rs->sr_text : "" ); + "conn=%lu op=%lu DISCONNECT tag=%lu err=%d text=%s\n", + op->o_connid, op->o_opid, rs->sr_tag, rs->sr_err, + rs->sr_text ? rs->sr_text : "" ); } } @@ -556,7 +557,7 @@ slap_send_ldap_result( Operation *op, SlapReply *rs ) #ifdef NEW_LOGGING LDAP_LOG( OPERATION, ENTRY, - "send_ldap_result: conn %lu op=%lu p=%d\n", + "send_ldap_result: conn=%lu op=%lu p=%d\n", op->o_connid, op->o_opid, op->o_protocol ); #else Debug( LDAP_DEBUG_TRACE, diff --git a/servers/slapd/sasl.c b/servers/slapd/sasl.c index cffc17423c..0599628d7d 100644 --- a/servers/slapd/sasl.c +++ b/servers/slapd/sasl.c @@ -318,7 +318,7 @@ slap_sasl_log( #if SASL_VERSION_MAJOR >= 2 static const char *slap_propnames[] = { - "*slapConn", "*authcDN", "*authzDN", NULL }; + "*slapConn", "*slapAuthcDN", "*slapAuthzDN", NULL }; static Filter generic_filter = { LDAP_FILTER_PRESENT }; static struct berval generic_filterstr = BER_BVC("(objectclass=*)"); @@ -326,9 +326,9 @@ static struct berval generic_filterstr = BER_BVC("(objectclass=*)"); #define PROP_CONN 0 #define PROP_AUTHC 1 #define PROP_AUTHZ 2 +#define PROP_COUNT 3 /* Number of properties we used */ typedef struct lookup_info { - int last; int flags; const struct propval *list; sasl_server_params_t *sparams; @@ -349,11 +349,16 @@ sasl_ap_lookup( Operation *op, SlapReply *rs ) if (rs->sr_type != REP_SEARCH) return 0; - for( i = 0; i < sl->last; i++ ) { + for( i = 0; sl->list[i].name; i++ ) { const char *name = sl->list[i].name; if ( name[0] == '*' ) { if ( sl->flags & SASL_AUXPROP_AUTHZID ) continue; + /* Skip our private properties */ + if ( !strcmp( name, slap_propnames[0] )) { + i += PROP_COUNT-1; + continue; + } name++; } else if ( !(sl->flags & SASL_AUXPROP_AUTHZID ) ) continue; @@ -408,23 +413,21 @@ slap_auxprop_lookup( sl.flags = flags; /* Find our DN and conn first */ - for( i = 0, sl.last = 0; sl.list[i].name; i++ ) { + for( i = 0; sl.list[i].name; i++ ) { if ( sl.list[i].name[0] == '*' ) { if ( !strcmp( sl.list[i].name, slap_propnames[PROP_CONN] ) ) { if ( sl.list[i].values && sl.list[i].values[0] ) AC_MEMCPY( &conn, sl.list[i].values[0], sizeof( conn ) ); - if ( !sl.last ) sl.last = i; + continue; } if ( (flags & SASL_AUXPROP_AUTHZID) && !strcmp( sl.list[i].name, slap_propnames[PROP_AUTHZ] ) ) { if ( sl.list[i].values && sl.list[i].values[0] ) AC_MEMCPY( &op.o_req_ndn, sl.list[i].values[0], sizeof( struct berval ) ); - if ( !sl.last ) sl.last = i; break; } if ( !strcmp( sl.list[i].name, slap_propnames[PROP_AUTHC] ) ) { - if ( !sl.last ) sl.last = i; if ( sl.list[i].values && sl.list[i].values[0] ) { AC_MEMCPY( &op.o_req_ndn, sl.list[i].values[0], sizeof( struct berval ) ); if ( !(flags & SASL_AUXPROP_AUTHZID) ) @@ -435,11 +438,16 @@ slap_auxprop_lookup( } /* Now see what else needs to be fetched */ - for( i = 0; i < sl.last; i++ ) { + for( i = 0; sl.list[i].name; i++ ) { const char *name = sl.list[i].name; if ( name[0] == '*' ) { if ( flags & SASL_AUXPROP_AUTHZID ) continue; + /* Skip our private properties */ + if ( !strcmp( name, slap_propnames[0] )) { + i += PROP_COUNT-1; + continue; + } name++; } else if ( !(flags & SASL_AUXPROP_AUTHZID ) ) continue; @@ -448,6 +456,7 @@ slap_auxprop_lookup( if ( !(flags & SASL_AUXPROP_OVERRIDE) ) continue; } doit = 1; + break; } if (doit) { @@ -1615,9 +1624,9 @@ char* slap_sasl_secprops( const char *in ) int slap_sasl_setpass( Operation *op, SlapReply *rs ) { - struct berval id = { 0, NULL }; /* needs to come from connection */ - struct berval new = { 0, NULL }; - struct berval old = { 0, NULL }; + struct berval id = BER_BVNULL; /* needs to come from connection */ + struct berval new = BER_BVNULL; + struct berval old = BER_BVNULL; assert( ber_bvcmp( &slap_EXOP_MODIFY_PASSWD, &op->ore_reqoid ) == 0 ); @@ -1783,7 +1792,7 @@ int slap_sasl_getdn( Connection *conn, Operation *op, char *id, int len, /* Username strings */ if( is_dn == SET_U ) { char *p; - struct berval realm = { 0, NULL }, c1 = *dn; + struct berval realm = BER_BVNULL, c1 = *dn; len = dn->bv_len + sizeof("uid=")-1 + sizeof(",cn=auth")-1; diff --git a/servers/slapd/saslauthz.c b/servers/slapd/saslauthz.c index 48ab0e9004..6aed39bb43 100644 --- a/servers/slapd/saslauthz.c +++ b/servers/slapd/saslauthz.c @@ -276,9 +276,9 @@ is_dn: bv.bv_len = uri->bv_len - (bv.bv_val - uri->bv_val); Connection c = *op->o_conn; char buf[ SLAP_LDAPDN_MAXLEN ]; struct berval id, - user = { 0, NULL }, - realm = { 0, NULL }, - mech = { 0, NULL }; + user = BER_BVNULL, + realm = BER_BVNULL, + mech = BER_BVNULL; if ( sizeof( buf ) <= uri->bv_len ) { return LDAP_INVALID_SYNTAX; @@ -750,6 +750,8 @@ exact_match: op.o_conn = opx->o_conn; op.o_connid = opx->o_connid; op.o_req_dn = op.o_req_ndn; + op.oq_search.rs_slimit = 1; + op.oq_search.rs_tlimit = -1; op.o_bd->be_search( &op, &rs ); @@ -849,7 +851,7 @@ void slap_sasl2dn( Operation *opx, slap_callback cb = { NULL, sasl_sc_sasl2dn, NULL, NULL }; Operation op = {0}; SlapReply rs = {REP_RESULT}; - struct berval regout = { 0, NULL }; + struct berval regout = BER_BVNULL; #ifdef NEW_LOGGING LDAP_LOG( TRANSPORT, ENTRY, @@ -941,6 +943,7 @@ void slap_sasl2dn( Operation *opx, #endif op.oq_search.rs_deref = LDAP_DEREF_NEVER; op.oq_search.rs_slimit = 1; + op.oq_search.rs_tlimit = -1; op.oq_search.rs_attrsonly = 1; op.o_req_dn = op.o_req_ndn; diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index d7832fcd53..bd4f74b92a 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -1034,7 +1034,6 @@ typedef struct slap_mod { AttributeDescription *sm_desc; struct berval sm_type; BerVarray sm_values; -#define sm_bvalues sm_values BerVarray sm_nvalues; } Modification; @@ -1043,7 +1042,6 @@ typedef struct slap_mod_list { #define sml_op sml_mod.sm_op #define sml_desc sml_mod.sm_desc #define sml_type sml_mod.sm_type -#define sml_bvalues sml_mod.sm_values #define sml_values sml_mod.sm_values #define sml_nvalues sml_mod.sm_nvalues struct slap_mod_list *sml_next; @@ -1055,7 +1053,6 @@ typedef struct slap_ldap_modlist { #define ml_op ml_mod.mod_op #define ml_type ml_mod.mod_type #define ml_values ml_mod.mod_values -#define ml_bvalues ml_mod.mod_values } LDAPModList; /* @@ -1287,6 +1284,7 @@ struct slap_limits_set { int lms_s_unchecked; int lms_s_pr; int lms_s_pr_hide; + int lms_s_pr_total; }; struct slap_limits { @@ -1452,9 +1450,11 @@ struct slap_backend_db { #define SLAP_DBFLAG_NOLASTMOD 0x0001U #define SLAP_DBFLAG_NO_SCHEMA_CHECK 0x0002U #define SLAP_DBFLAG_GLUE_INSTANCE 0x0010U /* a glue backend */ -#define SLAP_DBFLAG_GLUE_SUBORDINATE 0x0020U /* child of a glue hierarchy */ +#define SLAP_DBFLAG_GLUE_SUBORDINATE 0x0020U /* child of a glue hierarchy */ #define SLAP_DBFLAG_GLUE_LINKED 0x0040U /* child is connected to parent */ -#define SLAP_DBFLAG_SHADOW 0x8000U /* a shadow */ +#define SLAP_DBFLAG_SHADOW 0x8000U /* a shadow */ +#define SLAP_DBFLAG_SYNC_SHADOW 0x1000U /* a sync shadow */ +#define SLAP_DBFLAG_SLURP_SHADOW 0x2000U /* a slurp shadow */ slap_mask_t be_flags; #define SLAP_DBFLAGS(be) ((be)->be_flags) #define SLAP_NOLASTMOD(be) (SLAP_DBFLAGS(be) & SLAP_DBFLAG_NOLASTMOD) @@ -1468,6 +1468,8 @@ struct slap_backend_db { #define SLAP_GLUE_LINKED(be) \ (SLAP_DBFLAGS(be) & SLAP_DBFLAG_GLUE_LINKED) #define SLAP_SHADOW(be) (SLAP_DBFLAGS(be) & SLAP_DBFLAG_SHADOW) +#define SLAP_SYNC_SHADOW(be) (SLAP_DBFLAGS(be) & SLAP_DBFLAG_SYNC_SHADOW) +#define SLAP_SLURP_SHADOW(be) (SLAP_DBFLAGS(be) & SLAP_DBFLAG_SLURP_SHADOW) slap_mask_t be_restrictops; /* restriction operations */ #define SLAP_RESTRICT_OP_ADD 0x0001U @@ -1892,6 +1894,7 @@ typedef struct slap_paged_state { Backend *ps_be; PagedResultsCookie ps_cookie; ID ps_id; + int ps_count; } PagedResultsState; #define LDAP_PSEARCH_BY_ADD 0x01 diff --git a/servers/slapd/slapi/slapi_ops.c b/servers/slapd/slapi/slapi_ops.c index 5d0c93675b..415e80fb13 100644 --- a/servers/slapd/slapi/slapi_ops.c +++ b/servers/slapd/slapi/slapi_ops.c @@ -342,7 +342,7 @@ slapi_int_ldapmod_to_entry( char *ldn, LDAPMod **mods ) { - struct berval dn = { 0, NULL }; + struct berval dn = BER_BVNULL; Entry *pEntry=NULL; LDAPMod *pMod; struct berval *bv; @@ -392,11 +392,11 @@ slapi_int_ldapmod_to_entry( * being passed in may not have been allocated on the * heap. */ - rc = bvptr2obj_copy( pMod->mod_bvalues, &bv ); + rc = bvptr2obj_copy( pMod->mod_values, &bv ); if ( rc != LDAP_SUCCESS ) goto cleanup; tmp.sml_type.bv_val = pMod->mod_type; tmp.sml_type.bv_len = strlen( pMod->mod_type ); - tmp.sml_bvalues = bv; + tmp.sml_values = bv; tmp.sml_nvalues = NULL; mod = (Modifications *) ch_malloc( sizeof(Modifications) ); @@ -405,7 +405,7 @@ slapi_int_ldapmod_to_entry( mod->sml_next = NULL; mod->sml_desc = NULL; mod->sml_type = tmp.sml_type; - mod->sml_bvalues = tmp.sml_bvalues; + mod->sml_values = tmp.sml_values; mod->sml_nvalues = tmp.sml_nvalues; *modtail = mod; @@ -421,7 +421,7 @@ slapi_int_ldapmod_to_entry( if ( rc != LDAP_SUCCESS ) goto cleanup; tmp.sml_type.bv_val = pMod->mod_type; tmp.sml_type.bv_len = strlen( pMod->mod_type ); - tmp.sml_bvalues = bv; + tmp.sml_values = bv; tmp.sml_nvalues = NULL; mod = (Modifications *) ch_malloc( sizeof(Modifications) ); @@ -430,7 +430,7 @@ slapi_int_ldapmod_to_entry( mod->sml_next = NULL; mod->sml_desc = NULL; mod->sml_type = tmp.sml_type; - mod->sml_bvalues = tmp.sml_bvalues; + mod->sml_values = tmp.sml_values; mod->sml_nvalues = tmp.sml_nvalues; *modtail = mod; @@ -516,7 +516,7 @@ slapi_delete_internal( Slapi_PBlock *pPB = NULL; Slapi_PBlock *pSavePB = NULL; SlapReply rs = { REP_RESULT }; - struct berval dn = { 0, NULL }; + struct berval dn = BER_BVNULL; int manageDsaIt = 0; int isCritical; @@ -763,8 +763,8 @@ slapi_modrdn_internal( int log_change ) { #ifdef LDAP_SLAPI - struct berval dn = { 0, NULL }; - struct berval newrdn = { 0, NULL }; + struct berval dn = BER_BVNULL; + struct berval newrdn = BER_BVNULL; Connection *pConn = NULL; Operation *op = NULL; Slapi_PBlock *pPB = NULL; @@ -893,7 +893,7 @@ slapi_modify_internal( Slapi_PBlock *pPB = NULL; Slapi_PBlock *pSavePB = NULL; - struct berval dn = { 0, NULL }; + struct berval dn = BER_BVNULL; int manageDsaIt = 0; int isCritical; @@ -954,12 +954,12 @@ slapi_modify_internal( * convert an array of pointers to bervals * to an array of bervals */ - rs.sr_err = bvptr2obj_copy( pMod->mod_bvalues, &bv ); + rs.sr_err = bvptr2obj_copy( pMod->mod_values, &bv ); if ( rs.sr_err != LDAP_SUCCESS ) goto cleanup; tmp.sml_type.bv_val = pMod->mod_type; tmp.sml_type.bv_len = strlen( pMod->mod_type ); - tmp.sml_bvalues = bv; + tmp.sml_values = bv; tmp.sml_nvalues = NULL; mod = (Modifications *)ch_malloc( sizeof(Modifications) ); @@ -968,7 +968,7 @@ slapi_modify_internal( mod->sml_next = NULL; mod->sml_desc = NULL; mod->sml_type = tmp.sml_type; - mod->sml_bvalues = tmp.sml_bvalues; + mod->sml_values = tmp.sml_values; mod->sml_nvalues = tmp.sml_nvalues; } else { rs.sr_err = values2obj_copy( pMod->mod_values, &bv ); @@ -976,7 +976,7 @@ slapi_modify_internal( goto cleanup; tmp.sml_type.bv_val = pMod->mod_type; tmp.sml_type.bv_len = strlen( pMod->mod_type ); - tmp.sml_bvalues = bv; + tmp.sml_values = bv; tmp.sml_nvalues = NULL; mod = (Modifications *) ch_malloc( sizeof(Modifications) ); @@ -985,7 +985,7 @@ slapi_modify_internal( mod->sml_next = NULL; mod->sml_desc = NULL; mod->sml_type = tmp.sml_type; - mod->sml_bvalues = tmp.sml_bvalues; + mod->sml_values = tmp.sml_values; mod->sml_nvalues = tmp.sml_nvalues; } *modtail = mod; @@ -993,7 +993,7 @@ slapi_modify_internal( switch( pMod->mod_op & LDAP_MOD_OP ) { case LDAP_MOD_ADD: - if ( mod->sml_bvalues == NULL ) { + if ( mod->sml_values == NULL ) { rs.sr_err = LDAP_PROTOCOL_ERROR; goto cleanup; } @@ -1088,9 +1088,9 @@ slapi_search_internal( Operation *op = NULL; Slapi_PBlock *ptr = NULL; Slapi_PBlock *pSavePB = NULL; - struct berval dn = { 0, NULL }; + struct berval dn = BER_BVNULL; Filter *filter=NULL; - struct berval fstr = { 0, NULL }; + struct berval fstr = BER_BVNULL; AttributeName *an = NULL; const char *text = NULL; diff --git a/servers/slapd/slapi/slapi_utils.c b/servers/slapd/slapi/slapi_utils.c index e95c107795..d9ceeb43db 100644 --- a/servers/slapd/slapi/slapi_utils.c +++ b/servers/slapd/slapi/slapi_utils.c @@ -171,7 +171,7 @@ slapi_entry_set_dn( char *ldn ) { #ifdef LDAP_SLAPI - struct berval dn = { 0, NULL }; + struct berval dn = BER_BVNULL; dn.bv_val = ldn; dn.bv_len = strlen( ldn ); @@ -558,12 +558,12 @@ slapi_entry_add_values( Slapi_Entry *e, const char *type, struct berval **vals ) if ( vals == NULL ) { /* Apparently vals can be NULL - * FIXME: sm_bvalues = NULL ? */ - mod.sm_bvalues = (BerVarray)ch_malloc( sizeof(struct berval) ); - mod.sm_bvalues->bv_val = NULL; + * FIXME: sm_values = NULL ? */ + mod.sm_values = (BerVarray)ch_malloc( sizeof(struct berval) ); + mod.sm_values->bv_val = NULL; } else { - rc = bvptr2obj( vals, &mod.sm_bvalues ); + rc = bvptr2obj( vals, &mod.sm_values ); if ( rc != LDAP_SUCCESS ) { return LDAP_CONSTRAINT_VIOLATION; } @@ -572,7 +572,7 @@ slapi_entry_add_values( Slapi_Entry *e, const char *type, struct berval **vals ) rc = modify_add_values( e, &mod, 0, &text, textbuf, sizeof(textbuf) ); - ch_free( mod.sm_bvalues ); + ch_free( mod.sm_values ); return (rc == LDAP_SUCCESS) ? LDAP_SUCCESS : LDAP_CONSTRAINT_VIOLATION; #else @@ -638,7 +638,7 @@ slapi_entry_delete_values( Slapi_Entry *e, const char *type, struct berval **val return attr_delete( &e->e_attrs, mod.sm_desc ) ? LDAP_OTHER : LDAP_SUCCESS; } - rc = bvptr2obj( vals, &mod.sm_bvalues ); + rc = bvptr2obj( vals, &mod.sm_values ); if ( rc != LDAP_SUCCESS ) { return LDAP_CONSTRAINT_VIOLATION; } @@ -646,7 +646,7 @@ slapi_entry_delete_values( Slapi_Entry *e, const char *type, struct berval **val rc = modify_delete_values( e, &mod, 0, &text, textbuf, sizeof(textbuf) ); - ch_free( mod.sm_bvalues ); + ch_free( mod.sm_values ); return rc; #else @@ -3336,7 +3336,7 @@ int slapi_acl_check_mods(Slapi_PBlock *pb, Slapi_Entry *e, LDAPMod **mods, char mp = ml->sml_next; /* just free the containing array */ - slapi_ch_free( (void **)&ml->sml_bvalues ); + slapi_ch_free( (void **)&ml->sml_values ); slapi_ch_free( (void **)&ml ); } @@ -3377,18 +3377,18 @@ LDAPMod **slapi_int_modifications2ldapmods(Modifications **pmodlist) modp->mod_type = ml->sml_type.bv_val; ml->sml_type.bv_val = NULL; - if ( ml->sml_bvalues != NULL ) { - for( j = 0; ml->sml_bvalues[j].bv_val != NULL; j++ ) + if ( ml->sml_values != NULL ) { + for( j = 0; ml->sml_values[j].bv_val != NULL; j++ ) ; modp->mod_bvalues = (struct berval **)ch_malloc( (j + 1) * sizeof(struct berval *) ); - for( j = 0; ml->sml_bvalues[j].bv_val != NULL; j++ ) { + for( j = 0; ml->sml_values[j].bv_val != NULL; j++ ) { /* Take ownership of original values. */ modp->mod_bvalues[j] = (struct berval *)ch_malloc( sizeof(struct berval) ); - modp->mod_bvalues[j]->bv_len = ml->sml_bvalues[j].bv_len; - modp->mod_bvalues[j]->bv_val = ml->sml_bvalues[j].bv_val; - ml->sml_bvalues[j].bv_len = 0; - ml->sml_bvalues[j].bv_val = NULL; + modp->mod_bvalues[j]->bv_len = ml->sml_values[j].bv_len; + modp->mod_bvalues[j]->bv_val = ml->sml_values[j].bv_val; + ml->sml_values[j].bv_len = 0; + ml->sml_values[j].bv_val = NULL; } modp->mod_bvalues[j] = NULL; } else { @@ -3446,24 +3446,24 @@ Modifications *slapi_int_ldapmods2modifications (LDAPMod **mods) } if ( i == 0 ) { - mod->sml_bvalues = NULL; + mod->sml_values = NULL; } else { - mod->sml_bvalues = (BerVarray) ch_malloc( (i + 1) * sizeof(struct berval) ); + mod->sml_values = (BerVarray) ch_malloc( (i + 1) * sizeof(struct berval) ); /* NB: This implicitly trusts a plugin to return valid modifications. */ if ( (*modp)->mod_op & LDAP_MOD_BVALUES ) { for( i = 0, bvp = (*modp)->mod_bvalues; bvp != NULL && *bvp != NULL; bvp++, i++ ) { - mod->sml_bvalues[i].bv_val = (*bvp)->bv_val; - mod->sml_bvalues[i].bv_len = (*bvp)->bv_len; + mod->sml_values[i].bv_val = (*bvp)->bv_val; + mod->sml_values[i].bv_len = (*bvp)->bv_len; } } else { for( i = 0, p = (*modp)->mod_values; p != NULL && *p != NULL; p++, i++ ) { - mod->sml_bvalues[i].bv_val = *p; - mod->sml_bvalues[i].bv_len = strlen( *p ); + mod->sml_values[i].bv_val = *p; + mod->sml_values[i].bv_len = strlen( *p ); } } - mod->sml_bvalues[i].bv_val = NULL; - mod->sml_bvalues[i].bv_len = 0; + mod->sml_values[i].bv_val = NULL; + mod->sml_values[i].bv_len = 0; } mod->sml_nvalues = NULL; @@ -3497,10 +3497,10 @@ void slapi_int_free_ldapmods (LDAPMod **mods) * Modification list. Do free the containing array. */ if ( mods[i]->mod_op & LDAP_MOD_BVALUES ) { - for ( j = 0; mods[i]->mod_bvalues != NULL && mods[i]->mod_bvalues[j] != NULL; j++ ) { - ch_free( mods[i]->mod_bvalues[j] ); + for ( j = 0; mods[i]->mod_values != NULL && mods[i]->mod_values[j] != NULL; j++ ) { + ch_free( mods[i]->mod_values[j] ); } - ch_free( mods[i]->mod_bvalues ); + ch_free( mods[i]->mod_values ); } else { ch_free( mods[i]->mod_values ); } diff --git a/servers/slapd/syncrepl.c b/servers/slapd/syncrepl.c index 88da2c36d2..244a7a5031 100644 --- a/servers/slapd/syncrepl.c +++ b/servers/slapd/syncrepl.c @@ -343,7 +343,7 @@ do_syncrep1( sc = NULL; } else { /* stored cookie */ - struct berval newcookie = { 0, NULL }; + struct berval newcookie = BER_BVNULL; ber_dupbv( &cookie_bv, &cookie[0] ); ber_bvarray_add( &si->si_syncCookie.octet_str, &cookie_bv ); slap_parse_sync_cookie( &si->si_syncCookie ); @@ -434,10 +434,10 @@ do_syncrep2( Entry *entry = NULL; int syncstate; - struct berval syncUUID = { 0, NULL }; + struct berval syncUUID = BER_BVNULL; struct sync_cookie syncCookie = { NULL, -1, NULL }; struct sync_cookie syncCookie_req = { NULL, -1, NULL }; - struct berval cookie = { 0, NULL }; + struct berval cookie = BER_BVNULL; int rc, err, i; ber_len_t len; @@ -977,7 +977,7 @@ syncrepl_message_to_entry( mod->sml_next = NULL; mod->sml_desc = NULL; mod->sml_type = tmp.sml_type; - mod->sml_bvalues = tmp.sml_bvalues; + mod->sml_values = tmp.sml_values; mod->sml_nvalues = NULL; *modtail = mod; @@ -1042,8 +1042,8 @@ syncrepl_entry( Backend *be = op->o_bd; slap_callback cb = { NULL }; struct berval *syncuuid_bv = NULL; - struct berval syncUUID_strrep = { 0, NULL }; - struct berval uuid_bv = { 0, NULL }; + struct berval syncUUID_strrep = BER_BVNULL; + struct berval uuid_bv = BER_BVNULL; SlapReply rs = {REP_RESULT}; Filter f = {0}; @@ -1052,11 +1052,11 @@ syncrepl_entry( int ret = LDAP_SUCCESS; const char *text; - struct berval pdn = { 0, NULL }; - struct berval org_req_dn = { 0, NULL }; - struct berval org_req_ndn = { 0, NULL }; - struct berval org_dn = { 0, NULL }; - struct berval org_ndn = { 0, NULL }; + struct berval pdn = BER_BVNULL; + struct berval org_req_dn = BER_BVNULL; + struct berval org_req_ndn = BER_BVNULL; + struct berval org_dn = BER_BVNULL; + struct berval org_ndn = BER_BVNULL; int org_managedsait; if (( syncstate == LDAP_SYNC_PRESENT || syncstate == LDAP_SYNC_ADD )) @@ -1197,7 +1197,7 @@ syncrepl_entry( mod->sml_op = LDAP_MOD_REPLACE; mod->sml_desc = slap_schema.si_ad_entryUUID; mod->sml_type = mod->sml_desc->ad_cname; - ber_bvarray_add( &mod->sml_bvalues, &uuid_bv ); + ber_bvarray_add( &mod->sml_values, &uuid_bv ); modtail->sml_next = mod; op->o_tag = LDAP_REQ_MODIFY; @@ -1305,11 +1305,11 @@ syncrepl_del_nonpresent( Modifications **modtail = &modlist; Attribute *attr; - struct berval pdn = { 0, NULL }; - struct berval org_req_dn = { 0, NULL }; - struct berval org_req_ndn = { 0, NULL }; - struct berval org_dn = { 0, NULL }; - struct berval org_ndn = { 0, NULL }; + struct berval pdn = BER_BVNULL; + struct berval org_req_dn = BER_BVNULL; + struct berval org_req_ndn = BER_BVNULL; + struct berval org_dn = BER_BVNULL; + struct berval org_ndn = BER_BVNULL; int org_managedsait; op->o_req_dn = si->si_base; @@ -1360,7 +1360,7 @@ syncrepl_del_nonpresent( mod->sml_op = LDAP_MOD_REPLACE; mod->sml_desc = slap_schema.si_ad_objectClass; mod->sml_type = mod->sml_desc->ad_cname; - mod->sml_bvalues = &gcbva[0]; + mod->sml_values = &gcbva[0]; *modtail = mod; modtail = &mod->sml_next; @@ -1368,7 +1368,7 @@ syncrepl_del_nonpresent( mod->sml_op = LDAP_MOD_REPLACE; mod->sml_desc = slap_schema.si_ad_structuralObjectClass; mod->sml_type = mod->sml_desc->ad_cname; - mod->sml_bvalues = &gcbva[1]; + mod->sml_values = &gcbva[1]; *modtail = mod; modtail = &mod->sml_next; @@ -1615,7 +1615,7 @@ syncrepl_updateCookie( mod->sml_op = LDAP_MOD_REPLACE; mod->sml_desc = slap_schema.si_ad_objectClass; mod->sml_type = mod->sml_desc->ad_cname; - mod->sml_bvalues = ocbva; + mod->sml_values = ocbva; *modtail = mod; modtail = &mod->sml_next; @@ -1628,7 +1628,7 @@ syncrepl_updateCookie( mod->sml_op = LDAP_MOD_REPLACE; mod->sml_desc = slap_schema.si_ad_cn; mod->sml_type = mod->sml_desc->ad_cname; - mod->sml_bvalues = cnbva; + mod->sml_values = cnbva; *modtail = mod; modtail = &mod->sml_next; @@ -1638,7 +1638,7 @@ syncrepl_updateCookie( mod->sml_op = LDAP_MOD_REPLACE; mod->sml_desc = slap_schema.si_ad_syncreplCookie; mod->sml_type = mod->sml_desc->ad_cname; - mod->sml_bvalues = scbva; + mod->sml_values = scbva; *modtail = mod; modtail = &mod->sml_next; @@ -1646,7 +1646,7 @@ syncrepl_updateCookie( mod->sml_op = LDAP_MOD_REPLACE; mod->sml_desc = slap_schema.si_ad_subtreeSpecification; mod->sml_type = mod->sml_desc->ad_cname; - mod->sml_bvalues = ssbva; + mod->sml_values = ssbva; *modtail = mod; modtail = &mod->sml_next; @@ -1788,6 +1788,31 @@ done : return; } +int +syncrepl_isupdate( Operation *op ) +{ + return ( syncrepl_isupdate_dn( op->o_bd, &op->o_ndn )); +} + +int +syncrepl_isupdate_dn( + Backend* be, + struct berval* ndn +) +{ + syncinfo_t* si; + int ret = 0; + + if ( !LDAP_STAILQ_EMPTY( &be->be_syncinfo )) { + LDAP_STAILQ_FOREACH( si, &be->be_syncinfo, si_next ) { + if ( ret = dn_match( &si->si_updatedn, ndn )) { + return ret; + } + } + } + return 0; +} + static int dn_callback( Operation* op, @@ -1991,4 +2016,3 @@ avl_ber_bvfree( void *bv ) } ch_free ( (char *) bv ); } - -- 2.39.5