ldap/servers
by Richard Allen Megginson
ldap/servers/plugins/mep/mep.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
New commits:
commit 184a57a8358806b378d3e3568880c1f247ef4117
Author: Rich Megginson <rmeggins(a)redhat.com>
Date: Tue Jan 17 14:46:15 2012 -0700
fix mep sdn compiler warnings
Reviewed by: nhosoi (Thanks!)
diff --git a/ldap/servers/plugins/mep/mep.c b/ldap/servers/plugins/mep/mep.c
index 7e18991..537a606 100644
--- a/ldap/servers/plugins/mep/mep.c
+++ b/ldap/servers/plugins/mep/mep.c
@@ -757,7 +757,7 @@ mep_free_config_entry(struct configEntry ** entry)
if (e->sdn) {
slapi_log_error(SLAPI_LOG_CONFIG, MEP_PLUGIN_SUBSYSTEM,
"freeing config entry [%s]\n", slapi_sdn_get_dn(e->sdn));
- slapi_sdn_free_string(&e->sdn);
+ slapi_sdn_free(&e->sdn);
}
if (e->origin_scope) {
@@ -773,7 +773,7 @@ mep_free_config_entry(struct configEntry ** entry)
}
if (e->template_sdn) {
- slapi_sdn_free_(&e->template_sdn);
+ slapi_sdn_free(&e->template_sdn);
}
if (e->template_entry) {
11 years, 11 months
2 commits - ldap/admin ldap/servers
by Noriko Hosoi
ldap/admin/src/scripts/DSCreate.pm.in | 1
ldap/servers/plugins/usn/usn.c | 8 --
ldap/servers/slapd/entry.c | 11 ++
ldap/servers/slapd/libglobs.c | 88 +++++++++++++++++++++-
ldap/servers/slapd/mapping_tree.c | 131 +++++++++++++++++++++++++++++++---
ldap/servers/slapd/plugin.c | 2
ldap/servers/slapd/proto-slap.h | 3
ldap/servers/slapd/rdn.c | 12 +++
ldap/servers/slapd/rootdse.c | 8 +-
ldap/servers/slapd/slap.h | 2
ldap/servers/slapd/slapi-plugin.h | 14 +++
11 files changed, 253 insertions(+), 27 deletions(-)
New commits:
commit a8bacbae7878728573fb4b02a2afe24985d8b0ee
Author: Noriko Hosoi <nhosoi(a)redhat.com>
Date: Mon Jan 16 17:29:49 2012 -0800
Trac Ticket 75 - Unconfigure plugin opperations are being called.
https://fedorahosted.org/389/ticket/75
Fix descriptions:
When plugin is not enabled, the start function is not called,
but the initialization is made and the plugins are registered.
This patch calls the initialization/plugin registration only
when the plugin is enabled.
diff --git a/ldap/servers/plugins/usn/usn.c b/ldap/servers/plugins/usn/usn.c
index b211019..f5579c9 100644
--- a/ldap/servers/plugins/usn/usn.c
+++ b/ldap/servers/plugins/usn/usn.c
@@ -77,18 +77,10 @@ usn_init(Slapi_PBlock *pb)
{
int rc = 0;
void *identity = NULL;
- int enabled = 0;
slapi_log_error(SLAPI_LOG_TRACE, USN_PLUGIN_SUBSYSTEM,
"--> usn_init\n");
- slapi_pblock_get(pb, SLAPI_PLUGIN_ENABLED, &enabled);
-
- if (!enabled) {
- /* not enabled */
- goto bail;
- }
-
slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &identity);
/* slapi_register_plugin always returns SUCCESS (0) */
diff --git a/ldap/servers/slapd/plugin.c b/ldap/servers/slapd/plugin.c
index 52b560f..8179352 100644
--- a/ldap/servers/slapd/plugin.c
+++ b/ldap/servers/slapd/plugin.c
@@ -2293,7 +2293,7 @@ plugin_setup(Slapi_Entry *plugin_entry, struct slapi_componentid *group,
slapi_pblock_set(&pb, SLAPI_PLUGIN_ENABLED, &enabled);
slapi_pblock_set(&pb, SLAPI_PLUGIN_CONFIG_ENTRY, plugin_entry);
- if ((*initfunc)(&pb) != 0)
+ if (enabled && (*initfunc)(&pb) != 0)
{
LDAPDebug(LDAP_DEBUG_ANY, "Init function \"%s\" for \"%s\" plugin"
" in library \"%s\" failed\n",
commit 50ed1b2498b9441be34be9c68070835787677b07
Author: Noriko Hosoi <nhosoi(a)redhat.com>
Date: Mon Jan 16 17:25:07 2012 -0800
Trac Ticket 26 - Please support setting
defaultNamingContext in the rootdse.
https://fedorahosted.org/389/ticket/26
Fix descriptions:
1) Introducing an attribute defaultNamingContext to rootdse.
2) To support it, a config parameter nsslapd-defaultnamingcontext
is added.
. Suffix created in setup is set to nsslapd-defaultnamingcontext
in createConfigFile (DSCreate.pm).
. If the default naming context is deleted from mapping tree,
the config parameter nsslapd-defaultnamingcontext as well as
the attribute defaultNamingContext in rootdse are removed.
. When nsslapd-defaultnamingcontext does not exist, there are
3 ways to set it.
a) Next added suffix is automatically set.
b) Add nsslapd-defaultnamingcontext value to cn=config
using ldap client.
c) Shutdown the server and add nsslapd-defaultnamingcontext
value to cn=config
. nsslapd-defaultnamingcontext value could be replaced with
other existing suffix with ldap modify operation.
diff --git a/ldap/admin/src/scripts/DSCreate.pm.in b/ldap/admin/src/scripts/DSCreate.pm.in
index c60ca89..00d290c 100644
--- a/ldap/admin/src/scripts/DSCreate.pm.in
+++ b/ldap/admin/src/scripts/DSCreate.pm.in
@@ -418,6 +418,7 @@ sub createConfigFile {
$ent->setValues("nsslapd-ldapiautodnsuffix", "cn=peercred,cn=external,cn=auth");
}
}
+ $ent->setValues("nsslapd-defaultNamingContext", $inf->{slapd}->{Suffix});
if (!$conn->update($ent)) {
$conn->close();
return ("error_enabling_feature", "ldapi", $conn->getErrorString());
diff --git a/ldap/servers/slapd/entry.c b/ldap/servers/slapd/entry.c
index bf7b4bf..cac7b85 100644
--- a/ldap/servers/slapd/entry.c
+++ b/ldap/servers/slapd/entry.c
@@ -2185,7 +2185,16 @@ slapi_entry_get_rdn_const( const Slapi_Entry *e )
const char *
slapi_entry_get_nrdn_const( const Slapi_Entry *e )
{
- return (slapi_rdn_get_nrdn(slapi_entry_get_srdn((Slapi_Entry *)e)));
+ const char *nrdn =
+ slapi_rdn_get_nrdn(slapi_entry_get_srdn((Slapi_Entry *)e));
+ if (NULL == nrdn) {
+ const char *dn = slapi_entry_get_dn_const(e);
+ if (dn) {
+ slapi_rdn_init_all_dn(&e->e_srdn, dn);
+ nrdn = slapi_rdn_get_nrdn(slapi_entry_get_srdn((Slapi_Entry *)e));
+ }
+ }
+ return nrdn;
}
/*
diff --git a/ldap/servers/slapd/libglobs.c b/ldap/servers/slapd/libglobs.c
index b9beafb..2177934 100644
--- a/ldap/servers/slapd/libglobs.c
+++ b/ldap/servers/slapd/libglobs.c
@@ -643,12 +643,17 @@ static struct config_get_and_set {
(void**)&global_slapdFrontendConfig.allowed_to_delete_attrs,
CONFIG_STRING, (ConfigGetFunc)config_get_allowed_to_delete_attrs},
{CONFIG_VALIDATE_CERT_ATTRIBUTE, config_set_validate_cert_switch,
- NULL, 0,
- (void**)&global_slapdFrontendConfig.validate_cert, CONFIG_SPECIAL_VALIDATE_CERT_SWITCH,
- (ConfigGetFunc)config_get_validate_cert_switch},
+ NULL, 0,
+ (void**)&global_slapdFrontendConfig.validate_cert,
+ CONFIG_SPECIAL_VALIDATE_CERT_SWITCH,
+ (ConfigGetFunc)config_get_validate_cert_switch},
{CONFIG_PAGEDSIZELIMIT_ATTRIBUTE, config_set_pagedsizelimit,
NULL, 0,
(void**)&global_slapdFrontendConfig.pagedsizelimit, CONFIG_INT, NULL},
+ {CONFIG_DEFAULT_NAMING_CONTEXT, config_set_default_naming_context,
+ NULL, 0,
+ (void**)&global_slapdFrontendConfig.default_naming_context,
+ CONFIG_STRING, (ConfigGetFunc)config_get_default_naming_context},
#ifdef MEMPOOL_EXPERIMENTAL
,{CONFIG_MEMPOOL_SWITCH_ATTRIBUTE, config_set_mempool_switch,
NULL, 0,
@@ -1031,7 +1036,8 @@ FrontendConfig_init () {
cfg->entryusn_global = LDAP_OFF;
cfg->entryusn_import_init = slapi_ch_strdup("0");
- cfg->allowed_to_delete_attrs = slapi_ch_strdup("nsslapd-listenhost nsslapd-securelistenhost");
+ cfg->allowed_to_delete_attrs = slapi_ch_strdup("nsslapd-listenhost nsslapd-securelistenhost nsslapd-defaultnamingcontext");
+ cfg->default_naming_context = NULL; /* store normalized dn */
#ifdef MEMPOOL_EXPERIMENTAL
cfg->mempool_switch = LDAP_ON;
@@ -5801,6 +5807,80 @@ config_set_allowed_to_delete_attrs( const char *attrname, char *value,
return retVal;
}
+char *
+config_get_default_naming_context(void)
+{
+ char *retVal;
+ slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
+
+ CFG_LOCK_READ(slapdFrontendConfig);
+ retVal = slapdFrontendConfig->default_naming_context;
+ CFG_UNLOCK_READ(slapdFrontendConfig);
+
+ return retVal;
+}
+
+int
+config_set_default_naming_context(const char *attrname,
+ char *value, char *errorbuf, int apply)
+{
+ slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
+ void *node;
+ Slapi_DN *sdn;
+ char *suffix = NULL;
+
+ if (value && *value) {
+ int in_init = 0;
+ suffix = slapi_create_dn_string("%s", value);
+ if (NULL == suffix) {
+ if (errorbuf) {
+ PR_snprintf (errorbuf, SLAPI_DSE_RETURNTEXT_SIZE,
+ "%s is not a valid suffix.", value);
+ }
+ return LDAP_INVALID_DN_SYNTAX;
+ }
+ sdn = slapi_get_first_suffix(&node, 0);
+ if (NULL == sdn) {
+ in_init = 1; /* at the startup time, no suffix is set yet */
+ }
+ while (sdn) {
+ if (0 == strcasecmp(suffix, slapi_sdn_get_dn(sdn))) {
+ /* matched */
+ break;
+ }
+ sdn = slapi_get_next_suffix(&node, 0);
+ }
+ if (!in_init && (NULL == sdn)) { /* not in startup && no match */
+ if (errorbuf) {
+ PR_snprintf (errorbuf, SLAPI_DSE_RETURNTEXT_SIZE,
+ "%s is not an existing suffix.", value);
+ }
+ slapi_ch_free_string(&suffix);
+ return LDAP_NO_SUCH_OBJECT;
+ }
+ } else {
+ /* reset */
+ suffix = NULL;
+ }
+
+ if (!apply) {
+ return LDAP_SUCCESS;
+ }
+
+ if (errorbuf) {
+ *errorbuf = '\0';
+ }
+
+ if (apply) {
+ CFG_LOCK_WRITE(slapdFrontendConfig);
+ slapi_ch_free_string(&slapdFrontendConfig->default_naming_context);
+ /* normalized suffix*/
+ slapdFrontendConfig->default_naming_context = suffix;
+ CFG_UNLOCK_WRITE(slapdFrontendConfig);
+ }
+ return LDAP_SUCCESS;
+}
+
/*
* This function is intended to be used from the dse code modify callback. It
* is "optimized" for that case because it takes a berval** of values, which is
diff --git a/ldap/servers/slapd/mapping_tree.c b/ldap/servers/slapd/mapping_tree.c
index 935e34a..3aa3bec 100644
--- a/ldap/servers/slapd/mapping_tree.c
+++ b/ldap/servers/slapd/mapping_tree.c
@@ -155,6 +155,7 @@ static mapping_tree_node * mtn_get_first_node(mapping_tree_node * node,
int scope);
static mapping_tree_node *
get_mapping_tree_node_by_name(mapping_tree_node * node, char * be_name);
+static int _mtn_update_config_param(int op, char *type, char *strvalue);
#ifdef DEBUG
static void dump_mapping_tree(mapping_tree_node *parent, int depth);
@@ -1419,6 +1420,32 @@ int mapping_tree_entry_add_callback(Slapi_PBlock *pb, Slapi_Entry* entryBefore,
node->mtn_extension = factory_create_extension(mapping_tree_get_extension_type(), node, NULL);
+ /*
+ * Check defaultNamingContext is set.
+ * If it is not set, set the to-be-added suffix to the config param.
+ */
+ if (NULL == config_get_default_naming_context()) {
+ char *suffix =
+ slapi_rdn_get_value(slapi_entry_get_nrdn_const(entryBefore));
+ char *escaped = slapi_ch_strdup(suffix);
+ if (suffix && escaped) {
+ strcpy_unescape_value(escaped, suffix);
+ }
+ if (escaped) {
+ int rc = _mtn_update_config_param(LDAP_MOD_REPLACE,
+ CONFIG_DEFAULT_NAMING_CONTEXT,
+ escaped);
+ if (rc) {
+ LDAPDebug(LDAP_DEBUG_ANY,
+ "mapping_tree_entry_add_callback: "
+ "setting %s to %s failed: RC=%d\n",
+ escaped, CONFIG_DEFAULT_NAMING_CONTEXT, rc);
+ }
+ }
+ slapi_ch_free_string(&suffix);
+ slapi_ch_free_string(&escaped);
+ }
+
return SLAPI_DSE_CALLBACK_OK;
}
@@ -1443,7 +1470,7 @@ static void mtn_remove_node(mapping_tree_node * node)
int mapping_tree_entry_delete_callback(Slapi_PBlock *pb, Slapi_Entry* entryBefore, Slapi_Entry* e, int *returncode, char *returntext, void *arg)
{
- int result;
+ int result = SLAPI_DSE_CALLBACK_OK;
mapping_tree_node *node = NULL;
Slapi_DN * subtree;
int i;
@@ -1499,9 +1526,51 @@ int mapping_tree_entry_delete_callback(Slapi_PBlock *pb, Slapi_Entry* entryBefor
result = SLAPI_DSE_CALLBACK_OK;
removed = 1;
-
+
done:
mtn_unlock();
+
+ /* Remove defaultNamingContext if it is the to-be-deleted suffix.
+ * It should be done outside of mtn lock. */
+ if (SLAPI_DSE_CALLBACK_OK == result) {
+ char *default_naming_context = config_get_default_naming_context();
+ char *suffix, *escaped;
+ if (default_naming_context) {
+ suffix =
+ slapi_rdn_get_value(slapi_entry_get_nrdn_const(entryBefore));
+ escaped = slapi_ch_strdup(suffix);
+ if (suffix && escaped) {
+ strcpy_unescape_value(escaped, suffix);
+ }
+ if (escaped && (0 == strcasecmp(escaped, default_naming_context))) {
+ int rc = _mtn_update_config_param(LDAP_MOD_DELETE,
+ CONFIG_DEFAULT_NAMING_CONTEXT,
+ NULL);
+ if (rc) {
+ LDAPDebug2Args(LDAP_DEBUG_ANY,
+ "mapping_tree_entry_delete_callback: "
+ "deleting config param %s failed: RC=%d\n",
+ CONFIG_DEFAULT_NAMING_CONTEXT, rc);
+ }
+ if (LDAP_SUCCESS == rc) {
+ char errorbuf[SLAPI_DSE_RETURNTEXT_SIZE];
+ /* Removing defaultNamingContext from cn=config entry
+ * was successful. The remove does not reset the
+ * global parameter. We need to reset it separately. */
+ if (config_set_default_naming_context(
+ CONFIG_DEFAULT_NAMING_CONTEXT,
+ NULL, errorbuf, CONFIG_APPLY)) {
+ LDAPDebug2Args(LDAP_DEBUG_ANY,
+ "mapping_tree_entry_delete_callback: "
+ "setting NULL to %s failed. %s\n",
+ CONFIG_DEFAULT_NAMING_CONTEXT, errorbuf);
+ }
+ }
+ }
+ slapi_ch_free_string(&suffix);
+ slapi_ch_free_string(&escaped);
+ }
+ }
slapi_sdn_free(&subtree);
if (SLAPI_DSE_CALLBACK_OK == result && removed)
{
@@ -2506,11 +2575,11 @@ static int mtn_get_be(mapping_tree_node *target_node, Slapi_PBlock *pb,
target_sdn = operation_get_target_spec (op);
if (target_node->mtn_state == MTN_DISABLED) {
- if (errorbuf) {
- PR_snprintf(errorbuf, BUFSIZ,
+ if (errorbuf) {
+ PR_snprintf(errorbuf, BUFSIZ,
"Warning: Operation attempted on a disabled node : %s\n",
- slapi_sdn_get_dn(target_node->mtn_subtree));
- }
+ slapi_sdn_get_dn(target_node->mtn_subtree));
+ }
result = LDAP_OPERATIONS_ERROR;
return result;
}
@@ -3047,10 +3116,12 @@ slapi_be_exist(const Slapi_DN *sdn) /* JCM - The name of this should change??? *
Slapi_DN *
slapi_get_first_suffix(void ** node, int show_private)
{
- mapping_tree_node * first_node = mapping_tree_root->mtn_children;
- if (NULL == node) {
+ mapping_tree_node *first_node;
+
+ if ((NULL == node) || (NULL == mapping_tree_root)) {
return NULL;
}
+ first_node = mapping_tree_root->mtn_children;
*node = (void * ) first_node ;
while (first_node && (first_node->mtn_private && (show_private == 0)))
first_node = first_node->mtn_brother;
@@ -3060,9 +3131,9 @@ slapi_get_first_suffix(void ** node, int show_private)
Slapi_DN *
slapi_get_next_suffix(void ** node, int show_private)
{
- mapping_tree_node * next_node = NULL;
+ mapping_tree_node *next_node;
- if (NULL == node) {
+ if ((NULL == node) || (NULL == mapping_tree_root)) {
return NULL;
}
next_node = *node;
@@ -3681,3 +3752,43 @@ static void dump_mapping_tree(mapping_tree_node *parent, int depth)
return;
}
#endif
+
+/* helper function to set/remove the config param in cn=config */
+static int
+_mtn_update_config_param(int op, char *type, char *strvalue)
+{
+ Slapi_PBlock confpb;
+ Slapi_DN sdn;
+ Slapi_Mods smods;
+ LDAPMod **mods;
+ int rc = LDAP_PARAM_ERROR;
+
+ pblock_init (&confpb);
+ slapi_mods_init (&smods, 0);
+ switch (op) {
+ case LDAP_MOD_DELETE:
+ slapi_mods_add(&smods, op, type, 0, NULL);
+ break;
+ case LDAP_MOD_ADD:
+ case LDAP_MOD_REPLACE:
+ slapi_mods_add_string(&smods, op, type, strvalue);
+ break;
+ default:
+ return rc;
+ }
+ slapi_sdn_init_ndn_byref(&sdn, SLAPD_CONFIG_DN);
+ slapi_modify_internal_set_pb_ext(&confpb, &sdn,
+ slapi_mods_get_ldapmods_byref(&smods),
+ NULL, NULL,
+ (void *)plugin_get_default_component_id(), 0);
+ slapi_modify_internal_pb(&confpb);
+ slapi_pblock_get (&confpb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
+ slapi_sdn_done(&sdn);
+ /* need to free passed out mods
+ * since the internal modify could realloced mods. */
+ slapi_pblock_get(&confpb, SLAPI_MODIFY_MODS, &mods);
+ ldap_mods_free (mods, 1 /* Free the Array and the Elements */);
+ pblock_done(&confpb);
+
+ return rc;
+}
diff --git a/ldap/servers/slapd/proto-slap.h b/ldap/servers/slapd/proto-slap.h
index 9714871..a3fcc5f 100644
--- a/ldap/servers/slapd/proto-slap.h
+++ b/ldap/servers/slapd/proto-slap.h
@@ -377,7 +377,7 @@ int config_set_force_sasl_external(const char *attrname, char *value, char *erro
int config_set_entryusn_global( const char *attrname, char *value, char *errorbuf, int apply );
int config_set_allowed_to_delete_attrs( const char *attrname, char *value, char *errorbuf, int apply );
int config_set_entryusn_import_init( const char *attrname, char *value, char *errorbuf, int apply );
-
+int config_set_default_naming_context( const char *attrname, char *value, char *errorbuf, int apply );
#if !defined(_WIN32) && !defined(AIX)
int config_set_maxdescriptors( const char *attrname, char *value, char *errorbuf, int apply );
@@ -522,6 +522,7 @@ int config_get_force_sasl_external();
int config_get_entryusn_global(void);
char *config_get_allowed_to_delete_attrs(void);
char *config_get_entryusn_import_init(void);
+char *config_get_default_naming_context(void);
int is_abspath(const char *);
char* rel2abspath( char * );
diff --git a/ldap/servers/slapd/rdn.c b/ldap/servers/slapd/rdn.c
index c9f6386..d408f0e 100644
--- a/ldap/servers/slapd/rdn.c
+++ b/ldap/servers/slapd/rdn.c
@@ -1092,3 +1092,15 @@ bail:
return sz;
}
+char *
+slapi_rdn_get_value(const char *rdn)
+{
+ char *p = PL_strchr(rdn, '=');
+ if (p) {
+ p++;
+ while (isspace(*p)) p++;
+ p = slapi_ch_strdup(p);
+ }
+ return p;
+}
+
diff --git a/ldap/servers/slapd/rootdse.c b/ldap/servers/slapd/rootdse.c
index 2368a3d..e9e903d 100644
--- a/ldap/servers/slapd/rootdse.c
+++ b/ldap/servers/slapd/rootdse.c
@@ -161,8 +161,14 @@ read_root_dse( Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Entry *entryAfter, int *r
sdn = slapi_get_next_suffix(&node, 0);
}
+ val.bv_val = config_get_default_naming_context();
+ if (val.bv_val) {
+ val.bv_len = strlen(val.bv_val);
+ attrlist_replace( &e->e_attrs, "defaultnamingcontext", vals );
+ }
+
attrlist_delete( &e->e_attrs, "nsBackendSuffix");
- for (be = slapi_get_first_backend(&cookie); be != NULL;
+ for (be = slapi_get_first_backend(&cookie); be != NULL;
be = slapi_get_next_backend(cookie)) {
char * base;
diff --git a/ldap/servers/slapd/slap.h b/ldap/servers/slapd/slap.h
index 4acf375..b59299c 100644
--- a/ldap/servers/slapd/slap.h
+++ b/ldap/servers/slapd/slap.h
@@ -1969,6 +1969,7 @@ typedef struct _slapdEntryPoints {
#define CONFIG_ENTRYUSN_GLOBAL "nsslapd-entryusn-global"
#define CONFIG_ENTRYUSN_IMPORT_INITVAL "nsslapd-entryusn-import-initval"
#define CONFIG_ALLOWED_TO_DELETE_ATTRIBUTE "nsslapd-allowed-to-delete-attrs"
+#define CONFIG_DEFAULT_NAMING_CONTEXT "nsslapd-defaultnamingcontext"
#ifdef MEMPOOL_EXPERIMENTAL
#define CONFIG_MEMPOOL_SWITCH_ATTRIBUTE "nsslapd-mempool"
@@ -2191,6 +2192,7 @@ typedef struct _slapdFrontendConfig {
char *allowed_to_delete_attrs;/* list of config attrs allowed to delete */
char *entryusn_import_init; /* Entry USN: determine the initital value of import */
int pagedsizelimit;
+ char *default_naming_context; /* Default naming context (normalized) */
} slapdFrontendConfig_t;
/* possible values for slapdFrontendConfig_t.schemareplace */
diff --git a/ldap/servers/slapd/slapi-plugin.h b/ldap/servers/slapd/slapi-plugin.h
index a92cc5b..2296351 100644
--- a/ldap/servers/slapd/slapi-plugin.h
+++ b/ldap/servers/slapd/slapi-plugin.h
@@ -3279,6 +3279,14 @@ int slapi_rdn_partial_dup(Slapi_RDN *from, Slapi_RDN **to, int idx);
*/
size_t slapi_rdn_get_size(Slapi_RDN *srdn);
+/**
+ * Return the value of the RDN
+ *
+ * \param rdn A pointer to rdn to get the value.
+ * \return The value of the given RDN.
+ */
+char * slapi_rdn_get_value(const char *rdn);
+
/*
* utility routines for dealing with DNs
*/
@@ -3334,7 +3342,7 @@ int slapi_dn_normalize_case_ext(char *src, size_t src_len, char **dest, size_t *
*
* \param fmt The format used to generate a DN string.
* \param ... The arguments to generate a DN string.
- * \return A pointer to the generated DN. The
+ * \return A pointer to the generated DN.
* \return NULL if failed.
* \note When a DN needs to be internally created, this function is supposed to be called. This function allocates the enough memory for the normalized DN and returns it filled with the normalized DN.
*/
@@ -5466,7 +5474,11 @@ int slapi_is_loglevel_set( const int loglevel );
*/
typedef struct slapi_mutex Slapi_Mutex;
typedef struct slapi_condvar Slapi_CondVar;
+#ifdef USE_POSIX_RWLOCKS
+typedef pthread_rwlock_t Slapi_RWLock;
+#else
typedef struct slapi_rwlock Slapi_RWLock;
+#endif
Slapi_Mutex *slapi_new_mutex( void );
void slapi_destroy_mutex( Slapi_Mutex *mutex );
void slapi_lock_mutex( Slapi_Mutex *mutex );
11 years, 11 months
ldap/servers
by Noriko Hosoi
ldap/servers/plugins/mep/mep.c | 105 +++++++++++++++++------------------------
ldap/servers/plugins/mep/mep.h | 4 -
2 files changed, 48 insertions(+), 61 deletions(-)
New commits:
commit c43a5085d2cec1a08f6ea60ac9c9de39b1b92537
Author: Mark Reynolds <mareynol(a)redhat.com>
Date: Tue Jan 17 12:23:50 2012 -0500
Ticket #71 - unable to delete managed entry config
https://fedorahosted.org/389/ticket/71
Bug Description: Trying to delete a managed entry config entry using ldapmodify
resulted in an error 53 becuase the code did not handle delete
operations.
Fix Description: Just check for the delete operation, and skip to the end. The
Post op function handles the delete automatically since it reloads
the cache from the real config.
I also converted all the char dn's to Slapi_DN's
diff --git a/ldap/servers/plugins/mep/mep.c b/ldap/servers/plugins/mep/mep.c
index 82acdbd..7e18991 100644
--- a/ldap/servers/plugins/mep/mep.c
+++ b/ldap/servers/plugins/mep/mep.c
@@ -98,9 +98,9 @@ static Slapi_DN *mep_get_sdn(Slapi_PBlock * pb);
static Slapi_DN *mep_get_config_area();
static void mep_set_config_area(Slapi_DN *sdn);
static int mep_dn_is_config(Slapi_DN *sdn);
-static int mep_dn_is_template(const char *dn);
+static int mep_dn_is_template(Slapi_DN *dn);
static void mep_find_config(Slapi_Entry *e, struct configEntry **config);
-static void mep_find_config_by_template_dn(const char *template_dn,
+static void mep_find_config_by_template_dn(Slapi_DN *template_dn,
struct configEntry **config);
static int mep_oktodo(Slapi_PBlock *pb);
static int mep_isrepl(Slapi_PBlock *pb);
@@ -557,10 +557,8 @@ mep_parse_config_entry(Slapi_Entry * e, int apply, Slapi_PBlock *pb)
goto bail;
}
- value = slapi_entry_get_ndn(e);
- if (value) {
- entry->dn = slapi_ch_strdup(value);
- } else {
+ entry->sdn = slapi_sdn_dup(slapi_entry_get_sdn(e));
+ if(entry->sdn == NULL){
slapi_log_error(SLAPI_LOG_FATAL, MEP_PLUGIN_SUBSYSTEM,
"mep_parse_config_entry: Error "
"reading dn from config entry\n");
@@ -569,7 +567,7 @@ mep_parse_config_entry(Slapi_Entry * e, int apply, Slapi_PBlock *pb)
}
slapi_log_error(SLAPI_LOG_CONFIG, MEP_PLUGIN_SUBSYSTEM,
- "----------> dn [%s]\n", entry->dn);
+ "----------> dn [%s]\n", slapi_sdn_get_dn(entry->sdn));
slapi_pblock_get(pb, SLAPI_TXN, &txn);
/* Load the origin scope */
@@ -580,7 +578,7 @@ mep_parse_config_entry(Slapi_Entry * e, int apply, Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_FATAL, MEP_PLUGIN_SUBSYSTEM,
"mep_parse_config_entry: The %s config "
"setting is required for config entry \"%s\".\n",
- MEP_SCOPE_TYPE, entry->dn);
+ MEP_SCOPE_TYPE, slapi_sdn_get_dn(entry->sdn));
ret = -1;
goto bail;
}
@@ -593,7 +591,7 @@ mep_parse_config_entry(Slapi_Entry * e, int apply, Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_FATAL, MEP_PLUGIN_SUBSYSTEM ,
"mep_parse_config_entry: Invalid search filter in "
"%s config setting for config entry \"%s\" "
- "(filter = \"%s\").\n", MEP_FILTER_TYPE, entry->dn, value);
+ "(filter = \"%s\").\n", MEP_FILTER_TYPE, slapi_sdn_get_dn(entry->sdn), value);
ret = -1;
}
@@ -606,7 +604,7 @@ mep_parse_config_entry(Slapi_Entry * e, int apply, Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_FATAL, MEP_PLUGIN_SUBSYSTEM,
"mep_parse_config_entry: The %s config "
"setting is required for config entry \"%s\".\n",
- MEP_FILTER_TYPE, entry->dn);
+ MEP_FILTER_TYPE, slapi_sdn_get_dn(entry->sdn));
ret = -1;
goto bail;
}
@@ -619,7 +617,7 @@ mep_parse_config_entry(Slapi_Entry * e, int apply, Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_FATAL, MEP_PLUGIN_SUBSYSTEM,
"mep_parse_config_entry: The %s config "
"setting is required for config entry \"%s\".\n",
- MEP_MANAGED_BASE_TYPE, entry->dn);
+ MEP_MANAGED_BASE_TYPE, slapi_sdn_get_dn(entry->sdn));
ret = -1;
goto bail;
}
@@ -628,23 +626,20 @@ mep_parse_config_entry(Slapi_Entry * e, int apply, Slapi_PBlock *pb)
value = slapi_entry_attr_get_charptr(e, MEP_MANAGED_TEMPLATE_TYPE);
if (value) {
Slapi_Entry *test_entry = NULL;
- Slapi_DN *template_sdn = NULL;
- entry->template_dn = value;
+ entry->template_sdn = slapi_sdn_new_dn_byval(value);
/* Fetch the managed entry template */
- template_sdn = slapi_sdn_new_dn_byref(entry->template_dn);
- slapi_search_internal_get_entry_ext(template_sdn, 0,
+ slapi_search_internal_get_entry_ext(entry->template_sdn, 0,
&entry->template_entry, mep_get_plugin_id(), txn);
- slapi_sdn_free(&template_sdn);
if (entry->template_entry == NULL) {
slapi_log_error(SLAPI_LOG_FATAL, MEP_PLUGIN_SUBSYSTEM,
"mep_parse_config_entry: The managed entry "
"template \"%s\" does not exist. Please "
"add it or correct the %s config setting for "
- "config entry \"%s\"\n", entry->template_dn,
- MEP_MANAGED_TEMPLATE_TYPE, entry->dn);
+ "config entry \"%s\"\n", slapi_sdn_get_dn(entry->template_sdn),
+ MEP_MANAGED_TEMPLATE_TYPE, slapi_sdn_get_dn(entry->sdn));
ret = -1;
goto bail;
}
@@ -657,7 +652,7 @@ mep_parse_config_entry(Slapi_Entry * e, int apply, Slapi_PBlock *pb)
"mep_parse_config_entry: Unable to create "
"a test managed entry from managed entry "
"template \"%s\". Please check the template "
- "entry for errors.\n", entry->template_dn);
+ "entry for errors.\n", slapi_sdn_get_dn(entry->template_sdn));
ret = -1;
goto bail;
}
@@ -668,7 +663,7 @@ mep_parse_config_entry(Slapi_Entry * e, int apply, Slapi_PBlock *pb)
"entry created from managed entry template "
"\"%s\" violates the schema. Please check "
"the template entry for schema errors.\n",
- entry->template_dn);
+ slapi_sdn_get_dn(entry->template_sdn));
slapi_entry_free(test_entry);
ret = -1;
goto bail;
@@ -681,7 +676,7 @@ mep_parse_config_entry(Slapi_Entry * e, int apply, Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_FATAL, MEP_PLUGIN_SUBSYSTEM,
"mep_parse_config_entry: The %s config "
"setting is required for config entry \"%s\".\n",
- MEP_MANAGED_TEMPLATE_TYPE, entry->dn);
+ MEP_MANAGED_TEMPLATE_TYPE, slapi_sdn_get_dn(entry->sdn));
ret = -1;
goto bail;
}
@@ -704,8 +699,8 @@ mep_parse_config_entry(Slapi_Entry * e, int apply, Slapi_PBlock *pb)
if (slapi_dn_issuffix(entry->origin_scope, config_entry->origin_scope)) {
PR_INSERT_BEFORE(&(entry->list), list);
slapi_log_error(SLAPI_LOG_CONFIG, MEP_PLUGIN_SUBSYSTEM,
- "store [%s] before [%s] \n", entry->dn,
- config_entry->dn);
+ "store [%s] before [%s] \n", slapi_sdn_get_dn(entry->sdn),
+ slapi_sdn_get_dn(config_entry->sdn));
entry_added = 1;
break;
@@ -717,7 +712,7 @@ mep_parse_config_entry(Slapi_Entry * e, int apply, Slapi_PBlock *pb)
if (g_mep_config == list) {
PR_INSERT_BEFORE(&(entry->list), list);
slapi_log_error(SLAPI_LOG_CONFIG, MEP_PLUGIN_SUBSYSTEM,
- "store [%s] at tail\n", entry->dn);
+ "store [%s] at tail\n", slapi_sdn_get_dn(entry->sdn));
entry_added = 1;
break;
@@ -727,7 +722,7 @@ mep_parse_config_entry(Slapi_Entry * e, int apply, Slapi_PBlock *pb)
/* first entry */
PR_INSERT_LINK(&(entry->list), g_mep_config);
slapi_log_error(SLAPI_LOG_CONFIG, MEP_PLUGIN_SUBSYSTEM,
- "store [%s] at head \n", entry->dn);
+ "store [%s] at head \n", slapi_sdn_get_dn(entry->sdn));
entry_added = 1;
}
@@ -738,7 +733,7 @@ mep_parse_config_entry(Slapi_Entry * e, int apply, Slapi_PBlock *pb)
if ((apply != 0) && (entry != NULL)) {
slapi_log_error(SLAPI_LOG_FATAL, MEP_PLUGIN_SUBSYSTEM,
"mep_parse_config_entry: Invalid config entry "
- "[%s] skipped\n", entry->dn);
+ "[%s] skipped\n", slapi_sdn_get_dn(entry->sdn));
}
mep_free_config_entry(&entry);
} else {
@@ -759,10 +754,10 @@ mep_free_config_entry(struct configEntry ** entry)
if (e == NULL)
return;
- if (e->dn) {
+ if (e->sdn) {
slapi_log_error(SLAPI_LOG_CONFIG, MEP_PLUGIN_SUBSYSTEM,
- "freeing config entry [%s]\n", e->dn);
- slapi_ch_free_string(&e->dn);
+ "freeing config entry [%s]\n", slapi_sdn_get_dn(e->sdn));
+ slapi_sdn_free_string(&e->sdn);
}
if (e->origin_scope) {
@@ -777,8 +772,8 @@ mep_free_config_entry(struct configEntry ** entry)
slapi_ch_free_string(&e->managed_base);
}
- if (e->template_dn) {
- slapi_ch_free_string(&e->template_dn);
+ if (e->template_sdn) {
+ slapi_sdn_free_(&e->template_sdn);
}
if (e->template_entry) {
@@ -884,31 +879,26 @@ bail:
* Checks if dn is a managed entries template.
*/
static int
-mep_dn_is_template(const char *dn)
+mep_dn_is_template(Slapi_DN *sdn)
{
int ret = 0;
PRCList *list = NULL;
Slapi_DN *config_sdn = NULL;
- Slapi_DN *sdn = slapi_sdn_new_dn_byref(dn);
if (!PR_CLIST_IS_EMPTY(g_mep_config)) {
list = PR_LIST_HEAD(g_mep_config);
while (list != g_mep_config) {
- config_sdn = slapi_sdn_new_dn_byref(((struct configEntry *)list)->template_dn);
+ config_sdn = ((struct configEntry *)list)->template_sdn;
if (slapi_sdn_compare(config_sdn, sdn) == 0) {
ret = 1;
- slapi_sdn_free(&config_sdn);
break;
} else {
list = PR_NEXT_LINK(list);
- slapi_sdn_free(&config_sdn);
}
}
}
- slapi_sdn_free(&sdn);
-
return ret;
}
@@ -968,32 +958,27 @@ mep_find_config(Slapi_Entry *e, struct configEntry **config)
* Returns NULL if no applicable config entry is found.
*/
static void
-mep_find_config_by_template_dn(const char *template_dn,
+mep_find_config_by_template_dn(Slapi_DN *template_sdn,
struct configEntry **config)
{
PRCList *list = NULL;
Slapi_DN *config_sdn = NULL;
- Slapi_DN *template_sdn = slapi_sdn_new_dn_byref(template_dn);
*config = NULL;
if (!PR_CLIST_IS_EMPTY(g_mep_config)) {
list = PR_LIST_HEAD(g_mep_config);
while (list != g_mep_config) {
- config_sdn = slapi_sdn_new_dn_byref(((struct configEntry *)list)->template_dn);
+ config_sdn = ((struct configEntry *)list)->template_sdn;
if (slapi_sdn_compare(config_sdn, template_sdn) == 0) {
*config = (struct configEntry *)list;
- slapi_sdn_free(&config_sdn);
break;
} else {
list = PR_NEXT_LINK(list);
- slapi_sdn_free(&config_sdn);
}
}
}
-
- slapi_sdn_free(&template_sdn);
}
/*
@@ -1085,7 +1070,7 @@ mep_create_managed_entry(struct configEntry *config, Slapi_Entry *origin)
slapi_log_error( SLAPI_LOG_FATAL, MEP_PLUGIN_SUBSYSTEM,
"mep_create_managed_entry: The %s config attribute "
"was not found in template \"%s\". This attribute "
- "is required.\n", MEP_RDN_ATTR_TYPE, config->template_dn);
+ "is required.\n", MEP_RDN_ATTR_TYPE, slapi_sdn_get_dn(config->template_sdn));
err = 1;
goto done;
}
@@ -1105,7 +1090,7 @@ mep_create_managed_entry(struct configEntry *config, Slapi_Entry *origin)
"mep_create_managed_entry: Value for %s config setting "
"is not in the correct format in template \"%s\". "
"(value: \"%s\")\n", MEP_STATIC_ATTR_TYPE,
- config->template_dn, vals[i]);
+ slapi_sdn_get_dn(config->template_sdn), vals[i]);
err = 1;
goto done;
} else {
@@ -1144,7 +1129,7 @@ mep_create_managed_entry(struct configEntry *config, Slapi_Entry *origin)
} else {
slapi_log_error( SLAPI_LOG_FATAL, MEP_PLUGIN_SUBSYSTEM,
"mep_create_managed_entry: Error parsing mapped attribute "
- "in template \"%s\".\n", config->template_dn);
+ "in template \"%s\".\n", slapi_sdn_get_dn(config->template_sdn));
err = 1;
goto done;
}
@@ -1157,7 +1142,7 @@ mep_create_managed_entry(struct configEntry *config, Slapi_Entry *origin)
"mep_create_managed_entry: The RDN type \"%s\" "
"was not found as a mapped attribute in template "
"\"%s\". It must be a mapped attribute.\n",
- rdn_type, config->template_dn);
+ rdn_type, slapi_sdn_get_dn(config->template_sdn));
err = 1;
goto done;
} else {
@@ -1183,7 +1168,7 @@ mep_create_managed_entry(struct configEntry *config, Slapi_Entry *origin)
"mep_create_managed_entry: Error setting DN "
"in managed entry based off of template entry "
"\"%s\" (origin entry \"%s\").\n",
- config->template_dn,
+ slapi_sdn_get_dn(config->template_sdn),
origin ? slapi_entry_get_dn(origin) : "NULL");
err = 1;
goto done;
@@ -1232,13 +1217,13 @@ mep_add_managed_entry(struct configEntry *config,
"mep_add_managed_entry: Creating a managed "
"entry from origin entry \"%s\" using "
"config \"%s\".\n", slapi_entry_get_dn(origin),
- config->dn);
+ slapi_sdn_get_dn(config->sdn));
managed_entry = mep_create_managed_entry(config, origin);
if (managed_entry == NULL) {
slapi_log_error(SLAPI_LOG_FATAL, MEP_PLUGIN_SUBSYSTEM,
"mep_add_managed_entry: Unable to create a managed "
"entry from origin entry \"%s\" using config "
- "\"%s\".\n", slapi_entry_get_dn(origin), config->dn);
+ "\"%s\".\n", slapi_entry_get_dn(origin), slapi_sdn_get_dn(config->sdn));
} else {
/* Copy the managed entry DN to use when
* creating the pointer attribute. */
@@ -1427,7 +1412,7 @@ static Slapi_Mods *mep_get_mapped_mods(struct configEntry *config,
if ((rdn_type = slapi_entry_attr_get_charptr(template, MEP_RDN_ATTR_TYPE)) == NULL) {
slapi_log_error( SLAPI_LOG_FATAL, MEP_PLUGIN_SUBSYSTEM,
"mep_get_mapped_mods: Error getting RDN type from tempate "
- "\"%s\".\n", config->template_dn);
+ "\"%s\".\n", slapi_sdn_get_dn(config->template_sdn));
slapi_mods_free(&smods);
goto bail;
}
@@ -1453,7 +1438,7 @@ static Slapi_Mods *mep_get_mapped_mods(struct configEntry *config,
} else {
slapi_log_error( SLAPI_LOG_FATAL, MEP_PLUGIN_SUBSYSTEM,
"mep_get_mapped_mods: Error parsing mapped attribute "
- "in template \"%s\".\n", config->template_dn);
+ "in template \"%s\".\n", slapi_sdn_get_dn(config->template_sdn));
slapi_mods_free(&smods);
goto bail;
}
@@ -1840,7 +1825,9 @@ mep_pre_op(Slapi_PBlock * pb, int modop)
* to let the main server handle it. */
goto bailmod;
}
-
+ } else if (LDAP_CHANGETYPE_DELETE == modop){
+ /* we allow for deletes, so goto bail to we can skip the config parsing */
+ goto bail;
} else {
/* Refuse other operations. */
ret = LDAP_UNWILLING_TO_PERFORM;
@@ -1868,7 +1855,7 @@ mep_pre_op(Slapi_PBlock * pb, int modop)
goto bail;
}
- mep_find_config_by_template_dn(slapi_sdn_get_dn(sdn), &config);
+ mep_find_config_by_template_dn(sdn, &config);
if (config) {
Slapi_Entry *test_entry = NULL;
struct configEntry *config_copy = NULL;
@@ -1876,9 +1863,9 @@ mep_pre_op(Slapi_PBlock * pb, int modop)
config_copy = (struct configEntry *)slapi_ch_calloc(1, sizeof(struct configEntry));
/* Make a temporary copy of the config to use for validation. */
- config_copy->dn = slapi_ch_strdup(config->dn);
+ config_copy->sdn = slapi_sdn_dup(config->sdn);
config_copy->managed_base = slapi_ch_strdup(config->managed_base);
- config_copy->template_dn = slapi_ch_strdup(config->template_dn);
+ config_copy->template_sdn = slapi_sdn_dup(config->template_sdn);
/* Reject attempts to delete or rename an active template.
* Validate changes to an active template. */
@@ -2122,7 +2109,7 @@ mep_mod_post_op(Slapi_PBlock *pb)
slapi_pblock_get(pb, SLAPI_TXN, &txn);
if (mep_oktodo(pb) && (sdn = mep_get_sdn(pb))) {
/* First check if the config or a template is being modified. */
- if (mep_dn_is_config(sdn) || mep_dn_is_template(slapi_sdn_get_dn(sdn))) {
+ if (mep_dn_is_config(sdn) || mep_dn_is_template(sdn)) {
mep_load_config(pb);
}
diff --git a/ldap/servers/plugins/mep/mep.h b/ldap/servers/plugins/mep/mep.h
index e2e680c..8338a7d 100644
--- a/ldap/servers/plugins/mep/mep.h
+++ b/ldap/servers/plugins/mep/mep.h
@@ -99,11 +99,11 @@
*/
struct configEntry {
PRCList list;
- char *dn;
+ Slapi_DN *sdn;
char *origin_scope;
Slapi_Filter *origin_filter;
char *managed_base;
- char *template_dn;
+ Slapi_DN *template_sdn;
Slapi_Entry *template_entry;
};
11 years, 11 months
2 commits - ldap/servers VERSION.sh
by Richard Allen Megginson
VERSION.sh | 2
ldap/servers/plugins/acctpolicy/acct_plugin.c | 19 +-
ldap/servers/plugins/acctpolicy/acct_util.c | 6
ldap/servers/plugins/acctpolicy/acctpolicy.h | 2
ldap/servers/plugins/automember/automember.c | 130 ++++++++++++-----
ldap/servers/plugins/deref/deref.c | 4
ldap/servers/plugins/dna/dna.c | 170 ++++++++++++++--------
ldap/servers/plugins/linkedattrs/fixup_task.c | 44 ++++-
ldap/servers/plugins/linkedattrs/linked_attrs.c | 132 ++++++++++++-----
ldap/servers/plugins/mep/mep.c | 172 +++++++++++++++--------
ldap/servers/plugins/replication/urp.c | 60 +++++---
ldap/servers/plugins/replication/urp.h | 10 -
ldap/servers/plugins/replication/urp_glue.c | 12 -
ldap/servers/plugins/replication/urp_tombstone.c | 14 +
ldap/servers/plugins/retrocl/retrocl_po.c | 4
ldap/servers/plugins/uiduniq/plugin-utils.h | 6
ldap/servers/plugins/uiduniq/uid.c | 43 +++--
ldap/servers/plugins/uiduniq/utils.c | 29 ++-
ldap/servers/slapd/modify.c | 4
ldap/servers/slapd/passwd_extop.c | 4
ldap/servers/slapd/proto-slap.h | 1
ldap/servers/slapd/pw.c | 11 +
ldap/servers/slapd/pw_mgmt.c | 16 +-
ldap/servers/slapd/pw_retry.c | 26 ++-
24 files changed, 618 insertions(+), 303 deletions(-)
New commits:
commit 77fdecc3a2bf6d9ce8e545ba0746f619fb14ce84
Author: Rich Megginson <rmeggins(a)redhat.com>
Date: Wed Jan 11 15:04:05 2012 -0700
Ticket #167 - Mixing transaction and non-transaction plugins can cause deadlock
https://fedorahosted.org/389/ticket/167
Resolves: Ticket #167
Bug Description: Mixing transaction and non-transaction plugins can cause deadlock
Reviewed by: nhosoi (Thanks!)
Branch: master
Fix Description: Make all code that uses internal database operations be
transaction aware. This excludes code that works exclusively on the
config DSEs such as cn=schema or cn=config. This also excludes code in
a couple of areas, because of difficulty in passing in the txn handle:
1) views_entry_exists Slapi APIB functions
2) acllas.c code that does internal searching
3) cos_cache_follow_pointer()
Also allow dna, linkedattrs, automember, and mep to run as betxn plugins by
configuring the plugin config entry in the dse
Platforms tested: RHEL6 x86_64, Fedora 16
Flag Day: no
Doc impact: no
diff --git a/ldap/servers/plugins/acctpolicy/acct_plugin.c b/ldap/servers/plugins/acctpolicy/acct_plugin.c
index 5969bec..9c74278 100644
--- a/ldap/servers/plugins/acctpolicy/acct_plugin.c
+++ b/ldap/servers/plugins/acctpolicy/acct_plugin.c
@@ -90,7 +90,7 @@ done:
with the current time.
*/
static int
-acct_record_login( const char *dn )
+acct_record_login( const char *dn, void *txn )
{
int ldrc;
int rc = 0; /* Optimistic default */
@@ -125,6 +125,7 @@ acct_record_login( const char *dn )
slapi_modify_internal_set_pb( modpb, dn, mods, NULL, NULL,
plugin_id, SLAPI_OP_FLAG_NO_ACCESS_CHECK |
SLAPI_OP_FLAG_BYPASS_REFERRALS );
+ slapi_pblock_set( modpb, SLAPI_TXN, txn );
slapi_modify_internal_pb( modpb );
slapi_pblock_get( modpb, SLAPI_PLUGIN_INTOP_RESULT, &ldrc );
@@ -160,6 +161,7 @@ acct_bind_preop( Slapi_PBlock *pb )
int ldrc;
acctPolicy *policy = NULL;
void *plugin_id;
+ void *txn = NULL;
slapi_log_error( SLAPI_LOG_PLUGIN, PRE_PLUGIN_NAME,
"=> acct_bind_preop\n" );
@@ -180,8 +182,9 @@ acct_bind_preop( Slapi_PBlock *pb )
goto done;
}
- ldrc = slapi_search_internal_get_entry( sdn, NULL, &target_entry,
- plugin_id );
+ slapi_pblock_get(pb, SLAPI_TXN, &txn);
+ ldrc = slapi_search_internal_get_entry_ext( sdn, NULL, &target_entry,
+ plugin_id, txn );
/* There was a problem retrieving the entry */
if( ldrc != LDAP_SUCCESS ) {
@@ -194,7 +197,7 @@ acct_bind_preop( Slapi_PBlock *pb )
goto done;
}
- if( get_acctpolicy( pb, target_entry, plugin_id, &policy ) ) {
+ if( get_acctpolicy( pb, target_entry, plugin_id, &policy, txn ) ) {
slapi_log_error( SLAPI_LOG_FATAL, PRE_PLUGIN_NAME,
"Account Policy object for \"%s\" is missing\n", dn );
rc = -1;
@@ -244,6 +247,7 @@ acct_bind_postop( Slapi_PBlock *pb )
Slapi_Entry *target_entry = NULL;
acctPluginCfg *cfg;
void *plugin_id;
+ void *txn = NULL;
slapi_log_error( SLAPI_LOG_PLUGIN, POST_PLUGIN_NAME,
"=> acct_bind_postop\n" );
@@ -263,6 +267,7 @@ acct_bind_postop( Slapi_PBlock *pb )
goto done;
}
+ slapi_pblock_get(pb, SLAPI_TXN, &txn);
cfg = get_config();
tracklogin = cfg->always_record_login;
@@ -270,8 +275,8 @@ acct_bind_postop( Slapi_PBlock *pb )
covered by an account policy to decide whether we should track */
if( tracklogin == 0 ) {
sdn = slapi_sdn_new_dn_byref( dn );
- ldrc = slapi_search_internal_get_entry( sdn, NULL, &target_entry,
- plugin_id );
+ ldrc = slapi_search_internal_get_entry_ext( sdn, NULL, &target_entry,
+ plugin_id, txn );
if( ldrc != LDAP_SUCCESS ) {
slapi_log_error( SLAPI_LOG_FATAL, POST_PLUGIN_NAME,
@@ -288,7 +293,7 @@ acct_bind_postop( Slapi_PBlock *pb )
}
if( tracklogin ) {
- rc = acct_record_login( dn );
+ rc = acct_record_login( dn, txn );
}
/* ...Any additional account policy postops go here... */
diff --git a/ldap/servers/plugins/acctpolicy/acct_util.c b/ldap/servers/plugins/acctpolicy/acct_util.c
index 8e220c3..c421746 100644
--- a/ldap/servers/plugins/acctpolicy/acct_util.c
+++ b/ldap/servers/plugins/acctpolicy/acct_util.c
@@ -78,7 +78,7 @@ get_attr_string_val( Slapi_Entry* target_entry, char* attr_name ) {
*/
int
get_acctpolicy( Slapi_PBlock *pb, Slapi_Entry *target_entry, void *plugin_id,
- acctPolicy **policy ) {
+ acctPolicy **policy, void *txn ) {
Slapi_DN *sdn = NULL;
Slapi_Entry *policy_entry = NULL;
Slapi_Attr *attr;
@@ -114,8 +114,8 @@ get_acctpolicy( Slapi_PBlock *pb, Slapi_Entry *target_entry, void *plugin_id,
}
sdn = slapi_sdn_new_dn_byref( policy_dn );
- ldrc = slapi_search_internal_get_entry( sdn, NULL, &policy_entry,
- plugin_id );
+ ldrc = slapi_search_internal_get_entry_ext( sdn, NULL, &policy_entry,
+ plugin_id, txn );
slapi_sdn_free( &sdn );
/* There should be a policy but it can't be retrieved; fatal error */
diff --git a/ldap/servers/plugins/acctpolicy/acctpolicy.h b/ldap/servers/plugins/acctpolicy/acctpolicy.h
index e6f1497..0064009 100644
--- a/ldap/servers/plugins/acctpolicy/acctpolicy.h
+++ b/ldap/servers/plugins/acctpolicy/acctpolicy.h
@@ -65,7 +65,7 @@ typedef struct accountpolicy {
/* acct_util.c */
int get_acctpolicy( Slapi_PBlock *pb, Slapi_Entry *target_entry,
- void *plugin_id, acctPolicy **policy );
+ void *plugin_id, acctPolicy **policy, void *txn );
void free_acctpolicy( acctPolicy **policy );
int has_attr( Slapi_Entry* target_entry, char* attr_name,
char** val );
diff --git a/ldap/servers/plugins/automember/automember.c b/ldap/servers/plugins/automember/automember.c
index 1195a15..c5e5667 100644
--- a/ldap/servers/plugins/automember/automember.c
+++ b/ldap/servers/plugins/automember/automember.c
@@ -84,9 +84,9 @@ static int automember_add_pre_op(Slapi_PBlock *pb);
/*
* Config cache management functions
*/
-static int automember_load_config();
+static int automember_load_config(Slapi_PBlock *pb);
static void automember_delete_config();
-static int automember_parse_config_entry(Slapi_Entry * e, int apply);
+static int automember_parse_config_entry(Slapi_Entry * e, int apply, Slapi_PBlock *pb);
static void automember_free_config_entry(struct configEntry ** entry);
/*
@@ -103,9 +103,9 @@ static struct automemberRegexRule *automember_parse_regex_rule(char *rule_string
static void automember_free_regex_rule(struct automemberRegexRule *rule);
static int automember_parse_grouping_attr(char *value, char **grouping_attr,
char **grouping_value);
-static void automember_update_membership(struct configEntry *config, Slapi_Entry *e);
+static void automember_update_membership(struct configEntry *config, Slapi_Entry *e, void *txn);
static void automember_add_member_value(Slapi_Entry *member_e, const char *group_dn,
- char *grouping_attr, char *grouping_value);
+ char *grouping_attr, char *grouping_value, void *txn);
/*
* Config cache locking functions
@@ -156,6 +156,7 @@ automember_get_plugin_sdn()
return _PluginDN;
}
+static int plugin_is_betxn = 0;
/*
* Plug-in initialization functions
@@ -165,10 +166,25 @@ automember_init(Slapi_PBlock *pb)
{
int status = 0;
char *plugin_identity = NULL;
+ Slapi_Entry *plugin_entry = NULL;
+ char *plugin_type = NULL;
+ int preadd = SLAPI_PLUGIN_PRE_ADD_FN;
+ int premod = SLAPI_PLUGIN_PRE_MODIFY_FN;
slapi_log_error(SLAPI_LOG_TRACE, AUTOMEMBER_PLUGIN_SUBSYSTEM,
"--> automember_init\n");
+ /* get args */
+ if ((slapi_pblock_get(pb, SLAPI_PLUGIN_CONFIG_ENTRY, &plugin_entry) == 0) &&
+ plugin_entry &&
+ (plugin_type = slapi_entry_attr_get_charptr(plugin_entry, "nsslapd-plugintype")) &&
+ plugin_type && strstr(plugin_type, "betxn")) {
+ plugin_is_betxn = 1;
+ preadd = SLAPI_PLUGIN_BE_TXN_PRE_ADD_FN;
+ premod = SLAPI_PLUGIN_BE_TXN_PRE_MODIFY_FN;
+ }
+ slapi_ch_free_string(&plugin_type);
+
/* Store the plugin identity for later use.
* Used for internal operations. */
slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &plugin_identity);
@@ -184,10 +200,14 @@ automember_init(Slapi_PBlock *pb)
(void *) automember_close) != 0 ||
slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION,
(void *) &pdesc) != 0 ||
- slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_MODIFY_FN,
- (void *) automember_mod_pre_op) != 0 ||
- slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_ADD_FN,
- (void *) automember_add_pre_op) != 0 ||
+ slapi_pblock_set(pb, premod, (void *) automember_mod_pre_op) != 0 ||
+ slapi_pblock_set(pb, preadd, (void *) automember_add_pre_op) != 0) {
+ slapi_log_error(SLAPI_LOG_FATAL, AUTOMEMBER_PLUGIN_SUBSYSTEM,
+ "automember_init: failed to register plugin\n");
+ status = -1;
+ }
+
+ if (!plugin_is_betxn && !status &&
slapi_register_plugin("internalpostoperation", /* op type */
1, /* Enabled */
"automember_init", /* this function desc */
@@ -195,19 +215,30 @@ automember_init(Slapi_PBlock *pb)
AUTOMEMBER_INT_POSTOP_DESC, /* plugin desc */
NULL, /* ? */
plugin_identity /* access control */
- ) ||
- slapi_register_plugin("postoperation", /* op type */
- 1, /* Enabled */
- "automember_init", /* this function desc */
- automember_postop_init, /* init func for post op */
- AUTOMEMBER_POSTOP_DESC, /* plugin desc */
- NULL, /* ? */
- plugin_identity /* access control */
+ )) {
+ slapi_log_error(SLAPI_LOG_FATAL, AUTOMEMBER_PLUGIN_SUBSYSTEM,
+ "automember_init: failed to register internalpostoperation plugin\n");
+ status = -1;
+ }
+
+ if (!status) {
+ plugin_type = "postoperation";
+ if (plugin_is_betxn) {
+ plugin_type = "betxnpostoperation";
+ }
+ if (slapi_register_plugin(plugin_type, /* op type */
+ 1, /* Enabled */
+ "automember_init", /* this function desc */
+ automember_postop_init, /* init func for post op */
+ AUTOMEMBER_POSTOP_DESC, /* plugin desc */
+ NULL, /* ? */
+ plugin_identity /* access control */
)
) {
slapi_log_error(SLAPI_LOG_FATAL, AUTOMEMBER_PLUGIN_SUBSYSTEM,
- "automember_init: failed to register plugin\n");
+ "automember_init: failed to register postop plugin\n");
status = -1;
+ }
}
slapi_log_error(SLAPI_LOG_TRACE, AUTOMEMBER_PLUGIN_SUBSYSTEM,
@@ -215,6 +246,7 @@ automember_init(Slapi_PBlock *pb)
return status;
}
+/* not used when using plugin as a betxn plugin - betxn plugins are called for both internal and external ops */
static int
automember_internal_postop_init(Slapi_PBlock *pb)
{
@@ -244,19 +276,26 @@ static int
automember_postop_init(Slapi_PBlock *pb)
{
int status = 0;
+ int addfn = SLAPI_PLUGIN_POST_ADD_FN;
+ int delfn = SLAPI_PLUGIN_POST_DELETE_FN;
+ int modfn = SLAPI_PLUGIN_POST_MODIFY_FN;
+ int mdnfn = SLAPI_PLUGIN_POST_MODRDN_FN;
+
+ if (plugin_is_betxn) {
+ addfn = SLAPI_PLUGIN_BE_TXN_POST_ADD_FN;
+ delfn = SLAPI_PLUGIN_BE_TXN_POST_DELETE_FN;
+ modfn = SLAPI_PLUGIN_BE_TXN_POST_MODIFY_FN;
+ mdnfn = SLAPI_PLUGIN_BE_TXN_POST_MODRDN_FN;
+ }
if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION,
SLAPI_PLUGIN_VERSION_01) != 0 ||
slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION,
(void *) &pdesc) != 0 ||
- slapi_pblock_set(pb, SLAPI_PLUGIN_POST_ADD_FN,
- (void *) automember_add_post_op) != 0 ||
- slapi_pblock_set(pb, SLAPI_PLUGIN_POST_DELETE_FN,
- (void *) automember_del_post_op) != 0 ||
- slapi_pblock_set(pb, SLAPI_PLUGIN_POST_MODIFY_FN,
- (void *) automember_mod_post_op) != 0 ||
- slapi_pblock_set(pb, SLAPI_PLUGIN_POST_MODRDN_FN,
- (void *) automember_modrdn_post_op) != 0) {
+ slapi_pblock_set(pb, addfn, (void *) automember_add_post_op) != 0 ||
+ slapi_pblock_set(pb, delfn, (void *) automember_del_post_op) != 0 ||
+ slapi_pblock_set(pb, modfn, (void *) automember_mod_post_op) != 0 ||
+ slapi_pblock_set(pb, mdnfn, (void *) automember_modrdn_post_op) != 0) {
slapi_log_error(SLAPI_LOG_FATAL, AUTOMEMBER_PLUGIN_SUBSYSTEM,
"automember_postop_init: failed to register plugin\n");
status = -1;
@@ -319,7 +358,7 @@ automember_start(Slapi_PBlock * pb)
g_automember_config = (PRCList *)slapi_ch_calloc(1, sizeof(struct configEntry));
PR_INIT_CLIST(g_automember_config);
- if (automember_load_config() != 0) {
+ if (automember_load_config(pb) != 0) {
slapi_log_error(SLAPI_LOG_FATAL, AUTOMEMBER_PLUGIN_SUBSYSTEM,
"automember_start: unable to load plug-in configuration\n");
return -1;
@@ -391,13 +430,14 @@ automember_get_config()
* Parse and load the config entries.
*/
static int
-automember_load_config()
+automember_load_config(Slapi_PBlock *pb)
{
int status = 0;
int result;
int i;
Slapi_PBlock *search_pb;
Slapi_Entry **entries = NULL;
+ void *txn = NULL;
slapi_log_error(SLAPI_LOG_TRACE, AUTOMEMBER_PLUGIN_SUBSYSTEM,
"--> automember_load_config\n");
@@ -406,6 +446,7 @@ automember_load_config()
automember_config_write_lock();
automember_delete_config();
+ slapi_pblock_get(pb, SLAPI_TXN, &txn);
search_pb = slapi_pblock_new();
/* If an alternate config area is configured, find
@@ -432,6 +473,7 @@ automember_load_config()
NULL, 0, NULL, NULL, automember_get_plugin_id(), 0);
}
+ slapi_pblock_set(search_pb, SLAPI_TXN, txn);
slapi_search_internal_pb(search_pb);
slapi_pblock_get(search_pb, SLAPI_PLUGIN_INTOP_RESULT, &result);
@@ -458,7 +500,7 @@ automember_load_config()
/* We don't care about the status here because we may have
* some invalid config entries, but we just want to continue
* looking for valid ones. */
- automember_parse_config_entry(entries[i], 1);
+ automember_parse_config_entry(entries[i], 1, pb);
}
cleanup:
@@ -482,7 +524,7 @@ automember_load_config()
* Returns 0 if the entry is valid and -1 if it is invalid.
*/
static int
-automember_parse_config_entry(Slapi_Entry * e, int apply)
+automember_parse_config_entry(Slapi_Entry * e, int apply, Slapi_PBlock *pb)
{
char *value = NULL;
char **values = NULL;
@@ -497,6 +539,7 @@ automember_parse_config_entry(Slapi_Entry * e, int apply)
int entry_added = 0;
int i = 0;
int ret = 0;
+ void *txn = NULL;
slapi_log_error(SLAPI_LOG_TRACE, AUTOMEMBER_PLUGIN_SUBSYSTEM,
"--> automember_parse_config_entry\n");
@@ -529,6 +572,7 @@ automember_parse_config_entry(Slapi_Entry * e, int apply)
goto bail;
}
+ slapi_pblock_get(pb, SLAPI_TXN, &txn);
value = slapi_entry_get_ndn(e);
if (value) {
entry->dn = slapi_ch_strdup(value);
@@ -621,6 +665,7 @@ automember_parse_config_entry(Slapi_Entry * e, int apply)
slapi_search_internal_set_pb(search_pb, entry->dn, LDAP_SCOPE_SUBTREE,
AUTOMEMBER_REGEX_RULE_FILTER, NULL, 0, NULL,
NULL, automember_get_plugin_id(), 0);
+ slapi_pblock_set(search_pb, SLAPI_TXN, txn);
slapi_search_internal_pb(search_pb);
slapi_pblock_get(search_pb, SLAPI_PLUGIN_INTOP_RESULT, &result);
@@ -1302,7 +1347,7 @@ automember_parse_grouping_attr(char *value, char **grouping_attr, char **groupin
* the rules in config, then performs the updates.
*/
static void
-automember_update_membership(struct configEntry *config, Slapi_Entry *e)
+automember_update_membership(struct configEntry *config, Slapi_Entry *e, void *txn)
{
PRCList *rule = NULL;
struct automemberRegexRule *curr_rule = NULL;
@@ -1456,14 +1501,14 @@ automember_update_membership(struct configEntry *config, Slapi_Entry *e)
/* Add to each default group. */
for (i = 0; config->default_groups && config->default_groups[i]; i++) {
automember_add_member_value(e, config->default_groups[i],
- config->grouping_attr, config->grouping_value);
+ config->grouping_attr, config->grouping_value, txn);
}
} else {
/* Update the target groups. */
dnitem = (struct automemberDNListItem *)PR_LIST_HEAD(&targets);
while ((PRCList *)dnitem != &targets) {
automember_add_member_value(e, slapi_sdn_get_dn(dnitem->dn),
- config->grouping_attr, config->grouping_value);
+ config->grouping_attr, config->grouping_value, txn);
dnitem = (struct automemberDNListItem *)PR_NEXT_LINK((PRCList *)dnitem);
}
}
@@ -1491,7 +1536,7 @@ automember_update_membership(struct configEntry *config, Slapi_Entry *e)
*/
static void
automember_add_member_value(Slapi_Entry *member_e, const char *group_dn,
- char *grouping_attr, char *grouping_value)
+ char *grouping_attr, char *grouping_value, void *txn)
{
Slapi_PBlock *mod_pb = slapi_pblock_new();
int result = LDAP_SUCCESS;
@@ -1527,6 +1572,7 @@ automember_add_member_value(Slapi_Entry *member_e, const char *group_dn,
slapi_modify_internal_set_pb(mod_pb, group_dn,
mods, 0, 0, automember_get_plugin_id(), 0);
+ slapi_pblock_set(mod_pb, SLAPI_TXN, txn);
slapi_modify_internal_pb(mod_pb);
slapi_pblock_get(mod_pb, SLAPI_PLUGIN_INTOP_RESULT, &result);
@@ -1573,6 +1619,7 @@ automember_pre_op(Slapi_PBlock * pb, int modop)
int free_entry = 0;
char *errstr = NULL;
int ret = 0;
+ void *txn = NULL;
slapi_log_error(SLAPI_LOG_TRACE, AUTOMEMBER_PLUGIN_SUBSYSTEM,
"--> automember_pre_op\n");
@@ -1584,6 +1631,7 @@ automember_pre_op(Slapi_PBlock * pb, int modop)
if (0 == (sdn = automember_get_sdn(pb)))
goto bail;
+ slapi_pblock_get(pb, SLAPI_TXN, &txn);
if (automember_dn_is_config(sdn)) {
/* Validate config changes, but don't apply them.
* This allows us to reject invalid config changes
@@ -1602,7 +1650,7 @@ automember_pre_op(Slapi_PBlock * pb, int modop)
/* Fetch the entry being modified so we can
* create the resulting entry for validation. */
if (sdn) {
- slapi_search_internal_get_entry(sdn, 0, &e, automember_get_plugin_id());
+ slapi_search_internal_get_entry_ext(sdn, 0, &e, automember_get_plugin_id(), txn);
free_entry = 1;
}
@@ -1630,7 +1678,7 @@ automember_pre_op(Slapi_PBlock * pb, int modop)
goto bail;
}
- if (automember_parse_config_entry(e, 0) != 0) {
+ if (automember_parse_config_entry(e, 0, pb) != 0) {
/* Refuse the operation if config parsing failed. */
ret = LDAP_UNWILLING_TO_PERFORM;
if (LDAP_CHANGETYPE_ADD == modop) {
@@ -1700,7 +1748,7 @@ automember_mod_post_op(Slapi_PBlock *pb)
if (automember_oktodo(pb) && (sdn = automember_get_sdn(pb))) {
/* Check if the config is being modified and reload if so. */
if (automember_dn_is_config(sdn)) {
- automember_load_config();
+ automember_load_config(pb);
}
}
@@ -1718,6 +1766,7 @@ automember_add_post_op(Slapi_PBlock *pb)
Slapi_DN *sdn = NULL;
struct configEntry *config = NULL;
PRCList *list = NULL;
+ void *txn = NULL;
slapi_log_error(SLAPI_LOG_TRACE, AUTOMEMBER_PLUGIN_SUBSYSTEM,
"--> automember_add_post_op\n");
@@ -1729,7 +1778,7 @@ automember_add_post_op(Slapi_PBlock *pb)
/* Reload config if a config entry was added. */
if ((sdn = automember_get_sdn(pb))) {
if (automember_dn_is_config(sdn)) {
- automember_load_config();
+ automember_load_config(pb);
}
} else {
slapi_log_error(SLAPI_LOG_PLUGIN, AUTOMEMBER_PLUGIN_SUBSYSTEM,
@@ -1743,6 +1792,7 @@ automember_add_post_op(Slapi_PBlock *pb)
return 0;
}
+ slapi_pblock_get(pb, SLAPI_TXN, &txn);
/* Get the newly added entry. */
slapi_pblock_get(pb, SLAPI_ENTRY_POST_OP, &e);
@@ -1776,7 +1826,7 @@ automember_add_post_op(Slapi_PBlock *pb)
if (slapi_dn_issuffix(slapi_sdn_get_dn(sdn), config->scope) &&
(slapi_filter_test_simple(e, config->filter) == 0)) {
/* Find out what membership changes are needed and make them. */
- automember_update_membership(config, e);
+ automember_update_membership(config, e, txn);
}
list = PR_NEXT_LINK(list);
@@ -1817,7 +1867,7 @@ automember_del_post_op(Slapi_PBlock *pb)
/* Reload config if a config entry was deleted. */
if ((sdn = automember_get_sdn(pb))) {
if (automember_dn_is_config(sdn))
- automember_load_config();
+ automember_load_config(pb);
} else {
slapi_log_error(SLAPI_LOG_PLUGIN, AUTOMEMBER_PLUGIN_SUBSYSTEM,
"automember_del_post_op: Error "
@@ -1865,7 +1915,7 @@ automember_modrdn_post_op(Slapi_PBlock *pb)
if ((old_sdn = automember_get_sdn(pb))) {
if (automember_dn_is_config(old_sdn) || automember_dn_is_config(new_sdn))
- automember_load_config();
+ automember_load_config(pb);
} else {
slapi_log_error(SLAPI_LOG_PLUGIN, AUTOMEMBER_PLUGIN_SUBSYSTEM,
"automember_modrdn_post_op: Error "
diff --git a/ldap/servers/plugins/deref/deref.c b/ldap/servers/plugins/deref/deref.c
index fb6a54a..86055b2 100644
--- a/ldap/servers/plugins/deref/deref.c
+++ b/ldap/servers/plugins/deref/deref.c
@@ -594,6 +594,7 @@ deref_do_deref_attr(Slapi_PBlock *pb, BerElement *ctrlber, const char *derefdn,
Slapi_PBlock *derefpb = NULL;
Slapi_Entry **entries = NULL;
int rc;
+ void *txn = NULL;
if (deref_check_access(pb, NULL, derefdn, attrs, &retattrs,
(SLAPI_ACL_SEARCH|SLAPI_ACL_READ))) {
@@ -604,10 +605,11 @@ deref_do_deref_attr(Slapi_PBlock *pb, BerElement *ctrlber, const char *derefdn,
}
derefpb = slapi_pblock_new();
+ slapi_pblock_get(pb, SLAPI_TXN, &txn);
slapi_search_internal_set_pb(derefpb, derefdn, LDAP_SCOPE_BASE,
"(objectclass=*)", retattrs, 0,
NULL, NULL, deref_get_plugin_id(), 0);
-
+ slapi_pblock_set(derefpb, SLAPI_TXN, txn);
slapi_search_internal_pb(derefpb);
slapi_pblock_get(derefpb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
if (LDAP_SUCCESS == rc) {
diff --git a/ldap/servers/plugins/dna/dna.c b/ldap/servers/plugins/dna/dna.c
index 858a0d7..32b6d11 100644
--- a/ldap/servers/plugins/dna/dna.c
+++ b/ldap/servers/plugins/dna/dna.c
@@ -230,15 +230,15 @@ static char *dna_get_dn(Slapi_PBlock * pb);
static Slapi_DN *dna_get_sdn(Slapi_PBlock * pb);
static int dna_dn_is_config(char *dn);
static int dna_get_next_value(struct configEntry * config_entry,
- char **next_value_ret);
+ char **next_value_ret, void *txn);
static int dna_first_free_value(struct configEntry *config_entry,
- PRUint64 *newval);
-static int dna_fix_maxval(struct configEntry *config_entry);
+ PRUint64 *newval, void *txn);
+static int dna_fix_maxval(struct configEntry *config_entry, void *txn);
static void dna_notice_allocation(struct configEntry *config_entry,
- PRUint64 new, PRUint64 last, int fix);
-static int dna_update_shared_config(struct configEntry * config_entry);
+ PRUint64 new, PRUint64 last, int fix, void *txn);
+static int dna_update_shared_config(struct configEntry * config_entry, void *txn);
static void dna_update_config_event(time_t event_time, void *arg);
-static int dna_get_shared_servers(struct configEntry *config_entry, PRCList **servers);
+static int dna_get_shared_servers(struct configEntry *config_entry, PRCList **servers, void *txn);
static void dna_free_shared_server(struct dnaServer **server);
static void dna_delete_shared_servers(PRCList **servers);
static int dna_release_range(char *range_dn, PRUint64 *lower, PRUint64 *upper);
@@ -247,8 +247,8 @@ static int dna_request_range(struct configEntry *config_entry,
PRUint64 *lower, PRUint64 *upper);
static struct berval *dna_create_range_request(char *range_dn);
static int dna_update_next_range(struct configEntry *config_entry,
- PRUint64 lower, PRUint64 upper);
-static int dna_activate_next_range(struct configEntry *config_entry);
+ PRUint64 lower, PRUint64 upper, void *txn);
+static int dna_activate_next_range(struct configEntry *config_entry, void *txn);
static int dna_is_replica_bind_dn(char *range_dn, char *bind_dn);
static int dna_get_replica_bind_creds(char *range_dn, struct dnaServer *server,
char **bind_dn, char **bind_passwd,
@@ -341,6 +341,8 @@ const char *getPluginDN()
return _PluginDN;
}
+static int plugin_is_betxn = 0;
+
/*
dna_init
-------------
@@ -351,11 +353,25 @@ dna_init(Slapi_PBlock *pb)
{
int status = DNA_SUCCESS;
char *plugin_identity = NULL;
+ Slapi_Entry *plugin_entry = NULL;
+ char *plugin_type = NULL;
+ int preadd = SLAPI_PLUGIN_PRE_ADD_FN;
+ int premod = SLAPI_PLUGIN_PRE_MODIFY_FN;
slapi_log_error(SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM,
"--> dna_init\n");
- /**
+ if ((slapi_pblock_get(pb, SLAPI_PLUGIN_CONFIG_ENTRY, &plugin_entry) == 0) &&
+ plugin_entry &&
+ (plugin_type = slapi_entry_attr_get_charptr(plugin_entry, "nsslapd-plugintype")) &&
+ plugin_type && strstr(plugin_type, "betxn")) {
+ plugin_is_betxn = 1;
+ preadd = SLAPI_PLUGIN_BE_TXN_PRE_ADD_FN;
+ premod = SLAPI_PLUGIN_BE_TXN_PRE_MODIFY_FN;
+ }
+ slapi_ch_free_string(&plugin_type);
+
+ /**
* Store the plugin identity for later use.
* Used for internal operations
*/
@@ -372,10 +388,14 @@ dna_init(Slapi_PBlock *pb)
(void *) dna_close) != 0 ||
slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION,
(void *) &pdesc) != 0 ||
- slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_MODIFY_FN,
- (void *) dna_mod_pre_op) != 0 ||
- slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_ADD_FN,
- (void *) dna_add_pre_op) != 0 ||
+ slapi_pblock_set(pb, premod, (void *) dna_mod_pre_op) != 0 ||
+ slapi_pblock_set(pb, preadd, (void *) dna_add_pre_op) != 0) {
+ slapi_log_error(SLAPI_LOG_FATAL, DNA_PLUGIN_SUBSYSTEM,
+ "dna_init: failed to register plugin\n");
+ status = DNA_FAILURE;
+ }
+
+ if ((status == DNA_SUCCESS) && !plugin_is_betxn &&
/* internal preoperation */
slapi_register_plugin("internalpreoperation", /* op type */
1, /* Enabled */
@@ -384,16 +404,32 @@ dna_init(Slapi_PBlock *pb)
DNA_INT_PREOP_DESC, /* plugin desc */
NULL, /* ? */
plugin_identity /* access control */
- ) ||
+ )) {
+ slapi_log_error(SLAPI_LOG_FATAL, DNA_PLUGIN_SUBSYSTEM,
+ "dna_init: failed to register internalpreoperation plugin\n");
+ status = DNA_FAILURE;
+ }
+ if (status == DNA_SUCCESS) {
+ plugin_type = "postoperation";
+ if (plugin_is_betxn) {
+ plugin_type = "betxnpostoperation";
+ }
/* the config change checking post op */
- slapi_register_plugin("postoperation", /* op type */
- 1, /* Enabled */
- "dna_init", /* this function desc */
- dna_postop_init, /* init func for post op */
- DNA_POSTOP_DESC, /* plugin desc */
- NULL, /* ? */
- plugin_identity /* access control */
- ) ||
+ if (slapi_register_plugin(plugin_type, /* op type */
+ 1, /* Enabled */
+ "dna_init", /* this function desc */
+ dna_postop_init, /* init func for post op */
+ DNA_POSTOP_DESC, /* plugin desc */
+ NULL, /* ? */
+ plugin_identity /* access control */
+ )) {
+ slapi_log_error(SLAPI_LOG_FATAL, DNA_PLUGIN_SUBSYSTEM,
+ "dna_init: failed to register postop plugin\n");
+ status = DNA_FAILURE;
+ }
+ }
+
+ if ((status == DNA_SUCCESS) &&
/* the range extension extended operation */
slapi_register_plugin("extendedop", /* op type */
1, /* Enabled */
@@ -414,6 +450,7 @@ dna_init(Slapi_PBlock *pb)
return status;
}
+/* not used when using plugin as a betxn plugin - betxn plugins are called for both internal and external ops */
static int
dna_internal_preop_init(Slapi_PBlock *pb)
{
@@ -437,19 +474,26 @@ static int
dna_postop_init(Slapi_PBlock *pb)
{
int status = DNA_SUCCESS;
+ int addfn = SLAPI_PLUGIN_POST_ADD_FN;
+ int delfn = SLAPI_PLUGIN_POST_DELETE_FN;
+ int modfn = SLAPI_PLUGIN_POST_MODIFY_FN;
+ int mdnfn = SLAPI_PLUGIN_POST_MODRDN_FN;
+
+ if (plugin_is_betxn) {
+ addfn = SLAPI_PLUGIN_BE_TXN_POST_ADD_FN;
+ delfn = SLAPI_PLUGIN_BE_TXN_POST_DELETE_FN;
+ modfn = SLAPI_PLUGIN_BE_TXN_POST_MODIFY_FN;
+ mdnfn = SLAPI_PLUGIN_BE_TXN_POST_MODRDN_FN;
+ }
if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION,
SLAPI_PLUGIN_VERSION_01) != 0 ||
slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION,
(void *) &pdesc) != 0 ||
- slapi_pblock_set(pb, SLAPI_PLUGIN_POST_ADD_FN,
- (void *) dna_config_check_post_op) != 0 ||
- slapi_pblock_set(pb, SLAPI_PLUGIN_POST_MODRDN_FN,
- (void *) dna_config_check_post_op) != 0 ||
- slapi_pblock_set(pb, SLAPI_PLUGIN_POST_DELETE_FN,
- (void *) dna_config_check_post_op) != 0 ||
- slapi_pblock_set(pb, SLAPI_PLUGIN_POST_MODIFY_FN,
- (void *) dna_config_check_post_op) != 0) {
+ slapi_pblock_set(pb, addfn, (void *) dna_config_check_post_op) != 0 ||
+ slapi_pblock_set(pb, mdnfn, (void *) dna_config_check_post_op) != 0 ||
+ slapi_pblock_set(pb, delfn, (void *) dna_config_check_post_op) != 0 ||
+ slapi_pblock_set(pb, modfn, (void *) dna_config_check_post_op) != 0) {
slapi_log_error(SLAPI_LOG_FATAL, DNA_PLUGIN_SUBSYSTEM,
"dna_postop_init: failed to register plugin\n");
status = DNA_FAILURE;
@@ -1263,7 +1307,7 @@ dna_update_config_event(time_t event_time, void *arg)
slapi_delete_internal_pb(pb);
/* Now force the entry to be recreated */
- dna_update_shared_config(config_entry);
+ dna_update_shared_config(config_entry, NULL);
slapi_unlock_mutex(config_entry->lock);
slapi_pblock_init(pb);
@@ -1291,7 +1335,7 @@ bail:
* The lock for configEntry should be obtained
* before calling this function.
*/
-static int dna_fix_maxval(struct configEntry *config_entry)
+static int dna_fix_maxval(struct configEntry *config_entry, void *txn)
{
PRCList *servers = NULL;
PRCList *server = NULL;
@@ -1306,7 +1350,7 @@ static int dna_fix_maxval(struct configEntry *config_entry)
/* If we already have a next range we only need
* to activate it. */
if (config_entry->next_range_lower != 0) {
- ret = dna_activate_next_range(config_entry);
+ ret = dna_activate_next_range(config_entry, txn);
if (ret != 0) {
slapi_log_error(SLAPI_LOG_FATAL, DNA_PLUGIN_SUBSYSTEM,
"dna_fix_maxval: Unable to activate the "
@@ -1315,7 +1359,7 @@ static int dna_fix_maxval(struct configEntry *config_entry)
} else if (config_entry->shared_cfg_base) {
/* Find out if there are any other servers to request
* range from. */
- dna_get_shared_servers(config_entry, &servers);
+ dna_get_shared_servers(config_entry, &servers, txn);
if (servers) {
/* We have other servers we can try to extend
@@ -1330,7 +1374,7 @@ static int dna_fix_maxval(struct configEntry *config_entry)
} else {
/* Someone provided us with a new range. Attempt
* to update the config. */
- if ((ret = dna_update_next_range(config_entry, lower, upper)) == 0) {
+ if ((ret = dna_update_next_range(config_entry, lower, upper, txn)) == 0) {
break;
}
}
@@ -1362,7 +1406,7 @@ bail:
* this function. */
static void
dna_notice_allocation(struct configEntry *config_entry, PRUint64 new,
- PRUint64 last, int fix)
+ PRUint64 last, int fix, void *txn)
{
/* update our cached config entry */
if ((new != 0) && (new <= (config_entry->maxval + config_entry->interval))) {
@@ -1376,7 +1420,7 @@ dna_notice_allocation(struct configEntry *config_entry, PRUint64 new,
* new active range. */
if (config_entry->next_range_lower != 0) {
/* Make the next range active */
- if (dna_activate_next_range(config_entry) != 0) {
+ if (dna_activate_next_range(config_entry, txn) != 0) {
slapi_log_error(SLAPI_LOG_FATAL, DNA_PLUGIN_SUBSYSTEM,
"dna_notice_allocation: Unable to activate "
"the next range for range %s.\n", config_entry->dn);
@@ -1384,7 +1428,7 @@ dna_notice_allocation(struct configEntry *config_entry, PRUint64 new,
} else {
config_entry->remaining = 0;
/* update the shared configuration */
- dna_update_shared_config(config_entry);
+ dna_update_shared_config(config_entry, txn);
}
} else {
if (config_entry->next_range_lower != 0) {
@@ -1397,7 +1441,7 @@ dna_notice_allocation(struct configEntry *config_entry, PRUint64 new,
}
/* update the shared configuration */
- dna_update_shared_config(config_entry);
+ dna_update_shared_config(config_entry, txn);
}
/* Check if we passed the threshold and try to fix maxval if so. We
@@ -1409,7 +1453,7 @@ dna_notice_allocation(struct configEntry *config_entry, PRUint64 new,
config_entry->threshold, config_entry->dn, config_entry->remaining);
/* Only attempt to fix maxval if the fix flag is set. */
if (fix != 0) {
- dna_fix_maxval(config_entry);
+ dna_fix_maxval(config_entry, txn);
}
}
@@ -1417,7 +1461,7 @@ dna_notice_allocation(struct configEntry *config_entry, PRUint64 new,
}
static int
-dna_get_shared_servers(struct configEntry *config_entry, PRCList **servers)
+dna_get_shared_servers(struct configEntry *config_entry, PRCList **servers, void *txn)
{
int ret = LDAP_SUCCESS;
Slapi_PBlock *pb = NULL;
@@ -1442,6 +1486,7 @@ dna_get_shared_servers(struct configEntry *config_entry, PRCList **servers)
LDAP_SCOPE_ONELEVEL, "objectclass=*",
attrs, 0, NULL,
NULL, getPluginID(), 0);
+ slapi_pblock_set(pb, SLAPI_TXN, txn);
slapi_search_internal_pb(pb);
slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &ret);
@@ -1826,7 +1871,7 @@ static LDAPControl *dna_build_sort_control(const char *attr)
* maximum configured value for this range. */
static int
dna_first_free_value(struct configEntry *config_entry,
- PRUint64 *newval)
+ PRUint64 *newval, void *txn)
{
Slapi_Entry **entries = NULL;
Slapi_PBlock *pb = NULL;
@@ -1894,6 +1939,7 @@ dna_first_free_value(struct configEntry *config_entry,
LDAP_SCOPE_SUBTREE, filter,
config_entry->types, 0, ctrls,
NULL, getPluginID(), 0);
+ slapi_pblock_set(pb, SLAPI_TXN, txn);
slapi_search_internal_pb(pb);
slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &result);
@@ -1933,6 +1979,7 @@ dna_first_free_value(struct configEntry *config_entry,
config_entry->types, 0, 0,
NULL, getPluginID(), 0);
+ slapi_pblock_set(pb, SLAPI_TXN, txn);
slapi_search_internal_pb(pb);
slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &result);
@@ -2006,7 +2053,7 @@ cleanup:
* Return the next value to be assigned
*/
static int dna_get_next_value(struct configEntry *config_entry,
- char **next_value_ret)
+ char **next_value_ret, void *txn)
{
Slapi_PBlock *pb = NULL;
LDAPMod mod_replace;
@@ -2026,12 +2073,12 @@ static int dna_get_next_value(struct configEntry *config_entry,
slapi_lock_mutex(config_entry->lock);
/* get the first value */
- ret = dna_first_free_value(config_entry, &setval);
+ ret = dna_first_free_value(config_entry, &setval, txn);
if (LDAP_SUCCESS != ret) {
/* check if we overflowed the configured range */
if (setval > config_entry->maxval) {
/* try for a new range or fail */
- ret = dna_fix_maxval(config_entry);
+ ret = dna_fix_maxval(config_entry, txn);
if (LDAP_SUCCESS != ret) {
slapi_log_error(SLAPI_LOG_FATAL, DNA_PLUGIN_SUBSYSTEM,
"dna_get_next_value: no more values available!!\n");
@@ -2039,7 +2086,7 @@ static int dna_get_next_value(struct configEntry *config_entry,
}
/* get the first value from our newly extended range */
- ret = dna_first_free_value(config_entry, &setval);
+ ret = dna_first_free_value(config_entry, &setval, txn);
if (LDAP_SUCCESS != ret)
goto done;
} else {
@@ -2076,6 +2123,7 @@ static int dna_get_next_value(struct configEntry *config_entry,
slapi_modify_internal_set_pb(pb, config_entry->dn,
mods, 0, 0, getPluginID(), 0);
+ slapi_pblock_set(pb, SLAPI_TXN, txn);
slapi_modify_internal_pb(pb);
slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &ret);
@@ -2090,7 +2138,7 @@ static int dna_get_next_value(struct configEntry *config_entry,
}
/* update our cached config */
- dna_notice_allocation(config_entry, nextval, setval, 1);
+ dna_notice_allocation(config_entry, nextval, setval, 1, txn);
}
done:
@@ -2116,7 +2164,7 @@ static int dna_get_next_value(struct configEntry *config_entry,
* before calling this function.
* */
static int
-dna_update_shared_config(struct configEntry * config_entry)
+dna_update_shared_config(struct configEntry * config_entry, void *txn)
{
int ret = LDAP_SUCCESS;
@@ -2148,7 +2196,7 @@ dna_update_shared_config(struct configEntry * config_entry)
} else {
slapi_modify_internal_set_pb(pb, config_entry->shared_cfg_dn,
mods, NULL, NULL, getPluginID(), 0);
-
+ slapi_pblock_set(pb, SLAPI_TXN, txn);
slapi_modify_internal_pb(pb);
slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &ret);
@@ -2176,6 +2224,7 @@ dna_update_shared_config(struct configEntry * config_entry)
/* e will be consumed by slapi_add_internal() */
slapi_add_entry_internal_set_pb(pb, e, NULL, getPluginID(), 0);
+ slapi_pblock_set(pb, SLAPI_TXN, txn);
slapi_add_internal_pb(pb);
slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &ret);
}
@@ -2205,7 +2254,7 @@ dna_update_shared_config(struct configEntry * config_entry)
*/
static int
dna_update_next_range(struct configEntry *config_entry,
- PRUint64 lower, PRUint64 upper)
+ PRUint64 lower, PRUint64 upper, void *txn)
{
Slapi_PBlock *pb = NULL;
LDAPMod mod_replace;
@@ -2236,7 +2285,7 @@ dna_update_next_range(struct configEntry *config_entry,
slapi_modify_internal_set_pb(pb, config_entry->dn,
mods, 0, 0, getPluginID(), 0);
-
+ slapi_pblock_set(pb, SLAPI_TXN, txn);
slapi_modify_internal_pb(pb);
slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &ret);
@@ -2252,7 +2301,7 @@ dna_update_next_range(struct configEntry *config_entry,
/* update the cached config and the shared config */
config_entry->next_range_lower = lower;
config_entry->next_range_upper = upper;
- dna_notice_allocation(config_entry, 0, 0, 0);
+ dna_notice_allocation(config_entry, 0, 0, 0, txn);
}
bail:
@@ -2269,7 +2318,7 @@ bail:
* be obtained before calling this function.
*/
static int
-dna_activate_next_range(struct configEntry *config_entry)
+dna_activate_next_range(struct configEntry *config_entry, void *txn)
{
Slapi_PBlock *pb = NULL;
LDAPMod mod_maxval;
@@ -2318,7 +2367,7 @@ dna_activate_next_range(struct configEntry *config_entry)
slapi_modify_internal_set_pb(pb, config_entry->dn,
mods, 0, 0, getPluginID(), 0);
-
+ slapi_pblock_set(pb, SLAPI_TXN, txn);
slapi_modify_internal_pb(pb);
slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &ret);
@@ -2339,7 +2388,7 @@ dna_activate_next_range(struct configEntry *config_entry)
config_entry->remaining = ((config_entry->maxval - config_entry->nextval + 1) /
config_entry->interval);
/* update the shared configuration */
- dna_update_shared_config(config_entry);
+ dna_update_shared_config(config_entry, txn);
}
bail:
@@ -2781,6 +2830,7 @@ static int dna_pre_op(Slapi_PBlock * pb, int modtype)
char *errstr = NULL;
int i = 0;
int ret = 0;
+ void *txn = NULL;
slapi_log_error(SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM,
"--> dna_pre_op\n");
@@ -2792,6 +2842,7 @@ static int dna_pre_op(Slapi_PBlock * pb, int modtype)
if (0 == (dn = dna_get_dn(pb)))
goto bail;
+ slapi_pblock_get(pb, SLAPI_TXN, &txn);
if (LDAP_CHANGETYPE_ADD == modtype) {
slapi_pblock_get(pb, SLAPI_ADD_ENTRY, &e);
} else {
@@ -2808,7 +2859,7 @@ static int dna_pre_op(Slapi_PBlock * pb, int modtype)
*/
Slapi_DN *tmp_dn = dna_get_sdn(pb);
if (tmp_dn) {
- slapi_search_internal_get_entry(tmp_dn, 0, &e, getPluginID());
+ slapi_search_internal_get_entry_ext(tmp_dn, 0, &e, getPluginID(), txn);
free_entry = 1;
}
@@ -3047,7 +3098,7 @@ static int dna_pre_op(Slapi_PBlock * pb, int modtype)
int len;
/* create the value to add */
- ret = dna_get_next_value(config_entry, &value);
+ ret = dna_get_next_value(config_entry, &value, txn);
if (DNA_SUCCESS != ret) {
errstr = slapi_ch_smprintf("Allocation of a new value for range"
" %s failed! Unable to proceed.",
@@ -3420,7 +3471,7 @@ dna_release_range(char *range_dn, PRUint64 *lower, PRUint64 *upper)
/* Try to set the new next range in the config */
ret = dna_update_next_range(config_entry, config_entry->next_range_lower,
- *lower - 1);
+ *lower - 1, NULL);
} else {
/* We release up to half of our remaining values,
* but we'll only release a range that is a multiple
@@ -3457,7 +3508,6 @@ dna_release_range(char *range_dn, PRUint64 *lower, PRUint64 *upper)
slapi_modify_internal_set_pb(pb, config_entry->dn,
mods, 0, 0, getPluginID(), 0);
-
slapi_modify_internal_pb(pb);
slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &ret);
@@ -3468,7 +3518,7 @@ dna_release_range(char *range_dn, PRUint64 *lower, PRUint64 *upper)
if (ret == LDAP_SUCCESS) {
/* Adjust maxval in our cached config and shared config */
config_entry->maxval = *lower - 1;
- dna_notice_allocation(config_entry, config_entry->nextval, 0, 0);
+ dna_notice_allocation(config_entry, config_entry->nextval, 0, 0, NULL);
}
}
diff --git a/ldap/servers/plugins/linkedattrs/fixup_task.c b/ldap/servers/plugins/linkedattrs/fixup_task.c
index d5d0b14..ef2c7e0 100644
--- a/ldap/servers/plugins/linkedattrs/fixup_task.c
+++ b/ldap/servers/plugins/linkedattrs/fixup_task.c
@@ -48,7 +48,7 @@
*/
static void linked_attrs_fixup_task_destructor(Slapi_Task *task);
static void linked_attrs_fixup_task_thread(void *arg);
-static void linked_attrs_fixup_links(struct configEntry *config);
+static void linked_attrs_fixup_links(struct configEntry *config, void *txn);
static int linked_attrs_remove_backlinks_callback(Slapi_Entry *e, void *callback_data);
static int linked_attrs_add_backlinks_callback(Slapi_Entry *e, void *callback_data);
static const char *fetch_attr(Slapi_Entry *e, const char *attrname,
@@ -163,7 +163,7 @@ linked_attrs_fixup_task_thread(void *arg)
"Fixing up linked attribute pair (%s)\n",
config_entry->dn);
- linked_attrs_fixup_links(config_entry);
+ linked_attrs_fixup_links(config_entry, NULL);
break;
}
} else {
@@ -173,7 +173,7 @@ linked_attrs_fixup_task_thread(void *arg)
slapi_log_error(SLAPI_LOG_FATAL, LINK_PLUGIN_SUBSYSTEM,
"Fixing up linked attribute pair (%s)\n", config_entry->dn);
- linked_attrs_fixup_links(config_entry);
+ linked_attrs_fixup_links(config_entry, NULL);
}
list = PR_NEXT_LINK(list);
@@ -200,12 +200,19 @@ linked_attrs_fixup_task_thread(void *arg)
slapi_task_finish(task, rc);
}
+struct fixup_cb_data {
+ char *attrtype;
+ void *txn;
+ struct configEntry *config;
+};
+
static void
-linked_attrs_fixup_links(struct configEntry *config)
+linked_attrs_fixup_links(struct configEntry *config, void *txn)
{
Slapi_PBlock *pb = slapi_pblock_new();
char *del_filter = NULL;
char *add_filter = NULL;
+ struct fixup_cb_data cb_data = {NULL, NULL, NULL};
del_filter = slapi_ch_smprintf("%s=*", config->managedtype);
add_filter = slapi_ch_smprintf("%s=*", config->linktype);
@@ -218,8 +225,11 @@ linked_attrs_fixup_links(struct configEntry *config)
* within the scope and remove the managed type. */
slapi_search_internal_set_pb(pb, config->scope, LDAP_SCOPE_SUBTREE,
del_filter, 0, 0, 0, 0, linked_attrs_get_plugin_id(), 0);
+ slapi_pblock_set(pb, SLAPI_TXN, txn);
- slapi_search_internal_callback_pb(pb, config->managedtype, 0,
+ cb_data.attrtype = config->managedtype;
+ cb_data.txn = txn;
+ slapi_search_internal_callback_pb(pb, &cb_data, 0,
linked_attrs_remove_backlinks_callback, 0);
/* Clean out pblock for reuse. */
@@ -229,8 +239,12 @@ linked_attrs_fixup_links(struct configEntry *config)
* scope and add backlinks to the entries they point to. */
slapi_search_internal_set_pb(pb, config->scope, LDAP_SCOPE_SUBTREE,
add_filter, 0, 0, 0, 0, linked_attrs_get_plugin_id(), 0);
+ slapi_pblock_set(pb, SLAPI_TXN, txn);
- slapi_search_internal_callback_pb(pb, config, 0,
+ cb_data.attrtype = NULL;
+ cb_data.txn = txn;
+ cb_data.config = config;
+ slapi_search_internal_callback_pb(pb, &cb_data, 0,
linked_attrs_add_backlinks_callback, 0);
} else {
/* Loop through all non-private backend suffixes and
@@ -245,7 +259,10 @@ linked_attrs_fixup_links(struct configEntry *config)
LDAP_SCOPE_SUBTREE, del_filter,
0, 0, 0, 0,
linked_attrs_get_plugin_id(), 0);
+ slapi_pblock_set(pb, SLAPI_TXN, txn);
+ cb_data.attrtype = config->managedtype;
+ cb_data.txn = txn;
slapi_search_internal_callback_pb(pb, config->managedtype, 0,
linked_attrs_remove_backlinks_callback, 0);
@@ -256,8 +273,11 @@ linked_attrs_fixup_links(struct configEntry *config)
LDAP_SCOPE_SUBTREE, add_filter,
0, 0, 0, 0,
linked_attrs_get_plugin_id(), 0);
-
- slapi_search_internal_callback_pb(pb, config, 0,
+ slapi_pblock_set(pb, SLAPI_TXN, txn);
+ cb_data.attrtype = NULL;
+ cb_data.txn = txn;
+ cb_data.config = config;
+ slapi_search_internal_callback_pb(pb, &cb_data, 0,
linked_attrs_add_backlinks_callback, 0);
/* Clean out pblock for reuse. */
@@ -280,7 +300,8 @@ linked_attrs_remove_backlinks_callback(Slapi_Entry *e, void *callback_data)
{
int rc = 0;
Slapi_DN *sdn = slapi_entry_get_sdn(e);
- char *type = (char *)callback_data;
+ struct fixup_cb_data *cb_data = (struct fixup_cb_data *)callback_data;
+ char *type = cb_data->attrtype;
Slapi_PBlock *pb = slapi_pblock_new();
char *val[1];
LDAPMod mod;
@@ -303,6 +324,7 @@ linked_attrs_remove_backlinks_callback(Slapi_Entry *e, void *callback_data)
/* Perform the operation. */
slapi_modify_internal_set_pb_ext(pb, sdn, mods, 0, 0,
linked_attrs_get_plugin_id(), 0);
+ slapi_pblock_set(pb, SLAPI_TXN, cb_data->txn);
slapi_modify_internal_pb(pb);
slapi_pblock_destroy(pb);
@@ -315,7 +337,8 @@ linked_attrs_add_backlinks_callback(Slapi_Entry *e, void *callback_data)
{
int rc = 0;
char *linkdn = slapi_entry_get_dn(e);
- struct configEntry *config = (struct configEntry *)callback_data;
+ struct fixup_cb_data *cb_data = (struct fixup_cb_data *)callback_data;
+ struct configEntry *config = cb_data->config;
Slapi_PBlock *pb = slapi_pblock_new();
int i = 0;
char **targets = NULL;
@@ -365,6 +388,7 @@ linked_attrs_add_backlinks_callback(Slapi_Entry *e, void *callback_data)
/* Perform the modify operation. */
slapi_modify_internal_set_pb_ext(pb, targetsdn, mods, 0, 0,
linked_attrs_get_plugin_id(), 0);
+ slapi_pblock_set(pb, SLAPI_TXN, cb_data->txn);
slapi_modify_internal_pb(pb);
/* Initialize the pblock so we can reuse it. */
diff --git a/ldap/servers/plugins/linkedattrs/linked_attrs.c b/ldap/servers/plugins/linkedattrs/linked_attrs.c
index 5c6d462..2b5127d 100644
--- a/ldap/servers/plugins/linkedattrs/linked_attrs.c
+++ b/ldap/servers/plugins/linkedattrs/linked_attrs.c
@@ -107,13 +107,13 @@ static int linked_attrs_oktodo(Slapi_PBlock *pb);
void linked_attrs_load_array(Slapi_Value **array, Slapi_Attr *attr);
int linked_attrs_compare(const void *a, const void *b);
static void linked_attrs_add_backpointers(char *linkdn, struct configEntry *config,
- Slapi_Mod *smod);
+ Slapi_Mod *smod, void *txn);
static void linked_attrs_del_backpointers(Slapi_PBlock *pb, char *linkdn,
struct configEntry *config, Slapi_Mod *smod);
static void linked_attrs_replace_backpointers(Slapi_PBlock *pb, char *linkdn,
struct configEntry *config, Slapi_Mod *smod);
static void linked_attrs_mod_backpointers(char *linkdn, char *type, char *scope,
- int modop, Slapi_ValueSet *targetvals);
+ int modop, Slapi_ValueSet *targetvals, void *txn);
/*
* Config cache locking functions
@@ -164,6 +164,7 @@ linked_attrs_get_plugin_dn()
return _PluginDN;
}
+static int plugin_is_betxn = 0;
/*
* Plug-in initialization functions
@@ -173,10 +174,24 @@ linked_attrs_init(Slapi_PBlock *pb)
{
int status = 0;
char *plugin_identity = NULL;
+ Slapi_Entry *plugin_entry = NULL;
+ char *plugin_type = NULL;
+ int preadd = SLAPI_PLUGIN_PRE_ADD_FN;
+ int premod = SLAPI_PLUGIN_PRE_MODIFY_FN;
slapi_log_error(SLAPI_LOG_TRACE, LINK_PLUGIN_SUBSYSTEM,
"--> linked_attrs_init\n");
+ if ((slapi_pblock_get(pb, SLAPI_PLUGIN_CONFIG_ENTRY, &plugin_entry) == 0) &&
+ plugin_entry &&
+ (plugin_type = slapi_entry_attr_get_charptr(plugin_entry, "nsslapd-plugintype")) &&
+ plugin_type && strstr(plugin_type, "betxn")) {
+ plugin_is_betxn = 1;
+ preadd = SLAPI_PLUGIN_BE_TXN_PRE_ADD_FN;
+ premod = SLAPI_PLUGIN_BE_TXN_PRE_MODIFY_FN;
+ }
+ slapi_ch_free_string(&plugin_type);
+
/* Store the plugin identity for later use.
* Used for internal operations. */
slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &plugin_identity);
@@ -192,10 +207,14 @@ linked_attrs_init(Slapi_PBlock *pb)
(void *) linked_attrs_close) != 0 ||
slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION,
(void *) &pdesc) != 0 ||
- slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_MODIFY_FN,
- (void *) linked_attrs_mod_pre_op) != 0 ||
- slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_ADD_FN,
- (void *) linked_attrs_add_pre_op) != 0 ||
+ slapi_pblock_set(pb, premod, (void *) linked_attrs_mod_pre_op) != 0 ||
+ slapi_pblock_set(pb, preadd, (void *) linked_attrs_add_pre_op) != 0) {
+ slapi_log_error(SLAPI_LOG_FATAL, LINK_PLUGIN_SUBSYSTEM,
+ "linked_attrs_init: failed to register plugin\n");
+ status = -1;
+ }
+
+ if (!status && !plugin_is_betxn &&
slapi_register_plugin("internalpostoperation", /* op type */
1, /* Enabled */
"linked_attrs_init", /* this function desc */
@@ -203,26 +222,37 @@ linked_attrs_init(Slapi_PBlock *pb)
LINK_INT_POSTOP_DESC, /* plugin desc */
NULL, /* ? */
plugin_identity /* access control */
- ) ||
- slapi_register_plugin("postoperation", /* op type */
- 1, /* Enabled */
- "linked_attrs_init", /* this function desc */
- linked_attrs_postop_init, /* init func for post op */
- LINK_POSTOP_DESC, /* plugin desc */
- NULL, /* ? */
- plugin_identity /* access control */
- )
- ) {
+ )) {
slapi_log_error(SLAPI_LOG_FATAL, LINK_PLUGIN_SUBSYSTEM,
- "linked_attrs_init: failed to register plugin\n");
+ "linked_attrs_init: failed to register internalpostoperation plugin\n");
status = -1;
}
+ if (!status) {
+ plugin_type = "postoperation";
+ if (plugin_is_betxn) {
+ plugin_type = "betxnpostoperation";
+ }
+ if (slapi_register_plugin(plugin_type, /* op type */
+ 1, /* Enabled */
+ "linked_attrs_init", /* this function desc */
+ linked_attrs_postop_init, /* init func for post op */
+ LINK_POSTOP_DESC, /* plugin desc */
+ NULL, /* ? */
+ plugin_identity /* access control */
+ )) {
+ slapi_log_error(SLAPI_LOG_FATAL, LINK_PLUGIN_SUBSYSTEM,
+ "linked_attrs_init: failed to register postop plugin\n");
+ status = -1;
+ }
+ }
+
slapi_log_error(SLAPI_LOG_TRACE, LINK_PLUGIN_SUBSYSTEM,
"<-- linked_attrs_init\n");
return status;
}
+/* not used when using plugin as a betxn plugin - betxn plugins are called for both internal and external ops */
static int
linked_attrs_internal_postop_init(Slapi_PBlock *pb)
{
@@ -252,19 +282,26 @@ static int
linked_attrs_postop_init(Slapi_PBlock *pb)
{
int status = 0;
+ int addfn = SLAPI_PLUGIN_POST_ADD_FN;
+ int delfn = SLAPI_PLUGIN_POST_DELETE_FN;
+ int modfn = SLAPI_PLUGIN_POST_MODIFY_FN;
+ int mdnfn = SLAPI_PLUGIN_POST_MODRDN_FN;
+
+ if (plugin_is_betxn) {
+ addfn = SLAPI_PLUGIN_BE_TXN_POST_ADD_FN;
+ delfn = SLAPI_PLUGIN_BE_TXN_POST_DELETE_FN;
+ modfn = SLAPI_PLUGIN_BE_TXN_POST_MODIFY_FN;
+ mdnfn = SLAPI_PLUGIN_BE_TXN_POST_MODRDN_FN;
+ }
if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION,
SLAPI_PLUGIN_VERSION_01) != 0 ||
slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION,
(void *) &pdesc) != 0 ||
- slapi_pblock_set(pb, SLAPI_PLUGIN_POST_ADD_FN,
- (void *) linked_attrs_add_post_op) != 0 ||
- slapi_pblock_set(pb, SLAPI_PLUGIN_POST_DELETE_FN,
- (void *) linked_attrs_del_post_op) != 0 ||
- slapi_pblock_set(pb, SLAPI_PLUGIN_POST_MODIFY_FN,
- (void *) linked_attrs_mod_post_op) != 0 ||
- slapi_pblock_set(pb, SLAPI_PLUGIN_POST_MODRDN_FN,
- (void *) linked_attrs_modrdn_post_op) != 0) {
+ slapi_pblock_set(pb, addfn, (void *) linked_attrs_add_post_op) != 0 ||
+ slapi_pblock_set(pb, delfn, (void *) linked_attrs_del_post_op) != 0 ||
+ slapi_pblock_set(pb, modfn, (void *) linked_attrs_mod_post_op) != 0 ||
+ slapi_pblock_set(pb, mdnfn, (void *) linked_attrs_modrdn_post_op) != 0) {
slapi_log_error(SLAPI_LOG_FATAL, LINK_PLUGIN_SUBSYSTEM,
"linked_attrs_postop_init: failed to register plugin\n");
status = -1;
@@ -1218,13 +1255,13 @@ linked_attrs_compare(const void *a, const void *b)
*/
static void
linked_attrs_add_backpointers(char *linkdn, struct configEntry *config,
- Slapi_Mod *smod)
+ Slapi_Mod *smod, void *txn)
{
Slapi_ValueSet *vals = slapi_valueset_new();
slapi_valueset_set_from_smod(vals, smod);
linked_attrs_mod_backpointers(linkdn, config->managedtype, config->scope,
- LDAP_MOD_ADD, vals);
+ LDAP_MOD_ADD, vals, txn);
slapi_valueset_free(vals);
}
@@ -1240,6 +1277,7 @@ linked_attrs_del_backpointers(Slapi_PBlock *pb, char *linkdn,
struct configEntry *config, Slapi_Mod *smod)
{
Slapi_ValueSet *vals = NULL;
+ void *txn = NULL;
/* If no values are listed in the smod, we need to get
* a list of all of the values that were deleted by
@@ -1256,8 +1294,9 @@ linked_attrs_del_backpointers(Slapi_PBlock *pb, char *linkdn,
slapi_valueset_set_from_smod(vals, smod);
}
+ slapi_pblock_get(pb, SLAPI_TXN, &txn);
linked_attrs_mod_backpointers(linkdn, config->managedtype, config->scope,
- LDAP_MOD_DELETE, vals);
+ LDAP_MOD_DELETE, vals, txn);
slapi_valueset_free(vals);
}
@@ -1278,6 +1317,7 @@ linked_attrs_replace_backpointers(Slapi_PBlock *pb, char *linkdn,
Slapi_Entry *post_e = NULL;
Slapi_Attr *pre_attr = 0;
Slapi_Attr *post_attr = 0;
+ void *txn = NULL;
/* Get the pre and post copy of the entry to see
* what values have been added and removed. */
@@ -1288,6 +1328,7 @@ linked_attrs_replace_backpointers(Slapi_PBlock *pb, char *linkdn,
slapi_entry_attr_find(pre_e, config->linktype, &pre_attr);
slapi_entry_attr_find(post_e, config->linktype, &post_attr);
}
+ slapi_pblock_get(pb, SLAPI_TXN, &txn);
if(pre_attr || post_attr) {
int pre_total = 0;
@@ -1374,13 +1415,13 @@ linked_attrs_replace_backpointers(Slapi_PBlock *pb, char *linkdn,
/* Perform the actual updates to the target entries. */
if (delvals) {
linked_attrs_mod_backpointers(linkdn, config->managedtype,
- config->scope, LDAP_MOD_DELETE, delvals);
+ config->scope, LDAP_MOD_DELETE, delvals, txn);
slapi_valueset_free(delvals);
}
if (addvals) {
linked_attrs_mod_backpointers(linkdn, config->managedtype,
- config->scope, LDAP_MOD_ADD, addvals);
+ config->scope, LDAP_MOD_ADD, addvals, txn);
slapi_valueset_free(addvals);
}
@@ -1396,7 +1437,7 @@ linked_attrs_replace_backpointers(Slapi_PBlock *pb, char *linkdn,
*/
static void
linked_attrs_mod_backpointers(char *linkdn, char *type,
- char *scope, int modop, Slapi_ValueSet *targetvals)
+ char *scope, int modop, Slapi_ValueSet *targetvals, void *txn)
{
char *val[2];
int i = 0;
@@ -1449,6 +1490,7 @@ linked_attrs_mod_backpointers(char *linkdn, char *type,
/* Perform the modify operation. */
slapi_modify_internal_set_pb_ext(mod_pb, targetsdn, mods, 0, 0,
linked_attrs_get_plugin_id(), 0);
+ slapi_pblock_set(mod_pb, SLAPI_TXN, txn);
slapi_modify_internal_pb(mod_pb);
/* Initialize the pblock so we can reuse it. */
@@ -1482,6 +1524,7 @@ linked_attrs_pre_op(Slapi_PBlock * pb, int modop)
int free_entry = 0;
char *errstr = NULL;
int ret = 0;
+ void *txn = NULL;
slapi_log_error(SLAPI_LOG_TRACE, LINK_PLUGIN_SUBSYSTEM,
"--> linked_attrs_pre_op\n");
@@ -1493,6 +1536,7 @@ linked_attrs_pre_op(Slapi_PBlock * pb, int modop)
if (0 == (dn = linked_attrs_get_dn(pb)))
goto bail;
+ slapi_pblock_get(pb, SLAPI_TXN, &txn);
if (linked_attrs_dn_is_config(dn)) {
/* Validate config changes, but don't apply them.
* This allows us to reject invalid config changes
@@ -1507,7 +1551,7 @@ linked_attrs_pre_op(Slapi_PBlock * pb, int modop)
/* int free_sdn = 0; */
Slapi_DN *tmp_dn = linked_attrs_get_sdn(pb);
if (tmp_dn) {
- slapi_search_internal_get_entry(tmp_dn, 0, &e, linked_attrs_get_plugin_id());
+ slapi_search_internal_get_entry_ext(tmp_dn, 0, &e, linked_attrs_get_plugin_id(), txn);
free_entry = 1;
}
@@ -1579,6 +1623,7 @@ linked_attrs_mod_post_op(Slapi_PBlock *pb)
char *dn = NULL;
struct configEntry *config = NULL;
void *caller_id = NULL;
+ void *txn = NULL;
slapi_log_error(SLAPI_LOG_TRACE, LINK_PLUGIN_SUBSYSTEM,
"--> linked_attrs_mod_post_op\n");
@@ -1596,6 +1641,7 @@ linked_attrs_mod_post_op(Slapi_PBlock *pb)
/* Just return without processing */
return 0;
}
+ slapi_pblock_get(pb, SLAPI_TXN, &txn);
if (linked_attrs_oktodo(pb) &&
(dn = linked_attrs_get_dn(pb))) {
@@ -1638,7 +1684,7 @@ linked_attrs_mod_post_op(Slapi_PBlock *pb)
case LDAP_MOD_ADD:
/* Find the entries pointed to by the new
* values and add the backpointers. */
- linked_attrs_add_backpointers(dn, config, smod);
+ linked_attrs_add_backpointers(dn, config, smod, txn);
break;
case LDAP_MOD_DELETE:
/* Find the entries pointed to by the deleted
@@ -1682,6 +1728,7 @@ linked_attrs_add_post_op(Slapi_PBlock *pb)
{
Slapi_Entry *e = NULL;
char *dn = NULL;
+ void *txn = NULL;
slapi_log_error(SLAPI_LOG_TRACE, LINK_PLUGIN_SUBSYSTEM,
"--> linked_attrs_add_post_op\n");
@@ -1700,6 +1747,7 @@ linked_attrs_add_post_op(Slapi_PBlock *pb)
"retrieving dn\n");
}
+ slapi_pblock_get(pb, SLAPI_TXN, &txn);
/* Get the newly added entry. */
slapi_pblock_get(pb, SLAPI_ENTRY_POST_OP, &e);
@@ -1732,7 +1780,7 @@ linked_attrs_add_post_op(Slapi_PBlock *pb)
slapi_lock_mutex(config->lock);
linked_attrs_mod_backpointers(dn, config->managedtype,
- config->scope, LDAP_MOD_ADD, vals);
+ config->scope, LDAP_MOD_ADD, vals, txn);
slapi_unlock_mutex(config->lock);
@@ -1761,6 +1809,7 @@ linked_attrs_del_post_op(Slapi_PBlock *pb)
{
char *dn = NULL;
Slapi_Entry *e = NULL;
+ void *txn = NULL;
slapi_log_error(SLAPI_LOG_TRACE, LINK_PLUGIN_SUBSYSTEM,
"--> linked_attrs_del_post_op\n");
@@ -1769,6 +1818,7 @@ linked_attrs_del_post_op(Slapi_PBlock *pb)
if (!g_plugin_started || !linked_attrs_oktodo(pb))
return 0;
+ slapi_pblock_get(pb, SLAPI_TXN, &txn);
/* Reload config if a config entry was deleted. */
if ((dn = linked_attrs_get_dn(pb))) {
if (linked_attrs_dn_is_config(dn))
@@ -1811,7 +1861,7 @@ linked_attrs_del_post_op(Slapi_PBlock *pb)
slapi_lock_mutex(config->lock);
linked_attrs_mod_backpointers(dn, config->managedtype,
- config->scope, LDAP_MOD_DELETE, vals);
+ config->scope, LDAP_MOD_DELETE, vals, txn);
slapi_unlock_mutex(config->lock);
@@ -1840,7 +1890,7 @@ linked_attrs_del_post_op(Slapi_PBlock *pb)
/* Delete forward link value. */
linked_attrs_mod_backpointers(dn, config->linktype,
- config->scope, LDAP_MOD_DELETE, vals);
+ config->scope, LDAP_MOD_DELETE, vals, txn);
slapi_unlock_mutex(config->lock);
@@ -1878,6 +1928,7 @@ linked_attrs_modrdn_post_op(Slapi_PBlock *pb)
char *type = NULL;
struct configEntry *config = NULL;
int rc = 0;
+ void *txn = NULL;
slapi_log_error(SLAPI_LOG_TRACE, LINK_PLUGIN_SUBSYSTEM,
"--> linked_attrs_modrdn_post_op\n");
@@ -1887,6 +1938,7 @@ linked_attrs_modrdn_post_op(Slapi_PBlock *pb)
goto done;
}
+ slapi_pblock_get(pb, SLAPI_TXN, &txn);
/* Reload config if an existing config entry was renamed,
* or if the new dn brings an entry into the scope of the
* config entries. */
@@ -1939,7 +1991,7 @@ linked_attrs_modrdn_post_op(Slapi_PBlock *pb)
/* Delete old dn value. */
linked_attrs_mod_backpointers(old_dn, config->managedtype,
- config->scope, LDAP_MOD_DELETE, vals);
+ config->scope, LDAP_MOD_DELETE, vals, txn);
slapi_unlock_mutex(config->lock);
@@ -1962,7 +2014,7 @@ linked_attrs_modrdn_post_op(Slapi_PBlock *pb)
/* Add new dn value. */
linked_attrs_mod_backpointers(new_dn, config->managedtype,
- config->scope, LDAP_MOD_ADD, vals);
+ config->scope, LDAP_MOD_ADD, vals, txn);
slapi_unlock_mutex(config->lock);
@@ -1991,11 +2043,11 @@ linked_attrs_modrdn_post_op(Slapi_PBlock *pb)
/* Delete old dn value. */
linked_attrs_mod_backpointers(old_dn, config->linktype,
- config->scope, LDAP_MOD_DELETE, vals);
+ config->scope, LDAP_MOD_DELETE, vals, txn);
/* Add new dn value. */
linked_attrs_mod_backpointers(new_dn, config->linktype,
- config->scope, LDAP_MOD_ADD, vals);
+ config->scope, LDAP_MOD_ADD, vals, txn);
slapi_unlock_mutex(config->lock);
diff --git a/ldap/servers/plugins/mep/mep.c b/ldap/servers/plugins/mep/mep.c
index 237ef91..82acdbd 100644
--- a/ldap/servers/plugins/mep/mep.c
+++ b/ldap/servers/plugins/mep/mep.c
@@ -86,9 +86,9 @@ static int mep_modrdn_pre_op(Slapi_PBlock *pb);
/*
* Config cache management functions
*/
-static int mep_load_config();
+static int mep_load_config(Slapi_PBlock *pb);
static void mep_delete_config();
-static int mep_parse_config_entry(Slapi_Entry * e, int apply);
+static int mep_parse_config_entry(Slapi_Entry * e, int apply, Slapi_PBlock *pb);
static void mep_free_config_entry(struct configEntry ** entry);
/*
@@ -107,9 +107,9 @@ static int mep_isrepl(Slapi_PBlock *pb);
static Slapi_Entry *mep_create_managed_entry(struct configEntry *config,
Slapi_Entry *origin);
static void mep_add_managed_entry(struct configEntry *config,
- Slapi_Entry *origin);
+ Slapi_Entry *origin, void *txn);
static void mep_rename_managed_entry(Slapi_Entry *origin,
- Slapi_DN *new_dn, Slapi_DN *old_dn);
+ Slapi_DN *new_dn, Slapi_DN *old_dn, void *txn);
static Slapi_Mods *mep_get_mapped_mods(struct configEntry *config,
Slapi_Entry *origin, char **mapped_dn);
static int mep_parse_mapped_attr(char *mapping, Slapi_Entry *origin,
@@ -168,6 +168,8 @@ mep_get_plugin_sdn()
}
+static int plugin_is_betxn = 0;
+
/*
* Plug-in initialization functions
*/
@@ -176,10 +178,28 @@ mep_init(Slapi_PBlock *pb)
{
int status = 0;
char *plugin_identity = NULL;
+ Slapi_Entry *plugin_entry = NULL;
+ char *plugin_type = NULL;
+ int preadd = SLAPI_PLUGIN_PRE_ADD_FN;
+ int premod = SLAPI_PLUGIN_PRE_MODIFY_FN;
+ int predel = SLAPI_PLUGIN_PRE_DELETE_FN;
+ int premdn = SLAPI_PLUGIN_PRE_MODRDN_FN;
slapi_log_error(SLAPI_LOG_TRACE, MEP_PLUGIN_SUBSYSTEM,
"--> mep_init\n");
+ if ((slapi_pblock_get(pb, SLAPI_PLUGIN_CONFIG_ENTRY, &plugin_entry) == 0) &&
+ plugin_entry &&
+ (plugin_type = slapi_entry_attr_get_charptr(plugin_entry, "nsslapd-plugintype")) &&
+ plugin_type && strstr(plugin_type, "betxn")) {
+ plugin_is_betxn = 1;
+ preadd = SLAPI_PLUGIN_BE_TXN_PRE_ADD_FN;
+ premod = SLAPI_PLUGIN_BE_TXN_PRE_MODIFY_FN;
+ predel = SLAPI_PLUGIN_BE_TXN_PRE_DELETE_FN;
+ premdn = SLAPI_PLUGIN_BE_TXN_PRE_MODRDN_FN;
+ }
+ slapi_ch_free_string(&plugin_type);
+
/* Store the plugin identity for later use.
* Used for internal operations. */
slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &plugin_identity);
@@ -195,14 +215,16 @@ mep_init(Slapi_PBlock *pb)
(void *) mep_close) != 0 ||
slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION,
(void *) &pdesc) != 0 ||
- slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_MODIFY_FN,
- (void *) mep_mod_pre_op) != 0 ||
- slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_ADD_FN,
- (void *) mep_add_pre_op) != 0 ||
- slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_DELETE_FN,
- (void *) mep_del_pre_op) != 0 ||
- slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_MODRDN_FN,
- (void *) mep_modrdn_pre_op) != 0 ||
+ slapi_pblock_set(pb, premod, (void *) mep_mod_pre_op) != 0 ||
+ slapi_pblock_set(pb, preadd, (void *) mep_add_pre_op) != 0 ||
+ slapi_pblock_set(pb, predel, (void *) mep_del_pre_op) != 0 ||
+ slapi_pblock_set(pb, premdn, (void *) mep_modrdn_pre_op) != 0) {
+ slapi_log_error(SLAPI_LOG_FATAL, MEP_PLUGIN_SUBSYSTEM,
+ "mep_init: failed to register plugin\n");
+ status = -1;
+ }
+
+ if (!status && !plugin_is_betxn &&
slapi_register_plugin("internalpostoperation", /* op type */
1, /* Enabled */
"mep_init", /* this function desc */
@@ -210,26 +232,34 @@ mep_init(Slapi_PBlock *pb)
MEP_INT_POSTOP_DESC, /* plugin desc */
NULL, /* ? */
plugin_identity /* access control */
- ) ||
- slapi_register_plugin("postoperation", /* op type */
- 1, /* Enabled */
- "mep_init", /* this function desc */
- mep_postop_init, /* init func for post op */
- MEP_POSTOP_DESC, /* plugin desc */
- NULL, /* ? */
- plugin_identity /* access control */
- )
- ) {
+ )) {
slapi_log_error(SLAPI_LOG_FATAL, MEP_PLUGIN_SUBSYSTEM,
- "mep_init: failed to register plugin\n");
+ "mep_init: failed to register internalpostoperation plugin\n");
status = -1;
}
+ if (!status) {
+ plugin_type = plugin_is_betxn ? "betxnpostoperation" : "postoperation";
+ if (slapi_register_plugin(plugin_type, /* op type */
+ 1, /* Enabled */
+ "mep_init", /* this function desc */
+ mep_postop_init, /* init func for post op */
+ MEP_POSTOP_DESC, /* plugin desc */
+ NULL, /* ? */
+ plugin_identity /* access control */
+ )) {
+ slapi_log_error(SLAPI_LOG_FATAL, MEP_PLUGIN_SUBSYSTEM,
+ "mep_init: failed to register plugin\n");
+ status = -1;
+ }
+ }
+
slapi_log_error(SLAPI_LOG_TRACE, MEP_PLUGIN_SUBSYSTEM,
"<-- mep_init\n");
return status;
}
+/* not used when using plugin as a betxn plugin - betxn plugins are called for both internal and external ops */
static int
mep_internal_postop_init(Slapi_PBlock *pb)
{
@@ -259,19 +289,26 @@ static int
mep_postop_init(Slapi_PBlock *pb)
{
int status = 0;
+ int addfn = SLAPI_PLUGIN_POST_ADD_FN;
+ int delfn = SLAPI_PLUGIN_POST_DELETE_FN;
+ int modfn = SLAPI_PLUGIN_POST_MODIFY_FN;
+ int mdnfn = SLAPI_PLUGIN_POST_MODRDN_FN;
+
+ if (plugin_is_betxn) {
+ addfn = SLAPI_PLUGIN_BE_TXN_POST_ADD_FN;
+ delfn = SLAPI_PLUGIN_BE_TXN_POST_DELETE_FN;
+ modfn = SLAPI_PLUGIN_BE_TXN_POST_MODIFY_FN;
+ mdnfn = SLAPI_PLUGIN_BE_TXN_POST_MODRDN_FN;
+ }
if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION,
SLAPI_PLUGIN_VERSION_01) != 0 ||
slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION,
(void *) &pdesc) != 0 ||
- slapi_pblock_set(pb, SLAPI_PLUGIN_POST_ADD_FN,
- (void *) mep_add_post_op) != 0 ||
- slapi_pblock_set(pb, SLAPI_PLUGIN_POST_DELETE_FN,
- (void *) mep_del_post_op) != 0 ||
- slapi_pblock_set(pb, SLAPI_PLUGIN_POST_MODIFY_FN,
- (void *) mep_mod_post_op) != 0 ||
- slapi_pblock_set(pb, SLAPI_PLUGIN_POST_MODRDN_FN,
- (void *) mep_modrdn_post_op) != 0) {
+ slapi_pblock_set(pb, addfn, (void *) mep_add_post_op) != 0 ||
+ slapi_pblock_set(pb, delfn, (void *) mep_del_post_op) != 0 ||
+ slapi_pblock_set(pb, modfn, (void *) mep_mod_post_op) != 0 ||
+ slapi_pblock_set(pb, mdnfn, (void *) mep_modrdn_post_op) != 0) {
slapi_log_error(SLAPI_LOG_FATAL, MEP_PLUGIN_SUBSYSTEM,
"mep_postop_init: failed to register plugin\n");
status = -1;
@@ -333,7 +370,7 @@ mep_start(Slapi_PBlock * pb)
g_mep_config = (PRCList *)slapi_ch_calloc(1, sizeof(struct configEntry));
PR_INIT_CLIST(g_mep_config);
- if (mep_load_config() != 0) {
+ if (mep_load_config(pb) != 0) {
slapi_log_error(SLAPI_LOG_FATAL, MEP_PLUGIN_SUBSYSTEM,
"mep_start: unable to load plug-in configuration\n");
return -1;
@@ -401,13 +438,14 @@ mep_get_config()
* --- cn=etc,...
*/
static int
-mep_load_config()
+mep_load_config(Slapi_PBlock *pb)
{
int status = 0;
int result;
int i;
Slapi_PBlock *search_pb;
Slapi_Entry **entries = NULL;
+ void *txn = NULL;
slapi_log_error(SLAPI_LOG_TRACE, MEP_PLUGIN_SUBSYSTEM,
"--> mep_load_config\n");
@@ -442,6 +480,8 @@ mep_load_config()
NULL, 0, NULL, NULL, mep_get_plugin_id(), 0);
}
+ slapi_pblock_get(pb, SLAPI_TXN, &txn);
+ slapi_pblock_set(search_pb, SLAPI_TXN, txn);
slapi_search_internal_pb(search_pb);
slapi_pblock_get(search_pb, SLAPI_PLUGIN_INTOP_RESULT, &result);
@@ -465,7 +505,7 @@ mep_load_config()
/* We don't care about the status here because we may have
* some invalid config entries, but we just want to continue
* looking for valid ones. */
- mep_parse_config_entry(entries[i], 1);
+ mep_parse_config_entry(entries[i], 1, pb);
}
cleanup:
@@ -489,7 +529,7 @@ mep_load_config()
* Returns 0 if the entry is valid and -1 if it is invalid.
*/
static int
-mep_parse_config_entry(Slapi_Entry * e, int apply)
+mep_parse_config_entry(Slapi_Entry * e, int apply, Slapi_PBlock *pb)
{
char *value;
struct configEntry *entry = NULL;
@@ -497,6 +537,7 @@ mep_parse_config_entry(Slapi_Entry * e, int apply)
PRCList *list;
int entry_added = 0;
int ret = 0;
+ void *txn = NULL;
slapi_log_error(SLAPI_LOG_TRACE, MEP_PLUGIN_SUBSYSTEM,
"--> mep_parse_config_entry\n");
@@ -530,6 +571,7 @@ mep_parse_config_entry(Slapi_Entry * e, int apply)
slapi_log_error(SLAPI_LOG_CONFIG, MEP_PLUGIN_SUBSYSTEM,
"----------> dn [%s]\n", entry->dn);
+ slapi_pblock_get(pb, SLAPI_TXN, &txn);
/* Load the origin scope */
value = slapi_entry_attr_get_charptr(e, MEP_SCOPE_TYPE);
if (value) {
@@ -592,8 +634,8 @@ mep_parse_config_entry(Slapi_Entry * e, int apply)
/* Fetch the managed entry template */
template_sdn = slapi_sdn_new_dn_byref(entry->template_dn);
- slapi_search_internal_get_entry(template_sdn, 0,
- &entry->template_entry, mep_get_plugin_id());
+ slapi_search_internal_get_entry_ext(template_sdn, 0,
+ &entry->template_entry, mep_get_plugin_id(), txn);
slapi_sdn_free(&template_sdn);
if (entry->template_entry == NULL) {
@@ -1178,7 +1220,7 @@ mep_create_managed_entry(struct configEntry *config, Slapi_Entry *origin)
*/
static void
mep_add_managed_entry(struct configEntry *config,
- Slapi_Entry *origin)
+ Slapi_Entry *origin, void *txn)
{
Slapi_Entry *managed_entry = NULL;
char *managed_dn = NULL;
@@ -1208,6 +1250,7 @@ mep_add_managed_entry(struct configEntry *config,
"entry \"%s\"\n.", managed_dn, slapi_entry_get_dn(origin));
slapi_add_entry_internal_set_pb(mod_pb, managed_entry, NULL,
mep_get_plugin_id(), 0);
+ slapi_pblock_set(mod_pb, SLAPI_TXN, txn);
slapi_add_internal_pb(mod_pb);
slapi_pblock_get(mod_pb, SLAPI_PLUGIN_INTOP_RESULT, &result);
@@ -1253,6 +1296,7 @@ mep_add_managed_entry(struct configEntry *config,
slapi_modify_internal_set_pb_ext(mod_pb,
slapi_entry_get_sdn(origin),
mods, 0, 0, mep_get_plugin_id(), 0);
+ slapi_pblock_set(mod_pb, SLAPI_TXN, txn);
slapi_modify_internal_pb(mod_pb);
slapi_pblock_get(mod_pb, SLAPI_PLUGIN_INTOP_RESULT, &result);
@@ -1277,7 +1321,7 @@ mep_add_managed_entry(struct configEntry *config,
*/
static void
mep_rename_managed_entry(Slapi_Entry *origin,
- Slapi_DN *new_dn, Slapi_DN *old_dn)
+ Slapi_DN *new_dn, Slapi_DN *old_dn, void *txn)
{
Slapi_RDN *srdn = slapi_rdn_new();
Slapi_PBlock *mep_pb = slapi_pblock_new();
@@ -1298,6 +1342,7 @@ mep_rename_managed_entry(Slapi_Entry *origin,
slapi_rename_internal_set_pb_ext(mep_pb, old_dn,
slapi_rdn_get_rdn(srdn),
NULL, 1, NULL, NULL, mep_get_plugin_id(), 0);
+ slapi_pblock_set(mep_pb, SLAPI_TXN, txn);
slapi_modrdn_internal_pb(mep_pb);
slapi_pblock_get(mep_pb, SLAPI_PLUGIN_INTOP_RESULT, &result);
@@ -1326,6 +1371,7 @@ mep_rename_managed_entry(Slapi_Entry *origin,
vals[0], slapi_entry_get_dn(origin));
slapi_modify_internal_set_pb_ext(mep_pb, slapi_entry_get_sdn(origin),
mods, 0, 0, mep_get_plugin_id(), 0);
+ slapi_pblock_set(mep_pb, SLAPI_TXN, txn);
slapi_modify_internal_pb(mep_pb);
slapi_pblock_get(mep_pb, SLAPI_PLUGIN_INTOP_RESULT, &result);
@@ -1744,6 +1790,7 @@ mep_pre_op(Slapi_PBlock * pb, int modop)
struct configEntry *config = NULL;
void *caller_id = NULL;
int ret = 0;
+ void *txn = NULL;
slapi_log_error(SLAPI_LOG_TRACE, MEP_PLUGIN_SUBSYSTEM,
"--> mep_pre_op\n");
@@ -1758,6 +1805,7 @@ mep_pre_op(Slapi_PBlock * pb, int modop)
if (0 == (sdn = mep_get_sdn(pb)))
goto bail;
+ slapi_pblock_get(pb, SLAPI_TXN, &txn);
if (mep_dn_is_config(sdn)) {
/* Validate config changes, but don't apply them.
* This allows us to reject invalid config changes
@@ -1771,7 +1819,7 @@ mep_pre_op(Slapi_PBlock * pb, int modop)
/* Fetch the entry being modified so we can
* create the resulting entry for validation. */
if (sdn) {
- slapi_search_internal_get_entry(sdn, 0, &e, mep_get_plugin_id());
+ slapi_search_internal_get_entry_ext(sdn, 0, &e, mep_get_plugin_id(), txn);
free_entry = 1;
}
@@ -1800,7 +1848,7 @@ mep_pre_op(Slapi_PBlock * pb, int modop)
goto bail;
}
- if (mep_parse_config_entry(e, 0) != 0) {
+ if (mep_parse_config_entry(e, 0, pb) != 0) {
/* Refuse the operation if config parsing failed. */
ret = LDAP_UNWILLING_TO_PERFORM;
if (LDAP_CHANGETYPE_ADD == modop) {
@@ -1852,7 +1900,7 @@ mep_pre_op(Slapi_PBlock * pb, int modop)
case LDAP_CHANGETYPE_MODIFY:
/* Fetch the existing template entry. */
if (sdn) {
- slapi_search_internal_get_entry(sdn, 0, &e, mep_get_plugin_id());
+ slapi_search_internal_get_entry_ext(sdn, 0, &e, mep_get_plugin_id(), txn);
free_entry = 1;
}
@@ -1920,7 +1968,7 @@ mep_pre_op(Slapi_PBlock * pb, int modop)
slapi_entry_free(e);
}
- slapi_search_internal_get_entry(sdn, 0, &e, mep_get_plugin_id());
+ slapi_search_internal_get_entry_ext(sdn, 0, &e, mep_get_plugin_id(), txn);
free_entry = 1;
}
@@ -1930,8 +1978,8 @@ mep_pre_op(Slapi_PBlock * pb, int modop)
origin_dn = slapi_entry_attr_get_charptr(e, MEP_MANAGED_BY_TYPE);
if (origin_dn) {
origin_sdn = slapi_sdn_new_dn_byref(origin_dn);
- slapi_search_internal_get_entry(origin_sdn, 0,
- &origin_e, mep_get_plugin_id());
+ slapi_search_internal_get_entry_ext(origin_sdn, 0,
+ &origin_e, mep_get_plugin_id(), txn);
slapi_sdn_free(&origin_sdn);
}
@@ -2062,6 +2110,7 @@ mep_mod_post_op(Slapi_PBlock *pb)
Slapi_DN *mapped_sdn = NULL;
struct configEntry *config = NULL;
int result = 0;
+ void *txn = NULL;
slapi_log_error(SLAPI_LOG_TRACE, MEP_PLUGIN_SUBSYSTEM,
"--> mep_mod_post_op\n");
@@ -2070,10 +2119,11 @@ mep_mod_post_op(Slapi_PBlock *pb)
if (!g_plugin_started)
return 0;
+ slapi_pblock_get(pb, SLAPI_TXN, &txn);
if (mep_oktodo(pb) && (sdn = mep_get_sdn(pb))) {
/* First check if the config or a template is being modified. */
if (mep_dn_is_config(sdn) || mep_dn_is_template(slapi_sdn_get_dn(sdn))) {
- mep_load_config();
+ mep_load_config(pb);
}
/* If replication, just bail. */
@@ -2121,6 +2171,7 @@ mep_mod_post_op(Slapi_PBlock *pb)
slapi_modify_internal_set_pb(mep_pb, managed_dn,
slapi_mods_get_ldapmods_byref(smods), 0, 0,
mep_get_plugin_id(), 0);
+ slapi_pblock_set(mep_pb, SLAPI_TXN, txn);
slapi_modify_internal_pb(mep_pb);
slapi_pblock_get(mep_pb, SLAPI_PLUGIN_INTOP_RESULT, &result);
@@ -2142,7 +2193,7 @@ mep_mod_post_op(Slapi_PBlock *pb)
managed_sdn = slapi_sdn_new_dn_byref(managed_dn);
if (slapi_sdn_compare(managed_sdn, mapped_sdn) != 0) {
- mep_rename_managed_entry(e, mapped_sdn, managed_sdn);
+ mep_rename_managed_entry(e, mapped_sdn, managed_sdn, txn);
}
slapi_sdn_free(&mapped_sdn);
@@ -2174,6 +2225,7 @@ mep_add_post_op(Slapi_PBlock *pb)
Slapi_Entry *e = NULL;
Slapi_DN *sdn = NULL;
struct configEntry *config = NULL;
+ void *txn = NULL;
slapi_log_error(SLAPI_LOG_TRACE, MEP_PLUGIN_SUBSYSTEM,
"--> mep_add_post_op\n");
@@ -2182,10 +2234,11 @@ mep_add_post_op(Slapi_PBlock *pb)
if (!g_plugin_started || !mep_oktodo(pb))
return 0;
+ slapi_pblock_get(pb, SLAPI_TXN, &txn);
/* Reload config if a config entry was added. */
if ((sdn = mep_get_sdn(pb))) {
if (mep_dn_is_config(sdn)) {
- mep_load_config();
+ mep_load_config(pb);
}
} else {
slapi_log_error(SLAPI_LOG_PLUGIN, MEP_PLUGIN_SUBSYSTEM,
@@ -2219,7 +2272,7 @@ mep_add_post_op(Slapi_PBlock *pb)
mep_find_config(e, &config);
if (config) {
- mep_add_managed_entry(config, e);
+ mep_add_managed_entry(config, e, txn);
}
mep_config_unlock();
@@ -2240,6 +2293,7 @@ mep_del_post_op(Slapi_PBlock *pb)
{
Slapi_Entry *e = NULL;
Slapi_DN *sdn = NULL;
+ void *txn = NULL;
slapi_log_error(SLAPI_LOG_TRACE, MEP_PLUGIN_SUBSYSTEM,
"--> mep_del_post_op\n");
@@ -2252,7 +2306,7 @@ mep_del_post_op(Slapi_PBlock *pb)
/* Reload config if a config entry was deleted. */
if ((sdn = mep_get_sdn(pb))) {
if (mep_dn_is_config(sdn))
- mep_load_config();
+ mep_load_config(pb);
} else {
slapi_log_error(SLAPI_LOG_PLUGIN, MEP_PLUGIN_SUBSYSTEM,
"mep_del_post_op: Error "
@@ -2264,6 +2318,7 @@ mep_del_post_op(Slapi_PBlock *pb)
return 0;
}
+ slapi_pblock_get(pb, SLAPI_TXN, &txn);
/* Get deleted entry, then go through types to find config. */
slapi_pblock_get( pb, SLAPI_ENTRY_PRE_OP, &e );
@@ -2287,6 +2342,7 @@ mep_del_post_op(Slapi_PBlock *pb)
"\"%s\".\n ", managed_dn, slapi_sdn_get_dn(sdn));
slapi_delete_internal_set_pb(mep_pb, managed_dn, NULL,
NULL, mep_get_plugin_id(), 0);
+ slapi_pblock_set(mep_pb, SLAPI_TXN, txn);
slapi_delete_internal_pb(mep_pb);
slapi_ch_free_string(&managed_dn);
@@ -2313,6 +2369,7 @@ mep_modrdn_post_op(Slapi_PBlock *pb)
Slapi_Entry *post_e = NULL;
char *managed_dn = NULL;
struct configEntry *config = NULL;
+ void *txn = NULL;
slapi_log_error(SLAPI_LOG_TRACE, MEP_PLUGIN_SUBSYSTEM,
"--> mep_modrdn_post_op\n");
@@ -2335,9 +2392,10 @@ mep_modrdn_post_op(Slapi_PBlock *pb)
return 0;
}
+ slapi_pblock_get(pb, SLAPI_TXN, &txn);
if ((old_sdn = mep_get_sdn(pb))) {
if (mep_dn_is_config(old_sdn) || mep_dn_is_config(new_sdn))
- mep_load_config();
+ mep_load_config(pb);
} else {
slapi_log_error(SLAPI_LOG_PLUGIN, MEP_PLUGIN_SUBSYSTEM,
"mep_modrdn_post_op: Error "
@@ -2388,6 +2446,7 @@ mep_modrdn_post_op(Slapi_PBlock *pb)
managed_dn, slapi_sdn_get_dn(old_sdn));
slapi_delete_internal_set_pb (mep_pb, managed_dn, NULL, NULL,
mep_get_plugin_id(), 0);
+ slapi_pblock_set(mep_pb, SLAPI_TXN, txn);
slapi_delete_internal_pb(mep_pb);
/* Clear out the pblock for reuse. */
@@ -2417,6 +2476,7 @@ mep_modrdn_post_op(Slapi_PBlock *pb)
MEP_MANAGED_ENTRY_TYPE, MEP_ORIGIN_OC, new_dn);
slapi_modify_internal_set_pb_ext(mep_pb, new_sdn, mods, 0, 0,
mep_get_plugin_id(), 0);
+ slapi_pblock_set(mep_pb, SLAPI_TXN, txn);
slapi_modify_internal_pb(mep_pb);
slapi_pblock_get(mep_pb, SLAPI_PLUGIN_INTOP_RESULT, &result);
@@ -2454,8 +2514,8 @@ mep_modrdn_post_op(Slapi_PBlock *pb)
* perform our updates. */
managed_sdn = slapi_sdn_new_dn_byref(managed_dn);
- if (slapi_search_internal_get_entry(managed_sdn, 0,
- NULL, mep_get_plugin_id()) == LDAP_NO_SUCH_OBJECT) {
+ if (slapi_search_internal_get_entry_ext(managed_sdn, 0,
+ NULL, mep_get_plugin_id(), txn) == LDAP_NO_SUCH_OBJECT) {
slapi_ch_free_string(&managed_dn);
/* This DN is not a copy, so we don't want to free it later. */
managed_dn = slapi_entry_get_dn(new_managed_entry);
@@ -2469,6 +2529,7 @@ mep_modrdn_post_op(Slapi_PBlock *pb)
"in entry \"%s\".\n", MEP_MANAGED_BY_TYPE, new_dn, managed_dn);
slapi_modify_internal_set_pb(mep_pb, managed_dn, mods, 0, 0,
mep_get_plugin_id(), 0);
+ slapi_pblock_set(mep_pb, SLAPI_TXN, txn);
slapi_modify_internal_pb(mep_pb);
slapi_pblock_get(mep_pb, SLAPI_PLUGIN_INTOP_RESULT, &result);
@@ -2489,7 +2550,7 @@ mep_modrdn_post_op(Slapi_PBlock *pb)
slapi_sdn_get_dn(old_sdn));
mep_rename_managed_entry(post_e,
slapi_entry_get_sdn(new_managed_entry),
- managed_sdn);
+ managed_sdn, txn);
}
/* Update all of the mapped attributes
@@ -2507,6 +2568,7 @@ mep_modrdn_post_op(Slapi_PBlock *pb)
slapi_entry_get_sdn(new_managed_entry),
slapi_mods_get_ldapmods_byref(smods), 0, 0,
mep_get_plugin_id(), 0);
+ slapi_pblock_set(mep_pb, SLAPI_TXN, txn);
slapi_modify_internal_pb(mep_pb);
slapi_pblock_get(mep_pb, SLAPI_PLUGIN_INTOP_RESULT, &result);
@@ -2549,7 +2611,7 @@ bailmod:
mep_find_config(post_e, &config);
if (config) {
- mep_add_managed_entry(config, post_e);
+ mep_add_managed_entry(config, post_e, txn);
}
mep_config_unlock();
diff --git a/ldap/servers/plugins/replication/urp.c b/ldap/servers/plugins/replication/urp.c
index 1328996..33be252 100644
--- a/ldap/servers/plugins/replication/urp.c
+++ b/ldap/servers/plugins/replication/urp.c
@@ -53,10 +53,10 @@
extern int slapi_log_urp;
static int urp_add_resolve_parententry (Slapi_PBlock *pb, char *sessionid, Slapi_Entry *entry, Slapi_Entry *parententry, CSN *opcsn);
-static int urp_annotate_dn (char *sessionid, Slapi_Entry *entry, CSN *opcsn, const char *optype);
+static int urp_annotate_dn (char *sessionid, Slapi_Entry *entry, CSN *opcsn, const char *optype, void *txn);
static int urp_naming_conflict_removal (Slapi_PBlock *pb, char *sessionid, CSN *opcsn, const char *optype);
-static int mod_namingconflict_attr (const char *uniqueid, const Slapi_DN *entrysdn, const Slapi_DN *conflictsdn, CSN *opcsn);
-static int del_replconflict_attr (Slapi_Entry *entry, CSN *opcsn, int opflags);
+static int mod_namingconflict_attr (const char *uniqueid, const Slapi_DN *entrysdn, const Slapi_DN *conflictsdn, CSN *opcsn, void *txn);
+static int del_replconflict_attr (Slapi_Entry *entry, CSN *opcsn, int opflags, void *txn);
static char *get_dn_plus_uniqueid(char *sessionid,const char *olddn,const char *uniqueid);
static char *get_rdn_plus_uniqueid(char *sessionid,const char *olddn,const char *uniqueid);
static int is_suffix_entry (Slapi_PBlock *pb, Slapi_Entry *entry, Slapi_DN **parenddn);
@@ -123,12 +123,14 @@ urp_add_operation( Slapi_PBlock *pb )
int op_result= 0;
int rc= 0; /* OK */
Slapi_DN *sdn = NULL;
+ void *txn = NULL;
if ( slapi_op_abandoned(pb) )
{
return rc;
}
+ slapi_pblock_get( pb, SLAPI_TXN, &txn );
slapi_pblock_get( pb, SLAPI_ADD_EXISTING_UNIQUEID_ENTRY, &existing_uniqueid_entry );
if (existing_uniqueid_entry!=NULL)
{
@@ -227,7 +229,7 @@ urp_add_operation( Slapi_PBlock *pb )
else if(r>0)
{
/* Existing entry is a loser */
- if (!urp_annotate_dn(sessionid, existing_dn_entry, opcsn, "ADD"))
+ if (!urp_annotate_dn(sessionid, existing_dn_entry, opcsn, "ADD", txn))
{
op_result= LDAP_OPERATIONS_ERROR;
slapi_pblock_set(pb, SLAPI_RESULT_CODE, &op_result);
@@ -286,12 +288,14 @@ urp_modrdn_operation( Slapi_PBlock *pb )
int op_result= 0;
int rc= 0; /* OK */
int del_old_replconflict_attr = 0;
+ void *txn = NULL;
if ( slapi_op_abandoned(pb) )
{
return rc;
}
+ slapi_pblock_get (pb, SLAPI_TXN, &txn);
slapi_pblock_get (pb, SLAPI_MODRDN_TARGET_ENTRY, &target_entry);
if(target_entry==NULL)
{
@@ -417,7 +421,7 @@ urp_modrdn_operation( Slapi_PBlock *pb )
Unique ID already in RDN - Change to Lost and Found entry */
goto bailout;
}
- mod_namingconflict_attr (op_uniqueid, target_sdn, existing_sdn, opcsn);
+ mod_namingconflict_attr (op_uniqueid, target_sdn, existing_sdn, opcsn, txn);
slapi_pblock_set(pb, SLAPI_MODRDN_NEWRDN, newrdn_with_uniqueid);
slapi_log_error(slapi_log_urp, sessionid,
"Naming conflict MODRDN. Rename target entry to %s\n",
@@ -432,7 +436,7 @@ urp_modrdn_operation( Slapi_PBlock *pb )
{
/* The existing entry is a loser */
- int resolve = urp_annotate_dn (sessionid, existing_entry, opcsn, "MODRDN");
+ int resolve = urp_annotate_dn (sessionid, existing_entry, opcsn, "MODRDN", txn);
if(!resolve)
{
op_result= LDAP_OPERATIONS_ERROR;
@@ -543,7 +547,7 @@ urp_modrdn_operation( Slapi_PBlock *pb )
bailout:
if ( del_old_replconflict_attr && rc == 0 )
{
- del_replconflict_attr (target_entry, opcsn, 0);
+ del_replconflict_attr (target_entry, opcsn, 0, txn);
}
if ( parentdn )
slapi_sdn_free(&parentdn);
@@ -561,12 +565,14 @@ urp_delete_operation( Slapi_PBlock *pb )
char sessionid[REPL_SESSION_ID_SIZE];
int op_result= 0;
int rc= 0; /* OK */
+ void *txn = NULL;
if ( slapi_op_abandoned(pb) )
{
return rc;
}
+ slapi_pblock_get(pb, SLAPI_TXN, &txn);
slapi_pblock_get(pb, SLAPI_DELETE_EXISTING_ENTRY, &deleteentry);
if(deleteentry==NULL) /* uniqueid can't be found */
@@ -592,14 +598,14 @@ urp_delete_operation( Slapi_PBlock *pb )
if(!slapi_entry_has_children(deleteentry))
{
/* Remove possible conflict attributes */
- del_replconflict_attr (deleteentry, opcsn, 0);
+ del_replconflict_attr (deleteentry, opcsn, 0, txn);
rc= 0; /* OK, to delete the entry */
PROFILE_POINT; /* Delete Operation; OK. */
}
else
{
/* Turn this entry into a glue_absent_parent entry */
- entry_to_glue(sessionid, deleteentry, REASON_RESURRECT_ENTRY, opcsn);
+ entry_to_glue(sessionid, deleteentry, REASON_RESURRECT_ENTRY, opcsn, txn);
/* Turn the Delete into a No-Op */
op_result= LDAP_SUCCESS;
@@ -712,7 +718,7 @@ urp_post_delete_operation( Slapi_PBlock *pb )
}
int
-urp_fixup_add_entry (Slapi_Entry *e, const char *target_uniqueid, const char *parentuniqueid, CSN *opcsn, int opflags)
+urp_fixup_add_entry (Slapi_Entry *e, const char *target_uniqueid, const char *parentuniqueid, CSN *opcsn, int opflags, void *txn)
{
Slapi_PBlock *newpb;
Slapi_Operation *op;
@@ -743,6 +749,7 @@ urp_fixup_add_entry (Slapi_Entry *e, const char *target_uniqueid, const char *pa
slapi_pblock_get ( newpb, SLAPI_OPERATION, &op );
operation_set_csn ( op, opcsn );
+ slapi_pblock_set ( newpb, SLAPI_TXN, txn );
slapi_add_internal_pb ( newpb );
slapi_pblock_get ( newpb, SLAPI_PLUGIN_INTOP_RESULT, &op_result );
slapi_pblock_destroy ( newpb );
@@ -751,7 +758,7 @@ urp_fixup_add_entry (Slapi_Entry *e, const char *target_uniqueid, const char *pa
}
int
-urp_fixup_rename_entry (Slapi_Entry *entry, const char *newrdn, int opflags)
+urp_fixup_rename_entry (Slapi_Entry *entry, const char *newrdn, int opflags, void *txn)
{
Slapi_PBlock *newpb;
Slapi_Operation *op;
@@ -780,6 +787,7 @@ urp_fixup_rename_entry (Slapi_Entry *entry, const char *newrdn, int opflags)
slapi_pblock_get (newpb, SLAPI_OPERATION, &op);
operation_set_csn (op, opcsn);
+ slapi_pblock_set(newpb, SLAPI_TXN, txn);
slapi_modrdn_internal_pb(newpb);
slapi_pblock_get(newpb, SLAPI_PLUGIN_INTOP_RESULT, &op_result);
@@ -788,7 +796,7 @@ urp_fixup_rename_entry (Slapi_Entry *entry, const char *newrdn, int opflags)
}
int
-urp_fixup_delete_entry (const char *uniqueid, const char *dn, CSN *opcsn, int opflags)
+urp_fixup_delete_entry (const char *uniqueid, const char *dn, CSN *opcsn, int opflags, void *txn)
{
Slapi_PBlock *newpb;
Slapi_Operation *op;
@@ -810,6 +818,7 @@ urp_fixup_delete_entry (const char *uniqueid, const char *dn, CSN *opcsn, int op
slapi_pblock_get ( newpb, SLAPI_OPERATION, &op );
operation_set_csn ( op, opcsn );
+ slapi_pblock_set ( newpb, SLAPI_TXN, txn );
slapi_delete_internal_pb ( newpb );
slapi_pblock_get ( newpb, SLAPI_PLUGIN_INTOP_RESULT, &op_result );
slapi_pblock_destroy ( newpb );
@@ -818,7 +827,7 @@ urp_fixup_delete_entry (const char *uniqueid, const char *dn, CSN *opcsn, int op
}
int
-urp_fixup_modify_entry (const char *uniqueid, const Slapi_DN *sdn, CSN *opcsn, Slapi_Mods *smods, int opflags)
+urp_fixup_modify_entry (const char *uniqueid, const Slapi_DN *sdn, CSN *opcsn, Slapi_Mods *smods, int opflags, void *txn)
{
Slapi_PBlock *newpb;
Slapi_Operation *op;
@@ -839,6 +848,7 @@ urp_fixup_modify_entry (const char *uniqueid, const Slapi_DN *sdn, CSN *opcsn, S
slapi_pblock_get (newpb, SLAPI_OPERATION, &op);
operation_set_csn (op, opcsn);
+ slapi_pblock_set (newpb, SLAPI_TXN, txn);
/* do modify */
slapi_modify_internal_pb (newpb);
slapi_pblock_get (newpb, SLAPI_PLUGIN_INTOP_RESULT, &op_result);
@@ -962,7 +972,7 @@ bailout:
* a new entry (the operation entry) see urp_add_operation.
*/
static int
-urp_annotate_dn (char *sessionid, Slapi_Entry *entry, CSN *opcsn, const char *optype)
+urp_annotate_dn (char *sessionid, Slapi_Entry *entry, CSN *opcsn, const char *optype, void *txn)
{
int rc = 0; /* Fail */
int op_result;
@@ -978,8 +988,8 @@ urp_annotate_dn (char *sessionid, Slapi_Entry *entry, CSN *opcsn, const char *op
newrdn = get_rdn_plus_uniqueid ( sessionid, basedn, uniqueid );
if(newrdn!=NULL)
{
- mod_namingconflict_attr (uniqueid, basesdn, basesdn, opcsn);
- op_result = urp_fixup_rename_entry ( entry, newrdn, 0 );
+ mod_namingconflict_attr (uniqueid, basesdn, basesdn, opcsn, txn);
+ op_result = urp_fixup_rename_entry ( entry, newrdn, 0, txn );
switch(op_result)
{
case LDAP_SUCCESS:
@@ -1041,7 +1051,9 @@ urp_get_min_naming_conflict_entry ( Slapi_PBlock *pb, char *sessionid, CSN *opcs
int i = 0;
int min_i = -1;
int op_result = LDAP_SUCCESS;
+ void *txn = NULL;
+ slapi_pblock_get (pb, SLAPI_TXN, &txn);
slapi_pblock_get (pb, SLAPI_URP_NAMING_COLLISION_DN, &basedn);
if (NULL == basedn || strncmp (basedn, SLAPI_ATTR_UNIQUEID, strlen(SLAPI_ATTR_UNIQUEID)) == 0)
return NULL;
@@ -1068,6 +1080,7 @@ urp_get_min_naming_conflict_entry ( Slapi_PBlock *pb, char *sessionid, CSN *opcs
NULL, /* UniqueID */
repl_get_plugin_identity(PLUGIN_MULTIMASTER_REPLICATION),
0);
+ slapi_pblock_set(newpb, SLAPI_TXN, txn);
slapi_search_internal_pb(newpb);
slapi_pblock_get(newpb, SLAPI_PLUGIN_INTOP_RESULT, &op_result);
slapi_pblock_get(newpb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries);
@@ -1133,6 +1146,9 @@ urp_naming_conflict_removal ( Slapi_PBlock *pb, char *sessionid, CSN *opcsn, con
Slapi_RDN *oldrdn, *newrdn;
const char *oldrdnstr, *newrdnstr;
int op_result;
+ void *txn = NULL;
+
+ slapi_pblock_get (pb, SLAPI_TXN, &txn);
/*
* Backend op has set SLAPI_URP_NAMING_COLLISION_DN to the basedn.
@@ -1158,7 +1174,7 @@ urp_naming_conflict_removal ( Slapi_PBlock *pb, char *sessionid, CSN *opcsn, con
* is done after DB lock was released. The backend modrdn
* will acquire the DB lock if it sees this flag.
*/
- op_result = urp_fixup_rename_entry (min_naming_conflict_entry, newrdnstr, OP_FLAG_ACTION_INVOKE_FOR_REPLOP);
+ op_result = urp_fixup_rename_entry (min_naming_conflict_entry, newrdnstr, OP_FLAG_ACTION_INVOKE_FOR_REPLOP, txn);
if ( op_result != LDAP_SUCCESS )
{
slapi_log_error (slapi_log_urp, sessionid,
@@ -1173,7 +1189,7 @@ urp_naming_conflict_removal ( Slapi_PBlock *pb, char *sessionid, CSN *opcsn, con
* A fixup op will not invoke urp_modrdn_operation(). Even it does,
* urp_modrdn_operation() will do nothing because of the same CSN.
*/
- op_result = del_replconflict_attr (min_naming_conflict_entry, opcsn, OP_FLAG_ACTION_INVOKE_FOR_REPLOP);
+ op_result = del_replconflict_attr (min_naming_conflict_entry, opcsn, OP_FLAG_ACTION_INVOKE_FOR_REPLOP, txn);
if (op_result != LDAP_SUCCESS) {
slapi_log_error(SLAPI_LOG_REPL, sessionid,
"Failed to remove nsds5ReplConflict for %s, err=%d\n",
@@ -1277,7 +1293,7 @@ is_suffix_dn ( Slapi_PBlock *pb, const Slapi_DN *dn, Slapi_DN **parentdn )
static int
mod_namingconflict_attr (const char *uniqueid, const Slapi_DN *entrysdn,
- const Slapi_DN *conflictsdn, CSN *opcsn)
+ const Slapi_DN *conflictsdn, CSN *opcsn, void *txn)
{
Slapi_Mods smods;
char buf[BUFSIZ];
@@ -1300,13 +1316,13 @@ mod_namingconflict_attr (const char *uniqueid, const Slapi_DN *entrysdn,
*/
slapi_mods_add (&smods, LDAP_MOD_REPLACE, ATTR_NSDS5_REPLCONFLICT, strlen(buf), buf);
}
- op_result = urp_fixup_modify_entry (uniqueid, entrysdn, opcsn, &smods, 0);
+ op_result = urp_fixup_modify_entry (uniqueid, entrysdn, opcsn, &smods, 0, txn);
slapi_mods_done (&smods);
return op_result;
}
static int
-del_replconflict_attr (Slapi_Entry *entry, CSN *opcsn, int opflags)
+del_replconflict_attr (Slapi_Entry *entry, CSN *opcsn, int opflags, void *txn)
{
Slapi_Attr *attr;
int op_result = 0;
@@ -1321,7 +1337,7 @@ del_replconflict_attr (Slapi_Entry *entry, CSN *opcsn, int opflags)
entrysdn = slapi_entry_get_sdn_const (entry);
slapi_mods_init (&smods, 2);
slapi_mods_add (&smods, LDAP_MOD_DELETE, ATTR_NSDS5_REPLCONFLICT, 0, NULL);
- op_result = urp_fixup_modify_entry (uniqueid, entrysdn, opcsn, &smods, opflags);
+ op_result = urp_fixup_modify_entry (uniqueid, entrysdn, opcsn, &smods, opflags, txn);
slapi_mods_done (&smods);
}
return op_result;
diff --git a/ldap/servers/plugins/replication/urp.h b/ldap/servers/plugins/replication/urp.h
index 2ca7ad2..77ac8a4 100644
--- a/ldap/servers/plugins/replication/urp.h
+++ b/ldap/servers/plugins/replication/urp.h
@@ -57,10 +57,10 @@ int urp_modrdn_operation( Slapi_PBlock *pb );
int urp_post_modrdn_operation( Slapi_PBlock *pb );
/* urp internal ops */
-int urp_fixup_add_entry (Slapi_Entry *e, const char *target_uniqueid, const char *parentuniqueid, CSN *opcsn, int opflags);
-int urp_fixup_delete_entry (const char *uniqueid, const char *dn, CSN *opcsn, int opflags);
-int urp_fixup_rename_entry (Slapi_Entry *entry, const char *newrdn, int opflags);
-int urp_fixup_modify_entry (const char *uniqueid, const Slapi_DN *sdn, CSN *opcsn, Slapi_Mods *smods, int opflags);
+int urp_fixup_add_entry (Slapi_Entry *e, const char *target_uniqueid, const char *parentuniqueid, CSN *opcsn, int opflags, void *txn);
+int urp_fixup_delete_entry (const char *uniqueid, const char *dn, CSN *opcsn, int opflags, void *txn);
+int urp_fixup_rename_entry (Slapi_Entry *entry, const char *newrdn, int opflags, void *txn);
+int urp_fixup_modify_entry (const char *uniqueid, const Slapi_DN *sdn, CSN *opcsn, Slapi_Mods *smods, int opflags, void *txn);
int is_suffix_dn (Slapi_PBlock *pb, const Slapi_DN *dn, Slapi_DN **parenddn);
@@ -69,7 +69,7 @@ int is_suffix_dn (Slapi_PBlock *pb, const Slapi_DN *dn, Slapi_DN **parenddn);
*/
int is_glue_entry(const Slapi_Entry* entry);
int create_glue_entry ( Slapi_PBlock *pb, char *sessionid, Slapi_DN *dn, const char *uniqueid, CSN *opcsn );
-int entry_to_glue(char *sessionid, const Slapi_Entry* entry, const char *reason, CSN *opcsn);
+int entry_to_glue(char *sessionid, const Slapi_Entry* entry, const char *reason, CSN *opcsn, void *txn);
int glue_to_entry (Slapi_PBlock *pb, Slapi_Entry *entry );
PRBool get_glue_csn(const Slapi_Entry *entry, const CSN **gluecsn);
diff --git a/ldap/servers/plugins/replication/urp_glue.c b/ldap/servers/plugins/replication/urp_glue.c
index e51712c..499cb97 100644
--- a/ldap/servers/plugins/replication/urp_glue.c
+++ b/ldap/servers/plugins/replication/urp_glue.c
@@ -92,7 +92,7 @@ get_glue_csn(const Slapi_Entry *entry, const CSN **gluecsn)
* Submit a Modify operation to turn the Entry into Glue.
*/
int
-entry_to_glue(char *sessionid, const Slapi_Entry* entry, const char *reason, CSN *opcsn)
+entry_to_glue(char *sessionid, const Slapi_Entry* entry, const char *reason, CSN *opcsn, void *txn)
{
int op_result = 0;
const char *dn;
@@ -135,7 +135,7 @@ entry_to_glue(char *sessionid, const Slapi_Entry* entry, const char *reason, CSN
if (slapi_mods_get_num_mods(&smods) > 0)
{
- op_result = urp_fixup_modify_entry (NULL, sdn, opcsn, &smods, 0);
+ op_result = urp_fixup_modify_entry (NULL, sdn, opcsn, &smods, 0, txn);
if (op_result == LDAP_SUCCESS)
{
slapi_log_error (slapi_log_urp, repl_plugin_name,
@@ -158,7 +158,7 @@ static const char *glue_entry =
"%s: %s\n"; /* Add why it's been created */
static int
-do_create_glue_entry(const Slapi_RDN *rdn, const Slapi_DN *superiordn, const char *uniqueid, const char *reason, CSN *opcsn)
+do_create_glue_entry(const Slapi_RDN *rdn, const Slapi_DN *superiordn, const char *uniqueid, const char *reason, CSN *opcsn, void *txn)
{
int op_result= LDAP_OPERATIONS_ERROR;
int rdnval_index = 0;
@@ -202,7 +202,7 @@ do_create_glue_entry(const Slapi_RDN *rdn, const Slapi_DN *superiordn, const cha
if ( e!=NULL )
{
slapi_entry_set_uniqueid (e, slapi_ch_strdup(uniqueid));
- op_result = urp_fixup_add_entry (e, NULL, NULL, opcsn, 0);
+ op_result = urp_fixup_add_entry (e, NULL, NULL, opcsn, 0, txn);
}
slapi_ch_free_string(&estr);
slapi_sdn_free(&sdn);
@@ -214,12 +214,14 @@ create_glue_entry ( Slapi_PBlock *pb, char *sessionid, Slapi_DN *dn, const char
{
int op_result;
const char *dnstr;
+ void *txn = NULL;
if ( slapi_sdn_get_dn (dn) )
dnstr = slapi_sdn_get_dn (dn);
else
dnstr = "";
+ slapi_pblock_get(pb, SLAPI_TXN, &txn);
if ( NULL == uniqueid )
{
op_result = LDAP_OPERATIONS_ERROR;
@@ -239,7 +241,7 @@ create_glue_entry ( Slapi_PBlock *pb, char *sessionid, Slapi_DN *dn, const char
while(!done)
{
- op_result= do_create_glue_entry(rdn, superiordn, uniqueid, "missingEntry", opcsn);
+ op_result= do_create_glue_entry(rdn, superiordn, uniqueid, "missingEntry", opcsn, txn);
switch(op_result)
{
case LDAP_SUCCESS:
diff --git a/ldap/servers/plugins/replication/urp_tombstone.c b/ldap/servers/plugins/replication/urp_tombstone.c
index 6dd9a2a..7c36421 100644
--- a/ldap/servers/plugins/replication/urp_tombstone.c
+++ b/ldap/servers/plugins/replication/urp_tombstone.c
@@ -94,6 +94,10 @@ tombstone_to_glue_resolve_parent (
{
int op_result;
Slapi_PBlock *newpb= slapi_pblock_new();
+ void *txn = NULL;
+
+ slapi_pblock_get(pb, SLAPI_TXN, &txn);
+ slapi_pblock_set(newpb, SLAPI_TXN, txn);
slapi_search_internal_set_pb(
newpb,
slapi_sdn_get_dn(parentdn), /* JCM - This DN just identifies the backend to be searched. */
@@ -156,6 +160,7 @@ tombstone_to_glue (
Slapi_Entry *addingentry;
const char *addingdn;
int op_result;
+ void *txn = NULL;
/* JCMREPL
* Nothing logged to the 5.0 Change Log
@@ -189,7 +194,8 @@ tombstone_to_glue (
slapi_entry_add_string(addingentry, ATTR_NSDS5_REPLCONFLICT, reason);
}
tombstoneuniqueid= slapi_entry_get_uniqueid(tombstoneentry);
- op_result = urp_fixup_add_entry (addingentry, tombstoneuniqueid, parentuniqueid, opcsn, OP_FLAG_RESURECT_ENTRY);
+ slapi_pblock_get (pb, SLAPI_TXN, &txn);
+ op_result = urp_fixup_add_entry (addingentry, tombstoneuniqueid, parentuniqueid, opcsn, OP_FLAG_RESURECT_ENTRY, txn);
if (op_result == LDAP_SUCCESS)
{
slapi_log_error (slapi_log_urp, repl_plugin_name,
@@ -213,6 +219,7 @@ entry_to_tombstone ( Slapi_PBlock *pb, Slapi_Entry *entry )
CSN *opcsn;
const char *uniqueid;
int op_result = LDAP_SUCCESS;
+ void *txn = NULL;
slapi_pblock_get ( pb, SLAPI_OPERATION, &op );
opcsn = operation_get_csn ( op );
@@ -227,9 +234,10 @@ entry_to_tombstone ( Slapi_PBlock *pb, Slapi_Entry *entry )
*/
slapi_mods_add ( &smods, LDAP_MOD_DELETE, ATTR_NSDS5_REPLCONFLICT, 0, NULL );
+ slapi_pblock_get (pb, SLAPI_TXN, &txn);
op_result = urp_fixup_modify_entry (uniqueid,
slapi_entry_get_sdn_const (entry),
- opcsn, &smods, 0);
+ opcsn, &smods, 0, txn);
slapi_mods_done ( &smods );
/*
@@ -242,7 +250,7 @@ entry_to_tombstone ( Slapi_PBlock *pb, Slapi_Entry *entry )
* through the urp operations and trigger the recursive
* fixup if applicable.
*/
- op_result = urp_fixup_delete_entry (uniqueid, slapi_entry_get_dn_const (entry), opcsn, 0);
+ op_result = urp_fixup_delete_entry (uniqueid, slapi_entry_get_dn_const (entry), opcsn, 0, txn);
}
return op_result;
diff --git a/ldap/servers/plugins/retrocl/retrocl_po.c b/ldap/servers/plugins/retrocl/retrocl_po.c
index 29ce79f..729ffbb 100644
--- a/ldap/servers/plugins/retrocl/retrocl_po.c
+++ b/ldap/servers/plugins/retrocl/retrocl_po.c
@@ -178,12 +178,15 @@ write_replog_db(
changeNumber changenum;
int i;
int extensibleObject = 0;
+ void *txn = NULL;
if (!dn) {
slapi_log_error( SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME, "write_replog_db: NULL dn\n");
return;
}
+ slapi_pblock_get(pb, SLAPI_TXN, &txn);
+
PR_Lock(retrocl_internal_lock);
changenum = retrocl_assign_changenumber();
@@ -361,6 +364,7 @@ write_replog_db(
slapi_add_entry_internal_set_pb( newPb, e, NULL /* controls */,
g_plg_identity[PLUGIN_RETROCL],
0 /* actions */ );
+ slapi_pblock_set (newPb, SLAPI_TXN, txn);
slapi_add_internal_pb (newPb);
slapi_pblock_get( newPb, SLAPI_PLUGIN_INTOP_RESULT, &rc );
slapi_pblock_destroy(newPb);
diff --git a/ldap/servers/plugins/uiduniq/plugin-utils.h b/ldap/servers/plugins/uiduniq/plugin-utils.h
index 5cdd95b..9c5eeb1 100644
--- a/ldap/servers/plugins/uiduniq/plugin-utils.h
+++ b/ldap/servers/plugins/uiduniq/plugin-utils.h
@@ -87,10 +87,10 @@
int op_error(int internal_error);
Slapi_PBlock *readPblockAndEntry( const char *baseDN, const char *filter,
- char *attrs[] );
+ char *attrs[], void *txn, void *pluginid );
int entryHasObjectClass(Slapi_PBlock *pb, Slapi_Entry *e,
const char *objectClass);
-Slapi_PBlock *dnHasObjectClass( const char *baseDN, const char *objectClass );
-Slapi_PBlock *dnHasAttribute( const char *baseDN, const char *attrName );
+Slapi_PBlock *dnHasObjectClass( const char *baseDN, const char *objectClass, void *txn, void *pluginid );
+Slapi_PBlock *dnHasAttribute( const char *baseDN, const char *attrName, void *txn, void *pluginid );
#endif /* _PLUGIN_UTILS_H_ */
diff --git a/ldap/servers/plugins/uiduniq/uid.c b/ldap/servers/plugins/uiduniq/uid.c
index 8bd5e17..e1b855c 100644
--- a/ldap/servers/plugins/uiduniq/uid.c
+++ b/ldap/servers/plugins/uiduniq/uid.c
@@ -70,7 +70,7 @@ int ldap_quote_filter_value(
static int search_one_berval(const char *baseDN, const char *attrName,
- const struct berval *value, const char *requiredObjectClass, const char *target);
+ const struct berval *value, const char *requiredObjectClass, const char *target, void *txn);
/*
* ISSUES:
@@ -226,7 +226,7 @@ create_filter(const char *attribute, const struct berval *value, const char *req
static int
search(const char *baseDN, const char *attrName, Slapi_Attr *attr,
struct berval **values, const char *requiredObjectClass,
- const char *target)
+ const char *target, void *txn)
{
int result;
@@ -260,7 +260,7 @@ search(const char *baseDN, const char *attrName, Slapi_Attr *attr,
{
result = search_one_berval(baseDN, attrName,
slapi_value_get_berval(v),
- requiredObjectClass, target);
+ requiredObjectClass, target, txn);
}
}
else
@@ -268,7 +268,7 @@ search(const char *baseDN, const char *attrName, Slapi_Attr *attr,
for (;*values != NULL && LDAP_SUCCESS == result; values++)
{
result = search_one_berval(baseDN, attrName, *values, requiredObjectClass,
- target);
+ target, txn);
}
}
@@ -284,7 +284,7 @@ search(const char *baseDN, const char *attrName, Slapi_Attr *attr,
static int
search_one_berval(const char *baseDN, const char *attrName,
const struct berval *value, const char *requiredObjectClass,
- const char *target)
+ const char *target, void *txn)
{
int result;
char *filter;
@@ -319,6 +319,7 @@ search_one_berval(const char *baseDN, const char *attrName,
slapi_search_internal_set_pb(spb, baseDN, LDAP_SCOPE_SUBTREE,
filter, attrs, 0 /* attrs only */, NULL, NULL, plugin_identity, 0 /* actions */);
+ slapi_pblock_set(spb, SLAPI_TXN, txn);
slapi_search_internal_pb(spb);
err = slapi_pblock_get(spb, SLAPI_PLUGIN_INTOP_RESULT, &sres);
@@ -394,7 +395,7 @@ search_one_berval(const char *baseDN, const char *attrName,
static int
searchAllSubtrees(int argc, char *argv[], const char *attrName,
Slapi_Attr *attr, struct berval **values, const char *requiredObjectClass,
- const char *dn)
+ const char *dn, void *txn)
{
int result = LDAP_SUCCESS;
@@ -409,7 +410,7 @@ searchAllSubtrees(int argc, char *argv[], const char *attrName,
* worry about that here.
*/
if (slapi_dn_issuffix(dn, *argv)) {
- result = search(*argv, attrName, attr, values, requiredObjectClass, dn);
+ result = search(*argv, attrName, attr, values, requiredObjectClass, dn, txn);
if (result) break;
}
}
@@ -499,14 +500,14 @@ getArguments(Slapi_PBlock *pb, char **attrName, char **markerObjectClass,
static int
findSubtreeAndSearch(char *parentDN, const char *attrName, Slapi_Attr *attr,
struct berval **values, const char *requiredObjectClass, const char *target,
- const char *markerObjectClass)
+ const char *markerObjectClass, void *txn)
{
int result = LDAP_SUCCESS;
Slapi_PBlock *spb = NULL;
while (NULL != (parentDN = slapi_dn_parent(parentDN)))
{
- if ((spb = dnHasObjectClass(parentDN, markerObjectClass)))
+ if ((spb = dnHasObjectClass(parentDN, markerObjectClass, txn, plugin_identity)))
{
freePblock(spb);
/*
@@ -514,7 +515,7 @@ findSubtreeAndSearch(char *parentDN, const char *attrName, Slapi_Attr *attr,
* to have the attribute already.
*/
result = search(parentDN, attrName, attr, values, requiredObjectClass,
- target);
+ target, txn);
break;
}
}
@@ -554,6 +555,7 @@ preop_add(Slapi_PBlock *pb)
Slapi_Attr *attr;
int argc;
char **argv = NULL;
+ void *txn = NULL;
/*
* If this is a replication update, just be a noop.
@@ -565,6 +567,7 @@ preop_add(Slapi_PBlock *pb)
break;
}
+ slapi_pblock_get(pb, SLAPI_TXN, &txn);
/*
* Get the arguments
*/
@@ -631,12 +634,12 @@ preop_add(Slapi_PBlock *pb)
/* Subtree defined by location of marker object class */
result = findSubtreeAndSearch((char *)dn, attrName, attr, NULL,
requiredObjectClass, dn,
- markerObjectClass);
+ markerObjectClass, txn);
} else
{
/* Subtrees listed on invocation line */
result = searchAllSubtrees(argc, argv, attrName, attr, NULL,
- requiredObjectClass, dn);
+ requiredObjectClass, dn, txn);
}
END
@@ -708,6 +711,7 @@ preop_modify(Slapi_PBlock *pb)
int isupdatedn;
int argc;
char **argv = NULL;
+ void *txn = NULL;
/*
* If this is a replication update, just be a noop.
@@ -719,6 +723,7 @@ preop_modify(Slapi_PBlock *pb)
break;
}
+ slapi_pblock_get(pb, SLAPI_TXN, &txn);
/*
* Get the arguments
*/
@@ -780,7 +785,7 @@ preop_modify(Slapi_PBlock *pb)
* Check if it has the required object class
*/
if (requiredObjectClass &&
- !(spb = dnHasObjectClass(dn, requiredObjectClass))) {
+ !(spb = dnHasObjectClass(dn, requiredObjectClass, txn, plugin_identity))) {
break;
}
@@ -800,12 +805,12 @@ preop_modify(Slapi_PBlock *pb)
/* Subtree defined by location of marker object class */
result = findSubtreeAndSearch((char *)dn, attrName, NULL,
mod->mod_bvalues, requiredObjectClass,
- dn, markerObjectClass);
+ dn, markerObjectClass, txn);
} else
{
/* Subtrees listed on invocation line */
result = searchAllSubtrees(argc, argv, attrName, NULL,
- mod->mod_bvalues, requiredObjectClass, dn);
+ mod->mod_bvalues, requiredObjectClass, dn, txn);
}
}
END
@@ -866,6 +871,7 @@ preop_modrdn(Slapi_PBlock *pb)
Slapi_Attr *attr;
int argc;
char **argv = NULL;
+ void *txn = NULL;
/*
* If this is a replication update, just be a noop.
@@ -877,6 +883,7 @@ preop_modrdn(Slapi_PBlock *pb)
break;
}
+ slapi_pblock_get(pb, SLAPI_TXN, &txn);
/*
* Get the arguments
*/
@@ -935,7 +942,7 @@ preop_modrdn(Slapi_PBlock *pb)
/* Get the entry that is being renamed so we can make a dummy copy
* of what it will look like after the rename. */
- err = slapi_search_internal_get_entry(sdn, NULL, &e, plugin_identity);
+ err = slapi_search_internal_get_entry_ext(sdn, NULL, &e, plugin_identity, txn);
if (err != LDAP_SUCCESS) {
result = uid_op_error(35);
/* We want to return a no such object error if the target doesn't exist. */
@@ -971,12 +978,12 @@ preop_modrdn(Slapi_PBlock *pb)
/* Subtree defined by location of marker object class */
result = findSubtreeAndSearch(slapi_entry_get_dn(e), attrName, attr, NULL,
requiredObjectClass, dn,
- markerObjectClass);
+ markerObjectClass, txn);
} else
{
/* Subtrees listed on invocation line */
result = searchAllSubtrees(argc, argv, attrName, attr, NULL,
- requiredObjectClass, dn);
+ requiredObjectClass, dn, txn);
}
END
/* Clean-up */
diff --git a/ldap/servers/plugins/uiduniq/utils.c b/ldap/servers/plugins/uiduniq/utils.c
index 4966089..567218a 100644
--- a/ldap/servers/plugins/uiduniq/utils.c
+++ b/ldap/servers/plugins/uiduniq/utils.c
@@ -82,19 +82,22 @@ op_error(int internal_error) {
*/
Slapi_PBlock *
readPblockAndEntry( const char *baseDN, const char *filter,
- char *attrs[] ) {
+ char *attrs[], void *txn, void *pluginid ) {
Slapi_PBlock *spb = NULL;
BEGIN
int sres;
- /* Perform the search - the new pblock needs to be freed */
- spb = slapi_search_internal((char *)baseDN, LDAP_SCOPE_BASE,
- (char *)filter, NULL, attrs, 0);
- if ( !spb ) {
+ spb = slapi_pblock_new();
+ if (!spb) {
op_error(20);
break;
}
+ slapi_search_internal_set_pb (spb, baseDN, LDAP_SCOPE_BASE, filter,
+ attrs, 0, NULL,
+ NULL, pluginid, 0);
+ slapi_pblock_set(spb, SLAPI_TXN, txn);
+ slapi_search_internal_pb (spb);
if ( slapi_pblock_get( spb, SLAPI_PLUGIN_INTOP_RESULT, &sres ) ) {
op_error(21);
@@ -150,7 +153,7 @@ entryHasObjectClass(Slapi_PBlock *pb, Slapi_Entry *e,
* A pblock containing the entry, or NULL
*/
Slapi_PBlock *
-dnHasObjectClass( const char *baseDN, const char *objectClass ) {
+dnHasObjectClass( const char *baseDN, const char *objectClass, void *txn, void *pluginid ) {
char *filter = NULL;
Slapi_PBlock *spb = NULL;
@@ -162,7 +165,7 @@ dnHasObjectClass( const char *baseDN, const char *objectClass ) {
attrs[0] = "objectclass";
attrs[1] = NULL;
filter = PR_smprintf("objectclass=%s", objectClass );
- if ( !(spb = readPblockAndEntry( baseDN, filter, attrs) ) ) {
+ if ( !(spb = readPblockAndEntry( baseDN, filter, attrs, txn, pluginid ) ) ) {
break;
}
@@ -196,7 +199,7 @@ dnHasObjectClass( const char *baseDN, const char *objectClass ) {
* The entry, or NULL
*/
Slapi_PBlock *
-dnHasAttribute( const char *baseDN, const char *attrName ) {
+dnHasAttribute( const char *baseDN, const char *attrName, void *txn, void *pluginid ) {
Slapi_PBlock *spb = NULL;
char *filter = NULL;
@@ -209,12 +212,16 @@ dnHasAttribute( const char *baseDN, const char *attrName ) {
attrs[0] = (char *)attrName;
attrs[1] = NULL;
filter = PR_smprintf( "%s=*", attrName );
- spb = slapi_search_internal((char *)baseDN, LDAP_SCOPE_BASE,
- filter, NULL, attrs, 0);
- if ( !spb ) {
+ spb = slapi_pblock_new();
+ if (!spb) {
op_error(20);
break;
}
+ slapi_search_internal_set_pb (spb, baseDN, LDAP_SCOPE_BASE, filter,
+ attrs, 0, NULL,
+ NULL, pluginid, 0);
+ slapi_pblock_set(spb, SLAPI_TXN, txn);
+ slapi_search_internal_pb (spb);
if ( slapi_pblock_get( spb, SLAPI_PLUGIN_INTOP_RESULT, &sres ) ) {
op_error(21);
diff --git a/ldap/servers/slapd/modify.c b/ldap/servers/slapd/modify.c
index a0af006..e872f35 100644
--- a/ldap/servers/slapd/modify.c
+++ b/ldap/servers/slapd/modify.c
@@ -1013,6 +1013,7 @@ static int op_shared_allow_pw_change (Slapi_PBlock *pb, LDAPMod *mod, char **old
char *proxydn = NULL;
char *proxystr = NULL;
char *errtext = NULL;
+ void *txn = NULL;
slapi_pblock_get (pb, SLAPI_IS_REPLICATED_OPERATION, &repl_op);
if (repl_op) {
@@ -1027,6 +1028,7 @@ static int op_shared_allow_pw_change (Slapi_PBlock *pb, LDAPMod *mod, char **old
slapi_pblock_get (pb, SLAPI_OPERATION, &operation);
slapi_pblock_get (pb, SLAPI_PWPOLICY, &pwresponse_req);
internal_op= operation_is_flag_set(operation, OP_FLAG_INTERNAL);
+ slapi_pblock_get (pb, SLAPI_TXN, &txn);
slapi_sdn_init_dn_byref (&sdn, dn);
pwpolicy = new_passwdPolicy(pb, (char *)slapi_sdn_get_ndn(&sdn));
@@ -1056,7 +1058,7 @@ static int op_shared_allow_pw_change (Slapi_PBlock *pb, LDAPMod *mod, char **old
mods[1] = NULL;
/* We need to actually fetch the target here to use for ACI checking. */
- slapi_search_internal_get_entry(&sdn, NULL, &e, (void *)plugin_get_default_component_id());
+ slapi_search_internal_get_entry_ext(&sdn, NULL, &e, (void *)plugin_get_default_component_id(), txn);
/* Create a bogus entry with just the target dn if we were unable to
* find the actual entry. This will only be used for checking the ACIs. */
diff --git a/ldap/servers/slapd/passwd_extop.c b/ldap/servers/slapd/passwd_extop.c
index c77d3b7..c05dd81 100644
--- a/ldap/servers/slapd/passwd_extop.c
+++ b/ldap/servers/slapd/passwd_extop.c
@@ -153,6 +153,7 @@ passwd_apply_mods(Slapi_PBlock *pb_orig, const Slapi_DN *sdn, Slapi_Mods *mods,
LDAPControl **req_controls_copy = NULL;
LDAPControl **pb_resp_controls = NULL;
int ret=0;
+ void *txn = NULL;
LDAPDebug( LDAP_DEBUG_TRACE, "=> passwd_apply_mods\n", 0, 0, 0 );
@@ -179,6 +180,9 @@ passwd_apply_mods(Slapi_PBlock *pb_orig, const Slapi_DN *sdn, Slapi_Mods *mods,
* that it was done by the root DN. */
pb.pb_conn = pb_orig->pb_conn;
+ slapi_pblock_get(pb_orig, SLAPI_TXN, &txn);
+ slapi_pblock_set(&pb, SLAPI_TXN, txn);
+
ret =slapi_modify_internal_pb (&pb);
/* We now clean up the connection that we copied into the
diff --git a/ldap/servers/slapd/proto-slap.h b/ldap/servers/slapd/proto-slap.h
index da58f9b..9714871 100644
--- a/ldap/servers/slapd/proto-slap.h
+++ b/ldap/servers/slapd/proto-slap.h
@@ -862,6 +862,7 @@ void pw_add_allowchange_aci(Slapi_Entry *e, int pw_prohibit_change);
*/
int update_pw_retry ( Slapi_PBlock *pb );
void pw_apply_mods(const Slapi_DN *sdn, Slapi_Mods *mods);
+void pw_apply_mods_ext(const Slapi_DN *sdn, Slapi_Mods *mods, void *txn);
void pw_set_componentID(struct slapi_componentid * cid);
struct slapi_componentid * pw_get_componentID();
diff --git a/ldap/servers/slapd/pw.c b/ldap/servers/slapd/pw.c
index ed8d2c8..58fce28 100644
--- a/ldap/servers/slapd/pw.c
+++ b/ldap/servers/slapd/pw.c
@@ -593,7 +593,9 @@ update_pw_info ( Slapi_PBlock *pb , char *old_pw) {
passwdPolicy *pwpolicy = NULL;
int internal_op = 0;
Slapi_Operation *operation = NULL;
+ void *txn = NULL;
+ slapi_pblock_get(pb, SLAPI_TXN, &txn);
slapi_pblock_get(pb, SLAPI_OPERATION, &operation);
internal_op = slapi_operation_is_flag_set(operation, SLAPI_OP_FLAG_INTERNAL);
@@ -666,7 +668,7 @@ update_pw_info ( Slapi_PBlock *pb , char *old_pw) {
} else if (prev_exp_date == SLAPD_END_TIME) {
/* Special entries' passwords never expire */
slapi_ch_free((void**)&prev_exp_date_str);
- pw_apply_mods(sdn, &smods);
+ pw_apply_mods_ext(sdn, &smods, txn);
slapi_mods_done(&smods);
delete_passwdPolicy(&pwpolicy);
return 0;
@@ -683,7 +685,7 @@ update_pw_info ( Slapi_PBlock *pb , char *old_pw) {
*/
pw_exp_date = NOT_FIRST_TIME;
} else {
- pw_apply_mods(sdn, &smods);
+ pw_apply_mods_ext(sdn, &smods, txn);
slapi_mods_done(&smods);
delete_passwdPolicy(&pwpolicy);
return 0;
@@ -697,7 +699,7 @@ update_pw_info ( Slapi_PBlock *pb , char *old_pw) {
slapi_mods_add_string(&smods, LDAP_MOD_REPLACE, "passwordExpWarned", "0");
- pw_apply_mods(sdn, &smods);
+ pw_apply_mods_ext(sdn, &smods, txn);
slapi_mods_done(&smods);
if (pb->pb_conn) { /* no conn for internal op */
/* reset c_needpw to 0 */
@@ -1080,6 +1082,7 @@ update_pw_history( Slapi_PBlock *pb, const Slapi_DN *sdn, char *old_pw )
char *str;
passwdPolicy *pwpolicy = NULL;
const char *dn = slapi_sdn_get_dn(sdn);
+ void *txn = NULL;
pwpolicy = new_passwdPolicy(pb, dn);
@@ -1138,8 +1141,10 @@ update_pw_history( Slapi_PBlock *pb, const Slapi_DN *sdn, char *old_pw )
list_of_mods[1] = NULL;
pblock_init(&mod_pb);
+ slapi_pblock_get(pb, SLAPI_TXN, &txn);
slapi_modify_internal_set_pb_ext(&mod_pb, sdn, list_of_mods, NULL, NULL,
pw_get_componentID(), 0);
+ slapi_pblock_set(&mod_pb, SLAPI_TXN, txn);
slapi_modify_internal_pb(&mod_pb);
slapi_pblock_get(&mod_pb, SLAPI_PLUGIN_INTOP_RESULT, &res);
if (res != LDAP_SUCCESS){
diff --git a/ldap/servers/slapd/pw_mgmt.c b/ldap/servers/slapd/pw_mgmt.c
index 8d99879..28b0491 100644
--- a/ldap/servers/slapd/pw_mgmt.c
+++ b/ldap/servers/slapd/pw_mgmt.c
@@ -67,7 +67,9 @@ need_new_pw( Slapi_PBlock *pb, long *t, Slapi_Entry *e, int pwresponse_req )
passwdPolicy *pwpolicy = NULL;
int pwdGraceUserTime = 0;
char graceUserTime[8];
+ void *txn = NULL;
+ slapi_pblock_get(pb, SLAPI_TXN, &txn);
slapi_mods_init (&smods, 0);
sdn = slapi_entry_get_sdn_const( e );
dn = slapi_entry_get_ndn( e );
@@ -102,9 +104,9 @@ need_new_pw( Slapi_PBlock *pb, long *t, Slapi_Entry *e, int pwresponse_req )
slapi_ch_free((void **)×tring);
slapi_mods_add_string(&smods, LDAP_MOD_REPLACE, "passwordExpWarned", "0");
- pw_apply_mods(sdn, &smods);
+ pw_apply_mods_ext(sdn, &smods, txn);
} else if (pwpolicy->pw_lockout == 1) {
- pw_apply_mods(sdn, &smods);
+ pw_apply_mods_ext(sdn, &smods, txn);
}
slapi_mods_done(&smods);
delete_passwdPolicy(&pwpolicy);
@@ -150,7 +152,7 @@ skip:
}
slapi_add_pwd_control ( pb, LDAP_CONTROL_PWEXPIRED, 0);
}
- pw_apply_mods(sdn, &smods);
+ pw_apply_mods_ext(sdn, &smods, txn);
slapi_mods_done(&smods);
delete_passwdPolicy(&pwpolicy);
return ( 0 );
@@ -173,7 +175,7 @@ skip:
sprintf ( graceUserTime, "%d", pwdGraceUserTime );
slapi_mods_add_string(&smods, LDAP_MOD_REPLACE,
"passwordGraceUserTime", graceUserTime);
- pw_apply_mods(sdn, &smods);
+ pw_apply_mods_ext(sdn, &smods, txn);
slapi_mods_done(&smods);
if (pwresponse_req) {
/* check for "changeafterreset" condition */
@@ -216,7 +218,7 @@ skip:
pb->pb_op->o_opid, SLAPD_DISCONNECT_UNBIND, 0);
}
/* Apply current modifications */
- pw_apply_mods(sdn, &smods);
+ pw_apply_mods_ext(sdn, &smods, txn);
slapi_mods_done(&smods);
delete_passwdPolicy(&pwpolicy);
return (-1);
@@ -263,7 +265,7 @@ skip:
*t = (long)diff_t; /* jcm: had to cast double to long */
}
- pw_apply_mods(sdn, &smods);
+ pw_apply_mods_ext(sdn, &smods, txn);
slapi_mods_done(&smods);
if (pwresponse_req) {
/* check for "changeafterreset" condition */
@@ -283,7 +285,7 @@ skip:
return (2);
}
- pw_apply_mods(sdn, &smods);
+ pw_apply_mods_ext(sdn, &smods, txn);
slapi_mods_done(&smods);
/* Leftover from "changeafterreset" condition */
if (pb->pb_conn->c_needpw == 1) {
diff --git a/ldap/servers/slapd/pw_retry.c b/ldap/servers/slapd/pw_retry.c
index 5244622..48849fb 100644
--- a/ldap/servers/slapd/pw_retry.c
+++ b/ldap/servers/slapd/pw_retry.c
@@ -130,7 +130,9 @@ void set_retry_cnt_and_time ( Slapi_PBlock *pb, int count, time_t cur_time ) {
time_t reset_time;
char *timestr;
passwdPolicy *pwpolicy = NULL;
+ void *txn = NULL;
+ slapi_pblock_get( pb, SLAPI_TXN, &txn );
slapi_pblock_get( pb, SLAPI_TARGET_SDN, &sdn );
dn = slapi_sdn_get_dn(sdn);
pwpolicy = new_passwdPolicy(pb, dn);
@@ -146,7 +148,7 @@ void set_retry_cnt_and_time ( Slapi_PBlock *pb, int count, time_t cur_time ) {
set_retry_cnt_mods(pb, &smods, count);
- pw_apply_mods(sdn, &smods);
+ pw_apply_mods_ext(sdn, &smods, txn);
slapi_mods_done(&smods);
delete_passwdPolicy(&pwpolicy);
}
@@ -193,11 +195,13 @@ void set_retry_cnt ( Slapi_PBlock *pb, int count)
{
Slapi_DN *sdn = NULL;
Slapi_Mods smods;
-
+ void *txn = NULL;
+
+ slapi_pblock_get( pb, SLAPI_TXN, &txn );
slapi_pblock_get( pb, SLAPI_TARGET_SDN, &sdn );
slapi_mods_init(&smods, 0);
set_retry_cnt_mods(pb, &smods, count);
- pw_apply_mods(sdn, &smods);
+ pw_apply_mods_ext(sdn, &smods, txn);
slapi_mods_done(&smods);
}
@@ -208,6 +212,7 @@ Slapi_Entry *get_entry ( Slapi_PBlock *pb, const char *dn)
Slapi_Entry *retentry = NULL;
Slapi_DN *target_sdn = NULL;
Slapi_DN sdn;
+ void *txn = NULL;
if (NULL == pb) {
LDAPDebug(LDAP_DEBUG_ANY, "get_entry - no pblock specified.\n",
@@ -216,6 +221,7 @@ Slapi_Entry *get_entry ( Slapi_PBlock *pb, const char *dn)
}
slapi_pblock_get( pb, SLAPI_TARGET_SDN, &target_sdn );
+ slapi_pblock_get( pb, SLAPI_TXN, &txn );
if (dn == NULL) {
dn = slapi_sdn_get_dn(target_sdn);
@@ -232,9 +238,9 @@ Slapi_Entry *get_entry ( Slapi_PBlock *pb, const char *dn)
target_sdn = &sdn;
}
- search_result = slapi_search_internal_get_entry(target_sdn, NULL,
- &retentry,
- pw_get_componentID());
+ search_result = slapi_search_internal_get_entry_ext(target_sdn, NULL,
+ &retentry,
+ pw_get_componentID(), txn);
if (search_result != LDAP_SUCCESS) {
LDAPDebug (LDAP_DEBUG_TRACE, "WARNING: 'get_entry' can't find entry '%s', err %d\n", dn, search_result, 0);
}
@@ -244,7 +250,7 @@ bail:
}
void
-pw_apply_mods(const Slapi_DN *sdn, Slapi_Mods *mods)
+pw_apply_mods_ext(const Slapi_DN *sdn, Slapi_Mods *mods, void *txn)
{
Slapi_PBlock pb;
int res;
@@ -260,6 +266,7 @@ pw_apply_mods(const Slapi_DN *sdn, Slapi_Mods *mods)
NULL, /* UniqueID */
pw_get_componentID(), /* PluginID */
OP_FLAG_SKIP_MODIFIED_ATTRS); /* Flags */
+ slapi_pblock_set(&pb, SLAPI_TXN, txn);
slapi_modify_internal_pb (&pb);
slapi_pblock_get(&pb, SLAPI_PLUGIN_INTOP_RESULT, &res);
@@ -275,6 +282,11 @@ pw_apply_mods(const Slapi_DN *sdn, Slapi_Mods *mods)
return;
}
+void
+pw_apply_mods(const Slapi_DN *sdn, Slapi_Mods *mods)
+{
+ pw_apply_mods_ext(sdn, mods, NULL);
+}
/* Handle the component ID for the password policy */
static struct slapi_componentid * pw_componentid = NULL;
commit 89a862674858f3457e360033690e983316a73e50
Author: Rich Megginson <rmeggins(a)redhat.com>
Date: Fri Jan 13 12:03:07 2012 -0700
bump version to 1.2.10.a7
diff --git a/VERSION.sh b/VERSION.sh
index 701bddc..fce68b0 100644
--- a/VERSION.sh
+++ b/VERSION.sh
@@ -14,7 +14,7 @@ VERSION_MAINT=10
# if this is a PRERELEASE, set VERSION_PREREL
# otherwise, comment it out
# be sure to include the dot prefix in the prerel
-VERSION_PREREL=.a6
+VERSION_PREREL=.a7
# NOTES on VERSION_PREREL
# use aN for an alpha release e.g. a1, a2, etc.
# use rcN for a release candidate e.g. rc1, rc2, etc.
11 years, 11 months
ldap/servers
by Richard Allen Megginson
ldap/servers/plugins/acl/acl_ext.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
New commits:
commit e1a7823230d2aaadcea4eecf0794e784c12b33e9
Author: Rich Megginson <rmeggins(a)redhat.com>
Date: Wed Jan 11 20:32:45 2012 -0700
Ticket #256 - debug build assertion in ACL_EvalDestroy()
https://fedorahosted.org/389/ticket/256
Resolves: Ticket #256
Bug Description: debug build assertion in ACL_EvalDestroy()
Reviewed by: nkinder (Thanks!)
Branch: master
Fix Description: aclpb->aclpb_acleval does not own its acllist - so use
ACL_EvalDestroyNoDecrement() instead so the list is not freed.
Platforms tested: RHEL6 x86_64, Fedora 16
Flag Day: no
Doc impact: no
diff --git a/ldap/servers/plugins/acl/acl_ext.c b/ldap/servers/plugins/acl/acl_ext.c
index f045a97..f8699b4 100644
--- a/ldap/servers/plugins/acl/acl_ext.c
+++ b/ldap/servers/plugins/acl/acl_ext.c
@@ -749,8 +749,9 @@ acl__free_aclpb ( Acl_PBlock **aclpb_ptr)
aclpb = *aclpb_ptr;
- if (aclpb->aclpb_acleval)
- ACL_EvalDestroy(NULL, NULL, aclpb->aclpb_acleval);
+ if (aclpb->aclpb_acleval) {
+ ACL_EvalDestroyNoDecrement(NULL, NULL, aclpb->aclpb_acleval);
+ }
if (aclpb->aclpb_proplist)
PListDestroy(aclpb->aclpb_proplist);
11 years, 11 months
ldap/servers
by Richard Allen Megginson
ldap/servers/slapd/entry.c | 153 +++++++++++++++------------------------------
1 file changed, 52 insertions(+), 101 deletions(-)
New commits:
commit 0836138d060903aacc9f0b54203b54b9397f9830
Author: Rich Megginson <rmeggins(a)redhat.com>
Date: Wed Jan 4 15:40:57 2012 -0700
bak2db gets stuck in infinite loop
https://fedorahosted.org/389/ticket/4
Reviewed by: nkinder (Thanks!)
Branch: master
Fix Description: The logic was just plain faulty, so I rewrote the algorithm
and made it much simpler.
for each curr_ent: /* entry in current dse.ldif */
for each old_ent: /* entry in dse_index.ldif in backup */
if curr_ent.dn == old_ent.dn:
modify curr_ent to look like old_ent
curr_ent.inboth = old_ent.inboth = True
for each old_ent:
if old_ent.inboth:
clear old_ent.inboth
else: /* old_ent not in current config */
add old_ent to current dse.ldif
for each curr_ent:
if curr_ent.inboth:
clear curr_ent.inboth
else: /* curr_ent not in old config */
delete curr_ent from current dse.ldif
Platforms tested: RHEL6 x86_64
Flag Day: no
Doc impact: no
diff --git a/ldap/servers/slapd/entry.c b/ldap/servers/slapd/entry.c
index 03f2767..bf7b4bf 100644
--- a/ldap/servers/slapd/entry.c
+++ b/ldap/servers/slapd/entry.c
@@ -3664,13 +3664,6 @@ slapi_entry_diff(Slapi_Mods *smods, Slapi_Entry *e1, Slapi_Entry *e2, int diff_c
return;
}
-static int
-entry_cmp_with_dn(const void *e1, const void *e2)
-{
- return slapi_sdn_compare(slapi_entry_get_sdn_const(*(Slapi_Entry **)e1),
- slapi_entry_get_sdn_const(*(Slapi_Entry **)e2));
-}
-
/* delete the entry (and sub entries if any) specified with dn */
static void
delete_subtree(Slapi_PBlock *pb, const char *dn, void *plg_id)
@@ -3731,69 +3724,17 @@ slapi_entries_diff(Slapi_Entry **old_entries, Slapi_Entry **curr_entries,
Slapi_Entry **oep, **cep;
int rval = 0;
Slapi_PBlock pb;
-#ifdef ENTRY_DIFF_DEBUG
- int i;
-#endif
-
- for (oep = old_entries; oep != NULL && *oep != NULL; oep++)
- ;
-
- qsort(old_entries, oep - old_entries, sizeof(Slapi_Entry *),
- entry_cmp_with_dn);
-
-#ifdef ENTRY_DIFF_DEBUG
- LDAPDebug(LDAP_DEBUG_TRACE, "Old entries:\n", 0, 0, 0);
- for (oep = old_entries, i = 0; oep != NULL && *oep != NULL; oep++, i++)
- {
- LDAPDebug(LDAP_DEBUG_TRACE, "%d: %s\n", i, slapi_entry_get_dn_const(*oep), 0);
- }
-#endif
-
- for (cep = curr_entries; cep != NULL && *cep != NULL; cep++)
- ;
-
- qsort(curr_entries, cep - curr_entries, sizeof(Slapi_Entry *),
- entry_cmp_with_dn);
-
-#ifdef ENTRY_DIFF_DEBUG
- LDAPDebug(LDAP_DEBUG_TRACE, "New entries:\n", 0, 0, 0);
- for (cep = curr_entries, i = 0; cep != NULL && *cep != NULL; cep++, i++)
- {
- LDAPDebug(LDAP_DEBUG_TRACE, "%d: %s\n", i, slapi_entry_get_dn_const(*cep), 0);
- }
-#endif
+#define SLAPI_ENTRY_FLAG_DIFF_IN_BOTH 0x80
if (NULL != logging_prestr && '\0' != *logging_prestr)
{
my_logging_prestr = slapi_ch_smprintf("%s ", logging_prestr);
}
- for (oep = old_entries; oep != NULL && *oep != NULL; )
- {
- for (cep = curr_entries; cep != NULL && *cep != NULL; )
- {
- int dncmp;
- if ((*oep != NULL) && (*cep !=NULL)) {
- dncmp = slapi_sdn_compare(slapi_entry_get_sdn_const(*oep),
- slapi_entry_get_sdn_const(*cep));
- }
- else if (*oep==NULL) {
- dncmp=-1; // OEP is empty, it does not have the entry.
- }
- else if (*cep==NULL) {
- dncmp=1; // CEP is empty, it does not have the entry.
- }
- else {
- continue; // Not sure what happened, but cannot proceed.
- }
-
- if (force_update)
- {
- pblock_init(&pb);
- }
-
- if (0 == dncmp)
- {
+ for (oep = old_entries; oep != NULL && *oep != NULL; oep++) {
+ for (cep = curr_entries; cep != NULL && *cep != NULL; cep++) {
+ if (!slapi_sdn_compare(slapi_entry_get_sdn_const(*oep),
+ slapi_entry_get_sdn_const(*cep))) {
Slapi_Mods *smods = slapi_mods_new();
LDAPMod *mod;
int isfirst = 1;
@@ -3847,61 +3788,71 @@ slapi_entries_diff(Slapi_Entry **old_entries, Slapi_Entry **curr_entries,
}
if (0 == isfirst && force_update && testall)
{
+ pblock_init(&pb);
slapi_modify_internal_set_pb_ext(&pb,
slapi_entry_get_sdn_const(*oep),
slapi_mods_get_ldapmods_byref(smods),
NULL, NULL, plg_id, 0);
slapi_modify_internal_pb(&pb);
+ pblock_done(&pb);
}
slapi_mods_free(&smods);
- oep++; cep++;
+ slapi_entry_set_flag(*oep, SLAPI_ENTRY_FLAG_DIFF_IN_BOTH);
+ slapi_entry_set_flag(*cep, SLAPI_ENTRY_FLAG_DIFF_IN_BOTH);
}
- else if (dncmp < 0) /* old_entries does not have cep */
- {
- rval = 1;
-
- LDAPDebug(LDAP_DEBUG_ANY, "Del %sEntry %s\n",
- my_logging_prestr, slapi_entry_get_dn_const(*cep), 0);
+ }
+ }
- if (testall)
- {
- if (force_update)
- delete_subtree(&pb, slapi_entry_get_dn_const(*cep), plg_id);
- }
- else
+ for (oep = old_entries; oep != NULL && *oep != NULL; oep++) {
+ if (slapi_entry_flag_is_set(*oep, SLAPI_ENTRY_FLAG_DIFF_IN_BOTH)) {
+ slapi_entry_clear_flag(*oep, SLAPI_ENTRY_FLAG_DIFF_IN_BOTH);
+ } else {
+ rval = 1;
+ LDAPDebug(LDAP_DEBUG_ANY, "Add %sEntry %s\n",
+ my_logging_prestr, slapi_entry_get_dn_const(*oep), 0);
+ if (testall)
+ {
+ if (force_update)
{
- goto out;
+ LDAPMod **mods;
+ slapi_entry2mods(*oep, NULL, &mods);
+ pblock_init(&pb);
+ slapi_add_internal_set_pb(&pb,
+ slapi_entry_get_dn_const(*oep), mods, NULL, plg_id, 0);
+ slapi_add_internal_pb(&pb);
+ freepmods(mods);
+ pblock_done(&pb);
}
- cep++;
}
- else /* if (dncmp > 0) curr_entries does not have oep */
+ else
{
- rval = 1;
- LDAPDebug(LDAP_DEBUG_ANY, "Add %sEntry %s\n",
- my_logging_prestr, slapi_entry_get_dn_const(*oep), 0);
- if (testall)
- {
- if (force_update)
- {
- LDAPMod **mods;
- slapi_entry2mods(*oep, NULL, &mods);
- slapi_add_internal_set_pb(&pb,
- slapi_entry_get_dn_const(*oep), mods, NULL, plg_id, 0);
- slapi_add_internal_pb(&pb);
- freepmods(mods);
- }
- }
- else
- {
- goto out;
+ goto out;
+ }
+ }
+ }
+
+ for (cep = curr_entries; cep != NULL && *cep != NULL; cep++) {
+ if (slapi_entry_flag_is_set(*cep, SLAPI_ENTRY_FLAG_DIFF_IN_BOTH)) {
+ slapi_entry_clear_flag(*cep, SLAPI_ENTRY_FLAG_DIFF_IN_BOTH);
+ } else {
+ rval = 1;
+
+ LDAPDebug(LDAP_DEBUG_ANY, "Del %sEntry %s\n",
+ my_logging_prestr, slapi_entry_get_dn_const(*cep), 0);
+
+ if (testall)
+ {
+ if (force_update) {
+ pblock_init(&pb);
+ delete_subtree(&pb, slapi_entry_get_dn_const(*cep), plg_id);
+ pblock_done(&pb);
}
- oep++;
}
- if (force_update)
+ else
{
- pblock_done(&pb);
+ goto out;
}
}
}
11 years, 11 months
ldap/servers
by Richard Allen Megginson
ldap/servers/plugins/acl/acllas.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
New commits:
commit 1bbbb3e5049c1aa0650546efab87ed2f1ea59637
Author: Rich Megginson <rmeggins(a)redhat.com>
Date: Thu Jan 5 16:49:10 2012 -0700
Ticket #162 - Infinite loop / spin inside strcmpi_fast, acl_read_access_allowed_on_attr, server DoS
https://fedorahosted.org/389/ticket/162
Resolves: ticket 162
Bug Description: Infinite loop / spin inside strcmpi_fast, acl_read_access_allowed_on_attr, server DoS
Reviewed by: nhosoi (Thanks!)
Branch: master
Fix Description: Cannot use continue - have to go to the end of the loop and
get the next attribute - added a label for nextattr and use goto nextattr
instead of continue.
Platforms tested: RHEL6 x86_64
Flag Day: no
Doc impact: no
diff --git a/ldap/servers/plugins/acl/acllas.c b/ldap/servers/plugins/acl/acllas.c
index 4a82717..b838bc5 100644
--- a/ldap/servers/plugins/acl/acllas.c
+++ b/ldap/servers/plugins/acl/acllas.c
@@ -2450,7 +2450,9 @@ acllas__handle_group_entry (Slapi_Entry* e, void *callback_data)
} else if (strcasecmp ( attrType, type_memberURL) == 0) {
char *memberURL, *savURL;
- if (!info->userDN) continue;
+ if (!info->userDN) {
+ goto nextattr; /* cannot evaulate memberURL with no userDN - go to next group attribute */
+ }
i= slapi_attr_first_value ( currAttr,&sval );
while ( i != -1 ) {
@@ -2487,13 +2489,14 @@ acllas__handle_group_entry (Slapi_Entry* e, void *callback_data)
}
i = slapi_attr_next_value ( currAttr, i, &sval );
}
- /* Evaluate Fortezza groups */
+ /* Evaluate Certificate groups */
} else if ((strcasecmp (attrType, type_memberCert) == 0) ) {
/* Do we have the certificate around */
if (!info->clientCert) {
slapi_log_error( SLAPI_LOG_ACL, plugin_name,
" acllas__handle_group_entry:Client Cert missing\n" );
- continue;
+ /* cannot evaulate cert membership without cert - go to next attribute */
+ goto nextattr;
}
i = slapi_attr_first_value ( currAttr,&sval );
while ( i != -1 ) {
@@ -2507,7 +2510,8 @@ acllas__handle_group_entry (Slapi_Entry* e, void *callback_data)
i = slapi_attr_next_value ( currAttr, i, &sval );
}
}
-
+
+nextattr:
attrType = NULL;
/* get the next attr */
slapi_entry_next_attr ( e, currAttr, &nextAttr );
11 years, 11 months
ldap/admin
by Noriko Hosoi
ldap/admin/src/scripts/91subtreereindex.pl | 141 +++++++++++++++++++++++++++++
1 file changed, 141 insertions(+)
New commits:
commit aa28a59ef351aa78e8b3f956994041d393250206
Author: Noriko Hosoi <nhosoi(a)redhat.com>
Date: Thu Jan 5 14:24:07 2012 -0800
Trac Ticket 2 - If node entries are tombstone'd,
subordinate entries fail to get the full DN.
https://fedorahosted.org/389/ticket/2
New file ldap/admin/src/scripts/91subtreereindex.pl was dropped
from the commit 681b22ba43a12b83e588f00f2c5ddffdacf0679b.
This patch is adding the file.
diff --git a/ldap/admin/src/scripts/91subtreereindex.pl b/ldap/admin/src/scripts/91subtreereindex.pl
new file mode 100644
index 0000000..1e0e30d
--- /dev/null
+++ b/ldap/admin/src/scripts/91subtreereindex.pl
@@ -0,0 +1,141 @@
+use Mozilla::LDAP::Conn;
+use Mozilla::LDAP::Utils qw(normalizeDN);
+use Mozilla::LDAP::API qw(:constant ldap_url_parse ldap_explode_dn);
+
+sub runinst {
+ my ($inf, $inst, $dseldif, $conn) = @_;
+
+ my @errs = ();
+
+ my $config = $conn->search("cn=config", "base", "(objectclass=*)");
+ if (!$config) {
+ push @errs, ['error_finding_config_entry', 'cn=config',
+ $conn->getErrorString()];
+ return @errs;
+ }
+ my $rundir = $config->getValues('nsslapd-rundir');
+
+ # Check if the server is up or not
+ my $pidfile = $rundir . "/" . $inst . ".pid";
+ if (-e $pidfile) {
+ return (); # server is running; do nothing.
+ }
+
+ my $dbconf = $conn->search("cn=config,cn=ldbm database,cn=plugins,cn=config", "base", "(objectclass=*)");
+ if (!$dbconf) {
+ push @errs, ['error_finding_config_entry',
+ 'cn=config,cn=ldbm database,cn=plugins,cn=config',
+ $conn->getErrorString()];
+ return @errs;
+ }
+
+ # Get the value of nsslapd-subtree-rename-switch.
+ my $switch = $dbconf->getValues('nsslapd-subtree-rename-switch');
+ if ("" eq $switch) {
+ return (); # subtree-rename-switch does not exist; do nothing.
+ } elsif ("off" eq $switch || "OFF" eq $switch) {
+ return (); # subtree-rename-switch is OFF; do nothing.
+ }
+
+ my $dbdir = $dbconf->getValues('nsslapd-directory');
+ my $dbversion0 = $dbdir . "/DBVERSION";
+ my $is_rdn_format = 0;
+ my $dbversionstr = "";
+ if (!open(DBVERSION, "$dbversion0")) {
+ push @errs, ['error_opening_file', $dbversion0, $!];
+ return @errs;
+ } else {
+ while (<DBVERSION>) {
+ if ($_ =~ /rdn-format/) {
+ $is_rdn_format = 1;
+ $dbversionstr = $_;
+ if ($_ =~ /rdn-format-1/) {
+ $is_rdn_format = 2;
+ }
+ }
+ }
+ close DBVERSION;
+
+ if (2 == $is_rdn_format) {
+ return (); # DB already has the new rdn format.
+ }
+
+ if (0 == $is_rdn_format) {
+ push @errs, ['error_format_error', 'database'];
+ return @errs;
+ }
+ }
+
+ my $instconf = $conn->search("cn=ldbm database,cn=plugins,cn=config", "onelevel", "(objectclass=*)");
+ if (!$instconf) {
+ push @errs, ['error_finding_config_entry',
+ 'cn=*,cn=ldbm database,cn=plugins,cn=config',
+ $conn->getErrorString()];
+ return @errs;
+ }
+
+ my $instancedir = $config->getValues('nsslapd-instancedir');
+ my $reindex = $instancedir . "/db2index";
+
+ while ($instconf) {
+ my $backend= $instconf->getValues('cn');
+ if (($backend eq "config") || ($backend eq "monitor")) {
+ goto NEXT;
+ }
+ my $instdbdir = $instconf->getValues('nsslapd-directory');
+ my $dbversion1 = $instdbdir . "/DBVERSION";
+ if (!open(DBVERSION, "$dbversion1")) {
+ push @errs, ['error_opening_file', $dbversion1, $!];
+ goto NEXT;
+ } else {
+ my $versionstr = "";
+ while (<DBVERSION>) {
+ if ($_ =~ /rdn-format/) {
+ $is_rdn_format = 1;
+ $versionstr = $_;
+ if ($_ =~ /rdn-format-1/) {
+ $is_rdn_format = 2;
+ }
+ }
+ }
+ close DBVERSION;
+
+ if (2 == $is_rdn_format) {
+ # DB already has the new rdn format.
+ goto NEXT;
+ }
+
+ if (0 == $is_rdn_format) {
+ push @errs, ['error_format_error', $instdbdir];
+ goto NEXT;
+ }
+
+ # reindex entryrdn
+ my $rc = system("$reindex -n $backend -t entryrdn");
+
+ # update instance DBVERSION file
+ if ($versionstr ne "") {
+ if (!open(DBVERSION, "> $dbversion1")) {
+ push @errs, ['error_opening_file', $dbversion1, $!];
+ } else {
+ $versionstr =~ y/rdn\-format/rdn\-format\-1/;
+ print DBVERSION $versionstr . "\n";
+ close DBVERSION;
+ }
+ }
+ }
+NEXT:
+ $instconf = $conn->nextEntry();
+ }
+
+ # update main DBVERSION file
+ if (!open(DBVERSION, "$dbversion0")) {
+ push @errs, ['error_opening_file', $dbversion0, $!];
+ } else {
+ $dbversionstr = y/rdn\-format/rdn\-format\-1/;
+ print DBVERSION $versionstr . "\n";
+ close DBVERSION;
+ }
+
+ return @errs;
+}
11 years, 11 months
ldap/servers
by Richard Allen Megginson
ldap/servers/plugins/acl/acl.c | 14 ++--
ldap/servers/plugins/acl/acl.h | 23 ++++--
ldap/servers/plugins/acl/acl_ext.c | 120 +++++++++++++++++++++++++++++++++--
ldap/servers/plugins/acl/acllist.c | 10 +-
ldap/servers/plugins/acl/aclplugin.c | 2
5 files changed, 146 insertions(+), 23 deletions(-)
New commits:
commit 0070a45411ad8909389418b868638d08682f701c
Author: nturpin <nadia.rincon.turpin(a)kantega.no>
Date: Tue Dec 27 21:31:53 2011 +0100
Ticket #3: acl cache overflown problem
Fix Description: We have made ACLPB_MAX_SELECTED_ACLS and ACLPB_MAX_CACHE_RESULTS configurable.
Their default value is still 200 (same as before). To modify this value, you can add or
modify the attribute "nsslapd-aclpb-max-selected-acls" in the ACL plugin
config entry "cn=ACL Plugin,cn=plugins,cn=config".
- The constants were replaced with variables (same name in lower case)
- On init: the variables are initialized with the value contained in the mentioned
attribute, if it exists in config. Otherwise they are set to the default value.
- The arrays that depend on these values are now dynamically allocated
- On init: acl__malloc_aclpb ( )
- On pre-operation: acl_conn_ext_constructor ( ... )
- The memory is freed:
- On shutdown: acl_destroy_aclpb_pool()
- On post-operation: acl_conn_ext_destructor ( ... )
- I also free the space for aclQueue in acl_destroy_aclpb_pool(), since it seems
it is not done anywhere.
Platforms tested: Fedora 16, RHEL6
Reviewed by: rmeggins (and changed name of attribute slightly)
diff --git a/ldap/servers/plugins/acl/acl.c b/ldap/servers/plugins/acl/acl.c
index 9c3db10..c8a221e 100644
--- a/ldap/servers/plugins/acl/acl.c
+++ b/ldap/servers/plugins/acl/acl.c
@@ -1847,7 +1847,7 @@ acl__scan_for_acis(Acl_PBlock *aclpb, int *err)
if ( aclpb->aclpb_state & ACLPB_SEARCH_BASED_ON_LIST ||
aclpb->aclpb_handles_index[0] != -1 ) {
int kk = 0;
- while ( kk < ACLPB_MAX_SELECTED_ACLS && aclpb->aclpb_handles_index[kk] != -1 ) {
+ while ( kk < aclpb_max_selected_acls && aclpb->aclpb_handles_index[kk] != -1 ) {
slapi_log_error(SLAPI_LOG_ACL, plugin_name, "Using ACL Container:%d for evaluation\n", kk);
kk++;
}
@@ -2487,8 +2487,8 @@ acl__resource_match_aci( Acl_PBlock *aclpb, aci_t *aci, int skip_attrEval, int *
((aci->aci_access & SLAPI_ACL_READ) || (aci->aci_access & SLAPI_ACL_SEARCH))) {
int kk=0;
- while ( kk < ACLPB_MAX_SELECTED_ACLS && aclpb->aclpb_handles_index[kk] >=0 ) kk++;
- if (kk >= ACLPB_MAX_SELECTED_ACLS) {
+ while ( kk < aclpb_max_selected_acls && aclpb->aclpb_handles_index[kk] >=0 ) kk++;
+ if (kk >= aclpb_max_selected_acls) {
aclpb->aclpb_state &= ~ACLPB_SEARCH_BASED_ON_ENTRY_LIST;
} else {
aclpb->aclpb_handles_index[kk++] = aci->aci_index;
@@ -2503,7 +2503,7 @@ acl__resource_match_aci( Acl_PBlock *aclpb, aci_t *aci, int skip_attrEval, int *
aclEvalContext *c_evalContext = &aclpb->aclpb_curr_entryEval_context;
int nhandle = c_evalContext->acle_numof_tmatched_handles;
- if ( nhandle < ACLPB_MAX_SELECTED_ACLS) {
+ if ( nhandle < aclpb_max_selected_acls) {
c_evalContext->acle_handles_matched_target[nhandle] = aci->aci_index;
c_evalContext->acle_numof_tmatched_handles++;
}
@@ -2882,7 +2882,7 @@ acl__TestRights(Acl_PBlock *aclpb,int access, char **right, char ** map_generic,
if ( j < aclpb->aclpb_last_cache_result) {
/* already in cache */
- } else if ( j < ACLPB_MAX_CACHE_RESULTS ) {
+ } else if ( j < aclpb_max_cache_results ) {
/* j == aclpb->aclpb_last_cache_result &&
j < ACLPB_MAX_CACHE_RESULTS */
aclpb->aclpb_last_cache_result++;
@@ -3086,7 +3086,7 @@ acl__TestRights(Acl_PBlock *aclpb,int access, char **right, char ** map_generic,
if ( j < aclpb->aclpb_last_cache_result) {
/* already in cache */
- } else if ( j < ACLPB_MAX_CACHE_RESULTS ) {
+ } else if ( j < aclpb_max_cache_results ) {
/* j == aclpb->aclpb_last_cache_result &&
j < ACLPB_MAX_CACHE_RESULTS */
aclpb->aclpb_last_cache_result++;
@@ -4042,7 +4042,7 @@ acl__recompute_acl ( Acl_PBlock *aclpb,
if ( j < aclpb->aclpb_last_cache_result) {
/* already in cache */
- } else if ( j < ACLPB_MAX_CACHE_RESULTS-1) {
+ } else if ( j < aclpb_max_cache_results-1) {
/* rbyrneXXX: make this same as other last_cache_result code! */
j = ++aclpb->aclpb_last_cache_result;
aclpb->aclpb_cache_result[j].aci_index = aci->aci_index;
diff --git a/ldap/servers/plugins/acl/acl.h b/ldap/servers/plugins/acl/acl.h
index 8747de1..4be2849 100644
--- a/ldap/servers/plugins/acl/acl.h
+++ b/ldap/servers/plugins/acl/acl.h
@@ -339,8 +339,18 @@ typedef struct aci {
#define ACI_MAX_ELEVEL ACI_ELEVEL_GROUPDN +1
#define ACI_DEFAULT_ELEVEL ACI_MAX_ELEVEL
+#define ACL_PLUGIN_CONFIG_ENTRY_DN "cn=ACL Plugin,cn=plugins,cn=config"
-#define ACLPB_MAX_SELECTED_ACLS 200
+/*
+ * In plugin config entry, set this attribute to change the value
+ * of aclpb_max_selected_acls and aclpb_max_cache_results.
+ * If not set, DEFAULT_ACLPB_MAX_SELECTED_ACLS will be used.
+ */
+#define ATTR_ACLPB_MAX_SELECTED_ACLS "nsslapd-aclpb-max-selected-acls"
+#define DEFAULT_ACLPB_MAX_SELECTED_ACLS 200
+
+int aclpb_max_selected_acls; /* initialized from plugin config entry */
+int aclpb_max_cache_results; /* initialized from plugin config entry */
typedef struct result_cache {
int aci_index;
@@ -353,7 +363,7 @@ typedef struct result_cache {
#define ACLPB_CACHE_SEARCH_RES_SKIP (short)0x0010 /* used for both types */
#define ACLPB_CACHE_READ_RES_SKIP (short)0x0020 /* used for both types */
}r_cache_t;
-#define ACLPB_MAX_CACHE_RESULTS ACLPB_MAX_SELECTED_ACLS
+
/*
* This is use to keep the result of the evaluation of the attr.
@@ -392,7 +402,7 @@ struct acleval_context {
/* Handles information */
short acle_numof_tmatched_handles;
- int acle_handles_matched_target[ACLPB_MAX_SELECTED_ACLS];
+ int *acle_handles_matched_target;
};
typedef struct acleval_context aclEvalContext;
@@ -539,12 +549,12 @@ struct acl_pblock {
/* To keep the results in the cache */
int aclpb_last_cache_result;
- struct result_cache aclpb_cache_result[ACLPB_MAX_CACHE_RESULTS];
+ struct result_cache *aclpb_cache_result;
/* Index numbers of ACLs selected based on a locality search*/
char *aclpb_search_base;
- int aclpb_base_handles_index[ACLPB_MAX_SELECTED_ACLS];
- int aclpb_handles_index[ACLPB_MAX_SELECTED_ACLS];
+ int *aclpb_base_handles_index;
+ int *aclpb_handles_index;
/* Evaluation context info
** 1) Context cached from aclcb ( from connection struct )
@@ -825,6 +835,7 @@ void acl_set_authorization_dn( Slapi_PBlock *pb, char *dn, int type );
void acl_init_aclpb ( Slapi_PBlock *pb , Acl_PBlock *aclpb,
const char *dn, int copy_from_aclcb);
int acl_create_aclpb_pool ();
+void acl_destroy_aclpb_pool ();
int acl_skip_access_check ( Slapi_PBlock *pb, Slapi_Entry *e );
int aclext_alloc_lockarray ();
diff --git a/ldap/servers/plugins/acl/acl_ext.c b/ldap/servers/plugins/acl/acl_ext.c
index df7d1ed..f045a97 100644
--- a/ldap/servers/plugins/acl/acl_ext.c
+++ b/ldap/servers/plugins/acl/acl_ext.c
@@ -50,6 +50,7 @@ static char * acl__get_aclpb_type ( Acl_PBlock *aclpb );
static Acl_PBlock * acl__get_aclpb_from_pool ( );
static int acl__put_aclpb_back_to_pool ( Acl_PBlock *aclpb );
static Acl_PBlock * acl__malloc_aclpb ( );
+static void acl__free_aclpb ( Acl_PBlock **aclpb_ptr);
static PRLock *aclext_get_lock ();
@@ -198,6 +199,9 @@ acl_conn_ext_constructor ( void *object, void *parent )
ext->aclcb_sdn = slapi_sdn_new ();
/* store the signatures */
ext->aclcb_aclsignature = acl_get_aclsignature();
+ /* eval_context */
+ ext->aclcb_eval_context.acle_handles_matched_target = (int *)
+ slapi_ch_calloc (aclpb_max_selected_acls, sizeof (int));
ext->aclcb_state = -1;
return ext;
@@ -215,6 +219,7 @@ acl_conn_ext_destructor ( void *ext, void *object, void *parent )
shared_lock = aclcb->aclcb_lock;
acl_clean_aclEval_context ( &aclcb->aclcb_eval_context, 0 /* clean*/ );
slapi_sdn_free ( &aclcb->aclcb_sdn );
+ slapi_ch_free ( (void **)&(aclcb->aclcb_eval_context.acle_handles_matched_target));
aclcb->aclcb_lock = NULL;
slapi_ch_free ( (void **) &aclcb );
@@ -419,6 +424,21 @@ acl__handle_config_entry (Slapi_Entry *e, void *callback_data )
return 0;
}
+static int
+acl__handle_plugin_config_entry (Slapi_Entry *e, void *callback_data )
+{
+ int value = slapi_entry_attr_get_int(e, ATTR_ACLPB_MAX_SELECTED_ACLS);
+ if (value) {
+ aclpb_max_selected_acls = value;
+ aclpb_max_cache_results = value;
+ } else {
+ aclpb_max_selected_acls = DEFAULT_ACLPB_MAX_SELECTED_ACLS;
+ aclpb_max_cache_results = DEFAULT_ACLPB_MAX_SELECTED_ACLS;
+ }
+
+ return 0;
+}
+
/*
* Create a pool of acl pblock. Created during the ACL plugin
* initialization.
@@ -432,6 +452,7 @@ acl_create_aclpb_pool ()
Acl_PBlock *first_aclpb;
int i;
int maxThreads= 0;
+ int callbackData= 0;
slapi_search_internal_callback( "cn=config", LDAP_SCOPE_BASE, "(objectclass=*)",
NULL, 0 /* attrsonly */,
@@ -441,6 +462,14 @@ acl_create_aclpb_pool ()
acl__handle_config_entry,
NULL /* referral_callback */);
+ slapi_search_internal_callback( ACL_PLUGIN_CONFIG_ENTRY_DN, LDAP_SCOPE_BASE, "(objectclass=*)",
+ NULL, 0 /* attrsonly */,
+ &callbackData /* callback_data, not used in this case */,
+ NULL /* controls */,
+ NULL /* result_callback */,
+ acl__handle_plugin_config_entry,
+ NULL /* referral_callback */);
+
/* Create a pool pf aclpb */
maxThreads = 2 * maxThreads;
@@ -471,6 +500,40 @@ acl_create_aclpb_pool ()
}
/*
+ * Destroys the Acl_PBlock pool. To be called at shutdown,
+ * from function registered as SLAPI_PLUGIN_CLOSE_FN
+ */
+void
+acl_destroy_aclpb_pool ()
+{
+ Acl_PBlock *currentPbBlock;
+ Acl_PBlock *nextPbBlock;
+
+ if (!aclQueue) {
+ /* Nothing to do */
+ return;
+ }
+
+ /* Free all busy pbBlocks in queue */
+ currentPbBlock = aclQueue->aclq_busy;
+ while (currentPbBlock) {
+ nextPbBlock = currentPbBlock->aclpb_next;
+ acl__free_aclpb(¤tPbBlock);
+ currentPbBlock = nextPbBlock;
+ }
+
+ /* Free all free pbBlocks in queue */
+ currentPbBlock = aclQueue->aclq_free;
+ while (currentPbBlock) {
+ nextPbBlock = currentPbBlock->aclpb_next;
+ acl__free_aclpb(¤tPbBlock);
+ currentPbBlock = nextPbBlock;
+ }
+
+ slapi_ch_free((void**)&aclQueue);
+}
+
+/*
* Get a FREE acl pblock from the pool.
*
*/
@@ -646,16 +709,65 @@ acl__malloc_aclpb ( )
/* hash table to store macro matched values from targets */
aclpb->aclpb_macro_ht = acl_ht_new();
- return aclpb;
+ /* allocate arrays for handles */
+ aclpb->aclpb_handles_index = (int *)
+ slapi_ch_calloc (aclpb_max_selected_acls, sizeof (int));
+ aclpb->aclpb_base_handles_index = (int *)
+ slapi_ch_calloc (aclpb_max_selected_acls, sizeof (int));
+
+ /* allocate arrays for result cache */
+ aclpb->aclpb_cache_result = (r_cache_t *)
+ slapi_ch_calloc (aclpb_max_cache_results, sizeof (r_cache_t));
+
+ /* allocate arrays for target handles in eval_context */
+ aclpb->aclpb_curr_entryEval_context.acle_handles_matched_target = (int *)
+ slapi_ch_calloc (aclpb_max_selected_acls, sizeof (int));
+ aclpb->aclpb_prev_entryEval_context.acle_handles_matched_target = (int *)
+ slapi_ch_calloc (aclpb_max_selected_acls, sizeof (int));
+ aclpb->aclpb_prev_opEval_context.acle_handles_matched_target = (int *)
+ slapi_ch_calloc (aclpb_max_selected_acls, sizeof (int));
+
+ return aclpb;
error:
- if (aclpb->aclpb_acleval) ACL_EvalDestroy(NULL, NULL, aclpb->aclpb_acleval);
- if (aclpb->aclpb_proplist) PListDestroy(aclpb->aclpb_proplist);
- slapi_ch_free((void**)&aclpb);
+ acl__free_aclpb(&aclpb);
return NULL;
}
+/*
+ * Free the acl pb. To be used at shutdown (SLAPI_PLUGIN_CLOSE_FN)
+ * when we free the aclQueue
+ */
+static void
+acl__free_aclpb ( Acl_PBlock **aclpb_ptr)
+{
+ Acl_PBlock *aclpb = NULL;
+
+ if (aclpb_ptr == NULL || *aclpb_ptr == NULL)
+ return; // Nothing to do
+
+ aclpb = *aclpb_ptr;
+
+ if (aclpb->aclpb_acleval)
+ ACL_EvalDestroy(NULL, NULL, aclpb->aclpb_acleval);
+
+ if (aclpb->aclpb_proplist)
+ PListDestroy(aclpb->aclpb_proplist);
+
+ slapi_ch_free((void**)&(aclpb->aclpb_handles_index));
+ slapi_ch_free((void**)&(aclpb->aclpb_base_handles_index));
+ slapi_ch_free((void**)&(aclpb->aclpb_cache_result));
+ slapi_ch_free((void**)
+ &(aclpb->aclpb_curr_entryEval_context.acle_handles_matched_target));
+ slapi_ch_free((void**)
+ &(aclpb->aclpb_prev_entryEval_context.acle_handles_matched_target));
+ slapi_ch_free((void**)
+ &(aclpb->aclpb_prev_opEval_context.acle_handles_matched_target));
+
+ slapi_ch_free((void**)aclpb_ptr);
+}
+
/* Initializes the aclpb */
void
acl_init_aclpb ( Slapi_PBlock *pb , Acl_PBlock *aclpb, const char *ndn, int copy_from_aclcb)
diff --git a/ldap/servers/plugins/acl/acllist.c b/ldap/servers/plugins/acl/acllist.c
index 7e5221d..8eb39b9 100644
--- a/ldap/servers/plugins/acl/acllist.c
+++ b/ldap/servers/plugins/acl/acllist.c
@@ -646,7 +646,7 @@ acllist_init_scan (Slapi_PBlock *pb, int scope, const char *base)
root = (AciContainer *) avl_find(acllistRoot,
(caddr_t) aclpb->aclpb_aclContainer,
(IFP) __acllist_aciContainer_node_cmp);
- if ( index >= ACLPB_MAX_SELECTED_ACLS -2 ) {
+ if ( index >= aclpb_max_selected_acls -2 ) {
aclpb->aclpb_handles_index[0] = -1;
slapi_ch_free ( (void **) &basedn);
break;
@@ -673,7 +673,7 @@ acllist_init_scan (Slapi_PBlock *pb, int scope, const char *base)
acllist_acicache_READ_UNLOCK();
i = 0;
- while ( i < ACLPB_MAX_SELECTED_ACLS && aclpb->aclpb_base_handles_index[i] != -1 ) {
+ while ( i < aclpb_max_selected_acls && aclpb->aclpb_base_handles_index[i] != -1 ) {
i++;
}
}
@@ -711,7 +711,7 @@ acllist_aciscan_update_scan ( Acl_PBlock *aclpb, char *edn )
is_not_search_base = 0;
}
for (index = 0; (aclpb->aclpb_base_handles_index[index] != -1) &&
- (index < ACLPB_MAX_SELECTED_ACLS - 2); index++) ;
+ (index < aclpb_max_selected_acls - 2); index++) ;
memcpy(aclpb->aclpb_handles_index, aclpb->aclpb_base_handles_index,
sizeof(*aclpb->aclpb_handles_index) * index);
}
@@ -745,7 +745,7 @@ acllist_aciscan_update_scan ( Acl_PBlock *aclpb, char *edn )
slapi_log_error ( SLAPI_LOG_ACL, plugin_name,
"Searching AVL tree for update:%s: container:%d\n", basedn ,
root ? root->acic_index: -1);
- if ( index >= ACLPB_MAX_SELECTED_ACLS -2 ) {
+ if ( index >= aclpb_max_selected_acls -2 ) {
aclpb->aclpb_handles_index[0] = -1;
slapi_ch_free ( (void **) &basedn);
break;
@@ -835,7 +835,7 @@ start:
return NULL;
/* reached the end of the array */
- if ((!scan_entire_list && (*cookie >= (ACLPB_MAX_SELECTED_ACLS-1))) ||
+ if ((!scan_entire_list && (*cookie >= (aclpb_max_selected_acls-1))) ||
(*cookie >= currContainerIndex)) {
return NULL;
}
diff --git a/ldap/servers/plugins/acl/aclplugin.c b/ldap/servers/plugins/acl/aclplugin.c
index ecd1e11..0d35425 100644
--- a/ldap/servers/plugins/acl/aclplugin.c
+++ b/ldap/servers/plugins/acl/aclplugin.c
@@ -300,7 +300,7 @@ aclplugin_stop ( Slapi_PBlock *pb )
{
int rc = 0; /* OK */
- /* nothing to be done now */
+ acl_destroy_aclpb_pool ();
return rc;
}
11 years, 11 months
ldap/servers
by Richard Allen Megginson
ldap/servers/plugins/syntaxes/bitstring.c | 26 ++
ldap/servers/plugins/syntaxes/ces.c | 27 ++
ldap/servers/plugins/syntaxes/cis.c | 28 ++
ldap/servers/plugins/syntaxes/deliverymethod.c | 27 ++
ldap/servers/plugins/syntaxes/dn.c | 27 ++
ldap/servers/plugins/syntaxes/facsimile.c | 27 ++
ldap/servers/plugins/syntaxes/guide.c | 27 ++
ldap/servers/plugins/syntaxes/int.c | 29 ++
ldap/servers/plugins/syntaxes/nameoptuid.c | 26 ++
ldap/servers/plugins/syntaxes/numericstring.c | 27 ++
ldap/servers/plugins/syntaxes/sicis.c | 27 ++
ldap/servers/plugins/syntaxes/string.c | 265 +++++++++++++++----------
ldap/servers/plugins/syntaxes/syntax.h | 1
ldap/servers/plugins/syntaxes/tel.c | 27 ++
ldap/servers/plugins/syntaxes/teletex.c | 27 ++
ldap/servers/plugins/syntaxes/telex.c | 28 ++
ldap/servers/plugins/syntaxes/value.c | 4
ldap/servers/slapd/attr.c | 4
ldap/servers/slapd/ava.c | 2
ldap/servers/slapd/back-ldbm/back-ldbm.h | 1
ldap/servers/slapd/back-ldbm/filterindex.c | 1
ldap/servers/slapd/back-ldbm/ldbm_attr.c | 41 ---
ldap/servers/slapd/back-ldbm/ldbm_search.c | 135 ++++++++++++
ldap/servers/slapd/filter.c | 132 +++++++++---
ldap/servers/slapd/filtercmp.c | 1
ldap/servers/slapd/filterentry.c | 13 -
ldap/servers/slapd/pblock.c | 28 ++
ldap/servers/slapd/plugin_syntax.c | 40 +++
ldap/servers/slapd/proto-slap.h | 4
ldap/servers/slapd/slap.h | 5
ldap/servers/slapd/slapi-plugin.h | 36 +++
ldap/servers/slapd/slapi-private.h | 2
ldap/servers/slapd/utf8compare.c | 4
ldap/servers/slapd/value.c | 1
34 files changed, 896 insertions(+), 204 deletions(-)
New commits:
commit 62e93bc9dca3ddad91b171315615ea46df781fc4
Author: Rich Megginson <rmeggins(a)redhat.com>
Date: Mon Dec 12 21:07:59 2011 -0700
Ticket 1 - pre-normalize filter and pre-compile substring regex - and other optimizations
When processing large search filters which are applied to every entry in
the search result set, the filter is normalized anew each time a new entry
is tested. For substring filters, a regular expression must be created,
compiled, and freed each time the substring filter is tested, in addition
to normalizing the values. For example, if the search filter contains
1000 substring sub-filters, for each entry tested with the filter, this
will require 1000 filter normalizations followed by 1000 regex creation,
compilation, and cleanup. If there are 1000 entries in the search result
set, this will require a million such operations.
The solution is to "pre-compile" the search filter - perform all necessary
normalizations and compiling of the regular expressions used in the
filter once we know the search will go through.
struct subfilt and struct ava have "private" members which weren't being
used for anything. For subfilt, the private field is used to store the
pre-compiled regex to pass to the syntax filter code. For ava, the
private field is used to store the flags to specify if the type and/or
value is normalized.
Try to avoid normalization wherever possible. slapi_value has a v_flags
field which is used to specify if the value is normalized. Check this
before we attempt to normalize a value. If we are creating a new
slapi_value, set the normalized flag if the new value is already
normalized. Have to make sure that Slapi_Value structures are always
initialized correctly.
When examining the filter string, do not convert it to lower case first -
just use strcasestr - note that even though the string may be utf8,
strcasestr will still work, because we are searching for ascii characters.
Use PL_strcasestr because the system strcasestr causes valgrind to
print uninitialized memory errors.
Eliminate some uses of sprintf where a simple char assignment will suffice.
Reviewed by: nhosoi (Thanks!)
diff --git a/ldap/servers/plugins/syntaxes/bitstring.c b/ldap/servers/plugins/syntaxes/bitstring.c
index eefe8fc..2366ffd 100644
--- a/ldap/servers/plugins/syntaxes/bitstring.c
+++ b/ldap/servers/plugins/syntaxes/bitstring.c
@@ -59,6 +59,12 @@ static int bitstring_assertion2keys_sub( Slapi_PBlock *pb, char *initial, char *
char *final, Slapi_Value ***ivals );
static int bitstring_compare(struct berval *v1, struct berval *v2);
static int bitstring_validate(struct berval *val);
+static void bitstring_normalize(
+ Slapi_PBlock *pb,
+ char *s,
+ int trim_spaces,
+ char **alt
+);
/* the first name is the official one from RFC 4517 */
static char *names[] = { "Bit String", "bitstring", BITSTRING_SYNTAX_OID, 0 };
@@ -133,6 +139,8 @@ bitstring_init( Slapi_PBlock *pb )
(void *) bitstring_compare );
rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_VALIDATE,
(void *) bitstring_validate );
+ rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_NORMALIZE,
+ (void *) bitstring_normalize );
rc |= register_matching_rule_plugins();
LDAPDebug( LDAP_DEBUG_PLUGIN, "<= bitstring_init %d\n", rc, 0, 0 );
@@ -148,7 +156,13 @@ bitstring_filter_ava(
Slapi_Value **retVal
)
{
- return( string_filter_ava( bvfilter, bvals, SYNTAX_CES,
+ int filter_normalized = 0;
+ int syntax = SYNTAX_CES;
+ slapi_pblock_get( pb, SLAPI_PLUGIN_SYNTAX_FILTER_NORMALIZED, &filter_normalized );
+ if (filter_normalized) {
+ syntax |= SYNTAX_NORM_FILT;
+ }
+ return( string_filter_ava( bvfilter, bvals, syntax,
ftype, retVal ) );
}
@@ -229,3 +243,13 @@ exit:
return rc;
}
+static void bitstring_normalize(
+ Slapi_PBlock *pb,
+ char *s,
+ int trim_spaces,
+ char **alt
+)
+{
+ value_normalize_ext(s, SYNTAX_CES, trim_spaces, alt);
+ return;
+}
diff --git a/ldap/servers/plugins/syntaxes/ces.c b/ldap/servers/plugins/syntaxes/ces.c
index c0855d6..0571836 100644
--- a/ldap/servers/plugins/syntaxes/ces.c
+++ b/ldap/servers/plugins/syntaxes/ces.c
@@ -65,6 +65,12 @@ static int ces_assertion2keys_sub( Slapi_PBlock *pb, char *initial, char **any,
char *final, Slapi_Value ***ivals );
static int ces_compare(struct berval *v1, struct berval *v2);
static int ia5_validate(struct berval *val);
+static void ces_normalize(
+ Slapi_PBlock *pb,
+ char *s,
+ int trim_spaces,
+ char **alt
+);
/* the first name is the official one from RFC 2252 */
static char *ia5_names[] = { "IA5String", "ces", "caseexactstring",
@@ -251,6 +257,8 @@ register_ces_like_plugin( Slapi_PBlock *pb, Slapi_PluginDesc *pdescp,
rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_VALIDATE,
(void *)validate_fn );
}
+ rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_NORMALIZE,
+ (void *)ces_normalize );
return( rc );
}
@@ -292,7 +300,13 @@ ces_filter_ava(
Slapi_Value **retVal
)
{
- return( string_filter_ava( bvfilter, bvals, SYNTAX_CES, ftype,
+ int filter_normalized = 0;
+ int syntax = SYNTAX_CES;
+ slapi_pblock_get( pb, SLAPI_PLUGIN_SYNTAX_FILTER_NORMALIZED, &filter_normalized );
+ if (filter_normalized) {
+ syntax |= SYNTAX_NORM_FILT;
+ }
+ return( string_filter_ava( bvfilter, bvals, syntax, ftype,
retVal) );
}
@@ -378,3 +392,14 @@ ia5_validate(
exit:
return rc;
}
+
+static void ces_normalize(
+ Slapi_PBlock *pb,
+ char *s,
+ int trim_spaces,
+ char **alt
+)
+{
+ value_normalize_ext(s, SYNTAX_CES, trim_spaces, alt);
+ return;
+}
diff --git a/ldap/servers/plugins/syntaxes/cis.c b/ldap/servers/plugins/syntaxes/cis.c
index b25fe0a..71e7a7c 100644
--- a/ldap/servers/plugins/syntaxes/cis.c
+++ b/ldap/servers/plugins/syntaxes/cis.c
@@ -77,6 +77,12 @@ static int country_validate(struct berval *val);
static int postal_validate(struct berval *val);
static int oid_validate(struct berval *val);
static int printable_validate(struct berval *val);
+static void cis_normalize(
+ Slapi_PBlock *pb,
+ char *s,
+ int trim_spaces,
+ char **alt
+);
/*
Even though the official RFC 4517 says that the postal syntax
@@ -458,7 +464,8 @@ register_cis_like_plugin( Slapi_PBlock *pb, Slapi_PluginDesc *pdescp,
rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_VALIDATE,
(void *)validate_fn );
}
-
+ rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_NORMALIZE,
+ (void *) cis_normalize );
return( rc );
}
@@ -557,7 +564,13 @@ cis_filter_ava(
Slapi_Value **retVal
)
{
- return( string_filter_ava( bvfilter, bvals, SYNTAX_CIS, ftype,
+ int filter_normalized = 0;
+ int syntax = SYNTAX_CIS;
+ slapi_pblock_get( pb, SLAPI_PLUGIN_SYNTAX_FILTER_NORMALIZED, &filter_normalized );
+ if (filter_normalized) {
+ syntax |= SYNTAX_NORM_FILT;
+ }
+ return( string_filter_ava( bvfilter, bvals, syntax, ftype,
retVal ) );
}
@@ -1083,3 +1096,14 @@ static int printable_validate(
exit:
return( rc );
}
+
+static void cis_normalize(
+ Slapi_PBlock *pb,
+ char *s,
+ int trim_spaces,
+ char **alt
+)
+{
+ value_normalize_ext(s, SYNTAX_CIS, trim_spaces, alt);
+ return;
+}
diff --git a/ldap/servers/plugins/syntaxes/deliverymethod.c b/ldap/servers/plugins/syntaxes/deliverymethod.c
index c643156..99ee59a 100644
--- a/ldap/servers/plugins/syntaxes/deliverymethod.c
+++ b/ldap/servers/plugins/syntaxes/deliverymethod.c
@@ -60,6 +60,12 @@ static int delivery_assertion2keys_sub( Slapi_PBlock *pb, char *initial, char **
static int delivery_compare(struct berval *v1, struct berval *v2);
static int delivery_validate(struct berval *val);
static int pdm_validate(const char *start, const char *end);
+static void delivery_normalize(
+ Slapi_PBlock *pb,
+ char *s,
+ int trim_spaces,
+ char **alt
+);
/* the first name is the official one from RFC 4517 */
static char *names[] = { "Delivery Method", "delivery", DELIVERYMETHOD_SYNTAX_OID, 0 };
@@ -99,6 +105,8 @@ delivery_init( Slapi_PBlock *pb )
(void *) delivery_compare );
rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_VALIDATE,
(void *) delivery_validate );
+ rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_NORMALIZE,
+ (void *) delivery_normalize );
LDAPDebug( LDAP_DEBUG_PLUGIN, "<= delivery_init %d\n", rc, 0, 0 );
return( rc );
@@ -113,7 +121,13 @@ delivery_filter_ava(
Slapi_Value **retVal
)
{
- return( string_filter_ava( bvfilter, bvals, SYNTAX_CIS,
+ int filter_normalized = 0;
+ int syntax = SYNTAX_CIS;
+ slapi_pblock_get( pb, SLAPI_PLUGIN_SYNTAX_FILTER_NORMALIZED, &filter_normalized );
+ if (filter_normalized) {
+ syntax |= SYNTAX_NORM_FILT;
+ }
+ return( string_filter_ava( bvfilter, bvals, syntax,
ftype, retVal ) );
}
@@ -315,3 +329,14 @@ pdm_validate(const char *start, const char *end)
exit:
return rc;
}
+
+static void delivery_normalize(
+ Slapi_PBlock *pb,
+ char *s,
+ int trim_spaces,
+ char **alt
+)
+{
+ value_normalize_ext(s, SYNTAX_CIS, trim_spaces, alt);
+ return;
+}
diff --git a/ldap/servers/plugins/syntaxes/dn.c b/ldap/servers/plugins/syntaxes/dn.c
index 092175a..bcf951a 100644
--- a/ldap/servers/plugins/syntaxes/dn.c
+++ b/ldap/servers/plugins/syntaxes/dn.c
@@ -58,6 +58,12 @@ static int dn_assertion2keys_ava( Slapi_PBlock *pb, Slapi_Value *val,
static int dn_assertion2keys_sub( Slapi_PBlock *pb, char *initial, char **any,
char *final, Slapi_Value ***ivals );
static int dn_validate( struct berval *val );
+static void dn_normalize(
+ Slapi_PBlock *pb,
+ char *s,
+ int trim_spaces,
+ char **alt
+);
/* the first name is the official one from RFC 2252 */
static char *names[] = { "DN", DN_SYNTAX_OID, 0 };
@@ -133,6 +139,8 @@ dn_init( Slapi_PBlock *pb )
(void *) DN_SYNTAX_OID );
rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_VALIDATE,
(void *) dn_validate );
+ rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_NORMALIZE,
+ (void *) dn_normalize );
rc |= register_matching_rule_plugins();
LDAPDebug( LDAP_DEBUG_PLUGIN, "<= dn_init %d\n", rc, 0, 0 );
@@ -143,8 +151,13 @@ static int
dn_filter_ava( Slapi_PBlock *pb, struct berval *bvfilter,
Slapi_Value **bvals, int ftype, Slapi_Value **retVal )
{
- return( string_filter_ava( bvfilter, bvals, SYNTAX_CIS | SYNTAX_DN,
- ftype, retVal ) );
+ int filter_normalized = 0;
+ int syntax = SYNTAX_CIS | SYNTAX_DN;
+ slapi_pblock_get( pb, SLAPI_PLUGIN_SYNTAX_FILTER_NORMALIZED, &filter_normalized );
+ if (filter_normalized) {
+ syntax |= SYNTAX_NORM_FILT;
+ }
+ return( string_filter_ava( bvfilter, bvals, syntax, ftype, retVal ) );
}
static int
@@ -193,3 +206,13 @@ static int dn_validate( struct berval *val )
return rc;
}
+static void dn_normalize(
+ Slapi_PBlock *pb,
+ char *s,
+ int trim_spaces,
+ char **alt
+)
+{
+ value_normalize_ext(s, SYNTAX_CIS | SYNTAX_DN, trim_spaces, alt);
+ return;
+}
diff --git a/ldap/servers/plugins/syntaxes/facsimile.c b/ldap/servers/plugins/syntaxes/facsimile.c
index 34fedb1..21db4b1 100644
--- a/ldap/servers/plugins/syntaxes/facsimile.c
+++ b/ldap/servers/plugins/syntaxes/facsimile.c
@@ -60,6 +60,12 @@ static int facsimile_assertion2keys_sub( Slapi_PBlock *pb, char *initial, char *
static int facsimile_compare(struct berval *v1, struct berval *v2);
static int facsimile_validate(struct berval *val);
static int fax_parameter_validate(const char *start, const char *end);
+static void facsimile_normalize(
+ Slapi_PBlock *pb,
+ char *s,
+ int trim_spaces,
+ char **alt
+);
/* the first name is the official one from RFC 4517 */
static char *names[] = { "Facsimile Telephone Number", "facsimile", FACSIMILE_SYNTAX_OID, 0 };
@@ -99,6 +105,8 @@ facsimile_init( Slapi_PBlock *pb )
(void *) facsimile_compare );
rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_VALIDATE,
(void *) facsimile_validate );
+ rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_NORMALIZE,
+ (void *) facsimile_normalize );
LDAPDebug( LDAP_DEBUG_PLUGIN, "<= facsimile_init %d\n", rc, 0, 0 );
return( rc );
@@ -113,7 +121,13 @@ facsimile_filter_ava(
Slapi_Value **retVal
)
{
- return( string_filter_ava( bvfilter, bvals, SYNTAX_CIS,
+ int filter_normalized = 0;
+ int syntax = SYNTAX_CIS;
+ slapi_pblock_get( pb, SLAPI_PLUGIN_SYNTAX_FILTER_NORMALIZED, &filter_normalized );
+ if (filter_normalized) {
+ syntax |= SYNTAX_NORM_FILT;
+ }
+ return( string_filter_ava( bvfilter, bvals, syntax,
ftype, retVal ) );
}
@@ -321,3 +335,14 @@ fax_parameter_validate(const char *start, const char *end)
exit:
return rc;
}
+
+static void facsimile_normalize(
+ Slapi_PBlock *pb,
+ char *s,
+ int trim_spaces,
+ char **alt
+)
+{
+ value_normalize_ext(s, SYNTAX_CIS, trim_spaces, alt);
+ return;
+}
diff --git a/ldap/servers/plugins/syntaxes/guide.c b/ldap/servers/plugins/syntaxes/guide.c
index ec9fd6f..3222083 100644
--- a/ldap/servers/plugins/syntaxes/guide.c
+++ b/ldap/servers/plugins/syntaxes/guide.c
@@ -63,6 +63,12 @@ static int guide_validate(struct berval *val);
static int criteria_validate(const char *start, const char *end);
static int andterm_validate(const char *start, const char *end, const char **last);
static int term_validate(const char *start, const char *end, const char **last);
+static void guide_normalize(
+ Slapi_PBlock *pb,
+ char *s,
+ int trim_spaces,
+ char **alt
+);
/* the first name is the official one from RFC 4517 */
static char *guide_names[] = { "Guide", "guide", GUIDE_SYNTAX_OID, 0 };
@@ -109,6 +115,8 @@ guide_init( Slapi_PBlock *pb )
(void *) guide_compare );
rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_VALIDATE,
(void *) guide_validate );
+ rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_NORMALIZE,
+ (void *) guide_normalize );
LDAPDebug( LDAP_DEBUG_PLUGIN, "<= guide_init %d\n", rc, 0, 0 );
return( rc );
@@ -160,7 +168,13 @@ guide_filter_ava(
Slapi_Value **retVal
)
{
- return( string_filter_ava( bvfilter, bvals, SYNTAX_CIS,
+ int filter_normalized = 0;
+ int syntax = SYNTAX_CIS;
+ slapi_pblock_get( pb, SLAPI_PLUGIN_SYNTAX_FILTER_NORMALIZED, &filter_normalized );
+ if (filter_normalized) {
+ syntax |= SYNTAX_NORM_FILT;
+ }
+ return( string_filter_ava( bvfilter, bvals, syntax,
ftype, retVal ) );
}
@@ -732,3 +746,14 @@ term_validate(const char *start, const char *end, const char **last)
exit:
return rc;
}
+
+static void guide_normalize(
+ Slapi_PBlock *pb,
+ char *s,
+ int trim_spaces,
+ char **alt
+)
+{
+ value_normalize_ext(s, SYNTAX_CIS, trim_spaces, alt);
+ return;
+}
diff --git a/ldap/servers/plugins/syntaxes/int.c b/ldap/servers/plugins/syntaxes/int.c
index b3a7de0..e8b8817 100644
--- a/ldap/servers/plugins/syntaxes/int.c
+++ b/ldap/servers/plugins/syntaxes/int.c
@@ -55,6 +55,12 @@ static int int_assertion2keys( Slapi_PBlock *pb, Slapi_Value *val,
Slapi_Value ***ivals, int ftype );
static int int_compare(struct berval *v1, struct berval *v2);
static int int_validate(struct berval *val);
+static void int_normalize(
+ Slapi_PBlock *pb,
+ char *s,
+ int trim_spaces,
+ char **alt
+);
/* the first name is the official one from RFC 2252 */
static char *names[] = { "INTEGER", "int", INTEGER_SYNTAX_OID, 0 };
@@ -147,6 +153,8 @@ int_init( Slapi_PBlock *pb )
(void *) int_compare );
rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_VALIDATE,
(void *) int_validate );
+ rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_NORMALIZE,
+ (void *) int_normalize );
rc |= register_matching_rule_plugins();
LDAPDebug( LDAP_DEBUG_PLUGIN, "<= int_init %d\n", rc, 0, 0 );
@@ -157,8 +165,14 @@ static int
int_filter_ava( Slapi_PBlock *pb, struct berval *bvfilter,
Slapi_Value **bvals, int ftype, Slapi_Value **retVal )
{
- return( string_filter_ava( bvfilter, bvals, SYNTAX_INT | SYNTAX_CES,
- ftype, retVal ) );
+ int filter_normalized = 0;
+ int syntax = SYNTAX_INT | SYNTAX_CES;
+ slapi_pblock_get( pb, SLAPI_PLUGIN_SYNTAX_FILTER_NORMALIZED, &filter_normalized );
+ if (filter_normalized) {
+ syntax |= SYNTAX_NORM_FILT;
+ }
+ return( string_filter_ava( bvfilter, bvals, syntax,
+ ftype, retVal ) );
}
static int
@@ -235,3 +249,14 @@ static int int_validate(
exit:
return(rc);
}
+
+static void int_normalize(
+ Slapi_PBlock *pb,
+ char *s,
+ int trim_spaces,
+ char **alt
+)
+{
+ value_normalize_ext(s, SYNTAX_INT|SYNTAX_CES, trim_spaces, alt);
+ return;
+}
diff --git a/ldap/servers/plugins/syntaxes/nameoptuid.c b/ldap/servers/plugins/syntaxes/nameoptuid.c
index 8a76e05..b5a615e 100644
--- a/ldap/servers/plugins/syntaxes/nameoptuid.c
+++ b/ldap/servers/plugins/syntaxes/nameoptuid.c
@@ -59,6 +59,12 @@ static int nameoptuid_assertion2keys_sub( Slapi_PBlock *pb, char *initial, char
char *final, Slapi_Value ***ivals );
static int nameoptuid_compare(struct berval *v1, struct berval *v2);
static int nameoptuid_validate(struct berval *val);
+static void nameoptuid_normalize(
+ Slapi_PBlock *pb,
+ char *s,
+ int trim_spaces,
+ char **alt
+);
/* the first name is the official one from RFC 4517 */
static char *names[] = { "Name And Optional UID", "nameoptuid", NAMEANDOPTIONALUID_SYNTAX_OID, 0 };
@@ -138,6 +144,8 @@ nameoptuid_init( Slapi_PBlock *pb )
(void *) nameoptuid_compare );
rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_VALIDATE,
(void *) nameoptuid_validate );
+ rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_NORMALIZE,
+ (void *) nameoptuid_normalize );
rc |= register_matching_rule_plugins();
LDAPDebug( LDAP_DEBUG_PLUGIN, "<= nameoptuid_init %d\n", rc, 0, 0 );
@@ -153,7 +161,13 @@ nameoptuid_filter_ava(
Slapi_Value **retVal
)
{
- return( string_filter_ava( bvfilter, bvals, SYNTAX_CIS | SYNTAX_DN,
+ int filter_normalized = 0;
+ int syntax = SYNTAX_CIS | SYNTAX_DN;
+ slapi_pblock_get( pb, SLAPI_PLUGIN_SYNTAX_FILTER_NORMALIZED, &filter_normalized );
+ if (filter_normalized) {
+ syntax |= SYNTAX_NORM_FILT;
+ }
+ return( string_filter_ava( bvfilter, bvals, syntax,
ftype, retVal ) );
}
@@ -272,3 +286,13 @@ exit:
return rc;
}
+static void nameoptuid_normalize(
+ Slapi_PBlock *pb,
+ char *s,
+ int trim_spaces,
+ char **alt
+)
+{
+ value_normalize_ext(s, SYNTAX_CIS | SYNTAX_DN, trim_spaces, alt);
+ return;
+}
diff --git a/ldap/servers/plugins/syntaxes/numericstring.c b/ldap/servers/plugins/syntaxes/numericstring.c
index 0cb4876..4da67a6 100644
--- a/ldap/servers/plugins/syntaxes/numericstring.c
+++ b/ldap/servers/plugins/syntaxes/numericstring.c
@@ -59,6 +59,12 @@ static int numstr_assertion2keys_sub( Slapi_PBlock *pb, char *initial, char **an
char *final, Slapi_Value ***ivals );
static int numstr_compare(struct berval *v1, struct berval *v2);
static int numstr_validate(struct berval *val);
+static void numstr_normalize(
+ Slapi_PBlock *pb,
+ char *s,
+ int trim_spaces,
+ char **alt
+);
/* the first name is the official one from RFC 4517 */
static char *names[] = { "Numeric String", "numstr", NUMERICSTRING_SYNTAX_OID, 0 };
@@ -153,6 +159,8 @@ numstr_init( Slapi_PBlock *pb )
(void *) numstr_compare );
rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_VALIDATE,
(void *) numstr_validate );
+ rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_NORMALIZE,
+ (void *) numstr_normalize );
rc |= register_matching_rule_plugins();
LDAPDebug( LDAP_DEBUG_PLUGIN, "<= numstr_init %d\n", rc, 0, 0 );
@@ -163,7 +171,13 @@ static int
numstr_filter_ava( Slapi_PBlock *pb, struct berval *bvfilter,
Slapi_Value **bvals, int ftype, Slapi_Value **retVal )
{
- return( string_filter_ava( bvfilter, bvals, SYNTAX_SI | SYNTAX_CES,
+ int filter_normalized = 0;
+ int syntax = SYNTAX_SI | SYNTAX_CES;
+ slapi_pblock_get( pb, SLAPI_PLUGIN_SYNTAX_FILTER_NORMALIZED, &filter_normalized );
+ if (filter_normalized) {
+ syntax |= SYNTAX_NORM_FILT;
+ }
+ return( string_filter_ava( bvfilter, bvals, syntax,
ftype, retVal ) );
}
@@ -240,3 +254,14 @@ static int numstr_validate(
exit:
return(rc);
}
+
+static void numstr_normalize(
+ Slapi_PBlock *pb,
+ char *s,
+ int trim_spaces,
+ char **alt
+)
+{
+ value_normalize_ext(s, SYNTAX_SI|SYNTAX_CES, trim_spaces, alt);
+ return;
+}
diff --git a/ldap/servers/plugins/syntaxes/sicis.c b/ldap/servers/plugins/syntaxes/sicis.c
index dd4781a..3608d2c 100644
--- a/ldap/servers/plugins/syntaxes/sicis.c
+++ b/ldap/servers/plugins/syntaxes/sicis.c
@@ -63,6 +63,12 @@ static int sicis_assertion2keys_ava( Slapi_PBlock *pb, Slapi_Value *val,
static int sicis_assertion2keys_sub( Slapi_PBlock *pb, char *initial,
char **any, char *final, Slapi_Value ***ivals );
static int sicis_compare(struct berval *v1, struct berval *v2);
+static void sicis_normalize(
+ Slapi_PBlock *pb,
+ char *s,
+ int trim_spaces,
+ char **alt
+);
/* the first name is the official one from RFC 2252 */
static char *names[] = { "SpaceInsensitiveString",
@@ -102,6 +108,8 @@ sicis_init( Slapi_PBlock *pb )
(void *) SPACE_INSENSITIVE_STRING_SYNTAX_OID );
rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_COMPARE,
(void *) sicis_compare );
+ rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_NORMALIZE,
+ (void *) sicis_normalize );
LDAPDebug( LDAP_DEBUG_PLUGIN, "<= sicis_init %d\n", rc, 0, 0 );
return( rc );
@@ -116,7 +124,13 @@ sicis_filter_ava(
Slapi_Value **retVal
)
{
- return( string_filter_ava( bvfilter, bvals, SYNTAX_SI | SYNTAX_CIS,
+ int filter_normalized = 0;
+ int syntax = SYNTAX_SI | SYNTAX_CIS;
+ slapi_pblock_get( pb, SLAPI_PLUGIN_SYNTAX_FILTER_NORMALIZED, &filter_normalized );
+ if (filter_normalized) {
+ syntax |= SYNTAX_NORM_FILT;
+ }
+ return( string_filter_ava( bvfilter, bvals, syntax,
ftype, retVal ) );
}
@@ -177,3 +191,14 @@ static int sicis_compare(
{
return value_cmp(v1, v2, SYNTAX_SI|SYNTAX_CIS, 3 /* Normalise both values */);
}
+
+static void sicis_normalize(
+ Slapi_PBlock *pb,
+ char *s,
+ int trim_spaces,
+ char **alt
+)
+{
+ value_normalize_ext(s, SYNTAX_SI|SYNTAX_CIS, trim_spaces, alt);
+ return;
+}
diff --git a/ldap/servers/plugins/syntaxes/string.c b/ldap/servers/plugins/syntaxes/string.c
index d70ca5b..f482723 100644
--- a/ldap/servers/plugins/syntaxes/string.c
+++ b/ldap/servers/plugins/syntaxes/string.c
@@ -62,7 +62,8 @@ string_filter_ava( struct berval *bvfilter, Slapi_Value **bvals, int syntax,
int ftype, Slapi_Value **retVal )
{
int i, rc;
- struct berval bvfilter_norm;
+ struct berval bvfilter_norm = {0, NULL};
+ struct berval *pbvfilter_norm = &bvfilter_norm;
char *alt = NULL;
if(retVal) {
@@ -72,19 +73,32 @@ string_filter_ava( struct berval *bvfilter, Slapi_Value **bvals, int syntax,
return( string_filter_approx( bvfilter, bvals, retVal ) );
}
- bvfilter_norm.bv_val = slapi_ch_malloc( bvfilter->bv_len + 1 );
- SAFEMEMCPY( bvfilter_norm.bv_val, bvfilter->bv_val, bvfilter->bv_len );
- bvfilter_norm.bv_val[bvfilter->bv_len] = '\0';
- /* 3rd arg: 1 - trim leading blanks */
- value_normalize_ext( bvfilter_norm.bv_val, syntax, 1, &alt );
- if (alt) {
- slapi_ch_free_string(&bvfilter_norm.bv_val);
- bvfilter_norm.bv_val = alt;
+ if (syntax & SYNTAX_NORM_FILT) {
+ pbvfilter_norm = bvfilter; /* already normalized */
+ } else {
+ bvfilter_norm.bv_val = slapi_ch_malloc( bvfilter->bv_len + 1 );
+ SAFEMEMCPY( bvfilter_norm.bv_val, bvfilter->bv_val, bvfilter->bv_len );
+ bvfilter_norm.bv_val[bvfilter->bv_len] = '\0';
+ /* 3rd arg: 1 - trim leading blanks */
+ value_normalize_ext( bvfilter_norm.bv_val, syntax, 1, &alt );
+ if (alt) {
+ slapi_ch_free_string(&bvfilter_norm.bv_val);
+ bvfilter_norm.bv_val = alt;
+ alt = NULL;
+ }
+ bvfilter_norm.bv_len = strlen(bvfilter_norm.bv_val);
}
- bvfilter_norm.bv_len = strlen(bvfilter_norm.bv_val);
for ( i = 0; (bvals != NULL) && (bvals[i] != NULL); i++ ) {
- rc = value_cmp( (struct berval*)slapi_value_get_berval(bvals[i]), &bvfilter_norm, syntax, 1/* Normalise the first value only */ );
+ int norm_val = 1; /* normalize the first value only */
+ /* if the NORMALIZED flag is set, skip normalizing */
+ if (slapi_value_get_flags(bvals[i]) & SLAPI_ATTR_FLAG_NORMALIZED) {
+ norm_val = 0;
+ }
+ /* note - do not return the normalized value in retVal - the
+ caller will usually want the "raw" value, and can normalize it later
+ */
+ rc = value_cmp( (struct berval*)slapi_value_get_berval(bvals[i]), pbvfilter_norm, syntax, norm_val );
switch ( ftype ) {
case LDAP_FILTER_GE:
if ( rc >= 0 ) {
@@ -205,7 +219,7 @@ string_filter_sub( Slapi_PBlock *pb, char *initial, char **any, char *final,
Slapi_Value **bvals, int syntax )
{
int i, j, rc, size=0;
- char *p, *end, *realval, *tmpbuf, *bigpat = NULL;
+ char *p, *end, *realval, *tmpbuf = NULL, *bigpat = NULL;
size_t tmpbufsize;
char pat[BUFSIZ];
char buf[BUFSIZ];
@@ -218,6 +232,9 @@ string_filter_sub( Slapi_PBlock *pb, char *initial, char **any, char *final,
Slapi_Regex *re = NULL;
const char *re_result = NULL;
char *alt = NULL;
+ int filter_normalized = 0;
+ int free_re = 1;
+ struct subfilt *sf = NULL;
LDAPDebug( LDAP_DEBUG_FILTER, "=> string_filter_sub\n",
0, 0, 0 );
@@ -234,54 +251,85 @@ string_filter_sub( Slapi_PBlock *pb, char *initial, char **any, char *final,
*/
time_up = ( timelimit==-1 ? -1 : optime + timelimit);
- /*
- * construct a regular expression corresponding to the
- * filter and let regex do the work for each value
- * XXX should do this once and save it somewhere XXX
- */
- pat[0] = '\0';
- p = pat;
- end = pat + sizeof(pat) - 2; /* leave room for null */
-
- if ( initial != NULL ) {
- size = strlen( initial ) + 1; /* add 1 for "^" */
+ slapi_pblock_get( pb, SLAPI_PLUGIN_SYNTAX_FILTER_NORMALIZED, &filter_normalized );
+ slapi_pblock_get( pb, SLAPI_PLUGIN_SYNTAX_FILTER_DATA, &sf );
+ if ( sf ) {
+ re = (Slapi_Regex *)sf->sf_private;
+ if ( re ) {
+ free_re = 0;
+ }
}
- if ( any != NULL ) {
- i = 0;
- while ( any[i] ) {
- size += strlen(any[i++]) + 2; /* add 2 for ".*" */
+ if (!re) {
+ /*
+ * construct a regular expression corresponding to the
+ * filter and let regex do the work for each value
+ * XXX should do this once and save it somewhere XXX
+ */
+ pat[0] = '\0';
+ p = pat;
+ end = pat + sizeof(pat) - 2; /* leave room for null */
+
+ if ( initial != NULL ) {
+ size = strlen( initial ) + 1; /* add 1 for "^" */
}
- }
- if ( final != NULL ) {
- size += strlen( final ) + 3; /* add 3 for ".*" and "$" */
- }
+ if ( any != NULL ) {
+ i = 0;
+ while ( any[i] ) {
+ size += strlen(any[i++]) + 2; /* add 2 for ".*" */
+ }
+ }
- size *= 2; /* doubled in case all filter chars need escaping */
- size++; /* add 1 for null */
+ if ( final != NULL ) {
+ size += strlen( final ) + 3; /* add 3 for ".*" and "$" */
+ }
- if ( p + size > end ) {
- bigpat = slapi_ch_malloc( size );
- p = bigpat;
- }
+ size *= 2; /* doubled in case all filter chars need escaping */
+ size++; /* add 1 for null */
- if ( initial != NULL ) {
- /* 3rd arg: 1 - trim leading blanks */
- value_normalize_ext( initial, syntax, 1, &alt );
- *p++ = '^';
- if (alt) {
- filter_strcpy_special_ext( p, alt, FILTER_STRCPY_ESCAPE_RECHARS );
- slapi_ch_free_string(&alt);
- } else {
- filter_strcpy_special_ext( p, initial, FILTER_STRCPY_ESCAPE_RECHARS );
+ if ( p + size > end ) {
+ bigpat = slapi_ch_malloc( size );
+ p = bigpat;
}
- p = strchr( p, '\0' );
- }
- if ( any != NULL ) {
- for ( i = 0; any[i] != NULL; i++ ) {
+
+ if ( initial != NULL ) {
+ /* 3rd arg: 1 - trim leading blanks */
+ if (!filter_normalized) {
+ value_normalize_ext( initial, syntax, 1, &alt );
+ }
+ *p++ = '^';
+ if (alt) {
+ filter_strcpy_special_ext( p, alt, FILTER_STRCPY_ESCAPE_RECHARS );
+ slapi_ch_free_string(&alt);
+ } else {
+ filter_strcpy_special_ext( p, initial, FILTER_STRCPY_ESCAPE_RECHARS );
+ }
+ p = strchr( p, '\0' );
+ }
+ if ( any != NULL ) {
+ for ( i = 0; any[i] != NULL; i++ ) {
+ /* 3rd arg: 0 - DO NOT trim leading blanks */
+ if (!filter_normalized) {
+ value_normalize_ext( any[i], syntax, 0, &alt );
+ }
+ /* ".*" + value */
+ *p++ = '.';
+ *p++ = '*';
+ if (alt) {
+ filter_strcpy_special_ext( p, alt, FILTER_STRCPY_ESCAPE_RECHARS );
+ slapi_ch_free_string(&alt);
+ } else {
+ filter_strcpy_special_ext( p, any[i], FILTER_STRCPY_ESCAPE_RECHARS );
+ }
+ p = strchr( p, '\0' );
+ }
+ }
+ if ( final != NULL ) {
/* 3rd arg: 0 - DO NOT trim leading blanks */
- value_normalize_ext( any[i], syntax, 0, &alt );
+ if (!filter_normalized) {
+ value_normalize_ext( final, syntax, 0, &alt );
+ }
/* ".*" + value */
*p++ = '.';
*p++ = '*';
@@ -289,38 +337,24 @@ string_filter_sub( Slapi_PBlock *pb, char *initial, char **any, char *final,
filter_strcpy_special_ext( p, alt, FILTER_STRCPY_ESCAPE_RECHARS );
slapi_ch_free_string(&alt);
} else {
- filter_strcpy_special_ext( p, any[i], FILTER_STRCPY_ESCAPE_RECHARS );
+ filter_strcpy_special_ext( p, final, FILTER_STRCPY_ESCAPE_RECHARS );
}
- p = strchr( p, '\0' );
- }
- }
- if ( final != NULL ) {
- /* 3rd arg: 0 - DO NOT trim leading blanks */
- value_normalize_ext( final, syntax, 0, &alt );
- /* ".*" + value */
- *p++ = '.';
- *p++ = '*';
- if (alt) {
- filter_strcpy_special_ext( p, alt, FILTER_STRCPY_ESCAPE_RECHARS );
- slapi_ch_free_string(&alt);
+ strcat( p, "$" );
+ }
+
+ /* compile the regex */
+ p = (bigpat) ? bigpat : pat;
+ tmpbuf = NULL;
+ re = slapi_re_comp( p, &re_result );
+ if (NULL == re) {
+ LDAPDebug( LDAP_DEBUG_ANY, "re_comp (%s) failed (%s): %s\n",
+ pat, p, re_result?re_result:"unknown" );
+ rc = LDAP_OPERATIONS_ERROR;
+ goto bailout;
} else {
- filter_strcpy_special_ext( p, final, FILTER_STRCPY_ESCAPE_RECHARS );
+ LDAPDebug( LDAP_DEBUG_TRACE, "re_comp (%s)\n",
+ escape_string( p, ebuf ), 0, 0 );
}
- strcat( p, "$" );
- }
-
- /* compile the regex */
- p = (bigpat) ? bigpat : pat;
- tmpbuf = NULL;
- re = slapi_re_comp( p, &re_result );
- if (NULL == re) {
- LDAPDebug( LDAP_DEBUG_ANY, "re_comp (%s) failed (%s): %s\n",
- pat, p, re_result?re_result:"unknown" );
- rc = LDAP_OPERATIONS_ERROR;
- goto bailout;
- } else {
- LDAPDebug( LDAP_DEBUG_TRACE, "re_comp (%s)\n",
- escape_string( p, ebuf ), 0, 0 );
}
curtime = current_time();
@@ -353,8 +387,9 @@ string_filter_sub( Slapi_PBlock *pb, char *initial, char **any, char *final,
strncpy( realval, bvp->bv_val, tmpbufsize );
}
/* 3rd arg: 1 - trim leading blanks */
- value_normalize_ext( realval, syntax, 1, &alt );
-
+ if (!(slapi_value_get_flags(bvals[j]) & SLAPI_ATTR_FLAG_NORMALIZED)) {
+ value_normalize_ext( realval, syntax, 1, &alt );
+ }
if (alt) {
tmprc = slapi_re_exec( re, alt, time_up );
slapi_ch_free_string(&alt);
@@ -373,7 +408,9 @@ string_filter_sub( Slapi_PBlock *pb, char *initial, char **any, char *final,
}
}
bailout:
- slapi_re_free(re);
+ if (free_re) {
+ slapi_re_free(re);
+ }
slapi_ch_free((void**)&tmpbuf ); /* NULL is fine */
slapi_ch_free((void**)&bigpat ); /* NULL is fine */
@@ -419,9 +456,12 @@ string_values2keys( Slapi_PBlock *pb, Slapi_Value **bvals,
if (alt) {
slapi_ch_free_string(&c);
*nbvlp = slapi_value_new_string_passin(alt);
+ alt = NULL;
} else {
*nbvlp = slapi_value_new_string_passin(c);
}
+ /* new value is normalized */
+ slapi_value_set_flags(*nbvlp, slapi_value_get_flags(*bvlp)|SLAPI_ATTR_FLAG_NORMALIZED);
}
*ivals = nbvals;
break;
@@ -529,18 +569,23 @@ string_values2keys( Slapi_PBlock *pb, Slapi_Value **bvals,
bvdup= slapi_value_new();
for ( bvlp = bvals; bvlp && *bvlp; bvlp++ ) {
- c = slapi_ch_strdup(slapi_value_get_string(*bvlp));
/* 3rd arg: 1 - trim leading blanks */
- value_normalize_ext( c, syntax, 1, &alt );
- if (alt) {
- slapi_ch_free_string(&c);
- slapi_value_set_string_passin(bvdup, alt);
+ if (!(slapi_value_get_flags(*bvlp) & SLAPI_ATTR_FLAG_NORMALIZED)) {
+ c = slapi_ch_strdup(slapi_value_get_string(*bvlp));
+ value_normalize_ext( c, syntax, 1, &alt );
+ if (alt) {
+ slapi_ch_free_string(&c);
+ slapi_value_set_string_passin(bvdup, alt);
+ alt = NULL;
+ } else {
+ slapi_value_set_string_passin(bvdup, c);
+ c = NULL;
+ }
+ bvp = slapi_value_get_berval(bvdup);
} else {
- slapi_value_set_string_passin(bvdup, c);
+ bvp = slapi_value_get_berval(*bvlp);
}
- bvp = slapi_value_get_berval(bvdup);
-
/* leading */
if ( bvp->bv_len > substrlens[INDEX_SUBSTRBEGIN] - 2 ) {
buf[0] = '^';
@@ -549,6 +594,7 @@ string_values2keys( Slapi_PBlock *pb, Slapi_Value **bvals,
}
buf[substrlens[INDEX_SUBSTRBEGIN]] = '\0';
(*ivals)[n] = slapi_value_new_string(buf);
+ slapi_value_set_flags((*ivals)[n], slapi_value_get_flags(*bvlp)|SLAPI_ATTR_FLAG_NORMALIZED);
n++;
}
@@ -561,6 +607,7 @@ string_values2keys( Slapi_PBlock *pb, Slapi_Value **bvals,
}
buf[substrlens[INDEX_SUBSTRMIDDLE]] = '\0';
(*ivals)[n] = slapi_value_new_string(buf);
+ slapi_value_set_flags((*ivals)[n], slapi_value_get_flags(*bvlp)|SLAPI_ATTR_FLAG_NORMALIZED);
n++;
}
@@ -573,6 +620,7 @@ string_values2keys( Slapi_PBlock *pb, Slapi_Value **bvals,
buf[substrlens[INDEX_SUBSTREND] - 1] = '$';
buf[substrlens[INDEX_SUBSTREND]] = '\0';
(*ivals)[n] = slapi_value_new_string(buf);
+ slapi_value_set_flags((*ivals)[n], slapi_value_get_flags(*bvlp)|SLAPI_ATTR_FLAG_NORMALIZED);
n++;
}
}
@@ -602,6 +650,7 @@ string_assertion2keys_ava(
char *w, *c;
Slapi_Value *tmpval=NULL;
char *alt = NULL;
+ unsigned long flags = val ? slapi_value_get_flags(val) : 0;
switch ( ftype ) {
case LDAP_FILTER_EQUALITY_FAST:
@@ -613,26 +662,34 @@ string_assertion2keys_ava(
}
memcpy(tmpval->bv.bv_val,slapi_value_get_string(val),len);
tmpval->bv.bv_val[len]='\0';
- /* 3rd arg: 1 - trim leading blanks */
- value_normalize_ext(tmpval->bv.bv_val, syntax, 1, &alt );
- if (alt) {
- if (len >= tmpval->bv.bv_len) {
- slapi_ch_free_string(&tmpval->bv.bv_val);
+ if (!(flags & SLAPI_ATTR_FLAG_NORMALIZED)) {
+ /* 3rd arg: 1 - trim leading blanks */
+ value_normalize_ext(tmpval->bv.bv_val, syntax, 1, &alt );
+ if (alt) {
+ if (len >= tmpval->bv.bv_len) {
+ slapi_ch_free_string(&tmpval->bv.bv_val);
+ }
+ tmpval->bv.bv_val = alt;
+ alt = NULL;
}
- tmpval->bv.bv_val = alt;
+ tmpval->bv.bv_len=strlen(tmpval->bv.bv_val);
}
- tmpval->bv.bv_len=strlen(tmpval->bv.bv_val);
+ slapi_value_set_flags(tmpval, flags|SLAPI_ATTR_FLAG_NORMALIZED);
break;
case LDAP_FILTER_EQUALITY:
(*ivals) = (Slapi_Value **) slapi_ch_malloc( 2 * sizeof(Slapi_Value *) );
(*ivals)[0] = slapi_value_dup( val );
- /* 3rd arg: 1 - trim leading blanks */
- value_normalize_ext( (*ivals)[0]->bv.bv_val, syntax, 1, &alt );
- if (alt) {
- slapi_ch_free_string(&(*ivals)[0]->bv.bv_val);
- (*ivals)[0]->bv.bv_val = alt;
+ if (!(flags & SLAPI_ATTR_FLAG_NORMALIZED)) {
+ /* 3rd arg: 1 - trim leading blanks */
+ value_normalize_ext( (*ivals)[0]->bv.bv_val, syntax, 1, &alt );
+ if (alt) {
+ slapi_ch_free_string(&(*ivals)[0]->bv.bv_val);
+ (*ivals)[0]->bv.bv_val = alt;
+ (*ivals)[0]->bv.bv_len = strlen( (*ivals)[0]->bv.bv_val );
+ alt = NULL;
+ }
+ slapi_value_set_flags((*ivals)[0], flags|SLAPI_ATTR_FLAG_NORMALIZED);
}
- (*ivals)[0]->bv.bv_len = strlen( (*ivals)[0]->bv.bv_val );
(*ivals)[1] = NULL;
break;
diff --git a/ldap/servers/plugins/syntaxes/syntax.h b/ldap/servers/plugins/syntaxes/syntax.h
index 0a9c738..e0fee81 100644
--- a/ldap/servers/plugins/syntaxes/syntax.h
+++ b/ldap/servers/plugins/syntaxes/syntax.h
@@ -54,6 +54,7 @@
#define SYNTAX_DN 8 /* distinguished name: used with SYNTAX_CIS */
#define SYNTAX_SI 16 /* space insensitive: used with SYNTAX_CIS */
#define SYNTAX_INT 32 /* INTEGER */
+#define SYNTAX_NORM_FILT 64 /* filter already normalized */
#define SUBBEGIN 3
#define SUBMIDDLE 3
diff --git a/ldap/servers/plugins/syntaxes/tel.c b/ldap/servers/plugins/syntaxes/tel.c
index 10c7ced..65b6ddd 100644
--- a/ldap/servers/plugins/syntaxes/tel.c
+++ b/ldap/servers/plugins/syntaxes/tel.c
@@ -59,6 +59,12 @@ static int tel_assertion2keys_sub( Slapi_PBlock *pb, char *initial, char **any,
char *final, Slapi_Value ***ivals );
static int tel_compare(struct berval *v1, struct berval *v2);
static int tel_validate(struct berval *val);
+static void tel_normalize(
+ Slapi_PBlock *pb,
+ char *s,
+ int trim_spaces,
+ char **alt
+);
/* the first name is the official one from RFC 2252 */
static char *names[] = { "TelephoneNumber", "tel", TELEPHONE_SYNTAX_OID, 0 };
@@ -159,6 +165,8 @@ tel_init( Slapi_PBlock *pb )
(void *) tel_compare );
rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_VALIDATE,
(void *) tel_validate );
+ rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_NORMALIZE,
+ (void *) tel_normalize );
rc |= register_matching_rule_plugins();
LDAPDebug( LDAP_DEBUG_PLUGIN, "<= tel_init %d\n", rc, 0, 0 );
@@ -174,7 +182,13 @@ tel_filter_ava(
Slapi_Value **retVal
)
{
- return( string_filter_ava( bvfilter, bvals, SYNTAX_TEL | SYNTAX_CIS,
+ int filter_normalized = 0;
+ int syntax = SYNTAX_TEL | SYNTAX_CIS;
+ slapi_pblock_get( pb, SLAPI_PLUGIN_SYNTAX_FILTER_NORMALIZED, &filter_normalized );
+ if (filter_normalized) {
+ syntax |= SYNTAX_NORM_FILT;
+ }
+ return( string_filter_ava( bvfilter, bvals, syntax,
ftype, retVal ) );
}
@@ -267,3 +281,14 @@ tel_validate(
exit:
return rc;
}
+
+static void tel_normalize(
+ Slapi_PBlock *pb,
+ char *s,
+ int trim_spaces,
+ char **alt
+)
+{
+ value_normalize_ext(s, SYNTAX_TEL|SYNTAX_CIS, trim_spaces, alt);
+ return;
+}
diff --git a/ldap/servers/plugins/syntaxes/teletex.c b/ldap/servers/plugins/syntaxes/teletex.c
index 0d1f36d..3e328a9 100644
--- a/ldap/servers/plugins/syntaxes/teletex.c
+++ b/ldap/servers/plugins/syntaxes/teletex.c
@@ -60,6 +60,12 @@ static int teletex_assertion2keys_sub( Slapi_PBlock *pb, char *initial, char **a
static int teletex_compare(struct berval *v1, struct berval *v2);
static int teletex_validate(struct berval *val);
static int ttx_param_validate(const char *start, const char *end);
+static void teletex_normalize(
+ Slapi_PBlock *pb,
+ char *s,
+ int trim_spaces,
+ char **alt
+);
/* the first name is the official one from RFC 4517 */
static char *names[] = { "Teletex Terminal Identifier", "teletextermid", TELETEXTERMID_SYNTAX_OID, 0 };
@@ -99,6 +105,8 @@ teletex_init( Slapi_PBlock *pb )
(void *) teletex_compare );
rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_VALIDATE,
(void *) teletex_validate );
+ rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_NORMALIZE,
+ (void *) teletex_normalize );
LDAPDebug( LDAP_DEBUG_PLUGIN, "<= teletex_init %d\n", rc, 0, 0 );
return( rc );
@@ -113,7 +121,13 @@ teletex_filter_ava(
Slapi_Value **retVal
)
{
- return( string_filter_ava( bvfilter, bvals, SYNTAX_CIS,
+ int filter_normalized = 0;
+ int syntax = SYNTAX_CIS;
+ slapi_pblock_get( pb, SLAPI_PLUGIN_SYNTAX_FILTER_NORMALIZED, &filter_normalized );
+ if (filter_normalized) {
+ syntax |= SYNTAX_NORM_FILT;
+ }
+ return( string_filter_ava( bvfilter, bvals, syntax,
ftype, retVal ) );
}
@@ -340,3 +354,14 @@ ttx_param_validate(
exit:
return rc;
}
+
+static void teletex_normalize(
+ Slapi_PBlock *pb,
+ char *s,
+ int trim_spaces,
+ char **alt
+)
+{
+ value_normalize_ext(s, SYNTAX_CIS, trim_spaces, alt);
+ return;
+}
diff --git a/ldap/servers/plugins/syntaxes/telex.c b/ldap/servers/plugins/syntaxes/telex.c
index 456f8a2..6803810 100644
--- a/ldap/servers/plugins/syntaxes/telex.c
+++ b/ldap/servers/plugins/syntaxes/telex.c
@@ -59,6 +59,12 @@ static int telex_assertion2keys_sub( Slapi_PBlock *pb, char *initial, char **any
char *final, Slapi_Value ***ivals );
static int telex_compare(struct berval *v1, struct berval *v2);
static int telex_validate(struct berval *val);
+static void telex_normalize(
+ Slapi_PBlock *pb,
+ char *s,
+ int trim_spaces,
+ char **alt
+);
/* the first name is the official one from RFC 4517 */
static char *names[] = { "Telex Number", "telexnumber", TELEXNUMBER_SYNTAX_OID, 0 };
@@ -98,6 +104,8 @@ telex_init( Slapi_PBlock *pb )
(void *) telex_compare );
rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_VALIDATE,
(void *) telex_validate );
+ rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_NORMALIZE,
+ (void *) telex_normalize );
LDAPDebug( LDAP_DEBUG_PLUGIN, "<= telex_init %d\n", rc, 0, 0 );
return( rc );
@@ -112,8 +120,14 @@ telex_filter_ava(
Slapi_Value **retVal
)
{
- return( string_filter_ava( bvfilter, bvals, SYNTAX_CIS,
- ftype, retVal ) );
+ int filter_normalized = 0;
+ int syntax = SYNTAX_CIS;
+ slapi_pblock_get( pb, SLAPI_PLUGIN_SYNTAX_FILTER_NORMALIZED, &filter_normalized );
+ if (filter_normalized) {
+ syntax |= SYNTAX_NORM_FILT;
+ }
+ return( string_filter_ava( bvfilter, bvals, syntax,
+ ftype, retVal ) );
}
@@ -255,3 +269,13 @@ exit:
return rc;
}
+static void telex_normalize(
+ Slapi_PBlock *pb,
+ char *s,
+ int trim_spaces,
+ char **alt
+)
+{
+ value_normalize_ext(s, SYNTAX_CIS, trim_spaces, alt);
+ return;
+}
diff --git a/ldap/servers/plugins/syntaxes/value.c b/ldap/servers/plugins/syntaxes/value.c
index 70fa097..efef9a8 100644
--- a/ldap/servers/plugins/syntaxes/value.c
+++ b/ldap/servers/plugins/syntaxes/value.c
@@ -107,6 +107,10 @@ value_normalize_ext(
}
*alt = NULL;
+ if (NULL == s) {
+ return;
+ }
+
if ( ! (syntax & SYNTAX_CIS) && ! (syntax & SYNTAX_CES) ) {
return;
}
diff --git a/ldap/servers/slapd/attr.c b/ldap/servers/slapd/attr.c
index 05db7af..26d5947 100644
--- a/ldap/servers/slapd/attr.c
+++ b/ldap/servers/slapd/attr.c
@@ -411,6 +411,7 @@ slapi_attr_value_find( const Slapi_Attr *a, const struct berval *v )
ava.ava_type = a->a_type;
ava.ava_value = *v;
+ ava.ava_private = NULL;
return(plugin_call_syntax_filter_ava( a, LDAP_FILTER_EQUALITY, &ava ));
}
@@ -553,10 +554,12 @@ slapi_attr_value_cmp( const Slapi_Attr *a, const struct berval *v1, const struct
cvals[0] = &tmpcval;
cvals[0]->v_csnset = NULL;
cvals[0]->bv = *v1;
+ cvals[0]->v_flags = 0;
cvals[1] = NULL;
a2.a_present_values.va = cvals; /* JCM - PUKE */
ava.ava_type = a->a_type;
ava.ava_value = *v2;
+ ava.ava_private = NULL;
retVal = plugin_call_syntax_filter_ava(&a2, LDAP_FILTER_EQUALITY, &ava);
}
return retVal;
@@ -673,6 +676,7 @@ attr_value_find_wsi(Slapi_Attr *a, const struct berval *bval, Slapi_Value **valu
*/
ava.ava_type = a->a_type;
ava.ava_value = *bval;
+ ava.ava_private = NULL;
retVal = plugin_call_syntax_filter_ava_sv(a, LDAP_FILTER_EQUALITY, &ava, value, 0 /* Present */);
if(retVal==0)
diff --git a/ldap/servers/slapd/ava.c b/ldap/servers/slapd/ava.c
index 1acc5ef..e97e9e7 100644
--- a/ldap/servers/slapd/ava.c
+++ b/ldap/servers/slapd/ava.c
@@ -67,6 +67,7 @@ get_ava(
}
ava->ava_type = slapi_attr_syntax_normalize(type);
slapi_ch_free_string( &type );
+ ava->ava_private = NULL;
return( 0 );
}
@@ -97,6 +98,7 @@ rdn2ava(
strcpy_unescape_value( s, s );
ava->ava_value.bv_val = s;
ava->ava_value.bv_len = strlen( s );
+ ava->ava_private = NULL;
return( 0 );
}
diff --git a/ldap/servers/slapd/back-ldbm/back-ldbm.h b/ldap/servers/slapd/back-ldbm/back-ldbm.h
index 3d34682..3a92f59 100644
--- a/ldap/servers/slapd/back-ldbm/back-ldbm.h
+++ b/ldap/servers/slapd/back-ldbm/back-ldbm.h
@@ -790,6 +790,7 @@ typedef struct _back_search_result_set
Slapi_Entry* sr_vlventry; /* a special VLV Entry for when the ACL check fails */
int sr_flags; /* Magic flags, defined below */
int sr_current_sizelimit; /* Current sizelimit */
+ Slapi_Filter* sr_norm_filter; /* search filter pre-normalized */
} back_search_result_set;
#define SR_FLAG_CAN_SKIP_FILTER_TEST 1 /* If set in sr_flags, means that we can safely skip the filter test */
diff --git a/ldap/servers/slapd/back-ldbm/filterindex.c b/ldap/servers/slapd/back-ldbm/filterindex.c
index d214c54..fbc8ccf 100644
--- a/ldap/servers/slapd/back-ldbm/filterindex.c
+++ b/ldap/servers/slapd/back-ldbm/filterindex.c
@@ -303,6 +303,7 @@ ava_candidates(
tmp.bv = *bval;
tmp.v_csnset=NULL;
+ tmp.v_flags = 0;
fake.bv.bv_val=buf;
fake.bv.bv_len=sizeof(buf);
ptr[0]=&fake;
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_attr.c b/ldap/servers/slapd/back-ldbm/ldbm_attr.c
index b95f2ff..d09413f 100644
--- a/ldap/servers/slapd/back-ldbm/ldbm_attr.c
+++ b/ldap/servers/slapd/back-ldbm/ldbm_attr.c
@@ -461,39 +461,6 @@ ldbm_compute_evaluator(computed_attr_context *c,char* type,Slapi_Entry *e,slapi_
return -1; /* I see no ships */
}
-/*
- * string_find(): case sensitive search for the substring str2 within str1.
- */
-static
-char * string_find (
- const char * str1,
- const char * str2
- )
-{
- char *cp = (char *) str1;
- char *s1, *s2;
-
- if ( !*str2 )
- return((char *)str1);
-
- while (*cp)
- {
- s1 = cp;
- s2 = (char *) str2;
-
- while ( *s1 && *s2 && !(*s1-*s2) )
- s1++, s2++;
-
- if (!*s2)
- return(cp);
-
- cp++;
- }
-
- return(NULL);
-
-}
-
/* What are we doing ?
The back-end can't search properly for the hasSubordinates and
numSubordinates attributes. The reason being that they're not
@@ -727,12 +694,10 @@ ldbm_compute_rewriter(Slapi_PBlock *pb)
slapi_pblock_get( pb, SLAPI_SEARCH_STRFILTER, &fstr );
if ( NULL != fstr ) {
- char *lc_fstr = (char *)slapi_utf8StrToLower( (unsigned char *)fstr );
-
- if (lc_fstr && string_find(lc_fstr,"subordinates")) {
+ if (PL_strcasestr(fstr, "subordinates")) {
Slapi_Filter *f = NULL;
/* Look for special filters we want to leave alone */
- if (0 == strcmp(lc_fstr, "(&(numsubordinates=*)(numsubordinates>=1))" )) {
+ if (0 == strcasecmp(fstr, "(&(numsubordinates=*)(numsubordinates>=1))" )) {
; /* Do nothing, this one works OK */
} else {
/* So let's grok the filter in detail and try to rewrite it */
@@ -744,8 +709,6 @@ ldbm_compute_rewriter(Slapi_PBlock *pb)
}
}
}
-
- slapi_ch_free_string( &lc_fstr );
}
return rc;
}
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_search.c b/ldap/servers/slapd/back-ldbm/ldbm_search.c
index 91b0280..46309eb 100644
--- a/ldap/servers/slapd/back-ldbm/ldbm_search.c
+++ b/ldap/servers/slapd/back-ldbm/ldbm_search.c
@@ -198,6 +198,100 @@ ldbm_back_search_cleanup(Slapi_PBlock *pb,
return function_result;
}
+static int
+ldbm_search_compile_filter(Slapi_Filter *f, void *arg)
+{
+ int rc = SLAPI_FILTER_SCAN_CONTINUE;
+ if (f->f_choice == LDAP_FILTER_SUBSTRINGS) {
+ char pat[BUFSIZ];
+ char *p, *end, *tmpbuf, *bigpat = NULL;
+ size_t size = 0;
+ Slapi_Regex *re = NULL;
+ const char *re_result = NULL;
+ int i = 0;
+ char ebuf[BUFSIZ];
+
+ PR_ASSERT(NULL == f->f_un.f_un_sub.sf_private);
+ /*
+ * construct a regular expression corresponding to the filter
+ */
+ pat[0] = '\0';
+ p = pat;
+ end = pat + sizeof(pat) - 2; /* leave room for null */
+
+ if (f->f_sub_initial != NULL) {
+ size = strlen(f->f_sub_initial) + 1; /* add 1 for "^" */
+ }
+
+ while (f->f_sub_any && f->f_sub_any[i]) {
+ size += strlen(f->f_sub_any[i++]) + 2; /* add 2 for ".*" */
+ }
+
+ if (f->f_sub_final != NULL) {
+ size += strlen(f->f_sub_final) + 3; /* add 3 for ".*" and "$" */
+ }
+
+ size *= 2; /* doubled in case all filter chars need escaping (regex special chars) */
+ size++; /* add 1 for null */
+
+ if (p + size > end) {
+ bigpat = slapi_ch_malloc(size);
+ p = bigpat;
+ }
+ if (f->f_sub_initial != NULL) {
+ *p++ = '^';
+ p = filter_strcpy_special_ext(p, f->f_sub_initial, FILTER_STRCPY_ESCAPE_RECHARS);
+ }
+ for (i = 0; f->f_sub_any && f->f_sub_any[i]; i++) {
+ /* ".*" + value */
+ *p++ = '.';
+ *p++ = '*';
+ p = filter_strcpy_special_ext(p, f->f_sub_any[i], FILTER_STRCPY_ESCAPE_RECHARS);
+ }
+ if (f->f_sub_final != NULL) {
+ /* ".*" + value */
+ *p++ = '.';
+ *p++ = '*';
+ p = filter_strcpy_special_ext(p, f->f_sub_final, FILTER_STRCPY_ESCAPE_RECHARS);
+ strcat(p, "$");
+ }
+
+ /* compile the regex */
+ p = bigpat ? bigpat : pat;
+ tmpbuf = NULL;
+ re = slapi_re_comp(p, &re_result);
+ if (NULL == re) {
+ LDAPDebug(LDAP_DEBUG_ANY, "ldbm_search_compile_filter: re_comp (%s) failed (%s): %s\n",
+ pat, p, re_result?re_result:"unknown" );
+ rc = SLAPI_FILTER_SCAN_ERROR;
+ } else {
+ LDAPDebug(LDAP_DEBUG_TRACE, "ldbm_search_compile_filter: re_comp (%s)\n",
+ escape_string(p, ebuf), 0, 0);
+ f->f_un.f_un_sub.sf_private = (void *)re;
+ }
+ } else if (f->f_choice == LDAP_FILTER_EQUALITY) {
+ /* store the flags in the ava_private - should be ok - points
+ to itself - no dangling references */
+ f->f_un.f_un_ava.ava_private = &f->f_flags;
+ }
+ return rc;
+}
+
+static int
+ldbm_search_free_compiled_filter(Slapi_Filter *f, void *arg)
+{
+ int rc = SLAPI_FILTER_SCAN_CONTINUE;
+ if ((f->f_choice == LDAP_FILTER_SUBSTRINGS) &&
+ (f->f_un.f_un_sub.sf_private)) {
+ slapi_re_free((Slapi_Regex *)f->f_un.f_un_sub.sf_private);
+ f->f_un.f_un_sub.sf_private = NULL;
+ } else if (f->f_choice == LDAP_FILTER_EQUALITY) {
+ /* clear the flags in the ava_private */
+ f->f_un.f_un_ava.ava_private = NULL;
+ }
+ return rc;
+}
+
/*
* Return values from ldbm_back_search are:
*
@@ -774,6 +868,32 @@ ldbm_back_search( Slapi_PBlock *pb )
}
}
+ /* if we need to perform the filter test, pre-digest the filter to
+ speed up the filter test */
+ if ( !(sr->sr_flags & SR_FLAG_CAN_SKIP_FILTER_TEST) ||
+ li->li_filter_bypass_check ) {
+ int rc = 0, filt_errs = 0;
+ Slapi_Filter *filter= NULL;
+
+ slapi_pblock_get(pb, SLAPI_SEARCH_FILTER, &filter);
+ slapi_filter_free(sr->sr_norm_filter, 1);
+ sr->sr_norm_filter = slapi_filter_dup(filter);
+ /* step 1 - normalize all of the values used in the search filter */
+ slapi_filter_normalize(sr->sr_norm_filter, PR_TRUE /* normalize values too */);
+ /* step 2 - pre-compile the substr regex and the equality flags */
+ rc = slapi_filter_apply(sr->sr_norm_filter, ldbm_search_compile_filter,
+ NULL, &filt_errs);
+ if (rc != SLAPI_FILTER_SCAN_NOMORE) {
+ LDAPDebug2Args(LDAP_DEBUG_ANY,
+ "ERROR: could not pre-compile the search filter - error %d %d\n",
+ rc, filt_errs);
+ if (rc == SLAPI_FILTER_SCAN_ERROR) {
+ tmp_err = LDAP_OPERATIONS_ERROR;
+ tmp_desc = "Could not compile regex for filter matching";
+ }
+ }
+ }
+
/* Fix for bugid #394184, SD, 05 Jul 00 */
/* tmp_err == -1: no error */
return ldbm_back_search_cleanup(pb, li, sort_control, tmp_err, tmp_desc,
@@ -1234,6 +1354,12 @@ ldbm_back_next_search_entry_ext( Slapi_PBlock *pb, int use_extension )
goto bail;
}
+ if (sr->sr_norm_filter) {
+ int val = 1;
+ slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_FILTER_NORMALIZED, &val );
+ filter = sr->sr_norm_filter;
+ }
+
if (NULL == basesdn) {
slapi_send_ldap_result( pb, LDAP_INVALID_DN_SYNTAX, NULL,
"Null target DN", 0, NULL );
@@ -1602,6 +1728,7 @@ new_search_result_set(IDList *idl, int vlv, int lookthroughlimit)
static void
delete_search_result_set( back_search_result_set **sr )
{
+ int rc = 0, filt_errs = 0;
if ( NULL == sr || NULL == *sr)
{
return;
@@ -1610,6 +1737,14 @@ delete_search_result_set( back_search_result_set **sr )
{
idl_free( (*sr)->sr_candidates );
}
+ rc = slapi_filter_apply((*sr)->sr_norm_filter, ldbm_search_free_compiled_filter,
+ NULL, &filt_errs);
+ if (rc != SLAPI_FILTER_SCAN_NOMORE) {
+ LDAPDebug2Args(LDAP_DEBUG_ANY,
+ "ERROR: could not free the pre-compiled regexes in the search filter - error %d %d\n",
+ rc, filt_errs);
+ }
+ slapi_filter_free((*sr)->sr_norm_filter, 1);
memset( *sr, 0, sizeof( back_search_result_set ) );
slapi_ch_free( (void**)sr );
}
diff --git a/ldap/servers/slapd/filter.c b/ldap/servers/slapd/filter.c
index b4a3102..f7028dc 100644
--- a/ldap/servers/slapd/filter.c
+++ b/ldap/servers/slapd/filter.c
@@ -689,6 +689,7 @@ slapi_filter_dup(Slapi_Filter *f)
out->f_choice = f->f_choice;
out->f_hash = f->f_hash;
+ out->f_flags = f->f_flags;
LDAPDebug( LDAP_DEBUG_FILTER, "slapi_filter_dup type 0x%lX\n", f->f_choice, 0, 0 );
switch ( f->f_choice ) {
@@ -719,9 +720,6 @@ slapi_filter_dup(Slapi_Filter *f)
case LDAP_FILTER_OR:
case LDAP_FILTER_NOT:
outl = &out->f_list;
-
-/* out->f_list = slapi_filter_dup(f->f_list);
-*/
for (fl = f->f_list; fl != NULL; fl = fl->f_next) {
(*outl) = slapi_filter_dup( fl );
(*outl)->f_next = 0;
@@ -733,18 +731,15 @@ slapi_filter_dup(Slapi_Filter *f)
break;
case LDAP_FILTER_EXTENDED:
- /* something needs to be done here, but Im not sure how to do it
- slapi_ch_free((void**)&f->f_mr_oid);
- slapi_ch_free((void**)&f->f_mr_type);
- slapi_ch_free((void **)&f->f_mr_value.bv_val );
- if (f->f_mr.mrf_destroy != NULL) {
- Slapi_PBlock pb;
- pblock_init (&pb);
- if ( ! slapi_pblock_set (&pb, SLAPI_PLUGIN_OBJECT, f->f_mr.mrf_object)) {
- f->f_mr.mrf_destroy (&pb);
- }
+ out->f_mr_oid = slapi_ch_strdup(f->f_mr_oid);
+ out->f_mr_type = slapi_ch_strdup(f->f_mr_type);
+ out->f_mr_value.bv_val = slapi_ch_strdup(f->f_mr_value.bv_val);
+ out->f_mr_value.bv_len = f->f_mr_value.bv_len;
+ out->f_mr_dnAttrs = f->f_mr_dnAttrs;
+ if (f->f_mr.mrf_match) {
+ int rc = plugin_mr_filter_create(&out->f_mr);
+ LDAPDebug1Arg( LDAP_DEBUG_FILTER, "slapi_filter_dup plugin_mr_filter_create returned %d\n", rc );
}
- */
break;
default:
@@ -1043,34 +1038,92 @@ slapi_filter_get_subfilt(
}
static void
-filter_normalize_ava( struct ava *ava, int ftype )
+filter_normalize_ava( struct slapi_filter *f, PRBool norm_values )
{
- char *tmp;
+ char *tmp;
+ struct ava *ava;
- if ( ava == NULL ) {
- return;
+ if ( f == NULL ) {
+ return;
}
+
+ ava = &f->f_ava;
tmp = ava->ava_type;
ava->ava_type = slapi_attr_syntax_normalize(tmp);
slapi_ch_free((void**)&tmp );
- /* value will be normalized later */
+ f->f_flags |= SLAPI_FILTER_NORMALIZED_TYPE;
+ if (norm_values) {
+ char *newval = NULL;
+ /* NOTE: assumes ava->ava_value.bv_val is NULL terminated - get_ava/ber_scanf 'o'
+ will NULL terminate the string by default */
+ slapi_attr_value_normalize(NULL, NULL, ava->ava_type, ava->ava_value.bv_val, 1, &newval);
+ if (newval && (newval != ava->ava_value.bv_val)) {
+ slapi_ch_free_string(&ava->ava_value.bv_val);
+ ava->ava_value.bv_val = newval;
+ ava->ava_value.bv_len = strlen(newval);
+ }
+ f->f_flags |= SLAPI_FILTER_NORMALIZED_VALUE;
+ }
}
+static void
+filter_normalize_subfilt( struct slapi_filter *f, PRBool norm_values )
+{
+ struct subfilt *sf;
+
+ if ( f == NULL ) {
+ return;
+ }
+
+ sf = &f->f_sub;
+ char *tmp = sf->sf_type;
+ sf->sf_type = slapi_attr_syntax_normalize(tmp);
+ slapi_ch_free((void**)&tmp );
+ f->f_flags |= SLAPI_FILTER_NORMALIZED_TYPE;
+ if (norm_values) {
+ char *newval = NULL;
+ Slapi_Attr attr;
+ int ii;
+
+ slapi_attr_init(&attr, sf->sf_type);
+ slapi_attr_value_normalize(NULL, &attr, NULL, sf->sf_initial, 1, &newval);
+ if (newval && (newval != sf->sf_initial)) {
+ slapi_ch_free_string(&sf->sf_initial);
+ sf->sf_initial = newval;
+ }
+ for (ii = 0; sf->sf_any && sf->sf_any[ii]; ++ii) {
+ newval = NULL;
+ /* do not trim spaces of sf_any values - see string_filter_sub() */
+ slapi_attr_value_normalize(NULL, &attr, NULL, sf->sf_any[ii], 0, &newval);
+ if (newval && (newval != sf->sf_any[ii])) {
+ slapi_ch_free_string(&sf->sf_any[ii]);
+ sf->sf_any[ii] = newval;
+ }
+ }
+ newval = NULL;
+ /* do not trim spaces of sf_final values - see string_filter_sub() */
+ slapi_attr_value_normalize(NULL, &attr, NULL, sf->sf_final, 0, &newval);
+ if (newval && (newval != sf->sf_final)) {
+ slapi_ch_free_string(&sf->sf_final);
+ sf->sf_final = newval;
+ }
+ attr_done(&attr);
+ f->f_flags |= SLAPI_FILTER_NORMALIZED_VALUE;
+ }
+}
-void filter_normalize( struct slapi_filter *f );
+void filter_normalize_ext( struct slapi_filter *f, PRBool norm_values );
static void
-filter_normalize_list( struct slapi_filter *flist )
+filter_normalize_list( struct slapi_filter *flist, PRBool norm_values )
{
struct slapi_filter *f;
for ( f = flist; f != NULL; f = f->f_next ) {
- filter_normalize( f );
+ filter_normalize_ext( f, norm_values );
}
}
-
-
/*
* Normalize all values and types in a filter. This isn't necessary
* when we've read the slapi_filter off the wire, but if we've hand-constructed
@@ -1080,7 +1133,7 @@ filter_normalize_list( struct slapi_filter *flist )
* normalized.
*/
void
-filter_normalize( struct slapi_filter *f )
+filter_normalize_ext( struct slapi_filter *f, PRBool norm_values )
{
char *tmp;
@@ -1093,38 +1146,49 @@ filter_normalize( struct slapi_filter *f )
case LDAP_FILTER_LE:
case LDAP_FILTER_APPROX:
case LDAP_FILTER_EQUALITY:
- filter_normalize_ava( &f->f_ava, f->f_choice );
+ filter_normalize_ava( f, norm_values );
break;
case LDAP_FILTER_SUBSTRINGS:
- tmp = f->f_sub_type;
- f->f_sub_type = slapi_attr_syntax_normalize(tmp);
- slapi_ch_free((void**)&tmp );
- /* value will be normalized later */
+ filter_normalize_subfilt( f, norm_values );
break;
case LDAP_FILTER_PRESENT:
tmp = f->f_type;
f->f_type = slapi_attr_syntax_normalize(tmp);
slapi_ch_free((void**)&tmp );
+ f->f_flags |= SLAPI_FILTER_NORMALIZED_TYPE;
break;
case LDAP_FILTER_EXTENDED:
tmp = f->f_mr_type;
f->f_mr_type = slapi_attr_syntax_normalize(tmp);
slapi_ch_free((void**)&tmp );
+ f->f_flags |= SLAPI_FILTER_NORMALIZED_TYPE;
break;
case LDAP_FILTER_AND:
- filter_normalize_list( f->f_and );
+ filter_normalize_list( f->f_and, norm_values );
break;
case LDAP_FILTER_OR:
- filter_normalize_list( f->f_or );
+ filter_normalize_list( f->f_or, norm_values );
break;
case LDAP_FILTER_NOT:
- filter_normalize_list( f->f_not );
+ filter_normalize_list( f->f_not, norm_values );
break;
default:
return;
}
}
-
+
+void
+filter_normalize( struct slapi_filter *f )
+{
+ filter_normalize_ext(f, PR_FALSE);
+}
+
+void
+slapi_filter_normalize( struct slapi_filter *f, PRBool norm_values )
+{
+ filter_normalize_ext(f, norm_values);
+}
+
void
filter_print( struct slapi_filter *f )
{
diff --git a/ldap/servers/slapd/filtercmp.c b/ldap/servers/slapd/filtercmp.c
index 37c4591..e0ade67 100644
--- a/ldap/servers/slapd/filtercmp.c
+++ b/ldap/servers/slapd/filtercmp.c
@@ -91,6 +91,7 @@ static Slapi_Value **get_normalized_value(const Slapi_Attr *sattr, struct ava *a
sv.bv = ava->ava_value;
sv.v_csnset = NULL;
+ sv.v_flags = 0;
svlist[0] = &sv;
svlist[1] = NULL;
if ((slapi_attr_values2keys_sv(sattr, svlist, &keylist,
diff --git a/ldap/servers/slapd/filterentry.c b/ldap/servers/slapd/filterentry.c
index f217128..549bac7 100644
--- a/ldap/servers/slapd/filterentry.c
+++ b/ldap/servers/slapd/filterentry.c
@@ -498,8 +498,9 @@ test_extensible_filter(
*/
struct ava a;
a.ava_type= mrf->mrf_type;
- a.ava_value.bv_len= mrf->mrf_value.bv_len;
+ a.ava_value.bv_len= mrf->mrf_value.bv_len;
a.ava_value.bv_val = mrf->mrf_value.bv_val;
+ a.ava_private = NULL;
rc= test_ava_filter( callers_pb, e, e->e_attrs, &a, LDAP_FILTER_EQUALITY, 0 /* Don't Verify Access */ , 0 /* don't just verify access */, access_check_done );
if(rc!=LDAP_SUCCESS && mrf->mrf_dnAttrs)
{
@@ -566,8 +567,9 @@ test_extensible_filter(
*/
struct ava a;
a.ava_type= mrf->mrf_type;
- a.ava_value.bv_len= mrf->mrf_value.bv_len;
+ a.ava_value.bv_len= mrf->mrf_value.bv_len;
a.ava_value.bv_val = mrf->mrf_value.bv_val;
+ a.ava_private = NULL;
rc= test_ava_filter( callers_pb, e, e->e_attrs, &a, LDAP_FILTER_EQUALITY, 0 /* Don't Verify Access */ , 0 /* don't just verify access */, access_check_done );
if(rc!=LDAP_SUCCESS && mrf->mrf_dnAttrs)
{
@@ -646,7 +648,7 @@ test_filter_list(
return( nomatch );
}
-void
+char *
filter_strcpy_special_ext( char *d, char *s, int flags )
{
for ( ; *s; s++ ) {
@@ -677,12 +679,13 @@ filter_strcpy_special_ext( char *d, char *s, int flags )
*d++ = *s;
}
*d = '\0';
+ return d;
}
-void
+char *
filter_strcpy_special( char *d, char *s )
{
- filter_strcpy_special_ext(d, s, 0);
+ return filter_strcpy_special_ext(d, s, 0);
}
int test_substring_filter(
diff --git a/ldap/servers/slapd/pblock.c b/ldap/servers/slapd/pblock.c
index 3dbd828..86e0451 100644
--- a/ldap/servers/slapd/pblock.c
+++ b/ldap/servers/slapd/pblock.c
@@ -1244,6 +1244,12 @@ slapi_pblock_get( Slapi_PBlock *pblock, int arg, void *value )
}
(*(IFP *)value) = pblock->pb_plugin->plg_syntax_validate;
break;
+ case SLAPI_PLUGIN_SYNTAX_NORMALIZE:
+ if ( pblock->pb_plugin->plg_type != SLAPI_PLUGIN_SYNTAX ) {
+ return( -1 );
+ }
+ (*(VFPV *)value) = pblock->pb_plugin->plg_syntax_normalize;
+ break;
/* controls we know about */
case SLAPI_MANAGEDSAIT:
@@ -1905,6 +1911,14 @@ slapi_pblock_get( Slapi_PBlock *pblock, int arg, void *value )
(*(LDAPControl ***)value) = pblock->pb_search_ctrls;
break;
+ case SLAPI_PLUGIN_SYNTAX_FILTER_NORMALIZED:
+ (*(int *)value) = pblock->pb_syntax_filter_normalized;
+ break;
+
+ case SLAPI_PLUGIN_SYNTAX_FILTER_DATA:
+ (*(void **)value) = pblock->pb_syntax_filter_data;
+ break;
+
default:
LDAPDebug( LDAP_DEBUG_ANY,
"Unknown parameter block argument %d\n", arg, 0, 0 );
@@ -2717,6 +2731,12 @@ slapi_pblock_set( Slapi_PBlock *pblock, int arg, void *value )
}
pblock->pb_plugin->plg_syntax_validate = (IFP) value;
break;
+ case SLAPI_PLUGIN_SYNTAX_NORMALIZE:
+ if ( pblock->pb_plugin->plg_type != SLAPI_PLUGIN_SYNTAX ) {
+ return( -1 );
+ }
+ pblock->pb_plugin->plg_syntax_normalize = (VFPV) value;
+ break;
case SLAPI_ENTRY_PRE_OP:
pblock->pb_pre_op_entry = (Slapi_Entry *) value;
break;
@@ -3399,6 +3419,14 @@ slapi_pblock_set( Slapi_PBlock *pblock, int arg, void *value )
pblock->pb_search_ctrls = (LDAPControl **) value;
break;
+ case SLAPI_PLUGIN_SYNTAX_FILTER_NORMALIZED:
+ pblock->pb_syntax_filter_normalized = *((int *)value);
+ break;
+
+ case SLAPI_PLUGIN_SYNTAX_FILTER_DATA:
+ pblock->pb_syntax_filter_data = (void *)value;
+ break;
+
default:
LDAPDebug( LDAP_DEBUG_ANY,
"Unknown parameter block argument %d\n", arg, 0, 0 );
diff --git a/ldap/servers/slapd/plugin_syntax.c b/ldap/servers/slapd/plugin_syntax.c
index adfda4a..9e98b61 100644
--- a/ldap/servers/slapd/plugin_syntax.c
+++ b/ldap/servers/slapd/plugin_syntax.c
@@ -143,6 +143,13 @@ plugin_call_syntax_filter_ava_sv(
pblock_init( &pipb );
slapi_pblock_set( &pipb, SLAPI_PLUGIN, (void *) a->a_plugin );
+ if (ava->ava_private) {
+ int filter_normalized = 0;
+ int f_flags = 0;
+ f_flags = *(int *)ava->ava_private;
+ filter_normalized = f_flags | SLAPI_FILTER_NORMALIZED_VALUE;
+ slapi_pblock_set( &pipb, SLAPI_PLUGIN_SYNTAX_FILTER_NORMALIZED, &filter_normalized );
+ }
rc = -1; /* does not match by default */
switch ( ftype ) {
@@ -230,6 +237,7 @@ plugin_call_syntax_filter_sub_sv(
Slapi_PBlock pipb;
int rc;
IFP sub_fn = NULL;
+ int filter_normalized = 0;
LDAPDebug( LDAP_DEBUG_FILTER,
"=> plugin_call_syntax_filter_sub_sv\n", 0, 0, 0 );
@@ -242,6 +250,12 @@ plugin_call_syntax_filter_sub_sv(
}
pblock_init( &pipb );
+ if (pb) {
+ slapi_pblock_get( pb, SLAPI_PLUGIN_SYNTAX_FILTER_NORMALIZED, &filter_normalized );
+ slapi_pblock_set( &pipb, SLAPI_PLUGIN_SYNTAX_FILTER_NORMALIZED, &filter_normalized );
+ }
+ slapi_pblock_set( &pipb, SLAPI_PLUGIN_SYNTAX_FILTER_DATA, fsub );
+
/* use the substr matching rule plugin if available, otherwise, use
the syntax plugin */
if (a->a_mr_sub_plugin) {
@@ -913,3 +927,29 @@ slapi_attr_assertion2keys_sub( /* JCM SLOW FUNCTION */
valuearray_free(&svout);
return rc;
}
+
+void
+slapi_attr_value_normalize(
+ Slapi_PBlock *pb,
+ const Slapi_Attr *sattr, /* if sattr is NULL, type must be attr type name */
+ const char *type,
+ char *val,
+ int trim_spaces,
+ char **retval
+)
+{
+ Slapi_Attr myattr;
+ VFPV norm_fn = NULL;
+
+ if (!sattr) {
+ sattr = slapi_attr_init(&myattr, type);
+ }
+ norm_fn = sattr->a_plugin->plg_syntax_normalize;
+ if (norm_fn) {
+ (*norm_fn)(pb, val, trim_spaces, retval);
+ }
+ if (sattr == &myattr) {
+ attr_done(&myattr);
+ }
+ return;
+}
diff --git a/ldap/servers/slapd/proto-slap.h b/ldap/servers/slapd/proto-slap.h
index 9964043..da58f9b 100644
--- a/ldap/servers/slapd/proto-slap.h
+++ b/ldap/servers/slapd/proto-slap.h
@@ -606,9 +606,9 @@ void set_hash_filters(int i);
/*
* filterentry.c
*/
-void filter_strcpy_special( char *d, char *s );
+char *filter_strcpy_special( char *d, char *s );
#define FILTER_STRCPY_ESCAPE_RECHARS 0x01
-void filter_strcpy_special_ext( char *d, char *s, int flags );
+char *filter_strcpy_special_ext( char *d, char *s, int flags );
/*
diff --git a/ldap/servers/slapd/slap.h b/ldap/servers/slapd/slap.h
index acf7bbd..4acf375 100644
--- a/ldap/servers/slapd/slap.h
+++ b/ldap/servers/slapd/slap.h
@@ -214,6 +214,7 @@ typedef struct symbol_t {
typedef void (*VFP)(void *);
typedef void (*VFPP)(void **);
typedef void (*VFP0)(void);
+typedef void (*VFPV)(); /* takes undefined arguments */
#define LDAPI_INTERNAL 1
#include "slapi-private.h"
#include "pw.h"
@@ -1067,6 +1068,7 @@ struct slapdplugin {
char *plg_un_syntax_oid;
IFP plg_un_syntax_compare;
IFP plg_un_syntax_validate;
+ VFPV plg_un_syntax_normalize;
} plg_un_syntax;
#define plg_syntax_filter_ava plg_un.plg_un_syntax.plg_un_syntax_filter_ava
#define plg_syntax_filter_sub plg_un.plg_un_syntax.plg_un_syntax_filter_sub
@@ -1078,6 +1080,7 @@ struct slapdplugin {
#define plg_syntax_oid plg_un.plg_un_syntax.plg_un_syntax_oid
#define plg_syntax_compare plg_un.plg_un_syntax.plg_un_syntax_compare
#define plg_syntax_validate plg_un.plg_un_syntax.plg_un_syntax_validate
+#define plg_syntax_normalize plg_un.plg_un_syntax.plg_un_syntax_normalize
struct plg_un_acl_struct {
IFP plg_un_acl_init;
@@ -1629,6 +1632,8 @@ typedef struct slapi_pblock {
LDAPControl **pb_search_ctrls; /* for search operations, allows plugins to provide
controls to pass for each entry or referral returned */
IFP pb_mr_index_sv_fn; /* values and keys are Slapi_Value ** */
+ int pb_syntax_filter_normalized; /* the syntax filter types/values are already normalized */
+ void *pb_syntax_filter_data; /* extra data to pass to a syntax plugin function */
} slapi_pblock;
/* index if substrlens */
diff --git a/ldap/servers/slapd/slapi-plugin.h b/ldap/servers/slapd/slapi-plugin.h
index a7c3e60..a92cc5b 100644
--- a/ldap/servers/slapd/slapi-plugin.h
+++ b/ldap/servers/slapd/slapi-plugin.h
@@ -4777,6 +4777,15 @@ Slapi_Filter *slapi_filter_dup(Slapi_Filter *f);
int slapi_filter_changetype(Slapi_Filter *f, const char *newtype);
/**
+ * Normalize in-place the given filter. Normalizes the attribute types always.
+ * If norm_values is true, will also normalize the values.
+ *
+ * \param f the filter to normalize
+ * \param norm_values if true, normalize the values in addition to the type names
+ */
+void slapi_filter_normalize(Slapi_Filter *f, PRBool norm_values);
+
+/**
* Check whether a given attribute type is defined in schema or not
*
* \param attribute type name to be checked
@@ -5259,6 +5268,30 @@ int slapi_attr_assertion2keys_ava_sv( const Slapi_Attr *sattr, Slapi_Value *val,
int slapi_attr_assertion2keys_sub_sv( const Slapi_Attr *sattr, char *initial,
char **any, char *final, Slapi_Value ***ivals );
+/**
+ * Normalize the given value using the syntax associated with the
+ * given attribute. It will attempt to normalize the value in place.
+ * If it cannot, it will return the normalized value in retval. If
+ * trim_spaces is true, whitepace characters will be trimmed from the
+ * ends of the string. If sattr is NULL, the type will be used to look
+ * up the attribute syntax. If sattr is not NULL, type is ignored. If
+ * retval is set, the caller is responsible for freeing it.
+ *
+ * \param pb Slapi_PBlock to use
+ * \param sattr attribute to get the syntax from
+ * \param type attribute to get the syntax from if sattr is NULL
+ * \param val value to normalize in place - must be NULL terminated
+ * \param trim_spaces trim whitespace from ends of string
+ * \param retval if value could not be normalized in place, this is the malloc'd memory containg the new value - caller must free
+ */
+void slapi_attr_value_normalize(
+ Slapi_PBlock *pb,
+ const Slapi_Attr *sattr, /* if sattr is NULL, type must be attr type name */
+ const char *type,
+ char *val,
+ int trim_spaces,
+ char **retval
+);
/*
* internal operation and plugin callback routines
@@ -6272,6 +6305,9 @@ typedef struct slapi_plugindesc {
#define SLAPI_SYNTAX_SUBSTRLENS 709
#define SLAPI_MR_SUBSTRLENS SLAPI_SYNTAX_SUBSTRLENS /* alias */
#define SLAPI_PLUGIN_SYNTAX_VALIDATE 710
+#define SLAPI_PLUGIN_SYNTAX_NORMALIZE 711
+#define SLAPI_PLUGIN_SYNTAX_FILTER_NORMALIZED 712
+#define SLAPI_PLUGIN_SYNTAX_FILTER_DATA 713
/* ACL plugin functions and arguments */
#define SLAPI_PLUGIN_ACL_INIT 730
diff --git a/ldap/servers/slapd/slapi-private.h b/ldap/servers/slapd/slapi-private.h
index fda28a2..2ef4288 100644
--- a/ldap/servers/slapd/slapi-private.h
+++ b/ldap/servers/slapd/slapi-private.h
@@ -70,6 +70,8 @@ extern "C" {
#define SLAPI_FILTER_TOMBSTONE 2
#define SLAPI_FILTER_RUV 4
#define SLAPI_ENTRY_LDAPSUBENTRY 2
+#define SLAPI_FILTER_NORMALIZED_TYPE 8
+#define SLAPI_FILTER_NORMALIZED_VALUE 16
/*
Optimized filter path. For example the following code was lifted from int.c (syntaxes plugin):
diff --git a/ldap/servers/slapd/utf8compare.c b/ldap/servers/slapd/utf8compare.c
index 12cdf22..f595ed6 100644
--- a/ldap/servers/slapd/utf8compare.c
+++ b/ldap/servers/slapd/utf8compare.c
@@ -870,7 +870,7 @@ slapi_utf8StrToLower(unsigned char *s)
while ((np = (unsigned char *)ldap_utf8next((char *)p)) <= tail) {
switch(sz = np - p) {
case 1:
- sprintf((char *)lp, "%c", tolower(*p));
+ *lp = tolower(*p);
break;
case 2:
if (*p < UL2S || *p > UL2E) { /* out of range */
@@ -1871,7 +1871,7 @@ slapi_utf8StrToUpper(unsigned char *s)
while ((np = (unsigned char *)ldap_utf8next((char *)p)) <= tail) {
switch(sz = np - p) {
case 1: /* ASCII */
- sprintf((char *)up, "%c", toupper(*p));
+ *up = toupper(*p);
break;
case 2: /* 2 bytes */
if (*p < LU2S || *p > LU2E) { /* out of range */
diff --git a/ldap/servers/slapd/value.c b/ldap/servers/slapd/value.c
index 2817eaf..1edfe79 100644
--- a/ldap/servers/slapd/value.c
+++ b/ldap/servers/slapd/value.c
@@ -159,6 +159,7 @@ slapi_value_dup(const Slapi_Value *v)
{
Slapi_Value *newvalue= value_new(&v->bv,CSN_TYPE_UNKNOWN,NULL);
newvalue->v_csnset= csnset_dup(v->v_csnset);
+ newvalue->v_flags = v->v_flags;
return newvalue;
}
11 years, 11 months