Seite 1 von 1

LDAP

Verfasst: Donnerstag 20. Dezember 2012, 11:11
von patmaster
Hi,

Ich versuche einen user und ein pwd mithilfe von LDAP zu überprüfen.
Um mich mal in LDAP einzuarbeiten versuche ich erstmal eine Suche, erfolgreich auszuführen, wobei ich kläglich scheitere.
Hier mein derzeitiger Code, den ich mir aus Snippets die ich im Netz gefunden habe gebaut habe (zensiert):

Code: Alles auswählen

'''
Created on 20.12.2012

@author: xxx
'''
import ldap
import traceback

l = ldap.initialize('ldap://domain.net')
username = "DOMAIN\user"
password = 'passwort'
try:
    l.protocol_version = ldap.VERSION3
    l.simple_bind_s(username, password)
    valid = True
except:
    print(traceback.format_exc())
    
## The next lines will also need to be changed to support your search requirements and directory
baseDN = "ou=Users"
searchScope = ldap.SCOPE_SUBTREE
## retrieve all attributes - again adjust to your needs - see documentation for more options
retrieveAttributes = None 
searchFilter = "cn=*suchbegriff*"

try:
    ldap_result_id = l.search(baseDN, searchScope, searchFilter, retrieveAttributes)
    result_set = []
    while 1:
        result_type, result_data = l.result(ldap_result_id, 0)
        if (result_data == []):
            break
        else:
            ## here you don't have to append to a list
            ## you could do whatever you want with the individual entry
            ## The appending to list is just for illustration. 
            if result_type == ldap.RES_SEARCH_ENTRY:
                result_set.append(result_data)
    print (result_set)
except:
    print(traceback.format_exc()) 
Ich bekomme leider immer folgende Exception:
OPERATIONS_ERROR: {'info': '000020D6: SvcErr: DSID-031007DB, problem 5012 (DIR_ERROR), data 0\n', 'desc': 'Operations error'}
Hat jemand eine Idee ?
Wozu ich nirgends eine Doku gefunden habe ist was eigentlich dn,dc,ou usw heißen soll.

Re: LDAP

Verfasst: Donnerstag 20. Dezember 2012, 11:40
von BlackJack
@patmaster: Wenn man bei Wikipedia nach LDAP sucht stösst man auf das RFC zu LDAP und darin auf die dazugehörigen RFCs und damit dann zu Beispiel auch auf LDIF. Da könnte man dann wieder auf die Wikipedia-Seite von schauen.

Re: LDAP

Verfasst: Donnerstag 20. Dezember 2012, 12:43
von patmaster
BlackJack hat geschrieben:@patmaster: Wenn man bei Wikipedia nach LDAP sucht stösst man auf das RFC zu LDAP und darin auf die dazugehörigen RFCs und damit dann zu Beispiel auch auf LDIF. Da könnte man dann wieder auf die Wikipedia-Seite von schauen.
Danke das hat schon mal geholfen.
Ich habe diese Zeile verändert:

Code: Alles auswählen

baseDN = "dc=ser,dc=ver,dc=net"
Das komische ist das er mir jetzt folgendes sagt:
OPERATIONS_ERROR: {'info': '00000000: LdapErr: DSID-0C090627, comment: In order to perform this operation a successful bind must be completed on the connection., data 0, vece', 'desc': 'Operations error'}
Das ist doch etwas komisch, da er sich beim bind ja nicht beschwert.
Hat jemand eine Erklärung dafür?

//EDIT:

Das hats gebracht:

Code: Alles auswählen

l.set_option(ldap.OPT_REFERRALS, 0)