|
|
@@ -185,232 +185,238 @@ smods_has_mod(Slapi_Mods *smods, int modtype, const char *type, const char *val)
|
|
|
return rc;
|
|
|
}
|
|
|
|
|
|
+int
|
|
|
+isPosixGroup(Slapi_Entry *entry)
|
|
|
+{
|
|
|
+ int rc = 0;
|
|
|
+ int i;
|
|
|
+ Slapi_Attr *obj_attr = NULL;
|
|
|
+ Slapi_Value *value = NULL;
|
|
|
+
|
|
|
+ rc = slapi_entry_attr_find(entry, "objectclass", &obj_attr);
|
|
|
+
|
|
|
+ if (rc != 0) {
|
|
|
+ return 0; /* Doesn't have any objectclasses */
|
|
|
+ }
|
|
|
+
|
|
|
+ slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
|
|
|
+ "add/mod-GroupMembership scan objectclasses\n");
|
|
|
+
|
|
|
+ for (
|
|
|
+ i = slapi_attr_first_value(obj_attr, &value);
|
|
|
+ i != -1;
|
|
|
+ i = slapi_attr_next_value(obj_attr, i, &value)
|
|
|
+ ) {
|
|
|
+ const char *oc = NULL;
|
|
|
+ oc = slapi_value_get_string(value);
|
|
|
+ if (strncasecmp(oc, "posixGroup", 11) == 0) {
|
|
|
+ return 1; /* Entry has objectclass posixGroup */
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0; /* Doesn't have objectclass "posixGroup" */
|
|
|
+}
|
|
|
+
|
|
|
int
|
|
|
modGroupMembership(Slapi_Entry *entry, Slapi_Mods *smods, int *do_modify)
|
|
|
{
|
|
|
int rc = 0;
|
|
|
- Slapi_Attr * obj_attr = NULL; /* Entry attributes */
|
|
|
|
|
|
slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME, "modGroupMembership: ==>\n");
|
|
|
|
|
|
- rc = slapi_entry_attr_find(entry, "objectclass", &obj_attr);
|
|
|
- if (rc == 0) { /* Found objectclasses, so... */
|
|
|
- int i;
|
|
|
- Slapi_Value * value = NULL; /* Attribute values */
|
|
|
+ if (!isPosixGroup(entry)) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
|
|
|
- slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
|
|
|
- "modGroupMembership scan objectclasses\n");
|
|
|
- for (i = slapi_attr_first_value(obj_attr, &value); i != -1;
|
|
|
- i = slapi_attr_next_value(obj_attr, i, &value)) {
|
|
|
- const char * oc = NULL;
|
|
|
-
|
|
|
- oc = slapi_value_get_string(value);
|
|
|
- if (strncasecmp(oc, "posixGroup", 11) == 0) { /* entry has objectclass posixGroup */
|
|
|
- Slapi_Mod *smod = NULL;
|
|
|
- Slapi_Mod *nextMod = slapi_mod_new();
|
|
|
- int del_mod = 0;
|
|
|
- char **smod_adduids = NULL;
|
|
|
- char **smod_deluids = NULL;
|
|
|
+ Slapi_Mod *smod = NULL;
|
|
|
+ Slapi_Mod *nextMod = slapi_mod_new();
|
|
|
+ int del_mod = 0;
|
|
|
+ char **smod_adduids = NULL;
|
|
|
+ char **smod_deluids = NULL;
|
|
|
|
|
|
- slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
|
|
|
- "modGroupMembership: posixGroup -> look for uniquemember\n");
|
|
|
- if (slapi_is_loglevel_set(SLAPI_LOG_PLUGIN))
|
|
|
- slapi_mods_dump(smods, "memberUid - mods dump - initial");
|
|
|
- for (smod = slapi_mods_get_first_smod(smods, nextMod); smod; smod
|
|
|
- = slapi_mods_get_next_smod(smods, nextMod)) {
|
|
|
- if (slapi_attr_types_equivalent(slapi_mod_get_type(smod), "uniqueMember")) {
|
|
|
- struct berval *bv;
|
|
|
-
|
|
|
- del_mod = slapi_mod_get_operation(smod);
|
|
|
- for (bv = slapi_mod_get_first_value(smod); bv;
|
|
|
- bv = slapi_mod_get_next_value(smod)) {
|
|
|
- Slapi_Value *sv = slapi_value_new();
|
|
|
-
|
|
|
- slapi_value_init_berval(sv, bv); /* copies bv_val */
|
|
|
- if (SLAPI_IS_MOD_DELETE(slapi_mod_get_operation(smod))) {
|
|
|
- slapi_ch_array_add(&smod_deluids,
|
|
|
- slapi_ch_strdup(slapi_value_get_string(sv)));
|
|
|
- slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
|
|
|
- "modGroupMembership: add to deluids %s\n",
|
|
|
- bv->bv_val);
|
|
|
- } else {
|
|
|
- slapi_ch_array_add(&smod_adduids,
|
|
|
- slapi_ch_strdup(slapi_value_get_string(sv)));
|
|
|
- slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
|
|
|
- "modGroupMembership: add to adduids %s\n",
|
|
|
- bv->bv_val);
|
|
|
- }
|
|
|
- slapi_value_free(&sv);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- slapi_mod_free(&nextMod);
|
|
|
- if (!del_mod) {
|
|
|
+ slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
|
|
|
+ "modGroupMembership: posixGroup -> look for uniquemember\n");
|
|
|
+ if (slapi_is_loglevel_set(SLAPI_LOG_PLUGIN))
|
|
|
+ slapi_mods_dump(smods, "memberUid - mods dump - initial");
|
|
|
+ for (smod = slapi_mods_get_first_smod(smods, nextMod); smod; smod
|
|
|
+ = slapi_mods_get_next_smod(smods, nextMod)) {
|
|
|
+ if (slapi_attr_types_equivalent(slapi_mod_get_type(smod), "uniqueMember")) {
|
|
|
+ struct berval *bv;
|
|
|
+
|
|
|
+ del_mod = slapi_mod_get_operation(smod);
|
|
|
+ for (bv = slapi_mod_get_first_value(smod); bv;
|
|
|
+ bv = slapi_mod_get_next_value(smod)) {
|
|
|
+ Slapi_Value *sv = slapi_value_new();
|
|
|
+
|
|
|
+ slapi_value_init_berval(sv, bv); /* copies bv_val */
|
|
|
+ if (SLAPI_IS_MOD_DELETE(slapi_mod_get_operation(smod))) {
|
|
|
+ slapi_ch_array_add(&smod_deluids,
|
|
|
+ slapi_ch_strdup(slapi_value_get_string(sv)));
|
|
|
+ slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
|
|
|
+ "modGroupMembership: add to deluids %s\n",
|
|
|
+ bv->bv_val);
|
|
|
+ } else {
|
|
|
+ slapi_ch_array_add(&smod_adduids,
|
|
|
+ slapi_ch_strdup(slapi_value_get_string(sv)));
|
|
|
slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
|
|
|
- "modGroupMembership: no uniquemember mod, nothing to do<==\n");
|
|
|
- return 0;
|
|
|
+ "modGroupMembership: add to adduids %s\n",
|
|
|
+ bv->bv_val);
|
|
|
}
|
|
|
+ slapi_value_free(&sv);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ slapi_mod_free(&nextMod);
|
|
|
+ if (!del_mod) {
|
|
|
+ slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
|
|
|
+ "modGroupMembership: no uniquemember mod, nothing to do<==\n");
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
|
|
|
+ slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
|
|
|
+ "modGroupMembership: entry is posixGroup\n");
|
|
|
+
|
|
|
+ Slapi_Attr * muid_attr = NULL; /* Entry attributes */
|
|
|
+ Slapi_Value * uid_value = NULL; /* Attribute values */
|
|
|
+
|
|
|
+ char **adduids = NULL;
|
|
|
+ char **moduids = NULL;
|
|
|
+ char **deluids = NULL;
|
|
|
+ int doModify = false;
|
|
|
+ int j = 0;
|
|
|
+
|
|
|
+ if (SLAPI_IS_MOD_DELETE(del_mod) || smod_deluids != NULL) {
|
|
|
+ Slapi_Attr * mu_attr = NULL; /* Entry attributes */
|
|
|
+ rc = slapi_entry_attr_find(entry, "memberUid", &mu_attr);
|
|
|
+ if (rc != 0 || mu_attr == NULL) {
|
|
|
+ slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
|
|
|
+ "modGroupMembership end: attribute memberUid not found\n");
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ /* found attribute uniquemember */
|
|
|
+ if (smod_deluids == NULL) { /* deletion of the last value, deletes the Attribut from entry complete, this operation has no value, so we must look by self */
|
|
|
+ Slapi_Attr * um_attr = NULL; /* Entry attributes */
|
|
|
+ Slapi_Value * uid_dn_value = NULL; /* Attribute values */
|
|
|
+ int rc = slapi_entry_attr_find(entry, "uniquemember", &um_attr);
|
|
|
+ if (rc != 0 || um_attr == NULL) {
|
|
|
slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
|
|
|
- "modGroupMembership: entry is posixGroup\n");
|
|
|
+ "modGroupMembership end: attribute uniquemember not found\n");
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ /* found attribute uniquemember */
|
|
|
+ /* ...loop for value... */
|
|
|
+ for (j = slapi_attr_first_value(um_attr, &uid_dn_value); j != -1;
|
|
|
+ j = slapi_attr_next_value(um_attr, j, &uid_dn_value)) {
|
|
|
+ slapi_ch_array_add(&smod_deluids,
|
|
|
+ slapi_ch_strdup(slapi_value_get_string(uid_dn_value)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /* ...loop for value... */
|
|
|
+ for (j = slapi_attr_first_value(mu_attr, &uid_value); j != -1;
|
|
|
+ j = slapi_attr_next_value(mu_attr, j, &uid_value)) {
|
|
|
+ /* remove from uniquemember: remove from memberUid also */
|
|
|
+ const char *uid = NULL;
|
|
|
+ slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
|
|
|
+ "modGroupMembership: test dellist \n");
|
|
|
+ uid = slapi_value_get_string(uid_value);
|
|
|
+ slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
|
|
|
+ "modGroupMembership: test dellist %s\n", uid);
|
|
|
+ if (uid_in_set(uid, smod_deluids)) {
|
|
|
+ slapi_ch_array_add(&deluids, slapi_ch_strdup(uid));
|
|
|
+ slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
|
|
|
+ "modGroupMembership: add to dellist %s\n", uid);
|
|
|
+ doModify = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (smod_adduids != NULL) { /* not MOD_DELETE */
|
|
|
+ const char *uid_dn = NULL;
|
|
|
|
|
|
- Slapi_Attr * muid_attr = NULL; /* Entry attributes */
|
|
|
- Slapi_Value * uid_value = NULL; /* Attribute values */
|
|
|
+ slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
|
|
|
+ "modGroupMembership: posixGroup -> look for uniquemember\n");
|
|
|
+ /* found attribute uniquemember */
|
|
|
+ for (j = 0; smod_adduids[j]; j++) {
|
|
|
+ static char *uid = NULL;
|
|
|
|
|
|
- char **adduids = NULL;
|
|
|
- char **moduids = NULL;
|
|
|
- char **deluids = NULL;
|
|
|
- int doModify = false;
|
|
|
- int j = 0;
|
|
|
+ uid_dn = smod_adduids[j];
|
|
|
+ slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
|
|
|
+ "modGroupMembership: perform user %s\n", uid_dn);
|
|
|
|
|
|
- if (SLAPI_IS_MOD_DELETE(del_mod) || smod_deluids != NULL) {
|
|
|
- Slapi_Attr * mu_attr = NULL; /* Entry attributes */
|
|
|
- rc = slapi_entry_attr_find(entry, "memberUid", &mu_attr);
|
|
|
- if (rc != 0 || mu_attr == NULL) {
|
|
|
- slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
|
|
|
- "modGroupMembership end: attribute memberUid not found\n");
|
|
|
- return 0;
|
|
|
- }
|
|
|
- /* found attribute uniquemember */
|
|
|
- if (smod_deluids == NULL) { /* deletion of the last value, deletes the Attribut from entry complete, this operation has no value, so we must look by self */
|
|
|
- Slapi_Attr * um_attr = NULL; /* Entry attributes */
|
|
|
- Slapi_Value * uid_dn_value = NULL; /* Attribute values */
|
|
|
- int rc = slapi_entry_attr_find(entry, "uniquemember", &um_attr);
|
|
|
- if (rc != 0 || um_attr == NULL) {
|
|
|
- slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
|
|
|
- "modGroupMembership end: attribute uniquemember not found\n");
|
|
|
- return 0;
|
|
|
- }
|
|
|
- /* found attribute uniquemember */
|
|
|
- /* ...loop for value... */
|
|
|
- for (j = slapi_attr_first_value(um_attr, &uid_dn_value); j != -1;
|
|
|
- j = slapi_attr_next_value(um_attr, j, &uid_dn_value)) {
|
|
|
- slapi_ch_array_add(&smod_deluids,
|
|
|
- slapi_ch_strdup(slapi_value_get_string(uid_dn_value)));
|
|
|
- }
|
|
|
- }
|
|
|
- /* ...loop for value... */
|
|
|
- for (j = slapi_attr_first_value(mu_attr, &uid_value); j != -1;
|
|
|
- j = slapi_attr_next_value(mu_attr, j, &uid_value)) {
|
|
|
- /* remove from uniquemember: remove from memberUid also */
|
|
|
- const char *uid = NULL;
|
|
|
- slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
|
|
|
- "modGroupMembership: test dellist \n");
|
|
|
- uid = slapi_value_get_string(uid_value);
|
|
|
- slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
|
|
|
- "modGroupMembership: test dellist %s\n", uid);
|
|
|
- if (uid_in_set(uid, smod_deluids)) {
|
|
|
- slapi_ch_array_add(&deluids, slapi_ch_strdup(uid));
|
|
|
- slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
|
|
|
- "modGroupMembership: add to dellist %s\n", uid);
|
|
|
- doModify = true;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (smod_adduids != NULL) { /* not MOD_DELETE */
|
|
|
- const char *uid_dn = NULL;
|
|
|
+ uid = searchUid(uid_dn);
|
|
|
|
|
|
+ if (uid == NULL) {
|
|
|
+ slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
|
|
|
+ "modGroupMembership: uid not found for %s, cannot do anything\n",
|
|
|
+ uid_dn); /* member on longer on server, do nothing */
|
|
|
+ } else {
|
|
|
+ rc |= slapi_entry_attr_find(entry, "memberUid", &muid_attr);
|
|
|
+ if (rc != 0 || muid_attr == NULL) { /* Found no memberUid list, so create */
|
|
|
slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
|
|
|
- "modGroupMembership: posixGroup -> look for uniquemember\n");
|
|
|
- /* found attribute uniquemember */
|
|
|
- for (j = 0; smod_adduids[j]; j++) {
|
|
|
- static char *uid = NULL;
|
|
|
-
|
|
|
- uid_dn = smod_adduids[j];
|
|
|
+ "modGroupMembership: no attribute memberUid, add with %s \n",
|
|
|
+ uid_dn);
|
|
|
+ slapi_ch_array_add(&adduids, uid);
|
|
|
+ doModify = true;
|
|
|
+ } else { /* Found a memberUid list, so modify */
|
|
|
+ Slapi_ValueSet *vs = NULL;
|
|
|
+ Slapi_Value *v = slapi_value_new();
|
|
|
+
|
|
|
+ slapi_value_init_string_passin(v, uid);
|
|
|
+ slapi_attr_get_valueset(muid_attr, &vs);
|
|
|
+ if (slapi_valueset_find(muid_attr, vs, v) != NULL) { /* already exist, all ok */
|
|
|
slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
|
|
|
- "modGroupMembership: perform user %s\n", uid_dn);
|
|
|
-
|
|
|
- uid = searchUid(uid_dn);
|
|
|
-
|
|
|
- if (uid == NULL) {
|
|
|
- slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
|
|
|
- "modGroupMembership: uid not found for %s, cannot do anything\n",
|
|
|
- uid_dn); /* member on longer on server, do nothing */
|
|
|
- } else {
|
|
|
- rc |= slapi_entry_attr_find(entry, "memberUid", &muid_attr);
|
|
|
- if (rc != 0 || muid_attr == NULL) { /* Found no memberUid list, so create */
|
|
|
- slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
|
|
|
- "modGroupMembership: no attribute memberUid, add with %s \n",
|
|
|
- uid_dn);
|
|
|
- slapi_ch_array_add(&adduids, uid);
|
|
|
- doModify = true;
|
|
|
- } else { /* Found a memberUid list, so modify */
|
|
|
- Slapi_ValueSet *vs = NULL;
|
|
|
- Slapi_Value *v = slapi_value_new();
|
|
|
-
|
|
|
- slapi_value_init_string_passin(v, uid);
|
|
|
- slapi_attr_get_valueset(muid_attr, &vs);
|
|
|
- if (slapi_valueset_find(muid_attr, vs, v) != NULL) { /* already exist, all ok */
|
|
|
- slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
|
|
|
- "modGroupMembership: uid found in memberuid list %s nothing to do\n",
|
|
|
- uid);
|
|
|
- } else {
|
|
|
- slapi_ch_array_add(&moduids, uid);
|
|
|
- slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
|
|
|
- "modGroupMembership: add to modlist %s\n", uid);
|
|
|
- doModify = true;
|
|
|
- }
|
|
|
- slapi_valueset_free(vs);
|
|
|
- slapi_value_init_berval(v, NULL); /* otherwise we will try to free memory we do not own */
|
|
|
- slapi_value_free(&v);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (doModify) {
|
|
|
- if (adduids) {
|
|
|
- int i;
|
|
|
- for (i = 0; adduids[i]; i++) {
|
|
|
- if (!smods_has_mod(smods, LDAP_MOD_ADD, "memberUid", adduids[i])) {
|
|
|
- slapi_mods_add_string(smods, LDAP_MOD_ADD, "memberUid", adduids[i]);
|
|
|
- }
|
|
|
- }
|
|
|
+ "modGroupMembership: uid found in memberuid list %s nothing to do\n",
|
|
|
+ uid);
|
|
|
} else {
|
|
|
- int i;
|
|
|
- for (i = 0; moduids && moduids[i]; i++) {
|
|
|
- if (!smods_has_mod(smods, LDAP_MOD_ADD, "memberUid", moduids[i])) {
|
|
|
- slapi_mods_add_string(smods, LDAP_MOD_ADD, "memberUid", moduids[i]);
|
|
|
- }
|
|
|
- }
|
|
|
- slapi_ch_array_free(moduids);
|
|
|
- moduids = NULL;
|
|
|
- for (i = 0; deluids && deluids[i]; i++) {
|
|
|
- if (!smods_has_mod(smods, LDAP_MOD_DELETE, "memberUid", deluids[i])) {
|
|
|
- slapi_mods_add_string(smods, LDAP_MOD_DELETE, "memberUid",
|
|
|
- deluids[i]);
|
|
|
- }
|
|
|
- }
|
|
|
+ slapi_ch_array_add(&moduids, uid);
|
|
|
+ slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
|
|
|
+ "modGroupMembership: add to modlist %s\n", uid);
|
|
|
+ doModify = true;
|
|
|
}
|
|
|
- if (slapi_is_loglevel_set(SLAPI_LOG_PLUGIN))
|
|
|
- slapi_mods_dump(smods, "memberUid - mods dump");
|
|
|
- *do_modify = 1;
|
|
|
- posix_winsync_config_set_MOFTaskCreated();
|
|
|
-
|
|
|
- slapi_ch_array_free(smod_adduids);
|
|
|
- smod_adduids = NULL;
|
|
|
- slapi_ch_array_free(adduids);
|
|
|
- adduids = NULL;
|
|
|
- slapi_ch_array_free(smod_deluids);
|
|
|
- smod_deluids = NULL;
|
|
|
- slapi_ch_array_free(deluids);
|
|
|
- deluids = NULL;
|
|
|
- slapi_ch_array_free(moduids);
|
|
|
- moduids = NULL;
|
|
|
- break;
|
|
|
+ /* slapi_value_free(&v); */
|
|
|
}
|
|
|
- slapi_ch_array_free(smod_adduids);
|
|
|
- smod_adduids = NULL;
|
|
|
- slapi_ch_array_free(adduids);
|
|
|
- adduids = NULL;
|
|
|
- slapi_ch_array_free(smod_deluids);
|
|
|
- smod_deluids = NULL;
|
|
|
- slapi_ch_array_free(deluids);
|
|
|
- deluids = NULL;
|
|
|
- slapi_ch_array_free(moduids);
|
|
|
- moduids = NULL;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ if (doModify) {
|
|
|
+ if (adduids) {
|
|
|
+ int i;
|
|
|
+ for (i = 0; adduids[i]; i++) {
|
|
|
+ if (!smods_has_mod(smods, LDAP_MOD_ADD, "memberUid", adduids[i])) {
|
|
|
+ slapi_mods_add_string(smods, LDAP_MOD_ADD, "memberUid", adduids[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ int i;
|
|
|
+ for (i = 0; moduids && moduids[i]; i++) {
|
|
|
+ if (!smods_has_mod(smods, LDAP_MOD_ADD, "memberUid", moduids[i])) {
|
|
|
+ slapi_mods_add_string(smods, LDAP_MOD_ADD, "memberUid", moduids[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ slapi_ch_array_free(moduids);
|
|
|
+ moduids = NULL;
|
|
|
+ for (i = 0; deluids && deluids[i]; i++) {
|
|
|
+ if (!smods_has_mod(smods, LDAP_MOD_DELETE, "memberUid", deluids[i])) {
|
|
|
+ slapi_mods_add_string(smods, LDAP_MOD_DELETE, "memberUid",
|
|
|
+ deluids[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (slapi_is_loglevel_set(SLAPI_LOG_PLUGIN))
|
|
|
+ slapi_mods_dump(smods, "memberUid - mods dump");
|
|
|
+ *do_modify = 1;
|
|
|
+ posix_winsync_config_set_MOFTaskCreated();
|
|
|
+ }
|
|
|
+ slapi_ch_array_free(smod_adduids);
|
|
|
+ smod_adduids = NULL;
|
|
|
+ slapi_ch_array_free(adduids);
|
|
|
+ adduids = NULL;
|
|
|
+ slapi_ch_array_free(smod_deluids);
|
|
|
+ smod_deluids = NULL;
|
|
|
+ slapi_ch_array_free(deluids);
|
|
|
+ deluids = NULL;
|
|
|
+ slapi_ch_array_free(moduids);
|
|
|
+ moduids = NULL;
|
|
|
+
|
|
|
slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME, "modGroupMembership: <==\n");
|
|
|
return 0;
|
|
|
}
|
|
|
@@ -419,77 +425,65 @@ int
|
|
|
addGroupMembership(Slapi_Entry *entry, Slapi_Entry *ad_entry)
|
|
|
{
|
|
|
int rc = 0;
|
|
|
- Slapi_Attr * obj_attr = NULL; /* Entry attributes */
|
|
|
+ int i;
|
|
|
|
|
|
slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME, "addGroupMembership: ==>\n");
|
|
|
|
|
|
- rc = slapi_entry_attr_find(entry, "objectclass", &obj_attr);
|
|
|
- if (rc == 0) { /* Found objectclasses, so... */
|
|
|
- int i;
|
|
|
- Slapi_Value * value = NULL; /* Attribute values */
|
|
|
+ if(!isPosixGroup(entry)) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
|
|
|
- slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
|
|
|
- "addGroupMembership scan objectclasses\n");
|
|
|
- for (i = slapi_attr_first_value(obj_attr, &value); i != -1;
|
|
|
- i = slapi_attr_next_value(obj_attr, i, &value)) {
|
|
|
- Slapi_Attr * um_attr = NULL; /* Entry attributes uniquemember */
|
|
|
- Slapi_Attr * muid_attr = NULL; /* Entry attributes memebrof */
|
|
|
- Slapi_Value * uid_value = NULL; /* uniquemember Attribute values */
|
|
|
- const char * oc = NULL;
|
|
|
-
|
|
|
- oc = slapi_value_get_string(value);
|
|
|
- if (strncasecmp(oc, "posixGroup", 11) == 0) { /* entry has objectclass posixGroup */
|
|
|
- Slapi_ValueSet *newvs = NULL;
|
|
|
+ Slapi_Attr * um_attr = NULL; /* Entry attributes uniquemember */
|
|
|
+ Slapi_Attr * muid_attr = NULL; /* Entry attributes memebrof */
|
|
|
+ Slapi_Value * uid_value = NULL; /* uniquemember Attribute values */
|
|
|
|
|
|
- slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
|
|
|
- "addGroupMembership: posixGroup -> look for uniquemember\n");
|
|
|
- rc = slapi_entry_attr_find(entry, "uniquemember", &um_attr);
|
|
|
- if (rc != 0 || um_attr == NULL) {
|
|
|
- slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
|
|
|
- "addGroupMembership end: attribute uniquemember not found\n");
|
|
|
- return 0;
|
|
|
- }
|
|
|
- /* found attribute uniquemember */
|
|
|
- rc = slapi_entry_attr_find(entry, "memberUid", &muid_attr);
|
|
|
- if (rc != 0 || muid_attr == NULL) { /* Found no memberUid list, so create */
|
|
|
- slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
|
|
|
- "addGroupMembership: no attribute memberUid\n");
|
|
|
- }
|
|
|
- newvs = slapi_valueset_new();
|
|
|
- /* ...loop for value... */
|
|
|
- for (i = slapi_attr_first_value(um_attr, &uid_value); i != -1;
|
|
|
- i = slapi_attr_next_value(um_attr, i, &uid_value)) {
|
|
|
- const char *uid_dn = NULL;
|
|
|
- static char *uid = NULL;
|
|
|
- Slapi_Value *v = NULL;
|
|
|
-
|
|
|
- uid_dn = slapi_value_get_string(uid_value);
|
|
|
- slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
|
|
|
- "addGroupMembership: perform member %s\n", uid_dn);
|
|
|
- uid = searchUid(uid_dn);
|
|
|
- if (uid == NULL) {
|
|
|
- slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
|
|
|
- "addGroupMembership: uid not found for %s, cannot do anything\n",
|
|
|
- uid_dn); /* member on longer on server, do nothing */
|
|
|
- } else {
|
|
|
- v = slapi_value_new_string(uid);
|
|
|
- slapi_ch_free_string(&uid);
|
|
|
- if (slapi_attr_value_find(muid_attr, slapi_value_get_berval(v)) == 0) {
|
|
|
- slapi_value_free(&v);
|
|
|
- continue;
|
|
|
- }
|
|
|
- slapi_valueset_add_value(newvs, v);
|
|
|
- slapi_value_free(&v);
|
|
|
- }
|
|
|
- }
|
|
|
- slapi_entry_add_valueset(entry, "memberUid", newvs);
|
|
|
- slapi_valueset_free(newvs);
|
|
|
- posix_winsync_config_get_MOFTaskCreated();
|
|
|
+ Slapi_ValueSet *newvs = NULL;
|
|
|
|
|
|
- break;
|
|
|
+ slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
|
|
|
+ "addGroupMembership: posixGroup -> look for uniquemember\n");
|
|
|
+ rc = slapi_entry_attr_find(entry, "uniquemember", &um_attr);
|
|
|
+ if (rc != 0 || um_attr == NULL) {
|
|
|
+ slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
|
|
|
+ "addGroupMembership end: attribute uniquemember not found\n");
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ /* found attribute uniquemember */
|
|
|
+ rc = slapi_entry_attr_find(entry, "memberUid", &muid_attr);
|
|
|
+ if (rc != 0 || muid_attr == NULL) { /* Found no memberUid list, so create */
|
|
|
+ slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
|
|
|
+ "addGroupMembership: no attribute memberUid\n");
|
|
|
+ }
|
|
|
+ newvs = slapi_valueset_new();
|
|
|
+ /* ...loop for value... */
|
|
|
+ for (i = slapi_attr_first_value(um_attr, &uid_value); i != -1;
|
|
|
+ i = slapi_attr_next_value(um_attr, i, &uid_value)) {
|
|
|
+ const char *uid_dn = NULL;
|
|
|
+ static char *uid = NULL;
|
|
|
+ Slapi_Value *v = NULL;
|
|
|
+
|
|
|
+ uid_dn = slapi_value_get_string(uid_value);
|
|
|
+ slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
|
|
|
+ "addGroupMembership: perform member %s\n", uid_dn);
|
|
|
+ uid = searchUid(uid_dn);
|
|
|
+ if (uid == NULL) {
|
|
|
+ slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
|
|
|
+ "addGroupMembership: uid not found for %s, cannot do anything\n",
|
|
|
+ uid_dn); /* member on longer on server, do nothing */
|
|
|
+ } else {
|
|
|
+ v = slapi_value_new_string(uid);
|
|
|
+ slapi_ch_free_string(&uid);
|
|
|
+ if (slapi_attr_value_find(muid_attr, slapi_value_get_berval(v)) == 0) {
|
|
|
+ slapi_value_free(&v);
|
|
|
+ continue;
|
|
|
}
|
|
|
+ slapi_valueset_add_value(newvs, v);
|
|
|
+ slapi_value_free(&v);
|
|
|
}
|
|
|
}
|
|
|
+ slapi_entry_add_valueset(entry, "memberUid", newvs);
|
|
|
+ slapi_valueset_free(newvs);
|
|
|
+ posix_winsync_config_get_MOFTaskCreated();
|
|
|
+
|
|
|
slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME, "addGroupMembership: <==\n");
|
|
|
return 0;
|
|
|
}
|