[HowTo] Add new schema to OpenLDAP 2.4+

Hello ! In this post, I will explain how to add a new schema into OpenLDAP 2.4 and higher. Why ? Because since release 2.4, the structure of the server has a little changed. I’m not an LDAP expert but I’m writing this article because I insulted my OpenLDAP and my Linux several times during one week while I try to add my own schema into OpenLDAP 2.4. I have read a lot of posts but honestly, I never find a good “how-to” which respond to the question in this post’s title.

The configuration in OpenLDAP 2.4 and next versions is now in LDIF format and it follows a pretty logical schema like this :

 config_dit

We can look that schemas must be placed as child of cn=schema,cn=config. Before the release 2.4, all .schema (stored under /etc/ldap/schema/) were included into slapd.conf. Since 2.4, we must “forget” the .schema file. The best way to explain how to add new schema with 2.4 (and higher) release is to start with a real and practical example. I suppose you already have a OpenLDAP server  running. For your information, my OpenLDAP runs on a Ubuntu Server 12.04 LTS with a 3.5.0-48 64 bits kernel.

 The preparation

For this example, we can imagine that we want to add a new schema with a custom objectClass for our business application. This new objectClass has the name of nsaEngineer and the schema nsaProject. As a reminder, a schema is a container (package) for one or many objectClass. An objectClass contains references to other objectClass and attributes. Now, the objectClass nsaEngineer has 3 customs mandatory attributes and a optional (description) which is referenced in another base schema.

  • mainDoorKey (mandatory)
  • safeKey (mandatory)
  • nsaID (mandatory)
  • description (optional)

Now, let’s go to create this schema (and objectClass and attributes). Note : for more information about LDAP structures, please consult the following link : LDAP structure

Creation of classic .schema

The .schema format is simple to understand and to write for the beginners. Let’s start by creating a working directory for example /tmp/ldapworkingdir.

 Now, create the file nsaProject.schema which contains the definition of the new and custom attributes and the new objectClass nsaEngineer and save it in /etc/ldap/schema/. I will not explain in detail the content of nsaProject.schema because it is out of the scope for this post.

Convert and add the schema to OpenLDAP

Now it’s time to try to convert our .schema into an LDIF file and add it to OpenLDAP. To begin, create a dummy file into /tmp/ldapworkingdir called ldap.conf for example and write into it the include directive to the nsaProject.schema.

 Now try to convert the .schema file with this command

 This will create in place a directory called cn=config and a file cn=config.ldif. Now go to new created sub-directory ./cn=config/cn/schema/ and edit the file cn={0}nsaProject

 The file must contains the following:

 You must keep only the following things and delete the rest.

  • dn: cn={0}nsaproject
  • objectClass: olcSchemaConfig
  • cn: {0}nsaproject
  • olcAttributeTypes:
  • olcObjectClasses:

You must modify dn: and cn:  (just remove {0} for cn but write the correct dn for the schema ! (dn:cn=nsaproject,cn=schema,cn=config) ). After these modifications, the file is like this:

 That’s it ! Now we are ready to add this schema to the OpenLDAP server using this command

 Now you can verify if the new schema is correctly added using a ldapsearch command like this :

 That’s it ! I hope this post is helpful. Feel free to comment on this article if you have any comments or advice because I am not an LDAP expert 🙂

Note : I will write a program that will make the whole procedure automatically;-) Stay tuned!

 

 

 

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInShare on RedditShare on StumbleUponShare on TumblrPin on PinterestFlattr the authorDigg thisBuffer this pagePrint this page

3 comments

  1. Extremely helpful but please fix your keywords or make something to get this post more visibility on google. I’ve been searching for this exact info ( how to make the schema object+attributes ; convert it correctly to ldif; import it in my ldap ) and none of my searches for “how to add custom schema” or “how to add new custom schema” or ” how to add new schema” to ldap helped me.

    I had to ask questions on serverfault, read http://www.openldap.org/doc/admin24/schema.html and this http://www.zytrax.com/books/ldap/ch6/slapd-config.html#use-schemas and this http://www.zytrax.com/books/ldap/ch14/#ldapadd and just after that when I searched for “custom schemas with hdb” I found you 🙂

    Anyway, you came just when everything seemed lost and I sincerely thank you !

    Best of wishes,
    Tsouica

    1. Hello Tsouica and thank you for your advice ! I understand your problem because when I searched myself to understand how to add/create/modify schema on Google and friends, I had a lot of problems too. It is why I created this article after. The name of my post must be simple and short but maybe I must add some “search keywords” to help indexing by bots. Don’t hesitate to contact me if you have suggestions, advices and so on.

Leave a Reply

Your email address will not be published. Required fields are marked *