Blame SOURCES/0007-Issue-51132-Winsync-setting-winSyncWindowsFilter-not.patch

de47d7
From fe51cdabe75917e82195fcad47563fc169026625 Mon Sep 17 00:00:00 2001
de47d7
From: Mark Reynolds <mreynolds@redhat.com>
de47d7
Date: Wed, 3 Jun 2020 15:58:21 -0400
de47d7
Subject: [PATCH] Issue 51132 - Winsync setting winSyncWindowsFilter not
de47d7
 working as expected
de47d7
de47d7
Bug Description:  When processing updates from AD we search AD using a filter,
de47d7
                  and this filter can be customized via the attribute setting:
de47d7
                  winSyncWindowsFilter.  However, after setting a custom filter
de47d7
                  replication appears to stop working as expected.  New entries
de47d7
                  that match the filter are replicated to DS, but not updates
de47d7
                  to these entries.  The problem is that when dirsync sends
de47d7
                  updates, it is just a partial entry - only containing the
de47d7
                  attributes that changed.  Then the server checks the filter
de47d7
                  again on the returned entry, but if it's just a mod update then
de47d7
                  the entry is missing most of its attributes, and the filter
de47d7
                  check fails and the entry is not updated on DS.
de47d7
de47d7
Fix Description:  Do not check the filter on the returned entries when processing
de47d7
                  incremental updates as the fitler test was already done when
de47d7
                  gathering the candidates.
de47d7
de47d7
relates: https://pagure.io/389-ds-base/issue/51132
de47d7
de47d7
Reviewed by: tbordaz & firstyear (Thanks!)
de47d7
---
de47d7
 .../plugins/replication/windows_protocol_util.c   | 15 +++++++++------
de47d7
 1 file changed, 9 insertions(+), 6 deletions(-)
