#!/usr/bin/perl -w # # This is a simple tool to convert OpenLDAP Schema files to # LDIF suitable for usage with OpenLDAP's dynamic configuration # backend (cn=config) # # usage: # schema2ldif.pl # # The generated LDIF is printed to stdout. # use strict; use File::Basename; use Text::Wrap; my $infile = $ARGV[0] || print_usage(); sub print_usage { print STDERR "usage: schema2ldif.pl \n"; exit(1); } open( SCHEMA, "< $infile"); my $schemaline = ""; $Text::Wrap::columns=78; $Text::Wrap::separator="\n "; my $cn = basename($infile, ".schema"); print STDOUT "dn: cn=$cn,cn=schema,cn=config\n"; print STDOUT "objectClass: olcSchemaConfig\n"; print STDOUT "cn: $cn\n"; while ( ) { my $line = $_; if ( $line =~ /^\s+(.+)$/ ) { $schemaline .= " $1"; next; } elsif ( $schemaline ne "" ) { print STDOUT wrap(""," ", $schemaline); print STDOUT "\n"; $schemaline = ""; } if ( $line =~ /^#/ ) { print STDOUT $line; } elsif ( $line =~ /^\s*$/ ) { print STDOUT "#\n"; } elsif ( $line =~ /^(objectclass|attributetype|objectidentifier)\s+(.+)$/i ) { if ( lc($1) eq "objectidentifier" ) { $schemaline .= "olcObjectIdentifier: "; } elsif ( lc($1) eq "objectclass" ) { $schemaline .= "olcObjectClasses: "; } elsif ( lc($1) eq "attributetype" ) { $schemaline .= "olcAttributeTypes: "; } $schemaline .= $2; } }