title: How to find all the groups the user is a member? (LDAP)
body: <p>I am trying to get all the groups that a certain user is a member of.</p>
  
  <p>I have the following <em>structures</em> in ldap:</p>
  
  <pre><code>o=myOrganization
       ou=unit1
           cn=admin
           cn=guess
  </code></pre>
  
  <p>and</p>
  
  <pre><code>ou=users
      cn=ann
      cn=bob
      cn=carla
  </code></pre>
  
  <ul>
  <li><code>myOrganization</code> is an instance of Organization</li>
  <li><code>unit1</code> is an instance of OrganizationUnit</li>
  <li><code>admin</code> and <code>guess</code> are both GroupOfNames and have everyone as a member</li>
  <li><code>ann</code>, <code>bob</code>, and <code>carla</code> are instances of Person</li>
  </ul>
  
  <p>Currently, I am using the ldap module on python and this is what I have:</p>
  
  <pre><code>import ldap
  l = ldap.initialize("ldap://my_host")
  l.simple_bind_s("[my_dn]", "[my_pass]")
  ldap_result = l.search("[BASE_DN]", ldap.SCOPE_SUBTREE, "(&amp;(objectClass=Person)(cn=ann))", None)
  res_type, data = l.result(ldap_result, 0)
  print(data)
  </code></pre>
  
  <p>And I am able to get the user <code>ann</code>; but, how do I go about getting the groups <code>Ann</code> belongs to?</p>
  
  <p>I tried, the following from <a href="http://timony.com/mickzblog/2015/08/03/python-ldap-list-the-group-membership-of-a-user/" rel="noreferrer">this</a> page:</p>
  
  <pre><code>search_filter='(|(&amp;(objectClass=*)(member=cn=ann)))'
  results = l.search_s([BASE_DN], ldap.SCOPE_SUBTREE, search_filter, ['cn',])
  </code></pre>
  
  <p>But I got an empty list. I also tried various combinations of queries, but they all return empty.</p>
  
  <p>PS: I am using OpenLDAP on a linux machine</p>