[389-commits] 2 commits - ldap/servers

Mark Reynolds mreynolds at fedoraproject.org
Wed May 16 14:29:30 UTC 2012


 ldap/servers/plugins/chainingdb/cb_instance.c    |  192 ++--
 ldap/servers/plugins/referint/referint.c         |  903 ++++++++++-------------
 ldap/servers/plugins/replication/repl5_plugins.c |    7 
 3 files changed, 527 insertions(+), 575 deletions(-)

New commits:
commit dc379838f8e4cfd2c736e8c2fb8366fb3b4f73d4
Author: Mark Reynolds <mareynol at redhat.com>
Date:   Fri May 11 13:00:50 2012 -0400

    Ticket 367 - Invalid chaining config triggers a disk full error and shutdown
    
    Bug Description:  If you use the root DN for the chaining bind DN a error -2 (LDAP_LOCAL_ERROR)
                      is returned from the callback.  This is the same error code for SLAPI_FAIL_DISKFULL.
                      Once the error -2 is retuned, the server thinks we are out of disk space and the
                      instance is shutdown.
    
    Fix Description:  Return -1, instead of -2(LDAP_LOCAL_ERROR)
    
    https://fedorahosted.org/389/ticket/367
    
    Note:  also did a little code cleanup with indentation
    
    Reviewed by:

