These two situations in netgroup-add need to be distinguished:
 1) Netgroup cannot be added because a hostgroup with the same name
    created a colliding managed netgroup
 2) Another native netgroup with the same name exists

This patch checks the colliding netgroup and raise appropriate
error message based on this finding.

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

>From 1ea7d945cfcfddc71c5b12bc9c724e6f71704f53 Mon Sep 17 00:00:00 2001
From: Martin Kosek <[email protected]>
Date: Wed, 1 Feb 2012 16:33:54 +0100
Subject: [PATCH] Improve netgroup-add error messages

These two situations in netgroup-add need to be distinguished:
 1) Netgroup cannot be added because a hostgroup with the same name
    created a colliding managed netgroup
 2) Another native netgroup with the same name exists

This patch checks the colliding netgroup and raise appropriate
error message based on this finding.

https://fedorahosted.org/freeipa/ticket/2069
---
 ipalib/plugins/netgroup.py |   18 +++++++++++-------
 1 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/ipalib/plugins/netgroup.py b/ipalib/plugins/netgroup.py
index d8c3c4707a1f8a657ba2cc82aa94173147953b04..149936dc4fc09ac7a796c8c55bed6caaf23abb76 100644
--- a/ipalib/plugins/netgroup.py
+++ b/ipalib/plugins/netgroup.py
@@ -143,13 +143,20 @@ class netgroup_add(LDAPCreate):
 
     has_output_params = LDAPCreate.has_output_params + output_params
     msg_summary = _('Added netgroup "%(value)s"')
+
+    msg_collision = _(u'hostgroup with name "%s" already exists. ' \
+                      u'Hostgroups and netgroups share a common namespace')
+
     def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options):
         entry_attrs.setdefault('nisdomainname', self.api.env.domain)
 
         try:
-            # check duplicity with netgroups first to provide proper error
-            netgroup = api.Command['netgroup_show'](keys[-1])
-            self.obj.handle_duplicate_entry(*keys)
+            dn = self.obj.get_dn(keys[-1])
+            (dn_, netgroup) = ldap.get_entry(dn, ['objectclass'])
+            if 'mepManagedEntry' in netgroup.get('objectclass', []):
+                raise errors.DuplicateEntry(message=unicode(self.msg_collision % keys[-1]))
+            else:
+                self.obj.handle_duplicate_entry(*keys)
         except errors.NotFound:
             pass
 
@@ -158,10 +165,7 @@ class netgroup_add(LDAPCreate):
             # make sure that we don't create a collision if the plugin is
             # (temporarily) disabled
             netgroup = api.Command['hostgroup_show'](keys[-1])
-            raise errors.DuplicateEntry(message=unicode(_(\
-                    u'hostgroup with name "%s" already exists. ' \
-                    u'Hostgroups and netgroups share a common namespace'\
-                    ) % keys[-1]))
+            raise errors.DuplicateEntry(message=unicode(self.msg_collision % keys[-1]))
         except errors.NotFound:
             pass
 
-- 
1.7.7.6

_______________________________________________
Freeipa-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to