1
0
forked from pool/openldap2

Converted schema2ldif to awk instead of perl, to reduce runtime

dependencies.

OBS-URL: https://build.opensuse.org/package/show/network:ldap/openldap2?expand=0&rev=19
This commit is contained in:
Ralf Haferkamp 2009-09-28 16:16:36 +00:00 committed by Git OBS Bridge
parent 04c9eb4bdf
commit 66d5d81e65
4 changed files with 54 additions and 76 deletions

View File

@ -50,7 +50,7 @@ Source2: addonschema.tar.gz
Source3: DB_CONFIG
Source4: sasl-slapd.conf
Source5: README.update
Source6: schema2ldif.pl
Source6: schema2ldif
Source100: openldap-2.3.37.tar.bz2
Patch: openldap2.dif
Patch2: slapd_conf.dif

View File

@ -50,7 +50,7 @@ Source2: addonschema.tar.gz
Source3: DB_CONFIG
Source4: sasl-slapd.conf
Source5: README.update
Source6: schema2ldif.pl
Source6: schema2ldif
Source100: openldap-2.3.37.tar.bz2
Patch: openldap2.dif
Patch2: slapd_conf.dif

52
schema2ldif Normal file
View File

@ -0,0 +1,52 @@
#!/bin/bash
#
# 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 <input file>
#
# The generated LDIF is printed to stdout.
#
if [ -z "$1" ]; then
echo 'usage: schema2ldif <input file>'
exit;
fi
cn=`basename $1 .schema`
echo "dn: cn=$cn,cn=schema,cn=config";
echo "objectclass: olcSchemaConfig";
echo "cn: $cn";
/usr/bin/awk '
BEGIN {
buffer = "";
width=78 ;
}
function wrap(data)
{
if (length(data) > 0) {
do {
print substr(data,0,width);
data = " " substr(data, width+1);
}
while (length(data) > 1 )
};
}
/^[\t ]*$/ {wrap(buffer); buffer=""; print "#"; next; }
/^#.*$/ { wrap(buffer); buffer=""; print $0; next }
/^[\t ]+/ { gsub("^[\t ]+",""); buffer = buffer " " $0; next; }
{
wrap(buffer);
$1 = tolower($1) ;
gsub("^objectclass$","olcObjectclasses:",$1)
gsub("^attributetype$","olcAttributeTypes:",$1)
gsub("^objectidentifier$","olcObjectIdentifier:",$1)
buffer = $0;
}
END { wrap(buffer); print "" }
' "$@"

View File

@ -1,74 +0,0 @@
#!/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;
}
}