diff --git a/ldap/servers/plugins/chainingdb/cb_instance.c b/ldap/servers/plugins/chainingdb/cb_instance.c
index 9a33916..8fb694a 100644
--- a/ldap/servers/plugins/chainingdb/cb_instance.c
+++ b/ldap/servers/plugins/chainingdb/cb_instance.c
@@ -511,15 +511,15 @@ int cb_instance_modify_config_callback(Slapi_PBlock *pb, Slapi_Entry* entryBefor
 */
 
 int
-cb_parse_instance_config_entry(cb_backend * cb, Slapi_Entry * e) {
-
-	int rc 			=LDAP_SUCCESS;
-        Slapi_Attr 		*attr = NULL;
-        Slapi_Value 		*sval;
-    	const struct berval 	*attrValue;
-	cb_backend_instance 	*inst=NULL;
-	char			*instname;
-	char 			retmsg[CB_BUFSIZE];
+cb_parse_instance_config_entry(cb_backend * cb, Slapi_Entry * e)
+{
+	cb_backend_instance *inst = NULL;
+	Slapi_Attr *attr = NULL;
+	Slapi_Value *sval;
+	const struct berval *attrValue;
+	char *instname;
+	char retmsg[CB_BUFSIZE];
+	int rc = LDAP_SUCCESS;
 
 	CB_ASSERT(e!=NULL);
 	
@@ -529,17 +529,17 @@ cb_parse_instance_config_entry(cb_backend * cb, Slapi_Entry * e) {
 	*/
 	
 	if ( 0 == slapi_entry_attr_find( e, CB_CONFIG_INSTNAME, &attr )) {
-    		slapi_attr_first_value(attr, &sval);
-    		attrValue = slapi_value_get_berval(sval);
-		instname=attrValue->bv_val;
+		slapi_attr_first_value(attr, &sval);
+		attrValue = slapi_value_get_berval(sval);
+		instname = attrValue->bv_val;
 	} else {
 		slapi_log_error( SLAPI_LOG_PLUGIN, CB_PLUGIN_SUBSYSTEM, 
 			"Malformed backend instance (<%s> missing)>\n", CB_CONFIG_INSTNAME); 
-		return LDAP_LOCAL_ERROR;
+		return -1;
 	}
 
-        /* Allocate a new backend internal data structure */
-        inst = cb_instance_alloc(cb,instname,slapi_entry_get_dn(e));
+	/* Allocate a new backend internal data structure */
+	inst = cb_instance_alloc(cb,instname,slapi_entry_get_dn(e));
 
 	/* Emulate a add config entry to configure */
 	/* this backend instance.		   */
@@ -556,99 +556,96 @@ cb_parse_instance_config_entry(cb_backend * cb, Slapi_Entry * e) {
 */
 
 static int 
-cb_instance_config_initialize(cb_backend_instance * inst, Slapi_Entry * e , int phase, int apply) {
-
-        int rc                  =LDAP_SUCCESS;
-        Slapi_Attr              *attr = NULL;
-        Slapi_Value             *sval;
-	struct berval * 	 bval;
-	int 			using_def_connlifetime,i;
-        char 			err_buf[SLAPI_DSE_RETURNTEXT_SIZE];
-	int 			urlfound=0;
-	char 			*rootdn;
+cb_instance_config_initialize(cb_backend_instance * inst, Slapi_Entry * e , int phase, int apply)
+{
+	Slapi_Attr *attr = NULL;
+	Slapi_Value *sval;
+	Slapi_DN *suffix;
+	struct berval *bval;
+	char err_buf[SLAPI_DSE_RETURNTEXT_SIZE];
+	char *attr_name = NULL;
+	char *rootdn;
+	int using_def_connlifetime, i;
+	int urlfound = 0;
+	int rc = LDAP_SUCCESS;
 
 	using_def_connlifetime=1;
 
-        for (slapi_entry_first_attr(e, &attr); attr; slapi_entry_next_attr(e, attr, &attr)) {
-		char * attr_name=NULL;	
-                slapi_attr_get_type(attr, &attr_name);
+	for (slapi_entry_first_attr(e, &attr); attr; slapi_entry_next_attr(e, attr, &attr)) {
+		attr_name = NULL;
+		slapi_attr_get_type(attr, &attr_name);
 
 		if ( !strcasecmp ( attr_name, CB_CONFIG_SUFFIX )) {
 			if (apply && ( inst->inst_be != NULL )) {
-  				Slapi_DN *suffix;
 				suffix = slapi_sdn_new();
-                        	i = slapi_attr_first_value(attr, &sval);
-                        	while (i != -1 ) {
-                                	bval = (struct berval *) slapi_value_get_berval(sval);
-                                	slapi_sdn_set_dn_byref(suffix, bval->bv_val);
-
-                                	if (!slapi_be_issuffix(inst->inst_be, suffix)) {
-                                        	slapi_be_addsuffix(inst->inst_be, suffix);
-                                	}
-                                	i = slapi_attr_next_value(attr, i, &sval);
-                        	}
+				i = slapi_attr_first_value(attr, &sval);
+				while (i != -1 ) {
+					bval = (struct berval *) slapi_value_get_berval(sval);
+					slapi_sdn_set_dn_byref(suffix, bval->bv_val);
+
+					if (!slapi_be_issuffix(inst->inst_be, suffix)) {
+							slapi_be_addsuffix(inst->inst_be, suffix);
+					}
+					i = slapi_attr_next_value(attr, i, &sval);
+				}
 				slapi_sdn_free(&suffix);
 			}
-                        continue;
-		} else
-		if ( !strcasecmp ( attr_name, CB_CONFIG_CHAINING_COMPONENTS )) {
-
-       			if (apply) {
-	                	slapi_rwlock_wrlock(inst->rwl_config_lock);
-                                i = slapi_attr_first_value(attr, &sval);
+			continue;
+		} else if ( !strcasecmp ( attr_name, CB_CONFIG_CHAINING_COMPONENTS )) {
+			if (apply) {
+				slapi_rwlock_wrlock(inst->rwl_config_lock);
+				i = slapi_attr_first_value(attr, &sval);
 				charray_free(inst->chaining_components);
 				inst->chaining_components=NULL;
-                                while (i != -1 ) {
-                                        bval = (struct berval *) slapi_value_get_berval(sval);
+				while (i != -1 ) {
+					bval = (struct berval *) slapi_value_get_berval(sval);
 					charray_add(&inst->chaining_components,
-						slapi_dn_normalize(slapi_ch_strdup(bval->bv_val)));
-                                        i = slapi_attr_next_value(attr, i, &sval);
-                                }
-	                	slapi_rwlock_unlock(inst->rwl_config_lock);
-                        }
-                        continue;
-		} else
-		if ( !strcasecmp ( attr_name, CB_CONFIG_ILLEGAL_ATTRS )) {
-
-       			if (apply) {
-	                	slapi_rwlock_wrlock(inst->rwl_config_lock);
-                                i = slapi_attr_first_value(attr, &sval);
+					slapi_dn_normalize(slapi_ch_strdup(bval->bv_val)));
+					i = slapi_attr_next_value(attr, i, &sval);
+				}
+				slapi_rwlock_unlock(inst->rwl_config_lock);
+			}
+			continue;
+		} else if ( !strcasecmp ( attr_name, CB_CONFIG_ILLEGAL_ATTRS )) {
+			if (apply) {
+				slapi_rwlock_wrlock(inst->rwl_config_lock);
+				i = slapi_attr_first_value(attr, &sval);
 				charray_free(inst->illegal_attributes);
 				inst->illegal_attributes=NULL;
-                                while (i != -1 ) {
-                                        bval = (struct berval *) slapi_value_get_berval(sval);
+				while (i != -1 ) {
+					bval = (struct berval *) slapi_value_get_berval(sval);
 					charray_add(&inst->illegal_attributes,
-						slapi_ch_strdup(bval->bv_val));
-                                        i = slapi_attr_next_value(attr, i, &sval);
-                                }
-	                	slapi_rwlock_unlock(inst->rwl_config_lock);
-                        }
-                        continue;
+					slapi_ch_strdup(bval->bv_val));
+					i = slapi_attr_next_value(attr, i, &sval);
+				}
+				slapi_rwlock_unlock(inst->rwl_config_lock);
+			}
+			continue;
 		}
 
 
 		if ( !strcasecmp ( attr_name, CB_CONFIG_HOSTURL )) {
 			urlfound=1;
 		}
-			
 
-      		/* We are assuming that each of these attributes are to have
-                 * only one value.  If they have more than one value, like
-                 * the nsslapd-suffix attribute, then they need to be
-                 * handled differently. */
+		/*
+		 * We are assuming that each of these attributes are to have
+		 * only one value.  If they have more than one value, like
+		 * the nsslapd-suffix attribute, then they need to be
+		 * handled differently.
+		 */
 
-                slapi_attr_first_value(attr, &sval);
-                bval = (struct berval *) slapi_value_get_berval(sval);
- 
-                if (cb_instance_config_set((void *) inst, attr_name, 
+		slapi_attr_first_value(attr, &sval);
+		bval = (struct berval *) slapi_value_get_berval(sval);
+
+		if (cb_instance_config_set((void *) inst, attr_name,
 			cb_the_instance_config, bval, err_buf, phase, apply ) != LDAP_SUCCESS) {
-                        slapi_log_error( SLAPI_LOG_FATAL, 
-				CB_PLUGIN_SUBSYSTEM,"Error with config attribute %s : %s\n",
+			slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM,"Error with config attribute %s : %s\n",
 				attr_name, err_buf);
-			rc=LDAP_LOCAL_ERROR;
-                        break;
-                }
-                if ( !strcasecmp ( attr_name, CB_CONFIG_CONNLIFETIME )) {
+			rc = -1;
+			break;
+		}
+		if ( !strcasecmp ( attr_name, CB_CONFIG_CONNLIFETIME )) {
 			using_def_connlifetime=0;
 		}
 	}
@@ -661,20 +658,17 @@ cb_instance_config_initialize(cb_backend_instance * inst, Slapi_Entry * e , int
 
 	if (LDAP_SUCCESS == rc) {
 		if (!urlfound) {
-       	 		slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM,
-			"Malformed backend instance entry. Mandatory attr <%s> missing\n",
-			CB_CONFIG_HOSTURL);
-			rc= LDAP_LOCAL_ERROR;
+			slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM,
+				"Malformed backend instance entry. Mandatory attr <%s> missing\n",CB_CONFIG_HOSTURL);
+			rc = -1;
 		}
 
 		if (apply ) {
-    			if ( using_def_connlifetime &&
-                		strchr( inst->pool->hostname, ' ' ) != NULL ) {
-
-                		cb_instance_config_set((void *)inst, CB_CONFIG_CONNLIFETIME, 
-				cb_the_instance_config, NULL /* use default */, err_buf, 
+    		if ( using_def_connlifetime && strchr( inst->pool->hostname, ' ' ) != NULL ) {
+    			cb_instance_config_set((void *)inst, CB_CONFIG_CONNLIFETIME,
+    			cb_the_instance_config, NULL /* use default */, err_buf,
 					CB_CONFIG_PHASE_INITIALIZATION, 1 );
-        		}
+    		}
 		}
 	}
 
@@ -683,15 +677,13 @@ cb_instance_config_initialize(cb_backend_instance * inst, Slapi_Entry * e , int
 	** It is forbidden to use directory manager as proxy user
 	** due to a bug in the acl check
 	*/
-
-	rootdn=cb_get_rootdn();
+	rootdn = cb_get_rootdn();
 
 	if (inst->impersonate && inst->pool && inst->pool->binddn && 
 		!strcmp(inst->pool->binddn,rootdn)) {	/* UTF8 aware */
-                slapi_log_error( SLAPI_LOG_FATAL,
-                	CB_PLUGIN_SUBSYSTEM,"Error with config attribute %s (%s: forbidden value)\n",
-                                CB_CONFIG_BINDUSER, rootdn);
-                        rc=LDAP_LOCAL_ERROR;
+		slapi_log_error( SLAPI_LOG_FATAL, CB_PLUGIN_SUBSYSTEM,
+			"Error with config attribute %s (%s: forbidden value)\n", CB_CONFIG_BINDUSER, rootdn);
+		rc= -1;
 	}
 	slapi_ch_free((void **)&rootdn);
 
@@ -1494,7 +1486,7 @@ struct berval *bval, char *err_buf, int phase, int apply_mod)
         int use_default;
         int int_val;
         long long_val;
-        int retval=LDAP_LOCAL_ERROR;
+        int retval = -1;
 
         config = cb_get_config_info(config_array, attr_name);
         if (NULL == config) {


commit 162f41da35a88cfe5f8b49d8f182eb33c27be579
Author: Mark Reynolds <mareynol at redhat.com>
Date:   Thu May 10 14:30:44 2012 -0400

    Ticket #218 - Make RI Plugin worked with replicated updates
    
    Bug Description:  If a user is deleted from AD (or a master not using RI Plugin),
                      the operation comes in as a replicated op, and RI aborts its
                      processing.
    
    Fix Description:  Added a new config attribute to the plugin "nsslapd-pluginAllowReplUpdates: on".
                      We check for this setting at startup and set a flag.  We then allow these
                      operations, and we also attach OP_FLAG_REPLICATED flag to pblock for
                      slapi_modify_internal().
    
    Side note:        Cleaned up all the indentation/comments in referint.c
    
    https://fedorahosted.org/389/ticket/218
    
    reviewed by:

diff --git a/ldap/servers/plugins/referint/referint.c b/ldap/servers/plugins/referint/referint.c
index e8d4ead..266a7d1 100644
--- a/ldap/servers/plugins/referint/referint.c
+++ b/ldap/servers/plugins/referint/referint.c
@@ -58,15 +58,13 @@
 #include <sys/stat.h>
 #endif
 
-#define REFERINT_PLUGIN_SUBSYSTEM   "referint-plugin"   /* used for logging */
-
 #ifdef _WIN32
 #define REFERINT_DEFAULT_FILE_MODE	0
 #else
 #define REFERINT_DEFAULT_FILE_MODE S_IRUSR | S_IWUSR
 #endif
 
-
+#define REFERINT_PLUGIN_SUBSYSTEM   "referint-plugin"   /* used for logging */
 #define MAX_LINE 2048
 #define READ_BUFSIZE  4096
 #define MY_EOF   0 
@@ -78,23 +76,21 @@ int referint_postop_modrdn( Slapi_PBlock *pb );
 int referint_postop_start( Slapi_PBlock *pb);
 int referint_postop_close( Slapi_PBlock *pb);
 int update_integrity(char **argv, Slapi_DN *sDN, char *newrDN, Slapi_DN *newsuperior, int logChanges);
-void referint_thread_func(void *arg);
-int  GetNextLine(char *dest, int size_dest, PRFileDesc *stream);
-void writeintegritylog(Slapi_PBlock *pb, char *logfilename, Slapi_DN *sdn, char *newrdn, Slapi_DN *newsuperior, Slapi_DN *requestorsdn);
+int GetNextLine(char *dest, int size_dest, PRFileDesc *stream);
 int my_fgetc(PRFileDesc *stream);
+void referint_thread_func(void *arg);
+void writeintegritylog(Slapi_PBlock *pb, char *logfilename, Slapi_DN *sdn, char *newrdn,
+    Slapi_DN *newsuperior, Slapi_DN *requestorsdn);
 
 /* global thread control stuff */
-
 static PRLock 		*referint_mutex = NULL;       
 static PRThread		*referint_tid = NULL;
+static PRLock 		*keeprunning_mutex = NULL;
+static PRCondVar    *keeprunning_cv = NULL;
 int keeprunning = 0;
 
-static PRLock 		*keeprunning_mutex = NULL; 
-static PRCondVar        *keeprunning_cv = NULL; 
-
-static Slapi_PluginDesc pdesc = { "referint", VENDOR, DS_PACKAGE_VERSION,
-	"referential integrity plugin" };
-
+static Slapi_PluginDesc pdesc = { "referint", VENDOR, DS_PACKAGE_VERSION, "referential integrity plugin" };
+static int allow_repl = 0;
 static void* referint_plugin_identity = NULL;
 
 #ifdef _WIN32
@@ -109,221 +105,213 @@ void plugin_init_debug_level(int *level_ptr)
 int
 referint_postop_init( Slapi_PBlock *pb )
 {
-	Slapi_Entry *plugin_entry = NULL;
-	char *plugin_type = NULL;
-	int delfn = SLAPI_PLUGIN_POST_DELETE_FN;
-	int mdnfn = SLAPI_PLUGIN_POST_MODRDN_FN;
-
-	/*
-	 * Get plugin identity and stored it for later use
-	 * Used for internal operations
-	 */
-
-    	slapi_pblock_get (pb, SLAPI_PLUGIN_IDENTITY, &referint_plugin_identity);
-    	PR_ASSERT (referint_plugin_identity);
-
-	/* get args */ 
-	if ((slapi_pblock_get(pb, SLAPI_PLUGIN_CONFIG_ENTRY, &plugin_entry) == 0) &&
-		plugin_entry &&
-		(plugin_type = slapi_entry_attr_get_charptr(plugin_entry, "nsslapd-plugintype")) &&
-		plugin_type && strstr(plugin_type, "betxn")) {
-		delfn = SLAPI_PLUGIN_BE_TXN_POST_DELETE_FN;
-		mdnfn = SLAPI_PLUGIN_BE_TXN_POST_MODRDN_FN;
-	}
-	slapi_ch_free_string(&plugin_type);
-
-	if ( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION,
-	    			SLAPI_PLUGIN_VERSION_01 ) != 0 ||
-	  slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION,
-                     (void *)&pdesc ) != 0 ||
-         slapi_pblock_set( pb, delfn,
-                     (void *) referint_postop_del ) != 0 ||
-         slapi_pblock_set( pb, mdnfn,
-                     (void *) referint_postop_modrdn ) != 0 ||
-         slapi_pblock_set(pb, SLAPI_PLUGIN_START_FN,
-        	         (void *) referint_postop_start ) != 0 ||
-	     slapi_pblock_set(pb, SLAPI_PLUGIN_CLOSE_FN,
-			         (void *) referint_postop_close ) != 0)
-        {
-            slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
-                             "referint_postop_init failed\n" );
-            return( -1 );
+    Slapi_Entry *plugin_entry = NULL;
+    char *plugin_type = NULL;
+    int delfn = SLAPI_PLUGIN_POST_DELETE_FN;
+    int mdnfn = SLAPI_PLUGIN_POST_MODRDN_FN;
+
+    /*
+     *  Get plugin identity and stored it for later use.
+     *  Used for internal operations.
+     */
+    slapi_pblock_get (pb, SLAPI_PLUGIN_IDENTITY, &referint_plugin_identity);
+    PR_ASSERT (referint_plugin_identity);
+
+    /* get the args */
+    if ((slapi_pblock_get(pb, SLAPI_PLUGIN_CONFIG_ENTRY, &plugin_entry) == 0) &&
+         plugin_entry &&
+         (plugin_type = slapi_entry_attr_get_charptr(plugin_entry, "nsslapd-plugintype")) &&
+         plugin_type && strstr(plugin_type, "betxn"))
+    {
+        delfn = SLAPI_PLUGIN_BE_TXN_POST_DELETE_FN;
+        mdnfn = SLAPI_PLUGIN_BE_TXN_POST_MODRDN_FN;
+    }
+    if(plugin_entry){
+        char *allow_repl_updates;
+
+        allow_repl_updates = slapi_entry_attr_get_charptr(plugin_entry, "nsslapd-pluginAllowReplUpdates");
+        if(allow_repl_updates && strcasecmp(allow_repl_updates,"on")==0){
+            allow_repl = 1;
         }
+        slapi_ch_free_string(&allow_repl_updates);
+    }
+    slapi_ch_free_string(&plugin_type);
+
+    if ( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 ) != 0 ||
+         slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&pdesc ) != 0 ||
+         slapi_pblock_set( pb, delfn, (void *) referint_postop_del ) != 0 ||
+         slapi_pblock_set( pb, mdnfn, (void *) referint_postop_modrdn ) != 0 ||
+         slapi_pblock_set( pb, SLAPI_PLUGIN_START_FN, (void *) referint_postop_start ) != 0 ||
+         slapi_pblock_set( pb, SLAPI_PLUGIN_CLOSE_FN, (void *) referint_postop_close ) != 0)
+    {
+        slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM, "referint_postop_init failed\n" );
+        return( -1 );
+    }
 
-        return( 0 );
+    return( 0 );
 }
 
 
 int
 referint_postop_del( Slapi_PBlock *pb )
 {
-	Slapi_DN *sdn = NULL;
-	int rc;
-	int oprc;
-	char **argv;
-	int argc;
-	int delay;
-	int logChanges=0;
-	int isrepop = 0;
-
-	if ( slapi_pblock_get( pb, SLAPI_IS_REPLICATED_OPERATION, &isrepop ) != 0  ||
-	     slapi_pblock_get( pb, SLAPI_DELETE_TARGET_SDN, &sdn ) != 0  ||
-	     slapi_pblock_get(pb, SLAPI_PLUGIN_OPRETURN, &oprc) != 0) 
-        {
-            slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
-                             "referint_postop_del: could not get parameters\n" );
-            return( -1 );
-        }
+    Slapi_DN *sdn = NULL;
+    char **argv;
+    int argc;
+    int delay;
+    int logChanges=0;
+    int isrepop = 0;
+    int oprc;
+    int rc;
 
-        /* this plugin should only execute if the delete was successful
-		   and this is not a replicated op
-	    */
-        if(oprc != 0 || isrepop)
-        {
-            return( 0 );
-        }
-	/* get 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 ); 
-	} 
-	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 ); 
-	} 
+    if ( slapi_pblock_get( pb, SLAPI_IS_REPLICATED_OPERATION, &isrepop ) != 0  ||
+         slapi_pblock_get( pb, SLAPI_DELETE_TARGET_SDN, &sdn ) != 0  ||
+         slapi_pblock_get(pb, SLAPI_PLUGIN_OPRETURN, &oprc) != 0)
+    {
+        slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
+            "referint_postop_del: could not get parameters\n" );
+        return( -1 );
+    }
+    /*
+     *  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 );
+    }
+    /* 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 );
+    }
+    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 );
+    }
 	
-	if(argv == NULL){
-	  slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
-		     "referint_postop_modrdn, args are NULL\n" );
-	  return( -1 ); 
-	}
+    if(argv == NULL){
+        slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
+            "referint_postop_modrdn, args are NULL\n" );
+        return( -1 );
+    }
 	
-	if (argc >= 3) {
-		/* argv[0] will be the delay */
-		delay = atoi(argv[0]);
-
-		/* argv[2] will be wether or not to log changes */
-		logChanges = atoi(argv[2]);
-
-		if(delay == -1){
-		  /* integrity updating is off */
-		  rc = 0;
-		}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;
-		}
-	} else {
-		slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
-		     "referint_postop insufficient arguments supplied\n" );
-		return( -1 ); 
-	}
-
-	return( rc );
+    if (argc >= 3) {
+        /* argv[0] will be the delay */
+        delay = atoi(argv[0]);
+
+        /* argv[2] will be wether or not to log changes */
+        logChanges = atoi(argv[2]);
+
+        if(delay == -1){
+            /* integrity updating is off */
+            rc = 0;
+        } 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;
+        }
+    } else {
+        slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
+            "referint_postop insufficient arguments supplied\n" );
+        return( -1 );
+    }
 
