MARWAN docs NOC knowledge base
DocsOpenLDAP

Convert .schema file to .ldif

Convert an OpenLDAP .schema file to LDIF format and load it with ldapadd (OpenLDAP 2.4+).

Updated Sami Ait Ali Oulahcen




Applies to OpenLDAP 2.4+

  • Put your schema in /etc/openldap/schema/nameOfYour.schema
  • Create a temporary working directory
mkdir /tmp/ldif/
  • Create the configuration file, and add the path to your .schema file:
touch /tmp/ldif/conf
echo 'include /etc/openldap/schema/nameOfYour.schema' > /tmp/ldif/conf
  • Then generate the .ldif file:
slaptest -f /tmp/ldif/conf -F /tmp/ldif
  • Now modify the file accordingly:
vi /tmp/ldif/cn\=config/cn\=schema/cn\=\{0}nameofyour.ldif

Remove the header that looks like this (Be careful not to modify any spaces or indents, as ldif files can be very sensitive):

# AUTO-GENERATED FILE - DO NOT EDIT!! Use ldapmodify.
# CRC32 50a9d844

And remove the ending :

structuralObjectClass: olcSchemaConfig
entryUUID: 54op7iut-55kl-8054-167u-hg654fr54648
creatorsName: cn=config
createTimestamp: 20170125152602Z
entryCSN: 20170125152602.718989Z#000000#000#000000
modifiersName: cn=config
modifyTimestamp: 20170125152602Z

Then modify the dn and cn so as to make it like this:

dn: cn=nameofyour,cn=schema,cn=config
objectClass: olcSchemaConfig
cn: nameofyour

Now copy it to the schema folder:

cp /tmp/ldif/cn\=config/cn\=schema/cn\=\{0}nameofyour.ldif /etc/openldap/schema/nameofyour.ldif

And finally add it via ldapadd:

ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/nameofyour.ldif

You should see a message indicating that the schema's been added successfully.