LDAP query to get the list of users which are matching the group pattern - ldap

I am trying to query the groups from Ldap starting with groupname-* and all users part of these groups.
Group filter condition is: (CN=groupname-*).
User filter condition is: (memberof=cn=groupname*,OU=Application,OU=Groupings,DC=xx,DC=com))
This is returning all groups matching the pattern. However I'm not able to get the users details.Works only when I specify the complete group name in user filter. Is there any way to get all users matching the group pattern.

It appears you are querying AD. When searching for memberOf, only complete values are supported, not wildcards.
So your best bet is to query the groups and read their member attribute in order to get a list of user DNs.

Related

Searching for a user and associated groups on LDAP in one search

New to LDAP. The way our LDAP is arranged is People and groups. The people have user information such as name, uid, and mail. The groups have group name and multiple member field which has value like cn=First Last,cn=people,dc=comic,dc=com, listing the People that are members of the group.
Currently starting with userid and password, doing two searches:
1) Get user by searching on People base domain on uid=value. Then from the user get the first and last name.
2) Search on Groups base domain based on member=cn=First Last,cn=People,dc=comic,dc=com and iterate over the list of group objects returned to the group name field.
Am just wondering is there way to do all this in one search or are two searches necessary?
Unfortunately you cannot do what would like in one operation.
Also, what you are doing will not always work. Instead of retrieving the users first and last name you should retrieve their distinguished name (dn attribute) and do your group search based on that. First and last names can be modified within LDAP and can happen due to marriage / divorce / etc.
It is possible, provided that you implement a Reverse Group Membership Maintenance Overlay.
To determine which groups an entry is a member of without performing extra searches, the memberOf overlay is exactly what you need.
The memberof overlay updates an attribute (by default memberOf)
whenever changes occur to the membership attribute (by default member)
of entries of the objectclass (by default groupOfNames) configured to
trigger updates. Thus, it provides maintenance of the list of groups
an entry is a member of, when usual maintenance of groups is done by
modifying the members on the group entry.
You may find this Server Fault post useful for a how to.
Once you have memberOf attribute ready to be used, you may have to run ldapmodify manually on each group entries, but just once, so that all members entries can be provisioned with the corresponding group dn in their respective memberOf attribute.
Finally, to perform a group membership search for a given user, you would just search for the user entry and iterate the memberOf attribute to get group dn's.

Returning SaMAccount of members of a group

Is it possible to return the SaMAccountAttribute of members along with the distinguished name when querying the members of a group?
I have the query (&(objectCategory=group)(cn=group)) but it just returns the distinguished names of each user. I'm trying to avoid having to query each user just to get the needed attribute.
Nope it is not possible natively. That is the way the LDAP protocol works.
There is no join between requests.
Another approach could be :
Retrieve the DN of the group corresponding to the filter (&(objectCategory=group)(cn=group))
Search for all the users with a filter like : (&(objectClass=user)(memberof=<GROUP DN>)) and retrieve the samAccountName attribute only.
You will have the attribute you need, and every entry returned by a LDAP search should be accompanied by its DN.

Ldap Group filter query to excluse nested group in member list

I want to write the ldap group filter where I want to pull all the groups and their members but exclude nested group member within specified OU.
It will remove the chance of cyclic group.
For example Group A contains following member:
user 1
user 2
Group 1
In the query I only want Group A with user 1 and user 2.
The filter example is (&(objectClass=Group)(member=*)) but I do not know what are the options I can use in the member filter.
If you want to retrieve the members of a certain group you would use a filter like (&(objectClass=groupOfNames)(cn=rdn-of-the-very-group)) and include memberin the list of attributes to retrieve. Without further assistance by an extended search control you only will get direct members, so no worries about members of nested groups. In order to eliminate nested groups from the search result, include objectClassin the attribute list. You'll have to filter on the client side, though.

LDAP - filter records with two attributes equal (or different)

I want to filter LDAP records to find entries with two attributes equal (also different).
Let us assume we have records with userid.
userid=10
userid=15
Each record have name and surname and I want to filter people with identical name and surname.
I can filter people with a particular name using following filter
(&(name=Mark)(surname=Mark))
But this filter is not correct
(=(name)(surname))
nor this
name=surname
This is not possible in LDAP. LDAP does not support relational queries even on the attribute level of the same entry.
See LDAP Query Basics.

ldap query for group members

I'm trying to make an LDAP query, to get a list from all my groups/members. I can't figure out how can i do this. All my tries were unsuccesfull.
My "AD tree": mydomain.local/Mybusiness/Distribution Groups/ here are my groups
I tried with somethin' like this:
(objectCategory=user)
(memberOf=CN=Distribution Groups,OU=Mybusiness,DC=mydomain.local,DC=com)
I appreciate if somebody could help me to write an ldap query, which gives a list with my groups and the members of this groups.
The query should be:
(&(objectCategory=user)(memberOf=CN=Distribution Groups,OU=Mybusiness,DC=mydomain.local,DC=com))
You missed & and ()
Active Directory does not store the group membership on user objects. It only stores the Member list on the group. The tools show the group membership on user objects by doing queries for it.
How about:
(&(objectClass=group)(member=cn=my,ou=full,dc=domain))
(You forgot the (& ) bit in your example in the question as well).
The good way to get all the members from a group is to, make the DN of the group as the searchDN and pass the "member" as attribute to get in the search function. All of the members of the group can now be found by going through the attribute values returned by the search.
The filter can be made generic like (objectclass=*).