From 7b74f56c497c1cef1a97667548f5a49ea09a3552 Mon Sep 17 00:00:00 2001
From: Carsten Grzemba <cgrzemba@opencsw.org>
Date: Thu, 24 Jan 2013 14:23:49 +0100
Subject: [PATCH 9/9] fix for #550: memberuid not created

---
 ldap/servers/plugins/posix-winsync/posix-group-func.c |  8 ++++++--
 ldap/servers/plugins/posix-winsync/posix-group-func.h |  2 +-
 ldap/servers/plugins/posix-winsync/posix-winsync.c    | 18 ++++++------------
 3 Dateien geändert, 13 Zeilen hinzugefügt(+), 15 Zeilen entfernt(-)

diff --git a/ldap/servers/plugins/posix-winsync/posix-group-func.c b/ldap/servers/plugins/posix-winsync/posix-group-func.c
index 1403a89..37ab4d7 100644
--- a/ldap/servers/plugins/posix-winsync/posix-group-func.c
+++ b/ldap/servers/plugins/posix-winsync/posix-group-func.c
@@ -209,6 +209,9 @@ isPosixGroup(Slapi_Entry *entry)
     ) {
         const char *oc = NULL;
         oc = slapi_value_get_string(value);
+        slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
+                    "found objectclass %s\n", oc);
+
         if (strncasecmp(oc, "posixGroup", 11) == 0) {
             return 1; /* Entry has objectclass posixGroup */
         }
@@ -218,13 +221,14 @@ isPosixGroup(Slapi_Entry *entry)
 }
 
 int
-modGroupMembership(Slapi_Entry *entry, Slapi_Mods *smods, int *do_modify)
+modGroupMembership(Slapi_Entry *entry, Slapi_Mods *smods, int *do_modify, int newposixgroup)
 {
     int rc = 0;
 
     slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME, "modGroupMembership: ==>\n");
 
-    if (!isPosixGroup(entry)) {
+    if (!newposixgroup && !isPosixGroup(entry)) {
+        slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME, "modGroupMembership: <== no posixgroup\n");
         return 0;
     }
 
diff --git a/ldap/servers/plugins/posix-winsync/posix-group-func.h b/ldap/servers/plugins/posix-winsync/posix-group-func.h
index 9452022..8a8dc9a 100644
--- a/ldap/servers/plugins/posix-winsync/posix-group-func.h
+++ b/ldap/servers/plugins/posix-winsync/posix-group-func.h
@@ -11,7 +11,7 @@ Slapi_PBlock * dnHasObjectClass( const char *baseDN, const char *objectClass, Sl
 char * searchUid(const char *udn);
 int dn_in_set(const char* uid, char **uids);
 */
-int modGroupMembership(Slapi_Entry *entry, Slapi_Mods *smods, int *do_modify);
+int modGroupMembership(Slapi_Entry *entry, Slapi_Mods *smods, int *do_modify, int newposixgroup);
 int addGroupMembership(Slapi_Entry *entry, Slapi_Entry *ad_entry);
 char * searchUid(const char *udn);
 void memberUidLock();
diff --git a/ldap/servers/plugins/posix-winsync/posix-winsync.c b/ldap/servers/plugins/posix-winsync/posix-winsync.c
index 398541d..4cee336 100644
--- a/ldap/servers/plugins/posix-winsync/posix-winsync.c
+++ b/ldap/servers/plugins/posix-winsync/posix-winsync.c
@@ -897,12 +897,6 @@ posix_winsync_pre_ds_mod_group_cb(void *cbdata, const Slapi_Entry *rawentry, Sla
     slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
                     "_pre_ds_mod_group_cb present %d modify %d before\n", is_present_local,
                     do_modify_local);
-    if (posix_winsync_config_get_mapMemberUid()) {
-        memberUidLock();
-        modGroupMembership(ds_entry, smods, do_modify);
-        memberUidUnlock();
-    }
-
     slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
                     "_pre_ds_mod_group_cb present %d modify %d\n", is_present_local,
                     do_modify_local);
@@ -924,17 +918,17 @@ posix_winsync_pre_ds_mod_group_cb(void *cbdata, const Slapi_Entry *rawentry, Sla
                             "_pre_ds_mod_group_cb add oc:posixGroup\n");
             slapi_mods_add_mod_values(smods, LDAP_MOD_REPLACE, "objectClass",
                                       valueset_get_valuearray(oc_vs));
-            slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
-                            "_pre_ds_mod_group_cb step\n");
             slapi_value_free(&oc_nv);
-            slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
-                            "_pre_ds_mod_group_cb step\n");
             slapi_valueset_free(oc_vs);
-            slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name,
-                            "_pre_ds_mod_group_cb step\n");
         }
         slapi_value_free(&voc);
     }
+    if (posix_winsync_config_get_mapMemberUid()) {
+        memberUidLock();
+        modGroupMembership(ds_entry, smods, do_modify, !is_present_local && do_modify_local);
+        memberUidUnlock();
+    }
+
     slapi_log_error(SLAPI_LOG_PLUGIN, posix_winsync_plugin_name, "_pre_ds_mod_group_cb step\n");
 
     if (slapi_is_loglevel_set(SLAPI_LOG_PLUGIN)) {
-- 
1.7.12

