Hi,

this should prevent adding duplicate segments or segments with same start and end node
>From 759790e3c6c87ebe75610fdcfda06c6d4bc00475 Mon Sep 17 00:00:00 2001
From: Ludwig Krispenz <lkris...@redhat.com>
Date: Wed, 3 Jun 2015 14:22:52 +0200
Subject: [PATCH] check for existing and self referential segments

---
 daemons/ipa-slapi-plugins/topology/topology_pre.c | 30 +++++++++++++++--------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/daemons/ipa-slapi-plugins/topology/topology_pre.c b/daemons/ipa-slapi-plugins/topology/topology_pre.c
index 528f72b69dfe0e57c5312e558c6e0ac5f58801fb..0a0cd65b592e2dc796a179e035598e5f641bb01e 100644
--- a/daemons/ipa-slapi-plugins/topology/topology_pre.c
+++ b/daemons/ipa-slapi-plugins/topology/topology_pre.c
@@ -279,21 +279,31 @@ ipa_topo_check_connect_reject(Slapi_PBlock *pb)
     if (pi && 0 == strcasecmp(pi, ipa_topo_get_plugin_id())) {
         return 0;
     }
-    slapi_pblock_get(pb,SLAPI_DELETE_EXISTING_ENTRY,&add_entry);
+    slapi_pblock_get(pb,SLAPI_ADD_ENTRY,&add_entry);
     if (TOPO_SEGMENT_ENTRY != ipa_topo_check_entry_type(add_entry)) {
         return 0;
     } else {
         /* a new segment is added
          * verify that the segment does not yet exist
          */
-        TopoReplicaSegment *tsegm;
-        TopoReplica *tconf = ipa_topo_util_get_conf_for_segment(add_entry);
-        tsegm = ipa_topo_util_find_segment(tconf, add_entry);
-        if (tsegm) {
-            slapi_log_error(SLAPI_LOG_FATAL, IPA_TOPO_PLUGIN_SUBSYSTEM,
-                            "segment to be added does already exist\n");
-            rc = 1;
+        char *leftnode = slapi_entry_attr_get_charptr(add_entry,"ipaReplTopoSegmentLeftNode");
+        char *rightnode = slapi_entry_attr_get_charptr(add_entry,"ipaReplTopoSegmentRightNode");
+        if (0 == strcasecmp(leftnode,rightnode)) {
+                slapi_log_error(SLAPI_LOG_FATAL, IPA_TOPO_PLUGIN_SUBSYSTEM,
+                                "segment is self referential\n");
+                rc = 1;
+        } else {
+            TopoReplicaSegment *tsegm;
+            TopoReplica *tconf = ipa_topo_util_get_conf_for_segment(add_entry);
+            tsegm = ipa_topo_util_find_segment(tconf, add_entry);
+            if (tsegm) {
+                slapi_log_error(SLAPI_LOG_FATAL, IPA_TOPO_PLUGIN_SUBSYSTEM,
+                                "segment to be added does already exist\n");
+                rc = 1;
+            }
         }
+        slapi_ch_free_string(&leftnode);
+        slapi_ch_free_string(&rightnode);
     }
     return rc;
 }
@@ -378,8 +388,8 @@ int ipa_topo_pre_add(Slapi_PBlock *pb)
     } else if (ipa_topo_check_connect_reject(pb)) {
         int rc = LDAP_UNWILLING_TO_PERFORM;
         char *errtxt;
-        errtxt = slapi_ch_smprintf("Segment already exists in topology."
-                                   "Add rejected.\n");
+        errtxt = slapi_ch_smprintf("Segment already exists in topology or"
+                                   " is self referential. Add rejected.\n");
         slapi_pblock_set(pb, SLAPI_PB_RESULT_TEXT, errtxt);
         slapi_pblock_set(pb, SLAPI_RESULT_CODE, &rc);
         result = SLAPI_PLUGIN_FAILURE;
-- 
2.1.0

-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to