[Zope-Checkins] CVS: Zope3/lib/python/Zope/Security/secproxy - secproxy.c:1.1.2.2

Guido van Rossum guido@python.org
Wed, 17 Apr 2002 21:08:27 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/Security/secproxy
In directory cvs.zope.org:/tmp/cvs-serv28458

Modified Files:
      Tag: SecurityProxy-branch
	secproxy.c 
Log Message:
Make wrap_getattro call checker.check_getattr() and checkValue() as
prescribed by IChecker.  This doesn't crash for me now, but that
doesn't mean much.  No time for a real test suite.  Barry, take it
away!


=== Zope3/lib/python/Zope/Security/secproxy/secproxy.c 1.1.2.1 => 1.1.2.2 ===
+ * Based on code by Fred Drake.
+ */
+
 #include <Python.h>
 #include "secproxy.h"
 
@@ -79,19 +83,27 @@
 static PyObject *
 wrap_getattro(PyObject *self, PyObject *name)
 {
-	PyObject *result;
-	PyObject *checker;
-	PyObject *object;
+	PyObject *object, *checker, *allowed, *value;
+	PyObject *result = NULL;
 
 	object = Wrapper_GetObject(self);
 	checker = Wrapper_GetChecker(self);
-	/* Call checker.check_getattr(object, name) */
-	result = PyObject_CallMethod(checker, "check_getattr", "OO",
-				     object, name);
-	if (result == NULL)
-		return NULL;
-	Py_DECREF(result);
-	result = PyObject_GetAttr(object, name);
+	/*
+	 * allowed = checker.check_getattr(object, name)
+	 * value = getattr(object, name)
+	 * return checker.checkValue(value, allowed)
+	 */
+	allowed = PyObject_CallMethod(
+		checker, "check_getattr", "(OO)", object, name);
+	if (allowed != NULL) {
+		value = PyObject_GetAttr(object, name);
+		if (value != NULL) {
+			result = PyObject_CallMethod(
+				checker, "checkValue", "(OO)", value, allowed);
+			Py_DECREF(value);
+		}
+		Py_DECREF(allowed);
+	}
 	return result;
 }
 
@@ -135,13 +147,15 @@
 wrap_call(PyObject *self, PyObject *args, PyObject *kw)
 {
 	if (kw)
-		return PyEval_CallObjectWithKeywords(Wrapper_GetObject(self), args, kw);
+		return PyEval_CallObjectWithKeywords(Wrapper_GetObject(self),
+						     args, kw);
 	else
 		return PyObject_CallObject(Wrapper_GetObject(self), args);
 }
 
 /*
  *   Number methods
+ *   XXX need more :-)
  */
 
 static int
@@ -233,11 +247,6 @@
 	wrap_setitem,				/* mp_ass_subscript */
 };
 
-static PyMethodDef
-wrap_methods[] = {
-	{NULL}
-};
-
 /*
  * XXX Numeric methods are not yet supported.
  */
@@ -272,7 +281,7 @@
 	0,					/* tp_weaklistoffset */
 	wrap_iter,				/* tp_iter */
 	0,					/* tp_iternext */
-	wrap_methods,				/* tp_methods */
+	0,					/* tp_methods */
 	0,					/* tp_members */
 	0,					/* tp_getset */
 	0,					/* tp_base */
@@ -298,15 +307,14 @@
 void
 initsecproxy(void)
 {
-	PyObject *m = Py_InitModule3("secproxy",
-				     module_functions,
-				     module___doc__);
-
-	if (m == NULL)
-		return;
+	PyObject *m;
 
 	WrapperType.ob_type = &PyType_Type;
 	if (PyType_Ready(&WrapperType) < 0)
+		return;
+
+	m = Py_InitModule3("secproxy", module_functions, module___doc__);
+	if (m == NULL)
 		return;
 
 	Py_INCREF(&WrapperType);