Branch '389-ds-base-1.3.1' - ldap/servers
by Richard Allen Megginson
ldap/servers/slapd/csn.c | 12 +++
ldap/servers/slapd/entrywsi.c | 122 +++++++++++++++++++++----------------
ldap/servers/slapd/slapi-private.h | 2
3 files changed, 83 insertions(+), 53 deletions(-)
New commits:
commit ea333f2764a9f6120e12abc7556373a79646089a
Author: Rich Megginson <rmeggins(a)redhat.com>
Date: Wed Jul 17 17:51:36 2013 -0600
Ticket #47424 - Replication problem with add-delete requests on single-valued attributes
https://fedorahosted.org/389/ticket/47424
Reviewed by: lkrispenz (Thanks!)
Branch: 389-ds-base-1.3.1
Fix Description: Change the single master resolve attr code to handle the
specific case of doing
add: newvalue
delete: oldvalue
Had to add a new API function - csn_compare_ext - to be able to compare CSNs
without the subsequence number.
Platforms tested: RHEL6 x86_64
Flag Day: no
Doc impact: no
(cherry picked from commit 16e6fc20b51d94a22d73036f2809315b118bd5a4)
(cherry picked from commit 90f170c7e697ba6350a9721b4a09b8a746e32431)
diff --git a/ldap/servers/slapd/csn.c b/ldap/servers/slapd/csn.c
index 9fb5b4a..5c31689 100644
--- a/ldap/servers/slapd/csn.c
+++ b/ldap/servers/slapd/csn.c
@@ -298,7 +298,7 @@ csn_as_attr_option_string(CSNType t,const CSN *csn,char *ss)
}
int
-csn_compare(const CSN *csn1, const CSN *csn2)
+csn_compare_ext(const CSN *csn1, const CSN *csn2, unsigned int flags)
{
PRInt32 retVal;
if(csn1!=NULL && csn2!=NULL)
@@ -321,7 +321,7 @@ csn_compare(const CSN *csn1, const CSN *csn2)
retVal = -1;
else if (csn1->rid > csn2->rid)
retVal = 1;
- else
+ else if (!(flags & CSN_COMPARE_SKIP_SUBSEQ))
{
if (csn1->subseqnum < csn2->subseqnum)
retVal = -1;
@@ -330,6 +330,8 @@ csn_compare(const CSN *csn1, const CSN *csn2)
else
retVal = 0;
}
+ else
+ retVal = 0;
}
}
@@ -350,6 +352,12 @@ csn_compare(const CSN *csn1, const CSN *csn2)
return(retVal);
}
+int
+csn_compare(const CSN *csn1, const CSN *csn2)
+{
+ return csn_compare_ext(csn1, csn2, 0);
+}
+
time_t csn_time_difference(const CSN *csn1, const CSN *csn2)
{
return csn_get_time(csn1) - csn_get_time(csn2);
diff --git a/ldap/servers/slapd/entrywsi.c b/ldap/servers/slapd/entrywsi.c
index 158f0eb..c993950 100644
--- a/ldap/servers/slapd/entrywsi.c
+++ b/ldap/servers/slapd/entrywsi.c
@@ -423,8 +423,8 @@ static int
entry_add_present_values_wsi(Slapi_Entry *e, const char *type, struct berval **bervals, const CSN *csn, int urp, long flags)
{
int retVal= LDAP_SUCCESS;
- Slapi_Value **valuestoadd = NULL;
- valuearray_init_bervalarray(bervals,&valuestoadd); /* JCM SLOW FUNCTION */
+ Slapi_Value **valuestoadd = NULL;
+ valuearray_init_bervalarray(bervals,&valuestoadd); /* JCM SLOW FUNCTION */
if(!valuearray_isempty(valuestoadd))
{
Slapi_Attr *a= NULL;
@@ -437,7 +437,7 @@ entry_add_present_values_wsi(Slapi_Entry *e, const char *type, struct berval **b
slapi_attr_init(a, type);
attrlist_add(&e->e_attrs, a);
}
- a_flags_orig = a->a_flags;
+ a_flags_orig = a->a_flags;
a->a_flags |= flags;
/* Check if the type of the to-be-added values has DN syntax or not. */
if (slapi_attr_is_dn_syntax_attr(a)) {
@@ -558,8 +558,8 @@ entry_delete_present_values_wsi(Slapi_Entry *e, const char *type, struct berval
else
{
/* delete some specific values */
- Slapi_Value **valuestodelete= NULL;
- valuearray_init_bervalarray(vals,&valuestodelete); /* JCM SLOW FUNCTION */
+ Slapi_Value **valuestodelete= NULL;
+ valuearray_init_bervalarray(vals,&valuestodelete); /* JCM SLOW FUNCTION */
/* Check if the type of the to-be-deleted values has DN syntax
* or not. */
if (slapi_attr_is_dn_syntax_attr(a)) {
@@ -575,8 +575,7 @@ entry_delete_present_values_wsi(Slapi_Entry *e, const char *type, struct berval
there are present values with a later CSN - otherwise, even though
the value will be updated with a VDCSN which is later than the VUCSN,
the attribute will not be deleted */
- if(slapi_attr_flag_is_set(a,SLAPI_ATTR_FLAG_SINGLE) && valuesupdated &&
- *valuesupdated)
+ if(slapi_attr_flag_is_set(a,SLAPI_ATTR_FLAG_SINGLE) && valueset_isempty(&a->a_present_values))
{
attr_set_deletion_csn(a,csn);
}
@@ -627,8 +626,8 @@ entry_delete_present_values_wsi(Slapi_Entry *e, const char *type, struct berval
if ( retVal==LDAP_OPERATIONS_ERROR )
{
LDAPDebug( LDAP_DEBUG_ANY, "Possible existing duplicate "
- "value for attribute type %s found in "
- "entry %s\n", a->a_type, slapi_entry_get_dn_const(e), 0 );
+ "value for attribute type %s found in "
+ "entry %s\n", a->a_type, slapi_entry_get_dn_const(e), 0 );
}
}
valuearray_free(&valuestodelete);
@@ -693,7 +692,7 @@ entry_delete_present_values_wsi(Slapi_Entry *e, const char *type, struct berval
will add it back to the present list in the non urp case,
or determine if the attribute needs to be added
or not in the urp case
- */
+ */
entry_add_deleted_attribute_wsi(e, a);
}
}
@@ -1146,6 +1145,7 @@ resolve_attribute_state_single_valued(Slapi_Entry *e, Slapi_Attr *a, int attribu
Slapi_Value *new_value= NULL;
const CSN *current_value_vucsn;
const CSN *pending_value_vucsn;
+ const CSN *pending_value_vdcsn;
const CSN *adcsn;
int i;
@@ -1159,27 +1159,47 @@ resolve_attribute_state_single_valued(Slapi_Entry *e, Slapi_Attr *a, int attribu
slapi_attr_next_value(a,i,&new_value);
}
attr_first_deleted_value(a,&pending_value);
-
/* purge_attribute_state_single_valued */
adcsn= attr_get_deletion_csn(a);
current_value_vucsn= value_get_csn(current_value, CSN_TYPE_VALUE_UPDATED);
pending_value_vucsn= value_get_csn(pending_value, CSN_TYPE_VALUE_UPDATED);
- if((pending_value!=NULL && (csn_compare(adcsn, pending_value_vucsn)<0)) ||
- (pending_value==NULL && (csn_compare(adcsn, current_value_vucsn)<0)))
+ pending_value_vdcsn= value_get_csn(pending_value, CSN_TYPE_VALUE_DELETED);
+ if((pending_value!=NULL && (csn_compare(adcsn, pending_value_vucsn)<0)) ||
+ (pending_value==NULL && (csn_compare(adcsn, current_value_vucsn)<0)))
{
attr_set_deletion_csn(a,NULL);
adcsn= NULL;
- }
+ }
- if(new_value==NULL)
+ /* in the case of the following:
+ * add: value2
+ * delete: value1
+ * we will have current_value with VUCSN CSN1
+ * and pending_value with VDCSN CSN2
+ * and new_value == NULL
+ * current_value != pending_value
+ * and
+ * VUCSN == VDCSN (ignoring subseq)
+ * even though value1.VDCSN > value2.VUCSN
+ * value2 should still win because the value is _different_
+ */
+ if (current_value && pending_value && !new_value && !adcsn &&
+ (0 != slapi_value_compare(a, current_value, pending_value)) &&
+ (0 == csn_compare_ext(current_value_vucsn, pending_value_vdcsn, CSN_COMPARE_SKIP_SUBSEQ)))
{
- /* check if the pending value should become the current value */
- if(pending_value!=NULL)
+ /* just remove the deleted value */
+ entry_deleted_value_to_zapped_value(a,pending_value);
+ pending_value = NULL;
+ }
+ else if(new_value==NULL)
+ {
+ /* check if the pending value should become the current value */
+ if(pending_value!=NULL)
{
if(!value_distinguished_at_csn(e,a,current_value,pending_value_vucsn))
{
- /* attribute.current_value = attribute.pending_value; */
- /* attribute.pending_value = NULL; */
+ /* attribute.current_value = attribute.pending_value; */
+ /* attribute.pending_value = NULL; */
entry_present_value_to_zapped_value(a,current_value);
entry_deleted_value_to_present_value(a,pending_value);
current_value= pending_value;
@@ -1188,12 +1208,12 @@ resolve_attribute_state_single_valued(Slapi_Entry *e, Slapi_Attr *a, int attribu
pending_value_vucsn= NULL;
}
}
- /* check if the current value should be deleted */
- if(current_value!=NULL)
+ /* check if the current value should be deleted */
+ if(current_value!=NULL)
{
if(csn_compare(adcsn,current_value_vucsn)>0) /* check if the attribute was deleted after the value was last updated */
{
- if(!value_distinguished_at_csn(e,a,current_value,current_value_vucsn))
+ if(!value_distinguished_at_csn(e,a,current_value,current_value_vucsn))
{
entry_present_value_to_zapped_value(a,current_value);
current_value= NULL;
@@ -1205,17 +1225,17 @@ resolve_attribute_state_single_valued(Slapi_Entry *e, Slapi_Attr *a, int attribu
else /* addition of a new value */
{
const CSN *new_value_vucsn= value_get_csn(new_value,CSN_TYPE_VALUE_UPDATED);
- if(csn_compare(new_value_vucsn,current_value_vucsn)<0)
+ if(csn_compare(new_value_vucsn,current_value_vucsn)<0)
{
- /*
- * if the new value was distinguished at the time the current value was added
- * then the new value should become current
- */
- if(value_distinguished_at_csn(e,a,new_value,current_value_vucsn))
+ /*
+ * if the new value was distinguished at the time the current value was added
+ * then the new value should become current
+ */
+ if(value_distinguished_at_csn(e,a,new_value,current_value_vucsn))
{
- /* attribute.pending_value = attribute.current_value */
- /* attribute.current_value = new_value */
- if(pending_value==NULL)
+ /* attribute.pending_value = attribute.current_value */
+ /* attribute.current_value = new_value */
+ if(pending_value==NULL)
{
entry_present_value_to_deleted_value(a,current_value);
}
@@ -1231,63 +1251,63 @@ resolve_attribute_state_single_valued(Slapi_Entry *e, Slapi_Attr *a, int attribu
}
else
{
- /* new_value= NULL */
+ /* new_value= NULL */
entry_present_value_to_zapped_value(a, new_value);
new_value= NULL;
}
}
- else /* new value is after the current value */
+ else /* new value is after the current value */
{
- if(!value_distinguished_at_csn(e, a, current_value, new_value_vucsn))
+ if(!value_distinguished_at_csn(e, a, current_value, new_value_vucsn))
{
- /* attribute.current_value = new_value */
+ /* attribute.current_value = new_value */
entry_present_value_to_zapped_value(a, current_value);
current_value= new_value;
new_value= NULL;
current_value_vucsn= new_value_vucsn;
}
- else /* value is distinguished - check if we should replace the current pending value */
+ else /* value is distinguished - check if we should replace the current pending value */
{
- if(csn_compare(new_value_vucsn, pending_value_vucsn)>0)
+ if(csn_compare(new_value_vucsn, pending_value_vucsn)>0)
{
- /* attribute.pending_value = new_value */
+ /* attribute.pending_value = new_value */
entry_deleted_value_to_zapped_value(a,pending_value);
entry_present_value_to_deleted_value(a,new_value);
pending_value= new_value;
new_value= NULL;
pending_value_vucsn= new_value_vucsn;
- }
- }
- }
- }
+ }
+ }
+ }
+ }
- /*
- * This call ensures that the attribute does not have a pending_value
+ /*
+ * This call ensures that the attribute does not have a pending_value
* or a deletion_csn that is earlier than the current_value.
*/
/* purge_attribute_state_single_valued */
- if((pending_value!=NULL && (csn_compare(adcsn, pending_value_vucsn)<0)) ||
- (pending_value==NULL && (csn_compare(adcsn, current_value_vucsn)<0)))
+ if((pending_value!=NULL && (csn_compare(adcsn, pending_value_vucsn)<0)) ||
+ (pending_value==NULL && (csn_compare(adcsn, current_value_vucsn)<0)))
{
attr_set_deletion_csn(a,NULL);
adcsn= NULL;
- }
+ }
- /* set attribute state */
- if(current_value==NULL)
+ /* set attribute state */
+ if(current_value==NULL)
{
if(attribute_state==ATTRIBUTE_PRESENT)
{
entry_present_attribute_to_deleted_attribute(e, a);
}
}
- else
+ else
{
if(attribute_state==ATTRIBUTE_DELETED)
{
entry_deleted_attribute_to_present_attribute(e, a);
}
- }
+ }
}
static void
diff --git a/ldap/servers/slapd/slapi-private.h b/ldap/servers/slapd/slapi-private.h
index 0e38e00..b2364ab 100644
--- a/ldap/servers/slapd/slapi-private.h
+++ b/ldap/servers/slapd/slapi-private.h
@@ -196,6 +196,8 @@ PRUint16 csn_get_seqnum(const CSN *csn);
PRUint16 csn_get_subseqnum(const CSN *csn);
char *csn_as_string(const CSN *csn, PRBool replicaIdOrder, char *ss); /* WARNING: ss must be CSN_STRSIZE bytes, or NULL. */
int csn_compare(const CSN *csn1, const CSN *csn2);
+int csn_compare_ext(const CSN *csn1, const CSN *csn2, unsigned int flags);
+#define CSN_COMPARE_SKIP_SUBSEQ 0x1
time_t csn_time_difference(const CSN *csn1, const CSN *csn2);
size_t csn_string_size();
char *csn_as_attr_option_string(CSNType t,const CSN *csn,char *ss);
10 years, 9 months
Branch '389-ds-base-1.3.0' - 2 commits - ldap/servers
by Noriko Hosoi
ldap/servers/plugins/automember/automember.c | 23 +-
ldap/servers/plugins/cos/cos.c | 2
ldap/servers/plugins/dna/dna.c | 18 +
ldap/servers/plugins/linkedattrs/linked_attrs.c | 34 ++-
ldap/servers/plugins/memberof/memberof.c | 16 -
ldap/servers/plugins/mep/mep.c | 41 ++--
ldap/servers/plugins/pam_passthru/pam_ptpreop.c | 12 -
ldap/servers/plugins/referint/referint.c | 52 ++---
ldap/servers/plugins/replication/repl5.h | 4
ldap/servers/plugins/replication/repl5_init.c | 11 -
ldap/servers/plugins/replication/repl5_plugins.c | 192 +++++---------------
ldap/servers/plugins/replication/urp.c | 41 ++--
ldap/servers/plugins/retrocl/retrocl_po.c | 12 -
ldap/servers/plugins/roles/roles_plugin.c | 2
ldap/servers/plugins/statechange/statechange.c | 22 +-
ldap/servers/plugins/usn/usn.c | 65 ++++---
ldap/servers/plugins/views/views.c | 35 +--
ldap/servers/slapd/add.c | 2
ldap/servers/slapd/back-ldbm/ldbm_add.c | 213 +++++++++++------------
ldap/servers/slapd/back-ldbm/ldbm_delete.c | 51 +++--
ldap/servers/slapd/back-ldbm/ldbm_entryrdn.c | 2
ldap/servers/slapd/back-ldbm/ldbm_modrdn.c | 2
ldap/servers/slapd/back-ldbm/ldbm_search.c | 2
ldap/servers/slapd/delete.c | 2
ldap/servers/slapd/dn.c | 67 ++++++-
ldap/servers/slapd/modify.c | 2
ldap/servers/slapd/modrdn.c | 2
ldap/servers/slapd/plugin.c | 20 +-
ldap/servers/slapd/rdn.c | 24 --
ldap/servers/slapd/slapi-plugin.h | 18 +
30 files changed, 507 insertions(+), 482 deletions(-)
New commits:
commit 6b87414c935903ed6d77905a3d8a716a4f3d26db
Author: Noriko Hosoi <nhosoi(a)redhat.com>
Date: Thu Jul 18 11:38:30 2013 -0700
Ticket #47367 - (phase 2) ldapdelete returns non-leaf entry error while trying to remove a leaf entry
Fix description:
1) Make sure add/modify/modrdn/delete plug-in callbacks return
SLAPI_PLUGIN_SUCCESS (==0) on SUCCESS and SLAPI_PLUGIN_FAILURE
(==-1) on FAILURE. And set error code to SLAPI_RESULT_CODE in
pblock, if any.
2) replication: eliminated multimaster_betxnpreop_* which were
used for calling urp. Urp needs to be processed at bepreop
timing.
Reviewed by Rich (Thank you!!)
https://fedorahosted.org/389/ticket/47367
(cherry picked from commit 733059713a5dfb72c844de1e3b9bc153d4ae6ccb)
(cherry picked from commit ad0a2cabe349368e0cc72155994569564ca71290)
diff --git a/ldap/servers/plugins/automember/automember.c b/ldap/servers/plugins/automember/automember.c
index 49f47f7..2ba3314 100644
--- a/ldap/servers/plugins/automember/automember.c
+++ b/ldap/servers/plugins/automember/automember.c
@@ -1686,7 +1686,7 @@ automember_pre_op(Slapi_PBlock * pb, int modop)
LDAPMod **mods;
int free_entry = 0;
char *errstr = NULL;
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
slapi_log_error(SLAPI_LOG_TRACE, AUTOMEMBER_PLUGIN_SUBSYSTEM,
"--> automember_pre_op\n");
@@ -1771,7 +1771,8 @@ automember_pre_op(Slapi_PBlock * pb, int modop)
"automember_pre_op: operation failure [%d]\n", ret);
slapi_send_ldap_result(pb, ret, NULL, errstr, 0, NULL);
slapi_ch_free((void **)&errstr);
- ret = -1;
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ret);
+ ret = SLAPI_PLUGIN_FAILURE;
}
slapi_log_error(SLAPI_LOG_TRACE, AUTOMEMBER_PLUGIN_SUBSYSTEM,
@@ -1822,7 +1823,7 @@ automember_mod_post_op(Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_TRACE, AUTOMEMBER_PLUGIN_SUBSYSTEM,
"<-- automember_mod_post_op\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
static int
@@ -1838,7 +1839,7 @@ automember_add_post_op(Slapi_PBlock *pb)
/* Just bail if we aren't ready to service requests yet. */
if (!g_plugin_started || !automember_oktodo(pb))
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
/* Reload config if a config entry was added. */
if ((sdn = automember_get_sdn(pb))) {
@@ -1854,7 +1855,7 @@ automember_add_post_op(Slapi_PBlock *pb)
/* If replication, just bail. */
if (automember_isrepl(pb)) {
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
/* Get the newly added entry. */
@@ -1868,7 +1869,7 @@ automember_add_post_op(Slapi_PBlock *pb)
tombstone);
slapi_value_free(&tombstone);
if (rc) {
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
/* Check if a config entry applies
@@ -1878,7 +1879,7 @@ automember_add_post_op(Slapi_PBlock *pb)
/* Bail out if the plug-in close function was just called. */
if (!g_plugin_started) {
automember_config_unlock();
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if (!PR_CLIST_IS_EMPTY(g_automember_config)) {
@@ -1907,7 +1908,7 @@ bail:
slapi_log_error(SLAPI_LOG_TRACE, AUTOMEMBER_PLUGIN_SUBSYSTEM,
"<-- automember_add_post_op\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
/*
@@ -1925,7 +1926,7 @@ automember_del_post_op(Slapi_PBlock *pb)
/* Just bail if we aren't ready to service requests yet. */
if (!g_plugin_started || !automember_oktodo(pb)) {
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
/* Reload config if a config entry was deleted. */
@@ -1941,7 +1942,7 @@ automember_del_post_op(Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_TRACE, AUTOMEMBER_PLUGIN_SUBSYSTEM,
"<-- automember_del_post_op\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
typedef struct _task_data
@@ -2193,7 +2194,7 @@ void automember_rebuild_task_thread(void *arg){
/* Does the entry meet scope and filter requirements? */
if (slapi_dn_issuffix(slapi_sdn_get_dn(td->base_dn), config->scope) &&
(slapi_filter_test_simple(entries[i], config->filter) == 0))
- {
+ {
automember_update_membership(config, entries[i], NULL);
}
list = PR_NEXT_LINK(list);
diff --git a/ldap/servers/plugins/cos/cos.c b/ldap/servers/plugins/cos/cos.c
index 0d76d99..55ff850 100644
--- a/ldap/servers/plugins/cos/cos.c
+++ b/ldap/servers/plugins/cos/cos.c
@@ -306,6 +306,6 @@ int cos_post_op( Slapi_PBlock *pb )
cos_cache_change_notify(pb);
LDAPDebug( LDAP_DEBUG_TRACE, "<-- cos_post_op\n",0,0,0);
- return 0; /* always succeed */
+ return SLAPI_PLUGIN_SUCCESS; /* always succeed */
}
diff --git a/ldap/servers/plugins/dna/dna.c b/ldap/servers/plugins/dna/dna.c
index a631208..a3c5468 100644
--- a/ldap/servers/plugins/dna/dna.c
+++ b/ldap/servers/plugins/dna/dna.c
@@ -70,8 +70,8 @@
#define DNA_DN "cn=Distributed Numeric Assignment Plugin,cn=plugins,cn=config" /* temporary */
-#define DNA_SUCCESS 0
-#define DNA_FAILURE -1
+#define DNA_SUCCESS SLAPI_PLUGIN_SUCCESS
+#define DNA_FAILURE SLAPI_PLUGIN_FAILURE
/* Default range request timeout */
/* use the default replication timeout */
@@ -2798,7 +2798,7 @@ dna_create_valcheck_filter(struct configEntry *config_entry, PRUint64 value, cha
static int
_dna_pre_op_add(Slapi_PBlock *pb, Slapi_Entry *e, char **errstr)
{
- int ret = 0;
+ int ret = DNA_SUCCESS;
PRCList *list = NULL;
struct configEntry *config_entry = NULL;
char *dn = NULL;
@@ -2977,7 +2977,7 @@ _dna_pre_op_add(Slapi_PBlock *pb, Slapi_Entry *e, char **errstr)
slapi_ch_free((void **)&types_to_generate);
}
next:
- ret = 0;
+ ret = DNA_SUCCESS;
list = PR_NEXT_LINK(list);
}
}
@@ -2994,7 +2994,7 @@ bail:
static int
_dna_pre_op_modify(Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Mods *smods, char **errstr)
{
- int ret = 0;
+ int ret = DNA_SUCCESS;
PRCList *list = NULL;
struct configEntry *config_entry = NULL;
char *dn = NULL;
@@ -3376,6 +3376,7 @@ bail:
"dna_pre_op: operation failure [%d]\n", ret);
slapi_send_ldap_result(pb, ret, NULL, errstr, 0, NULL);
slapi_ch_free((void **)&errstr);
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ret);
ret = DNA_FAILURE;
}
@@ -3441,7 +3442,7 @@ static int dna_be_txn_pre_op(Slapi_PBlock *pb, int modtype)
char *dn = NULL;
char *type = NULL;
int numvals, e_numvals = 0;
- int i, len, ret = 0;
+ int i, len, ret = DNA_SUCCESS;
slapi_log_error(SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM,
"--> dna_be_txn_pre_op\n");
@@ -3688,13 +3689,14 @@ bail:
"dna_be_txn_pre_op: operation failure [%d]\n", ret);
slapi_send_ldap_result(pb, ret, NULL, errstr, 0, NULL);
slapi_ch_free((void **)&errstr);
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ret);
ret = DNA_FAILURE;
}
slapi_log_error(SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM,
"<-- dna_be_txn_pre_op\n");
- return ret;
+ return ret;
}
static int dna_config_check_post_op(Slapi_PBlock * pb)
@@ -3715,7 +3717,7 @@ static int dna_config_check_post_op(Slapi_PBlock * pb)
slapi_log_error(SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM,
"<-- dna_config_check_post_op\n");
- return 0;
+ return DNA_SUCCESS;
}
diff --git a/ldap/servers/plugins/linkedattrs/linked_attrs.c b/ldap/servers/plugins/linkedattrs/linked_attrs.c
index 7d8370d..30a8653 100644
--- a/ldap/servers/plugins/linkedattrs/linked_attrs.c
+++ b/ldap/servers/plugins/linkedattrs/linked_attrs.c
@@ -1536,7 +1536,7 @@ linked_attrs_pre_op(Slapi_PBlock * pb, int modop)
LDAPMod **mods = NULL;
int free_entry = 0;
char *errstr = NULL;
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
slapi_log_error(SLAPI_LOG_TRACE, LINK_PLUGIN_SUBSYSTEM,
"--> linked_attrs_pre_op\n");
@@ -1603,7 +1603,8 @@ linked_attrs_pre_op(Slapi_PBlock * pb, int modop)
"linked_attrs_pre_op: operation failure [%d]\n", ret);
slapi_send_ldap_result(pb, ret, NULL, errstr, 0, NULL);
slapi_ch_free((void **)&errstr);
- ret = -1;
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ret);
+ ret = SLAPI_PLUGIN_FAILURE;
}
slapi_log_error(SLAPI_LOG_TRACE, LINK_PLUGIN_SUBSYSTEM,
@@ -1640,7 +1641,7 @@ linked_attrs_mod_post_op(Slapi_PBlock *pb)
/* Just bail if we aren't ready to service requests yet. */
if (!g_plugin_started)
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
/* We don't want to process internal modify
* operations that originate from this plugin.
@@ -1649,7 +1650,7 @@ linked_attrs_mod_post_op(Slapi_PBlock *pb)
if (caller_id == linked_attrs_get_plugin_id()) {
/* Just return without processing */
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if (linked_attrs_oktodo(pb) &&
@@ -1675,7 +1676,7 @@ linked_attrs_mod_post_op(Slapi_PBlock *pb)
/* Bail out if the plug-in close function was just called. */
if (!g_plugin_started) {
linked_attrs_unlock();
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
linked_attrs_find_config(dn, type, &config);
@@ -1729,7 +1730,7 @@ linked_attrs_mod_post_op(Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_TRACE, LINK_PLUGIN_SUBSYSTEM,
"<-- linked_attrs_mod_post_op\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
static int
@@ -1743,7 +1744,7 @@ linked_attrs_add_post_op(Slapi_PBlock *pb)
/* Just bail if we aren't ready to service requests yet. */
if (!g_plugin_started || !linked_attrs_oktodo(pb))
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
/* Reload config if a config entry was added. */
if ((dn = linked_attrs_get_dn(pb))) {
@@ -1773,7 +1774,7 @@ linked_attrs_add_post_op(Slapi_PBlock *pb)
/* Bail out if the plug-in close function was just called. */
if (!g_plugin_started) {
linked_attrs_unlock();
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
linked_attrs_find_config(dn, type, &config);
@@ -1808,7 +1809,7 @@ linked_attrs_add_post_op(Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_TRACE, LINK_PLUGIN_SUBSYSTEM,
"<-- linked_attrs_add_post_op\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
static int
@@ -1822,7 +1823,7 @@ linked_attrs_del_post_op(Slapi_PBlock *pb)
/* Just bail if we aren't ready to service requests yet. */
if (!g_plugin_started || !linked_attrs_oktodo(pb))
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
/* Reload config if a config entry was deleted. */
if ((dn = linked_attrs_get_dn(pb))) {
@@ -1852,7 +1853,7 @@ linked_attrs_del_post_op(Slapi_PBlock *pb)
/* Bail out if the plug-in close function was just called. */
if (!g_plugin_started) {
linked_attrs_unlock();
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
linked_attrs_find_config(dn, type, &config);
@@ -1920,7 +1921,7 @@ linked_attrs_del_post_op(Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_TRACE, LINK_PLUGIN_SUBSYSTEM,
"<-- linked_attrs_del_post_op\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
static int
@@ -1932,7 +1933,7 @@ linked_attrs_modrdn_post_op(Slapi_PBlock *pb)
Slapi_Attr *attr = NULL;
char *type = NULL;
struct configEntry *config = NULL;
- int rc = 0;
+ int rc = SLAPI_PLUGIN_SUCCESS;
slapi_log_error(SLAPI_LOG_TRACE, LINK_PLUGIN_SUBSYSTEM,
"--> linked_attrs_modrdn_post_op\n");
@@ -1978,7 +1979,7 @@ linked_attrs_modrdn_post_op(Slapi_PBlock *pb)
/* Bail out if the plug-in close function was just called. */
if (!g_plugin_started) {
linked_attrs_unlock();
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
linked_attrs_find_config(old_dn, type, &config);
@@ -2069,7 +2070,10 @@ linked_attrs_modrdn_post_op(Slapi_PBlock *pb)
done:
slapi_log_error(SLAPI_LOG_TRACE, LINK_PLUGIN_SUBSYSTEM,
"<-- linked_attrs_modrdn_post_op\n");
-
+ if (rc) {
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &rc);
+ rc = SLAPI_PLUGIN_FAILURE;
+ }
return rc;
}
diff --git a/ldap/servers/plugins/memberof/memberof.c b/ldap/servers/plugins/memberof/memberof.c
index 4baad88..991bd78 100644
--- a/ldap/servers/plugins/memberof/memberof.c
+++ b/ldap/servers/plugins/memberof/memberof.c
@@ -380,7 +380,7 @@ int memberof_postop_close(Slapi_PBlock *pb)
*/
int memberof_postop_del(Slapi_PBlock *pb)
{
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
MemberOfConfig configCopy = {0, 0, 0, 0};
Slapi_DN *sdn;
void *caller_id = NULL;
@@ -393,7 +393,7 @@ int memberof_postop_del(Slapi_PBlock *pb)
slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &caller_id);
if (caller_id == memberof_get_plugin_id()) {
/* Just return without processing */
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if(memberof_oktodo(pb) && (sdn = memberof_getsdn(pb)))
@@ -626,7 +626,7 @@ int memberof_call_foreach_dn(Slapi_PBlock *pb, Slapi_DN *sdn,
*/
int memberof_postop_modrdn(Slapi_PBlock *pb)
{
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
void *caller_id = NULL;
slapi_log_error( SLAPI_LOG_TRACE, MEMBEROF_PLUGIN_SUBSYSTEM,
@@ -637,7 +637,7 @@ int memberof_postop_modrdn(Slapi_PBlock *pb)
slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &caller_id);
if (caller_id == memberof_get_plugin_id()) {
/* Just return without processing */
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if(memberof_oktodo(pb))
@@ -801,7 +801,7 @@ int memberof_replace_dn_type_callback(Slapi_Entry *e, void *callback_data)
*/
int memberof_postop_modify(Slapi_PBlock *pb)
{
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
Slapi_DN *sdn = NULL;
Slapi_Mods *smods = 0;
Slapi_Mod *smod = 0;
@@ -817,7 +817,7 @@ int memberof_postop_modify(Slapi_PBlock *pb)
slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &caller_id);
if (caller_id == memberof_get_plugin_id()) {
/* Just return without processing */
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if(memberof_oktodo(pb) && (sdn = memberof_getsdn(pb)))
@@ -945,7 +945,7 @@ int memberof_postop_modify(Slapi_PBlock *pb)
*/
int memberof_postop_add(Slapi_PBlock *pb)
{
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
int interested = 0;
Slapi_DN *sdn = 0;
void *caller_id = NULL;
@@ -958,7 +958,7 @@ int memberof_postop_add(Slapi_PBlock *pb)
slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &caller_id);
if (caller_id == memberof_get_plugin_id()) {
/* Just return without processing */
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if(memberof_oktodo(pb) && (sdn = memberof_getsdn(pb)))
diff --git a/ldap/servers/plugins/mep/mep.c b/ldap/servers/plugins/mep/mep.c
index f8e3c2b..58345e0 100644
--- a/ldap/servers/plugins/mep/mep.c
+++ b/ldap/servers/plugins/mep/mep.c
@@ -1984,7 +1984,7 @@ mep_pre_op(Slapi_PBlock * pb, int modop)
char *errstr = NULL;
struct configEntry *config = NULL;
void *caller_id = NULL;
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
slapi_log_error(SLAPI_LOG_TRACE, MEP_PLUGIN_SUBSYSTEM,
"--> mep_pre_op\n");
@@ -2259,7 +2259,8 @@ mep_pre_op(Slapi_PBlock * pb, int modop)
"mep_pre_op: operation failure [%d]\n", ret);
slapi_send_ldap_result(pb, ret, NULL, errstr, 0, NULL);
slapi_ch_free((void **)&errstr);
- ret = -1;
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ret);
+ ret = SLAPI_PLUGIN_FAILURE;
}
slapi_log_error(SLAPI_LOG_TRACE, MEP_PLUGIN_SUBSYSTEM,
@@ -2313,7 +2314,7 @@ mep_mod_post_op(Slapi_PBlock *pb)
/* Just bail if we aren't ready to service requests yet. */
if (!g_plugin_started)
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
if (mep_oktodo(pb) && (sdn = mep_get_sdn(pb))) {
/* First check if the config or a template is being modified. */
@@ -2430,7 +2431,7 @@ mep_mod_post_op(Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_TRACE, MEP_PLUGIN_SUBSYSTEM,
"<-- mep_mod_post_op\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
static int
@@ -2445,7 +2446,7 @@ mep_add_post_op(Slapi_PBlock *pb)
/* Just bail if we aren't ready to service requests yet. */
if (!g_plugin_started || !mep_oktodo(pb))
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
/* Reload config if a config entry was added. */
if ((sdn = mep_get_sdn(pb))) {
@@ -2460,7 +2461,7 @@ mep_add_post_op(Slapi_PBlock *pb)
/* If replication, just bail. */
if (mep_isrepl(pb)) {
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
/* Get the newly added entry. */
@@ -2469,7 +2470,7 @@ mep_add_post_op(Slapi_PBlock *pb)
if (e) {
/* If the entry is a tombstone, just bail. */
if (mep_has_tombstone_value(e)) {
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
/* Check if a config entry applies
@@ -2479,7 +2480,7 @@ mep_add_post_op(Slapi_PBlock *pb)
/* Bail out if the plug-in close function was just called. */
if (!g_plugin_started) {
mep_config_unlock();
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
mep_find_config(e, &config);
@@ -2497,7 +2498,7 @@ mep_add_post_op(Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_TRACE, MEP_PLUGIN_SUBSYSTEM,
"<-- mep_add_post_op\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
static int
@@ -2511,7 +2512,7 @@ mep_del_post_op(Slapi_PBlock *pb)
/* Just bail if we aren't ready to service requests yet. */
if (!g_plugin_started || !mep_oktodo(pb)) {
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
/* Reload config if a config entry was deleted. */
@@ -2526,7 +2527,7 @@ mep_del_post_op(Slapi_PBlock *pb)
/* If replication, just bail. */
if (mep_isrepl(pb)) {
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
/* Get deleted entry, then go through types to find config. */
@@ -2537,7 +2538,7 @@ mep_del_post_op(Slapi_PBlock *pb)
/* If the entry is a tombstone, just bail. */
if (mep_has_tombstone_value(e)) {
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
/* See if we're an origin entry . */
@@ -2566,7 +2567,7 @@ mep_del_post_op(Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_TRACE, MEP_PLUGIN_SUBSYSTEM,
"<-- mep_del_post_op\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
static int
@@ -2584,7 +2585,7 @@ mep_modrdn_post_op(Slapi_PBlock *pb)
/* Just bail if we aren't ready to service requests yet. */
if (!g_plugin_started || !mep_oktodo(pb))
- return 0;;
+ return SLAPI_PLUGIN_SUCCESS;;
/* Reload config if an existing config entry was renamed,
* or if the new dn brings an entry into the scope of the
@@ -2597,7 +2598,7 @@ mep_modrdn_post_op(Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_PLUGIN, MEP_PLUGIN_SUBSYSTEM,
"mep_modrdn_post_op: Error "
"retrieving post-op entry\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if ((old_sdn = mep_get_sdn(pb))) {
@@ -2611,12 +2612,12 @@ mep_modrdn_post_op(Slapi_PBlock *pb)
/* If replication, just bail. */
if (mep_isrepl(pb)) {
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
/* If the entry is a tombstone, just bail. */
if (mep_has_tombstone_value(post_e)) {
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
/* See if we're an origin entry . */
@@ -2638,7 +2639,7 @@ mep_modrdn_post_op(Slapi_PBlock *pb)
if (!g_plugin_started) {
mep_config_unlock();
slapi_pblock_destroy(mep_pb);
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
mep_find_config(post_e, &config);
@@ -2809,7 +2810,7 @@ bailmod:
/* Bail out if the plug-in close function was just called. */
if (!g_plugin_started) {
mep_config_unlock();
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
mep_find_config(post_e, &config);
@@ -2823,7 +2824,7 @@ bailmod:
slapi_log_error(SLAPI_LOG_TRACE, MEP_PLUGIN_SUBSYSTEM,
"<-- mep_modrdn_post_op\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
static int
diff --git a/ldap/servers/plugins/pam_passthru/pam_ptpreop.c b/ldap/servers/plugins/pam_passthru/pam_ptpreop.c
index 7d9ff8b..abf93e3 100644
--- a/ldap/servers/plugins/pam_passthru/pam_ptpreop.c
+++ b/ldap/servers/plugins/pam_passthru/pam_ptpreop.c
@@ -229,7 +229,7 @@ pam_passthruauth_init( Slapi_PBlock *pb )
slapi_log_error( SLAPI_LOG_TRACE, PAM_PASSTHRU_PLUGIN_SUBSYSTEM,
"<= pam_passthruauth_init\n" );
- bail:
+bail:
return status;
}
@@ -574,7 +574,7 @@ pam_passthru_preop(Slapi_PBlock *pb, int modtype)
Slapi_Entry *e = NULL;
LDAPMod **mods;
char returntext[SLAPI_DSE_RETURNTEXT_SIZE];
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
slapi_log_error(SLAPI_LOG_TRACE, PAM_PASSTHRU_PLUGIN_SUBSYSTEM,
"=> pam_passthru_preop\n");
@@ -640,11 +640,11 @@ pam_passthru_preop(Slapi_PBlock *pb, int modtype)
}
- bail:
+bail:
/* If we are refusing the operation, return the result to the client. */
if (ret) {
slapi_send_ldap_result(pb, ret, NULL, returntext, 0, NULL);
- ret = -1;
+ ret = SLAPI_PLUGIN_FAILURE;
}
slapi_log_error(SLAPI_LOG_TRACE, PAM_PASSTHRU_PLUGIN_SUBSYSTEM,
@@ -683,7 +683,7 @@ pam_passthru_modrdn_preop(Slapi_PBlock *pb)
static int
pam_passthru_postop(Slapi_PBlock *pb)
{
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
Slapi_DN *sdn = NULL;
Slapi_DN *new_sdn = NULL;
Slapi_Entry *e = NULL;
@@ -737,7 +737,7 @@ pam_passthru_postop(Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_TRACE, PAM_PASSTHRU_PLUGIN_SUBSYSTEM,
"<= pam_passthru_postop\n");
- bail:
+bail:
return ret;
}
diff --git a/ldap/servers/plugins/referint/referint.c b/ldap/servers/plugins/referint/referint.c
index 234c322..d31f53c 100644
--- a/ldap/servers/plugins/referint/referint.c
+++ b/ldap/servers/plugins/referint/referint.c
@@ -194,7 +194,7 @@ referint_postop_del( Slapi_PBlock *pb )
if (0 == refint_started) {
/* not initialized yet */
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if ( slapi_pblock_get( pb, SLAPI_IS_REPLICATED_OPERATION, &isrepop ) != 0 ||
@@ -203,33 +203,33 @@ referint_postop_del( Slapi_PBlock *pb )
{
slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
"referint_postop_del: could not get parameters\n" );
- return( -1 );
+ return SLAPI_PLUGIN_FAILURE;
}
/*
* This plugin should only execute if the delete was successful
* and this is not a replicated op(unless its allowed)
*/
if(oprc != 0 || (isrepop && !allow_repl)){
- return( 0 );
+ return SLAPI_PLUGIN_SUCCESS;
}
/* get the args */
if ( slapi_pblock_get( pb, SLAPI_PLUGIN_ARGC, &argc ) != 0) {
slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
"referint_postop failed to get argc\n" );
- return( -1 );
+ return SLAPI_PLUGIN_FAILURE;
}
if ( slapi_pblock_get( pb, SLAPI_PLUGIN_ARGV, &argv ) != 0) {
slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
"referint_postop failed to get argv\n" );
- return( -1 );
+ return SLAPI_PLUGIN_FAILURE;
}
-
+
if(argv == NULL){
slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
"referint_postop_del, args are NULL\n" );
- return( -1 );
+ return SLAPI_PLUGIN_FAILURE;
}
-
+
if (argc >= 3) {
/* argv[0] will be the delay */
delay = atoi(argv[0]);
@@ -239,19 +239,19 @@ referint_postop_del( Slapi_PBlock *pb )
if(delay == -1){
/* integrity updating is off */
- rc = 0;
+ rc = SLAPI_PLUGIN_SUCCESS;
} else if(delay == 0){ /* no delay */
/* call function to update references to entry */
rc = update_integrity(argv, sdn, NULL, NULL, logChanges);
} else {
/* write the entry to integrity log */
writeintegritylog(pb, argv[1], sdn, NULL, NULL, NULL /* slapi_get_requestor_sdn(pb) */);
- rc = 0;
+ rc = SLAPI_PLUGIN_SUCCESS;
}
} else {
slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
"referint_postop insufficient arguments supplied\n" );
- return( -1 );
+ return SLAPI_PLUGIN_FAILURE;
}
return( rc );
@@ -279,30 +279,30 @@ referint_postop_modrdn( Slapi_PBlock *pb )
{
slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
"referint_postop_modrdn: could not get parameters\n" );
- return( -1 );
+ return SLAPI_PLUGIN_FAILURE;
}
/*
* This plugin should only execute if the delete was successful
* and this is not a replicated op (unless its allowed)
*/
if(oprc != 0 || (isrepop && !allow_repl)){
- return( 0 );
+ return SLAPI_PLUGIN_SUCCESS;
}
/* get the args */
if ( slapi_pblock_get( pb, SLAPI_PLUGIN_ARGC, &argc ) != 0) {
slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
"referint_postop failed to get argv\n" );
- return( -1 );
+ return SLAPI_PLUGIN_FAILURE;
}
if ( slapi_pblock_get( pb, SLAPI_PLUGIN_ARGV, &argv ) != 0) {
slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
"referint_postop failed to get argv\n" );
- return( -1 );
+ return SLAPI_PLUGIN_FAILURE;
}
if(argv == NULL){
slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
"referint_postop_modrdn, args are NULL\n" );
- return( -1 );
+ return SLAPI_PLUGIN_FAILURE;
}
if (argc >= 3) {
@@ -314,19 +314,19 @@ referint_postop_modrdn( Slapi_PBlock *pb )
} else {
slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
"referint_postop_modrdn insufficient arguments supplied\n" );
- return( -1 );
+ return SLAPI_PLUGIN_FAILURE;
}
if(delay == -1){
/* integrity updating is off */
- rc = 0;
+ rc = SLAPI_PLUGIN_SUCCESS;
} else if(delay == 0){ /* no delay */
/* call function to update references to entry */
rc = update_integrity(argv, sdn, newrdn, newsuperior, logChanges);
} else {
/* write the entry to integrity log */
writeintegritylog(pb, argv[1], sdn, newrdn, newsuperior, NULL /* slapi_get_requestor_sdn(pb) */);
- rc = 0;
+ rc = SLAPI_PLUGIN_SUCCESS;
}
return( rc );
@@ -720,12 +720,12 @@ update_integrity(char **argv, Slapi_DN *origSDN,
int search_result;
int nval = 0;
int i, j;
- int rc;
+ int rc = SLAPI_PLUGIN_SUCCESS;
if ( argv == NULL ){
slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
"referint_postop required config file arguments missing\n" );
- rc = -1;
+ rc = SLAPI_PLUGIN_FAILURE;
goto free_and_return;
}
/*
@@ -818,7 +818,7 @@ update_integrity(char **argv, Slapi_DN *origSDN,
slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
"update_integrity search (base=%s filter=%s) returned "
"error %d\n", search_base, filter, search_result);
- rc = -1;
+ rc = SLAPI_PLUGIN_FAILURE;
goto free_and_return;
}
}
@@ -828,7 +828,7 @@ update_integrity(char **argv, Slapi_DN *origSDN,
}
}
/* if got here, then everything good rc = 0 */
- rc = 0;
+ rc = SLAPI_PLUGIN_SUCCESS;
free_and_return:
/* free filter and search_results_pb */
@@ -878,7 +878,7 @@ int referint_postop_start( Slapi_PBlock *pb)
keeprunning_mutex = PR_NewLock();
keeprunning_cv = PR_NewCondVar(keeprunning_mutex);
keeprunning =1;
-
+
referint_tid = PR_CreateThread (PR_USER_THREAD,
referint_thread_func,
(void *)argv,
@@ -1075,7 +1075,7 @@ int my_fgetc(PRFileDesc *stream)
}
return retval;
-}
+}
int
GetNextLine(char *dest, int size_dest, PRFileDesc *stream) {
@@ -1083,7 +1083,7 @@ GetNextLine(char *dest, int size_dest, PRFileDesc *stream) {
char nextchar ='\0';
int done = 0;
int i = 0;
-
+
while(!done){
if( ( nextchar = my_fgetc(stream) ) != 0){
if( i < (size_dest - 1) ){
diff --git a/ldap/servers/plugins/replication/repl5.h b/ldap/servers/plugins/replication/repl5.h
index b15f268..5d2a421 100644
--- a/ldap/servers/plugins/replication/repl5.h
+++ b/ldap/servers/plugins/replication/repl5.h
@@ -210,10 +210,6 @@ int multimaster_bepreop_add (Slapi_PBlock *pb);
int multimaster_bepreop_delete (Slapi_PBlock *pb);
int multimaster_bepreop_modify (Slapi_PBlock *pb);
int multimaster_bepreop_modrdn (Slapi_PBlock *pb);
-int multimaster_betxnpreop_add (Slapi_PBlock *pb);
-int multimaster_betxnpreop_delete (Slapi_PBlock *pb);
-int multimaster_betxnpreop_modify (Slapi_PBlock *pb);
-int multimaster_betxnpreop_modrdn (Slapi_PBlock *pb);
int replica_ruv_smods_for_op (Slapi_PBlock *pb, char **uniqueid,
Slapi_Mods **smods);
int multimaster_bepostop_modrdn (Slapi_PBlock *pb);
diff --git a/ldap/servers/plugins/replication/repl5_plugins.c b/ldap/servers/plugins/replication/repl5_plugins.c
index 590af7e..7bd24d7 100644
--- a/ldap/servers/plugins/replication/repl5_plugins.c
+++ b/ldap/servers/plugins/replication/repl5_plugins.c
@@ -190,13 +190,13 @@ multimaster_preop_add (Slapi_PBlock *pb)
copy_operation_parameters(pb);
slapi_operation_set_csngen_handler(op,
(void*)replica_generate_next_csn);
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if (!is_mmr_replica (pb))
{
copy_operation_parameters(pb);
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
is_replicated_operation= operation_is_flag_set(op,OP_FLAG_REPLICATED);
@@ -241,7 +241,7 @@ multimaster_preop_add (Slapi_PBlock *pb)
slapi_ch_free ((void**)&target_uuid);
slapi_ch_free ((void**)&superior_uuid);
- return -1;
+ return SLAPI_PLUGIN_FAILURE;
}
operation_set_csn(op, csn);
@@ -296,7 +296,7 @@ multimaster_preop_add (Slapi_PBlock *pb)
copy_operation_parameters(pb);
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
int
@@ -320,13 +320,13 @@ multimaster_preop_delete (Slapi_PBlock *pb)
slapi_operation_set_replica_attr_handler ( op, (void*)replica_get_attr );
slapi_operation_set_csngen_handler(op,
(void*)replica_generate_next_csn);
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if (!is_mmr_replica (pb))
{
copy_operation_parameters(pb);
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
is_replicated_operation= operation_is_flag_set(op,OP_FLAG_REPLICATED);
@@ -366,7 +366,7 @@ multimaster_preop_delete (Slapi_PBlock *pb)
csn_free (&csn);
slapi_ch_free ((void**)&target_uuid);
- return -1;
+ return SLAPI_PLUGIN_FAILURE;
}
/*
@@ -396,7 +396,7 @@ multimaster_preop_delete (Slapi_PBlock *pb)
copy_operation_parameters(pb);
slapi_operation_set_replica_attr_handler ( op, (void*)replica_get_attr );
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
int
@@ -419,13 +419,13 @@ multimaster_preop_modify (Slapi_PBlock *pb)
copy_operation_parameters(pb);
slapi_operation_set_csngen_handler(op,
(void*)replica_generate_next_csn);
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if (!is_mmr_replica (pb))
{
copy_operation_parameters(pb);
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
is_replicated_operation= operation_is_flag_set(op,OP_FLAG_REPLICATED);
@@ -465,7 +465,7 @@ multimaster_preop_modify (Slapi_PBlock *pb)
csn_free (&csn);
slapi_ch_free ((void**)&target_uuid);
- return -1;
+ return SLAPI_PLUGIN_FAILURE;
}
/*
@@ -498,7 +498,7 @@ multimaster_preop_modify (Slapi_PBlock *pb)
}
copy_operation_parameters(pb);
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
int
@@ -521,13 +521,13 @@ multimaster_preop_modrdn (Slapi_PBlock *pb)
copy_operation_parameters(pb);
slapi_operation_set_csngen_handler(op,
(void*)replica_generate_next_csn);
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if (!is_mmr_replica (pb))
{
copy_operation_parameters(pb);
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
is_replicated_operation= operation_is_flag_set(op,OP_FLAG_REPLICATED);
@@ -577,7 +577,7 @@ multimaster_preop_modrdn (Slapi_PBlock *pb)
slapi_ch_free ((void**)&newsuperior_uuid);
ldap_mods_free (modrdn_mods, 1);
- return -1;
+ return SLAPI_PLUGIN_FAILURE;
}
operation_set_csn(op, csn);
@@ -625,19 +625,19 @@ multimaster_preop_modrdn (Slapi_PBlock *pb)
copy_operation_parameters(pb);
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
int
multimaster_preop_search (Slapi_PBlock *pb)
{
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
int
multimaster_preop_compare (Slapi_PBlock *pb)
{
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
static void
@@ -704,7 +704,7 @@ purge_entry_state_information (Slapi_PBlock *pb)
int
multimaster_bepreop_add (Slapi_PBlock *pb)
{
- int rc= 0;
+ int rc= SLAPI_PLUGIN_SUCCESS;
Slapi_Operation *op;
int is_replicated_operation;
int is_fixup_operation;
@@ -729,7 +729,7 @@ multimaster_bepreop_add (Slapi_PBlock *pb)
int
multimaster_bepreop_delete (Slapi_PBlock *pb)
{
- int rc= 0;
+ int rc= SLAPI_PLUGIN_SUCCESS;
Slapi_Operation *op;
int is_replicated_operation;
int is_fixup_operation;
@@ -754,7 +754,7 @@ multimaster_bepreop_delete (Slapi_PBlock *pb)
int
multimaster_bepreop_modify (Slapi_PBlock *pb)
{
- int rc= 0;
+ int rc= SLAPI_PLUGIN_SUCCESS;
Slapi_Operation *op;
int is_replicated_operation;
int is_fixup_operation;
@@ -782,7 +782,7 @@ multimaster_bepreop_modify (Slapi_PBlock *pb)
int
multimaster_bepreop_modrdn (Slapi_PBlock *pb)
{
- int rc= 0;
+ int rc= SLAPI_PLUGIN_SUCCESS;
Slapi_Operation *op;
int is_replicated_operation;
int is_fixup_operation;
@@ -807,99 +807,6 @@ multimaster_bepreop_modrdn (Slapi_PBlock *pb)
return rc;
}
-/* betxn preop's */
-int
-multimaster_betxnpreop_add (Slapi_PBlock *pb)
-{
- int rc= 0;
- Slapi_Operation *op;
- int is_replicated_operation;
- int is_fixup_operation;
-
- slapi_pblock_get(pb, SLAPI_OPERATION, &op);
- is_replicated_operation= operation_is_flag_set(op,OP_FLAG_REPLICATED);
- is_fixup_operation= operation_is_flag_set(op,OP_FLAG_REPL_FIXUP);
-
- /* For replicated operations, apply URP algorithm */
- if (!is_fixup_operation)
- {
- if (is_replicated_operation) {
- rc = urp_add_operation(pb);
- }
- }
-
- return rc;
-}
-
-int
-multimaster_betxnpreop_delete (Slapi_PBlock *pb)
-{
- int rc= 0;
- Slapi_Operation *op;
- int is_replicated_operation;
- int is_fixup_operation;
-
- slapi_pblock_get(pb, SLAPI_OPERATION, &op);
- is_replicated_operation= operation_is_flag_set(op,OP_FLAG_REPLICATED);
- is_fixup_operation= operation_is_flag_set(op,OP_FLAG_REPL_FIXUP);
-
- /* For replicated operations, apply URP algorithm */
- if(!is_fixup_operation)
- {
- if (is_replicated_operation) {
- rc = urp_delete_operation(pb);
- }
- }
-
- return rc;
-}
-
-int
-multimaster_betxnpreop_modify (Slapi_PBlock *pb)
-{
- int rc= 0;
- Slapi_Operation *op;
- int is_replicated_operation;
- int is_fixup_operation;
-
- slapi_pblock_get(pb, SLAPI_OPERATION, &op);
- is_replicated_operation= operation_is_flag_set(op,OP_FLAG_REPLICATED);
- is_fixup_operation= operation_is_flag_set(op,OP_FLAG_REPL_FIXUP);
-
- /* For replicated operations, apply URP algorithm */
- if(!is_fixup_operation)
- {
- if (is_replicated_operation) {
- rc = urp_modify_operation(pb);
- }
- }
-
- return rc;
-}
-
-int
-multimaster_betxnpreop_modrdn (Slapi_PBlock *pb)
-{
- int rc= 0;
- Slapi_Operation *op;
- int is_replicated_operation;
- int is_fixup_operation;
-
- slapi_pblock_get(pb, SLAPI_OPERATION, &op);
- is_replicated_operation= operation_is_flag_set(op,OP_FLAG_REPLICATED);
- is_fixup_operation= operation_is_flag_set(op,OP_FLAG_REPL_FIXUP);
-
- /* For replicated operations, apply URP algorithm */
- if(!is_fixup_operation)
- {
- if (is_replicated_operation) {
- rc = urp_modrdn_operation(pb);
- }
- }
-
- return rc;
-}
-
int
multimaster_bepostop_modrdn (Slapi_PBlock *pb)
{
@@ -910,7 +817,7 @@ multimaster_bepostop_modrdn (Slapi_PBlock *pb)
{
urp_post_modrdn_operation (pb);
}
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
int
@@ -923,14 +830,14 @@ multimaster_bepostop_delete (Slapi_PBlock *pb)
{
urp_post_delete_operation (pb);
}
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
/* postop - write to changelog */
int
multimaster_postop_bind (Slapi_PBlock *pb)
{
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
int
@@ -985,7 +892,7 @@ multimaster_betxnpostop_modify (Slapi_PBlock *pb)
int
multimaster_be_betxnpostop_delete (Slapi_PBlock *pb)
{
- int rc = 0;
+ int rc = SLAPI_PLUGIN_SUCCESS;
/* original betxnpost */
rc = write_changelog_and_ruv(pb);
/* original bepost */
@@ -1119,7 +1026,7 @@ write_changelog_and_ruv (Slapi_PBlock *pb)
int rc;
slapi_operation_parameters *op_params = NULL;
Object *repl_obj;
- int return_value = 0;
+ int return_value = SLAPI_PLUGIN_SUCCESS;
Replica *r;
Slapi_Backend *be;
int is_replicated_operation = 0;
@@ -1129,7 +1036,7 @@ write_changelog_and_ruv (Slapi_PBlock *pb)
if ((operation_is_flag_set(op, OP_FLAG_REPL_FIXUP)) ||
(operation_is_flag_set(op, OP_FLAG_TOMBSTONE_ENTRY)))
{
- return 0;
+ return return_value;
}
/* ignore operations intended for chaining backends - they will be
@@ -1141,18 +1048,18 @@ write_changelog_and_ruv (Slapi_PBlock *pb)
if (!is_replicated_operation &&
slapi_be_is_flag_set(be,SLAPI_BE_FLAG_REMOTE_DATA))
{
- return 0;
+ return return_value;
}
slapi_pblock_get(pb, SLAPI_RESULT_CODE, &rc);
if (rc) { /* op failed - just return */
- return 0;
+ return return_value;
}
/* we only log changes for operations applied to a replica */
repl_obj = replica_get_replica_for_op (pb);
if (repl_obj == NULL)
- return 0;
+ return return_value;
r = (Replica*)object_get_data (repl_obj);
PR_ASSERT (r);
@@ -1214,7 +1121,7 @@ write_changelog_and_ruv (Slapi_PBlock *pb)
if( op_params->csn && is_cleaned_rid(csn_get_replicaid(op_params->csn))){
/* this RID has been cleaned */
object_release (repl_obj);
- return 0;
+ return return_value;
}
/* we might have stripped all the mods - in that case we do not
@@ -1227,7 +1134,7 @@ write_changelog_and_ruv (Slapi_PBlock *pb)
{
slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
"write_changelog_and_ruv: Skipped due to DISKFULL\n");
- return 0;
+ return return_value;
}
slapi_pblock_get(pb, SLAPI_TXN, &txn);
rc = cl5WriteOperationTxn(repl_name, repl_gen, op_params,
@@ -1243,7 +1150,7 @@ write_changelog_and_ruv (Slapi_PBlock *pb)
op_params->target_address.uniqueid,
op_params->operation_type,
csn_as_string(op_params->csn, PR_FALSE, csn_str));
- return_value = 1;
+ return_value = SLAPI_PLUGIN_FAILURE;
}
}
@@ -1313,7 +1220,7 @@ process_postop (Slapi_PBlock *pb)
if ((operation_is_flag_set(op, OP_FLAG_REPL_FIXUP)) ||
(operation_is_flag_set(op, OP_FLAG_TOMBSTONE_ENTRY)))
{
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
/* ignore operations intended for chaining backends - they will be
@@ -1325,24 +1232,27 @@ process_postop (Slapi_PBlock *pb)
if (!is_replicated_operation &&
slapi_be_is_flag_set(be,SLAPI_BE_FLAG_REMOTE_DATA))
{
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
get_repl_session_id (pb, sessionid, &opcsn);
- slapi_pblock_get(pb, SLAPI_RESULT_CODE, &rc);
+ slapi_pblock_get(pb, SLAPI_RESULT_CODE, &rc);
if (rc == LDAP_SUCCESS)
{
- agmtlist_notify_all(pb);
+ agmtlist_notify_all(pb);
+ rc = SLAPI_PLUGIN_SUCCESS;
}
- else if (opcsn)
+ else if (opcsn)
{
- rc = cancel_opcsn (pb);
+ rc = cancel_opcsn (pb);
/* Don't try to get session id since conn is always null */
slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name,
"%s process postop: canceling operation csn\n", sessionid);
- }
+ } else {
+ rc = SLAPI_PLUGIN_FAILURE;
+ }
/* the target unique id is set in the modify_preop above, so
we need to free it */
@@ -1436,7 +1346,7 @@ cancel_opcsn (Slapi_PBlock *pb)
object_release (repl_obj);
}
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
diff --git a/ldap/servers/plugins/retrocl/retrocl_po.c b/ldap/servers/plugins/retrocl/retrocl_po.c
index c3d1c41..382c98a 100644
--- a/ldap/servers/plugins/retrocl/retrocl_po.c
+++ b/ldap/servers/plugins/retrocl/retrocl_po.c
@@ -581,24 +581,24 @@ int retrocl_postob (Slapi_PBlock *pb,int optype)
if (slapi_be_logchanges(be) == 0) {
LDAPDebug0Args(LDAP_DEBUG_TRACE,"not applying change if not logging\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if (retrocl_be_changelog == NULL || be == retrocl_be_changelog) {
LDAPDebug0Args(LDAP_DEBUG_TRACE,"not applying change if no/cl be\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
slapi_pblock_get(pb, SLAPI_RESULT_CODE, &rc);
if (rc != LDAP_SUCCESS) {
LDAPDebug1Arg(LDAP_DEBUG_TRACE,"not applying change if op failed %d\n",rc);
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if (slapi_op_abandoned(pb)) {
LDAPDebug0Args(LDAP_DEBUG_PLUGIN,"not applying change if op abandoned\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
curtime = current_time();
@@ -613,12 +613,12 @@ int retrocl_postob (Slapi_PBlock *pb,int optype)
if (op == NULL) {
LDAPDebug0Args(LDAP_DEBUG_TRACE,"not applying change if no op\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if (operation_is_flag_set(op, OP_FLAG_TOMBSTONE_ENTRY)){
LDAPDebug0Args(LDAP_DEBUG_TRACE,"not applying change for nsTombstone entries\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
switch ( optype ) {
diff --git a/ldap/servers/plugins/roles/roles_plugin.c b/ldap/servers/plugins/roles/roles_plugin.c
index 9db76ca..b00e9a7 100644
--- a/ldap/servers/plugins/roles/roles_plugin.c
+++ b/ldap/servers/plugins/roles/roles_plugin.c
@@ -355,7 +355,7 @@ static int roles_post_op( Slapi_PBlock *pb )
roles_cache_change_notify(pb);
slapi_log_error( SLAPI_LOG_PLUGIN, ROLES_PLUGIN_SUBSYSTEM, "<-- roles_post_op\n");
- return 0; /* always succeed */
+ return SLAPI_PLUGIN_SUCCESS; /* always succeed */
}
static void roles_set_plugin_identity(void * identity)
diff --git a/ldap/servers/plugins/statechange/statechange.c b/ldap/servers/plugins/statechange/statechange.c
index 0b2b737..307ea75 100644
--- a/ldap/servers/plugins/statechange/statechange.c
+++ b/ldap/servers/plugins/statechange/statechange.c
@@ -110,7 +110,7 @@ void plugin_init_debug_level(int *level_ptr)
*/
int statechange_init( Slapi_PBlock *pb )
{
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
Slapi_Entry *plugin_entry = NULL;
char *plugin_type = NULL;
int postadd = SLAPI_PLUGIN_POST_ADD_FN;
@@ -148,7 +148,7 @@ int statechange_init( Slapi_PBlock *pb )
{
slapi_log_error( SLAPI_LOG_FATAL, SCN_PLUGIN_SUBSYSTEM,
"statechange_init: failed to register plugin\n" );
- ret = -1;
+ ret = SLAPI_PLUGIN_FAILURE;
}
slapi_log_error( SLAPI_LOG_TRACE, SCN_PLUGIN_SUBSYSTEM, "<-- statechange_init\n");
@@ -163,7 +163,7 @@ int statechange_init( Slapi_PBlock *pb )
*/
static int statechange_start( Slapi_PBlock *pb )
{
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
slapi_log_error( SLAPI_LOG_TRACE, SCN_PLUGIN_SUBSYSTEM, "--> statechange_start\n");
@@ -177,14 +177,14 @@ static int statechange_start( Slapi_PBlock *pb )
{
/* badness */
slapi_log_error( SLAPI_LOG_FATAL, SCN_PLUGIN_SUBSYSTEM, "statechange: failed to create lock\n");
- ret = -1;
+ ret = SLAPI_PLUGIN_FAILURE;
}
else
{
if( slapi_apib_register(StateChange_v1_0_GUID, api) )
{
slapi_log_error( SLAPI_LOG_FATAL, SCN_PLUGIN_SUBSYSTEM, "statechange: failed to publish state change interface\n");
- ret = -1;
+ ret = SLAPI_PLUGIN_FAILURE;
}
}
@@ -207,7 +207,7 @@ static int statechange_close( Slapi_PBlock *pb )
slapi_log_error( SLAPI_LOG_TRACE, SCN_PLUGIN_SUBSYSTEM, "<-- statechange_close\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
@@ -251,7 +251,7 @@ static int statechange_post_op( Slapi_PBlock *pb, int modtype )
struct slapi_entry *e_after = NULL;
if(head == 0)
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
slapi_log_error( SLAPI_LOG_TRACE, SCN_PLUGIN_SUBSYSTEM, "--> statechange_post_op\n");
@@ -317,13 +317,13 @@ bail:
slapi_unlock_mutex(buffer_lock);
slapi_log_error( SLAPI_LOG_TRACE, SCN_PLUGIN_SUBSYSTEM, "<-- statechange_post_op\n");
- return 0; /* always succeed */
+ return SLAPI_PLUGIN_SUCCESS; /* always succeed */
}
static int _statechange_register(char *caller_id, char *dn, char *filter, void *caller_data, notify_callback func)
{
- int ret = -1;
+ int ret = SLAPI_PLUGIN_FAILURE;
SCNotify *item;
/* simple - we don't check for duplicates */
@@ -352,7 +352,7 @@ static int _statechange_register(char *caller_id, char *dn, char *filter, void *
slapi_ch_free_string(&item->filter);
slapi_ch_free_string(&writable_filter);
slapi_ch_free((void **)&item);
- return -1;
+ return ret;
} else if (!writable_filter) {
item->realfilter = NULL;
}
@@ -375,7 +375,7 @@ static int _statechange_register(char *caller_id, char *dn, char *filter, void *
slapi_unlock_mutex(buffer_lock);
slapi_ch_free_string(&writable_filter);
- ret = 0;
+ ret = SLAPI_PLUGIN_SUCCESS;
}
return ret;
diff --git a/ldap/servers/plugins/usn/usn.c b/ldap/servers/plugins/usn/usn.c
index 4473618..338517f 100644
--- a/ldap/servers/plugins/usn/usn.c
+++ b/ldap/servers/plugins/usn/usn.c
@@ -148,13 +148,13 @@ bail:
static int
usn_preop_init(Slapi_PBlock *pb)
{
- int rc = 0;
+ int rc = SLAPI_PLUGIN_SUCCESS;
int predel = SLAPI_PLUGIN_PRE_DELETE_FN;
if (slapi_pblock_set(pb, predel, (void *)usn_preop_delete) != 0) {
slapi_log_error(SLAPI_LOG_FATAL, USN_PLUGIN_SUBSYSTEM,
"usn_preop_init: failed to register preop plugin\n");
- rc = -1;
+ rc = SLAPI_PLUGIN_FAILURE;
}
return rc;
@@ -163,7 +163,7 @@ usn_preop_init(Slapi_PBlock *pb)
static int
usn_bepreop_init(Slapi_PBlock *pb)
{
- int rc = 0;
+ int rc = SLAPI_PLUGIN_SUCCESS;
int premod = SLAPI_PLUGIN_BE_PRE_MODIFY_FN;
int premdn = SLAPI_PLUGIN_BE_PRE_MODRDN_FN;
@@ -175,7 +175,7 @@ usn_bepreop_init(Slapi_PBlock *pb)
(slapi_pblock_set(pb, premdn, (void *)usn_bepreop_modify) != 0)) {
slapi_log_error(SLAPI_LOG_FATAL, USN_PLUGIN_SUBSYSTEM,
"usn_bepreop_init: failed to register bepreop plugin\n");
- rc = -1;
+ rc = SLAPI_PLUGIN_FAILURE;
}
return rc;
@@ -184,7 +184,7 @@ usn_bepreop_init(Slapi_PBlock *pb)
static int
usn_betxnpreop_init(Slapi_PBlock *pb)
{
- int rc = 0;
+ int rc = SLAPI_PLUGIN_SUCCESS;
int preadd = SLAPI_PLUGIN_BE_TXN_PRE_ADD_FN;
int predel = SLAPI_PLUGIN_BE_TXN_PRE_DELETE_TOMBSTONE_FN;
@@ -192,7 +192,7 @@ usn_betxnpreop_init(Slapi_PBlock *pb)
(slapi_pblock_set(pb, predel, (void *)usn_betxnpreop_delete) != 0)) {
slapi_log_error(SLAPI_LOG_FATAL, USN_PLUGIN_SUBSYSTEM,
"usn_betxnpreop_init: failed to register betxnpreop plugin\n");
- rc = -1;
+ rc = SLAPI_PLUGIN_FAILURE;
}
return rc;
@@ -201,7 +201,7 @@ usn_betxnpreop_init(Slapi_PBlock *pb)
static int
usn_bepostop_init(Slapi_PBlock *pb)
{
- int rc = 0;
+ int rc = SLAPI_PLUGIN_SUCCESS;
Slapi_Entry *plugin_entry = NULL;
char *plugin_type = NULL;
int postadd = SLAPI_PLUGIN_BE_POST_ADD_FN;
@@ -227,7 +227,7 @@ usn_bepostop_init(Slapi_PBlock *pb)
(slapi_pblock_set(pb, postmdn, (void *)usn_bepostop) != 0)) {
slapi_log_error(SLAPI_LOG_FATAL, USN_PLUGIN_SUBSYSTEM,
"usn_bepostop_init: failed to register bepostop plugin\n");
- rc = -1;
+ rc = SLAPI_PLUGIN_FAILURE;
}
return rc;
@@ -236,12 +236,12 @@ usn_bepostop_init(Slapi_PBlock *pb)
static int
usn_rootdse_init()
{
- int rc = -1;
+ int rc = SLAPI_PLUGIN_FAILURE;
if (slapi_config_register_callback(SLAPI_OPERATION_SEARCH, DSE_FLAG_PREOP,
"", LDAP_SCOPE_BASE, "(objectclass=*)",
usn_rootdse_search, NULL)) {
- rc = 0;
+ rc = SLAPI_PLUGIN_SUCCESS;
}
return rc;
@@ -254,7 +254,7 @@ usn_rootdse_init()
static int
usn_start(Slapi_PBlock *pb)
{
- int rc = 0;
+ int rc = SLAPI_PLUGIN_SUCCESS;
Slapi_Value *value;
slapi_log_error(SLAPI_LOG_TRACE, USN_PLUGIN_SUBSYSTEM, "--> usn_start\n");
@@ -262,6 +262,7 @@ usn_start(Slapi_PBlock *pb)
rc = usn_rootdse_init();
rc |= usn_cleanup_start(pb);
if (rc) {
+ rc = SLAPI_PLUGIN_FAILURE;
goto bail;
}
if (0) { /* Not executed; test code for slapi_get_plugin_default_config */
@@ -284,7 +285,9 @@ usn_start(Slapi_PBlock *pb)
/* add nsds5ReplicatedAttributeList: (objectclass=*) $ EXCLUDE entryusn
* to cn=plugin default config,cn=config */
value = slapi_value_new_string("(objectclass=*) $ EXCLUDE entryusn");
- rc = slapi_set_plugin_default_config("nsds5ReplicatedAttributeList", value);
+ if (slapi_set_plugin_default_config("nsds5ReplicatedAttributeList", value)) {
+ rc = SLAPI_PLUGIN_FAILURE;
+ }
slapi_value_free(&value);
g_plugin_started = 1;
bail:
@@ -302,7 +305,7 @@ usn_close(Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_TRACE, USN_PLUGIN_SUBSYSTEM, "<-- usn_close\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
/*
@@ -311,7 +314,6 @@ usn_close(Slapi_PBlock *pb)
static int
usn_preop_delete(Slapi_PBlock *pb)
{
- int rc = 0;
Slapi_Operation *op = NULL;
slapi_log_error(SLAPI_LOG_TRACE, USN_PLUGIN_SUBSYSTEM,
@@ -323,7 +325,7 @@ usn_preop_delete(Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_TRACE, USN_PLUGIN_SUBSYSTEM,
"<-- usn_preop_delete\n");
- return rc;
+ return SLAPI_PLUGIN_SUCCESS;
}
static void
@@ -407,7 +409,7 @@ usn_betxnpreop_add(Slapi_PBlock *pb)
{
Slapi_Entry *e = NULL;
Slapi_Backend *be = NULL;
- int rc = LDAP_SUCCESS;
+ int rc = SLAPI_PLUGIN_SUCCESS;
slapi_log_error(SLAPI_LOG_TRACE, USN_PLUGIN_SUBSYSTEM,
"--> usn_betxnpreop_add\n");
@@ -416,11 +418,15 @@ usn_betxnpreop_add(Slapi_PBlock *pb)
slapi_pblock_get(pb, SLAPI_ADD_ENTRY, &e);
if (NULL == e) {
rc = LDAP_NO_SUCH_OBJECT;
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &rc);
+ rc = SLAPI_PLUGIN_FAILURE;
goto bail;
}
slapi_pblock_get(pb, SLAPI_BACKEND, &be);
if (NULL == be) {
rc = LDAP_PARAM_ERROR;
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &rc);
+ rc = SLAPI_PLUGIN_FAILURE;
goto bail;
}
_usn_add_next_usn(e, be);
@@ -439,7 +445,7 @@ usn_betxnpreop_delete(Slapi_PBlock *pb)
{
Slapi_Entry *e = NULL;
Slapi_Backend *be = NULL;
- int rc = LDAP_SUCCESS;
+ int rc = SLAPI_PLUGIN_SUCCESS;
slapi_log_error(SLAPI_LOG_TRACE, USN_PLUGIN_SUBSYSTEM,
"--> usn_betxnpreop_delete\n");
@@ -448,11 +454,15 @@ usn_betxnpreop_delete(Slapi_PBlock *pb)
slapi_pblock_get(pb, SLAPI_DELETE_BEPREOP_ENTRY, &e);
if (NULL == e) {
rc = LDAP_NO_SUCH_OBJECT;
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &rc);
+ rc = SLAPI_PLUGIN_FAILURE;
goto bail;
}
slapi_pblock_get(pb, SLAPI_BACKEND, &be);
if (NULL == be) {
rc = LDAP_PARAM_ERROR;
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &rc);
+ rc = SLAPI_PLUGIN_FAILURE;
goto bail;
}
_usn_add_next_usn(e, be);
@@ -472,7 +482,7 @@ usn_bepreop_modify (Slapi_PBlock *pb)
{
LDAPMod **mods = NULL;
Slapi_Backend *be = NULL;
- int rc = LDAP_SUCCESS;
+ int rc = SLAPI_PLUGIN_SUCCESS;
slapi_log_error(SLAPI_LOG_TRACE, USN_PLUGIN_SUBSYSTEM,
"--> usn_bepreop_modify\n");
@@ -483,6 +493,9 @@ usn_bepreop_modify (Slapi_PBlock *pb)
if (NULL == be) {
slapi_log_error(SLAPI_LOG_FATAL, USN_PLUGIN_SUBSYSTEM,
"usn_bepreop_modify: no backend.\n");
+ rc = LDAP_PARAM_ERROR;
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &rc);
+ rc = SLAPI_PLUGIN_FAILURE;
goto bail;
}
if (LDAP_SUCCESS == _usn_mod_next_usn(&mods, be)) {
@@ -498,7 +511,7 @@ bail:
static int
usn_bepostop (Slapi_PBlock *pb)
{
- int rc = -1;
+ int rc = SLAPI_PLUGIN_FAILURE;
Slapi_Backend *be = NULL;
slapi_log_error(SLAPI_LOG_TRACE, USN_PLUGIN_SUBSYSTEM,
@@ -507,12 +520,16 @@ usn_bepostop (Slapi_PBlock *pb)
/* if op is not successful, don't increment the counter */
slapi_pblock_get(pb, SLAPI_RESULT_CODE, &rc);
if (LDAP_SUCCESS != rc) {
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &rc);
+ rc = SLAPI_PLUGIN_FAILURE;
goto bail;
}
slapi_pblock_get(pb, SLAPI_BACKEND, &be);
if (NULL == be) {
rc = LDAP_PARAM_ERROR;
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &rc);
+ rc = SLAPI_PLUGIN_FAILURE;
goto bail;
}
@@ -529,7 +546,7 @@ bail:
static int
usn_bepostop_modify (Slapi_PBlock *pb)
{
- int rc = -1;
+ int rc = SLAPI_PLUGIN_FAILURE;
Slapi_Backend *be = NULL;
LDAPMod **mods = NULL;
int i;
@@ -540,6 +557,7 @@ usn_bepostop_modify (Slapi_PBlock *pb)
/* if op is not successful, don't increment the counter */
slapi_pblock_get(pb, SLAPI_RESULT_CODE, &rc);
if (LDAP_SUCCESS != rc) {
+ rc = SLAPI_PLUGIN_FAILURE;
goto bail;
}
@@ -560,6 +578,8 @@ usn_bepostop_modify (Slapi_PBlock *pb)
slapi_pblock_get(pb, SLAPI_BACKEND, &be);
if (NULL == be) {
rc = LDAP_PARAM_ERROR;
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &rc);
+ rc = SLAPI_PLUGIN_FAILURE;
goto bail;
}
@@ -577,7 +597,7 @@ bail:
static int
usn_bepostop_delete (Slapi_PBlock *pb)
{
- int rc = -1;
+ int rc = SLAPI_PLUGIN_FAILURE;
Slapi_Backend *be = NULL;
slapi_log_error(SLAPI_LOG_TRACE, USN_PLUGIN_SUBSYSTEM,
@@ -586,12 +606,15 @@ usn_bepostop_delete (Slapi_PBlock *pb)
/* if op is not successful, don't increment the counter */
slapi_pblock_get(pb, SLAPI_RESULT_CODE, &rc);
if (LDAP_SUCCESS != rc) {
+ rc = SLAPI_PLUGIN_FAILURE;
goto bail;
}
slapi_pblock_get(pb, SLAPI_BACKEND, &be);
if (NULL == be) {
rc = LDAP_PARAM_ERROR;
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &rc);
+ rc = SLAPI_PLUGIN_FAILURE;
goto bail;
}
diff --git a/ldap/servers/plugins/views/views.c b/ldap/servers/plugins/views/views.c
index 0892b0d..c6fd628 100644
--- a/ldap/servers/plugins/views/views.c
+++ b/ldap/servers/plugins/views/views.c
@@ -185,7 +185,7 @@ void * view_get_plugin_identity()
*/
int views_init( Slapi_PBlock *pb )
{
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
void * plugin_identity=NULL;
slapi_log_error( SLAPI_LOG_TRACE, VIEWS_PLUGIN_SUBSYSTEM, "--> views_init\n");
@@ -209,7 +209,7 @@ int views_init( Slapi_PBlock *pb )
{
slapi_log_error( SLAPI_LOG_FATAL, VIEWS_PLUGIN_SUBSYSTEM,
"views_init: failed to register plugin\n" );
- ret = -1;
+ ret = SLAPI_PLUGIN_FAILURE;
}
slapi_log_error( SLAPI_LOG_TRACE, VIEWS_PLUGIN_SUBSYSTEM, "<-- views_init\n");
@@ -238,7 +238,7 @@ void views_unlock()
*/
static int views_start( Slapi_PBlock *pb )
{
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
void **statechange_api;
slapi_log_error( SLAPI_LOG_TRACE, VIEWS_PLUGIN_SUBSYSTEM, "--> views_start\n");
@@ -270,7 +270,7 @@ static int views_start( Slapi_PBlock *pb )
if( slapi_apib_register(Views_v1_0_GUID, api) )
{
slapi_log_error( SLAPI_LOG_FATAL, VIEWS_PLUGIN_SUBSYSTEM, "views: failed to publish views interface\n");
- ret = -1;
+ ret = SLAPI_PLUGIN_FAILURE;
}
slapi_log_error( SLAPI_LOG_TRACE, VIEWS_PLUGIN_SUBSYSTEM, "<-- views_start\n");
@@ -296,7 +296,7 @@ static int _internal_api_views_entry_dn_exists(char *view_dn, char *e_dn)
static int _internal_api_views_entry_exists_general(char *view_dn, Slapi_Entry *e, char *e_dn)
{
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
viewEntry *view;
char *dn;
@@ -326,7 +326,7 @@ static int _internal_api_views_entry_exists_general(char *view_dn, Slapi_Entry *
if(slapi_dn_issuffix(dn, view_dn))
{
/* this entry is physically contained in the view hiearchy */
- ret = -1;
+ ret = SLAPI_PLUGIN_FAILURE;
goto bail;
}
@@ -346,7 +346,7 @@ static int _internal_api_views_entry_exists_general(char *view_dn, Slapi_Entry *
if(0==slapi_filter_test_simple(e,view->includeAncestorFiltersFilter))
{
/* this entry would appear in the view */
- ret = -1;
+ ret = SLAPI_PLUGIN_FAILURE;
}
}
@@ -408,7 +408,7 @@ static int views_close( Slapi_PBlock *pb )
slapi_log_error( SLAPI_LOG_TRACE, VIEWS_PLUGIN_SUBSYSTEM, "<-- views_close\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
@@ -419,7 +419,7 @@ static int views_close( Slapi_PBlock *pb )
*/
static int views_cache_create()
{
- int ret = -1;
+ int ret = SLAPI_PLUGIN_FAILURE;
slapi_log_error( SLAPI_LOG_TRACE, VIEWS_PLUGIN_SUBSYSTEM, "--> views_cache_create\n");
@@ -474,7 +474,7 @@ static int views_cache_create()
{
/* its ok to not have views to cache */
theCache.cache_built = 0;
- ret = 0;
+ ret = SLAPI_PLUGIN_SUCCESS;
}
theCache.currentUpdaterThread = 0;
@@ -530,7 +530,7 @@ int views_cache_dn_compare(const void *e1, const void *e2)
*/
static int views_cache_index()
{
- int ret = -1;
+ int ret = SLAPI_PLUGIN_FAILURE;
int i;
viewEntry *theView = theCache.pCacheViews;
viewEntry *current = 0;
@@ -558,7 +558,7 @@ static int views_cache_index()
/* sort the views */
qsort(theCache.ppViewIndex, theCache.view_count, sizeof(viewEntry*), views_cache_view_compare);
- ret = 0;
+ ret = SLAPI_PLUGIN_SUCCESS;
}
return ret;
@@ -569,7 +569,7 @@ static int views_cache_index()
views_cache_view_index_bsearch - RECURSIVE
----------------------------------------
performs a binary search on the cache view index
- return -1 if key is not found
+ return SLAPI_PLUGIN_FAILURE if key is not found
*/
viewEntry *views_cache_view_index_bsearch( const char *key, int lower, int upper )
{
@@ -617,7 +617,7 @@ viewEntry *views_cache_view_index_bsearch( const char *key, int lower, int upper
*/
static viewEntry *views_cache_find_view(char *view)
{
- viewEntry *ret = 0; /* assume failure */
+ viewEntry *ret = SLAPI_PLUGIN_SUCCESS; /* assume failure */
if(theCache.view_count != 1)
ret = views_cache_view_index_bsearch(view, 0, theCache.view_count-1);
@@ -1119,7 +1119,7 @@ static void views_cache_create_inclusion_filter(viewEntry *pView)
*/
static int views_cache_build_view_list(viewEntry **pViews)
{
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
Slapi_PBlock *pSuffixSearch = 0;
Slapi_Entry **pSuffixList = 0;
Slapi_Attr *suffixAttr;
@@ -1192,7 +1192,7 @@ static int views_cache_build_view_list(viewEntry **pViews)
else
{
slapi_log_error(SLAPI_LOG_PLUGIN, VIEWS_PLUGIN_SUBSYSTEM, "views_cache_build_view_list: failed to find suffixes\n");
- ret = -1;
+ ret = SLAPI_PLUGIN_FAILURE;
}
/* clean up */
@@ -1215,7 +1215,8 @@ struct dn_views_info {
/* does same funcationality as views_add_dn_views except it is invoked via a callback */
-static int views_dn_views_cb (Slapi_Entry* e, void *callback_data) {
+static int views_dn_views_cb (Slapi_Entry* e, void *callback_data)
+{
struct dn_views_info *info;
char *pDn = 0;
struct berval **dnVals;
diff --git a/ldap/servers/slapd/add.c b/ldap/servers/slapd/add.c
index 2a70f64..2e326cf 100644
--- a/ldap/servers/slapd/add.c
+++ b/ldap/servers/slapd/add.c
@@ -713,7 +713,7 @@ static void op_shared_add (Slapi_PBlock *pb)
sdn = slapi_sdn_dup(slapi_entry_get_sdn_const(e));
slapi_pblock_set(pb, SLAPI_ADD_TARGET_SDN, (void *)sdn);
if (plugin_call_plugins(pb, internal_op ? SLAPI_PLUGIN_INTERNAL_PRE_ADD_FN :
- SLAPI_PLUGIN_PRE_ADD_FN) == 0)
+ SLAPI_PLUGIN_PRE_ADD_FN) == SLAPI_PLUGIN_SUCCESS)
{
int rc;
Slapi_Entry *ec;
diff --git a/ldap/servers/slapd/delete.c b/ldap/servers/slapd/delete.c
index ced6351..68409c7 100644
--- a/ldap/servers/slapd/delete.c
+++ b/ldap/servers/slapd/delete.c
@@ -353,7 +353,7 @@ static void op_shared_delete (Slapi_PBlock *pb)
* post-delete plugins.
*/
if (plugin_call_plugins(pb, internal_op ? SLAPI_PLUGIN_INTERNAL_PRE_DELETE_FN :
- SLAPI_PLUGIN_PRE_DELETE_FN) == 0)
+ SLAPI_PLUGIN_PRE_DELETE_FN) == SLAPI_PLUGIN_SUCCESS)
{
int rc;
diff --git a/ldap/servers/slapd/modify.c b/ldap/servers/slapd/modify.c
index 867e391..be8b9b8 100644
--- a/ldap/servers/slapd/modify.c
+++ b/ldap/servers/slapd/modify.c
@@ -1040,7 +1040,7 @@ static void op_shared_modify (Slapi_PBlock *pb, int pw_change, char *old_pw)
*/
slapi_pblock_set (pb, SLAPI_MODIFY_MODS, (void*)slapi_mods_get_ldapmods_passout (&smods));
if (plugin_call_plugins(pb, internal_op ? SLAPI_PLUGIN_INTERNAL_PRE_MODIFY_FN :
- SLAPI_PLUGIN_PRE_MODIFY_FN) == 0)
+ SLAPI_PLUGIN_PRE_MODIFY_FN) == SLAPI_PLUGIN_SUCCESS)
{
int rc;
diff --git a/ldap/servers/slapd/modrdn.c b/ldap/servers/slapd/modrdn.c
index 62c7f6a..bbdd9dd 100644
--- a/ldap/servers/slapd/modrdn.c
+++ b/ldap/servers/slapd/modrdn.c
@@ -654,7 +654,7 @@ op_shared_rename(Slapi_PBlock *pb, int passin_args)
* post-modrdn plugins.
*/
if (plugin_call_plugins(pb, internal_op ? SLAPI_PLUGIN_INTERNAL_PRE_MODRDN_FN :
- SLAPI_PLUGIN_PRE_MODRDN_FN) == 0)
+ SLAPI_PLUGIN_PRE_MODRDN_FN) == SLAPI_PLUGIN_SUCCESS)
{
int rc= LDAP_OPERATIONS_ERROR;
slapi_pblock_set(pb, SLAPI_PLUGIN, be->be_database);
diff --git a/ldap/servers/slapd/plugin.c b/ldap/servers/slapd/plugin.c
index d19faa5..5f66ab2 100644
--- a/ldap/servers/slapd/plugin.c
+++ b/ldap/servers/slapd/plugin.c
@@ -1453,9 +1453,8 @@ plugin_call_func (struct slapdplugin *list, int operation, Slapi_PBlock *pb, int
if (( rc = func (pb)) != 0 )
{
if (SLAPI_PLUGIN_PREOPERATION == list->plg_type ||
- SLAPI_PLUGIN_INTERNAL_PREOPERATION == list->plg_type ||
- SLAPI_PLUGIN_BETXNPREOPERATION == list->plg_type ||
- SLAPI_PLUGIN_START_FN == operation )
+ SLAPI_PLUGIN_INTERNAL_PREOPERATION == list->plg_type ||
+ SLAPI_PLUGIN_START_FN == operation )
{
/*
* We bail out of plugin processing for preop plugins
@@ -1465,13 +1464,18 @@ plugin_call_func (struct slapdplugin *list, int operation, Slapi_PBlock *pb, int
*/
return_value = rc;
break;
- } else if (SLAPI_PLUGIN_BEPREOPERATION == list->plg_type ||
- SLAPI_PLUGIN_BEPOSTOPERATION == list->plg_type)
+ }
+ else if (SLAPI_PLUGIN_BEPREOPERATION == list->plg_type ||
+ SLAPI_PLUGIN_BETXNPREOPERATION == list->plg_type ||
+ SLAPI_PLUGIN_BEPOSTOPERATION == list->plg_type)
{
- /* respect fatal error (-1); should not OR it */
- if (-1 == rc) {
+ /*
+ * respect fatal error SLAPI_PLUGIN_FAILURE (-1);
+ * should not OR it.
+ */
+ if (SLAPI_PLUGIN_FAILURE == rc) {
return_value = rc;
- } else if (-1 != return_value) {
+ } else if (SLAPI_PLUGIN_FAILURE != return_value) {
/* OR the result into the return value
* for be pre/postops */
return_value |= rc;
commit 28b313cac943d9d50866f9d73e6486167f2dbc8a
Author: Noriko Hosoi <nhosoi(a)redhat.com>
Date: Thu Jul 18 14:27:28 2013 -0700
Ticket #47367 - (phase 1) ldapdelete returns non-leaf entry error while trying to remove a leaf entry
Bug description: Replication conflict confuses the numsubordinate count,
which leaves an entry that cannot be deleted even its subordinate entries
are all removed.
Fix description:
[urp.c] 1) get_dn_plus_uniqueid: a logic to create a conflict DN had a bug.
It used to call slapi_sdn_get_rdn to get the rdn. The function slapi_sdn_
get_rdn blindly returned the "dn" field without checking whether the field
is NULL or not. Instead, this patch changes the interface of the helper
function get_dn_plus_uniqueid and use the original Slapi_DN with slapi_sdn_
get_dn, then generates the conflict DN "nsuniqueid=...+ <RDN>,<PARENT>".
2) The urp calling timing was moved from SLAPI_PLUGIN_BE_TXN_PRE_* to
SLAPI_PLUGIN_BE_PRE_*. (Note: SLAPI_PLUGIN_BE_PRE_* is also in the
backend transaction.) This is necessary since urp needs to be done
prior to parent checking.
[ldbm_add.c] Moved SLAPI_PLUGIN_BE_PRE_ADD_FN inside of the transaction.
Other operations are already calling SLAPI_PLUGIN_BE_PRE function at the
timing.
[ldbm_delete.c] There is a case a parent of a delete-candidate entry runs
into a conflict and multiple parent entries exist. Once it occurs, a
parent entry found by the parent dn string may not be the entry which
manages the numsubordinate count the delete-candidate entry belonging to.
It confuses the numsubordinate counts and leaves an entry which cannot be
deleted due to the numsubordinate count mismatch. This patch retrieves
parent entry by parent id if it is available.
[ldbm_entryrdn.c] When traversing the DIT, a special treatment is needed
for a tombstone entry. I.e, 2 RDNs (nsuniqueid=..., <RDN>) is treated as
one RDN. It should decrement the index (rdnidx) one more to point to the
right position of the RDN array in Slapi_RDN.
[ldbm_search.c] When checking the scope of an entry in ldbm_back_next_
search_entry_ext, a tombstone entry was not properly examined. This patch
introduces a new slapi api slapi_sdn_scope_test_ext.
[dn.c] In slapi_sdn_get_rdn, use slapi_sdn_get_dn to get the dn value of
Slapi_DN. It was one cause of the problem in get_dn_plus_uniqueid (urp.c).
This patch adds slapi_sdn_scope_test_ext, which takes flags to indicates
the first argument dn is a tombstone sdn. Also, this patch replaces
"malloc + strcpy + strcat" with slapi_ch_smprintf to improve the
readability of the code.
[rdn.c] This patch replaces "malloc + strcpy + strcat" with slapi_create_
dn_string to normalize the newly added rdn and improve the readability of
the code.
Reviewed by Rich (Thanks!!)
https://fedorahosted.org/389/ticket/47367
(cherry picked from commit 2f4f74b3d38eeb38f0794dfb2e880a95e7e9bd49)
(cherry picked from commit 690d58ba5870e7f0dd3ad6593c92a86771fc54d5)
diff --git a/ldap/servers/plugins/replication/repl5_init.c b/ldap/servers/plugins/replication/repl5_init.c
index cc73f5d..b32a3b8 100644
--- a/ldap/servers/plugins/replication/repl5_init.c
+++ b/ldap/servers/plugins/replication/repl5_init.c
@@ -359,17 +359,6 @@ multimaster_betxnpreop_init( Slapi_PBlock *pb )
{
int rc= 0; /* OK */
- if( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 ) != 0 ||
- slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multimasterbepreopdesc ) != 0 ||
- slapi_pblock_set( pb, SLAPI_PLUGIN_BE_TXN_PRE_ADD_FN, (void *) multimaster_betxnpreop_add ) != 0 ||
- slapi_pblock_set( pb, SLAPI_PLUGIN_BE_TXN_PRE_DELETE_FN, (void *) multimaster_betxnpreop_delete ) != 0 ||
- slapi_pblock_set( pb, SLAPI_PLUGIN_BE_TXN_PRE_MODIFY_FN, (void *) multimaster_betxnpreop_modify ) != 0 ||
- slapi_pblock_set( pb, SLAPI_PLUGIN_BE_TXN_PRE_MODRDN_FN, (void *) multimaster_betxnpreop_modrdn ) != 0 )
- {
- slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "multimaster_betxnpreop_init failed\n" );
- rc= -1;
- }
-
return rc;
}
diff --git a/ldap/servers/plugins/replication/repl5_plugins.c b/ldap/servers/plugins/replication/repl5_plugins.c
index 01ac03c..590af7e 100644
--- a/ldap/servers/plugins/replication/repl5_plugins.c
+++ b/ldap/servers/plugins/replication/repl5_plugins.c
@@ -718,8 +718,7 @@ multimaster_bepreop_add (Slapi_PBlock *pb)
{
slapi_pblock_set(pb, SLAPI_TXN_RUV_MODS_FN,
(void *)replica_ruv_smods_for_op);
- if (!repl5_is_betxn && is_replicated_operation) {
- /* if is_betxn is on, urp is called at betxn preop */
+ if (is_replicated_operation) {
rc = urp_add_operation(pb);
}
}
@@ -744,8 +743,7 @@ multimaster_bepreop_delete (Slapi_PBlock *pb)
{
slapi_pblock_set(pb, SLAPI_TXN_RUV_MODS_FN,
(void *)replica_ruv_smods_for_op);
- if (!repl5_is_betxn && is_replicated_operation) {
- /* if is_betxn is on, urp is called at betxn preop */
+ if (is_replicated_operation) {
rc = urp_delete_operation(pb);
}
}
@@ -770,8 +768,7 @@ multimaster_bepreop_modify (Slapi_PBlock *pb)
{
slapi_pblock_set(pb, SLAPI_TXN_RUV_MODS_FN,
(void *)replica_ruv_smods_for_op);
- if (!repl5_is_betxn && is_replicated_operation) {
- /* if is_betxn is on, urp is called at betxn preop */
+ if (is_replicated_operation) {
rc = urp_modify_operation(pb);
}
}
@@ -799,8 +796,7 @@ multimaster_bepreop_modrdn (Slapi_PBlock *pb)
{
slapi_pblock_set(pb, SLAPI_TXN_RUV_MODS_FN,
(void *)replica_ruv_smods_for_op);
- if (!repl5_is_betxn && is_replicated_operation) {
- /* if is_betxn is on, urp is called at betxn preop */
+ if (is_replicated_operation) {
rc = urp_modrdn_operation(pb);
}
}
diff --git a/ldap/servers/plugins/replication/urp.c b/ldap/servers/plugins/replication/urp.c
index 3d0ea82..471bf8d 100644
--- a/ldap/servers/plugins/replication/urp.c
+++ b/ldap/servers/plugins/replication/urp.c
@@ -55,9 +55,9 @@ 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, const Slapi_Entry *entry, CSN *opcsn, const char *optype);
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 mod_namingconflict_attr (const char *uniqueid, const Slapi_DN *entrysdn, const Slapi_DN *conflictsdn, CSN *opcsn, const char *optype);
static int del_replconflict_attr (const Slapi_Entry *entry, CSN *opcsn, int opflags);
-static char *get_dn_plus_uniqueid(char *sessionid,const char *olddn,const char *uniqueid);
+static char *get_dn_plus_uniqueid(char *sessionid,const Slapi_DN *oldsdn,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);
@@ -184,7 +184,7 @@ urp_add_operation( Slapi_PBlock *pb )
if (r<0)
{
/* Entry to be added is a loser */
- char *newdn= get_dn_plus_uniqueid (sessionid, basedn, adduniqueid);
+ char *newdn= get_dn_plus_uniqueid (sessionid, (const Slapi_DN *)addentry, adduniqueid);
if(newdn==NULL)
{
op_result= LDAP_OPERATIONS_ERROR;
@@ -203,7 +203,11 @@ urp_add_operation( Slapi_PBlock *pb )
Slapi_RDN *rdn;
char buf[BUFSIZ];
+#ifdef DEBUG
+ PR_snprintf(buf, BUFSIZ, "%s (add) %s", REASON_ANNOTATE_DN, basedn);
+#else
PR_snprintf(buf, BUFSIZ, "%s %s", REASON_ANNOTATE_DN, basedn);
+#endif
if (slapi_entry_attr_find (addentry, ATTR_NSDS5_REPLCONFLICT, &attr) == 0)
{
/* ATTR_NSDS5_REPLCONFLICT exists */
@@ -466,7 +470,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, "MODRDN");
slapi_pblock_set(pb, SLAPI_MODRDN_NEWRDN, newrdn_with_uniqueid);
slapi_log_error(slapi_log_urp, sessionid,
"urp_modrdn: Naming conflict MODRDN. Rename target entry to %s\n",
@@ -1033,7 +1037,7 @@ urp_annotate_dn (char *sessionid, const Slapi_Entry *entry, CSN *opcsn, const ch
newrdn = get_rdn_plus_uniqueid ( sessionid, basedn, uniqueid );
if(newrdn!=NULL)
{
- mod_namingconflict_attr (uniqueid, basesdn, basesdn, opcsn);
+ mod_namingconflict_attr (uniqueid, basesdn, basesdn, opcsn, optype);
op_result = urp_fixup_rename_entry ( entry, newrdn, 0 );
switch(op_result)
{
@@ -1245,16 +1249,15 @@ bailout:
/* The returned value is either null or "uniqueid=<uniqueid>+<basedn>" */
static char *
-get_dn_plus_uniqueid(char *sessionid, const char *olddn, const char *uniqueid)
+get_dn_plus_uniqueid(char *sessionid, const Slapi_DN *oldsdn, const char *uniqueid)
{
- Slapi_DN *sdn= slapi_sdn_new_dn_byval(olddn);
Slapi_RDN *rdn= slapi_rdn_new();
char *newdn;
PR_ASSERT(uniqueid!=NULL);
/* Check if the RDN already contains the Unique ID */
- slapi_sdn_get_rdn(sdn,rdn);
+ slapi_rdn_set_dn(rdn, slapi_sdn_get_dn(oldsdn));
if(slapi_rdn_contains(rdn,SLAPI_ATTR_UNIQUEID,uniqueid,strlen(uniqueid)))
{
/* The Unique ID is already in the RDN.
@@ -1264,16 +1267,20 @@ get_dn_plus_uniqueid(char *sessionid, const char *olddn, const char *uniqueid)
* require admin intercession
*/
slapi_log_error(SLAPI_LOG_FATAL, sessionid,
- "Annotated DN %s has naming conflict\n", olddn );
+ "Annotated DN %s has naming conflict\n", slapi_sdn_get_dn(oldsdn) );
newdn= NULL;
}
else
{
- slapi_rdn_add(rdn,SLAPI_ATTR_UNIQUEID,uniqueid);
- slapi_sdn_set_rdn(sdn, rdn);
- newdn= slapi_ch_strdup(slapi_sdn_get_dn(sdn));
+ char *parentdn = slapi_dn_parent(slapi_sdn_get_dn(oldsdn));
+ slapi_rdn_add(rdn, SLAPI_ATTR_UNIQUEID, uniqueid);
+ /*
+ * using slapi_ch_smprintf is okay since ...
+ * uniqueid in rdn is normalized and
+ * parentdn is normalized by slapi_sdn_get_dn.
+ */
+ newdn = slapi_ch_smprintf("%s,%s", slapi_rdn_get_rdn(rdn), parentdn);
}
- slapi_sdn_free(&sdn);
slapi_rdn_free(&rdn);
return newdn;
}
@@ -1340,14 +1347,20 @@ 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,
+ const char *optype)
{
Slapi_Mods smods;
char buf[BUFSIZ];
int op_result;
+#ifdef DEBUG
+ PR_snprintf (buf, sizeof(buf), "%s (%s) %s",
+ REASON_ANNOTATE_DN, optype, slapi_sdn_get_dn(conflictsdn));
+#else
PR_snprintf (buf, sizeof(buf), "%s %s",
REASON_ANNOTATE_DN, slapi_sdn_get_dn(conflictsdn));
+#endif
slapi_mods_init (&smods, 2);
if ( strncmp (slapi_sdn_get_dn(entrysdn), SLAPI_ATTR_UNIQUEID,
strlen(SLAPI_ATTR_UNIQUEID)) != 0 )
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_add.c b/ldap/servers/slapd/back-ldbm/ldbm_add.c
index 708ccfa..fa1e9bc 100644
--- a/ldap/servers/slapd/back-ldbm/ldbm_add.c
+++ b/ldap/servers/slapd/back-ldbm/ldbm_add.c
@@ -194,112 +194,6 @@ ldbm_back_add( Slapi_PBlock *pb )
}
- if (!is_tombstone_operation) {
- rc= slapi_setbit_int(rc,SLAPI_RTN_BIT_FETCH_EXISTING_DN_ENTRY);
- }
- rc= slapi_setbit_int(rc,SLAPI_RTN_BIT_FETCH_EXISTING_UNIQUEID_ENTRY);
- rc= slapi_setbit_int(rc,SLAPI_RTN_BIT_FETCH_PARENT_ENTRY);
- while(rc!=0)
- {
- /* JCM - copying entries can be expensive... should optimize */
- /*
- * Some present state information is passed through the PBlock to the
- * backend pre-op plugin. To ensure a consistent snapshot of this state
- * we wrap the reading of the entry with the dblock.
- */
- if(slapi_isbitset_int(rc,SLAPI_RTN_BIT_FETCH_EXISTING_UNIQUEID_ENTRY))
- {
- /* Check if an entry with the intended uniqueid already exists. */
- done_with_pblock_entry(pb,SLAPI_ADD_EXISTING_UNIQUEID_ENTRY); /* Could be through this multiple times */
- addr.udn = NULL;
- addr.sdn = NULL;
- addr.uniqueid = (char*)slapi_entry_get_uniqueid(e); /* jcm - cast away const */
- ldap_result_code= get_copy_of_entry(pb, &addr, &txn, SLAPI_ADD_EXISTING_UNIQUEID_ENTRY, !is_replicated_operation);
- }
- if(slapi_isbitset_int(rc,SLAPI_RTN_BIT_FETCH_EXISTING_DN_ENTRY))
- {
- slapi_pblock_get( pb, SLAPI_ADD_TARGET_SDN, &sdn );
- if (NULL == sdn)
- {
- LDAPDebug0Args(LDAP_DEBUG_ANY,
- "ldbm_back_add: Null target dn\n");
- goto error_return;
- }
-
- /* not need to check the dn syntax as this is a replicated op */
- if(!is_replicated_operation){
- dn = slapi_sdn_get_dn(sdn);
- ldap_result_code = slapi_dn_syntax_check(pb, dn, 1);
- if (ldap_result_code)
- {
- ldap_result_code = LDAP_INVALID_DN_SYNTAX;
- slapi_pblock_get(pb, SLAPI_PB_RESULT_TEXT, &ldap_result_message);
- goto error_return;
- }
- }
-
- slapi_sdn_get_backend_parent(sdn, &parentsdn, pb->pb_backend);
- /* Check if an entry with the intended DN already exists. */
- done_with_pblock_entry(pb,SLAPI_ADD_EXISTING_DN_ENTRY); /* Could be through this multiple times */
- addr.sdn = sdn;
- addr.udn = NULL;
- addr.uniqueid = NULL;
- ldap_result_code= get_copy_of_entry(pb, &addr, &txn, SLAPI_ADD_EXISTING_DN_ENTRY, !is_replicated_operation);
- if(ldap_result_code==LDAP_OPERATIONS_ERROR ||
- ldap_result_code==LDAP_INVALID_DN_SYNTAX)
- {
- goto error_return;
- }
- }
- /* if we can find the parent by dn or uniqueid, and the operation has requested the parent
- then get it */
- if(have_parent_address(&parentsdn, operation->o_params.p.p_add.parentuniqueid) &&
- slapi_isbitset_int(rc,SLAPI_RTN_BIT_FETCH_PARENT_ENTRY))
- {
- done_with_pblock_entry(pb,SLAPI_ADD_PARENT_ENTRY); /* Could be through this multiple times */
- addr.sdn = &parentsdn;
- addr.udn = NULL;
- addr.uniqueid = operation->o_params.p.p_add.parentuniqueid;
- ldap_result_code= get_copy_of_entry(pb, &addr, &txn, SLAPI_ADD_PARENT_ENTRY, !is_replicated_operation);
- /* need to set parentsdn or parentuniqueid if either is not set? */
- }
-
- /* Call the Backend Pre Add plugins */
- slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ldap_result_code);
- rc= plugin_call_plugins(pb, SLAPI_PLUGIN_BE_PRE_ADD_FN);
- if (rc) {
- int opreturn = 0;
- if (SLAPI_PLUGIN_NOOP == rc) {
- not_an_error = 1;
- rc = LDAP_SUCCESS;
- }
- /*
- * Plugin indicated some kind of failure,
- * or that this Operation became a No-Op.
- */
- if (!ldap_result_code) {
- slapi_pblock_get(pb, SLAPI_RESULT_CODE, &ldap_result_code);
- }
- if (!ldap_result_code) {
- LDAPDebug0Args(LDAP_DEBUG_ANY,
- "ldbm_back_add: SLAPI_PLUGIN_BE_PRE_ADD_FN returned error but did not set SLAPI_RESULT_CODE\n");
- ldap_result_code = LDAP_OPERATIONS_ERROR;
- }
- slapi_pblock_get(pb, SLAPI_PLUGIN_OPRETURN, &opreturn);
- if (!opreturn) {
- /* make sure opreturn is set for the postop plugins */
- slapi_pblock_set(pb, SLAPI_PLUGIN_OPRETURN, ldap_result_code ? &ldap_result_code : &rc);
- }
-
- goto error_return;
- }
- /*
- * (rc!=-1 && rc!= 0) means that the plugin changed things, so we go around
- * the loop once again to get the new present state.
- */
- /* JCMREPL - Warning: A Plugin could cause an infinite loop by always returning a result code that requires some action. */
- }
-
/*
* Originally (in the U-M LDAP 3.3 code), there was a comment near this
* code about a race condition. The race was that a 2nd entry could be
@@ -365,6 +259,113 @@ ldbm_back_add( Slapi_PBlock *pb )
if (0 == retry_count) {
/* First time, hold SERIAL LOCK */
retval = dblayer_txn_begin(be, parent_txn, &txn);
+
+ if (!is_tombstone_operation) {
+ rc= slapi_setbit_int(rc,SLAPI_RTN_BIT_FETCH_EXISTING_DN_ENTRY);
+ }
+
+ rc= slapi_setbit_int(rc,SLAPI_RTN_BIT_FETCH_EXISTING_UNIQUEID_ENTRY);
+ rc= slapi_setbit_int(rc,SLAPI_RTN_BIT_FETCH_PARENT_ENTRY);
+ while(rc!=0)
+ {
+ /* JCM - copying entries can be expensive... should optimize */
+ /*
+ * Some present state information is passed through the PBlock to the
+ * backend pre-op plugin. To ensure a consistent snapshot of this state
+ * we wrap the reading of the entry with the dblock.
+ */
+ if(slapi_isbitset_int(rc,SLAPI_RTN_BIT_FETCH_EXISTING_UNIQUEID_ENTRY))
+ {
+ /* Check if an entry with the intended uniqueid already exists. */
+ done_with_pblock_entry(pb,SLAPI_ADD_EXISTING_UNIQUEID_ENTRY); /* Could be through this multiple times */
+ addr.udn = NULL;
+ addr.sdn = NULL;
+ addr.uniqueid = (char*)slapi_entry_get_uniqueid(e); /* jcm - cast away const */
+ ldap_result_code= get_copy_of_entry(pb, &addr, &txn, SLAPI_ADD_EXISTING_UNIQUEID_ENTRY, !is_replicated_operation);
+ }
+ if(slapi_isbitset_int(rc,SLAPI_RTN_BIT_FETCH_EXISTING_DN_ENTRY))
+ {
+ slapi_pblock_get( pb, SLAPI_ADD_TARGET_SDN, &sdn );
+ if (NULL == sdn)
+ {
+ LDAPDebug0Args(LDAP_DEBUG_ANY,
+ "ldbm_back_add: Null target dn\n");
+ goto error_return;
+ }
+
+ /* not need to check the dn syntax as this is a replicated op */
+ if(!is_replicated_operation){
+ dn = slapi_sdn_get_dn(sdn);
+ ldap_result_code = slapi_dn_syntax_check(pb, dn, 1);
+ if (ldap_result_code)
+ {
+ ldap_result_code = LDAP_INVALID_DN_SYNTAX;
+ slapi_pblock_get(pb, SLAPI_PB_RESULT_TEXT, &ldap_result_message);
+ goto error_return;
+ }
+ }
+
+ slapi_sdn_get_backend_parent(sdn, &parentsdn, pb->pb_backend);
+ /* Check if an entry with the intended DN already exists. */
+ done_with_pblock_entry(pb,SLAPI_ADD_EXISTING_DN_ENTRY); /* Could be through this multiple times */
+ addr.sdn = sdn;
+ addr.udn = NULL;
+ addr.uniqueid = NULL;
+ ldap_result_code= get_copy_of_entry(pb, &addr, &txn, SLAPI_ADD_EXISTING_DN_ENTRY, !is_replicated_operation);
+ if(ldap_result_code==LDAP_OPERATIONS_ERROR ||
+ ldap_result_code==LDAP_INVALID_DN_SYNTAX)
+ {
+ goto error_return;
+ }
+ }
+ /* if we can find the parent by dn or uniqueid, and the operation has requested the parent
+ then get it */
+ if(have_parent_address(&parentsdn, operation->o_params.p.p_add.parentuniqueid) &&
+ slapi_isbitset_int(rc,SLAPI_RTN_BIT_FETCH_PARENT_ENTRY))
+ {
+ done_with_pblock_entry(pb,SLAPI_ADD_PARENT_ENTRY); /* Could be through this multiple times */
+ addr.sdn = &parentsdn;
+ addr.udn = NULL;
+ addr.uniqueid = operation->o_params.p.p_add.parentuniqueid;
+ ldap_result_code= get_copy_of_entry(pb, &addr, &txn, SLAPI_ADD_PARENT_ENTRY, !is_replicated_operation);
+ /* need to set parentsdn or parentuniqueid if either is not set? */
+ }
+
+ /* Call the Backend Pre Add plugins */
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ldap_result_code);
+ rc= plugin_call_plugins(pb, SLAPI_PLUGIN_BE_PRE_ADD_FN);
+ if (rc < 0) {
+ int opreturn = 0;
+ if (SLAPI_PLUGIN_NOOP == rc) {
+ not_an_error = 1;
+ rc = LDAP_SUCCESS;
+ }
+ /*
+ * Plugin indicated some kind of failure,
+ * or that this Operation became a No-Op.
+ */
+ if (!ldap_result_code) {
+ slapi_pblock_get(pb, SLAPI_RESULT_CODE, &ldap_result_code);
+ }
+ if (!ldap_result_code) {
+ LDAPDebug0Args(LDAP_DEBUG_ANY,
+ "ldbm_back_add: SLAPI_PLUGIN_BE_PRE_ADD_FN returned error but did not set SLAPI_RESULT_CODE\n");
+ ldap_result_code = LDAP_OPERATIONS_ERROR;
+ }
+ slapi_pblock_get(pb, SLAPI_PLUGIN_OPRETURN, &opreturn);
+ if (!opreturn) {
+ /* make sure opreturn is set for the postop plugins */
+ slapi_pblock_set(pb, SLAPI_PLUGIN_OPRETURN, ldap_result_code ? &ldap_result_code : &rc);
+ }
+
+ goto error_return;
+ }
+ /*
+ * (rc!=-1 && rc!= 0) means that the plugin changed things, so we go around
+ * the loop once again to get the new present state.
+ */
+ /* JCMREPL - Warning: A Plugin could cause an infinite loop by always returning a result code that requires some action. */
+ }
} else {
/* Otherwise, no SERIAL LOCK */
retval = dblayer_txn_begin_ext(li, parent_txn, &txn, PR_FALSE);
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_delete.c b/ldap/servers/slapd/back-ldbm/ldbm_delete.c
index be73e04..011c2d5 100644
--- a/ldap/servers/slapd/back-ldbm/ldbm_delete.c
+++ b/ldap/servers/slapd/back-ldbm/ldbm_delete.c
@@ -288,7 +288,6 @@ ldbm_back_delete( Slapi_PBlock *pb )
/* Don't call pre-op for Tombstone entries */
if (!delete_tombstone_entry)
{
- int rc = 0;
/*
* Some present state information is passed through the PBlock to the
* backend pre-op plugin. To ensure a consistent snapshot of this state
@@ -305,12 +304,13 @@ ldbm_back_delete( Slapi_PBlock *pb )
goto error_return;
}
slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ldap_result_code);
-
- rc = plugin_call_plugins(pb, SLAPI_PLUGIN_BE_PRE_DELETE_FN);
- if (rc)
+
+ retval = plugin_call_plugins(pb, SLAPI_PLUGIN_BE_PRE_DELETE_FN);
+ if (retval)
{
- if (SLAPI_PLUGIN_NOOP == rc) {
+ if (SLAPI_PLUGIN_NOOP == retval) {
not_an_error = 1;
+ rc = LDAP_SUCCESS;
}
/*
* Plugin indicated some kind of failure,
@@ -324,12 +324,11 @@ ldbm_back_delete( Slapi_PBlock *pb )
if (!opreturn) {
slapi_pblock_set( pb, SLAPI_PLUGIN_OPRETURN, ldap_result_code ? &ldap_result_code : &rc );
}
- retval = -1;
goto error_return;
}
/* the flag could be set in a preop plugin (e.g., USN) */
delete_tombstone_entry = operation_is_flag_set(operation,
- OP_FLAG_TOMBSTONE_ENTRY);
+ OP_FLAG_TOMBSTONE_ENTRY);
}
/* call the transaction pre delete plugins just after the
@@ -363,16 +362,14 @@ ldbm_back_delete( Slapi_PBlock *pb )
*/
is_tombstone_entry = slapi_entry_flag_is_set(e->ep_entry, SLAPI_ENTRY_FLAG_TOMBSTONE);
if (delete_tombstone_entry) {
- PR_ASSERT(is_tombstone_entry);
if (!is_tombstone_entry) {
slapi_log_error(SLAPI_LOG_FATAL, "ldbm_back_delete",
"Attempt to delete a non-tombstone entry %s\n", dn);
delete_tombstone_entry = 0;
}
} else {
- PR_ASSERT(!is_tombstone_entry);
if (is_tombstone_entry) {
- slapi_log_error(SLAPI_LOG_FATAL, "ldbm_back_delete",
+ slapi_log_error(SLAPI_LOG_FATAL, "ldbm_back_delete",
"Attempt to Tombstone again a tombstone entry %s\n", dn);
delete_tombstone_entry = 1;
}
@@ -428,7 +425,7 @@ ldbm_back_delete( Slapi_PBlock *pb )
/* Save away a copy of the entry, before modifications */
slapi_pblock_set( pb, SLAPI_ENTRY_PRE_OP, slapi_entry_dup( e->ep_entry ));
- /* JCMACL - Shouldn't the access check be before the has children check...
+ /* JCMACL - Shouldn't the access check be before the has children check...
* otherwise we're revealing the fact that an entry exists and has children */
ldap_result_code = plugin_call_acl_plugin (pb, e->ep_entry, NULL, NULL, SLAPI_ACL_DELETE,
ACLPLUGIN_ACCESS_DEFAULT, &errbuf );
@@ -449,12 +446,31 @@ ldbm_back_delete( Slapi_PBlock *pb )
if ( !slapi_sdn_isempty(&parentsdn) )
{
struct backentry *parent = NULL;
- entry_address parent_addr;
+ char *pid_str = slapi_entry_attr_get_charptr(e->ep_entry, LDBM_PARENTID_STR);
+ if (pid_str) {
+ /* First, try to get the direct parent. */
+ /*
+ * Although a rare case, multiple parents from repl conflict could exist.
+ * In such case, if a parent entry is found just by parentsdn
+ * (find_entry2modify_only_ext), a wrong parent could be found,
+ * and numsubordinate count could get confused.
+ */
+ ID pid = (ID)strtol(pid_str, (char **)NULL, 10);
+ parent = id2entry(be, pid ,NULL, &retval);
+ if (parent && cache_lock_entry(&inst->inst_cache, parent)) {
+ /* Failed to obtain parent entry's entry lock */
+ CACHE_RETURN(&(inst->inst_cache), &parent);
+ goto error_return;
+ }
+ }
+ if (NULL == parent) {
+ entry_address parent_addr;
- parent_addr.sdn = &parentsdn;
- parent_addr.uniqueid = NULL;
- parent = find_entry2modify_only_ext(pb, be, &parent_addr,
- TOMBSTONE_INCLUDED, &txn);
+ parent_addr.sdn = &parentsdn;
+ parent_addr.uniqueid = NULL;
+ parent = find_entry2modify_only_ext(pb, be, &parent_addr,
+ TOMBSTONE_INCLUDED, &txn);
+ }
if (NULL != parent) {
int isglue;
size_t haschildren = 0;
@@ -549,7 +565,7 @@ ldbm_back_delete( Slapi_PBlock *pb )
slapi_value_free(&tomb_value);
/* XXXggood above used to be: slapi_entry_add_string(tombstone->ep_entry, SLAPI_ATTR_OBJECTCLASS, SLAPI_ATTR_VALUE_TOMBSTONE); */
/* JCMREPL - Add a description of what's going on? */
-
+
if ( (original_tombstone = backentry_dup( tombstone )) == NULL ) {
ldap_result_code= LDAP_OPERATIONS_ERROR;
retval = -1;
@@ -568,6 +584,7 @@ ldbm_back_delete( Slapi_PBlock *pb )
if (retval) {
if (SLAPI_PLUGIN_NOOP == retval) {
not_an_error = 1;
+ rc = LDAP_SUCCESS;
}
LDAPDebug1Arg( LDAP_DEBUG_TRACE,
"SLAPI_PLUGIN_BE_TXN_PRE_DELETE_FN plugin "
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_entryrdn.c b/ldap/servers/slapd/back-ldbm/ldbm_entryrdn.c
index 1b74fa0..e24b43b 100644
--- a/ldap/servers/slapd/back-ldbm/ldbm_entryrdn.c
+++ b/ldap/servers/slapd/back-ldbm/ldbm_entryrdn.c
@@ -3152,6 +3152,7 @@ _entryrdn_index_read(backend *be,
/* Node might be a tombstone. */
rc = _entryrdn_get_tombstone_elem(cursor, tmpsrdn,
&key, nrdn, elem);
+ rdnidx--; /* consider nsuniqueid=..,<RDN> one RDN */
}
if (rc || NULL == *elem) {
slapi_log_error(SLAPI_LOG_BACKLDBM, ENTRYRDN_TAG,
@@ -3258,6 +3259,7 @@ _entryrdn_index_read(backend *be,
}
goto bail;
}
+ rdnidx--; /* consider nsuniqueid=..,<RDN> one RDN */
} else {
slapi_ch_free((void **)&tmpelem);
if (DB_NOTFOUND != rc) {
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_modrdn.c b/ldap/servers/slapd/back-ldbm/ldbm_modrdn.c
index 3682485..ed75202 100644
--- a/ldap/servers/slapd/back-ldbm/ldbm_modrdn.c
+++ b/ldap/servers/slapd/back-ldbm/ldbm_modrdn.c
@@ -447,7 +447,7 @@ ldbm_back_modrdn( Slapi_PBlock *pb )
/* Call the Backend Pre ModRDN plugins */
slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ldap_result_code);
rc= plugin_call_plugins(pb, SLAPI_PLUGIN_BE_PRE_MODRDN_FN);
- if (rc) {
+ if (rc < 0) {
if (SLAPI_PLUGIN_NOOP == rc) {
not_an_error = 1;
rc = LDAP_SUCCESS;
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_search.c b/ldap/servers/slapd/back-ldbm/ldbm_search.c
index c4d3797..76b41d5 100644
--- a/ldap/servers/slapd/back-ldbm/ldbm_search.c
+++ b/ldap/servers/slapd/back-ldbm/ldbm_search.c
@@ -1608,7 +1608,7 @@ ldbm_back_next_search_entry_ext( Slapi_PBlock *pb, int use_extension )
* just forget about it, since we don't want to return anything at all. */
{
if ( slapi_uniqueIDCompareString(target_uniqueid, e->ep_entry->e_uniqueid) ||
- slapi_sdn_scope_test( backentry_get_sdn(e), basesdn, scope ))
+ slapi_sdn_scope_test_ext( backentry_get_sdn(e), basesdn, scope, e->ep_entry->e_flags ))
{
/* check size limit */
if ( slimit >= 0 )
diff --git a/ldap/servers/slapd/dn.c b/ldap/servers/slapd/dn.c
index bb5973a..074f0a3 100644
--- a/ldap/servers/slapd/dn.c
+++ b/ldap/servers/slapd/dn.c
@@ -2148,6 +2148,10 @@ slapi_sdn_set_rdn(Slapi_DN *sdn, const Slapi_RDN *rdn)
{
/* NewDN= NewRDN + OldParent */
char *parentdn = slapi_dn_parent(slapi_sdn_get_dn(sdn));
+ /*
+ * using slapi_ch_smprintf is okay since
+ * newdn is set to sdn as a pre-normalized dn.
+ */
char *newdn = slapi_ch_smprintf("%s,%s", rawrdn, parentdn);
slapi_ch_free((void**)&parentdn);
slapi_sdn_set_dn_passin(sdn,newdn);
@@ -2170,10 +2174,11 @@ slapi_sdn_add_rdn(Slapi_DN *sdn, const Slapi_RDN *rdn)
{
/* NewDN= NewRDN + DN */
const char *dn= slapi_sdn_get_dn(sdn);
- char *newdn= slapi_ch_malloc(strlen(rawrdn)+1+strlen(dn)+1);
- strcpy( newdn, rawrdn );
- strcat( newdn, "," );
- strcat( newdn, dn );
+ /*
+ * using slapi_ch_smprintf is okay since
+ * newdn is set to sdn as a pre-normalized dn.
+ */
+ char *newdn = slapi_ch_smprintf("%s,%s", rawrdn, dn);
slapi_sdn_set_dn_passin(sdn,newdn);
}
return sdn;
@@ -2401,7 +2406,7 @@ slapi_sdn_get_backend_parent(const Slapi_DN *sdn,Slapi_DN *sdn_parent,const Slap
void
slapi_sdn_get_rdn(const Slapi_DN *sdn,Slapi_RDN *rdn)
{
- slapi_rdn_set_dn(rdn,sdn->dn);
+ slapi_rdn_set_dn(rdn, slapi_sdn_get_dn(sdn));
}
Slapi_DN *
@@ -2572,6 +2577,47 @@ slapi_sdn_scope_test( const Slapi_DN *dn, const Slapi_DN *base, int scope )
return rc;
}
+/*
+ * Return non-zero if "dn" matches the scoping criteria
+ * given by "base" and "scope".
+ * If SLAPI_ENTRY_FLAG_TOMBSTONE is set to flags,
+ * DN without "nsuniqueid=...," is examined.
+ */
+int
+slapi_sdn_scope_test_ext( const Slapi_DN *dn, const Slapi_DN *base, int scope, int flags )
+{
+ int rc = 0;
+
+ switch ( scope ) {
+ case LDAP_SCOPE_BASE:
+ if (flags & SLAPI_ENTRY_FLAG_TOMBSTONE) {
+ Slapi_DN parent;
+ slapi_sdn_init(&parent);
+ slapi_sdn_get_parent(dn, &parent);
+ rc = ( slapi_sdn_compare( dn, &parent ) == 0 );
+ slapi_sdn_done(&parent);
+ } else {
+ rc = ( slapi_sdn_compare( dn, base ) == 0 );
+ }
+ break;
+ case LDAP_SCOPE_ONELEVEL:
+ if (flags & SLAPI_ENTRY_FLAG_TOMBSTONE) {
+ Slapi_DN parent;
+ slapi_sdn_init(&parent);
+ slapi_sdn_get_parent(dn, &parent);
+ rc = ( slapi_sdn_isparent( base, &parent ) != 0 );
+ slapi_sdn_done(&parent);
+ } else {
+ rc = ( slapi_sdn_isparent( base, dn ) != 0 );
+ }
+ break;
+ case LDAP_SCOPE_SUBTREE:
+ rc = ( slapi_sdn_issuffix( dn, base ) != 0 );
+ break;
+ }
+ return rc;
+}
+
/*
* build the new dn of an entry for moddn operations
*/
@@ -2619,8 +2665,17 @@ size_t
slapi_sdn_get_size(const Slapi_DN *sdn)
{
size_t sz = sizeof(Slapi_DN);
+ /* slapi_sdn_get_ndn_len returns the normalized dn length
+ * if dn or ndn exists. If both does not exist, it
+ * normalizes udn and set it to dn and returns the length.
+ */
sz += slapi_sdn_get_ndn_len(sdn);
- sz += strlen(sdn->dn) + 1;
+ if (sdn->dn && sdn->ndn) {
+ sz += slapi_sdn_get_ndn_len(sdn);
+ }
+ if (sdn->udn) {
+ sz += strlen(sdn->udn) + 1;
+ }
return sz;
}
diff --git a/ldap/servers/slapd/rdn.c b/ldap/servers/slapd/rdn.c
index d408f0e..fe2fae0 100644
--- a/ldap/servers/slapd/rdn.c
+++ b/ldap/servers/slapd/rdn.c
@@ -479,25 +479,17 @@ slapi_rdn_add(Slapi_RDN *rdn, const char *type, const char *value)
PR_ASSERT(NULL != value);
if(rdn->rdn==NULL)
{
- /* type=value '\0' */
- rdn->rdn= slapi_ch_malloc(strlen(type)+1+strlen(value)+1);
- strcpy( rdn->rdn, type );
- strcat( rdn->rdn, "=" );
- strcat( rdn->rdn, value );
+ /* type=value '\0' */
+ rdn->rdn = slapi_create_dn_string("%s=%s", type, value);
}
else
{
- /* type=value+rdn '\0' */
- char *newrdn= slapi_ch_malloc(strlen(type)+1+strlen(value)+1+strlen(rdn->rdn)+1);
- strcpy( newrdn, type );
- strcat( newrdn, "=" );
- strcat( newrdn, value );
- strcat( newrdn, "+" );
- strcat( newrdn, rdn->rdn );
- slapi_ch_free((void**)&rdn->rdn);
- rdn->rdn= newrdn;
- }
- slapi_unsetbit_uchar(rdn->flag,FLAG_RDNS);
+ /* type=value+rdn '\0' */
+ char *newrdn = slapi_create_dn_string("%s=%s+%s", type, value, rdn->rdn);
+ slapi_ch_free_string(&rdn->rdn);
+ rdn->rdn = newrdn;
+ }
+ slapi_unsetbit_uchar(rdn->flag,FLAG_RDNS);
return 1;
}
diff --git a/ldap/servers/slapd/slapi-plugin.h b/ldap/servers/slapd/slapi-plugin.h
index b216363..957e4ff 100644
--- a/ldap/servers/slapd/slapi-plugin.h
+++ b/ldap/servers/slapd/slapi-plugin.h
@@ -2722,6 +2722,24 @@ int slapi_sdn_get_ndn_len(const Slapi_DN *sdn);
int slapi_sdn_scope_test( const Slapi_DN *dn, const Slapi_DN *base, int scope );
/**
+ * Checks if a DN is within a specified scope under a specified base DN.
+ * This api adjusts tombstoned DN when comparing with the base dn.
+ *
+ * \param dn A pointer to the \c Slapi_DN structure to test.
+ * \param base The base DN against which \c dn is going to be tested.
+ * \param scope The scope tested. Valid scopes are:
+ * \arg \c LDAP_SCOPE_BASE
+ * \arg \c LDAP_SCOPE_ONELEVEL
+ * \arg \c LDAP_SCOPE_SUBTREE
+ * \param flags 0 or SLAPI_ENTRY_FLAG_TOMBSTONE
+ * \return non-zero if \c dn matches the scoping criteria given by \c base and \c scope.
+ * \see slapi_sdn_compare()
+ * \see slapi_sdn_isparent()
+ * \see slapi_sdn_issuffix()
+ */
+int slapi_sdn_scope_test_ext( const Slapi_DN *dn, const Slapi_DN *base, int scope, int flags );
+
+/**
* Retreives the RDN from a given DN.
*
* This function takes the DN stored in the \c Slapi_DN structure pointed to
10 years, 9 months
Branch '389-ds-base-1.3.1' - 2 commits - ldap/servers
by Noriko Hosoi
ldap/servers/plugins/automember/automember.c | 23 +-
ldap/servers/plugins/cos/cos.c | 2
ldap/servers/plugins/dna/dna.c | 18 +
ldap/servers/plugins/linkedattrs/linked_attrs.c | 34 ++-
ldap/servers/plugins/memberof/memberof.c | 16 -
ldap/servers/plugins/mep/mep.c | 41 ++--
ldap/servers/plugins/pam_passthru/pam_ptpreop.c | 12 -
ldap/servers/plugins/referint/referint.c | 52 ++---
ldap/servers/plugins/replication/repl5.h | 4
ldap/servers/plugins/replication/repl5_init.c | 11 -
ldap/servers/plugins/replication/repl5_plugins.c | 192 +++++---------------
ldap/servers/plugins/replication/urp.c | 41 ++--
ldap/servers/plugins/retrocl/retrocl_po.c | 12 -
ldap/servers/plugins/roles/roles_plugin.c | 2
ldap/servers/plugins/statechange/statechange.c | 22 +-
ldap/servers/plugins/usn/usn.c | 65 ++++---
ldap/servers/plugins/views/views.c | 35 +--
ldap/servers/slapd/add.c | 2
ldap/servers/slapd/back-ldbm/ldbm_add.c | 213 +++++++++++------------
ldap/servers/slapd/back-ldbm/ldbm_delete.c | 51 +++--
ldap/servers/slapd/back-ldbm/ldbm_entryrdn.c | 2
ldap/servers/slapd/back-ldbm/ldbm_modrdn.c | 2
ldap/servers/slapd/back-ldbm/ldbm_search.c | 2
ldap/servers/slapd/delete.c | 2
ldap/servers/slapd/dn.c | 67 ++++++-
ldap/servers/slapd/modify.c | 2
ldap/servers/slapd/modrdn.c | 2
ldap/servers/slapd/plugin.c | 20 +-
ldap/servers/slapd/rdn.c | 24 --
ldap/servers/slapd/slapi-plugin.h | 18 +
30 files changed, 507 insertions(+), 482 deletions(-)
New commits:
commit ad0a2cabe349368e0cc72155994569564ca71290
Author: Noriko Hosoi <nhosoi(a)redhat.com>
Date: Thu Jul 18 11:38:30 2013 -0700
Ticket #47367 - (phase 2) ldapdelete returns non-leaf entry error while trying to remove a leaf entry
Fix description:
1) Make sure add/modify/modrdn/delete plug-in callbacks return
SLAPI_PLUGIN_SUCCESS (==0) on SUCCESS and SLAPI_PLUGIN_FAILURE
(==-1) on FAILURE. And set error code to SLAPI_RESULT_CODE in
pblock, if any.
2) replication: eliminated multimaster_betxnpreop_* which were
used for calling urp. Urp needs to be processed at bepreop
timing.
Reviewed by Rich (Thank you!!)
https://fedorahosted.org/389/ticket/47367
(cherry picked from commit 733059713a5dfb72c844de1e3b9bc153d4ae6ccb)
diff --git a/ldap/servers/plugins/automember/automember.c b/ldap/servers/plugins/automember/automember.c
index 49f47f7..2ba3314 100644
--- a/ldap/servers/plugins/automember/automember.c
+++ b/ldap/servers/plugins/automember/automember.c
@@ -1686,7 +1686,7 @@ automember_pre_op(Slapi_PBlock * pb, int modop)
LDAPMod **mods;
int free_entry = 0;
char *errstr = NULL;
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
slapi_log_error(SLAPI_LOG_TRACE, AUTOMEMBER_PLUGIN_SUBSYSTEM,
"--> automember_pre_op\n");
@@ -1771,7 +1771,8 @@ automember_pre_op(Slapi_PBlock * pb, int modop)
"automember_pre_op: operation failure [%d]\n", ret);
slapi_send_ldap_result(pb, ret, NULL, errstr, 0, NULL);
slapi_ch_free((void **)&errstr);
- ret = -1;
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ret);
+ ret = SLAPI_PLUGIN_FAILURE;
}
slapi_log_error(SLAPI_LOG_TRACE, AUTOMEMBER_PLUGIN_SUBSYSTEM,
@@ -1822,7 +1823,7 @@ automember_mod_post_op(Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_TRACE, AUTOMEMBER_PLUGIN_SUBSYSTEM,
"<-- automember_mod_post_op\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
static int
@@ -1838,7 +1839,7 @@ automember_add_post_op(Slapi_PBlock *pb)
/* Just bail if we aren't ready to service requests yet. */
if (!g_plugin_started || !automember_oktodo(pb))
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
/* Reload config if a config entry was added. */
if ((sdn = automember_get_sdn(pb))) {
@@ -1854,7 +1855,7 @@ automember_add_post_op(Slapi_PBlock *pb)
/* If replication, just bail. */
if (automember_isrepl(pb)) {
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
/* Get the newly added entry. */
@@ -1868,7 +1869,7 @@ automember_add_post_op(Slapi_PBlock *pb)
tombstone);
slapi_value_free(&tombstone);
if (rc) {
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
/* Check if a config entry applies
@@ -1878,7 +1879,7 @@ automember_add_post_op(Slapi_PBlock *pb)
/* Bail out if the plug-in close function was just called. */
if (!g_plugin_started) {
automember_config_unlock();
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if (!PR_CLIST_IS_EMPTY(g_automember_config)) {
@@ -1907,7 +1908,7 @@ bail:
slapi_log_error(SLAPI_LOG_TRACE, AUTOMEMBER_PLUGIN_SUBSYSTEM,
"<-- automember_add_post_op\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
/*
@@ -1925,7 +1926,7 @@ automember_del_post_op(Slapi_PBlock *pb)
/* Just bail if we aren't ready to service requests yet. */
if (!g_plugin_started || !automember_oktodo(pb)) {
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
/* Reload config if a config entry was deleted. */
@@ -1941,7 +1942,7 @@ automember_del_post_op(Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_TRACE, AUTOMEMBER_PLUGIN_SUBSYSTEM,
"<-- automember_del_post_op\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
typedef struct _task_data
@@ -2193,7 +2194,7 @@ void automember_rebuild_task_thread(void *arg){
/* Does the entry meet scope and filter requirements? */
if (slapi_dn_issuffix(slapi_sdn_get_dn(td->base_dn), config->scope) &&
(slapi_filter_test_simple(entries[i], config->filter) == 0))
- {
+ {
automember_update_membership(config, entries[i], NULL);
}
list = PR_NEXT_LINK(list);
diff --git a/ldap/servers/plugins/cos/cos.c b/ldap/servers/plugins/cos/cos.c
index 0d76d99..55ff850 100644
--- a/ldap/servers/plugins/cos/cos.c
+++ b/ldap/servers/plugins/cos/cos.c
@@ -306,6 +306,6 @@ int cos_post_op( Slapi_PBlock *pb )
cos_cache_change_notify(pb);
LDAPDebug( LDAP_DEBUG_TRACE, "<-- cos_post_op\n",0,0,0);
- return 0; /* always succeed */
+ return SLAPI_PLUGIN_SUCCESS; /* always succeed */
}
diff --git a/ldap/servers/plugins/dna/dna.c b/ldap/servers/plugins/dna/dna.c
index f14da69..cec211b 100644
--- a/ldap/servers/plugins/dna/dna.c
+++ b/ldap/servers/plugins/dna/dna.c
@@ -70,8 +70,8 @@
#define DNA_DN "cn=Distributed Numeric Assignment Plugin,cn=plugins,cn=config" /* temporary */
-#define DNA_SUCCESS 0
-#define DNA_FAILURE -1
+#define DNA_SUCCESS SLAPI_PLUGIN_SUCCESS
+#define DNA_FAILURE SLAPI_PLUGIN_FAILURE
/* Default range request timeout */
/* use the default replication timeout */
@@ -2797,7 +2797,7 @@ dna_create_valcheck_filter(struct configEntry *config_entry, PRUint64 value, cha
static int
_dna_pre_op_add(Slapi_PBlock *pb, Slapi_Entry *e, char **errstr)
{
- int ret = 0;
+ int ret = DNA_SUCCESS;
PRCList *list = NULL;
struct configEntry *config_entry = NULL;
char *dn = NULL;
@@ -2976,7 +2976,7 @@ _dna_pre_op_add(Slapi_PBlock *pb, Slapi_Entry *e, char **errstr)
slapi_ch_free((void **)&types_to_generate);
}
next:
- ret = 0;
+ ret = DNA_SUCCESS;
list = PR_NEXT_LINK(list);
}
}
@@ -2993,7 +2993,7 @@ bail:
static int
_dna_pre_op_modify(Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Mods *smods, char **errstr)
{
- int ret = 0;
+ int ret = DNA_SUCCESS;
PRCList *list = NULL;
struct configEntry *config_entry = NULL;
char *dn = NULL;
@@ -3375,6 +3375,7 @@ bail:
"dna_pre_op: operation failure [%d]\n", ret);
slapi_send_ldap_result(pb, ret, NULL, errstr, 0, NULL);
slapi_ch_free((void **)&errstr);
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ret);
ret = DNA_FAILURE;
}
@@ -3440,7 +3441,7 @@ static int dna_be_txn_pre_op(Slapi_PBlock *pb, int modtype)
char *dn = NULL;
char *type = NULL;
int numvals, e_numvals = 0;
- int i, len, ret = 0;
+ int i, len, ret = DNA_SUCCESS;
slapi_log_error(SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM,
"--> dna_be_txn_pre_op\n");
@@ -3686,13 +3687,14 @@ bail:
"dna_be_txn_pre_op: operation failure [%d]\n", ret);
slapi_send_ldap_result(pb, ret, NULL, errstr, 0, NULL);
slapi_ch_free((void **)&errstr);
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ret);
ret = DNA_FAILURE;
}
slapi_log_error(SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM,
"<-- dna_be_txn_pre_op\n");
- return ret;
+ return ret;
}
static int dna_config_check_post_op(Slapi_PBlock * pb)
@@ -3713,7 +3715,7 @@ static int dna_config_check_post_op(Slapi_PBlock * pb)
slapi_log_error(SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM,
"<-- dna_config_check_post_op\n");
- return 0;
+ return DNA_SUCCESS;
}
diff --git a/ldap/servers/plugins/linkedattrs/linked_attrs.c b/ldap/servers/plugins/linkedattrs/linked_attrs.c
index 7d8370d..30a8653 100644
--- a/ldap/servers/plugins/linkedattrs/linked_attrs.c
+++ b/ldap/servers/plugins/linkedattrs/linked_attrs.c
@@ -1536,7 +1536,7 @@ linked_attrs_pre_op(Slapi_PBlock * pb, int modop)
LDAPMod **mods = NULL;
int free_entry = 0;
char *errstr = NULL;
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
slapi_log_error(SLAPI_LOG_TRACE, LINK_PLUGIN_SUBSYSTEM,
"--> linked_attrs_pre_op\n");
@@ -1603,7 +1603,8 @@ linked_attrs_pre_op(Slapi_PBlock * pb, int modop)
"linked_attrs_pre_op: operation failure [%d]\n", ret);
slapi_send_ldap_result(pb, ret, NULL, errstr, 0, NULL);
slapi_ch_free((void **)&errstr);
- ret = -1;
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ret);
+ ret = SLAPI_PLUGIN_FAILURE;
}
slapi_log_error(SLAPI_LOG_TRACE, LINK_PLUGIN_SUBSYSTEM,
@@ -1640,7 +1641,7 @@ linked_attrs_mod_post_op(Slapi_PBlock *pb)
/* Just bail if we aren't ready to service requests yet. */
if (!g_plugin_started)
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
/* We don't want to process internal modify
* operations that originate from this plugin.
@@ -1649,7 +1650,7 @@ linked_attrs_mod_post_op(Slapi_PBlock *pb)
if (caller_id == linked_attrs_get_plugin_id()) {
/* Just return without processing */
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if (linked_attrs_oktodo(pb) &&
@@ -1675,7 +1676,7 @@ linked_attrs_mod_post_op(Slapi_PBlock *pb)
/* Bail out if the plug-in close function was just called. */
if (!g_plugin_started) {
linked_attrs_unlock();
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
linked_attrs_find_config(dn, type, &config);
@@ -1729,7 +1730,7 @@ linked_attrs_mod_post_op(Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_TRACE, LINK_PLUGIN_SUBSYSTEM,
"<-- linked_attrs_mod_post_op\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
static int
@@ -1743,7 +1744,7 @@ linked_attrs_add_post_op(Slapi_PBlock *pb)
/* Just bail if we aren't ready to service requests yet. */
if (!g_plugin_started || !linked_attrs_oktodo(pb))
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
/* Reload config if a config entry was added. */
if ((dn = linked_attrs_get_dn(pb))) {
@@ -1773,7 +1774,7 @@ linked_attrs_add_post_op(Slapi_PBlock *pb)
/* Bail out if the plug-in close function was just called. */
if (!g_plugin_started) {
linked_attrs_unlock();
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
linked_attrs_find_config(dn, type, &config);
@@ -1808,7 +1809,7 @@ linked_attrs_add_post_op(Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_TRACE, LINK_PLUGIN_SUBSYSTEM,
"<-- linked_attrs_add_post_op\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
static int
@@ -1822,7 +1823,7 @@ linked_attrs_del_post_op(Slapi_PBlock *pb)
/* Just bail if we aren't ready to service requests yet. */
if (!g_plugin_started || !linked_attrs_oktodo(pb))
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
/* Reload config if a config entry was deleted. */
if ((dn = linked_attrs_get_dn(pb))) {
@@ -1852,7 +1853,7 @@ linked_attrs_del_post_op(Slapi_PBlock *pb)
/* Bail out if the plug-in close function was just called. */
if (!g_plugin_started) {
linked_attrs_unlock();
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
linked_attrs_find_config(dn, type, &config);
@@ -1920,7 +1921,7 @@ linked_attrs_del_post_op(Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_TRACE, LINK_PLUGIN_SUBSYSTEM,
"<-- linked_attrs_del_post_op\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
static int
@@ -1932,7 +1933,7 @@ linked_attrs_modrdn_post_op(Slapi_PBlock *pb)
Slapi_Attr *attr = NULL;
char *type = NULL;
struct configEntry *config = NULL;
- int rc = 0;
+ int rc = SLAPI_PLUGIN_SUCCESS;
slapi_log_error(SLAPI_LOG_TRACE, LINK_PLUGIN_SUBSYSTEM,
"--> linked_attrs_modrdn_post_op\n");
@@ -1978,7 +1979,7 @@ linked_attrs_modrdn_post_op(Slapi_PBlock *pb)
/* Bail out if the plug-in close function was just called. */
if (!g_plugin_started) {
linked_attrs_unlock();
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
linked_attrs_find_config(old_dn, type, &config);
@@ -2069,7 +2070,10 @@ linked_attrs_modrdn_post_op(Slapi_PBlock *pb)
done:
slapi_log_error(SLAPI_LOG_TRACE, LINK_PLUGIN_SUBSYSTEM,
"<-- linked_attrs_modrdn_post_op\n");
-
+ if (rc) {
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &rc);
+ rc = SLAPI_PLUGIN_FAILURE;
+ }
return rc;
}
diff --git a/ldap/servers/plugins/memberof/memberof.c b/ldap/servers/plugins/memberof/memberof.c
index e362cab..5aa22fd 100644
--- a/ldap/servers/plugins/memberof/memberof.c
+++ b/ldap/servers/plugins/memberof/memberof.c
@@ -380,7 +380,7 @@ int memberof_postop_close(Slapi_PBlock *pb)
*/
int memberof_postop_del(Slapi_PBlock *pb)
{
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
MemberOfConfig configCopy = {0, 0, 0, 0};
Slapi_DN *sdn;
void *caller_id = NULL;
@@ -393,7 +393,7 @@ int memberof_postop_del(Slapi_PBlock *pb)
slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &caller_id);
if (caller_id == memberof_get_plugin_id()) {
/* Just return without processing */
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if(memberof_oktodo(pb) && (sdn = memberof_getsdn(pb)))
@@ -626,7 +626,7 @@ int memberof_call_foreach_dn(Slapi_PBlock *pb, Slapi_DN *sdn,
*/
int memberof_postop_modrdn(Slapi_PBlock *pb)
{
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
void *caller_id = NULL;
slapi_log_error( SLAPI_LOG_TRACE, MEMBEROF_PLUGIN_SUBSYSTEM,
@@ -637,7 +637,7 @@ int memberof_postop_modrdn(Slapi_PBlock *pb)
slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &caller_id);
if (caller_id == memberof_get_plugin_id()) {
/* Just return without processing */
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if(memberof_oktodo(pb))
@@ -801,7 +801,7 @@ int memberof_replace_dn_type_callback(Slapi_Entry *e, void *callback_data)
*/
int memberof_postop_modify(Slapi_PBlock *pb)
{
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
Slapi_DN *sdn = NULL;
Slapi_Mods *smods = 0;
Slapi_Mod *smod = 0;
@@ -817,7 +817,7 @@ int memberof_postop_modify(Slapi_PBlock *pb)
slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &caller_id);
if (caller_id == memberof_get_plugin_id()) {
/* Just return without processing */
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if(memberof_oktodo(pb) && (sdn = memberof_getsdn(pb)))
@@ -945,7 +945,7 @@ int memberof_postop_modify(Slapi_PBlock *pb)
*/
int memberof_postop_add(Slapi_PBlock *pb)
{
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
int interested = 0;
Slapi_DN *sdn = 0;
void *caller_id = NULL;
@@ -958,7 +958,7 @@ int memberof_postop_add(Slapi_PBlock *pb)
slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &caller_id);
if (caller_id == memberof_get_plugin_id()) {
/* Just return without processing */
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if(memberof_oktodo(pb) && (sdn = memberof_getsdn(pb)))
diff --git a/ldap/servers/plugins/mep/mep.c b/ldap/servers/plugins/mep/mep.c
index f8e3c2b..58345e0 100644
--- a/ldap/servers/plugins/mep/mep.c
+++ b/ldap/servers/plugins/mep/mep.c
@@ -1984,7 +1984,7 @@ mep_pre_op(Slapi_PBlock * pb, int modop)
char *errstr = NULL;
struct configEntry *config = NULL;
void *caller_id = NULL;
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
slapi_log_error(SLAPI_LOG_TRACE, MEP_PLUGIN_SUBSYSTEM,
"--> mep_pre_op\n");
@@ -2259,7 +2259,8 @@ mep_pre_op(Slapi_PBlock * pb, int modop)
"mep_pre_op: operation failure [%d]\n", ret);
slapi_send_ldap_result(pb, ret, NULL, errstr, 0, NULL);
slapi_ch_free((void **)&errstr);
- ret = -1;
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ret);
+ ret = SLAPI_PLUGIN_FAILURE;
}
slapi_log_error(SLAPI_LOG_TRACE, MEP_PLUGIN_SUBSYSTEM,
@@ -2313,7 +2314,7 @@ mep_mod_post_op(Slapi_PBlock *pb)
/* Just bail if we aren't ready to service requests yet. */
if (!g_plugin_started)
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
if (mep_oktodo(pb) && (sdn = mep_get_sdn(pb))) {
/* First check if the config or a template is being modified. */
@@ -2430,7 +2431,7 @@ mep_mod_post_op(Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_TRACE, MEP_PLUGIN_SUBSYSTEM,
"<-- mep_mod_post_op\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
static int
@@ -2445,7 +2446,7 @@ mep_add_post_op(Slapi_PBlock *pb)
/* Just bail if we aren't ready to service requests yet. */
if (!g_plugin_started || !mep_oktodo(pb))
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
/* Reload config if a config entry was added. */
if ((sdn = mep_get_sdn(pb))) {
@@ -2460,7 +2461,7 @@ mep_add_post_op(Slapi_PBlock *pb)
/* If replication, just bail. */
if (mep_isrepl(pb)) {
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
/* Get the newly added entry. */
@@ -2469,7 +2470,7 @@ mep_add_post_op(Slapi_PBlock *pb)
if (e) {
/* If the entry is a tombstone, just bail. */
if (mep_has_tombstone_value(e)) {
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
/* Check if a config entry applies
@@ -2479,7 +2480,7 @@ mep_add_post_op(Slapi_PBlock *pb)
/* Bail out if the plug-in close function was just called. */
if (!g_plugin_started) {
mep_config_unlock();
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
mep_find_config(e, &config);
@@ -2497,7 +2498,7 @@ mep_add_post_op(Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_TRACE, MEP_PLUGIN_SUBSYSTEM,
"<-- mep_add_post_op\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
static int
@@ -2511,7 +2512,7 @@ mep_del_post_op(Slapi_PBlock *pb)
/* Just bail if we aren't ready to service requests yet. */
if (!g_plugin_started || !mep_oktodo(pb)) {
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
/* Reload config if a config entry was deleted. */
@@ -2526,7 +2527,7 @@ mep_del_post_op(Slapi_PBlock *pb)
/* If replication, just bail. */
if (mep_isrepl(pb)) {
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
/* Get deleted entry, then go through types to find config. */
@@ -2537,7 +2538,7 @@ mep_del_post_op(Slapi_PBlock *pb)
/* If the entry is a tombstone, just bail. */
if (mep_has_tombstone_value(e)) {
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
/* See if we're an origin entry . */
@@ -2566,7 +2567,7 @@ mep_del_post_op(Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_TRACE, MEP_PLUGIN_SUBSYSTEM,
"<-- mep_del_post_op\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
static int
@@ -2584,7 +2585,7 @@ mep_modrdn_post_op(Slapi_PBlock *pb)
/* Just bail if we aren't ready to service requests yet. */
if (!g_plugin_started || !mep_oktodo(pb))
- return 0;;
+ return SLAPI_PLUGIN_SUCCESS;;
/* Reload config if an existing config entry was renamed,
* or if the new dn brings an entry into the scope of the
@@ -2597,7 +2598,7 @@ mep_modrdn_post_op(Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_PLUGIN, MEP_PLUGIN_SUBSYSTEM,
"mep_modrdn_post_op: Error "
"retrieving post-op entry\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if ((old_sdn = mep_get_sdn(pb))) {
@@ -2611,12 +2612,12 @@ mep_modrdn_post_op(Slapi_PBlock *pb)
/* If replication, just bail. */
if (mep_isrepl(pb)) {
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
/* If the entry is a tombstone, just bail. */
if (mep_has_tombstone_value(post_e)) {
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
/* See if we're an origin entry . */
@@ -2638,7 +2639,7 @@ mep_modrdn_post_op(Slapi_PBlock *pb)
if (!g_plugin_started) {
mep_config_unlock();
slapi_pblock_destroy(mep_pb);
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
mep_find_config(post_e, &config);
@@ -2809,7 +2810,7 @@ bailmod:
/* Bail out if the plug-in close function was just called. */
if (!g_plugin_started) {
mep_config_unlock();
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
mep_find_config(post_e, &config);
@@ -2823,7 +2824,7 @@ bailmod:
slapi_log_error(SLAPI_LOG_TRACE, MEP_PLUGIN_SUBSYSTEM,
"<-- mep_modrdn_post_op\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
static int
diff --git a/ldap/servers/plugins/pam_passthru/pam_ptpreop.c b/ldap/servers/plugins/pam_passthru/pam_ptpreop.c
index 7d9ff8b..abf93e3 100644
--- a/ldap/servers/plugins/pam_passthru/pam_ptpreop.c
+++ b/ldap/servers/plugins/pam_passthru/pam_ptpreop.c
@@ -229,7 +229,7 @@ pam_passthruauth_init( Slapi_PBlock *pb )
slapi_log_error( SLAPI_LOG_TRACE, PAM_PASSTHRU_PLUGIN_SUBSYSTEM,
"<= pam_passthruauth_init\n" );
- bail:
+bail:
return status;
}
@@ -574,7 +574,7 @@ pam_passthru_preop(Slapi_PBlock *pb, int modtype)
Slapi_Entry *e = NULL;
LDAPMod **mods;
char returntext[SLAPI_DSE_RETURNTEXT_SIZE];
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
slapi_log_error(SLAPI_LOG_TRACE, PAM_PASSTHRU_PLUGIN_SUBSYSTEM,
"=> pam_passthru_preop\n");
@@ -640,11 +640,11 @@ pam_passthru_preop(Slapi_PBlock *pb, int modtype)
}
- bail:
+bail:
/* If we are refusing the operation, return the result to the client. */
if (ret) {
slapi_send_ldap_result(pb, ret, NULL, returntext, 0, NULL);
- ret = -1;
+ ret = SLAPI_PLUGIN_FAILURE;
}
slapi_log_error(SLAPI_LOG_TRACE, PAM_PASSTHRU_PLUGIN_SUBSYSTEM,
@@ -683,7 +683,7 @@ pam_passthru_modrdn_preop(Slapi_PBlock *pb)
static int
pam_passthru_postop(Slapi_PBlock *pb)
{
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
Slapi_DN *sdn = NULL;
Slapi_DN *new_sdn = NULL;
Slapi_Entry *e = NULL;
@@ -737,7 +737,7 @@ pam_passthru_postop(Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_TRACE, PAM_PASSTHRU_PLUGIN_SUBSYSTEM,
"<= pam_passthru_postop\n");
- bail:
+bail:
return ret;
}
diff --git a/ldap/servers/plugins/referint/referint.c b/ldap/servers/plugins/referint/referint.c
index 234c322..d31f53c 100644
--- a/ldap/servers/plugins/referint/referint.c
+++ b/ldap/servers/plugins/referint/referint.c
@@ -194,7 +194,7 @@ referint_postop_del( Slapi_PBlock *pb )
if (0 == refint_started) {
/* not initialized yet */
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if ( slapi_pblock_get( pb, SLAPI_IS_REPLICATED_OPERATION, &isrepop ) != 0 ||
@@ -203,33 +203,33 @@ referint_postop_del( Slapi_PBlock *pb )
{
slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
"referint_postop_del: could not get parameters\n" );
- return( -1 );
+ return SLAPI_PLUGIN_FAILURE;
}
/*
* This plugin should only execute if the delete was successful
* and this is not a replicated op(unless its allowed)
*/
if(oprc != 0 || (isrepop && !allow_repl)){
- return( 0 );
+ return SLAPI_PLUGIN_SUCCESS;
}
/* get the args */
if ( slapi_pblock_get( pb, SLAPI_PLUGIN_ARGC, &argc ) != 0) {
slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
"referint_postop failed to get argc\n" );
- return( -1 );
+ return SLAPI_PLUGIN_FAILURE;
}
if ( slapi_pblock_get( pb, SLAPI_PLUGIN_ARGV, &argv ) != 0) {
slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
"referint_postop failed to get argv\n" );
- return( -1 );
+ return SLAPI_PLUGIN_FAILURE;
}
-
+
if(argv == NULL){
slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
"referint_postop_del, args are NULL\n" );
- return( -1 );
+ return SLAPI_PLUGIN_FAILURE;
}
-
+
if (argc >= 3) {
/* argv[0] will be the delay */
delay = atoi(argv[0]);
@@ -239,19 +239,19 @@ referint_postop_del( Slapi_PBlock *pb )
if(delay == -1){
/* integrity updating is off */
- rc = 0;
+ rc = SLAPI_PLUGIN_SUCCESS;
} else if(delay == 0){ /* no delay */
/* call function to update references to entry */
rc = update_integrity(argv, sdn, NULL, NULL, logChanges);
} else {
/* write the entry to integrity log */
writeintegritylog(pb, argv[1], sdn, NULL, NULL, NULL /* slapi_get_requestor_sdn(pb) */);
- rc = 0;
+ rc = SLAPI_PLUGIN_SUCCESS;
}
} else {
slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
"referint_postop insufficient arguments supplied\n" );
- return( -1 );
+ return SLAPI_PLUGIN_FAILURE;
}
return( rc );
@@ -279,30 +279,30 @@ referint_postop_modrdn( Slapi_PBlock *pb )
{
slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
"referint_postop_modrdn: could not get parameters\n" );
- return( -1 );
+ return SLAPI_PLUGIN_FAILURE;
}
/*
* This plugin should only execute if the delete was successful
* and this is not a replicated op (unless its allowed)
*/
if(oprc != 0 || (isrepop && !allow_repl)){
- return( 0 );
+ return SLAPI_PLUGIN_SUCCESS;
}
/* get the args */
if ( slapi_pblock_get( pb, SLAPI_PLUGIN_ARGC, &argc ) != 0) {
slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
"referint_postop failed to get argv\n" );
- return( -1 );
+ return SLAPI_PLUGIN_FAILURE;
}
if ( slapi_pblock_get( pb, SLAPI_PLUGIN_ARGV, &argv ) != 0) {
slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
"referint_postop failed to get argv\n" );
- return( -1 );
+ return SLAPI_PLUGIN_FAILURE;
}
if(argv == NULL){
slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
"referint_postop_modrdn, args are NULL\n" );
- return( -1 );
+ return SLAPI_PLUGIN_FAILURE;
}
if (argc >= 3) {
@@ -314,19 +314,19 @@ referint_postop_modrdn( Slapi_PBlock *pb )
} else {
slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
"referint_postop_modrdn insufficient arguments supplied\n" );
- return( -1 );
+ return SLAPI_PLUGIN_FAILURE;
}
if(delay == -1){
/* integrity updating is off */
- rc = 0;
+ rc = SLAPI_PLUGIN_SUCCESS;
} else if(delay == 0){ /* no delay */
/* call function to update references to entry */
rc = update_integrity(argv, sdn, newrdn, newsuperior, logChanges);
} else {
/* write the entry to integrity log */
writeintegritylog(pb, argv[1], sdn, newrdn, newsuperior, NULL /* slapi_get_requestor_sdn(pb) */);
- rc = 0;
+ rc = SLAPI_PLUGIN_SUCCESS;
}
return( rc );
@@ -720,12 +720,12 @@ update_integrity(char **argv, Slapi_DN *origSDN,
int search_result;
int nval = 0;
int i, j;
- int rc;
+ int rc = SLAPI_PLUGIN_SUCCESS;
if ( argv == NULL ){
slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
"referint_postop required config file arguments missing\n" );
- rc = -1;
+ rc = SLAPI_PLUGIN_FAILURE;
goto free_and_return;
}
/*
@@ -818,7 +818,7 @@ update_integrity(char **argv, Slapi_DN *origSDN,
slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
"update_integrity search (base=%s filter=%s) returned "
"error %d\n", search_base, filter, search_result);
- rc = -1;
+ rc = SLAPI_PLUGIN_FAILURE;
goto free_and_return;
}
}
@@ -828,7 +828,7 @@ update_integrity(char **argv, Slapi_DN *origSDN,
}
}
/* if got here, then everything good rc = 0 */
- rc = 0;
+ rc = SLAPI_PLUGIN_SUCCESS;
free_and_return:
/* free filter and search_results_pb */
@@ -878,7 +878,7 @@ int referint_postop_start( Slapi_PBlock *pb)
keeprunning_mutex = PR_NewLock();
keeprunning_cv = PR_NewCondVar(keeprunning_mutex);
keeprunning =1;
-
+
referint_tid = PR_CreateThread (PR_USER_THREAD,
referint_thread_func,
(void *)argv,
@@ -1075,7 +1075,7 @@ int my_fgetc(PRFileDesc *stream)
}
return retval;
-}
+}
int
GetNextLine(char *dest, int size_dest, PRFileDesc *stream) {
@@ -1083,7 +1083,7 @@ GetNextLine(char *dest, int size_dest, PRFileDesc *stream) {
char nextchar ='\0';
int done = 0;
int i = 0;
-
+
while(!done){
if( ( nextchar = my_fgetc(stream) ) != 0){
if( i < (size_dest - 1) ){
diff --git a/ldap/servers/plugins/replication/repl5.h b/ldap/servers/plugins/replication/repl5.h
index 465d072..6752ac8 100644
--- a/ldap/servers/plugins/replication/repl5.h
+++ b/ldap/servers/plugins/replication/repl5.h
@@ -216,10 +216,6 @@ int multimaster_bepreop_add (Slapi_PBlock *pb);
int multimaster_bepreop_delete (Slapi_PBlock *pb);
int multimaster_bepreop_modify (Slapi_PBlock *pb);
int multimaster_bepreop_modrdn (Slapi_PBlock *pb);
-int multimaster_betxnpreop_add (Slapi_PBlock *pb);
-int multimaster_betxnpreop_delete (Slapi_PBlock *pb);
-int multimaster_betxnpreop_modify (Slapi_PBlock *pb);
-int multimaster_betxnpreop_modrdn (Slapi_PBlock *pb);
int replica_ruv_smods_for_op (Slapi_PBlock *pb, char **uniqueid,
Slapi_Mods **smods);
int multimaster_bepostop_modrdn (Slapi_PBlock *pb);
diff --git a/ldap/servers/plugins/replication/repl5_plugins.c b/ldap/servers/plugins/replication/repl5_plugins.c
index 590af7e..7bd24d7 100644
--- a/ldap/servers/plugins/replication/repl5_plugins.c
+++ b/ldap/servers/plugins/replication/repl5_plugins.c
@@ -190,13 +190,13 @@ multimaster_preop_add (Slapi_PBlock *pb)
copy_operation_parameters(pb);
slapi_operation_set_csngen_handler(op,
(void*)replica_generate_next_csn);
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if (!is_mmr_replica (pb))
{
copy_operation_parameters(pb);
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
is_replicated_operation= operation_is_flag_set(op,OP_FLAG_REPLICATED);
@@ -241,7 +241,7 @@ multimaster_preop_add (Slapi_PBlock *pb)
slapi_ch_free ((void**)&target_uuid);
slapi_ch_free ((void**)&superior_uuid);
- return -1;
+ return SLAPI_PLUGIN_FAILURE;
}
operation_set_csn(op, csn);
@@ -296,7 +296,7 @@ multimaster_preop_add (Slapi_PBlock *pb)
copy_operation_parameters(pb);
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
int
@@ -320,13 +320,13 @@ multimaster_preop_delete (Slapi_PBlock *pb)
slapi_operation_set_replica_attr_handler ( op, (void*)replica_get_attr );
slapi_operation_set_csngen_handler(op,
(void*)replica_generate_next_csn);
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if (!is_mmr_replica (pb))
{
copy_operation_parameters(pb);
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
is_replicated_operation= operation_is_flag_set(op,OP_FLAG_REPLICATED);
@@ -366,7 +366,7 @@ multimaster_preop_delete (Slapi_PBlock *pb)
csn_free (&csn);
slapi_ch_free ((void**)&target_uuid);
- return -1;
+ return SLAPI_PLUGIN_FAILURE;
}
/*
@@ -396,7 +396,7 @@ multimaster_preop_delete (Slapi_PBlock *pb)
copy_operation_parameters(pb);
slapi_operation_set_replica_attr_handler ( op, (void*)replica_get_attr );
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
int
@@ -419,13 +419,13 @@ multimaster_preop_modify (Slapi_PBlock *pb)
copy_operation_parameters(pb);
slapi_operation_set_csngen_handler(op,
(void*)replica_generate_next_csn);
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if (!is_mmr_replica (pb))
{
copy_operation_parameters(pb);
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
is_replicated_operation= operation_is_flag_set(op,OP_FLAG_REPLICATED);
@@ -465,7 +465,7 @@ multimaster_preop_modify (Slapi_PBlock *pb)
csn_free (&csn);
slapi_ch_free ((void**)&target_uuid);
- return -1;
+ return SLAPI_PLUGIN_FAILURE;
}
/*
@@ -498,7 +498,7 @@ multimaster_preop_modify (Slapi_PBlock *pb)
}
copy_operation_parameters(pb);
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
int
@@ -521,13 +521,13 @@ multimaster_preop_modrdn (Slapi_PBlock *pb)
copy_operation_parameters(pb);
slapi_operation_set_csngen_handler(op,
(void*)replica_generate_next_csn);
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if (!is_mmr_replica (pb))
{
copy_operation_parameters(pb);
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
is_replicated_operation= operation_is_flag_set(op,OP_FLAG_REPLICATED);
@@ -577,7 +577,7 @@ multimaster_preop_modrdn (Slapi_PBlock *pb)
slapi_ch_free ((void**)&newsuperior_uuid);
ldap_mods_free (modrdn_mods, 1);
- return -1;
+ return SLAPI_PLUGIN_FAILURE;
}
operation_set_csn(op, csn);
@@ -625,19 +625,19 @@ multimaster_preop_modrdn (Slapi_PBlock *pb)
copy_operation_parameters(pb);
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
int
multimaster_preop_search (Slapi_PBlock *pb)
{
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
int
multimaster_preop_compare (Slapi_PBlock *pb)
{
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
static void
@@ -704,7 +704,7 @@ purge_entry_state_information (Slapi_PBlock *pb)
int
multimaster_bepreop_add (Slapi_PBlock *pb)
{
- int rc= 0;
+ int rc= SLAPI_PLUGIN_SUCCESS;
Slapi_Operation *op;
int is_replicated_operation;
int is_fixup_operation;
@@ -729,7 +729,7 @@ multimaster_bepreop_add (Slapi_PBlock *pb)
int
multimaster_bepreop_delete (Slapi_PBlock *pb)
{
- int rc= 0;
+ int rc= SLAPI_PLUGIN_SUCCESS;
Slapi_Operation *op;
int is_replicated_operation;
int is_fixup_operation;
@@ -754,7 +754,7 @@ multimaster_bepreop_delete (Slapi_PBlock *pb)
int
multimaster_bepreop_modify (Slapi_PBlock *pb)
{
- int rc= 0;
+ int rc= SLAPI_PLUGIN_SUCCESS;
Slapi_Operation *op;
int is_replicated_operation;
int is_fixup_operation;
@@ -782,7 +782,7 @@ multimaster_bepreop_modify (Slapi_PBlock *pb)
int
multimaster_bepreop_modrdn (Slapi_PBlock *pb)
{
- int rc= 0;
+ int rc= SLAPI_PLUGIN_SUCCESS;
Slapi_Operation *op;
int is_replicated_operation;
int is_fixup_operation;
@@ -807,99 +807,6 @@ multimaster_bepreop_modrdn (Slapi_PBlock *pb)
return rc;
}
-/* betxn preop's */
-int
-multimaster_betxnpreop_add (Slapi_PBlock *pb)
-{
- int rc= 0;
- Slapi_Operation *op;
- int is_replicated_operation;
- int is_fixup_operation;
-
- slapi_pblock_get(pb, SLAPI_OPERATION, &op);
- is_replicated_operation= operation_is_flag_set(op,OP_FLAG_REPLICATED);
- is_fixup_operation= operation_is_flag_set(op,OP_FLAG_REPL_FIXUP);
-
- /* For replicated operations, apply URP algorithm */
- if (!is_fixup_operation)
- {
- if (is_replicated_operation) {
- rc = urp_add_operation(pb);
- }
- }
-
- return rc;
-}
-
-int
-multimaster_betxnpreop_delete (Slapi_PBlock *pb)
-{
- int rc= 0;
- Slapi_Operation *op;
- int is_replicated_operation;
- int is_fixup_operation;
-
- slapi_pblock_get(pb, SLAPI_OPERATION, &op);
- is_replicated_operation= operation_is_flag_set(op,OP_FLAG_REPLICATED);
- is_fixup_operation= operation_is_flag_set(op,OP_FLAG_REPL_FIXUP);
-
- /* For replicated operations, apply URP algorithm */
- if(!is_fixup_operation)
- {
- if (is_replicated_operation) {
- rc = urp_delete_operation(pb);
- }
- }
-
- return rc;
-}
-
-int
-multimaster_betxnpreop_modify (Slapi_PBlock *pb)
-{
- int rc= 0;
- Slapi_Operation *op;
- int is_replicated_operation;
- int is_fixup_operation;
-
- slapi_pblock_get(pb, SLAPI_OPERATION, &op);
- is_replicated_operation= operation_is_flag_set(op,OP_FLAG_REPLICATED);
- is_fixup_operation= operation_is_flag_set(op,OP_FLAG_REPL_FIXUP);
-
- /* For replicated operations, apply URP algorithm */
- if(!is_fixup_operation)
- {
- if (is_replicated_operation) {
- rc = urp_modify_operation(pb);
- }
- }
-
- return rc;
-}
-
-int
-multimaster_betxnpreop_modrdn (Slapi_PBlock *pb)
-{
- int rc= 0;
- Slapi_Operation *op;
- int is_replicated_operation;
- int is_fixup_operation;
-
- slapi_pblock_get(pb, SLAPI_OPERATION, &op);
- is_replicated_operation= operation_is_flag_set(op,OP_FLAG_REPLICATED);
- is_fixup_operation= operation_is_flag_set(op,OP_FLAG_REPL_FIXUP);
-
- /* For replicated operations, apply URP algorithm */
- if(!is_fixup_operation)
- {
- if (is_replicated_operation) {
- rc = urp_modrdn_operation(pb);
- }
- }
-
- return rc;
-}
-
int
multimaster_bepostop_modrdn (Slapi_PBlock *pb)
{
@@ -910,7 +817,7 @@ multimaster_bepostop_modrdn (Slapi_PBlock *pb)
{
urp_post_modrdn_operation (pb);
}
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
int
@@ -923,14 +830,14 @@ multimaster_bepostop_delete (Slapi_PBlock *pb)
{
urp_post_delete_operation (pb);
}
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
/* postop - write to changelog */
int
multimaster_postop_bind (Slapi_PBlock *pb)
{
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
int
@@ -985,7 +892,7 @@ multimaster_betxnpostop_modify (Slapi_PBlock *pb)
int
multimaster_be_betxnpostop_delete (Slapi_PBlock *pb)
{
- int rc = 0;
+ int rc = SLAPI_PLUGIN_SUCCESS;
/* original betxnpost */
rc = write_changelog_and_ruv(pb);
/* original bepost */
@@ -1119,7 +1026,7 @@ write_changelog_and_ruv (Slapi_PBlock *pb)
int rc;
slapi_operation_parameters *op_params = NULL;
Object *repl_obj;
- int return_value = 0;
+ int return_value = SLAPI_PLUGIN_SUCCESS;
Replica *r;
Slapi_Backend *be;
int is_replicated_operation = 0;
@@ -1129,7 +1036,7 @@ write_changelog_and_ruv (Slapi_PBlock *pb)
if ((operation_is_flag_set(op, OP_FLAG_REPL_FIXUP)) ||
(operation_is_flag_set(op, OP_FLAG_TOMBSTONE_ENTRY)))
{
- return 0;
+ return return_value;
}
/* ignore operations intended for chaining backends - they will be
@@ -1141,18 +1048,18 @@ write_changelog_and_ruv (Slapi_PBlock *pb)
if (!is_replicated_operation &&
slapi_be_is_flag_set(be,SLAPI_BE_FLAG_REMOTE_DATA))
{
- return 0;
+ return return_value;
}
slapi_pblock_get(pb, SLAPI_RESULT_CODE, &rc);
if (rc) { /* op failed - just return */
- return 0;
+ return return_value;
}
/* we only log changes for operations applied to a replica */
repl_obj = replica_get_replica_for_op (pb);
if (repl_obj == NULL)
- return 0;
+ return return_value;
r = (Replica*)object_get_data (repl_obj);
PR_ASSERT (r);
@@ -1214,7 +1121,7 @@ write_changelog_and_ruv (Slapi_PBlock *pb)
if( op_params->csn && is_cleaned_rid(csn_get_replicaid(op_params->csn))){
/* this RID has been cleaned */
object_release (repl_obj);
- return 0;
+ return return_value;
}
/* we might have stripped all the mods - in that case we do not
@@ -1227,7 +1134,7 @@ write_changelog_and_ruv (Slapi_PBlock *pb)
{
slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
"write_changelog_and_ruv: Skipped due to DISKFULL\n");
- return 0;
+ return return_value;
}
slapi_pblock_get(pb, SLAPI_TXN, &txn);
rc = cl5WriteOperationTxn(repl_name, repl_gen, op_params,
@@ -1243,7 +1150,7 @@ write_changelog_and_ruv (Slapi_PBlock *pb)
op_params->target_address.uniqueid,
op_params->operation_type,
csn_as_string(op_params->csn, PR_FALSE, csn_str));
- return_value = 1;
+ return_value = SLAPI_PLUGIN_FAILURE;
}
}
@@ -1313,7 +1220,7 @@ process_postop (Slapi_PBlock *pb)
if ((operation_is_flag_set(op, OP_FLAG_REPL_FIXUP)) ||
(operation_is_flag_set(op, OP_FLAG_TOMBSTONE_ENTRY)))
{
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
/* ignore operations intended for chaining backends - they will be
@@ -1325,24 +1232,27 @@ process_postop (Slapi_PBlock *pb)
if (!is_replicated_operation &&
slapi_be_is_flag_set(be,SLAPI_BE_FLAG_REMOTE_DATA))
{
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
get_repl_session_id (pb, sessionid, &opcsn);
- slapi_pblock_get(pb, SLAPI_RESULT_CODE, &rc);
+ slapi_pblock_get(pb, SLAPI_RESULT_CODE, &rc);
if (rc == LDAP_SUCCESS)
{
- agmtlist_notify_all(pb);
+ agmtlist_notify_all(pb);
+ rc = SLAPI_PLUGIN_SUCCESS;
}
- else if (opcsn)
+ else if (opcsn)
{
- rc = cancel_opcsn (pb);
+ rc = cancel_opcsn (pb);
/* Don't try to get session id since conn is always null */
slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name,
"%s process postop: canceling operation csn\n", sessionid);
- }
+ } else {
+ rc = SLAPI_PLUGIN_FAILURE;
+ }
/* the target unique id is set in the modify_preop above, so
we need to free it */
@@ -1436,7 +1346,7 @@ cancel_opcsn (Slapi_PBlock *pb)
object_release (repl_obj);
}
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
diff --git a/ldap/servers/plugins/retrocl/retrocl_po.c b/ldap/servers/plugins/retrocl/retrocl_po.c
index c3d1c41..382c98a 100644
--- a/ldap/servers/plugins/retrocl/retrocl_po.c
+++ b/ldap/servers/plugins/retrocl/retrocl_po.c
@@ -581,24 +581,24 @@ int retrocl_postob (Slapi_PBlock *pb,int optype)
if (slapi_be_logchanges(be) == 0) {
LDAPDebug0Args(LDAP_DEBUG_TRACE,"not applying change if not logging\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if (retrocl_be_changelog == NULL || be == retrocl_be_changelog) {
LDAPDebug0Args(LDAP_DEBUG_TRACE,"not applying change if no/cl be\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
slapi_pblock_get(pb, SLAPI_RESULT_CODE, &rc);
if (rc != LDAP_SUCCESS) {
LDAPDebug1Arg(LDAP_DEBUG_TRACE,"not applying change if op failed %d\n",rc);
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if (slapi_op_abandoned(pb)) {
LDAPDebug0Args(LDAP_DEBUG_PLUGIN,"not applying change if op abandoned\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
curtime = current_time();
@@ -613,12 +613,12 @@ int retrocl_postob (Slapi_PBlock *pb,int optype)
if (op == NULL) {
LDAPDebug0Args(LDAP_DEBUG_TRACE,"not applying change if no op\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if (operation_is_flag_set(op, OP_FLAG_TOMBSTONE_ENTRY)){
LDAPDebug0Args(LDAP_DEBUG_TRACE,"not applying change for nsTombstone entries\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
switch ( optype ) {
diff --git a/ldap/servers/plugins/roles/roles_plugin.c b/ldap/servers/plugins/roles/roles_plugin.c
index 9db76ca..b00e9a7 100644
--- a/ldap/servers/plugins/roles/roles_plugin.c
+++ b/ldap/servers/plugins/roles/roles_plugin.c
@@ -355,7 +355,7 @@ static int roles_post_op( Slapi_PBlock *pb )
roles_cache_change_notify(pb);
slapi_log_error( SLAPI_LOG_PLUGIN, ROLES_PLUGIN_SUBSYSTEM, "<-- roles_post_op\n");
- return 0; /* always succeed */
+ return SLAPI_PLUGIN_SUCCESS; /* always succeed */
}
static void roles_set_plugin_identity(void * identity)
diff --git a/ldap/servers/plugins/statechange/statechange.c b/ldap/servers/plugins/statechange/statechange.c
index 0b2b737..307ea75 100644
--- a/ldap/servers/plugins/statechange/statechange.c
+++ b/ldap/servers/plugins/statechange/statechange.c
@@ -110,7 +110,7 @@ void plugin_init_debug_level(int *level_ptr)
*/
int statechange_init( Slapi_PBlock *pb )
{
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
Slapi_Entry *plugin_entry = NULL;
char *plugin_type = NULL;
int postadd = SLAPI_PLUGIN_POST_ADD_FN;
@@ -148,7 +148,7 @@ int statechange_init( Slapi_PBlock *pb )
{
slapi_log_error( SLAPI_LOG_FATAL, SCN_PLUGIN_SUBSYSTEM,
"statechange_init: failed to register plugin\n" );
- ret = -1;
+ ret = SLAPI_PLUGIN_FAILURE;
}
slapi_log_error( SLAPI_LOG_TRACE, SCN_PLUGIN_SUBSYSTEM, "<-- statechange_init\n");
@@ -163,7 +163,7 @@ int statechange_init( Slapi_PBlock *pb )
*/
static int statechange_start( Slapi_PBlock *pb )
{
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
slapi_log_error( SLAPI_LOG_TRACE, SCN_PLUGIN_SUBSYSTEM, "--> statechange_start\n");
@@ -177,14 +177,14 @@ static int statechange_start( Slapi_PBlock *pb )
{
/* badness */
slapi_log_error( SLAPI_LOG_FATAL, SCN_PLUGIN_SUBSYSTEM, "statechange: failed to create lock\n");
- ret = -1;
+ ret = SLAPI_PLUGIN_FAILURE;
}
else
{
if( slapi_apib_register(StateChange_v1_0_GUID, api) )
{
slapi_log_error( SLAPI_LOG_FATAL, SCN_PLUGIN_SUBSYSTEM, "statechange: failed to publish state change interface\n");
- ret = -1;
+ ret = SLAPI_PLUGIN_FAILURE;
}
}
@@ -207,7 +207,7 @@ static int statechange_close( Slapi_PBlock *pb )
slapi_log_error( SLAPI_LOG_TRACE, SCN_PLUGIN_SUBSYSTEM, "<-- statechange_close\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
@@ -251,7 +251,7 @@ static int statechange_post_op( Slapi_PBlock *pb, int modtype )
struct slapi_entry *e_after = NULL;
if(head == 0)
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
slapi_log_error( SLAPI_LOG_TRACE, SCN_PLUGIN_SUBSYSTEM, "--> statechange_post_op\n");
@@ -317,13 +317,13 @@ bail:
slapi_unlock_mutex(buffer_lock);
slapi_log_error( SLAPI_LOG_TRACE, SCN_PLUGIN_SUBSYSTEM, "<-- statechange_post_op\n");
- return 0; /* always succeed */
+ return SLAPI_PLUGIN_SUCCESS; /* always succeed */
}
static int _statechange_register(char *caller_id, char *dn, char *filter, void *caller_data, notify_callback func)
{
- int ret = -1;
+ int ret = SLAPI_PLUGIN_FAILURE;
SCNotify *item;
/* simple - we don't check for duplicates */
@@ -352,7 +352,7 @@ static int _statechange_register(char *caller_id, char *dn, char *filter, void *
slapi_ch_free_string(&item->filter);
slapi_ch_free_string(&writable_filter);
slapi_ch_free((void **)&item);
- return -1;
+ return ret;
} else if (!writable_filter) {
item->realfilter = NULL;
}
@@ -375,7 +375,7 @@ static int _statechange_register(char *caller_id, char *dn, char *filter, void *
slapi_unlock_mutex(buffer_lock);
slapi_ch_free_string(&writable_filter);
- ret = 0;
+ ret = SLAPI_PLUGIN_SUCCESS;
}
return ret;
diff --git a/ldap/servers/plugins/usn/usn.c b/ldap/servers/plugins/usn/usn.c
index 4473618..338517f 100644
--- a/ldap/servers/plugins/usn/usn.c
+++ b/ldap/servers/plugins/usn/usn.c
@@ -148,13 +148,13 @@ bail:
static int
usn_preop_init(Slapi_PBlock *pb)
{
- int rc = 0;
+ int rc = SLAPI_PLUGIN_SUCCESS;
int predel = SLAPI_PLUGIN_PRE_DELETE_FN;
if (slapi_pblock_set(pb, predel, (void *)usn_preop_delete) != 0) {
slapi_log_error(SLAPI_LOG_FATAL, USN_PLUGIN_SUBSYSTEM,
"usn_preop_init: failed to register preop plugin\n");
- rc = -1;
+ rc = SLAPI_PLUGIN_FAILURE;
}
return rc;
@@ -163,7 +163,7 @@ usn_preop_init(Slapi_PBlock *pb)
static int
usn_bepreop_init(Slapi_PBlock *pb)
{
- int rc = 0;
+ int rc = SLAPI_PLUGIN_SUCCESS;
int premod = SLAPI_PLUGIN_BE_PRE_MODIFY_FN;
int premdn = SLAPI_PLUGIN_BE_PRE_MODRDN_FN;
@@ -175,7 +175,7 @@ usn_bepreop_init(Slapi_PBlock *pb)
(slapi_pblock_set(pb, premdn, (void *)usn_bepreop_modify) != 0)) {
slapi_log_error(SLAPI_LOG_FATAL, USN_PLUGIN_SUBSYSTEM,
"usn_bepreop_init: failed to register bepreop plugin\n");
- rc = -1;
+ rc = SLAPI_PLUGIN_FAILURE;
}
return rc;
@@ -184,7 +184,7 @@ usn_bepreop_init(Slapi_PBlock *pb)
static int
usn_betxnpreop_init(Slapi_PBlock *pb)
{
- int rc = 0;
+ int rc = SLAPI_PLUGIN_SUCCESS;
int preadd = SLAPI_PLUGIN_BE_TXN_PRE_ADD_FN;
int predel = SLAPI_PLUGIN_BE_TXN_PRE_DELETE_TOMBSTONE_FN;
@@ -192,7 +192,7 @@ usn_betxnpreop_init(Slapi_PBlock *pb)
(slapi_pblock_set(pb, predel, (void *)usn_betxnpreop_delete) != 0)) {
slapi_log_error(SLAPI_LOG_FATAL, USN_PLUGIN_SUBSYSTEM,
"usn_betxnpreop_init: failed to register betxnpreop plugin\n");
- rc = -1;
+ rc = SLAPI_PLUGIN_FAILURE;
}
return rc;
@@ -201,7 +201,7 @@ usn_betxnpreop_init(Slapi_PBlock *pb)
static int
usn_bepostop_init(Slapi_PBlock *pb)
{
- int rc = 0;
+ int rc = SLAPI_PLUGIN_SUCCESS;
Slapi_Entry *plugin_entry = NULL;
char *plugin_type = NULL;
int postadd = SLAPI_PLUGIN_BE_POST_ADD_FN;
@@ -227,7 +227,7 @@ usn_bepostop_init(Slapi_PBlock *pb)
(slapi_pblock_set(pb, postmdn, (void *)usn_bepostop) != 0)) {
slapi_log_error(SLAPI_LOG_FATAL, USN_PLUGIN_SUBSYSTEM,
"usn_bepostop_init: failed to register bepostop plugin\n");
- rc = -1;
+ rc = SLAPI_PLUGIN_FAILURE;
}
return rc;
@@ -236,12 +236,12 @@ usn_bepostop_init(Slapi_PBlock *pb)
static int
usn_rootdse_init()
{
- int rc = -1;
+ int rc = SLAPI_PLUGIN_FAILURE;
if (slapi_config_register_callback(SLAPI_OPERATION_SEARCH, DSE_FLAG_PREOP,
"", LDAP_SCOPE_BASE, "(objectclass=*)",
usn_rootdse_search, NULL)) {
- rc = 0;
+ rc = SLAPI_PLUGIN_SUCCESS;
}
return rc;
@@ -254,7 +254,7 @@ usn_rootdse_init()
static int
usn_start(Slapi_PBlock *pb)
{
- int rc = 0;
+ int rc = SLAPI_PLUGIN_SUCCESS;
Slapi_Value *value;
slapi_log_error(SLAPI_LOG_TRACE, USN_PLUGIN_SUBSYSTEM, "--> usn_start\n");
@@ -262,6 +262,7 @@ usn_start(Slapi_PBlock *pb)
rc = usn_rootdse_init();
rc |= usn_cleanup_start(pb);
if (rc) {
+ rc = SLAPI_PLUGIN_FAILURE;
goto bail;
}
if (0) { /* Not executed; test code for slapi_get_plugin_default_config */
@@ -284,7 +285,9 @@ usn_start(Slapi_PBlock *pb)
/* add nsds5ReplicatedAttributeList: (objectclass=*) $ EXCLUDE entryusn
* to cn=plugin default config,cn=config */
value = slapi_value_new_string("(objectclass=*) $ EXCLUDE entryusn");
- rc = slapi_set_plugin_default_config("nsds5ReplicatedAttributeList", value);
+ if (slapi_set_plugin_default_config("nsds5ReplicatedAttributeList", value)) {
+ rc = SLAPI_PLUGIN_FAILURE;
+ }
slapi_value_free(&value);
g_plugin_started = 1;
bail:
@@ -302,7 +305,7 @@ usn_close(Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_TRACE, USN_PLUGIN_SUBSYSTEM, "<-- usn_close\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
/*
@@ -311,7 +314,6 @@ usn_close(Slapi_PBlock *pb)
static int
usn_preop_delete(Slapi_PBlock *pb)
{
- int rc = 0;
Slapi_Operation *op = NULL;
slapi_log_error(SLAPI_LOG_TRACE, USN_PLUGIN_SUBSYSTEM,
@@ -323,7 +325,7 @@ usn_preop_delete(Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_TRACE, USN_PLUGIN_SUBSYSTEM,
"<-- usn_preop_delete\n");
- return rc;
+ return SLAPI_PLUGIN_SUCCESS;
}
static void
@@ -407,7 +409,7 @@ usn_betxnpreop_add(Slapi_PBlock *pb)
{
Slapi_Entry *e = NULL;
Slapi_Backend *be = NULL;
- int rc = LDAP_SUCCESS;
+ int rc = SLAPI_PLUGIN_SUCCESS;
slapi_log_error(SLAPI_LOG_TRACE, USN_PLUGIN_SUBSYSTEM,
"--> usn_betxnpreop_add\n");
@@ -416,11 +418,15 @@ usn_betxnpreop_add(Slapi_PBlock *pb)
slapi_pblock_get(pb, SLAPI_ADD_ENTRY, &e);
if (NULL == e) {
rc = LDAP_NO_SUCH_OBJECT;
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &rc);
+ rc = SLAPI_PLUGIN_FAILURE;
goto bail;
}
slapi_pblock_get(pb, SLAPI_BACKEND, &be);
if (NULL == be) {
rc = LDAP_PARAM_ERROR;
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &rc);
+ rc = SLAPI_PLUGIN_FAILURE;
goto bail;
}
_usn_add_next_usn(e, be);
@@ -439,7 +445,7 @@ usn_betxnpreop_delete(Slapi_PBlock *pb)
{
Slapi_Entry *e = NULL;
Slapi_Backend *be = NULL;
- int rc = LDAP_SUCCESS;
+ int rc = SLAPI_PLUGIN_SUCCESS;
slapi_log_error(SLAPI_LOG_TRACE, USN_PLUGIN_SUBSYSTEM,
"--> usn_betxnpreop_delete\n");
@@ -448,11 +454,15 @@ usn_betxnpreop_delete(Slapi_PBlock *pb)
slapi_pblock_get(pb, SLAPI_DELETE_BEPREOP_ENTRY, &e);
if (NULL == e) {
rc = LDAP_NO_SUCH_OBJECT;
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &rc);
+ rc = SLAPI_PLUGIN_FAILURE;
goto bail;
}
slapi_pblock_get(pb, SLAPI_BACKEND, &be);
if (NULL == be) {
rc = LDAP_PARAM_ERROR;
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &rc);
+ rc = SLAPI_PLUGIN_FAILURE;
goto bail;
}
_usn_add_next_usn(e, be);
@@ -472,7 +482,7 @@ usn_bepreop_modify (Slapi_PBlock *pb)
{
LDAPMod **mods = NULL;
Slapi_Backend *be = NULL;
- int rc = LDAP_SUCCESS;
+ int rc = SLAPI_PLUGIN_SUCCESS;
slapi_log_error(SLAPI_LOG_TRACE, USN_PLUGIN_SUBSYSTEM,
"--> usn_bepreop_modify\n");
@@ -483,6 +493,9 @@ usn_bepreop_modify (Slapi_PBlock *pb)
if (NULL == be) {
slapi_log_error(SLAPI_LOG_FATAL, USN_PLUGIN_SUBSYSTEM,
"usn_bepreop_modify: no backend.\n");
+ rc = LDAP_PARAM_ERROR;
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &rc);
+ rc = SLAPI_PLUGIN_FAILURE;
goto bail;
}
if (LDAP_SUCCESS == _usn_mod_next_usn(&mods, be)) {
@@ -498,7 +511,7 @@ bail:
static int
usn_bepostop (Slapi_PBlock *pb)
{
- int rc = -1;
+ int rc = SLAPI_PLUGIN_FAILURE;
Slapi_Backend *be = NULL;
slapi_log_error(SLAPI_LOG_TRACE, USN_PLUGIN_SUBSYSTEM,
@@ -507,12 +520,16 @@ usn_bepostop (Slapi_PBlock *pb)
/* if op is not successful, don't increment the counter */
slapi_pblock_get(pb, SLAPI_RESULT_CODE, &rc);
if (LDAP_SUCCESS != rc) {
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &rc);
+ rc = SLAPI_PLUGIN_FAILURE;
goto bail;
}
slapi_pblock_get(pb, SLAPI_BACKEND, &be);
if (NULL == be) {
rc = LDAP_PARAM_ERROR;
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &rc);
+ rc = SLAPI_PLUGIN_FAILURE;
goto bail;
}
@@ -529,7 +546,7 @@ bail:
static int
usn_bepostop_modify (Slapi_PBlock *pb)
{
- int rc = -1;
+ int rc = SLAPI_PLUGIN_FAILURE;
Slapi_Backend *be = NULL;
LDAPMod **mods = NULL;
int i;
@@ -540,6 +557,7 @@ usn_bepostop_modify (Slapi_PBlock *pb)
/* if op is not successful, don't increment the counter */
slapi_pblock_get(pb, SLAPI_RESULT_CODE, &rc);
if (LDAP_SUCCESS != rc) {
+ rc = SLAPI_PLUGIN_FAILURE;
goto bail;
}
@@ -560,6 +578,8 @@ usn_bepostop_modify (Slapi_PBlock *pb)
slapi_pblock_get(pb, SLAPI_BACKEND, &be);
if (NULL == be) {
rc = LDAP_PARAM_ERROR;
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &rc);
+ rc = SLAPI_PLUGIN_FAILURE;
goto bail;
}
@@ -577,7 +597,7 @@ bail:
static int
usn_bepostop_delete (Slapi_PBlock *pb)
{
- int rc = -1;
+ int rc = SLAPI_PLUGIN_FAILURE;
Slapi_Backend *be = NULL;
slapi_log_error(SLAPI_LOG_TRACE, USN_PLUGIN_SUBSYSTEM,
@@ -586,12 +606,15 @@ usn_bepostop_delete (Slapi_PBlock *pb)
/* if op is not successful, don't increment the counter */
slapi_pblock_get(pb, SLAPI_RESULT_CODE, &rc);
if (LDAP_SUCCESS != rc) {
+ rc = SLAPI_PLUGIN_FAILURE;
goto bail;
}
slapi_pblock_get(pb, SLAPI_BACKEND, &be);
if (NULL == be) {
rc = LDAP_PARAM_ERROR;
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &rc);
+ rc = SLAPI_PLUGIN_FAILURE;
goto bail;
}
diff --git a/ldap/servers/plugins/views/views.c b/ldap/servers/plugins/views/views.c
index 0892b0d..c6fd628 100644
--- a/ldap/servers/plugins/views/views.c
+++ b/ldap/servers/plugins/views/views.c
@@ -185,7 +185,7 @@ void * view_get_plugin_identity()
*/
int views_init( Slapi_PBlock *pb )
{
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
void * plugin_identity=NULL;
slapi_log_error( SLAPI_LOG_TRACE, VIEWS_PLUGIN_SUBSYSTEM, "--> views_init\n");
@@ -209,7 +209,7 @@ int views_init( Slapi_PBlock *pb )
{
slapi_log_error( SLAPI_LOG_FATAL, VIEWS_PLUGIN_SUBSYSTEM,
"views_init: failed to register plugin\n" );
- ret = -1;
+ ret = SLAPI_PLUGIN_FAILURE;
}
slapi_log_error( SLAPI_LOG_TRACE, VIEWS_PLUGIN_SUBSYSTEM, "<-- views_init\n");
@@ -238,7 +238,7 @@ void views_unlock()
*/
static int views_start( Slapi_PBlock *pb )
{
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
void **statechange_api;
slapi_log_error( SLAPI_LOG_TRACE, VIEWS_PLUGIN_SUBSYSTEM, "--> views_start\n");
@@ -270,7 +270,7 @@ static int views_start( Slapi_PBlock *pb )
if( slapi_apib_register(Views_v1_0_GUID, api) )
{
slapi_log_error( SLAPI_LOG_FATAL, VIEWS_PLUGIN_SUBSYSTEM, "views: failed to publish views interface\n");
- ret = -1;
+ ret = SLAPI_PLUGIN_FAILURE;
}
slapi_log_error( SLAPI_LOG_TRACE, VIEWS_PLUGIN_SUBSYSTEM, "<-- views_start\n");
@@ -296,7 +296,7 @@ static int _internal_api_views_entry_dn_exists(char *view_dn, char *e_dn)
static int _internal_api_views_entry_exists_general(char *view_dn, Slapi_Entry *e, char *e_dn)
{
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
viewEntry *view;
char *dn;
@@ -326,7 +326,7 @@ static int _internal_api_views_entry_exists_general(char *view_dn, Slapi_Entry *
if(slapi_dn_issuffix(dn, view_dn))
{
/* this entry is physically contained in the view hiearchy */
- ret = -1;
+ ret = SLAPI_PLUGIN_FAILURE;
goto bail;
}
@@ -346,7 +346,7 @@ static int _internal_api_views_entry_exists_general(char *view_dn, Slapi_Entry *
if(0==slapi_filter_test_simple(e,view->includeAncestorFiltersFilter))
{
/* this entry would appear in the view */
- ret = -1;
+ ret = SLAPI_PLUGIN_FAILURE;
}
}
@@ -408,7 +408,7 @@ static int views_close( Slapi_PBlock *pb )
slapi_log_error( SLAPI_LOG_TRACE, VIEWS_PLUGIN_SUBSYSTEM, "<-- views_close\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
@@ -419,7 +419,7 @@ static int views_close( Slapi_PBlock *pb )
*/
static int views_cache_create()
{
- int ret = -1;
+ int ret = SLAPI_PLUGIN_FAILURE;
slapi_log_error( SLAPI_LOG_TRACE, VIEWS_PLUGIN_SUBSYSTEM, "--> views_cache_create\n");
@@ -474,7 +474,7 @@ static int views_cache_create()
{
/* its ok to not have views to cache */
theCache.cache_built = 0;
- ret = 0;
+ ret = SLAPI_PLUGIN_SUCCESS;
}
theCache.currentUpdaterThread = 0;
@@ -530,7 +530,7 @@ int views_cache_dn_compare(const void *e1, const void *e2)
*/
static int views_cache_index()
{
- int ret = -1;
+ int ret = SLAPI_PLUGIN_FAILURE;
int i;
viewEntry *theView = theCache.pCacheViews;
viewEntry *current = 0;
@@ -558,7 +558,7 @@ static int views_cache_index()
/* sort the views */
qsort(theCache.ppViewIndex, theCache.view_count, sizeof(viewEntry*), views_cache_view_compare);
- ret = 0;
+ ret = SLAPI_PLUGIN_SUCCESS;
}
return ret;
@@ -569,7 +569,7 @@ static int views_cache_index()
views_cache_view_index_bsearch - RECURSIVE
----------------------------------------
performs a binary search on the cache view index
- return -1 if key is not found
+ return SLAPI_PLUGIN_FAILURE if key is not found
*/
viewEntry *views_cache_view_index_bsearch( const char *key, int lower, int upper )
{
@@ -617,7 +617,7 @@ viewEntry *views_cache_view_index_bsearch( const char *key, int lower, int upper
*/
static viewEntry *views_cache_find_view(char *view)
{
- viewEntry *ret = 0; /* assume failure */
+ viewEntry *ret = SLAPI_PLUGIN_SUCCESS; /* assume failure */
if(theCache.view_count != 1)
ret = views_cache_view_index_bsearch(view, 0, theCache.view_count-1);
@@ -1119,7 +1119,7 @@ static void views_cache_create_inclusion_filter(viewEntry *pView)
*/
static int views_cache_build_view_list(viewEntry **pViews)
{
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
Slapi_PBlock *pSuffixSearch = 0;
Slapi_Entry **pSuffixList = 0;
Slapi_Attr *suffixAttr;
@@ -1192,7 +1192,7 @@ static int views_cache_build_view_list(viewEntry **pViews)
else
{
slapi_log_error(SLAPI_LOG_PLUGIN, VIEWS_PLUGIN_SUBSYSTEM, "views_cache_build_view_list: failed to find suffixes\n");
- ret = -1;
+ ret = SLAPI_PLUGIN_FAILURE;
}
/* clean up */
@@ -1215,7 +1215,8 @@ struct dn_views_info {
/* does same funcationality as views_add_dn_views except it is invoked via a callback */
-static int views_dn_views_cb (Slapi_Entry* e, void *callback_data) {
+static int views_dn_views_cb (Slapi_Entry* e, void *callback_data)
+{
struct dn_views_info *info;
char *pDn = 0;
struct berval **dnVals;
diff --git a/ldap/servers/slapd/add.c b/ldap/servers/slapd/add.c
index b2319fa..0695727 100644
--- a/ldap/servers/slapd/add.c
+++ b/ldap/servers/slapd/add.c
@@ -714,7 +714,7 @@ static void op_shared_add (Slapi_PBlock *pb)
sdn = slapi_sdn_dup(slapi_entry_get_sdn_const(e));
slapi_pblock_set(pb, SLAPI_ADD_TARGET_SDN, (void *)sdn);
if (plugin_call_plugins(pb, internal_op ? SLAPI_PLUGIN_INTERNAL_PRE_ADD_FN :
- SLAPI_PLUGIN_PRE_ADD_FN) == 0)
+ SLAPI_PLUGIN_PRE_ADD_FN) == SLAPI_PLUGIN_SUCCESS)
{
int rc;
Slapi_Entry *ec;
diff --git a/ldap/servers/slapd/delete.c b/ldap/servers/slapd/delete.c
index ced6351..68409c7 100644
--- a/ldap/servers/slapd/delete.c
+++ b/ldap/servers/slapd/delete.c
@@ -353,7 +353,7 @@ static void op_shared_delete (Slapi_PBlock *pb)
* post-delete plugins.
*/
if (plugin_call_plugins(pb, internal_op ? SLAPI_PLUGIN_INTERNAL_PRE_DELETE_FN :
- SLAPI_PLUGIN_PRE_DELETE_FN) == 0)
+ SLAPI_PLUGIN_PRE_DELETE_FN) == SLAPI_PLUGIN_SUCCESS)
{
int rc;
diff --git a/ldap/servers/slapd/modify.c b/ldap/servers/slapd/modify.c
index cc1621b..0a8854b 100644
--- a/ldap/servers/slapd/modify.c
+++ b/ldap/servers/slapd/modify.c
@@ -1050,7 +1050,7 @@ static void op_shared_modify (Slapi_PBlock *pb, int pw_change, char *old_pw)
*/
slapi_pblock_set (pb, SLAPI_MODIFY_MODS, (void*)slapi_mods_get_ldapmods_passout (&smods));
if (plugin_call_plugins(pb, internal_op ? SLAPI_PLUGIN_INTERNAL_PRE_MODIFY_FN :
- SLAPI_PLUGIN_PRE_MODIFY_FN) == 0)
+ SLAPI_PLUGIN_PRE_MODIFY_FN) == SLAPI_PLUGIN_SUCCESS)
{
int rc;
diff --git a/ldap/servers/slapd/modrdn.c b/ldap/servers/slapd/modrdn.c
index e1d2440..457c2b0 100644
--- a/ldap/servers/slapd/modrdn.c
+++ b/ldap/servers/slapd/modrdn.c
@@ -642,7 +642,7 @@ op_shared_rename(Slapi_PBlock *pb, int passin_args)
* post-modrdn plugins.
*/
if (plugin_call_plugins(pb, internal_op ? SLAPI_PLUGIN_INTERNAL_PRE_MODRDN_FN :
- SLAPI_PLUGIN_PRE_MODRDN_FN) == 0)
+ SLAPI_PLUGIN_PRE_MODRDN_FN) == SLAPI_PLUGIN_SUCCESS)
{
int rc= LDAP_OPERATIONS_ERROR;
slapi_pblock_set(pb, SLAPI_PLUGIN, be->be_database);
diff --git a/ldap/servers/slapd/plugin.c b/ldap/servers/slapd/plugin.c
index d19faa5..5f66ab2 100644
--- a/ldap/servers/slapd/plugin.c
+++ b/ldap/servers/slapd/plugin.c
@@ -1453,9 +1453,8 @@ plugin_call_func (struct slapdplugin *list, int operation, Slapi_PBlock *pb, int
if (( rc = func (pb)) != 0 )
{
if (SLAPI_PLUGIN_PREOPERATION == list->plg_type ||
- SLAPI_PLUGIN_INTERNAL_PREOPERATION == list->plg_type ||
- SLAPI_PLUGIN_BETXNPREOPERATION == list->plg_type ||
- SLAPI_PLUGIN_START_FN == operation )
+ SLAPI_PLUGIN_INTERNAL_PREOPERATION == list->plg_type ||
+ SLAPI_PLUGIN_START_FN == operation )
{
/*
* We bail out of plugin processing for preop plugins
@@ -1465,13 +1464,18 @@ plugin_call_func (struct slapdplugin *list, int operation, Slapi_PBlock *pb, int
*/
return_value = rc;
break;
- } else if (SLAPI_PLUGIN_BEPREOPERATION == list->plg_type ||
- SLAPI_PLUGIN_BEPOSTOPERATION == list->plg_type)
+ }
+ else if (SLAPI_PLUGIN_BEPREOPERATION == list->plg_type ||
+ SLAPI_PLUGIN_BETXNPREOPERATION == list->plg_type ||
+ SLAPI_PLUGIN_BEPOSTOPERATION == list->plg_type)
{
- /* respect fatal error (-1); should not OR it */
- if (-1 == rc) {
+ /*
+ * respect fatal error SLAPI_PLUGIN_FAILURE (-1);
+ * should not OR it.
+ */
+ if (SLAPI_PLUGIN_FAILURE == rc) {
return_value = rc;
- } else if (-1 != return_value) {
+ } else if (SLAPI_PLUGIN_FAILURE != return_value) {
/* OR the result into the return value
* for be pre/postops */
return_value |= rc;
commit 690d58ba5870e7f0dd3ad6593c92a86771fc54d5
Author: Noriko Hosoi <nhosoi(a)redhat.com>
Date: Thu Jul 18 14:27:28 2013 -0700
Ticket #47367 - (phase 1) ldapdelete returns non-leaf entry error while trying to remove a leaf entry
Bug description: Replication conflict confuses the numsubordinate count,
which leaves an entry that cannot be deleted even its subordinate entries
are all removed.
Fix description:
[urp.c] 1) get_dn_plus_uniqueid: a logic to create a conflict DN had a bug.
It used to call slapi_sdn_get_rdn to get the rdn. The function slapi_sdn_
get_rdn blindly returned the "dn" field without checking whether the field
is NULL or not. Instead, this patch changes the interface of the helper
function get_dn_plus_uniqueid and use the original Slapi_DN with slapi_sdn_
get_dn, then generates the conflict DN "nsuniqueid=...+ <RDN>,<PARENT>".
2) The urp calling timing was moved from SLAPI_PLUGIN_BE_TXN_PRE_* to
SLAPI_PLUGIN_BE_PRE_*. (Note: SLAPI_PLUGIN_BE_PRE_* is also in the
backend transaction.) This is necessary since urp needs to be done
prior to parent checking.
[ldbm_add.c] Moved SLAPI_PLUGIN_BE_PRE_ADD_FN inside of the transaction.
Other operations are already calling SLAPI_PLUGIN_BE_PRE function at the
timing.
[ldbm_delete.c] There is a case a parent of a delete-candidate entry runs
into a conflict and multiple parent entries exist. Once it occurs, a
parent entry found by the parent dn string may not be the entry which
manages the numsubordinate count the delete-candidate entry belonging to.
It confuses the numsubordinate counts and leaves an entry which cannot be
deleted due to the numsubordinate count mismatch. This patch retrieves
parent entry by parent id if it is available.
[ldbm_entryrdn.c] When traversing the DIT, a special treatment is needed
for a tombstone entry. I.e, 2 RDNs (nsuniqueid=..., <RDN>) is treated as
one RDN. It should decrement the index (rdnidx) one more to point to the
right position of the RDN array in Slapi_RDN.
[ldbm_search.c] When checking the scope of an entry in ldbm_back_next_
search_entry_ext, a tombstone entry was not properly examined. This patch
introduces a new slapi api slapi_sdn_scope_test_ext.
[dn.c] In slapi_sdn_get_rdn, use slapi_sdn_get_dn to get the dn value of
Slapi_DN. It was one cause of the problem in get_dn_plus_uniqueid (urp.c).
This patch adds slapi_sdn_scope_test_ext, which takes flags to indicates
the first argument dn is a tombstone sdn. Also, this patch replaces
"malloc + strcpy + strcat" with slapi_ch_smprintf to improve the
readability of the code.
[rdn.c] This patch replaces "malloc + strcpy + strcat" with slapi_create_
dn_string to normalize the newly added rdn and improve the readability of
the code.
Reviewed by Rich (Thanks!!)
https://fedorahosted.org/389/ticket/47367
(cherry picked from commit 2f4f74b3d38eeb38f0794dfb2e880a95e7e9bd49)
diff --git a/ldap/servers/plugins/replication/repl5_init.c b/ldap/servers/plugins/replication/repl5_init.c
index 8471f00..fc27a4c 100644
--- a/ldap/servers/plugins/replication/repl5_init.c
+++ b/ldap/servers/plugins/replication/repl5_init.c
@@ -359,17 +359,6 @@ multimaster_betxnpreop_init( Slapi_PBlock *pb )
{
int rc= 0; /* OK */
- if( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 ) != 0 ||
- slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multimasterbepreopdesc ) != 0 ||
- slapi_pblock_set( pb, SLAPI_PLUGIN_BE_TXN_PRE_ADD_FN, (void *) multimaster_betxnpreop_add ) != 0 ||
- slapi_pblock_set( pb, SLAPI_PLUGIN_BE_TXN_PRE_DELETE_FN, (void *) multimaster_betxnpreop_delete ) != 0 ||
- slapi_pblock_set( pb, SLAPI_PLUGIN_BE_TXN_PRE_MODIFY_FN, (void *) multimaster_betxnpreop_modify ) != 0 ||
- slapi_pblock_set( pb, SLAPI_PLUGIN_BE_TXN_PRE_MODRDN_FN, (void *) multimaster_betxnpreop_modrdn ) != 0 )
- {
- slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "multimaster_betxnpreop_init failed\n" );
- rc= -1;
- }
-
return rc;
}
diff --git a/ldap/servers/plugins/replication/repl5_plugins.c b/ldap/servers/plugins/replication/repl5_plugins.c
index 01ac03c..590af7e 100644
--- a/ldap/servers/plugins/replication/repl5_plugins.c
+++ b/ldap/servers/plugins/replication/repl5_plugins.c
@@ -718,8 +718,7 @@ multimaster_bepreop_add (Slapi_PBlock *pb)
{
slapi_pblock_set(pb, SLAPI_TXN_RUV_MODS_FN,
(void *)replica_ruv_smods_for_op);
- if (!repl5_is_betxn && is_replicated_operation) {
- /* if is_betxn is on, urp is called at betxn preop */
+ if (is_replicated_operation) {
rc = urp_add_operation(pb);
}
}
@@ -744,8 +743,7 @@ multimaster_bepreop_delete (Slapi_PBlock *pb)
{
slapi_pblock_set(pb, SLAPI_TXN_RUV_MODS_FN,
(void *)replica_ruv_smods_for_op);
- if (!repl5_is_betxn && is_replicated_operation) {
- /* if is_betxn is on, urp is called at betxn preop */
+ if (is_replicated_operation) {
rc = urp_delete_operation(pb);
}
}
@@ -770,8 +768,7 @@ multimaster_bepreop_modify (Slapi_PBlock *pb)
{
slapi_pblock_set(pb, SLAPI_TXN_RUV_MODS_FN,
(void *)replica_ruv_smods_for_op);
- if (!repl5_is_betxn && is_replicated_operation) {
- /* if is_betxn is on, urp is called at betxn preop */
+ if (is_replicated_operation) {
rc = urp_modify_operation(pb);
}
}
@@ -799,8 +796,7 @@ multimaster_bepreop_modrdn (Slapi_PBlock *pb)
{
slapi_pblock_set(pb, SLAPI_TXN_RUV_MODS_FN,
(void *)replica_ruv_smods_for_op);
- if (!repl5_is_betxn && is_replicated_operation) {
- /* if is_betxn is on, urp is called at betxn preop */
+ if (is_replicated_operation) {
rc = urp_modrdn_operation(pb);
}
}
diff --git a/ldap/servers/plugins/replication/urp.c b/ldap/servers/plugins/replication/urp.c
index 3d0ea82..471bf8d 100644
--- a/ldap/servers/plugins/replication/urp.c
+++ b/ldap/servers/plugins/replication/urp.c
@@ -55,9 +55,9 @@ 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, const Slapi_Entry *entry, CSN *opcsn, const char *optype);
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 mod_namingconflict_attr (const char *uniqueid, const Slapi_DN *entrysdn, const Slapi_DN *conflictsdn, CSN *opcsn, const char *optype);
static int del_replconflict_attr (const Slapi_Entry *entry, CSN *opcsn, int opflags);
-static char *get_dn_plus_uniqueid(char *sessionid,const char *olddn,const char *uniqueid);
+static char *get_dn_plus_uniqueid(char *sessionid,const Slapi_DN *oldsdn,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);
@@ -184,7 +184,7 @@ urp_add_operation( Slapi_PBlock *pb )
if (r<0)
{
/* Entry to be added is a loser */
- char *newdn= get_dn_plus_uniqueid (sessionid, basedn, adduniqueid);
+ char *newdn= get_dn_plus_uniqueid (sessionid, (const Slapi_DN *)addentry, adduniqueid);
if(newdn==NULL)
{
op_result= LDAP_OPERATIONS_ERROR;
@@ -203,7 +203,11 @@ urp_add_operation( Slapi_PBlock *pb )
Slapi_RDN *rdn;
char buf[BUFSIZ];
+#ifdef DEBUG
+ PR_snprintf(buf, BUFSIZ, "%s (add) %s", REASON_ANNOTATE_DN, basedn);
+#else
PR_snprintf(buf, BUFSIZ, "%s %s", REASON_ANNOTATE_DN, basedn);
+#endif
if (slapi_entry_attr_find (addentry, ATTR_NSDS5_REPLCONFLICT, &attr) == 0)
{
/* ATTR_NSDS5_REPLCONFLICT exists */
@@ -466,7 +470,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, "MODRDN");
slapi_pblock_set(pb, SLAPI_MODRDN_NEWRDN, newrdn_with_uniqueid);
slapi_log_error(slapi_log_urp, sessionid,
"urp_modrdn: Naming conflict MODRDN. Rename target entry to %s\n",
@@ -1033,7 +1037,7 @@ urp_annotate_dn (char *sessionid, const Slapi_Entry *entry, CSN *opcsn, const ch
newrdn = get_rdn_plus_uniqueid ( sessionid, basedn, uniqueid );
if(newrdn!=NULL)
{
- mod_namingconflict_attr (uniqueid, basesdn, basesdn, opcsn);
+ mod_namingconflict_attr (uniqueid, basesdn, basesdn, opcsn, optype);
op_result = urp_fixup_rename_entry ( entry, newrdn, 0 );
switch(op_result)
{
@@ -1245,16 +1249,15 @@ bailout:
/* The returned value is either null or "uniqueid=<uniqueid>+<basedn>" */
static char *
-get_dn_plus_uniqueid(char *sessionid, const char *olddn, const char *uniqueid)
+get_dn_plus_uniqueid(char *sessionid, const Slapi_DN *oldsdn, const char *uniqueid)
{
- Slapi_DN *sdn= slapi_sdn_new_dn_byval(olddn);
Slapi_RDN *rdn= slapi_rdn_new();
char *newdn;
PR_ASSERT(uniqueid!=NULL);
/* Check if the RDN already contains the Unique ID */
- slapi_sdn_get_rdn(sdn,rdn);
+ slapi_rdn_set_dn(rdn, slapi_sdn_get_dn(oldsdn));
if(slapi_rdn_contains(rdn,SLAPI_ATTR_UNIQUEID,uniqueid,strlen(uniqueid)))
{
/* The Unique ID is already in the RDN.
@@ -1264,16 +1267,20 @@ get_dn_plus_uniqueid(char *sessionid, const char *olddn, const char *uniqueid)
* require admin intercession
*/
slapi_log_error(SLAPI_LOG_FATAL, sessionid,
- "Annotated DN %s has naming conflict\n", olddn );
+ "Annotated DN %s has naming conflict\n", slapi_sdn_get_dn(oldsdn) );
newdn= NULL;
}
else
{
- slapi_rdn_add(rdn,SLAPI_ATTR_UNIQUEID,uniqueid);
- slapi_sdn_set_rdn(sdn, rdn);
- newdn= slapi_ch_strdup(slapi_sdn_get_dn(sdn));
+ char *parentdn = slapi_dn_parent(slapi_sdn_get_dn(oldsdn));
+ slapi_rdn_add(rdn, SLAPI_ATTR_UNIQUEID, uniqueid);
+ /*
+ * using slapi_ch_smprintf is okay since ...
+ * uniqueid in rdn is normalized and
+ * parentdn is normalized by slapi_sdn_get_dn.
+ */
+ newdn = slapi_ch_smprintf("%s,%s", slapi_rdn_get_rdn(rdn), parentdn);
}
- slapi_sdn_free(&sdn);
slapi_rdn_free(&rdn);
return newdn;
}
@@ -1340,14 +1347,20 @@ 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,
+ const char *optype)
{
Slapi_Mods smods;
char buf[BUFSIZ];
int op_result;
+#ifdef DEBUG
+ PR_snprintf (buf, sizeof(buf), "%s (%s) %s",
+ REASON_ANNOTATE_DN, optype, slapi_sdn_get_dn(conflictsdn));
+#else
PR_snprintf (buf, sizeof(buf), "%s %s",
REASON_ANNOTATE_DN, slapi_sdn_get_dn(conflictsdn));
+#endif
slapi_mods_init (&smods, 2);
if ( strncmp (slapi_sdn_get_dn(entrysdn), SLAPI_ATTR_UNIQUEID,
strlen(SLAPI_ATTR_UNIQUEID)) != 0 )
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_add.c b/ldap/servers/slapd/back-ldbm/ldbm_add.c
index 708ccfa..fa1e9bc 100644
--- a/ldap/servers/slapd/back-ldbm/ldbm_add.c
+++ b/ldap/servers/slapd/back-ldbm/ldbm_add.c
@@ -194,112 +194,6 @@ ldbm_back_add( Slapi_PBlock *pb )
}
- if (!is_tombstone_operation) {
- rc= slapi_setbit_int(rc,SLAPI_RTN_BIT_FETCH_EXISTING_DN_ENTRY);
- }
- rc= slapi_setbit_int(rc,SLAPI_RTN_BIT_FETCH_EXISTING_UNIQUEID_ENTRY);
- rc= slapi_setbit_int(rc,SLAPI_RTN_BIT_FETCH_PARENT_ENTRY);
- while(rc!=0)
- {
- /* JCM - copying entries can be expensive... should optimize */
- /*
- * Some present state information is passed through the PBlock to the
- * backend pre-op plugin. To ensure a consistent snapshot of this state
- * we wrap the reading of the entry with the dblock.
- */
- if(slapi_isbitset_int(rc,SLAPI_RTN_BIT_FETCH_EXISTING_UNIQUEID_ENTRY))
- {
- /* Check if an entry with the intended uniqueid already exists. */
- done_with_pblock_entry(pb,SLAPI_ADD_EXISTING_UNIQUEID_ENTRY); /* Could be through this multiple times */
- addr.udn = NULL;
- addr.sdn = NULL;
- addr.uniqueid = (char*)slapi_entry_get_uniqueid(e); /* jcm - cast away const */
- ldap_result_code= get_copy_of_entry(pb, &addr, &txn, SLAPI_ADD_EXISTING_UNIQUEID_ENTRY, !is_replicated_operation);
- }
- if(slapi_isbitset_int(rc,SLAPI_RTN_BIT_FETCH_EXISTING_DN_ENTRY))
- {
- slapi_pblock_get( pb, SLAPI_ADD_TARGET_SDN, &sdn );
- if (NULL == sdn)
- {
- LDAPDebug0Args(LDAP_DEBUG_ANY,
- "ldbm_back_add: Null target dn\n");
- goto error_return;
- }
-
- /* not need to check the dn syntax as this is a replicated op */
- if(!is_replicated_operation){
- dn = slapi_sdn_get_dn(sdn);
- ldap_result_code = slapi_dn_syntax_check(pb, dn, 1);
- if (ldap_result_code)
- {
- ldap_result_code = LDAP_INVALID_DN_SYNTAX;
- slapi_pblock_get(pb, SLAPI_PB_RESULT_TEXT, &ldap_result_message);
- goto error_return;
- }
- }
-
- slapi_sdn_get_backend_parent(sdn, &parentsdn, pb->pb_backend);
- /* Check if an entry with the intended DN already exists. */
- done_with_pblock_entry(pb,SLAPI_ADD_EXISTING_DN_ENTRY); /* Could be through this multiple times */
- addr.sdn = sdn;
- addr.udn = NULL;
- addr.uniqueid = NULL;
- ldap_result_code= get_copy_of_entry(pb, &addr, &txn, SLAPI_ADD_EXISTING_DN_ENTRY, !is_replicated_operation);
- if(ldap_result_code==LDAP_OPERATIONS_ERROR ||
- ldap_result_code==LDAP_INVALID_DN_SYNTAX)
- {
- goto error_return;
- }
- }
- /* if we can find the parent by dn or uniqueid, and the operation has requested the parent
- then get it */
- if(have_parent_address(&parentsdn, operation->o_params.p.p_add.parentuniqueid) &&
- slapi_isbitset_int(rc,SLAPI_RTN_BIT_FETCH_PARENT_ENTRY))
- {
- done_with_pblock_entry(pb,SLAPI_ADD_PARENT_ENTRY); /* Could be through this multiple times */
- addr.sdn = &parentsdn;
- addr.udn = NULL;
- addr.uniqueid = operation->o_params.p.p_add.parentuniqueid;
- ldap_result_code= get_copy_of_entry(pb, &addr, &txn, SLAPI_ADD_PARENT_ENTRY, !is_replicated_operation);
- /* need to set parentsdn or parentuniqueid if either is not set? */
- }
-
- /* Call the Backend Pre Add plugins */
- slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ldap_result_code);
- rc= plugin_call_plugins(pb, SLAPI_PLUGIN_BE_PRE_ADD_FN);
- if (rc) {
- int opreturn = 0;
- if (SLAPI_PLUGIN_NOOP == rc) {
- not_an_error = 1;
- rc = LDAP_SUCCESS;
- }
- /*
- * Plugin indicated some kind of failure,
- * or that this Operation became a No-Op.
- */
- if (!ldap_result_code) {
- slapi_pblock_get(pb, SLAPI_RESULT_CODE, &ldap_result_code);
- }
- if (!ldap_result_code) {
- LDAPDebug0Args(LDAP_DEBUG_ANY,
- "ldbm_back_add: SLAPI_PLUGIN_BE_PRE_ADD_FN returned error but did not set SLAPI_RESULT_CODE\n");
- ldap_result_code = LDAP_OPERATIONS_ERROR;
- }
- slapi_pblock_get(pb, SLAPI_PLUGIN_OPRETURN, &opreturn);
- if (!opreturn) {
- /* make sure opreturn is set for the postop plugins */
- slapi_pblock_set(pb, SLAPI_PLUGIN_OPRETURN, ldap_result_code ? &ldap_result_code : &rc);
- }
-
- goto error_return;
- }
- /*
- * (rc!=-1 && rc!= 0) means that the plugin changed things, so we go around
- * the loop once again to get the new present state.
- */
- /* JCMREPL - Warning: A Plugin could cause an infinite loop by always returning a result code that requires some action. */
- }
-
/*
* Originally (in the U-M LDAP 3.3 code), there was a comment near this
* code about a race condition. The race was that a 2nd entry could be
@@ -365,6 +259,113 @@ ldbm_back_add( Slapi_PBlock *pb )
if (0 == retry_count) {
/* First time, hold SERIAL LOCK */
retval = dblayer_txn_begin(be, parent_txn, &txn);
+
+ if (!is_tombstone_operation) {
+ rc= slapi_setbit_int(rc,SLAPI_RTN_BIT_FETCH_EXISTING_DN_ENTRY);
+ }
+
+ rc= slapi_setbit_int(rc,SLAPI_RTN_BIT_FETCH_EXISTING_UNIQUEID_ENTRY);
+ rc= slapi_setbit_int(rc,SLAPI_RTN_BIT_FETCH_PARENT_ENTRY);
+ while(rc!=0)
+ {
+ /* JCM - copying entries can be expensive... should optimize */
+ /*
+ * Some present state information is passed through the PBlock to the
+ * backend pre-op plugin. To ensure a consistent snapshot of this state
+ * we wrap the reading of the entry with the dblock.
+ */
+ if(slapi_isbitset_int(rc,SLAPI_RTN_BIT_FETCH_EXISTING_UNIQUEID_ENTRY))
+ {
+ /* Check if an entry with the intended uniqueid already exists. */
+ done_with_pblock_entry(pb,SLAPI_ADD_EXISTING_UNIQUEID_ENTRY); /* Could be through this multiple times */
+ addr.udn = NULL;
+ addr.sdn = NULL;
+ addr.uniqueid = (char*)slapi_entry_get_uniqueid(e); /* jcm - cast away const */
+ ldap_result_code= get_copy_of_entry(pb, &addr, &txn, SLAPI_ADD_EXISTING_UNIQUEID_ENTRY, !is_replicated_operation);
+ }
+ if(slapi_isbitset_int(rc,SLAPI_RTN_BIT_FETCH_EXISTING_DN_ENTRY))
+ {
+ slapi_pblock_get( pb, SLAPI_ADD_TARGET_SDN, &sdn );
+ if (NULL == sdn)
+ {
+ LDAPDebug0Args(LDAP_DEBUG_ANY,
+ "ldbm_back_add: Null target dn\n");
+ goto error_return;
+ }
+
+ /* not need to check the dn syntax as this is a replicated op */
+ if(!is_replicated_operation){
+ dn = slapi_sdn_get_dn(sdn);
+ ldap_result_code = slapi_dn_syntax_check(pb, dn, 1);
+ if (ldap_result_code)
+ {
+ ldap_result_code = LDAP_INVALID_DN_SYNTAX;
+ slapi_pblock_get(pb, SLAPI_PB_RESULT_TEXT, &ldap_result_message);
+ goto error_return;
+ }
+ }
+
+ slapi_sdn_get_backend_parent(sdn, &parentsdn, pb->pb_backend);
+ /* Check if an entry with the intended DN already exists. */
+ done_with_pblock_entry(pb,SLAPI_ADD_EXISTING_DN_ENTRY); /* Could be through this multiple times */
+ addr.sdn = sdn;
+ addr.udn = NULL;
+ addr.uniqueid = NULL;
+ ldap_result_code= get_copy_of_entry(pb, &addr, &txn, SLAPI_ADD_EXISTING_DN_ENTRY, !is_replicated_operation);
+ if(ldap_result_code==LDAP_OPERATIONS_ERROR ||
+ ldap_result_code==LDAP_INVALID_DN_SYNTAX)
+ {
+ goto error_return;
+ }
+ }
+ /* if we can find the parent by dn or uniqueid, and the operation has requested the parent
+ then get it */
+ if(have_parent_address(&parentsdn, operation->o_params.p.p_add.parentuniqueid) &&
+ slapi_isbitset_int(rc,SLAPI_RTN_BIT_FETCH_PARENT_ENTRY))
+ {
+ done_with_pblock_entry(pb,SLAPI_ADD_PARENT_ENTRY); /* Could be through this multiple times */
+ addr.sdn = &parentsdn;
+ addr.udn = NULL;
+ addr.uniqueid = operation->o_params.p.p_add.parentuniqueid;
+ ldap_result_code= get_copy_of_entry(pb, &addr, &txn, SLAPI_ADD_PARENT_ENTRY, !is_replicated_operation);
+ /* need to set parentsdn or parentuniqueid if either is not set? */
+ }
+
+ /* Call the Backend Pre Add plugins */
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ldap_result_code);
+ rc= plugin_call_plugins(pb, SLAPI_PLUGIN_BE_PRE_ADD_FN);
+ if (rc < 0) {
+ int opreturn = 0;
+ if (SLAPI_PLUGIN_NOOP == rc) {
+ not_an_error = 1;
+ rc = LDAP_SUCCESS;
+ }
+ /*
+ * Plugin indicated some kind of failure,
+ * or that this Operation became a No-Op.
+ */
+ if (!ldap_result_code) {
+ slapi_pblock_get(pb, SLAPI_RESULT_CODE, &ldap_result_code);
+ }
+ if (!ldap_result_code) {
+ LDAPDebug0Args(LDAP_DEBUG_ANY,
+ "ldbm_back_add: SLAPI_PLUGIN_BE_PRE_ADD_FN returned error but did not set SLAPI_RESULT_CODE\n");
+ ldap_result_code = LDAP_OPERATIONS_ERROR;
+ }
+ slapi_pblock_get(pb, SLAPI_PLUGIN_OPRETURN, &opreturn);
+ if (!opreturn) {
+ /* make sure opreturn is set for the postop plugins */
+ slapi_pblock_set(pb, SLAPI_PLUGIN_OPRETURN, ldap_result_code ? &ldap_result_code : &rc);
+ }
+
+ goto error_return;
+ }
+ /*
+ * (rc!=-1 && rc!= 0) means that the plugin changed things, so we go around
+ * the loop once again to get the new present state.
+ */
+ /* JCMREPL - Warning: A Plugin could cause an infinite loop by always returning a result code that requires some action. */
+ }
} else {
/* Otherwise, no SERIAL LOCK */
retval = dblayer_txn_begin_ext(li, parent_txn, &txn, PR_FALSE);
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_delete.c b/ldap/servers/slapd/back-ldbm/ldbm_delete.c
index be73e04..011c2d5 100644
--- a/ldap/servers/slapd/back-ldbm/ldbm_delete.c
+++ b/ldap/servers/slapd/back-ldbm/ldbm_delete.c
@@ -288,7 +288,6 @@ ldbm_back_delete( Slapi_PBlock *pb )
/* Don't call pre-op for Tombstone entries */
if (!delete_tombstone_entry)
{
- int rc = 0;
/*
* Some present state information is passed through the PBlock to the
* backend pre-op plugin. To ensure a consistent snapshot of this state
@@ -305,12 +304,13 @@ ldbm_back_delete( Slapi_PBlock *pb )
goto error_return;
}
slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ldap_result_code);
-
- rc = plugin_call_plugins(pb, SLAPI_PLUGIN_BE_PRE_DELETE_FN);
- if (rc)
+
+ retval = plugin_call_plugins(pb, SLAPI_PLUGIN_BE_PRE_DELETE_FN);
+ if (retval)
{
- if (SLAPI_PLUGIN_NOOP == rc) {
+ if (SLAPI_PLUGIN_NOOP == retval) {
not_an_error = 1;
+ rc = LDAP_SUCCESS;
}
/*
* Plugin indicated some kind of failure,
@@ -324,12 +324,11 @@ ldbm_back_delete( Slapi_PBlock *pb )
if (!opreturn) {
slapi_pblock_set( pb, SLAPI_PLUGIN_OPRETURN, ldap_result_code ? &ldap_result_code : &rc );
}
- retval = -1;
goto error_return;
}
/* the flag could be set in a preop plugin (e.g., USN) */
delete_tombstone_entry = operation_is_flag_set(operation,
- OP_FLAG_TOMBSTONE_ENTRY);
+ OP_FLAG_TOMBSTONE_ENTRY);
}
/* call the transaction pre delete plugins just after the
@@ -363,16 +362,14 @@ ldbm_back_delete( Slapi_PBlock *pb )
*/
is_tombstone_entry = slapi_entry_flag_is_set(e->ep_entry, SLAPI_ENTRY_FLAG_TOMBSTONE);
if (delete_tombstone_entry) {
- PR_ASSERT(is_tombstone_entry);
if (!is_tombstone_entry) {
slapi_log_error(SLAPI_LOG_FATAL, "ldbm_back_delete",
"Attempt to delete a non-tombstone entry %s\n", dn);
delete_tombstone_entry = 0;
}
} else {
- PR_ASSERT(!is_tombstone_entry);
if (is_tombstone_entry) {
- slapi_log_error(SLAPI_LOG_FATAL, "ldbm_back_delete",
+ slapi_log_error(SLAPI_LOG_FATAL, "ldbm_back_delete",
"Attempt to Tombstone again a tombstone entry %s\n", dn);
delete_tombstone_entry = 1;
}
@@ -428,7 +425,7 @@ ldbm_back_delete( Slapi_PBlock *pb )
/* Save away a copy of the entry, before modifications */
slapi_pblock_set( pb, SLAPI_ENTRY_PRE_OP, slapi_entry_dup( e->ep_entry ));
- /* JCMACL - Shouldn't the access check be before the has children check...
+ /* JCMACL - Shouldn't the access check be before the has children check...
* otherwise we're revealing the fact that an entry exists and has children */
ldap_result_code = plugin_call_acl_plugin (pb, e->ep_entry, NULL, NULL, SLAPI_ACL_DELETE,
ACLPLUGIN_ACCESS_DEFAULT, &errbuf );
@@ -449,12 +446,31 @@ ldbm_back_delete( Slapi_PBlock *pb )
if ( !slapi_sdn_isempty(&parentsdn) )
{
struct backentry *parent = NULL;
- entry_address parent_addr;
+ char *pid_str = slapi_entry_attr_get_charptr(e->ep_entry, LDBM_PARENTID_STR);
+ if (pid_str) {
+ /* First, try to get the direct parent. */
+ /*
+ * Although a rare case, multiple parents from repl conflict could exist.
+ * In such case, if a parent entry is found just by parentsdn
+ * (find_entry2modify_only_ext), a wrong parent could be found,
+ * and numsubordinate count could get confused.
+ */
+ ID pid = (ID)strtol(pid_str, (char **)NULL, 10);
+ parent = id2entry(be, pid ,NULL, &retval);
+ if (parent && cache_lock_entry(&inst->inst_cache, parent)) {
+ /* Failed to obtain parent entry's entry lock */
+ CACHE_RETURN(&(inst->inst_cache), &parent);
+ goto error_return;
+ }
+ }
+ if (NULL == parent) {
+ entry_address parent_addr;
- parent_addr.sdn = &parentsdn;
- parent_addr.uniqueid = NULL;
- parent = find_entry2modify_only_ext(pb, be, &parent_addr,
- TOMBSTONE_INCLUDED, &txn);
+ parent_addr.sdn = &parentsdn;
+ parent_addr.uniqueid = NULL;
+ parent = find_entry2modify_only_ext(pb, be, &parent_addr,
+ TOMBSTONE_INCLUDED, &txn);
+ }
if (NULL != parent) {
int isglue;
size_t haschildren = 0;
@@ -549,7 +565,7 @@ ldbm_back_delete( Slapi_PBlock *pb )
slapi_value_free(&tomb_value);
/* XXXggood above used to be: slapi_entry_add_string(tombstone->ep_entry, SLAPI_ATTR_OBJECTCLASS, SLAPI_ATTR_VALUE_TOMBSTONE); */
/* JCMREPL - Add a description of what's going on? */
-
+
if ( (original_tombstone = backentry_dup( tombstone )) == NULL ) {
ldap_result_code= LDAP_OPERATIONS_ERROR;
retval = -1;
@@ -568,6 +584,7 @@ ldbm_back_delete( Slapi_PBlock *pb )
if (retval) {
if (SLAPI_PLUGIN_NOOP == retval) {
not_an_error = 1;
+ rc = LDAP_SUCCESS;
}
LDAPDebug1Arg( LDAP_DEBUG_TRACE,
"SLAPI_PLUGIN_BE_TXN_PRE_DELETE_FN plugin "
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_entryrdn.c b/ldap/servers/slapd/back-ldbm/ldbm_entryrdn.c
index 57b3a20..8c17104 100644
--- a/ldap/servers/slapd/back-ldbm/ldbm_entryrdn.c
+++ b/ldap/servers/slapd/back-ldbm/ldbm_entryrdn.c
@@ -3159,6 +3159,7 @@ _entryrdn_index_read(backend *be,
/* Node might be a tombstone. */
rc = _entryrdn_get_tombstone_elem(cursor, tmpsrdn,
&key, nrdn, elem);
+ rdnidx--; /* consider nsuniqueid=..,<RDN> one RDN */
}
if (rc || NULL == *elem) {
slapi_log_error(SLAPI_LOG_BACKLDBM, ENTRYRDN_TAG,
@@ -3265,6 +3266,7 @@ _entryrdn_index_read(backend *be,
}
goto bail;
}
+ rdnidx--; /* consider nsuniqueid=..,<RDN> one RDN */
} else {
slapi_ch_free((void **)&tmpelem);
if (DB_NOTFOUND != rc) {
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_modrdn.c b/ldap/servers/slapd/back-ldbm/ldbm_modrdn.c
index 8944b6c..b16b54c 100644
--- a/ldap/servers/slapd/back-ldbm/ldbm_modrdn.c
+++ b/ldap/servers/slapd/back-ldbm/ldbm_modrdn.c
@@ -447,7 +447,7 @@ ldbm_back_modrdn( Slapi_PBlock *pb )
/* Call the Backend Pre ModRDN plugins */
slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ldap_result_code);
rc= plugin_call_plugins(pb, SLAPI_PLUGIN_BE_PRE_MODRDN_FN);
- if (rc) {
+ if (rc < 0) {
if (SLAPI_PLUGIN_NOOP == rc) {
not_an_error = 1;
rc = LDAP_SUCCESS;
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_search.c b/ldap/servers/slapd/back-ldbm/ldbm_search.c
index a84689c..4b789a2 100644
--- a/ldap/servers/slapd/back-ldbm/ldbm_search.c
+++ b/ldap/servers/slapd/back-ldbm/ldbm_search.c
@@ -1647,7 +1647,7 @@ ldbm_back_next_search_entry_ext( Slapi_PBlock *pb, int use_extension )
* just forget about it, since we don't want to return anything at all. */
{
if ( slapi_uniqueIDCompareString(target_uniqueid, e->ep_entry->e_uniqueid) ||
- slapi_sdn_scope_test( backentry_get_sdn(e), basesdn, scope ))
+ slapi_sdn_scope_test_ext( backentry_get_sdn(e), basesdn, scope, e->ep_entry->e_flags ))
{
/* check size limit */
if ( slimit >= 0 )
diff --git a/ldap/servers/slapd/dn.c b/ldap/servers/slapd/dn.c
index 44459e1..9ed8091 100644
--- a/ldap/servers/slapd/dn.c
+++ b/ldap/servers/slapd/dn.c
@@ -2169,6 +2169,10 @@ slapi_sdn_set_rdn(Slapi_DN *sdn, const Slapi_RDN *rdn)
{
/* NewDN= NewRDN + OldParent */
char *parentdn = slapi_dn_parent(slapi_sdn_get_dn(sdn));
+ /*
+ * using slapi_ch_smprintf is okay since
+ * newdn is set to sdn as a pre-normalized dn.
+ */
char *newdn = slapi_ch_smprintf("%s,%s", rawrdn, parentdn);
slapi_ch_free((void**)&parentdn);
slapi_sdn_set_dn_passin(sdn,newdn);
@@ -2191,10 +2195,11 @@ slapi_sdn_add_rdn(Slapi_DN *sdn, const Slapi_RDN *rdn)
{
/* NewDN= NewRDN + DN */
const char *dn= slapi_sdn_get_dn(sdn);
- char *newdn= slapi_ch_malloc(strlen(rawrdn)+1+strlen(dn)+1);
- strcpy( newdn, rawrdn );
- strcat( newdn, "," );
- strcat( newdn, dn );
+ /*
+ * using slapi_ch_smprintf is okay since
+ * newdn is set to sdn as a pre-normalized dn.
+ */
+ char *newdn = slapi_ch_smprintf("%s,%s", rawrdn, dn);
slapi_sdn_set_dn_passin(sdn,newdn);
}
return sdn;
@@ -2422,7 +2427,7 @@ slapi_sdn_get_backend_parent(const Slapi_DN *sdn,Slapi_DN *sdn_parent,const Slap
void
slapi_sdn_get_rdn(const Slapi_DN *sdn,Slapi_RDN *rdn)
{
- slapi_rdn_set_dn(rdn,sdn->dn);
+ slapi_rdn_set_dn(rdn, slapi_sdn_get_dn(sdn));
}
Slapi_DN *
@@ -2616,6 +2621,47 @@ slapi_sdn_scope_test( const Slapi_DN *dn, const Slapi_DN *base, int scope )
return rc;
}
+/*
+ * Return non-zero if "dn" matches the scoping criteria
+ * given by "base" and "scope".
+ * If SLAPI_ENTRY_FLAG_TOMBSTONE is set to flags,
+ * DN without "nsuniqueid=...," is examined.
+ */
+int
+slapi_sdn_scope_test_ext( const Slapi_DN *dn, const Slapi_DN *base, int scope, int flags )
+{
+ int rc = 0;
+
+ switch ( scope ) {
+ case LDAP_SCOPE_BASE:
+ if (flags & SLAPI_ENTRY_FLAG_TOMBSTONE) {
+ Slapi_DN parent;
+ slapi_sdn_init(&parent);
+ slapi_sdn_get_parent(dn, &parent);
+ rc = ( slapi_sdn_compare( dn, &parent ) == 0 );
+ slapi_sdn_done(&parent);
+ } else {
+ rc = ( slapi_sdn_compare( dn, base ) == 0 );
+ }
+ break;
+ case LDAP_SCOPE_ONELEVEL:
+ if (flags & SLAPI_ENTRY_FLAG_TOMBSTONE) {
+ Slapi_DN parent;
+ slapi_sdn_init(&parent);
+ slapi_sdn_get_parent(dn, &parent);
+ rc = ( slapi_sdn_isparent( base, &parent ) != 0 );
+ slapi_sdn_done(&parent);
+ } else {
+ rc = ( slapi_sdn_isparent( base, dn ) != 0 );
+ }
+ break;
+ case LDAP_SCOPE_SUBTREE:
+ rc = ( slapi_sdn_issuffix( dn, base ) != 0 );
+ break;
+ }
+ return rc;
+}
+
/*
* build the new dn of an entry for moddn operations
*/
@@ -2663,8 +2709,17 @@ size_t
slapi_sdn_get_size(const Slapi_DN *sdn)
{
size_t sz = sizeof(Slapi_DN);
+ /* slapi_sdn_get_ndn_len returns the normalized dn length
+ * if dn or ndn exists. If both does not exist, it
+ * normalizes udn and set it to dn and returns the length.
+ */
sz += slapi_sdn_get_ndn_len(sdn);
- sz += strlen(sdn->dn) + 1;
+ if (sdn->dn && sdn->ndn) {
+ sz += slapi_sdn_get_ndn_len(sdn);
+ }
+ if (sdn->udn) {
+ sz += strlen(sdn->udn) + 1;
+ }
return sz;
}
diff --git a/ldap/servers/slapd/rdn.c b/ldap/servers/slapd/rdn.c
index d408f0e..fe2fae0 100644
--- a/ldap/servers/slapd/rdn.c
+++ b/ldap/servers/slapd/rdn.c
@@ -479,25 +479,17 @@ slapi_rdn_add(Slapi_RDN *rdn, const char *type, const char *value)
PR_ASSERT(NULL != value);
if(rdn->rdn==NULL)
{
- /* type=value '\0' */
- rdn->rdn= slapi_ch_malloc(strlen(type)+1+strlen(value)+1);
- strcpy( rdn->rdn, type );
- strcat( rdn->rdn, "=" );
- strcat( rdn->rdn, value );
+ /* type=value '\0' */
+ rdn->rdn = slapi_create_dn_string("%s=%s", type, value);
}
else
{
- /* type=value+rdn '\0' */
- char *newrdn= slapi_ch_malloc(strlen(type)+1+strlen(value)+1+strlen(rdn->rdn)+1);
- strcpy( newrdn, type );
- strcat( newrdn, "=" );
- strcat( newrdn, value );
- strcat( newrdn, "+" );
- strcat( newrdn, rdn->rdn );
- slapi_ch_free((void**)&rdn->rdn);
- rdn->rdn= newrdn;
- }
- slapi_unsetbit_uchar(rdn->flag,FLAG_RDNS);
+ /* type=value+rdn '\0' */
+ char *newrdn = slapi_create_dn_string("%s=%s+%s", type, value, rdn->rdn);
+ slapi_ch_free_string(&rdn->rdn);
+ rdn->rdn = newrdn;
+ }
+ slapi_unsetbit_uchar(rdn->flag,FLAG_RDNS);
return 1;
}
diff --git a/ldap/servers/slapd/slapi-plugin.h b/ldap/servers/slapd/slapi-plugin.h
index dfc48cf..3e0cf74 100644
--- a/ldap/servers/slapd/slapi-plugin.h
+++ b/ldap/servers/slapd/slapi-plugin.h
@@ -2753,6 +2753,24 @@ int slapi_sdn_get_ndn_len(const Slapi_DN *sdn);
int slapi_sdn_scope_test( const Slapi_DN *dn, const Slapi_DN *base, int scope );
/**
+ * Checks if a DN is within a specified scope under a specified base DN.
+ * This api adjusts tombstoned DN when comparing with the base dn.
+ *
+ * \param dn A pointer to the \c Slapi_DN structure to test.
+ * \param base The base DN against which \c dn is going to be tested.
+ * \param scope The scope tested. Valid scopes are:
+ * \arg \c LDAP_SCOPE_BASE
+ * \arg \c LDAP_SCOPE_ONELEVEL
+ * \arg \c LDAP_SCOPE_SUBTREE
+ * \param flags 0 or SLAPI_ENTRY_FLAG_TOMBSTONE
+ * \return non-zero if \c dn matches the scoping criteria given by \c base and \c scope.
+ * \see slapi_sdn_compare()
+ * \see slapi_sdn_isparent()
+ * \see slapi_sdn_issuffix()
+ */
+int slapi_sdn_scope_test_ext( const Slapi_DN *dn, const Slapi_DN *base, int scope, int flags );
+
+/**
* Retreives the RDN from a given DN.
*
* This function takes the DN stored in the \c Slapi_DN structure pointed to
10 years, 9 months
2 commits - ldap/servers
by Noriko Hosoi
ldap/servers/plugins/automember/automember.c | 23 +-
ldap/servers/plugins/cos/cos.c | 2
ldap/servers/plugins/dna/dna.c | 18 +
ldap/servers/plugins/linkedattrs/linked_attrs.c | 34 ++-
ldap/servers/plugins/memberof/memberof.c | 16 -
ldap/servers/plugins/mep/mep.c | 41 ++--
ldap/servers/plugins/pam_passthru/pam_ptpreop.c | 12 -
ldap/servers/plugins/referint/referint.c | 52 ++---
ldap/servers/plugins/replication/repl5.h | 4
ldap/servers/plugins/replication/repl5_init.c | 11 -
ldap/servers/plugins/replication/repl5_plugins.c | 196 +++++----------------
ldap/servers/plugins/replication/urp.c | 41 ++--
ldap/servers/plugins/retrocl/retrocl_po.c | 12 -
ldap/servers/plugins/roles/roles_plugin.c | 2
ldap/servers/plugins/statechange/statechange.c | 22 +-
ldap/servers/plugins/usn/usn.c | 65 ++++---
ldap/servers/plugins/views/views.c | 35 +--
ldap/servers/slapd/add.c | 2
ldap/servers/slapd/back-ldbm/ldbm_add.c | 213 +++++++++++------------
ldap/servers/slapd/back-ldbm/ldbm_delete.c | 51 +++--
ldap/servers/slapd/back-ldbm/ldbm_entryrdn.c | 2
ldap/servers/slapd/back-ldbm/ldbm_modrdn.c | 2
ldap/servers/slapd/back-ldbm/ldbm_search.c | 2
ldap/servers/slapd/delete.c | 2
ldap/servers/slapd/dn.c | 67 ++++++-
ldap/servers/slapd/modify.c | 2
ldap/servers/slapd/modrdn.c | 2
ldap/servers/slapd/plugin.c | 20 +-
ldap/servers/slapd/rdn.c | 24 --
ldap/servers/slapd/slapi-plugin.h | 18 +
30 files changed, 509 insertions(+), 484 deletions(-)
New commits:
commit 733059713a5dfb72c844de1e3b9bc153d4ae6ccb
Author: Noriko Hosoi <nhosoi(a)redhat.com>
Date: Thu Jul 18 11:38:30 2013 -0700
Ticket #47367 - (phase 2) ldapdelete returns non-leaf entry error while trying to remove a leaf entry
Fix description:
1) Make sure add/modify/modrdn/delete plug-in callbacks return
SLAPI_PLUGIN_SUCCESS (==0) on SUCCESS and SLAPI_PLUGIN_FAILURE
(==-1) on FAILURE. And set error code to SLAPI_RESULT_CODE in
pblock, if any.
2) replication: eliminated multimaster_betxnpreop_* which were
used for calling urp. Urp needs to be processed at bepreop
timing.
Reviewed by Rich (Thank you!!)
https://fedorahosted.org/389/ticket/47367
diff --git a/ldap/servers/plugins/automember/automember.c b/ldap/servers/plugins/automember/automember.c
index 49f47f7..2ba3314 100644
--- a/ldap/servers/plugins/automember/automember.c
+++ b/ldap/servers/plugins/automember/automember.c
@@ -1686,7 +1686,7 @@ automember_pre_op(Slapi_PBlock * pb, int modop)
LDAPMod **mods;
int free_entry = 0;
char *errstr = NULL;
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
slapi_log_error(SLAPI_LOG_TRACE, AUTOMEMBER_PLUGIN_SUBSYSTEM,
"--> automember_pre_op\n");
@@ -1771,7 +1771,8 @@ automember_pre_op(Slapi_PBlock * pb, int modop)
"automember_pre_op: operation failure [%d]\n", ret);
slapi_send_ldap_result(pb, ret, NULL, errstr, 0, NULL);
slapi_ch_free((void **)&errstr);
- ret = -1;
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ret);
+ ret = SLAPI_PLUGIN_FAILURE;
}
slapi_log_error(SLAPI_LOG_TRACE, AUTOMEMBER_PLUGIN_SUBSYSTEM,
@@ -1822,7 +1823,7 @@ automember_mod_post_op(Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_TRACE, AUTOMEMBER_PLUGIN_SUBSYSTEM,
"<-- automember_mod_post_op\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
static int
@@ -1838,7 +1839,7 @@ automember_add_post_op(Slapi_PBlock *pb)
/* Just bail if we aren't ready to service requests yet. */
if (!g_plugin_started || !automember_oktodo(pb))
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
/* Reload config if a config entry was added. */
if ((sdn = automember_get_sdn(pb))) {
@@ -1854,7 +1855,7 @@ automember_add_post_op(Slapi_PBlock *pb)
/* If replication, just bail. */
if (automember_isrepl(pb)) {
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
/* Get the newly added entry. */
@@ -1868,7 +1869,7 @@ automember_add_post_op(Slapi_PBlock *pb)
tombstone);
slapi_value_free(&tombstone);
if (rc) {
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
/* Check if a config entry applies
@@ -1878,7 +1879,7 @@ automember_add_post_op(Slapi_PBlock *pb)
/* Bail out if the plug-in close function was just called. */
if (!g_plugin_started) {
automember_config_unlock();
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if (!PR_CLIST_IS_EMPTY(g_automember_config)) {
@@ -1907,7 +1908,7 @@ bail:
slapi_log_error(SLAPI_LOG_TRACE, AUTOMEMBER_PLUGIN_SUBSYSTEM,
"<-- automember_add_post_op\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
/*
@@ -1925,7 +1926,7 @@ automember_del_post_op(Slapi_PBlock *pb)
/* Just bail if we aren't ready to service requests yet. */
if (!g_plugin_started || !automember_oktodo(pb)) {
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
/* Reload config if a config entry was deleted. */
@@ -1941,7 +1942,7 @@ automember_del_post_op(Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_TRACE, AUTOMEMBER_PLUGIN_SUBSYSTEM,
"<-- automember_del_post_op\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
typedef struct _task_data
@@ -2193,7 +2194,7 @@ void automember_rebuild_task_thread(void *arg){
/* Does the entry meet scope and filter requirements? */
if (slapi_dn_issuffix(slapi_sdn_get_dn(td->base_dn), config->scope) &&
(slapi_filter_test_simple(entries[i], config->filter) == 0))
- {
+ {
automember_update_membership(config, entries[i], NULL);
}
list = PR_NEXT_LINK(list);
diff --git a/ldap/servers/plugins/cos/cos.c b/ldap/servers/plugins/cos/cos.c
index 0d76d99..55ff850 100644
--- a/ldap/servers/plugins/cos/cos.c
+++ b/ldap/servers/plugins/cos/cos.c
@@ -306,6 +306,6 @@ int cos_post_op( Slapi_PBlock *pb )
cos_cache_change_notify(pb);
LDAPDebug( LDAP_DEBUG_TRACE, "<-- cos_post_op\n",0,0,0);
- return 0; /* always succeed */
+ return SLAPI_PLUGIN_SUCCESS; /* always succeed */
}
diff --git a/ldap/servers/plugins/dna/dna.c b/ldap/servers/plugins/dna/dna.c
index f5ebec6..f044c76 100644
--- a/ldap/servers/plugins/dna/dna.c
+++ b/ldap/servers/plugins/dna/dna.c
@@ -70,8 +70,8 @@
#define DNA_DN "cn=Distributed Numeric Assignment Plugin,cn=plugins,cn=config" /* temporary */
-#define DNA_SUCCESS 0
-#define DNA_FAILURE -1
+#define DNA_SUCCESS SLAPI_PLUGIN_SUCCESS
+#define DNA_FAILURE SLAPI_PLUGIN_FAILURE
/* Default range request timeout */
/* use the default replication timeout */
@@ -3016,7 +3016,7 @@ dna_create_valcheck_filter(struct configEntry *config_entry, PRUint64 value, cha
static int
_dna_pre_op_add(Slapi_PBlock *pb, Slapi_Entry *e, char **errstr)
{
- int ret = 0;
+ int ret = DNA_SUCCESS;
PRCList *list = NULL;
struct configEntry *config_entry = NULL;
char *dn = NULL;
@@ -3195,7 +3195,7 @@ _dna_pre_op_add(Slapi_PBlock *pb, Slapi_Entry *e, char **errstr)
slapi_ch_free((void **)&types_to_generate);
}
next:
- ret = 0;
+ ret = DNA_SUCCESS;
list = PR_NEXT_LINK(list);
}
}
@@ -3212,7 +3212,7 @@ bail:
static int
_dna_pre_op_modify(Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Mods *smods, char **errstr)
{
- int ret = 0;
+ int ret = DNA_SUCCESS;
PRCList *list = NULL;
struct configEntry *config_entry = NULL;
char *dn = NULL;
@@ -3594,6 +3594,7 @@ bail:
"dna_pre_op: operation failure [%d]\n", ret);
slapi_send_ldap_result(pb, ret, NULL, errstr, 0, NULL);
slapi_ch_free((void **)&errstr);
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ret);
ret = DNA_FAILURE;
}
@@ -3659,7 +3660,7 @@ static int dna_be_txn_pre_op(Slapi_PBlock *pb, int modtype)
char *dn = NULL;
char *type = NULL;
int numvals, e_numvals = 0;
- int i, len, ret = 0;
+ int i, len, ret = DNA_SUCCESS;
slapi_log_error(SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM,
"--> dna_be_txn_pre_op\n");
@@ -3905,13 +3906,14 @@ bail:
"dna_be_txn_pre_op: operation failure [%d]\n", ret);
slapi_send_ldap_result(pb, ret, NULL, errstr, 0, NULL);
slapi_ch_free((void **)&errstr);
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ret);
ret = DNA_FAILURE;
}
slapi_log_error(SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM,
"<-- dna_be_txn_pre_op\n");
- return ret;
+ return ret;
}
static int dna_config_check_post_op(Slapi_PBlock * pb)
@@ -3932,7 +3934,7 @@ static int dna_config_check_post_op(Slapi_PBlock * pb)
slapi_log_error(SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM,
"<-- dna_config_check_post_op\n");
- return 0;
+ return DNA_SUCCESS;
}
diff --git a/ldap/servers/plugins/linkedattrs/linked_attrs.c b/ldap/servers/plugins/linkedattrs/linked_attrs.c
index 7d8370d..30a8653 100644
--- a/ldap/servers/plugins/linkedattrs/linked_attrs.c
+++ b/ldap/servers/plugins/linkedattrs/linked_attrs.c
@@ -1536,7 +1536,7 @@ linked_attrs_pre_op(Slapi_PBlock * pb, int modop)
LDAPMod **mods = NULL;
int free_entry = 0;
char *errstr = NULL;
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
slapi_log_error(SLAPI_LOG_TRACE, LINK_PLUGIN_SUBSYSTEM,
"--> linked_attrs_pre_op\n");
@@ -1603,7 +1603,8 @@ linked_attrs_pre_op(Slapi_PBlock * pb, int modop)
"linked_attrs_pre_op: operation failure [%d]\n", ret);
slapi_send_ldap_result(pb, ret, NULL, errstr, 0, NULL);
slapi_ch_free((void **)&errstr);
- ret = -1;
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ret);
+ ret = SLAPI_PLUGIN_FAILURE;
}
slapi_log_error(SLAPI_LOG_TRACE, LINK_PLUGIN_SUBSYSTEM,
@@ -1640,7 +1641,7 @@ linked_attrs_mod_post_op(Slapi_PBlock *pb)
/* Just bail if we aren't ready to service requests yet. */
if (!g_plugin_started)
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
/* We don't want to process internal modify
* operations that originate from this plugin.
@@ -1649,7 +1650,7 @@ linked_attrs_mod_post_op(Slapi_PBlock *pb)
if (caller_id == linked_attrs_get_plugin_id()) {
/* Just return without processing */
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if (linked_attrs_oktodo(pb) &&
@@ -1675,7 +1676,7 @@ linked_attrs_mod_post_op(Slapi_PBlock *pb)
/* Bail out if the plug-in close function was just called. */
if (!g_plugin_started) {
linked_attrs_unlock();
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
linked_attrs_find_config(dn, type, &config);
@@ -1729,7 +1730,7 @@ linked_attrs_mod_post_op(Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_TRACE, LINK_PLUGIN_SUBSYSTEM,
"<-- linked_attrs_mod_post_op\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
static int
@@ -1743,7 +1744,7 @@ linked_attrs_add_post_op(Slapi_PBlock *pb)
/* Just bail if we aren't ready to service requests yet. */
if (!g_plugin_started || !linked_attrs_oktodo(pb))
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
/* Reload config if a config entry was added. */
if ((dn = linked_attrs_get_dn(pb))) {
@@ -1773,7 +1774,7 @@ linked_attrs_add_post_op(Slapi_PBlock *pb)
/* Bail out if the plug-in close function was just called. */
if (!g_plugin_started) {
linked_attrs_unlock();
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
linked_attrs_find_config(dn, type, &config);
@@ -1808,7 +1809,7 @@ linked_attrs_add_post_op(Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_TRACE, LINK_PLUGIN_SUBSYSTEM,
"<-- linked_attrs_add_post_op\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
static int
@@ -1822,7 +1823,7 @@ linked_attrs_del_post_op(Slapi_PBlock *pb)
/* Just bail if we aren't ready to service requests yet. */
if (!g_plugin_started || !linked_attrs_oktodo(pb))
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
/* Reload config if a config entry was deleted. */
if ((dn = linked_attrs_get_dn(pb))) {
@@ -1852,7 +1853,7 @@ linked_attrs_del_post_op(Slapi_PBlock *pb)
/* Bail out if the plug-in close function was just called. */
if (!g_plugin_started) {
linked_attrs_unlock();
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
linked_attrs_find_config(dn, type, &config);
@@ -1920,7 +1921,7 @@ linked_attrs_del_post_op(Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_TRACE, LINK_PLUGIN_SUBSYSTEM,
"<-- linked_attrs_del_post_op\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
static int
@@ -1932,7 +1933,7 @@ linked_attrs_modrdn_post_op(Slapi_PBlock *pb)
Slapi_Attr *attr = NULL;
char *type = NULL;
struct configEntry *config = NULL;
- int rc = 0;
+ int rc = SLAPI_PLUGIN_SUCCESS;
slapi_log_error(SLAPI_LOG_TRACE, LINK_PLUGIN_SUBSYSTEM,
"--> linked_attrs_modrdn_post_op\n");
@@ -1978,7 +1979,7 @@ linked_attrs_modrdn_post_op(Slapi_PBlock *pb)
/* Bail out if the plug-in close function was just called. */
if (!g_plugin_started) {
linked_attrs_unlock();
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
linked_attrs_find_config(old_dn, type, &config);
@@ -2069,7 +2070,10 @@ linked_attrs_modrdn_post_op(Slapi_PBlock *pb)
done:
slapi_log_error(SLAPI_LOG_TRACE, LINK_PLUGIN_SUBSYSTEM,
"<-- linked_attrs_modrdn_post_op\n");
-
+ if (rc) {
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &rc);
+ rc = SLAPI_PLUGIN_FAILURE;
+ }
return rc;
}
diff --git a/ldap/servers/plugins/memberof/memberof.c b/ldap/servers/plugins/memberof/memberof.c
index e362cab..5aa22fd 100644
--- a/ldap/servers/plugins/memberof/memberof.c
+++ b/ldap/servers/plugins/memberof/memberof.c
@@ -380,7 +380,7 @@ int memberof_postop_close(Slapi_PBlock *pb)
*/
int memberof_postop_del(Slapi_PBlock *pb)
{
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
MemberOfConfig configCopy = {0, 0, 0, 0};
Slapi_DN *sdn;
void *caller_id = NULL;
@@ -393,7 +393,7 @@ int memberof_postop_del(Slapi_PBlock *pb)
slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &caller_id);
if (caller_id == memberof_get_plugin_id()) {
/* Just return without processing */
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if(memberof_oktodo(pb) && (sdn = memberof_getsdn(pb)))
@@ -626,7 +626,7 @@ int memberof_call_foreach_dn(Slapi_PBlock *pb, Slapi_DN *sdn,
*/
int memberof_postop_modrdn(Slapi_PBlock *pb)
{
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
void *caller_id = NULL;
slapi_log_error( SLAPI_LOG_TRACE, MEMBEROF_PLUGIN_SUBSYSTEM,
@@ -637,7 +637,7 @@ int memberof_postop_modrdn(Slapi_PBlock *pb)
slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &caller_id);
if (caller_id == memberof_get_plugin_id()) {
/* Just return without processing */
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if(memberof_oktodo(pb))
@@ -801,7 +801,7 @@ int memberof_replace_dn_type_callback(Slapi_Entry *e, void *callback_data)
*/
int memberof_postop_modify(Slapi_PBlock *pb)
{
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
Slapi_DN *sdn = NULL;
Slapi_Mods *smods = 0;
Slapi_Mod *smod = 0;
@@ -817,7 +817,7 @@ int memberof_postop_modify(Slapi_PBlock *pb)
slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &caller_id);
if (caller_id == memberof_get_plugin_id()) {
/* Just return without processing */
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if(memberof_oktodo(pb) && (sdn = memberof_getsdn(pb)))
@@ -945,7 +945,7 @@ int memberof_postop_modify(Slapi_PBlock *pb)
*/
int memberof_postop_add(Slapi_PBlock *pb)
{
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
int interested = 0;
Slapi_DN *sdn = 0;
void *caller_id = NULL;
@@ -958,7 +958,7 @@ int memberof_postop_add(Slapi_PBlock *pb)
slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &caller_id);
if (caller_id == memberof_get_plugin_id()) {
/* Just return without processing */
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if(memberof_oktodo(pb) && (sdn = memberof_getsdn(pb)))
diff --git a/ldap/servers/plugins/mep/mep.c b/ldap/servers/plugins/mep/mep.c
index d4835ce..3e63773 100644
--- a/ldap/servers/plugins/mep/mep.c
+++ b/ldap/servers/plugins/mep/mep.c
@@ -1984,7 +1984,7 @@ mep_pre_op(Slapi_PBlock * pb, int modop)
char *errstr = NULL;
struct configEntry *config = NULL;
void *caller_id = NULL;
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
slapi_log_error(SLAPI_LOG_TRACE, MEP_PLUGIN_SUBSYSTEM,
"--> mep_pre_op\n");
@@ -2268,7 +2268,8 @@ mep_pre_op(Slapi_PBlock * pb, int modop)
"mep_pre_op: operation failure [%d]\n", ret);
slapi_send_ldap_result(pb, ret, NULL, errstr, 0, NULL);
slapi_ch_free((void **)&errstr);
- ret = -1;
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ret);
+ ret = SLAPI_PLUGIN_FAILURE;
}
slapi_log_error(SLAPI_LOG_TRACE, MEP_PLUGIN_SUBSYSTEM,
@@ -2322,7 +2323,7 @@ mep_mod_post_op(Slapi_PBlock *pb)
/* Just bail if we aren't ready to service requests yet. */
if (!g_plugin_started)
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
if (mep_oktodo(pb) && (sdn = mep_get_sdn(pb))) {
/* First check if the config or a template is being modified. */
@@ -2439,7 +2440,7 @@ mep_mod_post_op(Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_TRACE, MEP_PLUGIN_SUBSYSTEM,
"<-- mep_mod_post_op\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
static int
@@ -2454,7 +2455,7 @@ mep_add_post_op(Slapi_PBlock *pb)
/* Just bail if we aren't ready to service requests yet. */
if (!g_plugin_started || !mep_oktodo(pb))
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
/* Reload config if a config entry was added. */
if ((sdn = mep_get_sdn(pb))) {
@@ -2469,7 +2470,7 @@ mep_add_post_op(Slapi_PBlock *pb)
/* If replication, just bail. */
if (mep_isrepl(pb)) {
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
/* Get the newly added entry. */
@@ -2478,7 +2479,7 @@ mep_add_post_op(Slapi_PBlock *pb)
if (e) {
/* If the entry is a tombstone, just bail. */
if (mep_has_tombstone_value(e)) {
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
/* Check if a config entry applies
@@ -2488,7 +2489,7 @@ mep_add_post_op(Slapi_PBlock *pb)
/* Bail out if the plug-in close function was just called. */
if (!g_plugin_started) {
mep_config_unlock();
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
mep_find_config(e, &config);
@@ -2506,7 +2507,7 @@ mep_add_post_op(Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_TRACE, MEP_PLUGIN_SUBSYSTEM,
"<-- mep_add_post_op\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
static int
@@ -2520,7 +2521,7 @@ mep_del_post_op(Slapi_PBlock *pb)
/* Just bail if we aren't ready to service requests yet. */
if (!g_plugin_started || !mep_oktodo(pb)) {
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
/* Reload config if a config entry was deleted. */
@@ -2535,7 +2536,7 @@ mep_del_post_op(Slapi_PBlock *pb)
/* If replication, just bail. */
if (mep_isrepl(pb)) {
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
/* Get deleted entry, then go through types to find config. */
@@ -2546,7 +2547,7 @@ mep_del_post_op(Slapi_PBlock *pb)
/* If the entry is a tombstone, just bail. */
if (mep_has_tombstone_value(e)) {
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
/* See if we're an origin entry . */
@@ -2575,7 +2576,7 @@ mep_del_post_op(Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_TRACE, MEP_PLUGIN_SUBSYSTEM,
"<-- mep_del_post_op\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
static int
@@ -2593,7 +2594,7 @@ mep_modrdn_post_op(Slapi_PBlock *pb)
/* Just bail if we aren't ready to service requests yet. */
if (!g_plugin_started || !mep_oktodo(pb))
- return 0;;
+ return SLAPI_PLUGIN_SUCCESS;;
/* Reload config if an existing config entry was renamed,
* or if the new dn brings an entry into the scope of the
@@ -2606,7 +2607,7 @@ mep_modrdn_post_op(Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_PLUGIN, MEP_PLUGIN_SUBSYSTEM,
"mep_modrdn_post_op: Error "
"retrieving post-op entry\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if ((old_sdn = mep_get_sdn(pb))) {
@@ -2620,12 +2621,12 @@ mep_modrdn_post_op(Slapi_PBlock *pb)
/* If replication, just bail. */
if (mep_isrepl(pb)) {
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
/* If the entry is a tombstone, just bail. */
if (mep_has_tombstone_value(post_e)) {
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
/* See if we're an origin entry . */
@@ -2647,7 +2648,7 @@ mep_modrdn_post_op(Slapi_PBlock *pb)
if (!g_plugin_started) {
mep_config_unlock();
slapi_pblock_destroy(mep_pb);
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
mep_find_config(post_e, &config);
@@ -2818,7 +2819,7 @@ bailmod:
/* Bail out if the plug-in close function was just called. */
if (!g_plugin_started) {
mep_config_unlock();
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
mep_find_config(post_e, &config);
@@ -2832,7 +2833,7 @@ bailmod:
slapi_log_error(SLAPI_LOG_TRACE, MEP_PLUGIN_SUBSYSTEM,
"<-- mep_modrdn_post_op\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
static int
diff --git a/ldap/servers/plugins/pam_passthru/pam_ptpreop.c b/ldap/servers/plugins/pam_passthru/pam_ptpreop.c
index 7d9ff8b..abf93e3 100644
--- a/ldap/servers/plugins/pam_passthru/pam_ptpreop.c
+++ b/ldap/servers/plugins/pam_passthru/pam_ptpreop.c
@@ -229,7 +229,7 @@ pam_passthruauth_init( Slapi_PBlock *pb )
slapi_log_error( SLAPI_LOG_TRACE, PAM_PASSTHRU_PLUGIN_SUBSYSTEM,
"<= pam_passthruauth_init\n" );
- bail:
+bail:
return status;
}
@@ -574,7 +574,7 @@ pam_passthru_preop(Slapi_PBlock *pb, int modtype)
Slapi_Entry *e = NULL;
LDAPMod **mods;
char returntext[SLAPI_DSE_RETURNTEXT_SIZE];
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
slapi_log_error(SLAPI_LOG_TRACE, PAM_PASSTHRU_PLUGIN_SUBSYSTEM,
"=> pam_passthru_preop\n");
@@ -640,11 +640,11 @@ pam_passthru_preop(Slapi_PBlock *pb, int modtype)
}
- bail:
+bail:
/* If we are refusing the operation, return the result to the client. */
if (ret) {
slapi_send_ldap_result(pb, ret, NULL, returntext, 0, NULL);
- ret = -1;
+ ret = SLAPI_PLUGIN_FAILURE;
}
slapi_log_error(SLAPI_LOG_TRACE, PAM_PASSTHRU_PLUGIN_SUBSYSTEM,
@@ -683,7 +683,7 @@ pam_passthru_modrdn_preop(Slapi_PBlock *pb)
static int
pam_passthru_postop(Slapi_PBlock *pb)
{
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
Slapi_DN *sdn = NULL;
Slapi_DN *new_sdn = NULL;
Slapi_Entry *e = NULL;
@@ -737,7 +737,7 @@ pam_passthru_postop(Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_TRACE, PAM_PASSTHRU_PLUGIN_SUBSYSTEM,
"<= pam_passthru_postop\n");
- bail:
+bail:
return ret;
}
diff --git a/ldap/servers/plugins/referint/referint.c b/ldap/servers/plugins/referint/referint.c
index 234c322..d31f53c 100644
--- a/ldap/servers/plugins/referint/referint.c
+++ b/ldap/servers/plugins/referint/referint.c
@@ -194,7 +194,7 @@ referint_postop_del( Slapi_PBlock *pb )
if (0 == refint_started) {
/* not initialized yet */
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if ( slapi_pblock_get( pb, SLAPI_IS_REPLICATED_OPERATION, &isrepop ) != 0 ||
@@ -203,33 +203,33 @@ referint_postop_del( Slapi_PBlock *pb )
{
slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
"referint_postop_del: could not get parameters\n" );
- return( -1 );
+ return SLAPI_PLUGIN_FAILURE;
}
/*
* This plugin should only execute if the delete was successful
* and this is not a replicated op(unless its allowed)
*/
if(oprc != 0 || (isrepop && !allow_repl)){
- return( 0 );
+ return SLAPI_PLUGIN_SUCCESS;
}
/* get the args */
if ( slapi_pblock_get( pb, SLAPI_PLUGIN_ARGC, &argc ) != 0) {
slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
"referint_postop failed to get argc\n" );
- return( -1 );
+ return SLAPI_PLUGIN_FAILURE;
}
if ( slapi_pblock_get( pb, SLAPI_PLUGIN_ARGV, &argv ) != 0) {
slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
"referint_postop failed to get argv\n" );
- return( -1 );
+ return SLAPI_PLUGIN_FAILURE;
}
-
+
if(argv == NULL){
slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
"referint_postop_del, args are NULL\n" );
- return( -1 );
+ return SLAPI_PLUGIN_FAILURE;
}
-
+
if (argc >= 3) {
/* argv[0] will be the delay */
delay = atoi(argv[0]);
@@ -239,19 +239,19 @@ referint_postop_del( Slapi_PBlock *pb )
if(delay == -1){
/* integrity updating is off */
- rc = 0;
+ rc = SLAPI_PLUGIN_SUCCESS;
} else if(delay == 0){ /* no delay */
/* call function to update references to entry */
rc = update_integrity(argv, sdn, NULL, NULL, logChanges);
} else {
/* write the entry to integrity log */
writeintegritylog(pb, argv[1], sdn, NULL, NULL, NULL /* slapi_get_requestor_sdn(pb) */);
- rc = 0;
+ rc = SLAPI_PLUGIN_SUCCESS;
}
} else {
slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
"referint_postop insufficient arguments supplied\n" );
- return( -1 );
+ return SLAPI_PLUGIN_FAILURE;
}
return( rc );
@@ -279,30 +279,30 @@ referint_postop_modrdn( Slapi_PBlock *pb )
{
slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
"referint_postop_modrdn: could not get parameters\n" );
- return( -1 );
+ return SLAPI_PLUGIN_FAILURE;
}
/*
* This plugin should only execute if the delete was successful
* and this is not a replicated op (unless its allowed)
*/
if(oprc != 0 || (isrepop && !allow_repl)){
- return( 0 );
+ return SLAPI_PLUGIN_SUCCESS;
}
/* get the args */
if ( slapi_pblock_get( pb, SLAPI_PLUGIN_ARGC, &argc ) != 0) {
slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
"referint_postop failed to get argv\n" );
- return( -1 );
+ return SLAPI_PLUGIN_FAILURE;
}
if ( slapi_pblock_get( pb, SLAPI_PLUGIN_ARGV, &argv ) != 0) {
slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
"referint_postop failed to get argv\n" );
- return( -1 );
+ return SLAPI_PLUGIN_FAILURE;
}
if(argv == NULL){
slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
"referint_postop_modrdn, args are NULL\n" );
- return( -1 );
+ return SLAPI_PLUGIN_FAILURE;
}
if (argc >= 3) {
@@ -314,19 +314,19 @@ referint_postop_modrdn( Slapi_PBlock *pb )
} else {
slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
"referint_postop_modrdn insufficient arguments supplied\n" );
- return( -1 );
+ return SLAPI_PLUGIN_FAILURE;
}
if(delay == -1){
/* integrity updating is off */
- rc = 0;
+ rc = SLAPI_PLUGIN_SUCCESS;
} else if(delay == 0){ /* no delay */
/* call function to update references to entry */
rc = update_integrity(argv, sdn, newrdn, newsuperior, logChanges);
} else {
/* write the entry to integrity log */
writeintegritylog(pb, argv[1], sdn, newrdn, newsuperior, NULL /* slapi_get_requestor_sdn(pb) */);
- rc = 0;
+ rc = SLAPI_PLUGIN_SUCCESS;
}
return( rc );
@@ -720,12 +720,12 @@ update_integrity(char **argv, Slapi_DN *origSDN,
int search_result;
int nval = 0;
int i, j;
- int rc;
+ int rc = SLAPI_PLUGIN_SUCCESS;
if ( argv == NULL ){
slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
"referint_postop required config file arguments missing\n" );
- rc = -1;
+ rc = SLAPI_PLUGIN_FAILURE;
goto free_and_return;
}
/*
@@ -818,7 +818,7 @@ update_integrity(char **argv, Slapi_DN *origSDN,
slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
"update_integrity search (base=%s filter=%s) returned "
"error %d\n", search_base, filter, search_result);
- rc = -1;
+ rc = SLAPI_PLUGIN_FAILURE;
goto free_and_return;
}
}
@@ -828,7 +828,7 @@ update_integrity(char **argv, Slapi_DN *origSDN,
}
}
/* if got here, then everything good rc = 0 */
- rc = 0;
+ rc = SLAPI_PLUGIN_SUCCESS;
free_and_return:
/* free filter and search_results_pb */
@@ -878,7 +878,7 @@ int referint_postop_start( Slapi_PBlock *pb)
keeprunning_mutex = PR_NewLock();
keeprunning_cv = PR_NewCondVar(keeprunning_mutex);
keeprunning =1;
-
+
referint_tid = PR_CreateThread (PR_USER_THREAD,
referint_thread_func,
(void *)argv,
@@ -1075,7 +1075,7 @@ int my_fgetc(PRFileDesc *stream)
}
return retval;
-}
+}
int
GetNextLine(char *dest, int size_dest, PRFileDesc *stream) {
@@ -1083,7 +1083,7 @@ GetNextLine(char *dest, int size_dest, PRFileDesc *stream) {
char nextchar ='\0';
int done = 0;
int i = 0;
-
+
while(!done){
if( ( nextchar = my_fgetc(stream) ) != 0){
if( i < (size_dest - 1) ){
diff --git a/ldap/servers/plugins/replication/repl5.h b/ldap/servers/plugins/replication/repl5.h
index 0fa7ee4..b2c69a3 100644
--- a/ldap/servers/plugins/replication/repl5.h
+++ b/ldap/servers/plugins/replication/repl5.h
@@ -217,10 +217,6 @@ int multimaster_bepreop_add (Slapi_PBlock *pb);
int multimaster_bepreop_delete (Slapi_PBlock *pb);
int multimaster_bepreop_modify (Slapi_PBlock *pb);
int multimaster_bepreop_modrdn (Slapi_PBlock *pb);
-int multimaster_betxnpreop_add (Slapi_PBlock *pb);
-int multimaster_betxnpreop_delete (Slapi_PBlock *pb);
-int multimaster_betxnpreop_modify (Slapi_PBlock *pb);
-int multimaster_betxnpreop_modrdn (Slapi_PBlock *pb);
int replica_ruv_smods_for_op (Slapi_PBlock *pb, char **uniqueid,
Slapi_Mods **smods);
int multimaster_bepostop_modrdn (Slapi_PBlock *pb);
diff --git a/ldap/servers/plugins/replication/repl5_plugins.c b/ldap/servers/plugins/replication/repl5_plugins.c
index c2e95dc..4c048dc 100644
--- a/ldap/servers/plugins/replication/repl5_plugins.c
+++ b/ldap/servers/plugins/replication/repl5_plugins.c
@@ -190,13 +190,13 @@ multimaster_preop_add (Slapi_PBlock *pb)
copy_operation_parameters(pb);
slapi_operation_set_csngen_handler(op,
(void*)replica_generate_next_csn);
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if (!is_mmr_replica (pb))
{
copy_operation_parameters(pb);
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
is_replicated_operation= operation_is_flag_set(op,OP_FLAG_REPLICATED);
@@ -241,7 +241,7 @@ multimaster_preop_add (Slapi_PBlock *pb)
slapi_ch_free ((void**)&target_uuid);
slapi_ch_free ((void**)&superior_uuid);
- return -1;
+ return SLAPI_PLUGIN_FAILURE;
}
operation_set_csn(op, csn);
@@ -296,7 +296,7 @@ multimaster_preop_add (Slapi_PBlock *pb)
copy_operation_parameters(pb);
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
int
@@ -320,13 +320,13 @@ multimaster_preop_delete (Slapi_PBlock *pb)
slapi_operation_set_replica_attr_handler ( op, (void*)replica_get_attr );
slapi_operation_set_csngen_handler(op,
(void*)replica_generate_next_csn);
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if (!is_mmr_replica (pb))
{
copy_operation_parameters(pb);
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
is_replicated_operation= operation_is_flag_set(op,OP_FLAG_REPLICATED);
@@ -366,7 +366,7 @@ multimaster_preop_delete (Slapi_PBlock *pb)
csn_free (&csn);
slapi_ch_free ((void**)&target_uuid);
- return -1;
+ return SLAPI_PLUGIN_FAILURE;
}
/*
@@ -396,7 +396,7 @@ multimaster_preop_delete (Slapi_PBlock *pb)
copy_operation_parameters(pb);
slapi_operation_set_replica_attr_handler ( op, (void*)replica_get_attr );
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
int
@@ -419,13 +419,13 @@ multimaster_preop_modify (Slapi_PBlock *pb)
copy_operation_parameters(pb);
slapi_operation_set_csngen_handler(op,
(void*)replica_generate_next_csn);
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if (!is_mmr_replica (pb))
{
copy_operation_parameters(pb);
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
is_replicated_operation= operation_is_flag_set(op,OP_FLAG_REPLICATED);
@@ -465,7 +465,7 @@ multimaster_preop_modify (Slapi_PBlock *pb)
csn_free (&csn);
slapi_ch_free ((void**)&target_uuid);
- return -1;
+ return SLAPI_PLUGIN_FAILURE;
}
/*
@@ -498,7 +498,7 @@ multimaster_preop_modify (Slapi_PBlock *pb)
}
copy_operation_parameters(pb);
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
int
@@ -521,13 +521,13 @@ multimaster_preop_modrdn (Slapi_PBlock *pb)
copy_operation_parameters(pb);
slapi_operation_set_csngen_handler(op,
(void*)replica_generate_next_csn);
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if (!is_mmr_replica (pb))
{
copy_operation_parameters(pb);
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
is_replicated_operation= operation_is_flag_set(op,OP_FLAG_REPLICATED);
@@ -577,7 +577,7 @@ multimaster_preop_modrdn (Slapi_PBlock *pb)
slapi_ch_free ((void**)&newsuperior_uuid);
ldap_mods_free (modrdn_mods, 1);
- return -1;
+ return SLAPI_PLUGIN_FAILURE;
}
operation_set_csn(op, csn);
@@ -625,19 +625,19 @@ multimaster_preop_modrdn (Slapi_PBlock *pb)
copy_operation_parameters(pb);
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
int
multimaster_preop_search (Slapi_PBlock *pb)
{
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
int
multimaster_preop_compare (Slapi_PBlock *pb)
{
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
int
@@ -651,7 +651,7 @@ multimaster_ruv_search(Slapi_PBlock *pb)
slapi_pblock_get( pb, SLAPI_OPERATION, &operation);
if ((e == NULL) || (operation == NULL))
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
if (!operation_is_flag_set(operation, OP_FLAG_INTERNAL) && is_ruv_tombstone_entry(e)) {
/* We are about to send back the database RUV, we need to return
@@ -670,7 +670,7 @@ multimaster_ruv_search(Slapi_PBlock *pb)
slapi_sdn_free(&suffix_sdn);
}
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
static void
@@ -737,7 +737,7 @@ purge_entry_state_information (Slapi_PBlock *pb)
int
multimaster_bepreop_add (Slapi_PBlock *pb)
{
- int rc= 0;
+ int rc= SLAPI_PLUGIN_SUCCESS;
Slapi_Operation *op;
int is_replicated_operation;
int is_fixup_operation;
@@ -762,7 +762,7 @@ multimaster_bepreop_add (Slapi_PBlock *pb)
int
multimaster_bepreop_delete (Slapi_PBlock *pb)
{
- int rc= 0;
+ int rc= SLAPI_PLUGIN_SUCCESS;
Slapi_Operation *op;
int is_replicated_operation;
int is_fixup_operation;
@@ -787,7 +787,7 @@ multimaster_bepreop_delete (Slapi_PBlock *pb)
int
multimaster_bepreop_modify (Slapi_PBlock *pb)
{
- int rc= 0;
+ int rc= SLAPI_PLUGIN_SUCCESS;
Slapi_Operation *op;
int is_replicated_operation;
int is_fixup_operation;
@@ -815,7 +815,7 @@ multimaster_bepreop_modify (Slapi_PBlock *pb)
int
multimaster_bepreop_modrdn (Slapi_PBlock *pb)
{
- int rc= 0;
+ int rc= SLAPI_PLUGIN_SUCCESS;
Slapi_Operation *op;
int is_replicated_operation;
int is_fixup_operation;
@@ -840,99 +840,6 @@ multimaster_bepreop_modrdn (Slapi_PBlock *pb)
return rc;
}
-/* betxn preop's */
-int
-multimaster_betxnpreop_add (Slapi_PBlock *pb)
-{
- int rc= 0;
- Slapi_Operation *op;
- int is_replicated_operation;
- int is_fixup_operation;
-
- slapi_pblock_get(pb, SLAPI_OPERATION, &op);
- is_replicated_operation= operation_is_flag_set(op,OP_FLAG_REPLICATED);
- is_fixup_operation= operation_is_flag_set(op,OP_FLAG_REPL_FIXUP);
-
- /* For replicated operations, apply URP algorithm */
- if (!is_fixup_operation)
- {
- if (is_replicated_operation) {
- rc = urp_add_operation(pb);
- }
- }
-
- return rc;
-}
-
-int
-multimaster_betxnpreop_delete (Slapi_PBlock *pb)
-{
- int rc= 0;
- Slapi_Operation *op;
- int is_replicated_operation;
- int is_fixup_operation;
-
- slapi_pblock_get(pb, SLAPI_OPERATION, &op);
- is_replicated_operation= operation_is_flag_set(op,OP_FLAG_REPLICATED);
- is_fixup_operation= operation_is_flag_set(op,OP_FLAG_REPL_FIXUP);
-
- /* For replicated operations, apply URP algorithm */
- if(!is_fixup_operation)
- {
- if (is_replicated_operation) {
- rc = urp_delete_operation(pb);
- }
- }
-
- return rc;
-}
-
-int
-multimaster_betxnpreop_modify (Slapi_PBlock *pb)
-{
- int rc= 0;
- Slapi_Operation *op;
- int is_replicated_operation;
- int is_fixup_operation;
-
- slapi_pblock_get(pb, SLAPI_OPERATION, &op);
- is_replicated_operation= operation_is_flag_set(op,OP_FLAG_REPLICATED);
- is_fixup_operation= operation_is_flag_set(op,OP_FLAG_REPL_FIXUP);
-
- /* For replicated operations, apply URP algorithm */
- if(!is_fixup_operation)
- {
- if (is_replicated_operation) {
- rc = urp_modify_operation(pb);
- }
- }
-
- return rc;
-}
-
-int
-multimaster_betxnpreop_modrdn (Slapi_PBlock *pb)
-{
- int rc= 0;
- Slapi_Operation *op;
- int is_replicated_operation;
- int is_fixup_operation;
-
- slapi_pblock_get(pb, SLAPI_OPERATION, &op);
- is_replicated_operation= operation_is_flag_set(op,OP_FLAG_REPLICATED);
- is_fixup_operation= operation_is_flag_set(op,OP_FLAG_REPL_FIXUP);
-
- /* For replicated operations, apply URP algorithm */
- if(!is_fixup_operation)
- {
- if (is_replicated_operation) {
- rc = urp_modrdn_operation(pb);
- }
- }
-
- return rc;
-}
-
int
multimaster_bepostop_modrdn (Slapi_PBlock *pb)
{
@@ -943,7 +850,7 @@ multimaster_bepostop_modrdn (Slapi_PBlock *pb)
{
urp_post_modrdn_operation (pb);
}
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
int
@@ -956,14 +863,14 @@ multimaster_bepostop_delete (Slapi_PBlock *pb)
{
urp_post_delete_operation (pb);
}
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
/* postop - write to changelog */
int
multimaster_postop_bind (Slapi_PBlock *pb)
{
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
int
@@ -1018,7 +925,7 @@ multimaster_betxnpostop_modify (Slapi_PBlock *pb)
int
multimaster_be_betxnpostop_delete (Slapi_PBlock *pb)
{
- int rc = 0;
+ int rc = SLAPI_PLUGIN_SUCCESS;
/* original betxnpost */
rc = write_changelog_and_ruv(pb);
/* original bepost */
@@ -1152,7 +1059,7 @@ write_changelog_and_ruv (Slapi_PBlock *pb)
int rc;
slapi_operation_parameters *op_params = NULL;
Object *repl_obj;
- int return_value = 0;
+ int return_value = SLAPI_PLUGIN_SUCCESS;
Replica *r;
Slapi_Backend *be;
int is_replicated_operation = 0;
@@ -1162,7 +1069,7 @@ write_changelog_and_ruv (Slapi_PBlock *pb)
if ((operation_is_flag_set(op, OP_FLAG_REPL_FIXUP)) ||
(operation_is_flag_set(op, OP_FLAG_TOMBSTONE_ENTRY)))
{
- return 0;
+ return return_value;
}
/* ignore operations intended for chaining backends - they will be
@@ -1174,18 +1081,18 @@ write_changelog_and_ruv (Slapi_PBlock *pb)
if (!is_replicated_operation &&
slapi_be_is_flag_set(be,SLAPI_BE_FLAG_REMOTE_DATA))
{
- return 0;
+ return return_value;
}
slapi_pblock_get(pb, SLAPI_RESULT_CODE, &rc);
if (rc) { /* op failed - just return */
- return 0;
+ return return_value;
}
/* we only log changes for operations applied to a replica */
repl_obj = replica_get_replica_for_op (pb);
if (repl_obj == NULL)
- return 0;
+ return return_value;
r = (Replica*)object_get_data (repl_obj);
PR_ASSERT (r);
@@ -1247,7 +1154,7 @@ write_changelog_and_ruv (Slapi_PBlock *pb)
if( op_params->csn && is_cleaned_rid(csn_get_replicaid(op_params->csn))){
/* this RID has been cleaned */
object_release (repl_obj);
- return 0;
+ return return_value;
}
/* we might have stripped all the mods - in that case we do not
@@ -1260,7 +1167,7 @@ write_changelog_and_ruv (Slapi_PBlock *pb)
{
slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
"write_changelog_and_ruv: Skipped due to DISKFULL\n");
- return 0;
+ return return_value;
}
slapi_pblock_get(pb, SLAPI_TXN, &txn);
rc = cl5WriteOperationTxn(repl_name, repl_gen, op_params,
@@ -1276,7 +1183,7 @@ write_changelog_and_ruv (Slapi_PBlock *pb)
op_params->target_address.uniqueid,
op_params->operation_type,
csn_as_string(op_params->csn, PR_FALSE, csn_str));
- return_value = 1;
+ return_value = SLAPI_PLUGIN_FAILURE;
}
}
@@ -1346,7 +1253,7 @@ process_postop (Slapi_PBlock *pb)
if ((operation_is_flag_set(op, OP_FLAG_REPL_FIXUP)) ||
(operation_is_flag_set(op, OP_FLAG_TOMBSTONE_ENTRY)))
{
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
/* ignore operations intended for chaining backends - they will be
@@ -1358,24 +1265,27 @@ process_postop (Slapi_PBlock *pb)
if (!is_replicated_operation &&
slapi_be_is_flag_set(be,SLAPI_BE_FLAG_REMOTE_DATA))
{
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
get_repl_session_id (pb, sessionid, &opcsn);
- slapi_pblock_get(pb, SLAPI_RESULT_CODE, &rc);
+ slapi_pblock_get(pb, SLAPI_RESULT_CODE, &rc);
if (rc == LDAP_SUCCESS)
{
- agmtlist_notify_all(pb);
+ agmtlist_notify_all(pb);
+ rc = SLAPI_PLUGIN_SUCCESS;
}
- else if (opcsn)
+ else if (opcsn)
{
- rc = cancel_opcsn (pb);
+ rc = cancel_opcsn (pb);
/* Don't try to get session id since conn is always null */
slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name,
"%s process postop: canceling operation csn\n", sessionid);
- }
+ } else {
+ rc = SLAPI_PLUGIN_FAILURE;
+ }
/* the target unique id is set in the modify_preop above, so
we need to free it */
@@ -1469,7 +1379,7 @@ cancel_opcsn (Slapi_PBlock *pb)
object_release (repl_obj);
}
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
diff --git a/ldap/servers/plugins/retrocl/retrocl_po.c b/ldap/servers/plugins/retrocl/retrocl_po.c
index c3d1c41..382c98a 100644
--- a/ldap/servers/plugins/retrocl/retrocl_po.c
+++ b/ldap/servers/plugins/retrocl/retrocl_po.c
@@ -581,24 +581,24 @@ int retrocl_postob (Slapi_PBlock *pb,int optype)
if (slapi_be_logchanges(be) == 0) {
LDAPDebug0Args(LDAP_DEBUG_TRACE,"not applying change if not logging\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if (retrocl_be_changelog == NULL || be == retrocl_be_changelog) {
LDAPDebug0Args(LDAP_DEBUG_TRACE,"not applying change if no/cl be\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
slapi_pblock_get(pb, SLAPI_RESULT_CODE, &rc);
if (rc != LDAP_SUCCESS) {
LDAPDebug1Arg(LDAP_DEBUG_TRACE,"not applying change if op failed %d\n",rc);
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if (slapi_op_abandoned(pb)) {
LDAPDebug0Args(LDAP_DEBUG_PLUGIN,"not applying change if op abandoned\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
curtime = current_time();
@@ -613,12 +613,12 @@ int retrocl_postob (Slapi_PBlock *pb,int optype)
if (op == NULL) {
LDAPDebug0Args(LDAP_DEBUG_TRACE,"not applying change if no op\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
if (operation_is_flag_set(op, OP_FLAG_TOMBSTONE_ENTRY)){
LDAPDebug0Args(LDAP_DEBUG_TRACE,"not applying change for nsTombstone entries\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
switch ( optype ) {
diff --git a/ldap/servers/plugins/roles/roles_plugin.c b/ldap/servers/plugins/roles/roles_plugin.c
index 9db76ca..b00e9a7 100644
--- a/ldap/servers/plugins/roles/roles_plugin.c
+++ b/ldap/servers/plugins/roles/roles_plugin.c
@@ -355,7 +355,7 @@ static int roles_post_op( Slapi_PBlock *pb )
roles_cache_change_notify(pb);
slapi_log_error( SLAPI_LOG_PLUGIN, ROLES_PLUGIN_SUBSYSTEM, "<-- roles_post_op\n");
- return 0; /* always succeed */
+ return SLAPI_PLUGIN_SUCCESS; /* always succeed */
}
static void roles_set_plugin_identity(void * identity)
diff --git a/ldap/servers/plugins/statechange/statechange.c b/ldap/servers/plugins/statechange/statechange.c
index 0b2b737..307ea75 100644
--- a/ldap/servers/plugins/statechange/statechange.c
+++ b/ldap/servers/plugins/statechange/statechange.c
@@ -110,7 +110,7 @@ void plugin_init_debug_level(int *level_ptr)
*/
int statechange_init( Slapi_PBlock *pb )
{
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
Slapi_Entry *plugin_entry = NULL;
char *plugin_type = NULL;
int postadd = SLAPI_PLUGIN_POST_ADD_FN;
@@ -148,7 +148,7 @@ int statechange_init( Slapi_PBlock *pb )
{
slapi_log_error( SLAPI_LOG_FATAL, SCN_PLUGIN_SUBSYSTEM,
"statechange_init: failed to register plugin\n" );
- ret = -1;
+ ret = SLAPI_PLUGIN_FAILURE;
}
slapi_log_error( SLAPI_LOG_TRACE, SCN_PLUGIN_SUBSYSTEM, "<-- statechange_init\n");
@@ -163,7 +163,7 @@ int statechange_init( Slapi_PBlock *pb )
*/
static int statechange_start( Slapi_PBlock *pb )
{
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
slapi_log_error( SLAPI_LOG_TRACE, SCN_PLUGIN_SUBSYSTEM, "--> statechange_start\n");
@@ -177,14 +177,14 @@ static int statechange_start( Slapi_PBlock *pb )
{
/* badness */
slapi_log_error( SLAPI_LOG_FATAL, SCN_PLUGIN_SUBSYSTEM, "statechange: failed to create lock\n");
- ret = -1;
+ ret = SLAPI_PLUGIN_FAILURE;
}
else
{
if( slapi_apib_register(StateChange_v1_0_GUID, api) )
{
slapi_log_error( SLAPI_LOG_FATAL, SCN_PLUGIN_SUBSYSTEM, "statechange: failed to publish state change interface\n");
- ret = -1;
+ ret = SLAPI_PLUGIN_FAILURE;
}
}
@@ -207,7 +207,7 @@ static int statechange_close( Slapi_PBlock *pb )
slapi_log_error( SLAPI_LOG_TRACE, SCN_PLUGIN_SUBSYSTEM, "<-- statechange_close\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
@@ -251,7 +251,7 @@ static int statechange_post_op( Slapi_PBlock *pb, int modtype )
struct slapi_entry *e_after = NULL;
if(head == 0)
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
slapi_log_error( SLAPI_LOG_TRACE, SCN_PLUGIN_SUBSYSTEM, "--> statechange_post_op\n");
@@ -317,13 +317,13 @@ bail:
slapi_unlock_mutex(buffer_lock);
slapi_log_error( SLAPI_LOG_TRACE, SCN_PLUGIN_SUBSYSTEM, "<-- statechange_post_op\n");
- return 0; /* always succeed */
+ return SLAPI_PLUGIN_SUCCESS; /* always succeed */
}
static int _statechange_register(char *caller_id, char *dn, char *filter, void *caller_data, notify_callback func)
{
- int ret = -1;
+ int ret = SLAPI_PLUGIN_FAILURE;
SCNotify *item;
/* simple - we don't check for duplicates */
@@ -352,7 +352,7 @@ static int _statechange_register(char *caller_id, char *dn, char *filter, void *
slapi_ch_free_string(&item->filter);
slapi_ch_free_string(&writable_filter);
slapi_ch_free((void **)&item);
- return -1;
+ return ret;
} else if (!writable_filter) {
item->realfilter = NULL;
}
@@ -375,7 +375,7 @@ static int _statechange_register(char *caller_id, char *dn, char *filter, void *
slapi_unlock_mutex(buffer_lock);
slapi_ch_free_string(&writable_filter);
- ret = 0;
+ ret = SLAPI_PLUGIN_SUCCESS;
}
return ret;
diff --git a/ldap/servers/plugins/usn/usn.c b/ldap/servers/plugins/usn/usn.c
index 4473618..338517f 100644
--- a/ldap/servers/plugins/usn/usn.c
+++ b/ldap/servers/plugins/usn/usn.c
@@ -148,13 +148,13 @@ bail:
static int
usn_preop_init(Slapi_PBlock *pb)
{
- int rc = 0;
+ int rc = SLAPI_PLUGIN_SUCCESS;
int predel = SLAPI_PLUGIN_PRE_DELETE_FN;
if (slapi_pblock_set(pb, predel, (void *)usn_preop_delete) != 0) {
slapi_log_error(SLAPI_LOG_FATAL, USN_PLUGIN_SUBSYSTEM,
"usn_preop_init: failed to register preop plugin\n");
- rc = -1;
+ rc = SLAPI_PLUGIN_FAILURE;
}
return rc;
@@ -163,7 +163,7 @@ usn_preop_init(Slapi_PBlock *pb)
static int
usn_bepreop_init(Slapi_PBlock *pb)
{
- int rc = 0;
+ int rc = SLAPI_PLUGIN_SUCCESS;
int premod = SLAPI_PLUGIN_BE_PRE_MODIFY_FN;
int premdn = SLAPI_PLUGIN_BE_PRE_MODRDN_FN;
@@ -175,7 +175,7 @@ usn_bepreop_init(Slapi_PBlock *pb)
(slapi_pblock_set(pb, premdn, (void *)usn_bepreop_modify) != 0)) {
slapi_log_error(SLAPI_LOG_FATAL, USN_PLUGIN_SUBSYSTEM,
"usn_bepreop_init: failed to register bepreop plugin\n");
- rc = -1;
+ rc = SLAPI_PLUGIN_FAILURE;
}
return rc;
@@ -184,7 +184,7 @@ usn_bepreop_init(Slapi_PBlock *pb)
static int
usn_betxnpreop_init(Slapi_PBlock *pb)
{
- int rc = 0;
+ int rc = SLAPI_PLUGIN_SUCCESS;
int preadd = SLAPI_PLUGIN_BE_TXN_PRE_ADD_FN;
int predel = SLAPI_PLUGIN_BE_TXN_PRE_DELETE_TOMBSTONE_FN;
@@ -192,7 +192,7 @@ usn_betxnpreop_init(Slapi_PBlock *pb)
(slapi_pblock_set(pb, predel, (void *)usn_betxnpreop_delete) != 0)) {
slapi_log_error(SLAPI_LOG_FATAL, USN_PLUGIN_SUBSYSTEM,
"usn_betxnpreop_init: failed to register betxnpreop plugin\n");
- rc = -1;
+ rc = SLAPI_PLUGIN_FAILURE;
}
return rc;
@@ -201,7 +201,7 @@ usn_betxnpreop_init(Slapi_PBlock *pb)
static int
usn_bepostop_init(Slapi_PBlock *pb)
{
- int rc = 0;
+ int rc = SLAPI_PLUGIN_SUCCESS;
Slapi_Entry *plugin_entry = NULL;
char *plugin_type = NULL;
int postadd = SLAPI_PLUGIN_BE_POST_ADD_FN;
@@ -227,7 +227,7 @@ usn_bepostop_init(Slapi_PBlock *pb)
(slapi_pblock_set(pb, postmdn, (void *)usn_bepostop) != 0)) {
slapi_log_error(SLAPI_LOG_FATAL, USN_PLUGIN_SUBSYSTEM,
"usn_bepostop_init: failed to register bepostop plugin\n");
- rc = -1;
+ rc = SLAPI_PLUGIN_FAILURE;
}
return rc;
@@ -236,12 +236,12 @@ usn_bepostop_init(Slapi_PBlock *pb)
static int
usn_rootdse_init()
{
- int rc = -1;
+ int rc = SLAPI_PLUGIN_FAILURE;
if (slapi_config_register_callback(SLAPI_OPERATION_SEARCH, DSE_FLAG_PREOP,
"", LDAP_SCOPE_BASE, "(objectclass=*)",
usn_rootdse_search, NULL)) {
- rc = 0;
+ rc = SLAPI_PLUGIN_SUCCESS;
}
return rc;
@@ -254,7 +254,7 @@ usn_rootdse_init()
static int
usn_start(Slapi_PBlock *pb)
{
- int rc = 0;
+ int rc = SLAPI_PLUGIN_SUCCESS;
Slapi_Value *value;
slapi_log_error(SLAPI_LOG_TRACE, USN_PLUGIN_SUBSYSTEM, "--> usn_start\n");
@@ -262,6 +262,7 @@ usn_start(Slapi_PBlock *pb)
rc = usn_rootdse_init();
rc |= usn_cleanup_start(pb);
if (rc) {
+ rc = SLAPI_PLUGIN_FAILURE;
goto bail;
}
if (0) { /* Not executed; test code for slapi_get_plugin_default_config */
@@ -284,7 +285,9 @@ usn_start(Slapi_PBlock *pb)
/* add nsds5ReplicatedAttributeList: (objectclass=*) $ EXCLUDE entryusn
* to cn=plugin default config,cn=config */
value = slapi_value_new_string("(objectclass=*) $ EXCLUDE entryusn");
- rc = slapi_set_plugin_default_config("nsds5ReplicatedAttributeList", value);
+ if (slapi_set_plugin_default_config("nsds5ReplicatedAttributeList", value)) {
+ rc = SLAPI_PLUGIN_FAILURE;
+ }
slapi_value_free(&value);
g_plugin_started = 1;
bail:
@@ -302,7 +305,7 @@ usn_close(Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_TRACE, USN_PLUGIN_SUBSYSTEM, "<-- usn_close\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
/*
@@ -311,7 +314,6 @@ usn_close(Slapi_PBlock *pb)
static int
usn_preop_delete(Slapi_PBlock *pb)
{
- int rc = 0;
Slapi_Operation *op = NULL;
slapi_log_error(SLAPI_LOG_TRACE, USN_PLUGIN_SUBSYSTEM,
@@ -323,7 +325,7 @@ usn_preop_delete(Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_TRACE, USN_PLUGIN_SUBSYSTEM,
"<-- usn_preop_delete\n");
- return rc;
+ return SLAPI_PLUGIN_SUCCESS;
}
static void
@@ -407,7 +409,7 @@ usn_betxnpreop_add(Slapi_PBlock *pb)
{
Slapi_Entry *e = NULL;
Slapi_Backend *be = NULL;
- int rc = LDAP_SUCCESS;
+ int rc = SLAPI_PLUGIN_SUCCESS;
slapi_log_error(SLAPI_LOG_TRACE, USN_PLUGIN_SUBSYSTEM,
"--> usn_betxnpreop_add\n");
@@ -416,11 +418,15 @@ usn_betxnpreop_add(Slapi_PBlock *pb)
slapi_pblock_get(pb, SLAPI_ADD_ENTRY, &e);
if (NULL == e) {
rc = LDAP_NO_SUCH_OBJECT;
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &rc);
+ rc = SLAPI_PLUGIN_FAILURE;
goto bail;
}
slapi_pblock_get(pb, SLAPI_BACKEND, &be);
if (NULL == be) {
rc = LDAP_PARAM_ERROR;
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &rc);
+ rc = SLAPI_PLUGIN_FAILURE;
goto bail;
}
_usn_add_next_usn(e, be);
@@ -439,7 +445,7 @@ usn_betxnpreop_delete(Slapi_PBlock *pb)
{
Slapi_Entry *e = NULL;
Slapi_Backend *be = NULL;
- int rc = LDAP_SUCCESS;
+ int rc = SLAPI_PLUGIN_SUCCESS;
slapi_log_error(SLAPI_LOG_TRACE, USN_PLUGIN_SUBSYSTEM,
"--> usn_betxnpreop_delete\n");
@@ -448,11 +454,15 @@ usn_betxnpreop_delete(Slapi_PBlock *pb)
slapi_pblock_get(pb, SLAPI_DELETE_BEPREOP_ENTRY, &e);
if (NULL == e) {
rc = LDAP_NO_SUCH_OBJECT;
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &rc);
+ rc = SLAPI_PLUGIN_FAILURE;
goto bail;
}
slapi_pblock_get(pb, SLAPI_BACKEND, &be);
if (NULL == be) {
rc = LDAP_PARAM_ERROR;
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &rc);
+ rc = SLAPI_PLUGIN_FAILURE;
goto bail;
}
_usn_add_next_usn(e, be);
@@ -472,7 +482,7 @@ usn_bepreop_modify (Slapi_PBlock *pb)
{
LDAPMod **mods = NULL;
Slapi_Backend *be = NULL;
- int rc = LDAP_SUCCESS;
+ int rc = SLAPI_PLUGIN_SUCCESS;
slapi_log_error(SLAPI_LOG_TRACE, USN_PLUGIN_SUBSYSTEM,
"--> usn_bepreop_modify\n");
@@ -483,6 +493,9 @@ usn_bepreop_modify (Slapi_PBlock *pb)
if (NULL == be) {
slapi_log_error(SLAPI_LOG_FATAL, USN_PLUGIN_SUBSYSTEM,
"usn_bepreop_modify: no backend.\n");
+ rc = LDAP_PARAM_ERROR;
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &rc);
+ rc = SLAPI_PLUGIN_FAILURE;
goto bail;
}
if (LDAP_SUCCESS == _usn_mod_next_usn(&mods, be)) {
@@ -498,7 +511,7 @@ bail:
static int
usn_bepostop (Slapi_PBlock *pb)
{
- int rc = -1;
+ int rc = SLAPI_PLUGIN_FAILURE;
Slapi_Backend *be = NULL;
slapi_log_error(SLAPI_LOG_TRACE, USN_PLUGIN_SUBSYSTEM,
@@ -507,12 +520,16 @@ usn_bepostop (Slapi_PBlock *pb)
/* if op is not successful, don't increment the counter */
slapi_pblock_get(pb, SLAPI_RESULT_CODE, &rc);
if (LDAP_SUCCESS != rc) {
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &rc);
+ rc = SLAPI_PLUGIN_FAILURE;
goto bail;
}
slapi_pblock_get(pb, SLAPI_BACKEND, &be);
if (NULL == be) {
rc = LDAP_PARAM_ERROR;
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &rc);
+ rc = SLAPI_PLUGIN_FAILURE;
goto bail;
}
@@ -529,7 +546,7 @@ bail:
static int
usn_bepostop_modify (Slapi_PBlock *pb)
{
- int rc = -1;
+ int rc = SLAPI_PLUGIN_FAILURE;
Slapi_Backend *be = NULL;
LDAPMod **mods = NULL;
int i;
@@ -540,6 +557,7 @@ usn_bepostop_modify (Slapi_PBlock *pb)
/* if op is not successful, don't increment the counter */
slapi_pblock_get(pb, SLAPI_RESULT_CODE, &rc);
if (LDAP_SUCCESS != rc) {
+ rc = SLAPI_PLUGIN_FAILURE;
goto bail;
}
@@ -560,6 +578,8 @@ usn_bepostop_modify (Slapi_PBlock *pb)
slapi_pblock_get(pb, SLAPI_BACKEND, &be);
if (NULL == be) {
rc = LDAP_PARAM_ERROR;
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &rc);
+ rc = SLAPI_PLUGIN_FAILURE;
goto bail;
}
@@ -577,7 +597,7 @@ bail:
static int
usn_bepostop_delete (Slapi_PBlock *pb)
{
- int rc = -1;
+ int rc = SLAPI_PLUGIN_FAILURE;
Slapi_Backend *be = NULL;
slapi_log_error(SLAPI_LOG_TRACE, USN_PLUGIN_SUBSYSTEM,
@@ -586,12 +606,15 @@ usn_bepostop_delete (Slapi_PBlock *pb)
/* if op is not successful, don't increment the counter */
slapi_pblock_get(pb, SLAPI_RESULT_CODE, &rc);
if (LDAP_SUCCESS != rc) {
+ rc = SLAPI_PLUGIN_FAILURE;
goto bail;
}
slapi_pblock_get(pb, SLAPI_BACKEND, &be);
if (NULL == be) {
rc = LDAP_PARAM_ERROR;
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &rc);
+ rc = SLAPI_PLUGIN_FAILURE;
goto bail;
}
diff --git a/ldap/servers/plugins/views/views.c b/ldap/servers/plugins/views/views.c
index 0892b0d..c6fd628 100644
--- a/ldap/servers/plugins/views/views.c
+++ b/ldap/servers/plugins/views/views.c
@@ -185,7 +185,7 @@ void * view_get_plugin_identity()
*/
int views_init( Slapi_PBlock *pb )
{
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
void * plugin_identity=NULL;
slapi_log_error( SLAPI_LOG_TRACE, VIEWS_PLUGIN_SUBSYSTEM, "--> views_init\n");
@@ -209,7 +209,7 @@ int views_init( Slapi_PBlock *pb )
{
slapi_log_error( SLAPI_LOG_FATAL, VIEWS_PLUGIN_SUBSYSTEM,
"views_init: failed to register plugin\n" );
- ret = -1;
+ ret = SLAPI_PLUGIN_FAILURE;
}
slapi_log_error( SLAPI_LOG_TRACE, VIEWS_PLUGIN_SUBSYSTEM, "<-- views_init\n");
@@ -238,7 +238,7 @@ void views_unlock()
*/
static int views_start( Slapi_PBlock *pb )
{
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
void **statechange_api;
slapi_log_error( SLAPI_LOG_TRACE, VIEWS_PLUGIN_SUBSYSTEM, "--> views_start\n");
@@ -270,7 +270,7 @@ static int views_start( Slapi_PBlock *pb )
if( slapi_apib_register(Views_v1_0_GUID, api) )
{
slapi_log_error( SLAPI_LOG_FATAL, VIEWS_PLUGIN_SUBSYSTEM, "views: failed to publish views interface\n");
- ret = -1;
+ ret = SLAPI_PLUGIN_FAILURE;
}
slapi_log_error( SLAPI_LOG_TRACE, VIEWS_PLUGIN_SUBSYSTEM, "<-- views_start\n");
@@ -296,7 +296,7 @@ static int _internal_api_views_entry_dn_exists(char *view_dn, char *e_dn)
static int _internal_api_views_entry_exists_general(char *view_dn, Slapi_Entry *e, char *e_dn)
{
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
viewEntry *view;
char *dn;
@@ -326,7 +326,7 @@ static int _internal_api_views_entry_exists_general(char *view_dn, Slapi_Entry *
if(slapi_dn_issuffix(dn, view_dn))
{
/* this entry is physically contained in the view hiearchy */
- ret = -1;
+ ret = SLAPI_PLUGIN_FAILURE;
goto bail;
}
@@ -346,7 +346,7 @@ static int _internal_api_views_entry_exists_general(char *view_dn, Slapi_Entry *
if(0==slapi_filter_test_simple(e,view->includeAncestorFiltersFilter))
{
/* this entry would appear in the view */
- ret = -1;
+ ret = SLAPI_PLUGIN_FAILURE;
}
}
@@ -408,7 +408,7 @@ static int views_close( Slapi_PBlock *pb )
slapi_log_error( SLAPI_LOG_TRACE, VIEWS_PLUGIN_SUBSYSTEM, "<-- views_close\n");
- return 0;
+ return SLAPI_PLUGIN_SUCCESS;
}
@@ -419,7 +419,7 @@ static int views_close( Slapi_PBlock *pb )
*/
static int views_cache_create()
{
- int ret = -1;
+ int ret = SLAPI_PLUGIN_FAILURE;
slapi_log_error( SLAPI_LOG_TRACE, VIEWS_PLUGIN_SUBSYSTEM, "--> views_cache_create\n");
@@ -474,7 +474,7 @@ static int views_cache_create()
{
/* its ok to not have views to cache */
theCache.cache_built = 0;
- ret = 0;
+ ret = SLAPI_PLUGIN_SUCCESS;
}
theCache.currentUpdaterThread = 0;
@@ -530,7 +530,7 @@ int views_cache_dn_compare(const void *e1, const void *e2)
*/
static int views_cache_index()
{
- int ret = -1;
+ int ret = SLAPI_PLUGIN_FAILURE;
int i;
viewEntry *theView = theCache.pCacheViews;
viewEntry *current = 0;
@@ -558,7 +558,7 @@ static int views_cache_index()
/* sort the views */
qsort(theCache.ppViewIndex, theCache.view_count, sizeof(viewEntry*), views_cache_view_compare);
- ret = 0;
+ ret = SLAPI_PLUGIN_SUCCESS;
}
return ret;
@@ -569,7 +569,7 @@ static int views_cache_index()
views_cache_view_index_bsearch - RECURSIVE
----------------------------------------
performs a binary search on the cache view index
- return -1 if key is not found
+ return SLAPI_PLUGIN_FAILURE if key is not found
*/
viewEntry *views_cache_view_index_bsearch( const char *key, int lower, int upper )
{
@@ -617,7 +617,7 @@ viewEntry *views_cache_view_index_bsearch( const char *key, int lower, int upper
*/
static viewEntry *views_cache_find_view(char *view)
{
- viewEntry *ret = 0; /* assume failure */
+ viewEntry *ret = SLAPI_PLUGIN_SUCCESS; /* assume failure */
if(theCache.view_count != 1)
ret = views_cache_view_index_bsearch(view, 0, theCache.view_count-1);
@@ -1119,7 +1119,7 @@ static void views_cache_create_inclusion_filter(viewEntry *pView)
*/
static int views_cache_build_view_list(viewEntry **pViews)
{
- int ret = 0;
+ int ret = SLAPI_PLUGIN_SUCCESS;
Slapi_PBlock *pSuffixSearch = 0;
Slapi_Entry **pSuffixList = 0;
Slapi_Attr *suffixAttr;
@@ -1192,7 +1192,7 @@ static int views_cache_build_view_list(viewEntry **pViews)
else
{
slapi_log_error(SLAPI_LOG_PLUGIN, VIEWS_PLUGIN_SUBSYSTEM, "views_cache_build_view_list: failed to find suffixes\n");
- ret = -1;
+ ret = SLAPI_PLUGIN_FAILURE;
}
/* clean up */
@@ -1215,7 +1215,8 @@ struct dn_views_info {
/* does same funcationality as views_add_dn_views except it is invoked via a callback */
-static int views_dn_views_cb (Slapi_Entry* e, void *callback_data) {
+static int views_dn_views_cb (Slapi_Entry* e, void *callback_data)
+{
struct dn_views_info *info;
char *pDn = 0;
struct berval **dnVals;
diff --git a/ldap/servers/slapd/add.c b/ldap/servers/slapd/add.c
index b2319fa..0695727 100644
--- a/ldap/servers/slapd/add.c
+++ b/ldap/servers/slapd/add.c
@@ -714,7 +714,7 @@ static void op_shared_add (Slapi_PBlock *pb)
sdn = slapi_sdn_dup(slapi_entry_get_sdn_const(e));
slapi_pblock_set(pb, SLAPI_ADD_TARGET_SDN, (void *)sdn);
if (plugin_call_plugins(pb, internal_op ? SLAPI_PLUGIN_INTERNAL_PRE_ADD_FN :
- SLAPI_PLUGIN_PRE_ADD_FN) == 0)
+ SLAPI_PLUGIN_PRE_ADD_FN) == SLAPI_PLUGIN_SUCCESS)
{
int rc;
Slapi_Entry *ec;
diff --git a/ldap/servers/slapd/delete.c b/ldap/servers/slapd/delete.c
index ced6351..68409c7 100644
--- a/ldap/servers/slapd/delete.c
+++ b/ldap/servers/slapd/delete.c
@@ -353,7 +353,7 @@ static void op_shared_delete (Slapi_PBlock *pb)
* post-delete plugins.
*/
if (plugin_call_plugins(pb, internal_op ? SLAPI_PLUGIN_INTERNAL_PRE_DELETE_FN :
- SLAPI_PLUGIN_PRE_DELETE_FN) == 0)
+ SLAPI_PLUGIN_PRE_DELETE_FN) == SLAPI_PLUGIN_SUCCESS)
{
int rc;
diff --git a/ldap/servers/slapd/modify.c b/ldap/servers/slapd/modify.c
index cc1621b..0a8854b 100644
--- a/ldap/servers/slapd/modify.c
+++ b/ldap/servers/slapd/modify.c
@@ -1050,7 +1050,7 @@ static void op_shared_modify (Slapi_PBlock *pb, int pw_change, char *old_pw)
*/
slapi_pblock_set (pb, SLAPI_MODIFY_MODS, (void*)slapi_mods_get_ldapmods_passout (&smods));
if (plugin_call_plugins(pb, internal_op ? SLAPI_PLUGIN_INTERNAL_PRE_MODIFY_FN :
- SLAPI_PLUGIN_PRE_MODIFY_FN) == 0)
+ SLAPI_PLUGIN_PRE_MODIFY_FN) == SLAPI_PLUGIN_SUCCESS)
{
int rc;
diff --git a/ldap/servers/slapd/modrdn.c b/ldap/servers/slapd/modrdn.c
index e1d2440..457c2b0 100644
--- a/ldap/servers/slapd/modrdn.c
+++ b/ldap/servers/slapd/modrdn.c
@@ -642,7 +642,7 @@ op_shared_rename(Slapi_PBlock *pb, int passin_args)
* post-modrdn plugins.
*/
if (plugin_call_plugins(pb, internal_op ? SLAPI_PLUGIN_INTERNAL_PRE_MODRDN_FN :
- SLAPI_PLUGIN_PRE_MODRDN_FN) == 0)
+ SLAPI_PLUGIN_PRE_MODRDN_FN) == SLAPI_PLUGIN_SUCCESS)
{
int rc= LDAP_OPERATIONS_ERROR;
slapi_pblock_set(pb, SLAPI_PLUGIN, be->be_database);
diff --git a/ldap/servers/slapd/plugin.c b/ldap/servers/slapd/plugin.c
index d9b925c..5430a1c 100644
--- a/ldap/servers/slapd/plugin.c
+++ b/ldap/servers/slapd/plugin.c
@@ -1458,9 +1458,8 @@ plugin_call_func (struct slapdplugin *list, int operation, Slapi_PBlock *pb, int
if (( rc = func (pb)) != 0 )
{
if (SLAPI_PLUGIN_PREOPERATION == list->plg_type ||
- SLAPI_PLUGIN_INTERNAL_PREOPERATION == list->plg_type ||
- SLAPI_PLUGIN_BETXNPREOPERATION == list->plg_type ||
- SLAPI_PLUGIN_START_FN == operation )
+ SLAPI_PLUGIN_INTERNAL_PREOPERATION == list->plg_type ||
+ SLAPI_PLUGIN_START_FN == operation )
{
/*
* We bail out of plugin processing for preop plugins
@@ -1470,13 +1469,18 @@ plugin_call_func (struct slapdplugin *list, int operation, Slapi_PBlock *pb, int
*/
return_value = rc;
break;
- } else if (SLAPI_PLUGIN_BEPREOPERATION == list->plg_type ||
- SLAPI_PLUGIN_BEPOSTOPERATION == list->plg_type)
+ }
+ else if (SLAPI_PLUGIN_BEPREOPERATION == list->plg_type ||
+ SLAPI_PLUGIN_BETXNPREOPERATION == list->plg_type ||
+ SLAPI_PLUGIN_BEPOSTOPERATION == list->plg_type)
{
- /* respect fatal error (-1); should not OR it */
- if (-1 == rc) {
+ /*
+ * respect fatal error SLAPI_PLUGIN_FAILURE (-1);
+ * should not OR it.
+ */
+ if (SLAPI_PLUGIN_FAILURE == rc) {
return_value = rc;
- } else if (-1 != return_value) {
+ } else if (SLAPI_PLUGIN_FAILURE != return_value) {
/* OR the result into the return value
* for be pre/postops */
return_value |= rc;
commit 2f4f74b3d38eeb38f0794dfb2e880a95e7e9bd49
Author: Noriko Hosoi <nhosoi(a)redhat.com>
Date: Thu Jul 18 14:27:28 2013 -0700
Ticket #47367 - (phase 1) ldapdelete returns non-leaf entry error while trying to remove a leaf entry
Bug description: Replication conflict confuses the numsubordinate count,
which leaves an entry that cannot be deleted even its subordinate entries
are all removed.
Fix description:
[urp.c] 1) get_dn_plus_uniqueid: a logic to create a conflict DN had a bug.
It used to call slapi_sdn_get_rdn to get the rdn. The function slapi_sdn_
get_rdn blindly returned the "dn" field without checking whether the field
is NULL or not. Instead, this patch changes the interface of the helper
function get_dn_plus_uniqueid and use the original Slapi_DN with slapi_sdn_
get_dn, then generates the conflict DN "nsuniqueid=...+ <RDN>,<PARENT>".
2) The urp calling timing was moved from SLAPI_PLUGIN_BE_TXN_PRE_* to
SLAPI_PLUGIN_BE_PRE_*. (Note: SLAPI_PLUGIN_BE_PRE_* is also in the
backend transaction.) This is necessary since urp needs to be done
prior to parent checking.
[ldbm_add.c] Moved SLAPI_PLUGIN_BE_PRE_ADD_FN inside of the transaction.
Other operations are already calling SLAPI_PLUGIN_BE_PRE function at the
timing.
[ldbm_delete.c] There is a case a parent of a delete-candidate entry runs
into a conflict and multiple parent entries exist. Once it occurs, a
parent entry found by the parent dn string may not be the entry which
manages the numsubordinate count the delete-candidate entry belonging to.
It confuses the numsubordinate counts and leaves an entry which cannot be
deleted due to the numsubordinate count mismatch. This patch retrieves
parent entry by parent id if it is available.
[ldbm_entryrdn.c] When traversing the DIT, a special treatment is needed
for a tombstone entry. I.e, 2 RDNs (nsuniqueid=..., <RDN>) is treated as
one RDN. It should decrement the index (rdnidx) one more to point to the
right position of the RDN array in Slapi_RDN.
[ldbm_search.c] When checking the scope of an entry in ldbm_back_next_
search_entry_ext, a tombstone entry was not properly examined. This patch
introduces a new slapi api slapi_sdn_scope_test_ext.
[dn.c] In slapi_sdn_get_rdn, use slapi_sdn_get_dn to get the dn value of
Slapi_DN. It was one cause of the problem in get_dn_plus_uniqueid (urp.c).
This patch adds slapi_sdn_scope_test_ext, which takes flags to indicates
the first argument dn is a tombstone sdn. Also, this patch replaces
"malloc + strcpy + strcat" with slapi_ch_smprintf to improve the
readability of the code.
[rdn.c] This patch replaces "malloc + strcpy + strcat" with slapi_create_
dn_string to normalize the newly added rdn and improve the readability of
the code.
Reviewed by Rich (Thanks!!)
https://fedorahosted.org/389/ticket/47367
diff --git a/ldap/servers/plugins/replication/repl5_init.c b/ldap/servers/plugins/replication/repl5_init.c
index 1533db9..032bbb6 100644
--- a/ldap/servers/plugins/replication/repl5_init.c
+++ b/ldap/servers/plugins/replication/repl5_init.c
@@ -360,17 +360,6 @@ multimaster_betxnpreop_init( Slapi_PBlock *pb )
{
int rc= 0; /* OK */
- if( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 ) != 0 ||
- slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multimasterbepreopdesc ) != 0 ||
- slapi_pblock_set( pb, SLAPI_PLUGIN_BE_TXN_PRE_ADD_FN, (void *) multimaster_betxnpreop_add ) != 0 ||
- slapi_pblock_set( pb, SLAPI_PLUGIN_BE_TXN_PRE_DELETE_FN, (void *) multimaster_betxnpreop_delete ) != 0 ||
- slapi_pblock_set( pb, SLAPI_PLUGIN_BE_TXN_PRE_MODIFY_FN, (void *) multimaster_betxnpreop_modify ) != 0 ||
- slapi_pblock_set( pb, SLAPI_PLUGIN_BE_TXN_PRE_MODRDN_FN, (void *) multimaster_betxnpreop_modrdn ) != 0 )
- {
- slapi_log_error( SLAPI_LOG_PLUGIN, repl_plugin_name, "multimaster_betxnpreop_init failed\n" );
- rc= -1;
- }
-
return rc;
}
diff --git a/ldap/servers/plugins/replication/repl5_plugins.c b/ldap/servers/plugins/replication/repl5_plugins.c
index 5d1a776..c2e95dc 100644
--- a/ldap/servers/plugins/replication/repl5_plugins.c
+++ b/ldap/servers/plugins/replication/repl5_plugins.c
@@ -751,8 +751,7 @@ multimaster_bepreop_add (Slapi_PBlock *pb)
{
slapi_pblock_set(pb, SLAPI_TXN_RUV_MODS_FN,
(void *)replica_ruv_smods_for_op);
- if (!repl5_is_betxn && is_replicated_operation) {
- /* if is_betxn is on, urp is called at betxn preop */
+ if (is_replicated_operation) {
rc = urp_add_operation(pb);
}
}
@@ -777,8 +776,7 @@ multimaster_bepreop_delete (Slapi_PBlock *pb)
{
slapi_pblock_set(pb, SLAPI_TXN_RUV_MODS_FN,
(void *)replica_ruv_smods_for_op);
- if (!repl5_is_betxn && is_replicated_operation) {
- /* if is_betxn is on, urp is called at betxn preop */
+ if (is_replicated_operation) {
rc = urp_delete_operation(pb);
}
}
@@ -803,8 +801,7 @@ multimaster_bepreop_modify (Slapi_PBlock *pb)
{
slapi_pblock_set(pb, SLAPI_TXN_RUV_MODS_FN,
(void *)replica_ruv_smods_for_op);
- if (!repl5_is_betxn && is_replicated_operation) {
- /* if is_betxn is on, urp is called at betxn preop */
+ if (is_replicated_operation) {
rc = urp_modify_operation(pb);
}
}
@@ -832,8 +829,7 @@ multimaster_bepreop_modrdn (Slapi_PBlock *pb)
{
slapi_pblock_set(pb, SLAPI_TXN_RUV_MODS_FN,
(void *)replica_ruv_smods_for_op);
- if (!repl5_is_betxn && is_replicated_operation) {
- /* if is_betxn is on, urp is called at betxn preop */
+ if (is_replicated_operation) {
rc = urp_modrdn_operation(pb);
}
}
diff --git a/ldap/servers/plugins/replication/urp.c b/ldap/servers/plugins/replication/urp.c
index 3d0ea82..471bf8d 100644
--- a/ldap/servers/plugins/replication/urp.c
+++ b/ldap/servers/plugins/replication/urp.c
@@ -55,9 +55,9 @@ 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, const Slapi_Entry *entry, CSN *opcsn, const char *optype);
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 mod_namingconflict_attr (const char *uniqueid, const Slapi_DN *entrysdn, const Slapi_DN *conflictsdn, CSN *opcsn, const char *optype);
static int del_replconflict_attr (const Slapi_Entry *entry, CSN *opcsn, int opflags);
-static char *get_dn_plus_uniqueid(char *sessionid,const char *olddn,const char *uniqueid);
+static char *get_dn_plus_uniqueid(char *sessionid,const Slapi_DN *oldsdn,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);
@@ -184,7 +184,7 @@ urp_add_operation( Slapi_PBlock *pb )
if (r<0)
{
/* Entry to be added is a loser */
- char *newdn= get_dn_plus_uniqueid (sessionid, basedn, adduniqueid);
+ char *newdn= get_dn_plus_uniqueid (sessionid, (const Slapi_DN *)addentry, adduniqueid);
if(newdn==NULL)
{
op_result= LDAP_OPERATIONS_ERROR;
@@ -203,7 +203,11 @@ urp_add_operation( Slapi_PBlock *pb )
Slapi_RDN *rdn;
char buf[BUFSIZ];
+#ifdef DEBUG
+ PR_snprintf(buf, BUFSIZ, "%s (add) %s", REASON_ANNOTATE_DN, basedn);
+#else
PR_snprintf(buf, BUFSIZ, "%s %s", REASON_ANNOTATE_DN, basedn);
+#endif
if (slapi_entry_attr_find (addentry, ATTR_NSDS5_REPLCONFLICT, &attr) == 0)
{
/* ATTR_NSDS5_REPLCONFLICT exists */
@@ -466,7 +470,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, "MODRDN");
slapi_pblock_set(pb, SLAPI_MODRDN_NEWRDN, newrdn_with_uniqueid);
slapi_log_error(slapi_log_urp, sessionid,
"urp_modrdn: Naming conflict MODRDN. Rename target entry to %s\n",
@@ -1033,7 +1037,7 @@ urp_annotate_dn (char *sessionid, const Slapi_Entry *entry, CSN *opcsn, const ch
newrdn = get_rdn_plus_uniqueid ( sessionid, basedn, uniqueid );
if(newrdn!=NULL)
{
- mod_namingconflict_attr (uniqueid, basesdn, basesdn, opcsn);
+ mod_namingconflict_attr (uniqueid, basesdn, basesdn, opcsn, optype);
op_result = urp_fixup_rename_entry ( entry, newrdn, 0 );
switch(op_result)
{
@@ -1245,16 +1249,15 @@ bailout:
/* The returned value is either null or "uniqueid=<uniqueid>+<basedn>" */
static char *
-get_dn_plus_uniqueid(char *sessionid, const char *olddn, const char *uniqueid)
+get_dn_plus_uniqueid(char *sessionid, const Slapi_DN *oldsdn, const char *uniqueid)
{
- Slapi_DN *sdn= slapi_sdn_new_dn_byval(olddn);
Slapi_RDN *rdn= slapi_rdn_new();
char *newdn;
PR_ASSERT(uniqueid!=NULL);
/* Check if the RDN already contains the Unique ID */
- slapi_sdn_get_rdn(sdn,rdn);
+ slapi_rdn_set_dn(rdn, slapi_sdn_get_dn(oldsdn));
if(slapi_rdn_contains(rdn,SLAPI_ATTR_UNIQUEID,uniqueid,strlen(uniqueid)))
{
/* The Unique ID is already in the RDN.
@@ -1264,16 +1267,20 @@ get_dn_plus_uniqueid(char *sessionid, const char *olddn, const char *uniqueid)
* require admin intercession
*/
slapi_log_error(SLAPI_LOG_FATAL, sessionid,
- "Annotated DN %s has naming conflict\n", olddn );
+ "Annotated DN %s has naming conflict\n", slapi_sdn_get_dn(oldsdn) );
newdn= NULL;
}
else
{
- slapi_rdn_add(rdn,SLAPI_ATTR_UNIQUEID,uniqueid);
- slapi_sdn_set_rdn(sdn, rdn);
- newdn= slapi_ch_strdup(slapi_sdn_get_dn(sdn));
+ char *parentdn = slapi_dn_parent(slapi_sdn_get_dn(oldsdn));
+ slapi_rdn_add(rdn, SLAPI_ATTR_UNIQUEID, uniqueid);
+ /*
+ * using slapi_ch_smprintf is okay since ...
+ * uniqueid in rdn is normalized and
+ * parentdn is normalized by slapi_sdn_get_dn.
+ */
+ newdn = slapi_ch_smprintf("%s,%s", slapi_rdn_get_rdn(rdn), parentdn);
}
- slapi_sdn_free(&sdn);
slapi_rdn_free(&rdn);
return newdn;
}
@@ -1340,14 +1347,20 @@ 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,
+ const char *optype)
{
Slapi_Mods smods;
char buf[BUFSIZ];
int op_result;
+#ifdef DEBUG
+ PR_snprintf (buf, sizeof(buf), "%s (%s) %s",
+ REASON_ANNOTATE_DN, optype, slapi_sdn_get_dn(conflictsdn));
+#else
PR_snprintf (buf, sizeof(buf), "%s %s",
REASON_ANNOTATE_DN, slapi_sdn_get_dn(conflictsdn));
+#endif
slapi_mods_init (&smods, 2);
if ( strncmp (slapi_sdn_get_dn(entrysdn), SLAPI_ATTR_UNIQUEID,
strlen(SLAPI_ATTR_UNIQUEID)) != 0 )
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_add.c b/ldap/servers/slapd/back-ldbm/ldbm_add.c
index 0cd9432..50748a7 100644
--- a/ldap/servers/slapd/back-ldbm/ldbm_add.c
+++ b/ldap/servers/slapd/back-ldbm/ldbm_add.c
@@ -194,112 +194,6 @@ ldbm_back_add( Slapi_PBlock *pb )
}
- if (!is_tombstone_operation) {
- rc= slapi_setbit_int(rc,SLAPI_RTN_BIT_FETCH_EXISTING_DN_ENTRY);
- }
- rc= slapi_setbit_int(rc,SLAPI_RTN_BIT_FETCH_EXISTING_UNIQUEID_ENTRY);
- rc= slapi_setbit_int(rc,SLAPI_RTN_BIT_FETCH_PARENT_ENTRY);
- while(rc!=0)
- {
- /* JCM - copying entries can be expensive... should optimize */
- /*
- * Some present state information is passed through the PBlock to the
- * backend pre-op plugin. To ensure a consistent snapshot of this state
- * we wrap the reading of the entry with the dblock.
- */
- if(slapi_isbitset_int(rc,SLAPI_RTN_BIT_FETCH_EXISTING_UNIQUEID_ENTRY))
- {
- /* Check if an entry with the intended uniqueid already exists. */
- done_with_pblock_entry(pb,SLAPI_ADD_EXISTING_UNIQUEID_ENTRY); /* Could be through this multiple times */
- addr.udn = NULL;
- addr.sdn = NULL;
- addr.uniqueid = (char*)slapi_entry_get_uniqueid(e); /* jcm - cast away const */
- ldap_result_code= get_copy_of_entry(pb, &addr, &txn, SLAPI_ADD_EXISTING_UNIQUEID_ENTRY, !is_replicated_operation);
- }
- if(slapi_isbitset_int(rc,SLAPI_RTN_BIT_FETCH_EXISTING_DN_ENTRY))
- {
- slapi_pblock_get( pb, SLAPI_ADD_TARGET_SDN, &sdn );
- if (NULL == sdn)
- {
- LDAPDebug0Args(LDAP_DEBUG_ANY,
- "ldbm_back_add: Null target dn\n");
- goto error_return;
- }
-
- /* not need to check the dn syntax as this is a replicated op */
- if(!is_replicated_operation){
- dn = slapi_sdn_get_dn(sdn);
- ldap_result_code = slapi_dn_syntax_check(pb, dn, 1);
- if (ldap_result_code)
- {
- ldap_result_code = LDAP_INVALID_DN_SYNTAX;
- slapi_pblock_get(pb, SLAPI_PB_RESULT_TEXT, &ldap_result_message);
- goto error_return;
- }
- }
-
- slapi_sdn_get_backend_parent(sdn, &parentsdn, pb->pb_backend);
- /* Check if an entry with the intended DN already exists. */
- done_with_pblock_entry(pb,SLAPI_ADD_EXISTING_DN_ENTRY); /* Could be through this multiple times */
- addr.sdn = sdn;
- addr.udn = NULL;
- addr.uniqueid = NULL;
- ldap_result_code= get_copy_of_entry(pb, &addr, &txn, SLAPI_ADD_EXISTING_DN_ENTRY, !is_replicated_operation);
- if(ldap_result_code==LDAP_OPERATIONS_ERROR ||
- ldap_result_code==LDAP_INVALID_DN_SYNTAX)
- {
- goto error_return;
- }
- }
- /* if we can find the parent by dn or uniqueid, and the operation has requested the parent
- then get it */
- if(have_parent_address(&parentsdn, operation->o_params.p.p_add.parentuniqueid) &&
- slapi_isbitset_int(rc,SLAPI_RTN_BIT_FETCH_PARENT_ENTRY))
- {
- done_with_pblock_entry(pb,SLAPI_ADD_PARENT_ENTRY); /* Could be through this multiple times */
- addr.sdn = &parentsdn;
- addr.udn = NULL;
- addr.uniqueid = operation->o_params.p.p_add.parentuniqueid;
- ldap_result_code= get_copy_of_entry(pb, &addr, &txn, SLAPI_ADD_PARENT_ENTRY, !is_replicated_operation);
- /* need to set parentsdn or parentuniqueid if either is not set? */
- }
-
- /* Call the Backend Pre Add plugins */
- slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ldap_result_code);
- rc= plugin_call_plugins(pb, SLAPI_PLUGIN_BE_PRE_ADD_FN);
- if (rc) {
- int opreturn = 0;
- if (SLAPI_PLUGIN_NOOP == rc) {
- not_an_error = 1;
- rc = LDAP_SUCCESS;
- }
- /*
- * Plugin indicated some kind of failure,
- * or that this Operation became a No-Op.
- */
- if (!ldap_result_code) {
- slapi_pblock_get(pb, SLAPI_RESULT_CODE, &ldap_result_code);
- }
- if (!ldap_result_code) {
- LDAPDebug0Args(LDAP_DEBUG_ANY,
- "ldbm_back_add: SLAPI_PLUGIN_BE_PRE_ADD_FN returned error but did not set SLAPI_RESULT_CODE\n");
- ldap_result_code = LDAP_OPERATIONS_ERROR;
- }
- slapi_pblock_get(pb, SLAPI_PLUGIN_OPRETURN, &opreturn);
- if (!opreturn) {
- /* make sure opreturn is set for the postop plugins */
- slapi_pblock_set(pb, SLAPI_PLUGIN_OPRETURN, ldap_result_code ? &ldap_result_code : &rc);
- }
-
- goto error_return;
- }
- /*
- * (rc!=-1 && rc!= 0) means that the plugin changed things, so we go around
- * the loop once again to get the new present state.
- */
- /* JCMREPL - Warning: A Plugin could cause an infinite loop by always returning a result code that requires some action. */
- }
-
/*
* Originally (in the U-M LDAP 3.3 code), there was a comment near this
* code about a race condition. The race was that a 2nd entry could be
@@ -365,6 +259,113 @@ ldbm_back_add( Slapi_PBlock *pb )
if (0 == retry_count) {
/* First time, hold SERIAL LOCK */
retval = dblayer_txn_begin(be, parent_txn, &txn);
+
+ if (!is_tombstone_operation) {
+ rc= slapi_setbit_int(rc,SLAPI_RTN_BIT_FETCH_EXISTING_DN_ENTRY);
+ }
+
+ rc= slapi_setbit_int(rc,SLAPI_RTN_BIT_FETCH_EXISTING_UNIQUEID_ENTRY);
+ rc= slapi_setbit_int(rc,SLAPI_RTN_BIT_FETCH_PARENT_ENTRY);
+ while(rc!=0)
+ {
+ /* JCM - copying entries can be expensive... should optimize */
+ /*
+ * Some present state information is passed through the PBlock to the
+ * backend pre-op plugin. To ensure a consistent snapshot of this state
+ * we wrap the reading of the entry with the dblock.
+ */
+ if(slapi_isbitset_int(rc,SLAPI_RTN_BIT_FETCH_EXISTING_UNIQUEID_ENTRY))
+ {
+ /* Check if an entry with the intended uniqueid already exists. */
+ done_with_pblock_entry(pb,SLAPI_ADD_EXISTING_UNIQUEID_ENTRY); /* Could be through this multiple times */
+ addr.udn = NULL;
+ addr.sdn = NULL;
+ addr.uniqueid = (char*)slapi_entry_get_uniqueid(e); /* jcm - cast away const */
+ ldap_result_code= get_copy_of_entry(pb, &addr, &txn, SLAPI_ADD_EXISTING_UNIQUEID_ENTRY, !is_replicated_operation);
+ }
+ if(slapi_isbitset_int(rc,SLAPI_RTN_BIT_FETCH_EXISTING_DN_ENTRY))
+ {
+ slapi_pblock_get( pb, SLAPI_ADD_TARGET_SDN, &sdn );
+ if (NULL == sdn)
+ {
+ LDAPDebug0Args(LDAP_DEBUG_ANY,
+ "ldbm_back_add: Null target dn\n");
+ goto error_return;
+ }
+
+ /* not need to check the dn syntax as this is a replicated op */
+ if(!is_replicated_operation){
+ dn = slapi_sdn_get_dn(sdn);
+ ldap_result_code = slapi_dn_syntax_check(pb, dn, 1);
+ if (ldap_result_code)
+ {
+ ldap_result_code = LDAP_INVALID_DN_SYNTAX;
+ slapi_pblock_get(pb, SLAPI_PB_RESULT_TEXT, &ldap_result_message);
+ goto error_return;
+ }
+ }
+
+ slapi_sdn_get_backend_parent(sdn, &parentsdn, pb->pb_backend);
+ /* Check if an entry with the intended DN already exists. */
+ done_with_pblock_entry(pb,SLAPI_ADD_EXISTING_DN_ENTRY); /* Could be through this multiple times */
+ addr.sdn = sdn;
+ addr.udn = NULL;
+ addr.uniqueid = NULL;
+ ldap_result_code= get_copy_of_entry(pb, &addr, &txn, SLAPI_ADD_EXISTING_DN_ENTRY, !is_replicated_operation);
+ if(ldap_result_code==LDAP_OPERATIONS_ERROR ||
+ ldap_result_code==LDAP_INVALID_DN_SYNTAX)
+ {
+ goto error_return;
+ }
+ }
+ /* if we can find the parent by dn or uniqueid, and the operation has requested the parent
+ then get it */
+ if(have_parent_address(&parentsdn, operation->o_params.p.p_add.parentuniqueid) &&
+ slapi_isbitset_int(rc,SLAPI_RTN_BIT_FETCH_PARENT_ENTRY))
+ {
+ done_with_pblock_entry(pb,SLAPI_ADD_PARENT_ENTRY); /* Could be through this multiple times */
+ addr.sdn = &parentsdn;
+ addr.udn = NULL;
+ addr.uniqueid = operation->o_params.p.p_add.parentuniqueid;
+ ldap_result_code= get_copy_of_entry(pb, &addr, &txn, SLAPI_ADD_PARENT_ENTRY, !is_replicated_operation);
+ /* need to set parentsdn or parentuniqueid if either is not set? */
+ }
+
+ /* Call the Backend Pre Add plugins */
+ slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ldap_result_code);
+ rc= plugin_call_plugins(pb, SLAPI_PLUGIN_BE_PRE_ADD_FN);
+ if (rc < 0) {
+ int opreturn = 0;
+ if (SLAPI_PLUGIN_NOOP == rc) {
+ not_an_error = 1;
+ rc = LDAP_SUCCESS;
+ }
+ /*
+ * Plugin indicated some kind of failure,
+ * or that this Operation became a No-Op.
+ */
+ if (!ldap_result_code) {
+ slapi_pblock_get(pb, SLAPI_RESULT_CODE, &ldap_result_code);
+ }
+ if (!ldap_result_code) {
+ LDAPDebug0Args(LDAP_DEBUG_ANY,
+ "ldbm_back_add: SLAPI_PLUGIN_BE_PRE_ADD_FN returned error but did not set SLAPI_RESULT_CODE\n");
+ ldap_result_code = LDAP_OPERATIONS_ERROR;
+ }
+ slapi_pblock_get(pb, SLAPI_PLUGIN_OPRETURN, &opreturn);
+ if (!opreturn) {
+ /* make sure opreturn is set for the postop plugins */
+ slapi_pblock_set(pb, SLAPI_PLUGIN_OPRETURN, ldap_result_code ? &ldap_result_code : &rc);
+ }
+
+ goto error_return;
+ }
+ /*
+ * (rc!=-1 && rc!= 0) means that the plugin changed things, so we go around
+ * the loop once again to get the new present state.
+ */
+ /* JCMREPL - Warning: A Plugin could cause an infinite loop by always returning a result code that requires some action. */
+ }
} else {
/* Otherwise, no SERIAL LOCK */
retval = dblayer_txn_begin_ext(li, parent_txn, &txn, PR_FALSE);
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_delete.c b/ldap/servers/slapd/back-ldbm/ldbm_delete.c
index 61af3a6..3556658 100644
--- a/ldap/servers/slapd/back-ldbm/ldbm_delete.c
+++ b/ldap/servers/slapd/back-ldbm/ldbm_delete.c
@@ -288,7 +288,6 @@ ldbm_back_delete( Slapi_PBlock *pb )
/* Don't call pre-op for Tombstone entries */
if (!delete_tombstone_entry)
{
- int rc = 0;
/*
* Some present state information is passed through the PBlock to the
* backend pre-op plugin. To ensure a consistent snapshot of this state
@@ -305,12 +304,13 @@ ldbm_back_delete( Slapi_PBlock *pb )
goto error_return;
}
slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ldap_result_code);
-
- rc = plugin_call_plugins(pb, SLAPI_PLUGIN_BE_PRE_DELETE_FN);
- if (rc)
+
+ retval = plugin_call_plugins(pb, SLAPI_PLUGIN_BE_PRE_DELETE_FN);
+ if (retval)
{
- if (SLAPI_PLUGIN_NOOP == rc) {
+ if (SLAPI_PLUGIN_NOOP == retval) {
not_an_error = 1;
+ rc = LDAP_SUCCESS;
}
/*
* Plugin indicated some kind of failure,
@@ -324,12 +324,11 @@ ldbm_back_delete( Slapi_PBlock *pb )
if (!opreturn) {
slapi_pblock_set( pb, SLAPI_PLUGIN_OPRETURN, ldap_result_code ? &ldap_result_code : &rc );
}
- retval = -1;
goto error_return;
}
/* the flag could be set in a preop plugin (e.g., USN) */
delete_tombstone_entry = operation_is_flag_set(operation,
- OP_FLAG_TOMBSTONE_ENTRY);
+ OP_FLAG_TOMBSTONE_ENTRY);
}
/* call the transaction pre delete plugins just after the
@@ -363,16 +362,14 @@ ldbm_back_delete( Slapi_PBlock *pb )
*/
is_tombstone_entry = slapi_entry_flag_is_set(e->ep_entry, SLAPI_ENTRY_FLAG_TOMBSTONE);
if (delete_tombstone_entry) {
- PR_ASSERT(is_tombstone_entry);
if (!is_tombstone_entry) {
slapi_log_error(SLAPI_LOG_FATAL, "ldbm_back_delete",
"Attempt to delete a non-tombstone entry %s\n", dn);
delete_tombstone_entry = 0;
}
} else {
- PR_ASSERT(!is_tombstone_entry);
if (is_tombstone_entry) {
- slapi_log_error(SLAPI_LOG_FATAL, "ldbm_back_delete",
+ slapi_log_error(SLAPI_LOG_FATAL, "ldbm_back_delete",
"Attempt to Tombstone again a tombstone entry %s\n", dn);
delete_tombstone_entry = 1;
}
@@ -428,7 +425,7 @@ ldbm_back_delete( Slapi_PBlock *pb )
/* Save away a copy of the entry, before modifications */
slapi_pblock_set( pb, SLAPI_ENTRY_PRE_OP, slapi_entry_dup( e->ep_entry ));
- /* JCMACL - Shouldn't the access check be before the has children check...
+ /* JCMACL - Shouldn't the access check be before the has children check...
* otherwise we're revealing the fact that an entry exists and has children */
ldap_result_code = plugin_call_acl_plugin (pb, e->ep_entry, NULL, NULL, SLAPI_ACL_DELETE,
ACLPLUGIN_ACCESS_DEFAULT, &errbuf );
@@ -449,12 +446,31 @@ ldbm_back_delete( Slapi_PBlock *pb )
if ( !slapi_sdn_isempty(&parentsdn) )
{
struct backentry *parent = NULL;
- entry_address parent_addr;
+ char *pid_str = slapi_entry_attr_get_charptr(e->ep_entry, LDBM_PARENTID_STR);
+ if (pid_str) {
+ /* First, try to get the direct parent. */
+ /*
+ * Although a rare case, multiple parents from repl conflict could exist.
+ * In such case, if a parent entry is found just by parentsdn
+ * (find_entry2modify_only_ext), a wrong parent could be found,
+ * and numsubordinate count could get confused.
+ */
+ ID pid = (ID)strtol(pid_str, (char **)NULL, 10);
+ parent = id2entry(be, pid ,NULL, &retval);
+ if (parent && cache_lock_entry(&inst->inst_cache, parent)) {
+ /* Failed to obtain parent entry's entry lock */
+ CACHE_RETURN(&(inst->inst_cache), &parent);
+ goto error_return;
+ }
+ }
+ if (NULL == parent) {
+ entry_address parent_addr;
- parent_addr.sdn = &parentsdn;
- parent_addr.uniqueid = NULL;
- parent = find_entry2modify_only_ext(pb, be, &parent_addr,
- TOMBSTONE_INCLUDED, &txn);
+ parent_addr.sdn = &parentsdn;
+ parent_addr.uniqueid = NULL;
+ parent = find_entry2modify_only_ext(pb, be, &parent_addr,
+ TOMBSTONE_INCLUDED, &txn);
+ }
if (NULL != parent) {
int isglue;
size_t haschildren = 0;
@@ -549,7 +565,7 @@ ldbm_back_delete( Slapi_PBlock *pb )
slapi_value_free(&tomb_value);
/* XXXggood above used to be: slapi_entry_add_string(tombstone->ep_entry, SLAPI_ATTR_OBJECTCLASS, SLAPI_ATTR_VALUE_TOMBSTONE); */
/* JCMREPL - Add a description of what's going on? */
-
+
if ( (original_tombstone = backentry_dup( tombstone )) == NULL ) {
ldap_result_code= LDAP_OPERATIONS_ERROR;
retval = -1;
@@ -568,6 +584,7 @@ ldbm_back_delete( Slapi_PBlock *pb )
if (retval) {
if (SLAPI_PLUGIN_NOOP == retval) {
not_an_error = 1;
+ rc = LDAP_SUCCESS;
}
LDAPDebug1Arg( LDAP_DEBUG_TRACE,
"SLAPI_PLUGIN_BE_TXN_PRE_DELETE_FN plugin "
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_entryrdn.c b/ldap/servers/slapd/back-ldbm/ldbm_entryrdn.c
index 57b3a20..8c17104 100644
--- a/ldap/servers/slapd/back-ldbm/ldbm_entryrdn.c
+++ b/ldap/servers/slapd/back-ldbm/ldbm_entryrdn.c
@@ -3159,6 +3159,7 @@ _entryrdn_index_read(backend *be,
/* Node might be a tombstone. */
rc = _entryrdn_get_tombstone_elem(cursor, tmpsrdn,
&key, nrdn, elem);
+ rdnidx--; /* consider nsuniqueid=..,<RDN> one RDN */
}
if (rc || NULL == *elem) {
slapi_log_error(SLAPI_LOG_BACKLDBM, ENTRYRDN_TAG,
@@ -3265,6 +3266,7 @@ _entryrdn_index_read(backend *be,
}
goto bail;
}
+ rdnidx--; /* consider nsuniqueid=..,<RDN> one RDN */
} else {
slapi_ch_free((void **)&tmpelem);
if (DB_NOTFOUND != rc) {
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_modrdn.c b/ldap/servers/slapd/back-ldbm/ldbm_modrdn.c
index 416b928..8b4f3ef 100644
--- a/ldap/servers/slapd/back-ldbm/ldbm_modrdn.c
+++ b/ldap/servers/slapd/back-ldbm/ldbm_modrdn.c
@@ -447,7 +447,7 @@ ldbm_back_modrdn( Slapi_PBlock *pb )
/* Call the Backend Pre ModRDN plugins */
slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ldap_result_code);
rc= plugin_call_plugins(pb, SLAPI_PLUGIN_BE_PRE_MODRDN_FN);
- if (rc) {
+ if (rc < 0) {
if (SLAPI_PLUGIN_NOOP == rc) {
not_an_error = 1;
rc = LDAP_SUCCESS;
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_search.c b/ldap/servers/slapd/back-ldbm/ldbm_search.c
index 7e5a20a..f70388f 100644
--- a/ldap/servers/slapd/back-ldbm/ldbm_search.c
+++ b/ldap/servers/slapd/back-ldbm/ldbm_search.c
@@ -1651,7 +1651,7 @@ ldbm_back_next_search_entry_ext( Slapi_PBlock *pb, int use_extension )
* just forget about it, since we don't want to return anything at all. */
{
if ( slapi_uniqueIDCompareString(target_uniqueid, e->ep_entry->e_uniqueid) ||
- slapi_sdn_scope_test( backentry_get_sdn(e), basesdn, scope ))
+ slapi_sdn_scope_test_ext( backentry_get_sdn(e), basesdn, scope, e->ep_entry->e_flags ))
{
/* check size limit */
if ( slimit >= 0 )
diff --git a/ldap/servers/slapd/dn.c b/ldap/servers/slapd/dn.c
index 44459e1..9ed8091 100644
--- a/ldap/servers/slapd/dn.c
+++ b/ldap/servers/slapd/dn.c
@@ -2169,6 +2169,10 @@ slapi_sdn_set_rdn(Slapi_DN *sdn, const Slapi_RDN *rdn)
{
/* NewDN= NewRDN + OldParent */
char *parentdn = slapi_dn_parent(slapi_sdn_get_dn(sdn));
+ /*
+ * using slapi_ch_smprintf is okay since
+ * newdn is set to sdn as a pre-normalized dn.
+ */
char *newdn = slapi_ch_smprintf("%s,%s", rawrdn, parentdn);
slapi_ch_free((void**)&parentdn);
slapi_sdn_set_dn_passin(sdn,newdn);
@@ -2191,10 +2195,11 @@ slapi_sdn_add_rdn(Slapi_DN *sdn, const Slapi_RDN *rdn)
{
/* NewDN= NewRDN + DN */
const char *dn= slapi_sdn_get_dn(sdn);
- char *newdn= slapi_ch_malloc(strlen(rawrdn)+1+strlen(dn)+1);
- strcpy( newdn, rawrdn );
- strcat( newdn, "," );
- strcat( newdn, dn );
+ /*
+ * using slapi_ch_smprintf is okay since
+ * newdn is set to sdn as a pre-normalized dn.
+ */
+ char *newdn = slapi_ch_smprintf("%s,%s", rawrdn, dn);
slapi_sdn_set_dn_passin(sdn,newdn);
}
return sdn;
@@ -2422,7 +2427,7 @@ slapi_sdn_get_backend_parent(const Slapi_DN *sdn,Slapi_DN *sdn_parent,const Slap
void
slapi_sdn_get_rdn(const Slapi_DN *sdn,Slapi_RDN *rdn)
{
- slapi_rdn_set_dn(rdn,sdn->dn);
+ slapi_rdn_set_dn(rdn, slapi_sdn_get_dn(sdn));
}
Slapi_DN *
@@ -2616,6 +2621,47 @@ slapi_sdn_scope_test( const Slapi_DN *dn, const Slapi_DN *base, int scope )
return rc;
}
+/*
+ * Return non-zero if "dn" matches the scoping criteria
+ * given by "base" and "scope".
+ * If SLAPI_ENTRY_FLAG_TOMBSTONE is set to flags,
+ * DN without "nsuniqueid=...," is examined.
+ */
+int
+slapi_sdn_scope_test_ext( const Slapi_DN *dn, const Slapi_DN *base, int scope, int flags )
+{
+ int rc = 0;
+
+ switch ( scope ) {
+ case LDAP_SCOPE_BASE:
+ if (flags & SLAPI_ENTRY_FLAG_TOMBSTONE) {
+ Slapi_DN parent;
+ slapi_sdn_init(&parent);
+ slapi_sdn_get_parent(dn, &parent);
+ rc = ( slapi_sdn_compare( dn, &parent ) == 0 );
+ slapi_sdn_done(&parent);
+ } else {
+ rc = ( slapi_sdn_compare( dn, base ) == 0 );
+ }
+ break;
+ case LDAP_SCOPE_ONELEVEL:
+ if (flags & SLAPI_ENTRY_FLAG_TOMBSTONE) {
+ Slapi_DN parent;
+ slapi_sdn_init(&parent);
+ slapi_sdn_get_parent(dn, &parent);
+ rc = ( slapi_sdn_isparent( base, &parent ) != 0 );
+ slapi_sdn_done(&parent);
+ } else {
+ rc = ( slapi_sdn_isparent( base, dn ) != 0 );
+ }
+ break;
+ case LDAP_SCOPE_SUBTREE:
+ rc = ( slapi_sdn_issuffix( dn, base ) != 0 );
+ break;
+ }
+ return rc;
+}
+
/*
* build the new dn of an entry for moddn operations
*/
@@ -2663,8 +2709,17 @@ size_t
slapi_sdn_get_size(const Slapi_DN *sdn)
{
size_t sz = sizeof(Slapi_DN);
+ /* slapi_sdn_get_ndn_len returns the normalized dn length
+ * if dn or ndn exists. If both does not exist, it
+ * normalizes udn and set it to dn and returns the length.
+ */
sz += slapi_sdn_get_ndn_len(sdn);
- sz += strlen(sdn->dn) + 1;
+ if (sdn->dn && sdn->ndn) {
+ sz += slapi_sdn_get_ndn_len(sdn);
+ }
+ if (sdn->udn) {
+ sz += strlen(sdn->udn) + 1;
+ }
return sz;
}
diff --git a/ldap/servers/slapd/rdn.c b/ldap/servers/slapd/rdn.c
index d408f0e..fe2fae0 100644
--- a/ldap/servers/slapd/rdn.c
+++ b/ldap/servers/slapd/rdn.c
@@ -479,25 +479,17 @@ slapi_rdn_add(Slapi_RDN *rdn, const char *type, const char *value)
PR_ASSERT(NULL != value);
if(rdn->rdn==NULL)
{
- /* type=value '\0' */
- rdn->rdn= slapi_ch_malloc(strlen(type)+1+strlen(value)+1);
- strcpy( rdn->rdn, type );
- strcat( rdn->rdn, "=" );
- strcat( rdn->rdn, value );
+ /* type=value '\0' */
+ rdn->rdn = slapi_create_dn_string("%s=%s", type, value);
}
else
{
- /* type=value+rdn '\0' */
- char *newrdn= slapi_ch_malloc(strlen(type)+1+strlen(value)+1+strlen(rdn->rdn)+1);
- strcpy( newrdn, type );
- strcat( newrdn, "=" );
- strcat( newrdn, value );
- strcat( newrdn, "+" );
- strcat( newrdn, rdn->rdn );
- slapi_ch_free((void**)&rdn->rdn);
- rdn->rdn= newrdn;
- }
- slapi_unsetbit_uchar(rdn->flag,FLAG_RDNS);
+ /* type=value+rdn '\0' */
+ char *newrdn = slapi_create_dn_string("%s=%s+%s", type, value, rdn->rdn);
+ slapi_ch_free_string(&rdn->rdn);
+ rdn->rdn = newrdn;
+ }
+ slapi_unsetbit_uchar(rdn->flag,FLAG_RDNS);
return 1;
}
diff --git a/ldap/servers/slapd/slapi-plugin.h b/ldap/servers/slapd/slapi-plugin.h
index a22ef29..ecbf993 100644
--- a/ldap/servers/slapd/slapi-plugin.h
+++ b/ldap/servers/slapd/slapi-plugin.h
@@ -2761,6 +2761,24 @@ int slapi_sdn_get_ndn_len(const Slapi_DN *sdn);
int slapi_sdn_scope_test( const Slapi_DN *dn, const Slapi_DN *base, int scope );
/**
+ * Checks if a DN is within a specified scope under a specified base DN.
+ * This api adjusts tombstoned DN when comparing with the base dn.
+ *
+ * \param dn A pointer to the \c Slapi_DN structure to test.
+ * \param base The base DN against which \c dn is going to be tested.
+ * \param scope The scope tested. Valid scopes are:
+ * \arg \c LDAP_SCOPE_BASE
+ * \arg \c LDAP_SCOPE_ONELEVEL
+ * \arg \c LDAP_SCOPE_SUBTREE
+ * \param flags 0 or SLAPI_ENTRY_FLAG_TOMBSTONE
+ * \return non-zero if \c dn matches the scoping criteria given by \c base and \c scope.
+ * \see slapi_sdn_compare()
+ * \see slapi_sdn_isparent()
+ * \see slapi_sdn_issuffix()
+ */
+int slapi_sdn_scope_test_ext( const Slapi_DN *dn, const Slapi_DN *base, int scope, int flags );
+
+/**
* Retreives the RDN from a given DN.
*
* This function takes the DN stored in the \c Slapi_DN structure pointed to
10 years, 9 months
Branch '389-ds-base-1.3.1' - ldap/servers
by Mark Reynolds
ldap/servers/slapd/ldaputil.c | 1 +
1 file changed, 1 insertion(+)
New commits:
commit bd2a028415cdc673b5ac979335ba62ce52e3bf18
Author: Mark Reynolds <mreynolds(a)redhat.com>
Date: Thu Jul 18 15:50:36 2013 -0400
Ticket 47421 - memory leaks in set_krb5_creds
Bug Description: Valgrind shows memory leaks in set_krb5_creds()
Fix description: krb5_unparse_name() allocates/returns the principle name.
But we can call this function twice without freeing the first
returned value.
https://fedorahosted.org/389/ticket/47421
Reviewed by: richm(Thanks!)
(cherry picked from commit db124a2711576de2dd0009528d60b2860e815210)
diff --git a/ldap/servers/slapd/ldaputil.c b/ldap/servers/slapd/ldaputil.c
index 7a7b5ee..e56c392 100644
--- a/ldap/servers/slapd/ldaputil.c
+++ b/ldap/servers/slapd/ldaputil.c
@@ -1947,6 +1947,7 @@ set_krb5_creds(
}
}
+ slapi_ch_free_string(&princ_name);
if ((rc = krb5_unparse_name(ctx, princ, &princ_name))) {
slapi_log_error(SLAPI_LOG_FATAL, logname,
"Unable to get name of principal: "
10 years, 9 months
ldap/servers
by Mark Reynolds
ldap/servers/slapd/ldaputil.c | 1 +
1 file changed, 1 insertion(+)
New commits:
commit db124a2711576de2dd0009528d60b2860e815210
Author: Mark Reynolds <mreynolds(a)redhat.com>
Date: Thu Jul 18 15:50:36 2013 -0400
Ticket 47421 - memory leaks in set_krb5_creds
Bug Description: Valgrind shows memory leaks in set_krb5_creds()
Fix description: krb5_unparse_name() allocates/returns the principle name.
But we can call this function twice without freeing the first
returned value.
https://fedorahosted.org/389/ticket/47421
Reviewed by: richm(Thanks!)
diff --git a/ldap/servers/slapd/ldaputil.c b/ldap/servers/slapd/ldaputil.c
index ae07c44..f911767 100644
--- a/ldap/servers/slapd/ldaputil.c
+++ b/ldap/servers/slapd/ldaputil.c
@@ -1950,6 +1950,7 @@ set_krb5_creds(
}
}
+ slapi_ch_free_string(&princ_name);
if ((rc = krb5_unparse_name(ctx, princ, &princ_name))) {
slapi_log_error(SLAPI_LOG_FATAL, logname,
"Unable to get name of principal: "
10 years, 9 months
ldap/servers
by Mark Reynolds
ldap/servers/slapd/ldaputil.c | 39 +++++++
ldap/servers/slapd/sasl_io.c | 186 +++++++++++++++++++++++++++++++++-----
ldap/servers/slapd/slapi-plugin.h | 10 ++
3 files changed, 211 insertions(+), 24 deletions(-)
New commits:
commit b4cdebbef35fe413dc4d853256536e96ff3ee313
Author: Mark Reynolds <mreynolds(a)redhat.com>
Date: Wed Jul 17 23:57:04 2013 -0400
Ticket 47416 - SASL encrypted packet length exceeds maximum allowed limit
Bug Description: If an error occurs while establishing the secure layer during
a bind operation, the client will send an unbind request that
is not encrypted. The sasl code expects encrypted values
and it incorrectly parses the message for its length, but since
it's not encrypted the length is wrong, and exceeds the saslio limit.
Fix Description: Check if there is data in the encrypted buffer before the secure
layer is established. Check if the first byte in the buffer is an
LDAP_TAG_MESSAGE. Then we get the legnth of the LDAP message, and compare
it to maxbersize. Then attmept to read in the rest of the
packet(if necessary). If we fail to read in the LDAP msg length,
then return PR_WOULD_BLOCK_ERROR. Otherwise parse the berElement, and
check if it is an UNBIND operation. If it is then copy it to the socket
buffer, and let the server process the operation. Any other valid
LDAP operation is still treated as an error.
https://fedorahosted.org/389/ticket/47416
Reviewed by: richm (Thanks!!!)
diff --git a/ldap/servers/slapd/ldaputil.c b/ldap/servers/slapd/ldaputil.c
index f753570..ae07c44 100644
--- a/ldap/servers/slapd/ldaputil.c
+++ b/ldap/servers/slapd/ldaputil.c
@@ -2331,3 +2331,42 @@ slapi_is_ipv6_addr( const char *hostname ){
}
return 0;
}
+
+/*
+ * Get the length of the ber-encoded ldap message. Note, only the length of
+ * the LDAP operation is returned, not the length of the entire berval.
+ * Add 2 to the length for the entire PDU size. If "strict" is set then
+ * the entire LDAP PDU must be in the berval.
+ */
+ber_len_t
+slapi_berval_get_msg_len(struct berval *bv, int strict)
+{
+ ber_len_t len, rest;
+ unsigned char *ptr;
+ int i;
+
+ /* Get the ldap operation length */
+ rest = bv->bv_len - 1;
+ ptr = (unsigned char *)bv->bv_val ;
+ ptr++; /* skip the tag and get right to the length */
+ len = *ptr++;
+ rest--;
+
+ if ( len & 0x80U ) {
+ len &= 0x7fU;
+ if ( len - 1U > sizeof(ber_len_t) - 1U || rest < len ) {
+ /* Indefinite-length/too long length/not enough data */
+ return -1;
+ }
+ rest -= len;
+ i = len;
+ for( len = *ptr++ & 0xffU; --i; len |= *ptr++ & 0xffU ) {
+ len <<= 8;
+ }
+ }
+ if( strict && len > rest ) {
+ return -1;
+ }
+
+ return len;
+}
diff --git a/ldap/servers/slapd/sasl_io.c b/ldap/servers/slapd/sasl_io.c
index 52d6506..de9bea6 100644
--- a/ldap/servers/slapd/sasl_io.c
+++ b/ldap/servers/slapd/sasl_io.c
@@ -52,7 +52,9 @@
*/
#define SASL_IO_BUFFER_SIZE 1024
-
+#define SASL_IO_BUFFER_NOT_ENCRYPTED -99
+#define SASL_IO_BUFFER_START_SIZE 7
+
/*
* SASL sends its encrypted PDU's with an embedded 4-byte length
* at the beginning (in network byte order). We peek inside the
@@ -204,56 +206,184 @@ sasl_get_io_private(PRFileDesc *fd)
static PRInt32
sasl_io_start_packet(PRFileDesc *fd, PRIntn flags, PRIntervalTime timeout, PRInt32 *err)
{
- PRInt32 ret = 0;
- unsigned char buffer[sizeof(PRInt32)];
- size_t packet_length = 0;
- size_t saslio_limit;
+ unsigned char buffer[SASL_IO_BUFFER_START_SIZE];
sasl_io_private *sp = sasl_get_io_private(fd);
Connection *c = sp->conn;
PRInt32 amount = sizeof(buffer);
+ PRInt32 ret = 0;
+ size_t packet_length = 0;
+ size_t saslio_limit;
*err = 0;
debug_print_layers(fd);
- amount -= sp->encrypted_buffer_offset;
/* first we need the length bytes */
ret = PR_Recv(fd->lower, buffer, amount, flags, timeout);
LDAPDebug( LDAP_DEBUG_CONNS,
- "read sasl packet length returned %d on connection %" NSPRIu64 "\n", ret, c->c_connid, 0 );
+ "sasl_io_start_packet: read sasl packet length returned %d on connection %" NSPRIu64 "\n",
+ ret, c->c_connid, 0 );
if (ret <= 0) {
*err = PR_GetError();
if (ret == 0) {
LDAPDebug1Arg( LDAP_DEBUG_CONNS,
- "sasl_io_start_packet: connection closed while reading sasl packet length on connection %" NSPRIu64 "\n", c->c_connid );
+ "sasl_io_start_packet: connection closed while reading sasl packet length on connection %" NSPRIu64 "\n",
+ c->c_connid );
} else {
LDAPDebug( LDAP_DEBUG_CONNS,
- "sasl_io_start_packet: error reading sasl packet length on connection %" NSPRIu64 " %d:%s\n", c->c_connid, *err, slapd_pr_strerror(*err) );
+ "sasl_io_start_packet: error reading sasl packet length on connection %" NSPRIu64 " %d:%s\n",
+ c->c_connid, *err, slapd_pr_strerror(*err) );
}
return ret;
}
/*
* Read the bytes and add them to sp->encrypted_buffer
- * - if offset < 4, tell caller we didn't read enough bytes yet
- * - if offset >= 4, decode the length and proceed.
+ * - if offset < 7, tell caller we didn't read enough bytes yet
+ * - if offset >= 7, decode the length and proceed.
*/
- if (ret < sizeof(buffer)) {
- memcpy(sp->encrypted_buffer + sp->encrypted_buffer_offset, buffer, ret);
- sp->encrypted_buffer_offset += ret;
- if (sp->encrypted_buffer_offset < sizeof(buffer)) {
- LDAPDebug2Args( LDAP_DEBUG_CONNS,
- "sasl_io_start_packet: read only %d bytes of sasl packet "
- "length on connection %" NSPRIu64 "\n", ret, c->c_connid );
+ if((ret + sp->encrypted_buffer_offset) > sp->encrypted_buffer_size){
+ sasl_io_resize_encrypted_buffer(sp, ret + sp->encrypted_buffer_offset);
+ }
+ memcpy(sp->encrypted_buffer + sp->encrypted_buffer_offset, buffer, ret);
+ sp->encrypted_buffer_offset += ret;
+ if (sp->encrypted_buffer_offset < sizeof(buffer)) {
+ LDAPDebug2Args( LDAP_DEBUG_CONNS,
+ "sasl_io_start_packet: read only %d bytes of sasl packet "
+ "length on connection %" NSPRIu64 "\n", ret, c->c_connid );
#if defined(EWOULDBLOCK)
- errno = EWOULDBLOCK;
+ errno = EWOULDBLOCK;
#elif defined(EAGAIN)
- errno = EAGAIN;
+ errno = EAGAIN;
#endif
- PR_SetError(PR_WOULD_BLOCK_ERROR, errno);
+ PR_SetError(PR_WOULD_BLOCK_ERROR, errno);
+ return PR_FAILURE;
+ }
+
+ /*
+ * Check if an LDAP operation was sent unencrypted
+ */
+ if(!sp->send_encrypted && *sp->encrypted_buffer == LDAP_TAG_MESSAGE){
+ struct berval bv, tmp_bv;
+ BerElement *ber = NULL;
+ ber_len_t maxbersize = config_get_maxbersize();
+ ber_len_t ber_len = 0;
+ ber_tag_t tag;
+
+ slapi_log_error( SLAPI_LOG_CONNS, "sasl_io_start_packet", "conn=%" NSPRIu64 " fd=%d "
+ "Sent an LDAP message that was not encrypted.\n", c->c_connid, c->c_sd);
+
+ /* Build a berval so we can get the length before reading in the entire packet */
+ bv.bv_val = sp->encrypted_buffer;
+ bv.bv_len = sp->encrypted_buffer_offset;
+ if((ber_len = slapi_berval_get_msg_len(&bv, 0)) == -1){
+ goto done;
+ }
+
+ /* Is the ldap operation too large? */
+ if(ber_len > maxbersize){
+ slapi_log_error( SLAPI_LOG_FATAL, "connection",
+ "conn=%" NSPRIu64 " fd=%d Incoming BER Element was too long, max allowable "
+ "is %" BERLEN_T " bytes. Change the nsslapd-maxbersize attribute in "
+ "cn=config to increase.\n",
+ c->c_connid, c->c_sd, maxbersize );
+ PR_SetError(PR_IO_ERROR, 0);
return PR_FAILURE;
}
- } else {
- memcpy(sp->encrypted_buffer, buffer, sizeof(buffer));
- sp->encrypted_buffer_offset = sizeof(buffer);
+ /*
+ * Bump the ber length by 2 for the tag/length we skipped over when calculating the berval length.
+ * We now have the total "packet" size, so we know exactly what is left to read in.
+ */
+ ber_len += 2;
+
+ /*
+ * Read in the rest of the packet.
+ *
+ * sp->encrypted_buffer_offset is the total number of bytes that have been written
+ * to the buffer. Once we have the complete LDAP packet we'll set it back to zero,
+ * and adjust the sp->encrypted_buffer_count.
+ */
+ while(sp->encrypted_buffer_offset < ber_len){
+ unsigned char mybuf[SASL_IO_BUFFER_SIZE];
+
+ ret = PR_Recv(fd->lower, mybuf, SASL_IO_BUFFER_SIZE, flags, timeout);
+ if (ret == PR_WOULD_BLOCK_ERROR || (ret == 0 && sp->encrypted_buffer_offset < ber_len)){
+ /*
+ * Need more data, go back and try to get more data from connection_read_operation()
+ * We can return and continue to update sp->encrypted_buffer because we have
+ * maintained the current size in encrypted_buffer_offset.
+ */
+#if defined(EWOULDBLOCK)
+ errno = EWOULDBLOCK;
+#elif defined(EAGAIN)
+ errno = EAGAIN;
+#endif
+ PR_SetError(PR_WOULD_BLOCK_ERROR, errno);
+ return PR_FAILURE;
+ } else if (ret > 0) {
+ LDAPDebug( LDAP_DEBUG_CONNS,
+ "Continued: read sasl packet length returned %d on connection %" NSPRIu64 "\n",
+ ret, c->c_connid, 0 );
+ if((ret + sp->encrypted_buffer_offset) > sp->encrypted_buffer_size){
+ sasl_io_resize_encrypted_buffer(sp, ret + sp->encrypted_buffer_offset);
+ }
+ memcpy(sp->encrypted_buffer + sp->encrypted_buffer_offset, mybuf, ret );
+ sp->encrypted_buffer_offset += ret;
+ } else if (ret < 0){
+ *err = PR_GetError();
+ LDAPDebug( LDAP_DEBUG_CONNS, "sasl_io_start_packet: error reading sasl packet length on connection "
+ "%" NSPRIu64 " %d:%s\n", c->c_connid, *err, slapd_pr_strerror(*err) );
+ return ret;
+ }
+ }
+
+ /*
+ * Reset the berval with the updated buffer, and create the berElement
+ */
+ bv.bv_val = sp->encrypted_buffer;
+ bv.bv_len = sp->encrypted_buffer_offset;
+ if ( (ber = ber_init(&bv)) == NULL){
+ goto done;
+ }
+
+ /*
+ * Start parsing the berElement. First skip this tag, and move on to the
+ * tag msgid
+ */
+ ber_skip_tag(ber, &ber_len);
+ if( ber_peek_tag( ber, &ber_len ) == LDAP_TAG_MSGID) {
+ /*
+ * Skip the entire msgid element, so we can get to the LDAP op tag
+ */
+ if(ber_skip_element(ber, &tmp_bv) == LDAP_TAG_MSGID) {
+ /*
+ * We only allow unbind operations to be processed for unencrypted operations
+ */
+ if (( tag = ber_peek_tag( ber, &ber_len )) == LDAP_REQ_UNBIND ) {
+ slapi_log_error( SLAPI_LOG_CONNS, "sasl_io_start_packet", "conn=%" NSPRIu64 " fd=%d "
+ "Received unencrypted UNBIND operation.\n", c->c_connid, c->c_sd);
+ sp->encrypted_buffer_count = sp->encrypted_buffer_offset;
+ sp->encrypted_buffer_offset = 0;
+ ber_free(ber, 1);
+ return SASL_IO_BUFFER_NOT_ENCRYPTED;
+ }
+ slapi_log_error( SLAPI_LOG_CONNS, "sasl_io_start_packet", "conn=%" NSPRIu64 " fd=%d "
+ "Error: received an LDAP message (tag 0x%lx) that was not encrypted.\n",
+ c->c_connid, c->c_sd, tag);
+ }
+ }
+
+done:
+ /* If we got here we have garbage, or a denied LDAP operation */
+ slapi_log_error( SLAPI_LOG_CONNS, "sasl_io_start_packet", "conn=%" NSPRIu64 " fd=%d "
+ "Error: received an invalid message that was not encrypted.\n",
+ c->c_connid, c->c_sd);
+
+ if (NULL != ber){
+ ber_free(ber, 1);
+ }
+ PR_SetError(PR_IO_ERROR, 0);
+
+ return PR_FAILURE;
}
+
/* At this point, sp->encrypted_buffer_offset == sizeof(buffer) */
/* Decode the length */
packet_length = ntohl(*(uint32_t *)sp->encrypted_buffer);
@@ -334,6 +464,14 @@ sasl_io_recv(PRFileDesc *fd, void *buf, PRInt32 len, PRIntn flags,
if (!sasl_io_reading_packet(sp)) {
/* First read the packet length and so on */
ret = sasl_io_start_packet(fd, flags, timeout, &err);
+ if (SASL_IO_BUFFER_NOT_ENCRYPTED == ret) {
+ /*
+ * Special case: we received unencrypted data that was actually
+ * an unbind. Copy it to the buffer and return its length.
+ */
+ memcpy(buf, sp->encrypted_buffer, sp->encrypted_buffer_count);
+ return sp->encrypted_buffer_count;
+ }
if (0 >= ret) {
/* timeout, connection closed, or error */
return ret;
diff --git a/ldap/servers/slapd/slapi-plugin.h b/ldap/servers/slapd/slapi-plugin.h
index d548baf..a22ef29 100644
--- a/ldap/servers/slapd/slapi-plugin.h
+++ b/ldap/servers/slapd/slapi-plugin.h
@@ -2998,6 +2998,16 @@ void slapi_rdn_free(Slapi_RDN **rdn);
int slapi_is_ipv6_addr( const char *ipAddress);
/**
+ * Returns the length of a ber-encoded ldap operation
+ *
+ * \param bv is the berval of the encoded ldap operation
+ * \param strict set to 0 if "bv" does not contain the entire LDAP encoding
+ * \return -1 if the length can not be determined
+ * \return length
+ */
+ber_len_t slapi_berval_get_msg_len(struct berval *bv, int strict);
+
+/**
* Frees and clears the contents of a \c Slapi_RDN structure from memory.
*
* Both the RDN value and the array of split RDNs are freed. Those pointers
10 years, 9 months
Branch '389-ds-base-1.3.1' - ldap/servers
by Ludwig Krispenz
ldap/servers/slapd/attr.c | 60 -
ldap/servers/slapd/attrlist.c | 2
ldap/servers/slapd/attrsyntax.c | 6
ldap/servers/slapd/back-ldbm/import-threads.c | 2
ldap/servers/slapd/back-ldbm/index.c | 24
ldap/servers/slapd/back-ldbm/ldbm_attr.c | 6
ldap/servers/slapd/computed.c | 2
ldap/servers/slapd/entry.c | 123 ---
ldap/servers/slapd/entrywsi.c | 9
ldap/servers/slapd/proto-slap.h | 14
ldap/servers/slapd/schema.c | 101 --
ldap/servers/slapd/slap.h | 8
ldap/servers/slapd/slapi-plugin.h | 15
ldap/servers/slapd/slapi-private.h | 5
ldap/servers/slapd/valueset.c | 1015 ++++++++++++--------------
15 files changed, 598 insertions(+), 794 deletions(-)
New commits:
commit f6ef7dc23352c82f45c41dfd5e9392971a164a23
Author: Ludwig Krispenz <lkrispen(a)redhat.com>
Date: Thu Jul 18 16:30:17 2013 +0200
Ticket 346 - version 4 Slow ldapmodify operation time
for large quantities of multi-valued attribute values
Bug Description: The reason for the performance degradation is that for
operations like add and delete of values and for updating the index for
each values a check has tobe done if it exists in the current attribute.
if the number of values grows the seaqrch time increases
Fix Description: Keep a secondary array of the indexes of the valuearray which is sorted.
To locate a value, a binary search can be used.
A design doc is available at: http://port389.org/wiki/Static_group_performance
https://fedorahosted.org/389/ticket/346
Reviewed by: ?
diff --git a/ldap/servers/slapd/attr.c b/ldap/servers/slapd/attr.c
index 03b366c..a8c3796 100644
--- a/ldap/servers/slapd/attr.c
+++ b/ldap/servers/slapd/attr.c
@@ -365,11 +365,9 @@ Slapi_Attr *
slapi_attr_dup(const Slapi_Attr *attr)
{
Slapi_Attr *newattr= slapi_attr_new();
- Slapi_Value **present_va= valueset_get_valuearray(&attr->a_present_values); /* JCM Mucking about inside the value set */
- Slapi_Value **deleted_va= valueset_get_valuearray(&attr->a_deleted_values); /* JCM Mucking about inside the value set */
slapi_attr_init(newattr, attr->a_type);
- valueset_add_valuearray( &newattr->a_present_values, present_va );
- valueset_add_valuearray( &newattr->a_deleted_values, deleted_va );
+ slapi_valueset_set_valueset( &newattr->a_deleted_values, &attr->a_deleted_values );
+ slapi_valueset_set_valueset( &newattr->a_present_values, &attr->a_present_values );
newattr->a_deletioncsn= csn_dup(attr->a_deletioncsn);
return newattr;
}
@@ -835,43 +833,11 @@ attr_add_valuearray(Slapi_Attr *a, Slapi_Value **vals, const char *dn)
}
/*
- * determine whether we should use an AVL tree of values or not
+ * add values and check for duplicate values
*/
- for ( i = 0; vals[i] != NULL; i++ ) ;
- numofvals = i;
-
- /*
- * detect duplicate values
- */
- if ( numofvals > 1 ) {
- /*
- * Several values to add: use an AVL tree to detect duplicates.
- */
- LDAPDebug( LDAP_DEBUG_TRACE,
- "slapi_entry_add_values: using an AVL tree to "
- "detect duplicate values\n", 0, 0, 0 );
-
- if (valueset_isempty(&a->a_present_values)) {
- /* if the attribute contains no values yet, just check the
- * input vals array for duplicates
- */
- Avlnode *vtree = NULL;
- rc= valuetree_add_valuearray(a, vals, &vtree, &duplicate_index);
- valuetree_free(&vtree);
- was_present_null = 1;
- } else {
- /* the attr and vals both contain values, check intersection */
- rc= valueset_intersectswith_valuearray(&a->a_present_values, a, vals, &duplicate_index);
- }
-
- } else if ( !valueset_isempty(&a->a_present_values) ) {
- /*
- * One or no value to add: don't bother constructing
- * an AVL tree, etc. since it probably isn't worth the time.
- */
- for ( i = 0; vals[i] != NULL; ++i ) {
- if ( slapi_attr_value_find( a, slapi_value_get_berval(vals[i]) ) == 0 ) {
- duplicate_index = i;
+ numofvals = valuearray_count(vals);
+ rc = slapi_valueset_add_attr_valuearray_ext (a, &a->a_present_values, vals, numofvals, SLAPI_VALUE_FLAG_DUPCHECK, &duplicate_index);
+ if ( rc != LDAP_SUCCESS) {
#if defined(USE_OLD_UNHASHED)
if (is_type_forbidden(a->a_type)) {
/* If the attr is in the forbidden list
@@ -884,22 +850,12 @@ attr_add_valuearray(Slapi_Attr *a, Slapi_Value **vals, const char *dn)
#else
rc = LDAP_TYPE_OR_VALUE_EXISTS;
#endif
- break;
}
- }
- }
-
- /*
- * add values if no duplicates detected
- */
- if(rc==LDAP_SUCCESS) {
- valueset_add_valuearray( &a->a_present_values, vals );
- }
/* In the case of duplicate value, rc == LDAP_TYPE_OR_VALUE_EXISTS or
* LDAP_OPERATIONS_ERROR
*/
- else if ( duplicate_index >= 0 ) {
+ if ( duplicate_index >= 0 ) {
char bvvalcopy[BUFSIZ];
char *duplicate_string = "null or non-ASCII";
@@ -940,7 +896,7 @@ attr_add_valuearray(Slapi_Attr *a, Slapi_Value **vals, const char *dn)
*/
int attr_replace(Slapi_Attr *a, Slapi_Value **vals)
{
- return valueset_replace(a, &a->a_present_values, vals);
+ return valueset_replace_valuearray(a, &a->a_present_values, vals);
}
int
diff --git a/ldap/servers/slapd/attrlist.c b/ldap/servers/slapd/attrlist.c
index 1f52bb8..8825e2b 100644
--- a/ldap/servers/slapd/attrlist.c
+++ b/ldap/servers/slapd/attrlist.c
@@ -129,7 +129,7 @@ attrlist_merge_valuearray(Slapi_Attr **alist, const char *type, Slapi_Value **va
Slapi_Attr **a= NULL;
if (!vals) return;
attrlist_find_or_create(alist, type, &a);
- valueset_add_valuearray( &(*a)->a_present_values, vals );
+ slapi_valueset_add_valuearray( *a, &(*a)->a_present_values, vals );
}
diff --git a/ldap/servers/slapd/attrsyntax.c b/ldap/servers/slapd/attrsyntax.c
index 0759d61..547179f 100644
--- a/ldap/servers/slapd/attrsyntax.c
+++ b/ldap/servers/slapd/attrsyntax.c
@@ -1047,6 +1047,10 @@ slapi_attr_is_dn_syntax_attr(Slapi_Attr *attr)
const char *syntaxoid = NULL;
int dn_syntax = 0; /* not DN, by default */
+ if (attr && attr->a_flags & SLAPI_ATTR_FLAG_SYNTAX_IS_DN)
+ /* it was checked before */
+ return(1);
+
if (attr && attr->a_plugin == NULL) {
slapi_attr_init_syntax (attr);
}
@@ -1055,6 +1059,8 @@ slapi_attr_is_dn_syntax_attr(Slapi_Attr *attr)
dn_syntax = ((0 == strcmp(syntaxoid, NAMEANDOPTIONALUID_SYNTAX_OID))
|| (0 == strcmp(syntaxoid, DN_SYNTAX_OID)));
}
+ if (dn_syntax)
+ attr->a_flags |= SLAPI_ATTR_FLAG_SYNTAX_IS_DN;
}
return dn_syntax;
}
diff --git a/ldap/servers/slapd/back-ldbm/import-threads.c b/ldap/servers/slapd/back-ldbm/import-threads.c
index 5cb5663..3a2904e 100644
--- a/ldap/servers/slapd/back-ldbm/import-threads.c
+++ b/ldap/servers/slapd/back-ldbm/import-threads.c
@@ -2639,7 +2639,7 @@ import_foreman(void *param)
/* Setting new entrydn attribute value */
slapi_attr_init(new_entrydn, "entrydn");
- valueset_add_string(&new_entrydn->a_present_values,
+ valueset_add_string(new_entrydn, &new_entrydn->a_present_values,
/* new_dn: duped in valueset_add_string */
(const char *)new_dn,
CSN_TYPE_UNKNOWN, NULL);
diff --git a/ldap/servers/slapd/back-ldbm/index.c b/ldap/servers/slapd/back-ldbm/index.c
index c502017..bb69c57 100644
--- a/ldap/servers/slapd/back-ldbm/index.c
+++ b/ldap/servers/slapd/back-ldbm/index.c
@@ -545,7 +545,7 @@ index_add_mods(
for (curr_attr = newe->ep_entry->e_attrs; curr_attr != NULL; curr_attr = curr_attr->a_next) {
if (slapi_attr_type_cmp( basetype, curr_attr->a_type, SLAPI_TYPE_CMP_BASE ) == 0) {
- valueset_add_valuearray(all_vals, attr_get_present_values(curr_attr));
+ slapi_valueset_join_attr_valueset(curr_attr, all_vals, &curr_attr->a_present_values);
}
}
@@ -566,7 +566,7 @@ index_add_mods(
for (curr_attr = olde->ep_entry->e_attrs; curr_attr != NULL; curr_attr = curr_attr->a_next) {
if (slapi_attr_type_cmp( mods[i]->mod_type, curr_attr->a_type, SLAPI_TYPE_CMP_EXACT ) == 0) {
- valueset_add_valuearray(mod_vals, attr_get_present_values(curr_attr));
+ slapi_valueset_join_attr_valueset(curr_attr, mod_vals, &curr_attr->a_present_values);
}
}
@@ -584,7 +584,7 @@ index_add_mods(
slapi_entry_attr_find( olde->ep_entry, mods[i]->mod_type, &curr_attr );
if ( mods_valueArray != NULL ) {
for ( j = 0; mods_valueArray[j] != NULL; j++ ) {
- Slapi_Value *rval = valuearray_remove_value(curr_attr, evals, mods_valueArray[j]);
+ Slapi_Value *rval = valueset_remove_value(curr_attr, all_vals, mods_valueArray[j]);
slapi_value_free( &rval );
}
}
@@ -593,12 +593,12 @@ index_add_mods(
* they don't exist, delete the equality index.
*/
for ( j = 0; deleted_valueArray[j] != NULL; j++ ) {
- if (valuearray_find(curr_attr, evals, deleted_valueArray[j]) == -1) {
+ if ( !slapi_valueset_find(curr_attr, all_vals, deleted_valueArray[j])) {
if (!(flags & BE_INDEX_EQUALITY)) {
flags |= BE_INDEX_EQUALITY;
}
} else {
- Slapi_Value *rval = valuearray_remove_value(curr_attr, deleted_valueArray, deleted_valueArray[j]);
+ Slapi_Value *rval = valueset_remove_value(curr_attr, mod_vals, deleted_valueArray[j]);
slapi_value_free( &rval );
j--;
/* indicates there was some conflict */
@@ -637,8 +637,8 @@ index_add_mods(
if (curr_attr) { /* found the type */
for (j = 0; mods_valueArray[j] != NULL; j++) {
/* mods_valueArray[j] is in curr_attr ==> return 0 */
- if (slapi_attr_value_find(curr_attr,
- slapi_value_get_berval(mods_valueArray[j]))) {
+ if ( !slapi_valueset_find(curr_attr, &curr_attr->a_present_values,
+ mods_valueArray[j])) {
/* The value is NOT in newe, remove it. */
Slapi_Value *rval;
rval = valuearray_remove_value(curr_attr,
@@ -677,7 +677,7 @@ index_add_mods(
for (curr_attr = olde->ep_entry->e_attrs; curr_attr != NULL; curr_attr = curr_attr->a_next) {
if (slapi_attr_type_cmp( mods[i]->mod_type, curr_attr->a_type, SLAPI_TYPE_CMP_EXACT ) == 0) {
- valueset_add_valuearray(mod_vals, attr_get_present_values(curr_attr));
+ slapi_valueset_join_attr_valueset(curr_attr, mod_vals, &curr_attr->a_present_values);
}
}
@@ -693,15 +693,15 @@ index_add_mods(
/* Check if the any values being deleted
* also exist in a subtype.
*/
- for (j = 0; deleted_valueArray && deleted_valueArray[j]; j++) {
- if ( valuearray_find(curr_attr, evals, deleted_valueArray[j]) == -1 ) {
+ for ( j=0; deleted_valueArray[j] != NULL; j++) {
+ if ( !slapi_valueset_find(curr_attr, all_vals, deleted_valueArray[j])) {
/* If the equality flag isn't already set, set it */
if (!(flags & BE_INDEX_EQUALITY)) {
flags |= BE_INDEX_EQUALITY;
}
} else {
/* Remove duplicate value from the mod list */
- Slapi_Value *rval = valuearray_remove_value(curr_attr, deleted_valueArray, deleted_valueArray[j]);
+ Slapi_Value *rval = valueset_remove_value(curr_attr, mod_vals, deleted_valueArray[j]);
slapi_value_free( &rval );
j--;
}
@@ -750,7 +750,7 @@ index_add_mods(
if (curr_attr) {
int found = 0;
for (j = 0; mods_valueArray[j] != NULL; j++ ) {
- if ( valuearray_find(curr_attr, evals, mods_valueArray[j]) > -1 ) {
+ if ( slapi_valueset_find(curr_attr, all_vals, mods_valueArray[j])) {
/* The same value found in evals.
* We don't touch the equality index. */
found = 1;
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_attr.c b/ldap/servers/slapd/back-ldbm/ldbm_attr.c
index 7433ec7..fd43ce9 100644
--- a/ldap/servers/slapd/back-ldbm/ldbm_attr.c
+++ b/ldap/servers/slapd/back-ldbm/ldbm_attr.c
@@ -437,7 +437,7 @@ ldbm_compute_evaluator(computed_attr_context *c,char* type,Slapi_Entry *e,slapi_
Slapi_Attr our_attr;
slapi_attr_init(&our_attr, numsubordinates);
our_attr.a_flags = SLAPI_ATTR_FLAG_OPATTR;
- valueset_add_string(&our_attr.a_present_values,"0",CSN_TYPE_UNKNOWN,NULL);
+ valueset_add_string(&our_attr, &our_attr.a_present_values,"0",CSN_TYPE_UNKNOWN,NULL);
rc = (*outputfn) (c, &our_attr, e);
attr_done(&our_attr);
return (rc);
@@ -454,9 +454,9 @@ ldbm_compute_evaluator(computed_attr_context *c,char* type,Slapi_Entry *e,slapi_
rc = slapi_entry_attr_find( e, numsubordinates, &read_attr );
if ( (0 != rc) || slapi_entry_attr_hasvalue(e,numsubordinates,"0") ) {
/* If not, or present and zero, we return FALSE, otherwise TRUE */
- valueset_add_string(&our_attr.a_present_values,"FALSE",CSN_TYPE_UNKNOWN,NULL);
+ valueset_add_string(&our_attr, &our_attr.a_present_values,"FALSE",CSN_TYPE_UNKNOWN,NULL);
} else {
- valueset_add_string(&our_attr.a_present_values,"TRUE",CSN_TYPE_UNKNOWN,NULL);
+ valueset_add_string(&our_attr, &our_attr.a_present_values,"TRUE",CSN_TYPE_UNKNOWN,NULL);
}
rc = (*outputfn) (c, &our_attr, e);
attr_done(&our_attr);
diff --git a/ldap/servers/slapd/computed.c b/ldap/servers/slapd/computed.c
index 8259dea..7c99b45 100644
--- a/ldap/servers/slapd/computed.c
+++ b/ldap/servers/slapd/computed.c
@@ -148,7 +148,7 @@ compute_stock_evaluator(computed_attr_context *c,char* type,Slapi_Entry *e,slapi
Slapi_Attr our_attr;
slapi_attr_init(&our_attr, subschemasubentry);
our_attr.a_flags = SLAPI_ATTR_FLAG_OPATTR;
- valueset_add_string(&our_attr.a_present_values,SLAPD_SCHEMA_DN,CSN_TYPE_UNKNOWN,NULL);
+ valueset_add_string(&our_attr, &our_attr.a_present_values,SLAPD_SCHEMA_DN,CSN_TYPE_UNKNOWN,NULL);
rc = (*outputfn) (c, &our_attr, e);
attr_done(&our_attr);
return (rc);
diff --git a/ldap/servers/slapd/entry.c b/ldap/servers/slapd/entry.c
index ba7f338..d6f9fdd 100644
--- a/ldap/servers/slapd/entry.c
+++ b/ldap/servers/slapd/entry.c
@@ -237,8 +237,6 @@ str2entry_fast( const char *rawdn, const Slapi_RDN *srdn, char *s, int flags, in
int freeval = 0;
int value_state= VALUE_NOTFOUND;
int attr_state= ATTRIBUTE_NOTFOUND;
- int maxvals;
- int del_maxvals;
if ( *s == '\n' || *s == '\0' ) {
break;
@@ -280,9 +278,7 @@ str2entry_fast( const char *rawdn, const Slapi_RDN *srdn, char *s, int flags, in
slapi_ch_free_string(&ptype);
ptype=PL_strndup(type.bv_val, type.bv_len);
nvals = 0;
- maxvals = 0;
del_nvals = 0;
- del_maxvals = 0;
a = NULL;
}
@@ -503,25 +499,21 @@ str2entry_fast( const char *rawdn, const Slapi_RDN *srdn, char *s, int flags, in
if(value_state==VALUE_DELETED)
{
/* consumes the value */
- valuearray_add_value_fast(
- &(*a)->a_deleted_values.va, /* JCM .va is private */
+ slapi_valueset_add_attr_value_ext(
+ *a,
+ &(*a)->a_deleted_values,
svalue,
- del_nvals,
- &del_maxvals,
- 0/*!Exact*/,
- 1/*Passin*/ );
+ SLAPI_VALUE_FLAG_PASSIN );
del_nvals++;
}
else
{
/* consumes the value */
- valuearray_add_value_fast(
- &(*a)->a_present_values.va, /* JCM .va is private */
+ slapi_valueset_add_attr_value_ext(
+ *a,
+ &(*a)->a_present_values,
svalue,
- nvals,
- &maxvals,
- 0 /*!Exact*/,
- 1 /*Passin*/ );
+ SLAPI_VALUE_FLAG_PASSIN);
nvals++;
}
if(attributedeletioncsn!=NULL)
@@ -603,8 +595,8 @@ typedef struct _entry_attrs {
typedef struct _str2entry_attr {
char *sa_type;
int sa_state;
- struct valuearrayfast sa_present_values;
- struct valuearrayfast sa_deleted_values;
+ struct slapi_value_set sa_present_values;
+ struct slapi_value_set sa_deleted_values;
int sa_numdups;
value_compare_fn_type sa_comparefn;
Avlnode *sa_vtree;
@@ -617,8 +609,8 @@ entry_attr_init(str2entry_attr *sa, const char *type, int state)
{
sa->sa_type= slapi_ch_strdup(type);
sa->sa_state= state;
- valuearrayfast_init(&sa->sa_present_values,NULL);
- valuearrayfast_init(&sa->sa_deleted_values,NULL);
+ slapi_valueset_init(&sa->sa_present_values);
+ slapi_valueset_init(&sa->sa_deleted_values);
sa->sa_numdups= 0;
sa->sa_comparefn = NULL;
sa->sa_vtree= NULL;
@@ -1106,66 +1098,20 @@ str2entry_dupcheck( const char *rawdn, char *s, int flags, int read_stateinfo )
{
/*
* for deleted values, we do not want to perform a dupcheck against
- * existing values. Also, we do not want to add it to the
- * avl tree (if one is being maintained)
- *
+ * existing values.
*/
- rc = 0; /* Presume no duplicate */
+ rc = slapi_valueset_add_attr_value_ext(&sa->sa_attr, &sa->sa_deleted_values,value, SLAPI_VALUE_FLAG_PASSIN);
}
- else if ( !check_for_duplicate_values )
+ else
{
- rc = LDAP_SUCCESS; /* presume no duplicate */
- } else {
- /* For value dup checking, we either use brute-force, if there's a small number */
- /* Or a tree-based approach if there's a large number. */
- /* The tree code is expensive, which is why we don't use it unless there's many attributes */
- rc = 0; /* Presume no duplicate */
- if (fast_dup_check)
- {
- /* Fast dup-checking */
- /* Do we now have so many values that we should switch to tree-based checking ? */
- if (sa->sa_present_values.num > STR2ENTRY_VALUE_DUPCHECK_THRESHOLD)
- {
- /* Make the tree from the existing attr values */
- rc= valuetree_add_valuearray( &sa->sa_attr, sa->sa_present_values.va, &sa->sa_vtree, NULL);
- /* Check if the value already exists, in the tree. */
- rc= valuetree_add_value( &sa->sa_attr, value, &sa->sa_vtree);
- fast_dup_check = 0;
- }
- else
- {
- /* JCM - need an efficient valuearray function to do this */
- /* Brute-force check */
- for ( j = 0; j < sa->sa_present_values.num; j++ )/* JCM innards */
- {
- if (0 == sa->sa_comparefn(slapi_value_get_berval(value),slapi_value_get_berval(sa->sa_present_values.va[j])))/* JCM innards */
- {
- /* Oops---this value matches one already present */
- rc = LDAP_TYPE_OR_VALUE_EXISTS;
- break;
- }
- }
- }
- }
- else
- {
- /* Check if the value already exists, in the tree. */
- rc = valuetree_add_value( &sa->sa_attr, value, &sa->sa_vtree);
- }
+ int flags = SLAPI_VALUE_FLAG_PASSIN;
+ if (check_for_duplicate_values) flags |= SLAPI_VALUE_FLAG_DUPCHECK;
+ rc = slapi_valueset_add_attr_value_ext(&sa->sa_attr, &sa->sa_present_values,value, flags);
}
if ( rc==LDAP_SUCCESS )
{
- if(value_state==VALUE_DELETED)
- {
- valuearrayfast_add_value_passin(&sa->sa_deleted_values,value);
- value= NULL; /* value was consumed */
- }
- else
- {
- valuearrayfast_add_value_passin(&sa->sa_present_values,value);
- value= NULL; /* value was consumed */
- }
+ value= NULL; /* value was consumed */
if(attributedeletioncsn!=NULL)
{
sa->sa_attributedeletioncsn= attributedeletioncsn;
@@ -1180,7 +1126,7 @@ str2entry_dupcheck( const char *rawdn, char *s, int flags, int read_stateinfo )
else
{
/* Failure adding to value tree */
- LDAPDebug( LDAP_DEBUG_ANY, "str2entry_dupcheck: unexpected failure %d constructing value tree\n", rc, 0, 0 );
+ LDAPDebug( LDAP_DEBUG_ANY, "str2entry_dupcheck: unexpected failure %d adding value\n", rc, 0, 0 );
slapi_entry_free( e ); e = NULL;
goto free_and_return;
}
@@ -1245,27 +1191,21 @@ str2entry_dupcheck( const char *rawdn, char *s, int flags, int read_stateinfo )
}
if(alist!=NULL)
{
- int maxvals = 0;
Slapi_Attr **a= NULL;
attrlist_find_or_create_locking_optional(alist, sa->sa_type, &a, PR_FALSE);
- valuearray_add_valuearray_fast( /* JCM should be calling a valueset function */
- &(*a)->a_present_values.va, /* JCM .va is private */
+ slapi_valueset_add_attr_valuearray_ext(
+ *a,
+ &(*a)->a_present_values,
sa->sa_present_values.va,
- 0, /* Currently there are no present values on the attribute */
sa->sa_present_values.num,
- &maxvals,
- 1/*Exact*/,
- 1/*Passin*/);
+ SLAPI_VALUE_FLAG_PASSIN, NULL);
sa->sa_present_values.num= 0; /* The values have been consumed */
- maxvals = 0;
- valuearray_add_valuearray_fast( /* JCM should be calling a valueset function */
- &(*a)->a_deleted_values.va, /* JCM .va is private */
+ slapi_valueset_add_attr_valuearray_ext(
+ *a,
+ &(*a)->a_deleted_values,
sa->sa_deleted_values.va,
- 0, /* Currently there are no deleted values on the attribute */
sa->sa_deleted_values.num,
- &maxvals,
- 1/*Exact*/,
- 1/*Passin*/);
+ SLAPI_VALUE_FLAG_PASSIN, NULL);
sa->sa_deleted_values.num= 0; /* The values have been consumed */
if(sa->sa_attributedeletioncsn!=NULL)
{
@@ -1312,9 +1252,8 @@ free_and_return:
for ( i = 0; i < nattrs; i++ )
{
slapi_ch_free((void **) &(attrs[ i ].sa_type));
- valuearrayfast_done(&attrs[ i ].sa_present_values);
- valuearrayfast_done(&attrs[ i ].sa_deleted_values);
- valuetree_free( &attrs[ i ].sa_vtree );
+ slapi_ch_free((void **) &(attrs[ i ].sa_present_values.va));
+ slapi_ch_free((void **) &(attrs[ i ].sa_deleted_values.va));
attr_done( &attrs[ i ].sa_attr );
}
if (tree_attr_checking)
@@ -2719,7 +2658,7 @@ slapi_entry_add_string(Slapi_Entry *e, const char *type, const char *value)
{
Slapi_Attr **a= NULL;
attrlist_find_or_create(&e->e_attrs, type, &a);
- valueset_add_string ( &(*a)->a_present_values, value, CSN_TYPE_UNKNOWN, NULL);
+ valueset_add_string ( *a, &(*a)->a_present_values, value, CSN_TYPE_UNKNOWN, NULL);
return 0;
}
diff --git a/ldap/servers/slapd/entrywsi.c b/ldap/servers/slapd/entrywsi.c
index 1b16c65..158f0eb 100644
--- a/ldap/servers/slapd/entrywsi.c
+++ b/ldap/servers/slapd/entrywsi.c
@@ -464,7 +464,7 @@ entry_add_present_values_wsi(Slapi_Entry *e, const char *type, struct berval **b
/* Append the pending values to a->a_present_values */
valuearray_update_csn (valuestoadd,CSN_TYPE_VALUE_UPDATED,csn);
- valueset_add_valuearray_ext(&a->a_present_values, valuestoadd, SLAPI_VALUE_FLAG_PASSIN);
+ slapi_valueset_add_attr_valuearray_ext (a, &a->a_present_values, valuestoadd, valuearray_count(valuestoadd), SLAPI_VALUE_FLAG_PASSIN, NULL);
slapi_ch_free ( (void **)&valuestoadd );
/*
@@ -502,7 +502,7 @@ entry_add_present_values_wsi(Slapi_Entry *e, const char *type, struct berval **b
Slapi_ValueSet vs;
/* Add each deleted value to the present list */
valuearray_update_csn(deletedvalues,CSN_TYPE_VALUE_UPDATED,csn);
- valueset_add_valuearray_ext(&a->a_present_values, deletedvalues, SLAPI_VALUE_FLAG_PASSIN);
+ slapi_valueset_add_attr_valuearray_ext (a, &a->a_present_values, deletedvalues, valuearray_count(deletedvalues), SLAPI_VALUE_FLAG_PASSIN, NULL);
/* Remove the deleted values from the values to add */
valueset_set_valuearray_passin(&vs,valuestoadd);
valueset_remove_valuearray(&vs, a, deletedvalues, SLAPI_VALUE_FLAG_IGNOREERROR, &v);
@@ -584,7 +584,7 @@ entry_delete_present_values_wsi(Slapi_Entry *e, const char *type, struct berval
valueset_update_csn_for_valuearray(&a->a_deleted_values, a, valuestodelete, CSN_TYPE_VALUE_DELETED, csn, &valuesupdated);
valuearray_free(&valuesupdated);
valuearray_update_csn(valuestodelete,CSN_TYPE_VALUE_DELETED,csn);
- valueset_add_valuearray_ext(&a->a_deleted_values, valuestodelete, SLAPI_VALUE_FLAG_PASSIN);
+ slapi_valueset_add_attr_valuearray_ext (a, &a->a_deleted_values, valuestodelete, valuearray_count(valuestodelete), SLAPI_VALUE_FLAG_PASSIN, NULL);
/* all the elements in valuestodelete are passed;
* should free valuestodelete only (don't call valuearray_free)
* [622023] */
@@ -603,7 +603,8 @@ entry_delete_present_values_wsi(Slapi_Entry *e, const char *type, struct berval
/* We don't maintain a deleted value list for single valued attributes */
/* Add each deleted value to the deleted set */
valuearray_update_csn(deletedvalues,CSN_TYPE_VALUE_DELETED,csn);
- valueset_add_valuearray_ext(&a->a_deleted_values, deletedvalues, SLAPI_VALUE_FLAG_PASSIN);
+ slapi_valueset_add_attr_valuearray_ext (a,
+ &a->a_deleted_values, deletedvalues, valuearray_count(deletedvalues), SLAPI_VALUE_FLAG_PASSIN, NULL);
slapi_ch_free((void **)&deletedvalues);
}
else {
diff --git a/ldap/servers/slapd/proto-slap.h b/ldap/servers/slapd/proto-slap.h
index 52d5aee..cdcc952 100644
--- a/ldap/servers/slapd/proto-slap.h
+++ b/ldap/servers/slapd/proto-slap.h
@@ -168,13 +168,6 @@ int valuearray_first_value( Slapi_Value **va, Slapi_Value **v );
void valuearrayfast_init(struct valuearrayfast *vaf,Slapi_Value **va);
void valuearrayfast_done(struct valuearrayfast *vaf);
-void valuearrayfast_add_value(struct valuearrayfast *vaf,const Slapi_Value *v);
-void valuearrayfast_add_value_passin(struct valuearrayfast *vaf,Slapi_Value *v);
-void valuearrayfast_add_valuearrayfast(struct valuearrayfast *vaf,const struct valuearrayfast *vaf_add);
-
-int valuetree_add_value( const Slapi_Attr *sattr, const Slapi_Value *va, Avlnode **valuetreep);
-int valuetree_add_valuearray( const Slapi_Attr *sattr, Slapi_Value **va, Avlnode **valuetreep, int *duplicate_index);
-void valuetree_free( Avlnode **valuetreep );
/* Valueset functions */
@@ -185,15 +178,16 @@ int valueset_remove_valuearray(Slapi_ValueSet *vs, const Slapi_Attr *a, Slapi_Va
int valueset_purge(Slapi_ValueSet *vs, const CSN *csn);
Slapi_Value **valueset_get_valuearray(const Slapi_ValueSet *vs);
size_t valueset_size(const Slapi_ValueSet *vs);
+void slapi_valueset_add_valuearray(const Slapi_Attr *a, Slapi_ValueSet *vs, Slapi_Value **addvals);
void valueset_add_valuearray(Slapi_ValueSet *vs, Slapi_Value **addvals);
void valueset_add_valuearray_ext(Slapi_ValueSet *vs, Slapi_Value **addvals, PRUint32 flags);
-void valueset_add_string(Slapi_ValueSet *vs, const char *s, CSNType t, const CSN *csn);
+void valueset_add_string(const Slapi_Attr *a, Slapi_ValueSet *vs, const char *s, CSNType t, const CSN *csn);
void valueset_update_csn(Slapi_ValueSet *vs, CSNType t, const CSN *csn);
void valueset_add_valueset(Slapi_ValueSet *vs1, const Slapi_ValueSet *vs2);
-int valueset_intersectswith_valuearray(Slapi_ValueSet *vs, const Slapi_Attr *a, Slapi_Value **values, int *duplicate_index);
Slapi_ValueSet *valueset_dup(const Slapi_ValueSet *dupee);
void valueset_remove_string(const Slapi_Attr *a, Slapi_ValueSet *vs, const char *s);
-int valueset_replace(Slapi_Attr *a, Slapi_ValueSet *vs, Slapi_Value **vals);
+int valueset_replace_valuearray(Slapi_Attr *a, Slapi_ValueSet *vs, Slapi_Value **vals);
+int valueset_replace_valuearray_ext(Slapi_Attr *a, Slapi_ValueSet *vs, Slapi_Value **vals, int dupcheck);
void valueset_update_csn_for_valuearray(Slapi_ValueSet *vs, const Slapi_Attr *a, Slapi_Value **valuestoupdate, CSNType t, const CSN *csn, Slapi_Value ***valuesupdated);
void valueset_set_valuearray_byval(Slapi_ValueSet *vs, Slapi_Value **addvals);
void valueset_set_valuearray_passin(Slapi_ValueSet *vs, Slapi_Value **addvals);
diff --git a/ldap/servers/slapd/schema.c b/ldap/servers/slapd/schema.c
index 603ac08..0c781b1 100644
--- a/ldap/servers/slapd/schema.c
+++ b/ldap/servers/slapd/schema.c
@@ -4703,11 +4703,12 @@ va_locate_oc_val( Slapi_Value **va, const char *oc_name, const char *oc_oid )
* oc_unlock();
*/
static void
-va_expand_one_oc( const char *dn, Slapi_Value ***vap, const char *ocs )
+va_expand_one_oc( const char *dn, const Slapi_Attr *a, Slapi_ValueSet *vs, const char *ocs )
{
struct objclass *this_oc, *sup_oc;
- int p,i;
- Slapi_Value **newva;
+ int p;
+ Slapi_Value **va = vs->va;
+
this_oc = oc_find_nolock( ocs );
@@ -4724,29 +4725,19 @@ va_expand_one_oc( const char *dn, Slapi_Value ***vap, const char *ocs )
return; /* superior is unknown -- ignore */
}
- p = va_locate_oc_val( *vap, sup_oc->oc_name, sup_oc->oc_oid );
+ p = va_locate_oc_val( va, sup_oc->oc_name, sup_oc->oc_oid );
if ( p != -1 ) {
return; /* value already present -- done! */
}
- /* parent was not found. add to the end */
- for ( i = 0; (*vap)[i] != NULL; i++ ) {
- ;
- }
-
/* prevent loops: stop if more than 1000 OC values are present */
- if ( i > 1000 ) {
+ if ( slapi_valueset_count(vs) > 1000 ) {
return;
}
- newva = (Slapi_Value **)slapi_ch_realloc( (char *)*vap,
- ( i + 2 )*sizeof(Slapi_Value *));
+ slapi_valueset_add_attr_value_ext(a, vs, slapi_value_new_string(sup_oc->oc_name), SLAPI_VALUE_FLAG_PASSIN);
- newva[i] = slapi_value_new_string(sup_oc->oc_name);
- newva[i+1] = NULL;
-
- *vap = newva;
LDAPDebug( LDAP_DEBUG_TRACE,
"Entry \"%s\": added missing objectClass value %s\n",
dn, sup_oc->oc_name, 0 );
@@ -4758,88 +4749,54 @@ va_expand_one_oc( const char *dn, Slapi_Value ***vap, const char *ocs )
* All missing superior classes are added to the objectClass attribute, as
* is 'top' if it is missing.
*/
-void
-slapi_schema_expand_objectclasses( Slapi_Entry *e )
+static void
+schema_expand_objectclasses_ext( Slapi_Entry *e, int lock)
{
Slapi_Attr *sa;
- Slapi_Value **va;
+ Slapi_Value *v;
+ Slapi_ValueSet *vs;
const char *dn = slapi_entry_get_dn_const( e );
int i;
if ( 0 != slapi_entry_attr_find( e, SLAPI_ATTR_OBJECTCLASS, &sa )) {
return; /* no OC values -- nothing to do */
}
-
- va = attr_get_present_values( sa );
-
- if ( va == NULL || va[0] == NULL ) {
+ vs = &sa->a_present_values;
+ if ( slapi_valueset_isempty(vs) ) {
return; /* no OC values -- nothing to do */
}
- oc_lock_read();
+ if (lock)
+ oc_lock_read();
/*
* This loop relies on the fact that bv_expand_one_oc()
* always adds to the end
*/
- for ( i = 0; va[i] != NULL; ++i ) {
- if ( NULL != slapi_value_get_string(va[i]) ) {
- va_expand_one_oc( dn, &va, slapi_value_get_string(va[i]) );
+ i = slapi_valueset_first_value(vs,&v);
+ while ( v != NULL) {
+ if ( NULL != slapi_value_get_string(v) ) {
+ va_expand_one_oc( dn, sa, &sa->a_present_values, slapi_value_get_string(v) );
}
+ i = slapi_valueset_next_value(vs, i, &v);
}
/* top must always be present */
- va_expand_one_oc( dn, &va, "top" );
+ va_expand_one_oc( dn, sa, &sa->a_present_values, "top" );
- /*
- * Reset the present values in the set because we may have realloc'd it.
- * Note that this is the counterpart to the attr_get_present_values()
- * call we made above... nothing new has been allocated, but sa holds
- * a pointer to the original (pre realloc) va.
- */
- sa->a_present_values.va = va;
-
- oc_unlock();
+ if (lock)
+ oc_unlock();
+}
+void
+slapi_schema_expand_objectclasses( Slapi_Entry *e )
+{
+ schema_expand_objectclasses_ext( e, 1);
}
void
schema_expand_objectclasses_nolock( Slapi_Entry *e )
{
- Slapi_Attr *sa;
- Slapi_Value **va;
- const char *dn = slapi_entry_get_dn_const( e );
- int i;
-
- if ( 0 != slapi_entry_attr_find( e, SLAPI_ATTR_OBJECTCLASS, &sa )) {
- return; /* no OC values -- nothing to do */
- }
-
- va = attr_get_present_values( sa );
-
- if ( va == NULL || va[0] == NULL ) {
- return; /* no OC values -- nothing to do */
- }
-
- /*
- * This loop relies on the fact that bv_expand_one_oc()
- * always adds to the end
- */
- for ( i = 0; va[i] != NULL; ++i ) {
- if ( NULL != slapi_value_get_string(va[i]) ) {
- va_expand_one_oc( dn, &va, slapi_value_get_string(va[i]) );
- }
- }
-
- /* top must always be present */
- va_expand_one_oc( dn, &va, "top" );
-
- /*
- * Reset the present values in the set because we may have realloc'd it.
- * Note that this is the counterpart to the attr_get_present_values()
- * call we made above... nothing new has been allocated, but sa holds
- * a pointer to the original (pre realloc) va.
- */
- sa->a_present_values.va = va;
+ schema_expand_objectclasses_ext( e, 0);
}
/* lock to protect both objectclass and schema_dse */
diff --git a/ldap/servers/slapd/slap.h b/ldap/servers/slapd/slap.h
index 7e38d26..b1246c5 100644
--- a/ldap/servers/slapd/slap.h
+++ b/ldap/servers/slapd/slap.h
@@ -450,8 +450,14 @@ struct slapi_value
* struct slapi_value_tree *vt;
* };
*/
+
+/* It is a useless layer, always use the valuarray fast version */
+#define VALUE_SORT_THRESHOLD 10
struct slapi_value_set
{
+ int num; /* The number of values in the array */
+ int max; /* The number of slots in the array */
+ int *sorted; /* sorted array of indices, if NULL va is not sorted */
struct slapi_value **va;
};
@@ -522,6 +528,8 @@ typedef struct asyntaxinfo {
#define SLAPI_ATTR_FLAG_NOLOCKING 0x0020 /* the init code doesn't lock the
tables */
#define SLAPI_ATTR_FLAG_KEEP 0x8000 /* keep when replacing all */
+#define SLAPI_ATTR_FLAG_SYNTAX_LOOKUP_DONE 0x010000 /* syntax lookup done, flag set */
+#define SLAPI_ATTR_FLAG_SYNTAX_IS_DN 0x020000 /* syntax lookup done, flag set */
/* This is the type of the function passed into attr_syntax_enumerate_attrs */
typedef int (*AttrEnumFunc)(struct asyntaxinfo *asi, void *arg);
diff --git a/ldap/servers/slapd/slapi-plugin.h b/ldap/servers/slapd/slapi-plugin.h
index 632c081..dfc48cf 100644
--- a/ldap/servers/slapd/slapi-plugin.h
+++ b/ldap/servers/slapd/slapi-plugin.h
@@ -4650,6 +4650,7 @@ void slapi_ber_bvcpy(struct berval *bvd, const struct berval *bvs);
#define SLAPI_VALUE_FLAG_IGNOREERROR 0x2
#define SLAPI_VALUE_FLAG_PRESERVECSNSET 0x4
#define SLAPI_VALUE_FLAG_USENEWVALUE 0x8 /* see valueset_remove_valuearray */
+#define SLAPI_VALUE_FLAG_DUPCHECK 0x10 /* used in valueset_add... */
/**
* Creates an empty \c Slapi_ValueSet structure.
@@ -4743,7 +4744,8 @@ void slapi_valueset_add_value(Slapi_ValueSet *vs, const Slapi_Value *addval);
* \see slapi_valueset_first_value()
* \see slapi_valueset_next_value()
*/
-void slapi_valueset_add_value_ext(Slapi_ValueSet *vs, Slapi_Value *addval, unsigned long flags);
+void slapi_valueset_add_value_ext(Slapi_ValueSet *vs, const Slapi_Value *addval, unsigned long flags);
+int slapi_valueset_add_attr_value_ext(const Slapi_Attr *a, Slapi_ValueSet *vs, Slapi_Value *addval, unsigned long flags);
/**
* Gets the first value in a \c Slapi_ValueSet structure.
@@ -4799,6 +4801,16 @@ int slapi_valueset_next_value( Slapi_ValueSet *vs, int index, Slapi_Value **v);
int slapi_valueset_count( const Slapi_ValueSet *vs);
/**
+ * Checks if a \c Slapi_ValueSet structure has values
+ *
+ * \param vs Pointer to the \c Slapi_ValueSet structure of which
+ * you wish to get the count.
+ * \return 1 if there are no values contained in the \c Slapi_ValueSet structure.
+ * \return 0 if there are values contained in the \c Slapi_ValueSet structure.
+ */
+int slapi_valueset_isempty( const Slapi_ValueSet *vs);
+
+/**
* Initializes a \c Slapi_ValueSet with copies of the values of a \c Slapi_Mod structure.
*
* \param vs Pointer to the \c Slapi_ValueSet structure into which
@@ -4829,6 +4841,7 @@ void slapi_valueset_set_from_smod(Slapi_ValueSet *vs, Slapi_Mod *smod);
* \see slapi_valueset_done()
*/
void slapi_valueset_set_valueset(Slapi_ValueSet *vs1, const Slapi_ValueSet *vs2);
+void slapi_valueset_join_attr_valueset(const Slapi_Attr *a, Slapi_ValueSet *vs1, const Slapi_ValueSet *vs2);
/**
* Finds a requested value in a valueset.
diff --git a/ldap/servers/slapd/slapi-private.h b/ldap/servers/slapd/slapi-private.h
index faf110d..0e38e00 100644
--- a/ldap/servers/slapd/slapi-private.h
+++ b/ldap/servers/slapd/slapi-private.h
@@ -839,9 +839,12 @@ int charray_normdn_add(char ***chararray, char *dn, char *errstr);
* the very least before we make them public.
*/
void valuearray_add_value(Slapi_Value ***vals, const Slapi_Value *addval);
-void valuearray_add_value_fast(Slapi_Value ***vals, Slapi_Value *addval, int nvals, int *maxvals, int exact, int passin);
void valuearray_add_valuearray( Slapi_Value ***vals, Slapi_Value **addvals, PRUint32 flags );
void valuearray_add_valuearray_fast( Slapi_Value ***vals, Slapi_Value **addvals, int nvals, int naddvals, int *maxvals, int exact, int passin );
+Slapi_Value * valueset_find_sorted (const Slapi_Attr *a, const Slapi_ValueSet *vs, const Slapi_Value *v, int *index);
+int valueset_insert_value_to_sorted(const Slapi_Attr *a, Slapi_ValueSet *vs, Slapi_Value *vi, int dupcheck);
+void valueset_array_to_sorted (const Slapi_Attr *a, Slapi_ValueSet *vs);
+int slapi_valueset_add_attr_valuearray_ext(const Slapi_Attr *a, Slapi_ValueSet *vs, Slapi_Value **addval, int nvals, unsigned long flags, int *dup_index);
int valuearray_find(const Slapi_Attr *a, Slapi_Value **va, const Slapi_Value *v);
int valuearray_dn_normalize_value(Slapi_Value **vals);
diff --git a/ldap/servers/slapd/valueset.c b/ldap/servers/slapd/valueset.c
index dffcaeb..7ed8f36 100644
--- a/ldap/servers/slapd/valueset.c
+++ b/ldap/servers/slapd/valueset.c
@@ -500,8 +500,8 @@ valuearray_purge(Slapi_Value ***va, const CSN *csn)
slapi_ch_free((void**)va);
*va= NULL;
}
-
- return(0);
+ /* return the number of remaining values */
+ return(i);
}
size_t
@@ -530,51 +530,6 @@ valuearray_update_csn(Slapi_Value **va, CSNType t, const CSN *csn)
}
}
-/*
- * Shunt up the values to cover the empty slots.
- *
- * "compressed" means "contains no NULL's"
- *
- * Invariant for the outer loop:
- * va[0..i] is compressed &&
- * va[n..numvalues] contains just NULL's
- *
- * Invariant for the inner loop:
- * i<j<=k<=n && va[j..k] has been shifted left by (j-i) places &&
- * va[k..n] remains to be shifted left by (j-i) places
- *
- */
-void
-valuearray_compress(Slapi_Value **va,int numvalues)
-{
- int i = 0;
- int n= numvalues;
- while(i<n)
- {
- if ( va[i] != NULL ) {
- i++;
- } else {
- int k,j;
- j = i + 1;
- /* Find the length of the next run of NULL's */
- while( j<n && va[j] == NULL) { j++; }
- /* va[i..j] is all NULL && j<= n */
- for ( k = j; k<n; k++ )
- {
- va[k - (j-i)] = va[k];
- va[k] = NULL;
- }
- /* va[i..n] has been shifted down by j-i places */
- n = n - (j-i);
- /*
- * If va[i] in now non null, then bump i,
- * if not then we are done anyway (j==n) so can bump it.
- */
- i++;
- }
- }
-}
-
/* <=========================== Value Array Fast ==========================> */
void
@@ -615,237 +570,12 @@ valuearrayfast_add_value_passin(struct valuearrayfast *vaf,Slapi_Value *v)
vaf->num++;
}
-void
-valuearrayfast_add_valuearrayfast(struct valuearrayfast *vaf,const struct valuearrayfast *vaf_add)
-{
- valuearray_add_valuearray_fast(&vaf->va,vaf_add->va,vaf->num,vaf_add->num,&vaf->max,0/*Exact*/,0/*!PassIn*/);
- vaf->num+= vaf_add->num;
-}
-
-/* <=========================== ValueArrayIndexTree =======================> */
-
-static int valuetree_dupvalue_disallow( caddr_t d1, caddr_t d2 );
-static int valuetree_node_cmp( caddr_t d1, caddr_t d2 );
-static int valuetree_node_free( caddr_t data );
-
-/*
- * structure used within AVL value trees.
- */
-typedef struct valuetree_node
-{
- int index; /* index into the value array */
- Slapi_Value *sval; /* the actual value */
-} valuetree_node;
-
-/*
- * Create or update an AVL tree of values that can be used to speed up value
- * lookups. We store the index keys for the values in the AVL tree so
- * we can use a trivial comparison function.
- *
- * Returns:
- * LDAP_SUCCESS on success,
- * LDAP_TYPE_OR_VALUE_EXISTS if the value already exists,
- * LDAP_OPERATIONS_ERROR for some unexpected failure.
- *
- * Sets *valuetreep to the root of the AVL tree that was created. If a
- * non-zero value is returned, the tree is freed if free_on_error is non-zero
- * and *valuetreep is set to NULL.
- */
-int
-valuetree_add_valuearray( const Slapi_Attr *sattr, Slapi_Value **va, Avlnode **valuetreep, int *duplicate_index )
-{
- int rc= LDAP_SUCCESS;
-
- PR_ASSERT(sattr!=NULL);
- PR_ASSERT(valuetreep!=NULL);
-
- if ( duplicate_index ) {
- *duplicate_index = -1;
- }
-
- if ( !valuearray_isempty(va) )
- {
- Slapi_Value **keyvals;
- /* Convert the value array into key values */
- if ( slapi_attr_values2keys_sv( sattr, (Slapi_Value**)va, &keyvals, LDAP_FILTER_EQUALITY ) != 0 ) /* jcm cast */
- {
- LDAPDebug( LDAP_DEBUG_ANY,"slapi_attr_values2keys_sv for attribute %s failed\n", sattr->a_type, 0, 0 );
- rc= LDAP_OPERATIONS_ERROR;
- }
- else
- {
- int i;
- valuetree_node *vaip;
- for ( i = 0; rc==LDAP_SUCCESS && va[i] != NULL; ++i )
- {
- if ( keyvals[i] == NULL )
- {
- LDAPDebug( LDAP_DEBUG_ANY,"slapi_attr_values2keys_sv for attribute %s did not return enough key values\n", sattr->a_type, 0, 0 );
- rc= LDAP_OPERATIONS_ERROR;
- }
- else
- {
- vaip = (valuetree_node *)slapi_ch_malloc( sizeof( valuetree_node ));
- vaip->index = i;
- vaip->sval = keyvals[i];
- if (( rc = avl_insert( valuetreep, vaip, valuetree_node_cmp, valuetree_dupvalue_disallow )) != 0 )
- {
- slapi_ch_free( (void **)&vaip );
- /* Value must already be in there */
- rc= LDAP_TYPE_OR_VALUE_EXISTS;
- if ( duplicate_index ) {
- *duplicate_index = i;
- }
- }
- else
- {
- keyvals[i]= NULL;
- }
- }
- }
- /* start freeing at index i - the rest of them have already
- been moved into valuetreep
- the loop iteration will always do the +1, so we have
- to remove it if so */
- i = (i > 0) ? i-1 : 0;
- valuearray_free_ext( &keyvals, i );
- }
- }
- if(rc!=0)
- {
- valuetree_free( valuetreep );
- }
-
- return rc;
-}
-
-int
-valuetree_add_value( const Slapi_Attr *sattr, const Slapi_Value *v, Avlnode **valuetreep)
-{
- Slapi_Value *va[2];
- va[0]= (Slapi_Value*)v;
- va[1]= NULL;
- return valuetree_add_valuearray( sattr, va, valuetreep, NULL);
-}
-
-
-/*
- *
- * Find value "v" using AVL tree "valuetree"
- *
- * returns LDAP_SUCCESS if "v" was found, LDAP_NO_SUCH_ATTRIBUTE
- * if "v" was not found and LDAP_OPERATIONS_ERROR if some unexpected error occurs.
- */
-static int
-valuetree_find( const struct slapi_attr *a, const Slapi_Value *v, Avlnode *valuetree, int *index)
-{
- const Slapi_Value *oneval[2];
- Slapi_Value **keyvals;
- valuetree_node *vaip, tmpvain;
-
- PR_ASSERT(a!=NULL);
- PR_ASSERT(a->a_plugin!=NULL);
- PR_ASSERT(v!=NULL);
- PR_ASSERT(valuetree!=NULL);
- PR_ASSERT(index!=NULL);
-
- if ( a == NULL || v == NULL || valuetree == NULL )
- {
- return( LDAP_OPERATIONS_ERROR );
- }
-
- keyvals = NULL;
- oneval[0] = v;
- oneval[1] = NULL;
- if ( slapi_attr_values2keys_sv( a, (Slapi_Value**)oneval, &keyvals, LDAP_FILTER_EQUALITY ) != 0 /* jcm cast */
- || keyvals == NULL
- || keyvals[0] == NULL )
- {
- LDAPDebug( LDAP_DEBUG_ANY, "valuetree_find_and_replace: "
- "slapi_attr_values2keys_sv failed for type %s\n",
- a->a_type, 0, 0 );
- return( LDAP_OPERATIONS_ERROR );
- }
-
- tmpvain.index = 0;
- tmpvain.sval = keyvals[0];
- vaip = (valuetree_node *)avl_find( valuetree, &tmpvain, valuetree_node_cmp );
-
- if ( keyvals != NULL )
- {
- valuearray_free( &keyvals );
- }
-
- if (vaip == NULL)
- {
- return( LDAP_NO_SUCH_ATTRIBUTE );
- }
- else
- {
- *index= vaip->index;
- }
-
- return( LDAP_SUCCESS );
-}
-
-static int
-valuetree_dupvalue_disallow( caddr_t d1, caddr_t d2 )
-{
- return( 1 );
-}
-
-
-void
-valuetree_free( Avlnode **valuetreep )
-{
- if ( valuetreep != NULL && *valuetreep != NULL )
- {
- avl_free( *valuetreep, valuetree_node_free );
- *valuetreep = NULL;
- }
-}
-
-
-static int
-valuetree_node_free( caddr_t data )
-{
- if ( data!=NULL )
- {
- valuetree_node *vaip = (valuetree_node *)data;
-
- slapi_value_free(&vaip->sval);
- slapi_ch_free( (void **)&data );
- }
- return( 0 );
-}
-
-
-static int
-valuetree_node_cmp( caddr_t d1, caddr_t d2 )
-{
- const struct berval *bv1, *bv2;
- int rc;
-
- bv1 = slapi_value_get_berval(((valuetree_node *)d1)->sval);
- bv2 = slapi_value_get_berval(((valuetree_node *)d2)->sval);
-
- if ( bv1->bv_len < bv2->bv_len ) {
- rc = -1;
- } else if ( bv1->bv_len > bv2->bv_len ) {
- rc = 1;
- } else {
- rc = memcmp( bv1->bv_val, bv2->bv_val, bv1->bv_len );
- }
-
- return( rc );
-}
/* <=========================== Value Set =======================> */
-/*
- * JCM: All of these valueset functions are just forwarded to the
- * JCM: valuearray functions... waste of time. Inline them!
- */
+#define VALUESET_ARRAY_SORT_THRESHOLD 10
+#define VALUESET_ARRAY_MINSIZE 2
+#define VALUESET_ARRAY_MAXINCREMENT 4096
Slapi_ValueSet *
slapi_valueset_new()
@@ -864,6 +594,9 @@ slapi_valueset_init(Slapi_ValueSet *vs)
if(vs!=NULL)
{
vs->va= NULL;
+ vs->sorted = NULL;
+ vs->num = 0;
+ vs->max = 0;
}
}
@@ -877,6 +610,13 @@ slapi_valueset_done(Slapi_ValueSet *vs)
valuearray_free(&vs->va);
vs->va= NULL;
}
+ if (vs->sorted != NULL)
+ {
+ slapi_ch_free ((void **)&vs->sorted);
+ vs->sorted = NULL;
+ }
+ vs->num = 0;
+ vs->max = 0;
}
}
@@ -901,8 +641,22 @@ slapi_valueset_set_from_smod(Slapi_ValueSet *vs, Slapi_Mod *smod)
void
valueset_set_valuearray_byval(Slapi_ValueSet *vs, Slapi_Value **addvals)
{
+ int i, j=0;
slapi_valueset_init(vs);
- valueset_add_valuearray(vs,addvals);
+ vs->num = valuearray_count(addvals);
+ vs->max = vs->num + 1;
+ vs->va = (Slapi_Value **) slapi_ch_malloc( vs->max * sizeof(Slapi_Value *));
+ for ( i = 0, j = 0; i < vs->num; i++)
+ {
+ if ( addvals[i]!=NULL )
+ {
+ /* We copy the values */
+ vs->va[j] = slapi_value_dup(addvals[i]);
+ j++;
+ }
+ }
+ vs->va[j] = NULL;
+
}
void
@@ -910,6 +664,8 @@ valueset_set_valuearray_passin(Slapi_ValueSet *vs, Slapi_Value **addvals)
{
slapi_valueset_init(vs);
vs->va= addvals;
+ vs->num = valuearray_count(addvals);
+ vs->max = vs->num + 1;
}
void
@@ -919,6 +675,15 @@ slapi_valueset_set_valueset(Slapi_ValueSet *vs1, const Slapi_ValueSet *vs2)
valueset_add_valueset(vs1,vs2);
}
+void
+slapi_valueset_join_attr_valueset(const Slapi_Attr *a, Slapi_ValueSet *vs1, const Slapi_ValueSet *vs2)
+{
+ if (slapi_valueset_isempty(vs1))
+ valueset_add_valueset(vs1,vs2);
+ else
+ slapi_valueset_add_attr_valuearray_ext (a, vs1, vs2->va, vs2->num, 0, NULL);
+}
+
int
slapi_valueset_first_value( Slapi_ValueSet *vs, Slapi_Value **v )
{
@@ -934,15 +699,21 @@ slapi_valueset_next_value( Slapi_ValueSet *vs, int index, Slapi_Value **v)
int
slapi_valueset_count( const Slapi_ValueSet *vs)
{
- int r=0;
if (NULL != vs)
{
- if(!valuearray_isempty(vs->va))
- {
- r= valuearray_count(vs->va);
- }
+ return (vs->num);
}
- return r;
+ return 0;
+}
+
+int
+slapi_valueset_isempty( const Slapi_ValueSet *vs)
+{
+ if (NULL != vs)
+ {
+ return (vs->num == 0);
+ }
+ return 1;
}
int
@@ -956,13 +727,17 @@ Slapi_Value *
slapi_valueset_find(const Slapi_Attr *a, const Slapi_ValueSet *vs, const Slapi_Value *v)
{
Slapi_Value *r= NULL;
- if(!valuearray_isempty(vs->va))
+ if(vs->num > 0 )
{
+ if (vs->sorted) {
+ r = valueset_find_sorted(a,vs,v,NULL);
+ } else {
int i= valuearray_find(a,vs->va,v);
if(i!=-1)
{
r= vs->va[i];
}
+ }
}
return r;
}
@@ -970,16 +745,45 @@ slapi_valueset_find(const Slapi_Attr *a, const Slapi_ValueSet *vs, const Slapi_V
/*
* The value is found in the set, removed and returned.
* The caller is responsible for freeing the value.
+ *
+ * The _sorted function also handles the cleanup of the sorted array
*/
Slapi_Value *
+valueset_remove_value_sorted(const Slapi_Attr *a, Slapi_ValueSet *vs, const Slapi_Value *v)
+{
+ Slapi_Value *r= NULL;
+ int i, position = 0;
+ r = valueset_find_sorted(a,vs,v,&position);
+ if (r) {
+ /* the value was found, remove from valuearray */
+ int index = vs->sorted[position];
+ memmove(&vs->sorted[position],&vs->sorted[position+1],(vs->num - position)*sizeof(int));
+ memmove(&vs->va[index],&vs->va[index+1],(vs->num - index)*sizeof(Slapi_Value *));
+ vs->num--;
+ /* unfortunately the references in the sorted array
+ * to values past the removed one are no longer correct
+ * need to adjust */
+ for (i=0; i < vs->num; i++) {
+ if (vs->sorted[i] > index) vs->sorted[i]--;
+ }
+ }
+ return r;
+}
+Slapi_Value *
valueset_remove_value(const Slapi_Attr *a, Slapi_ValueSet *vs, const Slapi_Value *v)
{
+ if (vs->sorted) {
+ return (valueset_remove_value_sorted(a, vs, v));
+ } else {
Slapi_Value *r= NULL;
if(!valuearray_isempty(vs->va))
{
r= valuearray_remove_value(a, vs->va, v);
+ if (r)
+ vs->num--;
}
return r;
+ }
}
/*
@@ -991,9 +795,25 @@ valueset_purge(Slapi_ValueSet *vs, const CSN *csn)
int r= 0;
if(!valuearray_isempty(vs->va))
{
+ /* valuearray_purge is not valueset and sorting aware,
+ * maybe need to rewrite, at least keep the valueset
+ * consistent
+ */
r= valuearray_purge(&vs->va, csn);
+ vs->num = r;
+ if (vs->va == NULL) {
+ /* va was freed */
+ vs->max = 0;
+ }
+ /* we can no longer rely on the sorting */
+ if (vs->sorted != NULL)
+ {
+ slapi_ch_free ((void **)&vs->sorted);
+ vs->sorted = NULL;
+ }
+
}
- return r;
+ return 0;
}
Slapi_Value **
@@ -1017,11 +837,20 @@ valueset_size(const Slapi_ValueSet *vs)
* The value array is passed in by value.
*/
void
+slapi_valueset_add_valuearray(const Slapi_Attr *a, Slapi_ValueSet *vs, Slapi_Value **addvals)
+{
+ if(!valuearray_isempty(addvals))
+ {
+ slapi_valueset_add_attr_valuearray_ext (a, vs, addvals, valuearray_count(addvals), 0, NULL);
+ }
+}
+
+void
valueset_add_valuearray(Slapi_ValueSet *vs, Slapi_Value **addvals)
{
if(!valuearray_isempty(addvals))
{
- valuearray_add_valuearray(&vs->va, addvals, 0);
+ slapi_valueset_add_attr_valuearray_ext (NULL, vs, addvals, valuearray_count(addvals), 0, NULL);
}
}
@@ -1030,7 +859,7 @@ valueset_add_valuearray_ext(Slapi_ValueSet *vs, Slapi_Value **addvals, PRUint32
{
if(!valuearray_isempty(addvals))
{
- valuearray_add_valuearray(&vs->va, addvals, flags);
+ slapi_valueset_add_attr_valuearray_ext (NULL, vs, addvals, valuearray_count(addvals), flags, NULL);
}
}
@@ -1040,28 +869,282 @@ valueset_add_valuearray_ext(Slapi_ValueSet *vs, Slapi_Value **addvals, PRUint32
void
slapi_valueset_add_value(Slapi_ValueSet *vs, const Slapi_Value *addval)
{
- valuearray_add_value(&vs->va,addval);
+ slapi_valueset_add_value_ext(vs, addval, 0);
}
void
-slapi_valueset_add_value_ext(Slapi_ValueSet *vs, Slapi_Value *addval, unsigned long flags)
+slapi_valueset_add_value_ext(Slapi_ValueSet *vs, const Slapi_Value *addval, unsigned long flags)
{
Slapi_Value *oneval[2];
oneval[0]= (Slapi_Value*)addval;
oneval[1]= NULL;
- valuearray_add_valuearray(&vs->va, oneval, flags);
+ slapi_valueset_add_attr_valuearray_ext(NULL, vs, oneval, 1, flags, NULL);
}
+
+/* find value v in the sorted array of values, using syntax of attribut a for comparison
+ *
+ */
+static int
+valueset_value_syntax_cmp( const Slapi_Attr *a, const Slapi_Value *v1, const Slapi_Value *v2 )
+{
+ /* this looks like a huge overhead, but there are no simple functions to normalize and
+ * compare available
+ */
+ const Slapi_Value *oneval[3];
+ Slapi_Value **keyvals;
+ int rc;
+
+ keyvals = NULL;
+ oneval[0] = v1;
+ oneval[1] = v2;
+ oneval[2] = NULL;
+ if ( slapi_attr_values2keys_sv( a, (Slapi_Value**)oneval, &keyvals, LDAP_FILTER_EQUALITY ) != 0
+ || keyvals == NULL
+ || keyvals[0] == NULL || keyvals[1] == NULL)
+ {
+ LDAPDebug( LDAP_DEBUG_ANY, "valueset_value_syntax_cmp: "
+ "slapi_attr_values2keys_sv failed for type %s\n",
+ a->a_type, 0, 0 );
+ /* this should never happen since always a default syntax plugin
+ * will be found. Log an error and continue
+ */
+ rc = strcasecmp(v1->bv.bv_val, v2->bv.bv_val);
+ } else {
+ struct berval *bv1, *bv2;
+ bv1 = &keyvals[0]->bv;
+ bv2 = &keyvals[1]->bv;
+ if ( bv1->bv_len < bv2->bv_len ) {
+ rc = -1;
+ } else if ( bv1->bv_len > bv2->bv_len ) {
+ rc = 1;
+ } else {
+ rc = memcmp( bv1->bv_val, bv2->bv_val, bv1->bv_len );
+ }
+ }
+ if (keyvals != NULL)
+ valuearray_free( &keyvals );
+ return (rc);
+
+}
+static int
+valueset_value_cmp( const Slapi_Attr *a, const Slapi_Value *v1, const Slapi_Value *v2 )
+{
+
+ if ( a == NULL || slapi_attr_is_dn_syntax_attr(a)) {
+ /* if no attr is provided just do a utf8compare */
+ /* for all the values the first step of normalization is done,
+ * case folding still needs to be done
+ */
+ /* would this be enough ?: return (strcasecmp(v1->bv.bv_val, v2->bv.bv_val)); */
+ return (slapi_utf8casecmp((unsigned char *)v1->bv.bv_val, (unsigned char *)v2->bv.bv_val));
+ } else {
+ /* slapi_value_compare doesn't work, it only returns 0 or -1
+ return (slapi_value_compare(a, v1, v2));
+ * use special compare, base on what valuetree_find did
+ */
+ return(valueset_value_syntax_cmp(a, v1, v2));
+ }
+}
+/* find a value in the sorted valuearray.
+ * If the value is found the pointer to the value is returned and if index is provided
+ * it will return the index of the value in the valuearray
+ * If the value is not found, index will contain the place where the value would be inserted
+ */
+Slapi_Value *
+valueset_find_sorted (const Slapi_Attr *a, const Slapi_ValueSet *vs, const Slapi_Value *v, int *index)
+{
+ int cmp = -1;
+ int bot = -1;
+ int top;
+
+ if (vs->num == 0) {
+ /* empty valueset */
+ if (index) *index = 0;
+ return (NULL);
+ } else {
+ top = vs->num;
+ }
+ while (top - bot > 1) {
+ int mid = (top + bot)/2;
+ if ( (cmp = valueset_value_cmp(a, v, vs->va[vs->sorted[mid]])) > 0)
+ bot = mid;
+ else
+ top = mid;
+ }
+ if (index) *index = top;
+ /* check if the value is found */
+ if ( top < vs->num && (0 == valueset_value_cmp(a, v, vs->va[vs->sorted[top]])))
+ return (vs->va[vs->sorted[top]]);
+ else
+ return (NULL);
+}
+
+void
+valueset_array_to_sorted (const Slapi_Attr *a, Slapi_ValueSet *vs)
+{
+ int i, j, swap;
+
+ /* initialize sort array */
+ for (i = 0; i < vs->num; i++)
+ vs->sorted[i] = i;
+
+ /* now sort it, use a simple insertion sort as the array will always
+ * be very small when initially sorted
+ */
+ for (i = 1; i < vs->num; i++) {
+ swap = vs->sorted[i];
+ j = i -1;
+
+ while ( j >= 0 && valueset_value_cmp (a, vs->va[vs->sorted[j]], vs->va[swap]) > 0 ) {
+ vs->sorted[j+1] = vs->sorted[j];
+ j--;
+ }
+ vs->sorted[j+1] = swap;
+ }
+}
+/* insert a value into a sorted array, if dupcheck is set no duplicate values will be accepted
+ * (is there a reason to allow duplicates ? LK
+ * if the value is inserted the the function returns the index where it was inserted
+ * if the value already exists -index is returned to indicate anerror an the index of the existing value
+ */
+int
+valueset_insert_value_to_sorted(const Slapi_Attr *a, Slapi_ValueSet *vs, Slapi_Value *vi, int dupcheck)
+{
+ int index = -1;
+ Slapi_Value *v;
+ /* test for pre sorted array and to avoid boundary condition */
+ if (vs->num == 0) {
+ vs->sorted[0] = 0;
+ vs->num++;
+ return(0);
+ } else if (valueset_value_cmp (a, vi, vs->va[vs->sorted[vs->num-1]]) > 0 ) {
+ vs->sorted[vs->num] = vs->num;
+ vs->num++;
+ return (vs->num);
+ }
+ v = valueset_find_sorted (a, vs, vi, &index);
+ if (v && dupcheck) {
+ /* value already exists, do not insert duplicates */
+ return (-1);
+ } else {
+ memmove(&vs->sorted[index+1],&vs->sorted[index],(vs->num - index)* sizeof(int));
+ vs->sorted[index] = vs->num;
+ vs->num++;
+ return(index);
+ }
+
+}
+
+int
+slapi_valueset_add_attr_valuearray_ext(const Slapi_Attr *a, Slapi_ValueSet *vs,
+ Slapi_Value **addvals, int naddvals, unsigned long flags, int *dup_index)
+{
+ int rc = LDAP_SUCCESS;
+ int i, dup;
+ int allocate = 0;
+ int need;
+ int passin = flags & SLAPI_VALUE_FLAG_PASSIN;
+ int dupcheck = flags & SLAPI_VALUE_FLAG_DUPCHECK;
+
+ if (naddvals == 0)
+ return (rc);
+
+ need = vs->num + naddvals + 1;
+ if (need > vs->max) {
+ /* Expand the array */
+ allocate= vs->max;
+ if ( allocate == 0 ) /* initial allocation */
+ allocate = VALUESET_ARRAY_MINSIZE;
+ while ( allocate < need )
+ {
+ if (allocate > VALUESET_ARRAY_MAXINCREMENT )
+ /* do not grow exponentially */
+ allocate += VALUESET_ARRAY_MAXINCREMENT;
+ else
+ allocate *= 2;
+
+ }
+ }
+ if(allocate>0)
+ {
+ if(vs->va==NULL)
+ {
+ vs->va = (Slapi_Value **) slapi_ch_malloc( allocate * sizeof(Slapi_Value *));
+ }
+ else
+ {
+ vs->va = (Slapi_Value **) slapi_ch_realloc( (char *) vs->va, allocate * sizeof(Slapi_Value *));
+ if (vs->sorted) {
+ vs->sorted = (int *) slapi_ch_realloc( (char *) vs->sorted, allocate * sizeof(int));
+ }
+ }
+ vs->max= allocate;
+ }
+
+ if ( (vs->num + naddvals > VALUESET_ARRAY_SORT_THRESHOLD || dupcheck ) &&
+ !vs->sorted ) {
+ /* initialize sort array and do initial sort */
+ vs->sorted = (int *) slapi_ch_malloc( vs->max* sizeof(int));
+ valueset_array_to_sorted (a, vs);
+ }
+
+ for ( i = 0; i < naddvals; i++)
+ {
+ if ( addvals[i]!=NULL )
+ {
+ if(passin)
+ {
+ /* We consume the values */
+ (vs->va)[vs->num] = addvals[i];
+ }
+ else
+ {
+ /* We copy the values */
+ (vs->va)[vs->num] = slapi_value_dup(addvals[i]);
+ }
+ if (vs->sorted) {
+ dup = valueset_insert_value_to_sorted(a, vs, (vs->va)[vs->num], dupcheck);
+ if (dup < 0 ) {
+ rc = LDAP_TYPE_OR_VALUE_EXISTS;
+ if (dup_index) *dup_index = i;
+ if ( !passin)
+ slapi_value_free(&(vs->va)[vs->num]);
+ break;
+ }
+ } else {
+ vs->num++;
+ }
+ }
+ }
+ (vs->va)[vs->num] = NULL;
+
+ return (rc);
+}
+
+int
+slapi_valueset_add_attr_value_ext(const Slapi_Attr *a, Slapi_ValueSet *vs, Slapi_Value *addval, unsigned long flags)
+{
+
+ Slapi_Value *oneval[2];
+ int rc;
+ oneval[0]= (Slapi_Value*)addval;
+ oneval[1]= NULL;
+ rc = slapi_valueset_add_attr_valuearray_ext(a, vs, oneval, 1, flags, NULL );
+ return (rc);
+}
+
+
/*
* The string is passed in by value.
*/
void
-valueset_add_string(Slapi_ValueSet *vs, const char *s, CSNType t, const CSN *csn)
+valueset_add_string(const Slapi_Attr *a, Slapi_ValueSet *vs, const char *s, CSNType t, const CSN *csn)
{
Slapi_Value v;
value_init(&v,NULL,t,csn);
slapi_value_set_string(&v,s);
- valuearray_add_value(&vs->va,&v);
+ slapi_valueset_add_attr_value_ext(a, vs, &v, 0 );
value_done(&v);
}
@@ -1071,8 +1154,30 @@ valueset_add_string(Slapi_ValueSet *vs, const char *s, CSNType t, const CSN *csn
void
valueset_add_valueset(Slapi_ValueSet *vs1, const Slapi_ValueSet *vs2)
{
- if (vs1 && vs2)
- valueset_add_valuearray(vs1, vs2->va);
+ int i;
+
+ if (vs1 && vs2) {
+ if (vs2->va) {
+ /* need to copy valuearray */
+ if (vs2->max == 0) {
+ /* temporary hack, not all valuesets were created properly. fix it now */
+ vs1->num = valuearray_count(vs2->va);
+ vs1->max = vs1->num + 1;
+ } else {
+ vs1->num = vs2->num;
+ vs1->max = vs2->max;
+ }
+ vs1->va = (Slapi_Value **) slapi_ch_malloc( vs1->max * sizeof(Slapi_Value *));
+ for (i=0; i< vs1->num;i++) {
+ vs1->va[i] = slapi_value_dup(vs2->va[i]);
+ }
+ vs1->va[vs1->num] = NULL;
+ }
+ if (vs2->sorted) {
+ vs1->sorted = (int *) slapi_ch_malloc( vs1->max* sizeof(int));
+ memcpy(&vs1->sorted[0],&vs2->sorted[0],vs1->num* sizeof(int));
+ }
+ }
}
void
@@ -1082,7 +1187,7 @@ valueset_remove_string(const Slapi_Attr *a, Slapi_ValueSet *vs, const char *s)
Slapi_Value *removed;
value_init(&v,NULL,CSN_TYPE_NONE,NULL);
slapi_value_set_string(&v,s);
- removed = valuearray_remove_value(a, vs->va, &v);
+ removed = valueset_remove_value(a, vs, &v);
if(removed) {
slapi_value_free(&removed);
}
@@ -1121,121 +1226,23 @@ int
valueset_remove_valuearray(Slapi_ValueSet *vs, const Slapi_Attr *a, Slapi_Value **valuestodelete, int flags, Slapi_Value ***va_out)
{
int rc= LDAP_SUCCESS;
- if(!valuearray_isempty(vs->va))
+ if(vs->num > 0)
{
- int numberofvaluestodelete= valuearray_count(valuestodelete);
+ int i;
struct valuearrayfast vaf_out;
+
if ( va_out )
{
valuearrayfast_init(&vaf_out,*va_out);
}
/*
- * If there are more then one values, build an AVL tree to check
- * the duplicated values.
+ * For larger valuesets the valuarray is sorted, values can be deleted individually
+ *
*/
- if ( numberofvaluestodelete > 1 )
- {
- /*
- * Several values to delete: first build an AVL tree that
- * holds all of the existing values and use that to find
- * the values we want to delete.
- */
- Avlnode *vtree = NULL;
- int numberofexistingvalues= slapi_valueset_count(vs);
- rc= valuetree_add_valuearray( a, vs->va, &vtree, NULL );
- if ( rc!=LDAP_SUCCESS )
- {
- /*
- * failed while constructing AVL tree of existing
- * values... something bad happened.
- */
- rc= LDAP_OPERATIONS_ERROR;
- }
- else
- {
- int i;
- /*
- * find and mark all the values that are to be deleted
- */
- for ( i = 0; rc == LDAP_SUCCESS && valuestodelete[i] != NULL; ++i )
- {
- int index= 0;
- rc = valuetree_find( a, valuestodelete[i], vtree, &index );
- if(rc==LDAP_SUCCESS)
- {
- if(vs->va[index]!=NULL)
- {
- /* Move the value to be removed to the out array */
- if ( va_out )
- {
- if (vs->va[index]->v_csnset &&
- (flags & (SLAPI_VALUE_FLAG_PRESERVECSNSET|
- SLAPI_VALUE_FLAG_USENEWVALUE)))
- {
- valuestodelete[i]->v_csnset = csnset_dup (vs->va[index]->v_csnset);
- }
- if (flags & SLAPI_VALUE_FLAG_USENEWVALUE)
- {
- valuearrayfast_add_value_passin(&vaf_out,valuestodelete[i]);
- valuestodelete[i] = vs->va[index];
- vs->va[index] = NULL;
- }
- else
- {
- valuearrayfast_add_value_passin(&vaf_out,vs->va[index]);
- vs->va[index] = NULL;
- }
- }
- else
- {
- if (flags & SLAPI_VALUE_FLAG_PRESERVECSNSET)
- {
- valuestodelete[i]->v_csnset = vs->va[index]->v_csnset;
- vs->va[index]->v_csnset = NULL;
- }
- slapi_value_free ( & vs->va[index] );
- }
- }
- else
- {
- /* We already deleted this value... */
- if((flags & SLAPI_VALUE_FLAG_IGNOREERROR) == 0)
- {
- /* ...that's an error. */
- rc= LDAP_NO_SUCH_ATTRIBUTE;
- }
- }
- }
- else
- {
- /* Couldn't find the value to be deleted */
- if(rc==LDAP_NO_SUCH_ATTRIBUTE && (flags & SLAPI_VALUE_FLAG_IGNOREERROR ))
- {
- rc= LDAP_SUCCESS;
- }
- }
- }
- valuetree_free( &vtree );
-
- if ( rc != LDAP_SUCCESS )
- {
- LDAPDebug( LDAP_DEBUG_ANY,"could not find value %d for attr %s (%s)\n", i-1, a->a_type, ldap_err2string( rc ));
- }
- else
- {
- /* Shunt up all the remaining values to cover the deleted ones. */
- valuearray_compress(vs->va,numberofexistingvalues);
- }
- }
- }
- else
- {
- /* We delete one or no value, so we use brute force. */
- int i;
for ( i = 0; rc==LDAP_SUCCESS && valuestodelete[i] != NULL; ++i )
{
- Slapi_Value *found= valueset_remove_value(a, vs, valuestodelete[i]);
+ Slapi_Value *found = valueset_remove_value(a, vs, valuestodelete[i]);
if(found!=NULL)
{
if ( va_out )
@@ -1275,7 +1282,6 @@ valueset_remove_valuearray(Slapi_ValueSet *vs, const Slapi_Attr *a, Slapi_Value
}
}
}
- }
if ( va_out )
{
*va_out= vaf_out.va;
@@ -1288,88 +1294,13 @@ valueset_remove_valuearray(Slapi_ValueSet *vs, const Slapi_Attr *a, Slapi_Value
return rc;
}
-/*
- * Check if the set of values in the valueset and the valuearray intersect.
- *
- * Returns
- * LDAP_SUCCESS - No intersection.
- * LDAP_NO_SUCH_ATTRIBUTE - There is an intersection.
- * LDAP_OPERATIONS_ERROR - There are duplicate values in the value set already.
- */
-int
-valueset_intersectswith_valuearray(Slapi_ValueSet *vs, const Slapi_Attr *a, Slapi_Value **values, int *duplicate_index )
-{
- int rc= LDAP_SUCCESS;
-
- if ( duplicate_index ) {
- *duplicate_index = -1;
- }
-
- if(valuearray_isempty(vs->va))
- {
- /* No intersection */
- }
- else
- {
- int numberofvalues= valuearray_count(values);
- /*
- * determine whether we should use an AVL tree of values or not
- */
- if (numberofvalues==0)
- {
- /* No intersection */
- }
- else if ( numberofvalues > 1 )
- {
- /*
- * Several values to add: use an AVL tree to detect duplicates.
- */
- Avlnode *vtree = NULL;
- rc= valuetree_add_valuearray( a, vs->va, &vtree, duplicate_index );
- if(rc==LDAP_OPERATIONS_ERROR)
- {
- /* There were already duplicate values in the value set */
- }
- else
- {
- rc= valuetree_add_valuearray( a, values, &vtree, duplicate_index );
- /*
- * Returns LDAP_OPERATIONS_ERROR if something very bad happens.
- * Or LDAP_TYPE_OR_VALUE_EXISTS if a value already exists.
- */
- }
- valuetree_free( &vtree );
- }
- else
- {
- /*
- * One value to add: don't bother constructing
- * an AVL tree, etc. since it probably isn't worth the time.
- *
- * JCM - This is actually quite slow because the comparison function is looked up many times.
- */
- int i;
- for ( i = 0; rc == LDAP_SUCCESS && values[i] != NULL; ++i )
- {
- if(valuearray_find(a, vs->va, values[i])!=-1)
- {
- rc = LDAP_TYPE_OR_VALUE_EXISTS;
- *duplicate_index = i;
- break;
- }
- }
- }
- }
- return rc;
-}
-
Slapi_ValueSet *
valueset_dup(const Slapi_ValueSet *dupee)
{
- Slapi_ValueSet *duped= (Slapi_ValueSet *)slapi_ch_calloc(1,sizeof(Slapi_ValueSet));
+ Slapi_ValueSet *duped = slapi_valueset_new();
if (NULL!=duped)
{
- valueset_add_valuearray( duped, dupee->va );
+ valueset_set_valuearray_byval(duped,dupee->va);
}
return duped;
}
@@ -1381,43 +1312,53 @@ valueset_dup(const Slapi_ValueSet *dupee)
* : LDAP_OPERATIONS_ERROR - duplicated values given
*/
int
-valueset_replace(Slapi_Attr *a, Slapi_ValueSet *vs, Slapi_Value **valstoreplace)
+valueset_replace_valuearray(Slapi_Attr *a, Slapi_ValueSet *vs, Slapi_Value **valstoreplace)
+{
+ return (valueset_replace_valuearray_ext(a, vs,valstoreplace, 1));
+}
+int
+valueset_replace_valuearray_ext(Slapi_Attr *a, Slapi_ValueSet *vs, Slapi_Value **valstoreplace, int dupcheck)
{
int rc = LDAP_SUCCESS;
- int numberofvalstoreplace= valuearray_count(valstoreplace);
- /* verify the given values are not duplicated.
- if replacing with one value, no need to check. just replace it.
- */
- if (numberofvalstoreplace > 1)
- {
- Avlnode *vtree = NULL;
- rc = valuetree_add_valuearray( a, valstoreplace, &vtree, NULL );
- valuetree_free(&vtree);
- if ( LDAP_SUCCESS != rc &&
- /* bz 247413: don't override LDAP_TYPE_OR_VALUE_EXISTS */
- LDAP_TYPE_OR_VALUE_EXISTS != rc )
- {
- /* There were already duplicate values in the value set */
- rc = LDAP_OPERATIONS_ERROR;
- }
- }
-
- if ( rc == LDAP_SUCCESS )
- {
- /* values look good - replace the values in the attribute */
- if(!valuearray_isempty(vs->va))
- {
- /* remove old values */
- slapi_valueset_done(vs);
- }
- /* we now own valstoreplace */
- vs->va = valstoreplace;
- }
- else
- {
- /* caller expects us to own valstoreplace - since we cannot
- use them, just delete them */
- valuearray_free(&valstoreplace);
+ int vals_count = valuearray_count(valstoreplace);
+
+ if (vals_count == 0) {
+ /* no new values, just clear the valueset */
+ slapi_valueset_done(vs);
+ } else if (vals_count == 1 || !dupcheck) {
+ /* just repelace the valuearray and adjus num, max */
+ slapi_valueset_done(vs);
+ vs->va = valstoreplace;
+ vs->num = vals_count;
+ vs->max = vals_count + 1;
+ } else {
+ /* verify the given values are not duplicated. */
+ Slapi_ValueSet *vs_new = slapi_valueset_new();
+ rc = slapi_valueset_add_attr_valuearray_ext (a, vs_new, valstoreplace, vals_count, 0, NULL);
+
+ if ( rc == LDAP_SUCCESS )
+ {
+ /* values look good - replace the values in the attribute */
+ if(!valuearray_isempty(vs->va))
+ {
+ /* remove old values */
+ slapi_valueset_done(vs);
+ }
+ vs->va = vs_new->va;
+ vs_new->va = NULL;
+ vs->sorted = vs_new->sorted;
+ vs_new->sorted = NULL;
+ vs->num = vs_new->num;
+ vs->max = vs_new->max;
+ slapi_valueset_free (vs_new);
+ }
+ else
+ {
+ /* caller expects us to own valstoreplace - since we cannot
+ use them, just delete them */
+ slapi_valueset_free(vs_new);
+ valuearray_free(&valstoreplace);
+ }
}
return rc;
}
@@ -1434,46 +1375,33 @@ valueset_update_csn_for_valuearray(Slapi_ValueSet *vs, const Slapi_Attr *a, Slap
if(!valuearray_isempty(valuestoupdate) &&
!valuearray_isempty(vs->va))
{
- /*
- * determine whether we should use an AVL tree of values or not
- */
struct valuearrayfast vaf_valuesupdated;
- int numberofvaluestoupdate= valuearray_count(valuestoupdate);
valuearrayfast_init(&vaf_valuesupdated,*valuesupdated);
- if (numberofvaluestoupdate > 1) /* multiple values to update */
+ int i;
+ int del_index = -1, del_count = 0;
+ for (i=0;valuestoupdate[i]!=NULL;++i)
{
- int i;
- Avlnode *vtree = NULL;
- int rc= valuetree_add_valuearray( a, vs->va, &vtree, NULL );
- PR_ASSERT(rc==LDAP_SUCCESS);
- for (i=0;valuestoupdate[i]!=NULL;++i)
+ int index= valuearray_find(a, vs->va, valuestoupdate[i]);
+ if(index!=-1)
{
- int index= 0;
- rc = valuetree_find( a, valuestoupdate[i], vtree, &index );
- if(rc==LDAP_SUCCESS)
- {
- value_update_csn(vs->va[index],t,csn);
- valuearrayfast_add_value_passin(&vaf_valuesupdated,valuestoupdate[i]);
- valuestoupdate[i] = NULL;
- }
+ value_update_csn(vs->va[index],t,csn);
+ valuearrayfast_add_value_passin(&vaf_valuesupdated,valuestoupdate[i]);
+ valuestoupdate[i]= NULL;
+ del_count++;
+ if (del_index < 0) del_index = i;
}
- valuetree_free(&vtree);
- }
- else
- {
- int i;
- for (i=0;valuestoupdate[i]!=NULL;++i)
- {
- int index= valuearray_find(a, vs->va, valuestoupdate[i]);
- if(index!=-1)
- {
- value_update_csn(vs->va[index],t,csn);
- valuearrayfast_add_value_passin(&vaf_valuesupdated,valuestoupdate[i]);
- valuestoupdate[i]= NULL;
+ else
+ { /* keep the value in valuestoupdate, to keep array compressed, move to first free slot*/
+ if (del_index >= 0) {
+ valuestoupdate[del_index] = valuestoupdate[i];
+ del_index++;
}
}
}
- valuearray_compress(valuestoupdate,numberofvaluestoupdate);
+ /* complete compression */
+ for (i=0; i<del_count;i++)
+ valuestoupdate[del_index+i]= NULL;
+
*valuesupdated= vaf_valuesupdated.va;
}
}
@@ -1490,4 +1418,3 @@ valuearray_dn_normalize_value(Slapi_Value **vals)
return rc;
}
-
10 years, 9 months
ldap/servers
by Ludwig Krispenz
ldap/servers/slapd/entry.c | 23 +----------------------
ldap/servers/slapd/slapi-plugin.h | 2 +-
ldap/servers/slapd/valueset.c | 6 +++---
3 files changed, 5 insertions(+), 26 deletions(-)
New commits:
commit 708df4b77abaf8260f717f3d8e3a0bd6b47bd36c
Author: Ludwig Krispenz <lkrispen(a)redhat.com>
Date: Thu Jul 18 15:32:05 2013 +0200
fix compiler warnings
diff --git a/ldap/servers/slapd/entry.c b/ldap/servers/slapd/entry.c
index ee7c18f..4006d53 100644
--- a/ldap/servers/slapd/entry.c
+++ b/ldap/servers/slapd/entry.c
@@ -746,12 +746,11 @@ str2entry_dupcheck( const char *rawdn, char *s, int flags, int read_stateinfo )
char *type;
struct berval bvtype;
str2entry_attr *sa;
- int i, j;
+ int i;
char *next=NULL;
char *valuecharptr=NULL;
struct berval bvvalue;
int rc;
- int fast_dup_check = 0;
entry_attrs *ea = NULL;
int tree_attr_checking = 0;
int big_entry_attr_presence_check = 0;
@@ -991,7 +990,6 @@ str2entry_dupcheck( const char *rawdn, char *s, int flags, int read_stateinfo )
if ( prev_attr==NULL )
{
/* Haven't seen this type yet */
- fast_dup_check = 1;
if ( nattrs == maxattrs )
{
/* Out of space - reallocate */
@@ -1023,15 +1021,6 @@ str2entry_dupcheck( const char *rawdn, char *s, int flags, int read_stateinfo )
/* Get the comparison function for later use */
attr_get_value_cmp_fn( &attrs[nattrs].sa_attr, &(attrs[nattrs].sa_comparefn));
/*
- * If the compare function wasn't available,
- * we have to revert to AVL-tree-based dup checking,
- * which uses index keys for comparisons
- */
- if (NULL == attrs[nattrs].sa_comparefn)
- {
- fast_dup_check = 0;
- }
- /*
* If we are maintaining the attribute tree,
* then add the new attribute to the tree.
*/
@@ -1043,16 +1032,6 @@ str2entry_dupcheck( const char *rawdn, char *s, int flags, int read_stateinfo )
prev_attr = &attrs[nattrs];
nattrs++;
} else { /* prev_attr != NULL */
- if ( check_for_duplicate_values ) {
- /*
- * If the compare function wasn't available,
- * we have to revert to AVL-tree-based dup checking,
- * which uses index keys for comparisons
- */
- if (NULL == prev_attr->sa_comparefn) {
- fast_dup_check = 0;
- }
- }
}
sa = prev_attr; /* For readability */
diff --git a/ldap/servers/slapd/slapi-plugin.h b/ldap/servers/slapd/slapi-plugin.h
index d171f99..d548baf 100644
--- a/ldap/servers/slapd/slapi-plugin.h
+++ b/ldap/servers/slapd/slapi-plugin.h
@@ -4752,7 +4752,7 @@ void slapi_valueset_add_value(Slapi_ValueSet *vs, const Slapi_Value *addval);
* \see slapi_valueset_first_value()
* \see slapi_valueset_next_value()
*/
-void slapi_valueset_add_value_ext(Slapi_ValueSet *vs, Slapi_Value *addval, unsigned long flags);
+void slapi_valueset_add_value_ext(Slapi_ValueSet *vs, const Slapi_Value *addval, unsigned long flags);
int slapi_valueset_add_attr_value_ext(const Slapi_Attr *a, Slapi_ValueSet *vs, Slapi_Value *addval, unsigned long flags);
/**
diff --git a/ldap/servers/slapd/valueset.c b/ldap/servers/slapd/valueset.c
index 76d03e1..416a838 100644
--- a/ldap/servers/slapd/valueset.c
+++ b/ldap/servers/slapd/valueset.c
@@ -870,7 +870,7 @@ slapi_valueset_add_value(Slapi_ValueSet *vs, const Slapi_Value *addval)
}
void
-slapi_valueset_add_value_ext(Slapi_ValueSet *vs, Slapi_Value *addval, unsigned long flags)
+slapi_valueset_add_value_ext(Slapi_ValueSet *vs, const Slapi_Value *addval, unsigned long flags)
{
Slapi_Value *oneval[2];
oneval[0]= (Slapi_Value*)addval;
@@ -928,13 +928,13 @@ static int
valueset_value_cmp( const Slapi_Attr *a, const Slapi_Value *v1, const Slapi_Value *v2 )
{
- if ( a == NULL || slapi_attr_is_dn_syntax_attr(a)) {
+ if ( a == NULL || slapi_attr_is_dn_syntax_attr((Slapi_Attr *)a)) {
/* if no attr is provided just do a utf8compare */
/* for all the values the first step of normalization is done,
* case folding still needs to be done
*/
/* would this be enough ?: return (strcasecmp(v1->bv.bv_val, v2->bv.bv_val)); */
- return (slapi_utf8casecmp(v1->bv.bv_val, v2->bv.bv_val));
+ return (slapi_utf8casecmp((unsigned char*)v1->bv.bv_val, (unsigned char*)v2->bv.bv_val));
} else {
/* slapi_value_compare doesn't work, it only returns 0 or -1
return (slapi_value_compare(a, v1, v2));
10 years, 9 months
ldap/servers
by Ludwig Krispenz
ldap/servers/slapd/attr.c | 60 -
ldap/servers/slapd/attrlist.c | 2
ldap/servers/slapd/attrsyntax.c | 6
ldap/servers/slapd/back-ldbm/import-threads.c | 2
ldap/servers/slapd/back-ldbm/index.c | 22
ldap/servers/slapd/back-ldbm/ldbm_attr.c | 6
ldap/servers/slapd/computed.c | 2
ldap/servers/slapd/entry.c | 137 ---
ldap/servers/slapd/entrywsi.c | 13
ldap/servers/slapd/proto-slap.h | 13
ldap/servers/slapd/schema.c | 106 --
ldap/servers/slapd/slap.h | 8
ldap/servers/slapd/slapi-plugin.h | 13
ldap/servers/slapd/slapi-private.h | 5
ldap/servers/slapd/valueset.c | 1084 ++++++++++++--------------
15 files changed, 639 insertions(+), 840 deletions(-)
New commits:
commit 54bbaed10cd72d5e9809c6ef8d15c00bca6a5cdb
Author: Ludwig Krispenz <lkrispen(a)redhat.com>
Date: Wed Jul 17 15:54:50 2013 +0200
Ticket 346 - version 4 Slow ldapmodify operation time
for large quantities of multi-valued attribute values
Bug Description: The reason for the performance degradation is that for
operations like add and delete of values and for updating the index for
each values a check has tobe done if it exists in the current attribute.
if the number of values grows the seaqrch time increases
Fix Description: Keep a secondary array of the indexes of the valuearray which is sorted.
To locate a value, a binary search can be used.
A design doc is available at: http://port389.org/wiki/Static_group_performance
https://fedorahosted.org/389/ticket/346
Reviewed by: RichM
diff --git a/ldap/servers/slapd/attr.c b/ldap/servers/slapd/attr.c
index 03b366c..8ab7135 100644
--- a/ldap/servers/slapd/attr.c
+++ b/ldap/servers/slapd/attr.c
@@ -365,11 +365,9 @@ Slapi_Attr *
slapi_attr_dup(const Slapi_Attr *attr)
{
Slapi_Attr *newattr= slapi_attr_new();
- Slapi_Value **present_va= valueset_get_valuearray(&attr->a_present_values); /* JCM Mucking about inside the value set */
- Slapi_Value **deleted_va= valueset_get_valuearray(&attr->a_deleted_values); /* JCM Mucking about inside the value set */
slapi_attr_init(newattr, attr->a_type);
- valueset_add_valuearray( &newattr->a_present_values, present_va );
- valueset_add_valuearray( &newattr->a_deleted_values, deleted_va );
+ slapi_valueset_set_valueset( &newattr->a_deleted_values, &attr->a_deleted_values );
+ slapi_valueset_set_valueset( &newattr->a_present_values, &attr->a_present_values );
newattr->a_deletioncsn= csn_dup(attr->a_deletioncsn);
return newattr;
}
@@ -835,43 +833,11 @@ attr_add_valuearray(Slapi_Attr *a, Slapi_Value **vals, const char *dn)
}
/*
- * determine whether we should use an AVL tree of values or not
+ * add values and check for duplicate values
*/
- for ( i = 0; vals[i] != NULL; i++ ) ;
- numofvals = i;
-
- /*
- * detect duplicate values
- */
- if ( numofvals > 1 ) {
- /*
- * Several values to add: use an AVL tree to detect duplicates.
- */
- LDAPDebug( LDAP_DEBUG_TRACE,
- "slapi_entry_add_values: using an AVL tree to "
- "detect duplicate values\n", 0, 0, 0 );
-
- if (valueset_isempty(&a->a_present_values)) {
- /* if the attribute contains no values yet, just check the
- * input vals array for duplicates
- */
- Avlnode *vtree = NULL;
- rc= valuetree_add_valuearray(a, vals, &vtree, &duplicate_index);
- valuetree_free(&vtree);
- was_present_null = 1;
- } else {
- /* the attr and vals both contain values, check intersection */
- rc= valueset_intersectswith_valuearray(&a->a_present_values, a, vals, &duplicate_index);
- }
-
- } else if ( !valueset_isempty(&a->a_present_values) ) {
- /*
- * One or no value to add: don't bother constructing
- * an AVL tree, etc. since it probably isn't worth the time.
- */
- for ( i = 0; vals[i] != NULL; ++i ) {
- if ( slapi_attr_value_find( a, slapi_value_get_berval(vals[i]) ) == 0 ) {
- duplicate_index = i;
+ numofvals = valuearray_count(vals);
+ rc = slapi_valueset_add_attr_valuearray_ext (a, &a->a_present_values, vals, numofvals, SLAPI_VALUE_FLAG_DUPCHECK, &duplicate_index);
+ if ( rc != LDAP_SUCCESS) {
#if defined(USE_OLD_UNHASHED)
if (is_type_forbidden(a->a_type)) {
/* If the attr is in the forbidden list
@@ -884,22 +850,12 @@ attr_add_valuearray(Slapi_Attr *a, Slapi_Value **vals, const char *dn)
#else
rc = LDAP_TYPE_OR_VALUE_EXISTS;
#endif
- break;
}
- }
- }
-
- /*
- * add values if no duplicates detected
- */
- if(rc==LDAP_SUCCESS) {
- valueset_add_valuearray( &a->a_present_values, vals );
- }
/* In the case of duplicate value, rc == LDAP_TYPE_OR_VALUE_EXISTS or
* LDAP_OPERATIONS_ERROR
*/
- else if ( duplicate_index >= 0 ) {
+ if ( duplicate_index >= 0 ) {
char bvvalcopy[BUFSIZ];
char *duplicate_string = "null or non-ASCII";
@@ -940,7 +896,7 @@ attr_add_valuearray(Slapi_Attr *a, Slapi_Value **vals, const char *dn)
*/
int attr_replace(Slapi_Attr *a, Slapi_Value **vals)
{
- return valueset_replace(a, &a->a_present_values, vals);
+ return valueset_replace_valuearray(a, &a->a_present_values, vals);
}
int
diff --git a/ldap/servers/slapd/attrlist.c b/ldap/servers/slapd/attrlist.c
index 1f52bb8..8825e2b 100644
--- a/ldap/servers/slapd/attrlist.c
+++ b/ldap/servers/slapd/attrlist.c
@@ -129,7 +129,7 @@ attrlist_merge_valuearray(Slapi_Attr **alist, const char *type, Slapi_Value **va
Slapi_Attr **a= NULL;
if (!vals) return;
attrlist_find_or_create(alist, type, &a);
- valueset_add_valuearray( &(*a)->a_present_values, vals );
+ slapi_valueset_add_valuearray( *a, &(*a)->a_present_values, vals );
}
diff --git a/ldap/servers/slapd/attrsyntax.c b/ldap/servers/slapd/attrsyntax.c
index 7ce4264..7abd6b7 100644
--- a/ldap/servers/slapd/attrsyntax.c
+++ b/ldap/servers/slapd/attrsyntax.c
@@ -1047,6 +1047,10 @@ slapi_attr_is_dn_syntax_attr(Slapi_Attr *attr)
const char *syntaxoid = NULL;
int dn_syntax = 0; /* not DN, by default */
+ if (attr && attr->a_flags & SLAPI_ATTR_FLAG_SYNTAX_IS_DN)
+ /* it was checked before */
+ return(1);
+
if (attr && attr->a_plugin == NULL) {
slapi_attr_init_syntax (attr);
}
@@ -1055,6 +1059,8 @@ slapi_attr_is_dn_syntax_attr(Slapi_Attr *attr)
dn_syntax = ((0 == strcmp(syntaxoid, NAMEANDOPTIONALUID_SYNTAX_OID))
|| (0 == strcmp(syntaxoid, DN_SYNTAX_OID)));
}
+ if (dn_syntax)
+ attr->a_flags |= SLAPI_ATTR_FLAG_SYNTAX_IS_DN;
}
return dn_syntax;
}
diff --git a/ldap/servers/slapd/back-ldbm/import-threads.c b/ldap/servers/slapd/back-ldbm/import-threads.c
index 5cb5663..3a2904e 100644
--- a/ldap/servers/slapd/back-ldbm/import-threads.c
+++ b/ldap/servers/slapd/back-ldbm/import-threads.c
@@ -2639,7 +2639,7 @@ import_foreman(void *param)
/* Setting new entrydn attribute value */
slapi_attr_init(new_entrydn, "entrydn");
- valueset_add_string(&new_entrydn->a_present_values,
+ valueset_add_string(new_entrydn, &new_entrydn->a_present_values,
/* new_dn: duped in valueset_add_string */
(const char *)new_dn,
CSN_TYPE_UNKNOWN, NULL);
diff --git a/ldap/servers/slapd/back-ldbm/index.c b/ldap/servers/slapd/back-ldbm/index.c
index c502017..4b2b13a 100644
--- a/ldap/servers/slapd/back-ldbm/index.c
+++ b/ldap/servers/slapd/back-ldbm/index.c
@@ -545,7 +545,7 @@ index_add_mods(
for (curr_attr = newe->ep_entry->e_attrs; curr_attr != NULL; curr_attr = curr_attr->a_next) {
if (slapi_attr_type_cmp( basetype, curr_attr->a_type, SLAPI_TYPE_CMP_BASE ) == 0) {
- valueset_add_valuearray(all_vals, attr_get_present_values(curr_attr));
+ slapi_valueset_join_attr_valueset(curr_attr, all_vals, &curr_attr->a_present_values);
}
}
@@ -566,7 +566,7 @@ index_add_mods(
for (curr_attr = olde->ep_entry->e_attrs; curr_attr != NULL; curr_attr = curr_attr->a_next) {
if (slapi_attr_type_cmp( mods[i]->mod_type, curr_attr->a_type, SLAPI_TYPE_CMP_EXACT ) == 0) {
- valueset_add_valuearray(mod_vals, attr_get_present_values(curr_attr));
+ slapi_valueset_join_attr_valueset(curr_attr, mod_vals, &curr_attr->a_present_values);
}
}
@@ -584,7 +584,7 @@ index_add_mods(
slapi_entry_attr_find( olde->ep_entry, mods[i]->mod_type, &curr_attr );
if ( mods_valueArray != NULL ) {
for ( j = 0; mods_valueArray[j] != NULL; j++ ) {
- Slapi_Value *rval = valuearray_remove_value(curr_attr, evals, mods_valueArray[j]);
+ Slapi_Value *rval = valueset_remove_value(curr_attr, all_vals, mods_valueArray[j]);
slapi_value_free( &rval );
}
}
@@ -593,12 +593,12 @@ index_add_mods(
* they don't exist, delete the equality index.
*/
for ( j = 0; deleted_valueArray[j] != NULL; j++ ) {
- if (valuearray_find(curr_attr, evals, deleted_valueArray[j]) == -1) {
+ if ( !slapi_valueset_find(curr_attr, all_vals, deleted_valueArray[j])) {
if (!(flags & BE_INDEX_EQUALITY)) {
flags |= BE_INDEX_EQUALITY;
}
} else {
- Slapi_Value *rval = valuearray_remove_value(curr_attr, deleted_valueArray, deleted_valueArray[j]);
+ Slapi_Value *rval = valueset_remove_value(curr_attr, mod_vals, deleted_valueArray[j]);
slapi_value_free( &rval );
j--;
/* indicates there was some conflict */
@@ -637,8 +637,8 @@ index_add_mods(
if (curr_attr) { /* found the type */
for (j = 0; mods_valueArray[j] != NULL; j++) {
/* mods_valueArray[j] is in curr_attr ==> return 0 */
- if (slapi_attr_value_find(curr_attr,
- slapi_value_get_berval(mods_valueArray[j]))) {
+ if ( !slapi_valueset_find(curr_attr, &curr_attr->a_present_values,
+ mods_valueArray[j])) {
/* The value is NOT in newe, remove it. */
Slapi_Value *rval;
rval = valuearray_remove_value(curr_attr,
@@ -677,7 +677,7 @@ index_add_mods(
for (curr_attr = olde->ep_entry->e_attrs; curr_attr != NULL; curr_attr = curr_attr->a_next) {
if (slapi_attr_type_cmp( mods[i]->mod_type, curr_attr->a_type, SLAPI_TYPE_CMP_EXACT ) == 0) {
- valueset_add_valuearray(mod_vals, attr_get_present_values(curr_attr));
+ slapi_valueset_join_attr_valueset(curr_attr, mod_vals, &curr_attr->a_present_values);
}
}
@@ -694,14 +694,14 @@ index_add_mods(
* also exist in a subtype.
*/
for (j = 0; deleted_valueArray && deleted_valueArray[j]; j++) {
- if ( valuearray_find(curr_attr, evals, deleted_valueArray[j]) == -1 ) {
+ if ( !slapi_valueset_find(curr_attr, all_vals, deleted_valueArray[j])) {
/* If the equality flag isn't already set, set it */
if (!(flags & BE_INDEX_EQUALITY)) {
flags |= BE_INDEX_EQUALITY;
}
} else {
/* Remove duplicate value from the mod list */
- Slapi_Value *rval = valuearray_remove_value(curr_attr, deleted_valueArray, deleted_valueArray[j]);
+ Slapi_Value *rval = valueset_remove_value(curr_attr, mod_vals, deleted_valueArray[j]);
slapi_value_free( &rval );
j--;
}
@@ -750,7 +750,7 @@ index_add_mods(
if (curr_attr) {
int found = 0;
for (j = 0; mods_valueArray[j] != NULL; j++ ) {
- if ( valuearray_find(curr_attr, evals, mods_valueArray[j]) > -1 ) {
+ if ( slapi_valueset_find(curr_attr, all_vals, mods_valueArray[j])) {
/* The same value found in evals.
* We don't touch the equality index. */
found = 1;
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_attr.c b/ldap/servers/slapd/back-ldbm/ldbm_attr.c
index 09f1a48..c13fd6d 100644
--- a/ldap/servers/slapd/back-ldbm/ldbm_attr.c
+++ b/ldap/servers/slapd/back-ldbm/ldbm_attr.c
@@ -437,7 +437,7 @@ ldbm_compute_evaluator(computed_attr_context *c,char* type,Slapi_Entry *e,slapi_
Slapi_Attr our_attr;
slapi_attr_init(&our_attr, numsubordinates);
our_attr.a_flags = SLAPI_ATTR_FLAG_OPATTR;
- valueset_add_string(&our_attr.a_present_values,"0",CSN_TYPE_UNKNOWN,NULL);
+ valueset_add_string(&our_attr, &our_attr.a_present_values,"0",CSN_TYPE_UNKNOWN,NULL);
rc = (*outputfn) (c, &our_attr, e);
attr_done(&our_attr);
return (rc);
@@ -454,9 +454,9 @@ ldbm_compute_evaluator(computed_attr_context *c,char* type,Slapi_Entry *e,slapi_
rc = slapi_entry_attr_find( e, numsubordinates, &read_attr );
if ( (0 != rc) || slapi_entry_attr_hasvalue(e,numsubordinates,"0") ) {
/* If not, or present and zero, we return FALSE, otherwise TRUE */
- valueset_add_string(&our_attr.a_present_values,"FALSE",CSN_TYPE_UNKNOWN,NULL);
+ valueset_add_string(&our_attr, &our_attr.a_present_values,"FALSE",CSN_TYPE_UNKNOWN,NULL);
} else {
- valueset_add_string(&our_attr.a_present_values,"TRUE",CSN_TYPE_UNKNOWN,NULL);
+ valueset_add_string(&our_attr, &our_attr.a_present_values,"TRUE",CSN_TYPE_UNKNOWN,NULL);
}
rc = (*outputfn) (c, &our_attr, e);
attr_done(&our_attr);
diff --git a/ldap/servers/slapd/computed.c b/ldap/servers/slapd/computed.c
index 8259dea..7c99b45 100644
--- a/ldap/servers/slapd/computed.c
+++ b/ldap/servers/slapd/computed.c
@@ -148,7 +148,7 @@ compute_stock_evaluator(computed_attr_context *c,char* type,Slapi_Entry *e,slapi
Slapi_Attr our_attr;
slapi_attr_init(&our_attr, subschemasubentry);
our_attr.a_flags = SLAPI_ATTR_FLAG_OPATTR;
- valueset_add_string(&our_attr.a_present_values,SLAPD_SCHEMA_DN,CSN_TYPE_UNKNOWN,NULL);
+ valueset_add_string(&our_attr, &our_attr.a_present_values,SLAPD_SCHEMA_DN,CSN_TYPE_UNKNOWN,NULL);
rc = (*outputfn) (c, &our_attr, e);
attr_done(&our_attr);
return (rc);
diff --git a/ldap/servers/slapd/entry.c b/ldap/servers/slapd/entry.c
index f730ae0..ee7c18f 100644
--- a/ldap/servers/slapd/entry.c
+++ b/ldap/servers/slapd/entry.c
@@ -237,8 +237,6 @@ str2entry_fast( const char *rawdn, const Slapi_RDN *srdn, char *s, int flags, in
int freeval = 0;
int value_state= VALUE_NOTFOUND;
int attr_state= ATTRIBUTE_NOTFOUND;
- int maxvals;
- int del_maxvals;
if ( *s == '\n' || *s == '\0' ) {
break;
@@ -280,9 +278,7 @@ str2entry_fast( const char *rawdn, const Slapi_RDN *srdn, char *s, int flags, in
slapi_ch_free_string(&ptype);
ptype=PL_strndup(type.bv_val, type.bv_len);
nvals = 0;
- maxvals = 0;
del_nvals = 0;
- del_maxvals = 0;
a = NULL;
}
@@ -503,25 +499,21 @@ str2entry_fast( const char *rawdn, const Slapi_RDN *srdn, char *s, int flags, in
if(value_state==VALUE_DELETED)
{
/* consumes the value */
- valuearray_add_value_fast(
- &(*a)->a_deleted_values.va, /* JCM .va is private */
- svalue,
- del_nvals,
- &del_maxvals,
- 0/*!Exact*/,
- 1/*Passin*/ );
+ slapi_valueset_add_attr_value_ext(
+ *a,
+ &(*a)->a_deleted_values,
+ svalue,
+ SLAPI_VALUE_FLAG_PASSIN );
del_nvals++;
}
else
{
/* consumes the value */
- valuearray_add_value_fast(
- &(*a)->a_present_values.va, /* JCM .va is private */
- svalue,
- nvals,
- &maxvals,
- 0 /*!Exact*/,
- 1 /*Passin*/ );
+ slapi_valueset_add_attr_value_ext(
+ *a,
+ &(*a)->a_present_values,
+ svalue,
+ SLAPI_VALUE_FLAG_PASSIN);
nvals++;
}
if(attributedeletioncsn!=NULL)
@@ -603,8 +595,8 @@ typedef struct _entry_attrs {
typedef struct _str2entry_attr {
char *sa_type;
int sa_state;
- struct valuearrayfast sa_present_values;
- struct valuearrayfast sa_deleted_values;
+ struct slapi_value_set sa_present_values;
+ struct slapi_value_set sa_deleted_values;
int sa_numdups;
value_compare_fn_type sa_comparefn;
Avlnode *sa_vtree;
@@ -617,8 +609,8 @@ entry_attr_init(str2entry_attr *sa, const char *type, int state)
{
sa->sa_type= slapi_ch_strdup(type);
sa->sa_state= state;
- valuearrayfast_init(&sa->sa_present_values,NULL);
- valuearrayfast_init(&sa->sa_deleted_values,NULL);
+ slapi_valueset_init(&sa->sa_present_values);
+ slapi_valueset_init(&sa->sa_deleted_values);
sa->sa_numdups= 0;
sa->sa_comparefn = NULL;
sa->sa_vtree= NULL;
@@ -1106,66 +1098,20 @@ str2entry_dupcheck( const char *rawdn, char *s, int flags, int read_stateinfo )
{
/*
* for deleted values, we do not want to perform a dupcheck against
- * existing values. Also, we do not want to add it to the
- * avl tree (if one is being maintained)
- *
+ * existing values.
*/
- rc = 0; /* Presume no duplicate */
+ rc = slapi_valueset_add_attr_value_ext(&sa->sa_attr, &sa->sa_deleted_values,value, SLAPI_VALUE_FLAG_PASSIN);
}
- else if ( !check_for_duplicate_values )
+ else
{
- rc = LDAP_SUCCESS; /* presume no duplicate */
- } else {
- /* For value dup checking, we either use brute-force, if there's a small number */
- /* Or a tree-based approach if there's a large number. */
- /* The tree code is expensive, which is why we don't use it unless there's many attributes */
- rc = 0; /* Presume no duplicate */
- if (fast_dup_check)
- {
- /* Fast dup-checking */
- /* Do we now have so many values that we should switch to tree-based checking ? */
- if (sa->sa_present_values.num > STR2ENTRY_VALUE_DUPCHECK_THRESHOLD)
- {
- /* Make the tree from the existing attr values */
- rc= valuetree_add_valuearray( &sa->sa_attr, sa->sa_present_values.va, &sa->sa_vtree, NULL);
- /* Check if the value already exists, in the tree. */
- rc= valuetree_add_value( &sa->sa_attr, value, &sa->sa_vtree);
- fast_dup_check = 0;
- }
- else
- {
- /* JCM - need an efficient valuearray function to do this */
- /* Brute-force check */
- for ( j = 0; j < sa->sa_present_values.num; j++ )/* JCM innards */
- {
- if (0 == sa->sa_comparefn(slapi_value_get_berval(value),slapi_value_get_berval(sa->sa_present_values.va[j])))/* JCM innards */
- {
- /* Oops---this value matches one already present */
- rc = LDAP_TYPE_OR_VALUE_EXISTS;
- break;
- }
- }
- }
- }
- else
- {
- /* Check if the value already exists, in the tree. */
- rc = valuetree_add_value( &sa->sa_attr, value, &sa->sa_vtree);
- }
+ int flags = SLAPI_VALUE_FLAG_PASSIN;
+ if (check_for_duplicate_values) flags |= SLAPI_VALUE_FLAG_DUPCHECK;
+ rc = slapi_valueset_add_attr_value_ext(&sa->sa_attr, &sa->sa_present_values,value, flags);
}
if ( rc==LDAP_SUCCESS )
{
- if(value_state==VALUE_DELETED)
- {
- valuearrayfast_add_value_passin(&sa->sa_deleted_values,value);
- value= NULL; /* value was consumed */
- }
- else
- {
- valuearrayfast_add_value_passin(&sa->sa_present_values,value);
- value= NULL; /* value was consumed */
- }
+ value= NULL; /* value was consumed */
if(attributedeletioncsn!=NULL)
{
sa->sa_attributedeletioncsn= attributedeletioncsn;
@@ -1180,7 +1126,7 @@ str2entry_dupcheck( const char *rawdn, char *s, int flags, int read_stateinfo )
else
{
/* Failure adding to value tree */
- LDAPDebug( LDAP_DEBUG_ANY, "str2entry_dupcheck: unexpected failure %d constructing value tree\n", rc, 0, 0 );
+ LDAPDebug( LDAP_DEBUG_ANY, "str2entry_dupcheck: unexpected failure %d adding value\n", rc, 0, 0 );
slapi_entry_free( e ); e = NULL;
goto free_and_return;
}
@@ -1245,27 +1191,21 @@ str2entry_dupcheck( const char *rawdn, char *s, int flags, int read_stateinfo )
}
if(alist!=NULL)
{
- int maxvals = 0;
Slapi_Attr **a= NULL;
attrlist_find_or_create_locking_optional(alist, sa->sa_type, &a, PR_FALSE);
- valuearray_add_valuearray_fast( /* JCM should be calling a valueset function */
- &(*a)->a_present_values.va, /* JCM .va is private */
- sa->sa_present_values.va,
- 0, /* Currently there are no present values on the attribute */
- sa->sa_present_values.num,
- &maxvals,
- 1/*Exact*/,
- 1/*Passin*/);
+ slapi_valueset_add_attr_valuearray_ext(
+ *a,
+ &(*a)->a_present_values,
+ sa->sa_present_values.va,
+ sa->sa_present_values.num,
+ SLAPI_VALUE_FLAG_PASSIN, NULL);
sa->sa_present_values.num= 0; /* The values have been consumed */
- maxvals = 0;
- valuearray_add_valuearray_fast( /* JCM should be calling a valueset function */
- &(*a)->a_deleted_values.va, /* JCM .va is private */
- sa->sa_deleted_values.va,
- 0, /* Currently there are no deleted values on the attribute */
- sa->sa_deleted_values.num,
- &maxvals,
- 1/*Exact*/,
- 1/*Passin*/);
+ slapi_valueset_add_attr_valuearray_ext(
+ *a,
+ &(*a)->a_deleted_values,
+ sa->sa_deleted_values.va,
+ sa->sa_deleted_values.num,
+ SLAPI_VALUE_FLAG_PASSIN, NULL);
sa->sa_deleted_values.num= 0; /* The values have been consumed */
if(sa->sa_attributedeletioncsn!=NULL)
{
@@ -1312,9 +1252,8 @@ free_and_return:
for ( i = 0; i < nattrs; i++ )
{
slapi_ch_free((void **) &(attrs[ i ].sa_type));
- valuearrayfast_done(&attrs[ i ].sa_present_values);
- valuearrayfast_done(&attrs[ i ].sa_deleted_values);
- valuetree_free( &attrs[ i ].sa_vtree );
+ slapi_ch_free((void **) &(attrs[ i ].sa_present_values.va));
+ slapi_ch_free((void **) &(attrs[ i ].sa_deleted_values.va));
attr_done( &attrs[ i ].sa_attr );
}
if (tree_attr_checking)
@@ -1740,7 +1679,7 @@ entry2str_internal_put_attrlist( const Slapi_Attr *attrlist, int attr_state, int
* never be seen by any client. It will never be moved to the
* present values and is only used to preserve the AD-csn
*/
- valueset_add_string ((Slapi_ValueSet *)&a->a_deleted_values, "", CSN_TYPE_VALUE_DELETED, a->a_deletioncsn);
+ valueset_add_string (a, (Slapi_ValueSet *)&a->a_deleted_values, "", CSN_TYPE_VALUE_DELETED, a->a_deletioncsn);
}
entry2str_internal_put_valueset(a->a_type, a->a_deletioncsn, CSN_TYPE_ATTRIBUTE_DELETED, attr_state, &a->a_deleted_values, VALUE_DELETED, ecur, typebuf, typebuf_len, entry2str_ctrl);
@@ -2727,7 +2666,7 @@ slapi_entry_add_string(Slapi_Entry *e, const char *type, const char *value)
{
Slapi_Attr **a= NULL;
attrlist_find_or_create(&e->e_attrs, type, &a);
- valueset_add_string ( &(*a)->a_present_values, value, CSN_TYPE_UNKNOWN, NULL);
+ valueset_add_string ( *a, &(*a)->a_present_values, value, CSN_TYPE_UNKNOWN, NULL);
return 0;
}
diff --git a/ldap/servers/slapd/entrywsi.c b/ldap/servers/slapd/entrywsi.c
index 200743d..0335358 100644
--- a/ldap/servers/slapd/entrywsi.c
+++ b/ldap/servers/slapd/entrywsi.c
@@ -477,7 +477,7 @@ entry_add_present_values_wsi_single_valued(Slapi_Entry *e, const char *type, str
SLAPI_VALUE_FLAG_IGNOREERROR |
SLAPI_VALUE_FLAG_PRESERVECSNSET, NULL);
valuearray_update_csn (valuestoadd,CSN_TYPE_VALUE_UPDATED,csn);
- valueset_add_valuearray_ext(&a->a_present_values, valuestoadd, SLAPI_VALUE_FLAG_PASSIN);
+ slapi_valueset_add_attr_valuearray_ext (a, &a->a_present_values, valuestoadd, valuearray_count(valuestoadd), SLAPI_VALUE_FLAG_PASSIN, NULL);
slapi_ch_free ( (void **)&valuestoadd );
/*
* Now delete non-RDN values from a->a_present_values; and
@@ -514,7 +514,7 @@ entry_add_present_values_wsi_single_valued(Slapi_Entry *e, const char *type, str
Slapi_ValueSet vs;
/* Add each deleted value to the present list */
valuearray_update_csn(deletedvalues,CSN_TYPE_VALUE_UPDATED,csn);
- valueset_add_valuearray_ext(&a->a_present_values, deletedvalues, SLAPI_VALUE_FLAG_PASSIN);
+ slapi_valueset_add_attr_valuearray_ext (a, &a->a_present_values, deletedvalues, valuearray_count(deletedvalues), SLAPI_VALUE_FLAG_PASSIN, NULL);
/* Remove the deleted values from the values to add */
valueset_set_valuearray_passin(&vs,valuestoadd);
valueset_remove_valuearray(&vs, a, deletedvalues, SLAPI_VALUE_FLAG_IGNOREERROR, &v);
@@ -609,7 +609,7 @@ entry_add_present_values_wsi_multi_valued(Slapi_Entry *e, const char *type, stru
Slapi_ValueSet vs;
/* Add each deleted value to the present list */
valuearray_update_csn(deletedvalues,CSN_TYPE_VALUE_UPDATED,csn);
- valueset_add_valuearray_ext(&a->a_present_values, deletedvalues, SLAPI_VALUE_FLAG_PASSIN);
+ slapi_valueset_add_attr_valuearray_ext (a, &a->a_present_values, deletedvalues, valuearray_count(deletedvalues), SLAPI_VALUE_FLAG_PASSIN, NULL);
/* Remove the deleted values from the values to add */
valueset_set_valuearray_passin(&vs,valuestoadd);
valueset_remove_valuearray(&vs, a, deletedvalues, SLAPI_VALUE_FLAG_IGNOREERROR, &v);
@@ -744,7 +744,7 @@ entry_delete_present_values_wsi_single_valued(Slapi_Entry *e, const char *type,
valueset_update_csn_for_valuearray(&a->a_deleted_values, a, valuestodelete, CSN_TYPE_VALUE_DELETED, csn, &valuesupdated);
valuearray_free(&valuesupdated);
valuearray_update_csn(valuestodelete,CSN_TYPE_VALUE_DELETED,csn);
- valueset_add_valuearray_ext(&a->a_deleted_values, valuestodelete, SLAPI_VALUE_FLAG_PASSIN);
+ slapi_valueset_add_attr_valuearray_ext (a, &a->a_deleted_values, valuestodelete, valuearray_count(valuestodelete), SLAPI_VALUE_FLAG_PASSIN, NULL);
slapi_ch_free((void **)&valuestodelete);
resolve_attribute_state_single_valued(e, a, attr_state);
retVal= LDAP_SUCCESS;
@@ -838,7 +838,7 @@ entry_delete_present_values_wsi_multi_valued(Slapi_Entry *e, const char *type, s
valuearray_free(&valuesupdated);
valuearray_update_csn(valuestodelete,CSN_TYPE_VALUE_DELETED,csn);
- valueset_add_valuearray_ext(&a->a_deleted_values, valuestodelete, SLAPI_VALUE_FLAG_PASSIN);
+ slapi_valueset_add_attr_valuearray_ext (a, &a->a_deleted_values, valuestodelete, valuearray_count(valuestodelete), SLAPI_VALUE_FLAG_PASSIN, NULL);
/* all the elements in valuestodelete are passed;
* should free valuestodelete only (don't call valuearray_free)
* [622023] */
@@ -856,7 +856,8 @@ entry_delete_present_values_wsi_multi_valued(Slapi_Entry *e, const char *type, s
{
/* Add each deleted value to the deleted set */
valuearray_update_csn(deletedvalues,CSN_TYPE_VALUE_DELETED,csn);
- valueset_add_valuearray_ext(&a->a_deleted_values, deletedvalues, SLAPI_VALUE_FLAG_PASSIN);
+ slapi_valueset_add_attr_valuearray_ext (a,
+ &a->a_deleted_values, deletedvalues, valuearray_count(deletedvalues), SLAPI_VALUE_FLAG_PASSIN, NULL);
slapi_ch_free((void **)&deletedvalues);
if(valueset_isempty(&a->a_present_values))
{
diff --git a/ldap/servers/slapd/proto-slap.h b/ldap/servers/slapd/proto-slap.h
index 25663d2..a5317b4 100644
--- a/ldap/servers/slapd/proto-slap.h
+++ b/ldap/servers/slapd/proto-slap.h
@@ -167,13 +167,6 @@ int valuearray_first_value( Slapi_Value **va, Slapi_Value **v );
void valuearrayfast_init(struct valuearrayfast *vaf,Slapi_Value **va);
void valuearrayfast_done(struct valuearrayfast *vaf);
-void valuearrayfast_add_value(struct valuearrayfast *vaf,const Slapi_Value *v);
-void valuearrayfast_add_value_passin(struct valuearrayfast *vaf,Slapi_Value *v);
-void valuearrayfast_add_valuearrayfast(struct valuearrayfast *vaf,const struct valuearrayfast *vaf_add);
-
-int valuetree_add_value( const Slapi_Attr *sattr, const Slapi_Value *va, Avlnode **valuetreep);
-int valuetree_add_valuearray( const Slapi_Attr *sattr, Slapi_Value **va, Avlnode **valuetreep, int *duplicate_index);
-void valuetree_free( Avlnode **valuetreep );
/* Valueset functions */
@@ -184,15 +177,17 @@ int valueset_remove_valuearray(Slapi_ValueSet *vs, const Slapi_Attr *a, Slapi_Va
int valueset_purge(Slapi_ValueSet *vs, const CSN *csn);
Slapi_Value **valueset_get_valuearray(const Slapi_ValueSet *vs);
size_t valueset_size(const Slapi_ValueSet *vs);
+void slapi_valueset_add_valuearray(const Slapi_Attr *a, Slapi_ValueSet *vs, Slapi_Value **addvals);
void valueset_add_valuearray(Slapi_ValueSet *vs, Slapi_Value **addvals);
void valueset_add_valuearray_ext(Slapi_ValueSet *vs, Slapi_Value **addvals, PRUint32 flags);
-void valueset_add_string(Slapi_ValueSet *vs, const char *s, CSNType t, const CSN *csn);
+void valueset_add_string(const Slapi_Attr *a, Slapi_ValueSet *vs, const char *s, CSNType t, const CSN *csn);
void valueset_update_csn(Slapi_ValueSet *vs, CSNType t, const CSN *csn);
void valueset_add_valueset(Slapi_ValueSet *vs1, const Slapi_ValueSet *vs2);
int valueset_intersectswith_valuearray(Slapi_ValueSet *vs, const Slapi_Attr *a, Slapi_Value **values, int *duplicate_index);
Slapi_ValueSet *valueset_dup(const Slapi_ValueSet *dupee);
void valueset_remove_string(const Slapi_Attr *a, Slapi_ValueSet *vs, const char *s);
-int valueset_replace(Slapi_Attr *a, Slapi_ValueSet *vs, Slapi_Value **vals);
+int valueset_replace_valuearray(Slapi_Attr *a, Slapi_ValueSet *vs, Slapi_Value **vals);
+int valueset_replace_valuearray_ext(Slapi_Attr *a, Slapi_ValueSet *vs, Slapi_Value **vals, int dupcheck);
void valueset_update_csn_for_valuearray(Slapi_ValueSet *vs, const Slapi_Attr *a, Slapi_Value **valuestoupdate, CSNType t, const CSN *csn, Slapi_Value ***valuesupdated);
void valueset_update_csn_for_valuearray_ext(Slapi_ValueSet *vs, const Slapi_Attr *a, Slapi_Value **valuestoupdate, CSNType t, const CSN *csn, Slapi_Value ***valuesupdated, int csnref_updated);
void valueset_set_valuearray_byval(Slapi_ValueSet *vs, Slapi_Value **addvals);
diff --git a/ldap/servers/slapd/schema.c b/ldap/servers/slapd/schema.c
index 4962613..7a91aa1 100644
--- a/ldap/servers/slapd/schema.c
+++ b/ldap/servers/slapd/schema.c
@@ -5568,11 +5568,12 @@ va_locate_oc_val( Slapi_Value **va, const char *oc_name, const char *oc_oid )
* oc_unlock();
*/
static void
-va_expand_one_oc( const char *dn, Slapi_Value ***vap, const char *ocs )
+va_expand_one_oc( const char *dn, const Slapi_Attr *a, Slapi_ValueSet *vs, const char *ocs )
{
struct objclass *this_oc, *sup_oc;
- int p,i;
- Slapi_Value **newva;
+ int p;
+ Slapi_Value **va = vs->va;
+
this_oc = oc_find_nolock( ocs );
@@ -5589,29 +5590,18 @@ va_expand_one_oc( const char *dn, Slapi_Value ***vap, const char *ocs )
return; /* superior is unknown -- ignore */
}
- p = va_locate_oc_val( *vap, sup_oc->oc_name, sup_oc->oc_oid );
+ p = va_locate_oc_val( va, sup_oc->oc_name, sup_oc->oc_oid );
if ( p != -1 ) {
return; /* value already present -- done! */
}
- /* parent was not found. add to the end */
- for ( i = 0; (*vap)[i] != NULL; i++ ) {
- ;
- }
-
- /* prevent loops: stop if more than 1000 OC values are present */
- if ( i > 1000 ) {
+ if ( slapi_valueset_count(vs) > 1000 ) {
return;
}
- newva = (Slapi_Value **)slapi_ch_realloc( (char *)*vap,
- ( i + 2 )*sizeof(Slapi_Value *));
-
- newva[i] = slapi_value_new_string(sup_oc->oc_name);
- newva[i+1] = NULL;
-
- *vap = newva;
+ slapi_valueset_add_attr_value_ext(a, vs, slapi_value_new_string(sup_oc->oc_name), SLAPI_VALUE_FLAG_PASSIN);
+
LDAPDebug( LDAP_DEBUG_TRACE,
"Entry \"%s\": added missing objectClass value %s\n",
dn, sup_oc->oc_name, 0 );
@@ -5623,11 +5613,12 @@ va_expand_one_oc( const char *dn, Slapi_Value ***vap, const char *ocs )
* All missing superior classes are added to the objectClass attribute, as
* is 'top' if it is missing.
*/
-void
-slapi_schema_expand_objectclasses( Slapi_Entry *e )
+static void
+schema_expand_objectclasses_ext( Slapi_Entry *e, int lock)
{
Slapi_Attr *sa;
- Slapi_Value **va;
+ Slapi_Value *v;
+ Slapi_ValueSet *vs;
const char *dn = slapi_entry_get_dn_const( e );
int i;
@@ -5635,76 +5626,41 @@ slapi_schema_expand_objectclasses( Slapi_Entry *e )
return; /* no OC values -- nothing to do */
}
- va = attr_get_present_values( sa );
-
- if ( va == NULL || va[0] == NULL ) {
+ vs = &sa->a_present_values;
+ if ( slapi_valueset_isempty(vs) ) {
return; /* no OC values -- nothing to do */
}
- oc_lock_read();
+ if (lock)
+ oc_lock_read();
/*
* This loop relies on the fact that bv_expand_one_oc()
* always adds to the end
*/
- for ( i = 0; va[i] != NULL; ++i ) {
- if ( NULL != slapi_value_get_string(va[i]) ) {
- va_expand_one_oc( dn, &va, slapi_value_get_string(va[i]) );
- }
+ i = slapi_valueset_first_value(vs,&v);
+ while ( v != NULL) {
+ if ( NULL != slapi_value_get_string(v) ) {
+ va_expand_one_oc( dn, sa, &sa->a_present_values, slapi_value_get_string(v) );
+ }
+ i = slapi_valueset_next_value(vs, i, &v);
}
/* top must always be present */
- va_expand_one_oc( dn, &va, "top" );
-
- /*
- * Reset the present values in the set because we may have realloc'd it.
- * Note that this is the counterpart to the attr_get_present_values()
- * call we made above... nothing new has been allocated, but sa holds
- * a pointer to the original (pre realloc) va.
- */
- sa->a_present_values.va = va;
-
- oc_unlock();
+ va_expand_one_oc( dn, sa, &sa->a_present_values, "top" );
+ if (lock)
+ oc_unlock();
+}
+void
+slapi_schema_expand_objectclasses( Slapi_Entry *e )
+{
+ schema_expand_objectclasses_ext( e, 1);
}
void
schema_expand_objectclasses_nolock( Slapi_Entry *e )
{
- Slapi_Attr *sa;
- Slapi_Value **va;
- const char *dn = slapi_entry_get_dn_const( e );
- int i;
-
- if ( 0 != slapi_entry_attr_find( e, SLAPI_ATTR_OBJECTCLASS, &sa )) {
- return; /* no OC values -- nothing to do */
- }
-
- va = attr_get_present_values( sa );
-
- if ( va == NULL || va[0] == NULL ) {
- return; /* no OC values -- nothing to do */
- }
-
- /*
- * This loop relies on the fact that bv_expand_one_oc()
- * always adds to the end
- */
- for ( i = 0; va[i] != NULL; ++i ) {
- if ( NULL != slapi_value_get_string(va[i]) ) {
- va_expand_one_oc( dn, &va, slapi_value_get_string(va[i]) );
- }
- }
-
- /* top must always be present */
- va_expand_one_oc( dn, &va, "top" );
-
- /*
- * Reset the present values in the set because we may have realloc'd it.
- * Note that this is the counterpart to the attr_get_present_values()
- * call we made above... nothing new has been allocated, but sa holds
- * a pointer to the original (pre realloc) va.
- */
- sa->a_present_values.va = va;
+ schema_expand_objectclasses_ext( e, 0);
}
/* lock to protect both objectclass and schema_dse */
diff --git a/ldap/servers/slapd/slap.h b/ldap/servers/slapd/slap.h
index fff4646..0aa7aad 100644
--- a/ldap/servers/slapd/slap.h
+++ b/ldap/servers/slapd/slap.h
@@ -450,8 +450,14 @@ struct slapi_value
* struct slapi_value_tree *vt;
* };
*/
+
+/* It is a useless layer, always use the valuarray fast version */
+#define VALUE_SORT_THRESHOLD 10
struct slapi_value_set
{
+ int num; /* The number of values in the array */
+ int max; /* The number of slots in the array */
+ int *sorted; /* sorted array of indices, if NULL va is not sorted */
struct slapi_value **va;
};
@@ -530,6 +536,8 @@ typedef struct asyntaxinfo {
#define SLAPI_ATTR_FLAG_NOLOCKING 0x0020 /* the init code doesn't lock the
tables */
#define SLAPI_ATTR_FLAG_KEEP 0x8000 /* keep when replacing all */
+#define SLAPI_ATTR_FLAG_SYNTAX_LOOKUP_DONE 0x010000 /* syntax lookup done, flag set */
+#define SLAPI_ATTR_FLAG_SYNTAX_IS_DN 0x020000 /* syntax lookup done, flag set */
/* This is the type of the function passed into attr_syntax_enumerate_attrs */
typedef int (*AttrEnumFunc)(struct asyntaxinfo *asi, void *arg);
diff --git a/ldap/servers/slapd/slapi-plugin.h b/ldap/servers/slapd/slapi-plugin.h
index f08540f..d171f99 100644
--- a/ldap/servers/slapd/slapi-plugin.h
+++ b/ldap/servers/slapd/slapi-plugin.h
@@ -4658,6 +4658,7 @@ void slapi_ber_bvcpy(struct berval *bvd, const struct berval *bvs);
#define SLAPI_VALUE_FLAG_IGNOREERROR 0x2
#define SLAPI_VALUE_FLAG_PRESERVECSNSET 0x4
#define SLAPI_VALUE_FLAG_USENEWVALUE 0x8 /* see valueset_remove_valuearray */
+#define SLAPI_VALUE_FLAG_DUPCHECK 0x10 /* used in valueset_add... */
/**
* Creates an empty \c Slapi_ValueSet structure.
@@ -4752,6 +4753,7 @@ void slapi_valueset_add_value(Slapi_ValueSet *vs, const Slapi_Value *addval);
* \see slapi_valueset_next_value()
*/
void slapi_valueset_add_value_ext(Slapi_ValueSet *vs, Slapi_Value *addval, unsigned long flags);
+int slapi_valueset_add_attr_value_ext(const Slapi_Attr *a, Slapi_ValueSet *vs, Slapi_Value *addval, unsigned long flags);
/**
* Gets the first value in a \c Slapi_ValueSet structure.
@@ -4807,6 +4809,16 @@ int slapi_valueset_next_value( Slapi_ValueSet *vs, int index, Slapi_Value **v);
int slapi_valueset_count( const Slapi_ValueSet *vs);
/**
+ * Checks if a \c Slapi_ValueSet structure has values
+ *
+ * \param vs Pointer to the \c Slapi_ValueSet structure of which
+ * you wish to get the count.
+ * \return 1 if there are no values contained in the \c Slapi_ValueSet structure.
+ * \return 0 if there are values contained in the \c Slapi_ValueSet structure.
+ */
+int slapi_valueset_isempty( const Slapi_ValueSet *vs);
+
+/**
* Initializes a \c Slapi_ValueSet with copies of the values of a \c Slapi_Mod structure.
*
* \param vs Pointer to the \c Slapi_ValueSet structure into which
@@ -4837,6 +4849,7 @@ void slapi_valueset_set_from_smod(Slapi_ValueSet *vs, Slapi_Mod *smod);
* \see slapi_valueset_done()
*/
void slapi_valueset_set_valueset(Slapi_ValueSet *vs1, const Slapi_ValueSet *vs2);
+void slapi_valueset_join_attr_valueset(const Slapi_Attr *a, Slapi_ValueSet *vs1, const Slapi_ValueSet *vs2);
/**
* Finds a requested value in a valueset.
diff --git a/ldap/servers/slapd/slapi-private.h b/ldap/servers/slapd/slapi-private.h
index 1e8a53a..027056b 100644
--- a/ldap/servers/slapd/slapi-private.h
+++ b/ldap/servers/slapd/slapi-private.h
@@ -839,9 +839,12 @@ int charray_normdn_add(char ***chararray, char *dn, char *errstr);
* the very least before we make them public.
*/
void valuearray_add_value(Slapi_Value ***vals, const Slapi_Value *addval);
-void valuearray_add_value_fast(Slapi_Value ***vals, Slapi_Value *addval, int nvals, int *maxvals, int exact, int passin);
void valuearray_add_valuearray( Slapi_Value ***vals, Slapi_Value **addvals, PRUint32 flags );
void valuearray_add_valuearray_fast( Slapi_Value ***vals, Slapi_Value **addvals, int nvals, int naddvals, int *maxvals, int exact, int passin );
+Slapi_Value * valueset_find_sorted (const Slapi_Attr *a, const Slapi_ValueSet *vs, const Slapi_Value *v, int *index);
+int valueset_insert_value_to_sorted(const Slapi_Attr *a, Slapi_ValueSet *vs, Slapi_Value *vi, int dupcheck);
+void valueset_array_to_sorted (const Slapi_Attr *a, Slapi_ValueSet *vs);
+int slapi_valueset_add_attr_valuearray_ext(const Slapi_Attr *a, Slapi_ValueSet *vs, Slapi_Value **addval, int nvals, unsigned long flags, int *dup_index);
int valuearray_find(const Slapi_Attr *a, Slapi_Value **va, const Slapi_Value *v);
int valuearray_dn_normalize_value(Slapi_Value **vals);
diff --git a/ldap/servers/slapd/valueset.c b/ldap/servers/slapd/valueset.c
index c4e3d5d..76d03e1 100644
--- a/ldap/servers/slapd/valueset.c
+++ b/ldap/servers/slapd/valueset.c
@@ -501,7 +501,8 @@ valuearray_purge(Slapi_Value ***va, const CSN *csn)
*va= NULL;
}
- return(0);
+ /* return the number of remaining values */
+ return(i);
}
size_t
@@ -530,51 +531,6 @@ valuearray_update_csn(Slapi_Value **va, CSNType t, const CSN *csn)
}
}
-/*
- * Shunt up the values to cover the empty slots.
- *
- * "compressed" means "contains no NULL's"
- *
- * Invariant for the outer loop:
- * va[0..i] is compressed &&
- * va[n..numvalues] contains just NULL's
- *
- * Invariant for the inner loop:
- * i<j<=k<=n && va[j..k] has been shifted left by (j-i) places &&
- * va[k..n] remains to be shifted left by (j-i) places
- *
- */
-void
-valuearray_compress(Slapi_Value **va,int numvalues)
-{
- int i = 0;
- int n= numvalues;
- while(i<n)
- {
- if ( va[i] != NULL ) {
- i++;
- } else {
- int k,j;
- j = i + 1;
- /* Find the length of the next run of NULL's */
- while( j<n && va[j] == NULL) { j++; }
- /* va[i..j] is all NULL && j<= n */
- for ( k = j; k<n; k++ )
- {
- va[k - (j-i)] = va[k];
- va[k] = NULL;
- }
- /* va[i..n] has been shifted down by j-i places */
- n = n - (j-i);
- /*
- * If va[i] in now non null, then bump i,
- * if not then we are done anyway (j==n) so can bump it.
- */
- i++;
- }
- }
-}
-
/* <=========================== Value Array Fast ==========================> */
void
@@ -615,237 +571,11 @@ valuearrayfast_add_value_passin(struct valuearrayfast *vaf,Slapi_Value *v)
vaf->num++;
}
-void
-valuearrayfast_add_valuearrayfast(struct valuearrayfast *vaf,const struct valuearrayfast *vaf_add)
-{
- valuearray_add_valuearray_fast(&vaf->va,vaf_add->va,vaf->num,vaf_add->num,&vaf->max,0/*Exact*/,0/*!PassIn*/);
- vaf->num+= vaf_add->num;
-}
-
-/* <=========================== ValueArrayIndexTree =======================> */
-
-static int valuetree_dupvalue_disallow( caddr_t d1, caddr_t d2 );
-static int valuetree_node_cmp( caddr_t d1, caddr_t d2 );
-static int valuetree_node_free( caddr_t data );
-
-/*
- * structure used within AVL value trees.
- */
-typedef struct valuetree_node
-{
- int index; /* index into the value array */
- Slapi_Value *sval; /* the actual value */
-} valuetree_node;
-
-/*
- * Create or update an AVL tree of values that can be used to speed up value
- * lookups. We store the index keys for the values in the AVL tree so
- * we can use a trivial comparison function.
- *
- * Returns:
- * LDAP_SUCCESS on success,
- * LDAP_TYPE_OR_VALUE_EXISTS if the value already exists,
- * LDAP_OPERATIONS_ERROR for some unexpected failure.
- *
- * Sets *valuetreep to the root of the AVL tree that was created. If a
- * non-zero value is returned, the tree is freed if free_on_error is non-zero
- * and *valuetreep is set to NULL.
- */
-int
-valuetree_add_valuearray( const Slapi_Attr *sattr, Slapi_Value **va, Avlnode **valuetreep, int *duplicate_index )
-{
- int rc= LDAP_SUCCESS;
-
- PR_ASSERT(sattr!=NULL);
- PR_ASSERT(valuetreep!=NULL);
-
- if ( duplicate_index ) {
- *duplicate_index = -1;
- }
-
- if ( !valuearray_isempty(va) )
- {
- Slapi_Value **keyvals;
- /* Convert the value array into key values */
- if ( slapi_attr_values2keys_sv( sattr, (Slapi_Value**)va, &keyvals, LDAP_FILTER_EQUALITY ) != 0 ) /* jcm cast */
- {
- LDAPDebug( LDAP_DEBUG_ANY,"slapi_attr_values2keys_sv for attribute %s failed\n", sattr->a_type, 0, 0 );
- rc= LDAP_OPERATIONS_ERROR;
- }
- else
- {
- int i;
- valuetree_node *vaip;
- for ( i = 0; rc==LDAP_SUCCESS && va[i] != NULL; ++i )
- {
- if ( keyvals[i] == NULL )
- {
- LDAPDebug( LDAP_DEBUG_ANY,"slapi_attr_values2keys_sv for attribute %s did not return enough key values\n", sattr->a_type, 0, 0 );
- rc= LDAP_OPERATIONS_ERROR;
- }
- else
- {
- vaip = (valuetree_node *)slapi_ch_malloc( sizeof( valuetree_node ));
- vaip->index = i;
- vaip->sval = keyvals[i];
- if (( rc = avl_insert( valuetreep, vaip, valuetree_node_cmp, valuetree_dupvalue_disallow )) != 0 )
- {
- slapi_ch_free( (void **)&vaip );
- /* Value must already be in there */
- rc= LDAP_TYPE_OR_VALUE_EXISTS;
- if ( duplicate_index ) {
- *duplicate_index = i;
- }
- }
- else
- {
- keyvals[i]= NULL;
- }
- }
- }
- /* start freeing at index i - the rest of them have already
- been moved into valuetreep
- the loop iteration will always do the +1, so we have
- to remove it if so */
- i = (i > 0) ? i-1 : 0;
- valuearray_free_ext( &keyvals, i );
- }
- }
- if(rc!=0)
- {
- valuetree_free( valuetreep );
- }
-
- return rc;
-}
-
-int
-valuetree_add_value( const Slapi_Attr *sattr, const Slapi_Value *v, Avlnode **valuetreep)
-{
- Slapi_Value *va[2];
- va[0]= (Slapi_Value*)v;
- va[1]= NULL;
- return valuetree_add_valuearray( sattr, va, valuetreep, NULL);
-}
-
-
-/*
- *
- * Find value "v" using AVL tree "valuetree"
- *
- * returns LDAP_SUCCESS if "v" was found, LDAP_NO_SUCH_ATTRIBUTE
- * if "v" was not found and LDAP_OPERATIONS_ERROR if some unexpected error occurs.
- */
-static int
-valuetree_find( const struct slapi_attr *a, const Slapi_Value *v, Avlnode *valuetree, int *index)
-{
- const Slapi_Value *oneval[2];
- Slapi_Value **keyvals;
- valuetree_node *vaip, tmpvain;
-
- PR_ASSERT(a!=NULL);
- PR_ASSERT(a->a_plugin!=NULL);
- PR_ASSERT(v!=NULL);
- PR_ASSERT(valuetree!=NULL);
- PR_ASSERT(index!=NULL);
-
- if ( a == NULL || v == NULL || valuetree == NULL )
- {
- return( LDAP_OPERATIONS_ERROR );
- }
-
- keyvals = NULL;
- oneval[0] = v;
- oneval[1] = NULL;
- if ( slapi_attr_values2keys_sv( a, (Slapi_Value**)oneval, &keyvals, LDAP_FILTER_EQUALITY ) != 0 /* jcm cast */
- || keyvals == NULL
- || keyvals[0] == NULL )
- {
- LDAPDebug( LDAP_DEBUG_ANY, "valuetree_find_and_replace: "
- "slapi_attr_values2keys_sv failed for type %s\n",
- a->a_type, 0, 0 );
- return( LDAP_OPERATIONS_ERROR );
- }
-
- tmpvain.index = 0;
- tmpvain.sval = keyvals[0];
- vaip = (valuetree_node *)avl_find( valuetree, &tmpvain, valuetree_node_cmp );
-
- if ( keyvals != NULL )
- {
- valuearray_free( &keyvals );
- }
-
- if (vaip == NULL)
- {
- return( LDAP_NO_SUCH_ATTRIBUTE );
- }
- else
- {
- *index= vaip->index;
- }
-
- return( LDAP_SUCCESS );
-}
-
-static int
-valuetree_dupvalue_disallow( caddr_t d1, caddr_t d2 )
-{
- return( 1 );
-}
-
-
-void
-valuetree_free( Avlnode **valuetreep )
-{
- if ( valuetreep != NULL && *valuetreep != NULL )
- {
- avl_free( *valuetreep, valuetree_node_free );
- *valuetreep = NULL;
- }
-}
-
-
-static int
-valuetree_node_free( caddr_t data )
-{
- if ( data!=NULL )
- {
- valuetree_node *vaip = (valuetree_node *)data;
-
- slapi_value_free(&vaip->sval);
- slapi_ch_free( (void **)&data );
- }
- return( 0 );
-}
-
-
-static int
-valuetree_node_cmp( caddr_t d1, caddr_t d2 )
-{
- const struct berval *bv1, *bv2;
- int rc;
-
- bv1 = slapi_value_get_berval(((valuetree_node *)d1)->sval);
- bv2 = slapi_value_get_berval(((valuetree_node *)d2)->sval);
-
- if ( bv1->bv_len < bv2->bv_len ) {
- rc = -1;
- } else if ( bv1->bv_len > bv2->bv_len ) {
- rc = 1;
- } else {
- rc = memcmp( bv1->bv_val, bv2->bv_val, bv1->bv_len );
- }
-
- return( rc );
-}
-
/* <=========================== Value Set =======================> */
-/*
- * JCM: All of these valueset functions are just forwarded to the
- * JCM: valuearray functions... waste of time. Inline them!
- */
+#define VALUESET_ARRAY_SORT_THRESHOLD 10
+#define VALUESET_ARRAY_MINSIZE 2
+#define VALUESET_ARRAY_MAXINCREMENT 4096
Slapi_ValueSet *
slapi_valueset_new()
@@ -864,6 +594,9 @@ slapi_valueset_init(Slapi_ValueSet *vs)
if(vs!=NULL)
{
vs->va= NULL;
+ vs->sorted = NULL;
+ vs->num = 0;
+ vs->max = 0;
}
}
@@ -877,6 +610,13 @@ slapi_valueset_done(Slapi_ValueSet *vs)
valuearray_free(&vs->va);
vs->va= NULL;
}
+ if (vs->sorted != NULL)
+ {
+ slapi_ch_free ((void **)&vs->sorted);
+ vs->sorted = NULL;
+ }
+ vs->num = 0;
+ vs->max = 0;
}
}
@@ -901,8 +641,22 @@ slapi_valueset_set_from_smod(Slapi_ValueSet *vs, Slapi_Mod *smod)
void
valueset_set_valuearray_byval(Slapi_ValueSet *vs, Slapi_Value **addvals)
{
- slapi_valueset_init(vs);
- valueset_add_valuearray(vs,addvals);
+ int i, j=0;
+ slapi_valueset_init(vs);
+ vs->num = valuearray_count(addvals);
+ vs->max = vs->num + 1;
+ vs->va = (Slapi_Value **) slapi_ch_malloc( vs->max * sizeof(Slapi_Value *));
+ for ( i = 0, j = 0; i < vs->num; i++)
+ {
+ if ( addvals[i]!=NULL )
+ {
+ /* We copy the values */
+ vs->va[j] = slapi_value_dup(addvals[i]);
+ j++;
+ }
+ }
+ vs->va[j] = NULL;
+
}
void
@@ -910,6 +664,8 @@ valueset_set_valuearray_passin(Slapi_ValueSet *vs, Slapi_Value **addvals)
{
slapi_valueset_init(vs);
vs->va= addvals;
+ vs->num = valuearray_count(addvals);
+ vs->max = vs->num + 1;
}
void
@@ -919,6 +675,15 @@ slapi_valueset_set_valueset(Slapi_ValueSet *vs1, const Slapi_ValueSet *vs2)
valueset_add_valueset(vs1,vs2);
}
+void
+slapi_valueset_join_attr_valueset(const Slapi_Attr *a, Slapi_ValueSet *vs1, const Slapi_ValueSet *vs2)
+{
+ if (slapi_valueset_isempty(vs1))
+ valueset_add_valueset(vs1,vs2);
+ else
+ slapi_valueset_add_attr_valuearray_ext (a, vs1, vs2->va, vs2->num, 0, NULL);
+}
+
int
slapi_valueset_first_value( Slapi_ValueSet *vs, Slapi_Value **v )
{
@@ -934,15 +699,21 @@ slapi_valueset_next_value( Slapi_ValueSet *vs, int index, Slapi_Value **v)
int
slapi_valueset_count( const Slapi_ValueSet *vs)
{
- int r=0;
if (NULL != vs)
{
- if(!valuearray_isempty(vs->va))
- {
- r= valuearray_count(vs->va);
- }
+ return (vs->num);
}
- return r;
+ return 0;
+}
+
+int
+slapi_valueset_isempty( const Slapi_ValueSet *vs)
+{
+ if (NULL != vs)
+ {
+ return (vs->num == 0);
+ }
+ return 1;
}
int
@@ -956,12 +727,15 @@ Slapi_Value *
slapi_valueset_find(const Slapi_Attr *a, const Slapi_ValueSet *vs, const Slapi_Value *v)
{
Slapi_Value *r= NULL;
- if(!valuearray_isempty(vs->va))
- {
- int i= valuearray_find(a,vs->va,v);
- if(i!=-1)
- {
- r= vs->va[i];
+ if(vs->num > 0 )
+ {
+ if (vs->sorted) {
+ r = valueset_find_sorted(a,vs,v,NULL);
+ } else {
+ int i= valuearray_find(a,vs->va,v);
+ if(i!=-1) {
+ r= vs->va[i];
+ }
}
}
return r;
@@ -970,17 +744,46 @@ slapi_valueset_find(const Slapi_Attr *a, const Slapi_ValueSet *vs, const Slapi_V
/*
* The value is found in the set, removed and returned.
* The caller is responsible for freeing the value.
+ *
+ * The _sorted function also handles the cleanup of the sorted array
*/
Slapi_Value *
-valueset_remove_value(const Slapi_Attr *a, Slapi_ValueSet *vs, const Slapi_Value *v)
+valueset_remove_value_sorted(const Slapi_Attr *a, Slapi_ValueSet *vs, const Slapi_Value *v)
{
Slapi_Value *r= NULL;
- if(!valuearray_isempty(vs->va))
- {
- r= valuearray_remove_value(a, vs->va, v);
+ int i, position = 0;
+ r = valueset_find_sorted(a,vs,v,&position);
+ if (r) {
+ /* the value was found, remove from valuearray */
+ int index = vs->sorted[position];
+ memmove(&vs->sorted[position],&vs->sorted[position+1],(vs->num - position)*sizeof(int));
+ memmove(&vs->va[index],&vs->va[index+1],(vs->num - index)*sizeof(Slapi_Value *));
+ vs->num--;
+ /* unfortunately the references in the sorted array
+ * to values past the removed one are no longer correct
+ * need to adjust */
+ for (i=0; i < vs->num; i++) {
+ if (vs->sorted[i] > index) vs->sorted[i]--;
+ }
}
return r;
}
+Slapi_Value *
+valueset_remove_value(const Slapi_Attr *a, Slapi_ValueSet *vs, const Slapi_Value *v)
+{
+ if (vs->sorted) {
+ return (valueset_remove_value_sorted(a, vs, v));
+ } else {
+ Slapi_Value *r= NULL;
+ if(!valuearray_isempty(vs->va))
+ {
+ r= valuearray_remove_value(a, vs->va, v);
+ if (r)
+ vs->num--;
+ }
+ return r;
+ }
+}
/*
* Remove any values older than the CSN.
@@ -989,11 +792,25 @@ int
valueset_purge(Slapi_ValueSet *vs, const CSN *csn)
{
int r= 0;
- if(!valuearray_isempty(vs->va))
- {
+ if(!valuearray_isempty(vs->va)) {
+ /* valuearray_purge is not valueset and sorting aware,
+ * maybe need to rewrite, at least keep the valueset
+ * consistent
+ */
r= valuearray_purge(&vs->va, csn);
+ vs->num = r;
+ if (vs->va == NULL) {
+ /* va was freed */
+ vs->max = 0;
+ }
+ /* we can no longer rely on the sorting */
+ if (vs->sorted != NULL)
+ {
+ slapi_ch_free ((void **)&vs->sorted);
+ vs->sorted = NULL;
+ }
}
- return r;
+ return 0;
}
Slapi_Value **
@@ -1017,11 +834,20 @@ valueset_size(const Slapi_ValueSet *vs)
* The value array is passed in by value.
*/
void
+slapi_valueset_add_valuearray(const Slapi_Attr *a, Slapi_ValueSet *vs, Slapi_Value **addvals)
+{
+ if(!valuearray_isempty(addvals))
+ {
+ slapi_valueset_add_attr_valuearray_ext (a, vs, addvals, valuearray_count(addvals), 0, NULL);
+ }
+}
+
+void
valueset_add_valuearray(Slapi_ValueSet *vs, Slapi_Value **addvals)
{
if(!valuearray_isempty(addvals))
{
- valuearray_add_valuearray(&vs->va, addvals, 0);
+ slapi_valueset_add_attr_valuearray_ext (NULL, vs, addvals, valuearray_count(addvals), 0, NULL);
}
}
@@ -1030,7 +856,7 @@ valueset_add_valuearray_ext(Slapi_ValueSet *vs, Slapi_Value **addvals, PRUint32
{
if(!valuearray_isempty(addvals))
{
- valuearray_add_valuearray(&vs->va, addvals, flags);
+ slapi_valueset_add_attr_valuearray_ext (NULL, vs, addvals, valuearray_count(addvals), flags, NULL);
}
}
@@ -1040,7 +866,7 @@ valueset_add_valuearray_ext(Slapi_ValueSet *vs, Slapi_Value **addvals, PRUint32
void
slapi_valueset_add_value(Slapi_ValueSet *vs, const Slapi_Value *addval)
{
- valuearray_add_value(&vs->va,addval);
+ slapi_valueset_add_value_ext(vs, addval, 0);
}
void
@@ -1049,19 +875,272 @@ slapi_valueset_add_value_ext(Slapi_ValueSet *vs, Slapi_Value *addval, unsigned l
Slapi_Value *oneval[2];
oneval[0]= (Slapi_Value*)addval;
oneval[1]= NULL;
- valuearray_add_valuearray(&vs->va, oneval, flags);
+ slapi_valueset_add_attr_valuearray_ext(NULL, vs, oneval, 1, flags, NULL);
+}
+
+
+/* find value v in the sorted array of values, using syntax of attribut a for comparison
+ *
+ */
+static int
+valueset_value_syntax_cmp( const Slapi_Attr *a, const Slapi_Value *v1, const Slapi_Value *v2 )
+{
+ /* this looks like a huge overhead, but there are no simple functions to normalize and
+ * compare available
+ */
+ const Slapi_Value *oneval[3];
+ Slapi_Value **keyvals;
+ int rc = -1;
+
+ keyvals = NULL;
+ oneval[0] = v1;
+ oneval[1] = v2;
+ oneval[2] = NULL;
+ if ( slapi_attr_values2keys_sv( a, (Slapi_Value**)oneval, &keyvals, LDAP_FILTER_EQUALITY ) != 0
+ || keyvals == NULL
+ || keyvals[0] == NULL || keyvals[1] == NULL)
+ {
+ /* this should never happen since always a syntax plugin to
+ * generate the keys will be found (there exists a default plugin)
+ * log an error and continue.
+ */
+ LDAPDebug( LDAP_DEBUG_ANY, "valueset_value_syntax_cmp: "
+ "slapi_attr_values2keys_sv failed for type %s\n",
+ a->a_type, 0, 0 );
+ } else {
+ struct berval *bv1, *bv2;
+ bv1 = &keyvals[0]->bv;
+ bv2 = &keyvals[1]->bv;
+ if ( bv1->bv_len < bv2->bv_len ) {
+ rc = -1;
+ } else if ( bv1->bv_len > bv2->bv_len ) {
+ rc = 1;
+ } else {
+ rc = memcmp( bv1->bv_val, bv2->bv_val, bv1->bv_len );
+ }
+ }
+ if (keyvals != NULL)
+ valuearray_free( &keyvals );
+ return (rc);
+
+}
+static int
+valueset_value_cmp( const Slapi_Attr *a, const Slapi_Value *v1, const Slapi_Value *v2 )
+{
+
+ if ( a == NULL || slapi_attr_is_dn_syntax_attr(a)) {
+ /* if no attr is provided just do a utf8compare */
+ /* for all the values the first step of normalization is done,
+ * case folding still needs to be done
+ */
+ /* would this be enough ?: return (strcasecmp(v1->bv.bv_val, v2->bv.bv_val)); */
+ return (slapi_utf8casecmp(v1->bv.bv_val, v2->bv.bv_val));
+ } else {
+ /* slapi_value_compare doesn't work, it only returns 0 or -1
+ return (slapi_value_compare(a, v1, v2));
+ * use special compare, base on what valuetree_find did
+ */
+ return(valueset_value_syntax_cmp(a, v1, v2));
+ }
+}
+/* find a value in the sorted valuearray.
+ * If the value is found the pointer to the value is returned and if index is provided
+ * it will return the index of the value in the valuearray
+ * If the value is not found, index will contain the place where the value would be inserted
+ */
+Slapi_Value *
+valueset_find_sorted (const Slapi_Attr *a, const Slapi_ValueSet *vs, const Slapi_Value *v, int *index)
+{
+ int cmp = -1;
+ int bot = -1;
+ int top;
+
+ if (vs->num == 0) {
+ /* empty valueset */
+ if (index) *index = 0;
+ return (NULL);
+ } else {
+ top = vs->num;
+ }
+ while (top - bot > 1) {
+ int mid = (top + bot)/2;
+ if ( (cmp = valueset_value_cmp(a, v, vs->va[vs->sorted[mid]])) > 0)
+ bot = mid;
+ else
+ top = mid;
+ }
+ if (index) *index = top;
+ /* check if the value is found */
+ if ( top < vs->num && (0 == valueset_value_cmp(a, v, vs->va[vs->sorted[top]])))
+ return (vs->va[vs->sorted[top]]);
+ else
+ return (NULL);
+}
+
+void
+valueset_array_to_sorted (const Slapi_Attr *a, Slapi_ValueSet *vs)
+{
+ int i, j, swap;
+
+ /* initialize sort array */
+ for (i = 0; i < vs->num; i++)
+ vs->sorted[i] = i;
+
+ /* now sort it, use a simple insertion sort as the array will always
+ * be very small when initially sorted
+ */
+ for (i = 1; i < vs->num; i++) {
+ swap = vs->sorted[i];
+ j = i -1;
+
+ while ( j >= 0 && valueset_value_cmp (a, vs->va[vs->sorted[j]], vs->va[swap]) > 0 ) {
+ vs->sorted[j+1] = vs->sorted[j];
+ j--;
+ }
+ vs->sorted[j+1] = swap;
+ }
+}
+/* insert a value into a sorted array, if dupcheck is set no duplicate values will be accepted
+ * (is there a reason to allow duplicates ? LK
+ * if the value is inserted the the function returns the index where it was inserted
+ * if the value already exists -index is returned to indicate anerror an the index of the existing value
+ */
+int
+valueset_insert_value_to_sorted(const Slapi_Attr *a, Slapi_ValueSet *vs, Slapi_Value *vi, int dupcheck)
+{
+ int index = -1;
+ Slapi_Value *v;
+ /* test for pre sorted array and to avoid boundary condition */
+ if (vs->num == 0) {
+ vs->sorted[0] = 0;
+ vs->num++;
+ return(0);
+ } else if (valueset_value_cmp (a, vi, vs->va[vs->sorted[vs->num-1]]) > 0 ) {
+ vs->sorted[vs->num] = vs->num;
+ vs->num++;
+ return (vs->num);
+ }
+ v = valueset_find_sorted (a, vs, vi, &index);
+ if (v && dupcheck) {
+ /* value already exists, do not insert duplicates */
+ return (-1);
+ } else {
+ memmove(&vs->sorted[index+1],&vs->sorted[index],(vs->num - index)* sizeof(int));
+ vs->sorted[index] = vs->num;
+ vs->num++;
+ return(index);
+ }
+
+}
+
+int
+slapi_valueset_add_attr_valuearray_ext(const Slapi_Attr *a, Slapi_ValueSet *vs,
+ Slapi_Value **addvals, int naddvals, unsigned long flags, int *dup_index)
+{
+ int rc = LDAP_SUCCESS;
+ int i, dup;
+ int allocate = 0;
+ int need;
+ int passin = flags & SLAPI_VALUE_FLAG_PASSIN;
+ int dupcheck = flags & SLAPI_VALUE_FLAG_DUPCHECK;
+
+ if (naddvals == 0)
+ return (rc);
+
+ need = vs->num + naddvals + 1;
+ if (need > vs->max) {
+ /* Expand the array */
+ allocate= vs->max;
+ if ( allocate == 0 ) /* initial allocation */
+ allocate = VALUESET_ARRAY_MINSIZE;
+ while ( allocate < need )
+ {
+ if (allocate > VALUESET_ARRAY_MAXINCREMENT )
+ /* do not grow exponentially */
+ allocate += VALUESET_ARRAY_MAXINCREMENT;
+ else
+ allocate *= 2;
+
+ }
+ }
+ if(allocate>0)
+ {
+ if(vs->va==NULL)
+ {
+ vs->va = (Slapi_Value **) slapi_ch_malloc( allocate * sizeof(Slapi_Value *));
+ }
+ else
+ {
+ vs->va = (Slapi_Value **) slapi_ch_realloc( (char *) vs->va, allocate * sizeof(Slapi_Value *));
+ if (vs->sorted) {
+ vs->sorted = (int *) slapi_ch_realloc( (char *) vs->sorted, allocate * sizeof(int));
+ }
+ }
+ vs->max= allocate;
+ }
+
+ if ( (vs->num + naddvals > VALUESET_ARRAY_SORT_THRESHOLD || dupcheck ) &&
+ !vs->sorted ) {
+ /* initialize sort array and do initial sort */
+ vs->sorted = (int *) slapi_ch_malloc( vs->max* sizeof(int));
+ valueset_array_to_sorted (a, vs);
+ }
+
+ for ( i = 0; i < naddvals; i++)
+ {
+ if ( addvals[i]!=NULL )
+ {
+ if(passin)
+ {
+ /* We consume the values */
+ (vs->va)[vs->num] = addvals[i];
+ }
+ else
+ {
+ /* We copy the values */
+ (vs->va)[vs->num] = slapi_value_dup(addvals[i]);
+ }
+ if (vs->sorted) {
+ dup = valueset_insert_value_to_sorted(a, vs, (vs->va)[vs->num], dupcheck);
+ if (dup < 0 ) {
+ rc = LDAP_TYPE_OR_VALUE_EXISTS;
+ if (dup_index) *dup_index = i;
+ if ( !passin)
+ slapi_value_free(&(vs->va)[vs->num]);
+ break;
+ }
+ } else {
+ vs->num++;
+ }
+ }
+ }
+ (vs->va)[vs->num] = NULL;
+
+ return (rc);
+}
+
+int
+slapi_valueset_add_attr_value_ext(const Slapi_Attr *a, Slapi_ValueSet *vs, Slapi_Value *addval, unsigned long flags)
+{
+
+ Slapi_Value *oneval[2];
+ int rc;
+ oneval[0]= (Slapi_Value*)addval;
+ oneval[1]= NULL;
+ rc = slapi_valueset_add_attr_valuearray_ext(a, vs, oneval, 1, flags, NULL );
+ return (rc);
}
/*
* The string is passed in by value.
*/
void
-valueset_add_string(Slapi_ValueSet *vs, const char *s, CSNType t, const CSN *csn)
+valueset_add_string(const Slapi_Attr *a, Slapi_ValueSet *vs, const char *s, CSNType t, const CSN *csn)
{
Slapi_Value v;
value_init(&v,NULL,t,csn);
slapi_value_set_string(&v,s);
- valuearray_add_value(&vs->va,&v);
+ slapi_valueset_add_attr_value_ext(a, vs, &v, 0 );
value_done(&v);
}
@@ -1071,8 +1150,30 @@ valueset_add_string(Slapi_ValueSet *vs, const char *s, CSNType t, const CSN *csn
void
valueset_add_valueset(Slapi_ValueSet *vs1, const Slapi_ValueSet *vs2)
{
- if (vs1 && vs2)
- valueset_add_valuearray(vs1, vs2->va);
+ int i;
+
+ if (vs1 && vs2) {
+ if (vs2->va) {
+ /* need to copy valuearray */
+ if (vs2->max == 0) {
+ /* temporary hack, not all valuesets were created properly. fix it now */
+ vs1->num = valuearray_count(vs2->va);
+ vs1->max = vs1->num + 1;
+ } else {
+ vs1->num = vs2->num;
+ vs1->max = vs2->max;
+ }
+ vs1->va = (Slapi_Value **) slapi_ch_malloc( vs1->max * sizeof(Slapi_Value *));
+ for (i=0; i< vs1->num;i++) {
+ vs1->va[i] = slapi_value_dup(vs2->va[i]);
+ }
+ vs1->va[vs1->num] = NULL;
+ }
+ if (vs2->sorted) {
+ vs1->sorted = (int *) slapi_ch_malloc( vs1->max* sizeof(int));
+ memcpy(&vs1->sorted[0],&vs2->sorted[0],vs1->num* sizeof(int));
+ }
+ }
}
void
@@ -1082,7 +1183,7 @@ valueset_remove_string(const Slapi_Attr *a, Slapi_ValueSet *vs, const char *s)
Slapi_Value *removed;
value_init(&v,NULL,CSN_TYPE_NONE,NULL);
slapi_value_set_string(&v,s);
- removed = valuearray_remove_value(a, vs->va, &v);
+ removed = valueset_remove_value(a, vs, &v);
if(removed) {
slapi_value_free(&removed);
}
@@ -1121,158 +1222,59 @@ int
valueset_remove_valuearray(Slapi_ValueSet *vs, const Slapi_Attr *a, Slapi_Value **valuestodelete, int flags, Slapi_Value ***va_out)
{
int rc= LDAP_SUCCESS;
- if(!valuearray_isempty(vs->va))
+ if(vs->num > 0)
{
- int numberofvaluestodelete= valuearray_count(valuestodelete);
+ int i;
struct valuearrayfast vaf_out;
+
if ( va_out )
{
valuearrayfast_init(&vaf_out,*va_out);
}
/*
- * If there are more then one values, build an AVL tree to check
- * the duplicated values.
+ * For larger valuesets the valuarray is sorted, values can be deleted individually
+ *
*/
- if ( numberofvaluestodelete > 1 )
+ for ( i = 0; rc==LDAP_SUCCESS && valuestodelete[i] != NULL; ++i )
{
- /*
- * Several values to delete: first build an AVL tree that
- * holds all of the existing values and use that to find
- * the values we want to delete.
- */
- Avlnode *vtree = NULL;
- int numberofexistingvalues= slapi_valueset_count(vs);
- rc= valuetree_add_valuearray( a, vs->va, &vtree, NULL );
- if ( rc!=LDAP_SUCCESS )
- {
- /*
- * failed while constructing AVL tree of existing
- * values... something bad happened.
- */
- rc= LDAP_OPERATIONS_ERROR;
- }
- else
+ Slapi_Value *found = valueset_remove_value(a, vs, valuestodelete[i]);
+ if(found!=NULL)
{
- int i;
- /*
- * find and mark all the values that are to be deleted
- */
- for ( i = 0; rc == LDAP_SUCCESS && valuestodelete[i] != NULL; ++i )
+ if ( va_out )
{
- int index= 0;
- rc = valuetree_find( a, valuestodelete[i], vtree, &index );
- if(rc==LDAP_SUCCESS)
- {
- if(vs->va[index]!=NULL)
- {
- /* Move the value to be removed to the out array */
- if ( va_out )
- {
- if (vs->va[index]->v_csnset &&
- (flags & (SLAPI_VALUE_FLAG_PRESERVECSNSET|
- SLAPI_VALUE_FLAG_USENEWVALUE)))
- {
- valuestodelete[i]->v_csnset = csnset_dup (vs->va[index]->v_csnset);
- }
- if (flags & SLAPI_VALUE_FLAG_USENEWVALUE)
- {
- valuearrayfast_add_value_passin(&vaf_out,valuestodelete[i]);
- valuestodelete[i] = vs->va[index];
- vs->va[index] = NULL;
- }
- else
- {
- valuearrayfast_add_value_passin(&vaf_out,vs->va[index]);
- vs->va[index] = NULL;
- }
- }
- else
- {
- if (flags & SLAPI_VALUE_FLAG_PRESERVECSNSET)
- {
- valuestodelete[i]->v_csnset = vs->va[index]->v_csnset;
- vs->va[index]->v_csnset = NULL;
- }
- slapi_value_free ( & vs->va[index] );
- }
- }
- else
- {
- /* We already deleted this value... */
- if((flags & SLAPI_VALUE_FLAG_IGNOREERROR) == 0)
- {
- /* ...that's an error. */
- rc= LDAP_NO_SUCH_ATTRIBUTE;
- }
- }
- }
- else
+ if (found->v_csnset &&
+ (flags & (SLAPI_VALUE_FLAG_PRESERVECSNSET|
+ SLAPI_VALUE_FLAG_USENEWVALUE)))
{
- /* Couldn't find the value to be deleted */
- if(rc==LDAP_NO_SUCH_ATTRIBUTE && (flags & SLAPI_VALUE_FLAG_IGNOREERROR ))
- {
- rc= LDAP_SUCCESS;
- }
+ valuestodelete[i]->v_csnset = csnset_dup (found->v_csnset);
}
- }
- valuetree_free( &vtree );
-
- if ( rc != LDAP_SUCCESS )
- {
- LDAPDebug( LDAP_DEBUG_ANY,"could not find value %d for attr %s (%s)\n", i-1, a->a_type, ldap_err2string( rc ));
- }
- else
- {
- /* Shunt up all the remaining values to cover the deleted ones. */
- valuearray_compress(vs->va,numberofexistingvalues);
- }
- }
- }
- else
- {
- /* We delete one or no value, so we use brute force. */
- int i;
- for ( i = 0; rc==LDAP_SUCCESS && valuestodelete[i] != NULL; ++i )
- {
- Slapi_Value *found= valueset_remove_value(a, vs, valuestodelete[i]);
- if(found!=NULL)
- {
- if ( va_out )
+ if (flags & SLAPI_VALUE_FLAG_USENEWVALUE)
{
- if (found->v_csnset &&
- (flags & (SLAPI_VALUE_FLAG_PRESERVECSNSET|
- SLAPI_VALUE_FLAG_USENEWVALUE)))
- {
- valuestodelete[i]->v_csnset = csnset_dup (found->v_csnset);
- }
- if (flags & SLAPI_VALUE_FLAG_USENEWVALUE)
- {
- valuearrayfast_add_value_passin(&vaf_out,valuestodelete[i]);
- valuestodelete[i] = found;
- }
- else
- {
- valuearrayfast_add_value_passin(&vaf_out,found);
- }
+ valuearrayfast_add_value_passin(&vaf_out,valuestodelete[i]);
+ valuestodelete[i] = found;
}
else
{
- if (flags & SLAPI_VALUE_FLAG_PRESERVECSNSET)
- {
- valuestodelete[i]->v_csnset = found->v_csnset;
- found->v_csnset = NULL;
- }
- slapi_value_free ( & found );
+ valuearrayfast_add_value_passin(&vaf_out,found);
}
}
else
{
- if((flags & SLAPI_VALUE_FLAG_IGNOREERROR) == 0)
+ if (flags & SLAPI_VALUE_FLAG_PRESERVECSNSET)
{
- LDAPDebug( LDAP_DEBUG_ARGS,"could not find value %d for attr %s\n", i-1, a->a_type, 0 );
- rc= LDAP_NO_SUCH_ATTRIBUTE;
+ valuestodelete[i]->v_csnset = found->v_csnset;
+ found->v_csnset = NULL;
}
+ slapi_value_free ( & found );
+ }
+ }
+ else
+ {
+ if((flags & SLAPI_VALUE_FLAG_IGNOREERROR) == 0)
+ {
+ LDAPDebug( LDAP_DEBUG_ARGS,"could not find value %d for attr %s\n", i-1, a->a_type, 0 );
+ rc= LDAP_NO_SUCH_ATTRIBUTE;
}
}
}
@@ -1288,88 +1290,13 @@ valueset_remove_valuearray(Slapi_ValueSet *vs, const Slapi_Attr *a, Slapi_Value
return rc;
}
-/*
- * Check if the set of values in the valueset and the valuearray intersect.
- *
- * Returns
- * LDAP_SUCCESS - No intersection.
- * LDAP_NO_SUCH_ATTRIBUTE - There is an intersection.
- * LDAP_OPERATIONS_ERROR - There are duplicate values in the value set already.
- */
-int
-valueset_intersectswith_valuearray(Slapi_ValueSet *vs, const Slapi_Attr *a, Slapi_Value **values, int *duplicate_index )
-{
- int rc= LDAP_SUCCESS;
-
- if ( duplicate_index ) {
- *duplicate_index = -1;
- }
-
- if(valuearray_isempty(vs->va))
- {
- /* No intersection */
- }
- else
- {
- int numberofvalues= valuearray_count(values);
- /*
- * determine whether we should use an AVL tree of values or not
- */
- if (numberofvalues==0)
- {
- /* No intersection */
- }
- else if ( numberofvalues > 1 )
- {
- /*
- * Several values to add: use an AVL tree to detect duplicates.
- */
- Avlnode *vtree = NULL;
- rc= valuetree_add_valuearray( a, vs->va, &vtree, duplicate_index );
- if(rc==LDAP_OPERATIONS_ERROR)
- {
- /* There were already duplicate values in the value set */
- }
- else
- {
- rc= valuetree_add_valuearray( a, values, &vtree, duplicate_index );
- /*
- * Returns LDAP_OPERATIONS_ERROR if something very bad happens.
- * Or LDAP_TYPE_OR_VALUE_EXISTS if a value already exists.
- */
- }
- valuetree_free( &vtree );
- }
- else
- {
- /*
- * One value to add: don't bother constructing
- * an AVL tree, etc. since it probably isn't worth the time.
- *
- * JCM - This is actually quite slow because the comparison function is looked up many times.
- */
- int i;
- for ( i = 0; rc == LDAP_SUCCESS && values[i] != NULL; ++i )
- {
- if(valuearray_find(a, vs->va, values[i])!=-1)
- {
- rc = LDAP_TYPE_OR_VALUE_EXISTS;
- *duplicate_index = i;
- break;
- }
- }
- }
- }
- return rc;
-}
-
Slapi_ValueSet *
valueset_dup(const Slapi_ValueSet *dupee)
{
- Slapi_ValueSet *duped= (Slapi_ValueSet *)slapi_ch_calloc(1,sizeof(Slapi_ValueSet));
+ Slapi_ValueSet *duped = slapi_valueset_new();
if (NULL!=duped)
{
- valueset_add_valuearray( duped, dupee->va );
+ valueset_set_valuearray_byval(duped,dupee->va);
}
return duped;
}
@@ -1381,43 +1308,53 @@ valueset_dup(const Slapi_ValueSet *dupee)
* : LDAP_OPERATIONS_ERROR - duplicated values given
*/
int
-valueset_replace(Slapi_Attr *a, Slapi_ValueSet *vs, Slapi_Value **valstoreplace)
+valueset_replace_valuearray(Slapi_Attr *a, Slapi_ValueSet *vs, Slapi_Value **valstoreplace)
+{
+ return (valueset_replace_valuearray_ext(a, vs,valstoreplace, 1));
+}
+int
+valueset_replace_valuearray_ext(Slapi_Attr *a, Slapi_ValueSet *vs, Slapi_Value **valstoreplace, int dupcheck)
{
int rc = LDAP_SUCCESS;
- int numberofvalstoreplace= valuearray_count(valstoreplace);
- /* verify the given values are not duplicated.
- if replacing with one value, no need to check. just replace it.
- */
- if (numberofvalstoreplace > 1)
- {
- Avlnode *vtree = NULL;
- rc = valuetree_add_valuearray( a, valstoreplace, &vtree, NULL );
- valuetree_free(&vtree);
- if ( LDAP_SUCCESS != rc &&
- /* bz 247413: don't override LDAP_TYPE_OR_VALUE_EXISTS */
- LDAP_TYPE_OR_VALUE_EXISTS != rc )
- {
- /* There were already duplicate values in the value set */
- rc = LDAP_OPERATIONS_ERROR;
- }
- }
-
- if ( rc == LDAP_SUCCESS )
- {
- /* values look good - replace the values in the attribute */
- if(!valuearray_isempty(vs->va))
- {
- /* remove old values */
- slapi_valueset_done(vs);
- }
- /* we now own valstoreplace */
- vs->va = valstoreplace;
- }
- else
- {
- /* caller expects us to own valstoreplace - since we cannot
- use them, just delete them */
- valuearray_free(&valstoreplace);
+ int vals_count = valuearray_count(valstoreplace);
+
+ if (vals_count == 0) {
+ /* no new values, just clear the valueset */
+ slapi_valueset_done(vs);
+ } else if (vals_count == 1 || !dupcheck) {
+ /* just repelace the valuearray and adjus num, max */
+ slapi_valueset_done(vs);
+ vs->va = valstoreplace;
+ vs->num = vals_count;
+ vs->max = vals_count + 1;
+ } else {
+ /* verify the given values are not duplicated. */
+ Slapi_ValueSet *vs_new = slapi_valueset_new();
+ rc = slapi_valueset_add_attr_valuearray_ext (a, vs_new, valstoreplace, vals_count, 0, NULL);
+
+ if ( rc == LDAP_SUCCESS )
+ {
+ /* values look good - replace the values in the attribute */
+ if(!valuearray_isempty(vs->va))
+ {
+ /* remove old values */
+ slapi_valueset_done(vs);
+ }
+ vs->va = vs_new->va;
+ vs_new->va = NULL;
+ vs->sorted = vs_new->sorted;
+ vs_new->sorted = NULL;
+ vs->num = vs_new->num;
+ vs->max = vs_new->max;
+ slapi_valueset_free (vs_new);
+ }
+ else
+ {
+ /* caller expects us to own valstoreplace - since we cannot
+ use them, just delete them */
+ slapi_valueset_free(vs_new);
+ valuearray_free(&valstoreplace);
+ }
}
return rc;
}
@@ -1439,50 +1376,35 @@ valueset_update_csn_for_valuearray_ext(Slapi_ValueSet *vs, const Slapi_Attr *a,
if(!valuearray_isempty(valuestoupdate) &&
!valuearray_isempty(vs->va))
{
- /*
- * determine whether we should use an AVL tree of values or not
- */
struct valuearrayfast vaf_valuesupdated;
- int numberofvaluestoupdate= valuearray_count(valuestoupdate);
valuearrayfast_init(&vaf_valuesupdated,*valuesupdated);
- if (numberofvaluestoupdate > 1) /* multiple values to update */
+ int i;
+ int del_index = -1, del_count = 0;
+ for (i=0;valuestoupdate[i]!=NULL;++i)
{
- int i;
- Avlnode *vtree = NULL;
- int rc= valuetree_add_valuearray( a, vs->va, &vtree, NULL );
- PR_ASSERT(rc==LDAP_SUCCESS);
- for (i=0;valuestoupdate[i]!=NULL;++i)
+ int index= valuearray_find(a, vs->va, valuestoupdate[i]);
+ if(index!=-1)
{
- int index= 0;
- rc = valuetree_find( a, valuestoupdate[i], vtree, &index );
- if(rc==LDAP_SUCCESS)
- {
- value_update_csn(vs->va[index],t,csn);
- if (csnref_updated)
- valuestoupdate[i]->v_csnset = (CSNSet *)value_get_csnset(vs->va[index]);
- valuearrayfast_add_value_passin(&vaf_valuesupdated,valuestoupdate[i]);
- valuestoupdate[i] = NULL;
- }
+ value_update_csn(vs->va[index],t,csn);
+ if (csnref_updated)
+ valuestoupdate[i]->v_csnset = (CSNSet *)value_get_csnset(vs->va[index]);
+ valuearrayfast_add_value_passin(&vaf_valuesupdated,valuestoupdate[i]);
+ valuestoupdate[i]= NULL;
+ del_count++;
+ if (del_index < 0) del_index = i;
}
- valuetree_free(&vtree);
- }
- else
- {
- int i;
- for (i=0;valuestoupdate[i]!=NULL;++i)
- {
- int index= valuearray_find(a, vs->va, valuestoupdate[i]);
- if(index!=-1)
- {
- value_update_csn(vs->va[index],t,csn);
- if (csnref_updated)
- valuestoupdate[i]->v_csnset = (CSNSet *)value_get_csnset(vs->va[index]);
- valuearrayfast_add_value_passin(&vaf_valuesupdated,valuestoupdate[i]);
- valuestoupdate[i]= NULL;
+ else
+ { /* keep the value in valuestoupdate, to keep array compressed, move to first free slot*/
+ if (del_index >= 0) {
+ valuestoupdate[del_index] = valuestoupdate[i];
+ del_index++;
}
}
}
- valuearray_compress(valuestoupdate,numberofvaluestoupdate);
+ /* complete compression */
+ for (i=0; i<del_count;i++)
+ valuestoupdate[del_index+i]= NULL;
+
*valuesupdated= vaf_valuesupdated.va;
}
}
10 years, 9 months