s4:librpc/rpc: remember the target_hostname on ncacn_http connections
[Samba.git] / selftest / target / Samba4.pm
blob205e2813db6ee116605f2e35398af92118ae46f0
1 #!/usr/bin/perl
2 # Bootstrap Samba and run a number of tests against it.
3 # Copyright (C) 2005-2007 Jelmer Vernooij <jelmer@samba.org>
4 # Published under the GNU GPL, v3 or later.
6 package Samba4;
8 use strict;
9 use Cwd qw(abs_path);
10 use FindBin qw($RealBin);
11 use POSIX;
12 use SocketWrapper;
13 use target::Samba;
14 use target::Samba3;
16 sub new($$$$$) {
17 my ($classname, $bindir, $ldap, $srcdir, $server_maxtime) = @_;
19 my $self = {
20 vars => {},
21 ldap => $ldap,
22 bindir => $bindir,
23 srcdir => $srcdir,
24 server_maxtime => $server_maxtime,
25 target3 => new Samba3($bindir, $srcdir, $server_maxtime)
27 bless $self;
28 return $self;
31 sub scriptdir_path($$) {
32 my ($self, $path) = @_;
33 return "$self->{srcdir}/source4/scripting/$path";
36 sub openldap_start($$$) {
39 sub slapd_start($$)
41 my $count = 0;
42 my ($self, $env_vars, $STDIN_READER) = @_;
43 my $ldbsearch = Samba::bindir_path($self, "ldbsearch");
45 my $uri = $env_vars->{LDAP_URI};
47 if (system("$ldbsearch -H $uri -s base -b \"\" supportedLDAPVersion > /dev/null") == 0) {
48 print "A SLAPD is still listening to $uri before we started the LDAP backend. Aborting!";
49 return 1;
51 # running slapd in the background means it stays in the same process group, so it can be
52 # killed by timelimit
53 my $pid = fork();
54 if ($pid == 0) {
55 open STDOUT, ">$env_vars->{LDAPDIR}/logs";
56 open STDERR, '>&STDOUT';
57 close($env_vars->{STDIN_PIPE});
58 open STDIN, ">&", $STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
60 if ($self->{ldap} eq "fedora-ds") {
61 exec("$ENV{FEDORA_DS_ROOT}/sbin/ns-slapd", "-D", $env_vars->{FEDORA_DS_DIR}, "-d0", "-i", $env_vars->{FEDORA_DS_PIDFILE});
62 } elsif ($self->{ldap} eq "openldap") {
63 exec($ENV{OPENLDAP_SLAPD}, "-dnone", "-F", $env_vars->{SLAPD_CONF_D}, "-h", $uri);
65 die("Unable to start slapd: $!");
67 $env_vars->{SLAPD_PID} = $pid;
68 sleep(1);
69 while (system("$ldbsearch -H $uri -s base -b \"\" supportedLDAPVersion > /dev/null") != 0) {
70 $count++;
71 if ($count > 40) {
72 $self->slapd_stop($env_vars);
73 return 0;
75 sleep(1);
77 return 1;
80 sub slapd_stop($$)
82 my ($self, $envvars) = @_;
83 kill 9, $envvars->{SLAPD_PID};
84 return 1;
87 sub check_or_start($$$)
89 my ($self, $env_vars, $process_model) = @_;
90 my $STDIN_READER;
92 my $env_ok = $self->check_env($env_vars);
93 if ($env_ok) {
94 return $env_vars->{SAMBA_PID};
95 } elsif (defined($env_vars->{SAMBA_PID})) {
96 warn("SAMBA PID $env_vars->{SAMBA_PID} is not running (died)");
97 return undef;
100 # use a pipe for stdin in the child processes. This allows
101 # those processes to monitor the pipe for EOF to ensure they
102 # exit when the test script exits
103 pipe($STDIN_READER, $env_vars->{STDIN_PIPE});
105 # Start slapd before samba, but with the fifo on stdin
106 if (defined($self->{ldap})) {
107 unless($self->slapd_start($env_vars, $STDIN_READER)) {
108 warn("couldn't start slapd (main run)");
109 return undef;
113 print "STARTING SAMBA...\n";
114 my $pid = fork();
115 if ($pid == 0) {
116 # we want out from samba to go to the log file, but also
117 # to the users terminal when running 'make test' on the command
118 # line. This puts it on stderr on the terminal
119 open STDOUT, "| tee $env_vars->{SAMBA_TEST_LOG} 1>&2";
120 open STDERR, '>&STDOUT';
122 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
124 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
125 $ENV{KRB5CCNAME} = "$env_vars->{KRB5_CCACHE}.samba";
126 if (defined($ENV{MITKRB5})) {
127 $ENV{KRB5_KDC_PROFILE} = $env_vars->{MITKDC_CONFIG};
129 $ENV{SELFTEST_WINBINDD_SOCKET_DIR} = $env_vars->{SELFTEST_WINBINDD_SOCKET_DIR};
130 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
132 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
133 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
134 $ENV{NSS_WRAPPER_HOSTS} = $env_vars->{NSS_WRAPPER_HOSTS};
135 $ENV{NSS_WRAPPER_HOSTNAME} = $env_vars->{NSS_WRAPPER_HOSTNAME};
136 $ENV{NSS_WRAPPER_MODULE_SO_PATH} = $env_vars->{NSS_WRAPPER_MODULE_SO_PATH};
137 $ENV{NSS_WRAPPER_MODULE_FN_PREFIX} = $env_vars->{NSS_WRAPPER_MODULE_FN_PREFIX};
139 if (defined($env_vars->{RESOLV_WRAPPER_CONF})) {
140 $ENV{RESOLV_WRAPPER_CONF} = $env_vars->{RESOLV_WRAPPER_CONF};
141 } else {
142 $ENV{RESOLV_WRAPPER_HOSTS} = $env_vars->{RESOLV_WRAPPER_HOSTS};
145 $ENV{UID_WRAPPER} = "1";
146 $ENV{UID_WRAPPER_ROOT} = "1";
148 $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "samba");
149 my @preargs = ();
150 my @optargs = ();
151 if (defined($ENV{SAMBA_OPTIONS})) {
152 @optargs = split(/ /, $ENV{SAMBA_OPTIONS});
154 if(defined($ENV{SAMBA_VALGRIND})) {
155 @preargs = split(/ /,$ENV{SAMBA_VALGRIND});
158 close($env_vars->{STDIN_PIPE});
159 open STDIN, ">&", $STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
161 exec(@preargs, Samba::bindir_path($self, "samba"), "-M", $process_model, "-i", "--maximum-runtime=$self->{server_maxtime}", $env_vars->{CONFIGURATION}, @optargs) or die("Unable to start samba: $!");
163 $env_vars->{SAMBA_PID} = $pid;
164 print "DONE ($pid)\n";
166 close($STDIN_READER);
168 if ($self->wait_for_start($env_vars) != 0) {
169 warn("Samba $pid failed to start up");
170 return undef;
173 return $pid;
176 sub wait_for_start($$)
178 my ($self, $testenv_vars) = @_;
179 my $count = 0;
180 my $ret = 0;
182 if (not $self->check_env($testenv_vars)) {
183 warn("unable to confirm Samba $testenv_vars->{SAMBA_PID} is running");
184 return -1;
187 # This will return quickly when things are up, but be slow if we
188 # need to wait for (eg) SSL init
189 my $nmblookup = Samba::bindir_path($self, "nmblookup4");
191 do {
192 $ret = system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
193 if ($ret != 0) {
194 sleep(1);
195 } else {
196 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
197 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
198 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
199 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
200 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
201 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
202 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
203 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
204 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
205 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
206 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
208 $count++;
209 } while ($ret != 0 && $count < 20);
210 if ($count == 20) {
211 warn("nbt not reachable after 20 retries\n");
212 teardown_env($self, $testenv_vars);
213 return 0;
216 # Ensure we have the first RID Set before we start tests. This makes the tests more reliable.
217 if ($testenv_vars->{SERVER_ROLE} eq "domain controller") {
218 # Add hosts file for name lookups
219 $ENV{NSS_WRAPPER_HOSTS} = $testenv_vars->{NSS_WRAPPER_HOSTS};
220 if (defined($testenv_vars->{RESOLV_WRAPPER_CONF})) {
221 $ENV{RESOLV_WRAPPER_CONF} = $testenv_vars->{RESOLV_WRAPPER_CONF};
222 } else {
223 $ENV{RESOLV_WRAPPER_HOSTS} = $testenv_vars->{RESOLV_WRAPPER_HOSTS};
226 print "waiting for working LDAP and a RID Set to be allocated\n";
227 my $ldbsearch = Samba::bindir_path($self, "ldbsearch");
228 my $count = 0;
229 my $base_dn = "DC=".join(",DC=", split(/\./, $testenv_vars->{REALM}));
231 my $search_dn = $base_dn;
232 if ($testenv_vars->{NETBIOSNAME} ne "RODC") {
233 # TODO currently no check for actual rIDAllocationPool
234 $search_dn = "cn=RID Set,cn=$testenv_vars->{NETBIOSNAME},ou=domain controllers,$base_dn";
236 my $max_wait = 60;
237 my $cmd = "$ldbsearch $testenv_vars->{CONFIGURATION} -H ldap://$testenv_vars->{SERVER} -U$testenv_vars->{USERNAME}%$testenv_vars->{PASSWORD} -s base -b \"$search_dn\"";
238 while (system("$cmd >/dev/null") != 0) {
239 $count++;
240 if ($count > $max_wait) {
241 warn("Timed out ($max_wait sec) waiting for working LDAP and a RID Set to be allocated by $testenv_vars->{NETBIOSNAME} PID $testenv_vars->{SAMBA_PID}");
242 $ret = -1;
243 last;
245 sleep(1);
249 my $wbinfo = Samba::bindir_path($self, "wbinfo");
251 $count = 0;
252 do {
253 my $cmd = "NSS_WRAPPER_PASSWD=$testenv_vars->{NSS_WRAPPER_PASSWD} ";
254 $cmd .= "NSS_WRAPPER_GROUP=$testenv_vars->{NSS_WRAPPER_GROUP} ";
255 $cmd .= "SELFTEST_WINBINDD_SOCKET_DIR=$testenv_vars->{SELFTEST_WINBINDD_SOCKET_DIR} ";
256 $cmd .= "$wbinfo -p";
257 $ret = system($cmd);
259 if ($ret != 0) {
260 sleep(1);
262 $count++;
263 } while ($ret != 0 && $count < 20);
264 if ($count == 20) {
265 warn("winbind not reachable after 20 retries\n");
266 teardown_env($self, $testenv_vars);
267 return 0;
270 print $self->getlog_env($testenv_vars);
272 return $ret
275 sub write_ldb_file($$$)
277 my ($self, $file, $ldif) = @_;
279 my $ldbadd = Samba::bindir_path($self, "ldbadd");
280 open(LDIF, "|$ldbadd -H $file >/dev/null");
281 print LDIF $ldif;
282 return(close(LDIF));
285 sub add_wins_config($$)
287 my ($self, $privatedir) = @_;
289 return $self->write_ldb_file("$privatedir/wins_config.ldb", "
290 dn: name=TORTURE_11,CN=PARTNERS
291 objectClass: wreplPartner
292 name: TORTURE_11
293 address: 127.0.0.11
294 pullInterval: 0
295 pushChangeCount: 0
296 type: 0x3
300 sub mk_fedora_ds($$)
302 my ($self, $ctx) = @_;
304 #Make the subdirectory be as fedora DS would expect
305 my $fedora_ds_dir = "$ctx->{ldapdir}/slapd-$ctx->{ldap_instance}";
307 my $pidfile = "$fedora_ds_dir/logs/slapd-$ctx->{ldap_instance}.pid";
309 return ($fedora_ds_dir, $pidfile);
312 sub mk_openldap($$)
314 my ($self, $ctx) = @_;
316 my $slapd_conf_d = "$ctx->{ldapdir}/slapd.d";
317 my $pidfile = "$ctx->{ldapdir}/slapd.pid";
319 return ($slapd_conf_d, $pidfile);
322 sub setup_namespaces($$:$$)
324 my ($self, $localenv, $upn_array, $spn_array) = @_;
326 @{$upn_array} = [] unless defined($upn_array);
327 my $upn_args = "";
328 foreach my $upn (@{$upn_array}) {
329 $upn_args .= " --add-upn-suffix=$upn";
332 @{$spn_array} = [] unless defined($spn_array);
333 my $spn_args = "";
334 foreach my $spn (@{$spn_array}) {
335 $spn_args .= " --add-spn-suffix=$spn";
338 my $samba_tool = Samba::bindir_path($self, "samba-tool");
340 my $cmd_env = "";
341 $cmd_env .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$localenv->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
342 if (defined($localenv->{RESOLV_WRAPPER_CONF})) {
343 $cmd_env .= "RESOLV_WRAPPER_CONF=\"$localenv->{RESOLV_WRAPPER_CONF}\" ";
344 } else {
345 $cmd_env .= "RESOLV_WRAPPER_HOSTS=\"$localenv->{RESOLV_WRAPPER_HOSTS}\" ";
347 $cmd_env .= " KRB5_CONFIG=\"$localenv->{KRB5_CONFIG}\" ";
348 $cmd_env .= "KRB5CCNAME=\"$localenv->{KRB5_CCACHE}\" ";
350 my $cmd_config = " $localenv->{CONFIGURATION}";
352 my $namespaces = $cmd_env;
353 $namespaces .= " $samba_tool domain trust namespaces $upn_args $spn_args";
354 $namespaces .= $cmd_config;
355 unless (system($namespaces) == 0) {
356 warn("Failed to add namespaces \n$namespaces");
357 return;
360 return;
363 sub setup_trust($$$$$)
365 my ($self, $localenv, $remoteenv, $type, $extra_args) = @_;
367 $localenv->{TRUST_SERVER} = $remoteenv->{SERVER};
368 $localenv->{TRUST_SERVER_IP} = $remoteenv->{SERVER_IP};
369 $localenv->{TRUST_SERVER_IPV6} = $remoteenv->{SERVER_IPV6};
370 $localenv->{TRUST_NETBIOSNAME} = $remoteenv->{NETBIOSNAME};
371 $localenv->{TRUST_USERNAME} = $remoteenv->{USERNAME};
372 $localenv->{TRUST_PASSWORD} = $remoteenv->{PASSWORD};
373 $localenv->{TRUST_DOMAIN} = $remoteenv->{DOMAIN};
374 $localenv->{TRUST_REALM} = $remoteenv->{REALM};
376 my $samba_tool = Samba::bindir_path($self, "samba-tool");
377 # setup the trust
378 my $cmd_env = "";
379 $cmd_env .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$localenv->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
380 if (defined($localenv->{RESOLV_WRAPPER_CONF})) {
381 $cmd_env .= "RESOLV_WRAPPER_CONF=\"$localenv->{RESOLV_WRAPPER_CONF}\" ";
382 } else {
383 $cmd_env .= "RESOLV_WRAPPER_HOSTS=\"$localenv->{RESOLV_WRAPPER_HOSTS}\" ";
385 $cmd_env .= " KRB5_CONFIG=\"$localenv->{KRB5_CONFIG}\" ";
386 $cmd_env .= "KRB5CCNAME=\"$localenv->{KRB5_CCACHE}\" ";
388 my $cmd_config = " $localenv->{CONFIGURATION}";
389 my $cmd_creds = $cmd_config;
390 $cmd_creds .= " -U$localenv->{TRUST_DOMAIN}\\\\$localenv->{TRUST_USERNAME}\%$localenv->{TRUST_PASSWORD}";
392 my $create = $cmd_env;
393 $create .= " $samba_tool domain trust create --type=${type} $localenv->{TRUST_REALM}";
394 $create .= " $extra_args";
395 $create .= $cmd_creds;
396 unless (system($create) == 0) {
397 warn("Failed to create trust \n$create");
398 return undef;
401 return $localenv
404 sub provision_raw_prepare($$$$$$$$$$$)
406 my ($self, $prefix, $server_role, $hostname,
407 $domain, $realm, $functional_level,
408 $password, $kdc_ipv4, $kdc_ipv6) = @_;
409 my $ctx;
410 my $netbiosname = uc($hostname);
412 unless(-d $prefix or mkdir($prefix, 0777)) {
413 warn("Unable to create $prefix");
414 return undef;
416 my $prefix_abs = abs_path($prefix);
418 die ("prefix=''") if $prefix_abs eq "";
419 die ("prefix='/'") if $prefix_abs eq "/";
421 unless (system("rm -rf $prefix_abs/*") == 0) {
422 warn("Unable to clean up");
426 my $swiface = Samba::get_interface($hostname);
428 $ctx->{prefix} = $prefix;
429 $ctx->{prefix_abs} = $prefix_abs;
431 $ctx->{server_role} = $server_role;
432 $ctx->{hostname} = $hostname;
433 $ctx->{netbiosname} = $netbiosname;
434 $ctx->{swiface} = $swiface;
435 $ctx->{password} = $password;
436 $ctx->{kdc_ipv4} = $kdc_ipv4;
437 $ctx->{kdc_ipv6} = $kdc_ipv6;
438 $ctx->{krb5_ccname} = "$prefix_abs/krb5cc_%{uid}";
439 if ($functional_level eq "2000") {
440 $ctx->{supported_enctypes} = "arcfour-hmac-md5 des-cbc-md5 des-cbc-crc"
444 # Set smbd log level here.
446 $ctx->{server_loglevel} =$ENV{SERVER_LOG_LEVEL} || 1;
447 $ctx->{username} = "Administrator";
448 $ctx->{domain} = $domain;
449 $ctx->{realm} = uc($realm);
450 $ctx->{dnsname} = lc($realm);
452 $ctx->{functional_level} = $functional_level;
454 my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `whoami`);
455 chomp $unix_name;
456 $ctx->{unix_name} = $unix_name;
457 $ctx->{unix_uid} = $>;
458 my @mygid = split(" ", $();
459 $ctx->{unix_gid} = $mygid[0];
460 $ctx->{unix_gids_str} = $);
461 @{$ctx->{unix_gids}} = split(" ", $ctx->{unix_gids_str});
463 $ctx->{etcdir} = "$prefix_abs/etc";
464 $ctx->{piddir} = "$prefix_abs/pid";
465 $ctx->{smb_conf} = "$ctx->{etcdir}/smb.conf";
466 $ctx->{krb5_conf} = "$ctx->{etcdir}/krb5.conf";
467 $ctx->{krb5_ccache} = "$prefix_abs/krb5_ccache";
468 $ctx->{mitkdc_conf} = "$ctx->{etcdir}/mitkdc.conf";
469 $ctx->{privatedir} = "$prefix_abs/private";
470 $ctx->{ncalrpcdir} = "$prefix_abs/ncalrpc";
471 $ctx->{lockdir} = "$prefix_abs/lockdir";
472 $ctx->{logdir} = "$prefix_abs/logs";
473 $ctx->{statedir} = "$prefix_abs/statedir";
474 $ctx->{cachedir} = "$prefix_abs/cachedir";
475 $ctx->{winbindd_socket_dir} = "$prefix_abs/winbindd_socket";
476 $ctx->{ntp_signd_socket_dir} = "$prefix_abs/ntp_signd_socket";
477 $ctx->{nsswrap_passwd} = "$ctx->{etcdir}/passwd";
478 $ctx->{nsswrap_group} = "$ctx->{etcdir}/group";
479 $ctx->{nsswrap_hosts} = "$ENV{SELFTEST_PREFIX}/hosts";
480 $ctx->{nsswrap_hostname} = "$ctx->{hostname}.$ctx->{dnsname}";
481 if ($ENV{SAMBA_DNS_FAKING}) {
482 $ctx->{dns_host_file} = "$ENV{SELFTEST_PREFIX}/dns_host_file";
483 $ctx->{samba_dnsupdate} = "$ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate -s $ctx->{smb_conf} --all-interfaces --use-file=$ctx->{dns_host_file}";
484 } else {
485 $ctx->{samba_dnsupdate} = "$ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate -s $ctx->{smb_conf} --all-interfaces";
486 $ctx->{use_resolv_wrapper} = 1;
488 $ctx->{resolv_conf} = "$ctx->{etcdir}/resolv.conf";
490 $ctx->{tlsdir} = "$ctx->{privatedir}/tls";
492 $ctx->{ipv4} = "127.0.0.$swiface";
493 $ctx->{ipv6} = sprintf("fd00:0000:0000:0000:0000:0000:5357:5f%02x", $swiface);
494 $ctx->{interfaces} = "$ctx->{ipv4}/8 $ctx->{ipv6}/64";
496 push(@{$ctx->{directories}}, $ctx->{privatedir});
497 push(@{$ctx->{directories}}, $ctx->{etcdir});
498 push(@{$ctx->{directories}}, $ctx->{piddir});
499 push(@{$ctx->{directories}}, $ctx->{lockdir});
500 push(@{$ctx->{directories}}, $ctx->{logdir});
501 push(@{$ctx->{directories}}, $ctx->{statedir});
502 push(@{$ctx->{directories}}, $ctx->{cachedir});
504 $ctx->{smb_conf_extra_options} = "";
506 my @provision_options = ();
507 push (@provision_options, "KRB5_CONFIG=\"$ctx->{krb5_conf}\"");
508 push (@provision_options, "KRB5_CCACHE=\"$ctx->{krb5_ccache}\"");
509 push (@provision_options, "NSS_WRAPPER_PASSWD=\"$ctx->{nsswrap_passwd}\"");
510 push (@provision_options, "NSS_WRAPPER_GROUP=\"$ctx->{nsswrap_group}\"");
511 push (@provision_options, "NSS_WRAPPER_HOSTS=\"$ctx->{nsswrap_hosts}\"");
512 push (@provision_options, "NSS_WRAPPER_HOSTNAME=\"$ctx->{nsswrap_hostname}\"");
513 if (defined($ctx->{use_resolv_wrapper})) {
514 push (@provision_options, "RESOLV_WRAPPER_CONF=\"$ctx->{resolv_conf}\"");
515 } else {
516 push (@provision_options, "RESOLV_WRAPPER_HOSTS=\"$ctx->{dns_host_file}\"");
518 if (defined($ENV{GDB_PROVISION})) {
519 push (@provision_options, "gdb --args");
520 if (!defined($ENV{PYTHON})) {
521 push (@provision_options, "env");
522 push (@provision_options, "python");
525 if (defined($ENV{VALGRIND_PROVISION})) {
526 push (@provision_options, "valgrind");
527 if (!defined($ENV{PYTHON})) {
528 push (@provision_options, "env");
529 push (@provision_options, "python");
532 if (defined($ENV{PYTHON})) {
533 push (@provision_options, $ENV{PYTHON});
535 push (@provision_options, Samba::bindir_path($self, "samba-tool"));
536 push (@provision_options, "domain");
537 push (@provision_options, "provision");
538 push (@provision_options, "--configfile=$ctx->{smb_conf}");
539 push (@provision_options, "--host-name=$ctx->{hostname}");
540 push (@provision_options, "--host-ip=$ctx->{ipv4}");
541 push (@provision_options, "--quiet");
542 push (@provision_options, "--domain=$ctx->{domain}");
543 push (@provision_options, "--realm=$ctx->{realm}");
544 push (@provision_options, "--adminpass=$ctx->{password}");
545 push (@provision_options, "--krbtgtpass=krbtgt$ctx->{password}");
546 push (@provision_options, "--machinepass=machine$ctx->{password}");
547 push (@provision_options, "--root=$ctx->{unix_name}");
548 push (@provision_options, "--server-role=\"$ctx->{server_role}\"");
549 push (@provision_options, "--function-level=\"$ctx->{functional_level}\"");
551 @{$ctx->{provision_options}} = @provision_options;
553 return $ctx;
557 # Step1 creates the basic configuration
559 sub provision_raw_step1($$)
561 my ($self, $ctx) = @_;
563 mkdir($_, 0777) foreach (@{$ctx->{directories}});
566 ## lockdir and piddir must be 0755
568 chmod 0755, $ctx->{lockdir};
569 chmod 0755, $ctx->{piddir};
571 unless (open(CONFFILE, ">$ctx->{smb_conf}")) {
572 warn("can't open $ctx->{smb_conf}$?");
573 return undef;
576 Samba::prepare_keyblobs($ctx);
577 my $crlfile = "$ctx->{tlsdir}/crl.pem";
578 $crlfile = "" unless -e ${crlfile};
580 print CONFFILE "
581 [global]
582 netbios name = $ctx->{netbiosname}
583 posix:eadb = $ctx->{statedir}/eadb.tdb
584 workgroup = $ctx->{domain}
585 realm = $ctx->{realm}
586 private dir = $ctx->{privatedir}
587 pid directory = $ctx->{piddir}
588 ncalrpc dir = $ctx->{ncalrpcdir}
589 lock dir = $ctx->{lockdir}
590 state directory = $ctx->{statedir}
591 cache directory = $ctx->{cachedir}
592 winbindd socket directory = $ctx->{winbindd_socket_dir}
593 ntp signd socket directory = $ctx->{ntp_signd_socket_dir}
594 winbind separator = /
595 interfaces = $ctx->{interfaces}
596 tls dh params file = $ctx->{tlsdir}/dhparms.pem
597 tls crlfile = ${crlfile}
598 tls verify peer = no_check
599 panic action = $RealBin/gdb_backtrace \%d
600 wins support = yes
601 server role = $ctx->{server_role}
602 server services = +echo +smb -s3fs
603 dcerpc endpoint servers = +winreg +srvsvc
604 notify:inotify = false
605 ldb:nosync = true
606 ldap server require strong auth = yes
607 #We don't want to pass our self-tests if the PAC code is wrong
608 gensec:require_pac = true
609 log file = $ctx->{logdir}/log.\%m
610 log level = $ctx->{server_loglevel}
611 lanman auth = Yes
612 ntlm auth = Yes
613 rndc command = true
614 dns update command = $ctx->{samba_dnsupdate}
615 spn update command = $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_spnupdate -s $ctx->{smb_conf}
616 dreplsrv:periodic_startup_interval = 0
617 dsdb:schema update allowed = yes
619 vfs objects = dfs_samba4 acl_xattr fake_acls xattr_tdb streams_depot
621 idmap_ldb:use rfc2307=yes
622 winbind enum users = yes
623 winbind enum groups = yes
625 rpc server port:netlogon = 1026
629 print CONFFILE "
631 # Begin extra options
632 $ctx->{smb_conf_extra_options}
633 # End extra options
635 close(CONFFILE);
637 #Default the KDC IP to the server's IP
638 if (not defined($ctx->{kdc_ipv4})) {
639 $ctx->{kdc_ipv4} = $ctx->{ipv4};
641 if (not defined($ctx->{kdc_ipv6})) {
642 $ctx->{kdc_ipv6} = $ctx->{ipv6};
645 Samba::mk_krb5_conf($ctx);
646 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
648 open(PWD, ">$ctx->{nsswrap_passwd}");
649 if ($ctx->{unix_uid} != 0) {
650 print PWD "root:x:0:0:root gecos:$ctx->{prefix_abs}:/bin/false\n";
652 print PWD "$ctx->{unix_name}:x:$ctx->{unix_uid}:65531:$ctx->{unix_name} gecos:$ctx->{prefix_abs}:/bin/false\n";
653 print PWD "nobody:x:65534:65533:nobody gecos:$ctx->{prefix_abs}:/bin/false
654 pdbtest:x:65533:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
655 pdbtest2:x:65532:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
656 pdbtest3:x:65531:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
657 pdbtest4:x:65530:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
659 close(PWD);
660 my $uid_rfc2307test = 65533;
662 open(GRP, ">$ctx->{nsswrap_group}");
663 if ($ctx->{unix_gid} != 0) {
664 print GRP "root:x:0:\n";
666 print GRP "$ctx->{unix_name}:x:$ctx->{unix_gid}:\n";
667 print GRP "wheel:x:10:
668 users:x:65531:
669 nobody:x:65533:
670 nogroup:x:65534:nobody
672 close(GRP);
673 my $gid_rfc2307test = 65532;
675 my $hostname = lc($ctx->{hostname});
676 open(HOSTS, ">>$ctx->{nsswrap_hosts}");
677 if ($hostname eq "localdc") {
678 print HOSTS "$ctx->{ipv4} ${hostname}.$ctx->{dnsname} $ctx->{dnsname} ${hostname}\n";
679 print HOSTS "$ctx->{ipv6} ${hostname}.$ctx->{dnsname} $ctx->{dnsname} ${hostname}\n";
680 } else {
681 print HOSTS "$ctx->{ipv4} ${hostname}.$ctx->{dnsname} ${hostname}\n";
682 print HOSTS "$ctx->{ipv6} ${hostname}.$ctx->{dnsname} ${hostname}\n";
684 close(HOSTS);
686 if (defined($ctx->{resolv_conf})) {
687 open(RESOLV_CONF, ">$ctx->{resolv_conf}");
688 print RESOLV_CONF "nameserver $ctx->{kdc_ipv4}\n";
689 print RESOLV_CONF "nameserver $ctx->{kdc_ipv6}\n";
690 close(RESOLV_CONF);
693 my $configuration = "--configfile=$ctx->{smb_conf}";
695 #Ensure the config file is valid before we start
696 my $testparm = Samba::bindir_path($self, "samba-tool") . " testparm";
697 if (system("$testparm $configuration -v --suppress-prompt >/dev/null 2>&1") != 0) {
698 system("$testparm -v --suppress-prompt $configuration >&2");
699 warn("Failed to create a valid smb.conf configuration $testparm!");
700 return undef;
702 unless (system("($testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global 2> /dev/null | grep -i \"^$ctx->{netbiosname}\" ) >/dev/null 2>&1") == 0) {
703 warn("Failed to create a valid smb.conf configuration! $testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global");
704 return undef;
707 my $ret = {
708 KRB5_CONFIG => $ctx->{krb5_conf},
709 KRB5_CCACHE => $ctx->{krb5_ccache},
710 MITKDC_CONFIG => $ctx->{mitkdc_conf},
711 PIDDIR => $ctx->{piddir},
712 SERVER => $ctx->{hostname},
713 SERVER_IP => $ctx->{ipv4},
714 SERVER_IPV6 => $ctx->{ipv6},
715 NETBIOSNAME => $ctx->{netbiosname},
716 DOMAIN => $ctx->{domain},
717 USERNAME => $ctx->{username},
718 REALM => $ctx->{realm},
719 PASSWORD => $ctx->{password},
720 LDAPDIR => $ctx->{ldapdir},
721 LDAP_INSTANCE => $ctx->{ldap_instance},
722 SELFTEST_WINBINDD_SOCKET_DIR => $ctx->{winbindd_socket_dir},
723 NCALRPCDIR => $ctx->{ncalrpcdir},
724 LOCKDIR => $ctx->{lockdir},
725 STATEDIR => $ctx->{statedir},
726 CACHEDIR => $ctx->{cachedir},
727 PRIVATEDIR => $ctx->{privatedir},
728 SERVERCONFFILE => $ctx->{smb_conf},
729 CONFIGURATION => $configuration,
730 SOCKET_WRAPPER_DEFAULT_IFACE => $ctx->{swiface},
731 NSS_WRAPPER_PASSWD => $ctx->{nsswrap_passwd},
732 NSS_WRAPPER_GROUP => $ctx->{nsswrap_group},
733 NSS_WRAPPER_HOSTS => $ctx->{nsswrap_hosts},
734 NSS_WRAPPER_HOSTNAME => $ctx->{nsswrap_hostname},
735 SAMBA_TEST_FIFO => "$ctx->{prefix}/samba_test.fifo",
736 SAMBA_TEST_LOG => "$ctx->{prefix}/samba_test.log",
737 SAMBA_TEST_LOG_POS => 0,
738 NSS_WRAPPER_MODULE_SO_PATH => Samba::nss_wrapper_winbind_so_path($self),
739 NSS_WRAPPER_MODULE_FN_PREFIX => "winbind",
740 LOCAL_PATH => $ctx->{share},
741 UID_RFC2307TEST => $uid_rfc2307test,
742 GID_RFC2307TEST => $gid_rfc2307test,
743 SERVER_ROLE => $ctx->{server_role},
744 RESOLV_CONF => $ctx->{resolv_conf}
747 if (defined($ctx->{use_resolv_wrapper})) {
748 $ret->{RESOLV_WRAPPER_CONF} = $ctx->{resolv_conf};
749 } else {
750 $ret->{RESOLV_WRAPPER_HOSTS} = $ctx->{dns_host_file};
753 return $ret;
757 # Step2 runs the provision script
759 sub provision_raw_step2($$$)
761 my ($self, $ctx, $ret) = @_;
763 my $provision_cmd = join(" ", @{$ctx->{provision_options}});
764 unless (system($provision_cmd) == 0) {
765 warn("Unable to provision: \n$provision_cmd\n");
766 return undef;
769 my $testallowed_account = "testallowed";
770 my $samba_tool_cmd = "";
771 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
772 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
773 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
774 . " user create --configfile=$ctx->{smb_conf} $testallowed_account $ctx->{password}";
775 unless (system($samba_tool_cmd) == 0) {
776 warn("Unable to add testallowed user: \n$samba_tool_cmd\n");
777 return undef;
780 my $ldbmodify = "";
781 $ldbmodify .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
782 $ldbmodify .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
783 $ldbmodify .= Samba::bindir_path($self, "ldbmodify");
784 my $base_dn = "DC=".join(",DC=", split(/\./, $ctx->{realm}));
786 if ($ctx->{server_role} ne "domain controller") {
787 $base_dn = "DC=$ctx->{netbiosname}";
790 my $user_dn = "cn=$testallowed_account,cn=users,$base_dn";
791 $testallowed_account = "testallowed account";
792 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
793 print LDIF "dn: $user_dn
794 changetype: modify
795 replace: samAccountName
796 samAccountName: $testallowed_account
799 close(LDIF);
801 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
802 print LDIF "dn: $user_dn
803 changetype: modify
804 replace: userPrincipalName
805 userPrincipalName: testallowed upn\@$ctx->{realm}
806 replace: servicePrincipalName
807 servicePrincipalName: host/testallowed
810 close(LDIF);
812 $samba_tool_cmd = "";
813 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
814 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
815 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
816 . " user create --configfile=$ctx->{smb_conf} testdenied $ctx->{password}";
817 unless (system($samba_tool_cmd) == 0) {
818 warn("Unable to add testdenied user: \n$samba_tool_cmd\n");
819 return undef;
822 my $user_dn = "cn=testdenied,cn=users,$base_dn";
823 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
824 print LDIF "dn: $user_dn
825 changetype: modify
826 replace: userPrincipalName
827 userPrincipalName: testdenied_upn\@$ctx->{realm}.upn
830 close(LDIF);
832 $samba_tool_cmd = "";
833 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
834 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
835 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
836 . " group addmembers --configfile=$ctx->{smb_conf} 'Allowed RODC Password Replication Group' '$testallowed_account'";
837 unless (system($samba_tool_cmd) == 0) {
838 warn("Unable to add '$testallowed_account' user to 'Allowed RODC Password Replication Group': \n$samba_tool_cmd\n");
839 return undef;
842 # Create to users alice and bob!
843 my $user_account_array = ["alice", "bob"];
845 foreach my $user_account (@{$user_account_array}) {
846 my $samba_tool_cmd = "";
848 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
849 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
850 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
851 . " user create --configfile=$ctx->{smb_conf} $user_account Secret007";
852 unless (system($samba_tool_cmd) == 0) {
853 warn("Unable to create user: $user_account\n$samba_tool_cmd\n");
854 return undef;
858 return $ret;
861 sub provision($$$$$$$$$$)
863 my ($self, $prefix, $server_role, $hostname,
864 $domain, $realm, $functional_level,
865 $password, $kdc_ipv4, $kdc_ipv6, $extra_smbconf_options, $extra_smbconf_shares,
866 $extra_provision_options) = @_;
868 my $ctx = $self->provision_raw_prepare($prefix, $server_role,
869 $hostname,
870 $domain, $realm, $functional_level,
871 $password, $kdc_ipv4, $kdc_ipv6);
873 if (defined($extra_provision_options)) {
874 push (@{$ctx->{provision_options}}, @{$extra_provision_options});
875 } else {
876 push (@{$ctx->{provision_options}}, "--use-ntvfs");
879 $ctx->{share} = "$ctx->{prefix_abs}/share";
880 push(@{$ctx->{directories}}, "$ctx->{share}");
881 push(@{$ctx->{directories}}, "$ctx->{share}/test1");
882 push(@{$ctx->{directories}}, "$ctx->{share}/test2");
884 # precreate directories for printer drivers
885 push(@{$ctx->{directories}}, "$ctx->{share}/W32X86");
886 push(@{$ctx->{directories}}, "$ctx->{share}/x64");
887 push(@{$ctx->{directories}}, "$ctx->{share}/WIN40");
889 my $msdfs = "no";
890 $msdfs = "yes" if ($server_role eq "domain controller");
891 $ctx->{smb_conf_extra_options} = "
893 max xmit = 32K
894 server max protocol = SMB2
895 host msdfs = $msdfs
896 lanman auth = yes
898 # fruit:copyfile is a global option
899 fruit:copyfile = yes
901 $extra_smbconf_options
903 [tmp]
904 path = $ctx->{share}
905 read only = no
906 posix:sharedelay = 100000
907 posix:oplocktimeout = 3
908 posix:writetimeupdatedelay = 500000
910 [xcopy_share]
911 path = $ctx->{share}
912 read only = no
913 posix:sharedelay = 100000
914 posix:oplocktimeout = 3
915 posix:writetimeupdatedelay = 500000
916 create mask = 777
917 force create mode = 777
919 [posix_share]
920 path = $ctx->{share}
921 read only = no
922 create mask = 0777
923 force create mode = 0
924 directory mask = 0777
925 force directory mode = 0
927 [test1]
928 path = $ctx->{share}/test1
929 read only = no
930 posix:sharedelay = 100000
931 posix:oplocktimeout = 3
932 posix:writetimeupdatedelay = 500000
934 [test2]
935 path = $ctx->{share}/test2
936 read only = no
937 posix:sharedelay = 100000
938 posix:oplocktimeout = 3
939 posix:writetimeupdatedelay = 500000
941 [cifs]
942 path = $ctx->{share}/_ignore_cifs_
943 read only = no
944 ntvfs handler = cifs
945 cifs:server = $ctx->{netbiosname}
946 cifs:share = tmp
947 cifs:use-s4u2proxy = yes
948 # There is no username specified here, instead the client is expected
949 # to log in with kerberos, and the serverwill use delegated credentials.
950 # Or the server tries s4u2self/s4u2proxy to impersonate the client
952 [simple]
953 path = $ctx->{share}
954 read only = no
955 ntvfs handler = simple
957 [sysvol]
958 path = $ctx->{statedir}/sysvol
959 read only = no
961 [netlogon]
962 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
963 read only = no
965 [cifsposix]
966 copy = simple
967 ntvfs handler = cifsposix
969 [vfs_fruit]
970 path = $ctx->{share}
971 vfs objects = catia fruit streams_xattr acl_xattr
972 ea support = yes
973 fruit:resource = file
974 fruit:metadata = netatalk
975 fruit:locking = netatalk
976 fruit:encoding = native
978 $extra_smbconf_shares
981 if (defined($self->{ldap})) {
982 $ctx->{ldapdir} = "$ctx->{privatedir}/ldap";
983 push(@{$ctx->{directories}}, "$ctx->{ldapdir}");
985 my $ldap_uri= "$ctx->{ldapdir}/ldapi";
986 $ldap_uri =~ s|/|%2F|g;
987 $ldap_uri = "ldapi://$ldap_uri";
988 $ctx->{ldap_uri} = $ldap_uri;
990 $ctx->{ldap_instance} = lc($ctx->{netbiosname});
993 my $ret = $self->provision_raw_step1($ctx);
994 unless (defined $ret) {
995 return undef;
998 if (defined($self->{ldap})) {
999 $ret->{LDAP_URI} = $ctx->{ldap_uri};
1000 push (@{$ctx->{provision_options}}, "--ldap-backend-type=" . $self->{ldap});
1001 push (@{$ctx->{provision_options}}, "--ldap-backend-nosync");
1002 if ($self->{ldap} eq "openldap") {
1003 push (@{$ctx->{provision_options}}, "--slapd-path=" . $ENV{OPENLDAP_SLAPD});
1004 ($ret->{SLAPD_CONF_D}, $ret->{OPENLDAP_PIDFILE}) = $self->mk_openldap($ctx) or die("Unable to create openldap directories");
1006 } elsif ($self->{ldap} eq "fedora-ds") {
1007 push (@{$ctx->{provision_options}}, "--slapd-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/ns-slapd");
1008 push (@{$ctx->{provision_options}}, "--setup-ds-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/setup-ds.pl");
1009 ($ret->{FEDORA_DS_DIR}, $ret->{FEDORA_DS_PIDFILE}) = $self->mk_fedora_ds($ctx) or die("Unable to create fedora ds directories");
1014 return $self->provision_raw_step2($ctx, $ret);
1017 sub provision_s4member($$$$$)
1019 my ($self, $prefix, $dcvars, $hostname, $more_conf) = @_;
1020 print "PROVISIONING MEMBER...\n";
1021 my $extra_smb_conf = "
1022 passdb backend = samba_dsdb
1023 winbindd:use external pipes = true
1025 # the source4 smb server doesn't allow signing by default
1026 server signing = enabled
1028 rpc_server:default = external
1029 rpc_server:svcctl = embedded
1030 rpc_server:srvsvc = embedded
1031 rpc_server:eventlog = embedded
1032 rpc_server:ntsvcs = embedded
1033 rpc_server:winreg = embedded
1034 rpc_server:spoolss = embedded
1035 rpc_daemon:spoolssd = embedded
1036 rpc_server:tcpip = no
1038 if ($more_conf) {
1039 $extra_smb_conf = $extra_smb_conf . $more_conf . "\n";
1041 my $ret = $self->provision($prefix,
1042 "member server",
1043 $hostname,
1044 "SAMBADOMAIN",
1045 "samba.example.com",
1046 "2008",
1047 "locMEMpass3",
1048 $dcvars->{SERVER_IP},
1049 $dcvars->{SERVER_IPV6},
1050 $extra_smb_conf, "", undef);
1051 unless ($ret) {
1052 return undef;
1055 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1056 my $cmd = "";
1057 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1058 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1059 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1060 } else {
1061 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1063 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1064 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1065 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
1066 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1067 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1069 unless (system($cmd) == 0) {
1070 warn("Join failed\n$cmd");
1071 return undef;
1074 $ret->{MEMBER_SERVER} = $ret->{SERVER};
1075 $ret->{MEMBER_SERVER_IP} = $ret->{SERVER_IP};
1076 $ret->{MEMBER_SERVER_IPV6} = $ret->{SERVER_IPV6};
1077 $ret->{MEMBER_NETBIOSNAME} = $ret->{NETBIOSNAME};
1078 $ret->{MEMBER_USERNAME} = $ret->{USERNAME};
1079 $ret->{MEMBER_PASSWORD} = $ret->{PASSWORD};
1081 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1082 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1083 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1084 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1085 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1086 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1088 return $ret;
1091 sub provision_rpc_proxy($$$)
1093 my ($self, $prefix, $dcvars) = @_;
1094 print "PROVISIONING RPC PROXY...\n";
1096 my $extra_smbconf_options = "
1097 passdb backend = samba_dsdb
1099 # rpc_proxy
1100 dcerpc_remote:binding = ncacn_ip_tcp:$dcvars->{SERVER}
1101 dcerpc endpoint servers = epmapper, remote
1102 dcerpc_remote:interfaces = rpcecho
1104 [cifs_to_dc]
1105 path = /tmp/_ignore_cifs_to_dc_/_none_
1106 read only = no
1107 ntvfs handler = cifs
1108 cifs:server = $dcvars->{SERVER}
1109 cifs:share = cifs
1110 cifs:use-s4u2proxy = yes
1111 # There is no username specified here, instead the client is expected
1112 # to log in with kerberos, and the serverwill use delegated credentials.
1113 # Or the server tries s4u2self/s4u2proxy to impersonate the client
1117 my $ret = $self->provision($prefix,
1118 "member server",
1119 "localrpcproxy",
1120 "SAMBADOMAIN",
1121 "samba.example.com",
1122 "2008",
1123 "locRPCproxypass4",
1124 $dcvars->{SERVER_IP},
1125 $dcvars->{SERVER_IPV6},
1126 $extra_smbconf_options, "", undef);
1127 unless ($ret) {
1128 return undef;
1131 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1133 # The joind runs in the context of the rpc_proxy/member for now
1134 my $cmd = "";
1135 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1136 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1137 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1138 } else {
1139 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1141 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1142 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1143 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
1144 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1145 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1147 unless (system($cmd) == 0) {
1148 warn("Join failed\n$cmd");
1149 return undef;
1152 # Setting up delegation runs in the context of the DC for now
1153 $cmd = "";
1154 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1155 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
1156 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1157 $cmd .= "$samba_tool delegation for-any-protocol '$ret->{NETBIOSNAME}\$' on";
1158 $cmd .= " $dcvars->{CONFIGURATION}";
1159 print $cmd;
1161 unless (system($cmd) == 0) {
1162 warn("Delegation failed\n$cmd");
1163 return undef;
1166 # Setting up delegation runs in the context of the DC for now
1167 $cmd = "";
1168 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1169 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
1170 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1171 $cmd .= "$samba_tool delegation add-service '$ret->{NETBIOSNAME}\$' cifs/$dcvars->{SERVER}";
1172 $cmd .= " $dcvars->{CONFIGURATION}";
1174 unless (system($cmd) == 0) {
1175 warn("Delegation failed\n$cmd");
1176 return undef;
1179 $ret->{RPC_PROXY_SERVER} = $ret->{SERVER};
1180 $ret->{RPC_PROXY_SERVER_IP} = $ret->{SERVER_IP};
1181 $ret->{RPC_PROXY_SERVER_IPV6} = $ret->{SERVER_IPV6};
1182 $ret->{RPC_PROXY_NETBIOSNAME} = $ret->{NETBIOSNAME};
1183 $ret->{RPC_PROXY_USERNAME} = $ret->{USERNAME};
1184 $ret->{RPC_PROXY_PASSWORD} = $ret->{PASSWORD};
1186 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1187 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1188 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1189 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1190 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1191 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1193 return $ret;
1196 sub provision_promoted_dc($$$)
1198 my ($self, $prefix, $dcvars) = @_;
1199 print "PROVISIONING PROMOTED DC...\n";
1201 # We do this so that we don't run the provision. That's the job of 'samba-tool domain dcpromo'.
1202 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1203 "promotedvdc",
1204 "SAMBADOMAIN",
1205 "samba.example.com",
1206 "2008",
1207 $dcvars->{PASSWORD},
1208 $dcvars->{SERVER_IP},
1209 $dcvars->{SERVER_IPV6});
1211 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1213 $ctx->{smb_conf_extra_options} = "
1214 max xmit = 32K
1215 server max protocol = SMB2
1217 ntlm auth = ntlmv2-only
1219 [sysvol]
1220 path = $ctx->{statedir}/sysvol
1221 read only = yes
1223 [netlogon]
1224 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1225 read only = no
1229 my $ret = $self->provision_raw_step1($ctx);
1230 unless ($ret) {
1231 return undef;
1234 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1235 my $cmd = "";
1236 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1237 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1238 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1239 } else {
1240 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1242 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1243 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1244 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} MEMBER --realm=$dcvars->{REALM}";
1245 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1246 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1248 unless (system($cmd) == 0) {
1249 warn("Join failed\n$cmd");
1250 return undef;
1253 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1254 my $cmd = "";
1255 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1256 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1257 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1258 $cmd .= "$samba_tool domain dcpromo $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1259 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1260 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs --dns-backend=BIND9_DLZ";
1262 unless (system($cmd) == 0) {
1263 warn("Join failed\n$cmd");
1264 return undef;
1267 $ret->{PROMOTED_DC_SERVER} = $ret->{SERVER};
1268 $ret->{PROMOTED_DC_SERVER_IP} = $ret->{SERVER_IP};
1269 $ret->{PROMOTED_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1270 $ret->{PROMOTED_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1272 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1273 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1274 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1275 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1276 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1277 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1279 return $ret;
1282 sub provision_vampire_dc($$$)
1284 my ($self, $prefix, $dcvars, $fl) = @_;
1285 print "PROVISIONING VAMPIRE DC @ FL $fl...\n";
1286 my $name = "localvampiredc";
1288 if ($fl == "2000") {
1289 $name = "vampire2000dc";
1292 # We do this so that we don't run the provision. That's the job of 'net vampire'.
1293 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1294 $name,
1295 $dcvars->{DOMAIN},
1296 $dcvars->{REALM},
1297 $fl,
1298 $dcvars->{PASSWORD},
1299 $dcvars->{SERVER_IP},
1300 $dcvars->{SERVER_IPV6});
1302 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1304 $ctx->{smb_conf_extra_options} = "
1305 max xmit = 32K
1306 server max protocol = SMB2
1308 ntlm auth = mschapv2-and-ntlmv2-only
1310 [sysvol]
1311 path = $ctx->{statedir}/sysvol
1312 read only = yes
1314 [netlogon]
1315 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1316 read only = no
1320 my $ret = $self->provision_raw_step1($ctx);
1321 unless ($ret) {
1322 return undef;
1325 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1326 my $cmd = "";
1327 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1328 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1329 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1330 } else {
1331 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1333 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1334 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1335 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1336 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} --domain-critical-only";
1337 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs";
1339 unless (system($cmd) == 0) {
1340 warn("Join failed\n$cmd");
1341 return undef;
1344 if ($fl == "2000") {
1345 $ret->{VAMPIRE_2000_DC_SERVER} = $ret->{SERVER};
1346 $ret->{VAMPIRE_2000_DC_SERVER_IP} = $ret->{SERVER_IP};
1347 $ret->{VAMPIRE_2000_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1348 $ret->{VAMPIRE_2000_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1349 } else {
1350 $ret->{VAMPIRE_DC_SERVER} = $ret->{SERVER};
1351 $ret->{VAMPIRE_DC_SERVER_IP} = $ret->{SERVER_IP};
1352 $ret->{VAMPIRE_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1353 $ret->{VAMPIRE_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1355 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1356 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1357 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1358 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1359 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1360 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1361 $ret->{DC_REALM} = $dcvars->{DC_REALM};
1363 return $ret;
1366 sub provision_subdom_dc($$$)
1368 my ($self, $prefix, $dcvars) = @_;
1369 print "PROVISIONING SUBDOMAIN DC...\n";
1371 # We do this so that we don't run the provision. That's the job of 'net vampire'.
1372 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1373 "localsubdc",
1374 "SAMBASUBDOM",
1375 "sub.samba.example.com",
1376 "2008",
1377 $dcvars->{PASSWORD},
1378 undef);
1380 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1382 $ctx->{smb_conf_extra_options} = "
1383 max xmit = 32K
1384 server max protocol = SMB2
1386 [sysvol]
1387 path = $ctx->{statedir}/sysvol
1388 read only = yes
1390 [netlogon]
1391 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1392 read only = no
1396 my $ret = $self->provision_raw_step1($ctx);
1397 unless ($ret) {
1398 return undef;
1401 Samba::mk_krb5_conf($ctx);
1402 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
1404 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1405 my $cmd = "";
1406 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1407 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1408 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1409 } else {
1410 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1412 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1413 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1414 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $ctx->{dnsname} subdomain ";
1415 $cmd .= "--parent-domain=$dcvars->{REALM} -U$dcvars->{DC_USERNAME}\@$dcvars->{REALM}\%$dcvars->{DC_PASSWORD}";
1416 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs";
1417 $cmd .= " --adminpass=$ret->{PASSWORD}";
1419 unless (system($cmd) == 0) {
1420 warn("Join failed\n$cmd");
1421 return undef;
1424 $ret->{SUBDOM_DC_SERVER} = $ret->{SERVER};
1425 $ret->{SUBDOM_DC_SERVER_IP} = $ret->{SERVER_IP};
1426 $ret->{SUBDOM_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1427 $ret->{SUBDOM_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1429 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1430 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1431 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1432 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1433 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1434 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1436 return $ret;
1439 sub provision_ad_dc_ntvfs($$)
1441 my ($self, $prefix) = @_;
1443 # We keep the old 'winbind' name here in server services to
1444 # ensure upgrades which used that name still work with the now
1445 # alias.
1447 print "PROVISIONING AD DC (NTVFS)...\n";
1448 my $extra_conf_options = "netbios aliases = localDC1-a
1449 server services = +winbind -winbindd
1450 ldap server require strong auth = allow_sasl_over_tls
1451 allow nt4 crypto = yes
1452 lsa over netlogon = yes
1453 rpc server port = 1027
1454 auth event notification = true
1456 my $ret = $self->provision($prefix,
1457 "domain controller",
1458 "localdc",
1459 "SAMBADOMAIN",
1460 "samba.example.com",
1461 "2008",
1462 "locDCpass1",
1463 undef,
1464 undef,
1465 $extra_conf_options,
1467 undef);
1468 unless ($ret) {
1469 return undef;
1472 unless($self->add_wins_config("$prefix/private")) {
1473 warn("Unable to add wins configuration");
1474 return undef;
1476 $ret->{NETBIOSALIAS} = "localdc1-a";
1477 $ret->{DC_SERVER} = $ret->{SERVER};
1478 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1479 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1480 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1481 $ret->{DC_USERNAME} = $ret->{USERNAME};
1482 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1483 $ret->{DC_REALM} = $ret->{REALM};
1485 return $ret;
1488 sub provision_fl2000dc($$)
1490 my ($self, $prefix) = @_;
1492 print "PROVISIONING DC WITH FOREST LEVEL 2000...\n";
1493 my $extra_conf_options = "
1494 spnego:simulate_w2k=yes
1495 ntlmssp_server:force_old_spnego=yes
1497 my $ret = $self->provision($prefix,
1498 "domain controller",
1499 "dc5",
1500 "SAMBA2000",
1501 "samba2000.example.com",
1502 "2000",
1503 "locDCpass5",
1504 undef,
1505 undef,
1506 $extra_conf_options,
1508 undef);
1509 unless ($ret) {
1510 return undef;
1513 unless($self->add_wins_config("$prefix/private")) {
1514 warn("Unable to add wins configuration");
1515 return undef;
1517 $ret->{DC_SERVER} = $ret->{SERVER};
1518 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1519 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1520 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1521 $ret->{DC_USERNAME} = $ret->{USERNAME};
1522 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1523 $ret->{DC_REALM} = $ret->{REALM};
1525 return $ret;
1528 sub provision_fl2003dc($$$)
1530 my ($self, $prefix, $dcvars) = @_;
1531 my $swiface1 = Samba::get_interface("fakednsforwarder1");
1532 my $swiface2 = Samba::get_interface("fakednsforwarder2");
1534 print "PROVISIONING DC WITH FOREST LEVEL 2003...\n";
1535 my $extra_conf_options = "allow dns updates = nonsecure and secure
1536 dcesrv:header signing = no
1537 dns forwarder = 127.0.0.$swiface1 127.0.0.$swiface2";
1538 my $ret = $self->provision($prefix,
1539 "domain controller",
1540 "dc6",
1541 "SAMBA2003",
1542 "samba2003.example.com",
1543 "2003",
1544 "locDCpass6",
1545 undef,
1546 undef,
1547 $extra_conf_options,
1549 undef);
1550 unless (defined $ret) {
1551 return undef;
1554 $ret->{DC_SERVER} = $ret->{SERVER};
1555 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1556 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1557 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1558 $ret->{DC_USERNAME} = $ret->{USERNAME};
1559 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1560 $ret->{DNS_FORWARDER1} = "127.0.0.$swiface1";
1561 $ret->{DNS_FORWARDER2} = "127.0.0.$swiface2";
1563 my @samba_tool_options;
1564 push (@samba_tool_options, Samba::bindir_path($self, "samba-tool"));
1565 push (@samba_tool_options, "domain");
1566 push (@samba_tool_options, "passwordsettings");
1567 push (@samba_tool_options, "set");
1568 push (@samba_tool_options, "--configfile=$ret->{SERVERCONFFILE}");
1569 push (@samba_tool_options, "--min-pwd-age=0");
1570 push (@samba_tool_options, "--history-length=1");
1572 my $samba_tool_cmd = join(" ", @samba_tool_options);
1574 unless (system($samba_tool_cmd) == 0) {
1575 warn("Unable to set min password age to 0: \n$samba_tool_cmd\n");
1576 return undef;
1579 unless($self->add_wins_config("$prefix/private")) {
1580 warn("Unable to add wins configuration");
1581 return undef;
1584 return $ret;
1587 sub provision_fl2008r2dc($$$)
1589 my ($self, $prefix, $dcvars) = @_;
1591 print "PROVISIONING DC WITH FOREST LEVEL 2008r2...\n";
1592 my $extra_conf_options = "ldap server require strong auth = no";
1593 my $ret = $self->provision($prefix,
1594 "domain controller",
1595 "dc7",
1596 "SAMBA2008R2",
1597 "samba2008R2.example.com",
1598 "2008_R2",
1599 "locDCpass7",
1600 undef,
1601 undef,
1602 $extra_conf_options,
1604 undef);
1605 unless (defined $ret) {
1606 return undef;
1609 unless ($self->add_wins_config("$prefix/private")) {
1610 warn("Unable to add wins configuration");
1611 return undef;
1613 $ret->{DC_SERVER} = $ret->{SERVER};
1614 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1615 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1616 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1617 $ret->{DC_USERNAME} = $ret->{USERNAME};
1618 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1619 $ret->{DC_REALM} = $ret->{REALM};
1621 return $ret;
1625 sub provision_rodc($$$)
1627 my ($self, $prefix, $dcvars) = @_;
1628 print "PROVISIONING RODC...\n";
1630 # We do this so that we don't run the provision. That's the job of 'net join RODC'.
1631 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1632 "rodc",
1633 "SAMBADOMAIN",
1634 "samba.example.com",
1635 "2008",
1636 $dcvars->{PASSWORD},
1637 $dcvars->{SERVER_IP},
1638 $dcvars->{SERVER_IPV6});
1639 unless ($ctx) {
1640 return undef;
1643 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1645 $ctx->{share} = "$ctx->{prefix_abs}/share";
1646 push(@{$ctx->{directories}}, "$ctx->{share}");
1648 $ctx->{smb_conf_extra_options} = "
1649 max xmit = 32K
1650 server max protocol = SMB2
1651 password server = $dcvars->{DC_SERVER}
1653 [sysvol]
1654 path = $ctx->{statedir}/sysvol
1655 read only = yes
1657 [netlogon]
1658 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1659 read only = yes
1661 [tmp]
1662 path = $ctx->{share}
1663 read only = no
1664 posix:sharedelay = 10000
1665 posix:oplocktimeout = 3
1666 posix:writetimeupdatedelay = 50000
1670 my $ret = $self->provision_raw_step1($ctx);
1671 unless ($ret) {
1672 return undef;
1675 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1676 my $cmd = "";
1677 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1678 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1679 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1680 } else {
1681 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1683 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1684 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1685 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} RODC";
1686 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1687 $cmd .= " --server=$dcvars->{DC_SERVER} --use-ntvfs";
1689 unless (system($cmd) == 0) {
1690 warn("RODC join failed\n$cmd");
1691 return undef;
1694 # This ensures deterministic behaviour for tests that want to have the 'testallowed account'
1695 # user password verified on the RODC
1696 my $testallowed_account = "testallowed account";
1697 $cmd = "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1698 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1699 $cmd .= "$samba_tool rodc preload '$testallowed_account' $ret->{CONFIGURATION}";
1700 $cmd .= " --server=$dcvars->{DC_SERVER}";
1702 unless (system($cmd) == 0) {
1703 warn("RODC join failed\n$cmd");
1704 return undef;
1707 # we overwrite the kdc after the RODC join
1708 # so that use the RODC as kdc and test
1709 # the proxy code
1710 $ctx->{kdc_ipv4} = $ret->{SERVER_IP};
1711 $ctx->{kdc_ipv6} = $ret->{SERVER_IPV6};
1712 Samba::mk_krb5_conf($ctx);
1713 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
1715 $ret->{RODC_DC_SERVER} = $ret->{SERVER};
1716 $ret->{RODC_DC_SERVER_IP} = $ret->{SERVER_IP};
1717 $ret->{RODC_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1718 $ret->{RODC_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1720 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1721 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1722 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1723 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1724 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1725 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1727 return $ret;
1730 sub read_config_h($)
1732 my ($name) = @_;
1733 my %ret = {};
1734 open(LF, "<$name") or die("unable to read $name: $!");
1735 while (<LF>) {
1736 chomp;
1737 next if not (/^#define /);
1738 if (/^#define (.*?)[ \t]+(.*?)$/) {
1739 $ret{$1} = $2;
1740 next;
1742 if (/^#define (.*?)[ \t]+$/) {
1743 $ret{$1} = 1;;
1744 next;
1747 close(LF);
1748 return \%ret;
1751 sub provision_ad_dc($$)
1753 my ($self, $prefix) = @_;
1755 my $prefix_abs = abs_path($prefix);
1757 my $bindir_abs = abs_path($self->{bindir});
1758 my $lockdir="$prefix_abs/lockdir";
1759 my $conffile="$prefix_abs/etc/smb.conf";
1761 my $require_mutexes = "dbwrap_tdb_require_mutexes:* = yes";
1762 $require_mutexes = "" if ($ENV{SELFTEST_DONT_REQUIRE_TDB_MUTEX_SUPPORT} eq "1");
1764 my $config_h = {};
1766 if (defined($ENV{CONFIG_H})) {
1767 $config_h = read_config_h($ENV{CONFIG_H});
1770 my $password_hash_gpg_key_ids = "password hash gpg key ids = 4952E40301FAB41A";
1771 $password_hash_gpg_key_ids = "" unless defined($config_h->{HAVE_GPGME});
1773 my $extra_smbconf_options = "
1774 server services = -smb +s3fs
1775 xattr_tdb:file = $prefix_abs/statedir/xattr.tdb
1777 dbwrap_tdb_mutexes:* = yes
1778 ${require_mutexes}
1780 ${password_hash_gpg_key_ids}
1782 kernel oplocks = no
1783 kernel change notify = no
1784 smb2 leases = no
1786 logging = file
1787 printing = bsd
1788 printcap name = /dev/null
1790 max protocol = SMB3
1791 read only = no
1793 smbd:sharedelay = 100000
1794 smbd:writetimeupdatedelay = 500000
1795 create mask = 755
1796 dos filemode = yes
1798 dcerpc endpoint servers = -winreg -srvsvc
1800 printcap name = /dev/null
1802 addprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -a -s $conffile --
1803 deleteprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -d -s $conffile --
1805 printing = vlp
1806 print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
1807 lpq command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpq %p
1808 lp rm command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lprm %p %j
1809 lp pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lppause %p %j
1810 lp resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpresume %p %j
1811 queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
1812 queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
1813 lpq cache time = 0
1814 print notify backchannel = yes
1816 auth event notification = true
1819 my $extra_smbconf_shares = "
1821 [tmpenc]
1822 copy = tmp
1823 smb encrypt = required
1825 [tmpcase]
1826 copy = tmp
1827 case sensitive = yes
1829 [tmpguest]
1830 copy = tmp
1831 guest ok = yes
1833 [hideunread]
1834 copy = tmp
1835 hide unreadable = yes
1837 [durable]
1838 copy = tmp
1839 kernel share modes = no
1840 kernel oplocks = no
1841 posix locking = no
1843 [print\$]
1844 copy = tmp
1846 [print1]
1847 copy = tmp
1848 printable = yes
1850 [print2]
1851 copy = print1
1852 [print3]
1853 copy = print1
1854 [lp]
1855 copy = print1
1858 print "PROVISIONING AD DC...\n";
1859 my $ret = $self->provision($prefix,
1860 "domain controller",
1861 "addc",
1862 "ADDOMAIN",
1863 "addom.samba.example.com",
1864 "2008",
1865 "locDCpass1",
1866 undef,
1867 undef,
1868 $extra_smbconf_options,
1869 $extra_smbconf_shares,
1870 undef);
1871 unless (defined $ret) {
1872 return undef;
1875 unless($self->add_wins_config("$prefix/private")) {
1876 warn("Unable to add wins configuration");
1877 return undef;
1880 $ret->{DC_SERVER} = $ret->{SERVER};
1881 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1882 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1883 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1884 $ret->{DC_USERNAME} = $ret->{USERNAME};
1885 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1887 return $ret;
1890 sub provision_chgdcpass($$)
1892 my ($self, $prefix) = @_;
1894 print "PROVISIONING CHGDCPASS...\n";
1895 my $extra_provision_options = undef;
1896 # This environment disallows the use of this password
1897 # (and also removes the default AD complexity checks)
1898 my $unacceptable_password = "widk3Dsle32jxdBdskldsk55klASKQ";
1899 push (@{$extra_provision_options}, "--dns-backend=BIND9_DLZ");
1900 my $ret = $self->provision($prefix,
1901 "domain controller",
1902 "chgdcpass",
1903 "CHDCDOMAIN",
1904 "chgdcpassword.samba.example.com",
1905 "2008",
1906 "chgDCpass1",
1907 undef,
1908 undef,
1909 "check password script = sed -e '/$unacceptable_password/{;q1}; /$unacceptable_password/!{q0}'\n",
1911 $extra_provision_options);
1912 unless (defined $ret) {
1913 return undef;
1916 unless($self->add_wins_config("$prefix/private")) {
1917 warn("Unable to add wins configuration");
1918 return undef;
1921 # Remove secrets.tdb from this environment to test that we
1922 # still start up on systems without the new matching
1923 # secrets.tdb records.
1924 unless (unlink("$ret->{PRIVATEDIR}/secrets.tdb") || unlink("$ret->{PRIVATEDIR}/secrets.ntdb")) {
1925 warn("Unable to remove $ret->{PRIVATEDIR}/secrets.tdb added during provision");
1926 return undef;
1929 $ret->{DC_SERVER} = $ret->{SERVER};
1930 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1931 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1932 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1933 $ret->{DC_USERNAME} = $ret->{USERNAME};
1934 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1935 $ret->{UNACCEPTABLE_PASSWORD} = $unacceptable_password;
1937 return $ret;
1940 sub teardown_env_terminate($$)
1942 my ($self, $envvars) = @_;
1943 my $pid;
1945 # This should cause samba to terminate gracefully
1946 close($envvars->{STDIN_PIPE});
1948 $pid = $envvars->{SAMBA_PID};
1949 my $count = 0;
1950 my $childpid;
1952 # This should give it time to write out the gcov data
1953 until ($count > 15) {
1954 if (Samba::cleanup_child($pid, "samba") != 0) {
1955 return;
1957 sleep(1);
1958 $count++;
1961 # After 15 Seconds, work out why this thing is still alive
1962 warn "server process $pid took more than $count seconds to exit, showing backtrace:\n";
1963 system("$self->{srcdir}/selftest/gdb_backtrace $pid");
1965 until ($count > 30) {
1966 if (Samba::cleanup_child($pid, "samba") != 0) {
1967 return;
1969 sleep(1);
1970 $count++;
1973 if (kill(0, $pid)) {
1974 warn "server process $pid took more than $count seconds to exit, sending SIGTERM\n";
1975 kill "TERM", $pid;
1978 until ($count > 40) {
1979 if (Samba::cleanup_child($pid, "samba") != 0) {
1980 return;
1982 sleep(1);
1983 $count++;
1985 # If it is still around, kill it
1986 if (kill(0, $pid)) {
1987 warn "server process $pid took more than $count seconds to exit, killing\n with SIGKILL\n";
1988 kill 9, $pid;
1990 return;
1993 sub teardown_env($$)
1995 my ($self, $envvars) = @_;
1996 teardown_env_terminate($self, $envvars);
1998 $self->slapd_stop($envvars) if ($self->{ldap});
2000 print $self->getlog_env($envvars);
2002 return;
2005 sub getlog_env($$)
2007 my ($self, $envvars) = @_;
2008 my $title = "SAMBA LOG of: $envvars->{NETBIOSNAME} pid $envvars->{SAMBA_PID}\n";
2009 my $out = $title;
2011 open(LOG, "<$envvars->{SAMBA_TEST_LOG}");
2013 seek(LOG, $envvars->{SAMBA_TEST_LOG_POS}, SEEK_SET);
2014 while (<LOG>) {
2015 $out .= $_;
2017 $envvars->{SAMBA_TEST_LOG_POS} = tell(LOG);
2018 close(LOG);
2020 return "" if $out eq $title;
2022 return $out;
2025 sub check_env($$)
2027 my ($self, $envvars) = @_;
2028 my $samba_pid = $envvars->{SAMBA_PID};
2030 if (not defined($samba_pid)) {
2031 return 0;
2032 } elsif ($samba_pid > 0) {
2033 my $childpid = Samba::cleanup_child($samba_pid, "samba");
2035 if ($childpid == 0) {
2036 return 1;
2038 return 0;
2039 } else {
2040 return 1;
2045 sub setup_env($$$)
2047 my ($self, $envname, $path) = @_;
2048 my $target3 = $self->{target3};
2050 $ENV{ENVNAME} = $envname;
2052 if (defined($self->{vars}->{$envname})) {
2053 return $self->{vars}->{$envname};
2056 if ($envname eq "ad_dc_ntvfs") {
2057 return $self->setup_ad_dc_ntvfs("$path/ad_dc_ntvfs");
2058 } elsif ($envname eq "fl2000dc") {
2059 return $self->setup_fl2000dc("$path/fl2000dc");
2060 } elsif ($envname eq "vampire_2000_dc") {
2061 if (not defined($self->{vars}->{fl2000dc})) {
2062 $self->setup_fl2000dc("$path/fl2000dc");
2064 return $self->setup_vampire_dc("$path/vampire_2000_dc", $self->{vars}->{fl2000dc}, "2000");
2065 } elsif ($envname eq "fl2003dc") {
2066 if (not defined($self->{vars}->{ad_dc})) {
2067 $self->setup_ad_dc("$path/ad_dc");
2069 return $self->setup_fl2003dc("$path/fl2003dc", $self->{vars}->{ad_dc});
2070 } elsif ($envname eq "fl2008r2dc") {
2071 if (not defined($self->{vars}->{ad_dc})) {
2072 $self->setup_ad_dc("$path/ad_dc");
2074 return $self->setup_fl2008r2dc("$path/fl2008r2dc", $self->{vars}->{ad_dc});
2075 } elsif ($envname eq "rpc_proxy") {
2076 if (not defined($self->{vars}->{ad_dc_ntvfs})) {
2077 $self->setup_ad_dc_ntvfs("$path/ad_dc_ntvfs");
2079 return $self->setup_rpc_proxy("$path/rpc_proxy", $self->{vars}->{ad_dc_ntvfs});
2080 } elsif ($envname eq "vampire_dc") {
2081 if (not defined($self->{vars}->{ad_dc_ntvfs})) {
2082 $self->setup_ad_dc_ntvfs("$path/ad_dc_ntvfs");
2084 return $self->setup_vampire_dc("$path/vampire_dc", $self->{vars}->{ad_dc_ntvfs}, "2008");
2085 } elsif ($envname eq "promoted_dc") {
2086 if (not defined($self->{vars}->{ad_dc_ntvfs})) {
2087 $self->setup_ad_dc_ntvfs("$path/ad_dc_ntvfs");
2089 return $self->setup_promoted_dc("$path/promoted_dc", $self->{vars}->{ad_dc_ntvfs});
2090 } elsif ($envname eq "subdom_dc") {
2091 if (not defined($self->{vars}->{ad_dc_ntvfs})) {
2092 $self->setup_ad_dc_ntvfs("$path/ad_dc_ntvfs");
2094 return $self->setup_subdom_dc("$path/subdom_dc", $self->{vars}->{ad_dc_ntvfs});
2095 } elsif ($envname eq "s4member_dflt_domain") {
2096 if (not defined($self->{vars}->{ad_dc_ntvfs})) {
2097 $self->setup_ad_dc_ntvfs("$path/ad_dc_ntvfs");
2099 return $self->setup_s4member_dflt_domain("$path/s4member_dflt_domain", $self->{vars}->{ad_dc_ntvfs});
2100 } elsif ($envname eq "s4member") {
2101 if (not defined($self->{vars}->{ad_dc_ntvfs})) {
2102 $self->setup_ad_dc_ntvfs("$path/ad_dc_ntvfs");
2104 return $self->setup_s4member("$path/s4member", $self->{vars}->{ad_dc_ntvfs});
2105 } elsif ($envname eq "rodc") {
2106 if (not defined($self->{vars}->{ad_dc_ntvfs})) {
2107 $self->setup_ad_dc_ntvfs("$path/ad_dc_ntvfs");
2109 return $self->setup_rodc("$path/rodc", $self->{vars}->{ad_dc_ntvfs});
2110 } elsif ($envname eq "chgdcpass") {
2111 return $self->setup_chgdcpass("$path/chgdcpass", $self->{vars}->{chgdcpass});
2112 } elsif ($envname eq "ad_member") {
2113 if (not defined($self->{vars}->{ad_dc_ntvfs})) {
2114 $self->setup_ad_dc_ntvfs("$path/ad_dc_ntvfs");
2116 return $target3->setup_admember("$path/ad_member", $self->{vars}->{ad_dc_ntvfs}, 29);
2117 } elsif ($envname eq "ad_dc") {
2118 return $self->setup_ad_dc("$path/ad_dc");
2119 } elsif ($envname eq "ad_dc_no_nss") {
2120 return $self->setup_ad_dc("$path/ad_dc_no_nss", "no_nss");
2121 } elsif ($envname eq "ad_member_rfc2307") {
2122 if (not defined($self->{vars}->{ad_dc_ntvfs})) {
2123 $self->setup_ad_dc_ntvfs("$path/ad_dc_ntvfs");
2125 return $target3->setup_admember_rfc2307("$path/ad_member_rfc2307",
2126 $self->{vars}->{ad_dc_ntvfs}, 34);
2127 } elsif ($envname eq "ad_member_idmap_rid") {
2128 if (not defined($self->{vars}->{ad_dc})) {
2129 $self->setup_ad_dc("$path/ad_dc");
2131 return $target3->setup_ad_member_idmap_rid("$path/ad_member_idmap_rid",
2132 $self->{vars}->{ad_dc});
2133 } elsif ($envname eq "ad_member_idmap_ad") {
2134 if (not defined($self->{vars}->{ad_dc})) {
2135 $self->setup_ad_dc("$path/ad_dc");
2137 return $target3->setup_ad_member_idmap_ad("$path/ad_member_idmap_ad",
2138 $self->{vars}->{ad_dc});
2139 } elsif ($envname eq "none") {
2140 return $self->setup_none("$path/none");
2141 } else {
2142 return "UNKNOWN";
2146 sub setup_s4member($$$)
2148 my ($self, $path, $dc_vars) = @_;
2150 my $env = $self->provision_s4member($path, $dc_vars, "s4member");
2152 if (defined $env) {
2153 if (not defined($self->check_or_start($env, "standard"))) {
2154 return undef;
2157 $self->{vars}->{s4member} = $env;
2160 return $env;
2163 sub setup_s4member_dflt_domain($$$)
2165 my ($self, $path, $dc_vars) = @_;
2167 my $env = $self->provision_s4member($path, $dc_vars, "s4member_dflt",
2168 "winbind use default domain = yes");
2170 if (defined $env) {
2171 if (not defined($self->check_or_start($env, "standard"))) {
2172 return undef;
2175 $self->{vars}->{s4member_dflt_domain} = $env;
2178 return $env;
2181 sub setup_rpc_proxy($$$)
2183 my ($self, $path, $dc_vars) = @_;
2185 my $env = $self->provision_rpc_proxy($path, $dc_vars);
2187 if (defined $env) {
2188 if (not defined($self->check_or_start($env, "standard"))) {
2189 return undef;
2192 $self->{vars}->{rpc_proxy} = $env;
2194 return $env;
2197 sub setup_ad_dc_ntvfs($$)
2199 my ($self, $path) = @_;
2201 my $env = $self->provision_ad_dc_ntvfs($path);
2202 if (defined $env) {
2203 if (not defined($self->check_or_start($env, "standard"))) {
2204 warn("Failed to start ad_dc_ntvfs");
2205 return undef;
2208 $self->{vars}->{ad_dc_ntvfs} = $env;
2210 return $env;
2213 sub setup_chgdcpass($$)
2215 my ($self, $path) = @_;
2217 my $env = $self->provision_chgdcpass($path);
2218 if (defined $env) {
2219 if (not defined($self->check_or_start($env, "standard"))) {
2220 return undef;
2223 $self->{vars}->{chgdcpass} = $env;
2225 return $env;
2228 sub setup_fl2000dc($$)
2230 my ($self, $path) = @_;
2232 my $env = $self->provision_fl2000dc($path);
2233 if (defined $env) {
2234 if (not defined($self->check_or_start($env, "standard"))) {
2235 return undef;
2238 $self->{vars}->{fl2000dc} = $env;
2241 return $env;
2244 sub setup_fl2003dc($$$)
2246 my ($self, $path, $dc_vars) = @_;
2248 my $env = $self->provision_fl2003dc($path);
2250 if (defined $env) {
2251 if (not defined($self->check_or_start($env, "standard"))) {
2252 return undef;
2255 $env = $self->setup_trust($env, $dc_vars, "external", "--no-aes-keys");
2257 $self->{vars}->{fl2003dc} = $env;
2259 return $env;
2262 sub setup_fl2008r2dc($$$)
2264 my ($self, $path, $dc_vars) = @_;
2266 my $env = $self->provision_fl2008r2dc($path);
2268 if (defined $env) {
2269 if (not defined($self->check_or_start($env, "standard"))) {
2270 return undef;
2273 my $upn_array = ["$env->{REALM}.upn"];
2274 my $spn_array = ["$env->{REALM}.spn"];
2276 $self->setup_namespaces($env, $upn_array, $spn_array);
2278 $env = $self->setup_trust($env, $dc_vars, "forest", "");
2280 $self->{vars}->{fl2008r2dc} = $env;
2283 return $env;
2286 sub setup_vampire_dc($$$$)
2288 my ($self, $path, $dc_vars, $fl) = @_;
2290 my $env = $self->provision_vampire_dc($path, $dc_vars, $fl);
2292 if (defined $env) {
2293 if (not defined($self->check_or_start($env, "single"))) {
2294 return undef;
2297 $self->{vars}->{vampire_dc} = $env;
2299 # force replicated DC to update repsTo/repsFrom
2300 # for vampired partitions
2301 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2303 # as 'vampired' dc may add data in its local replica
2304 # we need to synchronize data between DCs
2305 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2306 my $cmd = "";
2307 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2308 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2309 $cmd .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2310 } else {
2311 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2313 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2314 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2315 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2316 $cmd .= " $dc_vars->{CONFIGURATION}";
2317 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2318 # replicate Configuration NC
2319 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2320 unless(system($cmd_repl) == 0) {
2321 warn("Failed to replicate\n$cmd_repl");
2322 return undef;
2324 # replicate Default NC
2325 $cmd_repl = "$cmd \"$base_dn\"";
2326 unless(system($cmd_repl) == 0) {
2327 warn("Failed to replicate\n$cmd_repl");
2328 return undef;
2331 # Pull in a full set of changes from the main DC
2332 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2333 $cmd = "";
2334 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2335 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2336 $cmd .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2337 } else {
2338 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2340 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2341 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2342 $cmd .= " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}";
2343 $cmd .= " $dc_vars->{CONFIGURATION}";
2344 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2345 # replicate Configuration NC
2346 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2347 unless(system($cmd_repl) == 0) {
2348 warn("Failed to replicate\n$cmd_repl");
2349 return undef;
2351 # replicate Default NC
2352 $cmd_repl = "$cmd \"$base_dn\"";
2353 unless(system($cmd_repl) == 0) {
2354 warn("Failed to replicate\n$cmd_repl");
2355 return undef;
2359 return $env;
2362 sub setup_promoted_dc($$$)
2364 my ($self, $path, $dc_vars) = @_;
2366 my $env = $self->provision_promoted_dc($path, $dc_vars);
2368 if (defined $env) {
2369 if (not defined($self->check_or_start($env, "single"))) {
2370 return undef;
2373 $self->{vars}->{promoted_dc} = $env;
2375 # force source and replicated DC to update repsTo/repsFrom
2376 # for vampired partitions
2377 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2378 my $cmd = "";
2379 # as 'vampired' dc may add data in its local replica
2380 # we need to synchronize data between DCs
2381 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2382 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2383 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2384 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2385 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2386 $cmd .= " $dc_vars->{CONFIGURATION}";
2387 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2388 # replicate Configuration NC
2389 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2390 unless(system($cmd_repl) == 0) {
2391 warn("Failed to replicate\n$cmd_repl");
2392 return undef;
2394 # replicate Default NC
2395 $cmd_repl = "$cmd \"$base_dn\"";
2396 unless(system($cmd_repl) == 0) {
2397 warn("Failed to replicate\n$cmd_repl");
2398 return undef;
2402 return $env;
2405 sub setup_subdom_dc($$$)
2407 my ($self, $path, $dc_vars) = @_;
2409 my $env = $self->provision_subdom_dc($path, $dc_vars);
2411 if (defined $env) {
2412 if (not defined($self->check_or_start($env, "single"))) {
2413 return undef;
2416 $self->{vars}->{subdom_dc} = $env;
2418 # force replicated DC to update repsTo/repsFrom
2419 # for primary domain partitions
2420 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2421 my $cmd = "";
2422 # as 'subdomain' dc may add data in its local replica
2423 # we need to synchronize data between DCs
2424 my $base_dn = "DC=".join(",DC=", split(/\./, $env->{REALM}));
2425 my $config_dn = "CN=Configuration,DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2426 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2427 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2428 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2429 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SUBDOM_DC_SERVER}";
2430 $cmd .= " $dc_vars->{CONFIGURATION}";
2431 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD} --realm=$dc_vars->{DC_REALM}";
2432 # replicate Configuration NC
2433 my $cmd_repl = "$cmd \"$config_dn\"";
2434 unless(system($cmd_repl) == 0) {
2435 warn("Failed to replicate\n$cmd_repl");
2436 return undef;
2438 # replicate Default NC
2439 $cmd_repl = "$cmd \"$base_dn\"";
2440 unless(system($cmd_repl) == 0) {
2441 warn("Failed to replicate\n$cmd_repl");
2442 return undef;
2446 return $env;
2449 sub setup_rodc($$$)
2451 my ($self, $path, $dc_vars) = @_;
2453 my $env = $self->provision_rodc($path, $dc_vars);
2455 unless ($env) {
2456 return undef;
2459 if (not defined($self->check_or_start($env, "standard"))) {
2460 return undef;
2463 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2464 my $cmd = "";
2466 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2467 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2468 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2469 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2470 $cmd .= " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}";
2471 $cmd .= " $dc_vars->{CONFIGURATION}";
2472 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2473 # replicate Configuration NC
2474 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2475 unless(system($cmd_repl) == 0) {
2476 warn("Failed to replicate\n$cmd_repl");
2477 return undef;
2479 # replicate Default NC
2480 $cmd_repl = "$cmd \"$base_dn\"";
2481 unless(system($cmd_repl) == 0) {
2482 warn("Failed to replicate\n$cmd_repl");
2483 return undef;
2486 $self->{vars}->{rodc} = $env;
2488 return $env;
2491 sub setup_ad_dc($$)
2493 my ($self, $path, $no_nss) = @_;
2495 # If we didn't build with ADS, pretend this env was never available
2496 if (not $self->{target3}->have_ads()) {
2497 return "UNKNOWN";
2500 my $env = $self->provision_ad_dc($path);
2501 unless ($env) {
2502 return undef;
2505 if (defined($no_nss) and $no_nss) {
2506 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2507 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2510 if (not defined($self->check_or_start($env, "single"))) {
2511 return undef;
2514 my $upn_array = ["$env->{REALM}.upn"];
2515 my $spn_array = ["$env->{REALM}.spn"];
2517 $self->setup_namespaces($env, $upn_array, $spn_array);
2519 $self->{vars}->{ad_dc} = $env;
2520 return $env;
2523 sub setup_none($$)
2525 my ($self, $path) = @_;
2527 my $ret = {
2528 KRB5_CONFIG => abs_path($path) . "/no_krb5.conf",
2529 SAMBA_PID => -1,