[Zope] updating LDAPserver from python script

Ashish Gautam AshishG@lambenttek.com
Mon, 22 Jul 2002 15:25:56 +0530


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.
My approach to add an entry from python script is correct or its bound to
fail?

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


During this attempt following error occured :
Error Value: You are not allowed to access open in this context


Then someone provided a link in which there was a solution for this error.
In that the solution was to add a new directory in Products folder of Zope.

Add a new python script __init_.py containing following code :

# Global module assertions for Python scripts

from Products.PythonScripts.Utility import allow_module

allow_module('ldap')
allow_module('ldap.async')
allow_module('ldap.modlist')
allow_module('ldif')
allow_module('ldapurl')

After adding above script, and keeping the python script as it is i got
following error.

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



Site Error

An error was encountered while publishing this resource.

Error Type: Unauthorized
Error Value: You are not allowed to access simple_bind_s 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: ldapSCRIPTCall)
  File /usr/local/Zope2.5.1/lib/python/ZPublisher/Publish.py, line 39, in
call_object
    (Object: ldapSCRIPTCall)
  File /usr/local/Zope2.5.1/lib/python/OFS/DTMLMethod.py, line 127, in
__call__
    (Object: ldapSCRIPTCall)
  File /usr/local/Zope2.5.1/lib/python/DocumentTemplate/DT_String.py, line
473, in __call__
    (Object: ldapSCRIPTCall)
  File /usr/local/Zope2.5.1/lib/python/Shared/DC/Scripts/Bindings.py, line
266, in __render_with_namespace__
    (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 8fd9298>, 'context':
<CMFSite instance at 8ad4ff0>, 'container': <CMFSite instance at 8ad4ff0>,
'traverse_subpath': []}, (), {}, None))
  File Script (Python), line 9, in ldap
  File /usr/local/Zope2.5.1/lib/python/AccessControl/ZopeGuards.py, line 60,
in guarded_getattr
  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)


Any solution for this will be most welcome.

Ashish.