2 # Bootstrap Samba and run a number of tests against it.
3 # Copyright (C) 2005-2007 Jelmer Vernooij <jelmer@samba.org>
4 # Published under the GNU GPL, v3 or later.
6 # NOTE: Refer to the README for more details about the various testenvs,
7 # and tips about adding new testenvs.
13 use FindBin qw($RealBin);
19 use File::Path 'make_path';
22 my ($classname, $bindir, $ldap, $srcdir, $server_maxtime) = @_;
29 server_maxtime => $server_maxtime,
30 target3 => new Samba3($bindir, $srcdir, $server_maxtime)
36 sub scriptdir_path($$) {
37 my ($self, $path) = @_;
38 return "$self->{srcdir}/source4/scripting/$path";
41 sub openldap_start($$$) {
47 my ($self, $env_vars, $STDIN_READER) = @_;
48 my $ldbsearch = Samba::bindir_path($self, "ldbsearch");
50 my $uri = $env_vars->{LDAP_URI};
52 if (system("$ldbsearch -H $uri -s base -b \"\" supportedLDAPVersion > /dev/null") == 0) {
53 print "A SLAPD is still listening to $uri before we started the LDAP backend. Aborting!";
56 # running slapd in the background means it stays in the same process group, so it can be
60 open STDOUT, ">$env_vars->{LDAPDIR}/logs";
61 open STDERR, '>&STDOUT';
62 close($env_vars->{STDIN_PIPE});
63 open STDIN, ">&", $STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
65 if ($self->{ldap} eq "fedora-ds") {
66 exec("$ENV{FEDORA_DS_ROOT}/sbin/ns-slapd", "-D", $env_vars->{FEDORA_DS_DIR}, "-d0", "-i", $env_vars->{FEDORA_DS_PIDFILE});
67 } elsif ($self->{ldap} eq "openldap") {
68 exec($ENV{OPENLDAP_SLAPD}, "-dnone", "-F", $env_vars->{SLAPD_CONF_D}, "-h", $uri);
70 die("Unable to start slapd: $!");
72 $env_vars->{SLAPD_PID} = $pid;
74 while (system("$ldbsearch -H $uri -s base -b \"\" supportedLDAPVersion > /dev/null") != 0) {
77 $self->slapd_stop($env_vars);
87 my ($self, $envvars) = @_;
88 kill 9, $envvars->{SLAPD_PID};
92 sub check_or_start($$$)
94 my ($self, $env_vars, $process_model) = @_;
97 my $env_ok = $self->check_env($env_vars);
99 return $env_vars->{SAMBA_PID};
100 } elsif (defined($env_vars->{SAMBA_PID})) {
101 warn("SAMBA PID $env_vars->{SAMBA_PID} is not running (died)");
105 # use a pipe for stdin in the child processes. This allows
106 # those processes to monitor the pipe for EOF to ensure they
107 # exit when the test script exits
108 pipe($STDIN_READER, $env_vars->{STDIN_PIPE});
110 # Start slapd before samba, but with the fifo on stdin
111 if (defined($self->{ldap})) {
112 unless($self->slapd_start($env_vars, $STDIN_READER)) {
113 warn("couldn't start slapd (main run)");
118 # build up the command to run samba
121 if (defined($ENV{SAMBA_OPTIONS})) {
122 @optargs = split(/ /, $ENV{SAMBA_OPTIONS});
124 if(defined($ENV{SAMBA_VALGRIND})) {
125 @preargs = split(/ /,$ENV{SAMBA_VALGRIND});
128 if (defined($process_model)) {
129 push @optargs, ("-M", $process_model);
131 my $binary = Samba::bindir_path($self, "samba");
132 my @full_cmd = (@preargs, $binary, "-i",
133 "--no-process-group", "--maximum-runtime=$self->{server_maxtime}",
134 $env_vars->{CONFIGURATION}, @optargs);
136 # the samba process takes some additional env variables (compared to s3)
137 my $samba_envs = Samba::get_env_for_process("samba", $env_vars);
138 $samba_envs->{RESOLV_CONF} = $env_vars->{RESOLV_CONF};
139 $samba_envs->{UID_WRAPPER} = "1";
140 if (defined($ENV{MITKRB5})) {
141 $samba_envs->{KRB5_KDC_PROFILE} = $env_vars->{MITKDC_CONFIG};
144 # fork a child process and exec() samba
147 BINARY_PATH => $binary,
148 FULL_CMD => [ @full_cmd ],
149 LOG_FILE => $env_vars->{SAMBA_TEST_LOG},
151 ENV_VARS => $samba_envs,
153 my $pid = Samba::fork_and_exec($self, $env_vars, $daemon_ctx, $STDIN_READER);
155 $env_vars->{SAMBA_PID} = $pid;
157 # close the parent's read-end of the pipe
158 close($STDIN_READER);
160 if ($self->wait_for_start($env_vars) != 0) {
161 warn("Samba $pid failed to start up");
168 sub wait_for_start($$)
170 my ($self, $testenv_vars) = @_;
174 if (not $self->check_env($testenv_vars)) {
175 warn("unable to confirm Samba $testenv_vars->{SAMBA_PID} is running");
179 # This will return quickly when things are up, but be slow if we
180 # need to wait for (eg) SSL init
181 my $nmblookup = Samba::bindir_path($self, "nmblookup4");
184 $ret = system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
188 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
189 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
190 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
191 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
192 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
193 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
194 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
195 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
196 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
197 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
198 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
201 } while ($ret != 0 && $count < 20);
203 teardown_env($self, $testenv_vars);
204 warn("nbt not reachable after 20 retries\n");
208 # Ensure we have the first RID Set before we start tests. This makes the tests more reliable.
209 if ($testenv_vars->{SERVER_ROLE} eq "domain controller") {
210 print "waiting for working LDAP and a RID Set to be allocated\n";
211 my $ldbsearch = Samba::bindir_path($self, "ldbsearch");
213 my $base_dn = "DC=".join(",DC=", split(/\./, $testenv_vars->{REALM}));
215 my $search_dn = $base_dn;
216 if ($testenv_vars->{NETBIOSNAME} ne "RODC") {
217 # TODO currently no check for actual rIDAllocationPool
218 $search_dn = "cn=RID Set,cn=$testenv_vars->{NETBIOSNAME},ou=domain controllers,$base_dn";
222 # Add hosts file for name lookups
223 my $cmd = "NSS_WRAPPER_HOSTS='$testenv_vars->{NSS_WRAPPER_HOSTS}' ";
224 if (defined($testenv_vars->{RESOLV_WRAPPER_CONF})) {
225 $cmd .= "RESOLV_WRAPPER_CONF='$testenv_vars->{RESOLV_WRAPPER_CONF}' ";
227 $cmd .= "RESOLV_WRAPPER_HOSTS='$testenv_vars->{RESOLV_WRAPPER_HOSTS}' ";
229 $cmd .= "RESOLV_CONF='$testenv_vars->{RESOLV_CONF}' ";
231 $cmd .= "$ldbsearch ";
232 $cmd .= "$testenv_vars->{CONFIGURATION} ";
233 $cmd .= "-H ldap://$testenv_vars->{SERVER} ";
234 $cmd .= "-U$testenv_vars->{USERNAME}%$testenv_vars->{PASSWORD} ";
236 $cmd .= "-b '$search_dn' ";
237 while (system("$cmd >/dev/null") != 0) {
239 if ($count > $max_wait) {
240 teardown_env($self, $testenv_vars);
241 warn("Timed out ($max_wait sec) waiting for working LDAP and a RID Set to be allocated by $testenv_vars->{NETBIOSNAME} PID $testenv_vars->{SAMBA_PID}");
244 print "Waiting for working LDAP...\n";
249 my $wbinfo = Samba::bindir_path($self, "wbinfo");
253 my $cmd = "NSS_WRAPPER_PASSWD=$testenv_vars->{NSS_WRAPPER_PASSWD} ";
254 $cmd .= "NSS_WRAPPER_GROUP=$testenv_vars->{NSS_WRAPPER_GROUP} ";
255 $cmd .= "SELFTEST_WINBINDD_SOCKET_DIR=$testenv_vars->{SELFTEST_WINBINDD_SOCKET_DIR} ";
256 $cmd .= "$wbinfo -P";
263 } while ($ret != 0 && $count < 20);
265 teardown_env($self, $testenv_vars);
266 warn("winbind not reachable after 20 retries\n");
270 # Ensure we registered all our names
271 if ($testenv_vars->{SERVER_ROLE} eq "domain controller") {
273 print "Waiting for dns_update_cache to be created.\n";
275 while (not -e "$testenv_vars->{PRIVATEDIR}/dns_update_cache") {
277 if ($count > $max_wait) {
278 teardown_env($self, $testenv_vars);
279 warn("Timed out ($max_wait sec) waiting for dns_update_cache PID $testenv_vars->{SAMBA_PID}");
282 print "Waiting for dns_update_cache to be created...\n";
285 print "Waiting for dns_update_cache to be filled.\n";
287 while ((-s "$testenv_vars->{PRIVATEDIR}/dns_update_cache") == 0) {
289 if ($count > $max_wait) {
290 teardown_env($self, $testenv_vars);
291 warn("Timed out ($max_wait sec) waiting for dns_update_cache PID $testenv_vars->{SAMBA_PID}");
294 print "Waiting for dns_update_cache to be filled...\n";
299 print $self->getlog_env($testenv_vars);
301 print "READY ($testenv_vars->{SAMBA_PID})\n";
306 sub write_ldb_file($$$)
308 my ($self, $file, $ldif) = @_;
310 my $ldbadd = Samba::bindir_path($self, "ldbadd");
311 open(LDIF, "|$ldbadd -H $file >/dev/null");
316 sub add_wins_config($$)
318 my ($self, $privatedir) = @_;
319 my $client_ip = Samba::get_ipv4_addr("client");
321 return $self->write_ldb_file("$privatedir/wins_config.ldb", "
322 dn: name=TORTURE_11,CN=PARTNERS
323 objectClass: wreplPartner
334 my ($self, $ctx) = @_;
336 #Make the subdirectory be as fedora DS would expect
337 my $fedora_ds_dir = "$ctx->{ldapdir}/slapd-$ctx->{ldap_instance}";
339 my $pidfile = "$fedora_ds_dir/logs/slapd-$ctx->{ldap_instance}.pid";
341 return ($fedora_ds_dir, $pidfile);
346 my ($self, $ctx) = @_;
348 my $slapd_conf_d = "$ctx->{ldapdir}/slapd.d";
349 my $pidfile = "$ctx->{ldapdir}/slapd.pid";
351 return ($slapd_conf_d, $pidfile);
354 sub setup_dns_hub_internal($$$)
356 my ($self, $hostname, $prefix) = @_;
359 unless(-d $prefix or make_path($prefix, 0777)) {
360 warn("Unable to create $prefix");
363 my $prefix_abs = abs_path($prefix);
365 die ("prefix=''") if $prefix_abs eq "";
366 die ("prefix='/'") if $prefix_abs eq "/";
368 unless (system("rm -rf $prefix_abs/*") == 0) {
369 warn("Unable to clean up");
373 $env->{NETBIOSNAME} = $hostname;
375 $env->{SERVER_IP} = Samba::get_ipv4_addr($hostname);
376 $env->{SERVER_IPV6} = Samba::get_ipv6_addr($hostname);
377 $env->{SOCKET_WRAPPER_DEFAULT_IFACE} = Samba::get_interface($hostname);
378 $env->{DNS_HUB_LOG} = "$prefix_abs/dns_hub.log";
379 $env->{RESOLV_CONF} = "$prefix_abs/resolv.conf";
380 $env->{TESTENV_DIR} = $prefix_abs;
382 open(RESOLV_CONF, ">$env->{RESOLV_CONF}");
383 print RESOLV_CONF "nameserver $env->{SERVER_IP}\n";
384 print RESOLV_CONF "nameserver $env->{SERVER_IPV6}\n";
389 if (!defined($ENV{PYTHON})) {
390 push (@preargs, "env");
391 push (@preargs, "python");
393 push (@preargs, $ENV{PYTHON});
395 my $binary = "$self->{srcdir}/selftest/target/dns_hub.py";
396 push (@args, "$self->{server_maxtime}");
397 push (@args, "$env->{SERVER_IP}");
398 push (@args, Samba::realm_to_ip_mappings());
399 my @full_cmd = (@preargs, $binary, @args);
403 BINARY_PATH => $binary,
404 FULL_CMD => [ @full_cmd ],
405 LOG_FILE => $env->{DNS_HUB_LOG},
407 PCAP_FILE => "$ENV{SOCKET_WRAPPER_PCAP_DIR}/env-$hostname$.pcap",
411 # use a pipe for stdin in the child processes. This allows
412 # those processes to monitor the pipe for EOF to ensure they
413 # exit when the test script exits
414 pipe($STDIN_READER, $env->{STDIN_PIPE});
416 my $pid = Samba::fork_and_exec($self, $env, $daemon_ctx, $STDIN_READER);
418 $env->{SAMBA_PID} = $pid;
419 $env->{KRB5_CONFIG} = "$prefix_abs/no_krb5.conf";
421 # close the parent's read-end of the pipe
422 close($STDIN_READER);
429 my ($self, $prefix) = @_;
431 my $hostname = "rootdnsforwarder";
433 my $env = $self->setup_dns_hub_internal("$hostname", "$prefix/$hostname");
435 $self->{dns_hub_env} = $env;
440 sub get_dns_hub_env($)
442 my ($self, $prefix) = @_;
444 if (defined($self->{dns_hub_env})) {
445 return $self->{dns_hub_env};
448 die("get_dns_hub_env() not setup 'dns_hub_env'");
452 # Returns the environmental variables that we pass to samba-tool commands
455 my ($self, $localenv) = @_;
457 my $cmd_env = "NSS_WRAPPER_HOSTS='$localenv->{NSS_WRAPPER_HOSTS}' ";
458 $cmd_env .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$localenv->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
459 if (defined($localenv->{RESOLV_WRAPPER_CONF})) {
460 $cmd_env .= "RESOLV_WRAPPER_CONF=\"$localenv->{RESOLV_WRAPPER_CONF}\" ";
462 $cmd_env .= "RESOLV_WRAPPER_HOSTS=\"$localenv->{RESOLV_WRAPPER_HOSTS}\" ";
464 $cmd_env .= " KRB5_CONFIG=\"$localenv->{KRB5_CONFIG}\" ";
465 $cmd_env .= "KRB5CCNAME=\"$localenv->{KRB5_CCACHE}\" ";
466 $cmd_env .= "RESOLV_CONF=\"$localenv->{RESOLV_CONF}\" ";
471 # Sets up a forest trust namespace.
472 # (Note this is different to kernel namespaces, setup by the
473 # USE_NAMESPACES=1 option)
474 sub setup_namespaces($$:$$)
476 my ($self, $localenv, $upn_array, $spn_array) = @_;
478 @{$upn_array} = [] unless defined($upn_array);
480 foreach my $upn (@{$upn_array}) {
481 $upn_args .= " --add-upn-suffix=$upn";
484 @{$spn_array} = [] unless defined($spn_array);
486 foreach my $spn (@{$spn_array}) {
487 $spn_args .= " --add-spn-suffix=$spn";
490 my $samba_tool = Samba::bindir_path($self, "samba-tool");
492 my $cmd_env = $self->get_cmd_env_vars($localenv);
494 my $cmd_config = " $localenv->{CONFIGURATION}";
496 my $namespaces = $cmd_env;
497 $namespaces .= " $samba_tool domain trust namespaces $upn_args $spn_args";
498 $namespaces .= $cmd_config;
499 unless (system($namespaces) == 0) {
500 warn("Failed to add namespaces \n$namespaces");
507 sub setup_trust($$$$$)
509 my ($self, $localenv, $remoteenv, $type, $extra_args) = @_;
511 $localenv->{TRUST_SERVER} = $remoteenv->{SERVER};
513 $localenv->{TRUST_USERNAME} = $remoteenv->{USERNAME};
514 $localenv->{TRUST_PASSWORD} = $remoteenv->{PASSWORD};
515 $localenv->{TRUST_DOMAIN} = $remoteenv->{DOMAIN};
516 $localenv->{TRUST_REALM} = $remoteenv->{REALM};
517 $localenv->{TRUST_DOMSID} = $remoteenv->{DOMSID};
519 my $samba_tool = Samba::bindir_path($self, "samba-tool");
522 my $cmd_env = $self->get_cmd_env_vars($localenv);
524 my $cmd_config = " $localenv->{CONFIGURATION}";
525 my $cmd_creds = $cmd_config;
526 $cmd_creds .= " -U$localenv->{TRUST_DOMAIN}\\\\$localenv->{TRUST_USERNAME}\%$localenv->{TRUST_PASSWORD}";
528 my $create = $cmd_env;
529 $create .= " $samba_tool domain trust create --type=${type} $localenv->{TRUST_REALM}";
530 $create .= " $extra_args";
531 $create .= $cmd_creds;
532 unless (system($create) == 0) {
533 warn("Failed to create trust \n$create");
537 my $groupname = "g_$localenv->{TRUST_DOMAIN}";
538 my $groupadd = $cmd_env;
539 $groupadd .= " $samba_tool group add '$groupname' --group-scope=Domain $cmd_config";
540 unless (system($groupadd) == 0) {
541 warn("Failed to create group \n$groupadd");
544 my $groupmem = $cmd_env;
545 $groupmem .= " $samba_tool group addmembers '$groupname' '$localenv->{TRUST_DOMSID}-513' $cmd_config";
546 unless (system($groupmem) == 0) {
547 warn("Failed to add group member \n$groupmem");
554 sub provision_raw_prepare($$$$$$$$$$$$)
556 my ($self, $prefix, $server_role, $hostname,
557 $domain, $realm, $samsid, $functional_level,
558 $password, $kdc_ipv4, $kdc_ipv6) = @_;
561 if (defined $ENV{PYTHON}) {
562 $python_cmd = $ENV{PYTHON} . " ";
564 $ctx->{python} = $python_cmd;
565 my $netbiosname = uc($hostname);
567 unless(-d $prefix or mkdir($prefix, 0777)) {
568 warn("Unable to create $prefix");
571 my $prefix_abs = abs_path($prefix);
573 die ("prefix=''") if $prefix_abs eq "";
574 die ("prefix='/'") if $prefix_abs eq "/";
576 unless (system("rm -rf $prefix_abs/*") == 0) {
577 warn("Unable to clean up");
581 my $swiface = Samba::get_interface($hostname);
583 $ctx->{prefix} = $prefix;
584 $ctx->{prefix_abs} = $prefix_abs;
586 $ctx->{server_role} = $server_role;
587 $ctx->{hostname} = $hostname;
588 $ctx->{netbiosname} = $netbiosname;
589 $ctx->{swiface} = $swiface;
590 $ctx->{password} = $password;
591 $ctx->{kdc_ipv4} = $kdc_ipv4;
592 $ctx->{kdc_ipv6} = $kdc_ipv6;
593 $ctx->{krb5_ccname} = "$prefix_abs/krb5cc_%{uid}";
594 if ($functional_level eq "2000") {
595 $ctx->{supported_enctypes} = "arcfour-hmac-md5 des-cbc-md5 des-cbc-crc"
599 # Set smbd log level here.
601 $ctx->{server_loglevel} =$ENV{SERVER_LOG_LEVEL} || 1;
602 $ctx->{username} = "Administrator";
603 $ctx->{domain} = $domain;
604 $ctx->{realm} = uc($realm);
605 $ctx->{dnsname} = lc($realm);
606 $ctx->{samsid} = $samsid;
608 $ctx->{functional_level} = $functional_level;
610 my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `whoami`);
612 $ctx->{unix_name} = $unix_name;
613 $ctx->{unix_uid} = $>;
614 my @mygid = split(" ", $();
615 $ctx->{unix_gid} = $mygid[0];
616 $ctx->{unix_gids_str} = $);
617 @{$ctx->{unix_gids}} = split(" ", $ctx->{unix_gids_str});
619 $ctx->{etcdir} = "$prefix_abs/etc";
620 $ctx->{piddir} = "$prefix_abs/pid";
621 $ctx->{smb_conf} = "$ctx->{etcdir}/smb.conf";
622 $ctx->{krb5_conf} = "$ctx->{etcdir}/krb5.conf";
623 $ctx->{krb5_ccache} = "$prefix_abs/krb5_ccache";
624 $ctx->{mitkdc_conf} = "$ctx->{etcdir}/mitkdc.conf";
625 $ctx->{privatedir} = "$prefix_abs/private";
626 $ctx->{binddnsdir} = "$prefix_abs/bind-dns";
627 $ctx->{ncalrpcdir} = "$prefix_abs/ncalrpc";
628 $ctx->{lockdir} = "$prefix_abs/lockdir";
629 $ctx->{logdir} = "$prefix_abs/logs";
630 $ctx->{statedir} = "$prefix_abs/statedir";
631 $ctx->{cachedir} = "$prefix_abs/cachedir";
632 $ctx->{winbindd_socket_dir} = "$prefix_abs/winbindd_socket";
633 $ctx->{ntp_signd_socket_dir} = "$prefix_abs/ntp_signd_socket";
634 $ctx->{nsswrap_passwd} = "$ctx->{etcdir}/passwd";
635 $ctx->{nsswrap_group} = "$ctx->{etcdir}/group";
636 $ctx->{nsswrap_hosts} = "$ENV{SELFTEST_PREFIX}/hosts";
637 $ctx->{nsswrap_hostname} = "$ctx->{hostname}.$ctx->{dnsname}";
638 if ($ENV{SAMBA_DNS_FAKING}) {
639 $ctx->{dns_host_file} = "$ENV{SELFTEST_PREFIX}/dns_host_file";
640 $ctx->{samba_dnsupdate} = "$ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate -s $ctx->{smb_conf} --all-interfaces --use-file=$ctx->{dns_host_file}";
641 $ctx->{samba_dnsupdate} = $python_cmd . $ctx->{samba_dnsupdate};
643 $ctx->{samba_dnsupdate} = "$ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate -s $ctx->{smb_conf} --all-interfaces";
644 $ctx->{samba_dnsupdate} = $python_cmd . $ctx->{samba_dnsupdate};
645 $ctx->{use_resolv_wrapper} = 1;
648 my $dns_hub = $self->get_dns_hub_env();
649 $ctx->{resolv_conf} = $dns_hub->{RESOLV_CONF};
651 $ctx->{tlsdir} = "$ctx->{privatedir}/tls";
653 $ctx->{ipv4} = Samba::get_ipv4_addr($hostname);
654 $ctx->{ipv6} = Samba::get_ipv6_addr($hostname);
656 push(@{$ctx->{directories}}, $ctx->{privatedir});
657 push(@{$ctx->{directories}}, $ctx->{binddnsdir});
658 push(@{$ctx->{directories}}, $ctx->{etcdir});
659 push(@{$ctx->{directories}}, $ctx->{piddir});
660 push(@{$ctx->{directories}}, $ctx->{lockdir});
661 push(@{$ctx->{directories}}, $ctx->{logdir});
662 push(@{$ctx->{directories}}, $ctx->{statedir});
663 push(@{$ctx->{directories}}, $ctx->{cachedir});
665 $ctx->{smb_conf_extra_options} = "";
667 my @provision_options = ();
668 push (@provision_options, "KRB5_CONFIG=\"$ctx->{krb5_conf}\"");
669 push (@provision_options, "KRB5_CCACHE=\"$ctx->{krb5_ccache}\"");
670 push (@provision_options, "NSS_WRAPPER_PASSWD=\"$ctx->{nsswrap_passwd}\"");
671 push (@provision_options, "NSS_WRAPPER_GROUP=\"$ctx->{nsswrap_group}\"");
672 push (@provision_options, "NSS_WRAPPER_HOSTS=\"$ctx->{nsswrap_hosts}\"");
673 push (@provision_options, "NSS_WRAPPER_HOSTNAME=\"$ctx->{nsswrap_hostname}\"");
674 if (defined($ctx->{use_resolv_wrapper})) {
675 push (@provision_options, "RESOLV_WRAPPER_CONF=\"$ctx->{resolv_conf}\"");
676 push (@provision_options, "RESOLV_CONF=\"$ctx->{resolv_conf}\"");
678 push (@provision_options, "RESOLV_WRAPPER_HOSTS=\"$ctx->{dns_host_file}\"");
680 if (defined($ENV{GDB_PROVISION})) {
681 push (@provision_options, "gdb --args");
682 if (!defined($ENV{PYTHON})) {
683 push (@provision_options, "env");
684 push (@provision_options, "python");
687 if (defined($ENV{VALGRIND_PROVISION})) {
688 push (@provision_options, "valgrind");
689 if (!defined($ENV{PYTHON})) {
690 push (@provision_options, "env");
691 push (@provision_options, "python");
695 my $samba_tool = Samba::bindir_path($self, "samba-tool");
697 push (@provision_options, $samba_tool);
698 push (@provision_options, "domain");
699 push (@provision_options, "provision");
700 push (@provision_options, "--configfile=$ctx->{smb_conf}");
701 push (@provision_options, "--host-name=$ctx->{hostname}");
702 push (@provision_options, "--host-ip=$ctx->{ipv4}");
703 push (@provision_options, "--quiet");
704 push (@provision_options, "--domain=$ctx->{domain}");
705 push (@provision_options, "--realm=$ctx->{realm}");
706 if (defined($ctx->{samsid})) {
707 push (@provision_options, "--domain-sid=$ctx->{samsid}");
709 push (@provision_options, "--adminpass=$ctx->{password}");
710 push (@provision_options, "--krbtgtpass=krbtgt$ctx->{password}");
711 push (@provision_options, "--machinepass=machine$ctx->{password}");
712 push (@provision_options, "--root=$ctx->{unix_name}");
713 push (@provision_options, "--server-role=\"$ctx->{server_role}\"");
714 push (@provision_options, "--function-level=\"$ctx->{functional_level}\"");
716 @{$ctx->{provision_options}} = @provision_options;
723 my ($self, $keyword, @options_list) = @_;
725 # convert the options-list to a hash-map for easy keyword lookup
726 my %options_dict = map { $_ => 1 } @options_list;
728 return exists $options_dict{$keyword};
732 # Step1 creates the basic configuration
734 sub provision_raw_step1($$)
736 my ($self, $ctx) = @_;
738 mkdir($_, 0777) foreach (@{$ctx->{directories}});
741 ## lockdir and piddir must be 0755
743 chmod 0755, $ctx->{lockdir};
744 chmod 0755, $ctx->{piddir};
746 unless (open(CONFFILE, ">$ctx->{smb_conf}")) {
747 warn("can't open $ctx->{smb_conf}$?");
751 Samba::prepare_keyblobs($ctx);
752 my $crlfile = "$ctx->{tlsdir}/crl.pem";
753 $crlfile = "" unless -e ${crlfile};
755 # work out which file server to use. Default to source3 smbd (s3fs),
756 # unless the source4 NTVFS (smb) file server has been specified
757 my $services = "-smb +s3fs";
758 if ($self->has_option("--use-ntvfs", @{$ctx->{provision_options}})) {
759 $services = "+smb -s3fs";
762 my $interfaces = Samba::get_interfaces_config($ctx->{netbiosname});
766 netbios name = $ctx->{netbiosname}
767 posix:eadb = $ctx->{statedir}/eadb.tdb
768 workgroup = $ctx->{domain}
769 realm = $ctx->{realm}
770 private dir = $ctx->{privatedir}
771 binddns dir = $ctx->{binddnsdir}
772 pid directory = $ctx->{piddir}
773 ncalrpc dir = $ctx->{ncalrpcdir}
774 lock dir = $ctx->{lockdir}
775 state directory = $ctx->{statedir}
776 cache directory = $ctx->{cachedir}
777 winbindd socket directory = $ctx->{winbindd_socket_dir}
778 ntp signd socket directory = $ctx->{ntp_signd_socket_dir}
779 winbind separator = /
780 interfaces = $interfaces
781 tls dh params file = $ctx->{tlsdir}/dhparms.pem
782 tls crlfile = ${crlfile}
783 tls verify peer = no_check
784 panic action = $RealBin/gdb_backtrace \%d
786 server role = $ctx->{server_role}
787 server services = +echo $services
788 dcerpc endpoint servers = +winreg +srvsvc
789 notify:inotify = false
791 ldap server require strong auth = yes
792 #We don't want to pass our self-tests if the PAC code is wrong
793 gensec:require_pac = true
794 log file = $ctx->{logdir}/log.\%m
795 log level = $ctx->{server_loglevel}
799 client min protocol = CORE
800 server min protocol = LANMAN1
802 dns update command = $ctx->{samba_dnsupdate}
803 spn update command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_spnupdate -s $ctx->{smb_conf}
804 gpo update command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba-gpupdate -s $ctx->{smb_conf} --target=Computer
805 samba kcc command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_kcc
806 dreplsrv:periodic_startup_interval = 0
807 dsdb:schema update allowed = yes
809 vfs objects = dfs_samba4 acl_xattr fake_acls xattr_tdb streams_depot
811 idmap_ldb:use rfc2307=yes
812 winbind enum users = yes
813 winbind enum groups = yes
815 rpc server port:netlogon = 1026
816 include system krb5 conf = no
822 # Begin extra options
823 $ctx->{smb_conf_extra_options}
828 #Default the KDC IP to the server's IP
829 if (not defined($ctx->{kdc_ipv4})) {
830 $ctx->{kdc_ipv4} = $ctx->{ipv4};
832 if (not defined($ctx->{kdc_ipv6})) {
833 $ctx->{kdc_ipv6} = $ctx->{ipv6};
836 Samba::mk_krb5_conf($ctx);
837 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
839 open(PWD, ">$ctx->{nsswrap_passwd}");
840 if ($ctx->{unix_uid} != 0) {
841 print PWD "root:x:0:0:root gecos:$ctx->{prefix_abs}:/bin/false\n";
843 print PWD "$ctx->{unix_name}:x:$ctx->{unix_uid}:65531:$ctx->{unix_name} gecos:$ctx->{prefix_abs}:/bin/false\n";
844 print PWD "nobody:x:65534:65533:nobody gecos:$ctx->{prefix_abs}:/bin/false
845 pdbtest:x:65533:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
846 pdbtest2:x:65532:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
847 pdbtest3:x:65531:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
848 pdbtest4:x:65530:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
851 my $uid_rfc2307test = 65533;
853 open(GRP, ">$ctx->{nsswrap_group}");
854 if ($ctx->{unix_gid} != 0) {
855 print GRP "root:x:0:\n";
857 print GRP "$ctx->{unix_name}:x:$ctx->{unix_gid}:\n";
858 print GRP "wheel:x:10:
861 nogroup:x:65534:nobody
864 my $gid_rfc2307test = 65532;
866 my $hostname = lc($ctx->{hostname});
867 open(HOSTS, ">>$ctx->{nsswrap_hosts}");
868 if ($hostname eq "localdc") {
869 print HOSTS "$ctx->{ipv4} ${hostname}.$ctx->{dnsname} $ctx->{dnsname} ${hostname}\n";
870 print HOSTS "$ctx->{ipv6} ${hostname}.$ctx->{dnsname} $ctx->{dnsname} ${hostname}\n";
872 print HOSTS "$ctx->{ipv4} ${hostname}.$ctx->{dnsname} ${hostname}\n";
873 print HOSTS "$ctx->{ipv6} ${hostname}.$ctx->{dnsname} ${hostname}\n";
877 my $configuration = "--configfile=$ctx->{smb_conf}";
879 #Ensure the config file is valid before we start
880 my $testparm = Samba::bindir_path($self, "samba-tool") . " testparm";
881 if (system("$testparm $configuration -v --suppress-prompt >/dev/null 2>&1") != 0) {
882 system("$testparm -v --suppress-prompt $configuration >&2");
883 warn("Failed to create a valid smb.conf configuration $testparm!");
886 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) {
887 warn("Failed to create a valid smb.conf configuration! $testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global");
891 # Return the environment variables for the new testenv DC.
892 # Note that we have SERVER_X and DC_SERVER_X variables (which have the same
893 # value initially). In a 2 DC setup, $DC_SERVER_X will always be the PDC.
895 KRB5_CONFIG => $ctx->{krb5_conf},
896 KRB5_CCACHE => $ctx->{krb5_ccache},
897 MITKDC_CONFIG => $ctx->{mitkdc_conf},
898 PIDDIR => $ctx->{piddir},
899 SERVER => $ctx->{hostname},
900 DC_SERVER => $ctx->{hostname},
901 SERVER_IP => $ctx->{ipv4},
902 DC_SERVER_IP => $ctx->{ipv4},
903 SERVER_IPV6 => $ctx->{ipv6},
904 DC_SERVER_IPV6 => $ctx->{ipv6},
905 NETBIOSNAME => $ctx->{netbiosname},
906 DC_NETBIOSNAME => $ctx->{netbiosname},
907 DOMAIN => $ctx->{domain},
908 USERNAME => $ctx->{username},
909 DC_USERNAME => $ctx->{username},
910 REALM => $ctx->{realm},
911 DNSNAME => $ctx->{dnsname},
912 SAMSID => $ctx->{samsid},
913 PASSWORD => $ctx->{password},
914 DC_PASSWORD => $ctx->{password},
915 LDAPDIR => $ctx->{ldapdir},
916 LDAP_INSTANCE => $ctx->{ldap_instance},
917 SELFTEST_WINBINDD_SOCKET_DIR => $ctx->{winbindd_socket_dir},
918 NCALRPCDIR => $ctx->{ncalrpcdir},
919 LOCKDIR => $ctx->{lockdir},
920 STATEDIR => $ctx->{statedir},
921 CACHEDIR => $ctx->{cachedir},
922 PRIVATEDIR => $ctx->{privatedir},
923 BINDDNSDIR => $ctx->{binddnsdir},
924 SERVERCONFFILE => $ctx->{smb_conf},
925 TESTENV_DIR => $ctx->{prefix_abs},
926 CONFIGURATION => $configuration,
927 SOCKET_WRAPPER_DEFAULT_IFACE => $ctx->{swiface},
928 NSS_WRAPPER_PASSWD => $ctx->{nsswrap_passwd},
929 NSS_WRAPPER_GROUP => $ctx->{nsswrap_group},
930 NSS_WRAPPER_HOSTS => $ctx->{nsswrap_hosts},
931 NSS_WRAPPER_HOSTNAME => $ctx->{nsswrap_hostname},
932 SAMBA_TEST_FIFO => "$ctx->{prefix}/samba_test.fifo",
933 SAMBA_TEST_LOG => "$ctx->{prefix}/samba_test.log",
934 SAMBA_TEST_LOG_POS => 0,
935 NSS_WRAPPER_MODULE_SO_PATH => Samba::nss_wrapper_winbind_so_path($self),
936 NSS_WRAPPER_MODULE_FN_PREFIX => "winbind",
937 LOCAL_PATH => $ctx->{share},
938 UID_RFC2307TEST => $uid_rfc2307test,
939 GID_RFC2307TEST => $gid_rfc2307test,
940 SERVER_ROLE => $ctx->{server_role},
941 RESOLV_CONF => $ctx->{resolv_conf}
944 if (defined($ctx->{use_resolv_wrapper})) {
945 $ret->{RESOLV_WRAPPER_CONF} = $ctx->{resolv_conf};
947 $ret->{RESOLV_WRAPPER_HOSTS} = $ctx->{dns_host_file};
950 if ($ctx->{server_role} eq "domain controller") {
951 $ret->{DOMSID} = $ret->{SAMSID};
958 # Step2 runs the provision script
960 sub provision_raw_step2($$$)
962 my ($self, $ctx, $ret) = @_;
964 my $provision_cmd = join(" ", @{$ctx->{provision_options}});
965 unless (system($provision_cmd) == 0) {
966 warn("Unable to provision: \n$provision_cmd\n");
970 my $testallowed_account = "testallowed";
971 my $samba_tool_cmd = "";
972 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
973 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
974 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
975 . " user create --configfile=$ctx->{smb_conf} $testallowed_account $ctx->{password}";
976 unless (system($samba_tool_cmd) == 0) {
977 warn("Unable to add testallowed user: \n$samba_tool_cmd\n");
982 $ldbmodify .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
983 $ldbmodify .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
984 $ldbmodify .= Samba::bindir_path($self, "ldbmodify");
985 $ldbmodify .= " --configfile=$ctx->{smb_conf}";
986 my $base_dn = "DC=".join(",DC=", split(/\./, $ctx->{realm}));
988 if ($ctx->{server_role} ne "domain controller") {
989 $base_dn = "DC=$ctx->{netbiosname}";
992 my $user_dn = "cn=$testallowed_account,cn=users,$base_dn";
993 $testallowed_account = "testallowed account";
994 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
995 print LDIF "dn: $user_dn
997 replace: samAccountName
998 samAccountName: $testallowed_account
1003 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
1004 print LDIF "dn: $user_dn
1006 replace: userPrincipalName
1007 userPrincipalName: testallowed upn\@$ctx->{realm}
1008 replace: servicePrincipalName
1009 servicePrincipalName: host/testallowed
1014 $samba_tool_cmd = "";
1015 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1016 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1017 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1018 . " user create --configfile=$ctx->{smb_conf} testdenied $ctx->{password}";
1019 unless (system($samba_tool_cmd) == 0) {
1020 warn("Unable to add testdenied user: \n$samba_tool_cmd\n");
1024 my $user_dn = "cn=testdenied,cn=users,$base_dn";
1025 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
1026 print LDIF "dn: $user_dn
1028 replace: userPrincipalName
1029 userPrincipalName: testdenied_upn\@$ctx->{realm}.upn
1034 $samba_tool_cmd = "";
1035 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1036 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1037 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1038 . " user create --configfile=$ctx->{smb_conf} testupnspn $ctx->{password}";
1039 unless (system($samba_tool_cmd) == 0) {
1040 warn("Unable to add testupnspn user: \n$samba_tool_cmd\n");
1044 my $user_dn = "cn=testupnspn,cn=users,$base_dn";
1045 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
1046 print LDIF "dn: $user_dn
1048 replace: userPrincipalName
1049 userPrincipalName: http/testupnspn.$ctx->{dnsname}\@$ctx->{realm}
1050 replace: servicePrincipalName
1051 servicePrincipalName: http/testupnspn.$ctx->{dnsname}
1056 $samba_tool_cmd = "";
1057 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1058 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1059 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1060 . " group addmembers --configfile=$ctx->{smb_conf} 'Allowed RODC Password Replication Group' '$testallowed_account'";
1061 unless (system($samba_tool_cmd) == 0) {
1062 warn("Unable to add '$testallowed_account' user to 'Allowed RODC Password Replication Group': \n$samba_tool_cmd\n");
1066 # Create to users alice and bob!
1067 my $user_account_array = ["alice", "bob", "jane"];
1069 foreach my $user_account (@{$user_account_array}) {
1070 my $samba_tool_cmd = "";
1072 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1073 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1074 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1075 . " user create --configfile=$ctx->{smb_conf} $user_account Secret007";
1076 unless (system($samba_tool_cmd) == 0) {
1077 warn("Unable to create user: $user_account\n$samba_tool_cmd\n");
1083 $ldbmodify .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1084 $ldbmodify .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1085 $ldbmodify .= Samba::bindir_path($self, "ldbmodify");
1086 $ldbmodify .= " --configfile=$ctx->{smb_conf}";
1087 my $base_dn = "DC=".join(",DC=", split(/\./, $ctx->{realm}));
1088 my $user_dn = "cn=jane,cn=users,$base_dn";
1090 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
1091 print LDIF "dn: $user_dn
1093 replace: userPrincipalName
1094 userPrincipalName: jane.doe\@$ctx->{realm}
1102 sub provision($$$$$$$$$$)
1104 my ($self, $prefix, $server_role, $hostname,
1105 $domain, $realm, $functional_level,
1106 $password, $kdc_ipv4, $kdc_ipv6, $extra_smbconf_options, $extra_smbconf_shares,
1107 $extra_provision_options) = @_;
1109 my $samsid = Samba::random_domain_sid();
1111 my $ctx = $self->provision_raw_prepare($prefix, $server_role,
1116 $password, $kdc_ipv4, $kdc_ipv6);
1118 if (defined($extra_provision_options)) {
1119 push (@{$ctx->{provision_options}}, @{$extra_provision_options});
1122 $ctx->{share} = "$ctx->{prefix_abs}/share";
1123 push(@{$ctx->{directories}}, "$ctx->{share}");
1124 push(@{$ctx->{directories}}, "$ctx->{share}/test1");
1125 push(@{$ctx->{directories}}, "$ctx->{share}/test2");
1127 # precreate directories for printer drivers
1128 push(@{$ctx->{directories}}, "$ctx->{share}/W32X86");
1129 push(@{$ctx->{directories}}, "$ctx->{share}/x64");
1130 push(@{$ctx->{directories}}, "$ctx->{share}/WIN40");
1133 $msdfs = "yes" if ($server_role eq "domain controller");
1134 $ctx->{smb_conf_extra_options} = "
1137 server max protocol = SMB2
1141 # fruit:copyfile is a global option
1142 fruit:copyfile = yes
1144 $extra_smbconf_options
1147 path = $ctx->{share}
1149 posix:sharedelay = 100000
1150 posix:oplocktimeout = 3
1151 posix:writetimeupdatedelay = 500000
1154 path = $ctx->{share}
1156 posix:sharedelay = 100000
1157 posix:oplocktimeout = 3
1158 posix:writetimeupdatedelay = 500000
1160 force create mode = 777
1163 path = $ctx->{share}
1166 force create mode = 0
1167 directory mask = 0777
1168 force directory mode = 0
1171 path = $ctx->{share}/test1
1173 posix:sharedelay = 100000
1174 posix:oplocktimeout = 3
1175 posix:writetimeupdatedelay = 500000
1178 path = $ctx->{share}/test2
1180 posix:sharedelay = 100000
1181 posix:oplocktimeout = 3
1182 posix:writetimeupdatedelay = 500000
1185 path = $ctx->{share}/_ignore_cifs_
1187 ntvfs handler = cifs
1188 cifs:server = $ctx->{netbiosname}
1190 cifs:use-s4u2proxy = yes
1191 # There is no username specified here, instead the client is expected
1192 # to log in with kerberos, and the serverwill use delegated credentials.
1193 # Or the server tries s4u2self/s4u2proxy to impersonate the client
1196 path = $ctx->{share}
1198 ntvfs handler = simple
1201 path = $ctx->{statedir}/sysvol
1205 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1210 ntvfs handler = cifsposix
1213 path = $ctx->{share}
1214 vfs objects = catia fruit streams_xattr acl_xattr
1216 fruit:resource = file
1217 fruit:metadata = netatalk
1218 fruit:locking = netatalk
1219 fruit:encoding = native
1222 path = $ctx->{share}
1223 # This can be used for testing real fs xattr stuff
1224 vfs objects = streams_xattr acl_xattr
1226 $extra_smbconf_shares
1229 if (defined($self->{ldap})) {
1230 $ctx->{ldapdir} = "$ctx->{privatedir}/ldap";
1231 push(@{$ctx->{directories}}, "$ctx->{ldapdir}");
1233 my $ldap_uri= "$ctx->{ldapdir}/ldapi";
1234 $ldap_uri =~ s|/|%2F|g;
1235 $ldap_uri = "ldapi://$ldap_uri";
1236 $ctx->{ldap_uri} = $ldap_uri;
1238 $ctx->{ldap_instance} = lc($ctx->{netbiosname});
1241 my $ret = $self->provision_raw_step1($ctx);
1242 unless (defined $ret) {
1246 if (defined($self->{ldap})) {
1247 $ret->{LDAP_URI} = $ctx->{ldap_uri};
1248 push (@{$ctx->{provision_options}}, "--ldap-backend-type=" . $self->{ldap});
1249 push (@{$ctx->{provision_options}}, "--ldap-backend-nosync");
1250 if ($self->{ldap} eq "openldap") {
1251 push (@{$ctx->{provision_options}}, "--slapd-path=" . $ENV{OPENLDAP_SLAPD});
1252 ($ret->{SLAPD_CONF_D}, $ret->{OPENLDAP_PIDFILE}) = $self->mk_openldap($ctx) or die("Unable to create openldap directories");
1254 } elsif ($self->{ldap} eq "fedora-ds") {
1255 push (@{$ctx->{provision_options}}, "--slapd-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/ns-slapd");
1256 push (@{$ctx->{provision_options}}, "--setup-ds-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/setup-ds.pl");
1257 ($ret->{FEDORA_DS_DIR}, $ret->{FEDORA_DS_PIDFILE}) = $self->mk_fedora_ds($ctx) or die("Unable to create fedora ds directories");
1262 return $self->provision_raw_step2($ctx, $ret);
1265 # For multi-DC testenvs, we want $DC_SERVER to always be the PDC (i.e. the
1266 # original DC) in the testenv. $SERVER is always the joined DC that we are
1267 # actually running the test against
1268 sub set_pdc_env_vars
1270 my ($self, $env, $dcvars) = @_;
1272 $env->{DC_SERVER} = $dcvars->{DC_SERVER};
1273 $env->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1274 $env->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1275 $env->{DC_SERVERCONFFILE} = $dcvars->{SERVERCONFFILE};
1276 $env->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1277 $env->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1278 $env->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1281 sub provision_s4member($$$$$)
1283 my ($self, $prefix, $dcvars, $hostname, $more_conf) = @_;
1284 print "PROVISIONING MEMBER...\n";
1285 my $extra_smb_conf = "
1286 passdb backend = samba_dsdb
1287 winbindd:use external pipes = true
1289 # the source4 smb server doesn't allow signing by default
1290 server signing = enabled
1291 raw NTLMv2 auth = yes
1293 rpc_server:default = external
1294 rpc_server:svcctl = embedded
1295 rpc_server:srvsvc = embedded
1296 rpc_server:eventlog = embedded
1297 rpc_server:ntsvcs = embedded
1298 rpc_server:winreg = embedded
1299 rpc_server:spoolss = embedded
1300 rpc_daemon:spoolssd = embedded
1301 rpc_server:tcpip = no
1304 $extra_smb_conf = $extra_smb_conf . $more_conf . "\n";
1306 my $extra_provision_options = ["--use-ntvfs"];
1307 my $ret = $self->provision($prefix,
1314 $dcvars->{SERVER_IP},
1315 $dcvars->{SERVER_IPV6},
1316 $extra_smb_conf, "",
1317 $extra_provision_options);
1322 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1323 my $cmd = $self->get_cmd_env_vars($ret);
1324 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
1325 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1326 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1328 unless (system($cmd) == 0) {
1329 warn("Join failed\n$cmd");
1333 $ret->{DOMSID} = $dcvars->{DOMSID};
1334 $self->set_pdc_env_vars($ret, $dcvars);
1339 sub provision_rpc_proxy($$$)
1341 my ($self, $prefix, $dcvars) = @_;
1342 print "PROVISIONING RPC PROXY...\n";
1344 my $extra_smbconf_options = "
1345 passdb backend = samba_dsdb
1348 dcerpc_remote:binding = ncacn_ip_tcp:$dcvars->{SERVER}
1349 dcerpc endpoint servers = epmapper, remote
1350 dcerpc_remote:interfaces = rpcecho
1351 dcerpc_remote:allow_anonymous_fallback = yes
1354 path = /tmp/_ignore_cifs_to_dc_/_none_
1356 ntvfs handler = cifs
1357 cifs:server = $dcvars->{SERVER}
1359 cifs:use-s4u2proxy = yes
1360 # There is no username specified here, instead the client is expected
1361 # to log in with kerberos, and the serverwill use delegated credentials.
1362 # Or the server tries s4u2self/s4u2proxy to impersonate the client
1366 my $extra_provision_options = ["--use-ntvfs"];
1367 my $ret = $self->provision($prefix,
1374 $dcvars->{SERVER_IP},
1375 $dcvars->{SERVER_IPV6},
1376 $extra_smbconf_options, "",
1377 $extra_provision_options);
1382 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1384 # The joind runs in the context of the rpc_proxy/member for now
1385 my $cmd = $self->get_cmd_env_vars($ret);
1386 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
1387 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1388 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1390 unless (system($cmd) == 0) {
1391 warn("Join failed\n$cmd");
1395 # Setting up delegation runs in the context of the DC for now
1397 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1398 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
1399 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1400 $cmd .= "RESOLV_CONF=\"$dcvars->{RESOLV_CONF}\" ";
1401 $cmd .= "$samba_tool delegation for-any-protocol '$ret->{NETBIOSNAME}\$' on";
1402 $cmd .= " $dcvars->{CONFIGURATION}";
1405 unless (system($cmd) == 0) {
1406 warn("Delegation failed\n$cmd");
1410 # Setting up delegation runs in the context of the DC for now
1412 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1413 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
1414 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1415 $cmd .= "RESOLV_CONF=\"$dcvars->{RESOLV_CONF}\" ";
1416 $cmd .= "$samba_tool delegation add-service '$ret->{NETBIOSNAME}\$' cifs/$dcvars->{SERVER}";
1417 $cmd .= " $dcvars->{CONFIGURATION}";
1419 unless (system($cmd) == 0) {
1420 warn("Delegation failed\n$cmd");
1424 $ret->{DOMSID} = $dcvars->{DOMSID};
1425 $self->set_pdc_env_vars($ret, $dcvars);
1430 sub provision_promoted_dc($$$)
1432 my ($self, $prefix, $dcvars) = @_;
1433 print "PROVISIONING PROMOTED DC...\n";
1435 # We do this so that we don't run the provision. That's the job of 'samba-tool domain dcpromo'.
1436 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1442 $dcvars->{PASSWORD},
1443 $dcvars->{SERVER_IP},
1444 $dcvars->{SERVER_IPV6});
1446 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1448 $ctx->{smb_conf_extra_options} = "
1450 server max protocol = SMB2
1452 ntlm auth = ntlmv2-only
1455 path = $ctx->{statedir}/sysvol
1459 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1464 my $ret = $self->provision_raw_step1($ctx);
1469 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1470 my $cmd = $self->get_cmd_env_vars($ret);
1471 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} MEMBER --realm=$dcvars->{REALM}";
1472 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1473 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1475 unless (system($cmd) == 0) {
1476 warn("Join failed\n$cmd");
1480 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1481 my $cmd = $self->get_cmd_env_vars($ret);
1482 $cmd .= "$samba_tool domain dcpromo $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1483 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1484 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs --dns-backend=BIND9_DLZ";
1486 unless (system($cmd) == 0) {
1487 warn("Join failed\n$cmd");
1491 $self->set_pdc_env_vars($ret, $dcvars);
1496 sub provision_vampire_dc($$$)
1498 my ($self, $prefix, $dcvars, $fl) = @_;
1499 print "PROVISIONING VAMPIRE DC @ FL $fl...\n";
1500 my $name = "localvampiredc";
1501 my $extra_conf = "";
1503 if ($fl == "2000") {
1504 $name = "vampire2000dc";
1506 $extra_conf = "drs: immediate link sync = yes
1507 drs: max link sync = 250";
1510 # We do this so that we don't run the provision. That's the job of 'net vampire'.
1511 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1517 $dcvars->{PASSWORD},
1518 $dcvars->{SERVER_IP},
1519 $dcvars->{SERVER_IPV6});
1521 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1523 $ctx->{smb_conf_extra_options} = "
1525 server max protocol = SMB2
1527 ntlm auth = mschapv2-and-ntlmv2-only
1531 path = $ctx->{statedir}/sysvol
1535 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1540 my $ret = $self->provision_raw_step1($ctx);
1545 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1546 my $cmd = $self->get_cmd_env_vars($ret);
1547 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1548 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} --domain-critical-only";
1549 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs";
1550 $cmd .= " --backend-store=mdb";
1552 unless (system($cmd) == 0) {
1553 warn("Join failed\n$cmd");
1557 $self->set_pdc_env_vars($ret, $dcvars);
1558 $ret->{DC_REALM} = $dcvars->{DC_REALM};
1563 sub provision_ad_dc_ntvfs($$$)
1565 my ($self, $prefix, $extra_provision_options) = @_;
1567 # We keep the old 'winbind' name here in server services to
1568 # ensure upgrades which used that name still work with the now
1571 print "PROVISIONING AD DC (NTVFS)...\n";
1572 my $extra_conf_options = "netbios aliases = localDC1-a
1573 server services = +winbind -winbindd
1574 ldap server require strong auth = allow_sasl_over_tls
1575 allow nt4 crypto = yes
1576 raw NTLMv2 auth = yes
1577 lsa over netlogon = yes
1578 rpc server port = 1027
1579 auth event notification = true
1580 dsdb event notification = true
1581 dsdb password event notification = true
1582 dsdb group change notification = true
1583 server schannel = auto
1585 push (@{$extra_provision_options}, "--use-ntvfs");
1586 my $ret = $self->provision($prefix,
1587 "domain controller",
1590 "samba.example.com",
1595 $extra_conf_options,
1597 $extra_provision_options);
1602 unless($self->add_wins_config("$prefix/private")) {
1603 warn("Unable to add wins configuration");
1606 $ret->{NETBIOSALIAS} = "localdc1-a";
1607 $ret->{DC_REALM} = $ret->{REALM};
1612 sub provision_fl2000dc($$)
1614 my ($self, $prefix) = @_;
1616 print "PROVISIONING DC WITH FOREST LEVEL 2000...\n";
1617 my $extra_conf_options = "
1618 spnego:simulate_w2k=yes
1619 ntlmssp_server:force_old_spnego=yes
1621 my $extra_provision_options = ["--use-ntvfs", "--base-schema=2008_R2"];
1622 # This environment uses plain text secrets
1623 # i.e. secret attributes are not encrypted on disk.
1624 # This allows testing of the --plaintext-secrets option for
1626 push (@{$extra_provision_options}, "--plaintext-secrets");
1627 my $ret = $self->provision($prefix,
1628 "domain controller",
1631 "samba2000.example.com",
1636 $extra_conf_options,
1638 $extra_provision_options);
1643 unless($self->add_wins_config("$prefix/private")) {
1644 warn("Unable to add wins configuration");
1647 $ret->{DC_REALM} = $ret->{REALM};
1652 sub provision_fl2003dc($$$)
1654 my ($self, $prefix, $dcvars) = @_;
1655 my $ip_addr1 = Samba::get_ipv4_addr("fakednsforwarder1");
1656 my $ip_addr2 = Samba::get_ipv4_addr("fakednsforwarder2");
1658 print "PROVISIONING DC WITH FOREST LEVEL 2003...\n";
1659 my $extra_conf_options = "allow dns updates = nonsecure and secure
1660 dcesrv:header signing = no
1661 dcesrv:max auth states = 0
1662 dns forwarder = $ip_addr1 $ip_addr2";
1663 my $extra_provision_options = ["--use-ntvfs", "--base-schema=2008_R2"];
1664 my $ret = $self->provision($prefix,
1665 "domain controller",
1668 "samba2003.example.com",
1673 $extra_conf_options,
1675 $extra_provision_options);
1676 unless (defined $ret) {
1680 $ret->{DNS_FORWARDER1} = $ip_addr1;
1681 $ret->{DNS_FORWARDER2} = $ip_addr2;
1683 my @samba_tool_options;
1684 push (@samba_tool_options, Samba::bindir_path($self, "samba-tool"));
1685 push (@samba_tool_options, "domain");
1686 push (@samba_tool_options, "passwordsettings");
1687 push (@samba_tool_options, "set");
1688 push (@samba_tool_options, "--configfile=$ret->{SERVERCONFFILE}");
1689 push (@samba_tool_options, "--min-pwd-age=0");
1690 push (@samba_tool_options, "--history-length=1");
1692 my $samba_tool_cmd = join(" ", @samba_tool_options);
1694 unless (system($samba_tool_cmd) == 0) {
1695 warn("Unable to set min password age to 0: \n$samba_tool_cmd\n");
1699 unless($self->add_wins_config("$prefix/private")) {
1700 warn("Unable to add wins configuration");
1707 sub provision_fl2008r2dc($$$)
1709 my ($self, $prefix, $dcvars) = @_;
1711 print "PROVISIONING DC WITH FOREST LEVEL 2008r2...\n";
1712 my $extra_conf_options = "ldap server require strong auth = no";
1713 my $extra_provision_options = ["--use-ntvfs", "--base-schema=2008_R2"];
1714 my $ret = $self->provision($prefix,
1715 "domain controller",
1718 "samba2008R2.example.com",
1723 $extra_conf_options,
1725 $extra_provision_options);
1726 unless (defined $ret) {
1730 unless ($self->add_wins_config("$prefix/private")) {
1731 warn("Unable to add wins configuration");
1734 $ret->{DC_REALM} = $ret->{REALM};
1740 sub provision_rodc($$$)
1742 my ($self, $prefix, $dcvars) = @_;
1743 print "PROVISIONING RODC...\n";
1745 # We do this so that we don't run the provision. That's the job of 'net join RODC'.
1746 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1752 $dcvars->{PASSWORD},
1753 $dcvars->{SERVER_IP},
1754 $dcvars->{SERVER_IPV6});
1759 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1761 $ctx->{share} = "$ctx->{prefix_abs}/share";
1762 push(@{$ctx->{directories}}, "$ctx->{share}");
1764 $ctx->{smb_conf_extra_options} = "
1766 server max protocol = SMB2
1767 password server = $dcvars->{DC_SERVER}
1770 path = $ctx->{statedir}/sysvol
1774 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1778 path = $ctx->{share}
1780 posix:sharedelay = 10000
1781 posix:oplocktimeout = 3
1782 posix:writetimeupdatedelay = 50000
1786 my $ret = $self->provision_raw_step1($ctx);
1791 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1792 my $cmd = $self->get_cmd_env_vars($ret);
1793 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} RODC";
1794 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1795 $cmd .= " --server=$dcvars->{DC_SERVER} --use-ntvfs";
1797 unless (system($cmd) == 0) {
1798 warn("RODC join failed\n$cmd");
1802 # This ensures deterministic behaviour for tests that want to have the 'testallowed account'
1803 # user password verified on the RODC
1804 my $testallowed_account = "testallowed account";
1805 $cmd = "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1806 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1807 $cmd .= "RESOLV_CONF=\"$ret->{RESOLV_CONF}\" ";
1808 $cmd .= "$samba_tool rodc preload '$testallowed_account' $ret->{CONFIGURATION}";
1809 $cmd .= " --server=$dcvars->{DC_SERVER}";
1811 unless (system($cmd) == 0) {
1812 warn("RODC join failed\n$cmd");
1816 # we overwrite the kdc after the RODC join
1817 # so that use the RODC as kdc and test
1819 $ctx->{kdc_ipv4} = $ret->{SERVER_IP};
1820 $ctx->{kdc_ipv6} = $ret->{SERVER_IPV6};
1821 Samba::mk_krb5_conf($ctx);
1822 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
1824 $self->set_pdc_env_vars($ret, $dcvars);
1829 sub read_config_h($)
1833 open(LF, "<$name") or die("unable to read $name: $!");
1836 next if not (/^#define /);
1837 if (/^#define (.*?)[ \t]+(.*?)$/) {
1841 if (/^#define (.*?)[ \t]+$/) {
1850 sub provision_ad_dc($$$$$$)
1852 my ($self, $prefix, $hostname, $domain, $realm, $smbconf_args,
1853 $extra_provision_options) = @_;
1855 my $prefix_abs = abs_path($prefix);
1857 my $bindir_abs = abs_path($self->{bindir});
1858 my $lockdir="$prefix_abs/lockdir";
1859 my $conffile="$prefix_abs/etc/smb.conf";
1861 my $require_mutexes = "dbwrap_tdb_require_mutexes:* = yes";
1862 $require_mutexes = "" if ($ENV{SELFTEST_DONT_REQUIRE_TDB_MUTEX_SUPPORT} eq "1");
1866 if (defined($ENV{CONFIG_H})) {
1867 $config_h = read_config_h($ENV{CONFIG_H});
1870 my $password_hash_gpg_key_ids = "password hash gpg key ids = 4952E40301FAB41A";
1871 $password_hash_gpg_key_ids = "" unless defined($config_h->{HAVE_GPGME});
1873 my $extra_smbconf_options = "
1874 xattr_tdb:file = $prefix_abs/statedir/xattr.tdb
1876 dbwrap_tdb_mutexes:* = yes
1879 ${password_hash_gpg_key_ids}
1882 kernel change notify = no
1887 printcap name = /dev/null
1892 smbd:sharedelay = 100000
1893 smbd:writetimeupdatedelay = 500000
1896 check parent directory delete on close = yes
1898 dcerpc endpoint servers = -winreg -srvsvc
1900 printcap name = /dev/null
1902 addprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -a -s $conffile --
1903 deleteprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -d -s $conffile --
1906 print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
1907 lpq command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpq %p
1908 lp rm command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lprm %p %j
1909 lp pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lppause %p %j
1910 lp resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpresume %p %j
1911 queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
1912 queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
1914 print notify backchannel = yes
1916 server schannel = auto
1917 auth event notification = true
1918 dsdb event notification = true
1919 dsdb password event notification = true
1920 dsdb group change notification = true
1924 my $extra_smbconf_shares = "
1928 smb encrypt = required
1932 case sensitive = yes
1940 hide unreadable = yes
1944 kernel share modes = no
1963 push (@{$extra_provision_options}, "--backend-store=mdb");
1964 print "PROVISIONING AD DC...\n";
1965 my $ret = $self->provision($prefix,
1966 "domain controller",
1974 $extra_smbconf_options,
1975 $extra_smbconf_shares,
1976 $extra_provision_options);
1977 unless (defined $ret) {
1981 unless($self->add_wins_config("$prefix/private")) {
1982 warn("Unable to add wins configuration");
1989 sub provision_chgdcpass($$)
1991 my ($self, $prefix) = @_;
1993 print "PROVISIONING CHGDCPASS...\n";
1994 # This environment disallows the use of this password
1995 # (and also removes the default AD complexity checks)
1996 my $unacceptable_password = "widk3Dsle32jxdBdskldsk55klASKQ";
1997 my $extra_smb_conf = "
1998 check password script = $self->{srcdir}/selftest/checkpassword_arg1.sh ${unacceptable_password}
1999 allow dcerpc auth level connect:lsarpc = yes
2000 dcesrv:max auth states = 8
2002 my $extra_provision_options = ["--use-ntvfs"];
2003 push (@{$extra_provision_options}, "--dns-backend=BIND9_DLZ");
2004 my $ret = $self->provision($prefix,
2005 "domain controller",
2008 "chgdcpassword.samba.example.com",
2015 $extra_provision_options);
2016 unless (defined $ret) {
2020 unless($self->add_wins_config("$prefix/private")) {
2021 warn("Unable to add wins configuration");
2025 # Remove secrets.tdb from this environment to test that we
2026 # still start up on systems without the new matching
2027 # secrets.tdb records.
2028 unless (unlink("$ret->{PRIVATEDIR}/secrets.tdb") || unlink("$ret->{PRIVATEDIR}/secrets.ntdb")) {
2029 warn("Unable to remove $ret->{PRIVATEDIR}/secrets.tdb added during provision");
2033 $ret->{UNACCEPTABLE_PASSWORD} = $unacceptable_password;
2038 sub teardown_env_terminate($$)
2040 my ($self, $envvars) = @_;
2043 # This should cause samba to terminate gracefully
2044 my $smbcontrol = Samba::bindir_path($self, "smbcontrol");
2046 $cmd .= "$smbcontrol samba shutdown $envvars->{CONFIGURATION}";
2047 my $ret = system($cmd);
2049 warn "'$cmd' failed with '$ret'\n";
2052 # This should cause samba to terminate gracefully
2053 close($envvars->{STDIN_PIPE});
2055 $pid = $envvars->{SAMBA_PID};
2059 # This should give it time to write out the gcov data
2060 until ($count > 15) {
2061 if (Samba::cleanup_child($pid, "samba") != 0) {
2068 # After 15 Seconds, work out why this thing is still alive
2069 warn "server process $pid took more than $count seconds to exit, showing backtrace:\n";
2070 system("$self->{srcdir}/selftest/gdb_backtrace $pid");
2072 until ($count > 30) {
2073 if (Samba::cleanup_child($pid, "samba") != 0) {
2080 if (kill(0, $pid)) {
2081 warn "server process $pid took more than $count seconds to exit, sending SIGTERM\n";
2085 until ($count > 40) {
2086 if (Samba::cleanup_child($pid, "samba") != 0) {
2092 # If it is still around, kill it
2093 if (kill(0, $pid)) {
2094 warn "server process $pid took more than $count seconds to exit, killing\n with SIGKILL\n";
2100 sub teardown_env($$)
2102 my ($self, $envvars) = @_;
2103 teardown_env_terminate($self, $envvars);
2105 $self->slapd_stop($envvars) if ($self->{ldap});
2107 print $self->getlog_env($envvars);
2114 my ($self, $envvars) = @_;
2115 my $title = "SAMBA LOG of: $envvars->{NETBIOSNAME} pid $envvars->{SAMBA_PID}\n";
2118 open(LOG, "<$envvars->{SAMBA_TEST_LOG}");
2120 seek(LOG, $envvars->{SAMBA_TEST_LOG_POS}, SEEK_SET);
2124 $envvars->{SAMBA_TEST_LOG_POS} = tell(LOG);
2127 return "" if $out eq $title;
2134 my ($self, $envvars) = @_;
2135 my $samba_pid = $envvars->{SAMBA_PID};
2137 if (not defined($samba_pid)) {
2139 } elsif ($samba_pid > 0) {
2140 my $childpid = Samba::cleanup_child($samba_pid, "samba");
2142 if ($childpid == 0) {
2151 # Declare the environments Samba4 makes available.
2152 # To be set up, they will be called as
2153 # samba4->setup_$envname($self, $path, $dep_1_vars, $dep_2_vars, ...)
2154 # The interdependencies between the testenvs are declared below. Some testenvs
2155 # are dependent on another testenv running first, e.g. vampire_dc is dependent
2156 # on ad_dc_ntvfs because vampire_dc joins ad_dc_ntvfs's domain. All DCs are
2157 # dependent on dns_hub, which handles resolving DNS queries for the realm.
2158 %Samba4::ENV_DEPS = (
2159 # name => [dep_1, dep_2, ...],
2161 ad_dc_ntvfs => ["dns_hub"],
2162 ad_dc => ["dns_hub"],
2163 ad_dc_no_nss => ["dns_hub"],
2164 ad_dc_no_ntlm => ["dns_hub"],
2166 fl2008r2dc => ["ad_dc"],
2167 fl2003dc => ["ad_dc"],
2168 fl2000dc => ["dns_hub"],
2170 vampire_2000_dc => ["fl2000dc"],
2171 vampire_dc => ["ad_dc_ntvfs"],
2172 promoted_dc => ["ad_dc_ntvfs"],
2174 rodc => ["ad_dc_ntvfs"],
2175 rpc_proxy => ["ad_dc_ntvfs"],
2176 chgdcpass => ["dns_hub"],
2178 s4member_dflt_domain => ["ad_dc_ntvfs"],
2179 s4member => ["ad_dc_ntvfs"],
2181 # envs that test the server process model
2182 proclimitdc => ["dns_hub"],
2183 preforkrestartdc => ["dns_hub"],
2185 # backup/restore testenvs
2186 backupfromdc => ["dns_hub"],
2187 customdc => ["dns_hub"],
2188 restoredc => ["backupfromdc"],
2189 renamedc => ["backupfromdc"],
2190 offlinebackupdc => ["backupfromdc"],
2191 labdc => ["backupfromdc"],
2193 # aliases in order to split autbuild tasks
2194 fl2008dc => ["ad_dc_ntvfs"],
2195 ad_dc_default => ["ad_dc_ntvfs"],
2196 ad_dc_slowtests => ["ad_dc_ntvfs"],
2197 ad_dc_backup => ["ad_dc"],
2199 schema_dc => ["dns_hub"],
2200 schema_pair_dc => ["schema_dc"],
2205 %Samba4::ENV_DEPS_POST = (
2206 schema_dc => ["schema_pair_dc"],
2209 sub return_alias_env
2211 my ($self, $path, $env) = @_;
2219 my ($self, $path) = @_;
2221 my $extra_args = ["--base-schema=2008_R2"];
2222 my $env = $self->provision_ad_dc_ntvfs($path, $extra_args);
2224 if (not defined($self->check_or_start($env, "standard"))) {
2225 warn("Failed to start fl2008dc");
2232 sub setup_ad_dc_default
2234 my ($self, $path, $dep_env) = @_;
2235 return $self->return_alias_env($path, $dep_env)
2238 sub setup_ad_dc_slowtests
2240 my ($self, $path, $dep_env) = @_;
2241 return $self->return_alias_env($path, $dep_env)
2244 sub setup_ad_dc_backup
2246 my ($self, $path, $dep_env) = @_;
2247 return $self->return_alias_env($path, $dep_env)
2252 my ($self, $path, $dc_vars) = @_;
2254 my $env = $self->provision_s4member($path, $dc_vars, "s4member");
2257 if (not defined($self->check_or_start($env, "standard"))) {
2265 sub setup_s4member_dflt_domain
2267 my ($self, $path, $dc_vars) = @_;
2269 my $env = $self->provision_s4member($path, $dc_vars, "s4member_dflt",
2270 "winbind use default domain = yes");
2273 if (not defined($self->check_or_start($env, "standard"))) {
2283 my ($self, $path, $dc_vars) = @_;
2285 my $env = $self->provision_rpc_proxy($path, $dc_vars);
2288 if (not defined($self->check_or_start($env, "standard"))) {
2295 sub setup_ad_dc_ntvfs
2297 my ($self, $path) = @_;
2299 my $env = $self->provision_ad_dc_ntvfs($path, undef);
2301 if (not defined($self->check_or_start($env, "standard"))) {
2302 warn("Failed to start ad_dc_ntvfs");
2311 my ($self, $path) = @_;
2313 my $env = $self->provision_chgdcpass($path);
2315 if (not defined($self->check_or_start($env, "standard"))) {
2324 my ($self, $path) = @_;
2326 my $env = $self->provision_fl2000dc($path);
2328 if (not defined($self->check_or_start($env, "standard"))) {
2338 my ($self, $path, $dc_vars) = @_;
2340 my $env = $self->provision_fl2003dc($path);
2343 if (not defined($self->check_or_start($env, "standard"))) {
2347 $env = $self->setup_trust($env, $dc_vars, "external", "--no-aes-keys");
2352 sub setup_fl2008r2dc
2354 my ($self, $path, $dc_vars) = @_;
2356 my $env = $self->provision_fl2008r2dc($path);
2359 if (not defined($self->check_or_start($env, "standard"))) {
2363 my $upn_array = ["$env->{REALM}.upn"];
2364 my $spn_array = ["$env->{REALM}.spn"];
2366 $self->setup_namespaces($env, $upn_array, $spn_array);
2368 $env = $self->setup_trust($env, $dc_vars, "forest", "");
2374 sub setup_vampire_dc
2376 return setup_generic_vampire_dc(@_, "2008");
2379 sub setup_vampire_2000_dc
2381 return setup_generic_vampire_dc(@_, "2000");
2384 sub setup_generic_vampire_dc
2386 my ($self, $path, $dc_vars, $fl) = @_;
2388 my $env = $self->provision_vampire_dc($path, $dc_vars, $fl);
2391 if (not defined($self->check_or_start($env, "single"))) {
2395 # force replicated DC to update repsTo/repsFrom
2396 # for vampired partitions
2397 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2399 # as 'vampired' dc may add data in its local replica
2400 # we need to synchronize data between DCs
2401 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2402 my $cmd = $self->get_cmd_env_vars($env);
2403 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2404 $cmd .= " $dc_vars->{CONFIGURATION}";
2405 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2406 # replicate Configuration NC
2407 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2408 unless(system($cmd_repl) == 0) {
2409 warn("Failed to replicate\n$cmd_repl");
2412 # replicate Default NC
2413 $cmd_repl = "$cmd \"$base_dn\"";
2414 unless(system($cmd_repl) == 0) {
2415 warn("Failed to replicate\n$cmd_repl");
2419 # Pull in a full set of changes from the main DC
2420 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2421 $cmd = $self->get_cmd_env_vars($env);
2422 $cmd .= " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}";
2423 $cmd .= " $dc_vars->{CONFIGURATION}";
2424 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2425 # replicate Configuration NC
2426 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2427 unless(system($cmd_repl) == 0) {
2428 warn("Failed to replicate\n$cmd_repl");
2431 # replicate Default NC
2432 $cmd_repl = "$cmd \"$base_dn\"";
2433 unless(system($cmd_repl) == 0) {
2434 warn("Failed to replicate\n$cmd_repl");
2442 sub setup_promoted_dc
2444 my ($self, $path, $dc_vars) = @_;
2446 my $env = $self->provision_promoted_dc($path, $dc_vars);
2449 if (not defined($self->check_or_start($env, "single"))) {
2453 # force source and replicated DC to update repsTo/repsFrom
2454 # for vampired partitions
2455 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2456 my $cmd = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2457 # as 'vampired' dc may add data in its local replica
2458 # we need to synchronize data between DCs
2459 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2460 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2461 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2462 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2463 $cmd .= "RESOLV_CONF=\"$env->{RESOLV_CONF}\" ";
2464 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2465 $cmd .= " $dc_vars->{CONFIGURATION}";
2466 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2467 # replicate Configuration NC
2468 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2469 unless(system($cmd_repl) == 0) {
2470 warn("Failed to replicate\n$cmd_repl");
2473 # replicate Default NC
2474 $cmd_repl = "$cmd \"$base_dn\"";
2475 unless(system($cmd_repl) == 0) {
2476 warn("Failed to replicate\n$cmd_repl");
2486 my ($self, $path, $dc_vars) = @_;
2488 my $env = $self->provision_rodc($path, $dc_vars);
2494 if (not defined($self->check_or_start($env, "standard"))) {
2498 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2501 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2502 $cmd .= "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2503 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2504 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2505 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2506 $cmd .= "RESOLV_CONF=\"$env->{RESOLV_CONF}\" ";
2507 $cmd .= " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}";
2508 $cmd .= " $dc_vars->{CONFIGURATION}";
2509 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2510 # replicate Configuration NC
2511 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2512 unless(system($cmd_repl) == 0) {
2513 warn("Failed to replicate\n$cmd_repl");
2516 # replicate Default NC
2517 $cmd_repl = "$cmd \"$base_dn\"";
2518 unless(system($cmd_repl) == 0) {
2519 warn("Failed to replicate\n$cmd_repl");
2528 my ($self, $path) = @_;
2530 # If we didn't build with ADS, pretend this env was never available
2531 if (not $self->{target3}->have_ads()) {
2535 my $env = $self->provision_ad_dc($path, "addc", "ADDOMAIN",
2536 "addom.samba.example.com", "", undef);
2541 if (not defined($self->check_or_start($env, "prefork"))) {
2545 my $upn_array = ["$env->{REALM}.upn"];
2546 my $spn_array = ["$env->{REALM}.spn"];
2548 $self->setup_namespaces($env, $upn_array, $spn_array);
2553 sub setup_ad_dc_no_nss
2555 my ($self, $path) = @_;
2557 # If we didn't build with ADS, pretend this env was never available
2558 if (not $self->{target3}->have_ads()) {
2562 my $env = $self->provision_ad_dc($path, "addc_no_nss", "ADNONSSDOMAIN",
2563 "adnonssdom.samba.example.com", "", undef);
2568 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2569 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2571 if (not defined($self->check_or_start($env, "single"))) {
2575 my $upn_array = ["$env->{REALM}.upn"];
2576 my $spn_array = ["$env->{REALM}.spn"];
2578 $self->setup_namespaces($env, $upn_array, $spn_array);
2583 sub setup_ad_dc_no_ntlm
2585 my ($self, $path) = @_;
2587 # If we didn't build with ADS, pretend this env was never available
2588 if (not $self->{target3}->have_ads()) {
2592 my $env = $self->provision_ad_dc($path, "addc_no_ntlm", "ADNONTLMDOMAIN",
2593 "adnontlmdom.samba.example.com",
2594 "ntlm auth = disabled", undef);
2599 if (not defined($self->check_or_start($env, "prefork"))) {
2603 my $upn_array = ["$env->{REALM}.upn"];
2604 my $spn_array = ["$env->{REALM}.spn"];
2606 $self->setup_namespaces($env, $upn_array, $spn_array);
2612 # AD DC test environment used solely to test pre-fork process restarts.
2613 # As processes get killed off and restarted it should not be used for other
2614 sub setup_preforkrestartdc
2616 my ($self, $path) = @_;
2618 # If we didn't build with ADS, pretend this env was never available
2619 if (not $self->{target3}->have_ads()) {
2623 # note DC name must be <= 15 chars so we use 'prockill' instead of
2625 my $env = $self->provision_ad_dc(
2629 "prockilldom.samba.example.com",
2630 "prefork backoff increment = 5\nprefork maximum backoff=10");
2635 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2636 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2638 if (not defined($self->check_or_start($env, "prefork"))) {
2642 my $upn_array = ["$env->{REALM}.upn"];
2643 my $spn_array = ["$env->{REALM}.spn"];
2645 $self->setup_namespaces($env, $upn_array, $spn_array);
2651 # ad_dc test environment used solely to test standard process model connection
2652 # process limits. As the limit is set artificially low it should not be used
2654 sub setup_proclimitdc
2656 my ($self, $path) = @_;
2658 # If we didn't build with ADS, pretend this env was never available
2659 if (not $self->{target3}->have_ads()) {
2663 my $env = $self->provision_ad_dc(
2667 "proclimit.samba.example.com",
2668 "max smbd processes = 20");
2673 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2674 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2676 if (not defined($self->check_or_start($env, "standard"))) {
2680 my $upn_array = ["$env->{REALM}.upn"];
2681 my $spn_array = ["$env->{REALM}.spn"];
2683 $self->setup_namespaces($env, $upn_array, $spn_array);
2688 # Used to test a live upgrade of the schema on a 2 DC network.
2691 my ($self, $path) = @_;
2693 # provision the PDC using an older base schema
2694 my $provision_args = ["--base-schema=2008_R2", "--backend-store=mdb"];
2696 my $env = $self->provision_ad_dc($path, "liveupgrade1dc", "SCHEMADOMAIN",
2697 "schema.samba.example.com",
2698 "drs: max link sync = 2",
2704 if (not defined($self->check_or_start($env, "prefork"))) {
2708 my $upn_array = ["$env->{REALM}.upn"];
2709 my $spn_array = ["$env->{REALM}.spn"];
2711 $self->setup_namespaces($env, $upn_array, $spn_array);
2716 # the second DC in the live schema upgrade pair
2717 sub setup_schema_pair_dc
2719 # note: dcvars contains the env info for the dependent testenv ('schema_dc')
2720 my ($self, $prefix, $dcvars) = @_;
2721 print "Preparing SCHEMA UPGRADE PAIR DC...\n";
2723 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "liveupgrade2dc",
2726 $dcvars->{PASSWORD},
2729 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2730 my $cmd_vars = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2731 $cmd_vars .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2732 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2733 $cmd_vars .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2735 $cmd_vars .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2737 $cmd_vars .= "KRB5_CONFIG=\"$env->{KRB5_CONFIG}\" ";
2738 $cmd_vars .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2739 $cmd_vars .= "RESOLV_CONF=\"$env->{RESOLV_CONF}\" ";
2741 my $join_cmd = $cmd_vars;
2742 $join_cmd .= "$samba_tool domain join $env->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
2743 $join_cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} ";
2744 $join_cmd .= " --backend-store=mdb";
2746 my $upgrade_cmd = $cmd_vars;
2747 $upgrade_cmd .= "$samba_tool domain schemaupgrade $dcvars->{CONFIGURATION}";
2748 $upgrade_cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}";
2750 my $repl_cmd = $cmd_vars;
2751 $repl_cmd .= "$samba_tool drs replicate $env->{SERVER} $dcvars->{SERVER}";
2752 $repl_cmd .= " CN=Schema,CN=Configuration,DC=schema,DC=samba,DC=example,DC=com";
2753 $repl_cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
2755 unless (system($join_cmd) == 0) {
2756 warn("Join failed\n$join_cmd");
2760 $env->{DC_SERVER} = $dcvars->{SERVER};
2761 $env->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
2762 $env->{DC_SERVER_IPV6} = $dcvars->{SERVER_IPV6};
2763 $env->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
2765 # start samba for the new DC
2766 if (not defined($self->check_or_start($env, "standard"))) {
2770 unless (system($upgrade_cmd) == 0) {
2771 warn("Schema upgrade failed\n$upgrade_cmd");
2775 unless (system($repl_cmd) == 0) {
2776 warn("Post-update schema replication failed\n$repl_cmd");
2783 # Sets up a DC that's solely used to do a domain backup from. We then use the
2784 # backupfrom-DC to create the restore-DC - this proves that the backup/restore
2785 # process will create a Samba DC that will actually start up.
2786 # We don't use the backup-DC for anything else because its domain will conflict
2787 # with the restore DC.
2788 sub setup_backupfromdc
2790 my ($self, $path) = @_;
2792 # If we didn't build with ADS, pretend this env was never available
2793 if (not $self->{target3}->have_ads()) {
2797 my $provision_args = ["--site=Backup-Site"];
2799 my $env = $self->provision_ad_dc($path, "backupfromdc", "BACKUPDOMAIN",
2800 "backupdom.samba.example.com",
2801 "samba kcc command = /bin/true",
2807 if (not defined($self->check_or_start($env))) {
2811 my $upn_array = ["$env->{REALM}.upn"];
2812 my $spn_array = ["$env->{REALM}.spn"];
2814 $self->setup_namespaces($env, $upn_array, $spn_array);
2819 # returns the server/user-auth params needed to run an online backup cmd
2820 sub get_backup_server_args
2822 # dcvars contains the env info for the backup DC testenv
2823 my ($self, $dcvars) = @_;
2824 my $server = $dcvars->{DC_SERVER_IP};
2825 my $server_args = "--server=$server ";
2826 $server_args .= "-U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
2827 $server_args .= " $dcvars->{CONFIGURATION}";
2829 return $server_args;
2832 # Creates a backup of a running testenv DC
2835 # note: dcvars contains the env info for the backup DC testenv
2836 my ($self, $env, $dcvars, $backupdir, $backup_cmd) = @_;
2838 # get all the env variables we pass in with the samba-tool command
2839 my $cmd_env = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2840 $cmd_env .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2841 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2842 $cmd_env .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2844 $cmd_env .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2846 # Note: use the backupfrom-DC's krb5.conf to do the backup
2847 $cmd_env .= " KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
2848 $cmd_env .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2850 # use samba-tool to create a backup from the 'backupfromdc' DC
2852 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2854 $cmd .= "$cmd_env $samba_tool domain backup $backup_cmd";
2855 $cmd .= " --targetdir=$backupdir";
2857 print "Executing: $cmd\n";
2858 unless(system($cmd) == 0) {
2859 warn("Failed to create backup using: \n$cmd");
2863 # get the name of the backup file created
2864 opendir(DIR, $backupdir);
2865 my @files = grep(/\.tar/, readdir(DIR));
2868 if(scalar @files != 1) {
2869 warn("Backup file not found in directory $backupdir\n");
2872 my $backup_file = "$backupdir/$files[0]";
2873 print "Using backup file $backup_file...\n";
2875 return $backup_file;
2878 # Restores a backup-file to populate a testenv for a new DC
2879 sub restore_backup_file
2881 my ($self, $backup_file, $restore_opts, $restoredir, $smbconf) = @_;
2883 # pass the restore command the testenv's smb.conf that we've already
2884 # generated. But move it to a temp-dir first, so that the restore doesn't
2886 my $tmpdir = File::Temp->newdir();
2887 my $tmpconf = "$tmpdir/smb.conf";
2888 my $cmd = "cp $smbconf $tmpconf";
2889 unless(system($cmd) == 0) {
2890 warn("Failed to backup smb.conf using: \n$cmd");
2894 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2895 $cmd = "$samba_tool domain backup restore --backup-file=$backup_file";
2896 $cmd .= " --targetdir=$restoredir $restore_opts --configfile=$tmpconf";
2898 print "Executing: $cmd\n";
2899 unless(system($cmd) == 0) {
2900 warn("Failed to restore backup using: \n$cmd");
2904 print "Restore complete\n";
2908 # sets up the initial directory and returns the new testenv's env info
2909 # (without actually doing a 'domain join')
2910 sub prepare_dc_testenv
2912 my ($self, $prefix, $dcname, $domain, $realm,
2913 $password, $conf_options) = @_;
2915 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
2925 # the restore uses a slightly different state-dir location to other testenvs
2926 $ctx->{statedir} = "$ctx->{prefix_abs}/state";
2927 push(@{$ctx->{directories}}, "$ctx->{statedir}");
2929 # add support for sysvol/netlogon/tmp shares
2930 $ctx->{share} = "$ctx->{prefix_abs}/share";
2931 push(@{$ctx->{directories}}, "$ctx->{share}");
2932 push(@{$ctx->{directories}}, "$ctx->{share}/test1");
2934 $ctx->{smb_conf_extra_options} = "
2937 server max protocol = SMB2
2938 samba kcc command = /bin/true
2939 xattr_tdb:file = $ctx->{statedir}/xattr.tdb
2942 path = $ctx->{statedir}/sysvol
2946 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
2950 path = $ctx->{share}
2952 posix:sharedelay = 10000
2953 posix:oplocktimeout = 3
2954 posix:writetimeupdatedelay = 50000
2957 path = $ctx->{share}/test1
2959 posix:sharedelay = 100000
2960 posix:oplocktimeout = 3
2961 posix:writetimeupdatedelay = 500000
2964 my $env = $self->provision_raw_step1($ctx);
2966 return ($env, $ctx);
2970 # Set up a DC testenv solely by using the samba-tool domain backup/restore
2971 # commands. This proves that we can backup an online DC ('backupfromdc') and
2972 # use the backup file to create a valid, working samba DC.
2975 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
2976 my ($self, $prefix, $dcvars) = @_;
2977 print "Preparing RESTORE DC...\n";
2979 # we arbitrarily designate the restored DC as having SMBv1 disabled
2981 server min protocol = SMB2
2982 client min protocol = SMB2
2983 prefork children = 1";
2985 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "restoredc",
2988 $dcvars->{PASSWORD},
2991 # create a backup of the 'backupfromdc'
2992 my $backupdir = File::Temp->newdir();
2993 my $server_args = $self->get_backup_server_args($dcvars);
2994 my $backup_args = "online $server_args";
2995 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
2997 unless($backup_file) {
3001 # restore the backup file to populate the restore-DC testenv
3002 my $restore_dir = abs_path($prefix);
3003 my $ret = $self->restore_backup_file($backup_file,
3004 "--newservername=$env->{SERVER}",
3005 $restore_dir, $env->{SERVERCONFFILE});
3006 unless ($ret == 0) {
3010 # start samba for the restored DC
3011 if (not defined($self->check_or_start($env))) {
3018 # Set up a DC testenv solely by using the 'samba-tool domain backup rename' and
3019 # restore commands. This proves that we can backup and rename an online DC
3020 # ('backupfromdc') and use the backup file to create a valid, working samba DC.
3023 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
3024 my ($self, $prefix, $dcvars) = @_;
3025 print "Preparing RENAME DC...\n";
3026 my $extra_conf = "prefork children = 1";
3028 my $realm = "renamedom.samba.example.com";
3029 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "renamedc",
3030 "RENAMEDOMAIN", $realm,
3031 $dcvars->{PASSWORD}, $extra_conf);
3033 # create a backup of the 'backupfromdc' which renames the domain
3034 my $backupdir = File::Temp->newdir();
3035 my $server_args = $self->get_backup_server_args($dcvars);
3036 my $backup_args = "rename $env->{DOMAIN} $env->{REALM} $server_args";
3037 $backup_args .= " --backend-store=tdb";
3038 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
3040 unless($backup_file) {
3044 # restore the backup file to populate the rename-DC testenv
3045 my $restore_dir = abs_path($prefix);
3046 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
3047 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
3048 $restore_dir, $env->{SERVERCONFFILE});
3049 unless ($ret == 0) {
3053 # start samba for the restored DC
3054 if (not defined($self->check_or_start($env))) {
3058 my $upn_array = ["$env->{REALM}.upn"];
3059 my $spn_array = ["$env->{REALM}.spn"];
3061 $self->setup_namespaces($env, $upn_array, $spn_array);
3066 # Set up a DC testenv solely by using the 'samba-tool domain backup offline' and
3067 # restore commands. This proves that we do an offline backup of a local DC
3068 # ('backupfromdc') and use the backup file to create a valid, working samba DC.
3069 sub setup_offlinebackupdc
3071 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
3072 my ($self, $prefix, $dcvars) = @_;
3073 print "Preparing OFFLINE BACKUP DC...\n";
3074 my $extra_conf = "prefork children = 1";
3076 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "offlinebackupdc",
3079 $dcvars->{PASSWORD}, $extra_conf);
3081 # create an offline backup of the 'backupfromdc' target
3082 my $backupdir = File::Temp->newdir();
3083 my $cmd = "offline -s $dcvars->{SERVERCONFFILE}";
3084 my $backup_file = $self->create_backup($env, $dcvars,
3087 unless($backup_file) {
3091 # restore the backup file to populate the rename-DC testenv
3092 my $restore_dir = abs_path($prefix);
3093 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
3094 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
3095 $restore_dir, $env->{SERVERCONFFILE});
3096 unless ($ret == 0) {
3100 # re-create the testenv's krb5.conf (the restore may have overwritten it)
3101 Samba::mk_krb5_conf($ctx);
3103 # start samba for the restored DC
3104 if (not defined($self->check_or_start($env))) {
3111 # Set up a DC testenv solely by using the samba-tool 'domain backup rename' and
3112 # restore commands, using the --no-secrets option. This proves that we can
3113 # create a realistic lab environment from an online DC ('backupfromdc').
3116 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
3117 my ($self, $prefix, $dcvars) = @_;
3118 print "Preparing LAB-DOMAIN DC...\n";
3119 my $extra_conf = "prefork children = 1";
3121 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "labdc",
3123 "labdom.samba.example.com",
3124 $dcvars->{PASSWORD}, $extra_conf);
3126 # create a backup of the 'backupfromdc' which renames the domain and uses
3127 # the --no-secrets option to scrub any sensitive info
3128 my $backupdir = File::Temp->newdir();
3129 my $server_args = $self->get_backup_server_args($dcvars);
3130 my $backup_args = "rename $env->{DOMAIN} $env->{REALM} $server_args";
3131 $backup_args .= " --no-secrets --backend-store=mdb";
3132 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
3134 unless($backup_file) {
3138 # restore the backup file to populate the lab-DC testenv
3139 my $restore_dir = abs_path($prefix);
3140 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
3141 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
3142 $restore_dir, $env->{SERVERCONFFILE});
3143 unless ($ret == 0) {
3147 # because we don't include any secrets in the backup, we need to reset the
3148 # admin user's password back to what the testenv expects
3149 my $samba_tool = Samba::bindir_path($self, "samba-tool");
3150 my $cmd = "$samba_tool user setpassword $env->{USERNAME} ";
3151 $cmd .= "--newpassword=$env->{PASSWORD} -H $restore_dir/private/sam.ldb";
3152 $cmd .= " $env->{CONFIGURATION}";
3154 unless(system($cmd) == 0) {
3155 warn("Failed to reset admin's password: \n$cmd");
3159 # start samba for the restored DC
3160 if (not defined($self->check_or_start($env))) {
3164 my $upn_array = ["$env->{REALM}.upn"];
3165 my $spn_array = ["$env->{REALM}.spn"];
3167 $self->setup_namespaces($env, $upn_array, $spn_array);
3172 # Inspects a backup *.tar.bz2 file and determines the realm/domain it contains
3173 sub get_backup_domain_realm
3175 my ($self, $backup_file) = @_;
3177 print "Determining REALM/DOMAIN values in backup...\n";
3179 # The backup will have the correct domain/realm values in the smb.conf.
3180 # So we can work out the env variables the testenv should use based on
3181 # that. Let's start by extracting the smb.conf
3182 my $tar = Archive::Tar->new($backup_file);
3183 my $tmpdir = File::Temp->newdir();
3184 my $smbconf = "$tmpdir/smb.conf";
3186 # note that the filepaths within the tar-file differ slightly for online
3187 # and offline backups
3188 if ($tar->contains_file("etc/smb.conf")) {
3189 $tar->extract_file("etc/smb.conf", $smbconf);
3190 } elsif ($tar->contains_file("./etc/smb.conf")) {
3191 $tar->extract_file("./etc/smb.conf", $smbconf);
3193 warn("Could not find smb.conf in $backup_file");
3194 return undef, undef;
3197 # make sure we don't try to create locks/sockets in the default install
3198 # location (i.e. /usr/local/samba/)
3199 my $options = "--option=\"private dir = $tmpdir\"";
3200 $options .= " --option=\"lock dir = $tmpdir\"";
3202 # now use testparm to read the values we're interested in
3203 my $testparm = Samba::bindir_path($self, "testparm");
3204 my $domain = `$testparm $smbconf -sl --parameter-name=WORKGROUP $options`;
3205 my $realm = `$testparm $smbconf -sl --parameter-name=REALM $options`;
3208 print "Backup-file REALM is $realm, DOMAIN is $domain\n";
3210 return ($domain, $realm);
3213 # This spins up a custom testenv that can be based on any backup-file you want.
3214 # This is just intended for manual testing (rather than automated test-cases)
3217 my ($self, $prefix) = @_;
3218 print "Preparing CUSTOM RESTORE DC...\n";
3219 my $dc_name = "customdc";
3220 my $password = "locDCpass1";
3221 my $backup_file = $ENV{'BACKUP_FILE'};
3223 # user must specify a backup file to restore via an ENV variable, i.e.
3224 # BACKUP_FILE=backup-blah.tar.bz2 SELFTEST_TESTENV=customdc make testenv
3225 if (not defined($backup_file)) {
3226 warn("Please specify BACKUP_FILE");
3230 # work out the correct domain/realm env values from the backup-file
3231 my ($domain, $realm) = $self->get_backup_domain_realm($backup_file);
3232 if ($domain eq '' or $realm eq '') {
3233 warn("Could not determine domain or realm");
3237 # create a placeholder directory and smb.conf, as well as the env vars.
3238 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, $dc_name,
3239 $domain, $realm, $password, "");
3241 # restore the specified backup file to populate the testenv
3242 my $restore_dir = abs_path($prefix);
3243 my $ret = $self->restore_backup_file($backup_file,
3244 "--newservername=$env->{SERVER}",
3245 $restore_dir, $env->{SERVERCONFFILE});
3246 unless ($ret == 0) {
3250 # Change the admin password to the testenv default, just in case it's
3251 # different, or in case this was a --no-secrets backup
3252 my $samba_tool = Samba::bindir_path($self, "samba-tool");
3253 my $cmd = "$samba_tool user setpassword $env->{USERNAME} ";
3254 $cmd .= "--newpassword=$password -H $restore_dir/private/sam.ldb";
3255 $cmd .= " $env->{CONFIGURATION}";
3257 unless(system($cmd) == 0) {
3258 warn("Failed to reset admin's password: \n$cmd");
3262 # re-create the testenv's krb5.conf (the restore may have overwritten it,
3263 # if the backup-file was an offline backup)
3264 Samba::mk_krb5_conf($ctx);
3266 # start samba for the restored DC
3267 if (not defined($self->check_or_start($env))) {
3271 # if this was a backup-rename, then we may need to setup namespaces
3272 my $upn_array = ["$env->{REALM}.upn"];
3273 my $spn_array = ["$env->{REALM}.spn"];
3275 $self->setup_namespaces($env, $upn_array, $spn_array);
3282 my ($self, $path) = @_;
3285 KRB5_CONFIG => abs_path($path) . "/no_krb5.conf",