forked from jengelh/openldap2
04c9eb4bdf
(bnc#541819) OBS-URL: https://build.opensuse.org/package/show/network:ldap/openldap2?expand=0&rev=18
75 lines
1.5 KiB
Perl
75 lines
1.5 KiB
Perl
#!/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 <input file>
|
|
#
|
|
# 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 <input file>\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 ( <SCHEMA> )
|
|
{
|
|
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;
|
|
}
|
|
}
|
|
|