For every hostgroup a managed netgroup is created (if this is allowed).
Make sure that if a stand-alone netgroup exists, a hostgroup with the
same name cannot be created to prevent collisions.

https://fedorahosted.org/freeipa/ticket/1914

>From d8b70961d51af2aa7ff2e3da3dfe9526a757be94 Mon Sep 17 00:00:00 2001
From: Martin Kosek <mko...@redhat.com>
Date: Wed, 5 Oct 2011 16:18:16 +0200
Subject: [PATCH] Prevent collisions of hostgroup and netgroup

For every hostgroup a managed netgroup is created (if this is allowed).
Make sure that if a stand-alone netgroup exists, a hostgroup with the
same name cannot be created to prevent collisions.

https://fedorahosted.org/freeipa/ticket/1914
---
 ipalib/plugins/hostgroup.py |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/ipalib/plugins/hostgroup.py b/ipalib/plugins/hostgroup.py
index 0d69d093e0fbaab30d7e99c6accfac116f5d89ff..0560bd7d2c95baa59720c41b982cac7a4bc1efe5 100644
--- a/ipalib/plugins/hostgroup.py
+++ b/ipalib/plugins/hostgroup.py
@@ -115,6 +115,17 @@ class hostgroup_add(LDAPCreate):
 
     msg_summary = _('Added hostgroup "%(value)s"')
 
+    def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options):
+        try:
+            netgroup = api.Command['netgroup_show'](keys[-1])
+            raise errors.DuplicateEntry(message=unicode(_(\
+                    u'netgroup with name "%s" already exists' % keys[-1]\
+                    )))
+        except errors.NotFound:
+            pass
+
+        return dn
+
     def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
         # Always wait for the associated netgroup to be created so we can
         # be sure to ignore it in memberOf
-- 
1.7.6.4

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to