Using ldapsearch to export the OID schema

A friend in need asked, so here it is.

Example of how to use ldapsearch to export an Oracle Internet Directory (OID) schema using the standard version that comes with Red Hat Enterprise Linux (a/k/a OpenLDAP ldapsearch):

ldapsearch -x -LLL -h [servername] -p [ldapport] -b "cn=subschemasubentry" 
 -s base "(cn=*)" objectclasses attributetypes >oidschema.ldif

The search filter needs to be either for cn or objectclass, and the scope must be “base” (there is no “sub” there).

If you wanted to then import any part of the schema exported into another OID you’ve got a number of options. Here’s two:

1. You could manually edit the file produced by the above command to remove all the objectclasses and attributetypes you’re not interested in (along with the objectclass lines right under the dn), and then put a “changetype: add” right under the dn line, like this:

dn: cn=subschemasubentry
changetype: add
objectclasses: ....

2. You could write a script that would iterate through the LDIF file and only named objectclasses and attributetypes you’re interested in adding to the other directory, kind of an LDIF rewrite kind of thing like this.