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, $SambaCtx, $bindir, $srcdir, $server_maxtime) = @_;
27 SambaCtx => $SambaCtx,
30 server_maxtime => $server_maxtime,
31 target3 => new Samba3($SambaCtx, $bindir, $srcdir, $server_maxtime)
37 sub scriptdir_path($$) {
38 my ($self, $path) = @_;
39 return "$self->{srcdir}/source4/scripting/$path";
42 sub check_or_start($$$)
44 my ($self, $env_vars, $process_model) = @_;
47 my $env_ok = $self->check_env($env_vars);
49 return $env_vars->{SAMBA_PID};
50 } elsif (defined($env_vars->{SAMBA_PID})) {
51 warn("SAMBA PID $env_vars->{SAMBA_PID} is not running (died)");
55 # use a pipe for stdin in the child processes. This allows
56 # those processes to monitor the pipe for EOF to ensure they
57 # exit when the test script exits
58 pipe($STDIN_READER, $env_vars->{STDIN_PIPE});
60 # build up the command to run samba
63 if (defined($ENV{SAMBA_OPTIONS})) {
64 @optargs = split(/ /, $ENV{SAMBA_OPTIONS});
66 if(defined($ENV{SAMBA_VALGRIND})) {
67 @preargs = split(/ /,$ENV{SAMBA_VALGRIND});
70 if (defined($process_model)) {
71 push @optargs, ("-M", $process_model);
73 my $binary = Samba::bindir_path($self, "samba");
74 my @full_cmd = (@preargs, $binary, "-i",
75 "--no-process-group", "--maximum-runtime=$self->{server_maxtime}",
76 $env_vars->{CONFIGURATION}, @optargs);
78 # the samba process takes some additional env variables (compared to s3)
79 my $samba_envs = Samba::get_env_for_process("samba", $env_vars);
80 if (defined($ENV{MITKRB5})) {
81 $samba_envs->{KRB5_KDC_PROFILE} = $env_vars->{MITKDC_CONFIG};
84 # fork a child process and exec() samba
87 BINARY_PATH => $binary,
88 FULL_CMD => [ @full_cmd ],
89 LOG_FILE => $env_vars->{SAMBA_TEST_LOG},
91 PCAP_FILE => "env-$ENV{ENVNAME}-samba",
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;
302 $ctx->{resolv_conf} = $env->{RESOLV_CONF};
303 $ctx->{dns_ipv4} = $env->{SERVER_IP};
304 $ctx->{dns_ipv6} = $env->{SERVER_IPV6};
305 Samba::mk_resolv_conf($ctx);
309 if (!defined($ENV{PYTHON})) {
310 push (@preargs, "env");
311 push (@preargs, "python");
313 push (@preargs, $ENV{PYTHON});
315 my $binary = "$self->{srcdir}/selftest/target/dns_hub.py";
316 push (@args, "$self->{server_maxtime}");
317 push (@args, "$env->{SERVER_IP}");
318 push (@args, Samba::realm_to_ip_mappings());
319 my @full_cmd = (@preargs, $binary, @args);
323 BINARY_PATH => $binary,
324 FULL_CMD => [ @full_cmd ],
325 LOG_FILE => $env->{DNS_HUB_LOG},
327 PCAP_FILE => "env-$ENV{ENVNAME}-dns_hub",
331 # use a pipe for stdin in the child processes. This allows
332 # those processes to monitor the pipe for EOF to ensure they
333 # exit when the test script exits
334 pipe($STDIN_READER, $env->{STDIN_PIPE});
336 my $pid = Samba::fork_and_exec($self, $env, $daemon_ctx, $STDIN_READER);
338 $env->{SAMBA_PID} = $pid;
339 $env->{KRB5_CONFIG} = "$prefix_abs/no_krb5.conf";
341 # close the parent's read-end of the pipe
342 close($STDIN_READER);
349 my ($self, $prefix) = @_;
351 my $hostname = "rootdnsforwarder";
353 my $env = $self->setup_dns_hub_internal("$hostname", "$prefix/$hostname");
355 $self->{dns_hub_env} = $env;
360 sub get_dns_hub_env($)
362 my ($self, $prefix) = @_;
364 if (defined($self->{dns_hub_env})) {
365 return $self->{dns_hub_env};
368 die("get_dns_hub_env() not setup 'dns_hub_env'");
372 # Returns the environmental variables that we pass to samba-tool commands
375 my ($self, $localenv) = @_;
377 my $cmd_env = "NSS_WRAPPER_HOSTS='$localenv->{NSS_WRAPPER_HOSTS}' ";
378 $cmd_env .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$localenv->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
379 if (defined($localenv->{RESOLV_WRAPPER_CONF})) {
380 $cmd_env .= "RESOLV_WRAPPER_CONF=\"$localenv->{RESOLV_WRAPPER_CONF}\" ";
382 $cmd_env .= "RESOLV_WRAPPER_HOSTS=\"$localenv->{RESOLV_WRAPPER_HOSTS}\" ";
384 $cmd_env .= " KRB5_CONFIG=\"$localenv->{KRB5_CONFIG}\" ";
385 $cmd_env .= "KRB5CCNAME=\"$localenv->{KRB5_CCACHE}\" ";
386 $cmd_env .= "RESOLV_CONF=\"$localenv->{RESOLV_CONF}\" ";
391 # Sets up a forest trust namespace.
392 # (Note this is different to kernel namespaces, setup by the
393 # USE_NAMESPACES=1 option)
396 my ($self, $localenv, $upn_array, $spn_array) = @_;
398 @{$upn_array} = [] unless defined($upn_array);
400 foreach my $upn (@{$upn_array}) {
401 $upn_args .= " --add-upn-suffix=$upn";
404 @{$spn_array} = [] unless defined($spn_array);
406 foreach my $spn (@{$spn_array}) {
407 $spn_args .= " --add-spn-suffix=$spn";
410 my $samba_tool = Samba::bindir_path($self, "samba-tool");
412 my $cmd_env = $self->get_cmd_env_vars($localenv);
414 my $cmd_config = " $localenv->{CONFIGURATION}";
416 my $namespaces = $cmd_env;
417 $namespaces .= " $samba_tool domain trust namespaces $upn_args $spn_args";
418 $namespaces .= $cmd_config;
419 unless (system($namespaces) == 0) {
420 warn("Failed to add namespaces \n$namespaces");
427 sub setup_trust($$$$$)
429 my ($self, $localenv, $remoteenv, $type, $extra_args) = @_;
431 $localenv->{TRUST_SERVER} = $remoteenv->{SERVER};
433 $localenv->{TRUST_USERNAME} = $remoteenv->{USERNAME};
434 $localenv->{TRUST_PASSWORD} = $remoteenv->{PASSWORD};
435 $localenv->{TRUST_DOMAIN} = $remoteenv->{DOMAIN};
436 $localenv->{TRUST_REALM} = $remoteenv->{REALM};
437 $localenv->{TRUST_DOMSID} = $remoteenv->{DOMSID};
439 my $samba_tool = Samba::bindir_path($self, "samba-tool");
442 my $cmd_env = $self->get_cmd_env_vars($localenv);
444 my $cmd_config = " $localenv->{CONFIGURATION}";
445 my $cmd_creds = $cmd_config;
446 $cmd_creds .= " -U$localenv->{TRUST_DOMAIN}\\\\$localenv->{TRUST_USERNAME}\%$localenv->{TRUST_PASSWORD}";
448 my $create = $cmd_env;
449 $create .= " $samba_tool domain trust create --type=${type} $localenv->{TRUST_REALM}";
450 $create .= " $extra_args";
451 $create .= $cmd_creds;
452 unless (system($create) == 0) {
453 warn("Failed to create trust \n$create");
457 my $groupname = "g_$localenv->{TRUST_DOMAIN}";
458 my $groupadd = $cmd_env;
459 $groupadd .= " $samba_tool group add '$groupname' --group-scope=Domain $cmd_config";
460 unless (system($groupadd) == 0) {
461 warn("Failed to create group \n$groupadd");
464 my $groupmem = $cmd_env;
465 $groupmem .= " $samba_tool group addmembers '$groupname' '$localenv->{TRUST_DOMSID}-513' $cmd_config";
466 unless (system($groupmem) == 0) {
467 warn("Failed to add group member \n$groupmem");
474 sub provision_raw_prepare($$$$$$$$$$$$)
476 my ($self, $prefix, $server_role, $hostname,
477 $domain, $realm, $samsid, $functional_level,
478 $password, $kdc_ipv4, $kdc_ipv6) = @_;
481 if (defined $ENV{PYTHON}) {
482 $python_cmd = $ENV{PYTHON} . " ";
484 $ctx->{python} = $python_cmd;
485 my $netbiosname = uc($hostname);
487 unless(-d $prefix or mkdir($prefix, 0777)) {
488 warn("Unable to create $prefix");
491 my $prefix_abs = abs_path($prefix);
493 die ("prefix=''") if $prefix_abs eq "";
494 die ("prefix='/'") if $prefix_abs eq "/";
496 unless (system("rm -rf $prefix_abs/*") == 0) {
497 warn("Unable to clean up");
501 my $swiface = Samba::get_interface($hostname);
503 $ctx->{prefix} = $prefix;
504 $ctx->{prefix_abs} = $prefix_abs;
506 $ctx->{server_role} = $server_role;
507 $ctx->{hostname} = $hostname;
508 $ctx->{netbiosname} = $netbiosname;
509 $ctx->{swiface} = $swiface;
510 $ctx->{password} = $password;
511 $ctx->{kdc_ipv4} = $kdc_ipv4;
512 $ctx->{kdc_ipv6} = $kdc_ipv6;
513 $ctx->{krb5_ccname} = "$prefix_abs/krb5cc_%{uid}";
514 if ($functional_level eq "2000") {
515 $ctx->{supported_enctypes} = "arcfour-hmac-md5 des-cbc-md5 des-cbc-crc"
519 # Set smbd log level here.
521 $ctx->{server_loglevel} =$ENV{SERVER_LOG_LEVEL} || 1;
522 $ctx->{username} = "Administrator";
523 $ctx->{domain} = $domain;
524 $ctx->{realm} = uc($realm);
525 $ctx->{dnsname} = lc($realm);
526 $ctx->{samsid} = $samsid;
528 $ctx->{functional_level} = $functional_level;
530 my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `whoami`);
532 $ctx->{unix_name} = $unix_name;
533 $ctx->{unix_uid} = $>;
534 my @mygid = split(" ", $();
535 $ctx->{unix_gid} = $mygid[0];
536 $ctx->{unix_gids_str} = $);
537 @{$ctx->{unix_gids}} = split(" ", $ctx->{unix_gids_str});
539 $ctx->{etcdir} = "$prefix_abs/etc";
540 $ctx->{piddir} = "$prefix_abs/pid";
541 $ctx->{smb_conf} = "$ctx->{etcdir}/smb.conf";
542 $ctx->{krb5_conf} = "$ctx->{etcdir}/krb5.conf";
543 $ctx->{krb5_ccache} = "$prefix_abs/krb5_ccache";
544 $ctx->{mitkdc_conf} = "$ctx->{etcdir}/mitkdc.conf";
545 $ctx->{privatedir} = "$prefix_abs/private";
546 $ctx->{binddnsdir} = "$prefix_abs/bind-dns";
547 $ctx->{ncalrpcdir} = "$prefix_abs/ncalrpc";
548 $ctx->{lockdir} = "$prefix_abs/lockdir";
549 $ctx->{logdir} = "$prefix_abs/logs";
550 $ctx->{statedir} = "$prefix_abs/statedir";
551 $ctx->{cachedir} = "$prefix_abs/cachedir";
552 $ctx->{winbindd_socket_dir} = "$prefix_abs/winbindd_socket";
553 $ctx->{ntp_signd_socket_dir} = "$prefix_abs/ntp_signd_socket";
554 $ctx->{nsswrap_passwd} = "$ctx->{etcdir}/passwd";
555 $ctx->{nsswrap_group} = "$ctx->{etcdir}/group";
556 $ctx->{nsswrap_hosts} = "$ENV{SELFTEST_PREFIX}/hosts";
557 $ctx->{nsswrap_hostname} = "$ctx->{hostname}.$ctx->{dnsname}";
558 if ($ENV{SAMBA_DNS_FAKING}) {
559 $ctx->{dns_host_file} = "$ENV{SELFTEST_PREFIX}/dns_host_file";
560 $ctx->{samba_dnsupdate} = "$ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate -s $ctx->{smb_conf} --all-interfaces --use-file=$ctx->{dns_host_file}";
561 $ctx->{samba_dnsupdate} = $python_cmd . $ctx->{samba_dnsupdate};
563 $ctx->{samba_dnsupdate} = "$ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate -s $ctx->{smb_conf} --all-interfaces";
564 $ctx->{samba_dnsupdate} = $python_cmd . $ctx->{samba_dnsupdate};
565 $ctx->{use_resolv_wrapper} = 1;
568 my $dns_hub = $self->get_dns_hub_env();
569 $ctx->{resolv_conf} = $dns_hub->{RESOLV_CONF};
571 $ctx->{tlsdir} = "$ctx->{privatedir}/tls";
573 $ctx->{ipv4} = Samba::get_ipv4_addr($hostname);
574 $ctx->{ipv6} = Samba::get_ipv6_addr($hostname);
576 push(@{$ctx->{directories}}, $ctx->{privatedir});
577 push(@{$ctx->{directories}}, $ctx->{binddnsdir});
578 push(@{$ctx->{directories}}, $ctx->{etcdir});
579 push(@{$ctx->{directories}}, $ctx->{piddir});
580 push(@{$ctx->{directories}}, $ctx->{lockdir});
581 push(@{$ctx->{directories}}, $ctx->{logdir});
582 push(@{$ctx->{directories}}, $ctx->{statedir});
583 push(@{$ctx->{directories}}, $ctx->{cachedir});
585 $ctx->{smb_conf_extra_options} = "";
587 my @provision_options = ();
588 push (@provision_options, "KRB5_CONFIG=\"$ctx->{krb5_conf}\"");
589 push (@provision_options, "KRB5_CCACHE=\"$ctx->{krb5_ccache}\"");
590 push (@provision_options, "NSS_WRAPPER_PASSWD=\"$ctx->{nsswrap_passwd}\"");
591 push (@provision_options, "NSS_WRAPPER_GROUP=\"$ctx->{nsswrap_group}\"");
592 push (@provision_options, "NSS_WRAPPER_HOSTS=\"$ctx->{nsswrap_hosts}\"");
593 push (@provision_options, "NSS_WRAPPER_HOSTNAME=\"$ctx->{nsswrap_hostname}\"");
594 if (defined($ctx->{use_resolv_wrapper})) {
595 push (@provision_options, "RESOLV_WRAPPER_CONF=\"$ctx->{resolv_conf}\"");
596 push (@provision_options, "RESOLV_CONF=\"$ctx->{resolv_conf}\"");
598 push (@provision_options, "RESOLV_WRAPPER_HOSTS=\"$ctx->{dns_host_file}\"");
600 if (defined($ENV{GDB_PROVISION})) {
601 push (@provision_options, "gdb --args");
602 if (!defined($ENV{PYTHON})) {
603 push (@provision_options, "env");
604 push (@provision_options, "python");
607 if (defined($ENV{VALGRIND_PROVISION})) {
608 push (@provision_options, "valgrind");
609 if (!defined($ENV{PYTHON})) {
610 push (@provision_options, "env");
611 push (@provision_options, "python");
615 my $samba_tool = Samba::bindir_path($self, "samba-tool");
617 push (@provision_options, $samba_tool);
618 push (@provision_options, "domain");
619 push (@provision_options, "provision");
620 push (@provision_options, "--configfile=$ctx->{smb_conf}");
621 push (@provision_options, "--host-name=$ctx->{hostname}");
622 push (@provision_options, "--host-ip=$ctx->{ipv4}");
623 push (@provision_options, "--quiet");
624 push (@provision_options, "--domain=$ctx->{domain}");
625 push (@provision_options, "--realm=$ctx->{realm}");
626 if (defined($ctx->{samsid})) {
627 push (@provision_options, "--domain-sid=$ctx->{samsid}");
629 push (@provision_options, "--adminpass=$ctx->{password}");
630 push (@provision_options, "--krbtgtpass=krbtgt$ctx->{password}");
631 push (@provision_options, "--machinepass=machine$ctx->{password}");
632 push (@provision_options, "--root=$ctx->{unix_name}");
633 push (@provision_options, "--server-role=\"$ctx->{server_role}\"");
634 push (@provision_options, "--function-level=\"$ctx->{functional_level}\"");
636 @{$ctx->{provision_options}} = @provision_options;
643 my ($self, $keyword, @options_list) = @_;
645 # convert the options-list to a hash-map for easy keyword lookup
646 my %options_dict = map { $_ => 1 } @options_list;
648 return exists $options_dict{$keyword};
652 # Step1 creates the basic configuration
654 sub provision_raw_step1($$)
656 my ($self, $ctx) = @_;
658 mkdir($_, 0777) foreach (@{$ctx->{directories}});
661 ## lockdir and piddir must be 0755
663 chmod 0755, $ctx->{lockdir};
664 chmod 0755, $ctx->{piddir};
666 unless (open(CONFFILE, ">$ctx->{smb_conf}")) {
667 warn("can't open $ctx->{smb_conf}$?");
671 Samba::prepare_keyblobs($ctx);
672 my $crlfile = "$ctx->{tlsdir}/crl.pem";
673 $crlfile = "" unless -e ${crlfile};
675 # work out which file server to use. Default to source3 smbd (s3fs),
676 # unless the source4 NTVFS (smb) file server has been specified
677 my $services = "-smb +s3fs";
678 if ($self->has_option("--use-ntvfs", @{$ctx->{provision_options}})) {
679 $services = "+smb -s3fs";
682 my $interfaces = Samba::get_interfaces_config($ctx->{netbiosname});
686 netbios name = $ctx->{netbiosname}
687 posix:eadb = $ctx->{statedir}/eadb.tdb
688 workgroup = $ctx->{domain}
689 realm = $ctx->{realm}
690 private dir = $ctx->{privatedir}
691 binddns dir = $ctx->{binddnsdir}
692 pid directory = $ctx->{piddir}
693 ncalrpc dir = $ctx->{ncalrpcdir}
694 lock dir = $ctx->{lockdir}
695 state directory = $ctx->{statedir}
696 cache directory = $ctx->{cachedir}
697 winbindd socket directory = $ctx->{winbindd_socket_dir}
698 ntp signd socket directory = $ctx->{ntp_signd_socket_dir}
699 winbind separator = /
700 interfaces = $interfaces
701 tls dh params file = $ctx->{tlsdir}/dhparms.pem
702 tls crlfile = ${crlfile}
703 tls verify peer = no_check
704 panic action = $RealBin/gdb_backtrace \%d
706 server role = $ctx->{server_role}
707 server services = +echo $services
708 dcerpc endpoint servers = +winreg +srvsvc
709 notify:inotify = false
711 ldap server require strong auth = yes
712 #We don't want to pass our self-tests if the PAC code is wrong
713 gensec:require_pac = true
714 log file = $ctx->{logdir}/log.\%m
715 log level = $ctx->{server_loglevel}
718 client min protocol = CORE
719 server min protocol = LANMAN1
721 dns update command = $ctx->{samba_dnsupdate}
722 spn update command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_spnupdate -s $ctx->{smb_conf}
723 gpo update command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba-gpupdate -s $ctx->{smb_conf} --target=Computer
724 samba kcc command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_kcc
725 dreplsrv:periodic_startup_interval = 0
726 dsdb:schema update allowed = yes
728 vfs objects = dfs_samba4 acl_xattr fake_acls xattr_tdb streams_depot
730 idmap_ldb:use rfc2307=yes
731 winbind enum users = yes
732 winbind enum groups = yes
734 rpc server port:netlogon = 1026
735 include system krb5 conf = no
741 # Begin extra options
742 $ctx->{smb_conf_extra_options}
747 #Default the KDC IP to the server's IP
748 if (not defined($ctx->{kdc_ipv4})) {
749 $ctx->{kdc_ipv4} = $ctx->{ipv4};
751 if (not defined($ctx->{kdc_ipv6})) {
752 $ctx->{kdc_ipv6} = $ctx->{ipv6};
755 Samba::mk_krb5_conf($ctx);
756 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
758 open(PWD, ">$ctx->{nsswrap_passwd}");
759 if ($ctx->{unix_uid} != 0) {
760 print PWD "root:x:0:0:root gecos:$ctx->{prefix_abs}:/bin/false\n";
762 print PWD "$ctx->{unix_name}:x:$ctx->{unix_uid}:65531:$ctx->{unix_name} gecos:$ctx->{prefix_abs}:/bin/false\n";
763 print PWD "nobody:x:65534:65533:nobody gecos:$ctx->{prefix_abs}:/bin/false
764 pdbtest:x:65533:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
765 pdbtest2:x:65532:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
766 pdbtest3:x:65531:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
767 pdbtest4:x:65530:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
770 my $uid_rfc2307test = 65533;
772 open(GRP, ">$ctx->{nsswrap_group}");
773 if ($ctx->{unix_gid} != 0) {
774 print GRP "root:x:0:\n";
776 print GRP "$ctx->{unix_name}:x:$ctx->{unix_gid}:\n";
777 print GRP "wheel:x:10:
780 nogroup:x:65534:nobody
783 my $gid_rfc2307test = 65532;
785 my $hostname = lc($ctx->{hostname});
786 open(HOSTS, ">>$ctx->{nsswrap_hosts}");
787 if ($hostname eq "localdc") {
788 print HOSTS "$ctx->{ipv4} ${hostname}.$ctx->{dnsname} $ctx->{dnsname} ${hostname}\n";
789 print HOSTS "$ctx->{ipv6} ${hostname}.$ctx->{dnsname} $ctx->{dnsname} ${hostname}\n";
791 print HOSTS "$ctx->{ipv4} ${hostname}.$ctx->{dnsname} ${hostname}\n";
792 print HOSTS "$ctx->{ipv6} ${hostname}.$ctx->{dnsname} ${hostname}\n";
796 my $configuration = "--configfile=$ctx->{smb_conf}";
798 #Ensure the config file is valid before we start
799 my $testparm = Samba::bindir_path($self, "samba-tool") . " testparm";
800 if (system("$testparm $configuration -v --suppress-prompt >/dev/null 2>&1") != 0) {
801 system("$testparm -v --suppress-prompt $configuration >&2");
802 warn("Failed to create a valid smb.conf configuration $testparm!");
805 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) {
806 warn("Failed to create a valid smb.conf configuration! $testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global");
810 # Return the environment variables for the new testenv DC.
811 # Note that we have SERVER_X and DC_SERVER_X variables (which have the same
812 # value initially). In a 2 DC setup, $DC_SERVER_X will always be the PDC.
814 KRB5_CONFIG => $ctx->{krb5_conf},
815 KRB5_CCACHE => $ctx->{krb5_ccache},
816 MITKDC_CONFIG => $ctx->{mitkdc_conf},
817 PIDDIR => $ctx->{piddir},
818 SERVER => $ctx->{hostname},
819 DC_SERVER => $ctx->{hostname},
820 SERVER_IP => $ctx->{ipv4},
821 DC_SERVER_IP => $ctx->{ipv4},
822 SERVER_IPV6 => $ctx->{ipv6},
823 DC_SERVER_IPV6 => $ctx->{ipv6},
824 NETBIOSNAME => $ctx->{netbiosname},
825 DC_NETBIOSNAME => $ctx->{netbiosname},
826 DOMAIN => $ctx->{domain},
827 USERNAME => $ctx->{username},
828 DC_USERNAME => $ctx->{username},
829 REALM => $ctx->{realm},
830 DNSNAME => $ctx->{dnsname},
831 SAMSID => $ctx->{samsid},
832 PASSWORD => $ctx->{password},
833 DC_PASSWORD => $ctx->{password},
834 LDAPDIR => $ctx->{ldapdir},
835 LDAP_INSTANCE => $ctx->{ldap_instance},
836 SELFTEST_WINBINDD_SOCKET_DIR => $ctx->{winbindd_socket_dir},
837 NCALRPCDIR => $ctx->{ncalrpcdir},
838 LOCKDIR => $ctx->{lockdir},
839 STATEDIR => $ctx->{statedir},
840 CACHEDIR => $ctx->{cachedir},
841 PRIVATEDIR => $ctx->{privatedir},
842 BINDDNSDIR => $ctx->{binddnsdir},
843 SERVERCONFFILE => $ctx->{smb_conf},
844 TESTENV_DIR => $ctx->{prefix_abs},
845 CONFIGURATION => $configuration,
846 SOCKET_WRAPPER_DEFAULT_IFACE => $ctx->{swiface},
847 NSS_WRAPPER_PASSWD => $ctx->{nsswrap_passwd},
848 NSS_WRAPPER_GROUP => $ctx->{nsswrap_group},
849 NSS_WRAPPER_HOSTS => $ctx->{nsswrap_hosts},
850 NSS_WRAPPER_HOSTNAME => $ctx->{nsswrap_hostname},
851 SAMBA_TEST_FIFO => "$ctx->{prefix}/samba_test.fifo",
852 SAMBA_TEST_LOG => "$ctx->{prefix}/samba_test.log",
853 SAMBA_TEST_LOG_POS => 0,
854 NSS_WRAPPER_MODULE_SO_PATH => Samba::nss_wrapper_winbind_so_path($self),
855 NSS_WRAPPER_MODULE_FN_PREFIX => "winbind",
856 LOCAL_PATH => $ctx->{share},
857 UID_RFC2307TEST => $uid_rfc2307test,
858 GID_RFC2307TEST => $gid_rfc2307test,
859 SERVER_ROLE => $ctx->{server_role},
860 RESOLV_CONF => $ctx->{resolv_conf}
863 if (defined($ctx->{use_resolv_wrapper})) {
864 $ret->{RESOLV_WRAPPER_CONF} = $ctx->{resolv_conf};
866 $ret->{RESOLV_WRAPPER_HOSTS} = $ctx->{dns_host_file};
869 if ($ctx->{server_role} eq "domain controller") {
870 $ret->{DOMSID} = $ret->{SAMSID};
877 # Step2 runs the provision script
879 sub provision_raw_step2($$$)
881 my ($self, $ctx, $ret) = @_;
883 my $provision_cmd = join(" ", @{$ctx->{provision_options}});
884 unless (system($provision_cmd) == 0) {
885 warn("Unable to provision: \n$provision_cmd\n");
889 my $testallowed_account = "testallowed";
890 my $samba_tool_cmd = "";
891 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
892 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
893 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
894 . " user create --configfile=$ctx->{smb_conf} $testallowed_account $ctx->{password}";
895 unless (system($samba_tool_cmd) == 0) {
896 warn("Unable to add testallowed user: \n$samba_tool_cmd\n");
901 $ldbmodify .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
902 $ldbmodify .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
903 $ldbmodify .= Samba::bindir_path($self, "ldbmodify");
904 $ldbmodify .= " --configfile=$ctx->{smb_conf}";
905 my $base_dn = "DC=".join(",DC=", split(/\./, $ctx->{realm}));
907 if ($ctx->{server_role} ne "domain controller") {
908 $base_dn = "DC=$ctx->{netbiosname}";
911 my $user_dn = "cn=$testallowed_account,cn=users,$base_dn";
912 $testallowed_account = "testallowed account";
913 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
914 print LDIF "dn: $user_dn
916 replace: samAccountName
917 samAccountName: $testallowed_account
922 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
923 print LDIF "dn: $user_dn
925 replace: userPrincipalName
926 userPrincipalName: testallowed upn\@$ctx->{realm}
927 replace: servicePrincipalName
928 servicePrincipalName: host/testallowed
933 $samba_tool_cmd = "";
934 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
935 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
936 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
937 . " user create --configfile=$ctx->{smb_conf} testdenied $ctx->{password}";
938 unless (system($samba_tool_cmd) == 0) {
939 warn("Unable to add testdenied user: \n$samba_tool_cmd\n");
943 $user_dn = "cn=testdenied,cn=users,$base_dn";
944 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
945 print LDIF "dn: $user_dn
947 replace: userPrincipalName
948 userPrincipalName: testdenied_upn\@$ctx->{realm}.upn
953 $samba_tool_cmd = "";
954 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
955 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
956 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
957 . " user create --configfile=$ctx->{smb_conf} testupnspn $ctx->{password}";
958 unless (system($samba_tool_cmd) == 0) {
959 warn("Unable to add testupnspn user: \n$samba_tool_cmd\n");
963 $user_dn = "cn=testupnspn,cn=users,$base_dn";
964 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
965 print LDIF "dn: $user_dn
967 replace: userPrincipalName
968 userPrincipalName: http/testupnspn.$ctx->{dnsname}\@$ctx->{realm}
969 replace: servicePrincipalName
970 servicePrincipalName: http/testupnspn.$ctx->{dnsname}
975 $samba_tool_cmd = "";
976 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
977 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
978 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
979 . " group addmembers --configfile=$ctx->{smb_conf} 'Allowed RODC Password Replication Group' '$testallowed_account'";
980 unless (system($samba_tool_cmd) == 0) {
981 warn("Unable to add '$testallowed_account' user to 'Allowed RODC Password Replication Group': \n$samba_tool_cmd\n");
985 # Create to users alice and bob!
986 my $user_account_array = ["alice", "bob", "jane", "joe"];
988 foreach my $user_account (@{$user_account_array}) {
989 my $samba_tool_cmd = "";
991 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
992 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
993 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
994 . " user create --configfile=$ctx->{smb_conf} $user_account Secret007";
995 unless (system($samba_tool_cmd) == 0) {
996 warn("Unable to create user: $user_account\n$samba_tool_cmd\n");
1001 my $group_array = ["Samba Users"];
1003 foreach my $group (@{$group_array}) {
1004 my $samba_tool_cmd = "";
1006 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1007 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1008 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1009 . " group add --configfile=$ctx->{smb_conf} \"$group\"";
1010 unless (system($samba_tool_cmd) == 0) {
1011 warn("Unable to create group: $group\n$samba_tool_cmd\n");
1016 # Add user joe to group "Samba Users"
1017 $samba_tool_cmd = "";
1018 my $group = "Samba Users";
1019 my $user_account = "joe";
1021 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1022 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1023 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1024 . " group addmembers --configfile=$ctx->{smb_conf} \"$group\" $user_account";
1025 unless (system($samba_tool_cmd) == 0) {
1026 warn("Unable to add " . $user_account . "to group group : $group\n$samba_tool_cmd\n");
1030 $samba_tool_cmd = "";
1031 $group = "Samba Users";
1032 $user_account = "joe";
1034 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1035 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1036 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1037 . " user setprimarygroup --configfile=$ctx->{smb_conf} $user_account \"$group\"";
1038 unless (system($samba_tool_cmd) == 0) {
1039 warn("Unable to set primary group of user: $user_account\n$samba_tool_cmd\n");
1043 # Change the userPrincipalName for jane
1045 $ldbmodify .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1046 $ldbmodify .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1047 $ldbmodify .= Samba::bindir_path($self, "ldbmodify");
1048 $ldbmodify .= " --configfile=$ctx->{smb_conf}";
1049 $base_dn = "DC=".join(",DC=", split(/\./, $ctx->{realm}));
1050 $user_dn = "cn=jane,cn=users,$base_dn";
1052 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
1053 print LDIF "dn: $user_dn
1055 replace: userPrincipalName
1056 userPrincipalName: jane.doe\@$ctx->{realm}
1064 sub provision($$$$$$$$$$)
1066 my ($self, $prefix, $server_role, $hostname,
1067 $domain, $realm, $functional_level,
1068 $password, $kdc_ipv4, $kdc_ipv6, $extra_smbconf_options, $extra_smbconf_shares,
1069 $extra_provision_options) = @_;
1071 my $samsid = Samba::random_domain_sid();
1073 my $ctx = $self->provision_raw_prepare($prefix, $server_role,
1078 $password, $kdc_ipv4, $kdc_ipv6);
1080 if (defined($extra_provision_options)) {
1081 push (@{$ctx->{provision_options}}, @{$extra_provision_options});
1084 $ctx->{share} = "$ctx->{prefix_abs}/share";
1085 push(@{$ctx->{directories}}, "$ctx->{share}");
1086 push(@{$ctx->{directories}}, "$ctx->{share}/test1");
1087 push(@{$ctx->{directories}}, "$ctx->{share}/test2");
1089 # precreate directories for printer drivers
1090 push(@{$ctx->{directories}}, "$ctx->{share}/W32X86");
1091 push(@{$ctx->{directories}}, "$ctx->{share}/x64");
1092 push(@{$ctx->{directories}}, "$ctx->{share}/WIN40");
1095 $msdfs = "yes" if ($server_role eq "domain controller");
1096 $ctx->{smb_conf_extra_options} = "
1099 server max protocol = SMB2
1103 # fruit:copyfile is a global option
1104 fruit:copyfile = yes
1106 $extra_smbconf_options
1109 path = $ctx->{share}
1111 posix:sharedelay = 100000
1112 posix:oplocktimeout = 3
1113 posix:writetimeupdatedelay = 500000
1116 path = $ctx->{share}
1118 posix:sharedelay = 100000
1119 posix:oplocktimeout = 3
1120 posix:writetimeupdatedelay = 500000
1122 force create mode = 777
1125 path = $ctx->{share}
1128 force create mode = 0
1129 directory mask = 0777
1130 force directory mode = 0
1133 path = $ctx->{share}/test1
1135 posix:sharedelay = 100000
1136 posix:oplocktimeout = 3
1137 posix:writetimeupdatedelay = 500000
1140 path = $ctx->{share}/test2
1142 posix:sharedelay = 100000
1143 posix:oplocktimeout = 3
1144 posix:writetimeupdatedelay = 500000
1147 path = $ctx->{share}/_ignore_cifs_
1149 ntvfs handler = cifs
1150 cifs:server = $ctx->{netbiosname}
1152 cifs:use-s4u2proxy = yes
1153 # There is no username specified here, instead the client is expected
1154 # to log in with kerberos, and the serverwill use delegated credentials.
1155 # Or the server tries s4u2self/s4u2proxy to impersonate the client
1158 path = $ctx->{share}
1160 ntvfs handler = simple
1163 path = $ctx->{statedir}/sysvol
1167 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1172 ntvfs handler = cifsposix
1175 path = $ctx->{share}
1176 vfs objects = catia fruit streams_xattr acl_xattr
1178 fruit:resource = file
1179 fruit:metadata = netatalk
1180 fruit:locking = netatalk
1181 fruit:encoding = native
1184 path = $ctx->{share}
1185 # This can be used for testing real fs xattr stuff
1186 vfs objects = streams_xattr acl_xattr
1188 $extra_smbconf_shares
1191 my $ret = $self->provision_raw_step1($ctx);
1192 unless (defined $ret) {
1196 return $self->provision_raw_step2($ctx, $ret);
1199 # For multi-DC testenvs, we want $DC_SERVER to always be the PDC (i.e. the
1200 # original DC) in the testenv. $SERVER is always the joined DC that we are
1201 # actually running the test against
1202 sub set_pdc_env_vars
1204 my ($self, $env, $dcvars) = @_;
1206 $env->{DC_SERVER} = $dcvars->{DC_SERVER};
1207 $env->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1208 $env->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1209 $env->{DC_SERVERCONFFILE} = $dcvars->{SERVERCONFFILE};
1210 $env->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1211 $env->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1212 $env->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1215 sub provision_s4member($$$$$)
1217 my ($self, $prefix, $dcvars, $hostname, $more_conf) = @_;
1218 print "PROVISIONING MEMBER...\n";
1219 my $extra_smb_conf = "
1220 passdb backend = samba_dsdb
1221 winbindd:use external pipes = true
1223 # the source4 smb server doesn't allow signing by default
1224 server signing = enabled
1225 raw NTLMv2 auth = yes
1227 rpc_server:default = external
1228 rpc_server:svcctl = embedded
1229 rpc_server:srvsvc = embedded
1230 rpc_server:eventlog = embedded
1231 rpc_server:ntsvcs = embedded
1232 rpc_server:winreg = embedded
1233 rpc_server:spoolss = embedded
1234 rpc_daemon:spoolssd = embedded
1235 rpc_server:tcpip = no
1238 $extra_smb_conf = $extra_smb_conf . $more_conf . "\n";
1240 my $extra_provision_options = ["--use-ntvfs"];
1241 my $ret = $self->provision($prefix,
1248 $dcvars->{SERVER_IP},
1249 $dcvars->{SERVER_IPV6},
1250 $extra_smb_conf, "",
1251 $extra_provision_options);
1256 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1257 my $cmd = $self->get_cmd_env_vars($ret);
1258 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
1259 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1260 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1262 unless (system($cmd) == 0) {
1263 warn("Join failed\n$cmd");
1267 $ret->{DOMSID} = $dcvars->{DOMSID};
1268 $self->set_pdc_env_vars($ret, $dcvars);
1273 sub provision_rpc_proxy($$$)
1275 my ($self, $prefix, $dcvars) = @_;
1276 print "PROVISIONING RPC PROXY...\n";
1278 my $extra_smbconf_options = "
1279 passdb backend = samba_dsdb
1282 dcerpc_remote:binding = ncacn_ip_tcp:$dcvars->{SERVER}
1283 dcerpc endpoint servers = epmapper, remote
1284 dcerpc_remote:interfaces = rpcecho
1285 dcerpc_remote:allow_anonymous_fallback = yes
1288 path = /tmp/_ignore_cifs_to_dc_/_none_
1290 ntvfs handler = cifs
1291 cifs:server = $dcvars->{SERVER}
1293 cifs:use-s4u2proxy = yes
1294 # There is no username specified here, instead the client is expected
1295 # to log in with kerberos, and the serverwill use delegated credentials.
1296 # Or the server tries s4u2self/s4u2proxy to impersonate the client
1300 my $extra_provision_options = ["--use-ntvfs"];
1301 my $ret = $self->provision($prefix,
1308 $dcvars->{SERVER_IP},
1309 $dcvars->{SERVER_IPV6},
1310 $extra_smbconf_options, "",
1311 $extra_provision_options);
1316 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1318 # The joind runs in the context of the rpc_proxy/member for now
1319 my $cmd = $self->get_cmd_env_vars($ret);
1320 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
1321 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1322 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1324 unless (system($cmd) == 0) {
1325 warn("Join failed\n$cmd");
1329 # Setting up delegation runs in the context of the DC for now
1331 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1332 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
1333 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1334 $cmd .= "RESOLV_CONF=\"$dcvars->{RESOLV_CONF}\" ";
1335 $cmd .= "$samba_tool delegation for-any-protocol '$ret->{NETBIOSNAME}\$' on";
1336 $cmd .= " $dcvars->{CONFIGURATION}";
1339 unless (system($cmd) == 0) {
1340 warn("Delegation failed\n$cmd");
1344 # Setting up delegation runs in the context of the DC for now
1346 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1347 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
1348 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1349 $cmd .= "RESOLV_CONF=\"$dcvars->{RESOLV_CONF}\" ";
1350 $cmd .= "$samba_tool delegation add-service '$ret->{NETBIOSNAME}\$' cifs/$dcvars->{SERVER}";
1351 $cmd .= " $dcvars->{CONFIGURATION}";
1353 unless (system($cmd) == 0) {
1354 warn("Delegation failed\n$cmd");
1358 $ret->{DOMSID} = $dcvars->{DOMSID};
1359 $self->set_pdc_env_vars($ret, $dcvars);
1364 sub provision_promoted_dc($$$)
1366 my ($self, $prefix, $dcvars) = @_;
1367 print "PROVISIONING PROMOTED DC...\n";
1369 # We do this so that we don't run the provision. That's the job of 'samba-tool domain dcpromo'.
1370 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1376 $dcvars->{PASSWORD},
1377 $dcvars->{SERVER_IP},
1378 $dcvars->{SERVER_IPV6});
1380 $ctx->{smb_conf_extra_options} = "
1382 server max protocol = SMB2
1384 ntlm auth = ntlmv2-only
1387 path = $ctx->{statedir}/sysvol
1391 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1396 my $ret = $self->provision_raw_step1($ctx);
1401 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1402 my $cmd = $self->get_cmd_env_vars($ret);
1403 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} MEMBER --realm=$dcvars->{REALM}";
1404 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1405 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1407 unless (system($cmd) == 0) {
1408 warn("Join failed\n$cmd");
1412 $samba_tool = Samba::bindir_path($self, "samba-tool");
1413 $cmd = $self->get_cmd_env_vars($ret);
1414 $cmd .= "$samba_tool domain dcpromo $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1415 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1416 $cmd .= " --machinepass=machine$ret->{PASSWORD} --dns-backend=BIND9_DLZ";
1418 unless (system($cmd) == 0) {
1419 warn("Join failed\n$cmd");
1423 $self->set_pdc_env_vars($ret, $dcvars);
1428 sub provision_vampire_dc($$$)
1430 my ($self, $prefix, $dcvars, $fl) = @_;
1431 print "PROVISIONING VAMPIRE DC @ FL $fl...\n";
1432 my $name = "localvampiredc";
1433 my $extra_conf = "";
1435 if ($fl == "2000") {
1436 $name = "vampire2000dc";
1438 $extra_conf = "drs: immediate link sync = yes
1439 drs: max link sync = 250";
1442 # We do this so that we don't run the provision. That's the job of 'net vampire'.
1443 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1449 $dcvars->{PASSWORD},
1450 $dcvars->{SERVER_IP},
1451 $dcvars->{SERVER_IPV6});
1453 $ctx->{smb_conf_extra_options} = "
1455 server max protocol = SMB2
1457 ntlm auth = mschapv2-and-ntlmv2-only
1461 path = $ctx->{statedir}/sysvol
1465 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1470 my $ret = $self->provision_raw_step1($ctx);
1475 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1476 my $cmd = $self->get_cmd_env_vars($ret);
1477 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1478 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} --domain-critical-only";
1479 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1480 $cmd .= " --backend-store=mdb";
1482 unless (system($cmd) == 0) {
1483 warn("Join failed\n$cmd");
1487 $self->set_pdc_env_vars($ret, $dcvars);
1488 $ret->{DC_REALM} = $dcvars->{DC_REALM};
1493 sub provision_ad_dc_ntvfs($$$)
1495 my ($self, $prefix, $extra_provision_options) = @_;
1497 # We keep the old 'winbind' name here in server services to
1498 # ensure upgrades which used that name still work with the now
1501 print "PROVISIONING AD DC (NTVFS)...\n";
1502 my $extra_conf_options = "netbios aliases = localDC1-a
1503 server services = +winbind -winbindd
1504 ldap server require strong auth = allow_sasl_over_tls
1505 allow nt4 crypto = yes
1506 raw NTLMv2 auth = yes
1507 lsa over netlogon = yes
1508 rpc server port = 1027
1509 auth event notification = true
1510 dsdb event notification = true
1511 dsdb password event notification = true
1512 dsdb group change notification = true
1513 server schannel = auto
1515 push (@{$extra_provision_options}, "--use-ntvfs");
1516 my $ret = $self->provision($prefix,
1517 "domain controller",
1520 "samba.example.com",
1525 $extra_conf_options,
1527 $extra_provision_options);
1532 unless($self->add_wins_config("$prefix/private")) {
1533 warn("Unable to add wins configuration");
1536 $ret->{NETBIOSALIAS} = "localdc1-a";
1537 $ret->{DC_REALM} = $ret->{REALM};
1542 sub provision_fl2000dc($$)
1544 my ($self, $prefix) = @_;
1546 print "PROVISIONING DC WITH FOREST LEVEL 2000...\n";
1547 my $extra_conf_options = "
1548 spnego:simulate_w2k=yes
1549 ntlmssp_server:force_old_spnego=yes
1551 my $extra_provision_options = ["--base-schema=2008_R2"];
1552 # This environment uses plain text secrets
1553 # i.e. secret attributes are not encrypted on disk.
1554 # This allows testing of the --plaintext-secrets option for
1556 push (@{$extra_provision_options}, "--plaintext-secrets");
1557 my $ret = $self->provision($prefix,
1558 "domain controller",
1561 "samba2000.example.com",
1566 $extra_conf_options,
1568 $extra_provision_options);
1573 unless($self->add_wins_config("$prefix/private")) {
1574 warn("Unable to add wins configuration");
1577 $ret->{DC_REALM} = $ret->{REALM};
1582 sub provision_fl2003dc($$$)
1584 my ($self, $prefix, $dcvars) = @_;
1585 my $ip_addr1 = Samba::get_ipv4_addr("fakednsforwarder1");
1586 my $ip_addr2 = Samba::get_ipv4_addr("fakednsforwarder2");
1588 print "PROVISIONING DC WITH FOREST LEVEL 2003...\n";
1589 my $extra_conf_options = "allow dns updates = nonsecure and secure
1590 dcesrv:header signing = no
1591 dcesrv:max auth states = 0
1592 dns forwarder = $ip_addr1 $ip_addr2";
1593 my $extra_provision_options = ["--base-schema=2008_R2"];
1594 my $ret = $self->provision($prefix,
1595 "domain controller",
1598 "samba2003.example.com",
1603 $extra_conf_options,
1605 $extra_provision_options);
1606 unless (defined $ret) {
1610 $ret->{DNS_FORWARDER1} = $ip_addr1;
1611 $ret->{DNS_FORWARDER2} = $ip_addr2;
1613 my @samba_tool_options;
1614 push (@samba_tool_options, Samba::bindir_path($self, "samba-tool"));
1615 push (@samba_tool_options, "domain");
1616 push (@samba_tool_options, "passwordsettings");
1617 push (@samba_tool_options, "set");
1618 push (@samba_tool_options, "--configfile=$ret->{SERVERCONFFILE}");
1619 push (@samba_tool_options, "--min-pwd-age=0");
1620 push (@samba_tool_options, "--history-length=1");
1622 my $samba_tool_cmd = join(" ", @samba_tool_options);
1624 unless (system($samba_tool_cmd) == 0) {
1625 warn("Unable to set min password age to 0: \n$samba_tool_cmd\n");
1629 unless($self->add_wins_config("$prefix/private")) {
1630 warn("Unable to add wins configuration");
1637 sub provision_fl2008r2dc($$$)
1639 my ($self, $prefix, $dcvars) = @_;
1641 print "PROVISIONING DC WITH FOREST LEVEL 2008r2...\n";
1642 my $extra_conf_options = "ldap server require strong auth = no";
1643 my $extra_provision_options = ["--base-schema=2008_R2"];
1644 my $ret = $self->provision($prefix,
1645 "domain controller",
1648 "samba2008R2.example.com",
1653 $extra_conf_options,
1655 $extra_provision_options);
1656 unless (defined $ret) {
1660 unless ($self->add_wins_config("$prefix/private")) {
1661 warn("Unable to add wins configuration");
1664 $ret->{DC_REALM} = $ret->{REALM};
1670 sub provision_rodc($$$)
1672 my ($self, $prefix, $dcvars) = @_;
1673 print "PROVISIONING RODC...\n";
1675 # We do this so that we don't run the provision. That's the job of 'net join RODC'.
1676 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1682 $dcvars->{PASSWORD},
1683 $dcvars->{SERVER_IP},
1684 $dcvars->{SERVER_IPV6});
1689 $ctx->{share} = "$ctx->{prefix_abs}/share";
1690 push(@{$ctx->{directories}}, "$ctx->{share}");
1692 $ctx->{smb_conf_extra_options} = "
1694 server max protocol = SMB2
1695 password server = $dcvars->{DC_SERVER}
1698 path = $ctx->{statedir}/sysvol
1702 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1706 path = $ctx->{share}
1708 posix:sharedelay = 10000
1709 posix:oplocktimeout = 3
1710 posix:writetimeupdatedelay = 50000
1714 my $ret = $self->provision_raw_step1($ctx);
1719 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1720 my $cmd = $self->get_cmd_env_vars($ret);
1721 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} RODC";
1722 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1723 $cmd .= " --server=$dcvars->{DC_SERVER}";
1725 unless (system($cmd) == 0) {
1726 warn("RODC join failed\n$cmd");
1730 # This ensures deterministic behaviour for tests that want to have the 'testallowed account'
1731 # user password verified on the RODC
1732 my $testallowed_account = "testallowed account";
1733 $cmd = "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1734 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1735 $cmd .= "RESOLV_CONF=\"$ret->{RESOLV_CONF}\" ";
1736 $cmd .= "$samba_tool rodc preload '$testallowed_account' $ret->{CONFIGURATION}";
1737 $cmd .= " --server=$dcvars->{DC_SERVER}";
1739 unless (system($cmd) == 0) {
1740 warn("RODC join failed\n$cmd");
1744 # we overwrite the kdc after the RODC join
1745 # so that use the RODC as kdc and test
1747 $ctx->{kdc_ipv4} = $ret->{SERVER_IP};
1748 $ctx->{kdc_ipv6} = $ret->{SERVER_IPV6};
1749 Samba::mk_krb5_conf($ctx);
1750 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
1752 $self->set_pdc_env_vars($ret, $dcvars);
1757 sub read_config_h($)
1761 open(LF, "<$name") or die("unable to read $name: $!");
1764 next if not (/^#define /);
1765 if (/^#define (.*?)[ \t]+(.*?)$/) {
1769 if (/^#define (.*?)[ \t]+$/) {
1778 sub provision_ad_dc($$$$$$)
1780 my ($self, $prefix, $hostname, $domain, $realm, $smbconf_args,
1781 $extra_provision_options) = @_;
1783 my $prefix_abs = abs_path($prefix);
1785 my $bindir_abs = abs_path($self->{bindir});
1786 my $lockdir="$prefix_abs/lockdir";
1787 my $conffile="$prefix_abs/etc/smb.conf";
1789 my $require_mutexes = "dbwrap_tdb_require_mutexes:* = yes";
1790 if ($ENV{SELFTEST_DONT_REQUIRE_TDB_MUTEX_SUPPORT} // '' eq "1") {
1791 $require_mutexes = "";
1796 if (defined($ENV{CONFIG_H})) {
1797 $config_h = read_config_h($ENV{CONFIG_H});
1800 my $password_hash_gpg_key_ids = "password hash gpg key ids = 4952E40301FAB41A";
1801 $password_hash_gpg_key_ids = "" unless defined($config_h->{HAVE_GPGME});
1803 my $extra_smbconf_options = "
1804 xattr_tdb:file = $prefix_abs/statedir/xattr.tdb
1806 dbwrap_tdb_mutexes:* = yes
1809 ${password_hash_gpg_key_ids}
1812 kernel change notify = no
1817 printcap name = /dev/null
1822 smbd:sharedelay = 100000
1823 smbd:writetimeupdatedelay = 500000
1826 check parent directory delete on close = yes
1828 dcerpc endpoint servers = -winreg -srvsvc
1830 printcap name = /dev/null
1832 addprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -a -s $conffile --
1833 deleteprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -d -s $conffile --
1836 print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
1837 lpq command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpq %p
1838 lp rm command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lprm %p %j
1839 lp pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lppause %p %j
1840 lp resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpresume %p %j
1841 queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
1842 queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
1844 print notify backchannel = yes
1846 server schannel = auto
1847 auth event notification = true
1848 dsdb event notification = true
1849 dsdb password event notification = true
1850 dsdb group change notification = true
1854 my $extra_smbconf_shares = "
1858 smb encrypt = required
1862 case sensitive = yes
1870 hide unreadable = yes
1874 kernel share modes = no
1896 push (@{$extra_provision_options}, "--backend-store=mdb");
1897 print "PROVISIONING AD DC...\n";
1898 my $ret = $self->provision($prefix,
1899 "domain controller",
1907 $extra_smbconf_options,
1908 $extra_smbconf_shares,
1909 $extra_provision_options);
1910 unless (defined $ret) {
1914 unless($self->add_wins_config("$prefix/private")) {
1915 warn("Unable to add wins configuration");
1922 sub provision_chgdcpass($$)
1924 my ($self, $prefix) = @_;
1926 print "PROVISIONING CHGDCPASS...\n";
1927 # This environment disallows the use of this password
1928 # (and also removes the default AD complexity checks)
1929 my $unacceptable_password = "Paßßword-widk3Dsle32jxdBdskldsk55klASKQ";
1930 my $extra_smb_conf = "
1931 check password script = $self->{srcdir}/selftest/checkpassword_arg1.sh ${unacceptable_password}
1932 allow dcerpc auth level connect:lsarpc = yes
1933 dcesrv:max auth states = 8
1935 my $extra_provision_options = ["--dns-backend=BIND9_DLZ"];
1936 my $ret = $self->provision($prefix,
1937 "domain controller",
1940 "chgdcpassword.samba.example.com",
1947 $extra_provision_options);
1948 unless (defined $ret) {
1952 unless($self->add_wins_config("$prefix/private")) {
1953 warn("Unable to add wins configuration");
1957 # Remove secrets.tdb from this environment to test that we
1958 # still start up on systems without the new matching
1959 # secrets.tdb records.
1960 unless (unlink("$ret->{PRIVATEDIR}/secrets.tdb") || unlink("$ret->{PRIVATEDIR}/secrets.ntdb")) {
1961 warn("Unable to remove $ret->{PRIVATEDIR}/secrets.tdb added during provision");
1965 $ret->{UNACCEPTABLE_PASSWORD} = $unacceptable_password;
1970 sub teardown_env_terminate($$)
1972 my ($self, $envvars) = @_;
1975 # This should cause samba to terminate gracefully
1976 my $smbcontrol = Samba::bindir_path($self, "smbcontrol");
1978 $cmd .= "$smbcontrol samba shutdown $envvars->{CONFIGURATION}";
1979 my $ret = system($cmd);
1981 warn "'$cmd' failed with '$ret'\n";
1984 # This should cause samba to terminate gracefully
1985 close($envvars->{STDIN_PIPE});
1987 $pid = $envvars->{SAMBA_PID};
1991 # This should give it time to write out the gcov data
1992 until ($count > 15) {
1993 if (Samba::cleanup_child($pid, "samba") != 0) {
2000 # After 15 Seconds, work out why this thing is still alive
2001 warn "server process $pid took more than $count seconds to exit, showing backtrace:\n";
2002 system("$self->{srcdir}/selftest/gdb_backtrace $pid");
2004 until ($count > 30) {
2005 if (Samba::cleanup_child($pid, "samba") != 0) {
2012 if (kill(0, $pid)) {
2013 warn "server process $pid took more than $count seconds to exit, sending SIGTERM\n";
2017 until ($count > 40) {
2018 if (Samba::cleanup_child($pid, "samba") != 0) {
2024 # If it is still around, kill it
2025 if (kill(0, $pid)) {
2026 warn "server process $pid took more than $count seconds to exit, killing\n with SIGKILL\n";
2032 sub teardown_env($$)
2034 my ($self, $envvars) = @_;
2035 teardown_env_terminate($self, $envvars);
2037 print $self->getlog_env($envvars);
2044 my ($self, $envvars) = @_;
2045 my $title = "SAMBA LOG of: $envvars->{NETBIOSNAME} pid $envvars->{SAMBA_PID}\n";
2048 open(LOG, "<$envvars->{SAMBA_TEST_LOG}");
2050 seek(LOG, $envvars->{SAMBA_TEST_LOG_POS}, SEEK_SET);
2054 $envvars->{SAMBA_TEST_LOG_POS} = tell(LOG);
2057 return "" if $out eq $title;
2064 my ($self, $envvars) = @_;
2065 my $samba_pid = $envvars->{SAMBA_PID};
2067 if (not defined($samba_pid)) {
2069 } elsif ($samba_pid > 0) {
2070 my $childpid = Samba::cleanup_child($samba_pid, "samba");
2072 if ($childpid == 0) {
2081 # Declare the environments Samba4 makes available.
2082 # To be set up, they will be called as
2083 # samba4->setup_$envname($self, $path, $dep_1_vars, $dep_2_vars, ...)
2084 # The interdependencies between the testenvs are declared below. Some testenvs
2085 # are dependent on another testenv running first, e.g. vampire_dc is dependent
2086 # on ad_dc_ntvfs because vampire_dc joins ad_dc_ntvfs's domain. All DCs are
2087 # dependent on dns_hub, which handles resolving DNS queries for the realm.
2088 %Samba4::ENV_DEPS = (
2089 # name => [dep_1, dep_2, ...],
2091 ad_dc_ntvfs => ["dns_hub"],
2092 ad_dc => ["dns_hub"],
2093 ad_dc_no_nss => ["dns_hub"],
2094 ad_dc_no_ntlm => ["dns_hub"],
2096 fl2008r2dc => ["ad_dc"],
2097 fl2003dc => ["ad_dc"],
2098 fl2000dc => ["dns_hub"],
2100 vampire_2000_dc => ["fl2000dc"],
2101 vampire_dc => ["ad_dc_ntvfs"],
2102 promoted_dc => ["ad_dc_ntvfs"],
2104 rodc => ["ad_dc_ntvfs"],
2105 rpc_proxy => ["ad_dc_ntvfs"],
2106 chgdcpass => ["dns_hub"],
2108 s4member_dflt_domain => ["ad_dc_ntvfs"],
2109 s4member => ["ad_dc_ntvfs"],
2111 # envs that test the server process model
2112 proclimitdc => ["dns_hub"],
2113 preforkrestartdc => ["dns_hub"],
2115 # backup/restore testenvs
2116 backupfromdc => ["dns_hub"],
2117 customdc => ["dns_hub"],
2118 restoredc => ["backupfromdc"],
2119 renamedc => ["backupfromdc"],
2120 offlinebackupdc => ["backupfromdc"],
2121 labdc => ["backupfromdc"],
2123 # aliases in order to split autbuild tasks
2124 fl2008dc => ["ad_dc"],
2125 ad_dc_default => ["ad_dc"],
2126 ad_dc_slowtests => ["ad_dc"],
2127 ad_dc_backup => ["ad_dc"],
2129 schema_dc => ["dns_hub"],
2130 schema_pair_dc => ["schema_dc"],
2135 %Samba4::ENV_DEPS_POST = (
2136 schema_dc => ["schema_pair_dc"],
2139 sub return_alias_env
2141 my ($self, $path, $env) = @_;
2149 my ($self, $path) = @_;
2151 my $extra_args = ["--base-schema=2008_R2"];
2152 my $env = $self->provision_ad_dc_ntvfs($path, $extra_args);
2154 if (not defined($self->check_or_start($env, "standard"))) {
2155 warn("Failed to start fl2008dc");
2162 sub setup_ad_dc_default
2164 my ($self, $path, $dep_env) = @_;
2165 return $self->return_alias_env($path, $dep_env)
2168 sub setup_ad_dc_slowtests
2170 my ($self, $path, $dep_env) = @_;
2171 return $self->return_alias_env($path, $dep_env)
2174 sub setup_ad_dc_backup
2176 my ($self, $path, $dep_env) = @_;
2177 return $self->return_alias_env($path, $dep_env)
2182 my ($self, $path, $dc_vars) = @_;
2184 my $env = $self->provision_s4member($path, $dc_vars, "s4member");
2187 if (not defined($self->check_or_start($env, "standard"))) {
2195 sub setup_s4member_dflt_domain
2197 my ($self, $path, $dc_vars) = @_;
2199 my $env = $self->provision_s4member($path, $dc_vars, "s4member_dflt",
2200 "winbind use default domain = yes");
2203 if (not defined($self->check_or_start($env, "standard"))) {
2213 my ($self, $path, $dc_vars) = @_;
2215 my $env = $self->provision_rpc_proxy($path, $dc_vars);
2218 if (not defined($self->check_or_start($env, "standard"))) {
2225 sub setup_ad_dc_ntvfs
2227 my ($self, $path) = @_;
2229 my $env = $self->provision_ad_dc_ntvfs($path, undef);
2231 if (not defined($self->check_or_start($env, "standard"))) {
2232 warn("Failed to start ad_dc_ntvfs");
2241 my ($self, $path) = @_;
2243 my $env = $self->provision_chgdcpass($path);
2245 if (not defined($self->check_or_start($env, "standard"))) {
2254 my ($self, $path) = @_;
2256 my $env = $self->provision_fl2000dc($path);
2258 if (not defined($self->check_or_start($env, "standard"))) {
2268 my ($self, $path, $dc_vars) = @_;
2270 my $env = $self->provision_fl2003dc($path);
2273 if (not defined($self->check_or_start($env, "standard"))) {
2277 $env = $self->setup_trust($env, $dc_vars, "external", "--no-aes-keys");
2282 sub setup_fl2008r2dc
2284 my ($self, $path, $dc_vars) = @_;
2286 my $env = $self->provision_fl2008r2dc($path);
2289 if (not defined($self->check_or_start($env, "standard"))) {
2293 my $upn_array = ["$env->{REALM}.upn"];
2294 my $spn_array = ["$env->{REALM}.spn"];
2296 $self->setup_namespaces($env, $upn_array, $spn_array);
2298 $env = $self->setup_trust($env, $dc_vars, "forest", "");
2304 sub setup_vampire_dc
2306 return setup_generic_vampire_dc(@_, "2008");
2309 sub setup_vampire_2000_dc
2311 return setup_generic_vampire_dc(@_, "2000");
2314 sub setup_generic_vampire_dc
2316 my ($self, $path, $dc_vars, $fl) = @_;
2318 my $env = $self->provision_vampire_dc($path, $dc_vars, $fl);
2321 if (not defined($self->check_or_start($env, "single"))) {
2325 # force replicated DC to update repsTo/repsFrom
2326 # for vampired partitions
2327 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2329 # as 'vampired' dc may add data in its local replica
2330 # we need to synchronize data between DCs
2331 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2332 my $cmd = $self->get_cmd_env_vars($env);
2333 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2334 $cmd .= " $dc_vars->{CONFIGURATION}";
2335 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2336 # replicate Configuration NC
2337 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2338 unless(system($cmd_repl) == 0) {
2339 warn("Failed to replicate\n$cmd_repl");
2342 # replicate Default NC
2343 $cmd_repl = "$cmd \"$base_dn\"";
2344 unless(system($cmd_repl) == 0) {
2345 warn("Failed to replicate\n$cmd_repl");
2349 # Pull in a full set of changes from the main DC
2350 $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2351 $cmd = $self->get_cmd_env_vars($env);
2352 $cmd .= " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}";
2353 $cmd .= " $dc_vars->{CONFIGURATION}";
2354 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2355 # replicate Configuration NC
2356 $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2357 unless(system($cmd_repl) == 0) {
2358 warn("Failed to replicate\n$cmd_repl");
2361 # replicate Default NC
2362 $cmd_repl = "$cmd \"$base_dn\"";
2363 unless(system($cmd_repl) == 0) {
2364 warn("Failed to replicate\n$cmd_repl");
2372 sub setup_promoted_dc
2374 my ($self, $path, $dc_vars) = @_;
2376 my $env = $self->provision_promoted_dc($path, $dc_vars);
2379 if (not defined($self->check_or_start($env, "single"))) {
2383 # force source and replicated DC to update repsTo/repsFrom
2384 # for vampired partitions
2385 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2386 my $cmd = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2387 # as 'vampired' dc may add data in its local replica
2388 # we need to synchronize data between DCs
2389 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2390 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2391 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2392 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2393 $cmd .= "RESOLV_CONF=\"$env->{RESOLV_CONF}\" ";
2394 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2395 $cmd .= " $dc_vars->{CONFIGURATION}";
2396 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2397 # replicate Configuration NC
2398 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2399 unless(system($cmd_repl) == 0) {
2400 warn("Failed to replicate\n$cmd_repl");
2403 # replicate Default NC
2404 $cmd_repl = "$cmd \"$base_dn\"";
2405 unless(system($cmd_repl) == 0) {
2406 warn("Failed to replicate\n$cmd_repl");
2416 my ($self, $path, $dc_vars) = @_;
2418 my $env = $self->provision_rodc($path, $dc_vars);
2424 if (not defined($self->check_or_start($env, "standard"))) {
2428 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2431 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2432 $cmd .= "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2433 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2434 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2435 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2436 $cmd .= "RESOLV_CONF=\"$env->{RESOLV_CONF}\" ";
2437 $cmd .= " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}";
2438 $cmd .= " $dc_vars->{CONFIGURATION}";
2439 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2440 # replicate Configuration NC
2441 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2442 unless(system($cmd_repl) == 0) {
2443 warn("Failed to replicate\n$cmd_repl");
2446 # replicate Default NC
2447 $cmd_repl = "$cmd \"$base_dn\"";
2448 unless(system($cmd_repl) == 0) {
2449 warn("Failed to replicate\n$cmd_repl");
2458 my ($self, $path) = @_;
2460 # If we didn't build with ADS, pretend this env was never available
2461 if (not $self->{target3}->have_ads()) {
2465 my $env = $self->provision_ad_dc($path, "addc", "ADDOMAIN",
2466 "addom.samba.example.com", "", undef);
2471 if (not defined($self->check_or_start($env, "prefork"))) {
2475 my $upn_array = ["$env->{REALM}.upn"];
2476 my $spn_array = ["$env->{REALM}.spn"];
2478 $self->setup_namespaces($env, $upn_array, $spn_array);
2483 sub setup_ad_dc_no_nss
2485 my ($self, $path) = @_;
2487 # If we didn't build with ADS, pretend this env was never available
2488 if (not $self->{target3}->have_ads()) {
2492 my $env = $self->provision_ad_dc($path, "addc_no_nss", "ADNONSSDOMAIN",
2493 "adnonssdom.samba.example.com", "", undef);
2498 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2499 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2501 if (not defined($self->check_or_start($env, "single"))) {
2505 my $upn_array = ["$env->{REALM}.upn"];
2506 my $spn_array = ["$env->{REALM}.spn"];
2508 $self->setup_namespaces($env, $upn_array, $spn_array);
2513 sub setup_ad_dc_no_ntlm
2515 my ($self, $path) = @_;
2517 # If we didn't build with ADS, pretend this env was never available
2518 if (not $self->{target3}->have_ads()) {
2522 my $env = $self->provision_ad_dc($path, "addc_no_ntlm", "ADNONTLMDOMAIN",
2523 "adnontlmdom.samba.example.com",
2524 "ntlm auth = disabled", undef);
2529 if (not defined($self->check_or_start($env, "prefork"))) {
2533 my $upn_array = ["$env->{REALM}.upn"];
2534 my $spn_array = ["$env->{REALM}.spn"];
2536 $self->setup_namespaces($env, $upn_array, $spn_array);
2542 # AD DC test environment used solely to test pre-fork process restarts.
2543 # As processes get killed off and restarted it should not be used for other
2544 sub setup_preforkrestartdc
2546 my ($self, $path) = @_;
2548 # If we didn't build with ADS, pretend this env was never available
2549 if (not $self->{target3}->have_ads()) {
2553 # note DC name must be <= 15 chars so we use 'prockill' instead of
2555 my $env = $self->provision_ad_dc(
2559 "prockilldom.samba.example.com",
2560 "prefork backoff increment = 5\nprefork maximum backoff=10");
2565 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2566 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2568 if (not defined($self->check_or_start($env, "prefork"))) {
2572 my $upn_array = ["$env->{REALM}.upn"];
2573 my $spn_array = ["$env->{REALM}.spn"];
2575 $self->setup_namespaces($env, $upn_array, $spn_array);
2581 # ad_dc test environment used solely to test standard process model connection
2582 # process limits. As the limit is set artificially low it should not be used
2584 sub setup_proclimitdc
2586 my ($self, $path) = @_;
2588 # If we didn't build with ADS, pretend this env was never available
2589 if (not $self->{target3}->have_ads()) {
2593 my $env = $self->provision_ad_dc(
2597 "proclimit.samba.example.com",
2598 "max smbd processes = 20");
2603 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2604 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2606 if (not defined($self->check_or_start($env, "standard"))) {
2610 my $upn_array = ["$env->{REALM}.upn"];
2611 my $spn_array = ["$env->{REALM}.spn"];
2613 $self->setup_namespaces($env, $upn_array, $spn_array);
2618 # Used to test a live upgrade of the schema on a 2 DC network.
2621 my ($self, $path) = @_;
2623 # provision the PDC using an older base schema
2624 my $provision_args = ["--base-schema=2008_R2", "--backend-store=mdb"];
2626 my $env = $self->provision_ad_dc($path, "liveupgrade1dc", "SCHEMADOMAIN",
2627 "schema.samba.example.com",
2628 "drs: max link sync = 2",
2634 if (not defined($self->check_or_start($env, "prefork"))) {
2638 my $upn_array = ["$env->{REALM}.upn"];
2639 my $spn_array = ["$env->{REALM}.spn"];
2641 $self->setup_namespaces($env, $upn_array, $spn_array);
2646 # the second DC in the live schema upgrade pair
2647 sub setup_schema_pair_dc
2649 # note: dcvars contains the env info for the dependent testenv ('schema_dc')
2650 my ($self, $prefix, $dcvars) = @_;
2651 print "Preparing SCHEMA UPGRADE PAIR DC...\n";
2653 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "liveupgrade2dc",
2656 $dcvars->{PASSWORD},
2659 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2660 my $cmd_vars = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2661 $cmd_vars .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2662 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2663 $cmd_vars .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2665 $cmd_vars .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2667 $cmd_vars .= "KRB5_CONFIG=\"$env->{KRB5_CONFIG}\" ";
2668 $cmd_vars .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2669 $cmd_vars .= "RESOLV_CONF=\"$env->{RESOLV_CONF}\" ";
2671 my $join_cmd = $cmd_vars;
2672 $join_cmd .= "$samba_tool domain join $env->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
2673 $join_cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} ";
2674 $join_cmd .= " --backend-store=mdb";
2676 my $upgrade_cmd = $cmd_vars;
2677 $upgrade_cmd .= "$samba_tool domain schemaupgrade $dcvars->{CONFIGURATION}";
2678 $upgrade_cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}";
2680 my $repl_cmd = $cmd_vars;
2681 $repl_cmd .= "$samba_tool drs replicate $env->{SERVER} $dcvars->{SERVER}";
2682 $repl_cmd .= " CN=Schema,CN=Configuration,DC=schema,DC=samba,DC=example,DC=com";
2683 $repl_cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
2685 unless (system($join_cmd) == 0) {
2686 warn("Join failed\n$join_cmd");
2690 $env->{DC_SERVER} = $dcvars->{SERVER};
2691 $env->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
2692 $env->{DC_SERVER_IPV6} = $dcvars->{SERVER_IPV6};
2693 $env->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
2695 # start samba for the new DC
2696 if (not defined($self->check_or_start($env, "standard"))) {
2700 unless (system($upgrade_cmd) == 0) {
2701 warn("Schema upgrade failed\n$upgrade_cmd");
2705 unless (system($repl_cmd) == 0) {
2706 warn("Post-update schema replication failed\n$repl_cmd");
2713 # Sets up a DC that's solely used to do a domain backup from. We then use the
2714 # backupfrom-DC to create the restore-DC - this proves that the backup/restore
2715 # process will create a Samba DC that will actually start up.
2716 # We don't use the backup-DC for anything else because its domain will conflict
2717 # with the restore DC.
2718 sub setup_backupfromdc
2720 my ($self, $path) = @_;
2722 # If we didn't build with ADS, pretend this env was never available
2723 if (not $self->{target3}->have_ads()) {
2727 my $provision_args = ["--site=Backup-Site"];
2729 my $env = $self->provision_ad_dc($path, "backupfromdc", "BACKUPDOMAIN",
2730 "backupdom.samba.example.com",
2731 "samba kcc command = /bin/true",
2737 if (not defined($self->check_or_start($env))) {
2741 my $upn_array = ["$env->{REALM}.upn"];
2742 my $spn_array = ["$env->{REALM}.spn"];
2744 $self->setup_namespaces($env, $upn_array, $spn_array);
2749 # returns the server/user-auth params needed to run an online backup cmd
2750 sub get_backup_server_args
2752 # dcvars contains the env info for the backup DC testenv
2753 my ($self, $dcvars) = @_;
2754 my $server = $dcvars->{DC_SERVER_IP};
2755 my $server_args = "--server=$server ";
2756 $server_args .= "-U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
2757 $server_args .= " $dcvars->{CONFIGURATION}";
2759 return $server_args;
2762 # Creates a backup of a running testenv DC
2765 # note: dcvars contains the env info for the backup DC testenv
2766 my ($self, $env, $dcvars, $backupdir, $backup_cmd) = @_;
2768 # get all the env variables we pass in with the samba-tool command
2769 my $cmd_env = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2770 $cmd_env .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2771 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2772 $cmd_env .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2774 $cmd_env .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2776 # Note: use the backupfrom-DC's krb5.conf to do the backup
2777 $cmd_env .= " KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
2778 $cmd_env .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2780 # use samba-tool to create a backup from the 'backupfromdc' DC
2782 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2784 $cmd .= "$cmd_env $samba_tool domain backup $backup_cmd";
2785 $cmd .= " --targetdir=$backupdir";
2787 print "Executing: $cmd\n";
2788 unless(system($cmd) == 0) {
2789 warn("Failed to create backup using: \n$cmd");
2793 # get the name of the backup file created
2794 opendir(DIR, $backupdir);
2795 my @files = grep(/\.tar/, readdir(DIR));
2798 if(scalar @files != 1) {
2799 warn("Backup file not found in directory $backupdir\n");
2802 my $backup_file = "$backupdir/$files[0]";
2803 print "Using backup file $backup_file...\n";
2805 return $backup_file;
2808 # Restores a backup-file to populate a testenv for a new DC
2809 sub restore_backup_file
2811 my ($self, $backup_file, $restore_opts, $restoredir, $smbconf) = @_;
2813 # pass the restore command the testenv's smb.conf that we've already
2814 # generated. But move it to a temp-dir first, so that the restore doesn't
2816 my $tmpdir = File::Temp->newdir();
2817 my $tmpconf = "$tmpdir/smb.conf";
2818 my $cmd = "cp $smbconf $tmpconf";
2819 unless(system($cmd) == 0) {
2820 warn("Failed to backup smb.conf using: \n$cmd");
2824 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2825 $cmd = "$samba_tool domain backup restore --backup-file=$backup_file";
2826 $cmd .= " --targetdir=$restoredir $restore_opts --configfile=$tmpconf";
2828 print "Executing: $cmd\n";
2829 unless(system($cmd) == 0) {
2830 warn("Failed to restore backup using: \n$cmd");
2834 print "Restore complete\n";
2838 # sets up the initial directory and returns the new testenv's env info
2839 # (without actually doing a 'domain join')
2840 sub prepare_dc_testenv
2842 my ($self, $prefix, $dcname, $domain, $realm,
2843 $password, $conf_options) = @_;
2845 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
2855 # the restore uses a slightly different state-dir location to other testenvs
2856 $ctx->{statedir} = "$ctx->{prefix_abs}/state";
2857 push(@{$ctx->{directories}}, "$ctx->{statedir}");
2859 # add support for sysvol/netlogon/tmp shares
2860 $ctx->{share} = "$ctx->{prefix_abs}/share";
2861 push(@{$ctx->{directories}}, "$ctx->{share}");
2862 push(@{$ctx->{directories}}, "$ctx->{share}/test1");
2864 $ctx->{smb_conf_extra_options} = "
2867 server max protocol = SMB2
2868 samba kcc command = /bin/true
2869 xattr_tdb:file = $ctx->{statedir}/xattr.tdb
2872 path = $ctx->{statedir}/sysvol
2876 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
2880 path = $ctx->{share}
2882 posix:sharedelay = 10000
2883 posix:oplocktimeout = 3
2884 posix:writetimeupdatedelay = 50000
2887 path = $ctx->{share}/test1
2889 posix:sharedelay = 100000
2890 posix:oplocktimeout = 3
2891 posix:writetimeupdatedelay = 500000
2894 my $env = $self->provision_raw_step1($ctx);
2896 return ($env, $ctx);
2900 # Set up a DC testenv solely by using the samba-tool domain backup/restore
2901 # commands. This proves that we can backup an online DC ('backupfromdc') and
2902 # use the backup file to create a valid, working samba DC.
2905 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
2906 my ($self, $prefix, $dcvars) = @_;
2907 print "Preparing RESTORE DC...\n";
2909 # we arbitrarily designate the restored DC as having SMBv1 disabled
2911 server min protocol = SMB2
2912 client min protocol = SMB2
2913 prefork children = 1";
2915 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "restoredc",
2918 $dcvars->{PASSWORD},
2921 # create a backup of the 'backupfromdc'
2922 my $backupdir = File::Temp->newdir();
2923 my $server_args = $self->get_backup_server_args($dcvars);
2924 my $backup_args = "online $server_args";
2925 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
2927 unless($backup_file) {
2931 # restore the backup file to populate the restore-DC testenv
2932 my $restore_dir = abs_path($prefix);
2933 my $ret = $self->restore_backup_file($backup_file,
2934 "--newservername=$env->{SERVER}",
2935 $restore_dir, $env->{SERVERCONFFILE});
2936 unless ($ret == 0) {
2940 # start samba for the restored DC
2941 if (not defined($self->check_or_start($env))) {
2948 # Set up a DC testenv solely by using the 'samba-tool domain backup rename' and
2949 # restore commands. This proves that we can backup and rename an online DC
2950 # ('backupfromdc') and use the backup file to create a valid, working samba DC.
2953 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
2954 my ($self, $prefix, $dcvars) = @_;
2955 print "Preparing RENAME DC...\n";
2956 my $extra_conf = "prefork children = 1";
2958 my $realm = "renamedom.samba.example.com";
2959 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "renamedc",
2960 "RENAMEDOMAIN", $realm,
2961 $dcvars->{PASSWORD}, $extra_conf);
2963 # create a backup of the 'backupfromdc' which renames the domain
2964 my $backupdir = File::Temp->newdir();
2965 my $server_args = $self->get_backup_server_args($dcvars);
2966 my $backup_args = "rename $env->{DOMAIN} $env->{REALM} $server_args";
2967 $backup_args .= " --backend-store=tdb";
2968 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
2970 unless($backup_file) {
2974 # restore the backup file to populate the rename-DC testenv
2975 my $restore_dir = abs_path($prefix);
2976 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
2977 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
2978 $restore_dir, $env->{SERVERCONFFILE});
2979 unless ($ret == 0) {
2983 # start samba for the restored DC
2984 if (not defined($self->check_or_start($env))) {
2988 my $upn_array = ["$env->{REALM}.upn"];
2989 my $spn_array = ["$env->{REALM}.spn"];
2991 $self->setup_namespaces($env, $upn_array, $spn_array);
2996 # Set up a DC testenv solely by using the 'samba-tool domain backup offline' and
2997 # restore commands. This proves that we do an offline backup of a local DC
2998 # ('backupfromdc') and use the backup file to create a valid, working samba DC.
2999 sub setup_offlinebackupdc
3001 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
3002 my ($self, $prefix, $dcvars) = @_;
3003 print "Preparing OFFLINE BACKUP DC...\n";
3004 my $extra_conf = "prefork children = 1";
3006 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "offlinebackupdc",
3009 $dcvars->{PASSWORD}, $extra_conf);
3011 # create an offline backup of the 'backupfromdc' target
3012 my $backupdir = File::Temp->newdir();
3013 my $cmd = "offline -s $dcvars->{SERVERCONFFILE}";
3014 my $backup_file = $self->create_backup($env, $dcvars,
3017 unless($backup_file) {
3021 # restore the backup file to populate the rename-DC testenv
3022 my $restore_dir = abs_path($prefix);
3023 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
3024 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
3025 $restore_dir, $env->{SERVERCONFFILE});
3026 unless ($ret == 0) {
3030 # re-create the testenv's krb5.conf (the restore may have overwritten it)
3031 Samba::mk_krb5_conf($ctx);
3033 # start samba for the restored DC
3034 if (not defined($self->check_or_start($env))) {
3041 # Set up a DC testenv solely by using the samba-tool 'domain backup rename' and
3042 # restore commands, using the --no-secrets option. This proves that we can
3043 # create a realistic lab environment from an online DC ('backupfromdc').
3046 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
3047 my ($self, $prefix, $dcvars) = @_;
3048 print "Preparing LAB-DOMAIN DC...\n";
3049 my $extra_conf = "prefork children = 1";
3051 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "labdc",
3053 "labdom.samba.example.com",
3054 $dcvars->{PASSWORD}, $extra_conf);
3056 # create a backup of the 'backupfromdc' which renames the domain and uses
3057 # the --no-secrets option to scrub any sensitive info
3058 my $backupdir = File::Temp->newdir();
3059 my $server_args = $self->get_backup_server_args($dcvars);
3060 my $backup_args = "rename $env->{DOMAIN} $env->{REALM} $server_args";
3061 $backup_args .= " --no-secrets --backend-store=mdb";
3062 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
3064 unless($backup_file) {
3068 # restore the backup file to populate the lab-DC testenv
3069 my $restore_dir = abs_path($prefix);
3070 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
3071 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
3072 $restore_dir, $env->{SERVERCONFFILE});
3073 unless ($ret == 0) {
3077 # because we don't include any secrets in the backup, we need to reset the
3078 # admin user's password back to what the testenv expects
3079 my $samba_tool = Samba::bindir_path($self, "samba-tool");
3080 my $cmd = "$samba_tool user setpassword $env->{USERNAME} ";
3081 $cmd .= "--newpassword=$env->{PASSWORD} -H $restore_dir/private/sam.ldb";
3082 $cmd .= " $env->{CONFIGURATION}";
3084 unless(system($cmd) == 0) {
3085 warn("Failed to reset admin's password: \n$cmd");
3089 # start samba for the restored DC
3090 if (not defined($self->check_or_start($env))) {
3094 my $upn_array = ["$env->{REALM}.upn"];
3095 my $spn_array = ["$env->{REALM}.spn"];
3097 $self->setup_namespaces($env, $upn_array, $spn_array);
3102 # Inspects a backup *.tar.bz2 file and determines the realm/domain it contains
3103 sub get_backup_domain_realm
3105 my ($self, $backup_file) = @_;
3107 print "Determining REALM/DOMAIN values in backup...\n";
3109 # The backup will have the correct domain/realm values in the smb.conf.
3110 # So we can work out the env variables the testenv should use based on
3111 # that. Let's start by extracting the smb.conf
3112 my $tar = Archive::Tar->new($backup_file);
3113 my $tmpdir = File::Temp->newdir();
3114 my $smbconf = "$tmpdir/smb.conf";
3116 # note that the filepaths within the tar-file differ slightly for online
3117 # and offline backups
3118 if ($tar->contains_file("etc/smb.conf")) {
3119 $tar->extract_file("etc/smb.conf", $smbconf);
3120 } elsif ($tar->contains_file("./etc/smb.conf")) {
3121 $tar->extract_file("./etc/smb.conf", $smbconf);
3123 warn("Could not find smb.conf in $backup_file");
3124 return undef, undef;
3127 # make sure we don't try to create locks/sockets in the default install
3128 # location (i.e. /usr/local/samba/)
3129 my $options = "--option=\"private dir = $tmpdir\"";
3130 $options .= " --option=\"lock dir = $tmpdir\"";
3132 # now use testparm to read the values we're interested in
3133 my $testparm = Samba::bindir_path($self, "testparm");
3134 my $domain = `$testparm $smbconf -sl --parameter-name=WORKGROUP $options`;
3135 my $realm = `$testparm $smbconf -sl --parameter-name=REALM $options`;
3138 print "Backup-file REALM is $realm, DOMAIN is $domain\n";
3140 return ($domain, $realm);
3143 # This spins up a custom testenv that can be based on any backup-file you want.
3144 # This is just intended for manual testing (rather than automated test-cases)
3147 my ($self, $prefix) = @_;
3148 print "Preparing CUSTOM RESTORE DC...\n";
3149 my $dc_name = "customdc";
3150 my $password = "locDCpass1";
3151 my $backup_file = $ENV{'BACKUP_FILE'};
3153 # user must specify a backup file to restore via an ENV variable, i.e.
3154 # BACKUP_FILE=backup-blah.tar.bz2 SELFTEST_TESTENV=customdc make testenv
3155 if (not defined($backup_file)) {
3156 warn("Please specify BACKUP_FILE");
3160 # work out the correct domain/realm env values from the backup-file
3161 my ($domain, $realm) = $self->get_backup_domain_realm($backup_file);
3162 if ($domain eq '' or $realm eq '') {
3163 warn("Could not determine domain or realm");
3167 # create a placeholder directory and smb.conf, as well as the env vars.
3168 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, $dc_name,
3169 $domain, $realm, $password, "");
3171 # restore the specified backup file to populate the testenv
3172 my $restore_dir = abs_path($prefix);
3173 my $ret = $self->restore_backup_file($backup_file,
3174 "--newservername=$env->{SERVER}",
3175 $restore_dir, $env->{SERVERCONFFILE});
3176 unless ($ret == 0) {
3180 # Change the admin password to the testenv default, just in case it's
3181 # different, or in case this was a --no-secrets backup
3182 my $samba_tool = Samba::bindir_path($self, "samba-tool");
3183 my $cmd = "$samba_tool user setpassword $env->{USERNAME} ";
3184 $cmd .= "--newpassword=$password -H $restore_dir/private/sam.ldb";
3185 $cmd .= " $env->{CONFIGURATION}";
3187 unless(system($cmd) == 0) {
3188 warn("Failed to reset admin's password: \n$cmd");
3192 # re-create the testenv's krb5.conf (the restore may have overwritten it,
3193 # if the backup-file was an offline backup)
3194 Samba::mk_krb5_conf($ctx);
3196 # start samba for the restored DC
3197 if (not defined($self->check_or_start($env))) {
3201 # if this was a backup-rename, then we may need to setup namespaces
3202 my $upn_array = ["$env->{REALM}.upn"];
3203 my $spn_array = ["$env->{REALM}.spn"];
3205 $self->setup_namespaces($env, $upn_array, $spn_array);
3212 my ($self, $path) = @_;
3215 KRB5_CONFIG => abs_path($path) . "/no_krb5.conf",