Skip to content

Instantly share code, notes, and snippets.

@ekohl
Created December 3, 2009 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ekohl/248162 to your computer and use it in GitHub Desktop.
Save ekohl/248162 to your computer and use it in GitHub Desktop.
Retrieves all unique values of a specific LDAP attribute
from ldap import initialize, SCOPE_SUBTREE
from operator import add
config = {'host': 'ldap://HOST', 'base': 'dc=example,dc=com', 'attr': 'l'}
result = initialize(config['host']).search_s(config['base'], SCOPE_SUBTREE, '(%s=*)' % config['attr'], [ config['attr'] ] )
data = reduce(add, [ entry[config['attr']] for (dn, entry) in result ])
print "\n".join(sorted(set(map(str.lower, data))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment