File: schema2ldif.pl

package info (click to toggle)
usbguard 1.1.2%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,528 kB
  • sloc: cpp: 18,119; sh: 1,836; makefile: 642; ansic: 122; xml: 76; perl: 39
file content (50 lines) | stat: -rwxr-xr-x 1,058 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env perl
# Converts OpenLDAP schema from traditional slapd.conf format to LDIF format
# usable for importing into cn=config.
#
# Copyright (c) 2012-2016 Mantas Mikulėnas <grawity@gmail.com>
# Released under the MIT license <https://spdx.org/licenses/MIT>

use warnings;
use strict;

my $name = shift(@ARGV) // "UNNAMED-SCHEMA";
my $unwrap = 0;

print "dn: cn=$name,cn=schema,cn=config\n";
print "objectClass: olcSchemaConfig\n";

my $key;
my $value;

while (<STDIN>) {
	if (/^(attributeType(?:s)?|objectClass(?:es)?) (.+)$/i) {
		if ($key && $value) {
			print "$key: $value\n";
		}
		($key, $value) = ($1, $2);
		if ($key =~ /^attributeType(s)?$/i) {
			$key = "olcAttributeTypes";
		} elsif ($key =~ /^objectClass(es)?$/i) {
			$key = "olcObjectClasses";
		} else {
			$key = "olc$key";
		}
	}
	elsif (/^\s+(.+)$/) {
		if ($unwrap) {
			$value .= " $1";
		} else {
			$value .= "\n $&";
		}
	}
	elsif (/^#.*/) {
		print "$&\n";
	}
	elsif (/.+/) {
		warn "$.:unrecognized input line: $&\n";
	}
}
if ($key && $value) {
	print "$key: $value\n";
}