Benutzer-Werkzeuge

Webseiten-Werkzeuge


python:python_ldap
>>> import ldap
>>> l = ldap.initialize('ldap://localhost:1390')
>>> l.search_s('ou=Testing,dc=stroeder,dc=de',ldap.SCOPE_SUBTREE,'(cn=fred*)',['cn','mail'])
[('cn=Fred Feuerstein,ou=Testing,dc=stroeder,dc=de', {'cn': ['Fred Feuerstein']})]
>>> r = l.search_s('ou=Testing,dc=stroeder,dc=de',ldap.SCOPE_SUBTREE,'(objectClass=*)',['cn','mail'])
>>> for dn,entry in r:
>>>   print 'Processing',repr(dn)
>>>   handle_ldap_entry(entry)
 
 
 
def list_email(): 
  filter="(objectClass=person)"
  attr=['mail','cn','uid','sn','givenName']
  resultId=lconn.search(ldapbase,2,filter,attr)
  result_type, result_data = lconn.result(resultId)
  for ldap_dn,ldapuser in result_data:
    print ldap_dn
    print "%s,%s" % ( 
                                 ldapuser['cn'][0],
                                 ldapuser['mail'][0],
                               )  
 
 
lconn=ldap.initialize('ldaps://'+ldaphost)
try:
  lconn.simple_bind_s()
except ldap.LDAPError, e:
  print e
  is_allconnect=False
else:
  try:
    lconn.simple_bind_s('cn=admin,dc=fh-sm,dc=de',
                        getpass.getpass("passwort für admin:"))
  except ldap.INVALID_CREDENTIALS:
    print "bind fehlgeschlagen, passwort falsch!"
 
if __name__ == "__main__":
  list_email()
python/python_ldap.txt · Zuletzt geändert: 2024/08/07 13:39 von 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki