ispman/scripts schema2ldif.pl,1.3,1.4

Joerg Delker <[email protected]> Wed, 31 Dec 2008 11:39:08 +0000
Newsgroups gmane.comp.isp.ispman.cvs
Message-ID <[email protected]>
Update of /cvsroot/ispman/ispman/scripts
In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv13226/scripts

Modified Files:
	schema2ldif.pl 
Log Message:
reimplemented schema converter

Index: schema2ldif.pl
===================================================================
RCS file: /cvsroot/ispman/ispman/scripts/schema2ldif.pl,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- schema2ldif.pl	30 May 2004 23:35:39 -0000	1.3
+++ schema2ldif.pl	31 Dec 2008 11:39:06 -0000	1.4
@@ -1,15 +1,42 @@
 #!/usr/bin/perl
-unless ( $ARGV[0] || ( -e $ARGV[0] && -f $ARGV[0] ) ) {
-    print "Usage: $0 schema_file type\n";
-    print "type: ibm|iplanet\n";
+
+use Getopt::Std;
+getopts( 't:f:', \%opts );
+
+unless ( $opts{'f'}) {
+    print "Usage: $0 [-t type] -f schema_file\n";
+    print "type: ibm|opends\n";
     exit;
 }
 
-$vendor = $ARGV[1] || "iplanet";
+$vendor = $opts{'t'} || "opends";
+
+# vendor definitions
+my %templ;
+$templ{opends} = {
+  header => "dn: cn=schema\nobjectClass: top\nobjectClass: ldapSubentry\nobjectClass: subschema\ncn: schema\n",
+  attr   => "attributeTypes:",
+  objc   => "objectClasses:"
+};
+
+$templ{ibm} = {
+  header => "",
+  attr   => "attributeTypes=",
+  objc   => "objectClasses="
+};
+
+
+
+if (!defined($templ{$vendor})) {
+   die "Error: Unknown vendor \"$vendor\"\n";
+}
+
+open(SCHEMA,"<$opts{'f'}") || die "Error: Unable to open \"$opts{'f'}\"\n";
+
+print $templ{$vendor}->{header};
 
-print "dn: cn=schema\n" if $type eq "iplanet";
 $c = -1;
-for (<>) {
+for (<SCHEMA>) {
     s/^ //g;
     next unless /\S/;
     next if /^#/;
@@ -27,25 +54,21 @@
     $data->{$type}[$c] .= $_;
 }
 
-$oc->{'iplanet'} = "objectClass:";
-$oc->{'ibm'}     = "objectClass=";
-$at->{'iplanet'} = "attributeTypes:";
-$at->{'ibm'}     = "attributeTypes=";
 
 for $type ( keys %$data ) {
     $array = $data->{$type};
   ELEMENT: for $element (@$array) {
         $element =~ s/\n/ /g;
         $element =~ s/\t/ /g;
+        $element =~ s/\x0d//g;
         $element =~ s/ {2}/ /g;
 
-        $element =~ s/^objectclass\s*\(\s*/$oc->{$vendor} ( /gi;
-        $element =~ s/^attributetype\s*\(\s*/$at->{$vendor} ( /gi;
+        $element =~ s/^objectclass\s*\(\s*/$templ{$vendor}->{objc} ( /gi;
+        $element =~ s/^attributetype\s*\(\s*/$templ{$vendor}->{attr} ( /gi;
         $element =~ s/ $//g;
         $element =~ s/\)$/ \)/;
         next ELEMENT unless $element =~ /\S/;
         print "$element\n";
     }
-
 }
 


------------------------------------------------------------------------------