Commit 26791c09 authored by Brian Lloyd's avatar Brian Lloyd

reenable cAccessControl

parent f54fc698
...@@ -34,28 +34,20 @@ def setImplementation(name): ...@@ -34,28 +34,20 @@ def setImplementation(name):
"""Select the policy implementation to use. """Select the policy implementation to use.
'name' must be either 'PYTHON' or 'C'. 'name' must be either 'PYTHON' or 'C'.
XXX: 'C' version is currently broken
""" """
import sys import sys
global _implementation_name global _implementation_name
#
name = name.upper() name = name.upper()
if name == _implementation_name: if name == _implementation_name:
return return
if name == "C": if name == "C":
raise NotImplementedError( # XXX from AccessControl import ImplC as impl
"'C' version of ZSP not yet working.")
try:
from AccessControl import ImplC as impl
except ImportError:
name = "PYTHON"
from AccessControl import ImplPython as impl
elif name == "PYTHON": elif name == "PYTHON":
from AccessControl import ImplPython as impl from AccessControl import ImplPython as impl
else: else:
raise ValueError("unknown policy implementation: %r" % name) raise ValueError("unknown policy implementation: %r" % name)
#
_implementation_name = name _implementation_name = name
for modname, names in _policy_names.items(): for modname, names in _policy_names.items():
__import__(modname) __import__(modname)
...@@ -91,5 +83,4 @@ _policy_names = { ...@@ -91,5 +83,4 @@ _policy_names = {
# start with the default, mostly because we need something for the tests # start with the default, mostly because we need something for the tests
#setImplementation("C") XXX: C version of ZSP isn't yet working setImplementation("C")
setImplementation("PYTHON")
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE. DAMAGE.
$Id: cAccessControl.c,v 1.25 2004/01/14 19:42:30 Brian Exp $ $Id: cAccessControl.c,v 1.26 2004/01/16 18:49:22 Brian Exp $
If you have questions regarding this software, If you have questions regarding this software,
contact: contact:
...@@ -674,6 +674,7 @@ static PyObject *unrestrictedTraverse_str = NULL; ...@@ -674,6 +674,7 @@ static PyObject *unrestrictedTraverse_str = NULL;
static PyObject *aq_validate = NULL; static PyObject *aq_validate = NULL;
static PyObject *aq_parent_str = NULL; static PyObject *aq_parent_str = NULL;
static PyObject *_check_context_str = NULL; static PyObject *_check_context_str = NULL;
static PyObject *getRoles = NULL;
static int ownerous = 1; static int ownerous = 1;
static int authenticated = 1; static int authenticated = 1;
...@@ -785,8 +786,8 @@ static PyObject *ZopeSecurityPolicy_validate(PyObject *self, PyObject *args) { ...@@ -785,8 +786,8 @@ static PyObject *ZopeSecurityPolicy_validate(PyObject *self, PyObject *args) {
return NULL; return NULL;
/*| # Provide special rules for acquisition attributes /*| # Provide special rules for acquisition attributes
**| if type(name) in (StringType, UnicodeType): **| if isinstance(name, str):
**| if name[:3] == 'aq_' and name not in valid_aq_: **| if name.startswith('aq_') and name not in valid_aq_:
**| raise Unauthorized(name, value) **| raise Unauthorized(name, value)
*/ */
...@@ -807,6 +808,30 @@ static PyObject *ZopeSecurityPolicy_validate(PyObject *self, PyObject *args) { ...@@ -807,6 +808,30 @@ static PyObject *ZopeSecurityPolicy_validate(PyObject *self, PyObject *args) {
Py_XINCREF(roles); /* Convert the borrowed ref to a real one */ Py_XINCREF(roles); /* Convert the borrowed ref to a real one */
/* new */
/*| # If roles weren't passed in, we'll try to get them from
**| # the object
**|
**| if roles is _noroles:
**| roles = getRoles(container, name, value, _noroles)
*/
if (roles == NULL) {
/* Note that the '_noroles' arg is just a marker - our C version
of _noroles is null */
roles = callfunction4(getRoles, container, name, value, getRoles);
if (roles == getRoles) {
Py_DECREF(roles);
roles = NULL;
}
if (roles == NULL)
PyErr_Clear();
}
/* old */
/*| # If roles weren't passed in, we'll try to get them from /*| # If roles weren't passed in, we'll try to get them from
**| # the object **| # the object
**| **|
...@@ -820,6 +845,10 @@ static PyObject *ZopeSecurityPolicy_validate(PyObject *self, PyObject *args) { ...@@ -820,6 +845,10 @@ static PyObject *ZopeSecurityPolicy_validate(PyObject *self, PyObject *args) {
PyErr_Clear(); PyErr_Clear();
} }
/*| # We still might not have any roles /*| # We still might not have any roles
**| **|
**| if roles is _noroles: **| if roles is _noroles:
...@@ -2323,7 +2352,7 @@ void initcAccessControl(void) { ...@@ -2323,7 +2352,7 @@ void initcAccessControl(void) {
module = Py_InitModule3("cAccessControl", module = Py_InitModule3("cAccessControl",
cAccessControl_methods, cAccessControl_methods,
"$Id: cAccessControl.c,v 1.25 2004/01/14 19:42:30 Brian Exp $\n"); "$Id: cAccessControl.c,v 1.26 2004/01/16 18:49:22 Brian Exp $\n");
aq_init(); /* For Python <= 2.1.1, aq_init() should be after aq_init(); /* For Python <= 2.1.1, aq_init() should be after
Py_InitModule(). */ Py_InitModule(). */
...@@ -2362,6 +2391,16 @@ void initcAccessControl(void) { ...@@ -2362,6 +2391,16 @@ void initcAccessControl(void) {
Py_DECREF(module); Py_DECREF(module);
module = NULL; module = NULL;
/*| from ZopeSecurityPolicy import getRoles
*/
IMPORT(module, "AccessControl.ZopeSecurityPolicy");
GETATTR(module, getRoles);
Py_DECREF(module);
module = NULL;
/*| from unauthorized import Unauthorized /*| from unauthorized import Unauthorized
*/ */
......
...@@ -38,11 +38,6 @@ class AccessControlImplementationTest(unittest.TestCase): ...@@ -38,11 +38,6 @@ class AccessControlImplementationTest(unittest.TestCase):
setImplementation(self.original) setImplementation(self.original)
def test_setImplemenationC(self): def test_setImplemenationC(self):
# XXX: 'C' ZSP is not yet working
self.assertRaises( NotImplementedError, setImplementation, "C")
return
setImplementation("C") setImplementation("C")
name = getImplementationName() name = getImplementationName()
if self.have_cAccessControl: if self.have_cAccessControl:
......
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