+    return( rc );
 }
 
 int
 referint_postop_modrdn( Slapi_PBlock *pb )
 {
-	Slapi_DN *sdn = NULL;
-	char	*newrdn;
-	Slapi_DN *newsuperior;
-	int oprc;
-	int rc;
-	char **argv;
-	int argc = 0;
-	int delay;
-	int logChanges=0;
-	int isrepop = 0;
-
-	if ( slapi_pblock_get( pb, SLAPI_IS_REPLICATED_OPERATION, &isrepop ) != 0  ||
-		 slapi_pblock_get( pb, SLAPI_MODRDN_TARGET_SDN, &sdn ) != 0 ||
-		 slapi_pblock_get( pb, SLAPI_MODRDN_NEWRDN, &newrdn ) != 0 ||
-		 slapi_pblock_get( pb, SLAPI_MODRDN_NEWSUPERIOR_SDN, &newsuperior ) != 0 ||
-		 slapi_pblock_get(pb, SLAPI_PLUGIN_OPRETURN, &oprc) != 0 ){
-
-		slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
-		    "referint_postop_modrdn: could not get parameters\n" );
-		return( -1 );
-	}
-
-	/* this plugin should only execute if the delete was successful 
-	   and this is not a replicated op
-	*/
-	if(oprc != 0 || isrepop){
-	  return( 0 );
-	}
-	/* get 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 ); 
-	} 
-	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 ); 
-	} 
-	
-	if(argv == NULL){
-	  slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
-		     "referint_postop_modrdn, args are NULL\n" ); 
-	  return( -1 ); 
-	}
-
-	if (argc >= 3) {
-		/* argv[0] will always be the delay */
-		delay = atoi(argv[0]);
-
-		/* argv[2] will be wether or not to log changes */
-		logChanges = atoi(argv[2]);
-	} else {
-		slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
-		     "referint_postop_modrdn insufficient arguments supplied\n" );
-		return( -1 ); 
-	}
-
-	if(delay == -1){
-	  /* integrity updating is off */
-	  rc = 0;
-	}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;
-	}
-
-	return( rc );
+    Slapi_DN *sdn = NULL;
+    Slapi_DN *newsuperior;
+    char *newrdn;
+    char **argv;
+    int oprc;
+    int rc;
+    int argc = 0;
+    int delay;
+    int logChanges=0;
+    int isrepop = 0;
+
+    if ( slapi_pblock_get( pb, SLAPI_IS_REPLICATED_OPERATION, &isrepop ) != 0  ||
+         slapi_pblock_get( pb, SLAPI_MODRDN_TARGET_SDN, &sdn ) != 0 ||
+         slapi_pblock_get( pb, SLAPI_MODRDN_NEWRDN, &newrdn ) != 0 ||
+         slapi_pblock_get( pb, SLAPI_MODRDN_NEWSUPERIOR_SDN, &newsuperior ) != 0 ||
+         slapi_pblock_get( pb, SLAPI_PLUGIN_OPRETURN, &oprc) != 0 )
+    {
+        slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
+            "referint_postop_modrdn: could not get parameters\n" );
+        return( -1 );
+    }
+    /*
+     *  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 );
+    }
+    /* 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 );
+    }
+    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 );
+    }
+    if(argv == NULL){
+        slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
+            "referint_postop_modrdn, args are NULL\n" );
+        return( -1 );
+    }
+
+    if (argc >= 3) {
+        /* argv[0] will always be the delay */
+        delay = atoi(argv[0]);
+
+        /* argv[2] will be wether or not to log changes */
+        logChanges = atoi(argv[2]);
+    } else {
+        slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
+            "referint_postop_modrdn insufficient arguments supplied\n" );
+        return( -1 );
+    }
+
+    if(delay == -1){
+        /* integrity updating is off */
+        rc = 0;
+    } 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;
+    }
+
+    return( rc );
 }
 
 int isFatalSearchError(int search_result)
 {
-
     /*   Make sure search result is fatal 
      *   Some conditions that happen quite often are not fatal 
      *   for example if you have two suffixes and one is null, you will always
-     *   get no such object, howerever this is not a fatal error. 
+     *   get no such object, however this is not a fatal error.
      *   Add other conditions to the if statement as they are found
      */
-
-	/* NPCTE fix for bugid 531225, esc 0. <P.R> <30-May-2001> */
-	switch(search_result) {
-		case LDAP_REFERRAL: 
-		case LDAP_NO_SUCH_OBJECT: return 0 ;
-	}
-	return 1;
-	 /* end of NPCTE fix for bugid 531225 */
-
+    switch(search_result) {
+        case LDAP_REFERRAL:
+        case LDAP_NO_SUCH_OBJECT: return 0 ;
+    }
+    return 1;
 }
 
 static int
