summaryrefslogtreecommitdiff
path: root/source4/script
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2004-10-09 10:11:26 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:59:41 -0500
commitc9e761a39e28f4a23ab8c31dd58743a794999b63 (patch)
tree5b4bd528cfe211a6a00005a931f14a363ffb5801 /source4/script
parentf9bac1dec23d2312d23d9605a39ce2819a10c1f3 (diff)
downloadsamba-c9e761a39e28f4a23ab8c31dd58743a794999b63.tar.gz
samba-c9e761a39e28f4a23ab8c31dd58743a794999b63.tar.bz2
samba-c9e761a39e28f4a23ab8c31dd58743a794999b63.zip
r2873: create a DNS zone file for a BIND name server
metze (This used to be commit 1e8c43133116881fb7ecf6358c1a91e0e3ea2222)
Diffstat (limited to 'source4/script')
-rwxr-xr-xsource4/script/provision.pl69
1 files changed, 64 insertions, 5 deletions
diff --git a/source4/script/provision.pl b/source4/script/provision.pl
index 8863653e34..e98181b05f 100755
--- a/source4/script/provision.pl
+++ b/source4/script/provision.pl
@@ -1,10 +1,12 @@
#!/usr/bin/perl -w
use strict;
+use Socket;
use Getopt::Long;
my $opt_hostname = `hostname`;
chomp $opt_hostname;
+my $opt_hostip;
my $opt_realm;
my $opt_domain;
my $opt_adminpass;
@@ -13,8 +15,10 @@ my $opt_nogroup;
my $opt_wheel;
my $opt_users;
my $dnsdomain;
+my $netbiosname;
my $dnsname;
my $basedn;
+my $defaultsite = "Default-First-Site-Name";
# return the current NTTIME as an integer
sub nttime()
@@ -38,6 +42,7 @@ sub randguid()
}
my $domainguid = randguid();
+my $hostguid = randguid();
sub randsid()
{
@@ -96,10 +101,18 @@ sub substitute($)
return $opt_hostname;
}
+ if ($var eq "NETBIOSNAME") {
+ return $netbiosname;
+ }
+
if ($var eq "DNSNAME") {
return $dnsname;
}
+ if ($var eq "HOSTIP") {
+ return $opt_hostip;
+ }
+
if ($var eq "LDAPTIME") {
return ldaptime();
}
@@ -108,6 +121,18 @@ sub substitute($)
return randguid();
}
+ if ($var eq "DOMAINGUID") {
+ return $domainguid;
+ }
+
+ if ($var eq "HOSTGUID") {
+ return $hostguid;
+ }
+
+ if ($var eq "DEFAULTSITE") {
+ return $defaultsite;
+ }
+
if ($var eq "ADMINPASS") {
return $opt_adminpass;
}
@@ -202,6 +227,7 @@ provision.pl [options]
--realm REALM set realm
--domain DOMAIN set domain
--hostname HOSTNAME set hostname
+ --hostip IPADDRESS set ipaddress
--adminpass PASSWORD choose admin password (otherwise random)
--nobody USERNAME choose 'nobody' user
--nogroup GROUPNAME choose 'nogroup' group
@@ -221,6 +247,7 @@ GetOptions(
'realm=s' => \$opt_realm,
'domain=s' => \$opt_domain,
'hostname=s' => \$opt_hostname,
+ 'hostip=s' => \$opt_hostip,
'adminpass=s' => \$opt_adminpass,
'nobody=s' => \$opt_nobody,
'nogroup=s' => \$opt_nogroup,
@@ -237,9 +264,19 @@ if ($opt_help ||
$opt_realm=uc($opt_realm);
$opt_domain=uc($opt_domain);
-$opt_hostname=uc($opt_hostname);
+$opt_hostname=lc($opt_hostname);
+$netbiosname=uc($opt_hostname);
+
+if (!$opt_hostip) {
+ my $hip = gethostbyname($opt_hostname);
+ if (defined $hip) {
+ $opt_hostip = inet_ntoa($hip);
+ } else {
+ $opt_hostip = "<0.0.0.0>";
+ }
+}
-print "Provisioning host '$opt_hostname' for domain '$opt_domain' in realm '$opt_realm'\n";
+print "Provisioning host '$opt_hostname'[$opt_hostip] for domain '$opt_domain' in realm '$opt_realm'\n";
if (!$opt_nobody) {
if (defined getpwnam("nobody")) {
@@ -317,9 +354,31 @@ $ENV{"PATH"} .= ":bin";
system("ldbadd -H newsam.ldb newsam.ldif");
+print "done\n";
+
+print "generating dns zone file ...\n";
+
+$data = FileLoad("provision.zone") || die "Unable to load provision.zone\n";
+
+$res = "";
+
+print "applying substitutions ...\n";
+
+while ($data =~ /(.*?)\$\{(\w*)\}(.*)/s) {
+ my $sub = substitute($2);
+ $res .= "$1$sub";
+ $data = $3;
+}
+$res .= $data;
+
+print "saving dns zone to newdns.zone ...\n";
+
+FileSave("$dnsdomain.zone", $res);
+
print "done
-Please move newsam.ldb to sam.ldb in the lib/private/ directory of your
-Samba4 installation
+Installation:
+- Please move newsam.ldb to sam.ldb in the lib/private/ directory of your
+ Samba4 installation
+- Please use $dnsdomain.zone to in BIND dns server
";
-