#!/usr/bin/perl # # schema2ldif: Tool for converting OpenLDAP-style schemas to the LDIF format # ----------- # # The LDIF-formated LDAP schemas are difficult to edit and maintain. OpenLDAP # defined a similar schema format that is more free-form and easier to edit. # This tool converts the OpenLDAP-formatted schema files to the LDIF. # # Usage # ----- # # schema2ldif < foo.schema > foo.ldif # # OpenLDAP schema format # ---------------------- # # attributetype ( oid-my-attr-1 # NAME 'my-attr-1' # DESC 'description of my-attr-1 attribute' # SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 # ) # # objectclass ( oid-my-person # NAME 'my-person' # DESC 'description of my-person attribute' # SUP 'inetOrgPerson' # MAY ( my-attr-1 ) # ) # # LDIF schema format # ------------------ # # dn: cn=schema # objectClass: top # objectClass: ldapSubentry # objectClass: subschema # cn: schema # attributeTypes: ( oid-my-attr-1 NAME 'my-attr-1' DESC 'description of my-attr-1 attribute' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 ) # objectClasses: ( oid-my-person NAME 'my-person' DESC 'description of my-person attribute' SUP 'inetOrgPerson' MAY ( my-attr-1 ) ) # # schema2ldif, Version 1.0, (c) 2005 Radovan Semancik # use strict; my %attrNameMap = ( 'attributetype' => 'attributeTypes', 'objectclass' => 'objectClasses', ); print "dn: cn=schema\n"; print "objectClass: top\n"; print "objectClass: ldapSubentry\n"; print "objectClass: subschema\n"; print "cn: schema\n"; while (<>) { if (/^\s*#/) { print; next; } chomp; if ( /^\s*(attributetype)\s*\(/ || /^\s*(objectclass)\s*\(/ ) { print $attrNameMap{lc($1)}.": ("; $_ = $'; my $level = 1; while ($level) { while ( /\(/g ) { $level++ } while ( /\)/g ) { $level-- } print; $_ = <>; exit unless defined $_; chomp; s/^\s+/ /; s/\s+$//; } print "\n"; } }