EN 
30.11.2025 Ondřej WELCOME IN MY WORLD

This website is originally written in the Czech language. Most content is machine (AI) translated into English. The translation may not be exact and may contain errors.

Tento článek si můžete zobrazit v originální české verzi. You can view this article in the original Czech version.
Adresářové služby a LDAP

Directory Services and LDAP

| Petr Bouška - Samuraj |
This article only briefly describes directory services, focusing mainly on Active Directory, and the protocol for communicating with LDAP directory services. In practice, the terms directory, directory service, and LDAP are often used interchangeably, and this article explains the interrelationships between them. This is a theoretical introduction to the practical use of LDAP in PHP.
displayed: 73 149x (72 364 CZ, 785 EN) | Comments [16]
Here's the translated HTML content:

Directory

Directory is a database (hierarchical structure) in which information about named objects on the network is stored, organized, and grouped. Examples include computers, printers, services, domains, or user accounts. A directory differs from a relational database; it is designed for frequent reading and searching and only occasional writing. In a directory, we can store data of various types, such as text, digital certificates, or images. We can restrict access to records using ACL (Access Control List).

Directory Service

Directory service (DS) is an application or group of applications that store and organize information about users and resources in a computer network. A directory service accesses a directory, sometimes referred to as a directory repository. The directory service also functions as a central authentication authority, enabling (secure) authentication of resources (users, services, computers).

Directory service provides information from the directory to administrators, users, applications, etc. The directory service creates a physical network topology and protocols to make everything transparent to users. A directory service can be part of an operating system or an application (e.g., email). Most network operating systems use directory services.

Directory services are very suitable for certain purposes that are in the style of a card index, such as managing users, phone numbers, and similar data. The authentication feature is equally widely used. On the other hand, compared to classic relational databases, they have some disadvantages, such as data control (referential integrity, etc.), complex queries, and extensive modifications.

A widespread example of a directory service is Microsoft's Active Directory (AD). AD uses LDAP (like most directory services) and complies with the LDAP v3 standard described in RFC 3377.

LDAP

LDAP stands for Lightweight Directory Access Protocol, which is an application protocol for querying and modifying directory services over TCP/IP. In the 1980s, a group of X.500 standards (DAP, DSP, DISP, DOP) was created, covering directory services. LDAP was created by simplifying the X.500 standard and focusing on TCP/IP.

LDAP uses LDAP Data Interchange Format (LDIF), which is a standardized text format for data exchange. During transmission, data is encoded using Lightweight Basic Encoding Rules (LBER), but this is not for security reasons but due to the heterogeneity of the environment, so it is very easy to decode the data.

LDAP is described using four models:

  • information model - schema - describes the structure of information (attributes) in the directory
  • naming model - describes how information is organized and referenced
  • functional model - describes what can be done with the information
  • security model - how information is protected

Information Model - Schema

Information in the directory is stored in a tree structure, which is referred to as the Directory Information Tree (DIT). The root of the directory tree is rootDSE, which contains global information about the directory and has no name or class. The information model is based on records that contain information about some object (something specific), such as a user or computer. In Active Directory, LDAP records are called objects. Objects are composed of a group of attributes, which always have a type and one or more values.

The implementation of the information model is called a schema, which is a set of objects that define the structure and content of each object that can be created in the directory service. The schema thus defines all possible object classes and attributes. Default schemas for a particular directory can be extended; an example is adding an Exchange server to AD, which extends the schema with additional attributes needed for mail services.

Object classes are categories of objects that can be created in the directory. In LDAP, the term objectClass is used, and it can be, for example, user, computer, organizationalUnit, domain, container, group. Object classes are categorized into one of three categories: Structural, Abstract, and Auxiliary.

Note: An object can be classified into multiple classes at once. For example, a user in AD is classified into the classes top, person, organizationalPerson, and user. Or a computer is in top, person, organizationalPerson, user, computer.

