From fcfc8f494bb17bb5f24c723d6c78b190d94092e6 Mon Sep 17 00:00:00 2001 From: Ben Klang Date: Sun, 11 Dec 2005 15:29:00 +0000 Subject: [PATCH] Added usage to scripts/data2ldap.pl Added default serial of now() in YYYYMMDD01 format to data2ldap.pl for better compatibility with ldap2dns git-svn-id: https://svn.alkaloid.net/gpl/ldap2dns/trunk@158 06cd67b6-e706-0410-b29e-9de616bca6e9 --- ldap2dns.c | 2 +- ldap2dns.schema | 2 +- ldap2dns.spec.in | 2 +- ldap2tinydns-conf | 2 +- scripts/data2ldap.pl | 75 +++++++++++++++++++++++++++++++++++++------- 5 files changed, 67 insertions(+), 16 deletions(-) mode change 100644 => 100755 scripts/data2ldap.pl diff --git a/ldap2dns.c b/ldap2dns.c index 1102d29..6e5fd7c 100644 --- a/ldap2dns.c +++ b/ldap2dns.c @@ -1,6 +1,6 @@ /* * Create data from an LDAP directory service to be used for tinydns - * $Id: ldap2dns.c,v 1.36 2005/12/07 19:03:11 bklang Exp $ + * $Id$ * Copyright 2000-2005 by Jacob Rief * Copyright 2005 by Ben Klang * License: GPL version 2. See http://www.fsf.org for details diff --git a/ldap2dns.schema b/ldap2dns.schema index 0ce813e..878e6b2 100644 --- a/ldap2dns.schema +++ b/ldap2dns.schema @@ -1,6 +1,6 @@ # schema for DNS data # include this file into Your slapd.conf for openldap-2.0.x -# $Id: dns.schema,v 1.9 2001/11/06 08:01:51 config Exp $ +# $Id$ attributetype ( 1.3.6.1.4.1.7222.1.4.1 NAME 'dnszonename' diff --git a/ldap2dns.spec.in b/ldap2dns.spec.in index ac84e7b..5b9728c 100644 --- a/ldap2dns.spec.in +++ b/ldap2dns.spec.in @@ -17,7 +17,7 @@ BuildRequires: %OPENLDAPPKG%-devel Summary: LDAP to DNS gateway Packager: Ben Klang Vendor: Alkaloid Networks -Name: ldap2dns +Name: ldap2dns-new Version: %VERSION% Release: %RELEASE% License: GPL diff --git a/ldap2tinydns-conf b/ldap2tinydns-conf index c3e8fb2..6e232c7 100755 --- a/ldap2tinydns-conf +++ b/ldap2tinydns-conf @@ -7,7 +7,7 @@ TINYDNSDIR=$4 if [ -z "$LDAP2DNSUSER" -o -z "$LDAP2DNSLOGUSER" -o -z "$LDAP2DNSDIR" -o \ -z "$TINYDNSDIR" ]; then - echo "usage: $0 acct logacct /path/to/supervise /path/to/tinydns-supervise" >&2 + echo "usage: $0 acct logacct /path/to/supervise /path/to/tinydns-supervise" >&2 exit 1 fi diff --git a/scripts/data2ldap.pl b/scripts/data2ldap.pl old mode 100644 new mode 100755 index d7727c7..7644386 --- a/scripts/data2ldap.pl +++ b/scripts/data2ldap.pl @@ -2,7 +2,7 @@ # $Id$ use strict; use warnings; -#use POSIX qw(strftime): +use POSIX qw(strftime); my $file = $ARGV[0]; my $output = $ARGV[1]; @@ -12,15 +12,35 @@ my %domains; # Keep track of which domains for which we have # already written an SOA my $outfh; my $rejfh; -#my $newserial = strftime("%Y%m%d01"); +my $newserial = strftime("%Y%m%d01", localtime); +my $errorrecs = 0; if (!defined($file)) { - print STDERR "Must specify path to 'data' file to read\n"; - exit 1; + print STDERR "\n"; + print STDERR " Must specify path to 'data' file to read\n"; + print STDERR "\n"; + usage(); + die("Should never get here\n"); } -if (!defined($output) || $output eq '-') { +if (!defined($output)) { + print STDERR "\n"; + print STDERR " Must specify path to output LDIF data\n"; + print STDERR "\n"; + usage(); + die("Should never get here\n"); +} +if (!defined($basedn)) { + print STDERR "\n"; + print STDERR " Must specify a base DN as the third argument\n"; + print STDERR "\n"; + usage(); + die("Should never get here\n"); +} + +if ($output eq '-') { $output = "/dev/stdout"; + # Rejects are already printed to STDERR by default. No need to duplicate $rejout = "/dev/null"; } else { $rejout = "$output.rej"; @@ -28,12 +48,6 @@ if (!defined($output) || $output eq '-') { open($outfh, ">$output") or die ("Unable to open $output for writing!"); open($rejfh, ">$rejout") or die ("Unable to open $rejout for writing"); -if (!defined($basedn)) { - print STDERR "Must specify a base DN as the third argument\n"; - exit 1; -} - - # We run in two iterations. The first attempts to enumerate all zones # for which we have records and create SOAs in LDAP. The reason for this is # zones are used as a container for all records so they must be in place before @@ -51,6 +65,7 @@ LINE: while() { /^-/ && do { # Found a disabled A record print STDERR "Ignoring disabled record: $_\n"; + $errorrecs++; print $rejfh "$_\n"; next LINE; }; @@ -86,7 +101,11 @@ LINE: while() { print $outfh "dnszonename: $domain\n"; print $outfh "dnszonemaster: $master\n"; print $outfh "dnsadminmailbox: $admin\n"; - if ($serial) { print $outfh "dnsserial: $serial\n"; } + if ($serial) { + print $outfh "dnsserial: $serial\n"; + } else { + print $outfh "dnsserial: $newserial\n"; + } if ($refresh) { print $outfh "dnsrefresh: $refresh\n"; } if ($retry) { print $outfh "dnsretry: $retry\n"; } if ($expire) { print $outfh "dnsexpire: $expire\n"; } @@ -121,6 +140,7 @@ LINE: while() { print $outfh "dnszonename: $domain\n"; print $outfh "dnszonemaster: $x\n"; print $outfh "dnsadminmailbox: hostmaster.$domain\n"; + print $outfh "dnsserial: $newserial\n"; if (defined($ttl)) { print $outfh "dnsttl: $ttl\n"; } if (defined($timestamp)) { print $outfh "dnstimestamp: $timestamp\n"; } if (defined($loc)) { print $outfh "dnslocation: $loc\n"; } @@ -288,6 +308,7 @@ LINE: while() { /^'/ && do { # Currently unsupported print STDERR "Ignoring unsupported TXT record: $_\n"; + $errorrecs++; print $rejfh "$_\n"; next LINE; # Found an MX @@ -368,11 +389,20 @@ LINE: while() { /^:/ && do { # Found unsupported "unknown record" print STDERR "Ignoring \"unknown record\": $_\n"; + $errorrecs++; print $rejfh "$_\n"; next LINE; } } # End for($_) block } # End LINE while() +print STDERR "\n"; +if ($errorrecs) { + print STDERR "$errorrecs records were found containing errors. Please inspect $rejout\n"; + print STDERR "for details. DNS TXT and TinyDNS \"unknown record\" formats are not supported\n"; +} + +print STDERR "Completed successfully\n"; +exit 0; sub getdomain { @@ -380,3 +410,24 @@ sub getdomain $fqdn =~ /\.*([A-Za-z0-9\-]+\.[A-Za-z0-9\-]+)\.*$/; return $1; } + +sub usage +{ + print STDERR "Usage: $0 \n"; + print STDERR "\n"; + print STDERR "This script takes a standard TinyDNS \"data\" file as input\n"; + print STDERR "and generates an LDIF format output suitable for use with\n"; + print STDERR "this \"ldap2dns\" package. If any unsupported or otherwise erroring records\n"; + print STDERR "are found in the input, they are printed to both STDERR as well as\n"; + print STDERR "\".rej\" , Currently unsupported are DNS TXT and the\n"; + print STDERR "TinyDNS \"unknown record\" format. There is planned support for\n"; + print STDERR "DNS TXT and DNS SRV (in \"unknown record\" format) in the near future\n"; + print STDERR "\n"; + print STDERR " may be either a filename or \"-\" for STDOUT. If STDOUT is used\n"; + print STDERR "as the output then no .rej file is created and error records\n"; + print STDERR "are only printed to STDERR\n"; + print STDERR "\n"; + print STDERR "Example: $0 data data.ldif ou=DNS,dc=example,dc=com\n"; + print STDERR "\n"; + exit 1; +}