590d18
From 964bce5fd60bbb52be1dcc67e628a6c1ab62e356 Mon Sep 17 00:00:00 2001
590d18
From: Tomas Babej <tbabej@redhat.com>
590d18
Date: Thu, 23 Jul 2015 12:36:53 +0200
590d18
Subject: [PATCH] idviews: Restrict anchor to name and name to anchor
590d18
 conversions
590d18
590d18
When converting the ID override anchor from AD SID representation to
590d18
the object name, we need to properly restrict the type of the object
590d18
that is being resolved.
590d18
590d18
The same restriction applies for the opposite direction, when
590d18
converting the object name to it's SID.
590d18
590d18
https://fedorahosted.org/freeipa/ticket/5029
590d18
590d18
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
590d18
---
590d18
 ipalib/plugins/idviews.py | 50 +++++++++++++++++++++++++++++++++++++++++++----
590d18
 1 file changed, 46 insertions(+), 4 deletions(-)
590d18
590d18
diff --git a/ipalib/plugins/idviews.py b/ipalib/plugins/idviews.py
590d18
index 67f52f886f0e19288a829616603c7aef6768f8db..c4f748132642f8702dcd12d38367dc36f4bc4a3c 100644
590d18
--- a/ipalib/plugins/idviews.py
590d18
+++ b/ipalib/plugins/idviews.py
590d18
@@ -432,6 +432,36 @@ class idview_unapply(baseidview_apply):
590d18
 
590d18
 
590d18
 # ID overrides helper methods
590d18
+def verify_trusted_domain_object_type(validator, desired_type, name_or_sid):
590d18
+
590d18
+    object_type = validator.get_trusted_domain_object_type(name_or_sid)
590d18
+
590d18
+    if object_type == desired_type:
590d18
+        # In case SSSD returns the same type as the type being
590d18
+        # searched, no problems here.
590d18
+        return True
590d18
+
590d18
+    elif desired_type == 'user' and object_type == 'both':
590d18
+        # Type both denotes users with magic private groups.
590d18
+        # Overriding attributes for such users is OK.
590d18
+        return True
590d18
+
590d18
+    elif desired_type == 'group' and object_type == 'both':
590d18
+        # However, overriding attributes for magic private groups
590d18
+        # does not make sense. One should override the GID of
590d18
+        # the user itself.
590d18
+
590d18
+        raise errors.ConversionError(
590d18
+            name='identifier',
590d18
+            error=_('You are trying to reference a magic private group '
590d18
+                    'which is not allowed to be overriden. '
590d18
+                    'Try overriding the GID attribute of the '
590d18
+                    'corresponding user instead.')
590d18
+            )
590d18
+
590d18
+    return False
590d18
+
590d18
+
590d18
 def resolve_object_to_anchor(ldap, obj_type, obj, fallback_to_ldap):
590d18
     """
590d18
     Resolves the user/group name to the anchor uuid:
590d18
@@ -482,9 +512,15 @@ def resolve_object_to_anchor(ldap, obj_type, obj, fallback_to_ldap):
590d18
                 sid = domain_validator.get_trusted_domain_object_sid(obj,
590d18
                         fallback_to_ldap=fallback_to_ldap)
590d18
 
590d18
-                # There is no domain prefix since SID contains information
590d18
-                # about the domain
590d18
-                return SID_ANCHOR_PREFIX + sid
590d18
+                # We need to verify that the object type is correct
590d18
+                type_correct = verify_trusted_domain_object_type(
590d18
+                        domain_validator, obj_type, sid)
590d18
+
590d18
+                if type_correct:
590d18
+                    # There is no domain prefix since SID contains information
590d18
+                    # about the domain
590d18
+                    return SID_ANCHOR_PREFIX + sid
590d18
+
590d18
     except errors.ValidationError:
590d18
         # Domain validator raises Validation Error if object name does not
590d18
         # contain domain part (either NETBIOS\ prefix or @domain.name suffix)
590d18
@@ -539,7 +575,13 @@ def resolve_anchor_to_object_name(ldap, obj_type, anchor):
590d18
             domain_validator = ipaserver.dcerpc.DomainValidator(api)
590d18
             if domain_validator.is_configured():
590d18
                 name = domain_validator.get_trusted_domain_object_from_sid(sid)
590d18
-                return name
590d18
+
590d18
+                # We need to verify that the object type is correct
590d18
+                type_correct = verify_trusted_domain_object_type(
590d18
+                        domain_validator, obj_type, name)
590d18
+
590d18
+                if type_correct:
590d18
+                    return name
590d18
 
590d18
     # No acceptable object was found
590d18
     raise errors.NotFound(
590d18
-- 
590d18
2.4.3
590d18