mirror of
				https://github.com/bklang/ldap2dns.git
				synced 2025-10-31 08:03:12 -04:00 
			
		
		
		
	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
This commit is contained in:
		| @@ -1,6 +1,6 @@ | |||||||
| /* | /* | ||||||
|  * Create data from an LDAP directory service to be used for tinydns |  * 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 <jacob.rief@tiscover.com> |  * Copyright 2000-2005 by Jacob Rief <jacob.rief@tiscover.com> | ||||||
|  * Copyright 2005 by Ben Klang <ben@alkaloid.net> |  * Copyright 2005 by Ben Klang <ben@alkaloid.net> | ||||||
|  * License: GPL version 2. See http://www.fsf.org for details |  * License: GPL version 2. See http://www.fsf.org for details | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| # schema for DNS data | # schema for DNS data | ||||||
| # include this file into Your slapd.conf for openldap-2.0.x | # 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 | attributetype ( 1.3.6.1.4.1.7222.1.4.1 | ||||||
|         NAME 'dnszonename' |         NAME 'dnszonename' | ||||||
|   | |||||||
| @@ -17,7 +17,7 @@ BuildRequires: %OPENLDAPPKG%-devel | |||||||
| Summary:	LDAP to DNS gateway | Summary:	LDAP to DNS gateway | ||||||
| Packager:	Ben Klang <ben@alkaloid.net> | Packager:	Ben Klang <ben@alkaloid.net> | ||||||
| Vendor:		Alkaloid Networks | Vendor:		Alkaloid Networks | ||||||
| Name:		ldap2dns | Name:		ldap2dns-new | ||||||
| Version:	%VERSION% | Version:	%VERSION% | ||||||
| Release:	%RELEASE% | Release:	%RELEASE% | ||||||
| License:	GPL | License:	GPL | ||||||
|   | |||||||
							
								
								
									
										75
									
								
								scripts/data2ldap.pl
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										75
									
								
								scripts/data2ldap.pl
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -2,7 +2,7 @@ | |||||||
| # $Id$ | # $Id$ | ||||||
| use strict; | use strict; | ||||||
| use warnings; | use warnings; | ||||||
| #use POSIX qw(strftime): | use POSIX qw(strftime); | ||||||
|  |  | ||||||
| my $file = $ARGV[0]; | my $file = $ARGV[0]; | ||||||
| my $output = $ARGV[1]; | my $output = $ARGV[1]; | ||||||
| @@ -12,15 +12,35 @@ my %domains; # Keep track of which domains for which we have | |||||||
|              # already written an SOA |              # already written an SOA | ||||||
| my $outfh; | my $outfh; | ||||||
| my $rejfh; | my $rejfh; | ||||||
| #my $newserial = strftime("%Y%m%d01"); | my $newserial = strftime("%Y%m%d01", localtime); | ||||||
|  | my $errorrecs = 0; | ||||||
|  |  | ||||||
| if (!defined($file)) { | if (!defined($file)) { | ||||||
|     print STDERR "Must specify path to 'data' file to read\n"; |     print STDERR "\n"; | ||||||
|     exit 1; |     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"; |     $output = "/dev/stdout"; | ||||||
|  |     # Rejects are already printed to STDERR by default.  No need to duplicate | ||||||
|     $rejout = "/dev/null"; |     $rejout = "/dev/null"; | ||||||
| } else { | } else { | ||||||
|     $rejout = "$output.rej"; |     $rejout = "$output.rej"; | ||||||
| @@ -28,12 +48,6 @@ if (!defined($output) || $output eq '-') { | |||||||
| open($outfh, ">$output") or die ("Unable to open $output for writing!"); | open($outfh, ">$output") or die ("Unable to open $output for writing!"); | ||||||
| open($rejfh, ">$rejout") or die ("Unable to open $rejout 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 | # 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 | # 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 | # zones are used as a container for all records so they must be in place before | ||||||
| @@ -51,6 +65,7 @@ LINE: while(<DATA>) { | |||||||
|         /^-/ && do { |         /^-/ && do { | ||||||
|             # Found a disabled A record |             # Found a disabled A record | ||||||
|             print STDERR "Ignoring disabled record: $_\n"; |             print STDERR "Ignoring disabled record: $_\n"; | ||||||
|  |             $errorrecs++; | ||||||
|             print $rejfh "$_\n"; |             print $rejfh "$_\n"; | ||||||
|             next LINE; |             next LINE; | ||||||
|         }; |         }; | ||||||
| @@ -86,7 +101,11 @@ LINE: while(<DATA>) { | |||||||
|             print $outfh "dnszonename: $domain\n"; |             print $outfh "dnszonename: $domain\n"; | ||||||
|             print $outfh "dnszonemaster: $master\n"; |             print $outfh "dnszonemaster: $master\n"; | ||||||
|             print $outfh "dnsadminmailbox: $admin\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 ($refresh) { print $outfh "dnsrefresh: $refresh\n"; } | ||||||
|             if ($retry) { print $outfh "dnsretry: $retry\n"; } |             if ($retry) { print $outfh "dnsretry: $retry\n"; } | ||||||
|             if ($expire) { print $outfh "dnsexpire: $expire\n"; } |             if ($expire) { print $outfh "dnsexpire: $expire\n"; } | ||||||
| @@ -121,6 +140,7 @@ LINE: while(<DATA>) { | |||||||
|             print $outfh "dnszonename: $domain\n"; |             print $outfh "dnszonename: $domain\n"; | ||||||
|             print $outfh "dnszonemaster: $x\n"; |             print $outfh "dnszonemaster: $x\n"; | ||||||
|             print $outfh "dnsadminmailbox: hostmaster.$domain\n"; |             print $outfh "dnsadminmailbox: hostmaster.$domain\n"; | ||||||
|  |             print $outfh "dnsserial: $newserial\n"; | ||||||
|             if (defined($ttl)) { print $outfh "dnsttl: $ttl\n"; } |             if (defined($ttl)) { print $outfh "dnsttl: $ttl\n"; } | ||||||
|             if (defined($timestamp)) { print $outfh "dnstimestamp: $timestamp\n"; } |             if (defined($timestamp)) { print $outfh "dnstimestamp: $timestamp\n"; } | ||||||
|             if (defined($loc)) { print $outfh "dnslocation: $loc\n"; } |             if (defined($loc)) { print $outfh "dnslocation: $loc\n"; } | ||||||
| @@ -288,6 +308,7 @@ LINE: while(<DATA>) { | |||||||
|         /^'/ && do { |         /^'/ && do { | ||||||
|             # Currently unsupported |             # Currently unsupported | ||||||
|             print STDERR "Ignoring unsupported TXT record: $_\n"; |             print STDERR "Ignoring unsupported TXT record: $_\n"; | ||||||
|  |             $errorrecs++; | ||||||
|             print $rejfh "$_\n"; |             print $rejfh "$_\n"; | ||||||
|             next LINE; |             next LINE; | ||||||
|             # Found an MX |             # Found an MX | ||||||
| @@ -368,11 +389,20 @@ LINE: while(<DATA>) { | |||||||
|         /^:/ && do { |         /^:/ && do { | ||||||
|             # Found unsupported "unknown record" |             # Found unsupported "unknown record" | ||||||
|             print STDERR "Ignoring \"unknown record\": $_\n"; |             print STDERR "Ignoring \"unknown record\": $_\n"; | ||||||
|  |             $errorrecs++; | ||||||
|             print $rejfh "$_\n"; |             print $rejfh "$_\n"; | ||||||
|             next LINE; |             next LINE; | ||||||
|         } |         } | ||||||
|     } # End for($_) block |     } # End for($_) block | ||||||
| } # End LINE while(<DATA>) | } # End LINE while(<DATA>) | ||||||
|  | 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 | sub getdomain | ||||||
| { | { | ||||||
| @@ -380,3 +410,24 @@ sub getdomain | |||||||
|     $fqdn =~  /\.*([A-Za-z0-9\-]+\.[A-Za-z0-9\-]+)\.*$/; |     $fqdn =~  /\.*([A-Za-z0-9\-]+\.[A-Za-z0-9\-]+)\.*$/; | ||||||
|     return $1; |     return $1; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | sub usage | ||||||
|  | { | ||||||
|  |     print STDERR "Usage: $0 <input> <output> <basedn>\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 "\"<output>.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 "<output> may be either a filename or \"-\" for STDOUT.  If STDOUT is used\n"; | ||||||
|  |     print STDERR "as the output then no <output>.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; | ||||||
|  | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user