user912877 user912877 - 1 year ago 66
Python Question

python ldap attribute query

I am trying to modify a python based-authenticator for murmur (voip software) to work with my ldap tree.

The LDAP authenticator is available at:

It works, but not quite with my ldap layout, so I have to modify it a bit. I know an approach that could work, but unfortunately I have no more knowledge about python than what I learned from google (I have some other programming expertise though).

My ldap layout looks like this:

charName=xxx, ou=people, dc=xxx, dc=com

Under this there are attributes stored such as
among others.

The python script above is tailored to use a ldap bind to authenticate. In this case I would have to bind as
"charName=logindatafromapp, ou=people, dc=xxx, dc=com"
. Unfortunately people don't log in with
but with
which is an attribute, but isn't identical with

I do not know a way to bind to an attribute, so here is my idea:

  • I first bind as ldap admin and perform a search over all entries for
    and match that value against
    . If a match is found I grab the matching
    and re-bind with that
    as originally intended.

I am currently stuck on querying the
value and at assigning that value to a variable, so i could use it in a second ldap bind (google didn't really help me).

Here is my code:

ldap_conn = ldap.initialize(ldap_uri, 0)
res = ldap_conn.search_s('ou=people,dc=xxxxxx,dc=com', ldap.SCOPE_ONELEVEL,'login=trony',['charName'])

It then prints
"[('charName=Trony,ou=people,dc=xxxxxxx,dc=com', {'charName': ['Trony']})]"

) is a temporary filter that I would have to replace with the
var. My problem is now how can I assign
(in this case) to a variable? The output seems to be a special struct?

Answer Source

'Trony' is in


You take the first element of the list — it's a tuple; then the first element of the tuple; it's a dictionary; then value of the dictionary for the key 'charName'; it's a list once again; and then the first element of the list.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download