Browse Source

Fix initial RUV logic and add support for Win2003

David Boreham 20 năm trước cách đây
mục cha
commit
3cf5a4f030

+ 29 - 11
ldap/servers/plugins/replication/windows_protocol_util.c

@@ -445,16 +445,12 @@ windows_acquire_replica(Private_Repl_Protocol *prp, RUV **ruv, int check_ruv)
 	/* Handle the pristine case */
 	if (cons_ruv_obj == NULL) 
 	{
-		/* DBDB: this is all wrong. Need to fix this */
-		RUV *s = NULL;
-		s = (RUV*)  object_get_data ( replica_get_ruv ( replica ) );
-		
-		agmt_set_consumer_ruv(prp->agmt, s );
-		object_release ( replica_get_ruv ( replica ) );
-		cons_ruv_obj = agmt_get_consumer_ruv(prp->agmt);		
+		*ruv = NULL;		
+	} else 
+	{
+		r = (RUV*)  object_get_data(cons_ruv_obj); 
+		*ruv = ruv_dup(r);
 	}
-	r = (RUV*)  object_get_data(cons_ruv_obj); 
-	*ruv = ruv_dup(r);
 
 	if ( supl_ruv_obj ) object_release ( supl_ruv_obj );
 	if ( cons_ruv_obj ) object_release ( cons_ruv_obj );
@@ -614,6 +610,21 @@ send_password_modify(Slapi_DN *sdn, char *password, Private_Repl_Protocol *prp)
 		return pw_return;
 }
 
+static int
+send_accountcontrol_modify(Slapi_DN *sdn, Private_Repl_Protocol *prp)
+{
+	ConnResult mod_return = 0;
+	Slapi_Mods smods = {0};
+
+    slapi_mods_init (&smods, 0);
+	slapi_mods_add_string(&smods, LDAP_MOD_REPLACE, "userAccountControl", "512");
+
+	mod_return = windows_conn_send_modify(prp->conn, slapi_sdn_get_dn(sdn), slapi_mods_get_ldapmods_byref(&smods), NULL, NULL );
+
+    slapi_mods_done(&smods);
+	return mod_return;
+}
+
 static int
 windows_entry_has_attr_and_value(Slapi_Entry *e, const char *attrname, char *value)
 {
@@ -927,6 +938,14 @@ windows_replay_update(Private_Repl_Protocol *prp, slapi_operation_parameters *op
 			{
 				slapi_log_error(SLAPI_LOG_REPL, windows_repl_plugin_name, "%s: windows_replay_update: update password returned %d\n",
 					agmt_get_long_name(prp->agmt), return_value );
+			} else {
+				/* If we successfully added an entry, and then subsequently changed its password, THEN we need to change its status in AD 
+				 * in order that it can be used (otherwise the user is marked as disabled). To do this we set this attribute and value:
+				 * userAccountControl: 512 */
+				if (op->operation_type == SLAPI_OPERATION_ADD && missing_entry)
+				{
+					return_value = send_accountcontrol_modify(remote_dn, prp);
+				}
 			}
 		}
 	} else {
@@ -1044,8 +1063,7 @@ windows_create_remote_entry(Private_Repl_Protocol *prp,Slapi_Entry *original_ent
    		"objectclass:person\n"
 		"objectclass:organizationalperson\n"
 		"objectclass:user\n"
-		"userPrincipalName:%s\n"
-		"userAccountControl:512\n";
+		"userPrincipalName:%s\n";
 
 	char *remote_group_entry_template = 
 		"dn: %s\n"

+ 27 - 2
ldap/servers/plugins/replication/windows_tot_protocol.c

@@ -78,6 +78,13 @@ static void get_result (int rc, void *cb_data);
 static int send_entry (Slapi_Entry *e, void *callback_data);
 static void windows_tot_delete(Private_Repl_Protocol **prp);
 
+#if 0
+		/* DBDB: this is all wrong. Need to fix this */
+
+		object_release ( replica_get_ruv ( replica ) );
+		cons_ruv_obj = agmt_get_consumer_ruv(prp->agmt);
+#endif
+
 /*
  * Completely refresh a replica. The basic protocol interaction goes
  * like this:
@@ -96,7 +103,10 @@ windows_tot_run(Private_Repl_Protocol *prp)
 	CSN *remote_schema_csn = NULL;
 	PRBool cookie_has_more = PR_TRUE;
 	RUV *ruv = NULL;
-
+	RUV *starting_ruv = NULL;
+	Replica *replica = NULL;
+	Object *local_ruv_obj = NULL;
+	
 	LDAPDebug( LDAP_DEBUG_TRACE, "=> windows_tot_run\n", 0, 0, 0 );
 	
 	PR_ASSERT(NULL != prp);
@@ -131,7 +141,14 @@ windows_tot_run(Private_Repl_Protocol *prp)
         prp->stopped = 1;
 		goto done;    
     }
-	
+
+	/* Get the current replica RUV.
+	 * If the total update succeeds, we will set the consumer RUV to this value.
+	 */
+	replica = object_get_data(prp->replica_object);
+	local_ruv_obj = replica_get_ruv (replica);
+	starting_ruv = ruv_dup((RUV*)  object_get_data ( local_ruv_obj ));
+	object_release (local_ruv_obj);
 	
 	agmt_set_last_init_status(prp->agmt, 0, 0, "Total schema update in progress");
 	remote_schema_csn = agmt_get_consumer_schema_csn ( prp->agmt );
@@ -184,9 +201,17 @@ windows_tot_run(Private_Repl_Protocol *prp)
 		slapi_log_error(SLAPI_LOG_FATAL, windows_repl_plugin_name, "Finished total update of replica "
 						"\"%s\". Sent %d entries.\n", agmt_get_long_name(prp->agmt), cb_data.num_entries);
 		agmt_set_last_init_status(prp->agmt, 0, 0, "Total update succeeded");
+		/* Now update our consumer RUV for this agreement.
+		 * This ensures that future incrememental updates work.
+		 */
+		agmt_set_consumer_ruv(prp->agmt, starting_ruv );
 	}
 
 done:
+	if (starting_ruv)
+	{
+		ruv_destroy(&starting_ruv);
+	}
 	
 	prp->stopped = 1;
 	LDAPDebug( LDAP_DEBUG_TRACE, "<= windows_tot_run\n", 0, 0, 0 );