Because an object is often classified into several objectClasses, searching is less efficient and may not be precise (for example, when searching by objectClass=user, computers will also be found). Therefore, we can use searching by object category, i.e., the attribute objectCategory. Unlike objectClass, objectCategory has only one value (it's a classSchema object), which should refer to the most specific class in the object class hierarchy. It can be, for example, user, computer, group, organizationalUnit.

Note: Each classSchema object has a defaultObjectCategory attribute, which for most classes is the class itself. When searching, if we specify objectCategory = X, X is the ldapDisplayName of the class. LDAP automatically expands this expression to objectCategory = defaultObjectCategory of class X. The objectCategory attribute is stored in the form of a distinguished name, and LDAP automatically converts to this form.

Object attributes are characteristics (properties) of objects. An attribute can contain one or more values, for example, first name, last name, email. Certain attributes belong to a certain object class, and the schema also defines which values must be filled and which are optional. The schema also determines what types of values an attribute can have, for example, text string, integer.

Depending on where the object is located in the tree structure, it is either a leaf (leaf object, has no descendants) or a container (container object). A container can contain one or more objects.

The following table shows several common attributes used in AD.

name description
sAMAccountName SAM Account Name, login username that supports older systems
sAMAccountType account type
userPrincipalName UPN, login name of the user account in the form <user>@<DNS-domain-name>
displayName name used by applications (e.g., Exchange)
givenName first name
sn surname
description description
mail email address
company company name
department department in the company
location location
streetAddress street
memberOf list of groups of which it is a member

Naming Model

Distinguished Name - DN

To identify objects, a Distinguished Name (DN) is used, which is a unique identifier of the object and contains the full path to the record (position in the tree). The DN consists of the object name and the names of individual containers and domains that contain the object, separated by commas. Individual items contain the attribute name and the assigned attribute value, for example ou=employees.

The following image shows an example of part of an AD directory for the domain company.com. In the container (organizational unit) employees, there is a user John Smith, for whom DN = cn=John Smith,ou=employees,dc=company,dc=com.

Část adresáře

Sometimes we don't need to specify the entire path to the object, and we can then use a Relative Distinguished Name (RDN), which is relative and unique in the given container. It is the last part of the DN; for our user, it is RDN = cn=John Smith.

Other Identification Options

A common identification of an object in LDAP and also in AD is using DN, but there are other methods specifically for Active Directory.

We can use OID (Object Identifiers), which is a hierarchical, unique identifier, composed of decimal digits separated by dots. It is the same identifier as in SNMP. It is common in X.500.

In Active Directory, each object is assigned a unique 128-bit number, which is called GUID (globally unique identifier). This number is permanent and does not change when the object is moved within the forest.

Active Directory also uses a variation of DN, which is referred to as AD canonical name, and an example is the notation company.com/employees/John Smith.

Naming Attributes

Each part of DN is expressed using attribute_type=value. The attribute type used to describe RDN is referred to as a naming attribute. Each class has an assigned naming attribute, for example, User has cn. The following table shows naming attributes for LDAP and their equivalent for AD.

LDAP attribute name AD attribute name
CN Common Name CN Common Name
OU Organization Unit OU Organization Unit
O Organization DC Domain Component
C Country - -

Functional Model

The Functional Model of LDAP defines what can be done with the information in the directory. It consists of 9 operations that are categorized into 3 functional areas.

area operation description
Authentication bind initializes connection, negotiates authentication method, authenticates
unbind terminates session
abandon client requests termination of sending results for the last query
Interrogation search selects data from a certain region using a filter
compare compares the value of an attribute with a given value
Update add creates a new object
modify modifies attributes of a record (create, delete, modify)
modify RDN used to move an object within the directory tree
delete record deletion

Note: Active Directory supports several other operations that are not defined in the RFC.

Queries using LDAP

The search operation has a number of input parameters. One of them is the search base, which determines the container from which the search will be conducted. Another important parameter is the filter.

In filters, we can use mathematical operations equals (attribute=value), greater than or equal to (attribute>=value), less than or equal to (attribute

Author:

Related articles:

Active Directory and the LDAP protocol

Managing a corporate computer network using Microsoft OS usually means managing Active Directory Domain Services (AD DS). It is a very extensive group of technologies, protocols and services. The basis is directory services, authentication and the LDAP communication protocol.

If you want write something about this article use comments.

Comments
  1. [1] Martin

    Skvele! Diky!

    Thursday, 31.01.2008 14:26 | answer
  2. [2] Pavel

    Perfektní článek, díky!

    Saturday, 21.02.2009 14:51 | answer
  3. [3] František Němec

    Stručně a jasně vysvětleno, co jsem potřeboval vědět.

    Friday, 12.06.2009 13:49 | answer
  4. [4] Tomas Riha

    vyborny clanek

    Thursday, 22.04.2010 09:57 | answer
  5. [5] Petr Čontofalský

    Skvělý článek. Děkuji.

    Friday, 23.04.2010 12:22 | answer
  6. [6] Brabeczek

    Perfektní..! Thenks ;-)

    Wednesday, 28.04.2010 12:47 | answer
  7. [7] Sunset

    největší vrušení, děkuju !;-)

    Friday, 30.04.2010 12:07 | answer
  8. [8] Karel (Karviná)

    Opravdu kvalitní stránky. Dokonce je používáme ve škole jako studijní materiál.. Lepší manželku než tyto webowky jsem si vybrat nemohl :)

    Friday, 30.04.2010 12:09 | answer
  9. [9] Michal Jirásek

    Mam problém se kterým si nevědí ani doktoři... Mam řítkou stolici nevíte jak to mam vyřešit prosím váás??:-(

    Friday, 30.04.2010 12:13 | answer
  10. [10] Blanka Protrhlá

    sakra Michale, proč se s tím svěřuješ tady? :-O

    Wednesday, 05.05.2010 13:11 | answer
  11. [11] Dement

    coool

    Monday, 16.01.2012 13:11 | answer
  12. [12] pan Ivan

    respond to [1]Martin: Hezké

    Tuesday, 20.01.2015 12:55 | answer
  13. [13] Standa

    Ahoj suprový článek, lepší jak Peterka!

    Monday, 06.02.2017 10:08 | answer
  14. [14] johnnybdude

    Super článek, díky za jemný úvod do AD:)

    Friday, 12.10.2018 10:30 | answer
  15. [15] Landa

    Bomba;-)

    Monday, 06.02.2023 14:08 | answer
  16. [16] Tuzar

    super:-)

    Monday, 06.02.2023 14:09 | answer
Add comment

Insert tag: strong em link

Help:
  • maximum length of comment is 2000 characters
  • HTML tags are not allowed (they will be removed), you can use only the special tags listed above the input field
  • new line (ENTER) ends paragraph and start new one
  • when you respond to a comment, put the original comment number in squar brackets at the beginning of the paragraph (line)