#!/usr/bin/perl
BEGIN {
	my $x = $0; $x =~ s/\/[^\/]+$//;
	if ($x eq $0 || $x eq '') { $x = `pwd`;chomp $x; };
	require "$x/config.pl";
};

sub usage {
	print "usage: set_ip_pointer ip host ns ...\n"; exit 1;
}

my $ip = shift @ARGV;
&usage if (!defined($ip));

my $host = shift @ARGV;
&usage if (!defined($host));

my (@ns) = (@ARGV);
&usage if (scalar(@ns) < 1);

my $ldap = &get_ldap_conn;

$host =~ s/^\.//; $host =~ s/\.$//;

my $ipaddr;
if ($ip =~ /\.in-addr\.arpa\.?$/i) {
	# trusting folk we are...
	$ipaddr = lc($ip);
} else {
	$ipaddr = join('.', reverse split /\./, $ip) . '.in-addr.arpa';
}

my @nsadd = ();
foreach my $i (@ns) {
	$i =~ s/^\.//; $i =~ s/\.$//;
	push(@nsadd, $i . '.');
}
dc_add_prefix($ldap, $ipaddr);

set_record($ldap, $ipaddr, [
	dc => dc_domain($ipaddr),
	objectClass => [ qw(dnsDomain dcObject) ],
	cNAMERecord => "$host.",
	nSRecord => \@nsadd,
], { cNAMERecord => "$host.", aRecord => [] });