de47d7
de47d7
diff --git a/ldap/servers/plugins/replication/windows_protocol_util.c b/ldap/servers/plugins/replication/windows_protocol_util.c
de47d7
index e35437221..c394f82ce 100644
de47d7
--- a/ldap/servers/plugins/replication/windows_protocol_util.c
de47d7
+++ b/ldap/servers/plugins/replication/windows_protocol_util.c
de47d7
@@ -48,7 +48,7 @@ static int windows_get_remote_entry(Private_Repl_Protocol *prp, const Slapi_DN *
de47d7
 static int windows_get_remote_tombstone(Private_Repl_Protocol *prp, const Slapi_DN *remote_dn, Slapi_Entry **remote_entry);
de47d7
 static int windows_reanimate_tombstone(Private_Repl_Protocol *prp, const Slapi_DN *tombstone_dn, const char *new_dn);
de47d7
 static const char *op2string(int op);
de47d7
-static int is_subject_of_agreement_remote(Slapi_Entry *e, const Repl_Agmt *ra);
de47d7
+static int is_subject_of_agreement_remote(Slapi_Entry *e, const Repl_Agmt *ra, int test_filter);
de47d7
 static int map_entry_dn_inbound(Slapi_Entry *e, Slapi_DN **dn, const Repl_Agmt *ra);
de47d7
 static int map_entry_dn_inbound_ext(Slapi_Entry *e, Slapi_DN **dn, const Repl_Agmt *ra, int use_guid, int user_username);
de47d7
 static int windows_update_remote_entry(Private_Repl_Protocol *prp, Slapi_Entry *remote_entry, Slapi_Entry *local_entry, int is_user);
de47d7
@@ -57,6 +57,9 @@ static int map_windows_tombstone_dn(Slapi_Entry *e, Slapi_DN **dn, Private_Repl_
de47d7
 static int windows_check_mods_for_rdn_change(Private_Repl_Protocol *prp, LDAPMod **original_mods, Slapi_Entry *local_entry, Slapi_DN *remote_dn, char **newrdn);
de47d7
 static int windows_get_superior_change(Private_Repl_Protocol *prp, Slapi_DN *local_dn, Slapi_DN *remote_dn, char **newsuperior, int to_windows);
de47d7
 
de47d7
+#define SKIP_FILTER 0
de47d7
+#define TEST_FILTER 1
de47d7
+
de47d7
 /* Controls the direction of flow for mapped attributes */
de47d7
 typedef enum mapping_types {
de47d7
     bidirectional,
de47d7
@@ -442,7 +445,7 @@ map_dn_values(Private_Repl_Protocol *prp, Slapi_ValueSet *original_values, Slapi
de47d7
             /* Try to get the remote entry */
de47d7
             retval = windows_get_remote_entry(prp, original_dn, &remote_entry);
de47d7
             if (remote_entry && 0 == retval) {
de47d7
-                is_ours = is_subject_of_agreement_remote(remote_entry, prp->agmt);
de47d7
+                is_ours = is_subject_of_agreement_remote(remote_entry, prp->agmt, TEST_FILTER);
de47d7
                 if (is_ours) {
de47d7
                     retval = map_entry_dn_inbound(remote_entry, &local_dn, prp->agmt);
de47d7
                     if (0 == retval && local_dn) {
de47d7
@@ -3708,7 +3711,7 @@ map_entry_dn_outbound(Slapi_Entry *e,
de47d7
                       slapi_sdn_get_dn(new_dn),
de47d7
                       remote_entry ? slapi_entry_get_dn_const(remote_entry) : "(null)");
de47d7
         if (0 == rc && remote_entry) {
de47d7
-            if (!is_subject_of_agreement_remote(remote_entry, prp->agmt)) {
de47d7
+            if (!is_subject_of_agreement_remote(remote_entry, prp->agmt, TEST_FILTER)) {
de47d7
                 /* The remote entry is out of scope of the agreement.
de47d7
                  * Thus, we don't map the entry_dn.
de47d7
                  * This occurs when the remote entry is moved out. */
de47d7
@@ -4198,7 +4201,7 @@ is_dn_subject_of_agreement_local(const Slapi_DN *sdn, const Repl_Agmt *ra)
de47d7
  *               0 -- out of scope
de47d7
  */
de47d7
 static int
de47d7
-is_subject_of_agreement_remote(Slapi_Entry *e, const Repl_Agmt *ra)
de47d7
+is_subject_of_agreement_remote(Slapi_Entry *e, const Repl_Agmt *ra, int test_filter)
de47d7
 {
de47d7
     int retval = 0;
de47d7
     int is_in_subtree = 0;
de47d7
@@ -4232,7 +4235,7 @@ is_subject_of_agreement_remote(Slapi_Entry *e, const Repl_Agmt *ra)
de47d7
         Slapi_DN psdn = {0};
de47d7
         Slapi_Entry *pentry = NULL;
de47d7
 
de47d7
-        if (windows_private_get_windows_filter(ra) &&
de47d7
+        if (test_filter && windows_private_get_windows_filter(ra) &&
de47d7
             slapi_filter_test_simple(e, windows_private_get_windows_filter(ra))) {
de47d7
             /* type_winSyncWindowsFilter is set and the remote entry does not match the filter */
de47d7
             goto error;
de47d7
@@ -5627,7 +5630,7 @@ windows_process_dirsync_entry(Private_Repl_Protocol *prp, Slapi_Entry *e, int is
de47d7
         }
de47d7
     } else {
de47d7
         /* Is this entry one we should be interested in ? */
de47d7
-        if (is_subject_of_agreement_remote(e, prp->agmt)) {
de47d7
+        if (is_subject_of_agreement_remote(e, prp->agmt, SKIP_FILTER)) {
de47d7
             ConnResult cres = 0;
de47d7
             const char *searchbase = slapi_entry_get_dn_const(e);
de47d7
             char *filter = "(objectclass=*)";
de47d7
-- 
de47d7
2.26.2
de47d7