r6206: go baack 10 revisions to get DatabaseDeltas, this shows that the bdc only
[Samba/gebeck_regimport.git] / source4 / script / rootdse.pl
blobcfe49a65820e4270c02fce20cfbcb38855b5a096
1 #!/usr/bin/perl -w
3 use strict;
4 use Getopt::Long;
6 my $opt_hostname = `hostname`;
7 chomp $opt_hostname;
8 my $netbiosname;
9 my $opt_realm;
10 my $opt_domain;
11 my $dnsdomain;
12 my $dnsname;
13 my $basedn;
15 sub ldaptime()
17 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = gmtime(time);
18 return sprintf "%04u%02u%02u%02u%02u%02u.0Z",
19 $year+1900, $mon+1, $mday, $hour, $min, $sec;
22 #######################
23 # substitute a single variable
24 sub substitute($)
26 my $var = shift;
28 if ($var eq "BASEDN") {
29 return $basedn;
32 if ($var eq "NETBIOSNAME") {
33 return $netbiosname;
36 if ($var eq "DNSNAME") {
37 return $dnsname;
40 if ($var eq "DNSDOMAIN") {
41 return $dnsdomain;
44 die "ERROR: Uknown substitution variable $var\n";
47 #####################################################################
48 # write a string into a file
49 sub FileSave($$)
51 my($filename) = shift;
52 my($v) = shift;
53 local(*FILE);
54 open(FILE, ">$filename") || die "can't open $filename";
55 print FILE $v;
56 close(FILE);
59 #####################################################################
60 # read a file into a string
61 sub FileLoad($)
63 my($filename) = shift;
64 local(*INPUTFILE);
65 open(INPUTFILE, $filename) || return undef;
66 my($saved_delim) = $/;
67 undef $/;
68 my($data) = <INPUTFILE>;
69 close(INPUTFILE);
70 $/ = $saved_delim;
71 return $data;
74 ############################################
75 # show some help
76 sub ShowHelp()
78 print "
79 Samba4 provisioning
81 rootdse.pl [options]
82 --realm REALM set realm
83 --domain DOMAIN set domain
84 --hostname HOSTNAME set hostname
86 You must provide at least a realm and domain
89 exit(1);
92 my $opt_help;
94 GetOptions(
95 'help|h|?' => \$opt_help,
96 'realm=s' => \$opt_realm,
97 'domain=s' => \$opt_domain,
98 'hostname=s' => \$opt_hostname,
101 if ($opt_help ||
102 !$opt_realm ||
103 !$opt_domain ||
104 !$opt_hostname) {
105 ShowHelp();
108 $opt_realm=uc($opt_realm);
109 $opt_domain=uc($opt_domain);
110 $opt_hostname=lc($opt_hostname);
111 $netbiosname=uc($opt_hostname);
113 print "Provisioning host '$opt_hostname' with netbios name '$netbiosname' for domain '$opt_domain' in realm '$opt_realm'\n";
115 print "generating ldif ...\n";
117 $dnsdomain = lc($opt_realm);
118 $dnsname = $opt_hostname.".".$dnsdomain;
119 $basedn = "DC=" . join(",DC=", split(/\./, $opt_realm));
121 my $data = FileLoad("rootdse.ldif") || die "Unable to load rootdse.ldif\n";
123 my $res = "";
125 print "applying substitutions ...\n";
127 while ($data =~ /(.*?)\$\{(\w*)\}(.*)/s) {
128 my $sub = substitute($2);
129 $res .= "$1$sub";
130 $data = $3;
132 $res .= $data;
134 print "saving ldif to newrootdse.ldif ...\n";
136 FileSave("newrootdse.ldif", $res);
138 unlink("newrootdse.ldb");
140 print "creating newrootdse.ldb ...\n";
142 # allow provisioning to be run from the source directory
143 $ENV{"PATH"} .= ":bin";
145 system("ldbadd -H newrootdse.ldb newrootdse.ldif");
147 print "done
149 Please move newrootdse.ldb to rootdse.ldb in the private/ directory of your
150 Samba4 installation