634

I have a search query in LDAP like this. What exactly does this query mean?

("CN=Dev-India,OU=Distribution Groups,DC=gp,DC=gl,DC=google,DC=com");
Ayed Mohamed Amine
  • 587
  • 2
  • 10
  • 30
Ritesh Chandora
  • 8,382
  • 5
  • 21
  • 38
  • 9
    It does not work, You do not have a proper LDAP Query. What you have is a fully distinguished name probably from a Active Directory Entry. Perhaps you should explain what you are trying to accomplish. – jwilleke Sep 13 '13 at 08:14
  • 1
    check this https://www.rlmueller.net/LDAP_Binding.htm#:~:text=The%20moniker%20%22cn%22%20means%20Common%20Name.%20moniker%20%22dc%22,As%20an%20example%2C%20the%20Distinguished%20Name%20%22cn%3DJoe%20Smith%2Cou%3DEast%2Cdc%3DMyDomain%2Cdc%3Dcom%22 – Jing He Jan 04 '21 at 02:57

4 Answers4

1029
  • CN = Common Name
  • OU = Organizational Unit
  • DC = Domain Component

These are all parts of the X.500 Directory Specification, which defines nodes in a LDAP directory.

You can also read up on LDAP data Interchange Format (LDIF), which is an alternate format.

You read it from right to left, the right-most component is the root of the tree, and the left most component is the node (or leaf) you want to reach.

Each = pair is a search criteria.

With your example query

("CN=Dev-India,OU=Distribution Groups,DC=gp,DC=gl,DC=google,DC=com");

In effect the query is:

From the com Domain Component, find the google Domain Component, and then inside it the gl Domain Component and then inside it the gp Domain Component.

In the gp Domain Component, find the Organizational Unit called Distribution Groups and then find the object that has a common name of Dev-India.

Pang
  • 9,564
  • 146
  • 81
  • 122
Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284
  • 7
    These are all part of the X.500 Directory specification, Distinguised Name component. Nothing specifically to do with LDIF at all. LDIF is not "how the LDAP tree is 'filtered'": that's the LDAP syntax specification, which is another thing altogether. – user207421 Mar 24 '15 at 09:09
  • 1
    TIL X.509 is an extension of X.500, eg TLS is based on LDAP :grumpycat: (This is a huge oversimplification) – ThorSummoner Aug 24 '17 at 21:38
  • @EJP How do I ask for several objects by their CN? Like if I want `Dev-India2` along with `Dev-India`? – arrowd Nov 29 '17 at 17:12
  • @arrowd read https://ldap.com/ldap-filters/. You could use the OR operator (a pipe follwed by the entries) or the SUBSTRING operator (star operator). OR > `(|(cn=Dev-India2)(cn=Dev-India))` SUBSTRING > `(cn=Dev-India*)` – strongmmc Feb 23 '22 at 14:23
576

What are CN, OU, DC?

From RFC2253 (UTF-8 String Representation of Distinguished Names):

String  X.500 AttributeType
------------------------------
CN      commonName
L       localityName
ST      stateOrProvinceName
O       organizationName
OU      organizationalUnitName
C       countryName
STREET  streetAddress
DC      domainComponent
UID     userid

**What does the string from that query mean?**

The string ("CN=Dev-India,OU=Distribution Groups,DC=gp,DC=gl,DC=google,DC=com") is a path from an hierarchical structure (DIT = Directory Information Tree) and should be read from right (root) to left (leaf).

It is a DN (Distinguished Name) (a series of comma-separated key/value pairs used to identify entries uniquely in the directory hierarchy). The DN is actually the entry's fully qualified name.

Here you can see an example where I added some more possible entries.
The actual path is represented using green.

LDAP tree

The following paths represent DNs (and their value depends on what you want to get after the query is run):

  • "DC=gp,DC=gl,DC=google,DC=com"
  • "OU=Distribution Groups,DC=gp,DC=gl,DC=google,DC=com"
  • "OU=People,DC=gp,DC=gl,DC=google,DC=com"
  • "OU=Groups,DC=gp,DC=gl,DC=google,DC=com"
  • "CN=QA-Romania,OU=Distribution Groups,DC=gp,DC=gl,DC=google,DC=com"
  • "CN=Dev-India,OU=Distribution Groups,DC=gp,DC=gl,DC=google,DC=com"
  • "CN=Diana Anton,OU=People,DC=gp,DC=gl,DC=google,DC=com"
Community
  • 1
  • 1
ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
  • Any idea why you may get an empty remaining name? For [this](http://stackoverflow.com/q/39372374/5606016) there is actually an open bounty on it – A_Di-Matteo Sep 12 '16 at 21:24
  • @ROMANIA_engineer, if I am logged in my windows machine (client) where can I get this information? – Artanis Zeratul Jul 31 '18 at 03:30
  • I know this post is quite old, yet, for the googlers (like me) that search for an answer on @ArtanisZeratul question for the information: [this answer](https://serverfault.com/questions/22866/how-can-i-determine-my-user-accounts-ou-in-a-windows-domain) helped me on that, if you look for the servers just try with nslookup: `nslookup -type=srv _ldap._tcp.MY.DOMAIN` – Rüdiger Dec 17 '18 at 12:23
  • Also, for those that need deeper information about the structure of the AD they're in (and do not have something like an Admin Console to look it up) you can use the ADSI editor provided by Windows (access via MMC) - [how to access ADSI Edit](https://support.symantec.com/en_US/article.HOWTO9340.html) – Rüdiger Dec 17 '18 at 22:02
26

I want to add somethings different from definitions of words. Most of them will be visual.

Technically, LDAP is just a protocol that defines the method by which directory data is accessed.Necessarily, it also defines and describes how data is represented in the directory service

Data is represented in an LDAP system as a hierarchy of objects, each of which is called an entry. The resulting tree structure is called a Directory Information Tree (DIT). The top of the tree is commonly called the root (a.k.a base or the suffix).the Data (Information) Model

To navigate the DIT we can define a path (a DN) to the place where our data is (cn=DEV-India,ou=Distrubition Groups,dc=gp,dc=gl,dc=google,dc=com will take us to a unique entry) or we can define a path (a DN) to where we think our data is (say, ou=Distrubition Groups,dc=gp,dc=gl,dc=google,dc=com) then search for the attribute=value or multiple attribute=value pairs to find our target entry (or entries).

enter image description here

If you want to get more depth information, you visit here

fgul
  • 5,763
  • 2
  • 46
  • 32
1

At least with Active Directory, I have been able to search by DistinguishedName by doing an LDAP query in this format (assuming that such a record exists with this distinguishedName):

"(distinguishedName=CN=Dev-India,OU=Distribution Groups,DC=gp,DC=gl,DC=google,DC=com)"
Craig Rodrigues
  • 771
  • 2
  • 7
  • 16