[Zope-Checkins] CVS: Packages/AccessControl - SecurityInfo.py:1.11.2.1 SimpleObjectPolicies.py:1.9.8.1 ZopeGuards.py:1.9.8.1 ZopeSecurityPolicy.py:1.17.2.1 __init__.py:1.13.8.1 cAccessControl.c:1.12.18.1
Evan Simpson
evan@zope.com
Wed, 2 Jan 2002 11:21:16 -0500
Update of /cvs-repository/Packages/AccessControl
In directory cvs.zope.org:/tmp/cvs-serv28972/AccessControl
Modified Files:
Tag: evan-modsec_fix-branch
SecurityInfo.py SimpleObjectPolicies.py ZopeGuards.py
ZopeSecurityPolicy.py __init__.py cAccessControl.c
Log Message:
Security cleanup. Make multiple module security declarations play nicely
together, move utility functions into AccessControl, add tests. Added the
ability to declare simple security for types.
=== Packages/AccessControl/SecurityInfo.py 1.11 => 1.11.2.1 ===
return module
-class ModuleSecurityInfo(SecurityInfo):
+def ModuleSecurityInfo(module_name=None):
+ if module_name is not None:
+ modsec = _moduleSecurity.get(module_name, None)
+ if modsec is not None:
+ return modsec
+ dot = module_name.rfind('.')
+ if dot > 0:
+ # If the module is in a package, recursively make sure
+ # there are security declarations for the package steps
+ # leading to the module
+ modname = module_name[dot + 1:]
+ pmodsec = ModuleSecurityInfo(module_name[:dot])
+ if not pmodsec.names.has_key(modname):
+ pmodsec.declarePublic(modname)
+ return _ModuleSecurityInfo(module_name)
+
+class _ModuleSecurityInfo(SecurityInfo):
"""Encapsulate security information for modules."""
__roles__ = ACCESS_PRIVATE
@@ -255,3 +271,25 @@
"""Cannot set default roles for permissions in a module."""
pass
+# Handy little utility functions
+
+def allow_module(module_name):
+ """Allow a module and all its contents to be used from a
+ restricted Script. The argument module_name may be a simple
+ or dotted module or package name. Note that if a package
+ path is given, all modules in the path will be available."""
+ ModuleSecurityInfo(module_name).setDefaultAccess(1)
+ dot = module_name.find('.')
+ while dot > 0:
+ ModuleSecurityInfo(module_name[:dot]).setDefaultAccess(1)
+ dot = module_name.find('.', dot + 1)
+
+def allow_class(Class):
+ """Allow a class and all of its methods to be used from a
+ restricted Script. The argument Class must be a class."""
+ Class._security = sec = ClassSecurityInfo()
+ sec.declareObjectPublic()
+ sec.setDefaultAccess(1)
+ sec.apply(Class)
+ from Globals import InitializeClass
+ InitializeClass(Class)
=== Packages/AccessControl/SimpleObjectPolicies.py 1.9 => 1.9.8.1 ===
Containers=ContainerAssertions.get
+
+from types import IntType, DictType, TypeType
+def allow_type(Type, allowed=1):
+ """Allow a type and all of its methods and attributes to be used from
+ restricted code. The argument Type must be a type."""
+ if type(Type) is not TypeType:
+ raise ValueError, "%s is not a type" % `Type`
+ if hasattr(Type, '__roles__'):
+ raise ValueError, "%s handles its own security" % `Type`
+ if not (isinstance(allowed, IntType) or isinstance(allowed, DictType)):
+ raise ValueError, "The 'allowed' argument must be an int or dict."
+ ContainerAssertions.update(Type, allowed)
+
=== Packages/AccessControl/ZopeGuards.py 1.9 => 1.9.8.1 ===
module = load_module(None, None, mnameparts, validate, globals, locals)
if module is not None:
- mtype = type(module)
if fromlist is None:
fromlist = ()
try:
=== Packages/AccessControl/ZopeSecurityPolicy.py 1.17 => 1.17.2.1 ===
StringType=type(''),
Containers=SimpleObjectPolicies.Containers,
- valid_aq_=('aq_parent','aq_explicit')):
+ valid_aq_=('aq_parent','aq_inner', 'aq_explicit')):
############################################################
=== Packages/AccessControl/__init__.py 1.13 => 1.13.8.1 ===
from SecurityInfo import ACCESS_PUBLIC
from SecurityInfo import ACCESS_NONE
-from SecurityInfo import secureModule
+from SecurityInfo import secureModule, allow_module, allow_class
+from SimpleObjectPolicies import allow_type
from ZopeGuards import full_read_guard, full_write_guard, safe_builtins
ModuleSecurityInfo('AccessControl').declarePublic('getSecurityManager')
=== Packages/AccessControl/cAccessControl.c 1.12 => 1.12.18.1 ===
if (*sname == 'a' && sname[1]=='q' && sname[2]=='_') {
if (strcmp(sname,"aq_parent") != 0 &&
+ strcmp(sname,"aq_inner") != 0 &&
strcmp(sname,"aq_explicit") != 0) {
/* Access control violation, return 0 */
return PyInt_FromLong(0);