diff options
author | Andrew Tridgell <tridge@samba.org> | 2004-05-03 14:58:08 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 12:51:44 -0500 |
commit | 8db18a0775a66ee3073484b987d4a9ff0fd22c90 (patch) | |
tree | 59d206db21060a70fc90f9d1e3b4dca8d1ebd211 /source4/script | |
parent | af48da52bf39f8055b6f1640bcadeb27aeaead2d (diff) | |
download | samba-8db18a0775a66ee3073484b987d4a9ff0fd22c90.tar.gz samba-8db18a0775a66ee3073484b987d4a9ff0fd22c90.tar.bz2 samba-8db18a0775a66ee3073484b987d4a9ff0fd22c90.zip |
r458: this is the (very primitive) beginnings of a SAMR server for
Samba4. I'm committing this now so I can get comments on the approach.
Note that you need to do something like this to initialise the SAM db:
edit script/provision.pl
script/provision.pl > provision.ldif.out
bin/ldbadd /path/to/private/sam.ldb provision.ldif.out
(This used to be commit e2002e40a5abe0cd33a2056b1da8ba5732f9021f)
Diffstat (limited to 'source4/script')
-rwxr-xr-x | source4/script/provision.pl | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/source4/script/provision.pl b/source4/script/provision.pl new file mode 100755 index 0000000000..e927ac13d2 --- /dev/null +++ b/source4/script/provision.pl @@ -0,0 +1,107 @@ +#!/usr/bin/perl -w + +use strict; + +my $hostname = `hostname`; +chomp $hostname; +my $realm = "tridgell.net"; +my $domain = "BLUDOM"; +my $dnsname = "$hostname.$realm"; + +my $basedn = "DC=" . join(",DN=", split(/\./, $dnsname)); + +# return the current NTTIME as an integer +sub nttime() +{ + my $t = time(); + $t += (369.0*365.25*24*60*60-(3.0*24*60*60+6.0*60*60)); + $t *= 1.0e7; + return sprintf("%lld", $t); +} + +# generate a random guid. Not a good algorithm. +sub randguid() +{ + my $r1 = int(rand(2**32)); + my $r2 = int(rand(2**16)); + my $r3 = int(rand(2**16)); + my $r4 = int(rand(2**16)); + my $r5 = int(rand(2**32)); + return sprintf("%08x-%04x-%04x-%04x-%08x", $r1, $r2, $r3, $r4, $r5); +} + +sub randsid() +{ + return sprintf("S-1-5-21-%d-%d-%d", + int(rand(10**8)), int(rand(10**8)), int(rand(10**8))); +} + +####################### +# substitute a single variable +sub substitute($) +{ + my $var = shift; + + if ($var eq "BASEDN") { + return $basedn; + } + + if ($var eq "DOMAINSID") { + return randsid(); + } + + if ($var eq "DOMAIN") { + return $domain; + } + + if ($var eq "HOSTNAME") { + return $hostname; + } + + if ($var eq "DNSNAME") { + return $dnsname; + } + + if ($var eq "LDAPTIME") { + return "20040408072022.0Z"; + } + + if ($var eq "NEWGUID") { + return randguid(); + } + + if ($var eq "NTTIME") { + return "" . nttime(); + } + + die "ERROR: Uknown substitution variable $var\n"; +} + +##################################################################### +# read a file into a string +sub FileLoad($) +{ + my($filename) = shift; + local(*INPUTFILE); + open(INPUTFILE, $filename) || return undef; + my($saved_delim) = $/; + undef $/; + my($data) = <INPUTFILE>; + close(INPUTFILE); + $/ = $saved_delim; + return $data; +} + + +my $data = FileLoad("provision.ldif") || die "Unable to load provision.ldif\n"; + +my $res = ""; + +while ($data =~ /(.*?)\$\{(\w*)\}(.*)/s) { + my $sub = substitute($2); + $res .= "$1$sub"; + $data = $3; +} + +print $res . $data; + |