[Zope-Checkins] CVS: Releases/Zope/lib/python/AccessControl - SecurityInfo.py:1.12 SimpleObjectPolicies.py:1.10 ZopeGuards.py:1.10 ZopeSecurityPolicy.py:1.18 __init__.py:1.14 cAccessControl.c:1.13

Evan Simpson evan@zope.com
Fri, 11 Jan 2002 12:14:59 -0500


Update of /cvs-repository/Releases/Zope/lib/python/AccessControl
In directory cvs.zope.org:/tmp/cvs-serv29374/AccessControl

Modified Files:
	SecurityInfo.py SimpleObjectPolicies.py ZopeGuards.py 
	ZopeSecurityPolicy.py __init__.py cAccessControl.c 
Log Message:
Merge evan-modsec_fix-branch


=== Releases/Zope/lib/python/AccessControl/SecurityInfo.py 1.11 => 1.12 ===
     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)


=== Releases/Zope/lib/python/AccessControl/SimpleObjectPolicies.py 1.9 => 1.10 ===
 
 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)
+


=== Releases/Zope/lib/python/AccessControl/ZopeGuards.py 1.9 => 1.10 ===
     module = load_module(None, None, mnameparts, validate, globals, locals)
     if module is not None:
-        mtype = type(module)
         if fromlist is None:
             fromlist = ()
         try:


=== Releases/Zope/lib/python/AccessControl/ZopeSecurityPolicy.py 1.17 => 1.18 ===
                      StringType=type(''),
                      Containers=SimpleObjectPolicies.Containers,
-                     valid_aq_=('aq_parent','aq_explicit')):
+                     valid_aq_=('aq_parent','aq_inner', 'aq_explicit')):
 
 
             ############################################################


=== Releases/Zope/lib/python/AccessControl/__init__.py 1.13 => 1.14 ===
 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')


=== Releases/Zope/lib/python/AccessControl/cAccessControl.c 1.12 => 1.13 ===
 		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);