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.
14 use FindBin qw($RealBin);
20 use File::Path 'make_path';
23 my ($classname, $bindir, $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 check_or_start($$$)
43 my ($self, $env_vars, $process_model) = @_;
46 my $env_ok = $self->check_env($env_vars);
48 return $env_vars->{SAMBA_PID};
49 } elsif (defined($env_vars->{SAMBA_PID})) {
50 warn("SAMBA PID $env_vars->{SAMBA_PID} is not running (died)");
54 # use a pipe for stdin in the child processes. This allows
55 # those processes to monitor the pipe for EOF to ensure they
56 # exit when the test script exits
57 pipe($STDIN_READER, $env_vars->{STDIN_PIPE});
59 # build up the command to run samba
62 if (defined($ENV{SAMBA_OPTIONS})) {
63 @optargs = split(/ /, $ENV{SAMBA_OPTIONS});
65 if(defined($ENV{SAMBA_VALGRIND})) {
66 @preargs = split(/ /,$ENV{SAMBA_VALGRIND});
69 if (defined($process_model)) {
70 push @optargs, ("-M", $process_model);
72 my $binary = Samba::bindir_path($self, "samba");
73 my @full_cmd = (@preargs, $binary, "-i",
74 "--no-process-group", "--maximum-runtime=$self->{server_maxtime}",
75 $env_vars->{CONFIGURATION}, @optargs);
77 # the samba process takes some additional env variables (compared to s3)
78 my $samba_envs = Samba::get_env_for_process("samba", $env_vars);
79 $samba_envs->{RESOLV_CONF} = $env_vars->{RESOLV_CONF};
80 $samba_envs->{UID_WRAPPER} = "1";
81 if (defined($ENV{MITKRB5})) {
82 $samba_envs->{KRB5_KDC_PROFILE} = $env_vars->{MITKDC_CONFIG};
85 # fork a child process and exec() samba
88 BINARY_PATH => $binary,
89 FULL_CMD => [ @full_cmd ],
90 LOG_FILE => $env_vars->{SAMBA_TEST_LOG},
92 ENV_VARS => $samba_envs,
94 my $pid = Samba::fork_and_exec($self, $env_vars, $daemon_ctx, $STDIN_READER);
96 $env_vars->{SAMBA_PID} = $pid;
98 # close the parent's read-end of the pipe
101 if ($self->wait_for_start($env_vars) != 0) {
102 warn("Samba $pid failed to start up");
109 sub wait_for_start($$)
111 my ($self, $testenv_vars) = @_;
115 if (not $self->check_env($testenv_vars)) {
116 warn("unable to confirm Samba $testenv_vars->{SAMBA_PID} is running");
120 # This will return quickly when things are up, but be slow if we
121 # need to wait for (eg) SSL init
122 my $nmblookup = Samba::bindir_path($self, "nmblookup4");
125 $ret = system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
129 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
130 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
131 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
132 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
133 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
134 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
135 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
136 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
137 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
138 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
139 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
142 } while ($ret != 0 && $count < 20);
144 teardown_env($self, $testenv_vars);
145 warn("nbt not reachable after 20 retries\n");
149 # Ensure we have the first RID Set before we start tests. This makes the tests more reliable.
150 if ($testenv_vars->{SERVER_ROLE} eq "domain controller") {
151 print "waiting for working LDAP and a RID Set to be allocated\n";
152 my $ldbsearch = Samba::bindir_path($self, "ldbsearch");
154 my $base_dn = "DC=".join(",DC=", split(/\./, $testenv_vars->{REALM}));
156 my $search_dn = $base_dn;
157 if ($testenv_vars->{NETBIOSNAME} ne "RODC") {
158 # TODO currently no check for actual rIDAllocationPool
159 $search_dn = "cn=RID Set,cn=$testenv_vars->{NETBIOSNAME},ou=domain controllers,$base_dn";
163 # Add hosts file for name lookups
164 my $cmd = "NSS_WRAPPER_HOSTS='$testenv_vars->{NSS_WRAPPER_HOSTS}' ";
165 if (defined($testenv_vars->{RESOLV_WRAPPER_CONF})) {
166 $cmd .= "RESOLV_WRAPPER_CONF='$testenv_vars->{RESOLV_WRAPPER_CONF}' ";
168 $cmd .= "RESOLV_WRAPPER_HOSTS='$testenv_vars->{RESOLV_WRAPPER_HOSTS}' ";
170 $cmd .= "RESOLV_CONF='$testenv_vars->{RESOLV_CONF}' ";
172 $cmd .= "$ldbsearch ";
173 $cmd .= "$testenv_vars->{CONFIGURATION} ";
174 $cmd .= "-H ldap://$testenv_vars->{SERVER} ";
175 $cmd .= "-U$testenv_vars->{USERNAME}%$testenv_vars->{PASSWORD} ";
177 $cmd .= "-b '$search_dn' ";
178 while (system("$cmd >/dev/null") != 0) {
180 if ($count > $max_wait) {
181 teardown_env($self, $testenv_vars);
182 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}");
185 print "Waiting for working LDAP...\n";
190 my $wbinfo = Samba::bindir_path($self, "wbinfo");
194 my $cmd = "NSS_WRAPPER_PASSWD=$testenv_vars->{NSS_WRAPPER_PASSWD} ";
195 $cmd .= "NSS_WRAPPER_GROUP=$testenv_vars->{NSS_WRAPPER_GROUP} ";
196 $cmd .= "SELFTEST_WINBINDD_SOCKET_DIR=$testenv_vars->{SELFTEST_WINBINDD_SOCKET_DIR} ";
197 $cmd .= "$wbinfo -P";
204 } while ($ret != 0 && $count < 20);
206 teardown_env($self, $testenv_vars);
207 warn("winbind not reachable after 20 retries\n");
211 # Ensure we registered all our names
212 if ($testenv_vars->{SERVER_ROLE} eq "domain controller") {
214 print "Waiting for dns_update_cache to be created.\n";
216 while (not -e "$testenv_vars->{PRIVATEDIR}/dns_update_cache") {
218 if ($count > $max_wait) {
219 teardown_env($self, $testenv_vars);
220 warn("Timed out ($max_wait sec) waiting for dns_update_cache PID $testenv_vars->{SAMBA_PID}");
223 print "Waiting for dns_update_cache to be created...\n";
226 print "Waiting for dns_update_cache to be filled.\n";
228 while ((-s "$testenv_vars->{PRIVATEDIR}/dns_update_cache") == 0) {
230 if ($count > $max_wait) {
231 teardown_env($self, $testenv_vars);
232 warn("Timed out ($max_wait sec) waiting for dns_update_cache PID $testenv_vars->{SAMBA_PID}");
235 print "Waiting for dns_update_cache to be filled...\n";
240 print $self->getlog_env($testenv_vars);
242 print "READY ($testenv_vars->{SAMBA_PID})\n";
247 sub write_ldb_file($$$)
249 my ($self, $file, $ldif) = @_;
251 my $ldbadd = Samba::bindir_path($self, "ldbadd");
252 open(LDIF, "|$ldbadd -H $file >/dev/null");
257 sub add_wins_config($$)
259 my ($self, $privatedir) = @_;
260 my $client_ip = Samba::get_ipv4_addr("client");
262 return $self->write_ldb_file("$privatedir/wins_config.ldb", "
263 dn: name=TORTURE_11,CN=PARTNERS
264 objectClass: wreplPartner
273 sub setup_dns_hub_internal($$$)
275 my ($self, $hostname, $prefix) = @_;
278 unless(-d $prefix or make_path($prefix, 0777)) {
279 warn("Unable to create $prefix");
282 my $prefix_abs = abs_path($prefix);
284 die ("prefix=''") if $prefix_abs eq "";
285 die ("prefix='/'") if $prefix_abs eq "/";
287 unless (system("rm -rf $prefix_abs/*") == 0) {
288 warn("Unable to clean up");
292 $env->{NETBIOSNAME} = $hostname;
294 $env->{SERVER_IP} = Samba::get_ipv4_addr($hostname);
295 $env->{SERVER_IPV6} = Samba::get_ipv6_addr($hostname);
296 $env->{SOCKET_WRAPPER_DEFAULT_IFACE} = Samba::get_interface($hostname);
297 $env->{DNS_HUB_LOG} = "$prefix_abs/dns_hub.log";
298 $env->{RESOLV_CONF} = "$prefix_abs/resolv.conf";
299 $env->{TESTENV_DIR} = $prefix_abs;
301 open(RESOLV_CONF, ">$env->{RESOLV_CONF}");
302 print RESOLV_CONF "nameserver $env->{SERVER_IP}\n";
303 print RESOLV_CONF "nameserver $env->{SERVER_IPV6}\n";
308 if (!defined($ENV{PYTHON})) {
309 push (@preargs, "env");
310 push (@preargs, "python");
312 push (@preargs, $ENV{PYTHON});
314 my $binary = "$self->{srcdir}/selftest/target/dns_hub.py";
315 push (@args, "$self->{server_maxtime}");
316 push (@args, "$env->{SERVER_IP}");
317 push (@args, Samba::realm_to_ip_mappings());
318 my @full_cmd = (@preargs, $binary, @args);
322 BINARY_PATH => $binary,
323 FULL_CMD => [ @full_cmd ],
324 LOG_FILE => $env->{DNS_HUB_LOG},
329 my $pcap_dir = $ENV{SOCKET_WRAPPER_PCAP_DIR};
330 if (defined $pcap_dir) {
331 $daemon_ctx->{PCAP_FILE} = "$pcap_dir/env-$hostname$.pcap",
334 # use a pipe for stdin in the child processes. This allows
335 # those processes to monitor the pipe for EOF to ensure they
336 # exit when the test script exits
337 pipe($STDIN_READER, $env->{STDIN_PIPE});
339 my $pid = Samba::fork_and_exec($self, $env, $daemon_ctx, $STDIN_READER);
341 $env->{SAMBA_PID} = $pid;
342 $env->{KRB5_CONFIG} = "$prefix_abs/no_krb5.conf";
344 # close the parent's read-end of the pipe
345 close($STDIN_READER);
352 my ($self, $prefix) = @_;
354 my $hostname = "rootdnsforwarder";
356 my $env = $self->setup_dns_hub_internal("$hostname", "$prefix/$hostname");
358 $self->{dns_hub_env} = $env;
363 sub get_dns_hub_env($)
365 my ($self, $prefix) = @_;
367 if (defined($self->{dns_hub_env})) {
368 return $self->{dns_hub_env};
371 die("get_dns_hub_env() not setup 'dns_hub_env'");
375 # Returns the environmental variables that we pass to samba-tool commands
378 my ($self, $localenv) = @_;
380 my $cmd_env = "NSS_WRAPPER_HOSTS='$localenv->{NSS_WRAPPER_HOSTS}' ";
381 $cmd_env .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$localenv->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
382 if (defined($localenv->{RESOLV_WRAPPER_CONF})) {
383 $cmd_env .= "RESOLV_WRAPPER_CONF=\"$localenv->{RESOLV_WRAPPER_CONF}\" ";
385 $cmd_env .= "RESOLV_WRAPPER_HOSTS=\"$localenv->{RESOLV_WRAPPER_HOSTS}\" ";
387 $cmd_env .= " KRB5_CONFIG=\"$localenv->{KRB5_CONFIG}\" ";
388 $cmd_env .= "KRB5CCNAME=\"$localenv->{KRB5_CCACHE}\" ";
389 $cmd_env .= "RESOLV_CONF=\"$localenv->{RESOLV_CONF}\" ";
394 # Sets up a forest trust namespace.
395 # (Note this is different to kernel namespaces, setup by the
396 # USE_NAMESPACES=1 option)
399 my ($self, $localenv, $upn_array, $spn_array) = @_;
401 @{$upn_array} = [] unless defined($upn_array);
403 foreach my $upn (@{$upn_array}) {
404 $upn_args .= " --add-upn-suffix=$upn";
407 @{$spn_array} = [] unless defined($spn_array);
409 foreach my $spn (@{$spn_array}) {
410 $spn_args .= " --add-spn-suffix=$spn";
413 my $samba_tool = Samba::bindir_path($self, "samba-tool");
415 my $cmd_env = $self->get_cmd_env_vars($localenv);
417 my $cmd_config = " $localenv->{CONFIGURATION}";
419 my $namespaces = $cmd_env;
420 $namespaces .= " $samba_tool domain trust namespaces $upn_args $spn_args";
421 $namespaces .= $cmd_config;
422 unless (system($namespaces) == 0) {
423 warn("Failed to add namespaces \n$namespaces");
430 sub setup_trust($$$$$)
432 my ($self, $localenv, $remoteenv, $type, $extra_args) = @_;
434 $localenv->{TRUST_SERVER} = $remoteenv->{SERVER};
436 $localenv->{TRUST_USERNAME} = $remoteenv->{USERNAME};
437 $localenv->{TRUST_PASSWORD} = $remoteenv->{PASSWORD};
438 $localenv->{TRUST_DOMAIN} = $remoteenv->{DOMAIN};
439 $localenv->{TRUST_REALM} = $remoteenv->{REALM};
440 $localenv->{TRUST_DOMSID} = $remoteenv->{DOMSID};
442 my $samba_tool = Samba::bindir_path($self, "samba-tool");
445 my $cmd_env = $self->get_cmd_env_vars($localenv);
447 my $cmd_config = " $localenv->{CONFIGURATION}";
448 my $cmd_creds = $cmd_config;
449 $cmd_creds .= " -U$localenv->{TRUST_DOMAIN}\\\\$localenv->{TRUST_USERNAME}\%$localenv->{TRUST_PASSWORD}";
451 my $create = $cmd_env;
452 $create .= " $samba_tool domain trust create --type=${type} $localenv->{TRUST_REALM}";
453 $create .= " $extra_args";
454 $create .= $cmd_creds;
455 unless (system($create) == 0) {
456 warn("Failed to create trust \n$create");
460 my $groupname = "g_$localenv->{TRUST_DOMAIN}";
461 my $groupadd = $cmd_env;
462 $groupadd .= " $samba_tool group add '$groupname' --group-scope=Domain $cmd_config";
463 unless (system($groupadd) == 0) {
464 warn("Failed to create group \n$groupadd");
467 my $groupmem = $cmd_env;
468 $groupmem .= " $samba_tool group addmembers '$groupname' '$localenv->{TRUST_DOMSID}-513' $cmd_config";
469 unless (system($groupmem) == 0) {
470 warn("Failed to add group member \n$groupmem");
477 sub provision_raw_prepare($$$$$$$$$$$$)
479 my ($self, $prefix, $server_role, $hostname,
480 $domain, $realm, $samsid, $functional_level,
481 $password, $kdc_ipv4, $kdc_ipv6) = @_;
484 if (defined $ENV{PYTHON}) {
485 $python_cmd = $ENV{PYTHON} . " ";
487 $ctx->{python} = $python_cmd;
488 my $netbiosname = uc($hostname);
490 unless(-d $prefix or mkdir($prefix, 0777)) {
491 warn("Unable to create $prefix");
494 my $prefix_abs = abs_path($prefix);
496 die ("prefix=''") if $prefix_abs eq "";
497 die ("prefix='/'") if $prefix_abs eq "/";
499 unless (system("rm -rf $prefix_abs/*") == 0) {
500 warn("Unable to clean up");
504 my $swiface = Samba::get_interface($hostname);
506 $ctx->{prefix} = $prefix;
507 $ctx->{prefix_abs} = $prefix_abs;
509 $ctx->{server_role} = $server_role;
510 $ctx->{hostname} = $hostname;
511 $ctx->{netbiosname} = $netbiosname;
512 $ctx->{swiface} = $swiface;
513 $ctx->{password} = $password;
514 $ctx->{kdc_ipv4} = $kdc_ipv4;
515 $ctx->{kdc_ipv6} = $kdc_ipv6;
516 $ctx->{krb5_ccname} = "$prefix_abs/krb5cc_%{uid}";
517 if ($functional_level eq "2000") {
518 $ctx->{supported_enctypes} = "arcfour-hmac-md5 des-cbc-md5 des-cbc-crc"
522 # Set smbd log level here.
524 $ctx->{server_loglevel} =$ENV{SERVER_LOG_LEVEL} || 1;
525 $ctx->{username} = "Administrator";
526 $ctx->{domain} = $domain;
527 $ctx->{realm} = uc($realm);
528 $ctx->{dnsname} = lc($realm);
529 $ctx->{samsid} = $samsid;
531 $ctx->{functional_level} = $functional_level;
533 my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `whoami`);
535 $ctx->{unix_name} = $unix_name;
536 $ctx->{unix_uid} = $>;
537 my @mygid = split(" ", $();
538 $ctx->{unix_gid} = $mygid[0];
539 $ctx->{unix_gids_str} = $);
540 @{$ctx->{unix_gids}} = split(" ", $ctx->{unix_gids_str});
542 $ctx->{etcdir} = "$prefix_abs/etc";
543 $ctx->{piddir} = "$prefix_abs/pid";
544 $ctx->{smb_conf} = "$ctx->{etcdir}/smb.conf";
545 $ctx->{krb5_conf} = "$ctx->{etcdir}/krb5.conf";
546 $ctx->{krb5_ccache} = "$prefix_abs/krb5_ccache";
547 $ctx->{mitkdc_conf} = "$ctx->{etcdir}/mitkdc.conf";
548 $ctx->{privatedir} = "$prefix_abs/private";
549 $ctx->{binddnsdir} = "$prefix_abs/bind-dns";
550 $ctx->{ncalrpcdir} = "$prefix_abs/ncalrpc";
551 $ctx->{lockdir} = "$prefix_abs/lockdir";
552 $ctx->{logdir} = "$prefix_abs/logs";
553 $ctx->{statedir} = "$prefix_abs/statedir";
554 $ctx->{cachedir} = "$prefix_abs/cachedir";
555 $ctx->{winbindd_socket_dir} = "$prefix_abs/winbindd_socket";
556 $ctx->{ntp_signd_socket_dir} = "$prefix_abs/ntp_signd_socket";
557 $ctx->{nsswrap_passwd} = "$ctx->{etcdir}/passwd";
558 $ctx->{nsswrap_group} = "$ctx->{etcdir}/group";
559 $ctx->{nsswrap_hosts} = "$ENV{SELFTEST_PREFIX}/hosts";
560 $ctx->{nsswrap_hostname} = "$ctx->{hostname}.$ctx->{dnsname}";
561 if ($ENV{SAMBA_DNS_FAKING}) {
562 $ctx->{dns_host_file} = "$ENV{SELFTEST_PREFIX}/dns_host_file";
563 $ctx->{samba_dnsupdate} = "$ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate -s $ctx->{smb_conf} --all-interfaces --use-file=$ctx->{dns_host_file}";
564 $ctx->{samba_dnsupdate} = $python_cmd . $ctx->{samba_dnsupdate};
566 $ctx->{samba_dnsupdate} = "$ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate -s $ctx->{smb_conf} --all-interfaces";
567 $ctx->{samba_dnsupdate} = $python_cmd . $ctx->{samba_dnsupdate};
568 $ctx->{use_resolv_wrapper} = 1;
571 my $dns_hub = $self->get_dns_hub_env();
572 $ctx->{resolv_conf} = $dns_hub->{RESOLV_CONF};
574 $ctx->{tlsdir} = "$ctx->{privatedir}/tls";
576 $ctx->{ipv4} = Samba::get_ipv4_addr($hostname);
577 $ctx->{ipv6} = Samba::get_ipv6_addr($hostname);
579 push(@{$ctx->{directories}}, $ctx->{privatedir});
580 push(@{$ctx->{directories}}, $ctx->{binddnsdir});
581 push(@{$ctx->{directories}}, $ctx->{etcdir});
582 push(@{$ctx->{directories}}, $ctx->{piddir});
583 push(@{$ctx->{directories}}, $ctx->{lockdir});
584 push(@{$ctx->{directories}}, $ctx->{logdir});
585 push(@{$ctx->{directories}}, $ctx->{statedir});
586 push(@{$ctx->{directories}}, $ctx->{cachedir});
588 $ctx->{smb_conf_extra_options} = "";
590 my @provision_options = ();
591 push (@provision_options, "KRB5_CONFIG=\"$ctx->{krb5_conf}\"");
592 push (@provision_options, "KRB5_CCACHE=\"$ctx->{krb5_ccache}\"");
593 push (@provision_options, "NSS_WRAPPER_PASSWD=\"$ctx->{nsswrap_passwd}\"");
594 push (@provision_options, "NSS_WRAPPER_GROUP=\"$ctx->{nsswrap_group}\"");
595 push (@provision_options, "NSS_WRAPPER_HOSTS=\"$ctx->{nsswrap_hosts}\"");
596 push (@provision_options, "NSS_WRAPPER_HOSTNAME=\"$ctx->{nsswrap_hostname}\"");
597 if (defined($ctx->{use_resolv_wrapper})) {
598 push (@provision_options, "RESOLV_WRAPPER_CONF=\"$ctx->{resolv_conf}\"");
599 push (@provision_options, "RESOLV_CONF=\"$ctx->{resolv_conf}\"");
601 push (@provision_options, "RESOLV_WRAPPER_HOSTS=\"$ctx->{dns_host_file}\"");
603 if (defined($ENV{GDB_PROVISION})) {
604 push (@provision_options, "gdb --args");
605 if (!defined($ENV{PYTHON})) {
606 push (@provision_options, "env");
607 push (@provision_options, "python");
610 if (defined($ENV{VALGRIND_PROVISION})) {
611 push (@provision_options, "valgrind");
612 if (!defined($ENV{PYTHON})) {
613 push (@provision_options, "env");
614 push (@provision_options, "python");
618 my $samba_tool = Samba::bindir_path($self, "samba-tool");
620 push (@provision_options, $samba_tool);
621 push (@provision_options, "domain");
622 push (@provision_options, "provision");
623 push (@provision_options, "--configfile=$ctx->{smb_conf}");
624 push (@provision_options, "--host-name=$ctx->{hostname}");
625 push (@provision_options, "--host-ip=$ctx->{ipv4}");
626 push (@provision_options, "--quiet");
627 push (@provision_options, "--domain=$ctx->{domain}");
628 push (@provision_options, "--realm=$ctx->{realm}");
629 if (defined($ctx->{samsid})) {
630 push (@provision_options, "--domain-sid=$ctx->{samsid}");
632 push (@provision_options, "--adminpass=$ctx->{password}");
633 push (@provision_options, "--krbtgtpass=krbtgt$ctx->{password}");
634 push (@provision_options, "--machinepass=machine$ctx->{password}");
635 push (@provision_options, "--root=$ctx->{unix_name}");
636 push (@provision_options, "--server-role=\"$ctx->{server_role}\"");
637 push (@provision_options, "--function-level=\"$ctx->{functional_level}\"");
639 @{$ctx->{provision_options}} = @provision_options;
646 my ($self, $keyword, @options_list) = @_;
648 # convert the options-list to a hash-map for easy keyword lookup
649 my %options_dict = map { $_ => 1 } @options_list;
651 return exists $options_dict{$keyword};
655 # Step1 creates the basic configuration
657 sub provision_raw_step1($$)
659 my ($self, $ctx) = @_;
661 mkdir($_, 0777) foreach (@{$ctx->{directories}});
664 ## lockdir and piddir must be 0755
666 chmod 0755, $ctx->{lockdir};
667 chmod 0755, $ctx->{piddir};
669 unless (open(CONFFILE, ">$ctx->{smb_conf}")) {
670 warn("can't open $ctx->{smb_conf}$?");
674 Samba::prepare_keyblobs($ctx);
675 my $crlfile = "$ctx->{tlsdir}/crl.pem";
676 $crlfile = "" unless -e ${crlfile};
678 # work out which file server to use. Default to source3 smbd (s3fs),
679 # unless the source4 NTVFS (smb) file server has been specified
680 my $services = "-smb +s3fs";
681 if ($self->has_option("--use-ntvfs", @{$ctx->{provision_options}})) {
682 $services = "+smb -s3fs";
685 my $interfaces = Samba::get_interfaces_config($ctx->{netbiosname});
689 netbios name = $ctx->{netbiosname}
690 posix:eadb = $ctx->{statedir}/eadb.tdb
691 workgroup = $ctx->{domain}
692 realm = $ctx->{realm}
693 private dir = $ctx->{privatedir}
694 binddns dir = $ctx->{binddnsdir}
695 pid directory = $ctx->{piddir}
696 ncalrpc dir = $ctx->{ncalrpcdir}
697 lock dir = $ctx->{lockdir}
698 state directory = $ctx->{statedir}
699 cache directory = $ctx->{cachedir}
700 winbindd socket directory = $ctx->{winbindd_socket_dir}
701 ntp signd socket directory = $ctx->{ntp_signd_socket_dir}
702 winbind separator = /
703 interfaces = $interfaces
704 tls dh params file = $ctx->{tlsdir}/dhparms.pem
705 tls crlfile = ${crlfile}
706 tls verify peer = no_check
707 panic action = $RealBin/gdb_backtrace \%d
709 server role = $ctx->{server_role}
710 server services = +echo $services
711 dcerpc endpoint servers = +winreg +srvsvc
712 notify:inotify = false
714 ldap server require strong auth = yes
715 #We don't want to pass our self-tests if the PAC code is wrong
716 gensec:require_pac = true
717 log file = $ctx->{logdir}/log.\%m
718 log level = $ctx->{server_loglevel}
721 client min protocol = CORE
722 server min protocol = LANMAN1
724 dns update command = $ctx->{samba_dnsupdate}
725 spn update command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_spnupdate -s $ctx->{smb_conf}
726 gpo update command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba-gpupdate -s $ctx->{smb_conf} --target=Computer
727 samba kcc command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_kcc
728 dreplsrv:periodic_startup_interval = 0
729 dsdb:schema update allowed = yes
731 vfs objects = dfs_samba4 acl_xattr fake_acls xattr_tdb streams_depot
733 idmap_ldb:use rfc2307=yes
734 winbind enum users = yes
735 winbind enum groups = yes
737 rpc server port:netlogon = 1026
738 include system krb5 conf = no
744 # Begin extra options
745 $ctx->{smb_conf_extra_options}
750 #Default the KDC IP to the server's IP
751 if (not defined($ctx->{kdc_ipv4})) {
752 $ctx->{kdc_ipv4} = $ctx->{ipv4};
754 if (not defined($ctx->{kdc_ipv6})) {
755 $ctx->{kdc_ipv6} = $ctx->{ipv6};
758 Samba::mk_krb5_conf($ctx);
759 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
761 open(PWD, ">$ctx->{nsswrap_passwd}");
762 if ($ctx->{unix_uid} != 0) {
763 print PWD "root:x:0:0:root gecos:$ctx->{prefix_abs}:/bin/false\n";
765 print PWD "$ctx->{unix_name}:x:$ctx->{unix_uid}:65531:$ctx->{unix_name} gecos:$ctx->{prefix_abs}:/bin/false\n";
766 print PWD "nobody:x:65534:65533:nobody gecos:$ctx->{prefix_abs}:/bin/false
767 pdbtest:x:65533:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
768 pdbtest2:x:65532:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
769 pdbtest3:x:65531:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
770 pdbtest4:x:65530:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
773 my $uid_rfc2307test = 65533;
775 open(GRP, ">$ctx->{nsswrap_group}");
776 if ($ctx->{unix_gid} != 0) {
777 print GRP "root:x:0:\n";
779 print GRP "$ctx->{unix_name}:x:$ctx->{unix_gid}:\n";
780 print GRP "wheel:x:10:
783 nogroup:x:65534:nobody
786 my $gid_rfc2307test = 65532;
788 my $hostname = lc($ctx->{hostname});
789 open(HOSTS, ">>$ctx->{nsswrap_hosts}");
790 if ($hostname eq "localdc") {
791 print HOSTS "$ctx->{ipv4} ${hostname}.$ctx->{dnsname} $ctx->{dnsname} ${hostname}\n";
792 print HOSTS "$ctx->{ipv6} ${hostname}.$ctx->{dnsname} $ctx->{dnsname} ${hostname}\n";
794 print HOSTS "$ctx->{ipv4} ${hostname}.$ctx->{dnsname} ${hostname}\n";
795 print HOSTS "$ctx->{ipv6} ${hostname}.$ctx->{dnsname} ${hostname}\n";
799 my $configuration = "--configfile=$ctx->{smb_conf}";
801 #Ensure the config file is valid before we start
802 my $testparm = Samba::bindir_path($self, "samba-tool") . " testparm";
803 if (system("$testparm $configuration -v --suppress-prompt >/dev/null 2>&1") != 0) {
804 system("$testparm -v --suppress-prompt $configuration >&2");
805 warn("Failed to create a valid smb.conf configuration $testparm!");
808 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) {
809 warn("Failed to create a valid smb.conf configuration! $testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global");
813 # Return the environment variables for the new testenv DC.
814 # Note that we have SERVER_X and DC_SERVER_X variables (which have the same
815 # value initially). In a 2 DC setup, $DC_SERVER_X will always be the PDC.
817 KRB5_CONFIG => $ctx->{krb5_conf},
818 KRB5_CCACHE => $ctx->{krb5_ccache},
819 MITKDC_CONFIG => $ctx->{mitkdc_conf},
820 PIDDIR => $ctx->{piddir},
821 SERVER => $ctx->{hostname},
822 DC_SERVER => $ctx->{hostname},
823 SERVER_IP => $ctx->{ipv4},
824 DC_SERVER_IP => $ctx->{ipv4},
825 SERVER_IPV6 => $ctx->{ipv6},
826 DC_SERVER_IPV6 => $ctx->{ipv6},
827 NETBIOSNAME => $ctx->{netbiosname},
828 DC_NETBIOSNAME => $ctx->{netbiosname},
829 DOMAIN => $ctx->{domain},
830 USERNAME => $ctx->{username},
831 DC_USERNAME => $ctx->{username},
832 REALM => $ctx->{realm},
833 DNSNAME => $ctx->{dnsname},
834 SAMSID => $ctx->{samsid},
835 PASSWORD => $ctx->{password},
836 DC_PASSWORD => $ctx->{password},
837 LDAPDIR => $ctx->{ldapdir},
838 LDAP_INSTANCE => $ctx->{ldap_instance},
839 SELFTEST_WINBINDD_SOCKET_DIR => $ctx->{winbindd_socket_dir},
840 NCALRPCDIR => $ctx->{ncalrpcdir},
841 LOCKDIR => $ctx->{lockdir},
842 STATEDIR => $ctx->{statedir},
843 CACHEDIR => $ctx->{cachedir},
844 PRIVATEDIR => $ctx->{privatedir},
845 BINDDNSDIR => $ctx->{binddnsdir},
846 SERVERCONFFILE => $ctx->{smb_conf},
847 TESTENV_DIR => $ctx->{prefix_abs},
848 CONFIGURATION => $configuration,
849 SOCKET_WRAPPER_DEFAULT_IFACE => $ctx->{swiface},
850 NSS_WRAPPER_PASSWD => $ctx->{nsswrap_passwd},
851 NSS_WRAPPER_GROUP => $ctx->{nsswrap_group},
852 NSS_WRAPPER_HOSTS => $ctx->{nsswrap_hosts},
853 NSS_WRAPPER_HOSTNAME => $ctx->{nsswrap_hostname},
854 SAMBA_TEST_FIFO => "$ctx->{prefix}/samba_test.fifo",
855 SAMBA_TEST_LOG => "$ctx->{prefix}/samba_test.log",
856 SAMBA_TEST_LOG_POS => 0,
857 NSS_WRAPPER_MODULE_SO_PATH => Samba::nss_wrapper_winbind_so_path($self),
858 NSS_WRAPPER_MODULE_FN_PREFIX => "winbind",
859 LOCAL_PATH => $ctx->{share},
860 UID_RFC2307TEST => $uid_rfc2307test,
861 GID_RFC2307TEST => $gid_rfc2307test,
862 SERVER_ROLE => $ctx->{server_role},
863 RESOLV_CONF => $ctx->{resolv_conf}
866 if (defined($ctx->{use_resolv_wrapper})) {
867 $ret->{RESOLV_WRAPPER_CONF} = $ctx->{resolv_conf};
869 $ret->{RESOLV_WRAPPER_HOSTS} = $ctx->{dns_host_file};
872 if ($ctx->{server_role} eq "domain controller") {
873 $ret->{DOMSID} = $ret->{SAMSID};
880 # Step2 runs the provision script
882 sub provision_raw_step2($$$)
884 my ($self, $ctx, $ret) = @_;
886 my $provision_cmd = join(" ", @{$ctx->{provision_options}});
887 unless (system($provision_cmd) == 0) {
888 warn("Unable to provision: \n$provision_cmd\n");
892 my $testallowed_account = "testallowed";
893 my $samba_tool_cmd = "";
894 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
895 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
896 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
897 . " user create --configfile=$ctx->{smb_conf} $testallowed_account $ctx->{password}";
898 unless (system($samba_tool_cmd) == 0) {
899 warn("Unable to add testallowed user: \n$samba_tool_cmd\n");
904 $ldbmodify .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
905 $ldbmodify .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
906 $ldbmodify .= Samba::bindir_path($self, "ldbmodify");
907 $ldbmodify .= " --configfile=$ctx->{smb_conf}";
908 my $base_dn = "DC=".join(",DC=", split(/\./, $ctx->{realm}));
910 if ($ctx->{server_role} ne "domain controller") {
911 $base_dn = "DC=$ctx->{netbiosname}";
914 my $user_dn = "cn=$testallowed_account,cn=users,$base_dn";
915 $testallowed_account = "testallowed account";
916 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
917 print LDIF "dn: $user_dn
919 replace: samAccountName
920 samAccountName: $testallowed_account
925 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
926 print LDIF "dn: $user_dn
928 replace: userPrincipalName
929 userPrincipalName: testallowed upn\@$ctx->{realm}
930 replace: servicePrincipalName
931 servicePrincipalName: host/testallowed
936 $samba_tool_cmd = "";
937 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
938 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
939 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
940 . " user create --configfile=$ctx->{smb_conf} testdenied $ctx->{password}";
941 unless (system($samba_tool_cmd) == 0) {
942 warn("Unable to add testdenied user: \n$samba_tool_cmd\n");
946 $user_dn = "cn=testdenied,cn=users,$base_dn";
947 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
948 print LDIF "dn: $user_dn
950 replace: userPrincipalName
951 userPrincipalName: testdenied_upn\@$ctx->{realm}.upn
956 $samba_tool_cmd = "";
957 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
958 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
959 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
960 . " user create --configfile=$ctx->{smb_conf} testupnspn $ctx->{password}";
961 unless (system($samba_tool_cmd) == 0) {
962 warn("Unable to add testupnspn user: \n$samba_tool_cmd\n");
966 $user_dn = "cn=testupnspn,cn=users,$base_dn";
967 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
968 print LDIF "dn: $user_dn
970 replace: userPrincipalName
971 userPrincipalName: http/testupnspn.$ctx->{dnsname}\@$ctx->{realm}
972 replace: servicePrincipalName
973 servicePrincipalName: http/testupnspn.$ctx->{dnsname}
978 $samba_tool_cmd = "";
979 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
980 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
981 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
982 . " group addmembers --configfile=$ctx->{smb_conf} 'Allowed RODC Password Replication Group' '$testallowed_account'";
983 unless (system($samba_tool_cmd) == 0) {
984 warn("Unable to add '$testallowed_account' user to 'Allowed RODC Password Replication Group': \n$samba_tool_cmd\n");
988 # Create to users alice and bob!
989 my $user_account_array = ["alice", "bob", "jane", "joe"];
991 foreach my $user_account (@{$user_account_array}) {
992 my $samba_tool_cmd = "";
994 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
995 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
996 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
997 . " user create --configfile=$ctx->{smb_conf} $user_account Secret007";
998 unless (system($samba_tool_cmd) == 0) {
999 warn("Unable to create user: $user_account\n$samba_tool_cmd\n");
1004 my $group_array = ["Samba Users"];
1006 foreach my $group (@{$group_array}) {
1007 my $samba_tool_cmd = "";
1009 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1010 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1011 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1012 . " group add --configfile=$ctx->{smb_conf} \"$group\"";
1013 unless (system($samba_tool_cmd) == 0) {
1014 warn("Unable to create group: $group\n$samba_tool_cmd\n");
1019 # Add user joe to group "Samba Users"
1020 $samba_tool_cmd = "";
1021 my $group = "Samba Users";
1022 my $user_account = "joe";
1024 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1025 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1026 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1027 . " group addmembers --configfile=$ctx->{smb_conf} \"$group\" $user_account";
1028 unless (system($samba_tool_cmd) == 0) {
1029 warn("Unable to add " . $user_account . "to group group : $group\n$samba_tool_cmd\n");
1033 $samba_tool_cmd = "";
1034 $group = "Samba Users";
1035 $user_account = "joe";
1037 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1038 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1039 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1040 . " user setprimarygroup --configfile=$ctx->{smb_conf} $user_account \"$group\"";
1041 unless (system($samba_tool_cmd) == 0) {
1042 warn("Unable to set primary group of user: $user_account\n$samba_tool_cmd\n");
1046 # Change the userPrincipalName for jane
1048 $ldbmodify .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1049 $ldbmodify .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1050 $ldbmodify .= Samba::bindir_path($self, "ldbmodify");
1051 $ldbmodify .= " --configfile=$ctx->{smb_conf}";
1052 $base_dn = "DC=".join(",DC=", split(/\./, $ctx->{realm}));
1053 $user_dn = "cn=jane,cn=users,$base_dn";
1055 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
1056 print LDIF "dn: $user_dn
1058 replace: userPrincipalName
1059 userPrincipalName: jane.doe\@$ctx->{realm}
1067 sub provision($$$$$$$$$$)
1069 my ($self, $prefix, $server_role, $hostname,
1070 $domain, $realm, $functional_level,
1071 $password, $kdc_ipv4, $kdc_ipv6, $extra_smbconf_options, $extra_smbconf_shares,
1072 $extra_provision_options) = @_;
1074 my $samsid = Samba::random_domain_sid();
1076 my $ctx = $self->provision_raw_prepare($prefix, $server_role,
1081 $password, $kdc_ipv4, $kdc_ipv6);
1083 if (defined($extra_provision_options)) {
1084 push (@{$ctx->{provision_options}}, @{$extra_provision_options});
1087 $ctx->{share} = "$ctx->{prefix_abs}/share";
1088 push(@{$ctx->{directories}}, "$ctx->{share}");
1089 push(@{$ctx->{directories}}, "$ctx->{share}/test1");
1090 push(@{$ctx->{directories}}, "$ctx->{share}/test2");
1092 # precreate directories for printer drivers
1093 push(@{$ctx->{directories}}, "$ctx->{share}/W32X86");
1094 push(@{$ctx->{directories}}, "$ctx->{share}/x64");
1095 push(@{$ctx->{directories}}, "$ctx->{share}/WIN40");
1098 $msdfs = "yes" if ($server_role eq "domain controller");
1099 $ctx->{smb_conf_extra_options} = "
1102 server max protocol = SMB2
1106 # fruit:copyfile is a global option
1107 fruit:copyfile = yes
1109 $extra_smbconf_options
1112 path = $ctx->{share}
1114 posix:sharedelay = 100000
1115 posix:oplocktimeout = 3
1116 posix:writetimeupdatedelay = 500000
1119 path = $ctx->{share}
1121 posix:sharedelay = 100000
1122 posix:oplocktimeout = 3
1123 posix:writetimeupdatedelay = 500000
1125 force create mode = 777
1128 path = $ctx->{share}
1131 force create mode = 0
1132 directory mask = 0777
1133 force directory mode = 0
1136 path = $ctx->{share}/test1
1138 posix:sharedelay = 100000
1139 posix:oplocktimeout = 3
1140 posix:writetimeupdatedelay = 500000
1143 path = $ctx->{share}/test2
1145 posix:sharedelay = 100000
1146 posix:oplocktimeout = 3
1147 posix:writetimeupdatedelay = 500000
1150 path = $ctx->{share}/_ignore_cifs_
1152 ntvfs handler = cifs
1153 cifs:server = $ctx->{netbiosname}
1155 cifs:use-s4u2proxy = yes
1156 # There is no username specified here, instead the client is expected
1157 # to log in with kerberos, and the serverwill use delegated credentials.
1158 # Or the server tries s4u2self/s4u2proxy to impersonate the client
1161 path = $ctx->{share}
1163 ntvfs handler = simple
1166 path = $ctx->{statedir}/sysvol
1170 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1175 ntvfs handler = cifsposix
1178 path = $ctx->{share}
1179 vfs objects = catia fruit streams_xattr acl_xattr
1181 fruit:resource = file
1182 fruit:metadata = netatalk
1183 fruit:locking = netatalk
1184 fruit:encoding = native
1187 path = $ctx->{share}
1188 # This can be used for testing real fs xattr stuff
1189 vfs objects = streams_xattr acl_xattr
1191 $extra_smbconf_shares
1194 my $ret = $self->provision_raw_step1($ctx);
1195 unless (defined $ret) {
1199 return $self->provision_raw_step2($ctx, $ret);
1202 # For multi-DC testenvs, we want $DC_SERVER to always be the PDC (i.e. the
1203 # original DC) in the testenv. $SERVER is always the joined DC that we are
1204 # actually running the test against
1205 sub set_pdc_env_vars
1207 my ($self, $env, $dcvars) = @_;
1209 $env->{DC_SERVER} = $dcvars->{DC_SERVER};
1210 $env->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1211 $env->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1212 $env->{DC_SERVERCONFFILE} = $dcvars->{SERVERCONFFILE};
1213 $env->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1214 $env->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1215 $env->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1218 sub provision_s4member($$$$$)
1220 my ($self, $prefix, $dcvars, $hostname, $more_conf) = @_;
1221 print "PROVISIONING MEMBER...\n";
1222 my $extra_smb_conf = "
1223 passdb backend = samba_dsdb
1224 winbindd:use external pipes = true
1226 # the source4 smb server doesn't allow signing by default
1227 server signing = enabled
1228 raw NTLMv2 auth = yes
1230 rpc_server:default = external
1231 rpc_server:svcctl = embedded
1232 rpc_server:srvsvc = embedded
1233 rpc_server:eventlog = embedded
1234 rpc_server:ntsvcs = embedded
1235 rpc_server:winreg = embedded
1236 rpc_server:spoolss = embedded
1237 rpc_daemon:spoolssd = embedded
1238 rpc_server:tcpip = no
1241 $extra_smb_conf = $extra_smb_conf . $more_conf . "\n";
1243 my $extra_provision_options = ["--use-ntvfs"];
1244 my $ret = $self->provision($prefix,
1251 $dcvars->{SERVER_IP},
1252 $dcvars->{SERVER_IPV6},
1253 $extra_smb_conf, "",
1254 $extra_provision_options);
1259 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1260 my $cmd = $self->get_cmd_env_vars($ret);
1261 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
1262 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1263 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1265 unless (system($cmd) == 0) {
1266 warn("Join failed\n$cmd");
1270 $ret->{DOMSID} = $dcvars->{DOMSID};
1271 $self->set_pdc_env_vars($ret, $dcvars);
1276 sub provision_rpc_proxy($$$)
1278 my ($self, $prefix, $dcvars) = @_;
1279 print "PROVISIONING RPC PROXY...\n";
1281 my $extra_smbconf_options = "
1282 passdb backend = samba_dsdb
1285 dcerpc_remote:binding = ncacn_ip_tcp:$dcvars->{SERVER}
1286 dcerpc endpoint servers = epmapper, remote
1287 dcerpc_remote:interfaces = rpcecho
1288 dcerpc_remote:allow_anonymous_fallback = yes
1291 path = /tmp/_ignore_cifs_to_dc_/_none_
1293 ntvfs handler = cifs
1294 cifs:server = $dcvars->{SERVER}
1296 cifs:use-s4u2proxy = yes
1297 # There is no username specified here, instead the client is expected
1298 # to log in with kerberos, and the serverwill use delegated credentials.
1299 # Or the server tries s4u2self/s4u2proxy to impersonate the client
1303 my $extra_provision_options = ["--use-ntvfs"];
1304 my $ret = $self->provision($prefix,
1311 $dcvars->{SERVER_IP},
1312 $dcvars->{SERVER_IPV6},
1313 $extra_smbconf_options, "",
1314 $extra_provision_options);
1319 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1321 # The joind runs in the context of the rpc_proxy/member for now
1322 my $cmd = $self->get_cmd_env_vars($ret);
1323 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
1324 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1325 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1327 unless (system($cmd) == 0) {
1328 warn("Join failed\n$cmd");
1332 # Setting up delegation runs in the context of the DC for now
1334 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1335 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
1336 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1337 $cmd .= "RESOLV_CONF=\"$dcvars->{RESOLV_CONF}\" ";
1338 $cmd .= "$samba_tool delegation for-any-protocol '$ret->{NETBIOSNAME}\$' on";
1339 $cmd .= " $dcvars->{CONFIGURATION}";
1342 unless (system($cmd) == 0) {
1343 warn("Delegation failed\n$cmd");
1347 # Setting up delegation runs in the context of the DC for now
1349 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1350 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
1351 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1352 $cmd .= "RESOLV_CONF=\"$dcvars->{RESOLV_CONF}\" ";
1353 $cmd .= "$samba_tool delegation add-service '$ret->{NETBIOSNAME}\$' cifs/$dcvars->{SERVER}";
1354 $cmd .= " $dcvars->{CONFIGURATION}";
1356 unless (system($cmd) == 0) {
1357 warn("Delegation failed\n$cmd");
1361 $ret->{DOMSID} = $dcvars->{DOMSID};
1362 $self->set_pdc_env_vars($ret, $dcvars);
1367 sub provision_promoted_dc($$$)
1369 my ($self, $prefix, $dcvars) = @_;
1370 print "PROVISIONING PROMOTED DC...\n";
1372 # We do this so that we don't run the provision. That's the job of 'samba-tool domain dcpromo'.
1373 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1379 $dcvars->{PASSWORD},
1380 $dcvars->{SERVER_IP},
1381 $dcvars->{SERVER_IPV6});
1383 $ctx->{smb_conf_extra_options} = "
1385 server max protocol = SMB2
1387 ntlm auth = ntlmv2-only
1390 path = $ctx->{statedir}/sysvol
1394 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1399 my $ret = $self->provision_raw_step1($ctx);
1404 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1405 my $cmd = $self->get_cmd_env_vars($ret);
1406 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} MEMBER --realm=$dcvars->{REALM}";
1407 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1408 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1410 unless (system($cmd) == 0) {
1411 warn("Join failed\n$cmd");
1415 $samba_tool = Samba::bindir_path($self, "samba-tool");
1416 $cmd = $self->get_cmd_env_vars($ret);
1417 $cmd .= "$samba_tool domain dcpromo $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1418 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1419 $cmd .= " --machinepass=machine$ret->{PASSWORD} --dns-backend=BIND9_DLZ";
1421 unless (system($cmd) == 0) {
1422 warn("Join failed\n$cmd");
1426 $self->set_pdc_env_vars($ret, $dcvars);
1431 sub provision_vampire_dc($$$)
1433 my ($self, $prefix, $dcvars, $fl) = @_;
1434 print "PROVISIONING VAMPIRE DC @ FL $fl...\n";
1435 my $name = "localvampiredc";
1436 my $extra_conf = "";
1438 if ($fl == "2000") {
1439 $name = "vampire2000dc";
1441 $extra_conf = "drs: immediate link sync = yes
1442 drs: max link sync = 250";
1445 # We do this so that we don't run the provision. That's the job of 'net vampire'.
1446 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1452 $dcvars->{PASSWORD},
1453 $dcvars->{SERVER_IP},
1454 $dcvars->{SERVER_IPV6});
1456 $ctx->{smb_conf_extra_options} = "
1458 server max protocol = SMB2
1460 ntlm auth = mschapv2-and-ntlmv2-only
1464 path = $ctx->{statedir}/sysvol
1468 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1473 my $ret = $self->provision_raw_step1($ctx);
1478 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1479 my $cmd = $self->get_cmd_env_vars($ret);
1480 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1481 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} --domain-critical-only";
1482 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1483 $cmd .= " --backend-store=mdb";
1485 unless (system($cmd) == 0) {
1486 warn("Join failed\n$cmd");
1490 $self->set_pdc_env_vars($ret, $dcvars);
1491 $ret->{DC_REALM} = $dcvars->{DC_REALM};
1496 sub provision_ad_dc_ntvfs($$$)
1498 my ($self, $prefix, $extra_provision_options) = @_;
1500 # We keep the old 'winbind' name here in server services to
1501 # ensure upgrades which used that name still work with the now
1504 print "PROVISIONING AD DC (NTVFS)...\n";
1505 my $extra_conf_options = "netbios aliases = localDC1-a
1506 server services = +winbind -winbindd
1507 ldap server require strong auth = allow_sasl_over_tls
1508 allow nt4 crypto = yes
1509 raw NTLMv2 auth = yes
1510 lsa over netlogon = yes
1511 rpc server port = 1027
1512 auth event notification = true
1513 dsdb event notification = true
1514 dsdb password event notification = true
1515 dsdb group change notification = true
1516 server schannel = auto
1518 push (@{$extra_provision_options}, "--use-ntvfs");
1519 my $ret = $self->provision($prefix,
1520 "domain controller",
1523 "samba.example.com",
1528 $extra_conf_options,
1530 $extra_provision_options);
1535 unless($self->add_wins_config("$prefix/private")) {
1536 warn("Unable to add wins configuration");
1539 $ret->{NETBIOSALIAS} = "localdc1-a";
1540 $ret->{DC_REALM} = $ret->{REALM};
1545 sub provision_fl2000dc($$)
1547 my ($self, $prefix) = @_;
1549 print "PROVISIONING DC WITH FOREST LEVEL 2000...\n";
1550 my $extra_conf_options = "
1551 spnego:simulate_w2k=yes
1552 ntlmssp_server:force_old_spnego=yes
1554 my $extra_provision_options = ["--base-schema=2008_R2"];
1555 # This environment uses plain text secrets
1556 # i.e. secret attributes are not encrypted on disk.
1557 # This allows testing of the --plaintext-secrets option for
1559 push (@{$extra_provision_options}, "--plaintext-secrets");
1560 my $ret = $self->provision($prefix,
1561 "domain controller",
1564 "samba2000.example.com",
1569 $extra_conf_options,
1571 $extra_provision_options);
1576 unless($self->add_wins_config("$prefix/private")) {
1577 warn("Unable to add wins configuration");
1580 $ret->{DC_REALM} = $ret->{REALM};
1585 sub provision_fl2003dc($$$)
1587 my ($self, $prefix, $dcvars) = @_;
1588 my $ip_addr1 = Samba::get_ipv4_addr("fakednsforwarder1");
1589 my $ip_addr2 = Samba::get_ipv4_addr("fakednsforwarder2");
1591 print "PROVISIONING DC WITH FOREST LEVEL 2003...\n";
1592 my $extra_conf_options = "allow dns updates = nonsecure and secure
1593 dcesrv:header signing = no
1594 dcesrv:max auth states = 0
1595 dns forwarder = $ip_addr1 $ip_addr2";
1596 my $extra_provision_options = ["--base-schema=2008_R2"];
1597 my $ret = $self->provision($prefix,
1598 "domain controller",
1601 "samba2003.example.com",
1606 $extra_conf_options,
1608 $extra_provision_options);
1609 unless (defined $ret) {
1613 $ret->{DNS_FORWARDER1} = $ip_addr1;
1614 $ret->{DNS_FORWARDER2} = $ip_addr2;
1616 my @samba_tool_options;
1617 push (@samba_tool_options, Samba::bindir_path($self, "samba-tool"));
1618 push (@samba_tool_options, "domain");
1619 push (@samba_tool_options, "passwordsettings");
1620 push (@samba_tool_options, "set");
1621 push (@samba_tool_options, "--configfile=$ret->{SERVERCONFFILE}");
1622 push (@samba_tool_options, "--min-pwd-age=0");
1623 push (@samba_tool_options, "--history-length=1");
1625 my $samba_tool_cmd = join(" ", @samba_tool_options);
1627 unless (system($samba_tool_cmd) == 0) {
1628 warn("Unable to set min password age to 0: \n$samba_tool_cmd\n");
1632 unless($self->add_wins_config("$prefix/private")) {
1633 warn("Unable to add wins configuration");
1640 sub provision_fl2008r2dc($$$)
1642 my ($self, $prefix, $dcvars) = @_;
1644 print "PROVISIONING DC WITH FOREST LEVEL 2008r2...\n";
1645 my $extra_conf_options = "ldap server require strong auth = no";
1646 my $extra_provision_options = ["--base-schema=2008_R2"];
1647 my $ret = $self->provision($prefix,
1648 "domain controller",
1651 "samba2008R2.example.com",
1656 $extra_conf_options,
1658 $extra_provision_options);
1659 unless (defined $ret) {
1663 unless ($self->add_wins_config("$prefix/private")) {
1664 warn("Unable to add wins configuration");
1667 $ret->{DC_REALM} = $ret->{REALM};
1673 sub provision_rodc($$$)
1675 my ($self, $prefix, $dcvars) = @_;
1676 print "PROVISIONING RODC...\n";
1678 # We do this so that we don't run the provision. That's the job of 'net join RODC'.
1679 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1685 $dcvars->{PASSWORD},
1686 $dcvars->{SERVER_IP},
1687 $dcvars->{SERVER_IPV6});
1692 $ctx->{share} = "$ctx->{prefix_abs}/share";
1693 push(@{$ctx->{directories}}, "$ctx->{share}");
1695 $ctx->{smb_conf_extra_options} = "
1697 server max protocol = SMB2
1698 password server = $dcvars->{DC_SERVER}
1701 path = $ctx->{statedir}/sysvol
1705 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1709 path = $ctx->{share}
1711 posix:sharedelay = 10000
1712 posix:oplocktimeout = 3
1713 posix:writetimeupdatedelay = 50000
1717 my $ret = $self->provision_raw_step1($ctx);
1722 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1723 my $cmd = $self->get_cmd_env_vars($ret);
1724 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} RODC";
1725 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1726 $cmd .= " --server=$dcvars->{DC_SERVER}";
1728 unless (system($cmd) == 0) {
1729 warn("RODC join failed\n$cmd");
1733 # This ensures deterministic behaviour for tests that want to have the 'testallowed account'
1734 # user password verified on the RODC
1735 my $testallowed_account = "testallowed account";
1736 $cmd = "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1737 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1738 $cmd .= "RESOLV_CONF=\"$ret->{RESOLV_CONF}\" ";
1739 $cmd .= "$samba_tool rodc preload '$testallowed_account' $ret->{CONFIGURATION}";
1740 $cmd .= " --server=$dcvars->{DC_SERVER}";
1742 unless (system($cmd) == 0) {
1743 warn("RODC join failed\n$cmd");
1747 # we overwrite the kdc after the RODC join
1748 # so that use the RODC as kdc and test
1750 $ctx->{kdc_ipv4} = $ret->{SERVER_IP};
1751 $ctx->{kdc_ipv6} = $ret->{SERVER_IPV6};
1752 Samba::mk_krb5_conf($ctx);
1753 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
1755 $self->set_pdc_env_vars($ret, $dcvars);
1760 sub read_config_h($)
1764 open(LF, "<$name") or die("unable to read $name: $!");
1767 next if not (/^#define /);
1768 if (/^#define (.*?)[ \t]+(.*?)$/) {
1772 if (/^#define (.*?)[ \t]+$/) {
1781 sub provision_ad_dc($$$$$$)
1783 my ($self, $prefix, $hostname, $domain, $realm, $smbconf_args,
1784 $extra_provision_options) = @_;
1786 my $prefix_abs = abs_path($prefix);
1788 my $bindir_abs = abs_path($self->{bindir});
1789 my $lockdir="$prefix_abs/lockdir";
1790 my $conffile="$prefix_abs/etc/smb.conf";
1792 my $require_mutexes = "dbwrap_tdb_require_mutexes:* = yes";
1793 $require_mutexes = "" if ($ENV{SELFTEST_DONT_REQUIRE_TDB_MUTEX_SUPPORT} eq "1");
1797 if (defined($ENV{CONFIG_H})) {
1798 $config_h = read_config_h($ENV{CONFIG_H});
1801 my $password_hash_gpg_key_ids = "password hash gpg key ids = 4952E40301FAB41A";
1802 $password_hash_gpg_key_ids = "" unless defined($config_h->{HAVE_GPGME});
1804 my $extra_smbconf_options = "
1805 xattr_tdb:file = $prefix_abs/statedir/xattr.tdb
1807 dbwrap_tdb_mutexes:* = yes
1810 ${password_hash_gpg_key_ids}
1813 kernel change notify = no
1818 printcap name = /dev/null
1823 smbd:sharedelay = 100000
1824 smbd:writetimeupdatedelay = 500000
1827 check parent directory delete on close = yes
1829 dcerpc endpoint servers = -winreg -srvsvc
1831 printcap name = /dev/null
1833 addprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -a -s $conffile --
1834 deleteprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -d -s $conffile --
1837 print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
1838 lpq command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpq %p
1839 lp rm command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lprm %p %j
1840 lp pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lppause %p %j
1841 lp resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpresume %p %j
1842 queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
1843 queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
1845 print notify backchannel = yes
1847 server schannel = auto
1848 auth event notification = true
1849 dsdb event notification = true
1850 dsdb password event notification = true
1851 dsdb group change notification = true
1855 my $extra_smbconf_shares = "
1859 smb encrypt = required
1863 case sensitive = yes
1871 hide unreadable = yes
1875 kernel share modes = no
1897 push (@{$extra_provision_options}, "--backend-store=mdb");
1898 print "PROVISIONING AD DC...\n";
1899 my $ret = $self->provision($prefix,
1900 "domain controller",
1908 $extra_smbconf_options,
1909 $extra_smbconf_shares,
1910 $extra_provision_options);
1911 unless (defined $ret) {
1915 unless($self->add_wins_config("$prefix/private")) {
1916 warn("Unable to add wins configuration");
1923 sub provision_chgdcpass($$)
1925 my ($self, $prefix) = @_;
1927 print "PROVISIONING CHGDCPASS...\n";
1928 # This environment disallows the use of this password
1929 # (and also removes the default AD complexity checks)
1930 my $unacceptable_password = "Paßßword-widk3Dsle32jxdBdskldsk55klASKQ";
1931 my $extra_smb_conf = "
1932 check password script = $self->{srcdir}/selftest/checkpassword_arg1.sh ${unacceptable_password}
1933 allow dcerpc auth level connect:lsarpc = yes
1934 dcesrv:max auth states = 8
1936 my $extra_provision_options = ["--dns-backend=BIND9_DLZ"];
1937 my $ret = $self->provision($prefix,
1938 "domain controller",
1941 "chgdcpassword.samba.example.com",
1948 $extra_provision_options);
1949 unless (defined $ret) {
1953 unless($self->add_wins_config("$prefix/private")) {
1954 warn("Unable to add wins configuration");
1958 # Remove secrets.tdb from this environment to test that we
1959 # still start up on systems without the new matching
1960 # secrets.tdb records.
1961 unless (unlink("$ret->{PRIVATEDIR}/secrets.tdb") || unlink("$ret->{PRIVATEDIR}/secrets.ntdb")) {
1962 warn("Unable to remove $ret->{PRIVATEDIR}/secrets.tdb added during provision");
1966 $ret->{UNACCEPTABLE_PASSWORD} = $unacceptable_password;
1971 sub teardown_env_terminate($$)
1973 my ($self, $envvars) = @_;
1976 # This should cause samba to terminate gracefully
1977 my $smbcontrol = Samba::bindir_path($self, "smbcontrol");
1979 $cmd .= "$smbcontrol samba shutdown $envvars->{CONFIGURATION}";
1980 my $ret = system($cmd);
1982 warn "'$cmd' failed with '$ret'\n";
1985 # This should cause samba to terminate gracefully
1986 close($envvars->{STDIN_PIPE});
1988 $pid = $envvars->{SAMBA_PID};
1992 # This should give it time to write out the gcov data
1993 until ($count > 15) {
1994 if (Samba::cleanup_child($pid, "samba") != 0) {
2001 # After 15 Seconds, work out why this thing is still alive
2002 warn "server process $pid took more than $count seconds to exit, showing backtrace:\n";
2003 system("$self->{srcdir}/selftest/gdb_backtrace $pid");
2005 until ($count > 30) {
2006 if (Samba::cleanup_child($pid, "samba") != 0) {
2013 if (kill(0, $pid)) {
2014 warn "server process $pid took more than $count seconds to exit, sending SIGTERM\n";
2018 until ($count > 40) {
2019 if (Samba::cleanup_child($pid, "samba") != 0) {
2025 # If it is still around, kill it
2026 if (kill(0, $pid)) {
2027 warn "server process $pid took more than $count seconds to exit, killing\n with SIGKILL\n";
2033 sub teardown_env($$)
2035 my ($self, $envvars) = @_;
2036 teardown_env_terminate($self, $envvars);
2038 print $self->getlog_env($envvars);
2045 my ($self, $envvars) = @_;
2046 my $title = "SAMBA LOG of: $envvars->{NETBIOSNAME} pid $envvars->{SAMBA_PID}\n";
2049 open(LOG, "<$envvars->{SAMBA_TEST_LOG}");
2051 seek(LOG, $envvars->{SAMBA_TEST_LOG_POS}, SEEK_SET);
2055 $envvars->{SAMBA_TEST_LOG_POS} = tell(LOG);
2058 return "" if $out eq $title;
2065 my ($self, $envvars) = @_;
2066 my $samba_pid = $envvars->{SAMBA_PID};
2068 if (not defined($samba_pid)) {
2070 } elsif ($samba_pid > 0) {
2071 my $childpid = Samba::cleanup_child($samba_pid, "samba");
2073 if ($childpid == 0) {
2082 # Declare the environments Samba4 makes available.
2083 # To be set up, they will be called as
2084 # samba4->setup_$envname($self, $path, $dep_1_vars, $dep_2_vars, ...)
2085 # The interdependencies between the testenvs are declared below. Some testenvs
2086 # are dependent on another testenv running first, e.g. vampire_dc is dependent
2087 # on ad_dc_ntvfs because vampire_dc joins ad_dc_ntvfs's domain. All DCs are
2088 # dependent on dns_hub, which handles resolving DNS queries for the realm.
2089 %Samba4::ENV_DEPS = (
2090 # name => [dep_1, dep_2, ...],
2092 ad_dc_ntvfs => ["dns_hub"],
2093 ad_dc => ["dns_hub"],
2094 ad_dc_no_nss => ["dns_hub"],
2095 ad_dc_no_ntlm => ["dns_hub"],
2097 fl2008r2dc => ["ad_dc"],
2098 fl2003dc => ["ad_dc"],
2099 fl2000dc => ["dns_hub"],
2101 vampire_2000_dc => ["fl2000dc"],
2102 vampire_dc => ["ad_dc_ntvfs"],
2103 promoted_dc => ["ad_dc_ntvfs"],
2105 rodc => ["ad_dc_ntvfs"],
2106 rpc_proxy => ["ad_dc_ntvfs"],
2107 chgdcpass => ["dns_hub"],
2109 s4member_dflt_domain => ["ad_dc_ntvfs"],
2110 s4member => ["ad_dc_ntvfs"],
2112 # envs that test the server process model
2113 proclimitdc => ["dns_hub"],
2114 preforkrestartdc => ["dns_hub"],
2116 # backup/restore testenvs
2117 backupfromdc => ["dns_hub"],
2118 customdc => ["dns_hub"],
2119 restoredc => ["backupfromdc"],
2120 renamedc => ["backupfromdc"],
2121 offlinebackupdc => ["backupfromdc"],
2122 labdc => ["backupfromdc"],
2124 # aliases in order to split autbuild tasks
2125 fl2008dc => ["ad_dc"],
2126 ad_dc_default => ["ad_dc"],
2127 ad_dc_slowtests => ["ad_dc"],
2128 ad_dc_backup => ["ad_dc"],
2130 schema_dc => ["dns_hub"],
2131 schema_pair_dc => ["schema_dc"],
2136 %Samba4::ENV_DEPS_POST = (
2137 schema_dc => ["schema_pair_dc"],
2140 sub return_alias_env
2142 my ($self, $path, $env) = @_;
2150 my ($self, $path) = @_;
2152 my $extra_args = ["--base-schema=2008_R2"];
2153 my $env = $self->provision_ad_dc_ntvfs($path, $extra_args);
2155 if (not defined($self->check_or_start($env, "standard"))) {
2156 warn("Failed to start fl2008dc");
2163 sub setup_ad_dc_default
2165 my ($self, $path, $dep_env) = @_;
2166 return $self->return_alias_env($path, $dep_env)
2169 sub setup_ad_dc_slowtests
2171 my ($self, $path, $dep_env) = @_;
2172 return $self->return_alias_env($path, $dep_env)
2175 sub setup_ad_dc_backup
2177 my ($self, $path, $dep_env) = @_;
2178 return $self->return_alias_env($path, $dep_env)
2183 my ($self, $path, $dc_vars) = @_;
2185 my $env = $self->provision_s4member($path, $dc_vars, "s4member");
2188 if (not defined($self->check_or_start($env, "standard"))) {
2196 sub setup_s4member_dflt_domain
2198 my ($self, $path, $dc_vars) = @_;
2200 my $env = $self->provision_s4member($path, $dc_vars, "s4member_dflt",
2201 "winbind use default domain = yes");
2204 if (not defined($self->check_or_start($env, "standard"))) {
2214 my ($self, $path, $dc_vars) = @_;
2216 my $env = $self->provision_rpc_proxy($path, $dc_vars);
2219 if (not defined($self->check_or_start($env, "standard"))) {
2226 sub setup_ad_dc_ntvfs
2228 my ($self, $path) = @_;
2230 my $env = $self->provision_ad_dc_ntvfs($path, undef);
2232 if (not defined($self->check_or_start($env, "standard"))) {
2233 warn("Failed to start ad_dc_ntvfs");
2242 my ($self, $path) = @_;
2244 my $env = $self->provision_chgdcpass($path);
2246 if (not defined($self->check_or_start($env, "standard"))) {
2255 my ($self, $path) = @_;
2257 my $env = $self->provision_fl2000dc($path);
2259 if (not defined($self->check_or_start($env, "standard"))) {
2269 my ($self, $path, $dc_vars) = @_;
2271 my $env = $self->provision_fl2003dc($path);
2274 if (not defined($self->check_or_start($env, "standard"))) {
2278 $env = $self->setup_trust($env, $dc_vars, "external", "--no-aes-keys");
2283 sub setup_fl2008r2dc
2285 my ($self, $path, $dc_vars) = @_;
2287 my $env = $self->provision_fl2008r2dc($path);
2290 if (not defined($self->check_or_start($env, "standard"))) {
2294 my $upn_array = ["$env->{REALM}.upn"];
2295 my $spn_array = ["$env->{REALM}.spn"];
2297 $self->setup_namespaces($env, $upn_array, $spn_array);
2299 $env = $self->setup_trust($env, $dc_vars, "forest", "");
2305 sub setup_vampire_dc
2307 return setup_generic_vampire_dc(@_, "2008");
2310 sub setup_vampire_2000_dc
2312 return setup_generic_vampire_dc(@_, "2000");
2315 sub setup_generic_vampire_dc
2317 my ($self, $path, $dc_vars, $fl) = @_;
2319 my $env = $self->provision_vampire_dc($path, $dc_vars, $fl);
2322 if (not defined($self->check_or_start($env, "single"))) {
2326 # force replicated DC to update repsTo/repsFrom
2327 # for vampired partitions
2328 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2330 # as 'vampired' dc may add data in its local replica
2331 # we need to synchronize data between DCs
2332 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2333 my $cmd = $self->get_cmd_env_vars($env);
2334 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2335 $cmd .= " $dc_vars->{CONFIGURATION}";
2336 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2337 # replicate Configuration NC
2338 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2339 unless(system($cmd_repl) == 0) {
2340 warn("Failed to replicate\n$cmd_repl");
2343 # replicate Default NC
2344 $cmd_repl = "$cmd \"$base_dn\"";
2345 unless(system($cmd_repl) == 0) {
2346 warn("Failed to replicate\n$cmd_repl");
2350 # Pull in a full set of changes from the main DC
2351 $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2352 $cmd = $self->get_cmd_env_vars($env);
2353 $cmd .= " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}";
2354 $cmd .= " $dc_vars->{CONFIGURATION}";
2355 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2356 # replicate Configuration NC
2357 $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2358 unless(system($cmd_repl) == 0) {
2359 warn("Failed to replicate\n$cmd_repl");
2362 # replicate Default NC
2363 $cmd_repl = "$cmd \"$base_dn\"";
2364 unless(system($cmd_repl) == 0) {
2365 warn("Failed to replicate\n$cmd_repl");
2373 sub setup_promoted_dc
2375 my ($self, $path, $dc_vars) = @_;
2377 my $env = $self->provision_promoted_dc($path, $dc_vars);
2380 if (not defined($self->check_or_start($env, "single"))) {
2384 # force source and replicated DC to update repsTo/repsFrom
2385 # for vampired partitions
2386 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2387 my $cmd = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2388 # as 'vampired' dc may add data in its local replica
2389 # we need to synchronize data between DCs
2390 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2391 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2392 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2393 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2394 $cmd .= "RESOLV_CONF=\"$env->{RESOLV_CONF}\" ";
2395 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2396 $cmd .= " $dc_vars->{CONFIGURATION}";
2397 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2398 # replicate Configuration NC
2399 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2400 unless(system($cmd_repl) == 0) {
2401 warn("Failed to replicate\n$cmd_repl");
2404 # replicate Default NC
2405 $cmd_repl = "$cmd \"$base_dn\"";
2406 unless(system($cmd_repl) == 0) {
2407 warn("Failed to replicate\n$cmd_repl");
2417 my ($self, $path, $dc_vars) = @_;
2419 my $env = $self->provision_rodc($path, $dc_vars);
2425 if (not defined($self->check_or_start($env, "standard"))) {
2429 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2432 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2433 $cmd .= "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2434 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2435 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2436 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2437 $cmd .= "RESOLV_CONF=\"$env->{RESOLV_CONF}\" ";
2438 $cmd .= " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}";
2439 $cmd .= " $dc_vars->{CONFIGURATION}";
2440 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2441 # replicate Configuration NC
2442 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2443 unless(system($cmd_repl) == 0) {
2444 warn("Failed to replicate\n$cmd_repl");
2447 # replicate Default NC
2448 $cmd_repl = "$cmd \"$base_dn\"";
2449 unless(system($cmd_repl) == 0) {
2450 warn("Failed to replicate\n$cmd_repl");
2459 my ($self, $path) = @_;
2461 # If we didn't build with ADS, pretend this env was never available
2462 if (not $self->{target3}->have_ads()) {
2466 my $env = $self->provision_ad_dc($path, "addc", "ADDOMAIN",
2467 "addom.samba.example.com", "", undef);
2472 if (not defined($self->check_or_start($env, "prefork"))) {
2476 my $upn_array = ["$env->{REALM}.upn"];
2477 my $spn_array = ["$env->{REALM}.spn"];
2479 $self->setup_namespaces($env, $upn_array, $spn_array);
2484 sub setup_ad_dc_no_nss
2486 my ($self, $path) = @_;
2488 # If we didn't build with ADS, pretend this env was never available
2489 if (not $self->{target3}->have_ads()) {
2493 my $env = $self->provision_ad_dc($path, "addc_no_nss", "ADNONSSDOMAIN",
2494 "adnonssdom.samba.example.com", "", undef);
2499 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2500 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2502 if (not defined($self->check_or_start($env, "single"))) {
2506 my $upn_array = ["$env->{REALM}.upn"];
2507 my $spn_array = ["$env->{REALM}.spn"];
2509 $self->setup_namespaces($env, $upn_array, $spn_array);
2514 sub setup_ad_dc_no_ntlm
2516 my ($self, $path) = @_;
2518 # If we didn't build with ADS, pretend this env was never available
2519 if (not $self->{target3}->have_ads()) {
2523 my $env = $self->provision_ad_dc($path, "addc_no_ntlm", "ADNONTLMDOMAIN",
2524 "adnontlmdom.samba.example.com",
2525 "ntlm auth = disabled", undef);
2530 if (not defined($self->check_or_start($env, "prefork"))) {
2534 my $upn_array = ["$env->{REALM}.upn"];
2535 my $spn_array = ["$env->{REALM}.spn"];
2537 $self->setup_namespaces($env, $upn_array, $spn_array);
2543 # AD DC test environment used solely to test pre-fork process restarts.
2544 # As processes get killed off and restarted it should not be used for other
2545 sub setup_preforkrestartdc
2547 my ($self, $path) = @_;
2549 # If we didn't build with ADS, pretend this env was never available
2550 if (not $self->{target3}->have_ads()) {
2554 # note DC name must be <= 15 chars so we use 'prockill' instead of
2556 my $env = $self->provision_ad_dc(
2560 "prockilldom.samba.example.com",
2561 "prefork backoff increment = 5\nprefork maximum backoff=10");
2566 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2567 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2569 if (not defined($self->check_or_start($env, "prefork"))) {
2573 my $upn_array = ["$env->{REALM}.upn"];
2574 my $spn_array = ["$env->{REALM}.spn"];
2576 $self->setup_namespaces($env, $upn_array, $spn_array);
2582 # ad_dc test environment used solely to test standard process model connection
2583 # process limits. As the limit is set artificially low it should not be used
2585 sub setup_proclimitdc
2587 my ($self, $path) = @_;
2589 # If we didn't build with ADS, pretend this env was never available
2590 if (not $self->{target3}->have_ads()) {
2594 my $env = $self->provision_ad_dc(
2598 "proclimit.samba.example.com",
2599 "max smbd processes = 20");
2604 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2605 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2607 if (not defined($self->check_or_start($env, "standard"))) {
2611 my $upn_array = ["$env->{REALM}.upn"];
2612 my $spn_array = ["$env->{REALM}.spn"];
2614 $self->setup_namespaces($env, $upn_array, $spn_array);
2619 # Used to test a live upgrade of the schema on a 2 DC network.
2622 my ($self, $path) = @_;
2624 # provision the PDC using an older base schema
2625 my $provision_args = ["--base-schema=2008_R2", "--backend-store=mdb"];
2627 my $env = $self->provision_ad_dc($path, "liveupgrade1dc", "SCHEMADOMAIN",
2628 "schema.samba.example.com",
2629 "drs: max link sync = 2",
2635 if (not defined($self->check_or_start($env, "prefork"))) {
2639 my $upn_array = ["$env->{REALM}.upn"];
2640 my $spn_array = ["$env->{REALM}.spn"];
2642 $self->setup_namespaces($env, $upn_array, $spn_array);
2647 # the second DC in the live schema upgrade pair
2648 sub setup_schema_pair_dc
2650 # note: dcvars contains the env info for the dependent testenv ('schema_dc')
2651 my ($self, $prefix, $dcvars) = @_;
2652 print "Preparing SCHEMA UPGRADE PAIR DC...\n";
2654 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "liveupgrade2dc",
2657 $dcvars->{PASSWORD},
2660 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2661 my $cmd_vars = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2662 $cmd_vars .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2663 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2664 $cmd_vars .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2666 $cmd_vars .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2668 $cmd_vars .= "KRB5_CONFIG=\"$env->{KRB5_CONFIG}\" ";
2669 $cmd_vars .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2670 $cmd_vars .= "RESOLV_CONF=\"$env->{RESOLV_CONF}\" ";
2672 my $join_cmd = $cmd_vars;
2673 $join_cmd .= "$samba_tool domain join $env->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
2674 $join_cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} ";
2675 $join_cmd .= " --backend-store=mdb";
2677 my $upgrade_cmd = $cmd_vars;
2678 $upgrade_cmd .= "$samba_tool domain schemaupgrade $dcvars->{CONFIGURATION}";
2679 $upgrade_cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}";
2681 my $repl_cmd = $cmd_vars;
2682 $repl_cmd .= "$samba_tool drs replicate $env->{SERVER} $dcvars->{SERVER}";
2683 $repl_cmd .= " CN=Schema,CN=Configuration,DC=schema,DC=samba,DC=example,DC=com";
2684 $repl_cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
2686 unless (system($join_cmd) == 0) {
2687 warn("Join failed\n$join_cmd");
2691 $env->{DC_SERVER} = $dcvars->{SERVER};
2692 $env->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
2693 $env->{DC_SERVER_IPV6} = $dcvars->{SERVER_IPV6};
2694 $env->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
2696 # start samba for the new DC
2697 if (not defined($self->check_or_start($env, "standard"))) {
2701 unless (system($upgrade_cmd) == 0) {
2702 warn("Schema upgrade failed\n$upgrade_cmd");
2706 unless (system($repl_cmd) == 0) {
2707 warn("Post-update schema replication failed\n$repl_cmd");
2714 # Sets up a DC that's solely used to do a domain backup from. We then use the
2715 # backupfrom-DC to create the restore-DC - this proves that the backup/restore
2716 # process will create a Samba DC that will actually start up.
2717 # We don't use the backup-DC for anything else because its domain will conflict
2718 # with the restore DC.
2719 sub setup_backupfromdc
2721 my ($self, $path) = @_;
2723 # If we didn't build with ADS, pretend this env was never available
2724 if (not $self->{target3}->have_ads()) {
2728 my $provision_args = ["--site=Backup-Site"];
2730 my $env = $self->provision_ad_dc($path, "backupfromdc", "BACKUPDOMAIN",
2731 "backupdom.samba.example.com",
2732 "samba kcc command = /bin/true",
2738 if (not defined($self->check_or_start($env))) {
2742 my $upn_array = ["$env->{REALM}.upn"];
2743 my $spn_array = ["$env->{REALM}.spn"];
2745 $self->setup_namespaces($env, $upn_array, $spn_array);
2750 # returns the server/user-auth params needed to run an online backup cmd
2751 sub get_backup_server_args
2753 # dcvars contains the env info for the backup DC testenv
2754 my ($self, $dcvars) = @_;
2755 my $server = $dcvars->{DC_SERVER_IP};
2756 my $server_args = "--server=$server ";
2757 $server_args .= "-U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
2758 $server_args .= " $dcvars->{CONFIGURATION}";
2760 return $server_args;
2763 # Creates a backup of a running testenv DC
2766 # note: dcvars contains the env info for the backup DC testenv
2767 my ($self, $env, $dcvars, $backupdir, $backup_cmd) = @_;
2769 # get all the env variables we pass in with the samba-tool command
2770 my $cmd_env = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2771 $cmd_env .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2772 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2773 $cmd_env .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2775 $cmd_env .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2777 # Note: use the backupfrom-DC's krb5.conf to do the backup
2778 $cmd_env .= " KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
2779 $cmd_env .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2781 # use samba-tool to create a backup from the 'backupfromdc' DC
2783 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2785 $cmd .= "$cmd_env $samba_tool domain backup $backup_cmd";
2786 $cmd .= " --targetdir=$backupdir";
2788 print "Executing: $cmd\n";
2789 unless(system($cmd) == 0) {
2790 warn("Failed to create backup using: \n$cmd");
2794 # get the name of the backup file created
2795 opendir(DIR, $backupdir);
2796 my @files = grep(/\.tar/, readdir(DIR));
2799 if(scalar @files != 1) {
2800 warn("Backup file not found in directory $backupdir\n");
2803 my $backup_file = "$backupdir/$files[0]";
2804 print "Using backup file $backup_file...\n";
2806 return $backup_file;
2809 # Restores a backup-file to populate a testenv for a new DC
2810 sub restore_backup_file
2812 my ($self, $backup_file, $restore_opts, $restoredir, $smbconf) = @_;
2814 # pass the restore command the testenv's smb.conf that we've already
2815 # generated. But move it to a temp-dir first, so that the restore doesn't
2817 my $tmpdir = File::Temp->newdir();
2818 my $tmpconf = "$tmpdir/smb.conf";
2819 my $cmd = "cp $smbconf $tmpconf";
2820 unless(system($cmd) == 0) {
2821 warn("Failed to backup smb.conf using: \n$cmd");
2825 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2826 $cmd = "$samba_tool domain backup restore --backup-file=$backup_file";
2827 $cmd .= " --targetdir=$restoredir $restore_opts --configfile=$tmpconf";
2829 print "Executing: $cmd\n";
2830 unless(system($cmd) == 0) {
2831 warn("Failed to restore backup using: \n$cmd");
2835 print "Restore complete\n";
2839 # sets up the initial directory and returns the new testenv's env info
2840 # (without actually doing a 'domain join')
2841 sub prepare_dc_testenv
2843 my ($self, $prefix, $dcname, $domain, $realm,
2844 $password, $conf_options) = @_;
2846 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
2856 # the restore uses a slightly different state-dir location to other testenvs
2857 $ctx->{statedir} = "$ctx->{prefix_abs}/state";
2858 push(@{$ctx->{directories}}, "$ctx->{statedir}");
2860 # add support for sysvol/netlogon/tmp shares
2861 $ctx->{share} = "$ctx->{prefix_abs}/share";
2862 push(@{$ctx->{directories}}, "$ctx->{share}");
2863 push(@{$ctx->{directories}}, "$ctx->{share}/test1");
2865 $ctx->{smb_conf_extra_options} = "
2868 server max protocol = SMB2
2869 samba kcc command = /bin/true
2870 xattr_tdb:file = $ctx->{statedir}/xattr.tdb
2873 path = $ctx->{statedir}/sysvol
2877 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
2881 path = $ctx->{share}
2883 posix:sharedelay = 10000
2884 posix:oplocktimeout = 3
2885 posix:writetimeupdatedelay = 50000
2888 path = $ctx->{share}/test1
2890 posix:sharedelay = 100000
2891 posix:oplocktimeout = 3
2892 posix:writetimeupdatedelay = 500000
2895 my $env = $self->provision_raw_step1($ctx);
2897 return ($env, $ctx);
2901 # Set up a DC testenv solely by using the samba-tool domain backup/restore
2902 # commands. This proves that we can backup an online DC ('backupfromdc') and
2903 # use the backup file to create a valid, working samba DC.
2906 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
2907 my ($self, $prefix, $dcvars) = @_;
2908 print "Preparing RESTORE DC...\n";
2910 # we arbitrarily designate the restored DC as having SMBv1 disabled
2912 server min protocol = SMB2
2913 client min protocol = SMB2
2914 prefork children = 1";
2916 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "restoredc",
2919 $dcvars->{PASSWORD},
2922 # create a backup of the 'backupfromdc'
2923 my $backupdir = File::Temp->newdir();
2924 my $server_args = $self->get_backup_server_args($dcvars);
2925 my $backup_args = "online $server_args";
2926 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
2928 unless($backup_file) {
2932 # restore the backup file to populate the restore-DC testenv
2933 my $restore_dir = abs_path($prefix);
2934 my $ret = $self->restore_backup_file($backup_file,
2935 "--newservername=$env->{SERVER}",
2936 $restore_dir, $env->{SERVERCONFFILE});
2937 unless ($ret == 0) {
2941 # start samba for the restored DC
2942 if (not defined($self->check_or_start($env))) {
2949 # Set up a DC testenv solely by using the 'samba-tool domain backup rename' and
2950 # restore commands. This proves that we can backup and rename an online DC
2951 # ('backupfromdc') and use the backup file to create a valid, working samba DC.
2954 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
2955 my ($self, $prefix, $dcvars) = @_;
2956 print "Preparing RENAME DC...\n";
2957 my $extra_conf = "prefork children = 1";
2959 my $realm = "renamedom.samba.example.com";
2960 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "renamedc",
2961 "RENAMEDOMAIN", $realm,
2962 $dcvars->{PASSWORD}, $extra_conf);
2964 # create a backup of the 'backupfromdc' which renames the domain
2965 my $backupdir = File::Temp->newdir();
2966 my $server_args = $self->get_backup_server_args($dcvars);
2967 my $backup_args = "rename $env->{DOMAIN} $env->{REALM} $server_args";
2968 $backup_args .= " --backend-store=tdb";
2969 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
2971 unless($backup_file) {
2975 # restore the backup file to populate the rename-DC testenv
2976 my $restore_dir = abs_path($prefix);
2977 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
2978 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
2979 $restore_dir, $env->{SERVERCONFFILE});
2980 unless ($ret == 0) {
2984 # start samba for the restored DC
2985 if (not defined($self->check_or_start($env))) {
2989 my $upn_array = ["$env->{REALM}.upn"];
2990 my $spn_array = ["$env->{REALM}.spn"];
2992 $self->setup_namespaces($env, $upn_array, $spn_array);
2997 # Set up a DC testenv solely by using the 'samba-tool domain backup offline' and
2998 # restore commands. This proves that we do an offline backup of a local DC
2999 # ('backupfromdc') and use the backup file to create a valid, working samba DC.
3000 sub setup_offlinebackupdc
3002 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
3003 my ($self, $prefix, $dcvars) = @_;
3004 print "Preparing OFFLINE BACKUP DC...\n";
3005 my $extra_conf = "prefork children = 1";
3007 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "offlinebackupdc",
3010 $dcvars->{PASSWORD}, $extra_conf);
3012 # create an offline backup of the 'backupfromdc' target
3013 my $backupdir = File::Temp->newdir();
3014 my $cmd = "offline -s $dcvars->{SERVERCONFFILE}";
3015 my $backup_file = $self->create_backup($env, $dcvars,
3018 unless($backup_file) {
3022 # restore the backup file to populate the rename-DC testenv
3023 my $restore_dir = abs_path($prefix);
3024 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
3025 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
3026 $restore_dir, $env->{SERVERCONFFILE});
3027 unless ($ret == 0) {
3031 # re-create the testenv's krb5.conf (the restore may have overwritten it)
3032 Samba::mk_krb5_conf($ctx);
3034 # start samba for the restored DC
3035 if (not defined($self->check_or_start($env))) {
3042 # Set up a DC testenv solely by using the samba-tool 'domain backup rename' and
3043 # restore commands, using the --no-secrets option. This proves that we can
3044 # create a realistic lab environment from an online DC ('backupfromdc').
3047 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
3048 my ($self, $prefix, $dcvars) = @_;
3049 print "Preparing LAB-DOMAIN DC...\n";
3050 my $extra_conf = "prefork children = 1";
3052 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "labdc",
3054 "labdom.samba.example.com",
3055 $dcvars->{PASSWORD}, $extra_conf);
3057 # create a backup of the 'backupfromdc' which renames the domain and uses
3058 # the --no-secrets option to scrub any sensitive info
3059 my $backupdir = File::Temp->newdir();
3060 my $server_args = $self->get_backup_server_args($dcvars);
3061 my $backup_args = "rename $env->{DOMAIN} $env->{REALM} $server_args";
3062 $backup_args .= " --no-secrets --backend-store=mdb";
3063 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
3065 unless($backup_file) {
3069 # restore the backup file to populate the lab-DC testenv
3070 my $restore_dir = abs_path($prefix);
3071 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
3072 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
3073 $restore_dir, $env->{SERVERCONFFILE});
3074 unless ($ret == 0) {
3078 # because we don't include any secrets in the backup, we need to reset the
3079 # admin user's password back to what the testenv expects
3080 my $samba_tool = Samba::bindir_path($self, "samba-tool");
3081 my $cmd = "$samba_tool user setpassword $env->{USERNAME} ";
3082 $cmd .= "--newpassword=$env->{PASSWORD} -H $restore_dir/private/sam.ldb";
3083 $cmd .= " $env->{CONFIGURATION}";
3085 unless(system($cmd) == 0) {
3086 warn("Failed to reset admin's password: \n$cmd");
3090 # start samba for the restored DC
3091 if (not defined($self->check_or_start($env))) {
3095 my $upn_array = ["$env->{REALM}.upn"];
3096 my $spn_array = ["$env->{REALM}.spn"];
3098 $self->setup_namespaces($env, $upn_array, $spn_array);
3103 # Inspects a backup *.tar.bz2 file and determines the realm/domain it contains
3104 sub get_backup_domain_realm
3106 my ($self, $backup_file) = @_;
3108 print "Determining REALM/DOMAIN values in backup...\n";
3110 # The backup will have the correct domain/realm values in the smb.conf.
3111 # So we can work out the env variables the testenv should use based on
3112 # that. Let's start by extracting the smb.conf
3113 my $tar = Archive::Tar->new($backup_file);
3114 my $tmpdir = File::Temp->newdir();
3115 my $smbconf = "$tmpdir/smb.conf";
3117 # note that the filepaths within the tar-file differ slightly for online
3118 # and offline backups
3119 if ($tar->contains_file("etc/smb.conf")) {
3120 $tar->extract_file("etc/smb.conf", $smbconf);
3121 } elsif ($tar->contains_file("./etc/smb.conf")) {
3122 $tar->extract_file("./etc/smb.conf", $smbconf);
3124 warn("Could not find smb.conf in $backup_file");
3125 return undef, undef;
3128 # make sure we don't try to create locks/sockets in the default install
3129 # location (i.e. /usr/local/samba/)
3130 my $options = "--option=\"private dir = $tmpdir\"";
3131 $options .= " --option=\"lock dir = $tmpdir\"";
3133 # now use testparm to read the values we're interested in
3134 my $testparm = Samba::bindir_path($self, "testparm");
3135 my $domain = `$testparm $smbconf -sl --parameter-name=WORKGROUP $options`;
3136 my $realm = `$testparm $smbconf -sl --parameter-name=REALM $options`;
3139 print "Backup-file REALM is $realm, DOMAIN is $domain\n";
3141 return ($domain, $realm);
3144 # This spins up a custom testenv that can be based on any backup-file you want.
3145 # This is just intended for manual testing (rather than automated test-cases)
3148 my ($self, $prefix) = @_;
3149 print "Preparing CUSTOM RESTORE DC...\n";
3150 my $dc_name = "customdc";
3151 my $password = "locDCpass1";
3152 my $backup_file = $ENV{'BACKUP_FILE'};
3154 # user must specify a backup file to restore via an ENV variable, i.e.
3155 # BACKUP_FILE=backup-blah.tar.bz2 SELFTEST_TESTENV=customdc make testenv
3156 if (not defined($backup_file)) {
3157 warn("Please specify BACKUP_FILE");
3161 # work out the correct domain/realm env values from the backup-file
3162 my ($domain, $realm) = $self->get_backup_domain_realm($backup_file);
3163 if ($domain eq '' or $realm eq '') {
3164 warn("Could not determine domain or realm");
3168 # create a placeholder directory and smb.conf, as well as the env vars.
3169 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, $dc_name,
3170 $domain, $realm, $password, "");
3172 # restore the specified backup file to populate the testenv
3173 my $restore_dir = abs_path($prefix);
3174 my $ret = $self->restore_backup_file($backup_file,
3175 "--newservername=$env->{SERVER}",
3176 $restore_dir, $env->{SERVERCONFFILE});
3177 unless ($ret == 0) {
3181 # Change the admin password to the testenv default, just in case it's
3182 # different, or in case this was a --no-secrets backup
3183 my $samba_tool = Samba::bindir_path($self, "samba-tool");
3184 my $cmd = "$samba_tool user setpassword $env->{USERNAME} ";
3185 $cmd .= "--newpassword=$password -H $restore_dir/private/sam.ldb";
3186 $cmd .= " $env->{CONFIGURATION}";
3188 unless(system($cmd) == 0) {
3189 warn("Failed to reset admin's password: \n$cmd");
3193 # re-create the testenv's krb5.conf (the restore may have overwritten it,
3194 # if the backup-file was an offline backup)
3195 Samba::mk_krb5_conf($ctx);
3197 # start samba for the restored DC
3198 if (not defined($self->check_or_start($env))) {
3202 # if this was a backup-rename, then we may need to setup namespaces
3203 my $upn_array = ["$env->{REALM}.upn"];
3204 my $spn_array = ["$env->{REALM}.spn"];
3206 $self->setup_namespaces($env, $upn_array, $spn_array);
3213 my ($self, $path) = @_;
3216 KRB5_CONFIG => abs_path($path) . "/no_krb5.conf",