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

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.

Related

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

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.

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.

LDAP: Retrieve entries from multiple OUs in one query

try to retrieve entries of objectClass 'groupOfNames' from multiple OUs from LDAP. My scheme looks like this:
ou=gp,ou=gruppen,dc=some,dc=my-company,dc=at
|
|-ou=99 (objectClass=organizaionalUnit)
|-cn=admins (objectClass=groupOfNames)
|-cn=managers (objectClass=groupOfNames)
|-ou=103 (objectClass=organizaionalUnit)
|-cn=admins (objectClass=groupOfNames)
|-cn=managers (objectClass=groupOfNames)
|-many more OUs
...
Now i try to create a query with which i can retrieve the admins/managers of the different OUs with one query. Within the CN the admins and managers groups contain the names of users that belong to theses groups. One filter i came up with was:
(cn=admins)
This Results in giving me back all the CNs of all OUs:
The search scope is set to complete subtree. How can I change this filter to get only the entries from specific OUs, e.g. ou=212917 and ou=211208, but not from the other OUs? The groups i want to extract in the end look like this:
Or is there another possibility to realise this? I'm fairly new to LDAP.
It's possible to use a very specific filter to search for only the groups with cn=admins in specific OUs.
(&(cn=admins)(|(ou:dn:=212917)(ou:dn:=211208)))
The notation means search for ou=212917 in the entry or part of the DN. Not all servers support this though, even it's part of LDAPv3 standard specifications.

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 command to delete all users attached to a group

Is there any LDAP command to delete all users attached to a specific group. Assume there are user1,user2,user3 assigned to group G1 . I want to delete all the users attached to group G1
Users are not attached to a group, entries are members of a group. To delete all entries that are members
of a group, execute a search that will return all of distinguished names that are members of the group:
make the base object of the search the distinguished name of the group
use (&) or (objectClass=*) for the filter. Some directory servers, for example Sun DSEE in certain
versions fail to properly parse the filter (&)
use base for the search scope
request the attribute type whose values are the distinguished names of the members of the groups. This varies,
but could be something like uniqueMember
Then, transmit a delete request for each distinguished name returned from the above search.
Some servers support referential integrity, if so, the members of the group will be deleted
at the same time as the entries are deleted.
See also
LDAP: Programming Practices
LDAP: Search best practices