Comment 2 for bug 1464090

Revision history for this message
Tim Landscheidt (scfc) wrote :

Tested with:

| #!/usr/bin/python3
|
| import re
|
| import ldap3
|
| if __name__ == '__main__':
| # Get user name and password.
| with open('/etc/ldap.conf', 'r') as f:
| for line in f.readlines():
| if line == '\n':
| continue
| m = re.match('^([^ ]+) +(.*?) *\n$', line)
| if m.group(1) == 'binddn':
| binddn = m.group(2)
| elif m.group(1) == 'bindpw':
| bindpw = m.group(2)
|
| # Connect to LDAP server.
| server = ldap3.Server('ldap-eqiad.wikimedia.org')
| conn = ldap3.Connection(server, read_only=True,
| user=binddn, password=bindpw)
| conn.bind()
| conn.start_tls()
|
| # Query.
| conn.search('ou=hosts,dc=wikimedia,dc=org',
| '(puppetVar=instanceproject=%s)' % 'tools',
| ldap3.SEARCH_SCOPE_WHOLE_SUBTREE,
| attributes=ldap3.ALL_ATTRIBUTES)
| for responseitem in conn.response:
| print(repr(responseitem))

for python3-ldap3 and amending the shebang line and the print call for python-ldap3 (Python 2).