Commit b6b70769 authored by Shane Hathaway's avatar Shane Hathaway

- Fixed mistake in restrictedTraverse() security.

- Made ZPT invoke DTML the normal way.
parent 2e2c0a72
...@@ -89,12 +89,13 @@ Page Template-specific implementation of TALES, with handlers ...@@ -89,12 +89,13 @@ Page Template-specific implementation of TALES, with handlers
for Python expressions, Python string literals, and paths. for Python expressions, Python string literals, and paths.
""" """
__version__='$Revision: 1.4 $'[11:-2] __version__='$Revision: 1.5 $'[11:-2]
import re, sys import re, sys
from TALES import Engine, CompilerError, _valid_name, NAME_RE from TALES import Engine, CompilerError, _valid_name, NAME_RE
from string import strip, split, join, replace, lstrip from string import strip, split, join, replace, lstrip
from DocumentTemplate.DT_Util import TemplateDict from DocumentTemplate.DT_Util import TemplateDict
from Acquisition import aq_base
_engine = None _engine = None
def getEngine(): def getEngine():
...@@ -114,6 +115,24 @@ def installHandlers(engine): ...@@ -114,6 +115,24 @@ def installHandlers(engine):
reg('not', NotExpr) reg('not', NotExpr)
reg('import', ImportExpr) reg('import', ImportExpr)
def render(ob):
"""
Calls the object, possibly a document template, or just returns it if
not callable. (From DT_Util.py)
"""
base = aq_base(ob)
if callable(base):
try:
if getattr(base, 'isDocTemp', 0):
ob = ob(ob, ob.REQUEST)
else:
ob = ob()
except AttributeError, n:
if n != '__call__':
raise
return ob
class PathExpr: class PathExpr:
def __init__(self, name, expr): def __init__(self, name, expr):
self._s = expr self._s = expr
...@@ -158,10 +177,7 @@ class PathExpr: ...@@ -158,10 +177,7 @@ class PathExpr:
return 1 return 1
if self._name == 'nocall': if self._name == 'nocall':
return ob return ob
mm = TemplateDict() return render(ob)
mm._push(var)
mm._push({'_ob': ob})
return mm['_ob']
def __str__(self): def __str__(self):
return '%s expression "%s"' % (self._name, self._s) return '%s expression "%s"' % (self._name, self._s)
...@@ -310,6 +326,8 @@ def restrictedTraverse(self, path): ...@@ -310,6 +326,8 @@ def restrictedTraverse(self, path):
if not path: return self if not path: return self
__traceback_info__ = path
get=getattr get=getattr
N=None N=None
M=[] #marker M=[] #marker
...@@ -335,7 +353,7 @@ def restrictedTraverse(self, path): ...@@ -335,7 +353,7 @@ def restrictedTraverse(self, path):
raise 'NotFound', name raise 'NotFound', name
if name=='..': if name=='..':
o=getattr(object, 'aq_parent', M) o = getattr(object, 'aq_parent', M)
if o is not M: if o is not M:
if not securityManager.validate(object, object, name, o): if not securityManager.validate(object, object, name, o):
raise 'Unauthorized', name raise 'Unauthorized', name
...@@ -354,19 +372,13 @@ def restrictedTraverse(self, path): ...@@ -354,19 +372,13 @@ def restrictedTraverse(self, path):
else: else:
o=get(object, name, M) o=get(object, name, M)
if o is not M: if o is not M:
# waaaa # Check security.
if hasattr(get(object,'aq_base',object), name): if hasattr(object, 'aq_acquire'):
# value wasn't acquired object.aq_acquire(
if not securityManager.validate( name, validate2, securityManager.validate)
object, object, name, o):
raise 'Unauthorized', name
pass
else: else:
if not securityManager.validate( if not securityManager.validate(object, object, name, o):
object, None, name, o):
raise 'Unauthorized', name raise 'Unauthorized', name
pass
else: else:
o=object[name] o=object[name]
if not securityManager.validate(object, object, None, o): if not securityManager.validate(object, object, None, o):
...@@ -374,3 +386,9 @@ def restrictedTraverse(self, path): ...@@ -374,3 +386,9 @@ def restrictedTraverse(self, path):
object = o object = o
return object return object
def validate2(orig, inst, name, v, real_validate):
if not real_validate(orig, inst, name, v):
raise 'Unauthorized', name
return 1
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