@@ -333,9 +321,14 @@ _do_modify(Slapi_PBlock *mod_pb, Slapi_DN *entrySDN, LDAPMod **mods)
 
     slapi_pblock_init(mod_pb);
 
-    /* Use internal operation API */
-    slapi_modify_internal_set_pb_ext(mod_pb, entrySDN, mods, NULL, NULL,
-                                     referint_plugin_identity, 0);
+    if(allow_repl){
+    	/* Must set as a replicated operation */
+    	slapi_modify_internal_set_pb_ext(mod_pb, entrySDN, mods, NULL, NULL,
+                                         referint_plugin_identity, OP_FLAG_REPLICATED);
+    } else {
+    	slapi_modify_internal_set_pb_ext(mod_pb, entrySDN, mods, NULL, NULL,
+                                         referint_plugin_identity, 0);
+    }
     slapi_modify_internal_pb(mod_pb);
     slapi_pblock_get(mod_pb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
     
@@ -354,6 +347,7 @@ _update_one_per_mod(Slapi_DN *entrySDN,      /* DN of the searched entry */
                     const char *newsuperior, /* new superior from modrdn */
                     Slapi_PBlock *mod_pb)
 {
+    LDAPMod attribute1, attribute2;
     LDAPMod *list_of_mods[3];
     char *values_del[2];
     char *values_add[2];
@@ -361,7 +355,8 @@ _update_one_per_mod(Slapi_DN *entrySDN,      /* DN of the searched entry */
     char **dnParts = NULL;
     char *sval = NULL;
     char *newvalue = NULL;
-    LDAPMod attribute1, attribute2;
+    char *p = NULL;
+    size_t dnlen = 0;
     int rc = 0;
 
     if (NULL == newRDN && NULL == newsuperior) {
@@ -431,11 +426,11 @@ _update_one_per_mod(Slapi_DN *entrySDN,      /* DN of the searched entry */
          * member: uid=A,ou=B,ou=C --> uid=A,ou=B',ou=C
          *         (sval)              (sval' + newDN)
          */
-        for (nval = slapi_attr_first_value(attr, &v);
-             nval != -1;
+        for (nval = slapi_attr_first_value(attr, &v); nval != -1;
              nval = slapi_attr_next_value(attr, nval, &v)) {
-            char *p = NULL;
-            size_t dnlen = 0;
+            p = NULL;
+            dnlen = 0;
+
             /* DN syntax, which should be a string */
             sval = slapi_ch_strdup(slapi_value_get_string(v));
             rc = slapi_dn_normalize_case_ext(sval, 0,  &p, &dnlen);
@@ -536,6 +531,8 @@ _update_all_per_mod(Slapi_DN *entrySDN,      /* DN of the searched entry */
     char **dnParts = NULL;
     char *sval = NULL;
     char *newvalue = NULL;
+    char *p = NULL;
+    size_t dnlen = 0;
     int rc = 0;
     int nval = 0;
 
@@ -619,8 +616,9 @@ _update_all_per_mod(Slapi_DN *entrySDN,      /* DN of the searched entry */
         for (nval = slapi_attr_first_value(attr, &v);
              nval != -1;
              nval = slapi_attr_next_value(attr, nval, &v)) {
-            char *p = NULL;
-            size_t dnlen = 0;
+            p = NULL;
+            dnlen = 0;
+
             /* DN syntax, which should be a string */
             sval = slapi_ch_strdup(slapi_value_get_string(v));
             rc = slapi_dn_normalize_case_ext(sval, 0,  &p, &dnlen);
@@ -665,6 +663,7 @@ _update_all_per_mod(Slapi_DN *entrySDN,      /* DN of the searched entry */
         slapi_ch_free_string(&newDN);
         slapi_mods_free(&smods);
     }
+
 bail:
     return rc;
 }
@@ -677,25 +676,30 @@ update_integrity(char **argv, Slapi_DN *origSDN,
     Slapi_PBlock *search_result_pb = NULL;
     Slapi_PBlock *mod_pb = slapi_pblock_new();
     Slapi_Entry  **search_entries = NULL;
-    int search_result;
     Slapi_DN *sdn = NULL;
+    Slapi_Attr *attr = NULL;
     void *node = NULL;
+    const char *origDN = slapi_sdn_get_dn(origSDN);
+    const char *search_base = NULL;
+    char *attrName = NULL;
     char *filter = NULL;
+    char *attrs[2];
+    size_t len = slapi_sdn_get_ndn_len(origSDN);
+    int search_result;
+    int nval = 0;
     int i, j;
-    const char *search_base = NULL;
     int rc;
-    size_t len = slapi_sdn_get_ndn_len(origSDN);
-    const char *origDN = slapi_sdn_get_dn(origSDN);
-   
-    if ( argv == NULL ) {
+
+    if ( argv == NULL ){
         slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
             "referint_postop required config file arguments missing\n" );
         rc = -1;
         goto free_and_return;
     } 
-  
-    /* for now, just putting attributes to keep integrity on in conf file,
-       until resolve the other timing mode issue */
+    /*
+     *  For now, just putting attributes to keep integrity on in conf file,
+     *  until resolve the other timing mode issue
+     */
     search_result_pb = slapi_pblock_new();
 
     /* Search each namingContext in turn */
@@ -704,14 +708,12 @@ update_integrity(char **argv, Slapi_DN *origSDN,
     {
         search_base = slapi_sdn_get_dn( sdn );
 
-        for(i = 3; argv[i] != NULL; i++)
-        {
+        for(i = 3; argv[i] != NULL; i++){
             char buf[BUFSIZ];
             filter = slapi_ch_smprintf("(%s=*%s)", argv[i],
                                     escape_filter_value(origDN, len, buf));
             if ( filter ) {
                 /* Need only the current attribute and its subtypes */
-                char *attrs[2];
                 attrs[0] = argv[i];
                 attrs[1] = NULL;
 
@@ -722,35 +724,34 @@ update_integrity(char **argv, Slapi_DN *origSDN,
                     NULL, NULL, referint_plugin_identity, 0);
                 slapi_search_internal_pb(search_result_pb);
   
-                slapi_pblock_get( search_result_pb, SLAPI_PLUGIN_INTOP_RESULT, 
-                                  &search_result);
+                slapi_pblock_get( search_result_pb, SLAPI_PLUGIN_INTOP_RESULT, &search_result);
 
                 /* if search successfull then do integrity update */
                 if(search_result == LDAP_SUCCESS)
                 {
-                    slapi_pblock_get(search_result_pb,
-                                     SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES,
+                    slapi_pblock_get(search_result_pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES,
                                      &search_entries);
 
-                    for(j=0; search_entries[j] != NULL; j++)
-                    {
-                        Slapi_Attr *attr = NULL;
-                        char *attrName = NULL;
-
-                        /* Loop over all the attributes of the entry and search
-                         * for the integrity attribute and its subtypes */
+                    for(j = 0; search_entries[j] != NULL; j++){
+                        attr = NULL;
+                        attrName = NULL;
+                        /*
+                         *  Loop over all the attributes of the entry and search
+                         *  for the integrity attribute and its subtypes
+                         */
                         for (slapi_entry_first_attr(search_entries[j], &attr); attr; 
                              slapi_entry_next_attr(search_entries[j], attr, &attr))
                         {
-                            /* Take into account only the subtypes of the attribute 
-                             * in argv[i] having the necessary value  - origDN */
+                            /*
+                             *  Take into account only the subtypes of the attribute
+                             *  in argv[i] having the necessary value  - origDN
+                             */
                             slapi_attr_get_type(attr, &attrName);
                             if (slapi_attr_type_cmp(argv[i], attrName,
                                                     SLAPI_TYPE_CMP_SUBTYPE) == 0)
                             {
-                                int nval = 0;
+                                nval = 0;
                                 slapi_attr_get_numvalues(attr, &nval);
-
                                 /* 
                                  * We want to reduce the "modify" call as much as
                                  * possible. But if an entry contains 1000s of 
@@ -781,21 +782,16 @@ update_integrity(char **argv, Slapi_DN *origSDN,
                         }
                     }
                 } else {
-                    if (isFatalSearchError(search_result))
-                    {
-                        /* NPCTE fix for bugid 531225, esc 0. <P.R> <30-May-2001> */
+                    if (isFatalSearchError(search_result)){
                         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);
-                        /* end of NPCTE fix for bugid 531225 */
                         rc = -1;
                         goto free_and_return;
                     }
                 }
-
                 slapi_ch_free_string(&filter);
             }
-  
             slapi_free_search_results_internal(search_result_pb);
         }
     }
@@ -817,221 +813,197 @@ free_and_return:
 
 int referint_postop_start( Slapi_PBlock *pb)
 {
-
     char **argv;
-	int argc = 0;
+    int argc = 0;
  
     /* get 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 ); 
+        slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
+            "referint_postop failed to get argv\n" );
+        return( -1 );
     } 
     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 ); 
+        slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
+            "referint_postop failed to get argv\n" );
+        return( -1 );
     } 
-
     if(argv == NULL){
         slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
-		  "args were null in referint_postop_start\n" );
-	return( -1  );
+            "args were null in referint_postop_start\n" );
+        return( -1  );
     }
-
-    /* only bother to start the thread if you are in delay mode. 
-       0  = no delay,
-       -1 = integrity off */
-
-	if (argc >= 1) {
-		if(atoi(argv[0]) > 0){
-
-		  /* initialize  cv and lock */
-			 
-		  referint_mutex = PR_NewLock();
-		  keeprunning_mutex = PR_NewLock();
-		  keeprunning_cv = PR_NewCondVar(keeprunning_mutex);
-		  keeprunning =1;
+    /*
+     *  Only bother to start the thread if you are in delay mode.
+     *     0  = no delay,
+     *     -1 = integrity off
+     */
+    if (argc >= 1) {
+        if(atoi(argv[0]) > 0){
+            /* initialize the cv and lock */
+            referint_mutex = PR_NewLock();
+            keeprunning_mutex = PR_NewLock();
+            keeprunning_cv = PR_NewCondVar(keeprunning_mutex);
+            keeprunning =1;
 			
-		  referint_tid = PR_CreateThread (PR_USER_THREAD, 
-							referint_thread_func, 
-							(void *)argv,
-							PR_PRIORITY_NORMAL, 
-							PR_GLOBAL_THREAD, 
-							PR_UNJOINABLE_THREAD, 
-							SLAPD_DEFAULT_THREAD_STACKSIZE);
-		  if ( referint_tid == NULL ) {
-			slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
-				   "referint_postop_start PR_CreateThread failed\n" );
-			exit( 1 );
-		  }
-		}
-	} else {
-		slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
-		     "referint_postop_start insufficient arguments supplied\n" );
-		return( -1 ); 
-	}
+            referint_tid = PR_CreateThread (PR_USER_THREAD,
+                               referint_thread_func,
+                               (void *)argv,
+                               PR_PRIORITY_NORMAL,
+                               PR_GLOBAL_THREAD,
+                               PR_UNJOINABLE_THREAD,
+                               SLAPD_DEFAULT_THREAD_STACKSIZE);
+            if ( referint_tid == NULL ) {
+                slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
+                    "referint_postop_start PR_CreateThread failed\n" );
+                exit( 1 );
+            }
+        }
+    } else {
+        slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
+            "referint_postop_start insufficient arguments supplied\n" );
+        return( -1 );
+    }
 
     return(0);
-
 }
 
 int referint_postop_close( Slapi_PBlock *pb)
 {
+    /* signal the thread to exit */
+    if (NULL != keeprunning_mutex) {
+        PR_Lock(keeprunning_mutex);
+        keeprunning=0;
+        if (NULL != keeprunning_cv) {
+            PR_NotifyCondVar(keeprunning_cv);
+        }
+        PR_Unlock(keeprunning_mutex);
+    }
 
-	/* signal the thread to exit */
-	if (NULL != keeprunning_mutex) {
-		PR_Lock(keeprunning_mutex);  
-		keeprunning=0;
-		if (NULL != keeprunning_cv) {
-			PR_NotifyCondVar(keeprunning_cv);
-		}
-		PR_Unlock(keeprunning_mutex);  
-	}
-
-	return(0);
+    return(0);
 }
 
 void
 referint_thread_func(void *arg)
 {
-    char **plugin_argv = (char **)arg;
     PRFileDesc *prfd;
+    char **plugin_argv = (char **)arg;
     char *logfilename;
     char thisline[MAX_LINE];
-    int delay;
-    int no_changes;
     char delimiter[]="\t\n";
     char *ptoken;
-	Slapi_DN *sdn = NULL;
     char *tmprdn;
+    char *iter = NULL;
+    Slapi_DN *sdn = NULL;
     Slapi_DN *tmpsuperior = NULL;
-    int logChanges=0;
-	char * iter = NULL;
+    int logChanges = 0;
+    int delay;
+    int no_changes;
 
     if(plugin_argv == NULL){
-      slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
-		 "referint_thread_func not get args \n" );
-      return;
+        slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
+            "referint_thread_func not get args \n" );
+        return;
     }
 
-    /* initialize the thread data index
-    if(slapi_td_dn_init()){
-    	slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,"Failed to create thread data index\n");
-
-    } */
-
     delay = atoi(plugin_argv[0]);
     logfilename = plugin_argv[1]; 
-	logChanges = atoi(plugin_argv[2]);
-
-    /* keep running this thread until plugin is signalled to close */
-
+    logChanges = atoi(plugin_argv[2]);
+    /*
+     * keep running this thread until plugin is signaled to close
+     */
     while(1){ 
-
         no_changes=1;
-
         while(no_changes){
-
-	    PR_Lock(keeprunning_mutex);
-	    if(keeprunning == 0){
-	        PR_Unlock(keeprunning_mutex);  
-	       break;
-	    }
-	    PR_Unlock(keeprunning_mutex);  
-
-
-	    PR_Lock(referint_mutex);
-        if (( prfd = PR_Open( logfilename, PR_RDONLY,
-	                          REFERINT_DEFAULT_FILE_MODE )) == NULL ) 
-        {
-            PR_Unlock(referint_mutex);	
-            /* go back to sleep and wait for this file */
-  	        PR_Lock(keeprunning_mutex);
-            PR_WaitCondVar(keeprunning_cv, PR_SecondsToInterval(delay));
+            PR_Lock(keeprunning_mutex);
+            if(keeprunning == 0){
+                PR_Unlock(keeprunning_mutex);
+                break;
+            }
             PR_Unlock(keeprunning_mutex);
-	    }else{
-	        no_changes = 0;
-	    }
-	}
-
-	/* check keep running here, because after break out of no
-	 * changes loop on shutdown, also need to break out of this
-	 * loop before trying to do the changes. The server
-	 * will pick them up on next startup as file still exists 
-	 */
+
+            PR_Lock(referint_mutex);
+            if (( prfd = PR_Open( logfilename, PR_RDONLY, REFERINT_DEFAULT_FILE_MODE )) == NULL ){
+                PR_Unlock(referint_mutex);
+                /* go back to sleep and wait for this file */
+                PR_Lock(keeprunning_mutex);
+                PR_WaitCondVar(keeprunning_cv, PR_SecondsToInterval(delay));
+                PR_Unlock(keeprunning_mutex);
+            } else {
+                no_changes = 0;
+            }
+        }
+        /*
+         *  Check keep running here, because after break out of no
+         *  changes loop on shutdown, also need to break out of this
+         *  loop before trying to do the changes. The server
+         *  will pick them up on next startup as file still exists
+         */
         PR_Lock(keeprunning_mutex);
         if(keeprunning == 0){
-	    PR_Unlock(keeprunning_mutex);  
-	    break;
+            PR_Unlock(keeprunning_mutex);
+            break;
         }
         PR_Unlock(keeprunning_mutex);  
-    
-  
-	while( GetNextLine(thisline, MAX_LINE, prfd) ){
-	    ptoken = ldap_utf8strtok_r(thisline, delimiter, &iter);
-		sdn = slapi_sdn_new_normdn_byref(ptoken);
-
-	    ptoken = ldap_utf8strtok_r (NULL, delimiter, &iter);
-	    if(!strcasecmp(ptoken, "NULL")) {
-	        tmprdn = NULL;
-	    } else {
-	        tmprdn = slapi_ch_smprintf("%s", ptoken);
-	    }
-
-	    ptoken = ldap_utf8strtok_r (NULL, delimiter, &iter);
-	    if (!strcasecmp(ptoken, "NULL")) {
-	        tmpsuperior = NULL;
-	    } else {
-	        tmpsuperior = slapi_sdn_new_normdn_byref(ptoken);
-	    }
-	    ptoken = ldap_utf8strtok_r (NULL, delimiter, &iter);
-	    if (strcasecmp(ptoken, "NULL") != 0) {
-	    	/* Set the bind DN in the thread data */
-	        if(slapi_td_set_dn(slapi_ch_strdup(ptoken))){
-	        	slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,"Failed to set thread data\n");
-	        }
-	    }
-      
-	    update_integrity(plugin_argv, sdn, tmprdn,
-	                     tmpsuperior, logChanges);
-      
-	    slapi_sdn_free(&sdn);
-	    slapi_ch_free_string(&tmprdn);
-	    slapi_sdn_free(&tmpsuperior);
-	}
-
-	PR_Close(prfd);
-      
-    /* remove the original file */
-    if( PR_SUCCESS != PR_Delete(logfilename) )
-    {
-        slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
-                         "referint_postop_close could not delete \"%s\"\n",
-                          logfilename );
-    }
 
-	/* unlock and let other writers back at the file */
-	PR_Unlock(referint_mutex);
-	
-	/* wait on condition here */
-	PR_Lock(keeprunning_mutex);
-	PR_WaitCondVar(keeprunning_cv, PR_SecondsToInterval(delay));
-	PR_Unlock(keeprunning_mutex);
-    }
+        while( GetNextLine(thisline, MAX_LINE, prfd) ){
+            ptoken = ldap_utf8strtok_r(thisline, delimiter, &iter);
+            sdn = slapi_sdn_new_normdn_byref(ptoken);
+            ptoken = ldap_utf8strtok_r (NULL, delimiter, &iter);
 
-	/* cleanup resources allocated in start  */
-	if (NULL != keeprunning_mutex) {
-		PR_DestroyLock(keeprunning_mutex);
-	}
-	if (NULL != referint_mutex) {
-		PR_DestroyLock(referint_mutex);
-	}
-	if (NULL != keeprunning_cv) {
-		PR_DestroyCondVar(keeprunning_cv);
-	}
+            if(!strcasecmp(ptoken, "NULL")) {
+                tmprdn = NULL;
+            } else {
+                tmprdn = slapi_ch_smprintf("%s", ptoken);
+            }
+
+            ptoken = ldap_utf8strtok_r (NULL, delimiter, &iter);
+            if (!strcasecmp(ptoken, "NULL")) {
+                tmpsuperior = NULL;
+            } else {
+                tmpsuperior = slapi_sdn_new_normdn_byref(ptoken);
+            }
+            ptoken = ldap_utf8strtok_r (NULL, delimiter, &iter);
+            if (strcasecmp(ptoken, "NULL") != 0) {
+                /* Set the bind DN in the thread data */
+                if(slapi_td_set_dn(slapi_ch_strdup(ptoken))){
+                    slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,"Failed to set thread data\n");
+                }
+            }
+
+            update_integrity(plugin_argv, sdn, tmprdn, tmpsuperior, logChanges);
+
+            slapi_sdn_free(&sdn);
+            slapi_ch_free_string(&tmprdn);
+            slapi_sdn_free(&tmpsuperior);
+        }
+
+        PR_Close(prfd);
+
+        /* remove the original file */
+        if( PR_SUCCESS != PR_Delete(logfilename) ){
+            slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
+                "referint_postop_close could not delete \"%s\"\n", logfilename );
+        }
+
+        /* unlock and let other writers back at the file */
+        PR_Unlock(referint_mutex);
 
+        /* wait on condition here */
+        PR_Lock(keeprunning_mutex);
+        PR_WaitCondVar(keeprunning_cv, PR_SecondsToInterval(delay));
+        PR_Unlock(keeprunning_mutex);
+    }
 
+    /* cleanup resources allocated in start  */
+    if (NULL != keeprunning_mutex) {
+        PR_DestroyLock(keeprunning_mutex);
+    }
+    if (NULL != referint_mutex) {
+        PR_DestroyLock(referint_mutex);
+    }
+    if (NULL != keeprunning_cv) {
+        PR_DestroyCondVar(keeprunning_cv);
+    }
 }
 
 int my_fgetc(PRFileDesc *stream)
@@ -1042,7 +1014,6 @@ int my_fgetc(PRFileDesc *stream)
     int         err;
 
     /* check if we need to load the buffer */
-
     if( READ_BUFSIZE == position )
     {
         memset(buf, '\0', READ_BUFSIZE);
@@ -1055,7 +1026,7 @@ int my_fgetc(PRFileDesc *stream)
             return err;
         }
     }
-	
+
     /* try to read some data */
     if( '\0' == buf[position])
     {
@@ -1066,9 +1037,8 @@ int my_fgetc(PRFileDesc *stream)
         retval = buf[position];
         position++;
     }
-        
-    return retval;
 
+    return retval;
 }	
 
 int
@@ -1078,38 +1048,33 @@ GetNextLine(char *dest, int size_dest, PRFileDesc *stream) {
     int  done     = 0;
     int  i        = 0;
 	
-    while(!done)
-    {
-        if( ( nextchar = my_fgetc(stream) ) != 0)
-        {
-            if( i < (size_dest - 1) ) 
-            {
+    while(!done){
+        if( ( nextchar = my_fgetc(stream) ) != 0){
+            if( i < (size_dest - 1) ){
                 dest[i] = nextchar;
                 i++;
-
-                if(nextchar == '\n')
-                {
+                if(nextchar == '\n'){
                     /* end of line reached */
                     done = 1;
                 }
-		             
-            }else{
+            } else {
                 /* no more room in buffer */
                 done = 1;
             }
-		
-        }else{
+        } else {
             /* error or end of file */
             done = 1;
         }
     }
-
     dest[i] =  '\0';
     
     /* return size of string read */
     return i;
 }
 
+/*
+ *  Write this record to the log file
+ */
 void
 writeintegritylog(Slapi_PBlock *pb, char *logfilename, Slapi_DN *sdn,
                   char *newrdn, Slapi_DN *newsuperior, Slapi_DN *requestorsdn)
@@ -1120,44 +1085,40 @@ writeintegritylog(Slapi_PBlock *pb, char *logfilename, Slapi_DN *sdn,
     int rc;
     const char *requestordn = NULL;
     size_t reqdn_len = 0;
-    /* write this record to the file */
-
-    /* use this lock to protect file data when update integrity is occuring */
-    /* should hopefully not be a big issue on concurrency */
     
+    /*
+     *  Use this lock to protect file data when update integrity is occuring
+     *  should hopefully not be a big issue on concurrency
+     */
     PR_Lock(referint_mutex);
     if (( prfd = PR_Open( logfilename, PR_WRONLY | PR_CREATE_FILE | PR_APPEND,
 	      REFERINT_DEFAULT_FILE_MODE )) == NULL ) 
     {
         slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
-	       "referint_postop could not write integrity log \"%s\" "
-		SLAPI_COMPONENT_NAME_NSPR " %d (%s)\n",
-	       logfilename, PR_GetError(), slapd_pr_strerror(PR_GetError()) );
-        
+            "referint_postop could not write integrity log \"%s\" "
+        SLAPI_COMPONENT_NAME_NSPR " %d (%s)\n",
+            logfilename, PR_GetError(), slapd_pr_strerror(PR_GetError()) );
+
         PR_Unlock(referint_mutex);
-	    return;
+        return;
     }
-
-    /* make sure we have enough room in our buffer
-       before trying to write it 
+    /*
+     *  Make sure we have enough room in our buffer before trying to write it.
+     *  add length of dn +  5(three tabs, a newline, and terminating \0)
      */
-
-	/* add length of dn +  5(three tabs, a newline, and terminating \0) */
     len_to_write = slapi_sdn_get_ndn_len(sdn) + 5;
 
-    if(newrdn == NULL)
-    {
+    if(newrdn == NULL){
         /* add the length of "NULL" */
         len_to_write += 4;
-    }else{
+    } else {
         /* add the length of the newrdn */
         len_to_write += strlen(newrdn);
     }
-    if(NULL == newsuperior)
-    {
+    if(NULL == newsuperior){
         /* add the length of "NULL" */
         len_to_write += 4;
-    }else{
+    } else {
         /* add the length of the newsuperior */
         len_to_write += slapi_sdn_get_ndn_len(newsuperior);
     }
@@ -1169,36 +1130,30 @@ writeintegritylog(Slapi_PBlock *pb, char *logfilename, Slapi_DN *sdn,
         len_to_write += 4; /* "NULL" */
     }
 
-    if(len_to_write > MAX_LINE )
-    {
+    if(len_to_write > MAX_LINE ){
         slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM,
                          "referint_postop could not write integrity log:"
                          " line length exceeded. It will not be able"
                          " to update references to this entry.\n");
-    }else{
-       PR_snprintf(buffer, MAX_LINE, "%s\t%s\t%s\t%s\t\n", 
-				   slapi_sdn_get_dn(sdn),
-				   (newrdn != NULL) ? newrdn : "NULL",
-				   (newsuperior != NULL) ? slapi_sdn_get_dn(newsuperior) :
-				                           "NULL",
-                   requestordn ? requestordn : "NULL");
+    } else {
+        PR_snprintf(buffer, MAX_LINE, "%s\t%s\t%s\t%s\t\n", slapi_sdn_get_dn(sdn),
+                   (newrdn != NULL) ? newrdn : "NULL",
+                   (newsuperior != NULL) ? slapi_sdn_get_dn(newsuperior) : "NULL",
+                    requestordn ? requestordn : "NULL");
         if (PR_Write(prfd,buffer,strlen(buffer)) < 0){
-           slapi_log_error(SLAPI_LOG_FATAL,REFERINT_PLUGIN_SUBSYSTEM,
-	       " writeintegritylog: PR_Write failed : The disk"
-	       " may be full or the file is unwritable :: NSPR error - %d\n",
-	       PR_GetError());
-	    }
-   }
+            slapi_log_error(SLAPI_LOG_FATAL,REFERINT_PLUGIN_SUBSYSTEM,
+                " writeintegritylog: PR_Write failed : The disk"
+                " may be full or the file is unwritable :: NSPR error - %d\n",
+            PR_GetError());
+        }
+    }
 
     /* If file descriptor is closed successfully, PR_SUCCESS */
-    
     rc = PR_Close(prfd);
-	if (rc != PR_SUCCESS)
-	{
-		slapi_log_error(SLAPI_LOG_FATAL,REFERINT_PLUGIN_SUBSYSTEM, 
-				" writeintegritylog: failed to close the file"
-				" descriptor prfd; NSPR error - %d\n",
-				PR_GetError());
-	}
+    if (rc != PR_SUCCESS){
+        slapi_log_error(SLAPI_LOG_FATAL,REFERINT_PLUGIN_SUBSYSTEM,
+            " writeintegritylog: failed to close the file descriptor prfd; NSPR error - %d\n",
+            PR_GetError());
+    }
     PR_Unlock(referint_mutex);    
-  }
+}
diff --git a/ldap/servers/plugins/replication/repl5_plugins.c b/ldap/servers/plugins/replication/repl5_plugins.c
index 9358daf..a768edb 100644
--- a/ldap/servers/plugins/replication/repl5_plugins.c
+++ b/ldap/servers/plugins/replication/repl5_plugins.c
@@ -479,7 +479,12 @@ multimaster_preop_modify (Slapi_PBlock *pb)
             }
             else
             {
-                PR_ASSERT(0); /* JCMREPL - A Replicated Operation with no Repl Baggage control... What does that mean? */
+                /*  PR_ASSERT(0); JCMREPL - A Replicated Operation with no Repl Baggage control... What does that mean? */
+                /*
+                 *  This could be RI plugin responding to a replicated update from AD or some other master that is not
+                 *  using the RI plugin, so don't PR_ASSERT here.  This only happens if we configure the RI plugin with
+                 *  "nsslapd-pluginAllowReplUpdates: on", also the RI plugin only issues "modifies".
+                 */
             }
         }
         else




More information about the 389-commits mailing list