Accessing openLDAP Server from Python Script inside a Zope CMF.

Jens Vagelpohl jens at zope.com
Tue Jul 16 13:54:07 CEST 2002


this is a Zope question, not a python-ldap question.

the simple solution: put the code into an external method instead of 
a python script.

the hard solution: look into the documentation for the pythonscript 
product itself to find out how to enable access to outside modules.

zope security is doing its job here. you cannot just willy-nilly 
import stuff in a script that can be edited through the web, it's a 
security disaster waiting to happen. that's why zope disallows what 
you are trying to do by default.

jens


On Tuesday, July 16, 2002, at 04:42 , Ashish Gautam wrote:

> Hi all,
> I am trying to access openLDAP server from a python script inside 
> CMF site
> of Zope.
> I have python-ldap module installed on a linux machine.
> My final intention is to Add an LDAP entry in to LDAP server.
> Following code i have written in a python script  just to get 
> started by
> connecting to LDAP server and accessing the existing contents.
>
> Script starts:
>
> import ldap
>
> ldapCon = ldap.open("localhost")
>
> ldapCon.simple_bind_s("cn=Manager,o=Lambent","secret");
>
> print 
> ldapCon.search_s("ou=HR,o=Lambent",ldap.SCOPE_SUBTREE,"objectclass=*")
>
> return printed
>
> Script ends.
>
> I am clueless as to what is causing this problem.
>
> Following error i have encountered :
>
>
> An error was encountered while publishing this resource.
>
> Error Type: Unauthorized
> Error Value: You are not allowed to access open in this context
>
>
>
> Troubleshooting Suggestions
>
> The URL may be incorrect.
> The parameters passed to this resource may be incorrect.
> A resource that this resource relies on may be encountering an error.
>
> For more detailed information about the error, please refer to the HTML
> source for this page.
>
> If the error persists please contact the site maintainer. Thank you 
> for your
> patience.
>
> Traceback (innermost last):
>   File /usr/local/Zope2.5.1/lib/python/ZPublisher/Publish.py, line 
> 150, in
> publish_module
>   File /usr/local/Zope2.5.1/lib/python/ZPublisher/Publish.py, line 
> 114, in
> publish
>   File /usr/local/Zope2.5.1/lib/python/Zope/__init__.py, line 159, in
> zpublisher_exception_hook
>     (Object: testsite)
>   File /usr/local/Zope2.5.1/lib/python/ZPublisher/Publish.py, line 
> 98, in
> publish
>   File /usr/local/Zope2.5.1/lib/python/ZPublisher/mapply.py, line 
> 88, in
> mapply
>     (Object: ldap)
>   File /usr/local/Zope2.5.1/lib/python/ZPublisher/Publish.py, line 
> 39, in
> call_object
>     (Object: ldap)
>   File 
> /usr/local/Zope2.5.1/lib/python/Shared/DC/Scripts/Bindings.py, line
> 252, in __call__
>     (Object: ldap)
>   File 
> /usr/local/Zope2.5.1/lib/python/Shared/DC/Scripts/Bindings.py, line
> 283, in _bindAndExec
>     (Object: ldap)
>   File
> /usr/local/Zope2.5.1/lib/python/Products/PythonScripts/PythonScript.py, 
> line
> 302, in _exec
>     (Object: ldap)
>     (Info: ({'script': <PythonScript instance at 8bbbeb0>, 'context':
> <CMFSite instance at 8b10098>, 'container': <CMFSite instance at 
> 8b10098>,
> 'traverse_subpath': []}, (), {}, None))
>   File Script (Python), line 7, in ldap
>   File /usr/local/Zope2.5.1/lib/python/AccessControl/ZopeGuards.py, 
> line 60,
> in guarded_getattr
>     (Object: ldap)
>   File 
> /usr/local/Zope2.5.1/lib/python/AccessControl/SecurityManager.py,
> line 83, in validate
>   File 
> /usr/local/Zope2.5.1/lib/python/AccessControl/ZopeSecurityPolicy.py,
> line 145, in validate
> Unauthorized: (see above)
>
>
> Plz reply ASAP,
>
> Regards
> Ashish.
>
>
>
>
> 


More information about the python-ldap mailing list