Add Customized Schema to Openldap

In this tutorial we will learn, how to add customized schema in ldap.

First create a temporary directory like “tp” or any xyz name.

Create a folder name schema in temporary directory and place schema file inside folder that folder.

It should look like

tp/schema/yourschema.schema

Inside ‘tp’ create a file ‘slapd.conf.yourschema’

It should look like this

#
# See slapd.conf(5) for details on configuration options.
# This file should NOT be world readable.
#
include tp/schema/yourschemaname.schema
# Define global ACLs to disable default read access.
# Do not enable referrals until AFTER you have a working directory
# service AND an understanding of referrals.
#referral ldap://root.openldap.org
#pidfile /usr/local/authz/var/run/slapd.pid
#argsfile /usr/local/authz/var/run/slapd.args
# Load dynamic backend modules:
# modulepath /usr/local/authz/libexec/openldap
# moduleload back_bdb.la
# moduleload back_hdb.la
# moduleload back_ldap.la
# Sample security restrictions
# Require integrity protection (prevent hijacking)
# Require 112-bit (3DES or better) encryption for updates
# Require 63-bit encryption for simple bind
# security ssf=1 update_ssf=112 simple_bind=64
# Sample access control policy:
# Root DSE: allow anyone to read it
# Subschema (sub)entry DSE: allow anyone to read it
# Other DSEs:
# Allow self write access
# Allow authenticated users read access
# Allow anonymous users to authenticate
# Directives needed to implement policy:
# access to dn.base=”” by * read
# access to dn.base=”cn=Subschema” by * read
# access to *
# by self write
# by users read
# by anonymous auth
#
# if no access controls are present, the default policy
# allows anyone and everyone to read anything but restricts
# updates to rootdn. (e.g., “access to * by * read”)
#
# rootdn can always read and write EVERYTHING!
#######################################################################
# BDB database definitions
#######################################################################
#database bdb
#suffix “dc=my-domain,dc=com”
#rootdn “cn=Manager,dc=my-domain,dc=com”
# Cleartext passwords, especially for the rootdn, should
# be avoid. See slappasswd(8) and slapd.conf(5) for details.
# Use of strong authentication encouraged.
#rootpw secret
# The database directory MUST exist prior to running slapd AND
# should only be accessible by the slapd and slap tools.
# Mode 700 recommended.
#directory /usr/local/authz/var/openldap-data
# Indices to maintain
#index objectClass eq

Now use this to generate ldif file of schema

slapcat -f slapd.conf.schemaname -F /tp/schema -n0(zero) -s cn=schema,cn=config

This will generate cn=config folder and inside it you will see cn=schema.

Inside it you will find your schema file

cn={0}yourschema.ldif

Now open it in vim or nano or gedit and make some changes like

structuralObjectClass: olcSchemaConfig entryUUID: dd03fc7a-d4fe-1033–96b0–055318f25a03 creatorsName: cn=config createTimestamp: 20140920104438Z entryCSN: 20140920104438.200261Z#000000#000#000000 modifiersName: cn=config modifyTimestamp: 20140920104438Z Modify the dn to be “cn=schemaname,cn=schema,cn=config and remove the ordering {0} bracket from the cn

Now make a ldif file such as manager.ldif for changing cn=config user password

dn: olcDatabase={0}config,cn=config
changetype: modify
replace: olcRootPW
olcRootPW: xyz-password

generate password using crypted slappasswd and add using

ldapmodify -Y EXTERNAL -H ldapi:/// -f manager.ldif

Now use command this command to add schema file

ldapadd -D cn=config -W -f cn\=\{0\}mycustom.ldif

It will prompt for password give the password set using manage.ldif

Show your support

Clapping shows how much you appreciated Abhishek koserwal’s story.