]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/amd/scripts/amd2ldif.in
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / amd / scripts / amd2ldif.in
1 #!@PERL@
2
3 $usage=<<EOU;
4 Usage $0 mapname base < mapfile >mapfile.ldif
5
6 mapname: name of the amd map beeing converted to ldif
7 base   : The LDAP search base. Do not forget the quotes!
8
9 This script should/could be used in a Makefile together
10 with ldif2ldbm(8C) to automagically update the ldap
11 databases and restart slapd whenever a master copy of
12 the maps have changed. Remember "cd /var/yp; make" ?
13 EOU
14
15 my $fmt = "%-12s: %s\n";
16 my $tfmt = "%-15s: %s\n";
17 my $mapname = $ARGV[0] or die $usage;
18 my $base = $ARGV[1] or die $usage;
19 $time = time();
20
21 print "dn: cn=amdmap $mapname timestamp, $base\n";
22 printf "$tfmt", "cn", "amdmap $mapname timestamp";
23 printf "$tfmt", "objectClass", "amdmapTimestamp";
24 printf "$tfmt", "amdmapName", "$mapname";
25 printf "$tfmt", "amdmapTimestamp", $time;
26 printf "$tfmt", "amdmapName", $mapname;
27 print "\n";
28
29 my $line = "";
30 my $done = 0;
31
32 while (<STDIN>) {
33   chomp;
34   if (/\s*(.+)\\\s*/) {
35     if ($line) {
36       $line .= " ".$1;
37     } else {
38       $line = $1;
39     }
40     $done = 0;
41   } else {
42     s/^\s+//g;
43     $line .= $_;
44     $done = 1;
45   }
46   if ($done) {
47     my @vals = split(/\s+/,$line);
48     my $key = shift @vals;
49     my $entry;
50
51     print "dn: cn=amdmap $mapname\[$key\], $base\n";
52     printf "$fmt","cn","amdmap $mapname\[$key\]";
53     printf "$fmt","objectClass", "amdmap";
54     printf "$fmt","amdmapName", $mapname;
55     printf "$fmt","amdmapKey", $key;
56     printf "$fmt","amdmapValue", join(' ',@vals);
57     print "\n";
58     $line = ""; $done = 0;
59   }
60 }