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
801 dns update command = $ctx->{samba_dnsupdate}
802 spn update command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_spnupdate -s $ctx->{smb_conf}
803 gpo update command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba-gpupdate -s $ctx->{smb_conf} --target=Computer
804 samba kcc command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_kcc
805 dreplsrv:periodic_startup_interval = 0
806 dsdb:schema update allowed = yes
808 vfs objects = dfs_samba4 acl_xattr fake_acls xattr_tdb streams_depot
810 idmap_ldb:use rfc2307=yes
811 winbind enum users = yes
812 winbind enum groups = yes
814 rpc server port:netlogon = 1026
815 include system krb5 conf = no
821 # Begin extra options
822 $ctx->{smb_conf_extra_options}
827 #Default the KDC IP to the server's IP
828 if (not defined($ctx->{kdc_ipv4})) {
829 $ctx->{kdc_ipv4} = $ctx->{ipv4};
831 if (not defined($ctx->{kdc_ipv6})) {
832 $ctx->{kdc_ipv6} = $ctx->{ipv6};
835 Samba::mk_krb5_conf($ctx);
836 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
838 open(PWD, ">$ctx->{nsswrap_passwd}");
839 if ($ctx->{unix_uid} != 0) {
840 print PWD "root:x:0:0:root gecos:$ctx->{prefix_abs}:/bin/false\n";
842 print PWD "$ctx->{unix_name}:x:$ctx->{unix_uid}:65531:$ctx->{unix_name} gecos:$ctx->{prefix_abs}:/bin/false\n";
843 print PWD "nobody:x:65534:65533:nobody gecos:$ctx->{prefix_abs}:/bin/false
844 pdbtest:x:65533:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
845 pdbtest2:x:65532:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
846 pdbtest3:x:65531:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
847 pdbtest4:x:65530:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
850 my $uid_rfc2307test = 65533;
852 open(GRP, ">$ctx->{nsswrap_group}");
853 if ($ctx->{unix_gid} != 0) {
854 print GRP "root:x:0:\n";
856 print GRP "$ctx->{unix_name}:x:$ctx->{unix_gid}:\n";
857 print GRP "wheel:x:10:
860 nogroup:x:65534:nobody
863 my $gid_rfc2307test = 65532;
865 my $hostname = lc($ctx->{hostname});
866 open(HOSTS, ">>$ctx->{nsswrap_hosts}");
867 if ($hostname eq "localdc") {
868 print HOSTS "$ctx->{ipv4} ${hostname}.$ctx->{dnsname} $ctx->{dnsname} ${hostname}\n";
869 print HOSTS "$ctx->{ipv6} ${hostname}.$ctx->{dnsname} $ctx->{dnsname} ${hostname}\n";
871 print HOSTS "$ctx->{ipv4} ${hostname}.$ctx->{dnsname} ${hostname}\n";
872 print HOSTS "$ctx->{ipv6} ${hostname}.$ctx->{dnsname} ${hostname}\n";
876 my $configuration = "--configfile=$ctx->{smb_conf}";
878 #Ensure the config file is valid before we start
879 my $testparm = Samba::bindir_path($self, "samba-tool") . " testparm";
880 if (system("$testparm $configuration -v --suppress-prompt >/dev/null 2>&1") != 0) {
881 system("$testparm -v --suppress-prompt $configuration >&2");
882 warn("Failed to create a valid smb.conf configuration $testparm!");
885 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) {
886 warn("Failed to create a valid smb.conf configuration! $testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global");
890 # Return the environment variables for the new testenv DC.
891 # Note that we have SERVER_X and DC_SERVER_X variables (which have the same
892 # value initially). In a 2 DC setup, $DC_SERVER_X will always be the PDC.
894 KRB5_CONFIG => $ctx->{krb5_conf},
895 KRB5_CCACHE => $ctx->{krb5_ccache},
896 MITKDC_CONFIG => $ctx->{mitkdc_conf},
897 PIDDIR => $ctx->{piddir},
898 SERVER => $ctx->{hostname},
899 DC_SERVER => $ctx->{hostname},
900 SERVER_IP => $ctx->{ipv4},
901 DC_SERVER_IP => $ctx->{ipv4},
902 SERVER_IPV6 => $ctx->{ipv6},
903 DC_SERVER_IPV6 => $ctx->{ipv6},
904 NETBIOSNAME => $ctx->{netbiosname},
905 DC_NETBIOSNAME => $ctx->{netbiosname},
906 DOMAIN => $ctx->{domain},
907 USERNAME => $ctx->{username},
908 DC_USERNAME => $ctx->{username},
909 REALM => $ctx->{realm},
910 DNSNAME => $ctx->{dnsname},
911 SAMSID => $ctx->{samsid},
912 PASSWORD => $ctx->{password},
913 DC_PASSWORD => $ctx->{password},
914 LDAPDIR => $ctx->{ldapdir},
915 LDAP_INSTANCE => $ctx->{ldap_instance},
916 SELFTEST_WINBINDD_SOCKET_DIR => $ctx->{winbindd_socket_dir},
917 NCALRPCDIR => $ctx->{ncalrpcdir},
918 LOCKDIR => $ctx->{lockdir},
919 STATEDIR => $ctx->{statedir},
920 CACHEDIR => $ctx->{cachedir},
921 PRIVATEDIR => $ctx->{privatedir},
922 BINDDNSDIR => $ctx->{binddnsdir},
923 SERVERCONFFILE => $ctx->{smb_conf},
924 TESTENV_DIR => $ctx->{prefix_abs},
925 CONFIGURATION => $configuration,
926 SOCKET_WRAPPER_DEFAULT_IFACE => $ctx->{swiface},
927 NSS_WRAPPER_PASSWD => $ctx->{nsswrap_passwd},
928 NSS_WRAPPER_GROUP => $ctx->{nsswrap_group},
929 NSS_WRAPPER_HOSTS => $ctx->{nsswrap_hosts},
930 NSS_WRAPPER_HOSTNAME => $ctx->{nsswrap_hostname},
931 SAMBA_TEST_FIFO => "$ctx->{prefix}/samba_test.fifo",
932 SAMBA_TEST_LOG => "$ctx->{prefix}/samba_test.log",
933 SAMBA_TEST_LOG_POS => 0,
934 NSS_WRAPPER_MODULE_SO_PATH => Samba::nss_wrapper_winbind_so_path($self),
935 NSS_WRAPPER_MODULE_FN_PREFIX => "winbind",
936 LOCAL_PATH => $ctx->{share},
937 UID_RFC2307TEST => $uid_rfc2307test,
938 GID_RFC2307TEST => $gid_rfc2307test,
939 SERVER_ROLE => $ctx->{server_role},
940 RESOLV_CONF => $ctx->{resolv_conf}
943 if (defined($ctx->{use_resolv_wrapper})) {
944 $ret->{RESOLV_WRAPPER_CONF} = $ctx->{resolv_conf};
946 $ret->{RESOLV_WRAPPER_HOSTS} = $ctx->{dns_host_file};
949 if ($ctx->{server_role} eq "domain controller") {
950 $ret->{DOMSID} = $ret->{SAMSID};
957 # Step2 runs the provision script
959 sub provision_raw_step2($$$)
961 my ($self, $ctx, $ret) = @_;
963 my $provision_cmd = join(" ", @{$ctx->{provision_options}});
964 unless (system($provision_cmd) == 0) {
965 warn("Unable to provision: \n$provision_cmd\n");
969 my $testallowed_account = "testallowed";
970 my $samba_tool_cmd = "";
971 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
972 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
973 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
974 . " user create --configfile=$ctx->{smb_conf} $testallowed_account $ctx->{password}";
975 unless (system($samba_tool_cmd) == 0) {
976 warn("Unable to add testallowed user: \n$samba_tool_cmd\n");
981 $ldbmodify .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
982 $ldbmodify .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
983 $ldbmodify .= Samba::bindir_path($self, "ldbmodify");
984 $ldbmodify .= " --configfile=$ctx->{smb_conf}";
985 my $base_dn = "DC=".join(",DC=", split(/\./, $ctx->{realm}));
987 if ($ctx->{server_role} ne "domain controller") {
988 $base_dn = "DC=$ctx->{netbiosname}";
991 my $user_dn = "cn=$testallowed_account,cn=users,$base_dn";
992 $testallowed_account = "testallowed account";
993 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
994 print LDIF "dn: $user_dn
996 replace: samAccountName
997 samAccountName: $testallowed_account
1002 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
1003 print LDIF "dn: $user_dn
1005 replace: userPrincipalName
1006 userPrincipalName: testallowed upn\@$ctx->{realm}
1007 replace: servicePrincipalName
1008 servicePrincipalName: host/testallowed
1013 $samba_tool_cmd = "";
1014 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1015 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1016 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1017 . " user create --configfile=$ctx->{smb_conf} testdenied $ctx->{password}";
1018 unless (system($samba_tool_cmd) == 0) {
1019 warn("Unable to add testdenied user: \n$samba_tool_cmd\n");
1023 my $user_dn = "cn=testdenied,cn=users,$base_dn";
1024 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
1025 print LDIF "dn: $user_dn
1027 replace: userPrincipalName
1028 userPrincipalName: testdenied_upn\@$ctx->{realm}.upn
1033 $samba_tool_cmd = "";
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 create --configfile=$ctx->{smb_conf} testupnspn $ctx->{password}";
1038 unless (system($samba_tool_cmd) == 0) {
1039 warn("Unable to add testupnspn user: \n$samba_tool_cmd\n");
1043 my $user_dn = "cn=testupnspn,cn=users,$base_dn";
1044 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
1045 print LDIF "dn: $user_dn
1047 replace: userPrincipalName
1048 userPrincipalName: http/testupnspn.$ctx->{dnsname}\@$ctx->{realm}
1049 replace: servicePrincipalName
1050 servicePrincipalName: http/testupnspn.$ctx->{dnsname}
1055 $samba_tool_cmd = "";
1056 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1057 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1058 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1059 . " group addmembers --configfile=$ctx->{smb_conf} 'Allowed RODC Password Replication Group' '$testallowed_account'";
1060 unless (system($samba_tool_cmd) == 0) {
1061 warn("Unable to add '$testallowed_account' user to 'Allowed RODC Password Replication Group': \n$samba_tool_cmd\n");
1065 # Create to users alice and bob!
1066 my $user_account_array = ["alice", "bob", "jane"];
1068 foreach my $user_account (@{$user_account_array}) {
1069 my $samba_tool_cmd = "";
1071 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1072 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1073 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1074 . " user create --configfile=$ctx->{smb_conf} $user_account Secret007";
1075 unless (system($samba_tool_cmd) == 0) {
1076 warn("Unable to create user: $user_account\n$samba_tool_cmd\n");
1082 $ldbmodify .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1083 $ldbmodify .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1084 $ldbmodify .= Samba::bindir_path($self, "ldbmodify");
1085 $ldbmodify .= " --configfile=$ctx->{smb_conf}";
1086 my $base_dn = "DC=".join(",DC=", split(/\./, $ctx->{realm}));
1087 my $user_dn = "cn=jane,cn=users,$base_dn";
1089 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
1090 print LDIF "dn: $user_dn
1092 replace: userPrincipalName
1093 userPrincipalName: jane.doe\@$ctx->{realm}
1101 sub provision($$$$$$$$$$)
1103 my ($self, $prefix, $server_role, $hostname,
1104 $domain, $realm, $functional_level,
1105 $password, $kdc_ipv4, $kdc_ipv6, $extra_smbconf_options, $extra_smbconf_shares,
1106 $extra_provision_options) = @_;
1108 my $samsid = Samba::random_domain_sid();
1110 my $ctx = $self->provision_raw_prepare($prefix, $server_role,
1115 $password, $kdc_ipv4, $kdc_ipv6);
1117 if (defined($extra_provision_options)) {
1118 push (@{$ctx->{provision_options}}, @{$extra_provision_options});
1121 $ctx->{share} = "$ctx->{prefix_abs}/share";
1122 push(@{$ctx->{directories}}, "$ctx->{share}");
1123 push(@{$ctx->{directories}}, "$ctx->{share}/test1");
1124 push(@{$ctx->{directories}}, "$ctx->{share}/test2");
1126 # precreate directories for printer drivers
1127 push(@{$ctx->{directories}}, "$ctx->{share}/W32X86");
1128 push(@{$ctx->{directories}}, "$ctx->{share}/x64");
1129 push(@{$ctx->{directories}}, "$ctx->{share}/WIN40");
1132 $msdfs = "yes" if ($server_role eq "domain controller");
1133 $ctx->{smb_conf_extra_options} = "
1136 server max protocol = SMB2
1140 # fruit:copyfile is a global option
1141 fruit:copyfile = yes
1143 $extra_smbconf_options
1146 path = $ctx->{share}
1148 posix:sharedelay = 100000
1149 posix:oplocktimeout = 3
1150 posix:writetimeupdatedelay = 500000
1153 path = $ctx->{share}
1155 posix:sharedelay = 100000
1156 posix:oplocktimeout = 3
1157 posix:writetimeupdatedelay = 500000
1159 force create mode = 777
1162 path = $ctx->{share}
1165 force create mode = 0
1166 directory mask = 0777
1167 force directory mode = 0
1170 path = $ctx->{share}/test1
1172 posix:sharedelay = 100000
1173 posix:oplocktimeout = 3
1174 posix:writetimeupdatedelay = 500000
1177 path = $ctx->{share}/test2
1179 posix:sharedelay = 100000
1180 posix:oplocktimeout = 3
1181 posix:writetimeupdatedelay = 500000
1184 path = $ctx->{share}/_ignore_cifs_
1186 ntvfs handler = cifs
1187 cifs:server = $ctx->{netbiosname}
1189 cifs:use-s4u2proxy = yes
1190 # There is no username specified here, instead the client is expected
1191 # to log in with kerberos, and the serverwill use delegated credentials.
1192 # Or the server tries s4u2self/s4u2proxy to impersonate the client
1195 path = $ctx->{share}
1197 ntvfs handler = simple
1200 path = $ctx->{statedir}/sysvol
1204 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1209 ntvfs handler = cifsposix
1212 path = $ctx->{share}
1213 vfs objects = catia fruit streams_xattr acl_xattr
1215 fruit:resource = file
1216 fruit:metadata = netatalk
1217 fruit:locking = netatalk
1218 fruit:encoding = native
1221 path = $ctx->{share}
1222 # This can be used for testing real fs xattr stuff
1223 vfs objects = streams_xattr acl_xattr
1225 $extra_smbconf_shares
1228 if (defined($self->{ldap})) {
1229 $ctx->{ldapdir} = "$ctx->{privatedir}/ldap";
1230 push(@{$ctx->{directories}}, "$ctx->{ldapdir}");
1232 my $ldap_uri= "$ctx->{ldapdir}/ldapi";
1233 $ldap_uri =~ s|/|%2F|g;
1234 $ldap_uri = "ldapi://$ldap_uri";
1235 $ctx->{ldap_uri} = $ldap_uri;
1237 $ctx->{ldap_instance} = lc($ctx->{netbiosname});
1240 my $ret = $self->provision_raw_step1($ctx);
1241 unless (defined $ret) {
1245 if (defined($self->{ldap})) {
1246 $ret->{LDAP_URI} = $ctx->{ldap_uri};
1247 push (@{$ctx->{provision_options}}, "--ldap-backend-type=" . $self->{ldap});
1248 push (@{$ctx->{provision_options}}, "--ldap-backend-nosync");
1249 if ($self->{ldap} eq "openldap") {
1250 push (@{$ctx->{provision_options}}, "--slapd-path=" . $ENV{OPENLDAP_SLAPD});
1251 ($ret->{SLAPD_CONF_D}, $ret->{OPENLDAP_PIDFILE}) = $self->mk_openldap($ctx) or die("Unable to create openldap directories");
1253 } elsif ($self->{ldap} eq "fedora-ds") {
1254 push (@{$ctx->{provision_options}}, "--slapd-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/ns-slapd");
1255 push (@{$ctx->{provision_options}}, "--setup-ds-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/setup-ds.pl");
1256 ($ret->{FEDORA_DS_DIR}, $ret->{FEDORA_DS_PIDFILE}) = $self->mk_fedora_ds($ctx) or die("Unable to create fedora ds directories");
1261 return $self->provision_raw_step2($ctx, $ret);
1264 # For multi-DC testenvs, we want $DC_SERVER to always be the PDC (i.e. the
1265 # original DC) in the testenv. $SERVER is always the joined DC that we are
1266 # actually running the test against
1267 sub set_pdc_env_vars
1269 my ($self, $env, $dcvars) = @_;
1271 $env->{DC_SERVER} = $dcvars->{DC_SERVER};
1272 $env->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1273 $env->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1274 $env->{DC_SERVERCONFFILE} = $dcvars->{SERVERCONFFILE};
1275 $env->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1276 $env->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1277 $env->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1280 sub provision_s4member($$$$$)
1282 my ($self, $prefix, $dcvars, $hostname, $more_conf) = @_;
1283 print "PROVISIONING MEMBER...\n";
1284 my $extra_smb_conf = "
1285 passdb backend = samba_dsdb
1286 winbindd:use external pipes = true
1288 # the source4 smb server doesn't allow signing by default
1289 server signing = enabled
1290 raw NTLMv2 auth = yes
1292 rpc_server:default = external
1293 rpc_server:svcctl = embedded
1294 rpc_server:srvsvc = embedded
1295 rpc_server:eventlog = embedded
1296 rpc_server:ntsvcs = embedded
1297 rpc_server:winreg = embedded
1298 rpc_server:spoolss = embedded
1299 rpc_daemon:spoolssd = embedded
1300 rpc_server:tcpip = no
1303 $extra_smb_conf = $extra_smb_conf . $more_conf . "\n";
1305 my $extra_provision_options = ["--use-ntvfs"];
1306 my $ret = $self->provision($prefix,
1313 $dcvars->{SERVER_IP},
1314 $dcvars->{SERVER_IPV6},
1315 $extra_smb_conf, "",
1316 $extra_provision_options);
1321 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1322 my $cmd = $self->get_cmd_env_vars($ret);
1323 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
1324 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1325 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1327 unless (system($cmd) == 0) {
1328 warn("Join failed\n$cmd");
1332 $ret->{DOMSID} = $dcvars->{DOMSID};
1333 $self->set_pdc_env_vars($ret, $dcvars);
1338 sub provision_rpc_proxy($$$)
1340 my ($self, $prefix, $dcvars) = @_;
1341 print "PROVISIONING RPC PROXY...\n";
1343 my $extra_smbconf_options = "
1344 passdb backend = samba_dsdb
1347 dcerpc_remote:binding = ncacn_ip_tcp:$dcvars->{SERVER}
1348 dcerpc endpoint servers = epmapper, remote
1349 dcerpc_remote:interfaces = rpcecho
1350 dcerpc_remote:allow_anonymous_fallback = yes
1353 path = /tmp/_ignore_cifs_to_dc_/_none_
1355 ntvfs handler = cifs
1356 cifs:server = $dcvars->{SERVER}
1358 cifs:use-s4u2proxy = yes
1359 # There is no username specified here, instead the client is expected
1360 # to log in with kerberos, and the serverwill use delegated credentials.
1361 # Or the server tries s4u2self/s4u2proxy to impersonate the client
1365 my $extra_provision_options = ["--use-ntvfs"];
1366 my $ret = $self->provision($prefix,
1373 $dcvars->{SERVER_IP},
1374 $dcvars->{SERVER_IPV6},
1375 $extra_smbconf_options, "",
1376 $extra_provision_options);
1381 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1383 # The joind runs in the context of the rpc_proxy/member for now
1384 my $cmd = $self->get_cmd_env_vars($ret);
1385 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
1386 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1387 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1389 unless (system($cmd) == 0) {
1390 warn("Join failed\n$cmd");
1394 # Setting up delegation runs in the context of the DC for now
1396 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1397 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
1398 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1399 $cmd .= "RESOLV_CONF=\"$dcvars->{RESOLV_CONF}\" ";
1400 $cmd .= "$samba_tool delegation for-any-protocol '$ret->{NETBIOSNAME}\$' on";
1401 $cmd .= " $dcvars->{CONFIGURATION}";
1404 unless (system($cmd) == 0) {
1405 warn("Delegation failed\n$cmd");
1409 # Setting up delegation runs in the context of the DC for now
1411 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1412 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
1413 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1414 $cmd .= "RESOLV_CONF=\"$dcvars->{RESOLV_CONF}\" ";
1415 $cmd .= "$samba_tool delegation add-service '$ret->{NETBIOSNAME}\$' cifs/$dcvars->{SERVER}";
1416 $cmd .= " $dcvars->{CONFIGURATION}";
1418 unless (system($cmd) == 0) {
1419 warn("Delegation failed\n$cmd");
1423 $ret->{DOMSID} = $dcvars->{DOMSID};
1424 $self->set_pdc_env_vars($ret, $dcvars);
1429 sub provision_promoted_dc($$$)
1431 my ($self, $prefix, $dcvars) = @_;
1432 print "PROVISIONING PROMOTED DC...\n";
1434 # We do this so that we don't run the provision. That's the job of 'samba-tool domain dcpromo'.
1435 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1441 $dcvars->{PASSWORD},
1442 $dcvars->{SERVER_IP},
1443 $dcvars->{SERVER_IPV6});
1445 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1447 $ctx->{smb_conf_extra_options} = "
1449 server max protocol = SMB2
1451 ntlm auth = ntlmv2-only
1454 path = $ctx->{statedir}/sysvol
1458 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1463 my $ret = $self->provision_raw_step1($ctx);
1468 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1469 my $cmd = $self->get_cmd_env_vars($ret);
1470 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} MEMBER --realm=$dcvars->{REALM}";
1471 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1472 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1474 unless (system($cmd) == 0) {
1475 warn("Join failed\n$cmd");
1479 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1480 my $cmd = $self->get_cmd_env_vars($ret);
1481 $cmd .= "$samba_tool domain dcpromo $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1482 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1483 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs --dns-backend=BIND9_DLZ";
1485 unless (system($cmd) == 0) {
1486 warn("Join failed\n$cmd");
1490 $self->set_pdc_env_vars($ret, $dcvars);
1495 sub provision_vampire_dc($$$)
1497 my ($self, $prefix, $dcvars, $fl) = @_;
1498 print "PROVISIONING VAMPIRE DC @ FL $fl...\n";
1499 my $name = "localvampiredc";
1500 my $extra_conf = "";
1502 if ($fl == "2000") {
1503 $name = "vampire2000dc";
1505 $extra_conf = "drs: immediate link sync = yes
1506 drs: max link sync = 250";
1509 # We do this so that we don't run the provision. That's the job of 'net vampire'.
1510 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1516 $dcvars->{PASSWORD},
1517 $dcvars->{SERVER_IP},
1518 $dcvars->{SERVER_IPV6});
1520 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1522 $ctx->{smb_conf_extra_options} = "
1524 server max protocol = SMB2
1526 ntlm auth = mschapv2-and-ntlmv2-only
1530 path = $ctx->{statedir}/sysvol
1534 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1539 my $ret = $self->provision_raw_step1($ctx);
1544 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1545 my $cmd = $self->get_cmd_env_vars($ret);
1546 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1547 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} --domain-critical-only";
1548 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs";
1549 $cmd .= " --backend-store=mdb";
1551 unless (system($cmd) == 0) {
1552 warn("Join failed\n$cmd");
1556 $self->set_pdc_env_vars($ret, $dcvars);
1557 $ret->{DC_REALM} = $dcvars->{DC_REALM};
1562 sub provision_ad_dc_ntvfs($$$)
1564 my ($self, $prefix, $extra_provision_options) = @_;
1566 # We keep the old 'winbind' name here in server services to
1567 # ensure upgrades which used that name still work with the now
1570 print "PROVISIONING AD DC (NTVFS)...\n";
1571 my $extra_conf_options = "netbios aliases = localDC1-a
1572 server services = +winbind -winbindd
1573 ldap server require strong auth = allow_sasl_over_tls
1574 allow nt4 crypto = yes
1575 raw NTLMv2 auth = yes
1576 lsa over netlogon = yes
1577 rpc server port = 1027
1578 auth event notification = true
1579 dsdb event notification = true
1580 dsdb password event notification = true
1581 dsdb group change notification = true
1582 server schannel = auto
1584 push (@{$extra_provision_options}, "--use-ntvfs");
1585 my $ret = $self->provision($prefix,
1586 "domain controller",
1589 "samba.example.com",
1594 $extra_conf_options,
1596 $extra_provision_options);
1601 unless($self->add_wins_config("$prefix/private")) {
1602 warn("Unable to add wins configuration");
1605 $ret->{NETBIOSALIAS} = "localdc1-a";
1606 $ret->{DC_REALM} = $ret->{REALM};
1611 sub provision_fl2000dc($$)
1613 my ($self, $prefix) = @_;
1615 print "PROVISIONING DC WITH FOREST LEVEL 2000...\n";
1616 my $extra_conf_options = "
1617 spnego:simulate_w2k=yes
1618 ntlmssp_server:force_old_spnego=yes
1620 my $extra_provision_options = ["--use-ntvfs", "--base-schema=2008_R2"];
1621 # This environment uses plain text secrets
1622 # i.e. secret attributes are not encrypted on disk.
1623 # This allows testing of the --plaintext-secrets option for
1625 push (@{$extra_provision_options}, "--plaintext-secrets");
1626 my $ret = $self->provision($prefix,
1627 "domain controller",
1630 "samba2000.example.com",
1635 $extra_conf_options,
1637 $extra_provision_options);
1642 unless($self->add_wins_config("$prefix/private")) {
1643 warn("Unable to add wins configuration");
1646 $ret->{DC_REALM} = $ret->{REALM};
1651 sub provision_fl2003dc($$$)
1653 my ($self, $prefix, $dcvars) = @_;
1654 my $ip_addr1 = Samba::get_ipv4_addr("fakednsforwarder1");
1655 my $ip_addr2 = Samba::get_ipv4_addr("fakednsforwarder2");
1657 print "PROVISIONING DC WITH FOREST LEVEL 2003...\n";
1658 my $extra_conf_options = "allow dns updates = nonsecure and secure
1659 dcesrv:header signing = no
1660 dcesrv:max auth states = 0
1661 dns forwarder = $ip_addr1 $ip_addr2";
1662 my $extra_provision_options = ["--use-ntvfs", "--base-schema=2008_R2"];
1663 my $ret = $self->provision($prefix,
1664 "domain controller",
1667 "samba2003.example.com",
1672 $extra_conf_options,
1674 $extra_provision_options);
1675 unless (defined $ret) {
1679 $ret->{DNS_FORWARDER1} = $ip_addr1;
1680 $ret->{DNS_FORWARDER2} = $ip_addr2;
1682 my @samba_tool_options;
1683 push (@samba_tool_options, Samba::bindir_path($self, "samba-tool"));
1684 push (@samba_tool_options, "domain");
1685 push (@samba_tool_options, "passwordsettings");
1686 push (@samba_tool_options, "set");
1687 push (@samba_tool_options, "--configfile=$ret->{SERVERCONFFILE}");
1688 push (@samba_tool_options, "--min-pwd-age=0");
1689 push (@samba_tool_options, "--history-length=1");
1691 my $samba_tool_cmd = join(" ", @samba_tool_options);
1693 unless (system($samba_tool_cmd) == 0) {
1694 warn("Unable to set min password age to 0: \n$samba_tool_cmd\n");
1698 unless($self->add_wins_config("$prefix/private")) {
1699 warn("Unable to add wins configuration");
1706 sub provision_fl2008r2dc($$$)
1708 my ($self, $prefix, $dcvars) = @_;
1710 print "PROVISIONING DC WITH FOREST LEVEL 2008r2...\n";
1711 my $extra_conf_options = "ldap server require strong auth = no";
1712 my $extra_provision_options = ["--use-ntvfs", "--base-schema=2008_R2"];
1713 my $ret = $self->provision($prefix,
1714 "domain controller",
1717 "samba2008R2.example.com",
1722 $extra_conf_options,
1724 $extra_provision_options);
1725 unless (defined $ret) {
1729 unless ($self->add_wins_config("$prefix/private")) {
1730 warn("Unable to add wins configuration");
1733 $ret->{DC_REALM} = $ret->{REALM};
1739 sub provision_rodc($$$)
1741 my ($self, $prefix, $dcvars) = @_;
1742 print "PROVISIONING RODC...\n";
1744 # We do this so that we don't run the provision. That's the job of 'net join RODC'.
1745 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1751 $dcvars->{PASSWORD},
1752 $dcvars->{SERVER_IP},
1753 $dcvars->{SERVER_IPV6});
1758 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1760 $ctx->{share} = "$ctx->{prefix_abs}/share";
1761 push(@{$ctx->{directories}}, "$ctx->{share}");
1763 $ctx->{smb_conf_extra_options} = "
1765 server max protocol = SMB2
1766 password server = $dcvars->{DC_SERVER}
1769 path = $ctx->{statedir}/sysvol
1773 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1777 path = $ctx->{share}
1779 posix:sharedelay = 10000
1780 posix:oplocktimeout = 3
1781 posix:writetimeupdatedelay = 50000
1785 my $ret = $self->provision_raw_step1($ctx);
1790 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1791 my $cmd = $self->get_cmd_env_vars($ret);
1792 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} RODC";
1793 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1794 $cmd .= " --server=$dcvars->{DC_SERVER} --use-ntvfs";
1796 unless (system($cmd) == 0) {
1797 warn("RODC join failed\n$cmd");
1801 # This ensures deterministic behaviour for tests that want to have the 'testallowed account'
1802 # user password verified on the RODC
1803 my $testallowed_account = "testallowed account";
1804 $cmd = "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1805 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1806 $cmd .= "RESOLV_CONF=\"$ret->{RESOLV_CONF}\" ";
1807 $cmd .= "$samba_tool rodc preload '$testallowed_account' $ret->{CONFIGURATION}";
1808 $cmd .= " --server=$dcvars->{DC_SERVER}";
1810 unless (system($cmd) == 0) {
1811 warn("RODC join failed\n$cmd");
1815 # we overwrite the kdc after the RODC join
1816 # so that use the RODC as kdc and test
1818 $ctx->{kdc_ipv4} = $ret->{SERVER_IP};
1819 $ctx->{kdc_ipv6} = $ret->{SERVER_IPV6};
1820 Samba::mk_krb5_conf($ctx);
1821 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
1823 $self->set_pdc_env_vars($ret, $dcvars);
1828 sub read_config_h($)
1832 open(LF, "<$name") or die("unable to read $name: $!");
1835 next if not (/^#define /);
1836 if (/^#define (.*?)[ \t]+(.*?)$/) {
1840 if (/^#define (.*?)[ \t]+$/) {
1849 sub provision_ad_dc($$$$$$)
1851 my ($self, $prefix, $hostname, $domain, $realm, $smbconf_args,
1852 $extra_provision_options) = @_;
1854 my $prefix_abs = abs_path($prefix);
1856 my $bindir_abs = abs_path($self->{bindir});
1857 my $lockdir="$prefix_abs/lockdir";
1858 my $conffile="$prefix_abs/etc/smb.conf";
1860 my $require_mutexes = "dbwrap_tdb_require_mutexes:* = yes";
1861 $require_mutexes = "" if ($ENV{SELFTEST_DONT_REQUIRE_TDB_MUTEX_SUPPORT} eq "1");
1865 if (defined($ENV{CONFIG_H})) {
1866 $config_h = read_config_h($ENV{CONFIG_H});
1869 my $password_hash_gpg_key_ids = "password hash gpg key ids = 4952E40301FAB41A";
1870 $password_hash_gpg_key_ids = "" unless defined($config_h->{HAVE_GPGME});
1872 my $extra_smbconf_options = "
1873 xattr_tdb:file = $prefix_abs/statedir/xattr.tdb
1875 dbwrap_tdb_mutexes:* = yes
1878 ${password_hash_gpg_key_ids}
1881 kernel change notify = no
1886 printcap name = /dev/null
1891 smbd:sharedelay = 100000
1892 smbd:writetimeupdatedelay = 500000
1895 check parent directory delete on close = yes
1897 dcerpc endpoint servers = -winreg -srvsvc
1899 printcap name = /dev/null
1901 addprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -a -s $conffile --
1902 deleteprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -d -s $conffile --
1905 print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
1906 lpq command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpq %p
1907 lp rm command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lprm %p %j
1908 lp pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lppause %p %j
1909 lp resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpresume %p %j
1910 queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
1911 queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
1913 print notify backchannel = yes
1915 server schannel = auto
1916 auth event notification = true
1917 dsdb event notification = true
1918 dsdb password event notification = true
1919 dsdb group change notification = true
1923 my $extra_smbconf_shares = "
1927 smb encrypt = required
1931 case sensitive = yes
1939 hide unreadable = yes
1943 kernel share modes = no
1962 push (@{$extra_provision_options}, "--backend-store=mdb");
1963 print "PROVISIONING AD DC...\n";
1964 my $ret = $self->provision($prefix,
1965 "domain controller",
1973 $extra_smbconf_options,
1974 $extra_smbconf_shares,
1975 $extra_provision_options);
1976 unless (defined $ret) {
1980 unless($self->add_wins_config("$prefix/private")) {
1981 warn("Unable to add wins configuration");
1988 sub provision_chgdcpass($$)
1990 my ($self, $prefix) = @_;
1992 print "PROVISIONING CHGDCPASS...\n";
1993 # This environment disallows the use of this password
1994 # (and also removes the default AD complexity checks)
1995 my $unacceptable_password = "widk3Dsle32jxdBdskldsk55klASKQ";
1996 my $extra_smb_conf = "
1997 check password script = $self->{srcdir}/selftest/checkpassword_arg1.sh ${unacceptable_password}
1998 allow dcerpc auth level connect:lsarpc = yes
1999 dcesrv:max auth states = 8
2001 my $extra_provision_options = ["--use-ntvfs"];
2002 push (@{$extra_provision_options}, "--dns-backend=BIND9_DLZ");
2003 my $ret = $self->provision($prefix,
2004 "domain controller",
2007 "chgdcpassword.samba.example.com",
2014 $extra_provision_options);
2015 unless (defined $ret) {
2019 unless($self->add_wins_config("$prefix/private")) {
2020 warn("Unable to add wins configuration");
2024 # Remove secrets.tdb from this environment to test that we
2025 # still start up on systems without the new matching
2026 # secrets.tdb records.
2027 unless (unlink("$ret->{PRIVATEDIR}/secrets.tdb") || unlink("$ret->{PRIVATEDIR}/secrets.ntdb")) {
2028 warn("Unable to remove $ret->{PRIVATEDIR}/secrets.tdb added during provision");
2032 $ret->{UNACCEPTABLE_PASSWORD} = $unacceptable_password;
2037 sub teardown_env_terminate($$)
2039 my ($self, $envvars) = @_;
2042 # This should cause samba to terminate gracefully
2043 my $smbcontrol = Samba::bindir_path($self, "smbcontrol");
2045 $cmd .= "$smbcontrol samba shutdown $envvars->{CONFIGURATION}";
2046 my $ret = system($cmd);
2048 warn "'$cmd' failed with '$ret'\n";
2051 # This should cause samba to terminate gracefully
2052 close($envvars->{STDIN_PIPE});
2054 $pid = $envvars->{SAMBA_PID};
2058 # This should give it time to write out the gcov data
2059 until ($count > 15) {
2060 if (Samba::cleanup_child($pid, "samba") != 0) {
2067 # After 15 Seconds, work out why this thing is still alive
2068 warn "server process $pid took more than $count seconds to exit, showing backtrace:\n";
2069 system("$self->{srcdir}/selftest/gdb_backtrace $pid");
2071 until ($count > 30) {
2072 if (Samba::cleanup_child($pid, "samba") != 0) {
2079 if (kill(0, $pid)) {
2080 warn "server process $pid took more than $count seconds to exit, sending SIGTERM\n";
2084 until ($count > 40) {
2085 if (Samba::cleanup_child($pid, "samba") != 0) {
2091 # If it is still around, kill it
2092 if (kill(0, $pid)) {
2093 warn "server process $pid took more than $count seconds to exit, killing\n with SIGKILL\n";
2099 sub teardown_env($$)
2101 my ($self, $envvars) = @_;
2102 teardown_env_terminate($self, $envvars);
2104 $self->slapd_stop($envvars) if ($self->{ldap});
2106 print $self->getlog_env($envvars);
2113 my ($self, $envvars) = @_;
2114 my $title = "SAMBA LOG of: $envvars->{NETBIOSNAME} pid $envvars->{SAMBA_PID}\n";
2117 open(LOG, "<$envvars->{SAMBA_TEST_LOG}");
2119 seek(LOG, $envvars->{SAMBA_TEST_LOG_POS}, SEEK_SET);
2123 $envvars->{SAMBA_TEST_LOG_POS} = tell(LOG);
2126 return "" if $out eq $title;
2133 my ($self, $envvars) = @_;
2134 my $samba_pid = $envvars->{SAMBA_PID};
2136 if (not defined($samba_pid)) {
2138 } elsif ($samba_pid > 0) {
2139 my $childpid = Samba::cleanup_child($samba_pid, "samba");
2141 if ($childpid == 0) {
2150 # Declare the environments Samba4 makes available.
2151 # To be set up, they will be called as
2152 # samba4->setup_$envname($self, $path, $dep_1_vars, $dep_2_vars, ...)
2153 # The interdependencies between the testenvs are declared below. Some testenvs
2154 # are dependent on another testenv running first, e.g. vampire_dc is dependent
2155 # on ad_dc_ntvfs because vampire_dc joins ad_dc_ntvfs's domain. All DCs are
2156 # dependent on dns_hub, which handles resolving DNS queries for the realm.
2157 %Samba4::ENV_DEPS = (
2158 # name => [dep_1, dep_2, ...],
2160 ad_dc_ntvfs => ["dns_hub"],
2161 ad_dc => ["dns_hub"],
2162 ad_dc_no_nss => ["dns_hub"],
2163 ad_dc_no_ntlm => ["dns_hub"],
2165 fl2008r2dc => ["ad_dc"],
2166 fl2003dc => ["ad_dc"],
2167 fl2000dc => ["dns_hub"],
2169 vampire_2000_dc => ["fl2000dc"],
2170 vampire_dc => ["ad_dc_ntvfs"],
2171 promoted_dc => ["ad_dc_ntvfs"],
2173 rodc => ["ad_dc_ntvfs"],
2174 rpc_proxy => ["ad_dc_ntvfs"],
2175 chgdcpass => ["dns_hub"],
2177 s4member_dflt_domain => ["ad_dc_ntvfs"],
2178 s4member => ["ad_dc_ntvfs"],
2180 # envs that test the server process model
2181 proclimitdc => ["dns_hub"],
2182 preforkrestartdc => ["dns_hub"],
2184 # backup/restore testenvs
2185 backupfromdc => ["dns_hub"],
2186 customdc => ["dns_hub"],
2187 restoredc => ["backupfromdc"],
2188 renamedc => ["backupfromdc"],
2189 offlinebackupdc => ["backupfromdc"],
2190 labdc => ["backupfromdc"],
2192 # aliases in order to split autbuild tasks
2193 fl2008dc => ["ad_dc_ntvfs"],
2194 ad_dc_default => ["ad_dc_ntvfs"],
2195 ad_dc_slowtests => ["ad_dc_ntvfs"],
2196 ad_dc_backup => ["ad_dc"],
2198 schema_dc => ["dns_hub"],
2199 schema_pair_dc => ["schema_dc"],
2204 %Samba4::ENV_DEPS_POST = (
2205 schema_dc => ["schema_pair_dc"],
2208 sub return_alias_env
2210 my ($self, $path, $env) = @_;
2218 my ($self, $path) = @_;
2220 my $extra_args = ["--base-schema=2008_R2"];
2221 my $env = $self->provision_ad_dc_ntvfs($path, $extra_args);
2223 if (not defined($self->check_or_start($env, "standard"))) {
2224 warn("Failed to start fl2008dc");
2231 sub setup_ad_dc_default
2233 my ($self, $path, $dep_env) = @_;
2234 return $self->return_alias_env($path, $dep_env)
2237 sub setup_ad_dc_slowtests
2239 my ($self, $path, $dep_env) = @_;
2240 return $self->return_alias_env($path, $dep_env)
2243 sub setup_ad_dc_backup
2245 my ($self, $path, $dep_env) = @_;
2246 return $self->return_alias_env($path, $dep_env)
2251 my ($self, $path, $dc_vars) = @_;
2253 my $env = $self->provision_s4member($path, $dc_vars, "s4member");
2256 if (not defined($self->check_or_start($env, "standard"))) {
2264 sub setup_s4member_dflt_domain
2266 my ($self, $path, $dc_vars) = @_;
2268 my $env = $self->provision_s4member($path, $dc_vars, "s4member_dflt",
2269 "winbind use default domain = yes");
2272 if (not defined($self->check_or_start($env, "standard"))) {
2282 my ($self, $path, $dc_vars) = @_;
2284 my $env = $self->provision_rpc_proxy($path, $dc_vars);
2287 if (not defined($self->check_or_start($env, "standard"))) {
2294 sub setup_ad_dc_ntvfs
2296 my ($self, $path) = @_;
2298 my $env = $self->provision_ad_dc_ntvfs($path, undef);
2300 if (not defined($self->check_or_start($env, "standard"))) {
2301 warn("Failed to start ad_dc_ntvfs");
2310 my ($self, $path) = @_;
2312 my $env = $self->provision_chgdcpass($path);
2314 if (not defined($self->check_or_start($env, "standard"))) {
2323 my ($self, $path) = @_;
2325 my $env = $self->provision_fl2000dc($path);
2327 if (not defined($self->check_or_start($env, "standard"))) {
2337 my ($self, $path, $dc_vars) = @_;
2339 my $env = $self->provision_fl2003dc($path);
2342 if (not defined($self->check_or_start($env, "standard"))) {
2346 $env = $self->setup_trust($env, $dc_vars, "external", "--no-aes-keys");
2351 sub setup_fl2008r2dc
2353 my ($self, $path, $dc_vars) = @_;
2355 my $env = $self->provision_fl2008r2dc($path);
2358 if (not defined($self->check_or_start($env, "standard"))) {
2362 my $upn_array = ["$env->{REALM}.upn"];
2363 my $spn_array = ["$env->{REALM}.spn"];
2365 $self->setup_namespaces($env, $upn_array, $spn_array);
2367 $env = $self->setup_trust($env, $dc_vars, "forest", "");
2373 sub setup_vampire_dc
2375 return setup_generic_vampire_dc(@_, "2008");
2378 sub setup_vampire_2000_dc
2380 return setup_generic_vampire_dc(@_, "2000");
2383 sub setup_generic_vampire_dc
2385 my ($self, $path, $dc_vars, $fl) = @_;
2387 my $env = $self->provision_vampire_dc($path, $dc_vars, $fl);
2390 if (not defined($self->check_or_start($env, "single"))) {
2394 # force replicated DC to update repsTo/repsFrom
2395 # for vampired partitions
2396 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2398 # as 'vampired' dc may add data in its local replica
2399 # we need to synchronize data between DCs
2400 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2401 my $cmd = $self->get_cmd_env_vars($env);
2402 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2403 $cmd .= " $dc_vars->{CONFIGURATION}";
2404 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2405 # replicate Configuration NC
2406 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2407 unless(system($cmd_repl) == 0) {
2408 warn("Failed to replicate\n$cmd_repl");
2411 # replicate Default NC
2412 $cmd_repl = "$cmd \"$base_dn\"";
2413 unless(system($cmd_repl) == 0) {
2414 warn("Failed to replicate\n$cmd_repl");
2418 # Pull in a full set of changes from the main DC
2419 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2420 $cmd = $self->get_cmd_env_vars($env);
2421 $cmd .= " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}";
2422 $cmd .= " $dc_vars->{CONFIGURATION}";
2423 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2424 # replicate Configuration NC
2425 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2426 unless(system($cmd_repl) == 0) {
2427 warn("Failed to replicate\n$cmd_repl");
2430 # replicate Default NC
2431 $cmd_repl = "$cmd \"$base_dn\"";
2432 unless(system($cmd_repl) == 0) {
2433 warn("Failed to replicate\n$cmd_repl");
2441 sub setup_promoted_dc
2443 my ($self, $path, $dc_vars) = @_;
2445 my $env = $self->provision_promoted_dc($path, $dc_vars);
2448 if (not defined($self->check_or_start($env, "single"))) {
2452 # force source and replicated DC to update repsTo/repsFrom
2453 # for vampired partitions
2454 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2455 my $cmd = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2456 # as 'vampired' dc may add data in its local replica
2457 # we need to synchronize data between DCs
2458 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2459 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2460 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2461 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2462 $cmd .= "RESOLV_CONF=\"$env->{RESOLV_CONF}\" ";
2463 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2464 $cmd .= " $dc_vars->{CONFIGURATION}";
2465 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2466 # replicate Configuration NC
2467 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2468 unless(system($cmd_repl) == 0) {
2469 warn("Failed to replicate\n$cmd_repl");
2472 # replicate Default NC
2473 $cmd_repl = "$cmd \"$base_dn\"";
2474 unless(system($cmd_repl) == 0) {
2475 warn("Failed to replicate\n$cmd_repl");
2485 my ($self, $path, $dc_vars) = @_;
2487 my $env = $self->provision_rodc($path, $dc_vars);
2493 if (not defined($self->check_or_start($env, "standard"))) {
2497 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2500 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2501 $cmd .= "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2502 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2503 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2504 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2505 $cmd .= "RESOLV_CONF=\"$env->{RESOLV_CONF}\" ";
2506 $cmd .= " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}";
2507 $cmd .= " $dc_vars->{CONFIGURATION}";
2508 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2509 # replicate Configuration NC
2510 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2511 unless(system($cmd_repl) == 0) {
2512 warn("Failed to replicate\n$cmd_repl");
2515 # replicate Default NC
2516 $cmd_repl = "$cmd \"$base_dn\"";
2517 unless(system($cmd_repl) == 0) {
2518 warn("Failed to replicate\n$cmd_repl");
2527 my ($self, $path) = @_;
2529 # If we didn't build with ADS, pretend this env was never available
2530 if (not $self->{target3}->have_ads()) {
2534 my $env = $self->provision_ad_dc($path, "addc", "ADDOMAIN",
2535 "addom.samba.example.com", "", undef);
2540 if (not defined($self->check_or_start($env, "prefork"))) {
2544 my $upn_array = ["$env->{REALM}.upn"];
2545 my $spn_array = ["$env->{REALM}.spn"];
2547 $self->setup_namespaces($env, $upn_array, $spn_array);
2552 sub setup_ad_dc_no_nss
2554 my ($self, $path) = @_;
2556 # If we didn't build with ADS, pretend this env was never available
2557 if (not $self->{target3}->have_ads()) {
2561 my $env = $self->provision_ad_dc($path, "addc_no_nss", "ADNONSSDOMAIN",
2562 "adnonssdom.samba.example.com", "", undef);
2567 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2568 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2570 if (not defined($self->check_or_start($env, "single"))) {
2574 my $upn_array = ["$env->{REALM}.upn"];
2575 my $spn_array = ["$env->{REALM}.spn"];
2577 $self->setup_namespaces($env, $upn_array, $spn_array);
2582 sub setup_ad_dc_no_ntlm
2584 my ($self, $path) = @_;
2586 # If we didn't build with ADS, pretend this env was never available
2587 if (not $self->{target3}->have_ads()) {
2591 my $env = $self->provision_ad_dc($path, "addc_no_ntlm", "ADNONTLMDOMAIN",
2592 "adnontlmdom.samba.example.com",
2593 "ntlm auth = disabled", undef);
2598 if (not defined($self->check_or_start($env, "prefork"))) {
2602 my $upn_array = ["$env->{REALM}.upn"];
2603 my $spn_array = ["$env->{REALM}.spn"];
2605 $self->setup_namespaces($env, $upn_array, $spn_array);
2611 # AD DC test environment used solely to test pre-fork process restarts.
2612 # As processes get killed off and restarted it should not be used for other
2613 sub setup_preforkrestartdc
2615 my ($self, $path) = @_;
2617 # If we didn't build with ADS, pretend this env was never available
2618 if (not $self->{target3}->have_ads()) {
2622 # note DC name must be <= 15 chars so we use 'prockill' instead of
2624 my $env = $self->provision_ad_dc(
2628 "prockilldom.samba.example.com",
2629 "prefork backoff increment = 5\nprefork maximum backoff=10");
2634 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2635 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2637 if (not defined($self->check_or_start($env, "prefork"))) {
2641 my $upn_array = ["$env->{REALM}.upn"];
2642 my $spn_array = ["$env->{REALM}.spn"];
2644 $self->setup_namespaces($env, $upn_array, $spn_array);
2650 # ad_dc test environment used solely to test standard process model connection
2651 # process limits. As the limit is set artificially low it should not be used
2653 sub setup_proclimitdc
2655 my ($self, $path) = @_;
2657 # If we didn't build with ADS, pretend this env was never available
2658 if (not $self->{target3}->have_ads()) {
2662 my $env = $self->provision_ad_dc(
2666 "proclimit.samba.example.com",
2667 "max smbd processes = 20");
2672 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2673 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2675 if (not defined($self->check_or_start($env, "standard"))) {
2679 my $upn_array = ["$env->{REALM}.upn"];
2680 my $spn_array = ["$env->{REALM}.spn"];
2682 $self->setup_namespaces($env, $upn_array, $spn_array);
2687 # Used to test a live upgrade of the schema on a 2 DC network.
2690 my ($self, $path) = @_;
2692 # provision the PDC using an older base schema
2693 my $provision_args = ["--base-schema=2008_R2", "--backend-store=mdb"];
2695 my $env = $self->provision_ad_dc($path, "liveupgrade1dc", "SCHEMADOMAIN",
2696 "schema.samba.example.com",
2697 "drs: max link sync = 2",
2703 if (not defined($self->check_or_start($env, "prefork"))) {
2707 my $upn_array = ["$env->{REALM}.upn"];
2708 my $spn_array = ["$env->{REALM}.spn"];
2710 $self->setup_namespaces($env, $upn_array, $spn_array);
2715 # the second DC in the live schema upgrade pair
2716 sub setup_schema_pair_dc
2718 # note: dcvars contains the env info for the dependent testenv ('schema_dc')
2719 my ($self, $prefix, $dcvars) = @_;
2720 print "Preparing SCHEMA UPGRADE PAIR DC...\n";
2722 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "liveupgrade2dc",
2725 $dcvars->{PASSWORD},
2728 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2729 my $cmd_vars = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2730 $cmd_vars .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2731 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2732 $cmd_vars .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2734 $cmd_vars .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2736 $cmd_vars .= "KRB5_CONFIG=\"$env->{KRB5_CONFIG}\" ";
2737 $cmd_vars .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2738 $cmd_vars .= "RESOLV_CONF=\"$env->{RESOLV_CONF}\" ";
2740 my $join_cmd = $cmd_vars;
2741 $join_cmd .= "$samba_tool domain join $env->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
2742 $join_cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} ";
2743 $join_cmd .= " --backend-store=mdb";
2745 my $upgrade_cmd = $cmd_vars;
2746 $upgrade_cmd .= "$samba_tool domain schemaupgrade $dcvars->{CONFIGURATION}";
2747 $upgrade_cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}";
2749 my $repl_cmd = $cmd_vars;
2750 $repl_cmd .= "$samba_tool drs replicate $env->{SERVER} $dcvars->{SERVER}";
2751 $repl_cmd .= " CN=Schema,CN=Configuration,DC=schema,DC=samba,DC=example,DC=com";
2752 $repl_cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
2754 unless (system($join_cmd) == 0) {
2755 warn("Join failed\n$join_cmd");
2759 $env->{DC_SERVER} = $dcvars->{SERVER};
2760 $env->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
2761 $env->{DC_SERVER_IPV6} = $dcvars->{SERVER_IPV6};
2762 $env->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
2764 # start samba for the new DC
2765 if (not defined($self->check_or_start($env, "standard"))) {
2769 unless (system($upgrade_cmd) == 0) {
2770 warn("Schema upgrade failed\n$upgrade_cmd");
2774 unless (system($repl_cmd) == 0) {
2775 warn("Post-update schema replication failed\n$repl_cmd");
2782 # Sets up a DC that's solely used to do a domain backup from. We then use the
2783 # backupfrom-DC to create the restore-DC - this proves that the backup/restore
2784 # process will create a Samba DC that will actually start up.
2785 # We don't use the backup-DC for anything else because its domain will conflict
2786 # with the restore DC.
2787 sub setup_backupfromdc
2789 my ($self, $path) = @_;
2791 # If we didn't build with ADS, pretend this env was never available
2792 if (not $self->{target3}->have_ads()) {
2796 my $provision_args = ["--site=Backup-Site"];
2798 my $env = $self->provision_ad_dc($path, "backupfromdc", "BACKUPDOMAIN",
2799 "backupdom.samba.example.com",
2800 "samba kcc command = /bin/true",
2806 if (not defined($self->check_or_start($env))) {
2810 my $upn_array = ["$env->{REALM}.upn"];
2811 my $spn_array = ["$env->{REALM}.spn"];
2813 $self->setup_namespaces($env, $upn_array, $spn_array);
2818 # returns the server/user-auth params needed to run an online backup cmd
2819 sub get_backup_server_args
2821 # dcvars contains the env info for the backup DC testenv
2822 my ($self, $dcvars) = @_;
2823 my $server = $dcvars->{DC_SERVER_IP};
2824 my $server_args = "--server=$server ";
2825 $server_args .= "-U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
2826 $server_args .= " $dcvars->{CONFIGURATION}";
2828 return $server_args;
2831 # Creates a backup of a running testenv DC
2834 # note: dcvars contains the env info for the backup DC testenv
2835 my ($self, $env, $dcvars, $backupdir, $backup_cmd) = @_;
2837 # get all the env variables we pass in with the samba-tool command
2838 my $cmd_env = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2839 $cmd_env .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2840 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2841 $cmd_env .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2843 $cmd_env .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2845 # Note: use the backupfrom-DC's krb5.conf to do the backup
2846 $cmd_env .= " KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
2847 $cmd_env .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2849 # use samba-tool to create a backup from the 'backupfromdc' DC
2851 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2853 $cmd .= "$cmd_env $samba_tool domain backup $backup_cmd";
2854 $cmd .= " --targetdir=$backupdir";
2856 print "Executing: $cmd\n";
2857 unless(system($cmd) == 0) {
2858 warn("Failed to create backup using: \n$cmd");
2862 # get the name of the backup file created
2863 opendir(DIR, $backupdir);
2864 my @files = grep(/\.tar/, readdir(DIR));
2867 if(scalar @files != 1) {
2868 warn("Backup file not found in directory $backupdir\n");
2871 my $backup_file = "$backupdir/$files[0]";
2872 print "Using backup file $backup_file...\n";
2874 return $backup_file;
2877 # Restores a backup-file to populate a testenv for a new DC
2878 sub restore_backup_file
2880 my ($self, $backup_file, $restore_opts, $restoredir, $smbconf) = @_;
2882 # pass the restore command the testenv's smb.conf that we've already
2883 # generated. But move it to a temp-dir first, so that the restore doesn't
2885 my $tmpdir = File::Temp->newdir();
2886 my $tmpconf = "$tmpdir/smb.conf";
2887 my $cmd = "cp $smbconf $tmpconf";
2888 unless(system($cmd) == 0) {
2889 warn("Failed to backup smb.conf using: \n$cmd");
2893 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2894 $cmd = "$samba_tool domain backup restore --backup-file=$backup_file";
2895 $cmd .= " --targetdir=$restoredir $restore_opts --configfile=$tmpconf";
2897 print "Executing: $cmd\n";
2898 unless(system($cmd) == 0) {
2899 warn("Failed to restore backup using: \n$cmd");
2903 print "Restore complete\n";
2907 # sets up the initial directory and returns the new testenv's env info
2908 # (without actually doing a 'domain join')
2909 sub prepare_dc_testenv
2911 my ($self, $prefix, $dcname, $domain, $realm,
2912 $password, $conf_options) = @_;
2914 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
2924 # the restore uses a slightly different state-dir location to other testenvs
2925 $ctx->{statedir} = "$ctx->{prefix_abs}/state";
2926 push(@{$ctx->{directories}}, "$ctx->{statedir}");
2928 # add support for sysvol/netlogon/tmp shares
2929 $ctx->{share} = "$ctx->{prefix_abs}/share";
2930 push(@{$ctx->{directories}}, "$ctx->{share}");
2931 push(@{$ctx->{directories}}, "$ctx->{share}/test1");
2933 $ctx->{smb_conf_extra_options} = "
2936 server max protocol = SMB2
2937 samba kcc command = /bin/true
2938 xattr_tdb:file = $ctx->{statedir}/xattr.tdb
2941 path = $ctx->{statedir}/sysvol
2945 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
2949 path = $ctx->{share}
2951 posix:sharedelay = 10000
2952 posix:oplocktimeout = 3
2953 posix:writetimeupdatedelay = 50000
2956 path = $ctx->{share}/test1
2958 posix:sharedelay = 100000
2959 posix:oplocktimeout = 3
2960 posix:writetimeupdatedelay = 500000
2963 my $env = $self->provision_raw_step1($ctx);
2965 return ($env, $ctx);
2969 # Set up a DC testenv solely by using the samba-tool domain backup/restore
2970 # commands. This proves that we can backup an online DC ('backupfromdc') and
2971 # use the backup file to create a valid, working samba DC.
2974 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
2975 my ($self, $prefix, $dcvars) = @_;
2976 print "Preparing RESTORE DC...\n";
2978 # we arbitrarily designate the restored DC as having SMBv1 disabled
2980 server min protocol = SMB2
2981 client min protocol = SMB2
2982 prefork children = 1";
2984 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "restoredc",
2987 $dcvars->{PASSWORD},
2990 # create a backup of the 'backupfromdc'
2991 my $backupdir = File::Temp->newdir();
2992 my $server_args = $self->get_backup_server_args($dcvars);
2993 my $backup_args = "online $server_args";
2994 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
2996 unless($backup_file) {
3000 # restore the backup file to populate the restore-DC testenv
3001 my $restore_dir = abs_path($prefix);
3002 my $ret = $self->restore_backup_file($backup_file,
3003 "--newservername=$env->{SERVER}",
3004 $restore_dir, $env->{SERVERCONFFILE});
3005 unless ($ret == 0) {
3009 # start samba for the restored DC
3010 if (not defined($self->check_or_start($env))) {
3017 # Set up a DC testenv solely by using the 'samba-tool domain backup rename' and
3018 # restore commands. This proves that we can backup and rename an online DC
3019 # ('backupfromdc') and use the backup file to create a valid, working samba DC.
3022 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
3023 my ($self, $prefix, $dcvars) = @_;
3024 print "Preparing RENAME DC...\n";
3025 my $extra_conf = "prefork children = 1";
3027 my $realm = "renamedom.samba.example.com";
3028 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "renamedc",
3029 "RENAMEDOMAIN", $realm,
3030 $dcvars->{PASSWORD}, $extra_conf);
3032 # create a backup of the 'backupfromdc' which renames the domain
3033 my $backupdir = File::Temp->newdir();
3034 my $server_args = $self->get_backup_server_args($dcvars);
3035 my $backup_args = "rename $env->{DOMAIN} $env->{REALM} $server_args";
3036 $backup_args .= " --backend-store=tdb";
3037 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
3039 unless($backup_file) {
3043 # restore the backup file to populate the rename-DC testenv
3044 my $restore_dir = abs_path($prefix);
3045 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
3046 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
3047 $restore_dir, $env->{SERVERCONFFILE});
3048 unless ($ret == 0) {
3052 # start samba for the restored DC
3053 if (not defined($self->check_or_start($env))) {
3057 my $upn_array = ["$env->{REALM}.upn"];
3058 my $spn_array = ["$env->{REALM}.spn"];
3060 $self->setup_namespaces($env, $upn_array, $spn_array);
3065 # Set up a DC testenv solely by using the 'samba-tool domain backup offline' and
3066 # restore commands. This proves that we do an offline backup of a local DC
3067 # ('backupfromdc') and use the backup file to create a valid, working samba DC.
3068 sub setup_offlinebackupdc
3070 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
3071 my ($self, $prefix, $dcvars) = @_;
3072 print "Preparing OFFLINE BACKUP DC...\n";
3073 my $extra_conf = "prefork children = 1";
3075 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "offlinebackupdc",
3078 $dcvars->{PASSWORD}, $extra_conf);
3080 # create an offline backup of the 'backupfromdc' target
3081 my $backupdir = File::Temp->newdir();
3082 my $cmd = "offline -s $dcvars->{SERVERCONFFILE}";
3083 my $backup_file = $self->create_backup($env, $dcvars,
3086 unless($backup_file) {
3090 # restore the backup file to populate the rename-DC testenv
3091 my $restore_dir = abs_path($prefix);
3092 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
3093 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
3094 $restore_dir, $env->{SERVERCONFFILE});
3095 unless ($ret == 0) {
3099 # re-create the testenv's krb5.conf (the restore may have overwritten it)
3100 Samba::mk_krb5_conf($ctx);
3102 # start samba for the restored DC
3103 if (not defined($self->check_or_start($env))) {
3110 # Set up a DC testenv solely by using the samba-tool 'domain backup rename' and
3111 # restore commands, using the --no-secrets option. This proves that we can
3112 # create a realistic lab environment from an online DC ('backupfromdc').
3115 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
3116 my ($self, $prefix, $dcvars) = @_;
3117 print "Preparing LAB-DOMAIN DC...\n";
3118 my $extra_conf = "prefork children = 1";
3120 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "labdc",
3122 "labdom.samba.example.com",
3123 $dcvars->{PASSWORD}, $extra_conf);
3125 # create a backup of the 'backupfromdc' which renames the domain and uses
3126 # the --no-secrets option to scrub any sensitive info
3127 my $backupdir = File::Temp->newdir();
3128 my $server_args = $self->get_backup_server_args($dcvars);
3129 my $backup_args = "rename $env->{DOMAIN} $env->{REALM} $server_args";
3130 $backup_args .= " --no-secrets --backend-store=mdb";
3131 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
3133 unless($backup_file) {
3137 # restore the backup file to populate the lab-DC testenv
3138 my $restore_dir = abs_path($prefix);
3139 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
3140 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
3141 $restore_dir, $env->{SERVERCONFFILE});
3142 unless ($ret == 0) {
3146 # because we don't include any secrets in the backup, we need to reset the
3147 # admin user's password back to what the testenv expects
3148 my $samba_tool = Samba::bindir_path($self, "samba-tool");
3149 my $cmd = "$samba_tool user setpassword $env->{USERNAME} ";
3150 $cmd .= "--newpassword=$env->{PASSWORD} -H $restore_dir/private/sam.ldb";
3151 $cmd .= " $env->{CONFIGURATION}";
3153 unless(system($cmd) == 0) {
3154 warn("Failed to reset admin's password: \n$cmd");
3158 # start samba for the restored DC
3159 if (not defined($self->check_or_start($env))) {
3163 my $upn_array = ["$env->{REALM}.upn"];
3164 my $spn_array = ["$env->{REALM}.spn"];
3166 $self->setup_namespaces($env, $upn_array, $spn_array);
3171 # Inspects a backup *.tar.bz2 file and determines the realm/domain it contains
3172 sub get_backup_domain_realm
3174 my ($self, $backup_file) = @_;
3176 print "Determining REALM/DOMAIN values in backup...\n";
3178 # The backup will have the correct domain/realm values in the smb.conf.
3179 # So we can work out the env variables the testenv should use based on
3180 # that. Let's start by extracting the smb.conf
3181 my $tar = Archive::Tar->new($backup_file);
3182 my $tmpdir = File::Temp->newdir();
3183 my $smbconf = "$tmpdir/smb.conf";
3185 # note that the filepaths within the tar-file differ slightly for online
3186 # and offline backups
3187 if ($tar->contains_file("etc/smb.conf")) {
3188 $tar->extract_file("etc/smb.conf", $smbconf);
3189 } elsif ($tar->contains_file("./etc/smb.conf")) {
3190 $tar->extract_file("./etc/smb.conf", $smbconf);
3192 warn("Could not find smb.conf in $backup_file");
3193 return undef, undef;
3196 # make sure we don't try to create locks/sockets in the default install
3197 # location (i.e. /usr/local/samba/)
3198 my $options = "--option=\"private dir = $tmpdir\"";
3199 $options .= " --option=\"lock dir = $tmpdir\"";
3201 # now use testparm to read the values we're interested in
3202 my $testparm = Samba::bindir_path($self, "testparm");
3203 my $domain = `$testparm $smbconf -sl --parameter-name=WORKGROUP $options`;
3204 my $realm = `$testparm $smbconf -sl --parameter-name=REALM $options`;
3207 print "Backup-file REALM is $realm, DOMAIN is $domain\n";
3209 return ($domain, $realm);
3212 # This spins up a custom testenv that can be based on any backup-file you want.
3213 # This is just intended for manual testing (rather than automated test-cases)
3216 my ($self, $prefix) = @_;
3217 print "Preparing CUSTOM RESTORE DC...\n";
3218 my $dc_name = "customdc";
3219 my $password = "locDCpass1";
3220 my $backup_file = $ENV{'BACKUP_FILE'};
3222 # user must specify a backup file to restore via an ENV variable, i.e.
3223 # BACKUP_FILE=backup-blah.tar.bz2 SELFTEST_TESTENV=customdc make testenv
3224 if (not defined($backup_file)) {
3225 warn("Please specify BACKUP_FILE");
3229 # work out the correct domain/realm env values from the backup-file
3230 my ($domain, $realm) = $self->get_backup_domain_realm($backup_file);
3231 if ($domain eq '' or $realm eq '') {
3232 warn("Could not determine domain or realm");
3236 # create a placeholder directory and smb.conf, as well as the env vars.
3237 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, $dc_name,
3238 $domain, $realm, $password, "");
3240 # restore the specified backup file to populate the testenv
3241 my $restore_dir = abs_path($prefix);
3242 my $ret = $self->restore_backup_file($backup_file,
3243 "--newservername=$env->{SERVER}",
3244 $restore_dir, $env->{SERVERCONFFILE});
3245 unless ($ret == 0) {
3249 # Change the admin password to the testenv default, just in case it's
3250 # different, or in case this was a --no-secrets backup
3251 my $samba_tool = Samba::bindir_path($self, "samba-tool");
3252 my $cmd = "$samba_tool user setpassword $env->{USERNAME} ";
3253 $cmd .= "--newpassword=$password -H $restore_dir/private/sam.ldb";
3254 $cmd .= " $env->{CONFIGURATION}";
3256 unless(system($cmd) == 0) {
3257 warn("Failed to reset admin's password: \n$cmd");
3261 # re-create the testenv's krb5.conf (the restore may have overwritten it,
3262 # if the backup-file was an offline backup)
3263 Samba::mk_krb5_conf($ctx);
3265 # start samba for the restored DC
3266 if (not defined($self->check_or_start($env))) {
3270 # if this was a backup-rename, then we may need to setup namespaces
3271 my $upn_array = ["$env->{REALM}.upn"];
3272 my $spn_array = ["$env->{REALM}.spn"];
3274 $self->setup_namespaces($env, $upn_array, $spn_array);
3281 my ($self, $path) = @_;
3284 KRB5_CONFIG => abs_path($path) . "/no_krb5.conf",