LDAP query to get list of members in an AD group - active-directory

I checked a few posts asked the similar questions before, but none works for my case, not sure if something wrong on my side or it's the AD.
So I have security group at path:
CN=MigratedUsers,OU=Azure Groups,OU=Security Groups,OU=National Organization,DC=abc,DC=firm,AD
And in the MigratedUsers group, there is a member property with a few AD users in the group.
I am trying to get the list of users, so I can iterate through them.
So in my base location I specified:
OU=Azure Groups,OU=Security Groups,OU=National Organization,DC=abc,DC=firm
For the LDAP Filter I have:
(&(objectCategory=user)(memberOf=CN=MigratedUsers,OU=Azure Groups,OU=Security Groups,OU=National Organization,DC=abc,DC=firm))
The result returned 0 records.
I tried other combinations such as (&(objectCategory=group)(CN=MigratedUsers)), it doesn't work either.
So, could anyone point out to me if anything in my query is wrong or I need to start checking something else like AD settings etc.
Thank you.

Your first filter looks fine :
(&(objectCategory=user)(memberOf=CN=MigratedUsers,OU=Azure Groups,OU=Security Groups,OU=National Organization,DC=abc,DC=firm))
But the search base is not, (it's a group search base, while you want to retrieve user entries). The user base should look like this :
OU=Users,OU=National Organization,DC=abc,DC=firm

You're searching for users, but you set the base of the search to:
OU=Azure Groups,OU=Security Groups,OU=National Organization,DC=abc,DC=firm
That tells it to only return users that are in the Azure Groups OU. I'm guessing that there are no users in that OU. Set the base of the search to the root of the domain (e.g. DC=abc,DC=firm), or just don't set it at all, since that will be the default.
Your first filter is the correct one (which has the full DN of the group).

Related

LDAP query for Window AD

For authentication in Jitsi Meet, we would like to read out a Windows AD group with an ldap query. Unfortunately our ldap query does not work.
LDAP_URL=ldaps://server.domain.local:636/
LDAP_BASE=DC=domain,DC=local
LDAP_BINDDN=CN=bind_user,OU=Administrative Accounts,OU=Benutzer,DC=domain,DC=local
LDAP_BINDPW=*
LDAP_FILTER= (&(|objectclass=user))(|(memberof=CN=group,OU=Jitsi,OU=Sicherheit,OU=Gruppen,DC=domain,DC=local)
(primaryGroupID=4989))
The error must be due to the filter, it works with the filter LDAP_FILTER = (sAMAccountName =% u).
Can you tell me what is wrong with our query.
A few things stand out to me:
The | in front of objectClass should not be there.
You have two closing parentheses after the objectClass condition, but the second one should be moved to the end of the whole query.
Oddly, objectClass=user will actually end up including other objects than just user accounts (like computer accounts). If you want to filter to only user objects, you have to use both (objectClass=user)(objectCategory=person). But that would only matter if you have other types of objects as members of that group.
Maybe this is just an error with pasting into the question, but there is a line break before (primaryGroupID=
I've never used Jitsi, but it may or may not like the space after LDAP_FILTER=. The other examples I see online don't show a space there.
It should look like this:
LDAP_FILTER=(&(objectclass=user)(objectCategory=person)(|(memberof=CN=group,OU=Jitsi,OU=Sicherheit,OU=Gruppen,DC=domain,DC=local)(primaryGroupID=4989)))
That means: find all user objects that are either members of that group, or have a primary group ID of 4989.

How to query for users where one set is deeper in the tree than the other

Let's say you have two sets of users:
OU=IT Dept,OU=Groups,DC=mycompany,DC=com
OU=XYZ Corp,OU=Temp Accounts,OU=Groups,DC=mycompany,DC=com
How would you express the query for that? I tried a search base of OU=Groups,DC=mycompany,DC=com and a filter of (|(OU=IT Dept)(OU=XYZ Corp,OU=Temp Accounts)) and that didn't work.
Never had to do much with LDAP, so please excuse the somewhat open-ended question.
Let's say you have two sets of users:
OU=IT Dept,OU=Groups,DC=mycompany,DC=com
OU=XYZ Corp,OU=Temp Accounts,OU=Groups,DC=mycompany,DC=com
These are not the valid distinguishedName for user objects.
User objects are stored in some parent container (like OUs), and their distinguishedName starts with CN. OUs are top level containers which contain child objects like users, computers, child OUs, etc.
I tried a search base of OU=Groups,DC=mycompany,DC=com and a filter of
(|(OU=IT Dept)(OU=XYZ Corp,OU=Temp Accounts)) and that didn't work.
Your filter didn't work because you didn't select the appropriate filtering conditions. You need to apply the filter for (objectCategory=person) or (objectCategory=user). You can also use objectClass as the filtering parameter instead of objectCategory. Check the link Filter on objectCategory and objectClass to know in detail.
How would you express the query for that?
Assuming your users are as below:
CN=Firstname lastname,OU=IT Dept,OU=Groups,DC=mycompany,DC=com
CN=Firstname lastname,OU=XYZ Corp,OU=Temp Accounts,OU=Groups,DC=mycompany,DC=com
Then your LDAP query should have SearchBase set to what you currently have (OU=Groups,DC=mycompany,DC=com), and filter on (|(objectCategory=person)(objectCategory=user)) and any additional filter if you'd like, e.g., you may want to search by sAMAccountName, name, etc.
As highlighted in the second para, you can also use objectClass as the filter type to get the desired result.

Get users "memberOf" AD-groups

I try to get all users "memberOf" all groups begining with "JE_"
I know that I cannot do the following:
memberOf=CN=JE*,OU=JE,OU=Gruppen,DC=subd,DC=dom,DC=net
But all the JE_* are located under a knot called "JE". Is it possible to get all users memberOf the groups located under the knot "JE"?
yes but you need to approach the problem differently. Rather than search against the user object you should search against teh group object with the user's DN.
For example, consider the user
cn=dave,OU=user,DC=subd,DC=dom,DC=net
The user is a member of several JE* groups.
CN=JE_1,OU=JE,OU=Gruppen,DC=subd,DC=dom,DC=net
CN=JE_2,OU=JE,OU=Gruppen,DC=subd,DC=dom,DC=net
CN=JE_3,OU=JE,OU=Gruppen,DC=subd,DC=dom,DC=net
In order to find the JE* groups to which the user belongs search for groups with a base of OU=JE,OU=Gruppen,DC=subd,DC=dom,DC=net and a search filter of
(&(objectclass=group)(member=cn=dave,OU=user,DC=subd,DC=dom,DC=net))
That will return all of the JE* group objects that contain the user in question. Ensure to specify that you only want the group name returned as an attribute otherwise all of the members will be returned too. Not a problem if there are only a handful but it might be a nuisance if there are thousands.

LDAP nested group filter for microsoft AD

I would like to write a search filter which would help me retrieve all groups which a user is part of.
For instance:
Say I am retrieving entries for user A (which is part of group A). And group A may be part of group B and group D which in turn may be part of group E.
Now, my search filter should return me MemberOf attribute as all possible groups which user A is part of (in this specific case it is Group A, B, D, E).
Any pointers on how the search filter can look like?
This should do what you are asking about. It will return the FDN of each group the user is a memberOf, however, this queries the group, not the user.
As an example, to find all the groups that "CN=John Smith,DC=MyDomain,DC=NET" is a member of, set the base to the groups container DN; for example (OU=groupsOU,DC=MyDomain,DC=NET) and the scope to subtree, and use the following filter.
(member:1.2.840.113556.1.4.1941:=(CN=John Smith,DC=MyDomain,DC=NET))
-jim
There is an attribute called tokenGroups in user object. It's a constructed attributes calculated by Active Directory on the runtime. It includes all the groups the user object belong to.
Make sure your domain has a Global Catalog and make sure the account that you are using Pre-Windows 2000 Compatible Access group. Then, make sure tokenGroups is specified as one of the returned property. Do a base scope search on the user object.
You can use adfind.exe (joeware) to sort out this issue and to utilize standard ldap filters that are described here. For example:
http://social.technet.microsoft.com/wiki/contents/articles/5392.active-directory-ldap-syntax-filters.aspx
Group nesting is specified to be like this:
(member:1.2.840.113556.1.4.1941:=cn=Jim Smith,ou=West,dc=Domain,dc=com)
and if you use adfind, then it would look like this:
adfind -f "(member:1.2.840.113556.1.4.1941:=cn=Jim Smith,ou=West,dc=Domain,dc=com)" samaccountname -list
If you want to have output other than samaccountname, for example displayname, or mail attribute, just add to the list. Also if you want to search multiple users, then you might want to have inputfile containing all users and some script to extract each lines to adfind for example.

single line LDAP query that enumerates users from a group within a supergroup

I have a scheme that looks like this:
Users exist like UserA, UserB, UserC.
Groups exist like OverGroup, SubGroup.
OverGroup automatically adds new users like UserA, UserB, etc. to its membership.
SubGroup I created myself. I have set OverGroup to be a member of SubGroup.
I want to be able to one-line query SubGroup and retrieve not OverGroup, i.e.:
Values:
CN=OverGroup,OU=Groups,DC=example,DC=com
but the full enumeration of the actual Users (User A, B, C) within OverGroup, i.e.:
Values:
CN=UserA,OU=OtherOU,DC=example,DC=com
CN=UserB,OU=OtherOU,DC=example,DC=com
CN=UserC,OU=OtherOU,DC=example,DC=com
Is there a one-liner LDAP filter that could retrieve this? (It will be put into the ExternalAuth configuration 'ldap' section in a Request Tracker instance. Pretty sure I can only do this with one query the ExternalAuth module can understand.)
Everything I try does not work, and from my reading, it does not seem possible to enumerate a list of users within a group that is a member of another group with any one-line query. Thoughts?
Active Directory has a special search filter option that allows it to filter through chained objects, like nested groups. The capability is described here.
Here is an example of how to retrieve all users in a group, including nested groups:
(&(objectClass=user)(memberof:1.2.840.113556.1.4.1941:={0}))
where {0} is the DN of the parent group.
(&(objectClass=user)(memberof:1.2.840.113556.1.4.1941:=CN=MPV_BedPlacement,OU=Security Groups,OU=Groups,OU=CCHCS,DC=CCHCS,DC=LDAP))
You have to add the full DN for the group and no curly braces.

Resources