-
Notifications
You must be signed in to change notification settings - Fork 67
/
migrate.pl
executable file
·71 lines (56 loc) · 1.8 KB
/
migrate.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/perl -w
#
# This was adapted from a script on the redhat-ds wiki,
# it now at least attempts to handle openldap's "objectidentifier"
# macros --Kevin Goess 12/2005
#
# this is a quick perl script to convert OpenLDAP schema files
# to FDS ldif (schema) files. it is probably not anywhere near
# useful, but it did allow me to convert a few of my .schema
# files and have FDS successfully start with them.
#
# -Nathan Benson <[email protected]>
#
use strict;
die "usage: $0 <openldap.schema>\n" unless my $file = $ARGV[0];
die "$! '$file'\n" unless -e $file;
my $start;
print "dn: cn=schema\n";
my (%objectidentifier, $objidmatch);
open SCHEMA, $file;
while (<SCHEMA>)
{
next if /^(#|$)/;
#see http://www.openldap.org/doc/admin22/schema.html#OID%20Macros
if ($objidmatch && /($objidmatch:| $objidmatch )/)
{
s/($objidmatch):/$objectidentifier{$1}./;
#boo, this doesn't work for stuff in quoted fields
s/\s($objidmatch)\s/ $objectidentifier{$1} / unless /DESC/;
}
if (/^\s*objectidentifier\s+(\S+)\s+(\S+)/)
{
$objectidentifier{$1} = $2;
$objidmatch = join('|',keys(%objectidentifier));
}
if (/^(objectclass|attributetype)\s/i)
{
print "\n" if ($start);
chomp;
$_ =~ s/^objectclass/objectclasses:/i;
$_ =~ s/^attributetype/attributetypes:/i;
$_ =~ s/(\t|\s)/ /;
$start = 1;
print;
}
elsif ((/^\s*\w/) && ($start))
{
chomp;
$_ =~ s/^(\s*)/ /;
print;
}
elsif (/^\s*\)\s*$/ && $start) {
print ')';
}
}
close SCHEMA;