From 79d4e4cf6ae95675f361d366ae391c55044808af Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Tue, 7 Sep 2010 13:21:20 +0000 Subject: [PATCH] add support for ADD_IF_NOT_PRESENT and SOFTDEL internal modification types (ITS#6561) --- servers/slapd/acl.c | 8 +++++ servers/slapd/back-bdb/modify.c | 50 +++++++++++++++++++++++++++++ servers/slapd/back-ldif/ldif.c | 25 +++++++++++++++ servers/slapd/back-ndb/modify.cpp | 43 +++++++++++++++++++++++++ servers/slapd/back-sql/add.c | 2 ++ servers/slapd/bconfig.c | 19 +++++++++-- servers/slapd/modify.c | 1 + servers/slapd/overlays/constraint.c | 23 +++++++++++++ servers/slapd/overlays/dds.c | 4 ++- servers/slapd/slap.h | 23 ++++++++++--- 10 files changed, 190 insertions(+), 8 deletions(-) diff --git a/servers/slapd/acl.c b/servers/slapd/acl.c index a1d52492b6..476b9e667b 100644 --- a/servers/slapd/acl.c +++ b/servers/slapd/acl.c @@ -1985,8 +1985,15 @@ acl_check_modlist( /* fall thru to check value to add */ case LDAP_MOD_ADD: + case SLAP_MOD_ADD_IF_NOT_PRESENT: assert( mlist->sml_values != NULL ); + if ( mlist->sml_op == SLAP_MOD_ADD_IF_NOT_PRESENT + && attr_find( e->e_attrs, mlist->sml_desc ) ) + { + break; + } + for ( bv = mlist->sml_nvalues ? mlist->sml_nvalues : mlist->sml_values; bv->bv_val != NULL; bv++ ) @@ -2003,6 +2010,7 @@ acl_check_modlist( break; case LDAP_MOD_DELETE: + case SLAP_MOD_SOFTDEL: if ( mlist->sml_values == NULL ) { if ( ! access_allowed( op, e, mlist->sml_desc, NULL, diff --git a/servers/slapd/back-bdb/modify.c b/servers/slapd/back-bdb/modify.c index 5db7aa9847..7bd80ea4f4 100644 --- a/servers/slapd/back-bdb/modify.c +++ b/servers/slapd/back-bdb/modify.c @@ -215,6 +215,56 @@ int bdb_modify_internal( } break; + case SLAP_MOD_SOFTDEL: + Debug(LDAP_DEBUG_ARGS, + "bdb_modify_internal: softdel %s\n", + mod->sm_desc->ad_cname.bv_val, 0, 0); + /* Avoid problems in index_delete_mods() + * We need to add index if necessary. + */ + mod->sm_op = LDAP_MOD_DELETE; + + err = modify_delete_values( e, mod, get_permissiveModify(op), + text, textbuf, textlen ); + + mod->sm_op = SLAP_MOD_SOFTDEL; + + if ( err == LDAP_TYPE_OR_VALUE_EXISTS ) { + err = LDAP_SUCCESS; + } + + if( err != LDAP_SUCCESS ) { + Debug(LDAP_DEBUG_ARGS, "bdb_modify_internal: %d %s\n", + err, *text, 0); + } + break; + + case SLAP_MOD_ADD_IF_NOT_PRESENT: + if ( attr_find( e->e_attrs, mod->sm_desc ) != NULL ) { + /* skip */ + err = LDAP_SUCCESS; + break; + } + + Debug(LDAP_DEBUG_ARGS, + "bdb_modify_internal: add_if_not_present %s\n", + mod->sm_desc->ad_cname.bv_val, 0, 0); + /* Avoid problems in index_add_mods() + * We need to add index if necessary. + */ + mod->sm_op = LDAP_MOD_ADD; + + err = modify_add_values( e, mod, get_permissiveModify(op), + text, textbuf, textlen ); + + mod->sm_op = SLAP_MOD_ADD_IF_NOT_PRESENT; + + if( err != LDAP_SUCCESS ) { + Debug(LDAP_DEBUG_ARGS, "bdb_modify_internal: %d %s\n", + err, *text, 0); + } + break; + default: Debug(LDAP_DEBUG_ANY, "bdb_modify_internal: invalid op %d\n", mod->sm_op, 0, 0); diff --git a/servers/slapd/back-ldif/ldif.c b/servers/slapd/back-ldif/ldif.c index 671550919b..a3f13b1365 100644 --- a/servers/slapd/back-ldif/ldif.c +++ b/servers/slapd/back-ldif/ldif.c @@ -1073,6 +1073,31 @@ apply_modify_to_entry( rc = LDAP_SUCCESS; } break; + + case SLAP_MOD_SOFTDEL: + mods->sm_op = LDAP_MOD_DELETE; + rc = modify_delete_values(entry, mods, + get_permissiveModify(op), + &rs->sr_text, textbuf, + sizeof( textbuf ) ); + mods->sm_op = SLAP_MOD_SOFTDEL; + if (rc == LDAP_NO_SUCH_ATTRIBUTE) { + rc = LDAP_SUCCESS; + } + break; + + case SLAP_MOD_ADD_IF_NOT_PRESENT: + if ( attr_find( entry->e_attrs, mods->sm_desc ) ) { + rc = LDAP_SUCCESS; + break; + } + mods->sm_op = LDAP_MOD_ADD; + rc = modify_add_values(entry, mods, + get_permissiveModify(op), + &rs->sr_text, textbuf, + sizeof( textbuf ) ); + mods->sm_op = SLAP_MOD_ADD_IF_NOT_PRESENT; + break; } if(rc != LDAP_SUCCESS) break; } diff --git a/servers/slapd/back-ndb/modify.cpp b/servers/slapd/back-ndb/modify.cpp index 274bc093f2..73bb9f755c 100644 --- a/servers/slapd/back-ndb/modify.cpp +++ b/servers/slapd/back-ndb/modify.cpp @@ -300,6 +300,49 @@ int ndb_modify_internal( } break; + case SLAP_MOD_SOFTDEL: + Debug(LDAP_DEBUG_ARGS, + "ndb_modify_internal: softdel %s\n", + mod->sm_desc->ad_cname.bv_val, 0, 0); + mod->sm_op = LDAP_MOD_DELETE; + + rc = modify_delete_values( NA->e, mod, get_permissiveModify(op), + text, textbuf, textlen ); + + mod->sm_op = SLAP_MOD_SOFTDEL; + + if ( rc == LDAP_NO_SUCH_ATTRIBUTE) { + rc = LDAP_SUCCESS; + } + + if( rc != LDAP_SUCCESS ) { + Debug(LDAP_DEBUG_ARGS, "ndb_modify_internal: %d %s\n", + rc, *text, 0); + } + break; + + case SLAP_MOD_ADD_IF_NOT_PRESENT: + Debug(LDAP_DEBUG_ARGS, + "ndb_modify_internal: add_if_not_present %s\n", + mod->sm_desc->ad_cname.bv_val, 0, 0); + if ( attr_find( NA->e->e_attrs, mod->sm_desc ) ) { + rc = LDAP_SUCCESS; + break; + } + + mod->sm_op = LDAP_MOD_ADD; + + rc = modify_add_values( NA->e, mod, get_permissiveModify(op), + text, textbuf, textlen ); + + mod->sm_op = SLAP_MOD_ADD_IF_NOT_PRESENT; + + if( rc != LDAP_SUCCESS ) { + Debug(LDAP_DEBUG_ARGS, "ndb_modify_internal: %d %s\n", + rc, *text, 0); + } + break; + default: Debug(LDAP_DEBUG_ANY, "ndb_modify_internal: invalid op %d\n", mod->sm_op, 0, 0); diff --git a/servers/slapd/back-sql/add.c b/servers/slapd/back-sql/add.c index 94d00732fe..9c162e926a 100644 --- a/servers/slapd/back-sql/add.c +++ b/servers/slapd/back-sql/add.c @@ -389,6 +389,7 @@ del_all: */ case LDAP_MOD_ADD: /* case SLAP_MOD_SOFTADD: */ + /* case SLAP_MOD_ADD_IF_NOT_PRESENT: */ add_only:; if ( at->bam_add_proc == NULL ) { Debug( LDAP_DEBUG_TRACE, @@ -541,6 +542,7 @@ add_only:; break; case LDAP_MOD_DELETE: + /* case SLAP_MOD_SOFTDEL: */ if ( at->bam_delete_proc == NULL ) { Debug( LDAP_DEBUG_TRACE, " backsql_modify_internal(): " diff --git a/servers/slapd/bconfig.c b/servers/slapd/bconfig.c index d08e3c98c8..de159d96e9 100644 --- a/servers/slapd/bconfig.c +++ b/servers/slapd/bconfig.c @@ -5562,7 +5562,9 @@ config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs, ct = config_find_table( colst, nocs, ml->sml_desc, ca ); switch (ml->sml_op) { case LDAP_MOD_DELETE: - case LDAP_MOD_REPLACE: { + case LDAP_MOD_REPLACE: + case SLAP_MOD_SOFTDEL: + { BerVarray vals = NULL, nvals = NULL; int *idx = NULL; if ( ct && ( ct->arg_type & ARG_NO_DELETE )) { @@ -5601,11 +5603,24 @@ config_modify_internal( CfEntryInfo *ce, Operation *op, SlapReply *rs, ml->sml_values = vals; ml->sml_nvalues = nvals; } + if ( rc == LDAP_NO_SUCH_ATTRIBUTE && ml->sml_op == SLAP_MOD_SOFTDEL ) + { + rc = LDAP_SUCCESS; + } + /* FIXME: check rc before fallthru? */ if ( !vals ) break; - } + } /* FALLTHRU: LDAP_MOD_REPLACE && vals */ + case SLAP_MOD_ADD_IF_NOT_PRESENT: + if ( ml->sml_op == SLAP_MOD_ADD_IF_NOT_PRESENT + && attr_find( e->e_attrs, ml->sml_desc ) ) + { + rc = LDAP_SUCCESS; + break; + } + case LDAP_MOD_ADD: case SLAP_MOD_SOFTADD: { int mop = ml->sml_op; diff --git a/servers/slapd/modify.c b/servers/slapd/modify.c index 3b5f7271a0..8898a8eebd 100644 --- a/servers/slapd/modify.c +++ b/servers/slapd/modify.c @@ -878,6 +878,7 @@ void slap_mods_opattrs( for ( modtail = modsp; *modtail; modtail = &(*modtail)->sml_next ) { if ( (*modtail)->sml_op != LDAP_MOD_ADD && (*modtail)->sml_op != SLAP_MOD_SOFTADD && + (*modtail)->sml_op != SLAP_MOD_ADD_IF_NOT_PRESENT && (*modtail)->sml_op != LDAP_MOD_REPLACE ) { continue; diff --git a/servers/slapd/overlays/constraint.c b/servers/slapd/overlays/constraint.c index ec640d9dad..dc6039de43 100644 --- a/servers/slapd/overlays/constraint.c +++ b/servers/slapd/overlays/constraint.c @@ -1027,6 +1027,29 @@ constraint_update( Operation *op, SlapReply *rs ) } break; + case SLAP_MOD_SOFTDEL: + mod->sm_op = LDAP_MOD_ADD; + err = modify_delete_values( target_entry_copy, + mod, get_permissiveModify(op), + &text, textbuf, textlen ); + mod->sm_op = SLAP_MOD_SOFTDEL; + if ( err == LDAP_NO_SUCH_ATTRIBUTE ) { + err = LDAP_SUCCESS; + } + break; + + case SLAP_MOD_ADD_IF_NOT_PRESENT: + if ( attr_find( target_entry_copy->e_attrs, mod->sm_desc ) ) { + err = LDAP_SUCCESS; + break; + } + mod->sm_op = LDAP_MOD_ADD; + err = modify_add_values( target_entry_copy, + mod, get_permissiveModify(op), + &text, textbuf, textlen ); + mod->sm_op = SLAP_MOD_ADD_IF_NOT_PRESENT; + break; + default: err = LDAP_OTHER; break; diff --git a/servers/slapd/overlays/dds.c b/servers/slapd/overlays/dds.c index c0bbc40d84..450ba78b20 100644 --- a/servers/slapd/overlays/dds.c +++ b/servers/slapd/overlays/dds.c @@ -587,6 +587,7 @@ dds_op_modify( Operation *op, SlapReply *rs ) switch ( mod->sml_op ) { case LDAP_MOD_DELETE: + case SLAP_MOD_SOFTDEL: /* FIXME? */ if ( mod->sml_values != NULL ) { if ( BER_BVISEMPTY( &bv_entryTtl ) || !bvmatch( &bv_entryTtl, &mod->sml_values[ 0 ] ) ) @@ -611,8 +612,9 @@ dds_op_modify( Operation *op, SlapReply *rs ) entryTtl = -1; /* fallthru */ - case SLAP_MOD_SOFTADD: /* FIXME? */ case LDAP_MOD_ADD: + case SLAP_MOD_SOFTADD: /* FIXME? */ + case SLAP_MOD_ADD_IF_NOT_PRESENT: /* FIXME? */ assert( mod->sml_values != NULL ); assert( BER_BVISNULL( &mod->sml_values[ 1 ] ) ); diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index a4bf1e9bc2..6b3d901937 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -111,12 +111,25 @@ LDAP_BEGIN_DECL # define SLAP_STRING_UNKNOWN "unknown" #endif /* ! TCP Wrappers */ -/* LDAPMod.mod_op value ===> Must be kept in sync with ldap.h! - * This is a value used internally by the backends. It is needed to allow - * adding values that already exist without getting an error as required by - * modrdn when the new rdn was already an attribute value itself. +/* LDAPMod.mod_op value ===> Must be kept in sync with ldap.h! */ +/* These values are used internally by the backends. */ +/* SLAP_MOD_SOFTADD allows adding values that already exist without getting + * an error as required by modrdn when the new rdn was already an attribute + * value itself. + */ +#define SLAP_MOD_SOFTADD 0x1000 +/* SLAP_MOD_SOFTDEL allows deleting values if they exist without getting + * an error otherwise. + */ +#define SLAP_MOD_SOFTDEL 0x1001 +/* SLAP_MOD_ADD_IF_NOT_PRESENT allows adding values unless the attribute + * is already present without getting an error. + */ +#define SLAP_MOD_ADD_IF_NOT_PRESENT 0x1002 +/* SLAP_MOD_DEL_IF_PRESENT allows deleting values if the attribute + * is present, without getting an error otherwise. + * The semantics can be obtained using SLAP_MOD_SOFTDEL with NULL values. */ -#define SLAP_MOD_SOFTADD 0x1000 #define MAXREMATCHES (100) -- 2.39.5