Skip to content
Snippets Groups Projects
Commit e60338fa authored by Andreas Åkre Solberg's avatar Andreas Åkre Solberg
Browse files

Added script for parsing LDAP schemas and create attributemaps (by Olav Morken)

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1428 44740490-163a-0410-bde0-09ae8108e29a
parent 3aa8c47c
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env perl
use strict;
use warnings;
my @valid_formats = (
'simple',
'oid2name',
'oid2urn',
'name2oid',
'name2urn',
'urn2oid',
'urn2name',
);
my $format = shift;
unless (defined($format)) {
print(STDERR "Usage: simpleparser.pl FORMAT <FILES>\n");
print(STDERR "Valid formats: ", join(' ', @valid_formats), "\n");
exit(1);
}
unless (grep { $_ eq $format } @valid_formats) {
print(STDERR "Invalid format: $format\n");
print(STDERR "Valid formats: ", join(' ', @valid_formats), "\n");
exit(1);
}
# Load file
my $text = join('', <>);
# Strip comments
$text =~ s/#.*$//gm;
my %oids;
my %names;
while ($text =~ m"attributetype\s*\(\s*([\d.]+).*?NAME\s+(?:'(.*?)'|(\(.*?\)))"sg) {
my $oid = $1;
my @attributes;
if (defined($2)) {
# Single attribute
@attributes = ($2);
} else {
# Multiple attributes
my $input = $3;
while ($input =~ m"'(.*?)'"gs) {
push(@attributes, $1);
}
}
foreach my $attrname (@attributes) {
$names{$attrname} = $oid;
}
$oids{$oid} = [ @attributes ];
}
if ($format eq 'simple') {
foreach my $oid (sort keys %oids) {
my @names = @{$oids{$oid}};
print "$oid ", join(' ', @names), "\n";
}
exit(0);
}
print "<?php\n";
print "\$attributemap = array(\n";
if ($format eq 'oid2name') {
foreach my $oid (sort keys %oids) {
my $name = $oids{$oid}->[0];
print "\t'urn:oid:$oid' => '$name',\n";
}
} elsif ($format eq 'oid2urn') {
foreach my $oid (sort keys %oids) {
my $name = $oids{$oid}->[0];
print "\t'urn:oid:$oid' => 'urn:mace:dir:attribute-def:$name',\n";
}
} elsif ($format eq 'name2oid') {
foreach my $name (sort keys %names) {
my $oid = $names{$name};
print "\t'$name' => 'urn:oid:$oid',\n";
}
} elsif ($format eq 'name2urn') {
foreach my $name (sort keys %names) {
print "\t'$name' => 'urn:mace:dir:attribute-def:$name',\n";
}
} elsif ($format eq 'urn2oid') {
foreach my $name (sort keys %names) {
my $oid = $names{$name};
print "\t'urn:mace:dir:attribute-def:$name' => 'urn:oid:$oid',\n";
}
} elsif ($format eq 'urn2name') {
foreach my $name (sort keys %names) {
print "\t'urn:mace:dir:attribute-def:$name' => '$name',\n";
}
}
print ");\n";
print "?>";
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment