Commit 065657f1 authored by Shane Hathaway's avatar Shane Hathaway

Added comments to allowed() and converted an old AttributeError bug into an

authentication failure.
parent 061b94cc
...@@ -84,7 +84,7 @@ ...@@ -84,7 +84,7 @@
############################################################################## ##############################################################################
"""Access control package""" """Access control package"""
__version__='$Revision: 1.124 $'[11:-2] __version__='$Revision: 1.125 $'[11:-2]
import Globals, socket, ts_regex, SpecialUsers import Globals, socket, ts_regex, SpecialUsers
import os import os
...@@ -217,40 +217,58 @@ class BasicUser(Implicit): ...@@ -217,40 +217,58 @@ class BasicUser(Implicit):
parent=parent.aq_parent parent=parent.aq_parent
else: return r else: return r
def allowed(self, parent, roles=None):
"""Check whether the user has access to parent, assuming that def allowed(self, object, object_roles=None):
parent.__roles__ is the given roles.""" """Check whether the user has access to object, assuming that
if roles is None or 'Anonymous' in roles: object.__roles__ is the given roles."""
if object_roles is None or 'Anonymous' in object_roles:
return 1 return 1
usr_roles=self.getRolesInContext(parent) usr_roles=self.getRolesInContext(object)
for role in roles: for role in object_roles:
if role in usr_roles: if role in usr_roles:
if (hasattr(self,'aq_parent') and # The user apparently has one of the necessary
hasattr(self.aq_parent,'aq_parent')): # roles, but first make sure the object exists
if parent is None: return 1 # in the context of the parent of the acl_users
if (not hasattr(parent, 'aq_inContextOf') and # folder.
hasattr(parent, 'im_self')): ufolder = getattr(self, 'aq_parent', None)
# This is a method, grab it's self. ucontext = getattr(ufolder, 'aq_parent', None)
parent=parent.im_self if ucontext is not None:
if not parent.aq_inContextOf(self.aq_parent.aq_parent,1): if object is None:
if 'Shared' in roles: # This is a strange rule, though
# it doesn't cause any security holes. SDH
return 1
if not hasattr(object, 'aq_inContextOf'):
if hasattr(object, 'im_self'):
# This is a method. Grab its self.
object=object.im_self
if not hasattr(object, 'aq_inContextOf'):
# object is not wrapped, therefore we
# can't determine context.
# Fail the access attempt. Otherwise
# this would be a security hole.
return None
if not object.aq_inContextOf(ucontext, 1):
if 'Shared' in object_roles:
# Damn, old role setting. Waaa # Damn, old role setting. Waaa
roles=self._shared_roles(parent) object_roles=self._shared_roles(object)
if 'Anonymous' in roles: return 1 if 'Anonymous' in roles: return 1
return None return None
# Note that if self were not wrapped, it would
# not be possible to determine the user's context
# and this method would return 1.
# However, as long as user folders always return
# wrapped user objects, this is safe.
return 1 return 1
if 'Shared' in roles: if 'Shared' in roles:
# Damn, old role setting. Waaa # Damn, old role setting. Waaa
roles=self._shared_roles(parent) roles=self._shared_roles(object)
if roles is None or 'Anonymous' in roles: return 1 if roles is None or 'Anonymous' in roles: return 1
while 'Shared' in roles: roles.remove('Shared') while 'Shared' in roles: roles.remove('Shared')
return self.allowed(parent,roles) return self.allowed(object,roles)
return None return None
hasRole=allowed hasRole=allowed
domains=[] domains=[]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment