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 # NOTE: Refer to the README for more details about the various testenvs,
7 # and tips about adding new testenvs.
13 use FindBin qw($RealBin);
19 use File::Path 'make_path';
22 my ($classname, $bindir, $ldap, $srcdir, $server_maxtime) = @_;
29 server_maxtime => $server_maxtime,
30 target3 => new Samba3($bindir, $srcdir, $server_maxtime)
36 sub scriptdir_path($$) {
37 my ($self, $path) = @_;
38 return "$self->{srcdir}/source4/scripting/$path";
41 sub openldap_start($$$) {
47 my ($self, $env_vars, $STDIN_READER) = @_;
48 my $ldbsearch = Samba::bindir_path($self, "ldbsearch");
50 my $uri = $env_vars->{LDAP_URI};
52 if (system("$ldbsearch -H $uri -s base -b \"\" supportedLDAPVersion > /dev/null") == 0) {
53 print "A SLAPD is still listening to $uri before we started the LDAP backend. Aborting!";
56 # running slapd in the background means it stays in the same process group, so it can be
60 open STDOUT, ">$env_vars->{LDAPDIR}/logs";
61 open STDERR, '>&STDOUT';
62 close($env_vars->{STDIN_PIPE});
63 open STDIN, ">&", $STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
65 if ($self->{ldap} eq "fedora-ds") {
66 exec("$ENV{FEDORA_DS_ROOT}/sbin/ns-slapd", "-D", $env_vars->{FEDORA_DS_DIR}, "-d0", "-i", $env_vars->{FEDORA_DS_PIDFILE});
67 } elsif ($self->{ldap} eq "openldap") {
68 exec($ENV{OPENLDAP_SLAPD}, "-dnone", "-F", $env_vars->{SLAPD_CONF_D}, "-h", $uri);
70 die("Unable to start slapd: $!");
72 $env_vars->{SLAPD_PID} = $pid;
74 while (system("$ldbsearch -H $uri -s base -b \"\" supportedLDAPVersion > /dev/null") != 0) {
77 $self->slapd_stop($env_vars);
87 my ($self, $envvars) = @_;
88 kill 9, $envvars->{SLAPD_PID};
92 sub check_or_start($$$)
94 my ($self, $env_vars, $process_model) = @_;
97 my $env_ok = $self->check_env($env_vars);
99 return $env_vars->{SAMBA_PID};
100 } elsif (defined($env_vars->{SAMBA_PID})) {
101 warn("SAMBA PID $env_vars->{SAMBA_PID} is not running (died)");
105 # use a pipe for stdin in the child processes. This allows
106 # those processes to monitor the pipe for EOF to ensure they
107 # exit when the test script exits
108 pipe($STDIN_READER, $env_vars->{STDIN_PIPE});
110 # Start slapd before samba, but with the fifo on stdin
111 if (defined($self->{ldap})) {
112 unless($self->slapd_start($env_vars, $STDIN_READER)) {
113 warn("couldn't start slapd (main run)");
118 # build up the command to run samba
121 if (defined($ENV{SAMBA_OPTIONS})) {
122 @optargs = split(/ /, $ENV{SAMBA_OPTIONS});
124 if(defined($ENV{SAMBA_VALGRIND})) {
125 @preargs = split(/ /,$ENV{SAMBA_VALGRIND});
128 if (defined($process_model)) {
129 push @optargs, ("-M", $process_model);
131 my $binary = Samba::bindir_path($self, "samba");
132 my @full_cmd = (@preargs, $binary, "-i",
133 "--no-process-group", "--maximum-runtime=$self->{server_maxtime}",
134 $env_vars->{CONFIGURATION}, @optargs);
136 # the samba process takes some additional env variables (compared to s3)
137 my $samba_envs = Samba::get_env_for_process("samba", $env_vars);
138 $samba_envs->{RESOLV_CONF} = $env_vars->{RESOLV_CONF};
139 $samba_envs->{UID_WRAPPER} = "1";
140 if (defined($ENV{MITKRB5})) {
141 $samba_envs->{KRB5_KDC_PROFILE} = $env_vars->{MITKDC_CONFIG};
144 # fork a child process and exec() samba
147 BINARY_PATH => $binary,
148 FULL_CMD => [ @full_cmd ],
149 LOG_FILE => $env_vars->{SAMBA_TEST_LOG},
151 ENV_VARS => $samba_envs,
153 my $pid = Samba::fork_and_exec($self, $env_vars, $daemon_ctx, $STDIN_READER);
155 $env_vars->{SAMBA_PID} = $pid;
157 # close the parent's read-end of the pipe
158 close($STDIN_READER);
160 if ($self->wait_for_start($env_vars) != 0) {
161 warn("Samba $pid failed to start up");
168 sub wait_for_start($$)
170 my ($self, $testenv_vars) = @_;
174 if (not $self->check_env($testenv_vars)) {
175 warn("unable to confirm Samba $testenv_vars->{SAMBA_PID} is running");
179 # This will return quickly when things are up, but be slow if we
180 # need to wait for (eg) SSL init
181 my $nmblookup = Samba::bindir_path($self, "nmblookup4");
184 $ret = system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
188 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
189 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
190 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
191 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
192 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
193 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
194 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
195 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
196 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
197 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
198 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
201 } while ($ret != 0 && $count < 20);
203 teardown_env($self, $testenv_vars);
204 warn("nbt not reachable after 20 retries\n");
208 # Ensure we have the first RID Set before we start tests. This makes the tests more reliable.
209 if ($testenv_vars->{SERVER_ROLE} eq "domain controller") {
210 print "waiting for working LDAP and a RID Set to be allocated\n";
211 my $ldbsearch = Samba::bindir_path($self, "ldbsearch");
213 my $base_dn = "DC=".join(",DC=", split(/\./, $testenv_vars->{REALM}));
215 my $search_dn = $base_dn;
216 if ($testenv_vars->{NETBIOSNAME} ne "RODC") {
217 # TODO currently no check for actual rIDAllocationPool
218 $search_dn = "cn=RID Set,cn=$testenv_vars->{NETBIOSNAME},ou=domain controllers,$base_dn";
222 # Add hosts file for name lookups
223 my $cmd = "NSS_WRAPPER_HOSTS='$testenv_vars->{NSS_WRAPPER_HOSTS}' ";
224 if (defined($testenv_vars->{RESOLV_WRAPPER_CONF})) {
225 $cmd .= "RESOLV_WRAPPER_CONF='$testenv_vars->{RESOLV_WRAPPER_CONF}' ";
227 $cmd .= "RESOLV_WRAPPER_HOSTS='$testenv_vars->{RESOLV_WRAPPER_HOSTS}' ";
229 $cmd .= "RESOLV_CONF='$testenv_vars->{RESOLV_CONF}' ";
231 $cmd .= "$ldbsearch ";
232 $cmd .= "$testenv_vars->{CONFIGURATION} ";
233 $cmd .= "-H ldap://$testenv_vars->{SERVER} ";
234 $cmd .= "-U$testenv_vars->{USERNAME}%$testenv_vars->{PASSWORD} ";
236 $cmd .= "-b '$search_dn' ";
237 while (system("$cmd >/dev/null") != 0) {
239 if ($count > $max_wait) {
240 teardown_env($self, $testenv_vars);
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}");
244 print "Waiting for working LDAP...\n";
249 my $wbinfo = Samba::bindir_path($self, "wbinfo");
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";
263 } while ($ret != 0 && $count < 20);
265 teardown_env($self, $testenv_vars);
266 warn("winbind not reachable after 20 retries\n");
270 # Ensure we registered all our names
271 if ($testenv_vars->{SERVER_ROLE} eq "domain controller") {
273 print "Waiting for dns_update_cache to be created.\n";
275 while (not -e "$testenv_vars->{PRIVATEDIR}/dns_update_cache") {
277 if ($count > $max_wait) {
278 teardown_env($self, $testenv_vars);
279 warn("Timed out ($max_wait sec) waiting for dns_update_cache PID $testenv_vars->{SAMBA_PID}");
282 print "Waiting for dns_update_cache to be created...\n";
285 print "Waiting for dns_update_cache to be filled.\n";
287 while ((-s "$testenv_vars->{PRIVATEDIR}/dns_update_cache") == 0) {
289 if ($count > $max_wait) {
290 teardown_env($self, $testenv_vars);
291 warn("Timed out ($max_wait sec) waiting for dns_update_cache PID $testenv_vars->{SAMBA_PID}");
294 print "Waiting for dns_update_cache to be filled...\n";
299 print $self->getlog_env($testenv_vars);
301 print "READY ($testenv_vars->{SAMBA_PID})\n";
306 sub write_ldb_file($$$)
308 my ($self, $file, $ldif) = @_;
310 my $ldbadd = Samba::bindir_path($self, "ldbadd");
311 open(LDIF, "|$ldbadd -H $file >/dev/null");
316 sub add_wins_config($$)
318 my ($self, $privatedir) = @_;
319 my $client_ip = Samba::get_ipv4_addr("client");
321 return $self->write_ldb_file("$privatedir/wins_config.ldb", "
322 dn: name=TORTURE_11,CN=PARTNERS
323 objectClass: wreplPartner
334 my ($self, $ctx) = @_;
336 #Make the subdirectory be as fedora DS would expect
337 my $fedora_ds_dir = "$ctx->{ldapdir}/slapd-$ctx->{ldap_instance}";
339 my $pidfile = "$fedora_ds_dir/logs/slapd-$ctx->{ldap_instance}.pid";
341 return ($fedora_ds_dir, $pidfile);
346 my ($self, $ctx) = @_;
348 my $slapd_conf_d = "$ctx->{ldapdir}/slapd.d";
349 my $pidfile = "$ctx->{ldapdir}/slapd.pid";
351 return ($slapd_conf_d, $pidfile);
354 sub setup_dns_hub_internal($$$)
356 my ($self, $hostname, $prefix) = @_;
359 unless(-d $prefix or make_path($prefix, 0777)) {
360 warn("Unable to create $prefix");
363 my $prefix_abs = abs_path($prefix);
365 die ("prefix=''") if $prefix_abs eq "";
366 die ("prefix='/'") if $prefix_abs eq "/";
368 unless (system("rm -rf $prefix_abs/*") == 0) {
369 warn("Unable to clean up");
373 $env->{NETBIOSNAME} = $hostname;
375 $env->{SERVER_IP} = Samba::get_ipv4_addr($hostname);
376 $env->{SERVER_IPV6} = Samba::get_ipv6_addr($hostname);
377 $env->{SOCKET_WRAPPER_DEFAULT_IFACE} = Samba::get_interface($hostname);
378 $env->{DNS_HUB_LOG} = "$prefix_abs/dns_hub.log";
379 $env->{RESOLV_CONF} = "$prefix_abs/resolv.conf";
380 $env->{TESTENV_DIR} = $prefix_abs;
382 open(RESOLV_CONF, ">$env->{RESOLV_CONF}");
383 print RESOLV_CONF "nameserver $env->{SERVER_IP}\n";
384 print RESOLV_CONF "nameserver $env->{SERVER_IPV6}\n";
389 if (!defined($ENV{PYTHON})) {
390 push (@preargs, "env");
391 push (@preargs, "python");
393 push (@preargs, $ENV{PYTHON});
395 my $binary = "$self->{srcdir}/selftest/target/dns_hub.py";
396 push (@args, "$self->{server_maxtime}");
397 push (@args, "$env->{SERVER_IP}");
398 push (@args, Samba::realm_to_ip_mappings());
399 my @full_cmd = (@preargs, $binary, @args);
403 BINARY_PATH => $binary,
404 FULL_CMD => [ @full_cmd ],
405 LOG_FILE => $env->{DNS_HUB_LOG},
407 PCAP_FILE => "$ENV{SOCKET_WRAPPER_PCAP_DIR}/env-$hostname$.pcap",
411 # use a pipe for stdin in the child processes. This allows
412 # those processes to monitor the pipe for EOF to ensure they
413 # exit when the test script exits
414 pipe($STDIN_READER, $env->{STDIN_PIPE});
416 my $pid = Samba::fork_and_exec($self, $env, $daemon_ctx, $STDIN_READER);
418 $env->{SAMBA_PID} = $pid;
419 $env->{KRB5_CONFIG} = "$prefix_abs/no_krb5.conf";
421 # close the parent's read-end of the pipe
422 close($STDIN_READER);
429 my ($self, $prefix) = @_;
431 my $hostname = "rootdnsforwarder";
433 my $env = $self->setup_dns_hub_internal("$hostname", "$prefix/$hostname");
435 $self->{dns_hub_env} = $env;
440 sub get_dns_hub_env($)
442 my ($self, $prefix) = @_;
444 if (defined($self->{dns_hub_env})) {
445 return $self->{dns_hub_env};
448 die("get_dns_hub_env() not setup 'dns_hub_env'");
452 # Returns the environmental variables that we pass to samba-tool commands
455 my ($self, $localenv) = @_;
457 my $cmd_env = "NSS_WRAPPER_HOSTS='$localenv->{NSS_WRAPPER_HOSTS}' ";
458 $cmd_env .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$localenv->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
459 if (defined($localenv->{RESOLV_WRAPPER_CONF})) {
460 $cmd_env .= "RESOLV_WRAPPER_CONF=\"$localenv->{RESOLV_WRAPPER_CONF}\" ";
462 $cmd_env .= "RESOLV_WRAPPER_HOSTS=\"$localenv->{RESOLV_WRAPPER_HOSTS}\" ";
464 $cmd_env .= " KRB5_CONFIG=\"$localenv->{KRB5_CONFIG}\" ";
465 $cmd_env .= "KRB5CCNAME=\"$localenv->{KRB5_CCACHE}\" ";
466 $cmd_env .= "RESOLV_CONF=\"$localenv->{RESOLV_CONF}\" ";
471 # Sets up a forest trust namespace.
472 # (Note this is different to kernel namespaces, setup by the
473 # USE_NAMESPACES=1 option)
474 sub setup_namespaces($$:$$)
476 my ($self, $localenv, $upn_array, $spn_array) = @_;
478 @{$upn_array} = [] unless defined($upn_array);
480 foreach my $upn (@{$upn_array}) {
481 $upn_args .= " --add-upn-suffix=$upn";
484 @{$spn_array} = [] unless defined($spn_array);
486 foreach my $spn (@{$spn_array}) {
487 $spn_args .= " --add-spn-suffix=$spn";
490 my $samba_tool = Samba::bindir_path($self, "samba-tool");
492 my $cmd_env = $self->get_cmd_env_vars($localenv);
494 my $cmd_config = " $localenv->{CONFIGURATION}";
496 my $namespaces = $cmd_env;
497 $namespaces .= " $samba_tool domain trust namespaces $upn_args $spn_args";
498 $namespaces .= $cmd_config;
499 unless (system($namespaces) == 0) {
500 warn("Failed to add namespaces \n$namespaces");
507 sub setup_trust($$$$$)
509 my ($self, $localenv, $remoteenv, $type, $extra_args) = @_;
511 $localenv->{TRUST_SERVER} = $remoteenv->{SERVER};
513 $localenv->{TRUST_USERNAME} = $remoteenv->{USERNAME};
514 $localenv->{TRUST_PASSWORD} = $remoteenv->{PASSWORD};
515 $localenv->{TRUST_DOMAIN} = $remoteenv->{DOMAIN};
516 $localenv->{TRUST_REALM} = $remoteenv->{REALM};
517 $localenv->{TRUST_DOMSID} = $remoteenv->{DOMSID};
519 my $samba_tool = Samba::bindir_path($self, "samba-tool");
522 my $cmd_env = $self->get_cmd_env_vars($localenv);
524 my $cmd_config = " $localenv->{CONFIGURATION}";
525 my $cmd_creds = $cmd_config;
526 $cmd_creds .= " -U$localenv->{TRUST_DOMAIN}\\\\$localenv->{TRUST_USERNAME}\%$localenv->{TRUST_PASSWORD}";
528 my $create = $cmd_env;
529 $create .= " $samba_tool domain trust create --type=${type} $localenv->{TRUST_REALM}";
530 $create .= " $extra_args";
531 $create .= $cmd_creds;
532 unless (system($create) == 0) {
533 warn("Failed to create trust \n$create");
537 my $groupname = "g_$localenv->{TRUST_DOMAIN}";
538 my $groupadd = $cmd_env;
539 $groupadd .= " $samba_tool group add '$groupname' --group-scope=Domain $cmd_config";
540 unless (system($groupadd) == 0) {
541 warn("Failed to create group \n$groupadd");
544 my $groupmem = $cmd_env;
545 $groupmem .= " $samba_tool group addmembers '$groupname' '$localenv->{TRUST_DOMSID}-513' $cmd_config";
546 unless (system($groupmem) == 0) {
547 warn("Failed to add group member \n$groupmem");
554 sub provision_raw_prepare($$$$$$$$$$$$)
556 my ($self, $prefix, $server_role, $hostname,
557 $domain, $realm, $samsid, $functional_level,
558 $password, $kdc_ipv4, $kdc_ipv6) = @_;
561 if (defined $ENV{PYTHON}) {
562 $python_cmd = $ENV{PYTHON} . " ";
564 $ctx->{python} = $python_cmd;
565 my $netbiosname = uc($hostname);
567 unless(-d $prefix or mkdir($prefix, 0777)) {
568 warn("Unable to create $prefix");
571 my $prefix_abs = abs_path($prefix);
573 die ("prefix=''") if $prefix_abs eq "";
574 die ("prefix='/'") if $prefix_abs eq "/";
576 unless (system("rm -rf $prefix_abs/*") == 0) {
577 warn("Unable to clean up");
581 my $swiface = Samba::get_interface($hostname);
583 $ctx->{prefix} = $prefix;
584 $ctx->{prefix_abs} = $prefix_abs;
586 $ctx->{server_role} = $server_role;
587 $ctx->{hostname} = $hostname;
588 $ctx->{netbiosname} = $netbiosname;
589 $ctx->{swiface} = $swiface;
590 $ctx->{password} = $password;
591 $ctx->{kdc_ipv4} = $kdc_ipv4;
592 $ctx->{kdc_ipv6} = $kdc_ipv6;
593 $ctx->{krb5_ccname} = "$prefix_abs/krb5cc_%{uid}";
594 if ($functional_level eq "2000") {
595 $ctx->{supported_enctypes} = "arcfour-hmac-md5 des-cbc-md5 des-cbc-crc"
599 # Set smbd log level here.
601 $ctx->{server_loglevel} =$ENV{SERVER_LOG_LEVEL} || 1;
602 $ctx->{username} = "Administrator";
603 $ctx->{domain} = $domain;
604 $ctx->{realm} = uc($realm);
605 $ctx->{dnsname} = lc($realm);
606 $ctx->{samsid} = $samsid;
608 $ctx->{functional_level} = $functional_level;
610 my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `whoami`);
612 $ctx->{unix_name} = $unix_name;
613 $ctx->{unix_uid} = $>;
614 my @mygid = split(" ", $();
615 $ctx->{unix_gid} = $mygid[0];
616 $ctx->{unix_gids_str} = $);
617 @{$ctx->{unix_gids}} = split(" ", $ctx->{unix_gids_str});
619 $ctx->{etcdir} = "$prefix_abs/etc";
620 $ctx->{piddir} = "$prefix_abs/pid";
621 $ctx->{smb_conf} = "$ctx->{etcdir}/smb.conf";
622 $ctx->{krb5_conf} = "$ctx->{etcdir}/krb5.conf";
623 $ctx->{krb5_ccache} = "$prefix_abs/krb5_ccache";
624 $ctx->{mitkdc_conf} = "$ctx->{etcdir}/mitkdc.conf";
625 $ctx->{privatedir} = "$prefix_abs/private";
626 $ctx->{binddnsdir} = "$prefix_abs/bind-dns";
627 $ctx->{ncalrpcdir} = "$prefix_abs/ncalrpc";
628 $ctx->{lockdir} = "$prefix_abs/lockdir";
629 $ctx->{logdir} = "$prefix_abs/logs";
630 $ctx->{statedir} = "$prefix_abs/statedir";
631 $ctx->{cachedir} = "$prefix_abs/cachedir";
632 $ctx->{winbindd_socket_dir} = "$prefix_abs/winbindd_socket";
633 $ctx->{ntp_signd_socket_dir} = "$prefix_abs/ntp_signd_socket";
634 $ctx->{nsswrap_passwd} = "$ctx->{etcdir}/passwd";
635 $ctx->{nsswrap_group} = "$ctx->{etcdir}/group";
636 $ctx->{nsswrap_hosts} = "$ENV{SELFTEST_PREFIX}/hosts";
637 $ctx->{nsswrap_hostname} = "$ctx->{hostname}.$ctx->{dnsname}";
638 if ($ENV{SAMBA_DNS_FAKING}) {
639 $ctx->{dns_host_file} = "$ENV{SELFTEST_PREFIX}/dns_host_file";
640 $ctx->{samba_dnsupdate} = "$ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate -s $ctx->{smb_conf} --all-interfaces --use-file=$ctx->{dns_host_file}";
641 $ctx->{samba_dnsupdate} = $python_cmd . $ctx->{samba_dnsupdate};
643 $ctx->{samba_dnsupdate} = "$ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate -s $ctx->{smb_conf} --all-interfaces";
644 $ctx->{samba_dnsupdate} = $python_cmd . $ctx->{samba_dnsupdate};
645 $ctx->{use_resolv_wrapper} = 1;
648 my $dns_hub = $self->get_dns_hub_env();
649 $ctx->{resolv_conf} = $dns_hub->{RESOLV_CONF};
651 $ctx->{tlsdir} = "$ctx->{privatedir}/tls";
653 $ctx->{ipv4} = Samba::get_ipv4_addr($hostname);
654 $ctx->{ipv6} = Samba::get_ipv6_addr($hostname);
656 push(@{$ctx->{directories}}, $ctx->{privatedir});
657 push(@{$ctx->{directories}}, $ctx->{binddnsdir});
658 push(@{$ctx->{directories}}, $ctx->{etcdir});
659 push(@{$ctx->{directories}}, $ctx->{piddir});
660 push(@{$ctx->{directories}}, $ctx->{lockdir});
661 push(@{$ctx->{directories}}, $ctx->{logdir});
662 push(@{$ctx->{directories}}, $ctx->{statedir});
663 push(@{$ctx->{directories}}, $ctx->{cachedir});
665 $ctx->{smb_conf_extra_options} = "";
667 my @provision_options = ();
668 push (@provision_options, "KRB5_CONFIG=\"$ctx->{krb5_conf}\"");
669 push (@provision_options, "KRB5_CCACHE=\"$ctx->{krb5_ccache}\"");
670 push (@provision_options, "NSS_WRAPPER_PASSWD=\"$ctx->{nsswrap_passwd}\"");
671 push (@provision_options, "NSS_WRAPPER_GROUP=\"$ctx->{nsswrap_group}\"");
672 push (@provision_options, "NSS_WRAPPER_HOSTS=\"$ctx->{nsswrap_hosts}\"");
673 push (@provision_options, "NSS_WRAPPER_HOSTNAME=\"$ctx->{nsswrap_hostname}\"");
674 if (defined($ctx->{use_resolv_wrapper})) {
675 push (@provision_options, "RESOLV_WRAPPER_CONF=\"$ctx->{resolv_conf}\"");
676 push (@provision_options, "RESOLV_CONF=\"$ctx->{resolv_conf}\"");
678 push (@provision_options, "RESOLV_WRAPPER_HOSTS=\"$ctx->{dns_host_file}\"");
680 if (defined($ENV{GDB_PROVISION})) {
681 push (@provision_options, "gdb --args");
682 if (!defined($ENV{PYTHON})) {
683 push (@provision_options, "env");
684 push (@provision_options, "python");
687 if (defined($ENV{VALGRIND_PROVISION})) {
688 push (@provision_options, "valgrind");
689 if (!defined($ENV{PYTHON})) {
690 push (@provision_options, "env");
691 push (@provision_options, "python");
695 my $samba_tool = Samba::bindir_path($self, "samba-tool");
697 push (@provision_options, $samba_tool);
698 push (@provision_options, "domain");
699 push (@provision_options, "provision");
700 push (@provision_options, "--configfile=$ctx->{smb_conf}");
701 push (@provision_options, "--host-name=$ctx->{hostname}");
702 push (@provision_options, "--host-ip=$ctx->{ipv4}");
703 push (@provision_options, "--quiet");
704 push (@provision_options, "--domain=$ctx->{domain}");
705 push (@provision_options, "--realm=$ctx->{realm}");
706 if (defined($ctx->{samsid})) {
707 push (@provision_options, "--domain-sid=$ctx->{samsid}");
709 push (@provision_options, "--adminpass=$ctx->{password}");
710 push (@provision_options, "--krbtgtpass=krbtgt$ctx->{password}");
711 push (@provision_options, "--machinepass=machine$ctx->{password}");
712 push (@provision_options, "--root=$ctx->{unix_name}");
713 push (@provision_options, "--server-role=\"$ctx->{server_role}\"");
714 push (@provision_options, "--function-level=\"$ctx->{functional_level}\"");
716 @{$ctx->{provision_options}} = @provision_options;
723 my ($self, $keyword, @options_list) = @_;
725 # convert the options-list to a hash-map for easy keyword lookup
726 my %options_dict = map { $_ => 1 } @options_list;
728 return exists $options_dict{$keyword};
732 # Step1 creates the basic configuration
734 sub provision_raw_step1($$)
736 my ($self, $ctx) = @_;
738 mkdir($_, 0777) foreach (@{$ctx->{directories}});
741 ## lockdir and piddir must be 0755
743 chmod 0755, $ctx->{lockdir};
744 chmod 0755, $ctx->{piddir};
746 unless (open(CONFFILE, ">$ctx->{smb_conf}")) {
747 warn("can't open $ctx->{smb_conf}$?");
751 Samba::prepare_keyblobs($ctx);
752 my $crlfile = "$ctx->{tlsdir}/crl.pem";
753 $crlfile = "" unless -e ${crlfile};
755 # work out which file server to use. Default to source3 smbd (s3fs),
756 # unless the source4 NTVFS (smb) file server has been specified
757 my $services = "-smb +s3fs";
758 if ($self->has_option("--use-ntvfs", @{$ctx->{provision_options}})) {
759 $services = "+smb -s3fs";
762 my $interfaces = Samba::get_interfaces_config($ctx->{netbiosname});
766 netbios name = $ctx->{netbiosname}
767 posix:eadb = $ctx->{statedir}/eadb.tdb
768 workgroup = $ctx->{domain}
769 realm = $ctx->{realm}
770 private dir = $ctx->{privatedir}
771 binddns dir = $ctx->{binddnsdir}
772 pid directory = $ctx->{piddir}
773 ncalrpc dir = $ctx->{ncalrpcdir}
774 lock dir = $ctx->{lockdir}
775 state directory = $ctx->{statedir}
776 cache directory = $ctx->{cachedir}
777 winbindd socket directory = $ctx->{winbindd_socket_dir}
778 ntp signd socket directory = $ctx->{ntp_signd_socket_dir}
779 winbind separator = /
780 interfaces = $interfaces
781 tls dh params file = $ctx->{tlsdir}/dhparms.pem
782 tls crlfile = ${crlfile}
783 tls verify peer = no_check
784 panic action = $RealBin/gdb_backtrace \%d
786 server role = $ctx->{server_role}
787 server services = +echo $services
788 dcerpc endpoint servers = +winreg +srvsvc
789 notify:inotify = false
791 ldap server require strong auth = yes
792 #We don't want to pass our self-tests if the PAC code is wrong
793 gensec:require_pac = true
794 log file = $ctx->{logdir}/log.\%m
795 log level = $ctx->{server_loglevel}
799 dns update command = $ctx->{samba_dnsupdate}
800 spn update command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_spnupdate -s $ctx->{smb_conf}
801 gpo update command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba-gpupdate -s $ctx->{smb_conf} --target=Computer
802 samba kcc command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_kcc
803 dreplsrv:periodic_startup_interval = 0
804 dsdb:schema update allowed = yes
806 vfs objects = dfs_samba4 acl_xattr fake_acls xattr_tdb streams_depot
808 idmap_ldb:use rfc2307=yes
809 winbind enum users = yes
810 winbind enum groups = yes
812 rpc server port:netlogon = 1026
813 include system krb5 conf = no
819 # Begin extra options
820 $ctx->{smb_conf_extra_options}
825 #Default the KDC IP to the server's IP
826 if (not defined($ctx->{kdc_ipv4})) {
827 $ctx->{kdc_ipv4} = $ctx->{ipv4};
829 if (not defined($ctx->{kdc_ipv6})) {
830 $ctx->{kdc_ipv6} = $ctx->{ipv6};
833 Samba::mk_krb5_conf($ctx);
834 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
836 open(PWD, ">$ctx->{nsswrap_passwd}");
837 if ($ctx->{unix_uid} != 0) {
838 print PWD "root:x:0:0:root gecos:$ctx->{prefix_abs}:/bin/false\n";
840 print PWD "$ctx->{unix_name}:x:$ctx->{unix_uid}:65531:$ctx->{unix_name} gecos:$ctx->{prefix_abs}:/bin/false\n";
841 print PWD "nobody:x:65534:65533:nobody gecos:$ctx->{prefix_abs}:/bin/false
842 pdbtest:x:65533:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
843 pdbtest2:x:65532:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
844 pdbtest3:x:65531:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
845 pdbtest4:x:65530:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
848 my $uid_rfc2307test = 65533;
850 open(GRP, ">$ctx->{nsswrap_group}");
851 if ($ctx->{unix_gid} != 0) {
852 print GRP "root:x:0:\n";
854 print GRP "$ctx->{unix_name}:x:$ctx->{unix_gid}:\n";
855 print GRP "wheel:x:10:
858 nogroup:x:65534:nobody
861 my $gid_rfc2307test = 65532;
863 my $hostname = lc($ctx->{hostname});
864 open(HOSTS, ">>$ctx->{nsswrap_hosts}");
865 if ($hostname eq "localdc") {
866 print HOSTS "$ctx->{ipv4} ${hostname}.$ctx->{dnsname} $ctx->{dnsname} ${hostname}\n";
867 print HOSTS "$ctx->{ipv6} ${hostname}.$ctx->{dnsname} $ctx->{dnsname} ${hostname}\n";
869 print HOSTS "$ctx->{ipv4} ${hostname}.$ctx->{dnsname} ${hostname}\n";
870 print HOSTS "$ctx->{ipv6} ${hostname}.$ctx->{dnsname} ${hostname}\n";
874 my $configuration = "--configfile=$ctx->{smb_conf}";
876 #Ensure the config file is valid before we start
877 my $testparm = Samba::bindir_path($self, "samba-tool") . " testparm";
878 if (system("$testparm $configuration -v --suppress-prompt >/dev/null 2>&1") != 0) {
879 system("$testparm -v --suppress-prompt $configuration >&2");
880 warn("Failed to create a valid smb.conf configuration $testparm!");
883 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) {
884 warn("Failed to create a valid smb.conf configuration! $testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global");
888 # Return the environment variables for the new testenv DC.
889 # Note that we have SERVER_X and DC_SERVER_X variables (which have the same
890 # value initially). In a 2 DC setup, $DC_SERVER_X will always be the PDC.
892 KRB5_CONFIG => $ctx->{krb5_conf},
893 KRB5_CCACHE => $ctx->{krb5_ccache},
894 MITKDC_CONFIG => $ctx->{mitkdc_conf},
895 PIDDIR => $ctx->{piddir},
896 SERVER => $ctx->{hostname},
897 DC_SERVER => $ctx->{hostname},
898 SERVER_IP => $ctx->{ipv4},
899 DC_SERVER_IP => $ctx->{ipv4},
900 SERVER_IPV6 => $ctx->{ipv6},
901 DC_SERVER_IPV6 => $ctx->{ipv6},
902 NETBIOSNAME => $ctx->{netbiosname},
903 DC_NETBIOSNAME => $ctx->{netbiosname},
904 DOMAIN => $ctx->{domain},
905 USERNAME => $ctx->{username},
906 DC_USERNAME => $ctx->{username},
907 REALM => $ctx->{realm},
908 DNSNAME => $ctx->{dnsname},
909 SAMSID => $ctx->{samsid},
910 PASSWORD => $ctx->{password},
911 DC_PASSWORD => $ctx->{password},
912 LDAPDIR => $ctx->{ldapdir},
913 LDAP_INSTANCE => $ctx->{ldap_instance},
914 SELFTEST_WINBINDD_SOCKET_DIR => $ctx->{winbindd_socket_dir},
915 NCALRPCDIR => $ctx->{ncalrpcdir},
916 LOCKDIR => $ctx->{lockdir},
917 STATEDIR => $ctx->{statedir},
918 CACHEDIR => $ctx->{cachedir},
919 PRIVATEDIR => $ctx->{privatedir},
920 BINDDNSDIR => $ctx->{binddnsdir},
921 SERVERCONFFILE => $ctx->{smb_conf},
922 TESTENV_DIR => $ctx->{prefix_abs},
923 CONFIGURATION => $configuration,
924 SOCKET_WRAPPER_DEFAULT_IFACE => $ctx->{swiface},
925 NSS_WRAPPER_PASSWD => $ctx->{nsswrap_passwd},
926 NSS_WRAPPER_GROUP => $ctx->{nsswrap_group},
927 NSS_WRAPPER_HOSTS => $ctx->{nsswrap_hosts},
928 NSS_WRAPPER_HOSTNAME => $ctx->{nsswrap_hostname},
929 SAMBA_TEST_FIFO => "$ctx->{prefix}/samba_test.fifo",
930 SAMBA_TEST_LOG => "$ctx->{prefix}/samba_test.log",
931 SAMBA_TEST_LOG_POS => 0,
932 NSS_WRAPPER_MODULE_SO_PATH => Samba::nss_wrapper_winbind_so_path($self),
933 NSS_WRAPPER_MODULE_FN_PREFIX => "winbind",
934 LOCAL_PATH => $ctx->{share},
935 UID_RFC2307TEST => $uid_rfc2307test,
936 GID_RFC2307TEST => $gid_rfc2307test,
937 SERVER_ROLE => $ctx->{server_role},
938 RESOLV_CONF => $ctx->{resolv_conf}
941 if (defined($ctx->{use_resolv_wrapper})) {
942 $ret->{RESOLV_WRAPPER_CONF} = $ctx->{resolv_conf};
944 $ret->{RESOLV_WRAPPER_HOSTS} = $ctx->{dns_host_file};
947 if ($ctx->{server_role} eq "domain controller") {
948 $ret->{DOMSID} = $ret->{SAMSID};
955 # Step2 runs the provision script
957 sub provision_raw_step2($$$)
959 my ($self, $ctx, $ret) = @_;
961 my $provision_cmd = join(" ", @{$ctx->{provision_options}});
962 unless (system($provision_cmd) == 0) {
963 warn("Unable to provision: \n$provision_cmd\n");
967 my $testallowed_account = "testallowed";
968 my $samba_tool_cmd = "";
969 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
970 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
971 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
972 . " user create --configfile=$ctx->{smb_conf} $testallowed_account $ctx->{password}";
973 unless (system($samba_tool_cmd) == 0) {
974 warn("Unable to add testallowed user: \n$samba_tool_cmd\n");
979 $ldbmodify .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
980 $ldbmodify .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
981 $ldbmodify .= Samba::bindir_path($self, "ldbmodify");
982 $ldbmodify .= " --configfile=$ctx->{smb_conf}";
983 my $base_dn = "DC=".join(",DC=", split(/\./, $ctx->{realm}));
985 if ($ctx->{server_role} ne "domain controller") {
986 $base_dn = "DC=$ctx->{netbiosname}";
989 my $user_dn = "cn=$testallowed_account,cn=users,$base_dn";
990 $testallowed_account = "testallowed account";
991 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
992 print LDIF "dn: $user_dn
994 replace: samAccountName
995 samAccountName: $testallowed_account
1000 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
1001 print LDIF "dn: $user_dn
1003 replace: userPrincipalName
1004 userPrincipalName: testallowed upn\@$ctx->{realm}
1005 replace: servicePrincipalName
1006 servicePrincipalName: host/testallowed
1011 $samba_tool_cmd = "";
1012 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1013 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1014 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1015 . " user create --configfile=$ctx->{smb_conf} testdenied $ctx->{password}";
1016 unless (system($samba_tool_cmd) == 0) {
1017 warn("Unable to add testdenied user: \n$samba_tool_cmd\n");
1021 my $user_dn = "cn=testdenied,cn=users,$base_dn";
1022 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
1023 print LDIF "dn: $user_dn
1025 replace: userPrincipalName
1026 userPrincipalName: testdenied_upn\@$ctx->{realm}.upn
1031 $samba_tool_cmd = "";
1032 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1033 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1034 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1035 . " user create --configfile=$ctx->{smb_conf} testupnspn $ctx->{password}";
1036 unless (system($samba_tool_cmd) == 0) {
1037 warn("Unable to add testupnspn user: \n$samba_tool_cmd\n");
1041 my $user_dn = "cn=testupnspn,cn=users,$base_dn";
1042 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
1043 print LDIF "dn: $user_dn
1045 replace: userPrincipalName
1046 userPrincipalName: http/testupnspn.$ctx->{dnsname}\@$ctx->{realm}
1047 replace: servicePrincipalName
1048 servicePrincipalName: http/testupnspn.$ctx->{dnsname}
1053 $samba_tool_cmd = "";
1054 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1055 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1056 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1057 . " group addmembers --configfile=$ctx->{smb_conf} 'Allowed RODC Password Replication Group' '$testallowed_account'";
1058 unless (system($samba_tool_cmd) == 0) {
1059 warn("Unable to add '$testallowed_account' user to 'Allowed RODC Password Replication Group': \n$samba_tool_cmd\n");
1063 # Create to users alice and bob!
1064 my $user_account_array = ["alice", "bob", "jane"];
1066 foreach my $user_account (@{$user_account_array}) {
1067 my $samba_tool_cmd = "";
1069 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1070 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1071 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1072 . " user create --configfile=$ctx->{smb_conf} $user_account Secret007";
1073 unless (system($samba_tool_cmd) == 0) {
1074 warn("Unable to create user: $user_account\n$samba_tool_cmd\n");
1080 $ldbmodify .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1081 $ldbmodify .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1082 $ldbmodify .= Samba::bindir_path($self, "ldbmodify");
1083 $ldbmodify .= " --configfile=$ctx->{smb_conf}";
1084 my $base_dn = "DC=".join(",DC=", split(/\./, $ctx->{realm}));
1085 my $user_dn = "cn=jane,cn=users,$base_dn";
1087 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
1088 print LDIF "dn: $user_dn
1090 replace: userPrincipalName
1091 userPrincipalName: jane.doe\@$ctx->{realm}
1099 sub provision($$$$$$$$$$)
1101 my ($self, $prefix, $server_role, $hostname,
1102 $domain, $realm, $functional_level,
1103 $password, $kdc_ipv4, $kdc_ipv6, $extra_smbconf_options, $extra_smbconf_shares,
1104 $extra_provision_options) = @_;
1106 my $samsid = Samba::random_domain_sid();
1108 my $ctx = $self->provision_raw_prepare($prefix, $server_role,
1113 $password, $kdc_ipv4, $kdc_ipv6);
1115 if (defined($extra_provision_options)) {
1116 push (@{$ctx->{provision_options}}, @{$extra_provision_options});
1119 $ctx->{share} = "$ctx->{prefix_abs}/share";
1120 push(@{$ctx->{directories}}, "$ctx->{share}");
1121 push(@{$ctx->{directories}}, "$ctx->{share}/test1");
1122 push(@{$ctx->{directories}}, "$ctx->{share}/test2");
1124 # precreate directories for printer drivers
1125 push(@{$ctx->{directories}}, "$ctx->{share}/W32X86");
1126 push(@{$ctx->{directories}}, "$ctx->{share}/x64");
1127 push(@{$ctx->{directories}}, "$ctx->{share}/WIN40");
1130 $msdfs = "yes" if ($server_role eq "domain controller");
1131 $ctx->{smb_conf_extra_options} = "
1134 server max protocol = SMB2
1138 # fruit:copyfile is a global option
1139 fruit:copyfile = yes
1141 $extra_smbconf_options
1144 path = $ctx->{share}
1146 posix:sharedelay = 100000
1147 posix:oplocktimeout = 3
1148 posix:writetimeupdatedelay = 500000
1151 path = $ctx->{share}
1153 posix:sharedelay = 100000
1154 posix:oplocktimeout = 3
1155 posix:writetimeupdatedelay = 500000
1157 force create mode = 777
1160 path = $ctx->{share}
1163 force create mode = 0
1164 directory mask = 0777
1165 force directory mode = 0
1168 path = $ctx->{share}/test1
1170 posix:sharedelay = 100000
1171 posix:oplocktimeout = 3
1172 posix:writetimeupdatedelay = 500000
1175 path = $ctx->{share}/test2
1177 posix:sharedelay = 100000
1178 posix:oplocktimeout = 3
1179 posix:writetimeupdatedelay = 500000
1182 path = $ctx->{share}/_ignore_cifs_
1184 ntvfs handler = cifs
1185 cifs:server = $ctx->{netbiosname}
1187 cifs:use-s4u2proxy = yes
1188 # There is no username specified here, instead the client is expected
1189 # to log in with kerberos, and the serverwill use delegated credentials.
1190 # Or the server tries s4u2self/s4u2proxy to impersonate the client
1193 path = $ctx->{share}
1195 ntvfs handler = simple
1198 path = $ctx->{statedir}/sysvol
1202 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1207 ntvfs handler = cifsposix
1210 path = $ctx->{share}
1211 vfs objects = catia fruit streams_xattr acl_xattr
1213 fruit:resource = file
1214 fruit:metadata = netatalk
1215 fruit:locking = netatalk
1216 fruit:encoding = native
1218 $extra_smbconf_shares
1221 if (defined($self->{ldap})) {
1222 $ctx->{ldapdir} = "$ctx->{privatedir}/ldap";
1223 push(@{$ctx->{directories}}, "$ctx->{ldapdir}");
1225 my $ldap_uri= "$ctx->{ldapdir}/ldapi";
1226 $ldap_uri =~ s|/|%2F|g;
1227 $ldap_uri = "ldapi://$ldap_uri";
1228 $ctx->{ldap_uri} = $ldap_uri;
1230 $ctx->{ldap_instance} = lc($ctx->{netbiosname});
1233 my $ret = $self->provision_raw_step1($ctx);
1234 unless (defined $ret) {
1238 if (defined($self->{ldap})) {
1239 $ret->{LDAP_URI} = $ctx->{ldap_uri};
1240 push (@{$ctx->{provision_options}}, "--ldap-backend-type=" . $self->{ldap});
1241 push (@{$ctx->{provision_options}}, "--ldap-backend-nosync");
1242 if ($self->{ldap} eq "openldap") {
1243 push (@{$ctx->{provision_options}}, "--slapd-path=" . $ENV{OPENLDAP_SLAPD});
1244 ($ret->{SLAPD_CONF_D}, $ret->{OPENLDAP_PIDFILE}) = $self->mk_openldap($ctx) or die("Unable to create openldap directories");
1246 } elsif ($self->{ldap} eq "fedora-ds") {
1247 push (@{$ctx->{provision_options}}, "--slapd-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/ns-slapd");
1248 push (@{$ctx->{provision_options}}, "--setup-ds-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/setup-ds.pl");
1249 ($ret->{FEDORA_DS_DIR}, $ret->{FEDORA_DS_PIDFILE}) = $self->mk_fedora_ds($ctx) or die("Unable to create fedora ds directories");
1254 return $self->provision_raw_step2($ctx, $ret);
1257 # For multi-DC testenvs, we want $DC_SERVER to always be the PDC (i.e. the
1258 # original DC) in the testenv. $SERVER is always the joined DC that we are
1259 # actually running the test against
1260 sub set_pdc_env_vars
1262 my ($self, $env, $dcvars) = @_;
1264 $env->{DC_SERVER} = $dcvars->{DC_SERVER};
1265 $env->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1266 $env->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1267 $env->{DC_SERVERCONFFILE} = $dcvars->{SERVERCONFFILE};
1268 $env->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1269 $env->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1270 $env->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1273 sub provision_s4member($$$$$)
1275 my ($self, $prefix, $dcvars, $hostname, $more_conf) = @_;
1276 print "PROVISIONING MEMBER...\n";
1277 my $extra_smb_conf = "
1278 passdb backend = samba_dsdb
1279 winbindd:use external pipes = true
1281 # the source4 smb server doesn't allow signing by default
1282 server signing = enabled
1283 raw NTLMv2 auth = yes
1285 rpc_server:default = external
1286 rpc_server:svcctl = embedded
1287 rpc_server:srvsvc = embedded
1288 rpc_server:eventlog = embedded
1289 rpc_server:ntsvcs = embedded
1290 rpc_server:winreg = embedded
1291 rpc_server:spoolss = embedded
1292 rpc_daemon:spoolssd = embedded
1293 rpc_server:tcpip = no
1296 $extra_smb_conf = $extra_smb_conf . $more_conf . "\n";
1298 my $extra_provision_options = ["--use-ntvfs"];
1299 my $ret = $self->provision($prefix,
1306 $dcvars->{SERVER_IP},
1307 $dcvars->{SERVER_IPV6},
1308 $extra_smb_conf, "",
1309 $extra_provision_options);
1314 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1315 my $cmd = $self->get_cmd_env_vars($ret);
1316 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
1317 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1318 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1320 unless (system($cmd) == 0) {
1321 warn("Join failed\n$cmd");
1325 $ret->{DOMSID} = $dcvars->{DOMSID};
1326 $self->set_pdc_env_vars($ret, $dcvars);
1331 sub provision_rpc_proxy($$$)
1333 my ($self, $prefix, $dcvars) = @_;
1334 print "PROVISIONING RPC PROXY...\n";
1336 my $extra_smbconf_options = "
1337 passdb backend = samba_dsdb
1340 dcerpc_remote:binding = ncacn_ip_tcp:$dcvars->{SERVER}
1341 dcerpc endpoint servers = epmapper, remote
1342 dcerpc_remote:interfaces = rpcecho
1343 dcerpc_remote:allow_anonymous_fallback = yes
1346 path = /tmp/_ignore_cifs_to_dc_/_none_
1348 ntvfs handler = cifs
1349 cifs:server = $dcvars->{SERVER}
1351 cifs:use-s4u2proxy = yes
1352 # There is no username specified here, instead the client is expected
1353 # to log in with kerberos, and the serverwill use delegated credentials.
1354 # Or the server tries s4u2self/s4u2proxy to impersonate the client
1358 my $extra_provision_options = ["--use-ntvfs"];
1359 my $ret = $self->provision($prefix,
1366 $dcvars->{SERVER_IP},
1367 $dcvars->{SERVER_IPV6},
1368 $extra_smbconf_options, "",
1369 $extra_provision_options);
1374 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1376 # The joind runs in the context of the rpc_proxy/member for now
1377 my $cmd = $self->get_cmd_env_vars($ret);
1378 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
1379 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1380 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1382 unless (system($cmd) == 0) {
1383 warn("Join failed\n$cmd");
1387 # Setting up delegation runs in the context of the DC for now
1389 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1390 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
1391 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1392 $cmd .= "RESOLV_CONF=\"$dcvars->{RESOLV_CONF}\" ";
1393 $cmd .= "$samba_tool delegation for-any-protocol '$ret->{NETBIOSNAME}\$' on";
1394 $cmd .= " $dcvars->{CONFIGURATION}";
1397 unless (system($cmd) == 0) {
1398 warn("Delegation failed\n$cmd");
1402 # Setting up delegation runs in the context of the DC for now
1404 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1405 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
1406 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1407 $cmd .= "RESOLV_CONF=\"$dcvars->{RESOLV_CONF}\" ";
1408 $cmd .= "$samba_tool delegation add-service '$ret->{NETBIOSNAME}\$' cifs/$dcvars->{SERVER}";
1409 $cmd .= " $dcvars->{CONFIGURATION}";
1411 unless (system($cmd) == 0) {
1412 warn("Delegation failed\n$cmd");
1416 $ret->{DOMSID} = $dcvars->{DOMSID};
1417 $self->set_pdc_env_vars($ret, $dcvars);
1422 sub provision_promoted_dc($$$)
1424 my ($self, $prefix, $dcvars) = @_;
1425 print "PROVISIONING PROMOTED DC...\n";
1427 # We do this so that we don't run the provision. That's the job of 'samba-tool domain dcpromo'.
1428 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1434 $dcvars->{PASSWORD},
1435 $dcvars->{SERVER_IP},
1436 $dcvars->{SERVER_IPV6});
1438 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1440 $ctx->{smb_conf_extra_options} = "
1442 server max protocol = SMB2
1444 ntlm auth = ntlmv2-only
1447 path = $ctx->{statedir}/sysvol
1451 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1456 my $ret = $self->provision_raw_step1($ctx);
1461 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1462 my $cmd = $self->get_cmd_env_vars($ret);
1463 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} MEMBER --realm=$dcvars->{REALM}";
1464 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1465 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1467 unless (system($cmd) == 0) {
1468 warn("Join failed\n$cmd");
1472 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1473 my $cmd = $self->get_cmd_env_vars($ret);
1474 $cmd .= "$samba_tool domain dcpromo $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1475 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1476 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs --dns-backend=BIND9_DLZ";
1478 unless (system($cmd) == 0) {
1479 warn("Join failed\n$cmd");
1483 $self->set_pdc_env_vars($ret, $dcvars);
1488 sub provision_vampire_dc($$$)
1490 my ($self, $prefix, $dcvars, $fl) = @_;
1491 print "PROVISIONING VAMPIRE DC @ FL $fl...\n";
1492 my $name = "localvampiredc";
1493 my $extra_conf = "";
1495 if ($fl == "2000") {
1496 $name = "vampire2000dc";
1498 $extra_conf = "drs: immediate link sync = yes
1499 drs: max link sync = 250";
1502 # We do this so that we don't run the provision. That's the job of 'net vampire'.
1503 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1509 $dcvars->{PASSWORD},
1510 $dcvars->{SERVER_IP},
1511 $dcvars->{SERVER_IPV6});
1513 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1515 $ctx->{smb_conf_extra_options} = "
1517 server max protocol = SMB2
1519 ntlm auth = mschapv2-and-ntlmv2-only
1523 path = $ctx->{statedir}/sysvol
1527 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1532 my $ret = $self->provision_raw_step1($ctx);
1537 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1538 my $cmd = $self->get_cmd_env_vars($ret);
1539 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1540 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} --domain-critical-only";
1541 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs";
1542 $cmd .= " --backend-store=mdb";
1544 unless (system($cmd) == 0) {
1545 warn("Join failed\n$cmd");
1549 $self->set_pdc_env_vars($ret, $dcvars);
1550 $ret->{DC_REALM} = $dcvars->{DC_REALM};
1555 sub provision_subdom_dc($$$)
1557 my ($self, $prefix, $dcvars) = @_;
1558 print "PROVISIONING SUBDOMAIN DC...\n";
1560 # We do this so that we don't run the provision. That's the job of 'net vampire'.
1561 my $samsid = undef; # TODO pass the domain sid all the way down
1562 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1565 "sub.samba.example.com",
1568 $dcvars->{PASSWORD},
1571 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1573 $ctx->{smb_conf_extra_options} = "
1575 server max protocol = SMB2
1578 path = $ctx->{statedir}/sysvol
1582 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1587 my $ret = $self->provision_raw_step1($ctx);
1592 Samba::mk_krb5_conf($ctx);
1593 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
1595 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1596 my $cmd = $self->get_cmd_env_vars($ret);
1597 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $ctx->{dnsname} subdomain ";
1598 $cmd .= "--parent-domain=$dcvars->{REALM} -U$dcvars->{DC_USERNAME}\@$dcvars->{REALM}\%$dcvars->{DC_PASSWORD}";
1599 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs";
1600 $cmd .= " --adminpass=$ret->{PASSWORD}";
1602 unless (system($cmd) == 0) {
1603 warn("Join failed\n$cmd");
1607 $ret->{SUBDOM_DC_SERVER} = $ret->{SERVER};
1609 $self->set_pdc_env_vars($ret, $dcvars);
1614 sub provision_ad_dc_ntvfs($$)
1616 my ($self, $prefix) = @_;
1618 # We keep the old 'winbind' name here in server services to
1619 # ensure upgrades which used that name still work with the now
1622 print "PROVISIONING AD DC (NTVFS)...\n";
1623 my $extra_conf_options = "netbios aliases = localDC1-a
1624 server services = +winbind -winbindd
1625 ldap server require strong auth = allow_sasl_over_tls
1626 allow nt4 crypto = yes
1627 raw NTLMv2 auth = yes
1628 lsa over netlogon = yes
1629 rpc server port = 1027
1630 auth event notification = true
1631 dsdb event notification = true
1632 dsdb password event notification = true
1633 dsdb group change notification = true
1634 server schannel = auto
1636 my $extra_provision_options = ["--use-ntvfs"];
1637 my $ret = $self->provision($prefix,
1638 "domain controller",
1641 "samba.example.com",
1646 $extra_conf_options,
1648 $extra_provision_options);
1653 unless($self->add_wins_config("$prefix/private")) {
1654 warn("Unable to add wins configuration");
1657 $ret->{NETBIOSALIAS} = "localdc1-a";
1658 $ret->{DC_REALM} = $ret->{REALM};
1663 sub provision_fl2000dc($$)
1665 my ($self, $prefix) = @_;
1667 print "PROVISIONING DC WITH FOREST LEVEL 2000...\n";
1668 my $extra_conf_options = "
1669 spnego:simulate_w2k=yes
1670 ntlmssp_server:force_old_spnego=yes
1672 my $extra_provision_options = ["--use-ntvfs"];
1673 # This environment uses plain text secrets
1674 # i.e. secret attributes are not encrypted on disk.
1675 # This allows testing of the --plaintext-secrets option for
1677 push (@{$extra_provision_options}, "--plaintext-secrets");
1678 my $ret = $self->provision($prefix,
1679 "domain controller",
1682 "samba2000.example.com",
1687 $extra_conf_options,
1689 $extra_provision_options);
1694 unless($self->add_wins_config("$prefix/private")) {
1695 warn("Unable to add wins configuration");
1698 $ret->{DC_REALM} = $ret->{REALM};
1703 sub provision_fl2003dc($$$)
1705 my ($self, $prefix, $dcvars) = @_;
1706 my $ip_addr1 = Samba::get_ipv4_addr("fakednsforwarder1");
1707 my $ip_addr2 = Samba::get_ipv4_addr("fakednsforwarder2");
1709 print "PROVISIONING DC WITH FOREST LEVEL 2003...\n";
1710 my $extra_conf_options = "allow dns updates = nonsecure and secure
1711 dcesrv:header signing = no
1712 dcesrv:max auth states = 0
1713 dns forwarder = $ip_addr1 $ip_addr2";
1714 my $extra_provision_options = ["--use-ntvfs"];
1715 my $ret = $self->provision($prefix,
1716 "domain controller",
1719 "samba2003.example.com",
1724 $extra_conf_options,
1726 $extra_provision_options);
1727 unless (defined $ret) {
1731 $ret->{DNS_FORWARDER1} = $ip_addr1;
1732 $ret->{DNS_FORWARDER2} = $ip_addr2;
1734 my @samba_tool_options;
1735 push (@samba_tool_options, Samba::bindir_path($self, "samba-tool"));
1736 push (@samba_tool_options, "domain");
1737 push (@samba_tool_options, "passwordsettings");
1738 push (@samba_tool_options, "set");
1739 push (@samba_tool_options, "--configfile=$ret->{SERVERCONFFILE}");
1740 push (@samba_tool_options, "--min-pwd-age=0");
1741 push (@samba_tool_options, "--history-length=1");
1743 my $samba_tool_cmd = join(" ", @samba_tool_options);
1745 unless (system($samba_tool_cmd) == 0) {
1746 warn("Unable to set min password age to 0: \n$samba_tool_cmd\n");
1750 unless($self->add_wins_config("$prefix/private")) {
1751 warn("Unable to add wins configuration");
1758 sub provision_fl2008r2dc($$$)
1760 my ($self, $prefix, $dcvars) = @_;
1762 print "PROVISIONING DC WITH FOREST LEVEL 2008r2...\n";
1763 my $extra_conf_options = "ldap server require strong auth = no";
1764 my $extra_provision_options = ["--use-ntvfs"];
1765 my $ret = $self->provision($prefix,
1766 "domain controller",
1769 "samba2008R2.example.com",
1774 $extra_conf_options,
1776 $extra_provision_options);
1777 unless (defined $ret) {
1781 unless ($self->add_wins_config("$prefix/private")) {
1782 warn("Unable to add wins configuration");
1785 $ret->{DC_REALM} = $ret->{REALM};
1791 sub provision_rodc($$$)
1793 my ($self, $prefix, $dcvars) = @_;
1794 print "PROVISIONING RODC...\n";
1796 # We do this so that we don't run the provision. That's the job of 'net join RODC'.
1797 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1803 $dcvars->{PASSWORD},
1804 $dcvars->{SERVER_IP},
1805 $dcvars->{SERVER_IPV6});
1810 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1812 $ctx->{share} = "$ctx->{prefix_abs}/share";
1813 push(@{$ctx->{directories}}, "$ctx->{share}");
1815 $ctx->{smb_conf_extra_options} = "
1817 server max protocol = SMB2
1818 password server = $dcvars->{DC_SERVER}
1821 path = $ctx->{statedir}/sysvol
1825 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1829 path = $ctx->{share}
1831 posix:sharedelay = 10000
1832 posix:oplocktimeout = 3
1833 posix:writetimeupdatedelay = 50000
1837 my $ret = $self->provision_raw_step1($ctx);
1842 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1843 my $cmd = $self->get_cmd_env_vars($ret);
1844 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} RODC";
1845 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1846 $cmd .= " --server=$dcvars->{DC_SERVER} --use-ntvfs";
1848 unless (system($cmd) == 0) {
1849 warn("RODC join failed\n$cmd");
1853 # This ensures deterministic behaviour for tests that want to have the 'testallowed account'
1854 # user password verified on the RODC
1855 my $testallowed_account = "testallowed account";
1856 $cmd = "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1857 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1858 $cmd .= "RESOLV_CONF=\"$ret->{RESOLV_CONF}\" ";
1859 $cmd .= "$samba_tool rodc preload '$testallowed_account' $ret->{CONFIGURATION}";
1860 $cmd .= " --server=$dcvars->{DC_SERVER}";
1862 unless (system($cmd) == 0) {
1863 warn("RODC join failed\n$cmd");
1867 # we overwrite the kdc after the RODC join
1868 # so that use the RODC as kdc and test
1870 $ctx->{kdc_ipv4} = $ret->{SERVER_IP};
1871 $ctx->{kdc_ipv6} = $ret->{SERVER_IPV6};
1872 Samba::mk_krb5_conf($ctx);
1873 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
1875 $self->set_pdc_env_vars($ret, $dcvars);
1880 sub read_config_h($)
1884 open(LF, "<$name") or die("unable to read $name: $!");
1887 next if not (/^#define /);
1888 if (/^#define (.*?)[ \t]+(.*?)$/) {
1892 if (/^#define (.*?)[ \t]+$/) {
1901 sub provision_ad_dc($$$$$$)
1903 my ($self, $prefix, $hostname, $domain, $realm, $smbconf_args,
1904 $extra_provision_options) = @_;
1906 my $prefix_abs = abs_path($prefix);
1908 my $bindir_abs = abs_path($self->{bindir});
1909 my $lockdir="$prefix_abs/lockdir";
1910 my $conffile="$prefix_abs/etc/smb.conf";
1912 my $require_mutexes = "dbwrap_tdb_require_mutexes:* = yes";
1913 $require_mutexes = "" if ($ENV{SELFTEST_DONT_REQUIRE_TDB_MUTEX_SUPPORT} eq "1");
1917 if (defined($ENV{CONFIG_H})) {
1918 $config_h = read_config_h($ENV{CONFIG_H});
1921 my $password_hash_gpg_key_ids = "password hash gpg key ids = 4952E40301FAB41A";
1922 $password_hash_gpg_key_ids = "" unless defined($config_h->{HAVE_GPGME});
1924 my $extra_smbconf_options = "
1925 xattr_tdb:file = $prefix_abs/statedir/xattr.tdb
1927 dbwrap_tdb_mutexes:* = yes
1930 ${password_hash_gpg_key_ids}
1933 kernel change notify = no
1938 printcap name = /dev/null
1943 smbd:sharedelay = 100000
1944 smbd:writetimeupdatedelay = 500000
1947 check parent directory delete on close = yes
1949 dcerpc endpoint servers = -winreg -srvsvc
1951 printcap name = /dev/null
1953 addprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -a -s $conffile --
1954 deleteprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -d -s $conffile --
1957 print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
1958 lpq command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpq %p
1959 lp rm command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lprm %p %j
1960 lp pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lppause %p %j
1961 lp resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpresume %p %j
1962 queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
1963 queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
1965 print notify backchannel = yes
1967 server schannel = auto
1968 auth event notification = true
1969 dsdb event notification = true
1970 dsdb password event notification = true
1971 dsdb group change notification = true
1975 my $extra_smbconf_shares = "
1979 smb encrypt = required
1983 case sensitive = yes
1991 hide unreadable = yes
1995 kernel share modes = no
2014 push (@{$extra_provision_options}, "--backend-store=mdb");
2015 print "PROVISIONING AD DC...\n";
2016 my $ret = $self->provision($prefix,
2017 "domain controller",
2025 $extra_smbconf_options,
2026 $extra_smbconf_shares,
2027 $extra_provision_options);
2028 unless (defined $ret) {
2032 unless($self->add_wins_config("$prefix/private")) {
2033 warn("Unable to add wins configuration");
2040 sub provision_chgdcpass($$)
2042 my ($self, $prefix) = @_;
2044 print "PROVISIONING CHGDCPASS...\n";
2045 # This environment disallows the use of this password
2046 # (and also removes the default AD complexity checks)
2047 my $unacceptable_password = "widk3Dsle32jxdBdskldsk55klASKQ";
2048 my $extra_smb_conf = "
2049 check password script = $self->{srcdir}/selftest/checkpassword_arg1.sh ${unacceptable_password}
2050 allow dcerpc auth level connect:lsarpc = yes
2051 dcesrv:max auth states = 8
2053 my $extra_provision_options = ["--use-ntvfs"];
2054 push (@{$extra_provision_options}, "--dns-backend=BIND9_DLZ");
2055 my $ret = $self->provision($prefix,
2056 "domain controller",
2059 "chgdcpassword.samba.example.com",
2066 $extra_provision_options);
2067 unless (defined $ret) {
2071 unless($self->add_wins_config("$prefix/private")) {
2072 warn("Unable to add wins configuration");
2076 # Remove secrets.tdb from this environment to test that we
2077 # still start up on systems without the new matching
2078 # secrets.tdb records.
2079 unless (unlink("$ret->{PRIVATEDIR}/secrets.tdb") || unlink("$ret->{PRIVATEDIR}/secrets.ntdb")) {
2080 warn("Unable to remove $ret->{PRIVATEDIR}/secrets.tdb added during provision");
2084 $ret->{UNACCEPTABLE_PASSWORD} = $unacceptable_password;
2089 sub teardown_env_terminate($$)
2091 my ($self, $envvars) = @_;
2094 # This should cause samba to terminate gracefully
2095 my $smbcontrol = Samba::bindir_path($self, "smbcontrol");
2097 $cmd .= "$smbcontrol samba shutdown $envvars->{CONFIGURATION}";
2098 my $ret = system($cmd);
2100 warn "'$cmd' failed with '$ret'\n";
2103 # This should cause samba to terminate gracefully
2104 close($envvars->{STDIN_PIPE});
2106 $pid = $envvars->{SAMBA_PID};
2110 # This should give it time to write out the gcov data
2111 until ($count > 15) {
2112 if (Samba::cleanup_child($pid, "samba") != 0) {
2119 # After 15 Seconds, work out why this thing is still alive
2120 warn "server process $pid took more than $count seconds to exit, showing backtrace:\n";
2121 system("$self->{srcdir}/selftest/gdb_backtrace $pid");
2123 until ($count > 30) {
2124 if (Samba::cleanup_child($pid, "samba") != 0) {
2131 if (kill(0, $pid)) {
2132 warn "server process $pid took more than $count seconds to exit, sending SIGTERM\n";
2136 until ($count > 40) {
2137 if (Samba::cleanup_child($pid, "samba") != 0) {
2143 # If it is still around, kill it
2144 if (kill(0, $pid)) {
2145 warn "server process $pid took more than $count seconds to exit, killing\n with SIGKILL\n";
2151 sub teardown_env($$)
2153 my ($self, $envvars) = @_;
2154 teardown_env_terminate($self, $envvars);
2156 $self->slapd_stop($envvars) if ($self->{ldap});
2158 print $self->getlog_env($envvars);
2165 my ($self, $envvars) = @_;
2166 my $title = "SAMBA LOG of: $envvars->{NETBIOSNAME} pid $envvars->{SAMBA_PID}\n";
2169 open(LOG, "<$envvars->{SAMBA_TEST_LOG}");
2171 seek(LOG, $envvars->{SAMBA_TEST_LOG_POS}, SEEK_SET);
2175 $envvars->{SAMBA_TEST_LOG_POS} = tell(LOG);
2178 return "" if $out eq $title;
2185 my ($self, $envvars) = @_;
2186 my $samba_pid = $envvars->{SAMBA_PID};
2188 if (not defined($samba_pid)) {
2190 } elsif ($samba_pid > 0) {
2191 my $childpid = Samba::cleanup_child($samba_pid, "samba");
2193 if ($childpid == 0) {
2202 # Declare the environments Samba4 makes available.
2203 # To be set up, they will be called as
2204 # samba4->setup_$envname($self, $path, $dep_1_vars, $dep_2_vars, ...)
2205 # The interdependencies between the testenvs are declared below. Some testenvs
2206 # are dependent on another testenv running first, e.g. vampire_dc is dependent
2207 # on ad_dc_ntvfs because vampire_dc joins ad_dc_ntvfs's domain. All DCs are
2208 # dependent on dns_hub, which handles resolving DNS queries for the realm.
2209 %Samba4::ENV_DEPS = (
2210 # name => [dep_1, dep_2, ...],
2212 ad_dc_ntvfs => ["dns_hub"],
2213 ad_dc => ["dns_hub"],
2214 ad_dc_no_nss => ["dns_hub"],
2215 ad_dc_no_ntlm => ["dns_hub"],
2217 fl2008r2dc => ["ad_dc"],
2218 fl2003dc => ["ad_dc"],
2219 fl2000dc => ["dns_hub"],
2221 vampire_2000_dc => ["fl2000dc"],
2222 vampire_dc => ["ad_dc_ntvfs"],
2223 promoted_dc => ["ad_dc_ntvfs"],
2224 subdom_dc => ["ad_dc_ntvfs"],
2226 rodc => ["ad_dc_ntvfs"],
2227 rpc_proxy => ["ad_dc_ntvfs"],
2228 chgdcpass => ["dns_hub"],
2230 s4member_dflt_domain => ["ad_dc_ntvfs"],
2231 s4member => ["ad_dc_ntvfs"],
2233 # envs that test the server process model
2234 proclimitdc => ["dns_hub"],
2235 preforkrestartdc => ["dns_hub"],
2237 # backup/restore testenvs
2238 backupfromdc => ["dns_hub"],
2239 customdc => ["dns_hub"],
2240 restoredc => ["backupfromdc"],
2241 renamedc => ["backupfromdc"],
2242 offlinebackupdc => ["backupfromdc"],
2243 labdc => ["backupfromdc"],
2245 # aliases in order to split autbuild tasks
2246 fl2008dc => ["ad_dc_ntvfs"],
2247 ad_dc_default => ["ad_dc_ntvfs"],
2248 ad_dc_slowtests => ["ad_dc_ntvfs"],
2249 ad_dc_backup => ["ad_dc"],
2251 schema_dc => ["dns_hub"],
2252 schema_pair_dc => ["schema_dc"],
2257 %Samba4::ENV_DEPS_POST = (
2258 schema_dc => ["schema_pair_dc"],
2261 sub return_alias_env
2263 my ($self, $path, $env) = @_;
2271 my ($self, $path, $dep_env) = @_;
2272 return $self->return_alias_env($path, $dep_env)
2275 sub setup_ad_dc_default
2277 my ($self, $path, $dep_env) = @_;
2278 return $self->return_alias_env($path, $dep_env)
2281 sub setup_ad_dc_slowtests
2283 my ($self, $path, $dep_env) = @_;
2284 return $self->return_alias_env($path, $dep_env)
2287 sub setup_ad_dc_backup
2289 my ($self, $path, $dep_env) = @_;
2290 return $self->return_alias_env($path, $dep_env)
2295 my ($self, $path, $dc_vars) = @_;
2297 my $env = $self->provision_s4member($path, $dc_vars, "s4member");
2300 if (not defined($self->check_or_start($env, "standard"))) {
2308 sub setup_s4member_dflt_domain
2310 my ($self, $path, $dc_vars) = @_;
2312 my $env = $self->provision_s4member($path, $dc_vars, "s4member_dflt",
2313 "winbind use default domain = yes");
2316 if (not defined($self->check_or_start($env, "standard"))) {
2326 my ($self, $path, $dc_vars) = @_;
2328 my $env = $self->provision_rpc_proxy($path, $dc_vars);
2331 if (not defined($self->check_or_start($env, "standard"))) {
2338 sub setup_ad_dc_ntvfs
2340 my ($self, $path) = @_;
2342 my $env = $self->provision_ad_dc_ntvfs($path);
2344 if (not defined($self->check_or_start($env, "standard"))) {
2345 warn("Failed to start ad_dc_ntvfs");
2354 my ($self, $path) = @_;
2356 my $env = $self->provision_chgdcpass($path);
2358 if (not defined($self->check_or_start($env, "standard"))) {
2367 my ($self, $path) = @_;
2369 my $env = $self->provision_fl2000dc($path);
2371 if (not defined($self->check_or_start($env, "standard"))) {
2381 my ($self, $path, $dc_vars) = @_;
2383 my $env = $self->provision_fl2003dc($path);
2386 if (not defined($self->check_or_start($env, "standard"))) {
2390 $env = $self->setup_trust($env, $dc_vars, "external", "--no-aes-keys");
2395 sub setup_fl2008r2dc
2397 my ($self, $path, $dc_vars) = @_;
2399 my $env = $self->provision_fl2008r2dc($path);
2402 if (not defined($self->check_or_start($env, "standard"))) {
2406 my $upn_array = ["$env->{REALM}.upn"];
2407 my $spn_array = ["$env->{REALM}.spn"];
2409 $self->setup_namespaces($env, $upn_array, $spn_array);
2411 $env = $self->setup_trust($env, $dc_vars, "forest", "");
2417 sub setup_vampire_dc
2419 return setup_generic_vampire_dc(@_, "2008");
2422 sub setup_vampire_2000_dc
2424 return setup_generic_vampire_dc(@_, "2000");
2427 sub setup_generic_vampire_dc
2429 my ($self, $path, $dc_vars, $fl) = @_;
2431 my $env = $self->provision_vampire_dc($path, $dc_vars, $fl);
2434 if (not defined($self->check_or_start($env, "single"))) {
2438 # force replicated DC to update repsTo/repsFrom
2439 # for vampired partitions
2440 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2442 # as 'vampired' dc may add data in its local replica
2443 # we need to synchronize data between DCs
2444 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2445 my $cmd = $self->get_cmd_env_vars($env);
2446 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2447 $cmd .= " $dc_vars->{CONFIGURATION}";
2448 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2449 # replicate Configuration NC
2450 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2451 unless(system($cmd_repl) == 0) {
2452 warn("Failed to replicate\n$cmd_repl");
2455 # replicate Default NC
2456 $cmd_repl = "$cmd \"$base_dn\"";
2457 unless(system($cmd_repl) == 0) {
2458 warn("Failed to replicate\n$cmd_repl");
2462 # Pull in a full set of changes from the main DC
2463 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2464 $cmd = $self->get_cmd_env_vars($env);
2465 $cmd .= " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}";
2466 $cmd .= " $dc_vars->{CONFIGURATION}";
2467 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2468 # replicate Configuration NC
2469 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2470 unless(system($cmd_repl) == 0) {
2471 warn("Failed to replicate\n$cmd_repl");
2474 # replicate Default NC
2475 $cmd_repl = "$cmd \"$base_dn\"";
2476 unless(system($cmd_repl) == 0) {
2477 warn("Failed to replicate\n$cmd_repl");
2485 sub setup_promoted_dc
2487 my ($self, $path, $dc_vars) = @_;
2489 my $env = $self->provision_promoted_dc($path, $dc_vars);
2492 if (not defined($self->check_or_start($env, "single"))) {
2496 # force source and replicated DC to update repsTo/repsFrom
2497 # for vampired partitions
2498 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2499 my $cmd = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2500 # as 'vampired' dc may add data in its local replica
2501 # we need to synchronize data between DCs
2502 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2503 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2504 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2505 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2506 $cmd .= "RESOLV_CONF=\"$env->{RESOLV_CONF}\" ";
2507 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2508 $cmd .= " $dc_vars->{CONFIGURATION}";
2509 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2510 # replicate Configuration NC
2511 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2512 unless(system($cmd_repl) == 0) {
2513 warn("Failed to replicate\n$cmd_repl");
2516 # replicate Default NC
2517 $cmd_repl = "$cmd \"$base_dn\"";
2518 unless(system($cmd_repl) == 0) {
2519 warn("Failed to replicate\n$cmd_repl");
2529 my ($self, $path, $dc_vars) = @_;
2531 my $env = $self->provision_subdom_dc($path, $dc_vars);
2534 if (not defined($self->check_or_start($env, "single"))) {
2538 # force replicated DC to update repsTo/repsFrom
2539 # for primary domain partitions
2540 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2541 my $cmd = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2542 # as 'subdomain' dc may add data in its local replica
2543 # we need to synchronize data between DCs
2544 my $base_dn = "DC=".join(",DC=", split(/\./, $env->{REALM}));
2545 my $config_dn = "CN=Configuration,DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2546 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2547 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2548 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2549 $cmd .= "RESOLV_CONF=\"$env->{RESOLV_CONF}\" ";
2550 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SUBDOM_DC_SERVER}";
2551 $cmd .= " $dc_vars->{CONFIGURATION}";
2552 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD} --realm=$dc_vars->{DC_REALM}";
2553 # replicate Configuration NC
2554 my $cmd_repl = "$cmd \"$config_dn\"";
2555 unless(system($cmd_repl) == 0) {
2556 warn("Failed to replicate\n$cmd_repl");
2559 # replicate Default NC
2560 $cmd_repl = "$cmd \"$base_dn\"";
2561 unless(system($cmd_repl) == 0) {
2562 warn("Failed to replicate\n$cmd_repl");
2572 my ($self, $path, $dc_vars) = @_;
2574 my $env = $self->provision_rodc($path, $dc_vars);
2580 if (not defined($self->check_or_start($env, "standard"))) {
2584 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2587 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2588 $cmd .= "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2589 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2590 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2591 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2592 $cmd .= "RESOLV_CONF=\"$env->{RESOLV_CONF}\" ";
2593 $cmd .= " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}";
2594 $cmd .= " $dc_vars->{CONFIGURATION}";
2595 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2596 # replicate Configuration NC
2597 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2598 unless(system($cmd_repl) == 0) {
2599 warn("Failed to replicate\n$cmd_repl");
2602 # replicate Default NC
2603 $cmd_repl = "$cmd \"$base_dn\"";
2604 unless(system($cmd_repl) == 0) {
2605 warn("Failed to replicate\n$cmd_repl");
2614 my ($self, $path) = @_;
2616 # If we didn't build with ADS, pretend this env was never available
2617 if (not $self->{target3}->have_ads()) {
2621 my $env = $self->provision_ad_dc($path, "addc", "ADDOMAIN",
2622 "addom.samba.example.com", "", undef);
2627 if (not defined($self->check_or_start($env, "prefork"))) {
2631 my $upn_array = ["$env->{REALM}.upn"];
2632 my $spn_array = ["$env->{REALM}.spn"];
2634 $self->setup_namespaces($env, $upn_array, $spn_array);
2639 sub setup_ad_dc_no_nss
2641 my ($self, $path) = @_;
2643 # If we didn't build with ADS, pretend this env was never available
2644 if (not $self->{target3}->have_ads()) {
2648 my $env = $self->provision_ad_dc($path, "addc_no_nss", "ADNONSSDOMAIN",
2649 "adnonssdom.samba.example.com", "", undef);
2654 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2655 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2657 if (not defined($self->check_or_start($env, "single"))) {
2661 my $upn_array = ["$env->{REALM}.upn"];
2662 my $spn_array = ["$env->{REALM}.spn"];
2664 $self->setup_namespaces($env, $upn_array, $spn_array);
2669 sub setup_ad_dc_no_ntlm
2671 my ($self, $path) = @_;
2673 # If we didn't build with ADS, pretend this env was never available
2674 if (not $self->{target3}->have_ads()) {
2678 my $env = $self->provision_ad_dc($path, "addc_no_ntlm", "ADNONTLMDOMAIN",
2679 "adnontlmdom.samba.example.com",
2680 "ntlm auth = disabled", undef);
2685 if (not defined($self->check_or_start($env, "prefork"))) {
2689 my $upn_array = ["$env->{REALM}.upn"];
2690 my $spn_array = ["$env->{REALM}.spn"];
2692 $self->setup_namespaces($env, $upn_array, $spn_array);
2698 # AD DC test environment used solely to test pre-fork process restarts.
2699 # As processes get killed off and restarted it should not be used for other
2700 sub setup_preforkrestartdc
2702 my ($self, $path) = @_;
2704 # If we didn't build with ADS, pretend this env was never available
2705 if (not $self->{target3}->have_ads()) {
2709 # note DC name must be <= 15 chars so we use 'prockill' instead of
2711 my $env = $self->provision_ad_dc(
2715 "prockilldom.samba.example.com",
2716 "prefork backoff increment = 5\nprefork maximum backoff=10");
2721 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2722 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2724 if (not defined($self->check_or_start($env, "prefork"))) {
2728 my $upn_array = ["$env->{REALM}.upn"];
2729 my $spn_array = ["$env->{REALM}.spn"];
2731 $self->setup_namespaces($env, $upn_array, $spn_array);
2737 # ad_dc test environment used solely to test standard process model connection
2738 # process limits. As the limit is set artificially low it should not be used
2740 sub setup_proclimitdc
2742 my ($self, $path) = @_;
2744 # If we didn't build with ADS, pretend this env was never available
2745 if (not $self->{target3}->have_ads()) {
2749 my $env = $self->provision_ad_dc(
2753 "proclimit.samba.example.com",
2754 "max smbd processes = 20");
2759 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2760 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2762 if (not defined($self->check_or_start($env, "standard"))) {
2766 my $upn_array = ["$env->{REALM}.upn"];
2767 my $spn_array = ["$env->{REALM}.spn"];
2769 $self->setup_namespaces($env, $upn_array, $spn_array);
2774 # Used to test a live upgrade of the schema on a 2 DC network.
2777 my ($self, $path) = @_;
2779 # provision the PDC using an older base schema
2780 my $provision_args = ["--base-schema=2008_R2", "--backend-store=mdb"];
2782 my $env = $self->provision_ad_dc($path, "liveupgrade1dc", "SCHEMADOMAIN",
2783 "schema.samba.example.com",
2784 "drs: max link sync = 2",
2790 if (not defined($self->check_or_start($env, "prefork"))) {
2794 my $upn_array = ["$env->{REALM}.upn"];
2795 my $spn_array = ["$env->{REALM}.spn"];
2797 $self->setup_namespaces($env, $upn_array, $spn_array);
2802 # the second DC in the live schema upgrade pair
2803 sub setup_schema_pair_dc
2805 # note: dcvars contains the env info for the dependent testenv ('schema_dc')
2806 my ($self, $prefix, $dcvars) = @_;
2807 print "Preparing SCHEMA UPGRADE PAIR DC...\n";
2809 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "liveupgrade2dc",
2812 $dcvars->{PASSWORD},
2815 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2816 my $cmd_vars = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2817 $cmd_vars .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2818 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2819 $cmd_vars .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2821 $cmd_vars .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2823 $cmd_vars .= "KRB5_CONFIG=\"$env->{KRB5_CONFIG}\" ";
2824 $cmd_vars .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2825 $cmd_vars .= "RESOLV_CONF=\"$env->{RESOLV_CONF}\" ";
2827 my $join_cmd = $cmd_vars;
2828 $join_cmd .= "$samba_tool domain join $env->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
2829 $join_cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} ";
2830 $join_cmd .= " --backend-store=mdb";
2832 my $upgrade_cmd = $cmd_vars;
2833 $upgrade_cmd .= "$samba_tool domain schemaupgrade $dcvars->{CONFIGURATION}";
2834 $upgrade_cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}";
2836 my $repl_cmd = $cmd_vars;
2837 $repl_cmd .= "$samba_tool drs replicate $env->{SERVER} $dcvars->{SERVER}";
2838 $repl_cmd .= " CN=Schema,CN=Configuration,DC=schema,DC=samba,DC=example,DC=com";
2839 $repl_cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
2841 unless (system($join_cmd) == 0) {
2842 warn("Join failed\n$join_cmd");
2846 $env->{DC_SERVER} = $dcvars->{SERVER};
2847 $env->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
2848 $env->{DC_SERVER_IPV6} = $dcvars->{SERVER_IPV6};
2849 $env->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
2851 # start samba for the new DC
2852 if (not defined($self->check_or_start($env, "standard"))) {
2856 unless (system($upgrade_cmd) == 0) {
2857 warn("Schema upgrade failed\n$upgrade_cmd");
2861 unless (system($repl_cmd) == 0) {
2862 warn("Post-update schema replication failed\n$repl_cmd");
2869 # Sets up a DC that's solely used to do a domain backup from. We then use the
2870 # backupfrom-DC to create the restore-DC - this proves that the backup/restore
2871 # process will create a Samba DC that will actually start up.
2872 # We don't use the backup-DC for anything else because its domain will conflict
2873 # with the restore DC.
2874 sub setup_backupfromdc
2876 my ($self, $path) = @_;
2878 # If we didn't build with ADS, pretend this env was never available
2879 if (not $self->{target3}->have_ads()) {
2883 my $provision_args = ["--site=Backup-Site"];
2885 my $env = $self->provision_ad_dc($path, "backupfromdc", "BACKUPDOMAIN",
2886 "backupdom.samba.example.com",
2887 "samba kcc command = /bin/true",
2893 if (not defined($self->check_or_start($env))) {
2897 my $upn_array = ["$env->{REALM}.upn"];
2898 my $spn_array = ["$env->{REALM}.spn"];
2900 $self->setup_namespaces($env, $upn_array, $spn_array);
2905 # returns the server/user-auth params needed to run an online backup cmd
2906 sub get_backup_server_args
2908 # dcvars contains the env info for the backup DC testenv
2909 my ($self, $dcvars) = @_;
2910 my $server = $dcvars->{DC_SERVER_IP};
2911 my $server_args = "--server=$server ";
2912 $server_args .= "-U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
2913 $server_args .= " $dcvars->{CONFIGURATION}";
2915 return $server_args;
2918 # Creates a backup of a running testenv DC
2921 # note: dcvars contains the env info for the backup DC testenv
2922 my ($self, $env, $dcvars, $backupdir, $backup_cmd) = @_;
2924 # get all the env variables we pass in with the samba-tool command
2925 my $cmd_env = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2926 $cmd_env .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2927 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2928 $cmd_env .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2930 $cmd_env .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2932 # Note: use the backupfrom-DC's krb5.conf to do the backup
2933 $cmd_env .= " KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
2934 $cmd_env .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2936 # use samba-tool to create a backup from the 'backupfromdc' DC
2938 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2940 $cmd .= "$cmd_env $samba_tool domain backup $backup_cmd";
2941 $cmd .= " --targetdir=$backupdir";
2943 print "Executing: $cmd\n";
2944 unless(system($cmd) == 0) {
2945 warn("Failed to create backup using: \n$cmd");
2949 # get the name of the backup file created
2950 opendir(DIR, $backupdir);
2951 my @files = grep(/\.tar/, readdir(DIR));
2954 if(scalar @files != 1) {
2955 warn("Backup file not found in directory $backupdir\n");
2958 my $backup_file = "$backupdir/$files[0]";
2959 print "Using backup file $backup_file...\n";
2961 return $backup_file;
2964 # Restores a backup-file to populate a testenv for a new DC
2965 sub restore_backup_file
2967 my ($self, $backup_file, $restore_opts, $restoredir, $smbconf) = @_;
2969 # pass the restore command the testenv's smb.conf that we've already
2970 # generated. But move it to a temp-dir first, so that the restore doesn't
2972 my $tmpdir = File::Temp->newdir();
2973 my $tmpconf = "$tmpdir/smb.conf";
2974 my $cmd = "cp $smbconf $tmpconf";
2975 unless(system($cmd) == 0) {
2976 warn("Failed to backup smb.conf using: \n$cmd");
2980 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2981 $cmd = "$samba_tool domain backup restore --backup-file=$backup_file";
2982 $cmd .= " --targetdir=$restoredir $restore_opts --configfile=$tmpconf";
2984 print "Executing: $cmd\n";
2985 unless(system($cmd) == 0) {
2986 warn("Failed to restore backup using: \n$cmd");
2990 print "Restore complete\n";
2994 # sets up the initial directory and returns the new testenv's env info
2995 # (without actually doing a 'domain join')
2996 sub prepare_dc_testenv
2998 my ($self, $prefix, $dcname, $domain, $realm,
2999 $password, $conf_options) = @_;
3001 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
3011 # the restore uses a slightly different state-dir location to other testenvs
3012 $ctx->{statedir} = "$ctx->{prefix_abs}/state";
3013 push(@{$ctx->{directories}}, "$ctx->{statedir}");
3015 # add support for sysvol/netlogon/tmp shares
3016 $ctx->{share} = "$ctx->{prefix_abs}/share";
3017 push(@{$ctx->{directories}}, "$ctx->{share}");
3018 push(@{$ctx->{directories}}, "$ctx->{share}/test1");
3020 $ctx->{smb_conf_extra_options} = "
3023 server max protocol = SMB2
3024 samba kcc command = /bin/true
3025 xattr_tdb:file = $ctx->{statedir}/xattr.tdb
3028 path = $ctx->{statedir}/sysvol
3032 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
3036 path = $ctx->{share}
3038 posix:sharedelay = 10000
3039 posix:oplocktimeout = 3
3040 posix:writetimeupdatedelay = 50000
3043 path = $ctx->{share}/test1
3045 posix:sharedelay = 100000
3046 posix:oplocktimeout = 3
3047 posix:writetimeupdatedelay = 500000
3050 my $env = $self->provision_raw_step1($ctx);
3052 return ($env, $ctx);
3056 # Set up a DC testenv solely by using the samba-tool domain backup/restore
3057 # commands. This proves that we can backup an online DC ('backupfromdc') and
3058 # use the backup file to create a valid, working samba DC.
3061 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
3062 my ($self, $prefix, $dcvars) = @_;
3063 print "Preparing RESTORE DC...\n";
3065 # we arbitrarily designate the restored DC as having SMBv1 disabled
3067 server min protocol = SMB2
3068 client min protocol = SMB2
3069 prefork children = 1";
3071 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "restoredc",
3074 $dcvars->{PASSWORD},
3077 # create a backup of the 'backupfromdc'
3078 my $backupdir = File::Temp->newdir();
3079 my $server_args = $self->get_backup_server_args($dcvars);
3080 my $backup_args = "online $server_args";
3081 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
3083 unless($backup_file) {
3087 # restore the backup file to populate the restore-DC testenv
3088 my $restore_dir = abs_path($prefix);
3089 my $ret = $self->restore_backup_file($backup_file,
3090 "--newservername=$env->{SERVER}",
3091 $restore_dir, $env->{SERVERCONFFILE});
3092 unless ($ret == 0) {
3096 # start samba for the restored DC
3097 if (not defined($self->check_or_start($env))) {
3104 # Set up a DC testenv solely by using the 'samba-tool domain backup rename' and
3105 # restore commands. This proves that we can backup and rename an online DC
3106 # ('backupfromdc') and use the backup file to create a valid, working samba DC.
3109 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
3110 my ($self, $prefix, $dcvars) = @_;
3111 print "Preparing RENAME DC...\n";
3112 my $extra_conf = "prefork children = 1";
3114 my $realm = "renamedom.samba.example.com";
3115 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "renamedc",
3116 "RENAMEDOMAIN", $realm,
3117 $dcvars->{PASSWORD}, $extra_conf);
3119 # create a backup of the 'backupfromdc' which renames the domain
3120 my $backupdir = File::Temp->newdir();
3121 my $server_args = $self->get_backup_server_args($dcvars);
3122 my $backup_args = "rename $env->{DOMAIN} $env->{REALM} $server_args";
3123 $backup_args .= " --backend-store=tdb";
3124 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
3126 unless($backup_file) {
3130 # restore the backup file to populate the rename-DC testenv
3131 my $restore_dir = abs_path($prefix);
3132 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
3133 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
3134 $restore_dir, $env->{SERVERCONFFILE});
3135 unless ($ret == 0) {
3139 # start samba for the restored DC
3140 if (not defined($self->check_or_start($env))) {
3144 my $upn_array = ["$env->{REALM}.upn"];
3145 my $spn_array = ["$env->{REALM}.spn"];
3147 $self->setup_namespaces($env, $upn_array, $spn_array);
3152 # Set up a DC testenv solely by using the 'samba-tool domain backup offline' and
3153 # restore commands. This proves that we do an offline backup of a local DC
3154 # ('backupfromdc') and use the backup file to create a valid, working samba DC.
3155 sub setup_offlinebackupdc
3157 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
3158 my ($self, $prefix, $dcvars) = @_;
3159 print "Preparing OFFLINE BACKUP DC...\n";
3160 my $extra_conf = "prefork children = 1";
3162 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "offlinebackupdc",
3165 $dcvars->{PASSWORD}, $extra_conf);
3167 # create an offline backup of the 'backupfromdc' target
3168 my $backupdir = File::Temp->newdir();
3169 my $cmd = "offline -s $dcvars->{SERVERCONFFILE}";
3170 my $backup_file = $self->create_backup($env, $dcvars,
3173 unless($backup_file) {
3177 # restore the backup file to populate the rename-DC testenv
3178 my $restore_dir = abs_path($prefix);
3179 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
3180 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
3181 $restore_dir, $env->{SERVERCONFFILE});
3182 unless ($ret == 0) {
3186 # re-create the testenv's krb5.conf (the restore may have overwritten it)
3187 Samba::mk_krb5_conf($ctx);
3189 # start samba for the restored DC
3190 if (not defined($self->check_or_start($env))) {
3197 # Set up a DC testenv solely by using the samba-tool 'domain backup rename' and
3198 # restore commands, using the --no-secrets option. This proves that we can
3199 # create a realistic lab environment from an online DC ('backupfromdc').
3202 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
3203 my ($self, $prefix, $dcvars) = @_;
3204 print "Preparing LAB-DOMAIN DC...\n";
3205 my $extra_conf = "prefork children = 1";
3207 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "labdc",
3209 "labdom.samba.example.com",
3210 $dcvars->{PASSWORD}, $extra_conf);
3212 # create a backup of the 'backupfromdc' which renames the domain and uses
3213 # the --no-secrets option to scrub any sensitive info
3214 my $backupdir = File::Temp->newdir();
3215 my $server_args = $self->get_backup_server_args($dcvars);
3216 my $backup_args = "rename $env->{DOMAIN} $env->{REALM} $server_args";
3217 $backup_args .= " --no-secrets --backend-store=mdb";
3218 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
3220 unless($backup_file) {
3224 # restore the backup file to populate the lab-DC testenv
3225 my $restore_dir = abs_path($prefix);
3226 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
3227 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
3228 $restore_dir, $env->{SERVERCONFFILE});
3229 unless ($ret == 0) {
3233 # because we don't include any secrets in the backup, we need to reset the
3234 # admin user's password back to what the testenv expects
3235 my $samba_tool = Samba::bindir_path($self, "samba-tool");
3236 my $cmd = "$samba_tool user setpassword $env->{USERNAME} ";
3237 $cmd .= "--newpassword=$env->{PASSWORD} -H $restore_dir/private/sam.ldb";
3238 $cmd .= " $env->{CONFIGURATION}";
3240 unless(system($cmd) == 0) {
3241 warn("Failed to reset admin's password: \n$cmd");
3245 # start samba for the restored DC
3246 if (not defined($self->check_or_start($env))) {
3250 my $upn_array = ["$env->{REALM}.upn"];
3251 my $spn_array = ["$env->{REALM}.spn"];
3253 $self->setup_namespaces($env, $upn_array, $spn_array);
3258 # Inspects a backup *.tar.bz2 file and determines the realm/domain it contains
3259 sub get_backup_domain_realm
3261 my ($self, $backup_file) = @_;
3263 print "Determining REALM/DOMAIN values in backup...\n";
3265 # The backup will have the correct domain/realm values in the smb.conf.
3266 # So we can work out the env variables the testenv should use based on
3267 # that. Let's start by extracting the smb.conf
3268 my $tar = Archive::Tar->new($backup_file);
3269 my $tmpdir = File::Temp->newdir();
3270 my $smbconf = "$tmpdir/smb.conf";
3272 # note that the filepaths within the tar-file differ slightly for online
3273 # and offline backups
3274 if ($tar->contains_file("etc/smb.conf")) {
3275 $tar->extract_file("etc/smb.conf", $smbconf);
3276 } elsif ($tar->contains_file("./etc/smb.conf")) {
3277 $tar->extract_file("./etc/smb.conf", $smbconf);
3279 warn("Could not find smb.conf in $backup_file");
3280 return undef, undef;
3283 # make sure we don't try to create locks/sockets in the default install
3284 # location (i.e. /usr/local/samba/)
3285 my $options = "--option=\"private dir = $tmpdir\"";
3286 $options .= " --option=\"lock dir = $tmpdir\"";
3288 # now use testparm to read the values we're interested in
3289 my $testparm = Samba::bindir_path($self, "testparm");
3290 my $domain = `$testparm $smbconf -sl --parameter-name=WORKGROUP $options`;
3291 my $realm = `$testparm $smbconf -sl --parameter-name=REALM $options`;
3294 print "Backup-file REALM is $realm, DOMAIN is $domain\n";
3296 return ($domain, $realm);
3299 # This spins up a custom testenv that can be based on any backup-file you want.
3300 # This is just intended for manual testing (rather than automated test-cases)
3303 my ($self, $prefix) = @_;
3304 print "Preparing CUSTOM RESTORE DC...\n";
3305 my $dc_name = "customdc";
3306 my $password = "locDCpass1";
3307 my $backup_file = $ENV{'BACKUP_FILE'};
3309 # user must specify a backup file to restore via an ENV variable, i.e.
3310 # BACKUP_FILE=backup-blah.tar.bz2 SELFTEST_TESTENV=customdc make testenv
3311 if (not defined($backup_file)) {
3312 warn("Please specify BACKUP_FILE");
3316 # work out the correct domain/realm env values from the backup-file
3317 my ($domain, $realm) = $self->get_backup_domain_realm($backup_file);
3318 if ($domain eq '' or $realm eq '') {
3319 warn("Could not determine domain or realm");
3323 # create a placeholder directory and smb.conf, as well as the env vars.
3324 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, $dc_name,
3325 $domain, $realm, $password, "");
3327 # restore the specified backup file to populate the testenv
3328 my $restore_dir = abs_path($prefix);
3329 my $ret = $self->restore_backup_file($backup_file,
3330 "--newservername=$env->{SERVER}",
3331 $restore_dir, $env->{SERVERCONFFILE});
3332 unless ($ret == 0) {
3336 # Change the admin password to the testenv default, just in case it's
3337 # different, or in case this was a --no-secrets backup
3338 my $samba_tool = Samba::bindir_path($self, "samba-tool");
3339 my $cmd = "$samba_tool user setpassword $env->{USERNAME} ";
3340 $cmd .= "--newpassword=$password -H $restore_dir/private/sam.ldb";
3341 $cmd .= " $env->{CONFIGURATION}";
3343 unless(system($cmd) == 0) {
3344 warn("Failed to reset admin's password: \n$cmd");
3348 # re-create the testenv's krb5.conf (the restore may have overwritten it,
3349 # if the backup-file was an offline backup)
3350 Samba::mk_krb5_conf($ctx);
3352 # start samba for the restored DC
3353 if (not defined($self->check_or_start($env))) {
3357 # if this was a backup-rename, then we may need to setup namespaces
3358 my $upn_array = ["$env->{REALM}.upn"];
3359 my $spn_array = ["$env->{REALM}.spn"];
3361 $self->setup_namespaces($env, $upn_array, $spn_array);
3368 my ($self, $path) = @_;
3371 KRB5_CONFIG => abs_path($path) . "/no_krb5.conf",